Sha256: 6ac7c80056eca101ba98565e67bfadf315a1aaf59c91180e1a6260b57dc06318

Contents?: true

Size: 844 Bytes

Versions: 134

Compression:

Stored size: 844 Bytes

Contents

class EqualUtf16Matcher
  def initialize(expected)
    @expected = expected
  end

  def matches?(actual)
    @actual = actual
    @actual == @expected || @actual == expected_swapped
  end

  def expected_swapped
    if @expected.respond_to?(:to_str)
      @expected_swapped ||= @expected.to_str.gsub(/(.)(.)/, '\2\1')
    else
      @expected_swapped ||= @expected.collect { |s| s.to_str.gsub(/(.)(.)/, '\2\1') }
    end
  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

134 entries across 110 versions & 3 rubygems

Version Path
rhodes-3.1.1 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.1.1.beta lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.1.0 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.1.0.beta.5 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.1.0.beta.4 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.1.0.beta.3 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.1.0.beta.2 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.1.0.beta.1 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.2 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.2.beta.1 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.1 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.1.beta.8 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.1.beta.7 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.1.beta.6 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.1.beta.5 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.1.beta.4 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.1.beta.3 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.1.beta.2 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.0 lib/extensions/mspec/mspec/matchers/equal_utf16.rb
rhodes-3.0.0.beta.7 lib/extensions/mspec/mspec/matchers/equal_utf16.rb