Sha256: a241be0d0aad0b025e80cb2e11884d680ce50809abd4a53ca6142dfb219bb47b

Contents?: true

Size: 823 Bytes

Versions: 58

Compression:

Stored size: 823 Bytes

Contents

require 'mspec/helpers/encode'

class EqualUtf16Matcher
  def initialize(expected)
    @expected = Array(expected).map { |x| encode x, "binary" }
  end

  def matches?(actual)
    @actual = Array(actual).map { |x| encode x, "binary" }
    @actual == @expected || @actual == expected_swapped
  end

  def expected_swapped
    @expected_swapped ||= @expected.map { |x| x.to_str.gsub(/(.)(.)/, '\2\1') }
  end

  def failure_message
    ["Expected #{@actual.pretty_inspect}",
     "to equal #{@expected.pretty_inspect} or #{expected_swapped.pretty_inspect}"]
  end

  def negative_failure_message
    ["Expected #{@actual.pretty_inspect}",
     "not to equal #{@expected.pretty_inspect} nor #{expected_swapped.pretty_inspect}"]
  end
end

class Object
  def equal_utf16(expected)
    EqualUtf16Matcher.new(expected)
  end
end

Version data entries

58 entries across 58 versions & 3 rubygems

Version Path
rhodes-5.5.18 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-5.5.17 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-5.5.15 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-5.5.0.22 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-5.5.2 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-5.5.0.7 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-5.5.0.3 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-5.5.0 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
tauplatform-1.0.3 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
mspec-1.9.1 lib/mspec/matchers/equal_utf16.rb
mspec-1.9.0 lib/mspec/matchers/equal_utf16.rb
tauplatform-1.0.2 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
tauplatform-1.0.1 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
mspec-1.8.0 lib/mspec/matchers/equal_utf16.rb
mspec-1.7.0 lib/mspec/matchers/equal_utf16.rb
mspec-1.6.0 lib/mspec/matchers/equal_utf16.rb
mspec-1.5.21 lib/mspec/matchers/equal_utf16.rb
mspec-1.5.20 lib/mspec/matchers/equal_utf16.rb
mspec-1.5.19 lib/mspec/matchers/equal_utf16.rb
mspec-1.5.18 lib/mspec/matchers/equal_utf16.rb