1 #! /usr/bin/env ruby -S rspec
4 describe "the is_integer function" do
5 let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
8 expect(Puppet::Parser::Functions.function("is_integer")).to eq("function_is_integer")
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))
15 it "should return true if an integer" do
16 result = scope.function_is_integer(["3"])
17 expect(result).to(eq(true))
20 it "should return true if a negative integer" do
21 result = scope.function_is_integer(["-7"])
22 expect(result).to(eq(true))
25 it "should return false if a float" do
26 result = scope.function_is_integer(["3.2"])
27 expect(result).to(eq(false))
30 it "should return false if a string" do
31 result = scope.function_is_integer(["asdf"])
32 expect(result).to(eq(false))
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))
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 a hash" do
46 result = scope.function_is_numeric([{"asdf" => false}])
47 expect(result).to(eq(false))
50 it "should return false if a boolean" do
51 result = scope.function_is_numeric([true])
52 expect(result).to(eq(false))
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))
60 it "should return false if it is zero prefixed" do
61 result = scope.function_is_numeric(["0001234"])
62 expect(result).to(eq(false))
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))