From 7a40814216f45494c279532545c69ad4b74d3dda Mon Sep 17 00:00:00 2001 From: Yann Hamdaoui Date: Fri, 11 Dec 2020 10:21:31 +0100 Subject: [PATCH] Test that Eq correctly clear the stack --- src/program.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/program.rs b/src/program.rs index e860e798..836c0c09 100644 --- a/src/program.rs +++ b/src/program.rs @@ -1307,6 +1307,33 @@ Assume(#alwaysTrue, false) assert_npeq!("{ a = { a = true } }", "{a = { a = { a = true } } }"); } + // Now that the equality operator directly uses the stack to store its continuation (see + // https://github.com/tweag/nickel/pull/247), check that it correctly cleans the stack when + // evaluating a subequality to `false`. + #[test] + fn poly_eq_nested() { + // Generate an non-empty evaluation context to evaluate equalities over a non-empty stack + let with_context = |t1, t2| { + format!("let not = fun b => if b then true else false in not (not (not (not (({}) == ({})))))", t1, t2) + }; + + assert_peq!( + with_context( + "{a = 1 + 0; b = 1 + 1; c = 0; d = 0}", + "{ a = 1; b = 3; c = 0; d = 0}" + ), + "false" + ); + + assert_peq!( + with_context( + "[[1,2,3,4], [1,0,3,4], [1,2,3,4], [1,2,3,4]]", + "[[1,2,3,4], [1,2,3,4], [1,2,3,4], [1,2,3,4]]" + ), + "false" + ); + } + #[test] fn fields_of() { assert_peq!("%fieldsOf% {}", "[]");