diff --git a/README.md b/README.md index 3381745..4236cc1 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ public function main() returns error? { ### Converting external CSV document to a record value -For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. +For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte block stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. ```ballerina import ballerina/data.csv; @@ -118,7 +118,7 @@ type Book record {| |}; public function main() returns error? { - record{}[] csvContent = [{ + record {}[] csvContent = [{ "name": "Clean Code", "author": "Robert C. Martin", "year": 2008, diff --git a/ballerina-tests/csv-commons/test_utils.bal b/ballerina-tests/csv-commons/test_utils.bal index ef482bf..2609cd9 100644 --- a/ballerina-tests/csv-commons/test_utils.bal +++ b/ballerina-tests/csv-commons/test_utils.bal @@ -35,5 +35,5 @@ public function generateErrorMessageForInvalidHeaders(string value, string 'type } public function generateErrorMessageForInvalidCustomHeader(string header) returns string { - return string `Header '${header}' cannot be find in data rows`; + return string `Header '${header}' cannot be found in data rows`; } diff --git a/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal index 6602f30..a094cdf 100644 --- a/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal +++ b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal @@ -450,107 +450,107 @@ function testArrayIndexes() { @test:Config function testParseListsWithOutputHeaders() { - [string, boolean, int][]|csv:Error ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1}); + [string, boolean, int][]|csv:Error ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); test:assertEquals(ct1bt1, [ ["a", true, 1] ]); - [string, boolean, int][]|[anydata...][]|csv:Error ct1bt1_union = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headersRows: 2}); + [string, boolean, int][]|[anydata...][]|csv:Error ct1bt1_union = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); test:assertTrue(ct1bt1_union is csv:Error); - test:assertEquals((ct1bt1_union).message(), "Custom headers should be provided"); + test:assertEquals((ct1bt1_union).message(), "custom headers should be provided"); - ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1, [ ["a", true, 1] ]); - ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1 = csv:parseList([["a", "true", "1"]], {headersRows: 1}); + ct1bt1 = csv:parseList([["a", "true", "1"]], {headerRows: 1}); test:assertEquals(ct1bt1, []); - (boolean|int|string)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1}); + (boolean|int|string)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); test:assertEquals(ct1bt1_2, [ ["a", true, 1] ]); - ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1_2, [ ["a", true, 1] ]); - ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1_2, [ ["a", true, 1], ["a", true, 1] ]); - [string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true}); + [string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_3, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean")); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean")); - [string, boolean, int|string][]|[anydata...][]|csv:Error ct1bt1_3_with_union = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21, outputWithHeaders: true}); + [string, boolean, int|string][]|[anydata...][]|csv:Error ct1bt1_3_with_union = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21, outputWithHeaders: true}); test:assertTrue(ct1bt1_3_with_union is csv:Error); - test:assertEquals((ct1bt1_3_with_union).message(), "Custom headers should be provided"); + test:assertEquals((ct1bt1_3_with_union).message(), "custom headers should be provided"); - string[][]|csv:Error ct1bt1_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true}); + string[][]|csv:Error ct1bt1_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_4, [ ["a", "b", "c"], ["a", "true", "1"] ]); - ct1bt1_4 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_4 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 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"]], {headersRows: 1, outputWithHeaders: true}); + (int|boolean|string)[][]|csv:Error ct1bt1_4_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 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"]], {headersRows: 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"]], {headerRows: 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"]], {headersRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + (int|boolean|string)[][]|csv:Error ct1bt1_4_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 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"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [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}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - ct1bt1_5 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_5 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 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"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1], @@ -563,35 +563,35 @@ function testParseListsWithOutputHeaders() { ["1", "a"] ]); - [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}); + [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}); test:assertEquals(ct1bt2_2, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - [string...][]|csv:Error ct1bt2_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string...][]|csv:Error ct1bt2_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 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"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 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"]], {headersRows: 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"]], {headerRows: 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"]], {headersRows: 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"]], {headerRows: 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"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string...][1]|csv:Error ct1bt6_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt6_3, [ ["h1", "h2", "h3"] ]); diff --git a/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_record_test.bal b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_record_test.bal index f51feb6..79162d7 100644 --- a/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_record_test.bal +++ b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_record_test.bal @@ -502,13 +502,13 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType6() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { - record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "c", "b"]}); + record {string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - record{() a; float b; decimal c; boolean d; int e; string f;}[]|csv:Error ct1br6 = csv:parseList( + record {() a; float b; decimal c; boolean d; int e; string f;}[]|csv:Error ct1br6 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br6, [ @@ -516,7 +516,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|decimal c; boolean d; int e; string f;|}[]|csv:Error ct1br7 = csv:parseList( + record {|decimal c; boolean d; int e; string f;|}[]|csv:Error ct1br7 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br7, [ @@ -524,7 +524,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {c: 2.23, d: true, e: 1, f: "a"} ]); - record{decimal c; boolean d; int e; string f;}[]|csv:Error ct1br8 = csv:parseList( + record {decimal c; boolean d; int e; string f;}[]|csv:Error ct1br8 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br8, [ @@ -532,7 +532,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|int|() a; float b; decimal? c; boolean d; int e; string f; string...;|}[]|csv:Error ct1br9 = csv:parseList( + record {|int|() a; float b; decimal? c; boolean d; int e; string f; string...;|}[]|csv:Error ct1br9 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br9, [ @@ -540,7 +540,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|int|() a; float b; decimal? c; string|boolean d; int|string e; string f; string...;|}[]|csv:Error ct1br9_2 = csv:parseList( + record {|int|() a; float b; decimal? c; string|boolean d; int|string e; string f; string...;|}[]|csv:Error ct1br9_2 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br9_2, [ @@ -548,7 +548,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: "true", e: 1, f: "a"} ]); - record{|int|() a; float b; decimal? c; boolean|string d; int|string e; string f; string...;|}[]|csv:Error ct1br9_3 = csv:parseList( + record {|int|() a; float b; decimal? c; boolean|string d; int|string e; string f; string...;|}[]|csv:Error ct1br9_3 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br9_3, [ @@ -559,81 +559,81 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { - record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 0, customHeaders: ["a", "c", "b"]}); + record {string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 0, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - record{string a; boolean b; int c;}[]|csv:Error ct1br4_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"]}); + record {string a; boolean b; int c;}[]|csv:Error ct1br4_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4_2, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - record{string a; boolean b; int c;}[]|csv:Error ct1br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"]}); + record {string a; boolean b; int c;}[]|csv:Error ct1br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4_3, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - record{string a; boolean b; int c;}[]|csv:Error ct1br4_4 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); + record {string a; boolean b; int c;}[]|csv:Error ct1br4_4 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4_4, [ {a: "a", b: true, c: 1} ]); - record{string a; boolean b; int c;}[]|record{}[]|csv:Error ct1br4_5 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2}); + record {string a; boolean b; int c;}[]|record {}[]|csv:Error ct1br4_5 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2}); test:assertTrue(ct1br4_5 is csv:Error); - test:assertEquals((ct1br4_5).message(), "Custom headers should be provided"); + test:assertEquals((ct1br4_5).message(), "custom headers should be provided"); - record{|string a; boolean b; int...;|}[]|csv:Error ct1br4_4_2 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); + record {|string a; boolean b; int...;|}[]|csv:Error ct1br4_4_2 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4_4_2, [ {a: "a", b: true, c: 1} ]); - record{|string a; boolean b; int...;|}[]|record{}[]|csv:Error ct1br4_5_2 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2}); + record {|string a; boolean b; int...;|}[]|record {}[]|csv:Error ct1br4_5_2 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2}); test:assertTrue(ct1br4_5_2 is csv:Error); - test:assertEquals((ct1br4_5).message(), "Custom headers should be provided"); + test:assertEquals((ct1br4_5).message(), "custom headers should be provided"); - map[]|csv:Error ct2br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"]}); + map[]|csv:Error ct2br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_3, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - map[]|csv:Error ct2br4_3_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 3, customHeaders: ["a", "c", "b"]}); + map[]|csv:Error ct2br4_3_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 3, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_3_2, []); map[]|csv:Error ct2br4_4 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_4, [ {a: "a", b: true, c: 1} ]); map[]|csv:Error ct2br4_5 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_5, [ {a: "a", b: "true", c: "1"}, {a: "a", b: "true", c: "1"} ]); - map[]|record{}[]|csv:Error ct2br4_7 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 4, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + map[]|record {}[]|csv:Error ct2br4_7 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 4, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); test:assertEquals(ct2br4_7, []); - map[]|record{}[]|csv:Error ct2br4_6 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, outputWithHeaders: true}); + map[]|record {}[]|csv:Error ct2br4_6 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, outputWithHeaders: true}); test:assertTrue(ct2br4_6 is csv:Error); - test:assertEquals((ct1br4_5).message(), "Custom headers should be provided"); + test:assertEquals((ct1br4_5).message(), "custom headers should be provided"); map[]|csv:Error ct2br4_8 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1}); test:assertEquals(ct2br4_8, [ {"a": "a", "1": "1", "true": "true"}, {"a": "a", "1": "1", "true": "true"}, @@ -641,7 +641,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_8_2 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1}); test:assertEquals(ct2br4_8_2, [ {"a": "a", "1": "1", "true": "true"}, {"a": "a", "1": "1", "true": "true"}, @@ -649,7 +649,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_9 = csv:parseList( - [["a", "c", "b"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1}); + [["a", "c", "b"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1}); test:assertEquals(ct2br4_9, [ {a: "a", b: "true", c: "2"}, {a: "a", b: "true", c: "3"}, @@ -658,7 +658,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_10 = csv:parseList( - [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1}); + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1}); test:assertEquals(ct2br4_10, [ {a: "a", c: true, b: 2}, {a: "a", c: true, b: 3}, @@ -667,7 +667,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_10_2 = csv:parseList( - [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1}); + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1}); test:assertEquals(ct2br4_10_2, [ {a: "a", c: true, b: 2}, {a: "a", c: true, b: 3}, @@ -675,8 +675,8 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { {a: "a", c: true, b: 5} ]); - map[]|record{}[]|csv:Error ct2br4_10_3 = csv:parseList( - [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1, customHeaders: ["c", "d", "e"], outputWithHeaders: false}); + map[]|record {}[]|csv:Error ct2br4_10_3 = csv:parseList( + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1, customHeaders: ["c", "d", "e"], outputWithHeaders: false}); test:assertEquals(ct2br4_10_3, [ {c: "a", e: true, d: 2}, {c: "a", e: true, d: 3}, @@ -687,7 +687,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { - record{|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseList( + record {|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br10, [ @@ -695,7 +695,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {a: "()", b: "0", c: 2.23, d: true, e: 1, f: "a"} ]); - record{|decimal? c; boolean d; int? e; string f; ()...;|}[]|csv:Error ct1br11 = csv:parseList( + record {|decimal? c; boolean d; int? e; string f; ()...;|}[]|csv:Error ct1br11 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br11, [ @@ -703,7 +703,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {a: (), c: 2.23, d: true, e: 1, f: "a"} ]); - record{|()...;|}[]|csv:Error ct1br12 = csv:parseList( + record {|()...;|}[]|csv:Error ct1br12 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br12, [ @@ -711,7 +711,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {a: ()} ]); - record{|string?...;|}[]|csv:Error ct1br13 = csv:parseList( + record {|string?...;|}[]|csv:Error ct1br13 = csv:parseList( [["a", "1"], ["a", "1"]], {customHeaders: ["f", "e"]}); test:assertEquals(ct1br13, [ @@ -719,7 +719,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {e: "1", f: "a"} ]); - record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseList( + record {|boolean...;|}[]|csv:Error ct1br14 = csv:parseList( [["2.23", "null"], ["7", "()"]], {customHeaders: ["b", "a"]}); test:assertEquals(ct1br14, [ @@ -736,7 +736,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {e: 2, f: ()} ]); - record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseList( + record {|boolean...;|}[]|csv:Error ct1br16 = csv:parseList( [["2.23", "null"], ["7", "()"]], {customHeaders: ["b", "a"]}); test:assertEquals(ct1br16, [ diff --git a/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal index 3a50795..b2bc041 100644 --- a/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal @@ -14,11 +14,11 @@ // specific language governing permissions and limitations // under the License. -string s1 = "string"; -string s2 = ""; -string:Char s3 = "a"; +final string s1 = "string"; +final string s2 = ""; +final string:Char s3 = "a"; -[string, string] st1 = [s1, s2]; -[string, string, string, string] st2 = [s1, s2, s3, s2]; -[string...] st3 = [s1, s2]; -[string, string, string...] st4 = [s1, s2, s3, s2]; +final [string, string] st1 = [s1, s2]; +final [string, string, string, string] st2 = [s1, s2, s3, s2]; +final [string...] st3 = [s1, s2]; +final [string, string, string...] st4 = [s1, s2, s3, s2]; diff --git a/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal b/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal index 23a4317..51a1840 100644 --- a/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal +++ b/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal @@ -20,105 +20,105 @@ import ballerina/test; @test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType() { - BooleanArrayArray|csv:Error bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm1ba = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, BooleanArrayArray); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b2", "b1"]}, BooleanArrayArray); + bm1ba = csv:transform([bm1, bm1], {headerOrder: ["b2", "b1"]}, BooleanArrayArray); test:assertEquals(bm1ba, [ [false, true], [false, true] ]); - BooleanArrayArray|csv:Error bm2ba = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm2ba = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanArrayArray); test:assertTrue(bm2ba is csv:Error); test:assertEquals((bm2ba).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanArrayArray|csv:Error bm3ba = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm3ba = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanArrayArray); test:assertTrue(bm3ba is csv:Error); test:assertEquals((bm3ba).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanArrayArray|csv:Error bm4ba = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm4ba = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, BooleanArrayArray); test:assertTrue(bm4ba is csv:Error); test:assertEquals((bm4ba).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanArrayArray|csv:Error bm5ba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm5ba = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, BooleanArrayArray); test:assertTrue(bm5ba is csv:Error); test:assertEquals((bm5ba).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - NillableBooleanArrayArray|csv:Error bm1nba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm1nba = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableBooleanArrayArray); test:assertEquals(bm1nba, [ [true, false], [true, false] ]); - NillableBooleanArrayArray|csv:Error bm2nba = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm2nba = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanArrayArray); test:assertEquals(bm2nba, [ [true, false, null, null, null], [true, false, null, null, null] ]); - NillableBooleanArrayArray|csv:Error bm3nba = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm3nba = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanArrayArray); test:assertTrue(bm3nba is csv:Error); test:assertEquals((bm3nba).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanArrayArray|csv:Error bm4nba = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm4nba = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableBooleanArrayArray); test:assertEquals(bm4nba, [ [(), ()], [(), ()] ]); - NillableBooleanArrayArray|csv:Error bm5nba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm5nba = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanArrayArray); test:assertEquals(bm5nba, [ [true, false, (), true], [true, false, (), true] ]); - bm5nba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b3", "b2", "b4"]}, NillableBooleanArrayArray); + bm5nba = csv:transform([bm5, bm5], {headerOrder: ["b1", "b3", "b2", "b4"]}, NillableBooleanArrayArray); test:assertEquals(bm5nba, [ [true, (), false, true], [true, (), false, true] ]); - bm5nba = csv:transform([bm5, bm5], {headersOrder: ["b4", "b3", "b2", "b1"]}, NillableBooleanArrayArray); + bm5nba = csv:transform([bm5, bm5], {headerOrder: ["b4", "b3", "b2", "b1"]}, NillableBooleanArrayArray); test:assertEquals(bm5nba, [ [true, (), false, true], [true, (), false, true] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm1niouba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm1niouba = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm1niouba, [ [true, false], [true, false] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm2niouba = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm2niouba = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm2niouba, [ [true, false, null, null, null], [true, false, null, null, null] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm3niouba = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm3niouba = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm3niouba, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm4niouba = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm4niouba = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm4niouba, [ [(), ()], [(), ()] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm5niouba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm5niouba = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm5niouba, [ [true, false, (), true], [true, false, (), true] ]); - JsonArray1Array|csv:Error bm1ja = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, JsonArray1Array); + JsonArray1Array|csv:Error bm1ja = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, JsonArray1Array); test:assertEquals(bm1ja, [ [true, false], [true, false] @@ -127,261 +127,261 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { @test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType2() { - JsonArray1Array|csv:Error bm2ja = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, JsonArray1Array); + JsonArray1Array|csv:Error bm2ja = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, JsonArray1Array); test:assertEquals(bm2ja, [ [true, false, null, null, null], [true, false, null, null, null] ]); - JsonArray1Array|csv:Error bm3ja = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, JsonArray1Array); + JsonArray1Array|csv:Error bm3ja = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, JsonArray1Array); test:assertEquals(bm3ja, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - JsonArray1Array|csv:Error bm4ja = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, JsonArray1Array); + JsonArray1Array|csv:Error bm4ja = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, JsonArray1Array); test:assertEquals(bm4ja, [ [(), ()], [(), ()] ]); - JsonArray1Array|csv:Error bm5ja = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, JsonArray1Array); + JsonArray1Array|csv:Error bm5ja = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, JsonArray1Array); test:assertEquals(bm5ja, [ [true, false, (), true], [true, false, (), true] ]); - AnydataArray1Array|csv:Error bm1anyda = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm1anyda = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, AnydataArray1Array); test:assertEquals(bm1anyda, [ [true, false], [true, false] ]); - AnydataArray1Array|csv:Error bm2anyda = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm2anyda = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, AnydataArray1Array); test:assertEquals(bm2anyda, [ [true, false, null, null, null], [true, false, null, null, null] ]); - AnydataArray1Array|csv:Error bm3anyda = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm3anyda = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, AnydataArray1Array); test:assertEquals(bm3anyda, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - AnydataArray1Array|csv:Error bm4anyda = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm4anyda = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, AnydataArray1Array); test:assertEquals(bm4anyda, [ [(), ()], [(), ()] ]); - AnydataArray1Array|csv:Error bm5anyda = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm5anyda = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, AnydataArray1Array); test:assertEquals(bm5anyda, [ [true, false, (), true], [true, false, (), true] ]); - StringArray1Array|csv:Error bm1sa = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, StringArray1Array); + StringArray1Array|csv:Error bm1sa = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, StringArray1Array); test:assertTrue(bm1sa is csv:Error); test:assertEquals((bm1sa).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|csv:Error bm2sa = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, StringArray1Array); + StringArray1Array|csv:Error bm2sa = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, StringArray1Array); test:assertTrue(bm2sa is csv:Error); test:assertEquals((bm2sa).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|csv:Error bm3sa = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, StringArray1Array); + StringArray1Array|csv:Error bm3sa = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, StringArray1Array); test:assertTrue(bm3sa is csv:Error); test:assertEquals((bm3sa).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|csv:Error bm4sa = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, StringArray1Array); + StringArray1Array|csv:Error bm4sa = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, StringArray1Array); test:assertTrue(bm4sa is csv:Error); test:assertEquals((bm4sa).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - StringArray1Array|csv:Error bm5sa = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, StringArray1Array); + StringArray1Array|csv:Error bm5sa = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, StringArray1Array); test:assertTrue(bm5sa is csv:Error); test:assertEquals((bm5sa).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } @test:Config function testFromCsvWithTypeForMapAndTupleAsExpectedType() { - BooleanTuple1Array|csv:Error bm1bt = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm1bt = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, BooleanTuple1Array); test:assertEquals(bm1bt, [ [true, false, false, false], [true, false, false, false] ]); - BooleanTuple1Array|csv:Error bm2bt = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm2bt = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple1Array); test:assertTrue(bm2bt is csv:Error); test:assertEquals((bm2bt).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple1Array|csv:Error bm3bt = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm3bt = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple1Array); test:assertTrue(bm3bt is csv:Error); test:assertEquals((bm3bt).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple1Array|csv:Error bm4bt = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm4bt = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, BooleanTuple1Array); test:assertTrue(bm4bt is csv:Error); test:assertEquals((bm4bt).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple1Array|csv:Error bm5bt = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm5bt = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple1Array); test:assertTrue(bm5bt is csv:Error); test:assertEquals((bm5bt).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple2Array|csv:Error bm1b2t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm1b2t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, BooleanTuple2Array); test:assertEquals(bm1b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error bm2b2t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm2b2t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple2Array); test:assertEquals(bm2b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error bm3b2t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm3b2t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple2Array); test:assertEquals(bm3b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error bm4b2t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm4b2t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, BooleanTuple2Array); test:assertTrue(bm4b2t is csv:Error); test:assertEquals((bm4b2t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple2Array|csv:Error bm5b2t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm5b2t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple2Array); test:assertEquals(bm5b2t, [ [true, false], [true, false] ]); - BooleanTuple3Array|csv:Error bm1b3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm1b3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, BooleanTuple3Array); test:assertEquals(bm1b3t, [ [true, false], [true, false] ]); - BooleanTuple3Array|csv:Error bm2b3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm2b3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple3Array); test:assertTrue(bm2b3t is csv:Error); test:assertEquals((bm2b3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple3Array|csv:Error bm3b3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm3b3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple3Array); test:assertTrue(bm3b3t is csv:Error); test:assertEquals((bm3b3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple3Array|csv:Error bm4b3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm4b3t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, BooleanTuple3Array); test:assertTrue(bm4b3t is csv:Error); test:assertEquals((bm4b3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple3Array|csv:Error bm5b3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm5b3t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple3Array); test:assertTrue(bm5b3t is csv:Error); test:assertEquals((bm5b3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple4Array|csv:Error bm1b4t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm1b4t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, BooleanTuple4Array); test:assertEquals(bm1b4t, [ [true, false], [true, false] ]); - BooleanTuple4Array|csv:Error bm2b4t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm2b4t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple4Array); test:assertTrue(bm2b4t is csv:Error); test:assertEquals((bm2b4t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); } @test:Config function testFromCsvWithTypeForMapAndTupleAsExpectedType2() { - BooleanTuple4Array|csv:Error bm3b4t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm3b4t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple4Array); test:assertTrue(bm3b4t is csv:Error); test:assertEquals((bm3b4t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple4Array|csv:Error bm4b4t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm4b4t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, BooleanTuple4Array); test:assertTrue(bm4b4t is csv:Error); test:assertEquals((bm4b4t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple4Array|csv:Error bm5b4t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm5b4t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple4Array); test:assertTrue(bm5b4t is csv:Error); test:assertEquals((bm5b4t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - NillableBooleanTuple5Array|csv:Error bm1nbt = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm1nbt = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableBooleanTuple5Array); test:assertEquals(bm1nbt, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple5Array|csv:Error bm2nbt = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm2nbt = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple5Array); test:assertEquals(bm2nbt, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple5Array|csv:Error bm3nbt = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm3nbt = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple5Array); test:assertTrue(bm3nbt is csv:Error); test:assertEquals((bm3nbt).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple5Array|csv:Error bm4nbt = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm4nbt = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableBooleanTuple5Array); test:assertEquals(bm4nbt, [ [(), (), (), (), ()], [(), (), (), (), ()] ]); - NillableBooleanTuple5Array|csv:Error bm5nbt = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm5nbt = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple5Array); test:assertEquals(bm5nbt, [ [true, false, (), true, ()], [true, false, (), true, ()] ]); - NillableBooleanTuple6Array|csv:Error bm1nb6t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm1nb6t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableBooleanTuple6Array); test:assertEquals(bm1nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error bm2nb6t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm2nb6t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple6Array); test:assertEquals(bm2nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error bm3nb6t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm3nb6t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple6Array); test:assertEquals(bm3nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error bm4nb6t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm4nb6t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableBooleanTuple6Array); test:assertEquals(bm4nb6t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple6Array|csv:Error bm5nb6t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm5nb6t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple6Array); test:assertEquals(bm5nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple7Array|csv:Error bm1nb7t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm1nb7t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableBooleanTuple7Array); test:assertEquals(bm1nb7t, [ [true, false], [true, false] ]); - NillableBooleanTuple7Array|csv:Error bm2nb7t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm2nb7t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple7Array); test:assertEquals(bm2nb7t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple7Array|csv:Error bm3nb7t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm3nb7t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple7Array); test:assertTrue(bm3nb7t is csv:Error); test:assertEquals((bm3nb7t).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple7Array|csv:Error bm4nb7t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm4nb7t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableBooleanTuple7Array); test:assertEquals(bm4nb7t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple7Array|csv:Error bm5nb7t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm5nb7t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple7Array); test:assertEquals(bm5nb7t, [ [true, false, (), true], [true, false, (), true] @@ -390,83 +390,83 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType2() { @test:Config function testFromCsvWithTypeForMapAndTupleAsExpectedType3() { - NillableBooleanTuple8Array|csv:Error bm1nb8t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm1nb8t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableBooleanTuple8Array); test:assertEquals(bm1nb8t, [ [true, false], [true, false] ]); - NillableBooleanTuple8Array|csv:Error bm2nb8t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm2nb8t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple8Array); test:assertEquals(bm2nb8t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple8Array|csv:Error bm3nb8t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm3nb8t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple8Array); test:assertTrue(bm3nb8t is csv:Error); test:assertEquals((bm3nb8t).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple8Array|csv:Error bm4nb8t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm4nb8t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableBooleanTuple8Array); test:assertEquals(bm4nb8t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple8Array|csv:Error bm5nb8t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm5nb8t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple8Array); test:assertEquals(bm5nb8t, [ [true, false, (), true], [true, false, (), true] ]); - NillableIntBooleanTuple9Array|csv:Error bm1nb9t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm1nb9t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm1nb9t, [ [true, false], [true, false] ]); - NillableIntBooleanTuple9Array|csv:Error bm2nb9t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm2nb9t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm2nb9t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableIntBooleanTuple9Array|csv:Error bm3nb9t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm3nb9t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm3nb9t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - NillableIntBooleanTuple9Array|csv:Error bm4nb9t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm4nb9t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm4nb9t, [ [(), ()], [(), ()] ]); - NillableIntBooleanTuple9Array|csv:Error bm5nb9t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm5nb9t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm5nb9t, [ [true, false, (), true], [true, false, (), true] ]); - NilTuple3Array|csv:Error bm1n3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NilTuple3Array); + NilTuple3Array|csv:Error bm1n3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NilTuple3Array); test:assertTrue(bm1n3t is csv:Error); test:assertEquals((bm1n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|csv:Error bm2n3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NilTuple3Array); + NilTuple3Array|csv:Error bm2n3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NilTuple3Array); test:assertTrue(bm2n3t is csv:Error); test:assertEquals((bm2n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|csv:Error bm3n3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NilTuple3Array); + NilTuple3Array|csv:Error bm3n3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NilTuple3Array); test:assertTrue(bm3n3t is csv:Error); test:assertEquals((bm3n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|csv:Error bm4n3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NilTuple3Array); + NilTuple3Array|csv:Error bm4n3t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NilTuple3Array); test:assertEquals(bm4n3t, [ [(), ()], [(), ()] ]); - NilTuple3Array|csv:Error bm5n3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NilTuple3Array); + NilTuple3Array|csv:Error bm5n3t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NilTuple3Array); test:assertTrue(bm5n3t is csv:Error); test:assertEquals((bm5n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); } @@ -474,83 +474,83 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType3() { @test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType3() { - AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"], outputWithHeaders: false}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"], outputWithHeaders: false}, AnydataTuple3Array); test:assertEquals(bm1anyd3t, [ [true, false], [true, false] ]); - AnydataTuple3Array|csv:Error bm2anyd3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm2anyd3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, AnydataTuple3Array); test:assertEquals(bm2anyd3t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - AnydataTuple3Array|csv:Error bm3anyd3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm3anyd3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, AnydataTuple3Array); test:assertEquals(bm3anyd3t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - AnydataTuple3Array|csv:Error bm4anyd3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"], outputWithHeaders: false}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm4anyd3t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"], outputWithHeaders: false}, AnydataTuple3Array); test:assertEquals(bm4anyd3t, [ [(), ()], [(), ()] ]); - AnydataTuple3Array|csv:Error bm5anyd3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm5anyd3t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, AnydataTuple3Array); test:assertEquals(bm5anyd3t, [ [true, false, (), true], [true, false, (), true] ]); - JsonTuple3Array|csv:Error bm1j3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm1j3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, JsonTuple3Array); test:assertEquals(bm1j3t, [ [true, false], [true, false] ]); - JsonTuple3Array|csv:Error bm2j3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm2j3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, JsonTuple3Array); test:assertEquals(bm2j3t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - JsonTuple3Array|csv:Error bm3j3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm3j3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, JsonTuple3Array); test:assertEquals(bm3j3t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - JsonTuple3Array|csv:Error bm4j3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm4j3t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, JsonTuple3Array); test:assertEquals(bm4j3t, [ [(), ()], [(), ()] ]); - JsonTuple3Array|csv:Error bm5j3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm5j3t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, JsonTuple3Array); test:assertEquals(bm5j3t, [ [true, false, (), true], [true, false, (), true] ]); - StringTuple3Array|csv:Error bm1s3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, StringTuple3Array); + StringTuple3Array|csv:Error bm1s3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, StringTuple3Array); test:assertTrue(bm1s3t is csv:Error); test:assertEquals((bm1s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|csv:Error bm2s3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, StringTuple3Array); + StringTuple3Array|csv:Error bm2s3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, StringTuple3Array); test:assertTrue(bm2s3t is csv:Error); test:assertEquals((bm2s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|csv:Error bm3s3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, StringTuple3Array); + StringTuple3Array|csv:Error bm3s3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, StringTuple3Array); test:assertTrue(bm3s3t is csv:Error); test:assertEquals((bm3s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|csv:Error bm4s3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, StringTuple3Array); + StringTuple3Array|csv:Error bm4s3t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, StringTuple3Array); test:assertTrue(bm4s3t is csv:Error); test:assertEquals((bm4s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - StringTuple3Array|csv:Error bm5s3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, StringTuple3Array); + StringTuple3Array|csv:Error bm5s3t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, StringTuple3Array); test:assertTrue(bm5s3t is csv:Error); test:assertEquals((bm5s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } @@ -559,7 +559,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType3() { function testArrayIndexes() { map[] csv = [{a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}, {a: 7, b: 8}]; - int[][2]|csv:Error rec3 = csv:transform(csv, {headersOrder: ["a", "b"]}); + int[][2]|csv:Error rec3 = csv:transform(csv, {headerOrder: ["a", "b"]}); test:assertEquals(rec3, [ [1, 2], [3, 4], @@ -567,13 +567,13 @@ function testArrayIndexes() { [7, 8] ]); - [int...][2]|csv:Error rec3_3 = csv:transform(csv, {headersOrder: ["a", "b"], skipLines: [1]}); + [int...][2]|csv:Error rec3_3 = csv:transform(csv, {headerOrder: ["a", "b"], skipLines: [1]}); test:assertEquals(rec3_3, [ [3, 4], [5, 6] ]); - int[1][2]|csv:Error rec4 = csv:transform(csv, {headersOrder: ["a", "b"], skipLines: [2]}); + int[1][2]|csv:Error rec4 = csv:transform(csv, {headerOrder: ["a", "b"], skipLines: [2]}); test:assertEquals(rec4, [ [1, 2] ]); @@ -581,58 +581,58 @@ function testArrayIndexes() { @test:Config function testParseRecordsAsListsWithHeaderOutput() { - AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"], outputWithHeaders: true}); + AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"], outputWithHeaders: true}); test:assertEquals(bm1anyd3t, [ ["b1", "b2"], [true, false], [true, false] ]); - AnydataTuple3Array|csv:Error bm2anyd3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: true}); + AnydataTuple3Array|csv:Error bm2anyd3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: true}); test:assertEquals(bm2anyd3t, [ ["b1", "b2", "b3", "n1", "n3"], [true, false, (), (), ()], [true, false, (), (), ()] ]); - AnydataTuple3Array|csv:Error bm3anyd3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"], outputWithHeaders: true}); + AnydataTuple3Array|csv:Error bm3anyd3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"], outputWithHeaders: true}); test:assertEquals(bm3anyd3t, [ ["b1", "b2", "b3", "b4", "i1"], [true, false, (), false, 1], [true, false, (), false, 1] ]); - anydata[][]|csv:Error bm1anyd3t_2 = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"], outputWithHeaders: true}); + anydata[][]|csv:Error bm1anyd3t_2 = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"], outputWithHeaders: true}); test:assertEquals(bm1anyd3t_2, [ ["b1", "b2"], [true, false], [true, false] ]); - anydata[][]|csv:Error bm2anyd3t_2 = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: true}); + anydata[][]|csv:Error bm2anyd3t_2 = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: true}); test:assertEquals(bm2anyd3t_2, [ ["b1", "b2", "b3", "n1", "n3"], [true, false, (), (), ()], [true, false, (), (), ()] ]); - anydata[2][3]|csv:Error bm3anyd3t_2 = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"], outputWithHeaders: true}); + anydata[2][3]|csv:Error bm3anyd3t_2 = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"], outputWithHeaders: true}); test:assertEquals(bm3anyd3t_2, [ ["b1", "b2", "b3"], [true, false, ()] ]); - anydata[][]|csv:Error bm2anyd3t_3 = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: false}); + anydata[][]|csv:Error bm2anyd3t_3 = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: false}); test:assertEquals(bm2anyd3t_3, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - anydata[][]|csv:Error bm2anyd3t_4 = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n2", "n3"], outputWithHeaders: false}); + anydata[][]|csv:Error bm2anyd3t_4 = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n2", "n3"], outputWithHeaders: false}); test:assertTrue(bm2anyd3t_4 is csv:Error); test:assertEquals(( bm2anyd3t_4).message(), "CSV data rows with varying headers are not yet supported"); - bm2anyd3t_4 = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n2", "n3"], outputWithHeaders: true}); + bm2anyd3t_4 = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n2", "n3"], outputWithHeaders: true}); test:assertTrue(bm2anyd3t_4 is csv:Error); test:assertEquals(( bm2anyd3t_4).message(), "CSV data rows with varying headers are not yet supported"); } @@ -667,7 +667,7 @@ function testsRecordsOutputWithHeadrs() { test:assertTrue(bm3anyd3t_3 is csv:Error); test:assertEquals(( bm3anyd3t_3).message(), "CSV data rows with varying headers are not yet supported"); - record{}[]|csv:Error bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"a": 3, "b": 4}]); + record {}[]|csv:Error bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"a": 3, "b": 4}]); test:assertEquals(bm3anyd3t_4, [{"a": 1, "b": 2}, {"a": 3, "b": 4}]); bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"c": 3, "d": 4}]); diff --git a/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal index 08845c7..547a3cb 100644 --- a/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal @@ -14,18 +14,18 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean? b3 = (); -boolean|int b4 = false; +final boolean b1 = true; +final false b2 = false; +final boolean? b3 = (); +final boolean|int b4 = false; -() n1 = (); -int? n2 = (); -() n3 = null; +final () n1 = (); +final int? n2 = (); +final () n3 = null; -int i1 = 1; -map bm1 = {b1, b2}; -map bm2 = {b1, b2, b3, n1, n3}; -map bm3 = {b1, b2, b3, b4, i1}; -map<()> bm4 = {n1, n3}; -map bm5 = {b1, b2, b3, b4:true}; +final int i1 = 1; +final map bm1 = {b1, b2}; +final map bm2 = {b1, b2, b3, n1, n3}; +final map bm3 = {b1, b2, b3, b4, i1}; +final map<()> bm4 = {n1, n3}; +final map bm5 = {b1, b2, b3, b4:true}; diff --git a/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal b/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal index e764c8e..10e3859 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal @@ -340,7 +340,7 @@ function testArrayIndexes() { 5, 6, 7 7, 8, 9`; - record{}[2]|csv:Error rec = csv:parseString(csv); + record {}[2]|csv:Error rec = csv:parseString(csv); test:assertEquals(rec, [ {a: 1, b: 2}, {a: 3, b: 4} @@ -445,7 +445,7 @@ function testParseStringArrayAsExpectedTypeWithOutputHeaders() { string[][]|csv:Error cv1baa_5 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true, header: 2}); test:assertTrue(cv1baa_5 is csv:Error); - test:assertEquals((cv1baa_5).message(), "Duplicate header found: 'true'"); + test:assertEquals((cv1baa_5).message(), "duplicate header found: 'true'"); string[][]|csv:Error cv1baa_6 = csv:parseString(csvStringWithBooleanValues8, {outputWithHeaders: false, header: 2}); test:assertEquals(cv1baa_6, [ diff --git a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal index e4d152b..b39e526 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal @@ -14,21 +14,21 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean|int b4 = false; +final boolean b1 = true; +final false b2 = false; +final boolean|int b4 = false; -string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 true,false,true,false true,false, true,false true,false,true,false `; -string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 +final string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 true,false, true,false,true true,false, true,false,true`; -string csvStringWithBooleanValues3 = string `b1,b2,b3 +final string csvStringWithBooleanValues3 = string `b1,b2,b3 ${" "}${"\t"} true, false,true ${" "} @@ -39,29 +39,29 @@ true, true,FALSE `; -string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 true,(), (),false true,(), null,false `; -string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 true,false,true,2 true,false,true,3 `; -string csvStringWithBooleanValues6 = string `b2,b3 +final string csvStringWithBooleanValues6 = string `b2,b3 (),() `; -string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 ${b1},${b2},(),${b4} `; -string csvStringWithBooleanValues8 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues8 = string `b1,b2,b3,b4 true,false,true1,false1 true,false, true1,false1 true,false,true1,false1 diff --git a/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal index 80cea06..db0814f 100644 --- a/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal @@ -14,22 +14,22 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean? b3 = (); -boolean|int b4 = false; +final boolean b1 = true; +final false b2 = false; +final boolean? b3 = (); +final boolean|int b4 = false; -string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 true,false,true,false true,false, true,false true,false,true,false `; -string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 +final string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 true,false, true,false,true true,false, true,false,true`; -string csvStringWithBooleanValues3 = string `b1,b2,b3 +final string csvStringWithBooleanValues3 = string `b1,b2,b3 ${" "}${"\t"} true, false,true ${" "} @@ -40,24 +40,24 @@ true, true,FALSE `; -string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 true,(), (),false true,(), null,false `; -string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 true,false,true,2 true,false,true,3 `; -string csvStringWithBooleanValues6 = string `b2,b3 +final string csvStringWithBooleanValues6 = string `b2,b3 (),() `; -string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 ${b1},${b2},(),${b4} `; diff --git a/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal b/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal index 728d683..49a00e6 100644 --- a/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal +++ b/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal @@ -7,13 +7,13 @@ type Book1 record { ()|string year; }; -string csvString1 = string `name,author,year - ,b,c - a,,c - a,b,`; - -@test:Config{} +@test:Config function testEmptyStringWithNilConfig() { + string csvString1 = string `name,author,year + ,b,c + a,,c + a,b,`; + Book1[]|error books1 = csv:parseString(csvString1, {nilValue: ""}); test:assertEquals(books1, [ {name: null, author: "b", year: "c"}, diff --git a/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal b/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal index b4a361a..6199175 100644 --- a/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal +++ b/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal @@ -208,7 +208,7 @@ function testSpaceBetweendData() { string csv = string `a b, b d e, f "Hello world", " Hi I am ", \" Hi I am \"`; - record{|string...;|}[]|csv:Error rec = csv:parseString(csv); + record {|string...;|}[]|csv:Error rec = csv:parseString(csv); test:assertEquals(rec, [ {"a b":"Hello world","b d e":" Hi I am ","f":"\"Hi I am \""}]); } @@ -218,7 +218,7 @@ function testParseBytes() returns error? { byte[] csvBytes = check io:fileReadBytes(filepath); byte[] csvBytes2 = check io:fileReadBytes(filepath2); - record{}[]|csv:Error rec = csv:parseBytes(csvBytes, {}); + record {}[]|csv:Error rec = csv:parseBytes(csvBytes, {}); test:assertEquals(rec, [ {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}, {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}, @@ -264,7 +264,7 @@ function testParseBytes() returns error? { test:assertTrue(rec3 is csv:Error); test:assertEquals(( rec3).message(), common:generateErrorMessageForInvalidCast("Hello World", "int")); - record{int a;}[]|csv:Error rec4 = csv:parseBytes(csvBytes, {}); + record {int a;}[]|csv:Error rec4 = csv:parseBytes(csvBytes, {}); test:assertTrue(rec4 is csv:Error); test:assertEquals(( rec4).message(), common:generateErrorMessageForInvalidCast("Hello World", "int")); } @@ -274,7 +274,7 @@ function testParseStream() returns error? { stream csvByteStream = check io:fileReadBlocksAsStream(filepath); stream csvByteStream2 = check io:fileReadBlocksAsStream(filepath2); - record{}[]|csv:Error rec = csv:parseStream(csvByteStream, {}); + record {}[]|csv:Error rec = csv:parseStream(csvByteStream, {}); test:assertEquals(rec, [ {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}, {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}, @@ -321,7 +321,7 @@ function testParseStream() returns error? { ]); csvByteStream = check io:fileReadBlocksAsStream(filepath); - record{int a;}[]|csv:Error rec3 = csv:parseStream(csvByteStream, {}); + record {int a;}[]|csv:Error rec3 = csv:parseStream(csvByteStream, {}); test:assertTrue(rec3 is csv:Error); test:assertEquals(( rec3).message(), "Error occurred while reading the stream: " + common:generateErrorMessageForInvalidCast("Hello World", "int")); @@ -341,7 +341,7 @@ function testErrorParseBytes() returns error? { test:assertTrue(rec3 is csv:Error); test:assertTrue(( rec3).message().includes("cannot be cast into")); - record{int a;}[]|csv:Error rec4 = csv:parseBytes(csvBytes, {}); + record {int a;}[]|csv:Error rec4 = csv:parseBytes(csvBytes, {}); test:assertTrue(rec4 is csv:Error); test:assertTrue(( rec3).message().includes("cannot be cast into")); } @@ -350,7 +350,7 @@ function testErrorParseBytes() returns error? { function testErrorParseStream() returns error? { stream csvByteStream = check io:fileReadBlocksAsStream(errorFilepath); - record{int a;}[]|csv:Error rec3 = csv:parseStream(csvByteStream, {}); + record {int a;}[]|csv:Error rec3 = csv:parseStream(csvByteStream, {}); test:assertTrue(rec3 is csv:Error); test:assertTrue(( rec3).message().includes("cannot be cast into")); diff --git a/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal b/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal index 06b36a7..1cf12ca 100644 --- a/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal +++ b/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal @@ -286,7 +286,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true} - ], {headersOrder: ["a", "b", "c"]}); + ], {headerOrder: ["a", "b", "c"]}); test:assertEquals(rt6a, [ [1, "string", true], @@ -296,7 +296,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [A, B, C][]|csv:Error rt7a = csv:transform( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] - , {headersOrder: ["a", "b", "c"]}); + , {headerOrder: ["a", "b", "c"]}); test:assertEquals(rt7a, [ [1d, "string", true], @@ -306,7 +306,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [A2, B2, C2][]|csv:Error rt8a = csv:transform( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] - , {headersOrder: ["a", "b", "c"]}); + , {headerOrder: ["a", "b", "c"]}); test:assertEquals(rt8a, [ [1, "string", true], @@ -316,7 +316,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [A2, B2, C2...][]|csv:Error rt9a = csv:transform( [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] - , {headersOrder: ["a", "b", "c", "d"]}); + , {headerOrder: ["a", "b", "c", "d"]}); test:assertEquals(rt9a, [ [1, "string", true, "string"], @@ -326,7 +326,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [C2...][]|csv:Error rt10a = csv:transform( [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] - , {headersOrder: ["a", "b", "c", "d"]}); + , {headerOrder: ["a", "b", "c", "d"]}); test:assertTrue(rt10a is csv:Error); test:assertEquals((rt10a).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "0", "type_compatible_tests:C2")); @@ -463,19 +463,19 @@ function testSliceOperation() { int[2][]|error c = csv:parseList(v); test:assertEquals(c, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c2 = csv:parseList(v, {customHeaders: ["a", "b"]}); + record {|int...;|}[2]|error c2 = csv:parseList(v, {customHeaders: ["a", "b"]}); test:assertEquals(c2, [{a: 1, b: 2}, {a: 3, b: 4}]); - int[2][]|error c3 = csv:transform(v2, {headersOrder: ["a", "b"]}); + int[2][]|error c3 = csv:transform(v2, {headerOrder: ["a", "b"]}); test:assertEquals(c3, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c4 = csv:transform(v2); + record {|int...;|}[2]|error c4 = csv:transform(v2); test:assertEquals(c4, [{a: 1, b: 2}, {a: 3, b: 4}]); int[2][]|error c5 = csv:parseString(v3); test:assertEquals(c5, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c6 = csv:parseString(v3); + record {|int...;|}[2]|error c6 = csv:parseString(v3); test:assertEquals(c6, [{a: 1, b: 2}, {a: 3, b: 4}]); } @@ -493,18 +493,18 @@ function testSliceOperation2() { int[2][2]|error c = csv:parseList(v, {skipLines: [1, 3]}); test:assertEquals(c, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c2 = csv:parseList(v, {customHeaders: ["a", "b", "c"], skipLines: [1, 3]}); + record {|int...;|}[2]|error c2 = csv:parseList(v, {customHeaders: ["a", "b", "c"], skipLines: [1, 3]}); test:assertEquals(c2, [{a: 1, b: 2}, {a: 3, b: 4}]); - int[2][2]|error c3 = csv:transform(v2, {headersOrder: ["a", "b", "c"], skipLines: [1, 3]}); + int[2][2]|error c3 = csv:transform(v2, {headerOrder: ["a", "b", "c"], skipLines: [1, 3]}); test:assertEquals(c3, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c4 = csv:transform(v2, {skipLines: [1, 3]}); + record {|int...;|}[2]|error c4 = csv:transform(v2, {skipLines: [1, 3]}); test:assertEquals(c4, [{a: 1, b: 2}, {a: 3, b: 4}]); int[2][2]|error c5 = csv:parseString(v3, {skipLines: [1, 3]}); test:assertEquals(c5, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c6 = csv:parseString(v3, {skipLines: [1, 3]}); + record {|int...;|}[2]|error c6 = csv:parseString(v3, {skipLines: [1, 3]}); test:assertEquals(c6, [{a: 1, b: 2}, {a: 3, b: 4}]); } \ No newline at end of file diff --git a/ballerina-tests/type-compatible-tests/tests/test_data_values.bal b/ballerina-tests/type-compatible-tests/tests/test_data_values.bal index 5993176..5838ec6 100644 --- a/ballerina-tests/type-compatible-tests/tests/test_data_values.bal +++ b/ballerina-tests/type-compatible-tests/tests/test_data_values.bal @@ -14,41 +14,41 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean? b3 = (); -boolean|int b4 = false; +final boolean b1 = true; +final false b2 = false; +final boolean? b3 = (); +final boolean|int b4 = false; -() n1 = (); -int? n2 = (); -() n3 = null; +final () n1 = (); +final int? n2 = (); +final () n3 = null; -int i1 = 1; -int i2 = -2; -int i3 = int:MAX_VALUE; -int i4 = int:MIN_VALUE; -int i5 = 0; -2 i6 = 2; -int? i7 = (); -int|string i8 = 100; +final int i1 = 1; +final int i2 = -2; +final int i3 = int:MAX_VALUE; +final int i4 = int:MIN_VALUE; +final int i5 = 0; +final 2 i6 = 2; +final int? i7 = (); +final int|string i8 = 100; -float f1 = 2.234; -float f2 = -3.21f; -float f3 = 0; -float f4 = float:Infinity; -float f5 = -float:Infinity; -float f6 = float:NaN; -2.3f f7 = 2.3; -float? f8 = (); -float|decimal f9 = 1.21; +final float f1 = 2.234; +final float f2 = -3.21f; +final float f3 = 0; +final float f4 = float:Infinity; +final float f5 = -float:Infinity; +final float f6 = float:NaN; +final 2.3f f7 = 2.3; +final float? f8 = (); +final float|decimal f9 = 1.21; -decimal d1 = 2.234; -decimal d2 = -3.21d; -decimal d3 = 0; -2.3d d4 = 2.3; -decimal? d5 = (); -decimal|int d6 = 1.21; +final decimal d1 = 2.234; +final decimal d2 = -3.21d; +final decimal d3 = 0; +final 2.3d d4 = 2.3; +final decimal? d5 = (); +final decimal|int d6 = 1.21; -string s1 = "string"; -string s2 = ""; -string:Char s3 = "a"; +final string s1 = "string"; +final string s2 = ""; +final string:Char s3 = "a"; diff --git a/ballerina-tests/unicode-tests/tests/escape_character_test.bal b/ballerina-tests/unicode-tests/tests/escape_character_test.bal index 9114e1b..5ed18d1 100644 --- a/ballerina-tests/unicode-tests/tests/escape_character_test.bal +++ b/ballerina-tests/unicode-tests/tests/escape_character_test.bal @@ -28,7 +28,7 @@ function testEscapedCharactres() returns error? { slash\/slash, 9 quoted string \\'abc\\', 10`; - record{string a; int b;}[]|csv:Error rec = csv:parseString(csvString); + record {string a; int b;}[]|csv:Error rec = csv:parseString(csvString); test:assertEquals(rec, [ {a: string `quote""quoted"quote`, b: 1}, {a: string `backslash${"\\"}backslash`, b: 2}, @@ -45,8 +45,8 @@ function testEscapedCharactres2() returns error? { string csvString = string `a, b backspace\bbackspace, 7`; - record{string a; int b;}[]|csv:Error rec = csv:parseString(csvString); - test:assertTrue(rec is record{string a; int b;}[]); + record {string a; int b;}[]|csv:Error rec = csv:parseString(csvString); + test:assertTrue(rec is record {string a; int b;}[]); } @test:Config @@ -54,7 +54,7 @@ function testEscapedCharactres3() returns error? { string csvString = string ` a c, b carriage return\r carriage return, 4`; - record{}[]|csv:Error rec = csv:parseString(csvString); + record {}[]|csv:Error rec = csv:parseString(csvString); test:assertEquals(rec, [ {"a c": string `carriage return${"\r"} carriage return`, b: 4} ]); @@ -65,7 +65,7 @@ function testEscapedCharactres4() returns error? { string csvString = string `a, b form feed\f form feed, 8`; - record{string a; int b;}[]|csv:Error rec = csv:parseString(csvString); + record {string a; int b;}[]|csv:Error rec = csv:parseString(csvString); test:assertTrue(rec is record {string a; int b;}[]); // TODO: Add tests after supports \f by Ballerina } diff --git a/ballerina-tests/union-type-tests/tests/test_data_values.bal b/ballerina-tests/union-type-tests/tests/test_data_values.bal index 7d88394..23c0be9 100644 --- a/ballerina-tests/union-type-tests/tests/test_data_values.bal +++ b/ballerina-tests/union-type-tests/tests/test_data_values.bal @@ -14,7 +14,7 @@ // specific language governing permissions and limitations // under the License. -string csvStringData1 = string ` +final string csvStringData1 = string ` a, b, c, d, e, f 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null diff --git a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal index 9b03961..85a4f8c 100644 --- a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal +++ b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal @@ -1,21 +1,21 @@ import ballerina/data.csv; import ballerina/test; -csv:TransformOptions op1 = {headersOrder: ["a", "b", "c", "d"], outputWithHeaders: false}; -csv:TransformOptions op2 = {headersOrder: ["a", "b", "c", "d"], outputWithHeaders: true}; -csv:TransformOptions op3 = {outputWithHeaders: true}; -csv:TransformOptions op4 = {headersOrder: ["a", "b"], outputWithHeaders: true}; - -csv:ParseOptions op5 = {outputWithHeaders: true}; - -csv:ParseListOptions op6 = {outputWithHeaders: true}; -csv:ParseListOptions op7 = {outputWithHeaders: true, headersRows: 1}; -csv:ParseListOptions op8 = {outputWithHeaders: true, headersRows: 2}; -csv:ParseListOptions op9 = {outputWithHeaders: true, headersRows: 2, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListOptions op10 = {outputWithHeaders: true, headersRows: 1, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListOptions op12 = {headersRows: 1, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; +final csv:TransformOptions op1 = {headerOrder: ["a", "b", "c", "d"], outputWithHeaders: false}; +final csv:TransformOptions op2 = {headerOrder: ["a", "b", "c", "d"], outputWithHeaders: true}; +final csv:TransformOptions op3 = {outputWithHeaders: true}; +final csv:TransformOptions op4 = {headerOrder: ["a", "b"], outputWithHeaders: true}; + +final csv:ParseOptions op5 = {outputWithHeaders: true}; + +final csv:ParseListOptions op6 = {outputWithHeaders: true}; +final csv:ParseListOptions op7 = {outputWithHeaders: true, headerRows: 1}; +final csv:ParseListOptions op8 = {outputWithHeaders: true, headerRows: 2}; +final csv:ParseListOptions op9 = {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b", "c", "d"]}; +final csv:ParseListOptions op10 = {outputWithHeaders: true, headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +final csv:ParseListOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", "c", "d"]}; +final csv:ParseListOptions op12 = {headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +final csv:ParseListOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; type UnionType1 boolean[][]|string[][]; @@ -25,23 +25,23 @@ type UnionType3 record {int d1;}[]|record {}[]; type UnionType4 (map|map)[]; -string[][] csv1 = [["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; -var csv2 = [{a: 1, b: 2, c: 3, d: 4}, {a: 5, b: 6, c: 7, d: 8}, {a: 9, b: 10, c: 11, d: 12}, {a: 13, b: 14, c: 15, d: 16}]; -var csv3 = string `a,b,c,d +final string[][] csv1 = [["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; +final var csv2 = [{a: 1, b: 2, c: 3, d: 4}, {a: 5, b: 6, c: 7, d: 8}, {a: 9, b: 10, c: 11, d: 12}, {a: 13, b: 14, c: 15, d: 16}]; +final var csv3 = string `a,b,c,d 1,2,3,4 5,6,7,8 9,10,11,12 13,14,15,16`; -var csv4 = [{a: "1", b: "2", c: "3", d: "4"}, {a: "5", b: "6", c: "7", d: "8"}, {a: "9", b: "10", c: "11", d: "12"}, {a: "13", b: "14", c: "15", d: "16"}]; - -var result1 = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]; -var result2 = [{a: 1, b: 2, c: 3, d: 4}, {a: 5, b: 6, c: 7, d: 8}, {a: 9, b: 10, c: 11, d: 12}, {a: 13, b: 14, c: 15, d: 16}]; -var result3 = [{a: "1", b: "2", c: "3", d: "4"}, {a: "5", b: "6", c: "7", d: "8"}, {a: "9", b: "10", c: "11", d: "12"}, {a: "13", b: "14", c: "15", d: "16"}]; -var result4 = [["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; -var result5 = [["a", "b", "c", "d"], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]; -var result6 = [["a", "b", "c", "d"], ["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; -var result7 = [{'1: 1, '2: 2, '3: 3, '4: 4}, {'1: 5, '2: 6, '3: 7, '4: 8}, {'1: 9, '2: 10, '3: 11, '4: 12}, {'1: 13, '2: 14, '3: 15, '4: 16}]; -var result8 = [{'1: "1", '2: "2", '3: "3", '4: "4"}, {'1: "5", '2: "6", '3: "7", '4: "8"}, {'1: "9", '2: "10", '3: "11", '4: "12"}, {'1: "13", '2: "14", '3: "15", '4: "16"}]; +final var csv4 = [{a: "1", b: "2", c: "3", d: "4"}, {a: "5", b: "6", c: "7", d: "8"}, {a: "9", b: "10", c: "11", d: "12"}, {a: "13", b: "14", c: "15", d: "16"}]; + +final var result1 = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]; +final var result2 = [{a: 1, b: 2, c: 3, d: 4}, {a: 5, b: 6, c: 7, d: 8}, {a: 9, b: 10, c: 11, d: 12}, {a: 13, b: 14, c: 15, d: 16}]; +final var result3 = [{a: "1", b: "2", c: "3", d: "4"}, {a: "5", b: "6", c: "7", d: "8"}, {a: "9", b: "10", c: "11", d: "12"}, {a: "13", b: "14", c: "15", d: "16"}]; +final var result4 = [["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; +final var result5 = [["a", "b", "c", "d"], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]; +final var result6 = [["a", "b", "c", "d"], ["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; +final var result7 = [{'1: 1, '2: 2, '3: 3, '4: 4}, {'1: 5, '2: 6, '3: 7, '4: 8}, {'1: 9, '2: 10, '3: 11, '4: 12}, {'1: 13, '2: 14, '3: 15, '4: 16}]; +final var result8 = [{'1: "1", '2: "2", '3: "3", '4: "4"}, {'1: "5", '2: "6", '3: "7", '4: "8"}, {'1: "9", '2: "10", '3: "11", '4: "12"}, {'1: "13", '2: "14", '3: "15", '4: "16"}]; @test:Config function testParseStringWithMapWithOutputHeaders() { diff --git a/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal b/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal index 726ef47..7661513 100644 --- a/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal @@ -82,11 +82,11 @@ function testIntersectionExpectedTypes() returns error? { @test:Config function testIntersectionExpectedTypes2() returns error? { - (int[] & readonly)[]|csv:Error a = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], {headersOrder: ["a", "b"]}); + (int[] & readonly)[]|csv:Error a = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], {headerOrder: ["a", "b"]}); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|csv:Error a2 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {headersOrder: ["a", "b"]}); + ([string, string])[] & readonly|csv:Error a2 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {headerOrder: ["a", "b"]}); test:assertTrue(a2 is [string, string][] & readonly); test:assertEquals(a2, [["a", "a"], ["c", "c"]]); @@ -98,11 +98,11 @@ function testIntersectionExpectedTypes2() returns error? { test:assertTrue(a4 is record {|string...;|}[] & readonly); test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - ([int] & readonly)[]|csv:Error a5 = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], {headersOrder: ["a", "b"]}); + ([int] & readonly)[]|csv:Error a5 = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], {headerOrder: ["a", "b"]}); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|csv:Error a6 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {headersOrder: ["a", "b"]}); + ([string, string])[] & readonly|csv:Error a6 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {headerOrder: ["a", "b"]}); test:assertTrue(a6 is [string, string][] & readonly); test:assertEquals(a6, [["a", "a"], ["c", "c"]]); @@ -114,11 +114,11 @@ function testIntersectionExpectedTypes2() returns error? { test:assertTrue(a8 is map[] & readonly); test:assertEquals(a8, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headerOrder: ["a", "b"]}); test:assertTrue(a9 is error); - test:assertEquals(( a9).message(), "The CSV cannot be converted into any of the uniform union types in '((int[] & readonly)|([string,string] & readonly))[]'"); + test:assertEquals(( a9).message(), "source value cannot converted in to the '((int[] & readonly)|([string,string] & readonly))[]'"); - (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9_2 = csv:transform([{"a": "1", "b": "2"}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9_2 = csv:transform([{"a": "1", "b": "2"}, {"a": "a", "b": "b"}], {headerOrder: ["a", "b"]}); test:assertTrue(a9_2 is (((int[] & readonly)|([string, string] & readonly)) & readonly)[]); test:assertEquals(a9_2, [["1", "2"], ["a", "b"]]); @@ -130,7 +130,7 @@ function testIntersectionExpectedTypes2() returns error? { ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly|csv:Error a10_2 = csv:transform([{"a": "a", "b": "a"}, {"a": 1, "b": 2}], {}); test:assertTrue(a10_2 is error); - test:assertEquals(( a10_2).message(), "The CSV cannot be converted into any of the uniform union types in '((union_type_tests:record {| string a; string b; anydata...; |} & readonly)|(union_type_tests:record {| int a; int b; anydata...; |} & readonly))[]'"); + test:assertEquals(( a10_2).message(), "source value cannot converted in to the '((union_type_tests:record {| string a; string b; anydata...; |} & readonly)|(union_type_tests:record {| int a; int b; anydata...; |} & readonly))[]'"); } @test:Config diff --git a/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal b/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal index 4bf4c7f..57bfa05 100644 --- a/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal @@ -202,13 +202,13 @@ function testSubtypeExpectedTypes() returns error? { SubtypeRecord3[]|csv:Error a9 = csv:transform(value1, {}); test:assertEquals(a9, value1); - SubtypeTuple[]|csv:Error a10 = csv:transform(value1, {headersOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); + SubtypeTuple[]|csv:Error a10 = csv:transform(value1, {headerOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a10, value3); - SubtypeTuple2[]|csv:Error a11 = csv:transform(value1, {headersOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); + SubtypeTuple2[]|csv:Error a11 = csv:transform(value1, {headerOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a11, [[1, 1], [1, 1]]); - SubtypeTuple3[]|csv:Error a12 = csv:transform(value1, {headersOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); + SubtypeTuple3[]|csv:Error a12 = csv:transform(value1, {headerOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a12, value3); SubtypeRecord[]|csv:Error a13 = csv:parseList(value2, {customHeaders: ["a", "c", "d", "e", "f", "g", "h", "i"]}); diff --git a/ballerina-tests/union-type-tests/tests/test_with_union_types.bal b/ballerina-tests/union-type-tests/tests/test_with_union_types.bal index f9246ce..594401b 100644 --- a/ballerina-tests/union-type-tests/tests/test_with_union_types.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_union_types.bal @@ -64,21 +64,21 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); + (record {|int a;|}|record {|string b;|})[]|csv:Error csv1op6 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); + (record {|string b;|}|record {|int a;|})[]|csv:Error csv1op7 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:parseString(csvStringData1, {header: 1}); + (record {|string...;|}|record {|int...;|})[]|csv:Error csv1op8 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op8, [ {a: "1", b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: "2", b: "string2", c: "false", d: "0", e: "0", f: "null"}, @@ -87,7 +87,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseString(csvStringData1, {header: 1}); + (record {|int...;|}|record {|string...;|})[]|csv:Error csv1op9 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -96,7 +96,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, d: 3, e: 3} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseString(csvStringData1, {header: 1}); + (record {|int a; string...;|}|record {|string a; int...;|})[]|csv:Error csv1op10 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: 2, b: "string2", c: "false", d: "0", e: "0", f: "null"}, @@ -105,7 +105,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:parseString(csvStringData1, {header: 1}); + (record {|string a; int...;|}|record {|int a; string...;|})[]|csv:Error csv1op11 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -114,7 +114,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "5", d: 3, e: 3} ]); - (record{|int a; int b;|}|record{|string a; string...;|})[]|csv:Error csv1op12 = csv:parseString(string ` + (record {|int a; int b;|}|record {|string a; string...;|})[]|csv:Error csv1op12 = csv:parseString(string ` a,b 1, 2 a, b`, {header: 1}); @@ -133,7 +133,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { ]); } -record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ +record {int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, @@ -181,21 +181,21 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:transform(value, {skipLines: [2, 4]}); + (record {|int a;|}|record {|string b;|})[]|csv:Error csv1op6 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:transform(value, {skipLines: [2, 4]}); + (record {|string b;|}|record {|int a;|})[]|csv:Error csv1op7 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:transform(value, {}); + (record {|string...;|}|record {|int...;|})[]|csv:Error csv1op8 = csv:transform(value, {}); test:assertEquals(csv1op8, [ {b: "string1"}, {b: "string2"}, @@ -204,7 +204,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {b: "string5"} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:transform(value, {}); + (record {|int...;|}|record {|string...;|})[]|csv:Error csv1op9 = csv:transform(value, {}); test:assertEquals(csv1op9, [ {a: 1, d: 2, e: 2}, {a: 2, d: 0, e: 0}, @@ -213,7 +213,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, d: 3, e: 3} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:transform(value, {}); + (record {|int a; string...;|}|record {|string a; int...;|})[]|csv:Error csv1op10 = csv:transform(value, {}); test:assertEquals(csv1op10, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -222,7 +222,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:transform(value, {}); + (record {|string a; int...;|}|record {|int a; string...;|})[]|csv:Error csv1op11 = csv:transform(value, {}); test:assertEquals(csv1op11, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -231,19 +231,19 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5"} ]); - (record{|string a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op12 = csv:transform(value, {}); + (record {|string a; int...;|}|record {|string a; string...;|})[]|csv:Error csv1op12 = csv:transform(value, {}); test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:record {| string a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); + test:assertEquals((csv1op12).message(), "source value cannot converted in to the '(union_type_tests:record {| string a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); - (record{|int a; int...;|}|record{|int|string a; int|string...;|})[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); + (record {|int a; int...;|}|record {|int|string a; int|string...;|})[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, {a: "a", b: "b"} ]); - (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op14 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); + (record {|int a; int...;|}|record {|string a; string...;|})[]|csv:Error csv1op14 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); test:assertTrue(csv1op14 is csv:Error); - test:assertEquals((csv1op14).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:record {| int a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); + test:assertEquals((csv1op14).message(), "source value cannot converted in to the '(union_type_tests:record {| int a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); } @test:Config @@ -294,28 +294,28 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (record {|int a;|}|record {|string b;|})[]|csv:Error csv1op6 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (record {|string b;|}|record {|int a;|})[]|csv:Error csv1op7 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); + (record {|string...;|}|record {|int...;|})[]|csv:Error csv1op8 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); test:assertEquals(csv1op8, [ {a: "1", b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: "3", b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: "5", b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); + (record {|int...;|}|record {|string...;|})[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -324,14 +324,14 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, d: 3} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); + (record {|int a; string...;|}|record {|string a; int...;|})[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: 3, b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: 5, b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); + (record {|string a; int...;|}|record {|int a; string...;|})[]|csv:Error csv1op11 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -340,7 +340,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", d: 3} ]); - (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); + (record {|int a; int...;|}|record {|string a; string...;|})[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, {a: "a", b: "b"} @@ -350,7 +350,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { @test:Config function testParseToStringWithUnionExpectedTypes4() returns error? { - record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + record {int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, @@ -358,7 +358,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - (TupA|TupC)[]|csv:Error csv1op1 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + (TupA|TupC)[]|csv:Error csv1op1 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -367,7 +367,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupA|TupC)[]|csv:Error csv1op2 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (TupA|TupC)[]|csv:Error csv1op2 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertTrue(csv1op2 is (TupA|TupC)[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -375,74 +375,74 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupC|TupA)[]|csv:Error csv1op3 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (TupC|TupA)[]|csv:Error csv1op3 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op3, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - (TupB|TupA)[]|csv:Error csv1op4 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (TupB|TupA)[]|csv:Error csv1op4 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op4, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - (TupB|[boolean])[]|csv:Error csv1op4_2 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (TupB|[boolean])[]|csv:Error csv1op4_2 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is csv:Error); - test:assertEquals((csv1op4_2).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:TupB|[boolean])[]'"); + test:assertEquals((csv1op4_2).message(), "source value cannot converted in to the '(union_type_tests:TupB|[boolean])[]'"); - (TupA|TupB)[]|csv:Error csv1op5 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (TupA|TupB)[]|csv:Error csv1op5 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op5, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - ([int]|[string])[]|csv:Error csv1op6 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + ([int]|[string])[]|csv:Error csv1op6 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - ([string]|[int])[]|csv:Error csv1op7 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + ([string]|[int])[]|csv:Error csv1op7 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ [1], [3], [5] ]); - ([string...]|[int...])[]|csv:Error csv1op8 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + ([string...]|[int...])[]|csv:Error csv1op8 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op8 is csv:Error); - test:assertEquals((csv1op8).message(), "The CSV cannot be converted into any of the uniform union types in '([string...]|[int...])[]'"); + test:assertEquals((csv1op8).message(), "source value cannot converted in to the '([string...]|[int...])[]'"); - ([int...]|[string...])[]|csv:Error csv1op9 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + ([int...]|[string...])[]|csv:Error csv1op9 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op9 is csv:Error); - test:assertEquals((csv1op9).message(), "The CSV cannot be converted into any of the uniform union types in '([int...]|[string...])[]'"); + test:assertEquals((csv1op9).message(), "source value cannot converted in to the '([int...]|[string...])[]'"); - ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op10 is csv:Error); - test:assertEquals((csv1op10).message(), "The CSV cannot be converted into any of the uniform union types in '([int,string...]|[string,int...])[]'"); + test:assertEquals((csv1op10).message(), "source value cannot converted in to the '([int,string...]|[string,int...])[]'"); - ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op11 is csv:Error); - test:assertEquals((csv1op11).message(), "The CSV cannot be converted into any of the uniform union types in '([string,int...]|[int,string...])[]'"); + test:assertEquals((csv1op11).message(), "source value cannot converted in to the '([string,int...]|[int,string...])[]'"); - ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The CSV cannot be converted into any of the uniform union types in '([string,int...]|[string,string...])[]'"); + test:assertEquals((csv1op12).message(), "source value cannot converted in to the '([string,int...]|[string,string...])[]'"); - ([string, string...]|[int|string, int|string...])[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + ([string, string...]|[int|string, int|string...])[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headerOrder: ["a", "b"]}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] ]); - ([int, int...]|[string, string...])[]|csv:Error csv1op14 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + ([int, int...]|[string, string...])[]|csv:Error csv1op14 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headerOrder: ["a", "b"]}); test:assertTrue(csv1op14 is csv:Error); - test:assertEquals((csv1op14).message(), "The CSV cannot be converted into any of the uniform union types in '([int,int...]|[string,string...])[]'"); + test:assertEquals((csv1op14).message(), "source value cannot converted in to the '([int,int...]|[string,string...])[]'"); } @test:Config @@ -488,7 +488,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { (TupB|[boolean])[]|csv:Error csv1op4_2 = csv:parseList(value, {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is csv:Error); - test:assertEquals((csv1op4_2).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:TupB|[boolean])[]'"); + test:assertEquals((csv1op4_2).message(), "source value cannot converted in to the '(union_type_tests:TupB|[boolean])[]'"); (TupA|TupB)[]|csv:Error csv1op5 = csv:parseList(value, {skipLines: [2, 4]}); test:assertEquals(csv1op5, [ @@ -585,21 +585,21 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); + record {|int a;|}[]|record {|string b;|}[]|csv:Error csv1op6 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); + record {|string b;|}[]|record {|int a;|}[]|csv:Error csv1op7 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:parseString(csvStringData1, {header: 1}); + record {|string...;|}[]|record {|int...;|}[]|csv:Error csv1op8 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op8, [ {a: "1", b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: "2", b: "string2", c: "false", d: "0", e: "0", f: "null"}, @@ -608,7 +608,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseString(csvStringData1, {header: 1}); + record {|int...;|}[]|record {|string...;|}[]|csv:Error csv1op9 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -617,7 +617,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, d: 3, e: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseString(csvStringData1, {header: 1}); + record {|int a; string...;|}[]|record {|string a; int...;|}[]|csv:Error csv1op10 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: 2, b: "string2", c: "false", d: "0", e: "0", f: "null"}, @@ -626,7 +626,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseString(csvStringData1, {header: 1}); + record {|string a; int...;|}[]|record {|int a; string...;|}[]|csv:Error csv1op11 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -635,7 +635,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: "5", d: 3, e: 3} ]); - record{|int a; int b;|}[]|record{|string a; string...;|}[]|csv:Error csv1op12 = csv:parseString(string ` + record {|int a; int b;|}[]|record {|string a; string...;|}[]|csv:Error csv1op12 = csv:parseString(string ` a,b 1, 2 a, b`, {header: 1}); @@ -647,7 +647,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { @test:Config function testParseToStringWithUnionExpectedTypes7() returns error? { - record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + record {int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, @@ -693,21 +693,21 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:transform(value, {skipLines: [2, 4]}); + record {|int a;|}[]|record {|string b;|}[]|csv:Error csv1op6 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:transform(value, {skipLines: [2, 4]}); + record {|string b;|}[]|record {|int a;|}[]|csv:Error csv1op7 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:transform(value, {}); + record {|string...;|}[]|record {|int...;|}[]|csv:Error csv1op8 = csv:transform(value, {}); test:assertEquals(csv1op8, [ {b: "string1"}, {b: "string2"}, @@ -716,7 +716,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {b: "string5"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:transform(value, {}); + record {|int...;|}[]|record {|string...;|}[]|csv:Error csv1op9 = csv:transform(value, {}); test:assertEquals(csv1op9, [ {a: 1, d: 2, e: 2}, {a: 2, d: 0, e: 0}, @@ -725,7 +725,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, d: 3, e: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:transform(value, {}); + record {|int a; string...;|}[]|record {|string a; int...;|}[]|csv:Error csv1op10 = csv:transform(value, {}); test:assertEquals(csv1op10, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -734,7 +734,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:transform(value, {}); + record {|string a; int...;|}[]|record {|int a; string...;|}[]|csv:Error csv1op11 = csv:transform(value, {}); test:assertEquals(csv1op11, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -743,9 +743,9 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5"} ]); - record{|string a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op12 = csv:transform(value, {}); + record {|string a; int...;|}[]|record {|string a; string...;|}[]|csv:Error csv1op12 = csv:transform(value, {}); test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(union_type_tests:record {| string a; int...; |}[]|union_type_tests:record {| string a; string...; |}[])'"); + test:assertEquals((csv1op12).message(), "source value cannot converted in to the '(union_type_tests:record {| string a; int...; |}[]|union_type_tests:record {| string a; string...; |}[])'"); } @test:Config @@ -796,28 +796,28 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + record {|int a;|}[]|record {|string b;|}[]|csv:Error csv1op6 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + record {|string b;|}[]|record {|int a;|}[]|csv:Error csv1op7 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); + record {|string...;|}[]|record {|int...;|}[]|csv:Error csv1op8 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); test:assertEquals(csv1op8, [ {a: "1", b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: "3", b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: "5", b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); + record {|int...;|}[]|record {|string...;|}[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -826,14 +826,14 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, d: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); + record {|int a; string...;|}[]|record {|string a; int...;|}[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: 3, b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: 5, b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); + record {|string a; int...;|}[]|record {|int a; string...;|}[]|csv:Error csv1op11 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -842,7 +842,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", d: 3} ]); - record{|int a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); + record {|int a; int...;|}[]|record {|string a; string...;|}[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, {a: "a", b: "b"} @@ -852,7 +852,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { @test:Config function testParseToStringWithUnionExpectedTypes9() returns error? { - record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + record {int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, @@ -860,7 +860,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - TupA[]|TupC[]|csv:Error csv1op1 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + TupA[]|TupC[]|csv:Error csv1op1 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -869,7 +869,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupA[]|TupC[]|csv:Error csv1op2 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + TupA[]|TupC[]|csv:Error csv1op2 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertTrue(csv1op2 is TupA[]|TupC[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -877,64 +877,64 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupC[]|TupA[]|csv:Error csv1op3 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + TupC[]|TupA[]|csv:Error csv1op3 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op3, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - TupB[]|TupA[]|csv:Error csv1op4 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + TupB[]|TupA[]|csv:Error csv1op4 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op4, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - TupB[]|[boolean][]|csv:Error csv1op4_2 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + TupB[]|[boolean][]|csv:Error csv1op4_2 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is csv:Error); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(union_type_tests:TupB[]|[boolean][])'"); + test:assertEquals((csv1op4_2).message(), "source value cannot converted in to the '(union_type_tests:TupB[]|[boolean][])'"); - TupA[]|TupB[]|csv:Error csv1op5 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + TupA[]|TupB[]|csv:Error csv1op5 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op5, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - [int][]|[string][]|csv:Error csv1op6 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + [int][]|[string][]|csv:Error csv1op6 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - [string][]|[int][]|csv:Error csv1op7 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + [string][]|[int][]|csv:Error csv1op7 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ [1], [3], [5] ]); - [string...][]|[int...][]|csv:Error csv1op8 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + [string...][]|[int...][]|csv:Error csv1op8 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op8 is csv:Error); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([string...][]|[int...][])'"); + test:assertEquals((csv1op8).message(), "source value cannot converted in to the '([string...][]|[int...][])'"); - [int...][]|[string...][]|csv:Error csv1op9 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + [int...][]|[string...][]|csv:Error csv1op9 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op9 is csv:Error); - test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '([int...][]|[string...][])'"); + test:assertEquals((csv1op9).message(), "source value cannot converted in to the '([int...][]|[string...][])'"); - [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op10 is csv:Error); - test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '([int,string...][]|[string,int...][])'"); + test:assertEquals((csv1op10).message(), "source value cannot converted in to the '([int,string...][]|[string,int...][])'"); - [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op11 is csv:Error); - test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '([string,int...][]|[int,string...][])'"); + test:assertEquals((csv1op11).message(), "source value cannot converted in to the '([string,int...][]|[int,string...][])'"); - [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...][]|[string,string...][])'"); + test:assertEquals((csv1op12).message(), "source value cannot converted in to the '([string,int...][]|[string,string...][])'"); } @test:Config @@ -980,7 +980,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { TupB[]|[boolean][]|csv:Error csv1op4_2 = csv:parseList(value, {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is csv:Error); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(union_type_tests:TupB[]|[boolean][])'"); + test:assertEquals((csv1op4_2).message(), "source value cannot converted in to the '(union_type_tests:TupB[]|[boolean][])'"); TupA[]|TupB[]|csv:Error csv1op5 = csv:parseList(value, {skipLines: [2, 4]}); test:assertEquals(csv1op5, [ @@ -1037,7 +1037,7 @@ function testUnionTypeWithOrdering() returns error? { string value2 = string `a,b, c, d 1, 1.0, true, a 2, 2.0, false, b`; - record{}[] value3 = [{"a": 1, "b": 1.0, "c": true, "d": "a"}, {"a": 2, "b": 2.0, "c": false, "d":"b"}]; + record {}[] value3 = [{"a": 1, "b": 1.0, "c": true, "d": "a"}, {"a": 2, "b": 2.0, "c": false, "d":"b"}]; string[][]|anydata[][]|error csv1op1 = csv:parseList(value1); test:assertEquals(csv1op1, [ @@ -1190,7 +1190,7 @@ function testUnionTypeWithNull() returns error? { string value2 = string `a,b, c, d 1, (), true, a 2, (), false, b`; - record{}[] value3 = [{"a": 1, "b": (), "c": true, "d": "a"}, {"a": 2, "b": (), "c": false, "d":"b"}]; + record {}[] value3 = [{"a": 1, "b": (), "c": true, "d": "a"}, {"a": 2, "b": (), "c": false, "d":"b"}]; string value4 = string `a,b, c, d 1, , true, a 2, , false, b`; diff --git a/ballerina-tests/user-config-tests/tests/test_data_values.bal b/ballerina-tests/user-config-tests/tests/test_data_values.bal index bf329ff..666d717 100644 --- a/ballerina-tests/user-config-tests/tests/test_data_values.bal +++ b/ballerina-tests/user-config-tests/tests/test_data_values.bal @@ -14,24 +14,24 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean? b3 = (); -boolean|int b4 = false; +final boolean b1 = true; +final false b2 = false; +final boolean? b3 = (); +final boolean|int b4 = false; -() n1 = (); -int? n2 = (); -() n3 = null; +final () n1 = (); +final int? n2 = (); +final () n3 = null; -int i1 = 1; +final int i1 = 1; -map bm1 = {b1, b2}; -map bm2 = {b1, b2, b3, n1, n3}; -map bm3 = {b1, b2, b3, b4, i1}; -map<()> bm4 = {n1, n3}; -map bm5 = {b1, b2, b3, b4:true}; +final map bm1 = {b1, b2}; +final map bm2 = {b1, b2, b3, n1, n3}; +final map bm3 = {b1, b2, b3, b4, i1}; +final map<()> bm4 = {n1, n3}; +final map bm5 = {b1, b2, b3, b4:true}; -string csvStringData1 = string ` +final string csvStringData1 = string ` a, b, c, d, e, f 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null @@ -39,7 +39,7 @@ string csvStringData1 = string ` 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; -string csvStringData2 = string ` +final string csvStringData2 = string ` hello, hello, (), 12, true, 12.34 // comment @@ -52,7 +52,7 @@ string csvStringData2 = string ` 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; -string csvStringData3 = string ` +final string csvStringData3 = string ` a, b, c, d, e, f @@ -64,14 +64,14 @@ string csvStringData3 = string ` 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; -string csvStringData4 = string ` +final string csvStringData4 = string ` 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null 3, string3, false, 1.23, 1.23, () 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; -string csvStringData5 = string ` +final string csvStringData5 = string ` @@ -83,7 +83,7 @@ string csvStringData5 = string ` 5, string5, true, 3, 3, ()`; -string csvStringData6 = string ` +final string csvStringData6 = string ` 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null @@ -93,14 +93,14 @@ string csvStringData6 = string ` 5, string5, true, 3, 3, ()`; -string csvStringData7 = string ` +final string csvStringData7 = string ` a@ b@ c@ d@ e@ f 1@ string@ true@ 2.234@ -3.21@ () 2@ s,tring@ true@ 2.234@ -3.21@ null 3@ stri,ng@ true@ 2.234@ -3.21@ () 4@ string@ true@ 2.234@ -3.21@ () 5@ string@ true@ 2.234@ -3.21@ ()`; -string csvStringData8 = string ` +final string csvStringData8 = string ` a@ b@ c@ d@ e@ f @@ -112,7 +112,7 @@ string csvStringData8 = string ` 4@ s,tring@ true@ 2.234@ -3.21@ () 5@ string@ true@ 2.234@ -3.21@ ()`; -string csvStringData9 = string ` +final string csvStringData9 = string ` 1@ string@ true@ 2.234@ -3.21@ () 2@ string@ true@ 2.234@ -3.21@ null @@ -122,7 +122,7 @@ string csvStringData9 = string ` 5@ string@ true@ 2.234@ -3.21@ null`; -string csvStringData10 = string ` +final string csvStringData10 = string ` hello, hello, (), 12, true, 12.34 // comment @@ -135,7 +135,7 @@ string csvStringData10 = string ` 4, string4, true, -6.51, -6.52, () 5, string5, true, 3, 31, ()`; -string csvStringData11 = string ` +final string csvStringData11 = string ` a, b, c, d, e, f diff --git a/ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal b/ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal index 2ad8e88..e6dd846 100644 --- a/ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal +++ b/ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal @@ -49,12 +49,12 @@ function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation2[]|csv:Error cn7 = csv:parseString(string `a,b 3,1`, {}); test:assertTrue(cn7 is csv:Error); - test:assertEquals((cn7).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn7).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation2[]|csv:Error cn8 = csv:parseString(string ` c,d,a,b 3,1,4,5`, {}); test:assertTrue(cn8 is csv:Error); - test:assertEquals((cn8).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn8).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation3[]|csv:Error cn9 = csv:parseString(string `d,c 1,3`, {}); @@ -72,12 +72,12 @@ function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation3[]|csv:Error cn12 = csv:parseString(string `a,b 3,1`, {}); test:assertTrue(cn12 is csv:Error); - test:assertEquals((cn12).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn12).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation3[]|csv:Error cn13 = csv:parseString(string ` c,d,a,b 3,1,4,5`, {}); test:assertTrue(cn13 is csv:Error); - test:assertEquals((cn13).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn13).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation4[]|csv:Error cn14 = csv:parseString(string `d,c,z 1,3,true`, {}); @@ -95,17 +95,17 @@ function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation4[]|csv:Error cn17 = csv:parseString(string `a,b 3,1`, {}); test:assertTrue(cn17 is csv:Error); - test:assertEquals((cn17).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn17).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation4[]|csv:Error cn18 = csv:parseString(string ` c,d,a,b 3,1,4,5`, {}); test:assertTrue(cn18 is csv:Error); - test:assertEquals((cn18).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn18).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation5[]|csv:Error cn19 = csv:parseString(string ` c,d,a,b 3,1,4,5`, {}); test:assertTrue(cn19 is csv:Error); - test:assertEquals((cn19).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn19).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation5[]|csv:Error cn20 = csv:parseString(string ` c,d,e 3,1,4 @@ -139,11 +139,11 @@ function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation2[]|csv:Error cnrr7 = csv:transform([{"a":3, "b": 1}], {}); test:assertTrue(cnrr7 is csv:Error); - test:assertEquals((cnrr7).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cnrr7).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation2[]|csv:Error cnrr8 = csv:transform([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); test:assertTrue(cnrr8 is csv:Error); - test:assertEquals((cnrr8).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cnrr8).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation3[]|csv:Error cnrr9 = csv:transform([{"d": 1, "c": 3}], {}); test:assertEquals(cnrr9, [{b: 1, a: 3}]); @@ -157,11 +157,11 @@ function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation3[]|csv:Error cnrr12 = csv:transform([{"a": 3, "b": 1}], {}); test:assertTrue(cnrr12 is csv:Error); - test:assertEquals((cnrr12).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cnrr12).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation3[]|csv:Error cnrr13 = csv:transform([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); test:assertTrue(cnrr13 is csv:Error); - test:assertEquals((cnrr13).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cnrr13).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation4[]|csv:Error cnrr14 = csv:transform([{"d": 1, "c": 3, "z": true}], {}); test:assertEquals(cnrr14, [{b: 1, a: 3, z: true}]); @@ -206,11 +206,11 @@ function testCustomNameAnnotation2() returns error? { RecordWithCustomAnnotation2[]|csv:Error cntr7 = csv:parseList([["3", "1"]], {customHeaders: ["a", "b"]}); test:assertTrue(cntr7 is csv:Error); - test:assertEquals((cntr7).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr7).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation2[]|csv:Error cntr8 = csv:parseList([["3", "1", "4", "5"]], {customHeaders: ["c", "d", "a", "b"]}); test:assertTrue(cntr8 is csv:Error); - test:assertEquals((cntr8).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr8).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation3[]|csv:Error cntr9 = csv:parseList([["1", "3"]], {customHeaders: ["d", "c"]}); test:assertEquals(cntr9, [{b: 1, a: 3}]); @@ -228,7 +228,7 @@ function testCustomNameAnnotation2() returns error? { RecordWithCustomAnnotation3[]|csv:Error cntr13 = csv:parseList([["3", "1", "4", "5"]], {customHeaders: ["c", "d", "a", "b"]}); test:assertTrue(cntr13 is csv:Error); - test:assertEquals((cntr13).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr13).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation4[]|csv:Error cntr14 = csv:parseList([["1", "3", "true"]], {customHeaders: ["d", "c", "z"]}); test:assertEquals(cntr14, [{b: 1, a: 3, z: true}]); @@ -242,15 +242,15 @@ function testCustomNameAnnotation2() returns error? { RecordWithCustomAnnotation4[]|csv:Error cntr17 = csv:parseList([["3", "1"]], {customHeaders: ["a", "b"]}); test:assertTrue(cntr17 is csv:Error); - test:assertEquals((cntr17).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr17).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation4[]|csv:Error cntr18 = csv:parseList([["3", "1", "4", "5"]], {customHeaders: ["c", "d", "a", "b"]}); test:assertTrue(cntr18 is csv:Error); - test:assertEquals((cntr18).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr18).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation5[]|csv:Error cntr19 = csv:parseList([["3", "1", "4", "5"]], {customHeaders: ["c", "d", "a", "b"]}); test:assertTrue(cntr19 is csv:Error); - test:assertEquals((cntr19).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr19).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation5[]|csv:Error cntr20 = csv:parseList( [["3", "1", "4"], ["3", "1", "4"]], {customHeaders: ["c", "d", "e"]}); @@ -485,45 +485,45 @@ function testDataProjectionConfig() returns error? { string csvValue1 = string `a,b "a",2 b,4`; - record{}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; + record {}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; - record{}[]|csv:Error cn = csv:parseString(csvValue1, { + record {}[]|csv:Error cn = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a; int b;|}[]|csv:Error cn_2 = csv:parseString(csvValue1, { + record {|string a; int b;|}[]|csv:Error cn_2 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a;|}[]|csv:Error cn2 = csv:parseString(csvValue1, { + record {|string a;|}[]|csv:Error cn2 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertTrue(cn2 is csv:Error); - test:assertEquals((cn2).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn2).message(), "no mapping field in the expected type for header 'b'"); - record{|string a; int...;|}[]|csv:Error cn3 = csv:parseString(csvValue1, { + record {|string a; int...;|}[]|csv:Error cn3 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn3, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string...;|}[]|csv:Error cn4 = csv:parseString(csvValue1, { + record {|string...;|}[]|csv:Error cn4 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn4, [{"a": "a", "b": "2"}, {"a": "b", "b": "4"}]); - record{|string a?;|}[]|csv:Error cn5 = csv:parseString(csvValue1, { + record {|string a?;|}[]|csv:Error cn5 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertTrue(cn5 is csv:Error); - test:assertEquals((cn5).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn5).message(), "no mapping field in the expected type for header 'b'"); - record{|string? a;|}[]|csv:Error cn6 = csv:parseString(csvValue1, { + record {|string? a;|}[]|csv:Error cn6 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertTrue(cn6 is csv:Error); - test:assertEquals((cn6).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn6).message(), "no mapping field in the expected type for header 'b'"); anydata[][]|csv:Error c7 = csv:parseString(csvValue1, { allowDataProjection: false @@ -579,95 +579,95 @@ function testDataProjectionConfig() returns error? { test:assertTrue(cn13 is csv:Error); test:assertEquals((cn13).message(), "invalid array size for expected array type, cannot be greater than '1'"); - record{}[]|csv:Error cn14 = csv:transform(csvValue2, { + record {}[]|csv:Error cn14 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertEquals(cn14, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a; int b;|}[]|csv:Error cn14_2 = csv:transform(csvValue2, { + record {|string a; int b;|}[]|csv:Error cn14_2 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertEquals(cn14_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a;|}[]|csv:Error cn15 = csv:transform(csvValue2, { + record {|string a;|}[]|csv:Error cn15 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertTrue(cn15 is csv:Error); - test:assertEquals((cn15).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn15).message(), "no mapping field in the expected type for header 'b'"); - record{|string a; int...;|}[]|csv:Error cn16 = csv:transform(csvValue2, { + record {|string a; int...;|}[]|csv:Error cn16 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertEquals(cn16, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string...;|}[]|csv:Error cn17 = csv:transform(csvValue2, { + record {|string...;|}[]|csv:Error cn17 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertEquals(cn17, [{"a": "a"}, {"a": "b"}]); - record{|string a?;|}[]|csv:Error cn18 = csv:transform(csvValue2, { + record {|string a?;|}[]|csv:Error cn18 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertTrue(cn18 is csv:Error); - test:assertEquals((cn18).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn18).message(), "no mapping field in the expected type for header 'b'"); - record{|string? a;|}[]|csv:Error cn19 = csv:transform(csvValue2, { + record {|string? a;|}[]|csv:Error cn19 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertTrue(cn19 is csv:Error); - test:assertEquals((cn19).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn19).message(), "no mapping field in the expected type for header 'b'"); - anydata[][]|csv:Error c20 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + anydata[][]|csv:Error c20 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertEquals(c20, [["a", 2], ["b", 4]]); - [string, int][]|csv:Error cn20_2 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string, int][]|csv:Error cn20_2 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertEquals(cn20_2, [["a", 2], ["b", 4]]); - [string][]|csv:Error cn21 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string][]|csv:Error cn21 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn21 is csv:Error); test:assertEquals((cn21).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); - [string][]|csv:Error cn21_2 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string][]|csv:Error cn21_2 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: {} }); test:assertEquals(cn21_2, [["a"], ["b"]]); - [int][]|csv:Error cn21_3 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [int][]|csv:Error cn21_3 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: {} }); test:assertTrue(cn21_3 is csv:Error); test:assertEquals((cn21_3).message(), common:generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); - [string, int...][]|csv:Error cn22 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string, int...][]|csv:Error cn22 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertEquals(cn22, [["a", 2], ["b", 4]]); - [string...][]|csv:Error cn23 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string...][]|csv:Error cn23 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn23 is csv:Error); test:assertEquals(( cn23).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - [string, ()][]|csv:Error cn24 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string, ()][]|csv:Error cn24 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn24 is csv:Error); test:assertEquals((cn24).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "()")); - string[][]|csv:Error cn25 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + string[][]|csv:Error cn25 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn25 is csv:Error); test:assertEquals(( cn25).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - string[][1]|csv:Error cn26 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + string[][1]|csv:Error cn26 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn26 is csv:Error); diff --git a/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal b/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal index dfbd53b..8bd7397 100644 --- a/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal +++ b/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal @@ -205,21 +205,21 @@ function testHeaderOption() { record {}[]|csv:Error csv2cop2 = csv:parseString(csvStringData10, {header: 100}); test:assertTrue(csv2cop2 is csv:Error); - test:assertEquals((csv2cop2).message(), "The provided header row is empty"); + test:assertEquals((csv2cop2).message(), "provided header row is empty"); record {}[]|csv:Error csv2cop3 = csv:parseString(csvStringData10, {header: 11}); test:assertEquals(csv2cop3, []); record {}[]|csv:Error csv2cop3_2 = csv:parseString(csvStringData10, {header: 9}); test:assertTrue(csv2cop3_2 is csv:Error); - test:assertEquals((csv2cop3_2).message(), "Duplicate header found: '1.23'"); + test:assertEquals((csv2cop3_2).message(), "duplicate header found: '1.23'"); record {}[]|csv:Error csv2cop4 = csv:parseString(csvStringData10, {header: 10}); test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", "true": true, "-6.51": 3, "-6.52": 31, "()": ()}]); record {}[]|csv:Error csv1cop5 = csv:parseString(csvStringData1, {}); test:assertTrue(csv1cop5 is csv:Error); - test:assertEquals((csv1cop5).message(), "The provided header row is empty"); + test:assertEquals((csv1cop5).message(), "provided header row is empty"); } @test:Config {dependsOn: [testCSVLocale]} @@ -354,11 +354,11 @@ function testCommentConfigOption() { cn = csv:parseString(csvValue10); test:assertTrue(cn is csv:Error); - test:assertEquals(( cn).message(), "Invalid number of headers"); + test:assertEquals(( cn).message(), "invalid number of headers"); cn = csv:parseString(csvValue9); test:assertTrue(cn is csv:Error); - test:assertEquals(( cn).message(), "The provided header row is empty"); + test:assertEquals(( cn).message(), "provided header row is empty"); } @test:Config {dependsOn: [testCSVLocale]} @@ -427,7 +427,7 @@ function testCommentConfigOption2() { cn = csv:parseString(csvValue6, {comment: "&", header: 2}); test:assertTrue(cn is csv:Error); - test:assertEquals((cn).message(), "The provided header row is empty"); + test:assertEquals((cn).message(), "provided header row is empty"); cn = csv:parseString(csvValue8, {comment: "&", header: 2}); test:assertTrue(cn is csv:Error); @@ -435,7 +435,7 @@ function testCommentConfigOption2() { cn = csv:parseString(csvValue7, {comment: "&", header: 2}); test:assertTrue(cn is csv:Error); - test:assertEquals((cn).message(), "Invalid number of headers"); + test:assertEquals((cn).message(), "invalid number of headers"); cn2 = csv:parseString(csvValue1, {comment: "&"}); test:assertTrue(cn2 is csv:Error); @@ -460,7 +460,7 @@ function testCommentConfigOption2() { cn2 = csv:parseString(csvValue6, {header: 2, comment: "&"}); test:assertTrue(cn2 is csv:Error); - test:assertEquals((cn2).message(), "The provided header row is empty"); + test:assertEquals((cn2).message(), "provided header row is empty"); } @test:Config {dependsOn: [testCSVLocale]} @@ -566,53 +566,53 @@ function testSkipLineParserOption() { @test:Config {dependsOn: [testCSVLocale]} function testCustomHeaderOption() { - anydata[][]|csv:Error bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}); + anydata[][]|csv:Error bm1ba = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - anydata[][]|csv:Error bm1ba2 = csv:transform([bm1, bm1], {headersOrder: ["b2", "b1"]}); + anydata[][]|csv:Error bm1ba2 = csv:transform([bm1, bm1], {headerOrder: ["b2", "b1"]}); test:assertEquals(bm1ba2, [ [false, true], [false, true] ]); - anydata[][]|csv:Error bm2ba = csv:transform([bm2, bm2], {headersOrder: ["b1", "n1", "b2", "n2", "b3"]}); + anydata[][]|csv:Error bm2ba = csv:transform([bm2, bm2], {headerOrder: ["b1", "n1", "b2", "n2", "b3"]}); test:assertTrue(bm2ba is csv:Error); test:assertEquals((bm2ba).message(), "CSV data rows with varying headers are not yet supported"); - anydata[][]|csv:Error bm3ba = csv:transform([bm3, bm3], {headersOrder: ["b1", "b4", "b2", "n2", "i1"]}); + anydata[][]|csv:Error bm3ba = csv:transform([bm3, bm3], {headerOrder: ["b1", "b4", "b2", "n2", "i1"]}); test:assertTrue(bm3ba is csv:Error); test:assertEquals((bm3ba).message(), "CSV data rows with varying headers are not yet supported"); - anydata[][]|csv:Error bm3ba2 = csv:transform([bm3, bm3], {headersOrder: ["b1", "b3", "b4", "b2", "i2"]}); + anydata[][]|csv:Error bm3ba2 = csv:transform([bm3, bm3], {headerOrder: ["b1", "b3", "b4", "b2", "i2"]}); test:assertTrue(bm3ba2 is csv:Error); test:assertEquals((bm3ba2).message(), "CSV data rows with varying headers are not yet supported"); - [boolean...][]|csv:Error bm3ba4 = csv:transform([bm3, bm3], {headersOrder: ["n2"]}); + [boolean...][]|csv:Error bm3ba4 = csv:transform([bm3, bm3], {headerOrder: ["n2"]}); test:assertTrue(bm3ba4 is csv:Error); - test:assertEquals((bm3ba4).message(), "Invalid number of headers"); + test:assertEquals((bm3ba4).message(), "invalid number of headers"); - [boolean...][]|csv:Error bm3ba5 = csv:transform([bm3, bm3], {headersOrder: []}); + [boolean...][]|csv:Error bm3ba5 = csv:transform([bm3, bm3], {headerOrder: []}); test:assertTrue(bm3ba5 is csv:Error); - test:assertEquals((bm3ba5).message(), "Invalid number of headers"); + test:assertEquals((bm3ba5).message(), "invalid number of headers"); record {}[]|csv:Error ct1br = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "b"]}); test:assertTrue(ct1br is csv:Error); - test:assertEquals((ct1br).message(), "Invalid number of headers"); + test:assertEquals((ct1br).message(), "invalid number of headers"); record {}[]|csv:Error ct1br2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "b", "c", "d"]}); test:assertTrue(ct1br2 is csv:Error); - test:assertEquals((ct1br2).message(), "Invalid number of headers"); + test:assertEquals((ct1br2).message(), "invalid number of headers"); record {}[]|csv:Error ct1br2_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "c", "b", "d"]}); test:assertTrue(ct1br2_2 is csv:Error); - test:assertEquals((ct1br2_2).message(), "Invalid number of headers"); + test:assertEquals((ct1br2_2).message(), "invalid number of headers"); record {}[]|csv:Error ct1br3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: []}); test:assertTrue(ct1br3 is csv:Error); - test:assertEquals((ct1br3).message(), "Invalid number of headers"); + test:assertEquals((ct1br3).message(), "invalid number of headers"); record {|string a; string b; string c;|}[]|csv:Error ct1br5 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"]}); test:assertTrue(ct1br5 is csv:Error); @@ -686,11 +686,11 @@ function testCustomHeaderParserOption2() { record {}[]|csv:Error ct1br2 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: []}); test:assertTrue(ct1br2 is csv:Error); - test:assertEquals((ct1br2).message(), "Invalid number of headers"); + test:assertEquals((ct1br2).message(), "invalid number of headers"); record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br3 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); test:assertTrue(ct1br3 is csv:Error); - test:assertEquals((ct1br3).message(), "Invalid number of headers"); + test:assertEquals((ct1br3).message(), "invalid number of headers"); record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br4 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(ct1br4, [ @@ -761,7 +761,7 @@ function testCustomHeaderParserOption2() { record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1"]}); test:assertTrue(ct1br11 is csv:Error); - test:assertEquals((ct1br11).message(), "Invalid number of headers"); + test:assertEquals((ct1br11).message(), "invalid number of headers"); record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ @@ -837,12 +837,12 @@ function testTextQuotesWithParserOptions() { record {}[]|csv:Error cn6 = csv:parseString(csvValue6, {}); test:assertTrue(cn6 is csv:Error); - test:assertEquals((cn6).message(), "Invalid number of headers"); + test:assertEquals((cn6).message(), "invalid number of headers"); cn6 = csv:parseString(string `a,b,c,d 1,1,1,1,1`, {}); test:assertTrue(cn6 is csv:Error); - test:assertEquals((cn6).message(), "Invalid number of headers"); + test:assertEquals((cn6).message(), "invalid number of headers"); } @test:Config @@ -1001,30 +1001,30 @@ function testSkipLineParameterWithOutputHeaderConfig() { result2 = csv:parseList(csv2, {outputWithHeaders: true, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [1, 2], [4, 5]]); - result = csv:parseList(csv2, {headersRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + result = csv:parseList(csv2, {headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result, [{a: 2, b: 3}]); - result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [2, 3]]); - result = csv:parseList(csv2, {headersRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); + result = csv:parseList(csv2, {headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result, [{a: 3, b: 4}]); - result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [3, 4]]); - result = csv:parseList(csv2, {headersRows: 1, skipLines: "2-3"}); + result = csv:parseList(csv2, {headerRows: 1, skipLines: "2-3"}); test:assertEquals(result, [{'1: 2, '2: 3}]); - result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 1, skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3"}); test:assertEquals(result2, [[1, 2], [2, 3]]); - result2 = csv:parseList(csv2, {outputWithHeaders: false, headersRows: 1, skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: false, headerRows: 1, skipLines: "2-3"}); test:assertEquals(result2, [[2, 3]]); - result = csv:parseList(csv2, {headersRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); + result = csv:parseList(csv2, {headerRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); test:assertEquals(result, [{a: 3, b: 4}]); - result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); test:assertEquals(result2, [["a", "b"], [3, 4]]); } diff --git a/ballerina-tests/user-config-tests/tests/user_configs.bal b/ballerina-tests/user-config-tests/tests/user_configs.bal index de47edf..8a38db6 100644 --- a/ballerina-tests/user-config-tests/tests/user_configs.bal +++ b/ballerina-tests/user-config-tests/tests/user_configs.bal @@ -17,29 +17,29 @@ import ballerina/data.csv; // Valid parser options -csv:ParseOptions option1 = {delimiter: "@", nilValue: "null", lineTerminator: [csv:LF]}; -csv:ParseOptions option2 = {nilValue: "N/A", lineTerminator: [csv:CRLF, csv:LF], comment: "/"}; -csv:ParseOptions option3 = {nilValue: "()", header: 1, skipLines: [1, 2]}; -csv:ParseOptions option4 = {nilValue: "", header: 4, skipLines: "1-5"}; -csv:ParseOptions option5 = {nilValue: "", header: 4, skipLines: "1-1"}; -csv:ParseOptions option6 = {nilValue: "()", header: false, skipLines: [1, 2]}; +final csv:ParseOptions option1 = {delimiter: "@", nilValue: "null", lineTerminator: [csv:LF]}; +final csv:ParseOptions option2 = {nilValue: "N/A", lineTerminator: [csv:CRLF, csv:LF], comment: "/"}; +final csv:ParseOptions option3 = {nilValue: "()", header: 1, skipLines: [1, 2]}; +final csv:ParseOptions option4 = {nilValue: "", header: 4, skipLines: "1-5"}; +final csv:ParseOptions option5 = {nilValue: "", header: 4, skipLines: "1-1"}; +final csv:ParseOptions option6 = {nilValue: "()", header: false, skipLines: [1, 2]}; -csv:ParseOptions ptOption1 = {nilValue: "", header: 1, skipLines: [2, 4]}; -csv:ParseOptions ptOption2 = {nilValue: "", header: 1, skipLines: "2-4"}; -csv:ParseOptions ptOption3 = {nilValue: "", header: 4, skipLines: "1-5"}; -csv:ParseOptions ptOption4 = {nilValue: "", header: 4, skipLines: [-1, -2, 4, 2]}; -csv:ParseOptions ptOption5 = {header: false, skipLines: [-1, -2, 5, 3]}; +final csv:ParseOptions ptOption1 = {nilValue: "", header: 1, skipLines: [2, 4]}; +final csv:ParseOptions ptOption2 = {nilValue: "", header: 1, skipLines: "2-4"}; +final csv:ParseOptions ptOption3 = {nilValue: "", header: 4, skipLines: "1-5"}; +final csv:ParseOptions ptOption4 = {nilValue: "", header: 4, skipLines: [-1, -2, 4, 2]}; +final csv:ParseOptions ptOption5 = {header: false, skipLines: [-1, -2, 5, 3]}; // Invalid parser options -csv:ParseOptions invalidParserOptions1 = {header: 4}; -csv:ParseOptions invalidParserOptions2 = {comment: "$"}; -csv:ParseOptions invalidParserOptions3 = {lineTerminator: csv:CRLF}; -csv:ParseOptions invalidParserOptions4 = {skipLines: [1000, 1001]}; -csv:ParseOptions invalidParserOptions5 = {skipLines: "a-b"}; -csv:ParseOptions invalidParserOptions6 = {skipLines: "3-1"}; -csv:ParseOptions invalidParserOptions7 = {skipLines: "a-5"}; -csv:ParseOptions invalidParserOptions8 = {skipLines: "6-a"}; -csv:ParseOptions invalidParserOptions9 = {skipLines: "a-5"}; -csv:ParseOptions invalidParserOptions10 = {skipLines: "-1-6"}; -csv:ParseOptions invalidParserOptions11 = {nilValue: "", header: 4, skipLines: "0-10"}; -csv:ParseOptions invalidParserOptions12 = {skipLines: [1, 3, 4, -1]}; +final csv:ParseOptions invalidParserOptions1 = {header: 4}; +final csv:ParseOptions invalidParserOptions2 = {comment: "$"}; +final csv:ParseOptions invalidParserOptions3 = {lineTerminator: csv:CRLF}; +final csv:ParseOptions invalidParserOptions4 = {skipLines: [1000, 1001]}; +final csv:ParseOptions invalidParserOptions5 = {skipLines: "a-b"}; +final csv:ParseOptions invalidParserOptions6 = {skipLines: "3-1"}; +final csv:ParseOptions invalidParserOptions7 = {skipLines: "a-5"}; +final csv:ParseOptions invalidParserOptions8 = {skipLines: "6-a"}; +final csv:ParseOptions invalidParserOptions9 = {skipLines: "a-5"}; +final csv:ParseOptions invalidParserOptions10 = {skipLines: "-1-6"}; +final csv:ParseOptions invalidParserOptions11 = {nilValue: "", header: 4, skipLines: "0-10"}; +final csv:ParseOptions invalidParserOptions12 = {skipLines: [1, 3, 4, -1]}; diff --git a/ballerina/Package.md b/ballerina/Package.md index ff1deb2..79dcd39 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -38,7 +38,7 @@ public function main() returns error? { ### Converting external CSV document to a record value -For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. +For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte block stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. ```ballerina import ballerina/data.csv; @@ -111,7 +111,7 @@ type Book record {| |}; public function main() returns error? { - record{}[] csvContent = [{ + record {}[] csvContent = [{ "name": "Clean Code", "author": "Robert C. Martin", "year": 2008, diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 66527eb..e39b2ce 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -16,91 +16,96 @@ import ballerina/jballerina.java; -# Converts CSV string to subtype of `record{}[]` or `anydata[][]`. +# Parse a CSV string as a subtype of `record {}[]` or `anydata[][]`. +# # ```ballerina # string csvString = string `id,name # 1,John # 3,Jane`; -# record{int id; string name;}[] csv1 = check csv:parseString(csvString); +# record {int id; string name;}[] csv1 = check csv:parseString(csvString); # [int, string][] csv2 = check csv:parseString(csvString); -# record{|int id;|}[] csv3 = check csv:parseString(csvString); -# record{int id;}[] csv4 = check csv:parseString(csvString, {skipLines: [1]}); +# record {|int id;|}[] csv3 = check csv:parseString(csvString); +# record {int id;}[] csv4 = check csv:parseString(csvString, {skipLines: [1]}); # ``` # # + csvString - Source CSV string value # + options - Options to be used for filtering in the projection # + t - Target type # + return - On success, value belonging to the given target type, else returns an `csv:Error` value. -public isolated function parseString(string csvString, ParseOptions options = {}, typedesc t = <>) +public isolated function parseString(string csvString, ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -# Converts byte[] to subtype of `record{}[]` or `anydata[][]`. +# Parse a byte[] as a subtype of `record {}[]` or `anydata[][]`. +# # ```ballerina # byte[] csvBytes = check io:fileReadBytes("example.csv"); # -# record{int id; string name;}[] csv1 = check csv:parseBytes(csvBytes); +# record {int id; string name;}[] csv1 = check csv:parseBytes(csvBytes); # [int, string][] csv2 = check csv:parseBytes(csvBytes); -# record{|int id;|}[] csv3 = check csv:parseBytes(csvBytes); -# record{int id;}[] csv4 = check csv:parseBytes(csvBytes, {skipLines: [1]}); +# record {|int id;|}[] csv3 = check csv:parseBytes(csvBytes); +# record {int id;}[] csv4 = check csv:parseBytes(csvBytes, {skipLines: [1]}); # ``` # # + csvBytes - Source CSV byte array # + options - Options to be used for filtering in the projection # + t - Target type # + return - On success, value belonging to the given target type, else returns an `csv:Error` value. -public isolated function parseBytes(byte[] csvBytes, ParseOptions options = {}, typedesc t = <>) +public isolated function parseBytes(byte[] csvBytes, ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -# Converts CSV byte-block-stream to subtype of `record{}[]` or `anydata[][]`. +# Parse a CSV byte block stream as a subtype of `record {}[]` or `anydata[][]`. +# # ```ballerina # stream csvByteStream = check io:fileReadBlocksAsStream("example.csv"); -# record{int id; string name;}[] csv1 = check csv:parseStream(csvByteStream); +# record {int id; string name;}[] csv1 = check csv:parseStream(csvByteStream); # # stream csvByteStream2 = check io:fileReadBlocksAsStream("example.csv"); # [int, string][] csv2 = check csv:parseStream(csvByteStream2); # # stream csvByteStream3 = check io:fileReadBlocksAsStream("example.csv"); -# record{|int id;|}[] csv3 = check csv:parseStream(csvByteStream3); +# record {|int id;|}[] csv3 = check csv:parseStream(csvByteStream3); # # stream csvByteStream4 = check io:fileReadBlocksAsStream("example.csv"); -# record{int id;}[] csv4 = check csv:parseStream(csvByteStream4, {skipLines: [1]}); +# record {int id;}[] csv4 = check csv:parseStream(csvByteStream4, {skipLines: [1]}); # ``` # -# + csvByteStream - Source CSV byte-block-stream +# + csvByteStream - Source CSV byte block stream # + options - Options to be used for filtering in the projection # + t - Target type # + return - On success, value belonging to the given target type, else returns an `csv:Error` value. public isolated function parseStream(stream csvByteStream, - ParseOptions options = {}, typedesc t = <>) + ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -# Convert value of type record{}[] to subtype of `record{}[]` or `anydata[][]`. +# Transform value of type record {}[] to subtype of `record {}[]` or `anydata[][]`. +# # ```ballerina -# record{int id; string name;}[] csvRecords = [{id: 1, name: "John"}, {id: 2, name: "Jane"}]; +# record {int id; string name;}[] csvRecords = [{id: 1, name: "John"}, {id: 2, name: "Jane"}]; # [int, string][] csv1 = check csv:transform(csvRecords); -# record{|int id;|}[] csv2 = check csv:transform(csvRecords); -# record{int id;}[] csv3 = check csv:transform(csvRecords, {skipLines: [1]}); +# record {|int id;|}[] csv2 = check csv:transform(csvRecords); +# record {int id;}[] csv3 = check csv:transform(csvRecords, {skipLines: [1]}); # ``` # # + csvRecords - Source Ballerina record array value # + options - Options to be used for filtering in the projection # + t - Target type # + return - On success, returns value belonging to the given target type, else returns an `csv:Error` value. -public isolated function transform(record{}[] csvRecords, - TransformOptions options = {}, typedesc t = <>) +public isolated function transform(record {}[] csvRecords, + TransformOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -# Convert value of type string array of array to subtype of `record{}[]` or `anydata[][]`. +# Parse a string array of array as a subtype of `record {}[]` or `anydata[][]`. +# # ```ballerina # string[][] csvList = [["1", "John"], ["2", "Jane"]]; # [int, string][] csv1 = check csv:parseList(csvList); -# record{|int id;|}[] csv2 = check csv:parseList(csvList, {customHeaders: ["id", "name"]}); -# record{int id;}[] csv3 = check csv:parseList(csvList, {skipLines: [1], customHeaders: ["id", "name"]}); +# record {|int id;|}[] csv2 = check csv:parseList(csvList, {customHeaders: ["id", "name"]}); +# record {int id;}[] csv3 = check csv:parseList(csvList, {skipLines: [1], customHeaders: ["id", "name"]}); # ``` # # + csvList - Source Ballerina string array of array value # + options - Options to be used for filtering in the projection # + t - Target type # + return - On success, returns value belonging to the given target type, else returns an `csv:Error` value. -public isolated function parseList(string[][] csvList, ParseListOptions options = {}, typedesc t = <>) +public isolated function parseList(string[][] csvList, ParseListOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; diff --git a/ballerina/types.bal b/ballerina/types.bal index c825679..84b5502 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -31,9 +31,9 @@ public const annotation NameConfig Name on record field; public type Options record { # Allows data projection with specific settings. # - # This configuration can be either a record or a boolean. - # If it's a record, it contains `nilAsOptionalField` and `absentAsNilableType` options. - # If it's set to `false`, data projection is not allowed. + # This configuration can be either a record or false. + # If it is a record, it contains `nilAsOptionalField` and `absentAsNilableType` options. + # If it is set to `false`, data projection is not allowed. record { # If `true`, nil values will be considered as optional fields in the projection. boolean nilAsOptionalField = false; @@ -78,19 +78,19 @@ public type ParseListOptions record {| *Options; # If `0`, all the source data will treat as data rows. # Otherwise specify the header rows(Starts from 1) in the source data. - int:Unsigned32 headersRows = 0; + int:Unsigned32 headerRows = 0; # Specify the header names of the source data. # This field will overwrite the header values in the header rows. # This will be mandatory if the header row parameter is larger than one. - string[]? customHeaders = (); + string[] customHeaders?; |}; # Represents options for treating a list as a record. public type TransformOptions record {| *Options; # Specify the order of the headers in the source data. - # If the expected type is a subset of `record{}[]` this parameter will be ignored. - string[]? headersOrder = (); + # If the expected type is a subset of `record {}[]` this parameter will be ignored. + string[]? headerOrder = (); |}; # Enum representing possible line terminators. @@ -110,5 +110,5 @@ public enum NilValue { # Represents an empty string as a nil value. EMPTY_STRING = "", # Represents a nil value as Ballerina nil value `()`. - BAL_NULL = "()" + NIL = "()" }; diff --git a/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTest.java b/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTest.java index 5c73016..086355b 100644 --- a/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTest.java +++ b/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTest.java @@ -45,7 +45,7 @@ public class CompilerPluginTest { "Tuple members can only be basic types, other types are not supported."; static final String IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY = "The option 'outputWithHeaders' will be not allowed" + " since the expected type is a subtype record array."; - static final String IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY = "The option 'headersOrder' will be not allowed" + + static final String IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY = "The option 'headerOrder' will be not allowed" + " since the expected type is a subtype record array."; static final String IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT = "The option " + "'customHeadersIfHeadersAbsent' will be not allowed since the header is present."; @@ -222,7 +222,7 @@ public void testIgnoredOutputHeaderOptions() { } @Test - public void testIgnoredHeadersOrderOptions() { + public void testIgnoredheaderOrderOptions() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_9").getCompilation().diagnosticResult(); List errorDiagnosticsList = diagnosticResult.diagnostics().stream() diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/main.bal index e4a416c..9052621 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/main.bal @@ -7,27 +7,27 @@ public function main() returns error? { [[int, string], [int, string]]|error v = csv:parseString(string `a,b`, {}); [[int, string], [int, string]]|[anydata...][]|error a = csv:parseString(string `a,b`, {}); - [record{}, record{}, record{}, record{}] _ = check csv:parseString(string `a,b`, {}); + [record {}, record {}, record {}, record {}] _ = check csv:parseString(string `a,b`, {}); [[int, string], [int, string]] _ = check csv:parseStream(s, {}); - [record{}, record{}, record{}, record{}] _ = check csv:parseStream(s, {}); + [record {}, record {}, record {}, record {}] _ = check csv:parseStream(s, {}); A _ = check csv:parseBytes([1,2,3], {}); - record{}[]|[record{}, record{}, record{}, record{}] _ = check csv:parseBytes([1,2,3], {}); + record {}[]|[record {}, record {}, record {}, record {}] _ = check csv:parseBytes([1,2,3], {}); int[][]|[[int, string], [int, string]] _ = check csv:transform([{}], {}); [[int, string], [int, string]] _ = check csv:parseList([], {}); - [record{}, record{}, record{}, record{}] _ = check csv:transform([{}], {}); - [record{}, record{}, record{}, record{}] _ = check csv:parseList([], {}); - record{record{} a;}[] _ = check csv:parseList([], {}); - record{int[] a;}[] _ = check csv:parseList([], {}); - record{[int...] a;}[] _ = check csv:parseList([], {}); - record{[int...] a;}[] _ = check csv:parseList([], {}); - record{record{} a;}[] _ = check csv:parseList([], {}); - record{xml a; regexp:RegExp b;}[] _ = check csv:parseList([], {}); + [record {}, record {}, record {}, record {}] _ = check csv:transform([{}], {}); + [record {}, record {}, record {}, record {}] _ = check csv:parseList([], {}); + record {record {} a;}[] _ = check csv:parseList([], {}); + record {int[] a;}[] _ = check csv:parseList([], {}); + record {[int...] a;}[] _ = check csv:parseList([], {}); + record {[int...] a;}[] _ = check csv:parseList([], {}); + record {record {} a;}[] _ = check csv:parseList([], {}); + record {xml a; regexp:RegExp b;}[] _ = check csv:parseList([], {}); [xml, xml][] _ = check csv:parseList([], {}); [regexp:RegExp, xml, int[]][]|csv:Error v2 = csv:parseList([], {}); [regexp:RegExp, xml, int[]][]|int[][] _ = check csv:parseList([], {}); int[][]|[regexp:RegExp, xml, int[]][] _ = check csv:parseList([], {}); - int[][]|[record{}|regexp:RegExp][] _ = check csv:parseList([], {}); - record{}[]|int[][] _ = check csv:parseList([], {}); - record{}[2] _ = check csv:parseList([], {}); + int[][]|[record {}|regexp:RegExp][] _ = check csv:parseList([], {}); + record {}[]|int[][] _ = check csv:parseList([], {}); + record {}[2] _ = check csv:parseList([], {}); int[3][2] _ = check csv:parseList([], {}); } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal index 70bbb6e..666f10f 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal @@ -2,57 +2,57 @@ import ballerina/data.csv; string[]? headers = (); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: false}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: false}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); public function main() returns error? { - record{}[] val = check csv:parseList([["1", "2"]], {headersRows: 0}); - val = check csv:parseList([["1", "2"]], {headersRows: 0}); + record {}[] val = check csv:parseList([["1", "2"]], {headerRows: 0}); + val = check csv:parseList([["1", "2"]], {headerRows: 0}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); - val = check csv:parseList([["1", "2"]], {headersRows: 1}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1}); + val = check csv:parseList([["1", "2"]], {headerRows: 1}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); - val = check csv:parseList([["1", "2"]], {headersRows: 2}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2}); + val = check csv:parseList([["1", "2"]], {headerRows: 2}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: true}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: true}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal index b548c58..d40a261 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal @@ -13,7 +13,7 @@ public function main() returns error? { record {} _ = test3({headerRows: 2, outputWithHeaders: false}); } -function test1(A a) returns record{}[] { +function test1(A a) returns record {}[] { return [{}]; } @@ -21,6 +21,6 @@ function test2(A a) returns [int...][] { return []; } -function test3(A a) returns record{} { +function test3(A a) returns record {} { return {}; } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal index f1ca8d8..a7a5241 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal @@ -2,57 +2,57 @@ import ballerina/data.csv; string[]? headers = (); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: false}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: false}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); public function main() returns error? { - [anydata...][] val = check csv:parseList([["1", "2"]], {headersRows: 0}); - val = check csv:parseList([["1", "2"]], {headersRows: 0}); + [anydata...][] val = check csv:parseList([["1", "2"]], {headerRows: 0}); + val = check csv:parseList([["1", "2"]], {headerRows: 0}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); - val = check csv:parseList([["1", "2"]], {headersRows: 1}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1}); + val = check csv:parseList([["1", "2"]], {headerRows: 1}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); - val = check csv:parseList([["1", "2"]], {headersRows: 2}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2}); + val = check csv:parseList([["1", "2"]], {headerRows: 2}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: true}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: true}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/main.bal index 08aeee3..ebad20f 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/main.bal @@ -4,14 +4,14 @@ type A [[int, string], [int, string]]; stream s = ( [[1, 2, 3, 4, 5]]).toStream(); [[int, string], [int, string]] val = check csv:parseString(string `a,b`, {}); -[record{}, record{}, record{}, record{}] val2 = check csv:parseString(string `a,b`, {}); +[record {}, record {}, record {}, record {}] val2 = check csv:parseString(string `a,b`, {}); [[int, string], [int, string]] val3 = check csv:parseStream(s, {}); -[record{}, record{}, record{}, record{}] val4 = check csv:parseStream(s, {}); +[record {}, record {}, record {}, record {}] val4 = check csv:parseStream(s, {}); A val5 = check csv:parseBytes([1,2,3], {}); -record{}[]|[record{}, record{}, record{}, record{}] val6 = check csv:parseBytes([1,2,3], {}); +record {}[]|[record {}, record {}, record {}, record {}] val6 = check csv:parseBytes([1,2,3], {}); int[][]|[[int, string], [int, string]] val7 = check csv:transform([{}], {}); [[int, string], [int, string]] val8 = check csv:parseList([], {}); -[record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); -[record{}, record{}, record{}, record{}] val10 = check csv:parseList([], {}); -record{}[2] val11 = check csv:parseList([], {}); +[record {}, record {}, record {}, record {}] val9 = check csv:transform([{}], {}); +[record {}, record {}, record {}, record {}] val10 = check csv:parseList([], {}); +record {}[2] val11 = check csv:parseList([], {}); int[3][2] val12 = check csv:parseList([], {}); diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/main.bal index 0d1fa56..2574a7f 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/main.bal @@ -10,15 +10,15 @@ public function test() returns error? { stream s = ( [[1, 2, 3, 4, 5]]).toStream(); [[int, string], [int, string]] val = check csv:parseString(string `a,b`, {}); - [record{}, record{}, record{}, record{}] val2 = check csv:parseString(string `a,b`, {}); + [record {}, record {}, record {}, record {}] val2 = check csv:parseString(string `a,b`, {}); [[int, string], [int, string]] val3 = check csv:parseStream(s, {}); - [record{}, record{}, record{}, record{}] val4 = check csv:parseStream(s, {}); + [record {}, record {}, record {}, record {}] val4 = check csv:parseStream(s, {}); A val5 = check csv:parseBytes([1,2,3], {}); - record{}[]|[record{}, record{}, record{}, record{}] val6 = check csv:parseBytes([1,2,3], {}); + record {}[]|[record {}, record {}, record {}, record {}] val6 = check csv:parseBytes([1,2,3], {}); int[][]|[[int, string], [int, string]] val7 = check csv:transform([{}], {}); [[int, string], [int, string]] val8 = check csv:parseList([], {}); - [record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); - [record{}, record{}, record{}, record{}] val10 = check csv:parseList([], {}); - record{}[2] val11 = check csv:parseList([], {}); + [record {}, record {}, record {}, record {}] val9 = check csv:transform([{}], {}); + [record {}, record {}, record {}, record {}] val10 = check csv:parseList([], {}); + record {}[2] val11 = check csv:parseList([], {}); int[3][2] val12 = check csv:parseList([], {}); } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal index e9a1acb..1251720 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal @@ -4,20 +4,20 @@ string[] customHeaders = ["a", "b"]; int:Unsigned32 header = 0; false header2 = false; -record{}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); -record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); -record{}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); -record{}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); -record{}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); -record{}[] val6 = check csv:parseString(string `a, b`, {header: false}); -record{}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); -record{}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); -record{}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); -record{}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); -record{}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); -record{}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); -record{}[]|error val13 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); -record{}[]|[int...][]|error val14 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); +record {}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); +record {}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); +record {}[] val6 = check csv:parseString(string `a, b`, {header: false}); +record {}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); +record {}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); +record {}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); +record {}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); +record {}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); +record {}[]|error val13 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[]|[int...][]|error val14 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); anydata[][] arrVal = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); anydata[][] arrVal2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); @@ -35,46 +35,46 @@ anydata[][]|error arrVal13 = csv:parseString(string `a, b`, {header: 0, customHe anydata[][]|[int...][]|error arrVal14 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); public function main() returns error? { - record{}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); val = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); - record{}[]|error val_2 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[]|error val_2 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); val_2 = csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); - record{}[]|record{int a;}[]|error val_3 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[]|record {int a;}[]|error val_3 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); val_3 = csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); - record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); + record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); val2 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ()}); - record{}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); val3 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); - record{}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); + record {}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); val4 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ()}); - record{}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); + record {}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); val5 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ()}); - record{}[] val6 = check csv:parseString(string `a, b`, {header: false}); + record {}[] val6 = check csv:parseString(string `a, b`, {header: false}); val6 = check csv:parseString(string ``, {header: false}); - record{}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); val7 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ["a", "b"]}); - record{}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); + record {}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); val8 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: null}); - record{}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); + record {}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); val9 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: null}); - record{}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); + record {}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); val10 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); - record{}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); + record {}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); - record{}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); + record {}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); val11 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); anydata[][] arrVal = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal index ee021b2..92ae689 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal @@ -1,18 +1,18 @@ import ballerina/data.csv; boolean o = false; -record{}[] val = check csv:parseString(string `a, b`, {outputWithHeaders: false}); -record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: true}); -record{}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); -record{}[] val4 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); +record {}[] val = check csv:parseString(string `a, b`, {outputWithHeaders: false}); +record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: true}); +record {}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val4 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); public function main() returns error? { - record{}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"], outputWithHeaders: false}); + record {}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"], outputWithHeaders: false}); val = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"], outputWithHeaders: true}); - record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: false}); + record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: false}); val2 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: true}); - record{}[] val3 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); + record {}[] val3 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); val3 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal index 669fe19..2a4dedf 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal @@ -1,22 +1,22 @@ import ballerina/data.csv; boolean o = false; -string[] headersOrder = ["a", "b"]; -record{}[] val = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"], outputWithHeaders: false}); -record{}[] val2 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"]}); -record{}[] val3 = check csv:transform([{"a": 1, "b": 2}], {"header": false, headersOrder: headersOrder}); -record{}[] val4 = check csv:transform([{"a": 1, "b": 2}], {outputWithHeaders: o, headersOrder: ()}); +string[] headerOrder = ["a", "b"]; +record {}[] val = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ["a", "b"], outputWithHeaders: false}); +record {}[] val2 = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ["a", "b"]}); +record {}[] val3 = check csv:transform([{"a": 1, "b": 2}], {"header": false, headerOrder: headerOrder}); +record {}[] val4 = check csv:transform([{"a": 1, "b": 2}], {outputWithHeaders: o, headerOrder: ()}); public function main() returns error? { - record{}[] val = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ()}); - val = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ()}); + record {}[] val = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ()}); + val = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ()}); - record{}[] val2 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"], outputWithHeaders: false}); - val2 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"], outputWithHeaders: true}); + record {}[] val2 = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ["a", "b"], outputWithHeaders: false}); + val2 = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ["a", "b"], outputWithHeaders: true}); - record{}[] val3 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: null}); - val3 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: null}); + record {}[] val3 = check csv:transform([{"a": 1, "b": 2}], {headerOrder: null}); + val3 = check csv:transform([{"a": 1, "b": 2}], {headerOrder: null}); - record{}[] val4 = check csv:transform([{"a": 1, "b": 2}], {headersOrder}); - val4 = check csv:transform([{"a": 1, "b": 2}], {headersOrder}); + record {}[] val4 = check csv:transform([{"a": 1, "b": 2}], {headerOrder}); + val4 = check csv:transform([{"a": 1, "b": 2}], {headerOrder}); } diff --git a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java index d768a0c..93e396d 100644 --- a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java @@ -34,7 +34,7 @@ public final class Constants { static final String BALLERINA = "ballerina"; static final String DATA_CSVDATA = "data.csv"; static final String FALSE = "false"; - static final String BAL_NULL = "()"; + static final String NIL = "()"; static final String NULL = "null"; static class UserConfigurations { @@ -42,10 +42,10 @@ private UserConfigurations() { } static final String OUTPUT_WITH_HEADERS = "outputWithHeaders"; - static final String HEADERS_ORDER = "headersOrder"; + static final String HEADERS_ORDER = "headerOrder"; static final String HEADER = "header"; static final String CUSTOM_HEADERS = "customHeaders"; - static final String HEADERS_ROWS = "headersRows"; + static final String HEADERS_ROWS = "headerRows"; static final String CUSTOM_HEADERS_IF_ABSENT = "customHeadersIfHeadersAbsent"; } diff --git a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java index 5104c40..5361b38 100644 --- a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java @@ -36,7 +36,7 @@ public enum CsvDataDiagnosticCodes { "be basic types, other types are not supported.", ERROR), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'outputWithHeaders' will " + "be not allowed since the expected type is a subtype record array.", ERROR), - IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'headersOrder' will " + + IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'headerOrder' will " + "be not allowed since the expected type is a subtype record array.", ERROR), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT("CSV_ERROR_6", "The option 'customHeadersIfHeadersAbsent' will be not " + diff --git a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java index 3892956..7d33b08 100644 --- a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java @@ -71,12 +71,13 @@ import io.ballerina.tools.diagnostics.DiagnosticSeverity; import io.ballerina.tools.diagnostics.Location; -import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; /** * CsvData Record Field Validator. @@ -203,14 +204,12 @@ private void checkTypeAndDetectDuplicateFields(TypeSymbol typeSymbol, SyntaxNode } private FunctionCallExpressionNode getFunctionCallExpressionNodeIfPresent(ExpressionNode expressionNode) { - if (expressionNode.kind() == SyntaxKind.CHECK_EXPRESSION) { - expressionNode = ((CheckExpressionNode) expressionNode).expression(); - } - - if (expressionNode.kind() != SyntaxKind.FUNCTION_CALL) { - return null; - } - return ((FunctionCallExpressionNode) expressionNode); + return switch(expressionNode.kind()) { + case CHECK_EXPRESSION -> getFunctionCallExpressionNodeIfPresent( + ((CheckExpressionNode) expressionNode).expression()); + case FUNCTION_CALL -> (FunctionCallExpressionNode) expressionNode; + default -> null; + }; } private String getFunctionName(FunctionCallExpressionNode node) { @@ -265,8 +264,8 @@ private void validateFunctionParameterTypesWithExpType(TypeSymbol expType, Locat List memberTypes = ((UnionTypeSymbol) expType).memberTypeDescriptors(); // only handles the A|error scenarios - if (isUnionContainsError(memberTypes)) { - if (memberTypes.size() == 2) { + if (memberTypes.size() == 2) { + if (isUnionContainsError(memberTypes)) { TypeSymbol nonErrorTypeSymbol = ignoreErrorTypeFromUnionTypeSymbolAndReturn(memberTypes); if (nonErrorTypeSymbol != null) { validateFunctionParameterTypesWithExpType(nonErrorTypeSymbol, currentLocation, @@ -307,7 +306,7 @@ private TypeSymbol ignoreErrorTypeFromUnionTypeSymbolAndReturn(List private void validateFunctionParameterTypesWithArrayType(ArrayTypeSymbol expType, Location currentLocation, SyntaxNodeAnalysisContext ctx, String functionName, - SeparatedNodeList args) { + SeparatedNodeList args) { TypeSymbol memberTypeSymbol = expType.memberTypeDescriptor(); if (memberTypeSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { memberTypeSymbol = ((TypeReferenceTypeSymbol) memberTypeSymbol).typeDescriptor(); @@ -324,10 +323,11 @@ private void validateFunctionParameterTypesWithOptions(Location currentLocation, String functionName, SeparatedNodeList args, boolean isRecord) { ExpressionNode expression; SeparatedNodeList fields; - String header = null, headersRows = null, customHeaders = null, - customHeadersIfHeaderAbsent = null, outputWithHeaders = null, headersOrder = null; + String header = null, headerRows = null, customHeaders = null, + customHeadersIfHeaderAbsent = null, outputWithHeaders = null, headerOrder = null; boolean isCustomHeaderPresent = false; for (FunctionArgumentNode arg : args) { + int mappingConstructorExprNodeCount = 0; if (arg instanceof PositionalArgumentNode positionalArgumentNode) { expression = positionalArgumentNode.expression(); } else if (arg instanceof NamedArgumentNode namedArgumentNode) { @@ -336,6 +336,7 @@ private void validateFunctionParameterTypesWithOptions(Location currentLocation, continue; } if (expression instanceof MappingConstructorExpressionNode mappingConstructorExpressionNode) { + checkAndAssertMappingConstructorArguments(mappingConstructorExprNodeCount); fields = mappingConstructorExpressionNode.fields(); for (MappingFieldNode field : fields) { if (field instanceof SpecificFieldNode specificFieldNode) { @@ -349,14 +350,14 @@ private void validateFunctionParameterTypesWithOptions(Location currentLocation, customHeadersIfHeaderAbsent = getTheValueOfTheUserConfigOption(specificFieldNode); } if (fieldName.equals(Constants.UserConfigurations.HEADERS_ROWS)) { - headersRows = getTheValueOfTheUserConfigOption(specificFieldNode); + headerRows = getTheValueOfTheUserConfigOption(specificFieldNode); } if (fieldName.equals(Constants.UserConfigurations.CUSTOM_HEADERS)) { customHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); isCustomHeaderPresent = true; } if (isRecord && fieldName.equals(Constants.UserConfigurations.HEADERS_ORDER)) { - headersOrder = getTheValueOfTheUserConfigOption(specificFieldNode); + headerOrder = getTheValueOfTheUserConfigOption(specificFieldNode); } if (isRecord && fieldName.equals(Constants.UserConfigurations.OUTPUT_WITH_HEADERS)) { outputWithHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); @@ -366,30 +367,37 @@ private void validateFunctionParameterTypesWithOptions(Location currentLocation, } } } - throwErrorsIfIgnoredFieldFoundForOutputs(header, customHeadersIfHeaderAbsent, headersRows, - customHeaders, isCustomHeaderPresent, headersOrder, + throwErrorsIfIgnoredFieldFoundForOutputs(header, customHeadersIfHeaderAbsent, headerRows, + customHeaders, isCustomHeaderPresent, headerOrder, outputWithHeaders, ctx, currentLocation, functionName, isRecord); } + private void checkAndAssertMappingConstructorArguments(int mappingConstructorExprNodeCount) { + if (mappingConstructorExprNodeCount > 1) { + assert false : "MappingConstructorExpressionNode count in the function " + + "arguments should be less than or equal to 1"; + } + } + private void throwErrorsIfIgnoredFieldFoundForOutputs(String header, String customHeadersIfHeaderAbsent, - String headersRows, String customHeaders, boolean isCustomHeaderPresent, String headersOrder, + String headerRows, String customHeaders, boolean isCustomHeaderPresent, String headerOrder, String outputWithHeaders, SyntaxNodeAnalysisContext ctx, Location currentLocation, String functionName, boolean isRecord) { if (functionName.equals(Constants.PARSE_STRING) && header != null && !header.equals(Constants.FALSE) - && customHeadersIfHeaderAbsent != null && !customHeadersIfHeaderAbsent.equals(Constants.BAL_NULL) + && customHeadersIfHeaderAbsent != null && !customHeadersIfHeaderAbsent.equals(Constants.NIL) && !customHeadersIfHeaderAbsent.equals(Constants.NULL)) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); } - if (functionName.equals(Constants.PARSE_LISTS) && headersRows != null - && !headersRows.equals("0") && !headersRows.equals("1") && - (!isCustomHeaderPresent || (customHeaders != null && (customHeaders.equals(Constants.BAL_NULL) + if (functionName.equals(Constants.PARSE_LISTS) && headerRows != null + && !headerRows.equals("0") && !headerRows.equals("1") && + (!isCustomHeaderPresent || (customHeaders != null && (customHeaders.equals(Constants.NIL) || customHeaders.equals(Constants.NULL))))) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.CUSTOM_HEADERS_SHOULD_BE_PROVIDED); } - if (isRecord && functionName.equals(Constants.TRANSFORM) && headersOrder != null - && !headersOrder.equals(Constants.BAL_NULL) && !headersOrder.equals(Constants.NULL)) { + if (isRecord && functionName.equals(Constants.TRANSFORM) && headerOrder != null + && !headerOrder.equals(Constants.NIL) && !headerOrder.equals(Constants.NULL)) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY); } @@ -410,7 +418,7 @@ private String getTheValueOfTheUserConfigOption(SpecificFieldNode specificFieldN return listConstructorExpressionNode.expressions().toString(); } if (expNode instanceof NilLiteralNode) { - return Constants.BAL_NULL; + return Constants.NIL; } } return null; @@ -432,8 +440,8 @@ private void validateTupleType(Location currentLocation, SyntaxNodeAnalysisConte reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); } - private void validateArrayType(ArrayTypeSymbol typeSymbol, Location currentLocation - , SyntaxNodeAnalysisContext ctx) { + private void validateArrayType(ArrayTypeSymbol typeSymbol, + Location currentLocation, SyntaxNodeAnalysisContext ctx) { if (!isSupportedArrayMemberType(ctx, currentLocation, typeSymbol.memberTypeDescriptor())) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); } @@ -592,7 +600,7 @@ private void validateRecordTypeDefinition(TypeDefinitionNode typeDefinitionNode, } private void detectDuplicateFields(RecordTypeSymbol recordTypeSymbol, SyntaxNodeAnalysisContext ctx) { - List fieldMembers = new ArrayList<>(); + Set fieldMembers = new HashSet<>(); for (Map.Entry entry : recordTypeSymbol.fieldDescriptors().entrySet()) { RecordFieldSymbol fieldSymbol = entry.getValue(); String name = getNameFromAnnotation(entry.getKey(), fieldSymbol.annotAttachments()); diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java index 8b22db5..16bdeee 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java @@ -257,11 +257,11 @@ private static BDecimal stringToDecimal(String value, CsvConfig config) throws N } private static Object stringToBoolean(String value) throws NumberFormatException { - if ("true".equalsIgnoreCase(value) || "TRUE".equalsIgnoreCase(value)) { + if ("true".equals(value) || "TRUE".equals(value)) { return true; } - if ("false".equalsIgnoreCase(value) || "FALSE".equalsIgnoreCase(value)) { + if ("false".equals(value) || "FALSE".equals(value)) { return false; } return returnError(value, "boolean"); diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java index 05f3ecf..23b054d 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java @@ -87,27 +87,24 @@ static void convertAndUpdateCurrentCsvNode(CsvParser.StateMachine sm, Type currentCsvNodeType = TypeUtils.getType(currentCsv); switch (currentCsvNodeType.getTag()) { - case TypeTags.MAP_TAG: - case TypeTags.RECORD_TYPE_TAG: + case TypeTags.MAP_TAG, TypeTags.RECORD_TYPE_TAG -> { ((BMap) currentCsv).put(StringUtils.fromString(getHeaderValueForColumnIndex(sm)), convertedValue); sm.currentCsvNodeLength++; - return; - case TypeTags.ARRAY_TAG: + } + case TypeTags.ARRAY_TAG -> { ArrayType arrayType = (ArrayType) currentCsvNodeType; if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < sm.columnIndex) { sm.isColumnMaxSizeReached = true; - return; } ((BArray) currentCsv).add(sm.columnIndex, convertedValue); sm.currentCsvNodeLength++; - return; - case TypeTags.TUPLE_TAG: + } + case TypeTags.TUPLE_TAG -> { ((BArray) currentCsv).add(sm.columnIndex, convertedValue); sm.currentCsvNodeLength++; - return; - default: + } } } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java index 5916908..7f0ee66 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java @@ -150,6 +150,8 @@ static class StateMachine { boolean isColumnMaxSizeReached = false; boolean isRowMaxSizeReached = false; + boolean isCarriageTokenPresent = false; + StateMachine() { reset(); } @@ -187,11 +189,12 @@ public void reset() { currentCsvNodeLength = 0; isColumnMaxSizeReached = false; isRowMaxSizeReached = false; + isCarriageTokenPresent = false; } - private static boolean isWhitespace(char ch, Object lineTerminator) { + private boolean isWhitespace(char ch, Object lineTerminator) { return ch == SPACE || ch == HZ_TAB || ch == CR - || CsvUtils.isCharContainsInLineTerminatorUserConfig(ch, lineTerminator); + || CsvUtils.isCharContainsInLineTerminatorUserConfig(ch, lineTerminator, isCarriageTokenPresent); } private static void throwExpected(String... chars) throws CsvParserException { @@ -344,7 +347,8 @@ private void append(char ch) { } private boolean isNewLineOrEof(char ch) { - return ch == EOF || CsvUtils.isCharContainsInLineTerminatorUserConfig(ch, config.lineTerminator); + return ch == EOF || CsvUtils.isCharContainsInLineTerminatorUserConfig(ch, + config.lineTerminator, isCarriageTokenPresent); } private void growCharBuff() { @@ -380,10 +384,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return HEADER_END_STATE; } if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); + sm.isCarriageTokenPresent = true; continue; - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = true; } if (sm.lineNumber < headerStartRowNumber) { @@ -418,7 +422,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } else if (!sm.insideComment && isEndOfTheHeaderRow(sm, ch)) { handleEndOfTheHeader(sm); state = HEADER_END_STATE; - } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { + } else if (sm.isWhitespace(ch, sm.config.lineTerminator)) { if (sm.isValueStart) { sm.append(ch); } @@ -555,10 +559,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { continue; } if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); + sm.isCarriageTokenPresent = true; continue; - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = false; } if (sm.skipTheRow) { @@ -612,7 +616,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { state = ROW_END_STATE; break; } - } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { + } else if (sm.isWhitespace(ch, sm.config.lineTerminator)) { if (sm.isValueStart) { sm.append(ch); } @@ -865,10 +869,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { return ROW_END_STATE; } if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); + sm.isCarriageTokenPresent = true; continue; - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = false; } if (ch == sm.config.textEnclosure) { @@ -931,10 +935,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) return ROW_END_STATE; } if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); + sm.isCarriageTokenPresent = true; continue; - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = false; } if (ch == sm.config.textEnclosure) { @@ -1016,10 +1020,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return ROW_END_STATE; } if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); + sm.isCarriageTokenPresent = true; continue; - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = false; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) { @@ -1096,9 +1100,9 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C ch = buff[i]; sm.processLocation(ch); if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + sm.isCarriageTokenPresent = true; + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = false; } if (ch == EOF) { handleEndOfTheRow(sm); diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java index 625ceea..61e4a4c 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java @@ -199,11 +199,9 @@ private Optional handleNonUnionIntersections(Type referredType, BArray c if (referredType.getTag() == TypeTags.ARRAY_TAG) { Type arrayElementType = TypeUtils.getReferredType(((ArrayType) referredType).getElementType()); if (arrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { - Optional mutableType = CsvUtils.getMutableType((IntersectionType) arrayElementType); - if (mutableType.isPresent()) { - return Optional.of(CsvCreator.constructReadOnlyValue(traverseCsv(csv, - config, TypeCreator.createArrayType(mutableType.get())))); - } + return CsvUtils.getMutableType((IntersectionType) arrayElementType) + .map(mutableType -> CsvCreator.constructReadOnlyValue( + traverseCsv(csv, config, TypeCreator.createArrayType(mutableType)))); } } return Optional.empty(); @@ -273,11 +271,11 @@ public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type e } Object o = csv.get(i); - if (i < config.headersRows && i != config.headersRows - 1) { + if (i < config.headerRows && i != config.headerRows - 1) { continue; } - if (i >= config.headersRows && ignoreRow(rowNumber + 1, config.skipLines)) { + if (i >= config.headerRows && ignoreRow(rowNumber + 1, config.skipLines)) { rowNumber++; continue; } @@ -291,7 +289,7 @@ public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type e rootCsvNode.add(this.arraySize, rowValue); this.arraySize++; } - if (i >= config.headersRows) { + if (i >= config.headerRows) { rowNumber++; } } @@ -311,11 +309,11 @@ public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expe Object o = csv.get(i); if (!addHeadersForOutput && config.outputWithHeaders - && (o instanceof BMap || (config.customHeaders != null || i == config.headersRows - 1))) { + && (o instanceof BMap || (config.customHeaders != null || i == config.headerRows - 1))) { // Headers will add to the list only in the first iteration insertHeaderValuesForTheCsvIfApplicable(o, expectedArrayType); } - if (i < config.headersRows) { + if (i < config.headerRows) { continue; } @@ -348,7 +346,7 @@ public void traverseCsvWithUnionExpectedType(BArray csv, resetForUnionTypes(); } } - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_UNION_CONVERSION, type); + throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); } private static boolean ignoreRow(int index, Object skipLinesConfig) { @@ -417,7 +415,7 @@ private void traverseCsvRowWithListAsExpectedType(Object csvElement, Type type) private void constructCsvArrayFromMapping(BMap map, Type type, int expectedSize) { int index = 0; - BString[] keys = generateCsvHeadersForMappingRow(map, config.headersOrder, map.size()); + BString[] keys = generateCsvHeadersForMappingRow(map, config.headerOrder, map.size()); for (BString key: keys) { if (!map.containsKey(key)) { throw DiagnosticLog.error(DiagnosticErrorCode.HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED, key); @@ -473,8 +471,8 @@ private void constructCsvMapFromNonMapping(BArray csvElement, String[] headers = new String[csvElement.size()]; if (this.headers == null) { this.headers = CsvUtils.createHeadersForParseLists(csvElement, headers, config); - if (!this.isFirstRowInserted && config.headersRows >= 1) { - // To skip the row at the position [config.headersRows - 1] from being aded to the result. + if (!this.isFirstRowInserted && config.headerRows >= 1) { + // To skip the row at the position [config.headerRows - 1] from being aded to the result. this.isFirstRowIsHeader = true; this.isFirstRowInserted = true; return; @@ -485,7 +483,7 @@ private void constructCsvMapFromNonMapping(BArray csvElement, throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONVERSION_FOR_ARRAY_TO_MAP, csvElement, expectedType); } - constructCsvMappingRow(csvElement, arraySize, mappingType, expectedType); + insertCsvMappingRow(csvElement, arraySize, mappingType, expectedType); } private void constructCsvMapFromMapping( @@ -517,7 +515,7 @@ private void insertHeaderValuesForTheCsvIfApplicable(Object obj, Type type) { if (this.headers == null && obj instanceof BMap) { BMap map = (BMap) obj; int size = map.size(); - BString[] headerArray = generateCsvHeadersForMappingRow(map, config.headersOrder, size); + BString[] headerArray = generateCsvHeadersForMappingRow(map, config.headerOrder, size); this.headers = new String[size]; for (int i = 0; i < headerArray.length; i++) { this.headers[i] = StringUtils.getStringValue(headerArray[i]); @@ -550,10 +548,10 @@ private void insertHeaderValuesForTheCsvIfApplicable(Object obj, Type type) { } } - private BString[] generateCsvHeadersForMappingRow(BMap map, Object headersOrder, int size) { + private BString[] generateCsvHeadersForMappingRow(BMap map, Object headerOrder, int size) { BString[] keys = new BString[size]; - if (headersOrder != null) { - String[] order = ((BArray) headersOrder).getStringArray(); + if (headerOrder != null) { + String[] order = ((BArray) headerOrder).getStringArray(); if (order.length != size) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_HEADER_NAMES_LENGTH); } @@ -670,7 +668,7 @@ private boolean validateHeadersWithArrayDataRows(Type expectedType) { return false; } - private void constructCsvMappingRow(BArray csvElement, int arraySize, boolean mappingType, Type expectedType) { + private void insertCsvMappingRow(BArray csvElement, int arraySize, boolean mappingType, Type expectedType) { Type fieldType; BString key; if (arraySize != this.headers.length) { diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java index 4cd1749..f2ad47b 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java @@ -27,11 +27,11 @@ public static final class ConfigConstants { public static final BString ENABLE_CONSTRAINT_VALIDATION = StringUtils. fromString("enableConstraintValidation"); public static final BString OUTPUT_WITH_HEADERS = StringUtils.fromString("outputWithHeaders"); - public static final BString HEADER_ROWS = StringUtils.fromString("headersRows"); + public static final BString HEADER_ROWS = StringUtils.fromString("headerRows"); public static final BString CUSTOM_HEADERS_IF_HEADER_ABSENT = StringUtils.fromString("customHeadersIfHeadersAbsent"); public static final BString CUSTOM_HEADERS = StringUtils.fromString("customHeaders"); - public static final BString HEADERS_ORDER = StringUtils.fromString("headersOrder"); + public static final BString HEADERS_ORDER = StringUtils.fromString("headerOrder"); private ConfigConstants() { } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java index eae6a63..cf1c64c 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java @@ -22,12 +22,12 @@ public class CsvConfig { public boolean nilAsOptionalField = false; public boolean absentAsNilableType = false; public boolean allowDataProjection = true; - public Object headersOrder = null; + public Object headerOrder = null; public boolean stringConversion = false; public boolean enableConstraintValidation = false; public boolean outputWithHeaders = false; public Object customHeadersIfHeadersAbsent = null; - public long headersRows = 0; + public long headerRows = 0; public Object customHeaders = null; private CsvConfig(CsvConfig config) { @@ -58,14 +58,14 @@ public static CsvConfig createParseListOptions(BMap options) { public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, Object skipLines, boolean enableConstraintValidation, boolean outputWithHeaders, - long headersRows, Object headers) { + long headerRows, Object headers) { this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; this.skipLines = skipLines; this.enableConstraintValidation = enableConstraintValidation; this.outputWithHeaders = outputWithHeaders; - this.headersRows = headersRows; + this.headerRows = headerRows; this.customHeaders = headers; } @@ -84,14 +84,14 @@ public static CsvConfig createTransformOptions(BMap options) { public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, Object skipLines, boolean enableConstraintValidation, boolean outputWithHeaders, - Object headersOrder) { + Object headerOrder) { this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; this.skipLines = skipLines; this.enableConstraintValidation = enableConstraintValidation; this.outputWithHeaders = outputWithHeaders; - this.headersOrder = headersOrder; + this.headerOrder = headerOrder; } public static CsvConfig createParseOptions(BMap options) { diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java index 917771f..2c63f34 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java @@ -31,11 +31,6 @@ */ public class CsvUtils { private static final long[] EMPTY_LONG_ARRAY = new long[]{}; - public static boolean isCarriageTokenPresent = false; - - public static void setCarriageTokenPresent(boolean isCarriageTokenPresent) { - CsvUtils.isCarriageTokenPresent = isCarriageTokenPresent; - } public static void validateExpectedArraySize(int size, int currentSize) { if (size != -1 && size > currentSize) { @@ -65,7 +60,7 @@ public static boolean isBasicType(Type type) { public static String[] createHeadersForParseLists(BArray csvElement, String[] headers, CsvConfig config) { Object customHeaders = config.customHeaders; - long headersRows = config.headersRows; + long headerRows = config.headerRows; int length = headers.length; if (customHeaders instanceof BArray array) { @@ -78,15 +73,15 @@ public static String[] createHeadersForParseLists(BArray csvElement, String[] he return headers; } - if (headersRows == 1) { + if (headerRows == 1) { return csvElement.getStringArray(); } - if (headersRows > 1) { + if (headerRows > 1) { throw DiagnosticLog.error(DiagnosticErrorCode.NO_CUSTOM_HEADER_PROVIDED); } - // when headersRows = 0 and customHeaders = null + // when headerRows = 0 and customHeaders = null for (int i = 0; i < length; i++) { headers[i] = String.valueOf(i + 1); } @@ -133,37 +128,36 @@ public static boolean isHeaderFieldsEmpty(Map currentField) { public static boolean checkTypeCompatibility(Type constraintType, Object csv, boolean stringConversion) { int tag = constraintType.getTag(); if (csv instanceof BString) { - if (stringConversion || tag == TypeTags.STRING_TAG - || tag == TypeTags.CHAR_STRING_TAG || isJsonOrAnyDataOrAny(tag)) { + if (stringConversion || TypeTags.isStringTypeTag(tag) || isJsonOrAnyDataOrAny(tag)) { return true; } + return false; } if (csv instanceof Long) { - if (tag == TypeTags.INT_TAG - || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.BYTE_TAG - || tag == TypeTags.SIGNED8_INT_TAG || tag == TypeTags.SIGNED16_INT_TAG - || tag == TypeTags.SIGNED32_INT_TAG || tag == TypeTags.UNSIGNED8_INT_TAG - || tag == TypeTags.UNSIGNED16_INT_TAG || tag == TypeTags.UNSIGNED32_INT_TAG - || isJsonOrAnyDataOrAny(tag)) { + if (TypeTags.isIntegerTypeTag(tag) || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG + || tag == TypeTags.BYTE_TAG || isJsonOrAnyDataOrAny(tag)) { return true; } + return false; } if (csv instanceof BDecimal) { if ((tag == TypeTags.DECIMAL_TAG - || tag == TypeTags.FLOAT_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag)) { + || tag == TypeTags.FLOAT_TAG || TypeTags.isIntegerTypeTag(tag)) || isJsonOrAnyDataOrAny(tag)) { return true; } } if (csv instanceof Double) { if ((tag == TypeTags.FLOAT_TAG - || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag)) { + || tag == TypeTags.DECIMAL_TAG || TypeTags.isIntegerTypeTag(tag)) || isJsonOrAnyDataOrAny(tag)) { return true; } + return false; } if (csv instanceof Boolean) { if (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag)) { return true; } + return false; } if (csv == null) { return tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag); @@ -262,20 +256,18 @@ public static long[] getSkipLinesFromStringConfigValue(String configValue) { } public static long[] getSkipDataRows(Object skipLines) { - long[] skipDataRows; if (skipLines == null) { return EMPTY_LONG_ARRAY; } + if (skipLines instanceof BArray skipLinesArray) { if (skipLinesArray.getLength() == 0) { return EMPTY_LONG_ARRAY; } - skipDataRows = skipLinesArray.getIntArray(); - return skipDataRows; + return skipLinesArray.getIntArray(); } - skipDataRows = getSkipLinesFromStringConfigValue(StringUtils.getStringValue(skipLines)); - return skipDataRows; + return getSkipLinesFromStringConfigValue(StringUtils.getStringValue(skipLines)); } public static boolean isNullValue(Object nullValue, Object value) { @@ -299,11 +291,12 @@ private static boolean handleStringNullValue(Object nullValue, String v, Object return nullValue != null && value.equals(StringUtils.getStringValue(nullValue)); } - public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object lineTerminatorObj) { + public static boolean isCharContainsInLineTerminatorUserConfig(char c, + Object lineTerminatorObj, boolean isCarriageTokenPresent) { if (lineTerminatorObj instanceof BArray array) { Object[] lineTerminators = array.getValues(); for (Object lineTerminator: lineTerminators) { - Optional value = handleLineTerminator(lineTerminator, c); + Optional value = handleLineTerminator(lineTerminator, c, isCarriageTokenPresent); if (value.isEmpty()) { continue; } @@ -324,18 +317,19 @@ public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object li return false; } - private static Optional handleLineTerminator(Object lineTerminator, char c) { - if (lineTerminator != null && c == Constants.LineTerminator.LF) { - String lineTerminatorString = lineTerminator.toString(); - if (isCarriageTokenPresent) { - if (lineTerminatorString.equals(Constants.LineTerminator.CRLF)) { - return Optional.of(true); - } - return Optional.empty(); + private static Optional handleLineTerminator(Object lineTerminator, + char c, boolean isCarriageTokenPresent) { + if (lineTerminator == null || c != Constants.LineTerminator.LF) { + return Optional.empty(); + } + String lineTerminatorString = lineTerminator.toString(); + if (isCarriageTokenPresent) { + if (lineTerminatorString.equals(Constants.LineTerminator.CRLF)) { + return Optional.of(true); } - return Optional.of(true); + return Optional.empty(); } - return Optional.empty(); + return Optional.of(true); } public static class UnMappedValue { @@ -361,9 +355,10 @@ public static SkipMappedValue createSkippedValue() { public static Locale createLocaleFromString(String localeString) { // Split the string into language, country, and variant String[] parts = localeString.split(Constants.UNDERSCORE); - if (parts.length == 3) { + int length = parts.length; + if (length == 3) { return new Locale(parts[0], parts[1], parts[2]); - } else if (parts.length == 2) { + } else if (length == 2) { return new Locale(parts[0], parts[1]); } else { return new Locale(parts[0]); // Only language @@ -371,7 +366,7 @@ public static Locale createLocaleFromString(String localeString) { } public static void validateConfigs(CsvConfig config) { - if (config.headersRows > 1 && config.customHeaders == null) { + if (config.headerRows > 1 && config.customHeaders == null) { throw DiagnosticLog.error(DiagnosticErrorCode.NO_CUSTOM_HEADER_PROVIDED); } } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java index 00258d3..b509a24 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java @@ -26,11 +26,11 @@ public static Object validateConstraints(Object convertedValue, BTypedesc typed, } private static String getPrintableErrorMsg(BError err) { - String errorMsg = err.getMessage() != null ? err.getMessage() : ""; + StringBuilder errorBuilder = new StringBuilder(err.getMessage() != null ? err.getMessage() : ""); Object details = err.getDetails(); if (details != null && !details.toString().equals("{}")) { - errorMsg += !errorMsg.isBlank() ? ", " : "" + details; + errorBuilder.append(!errorBuilder.isEmpty() ? ", " : "" + details); } - return errorMsg; + return errorBuilder.toString(); } } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java index f29bced..82df3a5 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java @@ -55,8 +55,7 @@ public enum DiagnosticErrorCode { HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED("BDE_0027", "headers.with.varying.length.not.supported"), HEADER_VALUE_CANNOT_BE_EMPTY("BDE_0028", "header.value.cannot.be.empty"), - DUPLICATE_HEADER("BDE_0029", "duplicate.header"), - INVALID_UNION_CONVERSION("BDE_0029", "invalid.union.conversion"); + DUPLICATE_HEADER("BDE_0029", "duplicate.header"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/csv_error.properties b/native/src/main/resources/csv_error.properties index 2afb2e2..96cc250 100644 --- a/native/src/main/resources/csv_error.properties +++ b/native/src/main/resources/csv_error.properties @@ -70,46 +70,43 @@ error.invalid.configurations=\ invalid configurations: ''{0}'' error.invalid.format.for.skiplines=\ - Invalid format for the skipLines field. Expected format: 'start-end' + invalid format for the skipLines field. Expected format: 'start-end' error.invalid.range.for.skiplines=\ - Invalid range for the skipLines field. Start value must be less than or equal to end value. + invalid range for the skipLines field. Start value must be less than or equal to end value. error.invalid.value.for.skiplines=\ - Invalid input for the skipLines field. Both start and end values must be integers. + invalid input for the skipLines field. Both start and end values must be integers. error.inconsistent.header=\ - Header ''{0}'' cannot be find in data rows + header ''{0}'' cannot be found in data rows error.invalid.custom.header.length=\ - Invalid number of headers + invalid number of headers error.invalid.header.names.length=\ - Invalid number of headers + invalid number of headers error.header.cannot.be.empty=\ - The provided header row is empty + provided header row is empty error.no.field.for.header=\ - No mapping field in the expected type for header ''{0}'' + no mapping field in the expected type for header ''{0}'' error.duplicate.field=\ - Duplicate field found in record fields: ''{0}'' + duplicate field found in record fields: ''{0}'' error.cannot.convert.into.exptype=\ - The source value cannot convert in to the ''{0}'' + source value cannot converted in to the ''{0}'' error.no.custom.header.provided=\ - Custom headers should be provided + custom headers should be provided error.headers.with.varying.length.not.supported=\ CSV data rows with varying headers are not yet supported error.header.value.cannot.be.empty=\ - Header cannot be empty + header cannot be empty error.duplicate.header=\ - Duplicate header found: ''{0}'' - -error.invalid.union.conversion=\ - The CSV cannot be converted into any of the uniform union types in ''{0}'' + duplicate header found: ''{0}''