summaryrefslogtreecommitdiffstats
path: root/spec/unit/parser/ast/minus.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/parser/ast/minus.rb')
-rwxr-xr-xspec/unit/parser/ast/minus.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/spec/unit/parser/ast/minus.rb b/spec/unit/parser/ast/minus.rb
new file mode 100755
index 000000000..83bd92d0d
--- /dev/null
+++ b/spec/unit/parser/ast/minus.rb
@@ -0,0 +1,36 @@
+#!/usr/bin/env ruby
+
+require File.dirname(__FILE__) + '/../../../spec_helper'
+
+describe Puppet::Parser::AST::Minus do
+ before :each do
+ @scope = Puppet::Parser::Scope.new()
+ end
+
+ it "should evaluate its argument" do
+ value = stub "value"
+ value.expects(:safeevaluate).with(@scope).returns(123)
+
+ operator = Puppet::Parser::AST::Minus.new :value => value
+ operator.evaluate(@scope)
+ end
+
+ it "should fail if argument is not a string or integer" do
+ array_ast = stub 'array_ast', :safeevaluate => [2]
+ operator = Puppet::Parser::AST::Minus.new :value => array_ast
+ lambda { operator.evaluate(@scope) }.should raise_error
+ end
+
+ it "should work with integer as string" do
+ string = stub 'string', :safeevaluate => "123"
+ operator = Puppet::Parser::AST::Minus.new :value => string
+ operator.evaluate(@scope).should == -123
+ end
+
+ it "should work with integers" do
+ int = stub 'int', :safeevaluate => 123
+ operator = Puppet::Parser::AST::Minus.new :value => int
+ operator.evaluate(@scope).should == -123
+ end
+
+end