From 2f37ab37a6c1bcd752eed51655940c790b3e1b28 Mon Sep 17 00:00:00 2001 From: MaryamZi Date: Thu, 26 Sep 2024 09:13:16 +0530 Subject: [PATCH] Add tests for member access on empty sequence types --- .../test/expressions/access/XmlMemberAccessTest.java | 4 +++- .../test-src/expressions/access/xml_member_access.bal | 6 ++++++ .../expressions/access/xml_member_access_negative.bal | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/access/XmlMemberAccessTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/access/XmlMemberAccessTest.java index 52b6a71b2a62..59e1efeb63b0 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/access/XmlMemberAccessTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/access/XmlMemberAccessTest.java @@ -86,6 +86,7 @@ public void testNegativeCases() { "found '(xml:Element|xml:Comment|xml)'", 74, 32); validateError(negativeResult, i++, "incompatible types: expected '(xml:Comment|xml)', " + "found '(xml:Comment|xml:ProcessingInstruction|never|xml)'", 77, 32); + validateError(negativeResult, i++, "incompatible types: expected 'xml:Element', found 'xml'", 82, 21); Assert.assertEquals(negativeResult.getErrorCount(), i); } @@ -104,7 +105,8 @@ public Object[][] xmlMemberAccessFunctions() { { "testXmlMemberAccessOnXmlProcessingInstructionSequences" }, { "testXmlMemberAccessOnXmlSingletons" }, { "testXmlMemberAccessOnXmlUnions" }, - { "testXmlMemberAccessOnXmlUnionSequences" } + { "testXmlMemberAccessOnXmlUnionSequences" }, + { "testXmlMemberAccessOnEmptySequenceType" } }; } } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/access/xml_member_access.bal b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/access/xml_member_access.bal index 7d6a9d964c29..5fc23e6e4778 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/access/xml_member_access.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/access/xml_member_access.bal @@ -197,6 +197,12 @@ function testXmlMemberAccessOnXmlUnionSequences() { assertTrue(seq2[1] is xml); } +function testXmlMemberAccessOnEmptySequenceType() { + xml seq = xml ``; + xml val = seq[0]; + assertEquality(xml ``, val); +} + function assertTrue(anydata actual) { assertEquality(true, actual); } diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/access/xml_member_access_negative.bal b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/access/xml_member_access_negative.bal index 763160ef6393..bafd570062f9 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/expressions/access/xml_member_access_negative.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/expressions/access/xml_member_access_negative.bal @@ -76,3 +76,8 @@ function testXmlMemberAccessOnXmlUnionSequencesNegative() { xml seq2 = xml ``; xml:Comment|xml _ = seq2[0]; } + +function testXmlMemberAccessOnEmptySequenceTypeNegative() { + xml seq = xml ``; + xml:Element _ = seq[0]; +}