Permalink
Browse files

Edge case, handle backspace characters

  • Loading branch information...
alloy committed Aug 6, 2010
1 parent e8cbcdc commit 7366450743a2a7b482b576c88dafa96d069b7941
Showing with 19 additions and 1 deletion.
  1. +1 −1 lib/irb/source.rb
  2. +18 −0 spec/source_spec.rb
View
@@ -191,7 +191,7 @@ def on_tstring_beg(token)
end
def on_tstring_end(token)
- if tokens_match?(@in_string, token)
+ if @in_string && tokens_match?(@in_string, token)
@in_string = nil
@level -= 1
end
View
@@ -191,19 +191,26 @@ def reflect(source)
["{ :foo => ", " :bar }"],
["[ 1", ", 2 ]"],
+ ["'", "'"],
+ ["' ", " '"],
["'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)"],
@@ -234,4 +241,15 @@ def reflect(source)
reflect("#{open}\n#{close}").code_block?.should == true
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

0 comments on commit 7366450

Please sign in to comment.