From 33841e88888a1a6afedeb2692c6afcffb915fe6b Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 22 Mar 2019 10:55:57 -0600 Subject: [PATCH] Sub-type value modifier from MatchDataValue This includes renaming the types. --- spec/helpers/matchers_helper.cr | 2 +- ...alternative_value.cr => alternative_match_data_value.cr} | 4 +++- src/spectator/matchers/attributes_matcher.cr | 2 +- src/spectator/matchers/case_matcher.cr | 2 +- src/spectator/matchers/contain_matcher.cr | 2 +- src/spectator/matchers/empty_matcher.cr | 2 +- src/spectator/matchers/end_with_matcher.cr | 2 +- src/spectator/matchers/equality_matcher.cr | 2 +- src/spectator/matchers/exception_matcher.cr | 6 +++--- src/spectator/matchers/greater_than_equal_matcher.cr | 4 ++-- src/spectator/matchers/greater_than_matcher.cr | 4 ++-- src/spectator/matchers/have_key_matcher.cr | 2 +- src/spectator/matchers/have_matcher.cr | 2 +- src/spectator/matchers/have_value_matcher.cr | 2 +- src/spectator/matchers/inequality_matcher.cr | 2 +- src/spectator/matchers/less_than_equal_matcher.cr | 4 ++-- src/spectator/matchers/less_than_matcher.cr | 4 ++-- src/spectator/matchers/match_data.cr | 2 +- .../{negatable_value.cr => negatable_match_data_value.cr} | 4 +++- ...ixed_value.cr => negatable_prefixed_match_data_value.cr} | 4 +++- src/spectator/matchers/nil_matcher.cr | 2 +- .../{prefixed_value.cr => prefixed_match_data_value.cr} | 4 +++- src/spectator/matchers/range_matcher.cr | 6 +++--- src/spectator/matchers/regex_matcher.cr | 2 +- src/spectator/matchers/start_with_matcher.cr | 2 +- src/spectator/matchers/truthy_matcher.cr | 2 +- src/spectator/matchers/type_matcher.cr | 2 +- 27 files changed, 43 insertions(+), 35 deletions(-) rename src/spectator/matchers/{alternative_value.cr => alternative_match_data_value.cr} (86%) rename src/spectator/matchers/{negatable_value.cr => negatable_match_data_value.cr} (88%) rename src/spectator/matchers/{negatable_prefixed_value.cr => negatable_prefixed_match_data_value.cr} (88%) rename src/spectator/matchers/{prefixed_value.cr => prefixed_match_data_value.cr} (85%) diff --git a/spec/helpers/matchers_helper.cr b/spec/helpers/matchers_helper.cr index 0f59020..478ef84 100644 --- a/spec/helpers/matchers_helper.cr +++ b/spec/helpers/matchers_helper.cr @@ -4,7 +4,7 @@ def match_data_value(match_data, key) end # Retrieves the string representation and base value -# from a `Spectator::Matchers::PrefixedValue` +# from a `Spectator::Matchers::PrefixedMatchDataValue` # in a `NamedTuple` returned by `Spectator::Matchers::MatchData#values`. def match_data_prefix(match_data, key) prefix = match_data.values.fetch(key) { raise "#{key} is missing" } diff --git a/src/spectator/matchers/alternative_value.cr b/src/spectator/matchers/alternative_match_data_value.cr similarity index 86% rename from src/spectator/matchers/alternative_value.cr rename to src/spectator/matchers/alternative_match_data_value.cr index 7023045..165ce9e 100644 --- a/src/spectator/matchers/alternative_value.cr +++ b/src/spectator/matchers/alternative_match_data_value.cr @@ -1,7 +1,9 @@ +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 AlternativeValue(T1, T2) + private struct AlternativeMatchDataValue(T1, T2) < MatchDataValue # Creates the wrapper. def initialize(@value1 : T1, @value2 : T2) @negated = false diff --git a/src/spectator/matchers/attributes_matcher.cr b/src/spectator/matchers/attributes_matcher.cr index 21e7605..12e7d49 100644 --- a/src/spectator/matchers/attributes_matcher.cr +++ b/src/spectator/matchers/attributes_matcher.cr @@ -49,7 +49,7 @@ module Spectator::Matchers {% begin %} { {% for attribute in ExpectedType.keys %} - {{"expected " + attribute.stringify}}: NegatableValue.new(@values.expected[{{attribute.symbolize}}]), + {{"expected " + attribute.stringify}}: NegatableMatchDataValue.new(@values.expected[{{attribute.symbolize}}]), {{"actual " + attribute.stringify}}: @values.actual[{{attribute.symbolize}}], {% end %} } diff --git a/src/spectator/matchers/case_matcher.cr b/src/spectator/matchers/case_matcher.cr index d90fe75..8dfc881 100644 --- a/src/spectator/matchers/case_matcher.cr +++ b/src/spectator/matchers/case_matcher.cr @@ -26,7 +26,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatableValue.new(@values.expected), + expected: NegatableMatchDataValue.new(@values.expected), actual: @values.actual, } end diff --git a/src/spectator/matchers/contain_matcher.cr b/src/spectator/matchers/contain_matcher.cr index 2e1d849..739d1e9 100644 --- a/src/spectator/matchers/contain_matcher.cr +++ b/src/spectator/matchers/contain_matcher.cr @@ -28,7 +28,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - subset: NegatableValue.new(@values.expected), + subset: NegatableMatchDataValue.new(@values.expected), superset: @values.actual, } end diff --git a/src/spectator/matchers/empty_matcher.cr b/src/spectator/matchers/empty_matcher.cr index 09aada7..b477ec4 100644 --- a/src/spectator/matchers/empty_matcher.cr +++ b/src/spectator/matchers/empty_matcher.cr @@ -27,7 +27,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatableValue.new([] of Nil), + expected: NegatableMatchDataValue.new([] of Nil), actual: @actual, } end diff --git a/src/spectator/matchers/end_with_matcher.cr b/src/spectator/matchers/end_with_matcher.cr index 6e99862..92655d5 100644 --- a/src/spectator/matchers/end_with_matcher.cr +++ b/src/spectator/matchers/end_with_matcher.cr @@ -39,7 +39,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatableValue.new(@values.expected), + expected: NegatableMatchDataValue.new(@values.expected), actual: @values.actual, } end diff --git a/src/spectator/matchers/equality_matcher.cr b/src/spectator/matchers/equality_matcher.cr index be08053..0e97e60 100644 --- a/src/spectator/matchers/equality_matcher.cr +++ b/src/spectator/matchers/equality_matcher.cr @@ -26,7 +26,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatableValue.new(@values.expected), + expected: NegatableMatchDataValue.new(@values.expected), actual: @values.actual, } end diff --git a/src/spectator/matchers/exception_matcher.cr b/src/spectator/matchers/exception_matcher.cr index 9c5d9cb..b35ce66 100644 --- a/src/spectator/matchers/exception_matcher.cr +++ b/src/spectator/matchers/exception_matcher.cr @@ -67,7 +67,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - "expected type": NegatableValue.new(ExceptionType), + "expected type": NegatableMatchDataValue.new(ExceptionType), "actual type": @values.actual.class, } end @@ -95,9 +95,9 @@ module Spectator::Matchers # Information about the match. def named_tuple { - "expected type": NegatableValue.new(ExceptionType), + "expected type": NegatableMatchDataValue.new(ExceptionType), "actual type": @values.actual.class, - "expected message": NegatableValue.new(@values.expected), + "expected message": NegatableMatchDataValue.new(@values.expected), "actual message": @values.actual.message, } end diff --git a/src/spectator/matchers/greater_than_equal_matcher.cr b/src/spectator/matchers/greater_than_equal_matcher.cr index 396e669..e9e716e 100644 --- a/src/spectator/matchers/greater_than_equal_matcher.cr +++ b/src/spectator/matchers/greater_than_equal_matcher.cr @@ -26,8 +26,8 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatablePrefixedValue.new(">=", "<", @values.expected), - actual: PrefixedValue.new(actual_operator, @values.actual), + expected: NegatablePrefixedMatchDataValue.new(">=", "<", @values.expected), + actual: PrefixedMatchDataValue.new(actual_operator, @values.actual), } end diff --git a/src/spectator/matchers/greater_than_matcher.cr b/src/spectator/matchers/greater_than_matcher.cr index 255c8b1..e9e239c 100644 --- a/src/spectator/matchers/greater_than_matcher.cr +++ b/src/spectator/matchers/greater_than_matcher.cr @@ -26,8 +26,8 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatablePrefixedValue.new(">", "<=", @values.expected), - actual: PrefixedValue.new(actual_operator, @values.actual), + expected: NegatablePrefixedMatchDataValue.new(">", "<=", @values.expected), + actual: PrefixedMatchDataValue.new(actual_operator, @values.actual), } end diff --git a/src/spectator/matchers/have_key_matcher.cr b/src/spectator/matchers/have_key_matcher.cr index 0aa461a..c27743a 100644 --- a/src/spectator/matchers/have_key_matcher.cr +++ b/src/spectator/matchers/have_key_matcher.cr @@ -27,7 +27,7 @@ module Spectator::Matchers def named_tuple actual = @values.actual { - key: NegatableValue.new(@values.expected), + key: NegatableMatchDataValue.new(@values.expected), actual: actual.responds_to?(:keys) ? actual.keys : actual, } end diff --git a/src/spectator/matchers/have_matcher.cr b/src/spectator/matchers/have_matcher.cr index 95e7412..7fb2a99 100644 --- a/src/spectator/matchers/have_matcher.cr +++ b/src/spectator/matchers/have_matcher.cr @@ -51,7 +51,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - subset: NegatableValue.new(@values.expected), + subset: NegatableMatchDataValue.new(@values.expected), superset: @values.actual, } end diff --git a/src/spectator/matchers/have_value_matcher.cr b/src/spectator/matchers/have_value_matcher.cr index 192e545..a59d1f4 100644 --- a/src/spectator/matchers/have_value_matcher.cr +++ b/src/spectator/matchers/have_value_matcher.cr @@ -27,7 +27,7 @@ module Spectator::Matchers def named_tuple actual = @values.actual { - value: NegatableValue.new(@values.expected), + value: NegatableMatchDataValue.new(@values.expected), actual: actual.responds_to?(:values) ? actual.values : actual, } end diff --git a/src/spectator/matchers/inequality_matcher.cr b/src/spectator/matchers/inequality_matcher.cr index 0abf617..71010fb 100644 --- a/src/spectator/matchers/inequality_matcher.cr +++ b/src/spectator/matchers/inequality_matcher.cr @@ -26,7 +26,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatablePrefixedValue.new("Not", "", @values.expected), + expected: NegatablePrefixedMatchDataValue.new("Not", "", @values.expected), actual: @values.actual, } end diff --git a/src/spectator/matchers/less_than_equal_matcher.cr b/src/spectator/matchers/less_than_equal_matcher.cr index f1a930c..98d6278 100644 --- a/src/spectator/matchers/less_than_equal_matcher.cr +++ b/src/spectator/matchers/less_than_equal_matcher.cr @@ -26,8 +26,8 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatablePrefixedValue.new("<=", ">", @values.expected), - actual: PrefixedValue.new(actual_operator, @values.actual), + expected: NegatablePrefixedMatchDataValue.new("<=", ">", @values.expected), + actual: PrefixedMatchDataValue.new(actual_operator, @values.actual), } end diff --git a/src/spectator/matchers/less_than_matcher.cr b/src/spectator/matchers/less_than_matcher.cr index e96e37b..c66bda7 100644 --- a/src/spectator/matchers/less_than_matcher.cr +++ b/src/spectator/matchers/less_than_matcher.cr @@ -26,8 +26,8 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatablePrefixedValue.new("<", ">=", @values.expected), - actual: PrefixedValue.new(actual_operator, @values.actual), + expected: NegatablePrefixedMatchDataValue.new("<", ">=", @values.expected), + actual: PrefixedMatchDataValue.new(actual_operator, @values.actual), } end diff --git a/src/spectator/matchers/match_data.cr b/src/spectator/matchers/match_data.cr index 8e80276..4595e33 100644 --- a/src/spectator/matchers/match_data.cr +++ b/src/spectator/matchers/match_data.cr @@ -1,6 +1,6 @@ require "./match_data_labeled_value" require "./match_data_value" -require "./generic_match-data_value" +require "./generic_match_data_value" module Spectator::Matchers # Information regarding a expectation parial and matcher. diff --git a/src/spectator/matchers/negatable_value.cr b/src/spectator/matchers/negatable_match_data_value.cr similarity index 88% rename from src/spectator/matchers/negatable_value.cr rename to src/spectator/matchers/negatable_match_data_value.cr index 77b82e4..ac764fe 100644 --- a/src/spectator/matchers/negatable_value.cr +++ b/src/spectator/matchers/negatable_match_data_value.cr @@ -1,7 +1,9 @@ +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 NegatableValue(T) + private class NegatableMatchDataValue(T) < MatchDataValue # Negatable value. getter value diff --git a/src/spectator/matchers/negatable_prefixed_value.cr b/src/spectator/matchers/negatable_prefixed_match_data_value.cr similarity index 88% rename from src/spectator/matchers/negatable_prefixed_value.cr rename to src/spectator/matchers/negatable_prefixed_match_data_value.cr index cb5435e..93f26c5 100644 --- a/src/spectator/matchers/negatable_prefixed_value.cr +++ b/src/spectator/matchers/negatable_prefixed_match_data_value.cr @@ -1,7 +1,9 @@ +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 NegatablePrefixedValue(T) + private struct NegatablePrefixedMatchDataValue(T) < MatchDataValue # Negatable value. getter value diff --git a/src/spectator/matchers/nil_matcher.cr b/src/spectator/matchers/nil_matcher.cr index 336b0cc..fd5021b 100644 --- a/src/spectator/matchers/nil_matcher.cr +++ b/src/spectator/matchers/nil_matcher.cr @@ -27,7 +27,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatableValue.new(nil), + expected: NegatableMatchDataValue.new(nil), actual: @actual, } end diff --git a/src/spectator/matchers/prefixed_value.cr b/src/spectator/matchers/prefixed_match_data_value.cr similarity index 85% rename from src/spectator/matchers/prefixed_value.cr rename to src/spectator/matchers/prefixed_match_data_value.cr index a9b981e..e1487c3 100644 --- a/src/spectator/matchers/prefixed_value.cr +++ b/src/spectator/matchers/prefixed_match_data_value.cr @@ -1,6 +1,8 @@ +require "./match_data_value" + module Spectator::Matchers # Prefixes (for output formatting) an actual or expected value. - private struct PrefixedValue(T) + private struct PrefixedMatchDataValue(T) < MatchDataValue # Value being prefixed. getter value : T diff --git a/src/spectator/matchers/range_matcher.cr b/src/spectator/matchers/range_matcher.cr index 6829466..8b66497 100644 --- a/src/spectator/matchers/range_matcher.cr +++ b/src/spectator/matchers/range_matcher.cr @@ -67,8 +67,8 @@ module Spectator::Matchers # Information about the match. def named_tuple { - lower: NegatablePrefixedValue.new(">=", "<", range.begin), - upper: NegatablePrefixedValue.new(exclusive? ? "<" : "<=", exclusive? ? ">=" : ">", range.end), + lower: NegatablePrefixedMatchDataValue.new(">=", "<", range.begin), + upper: NegatablePrefixedMatchDataValue.new(exclusive? ? "<" : "<=", exclusive? ? ">=" : ">", range.end), actual: @values.actual, } end @@ -112,7 +112,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - set: NegatableValue.new(@values.expected), + set: NegatableMatchDataValue.new(@values.expected), actual: @values.actual, } end diff --git a/src/spectator/matchers/regex_matcher.cr b/src/spectator/matchers/regex_matcher.cr index f1550d0..bd679a3 100644 --- a/src/spectator/matchers/regex_matcher.cr +++ b/src/spectator/matchers/regex_matcher.cr @@ -26,7 +26,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatableValue.new(@values.expected), + expected: NegatableMatchDataValue.new(@values.expected), actual: @values.actual, } end diff --git a/src/spectator/matchers/start_with_matcher.cr b/src/spectator/matchers/start_with_matcher.cr index b697006..6ece475 100644 --- a/src/spectator/matchers/start_with_matcher.cr +++ b/src/spectator/matchers/start_with_matcher.cr @@ -39,7 +39,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatableValue.new(@values.expected), + expected: NegatableMatchDataValue.new(@values.expected), actual: @values.actual, } end diff --git a/src/spectator/matchers/truthy_matcher.cr b/src/spectator/matchers/truthy_matcher.cr index 0a35fb8..7eac541 100644 --- a/src/spectator/matchers/truthy_matcher.cr +++ b/src/spectator/matchers/truthy_matcher.cr @@ -99,7 +99,7 @@ module Spectator::Matchers truthy = "Not false or nil" falsey = "false or nil" { - expected: AlternativeValue.new(@truthy ? truthy : falsey, @truthy ? falsey : truthy), + expected: AlternativeMatchDataValue.new(@truthy ? truthy : falsey, @truthy ? falsey : truthy), actual: @actual, truthy: !!@actual, } diff --git a/src/spectator/matchers/type_matcher.cr b/src/spectator/matchers/type_matcher.cr index 4892bbd..3283992 100644 --- a/src/spectator/matchers/type_matcher.cr +++ b/src/spectator/matchers/type_matcher.cr @@ -32,7 +32,7 @@ module Spectator::Matchers # Information about the match. def named_tuple { - expected: NegatableValue.new(ExpectedType), + expected: NegatableMatchDataValue.new(ExpectedType), actual: ActualType, } end