9 Config.instance.stubs(:color).returns(false)
13 it "should parse statements seperated by '='" do
14 parser = Parser.new("foo=bar")
15 parser.execution_stack.should == [{"statement" => "foo=bar"}]
18 it "should parse statements seperated by '<'" do
19 parser = Parser.new("foo<bar")
20 parser.execution_stack.should == [{"statement" => "foo<bar"}]
23 it "should parse statements seperated by '>'" do
24 parser = Parser.new("foo>bar")
25 parser.execution_stack.should == [{"statement" => "foo>bar"}]
28 it "should parse statements seperated by '<='" do
29 parser = Parser.new("foo<=bar")
30 parser.execution_stack.should == [{"statement" => "foo<=bar"}]
33 it "should parse statements seperated by '>='" do
34 parser = Parser.new("foo>=bar")
35 parser.execution_stack.should == [{"statement" => "foo>=bar"}]
38 it "should parse class regex statements" do
39 parser = Parser.new("/foo/")
40 parser.execution_stack.should == [{"statement" => "/foo/"}]
43 it "should parse fact regex statements" do
44 parser = Parser.new("foo=/bar/")
45 parser.execution_stack.should == [{"statement" => "foo=/bar/"}]
48 it "should parse a correct 'and' token" do
49 parser = Parser.new("foo=bar and bar=foo")
50 parser.execution_stack.should == [{"statement" => "foo=bar"}, {"and" => "and"}, {"statement" => "bar=foo"}]
53 it "should not parse an incorrect and token" do
55 parser = Parser.new("and foo=bar")
56 }.to raise_error(RuntimeError, "Parse errors found while parsing -S input and foo=bar")
59 it "should parse a correct 'or' token" do
60 parser = Parser.new("foo=bar or bar=foo")
61 parser.execution_stack.should == [{"statement" => "foo=bar"}, {"or" => "or"}, {"statement" => "bar=foo"}]
64 it "should not parse an incorrect or token" do
66 parser = Parser.new("or foo=bar")
67 }.to raise_error(RuntimeError, "Parse errors found while parsing -S input or foo=bar")
70 it "should parse a correct 'not' token" do
71 parser = Parser.new("! bar=foo")
72 parser.execution_stack.should == [{"not" => "not"}, {"statement" => "bar=foo"}]
73 parser = Parser.new("not bar=foo")
74 parser.execution_stack.should == [{"not" => "not"}, {"statement" => "bar=foo"}]
77 it "should not parse an incorrect 'not' token" do
79 parser = Parser.new("foo=bar !")
80 }.to raise_error(RuntimeError, "Parse errors found while parsing -S input foo=bar !")
83 it "should parse correct parentheses" do
84 parser = Parser.new("(foo=bar)")
85 parser.execution_stack.should == [{"(" => "("}, {"statement" => "foo=bar"}, {")" => ")"}]
88 it "should fail on incorrect parentheses" do
90 parser = Parser.new(")foo=bar(")
91 }.to raise_error(RuntimeError, "Malformed token(s) found while parsing -S input )foo=bar(")
94 it "should fail on missing parentheses" do
96 parser = Parser.new("(foo=bar")
97 }.to raise_error(RuntimeError, "Missing parenthesis found while parsing -S input (foo=bar")
100 it "should parse correctly formatted compound statements" do
101 parser = Parser.new("(foo=bar or foo=rab) and (bar=foo)")
102 parser.execution_stack.should == [{"(" => "("}, {"statement"=>"foo=bar"}, {"or"=>"or"}, {"statement"=>"foo=rab"},
103 {")"=>")"}, {"and"=>"and"}, {"("=>"("}, {"statement"=>"bar=foo"},
107 it "should parse complex fstatements and statements with operators seperated by whitespaces" do
108 parser = Parser.new("foo('bar').value = 1 and foo=bar or foo = bar")
109 parser.execution_stack.should == [{"fstatement"=>"foo('bar').value=1"}, {"and"=>"and"}, {"statement"=>"foo=bar"}, {"or"=>"or"}, {"statement"=>"foo=bar"}]
112 it "should parse statements where classes are mixed with fact comparisons and fstatements" do
113 parser = Parser.new("klass and function('param').value = 1 and fact=value")
114 parser.execution_stack.should == [{"statement" => "klass"},
116 {"fstatement" => "function('param').value=1"},
118 {"statement" => "fact=value"}]