[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, master, updated. debian/0.24.6-1-356-g5718585

Brice Figureau brice at daysofwonder.com
Fri Jan 23 14:21:04 UTC 2009


The following commit has been merged in the master branch:
commit 850e0baf0fbe321f14d4b9d913ce7dea39c9aa27
Author: Brice Figureau <brice-puppet at daysofwonder.com>
Date:   Fri Sep 26 22:59:50 2008 +0200

    Add not operator to AST

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

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list