Skip to content

Commit

Permalink
Edge case, handle backspace characters
Browse files Browse the repository at this point in the history
  • Loading branch information
alloy committed Aug 6, 2010
1 parent e8cbcdc commit 7366450
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/irb/source.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def on_tstring_beg(token)
end end


def on_tstring_end(token) def on_tstring_end(token)
if tokens_match?(@in_string, token) if @in_string && tokens_match?(@in_string, token)
@in_string = nil @in_string = nil
@level -= 1 @level -= 1
end end
Expand Down
18 changes: 18 additions & 0 deletions spec/source_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -191,19 +191,26 @@ def reflect(source)
["{ :foo => ", " :bar }"], ["{ :foo => ", " :bar }"],
["[ 1", ", 2 ]"], ["[ 1", ", 2 ]"],


["'", "'"],
["' ", " '"],
["'foo ", " bar'"], ["'foo ", " bar'"],
["' foo ", " bar '"], ["' foo ", " bar '"],


['"', '"'],
['" ', ' "'],
['"foo ', ' bar"'], ['"foo ', ' bar"'],
['" foo ', ' bar "'], ['" foo ', ' bar "'],


["%{", "}"],
["%{ ", " }"],
["%{foo ", " bar}"], ["%{foo ", " bar}"],
["%{ foo ", " bar }"], ["%{ foo ", " bar }"],
["%(foo ", " bar)"], ["%(foo ", " bar)"],
["%( foo ", " bar )"], ["%( foo ", " bar )"],
["%[ foo ", " bar ]"], ["%[ foo ", " bar ]"],
["%[foo ", " bar]"], ["%[foo ", " bar]"],


["%w{ ", " }"],
["%w{foo ", " bar}"], ["%w{foo ", " bar}"],
["%w{ foo ", " bar }"], ["%w{ foo ", " bar }"],
["%w(foo ", " bar)"], ["%w(foo ", " bar)"],
Expand Down Expand Up @@ -234,4 +241,15 @@ def reflect(source)
reflect("#{open}\n#{close}").code_block?.should == true reflect("#{open}\n#{close}").code_block?.should == true
end end
end end

it "handles cases that contain backspaces" do
[
["%{", "\b"],
["%w{", "\b"],
["%r{", "\b"],
].each do |open, close|
reflect("#{open}\n#{close}").level.should == 1
reflect("#{open}\n#{close}").code_block?.should == false
end
end
end end

0 comments on commit 7366450

Please sign in to comment.