summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/puppet/parser/ast.rb1
-rw-r--r--lib/puppet/parser/ast/not.rb19
-rwxr-xr-xspec/unit/parser/ast/not.rb30
3 files changed, 50 insertions, 0 deletions
diff --git a/lib/puppet/parser/ast.rb b/lib/puppet/parser/ast.rb
index da82a30c7..572771201 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 000000000..c8fa1df2c
--- /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 000000000..0fe2deddd
--- /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