spec/aws_support/deep_matcher/match_values_failure_messages.rb
#
# Match arrays using Diff::LCS to determine which elements correspond to
# which.
#
Match arrays using Diff::LCS to determine which elements correspond to
which.
Match arrays using Diff :: LCS to determine which elements correspond to which .
def match_arrays_failure_messages(expected_list, actual_list, identifier)
        result = ["#{identifier || 'value'} is different from expected!  Differences:"]
        different = false
        expected_list = expected_list.map { |v| ExpectedValue.new(v) }
        actual_list = actual_list.to_a unless actual_list.class <= Array
        Diff::LCS.sdiff(expected_list, actual_list) do |change|
          case change.action
          when "="
            messages = [change.new_element.inspect]
          when "+"
            messages = [change.new_element.inspect]
            different = true
          when "-"
            messages = [change.old_element.value.inspect]
            different = true
          when "!"
            messages = change.old_element.failure_messages(change.new_element)
            different = true
          else
            raise "Unknown operator returned from sdiff: #{op}"
          end
          op = change.action
          op = " " if op == "="
          result += messages.flat_map { |m| m.split("\n") }.map { |m| "#{op} #{m}" } if messages
        end
        different ? result : []
      end
def match_arrays_failure_messages ( expected_list , actual_list , identifier ) result = [ "#{identifier || 'value'} is different from expected!  Differences:" ] different = false expected_list = expected_list . map { | v | ExpectedValue . new ( v ) } actual_list = actual_list . to_a unless actual_list . class <= Array Diff :: LCS . sdiff ( expected_list , actual_list ) do | change | case change . action when "=" messages = [ change . new_element . inspect ] when "+" messages = [ change . new_element . inspect ] different = true when "-" messages = [ change . old_element . value . inspect ] different = true when "!" messages = change . old_element . failure_messages ( change . new_element ) different = true else raise "Unknown operator returned from sdiff: #{op}" end op = change . action op = " " if op == "=" result += messages . flat_map { | m | m . split ( "\n" ) } . map { | m | "#{op} #{m}" } if messages end different ? result : [ ] end
Match arrays using Diff::LCS to determine which elements correspond to
which.
Match arrays using Diff :: LCS to determine which elements correspond to which .
expected_list
<not_specific>
actual_list
<not_specific>
identifier
<not_specific>