Skip to content

Commit f346fd5

Browse files
committed
test: add negative test for reserved keyword in module import diagnostic
Adds a test case verifying that when a reserved keyword (e.g. 'client') is used unescaped in a module import path, the diagnostic message correctly includes the keyword in the module path string. Regression test for #44509 and #44519.
1 parent f37a702 commit f346fd5

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/imports/ImportsNegativeTests.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,16 @@ public void testInvalidAutoImports() {
5656
validateError(result, index++, "unknown type 'CallStackElement'", 51, 30);
5757
assertEquals(result.getErrorCount(), index);
5858
}
59+
60+
@Test(description = "Test diagnostic message for reserved keyword in module import path")
61+
public void testReservedKeywordInModuleImportDiagnostic() {
62+
CompileResult result = BCompileUtil.compile("test-src/imports/ReservedKeywordImportTestProject");
63+
int index = 0;
64+
// 'client' is a reserved keyword; the diagnostic must include it in the module path,
65+
// i.e. "ballerinax/client.config", not "ballerinax/.config" (regression for #44509/#44519)
66+
validateError(result, index++, "invalid token 'client'", 5, 19);
67+
validateError(result, index++, "missing identifier", 5, 19);
68+
validateError(result, index++, "cannot resolve module 'ballerinax/client.config as config'", 5, 1);
69+
assertEquals(result.getErrorCount(), index);
70+
}
5971
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[package]
2+
org = "testorg"
3+
name = "reservedkeywordimport"
4+
version = "1.0.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Test: using a reserved keyword (client) in a module import path without '^' escape
2+
// should produce a diagnostic that includes the keyword in the module path,
3+
// i.e. "cannot resolve module 'ballerinax/client.config as config'"
4+
// NOT "cannot resolve module 'ballerinax/.config as config'"
5+
import ballerinax/client.config;

0 commit comments

Comments
 (0)