@@ -190,6 +190,34 @@ describe('woql queries', () => {
190190 expect ( woqlObject . json ( ) ) . to . eql ( woqlMathJson . evalJson ) ;
191191 } ) ;
192192
193+ it ( 'check the evaluate method (functional style)' , ( ) => {
194+ const woqlObject = WOQL . evaluate ( '1+2' , 'b' ) ;
195+ expect ( woqlObject . json ( ) ) . to . eql ( woqlMathJson . evalJson ) ;
196+ } ) ;
197+
198+ it ( 'check the evaluate method (fluent style)' , ( ) => {
199+ // Test the reported bug: WOQL.limit(100).evaluate(...)
200+ const woqlObject = WOQL . limit ( 100 ) . evaluate ( WOQL . times ( 2 , 3 ) , 'v:result' ) ;
201+ const json = woqlObject . json ( ) ;
202+
203+ // Should have Limit with nested query
204+ expect ( json ) . to . have . property ( '@type' , 'Limit' ) ;
205+ expect ( json ) . to . have . property ( 'limit' , 100 ) ;
206+ expect ( json ) . to . have . property ( 'query' ) ;
207+
208+ // Nested query should be Eval
209+ expect ( json . query ) . to . have . property ( '@type' , 'Eval' ) ;
210+ expect ( json . query ) . to . have . property ( 'expression' ) ;
211+ expect ( json . query . expression ) . to . have . property ( '@type' , 'Times' ) ;
212+ } ) ;
213+
214+ it ( 'check evaluate and eval produce identical results' , ( ) => {
215+ const withEval = WOQL . limit ( 10 ) . eval ( WOQL . plus ( 5 , 3 ) , 'x' ) ;
216+ const withEvaluate = WOQL . limit ( 10 ) . evaluate ( WOQL . plus ( 5 , 3 ) , 'x' ) ;
217+
218+ expect ( withEval . json ( ) ) . to . deep . eql ( withEvaluate . json ( ) ) ;
219+ } ) ;
220+
193221 it ( 'check the minus method' , ( ) => {
194222 const woqlObject = WOQL . minus ( '2' , '1' ) ;
195223 expect ( woqlObject . json ( ) ) . to . eql ( woqlMathJson . minusJson ) ;
@@ -490,7 +518,6 @@ describe('woql queries', () => {
490518 WOQL . eval ( WOQL . times ( 3 , 4 ) , v . a ) ,
491519 WOQL . eval ( WOQL . times ( v . a , 3 ) , v . res )
492520 ) . json ( ) ;
493- console . log ( JSON . stringify ( wq ) ) ;
494521 expect ( wq ) . to . deep . eql (
495522 { "@type" :"And" , "and" :[ { "@type" :"Eval" , "expression" :{ "@type" :"Times" , "left" :{ "@type" :"ArithmeticValue" , "data" :{ "@type" :"xsd:decimal" , "@value" :3 } } , "right" :{ "@type" :"ArithmeticValue" , "data" :{ "@type" :"xsd:decimal" , "@value" :4 } } } , "result" :{ "@type" :"ArithmeticValue" , "variable" :"a" } } , { "@type" :"Eval" , "expression" :{ "@type" :"Times" , "left" :{ "@type" :"ArithmeticValue" , "variable" :"a" } , "right" :{ "@type" :"ArithmeticValue" , "data" :{ "@type" :"xsd:decimal" , "@value" :3 } } } , "result" :{ "@type" :"ArithmeticValue" , "variable" :"res" } } ] } )
496523 } ) ;
0 commit comments