diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BallerinaXmlSerializer.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BallerinaXmlSerializer.java index f47bf9dcbfbf..c836f4929cbb 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BallerinaXmlSerializer.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/BallerinaXmlSerializer.java @@ -287,7 +287,7 @@ private String getXmlNsUriPrefix(Map nsPrefixMap, String uri) { } private void writeAttributes(HashSet curNSSet, Map attributeMap) throws XMLStreamException { - String defaultNS = xmlStreamWriter.getNamespaceContext().getNamespaceURI(XMLNS); + String defaultNS = xmlStreamWriter.getNamespaceContext().getNamespaceURI(""); for (Map.Entry attributeEntry : attributeMap.entrySet()) { String key = attributeEntry.getKey(); int closingCurlyPos = key.lastIndexOf('}'); diff --git a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java index 842256465bd4..ab15068c0347 100644 --- a/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java +++ b/bvm/ballerina-runtime/src/main/java/io/ballerina/runtime/internal/values/XmlItem.java @@ -382,9 +382,9 @@ private BError createXMLCycleError() { } private void mergeAdjoiningTextNodesIntoList(List leftList, List appendingList) { - XmlPi lastChild = (XmlPi) leftList.get(leftList.size() - 1); - String firstChildContent = ((XmlPi) appendingList.get(0)).getData(); - String mergedTextContent = lastChild.getData() + firstChildContent; + XmlText lastChild = (XmlText) leftList.get(leftList.size() - 1); + String firstChildContent = appendingList.get(0).getTextValue(); + String mergedTextContent = lastChild.getTextValue() + firstChildContent; XmlText text = new XmlText(mergedTextContent); leftList.set(leftList.size() - 1, text); for (int i = 1; i < appendingList.size(); i++) { diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/ClosedRecordTypeInclusionTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/ClosedRecordTypeInclusionTest.java index ca828de57c9f..48ba6acd5de8 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/ClosedRecordTypeInclusionTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/ClosedRecordTypeInclusionTest.java @@ -51,7 +51,7 @@ public void setup() { compileResult = BCompileUtil.compile("test-src/record/closed_record_type_inclusion.bal"); } - @Test(description = "Negative tests" , groups = {"disableOnOldParser"}) + @Test(description = "Negative tests") public void negativeTests() { CompileResult negative = BCompileUtil.compile("test-src/record/closed_record_type_inclusion_negative.bal"); int index = 0; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/OpenRecordTypeInclusionTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/OpenRecordTypeInclusionTest.java index 5c6d9e62aaf0..e7f08457dc79 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/OpenRecordTypeInclusionTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/bala/record/OpenRecordTypeInclusionTest.java @@ -51,7 +51,7 @@ public void setup() { compileResult = BCompileUtil.compile("test-src/record/open_record_type_inclusion.bal"); } - @Test(description = "Negative tests" , groups = {"disableOnOldParser"}) + @Test(description = "Negative tests") public void negativeTests() { CompileResult negative = BCompileUtil.compile("test-src/record/open_record_type_inclusion_negative.bal"); int index = 0; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/lambda/FunctionPointersNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/lambda/FunctionPointersNegativeTest.java index 879e4768b73f..f29a3bf1da7d 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/lambda/FunctionPointersNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/lambda/FunctionPointersNegativeTest.java @@ -67,7 +67,7 @@ public void testFPInStructIncorrectArg() { BAssertUtil.validateError(result, 0, "incompatible types: expected 'string', found 'Person'", 32, 30); } - @Test(groups = { "disableOnOldParser" }) + @Test() public void testFPWithNoImport() { CompileResult result = BCompileUtil.compile("test-src/expressions/lambda/negative/fp-with-import-negative.bal"); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/lambda/FunctionPointersWithOptionalArgsTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/lambda/FunctionPointersWithOptionalArgsTest.java index 285867d08d7a..71d59cf48468 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/lambda/FunctionPointersWithOptionalArgsTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/lambda/FunctionPointersWithOptionalArgsTest.java @@ -41,7 +41,7 @@ public void setup() { result = BCompileUtil.compile("test-src/expressions/lambda/function-pointers-with-optional-args.bal"); } - @Test(groups = { "disableOnOldParser" }) + @Test() public void testFunctionPointersWithNamedArgs() { CompileResult result = BCompileUtil.compile("test-src/expressions/lambda/function-pointers-with-named-args-negative.bal"); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/mappingconstructor/MappingConstructorExprTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/mappingconstructor/MappingConstructorExprTest.java index 9914ad447bf9..6590d74cd67c 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/mappingconstructor/MappingConstructorExprTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/expressions/mappingconstructor/MappingConstructorExprTest.java @@ -327,7 +327,7 @@ public Object[][] readOnlyFieldTests() { }; } - @Test(groups = "disableOnOldParser") + @Test() public void testReadOnlyFieldsSemanticNegative() { CompileResult compileResult = BCompileUtil.compile("test-src/expressions/mappingconstructor/readonly_field_negative.bal"); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/object/ObjectDocumentationTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/object/ObjectDocumentationTest.java index 69f91d0e68d4..6d2564e4b04f 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/object/ObjectDocumentationTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/object/ObjectDocumentationTest.java @@ -66,7 +66,7 @@ public void testDocAnnotation() { Assert.assertNotNull(docNode); } - @Test(description = "Test doc struct.", groups = { "disableOnOldParser" }) + @Test(description = "Test doc struct.") public void testDocStruct() { CompileResult compileResult = BCompileUtil.compile("test-src/object/object_doc_annotation.bal"); Assert.assertEquals(compileResult.getWarnCount(), 0); @@ -88,7 +88,7 @@ public void testDocStruct() { EMPTY_STRING), "struct `field c` documentation"); } - @Test(description = "Test doc negative cases.", groups = { "disableOnOldParser" }) + @Test(description = "Test doc negative cases.") public void testDocumentationNegative() { CompileResult compileResult = BCompileUtil.compile("test-src/object/object_documentation_negative.bal"); Assert.assertEquals(compileResult.getErrorCount(), 0, getErrorString(compileResult.getDiagnostics())); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/LimitClauseTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/LimitClauseTest.java index 97427fbc9a3e..6bf2d3a5dbc3 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/LimitClauseTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/LimitClauseTest.java @@ -152,7 +152,7 @@ public void testLetExpressionWithLimitClause() { Assert.assertTrue((Boolean) values); } - @Test(description = "Test limit clause with incompatible types", groups = {"disableOnOldParser"}) + @Test(description = "Test limit clause with incompatible types") public void testNegativeScenarios() { negativeResult = BCompileUtil.compile("test-src/query/limit-clause-negative.bal"); Assert.assertEquals(negativeResult.getErrorCount(), 3); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/OrderByClauseTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/OrderByClauseTest.java index 3ed601d37ddb..59b4789c5199 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/OrderByClauseTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/OrderByClauseTest.java @@ -35,7 +35,7 @@ * * @since Swan Lake */ -@Test(groups = {"disableOnOldParser"}) +@Test() public class OrderByClauseTest { private CompileResult result; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/XMLQueryExpressionTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/XMLQueryExpressionTest.java index 39307ff0c501..6fe2729ab2d9 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/XMLQueryExpressionTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/query/XMLQueryExpressionTest.java @@ -50,7 +50,7 @@ public void testNegativeQueryExprForXML() { validateError(negativeResult, index++, "incompatible types: expected " + "'xml<((xml:Element|xml:Comment|xml:ProcessingInstruction|xml:Text) & readonly)> & readonly'," + " found 'xml'", 21, 16); - validateError(negativeResult, index++, "incompatible types: expected 'xml:Element & readonly', " + "" + + validateError(negativeResult, index++, "incompatible types: expected 'xml:Element & readonly', " + "found 'xml:Element'", 25, 16); validateError(negativeResult, index++, "incompatible types: expected 'xml<(xml:Element & readonly)> & readonly', found 'xml:Element'", @@ -89,7 +89,7 @@ public void testSimpleQueryExprForXML() { "Sherlock HolmesThe Da Vinci Code"); } - @Test(groups = {"disableOnOldParser"}, description = "Test simple query expression for XMLs - #2") + @Test(description = "Test simple query expression for XMLs - #2") public void testSimpleQueryExprForXML2() { Object returnValues = BRunUtil.invoke(result, "testSimpleQueryExprForXML2"); Assert.assertNotNull(returnValues); @@ -149,7 +149,7 @@ public void testSimpleQueryExprForXMLOrNilResult() { "Sherlock HolmesThe Da Vinci Code"); } - @Test(groups = {"disableOnOldParser"}, description = "Test simple query expression for xml? - #2") + @Test(description = "Test simple query expression for xml? - #2") public void testSimpleQueryExprForXMLOrNilResult2() { Object returnValues = BRunUtil.invoke(result, "testSimpleQueryExprForXMLOrNilResult2"); Assert.assertNotNull(returnValues); @@ -355,8 +355,7 @@ public void testSimpleQueryExprForXMLWithReadonly1() { BRunUtil.invoke(result, "testSimpleQueryExprForXMLWithReadonly1"); } - @Test(groups = {"disableOnOldParser"}, - description = "Test simple query expression for XMLs with readonly intersection - #2") + @Test(description = "Test simple query expression for XMLs with readonly intersection - #2") public void testSimpleQueryExprForXMLWithReadonly2() { BRunUtil.invoke(result, "testSimpleQueryExprForXMLWithReadonly2"); } @@ -386,8 +385,7 @@ public void testSimpleQueryExprForXMLOrNilResultWithReadonly1() { BRunUtil.invoke(result, "testSimpleQueryExprForXMLOrNilResultWithReadonly1"); } - @Test(groups = {"disableOnOldParser"}, - description = "Test simple query expression for xml? with readonly intersection - #2") + @Test(description = "Test simple query expression for xml? with readonly intersection - #2") public void testSimpleQueryExprForXMLOrNilResultWithReadonly2() { BRunUtil.invoke(result, "testSimpleQueryExprForXMLOrNilResultWithReadonly2"); } @@ -522,6 +520,11 @@ public void testQueryExpressionIteratingOverStreamReturningXMLWithReadonly() { BRunUtil.invoke(result, "testQueryExpressionIteratingOverStreamReturningXMLWithReadonly"); } + @Test(description = "Test XML template with query expression iterating over xml starting with whitespace") + public void testQueryExpressionXmlStartWithWhiteSpace() { + BRunUtil.invoke(result, "testQueryExpressionXmlStartWithWhiteSpace"); + } + @AfterClass public void tearDown() { result = null; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/ClosedRecordOptionalFieldsTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/ClosedRecordOptionalFieldsTest.java index 8cceda02f20e..da2f74175d23 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/ClosedRecordOptionalFieldsTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/ClosedRecordOptionalFieldsTest.java @@ -47,7 +47,7 @@ public void setup() { compileResult = BCompileUtil.compile("test-src/record/closed_record_optional_fields.bal"); } - @Test(description = "Test for the compile errors", groups = {"disableOnOldParser"}) + @Test(description = "Test for the compile errors") public void testNegatives() { CompileResult negativeResult = BCompileUtil.compile( "test-src/record/closed_record_optional_fields_negatives.bal"); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/OpenRecordNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/OpenRecordNegativeTest.java index ac64fb80990b..c5fef5094863 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/OpenRecordNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/OpenRecordNegativeTest.java @@ -71,8 +71,7 @@ public void invalidRecordAssignment() { " anydata...; |} j; anydata...; |}', found 'int'", 4, 9); } - @Test(description = "Test white space between the type name and ellipsis in rest descriptor", - groups = {"disableOnOldParser"}) + @Test(description = "Test white space between the type name and ellipsis in rest descriptor") public void testRestDescriptorSyntax() { CompileResult result = BCompileUtil.compile("test-src/record/open_record_invalid_rest_desc.bal"); assertEquals(result.getErrorCount(), 0); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/RecordDocumentationTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/RecordDocumentationTest.java index ef871e87c8b4..e3850bab3379 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/RecordDocumentationTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/record/RecordDocumentationTest.java @@ -40,7 +40,7 @@ public class RecordDocumentationTest { public void setup() { } - @Test(description = "Test doc annotation.", groups = {"disableOnOldParser"}) + @Test(description = "Test doc annotation.") public void testDocAnnotation() { CompileResult compileResult = BCompileUtil.compile("test-src/record/record_annotation.bal"); Assert.assertEquals(compileResult.getWarnCount(), 3); @@ -88,7 +88,7 @@ public void testDocStruct() { EMPTY_STRING), "struct `field c` documentation"); } - @Test(description = "Test doc negative cases.", groups = {"disableOnOldParser"}) + @Test(description = "Test doc negative cases.") public void testDocumentationNegative() { CompileResult compileResult = BCompileUtil.compile("test-src/record/record_documentation_negative.bal"); Assert.assertEquals(compileResult.getErrorCount(), 0, diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/arrays/SealedArrayTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/arrays/SealedArrayTest.java index 034251b4e140..1a515c77c94d 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/arrays/SealedArrayTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/statements/arrays/SealedArrayTest.java @@ -455,7 +455,7 @@ public void testSealedArrayConstrainedMapInvalidIndex() { BRunUtil.invoke(compileResult, "testSealedArrayConstrainedMapInvalidIndex", args); } - @Test(groups = { "disableOnOldParser" }) + @Test() public void testArrayWithConstantSizeReferenceFill() { BRunUtil.invoke(compileResult, "testArrayWithConstantSizeReferenceFill"); } diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/bytetype/BByteValueNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/bytetype/BByteValueNegativeTest.java index 1741d5fcb718..f472813c288d 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/bytetype/BByteValueNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/bytetype/BByteValueNegativeTest.java @@ -77,7 +77,7 @@ public void testByteValueNegative() { BAssertUtil.validateError(result, 22, msg4, 40, 87); } - @Test(description = "Test byte shift operators negative", groups = { "disableOnOldParser" }) + @Test(description = "Test byte shift operators negative") public void invalidByteShiftOperators() { CompileResult result = BCompileUtil.compile("test-src/types/byte/byte-shift-operators-negative.bal"); Assert.assertEquals(result.getErrorCount(), 13); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/integer/BIntegerValueNegativeTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/integer/BIntegerValueNegativeTest.java index 259c9ed265f5..65a56a863520 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/integer/BIntegerValueNegativeTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/integer/BIntegerValueNegativeTest.java @@ -26,7 +26,7 @@ /** * Test class for negative integer tests. */ -@Test(groups = { "disableOnOldParser" }) +@Test() public class BIntegerValueNegativeTest { @Test diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/map/MapAccessExprTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/map/MapAccessExprTest.java index 2633d1d610ba..a2781fa49824 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/map/MapAccessExprTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/map/MapAccessExprTest.java @@ -147,7 +147,7 @@ public void testGetMapValues() { Assert.assertEquals(returns.get(1).toString(), "Colombo"); } - @Test(description = "Map access negative scenarios", groups = {"disableOnOldParser"}) + @Test(description = "Map access negative scenarios") public void testNegativeSemantics() { Assert.assertEquals(resultSemanticsNegative.getDiagnostics().length, 4); int index = 0; diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/var/VarDeclaredAssignmentStmtTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/var/VarDeclaredAssignmentStmtTest.java index 31427964a1dd..2c36efc7c007 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/var/VarDeclaredAssignmentStmtTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/var/VarDeclaredAssignmentStmtTest.java @@ -153,7 +153,7 @@ public void testObjectToVarAssignment2() { BRunUtil.invoke(result, "testObjectToVarAssignment2"); } - @Test(description = "Test var in variable def.", groups = {"disableOnOldParser"}) + @Test(description = "Test var in variable def.") public void testVarTypeInVariableDefStatement() { //var type is not not allowed in variable def statements CompileResult res = BCompileUtil.compile("test-src/types/var/var-type-variable-def-negative.bal"); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLAttributesTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLAttributesTest.java index b17b8efd1c1b..b990c23dcc15 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLAttributesTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLAttributesTest.java @@ -72,8 +72,7 @@ public void testAddAttributeWithEmptyNamespace() { "xmlns:ns3=\"http://sample.com/wso2/f\" foo1=\"bar\"/>"); } - // ToDo: enable after fixing #40373 - @Test(enabled = false) + @Test() public void testAddNamespaceAsAttribute1() { BArray returns = (BArray) BRunUtil.invoke(xmlAttrProgFile, "testAddNamespaceAsAttribute"); Assert.assertTrue(returns.get(0) instanceof BXml); @@ -132,8 +131,7 @@ public void testAddAttributeWithQName_3() { "xmlns:ns5=\"http://sample.com/wso2/f/\" ns5:diff=\"yes\" ns5:foo1=\"bar1\"/>"); } - // ToDo: enable after fixing #40373 - @Test(enabled = false) + @Test() public void testAddAttributeWithQName_5() { Object returns = BRunUtil.invoke(xmlAttrProgFile, "testAddAttributeWithDiffQName_5"); Assert.assertTrue(returns instanceof BXml); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLIterationTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLIterationTest.java index 32fa97298e38..03425577fffe 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLIterationTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLIterationTest.java @@ -181,8 +181,7 @@ public void testXMLChainedIterableOps() { Assert.assertEquals(((BXmlSequence) resArray.getRefValue(1)).getTextValue().toString(), authors[1][0]); } - @Test(groups = {"disableOnOldParser"}, - description = "Test iterating over xml elements where some elements are characters") + @Test(description = "Test iterating over xml elements where some elements are characters") public void testXMLCompoundCharacterSequenceIteration() { Object results = BRunUtil.invoke(result, "xmlSequenceIter"); Assert.assertEquals(result.getDiagnostics().length, 0); @@ -190,8 +189,7 @@ public void testXMLCompoundCharacterSequenceIteration() { Assert.assertEquals(str, "the book\nbit of text\\u2702\\u2705\n"); } - @Test(groups = {"disableOnOldParser"}, - description = "Test iterating over xml sequence where all elements are character items") + @Test(description = "Test iterating over xml sequence where all elements are character items") public void testXMLCharacterSequenceIteration() { Object results = BRunUtil.invoke(result, "xmlCharItemIter"); Assert.assertEquals(result.getDiagnostics().length, 0); diff --git a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralWithNamespacesTest.java b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralWithNamespacesTest.java index 19c662608953..3ba39254c60b 100644 --- a/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralWithNamespacesTest.java +++ b/tests/jballerina-unit-test/src/test/java/org/ballerinalang/test/types/xml/XMLLiteralWithNamespacesTest.java @@ -31,6 +31,7 @@ import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; +import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.io.ByteArrayOutputStream; @@ -178,7 +179,7 @@ public void testObjectLevelXML() { public void xmlWithDefaultNamespaceToString() { Object returns = BRunUtil.invoke(literalWithNamespacesResult, "XMLWithDefaultNamespaceToString"); Assert.assertEquals(returns.toString(), - "\n" + + "\n" + " \n" + " \n" + " \n" + @@ -199,11 +200,6 @@ public void testXMLSerialize() { "hello"); } - @Test - public void testXmlLiteralUsingXmlNamespacePrefix() { - BRunUtil.invoke(literalWithNamespacesResult, "testXmlLiteralUsingXmlNamespacePrefix"); - } - @Test public void testXMLToString() { BXml xml = XmlFactory.parse("" + @@ -211,9 +207,18 @@ public void testXMLToString() { Assert.assertEquals(xml.toString(), "Example"); } - @Test - public void testXmlInterpolationWithQuery() { - BRunUtil.invoke(literalWithNamespacesResult, "testXmlInterpolationWithQuery"); + @Test (dataProvider = "xmlValueFunctions") + public void testXmlStrings(String functionName) { + BRunUtil.invoke(literalWithNamespacesResult, functionName); + } + + @DataProvider(name = "xmlValueFunctions") + private String[] xmlValueFunctions() { + return new String[]{ + "testXmlLiteralUsingXmlNamespacePrefix", + "testXmlInterpolationWithQuery", + "testAddAttributeToDefaultNS" + }; } @AfterClass diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/query/xml-query-expression.bal b/tests/jballerina-unit-test/src/test/resources/test-src/query/xml-query-expression.bal index 70c9bb27170a..c9db31e26b46 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/query/xml-query-expression.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/query/xml-query-expression.bal @@ -1514,6 +1514,53 @@ function testQueryExpressionIteratingOverStreamReturningXMLWithReadonly() { assertEquality(res.toString(), (xml `JohnMike`).toString()); } +function testQueryExpressionXmlStartWithWhiteSpace() { + Person[] personList = [{name: "John", country: "Australia"}, {name: "Mike", country : "Canada"}]; + xml xmlValue = xml ` + + + Dynamic Table + + + + + + + + ${from var {name, country} in personList + select xml ` + + + `} +
NameCountry
${name}${country}
+ + + `; + xml expected = xml ` + + + Dynamic Table + + + + + + + + + + + + + + +
NameCountry
JohnAustralia
MikeCanada
+ + + `; + assertEquality(xmlValue, expected); +} + function assertEquality(any|error actual, any|error expected) { if expected is anydata && actual is anydata && expected == actual { return; diff --git a/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-with-namespaces.bal b/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-with-namespaces.bal index 96cdb12d4820..e79c1010a186 100644 --- a/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-with-namespaces.bal +++ b/tests/jballerina-unit-test/src/test/resources/test-src/types/xml/xml-literals-with-namespaces.bal @@ -1,3 +1,5 @@ +import ballerina/test; + xmlns "http://ballerina.com/b" as ns1; function testElementLiteralWithNamespaces() returns [xml, xml] { @@ -147,7 +149,7 @@ function getXML() returns xml { } function XMLWithDefaultNamespaceToString() returns string { - xml x = xml ` + xml x = xml ` @@ -162,9 +164,7 @@ function testXmlLiteralUsingXmlNamespacePrefix() { xml x1 = xml ``; string s = x1.toString(); string expectedStr = ""; - if (s != expectedStr) { - panic error("Assertion error", expected = expectedStr, found=s); - } + test:assertEquals(s, expectedStr, "XML literal with xml namespace prefix failed"); } xmlns "http://www.so2w.org" as globalNS; @@ -177,9 +177,7 @@ function testXmlInterpolationWithQuery() returns error? { xml x2 = x1/[0]; string s1 = x2.toString(); string expectedStr1 = "1"; - if (s1 != expectedStr1) { - panic error("Assertion error", expected = expectedStr1, found = s1); - } + test:assertEquals(s1, expectedStr1, "XML interpolation with query failed"); xmlns "http://www.so2w.org" as localNS; xml x3 = xml ` @@ -189,17 +187,13 @@ function testXmlInterpolationWithQuery() returns error? { xml x4 = x3/[0]/; string s2 = x4.toString(); string expectedStr2 = "1"; - if (s2 != expectedStr2) { - panic error("Assertion error", expected = expectedStr2, found = s2); - } + test:assertEquals(s2, expectedStr2, "XML interpolation with query failed"); xml x5 = from int i in [1] select xml `${i}`; string s3 = x5.toString(); string expectedStr3 = "1"; - if (s3 != expectedStr3) { - panic error("Assertion error", expected = expectedStr3, found = s3); - } + test:assertEquals(s3, expectedStr3, "XML interpolation with query failed"); xml x6 = xml ` ${from int i in 1 ... 3 @@ -208,9 +202,7 @@ function testXmlInterpolationWithQuery() returns error? { xml x7 = x6/[0]/; string s4 = x7.toString(); string expectedStr4 = "1"; - if (s4 != expectedStr4) { - panic error("Assertion error", expected = expectedStr4, found = s4); - } + test:assertEquals(s4, expectedStr4, "XML interpolation with query failed"); xml x8 = xml ``; from int i in [1] @@ -218,9 +210,7 @@ function testXmlInterpolationWithQuery() returns error? { x8 = xml `${i}`; }; string s5 = x8.toString(); - if (s5 != expectedStr3) { - panic error("Assertion error", expected = expectedStr3, found = s5); - } + test:assertEquals(s5, expectedStr3, "XML interpolation with query failed"); xml x9 = xml ``; from int i in [1] @@ -231,26 +221,20 @@ function testXmlInterpolationWithQuery() returns error? { }; }; string s6 = x9.toString(); - if (s6 != expectedStr3) { - panic error("Assertion error", expected = expectedStr3, found = s6); - } + test:assertEquals(s6, expectedStr3, "XML interpolation with query failed"); xml x10 = from int i in [1] let xml y = xml `${i}` select xml `${y}`; string s7 = x10.toString(); string expectedStr5 = "1"; - if (s7 != expectedStr5) { - panic error("Assertion error", expected = expectedStr3, found = s7); - } + test:assertEquals(s7, expectedStr5, "XML interpolation with query failed"); xml x11 = from xml x in (from int j in [1] select xml `${j}`) select xml `${x}`; string s8 = x11.toString(); - if (s8 != expectedStr5) { - panic error("Assertion error", expected = expectedStr3, found = s7); - } + test:assertEquals(s8, expectedStr5, "XML interpolation with query failed"); xml x12 = from int i in [1] join int j in [1] @@ -259,18 +243,14 @@ function testXmlInterpolationWithQuery() returns error? { select xml `${i}`; string s9 = x12.toString(); string expectedStr6 = "1"; - if (s9 != expectedStr6) { - panic error("Assertion error", expected = expectedStr3, found = s7); - } + test:assertEquals(s9, expectedStr6, "XML interpolation with query failed"); xml expectedXml = xml `1`; xml x13 = from int i in [1] where xml `${i}` == expectedXml select xml `${expectedXml}`; string s10 = x13.toString(); - if (s10 != expectedStr5) { - panic error("Assertion error", expected = expectedStr5, found = s10); - } + test:assertEquals(s10, expectedStr5, "XML interpolation with query failed"); do { xmlns "http://www.so2w1.org" as doNS; @@ -278,9 +258,7 @@ function testXmlInterpolationWithQuery() returns error? { select xml `${i}`; string s11 = x14.toString(); string expectedStr7 = "1"; - if (s11 != expectedStr7) { - panic error("Assertion error", expected = expectedStr7, found = s11); - } + test:assertEquals(s11, expectedStr7, "XML interpolation with query failed"); } do { @@ -289,8 +267,20 @@ function testXmlInterpolationWithQuery() returns error? { select xml `${i}`; string s12 = x15.toString(); string expectedStr8 = "1"; - if (s12 != expectedStr8) { - panic error("Assertion error", expected = expectedStr8, found = s12); - } + test:assertEquals(s12, expectedStr8, "XML interpolation with query failed"); } } + +function testAddAttributeToDefaultNS() { + xml x1 = xml ``; + var xAttr = let var x2 = <'xml:Element>x1 in x2.getAttributes(); + //adding attribute with default namespace + xAttr["{http://sample.com/wso2/c1}foo1"] = "bar1"; + string s = x1.toString(); + string expectedStr = string ``; + test:assertEquals(s, expectedStr, "XML add attribute with default namespace failed"); + + s = xAttr.toString(); + expectedStr = string `{"{http://www.w3.org/2000/xmlns/}xmlns":"http://sample.com/wso2/c1","{http://www.w3.org/2000/xmlns/}ns3":"http://sample.com/wso2/f","{http://sample.com/wso2/c1}foo1":"bar1"}`; + test:assertEquals(s, expectedStr, "XML add attribute with default namespace failed"); +}