mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Simplify string (inspect) representation
These types make heavy use of generics and combined types. Instantiating string representation methods for all possibilities is unecesssary and slows down compilation.
This commit is contained in:
parent
2d6c8844d4
commit
a585ef0996
3 changed files with 25 additions and 1 deletions
|
@ -1,6 +1,11 @@
|
||||||
module Spectator
|
module Spectator
|
||||||
# Untyped arguments to a method call (message).
|
# Untyped arguments to a method call (message).
|
||||||
abstract class AbstractArguments
|
abstract class AbstractArguments
|
||||||
|
# Use the string representation to avoid over complicating debug output.
|
||||||
|
def inspect(io : IO) : Nil
|
||||||
|
to_s(io)
|
||||||
|
end
|
||||||
|
|
||||||
# Utility method for comparing two named tuples ignoring order.
|
# Utility method for comparing two named tuples ignoring order.
|
||||||
private def compare_named_tuples(a : NamedTuple, b : NamedTuple)
|
private def compare_named_tuples(a : NamedTuple, b : NamedTuple)
|
||||||
a.each do |k, v1|
|
a.each do |k, v1|
|
||||||
|
|
|
@ -101,6 +101,19 @@ module Spectator
|
||||||
io << _spectator_stubbed_name
|
io << _spectator_stubbed_name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# :ditto:
|
||||||
|
def inspect(io : IO) : Nil
|
||||||
|
{% if anno = @type.annotation(::Spectator::StubbedName) %}
|
||||||
|
io << "#<Double " << {{(anno[0] || :Anonymous.id).stringify}}
|
||||||
|
{% else %}
|
||||||
|
io << "#<Double Anonymous"
|
||||||
|
{% end %}
|
||||||
|
|
||||||
|
io << ":0x"
|
||||||
|
object_id.to_s(io, 16)
|
||||||
|
io << '>'
|
||||||
|
end
|
||||||
|
|
||||||
# Defines a stub to change the behavior of a method in this double.
|
# Defines a stub to change the behavior of a method in this double.
|
||||||
#
|
#
|
||||||
# NOTE: Defining a stub for a method not defined in the double's type has no effect.
|
# NOTE: Defining a stub for a method not defined in the double's type has no effect.
|
||||||
|
|
|
@ -30,7 +30,13 @@ module Spectator
|
||||||
|
|
||||||
# Constructs a string containing the method name and arguments.
|
# Constructs a string containing the method name and arguments.
|
||||||
def to_s(io : IO) : Nil
|
def to_s(io : IO) : Nil
|
||||||
io << '#' << method << arguments
|
io << '#' << method
|
||||||
|
arguments.inspect(io)
|
||||||
|
end
|
||||||
|
|
||||||
|
# :ditto:
|
||||||
|
def inspect(io : IO) : Nil
|
||||||
|
to_s(io)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue