Skip to content

Commit eaadd92

Browse files
committed
Add some test cases
1 parent 2cba6e9 commit eaadd92

File tree

11 files changed

+429
-0
lines changed

11 files changed

+429
-0
lines changed

test/dap/break2_test.rb

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
class BreakTest1 < TestCase
7+
PROGRAM = <<~RUBY
8+
1| module Foo
9+
2| class Bar
10+
3| def self.a
11+
4| "hello"
12+
5| end
13+
6| end
14+
7| Bar.a
15+
8| bar = Bar.new
16+
9| end
17+
RUBY
18+
19+
def test_break
20+
run_protocol_scenario PROGRAM do
21+
req_set_breakpoints 5
22+
req_continue
23+
assert_line_num 5
24+
req_set_breakpoints 8
25+
req_continue
26+
assert_line_num 8
27+
req_continue
28+
end
29+
end
30+
end
31+
32+
class BreakTest2 < TestCase
33+
def program path
34+
<<~RUBY
35+
1| require_relative "#{path}"
36+
2| Foo.new.bar
37+
RUBY
38+
end
39+
40+
def extra_file
41+
<<~RUBY
42+
class Foo
43+
def bar
44+
puts :hoge
45+
end
46+
end
47+
RUBY
48+
end
49+
50+
def test_break
51+
with_extra_tempfile do |extra_file|
52+
run_protocol_scenario(program(extra_file.path)) do
53+
req_set_breakpoints 3, path: extra_file.path
54+
req_continue
55+
assert_line_num 3
56+
req_continue
57+
end
58+
end
59+
end
60+
end
61+
end

test/dap/catch2_test.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class CatchTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| module Foo
10+
2| class Bar
11+
3| def self.a
12+
4| raise 'foo'
13+
5| end
14+
6| end
15+
7| Bar.a
16+
8| bar = Bar.new
17+
9| end
18+
RUBY
19+
20+
def test_catch
21+
run_protocol_scenario PROGRAM do
22+
req_set_exception_breakpoints
23+
req_continue
24+
assert_line_num 4
25+
req_continue
26+
end
27+
end
28+
end
29+
end

test/dap/detach2_test.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class DetachTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| module Foo
10+
2| class Bar
11+
3| def self.a
12+
4| "hello"
13+
5| end
14+
6| end
15+
7| loop do
16+
8| b = 1
17+
9| end
18+
10| Bar.a
19+
11| bar = Bar.new
20+
12| end
21+
RUBY
22+
23+
def test_detach
24+
run_protocol_scenario PROGRAM do
25+
req_set_breakpoints 3
26+
req_continue
27+
assert_reattach
28+
req_terminate_debuggee
29+
end
30+
end
31+
end
32+
end

test/dap/eval2_test.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class EvalTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| a = 2
10+
2| b = 3
11+
3| c = 1
12+
4| d = 4
13+
5| e = 5
14+
6| f = 6
15+
RUBY
16+
17+
def test_eval1
18+
run_protocol_scenario PROGRAM do
19+
req_set_breakpoints 5
20+
req_continue
21+
assert_repl_result 2, expression: 'a'
22+
assert_repl_result 4, expression: 'd'
23+
assert_repl_result 3, expression: '1+2'
24+
req_continue
25+
end
26+
end
27+
end
28+
end

test/dap/finish2_test.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class FinishTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| module Foo
10+
2| class Bar
11+
3| def self.a
12+
4| "hello"
13+
5| end
14+
6| end
15+
7| Bar.a
16+
8| bar = Bar.new
17+
9| end
18+
RUBY
19+
20+
def test_finish1
21+
run_protocol_scenario PROGRAM do
22+
req_set_breakpoints 4
23+
req_continue
24+
assert_line_num 4
25+
req_finish
26+
assert_line_num 5
27+
req_continue
28+
end
29+
end
30+
end
31+
end

