Add type annotations to to_s and inspect

This commit is contained in:
Michael Miller 2022-11-04 20:56:02 -06:00
parent 12eb2e9357
commit 6e7d215f69
No known key found for this signature in database
GPG key ID: 32B47AE8F388A1FF
24 changed files with 30 additions and 30 deletions

View file

@ -34,7 +34,7 @@ module Spectator
# Produces a string representation of the expression. # Produces a string representation of the expression.
# This consists of the label (if one is available) and the value. # This consists of the label (if one is available) and the value.
def to_s(io) def to_s(io : IO) : Nil
if (label = @label) if (label = @label)
io << label << ": " io << label << ": "
end end
@ -43,7 +43,7 @@ module Spectator
# Produces a detailed string representation of the expression. # Produces a detailed string representation of the expression.
# This consists of the label (if one is available) and the value. # This consists of the label (if one is available) and the value.
def inspect(io) def inspect(io : IO) : Nil
if (label = @label) if (label = @label)
io << label << ": " io << label << ": "
end end

View file

@ -13,12 +13,12 @@ module Spectator
end end
# Displays "anything". # Displays "anything".
def to_s(io) def to_s(io : IO) : Nil
io << "anything" io << "anything"
end end
# Displays "<anything>". # Displays "<anything>".
def inspect(io) def inspect(io : IO) : Nil
io << "<anything>" io << "<anything>"
end end
end end

View file

@ -10,12 +10,12 @@ abstract class SpectatorContext
# and that the Crystal compiler instantiates a `#to_s` and/or `#inspect` for each of those types, # and that the Crystal compiler instantiates a `#to_s` and/or `#inspect` for each of those types,
# an explosion in method instances can be created. # an explosion in method instances can be created.
# The compile time is drastically reduced by using a dummy string instead. # The compile time is drastically reduced by using a dummy string instead.
def to_s(io) def to_s(io : IO) : Nil
io << "Context" io << "Context"
end end
# :ditto: # :ditto:
def inspect(io) def inspect(io : IO) : Nil
io << "Context<" << self.class << '>' io << "Context<" << self.class << '>'
end end
end end

View file

@ -16,7 +16,7 @@ module Spectator
end end
# One-word description of the result. # One-word description of the result.
def to_s(io) def to_s(io : IO) : Nil
io << "error" io << "error"
end end

View file

@ -191,7 +191,7 @@ module Spectator
# Constructs the full name or description of the example. # Constructs the full name or description of the example.
# This prepends names of groups this example is part of. # This prepends names of groups this example is part of.
def to_s(io) def to_s(io : IO) : Nil
name = @name name = @name
# Prefix with group's full name if the node belongs to a group. # Prefix with group's full name if the node belongs to a group.
@ -210,7 +210,7 @@ module Spectator
end end
# Exposes information about the example useful for debugging. # Exposes information about the example useful for debugging.
def inspect(io) def inspect(io : IO) : Nil
super super
io << ' ' << result io << ' ' << result
end end
@ -286,7 +286,7 @@ module Spectator
# Constructs the full name or description of the example. # Constructs the full name or description of the example.
# This prepends names of groups this example is part of. # This prepends names of groups this example is part of.
def to_s(io) : Nil def to_s(io : IO) : Nil
@example.to_s(io) @example.to_s(io)
end end
end end

View file

@ -112,7 +112,7 @@ module Spectator
# Constructs the full name or description of the example group. # Constructs the full name or description of the example group.
# This prepends names of groups this group is part of. # This prepends names of groups this group is part of.
def to_s(io) def to_s(io : IO) : Nil
# Prefix with group's full name if the node belongs to a group. # Prefix with group's full name if the node belongs to a group.
return unless parent = @group return unless parent = @group

View file

@ -42,7 +42,7 @@ module Spectator
# Produces the string representation of the hook. # Produces the string representation of the hook.
# Includes the location and label if they're not nil. # Includes the location and label if they're not nil.
def to_s(io) def to_s(io : IO) : Nil
io << "example group hook" io << "example group hook"
if (label = @label) if (label = @label)

View file

@ -37,7 +37,7 @@ module Spectator
# Produces the string representation of the hook. # Produces the string representation of the hook.
# Includes the location and label if they're not nil. # Includes the location and label if they're not nil.
def to_s(io) def to_s(io : IO) : Nil
io << "example hook" io << "example hook"
if (label = @label) if (label = @label)

View file

@ -39,7 +39,7 @@ module Spectator
# Produces the string representation of the hook. # Produces the string representation of the hook.
# Includes the location and label if they're not nil. # Includes the location and label if they're not nil.
def to_s(io) def to_s(io : IO) : Nil
io << "example hook" io << "example hook"
if (label = @label) if (label = @label)

View file

