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:
Michael Miller 2022-11-29 20:28:15 -07:00
parent 2d6c8844d4
commit a585ef0996
No known key found for this signature in database
GPG Key ID: 32B47AE8F388A1FF
3 changed files with 25 additions and 1 deletions

View File

@ -1,6 +1,11 @@
module Spectator
# Untyped arguments to a method call (message).
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.
private def compare_named_tuples(a : NamedTuple, b : NamedTuple)
a.each do |k, v1|

View File

@ -101,6 +101,19 @@ module Spectator
io << _spectator_stubbed_name
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.
#
# NOTE: Defining a stub for a method not defined in the double's type has no effect.

View File

@ -30,7 +30,13 @@ module Spectator
# Constructs a string containing the method name and arguments.
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