From a19d9f00aa150ca8b0057ff6e782cac5d5c80ff7 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Fri, 22 Mar 2019 11:00:00 -0600 Subject: [PATCH] Update formatters to handle new labeled values --- src/spectator/formatting/match_data_value_pair.cr | 2 +- src/spectator/formatting/match_data_values.cr | 11 ++++++----- src/spectator/matchers/match_data_labeled_value.cr | 2 +- src/spectator/matchers/negatable_match_data_value.cr | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/spectator/formatting/match_data_value_pair.cr b/src/spectator/formatting/match_data_value_pair.cr index 46823c3..95fa57f 100644 --- a/src/spectator/formatting/match_data_value_pair.cr +++ b/src/spectator/formatting/match_data_value_pair.cr @@ -1,5 +1,5 @@ module Spectator::Formatting - # A single key-value pair from the `Spectator::Matchers::MatchData#value` method. + # A single labeled value from the `Spectator::Matchers::MatchData#value` method. private struct MatchDataValuePair(T) # Creates the pair formatter. def initialize(@key : Symbol, @value : T, @padding : Int32) diff --git a/src/spectator/formatting/match_data_values.cr b/src/spectator/formatting/match_data_values.cr index a9edac1..51b5f1e 100644 --- a/src/spectator/formatting/match_data_values.cr +++ b/src/spectator/formatting/match_data_values.cr @@ -1,22 +1,23 @@ module Spectator::Formatting # Produces a `MatchDataValuePair` for each key-value pair # from `Spectator::Matchers::MatchData#values`. - private struct MatchDataValues(T) + private struct MatchDataValues include Enumerable(MatchDataValuePair) @max_key_length : Int32 # Creates the values mapper. - def initialize(@values : T) - @max_key_length = @values.keys.map(&.to_s.size).max + def initialize(@values : Array(Spectator::Matchers::MatchDataLabeledValue)) + @max_key_length = @values.map(&.label.to_s.size).max end # Yields pairs that can be printed to output. def each - @values.each do |key, value| + @values.each do |labeled_value| + key = labeled_value.label key_length = key.to_s.size padding = @max_key_length - key_length - yield MatchDataValuePair.new(key, value, padding) + yield MatchDataValuePair.new(key, labeled_value.value, padding) end end end diff --git a/src/spectator/matchers/match_data_labeled_value.cr b/src/spectator/matchers/match_data_labeled_value.cr index 0fc3d59..2a39095 100644 --- a/src/spectator/matchers/match_data_labeled_value.cr +++ b/src/spectator/matchers/match_data_labeled_value.cr @@ -1,6 +1,6 @@ module Spectator::Matchers # A value from match data with a label. - private struct MatchDataLabeledValue + struct MatchDataLabeledValue # Label tied to the value. # This annotates what the value is. getter label : Symbol diff --git a/src/spectator/matchers/negatable_match_data_value.cr b/src/spectator/matchers/negatable_match_data_value.cr index ac764fe..aef6e66 100644 --- a/src/spectator/matchers/negatable_match_data_value.cr +++ b/src/spectator/matchers/negatable_match_data_value.cr @@ -3,7 +3,7 @@ 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 + private struct NegatableMatchDataValue(T) < MatchDataValue # Negatable value. getter value