@@ -30,6 +30,55 @@ describe('Unit: Stage 2 (AST)', () => {
3030 }
3131 } ) ;
3232
33+ it ( 'should parse comparisons as LiquidVariable > BooleanExpression > Comparison' , ( ) => {
34+ [
35+ { expression : `1 == 1` } ,
36+ { expression : `1 != 1` } ,
37+ { expression : `1 > 1` } ,
38+ { expression : `1 < 1` } ,
39+ { expression : `1 >= 1` } ,
40+ { expression : `1 <= 1` } ,
41+ ] . forEach ( ( { expression } ) => {
42+ for ( const { toAST, expectPath, expectPosition } of testCases ) {
43+ ast = toAST ( `{{ ${ expression } }}` ) ;
44+ expectPath ( ast , 'children.0' ) . to . exist ;
45+ expectPath ( ast , 'children.0.type' ) . to . eql ( 'LiquidVariableOutput' ) ;
46+ expectPath ( ast , 'children.0.markup.type' ) . to . eql ( 'LiquidVariable' ) ;
47+ expectPath ( ast , 'children.0.markup.rawSource' ) . to . eql ( expression ) ;
48+ expectPath ( ast , 'children.0.markup.expression.type' ) . to . eql ( 'BooleanExpression' ) ;
49+ expectPath ( ast , 'children.0.markup.expression.condition.type' ) . to . eql ( 'Comparison' ) ;
50+ expectPosition ( ast , 'children.0' ) ;
51+ expectPosition ( ast , 'children.0.markup' ) ;
52+ expectPosition ( ast , 'children.0.markup.expression' ) ;
53+ }
54+ } ) ;
55+ } ) ;
56+
57+ it ( 'should parse logical operations as LiquidVariable > BooleanExpression > LogicalExpression' , ( ) => {
58+ [
59+ { expression : `1 == 1 and 2 == 2` } ,
60+ { expression : `1 == 1 or 2 == 2` } ,
61+ { expression : `1 == 1 and 2 == 2 or 3 == 3` } ,
62+ { expression : `1 == 1 and some_variable or 3 == 3` } ,
63+ { expression : `some_var and 'raw string'` } ,
64+ ] . forEach ( ( { expression } ) => {
65+ for ( const { toAST, expectPath, expectPosition } of testCases ) {
66+ ast = toAST ( `{{ ${ expression } }}` ) ;
67+ expectPath ( ast , 'children.0' ) . to . exist ;
68+ expectPath ( ast , 'children.0.type' ) . to . eql ( 'LiquidVariableOutput' ) ;
69+ expectPath ( ast , 'children.0.markup.type' ) . to . eql ( 'LiquidVariable' ) ;
70+ expectPath ( ast , 'children.0.markup.rawSource' ) . to . eql ( expression ) ;
71+ expectPath ( ast , 'children.0.markup.expression.type' ) . to . eql ( 'BooleanExpression' ) ;
72+ expectPath ( ast , 'children.0.markup.expression.condition.type' ) . to . eql (
73+ 'LogicalExpression' ,
74+ ) ;
75+ expectPosition ( ast , 'children.0' ) ;
76+ expectPosition ( ast , 'children.0.markup' ) ;
77+ expectPosition ( ast , 'children.0.markup.expression' ) ;
78+ }
79+ } ) ;
80+ } ) ;
81+
3382 it ( 'should parse strings as LiquidVariable > String' , ( ) => {
3483 [
3584 { expression : `"string o' string"` , value : `string o' string` , single : false } ,
0 commit comments