mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add support for sub-index in result blocks
This commit is contained in:
parent
dcdb87e31a
commit
88f0c23a3e
5 changed files with 21 additions and 12 deletions
|
@ -7,8 +7,8 @@ module Spectator::Formatting::Components
|
|||
# Displays information about an error result.
|
||||
struct ErrorResultBlock < ResultBlock
|
||||
# Creates the component.
|
||||
def initialize(index : Int32, example : Example, @result : ErrorResult)
|
||||
super(index, example)
|
||||
def initialize(example : Example, index : Int32, @result : ErrorResult)
|
||||
super(example, index)
|
||||
end
|
||||
|
||||
# Content displayed on the second line of the block after the label.
|
||||
|
|
|
@ -11,8 +11,8 @@ module Spectator::Formatting::Components
|
|||
@longest_key : Int32
|
||||
|
||||
# Creates the component.
|
||||
def initialize(index : Int32, example : Example, result : FailResult)
|
||||
super(index, example)
|
||||
def initialize(example : Example, index : Int32, result : FailResult, subindex = 0)
|
||||
super(example, index, subindex)
|
||||
@expectation = result.expectations.find(&.failed?).not_nil!
|
||||
@longest_key = @expectation.values.max_of { |(key, _value)| key.to_s.size }
|
||||
end
|
||||
|
|
|
@ -7,8 +7,8 @@ module Spectator::Formatting::Components
|
|||
# Displays information about a pending result.
|
||||
struct PendingResultBlock < ResultBlock
|
||||
# Creates the component.
|
||||
def initialize(index : Int32, example : Example, @result : PendingResult)
|
||||
super(index, example)
|
||||
def initialize(example : Example, index : Int32, @result : PendingResult)
|
||||
super(example, index)
|
||||
end
|
||||
|
||||
# Content displayed on the second line of the block after the label.
|
||||
|
|
|
@ -14,7 +14,7 @@ module Spectator::Formatting::Components
|
|||
# ```
|
||||
abstract struct ResultBlock < Block
|
||||
# Creates the block with the specified *index* and for the given *example*.
|
||||
def initialize(@index : Int32, @example : Example)
|
||||
def initialize(@example : Example, @index : Int32, @subindex : Int32 = 0)
|
||||
super()
|
||||
end
|
||||
|
||||
|
@ -55,7 +55,9 @@ module Spectator::Formatting::Components
|
|||
# Produces the title line.
|
||||
private def title_line(io)
|
||||
line(io) do
|
||||
io << @index << ") " << title
|
||||
io << @index
|
||||
io << '.' << @subindex if @subindex > 0
|
||||
io << ") " << title
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -80,7 +82,14 @@ module Spectator::Formatting::Components
|
|||
|
||||
# Computes the number of spaces the index takes
|
||||
private def index_digit_count
|
||||
(Math.log(@index.to_f + 1) / Math::LOG10).ceil.to_i
|
||||
count = digit_count(@index)
|
||||
count += 1 + digit_count(@subindex) if @subindex > 0
|
||||
count
|
||||
end
|
||||
|
||||
# Computes the number of spaces an integer takes.
|
||||
private def digit_count(integer)
|
||||
(Math.log(integer.to_f + 1) / Math::LOG10).ceil.to_i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -25,7 +25,7 @@ module Spectator::Formatting
|
|||
io.puts
|
||||
examples.each_with_index(1) do |example, index|
|
||||
result = example.result.as(PendingResult)
|
||||
io.puts Components::PendingResultBlock.new(index, example, result)
|
||||
io.puts Components::PendingResultBlock.new(example, index, result)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -39,9 +39,9 @@ module Spectator::Formatting
|
|||
io.puts
|
||||
examples.each_with_index(1) do |example, index|
|
||||
if result = example.result.as?(ErrorResult)
|
||||
io.puts Components::ErrorResultBlock.new(index, example, result)
|
||||
io.puts Components::ErrorResultBlock.new(example, index, result)
|
||||
elsif result = example.result.as?(FailResult)
|
||||
io.puts Components::FailResultBlock.new(index, example, result)
|
||||
io.puts Components::FailResultBlock.new(example, index, result)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue