Skip to content

Commit

Permalink
Add toxml test for choice with element annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
SasinduDilshara committed Nov 17, 2024
1 parent c586f4c commit 0f4356c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ function testXsdChoiceWithElementAnnotationWithXmlValue() returns error? {
xmlValue = xml `<Root><EA2>ABC</EA2></Root>`;
v = parseAsType(xmlValue);
test:assertEquals(v, {"seq_EA1":{"EA2": "ABC"}});
// TODO: Empty element
test:assertEquals(toXml(check v), xmlValue);

xmlValue = xml `<Root><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3></Root>`;
Expand All @@ -43,6 +42,7 @@ function testXsdChoiceWithElementAnnotationWithXmlValue() returns error? {
xmlValue = xml `<Root><EA3>AB</EA3><EA3>AB</EA3></Root>`;
v = parseAsType(xmlValue);
test:assertEquals(v, {"seq_EA1":{EA3: ["AB", "AB"]}});
test:assertEquals(toXml(check v), xmlValue);

xmlValue = xml `<Root><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3></Root>`;
v = parseAsType(xmlValue);
Expand All @@ -61,6 +61,7 @@ function testXsdChoiceWithElementAnnotationWithXmlValue() returns error? {
xmlValue = xml `<Root><EA1>ABC</EA1></Root>`;
v = parseAsType(xmlValue);
test:assertEquals(v, {seq_EA1: {EA1: ["ABC"]}});
test:assertEquals(toXml(check v), xmlValue);

xmlValue = xml `<Root><EA2>ABC</EA2><EA3>AB</EA3></Root>`;
v = parseAsType(xmlValue);
Expand Down Expand Up @@ -113,18 +114,22 @@ function testXsdChoiceWithElementAnnotationWithXmlValue2() returns error? {
v = parseAsType(xmlValue);
test:assertEquals(v, {seq_EA2: {EA: {EA1: "ABC", EA2: "ABC", EA3: ["AB", "CD"]}}});
test:assertEquals(toXml(check v), xmlValue);
test:assertEquals(toXml(check v), xmlValue);

xmlValue = xml `<Root><EA><EA2>ABC</EA2><EA3>AB</EA3><EA3>AB</EA3></EA></Root>`;
v = parseAsType(xmlValue);
test:assertEquals(v, {"seq_EA2": {EA: {"EA2": "ABC", EA3: ["AB", "AB"]}}});
test:assertEquals(toXml(check v), xmlValue);

xmlValue = xml `<Root><EA><EA2>ABC</EA2><EA3>AB</EA3><EA3>AB</EA3></EA></Root>`;
v = parseAsType(xmlValue);
test:assertEquals(v, {"seq_EA2": {EA: {"EA2": "ABC", EA3: ["AB", "AB"]}}});
test:assertEquals(toXml(check v), xmlValue);

xmlValue = xml `<Root><EA><EA3>AB</EA3><EA3>AB</EA3></EA></Root>`;
v = parseAsType(xmlValue);
test:assertEquals(v, {"seq_EA2": {EA: {EA3: ["AB", "AB"]}}});
test:assertEquals(toXml(check v), xmlValue);

xmlValue = xml `<Root><EA><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3><EA3>AB</EA3></EA></Root>`;
v = parseAsType(xmlValue);
Expand Down
7 changes: 5 additions & 2 deletions ballerina/tests/xsd_sequence_array_test_with_parse_type.bal
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,12 @@ function testXSDSequenceArrayWithXmlValueRecord4() returns error? {
v2 = parseAsType(xmlValue);
test:assertTrue(v2 is Error);
test:assertEquals((<Error>v2).message(), "'value3' occurs more than the max allowed times");
}

xmlValue = xml `<Root><field1><a>1</a><b>2</b><c>3</c></field1><field2><d>1</d><e>2</e><f>3</f></field2><field3><g>1</g><h>2</h><i>3</i></field3><field4><a>1</a><b>2</b><c>3</c></field4><field5><d>1</d><e>2</e><f>3</f></field5><g>1</g><h>2</h><i>3</i><field6><g>1</g><h>2</h><i>3</i></field6></Root>`;
v2 = parseAsType(xmlValue);
@test:Config {groups: ["xsd", "xsd_sequence"]}
function testXSDSequenceArrayWithXmlValueRecord4P2() returns error? {
xml xmlValue = xml `<Root><field1><a>1</a><b>2</b><c>3</c></field1><field2><d>1</d><e>2</e><f>3</f></field2><field3><g>1</g><h>2</h><i>3</i></field3><field4><a>1</a><b>2</b><c>3</c></field4><field5><d>1</d><e>2</e><f>3</f></field5><g>1</g><h>2</h><i>3</i><field6><g>1</g><h>2</h><i>3</i></field6></Root>`;
XSDSequenceArrayWithXmlValueRecord13|Error v2 = parseAsType(xmlValue);
test:assertTrue(v2 is Error);
test:assertEquals((<Error>v2).message(), "Element(s) 'field6' is not found in 'seq_XSDSequenceArrayWithXmlValueRecord13_2'");

Expand Down

0 comments on commit 0f4356c

Please sign in to comment.