Set end_line equal to line if end_line not provided

This commit is contained in:
matthewmcgarvey 2021-03-30 15:29:51 -04:00
parent 8fafd2467d
commit 5bd911341b
2 changed files with 9 additions and 11 deletions

View file

@ -7,13 +7,9 @@ module Spectator
# Checks whether the example satisfies the filter. # Checks whether the example satisfies the filter.
def includes?(example) : Bool def includes?(example) : Bool
source = example.source start_line = example.source.line
# end_line is present so there is a range to check against end_line = example.source.end_line
if end_line = source.end_line (start_line..end_line).covers?(@line)
(source.line..end_line).covers?(@line)
else
source.line == @line
end
end end
end end
end end

View file

@ -4,15 +4,17 @@ module Spectator
# Absolute file path. # Absolute file path.
getter file : String getter file : String
# Line number in the file. # Starting line number in the file.
# If end_line is present, this is the starting line
getter line : Int32 getter line : Int32
# Ending line number in the file. # Ending line number in the file.
getter end_line : Int32? getter end_line : Int32
# Creates the source. # Creates the source.
def initialize(@file, @line, @end_line = nil) def initialize(@file, @line, end_line = nil)
# if an end line is not provided,
# make the end line the same as the start line
@end_line = end_line || @line
end end
# Parses a source from a string. # Parses a source from a string.