diff options
| author | Nick Lewis <nick@puppetlabs.com> | 2011-05-12 15:40:08 -0700 |
|---|---|---|
| committer | Nick Lewis <nick@puppetlabs.com> | 2011-05-17 14:54:43 -0700 |
| commit | 3ac7aede7233e0554077f7abbf6e561960a05e4d (patch) | |
| tree | 6d60a694bfe85a01a53b1314d4f6c6d9363f99e8 /spec/unit/parser | |
| parent | 99d437d2bbc2339f092304715ec562fbbcb0a50c (diff) | |
| download | puppet-3ac7aede7233e0554077f7abbf6e561960a05e4d.tar.gz puppet-3ac7aede7233e0554077f7abbf6e561960a05e4d.tar.xz puppet-3ac7aede7233e0554077f7abbf6e561960a05e4d.zip | |
(#7523) Refactor the grammar to reduce duplication
This commit unifies some paths in the grammar, which had previously been
duplicated to avoid shift/reduce conflicts. Merging these paths together and
separating only the conflicting structures leads to a cleaner grammar, with
fewer holes.
Several bugs are fixed as a result:
(#3129) Nested class names beginning with numbers work correctly
(#5268) Hyphens in class names work correctly
(#5817) Hashes and arrays can now be passed to functions (hashes require parentheses)
Additionally, expressions are now legal in most places where they would make
sense, when previously only bare rvalues were allowed.
Paired-With: Markus Roberts
Reviewed-By: Matt Robinson
Diffstat (limited to 'spec/unit/parser')
| -rwxr-xr-x | spec/unit/parser/lexer_spec.rb | 44 |
1 files changed, 27 insertions, 17 deletions
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 |
