From b4a171e78c501208798220910352943331ceb9e0 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Fri, 11 Feb 2011 22:46:15 +0100 Subject: Fix #5720 - puppetdoc misses some class comments It appears that the fix for #5252 wasn't complete, and class, nodes and definition were still using the current lexer line number instead of the line number of the class/define/node token. This combined with some missing comments stack pushing/pop on parenthesis prevented puppetdoc to correctly get the documentation of some class (including parametrized ones). Signed-off-by: Brice Figureau --- spec/unit/parser/lexer_spec.rb | 16 ++++++++++++++++ spec/unit/parser/parser_spec.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'spec/unit/parser') diff --git a/spec/unit/parser/lexer_spec.rb b/spec/unit/parser/lexer_spec.rb index 860326973..4ef242cf5 100755 --- a/spec/unit/parser/lexer_spec.rb +++ b/spec/unit/parser/lexer_spec.rb @@ -529,6 +529,22 @@ describe Puppet::Parser::Lexer, "when lexing comments" do @lexer.fullscan end + it "should add a new comment stack level on LPAREN" do + @lexer.string = "(" + + @lexer.expects(:commentpush) + + @lexer.fullscan + end + + it "should pop the current comment on RPAREN" do + @lexer.string = ")" + + @lexer.expects(:commentpop) + + @lexer.fullscan + end + it "should return the current comments on getcomment" do @lexer.string = "# comment" @lexer.fullscan diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb index 07e2d220b..9aab6a716 100755 --- a/spec/unit/parser/parser_spec.rb +++ b/spec/unit/parser/parser_spec.rb @@ -304,6 +304,33 @@ describe Puppet::Parser do it "should return an array of nodes" do @parser.newnode(@nodename).should be_instance_of(Array) end + + it "should initialize the ast context with the correct line number" do + @parser.expects(:ast_context).with { |a,b| b == 123 }.returns({}) + @parser.newnode(@nodename, { :line => 123 }) + end + end + + %w{class define}.each do |entity| + describe "when creating a #{entity}" do + before :each do + @parser.stubs(:ast_context).returns({}) + + @name = stub "#{entity}name", :is_a? => false, :value => "foo" + end + + it "should create and add the correct resource type" do + instance = stub 'instance' + Puppet::Resource::Type.expects(:new).returns(instance) + @parser.known_resource_types.expects(:add).with(instance) + @parser.send("new#{entity}", @name) + end + + it "should initialize the ast context with the correct line number" do + @parser.expects(:ast_context).with { |a,b| b == 123 }.returns({}) + @parser.send("new#{entity}", @name, { :line => 123 }) + end + end end describe "when retrieving a specific node" do -- cgit From 414e3a5989c4c1010af0c5d3f61af2608d91d9b8 Mon Sep 17 00:00:00 2001 From: Brice Figureau Date: Sat, 12 Feb 2011 17:34:35 +0100 Subject: Fix #5516 - Hashes can't be used in selectors The following manifest was producing a parse error: $int = { 'eth0' => 'bla' } $foo = $int['eth0'] ? { 'bla' => 'foo', default => 'bleh' } because selectors didn't support hash access. Signed-off-by: Brice Figureau --- spec/unit/parser/parser_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'spec/unit/parser') diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb index 07e2d220b..9e4c79588 100755 --- a/spec/unit/parser/parser_spec.rb +++ b/spec/unit/parser/parser_spec.rb @@ -76,6 +76,12 @@ describe Puppet::Parser do end + describe "when parsing selector" do + it "should support hash access on the left hand side" do + lambda { @parser.parse("$h = { 'a' => 'b' } $a = $h['a'] ? { 'b' => 'd', default => undef }") }.should_not raise_error + end + end + describe "when parsing 'if'" do it "not, it should create the correct ast objects" do ast::Not.expects(:new).with { |h| h[:value].is_a?(ast::Boolean) } -- cgit From b5b5923bf41196f5e72a69bfa627120c75732fe5 Mon Sep 17 00:00:00 2001 From: Daniel Pittman Date: Sat, 12 Feb 2011 11:44:19 -0800 Subject: misc: ast_context has two arguments, not one. This updates the spec expectation to reflect that, eliminating a warning during the spec run. --- spec/unit/parser/parser_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'spec/unit/parser') diff --git a/spec/unit/parser/parser_spec.rb b/spec/unit/parser/parser_spec.rb index 9aab6a716..2f5d4b8ea 100755 --- a/spec/unit/parser/parser_spec.rb +++ b/spec/unit/parser/parser_spec.rb @@ -276,7 +276,7 @@ describe Puppet::Parser do it "should include docs when the AST class uses them" do @class.expects(:use_docs).returns true @class.stubs(:new) - @parser.expects(:ast_context).with{ |a| a[0] == true }.returns({}) + @parser.expects(:ast_context).with{ |docs, line| docs == true }.returns({}) @parser.ast(@class, :file => "/bar") end -- cgit