~ubuntu-branches/ubuntu/karmic/puppet/karmic-security

« back to all changes in this revision

Viewing changes to spec/unit/parser/scope.rb

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Pollock
  • Date: 2009-04-13 17:12:47 UTC
  • mfrom: (1.1.9 upstream) (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090413171247-qou3gsiihama09cm
Tags: 0.24.8-1
* New upstream release
* debian/control: Add Nigel Kersten and myself as uploaders
* debian/changelog: wrap long lines
* debian/watch: ignore release candidates
* debian/compat: bump to 5
* debian/control: bump Standards-Version (no changes)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env ruby
 
2
 
 
3
require File.dirname(__FILE__) + '/../../spec_helper'
 
4
 
 
5
describe Puppet::Parser::Scope do
 
6
    before :each do
 
7
        @scope = Puppet::Parser::Scope.new()
 
8
        @topscope = Puppet::Parser::Scope.new()
 
9
        @scope.stubs(:parent).returns(@topscope)
 
10
    end
 
11
 
 
12
    describe Puppet::Parser::Scope, "when setvar is called with append=true" do
 
13
 
 
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)
 
17
        end
 
18
 
 
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)
 
22
        end
 
23
 
 
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"
 
28
        end
 
29
 
 
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]
 
34
        end
 
35
 
 
36
    end
 
37
 
 
38
    describe Puppet::Parser::Scope, "when calling number?" do
 
39
 
 
40
        it "should return nil if called with anything not a number" do
 
41
            Puppet::Parser::Scope.number?([2]).should be_nil
 
42
        end
 
43
 
 
44
        it "should return a Fixnum for a Fixnum" do
 
45
            Puppet::Parser::Scope.number?(2).should be_an_instance_of(Fixnum)
 
46
        end
 
47
 
 
48
        it "should return a Float for a Float" do
 
49
            Puppet::Parser::Scope.number?(2.34).should be_an_instance_of(Float)
 
50
        end
 
51
 
 
52
        it "should return 234 for '234'" do
 
53
            Puppet::Parser::Scope.number?("234").should == 234
 
54
        end
 
55
 
 
56
        it "should return nil for 'not a number'" do
 
57
            Puppet::Parser::Scope.number?("not a number").should be_nil
 
58
        end
 
59
 
 
60
        it "should return 23.4 for '23.4'" do
 
61
            Puppet::Parser::Scope.number?("23.4").should == 23.4
 
62
        end
 
63
 
 
64
        it "should return 23.4e13 for '23.4e13'" do
 
65
            Puppet::Parser::Scope.number?("23.4e13").should == 23.4e13
 
66
        end
 
67
 
 
68
        it "should understand negative numbers" do
 
69
            Puppet::Parser::Scope.number?("-234").should == -234
 
70
        end
 
71
 
 
72
        it "should know how to convert exponential float numbers ala '23e13'" do
 
73
            Puppet::Parser::Scope.number?("23e13").should == 23e13
 
74
        end
 
75
 
 
76
        it "should understand hexadecimal numbers" do
 
77
            Puppet::Parser::Scope.number?("0x234").should == 0x234
 
78
        end
 
79
 
 
80
        it "should understand octal numbers" do
 
81
            Puppet::Parser::Scope.number?("0755").should == 0755
 
82
        end
 
83
 
 
84
        it "should return nil on malformed integers" do
 
85
            Puppet::Parser::Scope.number?("0.24.5").should be_nil
 
86
        end
 
87
 
 
88
        it "should convert strings with leading 0 to integer if they are not octal" do
 
89
            Puppet::Parser::Scope.number?("0788").should == 788
 
90
        end
 
91
 
 
92
        it "should convert strings of negative integers" do
 
93
            Puppet::Parser::Scope.number?("-0788").should == -788
 
94
        end
 
95
 
 
96
        it "should return nil on malformed hexadecimal numbers" do
 
97
            Puppet::Parser::Scope.number?("0x89g").should be_nil
 
98
        end
 
99
    end
 
100
 
 
101
end