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.
def includes?(example) : Bool
source = example.source
# end_line is present so there is a range to check against
if end_line = source.end_line
(source.line..end_line).covers?(@line)
else
source.line == @line
end
start_line = example.source.line
end_line = example.source.end_line
(start_line..end_line).covers?(@line)
end
end
end

View file

@ -4,15 +4,17 @@ module Spectator
# Absolute file path.
getter file : String
# Line number in the file.
# If end_line is present, this is the starting line
# Starting line number in the file.
getter line : Int32
# Ending line number in the file.
getter end_line : Int32?
getter end_line : Int32
# 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
# Parses a source from a string.