]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/is_numeric_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / is_numeric_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the is_numeric function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("is_numeric")).to eq("function_is_numeric")
9   end
10
11   it "should raise a ParseError if there is less than 1 argument" do
12     expect { scope.function_is_numeric([]) }.to( raise_error(Puppet::ParseError))
13   end
14
15   it "should return true if an integer" do
16     result = scope.function_is_numeric(["3"])
17     expect(result).to(eq(true))
18   end
19
20   it "should return true if a float" do
21     result = scope.function_is_numeric(["3.2"])
22     expect(result).to(eq(true))
23   end
24
25   it "should return true if an integer is created from an arithmetical operation" do
26     result = scope.function_is_numeric([3*2])
27     expect(result).to(eq(true))
28   end
29
30   it "should return true if a float is created from an arithmetical operation" do
31     result = scope.function_is_numeric([3.2*2])
32     expect(result).to(eq(true))
33   end
34
35   it "should return false if a string" do
36     result = scope.function_is_numeric(["asdf"])
37     expect(result).to(eq(false))
38   end
39
40   it "should return false if an array" do
41     result = scope.function_is_numeric([["asdf"]])
42     expect(result).to(eq(false))
43   end
44
45   it "should return false if an array of integers" do
46     result = scope.function_is_numeric([[1,2,3,4]])
47     expect(result).to(eq(false))
48   end
49
50   it "should return false if a hash" do
51     result = scope.function_is_numeric([{"asdf" => false}])
52     expect(result).to(eq(false))
53   end
54
55   it "should return false if a hash with numbers in it" do
56     result = scope.function_is_numeric([{1 => 2}])
57     expect(result).to(eq(false))
58   end
59
60   it "should return false if a boolean" do
61     result = scope.function_is_numeric([true])
62     expect(result).to(eq(false))
63   end
64
65   it "should return true if a negative float with exponent" do
66     result = scope.function_is_numeric(["-342.2315e-12"])
67     expect(result).to(eq(true))
68   end
69
70   it "should return false if a negative integer with whitespaces before/after the dash" do
71     result = scope.function_is_numeric([" -  751"])
72     expect(result).to(eq(false))
73   end
74
75 #  it "should return true if a hexadecimal" do
76 #    result = scope.function_is_numeric(["0x52F8c"])
77 #    result.should(eq(true))
78 #  end
79 #
80 #  it "should return true if a hexadecimal with uppercase 0X prefix" do
81 #    result = scope.function_is_numeric(["0X52F8c"])
82 #    result.should(eq(true))
83 #  end
84 #
85 #  it "should return false if a hexadecimal without a prefix" do
86 #    result = scope.function_is_numeric(["52F8c"])
87 #    result.should(eq(false))
88 #  end
89 #
90 #  it "should return true if a octal" do
91 #    result = scope.function_is_numeric(["0751"])
92 #    result.should(eq(true))
93 #  end
94 #
95 #  it "should return true if a negative hexadecimal" do
96 #    result = scope.function_is_numeric(["-0x52F8c"])
97 #    result.should(eq(true))
98 #  end
99 #
100 #  it "should return true if a negative octal" do
101 #    result = scope.function_is_numeric(["-0751"])
102 #    result.should(eq(true))
103 #  end
104 #
105 #  it "should return false if a negative octal with whitespaces before/after the dash" do
106 #    result = scope.function_is_numeric([" -  0751"])
107 #    result.should(eq(false))
108 #  end
109 #
110 #  it "should return false if a bad hexadecimal" do
111 #    result = scope.function_is_numeric(["0x23d7g"])
112 #    result.should(eq(false))
113 #  end
114 #
115 #  it "should return false if a bad octal" do
116 #    result = scope.function_is_numeric(["0287"])
117 #    result.should(eq(false))
118 #  end
119 end