File: utils_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 (70 lines) | stat: -rw-r--r-- 2,512 bytes parent folder | download | duplicates (6)
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
require 'spec_helper'
require 'puppet/pops'

describe 'pops utils' do
  context 'when converting strings to numbers' do
    it 'should convert "0" to 0' do
      expect(Puppet::Pops::Utils.to_n("0")).to eq(0)
    end

    it 'should convert "0" to 0 with radix' do
      expect(Puppet::Pops::Utils.to_n_with_radix("0")).to eq([0, 10])
    end

    it 'should convert "0.0" to 0.0' do
      expect(Puppet::Pops::Utils.to_n("0.0")).to eq(0.0)
    end

    it 'should convert "0.0" to 0.0 with radix' do
      expect(Puppet::Pops::Utils.to_n_with_radix("0.0")).to eq([0.0, 10])
    end

    it 'should convert "0.01e1" to 0.01e1' do
      expect(Puppet::Pops::Utils.to_n("0.01e1")).to eq(0.01e1)
      expect(Puppet::Pops::Utils.to_n("0.01E1")).to eq(0.01e1)
    end

    it 'should convert "0.01e1" to 0.01e1 with radix' do
      expect(Puppet::Pops::Utils.to_n_with_radix("0.01e1")).to eq([0.01e1, 10])
      expect(Puppet::Pops::Utils.to_n_with_radix("0.01E1")).to eq([0.01e1, 10])
    end

    it 'should not convert "0e1" to floating point' do
      expect(Puppet::Pops::Utils.to_n("0e1")).to be_nil
      expect(Puppet::Pops::Utils.to_n("0E1")).to be_nil
    end

    it 'should not convert "0e1" to floating point with radix' do
      expect(Puppet::Pops::Utils.to_n_with_radix("0e1")).to be_nil
      expect(Puppet::Pops::Utils.to_n_with_radix("0E1")).to be_nil
    end

    it 'should not convert "0.0e1" to floating point' do
      expect(Puppet::Pops::Utils.to_n("0.0e1")).to be_nil
      expect(Puppet::Pops::Utils.to_n("0.0E1")).to be_nil
    end

    it 'should not convert "0.0e1" to floating point with radix' do
      expect(Puppet::Pops::Utils.to_n_with_radix("0.0e1")).to be_nil
      expect(Puppet::Pops::Utils.to_n_with_radix("0.0E1")).to be_nil
    end

    it 'should not convert "000000.0000e1" to floating point' do
      expect(Puppet::Pops::Utils.to_n("000000.0000e1")).to be_nil
      expect(Puppet::Pops::Utils.to_n("000000.0000E1")).to be_nil
    end

    it 'should not convert "000000.0000e1" to floating point with radix' do
      expect(Puppet::Pops::Utils.to_n_with_radix("000000.0000e1")).to be_nil
      expect(Puppet::Pops::Utils.to_n_with_radix("000000.0000E1")).to be_nil
    end

    it 'should not convert infinite values to floating point' do
      expect(Puppet::Pops::Utils.to_n("4e999")).to be_nil
    end

    it 'should not convert infinite values to floating point with_radix' do
      expect(Puppet::Pops::Utils.to_n_with_radix("4e999")).to be_nil
    end
  end
end