summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-11-25 22:20:39 -0600
committerJames Turnbull <james@lovedthanlost.net>2008-11-26 16:09:47 +1100
commit3421954444f4c06d6e7b80430f89fccf56343fe2 (patch)
treeed5d90a44a78ba25c242d5217bd795653fbec04c /spec/unit/parser
parenta1ac9a5c14d4589f5ee7fdaab3b2c47180c66a2e (diff)
Fixing #1755 - handling fully qualified classes correctly.
This involves lexing '::class' tokens along with correctly looking them up from the Resource::Reference class. Signed-off-by: Luke Kanies <luke@madstop.com>
Diffstat (limited to 'spec/unit/parser')
-rwxr-xr-xspec/unit/parser/lexer.rb36
-rwxr-xr-xspec/unit/parser/resource/reference.rb20
2 files changed, 56 insertions, 0 deletions
diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb
index 389f1fe1f..24c34632f 100755
--- a/spec/unit/parser/lexer.rb
+++ b/spec/unit/parser/lexer.rb
@@ -208,6 +208,42 @@ 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] }
+
+ it "should match against single upper-case alpha-numeric terms" do
+ @token.regex.should =~ "One"
+ end
+
+ it "should match against upper-case alpha-numeric terms separated by double colons" do
+ @token.regex.should =~ "One::Two"
+ end
+
+ it "should match against many upper-case alpha-numeric terms separated by double colons" do
+ @token.regex.should =~ "One::Two::Three::Four::Five"
+ end
+
+ it "should match against upper-case alpha-numeric terms prefixed by double colons" do
+ @token.regex.should =~ "::One"
+ end
+end
+
describe Puppet::Parser::Lexer::TOKENS[:NAME] do
before { @token = Puppet::Parser::Lexer::TOKENS[:NAME] }
diff --git a/spec/unit/parser/resource/reference.rb b/spec/unit/parser/resource/reference.rb
index 147f772d1..bb1452692 100755
--- a/spec/unit/parser/resource/reference.rb
+++ b/spec/unit/parser/resource/reference.rb
@@ -72,4 +72,24 @@ describe Puppet::Parser::Resource::Reference, " when modeling defined types" do
ref.builtin?.should be_false
ref.definedtype.object_id.should == @nodedef.object_id
end
+
+ it "should only look for fully qualified classes" do
+ top = @parser.newclass "top"
+ sub = @parser.newclass "other::top"
+
+ scope = @compiler.topscope.class.new(:parent => @compiler.topscope, :namespace => "other", :parser => @parser)
+
+ ref = @type.new(:type => "class", :title => "top", :scope => scope)
+ ref.definedtype.classname.should equal(top.classname)
+ end
+
+ it "should only look for fully qualified definitions" do
+ top = @parser.newdefine "top"
+ sub = @parser.newdefine "other::top"
+
+ scope = @compiler.topscope.class.new(:parent => @compiler.topscope, :namespace => "other", :parser => @parser)
+
+ ref = @type.new(:type => "top", :title => "foo", :scope => scope)
+ ref.definedtype.classname.should equal(top.classname)
+ end
end