summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorTP Honey <tphoney@users.noreply.github.com>2015-08-27 10:50:29 +0100
committerTP Honey <tphoney@users.noreply.github.com>2015-08-27 10:50:29 +0100
commitb10978703a5e4f07f240c509a3cf881210fbd5c5 (patch)
treefca31ecf05fee935edd06ea1b2e8ed8aaa24fa84 /spec
parent1bed010dbbd4590b3299c81b0e962e76b8ffa845 (diff)
parent2d4f5aa4d943e27ffeae524469f9c6eb18ce64d8 (diff)
downloadpuppet-stdlib-b10978703a5e4f07f240c509a3cf881210fbd5c5.tar.gz
puppet-stdlib-b10978703a5e4f07f240c509a3cf881210fbd5c5.tar.bz2
Merge pull request #514 from DavidS/add-convert_base
Adds a convert_base function, which can convert numbers between bases
Diffstat (limited to 'spec')
-rw-r--r--spec/functions/convert_base_spec.rb24
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/functions/convert_base_spec.rb b/spec/functions/convert_base_spec.rb
new file mode 100644
index 0000000..8ab2284
--- /dev/null
+++ b/spec/functions/convert_base_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper'
+
+describe 'convert_base' do
+ it { is_expected.not_to eq(nil) }
+ it { is_expected.to run.with_params().and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params("asdf").and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params("asdf","moo","cow").and_raise_error(ArgumentError) }
+ it { is_expected.to run.with_params(["1"],"2").and_raise_error(Puppet::ParseError, /argument must be either a string or an integer/) }
+ it { is_expected.to run.with_params("1",["2"]).and_raise_error(Puppet::ParseError, /argument must be either a string or an integer/) }
+ it { is_expected.to run.with_params("1",1).and_raise_error(Puppet::ParseError, /base must be at least 2 and must not be greater than 36/) }
+ it { is_expected.to run.with_params("1",37).and_raise_error(Puppet::ParseError, /base must be at least 2 and must not be greater than 36/) }
+
+ it "should raise a ParseError if argument 1 is a string that does not correspond to an integer in base 10" do
+ is_expected.to run.with_params("ten",6).and_raise_error(Puppet::ParseError, /argument must be an integer or a string corresponding to an integer in base 10/)
+ end
+
+ it "should raise a ParseError if argument 2 is a string and does not correspond to an integer in base 10" do
+ is_expected.to run.with_params(100,"hex").and_raise_error(Puppet::ParseError, /argument must be an integer or a string corresponding to an integer in base 10/)
+ end
+
+ it { is_expected.to run.with_params("11",'16').and_return('b') }
+ it { is_expected.to run.with_params("35",'36').and_return('z') }
+ it { is_expected.to run.with_params(5, 2).and_return('101') }
+end