Skip to content

Commit 62f44c6

Browse files
committed
unit-testing of incoming unescaping, fixed inspect test
1 parent 3d07d6b commit 62f44c6

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

lib/ruby-debug-ide/command.rb

+7-7
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ def method_missing(meth, *args, &block)
6464
def options
6565
@options ||= {}
6666
end
67+
68+
def unescape_incoming(str)
69+
str.gsub(/((?:^|[^\\])(?:\\\\)*)\\n/, "\\1\n")
70+
.gsub(/\\\\/, '\\')
71+
end
6772
end
6873

6974
def initialize(state, printer)
@@ -104,11 +109,11 @@ def timeout(sec)
104109
y.kill if y and y.alive?
105110
end
106111
end
107-
112+
108113
def debug_eval(str, b = get_binding)
109114
begin
110115
str = str.to_s
111-
to_inspect = unescape_incoming(str)
116+
to_inspect = Command.unescape_incoming(str)
112117
max_time = Debugger.evaluation_timeout
113118
@printer.print_debug("Evaluating #{str} with timeout after %i sec", max_time)
114119
timeout(max_time) do
@@ -120,11 +125,6 @@ def debug_eval(str, b = get_binding)
120125
end
121126
end
122127

123-
def unescape_incoming(str)
124-
str.gsub(/(?<backsl_escapes>(?:^|[^\\])(?:\\\\)*)\\n/, "\\k<backsl_escapes>\n")
125-
.gsub(/\\\\/, '\\')
126-
end
127-
128128
def debug_silent_eval(str)
129129
begin
130130
str = str.to_s

test-base/inspect_test.rb

+14-7
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,31 @@ def test_inspect_multiline_expression
6868
send_cont
6969
end
7070

71-
def test_inspect_escaping_escaped_newlines
71+
def test_inspect_unescaping_escaped_newlines
7272
create_socket ["sleep 0.1"]
7373
run_to_line(1)
7474

7575
send_ruby('v inspect "\\\\n".size')
76-
variable = read_variables
76+
variables = read_variables
7777
assert_equal(1, variables.length, "There is one variable returned.")
78-
assert_equal(1, variables[0].value, "There is one char (newline)")
78+
assert_equal("1", variables[0].value, "There is one char (newline)")
7979

8080
send_ruby('v inspect "\\\\\\n".size')
81-
variable = read_variables
81+
variables = read_variables
8282
assert_equal(1, variables.length, "There is one variable returned.")
83-
assert_equal(0, variables[0].value, "There are no chars, it's line continuation here")
83+
assert_equal("0", variables[0].value, "There are no chars, it's line continuation here")
8484

8585
send_ruby('v inspect "\\\\\\\\\\n".size')
86-
variable = read_variables
86+
variables = read_variables
87+
assert_equal(1, variables.length, "There is one variable returned.")
88+
assert_equal("2", variables[0].value, "There are two chars: escaped backslash and newline")
89+
90+
send_ruby('v inspect \'"\\\\n\'.size')
91+
variables = read_variables
8792
assert_equal(1, variables.length, "There is one variable returned.")
88-
assert_equal(2, variables[0].value, "There are two chars: escaped backslash and newline")
93+
assert_equal("3", variables[0].value, "There are three chars: quote, backslash and n")
94+
95+
send_cont
8996
end
9097

9198
end
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'test/unit'
2+
require 'ruby-debug-ide/command'
3+
4+
class UnescaperTest < Test::Unit::TestCase
5+
6+
def test_empty
7+
do_test('', '')
8+
do_test('a', 'a')
9+
end
10+
11+
def test_newline
12+
do_test('\n', "\n")
13+
do_test('a\n', "a\n")
14+
end
15+
16+
def test_escaped_newline
17+
do_test('\\\\n', '\n')
18+
do_test('a\\\\n', 'a\n')
19+
end
20+
21+
def test_backslash_and_newline
22+
do_test('\\\\\\n', "\\\n")
23+
do_test('a\\\\\\n', "a\\\n")
24+
end
25+
26+
def test_something
27+
do_test('hello\nthere\\\\n', "hello\nthere\\n")
28+
do_test('"\\\\\\n".size', "\"\\\n\".size")
29+
end
30+
31+
def do_test(input, expected_result)
32+
assert_equal(expected_result, Debugger::Command.unescape_incoming(input))
33+
end
34+
end

0 commit comments

Comments
 (0)