test/dap/hover2_test.rb

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class HoverTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| a = 1
10+
2| b = 2
11+
3| c = 3
12+
4| d = 4
13+
5| e = 5
14+
RUBY
15+
16+
def test_hover
17+
run_protocol_scenario PROGRAM do
18+
req_set_breakpoints 4
19+
req_continue
20+
assert_hover_result 2, expression: 'b'
21+
assert_hover_result 3, expression: 'c'
22+
assert_hover_result 1, expression: 'a'
23+
req_continue
24+
end
25+
end
26+
end
27+
28+
class HoverTest2 < TestCase
29+
PROGRAM = <<~RUBY
30+
1| p 1
31+
RUBY
32+
33+
def test_hover
34+
run_protocol_scenario PROGRAM do
35+
b = TOPLEVEL_BINDING.dup
36+
assert_hover_result b.eval('self').method(:p), expression: 'p'
37+
req_continue
38+
end
39+
end
40+
end
41+
42+
class HoverTest3 < TestCase
43+
PROGRAM = <<~RUBY
44+
1| module Abc
45+
2| class Def123
46+
3| class Ghi
47+
4| def initialize
48+
5| @a = 1
49+
6| end
50+
7|
51+
8| def a
52+
9| ::Abc.foo
53+
10| ::Abc::Def123.bar
54+
11| p @a
55+
12| end
56+
13| end
57+
14|
58+
15| def bar
59+
16| p :bar1
60+
17| end
61+
18|
62+
19| def self.bar
63+
20| p :bar2
64+
21| end
65+
22| end
66+
23|
67+
24| def self.foo
68+
25| p :foo
69+
26| end
70+
27| end
71+
28|
72+
29| Abc::Def123.new.bar
73+
30|
74+
31| ghi = Abc::Def123::Ghi.new
75+
32| ghi.a
76+
RUBY
77+
78+
def test_hover
79+
run_protocol_scenario PROGRAM do
80+
req_set_breakpoints 31
81+
req_continue
82+
assert_hover_result Object.const_set('Abc', Module.new), expression: 'Abc'
83+
assert_hover_result Abc.const_set('Def123', Class.new), expression: 'Abc::Def123'
84+
assert_hover_result Abc::Def123.const_set('Ghi', Class.new), expression: 'Abc::Def123::Ghi'
85+
assert_hover_result Abc::Def123::Ghi, expression: 'Abc::Def123::Ghi.new'
86+
assert_hover_result Abc, expression: '::Abc.foo'
87+
assert_hover_result Abc::Def123, expression: '::Abc::Def123'
88+
assert_hover_result Abc::Def123, expression: '::Abc::Def123.bar'
89+
req_continue
90+
end
91+
end
92+
end
93+
end

test/dap/next2_test.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class NextTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| module Foo
10+
2| class Bar
11+
3| def self.a
12+
4| "hello"
13+
5| end
14+
6| end
15+
7| Bar.a
16+
8| bar = Bar.new
17+
9| end
18+
RUBY
19+
20+
def test_next1
21+
run_protocol_scenario PROGRAM do
22+
req_next
23+
assert_line_num 2
24+
req_next
25+
assert_line_num 3
26+
req_next
27+
assert_line_num 7
28+
req_next
29+
assert_line_num 8
30+
req_next
31+
end
32+
end
33+
end
34+
end

test/dap/restart2_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class RestartTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| a = 1
10+
RUBY
11+
12+
def test_restart
13+
run_protocol_scenario PROGRAM do
14+
req_terminate_debuggee
15+
end
16+
end
17+
end
18+
end

test/dap/step2_test.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../support/test_case'
4+
5+
module DEBUGGER__
6+
7+
class StepTest < TestCase
8+
PROGRAM = <<~RUBY
9+
1| module Foo
10+
2| class Bar
11+
3| def self.a
12+
4| "hello"
13+
5| end
14+
6| end
15+
7| Bar.a
16+
8| bar = Bar.new
17+
9| end
18+
RUBY
19+
20+
def test_step1
21+
run_protocol_scenario PROGRAM do
22+
req_step
23+
assert_line_num 2
24+
req_step
25+
assert_line_num 3
26+
req_step
27+
assert_line_num 7
28+
req_step
29+
assert_line_num 4
30+
req_step
31+
assert_line_num 5
32+
req_step
33+
assert_line_num 8
34+
req_step
35+
end
36+
end
37+
end
38+
end

0 commit comments

Comments
 (0)