/* Ċ Ġ* ĠCopyright Ġ 2 0 2 0 ĠGoogle ĠLLC . Ċ Ġ* Ċ Ġ* ĠThis Ġcode Ġmay Ġonly Ġbe Ġused Ġunder Ġthe ĠBSD Ġstyle Ġlicense Ġfound Ġat Ċ Ġ* Ġhttp :// polymer . github . io / LICENSE . txt Ċ Ġ* Ċ Ġ* ĠCode Ġdistributed Ġby ĠGoogle Ġas Ġpart Ġof Ġthis Ġproject Ġis Ġalso Ġsubject Ġto Ġan Ġadditional ĠIP Ġrights Ċ Ġ* Ġgrant Ġfound Ġat Ċ Ġ* Ġhttp :// polymer . github . io / PAT ENTS . txt Ċ Ġ*/ Ċ Ċ package Ġar cs . core . data . expression Ċ Ċ import Ġar cs . core . data . expression . Expression . Scope Ċ import Ġcom . google . common . truth . Truth . assertThat Ċ import Ġkotlin . test . assert Fails With Ċ import Ġorg . junit . Test Ċ import Ġorg . junit . runner . RunWith Ċ import Ġorg . junit . runners . JUnit 4 Ċ Ċ /** ĠTests Ġfor Ġ[ Expression ]. Ġ*/ Ċ @ RunWith ( JUnit 4 :: class ) Ċ class ĠExpression Test Ġ{ ĊĠĠĠ Ġfun Ġ< T > Ġeval Bool ( expression : ĠExpression < T >) Ġ= Ġeval Expression < T >( ĊĠĠĠĠĠĠĠ Ġexpression , ĊĠĠĠĠĠĠĠ Ġcurrent Scope ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġfun Ġ< T > Ġeval Num ( expression : ĠExpression < T >) Ġ= Ġeval Expression < T >( ĊĠĠĠĠĠĠĠ Ġexpression Ġ= Ġexpression , Ġcurrent Scope Ġ= Ġcurrent Scope ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġval Ġnumbers Ġ= ĠlistOf ( 1 , Ġ 2 , Ġ 3 , Ġ 4 , Ġ 5 , Ġ 6 , Ġ 7 , Ġ 8 , Ġ 9 , Ġ 1 0 ) ĊĊĠĠĠ Ġval Ġcurrent Scope Ġ= ĠCurrent Scope < Any >( ĊĠĠĠĠĠĠĠ Ġmutable Map Of ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" blah " Ġto Ġ 1 0 , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" baz " Ġto Ġmap Of (" x " Ġto Ġ 2 4 ). as Scope (), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" numbers " Ġto Ġnumbers ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ) ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ binary Ops () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġnumeric Ġbinary Ġops Ġ( ints ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 . as Expr () Ġ+ Ġ 1 . as Expr ())). isEqualTo ( 3 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 . as Expr () Ġ- Ġ 1 . as Expr ())). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 . as Expr () Ġ* Ġ 2 . as Expr ())). isEqualTo ( 4 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 6 . as Expr () Ġ/ Ġ 3 . as Expr ())). isEqualTo ( 2 ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġfloats ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 f . as Expr () Ġ+ Ġ 1 . as Expr ())). isEqualTo ( 3 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 f . as Expr () Ġ- Ġ 1 . as Expr ())). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 f . as Expr () Ġ* Ġ 2 . as Expr ())). isEqualTo ( 4 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 6 f . as Expr () Ġ/ Ġ 3 . as Expr ())). isEqualTo ( 2 ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġlong s ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 L . as Expr () Ġ+ Ġ 1 . as Expr ())). isEqualTo ( 3 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 L . as Expr () Ġ- Ġ 1 . as Expr ())). isEqualTo ( 1 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 L . as Expr () Ġ* Ġ 2 . as Expr ())). isEqualTo ( 4 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 6 L . as Expr () Ġ/ Ġ 3 . as Expr ())). isEqualTo ( 2 ) ĊĊĠĠĠĠĠĠĠ Ġ// Ġbig Ġints ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 . to BigInteger (). as Expr () Ġ+ Ġ 1 . as Expr ())). isEqualTo ( 3 . to BigInteger ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 . to BigInteger (). as Expr () Ġ- Ġ 1 . as Expr ())). isEqualTo ( 1 . to BigInteger ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 2 . to BigInteger (). as Expr () Ġ* Ġ 2 . as Expr ())). isEqualTo ( 4 . to BigInteger ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num ( 6 . to BigInteger (). as Expr () Ġ/ Ġ 3 . as Expr ())). isEqualTo ( 2 . to BigInteger ()) ĊĠĠĠ Ġ} ĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ field Ops () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġfield Ġops ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num < Number >( map Of (" foo " Ġto Ġ 4 2 ). as Scope ()[" foo "] )). isEqualTo ( 4 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num < Number >( current Scope [" blah "]. as Number ())). isEqualTo ( 1 0 ) ĊĠĠĠĠĠĠĠ Ġval Ġbaz Ġ= Ġcurrent Scope [" baz "]. as Scope () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num < Number >( baz [" x "] )). isEqualTo ( 2 4 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ query Ops () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// Ġquery Ġops ĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Number >( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġquery (" arg "), Ġcurrent Scope , Ġ" arg " Ġto Ġ 4 2 ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ). isEqualTo ( 4 2 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ boolean Ops () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠBoolean Ġops ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 1 . as Expr () Ġlt Ġ 2 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 . as Expr () Ġlt Ġ 1 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 . as Expr () Ġl te Ġ 2 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 3 . as Expr () Ġl te Ġ 2 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 . as Expr () Ġgt Ġ 1 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 1 . as Expr () Ġgt Ġ 2 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 1 . as Expr () Ġg te Ġ 2 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 1 . as Expr () Ġlt Ġ 2 . as Expr ()) Ġand Ġ( 2 . as Expr () Ġgt Ġ 1 . as Expr ())) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 2 . as Expr () Ġlt Ġ 1 . as Expr ()) Ġand Ġ( 2 . as Expr () Ġgt Ġ 1 . as Expr ())) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 1 . as Expr () Ġlt Ġ 2 . as Expr ()) Ġor Ġ( 2 . as Expr () Ġlt Ġ 1 . as Expr ())) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 1 . as Expr () Ġgt Ġ 2 . as Expr ()) Ġor Ġ( 2 . as Expr () Ġlt Ġ 1 . as Expr ())) ). isFalse () ĊĊĠĠĠĠĠĠĠ Ġ// ĠSan ity Ġcheck Ġlong s Ġand Ġwid ening ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 1 L . as Expr () Ġlt Ġ 2 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 L . as Expr () Ġlt Ġ 1 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 L . as Expr () Ġl te Ġ 2 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 3 L . as Expr () Ġl te Ġ 2 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 L . as Expr () Ġgt Ġ 1 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 1 L . as Expr () Ġgt Ġ 2 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 1 L . as Expr () Ġg te Ġ 2 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 1 L . as Expr () Ġlt Ġ 2 . as Expr ()) Ġand Ġ( 2 L . as Expr () Ġgt Ġ 1 . as Expr ())) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 2 L . as Expr () Ġlt Ġ 1 . as Expr ()) Ġand Ġ( 2 L . as Expr () Ġgt Ġ 1 . as Expr ())) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 1 L . as Expr () Ġlt Ġ 2 . as Expr ()) Ġor Ġ( 2 L . as Expr () Ġlt Ġ 1 . as Expr ())) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 1 L . as Expr () Ġgt Ġ 2 . as Expr ()) Ġor Ġ( 2 L . as Expr () Ġlt Ġ 1 . as Expr ())) ). isFalse () ĊĊĠĠĠĠĠĠĠ Ġ// ĠSan ity Ġcheck ĠBigInteger ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 1 . to BigInteger (). as Expr () Ġlt Ġ 2 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 . to BigInteger (). as Expr () Ġlt Ġ 1 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 . to BigInteger (). as Expr () Ġl te Ġ 2 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 3 . to BigInteger (). as Expr () Ġl te Ġ 2 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 . to BigInteger (). as Expr () Ġgt Ġ 1 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 1 . to BigInteger (). as Expr () Ġgt Ġ 2 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 1 . to BigInteger (). as Expr () Ġg te Ġ 2 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 1 . to BigInteger (). as Expr () Ġlt Ġ 2 . as Expr ()) Ġand ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( 2 . to BigInteger (). as Expr () Ġgt Ġ 1 . to BigInteger (). as Expr ())) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 2 . to BigInteger (). as Expr () Ġlt Ġ 1 . as Expr ()) Ġand ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( 2 . to BigInteger (). as Expr () Ġgt Ġ 1 . to BigInteger (). as Expr ())) ). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 1 . to BigInteger (). as Expr () Ġlt Ġ 2 . as Expr ()) Ġor ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( 2 . to BigInteger (). as Expr () Ġlt Ġ 1 . to BigInteger (). as Expr ())) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (( 1 . to BigInteger (). as Expr () Ġgt Ġ 2 . as Expr ()) Ġor ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( 2 . to BigInteger (). as Expr () Ġlt Ġ 1 . to BigInteger (). as Expr ())) ). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ unary Ops () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠUnary Ġops ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num (- 2 . as Expr ())). isEqualTo (- 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (!( 2 . as Expr () Ġlt Ġ 1 . as Expr ())) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (!( 2 . as Expr () Ġgt Ġ 1 . as Expr ())) ). isFalse () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num (- 2 L . as Expr ())). isEqualTo (- 2 ) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (!( 2 L . as Expr () Ġlt Ġ 1 . as Expr ())) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (!( 2 L . as Expr () Ġgt Ġ 1 . as Expr ())) ). isFalse () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( eval Num (- 2 . to BigInteger (). as Expr ())). isEqualTo (- 2 . to BigInteger ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (!( 2 . to BigInteger (). as Expr () Ġlt Ġ 1 . as Expr ())) ). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (!( 2 . to BigInteger (). as Expr () Ġgt Ġ 1 . as Expr ())) ). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ equality Ops () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠE quality Ġops ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 . as Expr () Ġeq Ġ 2 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 . as Expr () Ġeq Ġ 1 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (" Hello ". as Expr () Ġeq Ġ" Hello ". as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (" Hello ". as Expr () Ġeq Ġ" World ". as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( true . as Expr () Ġeq Ġtrue . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( true . as Expr () Ġeq Ġfalse . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 . as Expr () Ġne q Ġ 1 . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( 2 . as Expr () Ġne q Ġ 2 . as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (" Hello ". as Expr () Ġne q Ġ" World ". as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool (" Hello ". as Expr () Ġne q Ġ" Hello ". as Expr ())). isFalse () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( true . as Expr () Ġne q Ġfalse . as Expr ())). isTrue () ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Bool ( true . as Expr () Ġne q Ġtrue . as Expr ())). isFalse () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ complex Expression () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠTest Ġcomplex Ġexpression ĊĠĠĠĠĠĠĠ Ġ// Ġ( 2 Ġ+ Ġ( 3 Ġ* Ġ 4 ) Ġ+ Ġscope . foo Ġ+ Ġ? arg Ġ- Ġ 1 ) Ġ/ Ġ 2 ĊĠĠĠĠĠĠĠ Ġval Ġobj Ġ= Ġmap Of (" foo " Ġto Ġ 4 2 ). as Scope (" handle ") ĊĠĠĠĠĠĠĠ Ġval Ġexpr Ġ= Ġ( 2 . 0 . as Expr () Ġ+ Ġ( 3 . as Expr () Ġ* Ġ 4 . as Expr ()) Ġ+ Ġobj [" foo "] Ġ+ Ġquery ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" arg " ĊĠĠĠĠĠĠĠ Ġ) Ġ- Ġ 1 . as Expr ()) Ġ/ Ġ 2 . as Expr () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( eval Expression < Number >( expr , Ġcurrent Scope , Ġ" arg " Ġto Ġ 1 )). isEqualTo ( 2 8 ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ p ax el _ from () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġfrom Expr Ġ= Ġfrom < Number >(" p ") Ġon Ġ" numbers " ĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Sequence < Number >>( from Expr , Ġcurrent Scope ). toList () ĊĠĠĠĠĠĠĠ Ġ). isEqualTo ( numbers ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ p ax el _ select () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġselect Expr Ġ= Ġfrom < Number >(" p ") Ġon Ġ" numbers " Ġselect Ġ 1 . as Expr () ĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Sequence < Number >>( select Expr , Ġcurrent Scope ). toList () ĊĠĠĠĠĠĠĠ Ġ). isEqualTo ( numbers . map Ġ{ Ġ 1 Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ p ax el _ where () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġwhere Expr Ġ= Ġfrom < Number >(" p ") Ġon Ġ" numbers " Ġwhere Ġ( current Scope [" p "] Ġeq Ġ 5 . as Expr ()) ĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Sequence < Number >>( where Expr , Ġcurrent Scope ). toList () ĊĠĠĠĠĠĠĠ Ġ). isEqualTo ( listOf ( 5 )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ p ax el _ max () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġselect Max Expr Ġ= Ġfrom < Number >(" p ") Ġon Ġ" numbers " Ġselect Ġmax ( current Scope [" numbers "]) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Sequence < Number >>( select Max Expr , Ġcurrent Scope ). toList () ĊĠĠĠĠĠĠĠ Ġ). isEqualTo ( numbers . map Ġ{ Ġnumbers . max () Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ p ax el _ count () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġselect Count Expr Ġ= Ġfrom < Number >(" p ") Ġon Ġ" numbers " Ġselect Ġcount ( current Scope [" numbers "]) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Sequence < Number >>( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġselect Count Expr , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Scope ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ). toList () ĊĠĠĠĠĠĠĠ Ġ). isEqualTo ( numbers . map Ġ{ Ġnumbers . size Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ p ax el _ min () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġselect Min Expr Ġ= Ġfrom < Number >(" p ") Ġon Ġ" numbers " Ġselect Ġmin ( current Scope [" numbers "]) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Sequence < Number >>( select Min Expr , Ġcurrent Scope ). toList () ĊĠĠĠĠĠĠĠ Ġ). isEqualTo ( numbers . map Ġ{ Ġ 1 Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ p ax el _ average () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġselect Avg Expr Ġ= Ġfrom < Number >(" p ") Ġon Ġ" numbers " Ġselect Ġaverage ( current Scope [" numbers "]) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Sequence < Number >>( select Avg Expr , Ġcurrent Scope ). toList () ĊĠĠĠĠĠĠĠ Ġ). isEqualTo ( numbers . map Ġ{ Ġ 5 . 5 Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ p ax el _ now () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġnow Expr Ġ= Ġnow () ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Long >( now Expr , Ġcurrent Scope ) ĊĠĠĠĠĠĠĠ Ġ). is At Least ( System . currentTimeMillis () Ġ- Ġ 1 0 0 0 L ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ p ax el _ union () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġless Than 8 Ġ= Ġfrom < Number >(" p ") Ġon Ġ" numbers " Ġwhere ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( current Scope [" p "]. as Number () Ġlt Ġ 8 . as Expr ()) ĊĠĠĠĠĠĠĠ Ġval Ġgreater Than 6 Ġ= Ġfrom < Number >(" p ") Ġon Ġ" numbers " Ġwhere ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( current Scope [" p "]. as Number () Ġgt Ġ 6 . as Expr ()) ĊĠĠĠĠĠĠĠ Ġval Ġunion Expr Ġ= Ġunion ( less Than 8 , Ġgreater Than 6 ) ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Sequence < Number >>( union Expr , Ġcurrent Scope ). toList () ĊĠĠĠĠĠĠĠ Ġ). isEqualTo ( numbers ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ p ax el _ expression () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠTest ĠExpression : ĊĠĠĠĠĠĠĠ Ġ// ĠFROM Ġp ĠIN Ġnumbers ĊĠĠĠĠĠĠĠ Ġ// ĠWHERE Ġp Ġ< Ġ 5 ĊĠĠĠĠĠĠĠ Ġ// ĠSELECT Ġnew ĠExample Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠĠ Ġx : Ġp Ġ+ Ġ 1 ĊĠĠĠĠĠĠĠ Ġ// ĠĠ Ġy : Ġp Ġ+ Ġ 2 ĊĠĠĠĠĠĠĠ Ġ// ĠĠ Ġz : ĠCOUNT ( numbers ) ĊĠĠĠĠĠĠĠ Ġ// Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġp ax el Expr Ġ= Ġfrom < Number >(" p ") Ġon Ġ" numbers " Ġwhere ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ( current Scope [" p "]. as Number () Ġlt Ġ 5 . as Expr ()) Ġselect Ġnew < Number , ĠScope >(" Example ") () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠlistOf ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" x " Ġto Ġcurrent Scope [" p "]. as Number () Ġ+ Ġ 1 . as Expr (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" y " Ġto Ġcurrent Scope [" p "]. as Number () Ġ+ Ġ 2 . as Expr (), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" z " Ġto Ġcount ( current Scope [" numbers "]) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ ĠassertThat ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Expression < Sequence < Scope >>( p ax el Expr , Ġcurrent Scope ). toList (). map Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ( it Ġas ĠMap Scope < *> ). map ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ). contains Exactly ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmap Of (" x " Ġto Ġ 2 , Ġ" y " Ġto Ġ 3 , Ġ" z " Ġto Ġ 1 0 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmap Of (" x " Ġto Ġ 3 , Ġ" y " Ġto Ġ 4 , Ġ" z " Ġto Ġ 1 0 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmap Of (" x " Ġto Ġ 4 , Ġ" y " Ġto Ġ 5 , Ġ" z " Ġto Ġ 1 0 ), ĊĠĠĠĠĠĠĠĠĠĠĠ Ġmap Of (" x " Ġto Ġ 5 , Ġ" y " Ġto Ġ 6 , Ġ" z " Ġto Ġ 1 0 ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ Expression With Scope Lookup Error _ throws () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġobj Ġ= Ġmap Of (" foo " Ġto Ġ 4 2 ). as Scope (" handle ") ĊĠĠĠĠĠĠĠ Ġval Ġexpr Ġ= Ġ 1 . as Expr () Ġ+ Ġobj [" bar "] ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Num ( expr ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġevaluate _ expression With QueryParam Lookup Error _ throws () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġexpr Ġ= Ġ 1 . as Expr () Ġ+ Ġquery (" arg ") ĊĠĠĠĠĠĠĠ Ġassert Fails With < IllegalArgumentException > Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġeval Num ( expr ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġfun Ġstringify () Ġ{ ĊĠĠĠĠĠĠĠ Ġ// ĠTest ĠMath Ġbinary Ġops , Ġfield Ġlook ups , Ġand Ġparameter Ġlook ups ĊĠĠĠĠĠĠĠ Ġ// Ġ( 2 Ġ+ Ġ( 3 Ġ* Ġ 4 ) Ġ+ Ġscope . foo Ġ+ Ġ? arg Ġ- Ġ 1 ) Ġ/ Ġ 2 ĊĠĠĠĠĠĠĠ Ġval Ġobj Ġ= Ġmap Of (" foo " Ġto Ġ 4 2 ). as Scope (" handle ") ĊĠĠĠĠĠĠĠ Ġval Ġexpr Ġ= Ġ( 2 . 0 . as Expr () Ġ+ Ġ( 3 . as Expr () Ġ* Ġ 4 . as Expr ()) Ġ+ Ġobj [" foo "] Ġ+ Ġquery ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" arg " ĊĠĠĠĠĠĠĠ Ġ) Ġ- Ġ 1 . as Expr ()) Ġ/ Ġ 2 . as Expr () ĊĠĠĠĠĠĠĠ ĠassertThat ( expr . toString ()). isEqualTo (" (((( 2 . 0 Ġ+ Ġ( 3 Ġ* Ġ 4 )) Ġ+ Ġhandle . foo ) Ġ+ Ġ? arg ) Ġ- Ġ 1 ) Ġ/ Ġ 2 ") ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Test ĊĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠ Ġfun Ġserialization _ round Trip () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġq Ġ= Ġquery < Scope >(" arg ") ĊĠĠĠĠĠĠĠ Ġval Ġfield Ġ= ĠExpression . Field Expression < Scope , ĠNumber >( q , Ġ" bar ") ĊĠĠĠĠĠĠĠ Ġval Ġbaz Ġ= Ġcurrent Scope . get ( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" baz " ĊĠĠĠĠĠĠĠ Ġ) Ġas ĠExpression . Field Expression < Current Scope < Any >, ĠScope > ĊĠĠĠĠĠĠĠ Ġval Ġx : ĠExpression < Number > Ġ= Ġbaz [" x "] ĊĠĠĠĠĠĠĠ Ġval Ġexpr Ġ= Ġ( x Ġ+ Ġ 2 . 0 . as Expr () Ġ+ Ġ( 3 f . as Expr () Ġ* Ġ 4 L . as Expr ()) Ġ+ Ġfield Ġ- Ġ 1 . to Byte (). as Expr ()) Ġ/ ĊĠĠĠĠĠĠĠĠĠĠĠĠ 2 . to BigInteger (). as Expr () ĊĠĠĠĠĠĠĠ Ġval Ġjson Ġ= Ġexpr . serialize () ĊĠĠĠĠĠĠĠ Ġval Ġparsed Ġ= Ġjson . deserialize Expression () Ġas ĠExpression < Number > ĊĠĠĠĠĠĠĠ ĠassertThat ( eval Expression < Number >( ĊĠĠĠĠĠĠĠĠĠĠĠ Ġparsed , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Scope , ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ" arg " Ġto Ġmap Of (" bar " Ġto Ġ 5 ). as Scope () ĊĠĠĠĠĠĠĠ Ġ )). isEqualTo ( 2 1 . 0 ) ĊĠĠĠ Ġ} Ċ } Ċ