diff options
Diffstat (limited to 'spec')
-rwxr-xr-x | spec/integration/parser/parser_spec.rb | 31 | ||||
-rwxr-xr-x | spec/unit/parser/lexer_spec.rb | 44 |
2 files changed, 58 insertions, 17 deletions
diff --git a/spec/integration/parser/parser_spec.rb b/spec/integration/parser/parser_spec.rb index 65c9ee302..b55aa04ce 100755 --- a/spec/integration/parser/parser_spec.rb +++ b/spec/integration/parser/parser_spec.rb @@ -117,5 +117,36 @@ describe Puppet::Parser::Parser do $out = $hash['a']['b']['c'] }.should parse_with { |v| v.value.is_a?(Puppet::Parser::AST::ASTHash) } end + + it "should fail if asked to parse '$foo::::bar'" do + expect { @parser.parse("$foo::::bar") }.should raise_error(Puppet::ParseError, /Syntax error at ':'/) + end + + describe "function calls" do + it "should be able to pass an array to a function" do + "my_function([1,2,3])".should parse_with { |fun| + fun.is_a?(Puppet::Parser::AST::Function) && + fun.arguments.first.evaluate(stub 'scope') == ['1','2','3'] + } + end + + it "should be able to pass a hash to a function" do + "my_function({foo => bar})".should parse_with { |fun| + fun.is_a?(Puppet::Parser::AST::Function) && + fun.arguments.first.evaluate(stub 'scope') == {'foo' => 'bar'} + } + end + end + + describe "collections" do + it "should find resources according to an expression" do + %q{ + File <| mode == 0700 + 0050 + 0050 |> + }.should parse_with { |coll| + coll.is_a?(Puppet::Parser::AST::Collection) && + coll.query.evaluate(stub 'scope').first == "param_values.value = '528' and param_names.name = 'mode'" + } + end + end end end diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb index 6cdb0553a..48f7304b4 100755 --- a/spec/unit/parser/lexer_spec.rb +++ b/spec/unit/parser/lexer_spec.rb @@ -230,22 +230,6 @@ describe Puppet::Parser::Lexer::TOKENS do end end -describe Puppet::Parser::Lexer::TOKENS[:CLASSNAME] do - before { @token = Puppet::Parser::Lexer::TOKENS[:CLASSNAME] } - - it "should match against lower-case alpha-numeric terms separated by double colons" do - @token.regex.should =~ "one::two" - end - - it "should match against many lower-case alpha-numeric terms separated by double colons" do - @token.regex.should =~ "one::two::three::four::five" - end - - it "should match against lower-case alpha-numeric terms prefixed by double colons" do - @token.regex.should =~ "::one" - end -end - describe Puppet::Parser::Lexer::TOKENS[:CLASSREF] do before { @token = Puppet::Parser::Lexer::TOKENS[:CLASSREF] } @@ -295,6 +279,22 @@ describe Puppet::Parser::Lexer::TOKENS[:NAME] do Puppet::Parser::Lexer::KEYWORDS.expects(:lookup).returns(keyword) @token.convert(stub('lexer'), "false").should == [Puppet::Parser::Lexer::TOKENS[:BOOLEAN], false] end + + it "should match against lower-case alpha-numeric terms separated by double colons" do + @token.regex.should =~ "one::two" + end + + it "should match against many lower-case alpha-numeric terms separated by double colons" do + @token.regex.should =~ "one::two::three::four::five" + end + + it "should match against lower-case alpha-numeric terms prefixed by double colons" do + @token.regex.should =~ "::one" + end + + it "should match against nested terms starting with numbers" do + @token.regex.should =~ "::1one::2two::3three" + end end describe Puppet::Parser::Lexer::TOKENS[:NUMBER] do @@ -445,6 +445,9 @@ describe Puppet::Parser::Lexer,"when lexing strings" do %q["foo$bar$"] => [[:DQPRE,"foo"],[:VARIABLE,"bar"],[:DQPOST,"$"]], %q["foo$$bar"] => [[:DQPRE,"foo$"],[:VARIABLE,"bar"],[:DQPOST,""]], %q[""] => [[:STRING,""]], + %q["123 456 789 0"] => [[:STRING,"123 456 789 0"]], + %q["${123} 456 $0"] => [[:DQPRE,""],[:VARIABLE,"123"],[:DQMID," 456 "],[:VARIABLE,"0"],[:DQPOST,""]], + %q["$foo::::bar"] => [[:DQPRE,""],[:VARIABLE,"foo"],[:DQPOST,"::::bar"]] }.each { |src,expected_result| it "should handle #{src} correctly" do tokens_scanned_from(src).should be_like(*expected_result) @@ -660,10 +663,17 @@ describe "Puppet::Parser::Lexer in the old tests" do end it "should correctly lex variables" do - ["$variable", "$::variable", "$qualified::variable", "$further::qualified::variable"].each do |string| + ["$variable", "$::variable", "$qualified::variable", "$further::qualified::variable", "$hyphenated-variable", "$-variable-with-leading-dash"].each do |string| tokens_scanned_from(string).should be_like([:VARIABLE,string.sub(/^\$/,'')]) end end + + it "should not include whitespace in a variable" do + tokens_scanned_from("$foo bar").should_not be_like([:VARIABLE, "foo bar"]) + end + it "should not include excess colons in a variable" do + tokens_scanned_from("$foo::::bar").should_not be_like([:VARIABLE, "foo::::bar"]) + end end describe "Puppet::Parser::Lexer in the old tests when lexing example files" do |