mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Create struct for colorized comment
This commit is contained in:
parent
4126ee3451
commit
1cd0f0249e
3 changed files with 23 additions and 4 deletions
20
src/spectator/formatters/comment.cr
Normal file
20
src/spectator/formatters/comment.cr
Normal 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
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue