@@ -80,20 +80,62 @@ def parse_with(&block)
8080# @parser = Puppet::Parser::Parser.new "development"
8181 end
8282 shared_examples_for 'a puppet parser' do
83- describe "when parsing comments before statement" do
83+ describe "when parsing comments before a statement" do
8484 it "should associate the documentation to the statement AST node" do
8585 if Puppet [ :parser ] == 'future'
8686 pending "egrammar does not yet process comments"
8787 end
8888 ast = @parser . parse ( "" "
8989 # comment
90- class test {}
90+ class test {
91+ $foo = {bar => 23}
92+ $bar = [23, 42]
93+ $x = 'argument'
94+ # this comment should not be returned
95+ some_function('with', {a => 'hash'},
96+ ['and', 1, 'array', $argument],
97+ ) # not?
98+ }
9199 " "" )
92100
93101 ast . code [ 0 ] . should be_a ( Puppet ::Parser ::AST ::Hostclass )
94102 ast . code [ 0 ] . name . should == 'test'
95103 ast . code [ 0 ] . instantiate ( '' ) [ 0 ] . doc . should == "comment\n "
96104 end
105+
106+ { "an empty hash" => "{}" ,
107+ "a simple hash" => "{ 'key' => 'value' }" ,
108+ "a nested hash" => "{ 'first' => $x, 'second' => { a => 1, b => 2 } }"
109+ } . each_pair do |hash_desc , hash_expr |
110+ context "in the presence of #{ hash_desc } " do
111+ { "a parameter default" => "class test($param = #{ hash_expr } ) { }" ,
112+ "a parameter value" => "foo { 'bar': options => #{ hash_expr } }" ,
113+ "an plusignment rvalue" => "Foo['bar'] { options +> #{ hash_expr } }" ,
114+ "an assignment rvalue" => "$x = #{ hash_expr } " ,
115+ "an inequality rvalue" => "if $x != #{ hash_expr } { }" ,
116+ "an function argument in parenthesis" => "flatten(#{ hash_expr } )" ,
117+ "a second argument" => "merge($x, #{ hash_expr } )" ,
118+ } . each_pair do |dsl_desc , dsl_expr |
119+ context "as #{ dsl_desc } " do
120+ it "should associate the docstring to the container" do
121+ ast = @parser . parse ( "# comment\n class container { #{ dsl_expr } }\n " )
122+ ast . code [ 0 ] . instantiate ( '' ) [ 0 ] . doc . should == "comment\n "
123+ end
124+ end
125+ end
126+ # Pending, these syntaxes are not yet supported in 3.x
127+ #
128+ # @todo Merge these into the test above after the migration to the new
129+ # parser is complete.
130+ { "a selector alternative" => "$opt ? { { 'a' => 1 } => true, default => false }" ,
131+ "an argument without parenthesis" => "flatten { 'a' => 1 }" ,
132+ } . each_pair do |dsl_desc , dsl_expr |
133+ context "as #{ dsl_desc } " do
134+ it "should associate the docstring to the container"
135+ end
136+ end
137+ end
138+ end
97139 end
98140
99141 describe "when parsing" do
0 commit comments