2012-07-20 00:27:52 +02:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
2011-06-29 22:21:55 +02:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe "the num2bool function" do
|
2012-07-23 17:28:06 +02:00
|
|
|
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
|
2011-06-29 22:21:55 +02:00
|
|
|
|
|
|
|
it "should exist" do
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(Puppet::Parser::Functions.function("num2bool")).to eq("function_num2bool")
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
2013-03-29 17:03:33 +01:00
|
|
|
it "should raise a ParseError if there are no arguments" do
|
2014-06-04 20:38:37 +02:00
|
|
|
expect { scope.function_num2bool([]) }.to( raise_error(Puppet::ParseError))
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|
|
|
|
|
2013-03-29 17:03:33 +01:00
|
|
|
it "should raise a ParseError if there are more than 1 arguments" do
|
2014-06-04 20:38:37 +02:00
|
|
|
expect { scope.function_num2bool(["foo","bar"]) }.to( raise_error(Puppet::ParseError))
|
2013-03-29 17:03:33 +01:00
|
|
|
end
|
|
|
|
|
2013-03-29 20:06:36 +01:00
|
|
|
it "should raise a ParseError if passed something non-numeric" do
|
2014-06-04 20:38:37 +02:00
|
|
|
expect { scope.function_num2bool(["xyzzy"]) }.to( raise_error(Puppet::ParseError))
|
2013-03-29 20:06:36 +01:00
|
|
|
end
|
|
|
|
|
2013-03-29 15:04:05 +01:00
|
|
|
it "should return true if passed string 1" do
|
2012-07-20 01:14:37 +02:00
|
|
|
result = scope.function_num2bool(["1"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2011-07-29 21:57:10 +02:00
|
|
|
end
|
|
|
|
|
2013-04-01 17:44:09 +02:00
|
|
|
it "should return true if passed string 1.5" do
|
|
|
|
result = scope.function_num2bool(["1.5"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2013-03-29 20:06:36 +01:00
|
|
|
end
|
|
|
|
|
2013-04-01 17:44:09 +02:00
|
|
|
it "should return true if passed number 1" do
|
|
|
|
result = scope.function_num2bool([1])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_truthy)
|
2013-03-29 20:06:36 +01:00
|
|
|
end
|
|
|
|
|
2013-03-29 15:04:05 +01:00
|
|
|
it "should return false if passed string 0" do
|
2012-07-20 01:14:37 +02:00
|
|
|
result = scope.function_num2bool(["0"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_falsey)
|
2011-07-24 01:39:17 +02:00
|
|
|
end
|
2013-03-29 15:04:05 +01:00
|
|
|
|
|
|
|
it "should return false if passed number 0" do
|
|
|
|
result = scope.function_num2bool([0])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_falsey)
|
2013-03-29 15:04:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "should return false if passed string -1" do
|
|
|
|
result = scope.function_num2bool(["-1"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_falsey)
|
2013-03-29 15:04:05 +01:00
|
|
|
end
|
|
|
|
|
2013-04-01 17:44:09 +02:00
|
|
|
it "should return false if passed string -1.5" do
|
|
|
|
result = scope.function_num2bool(["-1.5"])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_falsey)
|
2013-03-29 15:04:05 +01:00
|
|
|
end
|
2013-03-29 17:03:33 +01:00
|
|
|
|
2013-04-01 17:44:09 +02:00
|
|
|
it "should return false if passed number -1" do
|
|
|
|
result = scope.function_num2bool([-1])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_falsey)
|
2013-03-29 17:03:33 +01:00
|
|
|
end
|
2013-03-29 20:06:36 +01:00
|
|
|
|
2013-04-01 17:44:09 +02:00
|
|
|
it "should return false if passed float -1.5" do
|
|
|
|
result = scope.function_num2bool([-1.5])
|
2014-06-04 20:38:37 +02:00
|
|
|
expect(result).to(be_falsey)
|
2013-03-29 20:06:36 +01:00
|
|
|
end
|
2011-06-29 22:21:55 +02:00
|
|
|
end
|