From ae43c930bf9dd2f6c38ba782fa091d1154111bea Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Thu, 1 Aug 2019 13:49:08 -0600 Subject: [PATCH] Replace MatchDataValue types with a single LabeledValue --- .../matchers/alternative_match_data_value.cr | 32 --------------- .../matchers/generic_match_data_value.cr | 23 ----------- src/spectator/matchers/labeled_value.cr | 10 +++++ src/spectator/matchers/match_data_value.cr | 10 ----- .../matchers/negatable_match_data_value.cr | 34 ---------------- .../negatable_prefixed_match_data_value.cr | 39 ------------------- .../matchers/prefixed_match_data_value.cr | 27 ------------- 7 files changed, 10 insertions(+), 165 deletions(-) delete mode 100644 src/spectator/matchers/alternative_match_data_value.cr delete mode 100644 src/spectator/matchers/generic_match_data_value.cr create mode 100644 src/spectator/matchers/labeled_value.cr delete mode 100644 src/spectator/matchers/match_data_value.cr delete mode 100644 src/spectator/matchers/negatable_match_data_value.cr delete mode 100644 src/spectator/matchers/negatable_prefixed_match_data_value.cr delete mode 100644 src/spectator/matchers/prefixed_match_data_value.cr diff --git a/src/spectator/matchers/alternative_match_data_value.cr b/src/spectator/matchers/alternative_match_data_value.cr deleted file mode 100644 index b600312..0000000 --- a/src/spectator/matchers/alternative_match_data_value.cr +++ /dev/null @@ -1,32 +0,0 @@ -require "./match_data_value" - -module Spectator::Matchers - # Selects a value based on whether the value is negated. - # This is used when a matcher is negated. - private class AlternativeMatchDataValue(T1, T2) < MatchDataValue - # Creates the wrapper. - def initialize(@value1 : T1, @value2 : T2) - @negated = false - end - - # Negates (toggles) the value. - def negate - @negated = !@negated - end - - # Returns the correct value based on the negated status. - def value - @negated ? @value2 : @value1 - end - - # Produces a stringified value. - def to_s(io) - io << value - end - - # Produces a stringified value with additional information. - def inspect(io) - io << value - end - end -end diff --git a/src/spectator/matchers/generic_match_data_value.cr b/src/spectator/matchers/generic_match_data_value.cr deleted file mode 100644 index 9069489..0000000 --- a/src/spectator/matchers/generic_match_data_value.cr +++ /dev/null @@ -1,23 +0,0 @@ -require "./match_data_value" - -module Spectator::Matchers - # Wraps a value for used in match data. - private class GenericMatchDataValue(T) < MatchDataValue - # Underlying value. - getter value - - # Creates the wrapper. - def initialize(@value : T) - end - - # Stringifies the value. - def to_s(io) - @value.inspect(io) - end - - # Inspects the value. - def inspect(io) - @value.inspect(io) - end - end -end diff --git a/src/spectator/matchers/labeled_value.cr b/src/spectator/matchers/labeled_value.cr new file mode 100644 index 0000000..3a8c6be --- /dev/null +++ b/src/spectator/matchers/labeled_value.cr @@ -0,0 +1,10 @@ +module Spectator::Matchers + struct LabeledValue + getter label : Symbol + + getter value : String + + 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 deleted file mode 100644 index 21629fd..0000000 --- a/src/spectator/matchers/match_data_value.cr +++ /dev/null @@ -1,10 +0,0 @@ -module Spectator::Matchers - # Abstract base for all match data values. - # All sub-classes are expected to implement their own `#to_s`. - private abstract class MatchDataValue - # Placeholder for negating the value. - def negate - # ... - end - end -end diff --git a/src/spectator/matchers/negatable_match_data_value.cr b/src/spectator/matchers/negatable_match_data_value.cr deleted file mode 100644 index 62abf49..0000000 --- a/src/spectator/matchers/negatable_match_data_value.cr +++ /dev/null @@ -1,34 +0,0 @@ -require "./match_data_value" - -module Spectator::Matchers - # Wraps an expected value that can be negated. - # This is used when a matcher is negated. - private class NegatableMatchDataValue(T) < MatchDataValue - # Negatable value. - getter value - - # Creates the wrapper. - def initialize(@value : T) - @negated = false - end - - # Negates (toggles) the value. - def negate - @negated = !@negated - end - - # Produces a stringified value. - # The string will be prefixed with "Not" when negated. - def to_s(io) - io << "Not " if @negated - @value.inspect(io) - end - - # Produces a stringified value with additional information. - # The string will be prefixed with "Not" when negated. - def inspect(io) - io << "Not " if @negated - @value.inspect(io) - end - end -end diff --git a/src/spectator/matchers/negatable_prefixed_match_data_value.cr b/src/spectator/matchers/negatable_prefixed_match_data_value.cr deleted file mode 100644 index 9cc6138..0000000 --- a/src/spectator/matchers/negatable_prefixed_match_data_value.cr +++ /dev/null @@ -1,39 +0,0 @@ -require "./match_data_value" - -module Spectator::Matchers - # Wraps a prefixed value that can be negated. - # This is used when a matcher is negated. - private class NegatablePrefixedMatchDataValue(T) < MatchDataValue - # Negatable value. - getter value - - # Creates the wrapper. - def initialize(@positive_prefix : String, @negative_prefix : String, @value : T) - @negated = false - end - - # Negates (toggles) the value. - def negate - @negated = !@negated - end - - # Returns the correct prefix based on the negated status. - private def prefix - @negated ? @negative_prefix : @positive_prefix - end - - # Produces a stringified value. - def to_s(io) - io << prefix - io << ' ' - @value.inspect(io) - end - - # Produces a stringified value with additional information. - def inspect(io) - io << prefix - io << ' ' - @value.inspect(io) - end - end -end diff --git a/src/spectator/matchers/prefixed_match_data_value.cr b/src/spectator/matchers/prefixed_match_data_value.cr deleted file mode 100644 index feea8cc..0000000 --- a/src/spectator/matchers/prefixed_match_data_value.cr +++ /dev/null @@ -1,27 +0,0 @@ -require "./match_data_value" - -module Spectator::Matchers - # Prefixes (for output formatting) an actual or expected value. - private class PrefixedMatchDataValue(T) < MatchDataValue - # Value being prefixed. - getter value : T - - # Creates the prefixed value. - def initialize(@prefix : String, @value : T) - end - - # Outputs the formatted value with a prefix. - def to_s(io) - io << @prefix - io << ' ' - @value.inspect(io) - end - - # Outputs details of the formatted value with a prefix. - def inspect(io) - io << @prefix - io << ' ' - @prefix.inspect(io) - end - end -end