@@ -13,11 +13,21 @@ class SyntaxTest extends FlatSpec with Matchers {
1313 " Syntax.singularConditionWithOperator" should " be valid" in {
1414 val parseResult = new Syntax (" Filter1=abc" ).QueryRule .run()
1515 parseResult shouldBe a [Success [_]]
16+ parseResult match {
17+ case Success (ast) => {
18+ ast.toString shouldEqual " EqualExpr(Filter1,abc)"
19+ }
20+ }
1621 }
1722
1823 " Syntax.singularConditionNoOperator" should " be valid" in {
1924 val parseResult = new Syntax (" Filter1" ).QueryRule .run()
2025 parseResult shouldBe a [Success [_]]
26+ parseResult match {
27+ case Success (ast) => {
28+ ast.toString shouldEqual " TrueExpr(Filter1)"
29+ }
30+ }
2131 }
2232
2333 " Syntax.singularConditionTypo" should " be valid" in {
@@ -33,16 +43,33 @@ class SyntaxTest extends FlatSpec with Matchers {
3343 " Syntax.combinatoryConditionSimple" should " be valid" in {
3444 val parseResult = new Syntax (" Filter1&&Filter2=3" ).QueryRule .run()
3545 parseResult shouldBe a [Success [_]]
46+ parseResult match {
47+ case Success (ast) => {
48+ ast.toString shouldEqual " AndExpr(TrueExpr(Filter1),EqualExpr(Filter2,3))"
49+ }
50+ }
3651 }
3752
3853 " Syntax.combinatoryConditionParentheses" should " be valid" in {
39- val parseResult = new Syntax (" Filter1||Filter2&&(Filter3<3||Filter4>0)" ).QueryRule .run()
54+ val parseResult = new Syntax (" Filter1||( Filter2&&(Filter3<3||Filter4>0) )" ).QueryRule .run()
4055 parseResult shouldBe a [Success [_]]
56+ parseResult match {
57+ case Success (ast) => {
58+ ast.toString shouldEqual " OrExpr(TrueExpr(Filter1),AndExpr(TrueExpr(Filter2)," +
59+ " OrExpr(LessThanExpr(Filter3,3),GreaterThanExpr(Filter4,0))))"
60+ }
61+ }
4162 }
4263
4364 " Syntax.combinatoryConditionParenthesesComplex" should " be valid" in {
44- val parseResult = new Syntax (" Filter1&&(Filter2<3||Filter2>0%%(Filter4&&Filter5))" ).QueryRule .run()
65+ val parseResult = new Syntax (" Filter1&&(( Filter2<3||Filter2>0) %%(Filter4&&Filter5))" ).QueryRule .run()
4566 parseResult shouldBe a [Success [_]]
67+ parseResult match {
68+ case Success (ast) => {
69+ ast.toString shouldEqual " AndExpr(TrueExpr(Filter1),XorExpr(OrExpr(LessThanExpr(Filter2,3)," +
70+ " GreaterThanExpr(Filter2,0)),AndExpr(TrueExpr(Filter4),TrueExpr(Filter5))))"
71+ }
72+ }
4673 }
4774
4875 " Syntax.combinatoryConditionNonMatchingParentheses" should " be valid" in {
@@ -55,19 +82,69 @@ class SyntaxTest extends FlatSpec with Matchers {
5582 parseResult shouldBe a [Failure [_]]
5683 }
5784
85+ " Syntax.combinatoryConditionLeftToRightPriority" should " be valid" in {
86+ val parseResult = new Syntax (" Filter1&&Filter2&&Filter3" ).QueryRule .run()
87+ parseResult shouldBe a [Success [_]]
88+ parseResult match {
89+ case Success (ast) => {
90+ ast.toString shouldEqual " AndExpr(AndExpr(TrueExpr(Filter1)," +
91+ " TrueExpr(Filter2)),TrueExpr(Filter3))"
92+ }
93+ }
94+ }
95+
96+ " Syntax.combinatoryConditionOperatorPriorities" should " be valid" in {
97+ val parseResult = new Syntax (" Filter1||Filter2%%!Filter3&&Filter4" ).QueryRule .run()
98+ parseResult shouldBe a [Success [_]]
99+ parseResult match {
100+ case Success (ast) => {
101+ ast.toString shouldEqual " OrExpr(TrueExpr(Filter1),AndExpr(XorExpr(" +
102+ " TrueExpr(Filter2),NotExpr(TrueExpr(Filter3))),TrueExpr(Filter4)))"
103+ }
104+ }
105+ }
106+
107+ " Syntax.combinatoryConditionOperatorPrioritiesParentheses" should " be valid" in {
108+ val parseResult = new Syntax (" (Filter1||Filter2)&&!Filter3%%!(Filter4&&Filter5)" ).QueryRule .run()
109+ parseResult shouldBe a [Success [_]]
110+ parseResult match {
111+ case Success (ast) => {
112+ ast.toString shouldEqual " AndExpr(OrExpr(TrueExpr(Filter1),TrueExpr(Filter2))," +
113+ " XorExpr(NotExpr(TrueExpr(Filter3)),NotExpr(AndExpr(TrueExpr(Filter4)," +
114+ " TrueExpr(Filter5)))))"
115+ }
116+ }
117+ }
118+
58119 " Syntax.notConditionSimple" should " be valid" in {
59120 val parseResult = new Syntax (" Filter1&&!Filter2" ).QueryRule .run()
60121 parseResult shouldBe a [Success [_]]
122+ parseResult match {
123+ case Success (ast) => {
124+ ast.toString shouldEqual " AndExpr(TrueExpr(Filter1),NotExpr(TrueExpr(Filter2)))"
125+ }
126+ }
61127 }
62128
63129 " Syntax.notConditionSimpleParentheses" should " be valid" in {
64130 val parseResult = new Syntax (" !(Filter1&&Filter2)" ).QueryRule .run()
65131 parseResult shouldBe a [Success [_]]
132+ parseResult match {
133+ case Success (ast) => {
134+ ast.toString shouldEqual " NotExpr(AndExpr(TrueExpr(Filter1),TrueExpr(Filter2)))"
135+ }
136+ }
66137 }
67138
68139 " Syntax.notConditionComplex" should " be valid" in {
69140 val parseResult = new Syntax (" !!(Filter1)&&!(Filter2<=0||!(Filter3&&!Filter4%abc))" ).QueryRule .run()
70141 parseResult shouldBe a [Success [_]]
142+ parseResult match {
143+ case Success (ast) => {
144+ ast.toString shouldEqual " AndExpr(NotExpr(NotExpr(TrueExpr(Filter1)))," +
145+ " NotExpr(OrExpr(LessOrEqualExpr(Filter2,0),NotExpr(AndExpr(TrueExpr(Filter3)," +
146+ " NotExpr(LikeExpr(Filter4,abc)))))))"
147+ }
148+ }
71149 }
72-
73150}
0 commit comments