Class: EqualUtf16Matcher

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

Instance Method Summary collapse

Constructor Details

#initialize(expected) ⇒ EqualUtf16Matcher

Returns a new instance of EqualUtf16Matcher.



4
5
6
# File 'lib/extensions/mspec/mspec/matchers/equal_utf16.rb', line 4

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

Instance Method Details

#expected_swappedObject



13
14
15
# File 'lib/extensions/mspec/mspec/matchers/equal_utf16.rb', line 13

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

#failure_messageObject



17
18
19
20
# File 'lib/extensions/mspec/mspec/matchers/equal_utf16.rb', line 17

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

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
# File 'lib/extensions/mspec/mspec/matchers/equal_utf16.rb', line 8

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

#negative_failure_messageObject



22
23
24
25
# File 'lib/extensions/mspec/mspec/matchers/equal_utf16.rb', line 22

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