File: length_spec.rb

package info (click to toggle)
puppet 5.5.22-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 21,316 kB
  • sloc: ruby: 254,925; sh: 1,608; xml: 219; makefile: 153; sql: 103
file content (50 lines) | stat: -rw-r--r-- 1,649 bytes parent folder | download | duplicates (4)
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
require 'spec_helper'

require 'puppet_spec/compiler'
require 'matchers/resource'

describe 'the length function' do
  include PuppetSpec::Compiler
  include Matchers::Resource

  context 'for an array it' do
    it 'returns 0 when empty' do
      expect(compile_to_catalog("notify { String(length([])): }")).to have_resource('Notify[0]')
    end

    it 'returns number of elements when not empty' do
      expect(compile_to_catalog("notify { String(length([1, 2, 3])): }")).to have_resource('Notify[3]')
    end
  end

  context 'for a hash it' do
    it 'returns 0 empty' do
      expect(compile_to_catalog("notify { String(length({})): }")).to have_resource('Notify[0]')
    end

    it 'returns number of elements when not empty' do
      expect(compile_to_catalog("notify { String(length({1=>1,2=>2})): }")).to have_resource('Notify[2]')
    end
  end

  context 'for a string it' do
    it 'returns 0 when empty' do
      expect(compile_to_catalog("notify { String(length('')): }")).to have_resource('Notify[0]')
    end

    it 'returns number of characters when not empty' do
      # note the multibyte characters - åäö each taking two bytes in UTF-8
      expect(compile_to_catalog('notify { String(length("\u00e5\u00e4\u00f6")): }')).to have_resource('Notify[3]')
    end
  end

  context 'for a binary it' do
    it 'returns 0 when empty' do
      expect(compile_to_catalog("notify { String(length(Binary(''))): }")).to have_resource('Notify[0]')
    end

    it 'returns number of bytes when not empty' do
      expect(compile_to_catalog("notify { String(length(Binary('b25l'))): }")).to have_resource('Notify[3]')
    end
  end
end