From f9c670b6b3eff29dc4fa090e11eecb7148a1448c Mon Sep 17 00:00:00 2001 From: Natalia Pozhidaeva Date: Sat, 20 Jan 2024 01:23:19 -0500 Subject: [PATCH] [#234] Empty string is supposed to break the puzzle description. At least one space in the line will read the next line also --- lib/pdd/source.rb | 14 +++++--------- test/test_source.rb | 4 ++-- test/test_source_todo.rb | 30 ++++++++++++++++++++++++++++++ test_assets/puzzles/44-660e9d6f | 4 ++-- 4 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lib/pdd/source.rb b/lib/pdd/source.rb index ae592cb..ad06660 100644 --- a/lib/pdd/source.rb +++ b/lib/pdd/source.rb @@ -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 diff --git a/test/test_source.rb b/test/test_source.rb index 18433e4..f770f1b 100644 --- a/test/test_source.rb +++ b/test/test_source.rb @@ -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 */ " ) @@ -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 diff --git a/test/test_source_todo.rb b/test/test_source_todo.rb index 75e99ef..d6c722d 100644 --- a/test/test_source_todo.rb +++ b/test/test_source_todo.rb @@ -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( " diff --git a/test_assets/puzzles/44-660e9d6f b/test_assets/puzzles/44-660e9d6f index ac8de85..c65f59c 100644 --- a/test_assets/puzzles/44-660e9d6f +++ b/test_assets/puzzles/44-660e9d6f @@ -2,8 +2,8 @@ // @todo #44 This puzzle // consists // of -// +// // two // paragraphs -// This text doesn't belong to the puzzle \ No newline at end of file +// This text doesn't belong to the puzzle