Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ballerina-platform/ballerina-lang…
Browse files Browse the repository at this point in the history
… into fix-config-compiler-error
  • Loading branch information
HindujaB committed Nov 2, 2023
2 parents be0bbb4 + e57be43 commit 6a89bf0
Show file tree
Hide file tree
Showing 24 changed files with 127 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ private String getXmlNsUriPrefix(Map<String, String> nsPrefixMap, String uri) {
}

private void writeAttributes(HashSet<String> curNSSet, Map<String, String> attributeMap) throws XMLStreamException {
String defaultNS = xmlStreamWriter.getNamespaceContext().getNamespaceURI(XMLNS);
String defaultNS = xmlStreamWriter.getNamespaceContext().getNamespaceURI("");
for (Map.Entry<String, String> attributeEntry : attributeMap.entrySet()) {
String key = attributeEntry.getKey();
int closingCurlyPos = key.lastIndexOf('}');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ private BError createXMLCycleError() {
}

private void mergeAdjoiningTextNodesIntoList(List leftList, List<BXml> 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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*
* @since Swan Lake
*/
@Test(groups = {"disableOnOldParser"})
@Test()
public class OrderByClauseTest {

private CompileResult result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down Expand Up @@ -89,7 +89,7 @@ public void testSimpleQueryExprForXML() {
"<name>Sherlock Holmes</name><name>The Da Vinci Code</name>");
}

@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);
Expand Down Expand Up @@ -149,7 +149,7 @@ public void testSimpleQueryExprForXMLOrNilResult() {
"<name>Sherlock Holmes</name><name>The Da Vinci Code</name>");
}

@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);
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public void testSealedArrayConstrainedMapInvalidIndex() {
BRunUtil.invoke(compileResult, "testSealedArrayConstrainedMapInvalidIndex", args);
}

@Test(groups = { "disableOnOldParser" })
@Test()
public void testArrayWithConstantSizeReferenceFill() {
BRunUtil.invoke(compileResult, "testArrayWithConstantSizeReferenceFill");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/**
* Test class for negative integer tests.
*/
@Test(groups = { "disableOnOldParser" })
@Test()
public class BIntegerValueNegativeTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,15 @@ 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);
String str = results.toString();
Assert.assertEquals(str, "<book>the book</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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -178,7 +179,7 @@ public void testObjectLevelXML() {
public void xmlWithDefaultNamespaceToString() {
Object returns = BRunUtil.invoke(literalWithNamespacesResult, "XMLWithDefaultNamespaceToString");
Assert.assertEquals(returns.toString(),
"<Order xmlns=\"http://acme.company\" xmlns:acme=\"http://acme.company\">\n" +
"<Order xmlns=\"http://acme.company\" xmlns:acme=\"http://acme.company.nondefault\">\n" +
" <OrderLines>\n" +
" <OrderLine acme:lineNo=\"334\" itemCode=\"334-2\"/>\n" +
" </OrderLines>\n" +
Expand All @@ -199,21 +200,25 @@ public void testXMLSerialize() {
"<foo xmlns=\"http://wso2.com/\">hello</foo>");
}

@Test
public void testXmlLiteralUsingXmlNamespacePrefix() {
BRunUtil.invoke(literalWithNamespacesResult, "testXmlLiteralUsingXmlNamespacePrefix");
}

@Test
public void testXMLToString() {
BXml xml = XmlFactory.parse("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<!DOCTYPE foo [<!ELEMENT foo ANY ><!ENTITY data \"Example\" >]><foo>&data;</foo>");
Assert.assertEquals(xml.toString(), "<foo>Example</foo>");
}

@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1514,6 +1514,53 @@ function testQueryExpressionIteratingOverStreamReturningXMLWithReadonly() {
assertEquality(res.toString(), (xml `<person country="Russia">John</person><person country="Germany">Mike</person>`).toString());
}

function testQueryExpressionXmlStartWithWhiteSpace() {
Person[] personList = [{name: "John", country: "Australia"}, {name: "Mike", country : "Canada"}];
xml xmlValue = xml `
<html>
<head>
<title>Dynamic Table</title>
</head>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Country</th>
</tr>
${from var {name, country} in personList
select xml ` <tr>
<th>${name}</th>
<th>${country}</th>
</tr>`}
</table>
</body>
</html>
`;
xml expected = xml `
<html>
<head>
<title>Dynamic Table</title>
</head>
<body>
<table border="1">
<tr>
<th>Name</th>
<th>Country</th>
</tr>
<tr>
<th>John</th>
<th>Australia</th>
</tr> <tr>
<th>Mike</th>
<th>Canada</th>
</tr>
</table>
</body>
</html>
`;
assertEquality(xmlValue, expected);
}

function assertEquality(any|error actual, any|error expected) {
if expected is anydata && actual is anydata && expected == actual {
return;
Expand Down
Loading

0 comments on commit 6a89bf0

Please sign in to comment.