Sha256: 3ac422f1d3ca968147473623d9eaea04967fa283098026427c1c6d220f74d15e

Contents?: true

Size: 1.56 KB

Versions: 36

Compression:

Stored size: 1.56 KB

Contents

# encoding: UTF-8

require 'spec_helper'
require 'puppet/util/windows'

describe "Puppet::Util::Windows::String", :if => Puppet.features.microsoft_windows? do
  UTF16_NULL = [0, 0]

  def wide_string(str)
    Puppet::Util::Windows::String.wide_string(str)
  end

  def converts_to_wide_string(string_value)
    expected = string_value.encode(Encoding::UTF_16LE)
    expected_bytes = expected.bytes.to_a + UTF16_NULL

    expect(wide_string(string_value).bytes.to_a).to eq(expected_bytes)
  end

  context "wide_string" do
    it "should return encoding of UTF-16LE" do
      expect(wide_string("bob").encoding).to eq(Encoding::UTF_16LE)
    end

    it "should return valid encoding" do
      expect(wide_string("bob").valid_encoding?).to be_truthy
    end

    it "should convert an ASCII string" do
      converts_to_wide_string("bob".encode(Encoding::US_ASCII))
    end

    it "should convert a UTF-8 string" do
      converts_to_wide_string("bob".encode(Encoding::UTF_8))
    end

    it "should convert a UTF-16LE string" do
      converts_to_wide_string("bob\u00E8".encode(Encoding::UTF_16LE))
    end

    it "should convert a UTF-16BE string" do
      converts_to_wide_string("bob\u00E8".encode(Encoding::UTF_16BE))
    end

    it "should convert an UTF-32LE string" do
      converts_to_wide_string("bob\u00E8".encode(Encoding::UTF_32LE))
    end

    it "should convert an UTF-32BE string" do
      converts_to_wide_string("bob\u00E8".encode(Encoding::UTF_32BE))
    end

    it "should return a nil when given a nil" do
      expect(wide_string(nil)).to eq(nil)
    end
  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
puppet-5.5.22 spec/unit/util/windows/string_spec.rb
puppet-5.5.22-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-5.5.22-x64-mingw32 spec/unit/util/windows/string_spec.rb
puppet-5.5.22-universal-darwin spec/unit/util/windows/string_spec.rb
puppet-5.5.21 spec/unit/util/windows/string_spec.rb
puppet-5.5.21-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-5.5.21-x64-mingw32 spec/unit/util/windows/string_spec.rb
puppet-5.5.21-universal-darwin spec/unit/util/windows/string_spec.rb
puppet-5.5.20 spec/unit/util/windows/string_spec.rb
puppet-5.5.20-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-5.5.20-x64-mingw32 spec/unit/util/windows/string_spec.rb
puppet-5.5.20-universal-darwin spec/unit/util/windows/string_spec.rb
puppet-5.5.19 spec/unit/util/windows/string_spec.rb
puppet-5.5.19-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-5.5.19-x64-mingw32 spec/unit/util/windows/string_spec.rb
puppet-5.5.19-universal-darwin spec/unit/util/windows/string_spec.rb
puppet-5.5.18 spec/unit/util/windows/string_spec.rb
puppet-5.5.18-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-5.5.18-x64-mingw32 spec/unit/util/windows/string_spec.rb
puppet-5.5.18-universal-darwin spec/unit/util/windows/string_spec.rb