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

View file

@ -13,12 +13,12 @@ module Spectator
end
# Displays "anything".
def to_s(io)
def to_s(io : IO) : Nil
io << "anything"
end
# Displays "<anything>".
def inspect(io)
def inspect(io : IO) : Nil
io << "<anything>"
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,
# an explosion in method instances can be created.
# The compile time is drastically reduced by using a dummy string instead.
def to_s(io)
def to_s(io : IO) : Nil
io << "Context"
end
# :ditto:
def inspect(io)
def inspect(io : IO) : Nil
io << "Context<" << self.class << '>'
end
end

View file

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

View file

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

View file

@ -112,7 +112,7 @@ module Spectator
# Constructs the full name or description of the example group.
# 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.
return unless parent = @group

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -10,7 +10,7 @@ module Spectator::Formatting::Components
end
# 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
@failures.each do |failure|

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -66,12 +66,12 @@ module Spectator
# Constructs the full name or description of the node.
# 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)
end
# Exposes information about the node useful for debugging.
def inspect(io)
def inspect(io : IO) : Nil
# Full node name.
io << '"' << self << '"'

View file

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

View file

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