diff --git a/lib/undercover/result.rb b/lib/undercover/result.rb index fa236ca..da06ff8 100644 --- a/lib/undercover/result.rb +++ b/lib/undercover/result.rb @@ -13,7 +13,14 @@ class Result def initialize(node, file_cov, file_path) @node = node @coverage = file_cov.select do |ln, _| - (node.empty_def? ? ln >= first_line : ln > first_line) && ln < last_line + case + when first_line == last_line + ln == first_line + when node.empty_def? + ln >= first_line + else + ln > first_line && ln < last_line + end end @file_path = file_path @flagged = false diff --git a/spec/fixtures/single_line.lcov b/spec/fixtures/single_line.lcov new file mode 100644 index 0000000..38fbb01 --- /dev/null +++ b/spec/fixtures/single_line.lcov @@ -0,0 +1,3 @@ +SF:./single_line.rb +DA:1,1 +end_of_record diff --git a/spec/fixtures/single_line.rb b/spec/fixtures/single_line.rb new file mode 100644 index 0000000..24bae94 --- /dev/null +++ b/spec/fixtures/single_line.rb @@ -0,0 +1 @@ +[].each {} diff --git a/spec/result_spec.rb b/spec/result_spec.rb index 74dced9..ece773a 100644 --- a/spec/result_spec.rb +++ b/spec/result_spec.rb @@ -82,4 +82,19 @@ expect(result.uncovered?(7)).to be_truthy end end + + context 'for single-line node covered' do + let(:ast) { Imagen.from_local('spec/fixtures/single_line.rb') } + let(:lcov) do + Undercover::LcovParser.parse('spec/fixtures/single_line.lcov') + end + let(:coverage) { lcov.source_files['single_line.rb'] } + + it 'uncovered gives false' do + node = ast.children[0].find_all(->(_) { true }).last + result = described_class.new(node, coverage, 'single_line.rb') + + expect(result.uncovered?(1)).to be_falsy + end + end end