+1
On Sep 19, 2008, at 2:29 PM, Brice Figureau wrote:
>
>
> Signed-off-by: Brice Figureau <[EMAIL PROTECTED]>
> ---
> lib/puppet/parser/ast.rb | 1 +
> lib/puppet/parser/ast/not.rb | 19 +++++++++++++++++++
> spec/unit/parser/ast/not.rb | 30 ++++++++++++++++++++++++++++++
> 3 files changed, 50 insertions(+), 0 deletions(-)
> create mode 100644 lib/puppet/parser/ast/not.rb
> create mode 100755 spec/unit/parser/ast/not.rb
>
> diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb
> index da82a30..5727712 100644
> --- a/lib/puppet/parser/ast.rb
> +++ b/lib/puppet/parser/ast.rb
> @@ -89,6 +89,7 @@ require 'puppet/parser/ast/hostclass'
> require 'puppet/parser/ast/ifstatement'
> require 'puppet/parser/ast/leaf'
> require 'puppet/parser/ast/node'
> +require 'puppet/parser/ast/not'
> require 'puppet/parser/ast/resource'
> require 'puppet/parser/ast/resource_defaults'
> require 'puppet/parser/ast/resource_override'
> diff --git a/lib/puppet/parser/ast/not.rb b/lib/puppet/parser/ast/
> not.rb
> new file mode 100644
> index 0000000..c8fa1df
> --- /dev/null
> +++ b/lib/puppet/parser/ast/not.rb
> @@ -0,0 +1,19 @@
> +require 'puppet'
> +require 'puppet/parser/ast/branch'
> +
> +# An object that returns a boolean which is the boolean not
> +# of the given value.
> +class Puppet::Parser::AST
> + class Not < AST::Branch
> + attr_accessor :value
> +
> + def each
> + yield @value
> + end
> +
> + def evaluate(scope)
> + val = @value.safeevaluate(scope)
> + return ! Puppet::Parser::Scope.true?(val)
> + end
> + end
> +end
> diff --git a/spec/unit/parser/ast/not.rb b/spec/unit/parser/ast/not.rb
> new file mode 100755
> index 0000000..0fe2ded
> --- /dev/null
> +++ b/spec/unit/parser/ast/not.rb
> @@ -0,0 +1,30 @@
> +#!/usr/bin/env ruby
> +
> +require File.dirname(__FILE__) + '/../../../spec_helper'
> +
> +describe Puppet::Parser::AST::Not do
> + before :each do
> + @scope = Puppet::Parser::Scope.new()
> + @true_ast = Puppet::Parser::AST::Boolean.new( :value => true)
> + @false_ast = Puppet::Parser::AST::Boolean.new( :value =>
> false)
> + end
> +
> + it "should evaluate its child expression" do
> + val = stub "val"
> + val.expects(:safeevaluate).with(@scope)
> +
> + operator = Puppet::Parser::AST::Not.new :value => val
> + operator.evaluate(@scope)
> + end
> +
> + it "should return true for ! false" do
> + operator = Puppet::Parser::AST::Not.new :value => @false_ast
> + operator.evaluate(@scope).should == true
> + end
> +
> + it "should return false for ! true" do
> + operator = Puppet::Parser::AST::Not.new :value => @true_ast
> + operator.evaluate(@scope).should == false
> + end
> +
> +end
> --
> 1.5.6.5
>
>
> >
--
The cure for writer's cramp is writer's block.
-- Inigo DeLeon
---------------------------------------------------------------------
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
-~----------~----~----~----~------~----~------~--~---