Skip to content

Commit

Permalink
Merge pull request #15 from gimantha/toString-cycles
Browse files Browse the repository at this point in the history
Fix tests
  • Loading branch information
mohanvive authored Sep 11, 2020
2 parents 4a9f135 + 0dffd4d commit d535d3a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void testErrorStackTrace() {
BValue[] returns = BRunUtil.invoke(compileResult, "testErrorStackTrace");
assertEquals(returns[0].stringValue(), "5");
assertEquals(returns[1].stringValue(),
"[\"getError:errorlib_test.bal\", \"stack2:errorlib_test.bal\", \"stack1:errorlib_test.bal\", " +
"\"stack0:errorlib_test.bal\", \"testErrorStackTrace:errorlib_test.bal\"]");
"[\"getError:errorlib_test.bal\",\"stack2:errorlib_test.bal\",\"stack1:errorlib_test.bal\"," +
"\"stack0:errorlib_test.bal\",\"testErrorStackTrace:errorlib_test.bal\"]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,41 +133,41 @@ public void testToString() {
Assert.assertEquals(array.getString(i++), "true");
Assert.assertEquals(array.getString(i++), "345.2425341");
Assert.assertEquals(array.getString(i++), "{\"a\":\"STRING\", \"b\":12, \"c\":12.4, \"d\":true, " +
"\"e\":{\"x\":\"x\", \"y\": null}}");
"\"e\":{\"x\":\"x\", \"y\":null}}");
Assert.assertEquals(array.getString(i++),
"<CATALOG>" +
"<CD><TITLE>Empire Burlesque</TITLE><ARTIST>Bob Dylan</ARTIST></CD>" +
"<CD><TITLE>Hide your heart</TITLE><ARTIST>Bonnie Tyler</ARTIST></CD>" +
"<CD><TITLE>Greatest Hits</TITLE><ARTIST>Dolly Parton</ARTIST></CD>" +
"</CATALOG>");
Assert.assertEquals(array.getString(i++), "[\"str\", 23, 23.4, true]");
Assert.assertEquals(array.getString(i++), "[\"str\",23,23.4,true]");
Assert.assertEquals(array.getString(i++), "error FirstError (\"Reason1\", message=\"Test passing error " +
"union to a function\")");
Assert.assertEquals(array.getString(i++), "object Student");
Assert.assertEquals(array.getString(i++), "Rola from MMV");
Assert.assertEquals(array.getString(i++), "[object Student, Rola from MMV]");
Assert.assertEquals(array.getString(i++), "[object Student,Rola from MMV]");
Assert.assertEquals(array.getString(i++),
"{\"name\":\"Gima\", \"address\":{\"country\":\"Sri Lanka\", \"city\":\"Colombo\", " +
"\"street\":\"Palm Grove\"}, \"age\":12}");
Assert.assertEquals(array.getString(i),
"{\"varInt\":6, " +
"\"varFloat\":6.0, " +
"\"varStr\":\"toString\", " +
"\"varNil\": null, " +
"\"varNil\":null, " +
"\"varBool\":true, " +
"\"varDecimal\":345.2425341, " +
"\"varjson\":{\"a\":\"STRING\", \"b\":12, \"c\":12.4, \"d\":true, " +
"\"e\":{\"x\":\"x\", \"y\": null}}, " +
"\"e\":{\"x\":\"x\", \"y\":null}}, " +
"\"varXml\":`<CATALOG><CD><TITLE>Empire Burlesque</TITLE>" +
"<ARTIST>Bob Dylan</ARTIST></CD><CD><TITLE>Hide your heart</TITLE>" +
"<ARTIST>Bonnie Tyler</ARTIST></CD><CD><TITLE>Greatest Hits</TITLE>" +
"<ARTIST>Dolly Parton</ARTIST></CD></CATALOG>`, " +
"\"varArr\":[\"str\", 23, 23.4, true], " +
"\"varArr\":[\"str\",23,23.4,true], " +
"\"varErr\":error FirstError (\"Reason1\", " +
"message=\"Test passing error union to a function\"), " +
"\"varObj\":object Student, " +
"\"varObj2\":Rola from MMV, " +
"\"varObjArr\":[object Student, Rola from MMV], " +
"\"varObjArr\":[object Student,Rola from MMV], " +
"\"varRecord\":{\"name\":\"Gima\", \"address\":{\"country\":\"Sri Lanka\", " +
"\"city\":\"Colombo\", \"street\":\"Palm Grove\"}, \"age\":12}}");
}
Expand Down
52 changes: 26 additions & 26 deletions langlib/langlib-test/src/test/resources/test-src/arraylib_test.bal
Original file line number Diff line number Diff line change
Expand Up @@ -552,13 +552,13 @@ function testSort1() {
});

