From 8c1e27068ffccc7099c8fe1ac8c77e146976d659 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Sun, 5 Nov 2023 21:28:53 +0530 Subject: [PATCH] Fix failing debugger test --- .../debugadapter/evaluation/IdentifierModifier.java | 6 ++---- .../debugadapter/variable/NamedCompoundVariable.java | 6 ++++++ .../org/ballerinalang/test/identifiers/IdentifierTest.java | 6 +++--- .../test-src/identifiers/identifier_with_escape_char.bal | 7 +++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/IdentifierModifier.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/IdentifierModifier.java index e8bc44238d1e..3f0dc331e6a5 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/IdentifierModifier.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/evaluation/IdentifierModifier.java @@ -22,8 +22,6 @@ import io.ballerina.compiler.syntax.tree.TreeModifier; import io.ballerina.identifier.Utils; -import static io.ballerina.identifier.Utils.unescapeUnicodeCodepoints; - /** * Identifier specific expression modifier implementation. */ @@ -39,7 +37,7 @@ public IdentifierToken transform(IdentifierToken identifier) { identifierText = identifierText.substring(1); } // Processes escaped unicode codepoints. - String unescapedIdentifier = unescapeUnicodeCodepoints(identifierText); + String unescapedIdentifier = Utils.unescapeBallerina(identifierText); // Encodes the user provided identifier in order to be aligned with JVM runtime identifiers. NonTerminalNode parent = identifier.parent(); @@ -58,7 +56,7 @@ public static String encodeIdentifier(String identifier, IdentifierType type) { if (identifier.startsWith(QUOTED_IDENTIFIER_PREFIX)) { identifier = identifier.substring(1); } - identifier = Utils.unescapeUnicodeCodepoints(identifier); + identifier = Utils.unescapeBallerina(identifier); return type == IdentifierType.METHOD_NAME ? Utils.encodeFunctionIdentifier(identifier) : Utils.encodeNonFunctionIdentifier(identifier); } diff --git a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/NamedCompoundVariable.java b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/NamedCompoundVariable.java index 514645e7d418..8362d170c5aa 100644 --- a/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/NamedCompoundVariable.java +++ b/misc/debug-adapter/modules/debug-adapter-core/src/main/java/org/ballerinalang/debugadapter/variable/NamedCompoundVariable.java @@ -66,6 +66,12 @@ public Value getChildByName(String name) throws DebugVariableException { } if (!namedChildVariables.containsKey(name)) { + for (Map.Entry childVariable : namedChildVariables.entrySet()) { + String escaped = childVariable.getKey().replaceAll("\\$0092(\\$0092)?", "$1"); + if (escaped.equals(name)) { + return childVariable.getValue(); + } + } throw new DebugVariableException("No child variables found with name: '" + name + "'"); } return namedChildVariables.get(name); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/identifiers/IdentifierTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/identifiers/IdentifierTest.java index 9d1083d2b133..ba4a0e9d02cd 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/identifiers/IdentifierTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/identifiers/IdentifierTest.java @@ -78,9 +78,9 @@ public void testInvalidImportOnMultipleFiles() { public void testEscapedIdentifier() { CompileResult result = BCompileUtil.compile("test-src/identifiers/identifier_with_escape_char.bal"); int index = 0; - validateError(result, index++, "redeclared symbol 'a3'", 20, 9); - validateError(result, index++, "redeclared symbol 'student-performance'", 22, 9); - validateError(result, index++, "redeclared symbol 'resource\\1path'", 24, 12); + validateError(result, index++, "redeclared symbol 'a3'", 23, 9); + validateError(result, index++, "redeclared symbol 'student-performance'", 25, 9); + validateError(result, index++, "redeclared symbol 'resource\\1path'", 27, 12); assertEquals(result.getErrorCount(), index); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/identifiers/identifier_with_escape_char.bal b/tests/jballerina-unit-test/src/test/resources/test-src/identifiers/identifier_with_escape_char.bal index 17322b11e3b8..57cec50658c8 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/identifiers/identifier_with_escape_char.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/identifiers/identifier_with_escape_char.bal @@ -13,7 +13,10 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. -import ballerina/io; + +public function bar(string x) returns string { + return x; +} public function foo() { int a\3 = 0; @@ -22,5 +25,5 @@ public function foo() { int student\u{002D}performance = 2; string resource\\1path = "https:\\"; string resource\u{005c}1path = "http"; - io:println(resource\\1path); + _ = bar(resource\\1path); }