Skip to content

Commit

Permalink
[#207] fix wrongly detected puzzle body
Browse files Browse the repository at this point in the history
  • Loading branch information
mbao01 committed Jul 11, 2022
1 parent cd166ee commit ba4b803
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .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:
Expand Down
6 changes: 4 additions & 2 deletions lib/pdd/source.rb
Expand Up @@ -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])
Expand Down Expand Up @@ -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|
Expand Down
24 changes: 24 additions & 0 deletions test/test_source.rb
Expand Up @@ -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,
"
<!--
\x40todo #01:30min correctly formatted multi-line puzzle, with no
comment prefix before todo marker
-->
"
)
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')
Expand Down

0 comments on commit ba4b803

Please sign in to comment.