Skip to content

Commit 10efa8c

Browse files
committed
Add test for instance variable ordering in DAP
PR ruby#806 sorts instance variables by name before returning them. This commit adds a test that verifies this functionality under the DAP protocol.
1 parent 3c2d1c1 commit 10efa8c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

test/protocol/variables_test.rb

+26
Original file line numberDiff line numberDiff line change
@@ -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| @z = 4
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-2
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 }
@@ -1073,4 +1073,3 @@ def parse_ k, v
10731073
end
10741074
end
10751075
end
1076-

0 commit comments

Comments
 (0)