Skip to content
Open
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
8 changes: 6 additions & 2 deletions lib/lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,16 @@ def lines
# doctest: Indentation can also include the ?> marker
# >> l.range [">> 1 +", "?> 2"], 0
# => 0..1
#
# doctest: Indentation can also include the " |" marker
# >> l.range [">> 1 +", " | 2"], 0
# => 0..1
def range(doc_lines = @doc_lines, start_index = @line_index)
end_index = start_index
idt = indentation(doc_lines, start_index)
# Find next lines that are blank, or have indentation more than the first line
remaining_lines(doc_lines, start_index + 1).each do |current_line|
if current_line =~ /^(#{Regexp.escape(idt)}(\s+|\?>\s)|\s*$)/
if current_line =~ /^(#{Regexp.escape(idt)}(\s+|(\?>|\|)\s)|\s*$)/
end_index += 1
else
break
Expand Down Expand Up @@ -109,7 +113,7 @@ def inspect
# => " # "
def indentation(doc_lines = @doc_lines, line_index = @line_index)
if doc_lines[line_index]
doc_lines[line_index][/^(\s*#\s*|\s*)(\?>\s?)?/]
doc_lines[line_index][/^(\s*#\s*|\s*)((\?>|\|)\s?)?/]
else
""
end
Expand Down
5 changes: 5 additions & 0 deletions lib/statement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ def initialize(doc_lines, line_index = 0, file_name = nil)
# >> s = RubyDocTest::Statement.new([">> b = 1 +", "?> 1"])
# >> s.source_code
# => "b = 1 +\n1"
#
# doctest: Lines indented by " |" should have the " |" removed.
# >> s = RubyDocTest::Statement.new([">> b = 1 +", " | 1"])
# >> s.source_code
# => "b = 1 +\n1"
def source_code
lines.first =~ /^#{Regexp.escape(indentation)}>>\s(.*)$/
first = [$1]
Expand Down