From 5bd911341b1e8a7c8cbb92ab93812ac1a2a66864 Mon Sep 17 00:00:00 2001 From: matthewmcgarvey Date: Tue, 30 Mar 2021 15:29:51 -0400 Subject: [PATCH] Set end_line equal to line if end_line not provided --- src/spectator/line_example_filter.cr | 10 +++------- src/spectator/source.cr | 10 ++++++---- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/spectator/line_example_filter.cr b/src/spectator/line_example_filter.cr index 4063f34..0c65fba 100644 --- a/src/spectator/line_example_filter.cr +++ b/src/spectator/line_example_filter.cr @@ -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 diff --git a/src/spectator/source.cr b/src/spectator/source.cr index 699fb39..6afa3a7 100644 --- a/src/spectator/source.cr +++ b/src/spectator/source.cr @@ -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.