@@ -6,20 +6,12 @@ const Lexer = require('../../src/Lexer');
66const nb = require ( '../nodeBuilder' ) ;
77
88const {
9- OPERATOR_EQUALS ,
10- OPERATOR_NOT_EQUALS ,
11- OPERATOR_STRICT_EQUALS ,
12- OPERATOR_STRICT_NOT_EQUALS ,
139 OPERATOR_AND ,
1410 OPERATOR_OR ,
15- OPERATOR_NOT ,
1611 OPERATOR_GREATER_THAN ,
17- OPERATOR_LESS_THAN ,
18- OPERATOR_GREATER_EQUAL_THAN ,
19- OPERATOR_LESS_EQUAL_THAN ,
2012} = require ( '../../src/constants' ) ;
2113
22- describe . only ( 'Parser.generateExpression' , function ( ) {
14+ describe ( 'Parser.generateExpression' , function ( ) {
2315 [
2416 {
2517 description : 'with base binary operator' ,
@@ -31,13 +23,99 @@ describe.only('Parser.generateExpression', function() {
3123 )
3224 } ,
3325 {
34- description : 'with nested expression operator ' ,
26+ description : 'with expression chain ' ,
3527 input : 'a > b > c' ,
28+ expected : nb . binaryExpression (
29+ nb . binaryExpression (
30+ nb . variable ( 'a' ) ,
31+ nb . variable ( 'b' ) ,
32+ OPERATOR_GREATER_THAN
33+ ) ,
34+ nb . variable ( 'c' ) ,
35+ OPERATOR_GREATER_THAN
36+ )
37+ } ,
38+ {
39+ description : 'with brackets on the right' ,
40+ input : 'a > (b > c)' ,
3641 expected : nb . binaryExpression (
3742 nb . variable ( 'a' ) ,
38- nb . variable ( 'b' ) ,
43+ nb . binaryExpression (
44+ nb . variable ( 'b' ) ,
45+ nb . variable ( 'c' ) ,
46+ OPERATOR_GREATER_THAN
47+ ) ,
48+ OPERATOR_GREATER_THAN
49+ )
50+ } ,
51+ {
52+ description : 'with brackets on the left' ,
53+ input : '(a > b) > c' ,
54+ expected : nb . binaryExpression (
55+ nb . binaryExpression (
56+ nb . variable ( 'a' ) ,
57+ nb . variable ( 'b' ) ,
58+ OPERATOR_GREATER_THAN
59+ ) ,
60+ nb . variable ( 'c' ) ,
3961 OPERATOR_GREATER_THAN
4062 )
63+ } ,
64+ {
65+ description : 'with ors and ands' ,
66+ input : 'a || b && c' ,
67+ expected : nb . binaryExpression (
68+ nb . variable ( 'a' ) ,
69+ nb . binaryExpression (
70+ nb . variable ( 'b' ) ,
71+ nb . variable ( 'c' ) ,
72+ OPERATOR_AND
73+ ) ,
74+ OPERATOR_OR
75+ )
76+ } ,
77+ {
78+ description : 'with a not on the left' ,
79+ input : '!a || b' ,
80+ expected : nb . binaryExpression (
81+ nb . notConditional ( nb . variable ( 'a' ) ) ,
82+ nb . variable ( 'b' ) ,
83+ OPERATOR_OR
84+ )
85+ } ,
86+ {
87+ description : 'with a not on the right' ,
88+ input : 'a || !b' ,
89+ expected : nb . binaryExpression (
90+ nb . variable ( 'a' ) ,
91+ nb . notConditional ( nb . variable ( 'b' ) ) ,
92+ OPERATOR_OR
93+ )
94+ } ,
95+ {
96+ description : 'with a variable' ,
97+ input : 'a' ,
98+ expected : nb . variable ( 'a' )
99+ } ,
100+ {
101+ description : 'with a integer value' ,
102+ input : '123' ,
103+ expected : nb . value ( 123 )
104+ } ,
105+ {
106+ description : 'with a float value' ,
107+ input : '123.34' ,
108+ expected : nb . value ( 123.34 )
109+ } ,
110+ {
111+ description : 'with a single quote string' ,
112+ input : '\'foo\'' ,
113+ expected : nb . value ( 'foo' )
114+ } ,
115+ {
116+ description : 'with a double quote string' ,
117+ input : '"foo"' ,
118+ expected : nb . value ( 'foo' )
41119 }
42120 ] . forEach ( ( testCase ) => {
43121 it ( `should parse ${ testCase . description } ` , function ( ) {
0 commit comments