From 8d3ab0d44c6b42fae32ecbeb4dd228f90b8d5f85 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 22 Mar 2019 10:38:09 -0600 Subject: [PATCH] Transform named tuple match data to array Trying to keep some of the existing code (and better syntax). --- src/spectator/matchers/match_data.cr | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/spectator/matchers/match_data.cr b/src/spectator/matchers/match_data.cr index 56f1888..8e80276 100644 --- a/src/spectator/matchers/match_data.cr +++ b/src/spectator/matchers/match_data.cr @@ -1,3 +1,7 @@ +require "./match_data_labeled_value" +require "./match_data_value" +require "./generic_match-data_value" + module Spectator::Matchers # Information regarding a expectation parial and matcher. # `Matcher#match` will return a sub-type of this. @@ -14,7 +18,22 @@ module Spectator::Matchers # Information about the match. # Returned elments will differ by matcher, # but all will return a set of labeled values. - abstract def values : Array(MatchDataLabeledValue) + def values : Array(MatchDataLabeledValue) + named_tuple.map do |key, value| + if value.is_a?(MatchDataValue) + MatchDataLabeledValue.new(key, value) + else + wrapper = GenericMatchDataValue.new(value) + MatchDataLabeledValue.new(key, wrapper) + end + end + end + + # Raw information about the match. + # Sub-types must implement this and return a `NamedTuple` + # containing the match data values. + # This will be transformed and returned by `#values`. + private abstract def named_tuple # Describes the condition that satisfies the matcher. # This is informational and displayed to the end-user.