From 7df095894de2ea4bd71b19362c5d2787ad58c357 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Fri, 5 Jan 2024 16:35:50 +0530 Subject: [PATCH 01/11] Fix const module list access --- .../analyzer/ConstantTypeChecker.java | 5 +- .../bala/constant/ListConstantInBalaTest.java | 68 +++++++++++++++++++ .../constant/list-literal-constant.bal | 37 ++++++++++ .../test_project/list-constant.bal | 13 ++++ 4 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java create mode 100644 tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list-literal-constant.bal create mode 100644 tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list-constant.bal diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java index 59f16e44eda7..2a7098921ef8 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java @@ -1357,8 +1357,9 @@ private BType checkTupleType(BTupleType tupleType, BLangListConstructorExpr list } private BTupleType createNewTupleType(Location pos, List memberTypes, AnalyzerData data) { - BTypeSymbol tupleTypeSymbol = Symbols.createTypeSymbol(SymTag.TUPLE_TYPE, 0, Names.EMPTY, - data.env.enclPkg.symbol.pkgID, null, data.env.scope.owner, pos, SOURCE); + BTypeSymbol tupleTypeSymbol = + Symbols.createTypeSymbol(SymTag.TUPLE_TYPE, data.constantSymbol.flags, Names.EMPTY, + data.env.enclPkg.symbol.pkgID, null, data.env.scope.owner, pos, SOURCE); List members = new ArrayList<>(); memberTypes.forEach(m -> members.add(new BTupleMember(m, Symbols.createVarSymbolForTupleMember(m)))); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java new file mode 100644 index 000000000000..6479f3b45c3b --- /dev/null +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.ballerinalang.test.bala.constant; + +import org.ballerinalang.test.BCompileUtil; +import org.ballerinalang.test.BRunUtil; +import org.ballerinalang.test.CompileResult; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * Test cases for reading list constants. + */ +public class ListConstantInBalaTest { + + private CompileResult compileResult; + + @BeforeClass + public void setup() { + BCompileUtil.compileAndCacheBala("test-src/bala/test_projects/test_project"); + compileResult = BCompileUtil.compile("test-src/bala/test_bala/constant/list-literal-constant.bal"); + } + + @Test(dataProvider = "listAccessTestDataProvider") + public void testConstantListAccess(String testCase) { + try { + BRunUtil.invoke(compileResult, testCase); + } catch (Exception e) { + Assert.fail(testCase + " test case failed."); + } + } + + @DataProvider(name = "listAccessTestDataProvider") + public Object[] listAccessTestDataProvider() { + return new Object[]{ + "testSimpleArrayAccess", + "testSimpleTupleAccess", + "test2DTupleAccess", + "test2DArrayAccess", + "testFixedLengthArrayAccess", + "testArrayWithRestAccess", + "test2DUnionArrayAccess" + }; + } + + @AfterClass + public void tearDown() { + compileResult = null; + } +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list-literal-constant.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list-literal-constant.bal new file mode 100644 index 000000000000..97ae33a3d534 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list-literal-constant.bal @@ -0,0 +1,37 @@ +import testorg/foo; + +function testSimpleArrayAccess() { + assertEqual(foo:l1, ["a", "b", "c"]); +} + +function testSimpleTupleAccess() { + assertEqual(foo:l2, [1, "d"]); +} + +function test2DTupleAccess() { + assertEqual(foo:l3, [1, ["e", 2]]); +} + +function test2DArrayAccess() { + assertEqual(foo:l4, [[1, 2, 3], [4, 5, 6]]); +} + +function testFixedLengthArrayAccess() { + assertEqual(foo:l5, [true, false, true]); +} + +function testArrayWithRestAccess() { + assertEqual(foo:l7, [1, "f", "g"]); +} + +function test2DUnionArrayAccess() { + assertEqual(foo:l8, [[1, "2", 3], [4, 5, 6]]); + assertEqual(foo:l9, [[1, 2, 3], ["4", "5", "6"]]); +} + +function assertEqual(anydata actual, anydata expected) { + if expected == actual { + return; + } + panic error(string `expected '${expected.toBalString()}', found '${actual.toBalString()}'`); +} diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list-constant.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list-constant.bal new file mode 100644 index 000000000000..5dadfa94ae7f --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list-constant.bal @@ -0,0 +1,13 @@ +type IntArr int[]; + +const int length = 3; + +public const string[] l1 = ["a", "b", "c"]; +public const [int, string] l2 = [1, "d"]; +public const [int, [string, int]] l3 = [1, ["e", 2]]; +public const int[][] l4 = [[1, 2, 3], [4, 5, 6]]; +public const boolean[length] l5 = [true, false, true]; +public const IntArr l6 = [1, 2, 3]; +public const [int, string...] l7 = [1, "f", "g"]; +public const (string|int)[][] l8 = [[1, "2", 3], [4, 5, 6]]; +public const [(string[]|int[])...] l9 = [[1, 2, 3], ["4", "5", "6"]]; From 1b3ba5357beae93e4e858aabcb82b4a526fd00bf Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Mon, 8 Jan 2024 06:52:36 +0530 Subject: [PATCH 02/11] Add missing since in test --- .../test/bala/constant/ListConstantInBalaTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java index 6479f3b45c3b..187eec952e81 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java @@ -28,6 +28,8 @@ /** * Test cases for reading list constants. + * + * @since 2201.9.0 */ public class ListConstantInBalaTest { From 5701a735f536232d0b28372d345abae91ed7f2a7 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Mon, 22 Jan 2024 06:29:23 +0530 Subject: [PATCH 03/11] Add negative tests --- .../ListConstantInBalaNegativeTest.java | 66 +++++++++++++++++++ .../constant/list_constant_negative.bal | 20 ++++++ 2 files changed, 86 insertions(+) create mode 100644 tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java create mode 100644 tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java new file mode 100644 index 000000000000..b5ddbe398a08 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.ballerinalang.test.bala.constant; + +import org.ballerinalang.test.BAssertUtil; +import org.ballerinalang.test.BCompileUtil; +import org.ballerinalang.test.CompileResult; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * Negative Bala test cases for list constants. + * + * @since 2201.9.0 + */ + +public class ListConstantInBalaNegativeTest { + + @BeforeClass + public void setup() { + BCompileUtil.compileAndCacheBala("test-src/bala/test_projects/test_project"); + } + + @Test + public void testNegative() { + CompileResult compileResult = BCompileUtil.compile( + "test-src/bala/test_bala/constant/list_constant_negative.bal"); + int i = 0; + BAssertUtil.validateError(compileResult, i++, + "incompatible types: expected '[string,string,int...]', found '[\"a\",\"b\",\"c\"] & readonly'", 4, 34); + BAssertUtil.validateError(compileResult, i++, + "incompatible types: expected 'int[]', found '[true,false,true] & readonly'", 5, 15); + BAssertUtil.validateError(compileResult, i++, + "cannot update 'readonly' value of type '[\"a\",\"b\",\"c\"] & readonly'", 10, 5); + BAssertUtil.validateError(compileResult, i++, + "cannot update 'readonly' value of type '[\"a\",\"b\",\"c\"] & readonly'", 11, 5); + BAssertUtil.validateError(compileResult, i++, + "incompatible types: expected '(\"a\"|\"b\"|\"c\")', found 'string:Char'", 11, 12); + BAssertUtil.validateError(compileResult, i++, + "cannot update 'readonly' value of type '[1,\"f\",\"g\"] & readonly'", 14, 5); + BAssertUtil.validateError(compileResult, i++, "incompatible types: expected '(1|\"f\"|\"g\")', found 'string'", + 14, 12); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 18, 17); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 19, 18); + Assert.assertEquals(compileResult.getErrorCount(), i); + } + +} + + diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal new file mode 100644 index 000000000000..eda058124916 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal @@ -0,0 +1,20 @@ +import testorg/foo; + +function testIncompatibleAssignment() { + [string, string, int...] _ = foo:l1; + int[] _ = foo:l5; +} + +function testInvalidUpdates() { + var a = foo:l1; + a[0] = "1"; + a.push("2"); + + var b = foo:l7; + b.push("l7"); +} + +function testInvalidAccess() { + float[] _ = foo:l10; + string[] _ = foo:l11; +} From 13157cfe83ec56e9ddbae73ddeed182d40b5a7a4 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Thu, 8 Feb 2024 10:17:40 +0530 Subject: [PATCH 04/11] Address review comments --- .../compiler/semantics/analyzer/ConstantTypeChecker.java | 2 +- .../test/bala/constant/ListConstantInBalaNegativeTest.java | 2 -- .../test/bala/constant/ListConstantInBalaTest.java | 7 +------ .../bala/test_bala/constant/list_constant_negative.bal | 2 +- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java index 2a7098921ef8..3ec317055393 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java @@ -1358,7 +1358,7 @@ private BType checkTupleType(BTupleType tupleType, BLangListConstructorExpr list private BTupleType createNewTupleType(Location pos, List memberTypes, AnalyzerData data) { BTypeSymbol tupleTypeSymbol = - Symbols.createTypeSymbol(SymTag.TUPLE_TYPE, data.constantSymbol.flags, Names.EMPTY, + Symbols.createTypeSymbol(SymTag.TUPLE_TYPE, Flags.PUBLIC, Names.EMPTY, data.env.enclPkg.symbol.pkgID, null, data.env.scope.owner, pos, SOURCE); List members = new ArrayList<>(); memberTypes.forEach(m -> diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java index b5ddbe398a08..ece1d1d0c13a 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java @@ -62,5 +62,3 @@ public void testNegative() { } } - - diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java index 187eec952e81..3e416a033cb6 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java @@ -20,7 +20,6 @@ import org.ballerinalang.test.BCompileUtil; import org.ballerinalang.test.BRunUtil; import org.ballerinalang.test.CompileResult; -import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; @@ -43,11 +42,7 @@ public void setup() { @Test(dataProvider = "listAccessTestDataProvider") public void testConstantListAccess(String testCase) { - try { - BRunUtil.invoke(compileResult, testCase); - } catch (Exception e) { - Assert.fail(testCase + " test case failed."); - } + BRunUtil.invoke(compileResult, testCase); } @DataProvider(name = "listAccessTestDataProvider") diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal index eda058124916..701a66129838 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal @@ -14,7 +14,7 @@ function testInvalidUpdates() { b.push("l7"); } -function testInvalidAccess() { +function testUndefinedMemberAccess() { float[] _ = foo:l10; string[] _ = foo:l11; } From c605626e5159bfec1a57a3b545889b4edef4bbaf Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Sun, 25 Feb 2024 09:35:09 +0530 Subject: [PATCH 05/11] Add missing license headers --- .../ListConstantInBalaNegativeTest.java | 20 ++++++------- .../bala/constant/ListConstantInBalaTest.java | 2 +- .../constant/list_constant_negative.bal | 16 ++++++++++ ...constant.bal => list_literal_constant.bal} | 16 ++++++++++ .../test_project/list-constant.bal | 13 --------- .../test_project/list_constant.bal | 29 +++++++++++++++++++ 6 files changed, 72 insertions(+), 24 deletions(-) rename tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/{list-literal-constant.bal => list_literal_constant.bal} (56%) delete mode 100644 tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list-constant.bal create mode 100644 tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java index ece1d1d0c13a..4a863cab5f34 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java @@ -29,7 +29,6 @@ * * @since 2201.9.0 */ - public class ListConstantInBalaNegativeTest { @BeforeClass @@ -43,21 +42,22 @@ public void testNegative() { "test-src/bala/test_bala/constant/list_constant_negative.bal"); int i = 0; BAssertUtil.validateError(compileResult, i++, - "incompatible types: expected '[string,string,int...]', found '[\"a\",\"b\",\"c\"] & readonly'", 4, 34); + "incompatible types: expected '[string,string,int...]', found '[\"a\",\"b\",\"c\"] & readonly'", 20, + 34); BAssertUtil.validateError(compileResult, i++, - "incompatible types: expected 'int[]', found '[true,false,true] & readonly'", 5, 15); + "incompatible types: expected 'int[]', found '[true,false,true] & readonly'", 21, 15); BAssertUtil.validateError(compileResult, i++, - "cannot update 'readonly' value of type '[\"a\",\"b\",\"c\"] & readonly'", 10, 5); + "cannot update 'readonly' value of type '[\"a\",\"b\",\"c\"] & readonly'", 26, 5); BAssertUtil.validateError(compileResult, i++, - "cannot update 'readonly' value of type '[\"a\",\"b\",\"c\"] & readonly'", 11, 5); + "cannot update 'readonly' value of type '[\"a\",\"b\",\"c\"] & readonly'", 27, 5); BAssertUtil.validateError(compileResult, i++, - "incompatible types: expected '(\"a\"|\"b\"|\"c\")', found 'string:Char'", 11, 12); + "incompatible types: expected '(\"a\"|\"b\"|\"c\")', found 'string:Char'", 27, 12); BAssertUtil.validateError(compileResult, i++, - "cannot update 'readonly' value of type '[1,\"f\",\"g\"] & readonly'", 14, 5); + "cannot update 'readonly' value of type '[1,\"f\",\"g\"] & readonly'", 30, 5); BAssertUtil.validateError(compileResult, i++, "incompatible types: expected '(1|\"f\"|\"g\")', found 'string'", - 14, 12); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 18, 17); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 19, 18); + 30, 12); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 34, 17); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 35, 18); Assert.assertEquals(compileResult.getErrorCount(), i); } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java index 3e416a033cb6..0700b4c2a6e7 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java @@ -37,7 +37,7 @@ public class ListConstantInBalaTest { @BeforeClass public void setup() { BCompileUtil.compileAndCacheBala("test-src/bala/test_projects/test_project"); - compileResult = BCompileUtil.compile("test-src/bala/test_bala/constant/list-literal-constant.bal"); + compileResult = BCompileUtil.compile("test-src/bala/test_bala/constant/list_literal_constant.bal"); } @Test(dataProvider = "listAccessTestDataProvider") diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal index 701a66129838..acf82c3afed3 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import testorg/foo; function testIncompatibleAssignment() { diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list-literal-constant.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_literal_constant.bal similarity index 56% rename from tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list-literal-constant.bal rename to tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_literal_constant.bal index 97ae33a3d534..1c499cf54e45 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list-literal-constant.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_literal_constant.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License + import testorg/foo; function testSimpleArrayAccess() { diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list-constant.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list-constant.bal deleted file mode 100644 index 5dadfa94ae7f..000000000000 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list-constant.bal +++ /dev/null @@ -1,13 +0,0 @@ -type IntArr int[]; - -const int length = 3; - -public const string[] l1 = ["a", "b", "c"]; -public const [int, string] l2 = [1, "d"]; -public const [int, [string, int]] l3 = [1, ["e", 2]]; -public const int[][] l4 = [[1, 2, 3], [4, 5, 6]]; -public const boolean[length] l5 = [true, false, true]; -public const IntArr l6 = [1, 2, 3]; -public const [int, string...] l7 = [1, "f", "g"]; -public const (string|int)[][] l8 = [[1, "2", 3], [4, 5, 6]]; -public const [(string[]|int[])...] l9 = [[1, 2, 3], ["4", "5", "6"]]; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal new file mode 100644 index 000000000000..8ccd04b1b3e3 --- /dev/null +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal @@ -0,0 +1,29 @@ +// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License + +type IntArr int[]; + +const int length = 3; + +public const string[] l1 = ["a", "b", "c"]; +public const [int, string] l2 = [1, "d"]; +public const [int, [string, int]] l3 = [1, ["e", 2]]; +public const int[][] l4 = [[1, 2, 3], [4, 5, 6]]; +public const boolean[length] l5 = [true, false, true]; +public const IntArr l6 = [1, 2, 3]; +public const [int, string...] l7 = [1, "f", "g"]; +public const (string|int)[][] l8 = [[1, "2", 3], [4, 5, 6]]; +public const [(string[]|int[])...] l9 = [[1, 2, 3], ["4", "5", "6"]]; From e6506445183e81d97d2b77d8cf3b6632e12ba201 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Tue, 12 Mar 2024 10:24:19 +0530 Subject: [PATCH 06/11] Update recordTypeSymbol flags --- .../compiler/semantics/analyzer/ConstantTypeChecker.java | 2 +- .../test-src/bala/test_bala/constant/list_constant_negative.bal | 2 +- .../test-src/bala/test_bala/constant/list_literal_constant.bal | 2 +- .../test-src/bala/test_projects/test_project/list_constant.bal | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java index 3ec317055393..993715ea9f85 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java @@ -2060,7 +2060,7 @@ private BRecordTypeSymbol createRecordTypeSymbol(PackageID pkgID, Location locat SymbolEnv env = data.env; Name genName = Names.fromString(anonymousModelHelper.getNextAnonymousTypeKey(pkgID, data.anonTypeNameSuffixes)); - BRecordTypeSymbol recordSymbol = Symbols.createRecordSymbol(data.constantSymbol.flags, genName, + BRecordTypeSymbol recordSymbol = Symbols.createRecordSymbol(Flags.PUBLIC, genName, pkgID, null, env.scope.owner, location, origin); BInvokableType bInvokableType = new BInvokableType(new ArrayList<>(), symTable.nilType, null); diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal index acf82c3afed3..6c9b79746037 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023 WSO2 LLC. (http://www.wso2.com). +// Copyright (c) 2024 WSO2 LLC. (http://www.wso2.com). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_literal_constant.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_literal_constant.bal index 1c499cf54e45..dd56e80b1f53 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_literal_constant.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_literal_constant.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal index 8ccd04b1b3e3..9899182ce6cc 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal @@ -1,4 +1,4 @@ -// Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com). +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). // // WSO2 LLC. licenses this file to you under the Apache License, // Version 2.0 (the "License"); you may not use this file except From 36b7fe84fa7c484cb97e03edd1801498a426ac63 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Wed, 13 Mar 2024 16:50:20 +0530 Subject: [PATCH 07/11] Add non public access tests --- .../semantics/analyzer/ConstantTypeChecker.java | 5 +++-- .../bala/constant/ListConstantInBalaNegativeTest.java | 10 ++++++++-- .../bala/test_bala/constant/list_constant_negative.bal | 10 ++++++++-- .../bala/test_projects/test_project/list_constant.bal | 3 +++ 4 files changed, 22 insertions(+), 6 deletions(-) diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java index 993715ea9f85..6c2f666a935a 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java @@ -1357,9 +1357,10 @@ private BType checkTupleType(BTupleType tupleType, BLangListConstructorExpr list } private BTupleType createNewTupleType(Location pos, List memberTypes, AnalyzerData data) { + SymbolEnv symbolEnv = data.env; BTypeSymbol tupleTypeSymbol = - Symbols.createTypeSymbol(SymTag.TUPLE_TYPE, Flags.PUBLIC, Names.EMPTY, - data.env.enclPkg.symbol.pkgID, null, data.env.scope.owner, pos, SOURCE); + Symbols.createTypeSymbol(SymTag.TUPLE_TYPE, Flags.PUBLIC, Names.EMPTY, symbolEnv.enclPkg.symbol.pkgID, + null, symbolEnv.scope.owner, pos, SOURCE); List members = new ArrayList<>(); memberTypes.forEach(m -> members.add(new BTupleMember(m, Symbols.createVarSymbolForTupleMember(m)))); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java index 4a863cab5f34..8d6e6f40c79d 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java @@ -56,8 +56,14 @@ public void testNegative() { "cannot update 'readonly' value of type '[1,\"f\",\"g\"] & readonly'", 30, 5); BAssertUtil.validateError(compileResult, i++, "incompatible types: expected '(1|\"f\"|\"g\")', found 'string'", 30, 12); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 34, 17); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 35, 18); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l13'", 34, 17); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l14'", 35, 18); + BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l10'", 39, 15); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 39, 15); + BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l11'", 40, 29); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 40, 29); + BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l12'", 41, 18); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l12'", 41, 18); Assert.assertEquals(compileResult.getErrorCount(), i); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal index 6c9b79746037..bfb7617eac5f 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal @@ -31,6 +31,12 @@ function testInvalidUpdates() { } function testUndefinedMemberAccess() { - float[] _ = foo:l10; - string[] _ = foo:l11; + float[] _ = foo:l13; + string[] _ = foo:l14; +} + +function testNonPublicConstAccess() { + int[] _ = foo:l10; + [int, int, boolean] _ = foo:l11; + string[] _ = foo:l12; } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal index 9899182ce6cc..cae666c03b71 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_projects/test_project/list_constant.bal @@ -27,3 +27,6 @@ public const IntArr l6 = [1, 2, 3]; public const [int, string...] l7 = [1, "f", "g"]; public const (string|int)[][] l8 = [[1, "2", 3], [4, 5, 6]]; public const [(string[]|int[])...] l9 = [[1, 2, 3], ["4", "5", "6"]]; +const int[] l10 = [1, 2, 3]; +const [int, int, boolean] l11 = [1, 2, true]; +const l12 = l1; From 178f97c2a35d19bdff39b3e29d213a088d9e6d27 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Fri, 15 Mar 2024 06:22:29 +0530 Subject: [PATCH 08/11] Remove unnecessary types --- .../constant/ListConstantInBalaNegativeTest.java | 16 ++++++++-------- .../constant/list_constant_negative.bal | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java index 8d6e6f40c79d..4d586a0bf563 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java @@ -56,14 +56,14 @@ public void testNegative() { "cannot update 'readonly' value of type '[1,\"f\",\"g\"] & readonly'", 30, 5); BAssertUtil.validateError(compileResult, i++, "incompatible types: expected '(1|\"f\"|\"g\")', found 'string'", 30, 12); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l13'", 34, 17); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l14'", 35, 18); - BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l10'", 39, 15); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 39, 15); - BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l11'", 40, 29); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 40, 29); - BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l12'", 41, 18); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l12'", 41, 18); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l13'", 34, 9); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l14'", 35, 9); + BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l10'", 39, 9); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 39, 9); + BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l11'", 40, 9); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 40, 9); + BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l12'", 41, 9); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l12'", 41, 9); Assert.assertEquals(compileResult.getErrorCount(), i); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal index bfb7617eac5f..1e7aef464bb5 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal @@ -31,12 +31,12 @@ function testInvalidUpdates() { } function testUndefinedMemberAccess() { - float[] _ = foo:l13; - string[] _ = foo:l14; + _ = foo:l13; + _ = foo:l14; } function testNonPublicConstAccess() { - int[] _ = foo:l10; - [int, int, boolean] _ = foo:l11; - string[] _ = foo:l12; + _ = foo:l10; + _ = foo:l11; + _ = foo:l12; } From c71e4d454eb8fab913a0c84d0d937542b335696e Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Mon, 18 Mar 2024 16:35:26 +0530 Subject: [PATCH 09/11] Address review comments --- .../analyzer/ConstantTypeChecker.java | 2 +- .../ListConstantInBalaNegativeTest.java | 70 ------------------- .../bala/constant/ListConstantInBalaTest.java | 33 +++++++++ .../constant/list_constant_negative.bal | 2 +- 4 files changed, 35 insertions(+), 72 deletions(-) delete mode 100644 tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java diff --git a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java index 6c2f666a935a..685d8fc46f91 100644 --- a/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java +++ b/compiler/ballerina-lang/src/main/java/org/wso2/ballerinalang/compiler/semantics/analyzer/ConstantTypeChecker.java @@ -2061,7 +2061,7 @@ private BRecordTypeSymbol createRecordTypeSymbol(PackageID pkgID, Location locat SymbolEnv env = data.env; Name genName = Names.fromString(anonymousModelHelper.getNextAnonymousTypeKey(pkgID, data.anonTypeNameSuffixes)); - BRecordTypeSymbol recordSymbol = Symbols.createRecordSymbol(Flags.PUBLIC, genName, + BRecordTypeSymbol recordSymbol = Symbols.createRecordSymbol(data.constantSymbol.flags, genName, pkgID, null, env.scope.owner, location, origin); BInvokableType bInvokableType = new BInvokableType(new ArrayList<>(), symTable.nilType, null); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java deleted file mode 100644 index 4d586a0bf563..000000000000 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaNegativeTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). - * - * WSO2 LLC. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.ballerinalang.test.bala.constant; - -import org.ballerinalang.test.BAssertUtil; -import org.ballerinalang.test.BCompileUtil; -import org.ballerinalang.test.CompileResult; -import org.testng.Assert; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * Negative Bala test cases for list constants. - * - * @since 2201.9.0 - */ -public class ListConstantInBalaNegativeTest { - - @BeforeClass - public void setup() { - BCompileUtil.compileAndCacheBala("test-src/bala/test_projects/test_project"); - } - - @Test - public void testNegative() { - CompileResult compileResult = BCompileUtil.compile( - "test-src/bala/test_bala/constant/list_constant_negative.bal"); - int i = 0; - BAssertUtil.validateError(compileResult, i++, - "incompatible types: expected '[string,string,int...]', found '[\"a\",\"b\",\"c\"] & readonly'", 20, - 34); - BAssertUtil.validateError(compileResult, i++, - "incompatible types: expected 'int[]', found '[true,false,true] & readonly'", 21, 15); - BAssertUtil.validateError(compileResult, i++, - "cannot update 'readonly' value of type '[\"a\",\"b\",\"c\"] & readonly'", 26, 5); - BAssertUtil.validateError(compileResult, i++, - "cannot update 'readonly' value of type '[\"a\",\"b\",\"c\"] & readonly'", 27, 5); - BAssertUtil.validateError(compileResult, i++, - "incompatible types: expected '(\"a\"|\"b\"|\"c\")', found 'string:Char'", 27, 12); - BAssertUtil.validateError(compileResult, i++, - "cannot update 'readonly' value of type '[1,\"f\",\"g\"] & readonly'", 30, 5); - BAssertUtil.validateError(compileResult, i++, "incompatible types: expected '(1|\"f\"|\"g\")', found 'string'", - 30, 12); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l13'", 34, 9); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l14'", 35, 9); - BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l10'", 39, 9); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 39, 9); - BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l11'", 40, 9); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 40, 9); - BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l12'", 41, 9); - BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l12'", 41, 9); - Assert.assertEquals(compileResult.getErrorCount(), i); - } - -} diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java index 0700b4c2a6e7..a601b65b5457 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java @@ -17,9 +17,11 @@ */ package org.ballerinalang.test.bala.constant; +import org.ballerinalang.test.BAssertUtil; import org.ballerinalang.test.BCompileUtil; import org.ballerinalang.test.BRunUtil; import org.ballerinalang.test.CompileResult; +import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; @@ -58,6 +60,37 @@ public Object[] listAccessTestDataProvider() { }; } + @Test + public void testNegativeConstantListAccess() { + CompileResult compileResult = BCompileUtil.compile( + "test-src/bala/test_bala/constant/list_constant_negative.bal"); + int i = 0; + BAssertUtil.validateError(compileResult, i++, + "incompatible types: expected '[string,string,int...]', found '[\"a\",\"b\",\"c\"] & readonly'", 20, + 34); + BAssertUtil.validateError(compileResult, i++, + "incompatible types: expected 'int[]', found '[true,false,true] & readonly'", 21, 15); + BAssertUtil.validateError(compileResult, i++, + "cannot update 'readonly' value of type '[\"a\",\"b\",\"c\"] & readonly'", 26, 5); + BAssertUtil.validateError(compileResult, i++, + "cannot update 'readonly' value of type '[\"a\",\"b\",\"c\"] & readonly'", 27, 5); + BAssertUtil.validateError(compileResult, i++, + "incompatible types: expected '(\"a\"|\"b\"|\"c\")', found 'string:Char'", 27, 12); + BAssertUtil.validateError(compileResult, i++, + "cannot update 'readonly' value of type '[1,\"f\",\"g\"] & readonly'", 30, 5); + BAssertUtil.validateError(compileResult, i++, "incompatible types: expected '(1|\"f\"|\"g\")', found 'string'", + 30, 12); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l13'", 34, 9); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l14'", 35, 9); + BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l10'", 39, 9); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l10'", 39, 9); + BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l11'", 40, 9); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l11'", 40, 9); + BAssertUtil.validateError(compileResult, i++, "attempt to refer to non-accessible symbol 'l12'", 41, 9); + BAssertUtil.validateError(compileResult, i++, "undefined symbol 'l12'", 41, 9); + Assert.assertEquals(compileResult.getErrorCount(), i); + } + @AfterClass public void tearDown() { compileResult = null; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal index 1e7aef464bb5..afbb3ba33f80 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/bala/test_bala/constant/list_constant_negative.bal @@ -30,7 +30,7 @@ function testInvalidUpdates() { b.push("l7"); } -function testUndefinedMemberAccess() { +function testUndefinedSymbolAccess() { _ = foo:l13; _ = foo:l14; } From 2ae428b93c30a101cab85cb60df4ae4aaee737c7 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Tue, 19 Mar 2024 11:05:04 +0530 Subject: [PATCH 10/11] Update function and dataprovider names --- .../test/bala/constant/ListConstantInBalaTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java index a601b65b5457..e211fc4331b3 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java @@ -42,13 +42,13 @@ public void setup() { compileResult = BCompileUtil.compile("test-src/bala/test_bala/constant/list_literal_constant.bal"); } - @Test(dataProvider = "listAccessTestDataProvider") + @Test(dataProvider = "constantListAccessTestDataProvider") public void testConstantListAccess(String testCase) { BRunUtil.invoke(compileResult, testCase); } - @DataProvider(name = "listAccessTestDataProvider") - public Object[] listAccessTestDataProvider() { + @DataProvider(name = "constantListAccessTestDataProvider") + public Object[] constantListAccessTestDataProvider() { return new Object[]{ "testSimpleArrayAccess", "testSimpleTupleAccess", @@ -61,7 +61,7 @@ public Object[] listAccessTestDataProvider() { } @Test - public void testNegativeConstantListAccess() { + public void testConstantListAccessNegative() { CompileResult compileResult = BCompileUtil.compile( "test-src/bala/test_bala/constant/list_constant_negative.bal"); int i = 0; From 97dcc48bacd8a95c078857981c1396ca49b4cc17 Mon Sep 17 00:00:00 2001 From: poorna2152 Date: Wed, 21 Aug 2024 06:46:33 +0530 Subject: [PATCH 11/11] Update version in added new file --- .../test/bala/constant/ListConstantInBalaTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java index e211fc4331b3..57ef498aae48 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/constant/ListConstantInBalaTest.java @@ -30,7 +30,7 @@ /** * Test cases for reading list constants. * - * @since 2201.9.0 + * @since 2201.8.8 */ public class ListConstantInBalaTest {