Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support union type #20

Merged
merged 13 commits into from
Jun 24, 2024
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.9.0-20240403-114600-ceb51559"
distribution-version = "2201.9.0-20240502-141200-0a49fa42"

[[package]]
org = "ballerina"
Expand Down
80 changes: 2 additions & 78 deletions ballerina/tests/from_json_string_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -1552,7 +1552,7 @@ isolated function testParseStringNegative3() returns Error? {
@test:Config
isolated function testParseStringNegative4() returns Error? {
string str = string `{
name: "John"
"name": "John"
prakanth97 marked this conversation as resolved.
Show resolved Hide resolved
}`;

int|Error x = parseString(str);
Expand All @@ -1561,7 +1561,7 @@ isolated function testParseStringNegative4() returns Error? {

Union|Error y = parseString(str);
test:assertTrue(y is Error);
test:assertEquals((<Error>y).message(), "unsupported type 'ballerina/data.jsondata:0:Union'");
test:assertEquals((<Error>y).message(), "invalid type 'ballerina/data.jsondata:0:Union' expected 'anydata'");

table<RN2>|Error z = parseString(str);
test:assertTrue(z is Error);
Expand Down Expand Up @@ -1592,53 +1592,6 @@ isolated function testProjectionInArrayNegativeForParseString() {
test:assertEquals((<Error>val1).message(), "invalid type 'int' expected 'map type'");
}

@test:Config
isolated function testUnionTypeAsExpTypeForParseStringNegative() {
string str1 = string `[
123,
"Lakshan",
{
"city": "Colombo",
"street": "123",
"zip": 123
},
{
"code": 123,
"subject": "Bio"
}
]`;
(map<anydata>|int|float)[]|Error err1 = parseString(str1);
test:assertTrue(err1 is Error);
test:assertEquals((<Error>err1).message(), "incompatible expected type '(map<anydata>|int|float)' for value 'Lakshan'");

string str2 = string `[
{
"city": "Colombo",
"street": "123",
"zip": 123
},
{
"code": 123,
"subject": "Bio"
}
]`;
(map<anydata>|int|float)[]|Error err2 = parseString(str2);
test:assertTrue(err2 is Error);
test:assertEquals((<Error>err2).message(), "unsupported type '(map<anydata>|int|float)'");

string str3 = string `{
"a": "hello",
"b": 1,
"c": {
"d": "world",
"e": 2
}
}`;
(map<anydata>|int|float)|Error err3 = parseString(str3);
test:assertTrue(err3 is Error);
test:assertEquals((<Error>err3).message(), "unsupported type '(map<anydata>|int|float)'");
}

@test:Config {
dataProvider: dataProviderForSubTypeOfIntNegativeTestForParseString
}
Expand Down Expand Up @@ -1692,35 +1645,6 @@ isolated function testRecordWithRestAsExpectedTypeForParseStringNegative() {
test:assertEquals((<error>val).message(), "incompatible expected type 'int' for value '5.5'");
}

@test:Config
isolated function testComplexTypeAsUnionMemberAsExpTypeNegative() {
string str1 = string `[
{
"p1":"v1",
"p2":1
},
{
"p1":"v2",
"p2":true
}
]`;
T1|error t1 = parseString(str1);
test:assertTrue(t1 is error);
test:assertEquals((<error>t1).message(), "unsupported type '(map<anydata>|int|boolean)'");

string str2 = string `
{
"p1":"v1",
"p2": {
"a": 1,
"b": 2
}
}`;
T2|error t2 = parseString(str2);
test:assertTrue(t2 is error);
test:assertEquals((<error>t2).message(), "unsupported type '(map<anydata>|int)'");
}

@test:Config
isolated function testConvertNonStringValueNegative() {
string|Error err1 = parseString("null");
Expand Down
Loading
Loading