Skip to content

Commit 3677c24

Browse files
committed
[#209] mark end of puzzle body where indentation stops
1 parent ba4b803 commit 3677c24

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

features/cli.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ Feature: Command Line Processing
4343
"""
4444
~~
4545
~~ @todo #44 First
46-
~~ and second
47-
~~
46+
~~ and
47+
~~ second
4848
"""
4949
When I run bin/pdd with "> out.xml"
5050
Then Exit code is zero

lib/pdd/source.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,21 @@ def minutes(num, units)
141141
min
142142
end
143143

144+
# rubocop:disable Metrics/CyclomaticComplexity
145+
# @todo #209:30min temporarily disabled cyclomatic complexity for the method.
146+
# below. Please fix soon.
147+
#
144148
# Fetch puzzle tail (all lines after the first one)
145149
def tail(lines, prefix, start)
146150
prefix = prefix.rstrip
147151
prefix = " #{' ' * start}" if prefix.empty? # fallback to space indentation
152+
line = lines[0][prefix.length + 1, lines[0].length] if lines[0]
153+
is_indented = line&.start_with?(' ')
148154
lines
149155
.take_while { |t| match_markers(t).none? && t.start_with?(prefix) }
156+
.take_while do |t|
157+
!is_indented || t[prefix.length + 1, t.length].start_with?(' ')
158+
end
150159
.take_while do |t|
151160
# account for carriage return in line endings
152161
t_len = t.length - 1
@@ -155,6 +164,7 @@ def tail(lines, prefix, start)
155164
.map { |t| t[prefix.length, t.length] }
156165
.map { |t| t.start_with?(' ') ? t[1, t.length] : t }
157166
end
167+
# rubocop:enable Metrics/CyclomaticComplexity
158168

159169
# @todo #75:30min Let's make it possible to fetch Subversion data
160170
# in a similar way as we are doing with Git. We should also just

test/test_source.rb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
require 'tmpdir'
2323
require_relative '../lib/pdd'
2424
require_relative '../lib/pdd/sources'
25+
require_relative 'test__helper'
2526

2627
# Source test.
2728
# Author:: Yegor Bugayenko (yegor256@gmail.com)
@@ -46,8 +47,8 @@ def test_parsing
4647
list = source.puzzles
4748
assert_equal 2, list.size
4849
puzzle = list.first
49-
assert_equal '2-4', puzzle.props[:lines]
50-
assert_equal 'привет, how are you doing? -something else', \
50+
assert_equal '2-3', puzzle.props[:lines]
51+
assert_equal 'привет, how are you doing?', \
5152
puzzle.props[:body]
5253
assert_equal '44', puzzle.props[:ticket]
5354
assert puzzle.props[:author].nil?
@@ -103,6 +104,28 @@ def test_no_prefix_multiline_puzzle_block
103104
end
104105
end
105106

107+
def test_space_indented_multiline_puzzle_block
108+
Dir.mktmpdir 'test' do |dir|
109+
file = File.join(dir, 'a.txt')
110+
File.write(
111+
file,
112+
"
113+
# \x40todo #99:30min hello
114+
# good bye
115+
# hello again
116+
"
117+
)
118+
stub_source_find_github_user(file, 'hey') do |source|
119+
PDD.opts = nil
120+
assert_equal 1, source.puzzles.size
121+
puzzle = source.puzzles.last
122+
assert_equal '2-3', puzzle.props[:lines]
123+
assert_equal 'hello good bye', puzzle.props[:body]
124+
assert_equal '99', puzzle.props[:ticket]
125+
end
126+
end
127+
end
128+
106129
def test_multiple_puzzles_single_comment_block
107130
Dir.mktmpdir 'test' do |dir|
108131
file = File.join(dir, 'a.txt')

0 commit comments

Comments
 (0)