From ba4b803b3c41b812ace9cb090b0ad3c085ccfb95 Mon Sep 17 00:00:00 2001 From: Ayomide Bakare Date: Mon, 11 Jul 2022 12:38:07 +0300 Subject: [PATCH] [#207] fix wrongly detected puzzle body --- .rubocop.yml | 4 ++-- lib/pdd/source.rb | 6 ++++-- test/test_source.rb | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index cbfadf2..4624c00 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,13 +1,13 @@ AllCops: Exclude: - - 'assets/**/*' + - "assets/**/*" DisplayCopNames: true TargetRubyVersion: 2.3 Layout/EndOfLine: EnforcedStyle: lf Metrics/ClassLength: - Max: 300 + Max: 360 Metrics/LineLength: Max: 90 Metrics/MethodLength: diff --git a/lib/pdd/source.rb b/lib/pdd/source.rb index d9404cf..c1bf051 100644 --- a/lib/pdd/source.rb +++ b/lib/pdd/source.rb @@ -104,7 +104,8 @@ def get_space_after_hash_error(todo) # Fetch puzzle def puzzle(lines, match, idx) - tail = tail(lines, match[1]) + col_idx = match[0].length - match[0].lstrip.length + tail = tail(lines, match[1], col_idx) body = "#{match[3]} #{tail.join(' ')}".gsub(/\s+/, ' ').strip body = body.chomp('*/-->').strip marker = marker(match[2]) @@ -141,8 +142,9 @@ def minutes(num, units) end # Fetch puzzle tail (all lines after the first one) - def tail(lines, prefix) + def tail(lines, prefix, start) prefix = prefix.rstrip + prefix = " #{' ' * start}" if prefix.empty? # fallback to space indentation lines .take_while { |t| match_markers(t).none? && t.start_with?(prefix) } .take_while do |t| diff --git a/test/test_source.rb b/test/test_source.rb index e3e164c..a5e1370 100644 --- a/test/test_source.rb +++ b/test/test_source.rb @@ -79,6 +79,30 @@ def test_parsing_leading_spaces end end + def test_no_prefix_multiline_puzzle_block + Dir.mktmpdir 'test' do |dir| + file = File.join(dir, 'a.txt') + File.write( + file, + " + + " + ) + stub_source_find_github_user(file, 'hey') do |source| + PDD.opts = nil + assert_equal 1, source.puzzles.size + puzzle = source.puzzles.last + assert_equal '3-4', puzzle.props[:lines] + assert_equal 'correctly formatted multi-line puzzle, with no ' \ + 'comment prefix before todo marker', puzzle.props[:body] + assert_equal '01', puzzle.props[:ticket] + end + end + end + def test_multiple_puzzles_single_comment_block Dir.mktmpdir 'test' do |dir| file = File.join(dir, 'a.txt')