Initial work on match data values management

This commit is contained in:
Michael Miller 2019-03-22 10:30:03 -06:00
parent 51c267896f
commit 0b467012cb
4 changed files with 39 additions and 3 deletions

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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