3
require File.dirname(__FILE__) + '/../../spec_helper'
5
describe Puppet::Parser::Scope do
7
@scope = Puppet::Parser::Scope.new()
8
@topscope = Puppet::Parser::Scope.new()
9
@scope.stubs(:parent).returns(@topscope)
12
describe Puppet::Parser::Scope, "when setvar is called with append=true" do
14
it "should raise error if the variable is already defined in this scope" do
15
@scope.setvar("var","1",nil,nil,false)
16
lambda { @scope.setvar("var","1",nil,nil,true) }.should raise_error(Puppet::ParseError)
19
it "it should lookup current variable value" do
20
@scope.expects(:lookupvar).with("var").returns("2")
21
@scope.setvar("var","1",nil,nil,true)
24
it "it should store the concatenated string '42'" do
25
@topscope.setvar("var","4",nil,nil,false)
26
@scope.setvar("var","2",nil,nil,true)
27
@scope.lookupvar("var").should == "42"
30
it "it should store the concatenated array [4,2]" do
31
@topscope.setvar("var",[4],nil,nil,false)
32
@scope.setvar("var",[2],nil,nil,true)
33
@scope.lookupvar("var").should == [4,2]
38
describe Puppet::Parser::Scope, "when calling number?" do
40
it "should return nil if called with anything not a number" do
41
Puppet::Parser::Scope.number?([2]).should be_nil
44
it "should return a Fixnum for a Fixnum" do
45
Puppet::Parser::Scope.number?(2).should be_an_instance_of(Fixnum)
48
it "should return a Float for a Float" do
49
Puppet::Parser::Scope.number?(2.34).should be_an_instance_of(Float)
52
it "should return 234 for '234'" do
53
Puppet::Parser::Scope.number?("234").should == 234
56
it "should return nil for 'not a number'" do
57
Puppet::Parser::Scope.number?("not a number").should be_nil
60
it "should return 23.4 for '23.4'" do
61
Puppet::Parser::Scope.number?("23.4").should == 23.4
64
it "should return 23.4e13 for '23.4e13'" do
65
Puppet::Parser::Scope.number?("23.4e13").should == 23.4e13
68
it "should understand negative numbers" do
69
Puppet::Parser::Scope.number?("-234").should == -234
72
it "should know how to convert exponential float numbers ala '23e13'" do
73
Puppet::Parser::Scope.number?("23e13").should == 23e13
76
it "should understand hexadecimal numbers" do
77
Puppet::Parser::Scope.number?("0x234").should == 0x234
80
it "should understand octal numbers" do
81
Puppet::Parser::Scope.number?("0755").should == 0755
84
it "should return nil on malformed integers" do
85
Puppet::Parser::Scope.number?("0.24.5").should be_nil
88
it "should convert strings with leading 0 to integer if they are not octal" do
89
Puppet::Parser::Scope.number?("0788").should == 788
92
it "should convert strings of negative integers" do
93
Puppet::Parser::Scope.number?("-0788").should == -788
96
it "should return nil on malformed hexadecimal numbers" do
97
Puppet::Parser::Scope.number?("0x89g").should be_nil