assertValueEquality(sortedArr[0].toString(),
"{\"id\":20, \"fname\": null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
"{\"id\":20, \"fname\":null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
assertValueEquality(sortedArr[1].toString(),
"{\"id\":10, \"fname\":\"Kate\", \"fee\":NaN, \"impact\":0.146, \"isUndergrad\":false}");
assertValueEquality(sortedArr[2].toString(),
"{\"id\":3, \"fname\":\"Kate\", \"fee\":5000.56, \"impact\":0.4, \"isUndergrad\":false}");
assertValueEquality(sortedArr[3].toString(),
"{\"id\":2, \"fname\":\"Dan\", \"fee\": null, \"impact\":0.3, \"isUndergrad\":true}");
"{\"id\":2, \"fname\":\"Dan\", \"fee\":null, \"impact\":0.3, \"isUndergrad\":true}");
assertValueEquality(sortedArr[4].toString(),
"{\"id\":1, \"fname\":\"Amber\", \"fee\":10000.56, \"impact\":0.127, \"isUndergrad\":true}");
assertValueEquality(studentArr, sortedArr);
Expand All @@ -572,27 +572,27 @@ function testSort1() {
assertValueEquality(sortedArr2[1].toString(),
"{\"id\":3, \"fname\":\"Kate\", \"fee\":5000.56, \"impact\":0.4, \"isUndergrad\":false}");
assertValueEquality(sortedArr2[2].toString(),
"{\"id\":2, \"fname\":\"Dan\", \"fee\": null, \"impact\":0.3, \"isUndergrad\":true}");
"{\"id\":2, \"fname\":\"Dan\", \"fee\":null, \"impact\":0.3, \"isUndergrad\":true}");
assertValueEquality(sortedArr2[3].toString(),
"{\"id\":1, \"fname\":\"Amber\", \"fee\":10000.56, \"impact\":0.127, \"isUndergrad\":true}");
assertValueEquality(sortedArr2[4].toString(),
"{\"id\":20, \"fname\": null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
"{\"id\":20, \"fname\":null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
assertValueEquality(studentArr, sortedArr2);

Student[] sortedArr3 = studentArr.sort(array:ASCENDING, function(Student s) returns float? {
return s.fee;
});

assertValueEquality(sortedArr3[0].toString(),
"{\"id\":20, \"fname\": null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
"{\"id\":20, \"fname\":null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
assertValueEquality(sortedArr3[1].toString(),
"{\"id\":3, \"fname\":\"Kate\", \"fee\":5000.56, \"impact\":0.4, \"isUndergrad\":false}");
assertValueEquality(sortedArr3[2].toString(),
"{\"id\":1, \"fname\":\"Amber\", \"fee\":10000.56, \"impact\":0.127, \"isUndergrad\":true}");
assertValueEquality(sortedArr3[3].toString(),
"{\"id\":10, \"fname\":\"Kate\", \"fee\":NaN, \"impact\":0.146, \"isUndergrad\":false}");
assertValueEquality(sortedArr3[4].toString(),
"{\"id\":2, \"fname\":\"Dan\", \"fee\": null, \"impact\":0.3, \"isUndergrad\":true}");
"{\"id\":2, \"fname\":\"Dan\", \"fee\":null, \"impact\":0.3, \"isUndergrad\":true}");
assertValueEquality(studentArr, sortedArr3);

Student[] sortedArr4 = studentArr.sort(array:ASCENDING, function(Student s) returns decimal {
Expand All @@ -604,11 +604,11 @@ function testSort1() {
assertValueEquality(sortedArr4[1].toString(),
"{\"id\":10, \"fname\":\"Kate\", \"fee\":NaN, \"impact\":0.146, \"isUndergrad\":false}");
assertValueEquality(sortedArr4[2].toString(),
"{\"id\":2, \"fname\":\"Dan\", \"fee\": null, \"impact\":0.3, \"isUndergrad\":true}");
"{\"id\":2, \"fname\":\"Dan\", \"fee\":null, \"impact\":0.3, \"isUndergrad\":true}");
assertValueEquality(sortedArr4[3].toString(),
"{\"id\":3, \"fname\":\"Kate\", \"fee\":5000.56, \"impact\":0.4, \"isUndergrad\":false}");
assertValueEquality(sortedArr4[4].toString(),
"{\"id\":20, \"fname\": null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
"{\"id\":20, \"fname\":null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
assertValueEquality(studentArr, sortedArr4);

Student[] sortedArr5 = studentArr.sort(array:ASCENDING, function(Student s) returns boolean {
Expand All @@ -620,11 +620,11 @@ function testSort1() {
assertValueEquality(sortedArr5[1].toString(),
"{\"id\":3, \"fname\":\"Kate\", \"fee\":5000.56, \"impact\":0.4, \"isUndergrad\":false}");
assertValueEquality(sortedArr5[2].toString(),
"{\"id\":20, \"fname\": null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
"{\"id\":20, \"fname\":null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
assertValueEquality(sortedArr5[3].toString(),
"{\"id\":1, \"fname\":\"Amber\", \"fee\":10000.56, \"impact\":0.127, \"isUndergrad\":true}");
assertValueEquality(sortedArr5[4].toString(),
"{\"id\":2, \"fname\":\"Dan\", \"fee\": null, \"impact\":0.3, \"isUndergrad\":true}");
"{\"id\":2, \"fname\":\"Dan\", \"fee\":null, \"impact\":0.3, \"isUndergrad\":true}");
assertValueEquality(studentArr, sortedArr5);


Expand Down Expand Up @@ -689,11 +689,11 @@ function testSort5() {
assertValueEquality(sortedArr[1].toString(),
"{\"id\":10, \"fname\":\"Kate\", \"fee\":NaN, \"impact\":0.146, \"isUndergrad\":false}");
assertValueEquality(sortedArr[2].toString(),
"{\"id\":2, \"fname\":\"Dan\", \"fee\": null, \"impact\":0.3, \"isUndergrad\":true}");
"{\"id\":2, \"fname\":\"Dan\", \"fee\":null, \"impact\":0.3, \"isUndergrad\":true}");
assertValueEquality(sortedArr[3].toString(),
"{\"id\":1, \"fname\":\"Amber\", \"fee\":10000.56, \"impact\":0.127, \"isUndergrad\":true}");
assertValueEquality(sortedArr[4].toString(),
"{\"id\":20, \"fname\": null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
"{\"id\":20, \"fname\":null, \"fee\":2000.56, \"impact\":0.45, \"isUndergrad\":false}");
assertValueEquality(studentArr, sortedArr);
}

Expand Down Expand Up @@ -726,13 +726,13 @@ function testSort6() {
});

assertValueEquality(sortedArr.toString(),
"[{\"k\":\"Bar\"}, true, 1, 2.0, 3, 12.09, 32, 90, 100, \"AA\", [\"BB\", true]]");
"[{\"k\":\"Bar\"},true,1,2.0,3,12.09,32,90,100,\"AA\",[\"BB\",true]]");
assertValueEquality(arr, sortedArr);

string?[] arr2 = ["Hello", "World!", (), "from", "Ballerina"];

string?[] sortedArr2 = arr2.sort();
assertValueEquality(sortedArr2.toString(), "[\"Ballerina\", \"Hello\", \"World!\", \"from\", null]");
assertValueEquality(sortedArr2.toString(), "[\"Ballerina\",\"Hello\",\"World!\",\"from\",null]");

Obj obj1 = new Obj(1, 1);
Obj obj2 = new Obj(1,2);
Expand All @@ -753,12 +753,12 @@ function testSort6() {
return i;
});

assertValueEquality(sortedArr4.toString(), "[0, 1, 3, 7, 9, 21]");
assertValueEquality(sortedArr4.toString(), "[0,1,3,7,9,21]");

int[] arr5 = [2, 0, 12, 1, 23, 3, 100, 55];

int[] sortedArr5 = arr5.sort(array:DESCENDING);
assertValueEquality(sortedArr5.toString(), "[100, 55, 23, 12, 3, 2, 1, 0]");
assertValueEquality(sortedArr5.toString(), "[100,55,23,12,3,2,1,0]");

string?[] sortedArr6 = arr2.sort(array:DESCENDING, function(string? s) returns string?[]? {
if (s is string) {
Expand All @@ -767,7 +767,7 @@ function testSort6() {
return ();
});

assertValueEquality(sortedArr6.toString(), "[\"from\", \"World!\", \"Hello\", \"Ballerina\", null]");
assertValueEquality(sortedArr6.toString(), "[\"from\",\"World!\",\"Hello\",\"Ballerina\",null]");

string?[] sortedArr7 = arr2.sort(array:ASCENDING, function(string? s) returns string?[] {
if (s is string) {
Expand All @@ -776,18 +776,18 @@ function testSort6() {
return ["W", "A"];
});

assertValueEquality(sortedArr7.toString(), "[\"Ballerina\", \"Hello\", null, \"World!\", \"from\"]");
assertValueEquality(sortedArr7.toString(), "[\"Ballerina\",\"Hello\",null,\"World!\",\"from\"]");

int[] sortedArr8 = arr5.sort(array:ASCENDING, ());
assertValueEquality(sortedArr8.toString(), "[0, 1, 2, 3, 12, 23, 55, 100]");
assertValueEquality(sortedArr8.toString(), "[0,1,2,3,12,23,55,100]");

Grade[] arr6 = ["A+", "B+", "C", "F", "A-", "C", "A+", "B"];

Grade[] sortedArr9 = arr6.sort(array:DESCENDING, function(Grade grade) returns string {
return grade;
});

assertValueEquality(sortedArr9.toString(), "[\"F\", \"C\", \"C\", \"B+\", \"B\", \"A-\", \"A+\", \"A+\"]");
assertValueEquality(sortedArr9.toString(), "[\"F\",\"C\",\"C\",\"B+\",\"B\",\"A-\",\"A+\",\"A+\"]");
assertValueEquality(sortedArr9, arr6);

Student s1 = {id: 1, fname: "Amber", fee: 10000.56, impact: 0.127, isUndergrad: true};
Expand All @@ -808,26 +808,26 @@ function testSort6() {
"{\"id\":1, \"fname\":\"Amber\", \"fee\":10000.56, \"impact\":0.127, \"isUndergrad\":true}");
assertValueEquality(sortedArr10[1].toString(), "Anne");
assertValueEquality(sortedArr10[2].toString(),
"{\"id\":2, \"fname\":\"Dan\", \"fee\": null, \"impact\":0.3, \"isUndergrad\":true}");
"{\"id\":2, \"fname\":\"Dan\", \"fee\":null, \"impact\":0.3, \"isUndergrad\":true}");
assertValueEquality(sortedArr10[3].toString(), "Frank");
assertValueEquality(sortedArr10[4].toString(), "James");
assertValueEquality(sortedArr10[5].toString(),
"{\"id\":10, \"fname\":\"Kate\", \"fee\":NaN, \"impact\":0.146, \"isUndergrad\":false}");
assertValueEquality(sortedArr10, arr7);

int[] sortedArr11 = array:sort(arr5);
assertValueEquality(sortedArr11.toString(), "[0, 1, 2, 3, 12, 23, 55, 100]");
assertValueEquality(sortedArr11.toString(), "[0,1,2,3,12,23,55,100]");
assertValueEquality(sortedArr11, arr5);

int[2]|int[] sortedArr12 = array:sort(arr4, array:DESCENDING, function(int i) returns int {
return i;
});

assertValueEquality(sortedArr12.toString(), "[21, 9, 7, 3, 1, 0]");
assertValueEquality(sortedArr12.toString(), "[21,9,7,3,1,0]");
assertValueEquality(sortedArr12, arr4);

string?[] sortedArr13 = array:sort(arr2, array:DESCENDING);
assertValueEquality(sortedArr13.toString(), "[\"from\", \"World!\", \"Hello\", \"Ballerina\", null]");
assertValueEquality(sortedArr13.toString(), "[\"from\",\"World!\",\"Hello\",\"Ballerina\",null]");
}

function testSort7() {
Expand Down Expand Up @@ -927,13 +927,13 @@ function testSort9() {
strings:Char[] arr = ["s", "a", "b", "M", "Z"];

strings:Char[] sortedArr = arr.sort(array:DESCENDING);
assertValueEquality(sortedArr.toString(), "[\"s\", \"b\", \"a\", \"Z\", \"M\"]");
assertValueEquality(sortedArr.toString(), "[\"s\",\"b\",\"a\",\"Z\",\"M\"]");

int[] arr2 = [4294967295, 4194967295, 4294967290, 4284967295, 3294967295, 1294967295];

int[] sortedArr2 = arr2.sort();
assertValueEquality(sortedArr2.toString(),
"[1294967295, 3294967295, 4194967295, 4284967295, 4294967290, 4294967295]");
"[1294967295,3294967295,4194967295,4284967295,4294967290,4294967295]");

ints:Signed32[] arr3 = [2147483647, -2147483648, 2147483637, -1147483648, -2137483648, 1147483647];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,8 @@ function testAddValidDataWithMapConstrTbl() returns boolean {
PersonAnyTable personTbl = engineerTbl;
Intern intern1 = { name: "John", age: 23, intern: true, salary: 100 };
personTbl.add(intern1);
testPassed = testPassed && personTbl.toString() == "[{\"name\":\"Lisa\", \"age\":22, \"intern\":true}, " +
"{\"name\":\"Jonas\", \"age\":21, \"intern\":false}, {\"name\":\"John\", \"age\":23, \"intern\":true, " +
testPassed = testPassed && personTbl.toString() == "[{\"name\":\"Lisa\", \"age\":22, \"intern\":true}," +
"{\"name\":\"Jonas\", \"age\":21, \"intern\":false},{\"name\":\"John\", \"age\":23, \"intern\":true, " +
"\"salary\":100}]";
return testPassed;
}
Expand Down Expand Up @@ -535,8 +535,8 @@ function testPutValidDataWithMapConstrTbl() returns boolean {
PersonAnyTable personTbl = engineerTbl;
Intern intern1 = { name: "John", age: 23, intern: true, salary: 100 };
personTbl.put(intern1);
testPassed = testPassed && personTbl.toString() == "[{\"name\":\"Lisa\", \"age\":22, \"intern\":true}, " +
"{\"name\":\"Jonas\", \"age\":21, \"intern\":false}, {\"name\":\"John\", \"age\":23, \"intern\":true, " +
testPassed = testPassed && personTbl.toString() == "[{\"name\":\"Lisa\", \"age\":22, \"intern\":true}," +
"{\"name\":\"Jonas\", \"age\":21, \"intern\":false},{\"name\":\"John\", \"age\":23, \"intern\":true, " +
"\"salary\":100}]";
return testPassed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ function testToStringMethodForTable() {
{ id: 2, age: 20, salary: 300.5, name: "John", married: true }
];

assertEquality("[{\"id\":1, \"age\":30, \"salary\":300.5, \"name\":\"Mary\", \"married\":true}, "
assertEquality("[{\"id\":1, \"age\":30, \"salary\":300.5, \"name\":\"Mary\", \"married\":true},"
+ "{\"id\":2, \"age\":20, \"salary\":300.5, \"name\":\"John\", \"married\":true}]", employeeTable.toString());
}

Expand Down Expand Up @@ -945,7 +945,7 @@ function testToStringOnCycles() {
y["1"] = x;
y["2"] = arr;
arr.push(x);
assert(x.toString(), "{\"ee\":3, \"1\":{\"qq\":5, \"1\":..., \"2\":[2, 3, 5, ...]}}");
assert(x.toString(), "{\"ee\":3, \"1\":{\"qq\":5, \"1\":..., \"2\":[2,3,5,...]}}");
}

function assert(anydata actual, anydata expected) {
Expand Down

0 comments on commit d535d3a

Please sign in to comment.