Kick ass -- +1.
On Sep 20, 2008, at 7:28 AM, Brice Figureau wrote:
>
> Signed-off-by: Brice Figureau <[EMAIL PROTECTED]>
> ---
> spec/unit/parser/ast/vardef.rb | 47 +++++++++++++++++++++++++++++++
> +++++++++
> spec/unit/parser/lexer.rb | 3 +-
> spec/unit/parser/parser.rb | 34 ++++++++++++++++++++++++++++
> spec/unit/parser/scope.rb | 37 +++++++++++++++++++++++++++++++
> test/data/snippets/append.pp | 11 +++++++++
> 5 files changed, 131 insertions(+), 1 deletions(-)
> create mode 100755 spec/unit/parser/ast/vardef.rb
> create mode 100755 spec/unit/parser/parser.rb
> create mode 100755 spec/unit/parser/scope.rb
> create mode 100644 test/data/snippets/append.pp
>
> diff --git a/spec/unit/parser/ast/vardef.rb b/spec/unit/parser/ast/
> vardef.rb
> new file mode 100755
> index 0000000..6bd355c
> --- /dev/null
> +++ b/spec/unit/parser/ast/vardef.rb
> @@ -0,0 +1,47 @@
> +#!/usr/bin/env ruby
> +
> +require File.dirname(__FILE__) + '/../../../spec_helper'
> +
> +describe Puppet::Parser::AST::VarDef do
> + before :each do
> + @scope = Puppet::Parser::Scope.new()
> + end
> +
> + describe "when evaluating" do
> +
> + it "should evaluate arguments" do
> + name = mock 'name'
> + value = mock 'value'
> +
> + name.expects(:safeevaluate).with(@scope)
> + value.expects(:safeevaluate).with(@scope)
> +
> + vardef = Puppet::Parser::AST::VarDef.new :name =>
> name, :value => value, :file => nil,
> + :line => nil
> + vardef.evaluate(@scope)
> + end
> +
> + it "should be in append=false mode if called without
> append" do
> + name = stub 'name', :safeevaluate => "var"
> + value = stub 'value', :safeevaluate => "1"
> +
> + @scope.expects(:setvar).with { |
> name,value,file,line,append| append == nil }
> +
> + vardef = Puppet::Parser::AST::VarDef.new :name =>
> name, :value => value, :file => nil,
> + :line => nil
> + vardef.evaluate(@scope)
> + end
> +
> + it "should call scope in append mode if append is true" do
> + name = stub 'name', :safeevaluate => "var"
> + value = stub 'value', :safeevaluate => "1"
> +
> + @scope.expects(:setvar).with { |
> name,value,file,line,append| append == true }
> +
> + vardef = Puppet::Parser::AST::VarDef.new :name =>
> name, :value => value, :file => nil,
> + :line =>
> nil, :append => true
> + vardef.evaluate(@scope)
> + end
> +
> + end
> +end
> diff --git a/spec/unit/parser/lexer.rb b/spec/unit/parser/lexer.rb
> index fb66605..fed1ade 100755
> --- a/spec/unit/parser/lexer.rb
> +++ b/spec/unit/parser/lexer.rb
> @@ -135,7 +135,8 @@ describe Puppet::Parser::Lexer::TOKENS do
> :QMARK => '?',
> :BACKSLASH => '\\',
> :FARROW => '=>',
> - :PARROW => '+>'
> + :PARROW => '+>',
> + :APPENDS => '+='
> }.each do |name, string|
> it "should have a token named #{name.to_s}" do
> Puppet::Parser::Lexer::TOKENS[name].should_not be_nil
> diff --git a/spec/unit/parser/parser.rb b/spec/unit/parser/parser.rb
> new file mode 100755
> index 0000000..94b19be
> --- /dev/null
> +++ b/spec/unit/parser/parser.rb
> @@ -0,0 +1,34 @@
> +#!/usr/bin/env ruby
> +
> +require File.dirname(__FILE__) + '/../../spec_helper'
> +
> +describe Puppet::Parser do
> +
> + AST = Puppet::Parser::AST
> +
> + before :each do
> + @parser = Puppet::Parser::Parser.new :environment =>
> "development"
> + end
> +
> + describe "when parsing append operator" do
> +
> + it "should not raise syntax errors" do
> + lambda { @parser.parse("$var +=
> something") }.should_not raise_error
> + end
> +
> + it "shouldraise syntax error on incomplete syntax " do
> + lambda { @parser.parse("$var += ") }.should raise_error
> + end
> +
> + it "should call AST::VarDef with append=true" do
> + AST::VarDef.expects(:new).with { |h| h[:append] == true }
> + @parser.parse("$var += 2")
> + end
> +
> + it "should work with arrays too" do
> + AST::VarDef.expects(:new).with { |h| h[:append] == true }
> + @parser.parse("$var += ['test']")
> + end
> +
> + end
> +end
> diff --git a/spec/unit/parser/scope.rb b/spec/unit/parser/scope.rb
> new file mode 100755
> index 0000000..ec8ab6d
> --- /dev/null
> +++ b/spec/unit/parser/scope.rb
> @@ -0,0 +1,37 @@
> +#!/usr/bin/env ruby
> +
> +require File.dirname(__FILE__) + '/../../spec_helper'
> +
> +describe Puppet::Parser::Scope do
> + before :each do
> + @scope = Puppet::Parser::Scope.new()
> + @topscope = Puppet::Parser::Scope.new()
> + @scope.stubs(:parent).returns(@topscope)
> + end
> +
> + describe Puppet::Parser::Scope, "when setvar is called with
> append=true" do
> +
> + it "should raise error if the variable is already defined
> in this scope" do
> + @scope.setvar("var","1",nil,nil,false)
> + lambda { @scope.setvar("var","1",nil,nil,true) }.should
> raise_error(Puppet::ParseError)
> + end
> +
> + it "it should lookup current variable value" do
> + @scope.expects(:lookupvar).with("var").returns("2")
> + @scope.setvar("var","1",nil,nil,true)
> + end
> +
> + it "it should store the concatenated string '42'" do
> + @topscope.setvar("var","4",nil,nil,false)
> + @scope.setvar("var","2",nil,nil,true)
> + @scope.lookupvar("var").should == "42"
> + end
> +
> + it "it should store the concatenated array [4,2]" do
> + @topscope.setvar("var",[4],nil,nil,false)
> + @scope.setvar("var",[2],nil,nil,true)
> + @scope.lookupvar("var").should == [4,2]
> + end
> +
> + end
> +end
> diff --git a/test/data/snippets/append.pp b/test/data/snippets/
> append.pp
> new file mode 100644
> index 0000000..28edeb1
> --- /dev/null
> +++ b/test/data/snippets/append.pp
> @@ -0,0 +1,11 @@
> +$var=['/tmp/file1','/tmp/file2']
> +
> +class arraytest {
> + $var += ['/tmp/file3', '/tmp/file4']
> + file {
> + $var:
> + content => "test"
> + }
> +}
> +
> +include arraytest
> --
> 1.5.6.5
>
>
> >
--
Don't throw away the old bucket until you know whether the new one
holds water. -- Swedish Proverb
---------------------------------------------------------------------
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
-~----------~----~----~----~------~----~------~--~---