Sha256: 050ad1d78655ce06c790f131acf29649bab9b5e55161412810d89e911ed30265

Contents?: true

Size: 1.46 KB

Versions: 19

Compression:

Stored size: 1.46 KB

Contents

# encoding: UTF-8
#!/usr/bin/env ruby

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

    wide_string(string_value).bytes.to_a.should == expected_bytes
  end

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

    it "should return valid encoding" do
      wide_string("bob").valid_encoding?.should be_true
    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
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
puppet-3.6.2 spec/unit/util/windows/string_spec.rb
puppet-3.6.2-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-3.6.1 spec/unit/util/windows/string_spec.rb
puppet-3.6.1-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-3.6.0 spec/unit/util/windows/string_spec.rb
puppet-3.6.0-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-3.6.0.rc1 spec/unit/util/windows/string_spec.rb
puppet-3.6.0.rc1-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-3.5.1 spec/unit/util/windows/string_spec.rb
puppet-3.5.1-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-3.5.1.rc1 spec/unit/util/windows/string_spec.rb
puppet-3.5.1.rc1-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-3.5.0.rc3 spec/unit/util/windows/string_spec.rb
puppet-3.5.0.rc3-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-3.5.0.rc2 spec/unit/util/windows/string_spec.rb
puppet-3.5.0.rc2-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-3.5.0.rc1 spec/unit/util/windows/string_spec.rb
puppet-3.5.0.rc1-x86-mingw32 spec/unit/util/windows/string_spec.rb
puppet-3.4.3 spec/unit/util/windows/string_spec.rb