Create struct for colorized comment

This commit is contained in:
Michael Miller 2019-02-19 19:56:07 -07:00
parent 4126ee3451
commit 1cd0f0249e
3 changed files with 23 additions and 4 deletions

View File

@ -0,0 +1,20 @@
module Spectator::Formatters
# Produces a stringified comment for output.
private struct Comment(T)
# Creates the comment.
def initialize(@text : T)
end
# Appends the comment to the output.
def to_s(io)
io << '#'
io << ' '
io << @text
end
# Creates a colorized version of the comment.
def self.color(text : T) forall T
Color.comment(new(text))
end
end
end

View File

@ -77,9 +77,7 @@ module Spectator::Formatters
private def source(io)
INITIAL_INDENT.times { io << ' ' }
(@index_length + 2).times { io << ' ' } # +2 for ) and space.
io << '#'
io << ' '
io << Color.comment(@result.example.source)
io << Comment.color(@result.example.source)
end
# Gets the number of characters a positive integer spans in base 10.

View File

@ -47,7 +47,8 @@ module Spectator::Formatters
failures.each do |result|
@io.print "crystal spec "
result.example.source.to_s(@io)
@io.puts " # TODO"
@io << ' '
@io.puts Comment.color("TODO")
end
end