Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / num2bool_spec.rb
1 require 'spec_helper_acceptance'
2
3 describe 'num2bool function' do
4   describe 'success' do
5     pp1 = <<-DOC
6       $a = 1
7       $b = "1"
8       $c = "50"
9       $ao = num2bool($a)
10       $bo = num2bool($b)
11       $co = num2bool($c)
12       notice(inline_template('a is <%= @ao.inspect %>'))
13       notice(inline_template('b is <%= @bo.inspect %>'))
14       notice(inline_template('c is <%= @co.inspect %>'))
15     DOC
16     regex_array_true = [%r{a is true}, %r{b is true}, %r{c is true}]
17     it 'bools positive numbers and numeric strings as true' do
18       apply_manifest(pp1, :catch_failures => true) do |r|
19         regex_array_true.each do |i|
20           expect(r.stdout).to match(i)
21         end
22       end
23     end
24
25     pp2 = <<-DOC
26       $a = 0
27       $b = -0.1
28       $c = ["-50","1"]
29       $ao = num2bool($a)
30       $bo = num2bool($b)
31       $co = num2bool($c)
32       notice(inline_template('a is <%= @ao.inspect %>'))
33       notice(inline_template('b is <%= @bo.inspect %>'))
34       notice(inline_template('c is <%= @co.inspect %>'))
35     DOC
36     regex_array_false = [%r{a is false}, %r{b is false}, %r{c is false}]
37     it 'bools negative numbers as false' do
38       apply_manifest(pp2, :catch_failures => true) do |r|
39         regex_array_false.each do |i|
40           expect(r.stdout).to match(i)
41         end
42       end
43     end
44   end
45
46   describe 'failure' do
47     pp3 = <<-DOC
48       $a = "a"
49       $ao = num2bool($a)
50       notice(inline_template('a is <%= @ao.inspect %>'))
51     DOC
52     it 'fails on words' do
53       expect(apply_manifest(pp3, :expect_failures => true).stderr).to match(%r{not look like a number})
54     end
55
56     pp4 = <<-DOC
57       $b = "1b"
58       $bo = num2bool($b)
59       notice(inline_template('b is <%= @bo.inspect %>'))
60     DOC
61     it 'fails on numberwords' do
62       expect(apply_manifest(pp4, :expect_failures => true).stderr).to match(%r{not look like a number})
63     end
64
65     pp5 = <<-DOC # rubocop:disable Lint/UselessAssignment
66       $c = {"c" => "-50"}
67       $co = num2bool($c)
68       notice(inline_template('c is <%= @co.inspect %>'))
69     DOC
70     it 'fails on non-numeric/strings' do
71       pending "The function will call .to_s.to_i on anything not a Numeric or
72       String, and results in 0. Is this intended?"
73       expect(apply_manifest(pp5(:expect_failures => true)).stderr).to match(%r{Unable to parse})
74     end
75   end
76 end