git.delta.rocks / jrsonnet / refs/commits / c58af2989051

difftreelog

test split tests

Yaroslav Bolyukin2022-04-22parent: #0843f20.patch.diff
in: master

45 files changed

modifiedcrates/jrsonnet-evaluator/src/builtin/format.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/builtin/format.rs
+++ b/crates/jrsonnet-evaluator/src/builtin/format.rs
@@ -741,21 +741,51 @@
 
 	#[test]
 	fn octals() {
-		assert_eq!(format_arr("%#o", &[Val::Num(8.0)]).unwrap(), "010");
-		assert_eq!(format_arr("%#4o", &[Val::Num(8.0)]).unwrap(), " 010");
-		assert_eq!(format_arr("%4o", &[Val::Num(8.0)]).unwrap(), "  10");
-		assert_eq!(format_arr("%04o", &[Val::Num(8.0)]).unwrap(), "0010");
-		assert_eq!(format_arr("%+4o", &[Val::Num(8.0)]).unwrap(), " +10");
-		assert_eq!(format_arr("%+04o", &[Val::Num(8.0)]).unwrap(), "+010");
-		assert_eq!(format_arr("%-4o", &[Val::Num(8.0)]).unwrap(), "10  ");
-		assert_eq!(format_arr("%+-4o", &[Val::Num(8.0)]).unwrap(), "+10 ");
-		assert_eq!(format_arr("%+-04o", &[Val::Num(8.0)]).unwrap(), "+10 ");
+		let s = State::default();
+		assert_eq!(
+			format_arr(s.clone(), "%#o", &[Val::Num(8.0)]).unwrap(),
+			"010"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%#4o", &[Val::Num(8.0)]).unwrap(),
+			" 010"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%4o", &[Val::Num(8.0)]).unwrap(),
+			"  10"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%04o", &[Val::Num(8.0)]).unwrap(),
+			"0010"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%+4o", &[Val::Num(8.0)]).unwrap(),
+			" +10"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%+04o", &[Val::Num(8.0)]).unwrap(),
+			"+010"
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%-4o", &[Val::Num(8.0)]).unwrap(),
+			"10  "
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%+-4o", &[Val::Num(8.0)]).unwrap(),
+			"+10 "
+		);
+		assert_eq!(
+			format_arr(s.clone(), "%+-04o", &[Val::Num(8.0)]).unwrap(),
+			"+10 "
+		);
 	}
 
 	#[test]
 	fn percent_doesnt_consumes_values() {
+		let s = State::default();
 		assert_eq!(
 			format_arr(
+				s,
 				"How much error budget is left looking at our %.3f%% availability gurantees?",
 				&[Val::Num(4.0)]
 			)
modifiedcrates/jrsonnet-evaluator/src/builtin/mod.rsdiffbeforeafterboth
before · crates/jrsonnet-evaluator/src/builtin/mod.rs
1// All builtins should return results2#![allow(clippy::unnecessary_wraps)]34use std::collections::HashMap;56use format::{format_arr, format_obj};7use gcmodule::Cc;8use jrsonnet_interner::IStr;9use serde::Deserialize;10use serde_yaml::DeserializingQuirks;1112use crate::{13	builtin::manifest::{manifest_yaml_ex, ManifestYamlOptions},14	error::{Error::*, Result},15	function::{CallLocation, StaticBuiltin},16	operator::evaluate_mod_op,17	throw,18	typed::{Any, BoundedUsize, Bytes, Either2, Either4, PositiveF64, Typed, VecVal, M1},19	val::{equals, primitive_equals, ArrValue, FuncVal, IndexableVal, Slice},20	Either, ObjValue, State, Val,21};2223pub mod stdlib;24pub use stdlib::*;2526use self::manifest::{escape_string_json, manifest_json_ex, ManifestJsonOptions, ManifestType};2728pub mod format;29pub mod manifest;30pub mod sort;3132pub fn std_format(s: State, str: IStr, vals: Val) -> Result<String> {33	s.push(34		CallLocation::native(),35		|| format!("std.format of {}", str),36		|| {37			Ok(match vals {38				Val::Arr(vals) => format_arr(s.clone(), &str, &vals.evaluated(s.clone())?)?,39				Val::Obj(obj) => format_obj(s.clone(), &str, &obj)?,40				o => format_arr(s.clone(), &str, &[o])?,41			})42		},43	)44}4546pub fn std_slice(47	indexable: IndexableVal,48	index: Option<BoundedUsize<0, { i32::MAX as usize }>>,49	end: Option<BoundedUsize<0, { i32::MAX as usize }>>,50	step: Option<BoundedUsize<1, { i32::MAX as usize }>>,51) -> Result<Val> {52	match &indexable {53		IndexableVal::Str(s) => {54			let index = index.as_deref().copied().unwrap_or(0);55			let end = end.as_deref().copied().unwrap_or(usize::MAX);56			let step = step.as_deref().copied().unwrap_or(1);5758			if index >= end {59				return Ok(Val::Str("".into()));60			}6162			Ok(Val::Str(63				(s.chars()64					.skip(index)65					.take(end - index)66					.step_by(step)67					.collect::<String>())68				.into(),69			))70		}71		IndexableVal::Arr(arr) => {72			let index = index.as_deref().copied().unwrap_or(0);73			let end = end.as_deref().copied().unwrap_or(usize::MAX).min(arr.len());74			let step = step.as_deref().copied().unwrap_or(1);7576			if index >= end {77				return Ok(Val::Arr(ArrValue::new_eager()));78			}7980			Ok(Val::Arr(ArrValue::Slice(Box::new(Slice {81				inner: arr.clone(),82				from: index as u32,83				to: end as u32,84				step: step as u32,85			}))))86		}87	}88}8990type BuiltinsType = HashMap<IStr, &'static dyn StaticBuiltin>;9192thread_local! {93	pub static BUILTINS: BuiltinsType = {94		[95			("length".into(), builtin_length::INST),96			("type".into(), builtin_type::INST),97			("makeArray".into(), builtin_make_array::INST),98			("codepoint".into(), builtin_codepoint::INST),99			("objectFieldsEx".into(), builtin_object_fields_ex::INST),100			("objectHasEx".into(), builtin_object_has_ex::INST),101			("slice".into(), builtin_slice::INST),102			("substr".into(), builtin_substr::INST),103			("primitiveEquals".into(), builtin_primitive_equals::INST),104			("equals".into(), builtin_equals::INST),105			("modulo".into(), builtin_modulo::INST),106			("mod".into(), builtin_mod::INST),107			("floor".into(), builtin_floor::INST),108			("ceil".into(), builtin_ceil::INST),109			("log".into(), builtin_log::INST),110			("pow".into(), builtin_pow::INST),111			("sqrt".into(), builtin_sqrt::INST),112			("sin".into(), builtin_sin::INST),113			("cos".into(), builtin_cos::INST),114			("tan".into(), builtin_tan::INST),115			("asin".into(), builtin_asin::INST),116			("acos".into(), builtin_acos::INST),117			("atan".into(), builtin_atan::INST),118			("exp".into(), builtin_exp::INST),119			("mantissa".into(), builtin_mantissa::INST),120			("exponent".into(), builtin_exponent::INST),121			("extVar".into(), builtin_ext_var::INST),122			("native".into(), builtin_native::INST),123			("filter".into(), builtin_filter::INST),124			("map".into(), builtin_map::INST),125			("flatMap".into(), builtin_flatmap::INST),126			("foldl".into(), builtin_foldl::INST),127			("foldr".into(), builtin_foldr::INST),128			("sort".into(), builtin_sort::INST),129			("format".into(), builtin_format::INST),130			("range".into(), builtin_range::INST),131			("char".into(), builtin_char::INST),132			("encodeUTF8".into(), builtin_encode_utf8::INST),133			("decodeUTF8".into(), builtin_decode_utf8::INST),134			("md5".into(), builtin_md5::INST),135			("base64".into(), builtin_base64::INST),136			("base64DecodeBytes".into(), builtin_base64_decode_bytes::INST),137			("base64Decode".into(), builtin_base64_decode::INST),138			("trace".into(), builtin_trace::INST),139			("join".into(), builtin_join::INST),140			("escapeStringJson".into(), builtin_escape_string_json::INST),141			("manifestJsonEx".into(), builtin_manifest_json_ex::INST),142			("manifestYamlDoc".into(), builtin_manifest_yaml_doc::INST),143			("reverse".into(), builtin_reverse::INST),144			("id".into(), builtin_id::INST),145			("strReplace".into(), builtin_str_replace::INST),146			("splitLimit".into(), builtin_splitlimit::INST),147			("parseJson".into(), builtin_parse_json::INST),148			("parseYaml".into(), builtin_parse_yaml::INST),149			("asciiUpper".into(), builtin_ascii_upper::INST),150			("asciiLower".into(), builtin_ascii_lower::INST),151			("member".into(), builtin_member::INST),152			("count".into(), builtin_count::INST),153			("any".into(), builtin_any::INST),154			("all".into(), builtin_all::INST),155		].iter().cloned().collect()156	};157}158159#[jrsonnet_macros::builtin]160fn builtin_length(x: Either![IStr, ArrValue, ObjValue, FuncVal]) -> Result<usize> {161	use Either4::*;162	Ok(match x {163		A(x) => x.chars().count(),164		B(x) => x.len(),165		C(x) => x.len(),166		D(f) => f.args_len(),167	})168}169170#[jrsonnet_macros::builtin]171fn builtin_type(x: Any) -> Result<IStr> {172	Ok(x.0.value_type().name().into())173}174175#[jrsonnet_macros::builtin]176fn builtin_make_array(s: State, sz: usize, func: FuncVal) -> Result<VecVal> {177	let mut out = Vec::with_capacity(sz);178	for i in 0..sz {179		out.push(func.evaluate_simple(s.clone(), &[i as f64].as_slice())?);180	}181	Ok(VecVal(Cc::new(out)))182}183184#[jrsonnet_macros::builtin]185const fn builtin_codepoint(str: char) -> Result<u32> {186	Ok(str as u32)187}188189#[jrsonnet_macros::builtin]190fn builtin_object_fields_ex(191	obj: ObjValue,192	inc_hidden: bool,193	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,194) -> Result<VecVal> {195	#[cfg(feature = "exp-preserve-order")]196	let preserve_order = preserve_order.unwrap_or(false);197	let out = obj.fields_ex(198		inc_hidden,199		#[cfg(feature = "exp-preserve-order")]200		preserve_order,201	);202	Ok(VecVal(Cc::new(203		out.into_iter().map(Val::Str).collect::<Vec<_>>(),204	)))205}206207#[jrsonnet_macros::builtin]208fn builtin_object_has_ex(obj: ObjValue, f: IStr, inc_hidden: bool) -> Result<bool> {209	Ok(obj.has_field_ex(f, inc_hidden))210}211212#[jrsonnet_macros::builtin]213fn builtin_parse_json(st: State, s: IStr) -> Result<Any> {214	use serde_json::Value;215	let value: Value = serde_json::from_str(&s)216		.map_err(|e| RuntimeError(format!("failed to parse json: {}", e).into()))?;217	Ok(Any(Value::into_untyped(value, st)?))218}219220#[jrsonnet_macros::builtin]221fn builtin_parse_yaml(st: State, s: IStr) -> Result<Any> {222	use serde_json::Value;223	let value = serde_yaml::Deserializer::from_str_with_quirks(224		&s,225		DeserializingQuirks { old_octals: true },226	);227	let mut out = vec![];228	for item in value {229		let value = Value::deserialize(item)230			.map_err(|e| RuntimeError(format!("failed to parse yaml: {}", e).into()))?;231		let val = Value::into_untyped(value, st.clone())?;232		out.push(val);233	}234	Ok(Any(if out.is_empty() {235		Val::Null236	} else if out.len() == 1 {237		out.into_iter().next().unwrap()238	} else {239		Val::Arr(out.into())240	}))241}242243#[jrsonnet_macros::builtin]244fn builtin_slice(245	indexable: IndexableVal,246	index: Option<BoundedUsize<0, { i32::MAX as usize }>>,247	end: Option<BoundedUsize<0, { i32::MAX as usize }>>,248	step: Option<BoundedUsize<1, { i32::MAX as usize }>>,249) -> Result<Any> {250	std_slice(indexable, index, end, step).map(Any)251}252253#[jrsonnet_macros::builtin]254fn builtin_substr(str: IStr, from: usize, len: usize) -> Result<String> {255	Ok(str.chars().skip(from as usize).take(len as usize).collect())256}257258#[jrsonnet_macros::builtin]259fn builtin_primitive_equals(a: Any, b: Any) -> Result<bool> {260	primitive_equals(&a.0, &b.0)261}262263#[jrsonnet_macros::builtin]264fn builtin_equals(s: State, a: Any, b: Any) -> Result<bool> {265	equals(s, &a.0, &b.0)266}267268#[jrsonnet_macros::builtin]269fn builtin_modulo(a: f64, b: f64) -> Result<f64> {270	Ok(a % b)271}272273#[jrsonnet_macros::builtin]274fn builtin_mod(s: State, a: Either![f64, IStr], b: Any) -> Result<Any> {275	use Either2::*;276	Ok(Any(evaluate_mod_op(277		s,278		&match a {279			A(v) => Val::Num(v),280			B(s) => Val::Str(s),281		},282		&b.0,283	)?))284}285286#[jrsonnet_macros::builtin]287fn builtin_floor(x: f64) -> Result<f64> {288	Ok(x.floor())289}290291#[jrsonnet_macros::builtin]292fn builtin_ceil(x: f64) -> Result<f64> {293	Ok(x.ceil())294}295296#[jrsonnet_macros::builtin]297fn builtin_log(n: f64) -> Result<f64> {298	Ok(n.ln())299}300301#[jrsonnet_macros::builtin]302fn builtin_pow(x: f64, n: f64) -> Result<f64> {303	Ok(x.powf(n))304}305306#[jrsonnet_macros::builtin]307fn builtin_sqrt(x: PositiveF64) -> Result<f64> {308	Ok(x.0.sqrt())309}310311#[jrsonnet_macros::builtin]312fn builtin_sin(x: f64) -> Result<f64> {313	Ok(x.sin())314}315316#[jrsonnet_macros::builtin]317fn builtin_cos(x: f64) -> Result<f64> {318	Ok(x.cos())319}320321#[jrsonnet_macros::builtin]322fn builtin_tan(x: f64) -> Result<f64> {323	Ok(x.tan())324}325326#[jrsonnet_macros::builtin]327fn builtin_asin(x: f64) -> Result<f64> {328	Ok(x.asin())329}330331#[jrsonnet_macros::builtin]332fn builtin_acos(x: f64) -> Result<f64> {333	Ok(x.acos())334}335336#[jrsonnet_macros::builtin]337fn builtin_atan(x: f64) -> Result<f64> {338	Ok(x.atan())339}340341#[jrsonnet_macros::builtin]342fn builtin_exp(x: f64) -> Result<f64> {343	Ok(x.exp())344}345346fn frexp(s: f64) -> (f64, i16) {347	if 0.0 == s {348		(s, 0)349	} else {350		let lg = s.abs().log2();351		let x = (lg - lg.floor() - 1.0).exp2();352		let exp = lg.floor() + 1.0;353		(s.signum() * x, exp as i16)354	}355}356357#[jrsonnet_macros::builtin]358fn builtin_mantissa(x: f64) -> Result<f64> {359	Ok(frexp(x).0)360}361362#[jrsonnet_macros::builtin]363fn builtin_exponent(x: f64) -> Result<i16> {364	Ok(frexp(x).1)365}366367#[jrsonnet_macros::builtin]368fn builtin_ext_var(s: State, x: IStr) -> Result<Any> {369	Ok(Any(s370		.settings()371		.ext_vars372		.get(&x)373		.cloned()374		.ok_or(UndefinedExternalVariable(x))?))375}376377#[jrsonnet_macros::builtin]378fn builtin_native(s: State, name: IStr) -> Result<Any> {379	Ok(Any(s380		.settings()381		.ext_natives382		.get(&name)383		.cloned()384		.map(|v| Val::Func(FuncVal::Builtin(v.clone())))385		.unwrap_or(Val::Null)))386}387388#[jrsonnet_macros::builtin]389fn builtin_filter(s: State, func: FuncVal, arr: ArrValue) -> Result<ArrValue> {390	arr.filter(s.clone(), |val| {391		bool::from_untyped(392			func.evaluate_simple(s.clone(), &[Any(val.clone())].as_slice())?,393			s.clone(),394		)395	})396}397398#[jrsonnet_macros::builtin]399fn builtin_map(s: State, func: FuncVal, arr: ArrValue) -> Result<ArrValue> {400	arr.map(s.clone(), |val| {401		func.evaluate_simple(s.clone(), &[Any(val)].as_slice())402	})403}404405#[jrsonnet_macros::builtin]406fn builtin_flatmap(s: State, func: FuncVal, arr: IndexableVal) -> Result<IndexableVal> {407	match arr {408		IndexableVal::Str(str) => {409			let mut out = String::new();410			for c in str.chars() {411				match func.evaluate_simple(s.clone(), &[c.to_string()].as_slice())? {412					Val::Str(o) => out.push_str(&o),413					Val::Null => continue,414					_ => throw!(RuntimeError(415						"in std.join all items should be strings".into()416					)),417				};418			}419			Ok(IndexableVal::Str(out.into()))420		}421		IndexableVal::Arr(a) => {422			let mut out = Vec::new();423			for el in a.iter(s.clone()) {424				let el = el?;425				match func.evaluate_simple(s.clone(), &[Any(el)].as_slice())? {426					Val::Arr(o) => {427						for oe in o.iter(s.clone()) {428							out.push(oe?);429						}430					}431					Val::Null => continue,432					_ => throw!(RuntimeError(433						"in std.join all items should be arrays".into()434					)),435				};436			}437			Ok(IndexableVal::Arr(out.into()))438		}439	}440}441442#[jrsonnet_macros::builtin]443fn builtin_foldl(s: State, func: FuncVal, arr: ArrValue, init: Any) -> Result<Any> {444	let mut acc = init.0;445	for i in arr.iter(s.clone()) {446		acc = func.evaluate_simple(s.clone(), &[Any(acc), Any(i?)].as_slice())?;447	}448	Ok(Any(acc))449}450451#[jrsonnet_macros::builtin]452fn builtin_foldr(s: State, func: FuncVal, arr: ArrValue, init: Any) -> Result<Any> {453	let mut acc = init.0;454	for i in arr.iter(s.clone()).rev() {455		acc = func.evaluate_simple(s.clone(), &[Any(i?), Any(acc)].as_slice())?;456	}457	Ok(Any(acc))458}459460#[jrsonnet_macros::builtin]461#[allow(non_snake_case)]462fn builtin_sort(s: State, arr: ArrValue, keyF: Option<FuncVal>) -> Result<ArrValue> {463	if arr.len() <= 1 {464		return Ok(arr);465	}466	Ok(ArrValue::Eager(sort::sort(467		s.clone(),468		arr.evaluated(s)?,469		keyF.as_ref(),470	)?))471}472473#[jrsonnet_macros::builtin]474fn builtin_format(s: State, str: IStr, vals: Any) -> Result<String> {475	std_format(s, str, vals.0)476}477478#[jrsonnet_macros::builtin]479fn builtin_range(from: i32, to: i32) -> Result<ArrValue> {480	if to < from {481		return Ok(ArrValue::new_eager());482	}483	Ok(ArrValue::new_range(from, to))484}485486#[jrsonnet_macros::builtin]487fn builtin_char(n: u32) -> Result<char> {488	Ok(std::char::from_u32(n as u32).ok_or(InvalidUnicodeCodepointGot(n as u32))?)489}490491#[jrsonnet_macros::builtin]492fn builtin_encode_utf8(str: IStr) -> Result<Bytes> {493	Ok(Bytes(str.bytes().collect::<Vec<u8>>().into()))494}495496#[jrsonnet_macros::builtin]497fn builtin_decode_utf8(arr: Bytes) -> Result<IStr> {498	Ok(std::str::from_utf8(&arr.0)499		.map_err(|_| RuntimeError("bad utf8".into()))?500		.into())501}502503#[jrsonnet_macros::builtin]504fn builtin_md5(str: IStr) -> Result<String> {505	Ok(format!("{:x}", md5::compute(&str.as_bytes())))506}507508#[jrsonnet_macros::builtin]509fn builtin_trace(s: State, loc: CallLocation, str: IStr, rest: Any) -> Result<Any> {510	eprint!("TRACE:");511	if let Some(loc) = loc.0 {512		let locs = s.map_source_locations(&loc.0, &[loc.1]);513		eprint!(514			" {}:{}",515			loc.0.file_name().unwrap().to_str().unwrap(),516			locs[0].line517		);518	}519	eprintln!(" {}", str);520	Ok(rest) as Result<Any>521}522523#[jrsonnet_macros::builtin]524fn builtin_base64(input: Either![Bytes, IStr]) -> Result<String> {525	use Either2::*;526	Ok(match input {527		A(a) => base64::encode(a.0),528		B(l) => base64::encode(l.bytes().collect::<Vec<_>>()),529	})530}531532#[jrsonnet_macros::builtin]533fn builtin_base64_decode_bytes(input: IStr) -> Result<Bytes> {534	Ok(Bytes(535		base64::decode(&input.as_bytes())536			.map_err(|_| RuntimeError("bad base64".into()))?537			.into(),538	))539}540541#[jrsonnet_macros::builtin]542fn builtin_base64_decode(input: IStr) -> Result<String> {543	let bytes = base64::decode(&input.as_bytes()).map_err(|_| RuntimeError("bad base64".into()))?;544	Ok(String::from_utf8(bytes).map_err(|_| RuntimeError("bad utf8".into()))?)545}546547#[jrsonnet_macros::builtin]548fn builtin_join(s: State, sep: IndexableVal, arr: ArrValue) -> Result<IndexableVal> {549	Ok(match sep {550		IndexableVal::Arr(joiner_items) => {551			let mut out = Vec::new();552553			let mut first = true;554			for item in arr.iter(s.clone()) {555				let item = item?.clone();556				if let Val::Arr(items) = item {557					if !first {558						out.reserve(joiner_items.len());559						// TODO: extend560						for item in joiner_items.iter(s.clone()) {561							out.push(item?);562						}563					}564					first = false;565					out.reserve(items.len());566					for item in items.iter(s.clone()) {567						out.push(item?);568					}569				} else if matches!(item, Val::Null) {570					continue;571				} else {572					throw!(RuntimeError(573						"in std.join all items should be arrays".into()574					));575				}576			}577578			IndexableVal::Arr(out.into())579		}580		IndexableVal::Str(sep) => {581			let mut out = String::new();582583			let mut first = true;584			for item in arr.iter(s) {585				let item = item?.clone();586				if let Val::Str(item) = item {587					if !first {588						out += &sep;589					}590					first = false;591					out += &item;592				} else if matches!(item, Val::Null) {593					continue;594				} else {595					throw!(RuntimeError(596						"in std.join all items should be strings".into()597					));598				}599			}600601			IndexableVal::Str(out.into())602		}603	})604}605606#[jrsonnet_macros::builtin]607fn builtin_escape_string_json(str_: IStr) -> Result<String> {608	Ok(escape_string_json(&str_))609}610611#[jrsonnet_macros::builtin]612fn builtin_manifest_json_ex(613	s: State,614	value: Any,615	indent: IStr,616	newline: Option<IStr>,617	key_val_sep: Option<IStr>,618	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,619) -> Result<String> {620	let newline = newline.as_deref().unwrap_or("\n");621	let key_val_sep = key_val_sep.as_deref().unwrap_or(": ");622	manifest_json_ex(623		s,624		&value.0,625		&ManifestJsonOptions {626			padding: &indent,627			mtype: ManifestType::Std,628			newline,629			key_val_sep,630			#[cfg(feature = "exp-preserve-order")]631			preserve_order: preserve_order.unwrap_or(false),632		},633	)634}635636#[jrsonnet_macros::builtin]637fn builtin_manifest_yaml_doc(638	s: State,639	value: Any,640	indent_array_in_object: Option<bool>,641	quote_keys: Option<bool>,642	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,643) -> Result<String> {644	manifest_yaml_ex(645		s,646		&value.0,647		&ManifestYamlOptions {648			padding: "  ",649			arr_element_padding: if indent_array_in_object.unwrap_or(false) {650				"  "651			} else {652				""653			},654			quote_keys: quote_keys.unwrap_or(true),655			#[cfg(feature = "exp-preserve-order")]656			preserve_order: preserve_order.unwrap_or(false),657		},658	)659}660661#[jrsonnet_macros::builtin]662fn builtin_reverse(value: ArrValue) -> Result<ArrValue> {663	Ok(value.reversed())664}665666#[jrsonnet_macros::builtin]667const fn builtin_id(v: Any) -> Result<Any> {668	Ok(v)669}670671#[jrsonnet_macros::builtin]672fn builtin_str_replace(str: String, from: IStr, to: IStr) -> Result<String> {673	Ok(str.replace(&from as &str, &to as &str))674}675676#[jrsonnet_macros::builtin]677fn builtin_splitlimit(str: IStr, c: IStr, maxsplits: Either![usize, M1]) -> Result<VecVal> {678	use Either2::*;679	Ok(VecVal(Cc::new(match maxsplits {680		A(n) => str681			.splitn(n + 1, &c as &str)682			.map(|s| Val::Str(s.into()))683			.collect(),684		B(_) => str.split(&c as &str).map(|s| Val::Str(s.into())).collect(),685	})))686}687688#[jrsonnet_macros::builtin]689fn builtin_ascii_upper(str: IStr) -> Result<String> {690	Ok(str.to_ascii_uppercase())691}692693#[jrsonnet_macros::builtin]694fn builtin_ascii_lower(str: IStr) -> Result<String> {695	Ok(str.to_ascii_lowercase())696}697698#[jrsonnet_macros::builtin]699fn builtin_member(s: State, arr: IndexableVal, x: Any) -> Result<bool> {700	match arr {701		IndexableVal::Str(str) => {702			let x: IStr = IStr::from_untyped(x.0, s)?;703			Ok(!x.is_empty() && str.contains(&*x))704		}705		IndexableVal::Arr(a) => {706			for item in a.iter(s.clone()) {707				let item = item?;708				if equals(s.clone(), &item, &x.0)? {709					return Ok(true);710				}711			}712			Ok(false)713		}714	}715}716717#[jrsonnet_macros::builtin]718fn builtin_count(s: State, arr: Vec<Any>, v: Any) -> Result<usize> {719	let mut count = 0;720	for item in &arr {721		if equals(s.clone(), &item.0, &v.0)? {722			count += 1;723		}724	}725	Ok(count)726}727728#[jrsonnet_macros::builtin]729fn builtin_any(s: State, arr: ArrValue) -> Result<bool> {730	for v in arr.iter(s.clone()) {731		let v = bool::from_untyped(v?, s.clone())?;732		if v {733			return Ok(true);734		}735	}736	Ok(false)737}738739#[jrsonnet_macros::builtin]740fn builtin_all(s: State, arr: ArrValue) -> Result<bool> {741	for v in arr.iter(s.clone()) {742		let v = bool::from_untyped(v?, s.clone())?;743		if !v {744			return Ok(false);745		}746	}747	Ok(true)748}
after · crates/jrsonnet-evaluator/src/builtin/mod.rs
1// All builtins should return results2#![allow(clippy::unnecessary_wraps)]34use std::collections::HashMap;56use format::{format_arr, format_obj};7use gcmodule::Cc;8use jrsonnet_interner::IStr;9use serde::Deserialize;10use serde_yaml::DeserializingQuirks;1112use crate::{13	builtin::manifest::{manifest_yaml_ex, ManifestYamlOptions},14	error::{Error::*, Result},15	function::{CallLocation, StaticBuiltin},16	operator::evaluate_mod_op,17	throw,18	typed::{Any, BoundedUsize, Bytes, Either2, Either4, PositiveF64, Typed, VecVal, M1},19	val::{equals, primitive_equals, ArrValue, FuncVal, IndexableVal, Slice},20	Either, ObjValue, State, Val,21};2223pub mod stdlib;24pub use stdlib::*;2526use self::manifest::{escape_string_json, manifest_json_ex, ManifestJsonOptions, ManifestType};2728pub mod format;29pub mod manifest;30pub mod sort;3132pub fn std_format(s: State, str: IStr, vals: Val) -> Result<String> {33	s.push(34		CallLocation::native(),35		|| format!("std.format of {}", str),36		|| {37			Ok(match vals {38				Val::Arr(vals) => format_arr(s.clone(), &str, &vals.evaluated(s.clone())?)?,39				Val::Obj(obj) => format_obj(s.clone(), &str, &obj)?,40				o => format_arr(s.clone(), &str, &[o])?,41			})42		},43	)44}4546pub fn std_slice(47	indexable: IndexableVal,48	index: Option<BoundedUsize<0, { i32::MAX as usize }>>,49	end: Option<BoundedUsize<0, { i32::MAX as usize }>>,50	step: Option<BoundedUsize<1, { i32::MAX as usize }>>,51) -> Result<Val> {52	match &indexable {53		IndexableVal::Str(s) => {54			let index = index.as_deref().copied().unwrap_or(0);55			let end = end.as_deref().copied().unwrap_or(usize::MAX);56			let step = step.as_deref().copied().unwrap_or(1);5758			if index >= end {59				return Ok(Val::Str("".into()));60			}6162			Ok(Val::Str(63				(s.chars()64					.skip(index)65					.take(end - index)66					.step_by(step)67					.collect::<String>())68				.into(),69			))70		}71		IndexableVal::Arr(arr) => {72			let index = index.as_deref().copied().unwrap_or(0);73			let end = end.as_deref().copied().unwrap_or(usize::MAX).min(arr.len());74			let step = step.as_deref().copied().unwrap_or(1);7576			if index >= end {77				return Ok(Val::Arr(ArrValue::new_eager()));78			}7980			Ok(Val::Arr(ArrValue::Slice(Box::new(Slice {81				inner: arr.clone(),82				from: index as u32,83				to: end as u32,84				step: step as u32,85			}))))86		}87	}88}8990type BuiltinsType = HashMap<IStr, &'static dyn StaticBuiltin>;9192thread_local! {93	pub static BUILTINS: BuiltinsType = {94		[95			("length".into(), builtin_length::INST),96			("type".into(), builtin_type::INST),97			("makeArray".into(), builtin_make_array::INST),98			("codepoint".into(), builtin_codepoint::INST),99			("objectFieldsEx".into(), builtin_object_fields_ex::INST),100			("objectHasEx".into(), builtin_object_has_ex::INST),101			("slice".into(), builtin_slice::INST),102			("substr".into(), builtin_substr::INST),103			("primitiveEquals".into(), builtin_primitive_equals::INST),104			("equals".into(), builtin_equals::INST),105			("modulo".into(), builtin_modulo::INST),106			("mod".into(), builtin_mod::INST),107			("floor".into(), builtin_floor::INST),108			("ceil".into(), builtin_ceil::INST),109			("log".into(), builtin_log::INST),110			("pow".into(), builtin_pow::INST),111			("sqrt".into(), builtin_sqrt::INST),112			("sin".into(), builtin_sin::INST),113			("cos".into(), builtin_cos::INST),114			("tan".into(), builtin_tan::INST),115			("asin".into(), builtin_asin::INST),116			("acos".into(), builtin_acos::INST),117			("atan".into(), builtin_atan::INST),118			("exp".into(), builtin_exp::INST),119			("mantissa".into(), builtin_mantissa::INST),120			("exponent".into(), builtin_exponent::INST),121			("extVar".into(), builtin_ext_var::INST),122			("native".into(), builtin_native::INST),123			("filter".into(), builtin_filter::INST),124			("map".into(), builtin_map::INST),125			("flatMap".into(), builtin_flatmap::INST),126			("foldl".into(), builtin_foldl::INST),127			("foldr".into(), builtin_foldr::INST),128			("sort".into(), builtin_sort::INST),129			("format".into(), builtin_format::INST),130			("range".into(), builtin_range::INST),131			("char".into(), builtin_char::INST),132			("encodeUTF8".into(), builtin_encode_utf8::INST),133			("decodeUTF8".into(), builtin_decode_utf8::INST),134			("md5".into(), builtin_md5::INST),135			("base64".into(), builtin_base64::INST),136			("base64DecodeBytes".into(), builtin_base64_decode_bytes::INST),137			("base64Decode".into(), builtin_base64_decode::INST),138			("trace".into(), builtin_trace::INST),139			("join".into(), builtin_join::INST),140			("escapeStringJson".into(), builtin_escape_string_json::INST),141			("manifestJsonEx".into(), builtin_manifest_json_ex::INST),142			("manifestYamlDoc".into(), builtin_manifest_yaml_doc::INST),143			("reverse".into(), builtin_reverse::INST),144			("id".into(), builtin_id::INST),145			("strReplace".into(), builtin_str_replace::INST),146			("splitLimit".into(), builtin_splitlimit::INST),147			("parseJson".into(), builtin_parse_json::INST),148			("parseYaml".into(), builtin_parse_yaml::INST),149			("asciiUpper".into(), builtin_ascii_upper::INST),150			("asciiLower".into(), builtin_ascii_lower::INST),151			("member".into(), builtin_member::INST),152			("count".into(), builtin_count::INST),153			("any".into(), builtin_any::INST),154			("all".into(), builtin_all::INST),155		].iter().cloned().collect()156	};157}158159#[jrsonnet_macros::builtin]160fn builtin_length(x: Either![IStr, ArrValue, ObjValue, FuncVal]) -> Result<usize> {161	use Either4::*;162	Ok(match x {163		A(x) => x.chars().count(),164		B(x) => x.len(),165		C(x) => x.len(),166		D(f) => f.args_len(),167	})168}169170#[jrsonnet_macros::builtin]171fn builtin_type(x: Any) -> Result<IStr> {172	Ok(x.0.value_type().name().into())173}174175#[jrsonnet_macros::builtin]176fn builtin_make_array(s: State, sz: usize, func: FuncVal) -> Result<VecVal> {177	let mut out = Vec::with_capacity(sz);178	for i in 0..sz {179		out.push(func.evaluate_simple(s.clone(), &[i as f64].as_slice())?);180	}181	Ok(VecVal(Cc::new(out)))182}183184#[jrsonnet_macros::builtin]185const fn builtin_codepoint(str: char) -> Result<u32> {186	Ok(str as u32)187}188189#[jrsonnet_macros::builtin]190fn builtin_object_fields_ex(191	obj: ObjValue,192	inc_hidden: bool,193	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,194) -> Result<VecVal> {195	#[cfg(feature = "exp-preserve-order")]196	let preserve_order = preserve_order.unwrap_or(false);197	let out = obj.fields_ex(198		inc_hidden,199		#[cfg(feature = "exp-preserve-order")]200		preserve_order,201	);202	Ok(VecVal(Cc::new(203		out.into_iter().map(Val::Str).collect::<Vec<_>>(),204	)))205}206207#[jrsonnet_macros::builtin]208fn builtin_object_has_ex(obj: ObjValue, f: IStr, inc_hidden: bool) -> Result<bool> {209	Ok(obj.has_field_ex(f, inc_hidden))210}211212#[jrsonnet_macros::builtin]213fn builtin_parse_json(st: State, s: IStr) -> Result<Any> {214	use serde_json::Value;215	let value: Value = serde_json::from_str(&s)216		.map_err(|e| RuntimeError(format!("failed to parse json: {}", e).into()))?;217	Ok(Any(Value::into_untyped(value, st)?))218}219220#[jrsonnet_macros::builtin]221fn builtin_parse_yaml(st: State, s: IStr) -> Result<Any> {222	use serde_json::Value;223	let value = serde_yaml::Deserializer::from_str_with_quirks(224		&s,225		DeserializingQuirks { old_octals: true },226	);227	let mut out = vec![];228	for item in value {229		let value = Value::deserialize(item)230			.map_err(|e| RuntimeError(format!("failed to parse yaml: {}", e).into()))?;231		let val = Value::into_untyped(value, st.clone())?;232		out.push(val);233	}234	Ok(Any(if out.is_empty() {235		Val::Null236	} else if out.len() == 1 {237		out.into_iter().next().unwrap()238	} else {239		Val::Arr(out.into())240	}))241}242243#[jrsonnet_macros::builtin]244fn builtin_slice(245	indexable: IndexableVal,246	index: Option<BoundedUsize<0, { i32::MAX as usize }>>,247	end: Option<BoundedUsize<0, { i32::MAX as usize }>>,248	step: Option<BoundedUsize<1, { i32::MAX as usize }>>,249) -> Result<Any> {250	std_slice(indexable, index, end, step).map(Any)251}252253#[jrsonnet_macros::builtin]254fn builtin_substr(str: IStr, from: usize, len: usize) -> Result<String> {255	Ok(str.chars().skip(from as usize).take(len as usize).collect())256}257258#[jrsonnet_macros::builtin]259fn builtin_primitive_equals(a: Any, b: Any) -> Result<bool> {260	primitive_equals(&a.0, &b.0)261}262263#[jrsonnet_macros::builtin]264fn builtin_equals(s: State, a: Any, b: Any) -> Result<bool> {265	equals(s, &a.0, &b.0)266}267268#[jrsonnet_macros::builtin]269fn builtin_modulo(a: f64, b: f64) -> Result<f64> {270	Ok(a % b)271}272273#[jrsonnet_macros::builtin]274fn builtin_mod(s: State, a: Either![f64, IStr], b: Any) -> Result<Any> {275	use Either2::*;276	Ok(Any(evaluate_mod_op(277		s,278		&match a {279			A(v) => Val::Num(v),280			B(s) => Val::Str(s),281		},282		&b.0,283	)?))284}285286#[jrsonnet_macros::builtin]287fn builtin_floor(x: f64) -> Result<f64> {288	Ok(x.floor())289}290291#[jrsonnet_macros::builtin]292fn builtin_ceil(x: f64) -> Result<f64> {293	Ok(x.ceil())294}295296#[jrsonnet_macros::builtin]297fn builtin_log(n: f64) -> Result<f64> {298	Ok(n.ln())299}300301#[jrsonnet_macros::builtin]302fn builtin_pow(x: f64, n: f64) -> Result<f64> {303	Ok(x.powf(n))304}305306#[jrsonnet_macros::builtin]307fn builtin_sqrt(x: PositiveF64) -> Result<f64> {308	Ok(x.0.sqrt())309}310311#[jrsonnet_macros::builtin]312fn builtin_sin(x: f64) -> Result<f64> {313	Ok(x.sin())314}315316#[jrsonnet_macros::builtin]317fn builtin_cos(x: f64) -> Result<f64> {318	Ok(x.cos())319}320321#[jrsonnet_macros::builtin]322fn builtin_tan(x: f64) -> Result<f64> {323	Ok(x.tan())324}325326#[jrsonnet_macros::builtin]327fn builtin_asin(x: f64) -> Result<f64> {328	Ok(x.asin())329}330331#[jrsonnet_macros::builtin]332fn builtin_acos(x: f64) -> Result<f64> {333	Ok(x.acos())334}335336#[jrsonnet_macros::builtin]337fn builtin_atan(x: f64) -> Result<f64> {338	Ok(x.atan())339}340341#[jrsonnet_macros::builtin]342fn builtin_exp(x: f64) -> Result<f64> {343	Ok(x.exp())344}345346fn frexp(s: f64) -> (f64, i16) {347	if 0.0 == s {348		(s, 0)349	} else {350		let lg = s.abs().log2();351		let x = (lg - lg.floor() - 1.0).exp2();352		let exp = lg.floor() + 1.0;353		(s.signum() * x, exp as i16)354	}355}356357#[jrsonnet_macros::builtin]358fn builtin_mantissa(x: f64) -> Result<f64> {359	Ok(frexp(x).0)360}361362#[jrsonnet_macros::builtin]363fn builtin_exponent(x: f64) -> Result<i16> {364	Ok(frexp(x).1)365}366367#[jrsonnet_macros::builtin]368fn builtin_ext_var(s: State, x: IStr) -> Result<Any> {369	Ok(Any(s370		.settings()371		.ext_vars372		.get(&x)373		.cloned()374		.ok_or(UndefinedExternalVariable(x))?))375}376377#[jrsonnet_macros::builtin]378fn builtin_native(s: State, name: IStr) -> Result<Any> {379	Ok(Any(s380		.settings()381		.ext_natives382		.get(&name)383		.cloned()384		.map_or(Val::Null, |v| {385			Val::Func(FuncVal::Builtin(v.clone()))386		})))387}388389#[jrsonnet_macros::builtin]390fn builtin_filter(s: State, func: FuncVal, arr: ArrValue) -> Result<ArrValue> {391	arr.filter(s.clone(), |val| {392		bool::from_untyped(393			func.evaluate_simple(s.clone(), &[Any(val.clone())].as_slice())?,394			s.clone(),395		)396	})397}398399#[jrsonnet_macros::builtin]400fn builtin_map(s: State, func: FuncVal, arr: ArrValue) -> Result<ArrValue> {401	arr.map(s.clone(), |val| {402		func.evaluate_simple(s.clone(), &[Any(val)].as_slice())403	})404}405406#[jrsonnet_macros::builtin]407fn builtin_flatmap(s: State, func: FuncVal, arr: IndexableVal) -> Result<IndexableVal> {408	match arr {409		IndexableVal::Str(str) => {410			let mut out = String::new();411			for c in str.chars() {412				match func.evaluate_simple(s.clone(), &[c.to_string()].as_slice())? {413					Val::Str(o) => out.push_str(&o),414					Val::Null => continue,415					_ => throw!(RuntimeError(416						"in std.join all items should be strings".into()417					)),418				};419			}420			Ok(IndexableVal::Str(out.into()))421		}422		IndexableVal::Arr(a) => {423			let mut out = Vec::new();424			for el in a.iter(s.clone()) {425				let el = el?;426				match func.evaluate_simple(s.clone(), &[Any(el)].as_slice())? {427					Val::Arr(o) => {428						for oe in o.iter(s.clone()) {429							out.push(oe?);430						}431					}432					Val::Null => continue,433					_ => throw!(RuntimeError(434						"in std.join all items should be arrays".into()435					)),436				};437			}438			Ok(IndexableVal::Arr(out.into()))439		}440	}441}442443#[jrsonnet_macros::builtin]444fn builtin_foldl(s: State, func: FuncVal, arr: ArrValue, init: Any) -> Result<Any> {445	let mut acc = init.0;446	for i in arr.iter(s.clone()) {447		acc = func.evaluate_simple(s.clone(), &[Any(acc), Any(i?)].as_slice())?;448	}449	Ok(Any(acc))450}451452#[jrsonnet_macros::builtin]453fn builtin_foldr(s: State, func: FuncVal, arr: ArrValue, init: Any) -> Result<Any> {454	let mut acc = init.0;455	for i in arr.iter(s.clone()).rev() {456		acc = func.evaluate_simple(s.clone(), &[Any(i?), Any(acc)].as_slice())?;457	}458	Ok(Any(acc))459}460461#[jrsonnet_macros::builtin]462#[allow(non_snake_case)]463fn builtin_sort(s: State, arr: ArrValue, keyF: Option<FuncVal>) -> Result<ArrValue> {464	if arr.len() <= 1 {465		return Ok(arr);466	}467	Ok(ArrValue::Eager(sort::sort(468		s.clone(),469		arr.evaluated(s)?,470		keyF.as_ref(),471	)?))472}473474#[jrsonnet_macros::builtin]475fn builtin_format(s: State, str: IStr, vals: Any) -> Result<String> {476	std_format(s, str, vals.0)477}478479#[jrsonnet_macros::builtin]480fn builtin_range(from: i32, to: i32) -> Result<ArrValue> {481	if to < from {482		return Ok(ArrValue::new_eager());483	}484	Ok(ArrValue::new_range(from, to))485}486487#[jrsonnet_macros::builtin]488fn builtin_char(n: u32) -> Result<char> {489	Ok(std::char::from_u32(n as u32).ok_or(InvalidUnicodeCodepointGot(n as u32))?)490}491492#[jrsonnet_macros::builtin]493fn builtin_encode_utf8(str: IStr) -> Result<Bytes> {494	Ok(Bytes(str.bytes().collect::<Vec<u8>>().into()))495}496497#[jrsonnet_macros::builtin]498fn builtin_decode_utf8(arr: Bytes) -> Result<IStr> {499	Ok(std::str::from_utf8(&arr.0)500		.map_err(|_| RuntimeError("bad utf8".into()))?501		.into())502}503504#[jrsonnet_macros::builtin]505fn builtin_md5(str: IStr) -> Result<String> {506	Ok(format!("{:x}", md5::compute(&str.as_bytes())))507}508509#[jrsonnet_macros::builtin]510fn builtin_trace(s: State, loc: CallLocation, str: IStr, rest: Any) -> Result<Any> {511	eprint!("TRACE:");512	if let Some(loc) = loc.0 {513		let locs = s.map_source_locations(&loc.0, &[loc.1]);514		eprint!(515			" {}:{}",516			loc.0.file_name().unwrap().to_str().unwrap(),517			locs[0].line518		);519	}520	eprintln!(" {}", str);521	Ok(rest) as Result<Any>522}523524#[jrsonnet_macros::builtin]525fn builtin_base64(input: Either![Bytes, IStr]) -> Result<String> {526	use Either2::*;527	Ok(match input {528		A(a) => base64::encode(a.0),529		B(l) => base64::encode(l.bytes().collect::<Vec<_>>()),530	})531}532533#[jrsonnet_macros::builtin]534fn builtin_base64_decode_bytes(input: IStr) -> Result<Bytes> {535	Ok(Bytes(536		base64::decode(&input.as_bytes())537			.map_err(|_| RuntimeError("bad base64".into()))?538			.into(),539	))540}541542#[jrsonnet_macros::builtin]543fn builtin_base64_decode(input: IStr) -> Result<String> {544	let bytes = base64::decode(&input.as_bytes()).map_err(|_| RuntimeError("bad base64".into()))?;545	Ok(String::from_utf8(bytes).map_err(|_| RuntimeError("bad utf8".into()))?)546}547548#[jrsonnet_macros::builtin]549fn builtin_join(s: State, sep: IndexableVal, arr: ArrValue) -> Result<IndexableVal> {550	Ok(match sep {551		IndexableVal::Arr(joiner_items) => {552			let mut out = Vec::new();553554			let mut first = true;555			for item in arr.iter(s.clone()) {556				let item = item?.clone();557				if let Val::Arr(items) = item {558					if !first {559						out.reserve(joiner_items.len());560						// TODO: extend561						for item in joiner_items.iter(s.clone()) {562							out.push(item?);563						}564					}565					first = false;566					out.reserve(items.len());567					for item in items.iter(s.clone()) {568						out.push(item?);569					}570				} else if matches!(item, Val::Null) {571					continue;572				} else {573					throw!(RuntimeError(574						"in std.join all items should be arrays".into()575					));576				}577			}578579			IndexableVal::Arr(out.into())580		}581		IndexableVal::Str(sep) => {582			let mut out = String::new();583584			let mut first = true;585			for item in arr.iter(s) {586				let item = item?.clone();587				if let Val::Str(item) = item {588					if !first {589						out += &sep;590					}591					first = false;592					out += &item;593				} else if matches!(item, Val::Null) {594					continue;595				} else {596					throw!(RuntimeError(597						"in std.join all items should be strings".into()598					));599				}600			}601602			IndexableVal::Str(out.into())603		}604	})605}606607#[jrsonnet_macros::builtin]608fn builtin_escape_string_json(str_: IStr) -> Result<String> {609	Ok(escape_string_json(&str_))610}611612#[jrsonnet_macros::builtin]613fn builtin_manifest_json_ex(614	s: State,615	value: Any,616	indent: IStr,617	newline: Option<IStr>,618	key_val_sep: Option<IStr>,619	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,620) -> Result<String> {621	let newline = newline.as_deref().unwrap_or("\n");622	let key_val_sep = key_val_sep.as_deref().unwrap_or(": ");623	manifest_json_ex(624		s,625		&value.0,626		&ManifestJsonOptions {627			padding: &indent,628			mtype: ManifestType::Std,629			newline,630			key_val_sep,631			#[cfg(feature = "exp-preserve-order")]632			preserve_order: preserve_order.unwrap_or(false),633		},634	)635}636637#[jrsonnet_macros::builtin]638fn builtin_manifest_yaml_doc(639	s: State,640	value: Any,641	indent_array_in_object: Option<bool>,642	quote_keys: Option<bool>,643	#[cfg(feature = "exp-preserve-order")] preserve_order: Option<bool>,644) -> Result<String> {645	manifest_yaml_ex(646		s,647		&value.0,648		&ManifestYamlOptions {649			padding: "  ",650			arr_element_padding: if indent_array_in_object.unwrap_or(false) {651				"  "652			} else {653				""654			},655			quote_keys: quote_keys.unwrap_or(true),656			#[cfg(feature = "exp-preserve-order")]657			preserve_order: preserve_order.unwrap_or(false),658		},659	)660}661662#[jrsonnet_macros::builtin]663fn builtin_reverse(value: ArrValue) -> Result<ArrValue> {664	Ok(value.reversed())665}666667#[jrsonnet_macros::builtin]668const fn builtin_id(v: Any) -> Result<Any> {669	Ok(v)670}671672#[jrsonnet_macros::builtin]673fn builtin_str_replace(str: String, from: IStr, to: IStr) -> Result<String> {674	Ok(str.replace(&from as &str, &to as &str))675}676677#[jrsonnet_macros::builtin]678fn builtin_splitlimit(str: IStr, c: IStr, maxsplits: Either![usize, M1]) -> Result<VecVal> {679	use Either2::*;680	Ok(VecVal(Cc::new(match maxsplits {681		A(n) => str682			.splitn(n + 1, &c as &str)683			.map(|s| Val::Str(s.into()))684			.collect(),685		B(_) => str.split(&c as &str).map(|s| Val::Str(s.into())).collect(),686	})))687}688689#[jrsonnet_macros::builtin]690fn builtin_ascii_upper(str: IStr) -> Result<String> {691	Ok(str.to_ascii_uppercase())692}693694#[jrsonnet_macros::builtin]695fn builtin_ascii_lower(str: IStr) -> Result<String> {696	Ok(str.to_ascii_lowercase())697}698699#[jrsonnet_macros::builtin]700fn builtin_member(s: State, arr: IndexableVal, x: Any) -> Result<bool> {701	match arr {702		IndexableVal::Str(str) => {703			let x: IStr = IStr::from_untyped(x.0, s)?;704			Ok(!x.is_empty() && str.contains(&*x))705		}706		IndexableVal::Arr(a) => {707			for item in a.iter(s.clone()) {708				let item = item?;709				if equals(s.clone(), &item, &x.0)? {710					return Ok(true);711				}712			}713			Ok(false)714		}715	}716}717718#[jrsonnet_macros::builtin]719fn builtin_count(s: State, arr: Vec<Any>, v: Any) -> Result<usize> {720	let mut count = 0;721	for item in &arr {722		if equals(s.clone(), &item.0, &v.0)? {723			count += 1;724		}725	}726	Ok(count)727}728729#[jrsonnet_macros::builtin]730fn builtin_any(s: State, arr: ArrValue) -> Result<bool> {731	for v in arr.iter(s.clone()) {732		let v = bool::from_untyped(v?, s.clone())?;733		if v {734			return Ok(true);735		}736	}737	Ok(false)738}739740#[jrsonnet_macros::builtin]741fn builtin_all(s: State, arr: ArrValue) -> Result<bool> {742	for v in arr.iter(s.clone()) {743		let v = bool::from_untyped(v?, s.clone())?;744		if !v {745			return Ok(false);746		}747	}748	Ok(true)749}
modifiedcrates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -649,608 +649,3 @@
 	assert!(weak_ptr_eq(aw1, aw2));
 	assert!(!weak_ptr_eq(aw3, bw));
 }
-
-#[cfg(test)]
-pub mod tests {
-	use std::{
-		path::{Path, PathBuf},
-		rc::Rc,
-	};
-
-	use gcmodule::{Cc, Trace};
-	use jrsonnet_parser::*;
-
-	use super::Val;
-	use crate::{
-		error::Error::*,
-		function::{BuiltinParam, CallLocation},
-		gc::TraceBox,
-		native::NativeCallbackHandler,
-		val::primitive_equals,
-		State,
-	};
-
-	#[test]
-	#[should_panic]
-	fn eval_state_stacktrace() {
-		let state = State::default();
-		state
-			.push(
-				CallLocation::new(&ExprLocation(PathBuf::from("test1.jsonnet").into(), 10, 20)),
-				|| "outer".to_owned(),
-				|| {
-					state.push(
-						CallLocation::new(&ExprLocation(
-							PathBuf::from("test2.jsonnet").into(),
-							30,
-							40,
-						)),
-						|| "inner".to_owned(),
-						|| Err(RuntimeError("".into()).into()),
-					)?;
-					Ok(Val::Null)
-				},
-			)
-			.unwrap();
-	}
-
-	#[test]
-	fn eval_state_standard() {
-		let state = State::default();
-		state.with_stdlib();
-		assert!(primitive_equals(
-			&state
-				.evaluate_snippet_raw(
-					PathBuf::from("raw.jsonnet").into(),
-					r#"std.assertEqual(std.base64("test"), "dGVzdA==")"#.into()
-				)
-				.unwrap(),
-			&Val::Bool(true),
-		)
-		.unwrap());
-	}
-
-	macro_rules! eval {
-		($str: expr) => {{
-			let evaluator = State::default();
-			evaluator.with_stdlib();
-			evaluator
-				.evaluate_snippet_raw(PathBuf::from("raw.jsonnet").into(), $str.into())
-				.unwrap()
-		}};
-	}
-	macro_rules! eval_json {
-		($str: expr) => {{
-			let evaluator = State::default();
-			evaluator.with_stdlib();
-			evaluator
-				.evaluate_snippet_raw(PathBuf::from("raw.jsonnet").into(), $str.into())
-				.unwrap()
-				.to_json(0)
-				.unwrap()
-				.replace("\n", "")
-		}};
-	}
-
-	/// Asserts given code returns `true`
-	macro_rules! assert_eval {
-		($str: expr) => {
-			assert!(primitive_equals(&eval!($str), &Val::Bool(true)).unwrap())
-		};
-	}
-
-	/// Asserts given code returns `false`
-	macro_rules! assert_eval_neg {
-		($str: expr) => {
-			assert!(primitive_equals(&eval!($str), &Val::Bool(false)).unwrap())
-		};
-	}
-	macro_rules! assert_json {
-		($str: expr, $out: expr) => {
-			assert_eq!(eval_json!($str), $out.replace("\t", ""))
-		};
-	}
-
-	/// Sanity checking, before trusting to another tests
-	#[test]
-	fn equality_operator() {
-		assert_eval!("2 == 2");
-		assert_eval_neg!("2 != 2");
-		assert_eval!("2 != 3");
-		assert_eval_neg!("2 == 3");
-		assert_eval!("'Hello' == 'Hello'");
-		assert_eval_neg!("'Hello' != 'Hello'");
-		assert_eval!("'Hello' != 'World'");
-		assert_eval_neg!("'Hello' == 'World'");
-	}
-
-	#[test]
-	fn math_evaluation() {
-		assert_eval!("2 + 2 * 2 == 6");
-		assert_eval!("3 + (2 + 2 * 2) == 9");
-	}
-
-	#[test]
-	fn string_concat() {
-		assert_eval!("'Hello' + 'World' == 'HelloWorld'");
-		assert_eval!("'Hello' * 3 == 'HelloHelloHello'");
-		assert_eval!("'Hello' + 'World' * 3 == 'HelloWorldWorldWorld'");
-	}
-
-	#[test]
-	fn faster_join() {
-		assert_eval!("std.join([0,0], [[1,2],[3,4],[5,6]]) == [1,2,0,0,3,4,0,0,5,6]");
-		assert_eval!("std.join(',', ['1','2','3','4']) == '1,2,3,4'");
-	}
-
-	#[test]
-	fn function_contexts() {
-		assert_eval!(
-			r#"
-				local k = {
-					t(name = self.h): [self.h, name],
-					h: 3,
-				};
-				local f = {
-					t: k.t(),
-					h: 4,
-				};
-				f.t[0] == f.t[1]
-			"#
-		);
-	}
-
-	#[test]
-	fn local() {
-		assert_eval!("local a = 2; local b = 3; a + b == 5");
-		assert_eval!("local a = 1, b = a + 1; a + b == 3");
-		assert_eval!("local a = 1; local a = 2; a == 2");
-	}
-
-	#[test]
-	fn object_lazyness() {
-		assert_json!("local a = {a:error 'test'}; {}", r#"{}"#);
-	}
-
-	#[test]
-	fn object_inheritance() {
-		assert_json!("{a: self.b} + {b:3}", r#"{"a": 3,"b": 3}"#);
-	}
-
-	#[test]
-	fn object_assertion_success() {
-		eval!("{assert \"a\" in self} + {a:2}");
-	}
-
-	#[test]
-	fn object_assertion_error() {
-		eval!("{assert \"a\" in self}");
-	}
-
-	#[test]
-	fn lazy_args() {
-		eval!("local test(a) = 2; test(error '3')");
-	}
-
-	#[test]
-	#[should_panic]
-	fn tailstrict_args() {
-		eval!("local test(a) = 2; test(error '3') tailstrict");
-	}
-
-	#[test]
-	#[should_panic]
-	fn no_binding_error() {
-		eval!("a");
-	}
-
-	#[test]
-	fn test_object() {
-		assert_json!("{a:2}", r#"{"a": 2}"#);
-		assert_json!("{a:2+2}", r#"{"a": 4}"#);
-		assert_json!("{a:2}+{b:2}", r#"{"a": 2,"b": 2}"#);
-		assert_json!("{b:3}+{b:2}", r#"{"b": 2}"#);
-		assert_json!("{b:3}+{b+:2}", r#"{"b": 5}"#);
-		assert_json!("local test='a'; {[test]:2}", r#"{"a": 2}"#);
-		assert_json!(
-			r#"
-				{
-					name: "Alice",
-					welcome: "Hello " + self.name + "!",
-				}
-			"#,
-			r#"{"name": "Alice","welcome": "Hello Alice!"}"#
-		);
-		assert_json!(
-			r#"
-				{
-					name: "Alice",
-					welcome: "Hello " + self.name + "!",
-				} + {
-					name: "Bob"
-				}
-			"#,
-			r#"{"name": "Bob","welcome": "Hello Bob!"}"#
-		);
-	}
-
-	#[test]
-	fn functions() {
-		assert_json!(r#"local a = function(b, c = 2) b + c; a(2)"#, "4");
-		assert_json!(
-			r#"local a = function(b, c = "Dear") b + c + d, d = "World"; a("Hello")"#,
-			r#""HelloDearWorld""#
-		);
-	}
-
-	#[test]
-	fn local_methods() {
-		assert_json!(r#"local a(b, c = 2) = b + c; a(2)"#, "4");
-		assert_json!(
-			r#"local a(b, c = "Dear") = b + c + d, d = "World"; a("Hello")"#,
-			r#""HelloDearWorld""#
-		);
-	}
-
-	#[test]
-	fn object_locals() {
-		assert_json!(r#"{local a = 3, b: a}"#, r#"{"b": 3}"#);
-		assert_json!(r#"{local a = 3, local c = a, b: c}"#, r#"{"b": 3}"#);
-		assert_json!(
-			r#"{local a = function (b) {[b]:4}, test: a("test")}"#,
-			r#"{"test": {"test": 4}}"#
-		);
-	}
-
-	#[test]
-	fn object_comp() {
-		assert_json!(
-			r#"{local t = "a", ["h"+i+"_"+z]: if "h"+(i-1)+"_"+z in self then t+1 else 0+t for i in [1,2,3] for z in [2,3,4] if z != i}"#,
-			"{\"h1_2\": \"0a\",\"h1_3\": \"0a\",\"h1_4\": \"0a\",\"h2_3\": \"a1\",\"h2_4\": \"a1\",\"h3_2\": \"0a\",\"h3_4\": \"a1\"}"
-		)
-	}
-
-	#[test]
-	fn direct_self() {
-		println!(
-			"{:#?}",
-			eval!(
-				r#"
-					{
-						local me = self,
-						a: 3,
-						b(): me.a,
-					}
-				"#
-			)
-		);
-	}
-
-	#[test]
-	fn indirect_self() {
-		// `self` assigned to `me` was lost when being
-		// referenced from field
-		eval!(
-			r#"{
-				local me = self,
-				a: 3,
-				b: me.a,
-			}.b"#
-		);
-	}
-
-	// We can't trust other tests (And official jsonnet testsuite), if assert is not working correctly
-	#[test]
-	fn std_assert_ok() {
-		eval!("std.assertEqual(4.5 << 2, 16)");
-	}
-
-	#[test]
-	#[should_panic]
-	fn std_assert_failure() {
-		eval!("std.assertEqual(4.5 << 2, 15)");
-	}
-
-	#[test]
-	fn string_is_string() {
-		assert!(primitive_equals(
-			&eval!("local arr = 'hello'; (!std.isArray(arr)) && (!std.isString(arr))"),
-			&Val::Bool(false),
-		)
-		.unwrap());
-	}
-
-	#[test]
-	fn base64_works() {
-		assert_json!(r#"std.base64("test")"#, r#""dGVzdA==""#);
-	}
-
-	#[test]
-	fn utf8_chars() {
-		assert_json!(
-			r#"local c="😎";{c:std.codepoint(c),l:std.length(c)}"#,
-			r#"{"c": 128526,"l": 1}"#
-		)
-	}
-
-	#[test]
-	fn json() {
-		assert_json!(
-			r#"std.manifestJsonEx({a:3, b:4, c:6},"")"#,
-			r#""{\n\"a\": 3,\n\"b\": 4,\n\"c\": 6\n}""#
-		);
-	}
-
-	#[test]
-	fn json_minified() {
-		assert_json!(
-			r#"std.manifestJsonMinified({a:3, b:4, c:6})"#,
-			r#""{\"a\":3,\"b\":4,\"c\":6}""#
-		);
-	}
-
-	#[test]
-	fn parse_json() {
-		assert_json!(
-			r#"std.parseJson('{"a": -1,"b": 1,"c": 3.141,"d": []}')"#,
-			r#"{"a": -1,"b": 1,"c": 3.141,"d": []}"#
-		);
-	}
-
-	#[test]
-	fn test() {
-		assert_json!(
-			r#"[[a, b] for a in [1,2,3] for b in [4,5,6]]"#,
-			"[[1,4],[1,5],[1,6],[2,4],[2,5],[2,6],[3,4],[3,5],[3,6]]"
-		);
-	}
-
-	#[test]
-	fn sjsonnet() {
-		eval!(
-			r#"
-			local x0 = {k: 1};
-			local x1 = {k: x0.k + x0.k};
-			local x2 = {k: x1.k + x1.k};
-			local x3 = {k: x2.k + x2.k};
-			local x4 = {k: x3.k + x3.k};
-			local x5 = {k: x4.k + x4.k};
-			local x6 = {k: x5.k + x5.k};
-			local x7 = {k: x6.k + x6.k};
-			local x8 = {k: x7.k + x7.k};
-			local x9 = {k: x8.k + x8.k};
-			local x10 = {k: x9.k + x9.k};
-			local x11 = {k: x10.k + x10.k};
-			local x12 = {k: x11.k + x11.k};
-			local x13 = {k: x12.k + x12.k};
-			local x14 = {k: x13.k + x13.k};
-			local x15 = {k: x14.k + x14.k};
-			local x16 = {k: x15.k + x15.k};
-			local x17 = {k: x16.k + x16.k};
-			local x18 = {k: x17.k + x17.k};
-			local x19 = {k: x18.k + x18.k};
-			local x20 = {k: x19.k + x19.k};
-			local x21 = {k: x20.k + x20.k};
-			x21.k
-		"#
-		);
-	}
-
-	// This test is commented out by default, because of huge compilation slowdown
-	// #[bench]
-	// fn bench_codegen(b: &mut Bencher) {
-	// 	b.iter(|| {
-	// 		#[allow(clippy::all)]
-	// 		let stdlib = {
-	// 			use jrsonnet_parser::*;
-	// 			include!(concat!(env!("OUT_DIR"), "/stdlib.rs"))
-	// 		};
-	// 		stdlib
-	// 	})
-	// }
-
-	/*
-	#[bench]
-	fn bench_serialize(b: &mut Bencher) {
-		b.iter(|| {
-			bincode::deserialize::<jrsonnet_parser::LocExpr>(include_bytes!(concat!(
-				env!("OUT_DIR"),
-				"/stdlib.bincode"
-			)))
-			.expect("deserialize stdlib")
-		})
-	}
-
-	#[bench]
-	fn bench_parse(b: &mut Bencher) {
-		b.iter(|| {
-			jrsonnet_parser::parse(
-				jrsonnet_stdlib::STDLIB_STR,
-				&jrsonnet_parser::ParserSettings {
-					loc_data: true,
-					file_name: Rc::new(PathBuf::from("std.jsonnet")),
-				},
-			)
-		})
-	}
-	*/
-
-	#[test]
-	fn equality() {
-		println!(
-			"{:?}",
-			jrsonnet_parser::parse(
-				"{ x: 1, y: 2 } == { x: 1, y: 2 }",
-				&ParserSettings {
-					file_name: PathBuf::from("equality").into(),
-				}
-			)
-		);
-		assert_eval!("{ x: 1, y: 2 } == { x: 1, y: 2 }")
-	}
-
-	#[test]
-	fn native_ext() -> crate::error::Result<()> {
-		use super::native::NativeCallback;
-		let evaluator = State::default();
-
-		evaluator.with_stdlib();
-
-		#[derive(Trace)]
-		struct NativeAdd;
-		impl NativeCallbackHandler for NativeAdd {
-			fn call(&self, from: Option<Rc<Path>>, args: &[Val]) -> crate::error::Result<Val> {
-				assert_eq!(
-					&from.unwrap() as &Path,
-					&PathBuf::from("native_caller.jsonnet")
-				);
-				match (&args[0], &args[1]) {
-					(Val::Num(a), Val::Num(b)) => Ok(Val::Num(a + b)),
-					(_, _) => unreachable!(),
-				}
-			}
-		}
-		evaluator.settings_mut().ext_natives.insert(
-			"native_add".into(),
-			#[allow(deprecated)]
-			Cc::new(TraceBox(Box::new(NativeCallback::new(
-				vec![
-					BuiltinParam {
-						name: "a".into(),
-						has_default: false,
-					},
-					BuiltinParam {
-						name: "b".into(),
-						has_default: false,
-					},
-				],
-				TraceBox(Box::new(NativeAdd)),
-			)))),
-		);
-		dbg!(evaluator.settings().ext_natives.keys().collect::<Vec<_>>());
-		evaluator.evaluate_snippet_raw(
-			PathBuf::from("native_caller.jsonnet").into(),
-			"std.assertEqual(std.native(\"native_add\")(1, 2), 3)".into(),
-		)?;
-		dbg!(evaluator.settings().ext_natives.keys().collect::<Vec<_>>());
-		Ok(())
-	}
-
-	#[test]
-	fn constant_intrinsic() -> crate::error::Result<()> {
-		assert_eval!(
-			"local std2 = std; local std = std2 { primitiveEquals(a, b):: false }; 1 == 1"
-		);
-		Ok(())
-	}
-
-	#[test]
-	fn standalone_super() -> crate::error::Result<()> {
-		assert_eval!(
-			r#"
-			local obj = {
-				a: 1,
-				b: 2,
-				c: 3,
-			};
-			local test = obj + {
-				fields: std.objectFields(super),
-				d: 5,
-			};
-			test.fields == ['a', 'b', 'c']
-		"#
-		);
-		Ok(())
-	}
-
-	#[test]
-	fn comp_self() -> crate::error::Result<()> {
-		assert_eval!(
-			r#"
-			std.objectFields({
-				a:{
-					[name]: name for name in std.objectFields(self)
-				},
-				b: 2,
-				c: 3,
-			}.a) == ['a', 'b', 'c']
-			"#
-		);
-
-		Ok(())
-	}
-
-	struct TestImportResolver(Vec<u8>);
-	impl crate::import::ImportResolver for TestImportResolver {
-		fn resolve_file(&self, _: &Path, _: &Path) -> crate::error::Result<Rc<Path>> {
-			Ok(PathBuf::from("/test").into())
-		}
-
-		fn load_file_contents(&self, _: &Path) -> crate::error::Result<Vec<u8>> {
-			Ok(self.0.clone())
-		}
-
-		unsafe fn as_any(&self) -> &dyn std::any::Any {
-			panic!()
-		}
-
-		fn load_file_bin(&self, _resolved: &Path) -> crate::error::Result<Rc<[u8]>> {
-			panic!()
-		}
-	}
-
-	#[test]
-	fn issue_23() {
-		let state = State::default();
-		state.set_import_resolver(Box::new(TestImportResolver(r#"import "/test""#.into())));
-		let _ = state.evaluate_file_raw(&PathBuf::from("/test"));
-	}
-
-	#[test]
-	fn issue_40() {
-		let state = State::default();
-		state.with_stdlib();
-
-		let error = state
-			.evaluate_snippet_raw(
-				PathBuf::from("issue40.jsonnet").into(),
-				r#"
-				local conf = {
-					n: ""
-				};
-
-				local result = conf + {
-					assert std.isNumber(self.n): "is number"
-				};
-
-				std.manifestJsonEx(result, "")
-			"#
-				.into(),
-			)
-			.unwrap_err();
-		assert_eq!(error.error().to_string(), "assert failed: is number");
-	}
-
-	#[test]
-	fn test_ascii_upper_lower() {
-		assert_eval!(r#"std.assertEqual(std.asciiUpper("aBc😀"), "ABC😀")"#);
-		assert_eval!(r#"std.assertEqual(std.asciiLower("aBc😀"), "abc😀")"#);
-	}
-
-	#[test]
-	fn test_member() {
-		assert_eval!(r#"!std.member("", "")"#);
-		assert_eval!(r#"std.member("abc", "a")"#);
-		assert_eval!(r#"!std.member("abc", "d")"#);
-		assert_eval!(r#"!std.member([], "")"#);
-		assert_eval!(r#"std.member(["a", "b", "c"], "a")"#);
-		assert_eval!(r#"!std.member(["a", "b", "c"], "d")"#);
-	}
-
-	#[test]
-	fn test_count() {
-		assert_eval!(r#"std.assertEqual(std.count([], ""), 0)"#);
-		assert_eval!(r#"std.assertEqual(std.count(["a", "b", "a"], "d"), 0)"#);
-		assert_eval!(r#"std.assertEqual(std.count(["a", "b", "a"], "a"), 2)"#);
-	}
-}
modifiedcrates/jrsonnet-evaluator/tests/common.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/tests/common.rs
+++ b/crates/jrsonnet-evaluator/tests/common.rs
@@ -1,3 +1,8 @@
+use jrsonnet_evaluator::{
+	error::Result, function::builtin, throw_runtime, val::FuncVal, LazyVal, ObjValueBuilder, State,
+	Val,
+};
+
 #[macro_export]
 macro_rules! ensure_eq {
 	($a:expr, $b:expr $(,)?) => {{
@@ -32,3 +37,33 @@
 		}
 	}};
 }
+
+#[builtin]
+fn assert_throw(s: State, lazy: LazyVal, message: String) -> Result<bool> {
+	match lazy.evaluate(s) {
+		Ok(_) => {
+			throw_runtime!("expected argument to throw on evaluation, but it returned instead")
+		}
+		Err(e) => {
+			let error = format!("{}", e.error());
+			ensure_eq!(message, error);
+		}
+	}
+	Ok(true)
+}
+
+#[allow(dead_code)]
+pub fn with_test(s: &State) {
+	let mut bobj = ObjValueBuilder::new();
+	bobj.member("assertThrow".into())
+		.hide()
+		.value(
+			s.clone(),
+			Val::Func(FuncVal::StaticBuiltin(assert_throw::INST)),
+		)
+		.expect("no error");
+
+	s.settings_mut()
+		.globals
+		.insert("test".into(), Val::Obj(bobj.build()));
+}
addedcrates/jrsonnet-evaluator/tests/golden.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden.rs
@@ -0,0 +1,64 @@
+use std::{
+	fs, io,
+	path::{Path, PathBuf},
+};
+
+use jrsonnet_evaluator::{
+	trace::{CompactFormat, PathResolver},
+	FileImportResolver, State,
+};
+
+mod common;
+
+fn run(root: &Path, file: &Path) -> String {
+	let s = State::default();
+	s.set_trace_format(Box::new(CompactFormat {
+		resolver: PathResolver::Relative(root.to_owned()),
+		padding: 3,
+	}));
+	s.with_stdlib();
+	common::with_test(&s);
+	s.set_import_resolver(Box::new(FileImportResolver::default()));
+
+	let v = match s.evaluate_file_raw(file) {
+		Ok(v) => v,
+		Err(e) => return s.stringify_err(&e),
+	};
+	match v.to_json(s.clone(), 3) {
+		Ok(v) => v.to_string(),
+		Err(e) => s.stringify_err(&e),
+	}
+}
+
+#[test]
+fn test() -> io::Result<()> {
+	let mut root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+	root.push("tests/golden");
+
+	for entry in fs::read_dir(&root)? {
+		let entry = entry?;
+		if !entry.path().extension().map_or(false, |e| e == "jsonnet") {
+			continue;
+		}
+
+		let result = run(&root, &entry.path());
+
+		let mut golden_path = entry.path();
+		golden_path.set_extension("jsonnet.golden");
+
+		if !golden_path.exists() {
+			fs::write(golden_path, &result)?;
+		} else {
+			let golden = fs::read_to_string(golden_path)?;
+
+			assert_eq!(
+				result,
+				golden,
+				"golden didn't match for {}",
+				entry.path().display()
+			)
+		}
+	}
+
+	Ok(())
+}
addedcrates/jrsonnet-evaluator/tests/golden/array_comp.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/array_comp.jsonnet
@@ -0,0 +1 @@
+[[a, b] for a in [1, 2, 3] for b in [4, 5, 6]]
addedcrates/jrsonnet-evaluator/tests/golden/array_comp.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/array_comp.jsonnet.golden
@@ -0,0 +1,38 @@
+[
+   [
+      1,
+      4
+   ],
+   [
+      1,
+      5
+   ],
+   [
+      1,
+      6
+   ],
+   [
+      2,
+      4
+   ],
+   [
+      2,
+      5
+   ],
+   [
+      2,
+      6
+   ],
+   [
+      3,
+      4
+   ],
+   [
+      3,
+      5
+   ],
+   [
+      3,
+      6
+   ]
+]
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/builtin_json.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_json.jsonnet
@@ -0,0 +1 @@
+std.manifestJsonEx({ a: 3, b: 4, c: 6 }, '')
addedcrates/jrsonnet-evaluator/tests/golden/builtin_json.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_json.jsonnet.golden
@@ -0,0 +1 @@
+"{\n\"a\": 3,\n\"b\": 4,\n\"c\": 6\n}"
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/builtin_json_minified.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_json_minified.jsonnet
@@ -0,0 +1 @@
+std.manifestJsonMinified({ a: 3, b: 4, c: 6 })
addedcrates/jrsonnet-evaluator/tests/golden/builtin_json_minified.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_json_minified.jsonnet.golden
@@ -0,0 +1 @@
+"{\"a\":3,\"b\":4,\"c\":6}"
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/builtin_parseJson.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_parseJson.jsonnet
@@ -0,0 +1 @@
+std.parseJson('{"a": -1,"b": 1,"c": 3.141,"d": []}')
addedcrates/jrsonnet-evaluator/tests/golden/builtin_parseJson.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/builtin_parseJson.jsonnet.golden
@@ -0,0 +1,6 @@
+{
+   "a": -1,
+   "b": 1,
+   "c": 3.141,
+   "d": [ ]
+}
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/issue23.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/issue23.jsonnet
@@ -0,0 +1 @@
+import 'issue23.jsonnet'
addedcrates/jrsonnet-evaluator/tests/golden/issue23.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/issue23.jsonnet.golden
@@ -0,0 +1,202 @@
+stack overflow, try to reduce recursion, or set --max-stack to bigger value
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
+   issue23.jsonnet:1:1-26: import "issue23.jsonnet"
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/issue40.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/issue40.jsonnet
@@ -0,0 +1,9 @@
+local conf = {
+  n: '',
+};
+
+local result = conf {
+  assert std.isNumber(self.n) : 'is number',
+};
+
+std.manifestJsonEx(result, '')
addedcrates/jrsonnet-evaluator/tests/golden/issue40.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/issue40.jsonnet.golden
@@ -0,0 +1,3 @@
+assert failed: is number
+   issue40.jsonnet:6:10-31: assertion failure
+   issue40.jsonnet:9:1-32:  function <builtin_manifest_json_ex> call
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/missing_binding.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/missing_binding.jsonnet
@@ -0,0 +1 @@
+a
addedcrates/jrsonnet-evaluator/tests/golden/missing_binding.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/missing_binding.jsonnet.golden
@@ -0,0 +1,2 @@
+variable is not defined: a
+   missing_binding.jsonnet:1:1-3: variable <a> access
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/object_comp.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/object_comp.jsonnet
@@ -0,0 +1 @@
+{ local t = 'a', ['h' + i + '_' + z]: if 'h' + (i - 1) + '_' + z in self then t + 1 else 0 + t for i in [1, 2, 3] for z in [2, 3, 4] if z != i }
addedcrates/jrsonnet-evaluator/tests/golden/object_comp.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/object_comp.jsonnet.golden
@@ -0,0 +1,9 @@
+{
+   "h1_2": "0a",
+   "h1_3": "0a",
+   "h1_4": "0a",
+   "h2_3": "a1",
+   "h2_4": "a1",
+   "h3_2": "0a",
+   "h3_4": "a1"
+}
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/golden/test_assertThrow.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/test_assertThrow.jsonnet
@@ -0,0 +1,2 @@
+// Test that test.assertThrow will return error, if body is not errored
+test.assertThrow(1, '1')
addedcrates/jrsonnet-evaluator/tests/golden/test_assertThrow.jsonnet.goldendiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/golden/test_assertThrow.jsonnet.golden
@@ -0,0 +1,2 @@
+runtime error: expected argument to throw on evaluation, but it returned instead
+   test_assertThrow.jsonnet:2:1-26: function <assert_throw> call
\ No newline at end of file
addedcrates/jrsonnet-evaluator/tests/suite.rsdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite.rs
@@ -0,0 +1,46 @@
+use std::{
+	fs, io,
+	path::{Path, PathBuf},
+};
+
+use jrsonnet_evaluator::{
+	trace::{CompactFormat, PathResolver},
+	FileImportResolver, State, Val,
+};
+
+mod common;
+
+fn run(root: &Path, file: &Path) {
+	let s = State::default();
+	s.set_trace_format(Box::new(CompactFormat {
+		resolver: PathResolver::Relative(root.to_owned()),
+		padding: 3,
+	}));
+	s.with_stdlib();
+	common::with_test(&s);
+	s.set_import_resolver(Box::new(FileImportResolver::default()));
+
+	match s.evaluate_file_raw(file) {
+		Ok(Val::Bool(true)) => {}
+		Ok(Val::Bool(false)) => panic!("test {} returned false", file.display()),
+		Ok(_) => panic!("test {} returned wrong type as result", file.display()),
+		Err(e) => panic!("test {} failed:\n{}", file.display(), s.stringify_err(&e)),
+	};
+}
+
+#[test]
+fn test() -> io::Result<()> {
+	let mut root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
+	root.push("tests/suite");
+
+	for entry in fs::read_dir(&root)? {
+		let entry = entry?;
+		if !entry.path().extension().map_or(false, |e| e == "jsonnet") {
+			continue;
+		}
+
+		run(&root, &entry.path());
+	}
+
+	Ok(())
+}
addedcrates/jrsonnet-evaluator/tests/suite/builtin_ascii.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_ascii.jsonnet
@@ -0,0 +1,3 @@
+std.assertEqual(std.asciiUpper('aBc😀'), 'ABC😀') &&
+std.assertEqual(std.asciiLower('aBc😀'), 'abc😀') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/builtin_base64.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_base64.jsonnet
@@ -0,0 +1,2 @@
+std.assertEqual(std.base64('test'), 'dGVzdA==') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/builtin_chars.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_chars.jsonnet
@@ -0,0 +1,3 @@
+local c = '😎';
+std.assertEqual({ c: std.codepoint(c), l: std.length(c) }, { c: 128526, l: 1 }) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/builtin_constant.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_constant.jsonnet
@@ -0,0 +1,3 @@
+local std2 = std; local std = std2 { primitiveEquals(a, b):: false };
+// In jsonnet, this expression was failing because of being desugared to std.primitiveEquals(1, 1)
+std.assertEqual(1 == 1, true)
addedcrates/jrsonnet-evaluator/tests/suite/builtin_count.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_count.jsonnet
@@ -0,0 +1,4 @@
+std.assertEqual(std.count([], ''), 0) &&
+std.assertEqual(std.count(['a', 'b', 'a'], 'd'), 0) &&
+std.assertEqual(std.count(['a', 'b', 'a'], 'a'), 2) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/builtin_join.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_join.jsonnet
@@ -0,0 +1,4 @@
+std.assertEqual(std.join([0, 0], [[1, 2], [3, 4], [5, 6]]), [1, 2, 0, 0, 3, 4, 0, 0, 5, 6]) &&
+std.assertEqual(std.join(',', ['1', '2', '3', '4']), '1,2,3,4') &&
+std.assertEqual(std.join(',', ['1', null, '2', null, '3']), '1,2,3') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/builtin_member.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/builtin_member.jsonnet
@@ -0,0 +1,7 @@
+!std.member('', '') &&
+std.member('abc', 'a') &&
+!std.member('abc', 'd') &&
+!std.member([], '') &&
+std.member(['a', 'b', 'c'], 'a') &&
+!std.member(['a', 'b', 'c'], 'd') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/function_args.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/function_args.jsonnet
@@ -0,0 +1,3 @@
+std.assertEqual(local a = function(b, c=2) b + c; a(2), 4) &&
+std.assertEqual(local a = function(b, c='Dear') b + c + d, d = 'World'; a('Hello'), 'HelloDearWorld') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/function_context.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/function_context.jsonnet
@@ -0,0 +1,10 @@
+local k = {
+  t(name=self.h): [self.h, name],
+  h: 3,
+};
+local f = {
+  t: k.t(),
+  h: 4,
+};
+std.assertEqual(f.t[0], f.t[1]) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/function_lazy_args.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/function_lazy_args.jsonnet
@@ -0,0 +1,5 @@
+local fun(a) = 2;
+std.assertEqual(fun(error '3'), 2) &&
+// But in tailstrict mode arguments are evaluated eagerly
+test.assertThrow(fun(error '3') tailstrict, 'runtime error: 3') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/local.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/local.jsonnet
@@ -0,0 +1,4 @@
+std.assertEqual(local a = 2; local b = 3; a + b, 5) &&
+std.assertEqual(local a = 1, b = a + 1; a + b, 3) &&
+std.assertEqual(local a = 1; local a = 2; a, 2) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/math.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/math.jsonnet
@@ -0,0 +1,3 @@
+std.assertEqual(2 + 2 * 2, 6) &&
+std.assertEqual(3 + (2 + 2 * 2), 9) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_assertion.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_assertion.jsonnet
@@ -0,0 +1,3 @@
+std.assertEqual({ assert 'a' in self : 'missing a' } + { a: 2 }, { a: 2 }) &&
+test.assertThrow({ assert 'a' in self : 'missing a', b: 1 }.b, 'assert failed: missing a') &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_comp_self.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_comp_self.jsonnet
@@ -0,0 +1,8 @@
+std.assertEqual(std.objectFields({
+  a: {
+    [name]: name
+    for name in std.objectFields(self)
+  },
+  b: 2,
+  c: 3,
+}.a), ['a', 'b', 'c'])
addedcrates/jrsonnet-evaluator/tests/suite/object_context.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_context.jsonnet
@@ -0,0 +1,13 @@
+// `self` assigned to `me` was lost when being
+// referenced from field
+std.assertEqual({
+  local me = self,
+  a: 3,
+  b: me.a,
+}.b, 3) &&
+std.assertEqual({
+  local me = self,
+  a: 3,
+  b(): me.a,
+}.b(), 3) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_fields.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_fields.jsonnet
@@ -0,0 +1,4 @@
+local a = 'a', b = null;
+std.assertEqual({ [a]: 2 }, { a: 2 }) &&
+std.assertEqual({ [b]: 2 }, {}) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_inheritance.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_inheritance.jsonnet
@@ -0,0 +1,17 @@
+std.assertEqual({ a: self.b } + { b: 3 }, { a: 3, b: 3 }) &&
+std.assertEqual(
+  {
+    name: 'Alice',
+    welcome: 'Hello ' + self.name + '!',
+  },
+  { name: 'Alice', welcome: 'Hello Alice!' },
+) &&
+std.assertEqual(
+  {
+    name: 'Alice',
+    welcome: 'Hello ' + self.name + '!',
+  } + {
+    name: 'Bob',
+  }, { name: 'Bob', welcome: 'Hello Bob!' }
+) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_locals.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_locals.jsonnet
@@ -0,0 +1,4 @@
+std.assertEqual({ local a = 3, b: a }, { b: 3 }) &&
+std.assertEqual({ local a = 3, local c = a, b: c }, { b: 3 }) &&
+std.assertEqual({ local a = function(b) { [b]: 4 }, test: a('test') }, { test: { test: 4 } }) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/object_super_standalone.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/object_super_standalone.jsonnet
@@ -0,0 +1,11 @@
+local obj = {
+  a: 1,
+  b: 2,
+  c: 3,
+};
+local test = obj + {
+  fields: std.objectFields(super),
+  d: 5,
+};
+std.assertEqual(test.fields, ['a', 'b', 'c']) &&
+true
addedcrates/jrsonnet-evaluator/tests/suite/string_concat.jsonnetdiffbeforeafterboth
--- /dev/null
+++ b/crates/jrsonnet-evaluator/tests/suite/string_concat.jsonnet
@@ -0,0 +1,4 @@
+std.assertEqual('Hello' + 'World', 'HelloWorld') &&
+std.assertEqual('Hello' * 3, 'HelloHelloHello') &&
+std.assertEqual('Hello' + 'World' * 3, 'HelloWorldWorldWorld') &&
+true
modifiedcrates/jrsonnet-evaluator/tests/typed_obj.rsdiffbeforeafterboth
--- a/crates/jrsonnet-evaluator/tests/typed_obj.rs
+++ b/crates/jrsonnet-evaluator/tests/typed_obj.rs
@@ -51,7 +51,7 @@
 	ensure_eq!(b, B { a: 1, b: 2 });
 	ensure_eq!(
 		&B::into_untyped(b.clone(), s.clone())?.to_string(s.clone())? as &str,
-		"{a: 1, c: 2}",
+		r#"{"a": 1, "c": 2}"#,
 	);
 	test_roundtrip(b.clone(), s.clone())?;
 	Ok(())