Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#234] Empty line is supposed as stop for puzzle description #236

Merged
merged 3 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions lib/pdd/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,18 @@ 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 145 also has a leading space after an empty line, but it isn't part of puzzle text. How this line is different?

Copy link
Contributor

@php-coder php-coder Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see it now: on line 159 there is a trailing space.

Could we have a better rules for distinguishing one type of the comments from another? The current one seems like a subject for future confusions of our users.

/cc @yegor256 WDYT?

',
'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
Loading