logical tests

This commit is contained in:
Umur Ozkul 2022-05-19 17:00:00 +02:00
parent 470a6add42
commit 0753311b93

View File

@ -91,6 +91,29 @@ describe("Peggy parse", () => {
) //nested if
})
describe("logical", ()=> {
testParse("true || false", "{(::or true false)}")
testParse("true && false", "{(::and true false)}")
testParse("a && b || c", "{(::and :a (::or :b :c))}")
testParse("a && b || c && d", "{(::and (::and :a (::or :b :c)) :d)}")
testParse("a && !b || c", "{(::and :a (::or (::not :b) :c))}")
testParse("a && b==c || d", "{(::and :a (::or (::equal :b :c) :d))}")
testParse("a && b!=c || d", "{(::and :a (::or (::unequal :b :c) :d))}")
testParse("a && !(b==c) || d", "{(::and :a (::or (::not (::equal :b :c)) :d))}")
testParse("a && b>=c || d", "{(::and :a (::or (::largerEq :b :c) :d))}")
testParse("a && !(b>=c) || d", "{(::and :a (::or (::not (::largerEq :b :c)) :d))}")
testParse("a && b<=c || d", "{(::and :a (::or (::smallerEq :b :c) :d))}")
testParse("a && b>c || d", "{(::and :a (::or (::larger :b :c) :d))}")
testParse("a && b<c || d", "{(::and :a (::or (::smaller :b :c) :d))}")
testParse("a && b<c[i] || d", "{(::and :a (::or (::smaller :b (::$atIndex :c :i)) :d))}")
testParse("a && b<c.i || d", "{(::and :a (::or (::smaller :b (::$atIndex :c 'i')) :d))}")
testParse("a && b<c(i) || d", "{(::and :a (::or (::smaller :b (::c :i)) :d))}")
testParse("a && b<1+2 || d", "{(::and :a (::or (::smaller :b (::add 1 2)) :d))}")
testParse("a && b<1+2*3 || d", "{(::and :a (::or (::smaller :b (::add 1 (::multiply 2 3))) :d))}")
testParse("a && b<1+2*-3+4 || d", "{(::and :a (::or (::smaller :b (::add (::add 1 (::multiply 2 (::unaryMinus 3))) 4)) :d))}")
testParse("a && b<1+2*3 || d ? true : false", "{(::$$ternary (::and :a (::or (::smaller :b (::add 1 (::multiply 2 3))) :d)) true false)}")
})
describe("pipe", () => {
testParse("1 -> add(2)", "{(::add 1 2)}")
testParse("-1 -> add(2)", "{(::add (::unaryMinus 1) 2)}")