1 #! /usr/bin/env ruby -S rspec
4 describe "the is_numeric function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("is_numeric")).to eq("function_is_numeric")
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))
15 it "should return true if an integer" do
16 result = scope.function_is_numeric(["3"])
17 expect(result).to(eq(true))
20 it "should return true if a float" do
21 result = scope.function_is_numeric(["3.2"])
22 expect(result).to(eq(true))
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))
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))
35 it "should return false if a string" do
36 result = scope.function_is_numeric(["asdf"])
37 expect(result).to(eq(false))
40 it "should return false if an array" do
41 result = scope.function_is_numeric([["asdf"]])
42 expect(result).to(eq(false))
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))
50 it "should return false if a hash" do
51 result = scope.function_is_numeric([{"asdf" => false}])
52 expect(result).to(eq(false))
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))
60 it "should return false if a boolean" do
61 result = scope.function_is_numeric([true])
62 expect(result).to(eq(false))
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))
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))
75 # it "should return true if a hexadecimal" do
76 # result = scope.function_is_numeric(["0x52F8c"])
77 # result.should(eq(true))
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))
85 # it "should return false if a hexadecimal without a prefix" do
86 # result = scope.function_is_numeric(["52F8c"])
87 # result.should(eq(false))
90 # it "should return true if a octal" do
91 # result = scope.function_is_numeric(["0751"])
92 # result.should(eq(true))
95 # it "should return true if a negative hexadecimal" do
96 # result = scope.function_is_numeric(["-0x52F8c"])
97 # result.should(eq(true))
100 # it "should return true if a negative octal" do
101 # result = scope.function_is_numeric(["-0751"])
102 # result.should(eq(true))
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))
110 # it "should return false if a bad hexadecimal" do
111 # result = scope.function_is_numeric(["0x23d7g"])
112 # result.should(eq(false))
115 # it "should return false if a bad octal" do
116 # result = scope.function_is_numeric(["0287"])
117 # result.should(eq(false))