Class: EqualUtf16Matcher

Inherits:
Object show all
Defined in:
lib/mspec/matchers/equal_utf16.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ EqualUtf16Matcher

Returns a new instance of EqualUtf16Matcher.



2
3
4
# File 'lib/mspec/matchers/equal_utf16.rb', line 2

def initialize(expected)
  @expected = expected
end

Instance Method Details

#expected_swappedObject



11
12
13
14
15
16
17
# File 'lib/mspec/matchers/equal_utf16.rb', line 11

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

#failure_messageObject



19
20
21
22
# File 'lib/mspec/matchers/equal_utf16.rb', line 19

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
# File 'lib/mspec/matchers/equal_utf16.rb', line 6

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

#negative_failure_messageObject



24
25
26
27
# File 'lib/mspec/matchers/equal_utf16.rb', line 24

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