From 0b467012cbad761bec3bf4fe371e9e3753dea955 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 22 Mar 2019 10:30:03 -0600 Subject: [PATCH] Initial work on match data values management --- .../matchers/generic_match_data_value.cr | 15 +++++++++++++++ src/spectator/matchers/match_data.cr | 6 +++--- .../matchers/match_data_labeled_value.cr | 15 +++++++++++++++ src/spectator/matchers/match_data_value.cr | 6 ++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 src/spectator/matchers/generic_match_data_value.cr create mode 100644 src/spectator/matchers/match_data_labeled_value.cr create mode 100644 src/spectator/matchers/match_data_value.cr 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