Skip to content

Commit

Permalink
Add types to some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
poorna2152 committed Aug 1, 2024
1 parent 194c2b8 commit 1922024
Showing 1 changed file with 40 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ type XE xml:Element;

function testXmlAttributeAccessOnXmlUnionTypes() {
xml<xml:Element|xml:Text> x1 = xml `<a attr="aa">a</a>`;
assertNonErrorValue(x1.attr, "aa");
assertNonErrorValue(x1?.attr, "aa");
string|error result = x1.attr;
assertNonErrorValue(result, "aa");
string|error? resultOptional = x1?.attr;
assertNonErrorValue(resultOptional, "aa");

xml<xml:Element|xml:Comment> x2 = xml `<b attr="ba">b</b>`;
assertNonErrorValue(x2.attr, "ba");
Expand All @@ -217,40 +219,50 @@ function testXmlAttributeAccessOnXmlUnionTypes() {
assertNonErrorValue(x4?.attr, "da");

xml<xml:Element|xml:Comment|xml:ProcessingInstruction> x5 = xml `<e attr="ea">e</e>`;
assertNonErrorValue(x5.attr, "ea");
assertNonErrorValue(x5?.attr, "ea");
result = x5.attr;
assertNonErrorValue(result, "ea");
resultOptional = x5?.attr;
assertNonErrorValue(resultOptional, "ea");

xml<xml:Element|xml:Comment|xml:Text> x6 = xml `<f attr="fa">f</f>`;
assertNonErrorValue(x6.attr, "fa");
assertNonErrorValue(x6?.attr, "fa");

xml<xml:Element|xml:ProcessingInstruction|xml:Comment|xml:Text> x7 = xml `<g attr="ga">g</g>`;
assertNonErrorValue(x7.attr, "ga");
assertNonErrorValue(x7?.attr, "ga");
result = x7.attr;
assertNonErrorValue(result, "ga");
resultOptional = x7?.attr;
assertNonErrorValue(resultOptional, "ga");

xml:Element|xml:ProcessingInstruction x8 = xml `<h attr="ha">h</h>`;
assertNonErrorValue(x8.attr, "ha");
assertNonErrorValue(x8?.attr, "ha");

xml:Element|xml:Text x9 = xml `<j attr="ja">j</j>`;
assertNonErrorValue(x9.attr, "ja");
assertNonErrorValue(x9?.attr, "ja");
result = x9.attr;
assertNonErrorValue(result, "ja");
resultOptional = x9?.attr;
assertNonErrorValue(resultOptional, "ja");

xml:Element|xml:Comment x10 = xml `<k attr="ka">k</k>`;
assertNonErrorValue(x10.attr, "ka");
assertNonErrorValue(x10?.attr, "ka");

XC|XE x11 = xml `<l attr="la">l</l>`;
assertNonErrorValue(x11.attr, "la");
assertNonErrorValue(x11?.attr, "la");
result = x11.attr;
assertNonErrorValue(result, "la");
resultOptional = x11?.attr;
assertNonErrorValue(resultOptional, "la");
}

function testErrorsOnXmlAttributeAccessOnNonXmlElementValue() {
string errorMessage = "{ballerina/lang.xml}XMLOperationError";

xml:Comment x1 = xml `<!--comment-->`;
assertError(x1.attr, errorMessage, "invalid xml attribute access on xml comment");
assertError(x1?.attr, errorMessage, "invalid xml attribute access on xml comment");
string|error result = x1.attr;
assertError(result, errorMessage, "invalid xml attribute access on xml comment");
string|error? resultOptional = x1?.attr;
assertError(resultOptional, errorMessage, "invalid xml attribute access on xml comment");

xml:Text x2 = xml `text`;
assertError(x2.attr, errorMessage, "invalid xml attribute access on xml text");
Expand All @@ -261,8 +273,10 @@ function testErrorsOnXmlAttributeAccessOnNonXmlElementValue() {
assertError(x3?.attr, errorMessage, "invalid xml attribute access on xml pi");

xml<xml:Comment|xml:Text> x4 = xml `<!--comment-->text`;
assertError(x4.attr, errorMessage, "invalid xml attribute access on xml sequence");
assertError(x4?.attr, errorMessage, "invalid xml attribute access on xml sequence");
result = x4.attr;
assertError(result, errorMessage, "invalid xml attribute access on xml sequence");
resultOptional = x4?.attr;
assertError(resultOptional, errorMessage, "invalid xml attribute access on xml sequence");

xml<xml:Comment|xml:ProcessingInstruction> x5 = xml `<?data?><!--comment-->`;
assertError(x5.attr, errorMessage, "invalid xml attribute access on xml sequence");
Expand All @@ -273,8 +287,10 @@ function testErrorsOnXmlAttributeAccessOnNonXmlElementValue() {
assertError(x6?.attr, errorMessage, "invalid xml attribute access on xml sequence");

xml<xml:Text|xml:ProcessingInstruction|xml:Comment> x7 = xml `<!--comment--><?data?>text`;
assertError(x7.attr, errorMessage, "invalid xml attribute access on xml sequence");
assertError(x7?.attr, errorMessage, "invalid xml attribute access on xml sequence");
result = x7.attr;
assertError(result, errorMessage, "invalid xml attribute access on xml sequence");
resultOptional = x7?.attr;
assertError(resultOptional, errorMessage, "invalid xml attribute access on xml sequence");

xml<xml:Element|xml:Text> x8 = xml `text`;
assertError(x8.attr, errorMessage, "invalid xml attribute access on xml text");
Expand Down Expand Up @@ -310,8 +326,10 @@ function testErrorsOnXmlAttributeAccessOnNonXmlElementValue() {
assertError(x15?.attr, errorMessage, "invalid xml attribute access on xml comment");

XPI x16 = xml `<?data?>`;
assertError(x16.attr, errorMessage, "invalid xml attribute access on xml pi");
assertError(x16?.attr, errorMessage, "invalid xml attribute access on xml pi");
result = x16.attr;
assertError(result, errorMessage, "invalid xml attribute access on xml pi");
resultOptional = x16?.attr;
assertError(resultOptional, errorMessage, "invalid xml attribute access on xml pi");

XT x17 = xml `text`;
assertError(x17.attr, errorMessage, "invalid xml attribute access on xml text");
Expand All @@ -322,8 +340,10 @@ function testErrorsOnXmlAttributeAccessOnNonXmlElementValue() {
assertError(x18?.attr, errorMessage, "invalid xml attribute access on xml comment");

xml:Text|xml:ProcessingInstruction x19 = xml `text`;
assertError(x19.attr, errorMessage, "invalid xml attribute access on xml text");
assertError(x19?.attr, errorMessage, "invalid xml attribute access on xml text");
result = x19.attr;
assertError(result, errorMessage, "invalid xml attribute access on xml text");
resultOptional = x19.attr;
assertError(resultOptional, errorMessage, "invalid xml attribute access on xml text");

xml:ProcessingInstruction|xml:Comment x20 = xml `<?data?>`;
assertError(x20.attr, errorMessage, "invalid xml attribute access on xml pi");
Expand Down

0 comments on commit 1922024

Please sign in to comment.