]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/spec/functions/is_integer_spec.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / spec / functions / is_integer_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper'
3
4 describe "the is_integer function" do
5   let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
6
7   it "should exist" do
8     expect(Puppet::Parser::Functions.function("is_integer")).to eq("function_is_integer")
9   end
10
11   it "should raise a ParseError if there is less than 1 arguments" do
12     expect { scope.function_is_integer([]) }.to( raise_error(Puppet::ParseError))
13   end
14
15   it "should return true if an integer" do
16     result = scope.function_is_integer(["3"])
17     expect(result).to(eq(true))
18   end
19
20   it "should return true if a negative integer" do
21     result = scope.function_is_integer(["-7"])
22     expect(result).to(eq(true))
23   end
24
25   it "should return false if a float" do
26     result = scope.function_is_integer(["3.2"])
27     expect(result).to(eq(false))
28   end
29
30   it "should return false if a string" do
31     result = scope.function_is_integer(["asdf"])
32     expect(result).to(eq(false))
33   end
34
35   it "should return true if an integer is created from an arithmetical operation" do
36     result = scope.function_is_integer([3*2])
37     expect(result).to(eq(true))
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 a hash" do
46     result = scope.function_is_numeric([{"asdf" => false}])
47     expect(result).to(eq(false))
48   end
49
50   it "should return false if a boolean" do
51     result = scope.function_is_numeric([true])
52     expect(result).to(eq(false))
53   end
54
55   it "should return false if a whitespace is in the string" do
56     result = scope.function_is_numeric([" -1324"])
57     expect(result).to(eq(false))
58   end
59
60   it "should return false if it is zero prefixed" do
61     result = scope.function_is_numeric(["0001234"])
62     expect(result).to(eq(false))
63   end
64
65   it "should return false if it is wrapped inside an array" do
66     result = scope.function_is_numeric([[1234]])
67     expect(result).to(eq(false))
68   end
69 end