mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Simplify negated usage and expose value
This commit is contained in:
parent
ee7a91c3dd
commit
37f2ce99a3
2 changed files with 17 additions and 7 deletions
|
@ -2,9 +2,6 @@ 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)
|
||||
# Negatable value.
|
||||
getter value
|
||||
|
||||
# Creates the wrapper.
|
||||
def initialize(@value1 : T1, @value2 : T2)
|
||||
@negated = false
|
||||
|
@ -15,14 +12,19 @@ module Spectator::Matchers
|
|||
@negated = !@negated
|
||||
end
|
||||
|
||||
# Returns the correct value based on the negated status.
|
||||
def value
|
||||
@negated ? @value1 : @value2
|
||||
end
|
||||
|
||||
# Produces a stringified value.
|
||||
def to_s(io)
|
||||
io << @negated ? @value1 : @value2
|
||||
io << value
|
||||
end
|
||||
|
||||
# Produces a stringified value with additional information.
|
||||
def inspect(io)
|
||||
(@negated ? @value1 : @value2).inspect(io)
|
||||
value.inspect(io)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,6 +2,9 @@ module Spectator::Matchers
|
|||
# Wraps a prefixed value that can be negated.
|
||||
# This is used when a matcher is negated.
|
||||
private class NegatablePrefixedValue(T)
|
||||
# Negatable value.
|
||||
getter value
|
||||
|
||||
# Creates the wrapper.
|
||||
def initialize(@positive_prefix : String, @negative_prefix : String, @value : T)
|
||||
@negated = false
|
||||
|
@ -12,15 +15,20 @@ module Spectator::Matchers
|
|||
@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 << @negated ? @negative_prefix : @positive_prefix
|
||||
io << prefix
|
||||
io << @value
|
||||
end
|
||||
|
||||
# Produces a stringified value with additional information.
|
||||
def inspect(io)
|
||||
io << @negated ? @negative_prefix : @positive_prefix
|
||||
io << prefix
|
||||
@value.inspect(io)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue