diff --git a/README.md b/README.md index 22ff65d..3381745 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,14 @@ The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate ## Features - **Versatile CSV Data Input**: Accept CSV data as a string, byte array, or a stream and convert it into a subtype of ballerina records or lists. -- **CSV to anydata Value Conversion**: Transform CSV data into expected type which is subtype of ballerina records or lists. -- **Projection Support**: Perform selective conversion of CSV data subsets into ballerina records or lists values through projection. +- **CSV to anydata Value transformation**: Transform CSV data into expected type which is subtype of ballerina record arrays or anydata arrays. +- **Projection Support**: Perform selective conversion of CSV data subsets into ballerina record array or anydata array values through projection. ## Usage ### Converting CSV string to a record array -To convert a CSV string into a record value, you can use the `parseStringToRecord` function from the library. The following example demonstrates how to transform a CSV document into an array of records. +To convert a CSV string into a record array value, you can use the `parseString` function from the library. The following example demonstrates how to transform a CSV document into an array of records. ```ballerina import ballerina/data.csv; @@ -36,7 +36,7 @@ public function main() returns error? { Clean Code,Robert C. Martin,2008 The Pragmatic Programmer,Andrew Hunt and David Thomas,1999`; - Book[] books = check csv:parseStringToRecord(csvString); + Book[] books = check csv:parseString(csvString); foreach var book in books { io:println(book); } @@ -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 `parseStringToRecord`, `parseBytesToRecord`, `parseStreamToRecord`, `parseStringToList`, `parseBytesToList`and `parseStreamToList` 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; @@ -60,12 +60,12 @@ type Book record { public function main() returns error? { // Read the CSV content as a string string csvContent = check io:fileReadString("path/to/file.csv"); - Book[] book = check csv:parseStringToRecord(csvContent); + Book[] book = check csv:parseString(csvContent); io:println(book); // Read the CSV content as a stream stream csvStream = check io:fileReadBlocksAsStream("path/to/file.csv"); - Book[] book2 = check csv:parseStreamToRecord(csvStream); + Book[] book2 = check csv:parseStream(csvStream); io:println(book2); } ``` @@ -74,8 +74,8 @@ Make sure to handle possible errors that may arise during the file reading or CS ## CSV to record array/anydata array of array representation -The CSV Object can be represented as a value of type record/map array or string array of array in Ballerina which facilitates a structured and type-safe approach to handling CSV data. -The conversion of CSV data to subtype of record array or anydata array of array representation is a fundamental feature of the library. +The CSV Object can be represented as a value of type `record/map array` or `string array of array` in Ballerina, which facilitates a structured and type-safe approach to handling CSV data. +The conversion of CSV data to subtype of `record array` or `anydata array of array` representation is a fundamental feature of the library. ```ballerina import ballerina/data.csv; @@ -88,9 +88,19 @@ type Book record { public function main() returns error? { string[][] bookArray = [["Clean Code","2008"],["Clean Architecture","2017"]]; + Book[] bookRecords = [{name: "Clean Code", year: 2008}, {name: "Clean Architecture", year: 2017}]; - Book[] author = check csv:parseListAsRecordType(bookArray, customHeaders = ["name", "year"]); - io:println(author); + // Parse and output a record array from a source of string array of arrays. + Book[] books = check csv:parseList(bookArray, {customHeaders: ["name", "year"]}); + io:println(books); + + // Parse and output a tuple array from a source of string array of arrays. + [string, int][] books2 = check csv:parseList(bookArray, {customHeaders: ["name", "year"]}); + io:println(books2); + + // Transform CSV records to a string array of arrays. + [string, int][] books3 = check csv:transform(bookRecords); + io:println(books3); } ``` @@ -122,7 +132,7 @@ public function main() returns error? { // The CSV data above contains publisher and year fields which are not // required to be converted into a record field. - Book[] book = check csv:parseRecordAsRecordType(csvContent); + Book[] book = check csv:transform(csvContent); io:println(book); } ``` diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index 39f08c5..42807ca 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -30,8 +30,9 @@ def testCommonTomlFilePlaceHolder = new File("${project.rootDir}/build-config/re def ballerinaDist = "${project.rootDir}/target/ballerina-runtime" def distributionBinPath = "${ballerinaDist}/bin" def testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.lib.data.csvdata.*:ballerina.*" -def testPackages = ["user-config-tests", "type-compatible-tests", "parse-string-array-types-tests", "unicode-tests", "constraint-validation-tests", - "parse-list-types-tests", "parse-record-types-tests", "parse-string-record-types-tests", "union-type-tests"] +def testPackages = ["union-type-tests", "user-config-tests", "parse-string-record-types-tests", + "parse-string-array-types-tests", "parse-list-types-tests", "parse-record-types-tests", + "type-compatible-tests", "unicode-tests", "constraint-validation-tests"] def testCommonPackage = "csv-commons" def stripBallerinaExtensionVersion(String extVersion) { diff --git a/ballerina-tests/constraint-validation-tests/Ballerina.toml b/ballerina-tests/constraint-validation-tests/Ballerina.toml index 32c446c..84093d9 100644 --- a/ballerina-tests/constraint-validation-tests/Ballerina.toml +++ b/ballerina-tests/constraint-validation-tests/Ballerina.toml @@ -13,4 +13,4 @@ version = "0.1.0" graalvmCompatible = true [build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" +graalvmBuildOptions = "-H:+IncludeAllLocales" diff --git a/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal index e732ac4..de74848 100644 --- a/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal +++ b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal @@ -30,54 +30,100 @@ type ConstrainedRec record { string b; }; +@constraint:Array {length: 4} +type ConstrainedList int[][]; + +@test:Config +function testConstraintWithLists() returns error? { + ConstrainedList|csv:Error cList1 = csv:parseString(string `1 + 2 + 3 + 4`, {header: false, customHeadersIfHeaderAbsent: ["a", "b", "c", "d"]}); + test:assertEquals(cList1, [[1], [2], [3], [4]]); + + cList1 = csv:parseString(string `1 + 2 + 3 + 4 + 5 + 6`, {header: false, customHeadersIfHeaderAbsent: ["a", "b", "c", "d", "e", "f"]}); + test:assertTrue(cList1 is csv:Error); + test:assertTrue((cList1).message().startsWith("Validation failed") + && (cList1).message().includes("length")); + + cList1 = csv:parseString(string `1 + 2 + 3 + 4 + 5 + 6`, {header: false, customHeadersIfHeaderAbsent: ["a", "b", "c", "d", "e", "f"], enableConstraintValidation: false}); + test:assertEquals(cList1, [[1], [2], [3], [4], [5], [6]]); + + cList1 = csv:transform([{"a": 1}, {"a": 1}, {"a": 1}, {"a": 1}], {}); + test:assertEquals(cList1, [[1], [1], [1], [1]]); + + cList1 = csv:transform([{"a": 1}, {"a": 1}, {"a": 1}, {"a": 1}, {"a": 1}, {"a": 1}], {}); + test:assertTrue(cList1 is csv:Error); + test:assertTrue((cList1).message().startsWith("Validation failed") + && (cList1).message().includes("length")); + + cList1 = csv:parseList([["1"], ["2"], ["3"], ["4"]], {customHeaders: ["a", "b", "c", "d"]}); + test:assertEquals(cList1, [[1], [2], [3], [4]]); + + cList1 = csv:parseList([["1"], ["2"], ["3"], ["4"], ["5"], ["6"]], {customHeaders: ["a", "b", "c", "d"]}); + test:assertTrue(cList1 is csv:Error); + test:assertTrue((cList1).message().startsWith("Validation failed") + && (cList1).message().includes("length")); +} + @test:Config function testConstraintWithRecords() returns error? { - ConstrainedRec[]|csv:Error cRec1 = csv:parseStringToRecord(string `a,b + ConstrainedRec[]|csv:Error cRec1 = csv:parseString(string `a,b 4,abc 3, cde`); test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); - ConstrainedRec[]|csv:Error cRec1_2 = csv:parseStringToRecord(string `a,b + ConstrainedRec[]|csv:Error cRec1_2 = csv:parseString(string `a,b 4,abc 3, cde`, {enableConstraintValidation: false}); test:assertEquals(cRec1_2, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); - cRec1 = csv:parseStringToRecord(string `a,b + cRec1 = csv:parseString(string `a,b 4,abc 11, cde`); test:assertTrue(cRec1 is csv:Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("maxValue")); - cRec1 = csv:parseStringToRecord(string `a,b + cRec1 = csv:parseString(string `a,b 4,abc 5, "b"`, {}); test:assertTrue(cRec1 is csv:Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("minLength")); - cRec1 = csv:parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 3, "b": "cde"}], {}); + cRec1 = csv:transform([{"a": 4, "b": "abc"}, {"a": 3, "b": "cde"}], {}); test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); - cRec1 = csv:parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 11, "b": "cde"}], {}); + cRec1 = csv:transform([{"a": 4, "b": "abc"}, {"a": 11, "b": "cde"}], {}); test:assertTrue(cRec1 is csv:Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("maxValue")); - cRec1 = csv:parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 5, "b": "b"}], {}); + cRec1 = csv:transform([{"a": 4, "b": "abc"}, {"a": 5, "b": "b"}], {}); test:assertTrue(cRec1 is csv:Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("minLength")); - cRec1 = csv:parseListAsRecordType([["4", "abc"], ["3", "cde"]], ["a", "b"]); + cRec1 = csv:parseList([["4", "abc"], ["3", "cde"]], {customHeaders: ["a", "b"]}); test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); - cRec1 = csv:parseListAsRecordType([["4", "abc"], ["11", "cde"]], ["a", "b"]); + cRec1 = csv:parseList([["4", "abc"], ["11", "cde"]], {customHeaders: ["a", "b"]}); test:assertTrue(cRec1 is csv:Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("maxValue")); - cRec1 = csv:parseListAsRecordType([["4", "abc"], ["5", "b"]], ["a", "b"]); + cRec1 = csv:parseList([["4", "abc"], ["5", "b"]], {customHeaders: ["a", "b"]}); test:assertTrue(cRec1 is csv:Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("minLength")); diff --git a/ballerina-tests/csv-commons/Dependencies.toml b/ballerina-tests/csv-commons/Dependencies.toml index 88bd281..cf3bbba 100644 --- a/ballerina-tests/csv-commons/Dependencies.toml +++ b/ballerina-tests/csv-commons/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.0" +distribution-version = "2201.10.0-20240801-104200-87df251c" [[package]] org = "ballerina" diff --git a/ballerina-tests/csv-commons/test_utils.bal b/ballerina-tests/csv-commons/test_utils.bal index b4b0447..ef482bf 100644 --- a/ballerina-tests/csv-commons/test_utils.bal +++ b/ballerina-tests/csv-commons/test_utils.bal @@ -34,6 +34,6 @@ public function generateErrorMessageForInvalidHeaders(string value, string 'type return string `value '${value}' cannot be cast into '${'type}', because fields in '${'type}' or the provided expected headers are not matching with the '${value}'`; } -public function generateErrorMessageForInvalidCustomHeader(string header) returns string{ - return string `Invalid header value: '${header}'`; +public function generateErrorMessageForInvalidCustomHeader(string header) returns string { + return string `Header '${header}' cannot be find in data rows`; } diff --git a/ballerina-tests/parse-list-types-tests/Ballerina.toml b/ballerina-tests/parse-list-types-tests/Ballerina.toml index fed1b89..258e9ff 100644 --- a/ballerina-tests/parse-list-types-tests/Ballerina.toml +++ b/ballerina-tests/parse-list-types-tests/Ballerina.toml @@ -13,4 +13,4 @@ version = "0.1.0" graalvmCompatible = true [build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" +graalvmBuildOptions = "-H:+IncludeAllLocales" diff --git a/ballerina-tests/parse-list-types-tests/Dependencies.toml b/ballerina-tests/parse-list-types-tests/Dependencies.toml index 279d0c7..3e4b472 100644 --- a/ballerina-tests/parse-list-types-tests/Dependencies.toml +++ b/ballerina-tests/parse-list-types-tests/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.0" +distribution-version = "2201.10.0-20240801-104200-87df251c" [[package]] org = "ballerina" 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 548b42c..1bd498c 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 @@ -20,73 +20,73 @@ import ballerina/test; @test:Config function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { - StringTuple1Array|csv:Error st1st1 = csv:parseListAsListType([st1, st1], {}, StringTuple1Array); + StringTuple1Array|csv:Error st1st1 = csv:parseList([st1, st1], {}, StringTuple1Array); test:assertEquals(st1st1, [ [s1, s2, "", ""], [s1, s2, "", ""] ]); - StringTuple1Array|csv:Error st2st1 = csv:parseListAsListType([st2, st2], {}, StringTuple1Array); + StringTuple1Array|csv:Error st2st1 = csv:parseList([st2, st2], {}, StringTuple1Array); test:assertEquals(st2st1, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringTuple1Array|csv:Error st3st1 = csv:parseListAsListType([st3, st3], {}, StringTuple1Array); + StringTuple1Array|csv:Error st3st1 = csv:parseList([st3, st3], {}, StringTuple1Array); test:assertEquals(st3st1, [ [s1, s2, "", ""], [s1, s2, "", ""] ]); - StringTuple1Array|csv:Error st4st1 = csv:parseListAsListType([st4, st4], {}, StringTuple1Array); + StringTuple1Array|csv:Error st4st1 = csv:parseList([st4, st4], {}, StringTuple1Array); test:assertEquals(st4st1, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringTuple2Array|csv:Error st1st2 = csv:parseListAsListType([st1, st1], {}, StringTuple2Array); + StringTuple2Array|csv:Error st1st2 = csv:parseList([st1, st1], {}, StringTuple2Array); test:assertEquals(st1st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|csv:Error st2st2 = csv:parseListAsListType([st2, st2], {}, StringTuple2Array); + StringTuple2Array|csv:Error st2st2 = csv:parseList([st2, st2], {}, StringTuple2Array); test:assertEquals(st2st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|csv:Error st3st2 = csv:parseListAsListType([st3, st3], {}, StringTuple2Array); + StringTuple2Array|csv:Error st3st2 = csv:parseList([st3, st3], {}, StringTuple2Array); test:assertEquals(st3st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|csv:Error st4st2 = csv:parseListAsListType([st4, st4], {}, StringTuple2Array); + StringTuple2Array|csv:Error st4st2 = csv:parseList([st4, st4], {}, StringTuple2Array); test:assertEquals(st4st2, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|csv:Error st1st3 = csv:parseListAsListType([st1, st1], {}, StringTuple3Array); + StringTuple3Array|csv:Error st1st3 = csv:parseList([st1, st1], {}, StringTuple3Array); test:assertEquals(st1st3, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|csv:Error st2st3 = csv:parseListAsListType([st2, st2], {}, StringTuple3Array); + StringTuple3Array|csv:Error st2st3 = csv:parseList([st2, st2], {}, StringTuple3Array); test:assertEquals(st2st3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringTuple3Array|csv:Error st3st3 = csv:parseListAsListType([st3, st3], {}, StringTuple3Array); + StringTuple3Array|csv:Error st3st3 = csv:parseList([st3, st3], {}, StringTuple3Array); test:assertEquals(st3st3, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|csv:Error st4st3 = csv:parseListAsListType([st4, st4], {}, StringTuple3Array); + StringTuple3Array|csv:Error st4st3 = csv:parseList([st4, st4], {}, StringTuple3Array); test:assertEquals(st4st3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] @@ -95,179 +95,179 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { @test:Config function testFromCsvWithTypeForTupleAndTupleAsExpectedType2() { - StringTuple4Array|csv:Error st1st4 = csv:parseListAsListType([st1, st1], {}, StringTuple4Array); + StringTuple4Array|csv:Error st1st4 = csv:parseList([st1, st1], {}, StringTuple4Array); test:assertEquals(st1st4, [ [s1, s2], [s1, s2] ]); - StringTuple4Array|csv:Error st2st4 = csv:parseListAsListType([st2, st2], {}, StringTuple4Array); + StringTuple4Array|csv:Error st2st4 = csv:parseList([st2, st2], {}, StringTuple4Array); test:assertEquals(st2st4, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringTuple4Array|csv:Error st3st4 = csv:parseListAsListType([st3, st3], {}, StringTuple4Array); + StringTuple4Array|csv:Error st3st4 = csv:parseList([st3, st3], {}, StringTuple4Array); test:assertEquals(st3st4, [ [s1, s2], [s1, s2] ]); - StringTuple4Array|csv:Error st4st4 = csv:parseListAsListType([st4, st4], {}, StringTuple4Array); + StringTuple4Array|csv:Error st4st4 = csv:parseList([st4, st4], {}, StringTuple4Array); test:assertEquals(st4st4, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - AnydataTuple3Array|csv:Error st1anydt3 = csv:parseListAsListType([st1, st1], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error st1anydt3 = csv:parseList([st1, st1], {}, AnydataTuple3Array); test:assertEquals(st1anydt3, [ [s1, s2], [s1, s2] ]); - AnydataTuple3Array|csv:Error st2anydt3 = csv:parseListAsListType([st2, st2], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error st2anydt3 = csv:parseList([st2, st2], {}, AnydataTuple3Array); test:assertEquals(st2anydt3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - AnydataTuple3Array|csv:Error st3anydt3 = csv:parseListAsListType([st3, st3], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error st3anydt3 = csv:parseList([st3, st3], {}, AnydataTuple3Array); test:assertEquals(st3anydt3, [ [s1, s2], [s1, s2] ]); - AnydataTuple3Array|csv:Error st4anydt3 = csv:parseListAsListType([st4, st4], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error st4anydt3 = csv:parseList([st4, st4], {}, AnydataTuple3Array); test:assertEquals(st4anydt3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - JsonTuple3Array|csv:Error st1jt3 = csv:parseListAsListType([st1, st1], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error st1jt3 = csv:parseList([st1, st1], {}, JsonTuple3Array); test:assertEquals(st1jt3, [ [s1, s2], [s1, s2] ]); - JsonTuple3Array|csv:Error st2jt3 = csv:parseListAsListType([st2, st2], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error st2jt3 = csv:parseList([st2, st2], {}, JsonTuple3Array); test:assertEquals(st2jt3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - JsonTuple3Array|csv:Error st3jt3 = csv:parseListAsListType([st3, st3], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error st3jt3 = csv:parseList([st3, st3], {}, JsonTuple3Array); test:assertEquals(st3jt3, [ [s1, s2], [s1, s2] ]); - JsonTuple3Array|csv:Error st4jt3 = csv:parseListAsListType([st4, st4], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error st4jt3 = csv:parseList([st4, st4], {}, JsonTuple3Array); test:assertEquals(st4jt3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - DecimalTuple4Array|csv:Error st1dta = csv:parseListAsListType([st1, st1], {}, DecimalTuple4Array); + DecimalTuple4Array|csv:Error st1dta = csv:parseList([st1, st1], {}, DecimalTuple4Array); test:assertTrue(st1dta is csv:Error); test:assertEquals((st1dta).message(), common:generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); - IntegerTuple3Array|csv:Error st2bta = csv:parseListAsListType([st2, st2], {}, IntegerTuple3Array); + IntegerTuple3Array|csv:Error st2bta = csv:parseList([st2, st2], {}, IntegerTuple3Array); test:assertTrue(st2bta is csv:Error); test:assertEquals((st2bta).message(), common:generateErrorMessageForInvalidValueForArrayType("string", "0", "int")); - NilTuple3Array|csv:Error st3nta = csv:parseListAsListType([st3, st3], {}, NilTuple3Array); + NilTuple3Array|csv:Error st3nta = csv:parseList([st3, st3], {}, NilTuple3Array); test:assertTrue(st3nta is csv:Error); test:assertEquals((st3nta).message(), common:generateErrorMessageForInvalidValueForArrayType("string", "0", "()")); - BooleanTuple4Array|csv:Error st4bta = csv:parseListAsListType([st4, st4], {}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error st4bta = csv:parseList([st4, st4], {}, BooleanTuple4Array); test:assertTrue(st4bta is csv:Error); test:assertEquals((st4bta).message(), common:generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); } @test:Config function testFromCsvWithTypeForTupleAndTupleAsExpectedType3() { - [string, boolean, int][]|csv:Error ct1bt4 = csv:parseListAsListType([["a", "true", "1"], ["a", "true", "1"]], {}); + [string, boolean, int][]|csv:Error ct1bt4 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {}); test:assertEquals(ct1bt4, [ ["a", true, 1], ["a", true, 1] ]); - [(), float, decimal, boolean, int, string][]|csv:Error ct1bt6 = csv:parseListAsListType( + [(), float, decimal, boolean, int, string][]|csv:Error ct1bt6 = csv:parseList( [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); test:assertEquals(ct1bt6, [ [(), 2.23, 0, true, 1, "a"], [(), 0, 2.23, true, 1, "a"] ]); - [decimal, boolean, int, string][]|csv:Error ct1bt7 = csv:parseListAsListType( + [decimal, boolean, int, string][]|csv:Error ct1bt7 = csv:parseList( [["0", "true", "1", "a"], ["2.23", "true", "1", "a"]]); test:assertEquals(ct1bt7, [ [0, true, 1, "a"], [2.23, true, 1, "a"] ]); - [decimal, boolean, int, string, anydata...][]|csv:Error ct1bt8 = csv:parseListAsListType( + [decimal, boolean, int, string, anydata...][]|csv:Error ct1bt8 = csv:parseList( [["0", "true", "1", "a", "null", "2.23"], ["2.23", "true", "1", "a", "null", "0"]]); test:assertEquals(ct1bt8, [ [0, true, 1, "a", (), 2.23], [2.23, true, 1, "a", (), 0] ]); - [(), float, decimal, boolean, int, string, string...][]|csv:Error ct1bt9 = csv:parseListAsListType( + [(), float, decimal, boolean, int, string, string...][]|csv:Error ct1bt9 = csv:parseList( [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); test:assertEquals(ct1bt9, [ [(), 2.23, 0, true, 1, "a"], [(), 0, 2.23, true, 1, "a"] ]); - [decimal, boolean, int, string, string...][]|csv:Error ct1bt10 = csv:parseListAsListType( + [decimal, boolean, int, string, string...][]|csv:Error ct1bt10 = csv:parseList( [["0", "true", "1", "a", "null", "2.23"], ["2.23", "true", "1", "a", "null", "0"]]); test:assertEquals(ct1bt10, [ [0, true, 1, "a", "null", "2.23"], [2.23, true, 1, "a", "null", "0"] ]); - [decimal, boolean, int, string, ()...][]|csv:Error ct1bt11 = csv:parseListAsListType( + [decimal, boolean, int, string, ()...][]|csv:Error ct1bt11 = csv:parseList( [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); test:assertTrue(ct1bt11 is csv:Error); //TODO: Fix the message test:assertEquals((ct1bt11).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "decimal")); - [(), decimal, float, boolean, ()...][]|csv:Error ct1bt11_2 = csv:parseListAsListType( + [(), decimal, float, boolean, ()...][]|csv:Error ct1bt11_2 = csv:parseList( [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); test:assertTrue(ct1bt11_2 is csv:Error); test:assertEquals((ct1bt11_2).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "4", "()")); - [()...][]|csv:Error ct1bt12 = csv:parseListAsListType( + [()...][]|csv:Error ct1bt12 = csv:parseList( [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); test:assertTrue(ct1bt12 is csv:Error); test:assertEquals((ct1bt12).message(), common:generateErrorMessageForInvalidValueForArrayType("2.23", "1", "()")); - [string...][]|csv:Error ct1bt13 = csv:parseListAsListType( + [string...][]|csv:Error ct1bt13 = csv:parseList( [["1", "a"], ["1", "a"]]); test:assertEquals(ct1bt13, [ ["1", "a"], ["1", "a"] ]); - [boolean...][]|csv:Error ct1bt14 = csv:parseListAsListType( + [boolean...][]|csv:Error ct1bt14 = csv:parseList( [["2.23", "null"], ["7", "()"]]); test:assertTrue(ct1bt14 is csv:Error); test:assertEquals((ct1bt14).message(), common:generateErrorMessageForInvalidValueForArrayType("2.23", "0", "boolean")); - int?[][]|csv:Error ct1bt15 = csv:parseListAsListType( + int?[][]|csv:Error ct1bt15 = csv:parseList( [["1", "()"], ["1", "2"]]); test:assertEquals(ct1bt15, [ [1, ()], [1, 2] ]); - int[][]|csv:Error ct1bt16 = csv:parseListAsListType( + int[][]|csv:Error ct1bt16 = csv:parseList( [["1", "2"], ["1", "()"]]); test:assertTrue(ct1bt16 is csv:Error); test:assertEquals((ct1bt16).message(), common:generateErrorMessageForInvalidValueForArrayType("()", "1", "int")); - int[][]|csv:Error ct1bt17 = csv:parseListAsListType( + int[][]|csv:Error ct1bt17 = csv:parseList( [["a", "b"], ["a", "b"]]); test:assertTrue(ct1bt17 is csv:Error); test:assertEquals((ct1bt17).message(), common:generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); @@ -275,55 +275,55 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType3() { @test:Config function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { - StringArrayArray|csv:Error st1saa = csv:parseListAsListType([st1, st1], {}, StringArrayArray); + StringArrayArray|csv:Error st1saa = csv:parseList([st1, st1], {}, StringArrayArray); test:assertEquals(st1saa, [ [s1, s2], [s1, s2] ]); - StringArrayArray|csv:Error st2saa = csv:parseListAsListType([st2, st2], {}, StringArrayArray); + StringArrayArray|csv:Error st2saa = csv:parseList([st2, st2], {}, StringArrayArray); test:assertEquals(st2saa, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringArrayArray|csv:Error st3saa = csv:parseListAsListType([st3, st3], {}, StringArrayArray); + StringArrayArray|csv:Error st3saa = csv:parseList([st3, st3], {}, StringArrayArray); test:assertEquals(st3saa, [ [s1, s2], [s1, s2] ]); - StringArrayArray|csv:Error st4saa = csv:parseListAsListType([st4, st4], {}, StringArrayArray); + StringArrayArray|csv:Error st4saa = csv:parseList([st4, st4], {}, StringArrayArray); test:assertEquals(st4saa, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - NillableStringArrayArray|csv:Error st1nsaa = csv:parseListAsListType([st1, st1], {}, NillableStringArrayArray); + NillableStringArrayArray|csv:Error st1nsaa = csv:parseList([st1, st1], {}, NillableStringArrayArray); test:assertEquals(st1nsaa, [ [s1, s2], [s1, s2] ]); - NillableStringArrayArray|csv:Error st2nsaa = csv:parseListAsListType([st2, st2], {}, NillableStringArrayArray); + NillableStringArrayArray|csv:Error st2nsaa = csv:parseList([st2, st2], {}, NillableStringArrayArray); test:assertEquals(st2nsaa, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - NillableStringArrayArray|csv:Error st3nsaa = csv:parseListAsListType([st3, st3], {}, NillableStringArrayArray); + NillableStringArrayArray|csv:Error st3nsaa = csv:parseList([st3, st3], {}, NillableStringArrayArray); test:assertEquals(st3nsaa, [ [s1, s2], [s1, s2] ]); - NillableStringArrayArray|csv:Error st4nsaa = csv:parseListAsListType([st4, st4], {}, NillableStringArrayArray); + NillableStringArrayArray|csv:Error st4nsaa = csv:parseList([st4, st4], {}, NillableStringArrayArray); test:assertEquals(st4nsaa, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - NillableIntOrUnionStringArrayArray|csv:Error st1nsuiaa = csv:parseListAsListType([st1, st1], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|csv:Error st1nsuiaa = csv:parseList([st1, st1], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st1nsuiaa, [ [s1, s2], [s1, s2] @@ -332,101 +332,279 @@ function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { @test:Config function testFromCsvWithTypeForTupleAndTupleAsExpectedType4() { - NillableIntOrUnionStringArrayArray|csv:Error st2nsuiaa = csv:parseListAsListType([st2, st2], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|csv:Error st2nsuiaa = csv:parseList([st2, st2], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st2nsuiaa, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - NillableIntOrUnionStringArrayArray|csv:Error st3nsuiaa = csv:parseListAsListType([st3, st3], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|csv:Error st3nsuiaa = csv:parseList([st3, st3], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st3nsuiaa, [ [s1, s2], [s1, s2] ]); - NillableIntOrUnionStringArrayArray|csv:Error st4nsuiaa = csv:parseListAsListType([st4, st4], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|csv:Error st4nsuiaa = csv:parseList([st4, st4], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st4nsuiaa, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringArray2Array|csv:Error st1saa2 = csv:parseListAsListType([st1, st1], {}, StringArray2Array); + StringArray2Array|csv:Error st1saa2 = csv:parseList([st1, st1], {}, StringArray2Array); test:assertEquals(st1saa2, [ [s1, s2], [s1, s2] ]); - StringArray2Array|csv:Error st2saa2 = csv:parseListAsListType([st2, st2], {}, StringArray2Array); + StringArray2Array|csv:Error st2saa2 = csv:parseList([st2, st2], {}, StringArray2Array); test:assertEquals(st2saa2, [ [s1, s2], [s1, s2] ]); - StringArray2Array|csv:Error st3saa2 = csv:parseListAsListType([st3, st3], {}, StringArray2Array); + StringArray2Array|csv:Error st3saa2 = csv:parseList([st3, st3], {}, StringArray2Array); test:assertEquals(st3saa2, [ [s1, s2], [s1, s2] ]); - StringArray2Array|csv:Error st4saa2 = csv:parseListAsListType([st4, st4], {}, StringArray2Array); + StringArray2Array|csv:Error st4saa2 = csv:parseList([st4, st4], {}, StringArray2Array); test:assertEquals(st4saa2, [ [s1, s2], [s1, s2] ]); - JsonArray1Array|csv:Error st1jaa = csv:parseListAsListType([st1, st1], {}, JsonArray1Array); + JsonArray1Array|csv:Error st1jaa = csv:parseList([st1, st1], {}, JsonArray1Array); test:assertEquals(st1jaa, [ [s1, s2], [s1, s2] ]); - JsonArray1Array|csv:Error st2jaa = csv:parseListAsListType([st2, st2], {}, JsonArray1Array); + JsonArray1Array|csv:Error st2jaa = csv:parseList([st2, st2], {}, JsonArray1Array); test:assertEquals(st2jaa, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - JsonArray1Array|csv:Error st3jaa = csv:parseListAsListType([st3, st3], {}, JsonArray1Array); + JsonArray1Array|csv:Error st3jaa = csv:parseList([st3, st3], {}, JsonArray1Array); test:assertEquals(st3jaa, [ [s1, s2], [s1, s2] ]); - JsonArray1Array|csv:Error st4jaa = csv:parseListAsListType([st4, st4], {}, JsonArray1Array); + JsonArray1Array|csv:Error st4jaa = csv:parseList([st4, st4], {}, JsonArray1Array); test:assertEquals(st4jaa, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - AnydataArray1Array|csv:Error st1anyda = csv:parseListAsListType([st1, st1], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error st1anyda = csv:parseList([st1, st1], {}, AnydataArray1Array); test:assertEquals(st1anyda, [ [s1, s2], [s1, s2] ]); - AnydataArray1Array|csv:Error st2anyda = csv:parseListAsListType([st2, st2], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error st2anyda = csv:parseList([st2, st2], {}, AnydataArray1Array); test:assertEquals(st2anyda, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - AnydataArray1Array|csv:Error st3anyda = csv:parseListAsListType([st3, st3], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error st3anyda = csv:parseList([st3, st3], {}, AnydataArray1Array); test:assertEquals(st3anyda, [ [s1, s2], [s1, s2] ]); - AnydataArray1Array|csv:Error st4anyda = csv:parseListAsListType([st4, st4], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error st4anyda = csv:parseList([st4, st4], {}, AnydataArray1Array); test:assertEquals(st4anyda, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - DecimalArray1Array|csv:Error st1dda = csv:parseListAsListType([st1, st1], {}, DecimalArray1Array); + DecimalArray1Array|csv:Error st1dda = csv:parseList([st1, st1], {}, DecimalArray1Array); test:assertTrue(st1dda is csv:Error); test:assertEquals((st1dda).message(), common:generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); - DecimalArray1Array|csv:Error st3dda = csv:parseListAsListType([st3, st3], {}, DecimalArray1Array); + DecimalArray1Array|csv:Error st3dda = csv:parseList([st3, st3], {}, DecimalArray1Array); test:assertTrue(st3dda is csv:Error); test:assertEquals((st3dda).message(), common:generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); } + +@test:Config +function testArrayIndexes() { + string[][] csv = [["1", "2", "3"], ["3", "4", "5"], ["5", "6", "7"], ["7", "8", "9"]]; + + [int, int][2]|csv:Error rec3_2 = csv:parseList(csv); + test:assertEquals(rec3_2, [ + [1, 2], + [3, 4] + ]); + + int[2][]|csv:Error rec5 = csv:parseList(csv); + test:assertEquals(rec5, [ + [1, 2, 3], + [3, 4, 5] + ]); +} + +@test:Config +function testParseListsWithOutputHeaders() { + [string, boolean, int][]|csv:Error ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); + test:assertEquals(ct1bt1, [ + ["a", true, 1] + ]); + + ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); + test:assertEquals(ct1bt1, []); + + 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"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); + test:assertEquals(ct1bt1, [ + ["a", true, 1], + ["a", true, 1] + ]); + + ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21}); + test:assertEquals(ct1bt1, []); + + (string|boolean|int)[][]|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", "b", "c"]], {headerRows: 2}); + test:assertEquals(ct1bt1_2, []); + + 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"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); + test:assertEquals(ct1bt1_2, [ + ["a", true, 1], + ["a", true, 1] + ]); + + ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21}); + test:assertEquals(ct1bt1_2, []); + + [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"]], {headerRows: 2, outputWithHeaders: true}); + test:assertTrue(ct1bt1_3 is csv:Error); + test:assertEquals((ct1bt1_3).message(), "Custom headers should be provided"); + + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, outputWithHeaders: true}); + test:assertTrue(ct1bt1_3 is csv:Error); + test:assertEquals((ct1bt1_3).message(), "Custom headers should be provided"); + + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + 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"]], {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")); + + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21, outputWithHeaders: true}); + test:assertEquals(ct1bt1_3, []); + + 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"]], {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"]], {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"]], {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"]], {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"]], {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"]], {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"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + test:assertEquals(ct1bt1_5, [ + ["h1", "h2", "h3"], + ["a", true, 1], + ["a", true, 1] + ]); + + [string...][]|csv:Error ct1bt2 = csv:parseList([["1", "a"], ["1", "a"]]); + test:assertEquals(ct1bt2, [ + ["1", "a"], + ["1", "a"] + ]); + + [string, boolean|string, int|string...][]|csv:Error ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + test:assertEquals(ct1bt2_2, [ + ["h1", "h2", "h3"], + ["a", true, 1] + ]); + + [string...][]|csv:Error ct1bt2_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + test:assertEquals(ct1bt2_3, [ + ["h1", "h2", "h3"], + ["a", "true", "1"] + ]); + + ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + test:assertEquals(ct1bt2_2, [ + ["h1", "h2", "h3"], + ["a", true, 1], + ["a", true, 1] + ]); + + string[2][1]|csv:Error ct1bt6 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + test:assertEquals(ct1bt6, [ + ["h1"], + ["a"] + ]); + [string, boolean|string, int|string...][1]|csv:Error ct1bt6_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + test:assertEquals(ct1bt6_2, [ + ["h1", "h2", "h3"] + ]); + [string...][1]|csv:Error ct1bt6_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + 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 0893c54..d1c2fa1 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 @@ -20,55 +20,55 @@ import ballerina/test; @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { - StringRecord1Array|csv:Error st1sr1 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord1Array); + StringRecord1Array|csv:Error st1sr1 = csv:parseList([st1, st1], {}); test:assertTrue(st1sr1 is csv:Error); test:assertEquals((st1sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - StringRecord1Array|csv:Error st2sr1 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord1Array); + StringRecord1Array|csv:Error st2sr1 = csv:parseList([st2, st2], {}); test:assertTrue(st2sr1 is csv:Error); test:assertEquals((st2sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - StringRecord2Array|csv:Error st1sr2 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord2Array); + StringRecord2Array|csv:Error st1sr2 = csv:parseList([st1, st1], {}); test:assertTrue(st1sr2 is csv:Error); test:assertEquals((st1sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "parse_list_types_tests:StringRecord2")); - StringRecord2Array|csv:Error st2sr2 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord2Array); + StringRecord2Array|csv:Error st2sr2 = csv:parseList([st2, st2], {}); test:assertTrue(st2sr2 is csv:Error); test:assertEquals((st2sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","parse_list_types_tests:StringRecord2")); - StringRecord9Array|csv:Error st1sr9 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord9Array); + StringRecord9Array|csv:Error st1sr9 = csv:parseList([st1, st1], {}); test:assertTrue(st1sr9 is csv:Error); test:assertEquals((st1sr9).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "parse_list_types_tests:StringRecord9")); - StringRecord9Array|csv:Error st2sr9 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord9Array); + StringRecord9Array|csv:Error st2sr9 = csv:parseList([st2, st2], {}); test:assertTrue(st2sr9 is csv:Error); test:assertEquals((st2sr9).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","parse_list_types_tests:StringRecord9")); - StringRecord10Array|csv:Error st1sr10 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); + StringRecord10Array|csv:Error st1sr10 = csv:parseList([st1, st1], {}); test:assertEquals(st1sr10, [ {'1: "string", '2: ""}, {'1: "string", '2: ""} ]); - StringRecord10Array|csv:Error st2sr10 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord10Array); + StringRecord10Array|csv:Error st2sr10 = csv:parseList([st2, st2], {}); test:assertEquals(st2sr10, [ {'1: "string", '2: "", '3: "a", '4: ""}, {'1: "string", '2: "", '3: "a", '4: ""} ]); - StringRecord19Array|csv:Error st1sr19 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord19Array); + StringRecord19Array|csv:Error st1sr19 = csv:parseList([st1, st1], {}); test:assertEquals(st1sr19, [ {s1: "", s2: "", "1": s1, "2": s2}, {s1: "", s2: "", "1": s1, "2": s2} ]); - StringRecord19Array|csv:Error st2sr19 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord19Array); + StringRecord19Array|csv:Error st2sr19 = csv:parseList([st2, st2], {}); test:assertEquals(st2sr19, [ {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord20Array|csv:Error st1sr20 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord20Array); + StringRecord20Array|csv:Error st1sr20 = csv:parseList([st1, st1], {}); test:assertEquals(st1sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} @@ -77,71 +77,71 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { - StringRecord20Array|csv:Error st2sr20 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord20Array); + StringRecord20Array|csv:Error st2sr20 = csv:parseList([st2, st2], {}); test:assertEquals(st2sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} ]); - StringRecord21Array|csv:Error st1sr21 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord21Array); + StringRecord21Array|csv:Error st1sr21 = csv:parseList([st1, st1], {}); test:assertEquals(st1sr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord21Array|csv:Error st2sr21 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord21Array); + StringRecord21Array|csv:Error st2sr21 = csv:parseList([st2, st2], {}); test:assertEquals(st2sr21, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord22Array|csv:Error st1sr22 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord22Array); + StringRecord22Array|csv:Error st1sr22 = csv:parseList([st1, st1], {}); test:assertEquals(st1sr22, [ {s1: "", s2: "", "1": s1, "2": s2}, {s1: "", s2: "", "1": s1, "2": s2} ]); - StringRecord22Array|csv:Error st2sr22 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord22Array); + StringRecord22Array|csv:Error st2sr22 = csv:parseList([st2, st2], {}); test:assertEquals(st2sr22, [ {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord23Array|csv:Error st1sr23 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord23Array); + StringRecord23Array|csv:Error st1sr23 = csv:parseList([st1, st1], {}); test:assertEquals(st1sr23, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord23Array|csv:Error st2sr23 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord23Array); + StringRecord23Array|csv:Error st2sr23 = csv:parseList([st2, st2], {}); test:assertEquals(st2sr23, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord15Array|csv:Error st1cr15 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord15Array); + CustomRecord15Array|csv:Error st1cr15 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord15Array|csv:Error st2cr15 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord15Array); + CustomRecord15Array|csv:Error st2cr15 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord16Array|csv:Error st1cr16 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord16Array); + CustomRecord16Array|csv:Error st1cr16 = csv:parseList([st1, st1], {}); test:assertTrue(st1cr16 is csv:Error); test:assertEquals((st1cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); - CustomRecord16Array|csv:Error st2cr16 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord16Array); + CustomRecord16Array|csv:Error st2cr16 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr16, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord17Array|csv:Error st1cr17 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord17Array); + CustomRecord17Array|csv:Error st1cr17 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr17, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} @@ -150,59 +150,59 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { - CustomRecord17Array|csv:Error st2cr17 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord17Array); + CustomRecord17Array|csv:Error st2cr17 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr17, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord18Array|csv:Error st1cr18 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord18Array); + CustomRecord18Array|csv:Error st1cr18 = csv:parseList([st1, st1], {}); test:assertTrue(st1cr18 is csv:Error); test:assertEquals((st1cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); - CustomRecord18Array|csv:Error st2cr18 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord18Array); + CustomRecord18Array|csv:Error st2cr18 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr18, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord19Array|csv:Error st1cr19 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord19Array); + CustomRecord19Array|csv:Error st1cr19 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr19, [ {'1: s1, '2: s2, '3: "", '4: ""}, {'1: s1, '2: s2, '3: "", '4: ""} ]); - CustomRecord19Array|csv:Error st2cr19 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord19Array); + CustomRecord19Array|csv:Error st2cr19 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr19, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord20Array|csv:Error st1cr20 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord20Array); + CustomRecord20Array|csv:Error st1cr20 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr20, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord20Array|csv:Error st2cr20 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord20Array); + CustomRecord20Array|csv:Error st2cr20 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr20, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord21Array|csv:Error st1cr21 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord21Array); + CustomRecord21Array|csv:Error st1cr21 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord21Array|csv:Error st2cr21 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord21Array); + CustomRecord21Array|csv:Error st2cr21 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr21, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord22Array|csv:Error st1cr22 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord22Array); + CustomRecord22Array|csv:Error st1cr22 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr22, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} @@ -211,71 +211,71 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType4() { - CustomRecord22Array|csv:Error st2cr22 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord22Array); + CustomRecord22Array|csv:Error st2cr22 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr22, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord23Array|csv:Error st1cr23 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord23Array); + CustomRecord23Array|csv:Error st1cr23 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr23, [ {"1": s1, "2": s2, a: ""}, {"1": s1, "2": s2, a: ""} ]); - CustomRecord23Array|csv:Error st2cr23 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord23Array); + CustomRecord23Array|csv:Error st2cr23 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr23, [ {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} ]); - CustomRecord24Array|csv:Error st1cr24 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord24Array); + CustomRecord24Array|csv:Error st1cr24 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr24, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord24Array|csv:Error st2cr24 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord24Array); + CustomRecord24Array|csv:Error st2cr24 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr24, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord25Array|csv:Error st1cr25 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord25Array); + CustomRecord25Array|csv:Error st1cr25 = csv:parseList([st1, st1], {}); test:assertTrue(st1cr25 is csv:Error); test:assertEquals((st1cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - CustomRecord25Array|csv:Error st2cr25 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord25Array); + CustomRecord25Array|csv:Error st2cr25 = csv:parseList([st2, st2], {}); test:assertTrue(st2cr25 is csv:Error); test:assertEquals((st2cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - CustomRecord25Array|csv:Error st3cr25 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord25Array); + CustomRecord25Array|csv:Error st3cr25 = csv:parseList([st3, st3], {}); test:assertTrue(st3cr25 is csv:Error); test:assertEquals((st3cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - CustomRecord25Array|csv:Error st4cr25 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord25Array); + CustomRecord25Array|csv:Error st4cr25 = csv:parseList([st4, st4], {}); test:assertTrue(st4cr25 is csv:Error); test:assertEquals((st4cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - CustomRecord26Array|csv:Error st1cr26 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord26Array); + CustomRecord26Array|csv:Error st1cr26 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr26 , [ {'1: s1}, {'1: s1} ]); - CustomRecord26Array|csv:Error st2cr26 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord26Array); + CustomRecord26Array|csv:Error st2cr26 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr26 , [ {'1: s1}, {'1: s1} ]); - CustomRecord26Array|csv:Error st3cr26 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord26Array); + CustomRecord26Array|csv:Error st3cr26 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr26 , [ {'1: s1}, {'1: s1} ]); - CustomRecord26Array|csv:Error st4cr26 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord26Array); + CustomRecord26Array|csv:Error st4cr26 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr26 , [ {'1: s1}, {'1: s1} @@ -284,103 +284,103 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType4() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType5() { - StringRecord1Array|csv:Error st3sr1 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord1Array); + StringRecord1Array|csv:Error st3sr1 = csv:parseList([st3, st3], {}); test:assertTrue(st3sr1 is csv:Error); test:assertEquals((st3sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - StringRecord1Array|csv:Error st4sr1 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord1Array); + StringRecord1Array|csv:Error st4sr1 = csv:parseList([st4, st4], {}); test:assertTrue(st4sr1 is csv:Error); test:assertEquals((st4sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - StringRecord2Array|csv:Error st3sr2 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord2Array); + StringRecord2Array|csv:Error st3sr2 = csv:parseList([st3, st3], {}); test:assertTrue(st3sr2 is csv:Error); test:assertEquals((st3sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "parse_list_types_tests:StringRecord2")); - StringRecord2Array|csv:Error st4sr2 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord2Array); + StringRecord2Array|csv:Error st4sr2 = csv:parseList([st4, st4], {}); test:assertTrue(st4sr2 is csv:Error); test:assertEquals((st4sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","parse_list_types_tests:StringRecord2")); - StringRecord9Array|csv:Error st3sr9 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord9Array); + StringRecord9Array|csv:Error st3sr9 = csv:parseList([st3, st3], {}); test:assertTrue(st3sr9 is csv:Error); test:assertEquals((st3sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); - StringRecord9Array|csv:Error st4sr9 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord9Array); + StringRecord9Array|csv:Error st4sr9 = csv:parseList([st4, st4], {}); test:assertTrue(st4sr9 is csv:Error); test:assertEquals((st4sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); - StringRecord10Array|csv:Error st3sr10 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord10Array); + StringRecord10Array|csv:Error st3sr10 = csv:parseList([st3, st3], {}); test:assertEquals(st3sr10, [ {'1: "string", '2: ""}, {'1: "string", '2: ""} ]); - StringRecord10Array|csv:Error st4sr10 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord10Array); + StringRecord10Array|csv:Error st4sr10 = csv:parseList([st4, st4], {}); test:assertEquals(st4sr10, [ {'1: "string", '2: "", '3: "a", '4: ""}, {'1: "string", '2: "", '3: "a", '4: ""} ]); - StringRecord19Array|csv:Error st3sr19 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord19Array); + StringRecord19Array|csv:Error st3sr19 = csv:parseList([st3, st3], {}); test:assertEquals(st3sr19, [ {s1: "", s2: "", "1": s1, "2": s2}, {s1: "", s2: "", "1": s1, "2": s2} ]); - StringRecord19Array|csv:Error st4sr19 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord19Array); + StringRecord19Array|csv:Error st4sr19 = csv:parseList([st4, st4], {}); test:assertEquals(st4sr19, [ {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord20Array|csv:Error st3sr20 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord20Array); + StringRecord20Array|csv:Error st3sr20 = csv:parseList([st3, st3], {}); test:assertEquals(st3sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} ]); - StringRecord20Array|csv:Error st4sr20 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord20Array); + StringRecord20Array|csv:Error st4sr20 = csv:parseList([st4, st4], {}); test:assertEquals(st4sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} ]); - StringRecord21Array|csv:Error st3sr21 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord21Array); + StringRecord21Array|csv:Error st3sr21 = csv:parseList([st3, st3], {}); test:assertEquals(st3sr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord21Array|csv:Error st4sr21 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord21Array); + StringRecord21Array|csv:Error st4sr21 = csv:parseList([st4, st4], {}); test:assertEquals(st4sr21, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord22Array|csv:Error st3sr22 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord22Array); + StringRecord22Array|csv:Error st3sr22 = csv:parseList([st3, st3], {}); test:assertEquals(st3sr22, [ {s1: "", s2: "", "1": s1, "2": s2}, {s1: "", s2: "", "1": s1, "2": s2} ]); - StringRecord22Array|csv:Error st4sr22 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord22Array); + StringRecord22Array|csv:Error st4sr22 = csv:parseList([st4, st4], {}); test:assertEquals(st4sr22, [ {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord23Array|csv:Error st3sr23 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord23Array); + StringRecord23Array|csv:Error st3sr23 = csv:parseList([st3, st3], {}); test:assertEquals(st3sr23, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord23Array|csv:Error st4sr23 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord23Array); + StringRecord23Array|csv:Error st4sr23 = csv:parseList([st4, st4], {}); test:assertEquals(st4sr23, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord15Array|csv:Error st3cr15 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord15Array); + CustomRecord15Array|csv:Error st3cr15 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} @@ -389,111 +389,111 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType5() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType6() { - CustomRecord15Array|csv:Error st4cr15 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord15Array); + CustomRecord15Array|csv:Error st4cr15 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord16Array|csv:Error st3cr16 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord16Array); + CustomRecord16Array|csv:Error st3cr16 = csv:parseList([st3, st3], {}); test:assertTrue(st3cr16 is csv:Error); test:assertEquals((st3cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); - CustomRecord16Array|csv:Error st4cr16 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord16Array); + CustomRecord16Array|csv:Error st4cr16 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr16, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord17Array|csv:Error st3cr17 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord17Array); + CustomRecord17Array|csv:Error st3cr17 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr17, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord17Array|csv:Error st4cr17 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord17Array); + CustomRecord17Array|csv:Error st4cr17 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr17, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord18Array|csv:Error st3cr18 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord18Array); + CustomRecord18Array|csv:Error st3cr18 = csv:parseList([st3, st3], {}); test:assertTrue(st3cr18 is csv:Error); test:assertEquals((st3cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); - CustomRecord18Array|csv:Error st4cr18 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord18Array); + CustomRecord18Array|csv:Error st4cr18 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr18, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord19Array|csv:Error st3cr19 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord19Array); + CustomRecord19Array|csv:Error st3cr19 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr19, [ {'1: s1, '2: s2, '3: "", '4: ""}, {'1: s1, '2: s2, '3: "", '4: ""} ]); - CustomRecord19Array|csv:Error st4cr19 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord19Array); + CustomRecord19Array|csv:Error st4cr19 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr19, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord20Array|csv:Error st3cr20 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord20Array); + CustomRecord20Array|csv:Error st3cr20 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr20, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord20Array|csv:Error st4cr20 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord20Array); + CustomRecord20Array|csv:Error st4cr20 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr20, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord21Array|csv:Error st3cr21 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord21Array); + CustomRecord21Array|csv:Error st3cr21 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord21Array|csv:Error st4cr21 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord21Array); + CustomRecord21Array|csv:Error st4cr21 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr21, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord22Array|csv:Error st3cr22 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord22Array); + CustomRecord22Array|csv:Error st3cr22 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr22, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord22Array|csv:Error st4cr22 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord22Array); + CustomRecord22Array|csv:Error st4cr22 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr22, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord23Array|csv:Error st3cr23 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord23Array); + CustomRecord23Array|csv:Error st3cr23 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr23, [ {"1": s1, "2": s2, a: ""}, {"1": s1, "2": s2, a: ""} ]); - CustomRecord23Array|csv:Error st4cr23 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord23Array); + CustomRecord23Array|csv:Error st4cr23 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr23, [ {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} ]); - CustomRecord24Array|csv:Error st3cr24 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord24Array); + CustomRecord24Array|csv:Error st3cr24 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr24, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord24Array|csv:Error st4cr24 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord24Array); + CustomRecord24Array|csv:Error st4cr24 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr24, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} @@ -502,188 +502,327 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType6() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { - record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["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:parseListAsRecordType( + 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", "()"]], - ["f", "e", "d", "c", "b", "a"]); + {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br6, [ {a: (), b: 2.23, c: 0, d: true, e: 1, f: "a"}, {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:parseListAsRecordType( + 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", "()"]], - ["f", "e", "d", "c", "b", "a"]); + {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br7, [ {c: 0, d: true, e: 1, f: "a"}, {c: 2.23, d: true, e: 1, f: "a"} ]); - record{decimal c; boolean d; int e; string f;}[]|csv:Error ct1br8 = csv:parseListAsRecordType( + 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", "()"]], - ["f", "e", "d", "c", "b", "a"]); + {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br8, [ {a: (), b: 2.23, c: 0, d: true, e: 1, f: "a"}, {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:parseListAsRecordType( + 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", "()"]], - ["f", "e", "d", "c", "b", "a"]); + {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br9, [ {a: (), b: 2.23, c: 0, d: true, e: 1, f: "a"}, {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:parseListAsRecordType( + 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", "()"]], - ["f", "e", "d", "c", "b", "a"]); + {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br9_2, [ {a: (), b: 2.23, c: 0, d: true, e: 1, f: "a"}, {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); } +@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"]], {headerRows: 0, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + 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"]], {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"]], {headerRows: 1, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + 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"]], {headerRows: 2, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + test:assertEquals(ct1br4_4, [ + {a: "a", b: true, c: 1} + ]); + + record{string a; boolean b; int c;}[]|csv:Error ct1br4_5 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, outputWithHeaders: true}); + test:assertTrue(ct1br4_5 is csv:Error); + 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"]], {headerRows: 2, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + test:assertEquals(ct1br4_4_2, [ + {a: "a", b: true, c: 1} + ]); + + record{|string a; boolean b; int...;|}[]|csv:Error ct1br4_5_2 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, outputWithHeaders: true}); + test:assertTrue(ct1br4_5_2 is csv:Error); + 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"]], {headerRows: 1, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + 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"]], {headerRows: 3, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + test:assertEquals(ct2br4_3_2, []); + + map[]|csv:Error ct2br4_4 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + 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"]], {headerRows: 2, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + test:assertEquals(ct2br4_5, [ + {a: "a", b: "true", c: "1"}, + {a: "a", b: "true", c: "1"} + ]); + + map[]|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[]|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"); + + map[]|csv:Error ct2br4_8 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, outputWithHeaders: true}); + test:assertEquals(ct2br4_8, [ + {"a": "a", "1": "1", "true": "true"}, + {"a": "a", "1": "1", "true": "true"}, + {"a": "a", "1": "1", "true": "true"} + ]); + + map[]|csv:Error ct2br4_8_2 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, outputWithHeaders: false}); + test:assertEquals(ct2br4_8_2, [ + {"a": "a", "1": "1", "true": "true"}, + {"a": "a", "1": "1", "true": "true"}, + {"a": "a", "1": "1", "true": "true"} + ]); + + map[]|csv:Error ct2br4_9 = csv:parseList( + [["a", "c", "b"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1, outputWithHeaders: true}); + test:assertEquals(ct2br4_9, [ + {a: "a", b: "true", c: "2"}, + {a: "a", b: "true", c: "3"}, + {a: "a", b: "true", c: "4"}, + {a: "a", b: "true", c: "5"} + ]); + + map[]|csv:Error ct2br4_10 = csv:parseList( + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1, outputWithHeaders: true}); + test:assertEquals(ct2br4_10, [ + {a: "a", c: true, b: 2}, + {a: "a", c: true, b: 3}, + {a: "a", c: true, b: 4}, + {a: "a", c: true, b: 5} + ]); + + map[]|csv:Error ct2br4_10_2 = csv:parseList( + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1, outputWithHeaders: false}); + test:assertEquals(ct2br4_10_2, [ + {a: "a", c: true, b: 2}, + {a: "a", c: true, b: 3}, + {a: "a", c: true, b: 4}, + {a: "a", c: true, b: 5} + ]); + + ct2br4_10_2 = 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_2, [ + {c: "a", e: true, d: 2}, + {c: "a", e: true, d: 3}, + {c: "a", e: true, d: 4}, + {c: "a", e: true, d: 5} + ]); +} + @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { - record{|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseListAsRecordType( + 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", "()"]], - ["f", "e", "d", "c", "b", "a"]); + {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br10, [ {a: "null", b: "2.23", c: 0, d: true, e: 1, f: "a"}, {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:parseListAsRecordType( + 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", "()"]], - ["f", "e", "d", "c", "b", "a"]); + {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br11, [ {a: (), c: 0, d: true, e: 1, f: "a"}, {a: (), c: 2.23, d: true, e: 1, f: "a"} ]); - record{|()...;|}[]|csv:Error ct1br12 = csv:parseListAsRecordType( + record{|()...;|}[]|csv:Error ct1br12 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["f", "e", "d", "c", "b", "a"]); + {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br12, [ {a: ()}, {a: ()} ]); - record{|string?...;|}[]|csv:Error ct1br13 = csv:parseListAsRecordType( + record{|string?...;|}[]|csv:Error ct1br13 = csv:parseList( [["a", "1"], ["a", "1"]], - ["f", "e"]); + {customHeaders: ["f", "e"]}); test:assertEquals(ct1br13, [ {e: "1", f: "a"}, {e: "1", f: "a"} ]); - record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseListAsRecordType( + record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseList( [["2.23", "null"], ["7", "()"]], - ["b", "a"]); + {customHeaders: ["b", "a"]}); test:assertEquals(ct1br14, [ {}, {} ]); - map[]|csv:Error ct1br15 = csv:parseListAsRecordType( + map[]|csv:Error ct1br15 = csv:parseList( [["2", "()"], ["2", "1"], ["()", "2"]], - ["f", "e"]); + {customHeaders: ["f", "e"]}); test:assertEquals(ct1br15, [ {e: (), f: 2}, {e: 1, f: 2}, {e: 2, f: ()} ]); - record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseListAsRecordType( + record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseList( [["2.23", "null"], ["7", "()"]], - ["b", "a"]); + {customHeaders: ["b", "a"]}); test:assertEquals(ct1br16, [ {}, {} ]); } +@test:Config +function testArrayIndexesWithRecordAsExpectedType() { + string[][] csv = [["1", "2", "3"], ["3", "4", "5"], ["5", "6", "7"], ["7", "8", "9"]]; + + map[2]|csv:Error rec_2 = csv:parseList(csv, {customHeaders: ["a", "b", "c"]}); + test:assertEquals(rec_2, [ + {a: 1, b: 2, c: 3}, + {a: 3, b: 4, c: 5} + ]); +} + @test:Config function testFromCsvWithTypeForTupleAndMapAsExpectedType() { - StringMapArray|csv:Error st1sma = csv:parseListAsRecordType([st1, st1], (), {}, StringMapArray); + StringMapArray|csv:Error st1sma = csv:parseList([st1, st1], {}); test:assertEquals(st1sma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - StringMapArray|csv:Error st2sma = csv:parseListAsRecordType([st2, st2], (), {}, StringMapArray); + StringMapArray|csv:Error st2sma = csv:parseList([st2, st2], {}); test:assertEquals(st2sma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - StringMapArray|csv:Error st3sma = csv:parseListAsRecordType([st3, st3], (), {}, StringMapArray); + StringMapArray|csv:Error st3sma = csv:parseList([st3, st3], {}); test:assertEquals(st3sma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - StringMapArray|csv:Error st4sma = csv:parseListAsRecordType([st4, st4], (), {}, StringMapArray); + StringMapArray|csv:Error st4sma = csv:parseList([st4, st4], {}); test:assertEquals(st4sma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - NillableIntUnionStringMapArray|csv:Error st1niusma = csv:parseListAsRecordType([st1, st1], (), {}, NillableIntUnionStringMapArray); + NillableIntUnionStringMapArray|csv:Error st1niusma = csv:parseList([st1, st1], {}); test:assertEquals(st1niusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - NillableIntUnionStringMapArray|csv:Error st2niusma = csv:parseListAsRecordType([st2, st2], (), {}, NillableIntUnionStringMapArray); + NillableIntUnionStringMapArray|csv:Error st2niusma = csv:parseList([st2, st2], {}); test:assertEquals(st2niusma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - NillableIntUnionStringMapArray|csv:Error st3niusma = csv:parseListAsRecordType([st3, st3], (), {}, NillableIntUnionStringMapArray); + NillableIntUnionStringMapArray|csv:Error st3niusma = csv:parseList([st3, st3], {}); test:assertEquals(st3niusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - NillableIntUnionStringMapArray|csv:Error st4niusma = csv:parseListAsRecordType([st4, st4], (), {}, NillableIntUnionStringMapArray); + NillableIntUnionStringMapArray|csv:Error st4niusma = csv:parseList([st4, st4], {}); test:assertEquals(st4niusma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - IntUnionStringMapArray|csv:Error st1iusma = csv:parseListAsRecordType([st1, st1], (), {}, IntUnionStringMapArray); + IntUnionStringMapArray|csv:Error st1iusma = csv:parseList([st1, st1], {}); test:assertEquals(st1iusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - IntUnionStringMapArray|csv:Error st2iusma = csv:parseListAsRecordType([st2, st2], (), {}, IntUnionStringMapArray); + IntUnionStringMapArray|csv:Error st2iusma = csv:parseList([st2, st2], {}); test:assertEquals(st2iusma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - IntUnionStringMapArray|csv:Error st3iusma = csv:parseListAsRecordType([st3, st3], (), {}, IntUnionStringMapArray); + IntUnionStringMapArray|csv:Error st3iusma = csv:parseList([st3, st3], {}); test:assertEquals(st3iusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - IntUnionStringMapArray|csv:Error st4iusma = csv:parseListAsRecordType([st4, st4], (), {}, IntUnionStringMapArray); + IntUnionStringMapArray|csv:Error st4iusma = csv:parseList([st4, st4], {}); test:assertEquals(st4iusma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - JsonMapArray|csv:Error st1jma = csv:parseListAsRecordType([st1, st1], (), {}, JsonMapArray); + JsonMapArray|csv:Error st1jma = csv:parseList([st1, st1], {}); test:assertEquals(st1jma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} @@ -692,91 +831,91 @@ function testFromCsvWithTypeForTupleAndMapAsExpectedType() { @test:Config function testFromCsvWithTypeForTupleAndMapAsExpectedType2() { - JsonMapArray|csv:Error st2jma = csv:parseListAsRecordType([st2, st2], (), {}, JsonMapArray); + JsonMapArray|csv:Error st2jma = csv:parseList([st2, st2], {}); test:assertEquals(st2jma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - JsonMapArray|csv:Error st3jma = csv:parseListAsRecordType([st3, st3], (), {}, JsonMapArray); + JsonMapArray|csv:Error st3jma = csv:parseList([st3, st3], {}); test:assertEquals(st3jma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - JsonMapArray|csv:Error st4jma = csv:parseListAsRecordType([st4, st4], (), {}, JsonMapArray); + JsonMapArray|csv:Error st4jma = csv:parseList([st4, st4], {}); test:assertEquals(st4jma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - AnydataMapArray|csv:Error st1anydma = csv:parseListAsRecordType([st1, st1], (), {}, AnydataMapArray); + AnydataMapArray|csv:Error st1anydma = csv:parseList([st1, st1], {}); test:assertEquals(st1anydma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - AnydataMapArray|csv:Error st2anydma = csv:parseListAsRecordType([st2, st2], (), {}, AnydataMapArray); + AnydataMapArray|csv:Error st2anydma = csv:parseList([st2, st2], {}); test:assertEquals(st2anydma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - AnydataMapArray|csv:Error st3anydma = csv:parseListAsRecordType([st3, st3], (), {}, AnydataMapArray); + AnydataMapArray|csv:Error st3anydma = csv:parseList([st3, st3], {}); test:assertEquals(st3anydma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - AnydataMapArray|csv:Error st4anydma = csv:parseListAsRecordType([st4, st4], (), {}, AnydataMapArray); + AnydataMapArray|csv:Error st4anydma = csv:parseList([st4, st4], {}); test:assertEquals(st4anydma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomMapArray|csv:Error st1cma = csv:parseListAsRecordType([st1, st1], (), {}, CustomMapArray); + CustomMapArray|csv:Error st1cma = csv:parseList([st1, st1], {}); test:assertEquals(st1cma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - CustomMapArray|csv:Error st2cma = csv:parseListAsRecordType([st2, st2], (), {}, CustomMapArray); + CustomMapArray|csv:Error st2cma = csv:parseList([st2, st2], {}); test:assertEquals(st2cma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomMapArray|csv:Error st3cma = csv:parseListAsRecordType([st3, st3], (), {}, CustomMapArray); + CustomMapArray|csv:Error st3cma = csv:parseList([st3, st3], {}); test:assertEquals(st3cma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - CustomMapArray|csv:Error st4cma = csv:parseListAsRecordType([st4, st4], (), {}, CustomMapArray); + CustomMapArray|csv:Error st4cma = csv:parseList([st4, st4], {}); test:assertEquals(st4cma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - NilMapArray|csv:Error st1nma = csv:parseListAsRecordType([st1, st1], (), {}, NilMapArray); + NilMapArray|csv:Error st1nma = csv:parseList([st1, st1], {}); test:assertEquals(st1nma, ([ {}, {} ])); - IntegerMapArray|csv:Error st2ima = csv:parseListAsRecordType([st2, st2], (), {}, IntegerMapArray); + IntegerMapArray|csv:Error st2ima = csv:parseList([st2, st2], {}); test:assertEquals(st2ima, ([ {}, {} ])); - DecimalMapArray|csv:Error st3dma = csv:parseListAsRecordType([st3, st3], (), {}, DecimalMapArray); + DecimalMapArray|csv:Error st3dma = csv:parseList([st3, st3], {}); test:assertEquals(st3dma, ([ {}, {} ])); - BooleanMapArray|csv:Error st4bma = csv:parseListAsRecordType([st4, st4], (), {}, BooleanMapArray); + BooleanMapArray|csv:Error st4bma = csv:parseList([st4, st4], {}); test:assertEquals(st4bma, ([ {}, {} diff --git a/ballerina-tests/parse-record-types-tests/Ballerina.toml b/ballerina-tests/parse-record-types-tests/Ballerina.toml index bd4f487..7cdb2d4 100644 --- a/ballerina-tests/parse-record-types-tests/Ballerina.toml +++ b/ballerina-tests/parse-record-types-tests/Ballerina.toml @@ -13,4 +13,4 @@ version = "0.1.0" graalvmCompatible = true [build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" +graalvmBuildOptions = "-H:+IncludeAllLocales" 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 6ddef47..93b4e74 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:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanArrayArray); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - bm1ba = csv:parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}, BooleanArrayArray); + bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b2", "b1"]}, BooleanArrayArray); test:assertEquals(bm1ba, [ [false, true], [false, true] ]); - BooleanArrayArray|csv:Error bm2ba = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm2ba = csv:transform([bm2, bm2], {headersOrder: ["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:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm3ba = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm4ba = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanArrayArray); test:assertTrue(bm4ba is csv:Error); test:assertEquals((bm4ba).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanArrayArray|csv:Error bm5ba = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm5ba = csv:transform([bm5, bm5], {headersOrder: ["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:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm1nba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanArrayArray); test:assertEquals(bm1nba, [ [true, false], [true, false] ]); - NillableBooleanArrayArray|csv:Error bm2nba = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm2nba = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanArrayArray); test:assertEquals(bm2nba, [ [true, false, null, null, null], [true, false, null, null, null] ]); - NillableBooleanArrayArray|csv:Error bm3nba = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm3nba = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm4nba = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanArrayArray); test:assertEquals(bm4nba, [ [(), ()], [(), ()] ]); - NillableBooleanArrayArray|csv:Error bm5nba = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm5nba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanArrayArray); test:assertEquals(bm5nba, [ [true, false, (), true], [true, false, (), true] ]); - bm5nba = csv:parseRecordAsListType([bm5, bm5], ["b1", "b3", "b2", "b4"], {}, NillableBooleanArrayArray); + bm5nba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b3", "b2", "b4"]}, NillableBooleanArrayArray); test:assertEquals(bm5nba, [ [true, (), false, true], [true, (), false, true] ]); - bm5nba = csv:parseRecordAsListType([bm5, bm5], ["b4", "b3", "b2", "b1"], {}, NillableBooleanArrayArray); + bm5nba = csv:transform([bm5, bm5], {headersOrder: ["b4", "b3", "b2", "b1"]}, NillableBooleanArrayArray); test:assertEquals(bm5nba, [ [true, (), false, true], [true, (), false, true] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm1niouba = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm1niouba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm1niouba, [ [true, false], [true, false] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm2niouba = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm2niouba = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm2niouba, [ [true, false, null, null, null], [true, false, null, null, null] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm3niouba = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm3niouba = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm3niouba, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm4niouba = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm4niouba = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm4niouba, [ [(), ()], [(), ()] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm5niouba = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm5niouba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm5niouba, [ [true, false, (), true], [true, false, (), true] ]); - JsonArray1Array|csv:Error bm1ja = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, JsonArray1Array); + JsonArray1Array|csv:Error bm1ja = csv:transform([bm1, bm1], {headersOrder: ["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:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, JsonArray1Array); + JsonArray1Array|csv:Error bm2ja = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, JsonArray1Array); test:assertEquals(bm2ja, [ [true, false, null, null, null], [true, false, null, null, null] ]); - JsonArray1Array|csv:Error bm3ja = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, JsonArray1Array); + JsonArray1Array|csv:Error bm3ja = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, JsonArray1Array); test:assertEquals(bm3ja, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - JsonArray1Array|csv:Error bm4ja = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonArray1Array); + JsonArray1Array|csv:Error bm4ja = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, JsonArray1Array); test:assertEquals(bm4ja, [ [(), ()], [(), ()] ]); - JsonArray1Array|csv:Error bm5ja = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, JsonArray1Array); + JsonArray1Array|csv:Error bm5ja = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, JsonArray1Array); test:assertEquals(bm5ja, [ [true, false, (), true], [true, false, (), true] ]); - AnydataArray1Array|csv:Error bm1anyda = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm1anyda = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, AnydataArray1Array); test:assertEquals(bm1anyda, [ [true, false], [true, false] ]); - AnydataArray1Array|csv:Error bm2anyda = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm2anyda = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, AnydataArray1Array); test:assertEquals(bm2anyda, [ [true, false, null, null, null], [true, false, null, null, null] ]); - AnydataArray1Array|csv:Error bm3anyda = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm3anyda = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, AnydataArray1Array); test:assertEquals(bm3anyda, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - AnydataArray1Array|csv:Error bm4anyda = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm4anyda = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, AnydataArray1Array); test:assertEquals(bm4anyda, [ [(), ()], [(), ()] ]); - AnydataArray1Array|csv:Error bm5anyda = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm5anyda = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, AnydataArray1Array); test:assertEquals(bm5anyda, [ [true, false, (), true], [true, false, (), true] ]); - StringArray1Array|csv:Error bm1sa = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, StringArray1Array); + StringArray1Array|csv:Error bm1sa = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, StringArray1Array); test:assertTrue(bm1sa is csv:Error); test:assertEquals((bm1sa).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|csv:Error bm2sa = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, StringArray1Array); + StringArray1Array|csv:Error bm2sa = csv:transform([bm2, bm2], {headersOrder: ["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:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, StringArray1Array); + StringArray1Array|csv:Error bm3sa = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, StringArray1Array); + StringArray1Array|csv:Error bm4sa = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, StringArray1Array); test:assertTrue(bm4sa is csv:Error); test:assertEquals((bm4sa).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - StringArray1Array|csv:Error bm5sa = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, StringArray1Array); + StringArray1Array|csv:Error bm5sa = csv:transform([bm5, bm5], {headersOrder: ["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:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm1bt = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple1Array); test:assertEquals(bm1bt, [ [true, false, false, false], [true, false, false, false] ]); - BooleanTuple1Array|csv:Error bm2bt = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm2bt = csv:transform([bm2, bm2], {headersOrder: ["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:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm3bt = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm4bt = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple1Array); test:assertTrue(bm4bt is csv:Error); test:assertEquals((bm4bt).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple1Array|csv:Error bm5bt = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm5bt = csv:transform([bm5, bm5], {headersOrder: ["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:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm1b2t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple2Array); test:assertEquals(bm1b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error bm2b2t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm2b2t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple2Array); test:assertEquals(bm2b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error bm3b2t = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm3b2t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple2Array); test:assertEquals(bm3b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error bm4b2t = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm4b2t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple2Array); test:assertTrue(bm4b2t is csv:Error); test:assertEquals((bm4b2t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple2Array|csv:Error bm5b2t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm5b2t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple2Array); test:assertEquals(bm5b2t, [ [true, false], [true, false] ]); - BooleanTuple3Array|csv:Error bm1b3t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm1b3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple3Array); test:assertEquals(bm1b3t, [ [true, false], [true, false] ]); - BooleanTuple3Array|csv:Error bm2b3t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm2b3t = csv:transform([bm2, bm2], {headersOrder: ["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:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm3b3t = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm4b3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple3Array); test:assertTrue(bm4b3t is csv:Error); test:assertEquals((bm4b3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple3Array|csv:Error bm5b3t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm5b3t = csv:transform([bm5, bm5], {headersOrder: ["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:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm1b4t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple4Array); test:assertEquals(bm1b4t, [ [true, false], [true, false] ]); - BooleanTuple4Array|csv:Error bm2b4t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm2b4t = csv:transform([bm2, bm2], {headersOrder: ["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:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm3b4t = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm4b4t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple4Array); test:assertTrue(bm4b4t is csv:Error); test:assertEquals((bm4b4t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple4Array|csv:Error bm5b4t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm5b4t = csv:transform([bm5, bm5], {headersOrder: ["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:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm1nbt = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple5Array); test:assertEquals(bm1nbt, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple5Array|csv:Error bm2nbt = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm2nbt = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple5Array); test:assertEquals(bm2nbt, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple5Array|csv:Error bm3nbt = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm3nbt = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm4nbt = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple5Array); test:assertEquals(bm4nbt, [ [(), (), (), (), ()], [(), (), (), (), ()] ]); - NillableBooleanTuple5Array|csv:Error bm5nbt = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm5nbt = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple5Array); test:assertEquals(bm5nbt, [ [true, false, (), true, ()], [true, false, (), true, ()] ]); - NillableBooleanTuple6Array|csv:Error bm1nb6t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm1nb6t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple6Array); test:assertEquals(bm1nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error bm2nb6t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm2nb6t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple6Array); test:assertEquals(bm2nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error bm3nb6t = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm3nb6t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple6Array); test:assertEquals(bm3nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error bm4nb6t = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm4nb6t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple6Array); test:assertEquals(bm4nb6t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple6Array|csv:Error bm5nb6t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm5nb6t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple6Array); test:assertEquals(bm5nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple7Array|csv:Error bm1nb7t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm1nb7t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple7Array); test:assertEquals(bm1nb7t, [ [true, false], [true, false] ]); - NillableBooleanTuple7Array|csv:Error bm2nb7t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm2nb7t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple7Array); test:assertEquals(bm2nb7t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple7Array|csv:Error bm3nb7t = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm3nb7t = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm4nb7t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple7Array); test:assertEquals(bm4nb7t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple7Array|csv:Error bm5nb7t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm5nb7t = csv:transform([bm5, bm5], {headersOrder: ["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:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm1nb8t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple8Array); test:assertEquals(bm1nb8t, [ [true, false], [true, false] ]); - NillableBooleanTuple8Array|csv:Error bm2nb8t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm2nb8t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple8Array); test:assertEquals(bm2nb8t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple8Array|csv:Error bm3nb8t = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm3nb8t = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm4nb8t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple8Array); test:assertEquals(bm4nb8t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple8Array|csv:Error bm5nb8t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm5nb8t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple8Array); test:assertEquals(bm5nb8t, [ [true, false, (), true], [true, false, (), true] ]); - NillableIntBooleanTuple9Array|csv:Error bm1nb9t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm1nb9t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm1nb9t, [ [true, false], [true, false] ]); - NillableIntBooleanTuple9Array|csv:Error bm2nb9t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm2nb9t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm2nb9t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableIntBooleanTuple9Array|csv:Error bm3nb9t = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm3nb9t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm3nb9t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - NillableIntBooleanTuple9Array|csv:Error bm4nb9t = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm4nb9t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm4nb9t, [ [(), ()], [(), ()] ]); - NillableIntBooleanTuple9Array|csv:Error bm5nb9t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm5nb9t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm5nb9t, [ [true, false, (), true], [true, false, (), true] ]); - NilTuple3Array|csv:Error bm1n3t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NilTuple3Array); + NilTuple3Array|csv:Error bm1n3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NilTuple3Array); test:assertTrue(bm1n3t is csv:Error); test:assertEquals((bm1n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|csv:Error bm2n3t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NilTuple3Array); + NilTuple3Array|csv:Error bm2n3t = csv:transform([bm2, bm2], {headersOrder: ["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:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NilTuple3Array); + NilTuple3Array|csv:Error bm3n3t = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NilTuple3Array); + NilTuple3Array|csv:Error bm4n3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NilTuple3Array); test:assertEquals(bm4n3t, [ [(), ()], [(), ()] ]); - NilTuple3Array|csv:Error bm5n3t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NilTuple3Array); + NilTuple3Array|csv:Error bm5n3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NilTuple3Array); test:assertTrue(bm5n3t is csv:Error); test:assertEquals((bm5n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); } @@ -474,83 +474,209 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType3() { @test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType3() { - AnydataTuple3Array|csv:Error bm1anyd3t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"], outputWithHeaders: false}, AnydataTuple3Array); test:assertEquals(bm1anyd3t, [ [true, false], [true, false] ]); - AnydataTuple3Array|csv:Error bm2anyd3t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm2anyd3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, AnydataTuple3Array); test:assertEquals(bm2anyd3t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - AnydataTuple3Array|csv:Error bm3anyd3t = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm3anyd3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, AnydataTuple3Array); test:assertEquals(bm3anyd3t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - AnydataTuple3Array|csv:Error bm4anyd3t = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm4anyd3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"], outputWithHeaders: false}, AnydataTuple3Array); test:assertEquals(bm4anyd3t, [ [(), ()], [(), ()] ]); - AnydataTuple3Array|csv:Error bm5anyd3t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm5anyd3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, AnydataTuple3Array); test:assertEquals(bm5anyd3t, [ [true, false, (), true], [true, false, (), true] ]); - JsonTuple3Array|csv:Error bm1j3t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm1j3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, JsonTuple3Array); test:assertEquals(bm1j3t, [ [true, false], [true, false] ]); - JsonTuple3Array|csv:Error bm2j3t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm2j3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, JsonTuple3Array); test:assertEquals(bm2j3t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - JsonTuple3Array|csv:Error bm3j3t = csv:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm3j3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, JsonTuple3Array); test:assertEquals(bm3j3t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - JsonTuple3Array|csv:Error bm4j3t = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm4j3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, JsonTuple3Array); test:assertEquals(bm4j3t, [ [(), ()], [(), ()] ]); - JsonTuple3Array|csv:Error bm5j3t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm5j3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, JsonTuple3Array); test:assertEquals(bm5j3t, [ [true, false, (), true], [true, false, (), true] ]); - StringTuple3Array|csv:Error bm1s3t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, StringTuple3Array); + StringTuple3Array|csv:Error bm1s3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, StringTuple3Array); test:assertTrue(bm1s3t is csv:Error); test:assertEquals((bm1s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|csv:Error bm2s3t = csv:parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, StringTuple3Array); + StringTuple3Array|csv:Error bm2s3t = csv:transform([bm2, bm2], {headersOrder: ["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:parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, StringTuple3Array); + StringTuple3Array|csv:Error bm3s3t = csv:transform([bm3, bm3], {headersOrder: ["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:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, StringTuple3Array); + StringTuple3Array|csv:Error bm4s3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, StringTuple3Array); test:assertTrue(bm4s3t is csv:Error); test:assertEquals((bm4s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - StringTuple3Array|csv:Error bm5s3t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, StringTuple3Array); + StringTuple3Array|csv:Error bm5s3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, StringTuple3Array); test:assertTrue(bm5s3t is csv:Error); test:assertEquals((bm5s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } + +@test:Config +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"]}); + test:assertEquals(rec3, [ + [1, 2], + [3, 4], + [5, 6], + [7, 8] + ]); + + [int...][2]|csv:Error rec3_3 = csv:transform(csv, {headersOrder: ["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]}); + test:assertEquals(rec4, [ + [1, 2] + ]); +} + +@test:Config +function testParseRecordsAsListsWithHeaderOutput() { + AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([bm1, bm1], {headersOrder: ["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}); + 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}); + 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}); + 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}); + 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}); + 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}); + 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}); + 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}); + test:assertTrue(bm2anyd3t_4 is csv:Error); + test:assertEquals(( bm2anyd3t_4).message(), "CSV data rows with varying headers are not yet supported"); +} + +@test:Config +function testsRecordsOutputWithHeadrs() { + anydata[2][3]|csv:Error bm3anyd3t_2 = csv:transform([bm3, bm3], {outputWithHeaders: true}); + test:assertEquals(bm3anyd3t_2, [ + ["b1", "b2", "b3"], + [true, false, ()] + ]); + + anydata[][]|csv:Error bm3anyd3t_3 = csv:transform([bm3, bm3], {outputWithHeaders: true}); + test:assertEquals(bm3anyd3t_3, [ + ["b1", "b2", "b3", "b4", "i1"], + [true, false, (), false, 1], + [true, false, (), false, 1] + ]); + + bm3anyd3t_3 = csv:transform([{"a": 1, "b": 2}, {"a": 3, "b": 4}], {outputWithHeaders: true}); + test:assertEquals(bm3anyd3t_3, [ + ["a", "b"], + [1, 2], + [3, 4] + ]); + + bm3anyd3t_3 = csv:transform([{"a": 1, "b": 2}, {"c": 3, "d": 4}], {outputWithHeaders: true}); + test:assertTrue(bm3anyd3t_3 is csv:Error); + test:assertEquals(( bm3anyd3t_3).message(), "CSV data rows with varying headers are not yet supported"); + + bm3anyd3t_3 = csv:transform([{"a": 1, "b": 2}, {"c": 3, "d": 4}], {outputWithHeaders: false}); + 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}], {outputWithHeaders: true}); + test:assertEquals(bm3anyd3t_4, [{"a": 1, "b": 2}, {"a": 3, "b": 4}]); + + bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"c": 3, "d": 4}], {outputWithHeaders: true}); + test:assertEquals(bm3anyd3t_4, [{"a": 1, "b": 2}, {"c": 3, "d": 4}]); + + bm3anyd3t_3 = csv:parseList([["a", "b"], ["c", "d", "e"]], {outputWithHeaders: true}); + test:assertEquals(bm3anyd3t_3, [["a", "b"], ["c", "d", "e"]]); + + bm3anyd3t_4 = csv:parseList([["a", "b"], ["c", "d", "e"]], {outputWithHeaders: true}); + test:assertTrue(bm3anyd3t_4 is csv:Error); + test:assertEquals(( bm3anyd3t_4).message(), "CSV data rows with varying headers are not yet supported"); +} diff --git a/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_record_test.bal b/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_record_test.bal index 50dde64..3c603e6 100644 --- a/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_record_test.bal +++ b/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_record_test.bal @@ -20,108 +20,108 @@ import ballerina/test; @test:Config function testFromCsvWithTypeForMapAndRecordAsExpectedType() { - BooleanRecord1Array|csv:Error bm1br1 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord1Array); + BooleanRecord1Array|csv:Error bm1br1 = csv:transform([bm1, bm1], {}, BooleanRecord1Array); test:assertTrue(bm1br1 is csv:Error); test:assertEquals((bm1br1).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord1Array|csv:Error bm2br1 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord1Array); + BooleanRecord1Array|csv:Error bm2br1 = csv:transform([bm2, bm2], {}, BooleanRecord1Array); test:assertTrue(bm2br1 is csv:Error); test:assertEquals((bm2br1).message(), common:generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord1Array|csv:Error bm3br1 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord1Array); + BooleanRecord1Array|csv:Error bm3br1 = csv:transform([bm3, bm3], {}, BooleanRecord1Array); test:assertEquals(bm3br1, [ {b1: true, b2: false, b3: (), b4: false, i1: 1}, {b1: true, b2: false, b3: (), b4: false, i1: 1} ]); - BooleanRecord1Array|csv:Error bm4br1 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord1Array); + BooleanRecord1Array|csv:Error bm4br1 = csv:transform([bm4, bm4], {}, BooleanRecord1Array); test:assertTrue(bm4br1 is csv:Error); test:assertEquals((bm4br1).message(), common:generateErrorMessageForMissingRequiredField("b2")); - BooleanRecord1Array|csv:Error bm5br1 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord1Array); + BooleanRecord1Array|csv:Error bm5br1 = csv:transform([bm5, bm5], {}, BooleanRecord1Array); test:assertEquals(bm5br1, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - BooleanRecord2Array|csv:Error bm1br2 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord2Array); + BooleanRecord2Array|csv:Error bm1br2 = csv:transform([bm1, bm1], {}, BooleanRecord2Array); test:assertTrue(bm1br2 is csv:Error); test:assertEquals((bm1br2).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord2Array|csv:Error bm2br2 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord2Array); + BooleanRecord2Array|csv:Error bm2br2 = csv:transform([bm2, bm2], {}, BooleanRecord2Array); test:assertTrue(bm2br2 is csv:Error); test:assertEquals((bm2br2).message(), common:generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord2Array|csv:Error bm3br2 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord2Array); + BooleanRecord2Array|csv:Error bm3br2 = csv:transform([bm3, bm3], {}, BooleanRecord2Array); test:assertEquals(bm3br2, [ {b1: true, b2: false, b3: (), b4: false}, {b1: true, b2: false, b3: (), b4: false} ]); - BooleanRecord2Array|csv:Error bm4br2 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord2Array); + BooleanRecord2Array|csv:Error bm4br2 = csv:transform([bm4, bm4], {outputWithHeaders: false}, BooleanRecord2Array); test:assertTrue(bm4br2 is csv:Error); test:assertEquals((bm4br2).message(), common:generateErrorMessageForMissingRequiredField("b2")); - BooleanRecord2Array|csv:Error bm5br2 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord2Array); + BooleanRecord2Array|csv:Error bm5br2 = csv:transform([bm5, bm5], {}, BooleanRecord2Array); test:assertEquals(bm5br2, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - BooleanRecord3Array|csv:Error bm1br3 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord3Array); + BooleanRecord3Array|csv:Error bm1br3 = csv:transform([bm1, bm1], {}, BooleanRecord3Array); test:assertTrue(bm1br3 is csv:Error); test:assertEquals((bm1br3).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord3Array|csv:Error bm2br3 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord3Array); + BooleanRecord3Array|csv:Error bm2br3 = csv:transform([bm2, bm2], {}, BooleanRecord3Array); test:assertEquals(bm2br3, [ {b1: true, b3: ()}, {b1: true, b3: ()} ]); - BooleanRecord3Array|csv:Error bm3br3 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord3Array); + BooleanRecord3Array|csv:Error bm3br3 = csv:transform([bm3, bm3], {}, BooleanRecord3Array); test:assertEquals(bm3br3, [ {b1: true, b3: ()}, {b1: true, b3: ()} ]); - BooleanRecord3Array|csv:Error bm4br3 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord3Array); + BooleanRecord3Array|csv:Error bm4br3 = csv:transform([bm4, bm4], {}, BooleanRecord3Array); test:assertTrue(bm4br3 is csv:Error); test:assertEquals((bm4br3).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord3Array|csv:Error bm5br3 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord3Array); + BooleanRecord3Array|csv:Error bm5br3 = csv:transform([bm5, bm5], {}, BooleanRecord3Array); test:assertEquals(bm5br3, [{b1: true, b3: ()}, {b1: true, b3: ()}]); - BooleanRecord4Array|csv:Error bm1br4 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord4Array); + BooleanRecord4Array|csv:Error bm1br4 = csv:transform([bm1, bm1], {}, BooleanRecord4Array); test:assertTrue(bm1br4 is csv:Error); test:assertEquals((bm1br4).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord4Array|csv:Error bm2br4 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord4Array); + BooleanRecord4Array|csv:Error bm2br4 = csv:transform([bm2, bm2], {}, BooleanRecord4Array); test:assertEquals(bm2br4, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} ]); - BooleanRecord4Array|csv:Error bm3br4 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord4Array); + BooleanRecord4Array|csv:Error bm3br4 = csv:transform([bm3, bm3], {}, BooleanRecord4Array); test:assertEquals(bm3br4, [ {b1: true, b2: false, b3: (), b4: false, i1: 1}, {b1: true, b2: false, b3: (), b4: false, i1: 1} ]); - BooleanRecord4Array|csv:Error bm4br4 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord4Array); + BooleanRecord4Array|csv:Error bm4br4 = csv:transform([bm4, bm4], {}, BooleanRecord4Array); test:assertTrue(bm4br4 is csv:Error); test:assertEquals((bm4br4).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord4Array|csv:Error bm5br4 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord4Array); + BooleanRecord4Array|csv:Error bm5br4 = csv:transform([bm5, bm5], {}, BooleanRecord4Array); test:assertEquals(bm5br4, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - BooleanRecord5Array|csv:Error bm1br5 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord5Array); + BooleanRecord5Array|csv:Error bm1br5 = csv:transform([bm1, bm1], {}, BooleanRecord5Array); test:assertTrue(bm1br5 is csv:Error); test:assertEquals((bm1br5).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord5Array|csv:Error bm2br5 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord5Array); + BooleanRecord5Array|csv:Error bm2br5 = csv:transform([bm2, bm2], {}, BooleanRecord5Array); test:assertEquals(bm2br5, [ {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()}, {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()} @@ -130,214 +130,214 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType() { @test:Config function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { - BooleanRecord5Array|csv:Error bm3br5 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord5Array); + BooleanRecord5Array|csv:Error bm3br5 = csv:transform([bm3, bm3], {}, BooleanRecord5Array); test:assertEquals(bm3br5, [ {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, i1: 1, b4: false}, {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, i1: 1, b4: false} ]); - BooleanRecord5Array|csv:Error bm4br5 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord5Array); + BooleanRecord5Array|csv:Error bm4br5 = csv:transform([bm4, bm4], {}, BooleanRecord5Array); test:assertTrue(bm4br5 is csv:Error); test:assertEquals((bm4br5).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord5Array|csv:Error bm5br5 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord5Array); + BooleanRecord5Array|csv:Error bm5br5 = csv:transform([bm5, bm5], {}, BooleanRecord5Array); test:assertEquals(bm5br5, [ {b1: true, b2: false, b3: (), b4: true, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: (), b4: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error bm1br6 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord6Array); + BooleanRecord6Array|csv:Error bm1br6 = csv:transform([bm1, bm1], {outputWithHeaders: false}, BooleanRecord6Array); test:assertTrue(bm1br6 is csv:Error); test:assertEquals((bm1br6).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord6Array|csv:Error bm2br6 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord6Array); + BooleanRecord6Array|csv:Error bm2br6 = csv:transform([bm2, bm2], {}, BooleanRecord6Array); test:assertEquals(bm2br6, [ {b1: true, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error bm3br6 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord6Array); + BooleanRecord6Array|csv:Error bm3br6 = csv:transform([bm3, bm3], {outputWithHeaders: false}, BooleanRecord6Array); test:assertEquals(bm3br6, [ {b1: true, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error bm4br6 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord6Array); + BooleanRecord6Array|csv:Error bm4br6 = csv:transform([bm4, bm4], {}, BooleanRecord6Array); test:assertTrue(bm4br6 is csv:Error); test:assertEquals((bm4br6).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord6Array|csv:Error bm5br6 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord6Array); + BooleanRecord6Array|csv:Error bm5br6 = csv:transform([bm5, bm5], {}, BooleanRecord6Array); test:assertEquals(bm5br6, [ {b1: true, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord7Array|csv:Error bm1br7 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord7Array); + BooleanRecord7Array|csv:Error bm1br7 = csv:transform([bm1, bm1], {}, BooleanRecord7Array); test:assertTrue(bm1br7 is csv:Error); test:assertEquals((bm1br7).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord7Array|csv:Error bm2br7 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord7Array); + BooleanRecord7Array|csv:Error bm2br7 = csv:transform([bm2, bm2], {}, BooleanRecord7Array); test:assertTrue(bm2br7 is csv:Error); test:assertEquals((bm2br7).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord7Array|csv:Error bm3br7 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord7Array); + BooleanRecord7Array|csv:Error bm3br7 = csv:transform([bm3, bm3], {}, BooleanRecord7Array); test:assertTrue(bm3br7 is csv:Error); test:assertEquals((bm3br7).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord7Array|csv:Error bm4br7 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord7Array); + BooleanRecord7Array|csv:Error bm4br7 = csv:transform([bm4, bm4], {}, BooleanRecord7Array); test:assertTrue(bm4br7 is csv:Error); test:assertEquals((bm4br7).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord7Array|csv:Error bm5br7 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord7Array); + BooleanRecord7Array|csv:Error bm5br7 = csv:transform([bm5, bm5], {}, BooleanRecord7Array); test:assertTrue(bm5br7 is csv:Error); test:assertEquals((bm5br7).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord8Array|csv:Error bm1br8 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord8Array); + BooleanRecord8Array|csv:Error bm1br8 = csv:transform([bm1, bm1], {}, BooleanRecord8Array); test:assertTrue(bm1br8 is csv:Error); test:assertEquals((bm1br8).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord8Array|csv:Error bm2br8 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord8Array); + BooleanRecord8Array|csv:Error bm2br8 = csv:transform([bm2, bm2], {}, BooleanRecord8Array); test:assertTrue(bm2br8 is csv:Error); test:assertEquals((bm2br8).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord8Array|csv:Error bm3br8 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord8Array); + BooleanRecord8Array|csv:Error bm3br8 = csv:transform([bm3, bm3], {}, BooleanRecord8Array); test:assertTrue(bm3br8 is csv:Error); test:assertEquals((bm3br8).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord8Array|csv:Error bm4br8 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord8Array); + BooleanRecord8Array|csv:Error bm4br8 = csv:transform([bm4, bm4], {}, BooleanRecord8Array); test:assertTrue(bm4br8 is csv:Error); test:assertEquals((bm4br8).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord8Array|csv:Error bm5br8 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord8Array); + BooleanRecord8Array|csv:Error bm5br8 = csv:transform([bm5, bm5], {}, BooleanRecord8Array); test:assertTrue(bm5br8 is csv:Error); test:assertEquals((bm5br8).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); } @test:Config function testFromCsvWithTypeForMapAndRecordAsExpectedType3() { - BooleanRecord9Array|csv:Error bm1br9 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord9Array); + BooleanRecord9Array|csv:Error bm1br9 = csv:transform([bm1, bm1], {}, BooleanRecord9Array); test:assertTrue(bm1br9 is csv:Error); test:assertEquals((bm1br9).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord9Array|csv:Error bm2br9 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord9Array); + BooleanRecord9Array|csv:Error bm2br9 = csv:transform([bm2, bm2], {}, BooleanRecord9Array); test:assertEquals(bm2br9, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} ]); - BooleanRecord9Array|csv:Error bm3br9 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord9Array); + BooleanRecord9Array|csv:Error bm3br9 = csv:transform([bm3, bm3], {}, BooleanRecord9Array); test:assertEquals(bm3br9, [ {b1: true, b2: false, b3: (), b4: false}, {b1: true, b2: false, b3: (), b4: false} ]); - BooleanRecord9Array|csv:Error bm4br9 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord9Array); + BooleanRecord9Array|csv:Error bm4br9 = csv:transform([bm4, bm4], {}, BooleanRecord9Array); test:assertTrue(bm4br9 is csv:Error); test:assertEquals((bm4br9).message(), common:generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord9Array|csv:Error bm5br9 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord9Array); + BooleanRecord9Array|csv:Error bm5br9 = csv:transform([bm5, bm5], {}, BooleanRecord9Array); test:assertEquals(bm5br9, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - BooleanRecord10Array|csv:Error bm1br10 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord10Array); + BooleanRecord10Array|csv:Error bm1br10 = csv:transform([bm1, bm1], {}, BooleanRecord10Array); test:assertEquals(bm1br10, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanRecord10Array|csv:Error bm2br10 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord10Array); + BooleanRecord10Array|csv:Error bm2br10 = csv:transform([bm2, bm2], {outputWithHeaders: false}, BooleanRecord10Array); test:assertEquals(bm2br10, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanRecord10Array|csv:Error bm3br10 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord10Array); + BooleanRecord10Array|csv:Error bm3br10 = csv:transform([bm3, bm3], {}, BooleanRecord10Array); test:assertEquals(bm3br10, [ {b1: true, b2: false, b4: false}, {b1: true, b2: false, b4: false} ]); - BooleanRecord10Array|csv:Error bm4br10 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord10Array); + BooleanRecord10Array|csv:Error bm4br10 = csv:transform([bm4, bm4], {}, BooleanRecord10Array); test:assertEquals(bm4br10, [ {}, {} ]); - BooleanRecord10Array|csv:Error bm5br10 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord10Array); + BooleanRecord10Array|csv:Error bm5br10 = csv:transform([bm5, bm5], {}, BooleanRecord10Array); test:assertEquals(bm5br10, [ {b1: true, b2: false, b4: true}, {b1: true, b2: false, b4: true} ]); - BooleanRecord11Array|csv:Error bm1br11 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord11Array); + BooleanRecord11Array|csv:Error bm1br11 = csv:transform([bm1, bm1], {}, BooleanRecord11Array); test:assertEquals(bm1br11, [ {b1: true, b2: false, defaultableField: "", nillableField :null}, {b1: true, b2: false, defaultableField: "", nillableField :null} ]); - BooleanRecord11Array|csv:Error bm2br11 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord11Array); + BooleanRecord11Array|csv:Error bm2br11 = csv:transform([bm2, bm2], {}, BooleanRecord11Array); test:assertEquals(bm2br11, [ {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} ]); - BooleanRecord11Array|csv:Error bm3br11 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord11Array); + BooleanRecord11Array|csv:Error bm3br11 = csv:transform([bm3, bm3], {}, BooleanRecord11Array); test:assertEquals(bm3br11, [ {b1: true, b2: false, b3: (), b4: false, defaultableField: "", nillableField :null}, {b1: true, b2: false, b3: (), b4: false, defaultableField: "", nillableField :null} ]); - BooleanRecord11Array|csv:Error bm4br11 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord11Array); + BooleanRecord11Array|csv:Error bm4br11 = csv:transform([bm4, bm4], {}, BooleanRecord11Array); test:assertTrue(bm4br11 is csv:Error); test:assertEquals((bm4br11).message(), common:generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord11Array|csv:Error bm5br11 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord11Array); + BooleanRecord11Array|csv:Error bm5br11 = csv:transform([bm5, bm5], {}, BooleanRecord11Array); test:assertEquals(bm5br11, [ {b1: true, b2: false, b3: (), b4: true, defaultableField: "", nillableField :null}, {b1: true, b2: false, b3: (), b4: true, defaultableField: "", nillableField :null} ]); - BooleanRecord12Array|csv:Error bm1br12 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord12Array); + BooleanRecord12Array|csv:Error bm1br12 = csv:transform([bm1, bm1], {}, BooleanRecord12Array); test:assertTrue(bm1br12 is csv:Error); test:assertEquals((bm1br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord12Array|csv:Error bm2br12 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord12Array); + BooleanRecord12Array|csv:Error bm2br12 = csv:transform([bm2, bm2], {}, BooleanRecord12Array); test:assertTrue(bm2br12 is csv:Error); test:assertEquals((bm2br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord12Array|csv:Error bm3br12 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord12Array); + BooleanRecord12Array|csv:Error bm3br12 = csv:transform([bm3, bm3], {}, BooleanRecord12Array); test:assertTrue(bm3br12 is csv:Error); test:assertEquals((bm3br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord12Array|csv:Error bm4br12 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord12Array); + BooleanRecord12Array|csv:Error bm4br12 = csv:transform([bm4, bm4], {}, BooleanRecord12Array); test:assertTrue(bm4br12 is csv:Error); test:assertEquals((bm4br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord12Array|csv:Error bm5br12 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord12Array); + BooleanRecord12Array|csv:Error bm5br12 = csv:transform([bm5, bm5], {}, BooleanRecord12Array); test:assertTrue(bm5br12 is csv:Error); test:assertEquals((bm5br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord13Array|csv:Error bm1br13 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord13Array); + BooleanRecord13Array|csv:Error bm1br13 = csv:transform([bm1, bm1], {}, BooleanRecord13Array); test:assertEquals(bm1br13, [ {b1: true, b2: false, defaultableField: "", nillableField :null}, {b1: true, b2: false, defaultableField: "", nillableField :null} ]); - BooleanRecord13Array|csv:Error bm2br13 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord13Array); + BooleanRecord13Array|csv:Error bm2br13 = csv:transform([bm2, bm2], {outputWithHeaders: false}, BooleanRecord13Array); test:assertEquals(bm2br13, [ {b1: true, b2: false, defaultableField: "", nillableField :null}, {b1: true, b2: false, defaultableField: "", nillableField :null} ]); - BooleanRecord13Array|csv:Error bm3br13 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord13Array); + BooleanRecord13Array|csv:Error bm3br13 = csv:transform([bm3, bm3], {}, BooleanRecord13Array); test:assertEquals(bm3br13, [ {b1: true, b2: false, b4: false, defaultableField: "", nillableField :null}, {b1: true, b2: false, b4: false, defaultableField: "", nillableField :null} ]); - BooleanRecord13Array|csv:Error bm4br13 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord13Array); + BooleanRecord13Array|csv:Error bm4br13 = csv:transform([bm4, bm4], {}, BooleanRecord13Array); test:assertEquals(bm4br13, [ {defaultableField: "", nillableField :null}, {defaultableField: "", nillableField :null} @@ -346,127 +346,127 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType3() { @test:Config function testFromCsvWithTypeForMapAndRecordAsExpectedType4() { - BooleanRecord13Array|csv:Error bm5br13 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord13Array); + BooleanRecord13Array|csv:Error bm5br13 = csv:transform([bm5, bm5], {}, BooleanRecord13Array); test:assertEquals(bm5br13, [ {b1: true, b2: false, b4: true, defaultableField: "", nillableField :null}, {b1: true, b2: false, b4: true, defaultableField: "", nillableField :null} ]); - BooleanRecord14Array|csv:Error bm1br14 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord14Array); + BooleanRecord14Array|csv:Error bm1br14 = csv:transform([bm1, bm1], {}, BooleanRecord14Array); test:assertTrue(bm1br14 is csv:Error); test:assertEquals((bm1br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord14Array|csv:Error bm2br14 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord14Array); + BooleanRecord14Array|csv:Error bm2br14 = csv:transform([bm2, bm2], {}, BooleanRecord14Array); test:assertTrue(bm2br14 is csv:Error); test:assertEquals((bm2br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord14Array|csv:Error bm3br14 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord14Array); + BooleanRecord14Array|csv:Error bm3br14 = csv:transform([bm3, bm3], {}, BooleanRecord14Array); test:assertTrue(bm3br14 is csv:Error); test:assertEquals((bm3br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord14Array|csv:Error bm4br14 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord14Array); + BooleanRecord14Array|csv:Error bm4br14 = csv:transform([bm4, bm4], {}, BooleanRecord14Array); test:assertTrue(bm4br14 is csv:Error); test:assertEquals((bm4br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord14Array|csv:Error bm5br14 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord14Array); + BooleanRecord14Array|csv:Error bm5br14 = csv:transform([bm5, bm5], {outputWithHeaders: false}, BooleanRecord14Array); test:assertTrue(bm5br14 is csv:Error); test:assertEquals((bm5br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord15Array|csv:Error bm1br15 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord15Array); + BooleanRecord15Array|csv:Error bm1br15 = csv:transform([bm1, bm1], {}, BooleanRecord15Array); test:assertTrue(bm1br15 is csv:Error); test:assertEquals((bm1br15).message(), common:generateErrorMessageForInvalidFieldType("true", "b1")); - BooleanRecord15Array|csv:Error bm3br15 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord15Array); + BooleanRecord15Array|csv:Error bm3br15 = csv:transform([bm3, bm3], {}, BooleanRecord15Array); test:assertTrue(bm3br15 is csv:Error); test:assertEquals((bm3br15).message(), common:generateErrorMessageForInvalidFieldType("true", "b1")); - BooleanRecord15Array|csv:Error bm4br15 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord15Array); + BooleanRecord15Array|csv:Error bm4br15 = csv:transform([bm4, bm4], {}, BooleanRecord15Array); test:assertTrue(bm4br15 is csv:Error); test:assertEquals((bm4br15).message(), common:generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord16Array|csv:Error bm1br16 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord16Array); + BooleanRecord16Array|csv:Error bm1br16 = csv:transform([bm1, bm1], {headersOrder: ["b2", "b1"]}, BooleanRecord16Array); test:assertEquals(bm1br16, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanRecord16Array|csv:Error bm2br16 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord16Array); + BooleanRecord16Array|csv:Error bm2br16 = csv:transform([bm2, bm2], {outputWithHeaders: false}, BooleanRecord16Array); test:assertEquals(bm2br16, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} ]); - BooleanRecord16Array|csv:Error bm3br16 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord16Array); + BooleanRecord16Array|csv:Error bm3br16 = csv:transform([bm3, bm3], {}, BooleanRecord16Array); test:assertEquals(bm3br16, [ {b1: true, b2: false, b4: false, b3: ()}, {b1: true, b2: false, b4: false, b3: ()} ]); - BooleanRecord16Array|csv:Error bm4br16 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord16Array); + BooleanRecord16Array|csv:Error bm4br16 = csv:transform([bm4, bm4], {}, BooleanRecord16Array); test:assertEquals(bm4br16, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - BooleanRecord16Array|csv:Error bm5br16 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord16Array); + BooleanRecord16Array|csv:Error bm5br16 = csv:transform([bm5, bm5], {}, BooleanRecord16Array); test:assertEquals(bm5br16, [ {b1: true, b2: false, b4: true, b3: ()}, {b1: true, b2: false, b4: true, b3: ()} ]); - BooleanRecord17Array|csv:Error bm1br17 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord17Array); + BooleanRecord17Array|csv:Error bm1br17 = csv:transform([bm1, bm1], {}, BooleanRecord17Array); test:assertEquals(bm1br17, [ {}, {} ]); - BooleanRecord17Array|csv:Error bm2br17 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord17Array); + BooleanRecord17Array|csv:Error bm2br17 = csv:transform([bm2, bm2], {}, BooleanRecord17Array); test:assertEquals(bm2br17, [ {}, {} ]); - BooleanRecord17Array|csv:Error bm3br17 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord17Array); + BooleanRecord17Array|csv:Error bm3br17 = csv:transform([bm3, bm3], {}, BooleanRecord17Array); test:assertEquals(bm3br17, [ {i1: 1}, {i1: 1} ]); - BooleanRecord17Array|csv:Error bm4br17 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord17Array); + BooleanRecord17Array|csv:Error bm4br17 = csv:transform([bm4, bm4], {}, BooleanRecord17Array); test:assertEquals(bm4br17, [ {}, {} ]); - BooleanRecord17Array|csv:Error bm5br17 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord17Array); + BooleanRecord17Array|csv:Error bm5br17 = csv:transform([bm5, bm5], {}, BooleanRecord17Array); test:assertEquals(bm5br17, [ {}, {} ]); - BooleanRecord18Array|csv:Error bm1br18 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord18Array); + BooleanRecord18Array|csv:Error bm1br18 = csv:transform([bm1, bm1], {}, BooleanRecord18Array); test:assertEquals(bm1br18, [ {b2: false}, {b2: false} ]); - BooleanRecord18Array|csv:Error bm2br18 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord18Array); + BooleanRecord18Array|csv:Error bm2br18 = csv:transform([bm2, bm2], {}, BooleanRecord18Array); test:assertEquals(bm2br18, [ {b2: false, b3: (), n1: (), n3: ()}, {b2: false, b3: (), n1: (), n3: ()} ]); - BooleanRecord18Array|csv:Error bm3br18 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord18Array); + BooleanRecord18Array|csv:Error bm3br18 = csv:transform([bm3, bm3], {}, BooleanRecord18Array); test:assertEquals(bm3br18, [ {b2: false, b3: (), i1: 1}, {b2: false, b3: (), i1: 1} ]); - BooleanRecord18Array|csv:Error bm4br18 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord18Array); + BooleanRecord18Array|csv:Error bm4br18 = csv:transform([bm4, bm4], {outputWithHeaders: false}, BooleanRecord18Array); test:assertTrue(bm4br18 is csv:Error); test:assertEquals((bm4br18).message(), common:generateErrorMessageForMissingRequiredField("b2")); - BooleanRecord18Array|csv:Error bm5br18 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord18Array); + BooleanRecord18Array|csv:Error bm5br18 = csv:transform([bm5, bm5], {}, BooleanRecord18Array); test:assertEquals(bm5br18, [ {b2: false, b3: ()}, {b2: false, b3: ()} @@ -475,133 +475,133 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType4() { @test:Config function testFromCsvWithTypeForMapAndMapAsExpectedType() { - BooleanMapArray|csv:Error bm1bma = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanMapArray); + BooleanMapArray|csv:Error bm1bma = csv:transform([bm1, bm1], {}, BooleanMapArray); test:assertEquals(bm1bma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanMapArray|csv:Error bm2bma = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanMapArray); + BooleanMapArray|csv:Error bm2bma = csv:transform([bm2, bm2], {}, BooleanMapArray); test:assertEquals(bm2bma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanMapArray|csv:Error bm3bma = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanMapArray); + BooleanMapArray|csv:Error bm3bma = csv:transform([bm3, bm3], {}, BooleanMapArray); test:assertEquals(bm3bma, [ {b1: true, b2: false, b4: false}, {b1: true, b2: false, b4: false} ]); - BooleanMapArray|csv:Error bm4bma = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanMapArray); + BooleanMapArray|csv:Error bm4bma = csv:transform([bm4, bm4], {}, BooleanMapArray); test:assertEquals(bm4bma, [ {}, {} ]); - BooleanMapArray|csv:Error bm5bma = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanMapArray); + BooleanMapArray|csv:Error bm5bma = csv:transform([bm5, bm5], {}, BooleanMapArray); test:assertEquals(bm5bma, [ {b1: true, b2: false, b4: true}, {b1: true, b2: false, b4: true} ]); - NillableBooleanMapArray|csv:Error bm1nbma = csv:parseRecordAsRecordType([bm1, bm1], {}, NillableBooleanMapArray); + NillableBooleanMapArray|csv:Error bm1nbma = csv:transform([bm1, bm1], {}, NillableBooleanMapArray); test:assertEquals(bm1nbma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - NillableBooleanMapArray|csv:Error bm2nbma = csv:parseRecordAsRecordType([bm2, bm2], {}, NillableBooleanMapArray); + NillableBooleanMapArray|csv:Error bm2nbma = csv:transform([bm2, bm2], {outputWithHeaders: false}, NillableBooleanMapArray); test:assertEquals(bm2nbma, [ {b1: true, b2: false, b3:(), n1: (), n3: ()}, {b1: true, b2: false, b3:(), n1: (), n3: ()} ]); - NillableBooleanMapArray|csv:Error bm3nbma = csv:parseRecordAsRecordType([bm3, bm3], {}, NillableBooleanMapArray); + NillableBooleanMapArray|csv:Error bm3nbma = csv:transform([bm3, bm3], {}, NillableBooleanMapArray); test:assertEquals(bm3nbma, [ {b1: true, b2: false, b3:(), b4: false}, {b1: true, b2: false, b3:(), b4: false} ]); - NillableBooleanMapArray|csv:Error bm4nbma = csv:parseRecordAsRecordType([bm4, bm4], {}, NillableBooleanMapArray); + NillableBooleanMapArray|csv:Error bm4nbma = csv:transform([bm4, bm4], {}, NillableBooleanMapArray); test:assertEquals(bm4nbma, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - NillableBooleanMapArray|csv:Error bm5nbma = csv:parseRecordAsRecordType([bm5, bm5], {}, NillableBooleanMapArray); + NillableBooleanMapArray|csv:Error bm5nbma = csv:transform([bm5, bm5], {}, NillableBooleanMapArray); test:assertEquals(bm5nbma, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - NillableIntUnionBooleanMapArray|csv:Error bm1niubma = csv:parseRecordAsRecordType([bm1, bm1], {}, NillableIntUnionBooleanMapArray); + NillableIntUnionBooleanMapArray|csv:Error bm1niubma = csv:transform([bm1, bm1], {}, NillableIntUnionBooleanMapArray); test:assertEquals(bm1niubma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - NillableIntUnionBooleanMapArray|csv:Error bm2niubma = csv:parseRecordAsRecordType([bm2, bm2], {}, NillableIntUnionBooleanMapArray); + NillableIntUnionBooleanMapArray|csv:Error bm2niubma = csv:transform([bm2, bm2], {}, NillableIntUnionBooleanMapArray); test:assertEquals(bm2niubma, [ {b1: true, b2: false, b3:(), n1: (), n3: ()}, {b1: true, b2: false, b3:(), n1: (), n3: ()} ]); - NillableIntUnionBooleanMapArray|csv:Error bm3niubma = csv:parseRecordAsRecordType([bm3, bm3], {}, NillableIntUnionBooleanMapArray); + NillableIntUnionBooleanMapArray|csv:Error bm3niubma = csv:transform([bm3, bm3], {}, NillableIntUnionBooleanMapArray); test:assertEquals(bm3niubma, [ {b1: true, b2: false, b3:(), b4: false, i1: 1}, {b1: true, b2: false, b3:(), b4: false, i1: 1} ]); - NillableIntUnionBooleanMapArray|csv:Error bm4niubma = csv:parseRecordAsRecordType([bm4, bm4], {}, NillableIntUnionBooleanMapArray); + NillableIntUnionBooleanMapArray|csv:Error bm4niubma = csv:transform([bm4, bm4], {}, NillableIntUnionBooleanMapArray); test:assertEquals(bm4niubma, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - NillableIntUnionBooleanMapArray|csv:Error bm5niubma = csv:parseRecordAsRecordType([bm5, bm5], {}, NillableIntUnionBooleanMapArray); + NillableIntUnionBooleanMapArray|csv:Error bm5niubma = csv:transform([bm5, bm5], {}, NillableIntUnionBooleanMapArray); test:assertEquals(bm5niubma, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - IntUnionBooleanMapArray|csv:Error bm1iubma = csv:parseRecordAsRecordType([bm1, bm1], {}, IntUnionBooleanMapArray); + IntUnionBooleanMapArray|csv:Error bm1iubma = csv:transform([bm1, bm1], {}, IntUnionBooleanMapArray); test:assertEquals(bm1iubma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - IntUnionBooleanMapArray|csv:Error bm2iubma = csv:parseRecordAsRecordType([bm2, bm2], {}, IntUnionBooleanMapArray); + IntUnionBooleanMapArray|csv:Error bm2iubma = csv:transform([bm2, bm2], {}, IntUnionBooleanMapArray); test:assertEquals(bm2iubma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - IntUnionBooleanMapArray|csv:Error bm3iubma = csv:parseRecordAsRecordType([bm3, bm3], {}, IntUnionBooleanMapArray); + IntUnionBooleanMapArray|csv:Error bm3iubma = csv:transform([bm3, bm3], {}, IntUnionBooleanMapArray); test:assertEquals(bm3iubma, [ {b1: true, b2: false, b4: false, i1: 1}, {b1: true, b2: false, b4: false, i1: 1} ]); - IntUnionBooleanMapArray|csv:Error bm4iubma = csv:parseRecordAsRecordType([bm4, bm4], {}, IntUnionBooleanMapArray); + IntUnionBooleanMapArray|csv:Error bm4iubma = csv:transform([bm4, bm4], {}, IntUnionBooleanMapArray); test:assertEquals(bm4iubma, [ {}, {} ]); - IntUnionBooleanMapArray|csv:Error bm5iubma = csv:parseRecordAsRecordType([bm5, bm5], {}, IntUnionBooleanMapArray); + IntUnionBooleanMapArray|csv:Error bm5iubma = csv:transform([bm5, bm5], {}, IntUnionBooleanMapArray); test:assertEquals(bm5iubma, [ {b1: true, b2: false, b4: true}, {b1: true, b2: false, b4: true} ]); - NilMapArray|csv:Error bm1nma = csv:parseRecordAsRecordType([bm1, bm1], {}, NilMapArray); + NilMapArray|csv:Error bm1nma = csv:transform([bm1, bm1], {}, NilMapArray); test:assertEquals(bm1nma, [ {}, {} ]); - NilMapArray|csv:Error bm2nma = csv:parseRecordAsRecordType([bm2, bm2], {}, NilMapArray); + NilMapArray|csv:Error bm2nma = csv:transform([bm2, bm2], {}, NilMapArray); test:assertEquals(bm2nma, [ {n1: (), n3: (), b3: ()}, {n1: (), n3: (), b3: ()} @@ -610,140 +610,160 @@ function testFromCsvWithTypeForMapAndMapAsExpectedType() { @test:Config function testFromCsvWithTypeForMapAndMapAsExpectedType2() { - NilMapArray|csv:Error bm3nma = csv:parseRecordAsRecordType([bm3, bm3], {}, NilMapArray); + NilMapArray|csv:Error bm3nma = csv:transform([bm3, bm3], {}, NilMapArray); test:assertEquals(bm3nma, [ {b3: ()}, {b3: ()} ]); - NilMapArray|csv:Error bm4nma = csv:parseRecordAsRecordType([bm4, bm4], {}, NilMapArray); + NilMapArray|csv:Error bm4nma = csv:transform([bm4, bm4], {}, NilMapArray); test:assertEquals(bm4nma, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - NilMapArray|csv:Error bm5nma = csv:parseRecordAsRecordType([bm5, bm5], {}, NilMapArray); + NilMapArray|csv:Error bm5nma = csv:transform([bm5, bm5], {}, NilMapArray); test:assertEquals(bm5nma, [ {b3: ()}, {b3: ()} ]); - JsonMapArray|csv:Error bm1jma = csv:parseRecordAsRecordType([bm1, bm1], {}, JsonMapArray); + JsonMapArray|csv:Error bm1jma = csv:transform([bm1, bm1], {}, JsonMapArray); test:assertEquals(bm1jma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - JsonMapArray|csv:Error bm2jma = csv:parseRecordAsRecordType([bm2, bm2], {}, JsonMapArray); + JsonMapArray|csv:Error bm2jma = csv:transform([bm2, bm2], {outputWithHeaders: false, headersOrder: []}, JsonMapArray); test:assertEquals(bm2jma, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} ]); - JsonMapArray|csv:Error bm3jma = csv:parseRecordAsRecordType([bm3, bm3], {}, JsonMapArray); + JsonMapArray|csv:Error bm3jma = csv:transform([bm3, bm3], {}, JsonMapArray); test:assertEquals(bm3jma, [ {b1: true, b2: false, b4: false, b3: (), i1: 1}, {b1: true, b2: false, b4: false, b3: (), i1: 1} ]); - JsonMapArray|csv:Error bm4jma = csv:parseRecordAsRecordType([bm4, bm4], {}, JsonMapArray); + JsonMapArray|csv:Error bm4jma = csv:transform([bm4, bm4], {}, JsonMapArray); test:assertEquals(bm4jma, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - JsonMapArray|csv:Error bm5jma = csv:parseRecordAsRecordType([bm5, bm5], {}, JsonMapArray); + JsonMapArray|csv:Error bm5jma = csv:transform([bm5, bm5], {}, JsonMapArray); test:assertEquals(bm5jma, [ {b1: true, b2: false, b4: true, b3: ()}, {b1: true, b2: false, b4: true, b3: ()} ]); - AnydataMapArray|csv:Error bm1anydma = csv:parseRecordAsRecordType([bm1, bm1], {}, AnydataMapArray); + AnydataMapArray|csv:Error bm1anydma = csv:transform([bm1, bm1], {}, AnydataMapArray); test:assertEquals(bm1anydma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - AnydataMapArray|csv:Error bm2anydma = csv:parseRecordAsRecordType([bm2, bm2], {}, AnydataMapArray); + AnydataMapArray|csv:Error bm2anydma = csv:transform([bm2, bm2], {}, AnydataMapArray); test:assertEquals(bm2anydma, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} ]); - AnydataMapArray|csv:Error bm3anydma = csv:parseRecordAsRecordType([bm3, bm3], {}, AnydataMapArray); + AnydataMapArray|csv:Error bm3anydma = csv:transform([bm3, bm3], {}, AnydataMapArray); test:assertEquals(bm3anydma, [ {b1: true, b2: false, b4: false, b3: (), i1: 1}, {b1: true, b2: false, b4: false, b3: (), i1: 1} ]); - AnydataMapArray|csv:Error bm4anydma = csv:parseRecordAsRecordType([bm4, bm4], {}, AnydataMapArray); + AnydataMapArray|csv:Error bm4anydma = csv:transform([bm4, bm4], {}, AnydataMapArray); test:assertEquals(bm4anydma, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - AnydataMapArray|csv:Error bm5anydma = csv:parseRecordAsRecordType([bm5, bm5], {}, AnydataMapArray); + AnydataMapArray|csv:Error bm5anydma = csv:transform([bm5, bm5], {}, AnydataMapArray); test:assertEquals(bm5anydma, [ {b1: true, b2: false, b4: true, b3: ()}, {b1: true, b2: false, b4: true, b3: ()} ]); - CustomMapArray|csv:Error bm1cma = csv:parseRecordAsRecordType([bm1, bm1], {}, CustomMapArray); + CustomMapArray|csv:Error bm1cma = csv:transform([bm1, bm1], {}, CustomMapArray); test:assertEquals(bm1cma, [ {}, {} ]); - CustomMapArray|csv:Error bm2cma = csv:parseRecordAsRecordType([bm2, bm2], {}, CustomMapArray); + CustomMapArray|csv:Error bm2cma = csv:transform([bm2, bm2], {}, CustomMapArray); test:assertEquals(bm2cma, [ {}, {} ]); - CustomMapArray|csv:Error bm3cma = csv:parseRecordAsRecordType([bm3, bm3], {}, CustomMapArray); + CustomMapArray|csv:Error bm3cma = csv:transform([bm3, bm3], {}, CustomMapArray); test:assertEquals(bm3cma, [ {i1: 1}, {i1: 1} ]); - CustomMapArray|csv:Error bm4cma = csv:parseRecordAsRecordType([bm4, bm4], {}, CustomMapArray); + CustomMapArray|csv:Error bm4cma = csv:transform([bm4, bm4], {}, CustomMapArray); test:assertEquals(bm4cma, [ {}, {} ]); - CustomMapArray|csv:Error bm5cma = csv:parseRecordAsRecordType([bm5, bm5], {}, CustomMapArray); + CustomMapArray|csv:Error bm5cma = csv:transform([bm5, bm5], {}, CustomMapArray); test:assertEquals(bm5cma, [ {}, {} ]); - StringMapArray|csv:Error bm1sma = csv:parseRecordAsRecordType([bm1, bm1], {}, StringMapArray); + StringMapArray|csv:Error bm1sma = csv:transform([bm1, bm1], {outputWithHeaders: false}, StringMapArray); test:assertEquals(bm1sma, [ {}, {} ]); - StringMapArray|csv:Error bm2sma = csv:parseRecordAsRecordType([bm2, bm2], {}, StringMapArray); + StringMapArray|csv:Error bm2sma = csv:transform([bm2, bm2], {}, StringMapArray); test:assertEquals(bm2sma, [ {}, {} ]); - StringMapArray|csv:Error bm3sma = csv:parseRecordAsRecordType([bm3, bm3], {}, StringMapArray); + StringMapArray|csv:Error bm3sma = csv:transform([bm3, bm3], {}, StringMapArray); test:assertEquals(bm3sma, [ {}, {} ]); - StringMapArray|csv:Error bm4sma = csv:parseRecordAsRecordType([bm4, bm4], {}, StringMapArray); + StringMapArray|csv:Error bm4sma = csv:transform([bm4, bm4], {}, StringMapArray); test:assertEquals(bm4sma, [ {}, {} ]); - StringMapArray|csv:Error bm5sma = csv:parseRecordAsRecordType([bm5, bm5], {}, StringMapArray); + StringMapArray|csv:Error bm5sma = csv:transform([bm5, bm5], {}, StringMapArray); test:assertEquals(bm5sma, [ {}, {} ]); } + +@test:Config +function testArrayIndexesInRecords() { + map[] csv = [{a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}, {a: 7, b: 8}]; + + record {}[2]|csv:Error rec = csv:transform(csv); + test:assertEquals(rec, [ + {a: 1, b: 2}, + {a: 3, b: 4} + ]); + + record {|int a;|}[2]|csv:Error rec2 = csv:transform(csv, {skipLines: [2]}); + test:assertEquals(rec2, [ + {a: 1}, + {a: 5} + ]); + + record {|int a;|}[5]|csv:Error rec2_2 = csv:transform(csv, {skipLines: [2], outputWithHeaders: false, headersOrder: ["a", "b"]}); + test:assertTrue(rec2_2 is csv:Error); +} \ No newline at end of file diff --git a/ballerina-tests/parse-string-array-types-tests/Ballerina.toml b/ballerina-tests/parse-string-array-types-tests/Ballerina.toml index bfffdb6..d1d42fe 100644 --- a/ballerina-tests/parse-string-array-types-tests/Ballerina.toml +++ b/ballerina-tests/parse-string-array-types-tests/Ballerina.toml @@ -13,4 +13,4 @@ version = "0.1.0" graalvmCompatible = true [build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" +graalvmBuildOptions = "-H:+IncludeAllLocales" diff --git a/ballerina-tests/parse-string-array-types-tests/Dependencies.toml b/ballerina-tests/parse-string-array-types-tests/Dependencies.toml index 81c0d40..e07bf86 100644 --- a/ballerina-tests/parse-string-array-types-tests/Dependencies.toml +++ b/ballerina-tests/parse-string-array-types-tests/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.0" +distribution-version = "2201.10.0-20240801-104200-87df251c" [[package]] org = "ballerina" 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 9050847..46a49c0 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 @@ -20,106 +20,106 @@ import ballerina/test; @test:Config function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { - BooleanArrayArray|csv:Error cv1baa = csv:parseStringToList(csvStringWithBooleanValues1); + BooleanArrayArray|csv:Error cv1baa = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cv1baa, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - BooleanArrayArray|csv:Error cv2baa = csv:parseStringToList(csvStringWithBooleanValues2); + BooleanArrayArray|csv:Error cv2baa = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cv2baa, [ [true, false, true, false, true], [true, false, true, false, true] ]); - BooleanArrayArray|csv:Error cv3baa = csv:parseStringToList(csvStringWithBooleanValues3); + BooleanArrayArray|csv:Error cv3baa = csv:parseString(csvStringWithBooleanValues3); test:assertTrue(cv3baa is csv:Error); test:assertEquals((cv3baa).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanArrayArray|csv:Error cv4baa = csv:parseStringToList(csvStringWithBooleanValues4); + BooleanArrayArray|csv:Error cv4baa = csv:parseString(csvStringWithBooleanValues4); test:assertTrue(cv4baa is csv:Error); test:assertEquals((cv4baa).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanArrayArray|csv:Error cv5baa = csv:parseStringToList(csvStringWithBooleanValues5); + BooleanArrayArray|csv:Error cv5baa = csv:parseString(csvStringWithBooleanValues5); test:assertTrue(cv5baa is csv:Error); test:assertEquals((cv5baa).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); - BooleanArrayArray|csv:Error cv6baa = csv:parseStringToList(csvStringWithBooleanValues6); + BooleanArrayArray|csv:Error cv6baa = csv:parseString(csvStringWithBooleanValues6); test:assertTrue(cv6baa is csv:Error); test:assertEquals((cv6baa).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanArrayArray|csv:Error cv7baa = csv:parseStringToList(csvStringWithBooleanValues7); + BooleanArrayArray|csv:Error cv7baa = csv:parseString(csvStringWithBooleanValues7); test:assertTrue(cv7baa is csv:Error); test:assertEquals((cv7baa).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - NillableBooleanArrayArray|csv:Error cv1nbaa = csv:parseStringToList(csvStringWithBooleanValues1); + NillableBooleanArrayArray|csv:Error cv1nbaa = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cv1nbaa, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - NillableBooleanArrayArray|csv:Error cv2nbaa = csv:parseStringToList(csvStringWithBooleanValues2); + NillableBooleanArrayArray|csv:Error cv2nbaa = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cv2nbaa, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableBooleanArrayArray|csv:Error cv3nbaa = csv:parseStringToList(csvStringWithBooleanValues3); + NillableBooleanArrayArray|csv:Error cv3nbaa = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cv3nbaa, [ [true, false, true], [true, false, ()], [true, true, false] ]); - NillableBooleanArrayArray|csv:Error cv4nbaa = csv:parseStringToList(csvStringWithBooleanValues4); + NillableBooleanArrayArray|csv:Error cv4nbaa = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cv4nbaa, [ [true, (), (), false], [true, (), (), false] ]); - NillableBooleanArrayArray|csv:Error cv5nbaa = csv:parseStringToList(csvStringWithBooleanValues5); + NillableBooleanArrayArray|csv:Error cv5nbaa = csv:parseString(csvStringWithBooleanValues5); test:assertTrue(cv5nbaa is csv:Error); test:assertEquals((cv5nbaa).message(), common:generateErrorMessageForInvalidCast("2", "boolean?")); - NillableBooleanArrayArray|csv:Error cv6nbaa = csv:parseStringToList(csvStringWithBooleanValues6); + NillableBooleanArrayArray|csv:Error cv6nbaa = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cv6nbaa, [ [(), ()] ]); - NillableBooleanArrayArray|csv:Error cv7nbaa = csv:parseStringToList(csvStringWithBooleanValues7); + NillableBooleanArrayArray|csv:Error cv7nbaa = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cv7nbaa, [ [b1, b2, (), b4] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error cv1niubaa = csv:parseStringToList(csvStringWithBooleanValues1); + NillableIntOrUnionBooleanArrayArray|csv:Error cv1niubaa = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cv1niubaa, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error cv2niubaa = csv:parseStringToList(csvStringWithBooleanValues2); + NillableIntOrUnionBooleanArrayArray|csv:Error cv2niubaa = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cv2niubaa, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error cv3niubaa = csv:parseStringToList(csvStringWithBooleanValues3); + NillableIntOrUnionBooleanArrayArray|csv:Error cv3niubaa = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cv3niubaa, [ [true, false, true], [true, false, ()], [true, true, false] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error cv4niubaa = csv:parseStringToList(csvStringWithBooleanValues4); + NillableIntOrUnionBooleanArrayArray|csv:Error cv4niubaa = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cv4niubaa, [ [true, (), (), false], [true, (), (), false] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error cv5niubaa = csv:parseStringToList(csvStringWithBooleanValues5); + NillableIntOrUnionBooleanArrayArray|csv:Error cv5niubaa = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(cv5niubaa, [ [true, false, true, 2], [true, false, true, 3] @@ -128,101 +128,101 @@ function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { @test:Config function testFromCsvStringWithTypeForStringAndArrayAsExpectedType2() { - NillableIntOrUnionBooleanArrayArray|csv:Error cv6niubaa = csv:parseStringToList(csvStringWithBooleanValues6); + NillableIntOrUnionBooleanArrayArray|csv:Error cv6niubaa = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cv6niubaa, [ [(), ()] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error cv7niubaa = csv:parseStringToList(csvStringWithBooleanValues7); + NillableIntOrUnionBooleanArrayArray|csv:Error cv7niubaa = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cv7niubaa, [ [b1, b2, (), b4] ]); - StringArray1Array|csv:Error cv1saa = csv:parseStringToList(csvStringWithBooleanValues1); + StringArray1Array|csv:Error cv1saa = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cv1saa, [ ["true", "false", "true", "false"], ["true", "false", "true", "false"], ["true", "false", "true", "false"] ]); - StringArray1Array|csv:Error cv2saa = csv:parseStringToList(csvStringWithBooleanValues2); + StringArray1Array|csv:Error cv2saa = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cv2saa, [ ["true", "false", "true", "false", "true"], ["true", "false", "true", "false", "true"] ]); - StringArray1Array|csv:Error cv3saa = csv:parseStringToList(csvStringWithBooleanValues3); + StringArray1Array|csv:Error cv3saa = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cv3saa, [ ["true", "false", "true"], ["TRUE", "FALSE", "()"], ["true", "true", "FALSE"] ]); - StringArray1Array|csv:Error cv4saa = csv:parseStringToList(csvStringWithBooleanValues4); + StringArray1Array|csv:Error cv4saa = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cv4saa, [ ["true", "()", "()", "false"], ["true", "()", "null", "false"] ]); - StringArray1Array|csv:Error cv5saa = csv:parseStringToList(csvStringWithBooleanValues5); + StringArray1Array|csv:Error cv5saa = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(cv5saa, [ ["true", "false", "true", "2"], ["true", "false", "true", "3"] ]); - StringArray1Array|csv:Error cv6saa = csv:parseStringToList(csvStringWithBooleanValues6); + StringArray1Array|csv:Error cv6saa = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cv6saa, [ ["()", "()"] ]); - StringArray1Array|csv:Error cv7saa = csv:parseStringToList(csvStringWithBooleanValues7); + StringArray1Array|csv:Error cv7saa = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cv7saa, [ ["true", "false", "()", "false"] ]); - StringArray2Array|csv:Error cv1s2aa = csv:parseStringToList(csvStringWithBooleanValues1); + StringArray2Array|csv:Error cv1s2aa = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cv1s2aa, [ ["true", "false"], ["true", "false"], ["true", "false"] ]); - StringArray2Array|csv:Error cv2s2aa = csv:parseStringToList(csvStringWithBooleanValues2); + StringArray2Array|csv:Error cv2s2aa = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cv2s2aa, [ ["true", "false"], ["true", "false"] ]); - StringArray2Array|csv:Error cv3s2aa = csv:parseStringToList(csvStringWithBooleanValues3); + StringArray2Array|csv:Error cv3s2aa = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cv3s2aa, [ ["true", "false"], ["TRUE", "FALSE"], ["true", "true"] ]); - StringArray2Array|csv:Error cv4s2aa = csv:parseStringToList(csvStringWithBooleanValues4); + StringArray2Array|csv:Error cv4s2aa = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cv4s2aa, [ ["true", "()"], ["true", "()"] ]); - StringArray2Array|csv:Error cv5s2aa = csv:parseStringToList(csvStringWithBooleanValues5); + StringArray2Array|csv:Error cv5s2aa = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(cv5s2aa, [ ["true", "false"], ["true", "false"] ]); - StringArray2Array|csv:Error cv6s2aa = csv:parseStringToList(csvStringWithBooleanValues6); + StringArray2Array|csv:Error cv6s2aa = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cv6s2aa, [ ["()", "()"] ]); - StringArray2Array|csv:Error cv7s2aa = csv:parseStringToList(csvStringWithBooleanValues7); + StringArray2Array|csv:Error cv7s2aa = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cv7s2aa, [ ["true", "false"] ]); - JsonArray1Array|csv:Error cv1jaa = csv:parseStringToList(csvStringWithBooleanValues1); + JsonArray1Array|csv:Error cv1jaa = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cv1jaa, [ [true, false, true, false], [true, false, true, false], @@ -232,96 +232,96 @@ function testFromCsvStringWithTypeForStringAndArrayAsExpectedType2() { @test:Config function testFromCsvStringWithTypeForStringAndArrayAsExpectedType3() { - JsonArray1Array|csv:Error cv2jaa = csv:parseStringToList(csvStringWithBooleanValues2); + JsonArray1Array|csv:Error cv2jaa = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cv2jaa, [ [true, false, true, false, true], [true, false, true, false, true] ]); - JsonArray1Array|csv:Error cv3jaa = csv:parseStringToList(csvStringWithBooleanValues3); + JsonArray1Array|csv:Error cv3jaa = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cv3jaa, [ [true, false, true], [true, false, ()], [true, true, false] ]); - JsonArray1Array|csv:Error cv4jaa = csv:parseStringToList(csvStringWithBooleanValues4); + JsonArray1Array|csv:Error cv4jaa = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cv4jaa, [ [true, (), (), false], [true, (), (), false] ]); - JsonArray1Array|csv:Error cv5jaa = csv:parseStringToList(csvStringWithBooleanValues5); + JsonArray1Array|csv:Error cv5jaa = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(cv5jaa, [ [true, false, true, 2], [true, false, true, 3] ]); - JsonArray1Array|csv:Error cv6jaa = csv:parseStringToList(csvStringWithBooleanValues6); + JsonArray1Array|csv:Error cv6jaa = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cv6jaa, [ [(), ()] ]); - JsonArray1Array|csv:Error cv7jaa = csv:parseStringToList(csvStringWithBooleanValues7); + JsonArray1Array|csv:Error cv7jaa = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cv7jaa, [ [b1, b2, (), b4] ]); - AnydataArray1Array|csv:Error cv1anydaa = csv:parseStringToList(csvStringWithBooleanValues1); + AnydataArray1Array|csv:Error cv1anydaa = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cv1anydaa, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - AnydataArray1Array|csv:Error cv2anydaa = csv:parseStringToList(csvStringWithBooleanValues2); + AnydataArray1Array|csv:Error cv2anydaa = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cv2anydaa, [ [true, false, true, false, true], [true, false, true, false, true] ]); - AnydataArray1Array|csv:Error cv3anydaa = csv:parseStringToList(csvStringWithBooleanValues3); + AnydataArray1Array|csv:Error cv3anydaa = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cv3anydaa, [ [true, false, true], [true, false, ()], [true, true, false] ]); - AnydataArray1Array|csv:Error cv4anydaa = csv:parseStringToList(csvStringWithBooleanValues4); + AnydataArray1Array|csv:Error cv4anydaa = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cv4anydaa, [ [true, (), (), false], [true, (), (), false] ]); - AnydataArray1Array|csv:Error cv5anydaa = csv:parseStringToList(csvStringWithBooleanValues5); + AnydataArray1Array|csv:Error cv5anydaa = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(cv5anydaa, [ [true, false, true, 2], [true, false, true, 3] ]); - AnydataArray1Array|csv:Error cv6anydaa = csv:parseStringToList(csvStringWithBooleanValues6); + AnydataArray1Array|csv:Error cv6anydaa = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cv6anydaa, [ [(), ()] ]); - AnydataArray1Array|csv:Error cv7anydaa = csv:parseStringToList(csvStringWithBooleanValues7); + AnydataArray1Array|csv:Error cv7anydaa = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cv7anydaa, [ [b1, b2, (), b4] ]); - DecimalArray1Array|csv:Error cv1daa = csv:parseStringToList(csvStringWithBooleanValues1); + DecimalArray1Array|csv:Error cv1daa = csv:parseString(csvStringWithBooleanValues1); test:assertTrue(cv1daa is csv:Error); test:assertEquals((cv1daa).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); - DecimalArray1Array|csv:Error cv3daa = csv:parseStringToList(csvStringWithBooleanValues3); + DecimalArray1Array|csv:Error cv3daa = csv:parseString(csvStringWithBooleanValues3); test:assertTrue(cv3daa is csv:Error); test:assertEquals((cv3daa).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); - DecimalArray1Array|csv:Error cv6daa = csv:parseStringToList(csvStringWithBooleanValues6); + DecimalArray1Array|csv:Error cv6daa = csv:parseString(csvStringWithBooleanValues6); test:assertTrue(cv6daa is csv:Error); test:assertEquals((cv6daa).message(), common:generateErrorMessageForInvalidCast("()", "decimal")); - DecimalArray1Array|csv:Error cv7daa = csv:parseStringToList(csvStringWithBooleanValues7); + DecimalArray1Array|csv:Error cv7daa = csv:parseString(csvStringWithBooleanValues7); test:assertTrue(cv7daa is csv:Error); test:assertEquals((cv7daa).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); } @@ -340,28 +340,28 @@ function testArrayIndexes() { 5, 6, 7 7, 8, 9`; - record {}[2]|csv:Error rec = csv:parseStringToRecord(csv); + record {}[2]|csv:Error rec = csv:parseString(csv); test:assertEquals(rec, [ {a: 1, b: 2}, {a: 3, b: 4} ]); - map[2]|csv:Error rec_2 = csv:parseStringToRecord(csv); + map[2]|csv:Error rec_2 = csv:parseString(csv); test:assertEquals(rec_2, [ {a: 1, b: 2}, {a: 3, b: 4} ]); - record {|int a;|}[2]|csv:Error rec2 = csv:parseStringToRecord(csv, {skipLines: [2]}); + record {|int a;|}[2]|csv:Error rec2 = csv:parseString(csv, {skipLines: [2]}); test:assertEquals(rec2, [ {a: 1}, {a: 5} ]); - record {|int a;|}[5]|csv:Error rec2_2 = csv:parseStringToRecord(csv, {skipLines: [2]}); + record {|int a;|}[5]|csv:Error rec2_2 = csv:parseString(csv, {skipLines: [2]}); test:assertTrue(rec2_2 is csv:Error); - int[][2]|csv:Error rec3 = csv:parseStringToList(csv2); + int[][2]|csv:Error rec3 = csv:parseString(csv2); test:assertEquals(rec3, [ [1, 2], [3, 4], @@ -369,24 +369,24 @@ function testArrayIndexes() { [7, 8] ]); - [int, int][2]|csv:Error rec3_2 = csv:parseStringToList(csv2); + [int, int][2]|csv:Error rec3_2 = csv:parseString(csv2); test:assertEquals(rec3_2, [ [1, 2], [3, 4] ]); - [int...][2]|csv:Error rec3_3 = csv:parseStringToList(csv2); + [int...][2]|csv:Error rec3_3 = csv:parseString(csv2); test:assertEquals(rec3_3, [ [1, 2, 3], [3, 4, 5] ]); - int[1][2]|csv:Error rec4 = csv:parseStringToList(csv2, {skipLines: [2]}); + int[1][2]|csv:Error rec4 = csv:parseString(csv2, {skipLines: [2]}); test:assertEquals(rec4, [ [1, 2] ]); - int[2][]|csv:Error rec5 = csv:parseStringToList(csv2); + int[2][]|csv:Error rec5 = csv:parseString(csv2); test:assertEquals(rec5, [ [1, 2, 3], [3, 4, 5] @@ -394,59 +394,76 @@ function testArrayIndexes() { } @test:Config -function testArrayIndexes2() { - map[] csv = [{a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}, {a: 7, b: 8}]; - string[][] csv2 = [["1", "2", "3"], ["3", "4", "5"], ["5", "6", "7"], ["7", "8", "9"]]; - - record {}[2]|csv:Error rec = csv:parseRecordAsRecordType(csv); - test:assertEquals(rec, [ - {a: 1, b: 2}, - {a: 3, b: 4} - ]); +function testParseStringArrayAsExpectedTypeWithOutputHeaders() { + BooleanArrayArray|csv:Error cv1baa = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true}); + test:assertTrue(cv1baa is csv:Error); + test:assertEquals((cv1baa).message(), common:generateErrorMessageForInvalidCast("b1", "boolean")); + + string[][]|csv:Error cv1baa_2 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true}); + test:assertEquals(cv1baa_2, [ + ["b1", "b2", "b3", "b4"], + ["true", "false", "true", "false"], + ["true", "false", "true", "false"], + ["true", "false", "true", "false"] + ]); - map[2]|csv:Error rec_2 = csv:parseListAsRecordType(csv2, ["a", "b", "c"]); - test:assertEquals(rec_2, [ - {a: 1, b: 2, c: 3}, - {a: 3, b: 4, c: 5} - ]); + (string|boolean)[][]|csv:Error cv2baa = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); + test:assertEquals(cv2baa, [ + ["b1", "b2", "b3", "b4", "b5"], + [true, false, true, false, true], + [true, false, true, false, true] + ]); - record {|int a;|}[2]|csv:Error rec2 = csv:parseRecordAsRecordType(csv, {skipLines: [2]}); - test:assertEquals(rec2, [ - {a: 1}, - {a: 5} - ]); + [string...][]|csv:Error cv2baa_2 = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); + test:assertEquals(cv2baa_2, [ + ["b1", "b2", "b3", "b4", "b5"], + ["true", "false", "true", "false", "true"], + ["true", "false", "true", "false", "true"] + ]); - record {|int a;|}[5]|csv:Error rec2_2 = csv:parseRecordAsRecordType(csv, {skipLines: [2]}); - test:assertTrue(rec2_2 is csv:Error); + [boolean|string...][]|csv:Error cv2baa_3 = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); + test:assertEquals(cv2baa_3, [ + ["b1", "b2", "b3", "b4", "b5"], + [true, false, true, false, true], + [true, false, true, false, true] + ]); - int[][2]|csv:Error rec3 = csv:parseRecordAsListType(csv, ["a", "b"]); - test:assertEquals(rec3, [ - [1, 2], - [3, 4], - [5, 6], - [7, 8] - ]); + string[][]|csv:Error cv1baa_4 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true, header: false}); + test:assertEquals(cv1baa_4, [ + ["b1", "b2", "b3", "b4"], + ["true", "false", "true", "false"], + ["true", "false", "true", "false"], + ["true", "false", "true", "false"] + ]); - [int, int][2]|csv:Error rec3_2 = csv:parseListAsListType(csv2); - test:assertEquals(rec3_2, [ - [1, 2], - [3, 4] - ]); + string[][]|csv:Error cv1baa_5 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true, header: 2}); + test:assertEquals(cv1baa_5, [ + ["true", "false", "true", "false"], + ["true", "false", "true", "false"] + ]); - [int...][2]|csv:Error rec3_3 = csv:parseRecordAsListType(csv, ["a", "b"], {skipLines: [1]}); - test:assertEquals(rec3_3, [ - [3, 4], - [5, 6] - ]); + string[][]|csv:Error cv1baa_6 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: false, header: 2}); + test:assertEquals(cv1baa_6, [ + ["true", "false", "true", "false"] + ]); - int[1][2]|csv:Error rec4 = csv:parseRecordAsListType(csv, ["a", "b"], {skipLines: [2]}); - test:assertEquals(rec4, [ - [1, 2] - ]); + [string, string, string, string, string][]|csv:Error cv2baa_7 = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); + test:assertEquals(cv2baa_7, [ + ["b1", "b2", "b3", "b4", "b5"], + ["true", "false", "true", "false", "true"], + ["true", "false", "true", "false", "true"] + ]); - int[2][]|csv:Error rec5 = csv:parseListAsListType(csv2); - test:assertEquals(rec5, [ - [1, 2, 3], - [3, 4, 5] - ]); + [boolean|string, boolean|string...][]|csv:Error cv2baa_8 = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); + test:assertEquals(cv2baa_8, [ + ["b1", "b2", "b3", "b4", "b5"], + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + string[2][2]|csv:Error cv1baa_9 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true, header: false}); + test:assertEquals(cv1baa_9, [ + ["b1", "b2"], + ["true", "false"] + ]); } diff --git a/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_tuple_test.bal b/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_tuple_test.bal index efc268b..a43009d 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_tuple_test.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_tuple_test.bal @@ -20,106 +20,106 @@ import ballerina/test; @test:Config function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { - BooleanTuple1Array|csv:Error cbv1bt1 = csv:parseStringToList(csvStringWithBooleanValues1); + BooleanTuple1Array|csv:Error cbv1bt1 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1bt1, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - BooleanTuple1Array|csv:Error cbv2bt1 = csv:parseStringToList(csvStringWithBooleanValues2); + BooleanTuple1Array|csv:Error cbv2bt1 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2bt1, [ [true, false, true, false], [true, false, true, false] ]); - BooleanTuple1Array|csv:Error cbv3bt1 = csv:parseStringToList(csvStringWithBooleanValues3); + BooleanTuple1Array|csv:Error cbv3bt1 = csv:parseString(csvStringWithBooleanValues3); test:assertTrue(cbv3bt1 is csv:Error); test:assertEquals((cbv3bt1).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple1Array|csv:Error cbv5bt1 = csv:parseStringToList(csvStringWithBooleanValues5); + BooleanTuple1Array|csv:Error cbv5bt1 = csv:parseString(csvStringWithBooleanValues5); test:assertTrue(cbv5bt1 is csv:Error); test:assertEquals((cbv5bt1).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); - BooleanTuple1Array|csv:Error cbv7bt1 = csv:parseStringToList(csvStringWithBooleanValues7); + BooleanTuple1Array|csv:Error cbv7bt1 = csv:parseString(csvStringWithBooleanValues7); test:assertTrue(cbv7bt1 is csv:Error); test:assertEquals((cbv7bt1).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple2Array|csv:Error cbv1bt2 = csv:parseStringToList(csvStringWithBooleanValues1); + BooleanTuple2Array|csv:Error cbv1bt2 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1bt2, [ [true, false], [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error cbv2bt2 = csv:parseStringToList(csvStringWithBooleanValues2); + BooleanTuple2Array|csv:Error cbv2bt2 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2bt2, [ [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error cbv3bt2 = csv:parseStringToList(csvStringWithBooleanValues3); + BooleanTuple2Array|csv:Error cbv3bt2 = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cbv3bt2, [ [true, false], [true, false], [true, true] ]); - BooleanTuple2Array|csv:Error cbv4bt2 = csv:parseStringToList(csvStringWithBooleanValues4); + BooleanTuple2Array|csv:Error cbv4bt2 = csv:parseString(csvStringWithBooleanValues4); test:assertTrue(cbv4bt2 is csv:Error); test:assertEquals((cbv4bt2).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple3Array|csv:Error cbv1bt3 = csv:parseStringToList(csvStringWithBooleanValues1); + BooleanTuple3Array|csv:Error cbv1bt3 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1bt3, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - BooleanTuple3Array|csv:Error cbv2bt3 = csv:parseStringToList(csvStringWithBooleanValues2); + BooleanTuple3Array|csv:Error cbv2bt3 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2bt3, [ [true, false, true, false, true], [true, false, true, false, true] ]); - BooleanTuple3Array|csv:Error cbv3bt3 = csv:parseStringToList(csvStringWithBooleanValues3); + BooleanTuple3Array|csv:Error cbv3bt3 = csv:parseString(csvStringWithBooleanValues3); test:assertTrue(cbv3bt3 is csv:Error); test:assertEquals((cbv3bt3).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple3Array|csv:Error cbv5bt3 = csv:parseStringToList(csvStringWithBooleanValues5); + BooleanTuple3Array|csv:Error cbv5bt3 = csv:parseString(csvStringWithBooleanValues5); test:assertTrue(cbv5bt3 is csv:Error); test:assertEquals((cbv5bt3).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); - BooleanTuple3Array|csv:Error cbv7bt3 = csv:parseStringToList(csvStringWithBooleanValues7); + BooleanTuple3Array|csv:Error cbv7bt3 = csv:parseString(csvStringWithBooleanValues7); test:assertTrue(cbv7bt3 is csv:Error); test:assertEquals((cbv7bt3).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple4Array|csv:Error cbv1bt4 = csv:parseStringToList(csvStringWithBooleanValues1); + BooleanTuple4Array|csv:Error cbv1bt4 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1bt4, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - BooleanTuple4Array|csv:Error cbv2bt4 = csv:parseStringToList(csvStringWithBooleanValues2); + BooleanTuple4Array|csv:Error cbv2bt4 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2bt4, [ [true, false, true, false, true], [true, false, true, false, true] ]); - BooleanTuple4Array|csv:Error cbv3bt4 = csv:parseStringToList(csvStringWithBooleanValues3); + BooleanTuple4Array|csv:Error cbv3bt4 = csv:parseString(csvStringWithBooleanValues3); test:assertTrue(cbv3bt4 is csv:Error); test:assertEquals((cbv3bt4).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple4Array|csv:Error cbv4bt4 = csv:parseStringToList(csvStringWithBooleanValues4); + BooleanTuple4Array|csv:Error cbv4bt4 = csv:parseString(csvStringWithBooleanValues4); test:assertTrue(cbv4bt4 is csv:Error); test:assertEquals((cbv4bt4).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple4Array|csv:Error cbv5bt4 = csv:parseStringToList(csvStringWithBooleanValues5); + BooleanTuple4Array|csv:Error cbv5bt4 = csv:parseString(csvStringWithBooleanValues5); test:assertTrue(cbv5bt4 is csv:Error); test:assertEquals((cbv5bt4).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); - BooleanTuple4Array|csv:Error cbv6bt4 = csv:parseStringToList(csvStringWithBooleanValues6); + BooleanTuple4Array|csv:Error cbv6bt4 = csv:parseString(csvStringWithBooleanValues6); test:assertTrue(cbv6bt4 is csv:Error); test:assertEquals((cbv6bt4).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); @@ -127,107 +127,107 @@ function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { @test:Config function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { - BooleanTuple4Array|csv:Error cbv7bt4 = csv:parseStringToList(csvStringWithBooleanValues7); + BooleanTuple4Array|csv:Error cbv7bt4 = csv:parseString(csvStringWithBooleanValues7); test:assertTrue(cbv7bt4 is csv:Error); test:assertEquals((cbv7bt4).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - NillableBooleanTuple5Array|csv:Error cbv1bt5 = csv:parseStringToList(csvStringWithBooleanValues1); + NillableBooleanTuple5Array|csv:Error cbv1bt5 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1bt5, [ [true, false, true, false, null], [true, false, true, false, null], [true, false, true, false, null] ]); - NillableBooleanTuple5Array|csv:Error cbv2bt5 = csv:parseStringToList(csvStringWithBooleanValues2); + NillableBooleanTuple5Array|csv:Error cbv2bt5 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2bt5, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableBooleanTuple5Array|csv:Error cbv3bt5 = csv:parseStringToList(csvStringWithBooleanValues3); + NillableBooleanTuple5Array|csv:Error cbv3bt5 = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cbv3bt5, [ [true, false, true, null, null], [true, false, (), null, null], [true, true, false, null, null] ]); - NillableBooleanTuple5Array|csv:Error cbv4bt5 = csv:parseStringToList(csvStringWithBooleanValues4); + NillableBooleanTuple5Array|csv:Error cbv4bt5 = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cbv4bt5, [ [true, (), (), false, null], [true, (), (), false, null] ]); - NillableBooleanTuple5Array|csv:Error cbv5bt5 = csv:parseStringToList(csvStringWithBooleanValues5); + NillableBooleanTuple5Array|csv:Error cbv5bt5 = csv:parseString(csvStringWithBooleanValues5); test:assertTrue(cbv5bt5 is csv:Error); test:assertEquals((cbv5bt5).message(), common:generateErrorMessageForInvalidCast("2", "boolean?")); - NillableBooleanTuple5Array|csv:Error cbv6bt5 = csv:parseStringToList(csvStringWithBooleanValues6); + NillableBooleanTuple5Array|csv:Error cbv6bt5 = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cbv6bt5, [ [(), (), null, null, null] ]); - NillableBooleanTuple5Array|csv:Error cbv7bt5 = csv:parseStringToList(csvStringWithBooleanValues7); + NillableBooleanTuple5Array|csv:Error cbv7bt5 = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cbv7bt5, [ [b1, b2, (), b4, null] ]); - NillableBooleanTuple6Array|csv:Error cbv1bt6 = csv:parseStringToList(csvStringWithBooleanValues1); + NillableBooleanTuple6Array|csv:Error cbv1bt6 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1bt6, [ [true, false], [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error cbv2bt6 = csv:parseStringToList(csvStringWithBooleanValues2); + NillableBooleanTuple6Array|csv:Error cbv2bt6 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2bt6, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error cbv3bt6 = csv:parseStringToList(csvStringWithBooleanValues3); + NillableBooleanTuple6Array|csv:Error cbv3bt6 = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cbv3bt6, [ [true, false], [true, false], [true, true] ]); - NillableBooleanTuple6Array|csv:Error cbv4bt6 = csv:parseStringToList(csvStringWithBooleanValues4); + NillableBooleanTuple6Array|csv:Error cbv4bt6 = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cbv4bt6, [ [true, ()], [true, ()] ]); - NillableBooleanTuple6Array|csv:Error cbv6bt6 = csv:parseStringToList(csvStringWithBooleanValues6); + NillableBooleanTuple6Array|csv:Error cbv6bt6 = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cbv6bt6, [ [(), null] ]); - NillableBooleanTuple6Array|csv:Error cbv7bt6 = csv:parseStringToList(csvStringWithBooleanValues7); + NillableBooleanTuple6Array|csv:Error cbv7bt6 = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cbv7bt6, [ [b1, b2] ]); - NillableBooleanTuple7Array|csv:Error cbv1bt7 = csv:parseStringToList(csvStringWithBooleanValues1); + NillableBooleanTuple7Array|csv:Error cbv1bt7 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1bt7, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - NillableBooleanTuple7Array|csv:Error cbv2bt7 = csv:parseStringToList(csvStringWithBooleanValues2); + NillableBooleanTuple7Array|csv:Error cbv2bt7 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2bt7, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableBooleanTuple7Array|csv:Error cbv3bt7 = csv:parseStringToList(csvStringWithBooleanValues3); + NillableBooleanTuple7Array|csv:Error cbv3bt7 = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cbv3bt7, [ [true, false, true], [true, false, ()], [true, true, false] ]); - NillableBooleanTuple7Array|csv:Error cbv4bt7 = csv:parseStringToList(csvStringWithBooleanValues4); + NillableBooleanTuple7Array|csv:Error cbv4bt7 = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cbv4bt7, [ [true, (), (), false], [true, (), (), false] @@ -236,153 +236,153 @@ function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { } @test:Config function testFromCsvStringWithTypeForStringAndTupleAsExpectedType3() { - NillableBooleanTuple7Array|csv:Error cbv5bt7 = csv:parseStringToList(csvStringWithBooleanValues5); + NillableBooleanTuple7Array|csv:Error cbv5bt7 = csv:parseString(csvStringWithBooleanValues5); test:assertTrue(cbv5bt7 is csv:Error); test:assertEquals((cbv5bt7).message(), common:generateErrorMessageForInvalidCast("2", "boolean?")); - NillableBooleanTuple7Array|csv:Error cbv6bt7 = csv:parseStringToList(csvStringWithBooleanValues6); + NillableBooleanTuple7Array|csv:Error cbv6bt7 = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cbv6bt7, [ [(), ()] ]); - NillableBooleanTuple7Array|csv:Error cbv7bt7 = csv:parseStringToList(csvStringWithBooleanValues7); + NillableBooleanTuple7Array|csv:Error cbv7bt7 = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cbv7bt7, [ [b1, b2, (), false] ]); - NillableBooleanTuple8Array|csv:Error cbv1bt8 = csv:parseStringToList(csvStringWithBooleanValues1); + NillableBooleanTuple8Array|csv:Error cbv1bt8 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1bt8, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - NillableBooleanTuple8Array|csv:Error cbv2bt8 = csv:parseStringToList(csvStringWithBooleanValues2); + NillableBooleanTuple8Array|csv:Error cbv2bt8 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2bt8, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableBooleanTuple8Array|csv:Error cbv3bt8 = csv:parseStringToList(csvStringWithBooleanValues3); + NillableBooleanTuple8Array|csv:Error cbv3bt8 = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cbv3bt8, [ [true, false, true], [true, false, ()], [true, true, false] ]); - NillableBooleanTuple8Array|csv:Error cbv4bt8 = csv:parseStringToList(csvStringWithBooleanValues4); + NillableBooleanTuple8Array|csv:Error cbv4bt8 = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cbv4bt8, [ [true, (), (), false], [true, (), (), false] ]); - NillableBooleanTuple8Array|csv:Error cbv5bt8 = csv:parseStringToList(csvStringWithBooleanValues5); + NillableBooleanTuple8Array|csv:Error cbv5bt8 = csv:parseString(csvStringWithBooleanValues5); test:assertTrue(cbv5bt8 is csv:Error); test:assertEquals((cbv5bt8).message(), common:generateErrorMessageForInvalidCast("2", "boolean?")); - NillableBooleanTuple8Array|csv:Error cbv6bt8 = csv:parseStringToList(csvStringWithBooleanValues6); + NillableBooleanTuple8Array|csv:Error cbv6bt8 = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cbv6bt8, [ [(), ()] ]); - NillableBooleanTuple8Array|csv:Error cbv7bt8 = csv:parseStringToList(csvStringWithBooleanValues7); + NillableBooleanTuple8Array|csv:Error cbv7bt8 = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cbv7bt8, [ [b1, b2, (), false] ]); - NillableIntBooleanTuple9Array|csv:Error cbv1bt9 = csv:parseStringToList(csvStringWithBooleanValues1); + NillableIntBooleanTuple9Array|csv:Error cbv1bt9 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1bt9, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - NillableIntBooleanTuple9Array|csv:Error cbv2bt9 = csv:parseStringToList(csvStringWithBooleanValues2); + NillableIntBooleanTuple9Array|csv:Error cbv2bt9 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2bt9, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableIntBooleanTuple9Array|csv:Error cbv3bt9 = csv:parseStringToList(csvStringWithBooleanValues3); + NillableIntBooleanTuple9Array|csv:Error cbv3bt9 = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cbv3bt9, [ [true, false, true], [true, false, ()], [true, true, false] ]); - NillableIntBooleanTuple9Array|csv:Error cbv4bt9 = csv:parseStringToList(csvStringWithBooleanValues4); + NillableIntBooleanTuple9Array|csv:Error cbv4bt9 = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cbv4bt9, [ [true, (), (), false], [true, (), (), false] ]); - NillableIntBooleanTuple9Array|csv:Error cbv5bt9 = csv:parseStringToList(csvStringWithBooleanValues5); + NillableIntBooleanTuple9Array|csv:Error cbv5bt9 = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(cbv5bt9, [ [true, false, true, 2], [true, false, true, 3] ]); - NillableIntBooleanTuple9Array|csv:Error cbv6bt9 = csv:parseStringToList(csvStringWithBooleanValues6); + NillableIntBooleanTuple9Array|csv:Error cbv6bt9 = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cbv6bt9, [ [(), ()] ]); - NillableIntBooleanTuple9Array|csv:Error cbv7bt9 = csv:parseStringToList(csvStringWithBooleanValues7); + NillableIntBooleanTuple9Array|csv:Error cbv7bt9 = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cbv7bt9, [ [b1, b2, (), false] ]); - NilTuple3Array|csv:Error cbv1nt3 = csv:parseStringToList(csvStringWithBooleanValues1); + NilTuple3Array|csv:Error cbv1nt3 = csv:parseString(csvStringWithBooleanValues1); test:assertTrue(cbv1nt3 is csv:Error); test:assertEquals((cbv1nt3).message(), common:generateErrorMessageForInvalidCast("true", "()")); - NilTuple3Array|csv:Error cbv3nt3 = csv:parseStringToList(csvStringWithBooleanValues3); + NilTuple3Array|csv:Error cbv3nt3 = csv:parseString(csvStringWithBooleanValues3); test:assertTrue(cbv3nt3 is csv:Error); test:assertEquals((cbv3nt3).message(), common:generateErrorMessageForInvalidCast("true", "()")); - NilTuple3Array|csv:Error cbv6nt3 = csv:parseStringToList(csvStringWithBooleanValues6); + NilTuple3Array|csv:Error cbv6nt3 = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cbv6nt3, [ [(), ()] ]); - AnydataTuple3Array|csv:Error cbv1anyd3 = csv:parseStringToList(csvStringWithBooleanValues1); + AnydataTuple3Array|csv:Error cbv1anyd3 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1anyd3, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - AnydataTuple3Array|csv:Error cbv2anyd3 = csv:parseStringToList(csvStringWithBooleanValues2); + AnydataTuple3Array|csv:Error cbv2anyd3 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2anyd3, [ [true, false, true, false, true], [true, false, true, false, true] ]); - AnydataTuple3Array|csv:Error cbv3anyd3 = csv:parseStringToList(csvStringWithBooleanValues3); + AnydataTuple3Array|csv:Error cbv3anyd3 = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cbv3anyd3, [ [true, false, true], [true, false, ()], [true, true, false] ]); - AnydataTuple3Array|csv:Error cbv4anyd3 = csv:parseStringToList(csvStringWithBooleanValues4); + AnydataTuple3Array|csv:Error cbv4anyd3 = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cbv4anyd3, [ [true, (), (), false], [true, (), (), false] ]); - AnydataTuple3Array|csv:Error cbv5anyd3 = csv:parseStringToList(csvStringWithBooleanValues5); + AnydataTuple3Array|csv:Error cbv5anyd3 = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(cbv5anyd3, [ [true, false, true, 2], [true, false, true, 3] ]); - AnydataTuple3Array|csv:Error cbv6anyd3 = csv:parseStringToList(csvStringWithBooleanValues6); + AnydataTuple3Array|csv:Error cbv6anyd3 = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cbv6anyd3, [ [(), ()] ]); - AnydataTuple3Array|csv:Error cbv7anyd3 = csv:parseStringToList(csvStringWithBooleanValues7); + AnydataTuple3Array|csv:Error cbv7anyd3 = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cbv7anyd3, [ [b1, b2, (), false] ]); @@ -390,99 +390,99 @@ function testFromCsvStringWithTypeForStringAndTupleAsExpectedType3() { @test:Config function testFromCsvStringWithTypeForStringAndTupleAsExpectedType4() { - JsonTuple3Array|csv:Error cbv1j3 = csv:parseStringToList(csvStringWithBooleanValues1); + JsonTuple3Array|csv:Error cbv1j3 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1j3, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - JsonTuple3Array|csv:Error cbv2j3 = csv:parseStringToList(csvStringWithBooleanValues2); + JsonTuple3Array|csv:Error cbv2j3 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2j3, [ [true, false, true, false, true], [true, false, true, false, true] ]); - JsonTuple3Array|csv:Error cbv3j3 = csv:parseStringToList(csvStringWithBooleanValues3); + JsonTuple3Array|csv:Error cbv3j3 = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cbv3j3, [ [true, false, true], [true, false, ()], [true, true, false] ]); - JsonTuple3Array|csv:Error cbv4j3 = csv:parseStringToList(csvStringWithBooleanValues4); + JsonTuple3Array|csv:Error cbv4j3 = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cbv4j3, [ [true, (), (), false], [true, (), (), false] ]); - JsonTuple3Array|csv:Error cbv5j3 = csv:parseStringToList(csvStringWithBooleanValues5); + JsonTuple3Array|csv:Error cbv5j3 = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(cbv5j3, [ [true, false, true, 2], [true, false, true, 3] ]); - JsonTuple3Array|csv:Error cbv6j3 = csv:parseStringToList(csvStringWithBooleanValues6); + JsonTuple3Array|csv:Error cbv6j3 = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cbv6j3, [ [(), ()] ]); - JsonTuple3Array|csv:Error cbv7j3 = csv:parseStringToList(csvStringWithBooleanValues7); + JsonTuple3Array|csv:Error cbv7j3 = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cbv7j3, [ [b1, b2, (), false] ]); - StringTuple3Array|csv:Error cbv1s3 = csv:parseStringToList(csvStringWithBooleanValues1); + StringTuple3Array|csv:Error cbv1s3 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(cbv1s3, [ ["true", "false", "true", "false"], ["true", "false", "true", "false"], ["true", "false", "true", "false"] ]); - StringTuple3Array|csv:Error cbv2s3 = csv:parseStringToList(csvStringWithBooleanValues2); + StringTuple3Array|csv:Error cbv2s3 = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(cbv2s3, [ ["true", "false", "true", "false", "true"], ["true", "false", "true", "false", "true"] ]); - StringTuple3Array|csv:Error cbv3s3 = csv:parseStringToList(csvStringWithBooleanValues3); + StringTuple3Array|csv:Error cbv3s3 = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(cbv3s3, [ ["true", "false", "true"], ["TRUE", "FALSE", "()"], ["true", "true", "FALSE"] ]); - StringTuple3Array|csv:Error cbv4s3 = csv:parseStringToList(csvStringWithBooleanValues4); + StringTuple3Array|csv:Error cbv4s3 = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(cbv4s3, [ ["true", "()", "()", "false"], ["true", "()", "null", "false"] ]); - StringTuple3Array|csv:Error cbv5s3 = csv:parseStringToList(csvStringWithBooleanValues5); + StringTuple3Array|csv:Error cbv5s3 = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(cbv5s3, [ ["true", "false", "true", "2"], ["true", "false", "true", "3"] ]); - StringTuple3Array|csv:Error cbv6s3 = csv:parseStringToList(csvStringWithBooleanValues6); + StringTuple3Array|csv:Error cbv6s3 = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(cbv6s3, [ ["()", "()"] ]); - StringTuple3Array|csv:Error cbv7s3 = csv:parseStringToList(csvStringWithBooleanValues7); + StringTuple3Array|csv:Error cbv7s3 = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(cbv7s3, [ ["true", "false", "()", "false"] ]); - DecimalTuple3Array|csv:Error cbv1dt3 = csv:parseStringToList(csvStringWithBooleanValues1); + DecimalTuple3Array|csv:Error cbv1dt3 = csv:parseString(csvStringWithBooleanValues1); test:assertTrue(cbv1dt3 is csv:Error); test:assertEquals((cbv1dt3).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); - DecimalTuple3Array|csv:Error cbv3dt3 = csv:parseStringToList(csvStringWithBooleanValues3); + DecimalTuple3Array|csv:Error cbv3dt3 = csv:parseString(csvStringWithBooleanValues3); test:assertTrue(cbv3dt3 is csv:Error); test:assertEquals((cbv3dt3).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); - DecimalTuple3Array|csv:Error cbv6dt3 = csv:parseStringToList(csvStringWithBooleanValues6); + DecimalTuple3Array|csv:Error cbv6dt3 = csv:parseString(csvStringWithBooleanValues6); test:assertTrue(cbv6dt3 is csv:Error); test:assertEquals((cbv6dt3).message(), common:generateErrorMessageForInvalidCast("()", "decimal")); } diff --git a/ballerina-tests/parse-string-record-types-tests/Ballerina.toml b/ballerina-tests/parse-string-record-types-tests/Ballerina.toml index 3775e98..795eb35 100644 --- a/ballerina-tests/parse-string-record-types-tests/Ballerina.toml +++ b/ballerina-tests/parse-string-record-types-tests/Ballerina.toml @@ -13,4 +13,4 @@ version = "0.1.0" graalvmCompatible = true [build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" +graalvmBuildOptions = "-H:+IncludeAllLocales" diff --git a/ballerina-tests/parse-string-record-types-tests/Dependencies.toml b/ballerina-tests/parse-string-record-types-tests/Dependencies.toml index 7e5d364..cf6d15e 100644 --- a/ballerina-tests/parse-string-record-types-tests/Dependencies.toml +++ b/ballerina-tests/parse-string-record-types-tests/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.0" +distribution-version = "2201.10.0-20240801-104200-87df251c" [[package]] org = "ballerina" diff --git a/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests.bal b/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests.bal index c15191a..7a831e9 100644 --- a/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests.bal @@ -19,98 +19,98 @@ import ballerina/test; @test:Config function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { - BooleanMapArray|csv:Error bv1bma = csv:parseStringToRecord(csvStringWithBooleanValues1); + BooleanMapArray|csv:Error bv1bma = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(bv1bma, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - BooleanMapArray|csv:Error bv2bma = csv:parseStringToRecord(csvStringWithBooleanValues2); + BooleanMapArray|csv:Error bv2bma = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(bv2bma, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - BooleanMapArray|csv:Error bv3bma = csv:parseStringToRecord(csvStringWithBooleanValues3); + BooleanMapArray|csv:Error bv3bma = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(bv3bma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false}, {b1: true, b2: true, b3: false} ]); - BooleanMapArray|csv:Error bv4bma = csv:parseStringToRecord(csvStringWithBooleanValues4); + BooleanMapArray|csv:Error bv4bma = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(bv4bma, [ {b1: true, b4: false}, {b1: true, b4: false} ]); - BooleanMapArray|csv:Error bv5bma = csv:parseStringToRecord(csvStringWithBooleanValues5); + BooleanMapArray|csv:Error bv5bma = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(bv5bma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - BooleanMapArray|csv:Error bv6bma = csv:parseStringToRecord(csvStringWithBooleanValues6); + BooleanMapArray|csv:Error bv6bma = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(bv6bma, [ {} ]); - BooleanMapArray|csv:Error bv7bma = csv:parseStringToRecord(csvStringWithBooleanValues7); + BooleanMapArray|csv:Error bv7bma = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(bv7bma, [ {b1, b2, b4} ]); - NillableBooleanMapArray|csv:Error bv1bnbma = csv:parseStringToRecord(csvStringWithBooleanValues1); + NillableBooleanMapArray|csv:Error bv1bnbma = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(bv1bnbma, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - NillableBooleanMapArray|csv:Error bv2bnbma = csv:parseStringToRecord(csvStringWithBooleanValues2); + NillableBooleanMapArray|csv:Error bv2bnbma = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(bv2bnbma, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - NillableBooleanMapArray|csv:Error bv3bnbma = csv:parseStringToRecord(csvStringWithBooleanValues3); + NillableBooleanMapArray|csv:Error bv3bnbma = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(bv3bnbma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - NillableBooleanMapArray|csv:Error bv4bnbma = csv:parseStringToRecord(csvStringWithBooleanValues4); + NillableBooleanMapArray|csv:Error bv4bnbma = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(bv4bnbma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - NillableBooleanMapArray|csv:Error bv5bnbma = csv:parseStringToRecord(csvStringWithBooleanValues5); + NillableBooleanMapArray|csv:Error bv5bnbma = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(bv5bnbma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - NillableBooleanMapArray|csv:Error bv6bnbma = csv:parseStringToRecord(csvStringWithBooleanValues6); + NillableBooleanMapArray|csv:Error bv6bnbma = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(bv6bnbma, [ {b2: (), b3: ()} ]); - NillableBooleanMapArray|csv:Error bv7bnbma = csv:parseStringToRecord(csvStringWithBooleanValues7); + NillableBooleanMapArray|csv:Error bv7bnbma = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(bv7bnbma, [ {b1, b2, b3, b4} ]); - NillableIntUnionBooleanMapArray|csv:Error bv1bniubma = csv:parseStringToRecord(csvStringWithBooleanValues1); + NillableIntUnionBooleanMapArray|csv:Error bv1bniubma = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(bv1bniubma, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - NillableIntUnionBooleanMapArray|csv:Error bv2bniubma = csv:parseStringToRecord(csvStringWithBooleanValues2); + NillableIntUnionBooleanMapArray|csv:Error bv2bniubma = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(bv2bniubma, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} @@ -120,104 +120,104 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { @test:Config function testFromCsvStringWithTypeForStringAndMapAsExpectedType2() { - NillableIntUnionBooleanMapArray|csv:Error bv3bniubma = csv:parseStringToRecord(csvStringWithBooleanValues3); + NillableIntUnionBooleanMapArray|csv:Error bv3bniubma = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(bv3bniubma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - NillableIntUnionBooleanMapArray|csv:Error bv4bniubma = csv:parseStringToRecord(csvStringWithBooleanValues4); + NillableIntUnionBooleanMapArray|csv:Error bv4bniubma = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(bv4bniubma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - NillableIntUnionBooleanMapArray|csv:Error bv5bniubma = csv:parseStringToRecord(csvStringWithBooleanValues5); + NillableIntUnionBooleanMapArray|csv:Error bv5bniubma = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(bv5bniubma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - NillableIntUnionBooleanMapArray|csv:Error bv6bniubma = csv:parseStringToRecord(csvStringWithBooleanValues6); + NillableIntUnionBooleanMapArray|csv:Error bv6bniubma = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(bv6bniubma, [ {b2: (), b3: ()} ]); - NillableIntUnionBooleanMapArray|csv:Error bv7bniubma = csv:parseStringToRecord(csvStringWithBooleanValues7); + NillableIntUnionBooleanMapArray|csv:Error bv7bniubma = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(bv7bniubma, [ {b1, b2, b3, b4} ]); - IntUnionBooleanMapArray|csv:Error bv1biubma = csv:parseStringToRecord(csvStringWithBooleanValues1); + IntUnionBooleanMapArray|csv:Error bv1biubma = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(bv1biubma, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - IntUnionBooleanMapArray|csv:Error bv2biubma = csv:parseStringToRecord(csvStringWithBooleanValues2); + IntUnionBooleanMapArray|csv:Error bv2biubma = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(bv2biubma, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - IntUnionBooleanMapArray|csv:Error bv3biubma = csv:parseStringToRecord(csvStringWithBooleanValues3); + IntUnionBooleanMapArray|csv:Error bv3biubma = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(bv3biubma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false}, {b1: true, b2: true, b3: false} ]); - IntUnionBooleanMapArray|csv:Error bv4biubma = csv:parseStringToRecord(csvStringWithBooleanValues4); + IntUnionBooleanMapArray|csv:Error bv4biubma = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(bv4biubma, [ {b1: true, b4: false}, {b1: true, b4: false} ]); - IntUnionBooleanMapArray|csv:Error bv5biubma = csv:parseStringToRecord(csvStringWithBooleanValues5); + IntUnionBooleanMapArray|csv:Error bv5biubma = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(bv5biubma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - IntUnionBooleanMapArray|csv:Error bv6biubma = csv:parseStringToRecord(csvStringWithBooleanValues6); + IntUnionBooleanMapArray|csv:Error bv6biubma = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(bv6biubma, [ {} ]); - IntUnionBooleanMapArray|csv:Error bv7biubma = csv:parseStringToRecord(csvStringWithBooleanValues7); + IntUnionBooleanMapArray|csv:Error bv7biubma = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(bv7biubma, [ {b1, b2, b4} ]); - NilMapArray|csv:Error bv1bnma = csv:parseStringToRecord(csvStringWithBooleanValues1); + NilMapArray|csv:Error bv1bnma = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(bv1bnma, [ {}, {}, {} ]); - NilMapArray|csv:Error bv2bnma = csv:parseStringToRecord(csvStringWithBooleanValues2); + NilMapArray|csv:Error bv2bnma = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(bv2bnma, [ {}, {} ]); - NilMapArray|csv:Error bv3bnma = csv:parseStringToRecord(csvStringWithBooleanValues3); + NilMapArray|csv:Error bv3bnma = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(bv3bnma, [ {}, {b3: ()}, {} ]); - NilMapArray|csv:Error bv4bnma = csv:parseStringToRecord(csvStringWithBooleanValues4); + NilMapArray|csv:Error bv4bnma = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(bv4bnma, [ {b2: (), b3: ()}, {b2: (), b3: ()} ]); - NilMapArray|csv:Error bv5bnma = csv:parseStringToRecord(csvStringWithBooleanValues5); + NilMapArray|csv:Error bv5bnma = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(bv5bnma, [ {}, {} @@ -226,101 +226,101 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType2() { @test:Config function testFromCsvStringWithTypeForStringAndMapAsExpectedType3() { - NilMapArray|csv:Error bv6bnma = csv:parseStringToRecord(csvStringWithBooleanValues6); + NilMapArray|csv:Error bv6bnma = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(bv6bnma, [ {b2: (), b3: ()} ]); - NilMapArray|csv:Error bv7bnma = csv:parseStringToRecord(csvStringWithBooleanValues7); + NilMapArray|csv:Error bv7bnma = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(bv7bnma, [ {b3} ]); - JsonMapArray|csv:Error bv1bjma = csv:parseStringToRecord(csvStringWithBooleanValues1); + JsonMapArray|csv:Error bv1bjma = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(bv1bjma, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - JsonMapArray|csv:Error bv2bjma = csv:parseStringToRecord(csvStringWithBooleanValues2); + JsonMapArray|csv:Error bv2bjma = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(bv2bjma, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - JsonMapArray|csv:Error bv3bjma = csv:parseStringToRecord(csvStringWithBooleanValues3); + JsonMapArray|csv:Error bv3bjma = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(bv3bjma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - JsonMapArray|csv:Error bv4bjma = csv:parseStringToRecord(csvStringWithBooleanValues4); + JsonMapArray|csv:Error bv4bjma = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(bv4bjma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - JsonMapArray|csv:Error bv5bjma = csv:parseStringToRecord(csvStringWithBooleanValues5); + JsonMapArray|csv:Error bv5bjma = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(bv5bjma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - JsonMapArray|csv:Error bv6bjma = csv:parseStringToRecord(csvStringWithBooleanValues6); + JsonMapArray|csv:Error bv6bjma = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(bv6bjma, [ {b2: (), b3: ()} ]); - JsonMapArray|csv:Error bv7bjma = csv:parseStringToRecord(csvStringWithBooleanValues7); + JsonMapArray|csv:Error bv7bjma = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(bv7bjma, [ {b1, b2, b3, b4} ]); - AnydataMapArray|csv:Error bv1banydma = csv:parseStringToRecord(csvStringWithBooleanValues1); + AnydataMapArray|csv:Error bv1banydma = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(bv1banydma, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - AnydataMapArray|csv:Error bv2banydma = csv:parseStringToRecord(csvStringWithBooleanValues2); + AnydataMapArray|csv:Error bv2banydma = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(bv2banydma, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - AnydataMapArray|csv:Error bv3banydma = csv:parseStringToRecord(csvStringWithBooleanValues3); + AnydataMapArray|csv:Error bv3banydma = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(bv3banydma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - AnydataMapArray|csv:Error bv4banydma = csv:parseStringToRecord(csvStringWithBooleanValues4); + AnydataMapArray|csv:Error bv4banydma = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(bv4banydma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - AnydataMapArray|csv:Error bv5banydma = csv:parseStringToRecord(csvStringWithBooleanValues5); + AnydataMapArray|csv:Error bv5banydma = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(bv5banydma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - AnydataMapArray|csv:Error bv6banydma = csv:parseStringToRecord(csvStringWithBooleanValues6); + AnydataMapArray|csv:Error bv6banydma = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(bv6banydma, [ {b2: (), b3: ()} ]); - AnydataMapArray|csv:Error bv7banydma = csv:parseStringToRecord(csvStringWithBooleanValues7); + AnydataMapArray|csv:Error bv7banydma = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(bv7banydma, [ {b1, b2, b3, b4} ]); - CustomMapArray|csv:Error bv1bcma = csv:parseStringToRecord(csvStringWithBooleanValues1); + CustomMapArray|csv:Error bv1bcma = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(bv1bcma, [ {b1: "true", b2: "false", b3: "true", b4: "false"}, {b1: "true", b2: "false", b3: "true", b4: "false"}, @@ -330,95 +330,95 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType3() { @test:Config function testFromCsvStringWithTypeForStringAndMapAsExpectedType4() { - CustomMapArray|csv:Error bv2bcma = csv:parseStringToRecord(csvStringWithBooleanValues2); + CustomMapArray|csv:Error bv2bcma = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(bv2bcma, [ {b1: "true", b2: "false", b3: "true", b4: "false", b5: "true"}, {b1: "true", b2: "false", b3: "true", b4: "false", b5: "true"} ]); - CustomMapArray|csv:Error bv3bcma = csv:parseStringToRecord(csvStringWithBooleanValues3); + CustomMapArray|csv:Error bv3bcma = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(bv3bcma, [ {b1: "true", b2: "false", b3: "true"}, {b1: "TRUE", b2: "FALSE", b3: "()"}, {b1: "true", b2: "true", b3: "FALSE"} ]); - CustomMapArray|csv:Error bv4bcma = csv:parseStringToRecord(csvStringWithBooleanValues4); + CustomMapArray|csv:Error bv4bcma = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(bv4bcma, [ {b1: "true", b2: "()", b3: "()", b4: "false"}, {b1: "true", b2: "()", b3: "null", b4: "false"} ]); - CustomMapArray|csv:Error bv5bcma = csv:parseStringToRecord(csvStringWithBooleanValues5); + CustomMapArray|csv:Error bv5bcma = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(bv5bcma, [ {b1: "true", b2: "false", b3: "true", b4: 2}, {b1: "true", b2: "false", b3: "true", b4: 3} ]); - CustomMapArray|csv:Error bv6bcma = csv:parseStringToRecord(csvStringWithBooleanValues6); + CustomMapArray|csv:Error bv6bcma = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(bv6bcma, [ {b2: "()", b3: "()"} ]); - CustomMapArray|csv:Error bv7bcma = csv:parseStringToRecord(csvStringWithBooleanValues7); + CustomMapArray|csv:Error bv7bcma = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(bv7bcma, [ {b1: "true", b2: "false", b3: "()", b4: "false"} ]); - StringMapArray|csv:Error bv1bsma = csv:parseStringToRecord(csvStringWithBooleanValues1); + StringMapArray|csv:Error bv1bsma = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(bv1bsma, [ {b1: "true", b2: "false", b3: "true", b4: "false"}, {b1: "true", b2: "false", b3: "true", b4: "false"}, {b1: "true", b2: "false", b3: "true", b4: "false"} ]); - StringMapArray|csv:Error bv2bsma = csv:parseStringToRecord(csvStringWithBooleanValues2); + StringMapArray|csv:Error bv2bsma = csv:parseString(csvStringWithBooleanValues2); test:assertEquals(bv2bsma, [ {b1: "true", b2: "false", b3: "true", b4: "false", b5: "true"}, {b1: "true", b2: "false", b3: "true", b4: "false", b5: "true"} ]); - StringMapArray|csv:Error bv3bsma = csv:parseStringToRecord(csvStringWithBooleanValues3); + StringMapArray|csv:Error bv3bsma = csv:parseString(csvStringWithBooleanValues3); test:assertEquals(bv3bsma, [ {b1: "true", b2: "false", b3: "true"}, {b1: "TRUE", b2: "FALSE", b3: "()"}, {b1: "true", b2: "true", b3: "FALSE"} ]); - StringMapArray|csv:Error bv4bsma = csv:parseStringToRecord(csvStringWithBooleanValues4); + StringMapArray|csv:Error bv4bsma = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(bv4bsma, [ {b1: "true", b2: "()", b3: "()", b4: "false"}, {b1: "true", b2: "()", b3: "null", b4: "false"} ]); - StringMapArray|csv:Error bv5bsma = csv:parseStringToRecord(csvStringWithBooleanValues5); + StringMapArray|csv:Error bv5bsma = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(bv5bsma, [ {b1: "true", b2: "false", b3: "true", b4: "2"}, {b1: "true", b2: "false", b3: "true", b4: "3"} ]); - StringMapArray|csv:Error bv6bsma = csv:parseStringToRecord(csvStringWithBooleanValues6); + StringMapArray|csv:Error bv6bsma = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(bv6bsma, [ {b2: "()", b3: "()"} ]); - StringMapArray|csv:Error bv7bsma = csv:parseStringToRecord(csvStringWithBooleanValues7); + StringMapArray|csv:Error bv7bsma = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(bv7bsma, [ {b1: "true", b2: "false", b3: "()", b4: "false"} ]); - DecimalMapArray|csv:Error bv1dsma = csv:parseStringToRecord(csvStringWithBooleanValues1); + DecimalMapArray|csv:Error bv1dsma = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(bv1dsma, [ {}, {}, {} ]); - DecimalMapArray|csv:Error bv6dsma = csv:parseStringToRecord(csvStringWithBooleanValues6); + DecimalMapArray|csv:Error bv6dsma = csv:parseString(csvStringWithBooleanValues6); test:assertEquals(bv6dsma, [ {} ]); - DecimalMapArray|csv:Error bv7dsma = csv:parseStringToRecord(csvStringWithBooleanValues7); + DecimalMapArray|csv:Error bv7dsma = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(bv7dsma, [ {} ]); diff --git a/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_record_tests.bal b/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_record_tests.bal index de15f81..3a212dc 100644 --- a/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_record_tests.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_record_tests.bal @@ -20,101 +20,101 @@ import ballerina/test; @test:Config function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { - BooleanRecord1Array|csv:Error csvb1br1 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord1Array|csv:Error csvb1br1 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true}); test:assertEquals(csvb1br1, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - BooleanRecord1Array|csv:Error csvb2br1 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord1Array|csv:Error csvb2br1 = csv:parseString(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br1, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - BooleanRecord1Array|csv:Error csvb3br1 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord1Array|csv:Error csvb3br1 = csv:parseString(csvStringWithBooleanValues3, {}); test:assertTrue(csvb3br1 is csv:Error); test:assertEquals((csvb3br1).message(), common:generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord1Array|csv:Error csvb4br1 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord1Array|csv:Error csvb4br1 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br1, [ {b1: true, b2: "()", b3: (), b4: false}, {b1: true, b2: "()", b3: (), b4: false} ]); - BooleanRecord1Array|csv:Error csvb5br1 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord1Array|csv:Error csvb5br1 = csv:parseString(csvStringWithBooleanValues5, {}); test:assertTrue(csvb5br1 is csv:Error); test:assertEquals((csvb5br1).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); - BooleanRecord1Array|csv:Error csvb6br1 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord1Array|csv:Error csvb6br1 = csv:parseString(csvStringWithBooleanValues6, {}); test:assertTrue(csvb6br1 is csv:Error); test:assertEquals((csvb6br1).message(), common:generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord1Array|csv:Error csvb7br1 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord1Array|csv:Error csvb7br1 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br1, [ {b1, b2, b3: (), b4} ]); - BooleanRecord2Array|csv:Error csvb1br2 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord2Array|csv:Error csvb1br2 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br2, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - BooleanRecord2Array|csv:Error csvb2br2 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord2Array|csv:Error csvb2br2 = csv:parseString(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br2, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - BooleanRecord2Array|csv:Error csvb3br2 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord2Array|csv:Error csvb3br2 = csv:parseString(csvStringWithBooleanValues3, {outputWithHeaders: true}); test:assertTrue(csvb3br2 is csv:Error); test:assertEquals((csvb3br2).message(), common:generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord2Array|csv:Error csvb4br2 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord2Array|csv:Error csvb4br2 = csv:parseString(csvStringWithBooleanValues4, {outputWithHeaders: true}); test:assertEquals(csvb4br2, [ {b1: true, b2: "()", b3: (), b4: false}, {b1: true, b2: "()", b3: (), b4: false} ]); - BooleanRecord2Array|csv:Error csvb5br2 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord2Array|csv:Error csvb5br2 = csv:parseString(csvStringWithBooleanValues5, {}); test:assertTrue(csvb5br2 is csv:Error); test:assertEquals((csvb5br2).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); - BooleanRecord2Array|csv:Error csvb7br2 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord2Array|csv:Error csvb7br2 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br2, [ {b1, b2, b3: (), b4} ]); - BooleanRecord3Array|csv:Error csvb1br3 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord3Array|csv:Error csvb1br3 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br3, [ {b1: true, b3: true}, {b1: true, b3: true}, {b1: true, b3: true} ]); - BooleanRecord3Array|csv:Error csvb2br3 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord3Array|csv:Error csvb2br3 = csv:parseString(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br3, [ {b1: true, b3: true}, {b1: true, b3: true} ]); - BooleanRecord3Array|csv:Error csvb3br3 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord3Array|csv:Error csvb3br3 = csv:parseString(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br3, [ {b1: true, b3: true}, {b1: true, b3: ()}, {b1: true, b3: false} ]); - BooleanRecord3Array|csv:Error csvb4br3 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord3Array|csv:Error csvb4br3 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br3, [ {b1: true, b3: ()}, {b1: true, b3: ()} ]); - BooleanRecord3Array|csv:Error csvb5br3 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord3Array|csv:Error csvb5br3 = csv:parseString(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br3, [ {b1: true, b3: true}, {b1: true, b3: true} @@ -123,99 +123,99 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { @test:Config function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { - BooleanRecord3Array|csv:Error csvb7br3 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord3Array|csv:Error csvb7br3 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br3, [ {b1, b3: ()} ]); - BooleanRecord4Array|csv:Error csvb1br4 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord4Array|csv:Error csvb1br4 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br4, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - BooleanRecord4Array|csv:Error csvb2br4 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord4Array|csv:Error csvb2br4 = csv:parseString(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br4, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - BooleanRecord4Array|csv:Error csvb3br4 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord4Array|csv:Error csvb3br4 = csv:parseString(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br4, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: ()}, {b1: true, b2: true, b3: false} ]); - BooleanRecord4Array|csv:Error csvb4br4 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord4Array|csv:Error csvb4br4 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br4, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - BooleanRecord4Array|csv:Error csvb5br4 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord4Array|csv:Error csvb5br4 = csv:parseString(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br4, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - BooleanRecord4Array|csv:Error csvb7br4 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord4Array|csv:Error csvb7br4 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br4, [ {b1, b2, b3: (), b4} ]); - BooleanRecord5Array|csv:Error csvb1br5 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord5Array|csv:Error csvb1br5 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br5, [ {b1: true, b2: false, b3: true, b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord5Array|csv:Error csvb2br5 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord5Array|csv:Error csvb2br5 = csv:parseString(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br5, [ {b1: true, b2: false, b3: true, b4: false, b5: true, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: false, b5: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord5Array|csv:Error csvb3br5 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord5Array|csv:Error csvb3br5 = csv:parseString(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br5, [ {b1: true, b2: false, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b2: true, b3: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord5Array|csv:Error csvb4br5 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord5Array|csv:Error csvb4br5 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br5, [ {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord5Array|csv:Error csvb5br5 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord5Array|csv:Error csvb5br5 = csv:parseString(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br5, [ {b1: true, b2: false, b3: true, b4: 2, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: 3, defaultableField: "", nillableField: ()} ]); - BooleanRecord5Array|csv:Error csvb7br5 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord5Array|csv:Error csvb7br5 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br5, [ {b1, b2, b3: (), b4, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error csvb1br6 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord6Array|csv:Error csvb1br6 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br6, [ {b1: true, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b3: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error csvb2br6 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord6Array|csv:Error csvb2br6 = csv:parseString(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br6, [ {b1: true, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b3: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error csvb3br6 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord6Array|csv:Error csvb3br6 = csv:parseString(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br6, [ {b1: true, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()}, @@ -225,115 +225,115 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { @test:Config function testFromCsvStringWithTypeForStringAndRecordAsExpectedType3() { - BooleanRecord6Array|csv:Error csvb4br6 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord6Array|csv:Error csvb4br6 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br6, [ {b1: true, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error csvb5br6 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord6Array|csv:Error csvb5br6 = csv:parseString(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br6, [ {b1: true, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b3: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error csvb7br6 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord6Array|csv:Error csvb7br6 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br6, [ {b1, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord7Array|csv:Error csvb1br7 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord7Array|csv:Error csvb1br7 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertTrue(csvb1br7 is csv:Error); test:assertEquals((csvb1br7).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord8Array|csv:Error csvb1br8 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord8Array|csv:Error csvb1br8 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertTrue(csvb1br8 is csv:Error); test:assertEquals((csvb1br8).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord9Array|csv:Error csvb1br9 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord9Array|csv:Error csvb1br9 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br9, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - BooleanRecord9Array|csv:Error csvb2br9 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord9Array|csv:Error csvb2br9 = csv:parseString(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br9, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - BooleanRecord9Array|csv:Error csvb3br9 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord9Array|csv:Error csvb3br9 = csv:parseString(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br9, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: ()}, {b1: true, b2: true, b3: false} ]); - BooleanRecord9Array|csv:Error csvb4br9 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord9Array|csv:Error csvb4br9 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br9, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - BooleanRecord9Array|csv:Error csvb5br9 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord9Array|csv:Error csvb5br9 = csv:parseString(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br9, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - BooleanRecord9Array|csv:Error csvb6br9 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord9Array|csv:Error csvb6br9 = csv:parseString(csvStringWithBooleanValues6, {}); test:assertTrue(csvb6br9 is csv:Error); test:assertEquals((csvb6br9).message(), common:generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord9Array|csv:Error csvb7br9 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord9Array|csv:Error csvb7br9 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br9, [ {b1, b2, b3: (), b4} ]); - BooleanRecord10Array|csv:Error csvb1br10 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord10Array|csv:Error csvb1br10 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br10, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - BooleanRecord10Array|csv:Error csvb2br10 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord10Array|csv:Error csvb2br10 = csv:parseString(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br10, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - BooleanRecord10Array|csv:Error csvb3br10 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord10Array|csv:Error csvb3br10 = csv:parseString(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br10, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false}, {b1: true, b2: true, b3: false} ]); - BooleanRecord10Array|csv:Error csvb4br10 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord10Array|csv:Error csvb4br10 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br10, [ {b1: true, b4: false}, {b1: true, b4: false} ]); - BooleanRecord10Array|csv:Error csvb5br10 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord10Array|csv:Error csvb5br10 = csv:parseString(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br10, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - BooleanRecord10Array|csv:Error csvb6br10 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord10Array|csv:Error csvb6br10 = csv:parseString(csvStringWithBooleanValues6, {}); test:assertEquals(csvb6br10, [ {} ]); - BooleanRecord10Array|csv:Error csvb7br10 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord10Array|csv:Error csvb7br10 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br10, [ {b1, b2, b4} ]); - BooleanRecord11Array|csv:Error csvb1br11 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord11Array|csv:Error csvb1br11 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br11, [ {b1: true, b2: false, b3: true, b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: false, defaultableField: "", nillableField: ()}, @@ -343,170 +343,170 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType3() { @test:Config function testFromCsvStringWithTypeForStringAndRecordAsExpectedType4() { - BooleanRecord11Array|csv:Error csvb2br11 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord11Array|csv:Error csvb2br11 = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); test:assertEquals(csvb2br11, [ {b1: true, b2: false, b3: true, b4: false, b5: true, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: false, b5: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord11Array|csv:Error csvb3br11 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord11Array|csv:Error csvb3br11 = csv:parseString(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br11, [ {b1: true, b2: false, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b2: true, b3: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord11Array|csv:Error csvb4br11 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord11Array|csv:Error csvb4br11 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br11, [ {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord11Array|csv:Error csvb5br11 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord11Array|csv:Error csvb5br11 = csv:parseString(csvStringWithBooleanValues5, {outputWithHeaders: false}); test:assertEquals(csvb5br11, [ {b1: true, b2: false, b3: true, b4: "2", defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: "3", defaultableField: "", nillableField: ()} ]); - BooleanRecord11Array|csv:Error csvb6br11 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord11Array|csv:Error csvb6br11 = csv:parseString(csvStringWithBooleanValues6, {}); test:assertTrue(csvb6br11 is csv:Error); test:assertEquals((csvb6br11).message(), common:generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord11Array|csv:Error csvb7br11 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord11Array|csv:Error csvb7br11 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br11, [ {b1, b2, b3, b4, defaultableField: "", nillableField: ()} ]); - BooleanRecord12Array|csv:Error csvb1br12 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord12Array|csv:Error csvb1br12 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true}); test:assertTrue(csvb1br12 is csv:Error); test:assertEquals((csvb1br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord13Array|csv:Error csvb1br13 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord13Array|csv:Error csvb1br13 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br13, [ {b1: true, b2: false, b3: true, b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord13Array|csv:Error csvb2br13 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord13Array|csv:Error csvb2br13 = csv:parseString(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br13, [ {b1: true, b2: false, b3: true, b4: false, b5: true, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: false, b5: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord13Array|csv:Error csvb3br13 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord13Array|csv:Error csvb3br13 = csv:parseString(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br13, [ {b1: true, b2: false, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: "()", defaultableField: "", nillableField: ()}, {b1: true, b2: true, b3: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord13Array|csv:Error csvb4br13 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord13Array|csv:Error csvb4br13 = csv:parseString(csvStringWithBooleanValues4, {outputWithHeaders: true}); test:assertEquals(csvb4br13, [ {b1: true, b2: "()", b3: "()", b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: "()", b3: "null", b4: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord13Array|csv:Error csvb5br13 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord13Array|csv:Error csvb5br13 = csv:parseString(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br13, [ {b1: true, b2: false, b3: true, b4: "2", defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: "3", defaultableField: "", nillableField: ()} ]); - BooleanRecord13Array|csv:Error csvb6br13 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord13Array|csv:Error csvb6br13 = csv:parseString(csvStringWithBooleanValues6, {}); test:assertEquals(csvb6br13, [ {b2: "()", b3: "()", defaultableField: "", nillableField: ()} ]); - BooleanRecord13Array|csv:Error csvb7br13 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord13Array|csv:Error csvb7br13 = csv:parseString(csvStringWithBooleanValues7, {outputWithHeaders: true}); test:assertEquals(csvb7br13, [ {b1, b2, b3: "()", b4, defaultableField: "", nillableField: ()} ]); - BooleanRecord14Array|csv:Error csvb7br14 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord14Array|csv:Error csvb7br14 = csv:parseString(csvStringWithBooleanValues6, {}); test:assertTrue(csvb7br14 is csv:Error); test:assertEquals((csvb7br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); } @test:Config function testFromCsvStringWithTypeForStringAndRecordAsExpectedType5() { - BooleanRecord15Array|csv:Error csvb1br15 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord15Array|csv:Error csvb1br15 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertTrue(csvb1br15 is csv:Error); test:assertEquals((csvb1br15).message(), common:generateErrorMessageForInvalidCast("true", "int")); - BooleanRecord15Array|csv:Error csvb6br15 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord15Array|csv:Error csvb6br15 = csv:parseString(csvStringWithBooleanValues6, {}); test:assertTrue(csvb6br15 is csv:Error); test:assertEquals((csvb6br15).message(), common:generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord15Array|csv:Error csvb7br15 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord15Array|csv:Error csvb7br15 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertTrue(csvb7br15 is csv:Error); test:assertEquals((csvb7br15).message(), common:generateErrorMessageForInvalidCast("true", "int")); - BooleanRecord16Array|csv:Error csvb1br16 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord16Array|csv:Error csvb1br16 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br16, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - BooleanRecord16Array|csv:Error csvb2br16 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord16Array|csv:Error csvb2br16 = csv:parseString(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br16, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - BooleanRecord16Array|csv:Error csvb3br16 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord16Array|csv:Error csvb3br16 = csv:parseString(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br16, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: ()}, {b1: true, b2: true, b3: false} ]); - BooleanRecord16Array|csv:Error csvb4br16 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord16Array|csv:Error csvb4br16 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br16, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - BooleanRecord16Array|csv:Error csvb5br16 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord16Array|csv:Error csvb5br16 = csv:parseString(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br16, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - BooleanRecord16Array|csv:Error csvb6br16 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord16Array|csv:Error csvb6br16 = csv:parseString(csvStringWithBooleanValues6, {}); test:assertEquals(csvb6br16, [ {b2: (), b3: ()} ]); - BooleanRecord16Array|csv:Error csvb7br16 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord16Array|csv:Error csvb7br16 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br16, [ {b1, b2, b3: (), b4} ]); - BooleanRecord17Array|csv:Error csvb1br17 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord17Array|csv:Error csvb1br17 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br17, [{}, {}, {}]); - BooleanRecord17Array|csv:Error csvb4br17 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord17Array|csv:Error csvb4br17 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br17, [{}, {}]); - BooleanRecord17Array|csv:Error csvb6br17 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord17Array|csv:Error csvb6br17 = csv:parseString(csvStringWithBooleanValues6, {}); test:assertEquals(csvb6br17, [{}]); - BooleanRecord17Array|csv:Error csvb7br17 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord17Array|csv:Error csvb7br17 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br17, [{}]); - BooleanRecord18Array|csv:Error csvb1br18 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord18Array|csv:Error csvb1br18 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br18, [{b2: false}, {b2: false}, {b2: false}]); - BooleanRecord18Array|csv:Error csvb4br18 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord18Array|csv:Error csvb4br18 = csv:parseString(csvStringWithBooleanValues4, {}); test:assertTrue(csvb4br18 is csv:Error); test:assertEquals((csvb4br18).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanRecord18Array|csv:Error csvb6br18 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord18Array|csv:Error csvb6br18 = csv:parseString(csvStringWithBooleanValues6, {}); test:assertTrue(csvb6br18 is csv:Error); test:assertEquals((csvb6br18).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); - BooleanRecord18Array|csv:Error csvb7br18 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord18Array|csv:Error csvb7br18 = csv:parseString(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br18, [{b2, b3: ()}]); } diff --git a/ballerina-tests/type-compatible-tests/Ballerina.toml b/ballerina-tests/type-compatible-tests/Ballerina.toml index cfdb846..d7661d9 100644 --- a/ballerina-tests/type-compatible-tests/Ballerina.toml +++ b/ballerina-tests/type-compatible-tests/Ballerina.toml @@ -13,4 +13,4 @@ version = "0.1.0" graalvmCompatible = true [build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" +graalvmBuildOptions = "-H:+IncludeAllLocales" 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 35bf23e..bacada9 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 @@ -35,57 +35,57 @@ function testFromCsvStringWithTypeCompatibility() { ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3} `; - AnydataArray1Array|csv:Error v3anyd1a = csv:parseStringToList(value); + AnydataArray1Array|csv:Error v3anyd1a = csv:parseString(value); test:assertEquals(v3anyd1a, [ [i1, i2, s1, s2, b1, b2, n1, n2, 2.234, -3.21, 2.234, -3.21, b1, 2.234, b2, -3.21], [i1, i2, s1, s2, b1, b2, n1, n2, 2.234, -3.21, 2.234, -3.21, b1, 2.234, b2, -3.21] ]); - CustomRecord27Array|csv:Error vcr27a = csv:parseStringToRecord(value, {}, CustomRecord27Array); + CustomRecord27Array|csv:Error vcr27a = csv:parseString(value, {}, CustomRecord27Array); test:assertEquals(vcr27a, [ {i1, s1, b1, n1, f1, d1, a1: 2.234, j1: b1, defaultableField: "", nillableField: null, i2: "-2", s2: "", b2: "false", n2: "()", f2: "-3.21", d2: "-3.21", j2: "false", a2: "-3.21"}, {i1, s1, b1, n1, f1, d1, a1: 2.234, j1: b1, defaultableField: "", nillableField: null, i2: "-2", s2: "", b2: "false", n2: "()", f2: "-3.21", d2: "-3.21", j2: "false", a2: "-3.21"} ]); - CustomRecord27Array|csv:Error v2cr27a = csv:parseStringToRecord(value2, {}, CustomRecord27Array); + CustomRecord27Array|csv:Error v2cr27a = csv:parseString(value2, {}, CustomRecord27Array); test:assertEquals(v2cr27a, [ {i1, s1, b1, n1, f1, d1, a1: 2.234, j1: b1, defaultableField: "", nillableField: null, s2, j2: "false", a2: "-3.21", s3} ]); - CustomRecord27Array|csv:Error v3cr27a = csv:parseStringToRecord(value3, {}); + CustomRecord27Array|csv:Error v3cr27a = csv:parseString(value3, {}); test:assertEquals(v3cr27a, [ {i1, s1, b1, n1, f1, d1, a1: 2.234, j1: b1, defaultableField: "", nillableField: null, s2, s3} ]); - AnydataMapArray|csv:Error vanydma = csv:parseStringToRecord(value); + AnydataMapArray|csv:Error vanydma = csv:parseString(value); test:assertEquals(vanydma, [ {i1, i2, s1, s2, b1, b2, n1, n2, f1: 2.234, f2: -3.21, d1: 2.234, d2: -3.21, j1: b1, a1: 2.234, j2: false, a2: -3.21}, {i1, i2, s1, s2, b1, b2, n1, n2, f1: 2.234, f2: -3.21, d1: 2.234, d2: -3.21, j1: b1, a1: 2.234, j2: false, a2: -3.21} ]); - JsonMapArray|csv:Error vjma = csv:parseStringToRecord(value); + JsonMapArray|csv:Error vjma = csv:parseString(value); test:assertEquals(vjma, [ {i1, i2, s1, s2, b1, b2, n1, n2, f1: 2.234, f2: -3.21, d1: 2.234, d2: -3.21, j1: b1, a1: 2.234, j2: false, a2: -3.21}, {i1, i2, s1, s2, b1, b2, n1, n2, f1: 2.234, f2: -3.21, d1: 2.234, d2: -3.21, j1: b1, a1: 2.234, j2: false, a2: -3.21} ]); - StringMapArray|csv:Error vsma = csv:parseStringToRecord(value); + StringMapArray|csv:Error vsma = csv:parseString(value); test:assertEquals(vsma, [ {i1: "1", s1: "string", b1: "true", n1: "()", f1: "2.234", d1: "2.234", a1: "2.234", j1: "true", i2: "-2", s2: "", b2: "false", n2: "()", f2: "-3.21", d2: "-3.21", j2: "false", a2: "-3.21"}, {i1: "1", s1: "string", b1: "true", n1: "()", f1: "2.234", d1: "2.234", a1: "2.234", j1: "true", i2: "-2", s2: "", b2: "false", n2: "()", f2: "-3.21", d2: "-3.21", j2: "false", a2: "-3.21"} ]); - CustomTuple7Array|csv:Error v2ct7a = csv:parseStringToList(value2); + CustomTuple7Array|csv:Error v2ct7a = csv:parseString(value2); test:assertEquals(v2ct7a, [ [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3, "false", "-3.21"] ]); - CustomTuple7Array|csv:Error v3ct7a = csv:parseStringToList(value3); + CustomTuple7Array|csv:Error v3ct7a = csv:parseString(value3); test:assertEquals(v3ct7a, [ [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3] ]); - [float, decimal, string][]|csv:Error mrrta = csv:parseStringToList(string `a, b,c + [float, decimal, string][]|csv:Error mrrta = csv:parseString(string `a, b,c 1.23, 1.23, 1.23 0,0,0 0.0,0.0,0.0 @@ -97,7 +97,7 @@ function testFromCsvStringWithTypeCompatibility() { [-1.2, -1.2, "-1.2"] ]); - [float, decimal, string, int][]|csv:Error m2rrta = csv:parseStringToList(string `a, b,c,d + [float, decimal, string, int][]|csv:Error m2rrta = csv:parseString(string `a, b,c,d 1, 1, 1,1 0,0,0,0 -1,-1,-1,-1`); @@ -107,12 +107,12 @@ function testFromCsvStringWithTypeCompatibility() { [-1, -1, "-1", -1] ]); - [int...][]|csv:Error m3rrta = csv:parseStringToList(string `a, b,c,d + [int...][]|csv:Error m3rrta = csv:parseString(string `a, b,c,d 1.2, abc, true,1.0`); test:assertTrue(m3rrta is csv:Error); test:assertEquals((m3rrta).message(), common:generateErrorMessageForInvalidCast("1.2", "int")); - [boolean|int, int|boolean][]|csv:Error m4rrta = csv:parseStringToList(string `a, b + [boolean|int, int|boolean][]|csv:Error m4rrta = csv:parseString(string `a, b 1, 1 0,0`); test:assertEquals(m4rrta, [ @@ -120,7 +120,7 @@ function testFromCsvStringWithTypeCompatibility() { [0, 0] ]); - record {|int...;|}[]|csv:Error irrma = csv:parseStringToRecord(string ` + record {|int...;|}[]|csv:Error irrma = csv:parseString(string ` a, b, c 1, a, 2.3 1, -2, true @@ -131,7 +131,7 @@ function testFromCsvStringWithTypeCompatibility() { {b: i2} ]); - record {|()...;|}[]|csv:Error nrrma = csv:parseStringToRecord(string ` + record {|()...;|}[]|csv:Error nrrma = csv:parseString(string ` a, b, c 1, a, () 1, null, () @@ -142,7 +142,7 @@ function testFromCsvStringWithTypeCompatibility() { {} ]); - record {|decimal...;|}[]|csv:Error drra = csv:parseStringToRecord(string `a, b, c + record {|decimal...;|}[]|csv:Error drra = csv:parseString(string `a, b, c 2.234, invalid , 1 ${f2}, 0, 2.3d invalid, ${d2}, ${f3}`); @@ -153,7 +153,7 @@ function testFromCsvStringWithTypeCompatibility() { {b: -3.21d, c: f3} ]); - record {|string...;|}[]|csv:Error srra = csv:parseStringToRecord(string `a, b, c + record {|string...;|}[]|csv:Error srra = csv:parseString(string `a, b, c 1, a, 2.3 1, -2, true hello, -2, hello`); @@ -164,7 +164,7 @@ function testFromCsvStringWithTypeCompatibility() { {a: "hello", b: "-2", c: "hello"} ]); - record {|float...;|}[]|csv:Error frra = csv:parseStringToRecord(string `a, b, c + record {|float...;|}[]|csv:Error frra = csv:parseString(string `a, b, c 1.2, invalid , 1 ${d2}, ${d3}, true ${d4}, ${f2}, 0.0`); @@ -174,7 +174,7 @@ function testFromCsvStringWithTypeCompatibility() { {a: d4, b: f2, c: 0.0} ]); - record {float a; decimal b; string c;}[]|csv:Error mrra = csv:parseStringToRecord(string `a, b,c + record {float a; decimal b; string c;}[]|csv:Error mrra = csv:parseString(string `a, b,c 1.23, 1.23, 1.23 0,0,0 0.0,0.0,0.0 @@ -186,7 +186,7 @@ function testFromCsvStringWithTypeCompatibility() { {a: -1.2, b: -1.2, c: "-1.2"} ]); - record {|float a; decimal b; string c; int d;|}[]|csv:Error m2rra = csv:parseStringToRecord(string `a, b,c,d + record {|float a; decimal b; string c; int d;|}[]|csv:Error m2rra = csv:parseString(string `a, b,c,d 1, 1, 1,1 0,0,0,0 -1,-1,-1,-1`); @@ -196,7 +196,7 @@ function testFromCsvStringWithTypeCompatibility() { {a: -1, b: -1, c: "-1", d: -1} ]); - record {int d;}[]|csv:Error m3rra = csv:parseStringToRecord(string `a, b,c,d + record {int d;}[]|csv:Error m3rra = csv:parseString(string `a, b,c,d 1.2, abc, true,1.0`); test:assertTrue(m3rra is csv:Error); test:assertEquals((m3rra).message(), common:generateErrorMessageForInvalidCast("1.0", "int")); @@ -207,7 +207,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:parseStringToRecord(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 \""}]); } @@ -216,25 +216,53 @@ function testSpaceBetweendData() { function testParseBytes() returns error? { byte[] csvBytes = check io:fileReadBytes(filepath); - record{}[]|csv:Error rec = csv:parseBytesToRecord(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}, {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}] ); - string[][]|csv:Error rec2 = csv:parseBytesToList(csvBytes, {}); + rec = csv:parseBytes(csvBytes, {outputWithHeaders: true}); + 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}, + {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}] + ); + + string[][]|csv:Error rec2 = csv:parseBytes(csvBytes, {}); test:assertEquals(rec2, [ ["Hello World", "\"Hello World\"", "Hello World", "2"], ["Hello World", "\"Hello World\"", "Hello World", "2"], ["Hello World", "\"Hello World\"", "Hello World", "2"] ]); - int[][]|csv:Error rec3 = csv:parseBytesToList(csvBytes, {}); + rec2 = csv:parseBytes(csvBytes, {outputWithHeaders: true}); + test:assertEquals(rec2, [ + ["a", "b", "c d", "e"], + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"] + ]); + + rec2 = csv:parseBytes(csvBytes, {outputWithHeaders: true, header: 1}); + test:assertEquals(rec2, [ + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"] + ]); + + rec2 = csv:parseBytes(csvBytes, { header: 1}); + test:assertEquals(rec2, [ + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"] + ]); + + int[][]|csv:Error rec3 = csv:parseBytes(csvBytes, {}); test:assertTrue(rec3 is csv:Error); test:assertEquals(( rec3).message(), common:generateErrorMessageForInvalidCast("Hello World", "int")); - record{int a;}[]|csv:Error rec4 = csv:parseBytesToRecord(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")); } @@ -242,7 +270,15 @@ function testParseBytes() returns error? { @test:Config function testParseStream() returns error? { stream csvByteStream = check io:fileReadBlocksAsStream(filepath); - record{}[]|csv:Error rec = csv:parseStreamToRecord(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}, + {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}] + ); + + csvByteStream = check io:fileReadBlocksAsStream(filepath); + rec = csv:parseStream(csvByteStream, {outputWithHeaders: true}); 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}, @@ -250,7 +286,7 @@ function testParseStream() returns error? { ); csvByteStream = check io:fileReadBlocksAsStream(filepath); - string[][]|csv:Error rec2 = csv:parseStreamToList(csvByteStream, {}); + string[][]|csv:Error rec2 = csv:parseStream(csvByteStream, {}); test:assertEquals(rec2, [ ["Hello World", "\"Hello World\"", "Hello World", "2"], ["Hello World", "\"Hello World\"", "Hello World", "2"], @@ -258,13 +294,37 @@ function testParseStream() returns error? { ]); csvByteStream = check io:fileReadBlocksAsStream(filepath); - record{int a;}[]|csv:Error rec3 = csv:parseStreamToRecord(csvByteStream, {}); + rec2 = csv:parseStream(csvByteStream, {header: 1, outputWithHeaders: true}); + test:assertEquals(rec2, [ + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"] + ]); + + csvByteStream = check io:fileReadBlocksAsStream(filepath); + rec2 = csv:parseStream(csvByteStream, {outputWithHeaders: true}); + test:assertEquals(rec2, [ + ["a", "b", "c d", "e"], + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"] + ]); + + csvByteStream = check io:fileReadBlocksAsStream(filepath); + rec2 = csv:parseStream(csvByteStream, {header: 1}); + test:assertEquals(rec2, [ + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"] + ]); + + csvByteStream = check io:fileReadBlocksAsStream(filepath); + 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")); csvByteStream = check io:fileReadBlocksAsStream(filepath); - int[][]|csv:Error rec4 = csv:parseStreamToList(csvByteStream, {}); + int[][]|csv:Error rec4 = csv:parseStream(csvByteStream, {}); test:assertTrue(rec4 is csv:Error); test:assertEquals(( rec4).message(), "Error occurred while reading the stream: " + common:generateErrorMessageForInvalidCast("Hello World", "int")); @@ -274,11 +334,11 @@ function testParseStream() returns error? { function testErrorParseBytes() returns error? { byte[] csvBytes = check io:fileReadBytes(errorFilepath); - int[][]|csv:Error rec3 = csv:parseBytesToList(csvBytes, {}); + int[][]|csv:Error rec3 = csv:parseBytes(csvBytes, {}); test:assertTrue(rec3 is csv:Error); test:assertTrue(( rec3).message().includes("cannot be cast into")); - record{int a;}[]|csv:Error rec4 = csv:parseBytesToRecord(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")); } @@ -288,12 +348,12 @@ function testErrorParseStream() returns error? { byte[] csvBytes = check io:fileReadBytes(errorFilepath); stream csvByteStream = check io:fileReadBlocksAsStream(errorFilepath); - record{int a;}[]|csv:Error rec3 = csv:parseStreamToRecord(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")); csvByteStream = check io:fileReadBlocksAsStream(errorFilepath); - int[][]|csv:Error rec4 = csv:parseStreamToList(csvByteStream, {}); + int[][]|csv:Error rec4 = csv:parseStream(csvByteStream, {}); test:assertTrue(rec4 is csv:Error); test:assertTrue(( rec4).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 250dc69..cedf454 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 @@ -22,432 +22,422 @@ import ballerina/test; function testFromCsvWithTypeFunctionWithTypeCompatibility() { var value = {i1, i2, s1, s2, b1, b2, n1, n2, f1, f2, d1, d2, j1: b1, a1: d1, j2: b2, a2: d2}; - CustomRecord27Array|csv:Error vcr27a = csv:parseRecordAsRecordType([value, value, value], {}, CustomRecord27Array); - test:assertEquals(vcr27a , [ - {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()}, - {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()}, - {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()} - ]); - - AnydataMapArray|csv:Error vanydma = csv:parseRecordAsRecordType([value, value, value], {}, AnydataMapArray); - test:assertEquals(vanydma , [ - value, - value, - value - ]); - - JsonMapArray|csv:Error vjma = csv:parseRecordAsRecordType([value, value, value], {}, JsonMapArray); - test:assertEquals(vjma , [ - value, - value, - value - ]); - - record{|int...;|}[]|csv:Error irrma = csv:parseRecordAsRecordType([{"a": 1}, {"a": i1, "b": i2}, {"a": i1, "b": i2, "c": s1}]); - test:assertEquals(irrma , [ - {a:1}, - {a: i1, b: i2}, - {a: i1, b: i2} - ]); - - record{|decimal...;|}[]|csv:Error drra = csv:parseRecordAsRecordType([{"a": d1}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1, "d": f3}]); - test:assertTrue(drra is record{|decimal...;|}[]); - test:assertEquals(drra , [ - {a: d1}, - {a: d2, b: d3}, - {a: d4, b: -3.21d, d: f3} - ]); - - record{|string...;|}[]|csv:Error srra = csv:parseRecordAsRecordType([{"a": "string"}, {"c": 1, "a": s1, "b": s2}, {"a": b1, "b": s3, "c": d1}]); - test:assertEquals(srra , [ - {a: "string"}, - {a: s1, b: s2}, - {b: s3} - ]); - - record{|float...;|}[]|csv:Error frra = csv:parseRecordAsRecordType([{"a": 1.2, "b": 1.2f}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1}]); - test:assertEquals(frra , [ - {a: 1.2, b: 1.2}, - {a: d2, b: d3}, - {a: d4, b: f2} - ]); - - record{|float a; decimal b;|}[]|csv:Error fdc1a = csv:parseRecordAsRecordType([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); - test:assertEquals(fdc1a , [ - {a: d1, b: d2}, - {a: f1, b: f2}, - {a: d2, b: f2}, - {a: f2, b: d2} - ]); - - record{|float a; decimal ...;|}[]|csv:Error fdc2a = csv:parseRecordAsRecordType([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); - test:assertEquals(fdc2a , [ - {a: d1, b: d2}, - {a: f1, b: f2}, - {a: d2, b: f2}, - {a: f2, b: d2} - ]); - - record{|decimal b; float...;|}[]|csv:Error fdc3a = csv:parseRecordAsRecordType([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); - test:assertEquals(fdc3a , [ - {a: d1, b: d2}, - {a: f1, b: f2}, - {a: d2, b: f2}, - {a: f2, b: d2} - ]); + CustomRecord27Array|csv:Error vcr27a = csv:transform([value, value, value], {}, CustomRecord27Array); + test:assertEquals(vcr27a, [ + {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()}, + {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()}, + {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()} + ]); + + AnydataMapArray|csv:Error vanydma = csv:transform([value, value, value], {}, AnydataMapArray); + test:assertEquals(vanydma, [ + value, + value, + value + ]); + + JsonMapArray|csv:Error vjma = csv:transform([value, value, value], {}, JsonMapArray); + test:assertEquals(vjma, [ + value, + value, + value + ]); + + record {|int...;|}[]|csv:Error irrma = csv:transform([{"a": 1}, {"a": i1, "b": i2}, {"a": i1, "b": i2, "c": s1}]); + test:assertEquals(irrma, [ + {a: 1}, + {a: i1, b: i2}, + {a: i1, b: i2} + ]); + + record {|decimal...;|}[]|csv:Error drra = csv:transform([{"a": d1}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1, "d": f3}]); + test:assertTrue(drra is record {|decimal...;|}[]); + test:assertEquals(drra, [ + {a: d1}, + {a: d2, b: d3}, + {a: d4, b: -3.21d, d: f3} + ]); + + record {|string...;|}[]|csv:Error srra = csv:transform([{"a": "string"}, {"c": 1, "a": s1, "b": s2}, {"a": b1, "b": s3, "c": d1}]); + test:assertEquals(srra, [ + {a: "string"}, + {a: s1, b: s2}, + {b: s3} + ]); + + record {|float...;|}[]|csv:Error frra = csv:transform([{"a": 1.2, "b": 1.2f}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1}]); + test:assertEquals(frra, [ + {a: 1.2, b: 1.2}, + {a: d2, b: d3}, + {a: d4, b: f2} + ]); + + record {|float a; decimal b;|}[]|csv:Error fdc1a = csv:transform([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + test:assertEquals(fdc1a, [ + {a: d1, b: d2}, + {a: f1, b: f2}, + {a: d2, b: f2}, + {a: f2, b: d2} + ]); + + record {|float a; decimal...;|}[]|csv:Error fdc2a = csv:transform([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + test:assertEquals(fdc2a, [ + {a: d1, b: d2}, + {a: f1, b: f2}, + {a: d2, b: f2}, + {a: f2, b: d2} + ]); + + record {|decimal b; float...;|}[]|csv:Error fdc3a = csv:transform([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + test:assertEquals(fdc3a, [ + {a: d1, b: d2}, + {a: f1, b: f2}, + {a: d2, b: f2}, + {a: f2, b: d2} + ]); } type A decimal|int; + type A2 int|decimal; -type B readonly & A | C; -type B2 readonly & C | readonly & A2; + +type B readonly & A|C; + +type B2 readonly & C|readonly & A2; + type C string|boolean; + type C2 boolean|string; @test:Config function testFromCsvWithIntersectionTypeCompatibility2() { - record{ - readonly & int a; - readonly & string b; - (readonly & boolean) | (readonly & decimal) c; - }[]|csv:Error r1a = csv:parseStringToRecord( string `a,b,c + record { + readonly & int a; + readonly & string b; + (readonly & boolean)|(readonly & decimal) c; + }[]|csv:Error r1a = csv:parseString(string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r1a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); + test:assertEquals(r1a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); - record{A a; B b; C c;}[]|csv:Error r2a = csv:parseStringToRecord( string `a,b,c + record {A a; B b; C c;}[]|csv:Error r2a = csv:parseString(string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r2a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); + test:assertEquals(r2a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); - record{A2 a; B2 b; C2 c;}[]|csv:Error r3a = csv:parseStringToRecord( string `a,b,c + record {A2 a; B2 b; C2 c;}[]|csv:Error r3a = csv:parseString(string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r3a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); + test:assertEquals(r3a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); - record{|A2 a; B2 b; C2...;|}[]|csv:Error r4a = csv:parseStringToRecord( string ` + record {|A2 a; B2 b; C2...;|}[]|csv:Error r4a = csv:parseString(string ` a,b,c,d 1,string,true,string 2,string2,false,string2 3,string3,true,string3`, {header: 1}); - test:assertEquals(r4a , [ - {a: 1, b: "string", c: true, d: "string"}, - {a: 2, b: "string2", c: false, d: "string2"}, - {a: 3, b: "string3", c: true, d: "string3"} - ]); + test:assertEquals(r4a, [ + {a: 1, b: "string", c: true, d: "string"}, + {a: 2, b: "string2", c: false, d: "string2"}, + {a: 3, b: "string3", c: true, d: "string3"} + ]); - record{|C2...;|}[]|csv:Error r5a = csv:parseStringToRecord( string `a,b,c,d + record {|C2...;|}[]|csv:Error r5a = csv:parseString(string `a,b,c,d 1,string,true,string 2,string2,false,string2 3,string3,true,string3`); - test:assertEquals(r5a , [ - {a: "1", b: "string", c: true, d: "string"}, - {a: "2", b: "string2", c: false, d: "string2"}, - {a: "3", b: "string3", c: true, d: "string3"} - ]); + test:assertEquals(r5a, [ + {a: "1", b: "string", c: true, d: "string"}, + {a: "2", b: "string2", c: false, d: "string2"}, + {a: "3", b: "string3", c: true, d: "string3"} + ]); - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error r16a = - csv:parseStringToList( string `a,b,c + [readonly & int, readonly & string, (readonly & boolean)|(readonly & decimal)][]|csv:Error r16a = + csv:parseString(string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r16a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + test:assertEquals(r16a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); - [A, B, C][]|csv:Error r17a = csv:parseStringToList( - string `a,b,c + [A, B, C][]|csv:Error r17a = csv:parseString( + string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r17a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + test:assertEquals(r17a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); - [A2, B2, C2][]|csv:Error r18a = csv:parseStringToList( - string `a,b,c + [A2, B2, C2][]|csv:Error r18a = csv:parseString( + string `a,b,c 1,string,true 2,string2,false 3,string3,true`); - test:assertEquals(r18a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); + test:assertEquals(r18a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); - [A2, B2, C2...][]|csv:Error r19a = csv:parseStringToList( - string `a,b,c,d + [A2, B2, C2...][]|csv:Error r19a = csv:parseString( + string `a,b,c,d 1,string,true,string 2,string2,false,string2 3,string3,true,string3`); - test:assertEquals(r19a , [ - [1, "string", true, "string"], - [2, "string2", false, "string2"], - [3, "string3", true, "string3"] - ]); + test:assertEquals(r19a, [ + [1, "string", true, "string"], + [2, "string2", false, "string2"], + [3, "string3", true, "string3"] + ]); - [C2...][]|csv:Error r20a = csv:parseStringToList( - string `a,b,c,d + [C2...][]|csv:Error r20a = csv:parseString( + string `a,b,c,d 1,string,true,string 2,string2,false,string2 3,string3,true,string3`); - test:assertEquals(r20a, [["1", "string",true, "string"], - ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); - - - record{A a; B b; C c;}[]|csv:Error rt2a = csv:parseRecordAsRecordType( - [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); - - test:assertEquals(rt2a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{ - readonly & int a; - readonly & string b; - (readonly & boolean) | (readonly & decimal) c; - }[]|csv:Error rt1a = csv:parseRecordAsRecordType( - [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); - - test:assertEquals(rt1a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{A2 a; B2 b; C2 c;}[]|csv:Error rt3a = csv:parseRecordAsRecordType( - [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); - - test:assertEquals(rt3a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{|A2 a; B2 b; C2...;|}[]|csv:Error rt4a = csv:parseRecordAsRecordType( - [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}]); - - test:assertEquals(rt4a , [ - {a: 1, b: "string", c: true, d: "string"}, - {a: 2, b: "string2", c: false, d: "string2"}, - {a: 3, b: "string3", c: true, d: "string3"} - ]); - - record{|C2...;|}[]|csv:Error rt5a = csv:parseRecordAsRecordType( - [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}]); - - test:assertEquals(rt5a , [ - {b: "string", c: true, d: "string"}, - {b: "string2", c: false, d: "string2"}, - {b: "string3", c: true, d: "string3"} - ]); - - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error rt6a = - csv:parseRecordAsListType( - [{"a": 1, "b": "string", "c": true}, - {"a": 2, "b": "string2", "c": false}, - {"a": 3, "b": "string3", "c": true} - ], ["a", "b", "c"]); - - test:assertEquals(rt6a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); - - [A, B, C][]|csv:Error rt7a = csv:parseRecordAsListType( - [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] - , ["a", "b", "c"]); - - test:assertEquals(rt7a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); - - [A2, B2, C2][]|csv:Error rt8a = csv:parseRecordAsListType( - [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] - , ["a", "b", "c"]); - - test:assertEquals(rt8a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); - - [A2, B2, C2...][]|csv:Error rt9a = csv:parseRecordAsListType( - [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] - , ["a", "b", "c", "d"]); - - test:assertEquals(rt9a , [ - [1, "string", true, "string"], - [2, "string2", false, "string2"], - [3, "string3", true, "string3"] - ]); - - [C2...][]|csv:Error rt10a = csv:parseRecordAsListType( - [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] - , ["a", "b", "c", "d"]); + test:assertEquals(r20a, [ + ["1", "string", true, "string"], + ["2", "string2", false, "string2"], + ["3", "string3", true, "string3"] + ]); + + record {A a; B b; C c;}[]|csv:Error rt2a = csv:transform( + [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); + + test:assertEquals(rt2a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record { + readonly & int a; + readonly & string b; + (readonly & boolean)|(readonly & decimal) c; + }[]|csv:Error rt1a = csv:transform( + [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); + + test:assertEquals(rt1a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {A2 a; B2 b; C2 c;}[]|csv:Error rt3a = csv:transform( + [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); + + test:assertEquals(rt3a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {|A2 a; B2 b; C2...;|}[]|csv:Error rt4a = 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"}]); + + test:assertEquals(rt4a, [ + {a: 1, b: "string", c: true, d: "string"}, + {a: 2, b: "string2", c: false, d: "string2"}, + {a: 3, b: "string3", c: true, d: "string3"} + ]); + + record {|C2...;|}[]|csv:Error rt5a = 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"}]); + + test:assertEquals(rt5a, [ + {b: "string", c: true, d: "string"}, + {b: "string2", c: false, d: "string2"}, + {b: "string3", c: true, d: "string3"} + ]); + + [readonly & int, readonly & string, (readonly & boolean)|(readonly & decimal)][]|csv:Error rt6a = + csv:transform( + [ + {"a": 1, "b": "string", "c": true}, + {"a": 2, "b": "string2", "c": false}, + {"a": 3, "b": "string3", "c": true} + ], {headersOrder: ["a", "b", "c"]}); + + test:assertEquals(rt6a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); + + [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"]}); + + test:assertEquals(rt7a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); + + [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"]}); + + test:assertEquals(rt8a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); + + [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"]}); + + test:assertEquals(rt9a, [ + [1, "string", true, "string"], + [2, "string2", false, "string2"], + [3, "string3", true, "string3"] + ]); + + [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"]}); test:assertTrue(rt10a is csv:Error); test:assertEquals((rt10a).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "0", "type_compatible_tests:C2")); - record{ - readonly & int a; - readonly & string b; - (readonly & boolean) | (readonly & decimal) c; - }[]|csv:Error rt11a = csv:parseListAsRecordType( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); - - test:assertEquals(rt11a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{A a; B b; C c;}[]|csv:Error rt12a = csv:parseListAsRecordType( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); - - test:assertEquals(rt12a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{A a; B b; C c;}[]|csv:Error rt12a_2 = csv:parseListAsRecordType( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"], {stringConversion: false}); - - test:assertTrue(rt12a_2 is csv:Error); - test:assertEquals((rt12a_2).message(), - common:generateErrorMessageForInvalidFieldType("1", "a")); - - record{string|decimal a; B b; C c;}[]|csv:Error rt12a_3 = csv:parseListAsRecordType( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); - - test:assertEquals(rt12a_3 , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{A2 a; B2 b; C2 c;}[]|csv:Error rt13a = csv:parseListAsRecordType( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); - - test:assertEquals(rt13a , [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} - ]); - - record{|A2 a; B2 b; C2...;|}[]|csv:Error rt14a = csv:parseListAsRecordType( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] - , ["a", "b", "c", "d"]); - - test:assertEquals(rt14a , [ - {a: 1, b: "string", c: true, d: "string"}, - {a: 2, b: "string2", c: false, d: "string2"}, - {a: 3, b: "string3", c: true, d: "string3"} - ]); - - record{|C2...;|}[]|csv:Error rt15a = csv:parseListAsRecordType( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] - , ["a", "b", "c", "d"]); - - test:assertEquals(rt15a , [ - {a: "1", b: "string", c: true, d: "string"}, - {a: "2", b: "string2", c: false, d: "string2"}, - {a: "3", b: "string3", c: true, d: "string3"} - ]); - - record{|C2...;|}[]|csv:Error rt15a_2 = csv:parseListAsRecordType( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] - , ["a", "b", "c", "d"], {stringConversion: false}); - - test:assertEquals(rt15a_2 , [ - {a: "1", b: "string", c: "true", d: "string"}, - {a: "2", b: "string2", c: "false", d: "string2"}, - {a: "3",b: "string3", c: "true", d: "string3"} - ]); - - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error rt16a = - csv:parseListAsListType( - [["1", "string", "true"], - ["2", "string2", "false"], - ["3", "string3", "true"]]); - - test:assertEquals(rt16a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); - - [A, B, C][]|csv:Error rt17a = csv:parseListAsListType( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); - - test:assertEquals(rt17a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); - - [A, B, C][]|csv:Error rt17a_2 = csv:parseListAsListType( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {stringConversion: false}); - - test:assertTrue(rt17a_2 is csv:Error); - test:assertEquals((rt17a_2).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "0", "type_compatible_tests:A")); - - [A2, B2, C2][]|csv:Error rt18a = csv:parseListAsListType( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); - - test:assertEquals(rt18a , [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] - ]); - - [A2, B2, C2...][]|csv:Error rt19a = csv:parseListAsListType( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); - - test:assertEquals(rt19a , [ - [1, "string", true, "string"], - [2, "string2", false, "string2"], - [3, "string3", true, "string3"] - ]); - - [C2...][]|csv:Error rt20a = csv:parseListAsListType( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); - - test:assertEquals(rt20a, [["1", "string",true, "string"], - ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); -} \ No newline at end of file + record { + readonly & int a; + readonly & string b; + (readonly & boolean)|(readonly & decimal) c; + }[]|csv:Error rt11a = csv:parseList( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); + + test:assertEquals(rt11a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {A a; B b; C c;}[]|csv:Error rt12a = csv:parseList( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); + + test:assertEquals(rt12a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {string|decimal a; B b; C c;}[]|csv:Error rt12a_3 = csv:parseList( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); + + test:assertEquals(rt12a_3, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {A2 a; B2 b; C2 c;}[]|csv:Error rt13a = csv:parseList( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); + + test:assertEquals(rt13a, [ + {a: 1, b: "string", c: true}, + {a: 2, b: "string2", c: false}, + {a: 3, b: "string3", c: true} + ]); + + record {|A2 a; B2 b; C2...;|}[]|csv:Error rt14a = csv:parseList( + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] + , {customHeaders: ["a", "b", "c", "d"]}); + + test:assertEquals(rt14a, [ + {a: 1, b: "string", c: true, d: "string"}, + {a: 2, b: "string2", c: false, d: "string2"}, + {a: 3, b: "string3", c: true, d: "string3"} + ]); + + record {|C2...;|}[]|csv:Error rt15a = csv:parseList( + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] + , {customHeaders: ["a", "b", "c", "d"]}); + + test:assertEquals(rt15a, [ + {a: "1", b: "string", c: true, d: "string"}, + {a: "2", b: "string2", c: false, d: "string2"}, + {a: "3", b: "string3", c: true, d: "string3"} + ]); + + [readonly & int, readonly & string, (readonly & boolean)|(readonly & decimal)][]|csv:Error rt16a = + csv:parseList( + [ + ["1", "string", "true"], + ["2", "string2", "false"], + ["3", "string3", "true"] + ]); + + test:assertEquals(rt16a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); + + [A, B, C][]|csv:Error rt17a = csv:parseList( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); + + test:assertEquals(rt17a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); + + [A2, B2, C2][]|csv:Error rt18a = csv:parseList( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); + + test:assertEquals(rt18a, [ + [1, "string", true], + [2, "string2", false], + [3, "string3", true] + ]); + + [A2, B2, C2...][]|csv:Error rt19a = csv:parseList( + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); + + test:assertEquals(rt19a, [ + [1, "string", true, "string"], + [2, "string2", false, "string2"], + [3, "string3", true, "string3"] + ]); + + [C2...][]|csv:Error rt20a = csv:parseList( + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); + + test:assertEquals(rt20a, [ + ["1", "string", true, "string"], + ["2", "string2", false, "string2"], + ["3", "string3", true, "string3"] + ]); +} diff --git a/ballerina-tests/unicode-tests/Ballerina.toml b/ballerina-tests/unicode-tests/Ballerina.toml index 5dba598..a2cadc0 100644 --- a/ballerina-tests/unicode-tests/Ballerina.toml +++ b/ballerina-tests/unicode-tests/Ballerina.toml @@ -13,4 +13,4 @@ version = "0.1.0" graalvmCompatible = true [build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" +graalvmBuildOptions = "-H:+IncludeAllLocales" diff --git a/ballerina-tests/unicode-tests/tests/escape_character_test.bal b/ballerina-tests/unicode-tests/tests/escape_character_test.bal index 297fa87..9114e1b 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:parseStringToRecord(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,7 +45,7 @@ function testEscapedCharactres2() returns error? { string csvString = string `a, b backspace\bbackspace, 7`; - record{string a; int b;}[]|csv:Error rec = csv:parseStringToRecord(csvString); + record{string a; int b;}[]|csv:Error rec = csv:parseString(csvString); test:assertTrue(rec is record{string a; int b;}[]); } @@ -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:parseStringToRecord(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:parseStringToRecord(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/Ballerina.toml b/ballerina-tests/union-type-tests/Ballerina.toml index 1480b52..66da3f7 100644 --- a/ballerina-tests/union-type-tests/Ballerina.toml +++ b/ballerina-tests/union-type-tests/Ballerina.toml @@ -13,4 +13,4 @@ version = "0.1.0" graalvmCompatible = true [build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" +graalvmBuildOptions = "-H:+IncludeAllLocales" 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 new file mode 100644 index 0000000..7066c6d --- /dev/null +++ b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal @@ -0,0 +1,254 @@ +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, headerRows: 1}; +csv:ParseListOptions op8 = {outputWithHeaders: true, headerRows: 2}; +csv:ParseListOptions op9 = {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListOptions op10 = {outputWithHeaders: true, headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListOptions op12 = {headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; + +type UnionType1 boolean[][]|string[][]; + +type UnionType2 ([boolean...]|[string, string...])[]; + +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 + 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"}]; + +@test:Config +function testParseStringWithMapWithOutputHeaders() { + UnionType3|csv:Error psu3 = csv:parseString(csv3); + test:assertEquals(psu3, result2); + + psu3 = csv:parseString(csv3, op5); + test:assertEquals(psu3, result2); + + UnionType4|csv:Error psu4 = csv:parseString(csv3); + test:assertEquals(psu4, result3); + + psu4 = csv:parseString(csv3, op5); + test:assertEquals(psu4, result3); +} + +@test:Config +function testParseStringWithListWithOutputHeaders() { + UnionType1|csv:Error psu1 = csv:parseString(csv3); + test:assertEquals(psu1, result4); + + psu1 = csv:parseString(csv3, op5); + test:assertEquals(psu1, result6); + + UnionType2|csv:Error psu2 = csv:parseString(csv3); + test:assertEquals(psu2, result4); + + psu2 = csv:parseString(csv3, op5); + test:assertEquals(psu2, result6); +} + +@test:Config +function testTransformWithMapWithOutputHeaders() { + UnionType3|csv:Error psu3 = csv:transform(csv2); + test:assertEquals(psu3, result2); + + psu3 = csv:transform(csv2, op1); + test:assertEquals(psu3, result2); + + psu3 = csv:transform(csv2, op2); + test:assertEquals(psu3, result2); + + psu3 = csv:transform(csv2, op3); + test:assertEquals(psu3, result2); + + psu3 = csv:transform(csv2, op4); + test:assertEquals(psu3, result2); + + UnionType4|csv:Error psu4 = csv:transform(csv4); + test:assertEquals(psu4, result3); + + psu4 = csv:transform(csv4, op1); + test:assertEquals(psu4, result3); + + psu4 = csv:transform(csv4, op2); + test:assertEquals(psu4, result3); + + psu4 = csv:transform(csv4, op3); + test:assertEquals(psu4, result3); + + psu4 = csv:transform(csv4, op4); + test:assertEquals(psu4, result3); +} + +@test:Config +function testTransformWithListWithOutputHeaders() { + UnionType1|csv:Error psu1 = csv:transform(csv4); + test:assertEquals(psu1, result4); + + psu1 = csv:transform(csv4, op1); + test:assertEquals(psu1, result4); + + psu1 = csv:transform(csv4, op2); + test:assertEquals(psu1, result6); + + psu1 = csv:transform(csv4, op3); + test:assertEquals(psu1, result6); + + UnionType2|csv:Error psu2 = csv:transform(csv4); + test:assertEquals(psu2, result4); + + psu2 = csv:transform(csv4, op1); + test:assertEquals(psu2, result4); + + psu2 = csv:transform(csv4, op2); + test:assertEquals(psu2, result6); + + psu2 = csv:transform(csv4, op3); + test:assertEquals(psu2, result6); +} + +@test:Config +function testParseListWithMapWithOutputHeaders() { + UnionType3|csv:Error psu3 = csv:parseList(csv1); + test:assertEquals(psu3, result7); + + psu3 = csv:parseList(csv1, op6); + test:assertEquals(psu3, result7); + + psu3 = csv:parseList(csv1, op7); + test:assertEquals(psu3, [{"1": 5, "2": 6, "3": 7, "4": 8}, {"1": 9, "2": 10, "3": 11, "4": 12}, {"1": 13, "2": 14, "3": 15, "4": 16}]); + + psu3 = csv:parseList(csv1, op9); + test:assertEquals(psu3, [{"a": 9, "b": 10, "c": 11, "d": 12}, {"a": 13, "b": 14, "c": 15, "d": 16}]); + + UnionType4|csv:Error psu4 = csv:parseList(csv1); + test:assertEquals(psu4, result8); + + psu4 = csv:parseList(csv1, op6); + test:assertEquals(psu4, result8); + + psu4 = csv:parseList(csv1, op7); + test:assertEquals(psu4, [{"1": "5", "2": "6", "3": "7", "4": "8"}, {"1": "9", "2": "10", "3": "11", "4": "12"}, {"1": "13", "2": "14", "3": "15", "4": "16"}]); + + psu4 = csv:parseList(csv1, op9); + test:assertEquals(psu4, [{"a": "9", "b": "10", "c": "11", "d": "12"}, {"a": "13", "b": "14", "c": "15", "d": "16"}]); +} + +@test:Config +function testParseListWithListWithOutputHeaders() { + UnionType1|csv:Error psu1 = csv:parseList(csv1); + test:assertEquals(psu1, result4); + + psu1 = csv:parseList(csv1, op6); + test:assertEquals(psu1, result4); + + psu1 = csv:parseList(csv1, op7); + test:assertEquals(psu1, result4); + + psu1 = csv:parseList(csv1, op9); + test:assertEquals(psu1, [["a","b","c","d"],["9","10","11","12"],["13","14","15","16"]]); + + UnionType2|csv:Error psu2 = csv:parseList(csv1); + test:assertEquals(psu2, result4); + + psu2 = csv:parseList(csv1, op6); + test:assertEquals(psu2, result4); + + psu2 = csv:parseList(csv1, op7); + test:assertEquals(psu2, result4); + + psu2 = csv:parseList(csv1, op9); + test:assertEquals(psu2, [["a","b","c","d"],["9","10","11","12"],["13","14","15","16"]]); +} + +@test:Config +function testParseListWithMapWithOutputHeaders2() { + UnionType3|csv:Error psu3 = csv:parseList(csv1); + test:assertEquals(psu3, result7); + + psu3 = csv:parseList(csv1, op10); + test:assertEquals(psu3, [{"a":5,"b":6,"c":7,"d":8},{"a":9,"b":10,"c":11,"d":12},{"a":13,"b":14,"c":15,"d":16}]); + + psu3 = csv:parseList(csv1, op11); + test:assertEquals(psu3, result2); + + psu3 = csv:parseList(csv1, op12); + test:assertEquals(psu3, [{"a":5,"b":6,"c":7,"d":8},{"a":9,"b":10,"c":11,"d":12},{"a":13,"b":14,"c":15,"d":16}]); + + psu3 = csv:parseList(csv1, op13); + test:assertEquals(psu3, result2); + + UnionType4|csv:Error psu4 = csv:parseList(csv1); + test:assertEquals(psu4, result8); + + psu4 = csv:parseList(csv1, op10); + test:assertEquals(psu4, [{a: "5", b: "6", c: "7", d: "8"}, {a: "9", b: "10", c: "11", d: "12"}, {a: "13", b: "14", c: "15", d: "16"}]); + + psu4 = csv:parseList(csv1, op11); + test:assertEquals(psu4, result3); + + psu4 = csv:parseList(csv1, op12); + test:assertEquals(psu4, [{a: "5", b: "6", c: "7", d: "8"}, {a: "9", b: "10", c: "11", d: "12"}, {a: "13", b: "14", c: "15", d: "16"}]); + + psu4 = csv:parseList(csv1, op13); + test:assertEquals(psu4, result3); +} + +@test:Config +function testParseListWithListWithOutputHeaders2() { + UnionType1|csv:Error psu1 = csv:parseList(csv1); + test:assertEquals(psu1, result4); + + psu1 = csv:parseList(csv1, op10); + test:assertEquals(psu1, [["a","b","c","d"],["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); + + psu1 = csv:parseList(csv1, op11); + test:assertEquals(psu1, result6); + + psu1 = csv:parseList(csv1, op12); + test:assertEquals(psu1, [["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); + + psu1 = csv:parseList(csv1, op13); + test:assertEquals(psu1, result4); + + UnionType2|csv:Error psu2 = csv:parseList(csv1); + test:assertEquals(psu2, result4); + + psu2 = csv:parseList(csv1, op10); + test:assertEquals(psu2, [["a","b","c","d"],["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); + + psu2 = csv:parseList(csv1, op11); + test:assertEquals(psu2, [["a","b","c","d"], ["1", "2", "3", "4"],["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); + + psu2 = csv:parseList(csv1, op12); + test:assertEquals(psu2, [["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); + + psu2 = csv:parseList(csv1, op13); + test:assertEquals(psu2, [["1", "2", "3", "4"],["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); +} 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 be41c23..5d37b8b 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 @@ -18,62 +18,62 @@ import ballerina/test; @test:Config function testIntersectionExpectedTypes() returns error? { - (int[] & readonly)[]|csv:Error a = csv:parseStringToList(string `a,b + (int[] & readonly)[]|csv:Error a = csv:parseString(string `a,b 1,2 4,5`); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|csv:Error a2 = csv:parseStringToList(string `a,b + ([string, string])[] & readonly|csv:Error a2 = csv:parseString(string `a,b a,a c,c`); test:assertTrue(a2 is [string, string][] & readonly); test:assertEquals(a2, [["a", "a"], ["c", "c"]]); - (record {int a; string b;} & readonly)[]|csv:Error a3 = csv:parseStringToRecord(string `a,b + (record {int a; string b;} & readonly)[]|csv:Error a3 = csv:parseString(string `a,b 1,2 4,5`); test:assertTrue(a3 is (record {int a; string b;} & readonly)[]); test:assertEquals(a3, [{a: 1, b: "2"}, {a: 4, b: "5"}]); - record {|string...;|}[] & readonly|csv:Error a4 = csv:parseStringToRecord(string `a,b + record {|string...;|}[] & readonly|csv:Error a4 = csv:parseString(string `a,b a,a c,c`); test:assertTrue(a4 is record {|string...;|}[] & readonly); test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - ([int] & readonly)[]|csv:Error a5 = csv:parseStringToList(string `a,b + ([int] & readonly)[]|csv:Error a5 = csv:parseString(string `a,b 1,2 4,5`); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|csv:Error a6 = csv:parseStringToList(string `a,b + ([string, string])[] & readonly|csv:Error a6 = csv:parseString(string `a,b a,a c,c`); test:assertTrue(a6 is [string, string][] & readonly); test:assertEquals(a6, [["a", "a"], ["c", "c"]]); - (record {int a; string b;} & readonly)[]|csv:Error a7 = csv:parseStringToRecord(string `a,b + (record {int a; string b;} & readonly)[]|csv:Error a7 = csv:parseString(string `a,b 1,2 4,5`); test:assertTrue(a7 is record {int a; string b;}[] & readonly); test:assertEquals(a7, [{a: 1, b: "2"}, {a: 4, b: "5"}]); - map[] & readonly|csv:Error a8 = csv:parseStringToRecord(string `a,b + map[] & readonly|csv:Error a8 = csv:parseString(string `a,b a,a c,c`); 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:parseStringToList(string `a,b + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:parseString(string `a,b 1,2 a,a`); test:assertTrue(a9 is (((int[] & readonly)|([string, string] & readonly)) & readonly)[]); test:assertEquals(a9, [[1, 2], ["a", "a"]]); ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] - & readonly|csv:Error a10 = csv:parseStringToRecord(string `a,b + & readonly|csv:Error a10 = csv:parseString(string `a,b a,a 1,2`); test:assertTrue(a10 is ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly); @@ -82,93 +82,93 @@ function testIntersectionExpectedTypes() returns error? { @test:Config function testIntersectionExpectedTypes2() returns error? { - (int[] & readonly)[]|csv:Error a = csv:parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); + (int[] & readonly)[]|csv:Error a = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], {headersOrder: ["a", "b"]}); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|csv:Error a2 = csv:parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); + ([string, string])[] & readonly|csv:Error a2 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {headersOrder: ["a", "b"]}); test:assertTrue(a2 is [string, string][] & readonly); test:assertEquals(a2, [["a", "a"], ["c", "c"]]); - (record {int a; string b;} & readonly)[]|csv:Error a3 = csv:parseRecordAsRecordType([{"a": 1, "b": "2"}, {"a": 4, "b": "5"}], {}); + (record {int a; string b;} & readonly)[]|csv:Error a3 = csv:transform([{"a": 1, "b": "2"}, {"a": 4, "b": "5"}], {}); test:assertTrue(a3 is (record {int a; string b;} & readonly)[]); test:assertEquals(a3, [{a: 1, b: "2"}, {a: 4, b: "5"}]); - record {|string...;|}[] & readonly|csv:Error a4 = csv:parseRecordAsRecordType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {}); + record {|string...;|}[] & readonly|csv:Error a4 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {}); test:assertTrue(a4 is record {|string...;|}[] & readonly); test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - ([int] & readonly)[]|csv:Error a5 = csv:parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); + ([int] & readonly)[]|csv:Error a5 = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], {headersOrder: ["a", "b"]}); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|csv:Error a6 = csv:parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); + ([string, string])[] & readonly|csv:Error a6 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {headersOrder: ["a", "b"]}); test:assertTrue(a6 is [string, string][] & readonly); test:assertEquals(a6, [["a", "a"], ["c", "c"]]); - (record {int a; string b;} & readonly)[]|csv:Error a7 = csv:parseRecordAsRecordType([{"a": 1, "b": "2"}, {"a": 4, "b": "5"}], {}); + (record {int a; string b;} & readonly)[]|csv:Error a7 = csv:transform([{"a": 1, "b": "2"}, {"a": 4, "b": "5"}], {}); test:assertTrue(a7 is record {int a; string b;}[] & readonly); test:assertEquals(a7, [{a: 1, b: "2"}, {a: 4, b: "5"}]); - map[] & readonly|csv:Error a8 = csv:parseRecordAsRecordType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {}); + map[] & readonly|csv:Error a8 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {}); 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:parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["a", "b"], {}); + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); test:assertTrue(a9 is (((int[] & readonly)|([string, string] & readonly)) & readonly)[]); test:assertEquals(a9, [[1, 2], ["a", "b"]]); ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] - & readonly|csv:Error a10 = csv:parseRecordAsRecordType([{"a": "a", "b": "a"}, {"a": 1, "b": 2}], {}); + & readonly|csv:Error a10 = csv:transform([{"a": "a", "b": "a"}, {"a": 1, "b": 2}], {}); test:assertTrue(a10 is ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly); test:assertEquals(a10, [{a: "a", b: "a"}, {a: 1, b: 2}]); } @test:Config function testIntersectionExpectedTypes3() returns error? { - (int[] & readonly)[]|csv:Error a = csv:parseListAsListType([["1", "2"], ["4", "5"]], {}); + (int[] & readonly)[]|csv:Error a = csv:parseList([["1", "2"], ["4", "5"]], {}); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|csv:Error a2 = csv:parseListAsListType([["a", "a"], ["c", "c"]], {}); + ([string, string])[] & readonly|csv:Error a2 = csv:parseList([["a", "a"], ["c", "c"]], {}); test:assertTrue(a2 is [string, string][] & readonly); test:assertEquals(a2, [["a", "a"], ["c", "c"]]); - (record {int a; string b;} & readonly)[]|csv:Error a3 = csv:parseListAsRecordType([["1", "2"], ["4", "5"]], ["a", "b"], {}); + (record {int a; string b;} & readonly)[]|csv:Error a3 = csv:parseList([["1", "2"], ["4", "5"]], {customHeaders: ["a", "b"]}); test:assertTrue(a3 is (record {int a; string b;} & readonly)[]); test:assertEquals(a3, [{a: 1, b: "2"}, {a: 4, b: "5"}]); - record {|string...;|}[] & readonly|csv:Error a4 = csv:parseListAsRecordType([["a", "a"], ["c", "c"]], ["a", "b"], {}); + record {|string...;|}[] & readonly|csv:Error a4 = csv:parseList([["a", "a"], ["c", "c"]], {customHeaders: ["a", "b"]}); test:assertTrue(a4 is record {|string...;|}[] & readonly); test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - ([int] & readonly)[]|csv:Error a5 = csv:parseListAsListType([["1", "2"], ["4", "5"]], {}); + ([int] & readonly)[]|csv:Error a5 = csv:parseList([["1", "2"], ["4", "5"]], {}); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|csv:Error a6 = csv:parseListAsListType([["a", "a"], ["c", "c"]], {}); + ([string, string])[] & readonly|csv:Error a6 = csv:parseList([["a", "a"], ["c", "c"]], {}); test:assertTrue(a6 is [string, string][] & readonly); test:assertEquals(a6, [["a", "a"], ["c", "c"]]); - (record {int a; string b;} & readonly)[]|csv:Error a7 = csv:parseListAsRecordType([["1", "2"], ["4", "5"]], ["a", "b"], {}); + (record {int a; string b;} & readonly)[]|csv:Error a7 = csv:parseList([["1", "2"], ["4", "5"]], {customHeaders: ["a", "b"]}); test:assertTrue(a7 is record {int a; string b;}[] & readonly); test:assertEquals(a7, [{a: 1, b: "2"}, {a: 4, b: "5"}]); - map[] & readonly|csv:Error a8 = csv:parseListAsRecordType([["a", "a"], ["c", "c"]], ["a", "b"], {}); + map[] & readonly|csv:Error a8 = csv:parseList([["a", "a"], ["c", "c"]], {customHeaders: ["a", "b"]}); 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:parseListAsListType([["1", "2"], ["a", "b"]], {}); + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:parseList([["1", "2"], ["a", "b"]], {}); test:assertTrue(a9 is (((int[] & readonly)|([string, string] & readonly)) & readonly)[]); test:assertEquals(a9, [[1, 2], ["a", "b"]]); ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] - & readonly|csv:Error a10 = csv:parseListAsRecordType([["a", "a"], ["1", "2"]], ["a", "b"], {}); + & readonly|csv:Error a10 = csv:parseList([["a", "a"], ["1", "2"]], {customHeaders: ["a", "b"]}); test:assertTrue(a10 is ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly); test:assertEquals(a10, [{a: "a", b: "a"}, {a: "1", b: "2"}]); ((record {int a; int b;} & readonly)|(record {string a; string b;} & readonly))[] - & readonly|csv:Error a11 = csv:parseListAsRecordType([["a", "a"], ["1", "2"]], ["a", "b"], {}); + & readonly|csv:Error a11 = csv:parseList([["a", "a"], ["1", "2"]], {customHeaders: ["a", "b"]}); test:assertTrue(a11 is ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly); test:assertEquals(a11, [{a: "a", b: "a"}, {a: 1, b: 2}]); } 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 3aa7369..cf6a55a 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 @@ -22,43 +22,43 @@ type Singleton 1; @test:Config function testSingletonExpectedTypes() returns error? { - 1[][]|csv:Error a = csv:parseStringToList(string `a, b, c + 1[][]|csv:Error a = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a, [[1, 1, 1], [1, 1, 1]]); - record {1|2 a; 1 b;}[]|csv:Error a2 = csv:parseStringToRecord(string `a, b, c + record {1|2 a; 1 b;}[]|csv:Error a2 = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a2, [{a: 1, b: 1, c: 1}, {a: 1, b: 1, c: 1}]); - record {|1 a; 1|2...;|}[]|csv:Error a3 = csv:parseStringToRecord(string `a, b, c + record {|1 a; 1|2...;|}[]|csv:Error a3 = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a3, [{a: 1, b: 1, c: 1}, {a: 1, b: 1, c: 1}]); - [Singleton, Singleton...][]|csv:Error a4 = csv:parseStringToList(string `a, b, c + [Singleton, Singleton...][]|csv:Error a4 = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a4, [[1, 1, 1], [1, 1, 1]]); - record {|1|"a" a; 1 b;|}[]|csv:Error a5 = csv:parseStringToRecord(string `a, b, c + record {|1|"a" a; 1 b;|}[]|csv:Error a5 = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a5, [{a: 1, b: 1}, {a: 1, b: 1}]); - [Singleton, Singleton][]|csv:Error a6 = csv:parseStringToList(string `a, b, c + [Singleton, Singleton][]|csv:Error a6 = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a6, [[1, 1], [1, 1]]); - record {|"a"|"c" a; "b" b;|}[]|csv:Error a7 = csv:parseStringToRecord(string `a, b, c + record {|"a"|"c" a; "b" b;|}[]|csv:Error a7 = csv:parseString(string `a, b, c a, c, 1 1, 1,1 `); test:assertTrue(a7 is csv:Error); test:assertEquals((a7).message(), common:generateErrorMessageForInvalidCast("c", "\"b\"")); - ["a"|"d", "b"][]|csv:Error a8 = csv:parseStringToList(string `a, b, c + ["a"|"d", "b"][]|csv:Error a8 = csv:parseString(string `a, b, c a, b, 1 c, b,1 `); test:assertTrue(a8 is csv:Error); @@ -67,43 +67,43 @@ function testSingletonExpectedTypes() returns error? { @test:Config function testSingletonExpectedTypes2() returns error? { - 1[][]|csv:Error a = csv:parseStringToList(string `a, b, c + 1[][]|csv:Error a = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a, [[1, 1, 1], [1, 1, 1]]); - record {1|2 a; 1 b;}[]|csv:Error a2 = csv:parseStringToRecord(string `a, b, c + record {1|2 a; 1 b;}[]|csv:Error a2 = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a2, [{a: 1, b: 1, c: 1}, {a: 1, b: 1, c: 1}]); - record {|1 a; 1|2...;|}[]|csv:Error a3 = csv:parseStringToRecord(string `a, b, c + record {|1 a; 1|2...;|}[]|csv:Error a3 = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a3, [{a: 1, b: 1, c: 1}, {a: 1, b: 1, c: 1}]); - [Singleton, Singleton...][]|csv:Error a4 = csv:parseStringToList(string `a, b, c + [Singleton, Singleton...][]|csv:Error a4 = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a4, [[1, 1, 1], [1, 1, 1]]); - record {|1|"a" a; 1 b;|}[]|csv:Error a5 = csv:parseStringToRecord(string `a, b, c + record {|1|"a" a; 1 b;|}[]|csv:Error a5 = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a5, [{a: 1, b: 1}, {a: 1, b: 1}]); - [Singleton, Singleton][]|csv:Error a6 = csv:parseStringToList(string `a, b, c + [Singleton, Singleton][]|csv:Error a6 = csv:parseString(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a6, [[1, 1], [1, 1]]); - record {|"a"|"c" a; "b" b;|}[]|csv:Error a7 = csv:parseStringToRecord(string `a, b, c + record {|"a"|"c" a; "b" b;|}[]|csv:Error a7 = csv:parseString(string `a, b, c a, c, 1 1, 1,1 `); test:assertTrue(a7 is csv:Error); test:assertEquals((a7).message(), common:generateErrorMessageForInvalidCast("c", "\"b\"")); - ["a"|"d", "b"][]|csv:Error a8 = csv:parseStringToList(string `a, b, c + ["a"|"d", "b"][]|csv:Error a8 = csv:parseString(string `a, b, c a, b, 1 c, b,1 `); test:assertTrue(a8 is csv:Error); @@ -143,77 +143,71 @@ function testSubtypeExpectedTypes() returns error? { var value3 = [[1, 1, 1, 1, "a", 1, 1, 1], [1, 1, 1, 1, "a", 1, 1, 1]]; - SubtypeRecord[]|csv:Error a = csv:parseStringToRecord(string `a, c, d, e, f, g, h, i + SubtypeRecord[]|csv:Error a = csv:parseString(string `a, c, d, e, f, g, h, i 1, 1, 1, 1, a, 1, 1, 1 1, 1, 1, 1, a, 1, 1, 1 `); test:assertEquals(a, value1); - SubtypeRecord2[]|csv:Error a2 = csv:parseStringToRecord(string `a, c, d, e, f, g, h, i + SubtypeRecord2[]|csv:Error a2 = csv:parseString(string `a, c, d, e, f, g, h, i 1, 1, 1, 1, a, 1, 1, 1 1, 1, 1, 1, a, 1, 1, 1 `); test:assertEquals(a2, [{a: 1, c: 1}, {a: 1, c: 1}]); - SubtypeRecord3[]|csv:Error a3 = csv:parseStringToRecord(string `a, c, d, e, f, g, h, i + SubtypeRecord3[]|csv:Error a3 = csv:parseString(string `a, c, d, e, f, g, h, i 1, 1, 1, 1, a, 1, 1, 1 1, 1, 1, 1, a, 1, 1, 1 `); test:assertEquals(a3, value1); - SubtypeTuple[]|csv:Error a4 = csv:parseStringToList(string `a, c, d, e, f, g, h, i + SubtypeTuple[]|csv:Error a4 = csv:parseString(string `a, c, d, e, f, g, h, i 1, 1, 1, 1, a, 1, 1, 1 1, 1, 1, 1, a, 1, 1, 1 `); test:assertEquals(a4, value3); - SubtypeTuple2[]|csv:Error a5 = csv:parseStringToList(string `a, c, d, e, f, g, h, i + SubtypeTuple2[]|csv:Error a5 = csv:parseString(string `a, c, d, e, f, g, h, i 1, 1, 1, 1, a, 1, 1, 1 1, 1, 1, 1, a, 1, 1, 1 `); test:assertEquals(a5, [[1, 1], [1, 1]]); - SubtypeTuple3[]|csv:Error a6 = csv:parseStringToList(string `a, c, d, e, f, g, h, i + SubtypeTuple3[]|csv:Error a6 = csv:parseString(string `a, c, d, e, f, g, h, i 1, 1, 1, 1, a, 1, 1, 1 1, 1, 1, 1, a, 1, 1, 1 `); test:assertEquals(a6, value3); - SubtypeRecord[]|csv:Error a7 = csv:parseRecordAsRecordType(value1, {}); + SubtypeRecord[]|csv:Error a7 = csv:transform(value1, {}); test:assertEquals(a7, value1); - SubtypeRecord2[]|csv:Error a8 = csv:parseRecordAsRecordType(value1, {}); + SubtypeRecord2[]|csv:Error a8 = csv:transform(value1, {}); test:assertEquals(a8, [{a: 1, c: 1}, {a: 1, c: 1}]); - SubtypeRecord3[]|csv:Error a9 = csv:parseRecordAsRecordType(value1, {}); + SubtypeRecord3[]|csv:Error a9 = csv:transform(value1, {}); test:assertEquals(a9, value1); - SubtypeTuple[]|csv:Error a10 = csv:parseRecordAsListType(value1, - ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + SubtypeTuple[]|csv:Error a10 = csv:transform(value1, {headersOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a10, value3); - SubtypeTuple2[]|csv:Error a11 = csv:parseRecordAsListType(value1, - ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + SubtypeTuple2[]|csv:Error a11 = csv:transform(value1, {headersOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a11, [[1, 1], [1, 1]]); - SubtypeTuple3[]|csv:Error a12 = csv:parseRecordAsListType(value1, - ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + SubtypeTuple3[]|csv:Error a12 = csv:transform(value1, {headersOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a12, value3); - SubtypeRecord[]|csv:Error a13 = csv:parseListAsRecordType(value2, - ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + SubtypeRecord[]|csv:Error a13 = csv:parseList(value2, {customHeaders: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a13, value1); - SubtypeRecord2[]|csv:Error a14 = csv:parseListAsRecordType(value2, - ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + SubtypeRecord2[]|csv:Error a14 = csv:parseList(value2, {customHeaders: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a14, [{a: 1, c: 1}, {a: 1, c: 1}]); - SubtypeRecord3[]|csv:Error a15 = csv:parseListAsRecordType(value2, - ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + SubtypeRecord3[]|csv:Error a15 = csv:parseList(value2, {customHeaders: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a15, value1); - SubtypeTuple[]|csv:Error a16 = csv:parseListAsListType(value2, {}); + SubtypeTuple[]|csv:Error a16 = csv:parseList(value2, {}); test:assertEquals(a16, value3); - SubtypeTuple2[]|csv:Error a17 = csv:parseListAsListType(value2, {}); + SubtypeTuple2[]|csv:Error a17 = csv:parseList(value2, {}); test:assertEquals(a17, [[1, 1], [1, 1]]); - SubtypeTuple3[]|csv:Error a18 = csv:parseListAsListType(value2, {}); + SubtypeTuple3[]|csv:Error a18 = csv:parseList(value2, {}); test:assertEquals(a18, value3); } 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 4ed231a..f7dda6b 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 @@ -26,7 +26,7 @@ type TupC [int, int, int]; @test:Config function testParseToStringWithUnionExpectedTypes() returns error? { - (RecA|RecC)[]|csv:Error csv1op1 = csv:parseStringToRecord(csvStringData1, {header: 1}); + (RecA|RecC)[]|csv:Error csv1op1 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op1, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, @@ -35,7 +35,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecA|RecC)[]|csv:Error csv1op2 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecA|RecC)[]|csv:Error csv1op2 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertTrue(csv1op2 is (RecA|RecC)[]); test:assertEquals(csv1op2, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -43,42 +43,42 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecC|RecA)[]|csv:Error csv1op3 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecC|RecA)[]|csv:Error csv1op3 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op3, [ {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: ()} ]); - (RecB|RecA)[]|csv:Error csv1op4 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecB|RecA)[]|csv:Error csv1op4 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op4, [ {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", f: "()"} ]); - (RecA|RecB)[]|csv:Error csv1op5 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecA|RecB)[]|csv:Error csv1op5 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op5, [ {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 a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseStringToRecord(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:parseStringToRecord(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:parseStringToRecord(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:parseStringToRecord(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:parseStringToRecord(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:parseStringToRecord(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:parseStringToRecord(string ` + (record{|int a; int b;|}|record{|string a; string...;|})[]|csv:Error csv1op12 = csv:parseString(string ` a,b 1, 2 a, b`, {header: 1}); @@ -123,7 +123,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "a", b: "b"} ]); - ([int, int]|[string, string])[]|csv:Error csv1op13 = csv:parseStringToList(string ` + ([int, int]|[string, string])[]|csv:Error csv1op13 = csv:parseString(string ` a,b 1, 2 a, b`, {header: 1}); @@ -143,7 +143,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - (RecA|RecC)[]|csv:Error csv1op1 = csv:parseRecordAsRecordType(value, {}); + (RecA|RecC)[]|csv:Error csv1op1 = csv:transform(value, {}); test:assertEquals(csv1op1, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, @@ -152,7 +152,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecA|RecC)[]|csv:Error csv1op2 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecA|RecC)[]|csv:Error csv1op2 = csv:transform(value, {skipLines: [2, 4]}); test:assertTrue(csv1op2 is (RecA|RecC)[]); test:assertEquals(csv1op2, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -160,42 +160,42 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecC|RecA)[]|csv:Error csv1op3 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecC|RecA)[]|csv:Error csv1op3 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op3, [ {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: ()} ]); - (RecB|RecA)[]|csv:Error csv1op4 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecB|RecA)[]|csv:Error csv1op4 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op4, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (RecA|RecB)[]|csv:Error csv1op5 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecA|RecB)[]|csv:Error csv1op5 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op5, [ {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 a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseRecordAsRecordType(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:parseRecordAsRecordType(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:parseRecordAsRecordType(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:parseRecordAsRecordType(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:parseRecordAsRecordType(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:parseRecordAsRecordType(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,11 +231,11 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5"} ]); - (record{|string a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op12 = csv:parseRecordAsRecordType(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...; |})[]'"); - (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op13 = csv:parseRecordAsRecordType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); + (record{|int a; int...;|}|record{|string a; 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"} @@ -252,7 +252,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - (RecA|RecC)[]|csv:Error csv1op1 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + (RecA|RecC)[]|csv:Error csv1op1 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op1, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, @@ -261,7 +261,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecA|RecC)[]|csv:Error csv1op2 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecA|RecC)[]|csv:Error csv1op2 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertTrue(csv1op2 is (RecA|RecC)[]); test:assertEquals(csv1op2, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -269,49 +269,49 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecC|RecA)[]|csv:Error csv1op3 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecC|RecA)[]|csv:Error csv1op3 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op3, [ {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: ()} ]); - (RecB|RecA)[]|csv:Error csv1op4 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecB|RecA)[]|csv:Error csv1op4 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op4, [ {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: "()"} ]); - (RecA|RecB)[]|csv:Error csv1op5 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecA|RecB)[]|csv:Error csv1op5 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op5, [ {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 a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseListAsRecordType(value, ["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:parseListAsRecordType(value, ["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:parseListAsRecordType(value, ["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:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); + (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}, @@ -320,23 +320,14 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, d: 3} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9_2 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); - test:assertEquals(csv1op9_2, [ - {}, - {}, - {}, - {}, - {} - ]); - - (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseListAsRecordType(value, ["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:parseListAsRecordType(value, ["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}, @@ -345,11 +336,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", d: 3} ]); - (record{|int a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op12 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); - test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(union_type_tests:record {| int a; int...; |}|union_type_tests:record {| int a; string...; |})[]'"); - - (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op13 = csv:parseListAsRecordType([["1", "2"], ["a", "b"]], ["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"} @@ -367,7 +354,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - (TupA|TupC)[]|csv:Error csv1op1 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + (TupA|TupC)[]|csv:Error csv1op1 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -376,7 +363,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupA|TupC)[]|csv:Error csv1op2 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupA|TupC)[]|csv:Error csv1op2 = csv:transform(value, {headersOrder: ["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, ()], @@ -384,66 +371,66 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupC|TupA)[]|csv:Error csv1op3 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupC|TupA)[]|csv:Error csv1op3 = csv:transform(value, {headersOrder: ["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:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupB|TupA)[]|csv:Error csv1op4 = csv:transform(value, {headersOrder: ["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:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupB|[boolean])[]|csv:Error csv1op4_2 = csv:transform(value, {headersOrder: ["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])[]'"); - (TupA|TupB)[]|csv:Error csv1op5 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupA|TupB)[]|csv:Error csv1op5 = csv:transform(value, {headersOrder: ["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:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + ([int]|[string])[]|csv:Error csv1op6 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - ([string]|[int])[]|csv:Error csv1op7 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + ([string]|[int])[]|csv:Error csv1op7 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ [1], [3], [5] ]); - ([string...]|[int...])[]|csv:Error csv1op8 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + ([string...]|[int...])[]|csv:Error csv1op8 = csv:transform(value, {headersOrder: ["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...])[]'"); - ([int...]|[string...])[]|csv:Error csv1op9 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + ([int...]|[string...])[]|csv:Error csv1op9 = csv:transform(value, {headersOrder: ["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...])[]'"); - ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:transform(value, {headersOrder: ["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...])[]'"); - ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:transform(value, {headersOrder: ["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...])[]'"); - ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:transform(value, {headersOrder: ["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...])[]'"); - ([int, int...]|[string, string...])[]|csv:Error csv1op13 = csv:parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["a", "b"], {}); + ([int, int...]|[string, string...])[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] @@ -460,7 +447,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - (TupA|TupC)[]|csv:Error csv1op1 = csv:parseListAsListType(value, {}); + (TupA|TupC)[]|csv:Error csv1op1 = csv:parseList(value, {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -469,7 +456,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupA|TupC)[]|csv:Error csv1op2 = csv:parseListAsListType(value, {skipLines: [2, 4]}); + (TupA|TupC)[]|csv:Error csv1op2 = csv:parseList(value, {skipLines: [2, 4]}); test:assertTrue(csv1op2 is (TupA|TupC)[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -477,56 +464,52 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupC|TupA)[]|csv:Error csv1op3 = csv:parseListAsListType(value, {skipLines: [2, 4]}); + (TupC|TupA)[]|csv:Error csv1op3 = csv:parseList(value, {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:parseListAsListType(value, {skipLines: [2, 4]}); + (TupB|TupA)[]|csv:Error csv1op4 = csv:parseList(value, {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:parseListAsListType(value, {skipLines: [2, 4]}); + (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])[]'"); - (TupA|TupB)[]|csv:Error csv1op5 = csv:parseListAsListType(value, {skipLines: [2, 4]}); + (TupA|TupB)[]|csv:Error csv1op5 = csv:parseList(value, {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:parseListAsListType(value, {skipLines: [2, 4]}); + ([int]|[string])[]|csv:Error csv1op6 = csv:parseList(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - ([string]|[int])[]|csv:Error csv1op7 = csv:parseListAsListType(value, {skipLines: [2, 4]}); + ([string]|[int])[]|csv:Error csv1op7 = csv:parseList(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ ["1"], ["3"], ["5"] ]); - ([boolean...]|[int...])[]|csv:Error csv1op8 = csv:parseListAsListType(value, {stringConversion: false}); - test:assertTrue(csv1op8 is csv:Error); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...]|[int...])[]'"); - - ([string...]|[int...])[]|csv:Error csv1op8_2 = csv:parseListAsListType(value, {}); + ([string...]|[int...])[]|csv:Error csv1op8_2 = csv:parseList(value, {}); test:assertEquals(csv1op8_2, value); - ([int...]|[string...])[]|csv:Error csv1op9 = csv:parseListAsListType(value, {}); + ([int...]|[string...])[]|csv:Error csv1op9 = csv:parseList(value, {}); test:assertEquals(csv1op9, value); - ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:parseListAsListType(value, {}); + ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:parseList(value, {}); test:assertEquals(csv1op10, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -535,7 +518,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:parseListAsListType(value, {}); + ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:parseList(value, {}); test:assertEquals(csv1op11, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -544,10 +527,10 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:parseListAsListType(value, {}); + ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:parseList(value, {}); test:assertEquals(csv1op12, value); - ([int, int...]|[string, string...])[]|csv:Error csv1op13 = csv:parseListAsListType([["1", "2"], ["a", "b"]], {}); + ([int, int...]|[string, string...])[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] @@ -556,7 +539,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { @test:Config function testParseToStringWithUnionExpectedTypes6() returns error? { - RecA[]|RecC[]|csv:Error csv1op1 = csv:parseStringToRecord(csvStringData1, {header: 1}); + RecA[]|RecC[]|csv:Error csv1op1 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op1, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, @@ -565,7 +548,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|csv:Error csv1op2 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecA[]|RecC[]|csv:Error csv1op2 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertTrue(csv1op2 is RecA[]|RecC[]); test:assertEquals(csv1op2, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -573,42 +556,42 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|csv:Error csv1op3 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecC[]|RecA[]|csv:Error csv1op3 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op3, [ {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: ()} ]); - RecB[]|RecA[]|csv:Error csv1op4 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecB[]|RecA[]|csv:Error csv1op4 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op4, [ {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", f: "()"} ]); - RecA[]|RecB[]|csv:Error csv1op5 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecA[]|RecB[]|csv:Error csv1op5 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op5, [ {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 a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseStringToRecord(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:parseStringToRecord(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:parseStringToRecord(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"}, @@ -617,7 +600,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseStringToRecord(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}, @@ -626,7 +609,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, d: 3, e: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseStringToRecord(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"}, @@ -635,7 +618,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:parseStringToRecord(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}, @@ -644,7 +627,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: "5", d: 3, e: 3} ]); - record{|int a; int b;|}[]|record{|string a; string...;|}[]|csv:Error csv1op12 = csv:parseStringToRecord(string ` + record{|int a; int b;|}[]|record{|string a; string...;|}[]|csv:Error csv1op12 = csv:parseString(string ` a,b 1, 2 a, b`, {header: 1}); @@ -664,7 +647,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - RecA[]|RecC[]|csv:Error csv1op1 = csv:parseRecordAsRecordType(value, {}); + RecA[]|RecC[]|csv:Error csv1op1 = csv:transform(value, {}); test:assertEquals(csv1op1, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, @@ -673,7 +656,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|csv:Error csv1op2 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecA[]|RecC[]|csv:Error csv1op2 = csv:transform(value, {skipLines: [2, 4]}); test:assertTrue(csv1op2 is RecA[]|RecC[]); test:assertEquals(csv1op2, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -681,42 +664,42 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|csv:Error csv1op3 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecC[]|RecA[]|csv:Error csv1op3 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op3, [ {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: ()} ]); - RecB[]|RecA[]|csv:Error csv1op4 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecB[]|RecA[]|csv:Error csv1op4 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op4, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - RecA[]|RecB[]|csv:Error csv1op5 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecA[]|RecB[]|csv:Error csv1op5 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op5, [ {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 a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseRecordAsRecordType(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:parseRecordAsRecordType(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:parseRecordAsRecordType(value, {}); + record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:transform(value, {}); test:assertEquals(csv1op8, [ {b: "string1"}, {b: "string2"}, @@ -725,7 +708,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {b: "string5"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseRecordAsRecordType(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}, @@ -734,7 +717,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, d: 3, e: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseRecordAsRecordType(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"}, @@ -743,7 +726,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseRecordAsRecordType(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"}, @@ -752,7 +735,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5"} ]); - record{|string a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op12 = csv:parseRecordAsRecordType(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...; |}[])'"); } @@ -767,7 +750,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - RecA[]|RecC[]|csv:Error csv1op1 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + RecA[]|RecC[]|csv:Error csv1op1 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op1, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, @@ -776,7 +759,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|csv:Error csv1op2 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecA[]|RecC[]|csv:Error csv1op2 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertTrue(csv1op2 is RecA[]|RecC[]); test:assertEquals(csv1op2, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -784,49 +767,49 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|csv:Error csv1op3 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecC[]|RecA[]|csv:Error csv1op3 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op3, [ {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: ()} ]); - RecB[]|RecA[]|csv:Error csv1op4 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecB[]|RecA[]|csv:Error csv1op4 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op4, [ {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: "()"} ]); - RecA[]|RecB[]|csv:Error csv1op5 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecA[]|RecB[]|csv:Error csv1op5 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op5, [ {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 a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseListAsRecordType(value, ["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:parseListAsRecordType(value, ["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:parseListAsRecordType(value, ["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:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); + 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}, @@ -835,23 +818,14 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, d: 3} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9_2 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); - test:assertEquals(csv1op9_2, [ - {}, - {}, - {}, - {}, - {} - ]); - - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseListAsRecordType(value, ["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:parseListAsRecordType(value, ["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}, @@ -860,11 +834,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", d: 3} ]); - record{|int a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op12 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); - test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(union_type_tests:record {| int a; int...; |}[]|union_type_tests:record {| int a; string...; |}[])'"); - - record{|int a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op13 = csv:parseListAsRecordType([["1", "2"], ["a", "b"]], ["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"} @@ -882,7 +852,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - TupA[]|TupC[]|csv:Error csv1op1 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + TupA[]|TupC[]|csv:Error csv1op1 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -891,7 +861,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupA[]|TupC[]|csv:Error csv1op2 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupA[]|TupC[]|csv:Error csv1op2 = csv:transform(value, {headersOrder: ["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, ()], @@ -899,62 +869,62 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupC[]|TupA[]|csv:Error csv1op3 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupC[]|TupA[]|csv:Error csv1op3 = csv:transform(value, {headersOrder: ["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:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupB[]|TupA[]|csv:Error csv1op4 = csv:transform(value, {headersOrder: ["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:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupB[]|[boolean][]|csv:Error csv1op4_2 = csv:transform(value, {headersOrder: ["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][])'"); - TupA[]|TupB[]|csv:Error csv1op5 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupA[]|TupB[]|csv:Error csv1op5 = csv:transform(value, {headersOrder: ["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:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + [int][]|[string][]|csv:Error csv1op6 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - [string][]|[int][]|csv:Error csv1op7 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + [string][]|[int][]|csv:Error csv1op7 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ [1], [3], [5] ]); - [string...][]|[int...][]|csv:Error csv1op8 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + [string...][]|[int...][]|csv:Error csv1op8 = csv:transform(value, {headersOrder: ["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...][])'"); - [int...][]|[string...][]|csv:Error csv1op9 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + [int...][]|[string...][]|csv:Error csv1op9 = csv:transform(value, {headersOrder: ["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...][])'"); - [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:transform(value, {headersOrder: ["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...][])'"); - [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:transform(value, {headersOrder: ["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...][])'"); - [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:transform(value, {headersOrder: ["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...][])'"); } @@ -969,7 +939,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - TupA[]|TupC[]|csv:Error csv1op1 = csv:parseListAsListType(value, {}); + TupA[]|TupC[]|csv:Error csv1op1 = csv:parseList(value, {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -978,7 +948,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupA[]|TupC[]|csv:Error csv1op2 = csv:parseListAsListType(value, {skipLines: [2, 4]}); + TupA[]|TupC[]|csv:Error csv1op2 = csv:parseList(value, {skipLines: [2, 4]}); test:assertTrue(csv1op2 is TupA[]|TupC[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -986,56 +956,52 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupC[]|TupA[]|csv:Error csv1op3 = csv:parseListAsListType(value, {skipLines: [2, 4]}); + TupC[]|TupA[]|csv:Error csv1op3 = csv:parseList(value, {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:parseListAsListType(value, {skipLines: [2, 4]}); + TupB[]|TupA[]|csv:Error csv1op4 = csv:parseList(value, {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:parseListAsListType(value, {skipLines: [2, 4]}); + 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][])'"); - TupA[]|TupB[]|csv:Error csv1op5 = csv:parseListAsListType(value, {skipLines: [2, 4]}); + TupA[]|TupB[]|csv:Error csv1op5 = csv:parseList(value, {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:parseListAsListType(value, {skipLines: [2, 4]}); + [int][]|[string][]|csv:Error csv1op6 = csv:parseList(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - [string][]|[int][]|csv:Error csv1op7 = csv:parseListAsListType(value, {skipLines: [2, 4]}); + [string][]|[int][]|csv:Error csv1op7 = csv:parseList(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ ["1"], ["3"], ["5"] ]); - [boolean...][]|[int...][]|csv:Error csv1op8 = csv:parseListAsListType(value, {stringConversion: false}); - test:assertTrue(csv1op8 is csv:Error); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...][]|[int...][])'"); - - [string...][]|[int...][]|csv:Error csv1op8_2 = csv:parseListAsListType(value, {}); + [string...][]|[int...][]|csv:Error csv1op8_2 = csv:parseList(value, {}); test:assertEquals(csv1op8_2, value); - [int...][]|[string...][]|csv:Error csv1op9 = csv:parseListAsListType(value, {}); + [int...][]|[string...][]|csv:Error csv1op9 = csv:parseList(value, {}); test:assertEquals(csv1op9, value); - [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:parseListAsListType(value, {}); + [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:parseList(value, {}); test:assertEquals(csv1op10, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -1044,7 +1010,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:parseListAsListType(value, {}); + [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:parseList(value, {}); test:assertEquals(csv1op11, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -1053,6 +1019,6 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:parseListAsListType(value, {}); + [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:parseList(value, {}); test:assertEquals(csv1op12, value); } diff --git a/ballerina-tests/user-config-tests/Ballerina.toml b/ballerina-tests/user-config-tests/Ballerina.toml index b4d56ea..7810c0a 100644 --- a/ballerina-tests/user-config-tests/Ballerina.toml +++ b/ballerina-tests/user-config-tests/Ballerina.toml @@ -13,4 +13,4 @@ version = "0.1.0" graalvmCompatible = true [build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" +graalvmBuildOptions = "-H:+IncludeAllLocales" 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 662cb9f..2ad8e88 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 @@ -20,270 +20,270 @@ import ballerina/test; @test:Config function testCustomNameAnnotation() returns error? { - RecordWithCustomAnnotation[]|csv:Error cn1 = csv:parseStringToRecord(string `b,c + RecordWithCustomAnnotation[]|csv:Error cn1 = csv:parseString(string `b,c 1,3`, {}); test:assertEquals(cn1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|csv:Error cn2 = csv:parseStringToRecord(string `c,b + RecordWithCustomAnnotation[]|csv:Error cn2 = csv:parseString(string `c,b 3,1`, {}); test:assertEquals(cn2, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|csv:Error cn3 = csv:parseStringToRecord(string `f,c,b,e + RecordWithCustomAnnotation[]|csv:Error cn3 = csv:parseString(string `f,c,b,e 3,3,1,"cde" 3,3,1,"cde"`, {}); test:assertEquals(cn3, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); - RecordWithCustomAnnotation2[]|csv:Error cn4 = csv:parseStringToRecord(string `d,c + RecordWithCustomAnnotation2[]|csv:Error cn4 = csv:parseString(string `d,c 1,3`, {}); test:assertEquals(cn4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|csv:Error cn5 = csv:parseStringToRecord(string `c,d + RecordWithCustomAnnotation2[]|csv:Error cn5 = csv:parseString(string `c,d 3,1`, {}); test:assertEquals(cn5, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|csv:Error cn6 = csv:parseStringToRecord(string `c,f,d,e + RecordWithCustomAnnotation2[]|csv:Error cn6 = csv:parseString(string `c,f,d,e 3,3,1,"cde" 3,3,1,"cde"`, {}); test:assertEquals(cn6, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); - RecordWithCustomAnnotation2[]|csv:Error cn7 = csv:parseStringToRecord(string `a,b + 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'"); - RecordWithCustomAnnotation2[]|csv:Error cn8 = csv:parseStringToRecord(string ` c,d,a,b + 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'"); - RecordWithCustomAnnotation3[]|csv:Error cn9 = csv:parseStringToRecord(string `d,c + RecordWithCustomAnnotation3[]|csv:Error cn9 = csv:parseString(string `d,c 1,3`, {}); test:assertEquals(cn9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cn10 = csv:parseStringToRecord(string `c,d + RecordWithCustomAnnotation3[]|csv:Error cn10 = csv:parseString(string `c,d 3,1`, {}); test:assertEquals(cn10, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cn11 = csv:parseStringToRecord(string `c,f,d,e + RecordWithCustomAnnotation3[]|csv:Error cn11 = csv:parseString(string `c,f,d,e 3,3,1,"cde" 3,3,1,"cde"`, {}); test:assertEquals(cn11, [{b: 1, a: 3}, {b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cn12 = csv:parseStringToRecord(string `a,b + 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'"); - RecordWithCustomAnnotation3[]|csv:Error cn13 = csv:parseStringToRecord(string ` c,d,a,b + 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'"); - RecordWithCustomAnnotation4[]|csv:Error cn14 = csv:parseStringToRecord(string `d,c,z + RecordWithCustomAnnotation4[]|csv:Error cn14 = csv:parseString(string `d,c,z 1,3,true`, {}); test:assertEquals(cn14, [{b: 1, a: 3, z: true}]); - RecordWithCustomAnnotation4[]|csv:Error cn15 = csv:parseStringToRecord(string `c,d + RecordWithCustomAnnotation4[]|csv:Error cn15 = csv:parseString(string `c,d 3,1`, {}); test:assertEquals(cn15, [{b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|csv:Error cn16 = csv:parseStringToRecord(string `c,f,d,e + RecordWithCustomAnnotation4[]|csv:Error cn16 = csv:parseString(string `c,f,d,e 3,3,1,"cde" 3,3,1,"cde"`, {}); test:assertEquals(cn16, [{b: 1, a: 3}, {b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|csv:Error cn17 = csv:parseStringToRecord(string `a,b + 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'"); - RecordWithCustomAnnotation4[]|csv:Error cn18 = csv:parseStringToRecord(string ` c,d,a,b + 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'"); - RecordWithCustomAnnotation5[]|csv:Error cn19 = csv:parseStringToRecord(string ` c,d,a,b + 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'"); - RecordWithCustomAnnotation5[]|csv:Error cn20 = csv:parseStringToRecord(string ` c,d,e + RecordWithCustomAnnotation5[]|csv:Error cn20 = csv:parseString(string ` c,d,e 3,1,4 3,1,4`, {}); test:assertEquals(cn20, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); - RecordWithCustomAnnotation6[]|csv:Error cn21 = csv:parseStringToRecord(string ` c,d,a + RecordWithCustomAnnotation6[]|csv:Error cn21 = csv:parseString(string ` c,d,a 3,1,4 3,1,4`, {}); test:assertEquals(cn21, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); - RecordWithCustomAnnotation[]|csv:Error cnrr1 = csv:parseRecordAsRecordType([{"b": 1, "c": 3}], {}); + RecordWithCustomAnnotation[]|csv:Error cnrr1 = csv:transform([{"b": 1, "c": 3}], {}); test:assertEquals(cnrr1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|csv:Error cnrr2 = csv:parseRecordAsRecordType([{"c": 3, "b": 1}], {}); + RecordWithCustomAnnotation[]|csv:Error cnrr2 = csv:transform([{"c": 3, "b": 1}], {}); test:assertEquals(cnrr2, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|csv:Error cnrr3 = csv:parseRecordAsRecordType( + RecordWithCustomAnnotation[]|csv:Error cnrr3 = csv:transform( [{"f": 3, "c": 3, "b": 1, "e": "cde"}, {"f": 3, "c": 3, "b": 1, "e": "cde"}], {}); test:assertEquals(cnrr3, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); - RecordWithCustomAnnotation2[]|csv:Error cnrr4 = csv:parseRecordAsRecordType([{"d": 1, "c": 3}], {}); + RecordWithCustomAnnotation2[]|csv:Error cnrr4 = csv:transform([{"d": 1, "c": 3}], {}); test:assertEquals(cnrr4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|csv:Error cnrr5 = csv:parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + RecordWithCustomAnnotation2[]|csv:Error cnrr5 = csv:transform([{"c": 3, "d": 1}], {}); test:assertEquals(cnrr5, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|csv:Error cnrr6 = csv:parseRecordAsRecordType( + RecordWithCustomAnnotation2[]|csv:Error cnrr6 = csv:transform( [{"c": 3, "f": 3, "d": 1, "e": "cde"}, {"c": 3, "f": 3, "d": 1, "e": "cde"}], {}); test:assertEquals(cnrr6, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); - RecordWithCustomAnnotation2[]|csv:Error cnrr7 = csv:parseRecordAsRecordType([{"a":3, "b": 1}], {}); + 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'"); - RecordWithCustomAnnotation2[]|csv:Error cnrr8 = csv:parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + 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'"); - RecordWithCustomAnnotation3[]|csv:Error cnrr9 = csv:parseRecordAsRecordType([{"d": 1, "c": 3}], {}); + RecordWithCustomAnnotation3[]|csv:Error cnrr9 = csv:transform([{"d": 1, "c": 3}], {}); test:assertEquals(cnrr9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cnrr10 = csv:parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + RecordWithCustomAnnotation3[]|csv:Error cnrr10 = csv:transform([{"c": 3, "d": 1}], {}); test:assertEquals(cnrr10, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cnrr11 = csv:parseRecordAsRecordType( + RecordWithCustomAnnotation3[]|csv:Error cnrr11 = csv:transform( [{"c": 3, "f": 3, "d": 1, "e": "cde"}, {"c": 3, "f": 3, "d": 1, "e": "cde"}], {}); test:assertEquals(cnrr11, [{b: 1, a: 3}, {b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cnrr12 = csv:parseRecordAsRecordType([{"a": 3, "b": 1}], {}); + 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'"); - RecordWithCustomAnnotation3[]|csv:Error cnrr13 = csv:parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + 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'"); - RecordWithCustomAnnotation4[]|csv:Error cnrr14 = csv:parseRecordAsRecordType([{"d": 1, "c": 3, "z": true}], {}); + RecordWithCustomAnnotation4[]|csv:Error cnrr14 = csv:transform([{"d": 1, "c": 3, "z": true}], {}); test:assertEquals(cnrr14, [{b: 1, a: 3, z: true}]); - RecordWithCustomAnnotation4[]|csv:Error cnrr15 = csv:parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + RecordWithCustomAnnotation4[]|csv:Error cnrr15 = csv:transform([{"c": 3, "d": 1}], {}); test:assertEquals(cnrr15, [{b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|csv:Error cnrr16 = csv:parseRecordAsRecordType( + RecordWithCustomAnnotation4[]|csv:Error cnrr16 = csv:transform( [{"c": 3, "f": 3, "d": 1, "e": "cde"}, {"c": 3, "f": 3, "d": 1, "e": "cde"}], {}); test:assertEquals(cnrr16, [{b: 1, a: 3}, {b: 1, a: 3}]); - RecordWithCustomAnnotation5[]|csv:Error cnrr20 = csv:parseRecordAsRecordType( + RecordWithCustomAnnotation5[]|csv:Error cnrr20 = csv:transform( [{"c": 3, "d": 1, "e": 4}, {"c": 3, "d": 1, "e": 4}], {}); test:assertEquals(cnrr20, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); - RecordWithCustomAnnotation6[]|csv:Error cnrr21 = csv:parseRecordAsRecordType( + RecordWithCustomAnnotation6[]|csv:Error cnrr21 = csv:transform( [{"c": 3, "d": 1, "a": 4}, {"c": 3, "d": 1, "a": 4}], {}); test:assertEquals(cnrr21, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); } @test:Config function testCustomNameAnnotation2() returns error? { - RecordWithCustomAnnotation[]|csv:Error cntr1 = csv:parseListAsRecordType([["1", "3"]], ["b", "c"], {}); + RecordWithCustomAnnotation[]|csv:Error cntr1 = csv:parseList([["1", "3"]], {customHeaders: ["b", "c"]}); test:assertEquals(cntr1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|csv:Error cntr2 = csv:parseListAsRecordType([["3", "1"]], ["c", "b"], {}); + RecordWithCustomAnnotation[]|csv:Error cntr2 = csv:parseList([["3", "1"]], {customHeaders: ["c", "b"]}); test:assertEquals(cntr2, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|csv:Error cntr3 = csv:parseListAsRecordType( - [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["f", "c", "b", "e"], {}); + RecordWithCustomAnnotation[]|csv:Error cntr3 = csv:parseList( + [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], {customHeaders: ["f", "c", "b", "e"]}); test:assertEquals(cntr3, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); - RecordWithCustomAnnotation2[]|csv:Error cntr4 = csv:parseListAsRecordType([["1", "3"]], ["d", "c"], {}); + RecordWithCustomAnnotation2[]|csv:Error cntr4 = csv:parseList([["1", "3"]], {customHeaders: ["d", "c"]}); test:assertEquals(cntr4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|csv:Error cntr5 = csv:parseListAsRecordType([["3","1"]], ["c", "d"], {}); + RecordWithCustomAnnotation2[]|csv:Error cntr5 = csv:parseList([["3","1"]], {customHeaders: ["c", "d"]}); test:assertEquals(cntr5, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|csv:Error cntr6 = csv:parseListAsRecordType( - [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); + RecordWithCustomAnnotation2[]|csv:Error cntr6 = csv:parseList( + [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], {customHeaders: ["c", "f", "d", "e"]}); test:assertEquals(cntr6, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); - RecordWithCustomAnnotation2[]|csv:Error cntr7 = csv:parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + 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'"); - RecordWithCustomAnnotation2[]|csv:Error cntr8 = csv:parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + 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'"); - RecordWithCustomAnnotation3[]|csv:Error cntr9 = csv:parseListAsRecordType([["1", "3"]], ["d", "c"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr9 = csv:parseList([["1", "3"]], {customHeaders: ["d", "c"]}); test:assertEquals(cntr9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cntr10 = csv:parseListAsRecordType([["3", "1"]], ["c", "d"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr10 = csv:parseList([["3", "1"]], {customHeaders: ["c", "d"]}); test:assertEquals(cntr10, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cntr11 = csv:parseListAsRecordType( - [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr11 = csv:parseList( + [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], {customHeaders: ["c", "f", "d", "e"]}); test:assertEquals(cntr11, [{b: 1, a: 3}, {b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cntr12 = csv:parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr12 = csv:parseList([["3", "1"]], {customHeaders: ["a", "b"]}); test:assertTrue(cntr12 is csv:Error); test:assertEquals((cntr12).message(), common:generateErrorMessageForInvalidHeaders(string `["3","1"]`, "user_config_tests:RecordWithCustomAnnotation3")); - RecordWithCustomAnnotation3[]|csv:Error cntr13 = csv:parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + 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'"); - RecordWithCustomAnnotation4[]|csv:Error cntr14 = csv:parseListAsRecordType([["1", "3", "true"]], ["d", "c", "z"], {}); + RecordWithCustomAnnotation4[]|csv:Error cntr14 = csv:parseList([["1", "3", "true"]], {customHeaders: ["d", "c", "z"]}); test:assertEquals(cntr14, [{b: 1, a: 3, z: true}]); - RecordWithCustomAnnotation4[]|csv:Error cntr15 = csv:parseListAsRecordType([["3", "1"]], ["c", "d"], {}); + RecordWithCustomAnnotation4[]|csv:Error cntr15 = csv:parseList([["3", "1"]], {customHeaders: ["c", "d"]}); test:assertEquals(cntr15, [{b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|csv:Error cntr16 = csv:parseListAsRecordType( - [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); + RecordWithCustomAnnotation4[]|csv:Error cntr16 = csv:parseList( + [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], {customHeaders: ["c", "f", "d", "e"]}); test:assertEquals(cntr16, [{b: 1, a: 3}, {b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|csv:Error cntr17 = csv:parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + 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'"); - RecordWithCustomAnnotation4[]|csv:Error cntr18 = csv:parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + 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'"); - RecordWithCustomAnnotation5[]|csv:Error cntr19 = csv:parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + 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'"); - RecordWithCustomAnnotation5[]|csv:Error cntr20 = csv:parseListAsRecordType( - [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "e"], {}); + RecordWithCustomAnnotation5[]|csv:Error cntr20 = csv:parseList( + [["3", "1", "4"], ["3", "1", "4"]], {customHeaders: ["c", "d", "e"]}); test:assertEquals(cntr20, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); - RecordWithCustomAnnotation6[]|csv:Error cntr21 = csv:parseListAsRecordType( - [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "a"], {}); + RecordWithCustomAnnotation6[]|csv:Error cntr21 = csv:parseList( + [["3", "1", "4"], ["3", "1", "4"]], {customHeaders: ["c", "d", "a"]}); test:assertEquals(cntr21, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); } @test:Config function testAbsentAsNilableConfig() returns error? { - record {|int a; int? g; int? h;|}[]|csv:Error cn = csv:parseStringToRecord(csvStringData1, { + record {|int a; int? g; int? h;|}[]|csv:Error cn = csv:parseString(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1 }); test:assertEquals(cn, [{a: 1, g: (), h: ()}, {a: 2, g: (), h: ()}, {a: 3, g: (), h: ()}, {a: 4, g: (), h: ()}, {a: 5, g: (), h: ()}]); - record {|int a; int? g?;|}[]|csv:Error cn2 = csv:parseStringToRecord(csvStringData1, { + record {|int a; int? g?;|}[]|csv:Error cn2 = csv:parseString(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn2, [{a: 1}]); - record {|int a; int g?;|}[]|csv:Error cn3 = csv:parseStringToRecord(csvStringData1, { + record {|int a; int g?;|}[]|csv:Error cn3 = csv:parseString(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn3, [{a: 1}]); - record {|int a; int g;|}[]|csv:Error cn4 = csv:parseStringToRecord(csvStringData1, { + record {|int a; int g;|}[]|csv:Error cn4 = csv:parseString(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" @@ -291,7 +291,7 @@ function testAbsentAsNilableConfig() returns error? { test:assertTrue(cn4 is csv:Error); test:assertEquals((cn4).message(), common:generateErrorMessageForMissingRequiredField("g")); - int?[][]|csv:Error cn5 = csv:parseStringToList(string ` + int?[][]|csv:Error cn5 = csv:parseString(string ` a,b,c 1, 1,1`, { allowDataProjection: {absentAsNilableType: true}, @@ -299,7 +299,7 @@ function testAbsentAsNilableConfig() returns error? { }); test:assertEquals(cn5, [[1, 1, 1]]); - map[]|csv:Error cn6 = csv:parseStringToRecord(string ` + map[]|csv:Error cn6 = csv:parseString(string ` a,b,c 1, 1,1`, { allowDataProjection: {absentAsNilableType: true}, @@ -307,28 +307,28 @@ function testAbsentAsNilableConfig() returns error? { }); test:assertEquals(cn6, [{a: 1, b: 1, c: 1}]); - [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn7 = csv:parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn7 = csv:parseString(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn7, [[1, "string1", true, 2.234, 2.234, null, null]]); - [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn8 = csv:parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn8 = csv:parseString(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn8, [[1, "string1", true, 2.234, 2.234, null, null]]); - [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn9 = csv:parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn9 = csv:parseString(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn9, [[1, "string1", true, 2.234, 2.234, null, null]]); - [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn10 = csv:parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn10 = csv:parseString(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" @@ -338,43 +338,43 @@ function testAbsentAsNilableConfig() returns error? { @test:Config function testAbsentAsNilableConfig2() returns error? { - record {|int a; int? g; int? h;|}[]|csv:Error cn = csv:parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int? g; int? h;|}[]|csv:Error cn = csv:transform([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn, [{a: 1, g: (), h: ()}, {a: 2, g: (), h: ()}]); - record {|int a; int? g?;|}[]|csv:Error cn2 = csv:parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int? g?;|}[]|csv:Error cn2 = csv:transform([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn2, [{a: 1}, {a: 2}]); - record {|int a; int g?;|}[]|csv:Error cn3 = csv:parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int g?;|}[]|csv:Error cn3 = csv:transform([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn3, [{a: 1}, {a: 2}]); - record {|int a; int g;|}[]|csv:Error cn4 = csv:parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int g;|}[]|csv:Error cn4 = csv:transform([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertTrue(cn4 is csv:Error); test:assertEquals((cn4).message(), common:generateErrorMessageForMissingRequiredField("g")); - record {|string a; int? g; int? h;|}[]|csv:Error cn5 = csv:parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int? g; int? h;|}[]|csv:Error cn5 = csv:parseList([["a"], ["a"], ["a"]], {customHeaders: ["a"], allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn5, [{a: "a", g: (), h: ()}, {a: "a", g: (), h: ()}]); - record {|string a; int? g?;|}[]|csv:Error cn6 = csv:parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int? g?;|}[]|csv:Error cn6 = csv:parseList([["a"], ["a"], ["a"]], {customHeaders: ["a"], allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn6, [{a: "a"}, {a: "a"}]); - record {|string a; int g?;|}[]|csv:Error cn7 = csv:parseListAsRecordType([["a"], ["a"], ["b"]], ["a"], { + record {|string a; int g?;|}[]|csv:Error cn7 = csv:parseList([["a"], ["a"], ["b"]], {customHeaders: ["a"], allowDataProjection: {absentAsNilableType: true}, skipLines: [2] }); test:assertEquals(cn7, [{a: "a"}, {a: "b"}]); - record {|string a; int g;|}[]|csv:Error cn8 = csv:parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int g;|}[]|csv:Error cn8 = csv:parseList([["a"], ["a"], ["a"]], {customHeaders: ["a"], allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertTrue(cn8 is csv:Error); @@ -383,27 +383,27 @@ function testAbsentAsNilableConfig2() returns error? { @test:Config function testNilAsOptionalConfig() returns error? { - record {|int a; int f?;|}[]|csv:Error cn = csv:parseStringToRecord(csvStringData1, { + record {|int a; int f?;|}[]|csv:Error cn = csv:parseString(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1 }); test:assertEquals(cn, [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]); - record {|int a; int? f?;|}[]|csv:Error cn2 = csv:parseStringToRecord(csvStringData1, { + record {|int a; int? f?;|}[]|csv:Error cn2 = csv:parseString(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn2, [{a: 1, f: ()}]); - record {|int a; int f?;|}[]|csv:Error cn3 = csv:parseStringToRecord(csvStringData1, { + record {|int a; int f?;|}[]|csv:Error cn3 = csv:parseString(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn3, [{a: 1}]); - record {|int a; int f;|}[]|csv:Error cn4 = csv:parseStringToRecord(csvStringData1, { + record {|int a; int f;|}[]|csv:Error cn4 = csv:parseString(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" @@ -411,7 +411,7 @@ function testNilAsOptionalConfig() returns error? { test:assertTrue(cn4 is csv:Error); test:assertEquals((cn4).message(), common:generateErrorMessageForInvalidCast("()", "int")); - int?[][]|csv:Error cn5 = csv:parseStringToList(string ` + int?[][]|csv:Error cn5 = csv:parseString(string ` a,b,c 1, 1,1`, { allowDataProjection: {nilAsOptionalField: true}, @@ -419,7 +419,7 @@ function testNilAsOptionalConfig() returns error? { }); test:assertEquals(cn5, [[1, 1, 1]]); - map[]|csv:Error cn6 = csv:parseStringToRecord(string ` + map[]|csv:Error cn6 = csv:parseString(string ` a,b,c 1, 1,1`, { allowDataProjection: {nilAsOptionalField: true}, @@ -427,28 +427,28 @@ function testNilAsOptionalConfig() returns error? { }); test:assertEquals(cn6, [{a: 1, b: 1, c: 1}]); - [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn7 = csv:parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn7 = csv:parseString(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn7, [[1, "string1", true, 2.234, 2.234, null, null]]); - [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn8 = csv:parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn8 = csv:parseString(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn8, [[1, "string1", true, 2.234, 2.234, null, null]]); - [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn9 = csv:parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn9 = csv:parseString(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn9, [[1, "string1", true, 2.234, 2.234, null, null]]); - [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn10 = csv:parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn10 = csv:parseString(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" @@ -458,22 +458,22 @@ function testNilAsOptionalConfig() returns error? { @test:Config function testNilAsOptionalConfig2() returns error? { - record {|int a; int? f;|}[]|csv:Error cn = csv:parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int? f;|}[]|csv:Error cn = csv:transform([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] }); test:assertEquals(cn, [{a: 1, f: ()}, {a: 2, f: ()}]); - record {|int a; int? f?;|}[]|csv:Error cn2 = csv:parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int? f?;|}[]|csv:Error cn2 = csv:transform([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] }); test:assertEquals(cn2, [{a: 1, f: ()}, {a: 2, f: ()}]); - record {|int a; int f?;|}[]|csv:Error cn3 = csv:parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int f?;|}[]|csv:Error cn3 = csv:transform([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] }); test:assertEquals(cn3, [{a: 1}, {a: 2}]); - record {|int a; int f;|}[]|csv:Error cn4 = csv:parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int f;|}[]|csv:Error cn4 = csv:transform([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] }); test:assertTrue(cn4 is csv:Error); @@ -487,187 +487,187 @@ function testDataProjectionConfig() returns error? { b,4`; record{}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; - record{}[]|csv:Error cn = csv:parseStringToRecord(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:parseStringToRecord(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:parseStringToRecord(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'"); - record{|string a; int...;|}[]|csv:Error cn3 = csv:parseStringToRecord(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:parseStringToRecord(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:parseStringToRecord(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'"); - record{|string? a;|}[]|csv:Error cn6 = csv:parseStringToRecord(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'"); - anydata[][]|csv:Error c7 = csv:parseStringToList(csvValue1, { + anydata[][]|csv:Error c7 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(c7, [["a", 2], ["b", 4]]); - [string, int][]|csv:Error cn7_2 = csv:parseStringToList(csvValue1, { + [string, int][]|csv:Error cn7_2 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn7_2, [["a", 2], ["b", 4]]); - [string][]|csv:Error cn8 = csv:parseStringToList(csvValue1, { + [string][]|csv:Error cn8 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertTrue(cn8 is csv:Error); test:assertEquals((cn8).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); - [string][]|csv:Error cn8_2 = csv:parseStringToList(csvValue1, { + [string][]|csv:Error cn8_2 = csv:parseString(csvValue1, { allowDataProjection: {} }); test:assertEquals(cn8_2, [["a"], ["b"]]); - [int][]|csv:Error cn8_3 = csv:parseStringToList(csvValue1, { + [int][]|csv:Error cn8_3 = csv:parseString(csvValue1, { allowDataProjection: {} }); test:assertTrue(cn8_3 is csv:Error); test:assertEquals((cn8_3).message(), common:generateErrorMessageForInvalidCast("a", "int")); - [string, int...][]|csv:Error cn9 = csv:parseStringToList(csvValue1, { + [string, int...][]|csv:Error cn9 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn9, [["a", 2], ["b", 4]]); - [string...][]|csv:Error cn10 = csv:parseStringToList(csvValue1, { + [string...][]|csv:Error cn10 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn10, [["a", "2"], ["b", "4"]]); - [string, ()][]|csv:Error cn11 = csv:parseStringToList(csvValue1, { + [string, ()][]|csv:Error cn11 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertTrue(cn11 is csv:Error); test:assertEquals((cn11).message(), common:generateErrorMessageForInvalidCast("2", "()")); - string[][]|csv:Error cn12 = csv:parseStringToList(csvValue1, { + string[][]|csv:Error cn12 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn12, [["a", "2"], ["b", "4"]]); - string[][1]|csv:Error cn13 = csv:parseStringToList(csvValue1, { + string[][1]|csv:Error cn13 = csv:parseString(csvValue1, { allowDataProjection: false }); 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:parseRecordAsRecordType(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:parseRecordAsRecordType(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:parseRecordAsRecordType(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'"); - record{|string a; int...;|}[]|csv:Error cn16 = csv:parseRecordAsRecordType(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:parseRecordAsRecordType(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:parseRecordAsRecordType(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'"); - record{|string? a;|}[]|csv:Error cn19 = csv:parseRecordAsRecordType(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'"); - anydata[][]|csv:Error c20 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ + anydata[][]|csv:Error c20 = csv:transform(csvValue2, {headersOrder: ["a", "b"], allowDataProjection: false }); test:assertEquals(c20, [["a", 2], ["b", 4]]); - [string, int][]|csv:Error cn20_2 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string, int][]|csv:Error cn20_2 = csv:transform(csvValue2, {headersOrder: ["a", "b"], allowDataProjection: false }); test:assertEquals(cn20_2, [["a", 2], ["b", 4]]); - [string][]|csv:Error cn21 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string][]|csv:Error cn21 = csv:transform(csvValue2, {headersOrder: ["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:parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string][]|csv:Error cn21_2 = csv:transform(csvValue2, {headersOrder: ["a", "b"], allowDataProjection: {} }); test:assertEquals(cn21_2, [["a"], ["b"]]); - [int][]|csv:Error cn21_3 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [int][]|csv:Error cn21_3 = csv:transform(csvValue2, {headersOrder: ["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:parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string, int...][]|csv:Error cn22 = csv:transform(csvValue2, {headersOrder: ["a", "b"], allowDataProjection: false }); test:assertEquals(cn22, [["a", 2], ["b", 4]]); - [string...][]|csv:Error cn23 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string...][]|csv:Error cn23 = csv:transform(csvValue2, {headersOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn23 is csv:Error); test:assertEquals(( cn23).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - [string, ()][]|csv:Error cn24 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string, ()][]|csv:Error cn24 = csv:transform(csvValue2, {headersOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn24 is csv:Error); test:assertEquals((cn24).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "()")); - string[][]|csv:Error cn25 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ + string[][]|csv:Error cn25 = csv:transform(csvValue2, {headersOrder: ["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:parseRecordAsListType(csvValue2, ["a", "b"] ,{ + string[][1]|csv:Error cn26 = csv:transform(csvValue2, {headersOrder: ["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 1dfcbc0..10a83a9 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 @@ -20,7 +20,7 @@ import ballerina/test; @test:Config function testCSVEncoding() returns error? { - record {}[]|csv:Error rec; + record {}[]|csv:Error rec; string csvStr = string `value Alice @@ -28,192 +28,192 @@ function testCSVEncoding() returns error? { €123`; byte[] csvBytes = string:toBytes(csvStr); - rec = csv:parseBytesToRecord(csvBytes, {locale: "fr_FR", encoding: "ISO-8859-1"}); + rec = csv:parseBytes(csvBytes, {locale: "fr_FR", encoding: "ISO-8859-1"}); test:assertEquals((check rec)[0], {value: "Alice"}); } @test:Config function testCSVLocale() { - record {|string name; decimal completed\ tasks; string city;|}[]|csv:Error rec; + record {|string name; decimal completed\ tasks; string city;|}[]|csv:Error rec; - rec = csv:parseStringToRecord(string ` + rec = csv:parseString(string ` name, completed tasks, city Alice, "1234", New York Bob, "1,234", London €123, "12,34", Berlin`, {header: 1, locale: "fr_FR"}); - test:assertEquals(rec, [ - {name: "Alice", "completed tasks": 1234, city: "New York"}, - {name: "Bob", "completed tasks": 1.234, city: "London"}, - {name: "€123", "completed tasks": 12.34, city: "Berlin"} - ]); + test:assertEquals(rec, [ + {name: "Alice", "completed tasks": 1234, city: "New York"}, + {name: "Bob", "completed tasks": 1.234, city: "London"}, + {name: "€123", "completed tasks": 12.34, city: "Berlin"} + ]); - rec = csv:parseStringToRecord(string ` + rec = csv:parseString(string ` name, completed tasks, city Alice, "1234", New York Bob, "1.234", London €123, "12.34", Berlin`, {header: 1, locale: "en"}); test:assertEquals(rec, [ - {name: "Alice", "completed tasks": 1234, city: "New York"}, - {name: "Bob", "completed tasks": 1.234, city: "London"}, - {name: "€123", "completed tasks": 12.34, city: "Berlin"} - ]); + {name: "Alice", "completed tasks": 1234, city: "New York"}, + {name: "Bob", "completed tasks": 1.234, city: "London"}, + {name: "€123", "completed tasks": 12.34, city: "Berlin"} + ]); - rec = csv:parseStringToRecord(string ` + rec = csv:parseString(string ` name, completed tasks, city Alice, "1234", New York Bob, "1.234", London €123, "12.34", Berlin`, {header: 1, locale: "en_US_WIN"}); - test:assertEquals(rec, [ - {name: "Alice", "completed tasks": 1234, city: "New York"}, - {name: "Bob", "completed tasks": 1.234, city: "London"}, - {name: "€123", "completed tasks": 12.34, city: "Berlin"} - ]); + test:assertEquals(rec, [ + {name: "Alice", "completed tasks": 1234, city: "New York"}, + {name: "Bob", "completed tasks": 1.234, city: "London"}, + {name: "€123", "completed tasks": 12.34, city: "Berlin"} + ]); } @test:Config {dependsOn: [testCSVLocale]} function testFromCsvStringWithParserOptions() { - [int, string, boolean, decimal, float, string][]|csv:Error csv1op3 = csv:parseStringToList(csvStringData1, option3); + [int, string, boolean, decimal, float, string][]|csv:Error csv1op3 = csv:parseString(csvStringData1, option3); test:assertEquals(csv1op3, [ - [3, "string3", false, 1.23, 1.23, "()"], - [4, "string4", true, -6.51, -6.51, "()"], - [5, "string5", true, 3, 3.0, "()"] - ]); + [3, "string3", false, 1.23, 1.23, "()"], + [4, "string4", true, -6.51, -6.51, "()"], + [5, "string5", true, 3, 3.0, "()"] + ]); - record {int a; string b; boolean c; decimal d; float e; string f;}[]|csv:Error csv1op3_2 = csv:parseStringToRecord(csvStringData1, ptOption1); + record {int a; string b; boolean c; decimal d; float e; string f;}[]|csv:Error csv1op3_2 = csv:parseString(csvStringData1, ptOption1); test:assertEquals(csv1op3_2, [ - {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: "()"} - ]); + {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 a; string b; boolean c; decimal d; float e; string f;}[]|csv:Error csv1op3_3 = csv:parseStringToRecord(csvStringData1, ptOption2); + record {int a; string b; boolean c; decimal d; float e; string f;}[]|csv:Error csv1op3_3 = csv:parseString(csvStringData1, ptOption2); test:assertEquals(csv1op3_3, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, - {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: "()"} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, + {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: "()"} + ]); - [int, string, boolean, decimal, float, string][]|csv:Error csv2op4 = csv:parseStringToList(csvStringData2, option4); + [int, string, boolean, decimal, float, string][]|csv:Error csv2op4 = csv:parseString(csvStringData2, option4); test:assertEquals(csv2op4, []); - record {}[]|csv:Error csv2op4_2 = csv:parseStringToRecord(csvStringData2, ptOption3); + record {}[]|csv:Error csv2op4_2 = csv:parseString(csvStringData2, ptOption3); test:assertEquals(csv2op4_2, []); - record {}[]|csv:Error csv2op4_3 = csv:parseStringToRecord(csvStringData2, ptOption4); + record {}[]|csv:Error csv2op4_3 = csv:parseString(csvStringData2, ptOption4); test:assertEquals(csv2op4_3, [ - {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, f: "()"} - ]); + {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, f: "()"} + ]); - [int, string, boolean, decimal, float, string][]|csv:Error csv3op3 = csv:parseStringToList(csvStringData3, option3); + [int, string, boolean, decimal, float, string][]|csv:Error csv3op3 = csv:parseString(csvStringData3, option3); test:assertEquals(csv3op3, [ - [3, "string3", false, 1.23, 1.23, "()"], - [4, "string4", true, -6.51, -6.51, "()"], - [5, "string5", true, 3, 3.0, "()"] - ]); + [3, "string3", false, 1.23, 1.23, "()"], + [4, "string4", true, -6.51, -6.51, "()"], + [5, "string5", true, 3, 3.0, "()"] + ]); - record {}[]|csv:Error csv3op3_2 = csv:parseStringToRecord(csvStringData3, ptOption1); + record {}[]|csv:Error csv3op3_2 = csv:parseString(csvStringData3, ptOption1); test:assertEquals(csv3op3_2, [ - {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, f: "()"} - ]); + {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, f: "()"} + ]); - record {}[]|csv:Error csv3op3_3 = csv:parseStringToRecord(csvStringData3, ptOption2); + record {}[]|csv:Error csv3op3_3 = csv:parseString(csvStringData3, ptOption2); test:assertEquals(csv3op3_3, [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} - ]); + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} + ]); - record {}[]|csv:Error csv3op3_4 = csv:parseStringToRecord(csvStringData3, {header: 9, skipLines: "2-10"}); + record {}[]|csv:Error csv3op3_4 = csv:parseString(csvStringData3, {header: 9, skipLines: "2-10"}); test:assertEquals(csv3op3_4, [ - {'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": null} - ]); + {'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": null} + ]); } @test:Config {dependsOn: [testCSVLocale]} function testFromCsvStringWithHeaderLessParserOptions() { - [int, string, boolean, decimal, float, ()][]|csv:Error csv1op6 = csv:parseStringToList(csvStringData1, option6); + [int, string, boolean, decimal, float, ()][]|csv:Error csv1op6 = csv:parseString(csvStringData1, option6); test:assertTrue(csv1op6 is csv:Error); test:assertEquals((csv1op6).message(), common:generateErrorMessageForInvalidCast("null", "()")); - record {}[]|csv:Error csv1op5_2 = csv:parseStringToRecord(csvStringData1, ptOption5); + record {}[]|csv:Error csv1op5_2 = csv:parseString(csvStringData1, ptOption5); test:assertEquals(csv1op5_2, [ - {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); - record {}[]|csv:Error csv1op6_2 = csv:parseStringToRecord(csvStringData1, {header: false, skipLines: [3, 5]}); + record {}[]|csv:Error csv1op6_2 = csv:parseString(csvStringData1, {header: false, skipLines: [3, 5]}); test:assertEquals(csv1op6_2, [ - {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); - record {}[]|csv:Error csv3op6_2 = csv:parseStringToRecord(csvStringData3, {header: false, skipLines: [1, 3, 5, -1, 100, 100]}); + record {}[]|csv:Error csv3op6_2 = csv:parseString(csvStringData3, {header: false, skipLines: [1, 3, 5, -1, 100, 100]}); test:assertEquals(csv3op6_2, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); - record {}[]|csv:Error csv4op6_2 = csv:parseStringToRecord(csvStringData4, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|csv:Error csv4op6_2 = csv:parseString(csvStringData4, {header: false, skipLines: [2, 4, -1, 100, 100]}); test:assertEquals(csv4op6_2, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); - record {}[]|csv:Error csv5op6_2 = csv:parseStringToRecord(csvStringData5, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|csv:Error csv5op6_2 = csv:parseString(csvStringData5, {header: false, skipLines: [2, 4, -1, 100, 100]}); test:assertEquals(csv5op6_2, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); - record {}[]|csv:Error csv6op6_2 = csv:parseStringToRecord(csvStringData6, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|csv:Error csv6op6_2 = csv:parseString(csvStringData6, {header: false, skipLines: [2, 4, -1, 100, 100]}); test:assertEquals(csv6op6_2, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); - record {}[]|csv:Error csv2op6_2 = csv:parseStringToRecord(csvStringData2, {header: false, skipLines: [5, 7]}); + record {}[]|csv:Error csv2op6_2 = csv:parseString(csvStringData2, {header: false, skipLines: [5, 7]}); test:assertEquals(csv2op6_2, [ - {'1: "hello", '2: "hello", '3: (), '4: 12, '5: true, '6: 12.34}, - {'1: "// comment"}, - {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + {'1: "hello", '2: "hello", '3: (), '4: 12, '5: true, '6: 12.34}, + {'1: "// comment"}, + {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 3, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); } @test:Config {dependsOn: [testCSVLocale]} function testHeaderOption() { - record {}[]|csv:Error csv2cop1 = csv:parseStringToRecord(csvStringData2, {header: 4}); + record {}[]|csv:Error csv2cop1 = csv:parseString(csvStringData2, {header: 4}); test:assertEquals(csv2cop1, [ - {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: ()}, - {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} - ]); - - record {}[]|csv:Error csv2cop2 = csv:parseStringToRecord(csvStringData2, {header: 100}); + {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: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); + + record {}[]|csv:Error csv2cop2 = csv:parseString(csvStringData2, {header: 100}); test:assertTrue(csv2cop2 is csv:Error); - test:assertEquals(( csv2cop2).message(), "The provided header row is empty"); + test:assertEquals((csv2cop2).message(), "The provided header row is empty"); - record {}[]|csv:Error csv2cop3 = csv:parseStringToRecord(csvStringData2, {header: 11}); + record {}[]|csv:Error csv2cop3 = csv:parseString(csvStringData2, {header: 11}); test:assertEquals(csv2cop3, []); - record {}[]|csv:Error csv2cop4 = csv:parseStringToRecord(csvStringData2, {header: 10}); + record {}[]|csv:Error csv2cop4 = csv:parseString(csvStringData2, {header: 10}); test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": ()}]); - record {}[]|csv:Error csv1cop5 = csv:parseStringToRecord(csvStringData1, {}); + record {}[]|csv:Error csv1cop5 = csv:parseString(csvStringData1, {}); test:assertTrue(csv1cop5 is csv:Error); test:assertEquals((csv1cop5).message(), "The provided header row is empty"); } @@ -231,58 +231,58 @@ function testNullConfigOption() { string csvValue5 = string `b, a bN/Aa,N/A`; - record {() a;}[]|csv:Error cn = csv:parseStringToRecord(csvValue1, {nilValue: ()}); + record {() a;}[]|csv:Error cn = csv:parseString(csvValue1, {nilValue: ()}); test:assertEquals(cn, [{a: ()}]); - cn = csv:parseStringToRecord(csvValue2, {nilValue: ()}); + cn = csv:parseString(csvValue2, {nilValue: ()}); test:assertEquals(cn, [{a: ()}]); - cn = csv:parseStringToRecord(csvValue3, {nilValue: ()}); + cn = csv:parseString(csvValue3, {nilValue: ()}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("e", "()")); - cn = csv:parseStringToRecord(csvValue4, {nilValue: ()}); + cn = csv:parseString(csvValue4, {nilValue: ()}); test:assertEquals(cn, [{a: ()}]); - cn = csv:parseStringToRecord(csvValue1, {nilValue: null}); + cn = csv:parseString(csvValue1, {nilValue: null}); test:assertEquals(cn, [{a: ()}]); - cn = csv:parseStringToRecord(csvValue2, {nilValue: null}); + cn = csv:parseString(csvValue2, {nilValue: null}); test:assertEquals(cn, [{a: ()}]); - cn = csv:parseStringToRecord(csvValue3, {nilValue: null}); + cn = csv:parseString(csvValue3, {nilValue: null}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("e", "()")); - cn = csv:parseStringToRecord(csvValue4, {nilValue: null}); + cn = csv:parseString(csvValue4, {nilValue: null}); test:assertEquals(cn, [{a: ()}]); - cn = csv:parseStringToRecord(csvValue1, {nilValue: "()"}); + cn = csv:parseString(csvValue1, {nilValue: "()"}); test:assertEquals(cn, [{a: ()}]); - cn = csv:parseStringToRecord(csvValue2, {nilValue: "()"}); + cn = csv:parseString(csvValue2, {nilValue: "()"}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("null", "()")); - cn = csv:parseStringToRecord(csvValue3, {nilValue: "()"}); + cn = csv:parseString(csvValue3, {nilValue: "()"}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("e", "()")); - cn = csv:parseStringToRecord(csvValue4, {nilValue: "()"}); + cn = csv:parseString(csvValue4, {nilValue: "()"}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("Null", "()")); - cn = csv:parseStringToRecord(csvValue5, {nilValue: "N/A"}); + cn = csv:parseString(csvValue5, {nilValue: "N/A"}); test:assertEquals(cn, [{b: "bN/Aa", a: ()}]); - cn = csv:parseStringToRecord(csvValue2, {nilValue: "null"}); + cn = csv:parseString(csvValue2, {nilValue: "null"}); test:assertEquals(cn, [{a: ()}]); - cn = csv:parseStringToRecord(csvValue4, {nilValue: "null"}); + cn = csv:parseString(csvValue4, {nilValue: "null"}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("Null", "()")); - cn = csv:parseStringToRecord(csvValue1, {nilValue: "null"}); + cn = csv:parseString(csvValue1, {nilValue: "null"}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("()", "()")); } @@ -316,36 +316,36 @@ function testCommentConfigOption() { record {int a;}[]|csv:Error cn; - cn = csv:parseStringToRecord(csvValue1); + cn = csv:parseString(csvValue1); test:assertEquals(cn, [{a: 1}]); - cn = csv:parseStringToRecord(csvValue2); + cn = csv:parseString(csvValue2); test:assertEquals(cn, [{a: 1}]); - cn = csv:parseStringToRecord(csvValue3); + cn = csv:parseString(csvValue3); test:assertEquals(cn, [{a: 1}]); - cn = csv:parseStringToRecord(csvValue4); + cn = csv:parseString(csvValue4); test:assertEquals(cn, [{a: 1}]); - cn = csv:parseStringToRecord(csvValue5); + cn = csv:parseString(csvValue5); test:assertEquals(cn, [{a: 1, b: 2}]); - cn = csv:parseStringToRecord(csvValue6); + cn = csv:parseString(csvValue6); test:assertEquals(cn, [{a: 1, b: 2}]); - cn = csv:parseStringToRecord(csvValue7); + cn = csv:parseString(csvValue7); test:assertEquals(cn, [{a: 1}]); - record {|int a; int b;|}[]|csv:Error cn2 = csv:parseStringToRecord(csvValue7, {header: 0}); + record {|int a; int b;|}[]|csv:Error cn2 = csv:parseString(csvValue7, {header: 0}); test:assertEquals(cn2, [{a: 1, b: 0}]); - cn = csv:parseStringToRecord(csvValue8); + cn = csv:parseString(csvValue8); test:assertTrue(cn is csv:Error); // TODO:Fix the error message // test:assertEquals(( cn).message(), common:generateErrorMessageForInvalidCast("1, 2", "int")); - cn = csv:parseStringToRecord(csvValue9); + cn = csv:parseString(csvValue9); test:assertEquals(cn, [{a: 1}]); } @@ -378,363 +378,367 @@ function testCommentConfigOption2() { record {int a; int b;}[]|csv:Error cn; record {int c;}[]|csv:Error cn2; - cn = csv:parseStringToRecord(csvValue1, {comment: "&"}); + cn = csv:parseString(csvValue1, {comment: "&"}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn = csv:parseStringToRecord(csvValue2, {comment: "&"}); + cn = csv:parseString(csvValue2, {comment: "&"}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn = csv:parseStringToRecord(csvValue3, {comment: "&"}); + cn = csv:parseString(csvValue3, {comment: "&"}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn = csv:parseStringToRecord(csvValue4, {comment: "&"}); + cn = csv:parseString(csvValue4, {comment: "&"}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn = csv:parseStringToRecord(csvValue5, {comment: "&"}); + cn = csv:parseString(csvValue5, {comment: "&"}); test:assertTrue(cn is csv:Error); // TODO: Fix the error message // test:assertEquals(( cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn = csv:parseStringToRecord(csvValue6, {comment: "&", header: 2}); + cn = csv:parseString(csvValue6, {comment: "&", header: 2}); test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn2 = csv:parseStringToRecord(csvValue1, {comment: "&"}); + cn2 = csv:parseString(csvValue1, {comment: "&"}); test:assertTrue(cn2 is csv:Error); test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); - cn2 = csv:parseStringToRecord(csvValue2, {comment: "&"}); + cn2 = csv:parseString(csvValue2, {comment: "&"}); test:assertTrue(cn2 is csv:Error); test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); - cn2 = csv:parseStringToRecord(csvValue3, {comment: "&"}); + cn2 = csv:parseString(csvValue3, {comment: "&"}); test:assertTrue(cn2 is csv:Error); test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); - cn2 = csv:parseStringToRecord(csvValue4, {comment: "&"}); + cn2 = csv:parseString(csvValue4, {comment: "&"}); test:assertTrue(cn2 is csv:Error); test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); - cn2 = csv:parseStringToRecord(csvValue5, {comment: "&"}); + cn2 = csv:parseString(csvValue5, {comment: "&"}); test:assertTrue(cn2 is csv:Error); // TODO: Fix the error message // test:assertEquals(( cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); - cn2 = csv:parseStringToRecord(csvValue6, {header: 2, comment: "&"}); + cn2 = csv:parseString(csvValue6, {header: 2, comment: "&"}); test:assertTrue(cn2 is csv:Error); test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); } @test:Config {dependsOn: [testCSVLocale]} function testSkipLineParserOption() { - [int, string, boolean, decimal, float, ()][]|csv:Error csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [], header: 1}); + [int, string, boolean, decimal, float, ()][]|csv:Error csv1cp = csv:parseString(csvStringData1, {skipLines: [], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [2, "string2", false, 0, 0, ()], - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); - - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [0], header: 1}); + [1, "string1", true, 2.234, 2.234, ()], + [2, "string2", false, 0, 0, ()], + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); + + csv1cp = csv:parseString(csvStringData1, {skipLines: [0], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [2, "string2", false, 0, 0, ()], - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); - - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [0, 4, 10], header: 1}); + [1, "string1", true, 2.234, 2.234, ()], + [2, "string2", false, 0, 0, ()], + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); + + csv1cp = csv:parseString(csvStringData1, {skipLines: [0, 4, 10], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [2, "string2", false, 0, 0, ()], - [3, "string3", false, 1.23, 1.23, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [2, "string2", false, 0, 0, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [1, 2, 3, 4, 5], header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: [1, 2, 3, 4, 5], header: 1}); test:assertEquals(csv1cp, [ - ]); + ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: "1-5", header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: "1-5", header: 1}); test:assertEquals(csv1cp, [ - ]); + ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [4, 2], header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: [4, 2], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [3, "string3", false, 1.23, 1.23, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: "2-4", header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: "2-4", header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [5, "string5", true, 3, 3.0, ()] + ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [4, 2, -1], header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: [4, 2, -1], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [3, "string3", false, 1.23, 1.23, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [4, -1, 2], header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: [4, -1, 2], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [3, "string3", false, 1.23, 1.23, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [5, 4, 3, 2, 1], header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: [5, 4, 3, 2, 1], header: 1}); test:assertEquals(csv1cp, [ - ]); + ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [10], header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: [10], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [2, "string2", false, 0, 0, ()], - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); - - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [-2], header: 1}); + [1, "string1", true, 2.234, 2.234, ()], + [2, "string2", false, 0, 0, ()], + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); + + csv1cp = csv:parseString(csvStringData1, {skipLines: [-2], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [2, "string2", false, 0, 0, ()], - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); - - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [-2, 0, 2], header: 1}); + [1, "string1", true, 2.234, 2.234, ()], + [2, "string2", false, 0, 0, ()], + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); + + csv1cp = csv:parseString(csvStringData1, {skipLines: [-2, 0, 2], header: 1}); test:assertEquals(csv1cp, [ - [1, "string1", true, 2.234, 2.234, ()], - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: "0-2", header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: "0-2", header: 1}); test:assertEquals(csv1cp, [ - [3, "string3", false, 1.23, 1.23, ()], - [4, "string4", true, -6.51, -6.51, ()], - [5, "string5", true, 3, 3.0, ()] - ]); + [3, "string3", false, 1.23, 1.23, ()], + [4, "string4", true, -6.51, -6.51, ()], + [5, "string5", true, 3, 3.0, ()] + ]); } @test:Config {dependsOn: [testCSVLocale]} function testCustomHeaderOption() { - anydata[][]|csv:Error bm1ba = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}); + anydata[][]|csv:Error bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}); test:assertEquals(bm1ba, [ - [true, false], - [true, false] - ]); + [true, false], + [true, false] + ]); - anydata[][]|csv:Error bm1ba2 = csv:parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}); + anydata[][]|csv:Error bm1ba2 = csv:transform([bm1, bm1], {headersOrder: ["b2", "b1"]}); test:assertEquals(bm1ba2, [ - [false, true], - [false, true] - ]); + [false, true], + [false, true] + ]); - anydata[][]|csv:Error bm2ba = csv:parseRecordAsListType([bm2, bm2], ["b1", "n1", "b2", "n2", "b3"], {}); + anydata[][]|csv:Error bm2ba = csv:transform([bm2, bm2], {headersOrder: ["b1", "n1", "b2", "n2", "b3"]}); test:assertTrue(bm2ba is csv:Error); - test:assertEquals((bm2ba).message(), common:generateErrorMessageForInvalidCustomHeader("n2")); + test:assertEquals((bm2ba).message(), "CSV data rows with varying headers are not yet supported"); - anydata[][]|csv:Error bm3ba = csv:parseRecordAsListType([bm3, bm3], ["b1", "b4", "b2", "n2", "i1"], {}); + anydata[][]|csv:Error bm3ba = csv:transform([bm3, bm3], {headersOrder: ["b1", "b4", "b2", "n2", "i1"]}); test:assertTrue(bm3ba is csv:Error); - test:assertEquals((bm3ba).message(), common:generateErrorMessageForInvalidCustomHeader("n2")); + test:assertEquals((bm3ba).message(), "CSV data rows with varying headers are not yet supported"); - anydata[][]|csv:Error bm3ba2 = csv:parseRecordAsListType([bm3, bm3], ["b1", "b3", "b4", "b2", "i2"], {}); + anydata[][]|csv:Error bm3ba2 = csv:transform([bm3, bm3], {headersOrder: ["b1", "b3", "b4", "b2", "i2"]}); test:assertTrue(bm3ba2 is csv:Error); - test:assertEquals((bm3ba2).message(), common:generateErrorMessageForInvalidCustomHeader("i2")); + test:assertEquals((bm3ba2).message(), "CSV data rows with varying headers are not yet supported"); - [boolean...][]|csv:Error bm3ba4 = csv:parseRecordAsListType([bm3, bm3], ["n2"], {}); + [boolean...][]|csv:Error bm3ba4 = csv:transform([bm3, bm3], {headersOrder: ["n2"]}); test:assertTrue(bm3ba4 is csv:Error); - test:assertEquals((bm3ba4).message(), "Invalid length for the header names"); + test:assertEquals((bm3ba4).message(), "Invalid number of headers"); - [boolean...][]|csv:Error bm3ba5 = csv:parseRecordAsListType([bm3, bm3], [], {}); + [boolean...][]|csv:Error bm3ba5 = csv:transform([bm3, bm3], {headersOrder: []}); test:assertTrue(bm3ba5 is csv:Error); - test:assertEquals((bm3ba5).message(), "Invalid length for the header names"); + test:assertEquals((bm3ba5).message(), "Invalid number of headers"); - record {}[]|csv:Error ct1br = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); + 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 length for the custom headers"); + test:assertEquals((ct1br).message(), "Invalid length for the headers"); - record {}[]|csv:Error ct1br2 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); + 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 length for the custom headers"); + test:assertEquals((ct1br2).message(), "Invalid length for the headers"); - record {}[]|csv:Error ct1br2_2 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); + 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 length for the custom headers"); + test:assertEquals((ct1br2_2).message(), "Invalid length for the headers"); - record {}[]|csv:Error ct1br3 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], [], {}); + record {}[]|csv:Error ct1br3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: []}); test:assertTrue(ct1br3 is csv:Error); - test:assertEquals((ct1br3).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br3).message(), "Invalid length for the headers"); - record {|string a; string b; string c;|}[]|csv:Error ct1br5 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + 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); // TODO: Fix the error message test:assertEquals((ct1br5).message(), common:generateErrorMessageForMissingRequiredField("c")); - record {string a; string b; string c;}[]|csv:Error ct1br6 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + record {string a; string b; string c;}[]|csv:Error ct1br6 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"]}); test:assertTrue(ct1br6 is csv:Error); test:assertEquals((ct1br6).message(), common:generateErrorMessageForMissingRequiredField("c")); - record {string a; string b;}[]|csv:Error ct1br7 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { - stringConversion: false - }); + record {string a; string b;}[]|csv:Error ct1br7 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], { + customHeaders: ["a", "e", "b"] + }); test:assertEquals(ct1br7, [ - {a: "a", e: "1", b: "true"}, - {a: "a", e: "1", b: "true"} - ]); + {a: "a", e: 1, b: "true"}, + {a: "a", e: 1, b: "true"} + ]); - record {|string a; string b;|}[]|csv:Error ct1br8 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { - stringConversion: false - }); + record {|string a; string b;|}[]|csv:Error ct1br8 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], { + customHeaders: ["a", "e", "b"] + }); test:assertEquals(ct1br8, [ - {a: "a", b: "true"}, - {a: "a", b: "true"} - ]); + {a: "a", b: "true"}, + {a: "a", b: "true"} + ]); - record {|string...;|}[]|csv:Error ct1br9 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { - stringConversion: false - }); + record {|string...;|}[]|csv:Error ct1br9 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], { + customHeaders: ["a", "e", "b"] + }); test:assertEquals(ct1br9, [ - {a: "a", b: "true", e: "1"}, - {a: "a", b: "true", e: "1"} - ]); + {a: "a", b: "true", e: "1"}, + {a: "a", b: "true", e: "1"} + ]); - record {|string...;|}[]|csv:Error ct1br10 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), { - stringConversion: false - }); + record {|string...;|}[]|csv:Error ct1br10 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], { + }); test:assertEquals(ct1br10, [ - {'1: "a", '3: "true", '2: "1"}, - {'1: "a", '3: "true", '2: "1"} - ]); + {'1: "a", '3: "true", '2: "1"}, + {'1: "a", '3: "true", '2: "1"} + ]); } @test:Config function testCustomHeaderParserOption2() { - record {}[]|csv:Error ct1br = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); - test:assertTrue(ct1br is csv:Error); - test:assertEquals((ct1br).message(), "Invalid length for the custom headers"); - - record {}[]|csv:Error ct1br2 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: []}); + record {}[]|csv:Error ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["a", "b"]}); + test:assertEquals(ct1br, [ + {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: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); + + ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); + test:assertEquals(ct1br, [ + {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: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); + + ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["b", "a"]}); + test:assertEquals(ct1br, [ + {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: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); + + record {}[]|csv:Error ct1br2 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: []}); test:assertTrue(ct1br2 is csv:Error); - test:assertEquals((ct1br2).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br2).message(), "Invalid length for the headers"); - record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br3 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); + record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br3 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["a", "b"]}); test:assertTrue(ct1br3 is csv:Error); - test:assertEquals((ct1br3).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br3).message(), "Invalid length for the headers"); - record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br4 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b", "c", "d", "e", "f"]}); + record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br4 = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(ct1br4, [ - {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: ()}, - {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, - {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} - ]); - - record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f", "e", "d", "c", "b", "a"]}); + {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: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); + + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5 = csv:parseString(csvStringData4, {header: 1, customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); + test:assertTrue(ct1br5 is csv:Error); + + ct1br5 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br5, [ - {f: 1, e: "string1", d: true, c: 2.234, b: 2.234, a: ()}, - {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, - {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, - {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, - {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} - ]); - - record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_2 = csv:parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f", "e", "d", "c", "b", "a"]}); + {f: 1, e: "string1", d: true, c: 2.234, b: 2.234, a: ()}, + {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, + {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, + {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, + {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} + ]); + + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_2 = csv:parseString(csvStringData4, {header: false, skipLines: [1], customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br5_2, [ - {f: 1, e: "string1", d: true, c: 2.234, b: 2.234, a: ()}, - {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, - {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, - {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, - {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} - ]); - - record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_3 = csv:parseStringToRecord(csvStringData1, {skipLines: [1], customHeaders: ["f", "e", "d", "c", "b", "a"]}); + {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, + {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, + {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, + {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} + ]); + + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_3 = csv:parseString(csvStringData4, {skipLines: [1], header: false, customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br5_3, [ - {f: 1, e: "string1", d: true, c: 2.234, b: 2.234, a: ()}, - {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, - {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, - {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, - {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} - ]); - - record {|() a1; float b1; decimal c1; boolean d1; string e1; int f1;|}[]|csv:Error ct1br6 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); - test:assertEquals(ct1br6, [ - {f1: 1, e1: "string1", d1: true, c1: 2.234, b1: 2.234, a1: ()}, - {f1: 2, e1: "string2", d1: false, c1: 0, b1: 0, a1: ()}, - {f1: 3, e1: "string3", d1: false, c1: 1.23, b1: 1.23, a1: ()}, - {f1: 4, e1: "string4", d1: true, c1: -6.51, b1: -6.51, a1: ()}, - {f1: 5, e1: "string5", d1: true, c1: 3, b1: 3, a1: ()} - ]); - - record {|boolean d1; string e1;|}[]|csv:Error ct1br7 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, + {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, + {f: 4, e: "string4", d: true, c: -6.51, b: -6.51, a: ()}, + {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} + ]); + + record {|boolean d1; string e1;|}[]|csv:Error ct1br7 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7, [ - {e1: "string1", d1: true}, - {e1: "string2", d1: false}, - {e1: "string3", d1: false}, - {e1: "string4", d1: true}, - {e1: "string5", d1: true} - ]); - - record {|boolean d1; string e1;|}[]|csv:Error ct1br7_2 = csv:parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + {e1: "string1", d1: true}, + {e1: "string2", d1: false}, + {e1: "string3", d1: false}, + {e1: "string4", d1: true}, + {e1: "string5", d1: true} + ]); + + record {|boolean d1; string e1;|}[]|csv:Error ct1br7_2 = csv:parseString(csvStringData4, {header: false, skipLines: [1], customHeadersIfHeaderAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7_2, [ - {e1: "string1", d1: true}, - {e1: "string2", d1: false}, - {e1: "string3", d1: false}, - {e1: "string4", d1: true}, - {e1: "string5", d1: true} - ]); - - record {|boolean d1; string e1;|}[]|csv:Error ct1br8 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); + {e1: "string2", d1: false}, + {e1: "string3", d1: false}, + {e1: "string4", d1: true}, + {e1: "string5", d1: true} + ]); + + record {|boolean d1; string e1;|}[]|csv:Error ct1br8 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["e1", "d1"]}); test:assertTrue(ct1br8 is csv:Error); test:assertEquals((ct1br8).message(), common:generateErrorMessageForInvalidCast("string1", "boolean")); - record {|boolean d1; string e1;|}[]|csv:Error ct1br9 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br9 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br9, [ - {e1: "string1", d1: true}, - {e1: "string2", d1: false}, - {e1: "string3", d1: false}, - {e1: "string4", d1: true}, - {e1: "string5", d1: true} - ]); - - record {|boolean d1; string e1;|}[]|csv:Error ct1br10 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "f1", "b1", "a1"]}); - test:assertEquals(ct1br10, [ - {e1: "string1", d1: true}, - {e1: "string2", d1: false}, - {e1: "string3", d1: false}, - {e1: "string4", d1: true}, - {e1: "string5", d1: true} - ]); - - record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); + {e1: "string1", d1: true}, + {e1: "string2", d1: false}, + {e1: "string3", d1: false}, + {e1: "string4", d1: true}, + {e1: "string5", d1: true} + ]); + + record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1"]}); test:assertTrue(ct1br11 is csv:Error); - test:assertEquals((ct1br11).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br11).message(), "Invalid length for the headers"); - record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ - {e1: "string1", d1: "true"}, - {e1: "string2", d1: "false"}, - {e1: "string3", d1: "false"}, - {e1: "string4", d1: "true"}, - {e1: "string5", d1: "true"} - ]); - - record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); + {e1: "string1", d1: "true"}, + {e1: "string2", d1: "false"}, + {e1: "string3", d1: "false"}, + {e1: "string4", d1: "true"}, + {e1: "string5", d1: "true"} + ]); + + record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); test:assertTrue(ct1br13 is csv:Error); test:assertEquals((ct1br13).message(), common:generateErrorMessageForMissingRequiredField("d1")); } @@ -779,27 +783,32 @@ function testTextQuotesWithParserOptions() { 1, "2", "3" `; - record {int a;}[]|csv:Error cn = csv:parseStringToRecord(csvValue1, {header: 1}); + record {int a;}[]|csv:Error cn = csv:parseString(csvValue1, {header: 1}); test:assertEquals(cn, [{"a": 1, "b": 2, "c": 3}, {"a": 1, "b": 2, "c": 3}, {"a": 1, "b": 2, "c": 3}, {"a": 1, "b": 2, "c": 3}]); - record {|int c; string...;|}[]|csv:Error cn2 = csv:parseStringToRecord(csvValue2, {header: 1}); + record {|int c; string...;|}[]|csv:Error cn2 = csv:parseString(csvValue2, {header: 1}); test:assertEquals(cn2, [{"a": "1", "b": "2, 3", "c": 3}, {"a": "1", "b": "2, 3", "c": 3}, {"a": "4", "b": "5", "c": 6}]); - record {|string b; string c;|}[]|csv:Error cn3 = csv:parseStringToRecord(csvValue3, {}); + record {|string b; string c;|}[]|csv:Error cn3 = csv:parseString(csvValue3, {}); test:assertEquals(cn3, [{"b": "\"2\"", "c": "3"}, {"b": "5, 6\"b\" \" a \"", c: "\"6\""}]); - record {}[]|csv:Error cn4 = csv:parseStringToRecord(csvValue4, {textEnclosure: "'"}); + record {}[]|csv:Error cn4 = csv:parseString(csvValue4, {textEnclosure: "'"}); test:assertEquals(cn4, [{"a": 1, "b": 2, "c": 3}, {"a": 4, b: "5, '6'7", c: 8}, {a: 4, b: "\"5\"", c: "4, '5\"a\", ,\",\" a '6'7"}]); - anydata[][]|csv:Error cn4_2 = csv:parseStringToList(csvValue4, {textEnclosure: "'"}); + anydata[][]|csv:Error cn4_2 = csv:parseString(csvValue4, {textEnclosure: "'"}); test:assertEquals(cn4_2, [[1, 2, 3], [4, "5, '6'7", 8], [4, "\"5\"", "4, '5\"a\", ,\",\" a '6'7"]]); - record {}[]|csv:Error cn5 = csv:parseStringToRecord(csvValue5, {}); + record {}[]|csv:Error cn5 = csv:parseString(csvValue5, {}); test:assertEquals(cn5, [{a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}]); - record {}[]|csv:Error cn6 = csv:parseStringToRecord(csvValue6, {}); + record {}[]|csv:Error cn6 = csv:parseString(csvValue6, {}); + test:assertTrue(cn6 is csv:Error); + test:assertEquals((cn6).message(), "Invalid length for the 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 length for the custom headers"); + test:assertEquals((cn6).message(), "Invalid length for the headers"); } @test:Config @@ -824,16 +833,16 @@ function testHeaderQuotesWithParserOptions() { 4, '5, '6'7', 8 4, "5", '4, '5"a", ,"," a '6'7'`; - record {}[]|csv:Error cn = csv:parseStringToRecord(csvValue1, {header: 1}); + record {}[]|csv:Error cn = csv:parseString(csvValue1, {header: 1}); test:assertEquals(cn, [{"a": 1, "b": 2, "c": 3}, {"a": 1, "b": 2, "c": 3}, {"a": 1, "b": 2, "c": 3}, {"a": 1, "b": 2, "c": 3}]); - record {}[]|csv:Error cn2 = csv:parseStringToRecord(csvValue2, {header: 1}); + record {}[]|csv:Error cn2 = csv:parseString(csvValue2, {header: 1}); test:assertEquals(cn2, [{"a, b, c": 1, "b,c": "2, 3", "c,d": 3}, {"a, b, c": 1, "b,c": "2, 3", "c,d": 3}, {"a, b, c": 4, "b,c": 5, "c,d": 6}]); - anydata[][]|csv:Error cn2_2 = csv:parseStringToList(csvValue2, {header: 1}); + anydata[][]|csv:Error cn2_2 = csv:parseString(csvValue2, {header: 1}); test:assertEquals(cn2_2, [[1, "2, 3", 3], [1, "2, 3", 3], [4, 5, 6]]); - record {}[]|csv:Error cn3 = csv:parseStringToRecord(csvValue3, {textEnclosure: "'"}); + record {}[]|csv:Error cn3 = csv:parseString(csvValue3, {textEnclosure: "'"}); test:assertEquals(cn3, [{"a '1'a5,6": 1, "b\", \" \",\"\"\"": 2, "c": 3}, {"a '1'a5,6": 4, "b\", \" \",\"\"\"": "5, '6'7", c: 8}, {"a '1'a5,6": 4, "b\", \" \",\"\"\"": "\"5\"", c: "4, '5\"a\", ,\",\" a '6'7"}]); } @@ -863,44 +872,44 @@ function testEscapeCharactersWithParserOptions() { "1\\", "2\\"", "3"`; - record {}[]|csv:Error cn = csv:parseStringToRecord(csvValue1, {header: 1}); + record {}[]|csv:Error cn = csv:parseString(csvValue1, {header: 1}); test:assertEquals(cn, [{"a": 1, "b": "2a\t", "c": "3b\n"}, {"a": "1c\n", "b": 2, "c": 3}, {"a": 1, "b": "2a\"", "c": 3}, {"a": "1a\\", "b": "2b\\\"", "c": 3}]); - record {}[]|csv:Error cn2 = csv:parseStringToRecord(csvValue2, {header: 1}); + record {}[]|csv:Error cn2 = csv:parseString(csvValue2, {header: 1}); test:assertEquals(cn2, [{"a\"": 1, "\tb\t\n": "2a\t", "c": "3b\n"}, {"a\"": "1c\n", "\tb\t\n": "/2/", "c": 3}, {"a\"": 1, "\tb\t\n": "2a\"", "c": 3}, {"a\"": "1a\\", "\tb\t\n": "2b\\\"", "c": 3}]); - record {}[]|csv:Error cn3 = csv:parseStringToRecord(csvValue3, {header: 1}); + record {}[]|csv:Error cn3 = csv:parseString(csvValue3, {header: 1}); test:assertEquals(cn3, [{"a": 1, "b": "2\t", "c": "3\n"}, {"a": "1\n", "b": 2, "c": 3}, {"a": 1, "b": "2\"", "c": 3}, {"a": "1\\", "b": "2\\\"", "c": 3}]); - anydata[][]|csv:Error cn_2 = csv:parseStringToList(csvValue1, {header: 1}); + anydata[][]|csv:Error cn_2 = csv:parseString(csvValue1, {header: 1}); test:assertEquals(cn_2, [[1, "2a\t", "3b\n"], ["1c\n", 2, 3], [1, "2a\"", 3], ["1a\\", "2b\\\"", 3]]); - anydata[][]|csv:Error cn2_2 = csv:parseStringToList(csvValue2, {header: 1}); + anydata[][]|csv:Error cn2_2 = csv:parseString(csvValue2, {header: 1}); test:assertEquals(cn2_2, [[1, "2a\t", "3b\n"], ["1c\n", "/2/", 3], [1, "2a\"", 3], ["1a\\", "2b\\\"", 3]]); - anydata[][]|csv:Error cn3_2 = csv:parseStringToList(csvValue3, {header: 1}); + anydata[][]|csv:Error cn3_2 = csv:parseString(csvValue3, {header: 1}); test:assertEquals(cn3_2, [[1, "2\t", "3\n"], ["1\n", 2, 3], [1, "2\"", 3], ["1\\", "2\\\"", 3]]); } @test:Config function testDelimiterWithParserOptions() { - record {}[]|csv:Error cn = csv:parseStringToRecord(csvStringData7, {header: 1, delimiter: "@"}); + record {}[]|csv:Error cn = csv:parseString(csvStringData7, {header: 1, delimiter: "@"}); test:assertEquals(cn, [ - {a: 1, b: "string", c: true, d: 2.234, e: -3.21, f: ()}, - {a: 2, b: "s,tring", c: true, d: 2.234, e: -3.21, f: ()}, - {a: 3, b: "stri,ng", c: true, d: 2.234, e: -3.21, f: ()}, - {a: 4, b: "string", c: true, d: 2.234, e: -3.21, f: ()}, - {a: 5, b: "string", c: true, d: 2.234, e: -3.21, f: ()} - ]); - - anydata[][]|csv:Error cn2 = csv:parseStringToList(csvStringData7, {header: 1, delimiter: "@"}); + {a: 1, b: "string", c: true, d: 2.234, e: -3.21, f: ()}, + {a: 2, b: "s,tring", c: true, d: 2.234, e: -3.21, f: ()}, + {a: 3, b: "stri,ng", c: true, d: 2.234, e: -3.21, f: ()}, + {a: 4, b: "string", c: true, d: 2.234, e: -3.21, f: ()}, + {a: 5, b: "string", c: true, d: 2.234, e: -3.21, f: ()} + ]); + + anydata[][]|csv:Error cn2 = csv:parseString(csvStringData7, {header: 1, delimiter: "@"}); test:assertEquals(cn2, [ - [1, "string", true, 2.234, -3.21, ()], - [2, "s,tring", true, 2.234, -3.21, ()], - [3, "stri,ng", true, 2.234, -3.21, ()], - [4, "string", true, 2.234, -3.21, ()], - [5, "string", true, 2.234, -3.21, ()] - ]); + [1, "string", true, 2.234, -3.21, ()], + [2, "s,tring", true, 2.234, -3.21, ()], + [3, "stri,ng", true, 2.234, -3.21, ()], + [4, "string", true, 2.234, -3.21, ()], + [5, "string", true, 2.234, -3.21, ()] + ]); } @test:Config @@ -908,24 +917,80 @@ function testLineTerminatorWithParserOptions() { string csvValue = string `a,b 1,"2\n3"`; - record {}[]|csv:Error cn = csv:parseStringToRecord(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); + record {}[]|csv:Error cn = csv:parseString(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn, [{a: 1, b: "2\n3"}]); - cn = csv:parseStringToRecord(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); + cn = csv:parseString(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn, [{a: 1, b: "2\n3"}]); - cn = csv:parseStringToRecord(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); + cn = csv:parseString(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn, [{a: 1, b: "2\n3"}]); - anydata[][]|csv:Error cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); + anydata[][]|csv:Error cn2 = csv:parseString(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn2, [[1, "2\n3"]]); - cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); + cn2 = csv:parseString(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn2, [[1, "2\n3"]]); - cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); + cn2 = csv:parseString(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn2, [[1, "2\n3"]]); - cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: csv:LF}); + cn2 = csv:parseString(csvValue, {header: 0, lineTerminator: csv:LF}); test:assertEquals(cn2, [[1, "2\n3"]]); } + +@test:Config +function testSkipLineParameterWithOutputHeaderConfig() { + var csv1 = [{a: 1, b: 2}, {a: 2, b: 3}, {a: 3, b: 4}, {a: 4, b: 5}]; + string[][] csv2 = [["1", "2"], ["2", "3"], ["3", "4"], ["4", "5"]]; + var csv3 = string `a,b + 1,2 + 2,3 + 3,4 + 4,5`; + + record {}[]|csv:Error result = csv:parseString(csv3, {outputWithHeaders: true, skipLines: "2-3"}); + test:assertEquals(result, [{a: 1, b: 2}, {a: 4, b: 5}]); + + anydata[][]|csv:Error result2 = csv:parseString(csv3, {outputWithHeaders: true, skipLines: "2-3"}); + test:assertEquals(result2, [["a", "b"], [1, 2], [4, 5]]); + + result = csv:transform(csv1, {outputWithHeaders: true, skipLines: "2-3"}); + test:assertEquals(result, [{a: 1, b: 2}, {a: 4, b: 5}]); + + result2 = csv:transform(csv1, {outputWithHeaders: true, skipLines: "2-3"}); + test:assertEquals(result2, [["a", "b"], [1, 2], [4, 5]]); + + result = csv:parseList(csv2, {outputWithHeaders: true, skipLines: "2-3", customHeaders: ["a", "b"]}); + test:assertEquals(result, [{a: 1, b: 2}, {a: 4, b: 5}]); + + 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, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + test:assertEquals(result, [{a: 2, b: 3}]); + + 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, {outputWithHeaders: true, headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); + test:assertEquals(result, [{a: 3, b: 4}]); + + 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, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3"}); + test:assertEquals(result, [{'1: 2, '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, headerRows: 1, skipLines: "2-3"}); + test:assertEquals(result2, [[2, 3]]); + + result = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); + test:assertEquals(result, [{a: 3, b: 4}]); + + 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 f968a9e..de47edf 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:ParseOption option1 = {delimiter: "@", nilValue: "null", lineTerminator: [csv:LF]}; -csv:ParseOption option2 = {nilValue: "N/A", lineTerminator: [csv:CRLF, csv:LF], comment: "/"}; -csv:ParseOption option3 = {nilValue: "()", header: 1, skipLines: [1, 2]}; -csv:ParseOption option4 = {nilValue: "", header: 4, skipLines: "1-5"}; -csv:ParseOption option5 = {nilValue: "", header: 4, skipLines: "1-1"}; -csv:ParseOption option6 = {nilValue: "()", header: false, skipLines: [1, 2]}; +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]}; -csv:ParseToRecordOption ptOption1 = {nilValue: "", header: 1, skipLines: [2, 4]}; -csv:ParseToRecordOption ptOption2 = {nilValue: "", header: 1, skipLines: "2-4"}; -csv:ParseToRecordOption ptOption3 = {nilValue: "", header: 4, skipLines: "1-5"}; -csv:ParseToRecordOption ptOption4 = {nilValue: "", header: 4, skipLines: [-1, -2, 4, 2]}; -csv:ParseToRecordOption ptOption5 = {header: false, skipLines: [-1, -2, 5, 3]}; +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]}; // Invalid parser options -csv:ParseOption invalidParserOptions1 = {header: 4}; -csv:ParseOption invalidParserOptions2 = {comment: "$"}; -csv:ParseOption invalidParserOptions3 = {lineTerminator: csv:CRLF}; -csv:ParseOption invalidParserOptions4 = {skipLines: [1000, 1001]}; -csv:ParseOption invalidParserOptions5 = {skipLines: "a-b"}; -csv:ParseOption invalidParserOptions6 = {skipLines: "3-1"}; -csv:ParseOption invalidParserOptions7 = {skipLines: "a-5"}; -csv:ParseOption invalidParserOptions8 = {skipLines: "6-a"}; -csv:ParseOption invalidParserOptions9 = {skipLines: "a-5"}; -csv:ParseOption invalidParserOptions10 = {skipLines: "-1-6"}; -csv:ParseOption invalidParserOptions11 = {nilValue: "", header: 4, skipLines: "0-10"}; -csv:ParseOption invalidParserOptions12 = {skipLines: [1, 3, 4, -1]}; +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]}; diff --git a/ballerina/Package.md b/ballerina/Package.md index 1a20e65..ff1deb2 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -5,14 +5,14 @@ The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate ## Features - **Versatile CSV Data Input**: Accept CSV data as a string, byte array, or a stream and convert it into a subtype of ballerina records or lists. -- **CSV to anydata Value Conversion**: Transform CSV data into expected type which is subtype of ballerina records or lists. -- **Projection Support**: Perform selective conversion of CSV data subsets into ballerina records or lists values through projection. +- **CSV to anydata Value transformation**: Transform CSV data into expected type which is subtype of ballerina record arrays or anydata arrays. +- **Projection Support**: Perform selective conversion of CSV data subsets into ballerina record array or anydata array values through projection. ## Usage ### Converting CSV string to a record array -To convert a CSV string into a record value, you can use the `parseStringToRecord` function from the library. The following example demonstrates how to transform a CSV document into an array of records. +To convert a CSV string into a record array value, you can use the `parseString` function from the library. The following example demonstrates how to transform a CSV document into an array of records. ```ballerina import ballerina/data.csv; @@ -29,7 +29,7 @@ public function main() returns error? { Clean Code,Robert C. Martin,2008 The Pragmatic Programmer,Andrew Hunt and David Thomas,1999`; - Book[] books = check csv:parseStringToRecord(csvString); + Book[] books = check csv:parseString(csvString); foreach var book in books { io:println(book); } @@ -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 `parseStringToRecord`, `parseBytesToRecord`, `parseStreamToRecord`, `parseStringToList`, `parseBytesToList`and `parseStreamToList` 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; @@ -53,12 +53,12 @@ type Book record { public function main() returns error? { // Read the CSV content as a string string csvContent = check io:fileReadString("path/to/file.csv"); - Book[] book = check csv:parseStringToRecord(csvContent); + Book[] book = check csv:parseString(csvContent); io:println(book); // Read the CSV content as a stream stream csvStream = check io:fileReadBlocksAsStream("path/to/file.csv"); - Book[] book2 = check csv:parseStreamToRecord(csvStream); + Book[] book2 = check csv:parseStream(csvStream); io:println(book2); } ``` @@ -67,8 +67,8 @@ Make sure to handle possible errors that may arise during the file reading or CS ## CSV to record array/anydata array of array representation -The CSV Object can be represented as a value of type record/map array or string array of array in Ballerina which facilitates a structured and type-safe approach to handling CSV data. -The conversion of CSV data to subtype of record array or anydata array of array representation is a fundamental feature of the library. +The CSV Object can be represented as a value of type `record/map array` or `string array of array` in Ballerina, which facilitates a structured and type-safe approach to handling CSV data. +The conversion of CSV data to subtype of `record array` or `anydata array of array` representation is a fundamental feature of the library. ```ballerina import ballerina/data.csv; @@ -81,9 +81,19 @@ type Book record { public function main() returns error? { string[][] bookArray = [["Clean Code","2008"],["Clean Architecture","2017"]]; + Book[] bookRecords = [{name: "Clean Code", year: 2008}, {name: "Clean Architecture", year: 2017}]; - Book[] author = check csv:parseListAsRecordType(bookArray, customHeaders = ["name", "year"]); - io:println(author); + // Parse and output a record array from a source of string array of arrays. + Book[] books = check csv:parseList(bookArray, {customHeaders: ["name", "year"]}); + io:println(books); + + // Parse and output a tuple array from a source of string array of arrays. + [string, int][] books2 = check csv:parseList(bookArray, {customHeaders: ["name", "year"]}); + io:println(books2); + + // Transform CSV records to a string array of arrays. + [string, int][] books3 = check csv:transform(bookRecords); + io:println(books3); } ``` @@ -115,7 +125,7 @@ public function main() returns error? { // The CSV data above contains publisher and year fields which are not // required to be converted into a record field. - Book[] book = check csv:parseRecordAsRecordType(csvContent); + Book[] book = check csv:transform(csvContent); io:println(book); } ``` diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index fbf5036..b4089e1 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -16,99 +16,49 @@ import ballerina/jballerina.java; -# Converts CSV string to subtype of record array. +# Converts CSV string to subtype of `record{}[]` or `anydata[][]`. # -# + s - Source CSV string value +# + 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 parseStringToRecord(string s, ParseToRecordOption options = {}, typedesc t = <>) - returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; +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 array. +# Converts byte[] to subtype of `record{}[]` or `anydata[][]`. # -# + s - Source CSV byte array +# + 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 parseBytesToRecord(byte[] s, ParseToRecordOption options = {}, typedesc t = <>) - returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; +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 array. +# Converts CSV byte-block-stream to subtype of `record{}[]` or `anydata[][]`. # -# + s - 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 parseStreamToRecord(stream s, - ParseToRecordOption options = {}, typedesc t = <>) - returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; +public isolated function parseStream(stream csvByteStream, + ParseOptions options = {}, typedesc t = <>) + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -# Converts CSV string to subtype of anydata[][]. +# Convert value of type record{}[] to subtype of `record{}[]` or `anydata[][]`. # -# + s - 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 parseStringToList(string s, ParseOption options = {}, typedesc t = <>) - returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; - -# Converts byte[] to subtype of anydata[][]. -# -# + s - 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 parseBytesToList(byte[] s, ParseOption 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 anydata[][]. -# -# + s - 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 parseStreamToList(stream s, - ParseOption 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{}[]. -# -# + s - 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 parseRecordAsRecordType(record{}[] s, - RecordAsRecordOption 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 anydata[][]. -# -# + s - Source Ballerina record array value -# + headerNames - The order of the header names in the source -# + 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 parseRecordAsListType(record{}[] s, string[] headerNames, - Options options = {}, typedesc t = <>) - returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; - -# Convert value of type string[][] to subtype of record{}[]. -# -# + s - Source Ballerina string array of array value -# + customHeaders - The order of the header names in the source +# + 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 parseListAsRecordType(string[][] s, string[]? customHeaders = (), - ListAsRecordOption options = {}, typedesc t = <>) - returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; +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[][] to subtype of anydata[][]. +# Convert value of type string array of array to subtype of `record{}[]` or `anydata[][]`. # -# + s - Source Ballerina string array of array value +# + 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 parseListAsListType(string[][] s, ListAsListOption options = {}, typedesc t = <>) - returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; +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 3129d7c..030adb9 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -12,90 +12,84 @@ public type NameConfig record {| |}; # The annotation is used to overwrite the existing record field name. -public const annotation NameConfig Name on record field; +public const annotation NameConfig Name on record field; # Represents options for data projection. public type Options record { - # Allows data projection with specific settings. - # - # This field can be either a record or a boolean. If it's a record, it contains the following fields: - # If it's 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; - # If `true`, absent fields will be considered as nilable types in the projection. - boolean absentAsNilableType = false; - }|false allowDataProjection = {}; - - # Lines to skip during processing, specified either as an array of integers or a string. - int[]|string skipLines = []; + # Allows data projection with specific settings. + # + # This field can be either a record or a boolean. If it's a record, it contains the following fields: + # If it's 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; + # If `true`, absent fields will be considered as nilable types in the projection. + boolean absentAsNilableType = false; + }|false allowDataProjection = {}; + # Lines to skip during processing, specified either as an array of integers or a string. + int[]|string skipLines = []; + # If `true`, enables validation of constraints during processing. + boolean enableConstraintValidation = true; + # If `true`, the resulted CSV contains the headers as the first row. + # This field is only considered if the expected type is a subset of `anydata[][]` + boolean outputWithHeaders = false; }; # Represents the options for parsing data. -public type ParseOption record {| - *Options; - # The delimiter character used for separating fields in the data. - string:Char delimiter = ","; - # The character encoding of the data. - string encoding = "UTF-8"; - # The locale used for parsing. - string locale = "en_US"; - # The character used to enclose text fields. - string:Char textEnclosure = "\""; - # The character used for escaping. - string:Char escapeChar = "\\"; - # The line terminator(s) used in the data. - LineTerminator|LineTerminator[] lineTerminator = [LF, CRLF]; - # The value to represent nil. - NilValue? nilValue = (); - # The character used to indicate comments in the data. - string:Char comment = "#"; - # Specifies whether the header is present and, if so, the number of header lines. - false|int:Unsigned32 header = 0; -|}; - -# Represents options for parsing data into records. -public type ParseToRecordOption record {| - *ParseOption; - # Custom headers for the data, if any. - string[]? customHeaders = (); - # If `true`, enables validation of constraints during parsing. - boolean enableConstraintValidation = true; -|}; - -# Represents options for treating a list as a list. -public type ListAsListOption record {| +public type ParseOptions record {| *Options; - # If `true`, enables conversion of strings during processing. - boolean stringConversion = true; + # The delimiter character used for separating fields in the data. + string:Char delimiter = ","; + # The character encoding of the data. + string encoding = "UTF-8"; + # The locale used for parsing. + string locale = "en_US"; + # The character used to enclose text fields. + string:Char textEnclosure = "\""; + # The character used for escaping. + string:Char escapeChar = "\\"; + # The line terminator(s) used in the data. + LineTerminator|LineTerminator[] lineTerminator = [LF, CRLF]; + # The value to represent nil. + NilValue? nilValue = (); + # The character used to indicate comments in the data. + string:Char comment = "#"; + # Specifies whether the header is present and, if so, the number of header lines. + false|int:Unsigned32 header = 0; + # Custom headers for the data, if headers are absent. + string[]? customHeadersIfHeaderAbsent = (); |}; -# Represents options for treating a record as a record. -public type RecordAsRecordOption record {| +# Represents options for treating a list as a record. +public type ParseListOptions record {| *Options; - # If `true`, enables validation of constraints during processing. - boolean enableConstraintValidation = true; + # 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 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 = (); |}; # Represents options for treating a list as a record. -public type ListAsRecordOption record {| +public type TransformOptions record {| *Options; - # If `true`, enables validation of constraints during processing. - boolean enableConstraintValidation = true; - # If `true`, enables conversion of strings during processing. - boolean stringConversion = true; + # 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 = (); |}; # Enum representing possible line terminators. public enum LineTerminator { - LF = "\n", - CRLF = "\r\n" + LF = "\n", + CRLF = "\r\n" }; # Enum representing possible nil values. public enum NilValue { - NULL = "null", - EMPTY_STRING = "", - NOT_APPLICABLE = "N/A", - BAL_NULL = "()" + NULL = "null", + NOT_APPLICABLE = "N/A", + EMPTY_STRING = "", + BAL_NULL = "()" }; 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 71982b5..942f770 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 @@ -27,6 +27,9 @@ import java.util.List; import java.util.stream.Collectors; +import static io.ballerina.lib.data.csvdata.compiler.CsvDataDiagnosticCodes.UNSUPPORTED_FIELD_TYPE; +import static io.ballerina.lib.data.csvdata.compiler.CsvDataDiagnosticCodes.UNSUPPORTED_TUPLE_MEMBER_TYPE; + /** * This class includes tests for Ballerina Csv Data compiler plugin. * @@ -36,6 +39,10 @@ public class CompilerPluginTest { static final String UNSUPPORTED_TYPE = "unsupported type: type is not supported"; static final String DUPLICATE_FIELD = "invalid field: duplicate field found"; + static final String UNSUPPORTED_FIELD_TYPE = "Unsupported type in the field: Only basic types " + + "are supported for fields, and other types are not allowed."; + static final String UNSUPPORTED_TUPLE_MEMBER_TYPE = "Unsupported type in the tuple member: " + + "Tuple members can only be basic types, other types are not supported."; @Test public void testInvalidExpectedUnionType() { @@ -44,7 +51,7 @@ public void testInvalidExpectedUnionType() { List errorDiagnosticsList = diagnosticResult.diagnostics().stream() .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) .collect(Collectors.toList()); - Assert.assertEquals(errorDiagnosticsList.size(), 10); + Assert.assertEquals(errorDiagnosticsList.size(), 20); Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); Assert.assertEquals(errorDiagnosticsList.get(2).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); @@ -55,6 +62,20 @@ public void testInvalidExpectedUnionType() { Assert.assertEquals(errorDiagnosticsList.get(7).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); Assert.assertEquals(errorDiagnosticsList.get(8).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); Assert.assertEquals(errorDiagnosticsList.get(9).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(10).diagnosticInfo().messageFormat(), UNSUPPORTED_FIELD_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(11).diagnosticInfo().messageFormat(), UNSUPPORTED_FIELD_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(12).diagnosticInfo().messageFormat(), UNSUPPORTED_FIELD_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(13).diagnosticInfo().messageFormat(), UNSUPPORTED_FIELD_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(14).diagnosticInfo().messageFormat(), UNSUPPORTED_FIELD_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(15).diagnosticInfo().messageFormat(), UNSUPPORTED_FIELD_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(16). + diagnosticInfo().messageFormat(), UNSUPPORTED_TUPLE_MEMBER_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(17). + diagnosticInfo().messageFormat(), UNSUPPORTED_TUPLE_MEMBER_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(18). + diagnosticInfo().messageFormat(), UNSUPPORTED_TUPLE_MEMBER_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(19). + diagnosticInfo().messageFormat(), UNSUPPORTED_TUPLE_MEMBER_TYPE); } @Test 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 9483153..4adb715 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 @@ -1,20 +1,32 @@ import ballerina/data.csv; +import ballerina/lang.regexp; type A [[int, string], [int, string]]; - public function main() returns error? { stream s = ( [[1, 2, 3, 4, 5]]).toStream(); - [[int, string], [int, string]] val = check csv:parseStringToList(string `a,b`, {}); - [record{}, record{}, record{}, record{}] val2 = check csv:parseStringToRecord(string `a,b`, {}); - [[int, string], [int, string]] val3 = check csv:parseStreamToList(s, {}); - [record{}, record{}, record{}, record{}] val4 = check csv:parseStreamToRecord(s, {}); - A val5 = check csv:parseBytesToList([1,2,3], {}); - record{}[]|[record{}, record{}, record{}, record{}] val6 = check csv:parseBytesToRecord([1,2,3], {}); - int[][]|[[int, string], [int, string]] val7 = check csv:parseRecordAsListType([{}], [], {}); - [[int, string], [int, string]] val8 = check csv:parseListAsListType([], {}); - [record{}, record{}, record{}, record{}] val9 = check csv:parseRecordAsRecordType([{}], {}); - [record{}, record{}, record{}, record{}] val10 = check csv:parseListAsRecordType([], [], {}); - record{}[2] val11 = check csv:parseListAsRecordType([], [], {}); - int[3][2] val12 = check csv:parseListAsListType([], {}); + [[int, string], [int, string]] _ = 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, {}); + A _ = 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([], {}); + [xml, xml][] _ = check csv:parseList([], {}); + [regexp:RegExp, xml, int[]][] _ = check 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[3][2] _ = check csv:parseList([], {}); } 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 a8d1eb0..08aeee3 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 @@ -3,15 +3,15 @@ import ballerina/data.csv; type A [[int, string], [int, string]]; stream s = ( [[1, 2, 3, 4, 5]]).toStream(); -[[int, string], [int, string]] val = check csv:parseStringToList(string `a,b`, {}); -[record{}, record{}, record{}, record{}] val2 = check csv:parseStringToRecord(string `a,b`, {}); -[[int, string], [int, string]] val3 = check csv:parseStreamToList(s, {}); -[record{}, record{}, record{}, record{}] val4 = check csv:parseStreamToRecord(s, {}); -A val5 = check csv:parseBytesToList([1,2,3], {}); -record{}[]|[record{}, record{}, record{}, record{}] val6 = check csv:parseBytesToRecord([1,2,3], {}); -int[][]|[[int, string], [int, string]] val7 = check csv:parseRecordAsListType([{}], [], {}); -[[int, string], [int, string]] val8 = check csv:parseListAsListType([], {}); -[record{}, record{}, record{}, record{}] val9 = check csv:parseRecordAsRecordType([{}], {}); -[record{}, record{}, record{}, record{}] val10 = check csv:parseListAsRecordType([], [], {}); -record{}[2] val11 = check csv:parseListAsRecordType([], [], {}); -int[3][2] val12 = check csv:parseListAsListType([], {}); +[[int, string], [int, string]] val = 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, {}); +A val5 = 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([], {}); +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 7c615e9..0d1fa56 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 @@ -9,16 +9,16 @@ public function main() returns error? { public function test() returns error? { stream s = ( [[1, 2, 3, 4, 5]]).toStream(); - [[int, string], [int, string]] val = check csv:parseStringToList(string `a,b`, {}); - [record{}, record{}, record{}, record{}] val2 = check csv:parseStringToRecord(string `a,b`, {}); - [[int, string], [int, string]] val3 = check csv:parseStreamToList(s, {}); - [record{}, record{}, record{}, record{}] val4 = check csv:parseStreamToRecord(s, {}); - A val5 = check csv:parseBytesToList([1,2,3], {}); - record{}[]|[record{}, record{}, record{}, record{}] val6 = check csv:parseBytesToRecord([1,2,3], {}); - int[][]|[[int, string], [int, string]] val7 = check csv:parseRecordAsListType([{}], [], {}); - [[int, string], [int, string]] val8 = check csv:parseListAsListType([], {}); - [record{}, record{}, record{}, record{}] val9 = check csv:parseRecordAsRecordType([{}], {}); - [record{}, record{}, record{}, record{}] val10 = check csv:parseListAsRecordType([], [], {}); - record{}[2] val11 = check csv:parseListAsRecordType([], [], {}); - int[3][2] val12 = check csv:parseListAsListType([], {}); + [[int, string], [int, string]] val = 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, {}); + A val5 = 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([], {}); + int[3][2] val12 = check csv:parseList([], {}); } 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 00b8863..c1cb305 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 @@ -24,16 +24,11 @@ * @since 0.1.0 */ public final class Constants { - static final String PARSE_STRING_TO_RECORD = "parseStringToRecord"; - static final String PARSE_BYTES_TO_RECORD = "parseBytesToRecord"; - static final String PARSE_STREAM_TO_RECORD = "parseStreamToRecord"; - static final String PARSE_STRING_TO_LIST = "parseStringToList"; - static final String PARSE_BYTES_TO_LIST = "parseBytesToList"; - static final String PARSE_STREAM_TO_LIST = "parseStreamToList"; - static final String PARSE_RECORD_AS_RECORD_TYPE = "parseRecordAsRecordType"; - static final String PARSE_RECORD_AS_LIST_TYPE = "parseRecordAsListType"; - static final String PARSE_LIST_AS_RECORD_TYPE = "parseListAsRecordType"; - static final String PARSE_LIST_AS_LIST_TYPE = "parseListAsListType"; + static final String PARSE_STRING = "parseString"; + static final String PARSE_BYTES = "parseBytes"; + static final String PARSE_STREAM = "parseStream"; + static final String TRANSFORM = "transform"; + static final String PARSE_LISTS = "parseList"; static final String NAME = "Name"; static final String CSVDATA = "csv"; static final String BALLERINA = "ballerina"; 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 c47482b..a5e5cca 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 @@ -29,7 +29,11 @@ */ public enum CsvDataDiagnosticCodes { DUPLICATE_FIELD("CSV_ERROR_1", "invalid field: duplicate field found", ERROR), - UNSUPPORTED_TYPE("CSV_ERROR_2", "unsupported type: type is not supported", ERROR); + UNSUPPORTED_TYPE("CSV_ERROR_2", "unsupported type: type is not supported", ERROR), + UNSUPPORTED_FIELD_TYPE("CSV_ERROR_3", "Unsupported type in the field: Only basic types are supported for fields, " + + "and other types are not allowed.", ERROR), + UNSUPPORTED_TUPLE_MEMBER_TYPE("CSV_ERROR_4", "Unsupported type in the tuple member: Tuple members can only " + + "be basic types, other types are not supported.", ERROR); private final String code; private final String message; 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 acbc445..b13cf27 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 @@ -116,9 +116,7 @@ private void updateModulePrefix(ModulePartNode rootNode) { Optional symbol = semanticModel.symbol(importDeclarationNode); symbol.filter(moduleSymbol -> moduleSymbol.kind() == SymbolKind.MODULE) .filter(moduleSymbol -> isCsvDataImport((ModuleSymbol) moduleSymbol)) - .ifPresent(moduleSymbol -> { - modulePrefix = ((ModuleSymbol) moduleSymbol).id().modulePrefix(); - }); + .ifPresent(moduleSymbol -> modulePrefix = ((ModuleSymbol) moduleSymbol).id().modulePrefix()); } } @@ -147,7 +145,7 @@ private void processFunctionDefinitionNode(FunctionDefinitionNode functionDefini continue; } - validateExpectedType(typeSymbol, ctx); + validateExpectedType(typeSymbol, currentLocation, ctx); } } @@ -188,62 +186,115 @@ private boolean isParseFunctionOfStringSource(ExpressionNode expressionNode) { return false; } String functionName = ((FunctionCallExpressionNode) expressionNode).functionName().toString().trim(); - return functionName.contains(Constants.PARSE_STRING_TO_RECORD) || - functionName.contains(Constants.PARSE_BYTES_TO_RECORD) || - functionName.contains(Constants.PARSE_STREAM_TO_RECORD) || - functionName.contains(Constants.PARSE_STRING_TO_LIST) || - functionName.contains(Constants.PARSE_BYTES_TO_LIST) || - functionName.contains(Constants.PARSE_STREAM_TO_LIST) || - functionName.contains(Constants.PARSE_RECORD_AS_RECORD_TYPE) || - functionName.contains(Constants.PARSE_RECORD_AS_LIST_TYPE) || - functionName.contains(Constants.PARSE_LIST_AS_RECORD_TYPE) || - functionName.contains(Constants.PARSE_LIST_AS_LIST_TYPE); + return functionName.contains(Constants.PARSE_STRING) || + functionName.contains(Constants.PARSE_BYTES) || + functionName.contains(Constants.PARSE_STREAM) || + functionName.contains(Constants.TRANSFORM) || + functionName.contains(Constants.PARSE_LISTS); } - private void validateExpectedType(TypeSymbol typeSymbol, SyntaxNodeAnalysisContext ctx) { - typeSymbol.getLocation().ifPresent(location -> currentLocation = location); - + private void validateExpectedType(TypeSymbol typeSymbol, Location currentLocation, SyntaxNodeAnalysisContext ctx) { switch (typeSymbol.typeKind()) { - case UNION -> validateUnionType((UnionTypeSymbol) typeSymbol, ctx); - case ARRAY -> validateArrayType((ArrayTypeSymbol) typeSymbol, ctx); - case TUPLE -> validateTupleType((TupleTypeSymbol) typeSymbol, ctx); - case TYPE_REFERENCE -> validateExpectedType(((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor(), ctx); - case INTERSECTION -> validateExpectedType(getRawType(typeSymbol), ctx); + case UNION -> validateUnionType((UnionTypeSymbol) typeSymbol, currentLocation, ctx); + case ARRAY -> validateArrayType((ArrayTypeSymbol) typeSymbol, currentLocation, ctx); + case TUPLE -> validateTupleType(currentLocation, ctx); + case TYPE_REFERENCE -> validateExpectedType(((TypeReferenceTypeSymbol) typeSymbol) + .typeDescriptor(), currentLocation, ctx); + case INTERSECTION -> validateExpectedType(getRawType(typeSymbol), currentLocation, ctx); } } - private void validateTupleType(TupleTypeSymbol typeSymbol, SyntaxNodeAnalysisContext ctx) { - reportDiagnosticInfo(ctx, typeSymbol.getLocation(), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); + private void validateTupleType(Location currentLocation, SyntaxNodeAnalysisContext ctx) { + // Currently, this is unsupported. + reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); } - private void validateArrayType(ArrayTypeSymbol typeSymbol, SyntaxNodeAnalysisContext ctx) { - if (!isSupportedArrayMemberType(typeSymbol.memberTypeDescriptor())) { - reportDiagnosticInfo(ctx, typeSymbol.getLocation(), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); + private void validateArrayType(ArrayTypeSymbol typeSymbol, Location currentLocation + , SyntaxNodeAnalysisContext ctx) { + if (!isSupportedArrayMemberType(ctx, currentLocation, typeSymbol.memberTypeDescriptor())) { + reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); } } private void validateUnionType(UnionTypeSymbol unionTypeSymbol, - SyntaxNodeAnalysisContext ctx) { + Location currentLocation, SyntaxNodeAnalysisContext ctx) { List memberTypeSymbols = unionTypeSymbol.memberTypeDescriptors(); for (TypeSymbol memberTypeSymbol : memberTypeSymbols) { - validateExpectedType(memberTypeSymbol, ctx); + validateExpectedType(memberTypeSymbol, currentLocation, ctx); } } - private boolean isSupportedArrayMemberType(TypeSymbol typeSymbol) { + private boolean isSupportedArrayMemberType(SyntaxNodeAnalysisContext ctx, + Location currentLocation, TypeSymbol typeSymbol) { + if (typeSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { + typeSymbol = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor(); + } TypeDescKind kind = typeSymbol.typeKind(); if (kind == TypeDescKind.TYPE_REFERENCE) { kind = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor().typeKind(); } switch (kind) { - case RECORD, ARRAY, TUPLE, MAP, UNION, INTERSECTION -> { + case ARRAY, MAP, UNION, INTERSECTION -> { return true; } + case RECORD -> validateRecordFields(ctx, currentLocation, typeSymbol); + case TUPLE -> validateTupleMembers(ctx, currentLocation, typeSymbol); default -> { return false; } } + return true; + } + + private void validateTupleMembers(SyntaxNodeAnalysisContext ctx, Location currentLocation, TypeSymbol typeSymbol) { + if (typeSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { + typeSymbol = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor(); + } + TupleTypeSymbol tupleTypeSymbol = (TupleTypeSymbol) typeSymbol; + tupleTypeSymbol.memberTypeDescriptors().forEach(symbol -> + validateNestedTypeSymbols(ctx, currentLocation, symbol, false)); + Optional restSymbol = tupleTypeSymbol.restTypeDescriptor(); + if (restSymbol.isPresent()) { + TypeSymbol restSym = restSymbol.get(); + validateNestedTypeSymbols(ctx, currentLocation, restSym, false); + } + } + + private void validateRecordFields(SyntaxNodeAnalysisContext ctx, Location currentLocation, TypeSymbol typeSymbol) { + if (typeSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { + typeSymbol = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor(); + } + RecordTypeSymbol recordTypeSymbol = (RecordTypeSymbol) typeSymbol; + + recordTypeSymbol.typeInclusions().forEach(symbol -> + validateNestedTypeSymbols(ctx, currentLocation, symbol, true)); + + recordTypeSymbol.fieldDescriptors().values().forEach(field -> validateNestedTypeSymbols(ctx, + currentLocation, field.typeDescriptor(), true)); + + Optional restSymbol = recordTypeSymbol.restTypeDescriptor(); + if (restSymbol.isPresent()) { + TypeSymbol restSym = restSymbol.get(); + validateNestedTypeSymbols(ctx, currentLocation, restSym, true); + } + } + + private void validateNestedTypeSymbols(SyntaxNodeAnalysisContext ctx, + Location location, TypeSymbol typeSymbol, boolean isField) { + TypeDescKind kind = typeSymbol.typeKind(); + if (kind == TypeDescKind.TYPE_REFERENCE) { + kind = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor().typeKind(); + } + + switch (kind) { + case ARRAY, OBJECT, RECORD, MAP, ERROR, FUNCTION, TUPLE, STREAM, FUTURE, TYPEDESC, + TYPE_REFERENCE, XML, XML_ELEMENT, XML_PROCESSING_INSTRUCTION, XML_COMMENT, + XML_TEXT, HANDLE, TABLE, NEVER, REGEXP -> + reportDiagnosticInfo(ctx, Optional.ofNullable(location), + isField ? CsvDataDiagnosticCodes.UNSUPPORTED_FIELD_TYPE + : CsvDataDiagnosticCodes.UNSUPPORTED_TUPLE_MEMBER_TYPE); + } } public static TypeSymbol getRawType(TypeSymbol typeDescriptor) { @@ -285,7 +336,8 @@ private void processModuleVariableDeclarationNode(ModuleVariableDeclarationNode } Optional symbol = semanticModel.symbol(moduleVariableDeclarationNode.typedBindingPattern()); - symbol.map(s -> (VariableSymbol) s).map(s -> s.typeDescriptor()).ifPresent(s -> validateExpectedType(s, ctx)); + symbol.map(s -> (VariableSymbol) s).map(VariableSymbol::typeDescriptor) + .ifPresent(s -> validateExpectedType(s, currentLocation, ctx)); } private void processTypeDefinitionNode(TypeDefinitionNode typeDefinitionNode, SyntaxNodeAnalysisContext ctx) { 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 3a4a534..c7a2c4c 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 @@ -56,35 +56,31 @@ private CsvCreator() { static Object initRowValue(Type expectedType) { expectedType = TypeUtils.getReferredType(expectedType); - switch (expectedType.getTag()) { - case TypeTags.RECORD_TYPE_TAG: - return ValueCreator.createRecordValue(expectedType.getPackage(), expectedType.getName()); - case TypeTags.MAP_TAG: - return ValueCreator.createMapValue((MapType) expectedType); - case TypeTags.TUPLE_TAG: - return ValueCreator.createTupleValue((TupleType) expectedType); - case TypeTags.ARRAY_TAG: - return ValueCreator.createArrayValue((ArrayType) expectedType); - default: - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); - } + return switch (expectedType.getTag()) { + case TypeTags.RECORD_TYPE_TAG -> + ValueCreator.createRecordValue(expectedType.getPackage(), expectedType.getName()); + case TypeTags.MAP_TAG -> ValueCreator.createMapValue((MapType) expectedType); + case TypeTags.TUPLE_TAG -> ValueCreator.createTupleValue((TupleType) expectedType); + case TypeTags.ARRAY_TAG -> ValueCreator.createArrayValue((ArrayType) expectedType); + default -> throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); + }; } - static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, - String value, Type type, CsvConfig config, Type exptype, - Field currentField) { + static void convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, + String value, Type type, CsvConfig config, Type exptype, + Field currentField) { Object currentCsv = sm.currentCsvNode; Object nilValue = config.nilValue; if (sm.config.nilAsOptionalField && !type.isNilable() && CsvUtils.isNullValue(nilValue, value) && currentField != null && SymbolFlags.isFlagOn(currentField.getFlags(), SymbolFlags.OPTIONAL)) { - return null; + return; } Object convertedValue = convertToExpectedType(StringUtils.fromString(value), type, config); sm.isCurrentCsvNodeEmpty = false; if (convertedValue instanceof BError || convertedValue instanceof CsvUtils.UnMappedValue) { if (ignoreIncompatibilityErrorsForMaps(sm, exptype)) { - return null; + return; } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, value, type); } @@ -95,30 +91,27 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, case TypeTags.RECORD_TYPE_TAG: ((BMap) currentCsv).put(StringUtils.fromString(getHeaderValueForColumnIndex(sm)), convertedValue); - return currentCsv; + return; case TypeTags.ARRAY_TAG: ArrayType arrayType = (ArrayType) currentCsvNodeType; if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < sm.columnIndex) { - return currentCsv; + return; } ((BArray) currentCsv).add(sm.columnIndex, convertedValue); - return currentCsv; + return; case TypeTags.TUPLE_TAG: ((BArray) currentCsv).add(sm.columnIndex, convertedValue); - return currentCsv; + return; default: - return convertedValue; } } public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { - if (sm.config.customHeader == null && (sm.config.header == Boolean.FALSE)) { + if (sm.config.customHeadersIfHeaderAbsent == null && (sm.config.header == Boolean.FALSE)) { String header = String.valueOf(sm.columnIndex + 1); Map fieldHierarchy = sm.fieldHierarchy; - if (fieldHierarchy.containsKey(header)) { - fieldHierarchy.remove(header); - } + fieldHierarchy.remove(header); return header; } if (sm.columnIndex >= sm.headers.size()) { @@ -147,14 +140,9 @@ private static boolean ignoreIncompatibilityErrorsForMaps(CsvParser.StateMachine if (exptype.getTag() == TypeTags.RECORD_TYPE_TAG) { String header = getHeaderValueForColumnIndex(sm); Map fields = sm.fieldNames; - if (fields.containsKey(header)) { - return false; - } - return true; - } else if (exptype.getTag() == TypeTags.MAP_TAG) { - return true; + return !fields.containsKey(header); } - return false; + return exptype.getTag() == TypeTags.MAP_TAG; } public static Object convertToExpectedType(BString value, Type type, CsvConfig config) { 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 8f9bddf..d353eb2 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 @@ -144,6 +144,7 @@ static class StateMachine { boolean isValueStart = false; State prevState; int arraySize = 0; + boolean addHeadersForOutput = false; StateMachine() { reset(); @@ -178,6 +179,7 @@ public void reset() { isValueStart = false; prevState = null; arraySize = 0; + addHeadersForOutput = false; } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -268,10 +270,19 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, expectedArrayElementType); case TypeTags.UNION_TAG: + boolean outputHeaders = config.outputWithHeaders; + Object customHeaders = config.customHeadersIfHeaderAbsent; Object mapValue = execute(reader, TypeCreator.createArrayType( TypeCreator.createMapType(PredefinedTypes.TYPE_STRING) ), CsvConfig.createConfigOptionsForUnion(config), bTypedesc); config.stringConversion = true; + config.outputWithHeaders = outputHeaders; + if (config.outputWithHeaders && customHeaders == null) { + config.customHeadersIfHeaderAbsent = this.headers; + } + if (customHeaders != null) { + config.customHeadersIfHeaderAbsent = customHeaders; + } return CsvTraversal.traverse((BArray) mapValue, config, bTypedesc); default: throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, @@ -282,8 +293,9 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp if (config.header != Boolean.FALSE) { currentState = HEADER_START_STATE; } else { - if (config.customHeader != null) { - CsvCreator.addCustomHeadersIfNotNull(this, config.customHeader); + Object customHeadersIfHeaderAbsent = config.customHeadersIfHeaderAbsent; + if (customHeadersIfHeaderAbsent != null) { + CsvCreator.addCustomHeadersIfNotNull(this, customHeadersIfHeaderAbsent); } currentState = ROW_START_STATE; addFieldNamesForNonHeaderState(); @@ -352,7 +364,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C char ch; State state = HEADER_START_STATE; char separator = sm.config.delimiter; - Object customHeader = sm.config.customHeader; int headerStartRowNumber = getHeaderStartRowWhenHeaderIsPresent(sm.config.header); for (; i < count; i++) { ch = buff[i]; @@ -376,16 +387,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C continue; } sm.isHeaderConfigExceedLineNumber = false; - if (customHeader != null) { - if (sm.isNewLineOrEof(ch)) { - CsvCreator.addCustomHeadersIfNotNull(sm, customHeader); - sm.lineNumber++; - state = HEADER_END_STATE; - break; - } - state = this; - continue; - } if (ch == sm.config.comment) { sm.insideComment = true; @@ -528,7 +529,7 @@ private static class RowStartState implements State { State state = ROW_START_STATE; @Override - public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + public State transition(StateMachine sm, char[] buff, int i, int count) { char separator = sm.config.delimiter; long[] skipLines = CsvUtils.getSkipDataRows(sm.config.skipLines); @@ -543,7 +544,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } if (sm.skipTheRow) { - if (sm.isEndOfTheRowAndValueIsNotEmpty(sm, ch)) { + if (isEndOfTheRowAndValueIsNotEmpty(sm, ch)) { sm.insideComment = false; sm.skipTheRow = false; sm.clear(); @@ -564,6 +565,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C continue; } initiateNewRowType(sm); + addHeadersAsTheFirstElementForArraysIfApplicable(sm); } if (!sm.insideComment && ch == sm.config.comment) { handleEndOfTheRow(sm); @@ -614,17 +616,17 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } } - private static void handleEndOfTheRow(StateMachine sm) throws CsvParserException { + private static void handleEndOfTheRow(StateMachine sm) { handleEndOfTheRow(sm, true); } - private static void handleEndOfTheRow(StateMachine sm, boolean trim) throws CsvParserException { + private static void handleEndOfTheRow(StateMachine sm, boolean trim) { sm.isValueStart = false; handleCsvRow(sm, trim); CsvUtils.checkRequiredFieldsAndLogError(sm.fieldHierarchy, sm.config.absentAsNilableType); } - private static void handleCsvRow(StateMachine sm, boolean trim) throws CsvParserException { + private static void handleCsvRow(StateMachine sm, boolean trim) { String value = sm.peek(); if (trim) { value = value.trim(); @@ -665,6 +667,24 @@ private static void initiateNewRowType(StateMachine sm) { sm.currentCsvNode = CsvCreator.initRowValue(sm.expectedArrayElementType); } + private static void addHeadersAsTheFirstElementForArraysIfApplicable(StateMachine sm) { + if (!sm.addHeadersForOutput && CsvUtils + .isExpectedTypeIsArray(sm.expectedArrayElementType) && sm.config.outputWithHeaders) { + ArrayList headers = sm.headers; + if (!headers.isEmpty()) { + for (String header : headers) { + addHeaderAsRowValue(sm, header); + } + if (!sm.isCurrentCsvNodeEmpty) { + finalizeTheRow(sm); + initiateNewRowType(sm); + } + } + sm.addHeadersForOutput = true; + sm.columnIndex = 0; + } + } + private static void finalizeTheRow(StateMachine sm) { int rootArraySize = sm.rootArrayType.getSize(); if (rootArraySize == -1) { @@ -675,12 +695,11 @@ private static void finalizeTheRow(StateMachine sm) { sm.arraySize++; } - private static void addRowValue(StateMachine sm) throws CsvParserException { + private static void addRowValue(StateMachine sm) { addRowValue(sm, true); } - private static void addRowValue(StateMachine sm, boolean trim) throws CsvParserException { - Type type = null; + private static void addRowValue(StateMachine sm, boolean trim) { Field currentField = null; sm.isValueStart = false; Type exptype = sm.expectedArrayElementType; @@ -689,15 +708,10 @@ private static void addRowValue(StateMachine sm, boolean trim) throws CsvParserE value = value.trim(); } + Type type = getExpectedRowType(sm, exptype); + if (exptype instanceof RecordType) { - type = getExpectedRowTypeOfRecord(sm); currentField = getCurrentField(sm); - } else if (exptype instanceof MapType mapType) { - type = (mapType.getConstrainedType()); - } else if (exptype instanceof ArrayType arrayType) { - type = getExpectedRowTypeOfArray(sm, arrayType); - } else if (exptype instanceof TupleType tupleType) { - type = getExpectedRowTypeOfTuple(sm, tupleType); } if (type != null) { @@ -707,6 +721,35 @@ private static void addRowValue(StateMachine sm, boolean trim) throws CsvParserE sm.columnIndex++; } + private static void addHeaderAsRowValue(StateMachine sm, String value) { + Type exptype = sm.expectedArrayElementType; + Field currentField = null; + Type type = getExpectedRowType(sm, exptype); + + if (exptype instanceof RecordType) { + currentField = getCurrentField(sm); + } + + if (type != null) { + CsvCreator.convertAndUpdateCurrentJsonNode(sm, + value, type, sm.config, exptype, currentField); + } + sm.columnIndex++; + } + + private static Type getExpectedRowType(StateMachine sm, Type exptype) { + if (exptype instanceof RecordType) { + return getExpectedRowTypeOfRecord(sm); + } else if (exptype instanceof MapType mapType) { + return (mapType.getConstrainedType()); + } else if (exptype instanceof ArrayType arrayType) { + return getExpectedRowTypeOfArray(sm, arrayType); + } else if (exptype instanceof TupleType tupleType) { + return getExpectedRowTypeOfTuple(sm, tupleType); + } + return null; + } + private static Type getExpectedRowTypeOfTuple(StateMachine sm, TupleType tupleType) { List tupleTypes = tupleType.getTupleTypes(); if (tupleTypes.size() > sm.columnIndex) { @@ -781,8 +824,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { private static class StringQuoteValueState implements State { @Override - public State transition(StateMachine sm, char[] buff, int i, int count) - throws CsvParserException { + public State transition(StateMachine sm, char[] buff, int i, int count) { State state = this; char ch; for (; i < count; i++) { @@ -821,8 +863,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) sm.prevState = this; sm.isQuoteClosed = false; break; - } else if (!sm.isQuoteClosed && !sm.peek().isEmpty() && ch == EOF) { - throw new CsvParserException("unexpected end of csv stream"); } else { if (!sm.isQuoteClosed) { sm.append(ch); @@ -885,8 +925,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) sm.prevState = this; state = HEADER_ESCAPE_CHAR_STATE; break; - } else if (!sm.isQuoteClosed && ch == EOF) { - throw new CsvParserException("unexpected end of csv stream"); } else { if (!sm.isQuoteClosed) { sm.append(ch); 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 72d4493..4c03daa 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 @@ -88,7 +88,7 @@ public static Object traverse(BArray csv, CsvConfig config, BTypedesc typed, Typ } } - static class CsvTree { + private static class CsvTree { Object currentCsvNode; Field currentField; Map fieldHierarchy = new HashMap<>(); @@ -103,6 +103,10 @@ static class CsvTree { CsvConfig config; String[] headers = null; int arraySize = 0; + BString[] headersForArrayConversion = null; + boolean addHeadersForOutput = false; + boolean isFirstRowIsHeader = false; + boolean isFirstRowInserted = false; void reset() { currentCsvNode = null; @@ -119,6 +123,10 @@ void reset() { config = null; headers = null; arraySize = 0; + headersForArrayConversion = null; + addHeadersForOutput = false; + isFirstRowIsHeader = false; + isFirstRowInserted = false; } @@ -135,6 +143,23 @@ void resetForUnionTypes() { expectedArrayElementType = null; headers = null; arraySize = 0; + headersForArrayConversion = null; + addHeadersForOutput = false; + isFirstRowIsHeader = false; + isFirstRowInserted = false; + } + + void resetForUnionMemberTypes() { + currentCsvNode = null; + currentField = null; + fieldHierarchy.clear(); + updatedRecordFieldNames.clear(); + headerFieldHierarchy.clear(); + fields.clear(); + restType = null; + fieldNames.clear(); + headers = null; + headersForArrayConversion = null; } CsvTree() { @@ -144,7 +169,7 @@ void resetForUnionTypes() { @SuppressWarnings("unchecked") public Object traverseCsv(BArray csv, CsvConfig config, Type type) { this.config = config; - sourceArrayElementType = TypeUtils.getReferredType(getSourceElementTypeForTupleAndArrays(csv)); + sourceArrayElementType = TypeUtils.getReferredType(getSourceElementTypeForLists(csv)); Type referredType = TypeUtils.getReferredType(type); int sourceArraySize = (int) csv.getLength(); if (referredType.getTag() == TypeTags.INTERSECTION_TAG) { @@ -155,7 +180,7 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { } if (referredType.getTag() != TypeTags.UNION_TAG) { - Optional intersectionValue = handleNonUnionIntersection(referredType, csv, config); + Optional intersectionValue = handleNonUnionIntersections(referredType, csv, config); if (intersectionValue.isPresent()) { return intersectionValue.get(); } @@ -169,7 +194,7 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { return rootCsvNode; } - private Optional handleNonUnionIntersection(Type referredType, BArray csv, CsvConfig config) { + private Optional handleNonUnionIntersections(Type referredType, BArray csv, CsvConfig config) { if (referredType.getTag() == TypeTags.ARRAY_TAG) { Type arrayElementType = TypeUtils.getReferredType(((ArrayType) referredType).getElementType()); if (arrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { @@ -206,6 +231,7 @@ private void traverseCsvWithUnionExpectedType(Type referredType, Type type, int private void traverseCsvWithExpectedType(int sourceArraySize, BArray csv, Type type) { boolean isIntersection = false; + this.isFirstRowIsHeader = false; if (expectedArrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { Optional mutableType = CsvUtils.getMutableType((IntersectionType) expectedArrayElementType); if (mutableType.isPresent()) { @@ -217,16 +243,16 @@ private void traverseCsvWithExpectedType(int sourceArraySize, switch (expectedArrayElementType.getTag()) { case TypeTags.RECORD_TYPE_TAG: case TypeTags.MAP_TAG: - traverseCsvArrayMembersWithMapAsCsvElementType(sourceArraySize, csv, + traverseCsvWithMappingAsExpectedType(sourceArraySize, csv, expectedArrayElementType, isIntersection); break; case TypeTags.ARRAY_TAG: case TypeTags.TUPLE_TAG: - traverseCsvArrayMembersWithArrayAsCsvElementType(sourceArraySize, csv, + traverseCsvWithListAsExpectedType(sourceArraySize, csv, expectedArrayElementType, isIntersection); break; case TypeTags.UNION_TAG: - traverseCsvArrayMembersWithUnionAsCsvElementType(sourceArraySize, csv, + traverseCsvWithUnionExpectedType(sourceArraySize, csv, (UnionType) expectedArrayElementType, type); break; default: @@ -234,65 +260,98 @@ private void traverseCsvWithExpectedType(int sourceArraySize, } } - public void traverseCsvArrayMembersWithMapAsCsvElementType(long length, BArray csv, Type expectedArrayType, - boolean isIntersection) { + public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type expectedArrayType, + boolean isIntersection) { Object rowValue; ArrayType arrayType = (ArrayType) rootCsvNode.getType(); + int rowNumber = 0; for (int i = 0; i < length; i++) { - if (ignoreRow(i + 1, config.skipLines)) { - continue; - } if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < this.arraySize) { break; } + Object o = csv.get(i); + + if (i < config.headerRows && i != config.headerRows - 1) { + continue; + } - rowValue = traverseCsvElementWithMapOrRecord(csv.get(i), expectedArrayType); + if (i >= config.headerRows && ignoreRow(rowNumber + 1, config.skipLines)) { + rowNumber++; + continue; + } + + rowValue = initStatesForCsvRowWithMappingAsExpectedType(o, expectedArrayType); if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } - rootCsvNode.add(this.arraySize, rowValue); - this.arraySize++; + + if (!this.isFirstRowIsHeader) { + rootCsvNode.add(this.arraySize, rowValue); + this.arraySize++; + } + if (i >= config.headerRows) { + rowNumber++; + } } } - public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray csv, Type expectedArrayType, - boolean isIntersection) { + public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expectedArrayType, + boolean isIntersection) { Object rowValue; + expectedArrayType = TypeUtils.getReferredType(expectedArrayType); ArrayType arrayType = (ArrayType) rootCsvNode.getType(); + int rowNumber = 0; for (int i = 0; i < length; i++) { - if (ignoreRow(i + 1, config.skipLines)) { - continue; - } if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < this.arraySize) { break; } - rowValue = traverseCsvElementWithArray(csv.get(i), expectedArrayType); + Object o = csv.get(i); + if (!addHeadersForOutput && config.outputWithHeaders + && (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.headerRows) { + continue; + } + + if (ignoreRow(rowNumber + 1, config.skipLines)) { + rowNumber++; + continue; + } + + rowValue = initStatesForCsvRowWithListAsExpectedType(o, expectedArrayType); if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } - rootCsvNode.add(this.arraySize, rowValue); - this.arraySize++; + if (!this.isFirstRowIsHeader) { + rootCsvNode.add(this.arraySize, rowValue); + this.arraySize++; + } + rowNumber++; } } - public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray csv, - UnionType expectedArrayType, Type type) { + public void traverseCsvWithUnionExpectedType(long length, BArray csv, + UnionType expectedArrayType, Type type) { Object rowValue; ArrayType arrayType = (ArrayType) rootCsvNode.getType(); + int rowNumber = 0; + + outerLoop: for (int i = 0; i < length; i++) { boolean isCompatible = false; - if (ignoreRow(i + 1, config.skipLines)) { - continue; - } + this.isFirstRowIsHeader = false; if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < this.arraySize) { break; } - Object csvData = csv.get(i); + Object o = csv.get(i); + for (Type memberType: expectedArrayType.getMemberTypes()) { boolean isIntersection = false; try { @@ -305,29 +364,54 @@ public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray } } - if (memberType.getTag() == TypeTags.MAP_TAG - || memberType.getTag() == TypeTags.RECORD_TYPE_TAG) { - rowValue = traverseCsvElementWithMapOrRecord(csvData, memberType); - } else if (memberType.getTag() == TypeTags.TUPLE_TAG - || memberType.getTag() == TypeTags.ARRAY_TAG) { - rowValue = traverseCsvElementWithArray(csvData, memberType); + if (CsvUtils.isExpectedTypeIsMap(memberType)) { + if (i < config.headerRows && i != config.headerRows - 1) { + continue outerLoop; + } + + if (i >= config.headerRows && ignoreRow(rowNumber + 1, config.skipLines)) { + rowNumber++; + continue outerLoop; + } + rowValue = initStatesForCsvRowWithMappingAsExpectedType(o, memberType); + } else if (CsvUtils.isExpectedTypeIsArray(memberType)) { + if (!addHeadersForOutput && config.outputWithHeaders + && (o instanceof BMap || (config.customHeaders != null + || i == config.headerRows - 1))) { + // Headers will add to the list only in the first iteration + insertHeaderValuesForTheCsvIfApplicable(o, memberType); + } + if (i < config.headerRows) { + continue outerLoop; + } + + if (ignoreRow(rowNumber + 1, config.skipLines)) { + rowNumber++; + continue outerLoop; + } + rowValue = initStatesForCsvRowWithListAsExpectedType(o, memberType); } else { continue; } + if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } - rootCsvNode.add(this.arraySize, rowValue); - this.arraySize++; + + if (!this.isFirstRowIsHeader) { + rootCsvNode.add(this.arraySize, rowValue); + this.arraySize++; + } isCompatible = true; break; } catch (Exception e) { - // ignore + resetForUnionMemberTypes(); } } if (!isCompatible) { throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); } + rowNumber++; } } @@ -341,7 +425,7 @@ private static boolean ignoreRow(int index, Object skipLinesConfig) { return false; } - public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expectedType) { + public Object initStatesForCsvRowWithMappingAsExpectedType(Object csvElement, Type expectedType) { expectedType = TypeUtils.getReferredType(expectedType); switch (expectedType.getTag()) { case TypeTags.RECORD_TYPE_TAG: @@ -353,12 +437,12 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected this.headerFieldHierarchy = new HashMap<>(recordType.getFields()); this.restType = recordType.getRestFieldType(); currentCsvNode = ValueCreator.createRecordValue(recordType.getPackage(), recordType.getName()); - traverseCsvMap(csvElement, expectedType, false); + traverseCsvRowWithMappingAsExpectedType(csvElement, expectedType, false); break; case TypeTags.MAP_TAG: MapType mapType = (MapType) expectedType; currentCsvNode = ValueCreator.createMapValue(mapType); - traverseCsvMap(csvElement, expectedType, true); + traverseCsvRowWithMappingAsExpectedType(csvElement, expectedType, true); break; default: throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); @@ -366,19 +450,19 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected return currentCsvNode; } - public Object traverseCsvElementWithArray(Object csvElement, Type expectedType) { + public Object initStatesForCsvRowWithListAsExpectedType(Object csvElement, Type expectedType) { expectedType = TypeUtils.getReferredType(expectedType); switch (expectedType.getTag()) { case TypeTags.ARRAY_TAG: ArrayType arrayType = (ArrayType) expectedType; currentCsvNode = ValueCreator.createArrayValue(arrayType); - traverseArrayValue(csvElement, arrayType); + traverseCsvRowWithListAsExpectedType(csvElement, arrayType); break; case TypeTags.TUPLE_TAG: TupleType tupleType = (TupleType) expectedType; this.restType = tupleType.getRestType(); currentCsvNode = ValueCreator.createTupleValue(tupleType); - traverseArrayValue(csvElement, tupleType); + traverseCsvRowWithListAsExpectedType(csvElement, tupleType); break; default: throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); @@ -386,79 +470,167 @@ public Object traverseCsvElementWithArray(Object csvElement, Type expectedType) return currentCsvNode; } - private void traverseArrayValue(Object csvElement, Type type) { + private void traverseCsvRowWithListAsExpectedType(Object csvElement, Type type) { int expectedTypeSize = CsvUtils.getTheActualExpectedType(type); if (csvElement instanceof BMap map) { - constructArrayValuesFromMap(map, type, expectedTypeSize == -1 ? map.size() : expectedTypeSize); + constructCsvArrayFromMapping(map, type, expectedTypeSize == -1 ? map.size() : expectedTypeSize); } else if (csvElement instanceof BArray array) { - constructArrayValuesFromArray(array, type, expectedTypeSize == -1 ? array.size() : expectedTypeSize); + constructCsvArrayFromNonMapping(array, type, expectedTypeSize == -1 ? array.size() : expectedTypeSize); } } - private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { + private void constructCsvArrayFromMapping(BMap map, Type type, int expectedSize) { int index = 0; - for (int i = 0; i < csvElement.getLength(); i++) { + BString[] keys = generateCsvHeadersForMappingRow(map, config.headersOrder, map.size()); + for (BString key: keys) { + if (!map.containsKey(key)) { + throw DiagnosticLog.error(DiagnosticErrorCode.HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED, key); + } + Object v = map.get(key); if (config.allowDataProjection && index >= expectedSize) { break; } - Type memberType = getArrayOrTupleMemberType(type, index); + Type memberType = getTheElementTypeFromList(type, index); if (memberType != null) { - addValuesToArrayType(csvElement.get(i), memberType, index, currentCsvNode); + insertValuesIntoList(v, memberType, index, currentCsvNode); } index++; } } - private void constructArrayValuesFromMap(BMap map, Type type, int expectedSize) { - int size = map.size(); - BString[] keys = new BString[size]; - if (config.headersOrder != null) { - String[] headerOrder = config.headersOrder.getStringArray(); - if (headerOrder.length != size) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_HEADER_NAMES_LENGTH); + private void constructCsvArrayFromNonMapping(BArray csvElement, Type type, int expectedSize) { + int index = 0; + for (int i = 0; i < csvElement.getLength(); i++) { + if (config.allowDataProjection && index >= expectedSize) { + break; } - for (int i = 0; i < size; i++) { - keys[i] = StringUtils.fromString(headerOrder[i]); + Type memberType = getTheElementTypeFromList(type, index); + if (memberType != null) { + insertValuesIntoList(csvElement.get(i), memberType, index, currentCsvNode); } - } else if (config.customHeader == null) { - keys = map.getKeys(); + index++; + } + } + + private void traverseCsvRowWithMappingAsExpectedType(Object csvElement, + Type expectedType, boolean mappingType) { + if (csvElement instanceof BMap map) { + constructCsvMapFromMapping(map, mappingType, expectedType); + } else if (csvElement instanceof BArray array) { + constructCsvMapFromNonMapping(array, mappingType, expectedType); } else { - if (this.headers == null) { - this.headers = CsvUtils.createHeaders(new String[size], config); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CSV_DATA_FORMAT); + } + } + + private void constructCsvMapFromNonMapping(BArray csvElement, + boolean mappingType, Type expectedType) { + this.isFirstRowIsHeader = false; + int arraySize = csvElement.size(); + String[] headers = new String[csvElement.size()]; + if (this.headers == null) { + this.headers = CsvUtils.createHeadersForParseLists(csvElement, headers, config); + if (!this.isFirstRowInserted && config.headerRows >= 1) { + // To skip the row at the position [config.headerRows - 1] from being added to the result. + this.isFirstRowIsHeader = true; + this.isFirstRowInserted = true; + return; + } + } + boolean headersMatchWithExpType = validateHeaders(expectedType, csvElement, arraySize); + if (!headersMatchWithExpType) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONVERSION_FOR_ARRAY_TO_MAP, + csvElement, expectedType); + } + constructCsvMappingRow(csvElement, arraySize, mappingType, expectedType); + } + + private void constructCsvMapFromMapping( + BMap map, boolean mappingType, Type expType) { + Type currentFieldType; + for (BString key : map.getKeys()) { + if (!mappingType) { + if (!isMappingKeyBelongsToNonRestType(map.get(key), key)) { + continue; + } + currentFieldType = TypeUtils.getReferredType(currentField.getFieldType()); + } else { + addFieldInMapType(key); + currentFieldType = TypeUtils.getReferredType( + ((MapType) expType).getConstrainedType() + ); } - if (this.headers.length != size) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); + insertCurrentFieldMemberIntoMapping(currentFieldType, map.get(key), key, mappingType); + } + CsvUtils.checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); + } + + private void insertHeaderValuesForTheCsvIfApplicable(Object obj, Type type) { + if (config.outputWithHeaders && CsvUtils.isExpectedTypeIsArray(type)) { + if (this.headers == null && obj instanceof BArray array) { + String[] headers = new String[array.size()]; + this.headers = CsvUtils.createHeadersForParseLists(array, headers, config); } - for (int i = 0; i < size; i++) { - keys[i] = StringUtils.fromString(this.headers[i]); + if (this.headers == null && obj instanceof BMap) { + BMap map = (BMap) obj; + int size = map.size(); + BString[] headerArray = generateCsvHeadersForMappingRow(map, config.headersOrder, size); + this.headers = new String[size]; + for (int i = 0; i < headerArray.length; i++) { + this.headers[i] = StringUtils.getStringValue(headerArray[i]); + } + } + + BArray headersArray; + if (type instanceof ArrayType arrayType) { + headersArray = ValueCreator.createArrayValue(arrayType); + } else { + headersArray = ValueCreator.createTupleValue((TupleType) type); + } + + for (int i = 0; i < this.headers.length; i++) { + Type memberType = getTheElementTypeFromList(type, i); + if (memberType != null) { + insertValuesIntoList(StringUtils.fromString(headers[i]), memberType, i, headersArray); + } + } + + if (!this.isFirstRowIsHeader) { + rootCsvNode.add(this.arraySize, headersArray); + this.arraySize++; + addHeadersForOutput = true; } } + } - int index = 0; - for (BString key: keys) { - if (!map.containsKey(key)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER, key); + private BString[] generateCsvHeadersForMappingRow(BMap map, Object headersOrder, int size) { + BString[] keys = new BString[size]; + if (headersOrder != null) { + String[] headerOrder = ((BArray) headersOrder).getStringArray(); + if (headerOrder.length != size) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_HEADER_NAMES_LENGTH); } - Object v = map.get(key); - if (config.allowDataProjection && index >= expectedSize) { - break; + for (int i = 0; i < size; i++) { + keys[i] = StringUtils.fromString(headerOrder[i]); } - Type memberType = getArrayOrTupleMemberType(type, index); - if (memberType != null) { - addValuesToArrayType(v, memberType, index, currentCsvNode); + } else { + if (headersForArrayConversion == null) { + headersForArrayConversion = map.getKeys(); } - index++; + keys = headersForArrayConversion; } + return keys; } - private Type getArrayOrTupleMemberType(Type type, int index) { + private Type getTheElementTypeFromList(Type type, int index) { if (type instanceof TupleType tupleType) { List tupleTypes = tupleType.getTupleTypes(); if (tupleTypes.size() >= index + 1) { return tupleTypes.get(index); } - if (restType != null) { - return restType; + Type res = tupleType.getRestType(); + if (res != null) { + return res; } else { if (config.allowDataProjection) { return null; @@ -476,32 +648,22 @@ private Type getArrayOrTupleMemberType(Type type, int index) { return arrayType.getElementType(); } - private void traverseCsvMap(Object csvElement, Type expectedType, boolean mappingType) { - if (csvElement instanceof BMap map) { - traverseMapValueWithMapAsExpectedType(map, mappingType, expectedType); - } else if (csvElement instanceof BArray array) { - traverseArrayValueWithMapAsExpectedType(array, mappingType, expectedType); - } else { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CSV_DATA_FORMAT); - } - } - - private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, BArray csvElement, int arraySize) { + private boolean validateHeaders(Type expectedType, BArray csvElement, int arraySize) { if (arraySize < this.headers.length) { - return false; + throw DiagnosticLog.error(DiagnosticErrorCode.HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED); } if (expectedType instanceof MapType) { return true; } Type type = csvElement.getType(); if (type instanceof TupleType tupleType) { - return checkExpectedTypeMatchWithHeadersForTuple(expectedType, tupleType); + return validateHeadersWithTupleDataRows(expectedType, tupleType); } else { - return checkExpectedTypeMatchWithHeadersForArray(expectedType); + return validateHeadersWithArrayDataRows(expectedType); } } - private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, TupleType tupleType) { + private boolean validateHeadersWithTupleDataRows(Type expectedType, TupleType tupleType) { Type type; List tupleTypes = tupleType.getTupleTypes(); Type tupleRestType = tupleType.getRestType(); @@ -544,7 +706,7 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Tup return false; } - private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType) { + private boolean validateHeadersWithArrayDataRows(Type expectedType) { if (expectedType instanceof RecordType) { if (this.restType != null) { return true; @@ -561,28 +723,17 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType) { return false; } - private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, - boolean mappingType, Type expectedType) { - int arraySize = csvElement.size(); - String[] headers = new String[arraySize]; - if (this.headers == null) { - this.headers = CsvUtils.createHeaders(headers, config); - } - boolean headersMatchWithExpType = checkExpectedTypeMatchWithHeaders(expectedType, csvElement, arraySize); - if (!headersMatchWithExpType) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONVERSION_FOR_ARRAY_TO_MAP, - csvElement, expectedType); - } - addValuesToMapType(csvElement, arraySize, mappingType, expectedType); - } - - private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappingType, Type expectedType) { + private void constructCsvMappingRow(BArray csvElement, int arraySize, boolean mappingType, Type expectedType) { Type fieldType; BString key; + if (arraySize != this.headers.length) { + throw DiagnosticLog.error(DiagnosticErrorCode.HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED); + } + for (int i = 1; i <= arraySize; i++) { key = StringUtils.fromString(this.headers[i - 1]); if (!mappingType) { - if (!isKeyBelongsToNonRestType(csvElement.get(i - 1), key)) { + if (!isMappingKeyBelongsToNonRestType(csvElement.get(i - 1), key)) { continue; } fieldType = TypeUtils.getReferredType(currentField.getFieldType()); @@ -590,32 +741,12 @@ private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappin addFieldInMapType(key); fieldType = ((MapType) expectedType).getConstrainedType(); } - addCurrentFieldValue(fieldType, csvElement.get(i - 1), key, mappingType); - } - CsvUtils.checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); - } - - private void traverseMapValueWithMapAsExpectedType( - BMap map, boolean mappingType, Type expType) { - Type currentFieldType; - for (BString key : map.getKeys()) { - if (!mappingType) { - if (!isKeyBelongsToNonRestType(map.get(key), key)) { - continue; - } - currentFieldType = TypeUtils.getReferredType(currentField.getFieldType()); - } else { - addFieldInMapType(key); - currentFieldType = TypeUtils.getReferredType( - ((MapType) expType).getConstrainedType() - ); - } - addCurrentFieldValue(currentFieldType, map.get(key), key, mappingType); + insertCurrentFieldMemberIntoMapping(fieldType, csvElement.get(i - 1), key, mappingType); } CsvUtils.checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); } - private boolean isKeyBelongsToNonRestType(Object value, BString key) { + private boolean isMappingKeyBelongsToNonRestType(Object value, BString key) { String keyStr = StringUtils.getStringValue(key); String fieldName = CsvUtils.getUpdatedHeaders(this.updatedRecordFieldNames, keyStr, this.fields.contains(keyStr)); @@ -624,7 +755,7 @@ private boolean isKeyBelongsToNonRestType(Object value, BString key) { // Add to the rest field if (restType != null) { Type restFieldType = TypeUtils.getReferredType(restType); - addRestField(restFieldType, key, value); + insertRestFieldMemberIntoMapping(restFieldType, key, value); return false; } if (config.allowDataProjection) { @@ -640,7 +771,7 @@ private void addFieldInMapType(BString key) { fieldNames.push(key.toString()); } - private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { + private Object convertCsvValueIntoExpectedType(Type type, Object csvMember, boolean isRecursive) { Type fieldType = TypeUtils.getReferredType(type); Object nilValue = config.nilValue; if (!isRecursive && config.nilAsOptionalField && !fieldType.isNilable() @@ -686,7 +817,7 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { throw DiagnosticLog.error(DiagnosticErrorCode .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); } - Object value = getFieldValue(memberType, csvMember, true); + Object value = convertCsvValueIntoExpectedType(memberType, csvMember, true); if (!(value instanceof BError || value instanceof CsvUtils.UnMappedValue)) { return value; } @@ -703,7 +834,7 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { if (constituentType.getTag() == TypeTags.READONLY_TAG) { continue; } - return CsvCreator.constructReadOnlyValue(getFieldValue(constituentType, + return CsvCreator.constructReadOnlyValue(convertCsvValueIntoExpectedType(constituentType, csvMember, true)); } break; @@ -714,15 +845,15 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { return CsvUtils.UnMappedValue.createUnMappedValue(); } - private void addRestField(Type type, BString key, Object csvMember) { - Object value = getFieldValue(type, csvMember, false); + private void insertRestFieldMemberIntoMapping(Type type, BString key, Object csvMember) { + Object value = convertCsvValueIntoExpectedType(type, csvMember, false); if (!(value instanceof CsvUtils.UnMappedValue)) { ((BMap) currentCsvNode).put(key, value); } } - private void addCurrentFieldValue(Type type, Object recValue, BString key, boolean isMapType) { - Object value = getFieldValue(type, recValue, false); + private void insertCurrentFieldMemberIntoMapping(Type type, Object recValue, BString key, boolean isMapType) { + Object value = convertCsvValueIntoExpectedType(type, recValue, false); if (!(value instanceof CsvUtils.UnMappedValue || value instanceof CsvUtils.SkipMappedValue)) { ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), value); return; @@ -734,8 +865,8 @@ private void addCurrentFieldValue(Type type, Object recValue, BString key, boole throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, recValue, key); } - public void addValuesToArrayType(Object arrayValue, Type type, int index, Object currentCsvNode) { - Object value = getFieldValue(type, arrayValue, false); + public void insertValuesIntoList(Object arrayValue, Type type, int index, Object currentCsvNode) { + Object value = convertCsvValueIntoExpectedType(type, arrayValue, false); boolean isArrayType = type instanceof ArrayType; if (!(value instanceof CsvUtils.UnMappedValue)) { if (isArrayType) { @@ -761,7 +892,7 @@ private void setRootCsvNodeForNonUnionArrays(Type referredType, Type type) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); } - private Type getSourceElementTypeForTupleAndArrays(BArray csv) { + private Type getSourceElementTypeForLists(BArray csv) { if (csv.getType() instanceof TupleType tupleType) { List memberTypes = new ArrayList<>(tupleType.getTupleTypes()); return TypeCreator.createUnionType(memberTypes); diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java index 35dd9eb..619e01d 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java @@ -48,48 +48,7 @@ public final class Native { private Native() { } - public static Object parseStringToRecord(BString csv, BMap options, BTypedesc type) { - try { - return CsvParser.parse(new StringReader(csv.getValue()), - type, CsvConfig.createParserToRecordOptions(options)); - } catch (BError e) { - return e; - } catch (Exception e) { - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, type); - } - } - - public static Object parseBytesToRecord(BArray csv, BMap options, BTypedesc type) { - try { - byte[] bytes = csv.getBytes(); - return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes), - Charset.forName(options.getStringValue(Constants.ConfigConstants.ENCODING).toString())), - type, CsvConfig.createParserToRecordOptions(options)); - } catch (BError e) { - return e; - } catch (Exception e) { - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, type); - } - } - - public static Object parseStreamToRecord(Environment env, BStream csv, - BMap options, BTypedesc type) { - try { - final BObject iteratorObj = csv.getIteratorObj(); - final Future future = env.markAsync(); - DataReaderTask task = new DataReaderTask(env, iteratorObj, future, type, - CsvConfig.createParserToRecordOptions(options), - options.getStringValue(Constants.ConfigConstants.ENCODING)); - DataReaderThreadPool.EXECUTOR_SERVICE.submit(task); - return null; - } catch (BError e) { - return e; - } catch (Exception e) { - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, type); - } - } - - public static Object parseStringToList(BString csv, BMap options, BTypedesc type) { + public static Object parseString(BString csv, BMap options, BTypedesc type) { try { return CsvParser.parse(new StringReader(csv.getValue()), type, CsvConfig.createParseOptions(options)); @@ -100,7 +59,7 @@ public static Object parseStringToList(BString csv, BMap option } } - public static Object parseBytesToList(BArray csv, BMap options, BTypedesc type) { + public static Object parseBytes(BArray csv, BMap options, BTypedesc type) { try { byte[] bytes = csv.getBytes(); return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes), @@ -113,8 +72,8 @@ public static Object parseBytesToList(BArray csv, BMap options, } } - public static Object parseStreamToList(Environment env, BStream csv, - BMap options, BTypedesc type) { + public static Object parseStream(Environment env, BStream csv, + BMap options, BTypedesc type) { try { final BObject iteratorObj = csv.getIteratorObj(); final Future future = env.markAsync(); @@ -130,38 +89,18 @@ public static Object parseStreamToList(Environment env, BStream csv, } } - public static Object parseRecordAsRecordType(BArray csv, BMap options, BTypedesc type) { + public static Object transform(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvConfig.createRecordAsRecordOption(options), type); + return CsvTraversal.traverse(csv, CsvConfig.createTransformOptions(options), type); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } } - - public static Object parseRecordAsListType(BArray csv, BArray headers, - BMap options, BTypedesc type) { - try { - CsvConfig toRecordOptions = CsvConfig.createToRecordOptions(options); - toRecordOptions.headersOrder = headers; - return CsvTraversal.traverse(csv, toRecordOptions, type); - } catch (Exception e) { - return DiagnosticLog.getCsvError(e.getMessage()); - } - } - - public static Object parseListAsRecordType(BArray csv, Object customHeaders, - BMap options, BTypedesc type) { - try { - options.put(Constants.ConfigConstants.CUSTOM_HEADERS, customHeaders); - return CsvTraversal.traverse(csv, CsvConfig.createListAsRecordTypeOptions(options), type); - } catch (Exception e) { - return DiagnosticLog.getCsvError(e.getMessage()); - } - } - - public static Object parseListAsListType(BArray csv, BMap options, BTypedesc type) { + public static Object parseList(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvConfig.createListTypeOptions(options), type); + CsvConfig config = CsvConfig.createParseListOptions(options); + config.stringConversion = true; + return CsvTraversal.traverse(csv, config, type); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } 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 1cb88d5..3205e02 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 @@ -23,10 +23,15 @@ public final class ConfigConstants { public static final BString NIL_AS_OPTIONAL = StringUtils.fromString("nilAsOptionalField"); public static final BString ABSENT_AS_NILABLE = StringUtils.fromString("absentAsNilableType"); public static final BString ALLOW_DATA_PROJECTION = StringUtils.fromString("allowDataProjection"); - public static final BString CUSTOM_HEADERS = StringUtils.fromString("customHeaders"); public static final BString STRING_CONVERSION = StringUtils.fromString("stringConversion"); 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("headerRows"); + public static final BString CUSTOM_HEADERS_IF_HEADER_ABSENT = + StringUtils.fromString("customHeadersIfHeaderAbsent"); + public static final BString CUSTOM_HEADERS = StringUtils.fromString("customHeaders"); + public static final BString HEADERS_ORDER = StringUtils.fromString("headersOrder"); 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 fdfc08c..dd6bd56 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 @@ -1,7 +1,6 @@ package io.ballerina.lib.data.csvdata.utils; import io.ballerina.runtime.api.utils.StringUtils; -import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; @@ -13,7 +12,7 @@ public class CsvConfig { public char delimiter = ','; public char textEnclosure = '\\'; - public Object header = (long) 0; + public Object header = 0; public char escapeChar = '\\'; public Object lineTerminator = '\n'; public Object skipLines = null; @@ -23,10 +22,13 @@ public class CsvConfig { public boolean nilAsOptionalField = false; public boolean absentAsNilableType = false; public boolean allowDataProjection = true; - public Object customHeader = null; - public BArray headersOrder = null; + public Object headersOrder = null; public boolean stringConversion = false; public boolean enableConstraintValidation = false; + public boolean outputWithHeaders = false; + public Object customHeadersIfHeaderAbsent = null; + public long headerRows = 0; + public Object customHeaders = null; private CsvConfig(CsvConfig config) { this.allowDataProjection = false; @@ -40,168 +42,100 @@ private CsvConfig(CsvConfig config) { this.locale = config.locale; } - private CsvConfig(boolean enableConstraintValidation, Object skipLines, boolean nilAsOptionalField, - boolean absentAsNilableType, boolean allowDataProjection) { - this.skipLines = skipLines; - this.nilAsOptionalField = nilAsOptionalField; - this.absentAsNilableType = absentAsNilableType; - this.allowDataProjection = allowDataProjection; - this.enableConstraintValidation = enableConstraintValidation; - } - - private CsvConfig(Object skipLines, boolean nilAsOptionalField, - boolean absentAsNilableType, boolean allowDataProjection, Object customHeader) { - this.skipLines = skipLines; - this.nilAsOptionalField = nilAsOptionalField; - this.absentAsNilableType = absentAsNilableType; - this.allowDataProjection = allowDataProjection; - this.customHeader = customHeader; + public static CsvConfig createParseListOptions(BMap options) { + updateDataProjectOptions(options); + return new CsvConfig( + options.getBooleanValue(Constants.ConfigConstants.NIL_AS_OPTIONAL), + options.getBooleanValue(Constants.ConfigConstants.ABSENT_AS_NILABLE), + options.getBooleanValue(Constants.ConfigConstants.ALLOW_DATA_PROJECTION), + options.get(Constants.ConfigConstants.SKIP_LINES), + options.getBooleanValue(Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION), + options.getBooleanValue(Constants.ConfigConstants.OUTPUT_WITH_HEADERS), + options.getIntValue(Constants.ConfigConstants.HEADER_ROWS), + options.get(Constants.ConfigConstants.CUSTOM_HEADERS) + ); } - private CsvConfig(Object skipLines, boolean nilAsOptionalField, - boolean absentAsNilableType, boolean allowDataProjection, boolean stringConversion) { - this.skipLines = skipLines; + public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, + Object skipLines, boolean enableConstraintValidation, boolean outputWithHeaders, + long headerRows, Object headers) { this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; - this.stringConversion = stringConversion; - } - - private CsvConfig(Object skipLines, boolean nilAsOptionalField, boolean absentAsNilableType, - boolean allowDataProjection, boolean stringConversion, Object customHeader, - boolean enableConstraintValidation) { this.skipLines = skipLines; - this.nilAsOptionalField = nilAsOptionalField; - this.absentAsNilableType = absentAsNilableType; - this.allowDataProjection = allowDataProjection; - this.stringConversion = stringConversion; - this.customHeader = customHeader; this.enableConstraintValidation = enableConstraintValidation; + this.outputWithHeaders = outputWithHeaders; + this.headerRows = headerRows; + this.customHeaders = headers; } - public static CsvConfig createListTypeOptions(BMap options) { - updateDataProjectOptions(options); - return new CsvConfig( - options.get(Constants.ConfigConstants.SKIP_LINES), - options.getBooleanValue(Constants.ConfigConstants.NIL_AS_OPTIONAL).booleanValue(), - options.getBooleanValue(Constants.ConfigConstants.ABSENT_AS_NILABLE).booleanValue(), - options.getBooleanValue(Constants.ConfigConstants.ALLOW_DATA_PROJECTION).booleanValue(), - options.getBooleanValue(Constants.ConfigConstants.STRING_CONVERSION).booleanValue() - ); - } - - public static CsvConfig createListAsRecordTypeOptions(BMap options) { + public static CsvConfig createTransformOptions(BMap options) { updateDataProjectOptions(options); return new CsvConfig( + options.getBooleanValue(Constants.ConfigConstants.NIL_AS_OPTIONAL), + options.getBooleanValue(Constants.ConfigConstants.ABSENT_AS_NILABLE), + options.getBooleanValue(Constants.ConfigConstants.ALLOW_DATA_PROJECTION), options.get(Constants.ConfigConstants.SKIP_LINES), - options.getBooleanValue(Constants.ConfigConstants.NIL_AS_OPTIONAL).booleanValue(), - options.getBooleanValue(Constants.ConfigConstants.ABSENT_AS_NILABLE).booleanValue(), - options.getBooleanValue(Constants.ConfigConstants.ALLOW_DATA_PROJECTION).booleanValue(), - options.getBooleanValue(Constants.ConfigConstants.STRING_CONVERSION).booleanValue(), - options.get(Constants.ConfigConstants.CUSTOM_HEADERS), - options.getBooleanValue(Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION).booleanValue() + options.getBooleanValue(Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION), + options.getBooleanValue(Constants.ConfigConstants.OUTPUT_WITH_HEADERS), + options.get(Constants.ConfigConstants.HEADERS_ORDER) ); } - private CsvConfig(char delimiter, char textEnclosure, Object header, - char escapeChar, Object lineTerminator, Object skipLines, - Object nilValue, char comment, String locale, - boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection) { - this.delimiter = delimiter; - this.textEnclosure = textEnclosure; - this.header = header; - this.escapeChar = escapeChar; - this.lineTerminator = lineTerminator; - this.nilValue = nilValue == null ? null : nilValue; - this.comment = comment; - this.locale = locale; - this.nilAsOptionalField = nilAsOptionalField; - this.absentAsNilableType = absentAsNilableType; - this.allowDataProjection = allowDataProjection; - this.skipLines = skipLines; - } - - private CsvConfig(char delimiter, char textEnclosure, Object header, char escapeChar, Object lineTerminator, - Object skipLines, Object nilValue, char comment, String locale, - boolean nilAsOptionalField, boolean absentAsNilableType, - boolean allowDataProjection, Object customHeaders, boolean enableConstraintValidation) { - this.delimiter = delimiter; - this.textEnclosure = textEnclosure; - this.header = header; - this.escapeChar = escapeChar; - this.lineTerminator = lineTerminator; - this.nilValue = nilValue == null ? null : nilValue; - this.comment = comment; - this.locale = locale; + public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, + Object skipLines, boolean enableConstraintValidation, boolean outputWithHeaders, + Object headersOrder) { this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; this.skipLines = skipLines; - this.customHeader = customHeaders; this.enableConstraintValidation = enableConstraintValidation; + this.outputWithHeaders = outputWithHeaders; + this.headersOrder = headersOrder; } - public static CsvConfig createRecordAsRecordOption(BMap options) { + public static CsvConfig createParseOptions(BMap options) { updateDataProjectOptions(options); return new CsvConfig( - options.getBooleanValue(Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION), - options.get(Constants.ConfigConstants.SKIP_LINES), options.getBooleanValue(Constants.ConfigConstants.NIL_AS_OPTIONAL), options.getBooleanValue(Constants.ConfigConstants.ABSENT_AS_NILABLE), - options.getBooleanValue(Constants.ConfigConstants.ALLOW_DATA_PROJECTION) - ); - } - - public static CsvConfig createParseOptions(BMap options) { - updateDataProjectOptions(options); - return new CsvConfig( + options.getBooleanValue(Constants.ConfigConstants.ALLOW_DATA_PROJECTION), + options.get(Constants.ConfigConstants.SKIP_LINES), + options.getBooleanValue(Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION), + options.getBooleanValue(Constants.ConfigConstants.OUTPUT_WITH_HEADERS), StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.DELIMITER)).charAt(0), + StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.LOCALE)), StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.TEXT_ENCLOSURE)).charAt(0), - options.get(Constants.ConfigConstants.HEADER), StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.ESCAPE_CHAR)).charAt(0), options.get(Constants.ConfigConstants.LINE_TERMINATOR), - options.get(Constants.ConfigConstants.SKIP_LINES), options.get(Constants.ConfigConstants.NIL_VALUE), StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.COMMENT_CHAR)).charAt(0), - StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.LOCALE)), - options.getBooleanValue(Constants.ConfigConstants.NIL_AS_OPTIONAL), - options.getBooleanValue(Constants.ConfigConstants.ABSENT_AS_NILABLE), - options.getBooleanValue(Constants.ConfigConstants.ALLOW_DATA_PROJECTION) - ); - } - - public static CsvConfig createParserToRecordOptions(BMap options) { - updateDataProjectOptions(options); - return new CsvConfig( - StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.DELIMITER)).charAt(0), - StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.TEXT_ENCLOSURE)).charAt(0), options.get(Constants.ConfigConstants.HEADER), - StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.ESCAPE_CHAR)).charAt(0), - options.get(Constants.ConfigConstants.LINE_TERMINATOR), - options.get(Constants.ConfigConstants.SKIP_LINES), - options.getStringValue(Constants.ConfigConstants.NIL_VALUE), - StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.COMMENT_CHAR)).charAt(0), - StringUtils.getStringValue(options.getStringValue(Constants.ConfigConstants.LOCALE)), - options.getBooleanValue(Constants.ConfigConstants.NIL_AS_OPTIONAL), - options.getBooleanValue(Constants.ConfigConstants.ABSENT_AS_NILABLE), - options.getBooleanValue(Constants.ConfigConstants.ALLOW_DATA_PROJECTION), - options.get(Constants.ConfigConstants.CUSTOM_HEADERS), - options.getBooleanValue(Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION) + options.get(Constants.ConfigConstants.CUSTOM_HEADERS_IF_HEADER_ABSENT) ); } - public static CsvConfig createToRecordOptions(BMap options) { - updateDataProjectOptions(options); - return new CsvConfig( - options.get(Constants.ConfigConstants.SKIP_LINES), - options.getBooleanValue(Constants.ConfigConstants.NIL_AS_OPTIONAL), - options.getBooleanValue(Constants.ConfigConstants.ABSENT_AS_NILABLE), - options.getBooleanValue(Constants.ConfigConstants.ALLOW_DATA_PROJECTION), - options.get(Constants.ConfigConstants.CUSTOM_HEADERS) - ); + public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, + Object skipLines, boolean enableConstraintValidation, boolean outputWithHeaders, char delimiter, + String locale, char textEnclosure, char escapeChar, Object lineTerminator, + Object nilValue, char comment, Object header, Object customHeadersIfHeaderAbsent) { + this.nilAsOptionalField = nilAsOptionalField; + this.absentAsNilableType = absentAsNilableType; + this.allowDataProjection = allowDataProjection; + this.skipLines = skipLines; + this.enableConstraintValidation = enableConstraintValidation; + this.outputWithHeaders = outputWithHeaders; + this.delimiter = delimiter; + this.locale = locale; + this.textEnclosure = textEnclosure; + this.escapeChar = escapeChar; + this.lineTerminator = lineTerminator; + this.nilValue = nilValue; + this.comment = comment; + this.header = header; + this.customHeadersIfHeaderAbsent = customHeadersIfHeaderAbsent; } - public static CsvConfig createConfigOptionsForUnion(CsvConfig config) { return new CsvConfig(config); } 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 fd4c849..b7ff4c6 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 @@ -9,6 +9,7 @@ import io.ballerina.runtime.api.types.TupleType; import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BDecimal; @@ -42,51 +43,62 @@ public static void validateExpectedArraySize(int size, int currentSize) { } } - public static boolean isBasicType(Type type) { - switch (type.getTag()) { - case TypeTags.INT_TAG: - case TypeTags.STRING_TAG: - case TypeTags.BOOLEAN_TAG: - case TypeTags.DECIMAL_TAG: - case TypeTags.FLOAT_TAG: - case TypeTags.NULL_TAG: - case TypeTags.JSON_TAG: - case TypeTags.ANYDATA_TAG: - case TypeTags.UNION_TAG: - case TypeTags.INTERSECTION_TAG: - case TypeTags.CHAR_STRING_TAG: - case TypeTags.BYTE_TAG: - case TypeTags.SIGNED8_INT_TAG: - case TypeTags.SIGNED16_INT_TAG: - case TypeTags.SIGNED32_INT_TAG: - case TypeTags.UNSIGNED8_INT_TAG: - case TypeTags.UNSIGNED16_INT_TAG: - case TypeTags.UNSIGNED32_INT_TAG: - return true; - default: - return false; - } + public static boolean isExpectedTypeIsArray(Type expectedType) { + expectedType = TypeUtils.getReferredType(expectedType); + + return switch (expectedType.getTag()) { + case TypeTags.TUPLE_TAG, TypeTags.ARRAY_TAG -> true; + default -> false; + }; } - public static String[] createHeaders(String[] headers, CsvConfig config) { - Object customHeaders = config.customHeader; + public static boolean isExpectedTypeIsMap(Type expectedType) { + expectedType = TypeUtils.getReferredType(expectedType); - if (customHeaders == null) { - for (int i = 0; i < headers.length; i++) { - headers[i] = String.valueOf(i + 1); - } - } + return switch (expectedType.getTag()) { + case TypeTags.MAP_TAG, TypeTags.RECORD_TYPE_TAG -> true; + default -> false; + }; + } + + public static boolean isBasicType(Type type) { + return switch (type.getTag()) { + case TypeTags.INT_TAG, TypeTags.STRING_TAG, TypeTags.BOOLEAN_TAG, TypeTags.DECIMAL_TAG, TypeTags.FLOAT_TAG, + TypeTags.NULL_TAG, TypeTags.JSON_TAG, TypeTags.ANYDATA_TAG, TypeTags.UNION_TAG, + TypeTags.INTERSECTION_TAG, TypeTags.CHAR_STRING_TAG, TypeTags.BYTE_TAG, TypeTags.SIGNED8_INT_TAG, + TypeTags.SIGNED16_INT_TAG, TypeTags.SIGNED32_INT_TAG, TypeTags.UNSIGNED8_INT_TAG, + TypeTags.UNSIGNED16_INT_TAG, TypeTags.UNSIGNED32_INT_TAG -> true; + default -> false; + }; + } + + public static String[] createHeadersForParseLists(BArray csvElement, String[] headers, CsvConfig config) { + Object customHeaders = config.customHeaders; + long headerRows = config.headerRows; - if (customHeaders instanceof BArray) { - BArray array = (BArray) customHeaders; - if (array.size() != headers.length) { + int length = headers.length; + if (customHeaders instanceof BArray array) { + if (array.size() != length) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); } - for (int i = 0; i < headers.length; i++) { + for (int i = 0; i < length; i++) { headers[i] = array.get(i).toString(); } + return headers; } + if (headerRows == 1) { + return csvElement.getStringArray(); + } + + if (headerRows > 1) { + throw DiagnosticLog.error(DiagnosticErrorCode.NO_CUSTOM_HEADER_PROVIDED); + } + + // when headerRows = 0 and customHeaders = null + for (int i = 0; i < length; i++) { + headers[i] = String.valueOf(i + 1); + } return headers; } @@ -163,9 +175,7 @@ public static boolean checkTypeCompatibility(Type constraintType, Object csv, bo } } if (csv == null) { - if (tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag)) { - return true; - } + return tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag); } return false; } @@ -295,10 +305,7 @@ private static boolean handleStringNullValue(Object nullValue, String v, Object || Constants.Values.BALLERINA_NULL.equalsIgnoreCase(v))) { return true; } - if (nullValue != null && value.equals(StringUtils.getStringValue(nullValue))) { - return true; - } - return false; + return nullValue != null && value.equals(StringUtils.getStringValue(nullValue)); } public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object lineTerminatorObj) { @@ -318,10 +325,7 @@ public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object li if (c == Constants.LineTerminator.LF) { if (lineTerminator != null) { if (lineTerminator.equals(Constants.LineTerminator.CRLF)) { - if (isCarriageTokenPresent) { - return true; - } - return false; + return isCarriageTokenPresent; } return true; } 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 ce669fd..32e9941 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 @@ -44,13 +44,16 @@ public enum DiagnosticErrorCode { INVALID_FORMAT_FOR_SKIPLINES("BDE_0017", "invalid.format.for.skiplines"), INVALID_RANGE_FOR_SKIPLINES("BDE_0018", "invalid.range.for.skiplines"), INVALID_VALUE_FOR_SKIPLINES("BDE_0019", "invalid.value.for.skiplines"), - INVALID_CUSTOM_HEADER("BDE_0020", "invalid.custom.header"), + INCONSISTENT_HEADER("BDE_0020", "inconsistent.header"), INVALID_CUSTOM_HEADER_LENGTH("BDE_0021", "invalid.custom.header.length"), INVALID_HEADER_NAMES_LENGTH("BDE_0022", "invalid.header.names.length"), HEADER_CANNOT_BE_EMPTY("BDE_0023", "header.cannot.be.empty"), NO_FIELD_FOR_HEADER("BDE_0024", "no.field.for.header"), DUPLICATE_FIELD("BDE_0025", "duplicate.field"), - SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE("BDE_0026", "cannot.convert.into.exptype"); + SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE("BDE_0026", "cannot.convert.into.exptype"), + NO_CUSTOM_HEADER_PROVIDED("BDE_0027", "no.custom.header.provided"), + HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED("BDE_0027", + "headers.with.varying.length.not.supported"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/csv_error.properties b/native/src/main/resources/csv_error.properties index 5424a8e..d653d87 100644 --- a/native/src/main/resources/csv_error.properties +++ b/native/src/main/resources/csv_error.properties @@ -78,14 +78,14 @@ error.invalid.range.for.skiplines=\ error.invalid.value.for.skiplines=\ Invalid input for the skipLines field. Both start and end values must be integers. -error.invalid.custom.header=\ - Invalid header value: ''{0}'' +error.inconsistent.header=\ + Header ''{0}'' cannot be find in data rows error.invalid.custom.header.length=\ - Invalid length for the custom headers + Invalid length for the headers error.invalid.header.names.length=\ - Invalid length for the header names + Invalid number of headers error.header.cannot.be.empty=\ The provided header row is empty @@ -98,3 +98,9 @@ error.duplicate.field=\ error.cannot.convert.into.exptype=\ The source value cannot convert in to the ''{0}'' + +error.no.custom.header.provided=\ + Custom headers should be provided + +error.headers.with.varying.length.not.supported=\ + CSV data rows with varying headers are not yet supported \ No newline at end of file