Skip to content

Commit

Permalink
[cqfn#234] Empty string is supposed to break the puzzle description. …
Browse files Browse the repository at this point in the history
…At least one space in the line will read the next line also
  • Loading branch information
pnatashap committed Jan 20, 2024
1 parent 2215a6b commit f9c670b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 13 deletions.
14 changes: 5 additions & 9 deletions lib/pdd/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,22 @@ def minutes(num, units)
min
end

# rubocop:disable Metrics/CyclomaticComplexity
# @todo #209:30min temporarily disabled cyclomatic complexity for the method.
# below. Please fix soon.
#
# Fetch puzzle tail (all lines after the first one)
def tail(lines, prefix, start)
return [] if lines.empty?
prefix = " #{' ' * start}" if prefix.empty? # fallback to space indentation
line = lines[0][prefix.length, lines[0].length] if lines[0]
is_indented = line&.start_with?(' ')
empty_prefix = ' ' * (prefix.length + 1)
prefix = "#{prefix} " if lines[0][prefix.length, 1]&.start_with?(' ')
lines
.take_while do |t|
start = t.length > prefix.length ? prefix : prefix.rstrip
match_markers(t).none? && t.start_with?(start)
end
.take_while do |t|
!is_indented || t[prefix.length, t.length].start_with?(' ')
match_markers(t).none? && \
(t.start_with?(prefix) || t.start_with?(empty_prefix))
end
.map { |t| t[prefix.length, t.length]&.lstrip }
end
# rubocop:enable Metrics/CyclomaticComplexity

# @todo #75:30min Let's make it possible to fetch Subversion data
# in a similar way as we are doing with Git. We should also just
Expand Down
4 changes: 2 additions & 2 deletions test/test_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def test_multiple_puzzles_single_comment_block
* \x40todo #1 First one with
* a few lines
* \x40todo #1 Second one also
* with a few lines
* with a few lines of text
*/
"
)
Expand All @@ -145,7 +145,7 @@ def test_multiple_puzzles_single_comment_block
assert_equal 2, source.puzzles.size
puzzle = source.puzzles.last
assert_equal '5-6', puzzle.props[:lines]
assert_equal 'Second one also with a few lines', puzzle.props[:body]
assert_equal 'Second one also with a few lines of text', puzzle.props[:body]
assert_equal '1', puzzle.props[:ticket]
end
end
Expand Down
30 changes: 30 additions & 0 deletions test/test_source_todo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,36 @@ def test_todo_colon_parsing_multi_line
)
end

def test_todo_colon_parsing_multi_line_with_empty_line
check_valid_puzzle(
"
// TODO: #45 task description
//
// second line after empty line is not a puzzle text
",
'2-2',
'task description',
'45'
)
end

# space is needed in test data in the comment
# rubocop:disable Layout/TrailingWhitespace
def test_todo_colon_parsing_multi_line_with_empty_line_and_space
check_valid_puzzle(
'
// TODO: #46 task description
//
// second line after empty line is a part of the puzzle in case of space exists
',
'2-4',
'task description second line after empty line is a part ' \
'of the puzzle in case of space exists',
'46'
)
end
# rubocop:enable Layout/TrailingWhitespace

def test_todo_failing_no_ticket
check_invalid_puzzle(
"
Expand Down
4 changes: 2 additions & 2 deletions test_assets/puzzles/44-660e9d6f
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// @todo #44 This puzzle
// consists
// of
//
//
// two
// paragraphs

// This text doesn't belong to the puzzle
// This text doesn't belong to the puzzle

0 comments on commit f9c670b

Please sign in to comment.