Skip to content
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
4 changes: 2 additions & 2 deletions lib/dead_end/around_block_scan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ def next_down

def scan_adjacent_indent
before_after_indent = []
before_after_indent << next_up&.indent || 0
before_after_indent << next_down&.indent || 0
before_after_indent << (next_up&.indent || 0)
before_after_indent << (next_down&.indent || 0)

indent = before_after_indent.min
self.scan_while {|line| line.not_empty? && line.indent >= indent }
Expand Down
23 changes: 23 additions & 0 deletions spec/unit/around_block_scan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@

module DeadEnd
RSpec.describe AroundBlockScan do
it "scan_adjacent_indent works on first or last line" do
source_string = <<~EOM
def foo
if [options.output_format_tty, options.output_format_block].include?(nil)
raise("Bad output mode '\#{v}'; each must be one of \#{lookups.output_formats.keys}.")
end
end
EOM

code_lines = code_line_array(source_string)
block = CodeBlock.new(lines: code_lines[4])
expand = AroundBlockScan.new(code_lines: code_lines, block: block)
.scan_adjacent_indent

expect(expand.code_block.to_s).to eq(<<~EOM)
def foo
if [options.output_format_tty, options.output_format_block].include?(nil)
raise("Bad output mode '\#{v}'; each must be one of \#{lookups.output_formats.keys}.")
end
end
EOM
end

it "expands indentation" do
source_string = <<~EOM
def foo
Expand Down