From 63543f92083a25c057fda49fef8382c062461292 Mon Sep 17 00:00:00 2001 From: Stan Lo Date: Wed, 29 Mar 2023 11:14:00 +0100 Subject: [PATCH] Improve assert_repl_result for CDP The current implementation doesn't work when the result is a boolean type because the helper calls `#inspect` on the values of `JAVASCRIPT_TYPE_TO_CLASS_MAPS`, which is an array for boolean types. Example failure: ``` <["[TrueClass, FalseClass]"]> was expected to include <"FalseClass">. ``` Since `JAVASCRIPT_TYPE_TO_CLASS_MAPS` is never used in other places, we can just store the String representation of the class name in the hash and thus avoid calling `#inspect` on the values. --- test/protocol/eval_test.rb | 3 ++- test/support/protocol_test_case.rb | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/protocol/eval_test.rb b/test/protocol/eval_test.rb index ee56a63e8..443df11b1 100644 --- a/test/protocol/eval_test.rb +++ b/test/protocol/eval_test.rb @@ -13,13 +13,14 @@ class EvalTest < ProtocolTestCase 6| f = 6 RUBY - def test_eval_evaluates_arithmetic_expressions + def test_eval_evaluates_expressions run_protocol_scenario PROGRAM do req_add_breakpoint 5 req_continue assert_repl_result({value: '2', type: 'Integer'}, 'a') assert_repl_result({value: '4', type: 'Integer'}, 'd') assert_repl_result({value: '3', type: 'Integer'}, '1+2') + assert_repl_result({value: 'false', type: 'FalseClass'}, 'a == 1') req_terminate_debuggee end end diff --git a/test/support/protocol_test_case.rb b/test/support/protocol_test_case.rb index 888b06f51..4be42739d 100644 --- a/test/support/protocol_test_case.rb +++ b/test/support/protocol_test_case.rb @@ -455,10 +455,10 @@ def close_reader HOST = '127.0.0.1' JAVASCRIPT_TYPE_TO_CLASS_MAPS = { - 'string' => String, - 'number' => Integer, - 'boolean' => [TrueClass, FalseClass], - 'symbol' => Symbol + 'string' => "String", + 'number' => "Integer", + 'boolean' => ["TrueClass", "FalseClass"], + 'symbol' => "Symbol" } def assert_eval_result context, expression, expected, frame_idx @@ -497,7 +497,7 @@ def assert_eval_result context, expression, expected, frame_idx failure_msg = FailureMessage.new{create_protocol_message "result:\n#{JSON.pretty_generate res}"} - cl = res.dig(:result, :result, :className) || JAVASCRIPT_TYPE_TO_CLASS_MAPS[res.dig(:result, :result, :type)].inspect + cl = res.dig(:result, :result, :className) || JAVASCRIPT_TYPE_TO_CLASS_MAPS[res.dig(:result, :result, :type)] result_type = Array cl assert_include result_type, expected[:type], failure_msg