diff --git a/src/spectator/matchers/generic_match_data_value.cr b/src/spectator/matchers/generic_match_data_value.cr new file mode 100644 index 0000000..795951a --- /dev/null +++ b/src/spectator/matchers/generic_match_data_value.cr @@ -0,0 +1,15 @@ +require "./match_data_value" + +module Spectator::Matchers + # Wraps a value for used in match data. + private struct GenericMatchDataValue(T) < MatchDataValue + # Creates the wrapper. + def initialize(@value : T) + end + + # Stringifies the value. + def to_s(io) + @value.inspect(io) + end + end +end diff --git a/src/spectator/matchers/match_data.cr b/src/spectator/matchers/match_data.cr index 05a169f..56f1888 100644 --- a/src/spectator/matchers/match_data.cr +++ b/src/spectator/matchers/match_data.cr @@ -12,9 +12,9 @@ module Spectator::Matchers end # Information about the match. - # Returned value and type will differ by sub-type, - # but all will return a set of key-value pairs. - abstract def values + # Returned elments will differ by matcher, + # but all will return a set of labeled values. + abstract def values : Array(MatchDataLabeledValue) # Describes the condition that satisfies the matcher. # This is informational and displayed to the end-user. diff --git a/src/spectator/matchers/match_data_labeled_value.cr b/src/spectator/matchers/match_data_labeled_value.cr new file mode 100644 index 0000000..2b201ef --- /dev/null +++ b/src/spectator/matchers/match_data_labeled_value.cr @@ -0,0 +1,15 @@ +module Spectator::Matchers + # A value from match data with a label. + private struct MatchDataLabeledValue + # Label tied to the value. + # This annotates what the value is. + getter label : String + + # The actual value from the match data. + getter value : MatchDataValue + + # Creates a new labeled value. + def initialize(@label, @value) + end + end +end diff --git a/src/spectator/matchers/match_data_value.cr b/src/spectator/matchers/match_data_value.cr new file mode 100644 index 0000000..ef24d07 --- /dev/null +++ b/src/spectator/matchers/match_data_value.cr @@ -0,0 +1,6 @@ +module Spectator::Matchers + # Abstract base for all match data values. + # All sub-classes are expected to implement their own `#to_s`. + private abstract struct MatchDataValue + end +end