difftreelog
test pass full go-jsonnet test suite
in: master
54 files changed
crates/jrsonnet-evaluator/src/evaluate/mod.rsdiffbeforeafterboth1use std::rc::Rc;23use jrsonnet_gcmodule::{Cc, Trace};4use jrsonnet_interner::IStr;5use jrsonnet_parser::{6 ArgsDesc, AssertStmt, BinaryOpType, BindSpec, CompSpec, Expr, FieldMember, FieldName,7 ForSpecData, IfSpecData, LiteralType, LocExpr, Member, ObjBody, ParamsDesc,8};9use jrsonnet_types::ValType;10use rustc_hash::FxHashMap;1112use self::destructure::destruct;13use crate::{14 arr::ArrValue,15 bail,16 destructure::evaluate_dest,17 error::{suggest_object_fields, ErrorKind::*},18 evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},19 function::{CallLocation, FuncDesc, FuncVal},20 gc::WithCapacityExt as _,21 in_frame,22 typed::Typed,23 val::{CachedUnbound, IndexableVal, NumValue, StrValue, Thunk},24 with_state, Context, Error, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result,25 ResultExt, SupThis, Unbound, Val,26};27pub mod destructure;28pub mod operator;2930// This is the amount of bytes that need to be left on the stack before increasing the size.31// It must be at least as large as the stack required by any code that does not call32// `ensure_sufficient_stack`.33const RED_ZONE: usize = 100 * 1024; // 100k3435// Only the first stack that is pushed, grows exponentially (2^n * STACK_PER_RECURSION) from then36// on. This flag has performance relevant characteristics. Don't set it too high.37const STACK_PER_RECURSION: usize = 1024 * 1024; // 1MB3839/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations40/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit41/// from this.42///43/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.44#[inline]45pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {46 stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)47}4849pub fn evaluate_trivial(expr: &LocExpr) -> Option<Val> {50 fn is_trivial(expr: &LocExpr) -> bool {51 match expr.expr() {52 Expr::Str(_)53 | Expr::Num(_)54 | Expr::Literal(LiteralType::False | LiteralType::True | LiteralType::Null) => true,55 Expr::Arr(a) => a.iter().all(is_trivial),56 Expr::Parened(e) => is_trivial(e),57 _ => false,58 }59 }60 Some(match expr.expr() {61 Expr::Str(s) => Val::string(s.clone()),62 Expr::Num(n) => {63 Val::Num(NumValue::new(*n).expect("parser will not allow non-finite values"))64 }65 Expr::Literal(LiteralType::False) => Val::Bool(false),66 Expr::Literal(LiteralType::True) => Val::Bool(true),67 Expr::Literal(LiteralType::Null) => Val::Null,68 Expr::Arr(n) => {69 if n.iter().any(|e| !is_trivial(e)) {70 return None;71 }72 Val::Arr(ArrValue::eager(73 n.iter()74 .map(evaluate_trivial)75 .map(|e| e.expect("checked trivial"))76 .collect(),77 ))78 }79 Expr::Parened(e) => evaluate_trivial(e)?,80 _ => return None,81 })82}8384pub fn evaluate_method(ctx: Context, name: IStr, params: ParamsDesc, body: LocExpr) -> Val {85 Val::Func(FuncVal::Normal(Cc::new(FuncDesc {86 name,87 ctx,88 params,89 body,90 })))91}9293pub fn evaluate_field_name(ctx: Context, field_name: &FieldName) -> Result<Option<IStr>> {94 Ok(match field_name {95 FieldName::Fixed(n) => Some(n.clone()),96 FieldName::Dyn(expr) => in_frame(97 CallLocation::new(&expr.span()),98 || "evaluating field name".to_string(),99 || {100 let value = evaluate(ctx, expr)?;101 if matches!(value, Val::Null) {102 Ok(None)103 } else {104 Ok(Some(IStr::from_untyped(value)?))105 }106 },107 )?,108 })109}110111pub fn evaluate_comp(112 ctx: Context,113 specs: &[CompSpec],114 callback: &mut impl FnMut(Context) -> Result<()>,115) -> Result<()> {116 match specs.first() {117 None => callback(ctx)?,118 Some(CompSpec::IfSpec(IfSpecData(cond))) => {119 if bool::from_untyped(evaluate(ctx.clone(), cond)?)? {120 evaluate_comp(ctx, &specs[1..], callback)?;121 }122 }123 Some(CompSpec::ForSpec(ForSpecData(var, expr))) => match evaluate(ctx.clone(), expr)? {124 Val::Arr(list) => {125 for item in list.iter_lazy() {126 let fctx = Pending::new();127 let mut new_bindings = FxHashMap::with_capacity(var.capacity_hint());128 destruct(var, item, fctx.clone(), &mut new_bindings)?;129 let ctx = ctx.clone().extend_bindings(new_bindings).into_future(fctx);130131 evaluate_comp(ctx, &specs[1..], callback)?;132 }133 }134 #[cfg(feature = "exp-object-iteration")]135 Val::Obj(obj) => {136 for field in obj.fields(137 // TODO: Should there be ability to preserve iteration order?138 #[cfg(feature = "exp-preserve-order")]139 false,140 ) {141 let fctx = Pending::new();142 let mut new_bindings = FxHashMap::with_capacity(var.capacity_hint());143 let obj = obj.clone();144 let value = Thunk::evaluated(Val::Arr(ArrValue::lazy(vec![145 Thunk::evaluated(Val::string(field.clone())),146 Thunk!(move || obj.get(field).transpose().expect(147 "field exists, as field name was obtained from object.fields()",148 )),149 ])));150 destruct(var, value, fctx.clone(), &mut new_bindings)?;151 let ctx = ctx.clone().extend_bindings(new_bindings).into_future(fctx);152153 evaluate_comp(ctx, &specs[1..], callback)?;154 }155 }156 _ => bail!(InComprehensionCanOnlyIterateOverArray),157 },158 }159 Ok(())160}161162trait CloneableUnbound<T>: Unbound<Bound = T> + Clone {}163impl<V, T> CloneableUnbound<T> for V where V: Unbound<Bound = T> + Clone {}164165fn evaluate_object_locals(166 fctx: Context,167 locals: Rc<Vec<BindSpec>>,168) -> impl CloneableUnbound<Context> {169 #[derive(Trace, Clone)]170 struct UnboundLocals {171 fctx: Context,172 locals: Rc<Vec<BindSpec>>,173 }174 impl Unbound for UnboundLocals {175 type Bound = Context;176177 fn bind(&self, sup_this: SupThis) -> Result<Context> {178 let fctx = Context::new_future();179 let mut new_bindings =180 FxHashMap::with_capacity(self.locals.iter().map(BindSpec::capacity_hint).sum());181 for b in self.locals.iter() {182 evaluate_dest(b, fctx.clone(), &mut new_bindings)?;183 }184185 let ctx = self.fctx.clone();186187 let ctx = ctx188 .extend_bindings_sup_this(new_bindings, sup_this)189 .into_future(fctx);190191 Ok(ctx)192 }193 }194195 UnboundLocals { fctx, locals }196}197198pub fn evaluate_field_member<B: Unbound<Bound = Context> + Clone>(199 builder: &mut ObjValueBuilder,200 ctx: Context,201 uctx: B,202 field: &FieldMember,203) -> Result<()> {204 let name = evaluate_field_name(ctx, &field.name)?;205 let Some(name) = name else {206 return Ok(());207 };208209 match field {210 FieldMember {211 plus,212 params: None,213 visibility,214 value,215 ..216 } => {217 #[derive(Trace)]218 struct UnboundValue<B: Trace> {219 uctx: B,220 value: LocExpr,221 name: IStr,222 }223 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {224 type Bound = Val;225 fn bind(&self, sup_this: SupThis) -> Result<Val> {226 evaluate_named(self.uctx.bind(sup_this)?, &self.value, self.name.clone())227 }228 }229230 builder231 .field(name.clone())232 .with_add(*plus)233 .with_visibility(*visibility)234 .with_location(value.span())235 .bindable(UnboundValue {236 uctx,237 value: value.clone(),238 name,239 })?;240 }241 FieldMember {242 params: Some(params),243 visibility,244 value,245 ..246 } => {247 #[derive(Trace)]248 struct UnboundMethod<B: Trace> {249 uctx: B,250 value: LocExpr,251 params: ParamsDesc,252 name: IStr,253 }254 impl<B: Unbound<Bound = Context>> Unbound for UnboundMethod<B> {255 type Bound = Val;256 fn bind(&self, sup_this: SupThis) -> Result<Val> {257 Ok(evaluate_method(258 self.uctx.bind(sup_this)?,259 self.name.clone(),260 self.params.clone(),261 self.value.clone(),262 ))263 }264 }265266 builder267 .field(name.clone())268 .with_visibility(*visibility)269 .with_location(value.span())270 .bindable(UnboundMethod {271 uctx,272 value: value.clone(),273 params: params.clone(),274 name,275 })?;276 }277 }278 Ok(())279}280281#[allow(clippy::too_many_lines)]282pub fn evaluate_member_list_object(ctx: Context, members: &[Member]) -> Result<ObjValue> {283 let mut builder = ObjValueBuilder::new();284 let locals = Rc::new(285 members286 .iter()287 .filter_map(|m| match m {288 Member::BindStmt(bind) => Some(bind.clone()),289 _ => None,290 })291 .collect::<Vec<_>>(),292 );293294 // We have single context for all fields, so we can cache binds295 let uctx = CachedUnbound::new(evaluate_object_locals(ctx.clone(), locals));296297 for member in members {298 match member {299 Member::Field(field) => {300 evaluate_field_member(&mut builder, ctx.clone(), uctx.clone(), field)?;301 }302 Member::AssertStmt(stmt) => {303 #[derive(Trace)]304 struct ObjectAssert<B: Trace> {305 uctx: B,306 assert: AssertStmt,307 }308 impl<B: Unbound<Bound = Context>> ObjectAssertion for ObjectAssert<B> {309 fn run(&self, sup_this: SupThis) -> Result<()> {310 let ctx = self.uctx.bind(sup_this)?;311 evaluate_assert(ctx, &self.assert)312 }313 }314 builder.assert(ObjectAssert {315 uctx: uctx.clone(),316 assert: stmt.clone(),317 });318 }319 Member::BindStmt(_) => {320 // Already handled321 }322 }323 }324 Ok(builder.build())325}326327pub fn evaluate_object(ctx: Context, object: &ObjBody) -> Result<ObjValue> {328 Ok(match object {329 ObjBody::MemberList(members) => evaluate_member_list_object(ctx, members)?,330 ObjBody::ObjComp(obj) => {331 let mut builder = ObjValueBuilder::new();332 let locals = Rc::new(333 obj.pre_locals334 .iter()335 .chain(obj.post_locals.iter())336 .cloned()337 .collect::<Vec<_>>(),338 );339 evaluate_comp(ctx, &obj.compspecs, &mut |ctx| {340 let uctx = evaluate_object_locals(ctx.clone(), locals.clone());341342 evaluate_field_member(&mut builder, ctx, uctx, &obj.field)343 })?;344345 builder.build()346 }347 })348}349350pub fn evaluate_apply(351 ctx: Context,352 value: &LocExpr,353 args: &ArgsDesc,354 loc: CallLocation<'_>,355 tailstrict: bool,356) -> Result<Val> {357 let value = evaluate(ctx.clone(), value)?;358 Ok(match value {359 Val::Func(f) => {360 let body = || f.evaluate(ctx, loc, args, tailstrict);361 if tailstrict {362 body()?363 } else {364 in_frame(loc, || format!("function <{}> call", f.name()), body)?365 }366 }367 v => bail!(OnlyFunctionsCanBeCalledGot(v.value_type())),368 })369}370371pub fn evaluate_assert(ctx: Context, assertion: &AssertStmt) -> Result<()> {372 let value = &assertion.0;373 let msg = &assertion.1;374 let assertion_result = in_frame(375 CallLocation::new(&value.span()),376 || "assertion condition".to_owned(),377 || bool::from_untyped(evaluate(ctx.clone(), value)?),378 )?;379 if !assertion_result {380 in_frame(381 CallLocation::new(&value.span()),382 || "assertion failure".to_owned(),383 || {384 if let Some(msg) = msg {385 bail!(AssertionFailed(evaluate(ctx, msg)?.to_string()?));386 }387 bail!(AssertionFailed(Val::Null.to_string()?));388 },389 )?;390 }391 Ok(())392}393394pub fn evaluate_named(ctx: Context, expr: &LocExpr, name: IStr) -> Result<Val> {395 use Expr::*;396 Ok(match expr.expr() {397 Function(params, body) => evaluate_method(ctx, name, params.clone(), body.clone()),398 _ => evaluate(ctx, expr)?,399 })400}401402#[allow(clippy::too_many_lines)]403pub fn evaluate(ctx: Context, expr: &LocExpr) -> Result<Val> {404 use Expr::*;405406 if let Some(trivial) = evaluate_trivial(expr) {407 return Ok(trivial);408 }409 let loc = expr.span();410 Ok(match expr.expr() {411 Literal(LiteralType::This) => Val::Obj(ctx.try_this()?),412 Literal(LiteralType::Super) => Val::Obj(ctx.try_sup_this()?.standalone_super()?),413 Literal(LiteralType::Dollar) => Val::Obj(ctx.try_dollar()?),414 Literal(LiteralType::True) => Val::Bool(true),415 Literal(LiteralType::False) => Val::Bool(false),416 Literal(LiteralType::Null) => Val::Null,417 Parened(e) => evaluate(ctx, e)?,418 Str(v) => Val::string(v.clone()),419 Num(v) => Val::try_num(*v)?,420 // I have tried to remove special behavior from super by implementing standalone-super421 // expresion, but looks like this case still needs special treatment.422 //423 // Note that other jsonnet implementations will fail on `if value in (super)` expression,424 // because the standalone super literal is not supported, that is because in other425 // implementations `in super` treated differently from `in smth_else`.426 BinaryOp(field, BinaryOpType::In, e)427 if matches!(e.expr(), Expr::Literal(LiteralType::Super)) =>428 {429 let sup_this = ctx.try_sup_this()?;430 // In jsonnet, "field" in e is eager, LHS expression is always executed regardless of super existence.431 // In jrsonnet, however, this wasn't true, this was kept here for compatibility.432 if !sup_this.has_super() {433 return Ok(Val::Bool(false));434 }435 let field = evaluate(ctx, field)?;436 Val::Bool(sup_this.field_in_super(field.to_string()?))437 }438 BinaryOp(v1, o, v2) => evaluate_binary_op_special(ctx, v1, *o, v2)?,439 UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(ctx, v)?)?,440 Var(name) => in_frame(441 CallLocation::new(&loc),442 || format!("local <{name}> access"),443 || ctx.binding(name.clone())?.evaluate(),444 )?,445 Index { indexable, parts } => ensure_sufficient_stack(|| {446 let mut parts = parts.iter();447 let mut indexable = if matches!(indexable.expr(), Expr::Literal(LiteralType::Super)) {448 let part = parts.next().expect("at least part should exist");449 // sup_this existence check might also be skipped here for null-coalesce...450 // But I believe this might cause errors.451 let sup_this = ctx.try_sup_this()?;452 if !sup_this.has_super() {453 #[cfg(feature = "exp-null-coaelse")]454 if part.null_coaelse {455 return Ok(Val::Null);456 }457 bail!(NoSuperFound)458 }459 let name = evaluate(ctx.clone(), &part.value)?;460461 let Val::Str(name) = name else {462 bail!(ValueIndexMustBeTypeGot(463 ValType::Obj,464 ValType::Str,465 name.value_type(),466 ))467 };468469 let name = name.into_flat();470 match sup_this471 .get_super(name.clone())472 .with_description_src(&part.value, || format!("field <{name}> access"))?473 {474 Some(v) => v,475 #[cfg(feature = "exp-null-coaelse")]476 None if part.null_coaelse => return Ok(Val::Null),477 None => {478 let suggestions = suggest_object_fields(479 &sup_this.standalone_super().expect("super exists"),480 name.clone(),481 );482483 bail!(NoSuchField(name, suggestions))484 }485 }486 } else {487 evaluate(ctx.clone(), indexable)?488 };489490 for part in parts {491 indexable = match (indexable, evaluate(ctx.clone(), &part.value)?) {492 (Val::Obj(v), Val::Str(key)) => match v493 .get(key.clone().into_flat())494 .with_description_src(&part.value, || format!("field <{key}> access"))?495 {496 Some(v) => v,497 #[cfg(feature = "exp-null-coaelse")]498 None if part.null_coaelse => return Ok(Val::Null),499 None => {500 let suggestions = suggest_object_fields(&v, key.clone().into_flat());501502 return Err(Error::from(NoSuchField(503 key.clone().into_flat(),504 suggestions,505 )))506 .with_description_src(&part.value, || format!("field <{key}> access"));507 }508 },509 (Val::Obj(_), n) => bail!(ValueIndexMustBeTypeGot(510 ValType::Obj,511 ValType::Str,512 n.value_type(),513 )),514 (Val::Arr(v), Val::Num(n)) => {515 let n = n.get();516 if n.fract() > f64::EPSILON {517 bail!(FractionalIndex)518 }519 if n < 0.0 {520 bail!(ArrayBoundsError(n as isize, v.len()));521 }522 v.get(n as usize)?523 .ok_or_else(|| ArrayBoundsError(n as isize, v.len()))?524 }525 (Val::Arr(_), Val::Str(n)) => {526 bail!(AttemptedIndexAnArrayWithString(n.into_flat()))527 }528 (Val::Arr(_), n) => bail!(ValueIndexMustBeTypeGot(529 ValType::Arr,530 ValType::Num,531 n.value_type(),532 )),533534 (Val::Str(s), Val::Num(n)) => Val::Str({535 let v: IStr = s536 .clone()537 .into_flat()538 .chars()539 .skip(n.get() as usize)540 .take(1)541 .collect::<String>()542 .into();543 if v.is_empty() {544 let size = s.into_flat().chars().count();545 bail!(StringBoundsError(n.get() as usize, size))546 }547 StrValue::Flat(v)548 }),549 (Val::Str(_), n) => bail!(ValueIndexMustBeTypeGot(550 ValType::Str,551 ValType::Num,552 n.value_type(),553 )),554 #[cfg(feature = "exp-null-coaelse")]555 (Val::Null, _) if part.null_coaelse => return Ok(Val::Null),556 (v, _) => bail!(CantIndexInto(v.value_type())),557 };558 }559 Ok(indexable)560 })?,561 LocalExpr(bindings, returned) => {562 let mut new_bindings: FxHashMap<IStr, Thunk<Val>> =563 FxHashMap::with_capacity(bindings.iter().map(BindSpec::capacity_hint).sum());564 let fctx = Context::new_future();565 for b in bindings {566 evaluate_dest(b, fctx.clone(), &mut new_bindings)?;567 }568 let ctx = ctx.extend_bindings(new_bindings).into_future(fctx);569 evaluate(ctx, &returned.clone())?570 }571 Arr(items) => {572 if items.is_empty() {573 Val::Arr(ArrValue::empty())574 } else if items.len() == 1 {575 let item = items[0].clone();576 Val::Arr(ArrValue::lazy(vec![Thunk!(move || evaluate(ctx, &item))]))577 } else {578 Val::Arr(ArrValue::expr(ctx, items.iter().cloned()))579 }580 }581 ArrComp(expr, comp_specs) => {582 let mut out = Vec::new();583 evaluate_comp(ctx, comp_specs, &mut |ctx| {584 let expr = expr.clone();585 out.push(Thunk!(move || evaluate(ctx, &expr)));586 Ok(())587 })?;588 Val::Arr(ArrValue::lazy(out))589 }590 Obj(body) => Val::Obj(evaluate_object(ctx, body)?),591 ObjExtend(a, b) => evaluate_add_op(592 &evaluate(ctx.clone(), a)?,593 &Val::Obj(evaluate_object(ctx, b)?),594 )?,595 Apply(value, args, tailstrict) => ensure_sufficient_stack(|| {596 evaluate_apply(ctx, value, args, CallLocation::new(&loc), *tailstrict)597 })?,598 Function(params, body) => {599 evaluate_method(ctx, "anonymous".into(), params.clone(), body.clone())600 }601 AssertExpr(assert, returned) => {602 evaluate_assert(ctx.clone(), assert)?;603 evaluate(ctx, returned)?604 }605 ErrorStmt(e) => in_frame(606 CallLocation::new(&loc),607 || "error statement".to_owned(),608 || bail!(RuntimeError(evaluate(ctx, e)?.to_string()?,)),609 )?,610 IfElse {611 cond,612 cond_then,613 cond_else,614 } => {615 if in_frame(616 CallLocation::new(&loc),617 || "if condition".to_owned(),618 || bool::from_untyped(evaluate(ctx.clone(), &cond.0)?),619 )? {620 evaluate(ctx, cond_then)?621 } else {622 match cond_else {623 Some(v) => evaluate(ctx, v)?,624 None => Val::Null,625 }626 }627 }628 Slice(value, desc) => {629 fn parse_idx<T: Typed>(630 loc: CallLocation<'_>,631 ctx: Context,632 expr: Option<&LocExpr>,633 desc: &'static str,634 ) -> Result<Option<T>> {635 if let Some(value) = expr {636 Ok(in_frame(637 loc,638 || format!("slice {desc}"),639 || <Option<T>>::from_untyped(evaluate(ctx, value)?),640 )?)641 } else {642 Ok(None)643 }644 }645646 let indexable = evaluate(ctx.clone(), value)?;647 let loc = CallLocation::new(&loc);648649 let start = parse_idx(loc, ctx.clone(), desc.start.as_ref(), "start")?;650 let end = parse_idx(loc, ctx.clone(), desc.end.as_ref(), "end")?;651 let step = parse_idx(loc, ctx, desc.step.as_ref(), "step")?;652653 IndexableVal::into_untyped(indexable.into_indexable()?.slice(start, end, step)?)?654 }655 i @ (Import(path) | ImportStr(path) | ImportBin(path)) => {656 let Expr::Str(path) = &path.expr() else {657 bail!("computed imports are not supported")658 };659 let tmp = loc.clone().0;660 with_state(|s| {661 let resolved_path = s.resolve_from(tmp.source_path(), path)?;662 Ok(match i {663 Import(_) => in_frame(664 CallLocation::new(&loc),665 || format!("import {:?}", path.clone()),666 || s.import_resolved(resolved_path),667 )?,668 ImportStr(_) => Val::string(s.import_resolved_str(resolved_path)?),669 ImportBin(_) => {670 Val::Arr(ArrValue::bytes(s.import_resolved_bin(resolved_path)?))671 }672 _ => unreachable!(),673 }) as Result<Val>674 })?675 }676 })677}1use std::rc::Rc;23use jrsonnet_gcmodule::{Cc, Trace};4use jrsonnet_interner::IStr;5use jrsonnet_parser::{6 ArgsDesc, AssertStmt, BinaryOpType, BindSpec, CompSpec, Expr, FieldMember, FieldName,7 ForSpecData, IfSpecData, LiteralType, LocExpr, Member, ObjBody, ParamsDesc,8};9use jrsonnet_types::ValType;10use rustc_hash::FxHashMap;1112use self::destructure::destruct;13use crate::{14 arr::ArrValue,15 bail,16 destructure::evaluate_dest,17 error::{suggest_object_fields, ErrorKind::*},18 evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op},19 function::{CallLocation, FuncDesc, FuncVal},20 gc::WithCapacityExt as _,21 in_frame,22 typed::Typed,23 val::{CachedUnbound, IndexableVal, NumValue, StrValue, Thunk},24 with_state, Context, Error, ObjValue, ObjValueBuilder, ObjectAssertion, Pending, Result,25 ResultExt, SupThis, Unbound, Val,26};27pub mod destructure;28pub mod operator;2930// This is the amount of bytes that need to be left on the stack before increasing the size.31// It must be at least as large as the stack required by any code that does not call32// `ensure_sufficient_stack`.33const RED_ZONE: usize = 100 * 1024; // 100k3435// Only the first stack that is pushed, grows exponentially (2^n * STACK_PER_RECURSION) from then36// on. This flag has performance relevant characteristics. Don't set it too high.37const STACK_PER_RECURSION: usize = 1024 * 1024; // 1MB3839/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations40/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit41/// from this.42///43/// Should not be sprinkled around carelessly, as it causes a little bit of overhead.44#[inline]45pub fn ensure_sufficient_stack<R>(f: impl FnOnce() -> R) -> R {46 stacker::maybe_grow(RED_ZONE, STACK_PER_RECURSION, f)47}4849pub fn evaluate_trivial(expr: &LocExpr) -> Option<Val> {50 fn is_trivial(expr: &LocExpr) -> bool {51 match expr.expr() {52 Expr::Str(_)53 | Expr::Num(_)54 | Expr::Literal(LiteralType::False | LiteralType::True | LiteralType::Null) => true,55 Expr::Arr(a) => a.iter().all(is_trivial),56 Expr::Parened(e) => is_trivial(e),57 _ => false,58 }59 }60 Some(match expr.expr() {61 Expr::Str(s) => Val::string(s.clone()),62 Expr::Num(n) => {63 Val::Num(NumValue::new(*n).expect("parser will not allow non-finite values"))64 }65 Expr::Literal(LiteralType::False) => Val::Bool(false),66 Expr::Literal(LiteralType::True) => Val::Bool(true),67 Expr::Literal(LiteralType::Null) => Val::Null,68 Expr::Arr(n) => {69 if n.iter().any(|e| !is_trivial(e)) {70 return None;71 }72 Val::Arr(ArrValue::eager(73 n.iter()74 .map(evaluate_trivial)75 .map(|e| e.expect("checked trivial"))76 .collect(),77 ))78 }79 Expr::Parened(e) => evaluate_trivial(e)?,80 _ => return None,81 })82}8384pub fn evaluate_method(ctx: Context, name: IStr, params: ParamsDesc, body: LocExpr) -> Val {85 Val::Func(FuncVal::Normal(Cc::new(FuncDesc {86 name,87 ctx,88 params,89 body,90 })))91}9293pub fn evaluate_field_name(ctx: Context, field_name: &FieldName) -> Result<Option<IStr>> {94 Ok(match field_name {95 FieldName::Fixed(n) => Some(n.clone()),96 FieldName::Dyn(expr) => in_frame(97 CallLocation::new(&expr.span()),98 || "evaluating field name".to_string(),99 || {100 let value = evaluate(ctx, expr)?;101 if matches!(value, Val::Null) {102 Ok(None)103 } else {104 Ok(Some(IStr::from_untyped(value)?))105 }106 },107 )?,108 })109}110111pub fn evaluate_comp(112 ctx: Context,113 specs: &[CompSpec],114 callback: &mut impl FnMut(Context) -> Result<()>,115) -> Result<()> {116 match specs.first() {117 None => callback(ctx)?,118 Some(CompSpec::IfSpec(IfSpecData(cond))) => {119 if bool::from_untyped(evaluate(ctx.clone(), cond)?)? {120 evaluate_comp(ctx, &specs[1..], callback)?;121 }122 }123 Some(CompSpec::ForSpec(ForSpecData(var, expr))) => match evaluate(ctx.clone(), expr)? {124 Val::Arr(list) => {125 for item in list.iter_lazy() {126 let fctx = Pending::new();127 let mut new_bindings = FxHashMap::with_capacity(var.capacity_hint());128 destruct(var, item, fctx.clone(), &mut new_bindings)?;129 let ctx = ctx.clone().extend_bindings(new_bindings).into_future(fctx);130131 evaluate_comp(ctx, &specs[1..], callback)?;132 }133 }134 #[cfg(feature = "exp-object-iteration")]135 Val::Obj(obj) => {136 for field in obj.fields(137 // TODO: Should there be ability to preserve iteration order?138 #[cfg(feature = "exp-preserve-order")]139 false,140 ) {141 let fctx = Pending::new();142 let mut new_bindings = FxHashMap::with_capacity(var.capacity_hint());143 let obj = obj.clone();144 let value = Thunk::evaluated(Val::Arr(ArrValue::lazy(vec![145 Thunk::evaluated(Val::string(field.clone())),146 Thunk!(move || obj.get(field).transpose().expect(147 "field exists, as field name was obtained from object.fields()",148 )),149 ])));150 destruct(var, value, fctx.clone(), &mut new_bindings)?;151 let ctx = ctx.clone().extend_bindings(new_bindings).into_future(fctx);152153 evaluate_comp(ctx, &specs[1..], callback)?;154 }155 }156 _ => bail!(InComprehensionCanOnlyIterateOverArray),157 },158 }159 Ok(())160}161162trait CloneableUnbound<T>: Unbound<Bound = T> + Clone {}163impl<V, T> CloneableUnbound<T> for V where V: Unbound<Bound = T> + Clone {}164165fn evaluate_object_locals(166 fctx: Context,167 locals: Rc<Vec<BindSpec>>,168) -> impl CloneableUnbound<Context> {169 #[derive(Trace, Clone)]170 struct UnboundLocals {171 fctx: Context,172 locals: Rc<Vec<BindSpec>>,173 }174 impl Unbound for UnboundLocals {175 type Bound = Context;176177 fn bind(&self, sup_this: SupThis) -> Result<Context> {178 let fctx = Context::new_future();179 let mut new_bindings =180 FxHashMap::with_capacity(self.locals.iter().map(BindSpec::capacity_hint).sum());181 for b in self.locals.iter() {182 evaluate_dest(b, fctx.clone(), &mut new_bindings)?;183 }184185 let ctx = self.fctx.clone();186187 let ctx = ctx188 .extend_bindings_sup_this(new_bindings, sup_this)189 .into_future(fctx);190191 Ok(ctx)192 }193 }194195 UnboundLocals { fctx, locals }196}197198pub fn evaluate_field_member<B: Unbound<Bound = Context> + Clone>(199 builder: &mut ObjValueBuilder,200 ctx: Context,201 uctx: B,202 field: &FieldMember,203) -> Result<()> {204 let name = evaluate_field_name(ctx, &field.name)?;205 let Some(name) = name else {206 return Ok(());207 };208209 match field {210 FieldMember {211 plus,212 params: None,213 visibility,214 value,215 ..216 } => {217 #[derive(Trace)]218 struct UnboundValue<B: Trace> {219 uctx: B,220 value: LocExpr,221 name: IStr,222 }223 impl<B: Unbound<Bound = Context>> Unbound for UnboundValue<B> {224 type Bound = Val;225 fn bind(&self, sup_this: SupThis) -> Result<Val> {226 evaluate_named(self.uctx.bind(sup_this)?, &self.value, self.name.clone())227 }228 }229230 builder231 .field(name.clone())232 .with_add(*plus)233 .with_visibility(*visibility)234 .with_location(value.span())235 .bindable(UnboundValue {236 uctx,237 value: value.clone(),238 name,239 })?;240 }241 FieldMember {242 params: Some(params),243 visibility,244 value,245 ..246 } => {247 #[derive(Trace)]248 struct UnboundMethod<B: Trace> {249 uctx: B,250 value: LocExpr,251 params: ParamsDesc,252 name: IStr,253 }254 impl<B: Unbound<Bound = Context>> Unbound for UnboundMethod<B> {255 type Bound = Val;256 fn bind(&self, sup_this: SupThis) -> Result<Val> {257 Ok(evaluate_method(258 self.uctx.bind(sup_this)?,259 self.name.clone(),260 self.params.clone(),261 self.value.clone(),262 ))263 }264 }265266 builder267 .field(name.clone())268 .with_visibility(*visibility)269 .with_location(value.span())270 .bindable(UnboundMethod {271 uctx,272 value: value.clone(),273 params: params.clone(),274 name,275 })?;276 }277 }278 Ok(())279}280281#[allow(clippy::too_many_lines)]282pub fn evaluate_member_list_object(ctx: Context, members: &[Member]) -> Result<ObjValue> {283 let mut builder = ObjValueBuilder::new();284 let locals = Rc::new(285 members286 .iter()287 .filter_map(|m| match m {288 Member::BindStmt(bind) => Some(bind.clone()),289 _ => None,290 })291 .collect::<Vec<_>>(),292 );293294 // We have single context for all fields, so we can cache binds295 let uctx = CachedUnbound::new(evaluate_object_locals(ctx.clone(), locals));296297 for member in members {298 match member {299 Member::Field(field) => {300 evaluate_field_member(&mut builder, ctx.clone(), uctx.clone(), field)?;301 }302 Member::AssertStmt(stmt) => {303 #[derive(Trace)]304 struct ObjectAssert<B: Trace> {305 uctx: B,306 assert: AssertStmt,307 }308 impl<B: Unbound<Bound = Context>> ObjectAssertion for ObjectAssert<B> {309 fn run(&self, sup_this: SupThis) -> Result<()> {310 let ctx = self.uctx.bind(sup_this)?;311 evaluate_assert(ctx, &self.assert)312 }313 }314 builder.assert(ObjectAssert {315 uctx: uctx.clone(),316 assert: stmt.clone(),317 });318 }319 Member::BindStmt(_) => {320 // Already handled321 }322 }323 }324 Ok(builder.build())325}326327pub fn evaluate_object(ctx: Context, object: &ObjBody) -> Result<ObjValue> {328 Ok(match object {329 ObjBody::MemberList(members) => evaluate_member_list_object(ctx, members)?,330 ObjBody::ObjComp(obj) => {331 let mut builder = ObjValueBuilder::new();332 let locals = Rc::new(333 obj.pre_locals334 .iter()335 .chain(obj.post_locals.iter())336 .cloned()337 .collect::<Vec<_>>(),338 );339 evaluate_comp(ctx, &obj.compspecs, &mut |ctx| {340 let uctx = evaluate_object_locals(ctx.clone(), locals.clone());341342 evaluate_field_member(&mut builder, ctx, uctx, &obj.field)343 })?;344345 builder.build()346 }347 })348}349350pub fn evaluate_apply(351 ctx: Context,352 value: &LocExpr,353 args: &ArgsDesc,354 loc: CallLocation<'_>,355 tailstrict: bool,356) -> Result<Val> {357 let value = evaluate(ctx.clone(), value)?;358 Ok(match value {359 Val::Func(f) => {360 let body = || f.evaluate(ctx, loc, args, tailstrict);361 if tailstrict {362 body()?363 } else {364 in_frame(loc, || format!("function <{}> call", f.name()), body)?365 }366 }367 v => bail!(OnlyFunctionsCanBeCalledGot(v.value_type())),368 })369}370371pub fn evaluate_assert(ctx: Context, assertion: &AssertStmt) -> Result<()> {372 let value = &assertion.0;373 let msg = &assertion.1;374 let assertion_result = in_frame(375 CallLocation::new(&value.span()),376 || "assertion condition".to_owned(),377 || bool::from_untyped(evaluate(ctx.clone(), value)?),378 )?;379 if !assertion_result {380 in_frame(381 CallLocation::new(&value.span()),382 || "assertion failure".to_owned(),383 || {384 if let Some(msg) = msg {385 bail!(AssertionFailed(evaluate(ctx, msg)?.to_string()?));386 }387 bail!(AssertionFailed(Val::Null.to_string()?));388 },389 )?;390 }391 Ok(())392}393394pub fn evaluate_named(ctx: Context, expr: &LocExpr, name: IStr) -> Result<Val> {395 use Expr::*;396 Ok(match expr.expr() {397 Function(params, body) => evaluate_method(ctx, name, params.clone(), body.clone()),398 _ => evaluate(ctx, expr)?,399 })400}401402#[allow(clippy::too_many_lines)]403pub fn evaluate(ctx: Context, expr: &LocExpr) -> Result<Val> {404 use Expr::*;405406 if let Some(trivial) = evaluate_trivial(expr) {407 return Ok(trivial);408 }409 let loc = expr.span();410 Ok(match expr.expr() {411 Literal(LiteralType::This) => Val::Obj(ctx.try_this()?),412 Literal(LiteralType::Super) => Val::Obj(ctx.try_sup_this()?.standalone_super()?),413 Literal(LiteralType::Dollar) => Val::Obj(ctx.try_dollar()?),414 Literal(LiteralType::True) => Val::Bool(true),415 Literal(LiteralType::False) => Val::Bool(false),416 Literal(LiteralType::Null) => Val::Null,417 Parened(e) => evaluate(ctx, e)?,418 Str(v) => Val::string(v.clone()),419 Num(v) => Val::try_num(*v)?,420 // I have tried to remove special behavior from super by implementing standalone-super421 // expresion, but looks like this case still needs special treatment.422 //423 // Note that other jsonnet implementations will fail on `if value in (super)` expression,424 // because the standalone super literal is not supported, that is because in other425 // implementations `in super` treated differently from `in smth_else`.426 BinaryOp(field, BinaryOpType::In, e)427 if matches!(e.expr(), Expr::Literal(LiteralType::Super)) =>428 {429 let sup_this = ctx.try_sup_this()?;430 // In jsonnet, "field" in e is eager, LHS expression is always executed regardless of super existence.431 // In jrsonnet, however, this wasn't true, this was kept here for compatibility.432 if !sup_this.has_super() {433 return Ok(Val::Bool(false));434 }435 let field = evaluate(ctx, field)?;436 Val::Bool(sup_this.field_in_super(field.to_string()?))437 }438 BinaryOp(v1, o, v2) => evaluate_binary_op_special(ctx, v1, *o, v2)?,439 UnaryOp(o, v) => evaluate_unary_op(*o, &evaluate(ctx, v)?)?,440 Var(name) => in_frame(441 CallLocation::new(&loc),442 || format!("local <{name}> access"),443 || ctx.binding(name.clone())?.evaluate(),444 )?,445 Index { indexable, parts } => ensure_sufficient_stack(|| {446 let mut parts = parts.iter();447 let mut indexable = if matches!(indexable.expr(), Expr::Literal(LiteralType::Super)) {448 let part = parts.next().expect("at least part should exist");449 // sup_this existence check might also be skipped here for null-coalesce...450 // But I believe this might cause errors.451 let sup_this = ctx.try_sup_this()?;452 if !sup_this.has_super() {453 #[cfg(feature = "exp-null-coaelse")]454 if part.null_coaelse {455 return Ok(Val::Null);456 }457 bail!(NoSuperFound)458 }459 let name = evaluate(ctx.clone(), &part.value)?;460461 let Val::Str(name) = name else {462 bail!(ValueIndexMustBeTypeGot(463 ValType::Obj,464 ValType::Str,465 name.value_type(),466 ))467 };468469 let name = name.into_flat();470 match sup_this471 .get_super(name.clone())472 .with_description_src(&part.value, || format!("field <{name}> access"))?473 {474 Some(v) => v,475 #[cfg(feature = "exp-null-coaelse")]476 None if part.null_coaelse => return Ok(Val::Null),477 None => {478 let suggestions = suggest_object_fields(479 &sup_this.standalone_super().expect("super exists"),480 name.clone(),481 );482483 bail!(NoSuchField(name, suggestions))484 }485 }486 } else {487 evaluate(ctx.clone(), indexable)?488 };489490 for part in parts {491 indexable = match (indexable, evaluate(ctx.clone(), &part.value)?) {492 (Val::Obj(v), Val::Str(key)) => match v493 .get(key.clone().into_flat())494 .with_description_src(&part.value, || format!("field <{key}> access"))?495 {496 Some(v) => v,497 #[cfg(feature = "exp-null-coaelse")]498 None if part.null_coaelse => return Ok(Val::Null),499 None => {500 let suggestions = suggest_object_fields(&v, key.clone().into_flat());501502 return Err(Error::from(NoSuchField(503 key.clone().into_flat(),504 suggestions,505 )))506 .with_description_src(&part.value, || format!("field <{key}> access"));507 }508 },509 (Val::Obj(_), n) => bail!(ValueIndexMustBeTypeGot(510 ValType::Obj,511 ValType::Str,512 n.value_type(),513 )),514 (Val::Arr(v), Val::Num(n)) => {515 let n = n.get();516 if n.fract() > f64::EPSILON {517 bail!(FractionalIndex)518 }519 if n < 0.0 {520 bail!(ArrayBoundsError(n as isize, v.len()));521 }522 v.get(n as usize)?523 .ok_or_else(|| ArrayBoundsError(n as isize, v.len()))?524 }525 (Val::Arr(_), Val::Str(n)) => {526 bail!(AttemptedIndexAnArrayWithString(n.into_flat()))527 }528 (Val::Arr(_), n) => bail!(ValueIndexMustBeTypeGot(529 ValType::Arr,530 ValType::Num,531 n.value_type(),532 )),533534 (Val::Str(s), Val::Num(n)) => Val::Str({535 let n = n.get();536 if n.fract() > f64::EPSILON {537 bail!(FractionalIndex)538 }539 if n < 0.0 {540 bail!(ArrayBoundsError(n as isize, s.into_flat().chars().count()));541 }542 let v: IStr = s543 .clone()544 .into_flat()545 .chars()546 .skip(n as usize)547 .take(1)548 .collect::<String>()549 .into();550 if v.is_empty() {551 bail!(StringBoundsError(n as usize, s.into_flat().chars().count()))552 }553 StrValue::Flat(v)554 }),555 (Val::Str(_), n) => bail!(ValueIndexMustBeTypeGot(556 ValType::Str,557 ValType::Num,558 n.value_type(),559 )),560 #[cfg(feature = "exp-null-coaelse")]561 (Val::Null, _) if part.null_coaelse => return Ok(Val::Null),562 (v, _) => bail!(CantIndexInto(v.value_type())),563 };564 }565 Ok(indexable)566 })?,567 LocalExpr(bindings, returned) => {568 let mut new_bindings: FxHashMap<IStr, Thunk<Val>> =569 FxHashMap::with_capacity(bindings.iter().map(BindSpec::capacity_hint).sum());570 let fctx = Context::new_future();571 for b in bindings {572 evaluate_dest(b, fctx.clone(), &mut new_bindings)?;573 }574 let ctx = ctx.extend_bindings(new_bindings).into_future(fctx);575 evaluate(ctx, &returned.clone())?576 }577 Arr(items) => {578 if items.is_empty() {579 Val::Arr(ArrValue::empty())580 } else if items.len() == 1 {581 let item = items[0].clone();582 Val::Arr(ArrValue::lazy(vec![Thunk!(move || evaluate(ctx, &item))]))583 } else {584 Val::Arr(ArrValue::expr(ctx, items.iter().cloned()))585 }586 }587 ArrComp(expr, comp_specs) => {588 let mut out = Vec::new();589 evaluate_comp(ctx, comp_specs, &mut |ctx| {590 let expr = expr.clone();591 out.push(Thunk!(move || evaluate(ctx, &expr)));592 Ok(())593 })?;594 Val::Arr(ArrValue::lazy(out))595 }596 Obj(body) => Val::Obj(evaluate_object(ctx, body)?),597 ObjExtend(a, b) => evaluate_add_op(598 &evaluate(ctx.clone(), a)?,599 &Val::Obj(evaluate_object(ctx, b)?),600 )?,601 Apply(value, args, tailstrict) => ensure_sufficient_stack(|| {602 evaluate_apply(ctx, value, args, CallLocation::new(&loc), *tailstrict)603 })?,604 Function(params, body) => {605 evaluate_method(ctx, "anonymous".into(), params.clone(), body.clone())606 }607 AssertExpr(assert, returned) => {608 evaluate_assert(ctx.clone(), assert)?;609 evaluate(ctx, returned)?610 }611 ErrorStmt(e) => in_frame(612 CallLocation::new(&loc),613 || "error statement".to_owned(),614 || bail!(RuntimeError(evaluate(ctx, e)?.to_string()?,)),615 )?,616 IfElse {617 cond,618 cond_then,619 cond_else,620 } => {621 if in_frame(622 CallLocation::new(&loc),623 || "if condition".to_owned(),624 || bool::from_untyped(evaluate(ctx.clone(), &cond.0)?),625 )? {626 evaluate(ctx, cond_then)?627 } else {628 match cond_else {629 Some(v) => evaluate(ctx, v)?,630 None => Val::Null,631 }632 }633 }634 Slice(value, desc) => {635 fn parse_idx<T: Typed>(636 loc: CallLocation<'_>,637 ctx: Context,638 expr: Option<&LocExpr>,639 desc: &'static str,640 ) -> Result<Option<T>> {641 if let Some(value) = expr {642 Ok(in_frame(643 loc,644 || format!("slice {desc}"),645 || <Option<T>>::from_untyped(evaluate(ctx, value)?),646 )?)647 } else {648 Ok(None)649 }650 }651652 let indexable = evaluate(ctx.clone(), value)?;653 let loc = CallLocation::new(&loc);654655 let start = parse_idx(loc, ctx.clone(), desc.start.as_ref(), "start")?;656 let end = parse_idx(loc, ctx.clone(), desc.end.as_ref(), "end")?;657 let step = parse_idx(loc, ctx, desc.step.as_ref(), "step")?;658659 IndexableVal::into_untyped(indexable.into_indexable()?.slice(start, end, step)?)?660 }661 i @ (Import(path) | ImportStr(path) | ImportBin(path)) => {662 let Expr::Str(path) = &path.expr() else {663 bail!("computed imports are not supported")664 };665 let tmp = loc.clone().0;666 with_state(|s| {667 let resolved_path = s.resolve_from(tmp.source_path(), path)?;668 Ok(match i {669 Import(_) => in_frame(670 CallLocation::new(&loc),671 || format!("import {:?}", path.clone()),672 || s.import_resolved(resolved_path),673 )?,674 ImportStr(_) => Val::string(s.import_resolved_str(resolved_path)?),675 ImportBin(_) => {676 Val::Arr(ArrValue::bytes(s.import_resolved_bin(resolved_path)?))677 }678 _ => unreachable!(),679 }) as Result<Val>680 })?681 }682 })683}crates/jrsonnet-stdlib/src/math.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/math.rs
+++ b/crates/jrsonnet-stdlib/src/math.rs
@@ -168,12 +168,12 @@
#[builtin]
pub fn builtin_deg2rad(x: f64) -> f64 {
- x * f64::consts::PI / 180.0
+ x.to_radians()
}
#[builtin]
pub fn builtin_rad2deg(x: f64) -> f64 {
- x * 180.0 / f64::consts::PI
+ x.to_degrees()
}
#[builtin]
crates/jrsonnet-stdlib/src/sort.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/sort.rs
+++ b/crates/jrsonnet-stdlib/src/sort.rs
@@ -17,6 +17,7 @@
enum SortKeyType {
Number,
String,
+ Unspecialized,
Unknown,
}
@@ -31,7 +32,7 @@
(Val::Str(_) | Val::Num(_), _) => {
bail!("sort elements should have the same types")
}
- _ => {}
+ (_, _) => return Ok(SortKeyType::Unspecialized),
}
}
Ok(sort_type)
@@ -49,7 +50,7 @@
Val::Str(s) => s.clone(),
_ => unreachable!(),
}),
- SortKeyType::Unknown => {
+ SortKeyType::Unknown | SortKeyType::Unspecialized => {
let mut err = None;
// evaluate_compare_op will never return equal on types, which are different from
// jsonnet perspective
@@ -88,7 +89,7 @@
Val::Str(s) => s.clone(),
_ => unreachable!(),
}),
- SortKeyType::Unknown => {
+ SortKeyType::Unknown | SortKeyType::Unspecialized => {
let mut err = None;
// evaluate_compare_op will never return equal on types, which are different from
// jsonnet perspective
crates/jrsonnet-stdlib/src/strings.rsdiffbeforeafterboth--- a/crates/jrsonnet-stdlib/src/strings.rs
+++ b/crates/jrsonnet-stdlib/src/strings.rs
@@ -25,8 +25,11 @@
}
#[builtin]
-pub fn builtin_str_replace(str: String, from: IStr, to: IStr) -> String {
- str.replace(&from as &str, &to as &str)
+pub fn builtin_str_replace(str: String, from: IStr, to: IStr) -> Result<String> {
+ if from.is_empty() {
+ bail!("'from' string must not be zero length");
+ }
+ Ok(str.replace(&from as &str, &to as &str))
}
#[builtin]
tests/go_testdata_golden_override/builtinObjectRemoveKey_super_assert.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/builtinObjectRemoveKey_super_assert.jsonnet.golden
@@ -0,0 +1,3 @@
+no such field: x
+ builtinObjectRemoveKey_super_assert.jsonnet:2:15-17: field <x> access
+ builtinObjectRemoveKey_super_assert.jsonnet:2:10-17: assertion condition
\ No newline at end of file
tests/go_testdata_golden_override/std.filter8.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.filter8.jsonnet.golden
@@ -0,0 +1,3 @@
+type error: expected function, got array
+ argument <func> evaluation
+ std.filter8.jsonnet:1:1-37: function <builtin_filter> call
\ No newline at end of file
tests/go_testdata_golden_override/std.filter_swapped_args.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.filter_swapped_args.jsonnet.golden
@@ -0,0 +1,3 @@
+type error: expected function, got array
+ argument <func> evaluation
+ std.filter_swapped_args.jsonnet:1:1-39: function <builtin_filter> call
\ No newline at end of file
tests/go_testdata_golden_override/std.flatmap5.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.flatmap5.jsonnet.golden
@@ -0,0 +1,5 @@
+runtime error: a
+ std.flatmap5.jsonnet:1:21-29: error statement
+ std.flatmap5.jsonnet:2:10-49: function <builtin_flatmap> call
+ argument <x> evaluation
+ std.flatmap5.jsonnet:2:1-50: function <builtin_type> call
\ No newline at end of file
tests/go_testdata_golden_override/std.join7.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.join7.jsonnet.golden
@@ -0,0 +1,2 @@
+runtime error: in std.join all items should be strings
+ std.join7.jsonnet:1:1-28: function <builtin_join> call
\ No newline at end of file
tests/go_testdata_golden_override/std.join8.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.join8.jsonnet.golden
@@ -0,0 +1,2 @@
+runtime error: in std.join all items should be arrays
+ std.join8.jsonnet:1:1-34: function <builtin_join> call
\ No newline at end of file
tests/go_testdata_golden_override/std.makeArrayNamed3.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.makeArrayNamed3.jsonnet.golden
@@ -0,0 +1,2 @@
+parameter blahblah is not defined
+ std.makeArrayNamed3.jsonnet:1:1-55: function <builtin_make_array> call
\ No newline at end of file
tests/go_testdata_golden_override/std.makeArray_bad.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.makeArray_bad.jsonnet.golden
@@ -0,0 +1,3 @@
+type error: expected BoundedNumber<0, 2147483647>, got string
+ argument <sz> evaluation
+ std.makeArray_bad.jsonnet:1:1-37: function <builtin_make_array> call
\ No newline at end of file
tests/go_testdata_golden_override/std.makeArray_bad2.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.makeArray_bad2.jsonnet.golden
@@ -0,0 +1,3 @@
+type error: expected function, got string
+ argument <func> evaluation
+ std.makeArray_bad2.jsonnet:1:1-26: function <builtin_make_array> call
\ No newline at end of file
tests/go_testdata_golden_override/std.makeArray_noninteger.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.makeArray_noninteger.jsonnet.golden
@@ -0,0 +1,3 @@
+runtime error: cannot convert number with fractional part to i32
+ argument <sz> evaluation
+ std.makeArray_noninteger.jsonnet:1:1-35: function <builtin_make_array> call
\ No newline at end of file
tests/go_testdata_golden_override/std.makeArray_noninteger_big.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.makeArray_noninteger_big.jsonnet.golden
@@ -0,0 +1,3 @@
+type error: number out of bounds: 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 not in 0..2147483647
+ argument <sz> evaluation
+ std.makeArray_noninteger_big.jsonnet:1:1-37: function <builtin_make_array> call
\ No newline at end of file
tests/go_testdata_golden_override/std.manifestYamlDoc_error.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.manifestYamlDoc_error.jsonnet.golden
@@ -0,0 +1,5 @@
+runtime error: foo
+ std.manifestYamlDoc_error.jsonnet:1:31-43: error statement
+ field <y> evaluation
+ field <x> manifestification
+ std.manifestYamlDoc_error.jsonnet:1:1-48: function <builtin_manifest_yaml_doc> call
\ No newline at end of file
tests/go_testdata_golden_override/std.mantissa2.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.mantissa2.jsonnet.golden
@@ -0,0 +1 @@
+0.6562500000000002
\ No newline at end of file
tests/go_testdata_golden_override/std.mantissa3.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.mantissa3.jsonnet.golden
@@ -0,0 +1 @@
+0.8399999999999999
\ No newline at end of file
tests/go_testdata_golden_override/std.mantissa4.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.mantissa4.jsonnet.golden
@@ -0,0 +1 @@
+0.571493695641147
\ No newline at end of file
tests/go_testdata_golden_override/std.mantissa5.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.mantissa5.jsonnet.golden
@@ -0,0 +1 @@
+0.6562499999999998
\ No newline at end of file
tests/go_testdata_golden_override/std.mantissa6.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.mantissa6.jsonnet.golden
@@ -0,0 +1 @@
+0.6562499999999998
\ No newline at end of file
tests/go_testdata_golden_override/std.mantissa7.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.mantissa7.jsonnet.golden
@@ -0,0 +1 @@
+-0.6562500000000002
\ No newline at end of file
tests/go_testdata_golden_override/std.maxArrayOnEmpty.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.maxArrayOnEmpty.jsonnet.golden
@@ -0,0 +1,2 @@
+runtime error: expected non-empty array
+ std.maxArrayOnEmpty.jsonnet:1:1-18: function <builtin_max_array> call
\ No newline at end of file
tests/go_testdata_golden_override/std.md5_6.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.md5_6.jsonnet.golden
@@ -0,0 +1,3 @@
+type error: expected string, got number
+ argument <s> evaluation
+ std.md5_6.jsonnet:1:1-13: function <builtin_md5> call
\ No newline at end of file
tests/go_testdata_golden_override/std.minArrayOnEmpty.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.minArrayOnEmpty.jsonnet.golden
@@ -0,0 +1,2 @@
+runtime error: expected non-empty array
+ std.minArrayOnEmpty.jsonnet:1:1-18: function <builtin_min_array> call
\ No newline at end of file
tests/go_testdata_golden_override/std.modulo2.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.modulo2.jsonnet.golden
@@ -0,0 +1,3 @@
+type error: expected number, got string
+ argument <x> evaluation
+ std.modulo2.jsonnet:1:1-23: function <builtin_modulo> call
\ No newline at end of file
tests/go_testdata_golden_override/std.modulo3.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.modulo3.jsonnet.golden
@@ -0,0 +1,3 @@
+type error: expected number, got string
+ argument <x> evaluation
+ std.modulo3.jsonnet:1:1-23: function <builtin_modulo> call
\ No newline at end of file
tests/go_testdata_golden_override/std.primitiveEquals10.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.primitiveEquals10.jsonnet.golden
@@ -0,0 +1,4 @@
+runtime error: x
+ std.primitiveEquals10.jsonnet:1:21-31: error statement
+ argument <x> evaluation
+ std.primitiveEquals10.jsonnet:1:1-36: function <builtin_primitive_equals> call
\ No newline at end of file
tests/go_testdata_golden_override/std.primitiveEquals13.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.primitiveEquals13.jsonnet.golden
@@ -0,0 +1,2 @@
+runtime error: primitiveEquals operates on primitive types, got array
+ std.primitiveEquals13.jsonnet:1:1-29: function <builtin_primitive_equals> call
\ No newline at end of file
tests/go_testdata_golden_override/std.primitiveEquals6.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.primitiveEquals6.jsonnet.golden
@@ -0,0 +1,2 @@
+runtime error: primitiveEquals operates on primitive types, got object
+ std.primitiveEquals6.jsonnet:1:1-29: function <builtin_primitive_equals> call
\ No newline at end of file
tests/go_testdata_golden_override/std.primitiveEquals7.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.primitiveEquals7.jsonnet.golden
@@ -0,0 +1,2 @@
+runtime error: cannot test equality of functions
+ std.primitiveEquals7.jsonnet:1:1-51: function <builtin_primitive_equals> call
\ No newline at end of file
tests/go_testdata_golden_override/std.primitiveEquals9.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.primitiveEquals9.jsonnet.golden
@@ -0,0 +1,4 @@
+runtime error: x
+ std.primitiveEquals9.jsonnet:1:25-35: error statement
+ argument <y> evaluation
+ std.primitiveEquals9.jsonnet:1:1-36: function <builtin_primitive_equals> call
\ No newline at end of file
tests/go_testdata_golden_override/std.sort3.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.sort3.jsonnet.golden
@@ -0,0 +1,3 @@
+runtime error: foo
+ std.sort3.jsonnet:1:16-28: error statement
+ std.sort3.jsonnet:1:1-30: function <builtin_sort> call
\ No newline at end of file
tests/go_testdata_golden_override/std.sort4.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.sort4.jsonnet.golden
@@ -0,0 +1,2 @@
+binary operation array < number is not implemented
+ std.sort4.jsonnet:1:1-30: function <builtin_sort> call
\ No newline at end of file
tests/go_testdata_golden_override/std.thisFile.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.thisFile.jsonnet.golden
@@ -0,0 +1 @@
+"std.thisFile.jsonnet"
\ No newline at end of file
tests/go_testdata_golden_override/std.thisFile2.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.thisFile2.jsonnet.golden
@@ -0,0 +1 @@
+"std.thisFile.jsonnet"
\ No newline at end of file
tests/go_testdata_golden_override/std.toString5.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/std.toString5.jsonnet.golden
@@ -0,0 +1,4 @@
+runtime error: x
+ std.toString5.jsonnet:1:14-24: error statement
+ argument <a> evaluation
+ std.toString5.jsonnet:1:1-25: function <builtin_to_string> call
\ No newline at end of file
tests/go_testdata_golden_override/stdlib_smoke_test.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/stdlib_smoke_test.jsonnet.golden
@@ -0,0 +1,279 @@
+{
+ "abs": 42,
+ "acos": 1.0471975511965979,
+ "asciiLower": "blah",
+ "asciiUpper": "BLAH",
+ "asin": 0.5235987755982989,
+ "assertEqual": true,
+ "atan": 1.373400766945016,
+ "base64": [
+ "YmxhaA==",
+ "YmxhaA=="
+ ],
+ "base64Decode": "blah\n",
+ "base64DecodeBytes": [
+ 98,
+ 108,
+ 97,
+ 104,
+ 10
+ ],
+ "ceil": 5,
+ "char": "A",
+ "codepoint": 65,
+ "cos": 0.28366218546322625,
+ "count": 1,
+ "decodeUTF8": "AAA",
+ "encodeUTF8": [
+ 98,
+ 108,
+ 97,
+ 104
+ ],
+ "endsWith": true,
+ "escapeStringBash": "'test '\"'\"'test'\"'\"'test'",
+ "escapeStringDollars": "test 'test'test",
+ "escapeStringJson": "\"test 'test'test\"",
+ "escapeStringPython": "\"test 'test'test\"",
+ "exp": 148.4131591025766,
+ "exponent": 3,
+ "filter": [
+ 2,
+ 4
+ ],
+ "filterMap": [
+ 4,
+ 8
+ ],
+ "find": [
+ 2,
+ 4
+ ],
+ "findSubstr": [
+ 0,
+ 5
+ ],
+ "flatMap": [
+ 2,
+ 3,
+ 4,
+ 6,
+ 6,
+ 9
+ ],
+ "flattenArrays": [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5,
+ [
+ 6,
+ 7
+ ]
+ ],
+ "floor": 5,
+ "foldl": [
+ 0,
+ 1,
+ 2,
+ 3
+ ],
+ "foldr": [
+ 1,
+ 2,
+ 3,
+ 4
+ ],
+ "format": "test blah 42",
+ "get": [
+ 17,
+ 42,
+ 18,
+ 42
+ ],
+ "isArray": true,
+ "isBoolean": true,
+ "isFunction": true,
+ "isNumber": true,
+ "isObject": true,
+ "isString": true,
+ "join": "a,b,c",
+ "length": 0,
+ "lines": "a\nb\nc\n",
+ "log": 1.6094379124341003,
+ "lstripChars": "bbbbcccc",
+ "makeArray": [
+ 0,
+ 1,
+ 2,
+ 3,
+ 4
+ ],
+ "manifestIni": "a = 1\nb = 2\n[s1]\nx = 1\ny = 2\n",
+ "manifestJsonEx": "{\n \"a\": {\n \"b\": \"c\"\n }\n}",
+ "manifestJsonMinified": "{\"a\":{\"b\":\"c\"}}",
+ "manifestPython": "{\"a\": {\"b\": \"c\"}}",
+ "manifestPythonVars": "a = {\"b\": \"c\"}\n",
+ "manifestTomlEx": "[a]\n b = \"c\"",
+ "manifestXmlJsonml": "<blah a=\"42\"></blah>",
+ "manifestYamlDoc": "\"a\":\n \"b\": \"c\"",
+ "manifestYamlStream": "---\n42\n---\n\"a\":\n \"b\": \"c\"\n...\n",
+ "mantissa": 0.6249999999999999,
+ "map": [
+ -1,
+ -2,
+ -3
+ ],
+ "mapWithIndex": [
+ 3,
+ 3,
+ 3
+ ],
+ "mapWithKey": {
+ "a": 42
+ },
+ "max": 3,
+ "md5": "1bc29b36f623ba82aaf6724fd3b16718",
+ "member": true,
+ "mergePatch": { },
+ "min": 2,
+ "objectFields": [ ],
+ "objectFieldsAll": [ ],
+ "objectHas": false,
+ "objectHasAll": false,
+ "objectKeysValues": [ ],
+ "objectKeysValuesAll": [ ],
+ "objectValues": [ ],
+ "objectValuesAll": [ ],
+ "parseHex": 3735928559,
+ "parseInt": 42,
+ "parseJson": {
+ "a": "b"
+ },
+ "parseOctal": 83,
+ "pow": 8,
+ "prune": {
+ "y": [
+ "42"
+ ]
+ },
+ "range": [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5
+ ],
+ "repeat": "foofoofoo",
+ "reverse": [
+ "a",
+ "b"
+ ],
+ "rstripChars": "aaabbbb",
+ "set": [
+ [
+ 1,
+ 2,
+ 3
+ ],
+ [
+ 3,
+ 2,
+ 1
+ ]
+ ],
+ "setDiff": [
+ [
+ 1,
+ 2
+ ],
+ [
+ 1,
+ 3
+ ]
+ ],
+ "setInter": [
+ [
+ 3
+ ],
+ [
+ 2
+ ]
+ ],
+ "setMember": [
+ false,
+ true
+ ],
+ "setUnion": [
+ [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5
+ ],
+ [
+ 1,
+ 2,
+ 3,
+ 4,
+ 5
+ ]
+ ],
+ "sign": 1,
+ "sin": -0.9589242746631385,
+ "slice": "o",
+ "sort": [
+ [
+ 1,
+ 2,
+ 3
+ ],
+ [
+ 3,
+ 2,
+ 1
+ ]
+ ],
+ "split": [
+ "a",
+ "b",
+ "c"
+ ],
+ "splitLimit": [
+ "a",
+ "b,c"
+ ],
+ "splitLimitR": [
+ "a,b",
+ "c"
+ ],
+ "sqrt": 2.23606797749979,
+ "startsWith": true,
+ "strReplace": "bba",
+ "stringChars": [
+ "b",
+ "l",
+ "a",
+ "h"
+ ],
+ "stripChars": "bbbb",
+ "substr": "s",
+ "tan": -3.380515006246586,
+ "thisFile": "stdlib_smoke_test.jsonnet",
+ "toString": "42",
+ "type": "object",
+ "uniq": [
+ [
+ 1,
+ 2,
+ 3
+ ],
+ [
+ "a",
+ "B",
+ "a"
+ ]
+ ]
+}
\ No newline at end of file
tests/go_testdata_golden_override/strReplace3.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/strReplace3.jsonnet.golden
@@ -0,0 +1,2 @@
+runtime error: 'from' string must not be zero length
+ strReplace3.jsonnet:1:1-36: function <builtin_str_replace> call
\ No newline at end of file
tests/go_testdata_golden_override/string_divided_by_number.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/string_divided_by_number.jsonnet.golden
@@ -0,0 +1 @@
+binary operation string / number is not implemented
\ No newline at end of file
tests/go_testdata_golden_override/string_index_negative.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/string_index_negative.jsonnet.golden
@@ -0,0 +1 @@
+array out of bounds: -1 is not within [0,4)
\ No newline at end of file
tests/go_testdata_golden_override/string_index_out_of_bounds.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/string_index_out_of_bounds.jsonnet.golden
@@ -0,0 +1 @@
+string out of bounds: 4 is not within [0,4)
\ No newline at end of file
tests/go_testdata_golden_override/string_minus_number.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/string_minus_number.jsonnet.golden
@@ -0,0 +1 @@
+binary operation string - number is not implemented
\ No newline at end of file
tests/go_testdata_golden_override/string_plus_function.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/string_plus_function.jsonnet.golden
@@ -0,0 +1 @@
+runtime error: tried to manifest function
\ No newline at end of file
tests/go_testdata_golden_override/supersugar8.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/supersugar8.jsonnet.golden
@@ -0,0 +1,2 @@
+assert failed: null
+ supersugar8.jsonnet:1:10-17: assertion failure
\ No newline at end of file
tests/go_testdata_golden_override/syntax_error.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/syntax_error.jsonnet.golden
@@ -0,0 +1,2 @@
+syntax error: expected one of "(", "[", "{", <identifier>, <number>, <string>, <unary op>, ['"'], ['\''], got "EOF"
+ syntax_error.jsonnet:1:5
\ No newline at end of file
tests/go_testdata_golden_override/tailstrict2.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/tailstrict2.jsonnet.golden
@@ -0,0 +1,3 @@
+runtime error: xxx
+ tailstrict2.jsonnet:1:13-21: error statement
+ tailstrict2.jsonnet:2:14-19: function <e> call
\ No newline at end of file
tests/go_testdata_golden_override/too_many_arguments.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/too_many_arguments.jsonnet.golden
@@ -0,0 +1,3 @@
+too many args, function has 3
+Function has the following signature: (x, y, z)
+ too_many_arguments.jsonnet:1:1-36: function <anonymous> call
\ No newline at end of file
tests/go_testdata_golden_override/type_error.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/type_error.jsonnet.golden
@@ -0,0 +1,4 @@
+runtime error: xxx
+ type_error.jsonnet:1:10-22: error statement
+ argument <x> evaluation
+ type_error.jsonnet:1:1-23: function <builtin_type> call
\ No newline at end of file
tests/go_testdata_golden_override/unary_minus4.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/unary_minus4.jsonnet.golden
@@ -0,0 +1 @@
+operator - does not operate on type string
\ No newline at end of file
tests/go_testdata_golden_override/unary_object.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/unary_object.jsonnet.golden
@@ -0,0 +1 @@
+operator + does not operate on type object
\ No newline at end of file
tests/go_testdata_golden_override/unfinished_args.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/unfinished_args.jsonnet.golden
@@ -0,0 +1,2 @@
+syntax error: expected one of "(", ")", ".", "?", "[", "{", <binary op>, got "EOF"
+ unfinished_args.jsonnet:1:18
\ No newline at end of file
tests/go_testdata_golden_override/variable_not_visible.jsonnet.goldendiffbeforeafterboth--- /dev/null
+++ b/tests/go_testdata_golden_override/variable_not_visible.jsonnet.golden
@@ -0,0 +1,3 @@
+local is not defined: nested
+ variable_not_visible.jsonnet:1:44-51: local <nested> access
+ variable_not_visible.jsonnet:1:52-55: local <x2> access
\ No newline at end of file
tests/tests/cpp_test_suite.rsdiffbeforeafterboth--- a/tests/tests/cpp_test_suite.rs
+++ b/tests/tests/cpp_test_suite.rs
@@ -183,6 +183,15 @@
"number_leading_zero.jsonnet",
// Jrsonnet has this overload
"number_times_string.jsonnet",
+ // Jrsonnet has stricter implementations, this is a dumb thing that the filter value might not be
+ // evaluated anyway...
+ "std.filter7.jsonnet",
+ // Golang fails with max stack frames exceeded error
+ "std.makeArray_recursive_evalutation_order_matters.jsonnet",
+ // Jrsonnet has this overload
+ "string_times_number.jsonnet",
+ // Tailstrict semantics is partially unspecified
+ "tailstrict3.jsonnet",
];
#[test]
@@ -244,17 +253,21 @@
"expected error for golden {}:\n<got>\n{result}\n</got>\n<golden>\n{golden}\n</golden>",
entry.path().display()
),
- (Ok(result), Ok(golden)) => {
+ (Ok(result_v), Ok(golden)) => {
// Show diff relative to golden`.
- let diff = JsonDiff::diff_string(&golden, &result, false);
+ let diff = JsonDiff::diff_string(&golden, &result_v, false);
if let Some(diff) = diff {
- panic!(
- "Result \n{result:#}\n\
- and golden \n{golden:#}\n\
- did not match structurally:\n{diff:#}\n\
- for golden {}",
- entry.path().display()
- );
+ if env::var_os("UPDATE_GOLDEN").is_some() {
+ fs::write(golden_override, result)?;
+ } else {
+ panic!(
+ "Result \n{result_v:#}\n\
+ and golden \n{golden:#}\n\
+ did not match structurally:\n{diff:#}\n\
+ for golden {}",
+ entry.path().display()
+ );
+ }
}
}
(Err(_), Err(_)) => {