From 6d851457c04165390b84934b054dd615343708be Mon Sep 17 00:00:00 2001 From: schneems Date: Mon, 28 Dec 2020 10:46:18 -0600 Subject: [PATCH] Fix comparison of Integer with nil failed --- lib/dead_end/around_block_scan.rb | 4 ++-- spec/unit/around_block_scan_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/dead_end/around_block_scan.rb b/lib/dead_end/around_block_scan.rb index b13ed72..063b665 100644 --- a/lib/dead_end/around_block_scan.rb +++ b/lib/dead_end/around_block_scan.rb @@ -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 } diff --git a/spec/unit/around_block_scan_spec.rb b/spec/unit/around_block_scan_spec.rb index a9e6b73..e6390d2 100644 --- a/spec/unit/around_block_scan_spec.rb +++ b/spec/unit/around_block_scan_spec.rb @@ -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