+1

On Nov 9, 2008, at 3:47 AM, Brice Figureau wrote:

>
> Signed-off-by: Brice Figureau <[EMAIL PROTECTED]>
> ---
> spec/unit/parser/ast.rb    |   37 ++++++++++++++++++++++++++++
> spec/unit/parser/lexer.rb  |   58 +++++++++++++++++++++++++++++++++++ 
> ++++++++-
> spec/unit/parser/parser.rb |   31 ++++++++++++++++++++---
> 3 files changed, 121 insertions(+), 5 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..5139437
> --- /dev/null
> +++ b/spec/unit/parser/ast.rb
> @@ -0,0 +1,37 @@
> +#!/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 respond_to(:doc)
> +    end
> +
> +    it "should have a use_docs accessor to indicate it wants  
> documentation" do
> +        ast = Puppet::Parser::AST.new({})
> +        ast.should respond_to(:use_docs)
> +    end
> +
> +    [ Puppet::Parser::AST::Collection,  
> Puppet::Parser::AST::Definition, Puppet::Parser::AST::Else,
> +      Puppet::Parser::AST::Function,  
> Puppet::Parser::AST::HostClass, Puppet::Parser::AST::IfStatement,
> +      Puppet::Parser::AST::Node, Puppet::Parser::AST::Resource,  
> Puppet::Parser::AST::ResourceDefaults,
> +      Puppet::Parser::AST::ResourceOverride,  
> Puppet::Parser::AST::VarDef
> +    ].each do |k|
> +        it "#{k}.use_docs should return true" do
> +            ast = k.new({})
> +            ast.use_docs.should be_true
> +        end
> +    end
> +
> +    describe "when initializing" do
> +        it "should store the doc argument if passed" 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 d62d992..389f1fe 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[:MLCOMMENT] do
> @@ -313,6 +321,16 @@ describe  
> Puppet::Parser::Lexer::TOKENS[:MLCOMMENT] do
>         match[1].should == " first "
>     end
>
> +    it "should be marked to accumulate" do
> +        @token.accumulate?.should be_true
> +    end
> +
> +    it "'s block should return the comment without the comment  
> marks" do
> +        @lexer.stubs(:line=).with(0)
> +
> +        @token.convert(@lexer,"/* this is a comment */")[1].should  
> == "this is a comment"
> +    end
> +
> end
>
> describe Puppet::Parser::Lexer::TOKENS[:RETURN] do
> @@ -383,6 +401,43 @@ describe  
> Puppet::Parser::Lexer::TOKENS[:VARIABLE] do
>     end
> end
>
> +describe Puppet::Parser::Lexer, "when lexing comments" do
> +    before { @lexer = Puppet::Parser::Lexer.new }
> +
> +    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 return the current comments on getcomment" do
> +        @lexer.string = "# comment"
> +        @lexer.fullscan
> +
> +        @lexer.getcomment.should == "comment\n"
> +    end
> +
> +    it "should discard the previous comments on blank line" do
> +        @lexer.string = "# 1\n\n# 2"
> +        @lexer.fullscan
> +
> +        @lexer.getcomment.should == "2\n"
> +    end
> +
> +end
> +
> # FIXME: We need to rewrite all of these tests, but I just don't  
> want to take the time right now.
> describe "Puppet::Parser::Lexer in the old tests" do
>     before { @lexer = Puppet::Parser::Lexer.new }
> @@ -538,6 +593,7 @@ describe "Puppet::Parser::Lexer in the old  
> tests" do
>             @lexer.fullscan[0].should == [:CLASSREF, foo]
>         end
>     end
> +
> end
>
> require 'puppettest/support/utils'
> diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
> index 077f93d..2a086ad 100755
> --- a/spec/unit/parser/parser.rb
> +++ b/spec/unit/parser/parser.rb
> @@ -37,7 +37,6 @@ describe Puppet::Parser do
>         it "not, it should create the correct ast objects" do
>             AST::Not.expects(:new).with { |h| h[:value].is_a? 
> (AST::Boolean) }
>             @parser.parse("if ! true { $var = 1 }")
> -
>         end
>
>         it "boolean operation, it should create the correct ast  
> objects" do
> @@ -60,14 +59,15 @@ describe Puppet::Parser do
>
>     describe Puppet::Parser, "when parsing if complex expressions" do
>          it "should create a correct ast tree" do
> +             ast = stub_everything 'ast'
>              AST::ComparisonOperator.expects(:new).with {
>                  |h| h[:rval].is_a?(AST::Name) and h[:lval].is_a? 
> (AST::Name) and h[:operator]==">"
> -             }.returns("whatever")
> +             }.returns(ast)
>              AST::ComparisonOperator.expects(:new).with {
>                  |h| h[:rval].is_a?(AST::Name) and h[:lval].is_a? 
> (AST::Name) and h[:operator]=="=="
> -             }.returns("whatever")
> +             }.returns(ast)
>              AST::BooleanOperator.expects(:new).with {
> -                 |h| h[:rval]=="whatever" and h[:lval]=="whatever"  
> and h[:operator]=="and"
> +                 |h| h[:rval]==ast and h[:lval]==ast and  
> h[:operator]=="and"
>              }
>              @parser.parse("if (1 > 2) and (1 == 2) { $var = 1 }")
>          end
> @@ -199,7 +199,30 @@ describe Puppet::Parser do
>
>             klass1.code.children.should == [EMAIL PROTECTED],@two]
>         end
> +    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
>
> +    describe Puppet::Parser, "when building ast nodes" do
> +        it "should get lexer comments if ast node declares  
> use_docs" do
> +            lexer = stub 'lexer'
> +            ast = mock 'ast', :nil? => false, :use_docs =>  
> true, :doc => ""
> +            @parser.stubs(:lexer).returns(lexer)
> +
> +             
> Puppet::Parser::AST::Definition.expects(:new).returns(ast)
> +            lexer.expects(:getcomment).returns("comment")
> +            ast.expects(:doc=).with("comment")
> +
> +            @parser.ast(Puppet::Parser::AST::Definition)
> +        end
> +    end
>  end
> -- 
> 1.6.0.2
>
>
> >


-- 
Ours is the age that is proud of machines that think and suspicious of
men who try to. -- H. Mumford Jones
---------------------------------------------------------------------
Luke Kanies | http://reductivelabs.com | http://madstop.com


--~--~---------~--~----~------------~-------~--~----~
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