better tests for logical expressions

Two of the original checks were not testing what they were supposed to
test, because the result of eval didn't depend on correct parsing:

    eval("not true or not true")
    correct parse:      ((not true) or (not true)) == false
    incorrect parse:    (not (true or (not true))) == false

    eval("not false and not false")
    correct parse:      ((not false) and (not false)) == true
    incorrect parse:    (not (false and (not false))) == true
This commit is contained in:
Mickey Rose 2020-01-02 17:30:24 +01:00
parent f19bd188c2
commit d38d16ade9

View file

@ -153,10 +153,10 @@ TEST_CASE("expressions")
// logical // logical
TRY_CHECK(eval(" [int] = 123 and [double] = 1.23456 && [bool] = true and [null] = null && [foo] = 'bar' ") == true); TRY_CHECK(eval(" [int] = 123 and [double] = 1.23456 && [bool] = true and [null] = null && [foo] = 'bar' ") == true);
TRY_CHECK(eval(" [int] = 456 or [foo].match('foo') || length([foo]) = 3 ") == true); TRY_CHECK(eval(" [int] = 456 or [foo].match('foo') || length([foo]) = 3 ") == true);
TRY_CHECK(eval(" not true and not true ") == eval(" (not true ) and (not true ) ")); TRY_CHECK(eval(" not true and not true ") == false); // (not true) and (not true)
TRY_CHECK(eval(" not true or not true ") == eval(" (not true ) or (not true ) ")); TRY_CHECK(eval(" not false and not true ") == false); // (not false) and (not true)
TRY_CHECK(eval(" not false and not false ") == eval(" (not false) and (not false) ")); TRY_CHECK(eval(" not true or not false ") == true); // (not true) or (not false)
TRY_CHECK(eval(" not false or not false ") == eval(" (not false) or (not false) ")); TRY_CHECK(eval(" not false or not false ") == true); // (not false) or (not false)
// test not/and/or precedence using combinations of "not EQ1 OP1 not EQ2 OP2 not EQ3" // test not/and/or precedence using combinations of "not EQ1 OP1 not EQ2 OP2 not EQ3"
TRY_CHECK(eval(" not [grass] = 'grow' and not [wind] = 'blow' and not [sky] = 'is blue' ") == false); TRY_CHECK(eval(" not [grass] = 'grow' and not [wind] = 'blow' and not [sky] = 'is blue' ") == false);