Skip to content

Commit

Permalink
Merge pull request #24 from SasinduDilshara/development-revamp
Browse files Browse the repository at this point in the history
Refactor user configuration parameter
  • Loading branch information
SasinduDilshara authored Aug 12, 2024
2 parents 34bea43 + 40eef57 commit 0d98571
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ function testConstraintWithLists() returns error? {
ConstrainedList|csv:Error cList1 = csv:parseString(string `1
2
3
4`, {header: false, customHeadersIfHeaderAbsent: ["a", "b", "c", "d"]});
4`, {header: false, customHeadersIfHeadersAbsent: ["a", "b", "c", "d"]});
test:assertEquals(cList1, [[1], [2], [3], [4]]);

cList1 = csv:parseString(string `1
2
3
4
5
6`, {header: false, customHeadersIfHeaderAbsent: ["a", "b", "c", "d", "e", "f"]});
6`, {header: false, customHeadersIfHeadersAbsent: ["a", "b", "c", "d", "e", "f"]});
test:assertTrue(cList1 is csv:Error);
test:assertTrue((<error>cList1).message().startsWith("Validation failed")
&& (<error>cList1).message().includes("length"));
Expand All @@ -56,7 +56,7 @@ function testConstraintWithLists() returns error? {
3
4
5
6`, {header: false, customHeadersIfHeaderAbsent: ["a", "b", "c", "d", "e", "f"], enableConstraintValidation: false});
6`, {header: false, customHeadersIfHeadersAbsent: ["a", "b", "c", "d", "e", "f"], enableConstraintValidation: false});
test:assertEquals(cList1, [[1], [2], [3], [4], [5], [6]]);

cList1 = csv:transform([{"a": 1}, {"a": 1}, {"a": 1}, {"a": 1}], {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,119 +450,119 @@ function testArrayIndexes() {

@test:Config
function testParseListsWithOutputHeaders() {
[string, boolean, int][]|csv:Error ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1});
[string, boolean, int][]|csv:Error ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1});
test:assertEquals(ct1bt1, [
["a", true, 1]
]);

ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2});
ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headersRows: 2});
test:assertEquals(ct1bt1, []);

ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]});
ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"]});
test:assertEquals(ct1bt1, [
["a", true, 1]
]);

ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]});
ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"]});
test:assertEquals(ct1bt1, [
["a", true, 1],
["a", true, 1]
]);

ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21});
ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21});
test:assertEquals(ct1bt1, []);

(string|boolean|int)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1});
(string|boolean|int)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1});
test:assertEquals(ct1bt1_2, [
["a", true, 1]
]);

ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2});
ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headersRows: 2});
test:assertEquals(ct1bt1_2, []);

ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]});
ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"]});
test:assertEquals(ct1bt1_2, [
["a", true, 1]
]);

ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]});
ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"]});
test:assertEquals(ct1bt1_2, [
["a", true, 1],
["a", true, 1]
]);

ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21});
ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21});
test:assertEquals(ct1bt1_2, []);

[string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true});
[string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true});
test:assertEquals(ct1bt1_3, [
["a", true, 1],
["a", true, 1]
]);

ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, outputWithHeaders: true});
ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 2, outputWithHeaders: true});
test:assertTrue(ct1bt1_3 is csv:Error);
test:assertEquals((<error>ct1bt1_3).message(), "Custom headers should be provided");

ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, outputWithHeaders: true});
ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headersRows: 2, outputWithHeaders: true});
test:assertTrue(ct1bt1_3 is csv:Error);
test:assertEquals((<error>ct1bt1_3).message(), "Custom headers should be provided");

ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertTrue(ct1bt1_3 is csv:Error);
test:assertEquals((<error>ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean"));

ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertTrue(ct1bt1_3 is csv:Error);
test:assertEquals((<error>ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean"));

ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21, outputWithHeaders: true});
ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21, outputWithHeaders: true});
test:assertEquals(ct1bt1_3, []);

string[][]|csv:Error ct1bt1_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true});
string[][]|csv:Error ct1bt1_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true});
test:assertEquals(ct1bt1_4, [
["a", "b", "c"],
["a", "true", "1"]
]);

ct1bt1_4 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
ct1bt1_4 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt1_4, [
["h1", "h2", "h3"],
["a", "true", "1"],
["a", "true", "1"]
]);

(int|boolean|string)[][]|csv:Error ct1bt1_4_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true});
(int|boolean|string)[][]|csv:Error ct1bt1_4_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true});
test:assertEquals(ct1bt1_4_2, [
["a", "b", "c"],
["a", true, 1]
]);

string[][]|csv:Error ct1bt1_4_3 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
string[][]|csv:Error ct1bt1_4_3 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headersRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt1_4_3, [
["h1", "h2", "h3"],
["a", "true", "1"],
["a", "true", "1"]
]);

(int|boolean|string)[][]|csv:Error ct1bt1_4_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
(int|boolean|string)[][]|csv:Error ct1bt1_4_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt1_4_4, [
["h1", "h2", "h3"]
]);

[string, boolean|string, int|string][]|csv:Error ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
[string, boolean|string, int|string][]|csv:Error ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt1_5, [
["h1", "h2", "h3"],
["a", true, 1]
]);

ct1bt1_5 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
ct1bt1_5 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt1_5, [
["h1", "h2", "h3"],
["a", true, 1]
]);

ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt1_5, [
["h1", "h2", "h3"],
["a", true, 1],
Expand All @@ -575,35 +575,35 @@ function testParseListsWithOutputHeaders() {
["1", "a"]
]);

[string, boolean|string, int|string...][]|csv:Error ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
[string, boolean|string, int|string...][]|csv:Error ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt2_2, [
["h1", "h2", "h3"],
["a", true, 1]
]);

[string...][]|csv:Error ct1bt2_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
[string...][]|csv:Error ct1bt2_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt2_3, [
["h1", "h2", "h3"],
["a", "true", "1"]
]);

ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt2_2, [
["h1", "h2", "h3"],
["a", true, 1],
["a", true, 1]
]);

string[2][1]|csv:Error ct1bt6 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
string[2][1]|csv:Error ct1bt6 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headersRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt6, [
["h1"],
["a"]
]);
[string, boolean|string, int|string...][1]|csv:Error ct1bt6_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
[string, boolean|string, int|string...][1]|csv:Error ct1bt6_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt6_2, [
["h1", "h2", "h3"]
]);
[string...][1]|csv:Error ct1bt6_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
[string...][1]|csv:Error ct1bt6_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true});
test:assertEquals(ct1bt6_3, [
["h1", "h2", "h3"]
]);
Expand Down
Loading

0 comments on commit 0d98571

Please sign in to comment.