diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryExprWithQueryConstructTypeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryExprWithQueryConstructTypeTest.java index 01c2e7513834..20574f01978c 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryExprWithQueryConstructTypeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/QueryExprWithQueryConstructTypeTest.java @@ -131,6 +131,16 @@ public void testKeyLessTableWithReturnTable() { Assert.assertTrue((Boolean) returnValues); } + @Test(description = "Test query expr with map construction variable references in on conflict clause") + public void testQueryConstructingMapWithOnConflictsWithVarRef() { + BRunUtil.invoke(result, "testQueryConstructingMapWithOnConflictsWithVarRef"); + } + + @Test(description = "Test query expr with table construction variable references in on conflict clause") + public void testQueryConstructingTableWithOnConflictsWithVarRef() { + BRunUtil.invoke(result, "testQueryConstructingTableWithOnConflictsWithVarRef"); + } + @Test(description = "Test negative scenarios for query expr with query construct type") public void testNegativeScenarios() { int index = 0; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/query/query-expr-with-query-construct-type.bal b/tests/jballerina-unit-test/src/test/resources/test-src/query/query-expr-with-query-construct-type.bal index 67c8e3d87b9d..cb79c1ce777e 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/query/query-expr-with-query-construct-type.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/query/query-expr-with-query-construct-type.bal @@ -979,6 +979,30 @@ function testQueryConstructingTableWithOnConflictClauseHavingNonTableQueryInWher } } +function testQueryConstructingTableWithOnConflictsWithVarRef() { + TokenTable|error tbl1 = table key(idx) from int i in [1, 2, 3, 1, 2, 3] + let string value = "A" + i.toString() + select { + idx: i, + value + } + on conflict error(string `Duplicate Key: ${i} Value: ${value}`); + + assertEqual(true, tbl1 is error); + assertEqual("Duplicate Key: 1 Value: A1", (tbl1).message()); + + int duplicateKey = 1; + TokenTable|error tbl2 = table key(idx) from int i in [1, 2, 3, 1, 2, 3] + let string value = "A" + i.toString() + select { + idx: i, + value + } + on conflict error(string `Duplicate Key: ${duplicateKey} Value: ${value}`); + assertEqual(true, tbl2 is error); + assertEqual("Duplicate Key: 1 Value: A1", (tbl2).message()); +} + function testMapConstructingQueryExpr() { Customer c1 = {id: 1, name: "Melina", noOfItems: 12}; Customer c2 = {id: 2, name: "James", noOfItems: 5}; @@ -1609,6 +1633,24 @@ function testQueryConstructingMapsAndTablesWithClausesMayCompleteSEarlyWithError assertEqual(table6, error("Error")); } +function testQueryConstructingMapWithOnConflictsWithVarRef() { + map|error mp1 = map from int i in [1, 2, 3, 1, 2, 3] + let string value = "A" + i.toString() + select [i.toString(), value] + on conflict error(string `Duplicate Key: ${i} Value: ${value}`); + + assertEqual(true, mp1 is error); + assertEqual("Duplicate Key: 1 Value: A1", (mp1).message()); + + int duplicateKey = 1; + map|error mp2 = map from int i in [1, 2, 3, 1, 2, 3] + let string value = "A" + i.toString() + select [i.toString(), value] + on conflict error(string `Duplicate Key: ${duplicateKey} Value: ${value}`); + assertEqual(true, mp2 is error); + assertEqual("Duplicate Key: 1 Value: A1", (mp2).message()); +} + function testQueryConstructingMapsAndTablesWithClausesMayCompleteSEarlyWithError2() { EvenNumberGenerator evenGen = new(); stream evenNumberStream = new(evenGen);