File: value_translator_spec.rb

package info (click to toggle)
puppet-agent 7.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 19,092 kB
  • sloc: ruby: 245,074; sh: 456; makefile: 38; xml: 33
file content (75 lines) | stat: -rw-r--r-- 2,089 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require 'spec_helper'
require 'puppet/settings/value_translator'

describe Puppet::Settings::ValueTranslator do
  let(:translator) { Puppet::Settings::ValueTranslator.new }

  context "booleans" do
    it "translates strings representing booleans to booleans" do
      expect(translator['true']).to eq(true)
      expect(translator['false']).to eq(false)
    end

    it "translates boolean values into themselves" do
      expect(translator[true]).to eq(true)
      expect(translator[false]).to eq(false)
    end

    it "leaves a boolean string with whitespace as a string" do
      expect(translator[' true']).to eq(" true")
      expect(translator['true ']).to eq("true")

      expect(translator[' false']).to eq(" false")
      expect(translator['false ']).to eq("false")
    end
  end

  context "numbers" do
    it "leaves integer strings" do
      expect(translator["1"]).to eq("1")
    end

    it "leaves octal numbers as strings" do
      expect(translator["011"]).to eq("011")
    end

    it "leaves hex numbers as strings" do
      expect(translator["0x11"]).to eq("0x11")
    end
  end

  context "arbitrary strings" do
    it "translates an empty string as the empty string" do
      expect(translator[""]).to eq("")
    end


    it "strips double quotes" do
      expect(translator['"a string"']).to eq('a string')
    end

    it "strips single quotes" do
      expect(translator["'a string'"]).to eq("a string")
    end

    it "does not strip preceding whitespace" do
      expect(translator[" \ta string"]).to eq(" \ta string")
    end

    it "strips trailing whitespace" do
      expect(translator["a string\t "]).to eq("a string")
    end

    it "leaves leading quote that is preceded by whitespace" do
      expect(translator[" 'a string'"]).to eq(" 'a string")
    end

    it "leaves trailing quote that is succeeded by whitespace" do
      expect(translator["'a string' "]).to eq("a string'")
    end

    it "leaves quotes that are not at the beginning or end of the string" do
      expect(translator["a st'\"ring"]).to eq("a st'\"ring")
    end
  end
end