Skip to content

Commit

Permalink
Fix AroundBlockScan
Browse files Browse the repository at this point in the history
Previously we were accidentally not using the persisted @before_index and instead using the "original" before index. This commit fixes that problem and adds a test for the behavior.
  • Loading branch information
schneems committed Jan 20, 2022
1 parent 4255d30 commit 289cb0c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/dead_end/around_block_scan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def after_index
@code_lines[0...@orig_before_index] || []
end

private def before_lines
now = @code_lines[0...before_index] || []
end

private def after_lines
@code_lines[after_index.next..-1] || []
end
Expand Down
2 changes: 0 additions & 2 deletions spec/integration/dead_end_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ module DeadEnd
6 class SyntaxTree < Ripper
170 def self.parse(source)
174 end
176 private
❯ 754 def on_args_add(arguments, argument)
❯ 776 class ArgsAddBlock
❯ 810 end
Expand Down Expand Up @@ -119,7 +118,6 @@ module DeadEnd
7 REQUIRED_BY = {}
9 attr_reader :name
10 attr_writer :cost
11 attr_accessor :parent
❯ 13 def initialize(name)
❯ 18 def self.reset!
❯ 25 end
Expand Down
30 changes: 29 additions & 1 deletion spec/unit/capture_code_context_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@

module DeadEnd
RSpec.describe CaptureCodeContext do
it "capture_before_after_kws" do
source = <<~'EOM'
def sit
end
def bark
def eat
end
EOM

code_lines = CodeLine.from_source(source)

block = CodeBlock.new(lines: code_lines[0])

display = CaptureCodeContext.new(
blocks: [block],
code_lines: code_lines
)
lines = display.call
expect(lines.join).to eq(<<~EOM)
def sit
end
def bark
def eat
end
EOM
end

it "handles ambiguous end" do
source = <<~'EOM'
def call # 1
Expand Down Expand Up @@ -94,7 +123,6 @@ def call
expect(lines.join).to eq(<<~EOM)
class Rexe
VERSION = '1.5.1'
PROJECT_URL = 'https://github.com/keithrbennett/rexe'
class Lookups
def format_requires
end
Expand Down

0 comments on commit 289cb0c

Please sign in to comment.