Skip to content

Commit

Permalink
indent: handle consecutive linebreaks
Browse files Browse the repository at this point in the history
  • Loading branch information
bcgraham committed Dec 6, 2019
1 parent 62c8951 commit 5c4e14b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/pry/indent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,14 @@ def indent(input)

line = prefix + line.lstrip unless previously_in_string

output += line
output += "#{line.chomp}\n"

prefix = new_prefix
end

@indent_level = prefix

output
output.chomp
end

# Get the indentation for the start of the next line.
Expand Down
28 changes: 28 additions & 0 deletions spec/indent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,34 @@ def number
expect(@indent.indent(input)).to eq output
end

it 'should properly indent nested code with consecutive linebreaks' do
input = <<TXT.strip
class C
def foo
:foo
end
def bar
:bar
end
end
TXT

output = <<TXT.strip
class C
def foo
:foo
end
def bar
:bar
end
end
TXT

expect(@indent.indent(input)).to eq output
end

it 'should indent statements such as if, else, etc' do
input = <<TXT.strip
if a == 10
Expand Down

0 comments on commit 5c4e14b

Please sign in to comment.