spec/expressive_spec.rb in expressive-0.0.35 vs spec/expressive_spec.rb in expressive-0.0.36
- 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 $sub get put post >= > < <= and or if date datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash $concat $split $sms $hval $index $random $join $not $include) }
+ it { Expressive.all_symbols.should =~ %w(+ - * / = set sum $sub get put post >= > < <= and or if date datetime lookup round $round $days_ago $hours_ago $minutes_ago $append $id $head $lookup $reverse $tail $hash $concat $split $sms $hval $index $random $join $not $include $string $float $integer) }
end
describe "understands booleans" do
it { Expressive.run("true").should eql true }
it { Expressive.run("false").should eql false }
@@ -31,12 +31,25 @@
it {
@scope["scope_value"] = "world"
Expressive.run('($concat "hello " scope_value)', @scope).should eql "hello world"
}
it {Expressive.run('($split "a,b,c,d,e" ",")').should eql ['a', 'b', 'c', 'd', 'e'] }
+ it {
+ @scope["scope_value"] = "a,b,c,d,e"
+ Expressive.run('($split scope_value ",")', @scope).should eql ['a', 'b', 'c', 'd', 'e']
+ }
+
end
+ end
+ describe "understands literals" do
+ it {
+ @scope["test_value"] = 1
+ @scope["test_1_value"] = 3
+ Expressive.run('test_value', @scope).should eql 1
+ Expressive.run('test_1_value', @scope).should eql 3
+ }
end
describe "hash manipulation" do
context "hash definition" do
it { Expressive.run('($hash (test "value"))').should eql ({"test" => "value"})}
@@ -261,11 +274,11 @@
it { Expressive.run('(or false (or true false))').should eql true }
it { Expressive.run('(or true (or false false))').should eql true }
it "handles compound ors" do
expressive = "(if (or (= answer_2 \"Unemployed\") (or (= answer_2 \"Self-employed\") (or (= answer_2 \"Retired\") (= answer_2 \"Student\")))) 2 \"\")"
-
+
@scope["answer_2"] = "asdf"
result = Expressive.run(expressive, @scope)
result.should == ""
@scope["answer_2"] = "Unemployed"
@@ -537,10 +550,20 @@
it { Expressive.run("($days_ago 28)").should eql (@now - 28 * 86400) }
it { Expressive.run("($hours_ago 7)").should eql (@now - 7 * 3600) }
it { Expressive.run("($minutes_ago 12)").should eql (@now - 12 * 60) }
end
+ describe "string" do
+ it {Expressive.run("($string 7)").should eql "7" }
+ end
+ describe "integer" do
+ it {Expressive.run("($integer 7)").should eql 7 }
+ end
+ describe "float" do
+ it {Expressive.run("($float 7)").should eql 7.0 }
+ end
+
describe "concat" do
it "string and number values" do
Expressive.run('($concat "ref-" 3)').should eql "ref-3"
end
@@ -750,10 +773,10 @@
assert_requested(request)
@scope['goodbye'].should eql 'srsly'
end
end
end
-
+
describe "parse error handling" do
it "should raise parse exceptions" do
expect{ Expressive.run(nil) }.to raise_error Expressive::ParseError, "Error parsing nil expression: undefined method `length' for nil:NilClass"
end
it "should raise runtime exceptions" do