Skip to content

Commit 3bbff42

Browse files
egiurleoko1
authored andcommitted
Add test for instance variable ordering in DAP
PR #806 sorts instance variables by name before returning them. This commit adds a test that verifies this functionality under the DAP protocol.
1 parent b860e54 commit 3bbff42

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

test/protocol/variables_test.rb

+32-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require_relative "../support/protocol_test_case"
44

55
module DEBUGGER__
6-
class DAPVariablesTest < ProtocolTestCase
6+
class DAPGlobalVariablesTest < ProtocolTestCase
77
PROGRAM = <<~RUBY
88
1| $a = 1
99
2| $b = 2
@@ -18,19 +18,19 @@ def test_eval_evaluates_global_variables
1818
globals = gather_variables(type: "globals")
1919

2020
# User defined globals
21-
assert_includes(globals, { name: "$a", value: "1", type: "Integer" })
22-
assert_includes(globals, { name: "$b", value: "2", type: "Integer" })
21+
assert_includes(globals, { name: "$a", value: "1", type: "Integer", variablesReference: 0 })
22+
assert_includes(globals, { name: "$b", value: "2", type: "Integer", variablesReference: 0 })
2323

2424
# Ruby defined globals
25-
assert_includes(globals, { name: "$VERBOSE", value: "false", type: "FalseClass" })
26-
assert_includes(globals, { name: "$stdout", value: "#<IO:<STDOUT>>", type: "IO" })
25+
assert_includes(globals, { name: "$VERBOSE", value: "false", type: "FalseClass", variablesReference: 0 })
26+
assert_includes(globals, { name: "$stdout", value: "#<IO:<STDOUT>>", type: "IO", variablesReference: 0 })
2727

2828
req_terminate_debuggee
2929
end
3030
end
3131
end
3232

33-
class CDPVariablesTest < ProtocolTestCase
33+
class CDPGlobalVariablesTest < ProtocolTestCase
3434
PROGRAM = <<~RUBY
3535
1| $a = 1
3636
2| $b = 2
@@ -56,4 +56,30 @@ def test_eval_evaluates_global_variables
5656
end
5757
end
5858
end
59+
60+
class DAPInstanceVariableTest < ProtocolTestCase
61+
PROGRAM = <<~RUBY
62+
1| @a = 1
63+
2| @c = 3
64+
3| @b = 2
65+
4| __LINE__
66+
RUBY
67+
68+
def test_ordering_instance_variables
69+
run_protocol_scenario PROGRAM, cdp: false do
70+
req_add_breakpoint 4
71+
req_continue
72+
73+
locals = gather_variables
74+
75+
variables_reference = locals.find { |local| local[:name] == "%self" }[:variablesReference]
76+
res = send_dap_request 'variables', variablesReference: variables_reference
77+
78+
instance_vars = res.dig(:body, :variables)
79+
assert_equal instance_vars.map { |var| var[:name] }, ["#class", "@a", "@b", "@c"]
80+
81+
req_terminate_debuggee
82+
end
83+
end
84+
end
5985
end

test/support/protocol_test_case.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def gather_variables(frame_idx: 0, type: "locals")
224224

225225
# get variables
226226
res = send_dap_request 'variables', variablesReference: locals_reference
227-
res.dig(:body, :variables).map { |loc| { name: loc[:name], value: loc[:value], type: loc[:type] } }
227+
res.dig(:body, :variables).map { |loc| { name: loc[:name], value: loc[:value], type: loc[:type], variablesReference: loc[:variablesReference] } }
228228
when 'chrome'
229229
current_frame = @crt_frames.first
230230
locals_scope = current_frame[:scopeChain].find { |f| f[:type] == type }

0 commit comments

Comments
 (0)