spec/expressive_spec.rb in expressive-0.0.28 vs spec/expressive_spec.rb in expressive-0.0.29

- old
+ new

@@ -64,10 +64,12 @@ it { Expressive.run("(sum 1 2 3)").should eql 6.0 } it { Expressive.run("($sub 1 2 3)").should eql -4.0 } it { Expressive.run("(sum )").should eql 0 } it { Expressive.run("(- (sum 1 5 7) 3)").should eql 10.0} it { Expressive.run("(round 0.12345 2)").should eql 0.12} + it { Expressive.run("(round 0.45 0)").should eql 0} + it { Expressive.run("(round 0.55 0)").should eql 1} end describe "understands comparisson" do it { Expressive.run("(= 4 2)").should eql false } it { Expressive.run("(= 4 4)").should eql true } @@ -91,10 +93,15 @@ it { Expressive.run("(if (and (< 10 9) (> 2 1)), true, false)").should eql false } end describe "understands conditional statements" do it { Expressive.run('(if (> 5 4) "greater" "not so greater")').should eql "greater" } + it { Expressive.run('(if (= 5.2473 5.3473) true false)').should eql false } + it { Expressive.run('(if (= 5.3473 5.3473) true false)').should eql true } + it { Expressive.run('(if (= ($round 5.2473 2) ($round 5.3473 2)) true false)').should eql false } + it { Expressive.run('(if (= ($round 5.2473 1) ($round 5.3473 1)) true false)').should eql false } + it { Expressive.run('(if (= ($round 5.3473 1) ($round 5.3473 1)) true false)').should eql true } context "it understands the need for commas (if you like that kind of thing" do it { Expressive.run('(if (< 5 4), "greater", "not so greater")').should eql "not so greater" } end @@ -251,9 +258,32 @@ it { Expressive.run('(or nil_value false)', @scope).should eql false } end end describe "understands the modification of scope" do + + it "works" do + @scope['total_payment_amount'] = 2.32 + @scope['refund_amount'] = 2.32 + @scope['payment_reconciled'] = "asdf" + Expressive.run('(if (= ($round total_payment_amount 2) ($round refund_amount 2)) true false)', @scope).should eql true + Expressive.run('(if (= ($round total_payment_amount 2) ($round refund_amount 2)) true, false)', @scope).should eql true + Expressive.run('(= (- ($round total_payment_amount 2) ($round refund_amount 2)) 0)', @scope).should eql true + Expressive.run('(set payment_reconciled (if (= ($round total_payment_amount 2) ($round refund_amount 2)) true false))', @scope) + @scope['payment_reconciled'].should eql true + + @scope['total_payment_amount'] = 3 + @scope['refund_amount'] = 2.32 + @scope['payment_reconciled'] = "asdf" + Expressive.run('(if (= ($round total_payment_amount 2) ($round refund_amount 2)) true false)', @scope).should eql false + Expressive.run('(if (= ($round total_payment_amount 2) ($round refund_amount 2)) true, false)', @scope).should eql false + Expressive.run('(= (- ($round total_payment_amount 2) ($round refund_amount 2)) 0)', @scope).should eql false + Expressive.run('(set payment_reconciled (if (= ($round total_payment_amount 2) ($round refund_amount 2)) true false))', @scope) + puts @scope['payment_reconciled'] + @scope['payment_reconciled'].should eql false + + end + it "using single set commands" do @scope['vsi'] = 'oldvalue' Expressive.run('(set vsi "vsi1234")', @scope).should eql "vsi1234" @scope['vsi'].should eql 'vsi1234' end