@ -55,7 +55,7 @@ module Spectator
end end
# One-word description of the result. # One-word description of the result.
def to_s(io) def to_s(io : IO) : Nil
io << "fail" io << "fail"
end end

View file

@ -16,7 +16,7 @@ module Spectator::Formatting::Components
end end
# Writes the comment to the output. # Writes the comment to the output.
def to_s(io) def to_s(io : IO) : Nil
io << "# " << @content io << "# " << @content
end end
end end

View file

@ -9,7 +9,7 @@ module Spectator::Formatting::Components
end end
# Produces output for running the previously specified example. # Produces output for running the previously specified example.
def to_s(io) def to_s(io : IO) : Nil
io << "crystal spec " io << "crystal spec "
# Use location for argument if it's available, since it's simpler. # Use location for argument if it's available, since it's simpler.

View file

@ -10,7 +10,7 @@ module Spectator::Formatting::Components
end end
# Produces the list of commands to run failed examples. # Produces the list of commands to run failed examples.
def to_s(io) def to_s(io : IO) : Nil
io.puts "Failed examples:" io.puts "Failed examples:"
io.puts io.puts
@failures.each do |failure| @failures.each do |failure|

View file

@ -9,7 +9,7 @@ module Spectator::Formatting::Components
end end
# Produces the output containing the profiling information. # Produces the output containing the profiling information.
def to_s(io) def to_s(io : IO) : Nil
io << "Top " io << "Top "
io << @profile.size io << @profile.size
io << " slowest examples (" io << " slowest examples ("

View file

@ -41,7 +41,7 @@ module Spectator::Formatting::Components
private abstract def content(io) private abstract def content(io)
# Writes the component's output to the specified stream. # Writes the component's output to the specified stream.
def to_s(io) def to_s(io : IO) : Nil
title_line(io) title_line(io)
# Ident over to align with the spacing used by the index. # Ident over to align with the spacing used by the index.
indent(index_digit_count + 2) do indent(index_digit_count + 2) do

View file

@ -15,7 +15,7 @@ module Spectator::Formatting::Components
# #:##:## # #:##:##
# # days #:##:## # # days #:##:##
# ``` # ```
def to_s(io) def to_s(io : IO) : Nil
millis = @span.total_milliseconds millis = @span.total_milliseconds
return format_micro(io, millis * 1000) if millis < 1 return format_micro(io, millis * 1000) if millis < 1

View file

@ -11,7 +11,7 @@ module Spectator::Formatting::Components
end end
# Displays the stats. # Displays the stats.
def to_s(io) def to_s(io : IO) : Nil
runtime(io) runtime(io)
totals(io) totals(io)
if seed = @report.random_seed? if seed = @report.random_seed?

View file

@ -10,7 +10,7 @@ module Spectator::Formatting::Components
end end
# Produces the output containing the profiling information. # Produces the output containing the profiling information.
def to_s(io) def to_s(io : IO) : Nil
io << "# Top " io << "# Top "
io << @profile.size io << @profile.size
io << " slowest examples (" io << " slowest examples ("

View file

@ -31,7 +31,7 @@ module Spectator::Formatting::Components
end end
# Writes the counts to the output. # Writes the counts to the output.
def to_s(io) def to_s(io : IO) : Nil
io << @examples << " examples, " << @failures << " failures" io << @examples << " examples, " << @failures << " failures"
if @errors > 0 if @errors > 0

View file

@ -59,7 +59,7 @@ module Spectator
# ```text # ```text
# FILE:LINE # FILE:LINE
# ``` # ```
def to_s(io) def to_s(io : IO) : Nil
io << path << ':' << line io << path << ':' << line
end end
end end

View file

@ -15,7 +15,7 @@ module Spectator::Matchers
extend self extend self
# Text displayed when a method is undefined. # Text displayed when a method is undefined.
def inspect(io) def inspect(io : IO) : Nil
io << "<Method undefined>" io << "<Method undefined>"
end end
end end

View file

@ -66,12 +66,12 @@ module Spectator
# Constructs the full name or description of the node. # Constructs the full name or description of the node.
# This prepends names of groups this node is part of. # This prepends names of groups this node is part of.
def to_s(io) def to_s(io : IO) : Nil
display_name.to_s(io) display_name.to_s(io)
end end
# Exposes information about the node useful for debugging. # Exposes information about the node useful for debugging.
def inspect(io) def inspect(io : IO) : Nil
# Full node name. # Full node name.
io << '"' << self << '"' io << '"' << self << '"'

View file

@ -24,7 +24,7 @@ module Spectator
end end
# One-word description of the result. # One-word description of the result.
def to_s(io) def to_s(io : IO) : Nil
io << "pass" io << "pass"
end end

View file

@ -43,7 +43,7 @@ module Spectator
end end
# One-word description of the result. # One-word description of the result.
def to_s(io) def to_s(io : IO) : Nil
io << "pending" io << "pending"
end end