summaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorBrice Figureau <brice-puppet@daysofwonder.com>2009-07-18 13:08:57 +0200
committerJames Turnbull <james@lovedthanlost.net>2009-07-25 20:13:58 +1000
commite3ee594fdfa0e7a6d9de26c4307e217de866f462 (patch)
tree315177df89205b1747fb506edc543175ebf032f0 /spec
parentb3b76dffdd9cd8ed5c3d0230624bf05015bec5b8 (diff)
downloadpuppet-e3ee594fdfa0e7a6d9de26c4307e217de866f462.tar.gz
puppet-e3ee594fdfa0e7a6d9de26c4307e217de866f462.tar.xz
puppet-e3ee594fdfa0e7a6d9de26c4307e217de866f462.zip
Fix #2422 & #2433 - make sure puppetdoc transform AST::Leaf boolean correctly
AST nodes don't have a valid to_s that is producing a correct representation of said node. This patch adds some of the AST node to_s to produce correct values that can be used verbatim by puppetdoc to render the documentation. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'spec')
-rwxr-xr-xspec/unit/parser/ast/astarray.rb6
-rw-r--r--spec/unit/parser/ast/function.rb6
-rwxr-xr-xspec/unit/parser/ast/leaf.rb31
-rwxr-xr-xspec/unit/parser/ast/resource_reference.rb6
4 files changed, 49 insertions, 0 deletions
diff --git a/spec/unit/parser/ast/astarray.rb b/spec/unit/parser/ast/astarray.rb
index 212c3fd14..1791c711c 100755
--- a/spec/unit/parser/ast/astarray.rb
+++ b/spec/unit/parser/ast/astarray.rb
@@ -62,5 +62,11 @@ describe Puppet::Parser::AST::ASTArray do
operator.evaluate(@scope).should == [[123]]
end
+ it "should return a valid string with to_s" do
+ a = stub 'a', :is_a? => true, :to_s => "a"
+ b = stub 'b', :is_a? => true, :to_s => "b"
+ array = Puppet::Parser::AST::ASTArray.new :children => [a,b]
+ array.to_s.should == "[a, b]"
+ end
end
diff --git a/spec/unit/parser/ast/function.rb b/spec/unit/parser/ast/function.rb
index 15420132f..bb687eac0 100644
--- a/spec/unit/parser/ast/function.rb
+++ b/spec/unit/parser/ast/function.rb
@@ -16,6 +16,12 @@ describe Puppet::Parser::AST::Function do
end
end
+ it "should return its representation with to_s" do
+ args = stub 'args', :is_a? => true, :to_s => "[a, b]"
+
+ Puppet::Parser::AST::Function.new(:name => "func", :arguments => args).to_s.should == "func(a, b)"
+ end
+
describe "when evaluating" do
it "should fail if the function doesn't exist" do
diff --git a/spec/unit/parser/ast/leaf.rb b/spec/unit/parser/ast/leaf.rb
new file mode 100755
index 000000000..5ca7bc675
--- /dev/null
+++ b/spec/unit/parser/ast/leaf.rb
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::Leaf do
+ describe "when converting to string" do
+ it "should transform its value to string" do
+ value = stub 'value', :is_a? => true
+ value.expects(:to_s)
+ Puppet::Parser::AST::Leaf.new( :value => value ).to_s
+ end
+ end
+end
+
+describe Puppet::Parser::AST::FlatString do
+ describe "when converting to string" do
+ it "should transform its value to a quoted string" do
+ value = stub 'value', :is_a? => true, :to_s => "ab"
+ Puppet::Parser::AST::FlatString.new( :value => value ).to_s.should == "\"ab\""
+ end
+ end
+end
+
+describe Puppet::Parser::AST::FlatString do
+ describe "when converting to string" do
+ it "should transform its value to a quoted string" do
+ value = stub 'value', :is_a? => true, :to_s => "ab"
+ Puppet::Parser::AST::String.new( :value => value ).to_s.should == "\"ab\""
+ end
+ end
+end
diff --git a/spec/unit/parser/ast/resource_reference.rb b/spec/unit/parser/ast/resource_reference.rb
index 3a759c550..24865e846 100755
--- a/spec/unit/parser/ast/resource_reference.rb
+++ b/spec/unit/parser/ast/resource_reference.rb
@@ -60,4 +60,10 @@ describe Puppet::Parser::AST::ResourceReference do
ref.evaluate(@scope)
end
+ it "should return a correct representation when converting to string" do
+ type = stub 'type', :is_a? => true, :to_s => "file"
+ title = stub 'title', :is_a? => true, :to_s => "[/tmp/a, /tmp/b]"
+
+ ast::ResourceReference.new( :type => type, :title => title ).to_s.should == "File[/tmp/a, /tmp/b]"
+ end
end