Signed-off-by: Brice Figureau <[EMAIL PROTECTED]>
---
 spec/unit/parser/ast.rb    |   21 +++++++++++++++++++++
 spec/unit/parser/lexer.rb  |   37 ++++++++++++++++++++++++++++++++++++-
 spec/unit/parser/parser.rb |   12 ++++++++++++
 3 files changed, 69 insertions(+), 1 deletions(-)
 create mode 100644 spec/unit/parser/ast.rb

diff --git a/spec/unit/parser/ast.rb b/spec/unit/parser/ast.rb
new file mode 100644
index 0000000..85be803
--- /dev/null
+++ b/spec/unit/parser/ast.rb
@@ -0,0 +1,21 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../spec_helper'
+
+require 'puppet/parser/ast'
+
+describe Puppet::Parser::AST do
+
+    it "should have a doc accessor" do
+        ast = Puppet::Parser::AST.new({})
+        ast.should be_respond_to(:doc)
+    end
+
+    describe "when initializing" do
+        it "should store the doc argument" do
+            ast = Puppet::Parser::AST.new({ :doc => "documentation" })
+            ast.doc.should == "documentation"
+        end
+    end
+
+end
\ No newline at end of file
diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb
index 3b0df96..f67959f 100755
--- a/spec/unit/parser/lexer.rb
+++ b/spec/unit/parser/lexer.rb
@@ -30,7 +30,7 @@ describe Puppet::Parser::Lexer::Token do
         @token = Puppet::Parser::Lexer::Token.new(%r{something}, :NAME)
     end
 
-    [:regex, :name, :string, :skip, :incr_line, :skip_text].each do |param|
+    [:regex, :name, :string, :skip, :incr_line, :skip_text, :accumulate].each 
do |param|
         it "should have a #{param.to_s} reader" do
             @token.should be_respond_to(param)
         end
@@ -285,6 +285,14 @@ describe Puppet::Parser::Lexer::TOKENS[:COMMENT] do
     it "should be marked to get skipped" do
         @token.skip?.should be_true
     end
+
+    it "should be marked to accumulate" do
+        @token.accumulate?.should be_true
+    end
+
+    it "'s block should return the comment without the #" do
+        @token.convert(@lexer,"# this is a comment")[1].should == " this is a 
comment"
+    end
 end
 
 describe Puppet::Parser::Lexer::TOKENS[:RETURN] do
@@ -510,6 +518,33 @@ describe "Puppet::Parser::Lexer in the old tests" do
             @lexer.fullscan[0].should == [:CLASSREF, foo]
         end
     end
+
+    it "should accumulate token in munge_token" do
+        token = stub 'token', :skip => true, :accumulate? => true, :incr_line 
=> nil, :skip_text => false
+
+        token.stubs(:convert).with(@lexer, "# this is a 
comment").returns([token, " this is a comment"])
+        @lexer.munge_token(token, "# this is a comment")
+        @lexer.munge_token(token, "# this is a comment")
+
+        @lexer.getcomment.should == " this is a comment\n this is a comment\n"
+    end
+
+    it "should add a new comment stack level on LBRACE" do
+        @lexer.string = "{"
+
+        @lexer.expects(:commentpush)
+
+        @lexer.fullscan
+    end
+
+    it "should pop the comment stack on RBRACE" do
+        @lexer.string = "}"
+
+        @lexer.expects(:commentpop)
+
+        @lexer.fullscan
+    end
+
 end
 
 require 'puppettest/support/utils'
diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
index 07aad58..0e4b484 100755
--- a/spec/unit/parser/parser.rb
+++ b/spec/unit/parser/parser.rb
@@ -174,4 +174,16 @@ describe Puppet::Parser do
 
     end
 
+    describe Puppet::Parser, "when parsing comments before statement" do
+        it "should associate the documentation to the statement AST node" do
+            ast = @parser.parse("""
+            # comment
+            class test {}
+            """)
+
+            ast[:classes]["test"].doc.should == " comment\n"
+        end
+    end
+
+
  end
-- 
1.6.0.2


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to