spec/expressive_spec.rb in expressive-0.0.23 vs spec/expressive_spec.rb in expressive-0.0.24

- old
+ new

@@ -4,11 +4,11 @@ before(:each) do @scope = Expressive::TopLevel.new end describe "all_symbols" do - it { Expressive.all_symbols.should =~ %w(+ - * / = set sum get put post >= > < <= and or if date lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail) } + it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail) } end describe "understands booleans" do it { Expressive.run("true").should eql true } it { Expressive.run("false").should eql false } @@ -35,10 +35,11 @@ it { Expressive.run("(+ 4 2)").should eql 6.0 } it { Expressive.run("(- 4 2)").should eql 2.0 } it { Expressive.run("(* 4 2)").should eql 8.0 } it { Expressive.run("(/ 4 2)").should eql 2.0 } 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} end @@ -76,9 +77,62 @@ it { Expressive.run('(if (> nil_value 4) "greater" "not so greater")', @scope).should eql "not so greater" } it { Expressive.run('(if (> 4 nil_value) "greater" "not so greater")', @scope).should eql "greater" } it { Expressive.run('(if (> 4 nil_value) "greater" "not so greater")', @scope).should eql "greater" } it { Expressive.run('(if (<= nil_value 4) "greater" "not so greater")', @scope).should eql "greater" } it { Expressive.run('(if (>= 4 nil_value) "greater" "not so greater")', @scope).should eql "greater" } + end + + context "multiple if statements" do + before do + @scope["depth"] = "4mm" + @statement = <<-EOH + (if (= depth "8mm") 1 + (if (= depth "7mm") 0.8 + (if (= depth "6mm") 0.65 + (if (= depth "5mm") 0.5 + (if (= depth "4mm") 0.35 + (if (= depth "3mm") 0.2 + (if (= depth "2mm") 0.05 0) + ) + ) + ) + ) + ) + ) +EOH + end + it do + @scope["depth"] = "8mm" + Expressive.run(@statement, @scope).should eql 1 + end + it do + @scope["depth"] = "7mm" + Expressive.run(@statement, @scope).should eql 0.8 + end + it do + @scope["depth"] = "6mm" + Expressive.run(@statement, @scope).should eql 0.65 + end + it do + @scope["depth"] = "5mm" + Expressive.run(@statement, @scope).should eql 0.5 + end + it do + @scope["depth"] = "4mm" + Expressive.run(@statement, @scope).should eql 0.35 + end + it do + @scope["depth"] = "3mm" + Expressive.run(@statement, @scope).should eql 0.2 + end + it do + @scope["depth"] = "2mm" + Expressive.run(@statement, @scope).should eql 0.05 + end + it do + @scope["depth"] = "1.6mm" + Expressive.run(@statement, @scope).should eql 0 + end end end describe "understands logical statements" do it { Expressive.run('(and true true)').should eql true }