From 1dcb5c4176b4f4d0029311821161ad0555e986b9 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 15 Feb 2024 22:21:27 +0530 Subject: [PATCH 001/147] initial commit --- .gitattributes | 2 + .github/CODEOWNERS | 7 + .github/pull_request_template.md | 12 + .../workflows/build-timestamped-master.yml | 18 + .../workflows/build-with-bal-test-graalvm.yml | 37 + .github/workflows/central-publish.yml | 21 + .github/workflows/publish-release.yml | 16 + .github/workflows/pull-request.yml | 14 + .github/workflows/stale_check.yml | 19 + .github/workflows/trivy-scan.yml | 13 + .gitignore | 24 +- .vscode/launch.json | 28 + README.md | 455 ++++++++++- ballerina/Ballerina.toml | 19 + ballerina/Dependencies.toml | 74 ++ ballerina/Package.md | 400 ++++++++++ ballerina/a.txt | 3 + ballerina/build.gradle | 126 +++ ballerina/csv_api.bal | 80 ++ ballerina/init.bal | 25 + ballerina/tests/consider | 3 + ballerina/tests/test.bal | 327 ++++++++ build-config/checkstyle/build.gradle | 48 ++ build-config/resources/Ballerina.toml | 19 + build.gradle | 92 +++ gradle.properties | 15 + gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 59536 bytes gradle/wrapper/gradle-wrapper.properties | 7 + gradlew | 248 ++++++ gradlew.bat | 92 +++ native/build.gradle | 78 ++ .../stdlib/data/csvdata/FromString.java | 188 +++++ .../csv/BallerinaByteBlockInputStream.java | 168 ++++ .../stdlib/data/csvdata/csv/CsvCreator.java | 244 ++++++ .../stdlib/data/csvdata/csv/CsvParser.java | 545 +++++++++++++ .../stdlib/data/csvdata/csv/CsvTraversal.java | 530 +++++++++++++ .../stdlib/data/csvdata/csv/Native.java | 57 ++ .../data/csvdata/csv/QualifiedName.java | 83 ++ .../stdlib/data/csvdata/utils/Constants.java | 68 ++ .../stdlib/data/csvdata/utils/DataUtils.java | 721 ++++++++++++++++++ .../csvdata/utils/DiagnosticErrorCode.java | 60 ++ .../data/csvdata/utils/DiagnosticLog.java | 53 ++ .../data/csvdata/utils/ModuleUtils.java | 46 ++ native/src/main/java/module-info.java | 25 + .../data/csvdata-native/resource-config.json | 6 + native/src/main/resources/error.properties | 75 ++ settings.gradle | 41 + 47 files changed, 5230 insertions(+), 2 deletions(-) create mode 100644 .gitattributes create mode 100644 .github/CODEOWNERS create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/build-timestamped-master.yml create mode 100644 .github/workflows/build-with-bal-test-graalvm.yml create mode 100644 .github/workflows/central-publish.yml create mode 100644 .github/workflows/publish-release.yml create mode 100644 .github/workflows/pull-request.yml create mode 100644 .github/workflows/stale_check.yml create mode 100644 .github/workflows/trivy-scan.yml create mode 100644 .vscode/launch.json create mode 100644 ballerina/Ballerina.toml create mode 100644 ballerina/Dependencies.toml create mode 100644 ballerina/Package.md create mode 100644 ballerina/a.txt create mode 100644 ballerina/build.gradle create mode 100644 ballerina/csv_api.bal create mode 100644 ballerina/init.bal create mode 100644 ballerina/tests/consider create mode 100644 ballerina/tests/test.bal create mode 100644 build-config/checkstyle/build.gradle create mode 100644 build-config/resources/Ballerina.toml create mode 100644 build.gradle create mode 100644 gradle.properties create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100755 gradlew create mode 100644 gradlew.bat create mode 100644 native/build.gradle create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/BallerinaByteBlockInputStream.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QualifiedName.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/ModuleUtils.java create mode 100644 native/src/main/java/module-info.java create mode 100644 native/src/main/resources/META-INF/native-image/io.ballerina.stdlib/data/csvdata-native/resource-config.json create mode 100644 native/src/main/resources/error.properties create mode 100644 settings.gradle diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..d13affe --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Ensure all Java files use LF. +*.java eol=lf diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..c5ebbcf --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1,7 @@ +# Lines starting with '#' are comments. +# Each line is a file pattern followed by one or more owners. + +# See: https://help.github.com/articles/about-codeowners/ + +# These owners will be the default owners for everything in the repo. +* @hasithaa @prakanth97 diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..96b073c --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,12 @@ +## Purpose + +Fixes: + +## Examples + +## Checklist +- [ ] Linked to an issue +- [ ] Updated the changelog +- [ ] Added tests +- [ ] Updated the spec +- [ ] Checked native-image compatibility diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml new file mode 100644 index 0000000..dc0b8e4 --- /dev/null +++ b/.github/workflows/build-timestamped-master.yml @@ -0,0 +1,18 @@ +name: Build + +on: + push: + branches: + - main + paths-ignore: + - '*.md' + - 'docs/**' + - 'load-tests/**' + workflow_dispatch: + +jobs: + call_workflow: + name: Run Build Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-timestamp-master-template.yml@main + secrets: inherit diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml new file mode 100644 index 0000000..fc149e3 --- /dev/null +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -0,0 +1,37 @@ +name: GraalVM Check + +on: + workflow_dispatch: + inputs: + lang_tag: + description: Branch/Release Tag of the Ballerina Lang + required: true + default: master + lang_version: + description: Ballerina Lang Version (If given ballerina lang build will be skipped) + required: false + default: '' + native_image_options: + description: Default native-image options + required: false + default: '' + schedule: + - cron: '30 18 * * *' + pull_request: + branches: + - main + types: [ opened, synchronize, reopened, labeled, unlabeled ] + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: true + +jobs: + call_stdlib_workflow: + name: Run StdLib Workflow + if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main + with: + lang_tag: ${{ inputs.lang_tag }} + lang_version: ${{ inputs.lang_version }} + native_image_options: '-J-Xmx7G ${{ inputs.native_image_options }}' diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml new file mode 100644 index 0000000..c0bd478 --- /dev/null +++ b/.github/workflows/central-publish.yml @@ -0,0 +1,21 @@ +name: Publish to the Ballerina central + +on: + workflow_dispatch: + inputs: + environment: + type: choice + description: Select Environment + required: true + options: + - DEV CENTRAL + - STAGE CENTRAL + +jobs: + call_workflow: + name: Run Central Publish Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/central-publish-template.yml@main + secrets: inherit + with: + environment: ${{ github.event.inputs.environment }} diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 0000000..2091ca0 --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,16 @@ +name: Publish Release + +on: + workflow_dispatch: + repository_dispatch: + types: [stdlib-release-pipeline] + +jobs: + call_workflow: + name: Run Release Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/release-package-template.yml@main + secrets: inherit + with: + package-name: persist + package-org: ballerina diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml new file mode 100644 index 0000000..48bfdc3 --- /dev/null +++ b/.github/workflows/pull-request.yml @@ -0,0 +1,14 @@ +name: Pull Request + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }} + cancel-in-progress: true + +on: pull_request + +jobs: + call_workflow: + name: Run PR Build Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/pull-request-build-template.yml@main + secrets: inherit diff --git a/.github/workflows/stale_check.yml b/.github/workflows/stale_check.yml new file mode 100644 index 0000000..8763360 --- /dev/null +++ b/.github/workflows/stale_check.yml @@ -0,0 +1,19 @@ +name: 'Close stale pull requests' + +on: + schedule: + - cron: '30 19 * * *' + workflow_dispatch: + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v3 + with: + stale-pr-message: 'This PR has been open for more than 15 days with no activity. This will be closed in 3 days unless the `stale` label is removed or commented.' + close-pr-message: 'Closed PR due to inactivity for more than 18 days.' + days-before-pr-stale: 15 + days-before-pr-close: 3 + days-before-issue-stale: -1 + days-before-issue-close: -1 diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml new file mode 100644 index 0000000..e625103 --- /dev/null +++ b/.github/workflows/trivy-scan.yml @@ -0,0 +1,13 @@ +name: Trivy + +on: + workflow_dispatch: + schedule: + - cron: "30 20 * * *" + +jobs: + call_workflow: + name: Run Trivy Scan Workflow + if: ${{ github.repository_owner == 'ballerina-platform' }} + uses: ballerina-platform/ballerina-standard-library/.github/workflows/trivy-scan-template.yml@main + secrets: inherit diff --git a/.gitignore b/.gitignore index 524f096..1d2a7ee 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ # Log file *.log +# Lock file +*.lck + # BlueJ files *.ctxt @@ -12,6 +15,7 @@ # Package Files # *.jar +!gradle/wrapper/gradle-wrapper.jar *.war *.nar *.ear @@ -19,6 +23,24 @@ *.tar.gz *.rar -# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml +# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.csv hs_err_pid* replay_pid* + +build +.gradle/ +target +bin/ + +# IDEA Files +.idea/ +*.iml +*.ipr +*.iws + +# MacOS +*.DS_Store + +# Ballerina +velocity.log* +*Ballerina.lock diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..85f0dfd --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,28 @@ +{ + "configurations": [ + { + "name": "Ballerina Debug", + "type": "ballerina", + "request": "launch", + "programArgs": [], + "commandOptions": [], + "env": {} + }, + { + "name": "Ballerina Test", + "type": "ballerina", + "request": "launch", + "debugTests": true, + "programArgs": [], + "commandOptions": [], + "env": {} + }, + { + "name": "Ballerina Remote", + "type": "ballerina", + "request": "attach", + "debuggeeHost": "127.0.0.1", + "debuggeePort": "5005" + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 94f4ba4..ba9bc60 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,455 @@ -# module-ballerina-data.csv +# Ballerina CSV Data Library + The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate the handling and manipulation of CSV data within Ballerina applications. It streamlines the process of converting CSV data to native Ballerina data types, enabling developers to work with CSV content seamlessly and efficiently. + +This library is the refined successor of the `ballerina/csvdata` module, incorporating enhanced functionalities and improved performance. + +## Features + +- **Versatile CSV Data Input**: Accept CSV data as a csv, a string, byte array, or a stream and convert it into a Record value. +- **CSV to Record Value Conversion**: Transform CSV data into Ballerina records with ease in compliance with OpenAPI 3 standards. +- **Projection Support**: Perform selective conversion of CSV data subsets into Record values through projection. + +## Usage + +### Converting an CSV value to a Record value + +To convert an CSV value to a Record value, you can utilize the `fromCsvWithType` function provided by the library. The example below showcases the transformation of an CSV value into a Record value. + +```ballerina +import ballerina/data.csv; +import ballerina/io; + +public function main() returns error? { + csv data = csv ` + 0 + string + string + `; + + Book book = check csvdata:fromCsvWithType(data); + io:println(book); +} + +type Book record {| + int id; + string title; + string author; +|}; +``` + +### Converting an external CSV document to a Record value + +For transforming CSV content from an external source into a Record value, the `fromCsvStringWithType` function can be used. This external source can be in the form of a string or a byte array/byte 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; +import ballerina/io; + +public function main() returns error? { + string csvContent = check io:fileReadString("path/to/file.csv"); + Book book = check csvdata:fromCsvStringWithType(csvContent); + io:println(book); +} + +type Book record {| + int id; + string title; + string author; +|}; +``` + +Make sure to handle possible errors that may arise during the file reading or CSV to record conversion process. The `check` keyword is utilized to handle these errors, but more sophisticated error handling can be implemented as per your requirements. + +## CSV to Record Canonical Representation + +The translation of CSV to a Record representation is a fundamental feature of the library. It facilitates a structured and type-safe approach to handling CSV data within Ballerina applications. + +Take for instance the following CSV snippet: + +```csv + + 0 + string + string + +``` + +CSV data is inherently hierarchical, forming a tree structure. In the given example, the root element is `book`, which encompasses three child elements: `id`, `title`, and `author`. The `id` element harbors a numeric value `0`, whereas both the `title` and `author` elements contain string values. + +A straightforward record representation of the above CSV data is: + +```ballerina +type Book record {| + int id; + string title; + string author; +|}; +``` + +In this representation, the CSV data is efficiently translated into a record value. The `book` element is mapped to a record of type `Book`, and the child elements `id`, `title`, and `author` are converted into record fields of types `int` and `string` correspondingly. + +This record type definition can be further refined through annotations. Moreover, utilizing open and closed records grants control over the translation process, which is elaborated in subsequent sections. + +### CSV Element Names + +The name of the CSV element serves as the name of the record field, altered to fit a valid Ballerina identifier. Notably, the record field name corresponds to the local name of the CSV element, with any namespace prefixes being disregarded. + +Consider the CSV snippet: + +```csv + + 0 + string + string + +``` + +The canonical representation of the above CSV as a Ballerina record is: + +```ballerina +type Book record {| + int id; + string 'title\-name'; + string 'author\-name'; +|}; +``` + +Observe how the CSV element names `title-name` and `author-name` are represented using delimited identifiers in Ballerina; the `-` characters in the CSV element names are escaped using the `\` character. + +Moreover, the `@Name` annotation can be utilized to explicitly specify the name of the record field, providing control over the translation process: + +```ballerina +import ballerina/data.csv; + +type Book record {| + int id; + @csvdata:Name { value: "title-name" } + string title; + @csvdata:Name { value: "author-name" } + string author; +|}; +``` + +### CSV Attributes + +Similarly to CSV elements, CSV attributes are also represented into record fields within the corresponding parent Record type. The name of the CSV attribute is converted into the name of the record field, ensuring it is a valid Ballerina identifier. It is crucial to emphasize that the record field name aligns with the local name of the CSV attribute, and any namespace prefixes are ignored. + +Consider the following CSV snippet: + +```csv + + 0 + string + string + +``` + +The canonical representation of the above CSV as a Ballerina record is: + +```ballerina +type Book record {| + string lang; + decimal price; + int id; + string title; + string author; +|}; +``` + +Additionally the `@Attribute` annotation can be utilized to explicitly specify the name of the record field, providing control over the translation process. + +### Child Elements + +Child elements are mapped to record fields, with the type reflecting that of the corresponding child element. + +Examine the CSV snippet below: + +```csv + + 0 + string + + string + string + + +``` + +The canonical representation of the above CSV as a Ballerina record is: + +```ballerina +type Book record {| + int id; + string title; + Author author; +|}; + +type Author record {| + string name; + string country; +|}; +``` + +In this transformation, child elements, like the `author` element containing its own sub-elements, are converted into nested records. This maintains the hierarchical structure of the CSV data within the Ballerina type system, enabling intuitive and type-safe data manipulation. + +Alternatively, inline type definitions offer a compact method for representing child elements as records within their parent record. This approach is particularly beneficial when the child record does not require reuse elsewhere and is unique to its parent record. + +Consider the subsequent Ballerina record definition, which employs inline type definition for the `author` field: + +```ballerina +type Book record {| + int id; + string title; + record {| + string name; + string country; + |} author; +|}; +``` + +### CSV Text Content + +The transformation of CSV text content into record fields typically involves types like `string`, `boolean`, `int`, `float`, or `decimal`, depending on the textual content. For numeric values where type information is not explicitly defined, the default conversion type is `decimal`. Conversely, for non-numeric content, the default type is `string`. + +Consider the CSV snippet below: + +```csv + + 0 + string + string + true + 10.5 + +``` + +The translation into a Ballerina record would be as follows: + +```ballerina +type Book record {| + int id; + string title; + string author; + boolean available; + decimal price; +|}; +``` + +In scenarios where the parent CSV element of text content also includes attributes, the CSV text content can be represented by a `string` type field named `#content` within a record type, with the attributes being mapped to their respective fields. + +For instance, examine this CSV: + +```csv + + 0 + string + 10.5 + +``` + +The canonical translation of CSV to a Ballerina record is as such: + +```ballerina +type Book record {| + int id; + Title title; + decimal price; +|}; + +type Title record {| + string \#content; + string lang; +|}; +``` + +Modifications to the default behavior for converting numerical values can be achieved by providing `Options` mappings to the respective functions. This enables developers to choose specific data types and exert finer control over the conversion process. + +### CSV Namespaces + +CSV namespaces are accommodated by the library, supporting the translation of CSV data that contains namespace prefixes. However, the presence of CSV namespaces is not mandatory, and the library is capable of processing CSV data without namespaces. Should namespaces be present, they will be utilized to resolve the names of CSV elements and attributes. + +It's important to note that, unlike in the `csvdata` module, the namespace prefixes do not reflect in the record field names, as the record field names align with the local names of the CSV elements. + +Examine the CSV snippet below with default namespaces: + +```csv + + 0 + string + string + +``` + +The translation into a Ballerina record would be: + +```ballerina +type Book record {| + int id; + string title; + string author; +|}; +``` + +Incorporating namespace validation yields: + +```ballerina +import ballerina/data.csv; + +@csvdata:Namespace { + uri: "http://example.com/book" +} +type Book record {| + int id; + string title; + string author; +|}; +``` + +Here is the same CSV snippet with a namespace prefix: + +```csv + + 0 + string + string + +``` + +The translation into a Ballerina record would be: + +```ballerina +import ballerina/data.csv; + +@csvdata:Namespace { + uri: "http://example.com/book", + prefix: "bk" +} +type Book record {| + int id; + string title; + string author; +|}; +``` + +In these examples, the CSV namespaces are appropriately acknowledged, ensuring the integrity of the CSV structure within the Ballerina records. + +### Working with Arrays + +The library is equipped to handle the transformation of CSV data containing arrays into Ballerina records. + +Take the following CSV snippet as an example: + +```csv + + 0 + string + string + string + string + +``` + +The canonical representation of this CSV as a Ballerina record is: + +```ballerina +type Book record {| + int id; + string title; + string[] author; +|}; +``` + +### Controlling Which Elements to Convert + +The library allows for selective conversion of CSV elements into records through the use of rest fields. This is beneficial when the CSV data contains elements that are not necessary to be transformed into record fields. + +Take this CSV snippet as an example: + +```csv + + 0 + string + string + 10.5 + +``` + +Suppose that only the book `id`, and `title` elements are needed for conversion into record fields. This can be achieved by defining only the required fields in the record type and omitting the rest field: + +```ballerina +type Book record {| + int id; + string title; +|}; +``` + +However, if the rest field is utilized (or if the record type is defined as an open record), all elements in the CSV data will be transformed into record fields: + +```ballerina +type Book record {| + int id; + string title; +|}; +``` + +In this instance, all other elements in the CSV data, such as `author` and `price` along with their attributes, will be transformed into `string` type fields with the corresponding element name as the key. + +This behavior extends to arrays as well. + +The process of projecting CSV data into a record supports various use cases, including the filtering out of unnecessary elements. This functionality is anticipated to be enhanced in the future to accommodate more complex scenarios, such as filtering values based on regular expressions, among others. + +## Issues and projects + +Issues and Projects tabs are disabled for this repository as this is part of the Ballerina standard library. To report bugs, request new features, start new discussions, view project boards, etc. please visit Ballerina standard library [parent repository](https://github.com/ballerina-platform/ballerina-standard-library). + +This repository only contains the source code for the package. + +## Building from the source + +### Set up the prerequisites + +1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations). + * [Oracle](https://www.oracle.com/java/technologies/downloads/) + * [OpenJDK](https://adoptium.net/) + +2. Export your GitHub personal access token with the read package permissions as follows. + + export packageUser= + export packagePAT= + +### Building the source + +Execute the commands below to build from source. + +1. To build the library: + + ./gradlew clean build + +2. Publish ZIP artifact to the local `.m2` repository: + + ./gradlew clean build publishToMavenLocal + +3. Publish the generated artifacts to the local Ballerina central repository: + + ./gradlew clean build -PpublishToLocalCentral=true + +4. Publish the generated artifacts to the Ballerina central repository: + + ./gradlew clean build -PpublishToCentral=true + +## Contributing to Ballerina + +As an open source project, Ballerina welcomes contributions from the community. + +For more information, go to the [contribution guidelines](https://github.com/ballerina-platform/ballerina-lang/blob/master/CONTRIBUTING.md). + +## Code of conduct + +All contributors are encouraged to read the [Ballerina code of conduct](https://ballerina.io/code-of-conduct). + +## Useful links + +[//]: # (* For more information go to the [`csvdata` library](https://lib.ballerina.io/ballerina/data.csv/latest).) +* Chat live with us via our [Discord server](https://discord.gg/ballerinalang). +* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag. \ No newline at end of file diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml new file mode 100644 index 0000000..f53bd7a --- /dev/null +++ b/ballerina/Ballerina.toml @@ -0,0 +1,19 @@ +[package] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +authors = ["Ballerina"] +keywords = ["csv"] +repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" +license = ["Apache-2.0"] +distribution = "2201.8.1" +export = ["data.csv"] + +[platform.java17] +graalvmCompatible = true + +[[platform.java17.dependency]] +groupId = "io.ballerina.stdlib" +artifactId = "data.csv-native" +version = "0.1.0" +path = "../native/build/libs/data.csv-native-0.1.0-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml new file mode 100644 index 0000000..ddb95d8 --- /dev/null +++ b/ballerina/Dependencies.toml @@ -0,0 +1,74 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.8.3" + +[[package]] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} +] + +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +modules = [ + {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + diff --git a/ballerina/Package.md b/ballerina/Package.md new file mode 100644 index 0000000..ea15954 --- /dev/null +++ b/ballerina/Package.md @@ -0,0 +1,400 @@ +# Package overview + +This package is designed to facilitate the handling and manipulation of CSV data within Ballerina applications. It streamlines the process of converting CSV data to native Ballerina data types, enabling developers to work with CSV content seamlessly and efficiently. + +This library is the refined successor of the `ballerina/csvdata` module, incorporating enhanced functionalities and improved performance. + +## Features + +- **Versatile CSV Data Input**: Accept CSV data as a csv, a string, byte array, or a stream and convert it into a Record value. +- **CSV to Record Value Conversion**: Transform CSV data into Ballerina records with ease in compliance with OpenAPI 3 standards. +- **Projection Support**: Perform selective conversion of CSV data subsets into Record values through projection. + +## Usage + +### Converting an CSV value to a Record value + +To convert an CSV value to a Record value, you can utilize the `fromCsvWithType` function provided by the library. The example below showcases the transformation of an CSV value into a Record value. + +```ballerina +import ballerina/data.csv as csvdata; +import ballerina/io; + +public function main() returns error? { + csv data = csv ` + 0 + string + string + `; + + Book book = check csvdata:fromCsvWithType(data, Book); + io:println(book); +} + +type Book record { + int id; + string title; + string author; +}; +``` + +### Converting an external CSV document to a Record value + +For transforming CSV content from an external source into a Record value, the `fromCsvStringWithType` function can be used. This external source can be in the form of a string or a byte array/byte 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 as csvdata; +import ballerina/io; + +public function main() returns error? { + string csvContent = check io:fileReadString("path/to/file.csv"); + Book book = check csvdata:fromCsvStringWithType(csvContent, Book); + io:println(book); +} + +type Book record { + int id; + string title; + string author; +}; +``` + +Make sure to handle possible errors that may arise during the file reading or CSV to record conversion process. The `check` keyword is utilized to handle these errors, but more sophisticated error handling can be implemented as per your requirements. + +## CSV to Record Canonical Representation + +The translation of CSV to a Record representation is a fundamental feature of the library. It facilitates a structured and type-safe approach to handling CSV data within Ballerina applications. + +Take for instance the following CSV snippet: + +```csv + + 0 + string + string + +``` + +CSV data is inherently hierarchical, forming a tree structure. In the given example, the root element is `book`, which encompasses three child elements: `id`, `title`, and `author`. The `id` element harbors a numeric value `0`, whereas both the `title` and `author` elements contain string values. + +A straightforward record representation of the above CSV data is: + +```ballerina +type Book record { + int id; + string title; + string author; +}; +``` + +In this representation, the CSV data is efficiently translated into a record value. The `book` element is mapped to a record of type `Book`, and the child elements `id`, `title`, and `author` are converted into record fields of types `int` and `string` correspondingly. + +This record type definition can be further refined through annotations. Moreover, utilizing open and closed records grants control over the translation process, which is elaborated in subsequent sections. + +### CSV Element Names + +The name of the CSV element serves as the name of the record field, altered to fit a valid Ballerina identifier. Notably, the record field name corresponds to the local name of the CSV element, with any namespace prefixes being disregarded. + +Consider the CSV snippet: + +```csv + + 0 + string + string + +``` + +The canonical representation of the above CSV as a Ballerina record is: + +```ballerina +type Book record { + int id; + string 'title\-name'; + string 'author\-name'; +}; +``` + +Observe how the CSV element names `title-name` and `author-name` are represented using delimited identifiers in Ballerina; the `-` characters in the CSV element names are escaped using the `\` character. + +Moreover, the `@Name` annotation can be utilized to explicitly specify the name of the record field, providing control over the translation process: + +```ballerina +import ballerina/data.csv as csvdata; + +type Book record { + int id; + @csvdata:Name { value: "title-name" } + string title; + @csvdata:Name { value: "author-name" } + string author; +}; +``` + +### CSV Attributes + +Similarly to CSV elements, CSV attributes are also represented into record fields within the corresponding parent Record type. The name of the CSV attribute is converted into the name of the record field, ensuring it is a valid Ballerina identifier. It is crucial to emphasize that the record field name aligns with the local name of the CSV attribute, and any namespace prefixes are ignored. + +Consider the following CSV snippet: + +```csv + + 0 + string + string + +``` + +The canonical representation of the above CSV as a Ballerina record is: + +```ballerina +type Book record { + string lang; + decimal price; + int id; + string title; + string author; +}; +``` + +Additionally the `@Attribute` annotation can be utilized to explicitly specify the name of the record field, providing control over the translation process. + +### Child Elements + +Child elements are mapped to record fields, with the type reflecting that of the corresponding child element. + +Examine the CSV snippet below: + +```csv + + 0 + string + + string + string + + +``` + +The canonical representation of the above CSV as a Ballerina record is: + +```ballerina +type Book record { + int id; + string title; + Author author; +}; + +type Author record { + string name; + string country; +}; +``` + +In this transformation, child elements, like the `author` element containing its own sub-elements, are converted into nested records. This maintains the hierarchical structure of the CSV data within the Ballerina type system, enabling intuitive and type-safe data manipulation. + +Alternatively, inline type definitions offer a compact method for representing child elements as records within their parent record. This approach is particularly beneficial when the child record does not require reuse elsewhere and is unique to its parent record. + +Consider the subsequent Ballerina record definition, which employs inline type definition for the `author` field: + +```ballerina +type Book record { + int id; + string title; + record { + string name; + string country; + } author; +}; +``` + +### CSV Text Content + +The transformation of CSV text content into record fields typically involves types like `string`, `boolean`, `int`, `float`, or `decimal`, depending on the textual content. For numeric values where type information is not explicitly defined, the default conversion type is `decimal`. Conversely, for non-numeric content, the default type is `string`. + +Consider the CSV snippet below: + +```csv + + 0 + string + string + true + 10.5 + +``` + +The translation into a Ballerina record would be as follows: + +```ballerina +type Book record { + int id; + string title; + string author; + boolean available; + decimal price; +}; +``` + +In scenarios where the parent CSV element of text content also includes attributes, the CSV text content can be represented by a `string` type field named `#content` within a record type, with the attributes being mapped to their respective fields. + +For instance, examine this CSV: + +```csv + + 0 + string + 10.5 + +``` + +The canonical translation of CSV to a Ballerina record is as such: + +```ballerina +type Book record { + int id; + Title title; + decimal price; +}; + +type Title record { + string \#content; + string lang; +}; +``` + +Modifications to the default behavior for converting numerical values can be achieved by providing `Options` mappings to the respective functions. This enables developers to choose specific data types and exert finer control over the conversion process. + +### CSV Namespaces + +CSV namespaces are accommodated by the library, supporting the translation of CSV data that contains namespace prefixes. However, the presence of CSV namespaces is not mandatory, and the library is capable of processing CSV data without namespaces. Should namespaces be present, they will be utilized to resolve the names of CSV elements and attributes. + +It's important to note that, unlike in the `csvdata` module, the namespace prefixes do not reflect in the record field names, as the record field names align with the local names of the CSV elements. + +Examine the CSV snippet below with default namespaces: + +```csv + + 0 + string + string + +``` + +The translation into a Ballerina record would be: + +```ballerina +type Book record { + int id; + string title; + string author; +}; +``` + +Incorporating namespace validation yields: + +```ballerina +import ballerina/data.csv as csvdata; + +@csvdata:Namespace { + uri: "http://example.com/book" +} +type Book record { + int id; + string title; + string author; +}; +``` + +Here is the same CSV snippet with a namespace prefix: + +```csv + + 0 + string + string + +``` + +The translation into a Ballerina record would be: + +```ballerina +import ballerina/data.csv as csvdata; + +@csvdata:Namespace { + uri: "http://example.com/book", + prefix: "bk" +} +type Book record { + int id; + string title; + string author; +}; +``` + +In these examples, the CSV namespaces are appropriately acknowledged, ensuring the integrity of the CSV structure within the Ballerina records. + +### Working with Arrays + +The library is equipped to handle the transformation of CSV data containing arrays into Ballerina records. + +Take the following CSV snippet as an example: + +```csv + + 0 + string + string + string + string + +``` + +The canonical representation of this CSV as a Ballerina record is: + +```ballerina +type Book record { + int id; + string title; + string[] author; +}; +``` + +### Controlling Which Elements to Convert + +The library allows for selective conversion of CSV elements into records through the use of rest fields. This is beneficial when the CSV data contains elements that are not necessary to be transformed into record fields. + +Take this CSV snippet as an example: + +```csv + + 0 + string + string + 10.5 + +``` + +Suppose that only the book `id`, and `title` elements are needed for conversion into record fields. This can be achieved by defining only the required fields in the record type and omitting the rest field: + +```ballerina +type Book record {| + int id; + string title; +|}; +``` + +However, if the rest field is utilized (or if the record type is defined as an open record), all elements in the CSV data will be transformed into record fields: + +```ballerina +type Book record { + int id; + string title; +}; +``` + +In this instance, all other elements in the CSV data, such as `author` and `price` along with their attributes, will be transformed into `string` type fields with the corresponding element name as the key. + +This behavior extends to arrays as well. + +The process of projecting CSV data into a record supports various use cases, including the filtering out of unnecessary elements. This functionality is anticipated to be enhanced in the future to accommodate more complex scenarios, such as filtering values based on regular expressions, among others. diff --git a/ballerina/a.txt b/ballerina/a.txt new file mode 100644 index 0000000..efb9823 --- /dev/null +++ b/ballerina/a.txt @@ -0,0 +1,3 @@ +a,b,c +1,2,3 +4,5,6 \ No newline at end of file diff --git a/ballerina/build.gradle b/ballerina/build.gradle new file mode 100644 index 0000000..af94bbb --- /dev/null +++ b/ballerina/build.gradle @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +import org.apache.tools.ant.taskdefs.condition.Os + +buildscript { + repositories { + maven { + url = 'https://maven.pkg.github.com/ballerina-platform/plugin-gradle' + credentials { + username System.getenv("packageUser") + password System.getenv("packagePAT") + } + } + } + dependencies { + classpath "io.ballerina:plugin-gradle:${project.ballerinaGradlePluginVersion}" + } +} + +description = 'Ballerina - Data CSV Module' + +def packageName = "data.csv" +def packageOrg = "ballerina" + +def tomlVersion = stripBallerinaExtensionVersion("${project.version}") +def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/Ballerina.toml") +def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml") +// def compilerPluginTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/CompilerPlugin.toml") +// def compilerPluginTomlFile = new File("$project.projectDir/CompilerPlugin.toml") + +def stripBallerinaExtensionVersion(String extVersion) { + if (extVersion.matches(project.ext.timestampedVersionRegex)) { + def splitVersion = extVersion.split('-'); + if (splitVersion.length > 3) { + def strippedValues = splitVersion[0..-4] + return strippedValues.join('-') + } else { + return extVersion + } + } else { + return extVersion.replace("${project.ext.snapshotVersion}", "") + } +} + +apply plugin: 'io.ballerina.plugin' + +ballerina { + packageOrganization = packageOrg + module = packageName + langVersion = ballerinaLangVersion +} + +task updateTomlFiles { + doLast { + def newConfig = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version) + newConfig = newConfig.replace("@toml.version@", tomlVersion) + ballerinaTomlFile.text = newConfig + + // def newCompilerPluginToml = compilerPluginTomlFilePlaceHolder.text.replace("@project.version@", project.version) + // compilerPluginTomlFile.text = newCompilerPluginToml + } +} + +task commitTomlFiles { + doLast { + project.exec { + ignoreExitValue true + // if (Os.isFamily(Os.FAMILY_WINDOWS)) { + // commandLine 'cmd', '/c', "git commit Ballerina.toml Dependencies.toml CompilerPlugin.toml -m '[Automated] Update the native jar versions'" + // } else { + // commandLine 'sh', '-c', "git commit Ballerina.toml Dependencies.toml CompilerPlugin.toml -m '[Automated] Update the native jar versions'" + // } + } + } +} + +publishing { + publications { + maven(MavenPublication) { + artifact source: createArtifactZip, extension: 'zip' + } + } + + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/ballerina-platform/module-${packageOrg}-${packageName}") + credentials { + username = System.getenv("publishUser") + password = System.getenv("publishPAT") + } + } + } +} + +task deleteDependencyTomlFiles { + if (project.hasProperty("deleteDependencies")) { + delete "${project.projectDir}/Dependencies.toml" + } +} + + +updateTomlFiles.dependsOn copyStdlibs + +build.dependsOn "generatePomFileForMavenPublication" +build.dependsOn ":${packageName}-native:build" +//build.dependsOn ":${packageName}-compiler-plugin:build" +build.dependsOn deleteDependencyTomlFiles + +test.dependsOn ":${packageName}-native:build" +//test.dependsOn ":${packageName}-compiler-plugin:build" diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal new file mode 100644 index 0000000..30a77d1 --- /dev/null +++ b/ballerina/csv_api.bal @@ -0,0 +1,80 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/jballerina.java; + +type CsvConversionError error; + +public enum OrderType { + ASC, + DESC +}; + +public type ColumnOrder record {| + int|string column; + OrderType columnOrder = ASC; +|}; + +public type MappingConfig record {| + string keyValueSeparator = ":"; + string elementSeparator = ";"; +|}; + +public type FromCSVConfig record {| + int startNumber = 0; + int headerStartNumber = 0; + int dataStartNumber = 0; + boolean headers = true; + string:Char escapeCharacter = "\\"; + boolean ignoreEmptyLines = true; + string:Char separator = ","; + string quote = "\""; + boolean skipHeaders = false; + int skipdataRows = 0; + int dataRowCount = -1; + ColumnOrder|ColumnOrder[] orderBy = []; + string|int|string[]|int[]? skipColumns = (); + string[]|int[]? customheader = (); + boolean suppressEscaping = false; + MappingConfig mappingConfig = {}; + anydata nullValue = (); + string? root = (); +|}; + +public type ToCSVConfig record {| + string[]? headers = (); + string:Char separator = ","; + boolean skipHeaders = false; + int skipdataRows = 0; + int dataRowCount = -1; + ColumnOrder|ColumnOrder[] orderBy = []; + string|int|string[]|int[]? skipColumns = (); + boolean suppressEscaping = false; + MappingConfig mappingConfig = {}; + anydata nullValue = (); + string:Char escapeCharacter = "\\"; +|}; + +public isolated function fromCsvWithType((string[]|map|record{})[] value, FromCSVConfig config, typedesc<(record{}|map|anydata[])[]> t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + +public isolated function fromCsvStringWithType(string|byte[]|stream s, + FromCSVConfig config,typedesc<(record{}|map|anydata)[]> t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + +public isolated function toCsv(anydata[] value, ToCSVConfig config) returns (string|map|record{})[]|CsvConversionError { + return error(""); +} diff --git a/ballerina/init.bal b/ballerina/init.bal new file mode 100644 index 0000000..a0a98cb --- /dev/null +++ b/ballerina/init.bal @@ -0,0 +1,25 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/jballerina.java; + +isolated function init() { + setModule(); +} + +isolated function setModule() = @java:Method { + 'class: "io.ballerina.stdlib.data.csvdata.utils.ModuleUtils" +} external; diff --git a/ballerina/tests/consider b/ballerina/tests/consider new file mode 100644 index 0000000..96e06c7 --- /dev/null +++ b/ballerina/tests/consider @@ -0,0 +1,3 @@ +array size wenas, oter, inner, both +AA -> QQ +unions -. inp and output diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal new file mode 100644 index 0000000..5fbcf6d --- /dev/null +++ b/ballerina/tests/test.bal @@ -0,0 +1,327 @@ +import ballerina/test; +import ballerina/io; + +type A map[]; +type A2 map[]; + +type B record{|int a; int b;|}[]; +type B2 record{|string a; string b;|}[]; +type B3 record{}[]; +type B4 record{string '1; string '2; string '3;}[]; +type B5 record{string '1;}[]; +type B6 record{string name;}[]; + +type C string[][]; +type C2 string[][]; + +type D [int, int][]; +type D2 [string, string][]; + +map[] a = [{"a": "1", "b": "2"}, {"a": "1", "b": "2"}]; +map[] a2 = [{"a": 1, "b": 2}, {"a": 1, "b": 2}]; + +record {|int a; int b; int c;|}[] b = [{a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}]; +record {|string a; string b;|}[] b2 = [{a: "1", b: "2"}, {a: "1", b: "2"}]; + +string[][] c = [["1", "2", "3"], ["1", "2", "3"]]; +string[][] c2 = [["1", "2", "3"], ["1", "2", "3"]]; +int[][] c3 = [[1, 2], [1, 2]]; +int[][] c4 = [[1, 2, 3], [1, 2, 3]]; + +[string, string][] d = [["1", "2"], ["1", "2"]]; +[string, string][] d2 = [["1", "2"], ["1", "2"]]; + +@test:Config{enable: true} +public function testA() returns error? { + A aa = check fromCsvWithType(a, {}, A); + test:assertEquals(aa, a); + + A2 aa2 = check fromCsvWithType(a2, {}, A2); + test:assertEquals(aa2, a2); + + B bb = check fromCsvWithType(b, {}, B); + test:assertEquals(bb, [{a: 1, b: 2}, {a: 1, b: 2}]); + + B2 bb2 = check fromCsvWithType(b2, {}, B2); + test:assertEquals(bb2, b2); + + C cc = check fromCsvWithType(c, {}, C); + test:assertEquals(cc, c); + + C2 cc2 = check fromCsvWithType(c2, {}, C2); + test:assertEquals(cc2, c2); + + B2 ab2 = check fromCsvWithType(a, {}, B2); + test:assertEquals(ab2, a); + + C ac = check fromCsvWithType(a, {}, C); + test:assertEquals(ac, [["1", "2"], ["1", "2"]]); + + A ba = check fromCsvWithType(b, {}, A); + test:assertEquals(ba, [{a: "1", b: "2", c: "3"}, {a: "1", b: "2", c: "3"}]); + + A2 ba2 = check fromCsvWithType(b, {}, A2); + test:assertEquals(ba2, [{a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}]); + + C bc = check fromCsvWithType(b, {}, C); + test:assertEquals(bc, [["1", "2", "3"], ["1", "2", "3"]]); + + C2 bc2 = check fromCsvWithType(b2, {}, C2); + test:assertEquals(bc2, [["1", "2"], ["1", "2"]]); + + A ca = check fromCsvWithType(c, {}, A); + test:assertEquals(ca, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); + + // B2 cb2 = check fromCsvWithType(c, {}, B2); + // test:assertEquals(cb2, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); + + B3 cb3 = check fromCsvWithType(c, {}, B3); + test:assertEquals(cb3, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); + + B4 cb4 = check fromCsvWithType(c, {}, B4); + test:assertEquals(cb4, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); + + B5 cb5 = check fromCsvWithType(c, {}, B5); + test:assertEquals(cb5, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); + + // B6 cb6 = check fromCsvWithType(c, {}, B6); + // test:assertEquals(cb6, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); + + D2 ad2 = check fromCsvWithType(a, {}, D2); + test:assertEquals(ad2, [["1", "2"], ["1", "2"]]); + + D a2d = check fromCsvWithType(a2, {}, D); + test:assertEquals(a2d, [[1, 2], [1, 2]]); + + D2 a2d2 = check fromCsvWithType(a2, {}, D2); + test:assertEquals(a2d2, [["1", "2"], ["1", "2"]]); + + // D dd = check fromCsvWithType(d, {}, D); + // test:assertEquals(dd, d); + + D2 dd2 = check fromCsvWithType(d2, {}, D2); + test:assertEquals(dd2, d2); + + D bd = check fromCsvWithType(b, {}, D); + test:assertEquals(bd, [[1, 2], [1, 2]]); + + D2 bd2 = check fromCsvWithType(b2, {}, D2); + test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); + + D2 cd2 = check fromCsvWithType(c, {}, D2); + test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); + + A d2a = check fromCsvWithType(d2, {}, A); + test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); + + // B2 d2b2 = check fromCsvWithType(d2, {}, B2); + // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); + + C d2c = check fromCsvWithType(d2, {}, C); + test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); +} + +@test:Config{enable: false} +function testB() returns error? { + // B2 d2b2 = check fromCsvWithType(d2, {}, B2); + // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); + + // D2 ad2 = check fromCsvWithType(a, {}, D2); + // test:assertEquals(ad2, [["1", "2"], ["1", "2"]]); + + // D2 bd2 = check fromCsvWithType(b2, {}, D2); + // test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); + + // D2 cd2 = check fromCsvWithType(c, {}, D2); + // test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); + + // A d2a = check fromCsvWithType(d2, {}, A); + // test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); + + // B2 d2b2 = check fromCsvWithType(d2, {}, B2); + // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); + + // C d2c = check fromCsvWithType(d2, {}, C); + // test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); +} + + // D a2d = check fromCsvWithType(a2, {}, D); + // test:assertEquals(a2d, [[1, 2], [1, 2]]); + + // D2 a2d2 = check fromCsvWithType(a2, {}, D2); + // test:assertEquals(a2d2, [["1", "2"], ["1", "2"]]); + + // D dd = check fromCsvWithType(d, {}, D); + // test:assertEquals(dd, d); + + // D2 dd2 = check fromCsvWithType(d2, {}, D2); + // test:assertEquals(dd2, d2); + + // D bd = check fromCsvWithType(b, {}, D); + // test:assertEquals(bd, [[1, 2], [1, 2]]); + + // D2 bd2 = check fromCsvWithType(b2, {}, D2); + // test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); + + // D2 cd2 = check fromCsvWithType(c, {}, D2); + // test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); + + // A d2a = check fromCsvWithType(d2, {}, A); + // test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); + + // B2 d2b2 = check fromCsvWithType(d2, {}, B2); + // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); + + // C d2c = check fromCsvWithType(d2, {}, C); + // test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); + +type AA record{}[]; +type BB record {int a; int b; int c;}[]; +// type BBB record {string a; string b; string c;}[]; +type CC map[]; +type DD map[]; +type EE map[]; +type FF int[][]; +type GG string[][]; +type HH anydata[][]; +type II [int, int, int][]; +type JJ [string, string, string][]; +type KK [string, int, string][]; +type LL record {string a; int b; string c;}[]; +type MM record {|string a; int b; string c;|}[]; +type NN record {|int b; string c;|}[]; +type OO record {string a; string c;}[]; +type PP int[2][]; +type QQ string[2][]; +type RR anydata[2][]; +type SS [int, int][]; +type TT [string, string][]; +type UU [anydata, anydata][]; +type VV [int, string][]; +type WW int[][2]; +type XX string[][2]; +type YY anydata[][2]; + +@test:Config{} +function test() returns CsvConversionError? { + string a = check io:fileReadString("a.txt"); + + AA aa = check fromCsvStringWithType(a, {}, AA); + test:assertEquals(aa, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); + io:println(aa); + + BB bb = check fromCsvStringWithType(a, {}, BB); + test:assertEquals(bb, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); + io:println(bb); + + CC cc = check fromCsvStringWithType(a, {}, CC); + test:assertEquals(cc, [{a: "1", b: "2", c: "3"}, {a: "4", b: "5", c: "6"}]); + io:println(cc); + + DD dd = check fromCsvStringWithType(a, {}, DD); + test:assertEquals(dd, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); + io:println(dd); + + EE ee = check fromCsvStringWithType(a, {}, EE); + test:assertEquals(ee, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); + io:println(ee); + + FF ff = check fromCsvStringWithType(a, {}, FF); + test:assertEquals(ff, [[1, 2, 3], [4, 5, 6]]); + io:println(ff); + + GG gg = check fromCsvStringWithType(a, {}, GG); + test:assertEquals(gg, [["1", "2", "3"], ["4", "5", "6"]]); + io:println(gg); + + HH hh = check fromCsvStringWithType(a, {}, HH); + test:assertEquals(hh, [[1, 2, 3], [4, 5, 6]]); + io:println(hh); + + II ii = check fromCsvStringWithType(a, {}, II); + test:assertEquals(ii, [[1, 2, 3], [4, 5, 6]]); + io:println(ii); + + JJ jj = check fromCsvStringWithType(a, {}, JJ); + test:assertEquals(jj, [["1", "2", "3"], ["4", "5", "6"]]); + io:println(jj); + + KK kk = check fromCsvStringWithType(a, {}, KK); + test:assertEquals(kk, [["1", 2, "3"], ["4", 5, "6"]]); + io:println(kk); + + LL ll = check fromCsvStringWithType(a, {}, LL); + test:assertEquals(ll, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); + io:println(ll); + + MM mm = check fromCsvStringWithType(a, {}, MM); + test:assertEquals(mm, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); + io:println(mm); + + NN nn = check fromCsvStringWithType(a, {}, NN); + test:assertEquals(nn, [{b: 2, c: "3"}, {b: 5, c: "6"}]); + io:println(nn); + + OO oo = check fromCsvStringWithType(a, {}, OO); + test:assertEquals(oo, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); + io:println(oo); + + PP pp = check fromCsvStringWithType(a, {}, PP); + test:assertEquals(pp, [[1,2,3], [4,5,6]]); + io:println(pp); + + QQ qq = check fromCsvStringWithType(a, {}, QQ); + test:assertEquals(qq, [["1","2","3"],["4","5","6"]]); + io:println(qq); + + RR rr = check fromCsvStringWithType(a, {}, RR); + test:assertEquals(rr, [[1,2,3],[4,5,6]]); + io:println(rr); + + SS ss = check fromCsvStringWithType(a, {}, SS); + test:assertEquals(ss, [[1, 2],[4, 5]]); + io:println(ss); + + TT tt = check fromCsvStringWithType(a, {}, TT); + test:assertEquals(tt, [["1", "2"],["4", "5"]]); + io:println(tt); + + UU uu = check fromCsvStringWithType(a, {}, UU); + test:assertEquals(uu, [[1, 2],[4, 5]]); + io:println(uu); + + VV vv = check fromCsvStringWithType(a, {}, VV); + test:assertEquals(vv, [[1,"2"],[4,"5"]]); + io:println(vv); + + WW ww = check fromCsvStringWithType(a, {}, WW); + test:assertEquals(ww, [[1,2],[4,5]]); + io:println(ww); + + XX xx = check fromCsvStringWithType(a, {}, XX); + test:assertEquals(xx, [["1","2"],["4","5"]]); + io:println(xx); + + YY yy = check fromCsvStringWithType(a, {}, YY); + test:assertEquals(yy, [[1,2],[4,5]]); + io:println(yy); +} + +// =========================================================================================== + +// errors expected + +// EE ee2 = check fromCsvStringWithType(a, {}, EE); +// test:assertEquals(ee2, [{a: "1", b: "2", c: "3"}, {a: "4", b: "5", c: "6"}]); +// io:println(ee2); +// BBB bbb = check fromCsvStringWithType(a, {}, BBB); +// test:assertEquals(bbb, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); +// io:println(bbb); + +// =========================================================================================== + +// NEED TO check + +// OO oo = check fromCsvStringWithType(a, {}, MM); +// test:assertEquals(oo, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); +// io:println(oo); \ No newline at end of file diff --git a/build-config/checkstyle/build.gradle b/build-config/checkstyle/build.gradle new file mode 100644 index 0000000..6ec1c38 --- /dev/null +++ b/build-config/checkstyle/build.gradle @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +plugins { + id "de.undercouch.download" +} + +apply plugin: 'java' + +task downloadCheckstyleRuleFiles(type: Download) { + src([ + 'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/checkstyle.csv', + 'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/suppressions.csv' + ]) + overwrite false + onlyIfNewer true + dest buildDir +} + +jar { + enabled = false +} + +clean { + enabled = false +} + +artifacts.add('default', file("$project.buildDir/checkstyle.csv")) { + builtBy('downloadCheckstyleRuleFiles') +} + +artifacts.add('default', file("$project.buildDir/suppressions.csv")) { + builtBy('downloadCheckstyleRuleFiles') +} diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml new file mode 100644 index 0000000..70b960c --- /dev/null +++ b/build-config/resources/Ballerina.toml @@ -0,0 +1,19 @@ +[package] +org = "ballerina" +name = "data.csv" +version = "@toml.version@" +authors = ["Ballerina"] +keywords = ["csv"] +repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" +license = ["Apache-2.0"] +distribution = "2201.8.1" +export = ["data.csv"] + +[platform.java17] +graalvmCompatible = true + +[[platform.java17.dependency]] +groupId = "io.ballerina.stdlib" +artifactId = "data.csv-native" +version = "@toml.version@" +path = "../native/build/libs/data.csv-native-@project.version@.jar" diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..ac38747 --- /dev/null +++ b/build.gradle @@ -0,0 +1,92 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +plugins { + id "com.github.spotbugs" version "${githubSpotbugsVersion}" + id "com.github.johnrengelman.shadow" version "${githubJohnrengelmanShadowVersion}" + id "de.undercouch.download" version "${underCouchDownloadVersion}" + id "net.researchgate.release" version "${researchgateReleaseVersion}" +} + +allprojects { + group = project.group + version = project.version + + apply plugin: 'jacoco' + apply plugin: 'maven-publish' + + repositories { + mavenLocal() + maven { + url = 'https://maven.wso2.org/nexus/content/repositories/releases/' + } + + maven { + url = 'https://maven.wso2.org/nexus/content/groups/wso2-public/' + } + + maven { + url = 'https://repo.maven.apache.org/maven2' + } + + maven { + url = 'https://maven.pkg.github.com/ballerina-platform/ballerina-lang' + credentials { + username System.getenv("packageUser") + password System.getenv("packagePAT") + } + } + } + + ext { + snapshotVersion= '-SNAPSHOT' + timestampedVersionRegex = '.*-\\d{8}-\\d{6}-\\w.*\$' + } +} + +subprojects { + + configurations { + ballerinaStdLibs + } + + dependencies { + /* Standard libraries */ + ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${stdlibIoVersion}" + } +} + +def moduleVersion = project.version.replace("-SNAPSHOT", "") + +release { + failOnPublishNeeded = false + + buildTasks = ["build"] + failOnSnapshotDependencies = true + versionPropertyFile = 'gradle.properties' + tagTemplate = 'v$version' + + git { + requireBranch = "release-${moduleVersion}" + pushToRemote = 'origin' + } +} + +task build { + dependsOn('data.csv-ballerina:build') +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..538c62a --- /dev/null +++ b/gradle.properties @@ -0,0 +1,15 @@ +org.gradle.caching=true +group=io.ballerina.stdlib +version=0.1.0-SNAPSHOT +ballerinaLangVersion=2201.8.1 + +checkstyleToolVersion=10.12.0 +puppycrawlCheckstyleVersion=10.12.0 +testngVersion=7.6.1 +slf4jVersion=2.0.7 +githubSpotbugsVersion=5.0.14 +githubJohnrengelmanShadowVersion=8.1.1 +underCouchDownloadVersion=4.0.4 +researchgateReleaseVersion=2.8.0 +ballerinaGradlePluginVersion=2.0.1 +stdlibIoVersion=1.6.0 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..7454180f2ae8848c63b8b4dea2cb829da983f2fa GIT binary patch literal 59536 zcma&NbC71ylI~qywr$(CZQJHswz}-9F59+k+g;UV+cs{`J?GrGXYR~=-ydruB3JCa zB64N^cILAcWk5iofq)<(fq;O7{th4@;QxID0)qN`mJ?GIqLY#rX8-|G{5M0pdVW5^ zzXk$-2kQTAC?_N@B`&6-N-rmVFE=$QD?>*=4<|!MJu@}isLc4AW#{m2if&A5T5g&~ ziuMQeS*U5sL6J698wOd)K@oK@1{peP5&Esut<#VH^u)gp`9H4)`uE!2$>RTctN+^u z=ASkePDZA-X8)rp%D;p*~P?*a_=*Kwc<^>QSH|^<0>o37lt^+Mj1;4YvJ(JR-Y+?%Nu}JAYj5 z_Qc5%Ao#F?q32i?ZaN2OSNhWL;2oDEw_({7ZbgUjna!Fqn3NzLM@-EWFPZVmc>(fZ z0&bF-Ch#p9C{YJT9Rcr3+Y_uR^At1^BxZ#eo>$PLJF3=;t_$2|t+_6gg5(j{TmjYU zK12c&lE?Eh+2u2&6Gf*IdKS&6?rYbSEKBN!rv{YCm|Rt=UlPcW9j`0o6{66#y5t9C zruFA2iKd=H%jHf%ypOkxLnO8#H}#Zt{8p!oi6)7#NqoF({t6|J^?1e*oxqng9Q2Cc zg%5Vu!em)}Yuj?kaP!D?b?(C*w!1;>R=j90+RTkyEXz+9CufZ$C^umX^+4|JYaO<5 zmIM3#dv`DGM;@F6;(t!WngZSYzHx?9&$xEF70D1BvfVj<%+b#)vz)2iLCrTeYzUcL z(OBnNoG6Le%M+@2oo)&jdOg=iCszzv59e zDRCeaX8l1hC=8LbBt|k5?CXgep=3r9BXx1uR8!p%Z|0+4Xro=xi0G!e{c4U~1j6!) zH6adq0}#l{%*1U(Cb%4AJ}VLWKBPi0MoKFaQH6x?^hQ!6em@993xdtS%_dmevzeNl z(o?YlOI=jl(`L9^ z0O+H9k$_@`6L13eTT8ci-V0ljDMD|0ifUw|Q-Hep$xYj0hTO@0%IS^TD4b4n6EKDG z??uM;MEx`s98KYN(K0>c!C3HZdZ{+_53DO%9k5W%pr6yJusQAv_;IA}925Y%;+!tY z%2k!YQmLLOr{rF~!s<3-WEUs)`ix_mSU|cNRBIWxOox_Yb7Z=~Q45ZNe*u|m^|)d* zog=i>`=bTe!|;8F+#H>EjIMcgWcG2ORD`w0WD;YZAy5#s{65~qfI6o$+Ty&-hyMyJ z3Ra~t>R!p=5ZpxA;QkDAoPi4sYOP6>LT+}{xp}tk+<0k^CKCFdNYG(Es>p0gqD)jP zWOeX5G;9(m@?GOG7g;e74i_|SmE?`B2i;sLYwRWKLy0RLW!Hx`=!LH3&k=FuCsM=9M4|GqzA)anEHfxkB z?2iK-u(DC_T1};KaUT@3nP~LEcENT^UgPvp!QC@Dw&PVAhaEYrPey{nkcn(ro|r7XUz z%#(=$7D8uP_uU-oPHhd>>^adbCSQetgSG`e$U|7mr!`|bU0aHl_cmL)na-5x1#OsVE#m*+k84Y^+UMeSAa zbrVZHU=mFwXEaGHtXQq`2ZtjfS!B2H{5A<3(nb-6ARVV8kEmOkx6D2x7~-6hl;*-*}2Xz;J#a8Wn;_B5=m zl3dY;%krf?i-Ok^Pal-}4F`{F@TYPTwTEhxpZK5WCpfD^UmM_iYPe}wpE!Djai6_{ z*pGO=WB47#Xjb7!n2Ma)s^yeR*1rTxp`Mt4sfA+`HwZf%!7ZqGosPkw69`Ix5Ku6G z@Pa;pjzV&dn{M=QDx89t?p?d9gna*}jBly*#1!6}5K<*xDPJ{wv4& zM$17DFd~L*Te3A%yD;Dp9UGWTjRxAvMu!j^Tbc}2v~q^59d4bz zvu#!IJCy(BcWTc`;v$9tH;J%oiSJ_i7s;2`JXZF+qd4C)vY!hyCtl)sJIC{ebI*0> z@x>;EzyBv>AI-~{D6l6{ST=em*U( z(r$nuXY-#CCi^8Z2#v#UXOt`dbYN1z5jzNF2 z411?w)whZrfA20;nl&C1Gi+gk<`JSm+{|*2o<< zqM#@z_D`Cn|0H^9$|Tah)0M_X4c37|KQ*PmoT@%xHc3L1ZY6(p(sNXHa&49Frzto& zR`c~ClHpE~4Z=uKa5S(-?M8EJ$zt0&fJk~p$M#fGN1-y$7!37hld`Uw>Urri(DxLa;=#rK0g4J)pXMC zxzraOVw1+kNWpi#P=6(qxf`zSdUC?D$i`8ZI@F>k6k zz21?d+dw7b&i*>Kv5L(LH-?J%@WnqT7j#qZ9B>|Zl+=> z^U-pV@1y_ptHo4hl^cPRWewbLQ#g6XYQ@EkiP z;(=SU!yhjHp%1&MsU`FV1Z_#K1&(|5n(7IHbx&gG28HNT)*~-BQi372@|->2Aw5It z0CBpUcMA*QvsPy)#lr!lIdCi@1k4V2m!NH)%Px(vu-r(Q)HYc!p zJ^$|)j^E#q#QOgcb^pd74^JUi7fUmMiNP_o*lvx*q%_odv49Dsv$NV;6J z9GOXKomA{2Pb{w}&+yHtH?IkJJu~}Z?{Uk++2mB8zyvh*xhHKE``99>y#TdD z&(MH^^JHf;g(Tbb^&8P*;_i*2&fS$7${3WJtV7K&&(MBV2~)2KB3%cWg#1!VE~k#C z!;A;?p$s{ihyojEZz+$I1)L}&G~ml=udD9qh>Tu(ylv)?YcJT3ihapi!zgPtWb*CP zlLLJSRCj-^w?@;RU9aL2zDZY1`I3d<&OMuW=c3$o0#STpv_p3b9Wtbql>w^bBi~u4 z3D8KyF?YE?=HcKk!xcp@Cigvzy=lnFgc^9c%(^F22BWYNAYRSho@~*~S)4%AhEttv zvq>7X!!EWKG?mOd9&n>vvH1p4VzE?HCuxT-u+F&mnsfDI^}*-d00-KAauEaXqg3k@ zy#)MGX!X;&3&0s}F3q40ZmVM$(H3CLfpdL?hB6nVqMxX)q=1b}o_PG%r~hZ4gUfSp zOH4qlEOW4OMUc)_m)fMR_rl^pCfXc{$fQbI*E&mV77}kRF z&{<06AJyJ!e863o-V>FA1a9Eemx6>^F$~9ppt()ZbPGfg_NdRXBWoZnDy2;#ODgf! zgl?iOcF7Meo|{AF>KDwTgYrJLb$L2%%BEtO>T$C?|9bAB&}s;gI?lY#^tttY&hfr# zKhC+&b-rpg_?~uVK%S@mQleU#_xCsvIPK*<`E0fHE1&!J7!xD#IB|SSPW6-PyuqGn3^M^Rz%WT{e?OI^svARX&SAdU77V(C~ zM$H{Kg59op{<|8ry9ecfP%=kFm(-!W&?U0@<%z*+!*<e0XesMxRFu9QnGqun6R_%T+B%&9Dtk?*d$Q zb~>84jEAPi@&F@3wAa^Lzc(AJz5gsfZ7J53;@D<;Klpl?sK&u@gie`~vTsbOE~Cd4 z%kr56mI|#b(Jk&;p6plVwmNB0H@0SmgdmjIn5Ne@)}7Vty(yb2t3ev@22AE^s!KaN zyQ>j+F3w=wnx7w@FVCRe+`vUH)3gW%_72fxzqX!S&!dchdkRiHbXW1FMrIIBwjsai8`CB2r4mAbwp%rrO>3B$Zw;9=%fXI9B{d(UzVap7u z6piC-FQ)>}VOEuPpuqznpY`hN4dGa_1Xz9rVg(;H$5Te^F0dDv*gz9JS<|>>U0J^# z6)(4ICh+N_Q`Ft0hF|3fSHs*?a=XC;e`sJaU9&d>X4l?1W=|fr!5ShD|nv$GK;j46@BV6+{oRbWfqOBRb!ir88XD*SbC(LF}I1h#6@dvK%Toe%@ zhDyG$93H8Eu&gCYddP58iF3oQH*zLbNI;rN@E{T9%A8!=v#JLxKyUe}e}BJpB{~uN zqgxRgo0*-@-iaHPV8bTOH(rS(huwK1Xg0u+e!`(Irzu@Bld&s5&bWgVc@m7;JgELd zimVs`>vQ}B_1(2#rv#N9O`fJpVfPc7V2nv34PC);Dzbb;p!6pqHzvy?2pD&1NE)?A zt(t-ucqy@wn9`^MN5apa7K|L=9>ISC>xoc#>{@e}m#YAAa1*8-RUMKwbm|;5p>T`Z zNf*ph@tnF{gmDa3uwwN(g=`Rh)4!&)^oOy@VJaK4lMT&5#YbXkl`q?<*XtsqD z9PRK6bqb)fJw0g-^a@nu`^?71k|m3RPRjt;pIkCo1{*pdqbVs-Yl>4E>3fZx3Sv44grW=*qdSoiZ9?X0wWyO4`yDHh2E!9I!ZFi zVL8|VtW38}BOJHW(Ax#KL_KQzarbuE{(%TA)AY)@tY4%A%P%SqIU~8~-Lp3qY;U-} z`h_Gel7;K1h}7$_5ZZT0&%$Lxxr-<89V&&TCsu}LL#!xpQ1O31jaa{U34~^le*Y%L za?7$>Jk^k^pS^_M&cDs}NgXlR>16AHkSK-4TRaJSh#h&p!-!vQY%f+bmn6x`4fwTp z$727L^y`~!exvmE^W&#@uY!NxJi`g!i#(++!)?iJ(1)2Wk;RN zFK&O4eTkP$Xn~4bB|q8y(btx$R#D`O@epi4ofcETrx!IM(kWNEe42Qh(8*KqfP(c0 zouBl6>Fc_zM+V;F3znbo{x#%!?mH3`_ANJ?y7ppxS@glg#S9^MXu|FM&ynpz3o&Qh z2ujAHLF3($pH}0jXQsa#?t--TnF1P73b?4`KeJ9^qK-USHE)4!IYgMn-7z|=ALF5SNGkrtPG@Y~niUQV2?g$vzJN3nZ{7;HZHzWAeQ;5P|@Tl3YHpyznGG4-f4=XflwSJY+58-+wf?~Fg@1p1wkzuu-RF3j2JX37SQUc? zQ4v%`V8z9ZVZVqS8h|@@RpD?n0W<=hk=3Cf8R?d^9YK&e9ZybFY%jdnA)PeHvtBe- zhMLD+SSteHBq*q)d6x{)s1UrsO!byyLS$58WK;sqip$Mk{l)Y(_6hEIBsIjCr5t>( z7CdKUrJTrW%qZ#1z^n*Lb8#VdfzPw~OIL76aC+Rhr<~;4Tl!sw?Rj6hXj4XWa#6Tp z@)kJ~qOV)^Rh*-?aG>ic2*NlC2M7&LUzc9RT6WM%Cpe78`iAowe!>(T0jo&ivn8-7 zs{Qa@cGy$rE-3AY0V(l8wjI^uB8Lchj@?L}fYal^>T9z;8juH@?rG&g-t+R2dVDBe zq!K%{e-rT5jX19`(bP23LUN4+_zh2KD~EAYzhpEO3MUG8@}uBHH@4J zd`>_(K4q&>*k82(dDuC)X6JuPrBBubOg7qZ{?x!r@{%0);*`h*^F|%o?&1wX?Wr4b z1~&cy#PUuES{C#xJ84!z<1tp9sfrR(i%Tu^jnXy;4`Xk;AQCdFC@?V%|; zySdC7qS|uQRcH}EFZH%mMB~7gi}a0utE}ZE_}8PQH8f;H%PN41Cb9R%w5Oi5el^fd z$n{3SqLCnrF##x?4sa^r!O$7NX!}&}V;0ZGQ&K&i%6$3C_dR%I7%gdQ;KT6YZiQrW zk%q<74oVBV>@}CvJ4Wj!d^?#Zwq(b$E1ze4$99DuNg?6t9H}k_|D7KWD7i0-g*EO7 z;5{hSIYE4DMOK3H%|f5Edx+S0VI0Yw!tsaRS2&Il2)ea^8R5TG72BrJue|f_{2UHa z@w;^c|K3da#$TB0P3;MPlF7RuQeXT$ zS<<|C0OF(k)>fr&wOB=gP8!Qm>F41u;3esv7_0l%QHt(~+n; zf!G6%hp;Gfa9L9=AceiZs~tK+Tf*Wof=4!u{nIO90jH@iS0l+#%8=~%ASzFv7zqSB^?!@N7)kp0t&tCGLmzXSRMRyxCmCYUD2!B`? zhs$4%KO~m=VFk3Buv9osha{v+mAEq=ik3RdK@;WWTV_g&-$U4IM{1IhGX{pAu%Z&H zFfwCpUsX%RKg);B@7OUzZ{Hn{q6Vv!3#8fAg!P$IEx<0vAx;GU%}0{VIsmFBPq_mb zpe^BChDK>sc-WLKl<6 zwbW|e&d&dv9Wu0goueyu>(JyPx1mz0v4E?cJjFuKF71Q1)AL8jHO$!fYT3(;U3Re* zPPOe%*O+@JYt1bW`!W_1!mN&=w3G9ru1XsmwfS~BJ))PhD(+_J_^N6j)sx5VwbWK| zwRyC?W<`pOCY)b#AS?rluxuuGf-AJ=D!M36l{ua?@SJ5>e!IBr3CXIxWw5xUZ@Xrw z_R@%?{>d%Ld4p}nEsiA@v*nc6Ah!MUs?GA7e5Q5lPpp0@`%5xY$C;{%rz24$;vR#* zBP=a{)K#CwIY%p} zXVdxTQ^HS@O&~eIftU+Qt^~(DGxrdi3k}DdT^I7Iy5SMOp$QuD8s;+93YQ!OY{eB24%xY7ml@|M7I(Nb@K_-?F;2?et|CKkuZK_>+>Lvg!>JE~wN`BI|_h6$qi!P)+K-1Hh(1;a`os z55)4Q{oJiA(lQM#;w#Ta%T0jDNXIPM_bgESMCDEg6rM33anEr}=|Fn6)|jBP6Y}u{ zv9@%7*#RI9;fv;Yii5CI+KrRdr0DKh=L>)eO4q$1zmcSmglsV`*N(x=&Wx`*v!!hn6X-l0 zP_m;X??O(skcj+oS$cIdKhfT%ABAzz3w^la-Ucw?yBPEC+=Pe_vU8nd-HV5YX6X8r zZih&j^eLU=%*;VzhUyoLF;#8QsEfmByk+Y~caBqSvQaaWf2a{JKB9B>V&r?l^rXaC z8)6AdR@Qy_BxQrE2Fk?ewD!SwLuMj@&d_n5RZFf7=>O>hzVE*seW3U?_p|R^CfoY`?|#x9)-*yjv#lo&zP=uI`M?J zbzC<^3x7GfXA4{FZ72{PE*-mNHyy59Q;kYG@BB~NhTd6pm2Oj=_ zizmD?MKVRkT^KmXuhsk?eRQllPo2Ubk=uCKiZ&u3Xjj~<(!M94c)Tez@9M1Gfs5JV z->@II)CDJOXTtPrQudNjE}Eltbjq>6KiwAwqvAKd^|g!exgLG3;wP+#mZYr`cy3#39e653d=jrR-ulW|h#ddHu(m9mFoW~2yE zz5?dB%6vF}+`-&-W8vy^OCxm3_{02royjvmwjlp+eQDzFVEUiyO#gLv%QdDSI#3W* z?3!lL8clTaNo-DVJw@ynq?q!%6hTQi35&^>P85G$TqNt78%9_sSJt2RThO|JzM$iL zg|wjxdMC2|Icc5rX*qPL(coL!u>-xxz-rFiC!6hD1IR%|HSRsV3>Kq~&vJ=s3M5y8SG%YBQ|{^l#LGlg!D?E>2yR*eV%9m$_J6VGQ~AIh&P$_aFbh zULr0Z$QE!QpkP=aAeR4ny<#3Fwyw@rZf4?Ewq`;mCVv}xaz+3ni+}a=k~P+yaWt^L z@w67!DqVf7D%7XtXX5xBW;Co|HvQ8WR1k?r2cZD%U;2$bsM%u8{JUJ5Z0k= zZJARv^vFkmWx15CB=rb=D4${+#DVqy5$C%bf`!T0+epLJLnh1jwCdb*zuCL}eEFvE z{rO1%gxg>1!W(I!owu*mJZ0@6FM(?C+d*CeceZRW_4id*D9p5nzMY&{mWqrJomjIZ z97ZNnZ3_%Hx8dn;H>p8m7F#^2;T%yZ3H;a&N7tm=Lvs&lgJLW{V1@h&6Vy~!+Ffbb zv(n3+v)_D$}dqd!2>Y2B)#<+o}LH#%ogGi2-?xRIH)1!SD)u-L65B&bsJTC=LiaF+YOCif2dUX6uAA|#+vNR z>U+KQekVGon)Yi<93(d!(yw1h3&X0N(PxN2{%vn}cnV?rYw z$N^}_o!XUB!mckL`yO1rnUaI4wrOeQ(+&k?2mi47hzxSD`N#-byqd1IhEoh!PGq>t z_MRy{5B0eKY>;Ao3z$RUU7U+i?iX^&r739F)itdrTpAi-NN0=?^m%?{A9Ly2pVv>Lqs6moTP?T2-AHqFD-o_ znVr|7OAS#AEH}h8SRPQ@NGG47dO}l=t07__+iK8nHw^(AHx&Wb<%jPc$$jl6_p(b$ z)!pi(0fQodCHfM)KMEMUR&UID>}m^(!{C^U7sBDOA)$VThRCI0_+2=( zV8mMq0R(#z;C|7$m>$>`tX+T|xGt(+Y48@ZYu#z;0pCgYgmMVbFb!$?%yhZqP_nhn zy4<#3P1oQ#2b51NU1mGnHP$cf0j-YOgAA}A$QoL6JVLcmExs(kU{4z;PBHJD%_=0F z>+sQV`mzijSIT7xn%PiDKHOujX;n|M&qr1T@rOxTdxtZ!&u&3HHFLYD5$RLQ=heur zb>+AFokUVQeJy-#LP*^)spt{mb@Mqe=A~-4p0b+Bt|pZ+@CY+%x}9f}izU5;4&QFE zO1bhg&A4uC1)Zb67kuowWY4xbo&J=%yoXlFB)&$d*-}kjBu|w!^zbD1YPc0-#XTJr z)pm2RDy%J3jlqSMq|o%xGS$bPwn4AqitC6&e?pqWcjWPt{3I{>CBy;hg0Umh#c;hU3RhCUX=8aR>rmd` z7Orw(5tcM{|-^J?ZAA9KP|)X6n9$-kvr#j5YDecTM6n z&07(nD^qb8hpF0B^z^pQ*%5ePYkv&FabrlI61ntiVp!!C8y^}|<2xgAd#FY=8b*y( zuQOuvy2`Ii^`VBNJB&R!0{hABYX55ooCAJSSevl4RPqEGb)iy_0H}v@vFwFzD%>#I>)3PsouQ+_Kkbqy*kKdHdfkN7NBcq%V{x^fSxgXpg7$bF& zj!6AQbDY(1u#1_A#1UO9AxiZaCVN2F0wGXdY*g@x$ByvUA?ePdide0dmr#}udE%K| z3*k}Vv2Ew2u1FXBaVA6aerI36R&rzEZeDDCl5!t0J=ug6kuNZzH>3i_VN`%BsaVB3 zQYw|Xub_SGf{)F{$ZX5`Jc!X!;eybjP+o$I{Z^Hsj@D=E{MnnL+TbC@HEU2DjG{3-LDGIbq()U87x4eS;JXnSh;lRlJ z>EL3D>wHt-+wTjQF$fGyDO$>d+(fq@bPpLBS~xA~R=3JPbS{tzN(u~m#Po!?H;IYv zE;?8%^vle|%#oux(Lj!YzBKv+Fd}*Ur-dCBoX*t{KeNM*n~ZPYJ4NNKkI^MFbz9!v z4(Bvm*Kc!-$%VFEewYJKz-CQN{`2}KX4*CeJEs+Q(!kI%hN1!1P6iOq?ovz}X0IOi z)YfWpwW@pK08^69#wSyCZkX9?uZD?C^@rw^Y?gLS_xmFKkooyx$*^5#cPqntNTtSG zlP>XLMj2!VF^0k#ole7`-c~*~+_T5ls?x4)ah(j8vo_ zwb%S8qoaZqY0-$ZI+ViIA_1~~rAH7K_+yFS{0rT@eQtTAdz#8E5VpwnW!zJ_^{Utv zlW5Iar3V5t&H4D6A=>?mq;G92;1cg9a2sf;gY9pJDVKn$DYdQlvfXq}zz8#LyPGq@ z+`YUMD;^-6w&r-82JL7mA8&M~Pj@aK!m{0+^v<|t%APYf7`}jGEhdYLqsHW-Le9TL z_hZZ1gbrz7$f9^fAzVIP30^KIz!!#+DRLL+qMszvI_BpOSmjtl$hh;&UeM{ER@INV zcI}VbiVTPoN|iSna@=7XkP&-4#06C};8ajbxJ4Gcq8(vWv4*&X8bM^T$mBk75Q92j z1v&%a;OSKc8EIrodmIiw$lOES2hzGDcjjB`kEDfJe{r}yE6`eZL zEB`9u>Cl0IsQ+t}`-cx}{6jqcANucqIB>Qmga_&<+80E2Q|VHHQ$YlAt{6`Qu`HA3 z03s0-sSlwbvgi&_R8s={6<~M^pGvBNjKOa>tWenzS8s zR>L7R5aZ=mSU{f?ib4Grx$AeFvtO5N|D>9#)ChH#Fny2maHWHOf2G=#<9Myot#+4u zWVa6d^Vseq_0=#AYS(-m$Lp;*8nC_6jXIjEM`omUmtH@QDs3|G)i4j*#_?#UYVZvJ z?YjT-?!4Q{BNun;dKBWLEw2C-VeAz`%?A>p;)PL}TAZn5j~HK>v1W&anteARlE+~+ zj>c(F;?qO3pXBb|#OZdQnm<4xWmn~;DR5SDMxt0UK_F^&eD|KZ=O;tO3vy4@4h^;2 zUL~-z`-P1aOe?|ZC1BgVsL)2^J-&vIFI%q@40w0{jjEfeVl)i9(~bt2z#2Vm)p`V_ z1;6$Ae7=YXk#=Qkd24Y23t&GvRxaOoad~NbJ+6pxqzJ>FY#Td7@`N5xp!n(c!=RE& z&<<@^a$_Ys8jqz4|5Nk#FY$~|FPC0`*a5HH!|Gssa9=~66&xG9)|=pOOJ2KE5|YrR zw!w6K2aC=J$t?L-;}5hn6mHd%hC;p8P|Dgh6D>hGnXPgi;6r+eA=?f72y9(Cf_ho{ zH6#)uD&R=73^$$NE;5piWX2bzR67fQ)`b=85o0eOLGI4c-Tb@-KNi2pz=Ke@SDcPn za$AxXib84`!Sf;Z3B@TSo`Dz7GM5Kf(@PR>Ghzi=BBxK8wRp>YQoXm+iL>H*Jo9M3 z6w&E?BC8AFTFT&Tv8zf+m9<&S&%dIaZ)Aoqkak_$r-2{$d~0g2oLETx9Y`eOAf14QXEQw3tJne;fdzl@wV#TFXSLXM2428F-Q}t+n2g%vPRMUzYPvzQ9f# zu(liiJem9P*?0%V@RwA7F53r~|I!Ty)<*AsMX3J{_4&}{6pT%Tpw>)^|DJ)>gpS~1rNEh z0$D?uO8mG?H;2BwM5a*26^7YO$XjUm40XmBsb63MoR;bJh63J;OngS5sSI+o2HA;W zdZV#8pDpC9Oez&L8loZO)MClRz!_!WD&QRtQxnazhT%Vj6Wl4G11nUk8*vSeVab@N#oJ}`KyJv+8Mo@T1-pqZ1t|?cnaVOd;1(h9 z!$DrN=jcGsVYE-0-n?oCJ^4x)F}E;UaD-LZUIzcD?W^ficqJWM%QLy6QikrM1aKZC zi{?;oKwq^Vsr|&`i{jIphA8S6G4)$KGvpULjH%9u(Dq247;R#l&I0{IhcC|oBF*Al zvLo7Xte=C{aIt*otJD}BUq)|_pdR>{zBMT< z(^1RpZv*l*m*OV^8>9&asGBo8h*_4q*)-eCv*|Pq=XNGrZE)^(SF7^{QE_~4VDB(o zVcPA_!G+2CAtLbl+`=Q~9iW`4ZRLku!uB?;tWqVjB0lEOf}2RD7dJ=BExy=<9wkb- z9&7{XFA%n#JsHYN8t5d~=T~5DcW4$B%3M+nNvC2`0!#@sckqlzo5;hhGi(D9=*A4` z5ynobawSPRtWn&CDLEs3Xf`(8^zDP=NdF~F^s&={l7(aw&EG}KWpMjtmz7j_VLO;@ zM2NVLDxZ@GIv7*gzl1 zjq78tv*8#WSY`}Su0&C;2F$Ze(q>F(@Wm^Gw!)(j;dk9Ad{STaxn)IV9FZhm*n+U} zi;4y*3v%A`_c7a__DJ8D1b@dl0Std3F||4Wtvi)fCcBRh!X9$1x!_VzUh>*S5s!oq z;qd{J_r79EL2wIeiGAqFstWtkfIJpjVh%zFo*=55B9Zq~y0=^iqHWfQl@O!Ak;(o*m!pZqe9 z%U2oDOhR)BvW8&F70L;2TpkzIutIvNQaTjjs5V#8mV4!NQ}zN=i`i@WI1z0eN-iCS z;vL-Wxc^Vc_qK<5RPh(}*8dLT{~GzE{w2o$2kMFaEl&q zP{V=>&3kW7tWaK-Exy{~`v4J0U#OZBk{a9{&)&QG18L@6=bsZ1zC_d{{pKZ-Ey>I> z;8H0t4bwyQqgu4hmO`3|4K{R*5>qnQ&gOfdy?z`XD%e5+pTDzUt3`k^u~SaL&XMe= z9*h#kT(*Q9jO#w2Hd|Mr-%DV8i_1{J1MU~XJ3!WUplhXDYBpJH><0OU`**nIvPIof z|N8@I=wA)sf45SAvx||f?Z5uB$kz1qL3Ky_{%RPdP5iN-D2!p5scq}buuC00C@jom zhfGKm3|f?Z0iQ|K$Z~!`8{nmAS1r+fp6r#YDOS8V*;K&Gs7Lc&f^$RC66O|)28oh`NHy&vq zJh+hAw8+ybTB0@VhWN^0iiTnLsCWbS_y`^gs!LX!Lw{yE``!UVzrV24tP8o;I6-65 z1MUiHw^{bB15tmrVT*7-#sj6cs~z`wk52YQJ*TG{SE;KTm#Hf#a~|<(|ImHH17nNM z`Ub{+J3dMD!)mzC8b(2tZtokKW5pAwHa?NFiso~# z1*iaNh4lQ4TS)|@G)H4dZV@l*Vd;Rw;-;odDhW2&lJ%m@jz+Panv7LQm~2Js6rOW3 z0_&2cW^b^MYW3)@o;neZ<{B4c#m48dAl$GCc=$>ErDe|?y@z`$uq3xd(%aAsX)D%l z>y*SQ%My`yDP*zof|3@_w#cjaW_YW4BdA;#Glg1RQcJGY*CJ9`H{@|D+*e~*457kd z73p<%fB^PV!Ybw@)Dr%(ZJbX}xmCStCYv#K3O32ej{$9IzM^I{6FJ8!(=azt7RWf4 z7ib0UOPqN40X!wOnFOoddd8`!_IN~9O)#HRTyjfc#&MCZ zZAMzOVB=;qwt8gV?{Y2?b=iSZG~RF~uyx18K)IDFLl})G1v@$(s{O4@RJ%OTJyF+Cpcx4jmy|F3euCnMK!P2WTDu5j z{{gD$=M*pH!GGzL%P)V2*ROm>!$Y=z|D`!_yY6e7SU$~a5q8?hZGgaYqaiLnkK%?0 zs#oI%;zOxF@g*@(V4p!$7dS1rOr6GVs6uYCTt2h)eB4?(&w8{#o)s#%gN@BBosRUe z)@P@8_Zm89pr~)b>e{tbPC~&_MR--iB{=)y;INU5#)@Gix-YpgP<-c2Ms{9zuCX|3 z!p(?VaXww&(w&uBHzoT%!A2=3HAP>SDxcljrego7rY|%hxy3XlODWffO_%g|l+7Y_ zqV(xbu)s4lV=l7M;f>vJl{`6qBm>#ZeMA}kXb97Z)?R97EkoI?x6Lp0yu1Z>PS?2{ z0QQ(8D)|lc9CO3B~e(pQM&5(1y&y=e>C^X$`)_&XuaI!IgDTVqt31wX#n+@!a_A0ZQkA zCJ2@M_4Gb5MfCrm5UPggeyh)8 zO9?`B0J#rkoCx(R0I!ko_2?iO@|oRf1;3r+i)w-2&j?=;NVIdPFsB)`|IC0zk6r9c zRrkfxWsiJ(#8QndNJj@{@WP2Ackr|r1VxV{7S&rSU(^)-M8gV>@UzOLXu9K<{6e{T zXJ6b92r$!|lwjhmgqkdswY&}c)KW4A)-ac%sU;2^fvq7gfUW4Bw$b!i@duy1CAxSn z(pyh$^Z=&O-q<{bZUP+$U}=*#M9uVc>CQVgDs4swy5&8RAHZ~$)hrTF4W zPsSa~qYv_0mJnF89RnnJTH`3}w4?~epFl=D(35$ zWa07ON$`OMBOHgCmfO(9RFc<)?$x)N}Jd2A(<*Ll7+4jrRt9w zwGxExUXd9VB#I|DwfxvJ;HZ8Q{37^wDhaZ%O!oO(HpcqfLH%#a#!~;Jl7F5>EX_=8 z{()l2NqPz>La3qJR;_v+wlK>GsHl;uRA8%j`A|yH@k5r%55S9{*Cp%uw6t`qc1!*T za2OeqtQj7sAp#Q~=5Fs&aCR9v>5V+s&RdNvo&H~6FJOjvaj--2sYYBvMq;55%z8^o z|BJDA4vzfow#DO#ZQHh;Oq_{r+qP{R9ox2TOgwQiv7Ow!zjN+A@BN;0tA2lUb#+zO z(^b89eV)D7UVE+h{mcNc6&GtpOqDn_?VAQ)Vob$hlFwW%xh>D#wml{t&Ofmm_d_+; zKDxzdr}`n2Rw`DtyIjrG)eD0vut$}dJAZ0AohZ+ZQdWXn_Z@dI_y=7t3q8x#pDI-K z2VVc&EGq445Rq-j0=U=Zx`oBaBjsefY;%)Co>J3v4l8V(T8H?49_@;K6q#r~Wwppc z4XW0(4k}cP=5ex>-Xt3oATZ~bBWKv)aw|I|Lx=9C1s~&b77idz({&q3T(Y(KbWO?+ zmcZ6?WeUsGk6>km*~234YC+2e6Zxdl~<_g2J|IE`GH%n<%PRv-50; zH{tnVts*S5*_RxFT9eM0z-pksIb^drUq4>QSww=u;UFCv2AhOuXE*V4z?MM`|ABOC4P;OfhS(M{1|c%QZ=!%rQTDFx`+}?Kdx$&FU?Y<$x;j7z=(;Lyz+?EE>ov!8vvMtSzG!nMie zsBa9t8as#2nH}n8xzN%W%U$#MHNXmDUVr@GX{?(=yI=4vks|V)!-W5jHsU|h_&+kY zS_8^kd3jlYqOoiI`ZqBVY!(UfnAGny!FowZWY_@YR0z!nG7m{{)4OS$q&YDyw6vC$ zm4!$h>*|!2LbMbxS+VM6&DIrL*X4DeMO!@#EzMVfr)e4Tagn~AQHIU8?e61TuhcKD zr!F4(kEebk(Wdk-?4oXM(rJwanS>Jc%<>R(siF+>+5*CqJLecP_we33iTFTXr6W^G z7M?LPC-qFHK;E!fxCP)`8rkxZyFk{EV;G-|kwf4b$c1k0atD?85+|4V%YATWMG|?K zLyLrws36p%Qz6{}>7b>)$pe>mR+=IWuGrX{3ZPZXF3plvuv5Huax86}KX*lbPVr}L z{C#lDjdDeHr~?l|)Vp_}T|%$qF&q#U;ClHEPVuS+Jg~NjC1RP=17=aQKGOcJ6B3mp z8?4*-fAD~}sX*=E6!}^u8)+m2j<&FSW%pYr_d|p_{28DZ#Cz0@NF=gC-o$MY?8Ca8 zr5Y8DSR^*urS~rhpX^05r30Ik#2>*dIOGxRm0#0YX@YQ%Mg5b6dXlS!4{7O_kdaW8PFSdj1=ryI-=5$fiieGK{LZ+SX(1b=MNL!q#lN zv98?fqqTUH8r8C7v(cx#BQ5P9W>- zmW93;eH6T`vuJ~rqtIBg%A6>q>gnWb3X!r0wh_q;211+Om&?nvYzL1hhtjB zK_7G3!n7PL>d!kj){HQE zE8(%J%dWLh1_k%gVXTZt zEdT09XSKAx27Ncaq|(vzL3gm83q>6CAw<$fTnMU05*xAe&rDfCiu`u^1)CD<>sx0i z*hr^N_TeN89G(nunZoLBf^81#pmM}>JgD@Nn1l*lN#a=B=9pN%tmvYFjFIoKe_(GF z-26x{(KXdfsQL7Uv6UtDuYwV`;8V3w>oT_I<`Ccz3QqK9tYT5ZQzbop{=I=!pMOCb zCU68`n?^DT%^&m>A%+-~#lvF!7`L7a{z<3JqIlk1$<||_J}vW1U9Y&eX<}l8##6i( zZcTT@2`9(Mecptm@{3A_Y(X`w9K0EwtPq~O!16bq{7c0f7#(3wn-^)h zxV&M~iiF!{-6A@>o;$RzQ5A50kxXYj!tcgme=Qjrbje~;5X2xryU;vH|6bE(8z^<7 zQ>BG7_c*JG8~K7Oe68i#0~C$v?-t@~@r3t2inUnLT(c=URpA9kA8uq9PKU(Ps(LVH zqgcqW>Gm?6oV#AldDPKVRcEyQIdTT`Qa1j~vS{<;SwyTdr&3*t?J)y=M7q*CzucZ&B0M=joT zBbj@*SY;o2^_h*>R0e({!QHF0=)0hOj^B^d*m>SnRrwq>MolNSgl^~r8GR#mDWGYEIJA8B<|{{j?-7p zVnV$zancW3&JVDtVpIlI|5djKq0(w$KxEFzEiiL=h5Jw~4Le23@s(mYyXWL9SX6Ot zmb)sZaly_P%BeX_9 zw&{yBef8tFm+%=--m*J|o~+Xg3N+$IH)t)=fqD+|fEk4AAZ&!wcN5=mi~Vvo^i`}> z#_3ahR}Ju)(Px7kev#JGcSwPXJ2id9%Qd2A#Uc@t8~egZ8;iC{e! z%=CGJOD1}j!HW_sgbi_8suYnn4#Ou}%9u)dXd3huFIb!ytlX>Denx@pCS-Nj$`VO&j@(z!kKSP0hE4;YIP#w9ta=3DO$7f*x zc9M4&NK%IrVmZAe=r@skWD`AEWH=g+r|*13Ss$+{c_R!b?>?UaGXlw*8qDmY#xlR= z<0XFbs2t?8i^G~m?b|!Hal^ZjRjt<@a? z%({Gn14b4-a|#uY^=@iiKH+k?~~wTj5K1A&hU z2^9-HTC)7zpoWK|$JXaBL6C z#qSNYtY>65T@Zs&-0cHeu|RX(Pxz6vTITdzJdYippF zC-EB+n4}#lM7`2Ry~SO>FxhKboIAF#Z{1wqxaCb{#yEFhLuX;Rx(Lz%T`Xo1+a2M}7D+@wol2)OJs$TwtRNJ={( zD@#zTUEE}#Fz#&(EoD|SV#bayvr&E0vzmb%H?o~46|FAcx?r4$N z&67W3mdip-T1RIxwSm_&(%U|+WvtGBj*}t69XVd&ebn>KOuL(7Y8cV?THd-(+9>G7*Nt%T zcH;`p={`SOjaf7hNd(=37Lz3-51;58JffzIPgGs_7xIOsB5p2t&@v1mKS$2D$*GQ6 zM(IR*j4{nri7NMK9xlDy-hJW6sW|ZiDRaFiayj%;(%51DN!ZCCCXz+0Vm#};70nOx zJ#yA0P3p^1DED;jGdPbQWo0WATN=&2(QybbVdhd=Vq*liDk`c7iZ?*AKEYC#SY&2g z&Q(Ci)MJ{mEat$ZdSwTjf6h~roanYh2?9j$CF@4hjj_f35kTKuGHvIs9}Re@iKMxS-OI*`0S z6s)fOtz}O$T?PLFVSeOjSO26$@u`e<>k(OSP!&YstH3ANh>)mzmKGNOwOawq-MPXe zy4xbeUAl6tamnx))-`Gi2uV5>9n(73yS)Ukma4*7fI8PaEwa)dWHs6QA6>$}7?(L8 ztN8M}?{Tf!Zu22J5?2@95&rQ|F7=FK-hihT-vDp!5JCcWrVogEnp;CHenAZ)+E+K5 z$Cffk5sNwD_?4+ymgcHR(5xgt20Z8M`2*;MzOM#>yhk{r3x=EyM226wb&!+j`W<%* zSc&|`8!>dn9D@!pYow~(DsY_naSx7(Z4i>cu#hA5=;IuI88}7f%)bRkuY2B;+9Uep zpXcvFWkJ!mQai63BgNXG26$5kyhZ2&*3Q_tk)Ii4M>@p~_~q_cE!|^A;_MHB;7s#9 zKzMzK{lIxotjc};k67^Xsl-gS!^*m*m6kn|sbdun`O?dUkJ{0cmI0-_2y=lTAfn*Y zKg*A-2sJq)CCJgY0LF-VQvl&6HIXZyxo2#!O&6fOhbHXC?%1cMc6y^*dOS{f$=137Ds1m01qs`>iUQ49JijsaQ( zksqV9@&?il$|4Ua%4!O15>Zy&%gBY&wgqB>XA3!EldQ%1CRSM(pp#k~-pkcCg4LAT zXE=puHbgsw)!xtc@P4r~Z}nTF=D2~j(6D%gTBw$(`Fc=OOQ0kiW$_RDd=hcO0t97h zb86S5r=>(@VGy1&#S$Kg_H@7G^;8Ue)X5Y+IWUi`o;mpvoV)`fcVk4FpcT|;EG!;? zHG^zrVVZOm>1KFaHlaogcWj(v!S)O(Aa|Vo?S|P z5|6b{qkH(USa*Z7-y_Uvty_Z1|B{rTS^qmEMLEYUSk03_Fg&!O3BMo{b^*`3SHvl0 zhnLTe^_vVIdcSHe)SQE}r~2dq)VZJ!aSKR?RS<(9lzkYo&dQ?mubnWmgMM37Nudwo z3Vz@R{=m2gENUE3V4NbIzAA$H1z0pagz94-PTJyX{b$yndsdKptmlKQKaaHj@3=ED zc7L?p@%ui|RegVYutK$64q4pe9+5sv34QUpo)u{1ci?)_7gXQd{PL>b0l(LI#rJmN zGuO+%GO`xneFOOr4EU(Wg}_%bhzUf;d@TU+V*2#}!2OLwg~%D;1FAu=Un>OgjPb3S z7l(riiCwgghC=Lm5hWGf5NdGp#01xQ59`HJcLXbUR3&n%P(+W2q$h2Qd z*6+-QXJ*&Kvk9ht0f0*rO_|FMBALen{j7T1l%=Q>gf#kma zQlg#I9+HB+z*5BMxdesMND`_W;q5|FaEURFk|~&{@qY32N$G$2B=&Po{=!)x5b!#n zxLzblkq{yj05#O7(GRuT39(06FJlalyv<#K4m}+vs>9@q-&31@1(QBv82{}Zkns~K ze{eHC_RDX0#^A*JQTwF`a=IkE6Ze@j#-8Q`tTT?k9`^ZhA~3eCZJ-Jr{~7Cx;H4A3 zcZ+Zj{mzFZbVvQ6U~n>$U2ZotGsERZ@}VKrgGh0xM;Jzt29%TX6_&CWzg+YYMozrM z`nutuS)_0dCM8UVaKRj804J4i%z2BA_8A4OJRQ$N(P9Mfn-gF;4#q788C@9XR0O3< zsoS4wIoyt046d+LnSCJOy@B@Uz*#GGd#+Ln1ek5Dv>(ZtD@tgZlPnZZJGBLr^JK+!$$?A_fA3LOrkoDRH&l7 zcMcD$Hsjko3`-{bn)jPL6E9Ds{WskMrivsUu5apD z?grQO@W7i5+%X&E&p|RBaEZ(sGLR@~(y^BI@lDMot^Ll?!`90KT!JXUhYS`ZgX3jnu@Ja^seA*M5R@f`=`ynQV4rc$uT1mvE?@tz)TN<=&H1%Z?5yjxcpO+6y_R z6EPuPKM5uxKpmZfT(WKjRRNHs@ib)F5WAP7QCADvmCSD#hPz$V10wiD&{NXyEwx5S z6NE`3z!IS^$s7m}PCwQutVQ#~w+V z=+~->DI*bR2j0^@dMr9`p>q^Ny~NrAVxrJtX2DUveic5vM%#N*XO|?YAWwNI$Q)_) zvE|L(L1jP@F%gOGtnlXtIv2&1i8q<)Xfz8O3G^Ea~e*HJsQgBxWL(yuLY+jqUK zRE~`-zklrGog(X}$9@ZVUw!8*=l`6mzYLtsg`AvBYz(cxmAhr^j0~(rzXdiOEeu_p zE$sf2(w(BPAvO5DlaN&uQ$4@p-b?fRs}d7&2UQ4Fh?1Hzu*YVjcndqJLw0#q@fR4u zJCJ}>_7-|QbvOfylj+e^_L`5Ep9gqd>XI3-O?Wp z-gt*P29f$Tx(mtS`0d05nHH=gm~Po_^OxxUwV294BDKT>PHVlC5bndncxGR!n(OOm znsNt@Q&N{TLrmsoKFw0&_M9$&+C24`sIXGWgQaz=kY;S{?w`z^Q0JXXBKFLj0w0U6P*+jPKyZHX9F#b0D1$&(- zrm8PJd?+SrVf^JlfTM^qGDK&-p2Kdfg?f>^%>1n8bu&byH(huaocL>l@f%c*QkX2i znl}VZ4R1en4S&Bcqw?$=Zi7ohqB$Jw9x`aM#>pHc0x z0$!q7iFu zZ`tryM70qBI6JWWTF9EjgG@>6SRzsd}3h+4D8d~@CR07P$LJ}MFsYi-*O%XVvD@yT|rJ+Mk zDllJ7$n0V&A!0flbOf)HE6P_afPWZmbhpliqJuw=-h+r;WGk|ntkWN(8tKlYpq5Ow z(@%s>IN8nHRaYb*^d;M(D$zGCv5C|uqmsDjwy4g=Lz>*OhO3z=)VD}C<65;`89Ye} zSCxrv#ILzIpEx1KdLPlM&%Cctf@FqTKvNPXC&`*H9=l=D3r!GLM?UV zOxa(8ZsB`&+76S-_xuj?G#wXBfDY@Z_tMpXJS7^mp z@YX&u0jYw2A+Z+bD#6sgVK5ZgdPSJV3>{K^4~%HV?rn~4D)*2H!67Y>0aOmzup`{D zzDp3c9yEbGCY$U<8biJ_gB*`jluz1ShUd!QUIQJ$*1;MXCMApJ^m*Fiv88RZ zFopLViw}{$Tyhh_{MLGIE2~sZ)t0VvoW%=8qKZ>h=adTe3QM$&$PO2lfqH@brt!9j ziePM8$!CgE9iz6B<6_wyTQj?qYa;eC^{x_0wuwV~W+^fZmFco-o%wsKSnjXFEx02V zF5C2t)T6Gw$Kf^_c;Ei3G~uC8SM-xyycmXyC2hAVi-IfXqhu$$-C=*|X?R0~hu z8`J6TdgflslhrmDZq1f?GXF7*ALeMmOEpRDg(s*H`4>_NAr`2uqF;k;JQ+8>A|_6ZNsNLECC%NNEb1Y1dP zbIEmNpK)#XagtL4R6BC{C5T(+=yA-(Z|Ap}U-AfZM#gwVpus3(gPn}Q$CExObJ5AC z)ff9Yk?wZ}dZ-^)?cbb9Fw#EjqQ8jxF4G3=L?Ra zg_)0QDMV1y^A^>HRI$x?Op@t;oj&H@1xt4SZ9(kifQ zb59B*`M99Td7@aZ3UWvj1rD0sE)d=BsBuW*KwkCds7ay(7*01_+L}b~7)VHI>F_!{ zyxg-&nCO?v#KOUec0{OOKy+sjWA;8rTE|Lv6I9H?CI?H(mUm8VXGwU$49LGpz&{nQp2}dinE1@lZ1iox6{ghN&v^GZv9J${7WaXj)<0S4g_uiJ&JCZ zr8-hsu`U%N;+9N^@&Q0^kVPB3)wY(rr}p7{p0qFHb3NUUHJb672+wRZs`gd1UjKPX z4o6zljKKA+Kkj?H>Ew63o%QjyBk&1!P22;MkD>sM0=z_s-G{mTixJCT9@_|*(p^bz zJ8?ZZ&;pzV+7#6Mn`_U-)k8Pjg?a;|Oe^us^PoPY$Va~yi8|?+&=y$f+lABT<*pZr zP}D{~Pq1Qyni+@|aP;ixO~mbEW9#c0OU#YbDZIaw=_&$K%Ep2f%hO^&P67hApZe`x zv8b`Mz@?M_7-)b!lkQKk)JXXUuT|B8kJlvqRmRpxtQDgvrHMXC1B$M@Y%Me!BSx3P z#2Eawl$HleZhhTS6Txm>lN_+I`>eV$&v9fOg)%zVn3O5mI*lAl>QcHuW6!Kixmq`X zBCZ*Ck6OYtDiK!N47>jxI&O2a9x7M|i^IagRr-fmrmikEQGgw%J7bO|)*$2FW95O4 zeBs>KR)izRG1gRVL;F*sr8A}aRHO0gc$$j&ds8CIO1=Gwq1%_~E)CWNn9pCtBE}+`Jelk4{>S)M)`Ll=!~gnn1yq^EX(+y*ik@3Ou0qU`IgYi3*doM+5&dU!cho$pZ zn%lhKeZkS72P?Cf68<#kll_6OAO26bIbueZx**j6o;I0cS^XiL`y+>{cD}gd%lux} z)3N>MaE24WBZ}s0ApfdM;5J_Ny}rfUyxfkC``Awo2#sgLnGPewK};dORuT?@I6(5~ z?kE)Qh$L&fwJXzK){iYx!l5$Tt|^D~MkGZPA}(o6f7w~O2G6Vvzdo*a;iXzk$B66$ zwF#;wM7A+(;uFG4+UAY(2`*3XXx|V$K8AYu#ECJYSl@S=uZW$ksfC$~qrrbQj4??z-)uz0QL}>k^?fPnJTPw% zGz)~?B4}u0CzOf@l^um}HZzbaIwPmb<)< zi_3@E9lc)Qe2_`*Z^HH;1CXOceL=CHpHS{HySy3T%<^NrWQ}G0i4e1xm_K3(+~oi$ zoHl9wzb?Z4j#90DtURtjtgvi7uw8DzHYmtPb;?%8vb9n@bszT=1qr)V_>R%s!92_` zfnHQPANx z<#hIjIMm#*(v*!OXtF+w8kLu`o?VZ5k7{`vw{Yc^qYclpUGIM_PBN1+c{#Vxv&E*@ zxg=W2W~JuV{IuRYw3>LSI1)a!thID@R=bU+cU@DbR^_SXY`MC7HOsCN z!dO4OKV7(E_Z8T#8MA1H`99?Z!r0)qKW_#|29X3#Jb+5+>qUidbeP1NJ@)(qi2S-X zao|f0_tl(O+$R|Qwd$H{_ig|~I1fbp_$NkI!0E;Y z6JrnU{1Ra6^on{9gUUB0mwzP3S%B#h0fjo>JvV~#+X0P~JV=IG=yHG$O+p5O3NUgG zEQ}z6BTp^Fie)Sg<){Z&I8NwPR(=mO4joTLHkJ>|Tnk23E(Bo`FSbPc05lF2-+)X? z6vV3*m~IBHTy*^E!<0nA(tCOJW2G4DsH7)BxLV8kICn5lu6@U*R`w)o9;Ro$i8=Q^V%uH8n3q=+Yf;SFRZu z!+F&PKcH#8cG?aSK_Tl@K9P#8o+jry@gdexz&d(Q=47<7nw@e@FFfIRNL9^)1i@;A z28+$Z#rjv-wj#heI|<&J_DiJ*s}xd-f!{J8jfqOHE`TiHHZVIA8CjkNQ_u;Ery^^t zl1I75&u^`1_q)crO+JT4rx|z2ToSC>)Or@-D zy3S>jW*sNIZR-EBsfyaJ+Jq4BQE4?SePtD2+jY8*%FsSLZ9MY>+wk?}}}AFAw)vr{ml)8LUG-y9>^t!{~|sgpxYc0Gnkg`&~R z-pilJZjr@y5$>B=VMdZ73svct%##v%wdX~9fz6i3Q-zOKJ9wso+h?VME7}SjL=!NUG{J?M&i!>ma`eoEa@IX`5G>B1(7;%}M*%-# zfhJ(W{y;>MRz!Ic8=S}VaBKqh;~7KdnGEHxcL$kA-6E~=!hrN*zw9N+_=odt<$_H_8dbo;0=42wcAETPCVGUr~v(`Uai zb{=D!Qc!dOEU6v)2eHSZq%5iqK?B(JlCq%T6av$Cb4Rko6onlG&?CqaX7Y_C_cOC3 zYZ;_oI(}=>_07}Oep&Ws7x7-R)cc8zfe!SYxJYP``pi$FDS)4Fvw5HH=FiU6xfVqIM!hJ;Rx8c0cB7~aPtNH(Nmm5Vh{ibAoU#J6 zImRCr?(iyu_4W_6AWo3*vxTPUw@vPwy@E0`(>1Qi=%>5eSIrp^`` zK*Y?fK_6F1W>-7UsB)RPC4>>Ps9)f+^MqM}8AUm@tZ->j%&h1M8s*s!LX5&WxQcAh z8mciQej@RPm?660%>{_D+7er>%zX_{s|$Z+;G7_sfNfBgY(zLB4Ey}J9F>zX#K0f6 z?dVNIeEh?EIShmP6>M+d|0wMM85Sa4diw1hrg|ITJ}JDg@o8y>(rF9mXk5M z2@D|NA)-7>wD&wF;S_$KS=eE84`BGw3g0?6wGxu8ys4rwI?9U=*^VF22t3%mbGeOh z`!O-OpF7#Vceu~F`${bW0nYVU9ecmk31V{tF%iv&5hWofC>I~cqAt@u6|R+|HLMMX zVxuSlMFOK_EQ86#E8&KwxIr8S9tj_goWtLv4f@!&h8;Ov41{J~496vp9vX=(LK#j! zAwi*21RAV-LD>9Cw3bV_9X(X3)Kr0-UaB*7Y>t82EQ%!)(&(XuAYtTsYy-dz+w=$ir)VJpe!_$ z6SGpX^i(af3{o=VlFPC);|J8#(=_8#vdxDe|Cok+ANhYwbE*FO`Su2m1~w+&9<_9~ z-|tTU_ACGN`~CNW5WYYBn^B#SwZ(t4%3aPp z;o)|L6Rk569KGxFLUPx@!6OOa+5OjQLK5w&nAmwxkC5rZ|m&HT8G%GVZxB_@ME z>>{rnXUqyiJrT(8GMj_ap#yN_!9-lO5e8mR3cJiK3NE{_UM&=*vIU`YkiL$1%kf+1 z4=jk@7EEj`u(jy$HnzE33ZVW_J4bj}K;vT?T91YlO(|Y0FU4r+VdbmQ97%(J5 zkK*Bed8+C}FcZ@HIgdCMioV%A<*4pw_n}l*{Cr4}a(lq|injK#O?$tyvyE`S%(1`H z_wwRvk#13ElkZvij2MFGOj`fhy?nC^8`Zyo%yVcUAfEr8x&J#A{|moUBAV_^f$hpaUuyQeY3da^ zS9iRgf87YBwfe}>BO+T&Fl%rfpZh#+AM?Dq-k$Bq`vG6G_b4z%Kbd&v>qFjow*mBl z-OylnqOpLg}or7_VNwRg2za3VBK6FUfFX{|TD z`Wt0Vm2H$vdlRWYQJqDmM?JUbVqL*ZQY|5&sY*?!&%P8qhA~5+Af<{MaGo(dl&C5t zE%t!J0 zh6jqANt4ABdPxSTrVV}fLsRQal*)l&_*rFq(Ez}ClEH6LHv{J#v?+H-BZ2)Wy{K@9 z+ovXHq~DiDvm>O~r$LJo!cOuwL+Oa--6;UFE2q@g3N8Qkw5E>ytz^(&($!O47+i~$ zKM+tkAd-RbmP{s_rh+ugTD;lriL~`Xwkad#;_aM?nQ7L_muEFI}U_4$phjvYgleK~`Fo`;GiC07&Hq1F<%p;9Q;tv5b?*QnR%8DYJH3P>Svmv47Y>*LPZJy8_{9H`g6kQpyZU{oJ`m%&p~D=K#KpfoJ@ zn-3cqmHsdtN!f?~w+(t+I`*7GQA#EQC^lUA9(i6=i1PqSAc|ha91I%X&nXzjYaM{8$s&wEx@aVkQ6M{E2 zfzId#&r(XwUNtPcq4Ngze^+XaJA1EK-%&C9j>^9(secqe{}z>hR5CFNveMsVA)m#S zk)_%SidkY-XmMWlVnQ(mNJ>)ooszQ#vaK;!rPmGKXV7am^_F!Lz>;~{VrIO$;!#30XRhE1QqO_~#+Ux;B_D{Nk=grn z8Y0oR^4RqtcYM)7a%@B(XdbZCOqnX#fD{BQTeLvRHd(irHKq=4*jq34`6@VAQR8WG z^%)@5CXnD_T#f%@-l${>y$tfb>2LPmc{~5A82|16mH)R?&r#KKLs7xpN-D`=&Cm^R zvMA6#Ahr<3X>Q7|-qfTY)}32HkAz$_mibYV!I)u>bmjK`qwBe(>za^0Kt*HnFbSdO z1>+ryKCNxmm^)*$XfiDOF2|{-v3KKB?&!(S_Y=Ht@|ir^hLd978xuI&N{k>?(*f8H z=ClxVJK_%_z1TH0eUwm2J+2To7FK4o+n_na)&#VLn1m;!+CX+~WC+qg1?PA~KdOlC zW)C@pw75_xoe=w7i|r9KGIvQ$+3K?L{7TGHwrQM{dCp=Z*D}3kX7E-@sZnup!BImw z*T#a=+WcTwL78exTgBn|iNE3#EsOorO z*kt)gDzHiPt07fmisA2LWN?AymkdqTgr?=loT7z@d`wnlr6oN}@o|&JX!yPzC*Y8d zu6kWlTzE1)ckyBn+0Y^HMN+GA$wUO_LN6W>mxCo!0?oiQvT`z$jbSEu&{UHRU0E8# z%B^wOc@S!yhMT49Y)ww(Xta^8pmPCe@eI5C*ed96)AX9<>))nKx0(sci8gwob_1}4 z0DIL&vsJ1_s%<@y%U*-eX z5rN&(zef-5G~?@r79oZGW1d!WaTqQn0F6RIOa9tJ=0(kdd{d1{<*tHT#cCvl*i>YY zH+L7jq8xZNcTUBqj(S)ztTU!TM!RQ}In*n&Gn<>(60G7}4%WQL!o>hbJqNDSGwl#H z`4k+twp0cj%PsS+NKaxslAEu9!#U3xT1|_KB6`h=PI0SW`P9GTa7caD1}vKEglV8# zjKZR`pluCW19c2fM&ZG)c3T3Um;ir3y(tSCJ7Agl6|b524dy5El{^EQBG?E61H0XY z`bqg!;zhGhyMFl&(o=JWEJ8n~z)xI}A@C0d2hQGvw7nGv)?POU@(kS1m=%`|+^ika zXl8zjS?xqW$WlO?Ewa;vF~XbybHBor$f<%I&*t$F5fynwZlTGj|IjZtVfGa7l&tK} zW>I<69w(cZLu)QIVG|M2xzW@S+70NinQzk&Y0+3WT*cC)rx~04O-^<{JohU_&HL5XdUKW!uFy|i$FB|EMu0eUyW;gsf`XfIc!Z0V zeK&*hPL}f_cX=@iv>K%S5kL;cl_$v?n(Q9f_cChk8Lq$glT|=e+T*8O4H2n<=NGmn z+2*h+v;kBvF>}&0RDS>)B{1!_*XuE8A$Y=G8w^qGMtfudDBsD5>T5SB;Qo}fSkkiV ze^K^M(UthkwrD!&*tTsu>Dacdj_q`~V%r_twr$(Ct&_dKeeXE?fA&4&yASJWJ*}~- zel=@W)tusynfC_YqH4ll>4Eg`Xjs5F7Tj>tTLz<0N3)X<1px_d2yUY>X~y>>93*$) z5PuNMQLf9Bu?AAGO~a_|J2akO1M*@VYN^VxvP0F$2>;Zb9;d5Yfd8P%oFCCoZE$ z4#N$^J8rxYjUE_6{T%Y>MmWfHgScpuGv59#4u6fpTF%~KB^Ae`t1TD_^Ud#DhL+Dm zbY^VAM#MrAmFj{3-BpVSWph2b_Y6gCnCAombVa|1S@DU)2r9W<> zT5L8BB^er3zxKt1v(y&OYk!^aoQisqU zH(g@_o)D~BufUXcPt!Ydom)e|aW{XiMnes2z&rE?og>7|G+tp7&^;q?Qz5S5^yd$i z8lWr4g5nctBHtigX%0%XzIAB8U|T6&JsC4&^hZBw^*aIcuNO47de?|pGXJ4t}BB`L^d8tD`H`i zqrP8?#J@8T#;{^B!KO6J=@OWKhAerih(phML`(Rg7N1XWf1TN>=Z3Do{l_!d~DND&)O)D>ta20}@Lt77qSnVsA7>)uZAaT9bsB>u&aUQl+7GiY2|dAEg@%Al3i316y;&IhQL^8fw_nwS>f60M_-m+!5)S_6EPM7Y)(Nq^8gL7(3 zOiot`6Wy6%vw~a_H?1hLVzIT^i1;HedHgW9-P#)}Y6vF%C=P70X0Tk^z9Te@kPILI z_(gk!k+0%CG)%!WnBjjw*kAKs_lf#=5HXC00s-}oM-Q1aXYLj)(1d!_a7 z*Gg4Fe6F$*ujVjI|79Z5+Pr`us%zW@ln++2l+0hsngv<{mJ%?OfSo_3HJXOCys{Ug z00*YR-(fv<=&%Q!j%b-_ppA$JsTm^_L4x`$k{VpfLI(FMCap%LFAyq;#ns5bR7V+x zO!o;c5y~DyBPqdVQX)8G^G&jWkBy2|oWTw>)?5u}SAsI$RjT#)lTV&Rf8;>u*qXnb z8F%Xb=7#$m)83z%`E;49)t3fHInhtc#kx4wSLLms!*~Z$V?bTyUGiS&m>1P(952(H zuHdv=;o*{;5#X-uAyon`hP}d#U{uDlV?W?_5UjJvf%11hKwe&(&9_~{W)*y1nR5f_ z!N(R74nNK`y8>B!0Bt_Vr!;nc3W>~RiKtGSBkNlsR#-t^&;$W#)f9tTlZz>n*+Fjz z3zXZ;jf(sTM(oDzJt4FJS*8c&;PLTW(IQDFs_5QPy+7yhi1syPCarvqrHFcf&yTy)^O<1EBx;Ir`5W{TIM>{8w&PB>ro4;YD<5LF^TjTb0!zAP|QijA+1Vg>{Afv^% zmrkc4o6rvBI;Q8rj4*=AZacy*n8B{&G3VJc)so4$XUoie0)vr;qzPZVbb<#Fc=j+8CGBWe$n|3K& z_@%?{l|TzKSlUEO{U{{%Fz_pVDxs7i9H#bnbCw7@4DR=}r_qV!Zo~CvD4ZI*+j3kO zW6_=|S`)(*gM0Z;;}nj`73OigF4p6_NPZQ-Od~e$c_);;4-7sR>+2u$6m$Gf%T{aq zle>e3(*Rt(TPD}03n5)!Ca8Pu!V}m6v0o1;5<1h$*|7z|^(3$Y&;KHKTT}hV056wuF0Xo@mK-52~r=6^SI1NC%c~CC?n>yX6wPTgiWYVz!Sx^atLby9YNn1Rk{g?|pJaxD4|9cUf|V1_I*w zzxK)hRh9%zOl=*$?XUjly5z8?jPMy%vEN)f%T*|WO|bp5NWv@B(K3D6LMl!-6dQg0 zXNE&O>Oyf%K@`ngCvbGPR>HRg5!1IV$_}m@3dWB7x3t&KFyOJn9pxRXCAzFr&%37wXG;z^xaO$ekR=LJG ztIHpY8F5xBP{mtQidqNRoz= z@){+N3(VO5bD+VrmS^YjG@+JO{EOIW)9=F4v_$Ed8rZtHvjpiEp{r^c4F6Ic#ChlC zJX^DtSK+v(YdCW)^EFcs=XP7S>Y!4=xgmv>{S$~@h=xW-G4FF9?I@zYN$e5oF9g$# zb!eVU#J+NjLyX;yb)%SY)xJdvGhsnE*JEkuOVo^k5PyS=o#vq!KD46UTW_%R=Y&0G zFj6bV{`Y6)YoKgqnir2&+sl+i6foAn-**Zd1{_;Zb7Ki=u394C5J{l^H@XN`_6XTKY%X1AgQM6KycJ+= zYO=&t#5oSKB^pYhNdzPgH~aEGW2=ec1O#s-KG z71}LOg@4UEFtp3GY1PBemXpNs6UK-ax*)#$J^pC_me;Z$Je(OqLoh|ZrW*mAMBFn< zHttjwC&fkVfMnQeen8`Rvy^$pNRFVaiEN4Pih*Y3@jo!T0nsClN)pdrr9AYLcZxZ| zJ5Wlj+4q~($hbtuY zVQ7hl>4-+@6g1i`1a)rvtp-;b0>^`Dloy(#{z~ytgv=j4q^Kl}wD>K_Y!l~ zp(_&7sh`vfO(1*MO!B%<6E_bx1)&s+Ae`O)a|X=J9y~XDa@UB`m)`tSG4AUhoM=5& znWoHlA-(z@3n0=l{E)R-p8sB9XkV zZ#D8wietfHL?J5X0%&fGg@MH~(rNS2`GHS4xTo7L$>TPme+Is~!|79=^}QbPF>m%J zFMkGzSndiPO|E~hrhCeo@&Ea{M(ieIgRWMf)E}qeTxT8Q#g-!Lu*x$v8W^M^>?-g= zwMJ$dThI|~M06rG$Sv@C@tWR>_YgaG&!BAbkGggVQa#KdtDB)lMLNVLN|51C@F^y8 zCRvMB^{GO@j=cHfmy}_pCGbP%xb{pNN>? z?7tBz$1^zVaP|uaatYaIN+#xEN4jBzwZ|YI_)p(4CUAz1ZEbDk>J~Y|63SZaak~#0 zoYKruYsWHoOlC1(MhTnsdUOwQfz5p6-D0}4;DO$B;7#M{3lSE^jnTT;ns`>!G%i*F?@pR1JO{QTuD0U+~SlZxcc8~>IB{)@8p`P&+nDxNj`*gh|u?yrv$phpQcW)Us)bi`kT%qLj(fi{dWRZ%Es2!=3mI~UxiW0$-v3vUl?#g{p6eF zMEUAqo5-L0Ar(s{VlR9g=j7+lt!gP!UN2ICMokAZ5(Agd>})#gkA2w|5+<%-CuEP# zqgcM}u@3(QIC^Gx<2dbLj?cFSws_f3e%f4jeR?4M^M3cx1f+Qr6ydQ>n)kz1s##2w zk}UyQc+Z5G-d-1}{WzjkLXgS-2P7auWSJ%pSnD|Uivj5u!xk0 z_^-N9r9o;(rFDt~q1PvE#iJZ_f>J3gcP$)SOqhE~pD2|$=GvpL^d!r z6u=sp-CrMoF7;)}Zd7XO4XihC4ji?>V&(t^?@3Q&t9Mx=qex6C9d%{FE6dvU6%d94 zIE;hJ1J)cCqjv?F``7I*6bc#X)JW2b4f$L^>j{*$R`%5VHFi*+Q$2;nyieduE}qdS{L8y8F08yLs?w}{>8>$3236T-VMh@B zq-nujsb_1aUv_7g#)*rf9h%sFj*^mIcImRV*k~Vmw;%;YH(&ylYpy!&UjUVqqtfG` zox3esju?`unJJA_zKXRJP)rA3nXc$m^{S&-p|v|-0x9LHJm;XIww7C#R$?00l&Yyj z=e}gKUOpsImwW?N)+E(awoF@HyP^EhL+GlNB#k?R<2>95hz!h9sF@U20DHSB3~WMa zk90+858r@-+vWwkawJ)8ougd(i#1m3GLN{iSTylYz$brAsP%=&m$mQQrH$g%3-^VR zE%B`Vi&m8f3T~&myTEK28BDWCVzfWir1I?03;pX))|kY5ClO^+bae z*7E?g=3g7EiisYOrE+lA)2?Ln6q2*HLNpZEWMB|O-JI_oaHZB%CvYB(%=tU= zE*OY%QY58fW#RG5=gm0NR#iMB=EuNF@)%oZJ}nmm=tsJ?eGjia{e{yuU0l3{d^D@)kVDt=1PE)&tf_hHC%0MB znL|CRCPC}SeuVTdf>-QV70`0(EHizc21s^sU>y%hW0t!0&y<7}Wi-wGy>m%(-jsDj zP?mF|>p_K>liZ6ZP(w5(|9Ga%>tLgb$|doDDfkdW>Z z`)>V2XC?NJT26mL^@ zf+IKr27TfM!UbZ@?zRddC7#6ss1sw%CXJ4FWC+t3lHZupzM77m^=9 z&(a?-LxIq}*nvv)y?27lZ{j zifdl9hyJudyP2LpU$-kXctshbJDKS{WfulP5Dk~xU4Le4c#h^(YjJit4#R8_khheS z|8(>2ibaHES4+J|DBM7I#QF5u-*EdN{n=Kt@4Zt?@Tv{JZA{`4 zU#kYOv{#A&gGPwT+$Ud}AXlK3K7hYzo$(fBSFjrP{QQ zeaKg--L&jh$9N}`pu{Bs>?eDFPaWY4|9|foN%}i;3%;@4{dc+iw>m}{3rELqH21G! z`8@;w-zsJ1H(N3%|1B@#ioLOjib)j`EiJqPQVSbPSPVHCj6t5J&(NcWzBrzCiDt{4 zdlPAUKldz%6x5II1H_+jv)(xVL+a;P+-1hv_pM>gMRr%04@k;DTokASSKKhU1Qms| zrWh3a!b(J3n0>-tipg{a?UaKsP7?+|@A+1WPDiQIW1Sf@qDU~M_P65_s}7(gjTn0X zucyEm)o;f8UyshMy&>^SC3I|C6jR*R_GFwGranWZe*I>K+0k}pBuET&M~ z;Odo*ZcT?ZpduHyrf8E%IBFtv;JQ!N_m>!sV6ly$_1D{(&nO~w)G~Y`7sD3#hQk%^ zp}ucDF_$!6DAz*PM8yE(&~;%|=+h(Rn-=1Wykas_-@d&z#=S}rDf`4w(rVlcF&lF! z=1)M3YVz7orwk^BXhslJ8jR);sh^knJW(Qmm(QdSgIAIdlN4Te5KJisifjr?eB{FjAX1a0AB>d?qY4Wx>BZ8&}5K0fA+d{l8 z?^s&l8#j7pR&ijD?0b%;lL9l$P_mi2^*_OL+b}4kuLR$GAf85sOo02?Y#90}CCDiS zZ%rbCw>=H~CBO=C_JVV=xgDe%b4FaEFtuS7Q1##y686r%F6I)s-~2(}PWK|Z8M+Gu zl$y~5@#0Ka%$M<&Cv%L`a8X^@tY&T7<0|(6dNT=EsRe0%kp1Qyq!^43VAKYnr*A5~ zsI%lK1ewqO;0TpLrT9v}!@vJK{QoVa_+N4FYT#h?Y8rS1S&-G+m$FNMP?(8N`MZP zels(*?kK{{^g9DOzkuZXJ2;SrOQsp9T$hwRB1(phw1c7`!Q!by?Q#YsSM#I12RhU{$Q+{xj83axHcftEc$mNJ8_T7A-BQc*k(sZ+~NsO~xAA zxnbb%dam_fZlHvW7fKXrB~F&jS<4FD2FqY?VG?ix*r~MDXCE^WQ|W|WM;gsIA4lQP zJ2hAK@CF*3*VqPr2eeg6GzWFlICi8S>nO>5HvWzyZTE)hlkdC_>pBej*>o0EOHR|) z$?};&I4+_?wvL*g#PJ9)!bc#9BJu1(*RdNEn>#Oxta(VWeM40ola<0aOe2kSS~{^P zDJBd}0L-P#O-CzX*%+$#v;(x%<*SPgAje=F{Zh-@ucd2DA(yC|N_|ocs*|-!H%wEw z@Q!>siv2W;C^^j^59OAX03&}&D*W4EjCvfi(ygcL#~t8XGa#|NPO+*M@Y-)ctFA@I z-p7npT1#5zOLo>7q?aZpCZ=iecn3QYklP;gF0bq@>oyBq94f6C=;Csw3PkZ|5q=(c zfs`aw?II0e(h=|7o&T+hq&m$; zBrE09Twxd9BJ2P+QPN}*OdZ-JZV7%av@OM7v!!NL8R;%WFq*?{9T3{ct@2EKgc8h) zMxoM$SaF#p<`65BwIDfmXG6+OiK0e)`I=!A3E`+K@61f}0e z!2a*FOaDrOe>U`q%K!QN`&=&0C~)CaL3R4VY(NDt{Xz(Xpqru5=r#uQN1L$Je1*dkdqQ*=lofQaN%lO!<5z9ZlHgxt|`THd>2 zsWfU$9=p;yLyJyM^t zS2w9w?Bpto`@H^xJpZDKR1@~^30Il6oFGfk5%g6w*C+VM)+%R@gfIwNprOV5{F^M2 zO?n3DEzpT+EoSV-%OdvZvNF+pDd-ZVZ&d8 zKeIyrrfPN=EcFRCPEDCVflX#3-)Ik_HCkL(ejmY8vzcf-MTA{oHk!R2*36`O68$7J zf}zJC+bbQk--9Xm!u#lgLvx8TXx2J258E5^*IZ(FXMpq$2LUUvhWQPs((z1+2{Op% z?J}9k5^N=z;7ja~zi8a_-exIqWUBJwohe#4QJ`|FF*$C{lM18z^#hX6!5B8KAkLUX ziP=oti-gpV(BsLD{0(3*dw}4JxK23Y7M{BeFPucw!sHpY&l%Ws4pSm`+~V7;bZ%Dx zeI)MK=4vC&5#;2MT7fS?^ch9?2;%<8Jlu-IB&N~gg8t;6S-#C@!NU{`p7M8@2iGc& zg|JPg%@gCoCQ&s6JvDU&`X2S<57f(k8nJ1wvBu{8r?;q3_kpZZ${?|( z+^)UvR33sjSd)aT!UPkA;ylO6{aE3MQa{g%Mcf$1KONcjO@&g5zPHWtzM1rYC{_K> zgQNcs<{&X{OA=cEWw5JGqpr0O>x*Tfak2PE9?FuWtz^DDNI}rwAaT0(bdo-<+SJ6A z&}S%boGMWIS0L}=S>|-#kRX;e^sUsotry(MjE|3_9duvfc|nwF#NHuM-w7ZU!5ei8 z6Mkf>2)WunY2eU@C-Uj-A zG(z0Tz2YoBk>zCz_9-)4a>T46$(~kF+Y{#sA9MWH%5z#zNoz)sdXq7ZR_+`RZ%0(q zC7&GyS_|BGHNFl8Xa%@>iWh%Gr?=J5<(!OEjauj5jyrA-QXBjn0OAhJJ9+v=!LK`` z@g(`^*84Q4jcDL`OA&ZV60djgwG`|bcD*i50O}Q{9_noRg|~?dj%VtKOnyRs$Uzqg z191aWoR^rDX#@iSq0n z?9Sg$WSRPqSeI<}&n1T3!6%Wj@5iw5`*`Btni~G=&;J+4`7g#OQTa>u`{4ZZ(c@s$ zK0y;ySOGD-UTjREKbru{QaS>HjN<2)R%Nn-TZiQ(Twe4p@-saNa3~p{?^V9Nixz@a zykPv~<@lu6-Ng9i$Lrk(xi2Tri3q=RW`BJYOPC;S0Yly%77c727Yj-d1vF!Fuk{Xh z)lMbA69y7*5ufET>P*gXQrxsW+ zz)*MbHZv*eJPEXYE<6g6_M7N%#%mR{#awV3i^PafNv(zyI)&bH?F}2s8_rR(6%!V4SOWlup`TKAb@ee>!9JKPM=&8g#BeYRH9FpFybxBXQI2|g}FGJfJ+ zY-*2hB?o{TVL;Wt_ek;AP5PBqfDR4@Z->_182W z{P@Mc27j6jE*9xG{R$>6_;i=y{qf(c`5w9fa*`rEzX6t!KJ(p1H|>J1pC-2zqWENF zmm=Z5B4u{cY2XYl(PfrInB*~WGWik3@1oRhiMOS|D;acnf-Bs(QCm#wR;@Vf!hOPJ zgjhDCfDj$HcyVLJ=AaTbQ{@vIv14LWWF$=i-BDoC11}V;2V8A`S>_x)vIq44-VB-v z*w-d}$G+Ql?En8j!~ZkCpQ$|cA0|+rrY>tiCeWxkRGPoarxlGU2?7%k#F693RHT24 z-?JsiXlT2PTqZqNb&sSc>$d;O4V@|b6VKSWQb~bUaWn1Cf0+K%`Q&Wc<>mQ>*iEGB zbZ;aYOotBZ{vH3y<0A*L0QVM|#rf*LIsGx(O*-7)r@yyBIzJnBFSKBUSl1e|8lxU* zzFL+YDVVkIuzFWeJ8AbgN&w(4-7zbiaMn{5!JQXu)SELk*CNL+Fro|2v|YO)1l15t zs(0^&EB6DPMyaqvY>=KL>)tEpsn;N5Q#yJj<9}ImL((SqErWN3Q=;tBO~ExTCs9hB z2E$7eN#5wX4<3m^5pdjm#5o>s#eS_Q^P)tm$@SawTqF*1dj_i#)3};JslbLKHXl_N z)Fxzf>FN)EK&Rz&*|6&%Hs-^f{V|+_vL1S;-1K-l$5xiC@}%uDuwHYhmsV?YcOUlk zOYkG5v2+`+UWqpn0aaaqrD3lYdh0*!L`3FAsNKu=Q!vJu?Yc8n|CoYyDo_`r0mPoo z8>XCo$W4>l(==h?2~PoRR*kEe)&IH{1sM41mO#-36`02m#nTX{r*r`Q5rZ2-sE|nA zhnn5T#s#v`52T5|?GNS`%HgS2;R(*|^egNPDzzH_z^W)-Q98~$#YAe)cEZ%vge965AS_am#DK#pjPRr-!^za8>`kksCAUj(Xr*1NW5~e zpypt_eJpD&4_bl_y?G%>^L}=>xAaV>KR6;^aBytqpiHe%!j;&MzI_>Sx7O%F%D*8s zSN}cS^<{iiK)=Ji`FpO#^zY!_|D)qeRNAtgmH)m;qC|mq^j(|hL`7uBz+ULUj37gj zksdbnU+LSVo35riSX_4z{UX=%n&}7s0{WuZYoSfwAP`8aKN9P@%e=~1`~1ASL-z%# zw>DO&ixr}c9%4InGc*_y42bdEk)ZdG7-mTu0bD@_vGAr*NcFoMW;@r?@LUhRI zCUJgHb`O?M3!w)|CPu~ej%fddw20lod?Ufp8Dmt0PbnA0J%KE^2~AIcnKP()025V> zG>noSM3$5Btmc$GZoyP^v1@Poz0FD(6YSTH@aD0}BXva?LphAiSz9f&Y(aDAzBnUh z?d2m``~{z;{}kZJ>a^wYI?ry(V9hIoh;|EFc0*-#*`$T0DRQ1;WsqInG;YPS+I4{g zJGpKk%%Sdc5xBa$Q^_I~(F97eqDO7AN3EN0u)PNBAb+n+ zWBTxQx^;O9o0`=g+Zrt_{lP!sgWZHW?8bLYS$;1a@&7w9rD9|Ge;Gb?sEjFoF9-6v z#!2)t{DMHZ2@0W*fCx;62d#;jouz`R5Y(t{BT=$N4yr^^o$ON8d{PQ=!O zX17^CrdM~7D-;ZrC!||<+FEOxI_WI3CA<35va%4v>gc zEX-@h8esj=a4szW7x{0g$hwoWRQG$yK{@3mqd-jYiVofJE!Wok1* znV7Gm&Ssq#hFuvj1sRyHg(6PFA5U*Q8Rx>-blOs=lb`qa{zFy&n4xY;sd$fE+<3EI z##W$P9M{B3c3Si9gw^jlPU-JqD~Cye;wr=XkV7BSv#6}DrsXWFJ3eUNrc%7{=^sP> zrp)BWKA9<}^R9g!0q7yWlh;gr_TEOD|#BmGq<@IV;ueg+D2}cjpp+dPf&Q(36sFU&K8}hA85U61faW&{ zlB`9HUl-WWCG|<1XANN3JVAkRYvr5U4q6;!G*MTdSUt*Mi=z_y3B1A9j-@aK{lNvx zK%p23>M&=KTCgR!Ee8c?DAO2_R?B zkaqr6^BSP!8dHXxj%N1l+V$_%vzHjqvu7p@%Nl6;>y*S}M!B=pz=aqUV#`;h%M0rU zHfcog>kv3UZAEB*g7Er@t6CF8kHDmKTjO@rejA^ULqn!`LwrEwOVmHx^;g|5PHm#B zZ+jjWgjJ!043F+&#_;D*mz%Q60=L9Ove|$gU&~As5^uz@2-BfQ!bW)Khn}G+Wyjw- z19qI#oB(RSNydn0t~;tAmK!P-d{b-@@E5|cdgOS#!>%#Rj6ynkMvaW@37E>@hJP^8 z2zk8VXx|>#R^JCcWdBCy{0nPmYFOxN55#^-rlqobe0#L6)bi?E?SPymF*a5oDDeSd zO0gx?#KMoOd&G(2O@*W)HgX6y_aa6iMCl^~`{@UR`nMQE`>n_{_aY5nA}vqU8mt8H z`oa=g0SyiLd~BxAj2~l$zRSDHxvDs;I4>+M$W`HbJ|g&P+$!U7-PHX4RAcR0szJ*( ze-417=bO2q{492SWrqDK+L3#ChUHtz*@MP)e^%@>_&#Yk^1|tv@j4%3T)diEX zATx4K*hcO`sY$jk#jN5WD<=C3nvuVsRh||qDHnc~;Kf59zr0;c7VkVSUPD%NnnJC_ zl3F^#f_rDu8l}l8qcAz0FFa)EAt32IUy_JLIhU_J^l~FRH&6-ivSpG2PRqzDdMWft>Zc(c)#tb%wgmWN%>IOPm zZi-noqS!^Ftb81pRcQi`X#UhWK70hy4tGW1mz|+vI8c*h@ zfFGJtW3r>qV>1Z0r|L>7I3un^gcep$AAWfZHRvB|E*kktY$qQP_$YG60C@X~tTQjB3%@`uz!qxtxF+LE!+=nrS^07hn` zEgAp!h|r03h7B!$#OZW#ACD+M;-5J!W+{h|6I;5cNnE(Y863%1(oH}_FTW})8zYb$7czP zg~Szk1+_NTm6SJ0MS_|oSz%e(S~P-&SFp;!k?uFayytV$8HPwuyELSXOs^27XvK-D zOx-Dl!P|28DK6iX>p#Yb%3`A&CG0X2S43FjN%IB}q(!hC$fG}yl1y9W&W&I@KTg6@ zK^kpH8=yFuP+vI^+59|3%Zqnb5lTDAykf z9S#X`3N(X^SpdMyWQGOQRjhiwlj!0W-yD<3aEj^&X%=?`6lCy~?`&WSWt z?U~EKFcCG_RJ(Qp7j=$I%H8t)Z@6VjA#>1f@EYiS8MRHZphp zMA_5`znM=pzUpBPO)pXGYpQ6gkine{6u_o!P@Q+NKJ}k!_X7u|qfpAyIJb$_#3@wJ z<1SE2Edkfk9C!0t%}8Yio09^F`YGzpaJHGk*-ffsn85@)%4@`;Fv^8q(-Wk7r=Q8p zT&hD`5(f?M{gfzGbbwh8(}G#|#fDuk7v1W)5H9wkorE0ZZjL0Q1=NRGY>zwgfm81DdoaVwNH;or{{eSyybt)m<=zXoA^RALYG-2t zouH|L*BLvmm9cdMmn+KGopyR@4*=&0&4g|FLoreZOhRmh=)R0bg~ zT2(8V_q7~42-zvb)+y959OAv!V$u(O3)%Es0M@CRFmG{5sovIq4%8Ahjk#*5w{+)+ zMWQoJI_r$HxL5km1#6(e@{lK3Udc~n0@g`g$s?VrnQJ$!oPnb?IHh-1qA`Rz$)Ai< z6w$-MJW-gKNvOhL+XMbE7&mFt`x1KY>k4(!KbbpZ`>`K@1J<(#vVbjx@Z@(6Q}MF# zMnbr-f55(cTa^q4+#)=s+ThMaV~E`B8V=|W_fZWDwiso8tNMTNse)RNBGi=gVwgg% zbOg8>mbRN%7^Um-7oj4=6`$|(K7!+t^90a{$18Z>}<#!bm%ZEFQ{X(yBZMc>lCz0f1I2w9Sq zuGh<9<=AO&g6BZte6hn>Qmvv;Rt)*cJfTr2=~EnGD8P$v3R|&1RCl&7)b+`=QGapi zPbLg_pxm`+HZurtFZ;wZ=`Vk*do~$wB zxoW&=j0OTbQ=Q%S8XJ%~qoa3Ea|au5o}_(P;=!y-AjFrERh%8la!z6Fn@lR?^E~H12D?8#ht=1F;7@o4$Q8GDj;sSC%Jfn01xgL&%F2 zwG1|5ikb^qHv&9hT8w83+yv&BQXOQyMVJSBL(Ky~p)gU3#%|blG?IR9rP^zUbs7rOA0X52Ao=GRt@C&zlyjNLv-} z9?*x{y(`509qhCV*B47f2hLrGl^<@SuRGR!KwHei?!CM10Tq*YDIoBNyRuO*>3FU? zHjipIE#B~y3FSfOsMfj~F9PNr*H?0oHyYB^G(YyNh{SxcE(Y-`x5jFMKb~HO*m+R% zrq|ic4fzJ#USpTm;X7K+E%xsT_3VHKe?*uc4-FsILUH;kL>_okY(w`VU*8+l>o>Jm ziU#?2^`>arnsl#)*R&nf_%>A+qwl%o{l(u)M?DK1^mf260_oteV3#E_>6Y4!_hhVD zM8AI6MM2V*^_M^sQ0dmHu11fy^kOqXqzpr?K$`}BKWG`=Es(9&S@K@)ZjA{lj3ea7_MBP zk(|hBFRjHVMN!sNUkrB;(cTP)T97M$0Dtc&UXSec<+q?y>5=)}S~{Z@ua;1xt@=T5 zI7{`Z=z_X*no8s>mY;>BvEXK%b`a6(DTS6t&b!vf_z#HM{Uoy_5fiB(zpkF{})ruka$iX*~pq1ZxD?q68dIo zIZSVls9kFGsTwvr4{T_LidcWtt$u{kJlW7moRaH6+A5hW&;;2O#$oKyEN8kx`LmG)Wfq4ykh+q{I3|RfVpkR&QH_x;t41Uw z`P+tft^E2B$domKT@|nNW`EHwyj>&}K;eDpe z1bNOh=fvIfk`&B61+S8ND<(KC%>y&?>opCnY*r5M+!UrWKxv0_QvTlJc>X#AaI^xo zaRXL}t5Ej_Z$y*|w*$6D+A?Lw-CO-$itm^{2Ct82-<0IW)0KMNvJHgBrdsIR0v~=H z?n6^}l{D``Me90`^o|q!olsF?UX3YSq^6Vu>Ijm>>PaZI8G@<^NGw{Cx&%|PwYrfw zR!gX_%AR=L3BFsf8LxI|K^J}deh0ZdV?$3r--FEX`#INxsOG6_=!v)DI>0q|BxT)z z-G6kzA01M?rba+G_mwNMQD1mbVbNTWmBi*{s_v_Ft9m2Avg!^78(QFu&n6mbRJ2bA zv!b;%yo{g*9l2)>tsZJOOp}U~8VUH`}$ z8p_}t*XIOehezolNa-a2x0BS})Y9}&*TPgua{Ewn-=wVrmJUeU39EKx+%w%=ixQWK zDLpwaNJs65#6o7Ln7~~X+p_o2BR1g~VCfxLzxA{HlWAI6^H;`juI=&r1jQrUv_q0Z z1Ja-tjdktrrP>GOC*#p?*xfQU5MqjMsBe!9lh(u8)w$e@Z|>aUHI5o;MGw*|Myiz3 z-f0;pHg~Q#%*Kx8MxH%AluVXjG2C$)WL-K63@Q`#y9_k_+}eR(x4~dp7oV-ek0H>I zgy8p#i4GN{>#v=pFYUQT(g&b$OeTy-X_#FDgNF8XyfGY6R!>inYn8IR2RDa&O!(6< znXs{W!bkP|s_YI*Yx%4stI`=ZO45IK6rBs`g7sP40ic}GZ58s?Mc$&i`kq_tfci>N zIHrC0H+Qpam1bNa=(`SRKjixBTtm&e`j9porEci!zdlg1RI0Jw#b(_Tb@RQK1Zxr_ z%7SUeH6=TrXt3J@js`4iDD0=IoHhK~I7^W8^Rcp~Yaf>2wVe|Hh1bUpX9ATD#moByY57-f2Ef1TP^lBi&p5_s7WGG9|0T}dlfxOx zXvScJO1Cnq`c`~{Dp;{;l<-KkCDE+pmexJkd}zCgE{eF=)K``-qC~IT6GcRog_)!X z?fK^F8UDz$(zFUrwuR$qro5>qqn>+Z%<5>;_*3pZ8QM|yv9CAtrAx;($>4l^_$_-L z*&?(77!-=zvnCVW&kUcZMb6;2!83si518Y%R*A3JZ8Is|kUCMu`!vxDgaWjs7^0j( ziTaS4HhQ)ldR=r)_7vYFUr%THE}cPF{0H45FJ5MQW^+W>P+eEX2kLp3zzFe*-pFVA zdDZRybv?H|>`9f$AKVjFWJ=wegO7hOOIYCtd?Vj{EYLT*^gl35|HQ`R=ti+ADm{jyQE7K@kdjuqJhWVSks>b^ zxha88-h3s;%3_5b1TqFCPTxVjvuB5U>v=HyZ$?JSk+&I%)M7KE*wOg<)1-Iy)8-K! z^XpIt|0ibmk9RtMmlUd7#Ap3Q!q9N4atQy)TmrhrFhfx1DAN`^vq@Q_SRl|V z#lU<~n67$mT)NvHh`%als+G-)x1`Y%4Bp*6Un5Ri9h=_Db zA-AdP!f>f0m@~>7X#uBM?diI@)Egjuz@jXKvm zJo+==juc9_<;CqeRaU9_Mz@;3e=E4=6TK+c`|uu#pIqhSyNm`G(X)&)B`8q0RBv#> z`gGlw(Q=1Xmf55VHj%C#^1lpc>LY8kfA@|rlC1EA<1#`iuyNO z(=;irt{_&K=i4)^x%;U(Xv<)+o=dczC5H3W~+e|f~{*ucxj@{Yi-cw^MqYr3fN zF5D+~!wd$#al?UfMnz(@K#wn`_5na@rRr8XqN@&M&FGEC@`+OEv}sI1hw>Up0qAWf zL#e4~&oM;TVfjRE+10B_gFlLEP9?Q-dARr3xi6nQqnw>k-S;~b z;!0s2VS4}W8b&pGuK=7im+t(`nz@FnT#VD|!)eQNp-W6)@>aA+j~K*H{$G`y2|QHY z|Hmy+CR@#jWY4~)lr1qBJB_RfHJFfP<}pK5(#ZZGSqcpyS&}01LnTWk5fzmXMGHkJ zTP6L^B+uj;lmB_W<~4=${+v0>z31M!-_O@o-O9GyW)j_mjx}!0@br_LE-7SIuPP84 z;5=O(U*g_um0tyG|61N@d9lEuOeiRd+#NY^{nd5;-CVlw&Ap7J?qwM^?E29wvS}2d zbzar4Fz&RSR(-|s!Z6+za&Z zY#D<5q_JUktIzvL0)yq_kLWG6DO{ri=?c!y!f(Dk%G{8)k`Gym%j#!OgXVDD3;$&v@qy#ISJfp=Vm>pls@9-mapVQChAHHd-x+OGx)(*Yr zC1qDUTZ6mM(b_hi!TuFF2k#8uI2;kD70AQ&di$L*4P*Y-@p`jdm%_c3f)XhYD^6M8&#Y$ZpzQMcR|6nsH>b=*R_Von!$BTRj7yGCXokoAQ z&ANvx0-Epw`QIEPgI(^cS2f(Y85yV@ygI{ewyv5Frng)e}KCZF7JbR(&W618_dcEh(#+^zZFY;o<815<5sOHQdeax9_!PyM&;{P zkBa5xymca0#)c#tke@3KNEM8a_mT&1gm;p&&JlMGH(cL(b)BckgMQ^9&vRwj!~3@l zY?L5}=Jzr080OGKb|y`ee(+`flQg|!lo6>=H)X4`$Gz~hLmu2a%kYW_Uu8x09Pa0J zKZ`E$BKJ=2GPj_3l*TEcZ*uYRr<*J^#5pILTT;k_cgto1ZL-%slyc16J~OH-(RgDA z%;EjEnoUkZ&acS{Q8`{i6T5^nywgqQI5bDIymoa7CSZG|WWVk>GM9)zy*bNih|QIm z%0+(Nnc*a_xo;$=!HQYaapLms>J1ToyjtFByY`C2H1wT#178#4+|{H0BBqtCdd$L% z_3Hc60j@{t9~MjM@LBalR&6@>B;9?r<7J~F+WXyYu*y3?px*=8MAK@EA+jRX8{CG?GI-< z54?Dc9CAh>QTAvyOEm0^+x;r2BWX|{3$Y7)L5l*qVE*y0`7J>l2wCmW zL1?|a`pJ-l{fb_N;R(Z9UMiSj6pQjOvQ^%DvhIJF!+Th7jO2~1f1N+(-TyCFYQZYw z4)>7caf^Ki_KJ^Zx2JUb z&$3zJy!*+rCV4%jqwyuNY3j1ZEiltS0xTzd+=itTb;IPYpaf?8Y+RSdVdpacB(bVQ zC(JupLfFp8y43%PMj2}T|VS@%LVp>hv4Y!RPMF?pp8U_$xCJ)S zQx!69>bphNTIb9yn*_yfj{N%bY)t{L1cs8<8|!f$;UQ*}IN=2<6lA;x^(`8t?;+ST zh)z4qeYYgZkIy{$4x28O-pugO&gauRh3;lti9)9Pvw+^)0!h~%m&8Q!AKX%urEMnl z?yEz?g#ODn$UM`+Q#$Q!6|zsq_`dLO5YK-6bJM6ya>}H+vnW^h?o$z;V&wvuM$dR& zeEq;uUUh$XR`TWeC$$c&Jjau2it3#%J-y}Qm>nW*s?En?R&6w@sDXMEr#8~$=b(gk zwDC3)NtAP;M2BW_lL^5ShpK$D%@|BnD{=!Tq)o(5@z3i7Z){} zGr}Exom_qDO{kAVkZ*MbLNHE666Kina#D{&>Jy%~w7yX$oj;cYCd^p9zy z8*+wgSEcj$4{WxKmCF(5o7U4jqwEvO&dm1H#7z}%VXAbW&W24v-tS6N3}qrm1OnE)fUkoE8yMMn9S$?IswS88tQWm4#Oid#ckgr6 zRtHm!mfNl-`d>O*1~d7%;~n+{Rph6BBy^95zqI{K((E!iFQ+h*C3EsbxNo_aRm5gj zKYug($r*Q#W9`p%Bf{bi6;IY0v`pB^^qu)gbg9QHQ7 zWBj(a1YSu)~2RK8Pi#C>{DMlrqFb9e_RehEHyI{n?e3vL_}L>kYJC z_ly$$)zFi*SFyNrnOt(B*7E$??s67EO%DgoZL2XNk8iVx~X_)o++4oaK1M|ou73vA0K^503j@uuVmLcHH4ya-kOIDfM%5%(E z+Xpt~#7y2!KB&)PoyCA+$~DXqxPxxALy!g-O?<9+9KTk4Pgq4AIdUkl`1<1#j^cJg zgU3`0hkHj_jxV>`Y~%LAZl^3o0}`Sm@iw7kwff{M%VwtN)|~!p{AsfA6vB5UolF~d zHWS%*uBDt<9y!9v2Xe|au&1j&iR1HXCdyCjxSgG*L{wmTD4(NQ=mFjpa~xooc6kju z`~+d{j7$h-;HAB04H!Zscu^hZffL#9!p$)9>sRI|Yovm)g@F>ZnosF2EgkU3ln0bR zTA}|+E(tt)!SG)-bEJi_0m{l+(cAz^pi}`9=~n?y&;2eG;d9{M6nj>BHGn(KA2n|O zt}$=FPq!j`p&kQ8>cirSzkU0c08%8{^Qyqi-w2LoO8)^E7;;I1;HQ6B$u0nNaX2CY zSmfi)F`m94zL8>#zu;8|{aBui@RzRKBlP1&mfFxEC@%cjl?NBs`cr^nm){>;$g?rhKr$AO&6qV_Wbn^}5tfFBry^e1`%du2~o zs$~dN;S_#%iwwA_QvmMjh%Qo?0?rR~6liyN5Xmej8(*V9ym*T`xAhHih-v$7U}8=dfXi2i*aAB!xM(Xekg*ix@r|ymDw*{*s0?dlVys2e)z62u1 z+k3esbJE=-P5S$&KdFp+2H7_2e=}OKDrf( z9-207?6$@f4m4B+9E*e((Y89!q?zH|mz_vM>kp*HGXldO0Hg#!EtFhRuOm$u8e~a9 z5(roy7m$Kh+zjW6@zw{&20u?1f2uP&boD}$#Zy)4o&T;vyBoqFiF2t;*g=|1=)PxB z8eM3Mp=l_obbc?I^xyLz?4Y1YDWPa+nm;O<$Cn;@ane616`J9OO2r=rZr{I_Kizyc zP#^^WCdIEp*()rRT+*YZK>V@^Zs=ht32x>Kwe zab)@ZEffz;VM4{XA6e421^h~`ji5r%)B{wZu#hD}f3$y@L0JV9f3g{-RK!A?vBUA}${YF(vO4)@`6f1 z-A|}e#LN{)(eXloDnX4Vs7eH|<@{r#LodP@Nz--$Dg_Par%DCpu2>2jUnqy~|J?eZ zBG4FVsz_A+ibdwv>mLp>P!(t}E>$JGaK$R~;fb{O3($y1ssQQo|5M;^JqC?7qe|hg zu0ZOqeFcp?qVn&Qu7FQJ4hcFi&|nR!*j)MF#b}QO^lN%5)4p*D^H+B){n8%VPUzi! zDihoGcP71a6!ab`l^hK&*dYrVYzJ0)#}xVrp!e;lI!+x+bfCN0KXwUAPU9@#l7@0& QuEJmfE|#`Dqx|px0L@K;Y5)KL literal 0 HcmV?d00001 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..9f4197d --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..fcb6fca --- /dev/null +++ b/gradlew @@ -0,0 +1,248 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command; +# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of +# shell script including quotes and variable substitutions, so put them in +# double quotes to make sure that they get re-expanded; and +# * put everything else in single quotes, so that it's not re-expanded. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..6689b85 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/native/build.gradle b/native/build.gradle new file mode 100644 index 0000000..c1158de --- /dev/null +++ b/native/build.gradle @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +plugins { + id 'java' + id 'checkstyle' + id 'com.github.spotbugs' +} + +description = 'Ballerina - Data.CSV Java Utils' + +dependencies { + implementation 'junit:junit:4.13.1' +// checkstyle project(':checkstyle') + checkstyle "com.puppycrawl.tools:checkstyle:${puppycrawlCheckstyleVersion}" + implementation 'org.apache.commons:commons-lang3:3.6' + + implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}" + implementation group: 'org.ballerinalang', name: 'ballerina-runtime', version: "${ballerinaLangVersion}" + implementation group: 'org.ballerinalang', name: 'value', version: "${ballerinaLangVersion}" +} + +checkstyle { +// enabled false +// toolVersion "${checkstyleToolVersion}" +// configFile rootProject.file("build-config/checkstyle/build/checkstyle.csv") +// configProperties = ["suppressionFile" : file("${rootDir}/build-config/checkstyle/build/suppressions.csv")] +} + +//checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") + +def excludePattern = '**/module-info.java' +tasks.withType(Checkstyle) { + exclude excludePattern +} + +spotbugsMain { + enabled=false + effort "max" + reportLevel "low" + reportsDir = file("$project.buildDir/reports/spotbugs") + reports { + html.enabled true + text.enabled = true + } + def excludeFile = file("${rootDir}/spotbugs-exclude.csv") + if(excludeFile.exists()) { + excludeFilter = excludeFile + } +} + +spotbugsTest { + enabled = false +} + +compileJava { + doFirst { + options.compilerArgs = [ + '--module-path', classpath.asPath, + ] + classpath = files() + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java new file mode 100644 index 0000000..7e16281 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -0,0 +1,188 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata; + +import io.ballerina.runtime.api.PredefinedTypes; +import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.creators.ErrorCreator; +import io.ballerina.runtime.api.creators.TypeCreator; +import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.types.ReferenceType; +import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.UnionType; +import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.runtime.api.values.BDecimal; +import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.values.BString; +import io.ballerina.runtime.api.values.BTypedesc; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; + +/** + * Native implementation of data:fromStringWithType(string). + * + * @since 0.1.0 + */ +public class FromString { + + private static final HashMap TYPE_PRIORITY_ORDER = new HashMap<>() {{ + int precedence = 0; + put(TypeTags.INT_TAG, precedence++); + put(TypeTags.FLOAT_TAG, precedence++); + put(TypeTags.DECIMAL_TAG, precedence++); + put(TypeTags.NULL_TAG, precedence++); + put(TypeTags.BOOLEAN_TAG, precedence++); + put(TypeTags.JSON_TAG, precedence++); + put(TypeTags.STRING_TAG, precedence); + }}; + + private static final ArrayList BASIC_JSON_MEMBER_TYPES = new ArrayList<>() {{ + add(PredefinedTypes.TYPE_NULL); + add(PredefinedTypes.TYPE_BOOLEAN); + add(PredefinedTypes.TYPE_INT); + add(PredefinedTypes.TYPE_FLOAT); + add(PredefinedTypes.TYPE_DECIMAL); + add(PredefinedTypes.TYPE_STRING); + }}; + private static final UnionType JSON_TYPE_WITH_BASIC_TYPES = TypeCreator.createUnionType(BASIC_JSON_MEMBER_TYPES); + + public static Object fromStringWithType(BString string, BTypedesc typed) { + Type expType = typed.getDescribingType(); + + try { + return fromStringWithType(string, expType); + } catch (NumberFormatException e) { + return returnError(string.getValue(), expType.toString()); + } + } + + public static Object fromStringWithType(BString string, Type expType) { + String value = string.getValue(); + try { + switch (expType.getTag()) { + case TypeTags.INT_TAG: + return stringToInt(value); + case TypeTags.FLOAT_TAG: + return stringToFloat(value); + case TypeTags.DECIMAL_TAG: + return stringToDecimal(value); + case TypeTags.STRING_TAG: + return string; + case TypeTags.BOOLEAN_TAG: + return stringToBoolean(value); + case TypeTags.NULL_TAG: + return stringToNull(value); + case TypeTags.UNION_TAG: + return stringToUnion(string, (UnionType) expType); + case TypeTags.JSON_TAG: + return stringToUnion(string, JSON_TYPE_WITH_BASIC_TYPES); + case TypeTags.TYPE_REFERENCED_TYPE_TAG: + return fromStringWithType(string, ((ReferenceType) expType).getReferredType()); + default: + return returnError(value, expType.toString()); + } + } catch (NumberFormatException e) { + return returnError(value, expType.toString()); + } + } + + private static Long stringToInt(String value) throws NumberFormatException { + return Long.parseLong(value); + } + + private static Double stringToFloat(String value) throws NumberFormatException { + if (hasFloatOrDecimalLiteralSuffix(value)) { + throw new NumberFormatException(); + } + return Double.parseDouble(value); + } + + private static BDecimal stringToDecimal(String value) throws NumberFormatException { + return ValueCreator.createDecimalValue(value); + } + + private static Object stringToBoolean(String value) throws NumberFormatException { + if ("true".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value)) { + return true; + } + + if ("false".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value)) { + return false; + } + return returnError(value, "boolean"); + } + + private static Object stringToNull(String value) throws NumberFormatException { + if ("null".equalsIgnoreCase(value) || "()".equalsIgnoreCase(value)) { + return null; + } + return returnError(value, "()"); + } + + private static Object stringToUnion(BString string, UnionType expType) throws NumberFormatException { + List memberTypes = expType.getMemberTypes(); + memberTypes.sort(Comparator.comparingInt(t -> TYPE_PRIORITY_ORDER.getOrDefault( + TypeUtils.getReferredType(t).getTag(), Integer.MAX_VALUE))); + boolean isStringExpType = false; + for (Type memberType : memberTypes) { + try { + Object result = fromStringWithType(string, memberType); + if (result instanceof BString) { + isStringExpType = true; + continue; + } else if (result instanceof BError) { + continue; + } + return result; + } catch (Exception e) { + // Skip + } + } + + if (isStringExpType) { + return string; + } + return returnError(string.getValue(), expType.toString()); + } + + private static boolean hasFloatOrDecimalLiteralSuffix(String value) { + int length = value.length(); + if (length == 0) { + return false; + } + + switch (value.charAt(length - 1)) { + case 'F': + case 'f': + case 'D': + case 'd': + return true; + default: + return false; + } + } + + private static BError returnError(String string, String expType) { + return ErrorCreator.createError(StringUtils.fromString("Cannot convert to the exptype")); + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/BallerinaByteBlockInputStream.java new file mode 100644 index 0000000..5212335 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/BallerinaByteBlockInputStream.java @@ -0,0 +1,168 @@ +///* +// * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// * +// * WSO2 LLC. licenses this file to you under the Apache License, +// * Version 2.0 (the "License"); you may not use this file except +// * in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, +// * software distributed under the License is distributed on an +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// * KIND, either express or implied. See the License for the +// * specific language governing permissions and limitations +// * under the License. +// */ +// +//package io.ballerina.stdlib.data.csvdata.csv; +// +//import io.ballerina.runtime.api.Environment; +//import io.ballerina.runtime.api.async.Callback; +//import io.ballerina.runtime.api.async.StrandMetadata; +//import io.ballerina.runtime.api.types.MethodType; +//import io.ballerina.runtime.api.types.Type; +//import io.ballerina.runtime.api.values.BArray; +//import io.ballerina.runtime.api.values.BError; +//import io.ballerina.runtime.api.values.BMap; +//import io.ballerina.runtime.api.values.BObject; +//import io.ballerina.runtime.api.values.BString; +//import io.ballerina.stdlib.data.csvdata.csv.utils.DiagnosticErrorCode; +//import io.ballerina.stdlib.data.csvdata.csv.utils.DiagnosticLog; +// +//import java.io.IOException; +//import java.io.InputStream; +//import java.util.Arrays; +//import java.util.Map; +//import java.util.concurrent.Semaphore; +//import java.util.concurrent.atomic.AtomicBoolean; +//import java.util.function.Consumer; +// +///** +// * Java Input Stream based on Ballerina byte block stream. stream +// * +// * @since 0.1.0 +// */ +//public class BallerinaByteBlockInputStream extends InputStream { +// +// private final BObject iterator; +// private final Environment env; +// private final String nextMethodName; +// private final Type returnType; +// private final String strandName; +// private final StrandMetadata metadata; +// private final Map properties; +// private final AtomicBoolean done = new AtomicBoolean(false); +// private final MethodType closeMethod; +// private final Consumer futureResultConsumer; +// +// private byte[] currentChunk = new byte[0]; +// private int nextChunkIndex = 0; +// +// public BallerinaByteBlockInputStream(Environment env, BObject iterator, MethodType nextMethod, +// MethodType closeMethod, Consumer futureResultConsumer) { +// this.env = env; +// this.iterator = iterator; +// this.nextMethodName = nextMethod.getName(); +// this.returnType = nextMethod.getReturnType(); +// this.closeMethod = closeMethod; +// this.strandName = env.getStrandName().orElse(""); +// this.metadata = env.getStrandMetadata(); +// this.properties = Map.of(); +// this.futureResultConsumer = futureResultConsumer; +// } +// +// @Override +// public int read() { +// if (done.get()) { +// return -1; +// } +// if (hasBytesInCurrentChunk()) { +// return currentChunk[nextChunkIndex++]; +// } +// // Need to get a new block from the stream, before reading again. +// nextChunkIndex = 0; +// try { +// if (readNextChunk()) { +// return read(); +// } +// } catch (InterruptedException e) { +// BError error = DiagnosticLog.error(DiagnosticErrorCode.CAN_NOT_READ_STREAM); +// futureResultConsumer.accept(error); +// return -1; +// } +// return -1; +// } +// +// @Override +// public void close() throws IOException { +// super.close(); +// Semaphore semaphore = new Semaphore(0); +// if (closeMethod != null) { +// env.getRuntime().invokeMethodAsyncSequentially(iterator, closeMethod.getName(), strandName, metadata, +// new Callback() { +// @Override +// public void notifyFailure(BError bError) { +// semaphore.release(); +// } +// +// @Override +// public void notifySuccess(Object result) { +// semaphore.release(); +// } +// }, properties, returnType); +// } +// try { +// semaphore.acquire(); +// } catch (InterruptedException e) { +// throw new IOException("Error while closing the stream", e); +// } +// } +// +// private boolean hasBytesInCurrentChunk() { +// return currentChunk.length != 0 && nextChunkIndex < currentChunk.length; +// } +// +// private boolean readNextChunk() throws InterruptedException { +// Semaphore semaphore = new Semaphore(0); +// Callback callback = new Callback() { +// +// @Override +// public void notifyFailure(BError bError) { +// // Panic with an error +// done.set(true); +// futureResultConsumer.accept(bError); +// currentChunk = new byte[0]; +// semaphore.release(); +// // TODO : Should we panic here? +// } +// +// @Override +// public void notifySuccess(Object result) { +// if (result == null) { +// done.set(true); +// currentChunk = new byte[0]; +// semaphore.release(); +// return; +// } +// if (result instanceof BMap) { +// BMap valueRecord = (BMap) result; +// final BString value = Arrays.stream(valueRecord.getKeys()).findFirst().get(); +// final BArray arrayValue = valueRecord.getArrayValue(value); +// currentChunk = arrayValue.getByteArray(); +// semaphore.release(); +// } else { +// // Case where Completes with an error +// done.set(true); +// semaphore.release(); +// } +// } +// +// }; +// env.getRuntime().invokeMethodAsyncSequentially(iterator, nextMethodName, strandName, metadata, callback, +// properties, returnType); +// semaphore.acquire(); +// return !done.get(); +// } +//} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java new file mode 100644 index 0000000..04a72e8 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -0,0 +1,244 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.csv; + +import io.ballerina.runtime.api.PredefinedTypes; +import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.types.ArrayType; +import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.RecordType; +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.values.BArray; +import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BString; +import io.ballerina.stdlib.data.csvdata.FromString; +import io.ballerina.stdlib.data.csvdata.utils.Constants; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Optional; + +/** + * Create objects for partially parsed json. + * + * @since 0.1.0 + */ +public class CsvCreator { + + static BMap initRootMapValue(Type expectedType) { + switch (expectedType.getTag()) { + case TypeTags.RECORD_TYPE_TAG: + return ValueCreator.createRecordValue((RecordType) expectedType); + case TypeTags.MAP_TAG: + return ValueCreator.createMapValue((MapType) expectedType); +// case TypeTags.JSON_TAG: +// return ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// case TypeTags.ANYDATA_TAG: +// return ValueCreator.createMapValue(Constants.ANYDATA_MAP_TYPE); + default: + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType, "map type"); + } + } + + static BArray initArrayValue(Type expectedType) { + switch (expectedType.getTag()) { + case TypeTags.TUPLE_TAG: + return ValueCreator.createTupleValue((TupleType) expectedType); + case TypeTags.ARRAY_TAG: + return ValueCreator.createArrayValue((ArrayType) expectedType); +// case TypeTags.JSON_TAG: +// return ValueCreator.createArrayValue(PredefinedTypes.TYPE_JSON_ARRAY); +// case TypeTags.ANYDATA_TAG: +// return ValueCreator.createArrayValue(PredefinedTypes.TYPE_ANYDATA_ARRAY); + default: + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType, "list type"); + } + } + +// static Optional> initNewMapValue(CsvParser.StateMachine sm) { +// sm.parserContexts.push(CsvParser.StateMachine.ParserContexts.MAP); +// Type expType = sm.expectedTypes.peek(); +// if (expType == null) { +// return Optional.empty(); +// } +// Type currentType = TypeUtils.getReferredType(expType); +// +// if (sm.currentCsvNode != null) { +// sm.nodesStack.push(sm.currentCsvNode); +// } +// +// BMap nextMapValue; +// switch (currentType.getTag()) { +// case TypeTags.RECORD_TYPE_TAG: +// RecordType recordType = (RecordType) currentType; +// nextMapValue = ValueCreator.createRecordValue(recordType); +// sm.fieldHierarchy.push(new HashMap<>(recordType.getFields())); +// sm.restType.push(recordType.getRestFieldType()); +// break; +// case TypeTags.MAP_TAG: +// nextMapValue = ValueCreator.createMapValue((MapType) currentType); +// sm.fieldHierarchy.push(new HashMap<>()); +// sm.restType.push(((MapType) currentType).getConstrainedType()); +// break; +// case TypeTags.JSON_TAG: +// nextMapValue = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// sm.fieldHierarchy.push(new HashMap<>()); +// sm.restType.push(PredefinedTypes.TYPE_JSON); +// break; +// case TypeTags.ANYDATA_TAG: +// nextMapValue = ValueCreator.createMapValue(Constants.ANYDATA_MAP_TYPE); +// sm.fieldHierarchy.push(new HashMap<>()); +// sm.restType.push(PredefinedTypes.TYPE_JSON); +// break; +// default: +// throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, getCurrentFieldPath(sm)); +// } +// +// Object currentJson = sm.currentCsvNode; +// int valueTypeTag = TypeUtils.getType(currentJson).getTag(); +// if (valueTypeTag == TypeTags.MAP_TAG || valueTypeTag == TypeTags.RECORD_TYPE_TAG) { +// ((BMap) currentJson).put(StringUtils.fromString(sm.fieldNames.get(sm.columnIndex)), nextMapValue); +// } +// return Optional.of(nextMapValue); +// } + +// static Optional initNewArrayValue(CsvParser.StateMachine sm) { +// sm.parserContexts.push(CsvParser.StateMachine.ParserContexts.ARRAY); +// Type expType = sm.expectedTypes.peek(); +// if (expType == null) { +// return Optional.empty(); +// } +// +// Object currentCsvNode = sm.currentCsvNode; +// BArray nextArrValue = initArrayValue(sm.expectedTypes.peek()); +// if (currentCsvNode == null) { +// return Optional.ofNullable(nextArrValue); +// } +// +// sm.nodesStack.push(sm.currentCsvNode); +// return Optional.ofNullable(nextArrValue); +// } + + private static String getCurrentFieldPath(CsvParser.StateMachine sm) { +// Iterator itr = sm.fieldNames.descendingIterator(); +// +// StringBuilder result = new StringBuilder(itr.hasNext() ? itr.next() : ""); +// while (itr.hasNext()) { +// result.append(".").append(itr.next()); +// } +// return result.toString(); + return "Test"; + } + + static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, BString value, Type type) { + Object currentJson = sm.currentCsvNode; + Object convertedValue = convertToExpectedType(value, type); + if (convertedValue instanceof BError) { + if (sm.currentField != null) { + throw DiagnosticLog.error(DiagnosticErrorCode.CSV_PARSER_EXCEPTION, value, type, + getCurrentFieldPath(sm)); + } + throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, type, value); + } + + Type currentCsvNodeType = TypeUtils.getType(currentJson); + switch (currentCsvNodeType.getTag()) { + case TypeTags.MAP_TAG: + case TypeTags.RECORD_TYPE_TAG: + ((BMap) currentJson).put(StringUtils.fromString(sm.headers.get(sm.columnIndex)), + convertedValue); + return currentJson; + case TypeTags.ARRAY_TAG: + // Handle projection in array. + ArrayType arrayType = (ArrayType) currentCsvNodeType; + if (arrayType.getState() == ArrayType.ArrayState.CLOSED && + arrayType.getSize() - 1 < sm.columnIndex) { + return currentJson; + } + ((BArray) currentJson).add(sm.columnIndex, convertedValue); + return currentJson; + case TypeTags.TUPLE_TAG: + ((BArray) currentJson).add(sm.columnIndex, convertedValue); + return currentJson; + default: + return convertedValue; + } + } + + private static Object convertToExpectedType(BString value, Type type) { + if (type.getTag() == TypeTags.ANYDATA_TAG) { + return FromString.fromStringWithType(value, PredefinedTypes.TYPE_JSON); + } + return FromString.fromStringWithType(value, type); + } + + static void updateRecordFieldValue(BString fieldName, Object parent, Object currentJson) { + switch (TypeUtils.getType(parent).getTag()) { + case TypeTags.MAP_TAG: + case TypeTags.RECORD_TYPE_TAG: + ((BMap) parent).put(fieldName, currentJson); + break; + } + } + + static Type getMemberType(Type expectedType, int index) { + if (expectedType == null) { + return null; + } + + if (expectedType.getTag() == TypeTags.ARRAY_TAG) { + return ((ArrayType) expectedType).getElementType(); + } else if (expectedType.getTag() == TypeTags.TUPLE_TAG) { + TupleType tupleType = (TupleType) expectedType; + List tupleTypes = tupleType.getTupleTypes(); + if (tupleTypes.size() < index + 1) { + return tupleType.getRestType(); + } + return tupleTypes.get(index); + } else { + return expectedType; + } + } + + static void validateListSize(int currentIndex, Type expType) { + int expLength = 0; + if (expType == null) { + return; + } + + if (expType.getTag() == TypeTags.ARRAY_TAG) { + expLength = ((ArrayType) expType).getSize(); + } else if (expType.getTag() == TypeTags.TUPLE_TAG) { + TupleType tupleType = (TupleType) expType; + expLength = tupleType.getTupleTypes().size(); + } + + if (expLength >= 0 && expLength > currentIndex + 1) { + throw DiagnosticLog.error(DiagnosticErrorCode.ARRAY_SIZE_MISMATCH); + } + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java new file mode 100644 index 0000000..7217b23 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -0,0 +1,545 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.csv; + +import io.ballerina.runtime.api.PredefinedTypes; +import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.flags.SymbolFlags; +import io.ballerina.runtime.api.types.*; +import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.runtime.api.values.BArray; +import io.ballerina.runtime.api.values.BError; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; + +import java.io.IOException; +import java.io.Reader; +import java.util.*; + +/** + * Convert Csv string to a ballerina record. + * + * @since 0.1.0 + */ +public class CsvParser { + private static final char CR = 0x000D; + private static final char NEWLINE = 0x000A; + private static final char HZ_TAB = 0x0009; + private static final char SPACE = 0x0020; + private static final char BACKSPACE = 0x0008; + private static final char FORMFEED = 0x000C; + private static final char QUOTES = '"'; + private static final char REV_SOL = '\\'; + private static final char SOL = '/'; + private static final char EOF = (char) -1; + + + private static final ThreadLocal tlStateMachine = ThreadLocal.withInitial(StateMachine::new); + + public static Object parse(Reader reader, Type type) + throws BError { + StateMachine sm = tlStateMachine.get(); + try { + return sm.execute(reader, TypeUtils.getReferredType(type)); + } finally { + // Need to reset the state machine before leaving. Otherwise, references to the created + // JSON values will be maintained and the java GC will not happen properly. + sm.reset(); + } + } + + static class StateMachine { + private static State HEADER_START_STATE = new HeaderStartState(); + private static State HEADER_ELEMENT_START_STATE = new HeaderElementStartState(); + private static State HEADER_ELEMENT_END_STATE = new HeaderElementEndState(); + private static State HEADER_END_STATE = new HeaderEndState(); + private static State ROW_START_STATE = new RowStartState(); + private static State ROW_END_STATE = new RowEndState(); + private static State STRING_COLUMN_START_STATE = new StringColumnStartState(); + private static State STRING_COLUMN_END_STATE = new StringColumnEndState(); + private static State NON_STRING_COLUMN_START_STATE = new NonStringColumnStartState(); + private static State NON_STRING_COLUMN_END_STATE = new NonStringColumnEndState(); + private static State MAP_START_STATE = new MapStartState(); + private static State MAP_END_STATE = new MapEndState(); + + private static String lineBreak = "\n"; + + Object currentCsvNode; + Object currentRow; + ArrayList headers = new ArrayList<>(); + BArray rootCsvNode; + Deque nodesStack; + // TODO: Need group same level field and keep the hierarchy. + ArrayList fieldNames; + + private StringBuilder hexBuilder = new StringBuilder(4); + private char[] charBuff = new char[1024]; + private int charBuffIndex; + + private int index; + private int line; + private int column; + private char currentQuoteChar; + Field currentField; + Map fieldHierarchy = new HashMap<>(); + Stack restType = new Stack<>(); + Stack expectedTypes = new Stack<>(); + int csvFieldDepth = 0; + Stack arrayIndexes = new Stack<>(); + Stack parserContexts = new Stack<>(); + Type expectedArrayElementType; + int columnIndex = 0; + int rowIndex = 0; + + StateMachine() { + reset(); + } + + public enum ParserContexts { + MAP, + ARRAY + } + + public void reset() { + index = 0; + currentCsvNode = null; + line = 1; + column = 0; + nodesStack = new ArrayDeque<>(); + fieldNames = new ArrayList<>(); + fieldHierarchy.clear(); + currentField = null; + restType.clear(); + expectedTypes.clear(); + csvFieldDepth = 0; + rootCsvNode = null; + columnIndex = 0; + rowIndex = 0; + } + + private static boolean isWhitespace(char ch) { + return ch == SPACE || ch == HZ_TAB || ch == CR; + } + + private static void throwExpected(String... chars) throws CsvParserException { + throw new CsvParserException("expected '" + String.join("' or '", chars) + "'"); + } + + private void processLocation(char ch) { + if (ch == '\n') { + this.line++; + this.column = 0; + } else { + this.column++; + } + } + + private String value() { + String result = new String(this.charBuff, 0, this.charBuffIndex); + this.charBuffIndex = 0; + return result; + } + + public Object execute(Reader reader, Type type) throws BError { + Type referredType = TypeUtils.getReferredType(type); + if (referredType.getTag() != TypeTags.ARRAY_TAG) { + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); + } else { + rootCsvNode = ValueCreator.createArrayValue((ArrayType) type); + expectedArrayElementType = ((ArrayType) TypeUtils.getReferredType(referredType)).getElementType(); + } + switch (expectedArrayElementType.getTag()) { + // TODO: Handle readonly and singleton type as expType. + case TypeTags.RECORD_TYPE_TAG: + RecordType recordType = (RecordType) expectedArrayElementType; + expectedTypes.push(recordType); + restType.push(recordType.getRestFieldType()); + fieldHierarchy = recordType.getFields(); + break; + case TypeTags.MAP_TAG: + expectedTypes.push(expectedArrayElementType); + break; + case TypeTags.ARRAY_TAG: + case TypeTags.TUPLE_TAG: + expectedTypes.push(expectedArrayElementType); + arrayIndexes.push(0); + break; + // TODO: Check to add Union types as well + default: + throw DiagnosticLog.error(DiagnosticErrorCode.CSV_PARSER_EXCEPTION); + } + boolean header = true; + State currentState; + if (header) { + currentState = HEADER_START_STATE; + } else { + currentState = ROW_START_STATE; + } + try { + char[] buff = new char[1024]; + int count; + while ((count = reader.read(buff)) > 0) { + this.index = 0; + while (this.index < count) { + currentState = currentState.transition(this, buff, this.index, count); + } + } + return rootCsvNode; + } catch (IOException e) { + throw DiagnosticLog.error(DiagnosticErrorCode.CSV_PARSER_EXCEPTION, e.getMessage()); + } catch (CsvParserException e) { + throw DiagnosticLog.error(DiagnosticErrorCode.CSV_PARSER_EXCEPTION, e.getMessage(), line, column); + } + } + + private boolean isSupportedUnionType(UnionType type) { + boolean isContainUnsupportedMember = false; + for (Type memberType : type.getMemberTypes()) { + switch (memberType.getTag()) { + case TypeTags.RECORD_TYPE_TAG: + case TypeTags.OBJECT_TYPE_TAG: + case TypeTags.MAP_TAG: + case TypeTags.JSON_TAG: + case TypeTags.ANYDATA_TAG: + isContainUnsupportedMember = true; + break; + case TypeTags.UNION_TAG: + isContainUnsupportedMember = isSupportedUnionType(type); + break; + } + } + return !isContainUnsupportedMember; + } + + private void append(char ch) { + try { + this.charBuff[this.charBuffIndex] = ch; + this.charBuffIndex++; + } catch (ArrayIndexOutOfBoundsException e) { + /* this approach is faster than checking for the size by ourself */ + this.growCharBuff(); + this.charBuff[this.charBuffIndex++] = ch; + } + } + + private boolean isEndOftheRow(char ch) { + return ch == NEWLINE || ch == EOF; + } + + private void growCharBuff() { + char[] newBuff = new char[charBuff.length * 2]; + System.arraycopy(this.charBuff, 0, newBuff, 0, this.charBuff.length); + this.charBuff = newBuff; + } + + /** + * A specific state in the Csv parsing state machine. + */ + interface State { + State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException; + } + + private static class HeaderStartState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + char ch; + State state = HEADER_START_STATE; + //TODO: Add separator here + //TODO: If the header is not present make the headers and fieldnames to be default values + char separator = ','; + for (; i < count; i++) { + ch = buff[i]; + sm.processLocation(ch); + if (ch == separator) { + addHeader(sm.headers, sm.value(), sm.expectedTypes.peek()); + sm.columnIndex++; + } else if (sm.isEndOftheRow(ch)) { + addHeader(sm.headers, sm.value(), sm.expectedTypes.peek()); + finalizeHeaders(sm); +// state = HEADER_END_STATE; + sm.columnIndex = 0; + state = ROW_START_STATE; + } else if (StateMachine.isWhitespace(ch)) { + state = this; + continue; +// } else if (ch == EOF) { +// throw new CsvParserException("Unexpected Header"); + } else { + sm.append(ch); + state = this; + continue; + } + break; + } + sm.index = i + 1; + return state; + } + + private void finalizeHeaders(StateMachine sm) throws CsvParserException { + Type expType = sm.expectedArrayElementType; + if (expType instanceof RecordType) { + RecordType recordType = ((RecordType) expType); + if (recordType.getRestFieldType() == null) { + for (Field field : recordType.getFields().values()) { + if (!sm.headers.contains(field.getFieldName())) { + if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { + throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, field.getFieldName()); + } + } + } + } + } else if (expType instanceof ArrayType) { + // TODO: Get the other validation into here + ArrayType arrayType = (ArrayType) expType; + int size = arrayType.getSize(); + //TODO: Replace arraysize -1 with + if (size != -1 && size > sm.headers.size()) { + // TODO: Can remove using fillers + throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, "Test"); + } + } else if (expType instanceof MapType) { + //ignore + } else if (expType instanceof TupleType) { + TupleType tupleType = (TupleType) expType; + if (tupleType.getRestType() != null && tupleType.getTupleTypes().size() > sm.headers.size()) { + // TODO: Can remove using fillers + throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, "Test"); + } + } else { + throw new CsvParserException("Invalid expected type"); + } + } + + private void addHeader(ArrayList headers, String value, Type expectedType) throws CsvParserException { + if (expectedType instanceof RecordType) { + RecordType recordType = (RecordType) expectedType; + Type restType = recordType.getRestFieldType(); + if (restType != null && restType.getTag() != TypeTags.ANYDATA_TAG && !recordType.getFields().containsKey(StringUtils.fromString(value))) { + throw new CsvParserException("Invalid header name"); + } + } + headers.add(value); + } + } + + private static class HeaderElementStartState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + return null; + } + } + + private static class HeaderElementEndState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + return null; + } + } + + private static class HeaderEndState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + return null; + } + } + + private static class RowStartState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + char ch; + State state; + //TODO: Add separator here + char separator = ','; + + // TODO: Ignore this in future + sm.columnIndex = 0; + for (; i < count; i++) { + ch = buff[i]; + sm.processLocation(ch); + //TODO: Handle empty values and create again and again + if (sm.currentCsvNode == null) { + initiateNewRowType(sm); + } + if (ch == separator) { + addRowValue(sm); + sm.columnIndex++; + } else if (sm.isEndOftheRow(ch)) { + addRowValue(sm); + finalizeTheRow(sm); + sm.columnIndex = 0; + sm.currentCsvNode = null; + } else if (StateMachine.isWhitespace(ch)) { + // ignore + } else if (ch == EOF) { + throw new CsvParserException("Unexpected Header"); + } else { + sm.append(ch); + } + } + if (!isWhitespace(buff[i]) || buff[i] != separator) { + addRowValue(sm); + finalizeTheRow(sm); + sm.currentCsvNode = null; + } + sm.index = i + 1; + state = ROW_END_STATE; + return state; + } + + private void initiateNewRowType(StateMachine sm) throws CsvParserException { + sm.currentCsvNode = createRowType(sm.expectedTypes.peek()); + } + + private void finalizeTheRow(StateMachine sm) { + int rootArraySize = ((ArrayType)(sm.rootCsvNode.getType())).getSize(); + if (rootArraySize == -1 || sm.rowIndex < rootArraySize) { + sm.rootCsvNode.add(sm.rowIndex, sm.currentCsvNode); + sm.rowIndex++; + } + } + + private Object createRowType(Type expectedType) throws CsvParserException { + if (expectedType instanceof RecordType || expectedType instanceof MapType) { + return CsvCreator.initRootMapValue(expectedType); + } else if (expectedType instanceof ArrayType || expectedType instanceof TupleType) { + return CsvCreator.initArrayValue(expectedType); + } + throw new CsvParserException("Unexpected expected type"); + } + + private void addRowValue(StateMachine sm) throws CsvParserException { + // TODO: Can convert all at once by storing in a Object[] + Type type; + Type exptype = sm.expectedTypes.peek(); + if (exptype instanceof RecordType) { + // TODO: These can be make as module level variables + RecordType recordType = ((RecordType) exptype); + Map fields = recordType.getFields(); + Type restType = recordType.getRestFieldType(); + String header = sm.headers.get(sm.columnIndex); + if (fields.containsKey(header)) { + //TODO: Optimize + type = fields.get(header).getFieldType(); + } else { + if (restType != null) { + type = restType; + } else { + sm.charBuffIndex = 0; + return; + } + } + } else if (exptype instanceof MapType) { + MapType mapType = ((MapType) exptype); + type = mapType.getConstrainedType(); + } else if (exptype instanceof ArrayType) { + ArrayType arrayType = (ArrayType) exptype; + // TODO: add to a constant + if (arrayType.getSize() != -1 && arrayType.getSize() < sm.columnIndex) { + sm.charBuffIndex = 0; +// throw new CsvParserException("Unexpected Row count"); + return; + } + type = arrayType.getElementType(); + } else if (exptype instanceof TupleType) { + TupleType tupleType = (TupleType) exptype; + List tupleTypes = tupleType.getTupleTypes(); + Type restType = tupleType.getRestType(); + if (tupleTypes.size() > sm.columnIndex) { + type = tupleTypes.get(sm.columnIndex); + } else { + if (restType != null) { + type = restType; + } else { + sm.charBuffIndex = 0; + return; + } + } + } else { + throw new CsvParserException("Unexpected expected type"); + } + CsvCreator.convertAndUpdateCurrentJsonNode(sm, StringUtils.fromString(sm.value()), type); + } + } + + + + private static class RowEndState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + char ch; + State state = ROW_END_STATE; + for (; i < count; i++) { + + } + sm.index = i + 1; + return state; + } + } + + private static class StringColumnStartState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + return null; + } + } + + private static class StringColumnEndState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + return null; + } + } + + private static class NonStringColumnStartState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + return null; + } + } + + private static class NonStringColumnEndState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + return null; + } + } + + private static class MapStartState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + return null; + } + } + + private static class MapEndState implements State { + @Override + public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { + return null; + } + } + + public static class CsvParserException extends Exception { + public CsvParserException(String msg) { + super(msg); + } + } + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java new file mode 100644 index 0000000..aa851d6 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -0,0 +1,530 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.csv; + +import io.ballerina.runtime.api.PredefinedTypes; +import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.flags.SymbolFlags; +import io.ballerina.runtime.api.types.*; +import io.ballerina.runtime.api.utils.JsonUtils; +import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.values.*; +import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; + +import java.util.*; + +/** + * Convert Csv value to a ballerina record. + * + * @since 0.1.0 + */ +public class CsvTraversal { + private static final ThreadLocal tlCsvTree = ThreadLocal.withInitial(CsvTree::new); + public static Object traverse(BArray csv, BMap config, Type type) { + CsvTree csvTree = tlCsvTree.get(); + try { + return csvTree.traverseCsv(csv, config, type); + } catch (BError e) { + return e; + } finally { + csvTree.reset(); + } + } + + static class CsvTree { + Object currentCsvNode; + Field currentField; + Stack> fieldHierarchy = new Stack<>(); + Stack restType = new Stack<>(); + Deque nodesStack = new ArrayDeque<>(); + Deque fieldNames = new ArrayDeque<>(); + BArray rootCsvNode; + + Type rootArray; + Type expectedArrayElementType; + Type sourceArrayElementType; + + BMap config; + + void reset() { + currentCsvNode = null; + currentField = null; + fieldHierarchy.clear(); + restType.clear(); + nodesStack.clear(); + fieldNames.clear(); + expectedArrayElementType = null; + sourceArrayElementType = null; + } + + @SuppressWarnings("unchecked") + public Object traverseCsv(BArray csv, BMap config, Type type) { + Type referredType = TypeUtils.getReferredType(type); + // TODO: add root level node configurations + if (referredType.getTag() != TypeTags.ARRAY_TAG) { + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); + } else { + rootCsvNode = ValueCreator.createArrayValue((ArrayType) referredType); + expectedArrayElementType = ((ArrayType) TypeUtils.getReferredType(referredType)).getElementType(); + } + // TODO: Handle the array size count + sourceArrayElementType = csv.getElementType(); + int expectedArraySize = ((ArrayType) referredType).getSize(); + long sourceArraySize = csv.getLength(); + if (expectedArraySize > sourceArraySize) { + throw DiagnosticLog.error(DiagnosticErrorCode.ARRAY_SIZE_MISMATCH); + } + if (TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.UNION_TAG) { + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA); + } + this.config = config; + if (TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.RECORD_TYPE_TAG + || TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.TABLE_TAG + || TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.MAP_TAG) { + traverseCsvArrayMembersWithMapAsCsvElementType(expectedArraySize == -1 ? sourceArraySize : expectedArraySize, csv, expectedArrayElementType); + } else if (TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.ARRAY_TAG + || TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.TUPLE_TAG) { + //TODO:Handle tuples + traverseCsvArrayMembersWithArrayAsCsvElementType(expectedArraySize == -1 ? sourceArraySize : expectedArraySize, csv, expectedArrayElementType); + } + return rootCsvNode; + } + + public void traverseCsvArrayMembersWithMapAsCsvElementType(long length, BArray csv, Type expectedArrayType) { + // todo once checked, way to find a optimize a way to save and reuse + for (int i = 0; i < length; i++) { + rootCsvNode.append(traverseCsvElementWithMapOrRecord(csv.get(i), expectedArrayType)); + } + } + + public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray csv, Type expectedArrayType) { + for (int i = 0; i < length; i++) { + rootCsvNode.append(traverseCsvElementWithArray(csv.get(i), expectedArrayType)); + } + } + + public Object traverseCsvElementWithArray(Object csvElement, Type expectedType) { + BArray csvMember; + switch (expectedType.getTag()) { + case TypeTags.ARRAY_TAG: + // TODO: Do the array Check on the top since this is calling again and again + csvMember = ValueCreator.createArrayValue((ArrayType) TypeUtils.getReferredType(expectedType)); + traverseArrayValue(csvElement, csvMember, false); + return csvMember; + case TypeTags.TUPLE_TAG: + // TODO: Do the array Check on the top since this is calling again and again + csvMember = ValueCreator.createTupleValue((TupleType) TypeUtils.getReferredType(expectedType)); + traverseArrayValue(csvElement, csvMember, true); + return csvMember; + } + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType, PredefinedTypes.TYPE_ANYDATA); + } + + private void traverseArrayValue(Object csvElement, BArray csvMember, boolean tuple) { + Type arrayMemberType = csvMember.getType(); + if (csvElement instanceof BMap) { + constructArrayValuesFromMap(csvMember, (BMap) csvElement, arrayMemberType); + } else if (csvElement instanceof BArray) { + constructArrayValuesFromArray(csvMember, (BArray) csvElement, arrayMemberType); + } + } + + private void constructArrayValuesFromArray(BArray csvMember, BArray csvElement, Type arrayType) { + int index = 0; + int expectedTypeSize = getTheActualExpectedType(csvMember); + int expectedSize = expectedTypeSize == -1 ? csvElement.size() : expectedTypeSize; + for (int i = 0; i < csvElement.getLength(); i++) { + if (index >= expectedSize) { + break; + } + addValuesToArrayType(csvElement.get(i), csvMember, getArrayOrTupleMemberType(arrayType, index), index); + index++; + } + } + + private void constructArrayValuesFromMap(BArray csvMember, BMap map, Type arrayType) { + // TODO: This and above method can be merge + int index = 0; + int expectedTypeSize = getTheActualExpectedType(csvMember); + int expectedSize = expectedTypeSize == -1 ? map.size() : expectedTypeSize; + for (Object v: map.values()) { + if (index >= expectedSize) { + break; + } + addValuesToArrayType(v, csvMember, getArrayOrTupleMemberType(arrayType, index), index); + index++; + } + } + + private int getTheActualExpectedType(BArray csvMember) { + Type type = csvMember.getType(); + if (type instanceof TupleType) { + return ((TupleType) csvMember.getType()).getTupleTypes().size(); + } else { + return ((ArrayType) csvMember.getType()).getSize(); + } + } + + private Type getArrayOrTupleMemberType(Type type, int index) { + if (type instanceof TupleType) { + TupleType tupleType = (TupleType) type; + List tupleTypes = tupleType.getTupleTypes(); + if (tupleTypes.size() >= index + 1) { + return tupleTypes.get(index); + } + Type tupleRestType = tupleType.getRestType(); + if (tupleRestType != null) { + return tupleRestType; + } + return null; + } + return ((ArrayType) type).getElementType(); + } + + private void addValuesToArrayType(Object csvElement, BArray csvMember, Type arrayElementType, int index) { + switch (arrayElementType.getTag()) { + case TypeTags.NULL_TAG: + case TypeTags.BOOLEAN_TAG: + case TypeTags.INT_TAG: + case TypeTags.FLOAT_TAG: + case TypeTags.DECIMAL_TAG: + case TypeTags.STRING_TAG: + case TypeTags.XML_TAG: + csvMember.add(index, convertToBasicType(csvElement, arrayElementType)); + break; + default: + DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, arrayElementType, PredefinedTypes.TYPE_ANYDATA); + } + } + + public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expectedType) { + switch (expectedType.getTag()) { + case TypeTags.RECORD_TYPE_TAG: + traverseCsvElementWithRecordAsExpectedType(csvElement, expectedType); + break; + case TypeTags.MAP_TAG: + traverseCsvElementWithMapAsExpectedType(csvElement, expectedType); + break; + case TypeTags.TABLE_TAG: + //TODO: Check + traverseCsvElementWithMapAsExpectedType(csvElement, expectedType); + break; + case TypeTags.ARRAY_TAG: + ArrayType arrayType = (ArrayType) expectedType; + int arrayElementTypeTag = arrayType.getElementType().getTag(); + // TODO: Only allow string[] + if (arrayElementTypeTag != TypeTags.STRING_TAG) { + DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, + expectedType, PredefinedTypes.TYPE_ANYDATA_ARRAY); + } + traverseCsvElementWithArrayAsExpectedType(csvElement,expectedType, arrayType); + break; + default: + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType, PredefinedTypes.TYPE_ANYDATA); + } + return currentCsvNode; + } + + public void traverseCsvElementWithRecordAsExpectedType(Object csvElement, Type expectedType) { + RecordType recordType = (RecordType) expectedType; + this.fieldHierarchy.push(new HashMap<>(recordType.getFields())); + this.restType.push(recordType.getRestFieldType()); + currentCsvNode = ValueCreator.createRecordValue(recordType); + nodesStack.push(currentCsvNode); + traverseCsvMap(csvElement, expectedType, false); + } + + public void traverseCsvElementWithMapAsExpectedType(Object csvElement, Type expectedType) { + MapType mapType = (MapType) expectedType; + this.fieldHierarchy.push(new HashMap<>()); + currentCsvNode = ValueCreator.createMapValue(mapType); + nodesStack.push(currentCsvNode); + traverseCsvMap(csvElement, expectedType, true); + } + + public void traverseCsvElementWithArrayAsExpectedType(Object csvElement, Type expectedType, ArrayType arrayType) { + // todo Check sizes abnd log errors + rootArray = expectedType; + currentCsvNode = ValueCreator.createArrayValue(arrayType); + nodesStack.push(currentCsvNode); + traverseCsvElementWithArray(csvElement, expectedType); + } + + private void traverseCsvMap(Object csvElement, Type expectedType, boolean mappingType) { + Object parentJsonNode = nodesStack.peek(); + if (csvElement instanceof BMap map) { + traverseMapValueWithMapAsExpectedType(map, parentJsonNode, mappingType); + } else if (csvElement instanceof BArray) { + traverseArrayValueWithMapAsExpectedType((BArray) csvElement, parentJsonNode, mappingType, expectedType); + } else { + if (fieldNames.isEmpty()) { + throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, expectedType, csvElement); + } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, "Test"); + } + nodesStack.pop(); + } + + private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, String[] headers, BArray csvElement, int arraySize) { + if (arraySize < headers.length) { + return false; + } + if (expectedType instanceof MapType) { + return true; + } + Type type = csvElement.getType(); + if (type instanceof TupleType) { + return checkExpectedTypeMatchWithHeadersForTuple(expectedType, headers, (TupleType) type, arraySize); + } else { + return checkExpectedTypeMatchWithHeadersForArray(expectedType, headers, csvElement.getElementType(), arraySize); + } + } + + private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, String[] headers, TupleType tupleType, int arraySize) { + List tupleTypes = tupleType.getTupleTypes(); + Type restType = tupleType.getRestType(); + + if (expectedType instanceof RecordType) { + RecordType recordType = (RecordType) expectedType; + Type restFieldType = recordType.getRestFieldType(); + if (restFieldType != null && restFieldType.getTag() == TypeTags.ANYDATA_TAG) { + return true; + } + Map fields = recordType.getFields(); + boolean isCompatible = true; + for (Type type: tupleTypes) { + //TODO: optimize + for (Field field: fields.values()) { + if (field.getFieldType().getTag() == type.getTag()) { + fields.values().remove(field.getFieldType()); + continue; + } + if (type == restFieldType) { + continue; + } + break; + } + } + if (restType != null && restType != restFieldType) { + return false; + } + } + return false; + } + + private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, String[] headers, Type arrayType, int arraySize) { + arrayType = TypeUtils.getReferredType(arrayType); + if (expectedType instanceof RecordType) { + RecordType recordType = (RecordType) expectedType; + Type restFieldType = recordType.getRestFieldType(); + if (restFieldType != null && (restFieldType == arrayType + || restFieldType.getTag() == TypeTags.ANYDATA_TAG)) { + return true; + } + Set fields = recordType.getFields().keySet(); + for (int i = 0; i < headers.length; i++) { + if (!fields.contains(headers[i])) { + return false; + } + } + } + return false; + } + + private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, Object parent, boolean mappingType, Type expectedType) { + Type fieldType; + BString key; + int arraySize = csvElement.size(); + String[] headers = new String[arraySize]; + //TODO: Update this, set Default headers to field Hierachy + boolean defaultHeaders = true; + for (int i = 0; i < arraySize; i++) { + headers[i] = String.valueOf( i + 1); + } + boolean conversion = checkExpectedTypeMatchWithHeaders(expectedType, headers, csvElement, arraySize); + if (!conversion) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, headers.toString(), + csvElement.toString(), "Test"); + } + // TODO: Add headers from config + for(int i = 1; i <= arraySize; i++) { + key = StringUtils.fromString(String.valueOf(i)); + if (!mappingType) { + if (!isKeyBelongsToNonRestType(csvElement.get(i-1), key)) { + continue; + } + fieldType = TypeUtils.getReferredType(currentField.getFieldType()); + } else { + addFieldInMapType(key); + fieldType = ((MapType) expectedType).getConstrainedType();; + } + addCurrentFieldValue(fieldType, csvElement.get(i - 1), key, parent); + } + Map currentField = fieldHierarchy.pop(); + checkOptionalFieldsAndLogError(currentField); + if (!mappingType) { + restType.pop(); + } + } + + private void traverseMapValueWithMapAsExpectedType(BMap map, Object parent, boolean mappingType) { + Type currentFieldType; + for (BString key : map.getKeys()) { + if (!mappingType) { +// if (!isKeyBelongsToNonRestType(map, key)) { + if (!isKeyBelongsToNonRestType(map.get(key), key)) { + continue; + } + currentFieldType = TypeUtils.getReferredType(currentField.getFieldType()); + } else { + addFieldInMapType(key); + currentFieldType = TypeUtils.getReferredType(((MapType) ((BMap) parent).getType()).getConstrainedType()); + } + addCurrentFieldValue(currentFieldType, map.get(key), key, parent); + } + Map currentField = fieldHierarchy.pop(); + checkOptionalFieldsAndLogError(currentField); + if (!mappingType) { + restType.pop(); + } + } + + private boolean isKeyBelongsToNonRestType(Object value, BString key) { + currentField = fieldHierarchy.peek().remove(key.toString()); + if (currentField == null) { + // Add to the rest field + if (restType.peek() != null) { + Type restFieldType = TypeUtils.getReferredType(restType.peek()); + addRestField(restFieldType, key, value); + } + return false; + } + fieldNames.push(currentField.getFieldName()); + return true; + } + + private void addFieldInMapType(BString key) { + fieldNames.push(key.toString()); + } + + private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BString key, Object parent) { + int currentFieldTypeTag = currentFieldType.getTag(); + + switch (currentFieldTypeTag) { + case TypeTags.MAP_TAG: + // TODO: Check + if (!checkTypeCompatibility(((MapType) currentFieldType).getConstrainedType(), mapValue)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, + currentFieldType, "Test"); + } + ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), + mapValue); + break; + case TypeTags.NULL_TAG: + case TypeTags.BOOLEAN_TAG: + case TypeTags.INT_TAG: + case TypeTags.FLOAT_TAG: + case TypeTags.DECIMAL_TAG: + case TypeTags.STRING_TAG: + Object value = convertToBasicType(mapValue, currentFieldType); + ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), value); + break; + default: + //TODO: Check for Arrays + currentCsvNode = traverseCsvElementWithMapOrRecord(mapValue, currentFieldType); + ((BMap) parent).put(key, currentCsvNode); + currentCsvNode = parent; + } + } + + private void addRestField(Type restFieldType, BString key, Object csvMember) { + switch (restFieldType.getTag()) { + case TypeTags.ANYDATA_TAG: + case TypeTags.JSON_TAG: + ((BMap) currentCsvNode).put(key, csvMember); + break; + case TypeTags.BOOLEAN_TAG: + case TypeTags.INT_TAG: + case TypeTags.FLOAT_TAG: + case TypeTags.DECIMAL_TAG: + case TypeTags.STRING_TAG: + if (checkTypeCompatibility(restFieldType, csvMember)) { + ((BMap) currentCsvNode).put(key, csvMember); + } + break; + } + } + + private boolean checkTypeCompatibility(Type constraintType, Object csv) { + if (csv instanceof BMap) { + BMap map = (BMap) csv; + for (BString key : map.getKeys()) { + if (!checkTypeCompatibility(constraintType, map.get(key))) { + return false; + } + } + return true; + } else if ((csv instanceof BString && constraintType.getTag() == TypeTags.STRING_TAG) + || (csv instanceof Long && constraintType.getTag() == TypeTags.INT_TAG) + || (csv instanceof Double && (constraintType.getTag() == TypeTags.FLOAT_TAG + || constraintType.getTag() == TypeTags.DECIMAL_TAG)) + || (Boolean.class.isInstance(csv) && constraintType.getTag() == TypeTags.BOOLEAN_TAG) + || (csv == null && constraintType.getTag() == TypeTags.NULL_TAG)) { + return true; + } else { + return false; + } + } + + private void checkOptionalFieldsAndLogError(Map currentField) { + currentField.values().forEach(field -> { + if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { + throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, field.getFieldName()); + } + // TODO: Handle this properly + if (!(SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED) && + SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL))) { + throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, field.getFieldName()); + } + }); + } + + private Object convertToBasicType(Object json, Type targetType) { + if (targetType.getTag() == TypeTags.READONLY_TAG) { + return json; + } + try { + Object value = JsonUtils.convertJSON(json, targetType); + if (value instanceof String) { + return StringUtils.fromString(value.toString()); + } + return value; + } catch (Exception e) { + if (fieldNames.isEmpty()) { + throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, targetType, json); + } + throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, json, targetType, + "Test"); + } + } + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java new file mode 100644 index 0000000..b739f49 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.csv; + +import io.ballerina.runtime.api.Environment; +import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.values.*; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; + +import java.io.StringReader; + +/** + * Csv conversion. + * + * @since 0.1.0 + */ +public class Native { + + public static Object fromCsvWithType(BArray csv, BMap config, BTypedesc type) { + try { + return CsvTraversal.traverse(csv, config, type.getDescribingType()); + } catch (Exception e) { + return DiagnosticLog.getCsvError(e.getMessage()); + } + } + + public static Object fromCsvStringWithType(Object csv, BMap config, BTypedesc type) { + try { + Type expType = type.getDescribingType(); + if (csv instanceof BString) { + Object a = CsvParser.parse(new StringReader(((BString) csv).getValue()), expType); + return a; + } + } catch (BError e) { + return e; + } catch (Exception e) { + return e; + } + return null; + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QualifiedName.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QualifiedName.java new file mode 100644 index 0000000..6173b6b --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QualifiedName.java @@ -0,0 +1,83 @@ +///* +// * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// * +// * WSO2 LLC. licenses this file to you under the Apache License, +// * Version 2.0 (the "License"); you may not use this file except +// * in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, +// * software distributed under the License is distributed on an +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// * KIND, either express or implied. See the License for the +// * specific language governing permissions and limitations +// * under the License. +// */ +// +//package io.ballerina.stdlib.data.csvdata.csv; +// +///** +// * Represents a qualified name. +// * +// * @since 0.1.0 +// */ +//public class QualifiedName { +// public static final String NS_ANNOT_NOT_DEFINED = "$$ns_annot_not_defined$$"; +// private String localPart; +// private String namespaceURI; +// private String prefix; +// +// public QualifiedName(String namespaceURI, String localPart, String prefix) { +// this.localPart = localPart; +// this.namespaceURI = namespaceURI; +// this.prefix = prefix; +// } +// +// public QualifiedName(String localPart) { +// this.localPart = localPart; +// this.namespaceURI = ""; +// this.prefix = ""; +// } +// +// public String getLocalPart() { +// return localPart; +// } +// +// public void setLocalPart(String localPart) { +// this.localPart = localPart; +// } +// +// public String getNamespaceURI() { +// return namespaceURI; +// } +// +// public String getPrefix() { +// return prefix; +// } +// +// @Override +// public int hashCode() { +// return localPart.hashCode(); +// } +// +// @Override +// public boolean equals(Object objectToTest) { +// if (objectToTest == this) { +// return true; +// } +// +// if (objectToTest == null || !(objectToTest instanceof QualifiedName)) { +// return false; +// } +// +// QualifiedName qName = (QualifiedName) objectToTest; +// +// if (qName.namespaceURI.equals(NS_ANNOT_NOT_DEFINED) || namespaceURI.equals(NS_ANNOT_NOT_DEFINED)) { +// return localPart.equals(qName.localPart); +// } +// return localPart.equals(qName.localPart) && namespaceURI.equals(qName.namespaceURI) && +// prefix.equals(qName.prefix); +// } +//} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java new file mode 100644 index 0000000..90a5047 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -0,0 +1,68 @@ +package io.ballerina.stdlib.data.csvdata.utils; + +import io.ballerina.runtime.api.PredefinedTypes; +import io.ballerina.runtime.api.creators.TypeCreator; +import io.ballerina.runtime.api.types.MapType; + +///* +// * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// * +// * WSO2 LLC. licenses this file to you under the Apache License, +// * Version 2.0 (the "License"); you may not use this file except +// * in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, +// * software distributed under the License is distributed on an +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// * KIND, either express or implied. See the License for the +// * specific language governing permissions and limitations +// * under the License. +// */ +// +//package io.ballerina.stdlib.data.csvdata.csv.utils; +// +//import io.ballerina.runtime.api.PredefinedTypes; +//import io.ballerina.runtime.api.creators.TypeCreator; +//import io.ballerina.runtime.api.types.ArrayType; +//import io.ballerina.runtime.api.types.MapType; +//import io.ballerina.runtime.api.utils.StringUtils; +//import io.ballerina.runtime.api.values.BString; +//import io.ballerina.runtime.api.values.BCsvItem; +//import io.ballerina.stdlib.data.csvdata.csv.QualifiedName; +// +///** +// * Constants used in Ballerina CsvData library. +// * +// * @since 0.1.0 +// */ +//public class Constants { +// +// private Constants() {} +// +// public static final String UNDERSCORE = "_"; +// public static final String COLON = ":"; +// public static final MapType JSON_MAP_TYPE = TypeCreator.createMapType(PredefinedTypes.TYPE_JSON); +// public static final ArrayType JSON_ARRAY_TYPE = TypeCreator.createArrayType(PredefinedTypes.TYPE_JSON); +// public static final String FIELD = "$field$."; +// public static final String NAMESPACE = "Namespace"; +// public static final BString URI = StringUtils.fromString("uri"); +// public static final BString PREFIX = StringUtils.fromString("prefix"); +// public static final String ATTRIBUTE = "Attribute"; +// public static final int DEFAULT_TYPE_FLAG = 2049; +// public static final String NAME = "Name"; +// public static final BString VALUE = StringUtils.fromString("value"); +// public static final String CONTENT = "#content"; +// public static final QualifiedName CONTENT_QNAME = new QualifiedName("", CONTENT, ""); +// public static final String FIELD_REGEX = "\\$field\\$\\."; +// public static final int NS_PREFIX_BEGIN_INDEX = BCsvItem.CSVNS_NS_URI_PREFIX.length(); +// public static final String RECORD = "record"; +// public static final String RECORD_OR_MAP = "record or map"; +// public static final String ANON_TYPE = "$anonType$"; +//} +public class Constants { + public static final MapType JSON_MAP_TYPE = TypeCreator.createMapType(PredefinedTypes.TYPE_JSON); + public static final MapType ANYDATA_MAP_TYPE = TypeCreator.createMapType(PredefinedTypes.TYPE_ANYDATA); +} \ No newline at end of file diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java new file mode 100644 index 0000000..1a9ac30 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java @@ -0,0 +1,721 @@ +///* +// * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// * +// * WSO2 LLC. licenses this file to you under the Apache License, +// * Version 2.0 (the "License"); you may not use this file except +// * in compliance with the License. +// * You may obtain a copy of the License at +// * +// * http://www.apache.org/licenses/LICENSE-2.0 +// * +// * Unless required by applicable law or agreed to in writing, +// * software distributed under the License is distributed on an +// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// * KIND, either express or implied. See the License for the +// * specific language governing permissions and limitations +// * under the License. +// */ +// +//package io.ballerina.stdlib.data.csvdata.csv.utils; +// +//import io.ballerina.runtime.api.PredefinedTypes; +//import io.ballerina.runtime.api.TypeTags; +//import io.ballerina.runtime.api.creators.TypeCreator; +//import io.ballerina.runtime.api.creators.ValueCreator; +//import io.ballerina.runtime.api.flags.SymbolFlags; +//import io.ballerina.runtime.api.types.ArrayType; +//import io.ballerina.runtime.api.types.Field; +//import io.ballerina.runtime.api.types.MapType; +//import io.ballerina.runtime.api.types.RecordType; +//import io.ballerina.runtime.api.types.Type; +//import io.ballerina.runtime.api.types.UnionType; +//import io.ballerina.runtime.api.utils.StringUtils; +//import io.ballerina.runtime.api.utils.TypeUtils; +//import io.ballerina.runtime.api.values.BArray; +//import io.ballerina.runtime.api.values.BError; +//import io.ballerina.runtime.api.values.BMap; +//import io.ballerina.runtime.api.values.BString; +//import io.ballerina.runtime.api.values.BTypedesc; +//import io.ballerina.stdlib.data.csvdata.csv.FromString; +//import io.ballerina.stdlib.data.csvdata.csv.QualifiedName; +// +//import java.util.ArrayList; +//import java.util.HashMap; +//import java.util.LinkedHashMap; +//import java.util.List; +//import java.util.Locale; +//import java.util.Map; +//import java.util.Stack; +// +//import javax.csv.namespace.QName; +// +///** +// * A util class for the Data package's native implementation. +// * +// * @since 0.1.0 +// */ +//public class DataUtils { +// private static final String ATTRIBUTE_PREFIX = "attribute_"; +// private static final String VALUE = "value"; +// +// @SuppressWarnings("unchecked") +// public static QualifiedName validateAndGetCsvNameFromRecordAnnotation(RecordType recordType, String recordName, +// QualifiedName elementName) { +// BMap annotations = recordType.getAnnotations(); +// String localName = recordName; +// for (BString annotationsKey : annotations.getKeys()) { +// String key = annotationsKey.getValue(); +// if (!key.contains(Constants.FIELD) && key.endsWith(Constants.NAME)) { +// String name = ((BMap) annotations.get(annotationsKey)).get(Constants.VALUE).toString(); +// String localPart = elementName.getLocalPart(); +// if (!name.equals(localPart)) { +// throw DiagnosticLog.error(DiagnosticErrorCode.TYPE_NAME_MISMATCH_WITH_CSV_ELEMENT, name, localPart); +// } +// localName = name; +// break; +// } +// } +// +// // Handle the namespace annotation. +// for (BString annotationsKey : annotations.getKeys()) { +// String key = annotationsKey.getValue(); +// if (!key.contains(Constants.FIELD) && key.endsWith(Constants.NAMESPACE)) { +// Map namespaceAnnotation = +// ((Map) annotations.get(StringUtils.fromString(key))); +// BString uri = (BString) namespaceAnnotation.get(Constants.URI); +// BString prefix = (BString) namespaceAnnotation.get(Constants.PREFIX); +// return new QualifiedName(uri == null ? "" : uri.getValue(), localName, +// prefix == null ? "" : prefix.getValue()); +// } +// } +// return new QualifiedName(QualifiedName.NS_ANNOT_NOT_DEFINED, localName, ""); +// } +// +// public static void validateTypeNamespace(String prefix, String uri, RecordType recordType) { +// ArrayList namespace = getNamespace(recordType); +// if (namespace.isEmpty() || prefix.equals(namespace.get(0)) && uri.equals(namespace.get(1))) { +// return; +// } +// throw DiagnosticLog.error(DiagnosticErrorCode.NAMESPACE_MISMATCH, recordType.getName()); +// } +// +// @SuppressWarnings("unchecked") +// private static ArrayList getNamespace(RecordType recordType) { +// BMap annotations = recordType.getAnnotations(); +// ArrayList namespace = new ArrayList<>(); +// for (BString annotationsKey : annotations.getKeys()) { +// String key = annotationsKey.getValue(); +// if (!key.contains(Constants.FIELD) && key.endsWith(Constants.NAMESPACE)) { +// BMap namespaceAnnotation = (BMap) annotations.get(annotationsKey); +// namespace.add(namespaceAnnotation.containsKey(Constants.PREFIX) ? +// ((BString) namespaceAnnotation.get(Constants.PREFIX)).getValue() : ""); +// namespace.add(((BString) namespaceAnnotation.get(Constants.URI)).getValue()); +// break; +// } +// } +// return namespace; +// } +// +// @SuppressWarnings("unchecked") +// public static Map getAllFieldsInRecordType(RecordType recordType, +// CsvAnalyzerData analyzerData) { +// BMap annotations = recordType.getAnnotations(); +// HashMap modifiedNames = new LinkedHashMap<>(); +// for (BString annotationKey : annotations.getKeys()) { +// String keyStr = annotationKey.getValue(); +// if (keyStr.contains(Constants.FIELD)) { +// // Capture namespace and name from the field annotation. +// String fieldName = keyStr.split(Constants.FIELD_REGEX)[1].replaceAll("\\\\", ""); +// Map fieldAnnotation = (Map) annotations.get(annotationKey); +// QualifiedName fieldQName = DataUtils.getFieldNameFromRecord(fieldAnnotation, fieldName); +// fieldQName.setLocalPart(getModifiedName(fieldAnnotation, fieldName)); +// modifiedNames.put(fieldName, fieldQName); +// } +// } +// +// Map fields = new HashMap<>(); +// Map recordFields = recordType.getFields(); +// for (String key : recordFields.keySet()) { +// QualifiedName modifiedQName = modifiedNames.getOrDefault(key, +// new QualifiedName(QualifiedName.NS_ANNOT_NOT_DEFINED, key, "")); +// if (fields.containsKey(modifiedQName)) { +// throw DiagnosticLog.error(DiagnosticErrorCode.DUPLICATE_FIELD, modifiedQName.getLocalPart()); +// } else if (analyzerData.attributeHierarchy.peek().containsKey(modifiedQName)) { +// continue; +// } +// fields.put(modifiedQName, recordFields.get(key)); +// } +// return fields; +// } +// +// @SuppressWarnings("unchecked") +// public static Map getAllAttributesInRecordType(RecordType recordType) { +// BMap annotations = recordType.getAnnotations(); +// Map attributes = new HashMap<>(); +// for (BString annotationKey : annotations.getKeys()) { +// String keyStr = annotationKey.getValue(); +// if (keyStr.contains(Constants.FIELD) && DataUtils.isAttributeField(annotationKey, annotations)) { +// String attributeName = keyStr.split(Constants.FIELD_REGEX)[1].replaceAll("\\\\", ""); +// Map fieldAnnotation = (Map) annotations.get(annotationKey); +// QualifiedName fieldQName = getFieldNameFromRecord(fieldAnnotation, attributeName); +// fieldQName.setLocalPart(getModifiedName(fieldAnnotation, attributeName)); +// attributes.put(fieldQName, recordType.getFields().get(attributeName)); +// } +// } +// return attributes; +// } +// +// @SuppressWarnings("unchecked") +// public static QualifiedName getFieldNameFromRecord(Map fieldAnnotation, String fieldName) { +// for (BString key : fieldAnnotation.keySet()) { +// if (key.getValue().endsWith(Constants.NAMESPACE)) { +// Map namespaceAnnotation = ((Map) fieldAnnotation.get(key)); +// BString uri = (BString) namespaceAnnotation.get(Constants.URI); +// BString prefix = (BString) namespaceAnnotation.get(Constants.PREFIX); +// return new QualifiedName(uri == null ? "" : uri.getValue(), fieldName, +// prefix == null ? "" : prefix.getValue()); +// } +// } +// return new QualifiedName(QualifiedName.NS_ANNOT_NOT_DEFINED, fieldName, ""); +// } +// +// @SuppressWarnings("unchecked") +// private static String getModifiedName(Map fieldAnnotation, String attributeName) { +// for (BString key : fieldAnnotation.keySet()) { +// if (key.getValue().endsWith(Constants.NAME)) { +// return ((Map) fieldAnnotation.get(key)).get(Constants.VALUE).toString(); +// } +// } +// return attributeName; +// } +// +// public static BArray createNewAnydataList(Type type) { +// return ValueCreator.createArrayValue(getArrayTypeFromElementType(type)); +// } +// +// public static QualifiedName getElementName(QName qName) { +// return new QualifiedName(qName.getNamespaceURI(), qName.getLocalPart(), qName.getPrefix()); +// } +// +// public static Object convertStringToExpType(BString value, Type expType) { +// Object result; +// switch (expType.getTag()) { +// case TypeTags.ANYDATA_TAG, TypeTags.ANY_TAG, TypeTags.JSON_TAG -> +// result = FromString.fromStringWithTypeInternal(value, PredefinedTypes.TYPE_STRING); +// case TypeTags.ARRAY_TAG -> result = convertStringToExpType(value, ((ArrayType) expType).getElementType()); +// default -> result = FromString.fromStringWithTypeInternal(value, expType); +// } +// +// if (result instanceof BError) { +// throw (BError) result; +// } +// return result; +// } +// +// public static void validateRequiredFields(BMap currentMapValue, CsvAnalyzerData analyzerData) { +// Map fields = analyzerData.fieldHierarchy.peek(); +// for (QualifiedName key : fields.keySet()) { +// // Validate required array size +// Field field = fields.get(key); +// String fieldName = field.getFieldName(); +// if (field.getFieldType().getTag() == TypeTags.ARRAY_TAG) { +// ArrayType arrayType = (ArrayType) field.getFieldType(); +// if (arrayType.getSize() != -1 +// && arrayType.getSize() != ((BArray) currentMapValue.get( +// StringUtils.fromString(fieldName))).getLength()) { +// throw DiagnosticLog.error(DiagnosticErrorCode.ARRAY_SIZE_MISMATCH); +// } +// } +// +// if (!SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL) +// && !currentMapValue.containsKey(StringUtils.fromString(fieldName))) { +// throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, fieldName); +// } +// } +// +// Map attributes = analyzerData.attributeHierarchy.peek(); +// for (QualifiedName key : attributes.keySet()) { +// Field field = attributes.get(key); +// String fieldName = field.getFieldName(); +// if (!SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL)) { +// throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_ATTRIBUTE_NOT_PRESENT, fieldName); +// } +// } +// } +// +// public static boolean isArrayValueAssignable(int typeTag) { +// return typeTag == TypeTags.ARRAY_TAG || typeTag == TypeTags.ANYDATA_TAG || typeTag == TypeTags.JSON_TAG; +// } +// +// public static boolean isStringValueAssignable(int typeTag) { +// return typeTag == TypeTags.STRING_TAG || typeTag == TypeTags.ANYDATA_TAG || typeTag == TypeTags.JSON_TAG; +// } +// +// public static ArrayType getValidArrayType(Type type) { +// return switch (type.getTag()) { +// case TypeTags.ARRAY_TAG -> (ArrayType) type; +// case TypeTags.ANYDATA_TAG -> PredefinedTypes.TYPE_ANYDATA_ARRAY; +// case TypeTags.JSON_TAG -> PredefinedTypes.TYPE_JSON_ARRAY; +// default -> null; +// }; +// } +// +// public static ArrayType getArrayTypeFromElementType(Type type) { +// return switch (type.getTag()) { +// case TypeTags.ARRAY_TAG -> TypeCreator.createArrayType(((ArrayType) type).getElementType()); +// case TypeTags.JSON_TAG -> PredefinedTypes.TYPE_JSON_ARRAY; +// case TypeTags.INT_TAG, TypeTags.FLOAT_TAG, TypeTags.STRING_TAG, TypeTags.BOOLEAN_TAG, TypeTags.BYTE_TAG, +// TypeTags.DECIMAL_TAG, TypeTags.RECORD_TYPE_TAG, TypeTags.MAP_TAG, TypeTags.OBJECT_TYPE_TAG, +// TypeTags.CSV_TAG, TypeTags.NULL_TAG -> TypeCreator.createArrayType(type); +// case TypeTags.TYPE_REFERENCED_TYPE_TAG -> getArrayTypeFromElementType(TypeUtils.getReferredType(type)); +// default -> PredefinedTypes.TYPE_ANYDATA_ARRAY; +// }; +// } +// +// public static MapType getMapTypeFromConstraintType(Type constraintType) { +// return switch (constraintType.getTag()) { +// case TypeTags.MAP_TAG -> (MapType) constraintType; +// case TypeTags.INT_TAG, TypeTags.FLOAT_TAG, TypeTags.STRING_TAG, TypeTags.BOOLEAN_TAG, TypeTags.BYTE_TAG, +// TypeTags.DECIMAL_TAG, TypeTags.JSON_TAG, TypeTags.RECORD_TYPE_TAG, TypeTags.OBJECT_TYPE_TAG, +// TypeTags.CSV_TAG, TypeTags.NULL_TAG -> TypeCreator.createMapType(constraintType); +// case TypeTags.ARRAY_TAG -> TypeCreator.createMapType(((ArrayType) constraintType).getElementType()); +// case TypeTags.TYPE_REFERENCED_TYPE_TAG -> +// getMapTypeFromConstraintType(TypeUtils.getReferredType(constraintType)); +// default -> TypeCreator.createMapType(PredefinedTypes.TYPE_ANYDATA); +// }; +// } +// +// public static void updateExpectedTypeStacks(RecordType recordType, CsvAnalyzerData analyzerData) { +// analyzerData.attributeHierarchy.push(new HashMap<>(getAllAttributesInRecordType(recordType))); +// analyzerData.fieldHierarchy.push(new HashMap<>(getAllFieldsInRecordType(recordType, analyzerData))); +// analyzerData.restTypes.push(recordType.getRestFieldType()); +// } +// +// public static void removeExpectedTypeStacks(CsvAnalyzerData analyzerData) { +// analyzerData.attributeHierarchy.pop(); +// analyzerData.fieldHierarchy.pop(); +// analyzerData.restTypes.pop(); +// } +// +// @SuppressWarnings("unchecked") +// public static Object getModifiedRecord(BMap input, BTypedesc type) { +// Type describingType = type.getDescribingType(); +// if (describingType.getTag() == TypeTags.MAP_TAG) { +// Type constraintType = TypeUtils.getReferredType(((MapType) describingType).getConstrainedType()); +// switch (constraintType.getTag()) { +// case TypeTags.ARRAY_TAG -> { +// return processArrayValue(input, (ArrayType) constraintType); +// } +// case TypeTags.MAP_TAG -> { +// BMap jsonMap = +// ValueCreator.createMapValue(TypeCreator.createMapType(PredefinedTypes.TYPE_CSV)); +// for (Map.Entry entry : input.entrySet()) { +// jsonMap.put(entry.getKey(), entry.getValue()); +// } +// return jsonMap; +// } +// case TypeTags.UNION_TAG -> { +// return DiagnosticLog.error(DiagnosticErrorCode.UNSUPPORTED_TYPE); +// } +// } +// } +// if (describingType.getTag() == TypeTags.RECORD_TYPE_TAG && +// describingType.getFlags() != Constants.DEFAULT_TYPE_FLAG) { +// BArray jsonArray = ValueCreator.createArrayValue(PredefinedTypes.TYPE_JSON_ARRAY); +// BMap recordField = addFields(input, type.getDescribingType()); +// BMap processedRecord = processParentAnnotation(type.getDescribingType(), recordField); +// BString rootTagName = processedRecord.getKeys()[0]; +// jsonArray.append(processedRecord.get(rootTagName)); +// jsonArray.append(rootTagName); +// return jsonArray; +// } +// return input; +// } +// +// @SuppressWarnings("unchecked") +// private static BMap processArrayValue(BMap input, ArrayType arrayType) { +// Type elementType = TypeUtils.getReferredType(arrayType.getElementType()); +// switch (elementType.getTag()) { +// case TypeTags.RECORD_TYPE_TAG -> { +// BMap jsonMap = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// for (Map.Entry entry : input.entrySet()) { +// List> records = new ArrayList<>(); +// BArray arrayValue = (BArray) entry.getValue(); +// for (int i = 0; i < arrayValue.getLength(); i++) { +// BMap record = addFields(((BMap) arrayValue.get(i)), +// elementType); +// BMap parentRecord = processParentAnnotation(elementType, record); +// // Remove parent element +// records.add((BMap) parentRecord.get(parentRecord.getKeys()[0])); +// } +// jsonMap.put(entry.getKey(), ValueCreator.createArrayValue(records.toArray(), +// TypeCreator.createArrayType(elementType))); +// } +// return jsonMap; +// } +// case TypeTags.CSV_TAG -> { +// ArrayType csvArrayType = TypeCreator.createArrayType(PredefinedTypes.TYPE_CSV); +// BMap jsonMap = +// ValueCreator.createMapValue(TypeCreator.createMapType(csvArrayType)); +// for (Map.Entry entry : input.entrySet()) { +// BArray arrayValue = (BArray) entry.getValue(); +// BArray csvArrayValue = ValueCreator.createArrayValue(csvArrayType); +// for (int i = 0; i < arrayValue.getLength(); i++) { +// csvArrayValue.append(arrayValue.get(i)); +// } +// jsonMap.put(entry.getKey(), csvArrayValue); +// } +// return jsonMap; +// } +// default -> { +// return input; +// } +// } +// } +// +// @SuppressWarnings("unchecked") +// private static BMap addFields(BMap input, Type type) { +// BMap recordValue = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// Map fields = ((RecordType) type).getFields(); +// BMap annotations = ((RecordType) type).getAnnotations(); +// for (Map.Entry entry: input.entrySet()) { +// String key = entry.getKey().getValue(); +// Object value = entry.getValue(); +// if (fields.containsKey(key)) { +// Type fieldType = fields.get(key).getFieldType(); +// fieldType = getTypeFromUnionType(fieldType, value); +// if (fieldType.getTag() == TypeTags.RECORD_TYPE_TAG) { +// processRecord(key, annotations, recordValue, value, fieldType); +// } else if (fieldType.getTag() == TypeTags.TYPE_REFERENCED_TYPE_TAG) { +// Type referredType = TypeUtils.getReferredType(fieldType); +// if (annotations.size() > 0) { +// key = getKeyNameFromAnnotation(annotations, key); +// } +// BMap subRecordAnnotations = ((RecordType) referredType).getAnnotations(); +// key = getElementName(subRecordAnnotations, key); +// BMap annotationRecord = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// processSubRecordAnnotation(subRecordAnnotations, annotationRecord); +// BMap subRecordValue = addFields(((BMap) value), referredType); +// if (annotationRecord.size() > 0) { +// subRecordValue.put(annotationRecord.getKeys()[0], +// annotationRecord.get(annotationRecord.getKeys()[0])); +// } +// recordValue.put(StringUtils.fromString(key), subRecordValue); +// } else if (fieldType.getTag() == TypeTags.ARRAY_TAG) { +// processArray(fieldType, annotations, recordValue, entry); +// } else { +// addPrimitiveValue(addFieldNamespaceAnnotation(key, annotations, recordValue), +// annotations, recordValue, value); +// } +// } else { +// recordValue.put(StringUtils.fromString(key), value); +// } +// } +// return recordValue; +// } +// +// @SuppressWarnings("unchecked") +// private static QName addFieldNamespaceAnnotation(String key, BMap annotations, +// BMap recordValue) { +// BString annotationKey = +// StringUtils.fromString((Constants.FIELD + key).replace(Constants.COLON, "\\:")); +// boolean isAttributeField = isAttributeField(annotationKey, annotations); +// if (annotations.containsKey(annotationKey)) { +// BMap annotationValue = (BMap) annotations.get(annotationKey); +// for (BString fieldKey : annotationValue.getKeys()) { +// if (fieldKey.toString().endsWith(Constants.NAMESPACE)) { +// return processFieldNamespaceAnnotation(annotationValue, key, fieldKey, recordValue, +// isAttributeField); +// } +// } +// } +// return new QName("", key, ""); +// } +// +// @SuppressWarnings("unchecked") +// public static boolean isAttributeField(BString annotationKey, BMap annotations) { +// if (!annotations.containsKey(annotationKey)) { +// return false; +// } +// +// BMap annotationValue = (BMap) annotations.get(annotationKey); +// for (BString fieldKey : annotationValue.getKeys()) { +// if (fieldKey.toString().endsWith(Constants.ATTRIBUTE)) { +// return true; +// } +// } +// return false; +// } +// +// @SuppressWarnings("unchecked") +// private static BMap getFieldNamespaceAndNameAnnotations(String key, +// BMap parentAnnotations) { +// BMap nsFieldAnnotation = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// BString annotationKey = +// StringUtils.fromString((Constants.FIELD + key).replace(Constants.COLON, "\\:")); +// if (!parentAnnotations.containsKey(annotationKey)) { +// return nsFieldAnnotation; +// } +// +// BMap annotationValue = (BMap) parentAnnotations.get(annotationKey); +// for (BString fieldKey : annotationValue.getKeys()) { +// String keyName = fieldKey.getValue(); +// if (keyName.endsWith(Constants.NAMESPACE) || keyName.endsWith(Constants.NAME)) { +// nsFieldAnnotation.put(fieldKey, annotationValue.get(fieldKey)); +// break; +// } +// } +// return nsFieldAnnotation; +// } +// +// @SuppressWarnings("unchecked") +// private static void processRecord(String key, BMap parentAnnotations, +// BMap record, Object value, Type childType) { +// BMap parentRecordAnnotations = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// BMap annotation = ((RecordType) childType).getAnnotations(); +// if (parentAnnotations.size() > 0) { +// annotation.merge(getFieldNamespaceAndNameAnnotations(key, parentAnnotations), true); +// processSubRecordAnnotation(parentAnnotations, parentRecordAnnotations); +// } +// BMap subRecord = addFields(((BMap) value), childType); +// if (annotation.size() > 0) { +// processSubRecordAnnotation(annotation, subRecord); +// } +// key = getElementName(annotation, key); +// record.put(StringUtils.fromString(key), subRecord); +// if (parentRecordAnnotations.size() > 0) { +// record.put(parentRecordAnnotations.getKeys()[0], +// parentRecordAnnotations.get(parentRecordAnnotations.getKeys()[0])); +// } +// } +// +// @SuppressWarnings("unchecked") +// private static void addPrimitiveValue(QName qName, BMap annotations, +// BMap record, Object value) { +// BString localPart = StringUtils.fromString(qName.getLocalPart()); +// BString key = qName.getPrefix().isBlank() ? +// localPart : StringUtils.fromString(qName.getPrefix() + ":" + localPart); +// BString annotationKey = +// StringUtils.fromString((Constants.FIELD + localPart).replace(Constants.COLON, "\\:")); +// BMap currentValue; +// if (record.containsKey(key)) { +// currentValue = (BMap) record.get(key); +// key = StringUtils.fromString(Constants.CONTENT); +// } else { +// currentValue = record; +// } +// +// if (annotations.containsKey(annotationKey)) { +// BMap annotationValue = (BMap) annotations.get(annotationKey); +// currentValue.put(StringUtils.fromString(processFieldAnnotation(annotationValue, key.getValue())), value); +// } else { +// currentValue.put(key, value); +// } +// } +// +// @SuppressWarnings("unchecked") +// private static void processArray(Type childType, BMap annotations, +// BMap record, Map.Entry entry) { +// Type elementType = TypeUtils.getReferredType(((ArrayType) childType).getElementType()); +// BMap annotationRecord = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// String keyName = entry.getKey().getValue(); +// if (annotations.size() > 0) { +// keyName = getKeyNameFromAnnotation(annotations, keyName); +// processSubRecordAnnotation(annotations, annotationRecord); +// } +// BArray arrayValue = (BArray) entry.getValue(); +// if (elementType.getTag() == TypeTags.RECORD_TYPE_TAG) { +// List> records = new ArrayList<>(); +// for (int i = 0; i < arrayValue.getLength(); i++) { +// BMap subRecord = addFields(((BMap) arrayValue.get(i)), +// elementType); +// subRecord = processParentAnnotation(elementType, subRecord); +// records.add((BMap) subRecord.get(subRecord.getKeys()[0])); +// } +// record.put( +// StringUtils.fromString(getElementName(((RecordType) elementType).getAnnotations(), keyName)), +// ValueCreator.createArrayValue(records.toArray(), +// TypeCreator.createArrayType(Constants.JSON_ARRAY_TYPE))); +// } else { +// List records = new ArrayList<>(); +// for (int i = 0; i < arrayValue.getLength(); i++) { +// records.add(arrayValue.get(i)); +// } +// record.put(StringUtils.fromString(keyName), ValueCreator.createArrayValue(records.toArray(), +// TypeCreator.createArrayType(Constants.JSON_ARRAY_TYPE))); +// } +// if (annotationRecord.size() > 0) { +// record.put(annotationRecord.getKeys()[0], +// annotationRecord.get(annotationRecord.getKeys()[0])); +// } +// } +// +// @SuppressWarnings("unchecked") +// private static String getKeyNameFromAnnotation(BMap annotations, String keyName) { +// BString annotationKey = StringUtils.fromString((Constants.FIELD + keyName). +// replace(Constants.COLON, "\\:")); +// if (annotations.containsKey(annotationKey)) { +// BMap annotationValue = (BMap) annotations.get(annotationKey); +// return processFieldAnnotation(annotationValue, keyName); +// } +// return keyName; +// } +// +// public static Type getTypeFromUnionType(Type childType, Object value) { +// if (childType instanceof UnionType bUnionType) { +// for (Type memberType : bUnionType.getMemberTypes()) { +// if (value.getClass().getName().toUpperCase(Locale.ROOT).contains( +// memberType.getName().toUpperCase(Locale.ROOT))) { +// childType = TypeUtils.getReferredType(memberType); +// } +// } +// } +// return childType; +// } +// +// private static BMap processParentAnnotation(Type type, BMap record) { +// BMap parentRecord = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// BMap namespaces = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// BMap annotations = ((RecordType) type).getAnnotations(); +// BString rootName = processAnnotation(annotations, type.getName(), namespaces); +// if (namespaces.size() > 0) { +// for (Map.Entry namespace : namespaces.entrySet()) { +// record.put(namespace.getKey(), namespace.getValue()); +// } +// } +// parentRecord.put(rootName, record); +// return parentRecord; +// } +// +// @SuppressWarnings("unchecked") +// private static String processFieldAnnotation(BMap annotation, String key) { +// for (BString value : annotation.getKeys()) { +// String stringValue = value.getValue(); +// if (stringValue.endsWith(Constants.NAME)) { +// BMap names = (BMap) annotation.get(value); +// String name = names.get(StringUtils.fromString(VALUE)).toString(); +// if (key.contains(Constants.COLON)) { +// key = key.substring(0, key.indexOf(Constants.COLON) + 1) + name; +// } else if (key.contains(ATTRIBUTE_PREFIX)) { +// key = key.substring(0, key.indexOf(Constants.UNDERSCORE) + 1) + name; +// } else { +// key = name; +// } +// } +// if (stringValue.endsWith(Constants.ATTRIBUTE)) { +// key = ATTRIBUTE_PREFIX.concat(key); +// } +// } +// return key; +// } +// +// private static BString processAnnotation(BMap annotation, String key, +// BMap namespaces) { +// boolean hasNamespaceAnnotation = false; +// for (BString value : annotation.getKeys()) { +// if (!value.getValue().contains(Constants.FIELD)) { +// String stringValue = value.getValue(); +// if (stringValue.endsWith(Constants.NAME)) { +// key = processNameAnnotation(annotation, key, value, hasNamespaceAnnotation); +// } +// if (stringValue.endsWith(Constants.NAMESPACE)) { +// hasNamespaceAnnotation = true; +// key = processNamespaceAnnotation(annotation, key, value, namespaces); +// } +// } +// } +// return StringUtils.fromString(key); +// } +// +// private static void processSubRecordAnnotation(BMap annotation, BMap subRecord) { +// BString[] keys = annotation.getKeys(); +// for (BString value : keys) { +// if (value.getValue().endsWith(Constants.NAMESPACE)) { +// processNamespaceAnnotation(annotation, "", value, subRecord); +// } +// } +// } +// +// @SuppressWarnings("unchecked") +// private static String getElementName(BMap annotation, String key) { +// BString[] keys = annotation.getKeys(); +// boolean hasNamespaceAnnotation = false; +// for (BString value : keys) { +// if (value.getValue().endsWith(Constants.NAMESPACE)) { +// hasNamespaceAnnotation = true; +// BMap namespaceAnnotation = (BMap) annotation.get(value); +// BString prefix = (BString) namespaceAnnotation.get(Constants.PREFIX); +// if (prefix != null) { +// key = prefix.getValue().concat(Constants.COLON).concat(key); +// } +// } +// if (value.getValue().endsWith(Constants.NAME)) { +// key = processNameAnnotation(annotation, key, value, hasNamespaceAnnotation); +// } +// } +// return key; +// } +// +// @SuppressWarnings("unchecked") +// private static String processNameAnnotation(BMap annotation, String key, BString value, +// boolean hasNamespaceAnnotation) { +// String nameValue = ((BMap) annotation.get(value)). +// get(StringUtils.fromString(VALUE)).toString(); +// if (hasNamespaceAnnotation) { +// return key.substring(0, key.indexOf(Constants.COLON) + 1) + nameValue; +// } else { +// return nameValue; +// } +// } +// +// @SuppressWarnings("unchecked") +// private static String processNamespaceAnnotation(BMap annotation, String key, BString value, +// BMap subRecord) { +// BMap namespaceAnnotation = (BMap) annotation.get(value); +// BString uri = (BString) namespaceAnnotation.get(Constants.URI); +// BString prefix = (BString) namespaceAnnotation.get(Constants.PREFIX); +// if (prefix == null) { +// subRecord.put(StringUtils.fromString(ATTRIBUTE_PREFIX + "csvns"), uri); +// } else { +// subRecord.put(StringUtils.fromString(ATTRIBUTE_PREFIX + "csvns:" + prefix), uri); +// key = prefix.getValue().concat(Constants.COLON).concat(key); +// } +// return key; +// } +// +// @SuppressWarnings("unchecked") +// private static QName processFieldNamespaceAnnotation(BMap annotation, String key, BString value, +// BMap subRecord, boolean isAttributeField) { +// BMap namespaceAnnotation = (BMap) annotation.get(value); +// BString uri = (BString) namespaceAnnotation.get(Constants.URI); +// BString prefix = (BString) namespaceAnnotation.get(Constants.PREFIX); +// QName qName = new QName(uri == null ? "" : uri.getValue(), key, prefix == null ? "" : prefix.getValue()); +// if (isAttributeField) { +// addAttributeToRecord(prefix, uri, key, subRecord); +// } else { +// BMap nextMapValue = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); +// key = addAttributeToRecord(prefix, uri, key, nextMapValue); +// subRecord.put(StringUtils.fromString(key), nextMapValue); +// } +// return qName; +// } +// +// private static String addAttributeToRecord(BString prefix, BString uri, String key, +// BMap subRecord) { +// if (prefix == null) { +// subRecord.put(StringUtils.fromString(ATTRIBUTE_PREFIX + "csvns"), uri); +// return key; +// } +// subRecord.put(StringUtils.fromString(ATTRIBUTE_PREFIX + "csvns:" + prefix), uri); +// return prefix.getValue().concat(Constants.COLON).concat(key); +// } +// +// /** +// * Holds data required for the traversing. +// * +// * @since 0.1.0 +// */ +// public static class CsvAnalyzerData { +// public boolean mapContext = false; +// } +//} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java new file mode 100644 index 0000000..1b409ce --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.utils; + +/** + * Represents a diagnostic error code. + * + * @since 0.1.0 + */ +public enum DiagnosticErrorCode { + + INVALID_TYPE("BDE_0001", "invalid.type"), + CSV_ROOT_MISSING("BDE_0002", "csv.root.missing"), + INVALID_REST_TYPE("BDE_0003", "invalid.rest.type"), + ARRAY_SIZE_MISMATCH("BDE_0004", "array.size.mismatch"), + REQUIRED_FIELD_NOT_PRESENT("BDE_0005", "required.field.not.present"), + REQUIRED_ATTRIBUTE_NOT_PRESENT("BDE_0006", "required.attribute.not.present"), + DUPLICATE_FIELD("BDE_0007", "duplicate.field"), + FOUND_ARRAY_FOR_NON_ARRAY_TYPE("BDE_0008", "found.array.for.non.array.type"), + EXPECTED_ANYDATA_OR_JSON("BDE_0009", "expected.anydata.or.json"), + NAMESPACE_MISMATCH("BDE_0010", "namespace.mismatch"), + TYPE_NAME_MISMATCH_WITH_CSV_ELEMENT("BDE_0011", "type.name.mismatch.with.csv.element"), + CAN_NOT_READ_STREAM("BDE_0012", "error.cannot.read.stream"), + CANNOT_CONVERT_TO_EXPECTED_TYPE("BDE_0013", "cannot.convert.to.expected.type"), + UNSUPPORTED_TYPE("BDE_0014", "unsupported.type"), + STREAM_BROKEN("BDE_0015", "stream.broken"), + CSV_PARSE_ERROR("BDE_0016", "csv.parse.error"), + INCOMPATIBLE_TYPE("BDE_0017", "incompatible.error"), + INVALID_TYPE_FOR_FIELD("BDE_18", "invalid.type.for.field.error"), + + CSV_PARSER_EXCEPTION("BDE_19", "invalid.type.for.field.error"); + + String diagnosticId; + String messageKey; + + DiagnosticErrorCode(String diagnosticId, String messageKey) { + this.diagnosticId = diagnosticId; + this.messageKey = messageKey; + } + + public String messageKey() { + return messageKey; + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java new file mode 100644 index 0000000..2ed80ae --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.utils; + +import io.ballerina.runtime.api.creators.ErrorCreator; +import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.values.BError; + +import java.text.MessageFormat; +import java.util.Locale; +import java.util.ResourceBundle; + +/** + * Diagnostic log for data module. + * + * @since 0.1.0 + */ +public class DiagnosticLog { + private static final String ERROR_PREFIX = "error"; + private static final String ERROR = "Error"; + private static final ResourceBundle MESSAGES = ResourceBundle.getBundle("error", Locale.getDefault()); + + public static BError error(DiagnosticErrorCode code, Object... args) { + String msg = formatMessage(code, args); + return getCsvError(msg); + } + + private static String formatMessage(DiagnosticErrorCode code, Object[] args) { + String msgKey = MESSAGES.getString(ERROR_PREFIX + "." + code.messageKey()); + return MessageFormat.format(msgKey, args); + } + + public static BError getCsvError(String message) { + return ErrorCreator.createError(io.ballerina.stdlib.data.csvdata.utils.ModuleUtils.getModule(), ERROR, StringUtils.fromString(message), + null, null); + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/ModuleUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/ModuleUtils.java new file mode 100644 index 0000000..d9de709 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/ModuleUtils.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.utils; + +import io.ballerina.runtime.api.Environment; +import io.ballerina.runtime.api.Module; + +/** + * This class will hold module related utility functions. + * + * @since 0.1.0 + */ +public class ModuleUtils { + + /** + * Time standard library package ID. + */ + private static Module module = null; + + private ModuleUtils() { + } + + public static void setModule(Environment env) { + module = env.getCurrentModule(); + } + + public static Module getModule() { + return module; + } +} diff --git a/native/src/main/java/module-info.java b/native/src/main/java/module-info.java new file mode 100644 index 0000000..5cd8bce --- /dev/null +++ b/native/src/main/java/module-info.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +module io.ballerina.stdlib.data { + requires io.ballerina.runtime; + requires io.ballerina.lang.value; + requires junit; + requires org.apache.commons.lang3; + exports io.ballerina.stdlib.data.csvdata.csv; +} diff --git a/native/src/main/resources/META-INF/native-image/io.ballerina.stdlib/data/csvdata-native/resource-config.json b/native/src/main/resources/META-INF/native-image/io.ballerina.stdlib/data/csvdata-native/resource-config.json new file mode 100644 index 0000000..befe09e --- /dev/null +++ b/native/src/main/resources/META-INF/native-image/io.ballerina.stdlib/data/csvdata-native/resource-config.json @@ -0,0 +1,6 @@ +{ + "bundles":[{ + "name":"error", + "locales":[""] + }] +} diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties new file mode 100644 index 0000000..8575c97 --- /dev/null +++ b/native/src/main/resources/error.properties @@ -0,0 +1,75 @@ +# +# Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# ------------------------- +# Data module error messages +# ------------------------- + +error.invalid.type=\ + invalid type expected ''{0}'' but found ''{1}'' + +error.csv.root.missing=\ + csv root element is missing + +error.invalid.rest.type=\ + invalid rest type ''{0}'' + +error.array.size.mismatch=\ + array size is not compatible with the expected size + +error.required.field.not.present=\ + required field ''{0}'' not present in CSV + +error.required.attribute.not.present=\ + required attribute ''{0}'' not present in CSV + +error.duplicate.field=\ + duplicate field ''{0}'' + +error.found.array.for.non.array.type=\ + expected ''{0}'' value for the field ''{1}'' found ''array'' value + +error.expected.anydata.or.json=\ + incompatible type expected anydata or json + +error.namespace.mismatch=\ + namespace mismatched for the type: ''{0}'' + +error.type.name.mismatch.with.csv.element=\ + record type name ''{0}'' mismatch with given CSV name ''{1}'' + +error.cannot.read.stream=\ + cannot read the stream, interrupted error + +error.cannot.convert.to.expected.type=\ + ''{0}'' value ''{1}'' cannot be converted to ''{2}'' + +error.unsupported.type=\ + unsupported input type + +error.stream.broken=\ + error occurred while reading the stream: ''{0}'' + +error.csv.parse.error=\ + failed to parse csv: ''{0}'' + +error.incompatible.error=\ + incompatible type ''{0}'',''{1}'' + +error.invalid.type.for.field.error=\ + invalid type for field ''{0}'' diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..3fa92d3 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,41 @@ +/** + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +plugins { + id "com.gradle.enterprise" version "3.2" +} + +rootProject.name = 'data.csv' +include(':checkstyle') +include(':data.csv-native') +include(':data.csv-ballerina') +//include(':data.csv-compiler-plugin') +//include(':data.csv-compiler-plugin-tests') + +project(':checkstyle').projectDir = file("build-config${File.separator}checkstyle") +project(':data.csv-native').projectDir = file('native') +project(':data.csv-ballerina').projectDir = file('ballerina') +//project(':data.csv-compiler-plugin').projectDir = file('compiler-plugin') +//project(':data.csv-compiler-plugin-tests').projectDir = file('compiler-plugin-test') + +gradleEnterprise { + buildScan { + termsOfServiceUrl = 'https://gradle.com/terms-of-service' + termsOfServiceAgree = 'yes' + } +} From bf83a375e842420dea8291a4fb82a38aa8e716c3 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 16 Feb 2024 13:13:27 +0530 Subject: [PATCH 002/147] Add toCsvString function --- ballerina/csv_api.bal | 44 +++++++++++++++++-- ballerina/tests/test.bal | 19 ++++++-- .../stdlib/data/csvdata/csv/Native.java | 8 ++++ 3 files changed, 65 insertions(+), 6 deletions(-) diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 30a77d1..d576615 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -17,6 +17,7 @@ import ballerina/jballerina.java; type CsvConversionError error; +type UnSupportedOperation error; public enum OrderType { ASC, @@ -57,6 +58,7 @@ public type FromCSVConfig record {| public type ToCSVConfig record {| string[]? headers = (); string:Char separator = ","; + string:Char lineSeparator = "\n"; boolean skipHeaders = false; int skipdataRows = 0; int dataRowCount = -1; @@ -68,13 +70,49 @@ public type ToCSVConfig record {| string:Char escapeCharacter = "\\"; |}; -public isolated function fromCsvWithType((string[]|map|record{})[] value, FromCSVConfig config, typedesc<(record{}|map|anydata[])[]> t = <>) +public isolated function fromCsvWithType((string[]|map|record{})[] csv, FromCSVConfig config = {}, typedesc<(record{}|map|anydata[])[]> t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function fromCsvStringWithType(string|byte[]|stream s, FromCSVConfig config,typedesc<(record{}|map|anydata)[]> t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public isolated function toCsv(anydata[] value, ToCSVConfig config) returns (string|map|record{})[]|CsvConversionError { - return error(""); +public isolated function toCsv((anydata[]|map|record{})[] csv, ToCSVConfig config = {}, typedesc<(record{}|map|anydata[])[]> t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + +public isolated function toCsvString((anydata[]|map|record{})[] csv, ToCSVConfig config = {}) returns string|UnSupportedOperation { + string csvString = ""; + foreach anydata[]|map|record{} row in csv { + if row is anydata[] { + foreach anydata cell in row { + csvString += check convertToString(cell) + config.separator; + } + csvString = removeLastIndex(csvString); + csvString += config.lineSeparator; + continue; + } + + // issue: https://github.com/ballerina-platform/ballerina-lang/issues/42172 + foreach string cell in (row).keys() { + csvString += check convertToString(row[cell]) + config.separator; + } + + csvString = removeLastIndex(csvString); + csvString += config.lineSeparator; + } + + csvString = removeLastIndex(csvString); + return csvString; +} + +isolated function removeLastIndex(string content) returns string { + return content.substring(0, content.length() - 1); +} + +isolated function convertToString(anydata cell) returns string|UnSupportedOperation { + if cell is int|string|boolean|float|decimal|() { + return cell.toBalString(); + } else { + return error UnSupportedOperation(string `unsupported opration`); + } } diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 5fbcf6d..516d7c1 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -31,7 +31,7 @@ int[][] c4 = [[1, 2, 3], [1, 2, 3]]; [string, string][] d = [["1", "2"], ["1", "2"]]; [string, string][] d2 = [["1", "2"], ["1", "2"]]; -@test:Config{enable: true} +@test:Config{enable: false} public function testA() returns error? { A aa = check fromCsvWithType(a, {}, A); test:assertEquals(aa, a); @@ -202,7 +202,7 @@ type WW int[][2]; type XX string[][2]; type YY anydata[][2]; -@test:Config{} +@test:Config{ enable: false} function test() returns CsvConversionError? { string a = check io:fileReadString("a.txt"); @@ -324,4 +324,17 @@ function test() returns CsvConversionError? { // OO oo = check fromCsvStringWithType(a, {}, MM); // test:assertEquals(oo, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); -// io:println(oo); \ No newline at end of file +// io:println(oo); + +type AAA string[][]; + +@test:Config{ enable: true } +function testC() returns error? { + anydata[][] a = [[1, 2], [2, 3], [2, 3]]; + record{}[] b = [{"a": 1, "b": 2}, {"a": 1, "b": 2}, {"a": 1, "b": 2}]; + map[] c = [{"a": 1, "b": 2}, {"a": 1, "b": 2}, {"a": 1, "b": 2}]; + + io:println(toCsvString(a)); + io:println(toCsvString(b)); + io:println(toCsvString(c)); +} \ No newline at end of file diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index b739f49..ff6ceba 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -54,4 +54,12 @@ public static Object fromCsvStringWithType(Object csv, BMap con } return null; } + + public static Object toCsv(BArray csv, BMap config, BTypedesc type) { + try { + return CsvTraversal.traverse(csv, config, type.getDescribingType()); + } catch (Exception e) { + return DiagnosticLog.getCsvError(e.getMessage()); + } + } } From 11481e78611f3e0bc434df5effc40e8f2259d40f Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 16 Feb 2024 13:49:07 +0530 Subject: [PATCH 003/147] Update `fromStringWithType` function --- .../stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java | 2 ++ .../io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java | 2 ++ .../ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java | 2 ++ 3 files changed, 6 insertions(+) create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java new file mode 100644 index 0000000..a168ca7 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java @@ -0,0 +1,2 @@ +package io.ballerina.stdlib.data.csvdata.io;public class BallerinaByteBlockInputStream { +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java new file mode 100644 index 0000000..0b64bdb --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java @@ -0,0 +1,2 @@ +package io.ballerina.stdlib.data.csvdata.io;public class DataReaderTask { +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java new file mode 100644 index 0000000..74923d9 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java @@ -0,0 +1,2 @@ +package io.ballerina.stdlib.data.csvdata.io;public class DataReaderThreadPool { +} From 45f77d29c2205f889b2c59829baa32276174214d Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 16 Feb 2024 13:49:20 +0530 Subject: [PATCH 004/147] Update fromStringWithType function --- ballerina/Dependencies.toml | 2 +- ballerina/tests/test.bal | 6 +- .../stdlib/data/csvdata/csv/Native.java | 26 ++- .../io/BallerinaByteBlockInputStream.java | 167 +++++++++++++++++- .../data/csvdata/io/DataReaderTask.java | 105 ++++++++++- .../data/csvdata/io/DataReaderThreadPool.java | 53 +++++- 6 files changed, 347 insertions(+), 12 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ddb95d8..8c17176 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.3" +distribution-version = "2201.8.1" [[package]] org = "ballerina" diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 516d7c1..0b03a05 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -31,7 +31,7 @@ int[][] c4 = [[1, 2, 3], [1, 2, 3]]; [string, string][] d = [["1", "2"], ["1", "2"]]; [string, string][] d2 = [["1", "2"], ["1", "2"]]; -@test:Config{enable: false} +@test:Config{enable: true } public function testA() returns error? { A aa = check fromCsvWithType(a, {}, A); test:assertEquals(aa, a); @@ -121,7 +121,7 @@ public function testA() returns error? { test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); } -@test:Config{enable: false} +@test:Config{enable: true } function testB() returns error? { // B2 d2b2 = check fromCsvWithType(d2, {}, B2); // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); @@ -202,7 +202,7 @@ type WW int[][2]; type XX string[][2]; type YY anydata[][2]; -@test:Config{ enable: false} +@test:Config{ enable: true } function test() returns CsvConversionError? { string a = check io:fileReadString("a.txt"); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index ff6ceba..6d5b553 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -19,10 +19,16 @@ package io.ballerina.stdlib.data.csvdata.csv; import io.ballerina.runtime.api.Environment; +import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.values.*; +import io.ballerina.stdlib.data.csvdata.io.DataReaderTask; +import io.ballerina.stdlib.data.csvdata.io.DataReaderThreadPool; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; +import java.io.ByteArrayInputStream; +import java.io.InputStreamReader; import java.io.StringReader; /** @@ -40,19 +46,29 @@ public static Object fromCsvWithType(BArray csv, BMap config, B } } - public static Object fromCsvStringWithType(Object csv, BMap config, BTypedesc type) { + public static Object fromCsvStringWithType(Environment env, Object csv, BMap config, BTypedesc type) { try { Type expType = type.getDescribingType(); if (csv instanceof BString) { - Object a = CsvParser.parse(new StringReader(((BString) csv).getValue()), expType); - return a; + return CsvParser.parse(new StringReader(((BString) csv).getValue()), expType); + } else if (csv instanceof BArray) { + byte[] bytes = ((BArray) csv).getBytes(); + return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), + type.getDescribingType()); + } else if (csv instanceof BStream) { + final BObject iteratorObj = ((BStream) csv).getIteratorObj(); + final Future future = env.markAsync(); + DataReaderTask task = new DataReaderTask(env, iteratorObj, future, type); + DataReaderThreadPool.EXECUTOR_SERVICE.submit(task); + return null; + } else { + return DiagnosticLog.error(DiagnosticErrorCode.UNSUPPORTED_TYPE, expType); } } catch (BError e) { return e; } catch (Exception e) { - return e; + return DiagnosticLog.error(DiagnosticErrorCode.CSV_PARSE_ERROR, e.getMessage()); } - return null; } public static Object toCsv(BArray csv, BMap config, BTypedesc type) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java index a168ca7..203197a 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java @@ -1,2 +1,167 @@ -package io.ballerina.stdlib.data.csvdata.io;public class BallerinaByteBlockInputStream { +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.io; + +import io.ballerina.runtime.api.Environment; +import io.ballerina.runtime.api.async.Callback; +import io.ballerina.runtime.api.async.StrandMetadata; +import io.ballerina.runtime.api.types.MethodType; +import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.values.BArray; +import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BObject; +import io.ballerina.runtime.api.values.BString; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.Semaphore; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; + +/** + * Java Input Stream based on Ballerina byte block stream. stream + * + * @since 0.1.0 + */ +public class BallerinaByteBlockInputStream extends InputStream { + + private final BObject iterator; + private final Environment env; + private final String nextMethodName; + private final Type returnType; + private final String strandName; + private final StrandMetadata metadata; + private final Map properties; + private final AtomicBoolean done = new AtomicBoolean(false); + private final MethodType closeMethod; + private final Consumer futureResultConsumer; + + private byte[] currentChunk = new byte[0]; + private int nextChunkIndex = 0; + + public BallerinaByteBlockInputStream(Environment env, BObject iterator, MethodType nextMethod, + MethodType closeMethod, Consumer futureResultConsumer) { + this.env = env; + this.iterator = iterator; + this.nextMethodName = nextMethod.getName(); + this.returnType = nextMethod.getReturnType(); + this.closeMethod = closeMethod; + this.strandName = env.getStrandName().orElse(""); + this.metadata = env.getStrandMetadata(); + this.properties = Map.of(); + this.futureResultConsumer = futureResultConsumer; + } + + @Override + public int read() { + if (done.get()) { + return -1; + } + if (hasBytesInCurrentChunk()) { + return currentChunk[nextChunkIndex++]; + } + // Need to get a new block from the stream, before reading again. + nextChunkIndex = 0; + try { + if (readNextChunk()) { + return read(); + } + } catch (InterruptedException e) { + BError error = DiagnosticLog.getCsvError("Cannot read the stream, interrupted error"); + futureResultConsumer.accept(error); + return -1; + } + return -1; + } + + @Override + public void close() throws IOException { + super.close(); + Semaphore semaphore = new Semaphore(0); + if (closeMethod != null) { + env.getRuntime().invokeMethodAsyncSequentially(iterator, closeMethod.getName(), strandName, metadata, + new Callback() { + @Override + public void notifyFailure(BError bError) { + semaphore.release(); + } + + @Override + public void notifySuccess(Object result) { + semaphore.release(); + } + }, properties, returnType); + } + try { + semaphore.acquire(); + } catch (InterruptedException e) { + throw new IOException("Error while closing the stream", e); + } + } + + private boolean hasBytesInCurrentChunk() { + return currentChunk.length != 0 && nextChunkIndex < currentChunk.length; + } + + private boolean readNextChunk() throws InterruptedException { + Semaphore semaphore = new Semaphore(0); + Callback callback = new Callback() { + + @Override + public void notifyFailure(BError bError) { + // Panic with an error + done.set(true); + futureResultConsumer.accept(bError); + currentChunk = new byte[0]; + semaphore.release(); + // TODO : Should we panic here? + } + + @Override + public void notifySuccess(Object result) { + if (result == null) { + done.set(true); + currentChunk = new byte[0]; + semaphore.release(); + return; + } + if (result instanceof BMap) { + BMap valueRecord = (BMap) result; + final BString value = Arrays.stream(valueRecord.getKeys()).findFirst().get(); + final BArray arrayValue = valueRecord.getArrayValue(value); + currentChunk = arrayValue.getByteArray(); + semaphore.release(); + } else { + // Case where Completes with an error + done.set(true); + semaphore.release(); + } + } + + }; + env.getRuntime().invokeMethodAsyncSequentially(iterator, nextMethodName, strandName, metadata, callback, + properties, returnType); + semaphore.acquire(); + return !done.get(); + } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java index 0b64bdb..fb1f4a1 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java @@ -1,2 +1,105 @@ -package io.ballerina.stdlib.data.csvdata.io;public class DataReaderTask { +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.ballerina.stdlib.data.csvdata.io; + +import io.ballerina.runtime.api.Environment; +import io.ballerina.runtime.api.Future; +import io.ballerina.runtime.api.types.MethodType; +import io.ballerina.runtime.api.types.ObjectType; +import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.runtime.api.values.BObject; +import io.ballerina.runtime.api.values.BTypedesc; +import io.ballerina.stdlib.data.csvdata.csv.CsvParser; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; + +import java.io.InputStreamReader; +import java.util.function.Consumer; + +/** + * This class will read data from a Ballerina Stream of byte blocks, in non-blocking manner. + * + * @since 0.1.0 + */ +public class DataReaderTask implements Runnable { + + private static final String METHOD_NAME_NEXT = "next"; + private static final String METHOD_NAME_CLOSE = "close"; + + private final Environment env; + private final BObject iteratorObj; + private final Future future; + private final BTypedesc typed; + + public DataReaderTask(Environment env, BObject iteratorObj, Future future, BTypedesc typed) { + this.env = env; + this.iteratorObj = iteratorObj; + this.future = future; + this.typed = typed; + } + + static MethodType resolveNextMethod(BObject iterator) { + MethodType method = getMethodType(iterator, METHOD_NAME_NEXT); + if (method != null) { + return method; + } + throw new IllegalStateException("next method not found in the iterator object"); + } + + static MethodType resolveCloseMethod(BObject iterator) { + return getMethodType(iterator, METHOD_NAME_CLOSE); + } + + private static MethodType getMethodType(BObject iterator, String methodNameClose) { + ObjectType objectType = (ObjectType) TypeUtils.getReferredType(iterator.getOriginalType()); + MethodType[] methods = objectType.getMethods(); + // Assumes compile-time validation of the iterator object + for (MethodType method : methods) { + if (method.getName().equals(methodNameClose)) { + return method; + } + } + return null; + } + + @Override + public void run() { + ResultConsumer resultConsumer = new ResultConsumer<>(future); + try (var byteBlockSteam = new BallerinaByteBlockInputStream(env, iteratorObj, resolveNextMethod(iteratorObj), + resolveCloseMethod(iteratorObj), resultConsumer)) { + Object result = CsvParser.parse(new InputStreamReader(byteBlockSteam), typed.getDescribingType()); + future.complete(result); + } catch (Exception e) { + future.complete(DiagnosticLog.getCsvError("Error occurred while reading the stream: " + e.getMessage())); + } + } + + /** + * This class will hold module related utility functions. + * + * @param The type of the result + * @param future The future to complete + * @since 0.1.0 + */ + public record ResultConsumer(Future future) implements Consumer { + + @Override + public void accept(T t) { + future.complete(t); + } + } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java index 74923d9..21e9bad 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java @@ -1,2 +1,53 @@ -package io.ballerina.stdlib.data.csvdata.io;public class DataReaderThreadPool { +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package io.ballerina.stdlib.data.csvdata.io; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +/** + * Thread pool for data reader. + * + * @since 0.1.0 + */ +public class DataReaderThreadPool { + + // TODO : Make this configurable, in Ballerina Library. + private static final int CORE_POOL_SIZE = 0; + private static final int MAX_POOL_SIZE = 50; + private static final long KEEP_ALIVE_TIME = 60L; + private static final String THREAD_NAME = "bal-data-jsondata-thread"; + public static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(CORE_POOL_SIZE, + MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS, new SynchronousQueue<>(), new DataThreadFactory()); + + /** + * Thread factory for data reader. + */ + static class DataThreadFactory implements ThreadFactory { + + @Override + public Thread newThread(Runnable runnable) { + Thread ballerinaData = new Thread(runnable); + ballerinaData.setName(THREAD_NAME); + return ballerinaData; + } + } } From 3353ad42e632c1f470349583bdd572c780c03192 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Sun, 18 Feb 2024 19:39:48 +0530 Subject: [PATCH 005/147] Update json variables into csv variables --- .../stdlib/data/csvdata/utils/DataUtils.java | 721 ------------------ 1 file changed, 721 deletions(-) delete mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java deleted file mode 100644 index 1a9ac30..0000000 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java +++ /dev/null @@ -1,721 +0,0 @@ -///* -// * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// * -// * WSO2 LLC. licenses this file to you under the Apache License, -// * Version 2.0 (the "License"); you may not use this file except -// * in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, -// * software distributed under the License is distributed on an -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// * KIND, either express or implied. See the License for the -// * specific language governing permissions and limitations -// * under the License. -// */ -// -//package io.ballerina.stdlib.data.csvdata.csv.utils; -// -//import io.ballerina.runtime.api.PredefinedTypes; -//import io.ballerina.runtime.api.TypeTags; -//import io.ballerina.runtime.api.creators.TypeCreator; -//import io.ballerina.runtime.api.creators.ValueCreator; -//import io.ballerina.runtime.api.flags.SymbolFlags; -//import io.ballerina.runtime.api.types.ArrayType; -//import io.ballerina.runtime.api.types.Field; -//import io.ballerina.runtime.api.types.MapType; -//import io.ballerina.runtime.api.types.RecordType; -//import io.ballerina.runtime.api.types.Type; -//import io.ballerina.runtime.api.types.UnionType; -//import io.ballerina.runtime.api.utils.StringUtils; -//import io.ballerina.runtime.api.utils.TypeUtils; -//import io.ballerina.runtime.api.values.BArray; -//import io.ballerina.runtime.api.values.BError; -//import io.ballerina.runtime.api.values.BMap; -//import io.ballerina.runtime.api.values.BString; -//import io.ballerina.runtime.api.values.BTypedesc; -//import io.ballerina.stdlib.data.csvdata.csv.FromString; -//import io.ballerina.stdlib.data.csvdata.csv.QualifiedName; -// -//import java.util.ArrayList; -//import java.util.HashMap; -//import java.util.LinkedHashMap; -//import java.util.List; -//import java.util.Locale; -//import java.util.Map; -//import java.util.Stack; -// -//import javax.csv.namespace.QName; -// -///** -// * A util class for the Data package's native implementation. -// * -// * @since 0.1.0 -// */ -//public class DataUtils { -// private static final String ATTRIBUTE_PREFIX = "attribute_"; -// private static final String VALUE = "value"; -// -// @SuppressWarnings("unchecked") -// public static QualifiedName validateAndGetCsvNameFromRecordAnnotation(RecordType recordType, String recordName, -// QualifiedName elementName) { -// BMap annotations = recordType.getAnnotations(); -// String localName = recordName; -// for (BString annotationsKey : annotations.getKeys()) { -// String key = annotationsKey.getValue(); -// if (!key.contains(Constants.FIELD) && key.endsWith(Constants.NAME)) { -// String name = ((BMap) annotations.get(annotationsKey)).get(Constants.VALUE).toString(); -// String localPart = elementName.getLocalPart(); -// if (!name.equals(localPart)) { -// throw DiagnosticLog.error(DiagnosticErrorCode.TYPE_NAME_MISMATCH_WITH_CSV_ELEMENT, name, localPart); -// } -// localName = name; -// break; -// } -// } -// -// // Handle the namespace annotation. -// for (BString annotationsKey : annotations.getKeys()) { -// String key = annotationsKey.getValue(); -// if (!key.contains(Constants.FIELD) && key.endsWith(Constants.NAMESPACE)) { -// Map namespaceAnnotation = -// ((Map) annotations.get(StringUtils.fromString(key))); -// BString uri = (BString) namespaceAnnotation.get(Constants.URI); -// BString prefix = (BString) namespaceAnnotation.get(Constants.PREFIX); -// return new QualifiedName(uri == null ? "" : uri.getValue(), localName, -// prefix == null ? "" : prefix.getValue()); -// } -// } -// return new QualifiedName(QualifiedName.NS_ANNOT_NOT_DEFINED, localName, ""); -// } -// -// public static void validateTypeNamespace(String prefix, String uri, RecordType recordType) { -// ArrayList namespace = getNamespace(recordType); -// if (namespace.isEmpty() || prefix.equals(namespace.get(0)) && uri.equals(namespace.get(1))) { -// return; -// } -// throw DiagnosticLog.error(DiagnosticErrorCode.NAMESPACE_MISMATCH, recordType.getName()); -// } -// -// @SuppressWarnings("unchecked") -// private static ArrayList getNamespace(RecordType recordType) { -// BMap annotations = recordType.getAnnotations(); -// ArrayList namespace = new ArrayList<>(); -// for (BString annotationsKey : annotations.getKeys()) { -// String key = annotationsKey.getValue(); -// if (!key.contains(Constants.FIELD) && key.endsWith(Constants.NAMESPACE)) { -// BMap namespaceAnnotation = (BMap) annotations.get(annotationsKey); -// namespace.add(namespaceAnnotation.containsKey(Constants.PREFIX) ? -// ((BString) namespaceAnnotation.get(Constants.PREFIX)).getValue() : ""); -// namespace.add(((BString) namespaceAnnotation.get(Constants.URI)).getValue()); -// break; -// } -// } -// return namespace; -// } -// -// @SuppressWarnings("unchecked") -// public static Map getAllFieldsInRecordType(RecordType recordType, -// CsvAnalyzerData analyzerData) { -// BMap annotations = recordType.getAnnotations(); -// HashMap modifiedNames = new LinkedHashMap<>(); -// for (BString annotationKey : annotations.getKeys()) { -// String keyStr = annotationKey.getValue(); -// if (keyStr.contains(Constants.FIELD)) { -// // Capture namespace and name from the field annotation. -// String fieldName = keyStr.split(Constants.FIELD_REGEX)[1].replaceAll("\\\\", ""); -// Map fieldAnnotation = (Map) annotations.get(annotationKey); -// QualifiedName fieldQName = DataUtils.getFieldNameFromRecord(fieldAnnotation, fieldName); -// fieldQName.setLocalPart(getModifiedName(fieldAnnotation, fieldName)); -// modifiedNames.put(fieldName, fieldQName); -// } -// } -// -// Map fields = new HashMap<>(); -// Map recordFields = recordType.getFields(); -// for (String key : recordFields.keySet()) { -// QualifiedName modifiedQName = modifiedNames.getOrDefault(key, -// new QualifiedName(QualifiedName.NS_ANNOT_NOT_DEFINED, key, "")); -// if (fields.containsKey(modifiedQName)) { -// throw DiagnosticLog.error(DiagnosticErrorCode.DUPLICATE_FIELD, modifiedQName.getLocalPart()); -// } else if (analyzerData.attributeHierarchy.peek().containsKey(modifiedQName)) { -// continue; -// } -// fields.put(modifiedQName, recordFields.get(key)); -// } -// return fields; -// } -// -// @SuppressWarnings("unchecked") -// public static Map getAllAttributesInRecordType(RecordType recordType) { -// BMap annotations = recordType.getAnnotations(); -// Map attributes = new HashMap<>(); -// for (BString annotationKey : annotations.getKeys()) { -// String keyStr = annotationKey.getValue(); -// if (keyStr.contains(Constants.FIELD) && DataUtils.isAttributeField(annotationKey, annotations)) { -// String attributeName = keyStr.split(Constants.FIELD_REGEX)[1].replaceAll("\\\\", ""); -// Map fieldAnnotation = (Map) annotations.get(annotationKey); -// QualifiedName fieldQName = getFieldNameFromRecord(fieldAnnotation, attributeName); -// fieldQName.setLocalPart(getModifiedName(fieldAnnotation, attributeName)); -// attributes.put(fieldQName, recordType.getFields().get(attributeName)); -// } -// } -// return attributes; -// } -// -// @SuppressWarnings("unchecked") -// public static QualifiedName getFieldNameFromRecord(Map fieldAnnotation, String fieldName) { -// for (BString key : fieldAnnotation.keySet()) { -// if (key.getValue().endsWith(Constants.NAMESPACE)) { -// Map namespaceAnnotation = ((Map) fieldAnnotation.get(key)); -// BString uri = (BString) namespaceAnnotation.get(Constants.URI); -// BString prefix = (BString) namespaceAnnotation.get(Constants.PREFIX); -// return new QualifiedName(uri == null ? "" : uri.getValue(), fieldName, -// prefix == null ? "" : prefix.getValue()); -// } -// } -// return new QualifiedName(QualifiedName.NS_ANNOT_NOT_DEFINED, fieldName, ""); -// } -// -// @SuppressWarnings("unchecked") -// private static String getModifiedName(Map fieldAnnotation, String attributeName) { -// for (BString key : fieldAnnotation.keySet()) { -// if (key.getValue().endsWith(Constants.NAME)) { -// return ((Map) fieldAnnotation.get(key)).get(Constants.VALUE).toString(); -// } -// } -// return attributeName; -// } -// -// public static BArray createNewAnydataList(Type type) { -// return ValueCreator.createArrayValue(getArrayTypeFromElementType(type)); -// } -// -// public static QualifiedName getElementName(QName qName) { -// return new QualifiedName(qName.getNamespaceURI(), qName.getLocalPart(), qName.getPrefix()); -// } -// -// public static Object convertStringToExpType(BString value, Type expType) { -// Object result; -// switch (expType.getTag()) { -// case TypeTags.ANYDATA_TAG, TypeTags.ANY_TAG, TypeTags.JSON_TAG -> -// result = FromString.fromStringWithTypeInternal(value, PredefinedTypes.TYPE_STRING); -// case TypeTags.ARRAY_TAG -> result = convertStringToExpType(value, ((ArrayType) expType).getElementType()); -// default -> result = FromString.fromStringWithTypeInternal(value, expType); -// } -// -// if (result instanceof BError) { -// throw (BError) result; -// } -// return result; -// } -// -// public static void validateRequiredFields(BMap currentMapValue, CsvAnalyzerData analyzerData) { -// Map fields = analyzerData.fieldHierarchy.peek(); -// for (QualifiedName key : fields.keySet()) { -// // Validate required array size -// Field field = fields.get(key); -// String fieldName = field.getFieldName(); -// if (field.getFieldType().getTag() == TypeTags.ARRAY_TAG) { -// ArrayType arrayType = (ArrayType) field.getFieldType(); -// if (arrayType.getSize() != -1 -// && arrayType.getSize() != ((BArray) currentMapValue.get( -// StringUtils.fromString(fieldName))).getLength()) { -// throw DiagnosticLog.error(DiagnosticErrorCode.ARRAY_SIZE_MISMATCH); -// } -// } -// -// if (!SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL) -// && !currentMapValue.containsKey(StringUtils.fromString(fieldName))) { -// throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, fieldName); -// } -// } -// -// Map attributes = analyzerData.attributeHierarchy.peek(); -// for (QualifiedName key : attributes.keySet()) { -// Field field = attributes.get(key); -// String fieldName = field.getFieldName(); -// if (!SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL)) { -// throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_ATTRIBUTE_NOT_PRESENT, fieldName); -// } -// } -// } -// -// public static boolean isArrayValueAssignable(int typeTag) { -// return typeTag == TypeTags.ARRAY_TAG || typeTag == TypeTags.ANYDATA_TAG || typeTag == TypeTags.JSON_TAG; -// } -// -// public static boolean isStringValueAssignable(int typeTag) { -// return typeTag == TypeTags.STRING_TAG || typeTag == TypeTags.ANYDATA_TAG || typeTag == TypeTags.JSON_TAG; -// } -// -// public static ArrayType getValidArrayType(Type type) { -// return switch (type.getTag()) { -// case TypeTags.ARRAY_TAG -> (ArrayType) type; -// case TypeTags.ANYDATA_TAG -> PredefinedTypes.TYPE_ANYDATA_ARRAY; -// case TypeTags.JSON_TAG -> PredefinedTypes.TYPE_JSON_ARRAY; -// default -> null; -// }; -// } -// -// public static ArrayType getArrayTypeFromElementType(Type type) { -// return switch (type.getTag()) { -// case TypeTags.ARRAY_TAG -> TypeCreator.createArrayType(((ArrayType) type).getElementType()); -// case TypeTags.JSON_TAG -> PredefinedTypes.TYPE_JSON_ARRAY; -// case TypeTags.INT_TAG, TypeTags.FLOAT_TAG, TypeTags.STRING_TAG, TypeTags.BOOLEAN_TAG, TypeTags.BYTE_TAG, -// TypeTags.DECIMAL_TAG, TypeTags.RECORD_TYPE_TAG, TypeTags.MAP_TAG, TypeTags.OBJECT_TYPE_TAG, -// TypeTags.CSV_TAG, TypeTags.NULL_TAG -> TypeCreator.createArrayType(type); -// case TypeTags.TYPE_REFERENCED_TYPE_TAG -> getArrayTypeFromElementType(TypeUtils.getReferredType(type)); -// default -> PredefinedTypes.TYPE_ANYDATA_ARRAY; -// }; -// } -// -// public static MapType getMapTypeFromConstraintType(Type constraintType) { -// return switch (constraintType.getTag()) { -// case TypeTags.MAP_TAG -> (MapType) constraintType; -// case TypeTags.INT_TAG, TypeTags.FLOAT_TAG, TypeTags.STRING_TAG, TypeTags.BOOLEAN_TAG, TypeTags.BYTE_TAG, -// TypeTags.DECIMAL_TAG, TypeTags.JSON_TAG, TypeTags.RECORD_TYPE_TAG, TypeTags.OBJECT_TYPE_TAG, -// TypeTags.CSV_TAG, TypeTags.NULL_TAG -> TypeCreator.createMapType(constraintType); -// case TypeTags.ARRAY_TAG -> TypeCreator.createMapType(((ArrayType) constraintType).getElementType()); -// case TypeTags.TYPE_REFERENCED_TYPE_TAG -> -// getMapTypeFromConstraintType(TypeUtils.getReferredType(constraintType)); -// default -> TypeCreator.createMapType(PredefinedTypes.TYPE_ANYDATA); -// }; -// } -// -// public static void updateExpectedTypeStacks(RecordType recordType, CsvAnalyzerData analyzerData) { -// analyzerData.attributeHierarchy.push(new HashMap<>(getAllAttributesInRecordType(recordType))); -// analyzerData.fieldHierarchy.push(new HashMap<>(getAllFieldsInRecordType(recordType, analyzerData))); -// analyzerData.restTypes.push(recordType.getRestFieldType()); -// } -// -// public static void removeExpectedTypeStacks(CsvAnalyzerData analyzerData) { -// analyzerData.attributeHierarchy.pop(); -// analyzerData.fieldHierarchy.pop(); -// analyzerData.restTypes.pop(); -// } -// -// @SuppressWarnings("unchecked") -// public static Object getModifiedRecord(BMap input, BTypedesc type) { -// Type describingType = type.getDescribingType(); -// if (describingType.getTag() == TypeTags.MAP_TAG) { -// Type constraintType = TypeUtils.getReferredType(((MapType) describingType).getConstrainedType()); -// switch (constraintType.getTag()) { -// case TypeTags.ARRAY_TAG -> { -// return processArrayValue(input, (ArrayType) constraintType); -// } -// case TypeTags.MAP_TAG -> { -// BMap jsonMap = -// ValueCreator.createMapValue(TypeCreator.createMapType(PredefinedTypes.TYPE_CSV)); -// for (Map.Entry entry : input.entrySet()) { -// jsonMap.put(entry.getKey(), entry.getValue()); -// } -// return jsonMap; -// } -// case TypeTags.UNION_TAG -> { -// return DiagnosticLog.error(DiagnosticErrorCode.UNSUPPORTED_TYPE); -// } -// } -// } -// if (describingType.getTag() == TypeTags.RECORD_TYPE_TAG && -// describingType.getFlags() != Constants.DEFAULT_TYPE_FLAG) { -// BArray jsonArray = ValueCreator.createArrayValue(PredefinedTypes.TYPE_JSON_ARRAY); -// BMap recordField = addFields(input, type.getDescribingType()); -// BMap processedRecord = processParentAnnotation(type.getDescribingType(), recordField); -// BString rootTagName = processedRecord.getKeys()[0]; -// jsonArray.append(processedRecord.get(rootTagName)); -// jsonArray.append(rootTagName); -// return jsonArray; -// } -// return input; -// } -// -// @SuppressWarnings("unchecked") -// private static BMap processArrayValue(BMap input, ArrayType arrayType) { -// Type elementType = TypeUtils.getReferredType(arrayType.getElementType()); -// switch (elementType.getTag()) { -// case TypeTags.RECORD_TYPE_TAG -> { -// BMap jsonMap = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// for (Map.Entry entry : input.entrySet()) { -// List> records = new ArrayList<>(); -// BArray arrayValue = (BArray) entry.getValue(); -// for (int i = 0; i < arrayValue.getLength(); i++) { -// BMap record = addFields(((BMap) arrayValue.get(i)), -// elementType); -// BMap parentRecord = processParentAnnotation(elementType, record); -// // Remove parent element -// records.add((BMap) parentRecord.get(parentRecord.getKeys()[0])); -// } -// jsonMap.put(entry.getKey(), ValueCreator.createArrayValue(records.toArray(), -// TypeCreator.createArrayType(elementType))); -// } -// return jsonMap; -// } -// case TypeTags.CSV_TAG -> { -// ArrayType csvArrayType = TypeCreator.createArrayType(PredefinedTypes.TYPE_CSV); -// BMap jsonMap = -// ValueCreator.createMapValue(TypeCreator.createMapType(csvArrayType)); -// for (Map.Entry entry : input.entrySet()) { -// BArray arrayValue = (BArray) entry.getValue(); -// BArray csvArrayValue = ValueCreator.createArrayValue(csvArrayType); -// for (int i = 0; i < arrayValue.getLength(); i++) { -// csvArrayValue.append(arrayValue.get(i)); -// } -// jsonMap.put(entry.getKey(), csvArrayValue); -// } -// return jsonMap; -// } -// default -> { -// return input; -// } -// } -// } -// -// @SuppressWarnings("unchecked") -// private static BMap addFields(BMap input, Type type) { -// BMap recordValue = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// Map fields = ((RecordType) type).getFields(); -// BMap annotations = ((RecordType) type).getAnnotations(); -// for (Map.Entry entry: input.entrySet()) { -// String key = entry.getKey().getValue(); -// Object value = entry.getValue(); -// if (fields.containsKey(key)) { -// Type fieldType = fields.get(key).getFieldType(); -// fieldType = getTypeFromUnionType(fieldType, value); -// if (fieldType.getTag() == TypeTags.RECORD_TYPE_TAG) { -// processRecord(key, annotations, recordValue, value, fieldType); -// } else if (fieldType.getTag() == TypeTags.TYPE_REFERENCED_TYPE_TAG) { -// Type referredType = TypeUtils.getReferredType(fieldType); -// if (annotations.size() > 0) { -// key = getKeyNameFromAnnotation(annotations, key); -// } -// BMap subRecordAnnotations = ((RecordType) referredType).getAnnotations(); -// key = getElementName(subRecordAnnotations, key); -// BMap annotationRecord = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// processSubRecordAnnotation(subRecordAnnotations, annotationRecord); -// BMap subRecordValue = addFields(((BMap) value), referredType); -// if (annotationRecord.size() > 0) { -// subRecordValue.put(annotationRecord.getKeys()[0], -// annotationRecord.get(annotationRecord.getKeys()[0])); -// } -// recordValue.put(StringUtils.fromString(key), subRecordValue); -// } else if (fieldType.getTag() == TypeTags.ARRAY_TAG) { -// processArray(fieldType, annotations, recordValue, entry); -// } else { -// addPrimitiveValue(addFieldNamespaceAnnotation(key, annotations, recordValue), -// annotations, recordValue, value); -// } -// } else { -// recordValue.put(StringUtils.fromString(key), value); -// } -// } -// return recordValue; -// } -// -// @SuppressWarnings("unchecked") -// private static QName addFieldNamespaceAnnotation(String key, BMap annotations, -// BMap recordValue) { -// BString annotationKey = -// StringUtils.fromString((Constants.FIELD + key).replace(Constants.COLON, "\\:")); -// boolean isAttributeField = isAttributeField(annotationKey, annotations); -// if (annotations.containsKey(annotationKey)) { -// BMap annotationValue = (BMap) annotations.get(annotationKey); -// for (BString fieldKey : annotationValue.getKeys()) { -// if (fieldKey.toString().endsWith(Constants.NAMESPACE)) { -// return processFieldNamespaceAnnotation(annotationValue, key, fieldKey, recordValue, -// isAttributeField); -// } -// } -// } -// return new QName("", key, ""); -// } -// -// @SuppressWarnings("unchecked") -// public static boolean isAttributeField(BString annotationKey, BMap annotations) { -// if (!annotations.containsKey(annotationKey)) { -// return false; -// } -// -// BMap annotationValue = (BMap) annotations.get(annotationKey); -// for (BString fieldKey : annotationValue.getKeys()) { -// if (fieldKey.toString().endsWith(Constants.ATTRIBUTE)) { -// return true; -// } -// } -// return false; -// } -// -// @SuppressWarnings("unchecked") -// private static BMap getFieldNamespaceAndNameAnnotations(String key, -// BMap parentAnnotations) { -// BMap nsFieldAnnotation = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// BString annotationKey = -// StringUtils.fromString((Constants.FIELD + key).replace(Constants.COLON, "\\:")); -// if (!parentAnnotations.containsKey(annotationKey)) { -// return nsFieldAnnotation; -// } -// -// BMap annotationValue = (BMap) parentAnnotations.get(annotationKey); -// for (BString fieldKey : annotationValue.getKeys()) { -// String keyName = fieldKey.getValue(); -// if (keyName.endsWith(Constants.NAMESPACE) || keyName.endsWith(Constants.NAME)) { -// nsFieldAnnotation.put(fieldKey, annotationValue.get(fieldKey)); -// break; -// } -// } -// return nsFieldAnnotation; -// } -// -// @SuppressWarnings("unchecked") -// private static void processRecord(String key, BMap parentAnnotations, -// BMap record, Object value, Type childType) { -// BMap parentRecordAnnotations = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// BMap annotation = ((RecordType) childType).getAnnotations(); -// if (parentAnnotations.size() > 0) { -// annotation.merge(getFieldNamespaceAndNameAnnotations(key, parentAnnotations), true); -// processSubRecordAnnotation(parentAnnotations, parentRecordAnnotations); -// } -// BMap subRecord = addFields(((BMap) value), childType); -// if (annotation.size() > 0) { -// processSubRecordAnnotation(annotation, subRecord); -// } -// key = getElementName(annotation, key); -// record.put(StringUtils.fromString(key), subRecord); -// if (parentRecordAnnotations.size() > 0) { -// record.put(parentRecordAnnotations.getKeys()[0], -// parentRecordAnnotations.get(parentRecordAnnotations.getKeys()[0])); -// } -// } -// -// @SuppressWarnings("unchecked") -// private static void addPrimitiveValue(QName qName, BMap annotations, -// BMap record, Object value) { -// BString localPart = StringUtils.fromString(qName.getLocalPart()); -// BString key = qName.getPrefix().isBlank() ? -// localPart : StringUtils.fromString(qName.getPrefix() + ":" + localPart); -// BString annotationKey = -// StringUtils.fromString((Constants.FIELD + localPart).replace(Constants.COLON, "\\:")); -// BMap currentValue; -// if (record.containsKey(key)) { -// currentValue = (BMap) record.get(key); -// key = StringUtils.fromString(Constants.CONTENT); -// } else { -// currentValue = record; -// } -// -// if (annotations.containsKey(annotationKey)) { -// BMap annotationValue = (BMap) annotations.get(annotationKey); -// currentValue.put(StringUtils.fromString(processFieldAnnotation(annotationValue, key.getValue())), value); -// } else { -// currentValue.put(key, value); -// } -// } -// -// @SuppressWarnings("unchecked") -// private static void processArray(Type childType, BMap annotations, -// BMap record, Map.Entry entry) { -// Type elementType = TypeUtils.getReferredType(((ArrayType) childType).getElementType()); -// BMap annotationRecord = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// String keyName = entry.getKey().getValue(); -// if (annotations.size() > 0) { -// keyName = getKeyNameFromAnnotation(annotations, keyName); -// processSubRecordAnnotation(annotations, annotationRecord); -// } -// BArray arrayValue = (BArray) entry.getValue(); -// if (elementType.getTag() == TypeTags.RECORD_TYPE_TAG) { -// List> records = new ArrayList<>(); -// for (int i = 0; i < arrayValue.getLength(); i++) { -// BMap subRecord = addFields(((BMap) arrayValue.get(i)), -// elementType); -// subRecord = processParentAnnotation(elementType, subRecord); -// records.add((BMap) subRecord.get(subRecord.getKeys()[0])); -// } -// record.put( -// StringUtils.fromString(getElementName(((RecordType) elementType).getAnnotations(), keyName)), -// ValueCreator.createArrayValue(records.toArray(), -// TypeCreator.createArrayType(Constants.JSON_ARRAY_TYPE))); -// } else { -// List records = new ArrayList<>(); -// for (int i = 0; i < arrayValue.getLength(); i++) { -// records.add(arrayValue.get(i)); -// } -// record.put(StringUtils.fromString(keyName), ValueCreator.createArrayValue(records.toArray(), -// TypeCreator.createArrayType(Constants.JSON_ARRAY_TYPE))); -// } -// if (annotationRecord.size() > 0) { -// record.put(annotationRecord.getKeys()[0], -// annotationRecord.get(annotationRecord.getKeys()[0])); -// } -// } -// -// @SuppressWarnings("unchecked") -// private static String getKeyNameFromAnnotation(BMap annotations, String keyName) { -// BString annotationKey = StringUtils.fromString((Constants.FIELD + keyName). -// replace(Constants.COLON, "\\:")); -// if (annotations.containsKey(annotationKey)) { -// BMap annotationValue = (BMap) annotations.get(annotationKey); -// return processFieldAnnotation(annotationValue, keyName); -// } -// return keyName; -// } -// -// public static Type getTypeFromUnionType(Type childType, Object value) { -// if (childType instanceof UnionType bUnionType) { -// for (Type memberType : bUnionType.getMemberTypes()) { -// if (value.getClass().getName().toUpperCase(Locale.ROOT).contains( -// memberType.getName().toUpperCase(Locale.ROOT))) { -// childType = TypeUtils.getReferredType(memberType); -// } -// } -// } -// return childType; -// } -// -// private static BMap processParentAnnotation(Type type, BMap record) { -// BMap parentRecord = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// BMap namespaces = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// BMap annotations = ((RecordType) type).getAnnotations(); -// BString rootName = processAnnotation(annotations, type.getName(), namespaces); -// if (namespaces.size() > 0) { -// for (Map.Entry namespace : namespaces.entrySet()) { -// record.put(namespace.getKey(), namespace.getValue()); -// } -// } -// parentRecord.put(rootName, record); -// return parentRecord; -// } -// -// @SuppressWarnings("unchecked") -// private static String processFieldAnnotation(BMap annotation, String key) { -// for (BString value : annotation.getKeys()) { -// String stringValue = value.getValue(); -// if (stringValue.endsWith(Constants.NAME)) { -// BMap names = (BMap) annotation.get(value); -// String name = names.get(StringUtils.fromString(VALUE)).toString(); -// if (key.contains(Constants.COLON)) { -// key = key.substring(0, key.indexOf(Constants.COLON) + 1) + name; -// } else if (key.contains(ATTRIBUTE_PREFIX)) { -// key = key.substring(0, key.indexOf(Constants.UNDERSCORE) + 1) + name; -// } else { -// key = name; -// } -// } -// if (stringValue.endsWith(Constants.ATTRIBUTE)) { -// key = ATTRIBUTE_PREFIX.concat(key); -// } -// } -// return key; -// } -// -// private static BString processAnnotation(BMap annotation, String key, -// BMap namespaces) { -// boolean hasNamespaceAnnotation = false; -// for (BString value : annotation.getKeys()) { -// if (!value.getValue().contains(Constants.FIELD)) { -// String stringValue = value.getValue(); -// if (stringValue.endsWith(Constants.NAME)) { -// key = processNameAnnotation(annotation, key, value, hasNamespaceAnnotation); -// } -// if (stringValue.endsWith(Constants.NAMESPACE)) { -// hasNamespaceAnnotation = true; -// key = processNamespaceAnnotation(annotation, key, value, namespaces); -// } -// } -// } -// return StringUtils.fromString(key); -// } -// -// private static void processSubRecordAnnotation(BMap annotation, BMap subRecord) { -// BString[] keys = annotation.getKeys(); -// for (BString value : keys) { -// if (value.getValue().endsWith(Constants.NAMESPACE)) { -// processNamespaceAnnotation(annotation, "", value, subRecord); -// } -// } -// } -// -// @SuppressWarnings("unchecked") -// private static String getElementName(BMap annotation, String key) { -// BString[] keys = annotation.getKeys(); -// boolean hasNamespaceAnnotation = false; -// for (BString value : keys) { -// if (value.getValue().endsWith(Constants.NAMESPACE)) { -// hasNamespaceAnnotation = true; -// BMap namespaceAnnotation = (BMap) annotation.get(value); -// BString prefix = (BString) namespaceAnnotation.get(Constants.PREFIX); -// if (prefix != null) { -// key = prefix.getValue().concat(Constants.COLON).concat(key); -// } -// } -// if (value.getValue().endsWith(Constants.NAME)) { -// key = processNameAnnotation(annotation, key, value, hasNamespaceAnnotation); -// } -// } -// return key; -// } -// -// @SuppressWarnings("unchecked") -// private static String processNameAnnotation(BMap annotation, String key, BString value, -// boolean hasNamespaceAnnotation) { -// String nameValue = ((BMap) annotation.get(value)). -// get(StringUtils.fromString(VALUE)).toString(); -// if (hasNamespaceAnnotation) { -// return key.substring(0, key.indexOf(Constants.COLON) + 1) + nameValue; -// } else { -// return nameValue; -// } -// } -// -// @SuppressWarnings("unchecked") -// private static String processNamespaceAnnotation(BMap annotation, String key, BString value, -// BMap subRecord) { -// BMap namespaceAnnotation = (BMap) annotation.get(value); -// BString uri = (BString) namespaceAnnotation.get(Constants.URI); -// BString prefix = (BString) namespaceAnnotation.get(Constants.PREFIX); -// if (prefix == null) { -// subRecord.put(StringUtils.fromString(ATTRIBUTE_PREFIX + "csvns"), uri); -// } else { -// subRecord.put(StringUtils.fromString(ATTRIBUTE_PREFIX + "csvns:" + prefix), uri); -// key = prefix.getValue().concat(Constants.COLON).concat(key); -// } -// return key; -// } -// -// @SuppressWarnings("unchecked") -// private static QName processFieldNamespaceAnnotation(BMap annotation, String key, BString value, -// BMap subRecord, boolean isAttributeField) { -// BMap namespaceAnnotation = (BMap) annotation.get(value); -// BString uri = (BString) namespaceAnnotation.get(Constants.URI); -// BString prefix = (BString) namespaceAnnotation.get(Constants.PREFIX); -// QName qName = new QName(uri == null ? "" : uri.getValue(), key, prefix == null ? "" : prefix.getValue()); -// if (isAttributeField) { -// addAttributeToRecord(prefix, uri, key, subRecord); -// } else { -// BMap nextMapValue = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// key = addAttributeToRecord(prefix, uri, key, nextMapValue); -// subRecord.put(StringUtils.fromString(key), nextMapValue); -// } -// return qName; -// } -// -// private static String addAttributeToRecord(BString prefix, BString uri, String key, -// BMap subRecord) { -// if (prefix == null) { -// subRecord.put(StringUtils.fromString(ATTRIBUTE_PREFIX + "csvns"), uri); -// return key; -// } -// subRecord.put(StringUtils.fromString(ATTRIBUTE_PREFIX + "csvns:" + prefix), uri); -// return prefix.getValue().concat(Constants.COLON).concat(key); -// } -// -// /** -// * Holds data required for the traversing. -// * -// * @since 0.1.0 -// */ -// public static class CsvAnalyzerData { -// public boolean mapContext = false; -// } -//} From 41270d7fc68a67bf7e5050cd1d5a0776668d3b62 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Sun, 18 Feb 2024 19:40:02 +0530 Subject: [PATCH 006/147] Update csv var names --- .../csv/BallerinaByteBlockInputStream.java | 168 ------------------ .../stdlib/data/csvdata/csv/CsvCreator.java | 132 +------------- .../stdlib/data/csvdata/csv/CsvParser.java | 2 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 10 +- .../data/csvdata/io/DataReaderThreadPool.java | 2 +- .../csvdata/utils/DiagnosticErrorCode.java | 28 +-- .../data/csvdata/utils/DiagnosticLog.java | 11 +- native/src/main/resources/error.properties | 60 ++----- 8 files changed, 45 insertions(+), 368 deletions(-) delete mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/BallerinaByteBlockInputStream.java diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/BallerinaByteBlockInputStream.java deleted file mode 100644 index 5212335..0000000 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/BallerinaByteBlockInputStream.java +++ /dev/null @@ -1,168 +0,0 @@ -///* -// * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// * -// * WSO2 LLC. licenses this file to you under the Apache License, -// * Version 2.0 (the "License"); you may not use this file except -// * in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, -// * software distributed under the License is distributed on an -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// * KIND, either express or implied. See the License for the -// * specific language governing permissions and limitations -// * under the License. -// */ -// -//package io.ballerina.stdlib.data.csvdata.csv; -// -//import io.ballerina.runtime.api.Environment; -//import io.ballerina.runtime.api.async.Callback; -//import io.ballerina.runtime.api.async.StrandMetadata; -//import io.ballerina.runtime.api.types.MethodType; -//import io.ballerina.runtime.api.types.Type; -//import io.ballerina.runtime.api.values.BArray; -//import io.ballerina.runtime.api.values.BError; -//import io.ballerina.runtime.api.values.BMap; -//import io.ballerina.runtime.api.values.BObject; -//import io.ballerina.runtime.api.values.BString; -//import io.ballerina.stdlib.data.csvdata.csv.utils.DiagnosticErrorCode; -//import io.ballerina.stdlib.data.csvdata.csv.utils.DiagnosticLog; -// -//import java.io.IOException; -//import java.io.InputStream; -//import java.util.Arrays; -//import java.util.Map; -//import java.util.concurrent.Semaphore; -//import java.util.concurrent.atomic.AtomicBoolean; -//import java.util.function.Consumer; -// -///** -// * Java Input Stream based on Ballerina byte block stream. stream -// * -// * @since 0.1.0 -// */ -//public class BallerinaByteBlockInputStream extends InputStream { -// -// private final BObject iterator; -// private final Environment env; -// private final String nextMethodName; -// private final Type returnType; -// private final String strandName; -// private final StrandMetadata metadata; -// private final Map properties; -// private final AtomicBoolean done = new AtomicBoolean(false); -// private final MethodType closeMethod; -// private final Consumer futureResultConsumer; -// -// private byte[] currentChunk = new byte[0]; -// private int nextChunkIndex = 0; -// -// public BallerinaByteBlockInputStream(Environment env, BObject iterator, MethodType nextMethod, -// MethodType closeMethod, Consumer futureResultConsumer) { -// this.env = env; -// this.iterator = iterator; -// this.nextMethodName = nextMethod.getName(); -// this.returnType = nextMethod.getReturnType(); -// this.closeMethod = closeMethod; -// this.strandName = env.getStrandName().orElse(""); -// this.metadata = env.getStrandMetadata(); -// this.properties = Map.of(); -// this.futureResultConsumer = futureResultConsumer; -// } -// -// @Override -// public int read() { -// if (done.get()) { -// return -1; -// } -// if (hasBytesInCurrentChunk()) { -// return currentChunk[nextChunkIndex++]; -// } -// // Need to get a new block from the stream, before reading again. -// nextChunkIndex = 0; -// try { -// if (readNextChunk()) { -// return read(); -// } -// } catch (InterruptedException e) { -// BError error = DiagnosticLog.error(DiagnosticErrorCode.CAN_NOT_READ_STREAM); -// futureResultConsumer.accept(error); -// return -1; -// } -// return -1; -// } -// -// @Override -// public void close() throws IOException { -// super.close(); -// Semaphore semaphore = new Semaphore(0); -// if (closeMethod != null) { -// env.getRuntime().invokeMethodAsyncSequentially(iterator, closeMethod.getName(), strandName, metadata, -// new Callback() { -// @Override -// public void notifyFailure(BError bError) { -// semaphore.release(); -// } -// -// @Override -// public void notifySuccess(Object result) { -// semaphore.release(); -// } -// }, properties, returnType); -// } -// try { -// semaphore.acquire(); -// } catch (InterruptedException e) { -// throw new IOException("Error while closing the stream", e); -// } -// } -// -// private boolean hasBytesInCurrentChunk() { -// return currentChunk.length != 0 && nextChunkIndex < currentChunk.length; -// } -// -// private boolean readNextChunk() throws InterruptedException { -// Semaphore semaphore = new Semaphore(0); -// Callback callback = new Callback() { -// -// @Override -// public void notifyFailure(BError bError) { -// // Panic with an error -// done.set(true); -// futureResultConsumer.accept(bError); -// currentChunk = new byte[0]; -// semaphore.release(); -// // TODO : Should we panic here? -// } -// -// @Override -// public void notifySuccess(Object result) { -// if (result == null) { -// done.set(true); -// currentChunk = new byte[0]; -// semaphore.release(); -// return; -// } -// if (result instanceof BMap) { -// BMap valueRecord = (BMap) result; -// final BString value = Arrays.stream(valueRecord.getKeys()).findFirst().get(); -// final BArray arrayValue = valueRecord.getArrayValue(value); -// currentChunk = arrayValue.getByteArray(); -// semaphore.release(); -// } else { -// // Case where Completes with an error -// done.set(true); -// semaphore.release(); -// } -// } -// -// }; -// env.getRuntime().invokeMethodAsyncSequentially(iterator, nextMethodName, strandName, metadata, callback, -// properties, returnType); -// semaphore.acquire(); -// return !done.get(); -// } -//} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 04a72e8..c9d2e37 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -33,17 +33,11 @@ import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.data.csvdata.FromString; -import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Optional; - /** - * Create objects for partially parsed json. + * Create objects for partially parsed csv. * * @since 0.1.0 */ @@ -55,10 +49,6 @@ static BMap initRootMapValue(Type expectedType) { return ValueCreator.createRecordValue((RecordType) expectedType); case TypeTags.MAP_TAG: return ValueCreator.createMapValue((MapType) expectedType); -// case TypeTags.JSON_TAG: -// return ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// case TypeTags.ANYDATA_TAG: -// return ValueCreator.createMapValue(Constants.ANYDATA_MAP_TYPE); default: throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType, "map type"); } @@ -70,79 +60,11 @@ static BArray initArrayValue(Type expectedType) { return ValueCreator.createTupleValue((TupleType) expectedType); case TypeTags.ARRAY_TAG: return ValueCreator.createArrayValue((ArrayType) expectedType); -// case TypeTags.JSON_TAG: -// return ValueCreator.createArrayValue(PredefinedTypes.TYPE_JSON_ARRAY); -// case TypeTags.ANYDATA_TAG: -// return ValueCreator.createArrayValue(PredefinedTypes.TYPE_ANYDATA_ARRAY); default: throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType, "list type"); } } -// static Optional> initNewMapValue(CsvParser.StateMachine sm) { -// sm.parserContexts.push(CsvParser.StateMachine.ParserContexts.MAP); -// Type expType = sm.expectedTypes.peek(); -// if (expType == null) { -// return Optional.empty(); -// } -// Type currentType = TypeUtils.getReferredType(expType); -// -// if (sm.currentCsvNode != null) { -// sm.nodesStack.push(sm.currentCsvNode); -// } -// -// BMap nextMapValue; -// switch (currentType.getTag()) { -// case TypeTags.RECORD_TYPE_TAG: -// RecordType recordType = (RecordType) currentType; -// nextMapValue = ValueCreator.createRecordValue(recordType); -// sm.fieldHierarchy.push(new HashMap<>(recordType.getFields())); -// sm.restType.push(recordType.getRestFieldType()); -// break; -// case TypeTags.MAP_TAG: -// nextMapValue = ValueCreator.createMapValue((MapType) currentType); -// sm.fieldHierarchy.push(new HashMap<>()); -// sm.restType.push(((MapType) currentType).getConstrainedType()); -// break; -// case TypeTags.JSON_TAG: -// nextMapValue = ValueCreator.createMapValue(Constants.JSON_MAP_TYPE); -// sm.fieldHierarchy.push(new HashMap<>()); -// sm.restType.push(PredefinedTypes.TYPE_JSON); -// break; -// case TypeTags.ANYDATA_TAG: -// nextMapValue = ValueCreator.createMapValue(Constants.ANYDATA_MAP_TYPE); -// sm.fieldHierarchy.push(new HashMap<>()); -// sm.restType.push(PredefinedTypes.TYPE_JSON); -// break; -// default: -// throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, getCurrentFieldPath(sm)); -// } -// -// Object currentJson = sm.currentCsvNode; -// int valueTypeTag = TypeUtils.getType(currentJson).getTag(); -// if (valueTypeTag == TypeTags.MAP_TAG || valueTypeTag == TypeTags.RECORD_TYPE_TAG) { -// ((BMap) currentJson).put(StringUtils.fromString(sm.fieldNames.get(sm.columnIndex)), nextMapValue); -// } -// return Optional.of(nextMapValue); -// } - -// static Optional initNewArrayValue(CsvParser.StateMachine sm) { -// sm.parserContexts.push(CsvParser.StateMachine.ParserContexts.ARRAY); -// Type expType = sm.expectedTypes.peek(); -// if (expType == null) { -// return Optional.empty(); -// } -// -// Object currentCsvNode = sm.currentCsvNode; -// BArray nextArrValue = initArrayValue(sm.expectedTypes.peek()); -// if (currentCsvNode == null) { -// return Optional.ofNullable(nextArrValue); -// } -// -// sm.nodesStack.push(sm.currentCsvNode); -// return Optional.ofNullable(nextArrValue); -// } - private static String getCurrentFieldPath(CsvParser.StateMachine sm) { // Iterator itr = sm.fieldNames.descendingIterator(); // @@ -158,11 +80,7 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, BString Object currentJson = sm.currentCsvNode; Object convertedValue = convertToExpectedType(value, type); if (convertedValue instanceof BError) { - if (sm.currentField != null) { - throw DiagnosticLog.error(DiagnosticErrorCode.CSV_PARSER_EXCEPTION, value, type, - getCurrentFieldPath(sm)); - } - throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, type, value); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, type, value); } Type currentCsvNodeType = TypeUtils.getType(currentJson); @@ -195,50 +113,4 @@ private static Object convertToExpectedType(BString value, Type type) { } return FromString.fromStringWithType(value, type); } - - static void updateRecordFieldValue(BString fieldName, Object parent, Object currentJson) { - switch (TypeUtils.getType(parent).getTag()) { - case TypeTags.MAP_TAG: - case TypeTags.RECORD_TYPE_TAG: - ((BMap) parent).put(fieldName, currentJson); - break; - } - } - - static Type getMemberType(Type expectedType, int index) { - if (expectedType == null) { - return null; - } - - if (expectedType.getTag() == TypeTags.ARRAY_TAG) { - return ((ArrayType) expectedType).getElementType(); - } else if (expectedType.getTag() == TypeTags.TUPLE_TAG) { - TupleType tupleType = (TupleType) expectedType; - List tupleTypes = tupleType.getTupleTypes(); - if (tupleTypes.size() < index + 1) { - return tupleType.getRestType(); - } - return tupleTypes.get(index); - } else { - return expectedType; - } - } - - static void validateListSize(int currentIndex, Type expType) { - int expLength = 0; - if (expType == null) { - return; - } - - if (expType.getTag() == TypeTags.ARRAY_TAG) { - expLength = ((ArrayType) expType).getSize(); - } else if (expType.getTag() == TypeTags.TUPLE_TAG) { - TupleType tupleType = (TupleType) expType; - expLength = tupleType.getTupleTypes().size(); - } - - if (expLength >= 0 && expLength > currentIndex + 1) { - throw DiagnosticLog.error(DiagnosticErrorCode.ARRAY_SIZE_MISMATCH); - } - } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 7217b23..125da13 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -61,7 +61,7 @@ public static Object parse(Reader reader, Type type) return sm.execute(reader, TypeUtils.getReferredType(type)); } finally { // Need to reset the state machine before leaving. Otherwise, references to the created - // JSON values will be maintained and the java GC will not happen properly. + // CSV values will be maintained and the java GC will not happen properly. sm.reset(); } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index aa851d6..e0f52d5 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -508,21 +508,21 @@ private void checkOptionalFieldsAndLogError(Map currentField) { }); } - private Object convertToBasicType(Object json, Type targetType) { + private Object convertToBasicType(Object csv, Type targetType) { if (targetType.getTag() == TypeTags.READONLY_TAG) { - return json; + return csv; } try { - Object value = JsonUtils.convertJSON(json, targetType); + Object value = JsonUtils.convertJSON(csv, targetType); if (value instanceof String) { return StringUtils.fromString(value.toString()); } return value; } catch (Exception e) { if (fieldNames.isEmpty()) { - throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, targetType, json); + throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, targetType, csv); } - throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, json, targetType, + throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, csv, targetType, "Test"); } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java index 21e9bad..35728b7 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java @@ -34,7 +34,7 @@ public class DataReaderThreadPool { private static final int CORE_POOL_SIZE = 0; private static final int MAX_POOL_SIZE = 50; private static final long KEEP_ALIVE_TIME = 60L; - private static final String THREAD_NAME = "bal-data-jsondata-thread"; + private static final String THREAD_NAME = "bal-data-csv-thread"; public static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS, new SynchronousQueue<>(), new DataThreadFactory()); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index 1b409ce..eab0288 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -26,25 +26,15 @@ public enum DiagnosticErrorCode { INVALID_TYPE("BDE_0001", "invalid.type"), - CSV_ROOT_MISSING("BDE_0002", "csv.root.missing"), - INVALID_REST_TYPE("BDE_0003", "invalid.rest.type"), - ARRAY_SIZE_MISMATCH("BDE_0004", "array.size.mismatch"), - REQUIRED_FIELD_NOT_PRESENT("BDE_0005", "required.field.not.present"), - REQUIRED_ATTRIBUTE_NOT_PRESENT("BDE_0006", "required.attribute.not.present"), - DUPLICATE_FIELD("BDE_0007", "duplicate.field"), - FOUND_ARRAY_FOR_NON_ARRAY_TYPE("BDE_0008", "found.array.for.non.array.type"), - EXPECTED_ANYDATA_OR_JSON("BDE_0009", "expected.anydata.or.json"), - NAMESPACE_MISMATCH("BDE_0010", "namespace.mismatch"), - TYPE_NAME_MISMATCH_WITH_CSV_ELEMENT("BDE_0011", "type.name.mismatch.with.csv.element"), - CAN_NOT_READ_STREAM("BDE_0012", "error.cannot.read.stream"), - CANNOT_CONVERT_TO_EXPECTED_TYPE("BDE_0013", "cannot.convert.to.expected.type"), - UNSUPPORTED_TYPE("BDE_0014", "unsupported.type"), - STREAM_BROKEN("BDE_0015", "stream.broken"), - CSV_PARSE_ERROR("BDE_0016", "csv.parse.error"), - INCOMPATIBLE_TYPE("BDE_0017", "incompatible.error"), - INVALID_TYPE_FOR_FIELD("BDE_18", "invalid.type.for.field.error"), - - CSV_PARSER_EXCEPTION("BDE_19", "invalid.type.for.field.error"); + UNION_TYPES_NOT_ALLOWED("BDE_0002", "union.types.not.allowed.as.expected.type"), + INVALID_ARRAY_MEMBER("BDE_0001", "invalid.array.member.in.expected.type"), + INVALID_FIELD_IN_CSV("BDE_0001", "cannot.found.field.in.csv"), + INVALID_CAST("BDE_0001", "csv.value.cannot.cast.into.expected.type"), + INVALID_EXPECTED_TYPE("BDE_0001", "invalid.expected.type"), + INVALID_TOKEN("BDE_0001", "invalid.token.while.reading.the.csv.data"), + INVALID_CSV_DATA_FORMAT("BDE_0001", "invalid.csv.data.format"), + INVALID_EXPECTED_ARRAY_SIZE("BDE_0001", "invalid.expected.array.size"), + INVALID_EXPECTED_TUPLE_SIZE("BDE_0001", "invalid.expected.tuple.size"); String diagnosticId; String messageKey; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java index 2ed80ae..df57a48 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java @@ -33,7 +33,8 @@ */ public class DiagnosticLog { private static final String ERROR_PREFIX = "error"; - private static final String ERROR = "Error"; + private static final String CSV_CONVERSION_ERROR = "CsvConversionError"; + private static final String UNSUPPORTED_OPERATION_ERROR = "CsvConversionError"; private static final ResourceBundle MESSAGES = ResourceBundle.getBundle("error", Locale.getDefault()); public static BError error(DiagnosticErrorCode code, Object... args) { @@ -46,8 +47,12 @@ private static String formatMessage(DiagnosticErrorCode code, Object[] args) { return MessageFormat.format(msgKey, args); } + public static BError getCsvError(String message, String errorType) { + return ErrorCreator.createError(io.ballerina.stdlib.data.csvdata.utils.ModuleUtils.getModule(), + errorType, StringUtils.fromString(message), null, null); + } + public static BError getCsvError(String message) { - return ErrorCreator.createError(io.ballerina.stdlib.data.csvdata.utils.ModuleUtils.getModule(), ERROR, StringUtils.fromString(message), - null, null); + return getCsvError(message, CSV_CONVERSION_ERROR); } } diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index 8575c97..03f225e 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -21,55 +21,33 @@ # ------------------------- error.invalid.type=\ - invalid type expected ''{0}'' but found ''{1}'' + invalid expected type ''{0}'' -error.csv.root.missing=\ - csv root element is missing +error.union.types.not.allowed.as.expected.type=\ + union types are not allowed in the expected type, found ''{0}'' -error.invalid.rest.type=\ - invalid rest type ''{0}'' +error.invalid.array.member.in.expected.type=\ + invalid type ''{0}'' in the expected array type -error.array.size.mismatch=\ - array size is not compatible with the expected size +error.cannot.found.field.in.csv=\ + no matching header value is found for the required field ''{0}'' -error.required.field.not.present=\ - required field ''{0}'' not present in CSV +error.csv.value.cannot.cast.into.expected.type=\ + value ''{0}'' cannot be cast into ''{1}'' -error.required.attribute.not.present=\ - required attribute ''{0}'' not present in CSV +error.invalid.expected.type=\ + expected a array type, found ''{0}'' -error.duplicate.field=\ - duplicate field ''{0}'' +error.invalid.token.while.reading.the.csv.data=\ + error while reading the csv data ''{0}'' -error.found.array.for.non.array.type=\ - expected ''{0}'' value for the field ''{1}'' found ''array'' value +error.invalid.csv.data.format=\ + invalid csv data format -error.expected.anydata.or.json=\ - incompatible type expected anydata or json +error.invalid.expected.array.size=\ + invalid array size for expected array type, cannot be greater than ''{0}'' -error.namespace.mismatch=\ - namespace mismatched for the type: ''{0}'' +error.invalid.expected.tuple.size=\ + invalid array size for expected tuple type, cannot be greater than ''{0}'' -error.type.name.mismatch.with.csv.element=\ - record type name ''{0}'' mismatch with given CSV name ''{1}'' -error.cannot.read.stream=\ - cannot read the stream, interrupted error - -error.cannot.convert.to.expected.type=\ - ''{0}'' value ''{1}'' cannot be converted to ''{2}'' - -error.unsupported.type=\ - unsupported input type - -error.stream.broken=\ - error occurred while reading the stream: ''{0}'' - -error.csv.parse.error=\ - failed to parse csv: ''{0}'' - -error.incompatible.error=\ - incompatible type ''{0}'',''{1}'' - -error.invalid.type.for.field.error=\ - invalid type for field ''{0}'' From ee61184fa18d0b85788331f43e07cace6b1d9907 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Sun, 18 Feb 2024 20:09:49 +0530 Subject: [PATCH 007/147] Update error diagnostic codes --- .../stdlib/data/csvdata/csv/CsvCreator.java | 4 +-- .../stdlib/data/csvdata/csv/CsvParser.java | 15 ++++---- .../stdlib/data/csvdata/csv/CsvTraversal.java | 35 +++++++------------ .../stdlib/data/csvdata/csv/Native.java | 4 +-- native/src/main/resources/error.properties | 2 +- 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index c9d2e37..38f649a 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -50,7 +50,7 @@ static BMap initRootMapValue(Type expectedType) { case TypeTags.MAP_TAG: return ValueCreator.createMapValue((MapType) expectedType); default: - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType, "map type"); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } } @@ -61,7 +61,7 @@ static BArray initArrayValue(Type expectedType) { case TypeTags.ARRAY_TAG: return ValueCreator.createArrayValue((ArrayType) expectedType); default: - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType, "list type"); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 125da13..6c3b6af 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -18,7 +18,6 @@ package io.ballerina.stdlib.data.csvdata.csv; -import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; @@ -161,7 +160,7 @@ private String value() { public Object execute(Reader reader, Type type) throws BError { Type referredType = TypeUtils.getReferredType(type); if (referredType.getTag() != TypeTags.ARRAY_TAG) { - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type); } else { rootCsvNode = ValueCreator.createArrayValue((ArrayType) type); expectedArrayElementType = ((ArrayType) TypeUtils.getReferredType(referredType)).getElementType(); @@ -184,7 +183,7 @@ public Object execute(Reader reader, Type type) throws BError { break; // TODO: Check to add Union types as well default: - throw DiagnosticLog.error(DiagnosticErrorCode.CSV_PARSER_EXCEPTION); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); } boolean header = true; State currentState; @@ -204,9 +203,9 @@ public Object execute(Reader reader, Type type) throws BError { } return rootCsvNode; } catch (IOException e) { - throw DiagnosticLog.error(DiagnosticErrorCode.CSV_PARSER_EXCEPTION, e.getMessage()); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TOKEN, e.getMessage(), line, column); } catch (CsvParserException e) { - throw DiagnosticLog.error(DiagnosticErrorCode.CSV_PARSER_EXCEPTION, e.getMessage(), line, column); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TOKEN, e.getMessage(), line, column); } } @@ -301,7 +300,7 @@ private void finalizeHeaders(StateMachine sm) throws CsvParserException { for (Field field : recordType.getFields().values()) { if (!sm.headers.contains(field.getFieldName())) { if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { - throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, field.getFieldName()); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); } } } @@ -313,7 +312,7 @@ private void finalizeHeaders(StateMachine sm) throws CsvParserException { //TODO: Replace arraysize -1 with if (size != -1 && size > sm.headers.size()) { // TODO: Can remove using fillers - throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, "Test"); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, sm.headers.size()); } } else if (expType instanceof MapType) { //ignore @@ -321,7 +320,7 @@ private void finalizeHeaders(StateMachine sm) throws CsvParserException { TupleType tupleType = (TupleType) expType; if (tupleType.getRestType() != null && tupleType.getTupleTypes().size() > sm.headers.size()) { // TODO: Can remove using fillers - throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, "Test"); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, sm.headers.size()); } } else { throw new CsvParserException("Invalid expected type"); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index e0f52d5..519975c 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -91,10 +91,10 @@ public Object traverseCsv(BArray csv, BMap config, Type type) { int expectedArraySize = ((ArrayType) referredType).getSize(); long sourceArraySize = csv.getLength(); if (expectedArraySize > sourceArraySize) { - throw DiagnosticLog.error(DiagnosticErrorCode.ARRAY_SIZE_MISMATCH); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, sourceArraySize); } if (TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.UNION_TAG) { - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA); + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); } this.config = config; if (TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.RECORD_TYPE_TAG @@ -136,7 +136,7 @@ public Object traverseCsvElementWithArray(Object csvElement, Type expectedType) traverseArrayValue(csvElement, csvMember, true); return csvMember; } - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType, PredefinedTypes.TYPE_ANYDATA); + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } private void traverseArrayValue(Object csvElement, BArray csvMember, boolean tuple) { @@ -212,7 +212,7 @@ private void addValuesToArrayType(Object csvElement, BArray csvMember, Type arra csvMember.add(index, convertToBasicType(csvElement, arrayElementType)); break; default: - DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, arrayElementType, PredefinedTypes.TYPE_ANYDATA); + DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, arrayElementType); } } @@ -233,13 +233,12 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected int arrayElementTypeTag = arrayType.getElementType().getTag(); // TODO: Only allow string[] if (arrayElementTypeTag != TypeTags.STRING_TAG) { - DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, - expectedType, PredefinedTypes.TYPE_ANYDATA_ARRAY); + DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } traverseCsvElementWithArrayAsExpectedType(csvElement,expectedType, arrayType); break; default: - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType, PredefinedTypes.TYPE_ANYDATA); + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } return currentCsvNode; } @@ -276,10 +275,7 @@ private void traverseCsvMap(Object csvElement, Type expectedType, boolean mappin } else if (csvElement instanceof BArray) { traverseArrayValueWithMapAsExpectedType((BArray) csvElement, parentJsonNode, mappingType, expectedType); } else { - if (fieldNames.isEmpty()) { - throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, expectedType, csvElement); - } - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, "Test"); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CSV_DATA_FORMAT); } nodesStack.pop(); } @@ -362,8 +358,7 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, Object p } boolean conversion = checkExpectedTypeMatchWithHeaders(expectedType, headers, csvElement, arraySize); if (!conversion) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, headers.toString(), - csvElement.toString(), "Test"); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csvElement, expectedType); } // TODO: Add headers from config for(int i = 1; i <= arraySize; i++) { @@ -433,8 +428,8 @@ private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BStrin case TypeTags.MAP_TAG: // TODO: Check if (!checkTypeCompatibility(((MapType) currentFieldType).getConstrainedType(), mapValue)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, - currentFieldType, "Test"); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, mapValue, + currentFieldType); } ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), mapValue); @@ -498,12 +493,12 @@ private boolean checkTypeCompatibility(Type constraintType, Object csv) { private void checkOptionalFieldsAndLogError(Map currentField) { currentField.values().forEach(field -> { if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { - throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, field.getFieldName()); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); } // TODO: Handle this properly if (!(SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED) && SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL))) { - throw DiagnosticLog.error(DiagnosticErrorCode.REQUIRED_FIELD_NOT_PRESENT, field.getFieldName()); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); } }); } @@ -519,11 +514,7 @@ private Object convertToBasicType(Object csv, Type targetType) { } return value; } catch (Exception e) { - if (fieldNames.isEmpty()) { - throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, targetType, csv); - } - throw DiagnosticLog.error(DiagnosticErrorCode.INCOMPATIBLE_TYPE, csv, targetType, - "Test"); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, targetType); } } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index 6d5b553..114256f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -62,12 +62,12 @@ public static Object fromCsvStringWithType(Environment env, Object csv, BMap Date: Sun, 18 Feb 2024 20:52:38 +0530 Subject: [PATCH 008/147] Remove nodestack from csv traversal --- ballerina/csv_api.bal | 2 +- .../stdlib/data/csvdata/csv/CsvCreator.java | 13 +----- .../stdlib/data/csvdata/csv/CsvParser.java | 2 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 45 +++++-------------- 4 files changed, 15 insertions(+), 47 deletions(-) diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index d576615..d6302ee 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -37,7 +37,7 @@ public type MappingConfig record {| public type FromCSVConfig record {| int startNumber = 0; int headerStartNumber = 0; - int dataStartNumber = 0; + int dataStartNumber = 1; boolean headers = true; string:Char escapeCharacter = "\\"; boolean ignoreEmptyLines = true; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 38f649a..e48a1da 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -43,7 +43,7 @@ */ public class CsvCreator { - static BMap initRootMapValue(Type expectedType) { + static BMap initMapValue(Type expectedType) { switch (expectedType.getTag()) { case TypeTags.RECORD_TYPE_TAG: return ValueCreator.createRecordValue((RecordType) expectedType); @@ -65,17 +65,6 @@ static BArray initArrayValue(Type expectedType) { } } - private static String getCurrentFieldPath(CsvParser.StateMachine sm) { -// Iterator itr = sm.fieldNames.descendingIterator(); -// -// StringBuilder result = new StringBuilder(itr.hasNext() ? itr.next() : ""); -// while (itr.hasNext()) { -// result.append(".").append(itr.next()); -// } -// return result.toString(); - return "Test"; - } - static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, BString value, Type type) { Object currentJson = sm.currentCsvNode; Object convertedValue = convertToExpectedType(value, type); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 6c3b6af..336ce3b 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -417,7 +417,7 @@ private void finalizeTheRow(StateMachine sm) { private Object createRowType(Type expectedType) throws CsvParserException { if (expectedType instanceof RecordType || expectedType instanceof MapType) { - return CsvCreator.initRootMapValue(expectedType); + return CsvCreator.initMapValue(expectedType); } else if (expectedType instanceof ArrayType || expectedType instanceof TupleType) { return CsvCreator.initArrayValue(expectedType); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 519975c..f194206 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -55,14 +55,10 @@ static class CsvTree { Field currentField; Stack> fieldHierarchy = new Stack<>(); Stack restType = new Stack<>(); - Deque nodesStack = new ArrayDeque<>(); Deque fieldNames = new ArrayDeque<>(); BArray rootCsvNode; - - Type rootArray; Type expectedArrayElementType; Type sourceArrayElementType; - BMap config; void reset() { @@ -70,7 +66,6 @@ void reset() { currentField = null; fieldHierarchy.clear(); restType.clear(); - nodesStack.clear(); fieldNames.clear(); expectedArrayElementType = null; sourceArrayElementType = null; @@ -248,7 +243,6 @@ public void traverseCsvElementWithRecordAsExpectedType(Object csvElement, Type e this.fieldHierarchy.push(new HashMap<>(recordType.getFields())); this.restType.push(recordType.getRestFieldType()); currentCsvNode = ValueCreator.createRecordValue(recordType); - nodesStack.push(currentCsvNode); traverseCsvMap(csvElement, expectedType, false); } @@ -256,28 +250,23 @@ public void traverseCsvElementWithMapAsExpectedType(Object csvElement, Type expe MapType mapType = (MapType) expectedType; this.fieldHierarchy.push(new HashMap<>()); currentCsvNode = ValueCreator.createMapValue(mapType); - nodesStack.push(currentCsvNode); traverseCsvMap(csvElement, expectedType, true); } public void traverseCsvElementWithArrayAsExpectedType(Object csvElement, Type expectedType, ArrayType arrayType) { // todo Check sizes abnd log errors - rootArray = expectedType; currentCsvNode = ValueCreator.createArrayValue(arrayType); - nodesStack.push(currentCsvNode); traverseCsvElementWithArray(csvElement, expectedType); } private void traverseCsvMap(Object csvElement, Type expectedType, boolean mappingType) { - Object parentJsonNode = nodesStack.peek(); if (csvElement instanceof BMap map) { - traverseMapValueWithMapAsExpectedType(map, parentJsonNode, mappingType); + traverseMapValueWithMapAsExpectedType(map, mappingType, expectedType); } else if (csvElement instanceof BArray) { - traverseArrayValueWithMapAsExpectedType((BArray) csvElement, parentJsonNode, mappingType, expectedType); + traverseArrayValueWithMapAsExpectedType((BArray) csvElement, mappingType, expectedType); } else { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CSV_DATA_FORMAT); } - nodesStack.pop(); } private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, String[] headers, BArray csvElement, int arraySize) { @@ -346,7 +335,7 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Str return false; } - private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, Object parent, boolean mappingType, Type expectedType) { + private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean mappingType, Type expectedType) { Type fieldType; BString key; int arraySize = csvElement.size(); @@ -372,7 +361,7 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, Object p addFieldInMapType(key); fieldType = ((MapType) expectedType).getConstrainedType();; } - addCurrentFieldValue(fieldType, csvElement.get(i - 1), key, parent); + addCurrentFieldValue(fieldType, csvElement.get(i - 1), key); } Map currentField = fieldHierarchy.pop(); checkOptionalFieldsAndLogError(currentField); @@ -381,20 +370,21 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, Object p } } - private void traverseMapValueWithMapAsExpectedType(BMap map, Object parent, boolean mappingType) { + private void traverseMapValueWithMapAsExpectedType(BMap map, boolean mappingType, Type expType) { Type currentFieldType; for (BString key : map.getKeys()) { if (!mappingType) { -// if (!isKeyBelongsToNonRestType(map, key)) { if (!isKeyBelongsToNonRestType(map.get(key), key)) { continue; } currentFieldType = TypeUtils.getReferredType(currentField.getFieldType()); } else { addFieldInMapType(key); - currentFieldType = TypeUtils.getReferredType(((MapType) ((BMap) parent).getType()).getConstrainedType()); + currentFieldType = TypeUtils.getReferredType( + ((MapType) expType).getConstrainedType() + ); } - addCurrentFieldValue(currentFieldType, map.get(key), key, parent); + addCurrentFieldValue(currentFieldType, map.get(key), key); } Map currentField = fieldHierarchy.pop(); checkOptionalFieldsAndLogError(currentField); @@ -421,19 +411,10 @@ private void addFieldInMapType(BString key) { fieldNames.push(key.toString()); } - private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BString key, Object parent) { + private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BString key) { int currentFieldTypeTag = currentFieldType.getTag(); switch (currentFieldTypeTag) { - case TypeTags.MAP_TAG: - // TODO: Check - if (!checkTypeCompatibility(((MapType) currentFieldType).getConstrainedType(), mapValue)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, mapValue, - currentFieldType); - } - ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), - mapValue); - break; case TypeTags.NULL_TAG: case TypeTags.BOOLEAN_TAG: case TypeTags.INT_TAG: @@ -444,10 +425,8 @@ private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BStrin ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), value); break; default: - //TODO: Check for Arrays - currentCsvNode = traverseCsvElementWithMapOrRecord(mapValue, currentFieldType); - ((BMap) parent).put(key, currentCsvNode); - currentCsvNode = parent; + // TODO: handle maps and structure values in future + DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, currentFieldType); } } From 1dfcb0f7391222c96ef1a1b360a78fb5585d85da Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Sun, 18 Feb 2024 22:15:37 +0530 Subject: [PATCH 009/147] Update type of field hierachy and the rest type --- ballerina/tests/test.bal | 10 ++++--- .../stdlib/data/csvdata/csv/CsvTraversal.java | 30 +++++++------------ 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 0b03a05..c21eaac 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -31,7 +31,9 @@ int[][] c4 = [[1, 2, 3], [1, 2, 3]]; [string, string][] d = [["1", "2"], ["1", "2"]]; [string, string][] d2 = [["1", "2"], ["1", "2"]]; -@test:Config{enable: true } +boolean enable = true; + +@test:Config{enable } public function testA() returns error? { A aa = check fromCsvWithType(a, {}, A); test:assertEquals(aa, a); @@ -121,7 +123,7 @@ public function testA() returns error? { test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); } -@test:Config{enable: true } +@test:Config{enable } function testB() returns error? { // B2 d2b2 = check fromCsvWithType(d2, {}, B2); // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); @@ -202,7 +204,7 @@ type WW int[][2]; type XX string[][2]; type YY anydata[][2]; -@test:Config{ enable: true } +@test:Config{ enable } function test() returns CsvConversionError? { string a = check io:fileReadString("a.txt"); @@ -328,7 +330,7 @@ function test() returns CsvConversionError? { type AAA string[][]; -@test:Config{ enable: true } +@test:Config{ enable } function testC() returns error? { anydata[][] a = [[1, 2], [2, 3], [2, 3]]; record{}[] b = [{"a": 1, "b": 2}, {"a": 1, "b": 2}, {"a": 1, "b": 2}]; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index f194206..3decdbe 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -53,8 +53,8 @@ public static Object traverse(BArray csv, BMap config, Type typ static class CsvTree { Object currentCsvNode; Field currentField; - Stack> fieldHierarchy = new Stack<>(); - Stack restType = new Stack<>(); + Map fieldHierarchy = new HashMap<>(); + Type restType; Deque fieldNames = new ArrayDeque<>(); BArray rootCsvNode; Type expectedArrayElementType; @@ -65,7 +65,7 @@ void reset() { currentCsvNode = null; currentField = null; fieldHierarchy.clear(); - restType.clear(); + restType = null; fieldNames.clear(); expectedArrayElementType = null; sourceArrayElementType = null; @@ -240,15 +240,15 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected public void traverseCsvElementWithRecordAsExpectedType(Object csvElement, Type expectedType) { RecordType recordType = (RecordType) expectedType; - this.fieldHierarchy.push(new HashMap<>(recordType.getFields())); - this.restType.push(recordType.getRestFieldType()); + this.fieldHierarchy = new HashMap<>(recordType.getFields()); + this.restType = recordType.getRestFieldType(); currentCsvNode = ValueCreator.createRecordValue(recordType); traverseCsvMap(csvElement, expectedType, false); } public void traverseCsvElementWithMapAsExpectedType(Object csvElement, Type expectedType) { MapType mapType = (MapType) expectedType; - this.fieldHierarchy.push(new HashMap<>()); + this.fieldHierarchy = new HashMap<>(); currentCsvNode = ValueCreator.createMapValue(mapType); traverseCsvMap(csvElement, expectedType, true); } @@ -363,11 +363,7 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean } addCurrentFieldValue(fieldType, csvElement.get(i - 1), key); } - Map currentField = fieldHierarchy.pop(); - checkOptionalFieldsAndLogError(currentField); - if (!mappingType) { - restType.pop(); - } + checkOptionalFieldsAndLogError(fieldHierarchy); } private void traverseMapValueWithMapAsExpectedType(BMap map, boolean mappingType, Type expType) { @@ -386,19 +382,15 @@ private void traverseMapValueWithMapAsExpectedType(BMap map, bo } addCurrentFieldValue(currentFieldType, map.get(key), key); } - Map currentField = fieldHierarchy.pop(); - checkOptionalFieldsAndLogError(currentField); - if (!mappingType) { - restType.pop(); - } + checkOptionalFieldsAndLogError(fieldHierarchy); } private boolean isKeyBelongsToNonRestType(Object value, BString key) { - currentField = fieldHierarchy.peek().remove(key.toString()); + currentField = fieldHierarchy.remove(key.toString()); if (currentField == null) { // Add to the rest field - if (restType.peek() != null) { - Type restFieldType = TypeUtils.getReferredType(restType.peek()); + if (restType != null) { + Type restFieldType = TypeUtils.getReferredType(restType); addRestField(restFieldType, key, value); } return false; From f65b2cef8f2fe0bcee811ca492c213576830a904 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Sun, 18 Feb 2024 22:26:14 +0530 Subject: [PATCH 010/147] Remove unwanted fields in parser --- .../stdlib/data/csvdata/csv/CsvParser.java | 28 +------ .../data/csvdata/csv/QualifiedName.java | 83 ------------------- .../stdlib/data/csvdata/utils/Constants.java | 65 +-------------- 3 files changed, 4 insertions(+), 172 deletions(-) delete mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QualifiedName.java diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 336ce3b..a0c1604 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -78,32 +78,21 @@ static class StateMachine { private static State NON_STRING_COLUMN_END_STATE = new NonStringColumnEndState(); private static State MAP_START_STATE = new MapStartState(); private static State MAP_END_STATE = new MapEndState(); - private static String lineBreak = "\n"; Object currentCsvNode; - Object currentRow; ArrayList headers = new ArrayList<>(); BArray rootCsvNode; - Deque nodesStack; // TODO: Need group same level field and keep the hierarchy. ArrayList fieldNames; - - private StringBuilder hexBuilder = new StringBuilder(4); private char[] charBuff = new char[1024]; private int charBuffIndex; private int index; private int line; private int column; - private char currentQuoteChar; - Field currentField; - Map fieldHierarchy = new HashMap<>(); - Stack restType = new Stack<>(); + Type restType; Stack expectedTypes = new Stack<>(); - int csvFieldDepth = 0; - Stack arrayIndexes = new Stack<>(); - Stack parserContexts = new Stack<>(); Type expectedArrayElementType; int columnIndex = 0; int rowIndex = 0; @@ -112,23 +101,14 @@ static class StateMachine { reset(); } - public enum ParserContexts { - MAP, - ARRAY - } - public void reset() { index = 0; currentCsvNode = null; line = 1; column = 0; - nodesStack = new ArrayDeque<>(); fieldNames = new ArrayList<>(); - fieldHierarchy.clear(); - currentField = null; - restType.clear(); + restType = null; expectedTypes.clear(); - csvFieldDepth = 0; rootCsvNode = null; columnIndex = 0; rowIndex = 0; @@ -170,8 +150,7 @@ public Object execute(Reader reader, Type type) throws BError { case TypeTags.RECORD_TYPE_TAG: RecordType recordType = (RecordType) expectedArrayElementType; expectedTypes.push(recordType); - restType.push(recordType.getRestFieldType()); - fieldHierarchy = recordType.getFields(); + restType = recordType.getRestFieldType(); break; case TypeTags.MAP_TAG: expectedTypes.push(expectedArrayElementType); @@ -179,7 +158,6 @@ public Object execute(Reader reader, Type type) throws BError { case TypeTags.ARRAY_TAG: case TypeTags.TUPLE_TAG: expectedTypes.push(expectedArrayElementType); - arrayIndexes.push(0); break; // TODO: Check to add Union types as well default: diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QualifiedName.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QualifiedName.java deleted file mode 100644 index 6173b6b..0000000 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QualifiedName.java +++ /dev/null @@ -1,83 +0,0 @@ -///* -// * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// * -// * WSO2 LLC. licenses this file to you under the Apache License, -// * Version 2.0 (the "License"); you may not use this file except -// * in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, -// * software distributed under the License is distributed on an -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// * KIND, either express or implied. See the License for the -// * specific language governing permissions and limitations -// * under the License. -// */ -// -//package io.ballerina.stdlib.data.csvdata.csv; -// -///** -// * Represents a qualified name. -// * -// * @since 0.1.0 -// */ -//public class QualifiedName { -// public static final String NS_ANNOT_NOT_DEFINED = "$$ns_annot_not_defined$$"; -// private String localPart; -// private String namespaceURI; -// private String prefix; -// -// public QualifiedName(String namespaceURI, String localPart, String prefix) { -// this.localPart = localPart; -// this.namespaceURI = namespaceURI; -// this.prefix = prefix; -// } -// -// public QualifiedName(String localPart) { -// this.localPart = localPart; -// this.namespaceURI = ""; -// this.prefix = ""; -// } -// -// public String getLocalPart() { -// return localPart; -// } -// -// public void setLocalPart(String localPart) { -// this.localPart = localPart; -// } -// -// public String getNamespaceURI() { -// return namespaceURI; -// } -// -// public String getPrefix() { -// return prefix; -// } -// -// @Override -// public int hashCode() { -// return localPart.hashCode(); -// } -// -// @Override -// public boolean equals(Object objectToTest) { -// if (objectToTest == this) { -// return true; -// } -// -// if (objectToTest == null || !(objectToTest instanceof QualifiedName)) { -// return false; -// } -// -// QualifiedName qName = (QualifiedName) objectToTest; -// -// if (qName.namespaceURI.equals(NS_ANNOT_NOT_DEFINED) || namespaceURI.equals(NS_ANNOT_NOT_DEFINED)) { -// return localPart.equals(qName.localPart); -// } -// return localPart.equals(qName.localPart) && namespaceURI.equals(qName.namespaceURI) && -// prefix.equals(qName.prefix); -// } -//} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java index 90a5047..9b3b2a6 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -1,68 +1,5 @@ package io.ballerina.stdlib.data.csvdata.utils; -import io.ballerina.runtime.api.PredefinedTypes; -import io.ballerina.runtime.api.creators.TypeCreator; -import io.ballerina.runtime.api.types.MapType; - -///* -// * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// * -// * WSO2 LLC. licenses this file to you under the Apache License, -// * Version 2.0 (the "License"); you may not use this file except -// * in compliance with the License. -// * You may obtain a copy of the License at -// * -// * http://www.apache.org/licenses/LICENSE-2.0 -// * -// * Unless required by applicable law or agreed to in writing, -// * software distributed under the License is distributed on an -// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// * KIND, either express or implied. See the License for the -// * specific language governing permissions and limitations -// * under the License. -// */ -// -//package io.ballerina.stdlib.data.csvdata.csv.utils; -// -//import io.ballerina.runtime.api.PredefinedTypes; -//import io.ballerina.runtime.api.creators.TypeCreator; -//import io.ballerina.runtime.api.types.ArrayType; -//import io.ballerina.runtime.api.types.MapType; -//import io.ballerina.runtime.api.utils.StringUtils; -//import io.ballerina.runtime.api.values.BString; -//import io.ballerina.runtime.api.values.BCsvItem; -//import io.ballerina.stdlib.data.csvdata.csv.QualifiedName; -// -///** -// * Constants used in Ballerina CsvData library. -// * -// * @since 0.1.0 -// */ -//public class Constants { -// -// private Constants() {} -// -// public static final String UNDERSCORE = "_"; -// public static final String COLON = ":"; -// public static final MapType JSON_MAP_TYPE = TypeCreator.createMapType(PredefinedTypes.TYPE_JSON); -// public static final ArrayType JSON_ARRAY_TYPE = TypeCreator.createArrayType(PredefinedTypes.TYPE_JSON); -// public static final String FIELD = "$field$."; -// public static final String NAMESPACE = "Namespace"; -// public static final BString URI = StringUtils.fromString("uri"); -// public static final BString PREFIX = StringUtils.fromString("prefix"); -// public static final String ATTRIBUTE = "Attribute"; -// public static final int DEFAULT_TYPE_FLAG = 2049; -// public static final String NAME = "Name"; -// public static final BString VALUE = StringUtils.fromString("value"); -// public static final String CONTENT = "#content"; -// public static final QualifiedName CONTENT_QNAME = new QualifiedName("", CONTENT, ""); -// public static final String FIELD_REGEX = "\\$field\\$\\."; -// public static final int NS_PREFIX_BEGIN_INDEX = BCsvItem.CSVNS_NS_URI_PREFIX.length(); -// public static final String RECORD = "record"; -// public static final String RECORD_OR_MAP = "record or map"; -// public static final String ANON_TYPE = "$anonType$"; -//} public class Constants { - public static final MapType JSON_MAP_TYPE = TypeCreator.createMapType(PredefinedTypes.TYPE_JSON); - public static final MapType ANYDATA_MAP_TYPE = TypeCreator.createMapType(PredefinedTypes.TYPE_ANYDATA); + } \ No newline at end of file From 0e81e8a90ba2a9670dc55643c62c0af852e60f91 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 19 Feb 2024 00:30:42 +0530 Subject: [PATCH 011/147] Refactor header states --- ballerina/tests/test.bal | 8 + .../stdlib/data/csvdata/csv/CsvParser.java | 173 +++++++----------- 2 files changed, 79 insertions(+), 102 deletions(-) diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index c21eaac..f02915c 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -339,4 +339,12 @@ function testC() returns error? { io:println(toCsvString(a)); io:println(toCsvString(b)); io:println(toCsvString(c)); +} + +@test:Config{enable: !enable} +function t() returns error? { + string a = check io:fileReadString("a.txt"); + AA aa = check fromCsvStringWithType(a, {}, AA); + test:assertEquals(aa, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); + io:println(aa); } \ No newline at end of file diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index a0c1604..5bc321e 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -67,8 +67,6 @@ public static Object parse(Reader reader, Type type) static class StateMachine { private static State HEADER_START_STATE = new HeaderStartState(); - private static State HEADER_ELEMENT_START_STATE = new HeaderElementStartState(); - private static State HEADER_ELEMENT_END_STATE = new HeaderElementEndState(); private static State HEADER_END_STATE = new HeaderEndState(); private static State ROW_START_STATE = new RowStartState(); private static State ROW_END_STATE = new RowEndState(); @@ -78,21 +76,20 @@ static class StateMachine { private static State NON_STRING_COLUMN_END_STATE = new NonStringColumnEndState(); private static State MAP_START_STATE = new MapStartState(); private static State MAP_END_STATE = new MapEndState(); - private static String lineBreak = "\n"; + private static char LINE_BREAK = '\n'; Object currentCsvNode; ArrayList headers = new ArrayList<>(); BArray rootCsvNode; // TODO: Need group same level field and keep the hierarchy. ArrayList fieldNames; + Map fieldHierarchy = new HashMap<>(); private char[] charBuff = new char[1024]; private int charBuffIndex; - private int index; private int line; private int column; Type restType; - Stack expectedTypes = new Stack<>(); Type expectedArrayElementType; int columnIndex = 0; int rowIndex = 0; @@ -108,10 +105,10 @@ public void reset() { column = 0; fieldNames = new ArrayList<>(); restType = null; - expectedTypes.clear(); rootCsvNode = null; columnIndex = 0; rowIndex = 0; + fieldHierarchy.clear(); } private static boolean isWhitespace(char ch) { @@ -123,7 +120,7 @@ private static void throwExpected(String... chars) throws CsvParserException { } private void processLocation(char ch) { - if (ch == '\n') { + if (ch == LINE_BREAK) { this.line++; this.column = 0; } else { @@ -149,17 +146,17 @@ public Object execute(Reader reader, Type type) throws BError { // TODO: Handle readonly and singleton type as expType. case TypeTags.RECORD_TYPE_TAG: RecordType recordType = (RecordType) expectedArrayElementType; - expectedTypes.push(recordType); - restType = recordType.getRestFieldType(); + restType = (recordType).getRestFieldType(); + fieldHierarchy = new HashMap<>(recordType.getFields()); break; - case TypeTags.MAP_TAG: - expectedTypes.push(expectedArrayElementType); + case TypeTags.TUPLE_TAG: + restType = ((TupleType) expectedArrayElementType).getRestType(); break; + case TypeTags.MAP_TAG: case TypeTags.ARRAY_TAG: - case TypeTags.TUPLE_TAG: - expectedTypes.push(expectedArrayElementType); break; - // TODO: Check to add Union types as well + case TypeTags.UNION_TAG: + throw DiagnosticLog.error(DiagnosticErrorCode.UNION_TYPES_NOT_ALLOWED, expectedArrayElementType); default: throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); } @@ -179,6 +176,10 @@ public Object execute(Reader reader, Type type) throws BError { currentState = currentState.transition(this, buff, this.index, count); } } + currentState = currentState.transition(this, new char[] { EOF }, 0, 1); + if (currentState != ROW_END_STATE && currentState != HEADER_END_STATE) { + throw new CsvParserException("Invalid token found"); + } return rootCsvNode; } catch (IOException e) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TOKEN, e.getMessage(), line, column); @@ -187,25 +188,6 @@ public Object execute(Reader reader, Type type) throws BError { } } - private boolean isSupportedUnionType(UnionType type) { - boolean isContainUnsupportedMember = false; - for (Type memberType : type.getMemberTypes()) { - switch (memberType.getTag()) { - case TypeTags.RECORD_TYPE_TAG: - case TypeTags.OBJECT_TYPE_TAG: - case TypeTags.MAP_TAG: - case TypeTags.JSON_TAG: - case TypeTags.ANYDATA_TAG: - isContainUnsupportedMember = true; - break; - case TypeTags.UNION_TAG: - isContainUnsupportedMember = isSupportedUnionType(type); - break; - } - } - return !isContainUnsupportedMember; - } - private void append(char ch) { try { this.charBuff[this.charBuffIndex] = ch; @@ -217,7 +199,7 @@ private void append(char ch) { } } - private boolean isEndOftheRow(char ch) { + private boolean isEndOfTheRow(char ch) { return ch == NEWLINE || ch == EOF; } @@ -246,19 +228,19 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C ch = buff[i]; sm.processLocation(ch); if (ch == separator) { - addHeader(sm.headers, sm.value(), sm.expectedTypes.peek()); + addHeader(sm); sm.columnIndex++; - } else if (sm.isEndOftheRow(ch)) { - addHeader(sm.headers, sm.value(), sm.expectedTypes.peek()); + } else if (sm.isEndOfTheRow(ch)) { + addHeader(sm); finalizeHeaders(sm); -// state = HEADER_END_STATE; sm.columnIndex = 0; - state = ROW_START_STATE; + state = HEADER_END_STATE; } else if (StateMachine.isWhitespace(ch)) { state = this; continue; -// } else if (ch == EOF) { -// throw new CsvParserException("Unexpected Header"); + } else if (ch == EOF) { + addHeader(sm); + state = HEADER_END_STATE; } else { sm.append(ch); state = this; @@ -273,68 +255,68 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C private void finalizeHeaders(StateMachine sm) throws CsvParserException { Type expType = sm.expectedArrayElementType; if (expType instanceof RecordType) { - RecordType recordType = ((RecordType) expType); - if (recordType.getRestFieldType() == null) { - for (Field field : recordType.getFields().values()) { - if (!sm.headers.contains(field.getFieldName())) { - if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); - } - } - } - } + validateRemainingRecordFields(sm); } else if (expType instanceof ArrayType) { // TODO: Get the other validation into here + //TODO: Replace arraysize -1 with + // TODO: Can remove using fillers ArrayType arrayType = (ArrayType) expType; int size = arrayType.getSize(); - //TODO: Replace arraysize -1 with - if (size != -1 && size > sm.headers.size()) { - // TODO: Can remove using fillers - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, sm.headers.size()); - } + validateExpectedArraySize(size, sm.headers.size()); } else if (expType instanceof MapType) { //ignore } else if (expType instanceof TupleType) { - TupleType tupleType = (TupleType) expType; - if (tupleType.getRestType() != null && tupleType.getTupleTypes().size() > sm.headers.size()) { - // TODO: Can remove using fillers - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, sm.headers.size()); - } + validateTupleTypes((TupleType) expType, sm.restType, sm.headers.size()); } else { throw new CsvParserException("Invalid expected type"); } } - private void addHeader(ArrayList headers, String value, Type expectedType) throws CsvParserException { - if (expectedType instanceof RecordType) { - RecordType recordType = (RecordType) expectedType; - Type restType = recordType.getRestFieldType(); - if (restType != null && restType.getTag() != TypeTags.ANYDATA_TAG && !recordType.getFields().containsKey(StringUtils.fromString(value))) { - throw new CsvParserException("Invalid header name"); + private void validateTupleTypes(TupleType tupleType, Type restType, int currentSize) { + if (restType != null && tupleType.getTupleTypes().size() > currentSize) { + // TODO: Can remove using fillers + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, currentSize); + } + } + + private void validateExpectedArraySize(int size, int currentSize) { + if (size != -1 && size > currentSize) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, currentSize); + } + } + + private void validateRemainingRecordFields(StateMachine sm) { + if (sm.restType == null) { + for (Field field : sm.fieldHierarchy.values()) { + if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); + } } } - headers.add(value); } - } - private static class HeaderElementStartState implements State { - @Override - public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - return null; + private void addHeader(StateMachine sm) throws CsvParserException { + String value = sm.value(); + if (sm.expectedArrayElementType instanceof RecordType) { + if (validateHeaderValueWithRecordFields(sm, value)) { + throw new CsvParserException("Header " + value + " does not match " + + "with any record key in the expected type"); + } + sm.fieldHierarchy.remove(value); + } + sm.headers.add(value); } - } - private static class HeaderElementEndState implements State { - @Override - public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - return null; + private boolean validateHeaderValueWithRecordFields(StateMachine sm, String value) { + return sm.restType != null && sm.restType.getTag() != TypeTags.ANYDATA_TAG + && !sm.fieldHierarchy.containsKey(StringUtils.fromString(value)); } } private static class HeaderEndState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - return null; + return ROW_START_STATE; } } @@ -342,12 +324,11 @@ private static class RowStartState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { char ch; - State state; + State state = ROW_START_STATE; //TODO: Add separator here char separator = ','; // TODO: Ignore this in future - sm.columnIndex = 0; for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); @@ -358,31 +339,26 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C if (ch == separator) { addRowValue(sm); sm.columnIndex++; - } else if (sm.isEndOftheRow(ch)) { + } else if (sm.isEndOfTheRow(ch)) { addRowValue(sm); finalizeTheRow(sm); sm.columnIndex = 0; sm.currentCsvNode = null; + if (ch == EOF) { + state = ROW_END_STATE; + } } else if (StateMachine.isWhitespace(ch)) { // ignore - } else if (ch == EOF) { - throw new CsvParserException("Unexpected Header"); } else { sm.append(ch); } } - if (!isWhitespace(buff[i]) || buff[i] != separator) { - addRowValue(sm); - finalizeTheRow(sm); - sm.currentCsvNode = null; - } sm.index = i + 1; - state = ROW_END_STATE; return state; } private void initiateNewRowType(StateMachine sm) throws CsvParserException { - sm.currentCsvNode = createRowType(sm.expectedTypes.peek()); + sm.currentCsvNode = createRowType(sm.expectedArrayElementType); } private void finalizeTheRow(StateMachine sm) { @@ -405,17 +381,17 @@ private Object createRowType(Type expectedType) throws CsvParserException { private void addRowValue(StateMachine sm) throws CsvParserException { // TODO: Can convert all at once by storing in a Object[] Type type; - Type exptype = sm.expectedTypes.peek(); + Type exptype = sm.expectedArrayElementType; if (exptype instanceof RecordType) { // TODO: These can be make as module level variables RecordType recordType = ((RecordType) exptype); Map fields = recordType.getFields(); - Type restType = recordType.getRestFieldType(); String header = sm.headers.get(sm.columnIndex); if (fields.containsKey(header)) { //TODO: Optimize type = fields.get(header).getFieldType(); } else { + Type restType = sm.restType; if (restType != null) { type = restType; } else { @@ -431,17 +407,16 @@ private void addRowValue(StateMachine sm) throws CsvParserException { // TODO: add to a constant if (arrayType.getSize() != -1 && arrayType.getSize() < sm.columnIndex) { sm.charBuffIndex = 0; -// throw new CsvParserException("Unexpected Row count"); return; } type = arrayType.getElementType(); } else if (exptype instanceof TupleType) { TupleType tupleType = (TupleType) exptype; List tupleTypes = tupleType.getTupleTypes(); - Type restType = tupleType.getRestType(); if (tupleTypes.size() > sm.columnIndex) { type = tupleTypes.get(sm.columnIndex); } else { + Type restType = sm.restType; if (restType != null) { type = restType; } else { @@ -461,13 +436,7 @@ private void addRowValue(StateMachine sm) throws CsvParserException { private static class RowEndState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - char ch; - State state = ROW_END_STATE; - for (; i < count; i++) { - - } - sm.index = i + 1; - return state; + return ROW_END_STATE; } } From a9d571a64387465cc85052d5b3dde82c6a1b40c5 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 19 Feb 2024 01:39:04 +0530 Subject: [PATCH 012/147] Refactor csv parser --- .../stdlib/data/csvdata/csv/CsvCreator.java | 9 +---- .../stdlib/data/csvdata/csv/CsvParser.java | 39 +++++++------------ 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index e48a1da..a87dbe9 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -43,19 +43,12 @@ */ public class CsvCreator { - static BMap initMapValue(Type expectedType) { + static Object initRowValue(Type expectedType) { switch (expectedType.getTag()) { case TypeTags.RECORD_TYPE_TAG: return ValueCreator.createRecordValue((RecordType) expectedType); case TypeTags.MAP_TAG: return ValueCreator.createMapValue((MapType) expectedType); - default: - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); - } - } - - static BArray initArrayValue(Type expectedType) { - switch (expectedType.getTag()) { case TypeTags.TUPLE_TAG: return ValueCreator.createTupleValue((TupleType) expectedType); case TypeTags.ARRAY_TAG: diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 5bc321e..feda510 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -81,9 +81,8 @@ static class StateMachine { Object currentCsvNode; ArrayList headers = new ArrayList<>(); BArray rootCsvNode; - // TODO: Need group same level field and keep the hierarchy. - ArrayList fieldNames; Map fieldHierarchy = new HashMap<>(); + Map fieldNames = new HashMap<>(); private char[] charBuff = new char[1024]; private int charBuffIndex; private int index; @@ -93,6 +92,7 @@ static class StateMachine { Type expectedArrayElementType; int columnIndex = 0; int rowIndex = 0; + ArrayType rootArrayType = null; StateMachine() { reset(); @@ -103,12 +103,13 @@ public void reset() { currentCsvNode = null; line = 1; column = 0; - fieldNames = new ArrayList<>(); restType = null; rootCsvNode = null; columnIndex = 0; rowIndex = 0; fieldHierarchy.clear(); + fieldNames.clear(); + rootArrayType = null; } private static boolean isWhitespace(char ch) { @@ -139,7 +140,8 @@ public Object execute(Reader reader, Type type) throws BError { if (referredType.getTag() != TypeTags.ARRAY_TAG) { return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type); } else { - rootCsvNode = ValueCreator.createArrayValue((ArrayType) type); + rootArrayType = (ArrayType) type; + rootCsvNode = ValueCreator.createArrayValue(rootArrayType); expectedArrayElementType = ((ArrayType) TypeUtils.getReferredType(referredType)).getElementType(); } switch (expectedArrayElementType.getTag()) { @@ -238,9 +240,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } else if (StateMachine.isWhitespace(ch)) { state = this; continue; - } else if (ch == EOF) { - addHeader(sm); - state = HEADER_END_STATE; } else { sm.append(ch); state = this; @@ -260,9 +259,7 @@ private void finalizeHeaders(StateMachine sm) throws CsvParserException { // TODO: Get the other validation into here //TODO: Replace arraysize -1 with // TODO: Can remove using fillers - ArrayType arrayType = (ArrayType) expType; - int size = arrayType.getSize(); - validateExpectedArraySize(size, sm.headers.size()); + validateExpectedArraySize(((ArrayType) expType).getSize(), sm.headers.size()); } else if (expType instanceof MapType) { //ignore } else if (expType instanceof TupleType) { @@ -302,7 +299,11 @@ private void addHeader(StateMachine sm) throws CsvParserException { throw new CsvParserException("Header " + value + " does not match " + "with any record key in the expected type"); } - sm.fieldHierarchy.remove(value); + Field field = sm.fieldHierarchy.get(value); + if (field != null) { + sm.fieldNames.put(value, field); + sm.fieldHierarchy.remove(value); + } } sm.headers.add(value); } @@ -358,35 +359,25 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } private void initiateNewRowType(StateMachine sm) throws CsvParserException { - sm.currentCsvNode = createRowType(sm.expectedArrayElementType); + sm.currentCsvNode = CsvCreator.initRowValue(sm.expectedArrayElementType); } private void finalizeTheRow(StateMachine sm) { - int rootArraySize = ((ArrayType)(sm.rootCsvNode.getType())).getSize(); + int rootArraySize = sm.rootArrayType.getSize(); if (rootArraySize == -1 || sm.rowIndex < rootArraySize) { sm.rootCsvNode.add(sm.rowIndex, sm.currentCsvNode); sm.rowIndex++; } } - private Object createRowType(Type expectedType) throws CsvParserException { - if (expectedType instanceof RecordType || expectedType instanceof MapType) { - return CsvCreator.initMapValue(expectedType); - } else if (expectedType instanceof ArrayType || expectedType instanceof TupleType) { - return CsvCreator.initArrayValue(expectedType); - } - throw new CsvParserException("Unexpected expected type"); - } - private void addRowValue(StateMachine sm) throws CsvParserException { // TODO: Can convert all at once by storing in a Object[] Type type; Type exptype = sm.expectedArrayElementType; if (exptype instanceof RecordType) { // TODO: These can be make as module level variables - RecordType recordType = ((RecordType) exptype); - Map fields = recordType.getFields(); String header = sm.headers.get(sm.columnIndex); + Map fields = sm.fieldNames; if (fields.containsKey(header)) { //TODO: Optimize type = fields.get(header).getFieldType(); From 855f2022fe223264fc28cdf2310a29f0eabf3de0 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 19 Feb 2024 13:56:19 +0530 Subject: [PATCH 013/147] Add configs --- .../stdlib/data/csvdata/csv/CsvConfig.java | 101 ++++++++ .../stdlib/data/csvdata/csv/CsvParser.java | 235 ++++++++++++------ .../stdlib/data/csvdata/csv/CsvTraversal.java | 93 +++---- .../stdlib/data/csvdata/csv/Native.java | 13 +- .../data/csvdata/io/DataReaderTask.java | 8 +- .../stdlib/data/csvdata/utils/Constants.java | 24 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 21 ++ 7 files changed, 357 insertions(+), 138 deletions(-) create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java new file mode 100644 index 0000000..e6ea36b --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java @@ -0,0 +1,101 @@ +package io.ballerina.stdlib.data.csvdata.csv; + +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BString; + +import java.util.ArrayList; + +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.*; + +public class CsvConfig { + long startNumber = 0; + long headerStartNumber = 0; + long dataStartNumber = 1; + boolean headers = true; + char escapeCharacter = '\\'; + boolean ignoreEmptyLines = true; + char separator = ','; + String quote = "\""; + boolean skipHeaders = false; + long skipDataRows = 0; + long dataRowCount = -1; + Object orderBy = new ArrayList<>(); + Object skipColumns = null; + Object customHeader = null; + boolean suppressEscaping = false; + Object nullValue = null; + Object root = null; + char lineSeparator = '\n'; + + + private CsvConfig(boolean headers, char escapeCharacter, boolean ignoreEmptyLines, + char separator, boolean skipHeaders, long skipDataRows, + long dataRowCount, Object orderBy, Object skipColumns, Object customHeader, + boolean suppressEscaping, Object nullValue, char lineSeparator) { + this.headers = headers; + this.escapeCharacter = escapeCharacter; + this.separator = separator; + this.skipHeaders = skipHeaders; + this.skipDataRows = skipDataRows; + this.dataRowCount = dataRowCount; + this.orderBy = orderBy; + this.skipColumns = skipColumns; + this.customHeader = customHeader; + this.suppressEscaping = suppressEscaping; + this.nullValue = nullValue; + this.lineSeparator = lineSeparator; + } + + private CsvConfig(long startNumber, long headerStartNumber, long dataStartNumber, + boolean headers, char escapeCharacter, boolean ignoreEmptyLines, + char separator, String quote, boolean skipHeaders, long skipDataRows, + long dataRowCount, Object orderBy, Object skipColumns, Object customHeader, + boolean suppressEscaping, Object nullValue, Object root) { + this.startNumber = startNumber; + this.headerStartNumber = headerStartNumber; + this.dataStartNumber = dataStartNumber; + this.headers = headers; + this.escapeCharacter = escapeCharacter; + this.ignoreEmptyLines = ignoreEmptyLines; + this.separator = separator; + this.quote = quote; + this.skipHeaders = skipHeaders; + this.skipDataRows = skipDataRows; + this.dataRowCount = dataRowCount; + this.orderBy = orderBy; + this.skipColumns = skipColumns; + this.customHeader = customHeader; + this.suppressEscaping = suppressEscaping; + this.nullValue = nullValue; + this.root = root; + } + + public CsvConfig() { + } + + public static CsvConfig createFromCsvConfiguration(BMap config) { + return new CsvConfig( + config.getIntValue(START_NUMBER), config.getIntValue(HEADER_START_NUMBER), + config.getIntValue(DATA_START_NUMBER), config.getBooleanValue(HEADERS), + // TODO: Handle unicodes + config.getStringValue(ESCAPE_CHARACTER).toString().charAt(0), config.getBooleanValue(IGNORE_EMPTY_LINES), + config.getStringValue(SEPARATOR).toString().charAt(0), config.getStringValue(QUOTE).toString(), + config.getBooleanValue(SKIP_HEADERS), config.getIntValue(SKIP_DATA_ROWS), + config.getIntValue(DATA_ROW_COUNT), config.get(ORDER_BY), config.get(SKIP_COLUMNS), + config.get(CUSTOM_HEADER), config.getBooleanValue(SUPPRESS_ESCAPING), + config.get(NULL_VALUE), config.get(ROOT) + ); + } + + public static CsvConfig createToCsvConfiguration(BMap config) { + return new CsvConfig( + config.getBooleanValue(HEADERS), config.getStringValue(ESCAPE_CHARACTER).toString().charAt(0), + config.getBooleanValue(IGNORE_EMPTY_LINES), config.getStringValue(SEPARATOR).toString().charAt(0), + config.getBooleanValue(SKIP_HEADERS), config.getIntValue(SKIP_DATA_ROWS), + config.getIntValue(DATA_ROW_COUNT), config.get(ORDER_BY), + config.get(SKIP_COLUMNS), config.get(CUSTOM_HEADER), + config.getBooleanValue(SUPPRESS_ESCAPING), config.get(NULL_VALUE), + config.getStringValue(LINE_SEPARATOR).toString().charAt(0) + ); + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index feda510..90e309e 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -33,6 +33,8 @@ import java.io.Reader; import java.util.*; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.validateExpectedArraySize; + /** * Convert Csv string to a ballerina record. * @@ -53,11 +55,11 @@ public class CsvParser { private static final ThreadLocal tlStateMachine = ThreadLocal.withInitial(StateMachine::new); - public static Object parse(Reader reader, Type type) + public static Object parse(Reader reader, Type type, CsvConfig config) throws BError { StateMachine sm = tlStateMachine.get(); try { - return sm.execute(reader, TypeUtils.getReferredType(type)); + return sm.execute(reader, TypeUtils.getReferredType(type), config); } finally { // Need to reset the state machine before leaving. Otherwise, references to the created // CSV values will be maintained and the java GC will not happen properly. @@ -70,15 +72,12 @@ static class StateMachine { private static State HEADER_END_STATE = new HeaderEndState(); private static State ROW_START_STATE = new RowStartState(); private static State ROW_END_STATE = new RowEndState(); - private static State STRING_COLUMN_START_STATE = new StringColumnStartState(); - private static State STRING_COLUMN_END_STATE = new StringColumnEndState(); - private static State NON_STRING_COLUMN_START_STATE = new NonStringColumnStartState(); - private static State NON_STRING_COLUMN_END_STATE = new NonStringColumnEndState(); - private static State MAP_START_STATE = new MapStartState(); - private static State MAP_END_STATE = new MapEndState(); + private static State STRING_VALUE_STATE = new StringValueEscapedCharacterProcessingState(); + private static State HEADER_NAME_STATE = new HeaderNameEscapedCharacterProcessingState(); private static char LINE_BREAK = '\n'; Object currentCsvNode; + Stack currentEscapeCharacters = new Stack<>(); ArrayList headers = new ArrayList<>(); BArray rootCsvNode; Map fieldHierarchy = new HashMap<>(); @@ -135,7 +134,7 @@ private String value() { return result; } - public Object execute(Reader reader, Type type) throws BError { + public Object execute(Reader reader, Type type, CsvConfig config) throws BError { Type referredType = TypeUtils.getReferredType(type); if (referredType.getTag() != TypeTags.ARRAY_TAG) { return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type); @@ -276,12 +275,6 @@ private void validateTupleTypes(TupleType tupleType, Type restType, int currentS } } - private void validateExpectedArraySize(int size, int currentSize) { - if (size != -1 && size > currentSize) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, currentSize); - } - } - private void validateRemainingRecordFields(StateMachine sm) { if (sm.restType == null) { for (Field field : sm.fieldHierarchy.values()) { @@ -375,54 +368,64 @@ private void addRowValue(StateMachine sm) throws CsvParserException { Type type; Type exptype = sm.expectedArrayElementType; if (exptype instanceof RecordType) { - // TODO: These can be make as module level variables - String header = sm.headers.get(sm.columnIndex); - Map fields = sm.fieldNames; - if (fields.containsKey(header)) { - //TODO: Optimize - type = fields.get(header).getFieldType(); - } else { - Type restType = sm.restType; - if (restType != null) { - type = restType; - } else { - sm.charBuffIndex = 0; - return; - } - } + type = getExpectedRowTypeOfRecord(sm); } else if (exptype instanceof MapType) { - MapType mapType = ((MapType) exptype); - type = mapType.getConstrainedType(); + type = ((MapType) exptype).getConstrainedType(); } else if (exptype instanceof ArrayType) { - ArrayType arrayType = (ArrayType) exptype; - // TODO: add to a constant - if (arrayType.getSize() != -1 && arrayType.getSize() < sm.columnIndex) { - sm.charBuffIndex = 0; - return; - } - type = arrayType.getElementType(); + type = getExpectedRowTypeOfArray(sm, (ArrayType) exptype); } else if (exptype instanceof TupleType) { - TupleType tupleType = (TupleType) exptype; - List tupleTypes = tupleType.getTupleTypes(); - if (tupleTypes.size() > sm.columnIndex) { - type = tupleTypes.get(sm.columnIndex); - } else { - Type restType = sm.restType; - if (restType != null) { - type = restType; - } else { - sm.charBuffIndex = 0; - return; - } - } + type = getExpectedRowTypeOfTuple(sm, (TupleType) exptype); } else { throw new CsvParserException("Unexpected expected type"); } - CsvCreator.convertAndUpdateCurrentJsonNode(sm, StringUtils.fromString(sm.value()), type); + + if (type != null) { + CsvCreator.convertAndUpdateCurrentJsonNode(sm, StringUtils.fromString(sm.value()), type); + } + } + + private Type getExpectedRowTypeOfTuple(StateMachine sm, TupleType tupleType) { + List tupleTypes = tupleType.getTupleTypes(); + if (tupleTypes.size() > sm.columnIndex) { + return tupleTypes.get(sm.columnIndex); + } else { + Type restType = sm.restType; + if (restType != null) { + return restType; + } else { + sm.charBuffIndex = 0; + return null; + } + } } - } + private Type getExpectedRowTypeOfArray(StateMachine sm, ArrayType arrayType) { + // TODO: add to a constant + if (arrayType.getSize() != -1 && arrayType.getSize() < sm.columnIndex) { + sm.charBuffIndex = 0; + return null; + } + return arrayType.getElementType(); + } + private Type getExpectedRowTypeOfRecord(StateMachine sm) { + // TODO: These can be make as module level variables + String header = sm.headers.get(sm.columnIndex); + Map fields = sm.fieldNames; + if (fields.containsKey(header)) { + //TODO: Optimize + return fields.get(header).getFieldType(); + } else { + Type restType = sm.restType; + if (restType != null) { + return restType; + } else { + sm.charBuffIndex = 0; + return null; + } + } + } + } private static class RowEndState implements State { @Override @@ -431,46 +434,130 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } } - private static class StringColumnStartState implements State { - @Override - public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - return null; - } - } + /** + * Represents the state where an escaped character is processed in a string value. + */ + private static class StringValueEscapedCharacterProcessingState extends EscapedCharacterProcessingState { - private static class StringColumnEndState implements State { @Override - public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - return null; + protected State getSourceState() { + return STRING_VALUE_STATE; } - } - private static class NonStringColumnStartState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - return null; + State state = null; + char ch; + for (; i < count; i++) { + ch = buff[i]; + sm.processLocation(ch); + if (String.valueOf(ch) == sm.currentEscapeCharacters.peek()) { + sm.currentEscapeCharacters.pop(); + state = ROW_START_STATE; + } else if (ch == EOF) { + throw new CsvParserException("unexpected end of JSON document"); + } else { + sm.append(ch); + state = this; + continue; + } + break; + } + sm.index = i + 1; + return state; } + } - private static class NonStringColumnEndState implements State { + /** + * Represents the state where an escaped character is processed in a field name. + */ + private static class HeaderNameEscapedCharacterProcessingState extends EscapedCharacterProcessingState { + @Override - public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - return null; + protected State getSourceState() { + return HEADER_NAME_STATE; } - } - private static class MapStartState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - return null; + State state = null; + char ch; + for (; i < count; i++) { + ch = buff[i]; + sm.processLocation(ch); + if (String.valueOf(ch) == sm.currentEscapeCharacters.peek()) { + sm.currentEscapeCharacters.pop(); + state = HEADER_START_STATE; + } else if (ch == EOF) { + throw new CsvParserException("unexpected end of JSON document"); + } else { + sm.append(ch); + state = this; + continue; + } + break; + } + sm.index = i + 1; + return state; } } - private static class MapEndState implements State { + /** + * Represents the state where an escaped character is processed. + */ + private abstract static class EscapedCharacterProcessingState implements State { + + protected abstract State getSourceState(); + @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - return null; + State state = null; + char ch; + if (i < count) { + ch = buff[i]; + sm.processLocation(ch); + switch (ch) { + case '"': + sm.append(QUOTES); + state = this.getSourceState(); + break; + case '\\': + sm.append(REV_SOL); + state = this.getSourceState(); + break; + case '/': + sm.append(SOL); + state = this.getSourceState(); + break; + case 'b': + sm.append(BACKSPACE); + state = this.getSourceState(); + break; + case 'f': + sm.append(FORMFEED); + state = this.getSourceState(); + break; + case 'n': + sm.append(NEWLINE); + state = this.getSourceState(); + break; + case 'r': + sm.append(CR); + state = this.getSourceState(); + break; + case 't': + sm.append(HZ_TAB); + state = this.getSourceState(); + break; + default: + StateMachine.throwExpected("escaped characters"); + } + } + sm.index = i + 1; + return state; } + } public static class CsvParserException extends Exception { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 3decdbe..d716493 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -27,11 +27,14 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.*; import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import java.util.*; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.validateExpectedArraySize; + /** * Convert Csv value to a ballerina record. * @@ -39,7 +42,7 @@ */ public class CsvTraversal { private static final ThreadLocal tlCsvTree = ThreadLocal.withInitial(CsvTree::new); - public static Object traverse(BArray csv, BMap config, Type type) { + public static Object traverse(BArray csv, CsvConfig config, Type type) { CsvTree csvTree = tlCsvTree.get(); try { return csvTree.traverseCsv(csv, config, type); @@ -59,7 +62,7 @@ static class CsvTree { BArray rootCsvNode; Type expectedArrayElementType; Type sourceArrayElementType; - BMap config; + CsvConfig config; void reset() { currentCsvNode = null; @@ -72,7 +75,8 @@ void reset() { } @SuppressWarnings("unchecked") - public Object traverseCsv(BArray csv, BMap config, Type type) { + public Object traverseCsv(BArray csv, CsvConfig config, Type type) { + this.config = config; Type referredType = TypeUtils.getReferredType(type); // TODO: add root level node configurations if (referredType.getTag() != TypeTags.ARRAY_TAG) { @@ -84,14 +88,11 @@ public Object traverseCsv(BArray csv, BMap config, Type type) { // TODO: Handle the array size count sourceArrayElementType = csv.getElementType(); int expectedArraySize = ((ArrayType) referredType).getSize(); - long sourceArraySize = csv.getLength(); - if (expectedArraySize > sourceArraySize) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, sourceArraySize); - } + int sourceArraySize = (int) csv.getLength(); + validateExpectedArraySize(expectedArraySize, sourceArraySize); if (TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.UNION_TAG) { return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); } - this.config = config; if (TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.RECORD_TYPE_TAG || TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.TABLE_TAG || TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.MAP_TAG) { @@ -117,6 +118,34 @@ public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray } } + public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expectedType) { + switch (expectedType.getTag()) { + case TypeTags.RECORD_TYPE_TAG: + RecordType recordType = (RecordType) expectedType; + this.fieldHierarchy = new HashMap<>(recordType.getFields()); + this.restType = recordType.getRestFieldType(); + currentCsvNode = ValueCreator.createRecordValue(recordType); + traverseCsvMap(csvElement, expectedType, false); + break; + case TypeTags.MAP_TAG: + MapType mapType = (MapType) expectedType; + this.fieldHierarchy = new HashMap<>(); + currentCsvNode = ValueCreator.createMapValue(mapType); + traverseCsvMap(csvElement, expectedType, true); + break; +// case TypeTags.TABLE_TAG: +// //TODO: Check +// TableType tableType = (TableType) expectedType; +// this.fieldHierarchy = new HashMap<>(); +// currentCsvNode = ValueCreator.createT(tableType); +// traverseCsvMap(csvElement, expectedType, true); +// break; + default: + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); + } + return currentCsvNode; + } + public Object traverseCsvElementWithArray(Object csvElement, Type expectedType) { BArray csvMember; switch (expectedType.getTag()) { @@ -211,54 +240,6 @@ private void addValuesToArrayType(Object csvElement, BArray csvMember, Type arra } } - public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expectedType) { - switch (expectedType.getTag()) { - case TypeTags.RECORD_TYPE_TAG: - traverseCsvElementWithRecordAsExpectedType(csvElement, expectedType); - break; - case TypeTags.MAP_TAG: - traverseCsvElementWithMapAsExpectedType(csvElement, expectedType); - break; - case TypeTags.TABLE_TAG: - //TODO: Check - traverseCsvElementWithMapAsExpectedType(csvElement, expectedType); - break; - case TypeTags.ARRAY_TAG: - ArrayType arrayType = (ArrayType) expectedType; - int arrayElementTypeTag = arrayType.getElementType().getTag(); - // TODO: Only allow string[] - if (arrayElementTypeTag != TypeTags.STRING_TAG) { - DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); - } - traverseCsvElementWithArrayAsExpectedType(csvElement,expectedType, arrayType); - break; - default: - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); - } - return currentCsvNode; - } - - public void traverseCsvElementWithRecordAsExpectedType(Object csvElement, Type expectedType) { - RecordType recordType = (RecordType) expectedType; - this.fieldHierarchy = new HashMap<>(recordType.getFields()); - this.restType = recordType.getRestFieldType(); - currentCsvNode = ValueCreator.createRecordValue(recordType); - traverseCsvMap(csvElement, expectedType, false); - } - - public void traverseCsvElementWithMapAsExpectedType(Object csvElement, Type expectedType) { - MapType mapType = (MapType) expectedType; - this.fieldHierarchy = new HashMap<>(); - currentCsvNode = ValueCreator.createMapValue(mapType); - traverseCsvMap(csvElement, expectedType, true); - } - - public void traverseCsvElementWithArrayAsExpectedType(Object csvElement, Type expectedType, ArrayType arrayType) { - // todo Check sizes abnd log errors - currentCsvNode = ValueCreator.createArrayValue(arrayType); - traverseCsvElementWithArray(csvElement, expectedType); - } - private void traverseCsvMap(Object csvElement, Type expectedType, boolean mappingType) { if (csvElement instanceof BMap map) { traverseMapValueWithMapAsExpectedType(map, mappingType, expectedType); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index 114256f..a271f95 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.values.*; import io.ballerina.stdlib.data.csvdata.io.DataReaderTask; import io.ballerina.stdlib.data.csvdata.io.DataReaderThreadPool; +import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; @@ -40,7 +41,7 @@ public class Native { public static Object fromCsvWithType(BArray csv, BMap config, BTypedesc type) { try { - return CsvTraversal.traverse(csv, config, type.getDescribingType()); + return CsvTraversal.traverse(csv, CsvUtils.createFromCsvConfiguration(config), type.getDescribingType()); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } @@ -50,15 +51,17 @@ public static Object fromCsvStringWithType(Environment env, Object csv, BMap config, BTypedesc type) { try { - return CsvTraversal.traverse(csv, config, type.getDescribingType()); + return CsvTraversal.traverse(csv, CsvUtils.createToCsvConfiguration(config), type.getDescribingType()); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java index fb1f4a1..b16b732 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java @@ -24,6 +24,7 @@ import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BTypedesc; +import io.ballerina.stdlib.data.csvdata.csv.CsvConfig; import io.ballerina.stdlib.data.csvdata.csv.CsvParser; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; @@ -44,12 +45,14 @@ public class DataReaderTask implements Runnable { private final BObject iteratorObj; private final Future future; private final BTypedesc typed; + private final CsvConfig config; - public DataReaderTask(Environment env, BObject iteratorObj, Future future, BTypedesc typed) { + public DataReaderTask(Environment env, BObject iteratorObj, Future future, BTypedesc typed, CsvConfig config) { this.env = env; this.iteratorObj = iteratorObj; this.future = future; this.typed = typed; + this.config = config; } static MethodType resolveNextMethod(BObject iterator) { @@ -81,7 +84,8 @@ public void run() { ResultConsumer resultConsumer = new ResultConsumer<>(future); try (var byteBlockSteam = new BallerinaByteBlockInputStream(env, iteratorObj, resolveNextMethod(iteratorObj), resolveCloseMethod(iteratorObj), resultConsumer)) { - Object result = CsvParser.parse(new InputStreamReader(byteBlockSteam), typed.getDescribingType()); + Object result = CsvParser.parse(new InputStreamReader(byteBlockSteam), + typed.getDescribingType(), this.config); future.complete(result); } catch (Exception e) { future.complete(DiagnosticLog.getCsvError("Error occurred while reading the stream: " + e.getMessage())); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java index 9b3b2a6..a1c7cc7 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -1,5 +1,27 @@ package io.ballerina.stdlib.data.csvdata.utils; -public class Constants { +import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.values.BString; +public class Constants { + public static class ConfigConstants { + public static BString START_NUMBER = StringUtils.fromString("startNumber"); + public static BString HEADER_START_NUMBER = StringUtils.fromString("headerStartNumber"); + public static BString DATA_START_NUMBER = StringUtils.fromString("dataStartNumber"); + public static BString HEADERS = StringUtils.fromString("headers"); + public static BString ESCAPE_CHARACTER = StringUtils.fromString("escapeCharacter"); + public static BString IGNORE_EMPTY_LINES = StringUtils.fromString("ignoreEmptyLines"); + public static BString SEPARATOR = StringUtils.fromString("separator"); + public static BString QUOTE = StringUtils.fromString("quote"); + public static BString SKIP_HEADERS = StringUtils.fromString("skipHeaders"); + public static BString SKIP_DATA_ROWS = StringUtils.fromString("skipdataRows"); + public static BString DATA_ROW_COUNT = StringUtils.fromString("dataRowCount"); + public static BString ORDER_BY = StringUtils.fromString("orderBy"); + public static BString SKIP_COLUMNS = StringUtils.fromString("skipColumns"); + public static BString CUSTOM_HEADER = StringUtils.fromString("customheader"); + public static BString SUPPRESS_ESCAPING = StringUtils.fromString("suppressEscaping"); + public static BString NULL_VALUE = StringUtils.fromString("nullValue"); + public static BString ROOT = StringUtils.fromString("root"); + public static BString LINE_SEPARATOR = StringUtils.fromString("lineSeparator"); + } } \ No newline at end of file diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java new file mode 100644 index 0000000..a835414 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -0,0 +1,21 @@ +package io.ballerina.stdlib.data.csvdata.utils; + +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BString; +import io.ballerina.stdlib.data.csvdata.csv.CsvConfig; + +public class CsvUtils { + public static CsvConfig createFromCsvConfiguration(BMap config) { + return CsvConfig.createFromCsvConfiguration(config); + } + + public static CsvConfig createToCsvConfiguration(BMap config) { + return CsvConfig.createToCsvConfiguration(config); + } + + public static void validateExpectedArraySize(int size, int currentSize) { + if (size != -1 && size > currentSize) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, currentSize); + } + } +} From 03667eff99f66f870011d64a494e3329cf72c116 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 21 Feb 2024 13:31:55 +0530 Subject: [PATCH 014/147] Refactor the code with user configurations --- ballerina/csv_api.bal | 35 ++- ballerina/tests/consider | 8 + ballerina/tests/note | 1 + ballerina/tests/test.bal | 6 +- .../stdlib/data/csvdata/csv/CsvConfig.java | 36 +-- .../stdlib/data/csvdata/csv/CsvTraversal.java | 231 ++++++++++-------- .../stdlib/data/csvdata/csv/QueryParser.java | 116 +++++++++ .../stdlib/data/csvdata/utils/Constants.java | 9 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 142 +++++++++++ .../csvdata/utils/DiagnosticErrorCode.java | 17 +- native/src/main/resources/error.properties | 3 +- 11 files changed, 451 insertions(+), 153 deletions(-) create mode 100644 ballerina/tests/note create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index d6302ee..0e30437 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -35,24 +35,23 @@ public type MappingConfig record {| |}; public type FromCSVConfig record {| - int startNumber = 0; - int headerStartNumber = 0; - int dataStartNumber = 1; - boolean headers = true; - string:Char escapeCharacter = "\\"; - boolean ignoreEmptyLines = true; - string:Char separator = ","; - string quote = "\""; - boolean skipHeaders = false; - int skipdataRows = 0; - int dataRowCount = -1; - ColumnOrder|ColumnOrder[] orderBy = []; - string|int|string[]|int[]? skipColumns = (); - string[]|int[]? customheader = (); - boolean suppressEscaping = false; - MappingConfig mappingConfig = {}; - anydata nullValue = (); - string? root = (); + int startNumber = 0; // done - 1 + int headerStartNumber = 0; // done - 1 + int dataStartNumber = 1; // done - 1 + boolean headers = true; // done - 1 + string:Char escapeCharacter = "\\"; // done - 1 + boolean ignoreEmptyLines = true; // done - 1 + string:Char separator = ","; // done - 1 + string quote = "\""; // done - 1 + boolean skipHeaders = false; // done - 1 + int skipdataRows = 0; // done - 1 + int dataRowCount = -1; // done - 1 + ColumnOrder|ColumnOrder[]? orderBy = ();// done - 1 + string|int|string[]|int[]? skipColumns = (); // done - 1 + string[]|int[]? customheader = (); // done - 1 + boolean suppressEscaping = false; // done - 1 + // MappingConfig mappingConfig = {}; + anydata nullValue = (); // done - 1 |}; public type ToCSVConfig record {| diff --git a/ballerina/tests/consider b/ballerina/tests/consider index 96e06c7..55b9cdf 100644 --- a/ballerina/tests/consider +++ b/ballerina/tests/consider @@ -1,3 +1,11 @@ array size wenas, oter, inner, both AA -> QQ unions -. inp and output +empty csv, csv with only headers +null values in both data and headers +table +record { + int|string +} kind of tests + +int can be unsigned32 as well, in that case in the java siode we need to check, isNumber and is not Decimal \ No newline at end of file diff --git a/ballerina/tests/note b/ballerina/tests/note new file mode 100644 index 0000000..8b86c4b --- /dev/null +++ b/ballerina/tests/note @@ -0,0 +1 @@ +runtime error for annotaions with open recs, compile error for closed records \ No newline at end of file diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index f02915c..087fbce 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -343,8 +343,6 @@ function testC() returns error? { @test:Config{enable: !enable} function t() returns error? { - string a = check io:fileReadString("a.txt"); - AA aa = check fromCsvStringWithType(a, {}, AA); - test:assertEquals(aa, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); - io:println(aa); + A aa = check fromCsvWithType(a, {}, A); + test:assertEquals(aa, a); } \ No newline at end of file diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java index e6ea36b..2234c76 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java @@ -8,24 +8,24 @@ import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.*; public class CsvConfig { - long startNumber = 0; - long headerStartNumber = 0; - long dataStartNumber = 1; - boolean headers = true; - char escapeCharacter = '\\'; - boolean ignoreEmptyLines = true; - char separator = ','; - String quote = "\""; - boolean skipHeaders = false; - long skipDataRows = 0; - long dataRowCount = -1; - Object orderBy = new ArrayList<>(); - Object skipColumns = null; - Object customHeader = null; - boolean suppressEscaping = false; - Object nullValue = null; - Object root = null; - char lineSeparator = '\n'; + public long startNumber = 0; + public long headerStartNumber = 0; + public long dataStartNumber = 1; + public boolean headers = true; + public char escapeCharacter = '\\'; + public boolean ignoreEmptyLines = true; + public char separator = ','; + public String quote = "\""; + public boolean skipHeaders = false; + public long skipDataRows = 0; + public long dataRowCount = -1; + public Object orderBy = new ArrayList<>(); + public Object skipColumns = null; + public Object customHeader = null; + public boolean suppressEscaping = false; + public Object nullValue = null; + public Object root = null; + public char lineSeparator = '\n'; private CsvConfig(boolean headers, char escapeCharacter, boolean ignoreEmptyLines, diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index d716493..4d20e1a 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -22,18 +22,23 @@ import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; -import io.ballerina.runtime.api.types.*; +import io.ballerina.runtime.api.types.ArrayType; +import io.ballerina.runtime.api.types.Field; +import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.RecordType; +import io.ballerina.runtime.api.types.TupleType; +import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.utils.JsonUtils; import io.ballerina.runtime.api.utils.StringUtils; -import io.ballerina.runtime.api.values.*; import io.ballerina.runtime.api.utils.TypeUtils; +import io.ballerina.runtime.api.values.*; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import java.util.*; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.validateExpectedArraySize; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.*; /** * Convert Csv value to a ballerina record. @@ -77,45 +82,67 @@ void reset() { @SuppressWarnings("unchecked") public Object traverseCsv(BArray csv, CsvConfig config, Type type) { this.config = config; - Type referredType = TypeUtils.getReferredType(type); - // TODO: add root level node configurations - if (referredType.getTag() != TypeTags.ARRAY_TAG) { - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); - } else { - rootCsvNode = ValueCreator.createArrayValue((ArrayType) referredType); - expectedArrayElementType = ((ArrayType) TypeUtils.getReferredType(referredType)).getElementType(); - } - // TODO: Handle the array size count sourceArrayElementType = csv.getElementType(); + Type referredType = TypeUtils.getReferredType(type); int expectedArraySize = ((ArrayType) referredType).getSize(); int sourceArraySize = (int) csv.getLength(); + + setRootCsvNode(referredType, type); validateExpectedArraySize(expectedArraySize, sourceArraySize); - if (TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.UNION_TAG) { - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); - } - if (TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.RECORD_TYPE_TAG - || TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.TABLE_TAG - || TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.MAP_TAG) { - traverseCsvArrayMembersWithMapAsCsvElementType(expectedArraySize == -1 ? sourceArraySize : expectedArraySize, csv, expectedArrayElementType); - } else if (TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.ARRAY_TAG - || TypeUtils.getReferredType(expectedArrayElementType).getTag() == TypeTags.TUPLE_TAG) { - //TODO:Handle tuples - traverseCsvArrayMembersWithArrayAsCsvElementType(expectedArraySize == -1 ? sourceArraySize : expectedArraySize, csv, expectedArrayElementType); - } + + traverseCsvWithExpectedType(expectedArraySize, sourceArraySize, csv); + sortCsvData(); return rootCsvNode; } + private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArraySize, BArray csv) { + switch (expectedArrayElementType.getTag()) { + case TypeTags.RECORD_TYPE_TAG: + case TypeTags.MAP_TAG: + case TypeTags.TABLE_TAG: + traverseCsvArrayMembersWithMapAsCsvElementType(expectedArraySize == -1 ? + sourceArraySize : expectedArraySize, csv, expectedArrayElementType); + break; + case TypeTags.ARRAY_TAG: + case TypeTags.TUPLE_TAG: + traverseCsvArrayMembersWithArrayAsCsvElementType(expectedArraySize == -1 ? + sourceArraySize : expectedArraySize, csv, expectedArrayElementType); + break; + default: + DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); + } + } + public void traverseCsvArrayMembersWithMapAsCsvElementType(long length, BArray csv, Type expectedArrayType) { - // todo once checked, way to find a optimize a way to save and reuse + Object rowValue; for (int i = 0; i < length; i++) { - rootCsvNode.append(traverseCsvElementWithMapOrRecord(csv.get(i), expectedArrayType)); + rowValue = traverseCsvElementWithMapOrRecord(csv.get(i), expectedArrayType); + if (!constructRootCsvNode(rowValue, i, config.dataRowCount)) { + break; + } } } public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray csv, Type expectedArrayType) { + Object rowValue; for (int i = 0; i < length; i++) { - rootCsvNode.append(traverseCsvElementWithArray(csv.get(i), expectedArrayType)); + rowValue = traverseCsvElementWithArray(csv.get(i), expectedArrayType); + if (!constructRootCsvNode(rowValue, i, config.dataRowCount)) { + break; + } + } + } + + private boolean constructRootCsvNode(Object value, int i, long dataRowCount) { + long skipDataRows = config.skipDataRows; + if (i < skipDataRows) { + return true; + } + rootCsvNode.append(value); + if (calculateNumberOfRows(dataRowCount, i, skipDataRows)) { + return false; } + return true; } public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expectedType) { @@ -129,7 +156,6 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected break; case TypeTags.MAP_TAG: MapType mapType = (MapType) expectedType; - this.fieldHierarchy = new HashMap<>(); currentCsvNode = ValueCreator.createMapValue(mapType); traverseCsvMap(csvElement, expectedType, true); break; @@ -147,64 +173,62 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected } public Object traverseCsvElementWithArray(Object csvElement, Type expectedType) { - BArray csvMember; switch (expectedType.getTag()) { case TypeTags.ARRAY_TAG: - // TODO: Do the array Check on the top since this is calling again and again - csvMember = ValueCreator.createArrayValue((ArrayType) TypeUtils.getReferredType(expectedType)); - traverseArrayValue(csvElement, csvMember, false); - return csvMember; + ArrayType arrayType = (ArrayType) expectedType; + currentCsvNode = ValueCreator.createArrayValue(arrayType); + traverseArrayValue(csvElement, arrayType); + break; case TypeTags.TUPLE_TAG: - // TODO: Do the array Check on the top since this is calling again and again - csvMember = ValueCreator.createTupleValue((TupleType) TypeUtils.getReferredType(expectedType)); - traverseArrayValue(csvElement, csvMember, true); - return csvMember; + TupleType tupleType = (TupleType) expectedType; + this.restType = tupleType.getRestType(); + currentCsvNode = ValueCreator.createTupleValue(tupleType); + traverseArrayValue(csvElement, tupleType); + break; + default: + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); + return currentCsvNode; } - private void traverseArrayValue(Object csvElement, BArray csvMember, boolean tuple) { - Type arrayMemberType = csvMember.getType(); + private void traverseArrayValue(Object csvElement, Type type) { + int expectedTypeSize = getTheActualExpectedType(type); if (csvElement instanceof BMap) { - constructArrayValuesFromMap(csvMember, (BMap) csvElement, arrayMemberType); + BMap map = (BMap) csvElement; + constructArrayValuesFromMap(map, type, expectedTypeSize == -1 ? map.size() : expectedTypeSize); } else if (csvElement instanceof BArray) { - constructArrayValuesFromArray(csvMember, (BArray) csvElement, arrayMemberType); + BArray array = (BArray) csvElement; + constructArrayValuesFromArray(array, type, expectedTypeSize == -1 ? array.size() : expectedTypeSize); } } - private void constructArrayValuesFromArray(BArray csvMember, BArray csvElement, Type arrayType) { + private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { int index = 0; - int expectedTypeSize = getTheActualExpectedType(csvMember); - int expectedSize = expectedTypeSize == -1 ? csvElement.size() : expectedTypeSize; for (int i = 0; i < csvElement.getLength(); i++) { if (index >= expectedSize) { break; } - addValuesToArrayType(csvElement.get(i), csvMember, getArrayOrTupleMemberType(arrayType, index), index); + addValuesToArrayType(csvElement.get(i), getArrayOrTupleMemberType(type, index), index); index++; } } - private void constructArrayValuesFromMap(BArray csvMember, BMap map, Type arrayType) { - // TODO: This and above method can be merge + private void constructArrayValuesFromMap(BMap map, Type type, int expectedSize) { int index = 0; - int expectedTypeSize = getTheActualExpectedType(csvMember); - int expectedSize = expectedTypeSize == -1 ? map.size() : expectedTypeSize; for (Object v: map.values()) { if (index >= expectedSize) { break; } - addValuesToArrayType(v, csvMember, getArrayOrTupleMemberType(arrayType, index), index); + addValuesToArrayType(v, getArrayOrTupleMemberType(type, index), index); index++; } } - private int getTheActualExpectedType(BArray csvMember) { - Type type = csvMember.getType(); + private int getTheActualExpectedType(Type type) { if (type instanceof TupleType) { - return ((TupleType) csvMember.getType()).getTupleTypes().size(); + return ((TupleType) type).getTupleTypes().size(); } else { - return ((ArrayType) csvMember.getType()).getSize(); + return ((ArrayType) type).getSize(); } } @@ -215,16 +239,15 @@ private Type getArrayOrTupleMemberType(Type type, int index) { if (tupleTypes.size() >= index + 1) { return tupleTypes.get(index); } - Type tupleRestType = tupleType.getRestType(); - if (tupleRestType != null) { - return tupleRestType; + if (restType != null) { + return restType; } return null; } return ((ArrayType) type).getElementType(); } - private void addValuesToArrayType(Object csvElement, BArray csvMember, Type arrayElementType, int index) { + private void addValuesToArrayType(Object csvElement, Type arrayElementType, int index) { switch (arrayElementType.getTag()) { case TypeTags.NULL_TAG: case TypeTags.BOOLEAN_TAG: @@ -233,7 +256,7 @@ private void addValuesToArrayType(Object csvElement, BArray csvMember, Type arra case TypeTags.DECIMAL_TAG: case TypeTags.STRING_TAG: case TypeTags.XML_TAG: - csvMember.add(index, convertToBasicType(csvElement, arrayElementType)); + ((BArray) currentCsvNode).add(index, convertToBasicType(csvElement, arrayElementType, config)); break; default: DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, arrayElementType); @@ -261,38 +284,38 @@ private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, String[] he if (type instanceof TupleType) { return checkExpectedTypeMatchWithHeadersForTuple(expectedType, headers, (TupleType) type, arraySize); } else { - return checkExpectedTypeMatchWithHeadersForArray(expectedType, headers, csvElement.getElementType(), arraySize); + return checkExpectedTypeMatchWithHeadersForArray(expectedType, + headers, csvElement.getElementType(), arraySize); } } private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, String[] headers, TupleType tupleType, int arraySize) { List tupleTypes = tupleType.getTupleTypes(); - Type restType = tupleType.getRestType(); + Type tupleRestType = tupleType.getRestType(); if (expectedType instanceof RecordType) { - RecordType recordType = (RecordType) expectedType; - Type restFieldType = recordType.getRestFieldType(); - if (restFieldType != null && restFieldType.getTag() == TypeTags.ANYDATA_TAG) { + if (this.restType != null && this.restType.getTag() == TypeTags.ANYDATA_TAG) { return true; } - Map fields = recordType.getFields(); - boolean isCompatible = true; - for (Type type: tupleTypes) { - //TODO: optimize - for (Field field: fields.values()) { - if (field.getFieldType().getTag() == type.getTag()) { - fields.values().remove(field.getFieldType()); - continue; - } - if (type == restFieldType) { - continue; + + for (int i = 0; i < tupleTypes.size(); i++) { + Type type = tupleTypes.get(i); + String header = headers[i]; + Field field = this.fieldHierarchy.get(header); + + if (field != null) { + if (type.getTag() != field.getFieldType().getTag()) { + return false; } - break; + continue; + } + + if (tupleRestType != null && this.restType == tupleRestType) { + continue; } - } - if (restType != null && restType != restFieldType) { return false; } + return true; } return false; } @@ -300,18 +323,17 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Str private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, String[] headers, Type arrayType, int arraySize) { arrayType = TypeUtils.getReferredType(arrayType); if (expectedType instanceof RecordType) { - RecordType recordType = (RecordType) expectedType; - Type restFieldType = recordType.getRestFieldType(); - if (restFieldType != null && (restFieldType == arrayType - || restFieldType.getTag() == TypeTags.ANYDATA_TAG)) { + if (this.restType != null && (this.restType == arrayType + || this.restType.getTag() == TypeTags.ANYDATA_TAG)) { return true; } - Set fields = recordType.getFields().keySet(); + for (int i = 0; i < headers.length; i++) { - if (!fields.contains(headers[i])) { + if (!this.fieldHierarchy.containsKey(headers[i])) { return false; } } + return true; } return false; } @@ -321,11 +343,7 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean BString key; int arraySize = csvElement.size(); String[] headers = new String[arraySize]; - //TODO: Update this, set Default headers to field Hierachy - boolean defaultHeaders = true; - for (int i = 0; i < arraySize; i++) { - headers[i] = String.valueOf( i + 1); - } + headers = createHeaders(headers, config); boolean conversion = checkExpectedTypeMatchWithHeaders(expectedType, headers, csvElement, arraySize); if (!conversion) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csvElement, expectedType); @@ -394,8 +412,8 @@ private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BStrin case TypeTags.FLOAT_TAG: case TypeTags.DECIMAL_TAG: case TypeTags.STRING_TAG: - Object value = convertToBasicType(mapValue, currentFieldType); - ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), value); + ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), + convertToBasicType(mapValue, currentFieldType, config)); break; default: // TODO: handle maps and structure values in future @@ -432,6 +450,7 @@ private boolean checkTypeCompatibility(Type constraintType, Object csv) { return true; } else if ((csv instanceof BString && constraintType.getTag() == TypeTags.STRING_TAG) || (csv instanceof Long && constraintType.getTag() == TypeTags.INT_TAG) + || (csv instanceof BDecimal && constraintType.getTag() == TypeTags.DECIMAL_TAG) || (csv instanceof Double && (constraintType.getTag() == TypeTags.FLOAT_TAG || constraintType.getTag() == TypeTags.DECIMAL_TAG)) || (Boolean.class.isInstance(csv) && constraintType.getTag() == TypeTags.BOOLEAN_TAG) @@ -455,19 +474,25 @@ private void checkOptionalFieldsAndLogError(Map currentField) { }); } - private Object convertToBasicType(Object csv, Type targetType) { - if (targetType.getTag() == TypeTags.READONLY_TAG) { - return csv; + private void setRootCsvNode(Type referredType, Type type) { + if (referredType.getTag() != TypeTags.ARRAY_TAG) { + DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); + } else { + rootCsvNode = ValueCreator.createArrayValue((ArrayType) referredType); + expectedArrayElementType = ((ArrayType) TypeUtils.getReferredType(referredType)).getElementType(); } - try { - Object value = JsonUtils.convertJSON(csv, targetType); - if (value instanceof String) { - return StringUtils.fromString(value.toString()); - } - return value; - } catch (Exception e) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, targetType); + } + + private void sortCsvData() { + Object orderConfiguration = config.orderBy; + if (orderConfiguration == null) { + return; } + + Object[] arrayValues = rootCsvNode.getValues(); + Arrays.sort(arrayValues, (value1, value2) -> compareCsvColumns( + value1, value2, constructSortingColumnNames(orderConfiguration)) + ); } } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java new file mode 100644 index 0000000..75dd0ed --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java @@ -0,0 +1,116 @@ +package io.ballerina.stdlib.data.csvdata.csv; + +import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.values.BArray; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +public class QueryParser { + private static String columnSeparator = ","; + private static String rangeSeparator = ":"; + private static String exclamationCharacter = "!"; + private static String astrix = "*"; + private static String groupingStartCharacter = "("; + private static String groupingEndCharacter = ")"; + private static Object skipColumnQuery = null; + private static Set inclusiveHeaders = new HashSet<>(); + private static Set exclusiveHeaders = new HashSet<>(); + private static ArrayList columns = null; + private static String elementSeparatorRegex = "(?![^(]*\\))"; + private static String alphanumericRegex = "[0-9A-Za-z]"; + private static String rangeRegex = "[0-9A-Za-z]:[0-9A-Za-z]"; + + private void reset() { + inclusiveHeaders = new HashSet<>(); + exclusiveHeaders = new HashSet<>(); + } + + public static String[] parse(Object query, String[] headers) { + //TODO: Need specific error message for all the scenarios + skipColumnQuery = query; + columns = new ArrayList<>(Arrays.asList(headers)); + return parse(); + } + + private static String[] parse() { + if (skipColumnQuery instanceof BArray) { + BArray columns = (BArray) skipColumnQuery; + for (int i = 0; i < columns.size(); i++) { + exclusiveHeaders.add(StringUtils.getStringValue(columns.get(i))); + } + } else if (skipColumnQuery instanceof Long) { + exclusiveHeaders.add(skipColumnQuery.toString()); + } else { + processStringQuery(StringUtils.getStringValue(skipColumnQuery)); + } + + exclusiveHeaders.removeAll(inclusiveHeaders); + columns.removeAll(exclusiveHeaders); + return columns.toArray(new String[columns.size()]); + } + + private static void processStringQuery(String query) { + processStringQuery(query, false); + } + + private static void processStringQuery(String query, boolean exclamation) { + String[] queryElements = query.split(elementSeparatorRegex); + for (String element: queryElements) { + //TODO: Header validations + if (element.matches(alphanumericRegex)) { + addColumn(element, exclamation); + } else if (element.startsWith(groupingStartCharacter)) { + processGroupingElements(element, exclamation); + } else if (element.startsWith(exclamationCharacter)) { + processExcludeColumns(element, !exclamation); + } else if (element.matches(rangeRegex)) { + processRangeExpression(element, exclamation); + } else { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_SKIP_COLUMN_QUERY, skipColumnQuery); + } + } + } + + private static void addColumn(String element, boolean exclamation) { + if (exclamation) { + inclusiveHeaders.add(element); + } + exclusiveHeaders.add(element); + } + + private static void processExcludeColumns(String element, boolean exclamation) { + processStringQuery(element.substring(1), exclamation); + } + + private static void processRangeExpression(String element, boolean exclamation) { + //TODO: Handle if range contains brackets and :/,! + String[] rangeElements = element.split(rangeSeparator); + String rightValue = rangeElements[1]; + int leftIndex = columns.indexOf(rangeElements[0]); + int rightIndex = rightValue.equals(astrix) ? columns.size() - 1 : columns.indexOf(rightValue); + + if (leftIndex == -1 || rightIndex == -1) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_SKIP_COLUMN_QUERY, skipColumnQuery); + } + if (leftIndex > rightIndex) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_SKIP_COLUMN_QUERY, skipColumnQuery); + } + + for (int i = leftIndex; i <= rightIndex; i++) { + addColumn(columns.get(i), exclamation); + } + } + + private static void processGroupingElements(String element, boolean exclamation) { + if (element.endsWith(groupingEndCharacter)) { + processStringQuery(element.substring(0, element.length() - 1), exclamation); + } else { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_SKIP_COLUMN_QUERY, skipColumnQuery); + } + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java index a1c7cc7..15d1490 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -24,4 +24,11 @@ public static class ConfigConstants { public static BString ROOT = StringUtils.fromString("root"); public static BString LINE_SEPARATOR = StringUtils.fromString("lineSeparator"); } -} \ No newline at end of file + + public static class OrderConfigs { + public static BString COLUMN = StringUtils.fromString("column"); + public static BString COLUMN_ORDER = StringUtils.fromString("columnOrder"); + public static BString ASC = StringUtils.fromString("ASC"); + public static BString DESC = StringUtils.fromString("DESC"); + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index a835414..c1667a7 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -1,8 +1,16 @@ package io.ballerina.stdlib.data.csvdata.utils; +import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.utils.JsonUtils; +import io.ballerina.runtime.api.utils.StringUtils; +import io.ballerina.runtime.api.values.BArray; +import io.ballerina.runtime.api.values.BDecimal; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.data.csvdata.csv.CsvConfig; +import io.ballerina.stdlib.data.csvdata.csv.CsvTraversal; +import io.ballerina.stdlib.data.csvdata.csv.QueryParser; public class CsvUtils { public static CsvConfig createFromCsvConfiguration(BMap config) { @@ -18,4 +26,138 @@ public static void validateExpectedArraySize(int size, int currentSize) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, currentSize); } } + + public static int compareCsvColumns(Object row1, Object row2, SortConfigurations[] sortConfigurations) { + Object o1,o2; + int value; + for (SortConfigurations sortConfig: sortConfigurations) { + o1 = getRowValueForSort(row1, sortConfig.columnName); + o2 = getRowValueForSort(row2, sortConfig.columnName); + value = compareTwoColumnAndGetValue(o1, o2); + + if (value == 0) { + continue; + } + if (sortConfig.sortOrder.equals(Constants.OrderConfigs.DESC)) { + return -1 * value; + } + return value; + } + return 0; + } + + public static Object getRowValueForSort(Object row, Object columnName) { + if (row instanceof BMap) { + return ((BMap) row).get(columnName); + } else { + if (columnName instanceof Long) { + return ((BArray) row).get((long) columnName); + } else { + // TODO: Add a new error + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, "Test", "Test"); + } + } + } + + + public static SortConfigurations[] constructSortingColumnNames(Object orderConfiguration) { + BString columnName = Constants.OrderConfigs.COLUMN; + BString sortOrder = Constants.OrderConfigs.COLUMN_ORDER; + + SortConfigurations[] columns = new SortConfigurations[]{}; + if (orderConfiguration instanceof BMap) { + BMap orderConfigMap = (BMap) orderConfiguration; + columns[0] = new SortConfigurations(orderConfigMap.get(columnName), orderConfigMap.get(sortOrder)); + } else { + BArray orderConfigArray = (BArray) orderConfiguration; + for (int i = 0; i < orderConfigArray.size(); i++) { + BMap orderConfigMap = (BMap) orderConfigArray.get(i); + columns[i] = new SortConfigurations(orderConfigMap.get(columnName), orderConfigMap.get(sortOrder)); + } + } + return columns; + } + + public static int compareTwoColumnAndGetValue(Object o1, Object o2) { + if (o1 == null && o2 ==null) { + return 0; + } + if (o1 == null) { + return -1; + } + if (o2 == null) { + return 1; + } + if (o1 instanceof Long && o2 instanceof Long) { + return ((Long) o1).compareTo((Long) o2); + } + if (o1 instanceof Boolean && o2 instanceof Boolean) { + return ((Boolean) o1).compareTo((Boolean) o2); + } + if (o1 instanceof BDecimal && o2 instanceof BDecimal) { + return (((BDecimal) o1).decimalValue()).compareTo(((BDecimal) o1).decimalValue()); + } + if (o1 instanceof Float && o2 instanceof Float) { + return ((Float) o1).compareTo((Float) o2); + } + if (o1 instanceof Double && o2 instanceof Double) { + return ((Double) o1).compareTo((Double) o2); + } + return (StringUtils.getStringValue(o1)).compareTo(StringUtils.getStringValue(o2)); + } + + public static boolean calculateNumberOfRows(long dataRowCount, int i, long skipDataRows) { + return dataRowCount != -1 && i >= dataRowCount + skipDataRows; + } + + public static String[] createHeaders(String[] headers, CsvConfig config) { + Object customHeaders = config.customHeader; + + if (customHeaders == null) { + for (int i = 0; i < headers.length; i++) { + headers[i] = String.valueOf( i + 1); + } + } + + if (customHeaders instanceof BArray) { + BArray array = (BArray) customHeaders; + for (int i = 0; i < headers.length; i++) { + headers[i] = array.get(i).toString(); + } + } + + Object skipColumns = config.skipColumns; + if (skipColumns == null) { + return headers; + } + return QueryParser.parse(config.skipColumns, headers); + } + + public static Object convertToBasicType(Object csv, Type targetType, CsvConfig config) { + if (targetType.getTag() == TypeTags.READONLY_TAG) { + return csv; + } + try { + Object value = JsonUtils.convertJSON(csv, targetType); + if (value == null) { + return config.nullValue; + } + if (value instanceof String) { + return StringUtils.fromString(value.toString()); + } + return value; + } catch (Exception e) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, targetType); + } + } + + public static class SortConfigurations { + protected Object columnName; + protected Object sortOrder; + + public SortConfigurations(Object columnName, Object sortOrder) { + this.columnName = columnName; + this.sortOrder = sortOrder; + } + } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index eab0288..7d6425b 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -27,14 +27,15 @@ public enum DiagnosticErrorCode { INVALID_TYPE("BDE_0001", "invalid.type"), UNION_TYPES_NOT_ALLOWED("BDE_0002", "union.types.not.allowed.as.expected.type"), - INVALID_ARRAY_MEMBER("BDE_0001", "invalid.array.member.in.expected.type"), - INVALID_FIELD_IN_CSV("BDE_0001", "cannot.found.field.in.csv"), - INVALID_CAST("BDE_0001", "csv.value.cannot.cast.into.expected.type"), - INVALID_EXPECTED_TYPE("BDE_0001", "invalid.expected.type"), - INVALID_TOKEN("BDE_0001", "invalid.token.while.reading.the.csv.data"), - INVALID_CSV_DATA_FORMAT("BDE_0001", "invalid.csv.data.format"), - INVALID_EXPECTED_ARRAY_SIZE("BDE_0001", "invalid.expected.array.size"), - INVALID_EXPECTED_TUPLE_SIZE("BDE_0001", "invalid.expected.tuple.size"); + INVALID_ARRAY_MEMBER("BDE_0003", "invalid.array.member.in.expected.type"), + INVALID_FIELD_IN_CSV("BDE_0004", "cannot.found.field.in.csv"), + INVALID_CAST("BDE_0005", "csv.value.cannot.cast.into.expected.type"), + INVALID_EXPECTED_TYPE("BDE_0006", "invalid.expected.type"), + INVALID_TOKEN("BDE_0007", "invalid.token.while.reading.the.csv.data"), + INVALID_CSV_DATA_FORMAT("BDE_0008", "invalid.csv.data.format"), + INVALID_EXPECTED_ARRAY_SIZE("BDE_0009", "invalid.expected.array.size"), + INVALID_EXPECTED_TUPLE_SIZE("BDE_0010", "invalid.expected.tuple.size"), + INVALID_SKIP_COLUMN_QUERY("BDE_0011", "invalid.skip.column.query"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index ffc7b93..be6ad82 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -50,4 +50,5 @@ error.invalid.expected.array.size=\ error.invalid.expected.tuple.size=\ invalid array size for expected tuple type, cannot be greater than ''{0}'' - +error.invalid.skip.column.query=\ + invalid query found for skip column field, ''{0}'' From 940fd33f829bac04f18dc898ac5f1015a5779685 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 21 Feb 2024 13:44:25 +0530 Subject: [PATCH 015/147] Refactor the traversal function --- .../stdlib/data/csvdata/csv/CsvTraversal.java | 67 +------------------ .../stdlib/data/csvdata/utils/CsvUtils.java | 66 ++++++++++++++++++ 2 files changed, 69 insertions(+), 64 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 4d20e1a..bbb05f8 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -21,18 +21,15 @@ import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ValueCreator; -import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.Field; import io.ballerina.runtime.api.types.MapType; import io.ballerina.runtime.api.types.RecordType; import io.ballerina.runtime.api.types.TupleType; import io.ballerina.runtime.api.types.Type; -import io.ballerina.runtime.api.utils.JsonUtils; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.*; -import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; @@ -208,7 +205,8 @@ private void constructArrayValuesFromArray(BArray csvElement, Type type, int exp if (index >= expectedSize) { break; } - addValuesToArrayType(csvElement.get(i), getArrayOrTupleMemberType(type, index), index); + addValuesToArrayType(csvElement.get(i), + getArrayOrTupleMemberType(type, index), index, currentCsvNode, config); index++; } } @@ -219,19 +217,11 @@ private void constructArrayValuesFromMap(BMap map, Type type, i if (index >= expectedSize) { break; } - addValuesToArrayType(v, getArrayOrTupleMemberType(type, index), index); + addValuesToArrayType(v, getArrayOrTupleMemberType(type, index), index, currentCsvNode, config); index++; } } - private int getTheActualExpectedType(Type type) { - if (type instanceof TupleType) { - return ((TupleType) type).getTupleTypes().size(); - } else { - return ((ArrayType) type).getSize(); - } - } - private Type getArrayOrTupleMemberType(Type type, int index) { if (type instanceof TupleType) { TupleType tupleType = (TupleType) type; @@ -247,22 +237,6 @@ private Type getArrayOrTupleMemberType(Type type, int index) { return ((ArrayType) type).getElementType(); } - private void addValuesToArrayType(Object csvElement, Type arrayElementType, int index) { - switch (arrayElementType.getTag()) { - case TypeTags.NULL_TAG: - case TypeTags.BOOLEAN_TAG: - case TypeTags.INT_TAG: - case TypeTags.FLOAT_TAG: - case TypeTags.DECIMAL_TAG: - case TypeTags.STRING_TAG: - case TypeTags.XML_TAG: - ((BArray) currentCsvNode).add(index, convertToBasicType(csvElement, arrayElementType, config)); - break; - default: - DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, arrayElementType); - } - } - private void traverseCsvMap(Object csvElement, Type expectedType, boolean mappingType) { if (csvElement instanceof BMap map) { traverseMapValueWithMapAsExpectedType(map, mappingType, expectedType); @@ -439,41 +413,6 @@ private void addRestField(Type restFieldType, BString key, Object csvMember) { } } - private boolean checkTypeCompatibility(Type constraintType, Object csv) { - if (csv instanceof BMap) { - BMap map = (BMap) csv; - for (BString key : map.getKeys()) { - if (!checkTypeCompatibility(constraintType, map.get(key))) { - return false; - } - } - return true; - } else if ((csv instanceof BString && constraintType.getTag() == TypeTags.STRING_TAG) - || (csv instanceof Long && constraintType.getTag() == TypeTags.INT_TAG) - || (csv instanceof BDecimal && constraintType.getTag() == TypeTags.DECIMAL_TAG) - || (csv instanceof Double && (constraintType.getTag() == TypeTags.FLOAT_TAG - || constraintType.getTag() == TypeTags.DECIMAL_TAG)) - || (Boolean.class.isInstance(csv) && constraintType.getTag() == TypeTags.BOOLEAN_TAG) - || (csv == null && constraintType.getTag() == TypeTags.NULL_TAG)) { - return true; - } else { - return false; - } - } - - private void checkOptionalFieldsAndLogError(Map currentField) { - currentField.values().forEach(field -> { - if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); - } - // TODO: Handle this properly - if (!(SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED) && - SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL))) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); - } - }); - } - private void setRootCsvNode(Type referredType, Type type) { if (referredType.getTag() != TypeTags.ARRAY_TAG) { DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index c1667a7..9a3afaa 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -1,6 +1,10 @@ package io.ballerina.stdlib.data.csvdata.utils; import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.flags.SymbolFlags; +import io.ballerina.runtime.api.types.ArrayType; +import io.ballerina.runtime.api.types.Field; +import io.ballerina.runtime.api.types.TupleType; import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.utils.JsonUtils; import io.ballerina.runtime.api.utils.StringUtils; @@ -12,6 +16,8 @@ import io.ballerina.stdlib.data.csvdata.csv.CsvTraversal; import io.ballerina.stdlib.data.csvdata.csv.QueryParser; +import java.util.Map; + public class CsvUtils { public static CsvConfig createFromCsvConfiguration(BMap config) { return CsvConfig.createFromCsvConfiguration(config); @@ -151,6 +157,66 @@ public static Object convertToBasicType(Object csv, Type targetType, CsvConfig c } } + public static void checkOptionalFieldsAndLogError(Map currentField) { + currentField.values().forEach(field -> { + if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); + } + // TODO: Handle this properly + if (!(SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED) && + SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL))) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); + } + }); + } + + public static boolean checkTypeCompatibility(Type constraintType, Object csv) { + if (csv instanceof BMap) { + BMap map = (BMap) csv; + for (BString key : map.getKeys()) { + if (!checkTypeCompatibility(constraintType, map.get(key))) { + return false; + } + } + return true; + } else if ((csv instanceof BString && constraintType.getTag() == TypeTags.STRING_TAG) + || (csv instanceof Long && constraintType.getTag() == TypeTags.INT_TAG) + || (csv instanceof BDecimal && constraintType.getTag() == TypeTags.DECIMAL_TAG) + || (csv instanceof Double && (constraintType.getTag() == TypeTags.FLOAT_TAG + || constraintType.getTag() == TypeTags.DECIMAL_TAG)) + || (Boolean.class.isInstance(csv) && constraintType.getTag() == TypeTags.BOOLEAN_TAG) + || (csv == null && constraintType.getTag() == TypeTags.NULL_TAG)) { + return true; + } else { + return false; + } + } + + public static void addValuesToArrayType(Object csvElement, Type arrayElementType, int index, + Object currentCsvNode, CsvConfig config) { + switch (arrayElementType.getTag()) { + case TypeTags.NULL_TAG: + case TypeTags.BOOLEAN_TAG: + case TypeTags.INT_TAG: + case TypeTags.FLOAT_TAG: + case TypeTags.DECIMAL_TAG: + case TypeTags.STRING_TAG: + case TypeTags.XML_TAG: + ((BArray) currentCsvNode).add(index, convertToBasicType(csvElement, arrayElementType, config)); + break; + default: + DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, arrayElementType); + } + } + + public static int getTheActualExpectedType(Type type) { + if (type instanceof TupleType) { + return ((TupleType) type).getTupleTypes().size(); + } else { + return ((ArrayType) type).getSize(); + } + } + public static class SortConfigurations { protected Object columnName; protected Object sortOrder; From 4c9f9ad927e297fb34cf842baa68e97a5bd70d73 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 6 Mar 2024 15:08:44 +0530 Subject: [PATCH 016/147] Add usere configs and basic tests --- ballerina/Dependencies.toml | 25 +- ballerina/csv_api.bal | 34 +- ballerina/tests/consider | 24 +- ballerina/tests/from_csv_with_type_test.bal | 623 +++++++ ballerina/tests/test.bal | 556 +++--- ballerina/tests/types.bal | 1531 +++++++++++++++++ ballerina/tests/user_configurations.bal | 75 + ballerina/tests/values.bal | 107 ++ .../stdlib/data/csvdata/FromString.java | 28 +- .../stdlib/data/csvdata/csv/CsvCreator.java | 11 +- .../stdlib/data/csvdata/csv/CsvParser.java | 145 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 98 +- .../stdlib/data/csvdata/csv/QueryParser.java | 4 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 36 +- .../csvdata/utils/DiagnosticErrorCode.java | 3 +- native/src/main/resources/error.properties | 3 + 16 files changed, 2918 insertions(+), 385 deletions(-) create mode 100644 ballerina/tests/from_csv_with_type_test.bal create mode 100644 ballerina/tests/types.bal create mode 100644 ballerina/tests/user_configurations.bal create mode 100644 ballerina/tests/values.bal diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 8c17176..dff49a8 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,14 +5,13 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.1" +distribution-version = "2201.8.4" [[package]] org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] @@ -20,19 +19,6 @@ modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} ] -[[package]] -org = "ballerina" -name = "io" -version = "1.6.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -50,15 +36,6 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - [[package]] org = "ballerina" name = "test" diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 0e30437..01f4d6a 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -35,23 +35,23 @@ public type MappingConfig record {| |}; public type FromCSVConfig record {| - int startNumber = 0; // done - 1 - int headerStartNumber = 0; // done - 1 - int dataStartNumber = 1; // done - 1 - boolean headers = true; // done - 1 - string:Char escapeCharacter = "\\"; // done - 1 - boolean ignoreEmptyLines = true; // done - 1 - string:Char separator = ","; // done - 1 - string quote = "\""; // done - 1 - boolean skipHeaders = false; // done - 1 - int skipdataRows = 0; // done - 1 - int dataRowCount = -1; // done - 1 - ColumnOrder|ColumnOrder[]? orderBy = ();// done - 1 - string|int|string[]|int[]? skipColumns = (); // done - 1 - string[]|int[]? customheader = (); // done - 1 - boolean suppressEscaping = false; // done - 1 + int startNumber = 0; // done + int headerStartNumber = 0; // done + int dataStartNumber = 1; // done + boolean headers = true; // done + string:Char escapeCharacter = "\\"; + boolean ignoreEmptyLines = true; // done + string:Char separator = ","; // done + string quote = "\""; + boolean skipHeaders = false; // done + int skipdataRows = 0; // done + int dataRowCount = -1; // done + ColumnOrder|ColumnOrder[]? orderBy = (); // done + string|int|string[]|int[]? skipColumns = (); + string[]|int[]? customheader = (); // done + boolean suppressEscaping = false; // MappingConfig mappingConfig = {}; - anydata nullValue = (); // done - 1 + anydata nullValue = (); // done |}; public type ToCSVConfig record {| @@ -73,7 +73,7 @@ public isolated function fromCsvWithType((string[]|map|record{})[] csv, returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function fromCsvStringWithType(string|byte[]|stream s, - FromCSVConfig config,typedesc<(record{}|map|anydata)[]> t = <>) + FromCSVConfig config = {} ,typedesc<(record{}|map|anydata)[]> t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function toCsv((anydata[]|map|record{})[] csv, ToCSVConfig config = {}, typedesc<(record{}|map|anydata[])[]> t = <>) diff --git a/ballerina/tests/consider b/ballerina/tests/consider index 55b9cdf..0acdd36 100644 --- a/ballerina/tests/consider +++ b/ballerina/tests/consider @@ -8,4 +8,26 @@ record { int|string } kind of tests -int can be unsigned32 as well, in that case in the java siode we need to check, isNumber and is not Decimal \ No newline at end of file +int can be unsigned32 as well, in that case in the java siode we need to check, isNumber and is not Decimal +skip data rows and datarow count large small equal default scenarios + +startNumber > dataStartNumber +skip columns query, nested queries +target ttype should be compatible if the skip is happen or not + + +LESS TESTS FOR UNIONS AND NULLABLE< CHECK THE ERROR MESSAGES IN V1. + +A CSV header that not in record and vice versa +Add tests by changing the type, string to int int to string like that + +map record field with default values (match fields with default ) + + +without defining types. + +need a combination for mix types. string field to int. boolean field for null like that + +missing field error message, field is random + +unsigned 32 \ No newline at end of file diff --git a/ballerina/tests/from_csv_with_type_test.bal b/ballerina/tests/from_csv_with_type_test.bal new file mode 100644 index 0000000..586f688 --- /dev/null +++ b/ballerina/tests/from_csv_with_type_test.bal @@ -0,0 +1,623 @@ +import ballerina/test; + +// @test:Config +// function testFromCsvWithTypeForMapAndMapAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForRecordAndRecordAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForMapAndArrayAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForMapAndTupleAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForRecordAndMapAsExpextedType() { + +// } + +boolean enable = true; + +@test:Config {enable} +function testFromCsvWithTypeForMapAndRecordAsExpextedType() { + BooleanRecord1Array|CsvConversionError bm1br1 = fromCsvWithType([bm1, bm1], {}, BooleanRecord1Array); + test:assertTrue(bm1br1 is CsvConversionError); + test:assertEquals((bm1br1).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord1Array|CsvConversionError bm2br1 = fromCsvWithType([bm2, bm2], {}, BooleanRecord1Array); + test:assertTrue(bm2br1 is CsvConversionError); + test:assertEquals((bm2br1).message(), generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord1Array|CsvConversionError bm3br1 = fromCsvWithType([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|CsvConversionError bm4br1 = fromCsvWithType([bm4, bm4], {}, BooleanRecord1Array); + test:assertTrue(bm4br1 is CsvConversionError); + test:assertEquals((bm4br1).message(), generateErrorMessageForMissingRequiredField("b2")); + + BooleanRecord1Array|CsvConversionError bm5br1 = fromCsvWithType([bm5, bm5], {}, BooleanRecord1Array); + test:assertEquals(bm5br1, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + BooleanRecord2Array|CsvConversionError bm1br2 = fromCsvWithType([bm1, bm1], {}, BooleanRecord2Array); + test:assertTrue(bm1br2 is CsvConversionError); + test:assertEquals((bm1br2).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord2Array|CsvConversionError bm2br2 = fromCsvWithType([bm2, bm2], {}, BooleanRecord2Array); + test:assertTrue(bm2br2 is CsvConversionError); + test:assertEquals((bm2br2).message(), generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord2Array|CsvConversionError bm3br2 = fromCsvWithType([bm3, bm3], {}, BooleanRecord2Array); + test:assertEquals(bm3br2, [ + {b1: true, b2: false, b3: (), b4: false}, + {b1: true, b2: false, b3: (), b4: false} + ]); + + BooleanRecord2Array|CsvConversionError bm4br2 = fromCsvWithType([bm4, bm4], {}, BooleanRecord2Array); + test:assertTrue(bm4br2 is CsvConversionError); + test:assertEquals((bm4br2).message(), generateErrorMessageForMissingRequiredField("b2")); + + BooleanRecord2Array|CsvConversionError bm5br2 = fromCsvWithType([bm5, bm5], {}, BooleanRecord2Array); + test:assertEquals(bm5br2, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + BooleanRecord3Array|CsvConversionError bm1br3 = fromCsvWithType([bm1, bm1], {}, BooleanRecord3Array); + test:assertTrue(bm1br3 is CsvConversionError); + test:assertEquals((bm1br3).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord3Array|CsvConversionError bm2br3 = fromCsvWithType([bm2, bm2], {}, BooleanRecord3Array); + test:assertEquals(bm2br3, [ + {b1: true, b3: ()}, + {b1: true, b3: ()} + ]); + + BooleanRecord3Array|CsvConversionError bm3br3 = fromCsvWithType([bm3, bm3], {}, BooleanRecord3Array); + test:assertEquals(bm3br3, [ + {b1: true, b3: ()}, + {b1: true, b3: ()} + ]); + + BooleanRecord3Array|CsvConversionError bm4br3 = fromCsvWithType([bm4, bm4], {}, BooleanRecord3Array); + test:assertTrue(bm4br3 is CsvConversionError); + test:assertEquals((bm4br3).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord3Array|CsvConversionError bm5br3 = fromCsvWithType([bm5, bm5], {}, BooleanRecord3Array); + test:assertEquals(bm5br3, [{b1: true, b3: ()}, {b1: true, b3: ()}]); + + BooleanRecord4Array|CsvConversionError bm1br4 = fromCsvWithType([bm1, bm1], {}, BooleanRecord4Array); + test:assertTrue(bm1br4 is CsvConversionError); + test:assertEquals((bm1br4).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord4Array|CsvConversionError bm2br4 = fromCsvWithType([bm2, bm2], {}, BooleanRecord4Array); + test:assertEquals(bm2br4, [ + {b1: true, b2: false, b3: (), n1: (), n3: ()}, + {b1: true, b2: false, b3: (), n1: (), n3: ()} + ]); + + BooleanRecord4Array|CsvConversionError bm3br4 = fromCsvWithType([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|CsvConversionError bm4br4 = fromCsvWithType([bm4, bm4], {}, BooleanRecord4Array); + test:assertTrue(bm4br4 is CsvConversionError); + test:assertEquals((bm4br4).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord4Array|CsvConversionError bm5br4 = fromCsvWithType([bm5, bm5], {}, BooleanRecord4Array); + test:assertEquals(bm5br4, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + BooleanRecord5Array|CsvConversionError bm1br5 = fromCsvWithType([bm1, bm1], {}, BooleanRecord5Array); + test:assertTrue(bm1br5 is CsvConversionError); + test:assertEquals((bm1br5).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord5Array|CsvConversionError bm2br5 = fromCsvWithType([bm2, bm2], {}, BooleanRecord5Array); + test:assertEquals(bm2br5, [ + {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()} + ]); + + BooleanRecord5Array|CsvConversionError bm3br5 = fromCsvWithType([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|CsvConversionError bm4br5 = fromCsvWithType([bm4, bm4], {}, BooleanRecord5Array); + test:assertTrue(bm4br5 is CsvConversionError); + test:assertEquals((bm4br5).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord5Array|CsvConversionError bm5br5 = fromCsvWithType([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|CsvConversionError bm1br6 = fromCsvWithType([bm1, bm1], {}, BooleanRecord6Array); + test:assertTrue(bm1br6 is CsvConversionError); + test:assertEquals((bm1br6).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord6Array|CsvConversionError bm2br6 = fromCsvWithType([bm2, bm2], {}, BooleanRecord6Array); + test:assertEquals(bm2br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError bm3br6 = fromCsvWithType([bm3, bm3], {}, BooleanRecord6Array); + test:assertEquals(bm3br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError bm4br6 = fromCsvWithType([bm4, bm4], {}, BooleanRecord6Array); + test:assertTrue(bm4br6 is CsvConversionError); + test:assertEquals((bm4br6).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord6Array|CsvConversionError bm5br6 = fromCsvWithType([bm5, bm5], {}, BooleanRecord6Array); + test:assertEquals(bm5br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord7Array|CsvConversionError bm1br7 = fromCsvWithType([bm1, bm1], {}, BooleanRecord7Array); + test:assertTrue(bm1br7 is CsvConversionError); + test:assertEquals((bm1br7).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord7Array|CsvConversionError bm2br7 = fromCsvWithType([bm2, bm2], {}, BooleanRecord7Array); + test:assertTrue(bm2br7 is CsvConversionError); + test:assertEquals((bm2br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord7Array|CsvConversionError bm3br7 = fromCsvWithType([bm3, bm3], {}, BooleanRecord7Array); + test:assertTrue(bm3br7 is CsvConversionError); + test:assertEquals((bm3br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord7Array|CsvConversionError bm4br7 = fromCsvWithType([bm4, bm4], {}, BooleanRecord7Array); + test:assertTrue(bm4br7 is CsvConversionError); + test:assertEquals((bm4br7).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord7Array|CsvConversionError bm5br7 = fromCsvWithType([bm5, bm5], {}, BooleanRecord7Array); + test:assertTrue(bm5br7 is CsvConversionError); + test:assertEquals((bm5br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord8Array|CsvConversionError bm1br8 = fromCsvWithType([bm1, bm1], {}, BooleanRecord8Array); + test:assertTrue(bm1br8 is CsvConversionError); + test:assertEquals((bm1br8).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord8Array|CsvConversionError bm2br8 = fromCsvWithType([bm2, bm2], {}, BooleanRecord8Array); + test:assertTrue(bm2br8 is CsvConversionError); + test:assertEquals((bm2br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord8Array|CsvConversionError bm3br8 = fromCsvWithType([bm3, bm3], {}, BooleanRecord8Array); + test:assertTrue(bm3br8 is CsvConversionError); + test:assertEquals((bm3br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord8Array|CsvConversionError bm4br8 = fromCsvWithType([bm4, bm4], {}, BooleanRecord8Array); + test:assertTrue(bm4br8 is CsvConversionError); + test:assertEquals((bm4br8).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord8Array|CsvConversionError bm5br8 = fromCsvWithType([bm5, bm5], {}, BooleanRecord8Array); + test:assertTrue(bm5br8 is CsvConversionError); + test:assertEquals((bm5br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); +} + +@test:Config {enable} +function testFromCsvWithTypeForMapAndRecordAsExpextedType2() { + BooleanRecord9Array|CsvConversionError bm1br9 = fromCsvWithType([bm1, bm1], {}, BooleanRecord9Array); + test:assertTrue(bm1br9 is CsvConversionError); + test:assertEquals((bm1br9).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord9Array|CsvConversionError bm2br9 = fromCsvWithType([bm2, bm2], {}, BooleanRecord9Array); + test:assertEquals(bm2br9, [ + {b1: true, b2: false, b3: (), n1: (), n3: ()}, + {b1: true, b2: false, b3: (), n1: (), n3: ()} + ]); + + BooleanRecord9Array|CsvConversionError bm3br9 = fromCsvWithType([bm3, bm3], {}, BooleanRecord9Array); + test:assertEquals(bm3br9, [ + {b1: true, b2: false, b3: (), b4: false}, + {b1: true, b2: false, b3: (), b4: false} + ]); + + BooleanRecord9Array|CsvConversionError bm4br9 = fromCsvWithType([bm4, bm4], {}, BooleanRecord9Array); + test:assertTrue(bm4br9 is CsvConversionError); + test:assertEquals((bm4br9).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord9Array|CsvConversionError bm5br9 = fromCsvWithType([bm5, bm5], {}, BooleanRecord9Array); + test:assertEquals(bm5br9, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + BooleanRecord10Array|CsvConversionError bm1br10 = fromCsvWithType([bm1, bm1], {}, BooleanRecord10Array); + test:assertEquals(bm1br10, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanRecord10Array|CsvConversionError bm2br10 = fromCsvWithType([bm2, bm2], {}, BooleanRecord10Array); + test:assertEquals(bm2br10, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanRecord10Array|CsvConversionError bm3br10 = fromCsvWithType([bm3, bm3], {}, BooleanRecord10Array); + test:assertEquals(bm3br10, [ + {b1: true, b2: false, b4: false}, + {b1: true, b2: false, b4: false} + ]); + + BooleanRecord10Array|CsvConversionError bm4br10 = fromCsvWithType([bm4, bm4], {}, BooleanRecord10Array); + test:assertEquals(bm4br10, [ + {}, + {} + ]); + + BooleanRecord10Array|CsvConversionError bm5br10 = fromCsvWithType([bm5, bm5], {}, BooleanRecord10Array); + test:assertEquals(bm5br10, [ + {b1: true, b2: false, b4: true}, + {b1: true, b2: false, b4: true} + ]); + + BooleanRecord11Array|CsvConversionError bm1br11 = fromCsvWithType([bm1, bm1], {}, BooleanRecord11Array); + test:assertEquals(bm1br11, [ + {b1: true, b2: false, defaultableField: "", nillableField :null}, + {b1: true, b2: false, defaultableField: "", nillableField :null} + ]); + + BooleanRecord11Array|CsvConversionError bm2br11 = fromCsvWithType([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|CsvConversionError bm3br11 = fromCsvWithType([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|CsvConversionError bm4br11 = fromCsvWithType([bm4, bm4], {}, BooleanRecord11Array); + test:assertTrue(bm4br11 is CsvConversionError); + test:assertEquals((bm4br11).message(), generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord11Array|CsvConversionError bm5br11 = fromCsvWithType([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|CsvConversionError bm1br12 = fromCsvWithType([bm1, bm1], {}, BooleanRecord12Array); + test:assertTrue(bm1br12 is CsvConversionError); + test:assertEquals((bm1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord12Array|CsvConversionError bm2br12 = fromCsvWithType([bm2, bm2], {}, BooleanRecord12Array); + test:assertTrue(bm2br12 is CsvConversionError); + test:assertEquals((bm2br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord12Array|CsvConversionError bm3br12 = fromCsvWithType([bm3, bm3], {}, BooleanRecord12Array); + test:assertTrue(bm3br12 is CsvConversionError); + test:assertEquals((bm3br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord12Array|CsvConversionError bm4br12 = fromCsvWithType([bm4, bm4], {}, BooleanRecord12Array); + test:assertTrue(bm4br12 is CsvConversionError); + test:assertEquals((bm4br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord12Array|CsvConversionError bm5br12 = fromCsvWithType([bm5, bm5], {}, BooleanRecord12Array); + test:assertTrue(bm5br12 is CsvConversionError); + test:assertEquals((bm5br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord13Array|CsvConversionError bm1br13 = fromCsvWithType([bm1, bm1], {}, BooleanRecord13Array); + test:assertEquals(bm1br13, [ + {b1: true, b2: false, defaultableField: "", nillableField :null}, + {b1: true, b2: false, defaultableField: "", nillableField :null} + ]); + + BooleanRecord13Array|CsvConversionError bm2br13 = fromCsvWithType([bm2, bm2], {}, BooleanRecord13Array); + test:assertEquals(bm2br13, [ + {b1: true, b2: false, defaultableField: "", nillableField :null}, + {b1: true, b2: false, defaultableField: "", nillableField :null} + ]); + + BooleanRecord13Array|CsvConversionError bm3br13 = fromCsvWithType([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|CsvConversionError bm4br13 = fromCsvWithType([bm4, bm4], {}, BooleanRecord13Array); + test:assertEquals(bm4br13, [ + {defaultableField: "", nillableField :null}, + {defaultableField: "", nillableField :null} + ]); + + BooleanRecord13Array|CsvConversionError bm5br13 = fromCsvWithType([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|CsvConversionError bm1br14 = fromCsvWithType([bm1, bm1], {}, BooleanRecord14Array); + test:assertTrue(bm1br14 is CsvConversionError); + test:assertEquals((bm1br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord14Array|CsvConversionError bm2br14 = fromCsvWithType([bm2, bm2], {}, BooleanRecord14Array); + test:assertTrue(bm2br14 is CsvConversionError); + test:assertEquals((bm2br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord14Array|CsvConversionError bm3br14 = fromCsvWithType([bm3, bm3], {}, BooleanRecord14Array); + test:assertTrue(bm3br14 is CsvConversionError); + test:assertEquals((bm3br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord14Array|CsvConversionError bm4br14 = fromCsvWithType([bm4, bm4], {}, BooleanRecord14Array); + test:assertTrue(bm4br14 is CsvConversionError); + test:assertEquals((bm4br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord14Array|CsvConversionError bm5br14 = fromCsvWithType([bm5, bm5], {}, BooleanRecord14Array); + test:assertTrue(bm5br14 is CsvConversionError); + test:assertEquals((bm5br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord15Array|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, BooleanRecord15Array); + test:assertTrue(bm1br15 is CsvConversionError); + test:assertEquals((bm1br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); + + BooleanRecord15Array|CsvConversionError bm3br15 = fromCsvWithType([bm3, bm3], {}, BooleanRecord15Array); + test:assertTrue(bm3br15 is CsvConversionError); + test:assertEquals((bm3br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); + + BooleanRecord15Array|CsvConversionError bm4br15 = fromCsvWithType([bm4, bm4], {}, BooleanRecord15Array); + test:assertTrue(bm4br15 is CsvConversionError); + test:assertEquals((bm4br15).message(), generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord16Array|CsvConversionError bm1br16 = fromCsvWithType([bm1, bm1], {}, BooleanRecord16Array); + test:assertEquals(bm1br16, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanRecord16Array|CsvConversionError bm2br16 = fromCsvWithType([bm2, bm2], {}, BooleanRecord16Array); + test:assertEquals(bm2br16, [ + {b1: true, b2: false, b3: (), n1: (), n3: ()}, + {b1: true, b2: false, b3: (), n1: (), n3: ()} + ]); + + BooleanRecord16Array|CsvConversionError bm3br16 = fromCsvWithType([bm3, bm3], {}, BooleanRecord16Array); + test:assertEquals(bm3br16, [ + {b1: true, b2: false, b4: false, b3: ()}, + {b1: true, b2: false, b4: false, b3: ()} + ]); + + BooleanRecord16Array|CsvConversionError bm4br16 = fromCsvWithType([bm4, bm4], {}, BooleanRecord16Array); + test:assertEquals(bm4br16, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + BooleanRecord16Array|CsvConversionError bm5br16 = fromCsvWithType([bm5, bm5], {}, BooleanRecord16Array); + test:assertEquals(bm5br16, [ + {b1: true, b2: false, b4: true, b3: ()}, + {b1: true, b2: false, b4: true, b3: ()} + ]); + + BooleanRecord17Array|CsvConversionError bm1br17 = fromCsvWithType([bm1, bm1], {}, BooleanRecord17Array); + test:assertEquals(bm1br17, [ + {}, + {} + ]); + + BooleanRecord17Array|CsvConversionError bm2br17 = fromCsvWithType([bm2, bm2], {}, BooleanRecord17Array); + test:assertEquals(bm2br17, [ + {}, + {} + ]); + + BooleanRecord17Array|CsvConversionError bm3br17 = fromCsvWithType([bm3, bm3], {}, BooleanRecord17Array); + test:assertEquals(bm3br17, [ + {i1: 1}, + {i1: 1} + ]); + + BooleanRecord17Array|CsvConversionError bm4br17 = fromCsvWithType([bm4, bm4], {}, BooleanRecord17Array); + test:assertEquals(bm4br17, [ + {}, + {} + ]); + + BooleanRecord17Array|CsvConversionError bm5br17 = fromCsvWithType([bm5, bm5], {}, BooleanRecord17Array); + test:assertEquals(bm5br17, [ + {}, + {} + ]); + + BooleanRecord18Array|CsvConversionError bm1br18 = fromCsvWithType([bm1, bm1], {}, BooleanRecord18Array); + test:assertEquals(bm1br18, [ + {b2: false}, + {b2: false} + ]); + + BooleanRecord18Array|CsvConversionError bm2br18 = fromCsvWithType([bm2, bm2], {}, BooleanRecord18Array); + test:assertEquals(bm2br18, [ + {b2: false, b3: (), n1: (), n3: ()}, + {b2: false, b3: (), n1: (), n3: ()} + ]); + + BooleanRecord18Array|CsvConversionError bm3br18 = fromCsvWithType([bm3, bm3], {}, BooleanRecord18Array); + test:assertEquals(bm3br18, [ + {b2: false, b3: (), i1: 1}, + {b2: false, b3: (), i1: 1} + ]); + + BooleanRecord18Array|CsvConversionError bm4br18 = fromCsvWithType([bm4, bm4], {}, BooleanRecord18Array); + test:assertTrue(bm4br18 is CsvConversionError); + test:assertEquals((bm4br18).message(), generateErrorMessageForMissingRequiredField("b2")); + + BooleanRecord18Array|CsvConversionError bm5br18 = fromCsvWithType([bm5, bm5], {}, BooleanRecord18Array); + test:assertEquals(bm5br18, [ + {b2: false, b3: ()}, + {b2: false, b3: ()} + ]); +} + +@test:Config {enable: !enable} +function test() { + BooleanMapArray|CsvConversionError bm2bma = fromCsvWithType([bm2, bm2], {}, BooleanMapArray); + test:assertEquals(bm2bma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); +} + +@test:Config {enable} +function testFromCsvWithTypeForMapAndMapAsExpextedType() { + BooleanMapArray|CsvConversionError bm1bma = fromCsvWithType([bm1, bm1], {}, BooleanMapArray); + test:assertEquals(bm1bma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanMapArray|CsvConversionError bm2bma = fromCsvWithType([bm2, bm2], {}, BooleanMapArray); + test:assertEquals(bm2bma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanMapArray|CsvConversionError bm3bma = fromCsvWithType([bm3, bm3], {}, BooleanMapArray); + test:assertEquals(bm3bma, [ + {b1: true, b2: false, b4: false}, + {b1: true, b2: false, b4: false} + ]); + + BooleanMapArray|CsvConversionError bm4bma = fromCsvWithType([bm4, bm4], {}, BooleanMapArray); + test:assertEquals(bm4bma, [ + {}, + {} + ]); + + BooleanMapArray|CsvConversionError bm5bma = fromCsvWithType([bm5, bm5], {}, BooleanMapArray); + test:assertEquals(bm5bma, [ + {b1: true, b2: false, b4: true}, + {b1: true, b2: false, b4: true} + ]); + + // NillableBooleanMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, NillableBooleanMapArray); + // test:assertEquals(bm1br15, [ + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} + // ]); + + // NillableIntUnionBooleanMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, NillableIntUnionBooleanMapArray); + // test:assertEquals(bm1br15, [ + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} + // ]); + + // IntUnionBooleanMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, IntUnionBooleanMapArray); + // test:assertEquals(bm1br15, [ + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} + // ]); + + // NilMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, NilMapArray); + // test:assertEquals(bm1br15, [ + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} + // ]); + + // JsonMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, JsonMapArray); + // test:assertEquals(bm1br15, [ + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} + // ]); + + // AnydataMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, AnydataMapArray); + // test:assertEquals(bm1br15, [ + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} + // ]); + + // CustomMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, CustomMapArray); + // test:assertEquals(bm1br15, [ + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, + // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} + // ]); +} + +function generateErrorMessageForMissingRequiredField(string 'field) returns string { + return string `no matching header value is found for the required field '${'field}'`; +} + +function generateErrorMessageForInvalidCast(string value, string 'type) returns string { + return string `value '${value}' cannot be cast into '${'type}'`; +} + +function generateErrorMessageForInvalidFieldType(string value, string 'key) returns string { + return string `no mapping type found for value '${value}' in key '${'key}'`; +} + +// @test:Config +// function testFromCsvWithTypeForRecordAndArrayAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForRecordAndTupleAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForArrayAndMapAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForArrayAndRecordAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForArrayAndArrayAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForArrayAndTupleAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndMapAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndRecordAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndArrayAsExpextedType() { + +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndTupleAsExpextedType() { + +// } diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index 087fbce..f238e08 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -1,348 +1,350 @@ -import ballerina/test; -import ballerina/io; +// import ballerina/test; +// import ballerina/io; -type A map[]; -type A2 map[]; +// type A map[]; +// type A2 map[]; -type B record{|int a; int b;|}[]; -type B2 record{|string a; string b;|}[]; -type B3 record{}[]; -type B4 record{string '1; string '2; string '3;}[]; -type B5 record{string '1;}[]; -type B6 record{string name;}[]; +// type B record{|int a; int b;|}[]; +// type B2 record{|string a; string b;|}[]; +// type B3 record{}[]; +// type B4 record{string '1; string '2; string '3;}[]; +// type B5 record{string '1;}[]; +// type B6 record{string name;}[]; -type C string[][]; -type C2 string[][]; +// type C string[][]; +// type C2 string[][]; -type D [int, int][]; -type D2 [string, string][]; +// type D [int, int][]; +// type D2 [string, string][]; -map[] a = [{"a": "1", "b": "2"}, {"a": "1", "b": "2"}]; -map[] a2 = [{"a": 1, "b": 2}, {"a": 1, "b": 2}]; +// map[] a = [{"a": "1", "b": "2"}, {"a": "1", "b": "2"}]; +// map[] a2 = [{"a": 1, "b": 2}, {"a": 1, "b": 2}]; -record {|int a; int b; int c;|}[] b = [{a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}]; -record {|string a; string b;|}[] b2 = [{a: "1", b: "2"}, {a: "1", b: "2"}]; +// record {|int a; int b; int c;|}[] b = [{a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}]; +// record {|string a; string b;|}[] b2 = [{a: "1", b: "2"}, {a: "1", b: "2"}]; -string[][] c = [["1", "2", "3"], ["1", "2", "3"]]; -string[][] c2 = [["1", "2", "3"], ["1", "2", "3"]]; -int[][] c3 = [[1, 2], [1, 2]]; -int[][] c4 = [[1, 2, 3], [1, 2, 3]]; +// string[][] c = [["1", "2", "3"], ["1", "2", "3"]]; +// string[][] c2 = [["1", "2", "3"], ["1", "2", "3"]]; +// int[][] c3 = [[1, 2], [1, 2]]; +// int[][] c4 = [[1, 2, 3], [1, 2, 3]]; -[string, string][] d = [["1", "2"], ["1", "2"]]; -[string, string][] d2 = [["1", "2"], ["1", "2"]]; +// [string, string][] d = [["1", "2"], ["1", "2"]]; +// [string, string][] d2 = [["1", "2"], ["1", "2"]]; -boolean enable = true; +// boolean enable = true; -@test:Config{enable } -public function testA() returns error? { - A aa = check fromCsvWithType(a, {}, A); - test:assertEquals(aa, a); +// @test:Config{enable } +// public function testA() returns error? { +// A aa = check fromCsvWithType(a, {}, A); +// test:assertEquals(aa, a); - A2 aa2 = check fromCsvWithType(a2, {}, A2); - test:assertEquals(aa2, a2); +// A2 aa2 = check fromCsvWithType(a2, {}, A2); +// test:assertEquals(aa2, a2); - B bb = check fromCsvWithType(b, {}, B); - test:assertEquals(bb, [{a: 1, b: 2}, {a: 1, b: 2}]); +// B bb = check fromCsvWithType(b, {}, B); +// test:assertEquals(bb, [{a: 1, b: 2}, {a: 1, b: 2}]); - B2 bb2 = check fromCsvWithType(b2, {}, B2); - test:assertEquals(bb2, b2); +// B2 bb2 = check fromCsvWithType(b2, {}, B2); +// test:assertEquals(bb2, b2); - C cc = check fromCsvWithType(c, {}, C); - test:assertEquals(cc, c); +// C cc = check fromCsvWithType(c, {}, C); +// test:assertEquals(cc, c); - C2 cc2 = check fromCsvWithType(c2, {}, C2); - test:assertEquals(cc2, c2); +// C2 cc2 = check fromCsvWithType(c2, {}, C2); +// test:assertEquals(cc2, c2); - B2 ab2 = check fromCsvWithType(a, {}, B2); - test:assertEquals(ab2, a); +// B2 ab2 = check fromCsvWithType(a, {}, B2); +// test:assertEquals(ab2, a); - C ac = check fromCsvWithType(a, {}, C); - test:assertEquals(ac, [["1", "2"], ["1", "2"]]); +// C ac = check fromCsvWithType(a, {}, C); +// test:assertEquals(ac, [["1", "2"], ["1", "2"]]); - A ba = check fromCsvWithType(b, {}, A); - test:assertEquals(ba, [{a: "1", b: "2", c: "3"}, {a: "1", b: "2", c: "3"}]); +// A ba = check fromCsvWithType(b, {}, A); +// test:assertEquals(ba, [{a: "1", b: "2", c: "3"}, {a: "1", b: "2", c: "3"}]); - A2 ba2 = check fromCsvWithType(b, {}, A2); - test:assertEquals(ba2, [{a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}]); +// A2 ba2 = check fromCsvWithType(b, {}, A2); +// test:assertEquals(ba2, [{a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}]); - C bc = check fromCsvWithType(b, {}, C); - test:assertEquals(bc, [["1", "2", "3"], ["1", "2", "3"]]); +// C bc = check fromCsvWithType(b, {}, C); +// test:assertEquals(bc, [["1", "2", "3"], ["1", "2", "3"]]); - C2 bc2 = check fromCsvWithType(b2, {}, C2); - test:assertEquals(bc2, [["1", "2"], ["1", "2"]]); +// C2 bc2 = check fromCsvWithType(b2, {}, C2); +// test:assertEquals(bc2, [["1", "2"], ["1", "2"]]); - A ca = check fromCsvWithType(c, {}, A); - test:assertEquals(ca, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); +// A ca = check fromCsvWithType(c, {}, A); +// test:assertEquals(ca, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - // B2 cb2 = check fromCsvWithType(c, {}, B2); - // test:assertEquals(cb2, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); +// // B2 cb2 = check fromCsvWithType(c, {}, B2); +// // test:assertEquals(cb2, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - B3 cb3 = check fromCsvWithType(c, {}, B3); - test:assertEquals(cb3, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); +// B3 cb3 = check fromCsvWithType(c, {}, B3); +// test:assertEquals(cb3, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - B4 cb4 = check fromCsvWithType(c, {}, B4); - test:assertEquals(cb4, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); +// B4 cb4 = check fromCsvWithType(c, {}, B4); +// test:assertEquals(cb4, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - B5 cb5 = check fromCsvWithType(c, {}, B5); - test:assertEquals(cb5, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); +// B5 cb5 = check fromCsvWithType(c, {}, B5); +// test:assertEquals(cb5, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - // B6 cb6 = check fromCsvWithType(c, {}, B6); - // test:assertEquals(cb6, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); +// // B6 cb6 = check fromCsvWithType(c, {}, B6); +// // test:assertEquals(cb6, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - D2 ad2 = check fromCsvWithType(a, {}, D2); - test:assertEquals(ad2, [["1", "2"], ["1", "2"]]); +// D2 ad2 = check fromCsvWithType(a, {}, D2); +// test:assertEquals(ad2, [["1", "2"], ["1", "2"]]); - D a2d = check fromCsvWithType(a2, {}, D); - test:assertEquals(a2d, [[1, 2], [1, 2]]); +// D a2d = check fromCsvWithType(a2, {}, D); +// test:assertEquals(a2d, [[1, 2], [1, 2]]); - D2 a2d2 = check fromCsvWithType(a2, {}, D2); - test:assertEquals(a2d2, [["1", "2"], ["1", "2"]]); +// D2 a2d2 = check fromCsvWithType(a2, {}, D2); +// test:assertEquals(a2d2, [["1", "2"], ["1", "2"]]); - // D dd = check fromCsvWithType(d, {}, D); - // test:assertEquals(dd, d); +// // D dd = check fromCsvWithType(d, {}, D); +// // test:assertEquals(dd, d); - D2 dd2 = check fromCsvWithType(d2, {}, D2); - test:assertEquals(dd2, d2); +// D2 dd2 = check fromCsvWithType(d2, {}, D2); +// test:assertEquals(dd2, d2); - D bd = check fromCsvWithType(b, {}, D); - test:assertEquals(bd, [[1, 2], [1, 2]]); +// D bd = check fromCsvWithType(b, {}, D); +// test:assertEquals(bd, [[1, 2], [1, 2]]); - D2 bd2 = check fromCsvWithType(b2, {}, D2); - test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); +// D2 bd2 = check fromCsvWithType(b2, {}, D2); +// test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); - D2 cd2 = check fromCsvWithType(c, {}, D2); - test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); +// D2 cd2 = check fromCsvWithType(c, {}, D2); +// test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); - A d2a = check fromCsvWithType(d2, {}, A); - test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); +// A d2a = check fromCsvWithType(d2, {}, A); +// test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - // B2 d2b2 = check fromCsvWithType(d2, {}, B2); - // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); +// // B2 d2b2 = check fromCsvWithType(d2, {}, B2); +// // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - C d2c = check fromCsvWithType(d2, {}, C); - test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); -} +// C d2c = check fromCsvWithType(d2, {}, C); +// test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); +// } -@test:Config{enable } -function testB() returns error? { - // B2 d2b2 = check fromCsvWithType(d2, {}, B2); - // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); +// @test:Config{enable } +// function testB() returns error? { +// // B2 d2b2 = check fromCsvWithType(d2, {}, B2); +// // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - // D2 ad2 = check fromCsvWithType(a, {}, D2); - // test:assertEquals(ad2, [["1", "2"], ["1", "2"]]); +// // D2 ad2 = check fromCsvWithType(a, {}, D2); +// // test:assertEquals(ad2, [["1", "2"], ["1", "2"]]); - // D2 bd2 = check fromCsvWithType(b2, {}, D2); - // test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); +// // D2 bd2 = check fromCsvWithType(b2, {}, D2); +// // test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); - // D2 cd2 = check fromCsvWithType(c, {}, D2); - // test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); +// // D2 cd2 = check fromCsvWithType(c, {}, D2); +// // test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); - // A d2a = check fromCsvWithType(d2, {}, A); - // test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); +// // A d2a = check fromCsvWithType(d2, {}, A); +// // test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - // B2 d2b2 = check fromCsvWithType(d2, {}, B2); - // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); +// // B2 d2b2 = check fromCsvWithType(d2, {}, B2); +// // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - // C d2c = check fromCsvWithType(d2, {}, C); - // test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); -} +// // C d2c = check fromCsvWithType(d2, {}, C); +// // test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); +// } - // D a2d = check fromCsvWithType(a2, {}, D); - // test:assertEquals(a2d, [[1, 2], [1, 2]]); +// // D a2d = check fromCsvWithType(a2, {}, D); +// // test:assertEquals(a2d, [[1, 2], [1, 2]]); - // D2 a2d2 = check fromCsvWithType(a2, {}, D2); - // test:assertEquals(a2d2, [["1", "2"], ["1", "2"]]); +// // D2 a2d2 = check fromCsvWithType(a2, {}, D2); +// // test:assertEquals(a2d2, [["1", "2"], ["1", "2"]]); - // D dd = check fromCsvWithType(d, {}, D); - // test:assertEquals(dd, d); +// // D dd = check fromCsvWithType(d, {}, D); +// // test:assertEquals(dd, d); - // D2 dd2 = check fromCsvWithType(d2, {}, D2); - // test:assertEquals(dd2, d2); +// // D2 dd2 = check fromCsvWithType(d2, {}, D2); +// // test:assertEquals(dd2, d2); - // D bd = check fromCsvWithType(b, {}, D); - // test:assertEquals(bd, [[1, 2], [1, 2]]); +// // D bd = check fromCsvWithType(b, {}, D); +// // test:assertEquals(bd, [[1, 2], [1, 2]]); - // D2 bd2 = check fromCsvWithType(b2, {}, D2); - // test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); +// // D2 bd2 = check fromCsvWithType(b2, {}, D2); +// // test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); - // D2 cd2 = check fromCsvWithType(c, {}, D2); - // test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); +// // D2 cd2 = check fromCsvWithType(c, {}, D2); +// // test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); - // A d2a = check fromCsvWithType(d2, {}, A); - // test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); +// // A d2a = check fromCsvWithType(d2, {}, A); +// // test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - // B2 d2b2 = check fromCsvWithType(d2, {}, B2); - // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); +// // B2 d2b2 = check fromCsvWithType(d2, {}, B2); +// // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - // C d2c = check fromCsvWithType(d2, {}, C); - // test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); +// // C d2c = check fromCsvWithType(d2, {}, C); +// // test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); -type AA record{}[]; -type BB record {int a; int b; int c;}[]; -// type BBB record {string a; string b; string c;}[]; -type CC map[]; -type DD map[]; -type EE map[]; -type FF int[][]; -type GG string[][]; -type HH anydata[][]; -type II [int, int, int][]; -type JJ [string, string, string][]; -type KK [string, int, string][]; -type LL record {string a; int b; string c;}[]; -type MM record {|string a; int b; string c;|}[]; -type NN record {|int b; string c;|}[]; -type OO record {string a; string c;}[]; -type PP int[2][]; -type QQ string[2][]; -type RR anydata[2][]; -type SS [int, int][]; -type TT [string, string][]; -type UU [anydata, anydata][]; -type VV [int, string][]; -type WW int[][2]; -type XX string[][2]; -type YY anydata[][2]; +// type AA record{}[]; +// type BB record {int a; int b; int c;}[]; +// // type BBB record {string a; string b; string c;}[]; +// type CC map[]; +// type DD map[]; +// type EE map[]; +// type FF int[][]; +// type GG string[][]; +// type HH anydata[][]; +// type II [int, int, int][]; +// type JJ [string, string, string][]; +// type KK [string, int, string][]; +// type LL record {string a; int b; string c;}[]; +// type MM record {|string a; int b; string c;|}[]; +// type NN record {|int b; string c;|}[]; +// type OO record {string a; string c;}[]; +// type PP int[2][]; +// type QQ string[2][]; +// type RR anydata[2][]; +// type SS [int, int][]; +// type TT [string, string][]; +// type UU [anydata, anydata][]; +// type VV [int, string][]; +// type WW int[][2]; +// type XX string[][2]; +// type YY anydata[][2]; -@test:Config{ enable } -function test() returns CsvConversionError? { - string a = check io:fileReadString("a.txt"); - - AA aa = check fromCsvStringWithType(a, {}, AA); - test:assertEquals(aa, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); - io:println(aa); - - BB bb = check fromCsvStringWithType(a, {}, BB); - test:assertEquals(bb, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); - io:println(bb); - - CC cc = check fromCsvStringWithType(a, {}, CC); - test:assertEquals(cc, [{a: "1", b: "2", c: "3"}, {a: "4", b: "5", c: "6"}]); - io:println(cc); - - DD dd = check fromCsvStringWithType(a, {}, DD); - test:assertEquals(dd, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); - io:println(dd); - - EE ee = check fromCsvStringWithType(a, {}, EE); - test:assertEquals(ee, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); - io:println(ee); +// @test:Config{ enable } +// function test() returns CsvConversionError? { +// string a = check io:fileReadString("a.txt"); + +// AA aa = check fromCsvStringWithType(a, {}, AA); +// test:assertEquals(aa, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); +// io:println(aa); + +// BB bb = check fromCsvStringWithType(a, {}, BB); +// test:assertEquals(bb, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); +// io:println(bb); + +// CC cc = check fromCsvStringWithType(a, {}, CC); +// test:assertEquals(cc, [{a: "1", b: "2", c: "3"}, {a: "4", b: "5", c: "6"}]); +// io:println(cc); + +// DD dd = check fromCsvStringWithType(a, {}, DD); +// test:assertEquals(dd, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); +// io:println(dd); + +// EE ee = check fromCsvStringWithType(a, {}, EE); +// test:assertEquals(ee, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); +// io:println(ee); + +// FF ff = check fromCsvStringWithType(a, {}, FF); +// test:assertEquals(ff, [[1, 2, 3], [4, 5, 6]]); +// io:println(ff); + +// GG gg = check fromCsvStringWithType(a, {}, GG); +// test:assertEquals(gg, [["1", "2", "3"], ["4", "5", "6"]]); +// io:println(gg); + +// HH hh = check fromCsvStringWithType(a, {}, HH); +// test:assertEquals(hh, [[1, 2, 3], [4, 5, 6]]); +// io:println(hh); + +// II ii = check fromCsvStringWithType(a, {}, II); +// test:assertEquals(ii, [[1, 2, 3], [4, 5, 6]]); +// io:println(ii); + +// JJ jj = check fromCsvStringWithType(a, {}, JJ); +// test:assertEquals(jj, [["1", "2", "3"], ["4", "5", "6"]]); +// io:println(jj); + +// KK kk = check fromCsvStringWithType(a, {}, KK); +// test:assertEquals(kk, [["1", 2, "3"], ["4", 5, "6"]]); +// io:println(kk); + +// LL ll = check fromCsvStringWithType(a, {}, LL); +// test:assertEquals(ll, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); +// io:println(ll); + +// MM mm = check fromCsvStringWithType(a, {}, MM); +// test:assertEquals(mm, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); +// io:println(mm); + +// NN nn = check fromCsvStringWithType(a, {}, NN); +// test:assertEquals(nn, [{b: 2, c: "3"}, {b: 5, c: "6"}]); +// io:println(nn); + +// OO oo = check fromCsvStringWithType(a, {}, OO); +// test:assertEquals(oo, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); +// io:println(oo); - FF ff = check fromCsvStringWithType(a, {}, FF); - test:assertEquals(ff, [[1, 2, 3], [4, 5, 6]]); - io:println(ff); - - GG gg = check fromCsvStringWithType(a, {}, GG); - test:assertEquals(gg, [["1", "2", "3"], ["4", "5", "6"]]); - io:println(gg); - - HH hh = check fromCsvStringWithType(a, {}, HH); - test:assertEquals(hh, [[1, 2, 3], [4, 5, 6]]); - io:println(hh); - - II ii = check fromCsvStringWithType(a, {}, II); - test:assertEquals(ii, [[1, 2, 3], [4, 5, 6]]); - io:println(ii); - - JJ jj = check fromCsvStringWithType(a, {}, JJ); - test:assertEquals(jj, [["1", "2", "3"], ["4", "5", "6"]]); - io:println(jj); - - KK kk = check fromCsvStringWithType(a, {}, KK); - test:assertEquals(kk, [["1", 2, "3"], ["4", 5, "6"]]); - io:println(kk); - - LL ll = check fromCsvStringWithType(a, {}, LL); - test:assertEquals(ll, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); - io:println(ll); - - MM mm = check fromCsvStringWithType(a, {}, MM); - test:assertEquals(mm, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); - io:println(mm); - - NN nn = check fromCsvStringWithType(a, {}, NN); - test:assertEquals(nn, [{b: 2, c: "3"}, {b: 5, c: "6"}]); - io:println(nn); - - OO oo = check fromCsvStringWithType(a, {}, OO); - test:assertEquals(oo, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); - io:println(oo); - - PP pp = check fromCsvStringWithType(a, {}, PP); - test:assertEquals(pp, [[1,2,3], [4,5,6]]); - io:println(pp); - - QQ qq = check fromCsvStringWithType(a, {}, QQ); - test:assertEquals(qq, [["1","2","3"],["4","5","6"]]); - io:println(qq); - - RR rr = check fromCsvStringWithType(a, {}, RR); - test:assertEquals(rr, [[1,2,3],[4,5,6]]); - io:println(rr); - - SS ss = check fromCsvStringWithType(a, {}, SS); - test:assertEquals(ss, [[1, 2],[4, 5]]); - io:println(ss); - - TT tt = check fromCsvStringWithType(a, {}, TT); - test:assertEquals(tt, [["1", "2"],["4", "5"]]); - io:println(tt); - - UU uu = check fromCsvStringWithType(a, {}, UU); - test:assertEquals(uu, [[1, 2],[4, 5]]); - io:println(uu); - - VV vv = check fromCsvStringWithType(a, {}, VV); - test:assertEquals(vv, [[1,"2"],[4,"5"]]); - io:println(vv); +// PP pp = check fromCsvStringWithType(a, {}, PP); +// test:assertEquals(pp, [[1,2,3], [4,5,6]]); +// io:println(pp); - WW ww = check fromCsvStringWithType(a, {}, WW); - test:assertEquals(ww, [[1,2],[4,5]]); - io:println(ww); +// QQ qq = check fromCsvStringWithType(a, {}, QQ); +// test:assertEquals(qq, [["1","2","3"],["4","5","6"]]); +// io:println(qq); - XX xx = check fromCsvStringWithType(a, {}, XX); - test:assertEquals(xx, [["1","2"],["4","5"]]); - io:println(xx); +// RR rr = check fromCsvStringWithType(a, {}, RR); +// test:assertEquals(rr, [[1,2,3],[4,5,6]]); +// io:println(rr); - YY yy = check fromCsvStringWithType(a, {}, YY); - test:assertEquals(yy, [[1,2],[4,5]]); - io:println(yy); -} +// SS ss = check fromCsvStringWithType(a, {}, SS); +// test:assertEquals(ss, [[1, 2],[4, 5]]); +// io:println(ss); -// =========================================================================================== +// TT tt = check fromCsvStringWithType(a, {}, TT); +// test:assertEquals(tt, [["1", "2"],["4", "5"]]); +// io:println(tt); -// errors expected +// UU uu = check fromCsvStringWithType(a, {}, UU); +// test:assertEquals(uu, [[1, 2],[4, 5]]); +// io:println(uu); -// EE ee2 = check fromCsvStringWithType(a, {}, EE); -// test:assertEquals(ee2, [{a: "1", b: "2", c: "3"}, {a: "4", b: "5", c: "6"}]); -// io:println(ee2); -// BBB bbb = check fromCsvStringWithType(a, {}, BBB); -// test:assertEquals(bbb, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); -// io:println(bbb); +// VV vv = check fromCsvStringWithType(a, {}, VV); +// test:assertEquals(vv, [[1,"2"],[4,"5"]]); +// io:println(vv); -// =========================================================================================== +// WW ww = check fromCsvStringWithType(a, {}, WW); +// test:assertEquals(ww, [[1,2],[4,5]]); +// io:println(ww); -// NEED TO check +// XX xx = check fromCsvStringWithType(a, {}, XX); +// test:assertEquals(xx, [["1","2"],["4","5"]]); +// io:println(xx); -// OO oo = check fromCsvStringWithType(a, {}, MM); -// test:assertEquals(oo, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); -// io:println(oo); +// YY yy = check fromCsvStringWithType(a, {}, YY); +// test:assertEquals(yy, [[1,2],[4,5]]); +// io:println(yy); +// } + +// // =========================================================================================== + +// // errors expected + +// // EE ee2 = check fromCsvStringWithType(a, {}, EE); +// // test:assertEquals(ee2, [{a: "1", b: "2", c: "3"}, {a: "4", b: "5", c: "6"}]); +// // io:println(ee2); +// // BBB bbb = check fromCsvStringWithType(a, {}, BBB); +// // test:assertEquals(bbb, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); +// // io:println(bbb); + +// // =========================================================================================== + +// // NEED TO check + +// // OO oo = check fromCsvStringWithType(a, {}, MM); +// // test:assertEquals(oo, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); +// // io:println(oo); -type AAA string[][]; +// type AAA string[][]; -@test:Config{ enable } -function testC() returns error? { - anydata[][] a = [[1, 2], [2, 3], [2, 3]]; - record{}[] b = [{"a": 1, "b": 2}, {"a": 1, "b": 2}, {"a": 1, "b": 2}]; - map[] c = [{"a": 1, "b": 2}, {"a": 1, "b": 2}, {"a": 1, "b": 2}]; +// @test:Config{ enable } +// function testC() returns error? { +// anydata[][] a = [[1, 2], [2, 3], [2, 3]]; +// record{}[] b = [{"a": 1, "b": 2}, {"a": 1, "b": 2}, {"a": 1, "b": 2}]; +// map[] c = [{"a": 1, "b": 2}, {"a": 1, "b": 2}, {"a": 1, "b": 2}]; - io:println(toCsvString(a)); - io:println(toCsvString(b)); - io:println(toCsvString(c)); -} +// io:println(toCsvString(a)); +// io:println(toCsvString(b)); +// io:println(toCsvString(c)); +// } -@test:Config{enable: !enable} -function t() returns error? { - A aa = check fromCsvWithType(a, {}, A); - test:assertEquals(aa, a); -} \ No newline at end of file +// @test:Config{enable: !enable} +// function t() returns error? { +// string a = check io:fileReadString("a.txt"); +// AA aa = check fromCsvStringWithType(a, {}, AA); +// test:assertEquals(aa, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); +// io:println(aa); +// } \ No newline at end of file diff --git a/ballerina/tests/types.bal b/ballerina/tests/types.bal new file mode 100644 index 0000000..cbc19be --- /dev/null +++ b/ballerina/tests/types.bal @@ -0,0 +1,1531 @@ +type BooleanRecord1 record { + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +}; + +type BooleanRecord2 record {| + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +|}; + +type BooleanRecord3 record {| + boolean b1; + boolean? b3; +|}; + +type BooleanRecord4 record { + boolean b1; + boolean? b3; +}; + +type BooleanRecord5 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +}; + +type BooleanRecord6 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +|}; + +type BooleanRecord7 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type BooleanRecord8 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type BooleanRecord9 record {| + boolean b1; + boolean? b3; + boolean?...; +|}; + +type BooleanRecord10 record {| + boolean...; +|}; + +type BooleanRecord11 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + boolean?|string...; +|}; + +type BooleanRecord12 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string|boolean...; +|}; + +type BooleanRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord15 record {| + int b1; + string defaultableField = ""; + string? nillableField = (); + boolean?...; +|}; + +type BooleanRecord16 record {| + boolean?...; +|}; + +type BooleanRecord17 record {| + int...; +|}; + +type BooleanRecord18 record {| + boolean b2; + int?...; +|}; + +type NilRecord1 record { + () n1; + () n2; + () n3; +}; + +type NilRecord2 record {| + () n1; + () n2; + () n3; +|}; + +type NilRecord3 record {| + () n1; + () n4; +|}; + +type NilRecord4 record { + () n1; + () n4; +}; + +type NilRecord5 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +}; + +type NilRecord6 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type NilRecord7 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type NilRecord8 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type NilRecord9 record {| + () n1; + () n2; + ()...; +|}; + +type NilRecord10 record {| + ()...; +|}; + +type NilRecord11 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord12 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type NilRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type IntegerRecord1 record { + int i1; + int i2; + int i3; + int? i4; + int? i5; + int i6; + int i7; + int? i8; +}; + +type IntegerRecord2 record {| + int i1; + int? i2; + int i3; + int i4; + int? i5; + int i6; + int i7; + int? i8; +|}; + +type IntegerRecord3 record {| + int i1; + int i4; + int i6; +|}; + +type IntegerRecord4 record { + int i1; + int i4; + int i6; +}; + +type IntegerRecord5 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +}; + +type IntegerRecord6 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +|}; + +type IntegerRecord7 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type IntegerRecord8 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type IntegerRecord9 record {| + int i1; + int i2; + int...; +|}; + +type IntegerRecord10 record {| + int...; +|}; + +type IntegerRecord11 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord12 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type IntegerRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type FloatRecord1 record { + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +}; + +type FloatRecord2 record {| + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +|}; + +type FloatRecord3 record {| + float f1; + float f4; + float f7; +|}; + +type FloatRecord4 record { + float f1; + float f4; + float f7; +}; + +type FloatRecord5 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +}; + +type FloatRecord6 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type FloatRecord7 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type FloatRecord8 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type FloatRecord9 record {| + float f1; + float f2; + float...; +|}; + +type FloatRecord10 record {| + float...; +|}; + +type FloatRecord11 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord12 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type FloatRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type DecimalRecord1 record { + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +}; + +type DecimalRecord2 record {| + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +|}; + +type DecimalRecord3 record {| + decimal d1; + decimal d4; + decimal d7; +|}; + +type DecimalRecord4 record { + decimal d1; + decimal d4; + decimal d7; +}; + +type DecimalRecord5 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +}; + +type DecimalRecord6 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type DecimalRecord7 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type DecimalRecord8 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type DecimalRecord9 record {| + decimal d1; + decimal d2; + decimal...; +|}; + +type DecimalRecord10 record {| + decimal...; +|}; + +type DecimalRecord11 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord12 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type DecimalRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type StringRecord1 record { + string s1; + string s2; + string s3; +}; + +type StringRecord2 record {| + string s1; + string s2; + string s3; +|}; + +type StringRecord3 record {| + string s1; + string s4; +|}; + +type StringRecord4 record { + string s1; + string s4; +}; + +type StringRecord5 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +}; + +type StringRecord6 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type StringRecord7 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type StringRecord8 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type StringRecord9 record {| + string s1; + string s2; + string...; +|}; + +type StringRecord10 record {| + string...; +|}; + +type StringRecord11 record {| + string s1; + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord12 record {| + string d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type JsonRecord1 record { + json j1; + json j2; + json j3; +}; + +type JsonRecord2 record {| + json j1; + json j2; + json j3; +|}; + +type JsonRecord3 record {| + json j1; + json j4; +|}; + +type JsonRecord4 record { + json j1; + json j4; +}; + +type JsonRecord5 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +}; + +type JsonRecord6 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +|}; + +type JsonRecord7 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +}; + +type JsonRecord8 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +|}; + +type JsonRecord9 record {| + json j1; + json j2; + json...; +|}; + +type JsonRecord10 record {| + json...; +|}; + +type JsonRecord11 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord12 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type JsonRecord13 record {| + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord14 record {| + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type AnydataRecord1 record { + anydata anydata1; + anydata anydata2; + anydata anydata3; +}; + +type AnydataRecord2 record {| + anydata anydata1; + anydata anydata2; + anydata anydata3; +|}; + +type AnydataRecord3 record {| + anydata anydata1; + anydata anydata4; +|}; + +type AnydataRecord4 record { + anydata anydata1; + anydata anydata4; +}; + +type AnydataRecord5 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +}; + +type AnydataRecord6 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type AnydataRecord7 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type AnydataRecord8 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type AnydataRecord9 record {| + anydata anydata1; + anydata anydata2; + anydata...; +|}; + +type AnydataRecord10 record {| + anydata...; +|}; + +type AnydataRecord11 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord12 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type AnydataRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type CustomeRecord1 record { + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +}; + +type CustomeRecord2 record {| + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +|}; + +type CustomeRecord3 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +|}; + +type CustomeRecord4 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +}; + +type CustomeRecord5 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string defaultableField = ""; + string? nillableField = (); +}; + +type CustomeRecord6 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type CustomeRecord7 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type CustomeRecord8 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type CustomeRecord9 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string...; +|}; + +type CustomeRecord10 record {| + string...; +|}; + +type CustomeRecord11 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomeRecord12 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomeRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomeRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type BooleanTuple1 [boolean, boolean, boolean, boolean]; +type BooleanTuple2 [boolean, boolean]; +type BooleanTuple3 [boolean, boolean...]; +type BooleanTuple4 [boolean...]; + +type NilTuple1 [(), (), ()]; +type NilTuple2 [(), ()]; +type NilTuple3 [(), ()...]; +type NilTuple4 [()...]; + +type IntegerTuple1 [int, int, int, int, int, int]; +type IntegerTuple2 [int, int]; +type IntegerTuple3 [int, int...]; +type IntegerTuple4 [int...]; + +type FloatTuple1 [float, float, float, float, float, float, float]; +type FloatTuple2 [float, float]; +type FloatTuple3 [float, float...]; +type FloatTuple4 [float...]; + +type DecimalTuple1 [decimal, decimal, decimal, decimal]; +type DecimalTuple2 [decimal, decimal]; +type DecimalTuple3 [decimal, decimal...]; +type DecimalTuple4 [decimal...]; + +type StringTuple1 [string, string, string]; +type StringTuple2 [string, string]; +type StringTuple3 [string, string...]; +type StringTuple4 [string...]; + +type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata]; +type AnydataTuple2 [anydata, anydata]; +type AnydataTuple3 [anydata, anydata...]; +type AnydataTuple4 [anydata...]; + +type JsonTuple1 [json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json]; +type JsonTuple2 [json, json]; +type JsonTuple3 [json, json...]; +type JsonTuple4 [json...]; + +type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; +type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; +type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; +type CustomTuple4 [string...]; +type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; +type CustomTuple6 [anydata...]; + +type IntegerArray1 int[]; +type IntegerArray2 int[2]; +type IntegerArray3 int[]; +type IntegerArray4 int[2]; +type IntegerArray5 int[3]; +type IntegerArray6 int[4]; + +type StringArray1 string[]; +type StringArray2 string[2]; +type StringArray3 string[]; +type StringArray4 string[2]; +type StringArray5 string[3]; +type StringArray6 string[4]; + +type FloatArray1 float[]; +type FloatArray2 float[2]; +type FloatArray3 float[]; +type FloatArray4 float[2]; +type FloatArray5 float[3]; +type FloatArray6 float[4]; + +type DecimalArray1 decimal[]; +type DecimalArray2 decimal[2]; +type DecimalArray3 decimal[]; +type DecimalArray4 decimal[2]; +type DecimalArray5 decimal[3]; +type DecimalArray6 decimal[4]; + +type BooleanArray1 boolean[]; +type BooleanArray2 boolean[2]; +type BooleanArray3 boolean[]; +type BooleanArray4 boolean[2]; +type BooleanArray5 boolean[3]; +type BooleanArray6 boolean[4]; + +type NilArray1 ()[]; +type NilArray2 ()[2]; +type NilArray3 ()[]; +type NilArray4 ()[2]; +type NilArray5 ()[3]; +type NilArray6 ()[4]; + +type JsonArray1 json[]; +type JsonArray2 json[2]; +type JsonArray3 json[]; +type JsonArray4 json[2]; +type JsonArray5 json[3]; +type JsonArray6 json[4]; + +type AnydataArray1 anydata[]; +type AnydataArray2 anydata[2]; +type AnydataArray3 anydata[]; +type AnydataArray4 anydata[2]; +type AnydataArray5 anydata[3]; +type AnydataArray6 anydata[4]; + +type CustomArray1 CustomTuple2[]; +type CustomArray2 CustomTuple2[2]; +type CustomArray3 CustomTuple2[]; +type CustomArray4 CustomTuple2[2]; +type CustomArray5 CustomTuple2[3]; +type CustomArray6 CustomTuple2[4]; + +type IntegerMap map; +type StringMap map; +type DecimalMap map; +type FloatMap map; +type BooleanMap map; +type NillableBooleanMap map; +type NillableIntUnionBooleanMap map; +type IntUnionBooleanMap map; +type NilMap map<()>; +type JsonMap map; +type AnydataMap map; +type CustomMap map; + +type BooleanRecord1Array BooleanRecord1[]; +type ClosedBooleanRecord1Array BooleanRecord1[3]; +type BooleanRecord2Array BooleanRecord2[]; +type ClosedBooleanRecord2Array BooleanRecord2[3]; +type BooleanRecord3Array BooleanRecord3[]; +type ClosedBooleanRecord3Array BooleanRecord3[3]; +type BooleanRecord4Array BooleanRecord4[]; +type ClosedBooleanRecord4Array BooleanRecord4[3]; +type BooleanRecord5Array BooleanRecord5[]; +type ClosedBooleanRecord5Array BooleanRecord5[3]; +type BooleanRecord6Array BooleanRecord6[]; +type ClosedBooleanRecord6Array BooleanRecord6[3]; +type BooleanRecord7Array BooleanRecord7[]; +type ClosedBooleanRecord7Array BooleanRecord7[3]; +type BooleanRecord8Array BooleanRecord8[]; +type ClosedBooleanRecord8Array BooleanRecord8[3]; +type BooleanRecord9Array BooleanRecord9[]; +type ClosedBooleanRecord9Array BooleanRecord9[3]; +type BooleanRecord10Array BooleanRecord10[]; +type ClosedBooleanRecord10Array BooleanRecord10[3]; +type BooleanRecord11Array BooleanRecord11[]; +type ClosedBooleanRecord11Array BooleanRecord11[3]; +type BooleanRecord12Array BooleanRecord12[]; +type ClosedBooleanRecord12Array BooleanRecord12[3]; +type BooleanRecord13Array BooleanRecord13[]; +type ClosedBooleanRecord13Array BooleanRecord13[3]; +type BooleanRecord14Array BooleanRecord14[]; +type ClosedBooleanRecord14Array BooleanRecord14[3]; +type BooleanRecord15Array BooleanRecord15[]; +type ClosedBooleanRecord15Array BooleanRecord15[3]; +type BooleanRecord16Array BooleanRecord16[]; +type ClosedBooleanRecord16Array BooleanRecord16[3]; +type BooleanRecord17Array BooleanRecord17[]; +type ClosedBooleanRecord17Array BooleanRecord17[3]; +type BooleanRecord18Array BooleanRecord18[]; +type ClosedBooleanRecord18Array BooleanRecord18[3]; + +type NilRecord1Array NilRecord1[]; +type ClosedNilRecord1Array NilRecord1[3]; +type NilRecord2Array NilRecord2[]; +type ClosedNilRecord2Array NilRecord2[3]; +type NilRecord3Array NilRecord3[]; +type ClosedNilRecord3Array NilRecord3[3]; +type NilRecord4Array NilRecord4[]; +type ClosedNilRecord4Array NilRecord4[3]; +type NilRecord5Array NilRecord5[]; +type ClosedNilRecord5Array NilRecord5[3]; +type NilRecord6Array NilRecord6[]; +type ClosedNilRecord6Array NilRecord6[3]; +type NilRecord7Array NilRecord7[]; +type ClosedNilRecord7Array NilRecord7[3]; +type NilRecord8Array NilRecord8[]; +type ClosedNilRecord8Array NilRecord8[3]; +type NilRecord9Array NilRecord9[]; +type ClosedNilRecord9Array NilRecord9[3]; +type NilRecord10Array NilRecord10[]; +type ClosedNilRecord10Array NilRecord10[3]; +type NilRecord11Array NilRecord11[]; +type ClosedNilRecord11Array NilRecord11[3]; +type NilRecord12Array NilRecord12[]; +type ClosedNilRecord12Array NilRecord12[3]; +type NilRecord13Array NilRecord13[]; +type ClosedNilRecord13Array NilRecord13[3]; +type NilRecord14Array NilRecord14[]; +type ClosedNilRecord14Array NilRecord14[3]; +type IntegerRecord1Array IntegerRecord1[]; +type ClosedIntegerRecord1Array IntegerRecord1[3]; +type IntegerRecord2Array IntegerRecord2[]; +type ClosedIntegerRecord2Array IntegerRecord2[3]; +type IntegerRecord3Array IntegerRecord3[]; +type ClosedIntegerRecord3Array IntegerRecord3[3]; +type IntegerRecord4Array IntegerRecord4[]; +type ClosedIntegerRecord4Array IntegerRecord4[3]; +type IntegerRecord5Array IntegerRecord5[]; +type ClosedIntegerRecord5Array IntegerRecord5[3]; +type IntegerRecord6Array IntegerRecord6[]; +type ClosedIntegerRecord6Array IntegerRecord6[3]; +type IntegerRecord7Array IntegerRecord7[]; +type ClosedIntegerRecord7Array IntegerRecord7[3]; +type IntegerRecord8Array IntegerRecord8[]; +type ClosedIntegerRecord8Array IntegerRecord8[3]; +type IntegerRecord9Array IntegerRecord9[]; +type ClosedIntegerRecord9Array IntegerRecord9[3]; +type IntegerRecord10Array IntegerRecord10[]; +type ClosedIntegerRecord10Array IntegerRecord10[3]; +type IntegerRecord11Array IntegerRecord11[]; +type ClosedIntegerRecord11Array IntegerRecord11[3]; +type IntegerRecord12Array IntegerRecord12[]; +type ClosedIntegerRecord12Array IntegerRecord12[3]; +type IntegerRecord13Array IntegerRecord13[]; +type ClosedIntegerRecord13Array IntegerRecord13[3]; +type IntegerRecord14Array IntegerRecord14[]; +type ClosedIntegerRecord14Array IntegerRecord14[3]; +type FloatRecord1Array FloatRecord1[]; +type ClosedFloatRecord1Array FloatRecord1[3]; +type FloatRecord2Array FloatRecord2[]; +type ClosedFloatRecord2Array FloatRecord2[3]; +type FloatRecord3Array FloatRecord3[]; +type ClosedFloatRecord3Array FloatRecord3[3]; +type FloatRecord4Array FloatRecord4[]; +type ClosedFloatRecord4Array FloatRecord4[3]; +type FloatRecord5Array FloatRecord5[]; +type ClosedFloatRecord5Array FloatRecord5[3]; +type FloatRecord6Array FloatRecord6[]; +type ClosedFloatRecord6Array FloatRecord6[3]; +type FloatRecord7Array FloatRecord7[]; +type ClosedFloatRecord7Array FloatRecord7[3]; +type FloatRecord8Array FloatRecord8[]; +type ClosedFloatRecord8Array FloatRecord8[3]; +type FloatRecord9Array FloatRecord9[]; +type ClosedFloatRecord9Array FloatRecord9[3]; +type FloatRecord10Array FloatRecord10[]; +type ClosedFloatRecord10Array FloatRecord10[3]; +type FloatRecord11Array FloatRecord11[]; +type ClosedFloatRecord11Array FloatRecord11[3]; +type FloatRecord12Array FloatRecord12[]; +type ClosedFloatRecord12Array FloatRecord12[3]; +type FloatRecord13Array FloatRecord13[]; +type ClosedFloatRecord13Array FloatRecord13[3]; +type FloatRecord14Array FloatRecord14[]; +type ClosedFloatRecord14Array FloatRecord14[3]; +type DecimalRecord1Array DecimalRecord1[]; +type ClosedDecimalRecord1Array DecimalRecord1[3]; +type DecimalRecord2Array DecimalRecord2[]; +type ClosedDecimalRecord2Array DecimalRecord2[3]; +type DecimalRecord3Array DecimalRecord3[]; +type ClosedDecimalRecord3Array DecimalRecord3[3]; +type DecimalRecord4Array DecimalRecord4[]; +type ClosedDecimalRecord4Array DecimalRecord4[3]; +type DecimalRecord5Array DecimalRecord5[]; +type ClosedDecimalRecord5Array DecimalRecord5[3]; +type DecimalRecord6Array DecimalRecord6[]; +type ClosedDecimalRecord6Array DecimalRecord6[3]; +type DecimalRecord7Array DecimalRecord7[]; +type ClosedDecimalRecord7Array DecimalRecord7[3]; +type DecimalRecord8Array DecimalRecord8[]; +type ClosedDecimalRecord8Array DecimalRecord8[3]; +type DecimalRecord9Array DecimalRecord9[]; +type ClosedDecimalRecord9Array DecimalRecord9[3]; +type DecimalRecord10Array DecimalRecord10[]; +type ClosedDecimalRecord10Array DecimalRecord10[3]; +type DecimalRecord11Array DecimalRecord11[]; +type ClosedDecimalRecord11Array DecimalRecord11[3]; +type DecimalRecord12Array DecimalRecord12[]; +type ClosedDecimalRecord12Array DecimalRecord12[3]; +type DecimalRecord13Array DecimalRecord13[]; +type ClosedDecimalRecord13Array DecimalRecord13[3]; +type DecimalRecord14Array DecimalRecord14[]; +type ClosedDecimalRecord14Array DecimalRecord14[3]; +type StringRecord1Array StringRecord1[]; +type ClosedStringRecord1Array StringRecord1[3]; +type StringRecord2Array StringRecord2[]; +type ClosedStringRecord2Array StringRecord2[3]; +type StringRecord3Array StringRecord3[]; +type ClosedStringRecord3Array StringRecord3[3]; +type StringRecord4Array StringRecord4[]; +type ClosedStringRecord4Array StringRecord4[3]; +type StringRecord5Array StringRecord5[]; +type ClosedStringRecord5Array StringRecord5[3]; +type StringRecord6Array StringRecord6[]; +type ClosedStringRecord6Array StringRecord6[3]; +type StringRecord7Array StringRecord7[]; +type ClosedStringRecord7Array StringRecord7[3]; +type StringRecord8Array StringRecord8[]; +type ClosedStringRecord8Array StringRecord8[3]; +type StringRecord9Array StringRecord9[]; +type ClosedStringRecord9Array StringRecord9[3]; +type StringRecord10Array StringRecord10[]; +type ClosedStringRecord10Array StringRecord10[3]; +type StringRecord11Array StringRecord11[]; +type ClosedStringRecord11Array StringRecord11[3]; +type StringRecord12Array StringRecord12[]; +type ClosedStringRecord12Array StringRecord12[3]; +type StringRecord13Array StringRecord13[]; +type ClosedStringRecord13Array StringRecord13[3]; +type StringRecord14Array StringRecord14[]; +type ClosedStringRecord14Array StringRecord14[3]; +type JsonRecord1Array JsonRecord1[]; +type ClosedJsonRecord1Array JsonRecord1[3]; +type JsonRecord2Array JsonRecord2[]; +type ClosedJsonRecord2Array JsonRecord2[3]; +type JsonRecord3Array JsonRecord3[]; +type ClosedJsonRecord3Array JsonRecord3[3]; +type JsonRecord4Array JsonRecord4[]; +type ClosedJsonRecord4Array JsonRecord4[3]; +type JsonRecord5Array JsonRecord5[]; +type ClosedJsonRecord5Array JsonRecord5[3]; +type JsonRecord6Array JsonRecord6[]; +type ClosedJsonRecord6Array JsonRecord6[3]; +type JsonRecord7Array JsonRecord7[]; +type ClosedJsonRecord7Array JsonRecord7[3]; +type JsonRecord8Array JsonRecord8[]; +type ClosedJsonRecord8Array JsonRecord8[3]; +type JsonRecord9Array JsonRecord9[]; +type ClosedJsonRecord9Array JsonRecord9[3]; +type JsonRecord10Array JsonRecord10[]; +type ClosedJsonRecord10Array JsonRecord10[3]; +type JsonRecord11Array JsonRecord11[]; +type ClosedJsonRecord11Array JsonRecord11[3]; +type JsonRecord12Array JsonRecord12[]; +type ClosedJsonRecord12Array JsonRecord12[3]; +type JsonRecord13Array JsonRecord13[]; +type ClosedJsonRecord13Array JsonRecord13[3]; +type JsonRecord14Array JsonRecord14[]; +type ClosedJsonRecord14Array JsonRecord14[3]; +type AnydataRecord1Array AnydataRecord1[]; +type ClosedAnydataRecord1Array AnydataRecord1[3]; +type AnydataRecord2Array AnydataRecord2[]; +type ClosedAnydataRecord2Array AnydataRecord2[3]; +type AnydataRecord3Array AnydataRecord3[]; +type ClosedAnydataRecord3Array AnydataRecord3[3]; +type AnydataRecord4Array AnydataRecord4[]; +type ClosedAnydataRecord4Array AnydataRecord4[3]; +type AnydataRecord5Array AnydataRecord5[]; +type ClosedAnydataRecord5Array AnydataRecord5[3]; +type AnydataRecord6Array AnydataRecord6[]; +type ClosedAnydataRecord6Array AnydataRecord6[3]; +type AnydataRecord7Array AnydataRecord7[]; +type ClosedAnydataRecord7Array AnydataRecord7[3]; +type AnydataRecord8Array AnydataRecord8[]; +type ClosedAnydataRecord8Array AnydataRecord8[3]; +type AnydataRecord9Array AnydataRecord9[]; +type ClosedAnydataRecord9Array AnydataRecord9[3]; +type AnydataRecord10Array AnydataRecord10[]; +type ClosedAnydataRecord10Array AnydataRecord10[3]; +type AnydataRecord11Array AnydataRecord11[]; +type ClosedAnydataRecord11Array AnydataRecord11[3]; +type AnydataRecord12Array AnydataRecord12[]; +type ClosedAnydataRecord12Array AnydataRecord12[3]; +type AnydataRecord13Array AnydataRecord13[]; +type ClosedAnydataRecord13Array AnydataRecord13[3]; +type AnydataRecord14Array AnydataRecord14[]; +type ClosedAnydataRecord14Array AnydataRecord14[3]; +type CustomeRecord1Array CustomeRecord1[]; +type ClosedCustomeRecord1Array CustomeRecord1[3]; +type CustomeRecord2Array CustomeRecord2[]; +type ClosedCustomeRecord2Array CustomeRecord2[3]; +type CustomeRecord3Array CustomeRecord3[]; +type ClosedCustomeRecord3Array CustomeRecord3[3]; +type CustomeRecord4Array CustomeRecord4[]; +type ClosedCustomeRecord4Array CustomeRecord4[3]; +type CustomeRecord5Array CustomeRecord5[]; +type ClosedCustomeRecord5Array CustomeRecord5[3]; +type CustomeRecord6Array CustomeRecord6[]; +type ClosedCustomeRecord6Array CustomeRecord6[3]; +type CustomeRecord7Array CustomeRecord7[]; +type ClosedCustomeRecord7Array CustomeRecord7[3]; +type CustomeRecord8Array CustomeRecord8[]; +type ClosedCustomeRecord8Array CustomeRecord8[3]; +type CustomeRecord9Array CustomeRecord9[]; +type ClosedCustomeRecord9Array CustomeRecord9[3]; +type CustomeRecord10Array CustomeRecord10[]; +type ClosedCustomeRecord10Array CustomeRecord10[3]; +type CustomeRecord11Array CustomeRecord11[]; +type ClosedCustomeRecord11Array CustomeRecord11[3]; +type CustomeRecord12Array CustomeRecord12[]; +type ClosedCustomeRecord12Array CustomeRecord12[3]; +type CustomeRecord13Array CustomeRecord13[]; +type ClosedCustomeRecord13Array CustomeRecord13[3]; +type CustomeRecord14Array CustomeRecord14[]; +type ClosedCustomeRecord14Array CustomeRecord14[3]; +type BooleanTuple1Array BooleanTuple1[]; +type ClosedBooleanTuple1Array BooleanTuple1[3]; +type BooleanTuple2Array BooleanTuple2[]; +type ClosedBooleanTuple2Array BooleanTuple2[3]; +type BooleanTuple3Array BooleanTuple3[]; +type ClosedBooleanTuple3Array BooleanTuple3[3]; +type BooleanTuple4Array BooleanTuple4[]; +type ClosedBooleanTuple4Array BooleanTuple4[3]; +type NilTuple1Array NilTuple1[]; +type ClosedNilTuple1Array NilTuple1[3]; +type NilTuple2Array NilTuple2[]; +type ClosedNilTuple2Array NilTuple2[3]; +type NilTuple3Array NilTuple3[]; +type ClosedNilTuple3Array NilTuple3[3]; +type NilTuple4Array NilTuple4[]; +type ClosedNilTuple4Array NilTuple4[3]; +type IntegerTuple1Array IntegerTuple1[]; +type ClosedIntegerTuple1Array IntegerTuple1[3]; +type IntegerTuple2Array IntegerTuple2[]; +type ClosedIntegerTuple2Array IntegerTuple2[3]; +type IntegerTuple3Array IntegerTuple3[]; +type ClosedIntegerTuple3Array IntegerTuple3[3]; +type IntegerTuple4Array IntegerTuple4[]; +type ClosedIntegerTuple4Array IntegerTuple4[3]; +type FloatTuple1Array FloatTuple1[]; +type ClosedFloatTuple1Array FloatTuple1[3]; +type FloatTuple2Array FloatTuple2[]; +type ClosedFloatTuple2Array FloatTuple2[3]; +type FloatTuple3Array FloatTuple3[]; +type ClosedFloatTuple3Array FloatTuple3[3]; +type FloatTuple4Array FloatTuple4[]; +type ClosedFloatTuple4Array FloatTuple4[3]; +type DecimalTuple1Array DecimalTuple1[]; +type ClosedDecimalTuple1Array DecimalTuple1[3]; +type DecimalTuple2Array DecimalTuple2[]; +type ClosedDecimalTuple2Array DecimalTuple2[3]; +type DecimalTuple3Array DecimalTuple3[]; +type ClosedDecimalTuple3Array DecimalTuple3[3]; +type DecimalTuple4Array DecimalTuple4[]; +type ClosedDecimalTuple4Array DecimalTuple4[3]; +type StringTuple1Array StringTuple1[]; +type ClosedStringTuple1Array StringTuple1[3]; +type StringTuple2Array StringTuple2[]; +type ClosedStringTuple2Array StringTuple2[3]; +type StringTuple3Array StringTuple3[]; +type ClosedStringTuple3Array StringTuple3[3]; +type StringTuple4Array StringTuple4[]; +type ClosedStringTuple4Array StringTuple4[3]; +type AnydataTuple1Array AnydataTuple1[]; +type ClosedAnydataTuple1Array AnydataTuple1[3]; +type AnydataTuple2Array AnydataTuple2[]; +type ClosedAnydataTuple2Array AnydataTuple2[3]; +type AnydataTuple3Array AnydataTuple3[]; +type ClosedAnydataTuple3Array AnydataTuple3[3]; +type AnydataTuple4Array AnydataTuple4[]; +type ClosedAnydataTuple4Array AnydataTuple4[3]; +type JsonTuple1Array JsonTuple1[]; +type ClosedJsonTuple1Array JsonTuple1[3]; +type JsonTuple2Array JsonTuple2[]; +type ClosedJsonTuple2Array JsonTuple2[3]; +type JsonTuple3Array JsonTuple3[]; +type ClosedJsonTuple3Array JsonTuple3[3]; +type JsonTuple4Array JsonTuple4[]; +type ClosedJsonTuple4Array JsonTuple4[3]; +type CustomTuple1Array CustomTuple1[]; +type ClosedCustomTuple1Array CustomTuple1[3]; +type CustomTuple2Array CustomTuple2[]; +type ClosedCustomTuple2Array CustomTuple2[3]; +type CustomTuple3Array CustomTuple3[]; +type ClosedCustomTuple3Array CustomTuple3[3]; +type CustomTuple4Array CustomTuple4[]; +type ClosedCustomTuple4Array CustomTuple4[3]; +type CustomTuple5Array CustomTuple5[]; +type ClosedCustomTuple5Array CustomTuple5[3]; +type CustomTuple6Array CustomTuple6[]; +type ClosedCustomTuple6Array CustomTuple6[3]; +type IntegerArray1Array IntegerArray1[]; +type ClosedIntegerArray1Array IntegerArray1[3]; +type IntegerArray2Array IntegerArray2[]; +type ClosedIntegerArray2Array IntegerArray2[3]; +type IntegerArray3Array IntegerArray3[]; +type ClosedIntegerArray3Array IntegerArray3[3]; +type IntegerArray4Array IntegerArray4[]; +type ClosedIntegerArray4Array IntegerArray4[3]; +type IntegerArray5Array IntegerArray5[]; +type ClosedIntegerArray5Array IntegerArray5[3]; +type IntegerArray6Array IntegerArray5[]; +type ClosedIntegerArray6Array IntegerArray5[3]; +type StringArray1Array StringArray1[]; +type ClosedStringArray1Array StringArray1[3]; +type StringArray2Array StringArray2[]; +type ClosedStringArray2Array StringArray2[3]; +type StringArray3Array StringArray3[]; +type ClosedStringArray3Array StringArray3[3]; +type StringArray4Array StringArray4[]; +type ClosedStringArray4Array StringArray4[3]; +type StringArray5Array StringArray5[]; +type ClosedStringArray5Array StringArray5[3]; +type StringArray6Array StringArray5[]; +type ClosedStringArray6Array StringArray5[3]; +type FloatArray1Array FloatArray1[]; +type ClosedFloatArray1Array FloatArray1[3]; +type FloatArray2Array FloatArray2[]; +type ClosedFloatArray2Array FloatArray2[3]; +type FloatArray3Array FloatArray3[]; +type ClosedFloatArray3Array FloatArray3[3]; +type FloatArray4Array FloatArray4[]; +type ClosedFloatArray4Array FloatArray4[3]; +type FloatArray5Array FloatArray5[]; +type ClosedFloatArray5Array FloatArray5[3]; +type FloatArray6Array FloatArray5[]; +type ClosedFloatArray6Array FloatArray5[3]; +type DecimalArray1Array DecimalArray1[]; +type ClosedDecimalArray1Array DecimalArray1[3]; +type DecimalArray2Array DecimalArray2[]; +type ClosedDecimalArray2Array DecimalArray2[3]; +type DecimalArray3Array DecimalArray3[]; +type ClosedDecimalArray3Array DecimalArray3[3]; +type DecimalArray4Array DecimalArray4[]; +type ClosedDecimalArray4Array DecimalArray4[3]; +type DecimalArray5Array DecimalArray5[]; +type ClosedDecimalArray5Array DecimalArray5[3]; +type DecimalArray6Array DecimalArray5[]; +type ClosedDecimalArray6Array DecimalArray5[3]; +type BooleanArray1Array BooleanArray1[]; +type ClosedBooleanArray1Array BooleanArray1[3]; +type BooleanArray2Array BooleanArray2[]; +type ClosedBooleanArray2Array BooleanArray2[3]; +type BooleanArray3Array BooleanArray3[]; +type ClosedBooleanArray3Array BooleanArray3[3]; +type BooleanArray4Array BooleanArray4[]; +type ClosedBooleanArray4Array BooleanArray4[3]; +type BooleanArray5Array BooleanArray5[]; +type ClosedBooleanArray5Array BooleanArray5[3]; +type BooleanArray6Array BooleanArray5[]; +type ClosedBooleanArray6Array BooleanArray5[3]; +type NilArray1Array NilArray1[]; +type ClosedNilArray1Array NilArray1[3]; +type NilArray2Array NilArray2[]; +type ClosedNilArray2Array NilArray2[3]; +type NilArray3Array NilArray3[]; +type ClosedNilArray3Array NilArray3[3]; +type NilArray4Array NilArray4[]; +type ClosedNilArray4Array NilArray4[3]; +type NilArray5Array NilArray5[]; +type ClosedNilArray5Array NilArray5[3]; +type NilArray6Array NilArray5[]; +type ClosedNilArray6Array NilArray5[3]; +type JsonArray1Array JsonArray1[]; +type ClosedJsonArray1Array JsonArray1[3]; +type JsonArray2Array JsonArray2[]; +type ClosedJsonArray2Array JsonArray2[3]; +type JsonArray3Array JsonArray3[]; +type ClosedJsonArray3Array JsonArray3[3]; +type JsonArray4Array JsonArray4[]; +type ClosedJsonArray4Array JsonArray4[3]; +type JsonArray5Array JsonArray5[]; +type ClosedJsonArray5Array JsonArray5[3]; +type JsonArray6Array JsonArray5[]; +type ClosedJsonArray6Array JsonArray5[3]; +type AnydataArray1Array AnydataArray1[]; +type ClosedAnydataArray1Array AnydataArray1[3]; +type AnydataArray2Array AnydataArray2[]; +type ClosedAnydataArray2Array AnydataArray2[3]; +type AnydataArray3Array AnydataArray3[]; +type ClosedAnydataArray3Array AnydataArray3[3]; +type AnydataArray4Array AnydataArray4[]; +type ClosedAnydataArray4Array AnydataArray4[3]; +type AnydataArray5Array AnydataArray5[]; +type ClosedAnydataArray5Array AnydataArray5[3]; +type AnydataArray6Array AnydataArray5[]; +type ClosedAnydataArray6Array AnydataArray5[3]; +type CustomArray1Array CustomArray1[]; +type ClosedCustomArray1Array CustomArray1[3]; +type CustomArray2Array CustomArray2[]; +type ClosedCustomArray2Array CustomArray2[3]; +type CustomArray3Array CustomArray3[]; +type ClosedCustomArray3Array CustomArray3[3]; +type CustomArray4Array CustomArray4[]; +type ClosedCustomArray4Array CustomArray4[3]; +type CustomArray5Array CustomArray5[]; +type ClosedCustomArray5Array CustomArray5[3]; +type CustomArray6Array CustomArray5[]; +type ClosedCustomArray6Array CustomArray5[3]; +type IntegerMapArray IntegerMap[]; +type ClosedIntegerMapArray IntegerMap[3]; +type StringMapArray StringMap[]; +type ClosedStringMapArray StringMap[3]; +type DecimalMapArray DecimalMap[]; +type ClosedDecimalMapArray DecimalMap[3]; +type FloatMapArray FloatMap[]; +type ClosedFloatMapArray FloatMap[3]; +type BooleanMapArray BooleanMap[]; +type NillableBooleanMapArray NillableBooleanMap[]; +type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; +type IntUnionBooleanMapArray IntUnionBooleanMap[]; + +type ClosedBooleanMapArray BooleanMap[3]; +type NilMapArray NilMap[]; +type ClosedNilMapArray NilMap[3]; +type JsonMapArray JsonMap[]; +type ClosedJsonMapArray JsonMap[3]; +type AnydataMapArray AnydataMap[]; +type ClosedAnydataMapArray AnydataMap[3]; +type CustomMapArray CustomMap[]; +type ClosedCustomMapArray CustomMap[3]; diff --git a/ballerina/tests/user_configurations.bal b/ballerina/tests/user_configurations.bal new file mode 100644 index 0000000..837d24e --- /dev/null +++ b/ballerina/tests/user_configurations.bal @@ -0,0 +1,75 @@ +FromCSVConfig config1 = { + startNumber: 0, + headerStartNumber: 0, + dataStartNumber: 1, + headers: true, + escapeCharacter: "\\", + ignoreEmptyLines: true, + separator: ",", + quote: "\"", + skipHeaders: false, + skipdataRows: 0, + dataRowCount: -1, + orderBy: (), + skipColumns: (), + customheader: (), + suppressEscaping: false, + nullValue: () +}; + +FromCSVConfig config2 = { + startNumber: 10, + headerStartNumber: 5, + dataStartNumber: 2, + headers: false, + escapeCharacter: "/", + ignoreEmptyLines: false, + separator: ";", + quote: "'", + skipHeaders: true, + skipdataRows: 2, + dataRowCount: 100, + orderBy: [ + { + column: "column1", + columnOrder: ASC + } + ], + skipColumns:["column2"], + customheader:["column1", "column2", "column3", "column4"], + suppressEscaping: true, + nullValue: "" +}; + +FromCSVConfig config3 = { + customheader: () +}; + +FromCSVConfig config4 = { + skipColumns: ["column1"] +}; + +FromCSVConfig config5 = { + skipColumns: ["column1", "column2"] +}; + +FromCSVConfig config6 = { + skipColumns: [1, 2, 3] +}; + +FromCSVConfig config7 = { + customheader: ["header1", "header2", "header3"] +}; + +FromCSVConfig config8 = { + separator: ";" +}; + +FromCSVConfig config9 = { + escapeCharacter: "/" +}; + +FromCSVConfig config10 = { + quote: "'" +}; + diff --git a/ballerina/tests/values.bal b/ballerina/tests/values.bal new file mode 100644 index 0000000..5ec5391 --- /dev/null +++ b/ballerina/tests/values.bal @@ -0,0 +1,107 @@ +boolean b1 = true; +false b2 = false; +boolean? b3 = (); +boolean|int b4 = false; + +() n1 = (); +int? n2 = (); +() n3 = null; + +int i1 = 1; +int i2 = -2; +int i3 = int:MAX_VALUE; +int i4 = int:MIN_VALUE; +int i5 = 0; +2 i6 = 2; +int? i7 = (); +int|string i8 = 100; + +float f1 = 2.234; +float f2 = -3.21f; +float f3 = 0; +float f4 = float:Infinity; +float f5 = -float:Infinity; +float f6 = float:NaN; +2.3f f7 = 2.3; +float? f8 = (); +float|decimal f9 = 1.21; + +decimal d1 = 2.234; +decimal d2 = -3.21d; +decimal d3 = 0; +2.3d d4 = 2.3; +decimal? d5 = (); +decimal|int d6 = 1.21; + +string s1 = "string"; +string s2 = ""; +string:Char s3 = "a"; + +map bm1 = {b1, b2}; +map bm2 = {b1, b2, b3, n1, n3}; +map bm3 = {b1, b2, b3, b4, i1}; +map<()> bm4 = {n1, n3}; +map bm5 = {b1, b2, b3, b4:true}; +map m5 = {i1, i2, i3, i4, i5, i6}; +map m6 = {f1, f2, f3, f4, f5, f6, f7}; +map m7 = {d1, d2, d3, d4}; +map m8 = {d1, f1, f9, f10: 1.23}; +map m9 = {s1, s2, s3}; +map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; +map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; + +boolean[] arr1 = [b1, b2]; +boolean?[] arr2 = [b1, b2, b3, n1, n3]; +(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; +()[] arr4 = [n1, n3]; +int[] arr5 = [i1, i2, i3, i4, i5, i6]; +float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; +decimal[] arr7 = [d1, d2, d3, d4]; +(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; +string[] arr9 = [s1, s2, s3]; +anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; + +[boolean, boolean] tup1 = [b1, b2]; +[boolean?, boolean?, boolean?, boolean?, boolean?] tup2 = [b1, b2, b3, n1, n3]; +[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] tup3 = [b1, b2, b3, b4, i1]; +[(), ()] tup4 = [n1, n3]; +[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; +[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; +[string, string, string] tup9 = [s1, s2, s3]; +[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, + n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, json] tup11 = + [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, + f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 +]; + +[boolean, boolean...] restTup1 = [b1, b2]; +[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; +[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; +[(), ()...] restTup4 = [n1, n3]; +[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; +[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal...] restTup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; +[string...] restTup9 = [s1, s2, s3]; +[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 +]; + +var booleanRecordArray = [ + {b1, b2, b3, b4}, {b1, b2, b3, b4} +]; + +var booleanRecordArray2 = [ + {},{} +]; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index 7e16281..68e0e9f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -32,6 +32,7 @@ import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; +import io.ballerina.stdlib.data.csvdata.csv.CsvConfig; import java.util.ArrayList; import java.util.Comparator; @@ -66,17 +67,17 @@ public class FromString { }}; private static final UnionType JSON_TYPE_WITH_BASIC_TYPES = TypeCreator.createUnionType(BASIC_JSON_MEMBER_TYPES); - public static Object fromStringWithType(BString string, BTypedesc typed) { + public static Object fromStringWithType(BString string, CsvConfig config, BTypedesc typed) { Type expType = typed.getDescribingType(); try { - return fromStringWithType(string, expType); + return fromStringWithType(string, expType, config); } catch (NumberFormatException e) { return returnError(string.getValue(), expType.toString()); } } - public static Object fromStringWithType(BString string, Type expType) { + public static Object fromStringWithType(BString string, Type expType, CsvConfig config) { String value = string.getValue(); try { switch (expType.getTag()) { @@ -91,13 +92,13 @@ public static Object fromStringWithType(BString string, Type expType) { case TypeTags.BOOLEAN_TAG: return stringToBoolean(value); case TypeTags.NULL_TAG: - return stringToNull(value); + return stringToNull(value, config); case TypeTags.UNION_TAG: - return stringToUnion(string, (UnionType) expType); + return stringToUnion(string, (UnionType) expType, config); case TypeTags.JSON_TAG: - return stringToUnion(string, JSON_TYPE_WITH_BASIC_TYPES); + return stringToUnion(string, JSON_TYPE_WITH_BASIC_TYPES, config); case TypeTags.TYPE_REFERENCED_TYPE_TAG: - return fromStringWithType(string, ((ReferenceType) expType).getReferredType()); + return fromStringWithType(string, ((ReferenceType) expType).getReferredType(), config); default: return returnError(value, expType.toString()); } @@ -132,21 +133,28 @@ private static Object stringToBoolean(String value) throws NumberFormatException return returnError(value, "boolean"); } - private static Object stringToNull(String value) throws NumberFormatException { + private static Object stringToNull(String value, CsvConfig config) throws NumberFormatException { + Object nullValue = config.nullValue; + if (nullValue != null && StringUtils.getStringValue(nullValue).equalsIgnoreCase(value)) { + return nullValue; + } if ("null".equalsIgnoreCase(value) || "()".equalsIgnoreCase(value)) { + if (nullValue != null) { + return nullValue; + } return null; } return returnError(value, "()"); } - private static Object stringToUnion(BString string, UnionType expType) throws NumberFormatException { + private static Object stringToUnion(BString string, UnionType expType, CsvConfig config) throws NumberFormatException { List memberTypes = expType.getMemberTypes(); memberTypes.sort(Comparator.comparingInt(t -> TYPE_PRIORITY_ORDER.getOrDefault( TypeUtils.getReferredType(t).getTag(), Integer.MAX_VALUE))); boolean isStringExpType = false; for (Type memberType : memberTypes) { try { - Object result = fromStringWithType(string, memberType); + Object result = fromStringWithType(string, memberType, config); if (result instanceof BString) { isStringExpType = true; continue; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index a87dbe9..28b0ddc 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -58,9 +58,10 @@ static Object initRowValue(Type expectedType) { } } - static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, BString value, Type type) { + static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, + BString value, Type type, CsvConfig config) { Object currentJson = sm.currentCsvNode; - Object convertedValue = convertToExpectedType(value, type); + Object convertedValue = convertToExpectedType(value, type, config); if (convertedValue instanceof BError) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, type, value); } @@ -89,10 +90,10 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, BString } } - private static Object convertToExpectedType(BString value, Type type) { + private static Object convertToExpectedType(BString value, Type type, CsvConfig config) { if (type.getTag() == TypeTags.ANYDATA_TAG) { - return FromString.fromStringWithType(value, PredefinedTypes.TYPE_JSON); + return FromString.fromStringWithType(value, PredefinedTypes.TYPE_JSON, config); } - return FromString.fromStringWithType(value, type); + return FromString.fromStringWithType(value, type, config); } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 90e309e..291f568 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -33,7 +33,7 @@ import java.io.Reader; import java.util.*; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.validateExpectedArraySize; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.*; /** * Convert Csv string to a ballerina record. @@ -91,7 +91,10 @@ static class StateMachine { Type expectedArrayElementType; int columnIndex = 0; int rowIndex = 0; + int lineNumber = 0; ArrayType rootArrayType = null; + CsvConfig config = null; + ArrayList skipColumnIndexes = new ArrayList<>(); StateMachine() { reset(); @@ -109,6 +112,8 @@ public void reset() { fieldHierarchy.clear(); fieldNames.clear(); rootArrayType = null; + config = null; + lineNumber = 0; } private static boolean isWhitespace(char ch) { @@ -134,7 +139,16 @@ private String value() { return result; } + private void clear() { + this.charBuffIndex = 0; + } + + private String peek() { + return new String(this.charBuff, 0, this.charBuffIndex); + } + public Object execute(Reader reader, Type type, CsvConfig config) throws BError { + this.config = config; Type referredType = TypeUtils.getReferredType(type); if (referredType.getTag() != TypeTags.ARRAY_TAG) { return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type); @@ -161,7 +175,7 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError default: throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); } - boolean header = true; + boolean header = config.headers; State currentState; if (header) { currentState = HEADER_START_STATE; @@ -181,6 +195,8 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError if (currentState != ROW_END_STATE && currentState != HEADER_END_STATE) { throw new CsvParserException("Invalid token found"); } + + sortCsvData(rootCsvNode, config); return rootCsvNode; } catch (IOException e) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TOKEN, e.getMessage(), line, column); @@ -222,19 +238,35 @@ private static class HeaderStartState implements State { public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { char ch; State state = HEADER_START_STATE; - //TODO: Add separator here //TODO: If the header is not present make the headers and fieldnames to be default values - char separator = ','; + char separator = sm.config.separator; + boolean skipHeaders = sm.config.skipHeaders; + Object customHeader = sm.config.customHeader; for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); - if (ch == separator) { + + if (ignoreHeader(sm)) { + sm.lineNumber++; + continue; + } + if (skipHeaders || customHeader != null) { + if (sm.isEndOfTheRow(ch)) { + checkAndAddCustomHeaders(sm.headers, customHeader, sm.config.skipHeaders); + sm.lineNumber++; + state = HEADER_END_STATE; + break; + } + continue; + } else if (ch == separator) { addHeader(sm); sm.columnIndex++; + continue; } else if (sm.isEndOfTheRow(ch)) { addHeader(sm); finalizeHeaders(sm); sm.columnIndex = 0; + sm.lineNumber++; state = HEADER_END_STATE; } else if (StateMachine.isWhitespace(ch)) { state = this; @@ -250,6 +282,17 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return state; } + private void checkAndAddCustomHeaders(ArrayList headers, Object customHeader, boolean skipHeaders) { + if (skipHeaders || headers == null) { + return; + } + + BArray customHeaders = (BArray) customHeader; + for (int i = 0; i < customHeaders.size(); i++) { + headers.add(StringUtils.getStringValue(customHeaders.get(i))); + } + } + private void finalizeHeaders(StateMachine sm) throws CsvParserException { Type expType = sm.expectedArrayElementType; if (expType instanceof RecordType) { @@ -285,6 +328,15 @@ private void validateRemainingRecordFields(StateMachine sm) { } } + private boolean ignoreHeader(StateMachine sm) { + int lineNumber = sm.lineNumber; + if (lineNumber < sm.config.headerStartNumber + || lineNumber < sm.config.startNumber) { + return true; + } + return false; + } + private void addHeader(StateMachine sm) throws CsvParserException { String value = sm.value(); if (sm.expectedArrayElementType instanceof RecordType) { @@ -321,23 +373,35 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C State state = ROW_START_STATE; //TODO: Add separator here char separator = ','; + updateHeaders(sm); // TODO: Ignore this in future for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + + if (calculateNumberOfRows(sm.config.dataRowCount, sm.rowIndex, sm.config.skipDataRows)) { + sm.rowIndex++; + sm.lineNumber++; + break; + } + if (sm.rowIndex < sm.config.skipDataRows) { + if (sm.isEndOfTheRow(ch)) { + sm.lineNumber++; + sm.rowIndex++; + } + continue; + } + //TODO: Handle empty values and create again and again if (sm.currentCsvNode == null) { initiateNewRowType(sm); } if (ch == separator) { addRowValue(sm); - sm.columnIndex++; } else if (sm.isEndOfTheRow(ch)) { - addRowValue(sm); - finalizeTheRow(sm); - sm.columnIndex = 0; - sm.currentCsvNode = null; + sm.lineNumber++; + handleCsvRow(sm); if (ch == EOF) { state = ROW_END_STATE; } @@ -351,6 +415,41 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return state; } + private void updateHeaders(StateMachine sm) { + if (!sm.config.headers || sm.config.skipHeaders){ + return; + } + List updatedHeaders = Arrays.asList( + QueryParser.parse(sm.config.skipColumns, sm.headers.toArray(new String[]{}))); + generateSkipColumnIndexes(updatedHeaders, sm); + } + + private void generateSkipColumnIndexes(List updatedHeaders, StateMachine sm) { + String header; + ArrayList copyOfHeaders = new ArrayList<>(); + for (int i = 0; i < sm.headers.size(); i++) { + header = sm.headers.get(i); + if (!updatedHeaders.contains(header)) { + sm.skipColumnIndexes.add(i); + continue; + } + copyOfHeaders.add(header); + } + sm.headers = copyOfHeaders; + } + + private void handleCsvRow(StateMachine sm) throws CsvParserException { + if (ignoreRow(sm)) { + sm.clear(); + sm.columnIndex = 0; + return; + } + addRowValue(sm); + finalizeTheRow(sm); + sm.columnIndex = 0; + sm.currentCsvNode = null; + } + private void initiateNewRowType(StateMachine sm) throws CsvParserException { sm.currentCsvNode = CsvCreator.initRowValue(sm.expectedArrayElementType); } @@ -367,6 +466,11 @@ private void addRowValue(StateMachine sm) throws CsvParserException { // TODO: Can convert all at once by storing in a Object[] Type type; Type exptype = sm.expectedArrayElementType; + + if (checkColumnIsSkippedOrNot(sm)) { + return; + } + if (exptype instanceof RecordType) { type = getExpectedRowTypeOfRecord(sm); } else if (exptype instanceof MapType) { @@ -380,8 +484,27 @@ private void addRowValue(StateMachine sm) throws CsvParserException { } if (type != null) { - CsvCreator.convertAndUpdateCurrentJsonNode(sm, StringUtils.fromString(sm.value()), type); + CsvCreator.convertAndUpdateCurrentJsonNode(sm, StringUtils.fromString(sm.value()), type, sm.config); + } + sm.columnIndex++; + } + + private boolean checkColumnIsSkippedOrNot(StateMachine sm) { + return sm.skipColumnIndexes.contains(sm.columnIndex); + } + + private boolean ignoreRow(StateMachine sm) { + String value = sm.peek(); + int rowNumber = sm.rowIndex + 1; + if (sm.config.ignoreEmptyLines && value.isEmpty()) { + return true; + } + if (rowNumber < sm.config.dataStartNumber + || rowNumber < sm.config.startNumber) { + sm.rowIndex++; + return true; } + return false; } private Type getExpectedRowTypeOfTuple(StateMachine sm, TupleType tupleType) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index bbb05f8..3057c29 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -21,12 +21,7 @@ import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ValueCreator; -import io.ballerina.runtime.api.types.ArrayType; -import io.ballerina.runtime.api.types.Field; -import io.ballerina.runtime.api.types.MapType; -import io.ballerina.runtime.api.types.RecordType; -import io.ballerina.runtime.api.types.TupleType; -import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.*; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.*; @@ -79,7 +74,7 @@ void reset() { @SuppressWarnings("unchecked") public Object traverseCsv(BArray csv, CsvConfig config, Type type) { this.config = config; - sourceArrayElementType = csv.getElementType(); + sourceArrayElementType = TypeUtils.getReferredType(csv.getElementType()); Type referredType = TypeUtils.getReferredType(type); int expectedArraySize = ((ArrayType) referredType).getSize(); int sourceArraySize = (int) csv.getLength(); @@ -88,7 +83,7 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { validateExpectedArraySize(expectedArraySize, sourceArraySize); traverseCsvWithExpectedType(expectedArraySize, sourceArraySize, csv); - sortCsvData(); + sortCsvData(rootCsvNode, config); return rootCsvNode; } @@ -106,7 +101,7 @@ private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArrayS sourceArraySize : expectedArraySize, csv, expectedArrayElementType); break; default: - DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); } } @@ -148,7 +143,8 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected RecordType recordType = (RecordType) expectedType; this.fieldHierarchy = new HashMap<>(recordType.getFields()); this.restType = recordType.getRestFieldType(); - currentCsvNode = ValueCreator.createRecordValue(recordType); + // TODO: check for package ID + currentCsvNode = ValueCreator.createRecordValue(recordType.getPackage(), recordType.getName()); traverseCsvMap(csvElement, expectedType, false); break; case TypeTags.MAP_TAG: @@ -164,7 +160,7 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected // traverseCsvMap(csvElement, expectedType, true); // break; default: - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } return currentCsvNode; } @@ -183,7 +179,7 @@ public Object traverseCsvElementWithArray(Object csvElement, Type expectedType) traverseArrayValue(csvElement, tupleType); break; default: - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } return currentCsvNode; } @@ -313,16 +309,21 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Str } private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean mappingType, Type expectedType) { - Type fieldType; - BString key; int arraySize = csvElement.size(); String[] headers = new String[arraySize]; headers = createHeaders(headers, config); - boolean conversion = checkExpectedTypeMatchWithHeaders(expectedType, headers, csvElement, arraySize); - if (!conversion) { + boolean headersMatchWithExpType = checkExpectedTypeMatchWithHeaders( + expectedType, headers, csvElement, arraySize); + if (!headersMatchWithExpType) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csvElement, expectedType); } // TODO: Add headers from config + addValuesToMapType(csvElement, arraySize, mappingType, expectedType); + } + + private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappingType, Type expectedType) { + Type fieldType; + BString key; for(int i = 1; i <= arraySize; i++) { key = StringUtils.fromString(String.valueOf(i)); if (!mappingType) { @@ -334,7 +335,7 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean addFieldInMapType(key); fieldType = ((MapType) expectedType).getConstrainedType();; } - addCurrentFieldValue(fieldType, csvElement.get(i - 1), key); + addCurrentFieldValue(fieldType, csvElement.get(i - 1), key, mappingType); } checkOptionalFieldsAndLogError(fieldHierarchy); } @@ -353,7 +354,7 @@ private void traverseMapValueWithMapAsExpectedType(BMap map, bo ((MapType) expType).getConstrainedType() ); } - addCurrentFieldValue(currentFieldType, map.get(key), key); + addCurrentFieldValue(currentFieldType, map.get(key), key, mappingType); } checkOptionalFieldsAndLogError(fieldHierarchy); } @@ -376,7 +377,7 @@ private void addFieldInMapType(BString key) { fieldNames.push(key.toString()); } - private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BString key) { + private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BString key, boolean isMapType) { int currentFieldTypeTag = currentFieldType.getTag(); switch (currentFieldTypeTag) { @@ -386,12 +387,35 @@ private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BStrin case TypeTags.FLOAT_TAG: case TypeTags.DECIMAL_TAG: case TypeTags.STRING_TAG: + if (checkTypeCompatibility(currentFieldType, mapValue)) { + ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), + convertToBasicType(mapValue, currentFieldType, config)); + return; + } + if (!isMapType) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); + } + return; + case TypeTags.UNION_TAG: + boolean isCompatible = false; + for (Type memberType: ((UnionType) currentFieldType).getMemberTypes()) { + if (!isBasicType(memberType)) { + isCompatible = false; + break; + } + if (checkTypeCompatibility(memberType, mapValue)) { + isCompatible = true; + } + } + if (!isCompatible) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); + } ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), convertToBasicType(mapValue, currentFieldType, config)); break; default: // TODO: handle maps and structure values in future - DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, currentFieldType); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); } } @@ -410,28 +434,34 @@ private void addRestField(Type restFieldType, BString key, Object csvMember) { ((BMap) currentCsvNode).put(key, csvMember); } break; + case TypeTags.UNION_TAG: + boolean isCompatible = false; + for (Type memberType: ((UnionType) restFieldType).getMemberTypes()) { + if (!isBasicType(memberType)) { + isCompatible = false; + break; + } + if (checkTypeCompatibility(memberType, csvMember)) { + isCompatible = true; + } + } + if (isCompatible) { + ((BMap) currentCsvNode) + .put(key, convertToBasicType(csvMember, restFieldType, config)); + } + break; + default: + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, csvMember, key); } } private void setRootCsvNode(Type referredType, Type type) { if (referredType.getTag() != TypeTags.ARRAY_TAG) { - DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); } else { rootCsvNode = ValueCreator.createArrayValue((ArrayType) referredType); - expectedArrayElementType = ((ArrayType) TypeUtils.getReferredType(referredType)).getElementType(); + expectedArrayElementType = TypeUtils.getReferredType(((ArrayType) referredType).getElementType()); } } - - private void sortCsvData() { - Object orderConfiguration = config.orderBy; - if (orderConfiguration == null) { - return; - } - - Object[] arrayValues = rootCsvNode.getValues(); - Arrays.sort(arrayValues, (value1, value2) -> compareCsvColumns( - value1, value2, constructSortingColumnNames(orderConfiguration)) - ); - } } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java index 75dd0ed..b080a8c 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java @@ -22,8 +22,8 @@ public class QueryParser { private static Set exclusiveHeaders = new HashSet<>(); private static ArrayList columns = null; private static String elementSeparatorRegex = "(?![^(]*\\))"; - private static String alphanumericRegex = "[0-9A-Za-z]"; - private static String rangeRegex = "[0-9A-Za-z]:[0-9A-Za-z]"; + private static String alphanumericRegex = "\\w*"; + private static String rangeRegex = "\\w*:\\w*"; private void reset() { inclusiveHeaders = new HashSet<>(); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 9a3afaa..11e7b42 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -16,8 +16,11 @@ import io.ballerina.stdlib.data.csvdata.csv.CsvTraversal; import io.ballerina.stdlib.data.csvdata.csv.QueryParser; +import java.util.Arrays; import java.util.Map; +import static io.ballerina.runtime.api.TypeTags.INT_TAG; + public class CsvUtils { public static CsvConfig createFromCsvConfiguration(BMap config) { return CsvConfig.createFromCsvConfiguration(config); @@ -33,6 +36,32 @@ 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: + return true; + default: + return false; + } + } + + public static void sortCsvData(BArray rootCsvNode, CsvConfig config) { + Object orderConfiguration = config.orderBy; + if (orderConfiguration == null) { + return; + } + + Object[] arrayValues = rootCsvNode.getValues(); + Arrays.sort(arrayValues, (value1, value2) -> compareCsvColumns( + value1, value2, constructSortingColumnNames(orderConfiguration)) + ); + } + public static int compareCsvColumns(Object row1, Object row2, SortConfigurations[] sortConfigurations) { Object o1,o2; int value; @@ -165,12 +194,13 @@ public static void checkOptionalFieldsAndLogError(Map currentFiel // TODO: Handle this properly if (!(SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED) && SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL))) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); +// throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); } }); } public static boolean checkTypeCompatibility(Type constraintType, Object csv) { + // TODO: Remove this if (csv instanceof BMap) { BMap map = (BMap) csv; for (BString key : map.getKeys()) { @@ -180,7 +210,7 @@ public static boolean checkTypeCompatibility(Type constraintType, Object csv) { } return true; } else if ((csv instanceof BString && constraintType.getTag() == TypeTags.STRING_TAG) - || (csv instanceof Long && constraintType.getTag() == TypeTags.INT_TAG) + || (csv instanceof Long && constraintType.getTag() == INT_TAG) || (csv instanceof BDecimal && constraintType.getTag() == TypeTags.DECIMAL_TAG) || (csv instanceof Double && (constraintType.getTag() == TypeTags.FLOAT_TAG || constraintType.getTag() == TypeTags.DECIMAL_TAG)) @@ -197,7 +227,7 @@ public static void addValuesToArrayType(Object csvElement, Type arrayElementType switch (arrayElementType.getTag()) { case TypeTags.NULL_TAG: case TypeTags.BOOLEAN_TAG: - case TypeTags.INT_TAG: + case INT_TAG: case TypeTags.FLOAT_TAG: case TypeTags.DECIMAL_TAG: case TypeTags.STRING_TAG: diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index 7d6425b..536de14 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -35,7 +35,8 @@ public enum DiagnosticErrorCode { INVALID_CSV_DATA_FORMAT("BDE_0008", "invalid.csv.data.format"), INVALID_EXPECTED_ARRAY_SIZE("BDE_0009", "invalid.expected.array.size"), INVALID_EXPECTED_TUPLE_SIZE("BDE_0010", "invalid.expected.tuple.size"), - INVALID_SKIP_COLUMN_QUERY("BDE_0011", "invalid.skip.column.query"); + INVALID_SKIP_COLUMN_QUERY("BDE_0011", "invalid.skip.column.query"), + INVALID_TYPE_FOR_FIELD("BDE_0012", "invalid.type.for.field"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index be6ad82..a60e609 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -52,3 +52,6 @@ error.invalid.expected.tuple.size=\ error.invalid.skip.column.query=\ invalid query found for skip column field, ''{0}'' + +error.invalid.type.for.field=\ + no mapping type found for value ''{0}'' in key ''{1}'' From ed3cbf426b312d2874359f41f770712366f1c290 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 15 Mar 2024 13:59:26 +0530 Subject: [PATCH 017/147] Add tests for tuple source values --- ballerina/csv_api.bal | 8 +- ballerina/tests/from_csv_with_type_test.bal | 1841 +++++++++++++++-- ballerina/tests/types.bal | 291 ++- ballerina/tests/values.bal | 21 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 74 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 101 +- .../csvdata/utils/DiagnosticErrorCode.java | 5 +- native/src/main/resources/error.properties | 10 + 8 files changed, 2099 insertions(+), 252 deletions(-) diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 01f4d6a..b8455a7 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -69,19 +69,19 @@ public type ToCSVConfig record {| string:Char escapeCharacter = "\\"; |}; -public isolated function fromCsvWithType((string[]|map|record{})[] csv, FromCSVConfig config = {}, typedesc<(record{}|map|anydata[])[]> t = <>) +public isolated function fromCsvWithType((string[]|map)[] csv, FromCSVConfig config = {}, typedesc<(record{}|map|anydata[])[]> t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function fromCsvStringWithType(string|byte[]|stream s, FromCSVConfig config = {} ,typedesc<(record{}|map|anydata)[]> t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public isolated function toCsv((anydata[]|map|record{})[] csv, ToCSVConfig config = {}, typedesc<(record{}|map|anydata[])[]> t = <>) +public isolated function toCsv((anydata[]|map)[] csv, ToCSVConfig config = {}, typedesc<(record{}|map|anydata[])[]> t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public isolated function toCsvString((anydata[]|map|record{})[] csv, ToCSVConfig config = {}) returns string|UnSupportedOperation { +public isolated function toCsvString((anydata[]|map)[] csv, ToCSVConfig config = {}) returns string|UnSupportedOperation { string csvString = ""; - foreach anydata[]|map|record{} row in csv { + foreach anydata[]|map row in csv { if row is anydata[] { foreach anydata cell in row { csvString += check convertToString(cell) + config.separator; diff --git a/ballerina/tests/from_csv_with_type_test.bal b/ballerina/tests/from_csv_with_type_test.bal index 586f688..0eb22ab 100644 --- a/ballerina/tests/from_csv_with_type_test.bal +++ b/ballerina/tests/from_csv_with_type_test.bal @@ -1,34 +1,7 @@ import ballerina/test; -// @test:Config -// function testFromCsvWithTypeForMapAndMapAsExpextedType() { - -// } - -// @test:Config -// function testFromCsvWithTypeForRecordAndRecordAsExpextedType() { - -// } - -// @test:Config -// function testFromCsvWithTypeForMapAndArrayAsExpextedType() { - -// } - -// @test:Config -// function testFromCsvWithTypeForMapAndTupleAsExpextedType() { - -// } - -// @test:Config -// function testFromCsvWithTypeForRecordAndMapAsExpextedType() { - -// } - -boolean enable = true; - @test:Config {enable} -function testFromCsvWithTypeForMapAndRecordAsExpextedType() { +function testFromCsvWithTypeForMapAndRecordAsExpectedType() { BooleanRecord1Array|CsvConversionError bm1br1 = fromCsvWithType([bm1, bm1], {}, BooleanRecord1Array); test:assertTrue(bm1br1 is CsvConversionError); test:assertEquals((bm1br1).message(), generateErrorMessageForMissingRequiredField("b3")); @@ -220,7 +193,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpextedType() { } @test:Config {enable} -function testFromCsvWithTypeForMapAndRecordAsExpextedType2() { +function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { BooleanRecord9Array|CsvConversionError bm1br9 = fromCsvWithType([bm1, bm1], {}, BooleanRecord9Array); test:assertTrue(bm1br9 is CsvConversionError); test:assertEquals((bm1br9).message(), generateErrorMessageForMissingRequiredField("b3")); @@ -476,17 +449,8 @@ function testFromCsvWithTypeForMapAndRecordAsExpextedType2() { ]); } -@test:Config {enable: !enable} -function test() { - BooleanMapArray|CsvConversionError bm2bma = fromCsvWithType([bm2, bm2], {}, BooleanMapArray); - test:assertEquals(bm2bma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); -} - @test:Config {enable} -function testFromCsvWithTypeForMapAndMapAsExpextedType() { +function testFromCsvWithTypeForMapAndMapAsExpectedType() { BooleanMapArray|CsvConversionError bm1bma = fromCsvWithType([bm1, bm1], {}, BooleanMapArray); test:assertEquals(bm1bma, [ {b1: true, b2: false}, @@ -517,107 +481,1748 @@ function testFromCsvWithTypeForMapAndMapAsExpextedType() { {b1: true, b2: false, b4: true} ]); - // NillableBooleanMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, NillableBooleanMapArray); - // test:assertEquals(bm1br15, [ - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} - // ]); - - // NillableIntUnionBooleanMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, NillableIntUnionBooleanMapArray); - // test:assertEquals(bm1br15, [ - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} - // ]); - - // IntUnionBooleanMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, IntUnionBooleanMapArray); - // test:assertEquals(bm1br15, [ - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} - // ]); - - // NilMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, NilMapArray); - // test:assertEquals(bm1br15, [ - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} - // ]); - - // JsonMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, JsonMapArray); - // test:assertEquals(bm1br15, [ - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} - // ]); - - // AnydataMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, AnydataMapArray); - // test:assertEquals(bm1br15, [ - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} - // ]); - - // CustomMapArray|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, CustomMapArray); - // test:assertEquals(bm1br15, [ - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null}, - // {b1: true, b2: false, b3: (), n1: (), n3: (), defaultableField: "", nillableField :null} - // ]); -} + NillableBooleanMapArray|CsvConversionError bm1nbma = fromCsvWithType([bm1, bm1], {}, NillableBooleanMapArray); + test:assertEquals(bm1nbma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); -function generateErrorMessageForMissingRequiredField(string 'field) returns string { - return string `no matching header value is found for the required field '${'field}'`; -} + NillableBooleanMapArray|CsvConversionError bm2nbma = fromCsvWithType([bm2, bm2], {}, NillableBooleanMapArray); + test:assertEquals(bm2nbma, [ + {b1: true, b2: false, b3:(), n1: (), n3: ()}, + {b1: true, b2: false, b3:(), n1: (), n3: ()} + ]); -function generateErrorMessageForInvalidCast(string value, string 'type) returns string { - return string `value '${value}' cannot be cast into '${'type}'`; + NillableBooleanMapArray|CsvConversionError bm3nbma = fromCsvWithType([bm3, bm3], {}, NillableBooleanMapArray); + test:assertEquals(bm3nbma, [ + {b1: true, b2: false, b3:(), b4: false}, + {b1: true, b2: false, b3:(), b4: false} + ]); + + NillableBooleanMapArray|CsvConversionError bm4nbma = fromCsvWithType([bm4, bm4], {}, NillableBooleanMapArray); + test:assertEquals(bm4nbma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + NillableBooleanMapArray|CsvConversionError bm5nbma = fromCsvWithType([bm5, bm5], {}, NillableBooleanMapArray); + test:assertEquals(bm5nbma, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bm1niubma = fromCsvWithType([bm1, bm1], {}, NillableIntUnionBooleanMapArray); + test:assertEquals(bm1niubma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bm2niubma = fromCsvWithType([bm2, bm2], {}, NillableIntUnionBooleanMapArray); + test:assertEquals(bm2niubma, [ + {b1: true, b2: false, b3:(), n1: (), n3: ()}, + {b1: true, b2: false, b3:(), n1: (), n3: ()} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bm3niubma = fromCsvWithType([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|CsvConversionError bm4niubma = fromCsvWithType([bm4, bm4], {}, NillableIntUnionBooleanMapArray); + test:assertEquals(bm4niubma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bm5niubma = fromCsvWithType([bm5, bm5], {}, NillableIntUnionBooleanMapArray); + test:assertEquals(bm5niubma, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + IntUnionBooleanMapArray|CsvConversionError bm1iubma = fromCsvWithType([bm1, bm1], {}, IntUnionBooleanMapArray); + test:assertEquals(bm1iubma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + IntUnionBooleanMapArray|CsvConversionError bm2iubma = fromCsvWithType([bm2, bm2], {}, IntUnionBooleanMapArray); + test:assertEquals(bm2iubma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + IntUnionBooleanMapArray|CsvConversionError bm3iubma = fromCsvWithType([bm3, bm3], {}, IntUnionBooleanMapArray); + test:assertEquals(bm3iubma, [ + {b1: true, b2: false, b4: false, i1: 1}, + {b1: true, b2: false, b4: false, i1: 1} + ]); + + IntUnionBooleanMapArray|CsvConversionError bm4iubma = fromCsvWithType([bm4, bm4], {}, IntUnionBooleanMapArray); + test:assertEquals(bm4iubma, [ + {}, + {} + ]); + + IntUnionBooleanMapArray|CsvConversionError bm5iubma = fromCsvWithType([bm5, bm5], {}, IntUnionBooleanMapArray); + test:assertEquals(bm5iubma, [ + {b1: true, b2: false, b4: true}, + {b1: true, b2: false, b4: true} + ]); + + NilMapArray|CsvConversionError bm1nma = fromCsvWithType([bm1, bm1], {}, NilMapArray); + test:assertEquals(bm1nma, [ + {}, + {} + ]); + + NilMapArray|CsvConversionError bm2nma = fromCsvWithType([bm2, bm2], {}, NilMapArray); + test:assertEquals(bm2nma, [ + {n1: (), n3: (), b3: ()}, + {n1: (), n3: (), b3: ()} + ]); + + NilMapArray|CsvConversionError bm3nma = fromCsvWithType([bm3, bm3], {}, NilMapArray); + test:assertEquals(bm3nma, [ + {b3: ()}, + {b3: ()} + ]); + + NilMapArray|CsvConversionError bm4nma = fromCsvWithType([bm4, bm4], {}, NilMapArray); + test:assertEquals(bm4nma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + NilMapArray|CsvConversionError bm5nma = fromCsvWithType([bm5, bm5], {}, NilMapArray); + test:assertEquals(bm5nma, [ + {b3: ()}, + {b3: ()} + ]); + + JsonMapArray|CsvConversionError bm1jma = fromCsvWithType([bm1, bm1], {}, JsonMapArray); + test:assertEquals(bm1jma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + JsonMapArray|CsvConversionError bm2jma = fromCsvWithType([bm2, bm2], {}, JsonMapArray); + test:assertEquals(bm2jma, [ + {b1: true, b2: false, b3: (), n1: (), n3: ()}, + {b1: true, b2: false, b3: (), n1: (), n3: ()} + ]); + + JsonMapArray|CsvConversionError bm3jma = fromCsvWithType([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|CsvConversionError bm4jma = fromCsvWithType([bm4, bm4], {}, JsonMapArray); + test:assertEquals(bm4jma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + JsonMapArray|CsvConversionError bm5jma = fromCsvWithType([bm5, bm5], {}, JsonMapArray); + test:assertEquals(bm5jma, [ + {b1: true, b2: false, b4: true, b3: ()}, + {b1: true, b2: false, b4: true, b3: ()} + ]); + + AnydataMapArray|CsvConversionError bm1anydma = fromCsvWithType([bm1, bm1], {}, AnydataMapArray); + test:assertEquals(bm1anydma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + AnydataMapArray|CsvConversionError bm2anydma = fromCsvWithType([bm2, bm2], {}, AnydataMapArray); + test:assertEquals(bm2anydma, [ + {b1: true, b2: false, b3: (), n1: (), n3: ()}, + {b1: true, b2: false, b3: (), n1: (), n3: ()} + ]); + + AnydataMapArray|CsvConversionError bm3anydma = fromCsvWithType([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|CsvConversionError bm4anydma = fromCsvWithType([bm4, bm4], {}, AnydataMapArray); + test:assertEquals(bm4anydma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + AnydataMapArray|CsvConversionError bm5anydma = fromCsvWithType([bm5, bm5], {}, AnydataMapArray); + test:assertEquals(bm5anydma, [ + {b1: true, b2: false, b4: true, b3: ()}, + {b1: true, b2: false, b4: true, b3: ()} + ]); + + CustomMapArray|CsvConversionError bm1cma = fromCsvWithType([bm1, bm1], {}, CustomMapArray); + test:assertEquals(bm1cma, [ + {}, + {} + ]); + + CustomMapArray|CsvConversionError bm2cma = fromCsvWithType([bm2, bm2], {}, CustomMapArray); + test:assertEquals(bm2cma, [ + {}, + {} + ]); + + CustomMapArray|CsvConversionError bm3cma = fromCsvWithType([bm3, bm3], {}, CustomMapArray); + test:assertEquals(bm3cma, [ + {i1: 1}, + {i1: 1} + ]); + + CustomMapArray|CsvConversionError bm4cma = fromCsvWithType([bm4, bm4], {}, CustomMapArray); + test:assertEquals(bm4cma, [ + {}, + {} + ]); + + CustomMapArray|CsvConversionError bm5cma = fromCsvWithType([bm5, bm5], {}, CustomMapArray); + test:assertEquals(bm5cma, [ + {}, + {} + ]); + + StringMapArray|CsvConversionError bm1sma = fromCsvWithType([bm1, bm1], {}, StringMapArray); + test:assertEquals(bm1sma, [ + {}, + {} + ]); + + StringMapArray|CsvConversionError bm2sma = fromCsvWithType([bm2, bm2], {}, StringMapArray); + test:assertEquals(bm2sma, [ + {}, + {} + ]); + + StringMapArray|CsvConversionError bm3sma = fromCsvWithType([bm3, bm3], {}, StringMapArray); + test:assertEquals(bm3sma, [ + {}, + {} + ]); + + StringMapArray|CsvConversionError bm4sma = fromCsvWithType([bm4, bm4], {}, StringMapArray); + test:assertEquals(bm4sma, [ + {}, + {} + ]); + + StringMapArray|CsvConversionError bm5sma = fromCsvWithType([bm5, bm5], {}, StringMapArray); + test:assertEquals(bm5sma, [ + {}, + {} + ]); } -function generateErrorMessageForInvalidFieldType(string value, string 'key) returns string { - return string `no mapping type found for value '${value}' in key '${'key}'`; +@test:Config {enable} +function testFromCsvWithTypeForMapAndArrayAsExpectedType() { + BooleanArrayArray|CsvConversionError bm1ba = fromCsvWithType([bm1, bm1], {}, BooleanArrayArray); + test:assertEquals(bm1ba, [ + [true, false], + [true, false] + ]); + + BooleanArrayArray|CsvConversionError bm2ba = fromCsvWithType([bm2, bm2], {}, BooleanArrayArray); + test:assertTrue(bm2ba is CsvConversionError); + test:assertEquals((bm2ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanArrayArray|CsvConversionError bm3ba = fromCsvWithType([bm3, bm3], {}, BooleanArrayArray); + test:assertTrue(bm3ba is CsvConversionError); + test:assertEquals((bm3ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanArrayArray|CsvConversionError bm4ba = fromCsvWithType([bm4, bm4], {}, BooleanArrayArray); + test:assertTrue(bm4ba is CsvConversionError); + test:assertEquals((bm4ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + + BooleanArrayArray|CsvConversionError bm5ba = fromCsvWithType([bm5, bm5], {}, BooleanArrayArray); + test:assertTrue(bm5ba is CsvConversionError); + test:assertEquals((bm5ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + NillableBooleanArrayArray|CsvConversionError bm1nba = fromCsvWithType([bm1, bm1], {}, NillableBooleanArrayArray); + test:assertEquals(bm1nba, [ + [true, false], + [true, false] + ]); + + NillableBooleanArrayArray|CsvConversionError bm2nba = fromCsvWithType([bm2, bm2], {}, NillableBooleanArrayArray); + test:assertEquals(bm2nba, [ + [true, false, null, null, null], + [true, false, null, null, null] + ]); + + NillableBooleanArrayArray|CsvConversionError bm3nba = fromCsvWithType([bm3, bm3], {}, NillableBooleanArrayArray); + test:assertTrue(bm3nba is CsvConversionError); + test:assertEquals((bm3nba).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); + + NillableBooleanArrayArray|CsvConversionError bm4nba = fromCsvWithType([bm4, bm4], {}, NillableBooleanArrayArray); + test:assertEquals(bm4nba, [ + [(), ()], + [(), ()] + ]); + + NillableBooleanArrayArray|CsvConversionError bm5nba = fromCsvWithType([bm5, bm5], {}, NillableBooleanArrayArray); + test:assertEquals(bm5nba, [ + [true, false, (), true], + [true, false, (), true] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm1niouba = fromCsvWithType([bm1, bm1], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm1niouba, [ + [true, false], + [true, false] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm2niouba = fromCsvWithType([bm2, bm2], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm2niouba, [ + [true, false, null, null, null], + [true, false, null, null, null] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm3niouba = fromCsvWithType([bm3, bm3], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm3niouba, [ + [true, false, null, false, 1], + [true, false, null, false, 1] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm4niouba = fromCsvWithType([bm4, bm4], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm4niouba, [ + [(), ()], + [(), ()] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm5niouba = fromCsvWithType([bm5, bm5], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm5niouba, [ + [true, false, (), true], + [true, false, (), true] + ]); + + JsonArray1Array|CsvConversionError bm1ja = fromCsvWithType([bm1, bm1], {}, JsonArray1Array); + test:assertEquals(bm1ja, [ + [true, false], + [true, false] + ]); + + JsonArray1Array|CsvConversionError bm2ja = fromCsvWithType([bm2, bm2], {}, JsonArray1Array); + test:assertEquals(bm2ja, [ + [true, false, null, null, null], + [true, false, null, null, null] + ]); + + JsonArray1Array|CsvConversionError bm3ja = fromCsvWithType([bm3, bm3], {}, JsonArray1Array); + test:assertEquals(bm3ja, [ + [true, false, null, false, 1], + [true, false, null, false, 1] + ]); + + JsonArray1Array|CsvConversionError bm4ja = fromCsvWithType([bm4, bm4], {}, JsonArray1Array); + test:assertEquals(bm4ja, [ + [(), ()], + [(), ()] + ]); + + JsonArray1Array|CsvConversionError bm5ja = fromCsvWithType([bm5, bm5], {}, JsonArray1Array); + test:assertEquals(bm5ja, [ + [true, false, (), true], + [true, false, (), true] + ]); + + AnydataArray1Array|CsvConversionError bm1anyda = fromCsvWithType([bm1, bm1], {}, AnydataArray1Array); + test:assertEquals(bm1anyda, [ + [true, false], + [true, false] + ]); + + AnydataArray1Array|CsvConversionError bm2anyda = fromCsvWithType([bm2, bm2], {}, AnydataArray1Array); + test:assertEquals(bm2anyda, [ + [true, false, null, null, null], + [true, false, null, null, null] + ]); + + AnydataArray1Array|CsvConversionError bm3anyda = fromCsvWithType([bm3, bm3], {}, AnydataArray1Array); + test:assertEquals(bm3anyda, [ + [true, false, null, false, 1], + [true, false, null, false, 1] + ]); + + AnydataArray1Array|CsvConversionError bm4anyda = fromCsvWithType([bm4, bm4], {}, AnydataArray1Array); + test:assertEquals(bm4anyda, [ + [(), ()], + [(), ()] + ]); + + AnydataArray1Array|CsvConversionError bm5anyda = fromCsvWithType([bm5, bm5], {}, AnydataArray1Array); + test:assertEquals(bm5anyda, [ + [true, false, (), true], + [true, false, (), true] + ]); + + StringArray1Array|CsvConversionError bm1sa = fromCsvWithType([bm1, bm1], {}, StringArray1Array); + test:assertTrue(bm1sa is CsvConversionError); + test:assertEquals((bm1sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringArray1Array|CsvConversionError bm2sa = fromCsvWithType([bm2, bm2], {}, StringArray1Array); + test:assertTrue(bm2sa is CsvConversionError); + test:assertEquals((bm2sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringArray1Array|CsvConversionError bm3sa = fromCsvWithType([bm3, bm3], {}, StringArray1Array); + test:assertTrue(bm3sa is CsvConversionError); + test:assertEquals((bm3sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringArray1Array|CsvConversionError bm4sa = fromCsvWithType([bm4, bm4], {}, StringArray1Array); + test:assertTrue(bm4sa is CsvConversionError); + test:assertEquals((bm4sa).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); + + StringArray1Array|CsvConversionError bm5sa = fromCsvWithType([bm5, bm5], {}, StringArray1Array); + test:assertTrue(bm5sa is CsvConversionError); + test:assertEquals((bm5sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } -// @test:Config -// function testFromCsvWithTypeForRecordAndArrayAsExpextedType() { +@test:Config {enable} +function testFromCsvWithTypeForMapAndTupleAsExpectedType() { + BooleanTuple1Array|CsvConversionError bm1bt = fromCsvWithType([bm1, bm1], {}, BooleanTuple1Array); + test:assertEquals(bm1bt, [ + [true, false, false, false], + [true, false, false, false] + ]); + + BooleanTuple1Array|CsvConversionError bm2bt = fromCsvWithType([bm2, bm2], {}, BooleanTuple1Array); + test:assertTrue(bm2bt is CsvConversionError); + test:assertEquals((bm2bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple1Array|CsvConversionError bm3bt = fromCsvWithType([bm3, bm3], {}, BooleanTuple1Array); + test:assertTrue(bm3bt is CsvConversionError); + test:assertEquals((bm3bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple1Array|CsvConversionError bm4bt = fromCsvWithType([bm4, bm4], {}, BooleanTuple1Array); + test:assertTrue(bm4bt is CsvConversionError); + test:assertEquals((bm4bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + + BooleanTuple1Array|CsvConversionError bm5bt = fromCsvWithType([bm5, bm5], {}, BooleanTuple1Array); + test:assertTrue(bm5bt is CsvConversionError); + test:assertEquals((bm5bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple2Array|CsvConversionError bm1b2t = fromCsvWithType([bm1, bm1], {}, BooleanTuple2Array); + test:assertEquals(bm1b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|CsvConversionError bm2b2t = fromCsvWithType([bm2, bm2], {}, BooleanTuple2Array); + test:assertEquals(bm2b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|CsvConversionError bm3b2t = fromCsvWithType([bm3, bm3], {}, BooleanTuple2Array); + test:assertEquals(bm3b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|CsvConversionError bm4b2t = fromCsvWithType([bm4, bm4], {}, BooleanTuple2Array); + test:assertTrue(bm4b2t is CsvConversionError); + test:assertEquals((bm4b2t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + + BooleanTuple2Array|CsvConversionError bm5b2t = fromCsvWithType([bm5, bm5], {}, BooleanTuple2Array); + test:assertEquals(bm5b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple3Array|CsvConversionError bm1b3t = fromCsvWithType([bm1, bm1], {}, BooleanTuple3Array); + test:assertEquals(bm1b3t, [ + [true, false], + [true, false] + ]); + + BooleanTuple3Array|CsvConversionError bm2b3t = fromCsvWithType([bm2, bm2], {}, BooleanTuple3Array); + test:assertTrue(bm2b3t is CsvConversionError); + test:assertEquals((bm2b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple3Array|CsvConversionError bm3b3t = fromCsvWithType([bm3, bm3], {}, BooleanTuple3Array); + test:assertTrue(bm3b3t is CsvConversionError); + test:assertEquals((bm3b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple3Array|CsvConversionError bm4b3t = fromCsvWithType([bm4, bm4], {}, BooleanTuple3Array); + test:assertTrue(bm4b3t is CsvConversionError); + test:assertEquals((bm4b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + + BooleanTuple3Array|CsvConversionError bm5b3t = fromCsvWithType([bm5, bm5], {}, BooleanTuple3Array); + test:assertTrue(bm5b3t is CsvConversionError); + test:assertEquals((bm5b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple4Array|CsvConversionError bm1b4t = fromCsvWithType([bm1, bm1], {}, BooleanTuple4Array); + test:assertEquals(bm1b4t, [ + [true, false], + [true, false] + ]); + + BooleanTuple4Array|CsvConversionError bm2b4t = fromCsvWithType([bm2, bm2], {}, BooleanTuple4Array); + test:assertTrue(bm2b4t is CsvConversionError); + test:assertEquals((bm2b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple4Array|CsvConversionError bm3b4t = fromCsvWithType([bm3, bm3], {}, BooleanTuple4Array); + test:assertTrue(bm3b4t is CsvConversionError); + test:assertEquals((bm3b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple4Array|CsvConversionError bm4b4t = fromCsvWithType([bm4, bm4], {}, BooleanTuple4Array); + test:assertTrue(bm4b4t is CsvConversionError); + test:assertEquals((bm4b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + + BooleanTuple4Array|CsvConversionError bm5b4t = fromCsvWithType([bm5, bm5], {}, BooleanTuple4Array); + test:assertTrue(bm5b4t is CsvConversionError); + test:assertEquals((bm5b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); -// } + NillableBooleanTuple5Array|CsvConversionError bm1nbt = fromCsvWithType([bm1, bm1], {}, NillableBooleanTuple5Array); + test:assertEquals(bm1nbt, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); -// @test:Config -// function testFromCsvWithTypeForRecordAndTupleAsExpextedType() { + NillableBooleanTuple5Array|CsvConversionError bm2nbt = fromCsvWithType([bm2, bm2], {}, NillableBooleanTuple5Array); + test:assertEquals(bm2nbt, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); -// } + NillableBooleanTuple5Array|CsvConversionError bm3nbt = fromCsvWithType([bm3, bm3], {}, NillableBooleanTuple5Array); + test:assertTrue(bm3nbt is CsvConversionError); + test:assertEquals((bm3nbt).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); -// @test:Config -// function testFromCsvWithTypeForArrayAndMapAsExpextedType() { + NillableBooleanTuple5Array|CsvConversionError bm4nbt = fromCsvWithType([bm4, bm4], {}, NillableBooleanTuple5Array); + test:assertEquals(bm4nbt, [ + [(), (), (), (), ()], + [(), (), (), (), ()] + ]); -// } + NillableBooleanTuple5Array|CsvConversionError bm5nbt = fromCsvWithType([bm5, bm5], {}, NillableBooleanTuple5Array); + test:assertEquals(bm5nbt, [ + [true, false, (), true, ()], + [true, false, (), true, ()] + ]); -// @test:Config -// function testFromCsvWithTypeForArrayAndRecordAsExpextedType() { + NillableBooleanTuple6Array|CsvConversionError bm1nb6t = fromCsvWithType([bm1, bm1], {}, NillableBooleanTuple6Array); + test:assertEquals(bm1nb6t, [ + [true, false], + [true, false] + ]); -// } + NillableBooleanTuple6Array|CsvConversionError bm2nb6t = fromCsvWithType([bm2, bm2], {}, NillableBooleanTuple6Array); + test:assertEquals(bm2nb6t, [ + [true, false], + [true, false] + ]); -// @test:Config -// function testFromCsvWithTypeForArrayAndArrayAsExpextedType() { + NillableBooleanTuple6Array|CsvConversionError bm3nb6t = fromCsvWithType([bm3, bm3], {}, NillableBooleanTuple6Array); + test:assertEquals(bm3nb6t, [ + [true, false], + [true, false] + ]); -// } + NillableBooleanTuple6Array|CsvConversionError bm4nb6t = fromCsvWithType([bm4, bm4], {}, NillableBooleanTuple6Array); + test:assertEquals(bm4nb6t, [ + [(), ()], + [(), ()] + ]); -// @test:Config -// function testFromCsvWithTypeForArrayAndTupleAsExpextedType() { + NillableBooleanTuple6Array|CsvConversionError bm5nb6t = fromCsvWithType([bm5, bm5], {}, NillableBooleanTuple6Array); + test:assertEquals(bm5nb6t, [ + [true, false], + [true, false] + ]); -// } + NillableBooleanTuple7Array|CsvConversionError bm1nb7t = fromCsvWithType([bm1, bm1], {}, NillableBooleanTuple7Array); + test:assertEquals(bm1nb7t, [ + [true, false], + [true, false] + ]); -// @test:Config -// function testFromCsvWithTypeForTupleAndMapAsExpextedType() { + NillableBooleanTuple7Array|CsvConversionError bm2nb7t = fromCsvWithType([bm2, bm2], {}, NillableBooleanTuple7Array); + test:assertEquals(bm2nb7t, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); -// } + NillableBooleanTuple7Array|CsvConversionError bm3nb7t = fromCsvWithType([bm3, bm3], {}, NillableBooleanTuple7Array); + test:assertTrue(bm3nb7t is CsvConversionError); + test:assertEquals((bm3nb7t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); -// @test:Config -// function testFromCsvWithTypeForTupleAndRecordAsExpextedType() { + NillableBooleanTuple7Array|CsvConversionError bm4nb7t = fromCsvWithType([bm4, bm4], {}, NillableBooleanTuple7Array); + test:assertEquals(bm4nb7t, [ + [(), ()], + [(), ()] + ]); -// } + NillableBooleanTuple7Array|CsvConversionError bm5nb7t = fromCsvWithType([bm5, bm5], {}, NillableBooleanTuple7Array); + test:assertEquals(bm5nb7t, [ + [true, false, (), true], + [true, false, (), true] + ]); -// @test:Config -// function testFromCsvWithTypeForTupleAndArrayAsExpextedType() { + NillableBooleanTuple8Array|CsvConversionError bm1nb8t = fromCsvWithType([bm1, bm1], {}, NillableBooleanTuple8Array); + test:assertEquals(bm1nb8t, [ + [true, false], + [true, false] + ]); -// } + NillableBooleanTuple8Array|CsvConversionError bm2nb8t = fromCsvWithType([bm2, bm2], {}, NillableBooleanTuple8Array); + test:assertEquals(bm2nb8t, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); -// @test:Config -// function testFromCsvWithTypeForTupleAndTupleAsExpextedType() { + NillableBooleanTuple8Array|CsvConversionError bm3nb8t = fromCsvWithType([bm3, bm3], {}, NillableBooleanTuple8Array); + test:assertTrue(bm3nb8t is CsvConversionError); + test:assertEquals((bm3nb8t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); -// } + NillableBooleanTuple8Array|CsvConversionError bm4nb8t = fromCsvWithType([bm4, bm4], {}, NillableBooleanTuple8Array); + test:assertEquals(bm4nb8t, [ + [(), ()], + [(), ()] + ]); + + NillableBooleanTuple8Array|CsvConversionError bm5nb8t = fromCsvWithType([bm5, bm5], {}, NillableBooleanTuple8Array); + test:assertEquals(bm5nb8t, [ + [true, false, (), true], + [true, false, (), true] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError bm1nb9t = fromCsvWithType([bm1, bm1], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm1nb9t, [ + [true, false], + [true, false] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError bm2nb9t = fromCsvWithType([bm2, bm2], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm2nb9t, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError bm3nb9t = fromCsvWithType([bm3, bm3], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm3nb9t, [ + [true, false, (), false, 1], + [true, false, (), false, 1] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError bm4nb9t = fromCsvWithType([bm4, bm4], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm4nb9t, [ + [(), ()], + [(), ()] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError bm5nb9t = fromCsvWithType([bm5, bm5], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm5nb9t, [ + [true, false, (), true], + [true, false, (), true] + ]); + + NilTuple3Array|CsvConversionError bm1n3t = fromCsvWithType([bm1, bm1], {}, NilTuple3Array); + test:assertTrue(bm1n3t is CsvConversionError); + test:assertEquals((bm1n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + + NilTuple3Array|CsvConversionError bm2n3t = fromCsvWithType([bm2, bm2], {}, NilTuple3Array); + test:assertTrue(bm2n3t is CsvConversionError); + test:assertEquals((bm2n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + + NilTuple3Array|CsvConversionError bm3n3t = fromCsvWithType([bm3, bm3], {}, NilTuple3Array); + test:assertTrue(bm3n3t is CsvConversionError); + test:assertEquals((bm3n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + + NilTuple3Array|CsvConversionError bm4n3t = fromCsvWithType([bm4, bm4], {}, NilTuple3Array); + test:assertEquals(bm4n3t, [ + [(), ()], + [(), ()] + ]); + + NilTuple3Array|CsvConversionError bm5n3t = fromCsvWithType([bm5, bm5], {}, NilTuple3Array); + test:assertTrue(bm5n3t is CsvConversionError); + test:assertEquals((bm5n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + + AnydataTuple3Array|CsvConversionError bm1anyd3t = fromCsvWithType([bm1, bm1], {}, AnydataTuple3Array); + test:assertEquals(bm1anyd3t, [ + [true, false], + [true, false] + ]); + + AnydataTuple3Array|CsvConversionError bm2anyd3t = fromCsvWithType([bm2, bm2], {}, AnydataTuple3Array); + test:assertEquals(bm2anyd3t, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + AnydataTuple3Array|CsvConversionError bm3anyd3t = fromCsvWithType([bm3, bm3], {}, AnydataTuple3Array); + test:assertEquals(bm3anyd3t, [ + [true, false, (), false, 1], + [true, false, (), false, 1] + ]); + + AnydataTuple3Array|CsvConversionError bm4anyd3t = fromCsvWithType([bm4, bm4], {}, AnydataTuple3Array); + test:assertEquals(bm4anyd3t, [ + [(), ()], + [(), ()] + ]); + + AnydataTuple3Array|CsvConversionError bm5anyd3t = fromCsvWithType([bm5, bm5], {}, AnydataTuple3Array); + test:assertEquals(bm5anyd3t, [ + [true, false, (), true], + [true, false, (), true] + ]); + + JsonTuple3Array|CsvConversionError bm1j3t = fromCsvWithType([bm1, bm1], {}, JsonTuple3Array); + test:assertEquals(bm1j3t, [ + [true, false], + [true, false] + ]); + + JsonTuple3Array|CsvConversionError bm2j3t = fromCsvWithType([bm2, bm2], {}, JsonTuple3Array); + test:assertEquals(bm2j3t, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + JsonTuple3Array|CsvConversionError bm3j3t = fromCsvWithType([bm3, bm3], {}, JsonTuple3Array); + test:assertEquals(bm3j3t, [ + [true, false, (), false, 1], + [true, false, (), false, 1] + ]); + + JsonTuple3Array|CsvConversionError bm4j3t = fromCsvWithType([bm4, bm4], {}, JsonTuple3Array); + test:assertEquals(bm4j3t, [ + [(), ()], + [(), ()] + ]); + + JsonTuple3Array|CsvConversionError bm5j3t = fromCsvWithType([bm5, bm5], {}, JsonTuple3Array); + test:assertEquals(bm5j3t, [ + [true, false, (), true], + [true, false, (), true] + ]); + + StringTuple3Array|CsvConversionError bm1s3t = fromCsvWithType([bm1, bm1], {}, StringTuple3Array); + test:assertTrue(bm1s3t is CsvConversionError); + test:assertEquals((bm1s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringTuple3Array|CsvConversionError bm2s3t = fromCsvWithType([bm2, bm2], {}, StringTuple3Array); + test:assertTrue(bm2s3t is CsvConversionError); + test:assertEquals((bm2s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringTuple3Array|CsvConversionError bm3s3t = fromCsvWithType([bm3, bm3], {}, StringTuple3Array); + test:assertTrue(bm3s3t is CsvConversionError); + test:assertEquals((bm3s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringTuple3Array|CsvConversionError bm4s3t = fromCsvWithType([bm4, bm4], {}, StringTuple3Array); + test:assertTrue(bm4s3t is CsvConversionError); + test:assertEquals((bm4s3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); + + StringTuple3Array|CsvConversionError bm5s3t = fromCsvWithType([bm5, bm5], {}, StringTuple3Array); + test:assertTrue(bm5s3t is CsvConversionError); + test:assertEquals((bm5s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); +} + +@test:Config {enable} +function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { + StringRecord1Array|CsvConversionError st1sr1 = fromCsvWithType([st1, st1], {}, StringRecord1Array); + test:assertTrue(st1sr1 is CsvConversionError); + test:assertEquals((st1sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + + StringRecord1Array|CsvConversionError st2sr1 = fromCsvWithType([st2, st2], {}, StringRecord1Array); + test:assertTrue(st2sr1 is CsvConversionError); + test:assertEquals((st2sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + + StringRecord2Array|CsvConversionError st1sr2 = fromCsvWithType([st1, st1], {}, StringRecord2Array); + test:assertTrue(st1sr2 is CsvConversionError); + test:assertEquals((st1sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); + + StringRecord2Array|CsvConversionError st2sr2 = fromCsvWithType([st2, st2], {}, StringRecord2Array); + test:assertTrue(st2sr2 is CsvConversionError); + test:assertEquals((st2sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); + + StringRecord9Array|CsvConversionError st1sr9 = fromCsvWithType([st1, st1], {}, StringRecord9Array); + test:assertTrue(st1sr9 is CsvConversionError); + test:assertEquals((st1sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord9")); + + StringRecord9Array|CsvConversionError st2sr9 = fromCsvWithType([st2, st2], {}, StringRecord9Array); + test:assertTrue(st2sr9 is CsvConversionError); + test:assertEquals((st2sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord9")); + + StringRecord10Array|CsvConversionError st1sr10 = fromCsvWithType([st1, st1], {}, StringRecord10Array); + test:assertEquals(st1sr10, [ + {'1: "string", '2: ""}, + {'1: "string", '2: ""} + ]); + + StringRecord10Array|CsvConversionError st2sr10 = fromCsvWithType([st2, st2], {}, StringRecord10Array); + test:assertEquals(st2sr10, [ + {'1: "string", '2: "", '3: "a", '4: ""}, + {'1: "string", '2: "", '3: "a", '4: ""} + ]); + + StringRecord19Array|CsvConversionError st1sr19 = fromCsvWithType([st1, st1], {}, StringRecord19Array); + test:assertEquals(st1sr19, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord19Array|CsvConversionError st2sr19 = fromCsvWithType([st2, st2], {}, StringRecord19Array); + test:assertEquals(st2sr19, [ + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord20Array|CsvConversionError st1sr20 = fromCsvWithType([st1, st1], {}, StringRecord20Array); + test:assertEquals(st1sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord20Array|CsvConversionError st2sr20 = fromCsvWithType([st2, st2], {}, StringRecord20Array); + test:assertEquals(st2sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord21Array|CsvConversionError st1sr21 = fromCsvWithType([st1, st1], {}, StringRecord21Array); + test:assertEquals(st1sr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord21Array|CsvConversionError st2sr21 = fromCsvWithType([st2, st2], {}, StringRecord21Array); + test:assertEquals(st2sr21, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord22Array|CsvConversionError st1sr22 = fromCsvWithType([st1, st1], {}, StringRecord22Array); + test:assertEquals(st1sr22, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord22Array|CsvConversionError st2sr22 = fromCsvWithType([st2, st2], {}, StringRecord22Array); + test:assertEquals(st2sr22, [ + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord23Array|CsvConversionError st1sr23 = fromCsvWithType([st1, st1], {}, StringRecord23Array); + test:assertEquals(st1sr23, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord23Array|CsvConversionError st2sr23 = fromCsvWithType([st2, st2], {}, StringRecord23Array); + test:assertEquals(st2sr23, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord15Array|CsvConversionError st1cr15 = fromCsvWithType([st1, st1], {}, CustomRecord15Array); + test:assertEquals(st1cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord15Array|CsvConversionError st2cr15 = fromCsvWithType([st2, st2], {}, CustomRecord15Array); + test:assertEquals(st2cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord16Array|CsvConversionError st1cr16 = fromCsvWithType([st1, st1], {}, CustomRecord16Array); + test:assertTrue(st1cr16 is CsvConversionError); + test:assertEquals((st1cr16).message(), generateErrorMessageForMissingRequiredField("3")); + + CustomRecord16Array|CsvConversionError st2cr16 = fromCsvWithType([st2, st2], {}, CustomRecord16Array); + test:assertEquals(st2cr16, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord17Array|CsvConversionError st1cr17 = fromCsvWithType([st1, st1], {}, CustomRecord17Array); + test:assertEquals(st1cr17, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord17Array|CsvConversionError st2cr17 = fromCsvWithType([st2, st2], {}, CustomRecord17Array); + test:assertEquals(st2cr17, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord18Array|CsvConversionError st1cr18 = fromCsvWithType([st1, st1], {}, CustomRecord18Array); + test:assertTrue(st1cr18 is CsvConversionError); + test:assertEquals((st1cr18).message(), generateErrorMessageForMissingRequiredField("3")); + + CustomRecord18Array|CsvConversionError st2cr18 = fromCsvWithType([st2, st2], {}, CustomRecord18Array); + test:assertEquals(st2cr18, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord19Array|CsvConversionError st1cr19 = fromCsvWithType([st1, st1], {}, CustomRecord19Array); + test:assertEquals(st1cr19, [ + {'1: s1, '2: s2, '3: "", '4: ""}, + {'1: s1, '2: s2, '3: "", '4: ""} + ]); + + CustomRecord19Array|CsvConversionError st2cr19 = fromCsvWithType([st2, st2], {}, CustomRecord19Array); + test:assertEquals(st2cr19, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord20Array|CsvConversionError st1cr20 = fromCsvWithType([st1, st1], {}, CustomRecord20Array); + test:assertEquals(st1cr20, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord20Array|CsvConversionError st2cr20 = fromCsvWithType([st2, st2], {}, CustomRecord20Array); + test:assertEquals(st2cr20, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord21Array|CsvConversionError st1cr21 = fromCsvWithType([st1, st1], {}, CustomRecord21Array); + test:assertEquals(st1cr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord21Array|CsvConversionError st2cr21 = fromCsvWithType([st2, st2], {}, CustomRecord21Array); + test:assertEquals(st2cr21, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord22Array|CsvConversionError st1cr22 = fromCsvWithType([st1, st1], {}, CustomRecord22Array); + test:assertEquals(st1cr22, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord22Array|CsvConversionError st2cr22 = fromCsvWithType([st2, st2], {}, CustomRecord22Array); + test:assertEquals(st2cr22, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord23Array|CsvConversionError st1cr23 = fromCsvWithType([st1, st1], {}, CustomRecord23Array); + test:assertEquals(st1cr23, [ + {"1": s1, "2": s2, a: ""}, + {"1": s1, "2": s2, a: ""} + ]); + + CustomRecord23Array|CsvConversionError st2cr23 = fromCsvWithType([st2, st2], {}, CustomRecord23Array); + test:assertEquals(st2cr23, [ + {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, + {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} + ]); + + CustomRecord24Array|CsvConversionError st1cr24 = fromCsvWithType([st1, st1], {}, CustomRecord24Array); + test:assertEquals(st1cr24, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord24Array|CsvConversionError st2cr24 = fromCsvWithType([st2, st2], {}, CustomRecord24Array); + test:assertEquals(st2cr24, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord25Array|CsvConversionError st1cr25 = fromCsvWithType([st1, st1], {}, CustomRecord25Array); + test:assertTrue(st1cr25 is CsvConversionError); + test:assertEquals((st1cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:CustomRecord25")); + + CustomRecord25Array|CsvConversionError st2cr25 = fromCsvWithType([st2, st2], {}, CustomRecord25Array); + test:assertTrue(st2cr25 is CsvConversionError); + test:assertEquals((st2cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:CustomRecord25")); + + CustomRecord25Array|CsvConversionError st3cr25 = fromCsvWithType([st3, st3], {}, CustomRecord25Array); + test:assertTrue(st3cr25 is CsvConversionError); + test:assertEquals((st3cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:CustomRecord25")); + + CustomRecord25Array|CsvConversionError st4cr25 = fromCsvWithType([st4, st4], {}, CustomRecord25Array); + test:assertTrue(st4cr25 is CsvConversionError); + test:assertEquals((st4cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:CustomRecord25")); + + CustomRecord26Array|CsvConversionError st1cr26 = fromCsvWithType([st1, st1], {}, CustomRecord26Array); + test:assertEquals(st1cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|CsvConversionError st2cr26 = fromCsvWithType([st2, st2], {}, CustomRecord26Array); + test:assertEquals(st2cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|CsvConversionError st3cr26 = fromCsvWithType([st3, st3], {}, CustomRecord26Array); + test:assertEquals(st3cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|CsvConversionError st4cr26 = fromCsvWithType([st4, st4], {}, CustomRecord26Array); + test:assertEquals(st4cr26 , [ + {'1: s1}, + {'1: s1} + ]); +} + +@test:Config {enable} +function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { + StringRecord1Array|CsvConversionError st3sr1 = fromCsvWithType([st3, st3], {}, StringRecord1Array); + test:assertTrue(st3sr1 is CsvConversionError); + test:assertEquals((st3sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + + StringRecord1Array|CsvConversionError st4sr1 = fromCsvWithType([st4, st4], {}, StringRecord1Array); + test:assertTrue(st4sr1 is CsvConversionError); + test:assertEquals((st4sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + + StringRecord2Array|CsvConversionError st3sr2 = fromCsvWithType([st3, st3], {}, StringRecord2Array); + test:assertTrue(st3sr2 is CsvConversionError); + test:assertEquals((st3sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); + + StringRecord2Array|CsvConversionError st4sr2 = fromCsvWithType([st4, st4], {}, StringRecord2Array); + test:assertTrue(st4sr2 is CsvConversionError); + test:assertEquals((st4sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); + + StringRecord9Array|CsvConversionError st3sr9 = fromCsvWithType([st3, st3], {}, StringRecord9Array); + test:assertTrue(st3sr9 is CsvConversionError); + test:assertEquals((st3sr9).message(), generateErrorMessageForMissingRequiredField("s1")); + + StringRecord9Array|CsvConversionError st4sr9 = fromCsvWithType([st4, st4], {}, StringRecord9Array); + test:assertTrue(st4sr9 is CsvConversionError); + test:assertEquals((st4sr9).message(), generateErrorMessageForMissingRequiredField("s1")); + + StringRecord10Array|CsvConversionError st3sr10 = fromCsvWithType([st3, st3], {}, StringRecord10Array); + test:assertEquals(st3sr10, [ + {'1: "string", '2: ""}, + {'1: "string", '2: ""} + ]); + + StringRecord10Array|CsvConversionError st4sr10 = fromCsvWithType([st4, st4], {}, StringRecord10Array); + test:assertEquals(st4sr10, [ + {'1: "string", '2: "", '3: "a", '4: ""}, + {'1: "string", '2: "", '3: "a", '4: ""} + ]); + + StringRecord19Array|CsvConversionError st3sr19 = fromCsvWithType([st3, st3], {}, StringRecord19Array); + test:assertEquals(st3sr19, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord19Array|CsvConversionError st4sr19 = fromCsvWithType([st4, st4], {}, StringRecord19Array); + test:assertEquals(st4sr19, [ + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord20Array|CsvConversionError st3sr20 = fromCsvWithType([st3, st3], {}, StringRecord20Array); + test:assertEquals(st3sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord20Array|CsvConversionError st4sr20 = fromCsvWithType([st4, st4], {}, StringRecord20Array); + test:assertEquals(st4sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord21Array|CsvConversionError st3sr21 = fromCsvWithType([st3, st3], {}, StringRecord21Array); + test:assertEquals(st3sr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord21Array|CsvConversionError st4sr21 = fromCsvWithType([st4, st4], {}, StringRecord21Array); + test:assertEquals(st4sr21, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord22Array|CsvConversionError st3sr22 = fromCsvWithType([st3, st3], {}, StringRecord22Array); + test:assertEquals(st3sr22, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord22Array|CsvConversionError st4sr22 = fromCsvWithType([st4, st4], {}, StringRecord22Array); + test:assertEquals(st4sr22, [ + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord23Array|CsvConversionError st3sr23 = fromCsvWithType([st3, st3], {}, StringRecord23Array); + test:assertEquals(st3sr23, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord23Array|CsvConversionError st4sr23 = fromCsvWithType([st4, st4], {}, StringRecord23Array); + test:assertEquals(st4sr23, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord15Array|CsvConversionError st3cr15 = fromCsvWithType([st3, st3], {}, CustomRecord15Array); + test:assertEquals(st3cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord15Array|CsvConversionError st4cr15 = fromCsvWithType([st4, st4], {}, CustomRecord15Array); + test:assertEquals(st4cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord16Array|CsvConversionError st3cr16 = fromCsvWithType([st3, st3], {}, CustomRecord16Array); + test:assertTrue(st3cr16 is CsvConversionError); + test:assertEquals((st3cr16).message(), generateErrorMessageForMissingRequiredField("3")); + + CustomRecord16Array|CsvConversionError st4cr16 = fromCsvWithType([st4, st4], {}, CustomRecord16Array); + test:assertEquals(st4cr16, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord17Array|CsvConversionError st3cr17 = fromCsvWithType([st3, st3], {}, CustomRecord17Array); + test:assertEquals(st3cr17, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord17Array|CsvConversionError st4cr17 = fromCsvWithType([st4, st4], {}, CustomRecord17Array); + test:assertEquals(st4cr17, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord18Array|CsvConversionError st3cr18 = fromCsvWithType([st3, st3], {}, CustomRecord18Array); + test:assertTrue(st3cr18 is CsvConversionError); + test:assertEquals((st3cr18).message(), generateErrorMessageForMissingRequiredField("3")); + + CustomRecord18Array|CsvConversionError st4cr18 = fromCsvWithType([st4, st4], {}, CustomRecord18Array); + test:assertEquals(st4cr18, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord19Array|CsvConversionError st3cr19 = fromCsvWithType([st3, st3], {}, CustomRecord19Array); + test:assertEquals(st3cr19, [ + {'1: s1, '2: s2, '3: "", '4: ""}, + {'1: s1, '2: s2, '3: "", '4: ""} + ]); + + CustomRecord19Array|CsvConversionError st4cr19 = fromCsvWithType([st4, st4], {}, CustomRecord19Array); + test:assertEquals(st4cr19, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord20Array|CsvConversionError st3cr20 = fromCsvWithType([st3, st3], {}, CustomRecord20Array); + test:assertEquals(st3cr20, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord20Array|CsvConversionError st4cr20 = fromCsvWithType([st4, st4], {}, CustomRecord20Array); + test:assertEquals(st4cr20, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord21Array|CsvConversionError st3cr21 = fromCsvWithType([st3, st3], {}, CustomRecord21Array); + test:assertEquals(st3cr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord21Array|CsvConversionError st4cr21 = fromCsvWithType([st4, st4], {}, CustomRecord21Array); + test:assertEquals(st4cr21, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord22Array|CsvConversionError st3cr22 = fromCsvWithType([st3, st3], {}, CustomRecord22Array); + test:assertEquals(st3cr22, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord22Array|CsvConversionError st4cr22 = fromCsvWithType([st4, st4], {}, CustomRecord22Array); + test:assertEquals(st4cr22, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord23Array|CsvConversionError st3cr23 = fromCsvWithType([st3, st3], {}, CustomRecord23Array); + test:assertEquals(st3cr23, [ + {"1": s1, "2": s2, a: ""}, + {"1": s1, "2": s2, a: ""} + ]); + + CustomRecord23Array|CsvConversionError st4cr23 = fromCsvWithType([st4, st4], {}, CustomRecord23Array); + test:assertEquals(st4cr23, [ + {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, + {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} + ]); + + CustomRecord24Array|CsvConversionError st3cr24 = fromCsvWithType([st3, st3], {}, CustomRecord24Array); + test:assertEquals(st3cr24, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord24Array|CsvConversionError st4cr24 = fromCsvWithType([st4, st4], {}, CustomRecord24Array); + test:assertEquals(st4cr24, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); +} + +@test:Config {enable} +function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { + StringTuple1Array|CsvConversionError st1st1 = fromCsvWithType([st1, st1], {}, StringTuple1Array); + test:assertEquals(st1st1, [ + [s1, s2, "", ""], + [s1, s2, "", ""] + ]); + + StringTuple1Array|CsvConversionError st2st1 = fromCsvWithType([st2, st2], {}, StringTuple1Array); + test:assertEquals(st2st1, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + StringTuple1Array|CsvConversionError st3st1 = fromCsvWithType([st3, st3], {}, StringTuple1Array); + test:assertEquals(st3st1, [ + [s1, s2, "", ""], + [s1, s2, "", ""] + ]); + + StringTuple1Array|CsvConversionError st4st1 = fromCsvWithType([st4, st4], {}, StringTuple1Array); + test:assertEquals(st4st1, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple2Array|CsvConversionError st1st2 = fromCsvWithType([st1, st1], {}, StringTuple2Array); + test:assertEquals(st1st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple2Array|CsvConversionError st2st2 = fromCsvWithType([st2, st2], {}, StringTuple2Array); + test:assertEquals(st2st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple2Array|CsvConversionError st3st2 = fromCsvWithType([st3, st3], {}, StringTuple2Array); + test:assertEquals(st3st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple2Array|CsvConversionError st4st2 = fromCsvWithType([st4, st4], {}, StringTuple2Array); + test:assertEquals(st4st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple3Array|CsvConversionError st1st3 = fromCsvWithType([st1, st1], {}, StringTuple3Array); + test:assertEquals(st1st3, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple3Array|CsvConversionError st2st3 = fromCsvWithType([st2, st2], {}, StringTuple3Array); + test:assertEquals(st2st3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple3Array|CsvConversionError st3st3 = fromCsvWithType([st3, st3], {}, StringTuple3Array); + test:assertEquals(st3st3, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple3Array|CsvConversionError st4st3 = fromCsvWithType([st4, st4], {}, StringTuple3Array); + test:assertEquals(st4st3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple4Array|CsvConversionError st1st4 = fromCsvWithType([st1, st1], {}, StringTuple4Array); + test:assertEquals(st1st4, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple4Array|CsvConversionError st2st4 = fromCsvWithType([st2, st2], {}, StringTuple4Array); + test:assertEquals(st2st4, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple4Array|CsvConversionError st3st4 = fromCsvWithType([st3, st3], {}, StringTuple4Array); + test:assertEquals(st3st4, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple4Array|CsvConversionError st4st4 = fromCsvWithType([st4, st4], {}, StringTuple4Array); + test:assertEquals(st4st4, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataTuple3Array|CsvConversionError st1anydt3 = fromCsvWithType([st1, st1], {}, AnydataTuple3Array); + test:assertEquals(st1anydt3, [ + [s1, s2], + [s1, s2] + ]); + + AnydataTuple3Array|CsvConversionError st2anydt3 = fromCsvWithType([st2, st2], {}, AnydataTuple3Array); + test:assertEquals(st2anydt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataTuple3Array|CsvConversionError st3anydt3 = fromCsvWithType([st3, st3], {}, AnydataTuple3Array); + test:assertEquals(st3anydt3, [ + [s1, s2], + [s1, s2] + ]); + + AnydataTuple3Array|CsvConversionError st4anydt3 = fromCsvWithType([st4, st4], {}, AnydataTuple3Array); + test:assertEquals(st4anydt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + JsonTuple3Array|CsvConversionError st1jt3 = fromCsvWithType([st1, st1], {}, JsonTuple3Array); + test:assertEquals(st1jt3, [ + [s1, s2], + [s1, s2] + ]); + + JsonTuple3Array|CsvConversionError st2jt3 = fromCsvWithType([st2, st2], {}, JsonTuple3Array); + test:assertEquals(st2jt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + JsonTuple3Array|CsvConversionError st3jt3 = fromCsvWithType([st3, st3], {}, JsonTuple3Array); + test:assertEquals(st3jt3, [ + [s1, s2], + [s1, s2] + ]); + + JsonTuple3Array|CsvConversionError st4jt3 = fromCsvWithType([st4, st4], {}, JsonTuple3Array); + test:assertEquals(st4jt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + DecimalTuple4Array|CsvConversionError st1dta = fromCsvWithType([st1, st1], {}, DecimalTuple4Array); + test:assertTrue(st1dta is CsvConversionError); + test:assertEquals((st1dta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); + + IntegerTuple3Array|CsvConversionError st2bta = fromCsvWithType([st2, st2], {}, IntegerTuple3Array); + test:assertTrue(st2bta is CsvConversionError); + test:assertEquals((st2bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "int")); + + NilTuple3Array|CsvConversionError st3nta = fromCsvWithType([st3, st3], {}, NilTuple3Array); + test:assertTrue(st3nta is CsvConversionError); + test:assertEquals((st3nta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "()")); + + BooleanTuple4Array|CsvConversionError st4bta = fromCsvWithType([st4, st4], {}, BooleanTuple4Array); + test:assertTrue(st4bta is CsvConversionError); + test:assertEquals((st4bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); +} + +@test:Config {enable} +function testFromCsvWithTypeForTupleAndMapAsExpectedType() { + StringMapArray|CsvConversionError st1sma = fromCsvWithType([st1, st1], {}, StringMapArray); + test:assertEquals(st1sma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + StringMapArray|CsvConversionError st2sma = fromCsvWithType([st2, st2], {}, StringMapArray); + test:assertEquals(st2sma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringMapArray|CsvConversionError st3sma = fromCsvWithType([st3, st3], {}, StringMapArray); + test:assertEquals(st3sma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + StringMapArray|CsvConversionError st4sma = fromCsvWithType([st4, st4], {}, StringMapArray); + test:assertEquals(st4sma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + NillableIntUnionStringMapArray|CsvConversionError st1niusma = fromCsvWithType([st1, st1], {}, NillableIntUnionStringMapArray); + test:assertEquals(st1niusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + NillableIntUnionStringMapArray|CsvConversionError st2niusma = fromCsvWithType([st2, st2], {}, NillableIntUnionStringMapArray); + test:assertEquals(st2niusma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + NillableIntUnionStringMapArray|CsvConversionError st3niusma = fromCsvWithType([st3, st3], {}, NillableIntUnionStringMapArray); + test:assertEquals(st3niusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + NillableIntUnionStringMapArray|CsvConversionError st4niusma = fromCsvWithType([st4, st4], {}, NillableIntUnionStringMapArray); + test:assertEquals(st4niusma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + IntUnionStringMapArray|CsvConversionError st1iusma = fromCsvWithType([st1, st1], {}, IntUnionStringMapArray); + test:assertEquals(st1iusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + IntUnionStringMapArray|CsvConversionError st2iusma = fromCsvWithType([st2, st2], {}, IntUnionStringMapArray); + test:assertEquals(st2iusma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + IntUnionStringMapArray|CsvConversionError st3iusma = fromCsvWithType([st3, st3], {}, IntUnionStringMapArray); + test:assertEquals(st3iusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + IntUnionStringMapArray|CsvConversionError st4iusma = fromCsvWithType([st4, st4], {}, IntUnionStringMapArray); + test:assertEquals(st4iusma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + JsonMapArray|CsvConversionError st1jma = fromCsvWithType([st1, st1], {}, JsonMapArray); + test:assertEquals(st1jma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + JsonMapArray|CsvConversionError st2jma = fromCsvWithType([st2, st2], {}, JsonMapArray); + test:assertEquals(st2jma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + JsonMapArray|CsvConversionError st3jma = fromCsvWithType([st3, st3], {}, JsonMapArray); + test:assertEquals(st3jma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + JsonMapArray|CsvConversionError st4jma = fromCsvWithType([st4, st4], {}, JsonMapArray); + test:assertEquals(st4jma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + AnydataMapArray|CsvConversionError st1anydma = fromCsvWithType([st1, st1], {}, AnydataMapArray); + test:assertEquals(st1anydma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + AnydataMapArray|CsvConversionError st2anydma = fromCsvWithType([st2, st2], {}, AnydataMapArray); + test:assertEquals(st2anydma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + AnydataMapArray|CsvConversionError st3anydma = fromCsvWithType([st3, st3], {}, AnydataMapArray); + test:assertEquals(st3anydma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + AnydataMapArray|CsvConversionError st4anydma = fromCsvWithType([st4, st4], {}, AnydataMapArray); + test:assertEquals(st4anydma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomMapArray|CsvConversionError st1cma = fromCsvWithType([st1, st1], {}, CustomMapArray); + test:assertEquals(st1cma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + CustomMapArray|CsvConversionError st2cma = fromCsvWithType([st2, st2], {}, CustomMapArray); + test:assertEquals(st2cma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomMapArray|CsvConversionError st3cma = fromCsvWithType([st3, st3], {}, CustomMapArray); + test:assertEquals(st3cma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + CustomMapArray|CsvConversionError st4cma = fromCsvWithType([st4, st4], {}, CustomMapArray); + test:assertEquals(st4cma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + NilMapArray|CsvConversionError st1nma = fromCsvWithType([st1, st1], {}, NilMapArray); + test:assertEquals(st1nma, ([ + {}, + {} + ])); + + IntegerMapArray|CsvConversionError st2ima = fromCsvWithType([st2, st2], {}, IntegerMapArray); + test:assertEquals(st2ima, ([ + {}, + {} + ])); + + DecimalMapArray|CsvConversionError st3dma = fromCsvWithType([st3, st3], {}, DecimalMapArray); + test:assertEquals(st3dma, ([ + {}, + {} + ])); + + BooleanMapArray|CsvConversionError st4bma = fromCsvWithType([st4, st4], {}, BooleanMapArray); + test:assertEquals(st4bma, ([ + {}, + {} + ])); +} + +@test:Config {enable} +function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { + StringArrayArray|CsvConversionError st1saa = fromCsvWithType([st1, st1], {}, StringArrayArray); + test:assertEquals(st1saa , [ + [s1, s2], + [s1, s2] + ]); + + StringArrayArray|CsvConversionError st2saa = fromCsvWithType([st2, st2], {}, StringArrayArray); + test:assertEquals(st2saa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringArrayArray|CsvConversionError st3saa = fromCsvWithType([st3, st3], {}, StringArrayArray); + test:assertEquals(st3saa , [ + [s1, s2], + [s1, s2] + ]); + + StringArrayArray|CsvConversionError st4saa = fromCsvWithType([st4, st4], {}, StringArrayArray); + test:assertEquals(st4saa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableStringArrayArray|CsvConversionError st1nsaa = fromCsvWithType([st1, st1], {}, NillableStringArrayArray); + test:assertEquals(st1nsaa , [ + [s1, s2], + [s1, s2] + ]); + + NillableStringArrayArray|CsvConversionError st2nsaa = fromCsvWithType([st2, st2], {}, NillableStringArrayArray); + test:assertEquals(st2nsaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableStringArrayArray|CsvConversionError st3nsaa = fromCsvWithType([st3, st3], {}, NillableStringArrayArray); + test:assertEquals(st3nsaa , [ + [s1, s2], + [s1, s2] + ]); + + NillableStringArrayArray|CsvConversionError st4nsaa = fromCsvWithType([st4, st4], {}, NillableStringArrayArray); + test:assertEquals(st4nsaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableIntOrUnionStringArrayArray|CsvConversionError st1nsuiaa = fromCsvWithType([st1, st1], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st1nsuiaa , [ + [s1, s2], + [s1, s2] + ]); + + NillableIntOrUnionStringArrayArray|CsvConversionError st2nsuiaa = fromCsvWithType([st2, st2], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st2nsuiaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableIntOrUnionStringArrayArray|CsvConversionError st3nsuiaa = fromCsvWithType([st3, st3], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st3nsuiaa , [ + [s1, s2], + [s1, s2] + ]); + + NillableIntOrUnionStringArrayArray|CsvConversionError st4nsuiaa = fromCsvWithType([st4, st4], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st4nsuiaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringArray2Array|CsvConversionError st1saa2 = fromCsvWithType([st1, st1], {}, StringArray2Array); + test:assertEquals(st1saa2 , [ + [s1, s2], + [s1, s2] + ]); + + StringArray2Array|CsvConversionError st2saa2 = fromCsvWithType([st2, st2], {}, StringArray2Array); + test:assertEquals(st2saa2 , [ + [s1, s2], + [s1, s2] + ]); + + StringArray2Array|CsvConversionError st3saa2 = fromCsvWithType([st3, st3], {}, StringArray2Array); + test:assertEquals(st3saa2 , [ + [s1, s2], + [s1, s2] + ]); + + StringArray2Array|CsvConversionError st4saa2 = fromCsvWithType([st4, st4], {}, StringArray2Array); + test:assertEquals(st4saa2 , [ + [s1, s2], + [s1, s2] + ]); + + JsonArray1Array|CsvConversionError st1jaa = fromCsvWithType([st1, st1], {}, JsonArray1Array); + test:assertEquals(st1jaa , [ + [s1, s2], + [s1, s2] + ]); + + JsonArray1Array|CsvConversionError st2jaa = fromCsvWithType([st2, st2], {}, JsonArray1Array); + test:assertEquals(st2jaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + JsonArray1Array|CsvConversionError st3jaa = fromCsvWithType([st3, st3], {}, JsonArray1Array); + test:assertEquals(st3jaa , [ + [s1, s2], + [s1, s2] + ]); + + JsonArray1Array|CsvConversionError st4jaa = fromCsvWithType([st4, st4], {}, JsonArray1Array); + test:assertEquals(st4jaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataArray1Array|CsvConversionError st1anyda = fromCsvWithType([st1, st1], {}, AnydataArray1Array); + test:assertEquals(st1anyda , [ + [s1, s2], + [s1, s2] + ]); + + AnydataArray1Array|CsvConversionError st2anyda = fromCsvWithType([st2, st2], {}, AnydataArray1Array); + test:assertEquals(st2anyda , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataArray1Array|CsvConversionError st3anyda = fromCsvWithType([st3, st3], {}, AnydataArray1Array); + test:assertEquals(st3anyda , [ + [s1, s2], + [s1, s2] + ]); + + AnydataArray1Array|CsvConversionError st4anyda = fromCsvWithType([st4, st4], {}, AnydataArray1Array); + test:assertEquals(st4anyda , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + DecimalArray1Array|CsvConversionError st1dda = fromCsvWithType([st1, st1], {}, DecimalArray1Array); + test:assertTrue(st1dda is CsvConversionError); + test:assertEquals((st1dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); + + DecimalArray1Array|CsvConversionError st3dda = fromCsvWithType([st3, st3], {}, DecimalArray1Array); + test:assertTrue(st3dda is CsvConversionError); + test:assertEquals((st3dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); +} + +@test:Config {enable} +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|CsvConversionError stcr27 = fromCsvWithType([value, value, value], {}, CustomRecord27Array); + test:assertEquals(stcr27 , [ + {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: ()} + ]); +} + +boolean enable = !true; + +@test:Config {enable: !enable} +function test() { + BooleanTuple1Array|CsvConversionError bm1bt = fromCsvWithType([bm1, bm1], {}, BooleanTuple1Array); + test:assertEquals(bm1bt, [ + [true, false, false, false], + [true, false, false, false] + ]); +} + +function generateErrorMessageForMissingRequiredField(string 'field) returns string { + return string `no matching header value is found for the required field '${'field}'`; +} + +function generateErrorMessageForInvalidCast(string value, string 'type) returns string { + return string `value '${value}' cannot be cast into '${'type}'`; +} + +function generateErrorMessageForInvalidFieldType(string value, string 'key) returns string { + return string `no mapping type found for value '${value}' in key '${'key}'`; +} + +function generateErrorMessageForInvalidValueForArrayType(string value, string index, string arrayType) returns string { + return string `value '${value}' in index '${index}' is not compatible with array type '${arrayType}'`; +} + +function generateErrorMessageForInvalidHeaders(string value, string 'type) returns string{ + return string `value '${value}' cannot be cast into '${'type}', because fields in '${'type}' or the provided expected headers are not matching with the '${value}'`; +} diff --git a/ballerina/tests/types.bal b/ballerina/tests/types.bal index cbc19be..37fccd3 100644 --- a/ballerina/tests/types.bal +++ b/ballerina/tests/types.bal @@ -608,6 +608,49 @@ type StringRecord14 record {| string...; |}; +type StringRecord15 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord16 record {| + string?...; +|}; + +type StringRecord17 record {| + int...; +|}; + +type StringRecord18 record {| + string b2; + int?...; +|}; + +type StringRecord19 record { + string s1 = ""; + string s2 = ""; +}; + +type StringRecord20 record {| + string s1 = ""; + string s2 = ""; +|}; + +type StringRecord21 record { +}; + +type StringRecord22 record {| + string s1 = ""; + string s2 = ""; + json...; +|}; + +type StringRecord23 record {| + json...; +|}; + type JsonRecord1 record { json j1; json j2; @@ -788,7 +831,7 @@ type AnydataRecord14 record {| anydata...; |}; -type CustomeRecord1 record { +type CustomRecord1 record { int i1; int i2; string s1; @@ -803,7 +846,7 @@ type CustomeRecord1 record { decimal d2; }; -type CustomeRecord2 record {| +type CustomRecord2 record {| int i1; int i2; string s1; @@ -818,7 +861,7 @@ type CustomeRecord2 record {| decimal d2; |}; -type CustomeRecord3 record {| +type CustomRecord3 record {| int i1; string s1; boolean b1; @@ -827,7 +870,7 @@ type CustomeRecord3 record {| decimal d1; |}; -type CustomeRecord4 record { +type CustomRecord4 record { int i1; string s1; boolean b1; @@ -836,7 +879,7 @@ type CustomeRecord4 record { decimal d1; }; -type CustomeRecord5 record { +type CustomRecord5 record { int i1; string s1; boolean b1; @@ -847,7 +890,7 @@ type CustomeRecord5 record { string? nillableField = (); }; -type CustomeRecord6 record {| +type CustomRecord6 record {| int i1; string s1; boolean b1; @@ -858,7 +901,7 @@ type CustomeRecord6 record {| anydata? nillableField = (); |}; -type CustomeRecord7 record { +type CustomRecord7 record { int i1; string s1; boolean b1; @@ -870,7 +913,7 @@ type CustomeRecord7 record { anydata requiredField; }; -type CustomeRecord8 record {| +type CustomRecord8 record {| int i1; string s1; boolean b1; @@ -882,7 +925,7 @@ type CustomeRecord8 record {| anydata requiredField; |}; -type CustomeRecord9 record {| +type CustomRecord9 record {| int i1; string s1; boolean b1; @@ -892,11 +935,11 @@ type CustomeRecord9 record {| string...; |}; -type CustomeRecord10 record {| +type CustomRecord10 record {| string...; |}; -type CustomeRecord11 record {| +type CustomRecord11 record {| int i1; string s1; boolean b1; @@ -908,7 +951,7 @@ type CustomeRecord11 record {| string...; |}; -type CustomeRecord12 record {| +type CustomRecord12 record {| int i1; string s1; boolean b1; @@ -921,23 +964,109 @@ type CustomeRecord12 record {| string...; |}; -type CustomeRecord13 record {| +type CustomRecord13 record {| anydata defaultableField = ""; anydata? nillableField = (); string...; |}; -type CustomeRecord14 record {| +type CustomRecord14 record {| anydata defaultableField = ""; anydata? nillableField = (); anydata requiredField; string...; |}; +type CustomRecord15 record {| + string '1; + string '2; +|}; + +type CustomRecord16 record {| + string '1; + string '2; + string '3; + string '4; +|}; + +type CustomRecord17 record { + string '1; + string '2; +}; + +type CustomRecord18 record { + string '1; + string '2; + string '3; + string '4; +}; + +type CustomRecord19 record { + string '1; + string '2; + string '3 = ""; + string '4 = ""; +}; + +type CustomRecord20 record { + string '1; +}; + +type CustomRecord21 record {| + string '1; + json...; +|}; + +type CustomRecord22 record {| + string '1; + string...; +|}; + +type CustomRecord23 record {| + string '1; + string a = ""; + string...; +|}; + +type CustomRecord24 record {| + string '1; + string '2 = ""; + string...; +|}; + +type CustomRecord25 record {| + int '1; + string...; +|}; + +type CustomRecord26 record {| + string '1; + int...; +|}; + +type CustomRecord27 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata a1; + json j1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + type BooleanTuple1 [boolean, boolean, boolean, boolean]; type BooleanTuple2 [boolean, boolean]; type BooleanTuple3 [boolean, boolean...]; type BooleanTuple4 [boolean...]; +type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; +type NillableBooleanTuple6 [boolean?, boolean?]; +type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; +type NillableBooleanTuple8 [boolean?...]; +type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; type NilTuple1 [(), (), ()]; type NilTuple2 [(), ()]; @@ -959,7 +1088,7 @@ type DecimalTuple2 [decimal, decimal]; type DecimalTuple3 [decimal, decimal...]; type DecimalTuple4 [decimal...]; -type StringTuple1 [string, string, string]; +type StringTuple1 [string, string, string, string]; type StringTuple2 [string, string]; type StringTuple3 [string, string...]; type StringTuple4 [string...]; @@ -993,6 +1122,10 @@ type IntegerArray4 int[2]; type IntegerArray5 int[3]; type IntegerArray6 int[4]; +type StringArray string[]; +type NillableStringArray string?[]; +type NillableIntOrUnionStringArray (int|string?)[]; + type StringArray1 string[]; type StringArray2 string[2]; type StringArray3 string[]; @@ -1014,11 +1147,15 @@ type DecimalArray4 decimal[2]; type DecimalArray5 decimal[3]; type DecimalArray6 decimal[4]; -type BooleanArray1 boolean[]; +type BooleanArray boolean[]; +type NillableBooleanArray boolean?[]; +type NillableIntOrUnionBooleanArray (int|boolean?)[]; + type BooleanArray2 boolean[2]; -type BooleanArray3 boolean[]; -type BooleanArray4 boolean[2]; -type BooleanArray5 boolean[3]; +type BooleanArray3 boolean[3]; + +type BooleanArray4 boolean[]; +type BooleanArray5 boolean[2]; type BooleanArray6 boolean[4]; type NilArray1 ()[]; @@ -1051,12 +1188,15 @@ type CustomArray6 CustomTuple2[4]; type IntegerMap map; type StringMap map; +type NillableIntUnionStringMap map; +type IntUnionStringMap map; + type DecimalMap map; type FloatMap map; type BooleanMap map; -type NillableBooleanMap map; -type NillableIntUnionBooleanMap map; -type IntUnionBooleanMap map; +type NillableBooleanMap map; +type NillableIntUnionBooleanMap map; +type IntUnionBooleanMap map; type NilMap map<()>; type JsonMap map; type AnydataMap map; @@ -1239,6 +1379,16 @@ type StringRecord13Array StringRecord13[]; type ClosedStringRecord13Array StringRecord13[3]; type StringRecord14Array StringRecord14[]; type ClosedStringRecord14Array StringRecord14[3]; +type StringRecord15Array StringRecord15[]; +type StringRecord16Array StringRecord16[]; +type StringRecord17Array StringRecord17[]; +type StringRecord18Array StringRecord18[]; +type StringRecord19Array StringRecord19[]; +type StringRecord20Array StringRecord20[]; +type StringRecord21Array StringRecord21[]; +type StringRecord22Array StringRecord22[]; +type StringRecord23Array StringRecord23[]; + type JsonRecord1Array JsonRecord1[]; type ClosedJsonRecord1Array JsonRecord1[3]; type JsonRecord2Array JsonRecord2[]; @@ -1295,34 +1445,49 @@ type AnydataRecord13Array AnydataRecord13[]; type ClosedAnydataRecord13Array AnydataRecord13[3]; type AnydataRecord14Array AnydataRecord14[]; type ClosedAnydataRecord14Array AnydataRecord14[3]; -type CustomeRecord1Array CustomeRecord1[]; -type ClosedCustomeRecord1Array CustomeRecord1[3]; -type CustomeRecord2Array CustomeRecord2[]; -type ClosedCustomeRecord2Array CustomeRecord2[3]; -type CustomeRecord3Array CustomeRecord3[]; -type ClosedCustomeRecord3Array CustomeRecord3[3]; -type CustomeRecord4Array CustomeRecord4[]; -type ClosedCustomeRecord4Array CustomeRecord4[3]; -type CustomeRecord5Array CustomeRecord5[]; -type ClosedCustomeRecord5Array CustomeRecord5[3]; -type CustomeRecord6Array CustomeRecord6[]; -type ClosedCustomeRecord6Array CustomeRecord6[3]; -type CustomeRecord7Array CustomeRecord7[]; -type ClosedCustomeRecord7Array CustomeRecord7[3]; -type CustomeRecord8Array CustomeRecord8[]; -type ClosedCustomeRecord8Array CustomeRecord8[3]; -type CustomeRecord9Array CustomeRecord9[]; -type ClosedCustomeRecord9Array CustomeRecord9[3]; -type CustomeRecord10Array CustomeRecord10[]; -type ClosedCustomeRecord10Array CustomeRecord10[3]; -type CustomeRecord11Array CustomeRecord11[]; -type ClosedCustomeRecord11Array CustomeRecord11[3]; -type CustomeRecord12Array CustomeRecord12[]; -type ClosedCustomeRecord12Array CustomeRecord12[3]; -type CustomeRecord13Array CustomeRecord13[]; -type ClosedCustomeRecord13Array CustomeRecord13[3]; -type CustomeRecord14Array CustomeRecord14[]; -type ClosedCustomeRecord14Array CustomeRecord14[3]; +type CustomRecord1Array CustomRecord1[]; +type ClosedCustomRecord1Array CustomRecord1[3]; +type CustomRecord2Array CustomRecord2[]; +type ClosedCustomRecord2Array CustomRecord2[3]; +type CustomRecord3Array CustomRecord3[]; +type ClosedCustomRecord3Array CustomRecord3[3]; +type CustomRecord4Array CustomRecord4[]; +type ClosedCustomRecord4Array CustomRecord4[3]; +type CustomRecord5Array CustomRecord5[]; +type ClosedCustomRecord5Array CustomRecord5[3]; +type CustomRecord6Array CustomRecord6[]; +type ClosedCustomRecord6Array CustomRecord6[3]; +type CustomRecord7Array CustomRecord7[]; +type ClosedCustomRecord7Array CustomRecord7[3]; +type CustomRecord8Array CustomRecord8[]; +type ClosedCustomRecord8Array CustomRecord8[3]; +type CustomRecord9Array CustomRecord9[]; +type ClosedCustomRecord9Array CustomRecord9[3]; +type CustomRecord10Array CustomRecord10[]; +type ClosedCustomRecord10Array CustomRecord10[3]; +type CustomRecord11Array CustomRecord11[]; +type ClosedCustomRecord11Array CustomRecord11[3]; +type CustomRecord12Array CustomRecord12[]; +type ClosedCustomRecord12Array CustomRecord12[3]; +type CustomRecord13Array CustomRecord13[]; +type ClosedCustomRecord13Array CustomRecord13[3]; +type CustomRecord14Array CustomRecord14[]; +type ClosedCustomRecord14Array CustomRecord14[3]; + +type CustomRecord15Array CustomRecord15[]; +type CustomRecord16Array CustomRecord16[]; +type CustomRecord17Array CustomRecord17[]; +type CustomRecord18Array CustomRecord18[]; +type CustomRecord19Array CustomRecord19[]; +type CustomRecord20Array CustomRecord20[]; +type CustomRecord21Array CustomRecord21[]; +type CustomRecord22Array CustomRecord22[]; +type CustomRecord23Array CustomRecord23[]; +type CustomRecord24Array CustomRecord24[]; +type CustomRecord25Array CustomRecord25[]; +type CustomRecord26Array CustomRecord26[]; +type CustomRecord27Array CustomRecord27[]; + type BooleanTuple1Array BooleanTuple1[]; type ClosedBooleanTuple1Array BooleanTuple1[3]; type BooleanTuple2Array BooleanTuple2[]; @@ -1331,6 +1496,13 @@ type BooleanTuple3Array BooleanTuple3[]; type ClosedBooleanTuple3Array BooleanTuple3[3]; type BooleanTuple4Array BooleanTuple4[]; type ClosedBooleanTuple4Array BooleanTuple4[3]; + +type NillableBooleanTuple5Array NillableBooleanTuple5[]; +type NillableBooleanTuple6Array NillableBooleanTuple6[]; +type NillableBooleanTuple7Array NillableBooleanTuple7[]; +type NillableBooleanTuple8Array NillableBooleanTuple8[]; +type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; + type NilTuple1Array NilTuple1[]; type ClosedNilTuple1Array NilTuple1[3]; type NilTuple2Array NilTuple2[]; @@ -1371,6 +1543,7 @@ type StringTuple3Array StringTuple3[]; type ClosedStringTuple3Array StringTuple3[3]; type StringTuple4Array StringTuple4[]; type ClosedStringTuple4Array StringTuple4[3]; + type AnydataTuple1Array AnydataTuple1[]; type ClosedAnydataTuple1Array AnydataTuple1[3]; type AnydataTuple2Array AnydataTuple2[]; @@ -1412,6 +1585,11 @@ type ClosedIntegerArray5Array IntegerArray5[3]; type IntegerArray6Array IntegerArray5[]; type ClosedIntegerArray6Array IntegerArray5[3]; type StringArray1Array StringArray1[]; + +type StringArrayArray StringArray[]; +type NillableStringArrayArray NillableStringArray[]; +type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; + type ClosedStringArray1Array StringArray1[3]; type StringArray2Array StringArray2[]; type ClosedStringArray2Array StringArray2[3]; @@ -1447,8 +1625,14 @@ type DecimalArray5Array DecimalArray5[]; type ClosedDecimalArray5Array DecimalArray5[3]; type DecimalArray6Array DecimalArray5[]; type ClosedDecimalArray6Array DecimalArray5[3]; -type BooleanArray1Array BooleanArray1[]; -type ClosedBooleanArray1Array BooleanArray1[3]; + +type BooleanArrayArray BooleanArray[]; +type ClosedBooleanArrayArray BooleanArray[3]; + +type NillableBooleanArrayArray NillableBooleanArray[]; +type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; + + type BooleanArray2Array BooleanArray2[]; type ClosedBooleanArray2Array BooleanArray2[3]; type BooleanArray3Array BooleanArray3[]; @@ -1510,6 +1694,9 @@ type ClosedCustomArray6Array CustomArray5[3]; type IntegerMapArray IntegerMap[]; type ClosedIntegerMapArray IntegerMap[3]; type StringMapArray StringMap[]; +type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; +type IntUnionStringMapArray IntUnionStringMap[]; + type ClosedStringMapArray StringMap[3]; type DecimalMapArray DecimalMap[]; type ClosedDecimalMapArray DecimalMap[3]; diff --git a/ballerina/tests/values.bal b/ballerina/tests/values.bal index 5ec5391..f213c17 100644 --- a/ballerina/tests/values.bal +++ b/ballerina/tests/values.bal @@ -42,6 +42,7 @@ map bm2 = {b1, b2, b3, n1, n3}; map bm3 = {b1, b2, b3, b4, i1}; map<()> bm4 = {n1, n3}; map bm5 = {b1, b2, b3, b4:true}; + map m5 = {i1, i2, i3, i4, i5, i6}; map m6 = {f1, f2, f3, f4, f5, f6, f7}; map m7 = {d1, d2, d3, d4}; @@ -62,9 +63,23 @@ string[] arr9 = [s1, s2, s3]; anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[boolean, boolean] tup1 = [b1, b2]; -[boolean?, boolean?, boolean?, boolean?, boolean?] tup2 = [b1, b2, b3, n1, n3]; -[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] tup3 = [b1, b2, b3, b4, i1]; +[boolean, boolean] bt1 = [b1, b2]; +[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; +[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; +[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; +[boolean...] bt5 = [b1, b2]; + +[string, string] st1 = [s1, s2]; +[string, string, string, string] st2 = [s1, s2, s3, s2]; +[string...] st3 = [s1, s2]; +[string, string, string...] st4 = [s1, s2, s3, s2]; + +[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; +[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; +[string?...] st7 = [s1, s2]; +[string...] st8 = []; +[string, string, string] st9 = [s1, s2, s3]; + [(), ()] tup4 = [n1, n3]; [int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; [float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 3057c29..5b59ce4 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -54,6 +54,7 @@ static class CsvTree { Object currentCsvNode; Field currentField; Map fieldHierarchy = new HashMap<>(); + Map headerFieldHierarchy = new HashMap<>(); Type restType; Deque fieldNames = new ArrayDeque<>(); BArray rootCsvNode; @@ -65,6 +66,7 @@ void reset() { currentCsvNode = null; currentField = null; fieldHierarchy.clear(); + headerFieldHierarchy.clear(); restType = null; fieldNames.clear(); expectedArrayElementType = null; @@ -142,6 +144,7 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected case TypeTags.RECORD_TYPE_TAG: RecordType recordType = (RecordType) expectedType; this.fieldHierarchy = new HashMap<>(recordType.getFields()); + this.headerFieldHierarchy = new HashMap<>(recordType.getFields()); this.restType = recordType.getRestFieldType(); // TODO: check for package ID currentCsvNode = ValueCreator.createRecordValue(recordType.getPackage(), recordType.getName()); @@ -252,26 +255,33 @@ private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, String[] he } Type type = csvElement.getType(); if (type instanceof TupleType) { - return checkExpectedTypeMatchWithHeadersForTuple(expectedType, headers, (TupleType) type, arraySize); + return checkExpectedTypeMatchWithHeadersForTuple(expectedType, headers, (TupleType) type); } else { return checkExpectedTypeMatchWithHeadersForArray(expectedType, headers, csvElement.getElementType(), arraySize); } } - private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, String[] headers, TupleType tupleType, int arraySize) { + private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, String[] headers, TupleType tupleType) { + Type type; List tupleTypes = tupleType.getTupleTypes(); Type tupleRestType = tupleType.getRestType(); if (expectedType instanceof RecordType) { - if (this.restType != null && this.restType.getTag() == TypeTags.ANYDATA_TAG) { + if (this.restType != null + && (this.restType.getTag() == TypeTags.ANYDATA_TAG + || this.restType.getTag() == TypeTags.JSON_TAG)) { return true; } - for (int i = 0; i < tupleTypes.size(); i++) { - Type type = tupleTypes.get(i); + for (int i = 0; i < headers.length; i++) { + if (i >= tupleTypes.size()) { + type = tupleRestType; + } else { + type = tupleTypes.get(i); + } String header = headers[i]; - Field field = this.fieldHierarchy.get(header); + Field field = this.headerFieldHierarchy.remove(header); if (field != null) { if (type.getTag() != field.getFieldType().getTag()) { @@ -280,9 +290,15 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Str continue; } - if (tupleRestType != null && this.restType == tupleRestType) { + if ((tupleRestType != null && (type == this.restType ||this.restType == tupleRestType))) { + continue; + } + + if (isHeaderFieldsEmpty(this.headerFieldHierarchy)) { continue; } + + return false; } return true; @@ -315,7 +331,7 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean boolean headersMatchWithExpType = checkExpectedTypeMatchWithHeaders( expectedType, headers, csvElement, arraySize); if (!headersMatchWithExpType) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csvElement, expectedType); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONVERSION_FOR_ARRAY_TO_MAP, csvElement, expectedType); } // TODO: Add headers from config addValuesToMapType(csvElement, arraySize, mappingType, expectedType); @@ -387,6 +403,9 @@ private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BStrin case TypeTags.FLOAT_TAG: case TypeTags.DECIMAL_TAG: case TypeTags.STRING_TAG: + case TypeTags.JSON_TAG: + case TypeTags.ANYDATA_TAG: + case TypeTags.ANY_TAG: if (checkTypeCompatibility(currentFieldType, mapValue)) { ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), convertToBasicType(mapValue, currentFieldType, config)); @@ -397,22 +416,21 @@ private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BStrin } return; case TypeTags.UNION_TAG: - boolean isCompatible = false; for (Type memberType: ((UnionType) currentFieldType).getMemberTypes()) { if (!isBasicType(memberType)) { - isCompatible = false; - break; + throw DiagnosticLog.error(DiagnosticErrorCode + .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); } if (checkTypeCompatibility(memberType, mapValue)) { - isCompatible = true; + ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), + convertToBasicType(mapValue, memberType, config)); + return; } } - if (!isCompatible) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); + if (isMapType) { + return; } - ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), - convertToBasicType(mapValue, currentFieldType, config)); - break; + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); default: // TODO: handle maps and structure values in future throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); @@ -423,33 +441,33 @@ private void addRestField(Type restFieldType, BString key, Object csvMember) { switch (restFieldType.getTag()) { case TypeTags.ANYDATA_TAG: case TypeTags.JSON_TAG: - ((BMap) currentCsvNode).put(key, csvMember); - break; case TypeTags.BOOLEAN_TAG: case TypeTags.INT_TAG: case TypeTags.FLOAT_TAG: case TypeTags.DECIMAL_TAG: case TypeTags.STRING_TAG: if (checkTypeCompatibility(restFieldType, csvMember)) { - ((BMap) currentCsvNode).put(key, csvMember); + ((BMap) currentCsvNode) + .put(key, convertToBasicType(csvMember, restFieldType, config)); } break; case TypeTags.UNION_TAG: - boolean isCompatible = false; for (Type memberType: ((UnionType) restFieldType).getMemberTypes()) { if (!isBasicType(memberType)) { - isCompatible = false; - break; + throw DiagnosticLog.error(DiagnosticErrorCode + .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); } if (checkTypeCompatibility(memberType, csvMember)) { - isCompatible = true; + ((BMap) currentCsvNode) + .put(key, convertToBasicType(csvMember, memberType, config)); + break; } } - if (isCompatible) { - ((BMap) currentCsvNode) - .put(key, convertToBasicType(csvMember, restFieldType, config)); - } break; + case TypeTags.INTERSECTION_TAG: + for (Type memberType: ((IntersectionType) restFieldType).getConstituentTypes()) { + // + } default: throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, csvMember, key); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 11e7b42..36c8fa8 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -2,16 +2,11 @@ import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.flags.SymbolFlags; -import io.ballerina.runtime.api.types.ArrayType; -import io.ballerina.runtime.api.types.Field; -import io.ballerina.runtime.api.types.TupleType; -import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.*; import io.ballerina.runtime.api.utils.JsonUtils; import io.ballerina.runtime.api.utils.StringUtils; -import io.ballerina.runtime.api.values.BArray; -import io.ballerina.runtime.api.values.BDecimal; -import io.ballerina.runtime.api.values.BMap; -import io.ballerina.runtime.api.values.BString; +import io.ballerina.runtime.api.utils.ValueUtils; +import io.ballerina.runtime.api.values.*; import io.ballerina.stdlib.data.csvdata.csv.CsvConfig; import io.ballerina.stdlib.data.csvdata.csv.CsvTraversal; import io.ballerina.stdlib.data.csvdata.csv.QueryParser; @@ -44,6 +39,8 @@ public static boolean isBasicType(Type type) { case TypeTags.DECIMAL_TAG: case TypeTags.FLOAT_TAG: case TypeTags.NULL_TAG: + case TypeTags.JSON_TAG: + case TypeTags.ANYDATA_TAG: return true; default: return false; @@ -169,19 +166,12 @@ public static String[] createHeaders(String[] headers, CsvConfig config) { } public static Object convertToBasicType(Object csv, Type targetType, CsvConfig config) { - if (targetType.getTag() == TypeTags.READONLY_TAG) { - return csv; + if (csv == null) { + csv = config.nullValue; } try { - Object value = JsonUtils.convertJSON(csv, targetType); - if (value == null) { - return config.nullValue; - } - if (value instanceof String) { - return StringUtils.fromString(value.toString()); - } - return value; - } catch (Exception e) { + return ValueUtils.convert(csv, targetType); + } catch (BError e) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, targetType); } } @@ -191,57 +181,76 @@ public static void checkOptionalFieldsAndLogError(Map currentFiel if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); } - // TODO: Handle this properly - if (!(SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED) && - SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL))) { -// throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); - } }); } - public static boolean checkTypeCompatibility(Type constraintType, Object csv) { - // TODO: Remove this - if (csv instanceof BMap) { - BMap map = (BMap) csv; - for (BString key : map.getKeys()) { - if (!checkTypeCompatibility(constraintType, map.get(key))) { - return false; - } + public static boolean isHeaderFieldsEmpty(Map currentField) { + for (Field field: currentField.values()) { + if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { + return false; } - return true; - } else if ((csv instanceof BString && constraintType.getTag() == TypeTags.STRING_TAG) - || (csv instanceof Long && constraintType.getTag() == INT_TAG) - || (csv instanceof BDecimal && constraintType.getTag() == TypeTags.DECIMAL_TAG) - || (csv instanceof Double && (constraintType.getTag() == TypeTags.FLOAT_TAG - || constraintType.getTag() == TypeTags.DECIMAL_TAG)) - || (Boolean.class.isInstance(csv) && constraintType.getTag() == TypeTags.BOOLEAN_TAG) - || (csv == null && constraintType.getTag() == TypeTags.NULL_TAG)) { + } + return true; + } + + public static boolean checkTypeCompatibility(Type constraintType, Object csv) { + int tag = constraintType.getTag(); + if ((csv instanceof BString && (tag == TypeTags.STRING_TAG || isJsonOrAnyDataOrAny(tag))) + || (csv instanceof Long && (tag == INT_TAG || isJsonOrAnyDataOrAny(tag))) + || (csv instanceof BDecimal && (tag == TypeTags.DECIMAL_TAG || isJsonOrAnyDataOrAny(tag))) + || (csv instanceof Double && ((tag == TypeTags.FLOAT_TAG + || tag == TypeTags.DECIMAL_TAG) || isJsonOrAnyDataOrAny(tag))) + || (Boolean.class.isInstance(csv) && (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag))) + || (csv == null && (tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag)))) { return true; } else { return false; } } + private static boolean isJsonOrAnyDataOrAny(int tag) { + return tag == TypeTags.JSON_TAG || tag == TypeTags.ANYDATA_TAG || tag == TypeTags.ANY_TAG; + } + public static void addValuesToArrayType(Object csvElement, Type arrayElementType, int index, Object currentCsvNode, CsvConfig config) { switch (arrayElementType.getTag()) { case TypeTags.NULL_TAG: case TypeTags.BOOLEAN_TAG: - case INT_TAG: + case TypeTags.INT_TAG: case TypeTags.FLOAT_TAG: case TypeTags.DECIMAL_TAG: case TypeTags.STRING_TAG: - case TypeTags.XML_TAG: - ((BArray) currentCsvNode).add(index, convertToBasicType(csvElement, arrayElementType, config)); + case TypeTags.JSON_TAG: + case TypeTags.ANYDATA_TAG: + case TypeTags.ANY_TAG: + if (checkTypeCompatibility(arrayElementType, csvElement)) { + ((BArray) currentCsvNode).add(index, convertToBasicType(csvElement, arrayElementType, config)); + return; + } break; - default: - DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, arrayElementType); + case TypeTags.UNION_TAG: + for (Type memberType: ((UnionType) arrayElementType).getMemberTypes()) { + if (!isBasicType(memberType)) { + throw DiagnosticLog.error(DiagnosticErrorCode + .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); + } + if (checkTypeCompatibility(memberType, csvElement)) { + ((BArray) currentCsvNode).add(index, convertToBasicType(csvElement, memberType, config)); + return; + } + } } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_ARRAY, csvElement, index, arrayElementType); } public static int getTheActualExpectedType(Type type) { if (type instanceof TupleType) { - return ((TupleType) type).getTupleTypes().size(); + TupleType tupleType = (TupleType) type; + if (tupleType.getRestType() != null) { + return -1; + } + return tupleType.getTupleTypes().size(); } else { return ((ArrayType) type).getSize(); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index 536de14..c4632c5 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -36,7 +36,10 @@ public enum DiagnosticErrorCode { INVALID_EXPECTED_ARRAY_SIZE("BDE_0009", "invalid.expected.array.size"), INVALID_EXPECTED_TUPLE_SIZE("BDE_0010", "invalid.expected.tuple.size"), INVALID_SKIP_COLUMN_QUERY("BDE_0011", "invalid.skip.column.query"), - INVALID_TYPE_FOR_FIELD("BDE_0012", "invalid.type.for.field"); + INVALID_TYPE_FOR_FIELD("BDE_0012", "invalid.type.for.field"), + INVALID_TYPE_FOR_ARRAY("BDE_0013", "invalid.type.for.array"), + INVALID_CONVERSION_FOR_ARRAY_TO_MAP("BDE_0014", "invalid.conversion.for.array.to.map"), + EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES("BDE_0015", "expected.type.can.only.contains.basic.types"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index a60e609..bf1d1ba 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -55,3 +55,13 @@ error.invalid.skip.column.query=\ error.invalid.type.for.field=\ no mapping type found for value ''{0}'' in key ''{1}'' + +error.invalid.type.for.array=\ + value ''{0}'' in index ''{1}'' is not compatible with array type ''{2}'' + +error.expected.type.can.only.contains.basic.types=\ + expected type cannot contains types other than basic types, ''{0}'' not allowed + +error.invalid.conversion.for.array.to.map=\ + value ''{0}'' cannot be cast into ''{1}'', because fields in ''{1}'' or the provided \ + expected headers are not matching with the ''{0}'' \ No newline at end of file From d9f37535cb34c4fb6edbf2cb0b6c30bfd6aa6329 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 18 Mar 2024 15:30:39 +0530 Subject: [PATCH 018/147] Add tests for csvWithType Functiojn --- ballerina/csv_api.bal | 2 +- ..._csv_string_with_type_with_string_test.bal | 69 +++++++++ ballerina/tests/from_csv_with_type_test.bal | 139 +++++++++++++----- ballerina/tests/test.bal | 16 +- ballerina/tests/test_utils.bal | 19 +++ ballerina/tests/types.bal | 3 + ballerina/tests/values.bal | 37 +++++ .../stdlib/data/csvdata/csv/CsvParser.java | 4 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 50 +++++-- .../stdlib/data/csvdata/utils/CsvUtils.java | 5 +- 10 files changed, 280 insertions(+), 64 deletions(-) create mode 100644 ballerina/tests/from_csv_string_with_type_with_string_test.bal create mode 100644 ballerina/tests/test_utils.bal diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index b8455a7..710a7b6 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -73,7 +73,7 @@ public isolated function fromCsvWithType((string[]|map)[] csv, FromCSVC returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function fromCsvStringWithType(string|byte[]|stream s, - FromCSVConfig config = {} ,typedesc<(record{}|map|anydata)[]> t = <>) + FromCSVConfig config = {} ,typedesc<(map|anydata)[]> t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function toCsv((anydata[]|map)[] csv, ToCSVConfig config = {}, typedesc<(record{}|map|anydata[])[]> t = <>) diff --git a/ballerina/tests/from_csv_string_with_type_with_string_test.bal b/ballerina/tests/from_csv_string_with_type_with_string_test.bal new file mode 100644 index 0000000..ff48ca8 --- /dev/null +++ b/ballerina/tests/from_csv_string_with_type_with_string_test.bal @@ -0,0 +1,69 @@ +import ballerina/test; + +@test:Config {enable} +function testFromCsvStringWithTypeForMapAndRecordAsExpectedType() { + BooleanRecord1Array|CsvConversionError cv1br = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertEquals(cv1br, [ + {} + ]); +} + +// @test:Config {enable} +// function testFromCsvStringWithTypeForMapAndRecordAsExpectedType2() { + +// } + +// @test:Config {enable} +// function testFromCsvStringWithTypeForMapAndMapAsExpectedType() { + +// } + +// @test:Config {enable} +// function testFromCsvStringWithTypeForMapAndArrayAsExpectedType() { + +// } + +// @test:Config {enable} +// function testFromCsvStringWithTypeForMapAndTupleAsExpectedType() { + +// } + +// @test:Config {enable} +// function testFromCsvStringWithTypeForTupleAndRecordAsExpectedType() { + +// } + +// @test:Config {enable} +// function testFromCsvStringWithTypeForTupleAndRecordAsExpectedType2() { + +// } + +// @test:Config {enable} +// function testFromCsvStringWithTypeForTupleAndTupleAsExpectedType() { + +// } + +// @test:Config {enable} +// function testFromCsvStringWithTypeForTupleAndMapAsExpectedType() { + +// } + +// @test:Config {enable} +// function testFromCsvStringWithTypeForTupleAndArrayAsExpectedType() { + +// } + +// @test:Config {enable} +// function testFromCsvStringWithTypeFunctionWithTypeCompatibility() { + +// } + +boolean enable = !true; + +@test:Config {enable: !enable} +function test() { + BooleanRecord1Array|CsvConversionError cv1br = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertEquals(cv1br, [ + {} + ]); +} diff --git a/ballerina/tests/from_csv_with_type_test.bal b/ballerina/tests/from_csv_with_type_test.bal index 0eb22ab..b13b293 100644 --- a/ballerina/tests/from_csv_with_type_test.bal +++ b/ballerina/tests/from_csv_with_type_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config {enable: enable} function testFromCsvWithTypeForMapAndRecordAsExpectedType() { BooleanRecord1Array|CsvConversionError bm1br1 = fromCsvWithType([bm1, bm1], {}, BooleanRecord1Array); test:assertTrue(bm1br1 is CsvConversionError); @@ -192,7 +192,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType() { test:assertEquals((bm5br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); } -@test:Config {enable} +@test:Config {enable: enable} function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { BooleanRecord9Array|CsvConversionError bm1br9 = fromCsvWithType([bm1, bm1], {}, BooleanRecord9Array); test:assertTrue(bm1br9 is CsvConversionError); @@ -449,7 +449,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { ]); } -@test:Config {enable} +@test:Config {enable: enable} function testFromCsvWithTypeForMapAndMapAsExpectedType() { BooleanMapArray|CsvConversionError bm1bma = fromCsvWithType([bm1, bm1], {}, BooleanMapArray); test:assertEquals(bm1bma, [ @@ -721,7 +721,7 @@ function testFromCsvWithTypeForMapAndMapAsExpectedType() { ]); } -@test:Config {enable} +@test:Config {enable: enable} function testFromCsvWithTypeForMapAndArrayAsExpectedType() { BooleanArrayArray|CsvConversionError bm1ba = fromCsvWithType([bm1, bm1], {}, BooleanArrayArray); test:assertEquals(bm1ba, [ @@ -884,7 +884,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { test:assertEquals((bm5sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } -@test:Config {enable} +@test:Config {enable: enable} function testFromCsvWithTypeForMapAndTupleAsExpectedType() { BooleanTuple1Array|CsvConversionError bm1bt = fromCsvWithType([bm1, bm1], {}, BooleanTuple1Array); test:assertEquals(bm1bt, [ @@ -1227,7 +1227,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { test:assertEquals((bm5s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } -@test:Config {enable} +@test:Config {enable: enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { StringRecord1Array|CsvConversionError st1sr1 = fromCsvWithType([st1, st1], {}, StringRecord1Array); test:assertTrue(st1sr1 is CsvConversionError); @@ -1482,7 +1482,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { ]); } -@test:Config {enable} +@test:Config {enable: enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { StringRecord1Array|CsvConversionError st3sr1 = fromCsvWithType([st3, st3], {}, StringRecord1Array); test:assertTrue(st3sr1 is CsvConversionError); @@ -1697,7 +1697,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { ]); } -@test:Config {enable} +@test:Config {enable: enable} function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { StringTuple1Array|CsvConversionError st1st1 = fromCsvWithType([st1, st1], {}, StringTuple1Array); test:assertEquals(st1st1, [ @@ -1859,7 +1859,7 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { test:assertEquals((st4bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); } -@test:Config {enable} +@test:Config {enable: enable} function testFromCsvWithTypeForTupleAndMapAsExpectedType() { StringMapArray|CsvConversionError st1sma = fromCsvWithType([st1, st1], {}, StringMapArray); test:assertEquals(st1sma , [ @@ -2030,7 +2030,7 @@ function testFromCsvWithTypeForTupleAndMapAsExpectedType() { ])); } -@test:Config {enable} +@test:Config {enable: enable} function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { StringArrayArray|CsvConversionError st1saa = fromCsvWithType([st1, st1], {}, StringArrayArray); test:assertEquals(st1saa , [ @@ -2185,44 +2185,113 @@ function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { test:assertEquals((st3dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); } -@test:Config {enable} +@test:Config {enable: enable} 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|CsvConversionError stcr27 = fromCsvWithType([value, value, value], {}, CustomRecord27Array); - test:assertEquals(stcr27 , [ + var value2 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3, j2: b2, a2: d2}; + var value3 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3}; + + CustomRecord27Array|CsvConversionError vcr27a = fromCsvWithType([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: ()} ]); -} -boolean enable = !true; + CustomTuple7Array|CsvConversionError v2ct7a = fromCsvWithType([value2, value2, value2], {}, CustomTuple7Array); + test:assertTrue(v2ct7a is CsvConversionError); + test:assertEquals((v2ct7a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "string")); -@test:Config {enable: !enable} -function test() { - BooleanTuple1Array|CsvConversionError bm1bt = fromCsvWithType([bm1, bm1], {}, BooleanTuple1Array); - test:assertEquals(bm1bt, [ - [true, false, false, false], - [true, false, false, false] + CustomTuple7Array|CsvConversionError v3ct7a = fromCsvWithType([value3, value3, value3], {}, CustomTuple7Array); + test:assertEquals(v3ct7a , [ + [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], + [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], + [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3] ]); -} -function generateErrorMessageForMissingRequiredField(string 'field) returns string { - return string `no matching header value is found for the required field '${'field}'`; -} + AnydataArray1Array|CsvConversionError v3anyd1a = fromCsvWithType([value3, value3, value3], {}, AnydataArray1Array); + test:assertEquals(v3anyd1a , [ + [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], + [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], + [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3] + ]); -function generateErrorMessageForInvalidCast(string value, string 'type) returns string { - return string `value '${value}' cannot be cast into '${'type}'`; -} + AnydataMapArray|CsvConversionError vanydma = fromCsvWithType([value, value, value], {}, AnydataMapArray); + test:assertEquals(vanydma , [ + value, + value, + value + ]); -function generateErrorMessageForInvalidFieldType(string value, string 'key) returns string { - return string `no mapping type found for value '${value}' in key '${'key}'`; -} + JsonMapArray|CsvConversionError vjma = fromCsvWithType([value, value, value], {}, JsonMapArray); + test:assertEquals(vjma , [ + value, + value, + value + ]); -function generateErrorMessageForInvalidValueForArrayType(string value, string index, string arrayType) returns string { - return string `value '${value}' in index '${index}' is not compatible with array type '${arrayType}'`; + record{|int...;|}[]|CsvConversionError irrma = fromCsvWithType([{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...;|}[]|CsvConversionError drra = fromCsvWithType([{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...;|}[]|CsvConversionError srra = fromCsvWithType([{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...;|}[]|CsvConversionError frra = fromCsvWithType([{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;|}[]|CsvConversionError fdc1a = fromCsvWithType([{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 ...;|}[]|CsvConversionError fdc2a = fromCsvWithType([{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...;|}[]|CsvConversionError fdc3a = fromCsvWithType([{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} + ]); } -function generateErrorMessageForInvalidHeaders(string value, string 'type) returns string{ - return string `value '${value}' cannot be cast into '${'type}', because fields in '${'type}' or the provided expected headers are not matching with the '${value}'`; +// boolean enable = true; + +@test:Config {enable: !enable} +function testTemp1() { + // record{|float...;|}[]|CsvConversionError frra = fromCsvWithType([{a: d2, b: d3}]); + // test:assertEquals(frra , [ + // {a: 1.2, b: 1.2}, + // {}, + // {a: d4, b: f2} + // ]); } diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal index f238e08..9961148 100644 --- a/ballerina/tests/test.bal +++ b/ballerina/tests/test.bal @@ -31,9 +31,7 @@ // [string, string][] d = [["1", "2"], ["1", "2"]]; // [string, string][] d2 = [["1", "2"], ["1", "2"]]; -// boolean enable = true; - -// @test:Config{enable } +// @test:Config{enable: enableTest} // public function testA() returns error? { // A aa = check fromCsvWithType(a, {}, A); // test:assertEquals(aa, a); @@ -123,7 +121,7 @@ // test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); // } -// @test:Config{enable } +// @test:Config{enable: enableTest} // function testB() returns error? { // // B2 d2b2 = check fromCsvWithType(d2, {}, B2); // // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); @@ -204,8 +202,8 @@ // type XX string[][2]; // type YY anydata[][2]; -// @test:Config{ enable } -// function test() returns CsvConversionError? { +// @test:Config{enable: enableTest} +// function test1() returns CsvConversionError? { // string a = check io:fileReadString("a.txt"); // AA aa = check fromCsvStringWithType(a, {}, AA); @@ -330,7 +328,7 @@ // type AAA string[][]; -// @test:Config{ enable } +// @test:Config{enable: enableTest} // function testC() returns error? { // anydata[][] a = [[1, 2], [2, 3], [2, 3]]; // record{}[] b = [{"a": 1, "b": 2}, {"a": 1, "b": 2}, {"a": 1, "b": 2}]; @@ -341,7 +339,9 @@ // io:println(toCsvString(c)); // } -// @test:Config{enable: !enable} +// boolean enableTest = true; + +// @test:Config{enable: !enableTest} // function t() returns error? { // string a = check io:fileReadString("a.txt"); // AA aa = check fromCsvStringWithType(a, {}, AA); diff --git a/ballerina/tests/test_utils.bal b/ballerina/tests/test_utils.bal new file mode 100644 index 0000000..f2d8140 --- /dev/null +++ b/ballerina/tests/test_utils.bal @@ -0,0 +1,19 @@ +function generateErrorMessageForMissingRequiredField(string 'field) returns string { + return string `no matching header value is found for the required field '${'field}'`; +} + +function generateErrorMessageForInvalidCast(string value, string 'type) returns string { + return string `value '${value}' cannot be cast into '${'type}'`; +} + +function generateErrorMessageForInvalidFieldType(string value, string 'key) returns string { + return string `no mapping type found for value '${value}' in key '${'key}'`; +} + +function generateErrorMessageForInvalidValueForArrayType(string value, string index, string arrayType) returns string { + return string `value '${value}' in index '${index}' is not compatible with array type '${arrayType}'`; +} + +function generateErrorMessageForInvalidHeaders(string value, string 'type) returns string{ + return string `value '${value}' cannot be cast into '${'type}', because fields in '${'type}' or the provided expected headers are not matching with the '${value}'`; +} diff --git a/ballerina/tests/types.bal b/ballerina/tests/types.bal index 37fccd3..5d6f2c9 100644 --- a/ballerina/tests/types.bal +++ b/ballerina/tests/types.bal @@ -1114,6 +1114,7 @@ type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, stri type CustomTuple4 [string...]; type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; type CustomTuple6 [anydata...]; +type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; type IntegerArray1 int[]; type IntegerArray2 int[2]; @@ -1571,6 +1572,8 @@ type ClosedCustomTuple4Array CustomTuple4[3]; type CustomTuple5Array CustomTuple5[]; type ClosedCustomTuple5Array CustomTuple5[3]; type CustomTuple6Array CustomTuple6[]; +type CustomTuple7Array CustomTuple7[]; + type ClosedCustomTuple6Array CustomTuple6[3]; type IntegerArray1Array IntegerArray1[]; type ClosedIntegerArray1Array IntegerArray1[3]; diff --git a/ballerina/tests/values.bal b/ballerina/tests/values.bal index f213c17..89bfc7c 100644 --- a/ballerina/tests/values.bal +++ b/ballerina/tests/values.bal @@ -120,3 +120,40 @@ var booleanRecordArray = [ var booleanRecordArray2 = [ {},{} ]; + +string csvStringWithBooleanValues1 = string ` +b1,b2,b3,b4 +true,false,true,false +`; + +string csvStringWithBooleanValues2 = string ` +b1,b2,b3,b4,b5 +true,false, true,false,true +`; + +string csvStringWithBooleanValues3 = string ` +b1,b2,b3 +true, false,true +`; + +string csvStringWithBooleanValues4 = string ` +b1,b2,b3,b4 +true,(), (),false +`; + +string csvStringWithBooleanValues5 = string ` +b1,b2,b3,b4 + +true,false,true,1 +`; + +string csvStringWithBooleanValues6 = string ` +b1,b2 +(),() + +`; + +string csvStringWithBooleanValues7 = string ` +b1,b2,b3,b4 +${b1},${b2},(),${b4} +`; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 291f568..0c5bf67 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -151,11 +151,11 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError this.config = config; Type referredType = TypeUtils.getReferredType(type); if (referredType.getTag() != TypeTags.ARRAY_TAG) { - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type); } else { rootArrayType = (ArrayType) type; rootCsvNode = ValueCreator.createArrayValue(rootArrayType); - expectedArrayElementType = ((ArrayType) TypeUtils.getReferredType(referredType)).getElementType(); + expectedArrayElementType = TypeUtils.getReferredType(((ArrayType) referredType).getElementType()); } switch (expectedArrayElementType.getTag()) { // TODO: Handle readonly and singleton type as expType. diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 5b59ce4..6fb5834 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -61,6 +61,7 @@ static class CsvTree { Type expectedArrayElementType; Type sourceArrayElementType; CsvConfig config; + String[] headers= null; void reset() { currentCsvNode = null; @@ -71,6 +72,7 @@ void reset() { fieldNames.clear(); expectedArrayElementType = null; sourceArrayElementType = null; + headers = null; } @SuppressWarnings("unchecked") @@ -211,8 +213,21 @@ private void constructArrayValuesFromArray(BArray csvElement, Type type, int exp } private void constructArrayValuesFromMap(BMap map, Type type, int expectedSize) { + int size = map.size(); + BString[] keys = new BString[size]; int index = 0; - for (Object v: map.values()) { + if (config.customHeader == null) { + keys = map.getKeys(); + } else { + if (this.headers == null) { + this.headers = createHeaders(new String[size], config); + } + for (int i = 0; i < size; i++) { + keys[i] = StringUtils.fromString(this.headers[i]); + } + } + for (BString key: keys) { + Object v = map.get(key); if (index >= expectedSize) { break; } @@ -246,8 +261,8 @@ private void traverseCsvMap(Object csvElement, Type expectedType, boolean mappin } } - private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, String[] headers, BArray csvElement, int arraySize) { - if (arraySize < headers.length) { + private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, BArray csvElement, int arraySize) { + if (arraySize < this.headers.length) { return false; } if (expectedType instanceof MapType) { @@ -255,14 +270,13 @@ private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, String[] he } Type type = csvElement.getType(); if (type instanceof TupleType) { - return checkExpectedTypeMatchWithHeadersForTuple(expectedType, headers, (TupleType) type); + return checkExpectedTypeMatchWithHeadersForTuple(expectedType, (TupleType) type); } else { - return checkExpectedTypeMatchWithHeadersForArray(expectedType, - headers, csvElement.getElementType(), arraySize); + return checkExpectedTypeMatchWithHeadersForArray(expectedType, csvElement.getElementType(), arraySize); } } - private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, String[] headers, TupleType tupleType) { + private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, TupleType tupleType) { Type type; List tupleTypes = tupleType.getTupleTypes(); Type tupleRestType = tupleType.getRestType(); @@ -274,13 +288,13 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Str return true; } - for (int i = 0; i < headers.length; i++) { + for (int i = 0; i < this.headers.length; i++) { if (i >= tupleTypes.size()) { type = tupleRestType; } else { type = tupleTypes.get(i); } - String header = headers[i]; + String header = this.headers[i]; Field field = this.headerFieldHierarchy.remove(header); if (field != null) { @@ -306,7 +320,7 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Str return false; } - private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, String[] headers, Type arrayType, int arraySize) { + private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Type arrayType, int arraySize) { arrayType = TypeUtils.getReferredType(arrayType); if (expectedType instanceof RecordType) { if (this.restType != null && (this.restType == arrayType @@ -314,8 +328,8 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Str return true; } - for (int i = 0; i < headers.length; i++) { - if (!this.fieldHierarchy.containsKey(headers[i])) { + for (int i = 0; i < this.headers.length; i++) { + if (!this.fieldHierarchy.containsKey(this.headers[i])) { return false; } } @@ -327,9 +341,10 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Str private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean mappingType, Type expectedType) { int arraySize = csvElement.size(); String[] headers = new String[arraySize]; - headers = createHeaders(headers, config); - boolean headersMatchWithExpType = checkExpectedTypeMatchWithHeaders( - expectedType, headers, csvElement, arraySize); + if (this.headers == null) { + this.headers = createHeaders(headers, config); + } + boolean headersMatchWithExpType = checkExpectedTypeMatchWithHeaders(expectedType, csvElement, arraySize); if (!headersMatchWithExpType) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONVERSION_FOR_ARRAY_TO_MAP, csvElement, expectedType); } @@ -340,8 +355,11 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappingType, Type expectedType) { Type fieldType; BString key; + + // TODO: Canges the logic with headers parameter for(int i = 1; i <= arraySize; i++) { - key = StringUtils.fromString(String.valueOf(i)); +// key = StringUtils.fromString(String.valueOf(i)); + key = StringUtils.fromString(this.headers[i - 1]); if (!mappingType) { if (!isKeyBelongsToNonRestType(csvElement.get(i-1), key)) { continue; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 36c8fa8..bcd72ec 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -197,9 +197,10 @@ public static boolean checkTypeCompatibility(Type constraintType, Object csv) { int tag = constraintType.getTag(); if ((csv instanceof BString && (tag == TypeTags.STRING_TAG || isJsonOrAnyDataOrAny(tag))) || (csv instanceof Long && (tag == INT_TAG || isJsonOrAnyDataOrAny(tag))) - || (csv instanceof BDecimal && (tag == TypeTags.DECIMAL_TAG || isJsonOrAnyDataOrAny(tag))) + || (csv instanceof BDecimal && ((tag == TypeTags.DECIMAL_TAG + || tag == TypeTags.FLOAT_TAG) || isJsonOrAnyDataOrAny(tag))) || (csv instanceof Double && ((tag == TypeTags.FLOAT_TAG - || tag == TypeTags.DECIMAL_TAG) || isJsonOrAnyDataOrAny(tag))) + || tag == TypeTags.DECIMAL_TAG) || isJsonOrAnyDataOrAny(tag))) || (Boolean.class.isInstance(csv) && (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag))) || (csv == null && (tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag)))) { return true; From b7a93cd3282e4f8f008a97d7bcc8f8bd8be9389a Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 20 Mar 2024 17:04:55 +0530 Subject: [PATCH 019/147] Add record related tests for fromcsvstring with type function --- ..._csv_string_with_type_with_string_test.bal | 629 +++++++++++++++++- ballerina/tests/from_csv_with_type_test.bal | 22 +- ballerina/tests/values.bal | 25 +- .../stdlib/data/csvdata/FromString.java | 4 +- .../stdlib/data/csvdata/csv/CsvCreator.java | 49 +- .../stdlib/data/csvdata/csv/CsvParser.java | 23 +- 6 files changed, 671 insertions(+), 81 deletions(-) diff --git a/ballerina/tests/from_csv_string_with_type_with_string_test.bal b/ballerina/tests/from_csv_string_with_type_with_string_test.bal index ff48ca8..1766080 100644 --- a/ballerina/tests/from_csv_string_with_type_with_string_test.bal +++ b/ballerina/tests/from_csv_string_with_type_with_string_test.bal @@ -1,69 +1,628 @@ import ballerina/test; @test:Config {enable} -function testFromCsvStringWithTypeForMapAndRecordAsExpectedType() { - BooleanRecord1Array|CsvConversionError cv1br = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertEquals(cv1br, [ +function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { + BooleanRecord1Array|CsvConversionError csvb1br1 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + 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|CsvConversionError csvb2br1 = fromCsvStringWithType(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|CsvConversionError csvb3br1 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); + test:assertTrue(csvb3br1 is CsvConversionError); + test:assertEquals((csvb3br1).message(), generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord1Array|CsvConversionError csvb4br1 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br1, [ + {b1: true, b2: "()", b3: (), b4: false}, + {b1: true, b2: "()", b3: (), b4: false} + ]); + + BooleanRecord1Array|CsvConversionError csvb5br1 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); + test:assertTrue(csvb5br1 is CsvConversionError); + test:assertEquals((csvb5br1).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanRecord1Array|CsvConversionError csvb6br1 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br1 is CsvConversionError); + test:assertEquals((csvb6br1).message(), generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord1Array|CsvConversionError csvb7br1 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br1, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord2Array|CsvConversionError csvb1br2 = fromCsvStringWithType(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|CsvConversionError csvb2br2 = fromCsvStringWithType(csvStringWithBooleanValues2, {}); + test:assertEquals(csvb2br2, [ + {b1: true, b2: false, b3: true, b4: false}, + {b1: true, b2: false, b3: true, b4: false} + ]); + + BooleanRecord2Array|CsvConversionError csvb3br2 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); + test:assertTrue(csvb3br2 is CsvConversionError); + test:assertEquals((csvb3br2).message(), generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord2Array|CsvConversionError csvb4br2 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br2, [ + {b1: true, b2: "()", b3: (), b4: false}, + {b1: true, b2: "()", b3: (), b4: false} + ]); + + BooleanRecord2Array|CsvConversionError csvb5br2 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); + test:assertTrue(csvb5br2 is CsvConversionError); + test:assertEquals((csvb5br2).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanRecord2Array|CsvConversionError csvb7br2 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br2, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord3Array|CsvConversionError csvb1br3 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br3, [ + {b1: true, b3: true}, + {b1: true, b3: true}, + {b1: true, b3: true} + ]); + + BooleanRecord3Array|CsvConversionError csvb2br3 = fromCsvStringWithType(csvStringWithBooleanValues2, {}); + test:assertEquals(csvb2br3, [ + {b1: true, b3: true}, + {b1: true, b3: true} + ]); + + BooleanRecord3Array|CsvConversionError csvb3br3 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br3, [ + {b1: true, b3: true}, + {b1: true, b3: ()}, + {b1: true, b3: false} + ]); + + BooleanRecord3Array|CsvConversionError csvb4br3 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br3, [ + {b1: true, b3: ()}, + {b1: true, b3: ()} + ]); + + BooleanRecord3Array|CsvConversionError csvb5br3 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br3, [ + {b1: true, b3: true}, + {b1: true, b3: true} + ]); + + BooleanRecord3Array|CsvConversionError csvb7br3 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br3, [ + {b1, b3: ()} + ]); + + BooleanRecord4Array|CsvConversionError csvb1br4 = fromCsvStringWithType(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|CsvConversionError csvb2br4 = fromCsvStringWithType(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|CsvConversionError csvb3br4 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br4, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: ()}, + {b1: true, b2: true, b3: false} + ]); + + BooleanRecord4Array|CsvConversionError csvb4br4 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br4, [ + {b1: true, b2: (), b3: (), b4: 0}, + {b1: true, b2: (), b3: (), b4: false} + ]); + + BooleanRecord4Array|CsvConversionError csvb5br4 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br4, [ + {b1: true, b2: false, b3: true, b4: 2}, + {b1: true, b2: false, b3: true, b4: 3} + ]); + + BooleanRecord4Array|CsvConversionError csvb7br4 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br4, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord5Array|CsvConversionError csvb1br5 = fromCsvStringWithType(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|CsvConversionError csvb2br5 = fromCsvStringWithType(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|CsvConversionError csvb3br5 = fromCsvStringWithType(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|CsvConversionError csvb4br5 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br5, [ + {b1: true, b2: (), b3: (), b4: 0, defaultableField: "", nillableField: ()}, + {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord5Array|CsvConversionError csvb5br5 = fromCsvStringWithType(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|CsvConversionError csvb7br5 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br5, [ + {b1, b2, b3: (), b4, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb1br6 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: true, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb2br6 = fromCsvStringWithType(csvStringWithBooleanValues2, {}); + test:assertEquals(csvb2br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: true, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb3br6 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: false, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb4br6 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb5br6 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: true, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb7br6 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br6, [ + {b1, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord7Array|CsvConversionError csvb1br7 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br7 is CsvConversionError); + test:assertEquals((csvb1br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord8Array|CsvConversionError csvb1br8 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br8 is CsvConversionError); + test:assertEquals((csvb1br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord9Array|CsvConversionError csvb1br9 = fromCsvStringWithType(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|CsvConversionError csvb2br9 = fromCsvStringWithType(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|CsvConversionError csvb3br9 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br9, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: ()}, + {b1: true, b2: true, b3: false} + ]); + + BooleanRecord9Array|CsvConversionError csvb4br9 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br9, [ + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} + ]); + + BooleanRecord9Array|CsvConversionError csvb5br9 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br9, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + BooleanRecord9Array|CsvConversionError csvb6br9 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br9 is CsvConversionError); + test:assertEquals((csvb6br9).message(), generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord9Array|CsvConversionError csvb7br9 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br9, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord10Array|CsvConversionError csvb1br10 = fromCsvStringWithType(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|CsvConversionError csvb2br10 = fromCsvStringWithType(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|CsvConversionError csvb3br10 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br10, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false}, + {b1: true, b2: true, b3: false} + ]); + + BooleanRecord10Array|CsvConversionError csvb4br10 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br10, [ + {b1: true, b4: false}, + {b1: true, b4: false} + ]); + + BooleanRecord10Array|CsvConversionError csvb5br10 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br10, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + BooleanRecord10Array|CsvConversionError csvb6br10 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br10, [ {} ]); + + BooleanRecord10Array|CsvConversionError csvb7br10 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br10, [ + {b1, b2, b4} + ]); + + BooleanRecord11Array|CsvConversionError csvb1br11 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br11, [ + {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: ()} + ]); + + BooleanRecord11Array|CsvConversionError csvb2br11 = fromCsvStringWithType(csvStringWithBooleanValues2, {}); + 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|CsvConversionError csvb3br11 = fromCsvStringWithType(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|CsvConversionError csvb4br11 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br11, [ + {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()}, + {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord11Array|CsvConversionError csvb5br11 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br11, [ + {b1: true, b2: false, b3: true, b4: "2", defaultableField: "", nillableField: ()}, + {b1: true, b2: false, b3: true, b4: "3", defaultableField: "", nillableField: ()} + ]); + + BooleanRecord11Array|CsvConversionError csvb6br11 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br11 is CsvConversionError); + test:assertEquals((csvb6br11).message(), generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord11Array|CsvConversionError csvb7br11 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br11, [ + {b1, b2, b3, b4, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord12Array|CsvConversionError csvb1br12 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br12 is CsvConversionError); + test:assertEquals((csvb1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord13Array|CsvConversionError csvb1br13 = fromCsvStringWithType(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|CsvConversionError csvb2br13 = fromCsvStringWithType(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|CsvConversionError csvb3br13 = fromCsvStringWithType(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|CsvConversionError csvb4br13 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br13, [ + {b1: true, b2: "()", b3: "()", b4: false, defaultableField: "", nillableField: ()}, + {b1: true, b2: "()", b3: "null", b4: false, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord13Array|CsvConversionError csvb5br13 = fromCsvStringWithType(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|CsvConversionError csvb6br13 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br13, [ + {b2: "()", b3: "()", defaultableField: "", nillableField: ()} + ]); + + BooleanRecord13Array|CsvConversionError csvb7br13 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br13, [ + {b1, b2, b3: "()", b4, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord14Array|CsvConversionError csvb7br14 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb7br14 is CsvConversionError); + test:assertEquals((csvb7br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); } -// @test:Config {enable} -// function testFromCsvStringWithTypeForMapAndRecordAsExpectedType2() { - -// } +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { + BooleanRecord15Array|CsvConversionError csvb1br15 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br15 is CsvConversionError); + test:assertEquals((csvb1br15).message(), generateErrorMessageForInvalidCast("true", "int")); -// @test:Config {enable} -// function testFromCsvStringWithTypeForMapAndMapAsExpectedType() { + BooleanRecord15Array|CsvConversionError csvb6br15 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br15 is CsvConversionError); + test:assertEquals((csvb6br15).message(), generateErrorMessageForMissingRequiredField("b1")); -// } + BooleanRecord15Array|CsvConversionError csvb7br15 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertTrue(csvb7br15 is CsvConversionError); + test:assertEquals((csvb7br15).message(), generateErrorMessageForInvalidCast("true", "int")); -// @test:Config {enable} -// function testFromCsvStringWithTypeForMapAndArrayAsExpectedType() { - -// } + BooleanRecord16Array|CsvConversionError csvb1br16 = fromCsvStringWithType(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} + ]); -// @test:Config {enable} -// function testFromCsvStringWithTypeForMapAndTupleAsExpectedType() { + BooleanRecord16Array|CsvConversionError csvb2br16 = fromCsvStringWithType(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|CsvConversionError csvb3br16 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br16, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: ()}, + {b1: true, b2: true, b3: false} + ]); -// @test:Config {enable} -// function testFromCsvStringWithTypeForTupleAndRecordAsExpectedType() { + BooleanRecord16Array|CsvConversionError csvb4br16 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br16, [ + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} + ]); -// } + BooleanRecord16Array|CsvConversionError csvb5br16 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br16, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); -// @test:Config {enable} -// function testFromCsvStringWithTypeForTupleAndRecordAsExpectedType2() { + BooleanRecord16Array|CsvConversionError csvb6br16 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br16, [ + {b2: (), b3: ()} + ]); -// } + BooleanRecord16Array|CsvConversionError csvb7br16 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br16, [ + {b1, b2, b3: (), b4} + ]); -// @test:Config {enable} -// function testFromCsvStringWithTypeForTupleAndTupleAsExpectedType() { + BooleanRecord17Array|CsvConversionError csvb1br17 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br17, [{}, {}, {}]); -// } + BooleanRecord17Array|CsvConversionError csvb4br17 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br17, [{b4: 0}, {b1: 1}]); -// @test:Config {enable} -// function testFromCsvStringWithTypeForTupleAndMapAsExpectedType() { + BooleanRecord17Array|CsvConversionError csvb6br17 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br17, [{}]); -// } + BooleanRecord17Array|CsvConversionError csvb7br17 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br17, [{}]); + + BooleanRecord18Array|CsvConversionError csvb1br18 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br18, [{b2: false}, {b2: false}, {b2: false}]); + + BooleanRecord18Array|CsvConversionError csvb4br18 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); + test:assertTrue(csvb4br18 is CsvConversionError); + test:assertEquals((csvb4br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanRecord18Array|CsvConversionError csvb6br18 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br18 is CsvConversionError); + test:assertEquals((csvb6br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanRecord18Array|CsvConversionError csvb7br18 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br18, [{b2, b3: ()}]); +} // @test:Config {enable} -// function testFromCsvStringWithTypeForTupleAndArrayAsExpectedType() { +// function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { // } // @test:Config {enable} -// function testFromCsvStringWithTypeFunctionWithTypeCompatibility() { +// function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { // } -boolean enable = !true; +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { + BooleanTuple1Array|CsvConversionError bm1bt = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(bm1bt, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); +} + +@test:Config {enable} +function testFromCsvStringWithTypeFunctionWithTypeCompatibility() { + string value = string ` + i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 + ${i1},${i2},${s1},${s2},${b1},${b2},(),(),${f1}, ${f2},${d1},${d2},${b1},${d1},${b2},${d2} + ${i1},${i2},${s1},${s2},${b1},${b2},(),(), ${f1},${f2},${d1},${d2},${b1},${d1},${b2},${d2} + `; + string value2 = string ` + i1, s1, b1, n1, f1, d1, j1, a1, s2, s3, j2, a2 + ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3},${b2}, ${d2} + `; + string value3 = string ` + i1, s1, b1, n1, f1, d1, j1, a1, s2, s3 + ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3} + `; + + CustomRecord27Array|CsvConversionError vcr27a = fromCsvStringWithType(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|CsvConversionError v2cr27a = fromCsvStringWithType(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|CsvConversionError v3cr27a = fromCsvStringWithType(value3, {}); + test:assertEquals(v3cr27a, [ + {i1, s1, b1, n1, f1, d1, a1: 2.234, j1: b1, defaultableField: "", nillableField: null, s2, s3} + ]); + + record{|int...;|}[]|CsvConversionError irrma = fromCsvStringWithType(string ` + a, b, c + 1, a, 2.3 + 1, -2, true + hello, -2, hello`); + test:assertEquals(irrma , [ + {a:1}, + {a: i1, b: i2}, + {b: i2} + ]); + + record{|decimal...;|}[]|CsvConversionError drra = fromCsvStringWithType(string `a, b, c + 2.234, invalid , 1 + ${f2}, 0, 2.3d + invalid, ${d2}, ${f3}`); + test:assertTrue(drra is record{|decimal...;|}[]); + test:assertEquals(drra , [ + {a: d1, c: 1.0}, + {a: f2, b: d3}, + {b: -3.21d, c: f3} + ]); + + record{|string...;|}[]|CsvConversionError srra = fromCsvStringWithType(string ` + a, b, c + 1, a, 2.3 + 1, -2, true + hello, -2, hello`); + test:assertTrue(srra is record{|string...;|}[]); + test:assertEquals(srra , [ + {a: "1", b: "a", c: "2.3"}, + {a: "1", b: "-2", c: "true"}, + {a: "hello", b: "-2", c: "hello"} + ]); + + record{|float...;|}[]|CsvConversionError frra = fromCsvStringWithType(string `a, b, c + 1.2, invalid , 1 + ${d2}, ${d3}, true + ${d4}, ${f2}, 0.0`); + test:assertEquals(frra , [ + {a: 1.2, c: 1.0}, + {a: d2, b: d3}, + {a: d4, b: f2, c: 0.0} + ]); + + record{float a; decimal b; string c;}[]|CsvConversionError mrra = fromCsvStringWithType(string `a, b,c + 1.23, 1.23, 1.23 + 0,0,0 + 0.0,0.0,0.0 + -1.2,-1.2,-1.2`); + test:assertEquals(mrra, [ + {a: 1.23, b: 1.23, c: "1.23"}, + {a: 0, b: 0, c: "0"}, + {a: 0, b: 0, c: "0.0"}, + {a: -1.2, b: -1.2, c: "-1.2"} + ]); + + record{|float a; decimal b; string c; int d;|}[]|CsvConversionError m2rra = fromCsvStringWithType(string `a, b,c,d + 1, 1, 1,1 + 0,0,0,0 + -1,-1,-1,-1`); + test:assertEquals(m2rra, [ + {a: 1, b: 1, c: "1", d: 1}, + {a: 0, b: 0, c: "0", d: 0}, + {a: -1, b: -1, c: "-1", d: -1} + ]); + + record{int d;}[]|CsvConversionError m3rra = fromCsvStringWithType(string `a, b,c,d + 1.2, abc, true,1.0`); + test:assertTrue(m3rra is CsvConversionError); + test:assertEquals((m3rra).message(), generateErrorMessageForInvalidCast("1.0", "int")); + + record{int b; boolean a;}[]|CsvConversionError m4rra = fromCsvStringWithType(string `a, b + 1, 1 + 0,0`); + test:assertEquals(m4rra, [ + {a: true, b: 1}, + {a: false, b:0} + ]); +} + +boolean enable = true; @test:Config {enable: !enable} function test() { - BooleanRecord1Array|CsvConversionError cv1br = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertEquals(cv1br, [ - {} + BooleanRecord13Array|CsvConversionError csvb6br13 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br13, [ + {b2: "()", b3: "()", defaultableField: "", nillableField: ()}, + {b2: "()", b3: "()", defaultableField: "", nillableField: ()} ]); } diff --git a/ballerina/tests/from_csv_with_type_test.bal b/ballerina/tests/from_csv_with_type_test.bal index b13b293..414756d 100644 --- a/ballerina/tests/from_csv_with_type_test.bal +++ b/ballerina/tests/from_csv_with_type_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeForMapAndRecordAsExpectedType() { BooleanRecord1Array|CsvConversionError bm1br1 = fromCsvWithType([bm1, bm1], {}, BooleanRecord1Array); test:assertTrue(bm1br1 is CsvConversionError); @@ -192,7 +192,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType() { test:assertEquals((bm5br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); } -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { BooleanRecord9Array|CsvConversionError bm1br9 = fromCsvWithType([bm1, bm1], {}, BooleanRecord9Array); test:assertTrue(bm1br9 is CsvConversionError); @@ -449,7 +449,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { ]); } -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeForMapAndMapAsExpectedType() { BooleanMapArray|CsvConversionError bm1bma = fromCsvWithType([bm1, bm1], {}, BooleanMapArray); test:assertEquals(bm1bma, [ @@ -721,7 +721,7 @@ function testFromCsvWithTypeForMapAndMapAsExpectedType() { ]); } -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeForMapAndArrayAsExpectedType() { BooleanArrayArray|CsvConversionError bm1ba = fromCsvWithType([bm1, bm1], {}, BooleanArrayArray); test:assertEquals(bm1ba, [ @@ -884,7 +884,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { test:assertEquals((bm5sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeForMapAndTupleAsExpectedType() { BooleanTuple1Array|CsvConversionError bm1bt = fromCsvWithType([bm1, bm1], {}, BooleanTuple1Array); test:assertEquals(bm1bt, [ @@ -1227,7 +1227,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { test:assertEquals((bm5s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { StringRecord1Array|CsvConversionError st1sr1 = fromCsvWithType([st1, st1], {}, StringRecord1Array); test:assertTrue(st1sr1 is CsvConversionError); @@ -1482,7 +1482,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { ]); } -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { StringRecord1Array|CsvConversionError st3sr1 = fromCsvWithType([st3, st3], {}, StringRecord1Array); test:assertTrue(st3sr1 is CsvConversionError); @@ -1697,7 +1697,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { ]); } -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { StringTuple1Array|CsvConversionError st1st1 = fromCsvWithType([st1, st1], {}, StringTuple1Array); test:assertEquals(st1st1, [ @@ -1859,7 +1859,7 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { test:assertEquals((st4bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); } -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeForTupleAndMapAsExpectedType() { StringMapArray|CsvConversionError st1sma = fromCsvWithType([st1, st1], {}, StringMapArray); test:assertEquals(st1sma , [ @@ -2030,7 +2030,7 @@ function testFromCsvWithTypeForTupleAndMapAsExpectedType() { ])); } -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { StringArrayArray|CsvConversionError st1saa = fromCsvWithType([st1, st1], {}, StringArrayArray); test:assertEquals(st1saa , [ @@ -2185,7 +2185,7 @@ function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { test:assertEquals((st3dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); } -@test:Config {enable: enable} +@test:Config {enable} function testFromCsvWithTypeFunctionWithTypeCompatibility() { var value = {i1, i2, s1, s2, b1, b2, n1, n2, f1, f2, d1, d2, j1: b1, a1: d1, j2: b2, a2: d2}; var value2 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3, j2: b2, a2: d2}; diff --git a/ballerina/tests/values.bal b/ballerina/tests/values.bal index 89bfc7c..1c9b602 100644 --- a/ballerina/tests/values.bal +++ b/ballerina/tests/values.bal @@ -123,32 +123,45 @@ var booleanRecordArray2 = [ string csvStringWithBooleanValues1 = string ` b1,b2,b3,b4 +true,false,true,false +true,false, true,false true,false,true,false `; string csvStringWithBooleanValues2 = string ` b1,b2,b3,b4,b5 true,false, true,false,true -`; +true,false, true,false,true`; string csvStringWithBooleanValues3 = string ` -b1,b2,b3 + b1,b2,b3 +${" "}${" "} true, false,true +${" "} + TRUE, FALSE,() +${" "} + +true, true,FALSE + `; string csvStringWithBooleanValues4 = string ` -b1,b2,b3,b4 -true,(), (),false + b1,b2,b3,b4 + true,(), (),0 + 1,(), null,false + `; string csvStringWithBooleanValues5 = string ` b1,b2,b3,b4 -true,false,true,1 +true,false,true,2 + +true,false,true,3 `; string csvStringWithBooleanValues6 = string ` -b1,b2 +b2,b3 (),() `; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index 68e0e9f..e7ff817 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -123,11 +123,11 @@ private static BDecimal stringToDecimal(String value) throws NumberFormatExcepti } private static Object stringToBoolean(String value) throws NumberFormatException { - if ("true".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value)) { + if ("true".equalsIgnoreCase(value) || "TRUE".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value)) { return true; } - if ("false".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value)) { + if ("false".equalsIgnoreCase(value) || "FALSE".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value)) { return false; } return returnError(value, "boolean"); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 28b0ddc..156f99d 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -21,11 +21,7 @@ import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ValueCreator; -import io.ballerina.runtime.api.types.ArrayType; -import io.ballerina.runtime.api.types.MapType; -import io.ballerina.runtime.api.types.RecordType; -import io.ballerina.runtime.api.types.TupleType; -import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.*; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; @@ -36,6 +32,8 @@ import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; +import java.util.Map; + /** * Create objects for partially parsed csv. * @@ -46,7 +44,7 @@ public class CsvCreator { static Object initRowValue(Type expectedType) { switch (expectedType.getTag()) { case TypeTags.RECORD_TYPE_TAG: - return ValueCreator.createRecordValue((RecordType) expectedType); + return ValueCreator.createRecordValue(expectedType.getPackage(), expectedType.getName()); case TypeTags.MAP_TAG: return ValueCreator.createMapValue((MapType) expectedType); case TypeTags.TUPLE_TAG: @@ -59,37 +57,54 @@ static Object initRowValue(Type expectedType) { } static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, - BString value, Type type, CsvConfig config) { - Object currentJson = sm.currentCsvNode; + BString value, Type type, CsvConfig config, Type exptype) { + Object currentCsv = sm.currentCsvNode; Object convertedValue = convertToExpectedType(value, type, config); if (convertedValue instanceof BError) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, type, value); + if (ignoreIncompatibilityErrorsForMaps(sm, type, exptype)) { + return null; + } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, value, type); } - Type currentCsvNodeType = TypeUtils.getType(currentJson); + Type currentCsvNodeType = TypeUtils.getType(currentCsv); switch (currentCsvNodeType.getTag()) { case TypeTags.MAP_TAG: case TypeTags.RECORD_TYPE_TAG: - ((BMap) currentJson).put(StringUtils.fromString(sm.headers.get(sm.columnIndex)), + ((BMap) currentCsv).put(StringUtils.fromString(sm.headers.get(sm.columnIndex)), convertedValue); - return currentJson; + return currentCsv; case TypeTags.ARRAY_TAG: // Handle projection in array. ArrayType arrayType = (ArrayType) currentCsvNodeType; if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < sm.columnIndex) { - return currentJson; + return currentCsv; } - ((BArray) currentJson).add(sm.columnIndex, convertedValue); - return currentJson; + ((BArray) currentCsv).add(sm.columnIndex, convertedValue); + return currentCsv; case TypeTags.TUPLE_TAG: - ((BArray) currentJson).add(sm.columnIndex, convertedValue); - return currentJson; + ((BArray) currentCsv).add(sm.columnIndex, convertedValue); + return currentCsv; default: return convertedValue; } } + private static boolean ignoreIncompatibilityErrorsForMaps(CsvParser.StateMachine sm, Type type, Type exptype) { + if (exptype.getTag() == TypeTags.RECORD_TYPE_TAG) { + String header = sm.headers.get(sm.columnIndex); + Map fields = sm.fieldNames; + if (fields.containsKey(header)) { + return false; + } + return true; + } else if (exptype.getTag() == TypeTags.MAP_TAG) { + return true; + } + return false; + } + private static Object convertToExpectedType(BString value, Type type, CsvConfig config) { if (type.getTag() == TypeTags.ANYDATA_TAG) { return FromString.fromStringWithType(value, PredefinedTypes.TYPE_JSON, config); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 0c5bf67..b7275b0 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -114,10 +114,16 @@ public void reset() { rootArrayType = null; config = null; lineNumber = 0; + expectedArrayElementType = null; + headers = new ArrayList<>(); + currentEscapeCharacters = new Stack<>(); + charBuff = new char[1024]; + charBuffIndex = 0; + skipColumnIndexes = new ArrayList<>(); } private static boolean isWhitespace(char ch) { - return ch == SPACE || ch == HZ_TAB || ch == CR; + return ch == SPACE || ch == HZ_TAB || ch == CR || ch == NEWLINE; } private static void throwExpected(String... chars) throws CsvParserException { @@ -251,7 +257,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C continue; } if (skipHeaders || customHeader != null) { - if (sm.isEndOfTheRow(ch)) { + if (!sm.peek().isEmpty() && sm.isEndOfTheRow(ch)) { checkAndAddCustomHeaders(sm.headers, customHeader, sm.config.skipHeaders); sm.lineNumber++; state = HEADER_END_STATE; @@ -262,7 +268,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C addHeader(sm); sm.columnIndex++; continue; - } else if (sm.isEndOfTheRow(ch)) { + } else if (!sm.peek().isEmpty() && sm.isEndOfTheRow(ch)) { addHeader(sm); finalizeHeaders(sm); sm.columnIndex = 0; @@ -340,10 +346,6 @@ private boolean ignoreHeader(StateMachine sm) { private void addHeader(StateMachine sm) throws CsvParserException { String value = sm.value(); if (sm.expectedArrayElementType instanceof RecordType) { - if (validateHeaderValueWithRecordFields(sm, value)) { - throw new CsvParserException("Header " + value + " does not match " + - "with any record key in the expected type"); - } Field field = sm.fieldHierarchy.get(value); if (field != null) { sm.fieldNames.put(value, field); @@ -354,8 +356,7 @@ private void addHeader(StateMachine sm) throws CsvParserException { } private boolean validateHeaderValueWithRecordFields(StateMachine sm, String value) { - return sm.restType != null && sm.restType.getTag() != TypeTags.ANYDATA_TAG - && !sm.fieldHierarchy.containsKey(StringUtils.fromString(value)); + return sm.fieldHierarchy.containsKey(value) || sm.restType != null; } } @@ -403,6 +404,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.lineNumber++; handleCsvRow(sm); if (ch == EOF) { + checkOptionalFieldsAndLogError(sm.fieldHierarchy); state = ROW_END_STATE; } } else if (StateMachine.isWhitespace(ch)) { @@ -484,7 +486,8 @@ private void addRowValue(StateMachine sm) throws CsvParserException { } if (type != null) { - CsvCreator.convertAndUpdateCurrentJsonNode(sm, StringUtils.fromString(sm.value()), type, sm.config); + CsvCreator.convertAndUpdateCurrentJsonNode(sm, + StringUtils.fromString(sm.value()), type, sm.config, exptype); } sm.columnIndex++; } From 23a025be19d5c3f9c60e6f796552d1ae8eb01ce4 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 22 Mar 2024 17:49:06 +0530 Subject: [PATCH 020/147] Add tests for arrays & maps for fromStringWithType --- ..._csv_string_with_type_with_string_test.bal | 1298 ++++++++++++++++- ballerina/tests/types.bal | 2 + ballerina/tests/values.bal | 2 +- native/src/main/resources/error.properties | 2 +- 4 files changed, 1266 insertions(+), 38 deletions(-) diff --git a/ballerina/tests/from_csv_string_with_type_with_string_test.bal b/ballerina/tests/from_csv_string_with_type_with_string_test.bal index 1766080..022e831 100644 --- a/ballerina/tests/from_csv_string_with_type_with_string_test.bal +++ b/ballerina/tests/from_csv_string_with_type_with_string_test.bal @@ -484,28 +484,1169 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { test:assertEquals(csvb7br18, [{b2, b3: ()}]); } -// @test:Config {enable} -// function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { + BooleanArrayArray|CsvConversionError cv1baa = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cv1baa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanArrayArray|CsvConversionError cv2baa = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cv2baa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + BooleanArrayArray|CsvConversionError cv3baa = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertTrue(cv3baa is CsvConversionError); + test:assertEquals((cv3baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanArrayArray|CsvConversionError cv4baa = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertTrue(cv4baa is CsvConversionError); + test:assertEquals((cv4baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanArrayArray|CsvConversionError cv5baa = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertTrue(cv5baa is CsvConversionError); + test:assertEquals((cv5baa).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanArrayArray|CsvConversionError cv6baa = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertTrue(cv6baa is CsvConversionError); + test:assertEquals((cv6baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanArrayArray|CsvConversionError cv7baa = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertTrue(cv7baa is CsvConversionError); + test:assertEquals((cv7baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + NillableBooleanArrayArray|CsvConversionError cv1nbaa = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cv1nbaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableBooleanArrayArray|CsvConversionError cv2nbaa = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cv2nbaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanArrayArray|CsvConversionError cv3nbaa = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cv3nbaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableBooleanArrayArray|CsvConversionError cv4nbaa = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cv4nbaa, [ + [true, (), (), false], + [true, (), (), false] + ]); + + NillableBooleanArrayArray|CsvConversionError cv5nbaa = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertTrue(cv5nbaa is CsvConversionError); + test:assertEquals((cv5nbaa).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanArrayArray|CsvConversionError cv6nbaa = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cv6nbaa, [ + [(), ()] + ]); + + NillableBooleanArrayArray|CsvConversionError cv7nbaa = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cv7nbaa, [ + [b1, b2, (), b4] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv1niubaa = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cv1niubaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv2niubaa = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cv2niubaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv3niubaa = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cv3niubaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv4niubaa = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cv4niubaa, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv5niubaa = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(cv5niubaa, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv6niubaa = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cv6niubaa, [ + [(), ()] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv7niubaa = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cv7niubaa, [ + [b1, b2, (), b4] + ]); + + StringArray1Array|CsvConversionError cv1saa = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cv1saa, [ + ["true", "false", "true", "false"], + ["true", "false", "true", "false"], + ["true", "false", "true", "false"] + ]); + + StringArray1Array|CsvConversionError cv2saa = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cv2saa, [ + ["true", "false", "true", "false", "true"], + ["true", "false", "true", "false", "true"] + ]); + + StringArray1Array|CsvConversionError cv3saa = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cv3saa, [ + ["true", "false", "true"], + ["TRUE", "FALSE", "()"], + ["true", "true", "FALSE"] + ]); + + StringArray1Array|CsvConversionError cv4saa = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cv4saa, [ + ["true", "()", "()", "0"], + ["1", "()", "null", "false"] + ]); + + StringArray1Array|CsvConversionError cv5saa = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(cv5saa, [ + ["true", "false", "true", "2"], + ["true", "false", "true", "3"] + ]); + + StringArray1Array|CsvConversionError cv6saa = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cv6saa, [ + ["()", "()"] + ]); + + StringArray1Array|CsvConversionError cv7saa = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cv7saa, [ + ["true", "false", "()", "false"] + ]); + + StringArray2Array|CsvConversionError cv1s2aa = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cv1s2aa, [ + ["true", "false"], + ["true", "false"], + ["true", "false"] + ]); + + StringArray2Array|CsvConversionError cv2s2aa = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cv2s2aa, [ + ["true", "false"], + ["true", "false"] + ]); + + StringArray2Array|CsvConversionError cv3s2aa = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cv3s2aa, [ + ["true", "false"], + ["TRUE", "FALSE"], + ["true", "true"] + ]); + + StringArray2Array|CsvConversionError cv4s2aa = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cv4s2aa, [ + ["true", "()"], + ["1", "()"] + ]); + + StringArray2Array|CsvConversionError cv5s2aa = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(cv5s2aa, [ + ["true", "false"], + ["true", "false"] + ]); + + StringArray2Array|CsvConversionError cv6s2aa = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cv6s2aa, [ + ["()", "()"] + ]); + + StringArray2Array|CsvConversionError cv7s2aa = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cv7s2aa, [ + ["true", "false"] + ]); + + JsonArray1Array|CsvConversionError cv1jaa = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cv1jaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + JsonArray1Array|CsvConversionError cv2jaa = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cv2jaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + JsonArray1Array|CsvConversionError cv3jaa = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cv3jaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + JsonArray1Array|CsvConversionError cv4jaa = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cv4jaa, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + JsonArray1Array|CsvConversionError cv5jaa = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(cv5jaa, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + JsonArray1Array|CsvConversionError cv6jaa = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cv6jaa, [ + [(), ()] + ]); + + JsonArray1Array|CsvConversionError cv7jaa = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cv7jaa, [ + [b1, b2, (), b4] + ]); + + AnydataArray1Array|CsvConversionError cv1anydaa = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cv1anydaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + AnydataArray1Array|CsvConversionError cv2anydaa = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cv2anydaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + AnydataArray1Array|CsvConversionError cv3anydaa = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cv3anydaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + AnydataArray1Array|CsvConversionError cv4anydaa = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cv4anydaa, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + AnydataArray1Array|CsvConversionError cv5anydaa = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(cv5anydaa, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + AnydataArray1Array|CsvConversionError cv6anydaa = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cv6anydaa, [ + [(), ()] + ]); + + AnydataArray1Array|CsvConversionError cv7anydaa = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cv7anydaa, [ + [b1, b2, (), b4] + ]); + + DecimalArray1Array|CsvConversionError cv1daa = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertTrue(cv1daa is CsvConversionError); + test:assertEquals((cv1daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); + + DecimalArray1Array|CsvConversionError cv3daa = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertTrue(cv3daa is CsvConversionError); + test:assertEquals((cv3daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); + + DecimalArray1Array|CsvConversionError cv6daa = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertTrue(cv6daa is CsvConversionError); + test:assertEquals((cv6daa).message(), generateErrorMessageForInvalidCast("()", "decimal")); + + DecimalArray1Array|CsvConversionError cv7daa = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertTrue(cv7daa is CsvConversionError); + test:assertEquals((cv7daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); +} + +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { + BooleanTuple1Array|CsvConversionError cbv1bt1 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt1, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple1Array|CsvConversionError cbv2bt1 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt1, [ + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple1Array|CsvConversionError cbv3bt1 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt1 is CsvConversionError); + test:assertEquals((cbv3bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple1Array|CsvConversionError cbv5bt1 = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt1 is CsvConversionError); + test:assertEquals((cbv5bt1).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanTuple1Array|CsvConversionError cbv7bt1 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt1 is CsvConversionError); + test:assertEquals((cbv7bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple2Array|CsvConversionError cbv1bt2 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt2, [ + [true, false], + [true, false], + [true, false] + ]); + + BooleanTuple2Array|CsvConversionError cbv2bt2 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt2, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|CsvConversionError cbv3bt2 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt2, [ + [true, false], + [true, false], + [true, true] + ]); + + BooleanTuple2Array|CsvConversionError cbv4bt2 = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertTrue(cbv4bt2 is CsvConversionError); + test:assertEquals((cbv4bt2).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple3Array|CsvConversionError cbv1bt3 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt3, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple3Array|CsvConversionError cbv2bt3 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt3, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + BooleanTuple3Array|CsvConversionError cbv3bt3 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt3 is CsvConversionError); + test:assertEquals((cbv3bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple3Array|CsvConversionError cbv5bt3 = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt3 is CsvConversionError); + test:assertEquals((cbv5bt3).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanTuple3Array|CsvConversionError cbv7bt3 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt3 is CsvConversionError); + test:assertEquals((cbv7bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|CsvConversionError cbv1bt4 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt4, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple4Array|CsvConversionError cbv2bt4 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt4, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + BooleanTuple4Array|CsvConversionError cbv3bt4 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt4 is CsvConversionError); + test:assertEquals((cbv3bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|CsvConversionError cbv4bt4 = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertTrue(cbv4bt4 is CsvConversionError); + test:assertEquals((cbv4bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|CsvConversionError cbv5bt4 = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt4 is CsvConversionError); + test:assertEquals((cbv5bt4).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanTuple4Array|CsvConversionError cbv6bt4 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertTrue(cbv6bt4 is CsvConversionError); + test:assertEquals((cbv6bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|CsvConversionError cbv7bt4 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt4 is CsvConversionError); + test:assertEquals((cbv7bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + NillableBooleanTuple5Array|CsvConversionError cbv1bt5 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt5, [ + [true, false, true, false, null], + [true, false, true, false, null], + [true, false, true, false, null] + ]); + + NillableBooleanTuple5Array|CsvConversionError cbv2bt5 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt5, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanTuple5Array|CsvConversionError cbv3bt5 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt5, [ + [true, false, true, null, null], + [true, false, (), null, null], + [true, true, false, null, null] + ]); + + NillableBooleanTuple5Array|CsvConversionError cbv4bt5 = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt5, [ + [true, (), (), false, null], + [true, (), (), false, null] + ]); + + NillableBooleanTuple5Array|CsvConversionError cbv5bt5 = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt5 is CsvConversionError); + test:assertEquals((cbv5bt5).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanTuple5Array|CsvConversionError cbv6bt5 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt5, [ + [(), (), null, null, null] + ]); + + NillableBooleanTuple5Array|CsvConversionError cbv7bt5 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt5, [ + [b1, b2, (), b4, null] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv1bt6 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt6, [ + [true, false], + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv2bt6 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt6, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv3bt6 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt6, [ + [true, false], + [true, false], + [true, true] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv4bt6 = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt6, [ + [true, ()], + [true, ()] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv6bt6 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt6, [ + [(), null] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv7bt6 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt6, [ + [b1, b2] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv1bt7 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt7, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv2bt7 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt7, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv3bt7 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt7, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv4bt7 = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt7, [ + [true, (), (), false], + [true, (), (), false] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv5bt7 = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt7 is CsvConversionError); + test:assertEquals((cbv5bt7).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanTuple7Array|CsvConversionError cbv6bt7 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt7, [ + [(), ()] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv7bt7 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt7, [ + [b1, b2, (), false] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv1bt8 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt8, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv2bt8 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt8, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv3bt8 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt8, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv4bt8 = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt8, [ + [true, (), (), false], + [true, (), (), false] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv5bt8 = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt8 is CsvConversionError); + test:assertEquals((cbv5bt8).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanTuple8Array|CsvConversionError cbv6bt8 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt8, [ + [(), ()] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv7bt8 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt8, [ + [b1, b2, (), false] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv1bt9 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt9, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv2bt9 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt9, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv3bt9 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt9, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv4bt9 = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt9, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv5bt9 = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(cbv5bt9, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv6bt9 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt9, [ + [(), ()] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv7bt9 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt9, [ + [b1, b2, (), false] + ]); + + NilTuple3Array|CsvConversionError cbv1nt3 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertTrue(cbv1nt3 is CsvConversionError); + test:assertEquals((cbv1nt3).message(), generateErrorMessageForInvalidCast("true", "()")); + + NilTuple3Array|CsvConversionError cbv3nt3 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertTrue(cbv3nt3 is CsvConversionError); + test:assertEquals((cbv3nt3).message(), generateErrorMessageForInvalidCast("true", "()")); + + NilTuple3Array|CsvConversionError cbv6nt3 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cbv6nt3, [ + [(), ()] + ]); + + AnydataTuple3Array|CsvConversionError cbv1anyd3 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1anyd3, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + AnydataTuple3Array|CsvConversionError cbv2anyd3 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2anyd3, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + AnydataTuple3Array|CsvConversionError cbv3anyd3 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cbv3anyd3, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + AnydataTuple3Array|CsvConversionError cbv4anyd3 = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cbv4anyd3, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + AnydataTuple3Array|CsvConversionError cbv5anyd3 = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(cbv5anyd3, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + AnydataTuple3Array|CsvConversionError cbv6anyd3 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cbv6anyd3, [ + [(), ()] + ]); + + AnydataTuple3Array|CsvConversionError cbv7anyd3 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cbv7anyd3, [ + [b1, b2, (), false] + ]); +} + +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { + JsonTuple3Array|CsvConversionError cbv1j3 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1j3, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + JsonTuple3Array|CsvConversionError cbv2j3 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2j3, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + JsonTuple3Array|CsvConversionError cbv3j3 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cbv3j3, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + JsonTuple3Array|CsvConversionError cbv4j3 = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cbv4j3, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + JsonTuple3Array|CsvConversionError cbv5j3 = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(cbv5j3, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + JsonTuple3Array|CsvConversionError cbv6j3 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cbv6j3, [ + [(), ()] + ]); + + JsonTuple3Array|CsvConversionError cbv7j3 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cbv7j3, [ + [b1, b2, (), false] + ]); + + StringTuple3Array|CsvConversionError cbv1s3 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1s3, [ + ["true", "false", "true", "false"], + ["true", "false", "true", "false"], + ["true", "false", "true", "false"] + ]); + + StringTuple3Array|CsvConversionError cbv2s3 = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(cbv2s3, [ + ["true", "false", "true", "false", "true"], + ["true", "false", "true", "false", "true"] + ]); + + StringTuple3Array|CsvConversionError cbv3s3 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(cbv3s3, [ + ["true", "false", "true"], + ["TRUE", "FALSE", "()"], + ["true", "true", "FALSE"] + ]); + + StringTuple3Array|CsvConversionError cbv4s3 = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(cbv4s3, [ + ["true", "()", "()", "0"], + ["1", "()", "null", "false"] + ]); + + StringTuple3Array|CsvConversionError cbv5s3 = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(cbv5s3, [ + ["true", "false", "true", "2"], + ["true", "false", "true", "3"] + ]); + + StringTuple3Array|CsvConversionError cbv6s3 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(cbv6s3, [ + ["()", "()"] + ]); + + StringTuple3Array|CsvConversionError cbv7s3 = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(cbv7s3, [ + ["true", "false", "()", "false"] + ]); -// } + DecimalTuple3Array|CsvConversionError cbv1dt3 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertTrue(cbv1dt3 is CsvConversionError); + test:assertEquals((cbv1dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); -// @test:Config {enable} -// function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { + DecimalTuple3Array|CsvConversionError cbv3dt3 = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertTrue(cbv3dt3 is CsvConversionError); + test:assertEquals((cbv3dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); -// } + DecimalTuple3Array|CsvConversionError cbv6dt3 = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertTrue(cbv6dt3 is CsvConversionError); + test:assertEquals((cbv6dt3).message(), generateErrorMessageForInvalidCast("()", "decimal")); +} @test:Config {enable} -function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { - BooleanTuple1Array|CsvConversionError bm1bt = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(bm1bt, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] +function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { + BooleanMapArray|CsvConversionError bv1bma = fromCsvStringWithType(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|CsvConversionError bv2bma = fromCsvStringWithType(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|CsvConversionError bv3bma = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(bv3bma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false}, + {b1: true, b2: true, b3: false} + ]); + + BooleanMapArray|CsvConversionError bv4bma = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(bv4bma, [ + {b1: true, b4: false}, + {b1: true, b4: false} + ]); + + BooleanMapArray|CsvConversionError bv5bma = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(bv5bma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + BooleanMapArray|CsvConversionError bv6bma = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(bv6bma, [ + {} + ]); + + BooleanMapArray|CsvConversionError bv7bma = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(bv7bma, [ + {b1, b2, b4} + ]); + + NillableBooleanMapArray|CsvConversionError bv1bnbma = fromCsvStringWithType(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|CsvConversionError bv2bnbma = fromCsvStringWithType(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|CsvConversionError bv3bnbma = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(bv3bnbma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: null}, + {b1: true, b2: true, b3: false} + ]); + + NillableBooleanMapArray|CsvConversionError bv4bnbma = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(bv4bnbma, [ + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} + ]); + + NillableBooleanMapArray|CsvConversionError bv5bnbma = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(bv5bnbma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + NillableBooleanMapArray|CsvConversionError bv6bnbma = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(bv6bnbma, [ + {b2: (), b3: ()} + ]); + + NillableBooleanMapArray|CsvConversionError bv7bnbma = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(bv7bnbma, [ + {b1, b2, b3, b4} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv1bniubma = fromCsvStringWithType(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|CsvConversionError bv2bniubma = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(bv2bniubma, [ + {b1: true, b2: false, b3: true, b4: false, b5: true}, + {b1: true, b2: false, b3: true, b4: false, b5: true} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv3bniubma = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(bv3bniubma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: null}, + {b1: true, b2: true, b3: false} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv4bniubma = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(bv4bniubma, [ + {b1: true, b2: (), b3: (), b4: 0}, + {b1: 1, b2: (), b3: (), b4: false} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv5bniubma = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(bv5bniubma, [ + {b1: true, b2: false, b3: true, b4: 2}, + {b1: true, b2: false, b3: true, b4: 3} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv6bniubma = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(bv6bniubma, [ + {b2: (), b3: ()} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv7bniubma = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(bv7bniubma, [ + {b1, b2, b3, b4} + ]); + + IntUnionBooleanMapArray|CsvConversionError bv1biubma = fromCsvStringWithType(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|CsvConversionError bv2biubma = fromCsvStringWithType(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|CsvConversionError bv3biubma = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(bv3biubma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false}, + {b1: true, b2: true, b3: false} + ]); + + IntUnionBooleanMapArray|CsvConversionError bv4biubma = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(bv4biubma, [ + {b1: true, b4: 0}, + {b1: 1, b4: false} + ]); + + IntUnionBooleanMapArray|CsvConversionError bv5biubma = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(bv5biubma, [ + {b1: true, b2: false, b3: true, b4: 2}, + {b1: true, b2: false, b3: true, b4: 3} + ]); + + IntUnionBooleanMapArray|CsvConversionError bv6biubma = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(bv6biubma, [ + {} + ]); + + IntUnionBooleanMapArray|CsvConversionError bv7biubma = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(bv7biubma, [ + {b1, b2, b4} + ]); + + NilMapArray|CsvConversionError bv1bnma = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(bv1bnma, [ + {}, + {}, + {} + ]); + + NilMapArray|CsvConversionError bv2bnma = fromCsvStringWithType(csvStringWithBooleanValues2); + test:assertEquals(bv2bnma, [ + {}, + {} + ]); + + NilMapArray|CsvConversionError bv3bnma = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(bv3bnma, [ + {}, + {b3: ()}, + {} + ]); + + NilMapArray|CsvConversionError bv4bnma = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(bv4bnma, [ + {b2: (), b3: ()}, + {b2: (), b3: ()} + ]); + + NilMapArray|CsvConversionError bv5bnma = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(bv5bnma, [ + {}, + {} + ]); + + NilMapArray|CsvConversionError bv6bnma = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(bv6bnma, [ + {b2: (), b3: ()} + ]); + + NilMapArray|CsvConversionError bv7bnma = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(bv7bnma, [ + {b3} + ]); + + JsonMapArray|CsvConversionError bv1bjma = fromCsvStringWithType(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|CsvConversionError bv2bjma = fromCsvStringWithType(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|CsvConversionError bv3bjma = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(bv3bjma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: null}, + {b1: true, b2: true, b3: false} + ]); + + JsonMapArray|CsvConversionError bv4bjma = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(bv4bjma, [ + {b1: true, b2: (), b3: (), b4: 0}, + {b1: 1, b2: (), b3: (), b4: false} + ]); + + JsonMapArray|CsvConversionError bv5bjma = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(bv5bjma, [ + {b1: true, b2: false, b3: true, b4: 2}, + {b1: true, b2: false, b3: true, b4: 3} + ]); + + JsonMapArray|CsvConversionError bv6bjma = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(bv6bjma, [ + {b2: (), b3: ()} + ]); + + JsonMapArray|CsvConversionError bv7bjma = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(bv7bjma, [ + {b1, b2, b3, b4} + ]); + + AnydataMapArray|CsvConversionError bv1banydma = fromCsvStringWithType(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|CsvConversionError bv2banydma = fromCsvStringWithType(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|CsvConversionError bv3banydma = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(bv3banydma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: null}, + {b1: true, b2: true, b3: false} + ]); + + AnydataMapArray|CsvConversionError bv4banydma = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(bv4banydma, [ + {b1: true, b2: (), b3: (), b4: 0}, + {b1: 1, b2: (), b3: (), b4: false} + ]); + + AnydataMapArray|CsvConversionError bv5banydma = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(bv5banydma, [ + {b1: true, b2: false, b3: true, b4: 2}, + {b1: true, b2: false, b3: true, b4: 3} + ]); + + AnydataMapArray|CsvConversionError bv6banydma = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(bv6banydma, [ + {b2: (), b3: ()} + ]); + + AnydataMapArray|CsvConversionError bv7banydma = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(bv7banydma, [ + {b1, b2, b3, b4} + ]); + + CustomMapArray|CsvConversionError bv1bcma = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(bv1bcma, [ + {b1: "true", b2: "false", b3: "true", b4: "false"}, + {b1: "true", b2: "false", b3: "true", b4: "false"}, + {b1: "true", b2: "false", b3: "true", b4: "false"} + ]); + + CustomMapArray|CsvConversionError bv2bcma = fromCsvStringWithType(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|CsvConversionError bv3bcma = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(bv3bcma, [ + {b1: "true", b2: "false", b3: "true"}, + {b1: "TRUE", b2: "FALSE", b3: "()"}, + {b1: "true", b2: "true", b3: "FALSE"} + ]); + + CustomMapArray|CsvConversionError bv4bcma = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(bv4bcma, [ + {b1: "true", b2: "()", b3: "()", b4: 0}, + {b1: 1, b2: "()", b3: "null", b4: "false"} + ]); + + CustomMapArray|CsvConversionError bv5bcma = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(bv5bcma, [ + {b1: "true", b2: "false", b3: "true", b4: 2}, + {b1: "true", b2: "false", b3: "true", b4: 3} + ]); + + CustomMapArray|CsvConversionError bv6bcma = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(bv6bcma, [ + {b2: "()", b3: "()"} + ]); + + CustomMapArray|CsvConversionError bv7bcma = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(bv7bcma, [ + {b1: "true", b2: "false", b3: "()", b4: "false"} + ]); + + StringMapArray|CsvConversionError bv1bsma = fromCsvStringWithType(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|CsvConversionError bv2bsma = fromCsvStringWithType(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|CsvConversionError bv3bsma = fromCsvStringWithType(csvStringWithBooleanValues3); + test:assertEquals(bv3bsma, [ + {b1: "true", b2: "false", b3: "true"}, + {b1: "TRUE", b2: "FALSE", b3: "()"}, + {b1: "true", b2: "true", b3: "FALSE"} + ]); + + StringMapArray|CsvConversionError bv4bsma = fromCsvStringWithType(csvStringWithBooleanValues4); + test:assertEquals(bv4bsma, [ + {b1: "true", b2: "()", b3: "()", b4: "0"}, + {b1: "1", b2: "()", b3: "null", b4: "false"} + ]); + + StringMapArray|CsvConversionError bv5bsma = fromCsvStringWithType(csvStringWithBooleanValues5); + test:assertEquals(bv5bsma, [ + {b1: "true", b2: "false", b3: "true", b4: "2"}, + {b1: "true", b2: "false", b3: "true", b4: "3"} + ]); + + StringMapArray|CsvConversionError bv6bsma = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(bv6bsma, [ + {b2: "()", b3: "()"} + ]); + + StringMapArray|CsvConversionError bv7bsma = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(bv7bsma, [ + {b1: "true", b2: "false", b3: "()", b4: "false"} + ]); + + DecimalMapArray|CsvConversionError bv1dsma = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(bv1dsma, [ + {}, + {}, + {} + ]); + DecimalMapArray|CsvConversionError bv6dsma = fromCsvStringWithType(csvStringWithBooleanValues6); + test:assertEquals(bv6dsma, [ + {} + ]); + + DecimalMapArray|CsvConversionError bv7dsma = fromCsvStringWithType(csvStringWithBooleanValues7); + test:assertEquals(bv7dsma, [ + {} ]); } @test:Config {enable} -function testFromCsvStringWithTypeFunctionWithTypeCompatibility() { +function testFromCsvStringWithTypeCompatibility() { string value = string ` i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 ${i1},${i2},${s1},${s2},${b1},${b2},(),(),${f1}, ${f2},${d1},${d2},${b1},${d1},${b2},${d2} @@ -520,6 +1661,12 @@ function testFromCsvStringWithTypeFunctionWithTypeCompatibility() { ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3} `; + AnydataArray1Array|CsvConversionError v3anyd1a = fromCsvStringWithType(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|CsvConversionError vcr27a = fromCsvStringWithType(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"}, @@ -536,51 +1683,129 @@ function testFromCsvStringWithTypeFunctionWithTypeCompatibility() { {i1, s1, b1, n1, f1, d1, a1: 2.234, j1: b1, defaultableField: "", nillableField: null, s2, s3} ]); - record{|int...;|}[]|CsvConversionError irrma = fromCsvStringWithType(string ` + AnydataMapArray|CsvConversionError vanydma = fromCsvStringWithType(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|CsvConversionError vjma = fromCsvStringWithType(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|CsvConversionError vsma = fromCsvStringWithType(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|CsvConversionError v2ct7a = fromCsvStringWithType(value2); + test:assertEquals(v2ct7a, [ + [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3, "false", "-3.21"] + ]); + + CustomTuple7Array|CsvConversionError v3ct7a = fromCsvStringWithType(value3); + test:assertEquals(v3ct7a, [ + [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3] + ]); + + // CustomTuple8Array|CsvConversionError v2ct8a = fromCsvStringWithType(value2); + // test:assertTrue(v2ct8a is CsvConversionError); + // test:assertEquals((v2ct8a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "int")); + + [float, decimal, string][]|CsvConversionError mrrta = fromCsvStringWithType(string `a, b,c + 1.23, 1.23, 1.23 + 0,0,0 + 0.0,0.0,0.0 + -1.2,-1.2,-1.2`); + test:assertEquals(mrrta, [ + [1.23, 1.23, "1.23"], + [0, 0, "0"], + [0, 0, "0.0"], + [-1.2, -1.2, "-1.2"] + ]); + + [float, decimal, string, int][]|CsvConversionError m2rrta = fromCsvStringWithType(string `a, b,c,d + 1, 1, 1,1 + 0,0,0,0 + -1,-1,-1,-1`); + test:assertEquals(m2rrta, [ + [1, 1, "1", 1], + [0, 0, "0", 0], + [-1, -1, "-1", -1] + ]); + + [int...][]|CsvConversionError m3rrta = fromCsvStringWithType(string `a, b,c,d + 1.2, abc, true,1.0`); + test:assertTrue(m3rrta is CsvConversionError); + test:assertEquals((m3rrta).message(), generateErrorMessageForInvalidCast("1.2", "int")); + + [boolean, int][]|CsvConversionError m4rrta = fromCsvStringWithType(string `a, b + 1, 1 + 0,0`); + test:assertEquals(m4rrta, [ + [true, 1], + [false, 0] + ]); + + record {|int...;|}[]|CsvConversionError irrma = fromCsvStringWithType(string ` a, b, c 1, a, 2.3 1, -2, true hello, -2, hello`); - test:assertEquals(irrma , [ - {a:1}, + test:assertEquals(irrma, [ + {a: 1}, {a: i1, b: i2}, {b: i2} ]); - record{|decimal...;|}[]|CsvConversionError drra = fromCsvStringWithType(string `a, b, c + record {|()...;|}[]|CsvConversionError nrrma = fromCsvStringWithType(string ` + a, b, c + 1, a, () + 1, null, () + hello, -2, hello`); + test:assertEquals(nrrma, [ + {c: ()}, + {b: (), c: ()}, + {} + ]); + + record {|decimal...;|}[]|CsvConversionError drra = fromCsvStringWithType(string `a, b, c 2.234, invalid , 1 ${f2}, 0, 2.3d invalid, ${d2}, ${f3}`); - test:assertTrue(drra is record{|decimal...;|}[]); - test:assertEquals(drra , [ - {a: d1, c: 1.0}, + test:assertTrue(drra is record {|decimal...;|}[]); + test:assertEquals(drra, [ + {a: d1, c: 1.0}, {a: f2, b: d3}, {b: -3.21d, c: f3} ]); - record{|string...;|}[]|CsvConversionError srra = fromCsvStringWithType(string ` + record {|string...;|}[]|CsvConversionError srra = fromCsvStringWithType(string ` a, b, c 1, a, 2.3 1, -2, true hello, -2, hello`); - test:assertTrue(srra is record{|string...;|}[]); - test:assertEquals(srra , [ + test:assertTrue(srra is record {|string...;|}[]); + test:assertEquals(srra, [ {a: "1", b: "a", c: "2.3"}, {a: "1", b: "-2", c: "true"}, {a: "hello", b: "-2", c: "hello"} ]); - record{|float...;|}[]|CsvConversionError frra = fromCsvStringWithType(string `a, b, c + record {|float...;|}[]|CsvConversionError frra = fromCsvStringWithType(string `a, b, c 1.2, invalid , 1 ${d2}, ${d3}, true ${d4}, ${f2}, 0.0`); - test:assertEquals(frra , [ + test:assertEquals(frra, [ {a: 1.2, c: 1.0}, {a: d2, b: d3}, {a: d4, b: f2, c: 0.0} ]); - record{float a; decimal b; string c;}[]|CsvConversionError mrra = fromCsvStringWithType(string `a, b,c + record {float a; decimal b; string c;}[]|CsvConversionError mrra = fromCsvStringWithType(string `a, b,c 1.23, 1.23, 1.23 0,0,0 0.0,0.0,0.0 @@ -592,7 +1817,7 @@ function testFromCsvStringWithTypeFunctionWithTypeCompatibility() { {a: -1.2, b: -1.2, c: "-1.2"} ]); - record{|float a; decimal b; string c; int d;|}[]|CsvConversionError m2rra = fromCsvStringWithType(string `a, b,c,d + record {|float a; decimal b; string c; int d;|}[]|CsvConversionError m2rra = fromCsvStringWithType(string `a, b,c,d 1, 1, 1,1 0,0,0,0 -1,-1,-1,-1`); @@ -602,27 +1827,28 @@ function testFromCsvStringWithTypeFunctionWithTypeCompatibility() { {a: -1, b: -1, c: "-1", d: -1} ]); - record{int d;}[]|CsvConversionError m3rra = fromCsvStringWithType(string `a, b,c,d + record {int d;}[]|CsvConversionError m3rra = fromCsvStringWithType(string `a, b,c,d 1.2, abc, true,1.0`); test:assertTrue(m3rra is CsvConversionError); - test:assertEquals((m3rra).message(), generateErrorMessageForInvalidCast("1.0", "int")); + test:assertEquals((m3rra).message(), generateErrorMessageForInvalidCast("1.0", "int")); - record{int b; boolean a;}[]|CsvConversionError m4rra = fromCsvStringWithType(string `a, b + record {int b; boolean a;}[]|CsvConversionError m4rra = fromCsvStringWithType(string `a, b 1, 1 0,0`); test:assertEquals(m4rra, [ {a: true, b: 1}, - {a: false, b:0} - ]); + {a: false, b: 0} + ]); } boolean enable = true; @test:Config {enable: !enable} function test() { - BooleanRecord13Array|CsvConversionError csvb6br13 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertEquals(csvb6br13, [ - {b2: "()", b3: "()", defaultableField: "", nillableField: ()}, - {b2: "()", b3: "()", defaultableField: "", nillableField: ()} + NillableBooleanTuple5|CsvConversionError cbv1bt5 = fromCsvStringWithType(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt5, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] ]); } diff --git a/ballerina/tests/types.bal b/ballerina/tests/types.bal index 5d6f2c9..d4676ac 100644 --- a/ballerina/tests/types.bal +++ b/ballerina/tests/types.bal @@ -1115,6 +1115,7 @@ type CustomTuple4 [string...]; type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; type CustomTuple6 [anydata...]; type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; +type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; type IntegerArray1 int[]; type IntegerArray2 int[2]; @@ -1573,6 +1574,7 @@ type CustomTuple5Array CustomTuple5[]; type ClosedCustomTuple5Array CustomTuple5[3]; type CustomTuple6Array CustomTuple6[]; type CustomTuple7Array CustomTuple7[]; +type CustomTuple8Array CustomTuple8[]; type ClosedCustomTuple6Array CustomTuple6[3]; type IntegerArray1Array IntegerArray1[]; diff --git a/ballerina/tests/values.bal b/ballerina/tests/values.bal index 1c9b602..b0947d5 100644 --- a/ballerina/tests/values.bal +++ b/ballerina/tests/values.bal @@ -135,7 +135,7 @@ true,false, true,false,true`; string csvStringWithBooleanValues3 = string ` b1,b2,b3 -${" "}${" "} +${" "}${"\t"} true, false,true ${" "} TRUE, FALSE,() diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index bf1d1ba..99b3503 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -21,7 +21,7 @@ # ------------------------- error.invalid.type=\ - invalid expected type ''{0}'' + invalid expected type ''{0}'', expected a subtype of (map|anydata)[] error.union.types.not.allowed.as.expected.type=\ union types are not allowed in the expected type, found ''{0}'' From b6a379e2636656fcfdca280b229d7f7de8148209 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Sun, 24 Mar 2024 22:34:10 +0530 Subject: [PATCH 021/147] Add tests for config headers and custom headers --- ballerina/csv_api.bal | 1 - ..._csv_string_with_type_with_string_test.bal | 22 +- ballerina/tests/from_csv_with_type_test.bal | 6 +- .../{values.bal => test_data_values.bal} | 90 ++ .../test_from_csv_with_user_configs.bal.bal | 355 ++++++++ ballerina/tests/test_user_config_values.bal | 408 +++++++++ ballerina/tests/types.bal | 826 +++++++++++++++++- ballerina/tests/user_configurations.bal | 75 -- .../stdlib/data/csvdata/csv/CsvCreator.java | 16 +- .../stdlib/data/csvdata/csv/CsvParser.java | 71 +- .../stdlib/data/csvdata/csv/QueryParser.java | 1 - .../stdlib/data/csvdata/utils/CsvUtils.java | 3 +- 12 files changed, 1750 insertions(+), 124 deletions(-) rename ballerina/tests/{values.bal => test_data_values.bal} (62%) create mode 100644 ballerina/tests/test_from_csv_with_user_configs.bal.bal create mode 100644 ballerina/tests/test_user_config_values.bal delete mode 100644 ballerina/tests/user_configurations.bal diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 710a7b6..e40e840 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -64,7 +64,6 @@ public type ToCSVConfig record {| ColumnOrder|ColumnOrder[] orderBy = []; string|int|string[]|int[]? skipColumns = (); boolean suppressEscaping = false; - MappingConfig mappingConfig = {}; anydata nullValue = (); string:Char escapeCharacter = "\\"; |}; diff --git a/ballerina/tests/from_csv_string_with_type_with_string_test.bal b/ballerina/tests/from_csv_string_with_type_with_string_test.bal index 022e831..a243583 100644 --- a/ballerina/tests/from_csv_string_with_type_with_string_test.bal +++ b/ballerina/tests/from_csv_string_with_type_with_string_test.bal @@ -1841,14 +1841,14 @@ function testFromCsvStringWithTypeCompatibility() { ]); } -boolean enable = true; - -@test:Config {enable: !enable} -function test() { - NillableBooleanTuple5|CsvConversionError cbv1bt5 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt5, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); -} +// boolean enable = true; + +// @test:Config {enable: !enable} +// function test() { +// NillableBooleanTuple5|CsvConversionError cbv1bt5 = fromCsvStringWithType(csvStringWithBooleanValues1); +// test:assertEquals(cbv1bt5, [ +// [true, false, true, false], +// [true, false, true, false], +// [true, false, true, false] +// ]); +// } diff --git a/ballerina/tests/from_csv_with_type_test.bal b/ballerina/tests/from_csv_with_type_test.bal index 414756d..1a1c56c 100644 --- a/ballerina/tests/from_csv_with_type_test.bal +++ b/ballerina/tests/from_csv_with_type_test.bal @@ -2286,12 +2286,12 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { // boolean enable = true; -@test:Config {enable: !enable} -function testTemp1() { +// @test:Config {enable: !enable} +// function testTemp1() { // record{|float...;|}[]|CsvConversionError frra = fromCsvWithType([{a: d2, b: d3}]); // test:assertEquals(frra , [ // {a: 1.2, b: 1.2}, // {}, // {a: d4, b: f2} // ]); -} +// } diff --git a/ballerina/tests/values.bal b/ballerina/tests/test_data_values.bal similarity index 62% rename from ballerina/tests/values.bal rename to ballerina/tests/test_data_values.bal index b0947d5..b3c8e3c 100644 --- a/ballerina/tests/values.bal +++ b/ballerina/tests/test_data_values.bal @@ -170,3 +170,93 @@ string csvStringWithBooleanValues7 = string ` b1,b2,b3,b4 ${b1},${b2},(),${b4} `; + +string csvStringData1 = string ` + a, b, c, d, e, f + 1, string1, true, 2.234, 2.234, () + 1, string2, false, 0, 0, null + 1, string3, 0, 1.23, 1.23, () + 1, string4, 1, -6.51, -6.51, () + 1, string5, true, 3, 3, ()`; + +string csvStringData2 = string ` + + + a, b, c, d, e, f + + + 1, string1, true, 2.234, 2.234, () + 1, string2, false, 0, 0, null + 1, string3, 0, 1.23, 1.23, () + 1, string4, 1, -6.51, -6.51, () + 1, string5, true, 3, 3, ()`; + +string csvStringData3 = string ` + a, b, c, d, e, f + + + + 1, string1, true, 2.234, 2.234, () + 1, string2, false, 0, 0, null + 1, string3, 0, 1.23, 1.23, () + + 1, string4, 1, -6.51, -6.51, () + 1, string5, true, 3, 3, ()`; + +string csvStringData4 = string ` + 1, string1, true, 2.234, 2.234, () + 1, string2, false, 0, 0, null + 1, string3, 0, 1.23, 1.23, () + 1, string4, 1, -6.51, -6.51, () + 1, string5, true, 3, 3, ()`; + +string csvStringData5 = string ` + + + + 1, string1, true, 2.234, 2.234, () + 1, string2, false, 0, 0, null + + 1, string3, 0, 1.23, 1.23, () + 1, string4, 1, -6.51, -6.51, () + + 1, string5, true, 3, 3, ()`; + +string csvStringData6 = string ` + + 1, string1, true, 2.234, 2.234, () + 1, string2, false, 0, 0, null + + 1, string3, 0, 1.23, 1.23, () + 1, string4, 1, -6.51, -6.51, () + + 1, string5, true, 3, 3, ()`; + +string csvStringData7 = string ` + a@ b@ c@ d@ e@ f + 1@ string@ true@ 2.234@ -3.21@ () + 1@ s,tring@ true@ 2.234@ -3.21@ null + 1@ stri,ng@ true@ 2.234@ -3.21@ () + 1@ string@ true@ 2.234@ -3.21@ () + 1@ string@ true@ 2.234@ -3.21@ ()`; +string csvStringData8 = string ` + a@ b@ c@ d@ e@ f + + + + 1@ stri,ng@ true@ 2.234@ -3.21@ () + 1@ string@ true@ 2.234@ -3.21@ () + 1@ string@ true@ 2.234@ -3.21@ null + + 1@ s,tring@ true@ 2.234@ -3.21@ () + 1@ string@ true@ 2.234@ -3.21@ ()`; + +string csvStringData9 = string ` + + 1@ string@ true@ 2.234@ -3.21@ () + 1@ string@ true@ 2.234@ -3.21@ null + + 1@ string@ true@ 2.234@ -3.21@ () + 1@ string@ true@ 2.234@ -3.21@ () + + 1@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina/tests/test_from_csv_with_user_configs.bal.bal b/ballerina/tests/test_from_csv_with_user_configs.bal.bal new file mode 100644 index 0000000..cf668b5 --- /dev/null +++ b/ballerina/tests/test_from_csv_with_user_configs.bal.bal @@ -0,0 +1,355 @@ +import ballerina/test; + +@test:Config{enable} +function testStartNumbers() { + +} + +@test:Config{enable} +function testCustomHeaders() { + + // headers config parameter + + record {}[]|CsvConversionError v1 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v1, [ + {'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: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, + {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + CustomRecord28Array|CsvConversionError v2 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v2, [ + {'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: "1", '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, + {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, + {'1: "1", '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + + CustomRecord29Array|CsvConversionError v3 = fromCsvStringWithType(csvStringData1, config21); + test:assertTrue(v3 is CsvConversionError); + test:assertEquals((v3).message(), generateErrorMessageForInvalidCast("a", "int")); + + CustomRecord30Array|CsvConversionError v4 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v4, [ + {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, + {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, + {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, + {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} + ]); + + CustomRecord31Array|CsvConversionError v5 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v5, [ + {'1: "a", '6: "f"}, + {'1: "1", '6: "()"}, + {'1: "1", '6: "null"}, + {'1: "1", '6: "()"}, + {'1: "1", '6: "()"}, + {'1: "1", '6: "()"} + ]); + + + CustomRecord32Array|CsvConversionError v6 = fromCsvStringWithType(csvStringData1, config21); + test:assertTrue(v6 is CsvConversionError); + test:assertEquals((v3).message(), generateErrorMessageForInvalidCast("a", "int")); + + CustomRecord33Array|CsvConversionError v7 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v7, [ + {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, + {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, + {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, + {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} + ]); + + CustomRecord34Array|CsvConversionError v8 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v8, [ + {'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: "1", '2: "string2", '3: false, '4: 0, '5: "0", '6: "null"}, + {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: "1.23", '6: "()"}, + {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: "-6.51", '6: "()"}, + {'1: "1", '2: "string5", '3: true, '4: 3, '5: "3", '6: "()"} + ]); + + CustomRecord35Array|CsvConversionError v9 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v9, [ + {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f", '9: ""}, + {'1: "1", '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: "()", '9: ""}, + {'1: "1", '2: "string2", '3: false, '4: 0, '5: 0, '6: "null", '9: ""}, + {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: "()", '9: ""}, + {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: "()", '9: ""}, + {'1: "1", '2: "string5", '3: true, '4: 3, '5: 3, '6: "()", '9: ""} + ]); + + CustomRecord36Array|CsvConversionError v10 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v10, [ + {'1: "a", '6: "f", '9: ""}, + {'1: "1", '6: "()", '9: ""}, + {'1: "1", '6: "null", '9: ""}, + {'1: "1", '6: "()", '9: ""}, + {'1: "1", '6: "()", '9: ""}, + {'1: "1", '6: "()", '9: ""} + ]); + + CustomRecord37Array|CsvConversionError v11 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v11, [ + {'1: "a", '5: "e", '6: "f"}, + {'1: "1", '5: "2.234", '6: "()"}, + {'1: "1", '5: "0", '6: "null"}, + {'1: "1", '5: "1.23", '6: "()"}, + {'1: "1", '5: "-6.51", '6: "()"}, + {'1: "1", '5: "3", '6: "()"} + ]); + + CustomRecord38Array|CsvConversionError v12 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v12, [ + {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, + {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, + {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, + {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} + ]); + + CustomRecord39Array|CsvConversionError v13 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v13, [ + {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, + {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, + {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, + {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} + ]); + + CustomRecord40Array|CsvConversionError v14 = fromCsvStringWithType(csvStringData3, config21); + test:assertEquals(v14, [ + {'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: 1, '2: "string2", '3: false, '4: 0, '5: "0", '6: "null"}, + {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: "1.23", '6: "()"}, + {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: "-6.51", '6: "()"}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: "3", '6: "()"} + ]); + + CustomRecord41Array|CsvConversionError v15 = fromCsvStringWithType(csvStringData2, config21); + test:assertEquals(v15, [ + {'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: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, + {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + CustomRecord42Array|CsvConversionError v16 = fromCsvStringWithType(csvStringData6, config21); + test:assertEquals(v16, [ + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, + {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} + ]); + + CustomRecord43Array|CsvConversionError v17 = fromCsvStringWithType(csvStringData6, config21); + test:assertEquals(v17, [ + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, + {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} + ]); + + CustomRecord44Array|CsvConversionError v18 = fromCsvStringWithType(csvStringData6, config21); + test:assertEquals(v18, [ + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, + {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} + ]); + + CustomRecord45Array|CsvConversionError v19 = fromCsvStringWithType(csvStringData6, config21); + test:assertTrue(v19 is CsvConversionError); + test:assertEquals((v19).message(), generateErrorMessageForMissingRequiredField("H1")); + + CustomRecord46Array|CsvConversionError v19_2 = fromCsvStringWithType(csvStringData6, config21); + test:assertTrue(v19_2 is CsvConversionError); + test:assertEquals((v19_2).message(), generateErrorMessageForMissingRequiredField("H1")); + + CustomRecord47Array|CsvConversionError v19_3 = fromCsvStringWithType(csvStringData6, config21); + test:assertTrue(v19_3 is CsvConversionError); + test:assertEquals((v19_3).message(), generateErrorMessageForMissingRequiredField("H1")); + + CustomRecord56Array|CsvConversionError v19_4 = fromCsvStringWithType(csvStringData1, config21); + test:assertEquals(v19_4, [ + {H1: "", H4: "", '1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, + {H1: "", H4: "", '1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {H1: "", H4: "", '1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, + {H1: "", H4: "", '1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, + {H1: "", H4: "", '1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, + {H1: "", H4: "", '1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + // custom header config parameter + + CustomRecord46Array|CsvConversionError v20 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v20, [ + {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ]); + + CustomRecord46Array|CsvConversionError v20_2 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v20_2, [ + {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ]); + + CustomRecord47Array|CsvConversionError v21 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v21, [ + {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ]); + + CustomRecord48Array|CsvConversionError v22 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v22, [ + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ]); + + CustomRecord48Array|CsvConversionError v22_2 = fromCsvStringWithType(csvStringData1, config22); + test:assertEquals(v22_2, [ + {H1: "a", H2: "b", H3: "c", H4: "d", H5: "e", H6: "f"}, + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ]); + + CustomRecord49Array|CsvConversionError v23 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v23, [ + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ]); + + CustomRecord50Array|CsvConversionError v24 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v24, [ + {H1: 1, H4: 2.234, H2: "string1", H3: true, H5: 2.234, H6: ()}, + {H1: 1, H4: 0.0, H2: "string2", H3: false, H5: 0, H6: null}, + {H1: 1, H4: 1.23, H2: "string3", H3: 0, H5: 1.23, H6: ()}, + {H1: 1, H4: -6.51, H2: "string4", H3: 1, H5: -6.51, H6: ()}, + {H1: 1, H4: 3.0, H2: "string5", H3: true, H5: 3, H6: ()} + ]); + + CustomRecord50Array|CsvConversionError v24_2 = fromCsvStringWithType(csvStringData1, config22); + test:assertTrue(v24_2 is CsvConversionError); + test:assertEquals((v24_2).message(), generateErrorMessageForInvalidCast("a", "int")); + + CustomRecord51Array|CsvConversionError v25 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v25, [ + {H1: 1, H4: 2.234}, + {H1: 1, H4: 0.0}, + {H1: 1, H4: 1.23}, + {H1: 1, H4: -6.51}, + {H1: 1, H4: 3.0} + ]); + + CustomRecord52Array|CsvConversionError v26 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v26, [ + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ]); + + CustomRecord52Array|CsvConversionError v26_2 = fromCsvStringWithType(csvStringData1, config22); + test:assertEquals(v26_2, [ + {H1: "a", H2: "b", H3: "c", H4: "d", H5: "e", H6: "f"}, + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ]); + + CustomRecord53Array|CsvConversionError v27 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v27, [ + {H1: 1, H4: 2.234, "H5": 2.234}, + {H1: 1, H4: 0.0, "H5": 0}, + {H1: 1, H4: 1.23, "H3": 0, "H5": 1.23}, + {H1: 1, H4: -6.51, "H3": 1, "H5": -6.51}, + {H1: 1, H4: 3.0, "H5": 3} + ]); + + CustomRecord53Array|CsvConversionError v27_2 = fromCsvStringWithType(csvStringData1, config22); + test:assertTrue(v27_2 is CsvConversionError); + test:assertEquals((v27_2).message(), generateErrorMessageForInvalidCast("a", "int")); + + CustomRecord53Array|CsvConversionError v28 = fromCsvStringWithType(csvStringData1, config21); + test:assertTrue(v28 is CsvConversionError); + test:assertEquals((v28).message(), generateErrorMessageForMissingRequiredField("H4")); + + CustomRecord53Array|CsvConversionError v28_2 = fromCsvStringWithType(csvStringData6, config21); + test:assertTrue(v28_2 is CsvConversionError); + test:assertEquals((v28_2).message(), generateErrorMessageForMissingRequiredField("H4")); + + CustomRecord54Array|CsvConversionError v29 = fromCsvStringWithType(csvStringData1, config22); + test:assertTrue(v29 is CsvConversionError); + test:assertEquals((v29).message(), generateErrorMessageForMissingRequiredField("1")); + + CustomRecord54Array|CsvConversionError v29_2 = fromCsvStringWithType(csvStringData1, config22); + test:assertTrue(v29_2 is CsvConversionError); + test:assertEquals((v29_2).message(), generateErrorMessageForMissingRequiredField("1")); + + CustomRecord55Array|CsvConversionError v30 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v30, [ + {H1: "1", H4: "2.234",'1: 10}, + {H1: "1", H4: "0", '1: 10}, + {H1: "1", H4: "1.23", '1: 10}, + {H1: "1", H4: "-6.51", '1: 10}, + {H1: "1", H4: "3", '1: 10} + ]); + + CustomRecord55Array|CsvConversionError v30_2 = fromCsvStringWithType(csvStringData1, config21); + test:assertTrue(v30_2 is CsvConversionError); + test:assertEquals((v30_2).message(), generateErrorMessageForInvalidCast("a", "int")); +} + +boolean enable = true; + +@test:Config{enable: !enable} +function test() { + CustomRecord46Array|CsvConversionError v20 = fromCsvStringWithType(csvStringData6, config22); + test:assertEquals(v20, [ + {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ]); +} diff --git a/ballerina/tests/test_user_config_values.bal b/ballerina/tests/test_user_config_values.bal new file mode 100644 index 0000000..6d05873 --- /dev/null +++ b/ballerina/tests/test_user_config_values.bal @@ -0,0 +1,408 @@ +FromCSVConfig config1 = { + startNumber: 1 +}; + +FromCSVConfig config2 = { + startNumber: 2 +}; + +FromCSVConfig config3 = { + startNumber: -2 +}; + +FromCSVConfig config4 = { + startNumber: 100 +}; + +FromCSVConfig config5 = { + headerStartNumber: 1 +}; + +FromCSVConfig config6 = { + headerStartNumber: 2 +}; + +FromCSVConfig config7 = { + headerStartNumber: -2 +}; + +FromCSVConfig config8 = { + headerStartNumber: 100 +}; + +FromCSVConfig config9 = { + dataStartNumber: 1 +}; + +FromCSVConfig config10 = { + dataStartNumber: 2 +}; + +FromCSVConfig config11 = { + dataStartNumber: -2 +}; + +FromCSVConfig config12 = { + dataStartNumber: 100 +}; + +FromCSVConfig config13 = { + startNumber: 10, + headerStartNumber: 8 +}; + +FromCSVConfig config14 = { + startNumber: 10, + headerStartNumber: 10 +}; + +FromCSVConfig config15 = { + startNumber: 10, + dataStartNumber: 8 +}; + +FromCSVConfig config16 = { + startNumber: 10, + dataStartNumber: 10 +}; + +FromCSVConfig config17 = { + headerStartNumber: 10, + dataStartNumber: 8 +}; + +FromCSVConfig config18 = { + headerStartNumber: 10, + dataStartNumber: 10 +}; + +FromCSVConfig config19 = { + startNumber: 12, + headerStartNumber: 10, + dataStartNumber: 12 +}; + +FromCSVConfig config20 = { + startNumber: 12, + headerStartNumber: 10, + dataStartNumber: 12 +}; + +// startNumber, header Start number, data start number values should be configured to each test cases separately. + +FromCSVConfig config21 = { + headers: false +}; + +FromCSVConfig config22 = { + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] +}; + +FromCSVConfig config23 = { + headers: false, + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] +}; + +FromCSVConfig config24 = { + skipHeaders: true, + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] +}; + +FromCSVConfig config25 = { + customheader: [1, 2, 3, 4, 5, 6] +}; + +FromCSVConfig config26 = { + customheader: ["H2", "H3", "H4", "H5", "H6"] +}; + +FromCSVConfig config27 = { + skipHeaders: true, + customheader: [1, 2, 3, 5, 6] +}; + +FromCSVConfig config28 = { + ignoreEmptyLines: false +}; + +FromCSVConfig config29 = { + ignoreEmptyLines: false +}; + +// Tests with ignore empty lines with data startnumber, header Start number, Start number should be tested separaetly. + +FromCSVConfig config30 = { + ignoreEmptyLines: false, + orderBy: { + column: "a" + } +}; + +FromCSVConfig config31 = { + ignoreEmptyLines: false, + orderBy: [ + { column: "a", columnOrder: "DESC"}, + { column: "f", columnOrder: "ASC"} + ] +}; + +FromCSVConfig config32 = { + ignoreEmptyLines: false, + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"], + orderBy: [ + { column: "a", columnOrder: "DESC"}, + { column: "f", columnOrder: "ASC"} + ] +}; + +FromCSVConfig config33 = { + ignoreEmptyLines: false, + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"], + orderBy: [ + { column: "H3", columnOrder: "DESC"}, + { column: "H4", columnOrder: "ASC"} + ] +}; + +// Need to test with orders with each column(type) separately + +FromCSVConfig config34 = { + skipHeaders: true, + headers: false +}; + +FromCSVConfig config35 = { + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] +}; + +FromCSVConfig config36 = { + skipHeaders: true, + headers: false, + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] +}; + +FromCSVConfig config37 = { + skipHeaders: true, + headers: true, + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] +}; + +FromCSVConfig config38 = { + skipHeaders: true, + headers: true, + customheader: [1, 2, 3, 4, 5, 6] +}; + +FromCSVConfig config39 = { + skipHeaders: true, + headers: true, + customheader: ["H2", "H3", "H4", "H5", "H6"] +}; + +FromCSVConfig config40 = { + skipHeaders: true, + headers: true, + customheader: ["H2", "H3", "H4", "H5", "H6"] +}; + +FromCSVConfig config41 = { + skipdataRows: 2 +}; + +FromCSVConfig config42 = { + skipdataRows: 3, + ignoreEmptyLines: false +}; + +FromCSVConfig config43 = { + skipdataRows: 2, + headers: false +}; + +FromCSVConfig config44 = { + skipdataRows: 3, + ignoreEmptyLines: false, + skipHeaders: true +}; + +FromCSVConfig config45 = { + dataRowCount: 2 +}; + +FromCSVConfig config46 = { + dataRowCount: 3, + ignoreEmptyLines: false +}; + +FromCSVConfig config47 = { + dataRowCount: 2, + skipHeaders: true +}; + +FromCSVConfig config48 = { + dataRowCount: 3, + headers: false, + ignoreEmptyLines: false +}; + +FromCSVConfig config49 = { + dataRowCount: 2, + skipdataRows: 2 +}; + +FromCSVConfig config50 = { + dataRowCount: 2, + skipdataRows: 2, + ignoreEmptyLines: false +}; + +FromCSVConfig config51 = { + dataRowCount: 2, + skipdataRows: 2, + ignoreEmptyLines: false, + skipHeaders: true +}; + +FromCSVConfig config52 = { + dataRowCount: 2, + skipdataRows: 2, + ignoreEmptyLines: false, + headers: false +}; + +FromCSVConfig config53 = { + separator: "@" +}; + +FromCSVConfig config54 = { + separator: "@", + skipHeaders: true +}; + +FromCSVConfig config55 = { + separator: "@", + headers: false +}; + +FromCSVConfig config56 = { + headers: false, + orderBy: { + column: "abc" + } +}; + +FromCSVConfig config57 = { + skipHeaders: true, + orderBy: { + column: "abc" + } +}; + +FromCSVConfig config58 = { + orderBy: [ + {column: "a", columnOrder: "DESC"}, + {column: "b"} + ] +}; + +FromCSVConfig config59 = { + orderBy: [ + {column: "a", columnOrder: "DESC"}, + {column: "b"} + ], + skipColumns: "c" +}; + +FromCSVConfig config60 = { + orderBy: [ + {column: "a", columnOrder: "DESC"}, + {column: "b"} + ], + skipColumns: "a" +}; + +FromCSVConfig config61 = { + orderBy: [ + {column: "a", columnOrder: "DESC"}, + {column: "b"} + ], + skipColumns: ["c", "a"] +}; + +FromCSVConfig config62 = { + orderBy: [ + {column: "a", columnOrder: "DESC"}, + {column: "b"} + ], + skipColumns: ["b", "a"] +}; + +FromCSVConfig config63 = { + orderBy: [ + {column: "a", columnOrder: "DESC"}, + {column: "b"} + ], + skipColumns: 1 +}; + +FromCSVConfig config64 = { + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"], + orderBy: [ + {column: "H1", columnOrder: "DESC"}, + {column: "H2"} + ], + skipColumns: "a" +}; + +FromCSVConfig config65 = { + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"], + orderBy: [ + {column: "a", columnOrder: "DESC"}, + {column: "b"} + ], + skipColumns: ["a", "b"] +}; + +FromCSVConfig config66 = { + customheader: [1, 2, 3, 4, 5, 6], + orderBy: [ + {column: "1", columnOrder: "DESC"}, + {column: "2"} + ], + skipColumns: [1, 2] +}; + +FromCSVConfig config67 = { + customheader: [1, 2, 3, 4, 5, 6], + orderBy: [ + {column: 1, columnOrder: "DESC"}, + {column: 2} + ], + skipColumns: [1, 2] +}; + +FromCSVConfig config68 = { + customheader: [1, 2, 3, 4, 5, 6], + orderBy: [ + {column: 1, columnOrder: "DESC"}, + {column: 2} + ], + skipColumns: [3, 4] +}; + +FromCSVConfig config69 = { + customheader: [1, 2, 3, 4, 5, 6], + skipColumns: [100, 101] +}; + +FromCSVConfig config70 = { + customheader: ["H1", "H2", "H3", "H4", "H5", "H6"], + skipColumns: ["A", "B"] +}; + +FromCSVConfig config71 = { + customheader: [1, 2, 3, 4, 5, 6], + skipColumns: ["4", "5"] +}; + +// Needs to have separate tests for each skip columns query diff --git a/ballerina/tests/types.bal b/ballerina/tests/types.bal index d4676ac..d3ccc42 100644 --- a/ballerina/tests/types.bal +++ b/ballerina/tests/types.bal @@ -1058,666 +1058,1478 @@ type CustomRecord27 record {| string...; |}; +type CustomRecord28 record { + string '1; +}; + +type CustomRecord29 record { + int '1; +}; + +type CustomRecord30 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord31 record {| + string '1; + string '6; +|}; + +type CustomRecord32 record {| + int '1; +|}; + +type CustomRecord33 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord34 record { + string '1; + string '6; + string '5 = ""; +}; + +type CustomRecord35 record { + string '1; + string '6; + string '9 = ""; +}; + +type CustomRecord36 record {| + string '1; + string '6; + string '9 = ""; +|}; + +type CustomRecord37 record {| + string '1; + string '6; + string '5 = ""; +|}; + +type CustomRecord38 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + string ...; +|}; + +type CustomRecord39 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + json ...; +|}; + +type CustomRecord40 record {| + string '5; + string '6; + json ...; +|}; + +type CustomRecord41 record {| + json ...; +|}; + +type CustomRecord42 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +|}; + +type CustomRecord43 record { + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +}; + +type CustomRecord44 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; + string ...; +|}; + +type CustomRecord45 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +|}; + +type CustomRecord46 record { + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +}; + +type CustomRecord47 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; + string ...; +|}; + +type CustomRecord48 record { + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +}; + +type CustomRecord49 record {| + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +|}; + +type CustomRecord50 record { + int H1; + float H4; +}; + +type CustomRecord51 record {| + int H1; + float H4; +|}; + +type CustomRecord52 record {| + string H1; + string H4; + string ...; +|}; + +type CustomRecord53 record {| + int H1; + float H4; + decimal ...; +|}; + +type CustomRecord54 record {| + string H1 = ""; + string H4; + string '1; +|}; + +type CustomRecord55 record {| + string H1 = ""; + string H4 = ""; + int '1 = 10; +|}; + +type CustomRecord56 record { + string H1 = ""; + string H4 = ""; + anydata '1 = 10; +}; + type BooleanTuple1 [boolean, boolean, boolean, boolean]; + type BooleanTuple2 [boolean, boolean]; + type BooleanTuple3 [boolean, boolean...]; + type BooleanTuple4 [boolean...]; + type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; + type NillableBooleanTuple6 [boolean?, boolean?]; + type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; + type NillableBooleanTuple8 [boolean?...]; + type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; type NilTuple1 [(), (), ()]; + type NilTuple2 [(), ()]; + type NilTuple3 [(), ()...]; + type NilTuple4 [()...]; type IntegerTuple1 [int, int, int, int, int, int]; + type IntegerTuple2 [int, int]; + type IntegerTuple3 [int, int...]; + type IntegerTuple4 [int...]; type FloatTuple1 [float, float, float, float, float, float, float]; + type FloatTuple2 [float, float]; + type FloatTuple3 [float, float...]; + type FloatTuple4 [float...]; type DecimalTuple1 [decimal, decimal, decimal, decimal]; + type DecimalTuple2 [decimal, decimal]; + type DecimalTuple3 [decimal, decimal...]; + type DecimalTuple4 [decimal...]; type StringTuple1 [string, string, string, string]; + type StringTuple2 [string, string]; + type StringTuple3 [string, string...]; + type StringTuple4 [string...]; -type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, +type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata]; + type AnydataTuple2 [anydata, anydata]; + type AnydataTuple3 [anydata, anydata...]; + type AnydataTuple4 [anydata...]; -type JsonTuple1 [json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, +type JsonTuple1 [json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, json, json, json, json, json]; + type JsonTuple2 [json, json]; + type JsonTuple3 [json, json...]; + type JsonTuple4 [json...]; type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; + type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; + type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; + type CustomTuple4 [string...]; + type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; + type CustomTuple6 [anydata...]; + type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; + type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; type IntegerArray1 int[]; + type IntegerArray2 int[2]; + type IntegerArray3 int[]; + type IntegerArray4 int[2]; + type IntegerArray5 int[3]; + type IntegerArray6 int[4]; type StringArray string[]; + type NillableStringArray string?[]; + type NillableIntOrUnionStringArray (int|string?)[]; type StringArray1 string[]; + type StringArray2 string[2]; + type StringArray3 string[]; + type StringArray4 string[2]; + type StringArray5 string[3]; + type StringArray6 string[4]; type FloatArray1 float[]; + type FloatArray2 float[2]; + type FloatArray3 float[]; + type FloatArray4 float[2]; + type FloatArray5 float[3]; + type FloatArray6 float[4]; type DecimalArray1 decimal[]; + type DecimalArray2 decimal[2]; + type DecimalArray3 decimal[]; + type DecimalArray4 decimal[2]; + type DecimalArray5 decimal[3]; + type DecimalArray6 decimal[4]; type BooleanArray boolean[]; + type NillableBooleanArray boolean?[]; + type NillableIntOrUnionBooleanArray (int|boolean?)[]; type BooleanArray2 boolean[2]; + type BooleanArray3 boolean[3]; type BooleanArray4 boolean[]; + type BooleanArray5 boolean[2]; + type BooleanArray6 boolean[4]; type NilArray1 ()[]; + type NilArray2 ()[2]; + type NilArray3 ()[]; + type NilArray4 ()[2]; + type NilArray5 ()[3]; + type NilArray6 ()[4]; type JsonArray1 json[]; + type JsonArray2 json[2]; + type JsonArray3 json[]; + type JsonArray4 json[2]; + type JsonArray5 json[3]; + type JsonArray6 json[4]; type AnydataArray1 anydata[]; + type AnydataArray2 anydata[2]; + type AnydataArray3 anydata[]; + type AnydataArray4 anydata[2]; + type AnydataArray5 anydata[3]; + type AnydataArray6 anydata[4]; type CustomArray1 CustomTuple2[]; + type CustomArray2 CustomTuple2[2]; + type CustomArray3 CustomTuple2[]; + type CustomArray4 CustomTuple2[2]; + type CustomArray5 CustomTuple2[3]; + type CustomArray6 CustomTuple2[4]; type IntegerMap map; + type StringMap map; + type NillableIntUnionStringMap map; + type IntUnionStringMap map; type DecimalMap map; + type FloatMap map; + type BooleanMap map; + type NillableBooleanMap map; + type NillableIntUnionBooleanMap map; + type IntUnionBooleanMap map; + type NilMap map<()>; + type JsonMap map; + type AnydataMap map; + type CustomMap map; type BooleanRecord1Array BooleanRecord1[]; + type ClosedBooleanRecord1Array BooleanRecord1[3]; + type BooleanRecord2Array BooleanRecord2[]; + type ClosedBooleanRecord2Array BooleanRecord2[3]; + type BooleanRecord3Array BooleanRecord3[]; + type ClosedBooleanRecord3Array BooleanRecord3[3]; + type BooleanRecord4Array BooleanRecord4[]; + type ClosedBooleanRecord4Array BooleanRecord4[3]; + type BooleanRecord5Array BooleanRecord5[]; + type ClosedBooleanRecord5Array BooleanRecord5[3]; + type BooleanRecord6Array BooleanRecord6[]; + type ClosedBooleanRecord6Array BooleanRecord6[3]; + type BooleanRecord7Array BooleanRecord7[]; + type ClosedBooleanRecord7Array BooleanRecord7[3]; + type BooleanRecord8Array BooleanRecord8[]; + type ClosedBooleanRecord8Array BooleanRecord8[3]; + type BooleanRecord9Array BooleanRecord9[]; + type ClosedBooleanRecord9Array BooleanRecord9[3]; + type BooleanRecord10Array BooleanRecord10[]; + type ClosedBooleanRecord10Array BooleanRecord10[3]; + type BooleanRecord11Array BooleanRecord11[]; + type ClosedBooleanRecord11Array BooleanRecord11[3]; + type BooleanRecord12Array BooleanRecord12[]; + type ClosedBooleanRecord12Array BooleanRecord12[3]; + type BooleanRecord13Array BooleanRecord13[]; + type ClosedBooleanRecord13Array BooleanRecord13[3]; + type BooleanRecord14Array BooleanRecord14[]; + type ClosedBooleanRecord14Array BooleanRecord14[3]; + type BooleanRecord15Array BooleanRecord15[]; + type ClosedBooleanRecord15Array BooleanRecord15[3]; + type BooleanRecord16Array BooleanRecord16[]; + type ClosedBooleanRecord16Array BooleanRecord16[3]; + type BooleanRecord17Array BooleanRecord17[]; + type ClosedBooleanRecord17Array BooleanRecord17[3]; + type BooleanRecord18Array BooleanRecord18[]; + type ClosedBooleanRecord18Array BooleanRecord18[3]; type NilRecord1Array NilRecord1[]; + type ClosedNilRecord1Array NilRecord1[3]; + type NilRecord2Array NilRecord2[]; + type ClosedNilRecord2Array NilRecord2[3]; + type NilRecord3Array NilRecord3[]; + type ClosedNilRecord3Array NilRecord3[3]; + type NilRecord4Array NilRecord4[]; + type ClosedNilRecord4Array NilRecord4[3]; + type NilRecord5Array NilRecord5[]; + type ClosedNilRecord5Array NilRecord5[3]; + type NilRecord6Array NilRecord6[]; + type ClosedNilRecord6Array NilRecord6[3]; + type NilRecord7Array NilRecord7[]; + type ClosedNilRecord7Array NilRecord7[3]; + type NilRecord8Array NilRecord8[]; + type ClosedNilRecord8Array NilRecord8[3]; + type NilRecord9Array NilRecord9[]; + type ClosedNilRecord9Array NilRecord9[3]; + type NilRecord10Array NilRecord10[]; + type ClosedNilRecord10Array NilRecord10[3]; + type NilRecord11Array NilRecord11[]; + type ClosedNilRecord11Array NilRecord11[3]; + type NilRecord12Array NilRecord12[]; + type ClosedNilRecord12Array NilRecord12[3]; + type NilRecord13Array NilRecord13[]; + type ClosedNilRecord13Array NilRecord13[3]; + type NilRecord14Array NilRecord14[]; + type ClosedNilRecord14Array NilRecord14[3]; + type IntegerRecord1Array IntegerRecord1[]; + type ClosedIntegerRecord1Array IntegerRecord1[3]; + type IntegerRecord2Array IntegerRecord2[]; + type ClosedIntegerRecord2Array IntegerRecord2[3]; + type IntegerRecord3Array IntegerRecord3[]; + type ClosedIntegerRecord3Array IntegerRecord3[3]; + type IntegerRecord4Array IntegerRecord4[]; + type ClosedIntegerRecord4Array IntegerRecord4[3]; + type IntegerRecord5Array IntegerRecord5[]; + type ClosedIntegerRecord5Array IntegerRecord5[3]; + type IntegerRecord6Array IntegerRecord6[]; + type ClosedIntegerRecord6Array IntegerRecord6[3]; + type IntegerRecord7Array IntegerRecord7[]; + type ClosedIntegerRecord7Array IntegerRecord7[3]; + type IntegerRecord8Array IntegerRecord8[]; + type ClosedIntegerRecord8Array IntegerRecord8[3]; + type IntegerRecord9Array IntegerRecord9[]; + type ClosedIntegerRecord9Array IntegerRecord9[3]; + type IntegerRecord10Array IntegerRecord10[]; + type ClosedIntegerRecord10Array IntegerRecord10[3]; + type IntegerRecord11Array IntegerRecord11[]; + type ClosedIntegerRecord11Array IntegerRecord11[3]; + type IntegerRecord12Array IntegerRecord12[]; + type ClosedIntegerRecord12Array IntegerRecord12[3]; + type IntegerRecord13Array IntegerRecord13[]; + type ClosedIntegerRecord13Array IntegerRecord13[3]; + type IntegerRecord14Array IntegerRecord14[]; + type ClosedIntegerRecord14Array IntegerRecord14[3]; + type FloatRecord1Array FloatRecord1[]; + type ClosedFloatRecord1Array FloatRecord1[3]; + type FloatRecord2Array FloatRecord2[]; + type ClosedFloatRecord2Array FloatRecord2[3]; + type FloatRecord3Array FloatRecord3[]; + type ClosedFloatRecord3Array FloatRecord3[3]; + type FloatRecord4Array FloatRecord4[]; + type ClosedFloatRecord4Array FloatRecord4[3]; + type FloatRecord5Array FloatRecord5[]; + type ClosedFloatRecord5Array FloatRecord5[3]; + type FloatRecord6Array FloatRecord6[]; + type ClosedFloatRecord6Array FloatRecord6[3]; + type FloatRecord7Array FloatRecord7[]; + type ClosedFloatRecord7Array FloatRecord7[3]; + type FloatRecord8Array FloatRecord8[]; + type ClosedFloatRecord8Array FloatRecord8[3]; + type FloatRecord9Array FloatRecord9[]; + type ClosedFloatRecord9Array FloatRecord9[3]; + type FloatRecord10Array FloatRecord10[]; + type ClosedFloatRecord10Array FloatRecord10[3]; + type FloatRecord11Array FloatRecord11[]; + type ClosedFloatRecord11Array FloatRecord11[3]; + type FloatRecord12Array FloatRecord12[]; + type ClosedFloatRecord12Array FloatRecord12[3]; + type FloatRecord13Array FloatRecord13[]; + type ClosedFloatRecord13Array FloatRecord13[3]; + type FloatRecord14Array FloatRecord14[]; + type ClosedFloatRecord14Array FloatRecord14[3]; + type DecimalRecord1Array DecimalRecord1[]; + type ClosedDecimalRecord1Array DecimalRecord1[3]; + type DecimalRecord2Array DecimalRecord2[]; + type ClosedDecimalRecord2Array DecimalRecord2[3]; + type DecimalRecord3Array DecimalRecord3[]; + type ClosedDecimalRecord3Array DecimalRecord3[3]; + type DecimalRecord4Array DecimalRecord4[]; + type ClosedDecimalRecord4Array DecimalRecord4[3]; + type DecimalRecord5Array DecimalRecord5[]; + type ClosedDecimalRecord5Array DecimalRecord5[3]; + type DecimalRecord6Array DecimalRecord6[]; + type ClosedDecimalRecord6Array DecimalRecord6[3]; + type DecimalRecord7Array DecimalRecord7[]; + type ClosedDecimalRecord7Array DecimalRecord7[3]; + type DecimalRecord8Array DecimalRecord8[]; + type ClosedDecimalRecord8Array DecimalRecord8[3]; + type DecimalRecord9Array DecimalRecord9[]; + type ClosedDecimalRecord9Array DecimalRecord9[3]; + type DecimalRecord10Array DecimalRecord10[]; + type ClosedDecimalRecord10Array DecimalRecord10[3]; + type DecimalRecord11Array DecimalRecord11[]; + type ClosedDecimalRecord11Array DecimalRecord11[3]; + type DecimalRecord12Array DecimalRecord12[]; + type ClosedDecimalRecord12Array DecimalRecord12[3]; + type DecimalRecord13Array DecimalRecord13[]; + type ClosedDecimalRecord13Array DecimalRecord13[3]; + type DecimalRecord14Array DecimalRecord14[]; + type ClosedDecimalRecord14Array DecimalRecord14[3]; + type StringRecord1Array StringRecord1[]; + type ClosedStringRecord1Array StringRecord1[3]; + type StringRecord2Array StringRecord2[]; + type ClosedStringRecord2Array StringRecord2[3]; + type StringRecord3Array StringRecord3[]; + type ClosedStringRecord3Array StringRecord3[3]; + type StringRecord4Array StringRecord4[]; + type ClosedStringRecord4Array StringRecord4[3]; + type StringRecord5Array StringRecord5[]; + type ClosedStringRecord5Array StringRecord5[3]; + type StringRecord6Array StringRecord6[]; + type ClosedStringRecord6Array StringRecord6[3]; + type StringRecord7Array StringRecord7[]; + type ClosedStringRecord7Array StringRecord7[3]; + type StringRecord8Array StringRecord8[]; + type ClosedStringRecord8Array StringRecord8[3]; + type StringRecord9Array StringRecord9[]; + type ClosedStringRecord9Array StringRecord9[3]; + type StringRecord10Array StringRecord10[]; + type ClosedStringRecord10Array StringRecord10[3]; + type StringRecord11Array StringRecord11[]; + type ClosedStringRecord11Array StringRecord11[3]; + type StringRecord12Array StringRecord12[]; + type ClosedStringRecord12Array StringRecord12[3]; + type StringRecord13Array StringRecord13[]; + type ClosedStringRecord13Array StringRecord13[3]; + type StringRecord14Array StringRecord14[]; + type ClosedStringRecord14Array StringRecord14[3]; + type StringRecord15Array StringRecord15[]; + type StringRecord16Array StringRecord16[]; + type StringRecord17Array StringRecord17[]; + type StringRecord18Array StringRecord18[]; + type StringRecord19Array StringRecord19[]; + type StringRecord20Array StringRecord20[]; + type StringRecord21Array StringRecord21[]; + type StringRecord22Array StringRecord22[]; + type StringRecord23Array StringRecord23[]; type JsonRecord1Array JsonRecord1[]; + type ClosedJsonRecord1Array JsonRecord1[3]; + type JsonRecord2Array JsonRecord2[]; + type ClosedJsonRecord2Array JsonRecord2[3]; + type JsonRecord3Array JsonRecord3[]; + type ClosedJsonRecord3Array JsonRecord3[3]; + type JsonRecord4Array JsonRecord4[]; + type ClosedJsonRecord4Array JsonRecord4[3]; + type JsonRecord5Array JsonRecord5[]; + type ClosedJsonRecord5Array JsonRecord5[3]; + type JsonRecord6Array JsonRecord6[]; + type ClosedJsonRecord6Array JsonRecord6[3]; + type JsonRecord7Array JsonRecord7[]; + type ClosedJsonRecord7Array JsonRecord7[3]; + type JsonRecord8Array JsonRecord8[]; + type ClosedJsonRecord8Array JsonRecord8[3]; + type JsonRecord9Array JsonRecord9[]; + type ClosedJsonRecord9Array JsonRecord9[3]; + type JsonRecord10Array JsonRecord10[]; + type ClosedJsonRecord10Array JsonRecord10[3]; + type JsonRecord11Array JsonRecord11[]; + type ClosedJsonRecord11Array JsonRecord11[3]; + type JsonRecord12Array JsonRecord12[]; + type ClosedJsonRecord12Array JsonRecord12[3]; + type JsonRecord13Array JsonRecord13[]; + type ClosedJsonRecord13Array JsonRecord13[3]; + type JsonRecord14Array JsonRecord14[]; + type ClosedJsonRecord14Array JsonRecord14[3]; + type AnydataRecord1Array AnydataRecord1[]; + type ClosedAnydataRecord1Array AnydataRecord1[3]; + type AnydataRecord2Array AnydataRecord2[]; + type ClosedAnydataRecord2Array AnydataRecord2[3]; + type AnydataRecord3Array AnydataRecord3[]; + type ClosedAnydataRecord3Array AnydataRecord3[3]; + type AnydataRecord4Array AnydataRecord4[]; + type ClosedAnydataRecord4Array AnydataRecord4[3]; + type AnydataRecord5Array AnydataRecord5[]; + type ClosedAnydataRecord5Array AnydataRecord5[3]; + type AnydataRecord6Array AnydataRecord6[]; + type ClosedAnydataRecord6Array AnydataRecord6[3]; + type AnydataRecord7Array AnydataRecord7[]; + type ClosedAnydataRecord7Array AnydataRecord7[3]; + type AnydataRecord8Array AnydataRecord8[]; + type ClosedAnydataRecord8Array AnydataRecord8[3]; + type AnydataRecord9Array AnydataRecord9[]; + type ClosedAnydataRecord9Array AnydataRecord9[3]; + type AnydataRecord10Array AnydataRecord10[]; + type ClosedAnydataRecord10Array AnydataRecord10[3]; + type AnydataRecord11Array AnydataRecord11[]; + type ClosedAnydataRecord11Array AnydataRecord11[3]; + type AnydataRecord12Array AnydataRecord12[]; + type ClosedAnydataRecord12Array AnydataRecord12[3]; + type AnydataRecord13Array AnydataRecord13[]; + type ClosedAnydataRecord13Array AnydataRecord13[3]; + type AnydataRecord14Array AnydataRecord14[]; + type ClosedAnydataRecord14Array AnydataRecord14[3]; + type CustomRecord1Array CustomRecord1[]; + type ClosedCustomRecord1Array CustomRecord1[3]; + type CustomRecord2Array CustomRecord2[]; + type ClosedCustomRecord2Array CustomRecord2[3]; + type CustomRecord3Array CustomRecord3[]; + type ClosedCustomRecord3Array CustomRecord3[3]; + type CustomRecord4Array CustomRecord4[]; + type ClosedCustomRecord4Array CustomRecord4[3]; + type CustomRecord5Array CustomRecord5[]; + type ClosedCustomRecord5Array CustomRecord5[3]; + type CustomRecord6Array CustomRecord6[]; + type ClosedCustomRecord6Array CustomRecord6[3]; + type CustomRecord7Array CustomRecord7[]; + type ClosedCustomRecord7Array CustomRecord7[3]; + type CustomRecord8Array CustomRecord8[]; + type ClosedCustomRecord8Array CustomRecord8[3]; + type CustomRecord9Array CustomRecord9[]; + type ClosedCustomRecord9Array CustomRecord9[3]; + type CustomRecord10Array CustomRecord10[]; + type ClosedCustomRecord10Array CustomRecord10[3]; + type CustomRecord11Array CustomRecord11[]; + type ClosedCustomRecord11Array CustomRecord11[3]; + type CustomRecord12Array CustomRecord12[]; + type ClosedCustomRecord12Array CustomRecord12[3]; + type CustomRecord13Array CustomRecord13[]; + type ClosedCustomRecord13Array CustomRecord13[3]; + type CustomRecord14Array CustomRecord14[]; + type ClosedCustomRecord14Array CustomRecord14[3]; type CustomRecord15Array CustomRecord15[]; + type CustomRecord16Array CustomRecord16[]; + type CustomRecord17Array CustomRecord17[]; + type CustomRecord18Array CustomRecord18[]; + type CustomRecord19Array CustomRecord19[]; + type CustomRecord20Array CustomRecord20[]; + type CustomRecord21Array CustomRecord21[]; + type CustomRecord22Array CustomRecord22[]; + type CustomRecord23Array CustomRecord23[]; + type CustomRecord24Array CustomRecord24[]; + type CustomRecord25Array CustomRecord25[]; + type CustomRecord26Array CustomRecord26[]; + type CustomRecord27Array CustomRecord27[]; +type CustomRecord28Array CustomRecord28[]; +type CustomRecord29Array CustomRecord29[]; +type CustomRecord30Array CustomRecord30[]; +type CustomRecord31Array CustomRecord31[]; +type CustomRecord32Array CustomRecord32[]; +type CustomRecord33Array CustomRecord33[]; +type CustomRecord34Array CustomRecord34[]; +type CustomRecord35Array CustomRecord35[]; +type CustomRecord36Array CustomRecord36[]; +type CustomRecord37Array CustomRecord37[]; +type CustomRecord38Array CustomRecord38[]; +type CustomRecord39Array CustomRecord39[]; +type CustomRecord40Array CustomRecord40[]; +type CustomRecord41Array CustomRecord41[]; +type CustomRecord42Array CustomRecord42[]; +type CustomRecord43Array CustomRecord43[]; +type CustomRecord44Array CustomRecord44[]; +type CustomRecord45Array CustomRecord45[]; +type CustomRecord46Array CustomRecord46[]; +type CustomRecord47Array CustomRecord47[]; +type CustomRecord48Array CustomRecord48[]; +type CustomRecord49Array CustomRecord49[]; +type CustomRecord50Array CustomRecord50[]; +type CustomRecord51Array CustomRecord51[]; +type CustomRecord52Array CustomRecord52[]; +type CustomRecord53Array CustomRecord53[]; +type CustomRecord54Array CustomRecord54[]; +type CustomRecord55Array CustomRecord55[]; +type CustomRecord56Array CustomRecord56[]; +// type CustomRecord57Array CustomRecord57[]; type BooleanTuple1Array BooleanTuple1[]; + type ClosedBooleanTuple1Array BooleanTuple1[3]; + type BooleanTuple2Array BooleanTuple2[]; + type ClosedBooleanTuple2Array BooleanTuple2[3]; + type BooleanTuple3Array BooleanTuple3[]; + type ClosedBooleanTuple3Array BooleanTuple3[3]; + type BooleanTuple4Array BooleanTuple4[]; + type ClosedBooleanTuple4Array BooleanTuple4[3]; type NillableBooleanTuple5Array NillableBooleanTuple5[]; + type NillableBooleanTuple6Array NillableBooleanTuple6[]; + type NillableBooleanTuple7Array NillableBooleanTuple7[]; + type NillableBooleanTuple8Array NillableBooleanTuple8[]; + type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; type NilTuple1Array NilTuple1[]; + type ClosedNilTuple1Array NilTuple1[3]; + type NilTuple2Array NilTuple2[]; + type ClosedNilTuple2Array NilTuple2[3]; + type NilTuple3Array NilTuple3[]; + type ClosedNilTuple3Array NilTuple3[3]; + type NilTuple4Array NilTuple4[]; + type ClosedNilTuple4Array NilTuple4[3]; + type IntegerTuple1Array IntegerTuple1[]; + type ClosedIntegerTuple1Array IntegerTuple1[3]; + type IntegerTuple2Array IntegerTuple2[]; + type ClosedIntegerTuple2Array IntegerTuple2[3]; + type IntegerTuple3Array IntegerTuple3[]; + type ClosedIntegerTuple3Array IntegerTuple3[3]; + type IntegerTuple4Array IntegerTuple4[]; + type ClosedIntegerTuple4Array IntegerTuple4[3]; + type FloatTuple1Array FloatTuple1[]; + type ClosedFloatTuple1Array FloatTuple1[3]; + type FloatTuple2Array FloatTuple2[]; + type ClosedFloatTuple2Array FloatTuple2[3]; + type FloatTuple3Array FloatTuple3[]; + type ClosedFloatTuple3Array FloatTuple3[3]; + type FloatTuple4Array FloatTuple4[]; + type ClosedFloatTuple4Array FloatTuple4[3]; + type DecimalTuple1Array DecimalTuple1[]; + type ClosedDecimalTuple1Array DecimalTuple1[3]; + type DecimalTuple2Array DecimalTuple2[]; + type ClosedDecimalTuple2Array DecimalTuple2[3]; + type DecimalTuple3Array DecimalTuple3[]; + type ClosedDecimalTuple3Array DecimalTuple3[3]; + type DecimalTuple4Array DecimalTuple4[]; + type ClosedDecimalTuple4Array DecimalTuple4[3]; + type StringTuple1Array StringTuple1[]; + type ClosedStringTuple1Array StringTuple1[3]; + type StringTuple2Array StringTuple2[]; + type ClosedStringTuple2Array StringTuple2[3]; + type StringTuple3Array StringTuple3[]; + type ClosedStringTuple3Array StringTuple3[3]; + type StringTuple4Array StringTuple4[]; + type ClosedStringTuple4Array StringTuple4[3]; type AnydataTuple1Array AnydataTuple1[]; + type ClosedAnydataTuple1Array AnydataTuple1[3]; + type AnydataTuple2Array AnydataTuple2[]; + type ClosedAnydataTuple2Array AnydataTuple2[3]; + type AnydataTuple3Array AnydataTuple3[]; + type ClosedAnydataTuple3Array AnydataTuple3[3]; + type AnydataTuple4Array AnydataTuple4[]; + type ClosedAnydataTuple4Array AnydataTuple4[3]; + type JsonTuple1Array JsonTuple1[]; + type ClosedJsonTuple1Array JsonTuple1[3]; + type JsonTuple2Array JsonTuple2[]; + type ClosedJsonTuple2Array JsonTuple2[3]; + type JsonTuple3Array JsonTuple3[]; + type ClosedJsonTuple3Array JsonTuple3[3]; + type JsonTuple4Array JsonTuple4[]; + type ClosedJsonTuple4Array JsonTuple4[3]; + type CustomTuple1Array CustomTuple1[]; + type ClosedCustomTuple1Array CustomTuple1[3]; + type CustomTuple2Array CustomTuple2[]; + type ClosedCustomTuple2Array CustomTuple2[3]; + type CustomTuple3Array CustomTuple3[]; + type ClosedCustomTuple3Array CustomTuple3[3]; + type CustomTuple4Array CustomTuple4[]; + type ClosedCustomTuple4Array CustomTuple4[3]; + type CustomTuple5Array CustomTuple5[]; + type ClosedCustomTuple5Array CustomTuple5[3]; + type CustomTuple6Array CustomTuple6[]; + type CustomTuple7Array CustomTuple7[]; + type CustomTuple8Array CustomTuple8[]; type ClosedCustomTuple6Array CustomTuple6[3]; + type IntegerArray1Array IntegerArray1[]; + type ClosedIntegerArray1Array IntegerArray1[3]; + type IntegerArray2Array IntegerArray2[]; + type ClosedIntegerArray2Array IntegerArray2[3]; + type IntegerArray3Array IntegerArray3[]; + type ClosedIntegerArray3Array IntegerArray3[3]; + type IntegerArray4Array IntegerArray4[]; + type ClosedIntegerArray4Array IntegerArray4[3]; + type IntegerArray5Array IntegerArray5[]; + type ClosedIntegerArray5Array IntegerArray5[3]; + type IntegerArray6Array IntegerArray5[]; + type ClosedIntegerArray6Array IntegerArray5[3]; + type StringArray1Array StringArray1[]; type StringArrayArray StringArray[]; + type NillableStringArrayArray NillableStringArray[]; + type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; type ClosedStringArray1Array StringArray1[3]; + type StringArray2Array StringArray2[]; + type ClosedStringArray2Array StringArray2[3]; + type StringArray3Array StringArray3[]; + type ClosedStringArray3Array StringArray3[3]; + type StringArray4Array StringArray4[]; + type ClosedStringArray4Array StringArray4[3]; + type StringArray5Array StringArray5[]; + type ClosedStringArray5Array StringArray5[3]; + type StringArray6Array StringArray5[]; + type ClosedStringArray6Array StringArray5[3]; + type FloatArray1Array FloatArray1[]; + type ClosedFloatArray1Array FloatArray1[3]; + type FloatArray2Array FloatArray2[]; + type ClosedFloatArray2Array FloatArray2[3]; + type FloatArray3Array FloatArray3[]; + type ClosedFloatArray3Array FloatArray3[3]; + type FloatArray4Array FloatArray4[]; + type ClosedFloatArray4Array FloatArray4[3]; + type FloatArray5Array FloatArray5[]; + type ClosedFloatArray5Array FloatArray5[3]; + type FloatArray6Array FloatArray5[]; + type ClosedFloatArray6Array FloatArray5[3]; + type DecimalArray1Array DecimalArray1[]; + type ClosedDecimalArray1Array DecimalArray1[3]; + type DecimalArray2Array DecimalArray2[]; + type ClosedDecimalArray2Array DecimalArray2[3]; + type DecimalArray3Array DecimalArray3[]; + type ClosedDecimalArray3Array DecimalArray3[3]; + type DecimalArray4Array DecimalArray4[]; + type ClosedDecimalArray4Array DecimalArray4[3]; + type DecimalArray5Array DecimalArray5[]; + type ClosedDecimalArray5Array DecimalArray5[3]; + type DecimalArray6Array DecimalArray5[]; + type ClosedDecimalArray6Array DecimalArray5[3]; type BooleanArrayArray BooleanArray[]; + type ClosedBooleanArrayArray BooleanArray[3]; type NillableBooleanArrayArray NillableBooleanArray[]; -type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; +type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; type BooleanArray2Array BooleanArray2[]; + type ClosedBooleanArray2Array BooleanArray2[3]; + type BooleanArray3Array BooleanArray3[]; + type ClosedBooleanArray3Array BooleanArray3[3]; + type BooleanArray4Array BooleanArray4[]; + type ClosedBooleanArray4Array BooleanArray4[3]; + type BooleanArray5Array BooleanArray5[]; + type ClosedBooleanArray5Array BooleanArray5[3]; + type BooleanArray6Array BooleanArray5[]; + type ClosedBooleanArray6Array BooleanArray5[3]; + type NilArray1Array NilArray1[]; + type ClosedNilArray1Array NilArray1[3]; + type NilArray2Array NilArray2[]; + type ClosedNilArray2Array NilArray2[3]; + type NilArray3Array NilArray3[]; + type ClosedNilArray3Array NilArray3[3]; + type NilArray4Array NilArray4[]; + type ClosedNilArray4Array NilArray4[3]; + type NilArray5Array NilArray5[]; + type ClosedNilArray5Array NilArray5[3]; + type NilArray6Array NilArray5[]; + type ClosedNilArray6Array NilArray5[3]; + type JsonArray1Array JsonArray1[]; + type ClosedJsonArray1Array JsonArray1[3]; + type JsonArray2Array JsonArray2[]; + type ClosedJsonArray2Array JsonArray2[3]; + type JsonArray3Array JsonArray3[]; + type ClosedJsonArray3Array JsonArray3[3]; + type JsonArray4Array JsonArray4[]; + type ClosedJsonArray4Array JsonArray4[3]; + type JsonArray5Array JsonArray5[]; + type ClosedJsonArray5Array JsonArray5[3]; + type JsonArray6Array JsonArray5[]; + type ClosedJsonArray6Array JsonArray5[3]; + type AnydataArray1Array AnydataArray1[]; + type ClosedAnydataArray1Array AnydataArray1[3]; + type AnydataArray2Array AnydataArray2[]; + type ClosedAnydataArray2Array AnydataArray2[3]; + type AnydataArray3Array AnydataArray3[]; + type ClosedAnydataArray3Array AnydataArray3[3]; + type AnydataArray4Array AnydataArray4[]; + type ClosedAnydataArray4Array AnydataArray4[3]; + type AnydataArray5Array AnydataArray5[]; + type ClosedAnydataArray5Array AnydataArray5[3]; + type AnydataArray6Array AnydataArray5[]; + type ClosedAnydataArray6Array AnydataArray5[3]; + type CustomArray1Array CustomArray1[]; + type ClosedCustomArray1Array CustomArray1[3]; + type CustomArray2Array CustomArray2[]; + type ClosedCustomArray2Array CustomArray2[3]; + type CustomArray3Array CustomArray3[]; + type ClosedCustomArray3Array CustomArray3[3]; + type CustomArray4Array CustomArray4[]; + type ClosedCustomArray4Array CustomArray4[3]; + type CustomArray5Array CustomArray5[]; + type ClosedCustomArray5Array CustomArray5[3]; + type CustomArray6Array CustomArray5[]; + type ClosedCustomArray6Array CustomArray5[3]; + type IntegerMapArray IntegerMap[]; + type ClosedIntegerMapArray IntegerMap[3]; + type StringMapArray StringMap[]; + type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; -type IntUnionStringMapArray IntUnionStringMap[]; + +type IntUnionStringMapArray IntUnionStringMap[]; type ClosedStringMapArray StringMap[3]; + type DecimalMapArray DecimalMap[]; + type ClosedDecimalMapArray DecimalMap[3]; + type FloatMapArray FloatMap[]; + type ClosedFloatMapArray FloatMap[3]; + type BooleanMapArray BooleanMap[]; + type NillableBooleanMapArray NillableBooleanMap[]; + type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; + type IntUnionBooleanMapArray IntUnionBooleanMap[]; type ClosedBooleanMapArray BooleanMap[3]; + type NilMapArray NilMap[]; + type ClosedNilMapArray NilMap[3]; + type JsonMapArray JsonMap[]; + type ClosedJsonMapArray JsonMap[3]; + type AnydataMapArray AnydataMap[]; + type ClosedAnydataMapArray AnydataMap[3]; + type CustomMapArray CustomMap[]; + type ClosedCustomMapArray CustomMap[3]; diff --git a/ballerina/tests/user_configurations.bal b/ballerina/tests/user_configurations.bal deleted file mode 100644 index 837d24e..0000000 --- a/ballerina/tests/user_configurations.bal +++ /dev/null @@ -1,75 +0,0 @@ -FromCSVConfig config1 = { - startNumber: 0, - headerStartNumber: 0, - dataStartNumber: 1, - headers: true, - escapeCharacter: "\\", - ignoreEmptyLines: true, - separator: ",", - quote: "\"", - skipHeaders: false, - skipdataRows: 0, - dataRowCount: -1, - orderBy: (), - skipColumns: (), - customheader: (), - suppressEscaping: false, - nullValue: () -}; - -FromCSVConfig config2 = { - startNumber: 10, - headerStartNumber: 5, - dataStartNumber: 2, - headers: false, - escapeCharacter: "/", - ignoreEmptyLines: false, - separator: ";", - quote: "'", - skipHeaders: true, - skipdataRows: 2, - dataRowCount: 100, - orderBy: [ - { - column: "column1", - columnOrder: ASC - } - ], - skipColumns:["column2"], - customheader:["column1", "column2", "column3", "column4"], - suppressEscaping: true, - nullValue: "" -}; - -FromCSVConfig config3 = { - customheader: () -}; - -FromCSVConfig config4 = { - skipColumns: ["column1"] -}; - -FromCSVConfig config5 = { - skipColumns: ["column1", "column2"] -}; - -FromCSVConfig config6 = { - skipColumns: [1, 2, 3] -}; - -FromCSVConfig config7 = { - customheader: ["header1", "header2", "header3"] -}; - -FromCSVConfig config8 = { - separator: ";" -}; - -FromCSVConfig config9 = { - escapeCharacter: "/" -}; - -FromCSVConfig config10 = { - quote: "'" -}; - diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 156f99d..35ebe5f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -71,7 +71,7 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, switch (currentCsvNodeType.getTag()) { case TypeTags.MAP_TAG: case TypeTags.RECORD_TYPE_TAG: - ((BMap) currentCsv).put(StringUtils.fromString(sm.headers.get(sm.columnIndex)), + ((BMap) currentCsv).put(StringUtils.fromString(getHeaderValueForColumnIndex(sm)), convertedValue); return currentCsv; case TypeTags.ARRAY_TAG: @@ -91,9 +91,21 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, } } + public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { + if (sm.config.skipHeaders || !sm.config.headers) { + String header = String.valueOf(sm.columnIndex + 1); + Map fieldHierarchy = sm.fieldHierarchy; + if (fieldHierarchy.containsKey(header)) { + fieldHierarchy.remove(header); + } + return header; + } + return sm.headers.get(sm.columnIndex); + } + private static boolean ignoreIncompatibilityErrorsForMaps(CsvParser.StateMachine sm, Type type, Type exptype) { if (exptype.getTag() == TypeTags.RECORD_TYPE_TAG) { - String header = sm.headers.get(sm.columnIndex); + String header = getHeaderValueForColumnIndex(sm); Map fields = sm.fieldNames; if (fields.containsKey(header)) { return false; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index b7275b0..36e8af7 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -181,12 +181,13 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError default: throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); } - boolean header = config.headers; + State currentState; - if (header) { + if (config.headers) { currentState = HEADER_START_STATE; } else { currentState = ROW_START_STATE; + addFieldNamesForNonHeaderState(); } try { char[] buff = new char[1024]; @@ -211,6 +212,12 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError } } + private void addFieldNamesForNonHeaderState() { + for (Map.Entry entry: this.fieldHierarchy.entrySet()) { + this.fieldNames.put(entry.getKey(), entry.getValue()); + } + } + private void append(char ch) { try { this.charBuff[this.charBuffIndex] = ch; @@ -222,7 +229,7 @@ private void append(char ch) { } } - private boolean isEndOfTheRow(char ch) { + private boolean isNewLineOrEof(char ch) { return ch == NEWLINE || ch == EOF; } @@ -256,19 +263,29 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.lineNumber++; continue; } - if (skipHeaders || customHeader != null) { - if (!sm.peek().isEmpty() && sm.isEndOfTheRow(ch)) { - checkAndAddCustomHeaders(sm.headers, customHeader, sm.config.skipHeaders); + if (customHeader != null) { + if (isEndOfTheRow(sm, ch, true)) { + checkAndAddCustomHeaders(sm, customHeader); sm.lineNumber++; state = HEADER_END_STATE; break; } continue; - } else if (ch == separator) { + } + if (skipHeaders) { + if (isEndOfTheRow(sm, ch, true)) { + sm.lineNumber++; + state = HEADER_END_STATE; + break; + } + continue; + } + + if (ch == separator) { addHeader(sm); sm.columnIndex++; continue; - } else if (!sm.peek().isEmpty() && sm.isEndOfTheRow(ch)) { + } else if (isEndOfTheRow(sm, ch)) { addHeader(sm); finalizeHeaders(sm); sm.columnIndex = 0; @@ -288,14 +305,21 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return state; } - private void checkAndAddCustomHeaders(ArrayList headers, Object customHeader, boolean skipHeaders) { - if (skipHeaders || headers == null) { + private void checkAndAddCustomHeaders(StateMachine sm, Object customHeader) { + if (customHeader == null) { return; } BArray customHeaders = (BArray) customHeader; for (int i = 0; i < customHeaders.size(); i++) { - headers.add(StringUtils.getStringValue(customHeaders.get(i))); + String header = StringUtils.getStringValue(customHeaders.get(i)); + Map fieldHierarchy = sm.fieldHierarchy; + sm.headers.add(header); + if (fieldHierarchy.containsKey(header)) { + Field field = fieldHierarchy.get(header); + sm.fieldNames.put(header, field); + fieldHierarchy.remove(header); + } } } @@ -354,10 +378,6 @@ private void addHeader(StateMachine sm) throws CsvParserException { } sm.headers.add(value); } - - private boolean validateHeaderValueWithRecordFields(StateMachine sm, String value) { - return sm.fieldHierarchy.containsKey(value) || sm.restType != null; - } } private static class HeaderEndState implements State { @@ -372,8 +392,7 @@ private static class RowStartState implements State { public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { char ch; State state = ROW_START_STATE; - //TODO: Add separator here - char separator = ','; + char separator = sm.config.separator; updateHeaders(sm); // TODO: Ignore this in future @@ -387,7 +406,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C break; } if (sm.rowIndex < sm.config.skipDataRows) { - if (sm.isEndOfTheRow(ch)) { + if (isEndOfTheRow(sm, ch)) { sm.lineNumber++; sm.rowIndex++; } @@ -400,11 +419,11 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } if (ch == separator) { addRowValue(sm); - } else if (sm.isEndOfTheRow(ch)) { + } else if (isEndOfTheRow(sm, ch)) { sm.lineNumber++; handleCsvRow(sm); + checkOptionalFieldsAndLogError(sm.fieldHierarchy); if (ch == EOF) { - checkOptionalFieldsAndLogError(sm.fieldHierarchy); state = ROW_END_STATE; } } else if (StateMachine.isWhitespace(ch)) { @@ -418,7 +437,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } private void updateHeaders(StateMachine sm) { - if (!sm.config.headers || sm.config.skipHeaders){ + if (!sm.config.headers || sm.config.skipHeaders) { return; } List updatedHeaders = Arrays.asList( @@ -536,7 +555,7 @@ private Type getExpectedRowTypeOfArray(StateMachine sm, ArrayType arrayType) { private Type getExpectedRowTypeOfRecord(StateMachine sm) { // TODO: These can be make as module level variables - String header = sm.headers.get(sm.columnIndex); + String header = CsvCreator.getHeaderValueForColumnIndex(sm); Map fields = sm.fieldNames; if (fields.containsKey(header)) { //TODO: Optimize @@ -686,6 +705,14 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } + public static boolean isEndOfTheRow(CsvParser.StateMachine sm, char ch) { + return isEndOfTheRow(sm, ch, false); + } + + public static boolean isEndOfTheRow(CsvParser.StateMachine sm, char ch, boolean hasHeaderSkipConfig) { + return (ch == EOF || hasHeaderSkipConfig || !sm.peek().isEmpty()) && sm.isNewLineOrEof(ch); + } + public static class CsvParserException extends Exception { public CsvParserException(String msg) { super(msg); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java index b080a8c..88c00eb 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java @@ -11,7 +11,6 @@ import java.util.Set; public class QueryParser { - private static String columnSeparator = ","; private static String rangeSeparator = ":"; private static String exclamationCharacter = "!"; private static String astrix = "*"; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index bcd72ec..cc10e2d 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -3,12 +3,11 @@ import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.*; -import io.ballerina.runtime.api.utils.JsonUtils; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.*; import io.ballerina.stdlib.data.csvdata.csv.CsvConfig; -import io.ballerina.stdlib.data.csvdata.csv.CsvTraversal; +import io.ballerina.stdlib.data.csvdata.csv.CsvParser; import io.ballerina.stdlib.data.csvdata.csv.QueryParser; import java.util.Arrays; From 9074ecfbb7d8042fcff8bd6015c6314fb5543e6a Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 25 Mar 2024 04:27:43 +0530 Subject: [PATCH 022/147] Add tests for several configs of header params --- .../test_from_csv_with_user_configs.bal.bal | 726 +++++++++++++----- .../stdlib/data/csvdata/csv/CsvConfig.java | 22 + .../stdlib/data/csvdata/csv/CsvCreator.java | 43 +- .../stdlib/data/csvdata/csv/CsvParser.java | 67 +- .../csvdata/utils/DiagnosticErrorCode.java | 3 +- native/src/main/resources/error.properties | 5 +- 6 files changed, 624 insertions(+), 242 deletions(-) diff --git a/ballerina/tests/test_from_csv_with_user_configs.bal.bal b/ballerina/tests/test_from_csv_with_user_configs.bal.bal index cf668b5..6402fc2 100644 --- a/ballerina/tests/test_from_csv_with_user_configs.bal.bal +++ b/ballerina/tests/test_from_csv_with_user_configs.bal.bal @@ -2,77 +2,354 @@ import ballerina/test; @test:Config{enable} function testStartNumbers() { - + } @test:Config{enable} function testCustomHeaders() { + testHeaderConfigWithFalseValue(); + testSkipHeaderConfigWithFalseValue({skipHeaders: true}); + testHeaderConfigWithFalseValue(config34); + testCustomHeadersPresentConfigs(); + testCustomHeadersWithFalseHeadersPresentConfigs(); + testCustomHeadersWithFalseHeadersPresentConfigs(config36); + testCustomHeadersPresentConfigs(config24); +} + +function testCustomHeadersWithFalseHeadersPresentConfigs(FromCSVConfig config = config23) { + CustomRecord46Array|CsvConversionError v20 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v20, [ + {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord46Array|CsvConversionError v20_2 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v20_2, [ + {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord47Array|CsvConversionError v21 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v21, [ + {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord48Array|CsvConversionError v22 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v22, [ + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord48Array|CsvConversionError v22_2 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v22_2, [ + {H1: "a", H2: "b", H3: "c", H4: "d", H5: "e", H6: "f"}, + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord49Array|CsvConversionError v23 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v23, [ + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord50Array|CsvConversionError v24 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v24, [ + {H1: 1, H4: 2.234, H2: "string1", H3: true, H5: 2.234, H6: ()}, + {H1: 1, H4: 0.0, H2: "string2", H3: false, H5: 0, H6: null}, + {H1: 1, H4: 1.23, H2: "string3", H3: 0, H5: 1.23, H6: ()}, + {H1: 1, H4: -6.51, H2: "string4", H3: 1, H5: -6.51, H6: ()}, + {H1: 1, H4: 3.0, H2: "string5", H3: true, H5: 3, H6: ()} + ], string `Test failed for config ${config.toBalString()}`); - // headers config parameter + CustomRecord50Array|CsvConversionError v24_2 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v24_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v24_2).message(), generateErrorMessageForInvalidCast("a", "int"), string `Test failed for config ${config.toBalString()}`); - record {}[]|CsvConversionError v1 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord51Array|CsvConversionError v25 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v25, [ + {H1: 1, H4: 2.234}, + {H1: 1, H4: 0.0}, + {H1: 1, H4: 1.23}, + {H1: 1, H4: -6.51}, + {H1: 1, H4: 3.0} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord52Array|CsvConversionError v26 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v26, [ + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord52Array|CsvConversionError v26_2 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v26_2, [ + {H1: "a", H2: "b", H3: "c", H4: "d", H5: "e", H6: "f"}, + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord53Array|CsvConversionError v27 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v27, [ + {H1: 1, H4: 2.234, "H5": 2.234}, + {H1: 1, H4: 0.0, "H5": 0}, + {H1: 1, H4: 1.23, "H3": 0, "H5": 1.23}, + {H1: 1, H4: -6.51, "H3": 1, "H5": -6.51}, + {H1: 1, H4: 3.0, "H5": 3} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord53Array|CsvConversionError v27_2 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v27_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v27_2).message(), generateErrorMessageForInvalidCast("a", "int"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord54Array|CsvConversionError v29 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v29 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v29).message(), generateErrorMessageForMissingRequiredField("1"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord54Array|CsvConversionError v29_2 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v29_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v29_2).message(), generateErrorMessageForMissingRequiredField("1"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord55Array|CsvConversionError v30 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v30, [ + {H1: "1", H4: "2.234",'1: 10}, + {H1: "1", H4: "0", '1: 10}, + {H1: "1", H4: "1.23", '1: 10}, + {H1: "1", H4: "-6.51", '1: 10}, + {H1: "1", H4: "3", '1: 10} + ], string `Test failed for config ${config.toBalString()}`); +} + +function testCustomHeadersPresentConfigs(FromCSVConfig config = config22) { + CustomRecord46Array|CsvConversionError v20 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v20, [ + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord46Array|CsvConversionError v20_2 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v20_2, [ + {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord47Array|CsvConversionError v21 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v21, [ + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord47Array|CsvConversionError v21_2 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v21_2, [ + {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, + {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, + {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, + {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, + {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord48Array|CsvConversionError v22 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v22, [ + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord48Array|CsvConversionError v22_2 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v22_2, [ + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord49Array|CsvConversionError v23 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v23, [ + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord49Array|CsvConversionError v23_2 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v23_2, [ + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord50Array|CsvConversionError v24 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v24, [ + {H1: 1, H4: 0.0, H2: "string2", H3: false, H5: 0, H6: null}, + {H1: 1, H4: 1.23, H2: "string3", H3: 0, H5: 1.23, H6: ()}, + {H1: 1, H4: -6.51, H2: "string4", H3: 1, H5: -6.51, H6: ()}, + {H1: 1, H4: 3.0, H2: "string5", H3: true, H5: 3, H6: ()} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord50Array|CsvConversionError v24_2 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v24_2, [ + {H1: 1, H4: 2.234, H2: "string1", H3: true, H5: 2.234, H6: ()}, + {H1: 1, H4: 0.0, H2: "string2", H3: false, H5: 0, H6: null}, + {H1: 1, H4: 1.23, H2: "string3", H3: 0, H5: 1.23, H6: ()}, + {H1: 1, H4: -6.51, H2: "string4", H3: 1, H5: -6.51, H6: ()}, + {H1: 1, H4: 3.0, H2: "string5", H3: true, H5: 3, H6: ()} + ], string `Test failed for config ${config.toBalString()}`); + + record{() H1;}[]|CsvConversionError v24_3 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v24_3 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v24_3).message(), generateErrorMessageForInvalidCast("1", "()"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord51Array|CsvConversionError v25 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v25, [ + {H1: 1, H4: 0.0}, + {H1: 1, H4: 1.23}, + {H1: 1, H4: -6.51}, + {H1: 1, H4: 3.0} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord52Array|CsvConversionError v26 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v26, [ + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord52Array|CsvConversionError v26_2 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v26_2, [ + {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, + {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, + {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, + {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, + {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord53Array|CsvConversionError v27 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v27, [ + {H1: 1, H4: 0.0, "H5": 0}, + {H1: 1, H4: 1.23, "H3": 0, "H5": 1.23}, + {H1: 1, H4: -6.51, "H3": 1, "H5": -6.51}, + {H1: 1, H4: 3.0, "H5": 3} + ], string `Test failed for config ${config.toBalString()}`); + + record{() H1;}[]|CsvConversionError v27_2 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v27_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v27_2).message(), generateErrorMessageForInvalidCast("1", "()"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord54Array|CsvConversionError v29 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v29 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v29).message(), generateErrorMessageForMissingRequiredField("1"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord54Array|CsvConversionError v29_2 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v29_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v29_2).message(), generateErrorMessageForMissingRequiredField("1"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord55Array|CsvConversionError v30 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v30, [ + {H1: "1", H4: "0", '1: 10}, + {H1: "1", H4: "1.23", '1: 10}, + {H1: "1", H4: "-6.51", '1: 10}, + {H1: "1", H4: "3", '1: 10} + ], string `Test failed for config ${config.toBalString()}`); +} + +function testSkipHeaderConfigWithFalseValue(FromCSVConfig config) { + record {}[]|CsvConversionError v1 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v1, [ - {'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: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord28Array|CsvConversionError v2 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord28Array|CsvConversionError v2 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v2, [ - {'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: "1", '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, {'1: "1", '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord29Array|CsvConversionError v3 = fromCsvStringWithType(csvStringData1, config21); - test:assertTrue(v3 is CsvConversionError); - test:assertEquals((v3).message(), generateErrorMessageForInvalidCast("a", "int")); + CustomRecord29Array|CsvConversionError v3 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v3, [ + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, + {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord30Array|CsvConversionError v4 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord30Array|CsvConversionError v4 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v4, [ - {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord31Array|CsvConversionError v5 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord31Array|CsvConversionError v5 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v5, [ - {'1: "a", '6: "f"}, {'1: "1", '6: "()"}, {'1: "1", '6: "null"}, {'1: "1", '6: "()"}, {'1: "1", '6: "()"}, {'1: "1", '6: "()"} - ]); + ], string `Test failed for config ${config.toBalString()}`); + record{() '1;}[]|CsvConversionError v6 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v6 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v6).message(), generateErrorMessageForInvalidCast("1", "()"), string `Test failed for config ${config.toBalString()}`); - CustomRecord32Array|CsvConversionError v6 = fromCsvStringWithType(csvStringData1, config21); - test:assertTrue(v6 is CsvConversionError); - test:assertEquals((v3).message(), generateErrorMessageForInvalidCast("a", "int")); - - CustomRecord33Array|CsvConversionError v7 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord33Array|CsvConversionError v7 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v7, [ - {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord34Array|CsvConversionError v8 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord34Array|CsvConversionError v8 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v8, [ - {'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: "1", '2: "string2", '3: false, '4: 0, '5: "0", '6: "null"}, {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: "1.23", '6: "()"}, @@ -80,271 +357,342 @@ function testCustomHeaders() { {'1: "1", '2: "string5", '3: true, '4: 3, '5: "3", '6: "()"} ]); - CustomRecord35Array|CsvConversionError v9 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord35Array|CsvConversionError v9 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v9, [ - {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f", '9: ""}, {'1: "1", '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: "()", '9: ""}, {'1: "1", '2: "string2", '3: false, '4: 0, '5: 0, '6: "null", '9: ""}, {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: "()", '9: ""}, {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: "()", '9: ""}, {'1: "1", '2: "string5", '3: true, '4: 3, '5: 3, '6: "()", '9: ""} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord36Array|CsvConversionError v10 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord36Array|CsvConversionError v10 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v10, [ - {'1: "a", '6: "f", '9: ""}, {'1: "1", '6: "()", '9: ""}, {'1: "1", '6: "null", '9: ""}, {'1: "1", '6: "()", '9: ""}, {'1: "1", '6: "()", '9: ""}, {'1: "1", '6: "()", '9: ""} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord37Array|CsvConversionError v11 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord37Array|CsvConversionError v11 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v11, [ - {'1: "a", '5: "e", '6: "f"}, {'1: "1", '5: "2.234", '6: "()"}, {'1: "1", '5: "0", '6: "null"}, {'1: "1", '5: "1.23", '6: "()"}, {'1: "1", '5: "-6.51", '6: "()"}, {'1: "1", '5: "3", '6: "()"} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord38Array|CsvConversionError v12 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord38Array|CsvConversionError v12 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v12, [ - {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord39Array|CsvConversionError v13 = fromCsvStringWithType(csvStringData1, config21); + CustomRecord39Array|CsvConversionError v13 = fromCsvStringWithType(csvStringData1, config); test:assertEquals(v13, [ - {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord40Array|CsvConversionError v14 = fromCsvStringWithType(csvStringData3, config21); + CustomRecord40Array|CsvConversionError v14 = fromCsvStringWithType(csvStringData3, config); test:assertEquals(v14, [ - {'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: 1, '2: "string2", '3: false, '4: 0, '5: "0", '6: "null"}, {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: "1.23", '6: "()"}, {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: "-6.51", '6: "()"}, {'1: 1, '2: "string5", '3: true, '4: 3, '5: "3", '6: "()"} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord41Array|CsvConversionError v15 = fromCsvStringWithType(csvStringData2, config21); + CustomRecord41Array|CsvConversionError v15 = fromCsvStringWithType(csvStringData2, config); test:assertEquals(v15, [ - {'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: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord42Array|CsvConversionError v16 = fromCsvStringWithType(csvStringData6, config21); + CustomRecord42Array|CsvConversionError v16 = fromCsvStringWithType(csvStringData6, config); test:assertEquals(v16, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord43Array|CsvConversionError v17 = fromCsvStringWithType(csvStringData6, config21); + CustomRecord43Array|CsvConversionError v17 = fromCsvStringWithType(csvStringData6, config); test:assertEquals(v17, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord44Array|CsvConversionError v18 = fromCsvStringWithType(csvStringData6, config21); + CustomRecord44Array|CsvConversionError v18 = fromCsvStringWithType(csvStringData6, config); test:assertEquals(v18, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} - ]); + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord45Array|CsvConversionError v19 = fromCsvStringWithType(csvStringData6, config21); - test:assertTrue(v19 is CsvConversionError); - test:assertEquals((v19).message(), generateErrorMessageForMissingRequiredField("H1")); + CustomRecord45Array|CsvConversionError v19 = fromCsvStringWithType(csvStringData6, config); + test:assertTrue(v19 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v19).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - CustomRecord46Array|CsvConversionError v19_2 = fromCsvStringWithType(csvStringData6, config21); - test:assertTrue(v19_2 is CsvConversionError); - test:assertEquals((v19_2).message(), generateErrorMessageForMissingRequiredField("H1")); + CustomRecord46Array|CsvConversionError v19_2 = fromCsvStringWithType(csvStringData6, config); + test:assertTrue(v19_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v19_2).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - CustomRecord47Array|CsvConversionError v19_3 = fromCsvStringWithType(csvStringData6, config21); - test:assertTrue(v19_3 is CsvConversionError); - test:assertEquals((v19_3).message(), generateErrorMessageForMissingRequiredField("H1")); + CustomRecord47Array|CsvConversionError v19_3 = fromCsvStringWithType(csvStringData6, config); + test:assertTrue(v19_3 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v19_3).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - CustomRecord56Array|CsvConversionError v19_4 = fromCsvStringWithType(csvStringData1, config21); - test:assertEquals(v19_4, [ - {H1: "", H4: "", '1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, + CustomRecord49Array|CsvConversionError v19_4 = fromCsvStringWithType(csvStringData6, config); + test:assertTrue(v19_4 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v19_4).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord56Array|CsvConversionError v19_5 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v19_5, [ {H1: "", H4: "", '1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, {H1: "", H4: "", '1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, {H1: "", H4: "", '1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, {H1: "", H4: "", '1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, {H1: "", H4: "", '1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); + ], string `Test failed for config ${config.toBalString()}`); - // custom header config parameter + record {string H1 = ""; string H4 = ""; int '2 = 10;}[]|CsvConversionError v30_2 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v30_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v30_2).message(), generateErrorMessageForInvalidCast("string1", "int"), string `Test failed for config ${config.toBalString()}`); - CustomRecord46Array|CsvConversionError v20 = fromCsvStringWithType(csvStringData6, config22); - test:assertEquals(v20, [ - {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ]); + CustomRecord53Array|CsvConversionError v28 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v28 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v28).message(), generateErrorMessageForMissingRequiredField("H4"), string `Test failed for config ${config.toBalString()}`); - CustomRecord46Array|CsvConversionError v20_2 = fromCsvStringWithType(csvStringData6, config22); - test:assertEquals(v20_2, [ - {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ]); + CustomRecord53Array|CsvConversionError v28_2 = fromCsvStringWithType(csvStringData6, config); + test:assertTrue(v28_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v28_2).message(), generateErrorMessageForMissingRequiredField("H4"), string `Test failed for config ${config.toBalString()}`); +} - CustomRecord47Array|CsvConversionError v21 = fromCsvStringWithType(csvStringData6, config22); - test:assertEquals(v21, [ - {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ]); +function testHeaderConfigWithFalseValue(FromCSVConfig config = config21) { + record {}[]|CsvConversionError v1 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v1, [ + {'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: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, + {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord48Array|CsvConversionError v22 = fromCsvStringWithType(csvStringData6, config22); - test:assertEquals(v22, [ - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ]); + CustomRecord28Array|CsvConversionError v2 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v2, [ + {'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: "1", '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, + {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, + {'1: "1", '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ], string `Test failed for config ${config.toBalString()}`); + - CustomRecord48Array|CsvConversionError v22_2 = fromCsvStringWithType(csvStringData1, config22); - test:assertEquals(v22_2, [ - {H1: "a", H2: "b", H3: "c", H4: "d", H5: "e", H6: "f"}, - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ]); + CustomRecord29Array|CsvConversionError v3 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v3 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v3).message(), generateErrorMessageForInvalidCast("a", "int"), string `Test failed for config ${config.toBalString()}`); - CustomRecord49Array|CsvConversionError v23 = fromCsvStringWithType(csvStringData6, config22); - test:assertEquals(v23, [ - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ]); + CustomRecord30Array|CsvConversionError v4 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v4, [ + {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, + {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, + {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, + {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord50Array|CsvConversionError v24 = fromCsvStringWithType(csvStringData6, config22); - test:assertEquals(v24, [ - {H1: 1, H4: 2.234, H2: "string1", H3: true, H5: 2.234, H6: ()}, - {H1: 1, H4: 0.0, H2: "string2", H3: false, H5: 0, H6: null}, - {H1: 1, H4: 1.23, H2: "string3", H3: 0, H5: 1.23, H6: ()}, - {H1: 1, H4: -6.51, H2: "string4", H3: 1, H5: -6.51, H6: ()}, - {H1: 1, H4: 3.0, H2: "string5", H3: true, H5: 3, H6: ()} - ]); + CustomRecord31Array|CsvConversionError v5 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v5, [ + {'1: "a", '6: "f"}, + {'1: "1", '6: "()"}, + {'1: "1", '6: "null"}, + {'1: "1", '6: "()"}, + {'1: "1", '6: "()"}, + {'1: "1", '6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord32Array|CsvConversionError v6 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v6 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v6).message(), generateErrorMessageForInvalidCast("a", "int"), string `Test failed for config ${config.toBalString()}`); - CustomRecord50Array|CsvConversionError v24_2 = fromCsvStringWithType(csvStringData1, config22); - test:assertTrue(v24_2 is CsvConversionError); - test:assertEquals((v24_2).message(), generateErrorMessageForInvalidCast("a", "int")); + CustomRecord33Array|CsvConversionError v7 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v7, [ + {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, + {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, + {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, + {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord51Array|CsvConversionError v25 = fromCsvStringWithType(csvStringData6, config22); - test:assertEquals(v25, [ - {H1: 1, H4: 2.234}, - {H1: 1, H4: 0.0}, - {H1: 1, H4: 1.23}, - {H1: 1, H4: -6.51}, - {H1: 1, H4: 3.0} + CustomRecord34Array|CsvConversionError v8 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v8, [ + {'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: "1", '2: "string2", '3: false, '4: 0, '5: "0", '6: "null"}, + {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: "1.23", '6: "()"}, + {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: "-6.51", '6: "()"}, + {'1: "1", '2: "string5", '3: true, '4: 3, '5: "3", '6: "()"} ]); - CustomRecord52Array|CsvConversionError v26 = fromCsvStringWithType(csvStringData6, config22); - test:assertEquals(v26, [ - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ]); + CustomRecord35Array|CsvConversionError v9 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v9, [ + {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f", '9: ""}, + {'1: "1", '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: "()", '9: ""}, + {'1: "1", '2: "string2", '3: false, '4: 0, '5: 0, '6: "null", '9: ""}, + {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: "()", '9: ""}, + {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: "()", '9: ""}, + {'1: "1", '2: "string5", '3: true, '4: 3, '5: 3, '6: "()", '9: ""} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord52Array|CsvConversionError v26_2 = fromCsvStringWithType(csvStringData1, config22); - test:assertEquals(v26_2, [ - {H1: "a", H2: "b", H3: "c", H4: "d", H5: "e", H6: "f"}, - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ]); + CustomRecord36Array|CsvConversionError v10 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v10, [ + {'1: "a", '6: "f", '9: ""}, + {'1: "1", '6: "()", '9: ""}, + {'1: "1", '6: "null", '9: ""}, + {'1: "1", '6: "()", '9: ""}, + {'1: "1", '6: "()", '9: ""}, + {'1: "1", '6: "()", '9: ""} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord53Array|CsvConversionError v27 = fromCsvStringWithType(csvStringData6, config22); - test:assertEquals(v27, [ - {H1: 1, H4: 2.234, "H5": 2.234}, - {H1: 1, H4: 0.0, "H5": 0}, - {H1: 1, H4: 1.23, "H3": 0, "H5": 1.23}, - {H1: 1, H4: -6.51, "H3": 1, "H5": -6.51}, - {H1: 1, H4: 3.0, "H5": 3} - ]); + CustomRecord37Array|CsvConversionError v11 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v11, [ + {'1: "a", '5: "e", '6: "f"}, + {'1: "1", '5: "2.234", '6: "()"}, + {'1: "1", '5: "0", '6: "null"}, + {'1: "1", '5: "1.23", '6: "()"}, + {'1: "1", '5: "-6.51", '6: "()"}, + {'1: "1", '5: "3", '6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord38Array|CsvConversionError v12 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v12, [ + {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, + {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, + {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, + {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord39Array|CsvConversionError v13 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v13, [ + {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, + {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, + {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, + {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord53Array|CsvConversionError v27_2 = fromCsvStringWithType(csvStringData1, config22); - test:assertTrue(v27_2 is CsvConversionError); - test:assertEquals((v27_2).message(), generateErrorMessageForInvalidCast("a", "int")); + CustomRecord40Array|CsvConversionError v14 = fromCsvStringWithType(csvStringData3, config); + test:assertEquals(v14, [ + {'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: 1, '2: "string2", '3: false, '4: 0, '5: "0", '6: "null"}, + {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: "1.23", '6: "()"}, + {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: "-6.51", '6: "()"}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: "3", '6: "()"} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord53Array|CsvConversionError v28 = fromCsvStringWithType(csvStringData1, config21); - test:assertTrue(v28 is CsvConversionError); - test:assertEquals((v28).message(), generateErrorMessageForMissingRequiredField("H4")); + CustomRecord41Array|CsvConversionError v15 = fromCsvStringWithType(csvStringData2, config); + test:assertEquals(v15, [ + {'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: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, + {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord53Array|CsvConversionError v28_2 = fromCsvStringWithType(csvStringData6, config21); - test:assertTrue(v28_2 is CsvConversionError); - test:assertEquals((v28_2).message(), generateErrorMessageForMissingRequiredField("H4")); + CustomRecord42Array|CsvConversionError v16 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v16, [ + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, + {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord54Array|CsvConversionError v29 = fromCsvStringWithType(csvStringData1, config22); - test:assertTrue(v29 is CsvConversionError); - test:assertEquals((v29).message(), generateErrorMessageForMissingRequiredField("1")); + CustomRecord43Array|CsvConversionError v17 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v17, [ + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, + {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord54Array|CsvConversionError v29_2 = fromCsvStringWithType(csvStringData1, config22); - test:assertTrue(v29_2 is CsvConversionError); - test:assertEquals((v29_2).message(), generateErrorMessageForMissingRequiredField("1")); + CustomRecord44Array|CsvConversionError v18 = fromCsvStringWithType(csvStringData6, config); + test:assertEquals(v18, [ + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, + {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} + ], string `Test failed for config ${config.toBalString()}`); - CustomRecord55Array|CsvConversionError v30 = fromCsvStringWithType(csvStringData6, config22); - test:assertEquals(v30, [ - {H1: "1", H4: "2.234",'1: 10}, - {H1: "1", H4: "0", '1: 10}, - {H1: "1", H4: "1.23", '1: 10}, - {H1: "1", H4: "-6.51", '1: 10}, - {H1: "1", H4: "3", '1: 10} - ]); + CustomRecord45Array|CsvConversionError v19 = fromCsvStringWithType(csvStringData6, config); + test:assertTrue(v19 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v19).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord46Array|CsvConversionError v19_2 = fromCsvStringWithType(csvStringData6, config); + test:assertTrue(v19_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v19_2).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord47Array|CsvConversionError v19_3 = fromCsvStringWithType(csvStringData6, config); + test:assertTrue(v19_3 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v19_3).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord49Array|CsvConversionError v19_4 = fromCsvStringWithType(csvStringData6, config); + test:assertTrue(v19_4 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v19_4).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord56Array|CsvConversionError v19_5 = fromCsvStringWithType(csvStringData1, config); + test:assertEquals(v19_5, [ + {H1: "", H4: "", '1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, + {H1: "", H4: "", '1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {H1: "", H4: "", '1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, + {H1: "", H4: "", '1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, + {H1: "", H4: "", '1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, + {H1: "", H4: "", '1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ], string `Test failed for config ${config.toBalString()}`); + + CustomRecord55Array|CsvConversionError v30_2 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v30_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v30_2).message(), generateErrorMessageForInvalidCast("a", "int"), string `Test failed for config ${config.toBalString()}`); + + CustomRecord53Array|CsvConversionError v28 = fromCsvStringWithType(csvStringData1, config); + test:assertTrue(v28 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v28).message(), generateErrorMessageForMissingRequiredField("H4"), string `Test failed for config ${config.toBalString()}`); - CustomRecord55Array|CsvConversionError v30_2 = fromCsvStringWithType(csvStringData1, config21); - test:assertTrue(v30_2 is CsvConversionError); - test:assertEquals((v30_2).message(), generateErrorMessageForInvalidCast("a", "int")); + CustomRecord53Array|CsvConversionError v28_2 = fromCsvStringWithType(csvStringData6, config); + test:assertTrue(v28_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); + test:assertEquals((v28_2).message(), generateErrorMessageForMissingRequiredField("H4"), string `Test failed for config ${config.toBalString()}`); } boolean enable = true; @test:Config{enable: !enable} function test() { - CustomRecord46Array|CsvConversionError v20 = fromCsvStringWithType(csvStringData6, config22); + CustomRecord46Array|CsvConversionError v20 = fromCsvStringWithType(csvStringData6, config23); test:assertEquals(v20, [ {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java index 2234c76..73c7d87 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java @@ -2,6 +2,8 @@ import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import java.util.ArrayList; @@ -44,6 +46,25 @@ private CsvConfig(boolean headers, char escapeCharacter, boolean ignoreEmptyLine this.suppressEscaping = suppressEscaping; this.nullValue = nullValue; this.lineSeparator = lineSeparator; + updateDependentConfigurations(); + } + + private void updateDependentConfigurations() { + if (!this.headers) { + this.skipHeaders = false; + } + if (this.startNumber > this.headerStartNumber) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, + "startNumber parameter cannot be greater than headerStartNumber parameter"); + } + if (this.headerStartNumber > this.dataStartNumber) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, + "headerStartNumber parameter cannot be greater than dataStartNumber parameter"); + } + if (this.startNumber > this.dataStartNumber) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, + "startNumber parameter cannot be greater than dataStartNumber parameter"); + } } private CsvConfig(long startNumber, long headerStartNumber, long dataStartNumber, @@ -68,6 +89,7 @@ private CsvConfig(long startNumber, long headerStartNumber, long dataStartNumber this.suppressEscaping = suppressEscaping; this.nullValue = nullValue; this.root = root; + updateDependentConfigurations(); } public CsvConfig() { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 35ebe5f..2e6512d 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -32,6 +32,9 @@ import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import java.util.Map; /** @@ -92,7 +95,7 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, } public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { - if (sm.config.skipHeaders || !sm.config.headers) { + if (sm.config.customHeader == null && (sm.config.skipHeaders || !sm.config.headers)) { String header = String.valueOf(sm.columnIndex + 1); Map fieldHierarchy = sm.fieldHierarchy; if (fieldHierarchy.containsKey(header)) { @@ -103,6 +106,44 @@ public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { return sm.headers.get(sm.columnIndex); } + public static void updateHeaders(CsvParser.StateMachine sm) { + List updatedHeaders = Arrays.asList( + QueryParser.parse(sm.config.skipColumns, sm.headers.toArray(new String[]{}))); + generateSkipColumnIndexes(updatedHeaders, sm); + } + + public static void generateSkipColumnIndexes(List updatedHeaders, CsvParser.StateMachine sm) { + String header; + ArrayList copyOfHeaders = new ArrayList<>(); + for (int i = 0; i < sm.headers.size(); i++) { + header = sm.headers.get(i); + if (!updatedHeaders.contains(header)) { + sm.skipColumnIndexes.add(i); + continue; + } + copyOfHeaders.add(header); + } + sm.headers = copyOfHeaders; + } + + public static void checkAndAddCustomHeaders(CsvParser.StateMachine sm, Object customHeader) { + if (customHeader == null) { + return; + } + + BArray customHeaders = (BArray) customHeader; + for (int i = 0; i < customHeaders.size(); i++) { + String header = StringUtils.getStringValue(customHeaders.get(i)); + Map fieldHierarchy = sm.fieldHierarchy; + sm.headers.add(header); + if (fieldHierarchy.containsKey(header)) { + Field field = fieldHierarchy.get(header); + sm.fieldNames.put(header, field); + fieldHierarchy.remove(header); + } + } + } + private static boolean ignoreIncompatibilityErrorsForMaps(CsvParser.StateMachine sm, Type type, Type exptype) { if (exptype.getTag() == TypeTags.RECORD_TYPE_TAG) { String header = getHeaderValueForColumnIndex(sm); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 36e8af7..984db59 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -33,6 +33,8 @@ import java.io.Reader; import java.util.*; +import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.checkAndAddCustomHeaders; +import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.updateHeaders; import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.*; /** @@ -186,6 +188,10 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError if (config.headers) { currentState = HEADER_START_STATE; } else { + if (config.customHeader != null) { + checkAndAddCustomHeaders(this, config.customHeader); + updateHeaders(this); + } currentState = ROW_START_STATE; addFieldNamesForNonHeaderState(); } @@ -255,26 +261,32 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C char separator = sm.config.separator; boolean skipHeaders = sm.config.skipHeaders; Object customHeader = sm.config.customHeader; + boolean headerStart = false; for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); - + if (!(isWhitespace(ch) && sm.isNewLineOrEof(ch))) { + headerStart = true; + } if (ignoreHeader(sm)) { sm.lineNumber++; continue; } if (customHeader != null) { - if (isEndOfTheRow(sm, ch, true)) { + if (headerStart && sm.isNewLineOrEof(ch)) { checkAndAddCustomHeaders(sm, customHeader); sm.lineNumber++; + updateHeaders(sm); state = HEADER_END_STATE; break; } continue; } if (skipHeaders) { - if (isEndOfTheRow(sm, ch, true)) { + if (headerStart && sm.isNewLineOrEof(ch)) { sm.lineNumber++; + sm.addFieldNamesForNonHeaderState(); + updateHeaders(sm); state = HEADER_END_STATE; break; } @@ -290,6 +302,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C finalizeHeaders(sm); sm.columnIndex = 0; sm.lineNumber++; + updateHeaders(sm); state = HEADER_END_STATE; } else if (StateMachine.isWhitespace(ch)) { state = this; @@ -305,24 +318,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return state; } - private void checkAndAddCustomHeaders(StateMachine sm, Object customHeader) { - if (customHeader == null) { - return; - } - - BArray customHeaders = (BArray) customHeader; - for (int i = 0; i < customHeaders.size(); i++) { - String header = StringUtils.getStringValue(customHeaders.get(i)); - Map fieldHierarchy = sm.fieldHierarchy; - sm.headers.add(header); - if (fieldHierarchy.containsKey(header)) { - Field field = fieldHierarchy.get(header); - sm.fieldNames.put(header, field); - fieldHierarchy.remove(header); - } - } - } - private void finalizeHeaders(StateMachine sm) throws CsvParserException { Type expType = sm.expectedArrayElementType; if (expType instanceof RecordType) { @@ -393,7 +388,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C char ch; State state = ROW_START_STATE; char separator = sm.config.separator; - updateHeaders(sm); // TODO: Ignore this in future for (; i < count; i++) { @@ -436,29 +430,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return state; } - private void updateHeaders(StateMachine sm) { - if (!sm.config.headers || sm.config.skipHeaders) { - return; - } - List updatedHeaders = Arrays.asList( - QueryParser.parse(sm.config.skipColumns, sm.headers.toArray(new String[]{}))); - generateSkipColumnIndexes(updatedHeaders, sm); - } - - private void generateSkipColumnIndexes(List updatedHeaders, StateMachine sm) { - String header; - ArrayList copyOfHeaders = new ArrayList<>(); - for (int i = 0; i < sm.headers.size(); i++) { - header = sm.headers.get(i); - if (!updatedHeaders.contains(header)) { - sm.skipColumnIndexes.add(i); - continue; - } - copyOfHeaders.add(header); - } - sm.headers = copyOfHeaders; - } - private void handleCsvRow(StateMachine sm) throws CsvParserException { if (ignoreRow(sm)) { sm.clear(); @@ -706,11 +677,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } public static boolean isEndOfTheRow(CsvParser.StateMachine sm, char ch) { - return isEndOfTheRow(sm, ch, false); - } - - public static boolean isEndOfTheRow(CsvParser.StateMachine sm, char ch, boolean hasHeaderSkipConfig) { - return (ch == EOF || hasHeaderSkipConfig || !sm.peek().isEmpty()) && sm.isNewLineOrEof(ch); + return (ch == EOF || !sm.peek().isEmpty()) && sm.isNewLineOrEof(ch); } public static class CsvParserException extends Exception { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index c4632c5..a816cbb 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -39,7 +39,8 @@ public enum DiagnosticErrorCode { INVALID_TYPE_FOR_FIELD("BDE_0012", "invalid.type.for.field"), INVALID_TYPE_FOR_ARRAY("BDE_0013", "invalid.type.for.array"), INVALID_CONVERSION_FOR_ARRAY_TO_MAP("BDE_0014", "invalid.conversion.for.array.to.map"), - EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES("BDE_0015", "expected.type.can.only.contains.basic.types"); + INVALID_CONFIGURATIONS( "BDE_0015", "invalid.configurations"), + EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES("BDE_0016", "expected.type.can.only.contains.basic.types"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index 99b3503..50d77f3 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -64,4 +64,7 @@ error.expected.type.can.only.contains.basic.types=\ error.invalid.conversion.for.array.to.map=\ value ''{0}'' cannot be cast into ''{1}'', because fields in ''{1}'' or the provided \ - expected headers are not matching with the ''{0}'' \ No newline at end of file + expected headers are not matching with the ''{0}'' + +error.invalid.configurations=\ + invalid configurations: ''{0}'' \ No newline at end of file From b1284ed4ffe2807f730ad7ee785162bbf1e9fc36 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 29 Mar 2024 11:20:01 +0530 Subject: [PATCH 023/147] Update user configs --- ballerina/Dependencies.toml | 2 +- ballerina/tests/test_data_values.bal | 2 +- .../test_from_csv_with_user_configs.bal.bal | 20 ++++++++++++++++++- ballerina/tests/test_user_config_values.bal | 6 ++++-- .../stdlib/data/csvdata/csv/CsvConfig.java | 14 ++++++++++++- 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index dff49a8..f95f329 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.4" +distribution-version = "2201.8.6" [[package]] org = "ballerina" diff --git a/ballerina/tests/test_data_values.bal b/ballerina/tests/test_data_values.bal index b3c8e3c..769dabe 100644 --- a/ballerina/tests/test_data_values.bal +++ b/ballerina/tests/test_data_values.bal @@ -229,7 +229,7 @@ string csvStringData6 = string ` 1, string3, 0, 1.23, 1.23, () 1, string4, 1, -6.51, -6.51, () - + 1, string5, true, 3, 3, ()`; string csvStringData7 = string ` diff --git a/ballerina/tests/test_from_csv_with_user_configs.bal.bal b/ballerina/tests/test_from_csv_with_user_configs.bal.bal index 6402fc2..ca71a87 100644 --- a/ballerina/tests/test_from_csv_with_user_configs.bal.bal +++ b/ballerina/tests/test_from_csv_with_user_configs.bal.bal @@ -2,7 +2,25 @@ import ballerina/test; @test:Config{enable} function testStartNumbers() { - + record{}[]|CsvConversionError v1 = fromCsvStringWithType(csvStringData1, config1); + if v1 is record{}[] { + test:assertEquals((v1).length(), 5); + } + test:assertEquals(v1, [ + {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, + {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, + {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, + {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + record{}[]|CsvConversionError v2 = fromCsvStringWithType(csvStringData1, config2); + test:assertEquals(v2, [ + {a: 1, b: "string2", c: false, d: 0, e: 0, f: null}, + {a: 1, b: "string3", c: 0, d: 1.23, e: 1.23, f: ()}, + {a: 1, b: "string4", c: 1, d: -6.51, e: -6.51, f: ()}, + {a: 1, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); } @test:Config{enable} diff --git a/ballerina/tests/test_user_config_values.bal b/ballerina/tests/test_user_config_values.bal index 6d05873..730707e 100644 --- a/ballerina/tests/test_user_config_values.bal +++ b/ballerina/tests/test_user_config_values.bal @@ -1,9 +1,11 @@ FromCSVConfig config1 = { - startNumber: 1 + startNumber: 1, + skipHeaders: true }; FromCSVConfig config2 = { - startNumber: 2 + startNumber: 2, + skipHeaders: true }; FromCSVConfig config3 = { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java index 73c7d87..3d4b199 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java @@ -53,7 +53,19 @@ private void updateDependentConfigurations() { if (!this.headers) { this.skipHeaders = false; } - if (this.startNumber > this.headerStartNumber) { + if (this.startNumber < 0) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, + "startNumber parameter cannot be lower than 0"); + } + if (!this.skipHeaders && this.headerStartNumber < 0) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, + "headerStartNumber parameter cannot be lower than 0"); + } + if (this.startNumber < 0) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, + "dataStartNumber parameter cannot be lower than 0"); + } + if (!this.skipHeaders && this.startNumber > this.headerStartNumber) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, "startNumber parameter cannot be greater than headerStartNumber parameter"); } From f89691cb9f40fe1a2f3c722406ebc059309d77b8 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 13 May 2024 10:58:35 +0530 Subject: [PATCH 024/147] Add test files for basic functionality --- ballerina/Ballerina.toml | 2 +- ballerina/csv_api.bal | 112 +- ballerina/tests/consider | 33 - ..._csv_string_with_type_with_string_test.bal | 1854 ------------- ballerina/tests/from_csv_with_type_test.bal | 2297 ----------------- ballerina/tests/note | 1 - .../tests/parse_list_type_as_list_test.bal | 330 +++ .../tests/parse_list_type_as_record_test.bal | 653 +++++ .../tests/parse_record_type_as_list_test.bal | 540 ++++ .../parse_record_type_as_record_test.bal | 733 ++++++ .../tests/parse_string_compatibality_test.bal | 208 ++ .../tests/parse_string_to_array_test.bal | 314 +++ .../tests/parse_string_to_map_tests copy.bal | 409 +++ .../tests/parse_string_to_record_tests.bal | 496 ++++ .../tests/parse_string_to_tuple_test.bal | 474 ++++ .../tests/parse_type_compatibility_test.bal | 112 + ballerina/tests/test.bal | 350 --- .../test_from_csv_with_user_configs.bal.bal | 721 ------ ballerina/tests/test_user_config_values.bal | 410 --- ballerina/types.bal | 51 + build-config/resources/Ballerina.toml | 2 +- gradle.properties | 2 +- .../stdlib/data/csvdata/FromString.java | 9 +- .../stdlib/data/csvdata/csv/CsvConfig.java | 135 - .../stdlib/data/csvdata/csv/CsvCreator.java | 23 +- .../stdlib/data/csvdata/csv/CsvParser.java | 92 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 27 +- .../stdlib/data/csvdata/csv/Native.java | 138 +- .../stdlib/data/csvdata/csv/QueryParser.java | 115 - .../data/csvdata/io/DataReaderTask.java | 2 +- .../stdlib/data/csvdata/utils/Constants.java | 42 +- .../stdlib/data/csvdata/utils/CsvConfig.java | 154 ++ .../stdlib/data/csvdata/utils/CsvUtils.java | 113 +- .../csvdata/utils/DiagnosticErrorCode.java | 5 +- native/src/main/java/module-info.java | 1 + native/src/main/resources/error.properties | 9 +- 36 files changed, 4730 insertions(+), 6239 deletions(-) delete mode 100644 ballerina/tests/consider delete mode 100644 ballerina/tests/from_csv_string_with_type_with_string_test.bal delete mode 100644 ballerina/tests/from_csv_with_type_test.bal delete mode 100644 ballerina/tests/note create mode 100644 ballerina/tests/parse_list_type_as_list_test.bal create mode 100644 ballerina/tests/parse_list_type_as_record_test.bal create mode 100644 ballerina/tests/parse_record_type_as_list_test.bal create mode 100644 ballerina/tests/parse_record_type_as_record_test.bal create mode 100644 ballerina/tests/parse_string_compatibality_test.bal create mode 100644 ballerina/tests/parse_string_to_array_test.bal create mode 100644 ballerina/tests/parse_string_to_map_tests copy.bal create mode 100644 ballerina/tests/parse_string_to_record_tests.bal create mode 100644 ballerina/tests/parse_string_to_tuple_test.bal create mode 100644 ballerina/tests/parse_type_compatibility_test.bal delete mode 100644 ballerina/tests/test.bal delete mode 100644 ballerina/tests/test_from_csv_with_user_configs.bal.bal delete mode 100644 ballerina/tests/test_user_config_values.bal create mode 100644 ballerina/types.bal delete mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java delete mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index f53bd7a..ecae9dc 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -6,7 +6,7 @@ authors = ["Ballerina"] keywords = ["csv"] repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" license = ["Apache-2.0"] -distribution = "2201.8.1" +distribution = "2201.9.0" export = ["data.csv"] [platform.java17] diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index e40e840..fb526cb 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -16,101 +16,41 @@ import ballerina/jballerina.java; -type CsvConversionError error; -type UnSupportedOperation error; -public enum OrderType { - ASC, - DESC -}; +public isolated function parseStringToRecord(string s, parseToRecordOption options = {}, typedesc t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public type ColumnOrder record {| - int|string column; - OrderType columnOrder = ASC; -|}; +public isolated function parseBytesToRecord(byte[] s, parseToRecordOption options = {}, typedesc t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public type MappingConfig record {| - string keyValueSeparator = ":"; - string elementSeparator = ";"; -|}; +public isolated function parseStreamToRecord(stream s, + parseToRecordOption options = {}, typedesc t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public type FromCSVConfig record {| - int startNumber = 0; // done - int headerStartNumber = 0; // done - int dataStartNumber = 1; // done - boolean headers = true; // done - string:Char escapeCharacter = "\\"; - boolean ignoreEmptyLines = true; // done - string:Char separator = ","; // done - string quote = "\""; - boolean skipHeaders = false; // done - int skipdataRows = 0; // done - int dataRowCount = -1; // done - ColumnOrder|ColumnOrder[]? orderBy = (); // done - string|int|string[]|int[]? skipColumns = (); - string[]|int[]? customheader = (); // done - boolean suppressEscaping = false; - // MappingConfig mappingConfig = {}; - anydata nullValue = (); // done -|}; +public isolated function parseStringToList(string s, ParseOption options = {}, typedesc t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public type ToCSVConfig record {| - string[]? headers = (); - string:Char separator = ","; - string:Char lineSeparator = "\n"; - boolean skipHeaders = false; - int skipdataRows = 0; - int dataRowCount = -1; - ColumnOrder|ColumnOrder[] orderBy = []; - string|int|string[]|int[]? skipColumns = (); - boolean suppressEscaping = false; - anydata nullValue = (); - string:Char escapeCharacter = "\\"; -|}; +public isolated function parseBytesToList(byte[] s, ParseOption options = {}, typedesc t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public isolated function fromCsvWithType((string[]|map)[] csv, FromCSVConfig config = {}, typedesc<(record{}|map|anydata[])[]> t = <>) - returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; +public isolated function parseStreamToList(stream s, + ParseOption options = {}, typedesc t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public isolated function fromCsvStringWithType(string|byte[]|stream s, - FromCSVConfig config = {} ,typedesc<(map|anydata)[]> t = <>) - returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; +public isolated function parseRecordAsRecordType(record{}[] s, + ToRecordOptions options = {}, typedesc t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public isolated function toCsv((anydata[]|map)[] csv, ToCSVConfig config = {}, typedesc<(record{}|map|anydata[])[]> t = <>) - returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; +public isolated function parseRecordAsListType(record{}[] s, string[] customHeaders, + Options options = {}, typedesc t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public isolated function toCsvString((anydata[]|map)[] csv, ToCSVConfig config = {}) returns string|UnSupportedOperation { - string csvString = ""; - foreach anydata[]|map row in csv { - if row is anydata[] { - foreach anydata cell in row { - csvString += check convertToString(cell) + config.separator; - } - csvString = removeLastIndex(csvString); - csvString += config.lineSeparator; - continue; - } +public isolated function parseListAsRecordType(string[][] s, string[]? customHeaders = (), + Options options = {}, typedesc t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; - // issue: https://github.com/ballerina-platform/ballerina-lang/issues/42172 - foreach string cell in (row).keys() { - csvString += check convertToString(row[cell]) + config.separator; - } +public isolated function parseListAsListType(string[][] s, Options options = {}, typedesc t = <>) + returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; - csvString = removeLastIndex(csvString); - csvString += config.lineSeparator; - } +// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - csvString = removeLastIndex(csvString); - return csvString; -} - -isolated function removeLastIndex(string content) returns string { - return content.substring(0, content.length() - 1); -} - -isolated function convertToString(anydata cell) returns string|UnSupportedOperation { - if cell is int|string|boolean|float|decimal|() { - return cell.toBalString(); - } else { - return error UnSupportedOperation(string `unsupported opration`); - } -} diff --git a/ballerina/tests/consider b/ballerina/tests/consider deleted file mode 100644 index 0acdd36..0000000 --- a/ballerina/tests/consider +++ /dev/null @@ -1,33 +0,0 @@ -array size wenas, oter, inner, both -AA -> QQ -unions -. inp and output -empty csv, csv with only headers -null values in both data and headers -table -record { - int|string -} kind of tests - -int can be unsigned32 as well, in that case in the java siode we need to check, isNumber and is not Decimal -skip data rows and datarow count large small equal default scenarios - -startNumber > dataStartNumber -skip columns query, nested queries -target ttype should be compatible if the skip is happen or not - - -LESS TESTS FOR UNIONS AND NULLABLE< CHECK THE ERROR MESSAGES IN V1. - -A CSV header that not in record and vice versa -Add tests by changing the type, string to int int to string like that - -map record field with default values (match fields with default ) - - -without defining types. - -need a combination for mix types. string field to int. boolean field for null like that - -missing field error message, field is random - -unsigned 32 \ No newline at end of file diff --git a/ballerina/tests/from_csv_string_with_type_with_string_test.bal b/ballerina/tests/from_csv_string_with_type_with_string_test.bal deleted file mode 100644 index a243583..0000000 --- a/ballerina/tests/from_csv_string_with_type_with_string_test.bal +++ /dev/null @@ -1,1854 +0,0 @@ -import ballerina/test; - -@test:Config {enable} -function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { - BooleanRecord1Array|CsvConversionError csvb1br1 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - 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|CsvConversionError csvb2br1 = fromCsvStringWithType(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|CsvConversionError csvb3br1 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); - test:assertTrue(csvb3br1 is CsvConversionError); - test:assertEquals((csvb3br1).message(), generateErrorMessageForMissingRequiredField("b4")); - - BooleanRecord1Array|CsvConversionError csvb4br1 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br1, [ - {b1: true, b2: "()", b3: (), b4: false}, - {b1: true, b2: "()", b3: (), b4: false} - ]); - - BooleanRecord1Array|CsvConversionError csvb5br1 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); - test:assertTrue(csvb5br1 is CsvConversionError); - test:assertEquals((csvb5br1).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanRecord1Array|CsvConversionError csvb6br1 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br1 is CsvConversionError); - test:assertEquals((csvb6br1).message(), generateErrorMessageForMissingRequiredField("b4")); - - BooleanRecord1Array|CsvConversionError csvb7br1 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br1, [ - {b1, b2, b3: (), b4} - ]); - - BooleanRecord2Array|CsvConversionError csvb1br2 = fromCsvStringWithType(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|CsvConversionError csvb2br2 = fromCsvStringWithType(csvStringWithBooleanValues2, {}); - test:assertEquals(csvb2br2, [ - {b1: true, b2: false, b3: true, b4: false}, - {b1: true, b2: false, b3: true, b4: false} - ]); - - BooleanRecord2Array|CsvConversionError csvb3br2 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); - test:assertTrue(csvb3br2 is CsvConversionError); - test:assertEquals((csvb3br2).message(), generateErrorMessageForMissingRequiredField("b4")); - - BooleanRecord2Array|CsvConversionError csvb4br2 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br2, [ - {b1: true, b2: "()", b3: (), b4: false}, - {b1: true, b2: "()", b3: (), b4: false} - ]); - - BooleanRecord2Array|CsvConversionError csvb5br2 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); - test:assertTrue(csvb5br2 is CsvConversionError); - test:assertEquals((csvb5br2).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanRecord2Array|CsvConversionError csvb7br2 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br2, [ - {b1, b2, b3: (), b4} - ]); - - BooleanRecord3Array|CsvConversionError csvb1br3 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertEquals(csvb1br3, [ - {b1: true, b3: true}, - {b1: true, b3: true}, - {b1: true, b3: true} - ]); - - BooleanRecord3Array|CsvConversionError csvb2br3 = fromCsvStringWithType(csvStringWithBooleanValues2, {}); - test:assertEquals(csvb2br3, [ - {b1: true, b3: true}, - {b1: true, b3: true} - ]); - - BooleanRecord3Array|CsvConversionError csvb3br3 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br3, [ - {b1: true, b3: true}, - {b1: true, b3: ()}, - {b1: true, b3: false} - ]); - - BooleanRecord3Array|CsvConversionError csvb4br3 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br3, [ - {b1: true, b3: ()}, - {b1: true, b3: ()} - ]); - - BooleanRecord3Array|CsvConversionError csvb5br3 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br3, [ - {b1: true, b3: true}, - {b1: true, b3: true} - ]); - - BooleanRecord3Array|CsvConversionError csvb7br3 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br3, [ - {b1, b3: ()} - ]); - - BooleanRecord4Array|CsvConversionError csvb1br4 = fromCsvStringWithType(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|CsvConversionError csvb2br4 = fromCsvStringWithType(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|CsvConversionError csvb3br4 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br4, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: ()}, - {b1: true, b2: true, b3: false} - ]); - - BooleanRecord4Array|CsvConversionError csvb4br4 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br4, [ - {b1: true, b2: (), b3: (), b4: 0}, - {b1: true, b2: (), b3: (), b4: false} - ]); - - BooleanRecord4Array|CsvConversionError csvb5br4 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br4, [ - {b1: true, b2: false, b3: true, b4: 2}, - {b1: true, b2: false, b3: true, b4: 3} - ]); - - BooleanRecord4Array|CsvConversionError csvb7br4 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br4, [ - {b1, b2, b3: (), b4} - ]); - - BooleanRecord5Array|CsvConversionError csvb1br5 = fromCsvStringWithType(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|CsvConversionError csvb2br5 = fromCsvStringWithType(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|CsvConversionError csvb3br5 = fromCsvStringWithType(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|CsvConversionError csvb4br5 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br5, [ - {b1: true, b2: (), b3: (), b4: 0, defaultableField: "", nillableField: ()}, - {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord5Array|CsvConversionError csvb5br5 = fromCsvStringWithType(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|CsvConversionError csvb7br5 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br5, [ - {b1, b2, b3: (), b4, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|CsvConversionError csvb1br6 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertEquals(csvb1br6, [ - {b1: true, b3: true, defaultableField: "", nillableField: ()}, - {b1: true, b3: true, defaultableField: "", nillableField: ()}, - {b1: true, b3: true, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|CsvConversionError csvb2br6 = fromCsvStringWithType(csvStringWithBooleanValues2, {}); - test:assertEquals(csvb2br6, [ - {b1: true, b3: true, defaultableField: "", nillableField: ()}, - {b1: true, b3: true, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|CsvConversionError csvb3br6 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br6, [ - {b1: true, b3: true, defaultableField: "", nillableField: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: ()}, - {b1: true, b3: false, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|CsvConversionError csvb4br6 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br6, [ - {b1: true, b3: (), defaultableField: "", nillableField: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|CsvConversionError csvb5br6 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br6, [ - {b1: true, b3: true, defaultableField: "", nillableField: ()}, - {b1: true, b3: true, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|CsvConversionError csvb7br6 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br6, [ - {b1, b3: (), defaultableField: "", nillableField: ()} - ]); - - BooleanRecord7Array|CsvConversionError csvb1br7 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br7 is CsvConversionError); - test:assertEquals((csvb1br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord8Array|CsvConversionError csvb1br8 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br8 is CsvConversionError); - test:assertEquals((csvb1br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord9Array|CsvConversionError csvb1br9 = fromCsvStringWithType(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|CsvConversionError csvb2br9 = fromCsvStringWithType(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|CsvConversionError csvb3br9 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br9, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: ()}, - {b1: true, b2: true, b3: false} - ]); - - BooleanRecord9Array|CsvConversionError csvb4br9 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br9, [ - {b1: true, b2: (), b3: (), b4: false}, - {b1: true, b2: (), b3: (), b4: false} - ]); - - BooleanRecord9Array|CsvConversionError csvb5br9 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br9, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: true} - ]); - - BooleanRecord9Array|CsvConversionError csvb6br9 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br9 is CsvConversionError); - test:assertEquals((csvb6br9).message(), generateErrorMessageForMissingRequiredField("b1")); - - BooleanRecord9Array|CsvConversionError csvb7br9 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br9, [ - {b1, b2, b3: (), b4} - ]); - - BooleanRecord10Array|CsvConversionError csvb1br10 = fromCsvStringWithType(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|CsvConversionError csvb2br10 = fromCsvStringWithType(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|CsvConversionError csvb3br10 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br10, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false}, - {b1: true, b2: true, b3: false} - ]); - - BooleanRecord10Array|CsvConversionError csvb4br10 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br10, [ - {b1: true, b4: false}, - {b1: true, b4: false} - ]); - - BooleanRecord10Array|CsvConversionError csvb5br10 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br10, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: true} - ]); - - BooleanRecord10Array|CsvConversionError csvb6br10 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertEquals(csvb6br10, [ - {} - ]); - - BooleanRecord10Array|CsvConversionError csvb7br10 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br10, [ - {b1, b2, b4} - ]); - - BooleanRecord11Array|CsvConversionError csvb1br11 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertEquals(csvb1br11, [ - {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: ()} - ]); - - BooleanRecord11Array|CsvConversionError csvb2br11 = fromCsvStringWithType(csvStringWithBooleanValues2, {}); - 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|CsvConversionError csvb3br11 = fromCsvStringWithType(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|CsvConversionError csvb4br11 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br11, [ - {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()}, - {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord11Array|CsvConversionError csvb5br11 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br11, [ - {b1: true, b2: false, b3: true, b4: "2", defaultableField: "", nillableField: ()}, - {b1: true, b2: false, b3: true, b4: "3", defaultableField: "", nillableField: ()} - ]); - - BooleanRecord11Array|CsvConversionError csvb6br11 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br11 is CsvConversionError); - test:assertEquals((csvb6br11).message(), generateErrorMessageForMissingRequiredField("b1")); - - BooleanRecord11Array|CsvConversionError csvb7br11 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br11, [ - {b1, b2, b3, b4, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord12Array|CsvConversionError csvb1br12 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br12 is CsvConversionError); - test:assertEquals((csvb1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord13Array|CsvConversionError csvb1br13 = fromCsvStringWithType(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|CsvConversionError csvb2br13 = fromCsvStringWithType(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|CsvConversionError csvb3br13 = fromCsvStringWithType(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|CsvConversionError csvb4br13 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br13, [ - {b1: true, b2: "()", b3: "()", b4: false, defaultableField: "", nillableField: ()}, - {b1: true, b2: "()", b3: "null", b4: false, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord13Array|CsvConversionError csvb5br13 = fromCsvStringWithType(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|CsvConversionError csvb6br13 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertEquals(csvb6br13, [ - {b2: "()", b3: "()", defaultableField: "", nillableField: ()} - ]); - - BooleanRecord13Array|CsvConversionError csvb7br13 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br13, [ - {b1, b2, b3: "()", b4, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord14Array|CsvConversionError csvb7br14 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb7br14 is CsvConversionError); - test:assertEquals((csvb7br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); -} - -@test:Config {enable} -function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { - BooleanRecord15Array|CsvConversionError csvb1br15 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br15 is CsvConversionError); - test:assertEquals((csvb1br15).message(), generateErrorMessageForInvalidCast("true", "int")); - - BooleanRecord15Array|CsvConversionError csvb6br15 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br15 is CsvConversionError); - test:assertEquals((csvb6br15).message(), generateErrorMessageForMissingRequiredField("b1")); - - BooleanRecord15Array|CsvConversionError csvb7br15 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertTrue(csvb7br15 is CsvConversionError); - test:assertEquals((csvb7br15).message(), generateErrorMessageForInvalidCast("true", "int")); - - BooleanRecord16Array|CsvConversionError csvb1br16 = fromCsvStringWithType(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|CsvConversionError csvb2br16 = fromCsvStringWithType(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|CsvConversionError csvb3br16 = fromCsvStringWithType(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br16, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: ()}, - {b1: true, b2: true, b3: false} - ]); - - BooleanRecord16Array|CsvConversionError csvb4br16 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br16, [ - {b1: true, b2: (), b3: (), b4: false}, - {b1: true, b2: (), b3: (), b4: false} - ]); - - BooleanRecord16Array|CsvConversionError csvb5br16 = fromCsvStringWithType(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br16, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: true} - ]); - - BooleanRecord16Array|CsvConversionError csvb6br16 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertEquals(csvb6br16, [ - {b2: (), b3: ()} - ]); - - BooleanRecord16Array|CsvConversionError csvb7br16 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br16, [ - {b1, b2, b3: (), b4} - ]); - - BooleanRecord17Array|CsvConversionError csvb1br17 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertEquals(csvb1br17, [{}, {}, {}]); - - BooleanRecord17Array|CsvConversionError csvb4br17 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br17, [{b4: 0}, {b1: 1}]); - - BooleanRecord17Array|CsvConversionError csvb6br17 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertEquals(csvb6br17, [{}]); - - BooleanRecord17Array|CsvConversionError csvb7br17 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br17, [{}]); - - BooleanRecord18Array|CsvConversionError csvb1br18 = fromCsvStringWithType(csvStringWithBooleanValues1, {}); - test:assertEquals(csvb1br18, [{b2: false}, {b2: false}, {b2: false}]); - - BooleanRecord18Array|CsvConversionError csvb4br18 = fromCsvStringWithType(csvStringWithBooleanValues4, {}); - test:assertTrue(csvb4br18 is CsvConversionError); - test:assertEquals((csvb4br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanRecord18Array|CsvConversionError csvb6br18 = fromCsvStringWithType(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br18 is CsvConversionError); - test:assertEquals((csvb6br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanRecord18Array|CsvConversionError csvb7br18 = fromCsvStringWithType(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br18, [{b2, b3: ()}]); -} - -@test:Config {enable} -function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { - BooleanArrayArray|CsvConversionError cv1baa = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cv1baa, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - BooleanArrayArray|CsvConversionError cv2baa = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cv2baa, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - BooleanArrayArray|CsvConversionError cv3baa = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertTrue(cv3baa is CsvConversionError); - test:assertEquals((cv3baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanArrayArray|CsvConversionError cv4baa = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertTrue(cv4baa is CsvConversionError); - test:assertEquals((cv4baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanArrayArray|CsvConversionError cv5baa = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertTrue(cv5baa is CsvConversionError); - test:assertEquals((cv5baa).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanArrayArray|CsvConversionError cv6baa = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertTrue(cv6baa is CsvConversionError); - test:assertEquals((cv6baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanArrayArray|CsvConversionError cv7baa = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertTrue(cv7baa is CsvConversionError); - test:assertEquals((cv7baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - NillableBooleanArrayArray|CsvConversionError cv1nbaa = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cv1nbaa, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - NillableBooleanArrayArray|CsvConversionError cv2nbaa = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cv2nbaa, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableBooleanArrayArray|CsvConversionError cv3nbaa = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cv3nbaa, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - NillableBooleanArrayArray|CsvConversionError cv4nbaa = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cv4nbaa, [ - [true, (), (), false], - [true, (), (), false] - ]); - - NillableBooleanArrayArray|CsvConversionError cv5nbaa = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertTrue(cv5nbaa is CsvConversionError); - test:assertEquals((cv5nbaa).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - - NillableBooleanArrayArray|CsvConversionError cv6nbaa = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cv6nbaa, [ - [(), ()] - ]); - - NillableBooleanArrayArray|CsvConversionError cv7nbaa = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cv7nbaa, [ - [b1, b2, (), b4] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv1niubaa = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cv1niubaa, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv2niubaa = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cv2niubaa, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv3niubaa = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cv3niubaa, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv4niubaa = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cv4niubaa, [ - [true, (), (), 0], - [1, (), (), false] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv5niubaa = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(cv5niubaa, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv6niubaa = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cv6niubaa, [ - [(), ()] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv7niubaa = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cv7niubaa, [ - [b1, b2, (), b4] - ]); - - StringArray1Array|CsvConversionError cv1saa = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cv1saa, [ - ["true", "false", "true", "false"], - ["true", "false", "true", "false"], - ["true", "false", "true", "false"] - ]); - - StringArray1Array|CsvConversionError cv2saa = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cv2saa, [ - ["true", "false", "true", "false", "true"], - ["true", "false", "true", "false", "true"] - ]); - - StringArray1Array|CsvConversionError cv3saa = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cv3saa, [ - ["true", "false", "true"], - ["TRUE", "FALSE", "()"], - ["true", "true", "FALSE"] - ]); - - StringArray1Array|CsvConversionError cv4saa = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cv4saa, [ - ["true", "()", "()", "0"], - ["1", "()", "null", "false"] - ]); - - StringArray1Array|CsvConversionError cv5saa = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(cv5saa, [ - ["true", "false", "true", "2"], - ["true", "false", "true", "3"] - ]); - - StringArray1Array|CsvConversionError cv6saa = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cv6saa, [ - ["()", "()"] - ]); - - StringArray1Array|CsvConversionError cv7saa = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cv7saa, [ - ["true", "false", "()", "false"] - ]); - - StringArray2Array|CsvConversionError cv1s2aa = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cv1s2aa, [ - ["true", "false"], - ["true", "false"], - ["true", "false"] - ]); - - StringArray2Array|CsvConversionError cv2s2aa = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cv2s2aa, [ - ["true", "false"], - ["true", "false"] - ]); - - StringArray2Array|CsvConversionError cv3s2aa = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cv3s2aa, [ - ["true", "false"], - ["TRUE", "FALSE"], - ["true", "true"] - ]); - - StringArray2Array|CsvConversionError cv4s2aa = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cv4s2aa, [ - ["true", "()"], - ["1", "()"] - ]); - - StringArray2Array|CsvConversionError cv5s2aa = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(cv5s2aa, [ - ["true", "false"], - ["true", "false"] - ]); - - StringArray2Array|CsvConversionError cv6s2aa = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cv6s2aa, [ - ["()", "()"] - ]); - - StringArray2Array|CsvConversionError cv7s2aa = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cv7s2aa, [ - ["true", "false"] - ]); - - JsonArray1Array|CsvConversionError cv1jaa = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cv1jaa, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - JsonArray1Array|CsvConversionError cv2jaa = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cv2jaa, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - JsonArray1Array|CsvConversionError cv3jaa = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cv3jaa, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - JsonArray1Array|CsvConversionError cv4jaa = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cv4jaa, [ - [true, (), (), 0], - [1, (), (), false] - ]); - - JsonArray1Array|CsvConversionError cv5jaa = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(cv5jaa, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - JsonArray1Array|CsvConversionError cv6jaa = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cv6jaa, [ - [(), ()] - ]); - - JsonArray1Array|CsvConversionError cv7jaa = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cv7jaa, [ - [b1, b2, (), b4] - ]); - - AnydataArray1Array|CsvConversionError cv1anydaa = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cv1anydaa, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - AnydataArray1Array|CsvConversionError cv2anydaa = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cv2anydaa, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - AnydataArray1Array|CsvConversionError cv3anydaa = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cv3anydaa, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - AnydataArray1Array|CsvConversionError cv4anydaa = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cv4anydaa, [ - [true, (), (), 0], - [1, (), (), false] - ]); - - AnydataArray1Array|CsvConversionError cv5anydaa = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(cv5anydaa, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - AnydataArray1Array|CsvConversionError cv6anydaa = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cv6anydaa, [ - [(), ()] - ]); - - AnydataArray1Array|CsvConversionError cv7anydaa = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cv7anydaa, [ - [b1, b2, (), b4] - ]); - - DecimalArray1Array|CsvConversionError cv1daa = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertTrue(cv1daa is CsvConversionError); - test:assertEquals((cv1daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); - - DecimalArray1Array|CsvConversionError cv3daa = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertTrue(cv3daa is CsvConversionError); - test:assertEquals((cv3daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); - - DecimalArray1Array|CsvConversionError cv6daa = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertTrue(cv6daa is CsvConversionError); - test:assertEquals((cv6daa).message(), generateErrorMessageForInvalidCast("()", "decimal")); - - DecimalArray1Array|CsvConversionError cv7daa = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertTrue(cv7daa is CsvConversionError); - test:assertEquals((cv7daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); -} - -@test:Config {enable} -function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { - BooleanTuple1Array|CsvConversionError cbv1bt1 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt1, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - BooleanTuple1Array|CsvConversionError cbv2bt1 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt1, [ - [true, false, true, false], - [true, false, true, false] - ]); - - BooleanTuple1Array|CsvConversionError cbv3bt1 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertTrue(cbv3bt1 is CsvConversionError); - test:assertEquals((cbv3bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple1Array|CsvConversionError cbv5bt1 = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt1 is CsvConversionError); - test:assertEquals((cbv5bt1).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanTuple1Array|CsvConversionError cbv7bt1 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertTrue(cbv7bt1 is CsvConversionError); - test:assertEquals((cbv7bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple2Array|CsvConversionError cbv1bt2 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt2, [ - [true, false], - [true, false], - [true, false] - ]); - - BooleanTuple2Array|CsvConversionError cbv2bt2 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt2, [ - [true, false], - [true, false] - ]); - - BooleanTuple2Array|CsvConversionError cbv3bt2 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt2, [ - [true, false], - [true, false], - [true, true] - ]); - - BooleanTuple2Array|CsvConversionError cbv4bt2 = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertTrue(cbv4bt2 is CsvConversionError); - test:assertEquals((cbv4bt2).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple3Array|CsvConversionError cbv1bt3 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt3, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - BooleanTuple3Array|CsvConversionError cbv2bt3 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt3, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - BooleanTuple3Array|CsvConversionError cbv3bt3 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertTrue(cbv3bt3 is CsvConversionError); - test:assertEquals((cbv3bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple3Array|CsvConversionError cbv5bt3 = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt3 is CsvConversionError); - test:assertEquals((cbv5bt3).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanTuple3Array|CsvConversionError cbv7bt3 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertTrue(cbv7bt3 is CsvConversionError); - test:assertEquals((cbv7bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple4Array|CsvConversionError cbv1bt4 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt4, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - BooleanTuple4Array|CsvConversionError cbv2bt4 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt4, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - BooleanTuple4Array|CsvConversionError cbv3bt4 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertTrue(cbv3bt4 is CsvConversionError); - test:assertEquals((cbv3bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple4Array|CsvConversionError cbv4bt4 = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertTrue(cbv4bt4 is CsvConversionError); - test:assertEquals((cbv4bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple4Array|CsvConversionError cbv5bt4 = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt4 is CsvConversionError); - test:assertEquals((cbv5bt4).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanTuple4Array|CsvConversionError cbv6bt4 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertTrue(cbv6bt4 is CsvConversionError); - test:assertEquals((cbv6bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple4Array|CsvConversionError cbv7bt4 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertTrue(cbv7bt4 is CsvConversionError); - test:assertEquals((cbv7bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - NillableBooleanTuple5Array|CsvConversionError cbv1bt5 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt5, [ - [true, false, true, false, null], - [true, false, true, false, null], - [true, false, true, false, null] - ]); - - NillableBooleanTuple5Array|CsvConversionError cbv2bt5 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt5, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableBooleanTuple5Array|CsvConversionError cbv3bt5 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt5, [ - [true, false, true, null, null], - [true, false, (), null, null], - [true, true, false, null, null] - ]); - - NillableBooleanTuple5Array|CsvConversionError cbv4bt5 = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cbv4bt5, [ - [true, (), (), false, null], - [true, (), (), false, null] - ]); - - NillableBooleanTuple5Array|CsvConversionError cbv5bt5 = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt5 is CsvConversionError); - test:assertEquals((cbv5bt5).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - - NillableBooleanTuple5Array|CsvConversionError cbv6bt5 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cbv6bt5, [ - [(), (), null, null, null] - ]); - - NillableBooleanTuple5Array|CsvConversionError cbv7bt5 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cbv7bt5, [ - [b1, b2, (), b4, null] - ]); - - NillableBooleanTuple6Array|CsvConversionError cbv1bt6 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt6, [ - [true, false], - [true, false], - [true, false] - ]); - - NillableBooleanTuple6Array|CsvConversionError cbv2bt6 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt6, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple6Array|CsvConversionError cbv3bt6 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt6, [ - [true, false], - [true, false], - [true, true] - ]); - - NillableBooleanTuple6Array|CsvConversionError cbv4bt6 = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cbv4bt6, [ - [true, ()], - [true, ()] - ]); - - NillableBooleanTuple6Array|CsvConversionError cbv6bt6 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cbv6bt6, [ - [(), null] - ]); - - NillableBooleanTuple6Array|CsvConversionError cbv7bt6 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cbv7bt6, [ - [b1, b2] - ]); - - NillableBooleanTuple7Array|CsvConversionError cbv1bt7 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt7, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - NillableBooleanTuple7Array|CsvConversionError cbv2bt7 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt7, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableBooleanTuple7Array|CsvConversionError cbv3bt7 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt7, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - NillableBooleanTuple7Array|CsvConversionError cbv4bt7 = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cbv4bt7, [ - [true, (), (), false], - [true, (), (), false] - ]); - - NillableBooleanTuple7Array|CsvConversionError cbv5bt7 = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt7 is CsvConversionError); - test:assertEquals((cbv5bt7).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - - NillableBooleanTuple7Array|CsvConversionError cbv6bt7 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cbv6bt7, [ - [(), ()] - ]); - - NillableBooleanTuple7Array|CsvConversionError cbv7bt7 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cbv7bt7, [ - [b1, b2, (), false] - ]); - - NillableBooleanTuple8Array|CsvConversionError cbv1bt8 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt8, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - NillableBooleanTuple8Array|CsvConversionError cbv2bt8 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt8, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableBooleanTuple8Array|CsvConversionError cbv3bt8 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt8, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - NillableBooleanTuple8Array|CsvConversionError cbv4bt8 = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cbv4bt8, [ - [true, (), (), false], - [true, (), (), false] - ]); - - NillableBooleanTuple8Array|CsvConversionError cbv5bt8 = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt8 is CsvConversionError); - test:assertEquals((cbv5bt8).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - - NillableBooleanTuple8Array|CsvConversionError cbv6bt8 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cbv6bt8, [ - [(), ()] - ]); - - NillableBooleanTuple8Array|CsvConversionError cbv7bt8 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cbv7bt8, [ - [b1, b2, (), false] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError cbv1bt9 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt9, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError cbv2bt9 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt9, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError cbv3bt9 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt9, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError cbv4bt9 = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cbv4bt9, [ - [true, (), (), 0], - [1, (), (), false] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError cbv5bt9 = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(cbv5bt9, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError cbv6bt9 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cbv6bt9, [ - [(), ()] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError cbv7bt9 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cbv7bt9, [ - [b1, b2, (), false] - ]); - - NilTuple3Array|CsvConversionError cbv1nt3 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertTrue(cbv1nt3 is CsvConversionError); - test:assertEquals((cbv1nt3).message(), generateErrorMessageForInvalidCast("true", "()")); - - NilTuple3Array|CsvConversionError cbv3nt3 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertTrue(cbv3nt3 is CsvConversionError); - test:assertEquals((cbv3nt3).message(), generateErrorMessageForInvalidCast("true", "()")); - - NilTuple3Array|CsvConversionError cbv6nt3 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cbv6nt3, [ - [(), ()] - ]); - - AnydataTuple3Array|CsvConversionError cbv1anyd3 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1anyd3, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - AnydataTuple3Array|CsvConversionError cbv2anyd3 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2anyd3, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - AnydataTuple3Array|CsvConversionError cbv3anyd3 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cbv3anyd3, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - AnydataTuple3Array|CsvConversionError cbv4anyd3 = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cbv4anyd3, [ - [true, (), (), 0], - [1, (), (), false] - ]); - - AnydataTuple3Array|CsvConversionError cbv5anyd3 = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(cbv5anyd3, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - AnydataTuple3Array|CsvConversionError cbv6anyd3 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cbv6anyd3, [ - [(), ()] - ]); - - AnydataTuple3Array|CsvConversionError cbv7anyd3 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cbv7anyd3, [ - [b1, b2, (), false] - ]); -} - -@test:Config {enable} -function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { - JsonTuple3Array|CsvConversionError cbv1j3 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1j3, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - JsonTuple3Array|CsvConversionError cbv2j3 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2j3, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - JsonTuple3Array|CsvConversionError cbv3j3 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cbv3j3, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - JsonTuple3Array|CsvConversionError cbv4j3 = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cbv4j3, [ - [true, (), (), 0], - [1, (), (), false] - ]); - - JsonTuple3Array|CsvConversionError cbv5j3 = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(cbv5j3, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - JsonTuple3Array|CsvConversionError cbv6j3 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cbv6j3, [ - [(), ()] - ]); - - JsonTuple3Array|CsvConversionError cbv7j3 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cbv7j3, [ - [b1, b2, (), false] - ]); - - StringTuple3Array|CsvConversionError cbv1s3 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(cbv1s3, [ - ["true", "false", "true", "false"], - ["true", "false", "true", "false"], - ["true", "false", "true", "false"] - ]); - - StringTuple3Array|CsvConversionError cbv2s3 = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(cbv2s3, [ - ["true", "false", "true", "false", "true"], - ["true", "false", "true", "false", "true"] - ]); - - StringTuple3Array|CsvConversionError cbv3s3 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(cbv3s3, [ - ["true", "false", "true"], - ["TRUE", "FALSE", "()"], - ["true", "true", "FALSE"] - ]); - - StringTuple3Array|CsvConversionError cbv4s3 = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(cbv4s3, [ - ["true", "()", "()", "0"], - ["1", "()", "null", "false"] - ]); - - StringTuple3Array|CsvConversionError cbv5s3 = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(cbv5s3, [ - ["true", "false", "true", "2"], - ["true", "false", "true", "3"] - ]); - - StringTuple3Array|CsvConversionError cbv6s3 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(cbv6s3, [ - ["()", "()"] - ]); - - StringTuple3Array|CsvConversionError cbv7s3 = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(cbv7s3, [ - ["true", "false", "()", "false"] - ]); - - DecimalTuple3Array|CsvConversionError cbv1dt3 = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertTrue(cbv1dt3 is CsvConversionError); - test:assertEquals((cbv1dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); - - DecimalTuple3Array|CsvConversionError cbv3dt3 = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertTrue(cbv3dt3 is CsvConversionError); - test:assertEquals((cbv3dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); - - DecimalTuple3Array|CsvConversionError cbv6dt3 = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertTrue(cbv6dt3 is CsvConversionError); - test:assertEquals((cbv6dt3).message(), generateErrorMessageForInvalidCast("()", "decimal")); -} - -@test:Config {enable} -function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { - BooleanMapArray|CsvConversionError bv1bma = fromCsvStringWithType(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|CsvConversionError bv2bma = fromCsvStringWithType(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|CsvConversionError bv3bma = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(bv3bma, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false}, - {b1: true, b2: true, b3: false} - ]); - - BooleanMapArray|CsvConversionError bv4bma = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(bv4bma, [ - {b1: true, b4: false}, - {b1: true, b4: false} - ]); - - BooleanMapArray|CsvConversionError bv5bma = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(bv5bma, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: true} - ]); - - BooleanMapArray|CsvConversionError bv6bma = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(bv6bma, [ - {} - ]); - - BooleanMapArray|CsvConversionError bv7bma = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(bv7bma, [ - {b1, b2, b4} - ]); - - NillableBooleanMapArray|CsvConversionError bv1bnbma = fromCsvStringWithType(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|CsvConversionError bv2bnbma = fromCsvStringWithType(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|CsvConversionError bv3bnbma = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(bv3bnbma, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: null}, - {b1: true, b2: true, b3: false} - ]); - - NillableBooleanMapArray|CsvConversionError bv4bnbma = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(bv4bnbma, [ - {b1: true, b2: (), b3: (), b4: false}, - {b1: true, b2: (), b3: (), b4: false} - ]); - - NillableBooleanMapArray|CsvConversionError bv5bnbma = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(bv5bnbma, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: true} - ]); - - NillableBooleanMapArray|CsvConversionError bv6bnbma = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(bv6bnbma, [ - {b2: (), b3: ()} - ]); - - NillableBooleanMapArray|CsvConversionError bv7bnbma = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(bv7bnbma, [ - {b1, b2, b3, b4} - ]); - - NillableIntUnionBooleanMapArray|CsvConversionError bv1bniubma = fromCsvStringWithType(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|CsvConversionError bv2bniubma = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(bv2bniubma, [ - {b1: true, b2: false, b3: true, b4: false, b5: true}, - {b1: true, b2: false, b3: true, b4: false, b5: true} - ]); - - NillableIntUnionBooleanMapArray|CsvConversionError bv3bniubma = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(bv3bniubma, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: null}, - {b1: true, b2: true, b3: false} - ]); - - NillableIntUnionBooleanMapArray|CsvConversionError bv4bniubma = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(bv4bniubma, [ - {b1: true, b2: (), b3: (), b4: 0}, - {b1: 1, b2: (), b3: (), b4: false} - ]); - - NillableIntUnionBooleanMapArray|CsvConversionError bv5bniubma = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(bv5bniubma, [ - {b1: true, b2: false, b3: true, b4: 2}, - {b1: true, b2: false, b3: true, b4: 3} - ]); - - NillableIntUnionBooleanMapArray|CsvConversionError bv6bniubma = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(bv6bniubma, [ - {b2: (), b3: ()} - ]); - - NillableIntUnionBooleanMapArray|CsvConversionError bv7bniubma = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(bv7bniubma, [ - {b1, b2, b3, b4} - ]); - - IntUnionBooleanMapArray|CsvConversionError bv1biubma = fromCsvStringWithType(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|CsvConversionError bv2biubma = fromCsvStringWithType(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|CsvConversionError bv3biubma = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(bv3biubma, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false}, - {b1: true, b2: true, b3: false} - ]); - - IntUnionBooleanMapArray|CsvConversionError bv4biubma = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(bv4biubma, [ - {b1: true, b4: 0}, - {b1: 1, b4: false} - ]); - - IntUnionBooleanMapArray|CsvConversionError bv5biubma = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(bv5biubma, [ - {b1: true, b2: false, b3: true, b4: 2}, - {b1: true, b2: false, b3: true, b4: 3} - ]); - - IntUnionBooleanMapArray|CsvConversionError bv6biubma = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(bv6biubma, [ - {} - ]); - - IntUnionBooleanMapArray|CsvConversionError bv7biubma = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(bv7biubma, [ - {b1, b2, b4} - ]); - - NilMapArray|CsvConversionError bv1bnma = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(bv1bnma, [ - {}, - {}, - {} - ]); - - NilMapArray|CsvConversionError bv2bnma = fromCsvStringWithType(csvStringWithBooleanValues2); - test:assertEquals(bv2bnma, [ - {}, - {} - ]); - - NilMapArray|CsvConversionError bv3bnma = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(bv3bnma, [ - {}, - {b3: ()}, - {} - ]); - - NilMapArray|CsvConversionError bv4bnma = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(bv4bnma, [ - {b2: (), b3: ()}, - {b2: (), b3: ()} - ]); - - NilMapArray|CsvConversionError bv5bnma = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(bv5bnma, [ - {}, - {} - ]); - - NilMapArray|CsvConversionError bv6bnma = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(bv6bnma, [ - {b2: (), b3: ()} - ]); - - NilMapArray|CsvConversionError bv7bnma = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(bv7bnma, [ - {b3} - ]); - - JsonMapArray|CsvConversionError bv1bjma = fromCsvStringWithType(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|CsvConversionError bv2bjma = fromCsvStringWithType(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|CsvConversionError bv3bjma = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(bv3bjma, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: null}, - {b1: true, b2: true, b3: false} - ]); - - JsonMapArray|CsvConversionError bv4bjma = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(bv4bjma, [ - {b1: true, b2: (), b3: (), b4: 0}, - {b1: 1, b2: (), b3: (), b4: false} - ]); - - JsonMapArray|CsvConversionError bv5bjma = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(bv5bjma, [ - {b1: true, b2: false, b3: true, b4: 2}, - {b1: true, b2: false, b3: true, b4: 3} - ]); - - JsonMapArray|CsvConversionError bv6bjma = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(bv6bjma, [ - {b2: (), b3: ()} - ]); - - JsonMapArray|CsvConversionError bv7bjma = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(bv7bjma, [ - {b1, b2, b3, b4} - ]); - - AnydataMapArray|CsvConversionError bv1banydma = fromCsvStringWithType(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|CsvConversionError bv2banydma = fromCsvStringWithType(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|CsvConversionError bv3banydma = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(bv3banydma, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: null}, - {b1: true, b2: true, b3: false} - ]); - - AnydataMapArray|CsvConversionError bv4banydma = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(bv4banydma, [ - {b1: true, b2: (), b3: (), b4: 0}, - {b1: 1, b2: (), b3: (), b4: false} - ]); - - AnydataMapArray|CsvConversionError bv5banydma = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(bv5banydma, [ - {b1: true, b2: false, b3: true, b4: 2}, - {b1: true, b2: false, b3: true, b4: 3} - ]); - - AnydataMapArray|CsvConversionError bv6banydma = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(bv6banydma, [ - {b2: (), b3: ()} - ]); - - AnydataMapArray|CsvConversionError bv7banydma = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(bv7banydma, [ - {b1, b2, b3, b4} - ]); - - CustomMapArray|CsvConversionError bv1bcma = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(bv1bcma, [ - {b1: "true", b2: "false", b3: "true", b4: "false"}, - {b1: "true", b2: "false", b3: "true", b4: "false"}, - {b1: "true", b2: "false", b3: "true", b4: "false"} - ]); - - CustomMapArray|CsvConversionError bv2bcma = fromCsvStringWithType(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|CsvConversionError bv3bcma = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(bv3bcma, [ - {b1: "true", b2: "false", b3: "true"}, - {b1: "TRUE", b2: "FALSE", b3: "()"}, - {b1: "true", b2: "true", b3: "FALSE"} - ]); - - CustomMapArray|CsvConversionError bv4bcma = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(bv4bcma, [ - {b1: "true", b2: "()", b3: "()", b4: 0}, - {b1: 1, b2: "()", b3: "null", b4: "false"} - ]); - - CustomMapArray|CsvConversionError bv5bcma = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(bv5bcma, [ - {b1: "true", b2: "false", b3: "true", b4: 2}, - {b1: "true", b2: "false", b3: "true", b4: 3} - ]); - - CustomMapArray|CsvConversionError bv6bcma = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(bv6bcma, [ - {b2: "()", b3: "()"} - ]); - - CustomMapArray|CsvConversionError bv7bcma = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(bv7bcma, [ - {b1: "true", b2: "false", b3: "()", b4: "false"} - ]); - - StringMapArray|CsvConversionError bv1bsma = fromCsvStringWithType(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|CsvConversionError bv2bsma = fromCsvStringWithType(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|CsvConversionError bv3bsma = fromCsvStringWithType(csvStringWithBooleanValues3); - test:assertEquals(bv3bsma, [ - {b1: "true", b2: "false", b3: "true"}, - {b1: "TRUE", b2: "FALSE", b3: "()"}, - {b1: "true", b2: "true", b3: "FALSE"} - ]); - - StringMapArray|CsvConversionError bv4bsma = fromCsvStringWithType(csvStringWithBooleanValues4); - test:assertEquals(bv4bsma, [ - {b1: "true", b2: "()", b3: "()", b4: "0"}, - {b1: "1", b2: "()", b3: "null", b4: "false"} - ]); - - StringMapArray|CsvConversionError bv5bsma = fromCsvStringWithType(csvStringWithBooleanValues5); - test:assertEquals(bv5bsma, [ - {b1: "true", b2: "false", b3: "true", b4: "2"}, - {b1: "true", b2: "false", b3: "true", b4: "3"} - ]); - - StringMapArray|CsvConversionError bv6bsma = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(bv6bsma, [ - {b2: "()", b3: "()"} - ]); - - StringMapArray|CsvConversionError bv7bsma = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(bv7bsma, [ - {b1: "true", b2: "false", b3: "()", b4: "false"} - ]); - - DecimalMapArray|CsvConversionError bv1dsma = fromCsvStringWithType(csvStringWithBooleanValues1); - test:assertEquals(bv1dsma, [ - {}, - {}, - {} - ]); - DecimalMapArray|CsvConversionError bv6dsma = fromCsvStringWithType(csvStringWithBooleanValues6); - test:assertEquals(bv6dsma, [ - {} - ]); - - DecimalMapArray|CsvConversionError bv7dsma = fromCsvStringWithType(csvStringWithBooleanValues7); - test:assertEquals(bv7dsma, [ - {} - ]); -} - -@test:Config {enable} -function testFromCsvStringWithTypeCompatibility() { - string value = string ` - i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 - ${i1},${i2},${s1},${s2},${b1},${b2},(),(),${f1}, ${f2},${d1},${d2},${b1},${d1},${b2},${d2} - ${i1},${i2},${s1},${s2},${b1},${b2},(),(), ${f1},${f2},${d1},${d2},${b1},${d1},${b2},${d2} - `; - string value2 = string ` - i1, s1, b1, n1, f1, d1, j1, a1, s2, s3, j2, a2 - ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3},${b2}, ${d2} - `; - string value3 = string ` - i1, s1, b1, n1, f1, d1, j1, a1, s2, s3 - ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3} - `; - - AnydataArray1Array|CsvConversionError v3anyd1a = fromCsvStringWithType(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|CsvConversionError vcr27a = fromCsvStringWithType(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|CsvConversionError v2cr27a = fromCsvStringWithType(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|CsvConversionError v3cr27a = fromCsvStringWithType(value3, {}); - test:assertEquals(v3cr27a, [ - {i1, s1, b1, n1, f1, d1, a1: 2.234, j1: b1, defaultableField: "", nillableField: null, s2, s3} - ]); - - AnydataMapArray|CsvConversionError vanydma = fromCsvStringWithType(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|CsvConversionError vjma = fromCsvStringWithType(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|CsvConversionError vsma = fromCsvStringWithType(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|CsvConversionError v2ct7a = fromCsvStringWithType(value2); - test:assertEquals(v2ct7a, [ - [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3, "false", "-3.21"] - ]); - - CustomTuple7Array|CsvConversionError v3ct7a = fromCsvStringWithType(value3); - test:assertEquals(v3ct7a, [ - [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3] - ]); - - // CustomTuple8Array|CsvConversionError v2ct8a = fromCsvStringWithType(value2); - // test:assertTrue(v2ct8a is CsvConversionError); - // test:assertEquals((v2ct8a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "int")); - - [float, decimal, string][]|CsvConversionError mrrta = fromCsvStringWithType(string `a, b,c - 1.23, 1.23, 1.23 - 0,0,0 - 0.0,0.0,0.0 - -1.2,-1.2,-1.2`); - test:assertEquals(mrrta, [ - [1.23, 1.23, "1.23"], - [0, 0, "0"], - [0, 0, "0.0"], - [-1.2, -1.2, "-1.2"] - ]); - - [float, decimal, string, int][]|CsvConversionError m2rrta = fromCsvStringWithType(string `a, b,c,d - 1, 1, 1,1 - 0,0,0,0 - -1,-1,-1,-1`); - test:assertEquals(m2rrta, [ - [1, 1, "1", 1], - [0, 0, "0", 0], - [-1, -1, "-1", -1] - ]); - - [int...][]|CsvConversionError m3rrta = fromCsvStringWithType(string `a, b,c,d - 1.2, abc, true,1.0`); - test:assertTrue(m3rrta is CsvConversionError); - test:assertEquals((m3rrta).message(), generateErrorMessageForInvalidCast("1.2", "int")); - - [boolean, int][]|CsvConversionError m4rrta = fromCsvStringWithType(string `a, b - 1, 1 - 0,0`); - test:assertEquals(m4rrta, [ - [true, 1], - [false, 0] - ]); - - record {|int...;|}[]|CsvConversionError irrma = fromCsvStringWithType(string ` - a, b, c - 1, a, 2.3 - 1, -2, true - hello, -2, hello`); - test:assertEquals(irrma, [ - {a: 1}, - {a: i1, b: i2}, - {b: i2} - ]); - - record {|()...;|}[]|CsvConversionError nrrma = fromCsvStringWithType(string ` - a, b, c - 1, a, () - 1, null, () - hello, -2, hello`); - test:assertEquals(nrrma, [ - {c: ()}, - {b: (), c: ()}, - {} - ]); - - record {|decimal...;|}[]|CsvConversionError drra = fromCsvStringWithType(string `a, b, c - 2.234, invalid , 1 - ${f2}, 0, 2.3d - invalid, ${d2}, ${f3}`); - test:assertTrue(drra is record {|decimal...;|}[]); - test:assertEquals(drra, [ - {a: d1, c: 1.0}, - {a: f2, b: d3}, - {b: -3.21d, c: f3} - ]); - - record {|string...;|}[]|CsvConversionError srra = fromCsvStringWithType(string ` - a, b, c - 1, a, 2.3 - 1, -2, true - hello, -2, hello`); - test:assertTrue(srra is record {|string...;|}[]); - test:assertEquals(srra, [ - {a: "1", b: "a", c: "2.3"}, - {a: "1", b: "-2", c: "true"}, - {a: "hello", b: "-2", c: "hello"} - ]); - - record {|float...;|}[]|CsvConversionError frra = fromCsvStringWithType(string `a, b, c - 1.2, invalid , 1 - ${d2}, ${d3}, true - ${d4}, ${f2}, 0.0`); - test:assertEquals(frra, [ - {a: 1.2, c: 1.0}, - {a: d2, b: d3}, - {a: d4, b: f2, c: 0.0} - ]); - - record {float a; decimal b; string c;}[]|CsvConversionError mrra = fromCsvStringWithType(string `a, b,c - 1.23, 1.23, 1.23 - 0,0,0 - 0.0,0.0,0.0 - -1.2,-1.2,-1.2`); - test:assertEquals(mrra, [ - {a: 1.23, b: 1.23, c: "1.23"}, - {a: 0, b: 0, c: "0"}, - {a: 0, b: 0, c: "0.0"}, - {a: -1.2, b: -1.2, c: "-1.2"} - ]); - - record {|float a; decimal b; string c; int d;|}[]|CsvConversionError m2rra = fromCsvStringWithType(string `a, b,c,d - 1, 1, 1,1 - 0,0,0,0 - -1,-1,-1,-1`); - test:assertEquals(m2rra, [ - {a: 1, b: 1, c: "1", d: 1}, - {a: 0, b: 0, c: "0", d: 0}, - {a: -1, b: -1, c: "-1", d: -1} - ]); - - record {int d;}[]|CsvConversionError m3rra = fromCsvStringWithType(string `a, b,c,d - 1.2, abc, true,1.0`); - test:assertTrue(m3rra is CsvConversionError); - test:assertEquals((m3rra).message(), generateErrorMessageForInvalidCast("1.0", "int")); - - record {int b; boolean a;}[]|CsvConversionError m4rra = fromCsvStringWithType(string `a, b - 1, 1 - 0,0`); - test:assertEquals(m4rra, [ - {a: true, b: 1}, - {a: false, b: 0} - ]); -} - -// boolean enable = true; - -// @test:Config {enable: !enable} -// function test() { -// NillableBooleanTuple5|CsvConversionError cbv1bt5 = fromCsvStringWithType(csvStringWithBooleanValues1); -// test:assertEquals(cbv1bt5, [ -// [true, false, true, false], -// [true, false, true, false], -// [true, false, true, false] -// ]); -// } diff --git a/ballerina/tests/from_csv_with_type_test.bal b/ballerina/tests/from_csv_with_type_test.bal deleted file mode 100644 index 1a1c56c..0000000 --- a/ballerina/tests/from_csv_with_type_test.bal +++ /dev/null @@ -1,2297 +0,0 @@ -import ballerina/test; - -@test:Config {enable} -function testFromCsvWithTypeForMapAndRecordAsExpectedType() { - BooleanRecord1Array|CsvConversionError bm1br1 = fromCsvWithType([bm1, bm1], {}, BooleanRecord1Array); - test:assertTrue(bm1br1 is CsvConversionError); - test:assertEquals((bm1br1).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord1Array|CsvConversionError bm2br1 = fromCsvWithType([bm2, bm2], {}, BooleanRecord1Array); - test:assertTrue(bm2br1 is CsvConversionError); - test:assertEquals((bm2br1).message(), generateErrorMessageForMissingRequiredField("b4")); - - BooleanRecord1Array|CsvConversionError bm3br1 = fromCsvWithType([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|CsvConversionError bm4br1 = fromCsvWithType([bm4, bm4], {}, BooleanRecord1Array); - test:assertTrue(bm4br1 is CsvConversionError); - test:assertEquals((bm4br1).message(), generateErrorMessageForMissingRequiredField("b2")); - - BooleanRecord1Array|CsvConversionError bm5br1 = fromCsvWithType([bm5, bm5], {}, BooleanRecord1Array); - test:assertEquals(bm5br1, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - BooleanRecord2Array|CsvConversionError bm1br2 = fromCsvWithType([bm1, bm1], {}, BooleanRecord2Array); - test:assertTrue(bm1br2 is CsvConversionError); - test:assertEquals((bm1br2).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord2Array|CsvConversionError bm2br2 = fromCsvWithType([bm2, bm2], {}, BooleanRecord2Array); - test:assertTrue(bm2br2 is CsvConversionError); - test:assertEquals((bm2br2).message(), generateErrorMessageForMissingRequiredField("b4")); - - BooleanRecord2Array|CsvConversionError bm3br2 = fromCsvWithType([bm3, bm3], {}, BooleanRecord2Array); - test:assertEquals(bm3br2, [ - {b1: true, b2: false, b3: (), b4: false}, - {b1: true, b2: false, b3: (), b4: false} - ]); - - BooleanRecord2Array|CsvConversionError bm4br2 = fromCsvWithType([bm4, bm4], {}, BooleanRecord2Array); - test:assertTrue(bm4br2 is CsvConversionError); - test:assertEquals((bm4br2).message(), generateErrorMessageForMissingRequiredField("b2")); - - BooleanRecord2Array|CsvConversionError bm5br2 = fromCsvWithType([bm5, bm5], {}, BooleanRecord2Array); - test:assertEquals(bm5br2, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - BooleanRecord3Array|CsvConversionError bm1br3 = fromCsvWithType([bm1, bm1], {}, BooleanRecord3Array); - test:assertTrue(bm1br3 is CsvConversionError); - test:assertEquals((bm1br3).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord3Array|CsvConversionError bm2br3 = fromCsvWithType([bm2, bm2], {}, BooleanRecord3Array); - test:assertEquals(bm2br3, [ - {b1: true, b3: ()}, - {b1: true, b3: ()} - ]); - - BooleanRecord3Array|CsvConversionError bm3br3 = fromCsvWithType([bm3, bm3], {}, BooleanRecord3Array); - test:assertEquals(bm3br3, [ - {b1: true, b3: ()}, - {b1: true, b3: ()} - ]); - - BooleanRecord3Array|CsvConversionError bm4br3 = fromCsvWithType([bm4, bm4], {}, BooleanRecord3Array); - test:assertTrue(bm4br3 is CsvConversionError); - test:assertEquals((bm4br3).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord3Array|CsvConversionError bm5br3 = fromCsvWithType([bm5, bm5], {}, BooleanRecord3Array); - test:assertEquals(bm5br3, [{b1: true, b3: ()}, {b1: true, b3: ()}]); - - BooleanRecord4Array|CsvConversionError bm1br4 = fromCsvWithType([bm1, bm1], {}, BooleanRecord4Array); - test:assertTrue(bm1br4 is CsvConversionError); - test:assertEquals((bm1br4).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord4Array|CsvConversionError bm2br4 = fromCsvWithType([bm2, bm2], {}, BooleanRecord4Array); - test:assertEquals(bm2br4, [ - {b1: true, b2: false, b3: (), n1: (), n3: ()}, - {b1: true, b2: false, b3: (), n1: (), n3: ()} - ]); - - BooleanRecord4Array|CsvConversionError bm3br4 = fromCsvWithType([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|CsvConversionError bm4br4 = fromCsvWithType([bm4, bm4], {}, BooleanRecord4Array); - test:assertTrue(bm4br4 is CsvConversionError); - test:assertEquals((bm4br4).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord4Array|CsvConversionError bm5br4 = fromCsvWithType([bm5, bm5], {}, BooleanRecord4Array); - test:assertEquals(bm5br4, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - BooleanRecord5Array|CsvConversionError bm1br5 = fromCsvWithType([bm1, bm1], {}, BooleanRecord5Array); - test:assertTrue(bm1br5 is CsvConversionError); - test:assertEquals((bm1br5).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord5Array|CsvConversionError bm2br5 = fromCsvWithType([bm2, bm2], {}, BooleanRecord5Array); - test:assertEquals(bm2br5, [ - {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()} - ]); - - BooleanRecord5Array|CsvConversionError bm3br5 = fromCsvWithType([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|CsvConversionError bm4br5 = fromCsvWithType([bm4, bm4], {}, BooleanRecord5Array); - test:assertTrue(bm4br5 is CsvConversionError); - test:assertEquals((bm4br5).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord5Array|CsvConversionError bm5br5 = fromCsvWithType([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|CsvConversionError bm1br6 = fromCsvWithType([bm1, bm1], {}, BooleanRecord6Array); - test:assertTrue(bm1br6 is CsvConversionError); - test:assertEquals((bm1br6).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord6Array|CsvConversionError bm2br6 = fromCsvWithType([bm2, bm2], {}, BooleanRecord6Array); - test:assertEquals(bm2br6, [ - {b1: true, b3: (), defaultableField: "", nillableField: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|CsvConversionError bm3br6 = fromCsvWithType([bm3, bm3], {}, BooleanRecord6Array); - test:assertEquals(bm3br6, [ - {b1: true, b3: (), defaultableField: "", nillableField: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|CsvConversionError bm4br6 = fromCsvWithType([bm4, bm4], {}, BooleanRecord6Array); - test:assertTrue(bm4br6 is CsvConversionError); - test:assertEquals((bm4br6).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord6Array|CsvConversionError bm5br6 = fromCsvWithType([bm5, bm5], {}, BooleanRecord6Array); - test:assertEquals(bm5br6, [ - {b1: true, b3: (), defaultableField: "", nillableField: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: ()} - ]); - - BooleanRecord7Array|CsvConversionError bm1br7 = fromCsvWithType([bm1, bm1], {}, BooleanRecord7Array); - test:assertTrue(bm1br7 is CsvConversionError); - test:assertEquals((bm1br7).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord7Array|CsvConversionError bm2br7 = fromCsvWithType([bm2, bm2], {}, BooleanRecord7Array); - test:assertTrue(bm2br7 is CsvConversionError); - test:assertEquals((bm2br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord7Array|CsvConversionError bm3br7 = fromCsvWithType([bm3, bm3], {}, BooleanRecord7Array); - test:assertTrue(bm3br7 is CsvConversionError); - test:assertEquals((bm3br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord7Array|CsvConversionError bm4br7 = fromCsvWithType([bm4, bm4], {}, BooleanRecord7Array); - test:assertTrue(bm4br7 is CsvConversionError); - test:assertEquals((bm4br7).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord7Array|CsvConversionError bm5br7 = fromCsvWithType([bm5, bm5], {}, BooleanRecord7Array); - test:assertTrue(bm5br7 is CsvConversionError); - test:assertEquals((bm5br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord8Array|CsvConversionError bm1br8 = fromCsvWithType([bm1, bm1], {}, BooleanRecord8Array); - test:assertTrue(bm1br8 is CsvConversionError); - test:assertEquals((bm1br8).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord8Array|CsvConversionError bm2br8 = fromCsvWithType([bm2, bm2], {}, BooleanRecord8Array); - test:assertTrue(bm2br8 is CsvConversionError); - test:assertEquals((bm2br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord8Array|CsvConversionError bm3br8 = fromCsvWithType([bm3, bm3], {}, BooleanRecord8Array); - test:assertTrue(bm3br8 is CsvConversionError); - test:assertEquals((bm3br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord8Array|CsvConversionError bm4br8 = fromCsvWithType([bm4, bm4], {}, BooleanRecord8Array); - test:assertTrue(bm4br8 is CsvConversionError); - test:assertEquals((bm4br8).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord8Array|CsvConversionError bm5br8 = fromCsvWithType([bm5, bm5], {}, BooleanRecord8Array); - test:assertTrue(bm5br8 is CsvConversionError); - test:assertEquals((bm5br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); -} - -@test:Config {enable} -function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { - BooleanRecord9Array|CsvConversionError bm1br9 = fromCsvWithType([bm1, bm1], {}, BooleanRecord9Array); - test:assertTrue(bm1br9 is CsvConversionError); - test:assertEquals((bm1br9).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord9Array|CsvConversionError bm2br9 = fromCsvWithType([bm2, bm2], {}, BooleanRecord9Array); - test:assertEquals(bm2br9, [ - {b1: true, b2: false, b3: (), n1: (), n3: ()}, - {b1: true, b2: false, b3: (), n1: (), n3: ()} - ]); - - BooleanRecord9Array|CsvConversionError bm3br9 = fromCsvWithType([bm3, bm3], {}, BooleanRecord9Array); - test:assertEquals(bm3br9, [ - {b1: true, b2: false, b3: (), b4: false}, - {b1: true, b2: false, b3: (), b4: false} - ]); - - BooleanRecord9Array|CsvConversionError bm4br9 = fromCsvWithType([bm4, bm4], {}, BooleanRecord9Array); - test:assertTrue(bm4br9 is CsvConversionError); - test:assertEquals((bm4br9).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord9Array|CsvConversionError bm5br9 = fromCsvWithType([bm5, bm5], {}, BooleanRecord9Array); - test:assertEquals(bm5br9, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - BooleanRecord10Array|CsvConversionError bm1br10 = fromCsvWithType([bm1, bm1], {}, BooleanRecord10Array); - test:assertEquals(bm1br10, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - BooleanRecord10Array|CsvConversionError bm2br10 = fromCsvWithType([bm2, bm2], {}, BooleanRecord10Array); - test:assertEquals(bm2br10, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - BooleanRecord10Array|CsvConversionError bm3br10 = fromCsvWithType([bm3, bm3], {}, BooleanRecord10Array); - test:assertEquals(bm3br10, [ - {b1: true, b2: false, b4: false}, - {b1: true, b2: false, b4: false} - ]); - - BooleanRecord10Array|CsvConversionError bm4br10 = fromCsvWithType([bm4, bm4], {}, BooleanRecord10Array); - test:assertEquals(bm4br10, [ - {}, - {} - ]); - - BooleanRecord10Array|CsvConversionError bm5br10 = fromCsvWithType([bm5, bm5], {}, BooleanRecord10Array); - test:assertEquals(bm5br10, [ - {b1: true, b2: false, b4: true}, - {b1: true, b2: false, b4: true} - ]); - - BooleanRecord11Array|CsvConversionError bm1br11 = fromCsvWithType([bm1, bm1], {}, BooleanRecord11Array); - test:assertEquals(bm1br11, [ - {b1: true, b2: false, defaultableField: "", nillableField :null}, - {b1: true, b2: false, defaultableField: "", nillableField :null} - ]); - - BooleanRecord11Array|CsvConversionError bm2br11 = fromCsvWithType([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|CsvConversionError bm3br11 = fromCsvWithType([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|CsvConversionError bm4br11 = fromCsvWithType([bm4, bm4], {}, BooleanRecord11Array); - test:assertTrue(bm4br11 is CsvConversionError); - test:assertEquals((bm4br11).message(), generateErrorMessageForMissingRequiredField("b1")); - - BooleanRecord11Array|CsvConversionError bm5br11 = fromCsvWithType([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|CsvConversionError bm1br12 = fromCsvWithType([bm1, bm1], {}, BooleanRecord12Array); - test:assertTrue(bm1br12 is CsvConversionError); - test:assertEquals((bm1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord12Array|CsvConversionError bm2br12 = fromCsvWithType([bm2, bm2], {}, BooleanRecord12Array); - test:assertTrue(bm2br12 is CsvConversionError); - test:assertEquals((bm2br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord12Array|CsvConversionError bm3br12 = fromCsvWithType([bm3, bm3], {}, BooleanRecord12Array); - test:assertTrue(bm3br12 is CsvConversionError); - test:assertEquals((bm3br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord12Array|CsvConversionError bm4br12 = fromCsvWithType([bm4, bm4], {}, BooleanRecord12Array); - test:assertTrue(bm4br12 is CsvConversionError); - test:assertEquals((bm4br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord12Array|CsvConversionError bm5br12 = fromCsvWithType([bm5, bm5], {}, BooleanRecord12Array); - test:assertTrue(bm5br12 is CsvConversionError); - test:assertEquals((bm5br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord13Array|CsvConversionError bm1br13 = fromCsvWithType([bm1, bm1], {}, BooleanRecord13Array); - test:assertEquals(bm1br13, [ - {b1: true, b2: false, defaultableField: "", nillableField :null}, - {b1: true, b2: false, defaultableField: "", nillableField :null} - ]); - - BooleanRecord13Array|CsvConversionError bm2br13 = fromCsvWithType([bm2, bm2], {}, BooleanRecord13Array); - test:assertEquals(bm2br13, [ - {b1: true, b2: false, defaultableField: "", nillableField :null}, - {b1: true, b2: false, defaultableField: "", nillableField :null} - ]); - - BooleanRecord13Array|CsvConversionError bm3br13 = fromCsvWithType([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|CsvConversionError bm4br13 = fromCsvWithType([bm4, bm4], {}, BooleanRecord13Array); - test:assertEquals(bm4br13, [ - {defaultableField: "", nillableField :null}, - {defaultableField: "", nillableField :null} - ]); - - BooleanRecord13Array|CsvConversionError bm5br13 = fromCsvWithType([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|CsvConversionError bm1br14 = fromCsvWithType([bm1, bm1], {}, BooleanRecord14Array); - test:assertTrue(bm1br14 is CsvConversionError); - test:assertEquals((bm1br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord14Array|CsvConversionError bm2br14 = fromCsvWithType([bm2, bm2], {}, BooleanRecord14Array); - test:assertTrue(bm2br14 is CsvConversionError); - test:assertEquals((bm2br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord14Array|CsvConversionError bm3br14 = fromCsvWithType([bm3, bm3], {}, BooleanRecord14Array); - test:assertTrue(bm3br14 is CsvConversionError); - test:assertEquals((bm3br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord14Array|CsvConversionError bm4br14 = fromCsvWithType([bm4, bm4], {}, BooleanRecord14Array); - test:assertTrue(bm4br14 is CsvConversionError); - test:assertEquals((bm4br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord14Array|CsvConversionError bm5br14 = fromCsvWithType([bm5, bm5], {}, BooleanRecord14Array); - test:assertTrue(bm5br14 is CsvConversionError); - test:assertEquals((bm5br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord15Array|CsvConversionError bm1br15 = fromCsvWithType([bm1, bm1], {}, BooleanRecord15Array); - test:assertTrue(bm1br15 is CsvConversionError); - test:assertEquals((bm1br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); - - BooleanRecord15Array|CsvConversionError bm3br15 = fromCsvWithType([bm3, bm3], {}, BooleanRecord15Array); - test:assertTrue(bm3br15 is CsvConversionError); - test:assertEquals((bm3br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); - - BooleanRecord15Array|CsvConversionError bm4br15 = fromCsvWithType([bm4, bm4], {}, BooleanRecord15Array); - test:assertTrue(bm4br15 is CsvConversionError); - test:assertEquals((bm4br15).message(), generateErrorMessageForMissingRequiredField("b1")); - - BooleanRecord16Array|CsvConversionError bm1br16 = fromCsvWithType([bm1, bm1], {}, BooleanRecord16Array); - test:assertEquals(bm1br16, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - BooleanRecord16Array|CsvConversionError bm2br16 = fromCsvWithType([bm2, bm2], {}, BooleanRecord16Array); - test:assertEquals(bm2br16, [ - {b1: true, b2: false, b3: (), n1: (), n3: ()}, - {b1: true, b2: false, b3: (), n1: (), n3: ()} - ]); - - BooleanRecord16Array|CsvConversionError bm3br16 = fromCsvWithType([bm3, bm3], {}, BooleanRecord16Array); - test:assertEquals(bm3br16, [ - {b1: true, b2: false, b4: false, b3: ()}, - {b1: true, b2: false, b4: false, b3: ()} - ]); - - BooleanRecord16Array|CsvConversionError bm4br16 = fromCsvWithType([bm4, bm4], {}, BooleanRecord16Array); - test:assertEquals(bm4br16, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - - BooleanRecord16Array|CsvConversionError bm5br16 = fromCsvWithType([bm5, bm5], {}, BooleanRecord16Array); - test:assertEquals(bm5br16, [ - {b1: true, b2: false, b4: true, b3: ()}, - {b1: true, b2: false, b4: true, b3: ()} - ]); - - BooleanRecord17Array|CsvConversionError bm1br17 = fromCsvWithType([bm1, bm1], {}, BooleanRecord17Array); - test:assertEquals(bm1br17, [ - {}, - {} - ]); - - BooleanRecord17Array|CsvConversionError bm2br17 = fromCsvWithType([bm2, bm2], {}, BooleanRecord17Array); - test:assertEquals(bm2br17, [ - {}, - {} - ]); - - BooleanRecord17Array|CsvConversionError bm3br17 = fromCsvWithType([bm3, bm3], {}, BooleanRecord17Array); - test:assertEquals(bm3br17, [ - {i1: 1}, - {i1: 1} - ]); - - BooleanRecord17Array|CsvConversionError bm4br17 = fromCsvWithType([bm4, bm4], {}, BooleanRecord17Array); - test:assertEquals(bm4br17, [ - {}, - {} - ]); - - BooleanRecord17Array|CsvConversionError bm5br17 = fromCsvWithType([bm5, bm5], {}, BooleanRecord17Array); - test:assertEquals(bm5br17, [ - {}, - {} - ]); - - BooleanRecord18Array|CsvConversionError bm1br18 = fromCsvWithType([bm1, bm1], {}, BooleanRecord18Array); - test:assertEquals(bm1br18, [ - {b2: false}, - {b2: false} - ]); - - BooleanRecord18Array|CsvConversionError bm2br18 = fromCsvWithType([bm2, bm2], {}, BooleanRecord18Array); - test:assertEquals(bm2br18, [ - {b2: false, b3: (), n1: (), n3: ()}, - {b2: false, b3: (), n1: (), n3: ()} - ]); - - BooleanRecord18Array|CsvConversionError bm3br18 = fromCsvWithType([bm3, bm3], {}, BooleanRecord18Array); - test:assertEquals(bm3br18, [ - {b2: false, b3: (), i1: 1}, - {b2: false, b3: (), i1: 1} - ]); - - BooleanRecord18Array|CsvConversionError bm4br18 = fromCsvWithType([bm4, bm4], {}, BooleanRecord18Array); - test:assertTrue(bm4br18 is CsvConversionError); - test:assertEquals((bm4br18).message(), generateErrorMessageForMissingRequiredField("b2")); - - BooleanRecord18Array|CsvConversionError bm5br18 = fromCsvWithType([bm5, bm5], {}, BooleanRecord18Array); - test:assertEquals(bm5br18, [ - {b2: false, b3: ()}, - {b2: false, b3: ()} - ]); -} - -@test:Config {enable} -function testFromCsvWithTypeForMapAndMapAsExpectedType() { - BooleanMapArray|CsvConversionError bm1bma = fromCsvWithType([bm1, bm1], {}, BooleanMapArray); - test:assertEquals(bm1bma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - BooleanMapArray|CsvConversionError bm2bma = fromCsvWithType([bm2, bm2], {}, BooleanMapArray); - test:assertEquals(bm2bma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - BooleanMapArray|CsvConversionError bm3bma = fromCsvWithType([bm3, bm3], {}, BooleanMapArray); - test:assertEquals(bm3bma, [ - {b1: true, b2: false, b4: false}, - {b1: true, b2: false, b4: false} - ]); - - BooleanMapArray|CsvConversionError bm4bma = fromCsvWithType([bm4, bm4], {}, BooleanMapArray); - test:assertEquals(bm4bma, [ - {}, - {} - ]); - - BooleanMapArray|CsvConversionError bm5bma = fromCsvWithType([bm5, bm5], {}, BooleanMapArray); - test:assertEquals(bm5bma, [ - {b1: true, b2: false, b4: true}, - {b1: true, b2: false, b4: true} - ]); - - NillableBooleanMapArray|CsvConversionError bm1nbma = fromCsvWithType([bm1, bm1], {}, NillableBooleanMapArray); - test:assertEquals(bm1nbma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - NillableBooleanMapArray|CsvConversionError bm2nbma = fromCsvWithType([bm2, bm2], {}, NillableBooleanMapArray); - test:assertEquals(bm2nbma, [ - {b1: true, b2: false, b3:(), n1: (), n3: ()}, - {b1: true, b2: false, b3:(), n1: (), n3: ()} - ]); - - NillableBooleanMapArray|CsvConversionError bm3nbma = fromCsvWithType([bm3, bm3], {}, NillableBooleanMapArray); - test:assertEquals(bm3nbma, [ - {b1: true, b2: false, b3:(), b4: false}, - {b1: true, b2: false, b3:(), b4: false} - ]); - - NillableBooleanMapArray|CsvConversionError bm4nbma = fromCsvWithType([bm4, bm4], {}, NillableBooleanMapArray); - test:assertEquals(bm4nbma, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - - NillableBooleanMapArray|CsvConversionError bm5nbma = fromCsvWithType([bm5, bm5], {}, NillableBooleanMapArray); - test:assertEquals(bm5nbma, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - NillableIntUnionBooleanMapArray|CsvConversionError bm1niubma = fromCsvWithType([bm1, bm1], {}, NillableIntUnionBooleanMapArray); - test:assertEquals(bm1niubma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - NillableIntUnionBooleanMapArray|CsvConversionError bm2niubma = fromCsvWithType([bm2, bm2], {}, NillableIntUnionBooleanMapArray); - test:assertEquals(bm2niubma, [ - {b1: true, b2: false, b3:(), n1: (), n3: ()}, - {b1: true, b2: false, b3:(), n1: (), n3: ()} - ]); - - NillableIntUnionBooleanMapArray|CsvConversionError bm3niubma = fromCsvWithType([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|CsvConversionError bm4niubma = fromCsvWithType([bm4, bm4], {}, NillableIntUnionBooleanMapArray); - test:assertEquals(bm4niubma, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - - NillableIntUnionBooleanMapArray|CsvConversionError bm5niubma = fromCsvWithType([bm5, bm5], {}, NillableIntUnionBooleanMapArray); - test:assertEquals(bm5niubma, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - IntUnionBooleanMapArray|CsvConversionError bm1iubma = fromCsvWithType([bm1, bm1], {}, IntUnionBooleanMapArray); - test:assertEquals(bm1iubma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - IntUnionBooleanMapArray|CsvConversionError bm2iubma = fromCsvWithType([bm2, bm2], {}, IntUnionBooleanMapArray); - test:assertEquals(bm2iubma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - IntUnionBooleanMapArray|CsvConversionError bm3iubma = fromCsvWithType([bm3, bm3], {}, IntUnionBooleanMapArray); - test:assertEquals(bm3iubma, [ - {b1: true, b2: false, b4: false, i1: 1}, - {b1: true, b2: false, b4: false, i1: 1} - ]); - - IntUnionBooleanMapArray|CsvConversionError bm4iubma = fromCsvWithType([bm4, bm4], {}, IntUnionBooleanMapArray); - test:assertEquals(bm4iubma, [ - {}, - {} - ]); - - IntUnionBooleanMapArray|CsvConversionError bm5iubma = fromCsvWithType([bm5, bm5], {}, IntUnionBooleanMapArray); - test:assertEquals(bm5iubma, [ - {b1: true, b2: false, b4: true}, - {b1: true, b2: false, b4: true} - ]); - - NilMapArray|CsvConversionError bm1nma = fromCsvWithType([bm1, bm1], {}, NilMapArray); - test:assertEquals(bm1nma, [ - {}, - {} - ]); - - NilMapArray|CsvConversionError bm2nma = fromCsvWithType([bm2, bm2], {}, NilMapArray); - test:assertEquals(bm2nma, [ - {n1: (), n3: (), b3: ()}, - {n1: (), n3: (), b3: ()} - ]); - - NilMapArray|CsvConversionError bm3nma = fromCsvWithType([bm3, bm3], {}, NilMapArray); - test:assertEquals(bm3nma, [ - {b3: ()}, - {b3: ()} - ]); - - NilMapArray|CsvConversionError bm4nma = fromCsvWithType([bm4, bm4], {}, NilMapArray); - test:assertEquals(bm4nma, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - NilMapArray|CsvConversionError bm5nma = fromCsvWithType([bm5, bm5], {}, NilMapArray); - test:assertEquals(bm5nma, [ - {b3: ()}, - {b3: ()} - ]); - - JsonMapArray|CsvConversionError bm1jma = fromCsvWithType([bm1, bm1], {}, JsonMapArray); - test:assertEquals(bm1jma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - JsonMapArray|CsvConversionError bm2jma = fromCsvWithType([bm2, bm2], {}, JsonMapArray); - test:assertEquals(bm2jma, [ - {b1: true, b2: false, b3: (), n1: (), n3: ()}, - {b1: true, b2: false, b3: (), n1: (), n3: ()} - ]); - - JsonMapArray|CsvConversionError bm3jma = fromCsvWithType([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|CsvConversionError bm4jma = fromCsvWithType([bm4, bm4], {}, JsonMapArray); - test:assertEquals(bm4jma, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - - JsonMapArray|CsvConversionError bm5jma = fromCsvWithType([bm5, bm5], {}, JsonMapArray); - test:assertEquals(bm5jma, [ - {b1: true, b2: false, b4: true, b3: ()}, - {b1: true, b2: false, b4: true, b3: ()} - ]); - - AnydataMapArray|CsvConversionError bm1anydma = fromCsvWithType([bm1, bm1], {}, AnydataMapArray); - test:assertEquals(bm1anydma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - AnydataMapArray|CsvConversionError bm2anydma = fromCsvWithType([bm2, bm2], {}, AnydataMapArray); - test:assertEquals(bm2anydma, [ - {b1: true, b2: false, b3: (), n1: (), n3: ()}, - {b1: true, b2: false, b3: (), n1: (), n3: ()} - ]); - - AnydataMapArray|CsvConversionError bm3anydma = fromCsvWithType([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|CsvConversionError bm4anydma = fromCsvWithType([bm4, bm4], {}, AnydataMapArray); - test:assertEquals(bm4anydma, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - - AnydataMapArray|CsvConversionError bm5anydma = fromCsvWithType([bm5, bm5], {}, AnydataMapArray); - test:assertEquals(bm5anydma, [ - {b1: true, b2: false, b4: true, b3: ()}, - {b1: true, b2: false, b4: true, b3: ()} - ]); - - CustomMapArray|CsvConversionError bm1cma = fromCsvWithType([bm1, bm1], {}, CustomMapArray); - test:assertEquals(bm1cma, [ - {}, - {} - ]); - - CustomMapArray|CsvConversionError bm2cma = fromCsvWithType([bm2, bm2], {}, CustomMapArray); - test:assertEquals(bm2cma, [ - {}, - {} - ]); - - CustomMapArray|CsvConversionError bm3cma = fromCsvWithType([bm3, bm3], {}, CustomMapArray); - test:assertEquals(bm3cma, [ - {i1: 1}, - {i1: 1} - ]); - - CustomMapArray|CsvConversionError bm4cma = fromCsvWithType([bm4, bm4], {}, CustomMapArray); - test:assertEquals(bm4cma, [ - {}, - {} - ]); - - CustomMapArray|CsvConversionError bm5cma = fromCsvWithType([bm5, bm5], {}, CustomMapArray); - test:assertEquals(bm5cma, [ - {}, - {} - ]); - - StringMapArray|CsvConversionError bm1sma = fromCsvWithType([bm1, bm1], {}, StringMapArray); - test:assertEquals(bm1sma, [ - {}, - {} - ]); - - StringMapArray|CsvConversionError bm2sma = fromCsvWithType([bm2, bm2], {}, StringMapArray); - test:assertEquals(bm2sma, [ - {}, - {} - ]); - - StringMapArray|CsvConversionError bm3sma = fromCsvWithType([bm3, bm3], {}, StringMapArray); - test:assertEquals(bm3sma, [ - {}, - {} - ]); - - StringMapArray|CsvConversionError bm4sma = fromCsvWithType([bm4, bm4], {}, StringMapArray); - test:assertEquals(bm4sma, [ - {}, - {} - ]); - - StringMapArray|CsvConversionError bm5sma = fromCsvWithType([bm5, bm5], {}, StringMapArray); - test:assertEquals(bm5sma, [ - {}, - {} - ]); -} - -@test:Config {enable} -function testFromCsvWithTypeForMapAndArrayAsExpectedType() { - BooleanArrayArray|CsvConversionError bm1ba = fromCsvWithType([bm1, bm1], {}, BooleanArrayArray); - test:assertEquals(bm1ba, [ - [true, false], - [true, false] - ]); - - BooleanArrayArray|CsvConversionError bm2ba = fromCsvWithType([bm2, bm2], {}, BooleanArrayArray); - test:assertTrue(bm2ba is CsvConversionError); - test:assertEquals((bm2ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanArrayArray|CsvConversionError bm3ba = fromCsvWithType([bm3, bm3], {}, BooleanArrayArray); - test:assertTrue(bm3ba is CsvConversionError); - test:assertEquals((bm3ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanArrayArray|CsvConversionError bm4ba = fromCsvWithType([bm4, bm4], {}, BooleanArrayArray); - test:assertTrue(bm4ba is CsvConversionError); - test:assertEquals((bm4ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - - BooleanArrayArray|CsvConversionError bm5ba = fromCsvWithType([bm5, bm5], {}, BooleanArrayArray); - test:assertTrue(bm5ba is CsvConversionError); - test:assertEquals((bm5ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - NillableBooleanArrayArray|CsvConversionError bm1nba = fromCsvWithType([bm1, bm1], {}, NillableBooleanArrayArray); - test:assertEquals(bm1nba, [ - [true, false], - [true, false] - ]); - - NillableBooleanArrayArray|CsvConversionError bm2nba = fromCsvWithType([bm2, bm2], {}, NillableBooleanArrayArray); - test:assertEquals(bm2nba, [ - [true, false, null, null, null], - [true, false, null, null, null] - ]); - - NillableBooleanArrayArray|CsvConversionError bm3nba = fromCsvWithType([bm3, bm3], {}, NillableBooleanArrayArray); - test:assertTrue(bm3nba is CsvConversionError); - test:assertEquals((bm3nba).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - - NillableBooleanArrayArray|CsvConversionError bm4nba = fromCsvWithType([bm4, bm4], {}, NillableBooleanArrayArray); - test:assertEquals(bm4nba, [ - [(), ()], - [(), ()] - ]); - - NillableBooleanArrayArray|CsvConversionError bm5nba = fromCsvWithType([bm5, bm5], {}, NillableBooleanArrayArray); - test:assertEquals(bm5nba, [ - [true, false, (), true], - [true, false, (), true] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm1niouba = fromCsvWithType([bm1, bm1], {}, NillableIntOrUnionBooleanArrayArray); - test:assertEquals(bm1niouba, [ - [true, false], - [true, false] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm2niouba = fromCsvWithType([bm2, bm2], {}, NillableIntOrUnionBooleanArrayArray); - test:assertEquals(bm2niouba, [ - [true, false, null, null, null], - [true, false, null, null, null] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm3niouba = fromCsvWithType([bm3, bm3], {}, NillableIntOrUnionBooleanArrayArray); - test:assertEquals(bm3niouba, [ - [true, false, null, false, 1], - [true, false, null, false, 1] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm4niouba = fromCsvWithType([bm4, bm4], {}, NillableIntOrUnionBooleanArrayArray); - test:assertEquals(bm4niouba, [ - [(), ()], - [(), ()] - ]); - - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm5niouba = fromCsvWithType([bm5, bm5], {}, NillableIntOrUnionBooleanArrayArray); - test:assertEquals(bm5niouba, [ - [true, false, (), true], - [true, false, (), true] - ]); - - JsonArray1Array|CsvConversionError bm1ja = fromCsvWithType([bm1, bm1], {}, JsonArray1Array); - test:assertEquals(bm1ja, [ - [true, false], - [true, false] - ]); - - JsonArray1Array|CsvConversionError bm2ja = fromCsvWithType([bm2, bm2], {}, JsonArray1Array); - test:assertEquals(bm2ja, [ - [true, false, null, null, null], - [true, false, null, null, null] - ]); - - JsonArray1Array|CsvConversionError bm3ja = fromCsvWithType([bm3, bm3], {}, JsonArray1Array); - test:assertEquals(bm3ja, [ - [true, false, null, false, 1], - [true, false, null, false, 1] - ]); - - JsonArray1Array|CsvConversionError bm4ja = fromCsvWithType([bm4, bm4], {}, JsonArray1Array); - test:assertEquals(bm4ja, [ - [(), ()], - [(), ()] - ]); - - JsonArray1Array|CsvConversionError bm5ja = fromCsvWithType([bm5, bm5], {}, JsonArray1Array); - test:assertEquals(bm5ja, [ - [true, false, (), true], - [true, false, (), true] - ]); - - AnydataArray1Array|CsvConversionError bm1anyda = fromCsvWithType([bm1, bm1], {}, AnydataArray1Array); - test:assertEquals(bm1anyda, [ - [true, false], - [true, false] - ]); - - AnydataArray1Array|CsvConversionError bm2anyda = fromCsvWithType([bm2, bm2], {}, AnydataArray1Array); - test:assertEquals(bm2anyda, [ - [true, false, null, null, null], - [true, false, null, null, null] - ]); - - AnydataArray1Array|CsvConversionError bm3anyda = fromCsvWithType([bm3, bm3], {}, AnydataArray1Array); - test:assertEquals(bm3anyda, [ - [true, false, null, false, 1], - [true, false, null, false, 1] - ]); - - AnydataArray1Array|CsvConversionError bm4anyda = fromCsvWithType([bm4, bm4], {}, AnydataArray1Array); - test:assertEquals(bm4anyda, [ - [(), ()], - [(), ()] - ]); - - AnydataArray1Array|CsvConversionError bm5anyda = fromCsvWithType([bm5, bm5], {}, AnydataArray1Array); - test:assertEquals(bm5anyda, [ - [true, false, (), true], - [true, false, (), true] - ]); - - StringArray1Array|CsvConversionError bm1sa = fromCsvWithType([bm1, bm1], {}, StringArray1Array); - test:assertTrue(bm1sa is CsvConversionError); - test:assertEquals((bm1sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringArray1Array|CsvConversionError bm2sa = fromCsvWithType([bm2, bm2], {}, StringArray1Array); - test:assertTrue(bm2sa is CsvConversionError); - test:assertEquals((bm2sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringArray1Array|CsvConversionError bm3sa = fromCsvWithType([bm3, bm3], {}, StringArray1Array); - test:assertTrue(bm3sa is CsvConversionError); - test:assertEquals((bm3sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringArray1Array|CsvConversionError bm4sa = fromCsvWithType([bm4, bm4], {}, StringArray1Array); - test:assertTrue(bm4sa is CsvConversionError); - test:assertEquals((bm4sa).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - - StringArray1Array|CsvConversionError bm5sa = fromCsvWithType([bm5, bm5], {}, StringArray1Array); - test:assertTrue(bm5sa is CsvConversionError); - test:assertEquals((bm5sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); -} - -@test:Config {enable} -function testFromCsvWithTypeForMapAndTupleAsExpectedType() { - BooleanTuple1Array|CsvConversionError bm1bt = fromCsvWithType([bm1, bm1], {}, BooleanTuple1Array); - test:assertEquals(bm1bt, [ - [true, false, false, false], - [true, false, false, false] - ]); - - BooleanTuple1Array|CsvConversionError bm2bt = fromCsvWithType([bm2, bm2], {}, BooleanTuple1Array); - test:assertTrue(bm2bt is CsvConversionError); - test:assertEquals((bm2bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple1Array|CsvConversionError bm3bt = fromCsvWithType([bm3, bm3], {}, BooleanTuple1Array); - test:assertTrue(bm3bt is CsvConversionError); - test:assertEquals((bm3bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple1Array|CsvConversionError bm4bt = fromCsvWithType([bm4, bm4], {}, BooleanTuple1Array); - test:assertTrue(bm4bt is CsvConversionError); - test:assertEquals((bm4bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - - BooleanTuple1Array|CsvConversionError bm5bt = fromCsvWithType([bm5, bm5], {}, BooleanTuple1Array); - test:assertTrue(bm5bt is CsvConversionError); - test:assertEquals((bm5bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple2Array|CsvConversionError bm1b2t = fromCsvWithType([bm1, bm1], {}, BooleanTuple2Array); - test:assertEquals(bm1b2t, [ - [true, false], - [true, false] - ]); - - BooleanTuple2Array|CsvConversionError bm2b2t = fromCsvWithType([bm2, bm2], {}, BooleanTuple2Array); - test:assertEquals(bm2b2t, [ - [true, false], - [true, false] - ]); - - BooleanTuple2Array|CsvConversionError bm3b2t = fromCsvWithType([bm3, bm3], {}, BooleanTuple2Array); - test:assertEquals(bm3b2t, [ - [true, false], - [true, false] - ]); - - BooleanTuple2Array|CsvConversionError bm4b2t = fromCsvWithType([bm4, bm4], {}, BooleanTuple2Array); - test:assertTrue(bm4b2t is CsvConversionError); - test:assertEquals((bm4b2t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - - BooleanTuple2Array|CsvConversionError bm5b2t = fromCsvWithType([bm5, bm5], {}, BooleanTuple2Array); - test:assertEquals(bm5b2t, [ - [true, false], - [true, false] - ]); - - BooleanTuple3Array|CsvConversionError bm1b3t = fromCsvWithType([bm1, bm1], {}, BooleanTuple3Array); - test:assertEquals(bm1b3t, [ - [true, false], - [true, false] - ]); - - BooleanTuple3Array|CsvConversionError bm2b3t = fromCsvWithType([bm2, bm2], {}, BooleanTuple3Array); - test:assertTrue(bm2b3t is CsvConversionError); - test:assertEquals((bm2b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple3Array|CsvConversionError bm3b3t = fromCsvWithType([bm3, bm3], {}, BooleanTuple3Array); - test:assertTrue(bm3b3t is CsvConversionError); - test:assertEquals((bm3b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple3Array|CsvConversionError bm4b3t = fromCsvWithType([bm4, bm4], {}, BooleanTuple3Array); - test:assertTrue(bm4b3t is CsvConversionError); - test:assertEquals((bm4b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - - BooleanTuple3Array|CsvConversionError bm5b3t = fromCsvWithType([bm5, bm5], {}, BooleanTuple3Array); - test:assertTrue(bm5b3t is CsvConversionError); - test:assertEquals((bm5b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple4Array|CsvConversionError bm1b4t = fromCsvWithType([bm1, bm1], {}, BooleanTuple4Array); - test:assertEquals(bm1b4t, [ - [true, false], - [true, false] - ]); - - BooleanTuple4Array|CsvConversionError bm2b4t = fromCsvWithType([bm2, bm2], {}, BooleanTuple4Array); - test:assertTrue(bm2b4t is CsvConversionError); - test:assertEquals((bm2b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple4Array|CsvConversionError bm3b4t = fromCsvWithType([bm3, bm3], {}, BooleanTuple4Array); - test:assertTrue(bm3b4t is CsvConversionError); - test:assertEquals((bm3b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple4Array|CsvConversionError bm4b4t = fromCsvWithType([bm4, bm4], {}, BooleanTuple4Array); - test:assertTrue(bm4b4t is CsvConversionError); - test:assertEquals((bm4b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - - BooleanTuple4Array|CsvConversionError bm5b4t = fromCsvWithType([bm5, bm5], {}, BooleanTuple4Array); - test:assertTrue(bm5b4t is CsvConversionError); - test:assertEquals((bm5b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - NillableBooleanTuple5Array|CsvConversionError bm1nbt = fromCsvWithType([bm1, bm1], {}, NillableBooleanTuple5Array); - test:assertEquals(bm1nbt, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - NillableBooleanTuple5Array|CsvConversionError bm2nbt = fromCsvWithType([bm2, bm2], {}, NillableBooleanTuple5Array); - test:assertEquals(bm2nbt, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - NillableBooleanTuple5Array|CsvConversionError bm3nbt = fromCsvWithType([bm3, bm3], {}, NillableBooleanTuple5Array); - test:assertTrue(bm3nbt is CsvConversionError); - test:assertEquals((bm3nbt).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - - NillableBooleanTuple5Array|CsvConversionError bm4nbt = fromCsvWithType([bm4, bm4], {}, NillableBooleanTuple5Array); - test:assertEquals(bm4nbt, [ - [(), (), (), (), ()], - [(), (), (), (), ()] - ]); - - NillableBooleanTuple5Array|CsvConversionError bm5nbt = fromCsvWithType([bm5, bm5], {}, NillableBooleanTuple5Array); - test:assertEquals(bm5nbt, [ - [true, false, (), true, ()], - [true, false, (), true, ()] - ]); - - NillableBooleanTuple6Array|CsvConversionError bm1nb6t = fromCsvWithType([bm1, bm1], {}, NillableBooleanTuple6Array); - test:assertEquals(bm1nb6t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple6Array|CsvConversionError bm2nb6t = fromCsvWithType([bm2, bm2], {}, NillableBooleanTuple6Array); - test:assertEquals(bm2nb6t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple6Array|CsvConversionError bm3nb6t = fromCsvWithType([bm3, bm3], {}, NillableBooleanTuple6Array); - test:assertEquals(bm3nb6t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple6Array|CsvConversionError bm4nb6t = fromCsvWithType([bm4, bm4], {}, NillableBooleanTuple6Array); - test:assertEquals(bm4nb6t, [ - [(), ()], - [(), ()] - ]); - - NillableBooleanTuple6Array|CsvConversionError bm5nb6t = fromCsvWithType([bm5, bm5], {}, NillableBooleanTuple6Array); - test:assertEquals(bm5nb6t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple7Array|CsvConversionError bm1nb7t = fromCsvWithType([bm1, bm1], {}, NillableBooleanTuple7Array); - test:assertEquals(bm1nb7t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple7Array|CsvConversionError bm2nb7t = fromCsvWithType([bm2, bm2], {}, NillableBooleanTuple7Array); - test:assertEquals(bm2nb7t, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - NillableBooleanTuple7Array|CsvConversionError bm3nb7t = fromCsvWithType([bm3, bm3], {}, NillableBooleanTuple7Array); - test:assertTrue(bm3nb7t is CsvConversionError); - test:assertEquals((bm3nb7t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - - NillableBooleanTuple7Array|CsvConversionError bm4nb7t = fromCsvWithType([bm4, bm4], {}, NillableBooleanTuple7Array); - test:assertEquals(bm4nb7t, [ - [(), ()], - [(), ()] - ]); - - NillableBooleanTuple7Array|CsvConversionError bm5nb7t = fromCsvWithType([bm5, bm5], {}, NillableBooleanTuple7Array); - test:assertEquals(bm5nb7t, [ - [true, false, (), true], - [true, false, (), true] - ]); - - NillableBooleanTuple8Array|CsvConversionError bm1nb8t = fromCsvWithType([bm1, bm1], {}, NillableBooleanTuple8Array); - test:assertEquals(bm1nb8t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple8Array|CsvConversionError bm2nb8t = fromCsvWithType([bm2, bm2], {}, NillableBooleanTuple8Array); - test:assertEquals(bm2nb8t, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - NillableBooleanTuple8Array|CsvConversionError bm3nb8t = fromCsvWithType([bm3, bm3], {}, NillableBooleanTuple8Array); - test:assertTrue(bm3nb8t is CsvConversionError); - test:assertEquals((bm3nb8t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - - NillableBooleanTuple8Array|CsvConversionError bm4nb8t = fromCsvWithType([bm4, bm4], {}, NillableBooleanTuple8Array); - test:assertEquals(bm4nb8t, [ - [(), ()], - [(), ()] - ]); - - NillableBooleanTuple8Array|CsvConversionError bm5nb8t = fromCsvWithType([bm5, bm5], {}, NillableBooleanTuple8Array); - test:assertEquals(bm5nb8t, [ - [true, false, (), true], - [true, false, (), true] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError bm1nb9t = fromCsvWithType([bm1, bm1], {}, NillableIntBooleanTuple9Array); - test:assertEquals(bm1nb9t, [ - [true, false], - [true, false] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError bm2nb9t = fromCsvWithType([bm2, bm2], {}, NillableIntBooleanTuple9Array); - test:assertEquals(bm2nb9t, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError bm3nb9t = fromCsvWithType([bm3, bm3], {}, NillableIntBooleanTuple9Array); - test:assertEquals(bm3nb9t, [ - [true, false, (), false, 1], - [true, false, (), false, 1] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError bm4nb9t = fromCsvWithType([bm4, bm4], {}, NillableIntBooleanTuple9Array); - test:assertEquals(bm4nb9t, [ - [(), ()], - [(), ()] - ]); - - NillableIntBooleanTuple9Array|CsvConversionError bm5nb9t = fromCsvWithType([bm5, bm5], {}, NillableIntBooleanTuple9Array); - test:assertEquals(bm5nb9t, [ - [true, false, (), true], - [true, false, (), true] - ]); - - NilTuple3Array|CsvConversionError bm1n3t = fromCsvWithType([bm1, bm1], {}, NilTuple3Array); - test:assertTrue(bm1n3t is CsvConversionError); - test:assertEquals((bm1n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - - NilTuple3Array|CsvConversionError bm2n3t = fromCsvWithType([bm2, bm2], {}, NilTuple3Array); - test:assertTrue(bm2n3t is CsvConversionError); - test:assertEquals((bm2n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - - NilTuple3Array|CsvConversionError bm3n3t = fromCsvWithType([bm3, bm3], {}, NilTuple3Array); - test:assertTrue(bm3n3t is CsvConversionError); - test:assertEquals((bm3n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - - NilTuple3Array|CsvConversionError bm4n3t = fromCsvWithType([bm4, bm4], {}, NilTuple3Array); - test:assertEquals(bm4n3t, [ - [(), ()], - [(), ()] - ]); - - NilTuple3Array|CsvConversionError bm5n3t = fromCsvWithType([bm5, bm5], {}, NilTuple3Array); - test:assertTrue(bm5n3t is CsvConversionError); - test:assertEquals((bm5n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - - AnydataTuple3Array|CsvConversionError bm1anyd3t = fromCsvWithType([bm1, bm1], {}, AnydataTuple3Array); - test:assertEquals(bm1anyd3t, [ - [true, false], - [true, false] - ]); - - AnydataTuple3Array|CsvConversionError bm2anyd3t = fromCsvWithType([bm2, bm2], {}, AnydataTuple3Array); - test:assertEquals(bm2anyd3t, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - AnydataTuple3Array|CsvConversionError bm3anyd3t = fromCsvWithType([bm3, bm3], {}, AnydataTuple3Array); - test:assertEquals(bm3anyd3t, [ - [true, false, (), false, 1], - [true, false, (), false, 1] - ]); - - AnydataTuple3Array|CsvConversionError bm4anyd3t = fromCsvWithType([bm4, bm4], {}, AnydataTuple3Array); - test:assertEquals(bm4anyd3t, [ - [(), ()], - [(), ()] - ]); - - AnydataTuple3Array|CsvConversionError bm5anyd3t = fromCsvWithType([bm5, bm5], {}, AnydataTuple3Array); - test:assertEquals(bm5anyd3t, [ - [true, false, (), true], - [true, false, (), true] - ]); - - JsonTuple3Array|CsvConversionError bm1j3t = fromCsvWithType([bm1, bm1], {}, JsonTuple3Array); - test:assertEquals(bm1j3t, [ - [true, false], - [true, false] - ]); - - JsonTuple3Array|CsvConversionError bm2j3t = fromCsvWithType([bm2, bm2], {}, JsonTuple3Array); - test:assertEquals(bm2j3t, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - JsonTuple3Array|CsvConversionError bm3j3t = fromCsvWithType([bm3, bm3], {}, JsonTuple3Array); - test:assertEquals(bm3j3t, [ - [true, false, (), false, 1], - [true, false, (), false, 1] - ]); - - JsonTuple3Array|CsvConversionError bm4j3t = fromCsvWithType([bm4, bm4], {}, JsonTuple3Array); - test:assertEquals(bm4j3t, [ - [(), ()], - [(), ()] - ]); - - JsonTuple3Array|CsvConversionError bm5j3t = fromCsvWithType([bm5, bm5], {}, JsonTuple3Array); - test:assertEquals(bm5j3t, [ - [true, false, (), true], - [true, false, (), true] - ]); - - StringTuple3Array|CsvConversionError bm1s3t = fromCsvWithType([bm1, bm1], {}, StringTuple3Array); - test:assertTrue(bm1s3t is CsvConversionError); - test:assertEquals((bm1s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringTuple3Array|CsvConversionError bm2s3t = fromCsvWithType([bm2, bm2], {}, StringTuple3Array); - test:assertTrue(bm2s3t is CsvConversionError); - test:assertEquals((bm2s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringTuple3Array|CsvConversionError bm3s3t = fromCsvWithType([bm3, bm3], {}, StringTuple3Array); - test:assertTrue(bm3s3t is CsvConversionError); - test:assertEquals((bm3s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringTuple3Array|CsvConversionError bm4s3t = fromCsvWithType([bm4, bm4], {}, StringTuple3Array); - test:assertTrue(bm4s3t is CsvConversionError); - test:assertEquals((bm4s3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - - StringTuple3Array|CsvConversionError bm5s3t = fromCsvWithType([bm5, bm5], {}, StringTuple3Array); - test:assertTrue(bm5s3t is CsvConversionError); - test:assertEquals((bm5s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); -} - -@test:Config {enable} -function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { - StringRecord1Array|CsvConversionError st1sr1 = fromCsvWithType([st1, st1], {}, StringRecord1Array); - test:assertTrue(st1sr1 is CsvConversionError); - test:assertEquals((st1sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - - StringRecord1Array|CsvConversionError st2sr1 = fromCsvWithType([st2, st2], {}, StringRecord1Array); - test:assertTrue(st2sr1 is CsvConversionError); - test:assertEquals((st2sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - - StringRecord2Array|CsvConversionError st1sr2 = fromCsvWithType([st1, st1], {}, StringRecord2Array); - test:assertTrue(st1sr2 is CsvConversionError); - test:assertEquals((st1sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); - - StringRecord2Array|CsvConversionError st2sr2 = fromCsvWithType([st2, st2], {}, StringRecord2Array); - test:assertTrue(st2sr2 is CsvConversionError); - test:assertEquals((st2sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); - - StringRecord9Array|CsvConversionError st1sr9 = fromCsvWithType([st1, st1], {}, StringRecord9Array); - test:assertTrue(st1sr9 is CsvConversionError); - test:assertEquals((st1sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord9")); - - StringRecord9Array|CsvConversionError st2sr9 = fromCsvWithType([st2, st2], {}, StringRecord9Array); - test:assertTrue(st2sr9 is CsvConversionError); - test:assertEquals((st2sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord9")); - - StringRecord10Array|CsvConversionError st1sr10 = fromCsvWithType([st1, st1], {}, StringRecord10Array); - test:assertEquals(st1sr10, [ - {'1: "string", '2: ""}, - {'1: "string", '2: ""} - ]); - - StringRecord10Array|CsvConversionError st2sr10 = fromCsvWithType([st2, st2], {}, StringRecord10Array); - test:assertEquals(st2sr10, [ - {'1: "string", '2: "", '3: "a", '4: ""}, - {'1: "string", '2: "", '3: "a", '4: ""} - ]); - - StringRecord19Array|CsvConversionError st1sr19 = fromCsvWithType([st1, st1], {}, StringRecord19Array); - test:assertEquals(st1sr19, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord19Array|CsvConversionError st2sr19 = fromCsvWithType([st2, st2], {}, StringRecord19Array); - test:assertEquals(st2sr19, [ - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord20Array|CsvConversionError st1sr20 = fromCsvWithType([st1, st1], {}, StringRecord20Array); - test:assertEquals(st1sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord20Array|CsvConversionError st2sr20 = fromCsvWithType([st2, st2], {}, StringRecord20Array); - test:assertEquals(st2sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord21Array|CsvConversionError st1sr21 = fromCsvWithType([st1, st1], {}, StringRecord21Array); - test:assertEquals(st1sr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord21Array|CsvConversionError st2sr21 = fromCsvWithType([st2, st2], {}, StringRecord21Array); - test:assertEquals(st2sr21, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord22Array|CsvConversionError st1sr22 = fromCsvWithType([st1, st1], {}, StringRecord22Array); - test:assertEquals(st1sr22, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord22Array|CsvConversionError st2sr22 = fromCsvWithType([st2, st2], {}, StringRecord22Array); - test:assertEquals(st2sr22, [ - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord23Array|CsvConversionError st1sr23 = fromCsvWithType([st1, st1], {}, StringRecord23Array); - test:assertEquals(st1sr23, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord23Array|CsvConversionError st2sr23 = fromCsvWithType([st2, st2], {}, StringRecord23Array); - test:assertEquals(st2sr23, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord15Array|CsvConversionError st1cr15 = fromCsvWithType([st1, st1], {}, CustomRecord15Array); - test:assertEquals(st1cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord15Array|CsvConversionError st2cr15 = fromCsvWithType([st2, st2], {}, CustomRecord15Array); - test:assertEquals(st2cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord16Array|CsvConversionError st1cr16 = fromCsvWithType([st1, st1], {}, CustomRecord16Array); - test:assertTrue(st1cr16 is CsvConversionError); - test:assertEquals((st1cr16).message(), generateErrorMessageForMissingRequiredField("3")); - - CustomRecord16Array|CsvConversionError st2cr16 = fromCsvWithType([st2, st2], {}, CustomRecord16Array); - test:assertEquals(st2cr16, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord17Array|CsvConversionError st1cr17 = fromCsvWithType([st1, st1], {}, CustomRecord17Array); - test:assertEquals(st1cr17, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord17Array|CsvConversionError st2cr17 = fromCsvWithType([st2, st2], {}, CustomRecord17Array); - test:assertEquals(st2cr17, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord18Array|CsvConversionError st1cr18 = fromCsvWithType([st1, st1], {}, CustomRecord18Array); - test:assertTrue(st1cr18 is CsvConversionError); - test:assertEquals((st1cr18).message(), generateErrorMessageForMissingRequiredField("3")); - - CustomRecord18Array|CsvConversionError st2cr18 = fromCsvWithType([st2, st2], {}, CustomRecord18Array); - test:assertEquals(st2cr18, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord19Array|CsvConversionError st1cr19 = fromCsvWithType([st1, st1], {}, CustomRecord19Array); - test:assertEquals(st1cr19, [ - {'1: s1, '2: s2, '3: "", '4: ""}, - {'1: s1, '2: s2, '3: "", '4: ""} - ]); - - CustomRecord19Array|CsvConversionError st2cr19 = fromCsvWithType([st2, st2], {}, CustomRecord19Array); - test:assertEquals(st2cr19, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord20Array|CsvConversionError st1cr20 = fromCsvWithType([st1, st1], {}, CustomRecord20Array); - test:assertEquals(st1cr20, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord20Array|CsvConversionError st2cr20 = fromCsvWithType([st2, st2], {}, CustomRecord20Array); - test:assertEquals(st2cr20, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord21Array|CsvConversionError st1cr21 = fromCsvWithType([st1, st1], {}, CustomRecord21Array); - test:assertEquals(st1cr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord21Array|CsvConversionError st2cr21 = fromCsvWithType([st2, st2], {}, CustomRecord21Array); - test:assertEquals(st2cr21, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord22Array|CsvConversionError st1cr22 = fromCsvWithType([st1, st1], {}, CustomRecord22Array); - test:assertEquals(st1cr22, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord22Array|CsvConversionError st2cr22 = fromCsvWithType([st2, st2], {}, CustomRecord22Array); - test:assertEquals(st2cr22, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord23Array|CsvConversionError st1cr23 = fromCsvWithType([st1, st1], {}, CustomRecord23Array); - test:assertEquals(st1cr23, [ - {"1": s1, "2": s2, a: ""}, - {"1": s1, "2": s2, a: ""} - ]); - - CustomRecord23Array|CsvConversionError st2cr23 = fromCsvWithType([st2, st2], {}, CustomRecord23Array); - test:assertEquals(st2cr23, [ - {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, - {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} - ]); - - CustomRecord24Array|CsvConversionError st1cr24 = fromCsvWithType([st1, st1], {}, CustomRecord24Array); - test:assertEquals(st1cr24, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord24Array|CsvConversionError st2cr24 = fromCsvWithType([st2, st2], {}, CustomRecord24Array); - test:assertEquals(st2cr24, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord25Array|CsvConversionError st1cr25 = fromCsvWithType([st1, st1], {}, CustomRecord25Array); - test:assertTrue(st1cr25 is CsvConversionError); - test:assertEquals((st1cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:CustomRecord25")); - - CustomRecord25Array|CsvConversionError st2cr25 = fromCsvWithType([st2, st2], {}, CustomRecord25Array); - test:assertTrue(st2cr25 is CsvConversionError); - test:assertEquals((st2cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:CustomRecord25")); - - CustomRecord25Array|CsvConversionError st3cr25 = fromCsvWithType([st3, st3], {}, CustomRecord25Array); - test:assertTrue(st3cr25 is CsvConversionError); - test:assertEquals((st3cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:CustomRecord25")); - - CustomRecord25Array|CsvConversionError st4cr25 = fromCsvWithType([st4, st4], {}, CustomRecord25Array); - test:assertTrue(st4cr25 is CsvConversionError); - test:assertEquals((st4cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:CustomRecord25")); - - CustomRecord26Array|CsvConversionError st1cr26 = fromCsvWithType([st1, st1], {}, CustomRecord26Array); - test:assertEquals(st1cr26 , [ - {'1: s1}, - {'1: s1} - ]); - - CustomRecord26Array|CsvConversionError st2cr26 = fromCsvWithType([st2, st2], {}, CustomRecord26Array); - test:assertEquals(st2cr26 , [ - {'1: s1}, - {'1: s1} - ]); - - CustomRecord26Array|CsvConversionError st3cr26 = fromCsvWithType([st3, st3], {}, CustomRecord26Array); - test:assertEquals(st3cr26 , [ - {'1: s1}, - {'1: s1} - ]); - - CustomRecord26Array|CsvConversionError st4cr26 = fromCsvWithType([st4, st4], {}, CustomRecord26Array); - test:assertEquals(st4cr26 , [ - {'1: s1}, - {'1: s1} - ]); -} - -@test:Config {enable} -function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { - StringRecord1Array|CsvConversionError st3sr1 = fromCsvWithType([st3, st3], {}, StringRecord1Array); - test:assertTrue(st3sr1 is CsvConversionError); - test:assertEquals((st3sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - - StringRecord1Array|CsvConversionError st4sr1 = fromCsvWithType([st4, st4], {}, StringRecord1Array); - test:assertTrue(st4sr1 is CsvConversionError); - test:assertEquals((st4sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - - StringRecord2Array|CsvConversionError st3sr2 = fromCsvWithType([st3, st3], {}, StringRecord2Array); - test:assertTrue(st3sr2 is CsvConversionError); - test:assertEquals((st3sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); - - StringRecord2Array|CsvConversionError st4sr2 = fromCsvWithType([st4, st4], {}, StringRecord2Array); - test:assertTrue(st4sr2 is CsvConversionError); - test:assertEquals((st4sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); - - StringRecord9Array|CsvConversionError st3sr9 = fromCsvWithType([st3, st3], {}, StringRecord9Array); - test:assertTrue(st3sr9 is CsvConversionError); - test:assertEquals((st3sr9).message(), generateErrorMessageForMissingRequiredField("s1")); - - StringRecord9Array|CsvConversionError st4sr9 = fromCsvWithType([st4, st4], {}, StringRecord9Array); - test:assertTrue(st4sr9 is CsvConversionError); - test:assertEquals((st4sr9).message(), generateErrorMessageForMissingRequiredField("s1")); - - StringRecord10Array|CsvConversionError st3sr10 = fromCsvWithType([st3, st3], {}, StringRecord10Array); - test:assertEquals(st3sr10, [ - {'1: "string", '2: ""}, - {'1: "string", '2: ""} - ]); - - StringRecord10Array|CsvConversionError st4sr10 = fromCsvWithType([st4, st4], {}, StringRecord10Array); - test:assertEquals(st4sr10, [ - {'1: "string", '2: "", '3: "a", '4: ""}, - {'1: "string", '2: "", '3: "a", '4: ""} - ]); - - StringRecord19Array|CsvConversionError st3sr19 = fromCsvWithType([st3, st3], {}, StringRecord19Array); - test:assertEquals(st3sr19, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord19Array|CsvConversionError st4sr19 = fromCsvWithType([st4, st4], {}, StringRecord19Array); - test:assertEquals(st4sr19, [ - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord20Array|CsvConversionError st3sr20 = fromCsvWithType([st3, st3], {}, StringRecord20Array); - test:assertEquals(st3sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord20Array|CsvConversionError st4sr20 = fromCsvWithType([st4, st4], {}, StringRecord20Array); - test:assertEquals(st4sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord21Array|CsvConversionError st3sr21 = fromCsvWithType([st3, st3], {}, StringRecord21Array); - test:assertEquals(st3sr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord21Array|CsvConversionError st4sr21 = fromCsvWithType([st4, st4], {}, StringRecord21Array); - test:assertEquals(st4sr21, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord22Array|CsvConversionError st3sr22 = fromCsvWithType([st3, st3], {}, StringRecord22Array); - test:assertEquals(st3sr22, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord22Array|CsvConversionError st4sr22 = fromCsvWithType([st4, st4], {}, StringRecord22Array); - test:assertEquals(st4sr22, [ - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord23Array|CsvConversionError st3sr23 = fromCsvWithType([st3, st3], {}, StringRecord23Array); - test:assertEquals(st3sr23, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord23Array|CsvConversionError st4sr23 = fromCsvWithType([st4, st4], {}, StringRecord23Array); - test:assertEquals(st4sr23, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord15Array|CsvConversionError st3cr15 = fromCsvWithType([st3, st3], {}, CustomRecord15Array); - test:assertEquals(st3cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord15Array|CsvConversionError st4cr15 = fromCsvWithType([st4, st4], {}, CustomRecord15Array); - test:assertEquals(st4cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord16Array|CsvConversionError st3cr16 = fromCsvWithType([st3, st3], {}, CustomRecord16Array); - test:assertTrue(st3cr16 is CsvConversionError); - test:assertEquals((st3cr16).message(), generateErrorMessageForMissingRequiredField("3")); - - CustomRecord16Array|CsvConversionError st4cr16 = fromCsvWithType([st4, st4], {}, CustomRecord16Array); - test:assertEquals(st4cr16, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord17Array|CsvConversionError st3cr17 = fromCsvWithType([st3, st3], {}, CustomRecord17Array); - test:assertEquals(st3cr17, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord17Array|CsvConversionError st4cr17 = fromCsvWithType([st4, st4], {}, CustomRecord17Array); - test:assertEquals(st4cr17, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord18Array|CsvConversionError st3cr18 = fromCsvWithType([st3, st3], {}, CustomRecord18Array); - test:assertTrue(st3cr18 is CsvConversionError); - test:assertEquals((st3cr18).message(), generateErrorMessageForMissingRequiredField("3")); - - CustomRecord18Array|CsvConversionError st4cr18 = fromCsvWithType([st4, st4], {}, CustomRecord18Array); - test:assertEquals(st4cr18, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord19Array|CsvConversionError st3cr19 = fromCsvWithType([st3, st3], {}, CustomRecord19Array); - test:assertEquals(st3cr19, [ - {'1: s1, '2: s2, '3: "", '4: ""}, - {'1: s1, '2: s2, '3: "", '4: ""} - ]); - - CustomRecord19Array|CsvConversionError st4cr19 = fromCsvWithType([st4, st4], {}, CustomRecord19Array); - test:assertEquals(st4cr19, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord20Array|CsvConversionError st3cr20 = fromCsvWithType([st3, st3], {}, CustomRecord20Array); - test:assertEquals(st3cr20, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord20Array|CsvConversionError st4cr20 = fromCsvWithType([st4, st4], {}, CustomRecord20Array); - test:assertEquals(st4cr20, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord21Array|CsvConversionError st3cr21 = fromCsvWithType([st3, st3], {}, CustomRecord21Array); - test:assertEquals(st3cr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord21Array|CsvConversionError st4cr21 = fromCsvWithType([st4, st4], {}, CustomRecord21Array); - test:assertEquals(st4cr21, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord22Array|CsvConversionError st3cr22 = fromCsvWithType([st3, st3], {}, CustomRecord22Array); - test:assertEquals(st3cr22, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord22Array|CsvConversionError st4cr22 = fromCsvWithType([st4, st4], {}, CustomRecord22Array); - test:assertEquals(st4cr22, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord23Array|CsvConversionError st3cr23 = fromCsvWithType([st3, st3], {}, CustomRecord23Array); - test:assertEquals(st3cr23, [ - {"1": s1, "2": s2, a: ""}, - {"1": s1, "2": s2, a: ""} - ]); - - CustomRecord23Array|CsvConversionError st4cr23 = fromCsvWithType([st4, st4], {}, CustomRecord23Array); - test:assertEquals(st4cr23, [ - {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, - {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} - ]); - - CustomRecord24Array|CsvConversionError st3cr24 = fromCsvWithType([st3, st3], {}, CustomRecord24Array); - test:assertEquals(st3cr24, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord24Array|CsvConversionError st4cr24 = fromCsvWithType([st4, st4], {}, CustomRecord24Array); - test:assertEquals(st4cr24, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); -} - -@test:Config {enable} -function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { - StringTuple1Array|CsvConversionError st1st1 = fromCsvWithType([st1, st1], {}, StringTuple1Array); - test:assertEquals(st1st1, [ - [s1, s2, "", ""], - [s1, s2, "", ""] - ]); - - StringTuple1Array|CsvConversionError st2st1 = fromCsvWithType([st2, st2], {}, StringTuple1Array); - test:assertEquals(st2st1, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - StringTuple1Array|CsvConversionError st3st1 = fromCsvWithType([st3, st3], {}, StringTuple1Array); - test:assertEquals(st3st1, [ - [s1, s2, "", ""], - [s1, s2, "", ""] - ]); - - StringTuple1Array|CsvConversionError st4st1 = fromCsvWithType([st4, st4], {}, StringTuple1Array); - test:assertEquals(st4st1, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringTuple2Array|CsvConversionError st1st2 = fromCsvWithType([st1, st1], {}, StringTuple2Array); - test:assertEquals(st1st2, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple2Array|CsvConversionError st2st2 = fromCsvWithType([st2, st2], {}, StringTuple2Array); - test:assertEquals(st2st2, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple2Array|CsvConversionError st3st2 = fromCsvWithType([st3, st3], {}, StringTuple2Array); - test:assertEquals(st3st2, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple2Array|CsvConversionError st4st2 = fromCsvWithType([st4, st4], {}, StringTuple2Array); - test:assertEquals(st4st2, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple3Array|CsvConversionError st1st3 = fromCsvWithType([st1, st1], {}, StringTuple3Array); - test:assertEquals(st1st3, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple3Array|CsvConversionError st2st3 = fromCsvWithType([st2, st2], {}, StringTuple3Array); - test:assertEquals(st2st3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringTuple3Array|CsvConversionError st3st3 = fromCsvWithType([st3, st3], {}, StringTuple3Array); - test:assertEquals(st3st3, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple3Array|CsvConversionError st4st3 = fromCsvWithType([st4, st4], {}, StringTuple3Array); - test:assertEquals(st4st3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringTuple4Array|CsvConversionError st1st4 = fromCsvWithType([st1, st1], {}, StringTuple4Array); - test:assertEquals(st1st4, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple4Array|CsvConversionError st2st4 = fromCsvWithType([st2, st2], {}, StringTuple4Array); - test:assertEquals(st2st4, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringTuple4Array|CsvConversionError st3st4 = fromCsvWithType([st3, st3], {}, StringTuple4Array); - test:assertEquals(st3st4, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple4Array|CsvConversionError st4st4 = fromCsvWithType([st4, st4], {}, StringTuple4Array); - test:assertEquals(st4st4, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - AnydataTuple3Array|CsvConversionError st1anydt3 = fromCsvWithType([st1, st1], {}, AnydataTuple3Array); - test:assertEquals(st1anydt3, [ - [s1, s2], - [s1, s2] - ]); - - AnydataTuple3Array|CsvConversionError st2anydt3 = fromCsvWithType([st2, st2], {}, AnydataTuple3Array); - test:assertEquals(st2anydt3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - AnydataTuple3Array|CsvConversionError st3anydt3 = fromCsvWithType([st3, st3], {}, AnydataTuple3Array); - test:assertEquals(st3anydt3, [ - [s1, s2], - [s1, s2] - ]); - - AnydataTuple3Array|CsvConversionError st4anydt3 = fromCsvWithType([st4, st4], {}, AnydataTuple3Array); - test:assertEquals(st4anydt3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - JsonTuple3Array|CsvConversionError st1jt3 = fromCsvWithType([st1, st1], {}, JsonTuple3Array); - test:assertEquals(st1jt3, [ - [s1, s2], - [s1, s2] - ]); - - JsonTuple3Array|CsvConversionError st2jt3 = fromCsvWithType([st2, st2], {}, JsonTuple3Array); - test:assertEquals(st2jt3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - JsonTuple3Array|CsvConversionError st3jt3 = fromCsvWithType([st3, st3], {}, JsonTuple3Array); - test:assertEquals(st3jt3, [ - [s1, s2], - [s1, s2] - ]); - - JsonTuple3Array|CsvConversionError st4jt3 = fromCsvWithType([st4, st4], {}, JsonTuple3Array); - test:assertEquals(st4jt3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - DecimalTuple4Array|CsvConversionError st1dta = fromCsvWithType([st1, st1], {}, DecimalTuple4Array); - test:assertTrue(st1dta is CsvConversionError); - test:assertEquals((st1dta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); - - IntegerTuple3Array|CsvConversionError st2bta = fromCsvWithType([st2, st2], {}, IntegerTuple3Array); - test:assertTrue(st2bta is CsvConversionError); - test:assertEquals((st2bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "int")); - - NilTuple3Array|CsvConversionError st3nta = fromCsvWithType([st3, st3], {}, NilTuple3Array); - test:assertTrue(st3nta is CsvConversionError); - test:assertEquals((st3nta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "()")); - - BooleanTuple4Array|CsvConversionError st4bta = fromCsvWithType([st4, st4], {}, BooleanTuple4Array); - test:assertTrue(st4bta is CsvConversionError); - test:assertEquals((st4bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); -} - -@test:Config {enable} -function testFromCsvWithTypeForTupleAndMapAsExpectedType() { - StringMapArray|CsvConversionError st1sma = fromCsvWithType([st1, st1], {}, StringMapArray); - test:assertEquals(st1sma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - StringMapArray|CsvConversionError st2sma = fromCsvWithType([st2, st2], {}, StringMapArray); - test:assertEquals(st2sma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringMapArray|CsvConversionError st3sma = fromCsvWithType([st3, st3], {}, StringMapArray); - test:assertEquals(st3sma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - StringMapArray|CsvConversionError st4sma = fromCsvWithType([st4, st4], {}, StringMapArray); - test:assertEquals(st4sma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - NillableIntUnionStringMapArray|CsvConversionError st1niusma = fromCsvWithType([st1, st1], {}, NillableIntUnionStringMapArray); - test:assertEquals(st1niusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - NillableIntUnionStringMapArray|CsvConversionError st2niusma = fromCsvWithType([st2, st2], {}, NillableIntUnionStringMapArray); - test:assertEquals(st2niusma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - NillableIntUnionStringMapArray|CsvConversionError st3niusma = fromCsvWithType([st3, st3], {}, NillableIntUnionStringMapArray); - test:assertEquals(st3niusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - NillableIntUnionStringMapArray|CsvConversionError st4niusma = fromCsvWithType([st4, st4], {}, NillableIntUnionStringMapArray); - test:assertEquals(st4niusma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - IntUnionStringMapArray|CsvConversionError st1iusma = fromCsvWithType([st1, st1], {}, IntUnionStringMapArray); - test:assertEquals(st1iusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - IntUnionStringMapArray|CsvConversionError st2iusma = fromCsvWithType([st2, st2], {}, IntUnionStringMapArray); - test:assertEquals(st2iusma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - IntUnionStringMapArray|CsvConversionError st3iusma = fromCsvWithType([st3, st3], {}, IntUnionStringMapArray); - test:assertEquals(st3iusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - IntUnionStringMapArray|CsvConversionError st4iusma = fromCsvWithType([st4, st4], {}, IntUnionStringMapArray); - test:assertEquals(st4iusma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - JsonMapArray|CsvConversionError st1jma = fromCsvWithType([st1, st1], {}, JsonMapArray); - test:assertEquals(st1jma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - JsonMapArray|CsvConversionError st2jma = fromCsvWithType([st2, st2], {}, JsonMapArray); - test:assertEquals(st2jma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - JsonMapArray|CsvConversionError st3jma = fromCsvWithType([st3, st3], {}, JsonMapArray); - test:assertEquals(st3jma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - JsonMapArray|CsvConversionError st4jma = fromCsvWithType([st4, st4], {}, JsonMapArray); - test:assertEquals(st4jma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - AnydataMapArray|CsvConversionError st1anydma = fromCsvWithType([st1, st1], {}, AnydataMapArray); - test:assertEquals(st1anydma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - AnydataMapArray|CsvConversionError st2anydma = fromCsvWithType([st2, st2], {}, AnydataMapArray); - test:assertEquals(st2anydma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - AnydataMapArray|CsvConversionError st3anydma = fromCsvWithType([st3, st3], {}, AnydataMapArray); - test:assertEquals(st3anydma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - AnydataMapArray|CsvConversionError st4anydma = fromCsvWithType([st4, st4], {}, AnydataMapArray); - test:assertEquals(st4anydma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomMapArray|CsvConversionError st1cma = fromCsvWithType([st1, st1], {}, CustomMapArray); - test:assertEquals(st1cma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - CustomMapArray|CsvConversionError st2cma = fromCsvWithType([st2, st2], {}, CustomMapArray); - test:assertEquals(st2cma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomMapArray|CsvConversionError st3cma = fromCsvWithType([st3, st3], {}, CustomMapArray); - test:assertEquals(st3cma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - CustomMapArray|CsvConversionError st4cma = fromCsvWithType([st4, st4], {}, CustomMapArray); - test:assertEquals(st4cma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - NilMapArray|CsvConversionError st1nma = fromCsvWithType([st1, st1], {}, NilMapArray); - test:assertEquals(st1nma, ([ - {}, - {} - ])); - - IntegerMapArray|CsvConversionError st2ima = fromCsvWithType([st2, st2], {}, IntegerMapArray); - test:assertEquals(st2ima, ([ - {}, - {} - ])); - - DecimalMapArray|CsvConversionError st3dma = fromCsvWithType([st3, st3], {}, DecimalMapArray); - test:assertEquals(st3dma, ([ - {}, - {} - ])); - - BooleanMapArray|CsvConversionError st4bma = fromCsvWithType([st4, st4], {}, BooleanMapArray); - test:assertEquals(st4bma, ([ - {}, - {} - ])); -} - -@test:Config {enable} -function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { - StringArrayArray|CsvConversionError st1saa = fromCsvWithType([st1, st1], {}, StringArrayArray); - test:assertEquals(st1saa , [ - [s1, s2], - [s1, s2] - ]); - - StringArrayArray|CsvConversionError st2saa = fromCsvWithType([st2, st2], {}, StringArrayArray); - test:assertEquals(st2saa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringArrayArray|CsvConversionError st3saa = fromCsvWithType([st3, st3], {}, StringArrayArray); - test:assertEquals(st3saa , [ - [s1, s2], - [s1, s2] - ]); - - StringArrayArray|CsvConversionError st4saa = fromCsvWithType([st4, st4], {}, StringArrayArray); - test:assertEquals(st4saa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - NillableStringArrayArray|CsvConversionError st1nsaa = fromCsvWithType([st1, st1], {}, NillableStringArrayArray); - test:assertEquals(st1nsaa , [ - [s1, s2], - [s1, s2] - ]); - - NillableStringArrayArray|CsvConversionError st2nsaa = fromCsvWithType([st2, st2], {}, NillableStringArrayArray); - test:assertEquals(st2nsaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - NillableStringArrayArray|CsvConversionError st3nsaa = fromCsvWithType([st3, st3], {}, NillableStringArrayArray); - test:assertEquals(st3nsaa , [ - [s1, s2], - [s1, s2] - ]); - - NillableStringArrayArray|CsvConversionError st4nsaa = fromCsvWithType([st4, st4], {}, NillableStringArrayArray); - test:assertEquals(st4nsaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - NillableIntOrUnionStringArrayArray|CsvConversionError st1nsuiaa = fromCsvWithType([st1, st1], {}, NillableIntOrUnionStringArrayArray); - test:assertEquals(st1nsuiaa , [ - [s1, s2], - [s1, s2] - ]); - - NillableIntOrUnionStringArrayArray|CsvConversionError st2nsuiaa = fromCsvWithType([st2, st2], {}, NillableIntOrUnionStringArrayArray); - test:assertEquals(st2nsuiaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - NillableIntOrUnionStringArrayArray|CsvConversionError st3nsuiaa = fromCsvWithType([st3, st3], {}, NillableIntOrUnionStringArrayArray); - test:assertEquals(st3nsuiaa , [ - [s1, s2], - [s1, s2] - ]); - - NillableIntOrUnionStringArrayArray|CsvConversionError st4nsuiaa = fromCsvWithType([st4, st4], {}, NillableIntOrUnionStringArrayArray); - test:assertEquals(st4nsuiaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringArray2Array|CsvConversionError st1saa2 = fromCsvWithType([st1, st1], {}, StringArray2Array); - test:assertEquals(st1saa2 , [ - [s1, s2], - [s1, s2] - ]); - - StringArray2Array|CsvConversionError st2saa2 = fromCsvWithType([st2, st2], {}, StringArray2Array); - test:assertEquals(st2saa2 , [ - [s1, s2], - [s1, s2] - ]); - - StringArray2Array|CsvConversionError st3saa2 = fromCsvWithType([st3, st3], {}, StringArray2Array); - test:assertEquals(st3saa2 , [ - [s1, s2], - [s1, s2] - ]); - - StringArray2Array|CsvConversionError st4saa2 = fromCsvWithType([st4, st4], {}, StringArray2Array); - test:assertEquals(st4saa2 , [ - [s1, s2], - [s1, s2] - ]); - - JsonArray1Array|CsvConversionError st1jaa = fromCsvWithType([st1, st1], {}, JsonArray1Array); - test:assertEquals(st1jaa , [ - [s1, s2], - [s1, s2] - ]); - - JsonArray1Array|CsvConversionError st2jaa = fromCsvWithType([st2, st2], {}, JsonArray1Array); - test:assertEquals(st2jaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - JsonArray1Array|CsvConversionError st3jaa = fromCsvWithType([st3, st3], {}, JsonArray1Array); - test:assertEquals(st3jaa , [ - [s1, s2], - [s1, s2] - ]); - - JsonArray1Array|CsvConversionError st4jaa = fromCsvWithType([st4, st4], {}, JsonArray1Array); - test:assertEquals(st4jaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - AnydataArray1Array|CsvConversionError st1anyda = fromCsvWithType([st1, st1], {}, AnydataArray1Array); - test:assertEquals(st1anyda , [ - [s1, s2], - [s1, s2] - ]); - - AnydataArray1Array|CsvConversionError st2anyda = fromCsvWithType([st2, st2], {}, AnydataArray1Array); - test:assertEquals(st2anyda , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - AnydataArray1Array|CsvConversionError st3anyda = fromCsvWithType([st3, st3], {}, AnydataArray1Array); - test:assertEquals(st3anyda , [ - [s1, s2], - [s1, s2] - ]); - - AnydataArray1Array|CsvConversionError st4anyda = fromCsvWithType([st4, st4], {}, AnydataArray1Array); - test:assertEquals(st4anyda , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - DecimalArray1Array|CsvConversionError st1dda = fromCsvWithType([st1, st1], {}, DecimalArray1Array); - test:assertTrue(st1dda is CsvConversionError); - test:assertEquals((st1dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); - - DecimalArray1Array|CsvConversionError st3dda = fromCsvWithType([st3, st3], {}, DecimalArray1Array); - test:assertTrue(st3dda is CsvConversionError); - test:assertEquals((st3dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); -} - -@test:Config {enable} -function testFromCsvWithTypeFunctionWithTypeCompatibility() { - var value = {i1, i2, s1, s2, b1, b2, n1, n2, f1, f2, d1, d2, j1: b1, a1: d1, j2: b2, a2: d2}; - var value2 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3, j2: b2, a2: d2}; - var value3 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3}; - - CustomRecord27Array|CsvConversionError vcr27a = fromCsvWithType([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: ()} - ]); - - CustomTuple7Array|CsvConversionError v2ct7a = fromCsvWithType([value2, value2, value2], {}, CustomTuple7Array); - test:assertTrue(v2ct7a is CsvConversionError); - test:assertEquals((v2ct7a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "string")); - - CustomTuple7Array|CsvConversionError v3ct7a = fromCsvWithType([value3, value3, value3], {}, CustomTuple7Array); - test:assertEquals(v3ct7a , [ - [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], - [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], - [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3] - ]); - - AnydataArray1Array|CsvConversionError v3anyd1a = fromCsvWithType([value3, value3, value3], {}, AnydataArray1Array); - test:assertEquals(v3anyd1a , [ - [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], - [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], - [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3] - ]); - - AnydataMapArray|CsvConversionError vanydma = fromCsvWithType([value, value, value], {}, AnydataMapArray); - test:assertEquals(vanydma , [ - value, - value, - value - ]); - - JsonMapArray|CsvConversionError vjma = fromCsvWithType([value, value, value], {}, JsonMapArray); - test:assertEquals(vjma , [ - value, - value, - value - ]); - - record{|int...;|}[]|CsvConversionError irrma = fromCsvWithType([{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...;|}[]|CsvConversionError drra = fromCsvWithType([{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...;|}[]|CsvConversionError srra = fromCsvWithType([{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...;|}[]|CsvConversionError frra = fromCsvWithType([{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;|}[]|CsvConversionError fdc1a = fromCsvWithType([{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 ...;|}[]|CsvConversionError fdc2a = fromCsvWithType([{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...;|}[]|CsvConversionError fdc3a = fromCsvWithType([{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} - ]); -} - -// boolean enable = true; - -// @test:Config {enable: !enable} -// function testTemp1() { - // record{|float...;|}[]|CsvConversionError frra = fromCsvWithType([{a: d2, b: d3}]); - // test:assertEquals(frra , [ - // {a: 1.2, b: 1.2}, - // {}, - // {a: d4, b: f2} - // ]); -// } diff --git a/ballerina/tests/note b/ballerina/tests/note deleted file mode 100644 index 8b86c4b..0000000 --- a/ballerina/tests/note +++ /dev/null @@ -1 +0,0 @@ -runtime error for annotaions with open recs, compile error for closed records \ No newline at end of file diff --git a/ballerina/tests/parse_list_type_as_list_test.bal b/ballerina/tests/parse_list_type_as_list_test.bal new file mode 100644 index 0000000..4c0a9b6 --- /dev/null +++ b/ballerina/tests/parse_list_type_as_list_test.bal @@ -0,0 +1,330 @@ +import ballerina/test; + +// boolean enable = true; + +// // @test:Config {enable: !enable} +// // function debugTest() { +// // BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// // test:assertEquals(csvb4br1, [ +// // {b1: true, b2: "()", b3: (), b4: false}, +// // {b1: true, b2: "()", b3: (), b4: false} +// // ]); +// // } + +@test:Config {enable} +function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { + StringTuple1Array|CsvConversionError st1st1 = parseListAsListType([st1, st1], {}, StringTuple1Array); + test:assertEquals(st1st1, [ + [s1, s2, "", ""], + [s1, s2, "", ""] + ]); + + StringTuple1Array|CsvConversionError st2st1 = parseListAsListType([st2, st2], {}, StringTuple1Array); + test:assertEquals(st2st1, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + StringTuple1Array|CsvConversionError st3st1 = parseListAsListType([st3, st3], {}, StringTuple1Array); + test:assertEquals(st3st1, [ + [s1, s2, "", ""], + [s1, s2, "", ""] + ]); + + StringTuple1Array|CsvConversionError st4st1 = parseListAsListType([st4, st4], {}, StringTuple1Array); + test:assertEquals(st4st1, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple2Array|CsvConversionError st1st2 = parseListAsListType([st1, st1], {}, StringTuple2Array); + test:assertEquals(st1st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple2Array|CsvConversionError st2st2 = parseListAsListType([st2, st2], {}, StringTuple2Array); + test:assertEquals(st2st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple2Array|CsvConversionError st3st2 = parseListAsListType([st3, st3], {}, StringTuple2Array); + test:assertEquals(st3st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple2Array|CsvConversionError st4st2 = parseListAsListType([st4, st4], {}, StringTuple2Array); + test:assertEquals(st4st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple3Array|CsvConversionError st1st3 = parseListAsListType([st1, st1], {}, StringTuple3Array); + test:assertEquals(st1st3, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple3Array|CsvConversionError st2st3 = parseListAsListType([st2, st2], {}, StringTuple3Array); + test:assertEquals(st2st3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple3Array|CsvConversionError st3st3 = parseListAsListType([st3, st3], {}, StringTuple3Array); + test:assertEquals(st3st3, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple3Array|CsvConversionError st4st3 = parseListAsListType([st4, st4], {}, StringTuple3Array); + test:assertEquals(st4st3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple4Array|CsvConversionError st1st4 = parseListAsListType([st1, st1], {}, StringTuple4Array); + test:assertEquals(st1st4, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple4Array|CsvConversionError st2st4 = parseListAsListType([st2, st2], {}, StringTuple4Array); + test:assertEquals(st2st4, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple4Array|CsvConversionError st3st4 = parseListAsListType([st3, st3], {}, StringTuple4Array); + test:assertEquals(st3st4, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple4Array|CsvConversionError st4st4 = parseListAsListType([st4, st4], {}, StringTuple4Array); + test:assertEquals(st4st4, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataTuple3Array|CsvConversionError st1anydt3 = parseListAsListType([st1, st1], {}, AnydataTuple3Array); + test:assertEquals(st1anydt3, [ + [s1, s2], + [s1, s2] + ]); + + AnydataTuple3Array|CsvConversionError st2anydt3 = parseListAsListType([st2, st2], {}, AnydataTuple3Array); + test:assertEquals(st2anydt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataTuple3Array|CsvConversionError st3anydt3 = parseListAsListType([st3, st3], {}, AnydataTuple3Array); + test:assertEquals(st3anydt3, [ + [s1, s2], + [s1, s2] + ]); + + AnydataTuple3Array|CsvConversionError st4anydt3 = parseListAsListType([st4, st4], {}, AnydataTuple3Array); + test:assertEquals(st4anydt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + JsonTuple3Array|CsvConversionError st1jt3 = parseListAsListType([st1, st1], {}, JsonTuple3Array); + test:assertEquals(st1jt3, [ + [s1, s2], + [s1, s2] + ]); + + JsonTuple3Array|CsvConversionError st2jt3 = parseListAsListType([st2, st2], {}, JsonTuple3Array); + test:assertEquals(st2jt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + JsonTuple3Array|CsvConversionError st3jt3 = parseListAsListType([st3, st3], {}, JsonTuple3Array); + test:assertEquals(st3jt3, [ + [s1, s2], + [s1, s2] + ]); + + JsonTuple3Array|CsvConversionError st4jt3 = parseListAsListType([st4, st4], {}, JsonTuple3Array); + test:assertEquals(st4jt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + DecimalTuple4Array|CsvConversionError st1dta = parseListAsListType([st1, st1], {}, DecimalTuple4Array); + test:assertTrue(st1dta is CsvConversionError); + test:assertEquals((st1dta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); + + IntegerTuple3Array|CsvConversionError st2bta = parseListAsListType([st2, st2], {}, IntegerTuple3Array); + test:assertTrue(st2bta is CsvConversionError); + test:assertEquals((st2bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "int")); + + NilTuple3Array|CsvConversionError st3nta = parseListAsListType([st3, st3], {}, NilTuple3Array); + test:assertTrue(st3nta is CsvConversionError); + test:assertEquals((st3nta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "()")); + + BooleanTuple4Array|CsvConversionError st4bta = parseListAsListType([st4, st4], {}, BooleanTuple4Array); + test:assertTrue(st4bta is CsvConversionError); + test:assertEquals((st4bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); +} + + +@test:Config {enable} +function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { + StringArrayArray|CsvConversionError st1saa = parseListAsListType([st1, st1], {}, StringArrayArray); + test:assertEquals(st1saa , [ + [s1, s2], + [s1, s2] + ]); + + StringArrayArray|CsvConversionError st2saa = parseListAsListType([st2, st2], {}, StringArrayArray); + test:assertEquals(st2saa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringArrayArray|CsvConversionError st3saa = parseListAsListType([st3, st3], {}, StringArrayArray); + test:assertEquals(st3saa , [ + [s1, s2], + [s1, s2] + ]); + + StringArrayArray|CsvConversionError st4saa = parseListAsListType([st4, st4], {}, StringArrayArray); + test:assertEquals(st4saa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableStringArrayArray|CsvConversionError st1nsaa = parseListAsListType([st1, st1], {}, NillableStringArrayArray); + test:assertEquals(st1nsaa , [ + [s1, s2], + [s1, s2] + ]); + + NillableStringArrayArray|CsvConversionError st2nsaa = parseListAsListType([st2, st2], {}, NillableStringArrayArray); + test:assertEquals(st2nsaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableStringArrayArray|CsvConversionError st3nsaa = parseListAsListType([st3, st3], {}, NillableStringArrayArray); + test:assertEquals(st3nsaa , [ + [s1, s2], + [s1, s2] + ]); + + NillableStringArrayArray|CsvConversionError st4nsaa = parseListAsListType([st4, st4], {}, NillableStringArrayArray); + test:assertEquals(st4nsaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableIntOrUnionStringArrayArray|CsvConversionError st1nsuiaa = parseListAsListType([st1, st1], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st1nsuiaa , [ + [s1, s2], + [s1, s2] + ]); + + NillableIntOrUnionStringArrayArray|CsvConversionError st2nsuiaa = parseListAsListType([st2, st2], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st2nsuiaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableIntOrUnionStringArrayArray|CsvConversionError st3nsuiaa = parseListAsListType([st3, st3], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st3nsuiaa , [ + [s1, s2], + [s1, s2] + ]); + + NillableIntOrUnionStringArrayArray|CsvConversionError st4nsuiaa = parseListAsListType([st4, st4], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st4nsuiaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringArray2Array|CsvConversionError st1saa2 = parseListAsListType([st1, st1], {}, StringArray2Array); + test:assertEquals(st1saa2 , [ + [s1, s2], + [s1, s2] + ]); + + StringArray2Array|CsvConversionError st2saa2 = parseListAsListType([st2, st2], {}, StringArray2Array); + test:assertEquals(st2saa2 , [ + [s1, s2], + [s1, s2] + ]); + + StringArray2Array|CsvConversionError st3saa2 = parseListAsListType([st3, st3], {}, StringArray2Array); + test:assertEquals(st3saa2 , [ + [s1, s2], + [s1, s2] + ]); + + StringArray2Array|CsvConversionError st4saa2 = parseListAsListType([st4, st4], {}, StringArray2Array); + test:assertEquals(st4saa2 , [ + [s1, s2], + [s1, s2] + ]); + + JsonArray1Array|CsvConversionError st1jaa = parseListAsListType([st1, st1], {}, JsonArray1Array); + test:assertEquals(st1jaa , [ + [s1, s2], + [s1, s2] + ]); + + JsonArray1Array|CsvConversionError st2jaa = parseListAsListType([st2, st2], {}, JsonArray1Array); + test:assertEquals(st2jaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + JsonArray1Array|CsvConversionError st3jaa = parseListAsListType([st3, st3], {}, JsonArray1Array); + test:assertEquals(st3jaa , [ + [s1, s2], + [s1, s2] + ]); + + JsonArray1Array|CsvConversionError st4jaa = parseListAsListType([st4, st4], {}, JsonArray1Array); + test:assertEquals(st4jaa , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataArray1Array|CsvConversionError st1anyda = parseListAsListType([st1, st1], {}, AnydataArray1Array); + test:assertEquals(st1anyda , [ + [s1, s2], + [s1, s2] + ]); + + AnydataArray1Array|CsvConversionError st2anyda = parseListAsListType([st2, st2], {}, AnydataArray1Array); + test:assertEquals(st2anyda , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataArray1Array|CsvConversionError st3anyda = parseListAsListType([st3, st3], {}, AnydataArray1Array); + test:assertEquals(st3anyda , [ + [s1, s2], + [s1, s2] + ]); + + AnydataArray1Array|CsvConversionError st4anyda = parseListAsListType([st4, st4], {}, AnydataArray1Array); + test:assertEquals(st4anyda , [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + DecimalArray1Array|CsvConversionError st1dda = parseListAsListType([st1, st1], {}, DecimalArray1Array); + test:assertTrue(st1dda is CsvConversionError); + test:assertEquals((st1dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); + + DecimalArray1Array|CsvConversionError st3dda = parseListAsListType([st3, st3], {}, DecimalArray1Array); + test:assertTrue(st3dda is CsvConversionError); + test:assertEquals((st3dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); +} diff --git a/ballerina/tests/parse_list_type_as_record_test.bal b/ballerina/tests/parse_list_type_as_record_test.bal new file mode 100644 index 0000000..ba84d2e --- /dev/null +++ b/ballerina/tests/parse_list_type_as_record_test.bal @@ -0,0 +1,653 @@ +import ballerina/test; + +// boolean enable = false; + +// @test:Config {enable: !enable} +// function debugTest() { +// StringRecord10Array|CsvConversionError st1sr10 = parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); +// test:assertEquals(st1sr10, [ +// {'1: "string", '2: ""}, +// {'1: "string", '2: ""} +// ]); +// } + +@test:Config {enable} +function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { + StringRecord1Array|CsvConversionError st1sr1 = parseListAsRecordType([st1, st1], (), {}, StringRecord1Array); + test:assertTrue(st1sr1 is CsvConversionError); + test:assertEquals((st1sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + + StringRecord1Array|CsvConversionError st2sr1 = parseListAsRecordType([st2, st2], (), {}, StringRecord1Array); + test:assertTrue(st2sr1 is CsvConversionError); + test:assertEquals((st2sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + + StringRecord2Array|CsvConversionError st1sr2 = parseListAsRecordType([st1, st1], (), {}, StringRecord2Array); + test:assertTrue(st1sr2 is CsvConversionError); + test:assertEquals((st1sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); + + StringRecord2Array|CsvConversionError st2sr2 = parseListAsRecordType([st2, st2], (), {}, StringRecord2Array); + test:assertTrue(st2sr2 is CsvConversionError); + test:assertEquals((st2sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); + + StringRecord9Array|CsvConversionError st1sr9 = parseListAsRecordType([st1, st1], (), {}, StringRecord9Array); + test:assertTrue(st1sr9 is CsvConversionError); + test:assertEquals((st1sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord9")); + + StringRecord9Array|CsvConversionError st2sr9 = parseListAsRecordType([st2, st2], (), {}, StringRecord9Array); + test:assertTrue(st2sr9 is CsvConversionError); + test:assertEquals((st2sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord9")); + + StringRecord10Array|CsvConversionError st1sr10 = parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); + test:assertEquals(st1sr10, [ + {'1: "string", '2: ""}, + {'1: "string", '2: ""} + ]); + + StringRecord10Array|CsvConversionError st2sr10 = parseListAsRecordType([st2, st2], (), {}, StringRecord10Array); + test:assertEquals(st2sr10, [ + {'1: "string", '2: "", '3: "a", '4: ""}, + {'1: "string", '2: "", '3: "a", '4: ""} + ]); + + StringRecord19Array|CsvConversionError st1sr19 = parseListAsRecordType([st1, st1], (), {}, StringRecord19Array); + test:assertEquals(st1sr19, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord19Array|CsvConversionError st2sr19 = parseListAsRecordType([st2, st2], (), {}, StringRecord19Array); + test:assertEquals(st2sr19, [ + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord20Array|CsvConversionError st1sr20 = parseListAsRecordType([st1, st1], (), {}, StringRecord20Array); + test:assertEquals(st1sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord20Array|CsvConversionError st2sr20 = parseListAsRecordType([st2, st2], (), {}, StringRecord20Array); + test:assertEquals(st2sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord21Array|CsvConversionError st1sr21 = parseListAsRecordType([st1, st1], (), {}, StringRecord21Array); + test:assertEquals(st1sr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord21Array|CsvConversionError st2sr21 = parseListAsRecordType([st2, st2], (), {}, StringRecord21Array); + test:assertEquals(st2sr21, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord22Array|CsvConversionError st1sr22 = parseListAsRecordType([st1, st1], (), {}, StringRecord22Array); + test:assertEquals(st1sr22, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord22Array|CsvConversionError st2sr22 = parseListAsRecordType([st2, st2], (), {}, StringRecord22Array); + test:assertEquals(st2sr22, [ + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord23Array|CsvConversionError st1sr23 = parseListAsRecordType([st1, st1], (), {}, StringRecord23Array); + test:assertEquals(st1sr23, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord23Array|CsvConversionError st2sr23 = parseListAsRecordType([st2, st2], (), {}, StringRecord23Array); + test:assertEquals(st2sr23, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord15Array|CsvConversionError st1cr15 = parseListAsRecordType([st1, st1], (), {}, CustomRecord15Array); + test:assertEquals(st1cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord15Array|CsvConversionError st2cr15 = parseListAsRecordType([st2, st2], (), {}, CustomRecord15Array); + test:assertEquals(st2cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord16Array|CsvConversionError st1cr16 = parseListAsRecordType([st1, st1], (), {}, CustomRecord16Array); + test:assertTrue(st1cr16 is CsvConversionError); + test:assertEquals((st1cr16).message(), generateErrorMessageForMissingRequiredField("3")); + + CustomRecord16Array|CsvConversionError st2cr16 = parseListAsRecordType([st2, st2], (), {}, CustomRecord16Array); + test:assertEquals(st2cr16, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord17Array|CsvConversionError st1cr17 = parseListAsRecordType([st1, st1], (), {}, CustomRecord17Array); + test:assertEquals(st1cr17, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord17Array|CsvConversionError st2cr17 = parseListAsRecordType([st2, st2], (), {}, CustomRecord17Array); + test:assertEquals(st2cr17, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord18Array|CsvConversionError st1cr18 = parseListAsRecordType([st1, st1], (), {}, CustomRecord18Array); + test:assertTrue(st1cr18 is CsvConversionError); + test:assertEquals((st1cr18).message(), generateErrorMessageForMissingRequiredField("3")); + + CustomRecord18Array|CsvConversionError st2cr18 = parseListAsRecordType([st2, st2], (), {}, CustomRecord18Array); + test:assertEquals(st2cr18, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord19Array|CsvConversionError st1cr19 = parseListAsRecordType([st1, st1], (), {}, CustomRecord19Array); + test:assertEquals(st1cr19, [ + {'1: s1, '2: s2, '3: "", '4: ""}, + {'1: s1, '2: s2, '3: "", '4: ""} + ]); + + CustomRecord19Array|CsvConversionError st2cr19 = parseListAsRecordType([st2, st2], (), {}, CustomRecord19Array); + test:assertEquals(st2cr19, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord20Array|CsvConversionError st1cr20 = parseListAsRecordType([st1, st1], (), {}, CustomRecord20Array); + test:assertEquals(st1cr20, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord20Array|CsvConversionError st2cr20 = parseListAsRecordType([st2, st2], (), {}, CustomRecord20Array); + test:assertEquals(st2cr20, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord21Array|CsvConversionError st1cr21 = parseListAsRecordType([st1, st1], (), {}, CustomRecord21Array); + test:assertEquals(st1cr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord21Array|CsvConversionError st2cr21 = parseListAsRecordType([st2, st2], (), {}, CustomRecord21Array); + test:assertEquals(st2cr21, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord22Array|CsvConversionError st1cr22 = parseListAsRecordType([st1, st1], (), {}, CustomRecord22Array); + test:assertEquals(st1cr22, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord22Array|CsvConversionError st2cr22 = parseListAsRecordType([st2, st2], (), {}, CustomRecord22Array); + test:assertEquals(st2cr22, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord23Array|CsvConversionError st1cr23 = parseListAsRecordType([st1, st1], (), {}, CustomRecord23Array); + test:assertEquals(st1cr23, [ + {"1": s1, "2": s2, a: ""}, + {"1": s1, "2": s2, a: ""} + ]); + + CustomRecord23Array|CsvConversionError st2cr23 = parseListAsRecordType([st2, st2], (), {}, CustomRecord23Array); + test:assertEquals(st2cr23, [ + {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, + {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} + ]); + + CustomRecord24Array|CsvConversionError st1cr24 = parseListAsRecordType([st1, st1], (), {}, CustomRecord24Array); + test:assertEquals(st1cr24, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord24Array|CsvConversionError st2cr24 = parseListAsRecordType([st2, st2], (), {}, CustomRecord24Array); + test:assertEquals(st2cr24, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord25Array|CsvConversionError st1cr25 = parseListAsRecordType([st1, st1], (), {}, CustomRecord25Array); + test:assertTrue(st1cr25 is CsvConversionError); + test:assertEquals((st1cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:CustomRecord25")); + + CustomRecord25Array|CsvConversionError st2cr25 = parseListAsRecordType([st2, st2], (), {}, CustomRecord25Array); + test:assertTrue(st2cr25 is CsvConversionError); + test:assertEquals((st2cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:CustomRecord25")); + + CustomRecord25Array|CsvConversionError st3cr25 = parseListAsRecordType([st3, st3], (), {}, CustomRecord25Array); + test:assertTrue(st3cr25 is CsvConversionError); + test:assertEquals((st3cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:CustomRecord25")); + + CustomRecord25Array|CsvConversionError st4cr25 = parseListAsRecordType([st4, st4], (), {}, CustomRecord25Array); + test:assertTrue(st4cr25 is CsvConversionError); + test:assertEquals((st4cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:CustomRecord25")); + + CustomRecord26Array|CsvConversionError st1cr26 = parseListAsRecordType([st1, st1], (), {}, CustomRecord26Array); + test:assertEquals(st1cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|CsvConversionError st2cr26 = parseListAsRecordType([st2, st2], (), {}, CustomRecord26Array); + test:assertEquals(st2cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|CsvConversionError st3cr26 = parseListAsRecordType([st3, st3], (), {}, CustomRecord26Array); + test:assertEquals(st3cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|CsvConversionError st4cr26 = parseListAsRecordType([st4, st4], (), {}, CustomRecord26Array); + test:assertEquals(st4cr26 , [ + {'1: s1}, + {'1: s1} + ]); +} + +@test:Config {enable} +function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { + StringRecord1Array|CsvConversionError st3sr1 = parseListAsRecordType([st3, st3], (), {}, StringRecord1Array); + test:assertTrue(st3sr1 is CsvConversionError); + test:assertEquals((st3sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + + StringRecord1Array|CsvConversionError st4sr1 = parseListAsRecordType([st4, st4], (), {}, StringRecord1Array); + test:assertTrue(st4sr1 is CsvConversionError); + test:assertEquals((st4sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + + StringRecord2Array|CsvConversionError st3sr2 = parseListAsRecordType([st3, st3], (), {}, StringRecord2Array); + test:assertTrue(st3sr2 is CsvConversionError); + test:assertEquals((st3sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); + + StringRecord2Array|CsvConversionError st4sr2 = parseListAsRecordType([st4, st4], (), {}, StringRecord2Array); + test:assertTrue(st4sr2 is CsvConversionError); + test:assertEquals((st4sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); + + StringRecord9Array|CsvConversionError st3sr9 = parseListAsRecordType([st3, st3], (), {}, StringRecord9Array); + test:assertTrue(st3sr9 is CsvConversionError); + test:assertEquals((st3sr9).message(), generateErrorMessageForMissingRequiredField("s1")); + + StringRecord9Array|CsvConversionError st4sr9 = parseListAsRecordType([st4, st4], (), {}, StringRecord9Array); + test:assertTrue(st4sr9 is CsvConversionError); + test:assertEquals((st4sr9).message(), generateErrorMessageForMissingRequiredField("s1")); + + StringRecord10Array|CsvConversionError st3sr10 = parseListAsRecordType([st3, st3], (), {}, StringRecord10Array); + test:assertEquals(st3sr10, [ + {'1: "string", '2: ""}, + {'1: "string", '2: ""} + ]); + + StringRecord10Array|CsvConversionError st4sr10 = parseListAsRecordType([st4, st4], (), {}, StringRecord10Array); + test:assertEquals(st4sr10, [ + {'1: "string", '2: "", '3: "a", '4: ""}, + {'1: "string", '2: "", '3: "a", '4: ""} + ]); + + StringRecord19Array|CsvConversionError st3sr19 = parseListAsRecordType([st3, st3], (), {}, StringRecord19Array); + test:assertEquals(st3sr19, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord19Array|CsvConversionError st4sr19 = parseListAsRecordType([st4, st4], (), {}, StringRecord19Array); + test:assertEquals(st4sr19, [ + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord20Array|CsvConversionError st3sr20 = parseListAsRecordType([st3, st3], (), {}, StringRecord20Array); + test:assertEquals(st3sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord20Array|CsvConversionError st4sr20 = parseListAsRecordType([st4, st4], (), {}, StringRecord20Array); + test:assertEquals(st4sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord21Array|CsvConversionError st3sr21 = parseListAsRecordType([st3, st3], (), {}, StringRecord21Array); + test:assertEquals(st3sr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord21Array|CsvConversionError st4sr21 = parseListAsRecordType([st4, st4], (), {}, StringRecord21Array); + test:assertEquals(st4sr21, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord22Array|CsvConversionError st3sr22 = parseListAsRecordType([st3, st3], (), {}, StringRecord22Array); + test:assertEquals(st3sr22, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord22Array|CsvConversionError st4sr22 = parseListAsRecordType([st4, st4], (), {}, StringRecord22Array); + test:assertEquals(st4sr22, [ + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, + {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringRecord23Array|CsvConversionError st3sr23 = parseListAsRecordType([st3, st3], (), {}, StringRecord23Array); + test:assertEquals(st3sr23, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord23Array|CsvConversionError st4sr23 = parseListAsRecordType([st4, st4], (), {}, StringRecord23Array); + test:assertEquals(st4sr23, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord15Array|CsvConversionError st3cr15 = parseListAsRecordType([st3, st3], (), {}, CustomRecord15Array); + test:assertEquals(st3cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord15Array|CsvConversionError st4cr15 = parseListAsRecordType([st4, st4], (), {}, CustomRecord15Array); + test:assertEquals(st4cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord16Array|CsvConversionError st3cr16 = parseListAsRecordType([st3, st3], (), {}, CustomRecord16Array); + test:assertTrue(st3cr16 is CsvConversionError); + test:assertEquals((st3cr16).message(), generateErrorMessageForMissingRequiredField("3")); + + CustomRecord16Array|CsvConversionError st4cr16 = parseListAsRecordType([st4, st4], (), {}, CustomRecord16Array); + test:assertEquals(st4cr16, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord17Array|CsvConversionError st3cr17 = parseListAsRecordType([st3, st3], (), {}, CustomRecord17Array); + test:assertEquals(st3cr17, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord17Array|CsvConversionError st4cr17 = parseListAsRecordType([st4, st4], (), {}, CustomRecord17Array); + test:assertEquals(st4cr17, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord18Array|CsvConversionError st3cr18 = parseListAsRecordType([st3, st3], (), {}, CustomRecord18Array); + test:assertTrue(st3cr18 is CsvConversionError); + test:assertEquals((st3cr18).message(), generateErrorMessageForMissingRequiredField("3")); + + CustomRecord18Array|CsvConversionError st4cr18 = parseListAsRecordType([st4, st4], (), {}, CustomRecord18Array); + test:assertEquals(st4cr18, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord19Array|CsvConversionError st3cr19 = parseListAsRecordType([st3, st3], (), {}, CustomRecord19Array); + test:assertEquals(st3cr19, [ + {'1: s1, '2: s2, '3: "", '4: ""}, + {'1: s1, '2: s2, '3: "", '4: ""} + ]); + + CustomRecord19Array|CsvConversionError st4cr19 = parseListAsRecordType([st4, st4], (), {}, CustomRecord19Array); + test:assertEquals(st4cr19, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord20Array|CsvConversionError st3cr20 = parseListAsRecordType([st3, st3], (), {}, CustomRecord20Array); + test:assertEquals(st3cr20, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord20Array|CsvConversionError st4cr20 = parseListAsRecordType([st4, st4], (), {}, CustomRecord20Array); + test:assertEquals(st4cr20, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord21Array|CsvConversionError st3cr21 = parseListAsRecordType([st3, st3], (), {}, CustomRecord21Array); + test:assertEquals(st3cr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord21Array|CsvConversionError st4cr21 = parseListAsRecordType([st4, st4], (), {}, CustomRecord21Array); + test:assertEquals(st4cr21, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord22Array|CsvConversionError st3cr22 = parseListAsRecordType([st3, st3], (), {}, CustomRecord22Array); + test:assertEquals(st3cr22, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord22Array|CsvConversionError st4cr22 = parseListAsRecordType([st4, st4], (), {}, CustomRecord22Array); + test:assertEquals(st4cr22, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomRecord23Array|CsvConversionError st3cr23 = parseListAsRecordType([st3, st3], (), {}, CustomRecord23Array); + test:assertEquals(st3cr23, [ + {"1": s1, "2": s2, a: ""}, + {"1": s1, "2": s2, a: ""} + ]); + + CustomRecord23Array|CsvConversionError st4cr23 = parseListAsRecordType([st4, st4], (), {}, CustomRecord23Array); + test:assertEquals(st4cr23, [ + {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, + {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} + ]); + + CustomRecord24Array|CsvConversionError st3cr24 = parseListAsRecordType([st3, st3], (), {}, CustomRecord24Array); + test:assertEquals(st3cr24, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord24Array|CsvConversionError st4cr24 = parseListAsRecordType([st4, st4], (), {}, CustomRecord24Array); + test:assertEquals(st4cr24, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); +} + +@test:Config {enable} +function testFromCsvWithTypeForTupleAndMapAsExpectedType() { + StringMapArray|CsvConversionError st1sma = parseListAsRecordType([st1, st1], (), {}, StringMapArray); + test:assertEquals(st1sma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + StringMapArray|CsvConversionError st2sma = parseListAsRecordType([st2, st2], (), {}, StringMapArray); + test:assertEquals(st2sma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + StringMapArray|CsvConversionError st3sma = parseListAsRecordType([st3, st3], (), {}, StringMapArray); + test:assertEquals(st3sma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + StringMapArray|CsvConversionError st4sma = parseListAsRecordType([st4, st4], (), {}, StringMapArray); + test:assertEquals(st4sma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + NillableIntUnionStringMapArray|CsvConversionError st1niusma = parseListAsRecordType([st1, st1], (), {}, NillableIntUnionStringMapArray); + test:assertEquals(st1niusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + NillableIntUnionStringMapArray|CsvConversionError st2niusma = parseListAsRecordType([st2, st2], (), {}, NillableIntUnionStringMapArray); + test:assertEquals(st2niusma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + NillableIntUnionStringMapArray|CsvConversionError st3niusma = parseListAsRecordType([st3, st3], (), {}, NillableIntUnionStringMapArray); + test:assertEquals(st3niusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + NillableIntUnionStringMapArray|CsvConversionError st4niusma = parseListAsRecordType([st4, st4], (), {}, NillableIntUnionStringMapArray); + test:assertEquals(st4niusma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + IntUnionStringMapArray|CsvConversionError st1iusma = parseListAsRecordType([st1, st1], (), {}, IntUnionStringMapArray); + test:assertEquals(st1iusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + IntUnionStringMapArray|CsvConversionError st2iusma = parseListAsRecordType([st2, st2], (), {}, IntUnionStringMapArray); + test:assertEquals(st2iusma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + IntUnionStringMapArray|CsvConversionError st3iusma = parseListAsRecordType([st3, st3], (), {}, IntUnionStringMapArray); + test:assertEquals(st3iusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + IntUnionStringMapArray|CsvConversionError st4iusma = parseListAsRecordType([st4, st4], (), {}, IntUnionStringMapArray); + test:assertEquals(st4iusma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + JsonMapArray|CsvConversionError st1jma = parseListAsRecordType([st1, st1], (), {}, JsonMapArray); + test:assertEquals(st1jma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + JsonMapArray|CsvConversionError st2jma = parseListAsRecordType([st2, st2], (), {}, JsonMapArray); + test:assertEquals(st2jma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + JsonMapArray|CsvConversionError st3jma = parseListAsRecordType([st3, st3], (), {}, JsonMapArray); + test:assertEquals(st3jma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + JsonMapArray|CsvConversionError st4jma = parseListAsRecordType([st4, st4], (), {}, JsonMapArray); + test:assertEquals(st4jma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + AnydataMapArray|CsvConversionError st1anydma = parseListAsRecordType([st1, st1], (), {}, AnydataMapArray); + test:assertEquals(st1anydma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + AnydataMapArray|CsvConversionError st2anydma = parseListAsRecordType([st2, st2], (), {}, AnydataMapArray); + test:assertEquals(st2anydma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + AnydataMapArray|CsvConversionError st3anydma = parseListAsRecordType([st3, st3], (), {}, AnydataMapArray); + test:assertEquals(st3anydma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + AnydataMapArray|CsvConversionError st4anydma = parseListAsRecordType([st4, st4], (), {}, AnydataMapArray); + test:assertEquals(st4anydma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomMapArray|CsvConversionError st1cma = parseListAsRecordType([st1, st1], (), {}, CustomMapArray); + test:assertEquals(st1cma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + CustomMapArray|CsvConversionError st2cma = parseListAsRecordType([st2, st2], (), {}, CustomMapArray); + test:assertEquals(st2cma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + CustomMapArray|CsvConversionError st3cma = parseListAsRecordType([st3, st3], (), {}, CustomMapArray); + test:assertEquals(st3cma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + CustomMapArray|CsvConversionError st4cma = parseListAsRecordType([st4, st4], (), {}, CustomMapArray); + test:assertEquals(st4cma , [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); + + NilMapArray|CsvConversionError st1nma = parseListAsRecordType([st1, st1], (), {}, NilMapArray); + test:assertEquals(st1nma, ([ + {}, + {} + ])); + + IntegerMapArray|CsvConversionError st2ima = parseListAsRecordType([st2, st2], (), {}, IntegerMapArray); + test:assertEquals(st2ima, ([ + {}, + {} + ])); + + DecimalMapArray|CsvConversionError st3dma = parseListAsRecordType([st3, st3], (), {}, DecimalMapArray); + test:assertEquals(st3dma, ([ + {}, + {} + ])); + + BooleanMapArray|CsvConversionError st4bma = parseListAsRecordType([st4, st4], (), {}, BooleanMapArray); + test:assertEquals(st4bma, ([ + {}, + {} + ])); +} diff --git a/ballerina/tests/parse_record_type_as_list_test.bal b/ballerina/tests/parse_record_type_as_list_test.bal new file mode 100644 index 0000000..2a4e694 --- /dev/null +++ b/ballerina/tests/parse_record_type_as_list_test.bal @@ -0,0 +1,540 @@ +import ballerina/test; + +boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() { +// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// test:assertEquals(csvb4br1, [ +// {b1: true, b2: "()", b3: (), b4: false}, +// {b1: true, b2: "()", b3: (), b4: false} +// ]); +// } + +@test:Config {enable} +function testFromCsvWithTypeForMapAndArrayAsExpectedType() { + BooleanArrayArray|CsvConversionError bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanArrayArray); + test:assertEquals(bm1ba, [ + [true, false], + [true, false] + ]); + + bm1ba = parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}, BooleanArrayArray); + test:assertEquals(bm1ba, [ + [false, true], + [false, true] + ]); + + BooleanArrayArray|CsvConversionError bm2ba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanArrayArray); + test:assertTrue(bm2ba is CsvConversionError); + test:assertEquals((bm2ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanArrayArray|CsvConversionError bm3ba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanArrayArray); + test:assertTrue(bm3ba is CsvConversionError); + test:assertEquals((bm3ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanArrayArray|CsvConversionError bm4ba = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, BooleanArrayArray); + test:assertTrue(bm4ba is CsvConversionError); + test:assertEquals((bm4ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + + BooleanArrayArray|CsvConversionError bm5ba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanArrayArray); + test:assertTrue(bm5ba is CsvConversionError); + test:assertEquals((bm5ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + NillableBooleanArrayArray|CsvConversionError bm1nba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanArrayArray); + test:assertEquals(bm1nba, [ + [true, false], + [true, false] + ]); + + NillableBooleanArrayArray|CsvConversionError bm2nba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanArrayArray); + test:assertEquals(bm2nba, [ + [true, false, null, null, null], + [true, false, null, null, null] + ]); + + NillableBooleanArrayArray|CsvConversionError bm3nba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanArrayArray); + test:assertTrue(bm3nba is CsvConversionError); + test:assertEquals((bm3nba).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); + + NillableBooleanArrayArray|CsvConversionError bm4nba = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableBooleanArrayArray); + test:assertEquals(bm4nba, [ + [(), ()], + [(), ()] + ]); + + NillableBooleanArrayArray|CsvConversionError bm5nba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanArrayArray); + test:assertEquals(bm5nba, [ + [true, false, (), true], + [true, false, (), true] + ]); + + bm5nba = parseRecordAsListType([bm5, bm5], ["b1", "b3", "b2", "b4"], {}, NillableBooleanArrayArray); + test:assertEquals(bm5nba, [ + [true, (), false, true], + [true, (), false, true] + ]); + + bm5nba = parseRecordAsListType([bm5, bm5], ["b4", "b3", "b2", "b1"], {}, NillableBooleanArrayArray); + test:assertEquals(bm5nba, [ + [true, (), false, true], + [true, (), false, true] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm1niouba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm1niouba, [ + [true, false], + [true, false] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm2niouba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm2niouba, [ + [true, false, null, null, null], + [true, false, null, null, null] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm3niouba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm3niouba, [ + [true, false, null, false, 1], + [true, false, null, false, 1] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm4niouba = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm4niouba, [ + [(), ()], + [(), ()] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm5niouba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm5niouba, [ + [true, false, (), true], + [true, false, (), true] + ]); + + JsonArray1Array|CsvConversionError bm1ja = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, JsonArray1Array); + test:assertEquals(bm1ja, [ + [true, false], + [true, false] + ]); + + JsonArray1Array|CsvConversionError bm2ja = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, JsonArray1Array); + test:assertEquals(bm2ja, [ + [true, false, null, null, null], + [true, false, null, null, null] + ]); + + JsonArray1Array|CsvConversionError bm3ja = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, JsonArray1Array); + test:assertEquals(bm3ja, [ + [true, false, null, false, 1], + [true, false, null, false, 1] + ]); + + JsonArray1Array|CsvConversionError bm4ja = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, JsonArray1Array); + test:assertEquals(bm4ja, [ + [(), ()], + [(), ()] + ]); + + JsonArray1Array|CsvConversionError bm5ja = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, JsonArray1Array); + test:assertEquals(bm5ja, [ + [true, false, (), true], + [true, false, (), true] + ]); + + AnydataArray1Array|CsvConversionError bm1anyda = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataArray1Array); + test:assertEquals(bm1anyda, [ + [true, false], + [true, false] + ]); + + AnydataArray1Array|CsvConversionError bm2anyda = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, AnydataArray1Array); + test:assertEquals(bm2anyda, [ + [true, false, null, null, null], + [true, false, null, null, null] + ]); + + AnydataArray1Array|CsvConversionError bm3anyda = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, AnydataArray1Array); + test:assertEquals(bm3anyda, [ + [true, false, null, false, 1], + [true, false, null, false, 1] + ]); + + AnydataArray1Array|CsvConversionError bm4anyda = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, AnydataArray1Array); + test:assertEquals(bm4anyda, [ + [(), ()], + [(), ()] + ]); + + AnydataArray1Array|CsvConversionError bm5anyda = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, AnydataArray1Array); + test:assertEquals(bm5anyda, [ + [true, false, (), true], + [true, false, (), true] + ]); + + StringArray1Array|CsvConversionError bm1sa = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, StringArray1Array); + test:assertTrue(bm1sa is CsvConversionError); + test:assertEquals((bm1sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringArray1Array|CsvConversionError bm2sa = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, StringArray1Array); + test:assertTrue(bm2sa is CsvConversionError); + test:assertEquals((bm2sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringArray1Array|CsvConversionError bm3sa = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, StringArray1Array); + test:assertTrue(bm3sa is CsvConversionError); + test:assertEquals((bm3sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringArray1Array|CsvConversionError bm4sa = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, StringArray1Array); + test:assertTrue(bm4sa is CsvConversionError); + test:assertEquals((bm4sa).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); + + StringArray1Array|CsvConversionError bm5sa = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, StringArray1Array); + test:assertTrue(bm5sa is CsvConversionError); + test:assertEquals((bm5sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); +} + +@test:Config {enable} +function testFromCsvWithTypeForMapAndTupleAsExpectedType() { + BooleanTuple1Array|CsvConversionError bm1bt = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple1Array); + test:assertEquals(bm1bt, [ + [true, false, false, false], + [true, false, false, false] + ]); + + BooleanTuple1Array|CsvConversionError bm2bt = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple1Array); + test:assertTrue(bm2bt is CsvConversionError); + test:assertEquals((bm2bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple1Array|CsvConversionError bm3bt = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple1Array); + test:assertTrue(bm3bt is CsvConversionError); + test:assertEquals((bm3bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple1Array|CsvConversionError bm4bt = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, BooleanTuple1Array); + test:assertTrue(bm4bt is CsvConversionError); + test:assertEquals((bm4bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + + BooleanTuple1Array|CsvConversionError bm5bt = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple1Array); + test:assertTrue(bm5bt is CsvConversionError); + test:assertEquals((bm5bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple2Array|CsvConversionError bm1b2t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple2Array); + test:assertEquals(bm1b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|CsvConversionError bm2b2t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple2Array); + test:assertEquals(bm2b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|CsvConversionError bm3b2t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple2Array); + test:assertEquals(bm3b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|CsvConversionError bm4b2t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, BooleanTuple2Array); + test:assertTrue(bm4b2t is CsvConversionError); + test:assertEquals((bm4b2t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + + BooleanTuple2Array|CsvConversionError bm5b2t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple2Array); + test:assertEquals(bm5b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple3Array|CsvConversionError bm1b3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple3Array); + test:assertEquals(bm1b3t, [ + [true, false], + [true, false] + ]); + + BooleanTuple3Array|CsvConversionError bm2b3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple3Array); + test:assertTrue(bm2b3t is CsvConversionError); + test:assertEquals((bm2b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple3Array|CsvConversionError bm3b3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple3Array); + test:assertTrue(bm3b3t is CsvConversionError); + test:assertEquals((bm3b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple3Array|CsvConversionError bm4b3t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, BooleanTuple3Array); + test:assertTrue(bm4b3t is CsvConversionError); + test:assertEquals((bm4b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + + BooleanTuple3Array|CsvConversionError bm5b3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple3Array); + test:assertTrue(bm5b3t is CsvConversionError); + test:assertEquals((bm5b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple4Array|CsvConversionError bm1b4t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple4Array); + test:assertEquals(bm1b4t, [ + [true, false], + [true, false] + ]); + + BooleanTuple4Array|CsvConversionError bm2b4t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple4Array); + test:assertTrue(bm2b4t is CsvConversionError); + test:assertEquals((bm2b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple4Array|CsvConversionError bm3b4t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple4Array); + test:assertTrue(bm3b4t is CsvConversionError); + test:assertEquals((bm3b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + BooleanTuple4Array|CsvConversionError bm4b4t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, BooleanTuple4Array); + test:assertTrue(bm4b4t is CsvConversionError); + test:assertEquals((bm4b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + + BooleanTuple4Array|CsvConversionError bm5b4t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple4Array); + test:assertTrue(bm5b4t is CsvConversionError); + test:assertEquals((bm5b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + + NillableBooleanTuple5Array|CsvConversionError bm1nbt = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple5Array); + test:assertEquals(bm1nbt, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + NillableBooleanTuple5Array|CsvConversionError bm2nbt = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple5Array); + test:assertEquals(bm2nbt, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + NillableBooleanTuple5Array|CsvConversionError bm3nbt = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple5Array); + test:assertTrue(bm3nbt is CsvConversionError); + test:assertEquals((bm3nbt).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); + + NillableBooleanTuple5Array|CsvConversionError bm4nbt = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableBooleanTuple5Array); + test:assertEquals(bm4nbt, [ + [(), (), (), (), ()], + [(), (), (), (), ()] + ]); + + NillableBooleanTuple5Array|CsvConversionError bm5nbt = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple5Array); + test:assertEquals(bm5nbt, [ + [true, false, (), true, ()], + [true, false, (), true, ()] + ]); + + NillableBooleanTuple6Array|CsvConversionError bm1nb6t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple6Array); + test:assertEquals(bm1nb6t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|CsvConversionError bm2nb6t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple6Array); + test:assertEquals(bm2nb6t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|CsvConversionError bm3nb6t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple6Array); + test:assertEquals(bm3nb6t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|CsvConversionError bm4nb6t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableBooleanTuple6Array); + test:assertEquals(bm4nb6t, [ + [(), ()], + [(), ()] + ]); + + NillableBooleanTuple6Array|CsvConversionError bm5nb6t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple6Array); + test:assertEquals(bm5nb6t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple7Array|CsvConversionError bm1nb7t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple7Array); + test:assertEquals(bm1nb7t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple7Array|CsvConversionError bm2nb7t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple7Array); + test:assertEquals(bm2nb7t, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + NillableBooleanTuple7Array|CsvConversionError bm3nb7t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple7Array); + test:assertTrue(bm3nb7t is CsvConversionError); + test:assertEquals((bm3nb7t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); + + NillableBooleanTuple7Array|CsvConversionError bm4nb7t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableBooleanTuple7Array); + test:assertEquals(bm4nb7t, [ + [(), ()], + [(), ()] + ]); + + NillableBooleanTuple7Array|CsvConversionError bm5nb7t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple7Array); + test:assertEquals(bm5nb7t, [ + [true, false, (), true], + [true, false, (), true] + ]); + + NillableBooleanTuple8Array|CsvConversionError bm1nb8t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple8Array); + test:assertEquals(bm1nb8t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple8Array|CsvConversionError bm2nb8t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple8Array); + test:assertEquals(bm2nb8t, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + NillableBooleanTuple8Array|CsvConversionError bm3nb8t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple8Array); + test:assertTrue(bm3nb8t is CsvConversionError); + test:assertEquals((bm3nb8t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); + + NillableBooleanTuple8Array|CsvConversionError bm4nb8t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableBooleanTuple8Array); + test:assertEquals(bm4nb8t, [ + [(), ()], + [(), ()] + ]); + + NillableBooleanTuple8Array|CsvConversionError bm5nb8t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple8Array); + test:assertEquals(bm5nb8t, [ + [true, false, (), true], + [true, false, (), true] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError bm1nb9t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm1nb9t, [ + [true, false], + [true, false] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError bm2nb9t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm2nb9t, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError bm3nb9t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm3nb9t, [ + [true, false, (), false, 1], + [true, false, (), false, 1] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError bm4nb9t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm4nb9t, [ + [(), ()], + [(), ()] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError bm5nb9t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm5nb9t, [ + [true, false, (), true], + [true, false, (), true] + ]); + + NilTuple3Array|CsvConversionError bm1n3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NilTuple3Array); + test:assertTrue(bm1n3t is CsvConversionError); + test:assertEquals((bm1n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + + NilTuple3Array|CsvConversionError bm2n3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NilTuple3Array); + test:assertTrue(bm2n3t is CsvConversionError); + test:assertEquals((bm2n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + + NilTuple3Array|CsvConversionError bm3n3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NilTuple3Array); + test:assertTrue(bm3n3t is CsvConversionError); + test:assertEquals((bm3n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + + NilTuple3Array|CsvConversionError bm4n3t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NilTuple3Array); + test:assertEquals(bm4n3t, [ + [(), ()], + [(), ()] + ]); + + NilTuple3Array|CsvConversionError bm5n3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NilTuple3Array); + test:assertTrue(bm5n3t is CsvConversionError); + test:assertEquals((bm5n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); +} + +@test:Config {enable} +function testFromCsvWithTypeForMapAndArrayAsExpectedType2() { + + AnydataTuple3Array|CsvConversionError bm1anyd3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataTuple3Array); + test:assertEquals(bm1anyd3t, [ + [true, false], + [true, false] + ]); + + AnydataTuple3Array|CsvConversionError bm2anyd3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, AnydataTuple3Array); + test:assertEquals(bm2anyd3t, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + AnydataTuple3Array|CsvConversionError bm3anyd3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, AnydataTuple3Array); + test:assertEquals(bm3anyd3t, [ + [true, false, (), false, 1], + [true, false, (), false, 1] + ]); + + AnydataTuple3Array|CsvConversionError bm4anyd3t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, AnydataTuple3Array); + test:assertEquals(bm4anyd3t, [ + [(), ()], + [(), ()] + ]); + + AnydataTuple3Array|CsvConversionError bm5anyd3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, AnydataTuple3Array); + test:assertEquals(bm5anyd3t, [ + [true, false, (), true], + [true, false, (), true] + ]); + + JsonTuple3Array|CsvConversionError bm1j3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, JsonTuple3Array); + test:assertEquals(bm1j3t, [ + [true, false], + [true, false] + ]); + + JsonTuple3Array|CsvConversionError bm2j3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, JsonTuple3Array); + test:assertEquals(bm2j3t, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + JsonTuple3Array|CsvConversionError bm3j3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, JsonTuple3Array); + test:assertEquals(bm3j3t, [ + [true, false, (), false, 1], + [true, false, (), false, 1] + ]); + + JsonTuple3Array|CsvConversionError bm4j3t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, JsonTuple3Array); + test:assertEquals(bm4j3t, [ + [(), ()], + [(), ()] + ]); + + JsonTuple3Array|CsvConversionError bm5j3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, JsonTuple3Array); + test:assertEquals(bm5j3t, [ + [true, false, (), true], + [true, false, (), true] + ]); + + StringTuple3Array|CsvConversionError bm1s3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, StringTuple3Array); + test:assertTrue(bm1s3t is CsvConversionError); + test:assertEquals((bm1s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringTuple3Array|CsvConversionError bm2s3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, StringTuple3Array); + test:assertTrue(bm2s3t is CsvConversionError); + test:assertEquals((bm2s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringTuple3Array|CsvConversionError bm3s3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, StringTuple3Array); + test:assertTrue(bm3s3t is CsvConversionError); + test:assertEquals((bm3s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + + StringTuple3Array|CsvConversionError bm4s3t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, StringTuple3Array); + test:assertTrue(bm4s3t is CsvConversionError); + test:assertEquals((bm4s3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); + + StringTuple3Array|CsvConversionError bm5s3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, StringTuple3Array); + test:assertTrue(bm5s3t is CsvConversionError); + test:assertEquals((bm5s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); +} diff --git a/ballerina/tests/parse_record_type_as_record_test.bal b/ballerina/tests/parse_record_type_as_record_test.bal new file mode 100644 index 0000000..be66a07 --- /dev/null +++ b/ballerina/tests/parse_record_type_as_record_test.bal @@ -0,0 +1,733 @@ +import ballerina/test; + +// boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() { +// StringRecord10Array|CsvConversionError st1sr10 = parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); +// test:assertEquals(st1sr10, [ +// {'1: "string", '2: ""}, +// {'1: "string", '2: ""} +// ]); +// } + +@test:Config {enable} +function testFromCsvWithTypeForMapAndRecordAsExpectedType() { + BooleanRecord1Array|CsvConversionError bm1br1 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord1Array); + test:assertTrue(bm1br1 is CsvConversionError); + test:assertEquals((bm1br1).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord1Array|CsvConversionError bm2br1 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord1Array); + test:assertTrue(bm2br1 is CsvConversionError); + test:assertEquals((bm2br1).message(), generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord1Array|CsvConversionError bm3br1 = parseRecordAsRecordType([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|CsvConversionError bm4br1 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord1Array); + test:assertTrue(bm4br1 is CsvConversionError); + test:assertEquals((bm4br1).message(), generateErrorMessageForMissingRequiredField("b2")); + + BooleanRecord1Array|CsvConversionError bm5br1 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord1Array); + test:assertEquals(bm5br1, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + BooleanRecord2Array|CsvConversionError bm1br2 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord2Array); + test:assertTrue(bm1br2 is CsvConversionError); + test:assertEquals((bm1br2).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord2Array|CsvConversionError bm2br2 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord2Array); + test:assertTrue(bm2br2 is CsvConversionError); + test:assertEquals((bm2br2).message(), generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord2Array|CsvConversionError bm3br2 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord2Array); + test:assertEquals(bm3br2, [ + {b1: true, b2: false, b3: (), b4: false}, + {b1: true, b2: false, b3: (), b4: false} + ]); + + BooleanRecord2Array|CsvConversionError bm4br2 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord2Array); + test:assertTrue(bm4br2 is CsvConversionError); + test:assertEquals((bm4br2).message(), generateErrorMessageForMissingRequiredField("b2")); + + BooleanRecord2Array|CsvConversionError bm5br2 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord2Array); + test:assertEquals(bm5br2, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + BooleanRecord3Array|CsvConversionError bm1br3 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord3Array); + test:assertTrue(bm1br3 is CsvConversionError); + test:assertEquals((bm1br3).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord3Array|CsvConversionError bm2br3 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord3Array); + test:assertEquals(bm2br3, [ + {b1: true, b3: ()}, + {b1: true, b3: ()} + ]); + + BooleanRecord3Array|CsvConversionError bm3br3 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord3Array); + test:assertEquals(bm3br3, [ + {b1: true, b3: ()}, + {b1: true, b3: ()} + ]); + + BooleanRecord3Array|CsvConversionError bm4br3 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord3Array); + test:assertTrue(bm4br3 is CsvConversionError); + test:assertEquals((bm4br3).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord3Array|CsvConversionError bm5br3 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord3Array); + test:assertEquals(bm5br3, [{b1: true, b3: ()}, {b1: true, b3: ()}]); + + BooleanRecord4Array|CsvConversionError bm1br4 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord4Array); + test:assertTrue(bm1br4 is CsvConversionError); + test:assertEquals((bm1br4).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord4Array|CsvConversionError bm2br4 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord4Array); + test:assertEquals(bm2br4, [ + {b1: true, b2: false, b3: (), n1: (), n3: ()}, + {b1: true, b2: false, b3: (), n1: (), n3: ()} + ]); + + BooleanRecord4Array|CsvConversionError bm3br4 = parseRecordAsRecordType([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|CsvConversionError bm4br4 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord4Array); + test:assertTrue(bm4br4 is CsvConversionError); + test:assertEquals((bm4br4).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord4Array|CsvConversionError bm5br4 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord4Array); + test:assertEquals(bm5br4, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + BooleanRecord5Array|CsvConversionError bm1br5 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord5Array); + test:assertTrue(bm1br5 is CsvConversionError); + test:assertEquals((bm1br5).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord5Array|CsvConversionError bm2br5 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord5Array); + test:assertEquals(bm2br5, [ + {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()} + ]); + + BooleanRecord5Array|CsvConversionError bm3br5 = parseRecordAsRecordType([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|CsvConversionError bm4br5 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord5Array); + test:assertTrue(bm4br5 is CsvConversionError); + test:assertEquals((bm4br5).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord5Array|CsvConversionError bm5br5 = parseRecordAsRecordType([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|CsvConversionError bm1br6 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord6Array); + test:assertTrue(bm1br6 is CsvConversionError); + test:assertEquals((bm1br6).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord6Array|CsvConversionError bm2br6 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord6Array); + test:assertEquals(bm2br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError bm3br6 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord6Array); + test:assertEquals(bm3br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError bm4br6 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord6Array); + test:assertTrue(bm4br6 is CsvConversionError); + test:assertEquals((bm4br6).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord6Array|CsvConversionError bm5br6 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord6Array); + test:assertEquals(bm5br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord7Array|CsvConversionError bm1br7 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord7Array); + test:assertTrue(bm1br7 is CsvConversionError); + test:assertEquals((bm1br7).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord7Array|CsvConversionError bm2br7 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord7Array); + test:assertTrue(bm2br7 is CsvConversionError); + test:assertEquals((bm2br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord7Array|CsvConversionError bm3br7 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord7Array); + test:assertTrue(bm3br7 is CsvConversionError); + test:assertEquals((bm3br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord7Array|CsvConversionError bm4br7 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord7Array); + test:assertTrue(bm4br7 is CsvConversionError); + test:assertEquals((bm4br7).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord7Array|CsvConversionError bm5br7 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord7Array); + test:assertTrue(bm5br7 is CsvConversionError); + test:assertEquals((bm5br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord8Array|CsvConversionError bm1br8 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord8Array); + test:assertTrue(bm1br8 is CsvConversionError); + test:assertEquals((bm1br8).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord8Array|CsvConversionError bm2br8 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord8Array); + test:assertTrue(bm2br8 is CsvConversionError); + test:assertEquals((bm2br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord8Array|CsvConversionError bm3br8 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord8Array); + test:assertTrue(bm3br8 is CsvConversionError); + test:assertEquals((bm3br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord8Array|CsvConversionError bm4br8 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord8Array); + test:assertTrue(bm4br8 is CsvConversionError); + test:assertEquals((bm4br8).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord8Array|CsvConversionError bm5br8 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord8Array); + test:assertTrue(bm5br8 is CsvConversionError); + test:assertEquals((bm5br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); +} + +@test:Config {enable} +function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { + BooleanRecord9Array|CsvConversionError bm1br9 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord9Array); + test:assertTrue(bm1br9 is CsvConversionError); + test:assertEquals((bm1br9).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord9Array|CsvConversionError bm2br9 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord9Array); + test:assertEquals(bm2br9, [ + {b1: true, b2: false, b3: (), n1: (), n3: ()}, + {b1: true, b2: false, b3: (), n1: (), n3: ()} + ]); + + BooleanRecord9Array|CsvConversionError bm3br9 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord9Array); + test:assertEquals(bm3br9, [ + {b1: true, b2: false, b3: (), b4: false}, + {b1: true, b2: false, b3: (), b4: false} + ]); + + BooleanRecord9Array|CsvConversionError bm4br9 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord9Array); + test:assertTrue(bm4br9 is CsvConversionError); + test:assertEquals((bm4br9).message(), generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord9Array|CsvConversionError bm5br9 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord9Array); + test:assertEquals(bm5br9, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + BooleanRecord10Array|CsvConversionError bm1br10 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord10Array); + test:assertEquals(bm1br10, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanRecord10Array|CsvConversionError bm2br10 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord10Array); + test:assertEquals(bm2br10, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanRecord10Array|CsvConversionError bm3br10 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord10Array); + test:assertEquals(bm3br10, [ + {b1: true, b2: false, b4: false}, + {b1: true, b2: false, b4: false} + ]); + + BooleanRecord10Array|CsvConversionError bm4br10 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord10Array); + test:assertEquals(bm4br10, [ + {}, + {} + ]); + + BooleanRecord10Array|CsvConversionError bm5br10 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord10Array); + test:assertEquals(bm5br10, [ + {b1: true, b2: false, b4: true}, + {b1: true, b2: false, b4: true} + ]); + + BooleanRecord11Array|CsvConversionError bm1br11 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord11Array); + test:assertEquals(bm1br11, [ + {b1: true, b2: false, defaultableField: "", nillableField :null}, + {b1: true, b2: false, defaultableField: "", nillableField :null} + ]); + + BooleanRecord11Array|CsvConversionError bm2br11 = parseRecordAsRecordType([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|CsvConversionError bm3br11 = parseRecordAsRecordType([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|CsvConversionError bm4br11 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord11Array); + test:assertTrue(bm4br11 is CsvConversionError); + test:assertEquals((bm4br11).message(), generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord11Array|CsvConversionError bm5br11 = parseRecordAsRecordType([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|CsvConversionError bm1br12 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord12Array); + test:assertTrue(bm1br12 is CsvConversionError); + test:assertEquals((bm1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord12Array|CsvConversionError bm2br12 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord12Array); + test:assertTrue(bm2br12 is CsvConversionError); + test:assertEquals((bm2br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord12Array|CsvConversionError bm3br12 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord12Array); + test:assertTrue(bm3br12 is CsvConversionError); + test:assertEquals((bm3br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord12Array|CsvConversionError bm4br12 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord12Array); + test:assertTrue(bm4br12 is CsvConversionError); + test:assertEquals((bm4br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord12Array|CsvConversionError bm5br12 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord12Array); + test:assertTrue(bm5br12 is CsvConversionError); + test:assertEquals((bm5br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord13Array|CsvConversionError bm1br13 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord13Array); + test:assertEquals(bm1br13, [ + {b1: true, b2: false, defaultableField: "", nillableField :null}, + {b1: true, b2: false, defaultableField: "", nillableField :null} + ]); + + BooleanRecord13Array|CsvConversionError bm2br13 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord13Array); + test:assertEquals(bm2br13, [ + {b1: true, b2: false, defaultableField: "", nillableField :null}, + {b1: true, b2: false, defaultableField: "", nillableField :null} + ]); + + BooleanRecord13Array|CsvConversionError bm3br13 = parseRecordAsRecordType([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|CsvConversionError bm4br13 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord13Array); + test:assertEquals(bm4br13, [ + {defaultableField: "", nillableField :null}, + {defaultableField: "", nillableField :null} + ]); + + BooleanRecord13Array|CsvConversionError bm5br13 = parseRecordAsRecordType([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|CsvConversionError bm1br14 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord14Array); + test:assertTrue(bm1br14 is CsvConversionError); + test:assertEquals((bm1br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord14Array|CsvConversionError bm2br14 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord14Array); + test:assertTrue(bm2br14 is CsvConversionError); + test:assertEquals((bm2br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord14Array|CsvConversionError bm3br14 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord14Array); + test:assertTrue(bm3br14 is CsvConversionError); + test:assertEquals((bm3br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord14Array|CsvConversionError bm4br14 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord14Array); + test:assertTrue(bm4br14 is CsvConversionError); + test:assertEquals((bm4br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord14Array|CsvConversionError bm5br14 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord14Array); + test:assertTrue(bm5br14 is CsvConversionError); + test:assertEquals((bm5br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord15Array|CsvConversionError bm1br15 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord15Array); + test:assertTrue(bm1br15 is CsvConversionError); + test:assertEquals((bm1br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); + + BooleanRecord15Array|CsvConversionError bm3br15 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord15Array); + test:assertTrue(bm3br15 is CsvConversionError); + test:assertEquals((bm3br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); + + BooleanRecord15Array|CsvConversionError bm4br15 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord15Array); + test:assertTrue(bm4br15 is CsvConversionError); + test:assertEquals((bm4br15).message(), generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord16Array|CsvConversionError bm1br16 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord16Array); + test:assertEquals(bm1br16, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanRecord16Array|CsvConversionError bm2br16 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord16Array); + test:assertEquals(bm2br16, [ + {b1: true, b2: false, b3: (), n1: (), n3: ()}, + {b1: true, b2: false, b3: (), n1: (), n3: ()} + ]); + + BooleanRecord16Array|CsvConversionError bm3br16 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord16Array); + test:assertEquals(bm3br16, [ + {b1: true, b2: false, b4: false, b3: ()}, + {b1: true, b2: false, b4: false, b3: ()} + ]); + + BooleanRecord16Array|CsvConversionError bm4br16 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord16Array); + test:assertEquals(bm4br16, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + BooleanRecord16Array|CsvConversionError bm5br16 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord16Array); + test:assertEquals(bm5br16, [ + {b1: true, b2: false, b4: true, b3: ()}, + {b1: true, b2: false, b4: true, b3: ()} + ]); + + BooleanRecord17Array|CsvConversionError bm1br17 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord17Array); + test:assertEquals(bm1br17, [ + {}, + {} + ]); + + BooleanRecord17Array|CsvConversionError bm2br17 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord17Array); + test:assertEquals(bm2br17, [ + {}, + {} + ]); + + BooleanRecord17Array|CsvConversionError bm3br17 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord17Array); + test:assertEquals(bm3br17, [ + {i1: 1}, + {i1: 1} + ]); + + BooleanRecord17Array|CsvConversionError bm4br17 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord17Array); + test:assertEquals(bm4br17, [ + {}, + {} + ]); + + BooleanRecord17Array|CsvConversionError bm5br17 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord17Array); + test:assertEquals(bm5br17, [ + {}, + {} + ]); + + BooleanRecord18Array|CsvConversionError bm1br18 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord18Array); + test:assertEquals(bm1br18, [ + {b2: false}, + {b2: false} + ]); + + BooleanRecord18Array|CsvConversionError bm2br18 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord18Array); + test:assertEquals(bm2br18, [ + {b2: false, b3: (), n1: (), n3: ()}, + {b2: false, b3: (), n1: (), n3: ()} + ]); + + BooleanRecord18Array|CsvConversionError bm3br18 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord18Array); + test:assertEquals(bm3br18, [ + {b2: false, b3: (), i1: 1}, + {b2: false, b3: (), i1: 1} + ]); + + BooleanRecord18Array|CsvConversionError bm4br18 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord18Array); + test:assertTrue(bm4br18 is CsvConversionError); + test:assertEquals((bm4br18).message(), generateErrorMessageForMissingRequiredField("b2")); + + BooleanRecord18Array|CsvConversionError bm5br18 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord18Array); + test:assertEquals(bm5br18, [ + {b2: false, b3: ()}, + {b2: false, b3: ()} + ]); +} + +@test:Config {enable} +function testFromCsvWithTypeForMapAndMapAsExpectedType() { + BooleanMapArray|CsvConversionError bm1bma = parseRecordAsRecordType([bm1, bm1], {}, BooleanMapArray); + test:assertEquals(bm1bma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanMapArray|CsvConversionError bm2bma = parseRecordAsRecordType([bm2, bm2], {}, BooleanMapArray); + test:assertEquals(bm2bma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanMapArray|CsvConversionError bm3bma = parseRecordAsRecordType([bm3, bm3], {}, BooleanMapArray); + test:assertEquals(bm3bma, [ + {b1: true, b2: false, b4: false}, + {b1: true, b2: false, b4: false} + ]); + + BooleanMapArray|CsvConversionError bm4bma = parseRecordAsRecordType([bm4, bm4], {}, BooleanMapArray); + test:assertEquals(bm4bma, [ + {}, + {} + ]); + + BooleanMapArray|CsvConversionError bm5bma = parseRecordAsRecordType([bm5, bm5], {}, BooleanMapArray); + test:assertEquals(bm5bma, [ + {b1: true, b2: false, b4: true}, + {b1: true, b2: false, b4: true} + ]); + + NillableBooleanMapArray|CsvConversionError bm1nbma = parseRecordAsRecordType([bm1, bm1], {}, NillableBooleanMapArray); + test:assertEquals(bm1nbma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + NillableBooleanMapArray|CsvConversionError bm2nbma = parseRecordAsRecordType([bm2, bm2], {}, NillableBooleanMapArray); + test:assertEquals(bm2nbma, [ + {b1: true, b2: false, b3:(), n1: (), n3: ()}, + {b1: true, b2: false, b3:(), n1: (), n3: ()} + ]); + + NillableBooleanMapArray|CsvConversionError bm3nbma = parseRecordAsRecordType([bm3, bm3], {}, NillableBooleanMapArray); + test:assertEquals(bm3nbma, [ + {b1: true, b2: false, b3:(), b4: false}, + {b1: true, b2: false, b3:(), b4: false} + ]); + + NillableBooleanMapArray|CsvConversionError bm4nbma = parseRecordAsRecordType([bm4, bm4], {}, NillableBooleanMapArray); + test:assertEquals(bm4nbma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + NillableBooleanMapArray|CsvConversionError bm5nbma = parseRecordAsRecordType([bm5, bm5], {}, NillableBooleanMapArray); + test:assertEquals(bm5nbma, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bm1niubma = parseRecordAsRecordType([bm1, bm1], {}, NillableIntUnionBooleanMapArray); + test:assertEquals(bm1niubma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bm2niubma = parseRecordAsRecordType([bm2, bm2], {}, NillableIntUnionBooleanMapArray); + test:assertEquals(bm2niubma, [ + {b1: true, b2: false, b3:(), n1: (), n3: ()}, + {b1: true, b2: false, b3:(), n1: (), n3: ()} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bm3niubma = parseRecordAsRecordType([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|CsvConversionError bm4niubma = parseRecordAsRecordType([bm4, bm4], {}, NillableIntUnionBooleanMapArray); + test:assertEquals(bm4niubma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bm5niubma = parseRecordAsRecordType([bm5, bm5], {}, NillableIntUnionBooleanMapArray); + test:assertEquals(bm5niubma, [ + {b1: true, b2: false, b3: (), b4: true}, + {b1: true, b2: false, b3: (), b4: true} + ]); + + IntUnionBooleanMapArray|CsvConversionError bm1iubma = parseRecordAsRecordType([bm1, bm1], {}, IntUnionBooleanMapArray); + test:assertEquals(bm1iubma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + IntUnionBooleanMapArray|CsvConversionError bm2iubma = parseRecordAsRecordType([bm2, bm2], {}, IntUnionBooleanMapArray); + test:assertEquals(bm2iubma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + IntUnionBooleanMapArray|CsvConversionError bm3iubma = parseRecordAsRecordType([bm3, bm3], {}, IntUnionBooleanMapArray); + test:assertEquals(bm3iubma, [ + {b1: true, b2: false, b4: false, i1: 1}, + {b1: true, b2: false, b4: false, i1: 1} + ]); + + IntUnionBooleanMapArray|CsvConversionError bm4iubma = parseRecordAsRecordType([bm4, bm4], {}, IntUnionBooleanMapArray); + test:assertEquals(bm4iubma, [ + {}, + {} + ]); + + IntUnionBooleanMapArray|CsvConversionError bm5iubma = parseRecordAsRecordType([bm5, bm5], {}, IntUnionBooleanMapArray); + test:assertEquals(bm5iubma, [ + {b1: true, b2: false, b4: true}, + {b1: true, b2: false, b4: true} + ]); + + NilMapArray|CsvConversionError bm1nma = parseRecordAsRecordType([bm1, bm1], {}, NilMapArray); + test:assertEquals(bm1nma, [ + {}, + {} + ]); + + NilMapArray|CsvConversionError bm2nma = parseRecordAsRecordType([bm2, bm2], {}, NilMapArray); + test:assertEquals(bm2nma, [ + {n1: (), n3: (), b3: ()}, + {n1: (), n3: (), b3: ()} + ]); + + NilMapArray|CsvConversionError bm3nma = parseRecordAsRecordType([bm3, bm3], {}, NilMapArray); + test:assertEquals(bm3nma, [ + {b3: ()}, + {b3: ()} + ]); + + NilMapArray|CsvConversionError bm4nma = parseRecordAsRecordType([bm4, bm4], {}, NilMapArray); + test:assertEquals(bm4nma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + NilMapArray|CsvConversionError bm5nma = parseRecordAsRecordType([bm5, bm5], {}, NilMapArray); + test:assertEquals(bm5nma, [ + {b3: ()}, + {b3: ()} + ]); + + JsonMapArray|CsvConversionError bm1jma = parseRecordAsRecordType([bm1, bm1], {}, JsonMapArray); + test:assertEquals(bm1jma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + JsonMapArray|CsvConversionError bm2jma = parseRecordAsRecordType([bm2, bm2], {}, JsonMapArray); + test:assertEquals(bm2jma, [ + {b1: true, b2: false, b3: (), n1: (), n3: ()}, + {b1: true, b2: false, b3: (), n1: (), n3: ()} + ]); + + JsonMapArray|CsvConversionError bm3jma = parseRecordAsRecordType([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|CsvConversionError bm4jma = parseRecordAsRecordType([bm4, bm4], {}, JsonMapArray); + test:assertEquals(bm4jma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + JsonMapArray|CsvConversionError bm5jma = parseRecordAsRecordType([bm5, bm5], {}, JsonMapArray); + test:assertEquals(bm5jma, [ + {b1: true, b2: false, b4: true, b3: ()}, + {b1: true, b2: false, b4: true, b3: ()} + ]); + + AnydataMapArray|CsvConversionError bm1anydma = parseRecordAsRecordType([bm1, bm1], {}, AnydataMapArray); + test:assertEquals(bm1anydma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + AnydataMapArray|CsvConversionError bm2anydma = parseRecordAsRecordType([bm2, bm2], {}, AnydataMapArray); + test:assertEquals(bm2anydma, [ + {b1: true, b2: false, b3: (), n1: (), n3: ()}, + {b1: true, b2: false, b3: (), n1: (), n3: ()} + ]); + + AnydataMapArray|CsvConversionError bm3anydma = parseRecordAsRecordType([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|CsvConversionError bm4anydma = parseRecordAsRecordType([bm4, bm4], {}, AnydataMapArray); + test:assertEquals(bm4anydma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + AnydataMapArray|CsvConversionError bm5anydma = parseRecordAsRecordType([bm5, bm5], {}, AnydataMapArray); + test:assertEquals(bm5anydma, [ + {b1: true, b2: false, b4: true, b3: ()}, + {b1: true, b2: false, b4: true, b3: ()} + ]); + + CustomMapArray|CsvConversionError bm1cma = parseRecordAsRecordType([bm1, bm1], {}, CustomMapArray); + test:assertEquals(bm1cma, [ + {}, + {} + ]); + + CustomMapArray|CsvConversionError bm2cma = parseRecordAsRecordType([bm2, bm2], {}, CustomMapArray); + test:assertEquals(bm2cma, [ + {}, + {} + ]); + + CustomMapArray|CsvConversionError bm3cma = parseRecordAsRecordType([bm3, bm3], {}, CustomMapArray); + test:assertEquals(bm3cma, [ + {i1: 1}, + {i1: 1} + ]); + + CustomMapArray|CsvConversionError bm4cma = parseRecordAsRecordType([bm4, bm4], {}, CustomMapArray); + test:assertEquals(bm4cma, [ + {}, + {} + ]); + + CustomMapArray|CsvConversionError bm5cma = parseRecordAsRecordType([bm5, bm5], {}, CustomMapArray); + test:assertEquals(bm5cma, [ + {}, + {} + ]); + + StringMapArray|CsvConversionError bm1sma = parseRecordAsRecordType([bm1, bm1], {}, StringMapArray); + test:assertEquals(bm1sma, [ + {}, + {} + ]); + + StringMapArray|CsvConversionError bm2sma = parseRecordAsRecordType([bm2, bm2], {}, StringMapArray); + test:assertEquals(bm2sma, [ + {}, + {} + ]); + + StringMapArray|CsvConversionError bm3sma = parseRecordAsRecordType([bm3, bm3], {}, StringMapArray); + test:assertEquals(bm3sma, [ + {}, + {} + ]); + + StringMapArray|CsvConversionError bm4sma = parseRecordAsRecordType([bm4, bm4], {}, StringMapArray); + test:assertEquals(bm4sma, [ + {}, + {} + ]); + + StringMapArray|CsvConversionError bm5sma = parseRecordAsRecordType([bm5, bm5], {}, StringMapArray); + test:assertEquals(bm5sma, [ + {}, + {} + ]); +} diff --git a/ballerina/tests/parse_string_compatibality_test.bal b/ballerina/tests/parse_string_compatibality_test.bal new file mode 100644 index 0000000..a8c4811 --- /dev/null +++ b/ballerina/tests/parse_string_compatibality_test.bal @@ -0,0 +1,208 @@ +import ballerina/test; + +// boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() { +// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// test:assertEquals(csvb4br1, [ +// {b1: true, b2: "()", b3: (), b4: false}, +// {b1: true, b2: "()", b3: (), b4: false} +// ]); +// } + +@test:Config {enable} +function testFromCsvStringWithTypeCompatibility() { + string value = string ` + i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 + ${i1},${i2},${s1},${s2},${b1},${b2},(),(),${f1}, ${f2},${d1},${d2},${b1},${d1},${b2},${d2} + ${i1},${i2},${s1},${s2},${b1},${b2},(),(), ${f1},${f2},${d1},${d2},${b1},${d1},${b2},${d2} + `; + string value2 = string ` + i1, s1, b1, n1, f1, d1, j1, a1, s2, s3, j2, a2 + ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3},${b2}, ${d2} + `; + string value3 = string ` + i1, s1, b1, n1, f1, d1, j1, a1, s2, s3 + ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3} + `; + + AnydataArray1Array|CsvConversionError v3anyd1a = parseStringToList(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|CsvConversionError vcr27a = parseStringToRecord(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|CsvConversionError v2cr27a = parseStringToRecord(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|CsvConversionError v3cr27a = parseStringToRecord(value3, {}); + test:assertEquals(v3cr27a, [ + {i1, s1, b1, n1, f1, d1, a1: 2.234, j1: b1, defaultableField: "", nillableField: null, s2, s3} + ]); + + AnydataMapArray|CsvConversionError vanydma = parseStringToRecord(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|CsvConversionError vjma = parseStringToRecord(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|CsvConversionError vsma = parseStringToRecord(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|CsvConversionError v2ct7a = parseStringToList(value2); + test:assertEquals(v2ct7a, [ + [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3, "false", "-3.21"] + ]); + + CustomTuple7Array|CsvConversionError v3ct7a = parseStringToList(value3); + test:assertEquals(v3ct7a, [ + [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3] + ]); + + // CustomTuple8Array|CsvConversionError v2ct8a = fromCsvStringWithType(value2); + // test:assertTrue(v2ct8a is CsvConversionError); + // test:assertEquals((v2ct8a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "int")); + + [float, decimal, string][]|CsvConversionError mrrta = parseStringToList(string `a, b,c + 1.23, 1.23, 1.23 + 0,0,0 + 0.0,0.0,0.0 + -1.2,-1.2,-1.2`); + test:assertEquals(mrrta, [ + [1.23, 1.23, "1.23"], + [0, 0, "0"], + [0, 0, "0.0"], + [-1.2, -1.2, "-1.2"] + ]); + + [float, decimal, string, int][]|CsvConversionError m2rrta = parseStringToList(string `a, b,c,d + 1, 1, 1,1 + 0,0,0,0 + -1,-1,-1,-1`); + test:assertEquals(m2rrta, [ + [1, 1, "1", 1], + [0, 0, "0", 0], + [-1, -1, "-1", -1] + ]); + + [int...][]|CsvConversionError m3rrta = parseStringToList(string `a, b,c,d + 1.2, abc, true,1.0`); + test:assertTrue(m3rrta is CsvConversionError); + test:assertEquals((m3rrta).message(), generateErrorMessageForInvalidCast("1.2", "int")); + + [boolean, int][]|CsvConversionError m4rrta = parseStringToList(string `a, b + 1, 1 + 0,0`); + test:assertEquals(m4rrta, [ + [true, 1], + [false, 0] + ]); + + record {|int...;|}[]|CsvConversionError irrma = parseStringToRecord(string ` + a, b, c + 1, a, 2.3 + 1, -2, true + hello, -2, hello`); + test:assertEquals(irrma, [ + {a: 1}, + {a: i1, b: i2}, + {b: i2} + ]); + + record {|()...;|}[]|CsvConversionError nrrma = parseStringToRecord(string ` + a, b, c + 1, a, () + 1, null, () + hello, -2, hello`); + test:assertEquals(nrrma, [ + {c: ()}, + {b: (), c: ()}, + {} + ]); + + record {|decimal...;|}[]|CsvConversionError drra = parseStringToRecord(string `a, b, c + 2.234, invalid , 1 + ${f2}, 0, 2.3d + invalid, ${d2}, ${f3}`); + test:assertTrue(drra is record {|decimal...;|}[]); + test:assertEquals(drra, [ + {a: d1, c: 1.0}, + {a: f2, b: d3}, + {b: -3.21d, c: f3} + ]); + + record {|string...;|}[]|CsvConversionError srra = parseStringToRecord(string ` + a, b, c + 1, a, 2.3 + 1, -2, true + hello, -2, hello`); + test:assertTrue(srra is record {|string...;|}[]); + test:assertEquals(srra, [ + {a: "1", b: "a", c: "2.3"}, + {a: "1", b: "-2", c: "true"}, + {a: "hello", b: "-2", c: "hello"} + ]); + + record {|float...;|}[]|CsvConversionError frra = parseStringToRecord(string `a, b, c + 1.2, invalid , 1 + ${d2}, ${d3}, true + ${d4}, ${f2}, 0.0`); + test:assertEquals(frra, [ + {a: 1.2, c: 1.0}, + {a: d2, b: d3}, + {a: d4, b: f2, c: 0.0} + ]); + + record {float a; decimal b; string c;}[]|CsvConversionError mrra = parseStringToRecord(string `a, b,c + 1.23, 1.23, 1.23 + 0,0,0 + 0.0,0.0,0.0 + -1.2,-1.2,-1.2`); + test:assertEquals(mrra, [ + {a: 1.23, b: 1.23, c: "1.23"}, + {a: 0, b: 0, c: "0"}, + {a: 0, b: 0, c: "0.0"}, + {a: -1.2, b: -1.2, c: "-1.2"} + ]); + + record {|float a; decimal b; string c; int d;|}[]|CsvConversionError m2rra = parseStringToRecord(string `a, b,c,d + 1, 1, 1,1 + 0,0,0,0 + -1,-1,-1,-1`); + test:assertEquals(m2rra, [ + {a: 1, b: 1, c: "1", d: 1}, + {a: 0, b: 0, c: "0", d: 0}, + {a: -1, b: -1, c: "-1", d: -1} + ]); + + record {int d;}[]|CsvConversionError m3rra = parseStringToRecord(string `a, b,c,d + 1.2, abc, true,1.0`); + test:assertTrue(m3rra is CsvConversionError); + test:assertEquals((m3rra).message(), generateErrorMessageForInvalidCast("1.0", "int")); + + record {int b; boolean a;}[]|CsvConversionError m4rra = parseStringToRecord(string `a, b + 1, 1 + 0,0`); + test:assertEquals(m4rra, [ + {a: true, b: 1}, + {a: false, b: 0} + ]); +} \ No newline at end of file diff --git a/ballerina/tests/parse_string_to_array_test.bal b/ballerina/tests/parse_string_to_array_test.bal new file mode 100644 index 0000000..92a3a13 --- /dev/null +++ b/ballerina/tests/parse_string_to_array_test.bal @@ -0,0 +1,314 @@ +import ballerina/test; + +// boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() { +// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// test:assertEquals(csvb4br1, [ +// {b1: true, b2: "()", b3: (), b4: false}, +// {b1: true, b2: "()", b3: (), b4: false} +// ]); +// } + +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { + BooleanArrayArray|CsvConversionError cv1baa = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1baa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanArrayArray|CsvConversionError cv2baa = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2baa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + BooleanArrayArray|CsvConversionError cv3baa = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cv3baa is CsvConversionError); + test:assertEquals((cv3baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanArrayArray|CsvConversionError cv4baa = parseStringToList(csvStringWithBooleanValues4); + test:assertTrue(cv4baa is CsvConversionError); + test:assertEquals((cv4baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanArrayArray|CsvConversionError cv5baa = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cv5baa is CsvConversionError); + test:assertEquals((cv5baa).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanArrayArray|CsvConversionError cv6baa = parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cv6baa is CsvConversionError); + test:assertEquals((cv6baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanArrayArray|CsvConversionError cv7baa = parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cv7baa is CsvConversionError); + test:assertEquals((cv7baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + NillableBooleanArrayArray|CsvConversionError cv1nbaa = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1nbaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableBooleanArrayArray|CsvConversionError cv2nbaa = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2nbaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanArrayArray|CsvConversionError cv3nbaa = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3nbaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableBooleanArrayArray|CsvConversionError cv4nbaa = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4nbaa, [ + [true, (), (), false], + [true, (), (), false] + ]); + + NillableBooleanArrayArray|CsvConversionError cv5nbaa = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cv5nbaa is CsvConversionError); + test:assertEquals((cv5nbaa).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanArrayArray|CsvConversionError cv6nbaa = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6nbaa, [ + [(), ()] + ]); + + NillableBooleanArrayArray|CsvConversionError cv7nbaa = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7nbaa, [ + [b1, b2, (), b4] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv1niubaa = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1niubaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv2niubaa = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2niubaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv3niubaa = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3niubaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv4niubaa = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4niubaa, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv5niubaa = parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cv5niubaa, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv6niubaa = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6niubaa, [ + [(), ()] + ]); + + NillableIntOrUnionBooleanArrayArray|CsvConversionError cv7niubaa = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7niubaa, [ + [b1, b2, (), b4] + ]); + + StringArray1Array|CsvConversionError cv1saa = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1saa, [ + ["true", "false", "true", "false"], + ["true", "false", "true", "false"], + ["true", "false", "true", "false"] + ]); + + StringArray1Array|CsvConversionError cv2saa = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2saa, [ + ["true", "false", "true", "false", "true"], + ["true", "false", "true", "false", "true"] + ]); + + StringArray1Array|CsvConversionError cv3saa = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3saa, [ + ["true", "false", "true"], + ["TRUE", "FALSE", "()"], + ["true", "true", "FALSE"] + ]); + + StringArray1Array|CsvConversionError cv4saa = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4saa, [ + ["true", "()", "()", "0"], + ["1", "()", "null", "false"] + ]); + + StringArray1Array|CsvConversionError cv5saa = parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cv5saa, [ + ["true", "false", "true", "2"], + ["true", "false", "true", "3"] + ]); + + StringArray1Array|CsvConversionError cv6saa = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6saa, [ + ["()", "()"] + ]); + + StringArray1Array|CsvConversionError cv7saa = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7saa, [ + ["true", "false", "()", "false"] + ]); + + StringArray2Array|CsvConversionError cv1s2aa = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1s2aa, [ + ["true", "false"], + ["true", "false"], + ["true", "false"] + ]); + + StringArray2Array|CsvConversionError cv2s2aa = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2s2aa, [ + ["true", "false"], + ["true", "false"] + ]); + + StringArray2Array|CsvConversionError cv3s2aa = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3s2aa, [ + ["true", "false"], + ["TRUE", "FALSE"], + ["true", "true"] + ]); + + StringArray2Array|CsvConversionError cv4s2aa = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4s2aa, [ + ["true", "()"], + ["1", "()"] + ]); + + StringArray2Array|CsvConversionError cv5s2aa = parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cv5s2aa, [ + ["true", "false"], + ["true", "false"] + ]); + + StringArray2Array|CsvConversionError cv6s2aa = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6s2aa, [ + ["()", "()"] + ]); + + StringArray2Array|CsvConversionError cv7s2aa = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7s2aa, [ + ["true", "false"] + ]); + + JsonArray1Array|CsvConversionError cv1jaa = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1jaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + JsonArray1Array|CsvConversionError cv2jaa = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2jaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + JsonArray1Array|CsvConversionError cv3jaa = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3jaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + JsonArray1Array|CsvConversionError cv4jaa = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4jaa, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + JsonArray1Array|CsvConversionError cv5jaa = parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cv5jaa, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + JsonArray1Array|CsvConversionError cv6jaa = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6jaa, [ + [(), ()] + ]); + + JsonArray1Array|CsvConversionError cv7jaa = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7jaa, [ + [b1, b2, (), b4] + ]); + + AnydataArray1Array|CsvConversionError cv1anydaa = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1anydaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + AnydataArray1Array|CsvConversionError cv2anydaa = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2anydaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + AnydataArray1Array|CsvConversionError cv3anydaa = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3anydaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + AnydataArray1Array|CsvConversionError cv4anydaa = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4anydaa, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + AnydataArray1Array|CsvConversionError cv5anydaa = parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cv5anydaa, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + AnydataArray1Array|CsvConversionError cv6anydaa = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6anydaa, [ + [(), ()] + ]); + + AnydataArray1Array|CsvConversionError cv7anydaa = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7anydaa, [ + [b1, b2, (), b4] + ]); + + DecimalArray1Array|CsvConversionError cv1daa = parseStringToList(csvStringWithBooleanValues1); + test:assertTrue(cv1daa is CsvConversionError); + test:assertEquals((cv1daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); + + DecimalArray1Array|CsvConversionError cv3daa = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cv3daa is CsvConversionError); + test:assertEquals((cv3daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); + + DecimalArray1Array|CsvConversionError cv6daa = parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cv6daa is CsvConversionError); + test:assertEquals((cv6daa).message(), generateErrorMessageForInvalidCast("()", "decimal")); + + DecimalArray1Array|CsvConversionError cv7daa = parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cv7daa is CsvConversionError); + test:assertEquals((cv7daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); +} diff --git a/ballerina/tests/parse_string_to_map_tests copy.bal b/ballerina/tests/parse_string_to_map_tests copy.bal new file mode 100644 index 0000000..88fd2c6 --- /dev/null +++ b/ballerina/tests/parse_string_to_map_tests copy.bal @@ -0,0 +1,409 @@ +import ballerina/test; + +// boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() { +// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// test:assertEquals(csvb4br1, [ +// {b1: true, b2: "()", b3: (), b4: false}, +// {b1: true, b2: "()", b3: (), b4: false} +// ]); +// } + +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { + BooleanMapArray|CsvConversionError bv1bma = parseStringToRecord(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|CsvConversionError bv2bma = parseStringToRecord(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|CsvConversionError bv3bma = parseStringToRecord(csvStringWithBooleanValues3); + test:assertEquals(bv3bma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false}, + {b1: true, b2: true, b3: false} + ]); + + BooleanMapArray|CsvConversionError bv4bma = parseStringToRecord(csvStringWithBooleanValues4); + test:assertEquals(bv4bma, [ + {b1: true, b4: false}, + {b1: true, b4: false} + ]); + + BooleanMapArray|CsvConversionError bv5bma = parseStringToRecord(csvStringWithBooleanValues5); + test:assertEquals(bv5bma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + BooleanMapArray|CsvConversionError bv6bma = parseStringToRecord(csvStringWithBooleanValues6); + test:assertEquals(bv6bma, [ + {} + ]); + + BooleanMapArray|CsvConversionError bv7bma = parseStringToRecord(csvStringWithBooleanValues7); + test:assertEquals(bv7bma, [ + {b1, b2, b4} + ]); + + NillableBooleanMapArray|CsvConversionError bv1bnbma = parseStringToRecord(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|CsvConversionError bv2bnbma = parseStringToRecord(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|CsvConversionError bv3bnbma = parseStringToRecord(csvStringWithBooleanValues3); + test:assertEquals(bv3bnbma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: null}, + {b1: true, b2: true, b3: false} + ]); + + NillableBooleanMapArray|CsvConversionError bv4bnbma = parseStringToRecord(csvStringWithBooleanValues4); + test:assertEquals(bv4bnbma, [ + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} + ]); + + NillableBooleanMapArray|CsvConversionError bv5bnbma = parseStringToRecord(csvStringWithBooleanValues5); + test:assertEquals(bv5bnbma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + NillableBooleanMapArray|CsvConversionError bv6bnbma = parseStringToRecord(csvStringWithBooleanValues6); + test:assertEquals(bv6bnbma, [ + {b2: (), b3: ()} + ]); + + NillableBooleanMapArray|CsvConversionError bv7bnbma = parseStringToRecord(csvStringWithBooleanValues7); + test:assertEquals(bv7bnbma, [ + {b1, b2, b3, b4} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv1bniubma = parseStringToRecord(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|CsvConversionError bv2bniubma = parseStringToRecord(csvStringWithBooleanValues2); + test:assertEquals(bv2bniubma, [ + {b1: true, b2: false, b3: true, b4: false, b5: true}, + {b1: true, b2: false, b3: true, b4: false, b5: true} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv3bniubma = parseStringToRecord(csvStringWithBooleanValues3); + test:assertEquals(bv3bniubma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: null}, + {b1: true, b2: true, b3: false} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv4bniubma = parseStringToRecord(csvStringWithBooleanValues4); + test:assertEquals(bv4bniubma, [ + {b1: true, b2: (), b3: (), b4: 0}, + {b1: 1, b2: (), b3: (), b4: false} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv5bniubma = parseStringToRecord(csvStringWithBooleanValues5); + test:assertEquals(bv5bniubma, [ + {b1: true, b2: false, b3: true, b4: 2}, + {b1: true, b2: false, b3: true, b4: 3} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv6bniubma = parseStringToRecord(csvStringWithBooleanValues6); + test:assertEquals(bv6bniubma, [ + {b2: (), b3: ()} + ]); + + NillableIntUnionBooleanMapArray|CsvConversionError bv7bniubma = parseStringToRecord(csvStringWithBooleanValues7); + test:assertEquals(bv7bniubma, [ + {b1, b2, b3, b4} + ]); + + IntUnionBooleanMapArray|CsvConversionError bv1biubma = parseStringToRecord(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|CsvConversionError bv2biubma = parseStringToRecord(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|CsvConversionError bv3biubma = parseStringToRecord(csvStringWithBooleanValues3); + test:assertEquals(bv3biubma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false}, + {b1: true, b2: true, b3: false} + ]); + + IntUnionBooleanMapArray|CsvConversionError bv4biubma = parseStringToRecord(csvStringWithBooleanValues4); + test:assertEquals(bv4biubma, [ + {b1: true, b4: 0}, + {b1: 1, b4: false} + ]); + + IntUnionBooleanMapArray|CsvConversionError bv5biubma = parseStringToRecord(csvStringWithBooleanValues5); + test:assertEquals(bv5biubma, [ + {b1: true, b2: false, b3: true, b4: 2}, + {b1: true, b2: false, b3: true, b4: 3} + ]); + + IntUnionBooleanMapArray|CsvConversionError bv6biubma = parseStringToRecord(csvStringWithBooleanValues6); + test:assertEquals(bv6biubma, [ + {} + ]); + + IntUnionBooleanMapArray|CsvConversionError bv7biubma = parseStringToRecord(csvStringWithBooleanValues7); + test:assertEquals(bv7biubma, [ + {b1, b2, b4} + ]); + + NilMapArray|CsvConversionError bv1bnma = parseStringToRecord(csvStringWithBooleanValues1); + test:assertEquals(bv1bnma, [ + {}, + {}, + {} + ]); + + NilMapArray|CsvConversionError bv2bnma = parseStringToRecord(csvStringWithBooleanValues2); + test:assertEquals(bv2bnma, [ + {}, + {} + ]); + + NilMapArray|CsvConversionError bv3bnma = parseStringToRecord(csvStringWithBooleanValues3); + test:assertEquals(bv3bnma, [ + {}, + {b3: ()}, + {} + ]); + + NilMapArray|CsvConversionError bv4bnma = parseStringToRecord(csvStringWithBooleanValues4); + test:assertEquals(bv4bnma, [ + {b2: (), b3: ()}, + {b2: (), b3: ()} + ]); + + NilMapArray|CsvConversionError bv5bnma = parseStringToRecord(csvStringWithBooleanValues5); + test:assertEquals(bv5bnma, [ + {}, + {} + ]); + + NilMapArray|CsvConversionError bv6bnma = parseStringToRecord(csvStringWithBooleanValues6); + test:assertEquals(bv6bnma, [ + {b2: (), b3: ()} + ]); + + NilMapArray|CsvConversionError bv7bnma = parseStringToRecord(csvStringWithBooleanValues7); + test:assertEquals(bv7bnma, [ + {b3} + ]); + + JsonMapArray|CsvConversionError bv1bjma = parseStringToRecord(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|CsvConversionError bv2bjma = parseStringToRecord(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|CsvConversionError bv3bjma = parseStringToRecord(csvStringWithBooleanValues3); + test:assertEquals(bv3bjma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: null}, + {b1: true, b2: true, b3: false} + ]); + + JsonMapArray|CsvConversionError bv4bjma = parseStringToRecord(csvStringWithBooleanValues4); + test:assertEquals(bv4bjma, [ + {b1: true, b2: (), b3: (), b4: 0}, + {b1: 1, b2: (), b3: (), b4: false} + ]); + + JsonMapArray|CsvConversionError bv5bjma = parseStringToRecord(csvStringWithBooleanValues5); + test:assertEquals(bv5bjma, [ + {b1: true, b2: false, b3: true, b4: 2}, + {b1: true, b2: false, b3: true, b4: 3} + ]); + + JsonMapArray|CsvConversionError bv6bjma = parseStringToRecord(csvStringWithBooleanValues6); + test:assertEquals(bv6bjma, [ + {b2: (), b3: ()} + ]); + + JsonMapArray|CsvConversionError bv7bjma = parseStringToRecord(csvStringWithBooleanValues7); + test:assertEquals(bv7bjma, [ + {b1, b2, b3, b4} + ]); + + AnydataMapArray|CsvConversionError bv1banydma = parseStringToRecord(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|CsvConversionError bv2banydma = parseStringToRecord(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|CsvConversionError bv3banydma = parseStringToRecord(csvStringWithBooleanValues3); + test:assertEquals(bv3banydma, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: null}, + {b1: true, b2: true, b3: false} + ]); + + AnydataMapArray|CsvConversionError bv4banydma = parseStringToRecord(csvStringWithBooleanValues4); + test:assertEquals(bv4banydma, [ + {b1: true, b2: (), b3: (), b4: 0}, + {b1: 1, b2: (), b3: (), b4: false} + ]); + + AnydataMapArray|CsvConversionError bv5banydma = parseStringToRecord(csvStringWithBooleanValues5); + test:assertEquals(bv5banydma, [ + {b1: true, b2: false, b3: true, b4: 2}, + {b1: true, b2: false, b3: true, b4: 3} + ]); + + AnydataMapArray|CsvConversionError bv6banydma = parseStringToRecord(csvStringWithBooleanValues6); + test:assertEquals(bv6banydma, [ + {b2: (), b3: ()} + ]); + + AnydataMapArray|CsvConversionError bv7banydma = parseStringToRecord(csvStringWithBooleanValues7); + test:assertEquals(bv7banydma, [ + {b1, b2, b3, b4} + ]); + + CustomMapArray|CsvConversionError bv1bcma = parseStringToRecord(csvStringWithBooleanValues1); + test:assertEquals(bv1bcma, [ + {b1: "true", b2: "false", b3: "true", b4: "false"}, + {b1: "true", b2: "false", b3: "true", b4: "false"}, + {b1: "true", b2: "false", b3: "true", b4: "false"} + ]); + + CustomMapArray|CsvConversionError bv2bcma = parseStringToRecord(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|CsvConversionError bv3bcma = parseStringToRecord(csvStringWithBooleanValues3); + test:assertEquals(bv3bcma, [ + {b1: "true", b2: "false", b3: "true"}, + {b1: "TRUE", b2: "FALSE", b3: "()"}, + {b1: "true", b2: "true", b3: "FALSE"} + ]); + + CustomMapArray|CsvConversionError bv4bcma = parseStringToRecord(csvStringWithBooleanValues4); + test:assertEquals(bv4bcma, [ + {b1: "true", b2: "()", b3: "()", b4: 0}, + {b1: 1, b2: "()", b3: "null", b4: "false"} + ]); + + CustomMapArray|CsvConversionError bv5bcma = parseStringToRecord(csvStringWithBooleanValues5); + test:assertEquals(bv5bcma, [ + {b1: "true", b2: "false", b3: "true", b4: 2}, + {b1: "true", b2: "false", b3: "true", b4: 3} + ]); + + CustomMapArray|CsvConversionError bv6bcma = parseStringToRecord(csvStringWithBooleanValues6); + test:assertEquals(bv6bcma, [ + {b2: "()", b3: "()"} + ]); + + CustomMapArray|CsvConversionError bv7bcma = parseStringToRecord(csvStringWithBooleanValues7); + test:assertEquals(bv7bcma, [ + {b1: "true", b2: "false", b3: "()", b4: "false"} + ]); + + StringMapArray|CsvConversionError bv1bsma = parseStringToRecord(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|CsvConversionError bv2bsma = parseStringToRecord(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|CsvConversionError bv3bsma = parseStringToRecord(csvStringWithBooleanValues3); + test:assertEquals(bv3bsma, [ + {b1: "true", b2: "false", b3: "true"}, + {b1: "TRUE", b2: "FALSE", b3: "()"}, + {b1: "true", b2: "true", b3: "FALSE"} + ]); + + StringMapArray|CsvConversionError bv4bsma = parseStringToRecord(csvStringWithBooleanValues4); + test:assertEquals(bv4bsma, [ + {b1: "true", b2: "()", b3: "()", b4: "0"}, + {b1: "1", b2: "()", b3: "null", b4: "false"} + ]); + + StringMapArray|CsvConversionError bv5bsma = parseStringToRecord(csvStringWithBooleanValues5); + test:assertEquals(bv5bsma, [ + {b1: "true", b2: "false", b3: "true", b4: "2"}, + {b1: "true", b2: "false", b3: "true", b4: "3"} + ]); + + StringMapArray|CsvConversionError bv6bsma = parseStringToRecord(csvStringWithBooleanValues6); + test:assertEquals(bv6bsma, [ + {b2: "()", b3: "()"} + ]); + + StringMapArray|CsvConversionError bv7bsma = parseStringToRecord(csvStringWithBooleanValues7); + test:assertEquals(bv7bsma, [ + {b1: "true", b2: "false", b3: "()", b4: "false"} + ]); + + DecimalMapArray|CsvConversionError bv1dsma = parseStringToRecord(csvStringWithBooleanValues1); + test:assertEquals(bv1dsma, [ + {}, + {}, + {} + ]); + DecimalMapArray|CsvConversionError bv6dsma = parseStringToRecord(csvStringWithBooleanValues6); + test:assertEquals(bv6dsma, [ + {} + ]); + + DecimalMapArray|CsvConversionError bv7dsma = parseStringToRecord(csvStringWithBooleanValues7); + test:assertEquals(bv7dsma, [ + {} + ]); +} diff --git a/ballerina/tests/parse_string_to_record_tests.bal b/ballerina/tests/parse_string_to_record_tests.bal new file mode 100644 index 0000000..2b21e5e --- /dev/null +++ b/ballerina/tests/parse_string_to_record_tests.bal @@ -0,0 +1,496 @@ +import ballerina/test; + +// boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() { +// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// test:assertEquals(csvb4br1, [ +// {b1: true, b2: "()", b3: (), b4: false}, +// {b1: true, b2: "()", b3: (), b4: false} +// ]); +// } + +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { + BooleanRecord1Array|CsvConversionError csvb1br1 = parseStringToRecord(csvStringWithBooleanValues1, {}); + 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|CsvConversionError csvb2br1 = parseStringToRecord(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|CsvConversionError csvb3br1 = parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertTrue(csvb3br1 is CsvConversionError); + test:assertEquals((csvb3br1).message(), generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br1, [ + {b1: true, b2: "()", b3: (), b4: false}, + {b1: true, b2: "()", b3: (), b4: false} + ]); + + BooleanRecord1Array|CsvConversionError csvb5br1 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertTrue(csvb5br1 is CsvConversionError); + test:assertEquals((csvb5br1).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanRecord1Array|CsvConversionError csvb6br1 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br1 is CsvConversionError); + test:assertEquals((csvb6br1).message(), generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord1Array|CsvConversionError csvb7br1 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br1, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord2Array|CsvConversionError csvb1br2 = parseStringToRecord(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|CsvConversionError csvb2br2 = parseStringToRecord(csvStringWithBooleanValues2, {}); + test:assertEquals(csvb2br2, [ + {b1: true, b2: false, b3: true, b4: false}, + {b1: true, b2: false, b3: true, b4: false} + ]); + + BooleanRecord2Array|CsvConversionError csvb3br2 = parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertTrue(csvb3br2 is CsvConversionError); + test:assertEquals((csvb3br2).message(), generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord2Array|CsvConversionError csvb4br2 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br2, [ + {b1: true, b2: "()", b3: (), b4: false}, + {b1: true, b2: "()", b3: (), b4: false} + ]); + + BooleanRecord2Array|CsvConversionError csvb5br2 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertTrue(csvb5br2 is CsvConversionError); + test:assertEquals((csvb5br2).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanRecord2Array|CsvConversionError csvb7br2 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br2, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord3Array|CsvConversionError csvb1br3 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br3, [ + {b1: true, b3: true}, + {b1: true, b3: true}, + {b1: true, b3: true} + ]); + + BooleanRecord3Array|CsvConversionError csvb2br3 = parseStringToRecord(csvStringWithBooleanValues2, {}); + test:assertEquals(csvb2br3, [ + {b1: true, b3: true}, + {b1: true, b3: true} + ]); + + BooleanRecord3Array|CsvConversionError csvb3br3 = parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br3, [ + {b1: true, b3: true}, + {b1: true, b3: ()}, + {b1: true, b3: false} + ]); + + BooleanRecord3Array|CsvConversionError csvb4br3 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br3, [ + {b1: true, b3: ()}, + {b1: true, b3: ()} + ]); + + BooleanRecord3Array|CsvConversionError csvb5br3 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br3, [ + {b1: true, b3: true}, + {b1: true, b3: true} + ]); + + BooleanRecord3Array|CsvConversionError csvb7br3 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br3, [ + {b1, b3: ()} + ]); + + BooleanRecord4Array|CsvConversionError csvb1br4 = parseStringToRecord(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|CsvConversionError csvb2br4 = parseStringToRecord(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|CsvConversionError csvb3br4 = parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br4, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: ()}, + {b1: true, b2: true, b3: false} + ]); + + BooleanRecord4Array|CsvConversionError csvb4br4 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br4, [ + {b1: true, b2: (), b3: (), b4: 0}, + {b1: true, b2: (), b3: (), b4: false} + ]); + + BooleanRecord4Array|CsvConversionError csvb5br4 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br4, [ + {b1: true, b2: false, b3: true, b4: 2}, + {b1: true, b2: false, b3: true, b4: 3} + ]); + + BooleanRecord4Array|CsvConversionError csvb7br4 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br4, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord5Array|CsvConversionError csvb1br5 = parseStringToRecord(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|CsvConversionError csvb2br5 = parseStringToRecord(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|CsvConversionError csvb3br5 = parseStringToRecord(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|CsvConversionError csvb4br5 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br5, [ + {b1: true, b2: (), b3: (), b4: 0, defaultableField: "", nillableField: ()}, + {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord5Array|CsvConversionError csvb5br5 = parseStringToRecord(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|CsvConversionError csvb7br5 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br5, [ + {b1, b2, b3: (), b4, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb1br6 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: true, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb2br6 = parseStringToRecord(csvStringWithBooleanValues2, {}); + test:assertEquals(csvb2br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: true, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb3br6 = parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: false, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb4br6 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb5br6 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: true, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|CsvConversionError csvb7br6 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br6, [ + {b1, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord7Array|CsvConversionError csvb1br7 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br7 is CsvConversionError); + test:assertEquals((csvb1br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord8Array|CsvConversionError csvb1br8 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br8 is CsvConversionError); + test:assertEquals((csvb1br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord9Array|CsvConversionError csvb1br9 = parseStringToRecord(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|CsvConversionError csvb2br9 = parseStringToRecord(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|CsvConversionError csvb3br9 = parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br9, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: ()}, + {b1: true, b2: true, b3: false} + ]); + + BooleanRecord9Array|CsvConversionError csvb4br9 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br9, [ + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} + ]); + + BooleanRecord9Array|CsvConversionError csvb5br9 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br9, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + BooleanRecord9Array|CsvConversionError csvb6br9 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br9 is CsvConversionError); + test:assertEquals((csvb6br9).message(), generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord9Array|CsvConversionError csvb7br9 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br9, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord10Array|CsvConversionError csvb1br10 = parseStringToRecord(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|CsvConversionError csvb2br10 = parseStringToRecord(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|CsvConversionError csvb3br10 = parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br10, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false}, + {b1: true, b2: true, b3: false} + ]); + + BooleanRecord10Array|CsvConversionError csvb4br10 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br10, [ + {b1: true, b4: false}, + {b1: true, b4: false} + ]); + + BooleanRecord10Array|CsvConversionError csvb5br10 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br10, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + BooleanRecord10Array|CsvConversionError csvb6br10 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br10, [ + {} + ]); + + BooleanRecord10Array|CsvConversionError csvb7br10 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br10, [ + {b1, b2, b4} + ]); + + BooleanRecord11Array|CsvConversionError csvb1br11 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br11, [ + {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: ()} + ]); + + BooleanRecord11Array|CsvConversionError csvb2br11 = parseStringToRecord(csvStringWithBooleanValues2, {}); + 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|CsvConversionError csvb3br11 = parseStringToRecord(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|CsvConversionError csvb4br11 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br11, [ + {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()}, + {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord11Array|CsvConversionError csvb5br11 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br11, [ + {b1: true, b2: false, b3: true, b4: "2", defaultableField: "", nillableField: ()}, + {b1: true, b2: false, b3: true, b4: "3", defaultableField: "", nillableField: ()} + ]); + + BooleanRecord11Array|CsvConversionError csvb6br11 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br11 is CsvConversionError); + test:assertEquals((csvb6br11).message(), generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord11Array|CsvConversionError csvb7br11 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br11, [ + {b1, b2, b3, b4, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord12Array|CsvConversionError csvb1br12 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br12 is CsvConversionError); + test:assertEquals((csvb1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord13Array|CsvConversionError csvb1br13 = parseStringToRecord(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|CsvConversionError csvb2br13 = parseStringToRecord(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|CsvConversionError csvb3br13 = parseStringToRecord(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|CsvConversionError csvb4br13 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br13, [ + {b1: true, b2: "()", b3: "()", b4: false, defaultableField: "", nillableField: ()}, + {b1: true, b2: "()", b3: "null", b4: false, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord13Array|CsvConversionError csvb5br13 = parseStringToRecord(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|CsvConversionError csvb6br13 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br13, [ + {b2: "()", b3: "()", defaultableField: "", nillableField: ()} + ]); + + BooleanRecord13Array|CsvConversionError csvb7br13 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br13, [ + {b1, b2, b3: "()", b4, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord14Array|CsvConversionError csvb7br14 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb7br14 is CsvConversionError); + test:assertEquals((csvb7br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); +} + +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { + BooleanRecord15Array|CsvConversionError csvb1br15 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br15 is CsvConversionError); + test:assertEquals((csvb1br15).message(), generateErrorMessageForInvalidCast("true", "int")); + + BooleanRecord15Array|CsvConversionError csvb6br15 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br15 is CsvConversionError); + test:assertEquals((csvb6br15).message(), generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord15Array|CsvConversionError csvb7br15 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertTrue(csvb7br15 is CsvConversionError); + test:assertEquals((csvb7br15).message(), generateErrorMessageForInvalidCast("true", "int")); + + BooleanRecord16Array|CsvConversionError csvb1br16 = parseStringToRecord(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|CsvConversionError csvb2br16 = parseStringToRecord(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|CsvConversionError csvb3br16 = parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br16, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: ()}, + {b1: true, b2: true, b3: false} + ]); + + BooleanRecord16Array|CsvConversionError csvb4br16 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br16, [ + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} + ]); + + BooleanRecord16Array|CsvConversionError csvb5br16 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br16, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + BooleanRecord16Array|CsvConversionError csvb6br16 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br16, [ + {b2: (), b3: ()} + ]); + + BooleanRecord16Array|CsvConversionError csvb7br16 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br16, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord17Array|CsvConversionError csvb1br17 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br17, [{}, {}, {}]); + + BooleanRecord17Array|CsvConversionError csvb4br17 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br17, [{b4: 0}, {b1: 1}]); + + BooleanRecord17Array|CsvConversionError csvb6br17 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br17, [{}]); + + BooleanRecord17Array|CsvConversionError csvb7br17 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br17, [{}]); + + BooleanRecord18Array|CsvConversionError csvb1br18 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br18, [{b2: false}, {b2: false}, {b2: false}]); + + BooleanRecord18Array|CsvConversionError csvb4br18 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertTrue(csvb4br18 is CsvConversionError); + test:assertEquals((csvb4br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanRecord18Array|CsvConversionError csvb6br18 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br18 is CsvConversionError); + test:assertEquals((csvb6br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanRecord18Array|CsvConversionError csvb7br18 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br18, [{b2, b3: ()}]); +} diff --git a/ballerina/tests/parse_string_to_tuple_test.bal b/ballerina/tests/parse_string_to_tuple_test.bal new file mode 100644 index 0000000..adb8985 --- /dev/null +++ b/ballerina/tests/parse_string_to_tuple_test.bal @@ -0,0 +1,474 @@ +import ballerina/test; + +// boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() { +// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// test:assertEquals(csvb4br1, [ +// {b1: true, b2: "()", b3: (), b4: false}, +// {b1: true, b2: "()", b3: (), b4: false} +// ]); +// } + +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { + BooleanTuple1Array|CsvConversionError cbv1bt1 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt1, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple1Array|CsvConversionError cbv2bt1 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt1, [ + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple1Array|CsvConversionError cbv3bt1 = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt1 is CsvConversionError); + test:assertEquals((cbv3bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple1Array|CsvConversionError cbv5bt1 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt1 is CsvConversionError); + test:assertEquals((cbv5bt1).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanTuple1Array|CsvConversionError cbv7bt1 = parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt1 is CsvConversionError); + test:assertEquals((cbv7bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple2Array|CsvConversionError cbv1bt2 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt2, [ + [true, false], + [true, false], + [true, false] + ]); + + BooleanTuple2Array|CsvConversionError cbv2bt2 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt2, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|CsvConversionError cbv3bt2 = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt2, [ + [true, false], + [true, false], + [true, true] + ]); + + BooleanTuple2Array|CsvConversionError cbv4bt2 = parseStringToList(csvStringWithBooleanValues4); + test:assertTrue(cbv4bt2 is CsvConversionError); + test:assertEquals((cbv4bt2).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple3Array|CsvConversionError cbv1bt3 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt3, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple3Array|CsvConversionError cbv2bt3 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt3, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + BooleanTuple3Array|CsvConversionError cbv3bt3 = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt3 is CsvConversionError); + test:assertEquals((cbv3bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple3Array|CsvConversionError cbv5bt3 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt3 is CsvConversionError); + test:assertEquals((cbv5bt3).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanTuple3Array|CsvConversionError cbv7bt3 = parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt3 is CsvConversionError); + test:assertEquals((cbv7bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|CsvConversionError cbv1bt4 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt4, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple4Array|CsvConversionError cbv2bt4 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt4, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + BooleanTuple4Array|CsvConversionError cbv3bt4 = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt4 is CsvConversionError); + test:assertEquals((cbv3bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|CsvConversionError cbv4bt4 = parseStringToList(csvStringWithBooleanValues4); + test:assertTrue(cbv4bt4 is CsvConversionError); + test:assertEquals((cbv4bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|CsvConversionError cbv5bt4 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt4 is CsvConversionError); + test:assertEquals((cbv5bt4).message(), generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanTuple4Array|CsvConversionError cbv6bt4 = parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cbv6bt4 is CsvConversionError); + test:assertEquals((cbv6bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|CsvConversionError cbv7bt4 = parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt4 is CsvConversionError); + test:assertEquals((cbv7bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + + NillableBooleanTuple5Array|CsvConversionError cbv1bt5 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt5, [ + [true, false, true, false, null], + [true, false, true, false, null], + [true, false, true, false, null] + ]); + + NillableBooleanTuple5Array|CsvConversionError cbv2bt5 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt5, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanTuple5Array|CsvConversionError cbv3bt5 = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt5, [ + [true, false, true, null, null], + [true, false, (), null, null], + [true, true, false, null, null] + ]); + + NillableBooleanTuple5Array|CsvConversionError cbv4bt5 = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt5, [ + [true, (), (), false, null], + [true, (), (), false, null] + ]); + + NillableBooleanTuple5Array|CsvConversionError cbv5bt5 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt5 is CsvConversionError); + test:assertEquals((cbv5bt5).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanTuple5Array|CsvConversionError cbv6bt5 = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt5, [ + [(), (), null, null, null] + ]); + + NillableBooleanTuple5Array|CsvConversionError cbv7bt5 = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt5, [ + [b1, b2, (), b4, null] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv1bt6 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt6, [ + [true, false], + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv2bt6 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt6, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv3bt6 = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt6, [ + [true, false], + [true, false], + [true, true] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv4bt6 = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt6, [ + [true, ()], + [true, ()] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv6bt6 = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt6, [ + [(), null] + ]); + + NillableBooleanTuple6Array|CsvConversionError cbv7bt6 = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt6, [ + [b1, b2] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv1bt7 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt7, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv2bt7 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt7, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv3bt7 = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt7, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv4bt7 = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt7, [ + [true, (), (), false], + [true, (), (), false] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv5bt7 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt7 is CsvConversionError); + test:assertEquals((cbv5bt7).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanTuple7Array|CsvConversionError cbv6bt7 = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt7, [ + [(), ()] + ]); + + NillableBooleanTuple7Array|CsvConversionError cbv7bt7 = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt7, [ + [b1, b2, (), false] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv1bt8 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt8, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv2bt8 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt8, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv3bt8 = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt8, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv4bt8 = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt8, [ + [true, (), (), false], + [true, (), (), false] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv5bt8 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt8 is CsvConversionError); + test:assertEquals((cbv5bt8).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanTuple8Array|CsvConversionError cbv6bt8 = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt8, [ + [(), ()] + ]); + + NillableBooleanTuple8Array|CsvConversionError cbv7bt8 = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt8, [ + [b1, b2, (), false] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv1bt9 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt9, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv2bt9 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt9, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv3bt9 = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt9, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv4bt9 = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt9, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv5bt9 = parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cbv5bt9, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv6bt9 = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt9, [ + [(), ()] + ]); + + NillableIntBooleanTuple9Array|CsvConversionError cbv7bt9 = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt9, [ + [b1, b2, (), false] + ]); + + NilTuple3Array|CsvConversionError cbv1nt3 = parseStringToList(csvStringWithBooleanValues1); + test:assertTrue(cbv1nt3 is CsvConversionError); + test:assertEquals((cbv1nt3).message(), generateErrorMessageForInvalidCast("true", "()")); + + NilTuple3Array|CsvConversionError cbv3nt3 = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3nt3 is CsvConversionError); + test:assertEquals((cbv3nt3).message(), generateErrorMessageForInvalidCast("true", "()")); + + NilTuple3Array|CsvConversionError cbv6nt3 = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6nt3, [ + [(), ()] + ]); + + AnydataTuple3Array|CsvConversionError cbv1anyd3 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1anyd3, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + AnydataTuple3Array|CsvConversionError cbv2anyd3 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2anyd3, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + AnydataTuple3Array|CsvConversionError cbv3anyd3 = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3anyd3, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + AnydataTuple3Array|CsvConversionError cbv4anyd3 = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4anyd3, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + AnydataTuple3Array|CsvConversionError cbv5anyd3 = parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cbv5anyd3, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + AnydataTuple3Array|CsvConversionError cbv6anyd3 = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6anyd3, [ + [(), ()] + ]); + + AnydataTuple3Array|CsvConversionError cbv7anyd3 = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7anyd3, [ + [b1, b2, (), false] + ]); +} + +@test:Config {enable} +function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { + JsonTuple3Array|CsvConversionError cbv1j3 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1j3, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + JsonTuple3Array|CsvConversionError cbv2j3 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2j3, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + JsonTuple3Array|CsvConversionError cbv3j3 = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3j3, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + JsonTuple3Array|CsvConversionError cbv4j3 = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4j3, [ + [true, (), (), 0], + [1, (), (), false] + ]); + + JsonTuple3Array|CsvConversionError cbv5j3 = parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cbv5j3, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + JsonTuple3Array|CsvConversionError cbv6j3 = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6j3, [ + [(), ()] + ]); + + JsonTuple3Array|CsvConversionError cbv7j3 = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7j3, [ + [b1, b2, (), false] + ]); + + StringTuple3Array|CsvConversionError cbv1s3 = parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1s3, [ + ["true", "false", "true", "false"], + ["true", "false", "true", "false"], + ["true", "false", "true", "false"] + ]); + + StringTuple3Array|CsvConversionError cbv2s3 = parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2s3, [ + ["true", "false", "true", "false", "true"], + ["true", "false", "true", "false", "true"] + ]); + + StringTuple3Array|CsvConversionError cbv3s3 = parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3s3, [ + ["true", "false", "true"], + ["TRUE", "FALSE", "()"], + ["true", "true", "FALSE"] + ]); + + StringTuple3Array|CsvConversionError cbv4s3 = parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4s3, [ + ["true", "()", "()", "0"], + ["1", "()", "null", "false"] + ]); + + StringTuple3Array|CsvConversionError cbv5s3 = parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cbv5s3, [ + ["true", "false", "true", "2"], + ["true", "false", "true", "3"] + ]); + + StringTuple3Array|CsvConversionError cbv6s3 = parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6s3, [ + ["()", "()"] + ]); + + StringTuple3Array|CsvConversionError cbv7s3 = parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7s3, [ + ["true", "false", "()", "false"] + ]); + + DecimalTuple3Array|CsvConversionError cbv1dt3 = parseStringToList(csvStringWithBooleanValues1); + test:assertTrue(cbv1dt3 is CsvConversionError); + test:assertEquals((cbv1dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); + + DecimalTuple3Array|CsvConversionError cbv3dt3 = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3dt3 is CsvConversionError); + test:assertEquals((cbv3dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); + + DecimalTuple3Array|CsvConversionError cbv6dt3 = parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cbv6dt3 is CsvConversionError); + test:assertEquals((cbv6dt3).message(), generateErrorMessageForInvalidCast("()", "decimal")); +} diff --git a/ballerina/tests/parse_type_compatibility_test.bal b/ballerina/tests/parse_type_compatibility_test.bal new file mode 100644 index 0000000..f983d08 --- /dev/null +++ b/ballerina/tests/parse_type_compatibility_test.bal @@ -0,0 +1,112 @@ +import ballerina/test; + +// boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() { +// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// test:assertEquals(csvb4br1, [ +// {b1: true, b2: "()", b3: (), b4: false}, +// {b1: true, b2: "()", b3: (), b4: false} +// ]); +// } + +@test:Config {enable} +function testFromCsvWithTypeFunctionWithTypeCompatibility() { + var value = {i1, i2, s1, s2, b1, b2, n1, n2, f1, f2, d1, d2, j1: b1, a1: d1, j2: b2, a2: d2}; + var value2 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3, j2: b2, a2: d2}; + var value3 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3}; + + CustomRecord27Array|CsvConversionError vcr27a = 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: ()} + ]); + + // TODO: + // CustomTuple7Array|CsvConversionError v2ct7a = parseRecordAsListType([value2, value2, value2], {}, CustomTuple7Array); + // test:assertTrue(v2ct7a is CsvConversionError); + // test:assertEquals((v2ct7a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "string")); + + // CustomTuple7Array|CsvConversionError v3ct7a = parseRecordAsListType([value3, value3, value3], {}, CustomTuple7Array); + // test:assertEquals(v3ct7a , [ + // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], + // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], + // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3] + // ]); + + // AnydataArray1Array|CsvConversionError v3anyd1a = parseRecordAsListType([value3, value3, value3], {}, AnydataArray1Array); + // test:assertEquals(v3anyd1a , [ + // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], + // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], + // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3] + // ]); + + AnydataMapArray|CsvConversionError vanydma = parseRecordAsRecordType([value, value, value], {}, AnydataMapArray); + test:assertEquals(vanydma , [ + value, + value, + value + ]); + + JsonMapArray|CsvConversionError vjma = parseRecordAsRecordType([value, value, value], {}, JsonMapArray); + test:assertEquals(vjma , [ + value, + value, + value + ]); + + record{|int...;|}[]|CsvConversionError irrma = 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...;|}[]|CsvConversionError drra = 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...;|}[]|CsvConversionError srra = 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...;|}[]|CsvConversionError frra = 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;|}[]|CsvConversionError fdc1a = 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 ...;|}[]|CsvConversionError fdc2a = 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...;|}[]|CsvConversionError fdc3a = 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} + ]); +} diff --git a/ballerina/tests/test.bal b/ballerina/tests/test.bal deleted file mode 100644 index 9961148..0000000 --- a/ballerina/tests/test.bal +++ /dev/null @@ -1,350 +0,0 @@ -// import ballerina/test; -// import ballerina/io; - -// type A map[]; -// type A2 map[]; - -// type B record{|int a; int b;|}[]; -// type B2 record{|string a; string b;|}[]; -// type B3 record{}[]; -// type B4 record{string '1; string '2; string '3;}[]; -// type B5 record{string '1;}[]; -// type B6 record{string name;}[]; - -// type C string[][]; -// type C2 string[][]; - -// type D [int, int][]; -// type D2 [string, string][]; - -// map[] a = [{"a": "1", "b": "2"}, {"a": "1", "b": "2"}]; -// map[] a2 = [{"a": 1, "b": 2}, {"a": 1, "b": 2}]; - -// record {|int a; int b; int c;|}[] b = [{a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}]; -// record {|string a; string b;|}[] b2 = [{a: "1", b: "2"}, {a: "1", b: "2"}]; - -// string[][] c = [["1", "2", "3"], ["1", "2", "3"]]; -// string[][] c2 = [["1", "2", "3"], ["1", "2", "3"]]; -// int[][] c3 = [[1, 2], [1, 2]]; -// int[][] c4 = [[1, 2, 3], [1, 2, 3]]; - -// [string, string][] d = [["1", "2"], ["1", "2"]]; -// [string, string][] d2 = [["1", "2"], ["1", "2"]]; - -// @test:Config{enable: enableTest} -// public function testA() returns error? { -// A aa = check fromCsvWithType(a, {}, A); -// test:assertEquals(aa, a); - -// A2 aa2 = check fromCsvWithType(a2, {}, A2); -// test:assertEquals(aa2, a2); - -// B bb = check fromCsvWithType(b, {}, B); -// test:assertEquals(bb, [{a: 1, b: 2}, {a: 1, b: 2}]); - -// B2 bb2 = check fromCsvWithType(b2, {}, B2); -// test:assertEquals(bb2, b2); - -// C cc = check fromCsvWithType(c, {}, C); -// test:assertEquals(cc, c); - -// C2 cc2 = check fromCsvWithType(c2, {}, C2); -// test:assertEquals(cc2, c2); - -// B2 ab2 = check fromCsvWithType(a, {}, B2); -// test:assertEquals(ab2, a); - -// C ac = check fromCsvWithType(a, {}, C); -// test:assertEquals(ac, [["1", "2"], ["1", "2"]]); - -// A ba = check fromCsvWithType(b, {}, A); -// test:assertEquals(ba, [{a: "1", b: "2", c: "3"}, {a: "1", b: "2", c: "3"}]); - -// A2 ba2 = check fromCsvWithType(b, {}, A2); -// test:assertEquals(ba2, [{a: 1, b: 2, c: 3}, {a: 1, b: 2, c: 3}]); - -// C bc = check fromCsvWithType(b, {}, C); -// test:assertEquals(bc, [["1", "2", "3"], ["1", "2", "3"]]); - -// C2 bc2 = check fromCsvWithType(b2, {}, C2); -// test:assertEquals(bc2, [["1", "2"], ["1", "2"]]); - -// A ca = check fromCsvWithType(c, {}, A); -// test:assertEquals(ca, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - -// // B2 cb2 = check fromCsvWithType(c, {}, B2); -// // test:assertEquals(cb2, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - -// B3 cb3 = check fromCsvWithType(c, {}, B3); -// test:assertEquals(cb3, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - -// B4 cb4 = check fromCsvWithType(c, {}, B4); -// test:assertEquals(cb4, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - -// B5 cb5 = check fromCsvWithType(c, {}, B5); -// test:assertEquals(cb5, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - -// // B6 cb6 = check fromCsvWithType(c, {}, B6); -// // test:assertEquals(cb6, [{"1": "1", "2": "2", "3": "3"}, {"1": "1", "2": "2", "3": "3"}]); - -// D2 ad2 = check fromCsvWithType(a, {}, D2); -// test:assertEquals(ad2, [["1", "2"], ["1", "2"]]); - -// D a2d = check fromCsvWithType(a2, {}, D); -// test:assertEquals(a2d, [[1, 2], [1, 2]]); - -// D2 a2d2 = check fromCsvWithType(a2, {}, D2); -// test:assertEquals(a2d2, [["1", "2"], ["1", "2"]]); - -// // D dd = check fromCsvWithType(d, {}, D); -// // test:assertEquals(dd, d); - -// D2 dd2 = check fromCsvWithType(d2, {}, D2); -// test:assertEquals(dd2, d2); - -// D bd = check fromCsvWithType(b, {}, D); -// test:assertEquals(bd, [[1, 2], [1, 2]]); - -// D2 bd2 = check fromCsvWithType(b2, {}, D2); -// test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); - -// D2 cd2 = check fromCsvWithType(c, {}, D2); -// test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); - -// A d2a = check fromCsvWithType(d2, {}, A); -// test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - -// // B2 d2b2 = check fromCsvWithType(d2, {}, B2); -// // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - -// C d2c = check fromCsvWithType(d2, {}, C); -// test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); -// } - -// @test:Config{enable: enableTest} -// function testB() returns error? { -// // B2 d2b2 = check fromCsvWithType(d2, {}, B2); -// // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - -// // D2 ad2 = check fromCsvWithType(a, {}, D2); -// // test:assertEquals(ad2, [["1", "2"], ["1", "2"]]); - -// // D2 bd2 = check fromCsvWithType(b2, {}, D2); -// // test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); - -// // D2 cd2 = check fromCsvWithType(c, {}, D2); -// // test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); - -// // A d2a = check fromCsvWithType(d2, {}, A); -// // test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - -// // B2 d2b2 = check fromCsvWithType(d2, {}, B2); -// // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - -// // C d2c = check fromCsvWithType(d2, {}, C); -// // test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); -// } - -// // D a2d = check fromCsvWithType(a2, {}, D); -// // test:assertEquals(a2d, [[1, 2], [1, 2]]); - -// // D2 a2d2 = check fromCsvWithType(a2, {}, D2); -// // test:assertEquals(a2d2, [["1", "2"], ["1", "2"]]); - -// // D dd = check fromCsvWithType(d, {}, D); -// // test:assertEquals(dd, d); - -// // D2 dd2 = check fromCsvWithType(d2, {}, D2); -// // test:assertEquals(dd2, d2); - -// // D bd = check fromCsvWithType(b, {}, D); -// // test:assertEquals(bd, [[1, 2], [1, 2]]); - -// // D2 bd2 = check fromCsvWithType(b2, {}, D2); -// // test:assertEquals(bd2, [["1", "2"], ["1", "2"]]); - -// // D2 cd2 = check fromCsvWithType(c, {}, D2); -// // test:assertEquals(cd2, [["1", "2"], ["1", "2"]]); - -// // A d2a = check fromCsvWithType(d2, {}, A); -// // test:assertEquals(d2a, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - -// // B2 d2b2 = check fromCsvWithType(d2, {}, B2); -// // test:assertEquals(d2b2, [{"1": "1", "2": "2"}, {"1": "1", "2": "2"}]); - -// // C d2c = check fromCsvWithType(d2, {}, C); -// // test:assertEquals(d2c, [["1", "2"], ["1", "2"]]); - -// type AA record{}[]; -// type BB record {int a; int b; int c;}[]; -// // type BBB record {string a; string b; string c;}[]; -// type CC map[]; -// type DD map[]; -// type EE map[]; -// type FF int[][]; -// type GG string[][]; -// type HH anydata[][]; -// type II [int, int, int][]; -// type JJ [string, string, string][]; -// type KK [string, int, string][]; -// type LL record {string a; int b; string c;}[]; -// type MM record {|string a; int b; string c;|}[]; -// type NN record {|int b; string c;|}[]; -// type OO record {string a; string c;}[]; -// type PP int[2][]; -// type QQ string[2][]; -// type RR anydata[2][]; -// type SS [int, int][]; -// type TT [string, string][]; -// type UU [anydata, anydata][]; -// type VV [int, string][]; -// type WW int[][2]; -// type XX string[][2]; -// type YY anydata[][2]; - -// @test:Config{enable: enableTest} -// function test1() returns CsvConversionError? { -// string a = check io:fileReadString("a.txt"); - -// AA aa = check fromCsvStringWithType(a, {}, AA); -// test:assertEquals(aa, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); -// io:println(aa); - -// BB bb = check fromCsvStringWithType(a, {}, BB); -// test:assertEquals(bb, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); -// io:println(bb); - -// CC cc = check fromCsvStringWithType(a, {}, CC); -// test:assertEquals(cc, [{a: "1", b: "2", c: "3"}, {a: "4", b: "5", c: "6"}]); -// io:println(cc); - -// DD dd = check fromCsvStringWithType(a, {}, DD); -// test:assertEquals(dd, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); -// io:println(dd); - -// EE ee = check fromCsvStringWithType(a, {}, EE); -// test:assertEquals(ee, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); -// io:println(ee); - -// FF ff = check fromCsvStringWithType(a, {}, FF); -// test:assertEquals(ff, [[1, 2, 3], [4, 5, 6]]); -// io:println(ff); - -// GG gg = check fromCsvStringWithType(a, {}, GG); -// test:assertEquals(gg, [["1", "2", "3"], ["4", "5", "6"]]); -// io:println(gg); - -// HH hh = check fromCsvStringWithType(a, {}, HH); -// test:assertEquals(hh, [[1, 2, 3], [4, 5, 6]]); -// io:println(hh); - -// II ii = check fromCsvStringWithType(a, {}, II); -// test:assertEquals(ii, [[1, 2, 3], [4, 5, 6]]); -// io:println(ii); - -// JJ jj = check fromCsvStringWithType(a, {}, JJ); -// test:assertEquals(jj, [["1", "2", "3"], ["4", "5", "6"]]); -// io:println(jj); - -// KK kk = check fromCsvStringWithType(a, {}, KK); -// test:assertEquals(kk, [["1", 2, "3"], ["4", 5, "6"]]); -// io:println(kk); - -// LL ll = check fromCsvStringWithType(a, {}, LL); -// test:assertEquals(ll, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); -// io:println(ll); - -// MM mm = check fromCsvStringWithType(a, {}, MM); -// test:assertEquals(mm, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); -// io:println(mm); - -// NN nn = check fromCsvStringWithType(a, {}, NN); -// test:assertEquals(nn, [{b: 2, c: "3"}, {b: 5, c: "6"}]); -// io:println(nn); - -// OO oo = check fromCsvStringWithType(a, {}, OO); -// test:assertEquals(oo, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); -// io:println(oo); - -// PP pp = check fromCsvStringWithType(a, {}, PP); -// test:assertEquals(pp, [[1,2,3], [4,5,6]]); -// io:println(pp); - -// QQ qq = check fromCsvStringWithType(a, {}, QQ); -// test:assertEquals(qq, [["1","2","3"],["4","5","6"]]); -// io:println(qq); - -// RR rr = check fromCsvStringWithType(a, {}, RR); -// test:assertEquals(rr, [[1,2,3],[4,5,6]]); -// io:println(rr); - -// SS ss = check fromCsvStringWithType(a, {}, SS); -// test:assertEquals(ss, [[1, 2],[4, 5]]); -// io:println(ss); - -// TT tt = check fromCsvStringWithType(a, {}, TT); -// test:assertEquals(tt, [["1", "2"],["4", "5"]]); -// io:println(tt); - -// UU uu = check fromCsvStringWithType(a, {}, UU); -// test:assertEquals(uu, [[1, 2],[4, 5]]); -// io:println(uu); - -// VV vv = check fromCsvStringWithType(a, {}, VV); -// test:assertEquals(vv, [[1,"2"],[4,"5"]]); -// io:println(vv); - -// WW ww = check fromCsvStringWithType(a, {}, WW); -// test:assertEquals(ww, [[1,2],[4,5]]); -// io:println(ww); - -// XX xx = check fromCsvStringWithType(a, {}, XX); -// test:assertEquals(xx, [["1","2"],["4","5"]]); -// io:println(xx); - -// YY yy = check fromCsvStringWithType(a, {}, YY); -// test:assertEquals(yy, [[1,2],[4,5]]); -// io:println(yy); -// } - -// // =========================================================================================== - -// // errors expected - -// // EE ee2 = check fromCsvStringWithType(a, {}, EE); -// // test:assertEquals(ee2, [{a: "1", b: "2", c: "3"}, {a: "4", b: "5", c: "6"}]); -// // io:println(ee2); -// // BBB bbb = check fromCsvStringWithType(a, {}, BBB); -// // test:assertEquals(bbb, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); -// // io:println(bbb); - -// // =========================================================================================== - -// // NEED TO check - -// // OO oo = check fromCsvStringWithType(a, {}, MM); -// // test:assertEquals(oo, [{a: "1", b: 2, c: "3"}, {a: "4", b: 5, c: "6"}]); -// // io:println(oo); - -// type AAA string[][]; - -// @test:Config{enable: enableTest} -// function testC() returns error? { -// anydata[][] a = [[1, 2], [2, 3], [2, 3]]; -// record{}[] b = [{"a": 1, "b": 2}, {"a": 1, "b": 2}, {"a": 1, "b": 2}]; -// map[] c = [{"a": 1, "b": 2}, {"a": 1, "b": 2}, {"a": 1, "b": 2}]; - -// io:println(toCsvString(a)); -// io:println(toCsvString(b)); -// io:println(toCsvString(c)); -// } - -// boolean enableTest = true; - -// @test:Config{enable: !enableTest} -// function t() returns error? { -// string a = check io:fileReadString("a.txt"); -// AA aa = check fromCsvStringWithType(a, {}, AA); -// test:assertEquals(aa, [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]); -// io:println(aa); -// } \ No newline at end of file diff --git a/ballerina/tests/test_from_csv_with_user_configs.bal.bal b/ballerina/tests/test_from_csv_with_user_configs.bal.bal deleted file mode 100644 index ca71a87..0000000 --- a/ballerina/tests/test_from_csv_with_user_configs.bal.bal +++ /dev/null @@ -1,721 +0,0 @@ -import ballerina/test; - -@test:Config{enable} -function testStartNumbers() { - record{}[]|CsvConversionError v1 = fromCsvStringWithType(csvStringData1, config1); - if v1 is record{}[] { - test:assertEquals((v1).length(), 5); - } - test:assertEquals(v1, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, - {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ]); - - record{}[]|CsvConversionError v2 = fromCsvStringWithType(csvStringData1, config2); - test:assertEquals(v2, [ - {a: 1, b: "string2", c: false, d: 0, e: 0, f: null}, - {a: 1, b: "string3", c: 0, d: 1.23, e: 1.23, f: ()}, - {a: 1, b: "string4", c: 1, d: -6.51, e: -6.51, f: ()}, - {a: 1, b: "string5", c: true, d: 3, e: 3, f: ()} - ]); -} - -@test:Config{enable} -function testCustomHeaders() { - testHeaderConfigWithFalseValue(); - testSkipHeaderConfigWithFalseValue({skipHeaders: true}); - testHeaderConfigWithFalseValue(config34); - testCustomHeadersPresentConfigs(); - testCustomHeadersWithFalseHeadersPresentConfigs(); - testCustomHeadersWithFalseHeadersPresentConfigs(config36); - testCustomHeadersPresentConfigs(config24); -} - -function testCustomHeadersWithFalseHeadersPresentConfigs(FromCSVConfig config = config23) { - CustomRecord46Array|CsvConversionError v20 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v20, [ - {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord46Array|CsvConversionError v20_2 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v20_2, [ - {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord47Array|CsvConversionError v21 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v21, [ - {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord48Array|CsvConversionError v22 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v22, [ - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord48Array|CsvConversionError v22_2 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v22_2, [ - {H1: "a", H2: "b", H3: "c", H4: "d", H5: "e", H6: "f"}, - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord49Array|CsvConversionError v23 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v23, [ - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord50Array|CsvConversionError v24 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v24, [ - {H1: 1, H4: 2.234, H2: "string1", H3: true, H5: 2.234, H6: ()}, - {H1: 1, H4: 0.0, H2: "string2", H3: false, H5: 0, H6: null}, - {H1: 1, H4: 1.23, H2: "string3", H3: 0, H5: 1.23, H6: ()}, - {H1: 1, H4: -6.51, H2: "string4", H3: 1, H5: -6.51, H6: ()}, - {H1: 1, H4: 3.0, H2: "string5", H3: true, H5: 3, H6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord50Array|CsvConversionError v24_2 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v24_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v24_2).message(), generateErrorMessageForInvalidCast("a", "int"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord51Array|CsvConversionError v25 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v25, [ - {H1: 1, H4: 2.234}, - {H1: 1, H4: 0.0}, - {H1: 1, H4: 1.23}, - {H1: 1, H4: -6.51}, - {H1: 1, H4: 3.0} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord52Array|CsvConversionError v26 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v26, [ - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord52Array|CsvConversionError v26_2 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v26_2, [ - {H1: "a", H2: "b", H3: "c", H4: "d", H5: "e", H6: "f"}, - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord53Array|CsvConversionError v27 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v27, [ - {H1: 1, H4: 2.234, "H5": 2.234}, - {H1: 1, H4: 0.0, "H5": 0}, - {H1: 1, H4: 1.23, "H3": 0, "H5": 1.23}, - {H1: 1, H4: -6.51, "H3": 1, "H5": -6.51}, - {H1: 1, H4: 3.0, "H5": 3} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord53Array|CsvConversionError v27_2 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v27_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v27_2).message(), generateErrorMessageForInvalidCast("a", "int"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord54Array|CsvConversionError v29 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v29 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v29).message(), generateErrorMessageForMissingRequiredField("1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord54Array|CsvConversionError v29_2 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v29_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v29_2).message(), generateErrorMessageForMissingRequiredField("1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord55Array|CsvConversionError v30 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v30, [ - {H1: "1", H4: "2.234",'1: 10}, - {H1: "1", H4: "0", '1: 10}, - {H1: "1", H4: "1.23", '1: 10}, - {H1: "1", H4: "-6.51", '1: 10}, - {H1: "1", H4: "3", '1: 10} - ], string `Test failed for config ${config.toBalString()}`); -} - -function testCustomHeadersPresentConfigs(FromCSVConfig config = config22) { - CustomRecord46Array|CsvConversionError v20 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v20, [ - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord46Array|CsvConversionError v20_2 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v20_2, [ - {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord47Array|CsvConversionError v21 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v21, [ - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord47Array|CsvConversionError v21_2 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v21_2, [ - {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord48Array|CsvConversionError v22 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v22, [ - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord48Array|CsvConversionError v22_2 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v22_2, [ - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord49Array|CsvConversionError v23 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v23, [ - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord49Array|CsvConversionError v23_2 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v23_2, [ - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord50Array|CsvConversionError v24 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v24, [ - {H1: 1, H4: 0.0, H2: "string2", H3: false, H5: 0, H6: null}, - {H1: 1, H4: 1.23, H2: "string3", H3: 0, H5: 1.23, H6: ()}, - {H1: 1, H4: -6.51, H2: "string4", H3: 1, H5: -6.51, H6: ()}, - {H1: 1, H4: 3.0, H2: "string5", H3: true, H5: 3, H6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord50Array|CsvConversionError v24_2 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v24_2, [ - {H1: 1, H4: 2.234, H2: "string1", H3: true, H5: 2.234, H6: ()}, - {H1: 1, H4: 0.0, H2: "string2", H3: false, H5: 0, H6: null}, - {H1: 1, H4: 1.23, H2: "string3", H3: 0, H5: 1.23, H6: ()}, - {H1: 1, H4: -6.51, H2: "string4", H3: 1, H5: -6.51, H6: ()}, - {H1: 1, H4: 3.0, H2: "string5", H3: true, H5: 3, H6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - record{() H1;}[]|CsvConversionError v24_3 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v24_3 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v24_3).message(), generateErrorMessageForInvalidCast("1", "()"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord51Array|CsvConversionError v25 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v25, [ - {H1: 1, H4: 0.0}, - {H1: 1, H4: 1.23}, - {H1: 1, H4: -6.51}, - {H1: 1, H4: 3.0} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord52Array|CsvConversionError v26 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v26, [ - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord52Array|CsvConversionError v26_2 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v26_2, [ - {H1: "1", H2: "string1", H3: "true", H4: "2.234", H5: "2.234", H6: "()"}, - {H1: "1", H2: "string2", H3: "false", H4: "0", H5: "0", H6: "null"}, - {H1: "1", H2: "string3", H3: "0", H4: "1.23", H5: "1.23", H6: "()"}, - {H1: "1", H2: "string4", H3: "1", H4: "-6.51", H5: "-6.51", H6: "()"}, - {H1: "1", H2: "string5", H3: "true", H4: "3", H5: "3", H6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord53Array|CsvConversionError v27 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v27, [ - {H1: 1, H4: 0.0, "H5": 0}, - {H1: 1, H4: 1.23, "H3": 0, "H5": 1.23}, - {H1: 1, H4: -6.51, "H3": 1, "H5": -6.51}, - {H1: 1, H4: 3.0, "H5": 3} - ], string `Test failed for config ${config.toBalString()}`); - - record{() H1;}[]|CsvConversionError v27_2 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v27_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v27_2).message(), generateErrorMessageForInvalidCast("1", "()"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord54Array|CsvConversionError v29 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v29 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v29).message(), generateErrorMessageForMissingRequiredField("1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord54Array|CsvConversionError v29_2 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v29_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v29_2).message(), generateErrorMessageForMissingRequiredField("1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord55Array|CsvConversionError v30 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v30, [ - {H1: "1", H4: "0", '1: 10}, - {H1: "1", H4: "1.23", '1: 10}, - {H1: "1", H4: "-6.51", '1: 10}, - {H1: "1", H4: "3", '1: 10} - ], string `Test failed for config ${config.toBalString()}`); -} - -function testSkipHeaderConfigWithFalseValue(FromCSVConfig config) { - record {}[]|CsvConversionError v1 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v1, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, - {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord28Array|CsvConversionError v2 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v2, [ - {'1: "1", '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: "1", '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, - {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, - {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, - {'1: "1", '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - - CustomRecord29Array|CsvConversionError v3 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v3, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, - {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord30Array|CsvConversionError v4 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v4, [ - {'1: "1", '2: "string1", '3: "true", '4: "2.234", '5: "2.234", '6: "()"}, - {'1: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, - {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, - {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, - {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord31Array|CsvConversionError v5 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v5, [ - {'1: "1", '6: "()"}, - {'1: "1", '6: "null"}, - {'1: "1", '6: "()"}, - {'1: "1", '6: "()"}, - {'1: "1", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - record{() '1;}[]|CsvConversionError v6 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v6 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v6).message(), generateErrorMessageForInvalidCast("1", "()"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord33Array|CsvConversionError v7 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v7, [ - {'1: "1", '2: "string1", '3: "true", '4: "2.234", '5: "2.234", '6: "()"}, - {'1: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, - {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, - {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, - {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord34Array|CsvConversionError v8 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v8, [ - {'1: "1", '2: "string1", '3: true, '4: 2.234, '5: "2.234", '6: "()"}, - {'1: "1", '2: "string2", '3: false, '4: 0, '5: "0", '6: "null"}, - {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: "1.23", '6: "()"}, - {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: "-6.51", '6: "()"}, - {'1: "1", '2: "string5", '3: true, '4: 3, '5: "3", '6: "()"} - ]); - - CustomRecord35Array|CsvConversionError v9 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v9, [ - {'1: "1", '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: "()", '9: ""}, - {'1: "1", '2: "string2", '3: false, '4: 0, '5: 0, '6: "null", '9: ""}, - {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: "()", '9: ""}, - {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: "()", '9: ""}, - {'1: "1", '2: "string5", '3: true, '4: 3, '5: 3, '6: "()", '9: ""} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord36Array|CsvConversionError v10 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v10, [ - {'1: "1", '6: "()", '9: ""}, - {'1: "1", '6: "null", '9: ""}, - {'1: "1", '6: "()", '9: ""}, - {'1: "1", '6: "()", '9: ""}, - {'1: "1", '6: "()", '9: ""} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord37Array|CsvConversionError v11 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v11, [ - {'1: "1", '5: "2.234", '6: "()"}, - {'1: "1", '5: "0", '6: "null"}, - {'1: "1", '5: "1.23", '6: "()"}, - {'1: "1", '5: "-6.51", '6: "()"}, - {'1: "1", '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord38Array|CsvConversionError v12 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v12, [ - {'1: "1", '2: "string1", '3: "true", '4: "2.234", '5: "2.234", '6: "()"}, - {'1: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, - {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, - {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, - {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord39Array|CsvConversionError v13 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v13, [ - {'1: "1", '2: "string1", '3: "true", '4: "2.234", '5: "2.234", '6: "()"}, - {'1: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, - {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, - {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, - {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord40Array|CsvConversionError v14 = fromCsvStringWithType(csvStringData3, config); - test:assertEquals(v14, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: "2.234", '6: "()"}, - {'1: 1, '2: "string2", '3: false, '4: 0, '5: "0", '6: "null"}, - {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: "1.23", '6: "()"}, - {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: "-6.51", '6: "()"}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord41Array|CsvConversionError v15 = fromCsvStringWithType(csvStringData2, config); - test:assertEquals(v15, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, - {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord42Array|CsvConversionError v16 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v16, [ - {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, - {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord43Array|CsvConversionError v17 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v17, [ - {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, - {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord44Array|CsvConversionError v18 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v18, [ - {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, - {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord45Array|CsvConversionError v19 = fromCsvStringWithType(csvStringData6, config); - test:assertTrue(v19 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v19).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord46Array|CsvConversionError v19_2 = fromCsvStringWithType(csvStringData6, config); - test:assertTrue(v19_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v19_2).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord47Array|CsvConversionError v19_3 = fromCsvStringWithType(csvStringData6, config); - test:assertTrue(v19_3 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v19_3).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord49Array|CsvConversionError v19_4 = fromCsvStringWithType(csvStringData6, config); - test:assertTrue(v19_4 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v19_4).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord56Array|CsvConversionError v19_5 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v19_5, [ - {H1: "", H4: "", '1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {H1: "", H4: "", '1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, - {H1: "", H4: "", '1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, - {H1: "", H4: "", '1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, - {H1: "", H4: "", '1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - record {string H1 = ""; string H4 = ""; int '2 = 10;}[]|CsvConversionError v30_2 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v30_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v30_2).message(), generateErrorMessageForInvalidCast("string1", "int"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord53Array|CsvConversionError v28 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v28 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v28).message(), generateErrorMessageForMissingRequiredField("H4"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord53Array|CsvConversionError v28_2 = fromCsvStringWithType(csvStringData6, config); - test:assertTrue(v28_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v28_2).message(), generateErrorMessageForMissingRequiredField("H4"), string `Test failed for config ${config.toBalString()}`); -} - -function testHeaderConfigWithFalseValue(FromCSVConfig config = config21) { - record {}[]|CsvConversionError v1 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v1, [ - {'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: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, - {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord28Array|CsvConversionError v2 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v2, [ - {'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: "1", '2: "string2", '3: false, '4: 0, '5: 0, '6: ()}, - {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, - {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, - {'1: "1", '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - - CustomRecord29Array|CsvConversionError v3 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v3 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v3).message(), generateErrorMessageForInvalidCast("a", "int"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord30Array|CsvConversionError v4 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v4, [ - {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, - {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, - {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, - {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord31Array|CsvConversionError v5 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v5, [ - {'1: "a", '6: "f"}, - {'1: "1", '6: "()"}, - {'1: "1", '6: "null"}, - {'1: "1", '6: "()"}, - {'1: "1", '6: "()"}, - {'1: "1", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord32Array|CsvConversionError v6 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v6 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v6).message(), generateErrorMessageForInvalidCast("a", "int"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord33Array|CsvConversionError v7 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v7, [ - {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, - {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, - {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, - {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord34Array|CsvConversionError v8 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v8, [ - {'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: "1", '2: "string2", '3: false, '4: 0, '5: "0", '6: "null"}, - {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: "1.23", '6: "()"}, - {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: "-6.51", '6: "()"}, - {'1: "1", '2: "string5", '3: true, '4: 3, '5: "3", '6: "()"} - ]); - - CustomRecord35Array|CsvConversionError v9 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v9, [ - {'1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f", '9: ""}, - {'1: "1", '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: "()", '9: ""}, - {'1: "1", '2: "string2", '3: false, '4: 0, '5: 0, '6: "null", '9: ""}, - {'1: "1", '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: "()", '9: ""}, - {'1: "1", '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: "()", '9: ""}, - {'1: "1", '2: "string5", '3: true, '4: 3, '5: 3, '6: "()", '9: ""} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord36Array|CsvConversionError v10 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v10, [ - {'1: "a", '6: "f", '9: ""}, - {'1: "1", '6: "()", '9: ""}, - {'1: "1", '6: "null", '9: ""}, - {'1: "1", '6: "()", '9: ""}, - {'1: "1", '6: "()", '9: ""}, - {'1: "1", '6: "()", '9: ""} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord37Array|CsvConversionError v11 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v11, [ - {'1: "a", '5: "e", '6: "f"}, - {'1: "1", '5: "2.234", '6: "()"}, - {'1: "1", '5: "0", '6: "null"}, - {'1: "1", '5: "1.23", '6: "()"}, - {'1: "1", '5: "-6.51", '6: "()"}, - {'1: "1", '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord38Array|CsvConversionError v12 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v12, [ - {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, - {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, - {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, - {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord39Array|CsvConversionError v13 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v13, [ - {'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: "1", '2: "string2", '3: "false", '4: "0", '5: "0", '6: "null"}, - {'1: "1", '2: "string3", '3: "0", '4: "1.23", '5: "1.23", '6: "()"}, - {'1: "1", '2: "string4", '3: "1", '4: "-6.51", '5: "-6.51", '6: "()"}, - {'1: "1", '2: "string5", '3: "true", '4: "3", '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord40Array|CsvConversionError v14 = fromCsvStringWithType(csvStringData3, config); - test:assertEquals(v14, [ - {'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: 1, '2: "string2", '3: false, '4: 0, '5: "0", '6: "null"}, - {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: "1.23", '6: "()"}, - {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: "-6.51", '6: "()"}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: "3", '6: "()"} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord41Array|CsvConversionError v15 = fromCsvStringWithType(csvStringData2, config); - test:assertEquals(v15, [ - {'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: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, - {'1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord42Array|CsvConversionError v16 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v16, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, - {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord43Array|CsvConversionError v17 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v17, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, - {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord44Array|CsvConversionError v18 = fromCsvStringWithType(csvStringData6, config); - test:assertEquals(v18, [ - {'1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {'1: 1, '2: "string2", '3: false, '4: 0, '5: 0.0, '6: null}, - {'1: 1, '2: "string3", '3: false, '4: 1.23, '5: 1.23, '6: ()}, - {'1: 1, '2: "string4", '3: true, '4: -6.51, '5: -6.51, '6: ()}, - {'1: 1, '2: "string5", '3: true, '4: 3, '5: 3.0, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord45Array|CsvConversionError v19 = fromCsvStringWithType(csvStringData6, config); - test:assertTrue(v19 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v19).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord46Array|CsvConversionError v19_2 = fromCsvStringWithType(csvStringData6, config); - test:assertTrue(v19_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v19_2).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord47Array|CsvConversionError v19_3 = fromCsvStringWithType(csvStringData6, config); - test:assertTrue(v19_3 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v19_3).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord49Array|CsvConversionError v19_4 = fromCsvStringWithType(csvStringData6, config); - test:assertTrue(v19_4 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v19_4).message(), generateErrorMessageForMissingRequiredField("H1"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord56Array|CsvConversionError v19_5 = fromCsvStringWithType(csvStringData1, config); - test:assertEquals(v19_5, [ - {H1: "", H4: "", '1: "a", '2: "b", '3: "c", '4: "d", '5: "e", '6: "f"}, - {H1: "", H4: "", '1: 1, '2: "string1", '3: true, '4: 2.234, '5: 2.234, '6: ()}, - {H1: "", H4: "", '1: 1, '2: "string2", '3: false, '4: 0, '5: 0, '6: null}, - {H1: "", H4: "", '1: 1, '2: "string3", '3: 0, '4: 1.23, '5: 1.23, '6: ()}, - {H1: "", H4: "", '1: 1, '2: "string4", '3: 1, '4: -6.51, '5: -6.51, '6: ()}, - {H1: "", H4: "", '1: 1, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} - ], string `Test failed for config ${config.toBalString()}`); - - CustomRecord55Array|CsvConversionError v30_2 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v30_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v30_2).message(), generateErrorMessageForInvalidCast("a", "int"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord53Array|CsvConversionError v28 = fromCsvStringWithType(csvStringData1, config); - test:assertTrue(v28 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v28).message(), generateErrorMessageForMissingRequiredField("H4"), string `Test failed for config ${config.toBalString()}`); - - CustomRecord53Array|CsvConversionError v28_2 = fromCsvStringWithType(csvStringData6, config); - test:assertTrue(v28_2 is CsvConversionError, string `Test failed for config ${config.toBalString()}`); - test:assertEquals((v28_2).message(), generateErrorMessageForMissingRequiredField("H4"), string `Test failed for config ${config.toBalString()}`); -} - -boolean enable = true; - -@test:Config{enable: !enable} -function test() { - CustomRecord46Array|CsvConversionError v20 = fromCsvStringWithType(csvStringData6, config23); - test:assertEquals(v20, [ - {H1: 1, H2: "string1", H3: true, H4: 2.234, H5: 2.234, H6: ()}, - {H1: 1, H2: "string2", H3: false, H4: 0, H5: 0.0, H6: null}, - {H1: 1, H2: "string3", H3: false, H4: 1.23, H5: 1.23, H6: ()}, - {H1: 1, H2: "string4", H3: true, H4: -6.51, H5: -6.51, H6: ()}, - {H1: 1, H2: "string5", H3: true, H4: 3, H5: 3.0, H6: ()} - ]); -} diff --git a/ballerina/tests/test_user_config_values.bal b/ballerina/tests/test_user_config_values.bal deleted file mode 100644 index 730707e..0000000 --- a/ballerina/tests/test_user_config_values.bal +++ /dev/null @@ -1,410 +0,0 @@ -FromCSVConfig config1 = { - startNumber: 1, - skipHeaders: true -}; - -FromCSVConfig config2 = { - startNumber: 2, - skipHeaders: true -}; - -FromCSVConfig config3 = { - startNumber: -2 -}; - -FromCSVConfig config4 = { - startNumber: 100 -}; - -FromCSVConfig config5 = { - headerStartNumber: 1 -}; - -FromCSVConfig config6 = { - headerStartNumber: 2 -}; - -FromCSVConfig config7 = { - headerStartNumber: -2 -}; - -FromCSVConfig config8 = { - headerStartNumber: 100 -}; - -FromCSVConfig config9 = { - dataStartNumber: 1 -}; - -FromCSVConfig config10 = { - dataStartNumber: 2 -}; - -FromCSVConfig config11 = { - dataStartNumber: -2 -}; - -FromCSVConfig config12 = { - dataStartNumber: 100 -}; - -FromCSVConfig config13 = { - startNumber: 10, - headerStartNumber: 8 -}; - -FromCSVConfig config14 = { - startNumber: 10, - headerStartNumber: 10 -}; - -FromCSVConfig config15 = { - startNumber: 10, - dataStartNumber: 8 -}; - -FromCSVConfig config16 = { - startNumber: 10, - dataStartNumber: 10 -}; - -FromCSVConfig config17 = { - headerStartNumber: 10, - dataStartNumber: 8 -}; - -FromCSVConfig config18 = { - headerStartNumber: 10, - dataStartNumber: 10 -}; - -FromCSVConfig config19 = { - startNumber: 12, - headerStartNumber: 10, - dataStartNumber: 12 -}; - -FromCSVConfig config20 = { - startNumber: 12, - headerStartNumber: 10, - dataStartNumber: 12 -}; - -// startNumber, header Start number, data start number values should be configured to each test cases separately. - -FromCSVConfig config21 = { - headers: false -}; - -FromCSVConfig config22 = { - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] -}; - -FromCSVConfig config23 = { - headers: false, - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] -}; - -FromCSVConfig config24 = { - skipHeaders: true, - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] -}; - -FromCSVConfig config25 = { - customheader: [1, 2, 3, 4, 5, 6] -}; - -FromCSVConfig config26 = { - customheader: ["H2", "H3", "H4", "H5", "H6"] -}; - -FromCSVConfig config27 = { - skipHeaders: true, - customheader: [1, 2, 3, 5, 6] -}; - -FromCSVConfig config28 = { - ignoreEmptyLines: false -}; - -FromCSVConfig config29 = { - ignoreEmptyLines: false -}; - -// Tests with ignore empty lines with data startnumber, header Start number, Start number should be tested separaetly. - -FromCSVConfig config30 = { - ignoreEmptyLines: false, - orderBy: { - column: "a" - } -}; - -FromCSVConfig config31 = { - ignoreEmptyLines: false, - orderBy: [ - { column: "a", columnOrder: "DESC"}, - { column: "f", columnOrder: "ASC"} - ] -}; - -FromCSVConfig config32 = { - ignoreEmptyLines: false, - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"], - orderBy: [ - { column: "a", columnOrder: "DESC"}, - { column: "f", columnOrder: "ASC"} - ] -}; - -FromCSVConfig config33 = { - ignoreEmptyLines: false, - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"], - orderBy: [ - { column: "H3", columnOrder: "DESC"}, - { column: "H4", columnOrder: "ASC"} - ] -}; - -// Need to test with orders with each column(type) separately - -FromCSVConfig config34 = { - skipHeaders: true, - headers: false -}; - -FromCSVConfig config35 = { - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] -}; - -FromCSVConfig config36 = { - skipHeaders: true, - headers: false, - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] -}; - -FromCSVConfig config37 = { - skipHeaders: true, - headers: true, - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"] -}; - -FromCSVConfig config38 = { - skipHeaders: true, - headers: true, - customheader: [1, 2, 3, 4, 5, 6] -}; - -FromCSVConfig config39 = { - skipHeaders: true, - headers: true, - customheader: ["H2", "H3", "H4", "H5", "H6"] -}; - -FromCSVConfig config40 = { - skipHeaders: true, - headers: true, - customheader: ["H2", "H3", "H4", "H5", "H6"] -}; - -FromCSVConfig config41 = { - skipdataRows: 2 -}; - -FromCSVConfig config42 = { - skipdataRows: 3, - ignoreEmptyLines: false -}; - -FromCSVConfig config43 = { - skipdataRows: 2, - headers: false -}; - -FromCSVConfig config44 = { - skipdataRows: 3, - ignoreEmptyLines: false, - skipHeaders: true -}; - -FromCSVConfig config45 = { - dataRowCount: 2 -}; - -FromCSVConfig config46 = { - dataRowCount: 3, - ignoreEmptyLines: false -}; - -FromCSVConfig config47 = { - dataRowCount: 2, - skipHeaders: true -}; - -FromCSVConfig config48 = { - dataRowCount: 3, - headers: false, - ignoreEmptyLines: false -}; - -FromCSVConfig config49 = { - dataRowCount: 2, - skipdataRows: 2 -}; - -FromCSVConfig config50 = { - dataRowCount: 2, - skipdataRows: 2, - ignoreEmptyLines: false -}; - -FromCSVConfig config51 = { - dataRowCount: 2, - skipdataRows: 2, - ignoreEmptyLines: false, - skipHeaders: true -}; - -FromCSVConfig config52 = { - dataRowCount: 2, - skipdataRows: 2, - ignoreEmptyLines: false, - headers: false -}; - -FromCSVConfig config53 = { - separator: "@" -}; - -FromCSVConfig config54 = { - separator: "@", - skipHeaders: true -}; - -FromCSVConfig config55 = { - separator: "@", - headers: false -}; - -FromCSVConfig config56 = { - headers: false, - orderBy: { - column: "abc" - } -}; - -FromCSVConfig config57 = { - skipHeaders: true, - orderBy: { - column: "abc" - } -}; - -FromCSVConfig config58 = { - orderBy: [ - {column: "a", columnOrder: "DESC"}, - {column: "b"} - ] -}; - -FromCSVConfig config59 = { - orderBy: [ - {column: "a", columnOrder: "DESC"}, - {column: "b"} - ], - skipColumns: "c" -}; - -FromCSVConfig config60 = { - orderBy: [ - {column: "a", columnOrder: "DESC"}, - {column: "b"} - ], - skipColumns: "a" -}; - -FromCSVConfig config61 = { - orderBy: [ - {column: "a", columnOrder: "DESC"}, - {column: "b"} - ], - skipColumns: ["c", "a"] -}; - -FromCSVConfig config62 = { - orderBy: [ - {column: "a", columnOrder: "DESC"}, - {column: "b"} - ], - skipColumns: ["b", "a"] -}; - -FromCSVConfig config63 = { - orderBy: [ - {column: "a", columnOrder: "DESC"}, - {column: "b"} - ], - skipColumns: 1 -}; - -FromCSVConfig config64 = { - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"], - orderBy: [ - {column: "H1", columnOrder: "DESC"}, - {column: "H2"} - ], - skipColumns: "a" -}; - -FromCSVConfig config65 = { - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"], - orderBy: [ - {column: "a", columnOrder: "DESC"}, - {column: "b"} - ], - skipColumns: ["a", "b"] -}; - -FromCSVConfig config66 = { - customheader: [1, 2, 3, 4, 5, 6], - orderBy: [ - {column: "1", columnOrder: "DESC"}, - {column: "2"} - ], - skipColumns: [1, 2] -}; - -FromCSVConfig config67 = { - customheader: [1, 2, 3, 4, 5, 6], - orderBy: [ - {column: 1, columnOrder: "DESC"}, - {column: 2} - ], - skipColumns: [1, 2] -}; - -FromCSVConfig config68 = { - customheader: [1, 2, 3, 4, 5, 6], - orderBy: [ - {column: 1, columnOrder: "DESC"}, - {column: 2} - ], - skipColumns: [3, 4] -}; - -FromCSVConfig config69 = { - customheader: [1, 2, 3, 4, 5, 6], - skipColumns: [100, 101] -}; - -FromCSVConfig config70 = { - customheader: ["H1", "H2", "H3", "H4", "H5", "H6"], - skipColumns: ["A", "B"] -}; - -FromCSVConfig config71 = { - customheader: [1, 2, 3, 4, 5, 6], - skipColumns: ["4", "5"] -}; - -// Needs to have separate tests for each skip columns query diff --git a/ballerina/types.bal b/ballerina/types.bal new file mode 100644 index 0000000..e7521c7 --- /dev/null +++ b/ballerina/types.bal @@ -0,0 +1,51 @@ +public type CsvConversionError error; + +public type Options record { + 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 = {}; + int[]|string skipLines = []; +}; + +public type ParseOption record {| + *Options; + string delimiter = ","; + string encoding = "UTF-8"; + string locale = "en_US"; + string textEnclosure = "\""; + string escapeChar = "\\"; + LineTerminator|LineTerminator[] lineTerminator = [CR, LF, CRLF]; + NilValue? nilValue = (); + string comment = "#"; + false|int:Unsigned32 header = 0; +|}; + +public type parseToRecordOption record {| + *ParseOption; + + // if header = false and this value is null, Then compiler time error. + string[]? customHeaders = (); +|}; + +public type ToRecordOptions record { + *Options; + + // if source is array and this field is null => compile time error + string[]? customHeaders = (); +}; + +public enum LineTerminator { + CR = "\r", + LF = "\n", + CRLF = "\r\n" +}; + +public enum NilValue { + NULL = "null", + EMPTY_STRING = "", + NOT_APPLICABLE = "N/A", + BAL_NULL = "()" +}; diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index 70b960c..3db6b47 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -6,7 +6,7 @@ authors = ["Ballerina"] keywords = ["csv"] repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" license = ["Apache-2.0"] -distribution = "2201.8.1" +distribution = "2201.9.0" export = ["data.csv"] [platform.java17] diff --git a/gradle.properties b/gradle.properties index 538c62a..da791ab 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.stdlib version=0.1.0-SNAPSHOT -ballerinaLangVersion=2201.8.1 +ballerinaLangVersion=2201.9.0 checkstyleToolVersion=10.12.0 puppycrawlCheckstyleVersion=10.12.0 diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index e7ff817..04d7063 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -32,7 +32,8 @@ import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; -import io.ballerina.stdlib.data.csvdata.csv.CsvConfig; +import io.ballerina.stdlib.data.csvdata.utils.Constants; +import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import java.util.ArrayList; import java.util.Comparator; @@ -134,17 +135,17 @@ private static Object stringToBoolean(String value) throws NumberFormatException } private static Object stringToNull(String value, CsvConfig config) throws NumberFormatException { - Object nullValue = config.nullValue; + Object nullValue = config.nilValue; if (nullValue != null && StringUtils.getStringValue(nullValue).equalsIgnoreCase(value)) { return nullValue; } - if ("null".equalsIgnoreCase(value) || "()".equalsIgnoreCase(value)) { + if (Constants.Values.NULL.equalsIgnoreCase(value) || Constants.Values.BALLERINA_NULL.equalsIgnoreCase(value)) { if (nullValue != null) { return nullValue; } return null; } - return returnError(value, "()"); + return returnError(value, Constants.Values.BALLERINA_NULL); } private static Object stringToUnion(BString string, UnionType expType, CsvConfig config) throws NumberFormatException { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java deleted file mode 100644 index 3d4b199..0000000 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvConfig.java +++ /dev/null @@ -1,135 +0,0 @@ -package io.ballerina.stdlib.data.csvdata.csv; - -import io.ballerina.runtime.api.values.BMap; -import io.ballerina.runtime.api.values.BString; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; - -import java.util.ArrayList; - -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.*; - -public class CsvConfig { - public long startNumber = 0; - public long headerStartNumber = 0; - public long dataStartNumber = 1; - public boolean headers = true; - public char escapeCharacter = '\\'; - public boolean ignoreEmptyLines = true; - public char separator = ','; - public String quote = "\""; - public boolean skipHeaders = false; - public long skipDataRows = 0; - public long dataRowCount = -1; - public Object orderBy = new ArrayList<>(); - public Object skipColumns = null; - public Object customHeader = null; - public boolean suppressEscaping = false; - public Object nullValue = null; - public Object root = null; - public char lineSeparator = '\n'; - - - private CsvConfig(boolean headers, char escapeCharacter, boolean ignoreEmptyLines, - char separator, boolean skipHeaders, long skipDataRows, - long dataRowCount, Object orderBy, Object skipColumns, Object customHeader, - boolean suppressEscaping, Object nullValue, char lineSeparator) { - this.headers = headers; - this.escapeCharacter = escapeCharacter; - this.separator = separator; - this.skipHeaders = skipHeaders; - this.skipDataRows = skipDataRows; - this.dataRowCount = dataRowCount; - this.orderBy = orderBy; - this.skipColumns = skipColumns; - this.customHeader = customHeader; - this.suppressEscaping = suppressEscaping; - this.nullValue = nullValue; - this.lineSeparator = lineSeparator; - updateDependentConfigurations(); - } - - private void updateDependentConfigurations() { - if (!this.headers) { - this.skipHeaders = false; - } - if (this.startNumber < 0) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, - "startNumber parameter cannot be lower than 0"); - } - if (!this.skipHeaders && this.headerStartNumber < 0) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, - "headerStartNumber parameter cannot be lower than 0"); - } - if (this.startNumber < 0) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, - "dataStartNumber parameter cannot be lower than 0"); - } - if (!this.skipHeaders && this.startNumber > this.headerStartNumber) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, - "startNumber parameter cannot be greater than headerStartNumber parameter"); - } - if (this.headerStartNumber > this.dataStartNumber) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, - "headerStartNumber parameter cannot be greater than dataStartNumber parameter"); - } - if (this.startNumber > this.dataStartNumber) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONFIGURATIONS, - "startNumber parameter cannot be greater than dataStartNumber parameter"); - } - } - - private CsvConfig(long startNumber, long headerStartNumber, long dataStartNumber, - boolean headers, char escapeCharacter, boolean ignoreEmptyLines, - char separator, String quote, boolean skipHeaders, long skipDataRows, - long dataRowCount, Object orderBy, Object skipColumns, Object customHeader, - boolean suppressEscaping, Object nullValue, Object root) { - this.startNumber = startNumber; - this.headerStartNumber = headerStartNumber; - this.dataStartNumber = dataStartNumber; - this.headers = headers; - this.escapeCharacter = escapeCharacter; - this.ignoreEmptyLines = ignoreEmptyLines; - this.separator = separator; - this.quote = quote; - this.skipHeaders = skipHeaders; - this.skipDataRows = skipDataRows; - this.dataRowCount = dataRowCount; - this.orderBy = orderBy; - this.skipColumns = skipColumns; - this.customHeader = customHeader; - this.suppressEscaping = suppressEscaping; - this.nullValue = nullValue; - this.root = root; - updateDependentConfigurations(); - } - - public CsvConfig() { - } - - public static CsvConfig createFromCsvConfiguration(BMap config) { - return new CsvConfig( - config.getIntValue(START_NUMBER), config.getIntValue(HEADER_START_NUMBER), - config.getIntValue(DATA_START_NUMBER), config.getBooleanValue(HEADERS), - // TODO: Handle unicodes - config.getStringValue(ESCAPE_CHARACTER).toString().charAt(0), config.getBooleanValue(IGNORE_EMPTY_LINES), - config.getStringValue(SEPARATOR).toString().charAt(0), config.getStringValue(QUOTE).toString(), - config.getBooleanValue(SKIP_HEADERS), config.getIntValue(SKIP_DATA_ROWS), - config.getIntValue(DATA_ROW_COUNT), config.get(ORDER_BY), config.get(SKIP_COLUMNS), - config.get(CUSTOM_HEADER), config.getBooleanValue(SUPPRESS_ESCAPING), - config.get(NULL_VALUE), config.get(ROOT) - ); - } - - public static CsvConfig createToCsvConfiguration(BMap config) { - return new CsvConfig( - config.getBooleanValue(HEADERS), config.getStringValue(ESCAPE_CHARACTER).toString().charAt(0), - config.getBooleanValue(IGNORE_EMPTY_LINES), config.getStringValue(SEPARATOR).toString().charAt(0), - config.getBooleanValue(SKIP_HEADERS), config.getIntValue(SKIP_DATA_ROWS), - config.getIntValue(DATA_ROW_COUNT), config.get(ORDER_BY), - config.get(SKIP_COLUMNS), config.get(CUSTOM_HEADER), - config.getBooleanValue(SUPPRESS_ESCAPING), config.get(NULL_VALUE), - config.getStringValue(LINE_SEPARATOR).toString().charAt(0) - ); - } -} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 2e6512d..e7a9b07 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -29,6 +29,7 @@ import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.data.csvdata.FromString; +import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; @@ -95,7 +96,7 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, } public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { - if (sm.config.customHeader == null && (sm.config.skipHeaders || !sm.config.headers)) { + if (sm.config.customHeader == null && (sm.config.header == Boolean.FALSE)) { String header = String.valueOf(sm.columnIndex + 1); Map fieldHierarchy = sm.fieldHierarchy; if (fieldHierarchy.containsKey(header)) { @@ -106,26 +107,6 @@ public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { return sm.headers.get(sm.columnIndex); } - public static void updateHeaders(CsvParser.StateMachine sm) { - List updatedHeaders = Arrays.asList( - QueryParser.parse(sm.config.skipColumns, sm.headers.toArray(new String[]{}))); - generateSkipColumnIndexes(updatedHeaders, sm); - } - - public static void generateSkipColumnIndexes(List updatedHeaders, CsvParser.StateMachine sm) { - String header; - ArrayList copyOfHeaders = new ArrayList<>(); - for (int i = 0; i < sm.headers.size(); i++) { - header = sm.headers.get(i); - if (!updatedHeaders.contains(header)) { - sm.skipColumnIndexes.add(i); - continue; - } - copyOfHeaders.add(header); - } - sm.headers = copyOfHeaders; - } - public static void checkAndAddCustomHeaders(CsvParser.StateMachine sm, Object customHeader) { if (customHeader == null) { return; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 984db59..fa6053f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -26,6 +26,7 @@ import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; +import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; @@ -34,7 +35,6 @@ import java.util.*; import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.checkAndAddCustomHeaders; -import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.updateHeaders; import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.*; /** @@ -96,8 +96,6 @@ static class StateMachine { int lineNumber = 0; ArrayType rootArrayType = null; CsvConfig config = null; - ArrayList skipColumnIndexes = new ArrayList<>(); - StateMachine() { reset(); } @@ -121,7 +119,6 @@ public void reset() { currentEscapeCharacters = new Stack<>(); charBuff = new char[1024]; charBuffIndex = 0; - skipColumnIndexes = new ArrayList<>(); } private static boolean isWhitespace(char ch) { @@ -185,12 +182,11 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError } State currentState; - if (config.headers) { + if (config.header != Boolean.FALSE) { currentState = HEADER_START_STATE; } else { if (config.customHeader != null) { checkAndAddCustomHeaders(this, config.customHeader); - updateHeaders(this); } currentState = ROW_START_STATE; addFieldNamesForNonHeaderState(); @@ -209,7 +205,6 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError throw new CsvParserException("Invalid token found"); } - sortCsvData(rootCsvNode, config); return rootCsvNode; } catch (IOException e) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TOKEN, e.getMessage(), line, column); @@ -258,35 +253,24 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C char ch; State state = HEADER_START_STATE; //TODO: If the header is not present make the headers and fieldnames to be default values - char separator = sm.config.separator; - boolean skipHeaders = sm.config.skipHeaders; + char separator = sm.config.delimiter; Object customHeader = sm.config.customHeader; boolean headerStart = false; + int headerStartRowNumber = getHeaderStartRowWhenHeaderIsPresent(sm.config.header); for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); - if (!(isWhitespace(ch) && sm.isNewLineOrEof(ch))) { - headerStart = true; - } - if (ignoreHeader(sm)) { + if (sm.lineNumber < headerStartRowNumber - 1) { sm.lineNumber++; continue; } + if (!(isWhitespace(ch) && sm.isNewLineOrEof(ch))) { + headerStart = true; + } if (customHeader != null) { if (headerStart && sm.isNewLineOrEof(ch)) { checkAndAddCustomHeaders(sm, customHeader); sm.lineNumber++; - updateHeaders(sm); - state = HEADER_END_STATE; - break; - } - continue; - } - if (skipHeaders) { - if (headerStart && sm.isNewLineOrEof(ch)) { - sm.lineNumber++; - sm.addFieldNamesForNonHeaderState(); - updateHeaders(sm); state = HEADER_END_STATE; break; } @@ -302,7 +286,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C finalizeHeaders(sm); sm.columnIndex = 0; sm.lineNumber++; - updateHeaders(sm); state = HEADER_END_STATE; } else if (StateMachine.isWhitespace(ch)) { state = this; @@ -318,6 +301,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return state; } + private int getHeaderStartRowWhenHeaderIsPresent(Object header) { + return ((Long) header).intValue(); + } + private void finalizeHeaders(StateMachine sm) throws CsvParserException { Type expType = sm.expectedArrayElementType; if (expType instanceof RecordType) { @@ -353,15 +340,6 @@ private void validateRemainingRecordFields(StateMachine sm) { } } - private boolean ignoreHeader(StateMachine sm) { - int lineNumber = sm.lineNumber; - if (lineNumber < sm.config.headerStartNumber - || lineNumber < sm.config.startNumber) { - return true; - } - return false; - } - private void addHeader(StateMachine sm) throws CsvParserException { String value = sm.value(); if (sm.expectedArrayElementType instanceof RecordType) { @@ -387,19 +365,15 @@ private static class RowStartState implements State { public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { char ch; State state = ROW_START_STATE; - char separator = sm.config.separator; + char separator = sm.config.delimiter; + long[] skipLines = getSkipDataRows(sm.config.skipLines); // TODO: Ignore this in future for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); - if (calculateNumberOfRows(sm.config.dataRowCount, sm.rowIndex, sm.config.skipDataRows)) { - sm.rowIndex++; - sm.lineNumber++; - break; - } - if (sm.rowIndex < sm.config.skipDataRows) { + if (skipLines[0] <= sm.lineNumber && sm.lineNumber < skipLines[skipLines.length - 1]) { if (isEndOfTheRow(sm, ch)) { sm.lineNumber++; sm.rowIndex++; @@ -431,9 +405,9 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } private void handleCsvRow(StateMachine sm) throws CsvParserException { - if (ignoreRow(sm)) { - sm.clear(); - sm.columnIndex = 0; + if (ignoreRow(sm.peek())) { + sm.lineNumber++; + sm.rowIndex++; return; } addRowValue(sm); @@ -442,6 +416,10 @@ private void handleCsvRow(StateMachine sm) throws CsvParserException { sm.currentCsvNode = null; } + private boolean ignoreRow(String peek) { + return peek.isEmpty(); + } + private void initiateNewRowType(StateMachine sm) throws CsvParserException { sm.currentCsvNode = CsvCreator.initRowValue(sm.expectedArrayElementType); } @@ -451,6 +429,7 @@ private void finalizeTheRow(StateMachine sm) { if (rootArraySize == -1 || sm.rowIndex < rootArraySize) { sm.rootCsvNode.add(sm.rowIndex, sm.currentCsvNode); sm.rowIndex++; + sm.lineNumber++; } } @@ -459,10 +438,6 @@ private void addRowValue(StateMachine sm) throws CsvParserException { Type type; Type exptype = sm.expectedArrayElementType; - if (checkColumnIsSkippedOrNot(sm)) { - return; - } - if (exptype instanceof RecordType) { type = getExpectedRowTypeOfRecord(sm); } else if (exptype instanceof MapType) { @@ -476,30 +451,13 @@ private void addRowValue(StateMachine sm) throws CsvParserException { } if (type != null) { + String value = sm.value(); CsvCreator.convertAndUpdateCurrentJsonNode(sm, - StringUtils.fromString(sm.value()), type, sm.config, exptype); + StringUtils.fromString(value), type, sm.config, exptype); } sm.columnIndex++; } - private boolean checkColumnIsSkippedOrNot(StateMachine sm) { - return sm.skipColumnIndexes.contains(sm.columnIndex); - } - - private boolean ignoreRow(StateMachine sm) { - String value = sm.peek(); - int rowNumber = sm.rowIndex + 1; - if (sm.config.ignoreEmptyLines && value.isEmpty()) { - return true; - } - if (rowNumber < sm.config.dataStartNumber - || rowNumber < sm.config.startNumber) { - sm.rowIndex++; - return true; - } - return false; - } - private Type getExpectedRowTypeOfTuple(StateMachine sm, TupleType tupleType) { List tupleTypes = tupleType.getTupleTypes(); if (tupleTypes.size() > sm.columnIndex) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 6fb5834..476e32b 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.*; +import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; @@ -87,7 +88,6 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { validateExpectedArraySize(expectedArraySize, sourceArraySize); traverseCsvWithExpectedType(expectedArraySize, sourceArraySize, csv); - sortCsvData(rootCsvNode, config); return rootCsvNode; } @@ -113,9 +113,7 @@ public void traverseCsvArrayMembersWithMapAsCsvElementType(long length, BArray c Object rowValue; for (int i = 0; i < length; i++) { rowValue = traverseCsvElementWithMapOrRecord(csv.get(i), expectedArrayType); - if (!constructRootCsvNode(rowValue, i, config.dataRowCount)) { - break; - } + checkSkipDataRowsAndAddDataRow(rowValue, i, config.skipLines); } } @@ -123,21 +121,16 @@ public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray Object rowValue; for (int i = 0; i < length; i++) { rowValue = traverseCsvElementWithArray(csv.get(i), expectedArrayType); - if (!constructRootCsvNode(rowValue, i, config.dataRowCount)) { - break; - } + checkSkipDataRowsAndAddDataRow(rowValue, i, config.skipLines); } } - private boolean constructRootCsvNode(Object value, int i, long dataRowCount) { - long skipDataRows = config.skipDataRows; - if (i < skipDataRows) { + private boolean checkSkipDataRowsAndAddDataRow(Object value, int index, Object skipLinesConfig) { + long[] skipLines = getSkipDataRows(skipLinesConfig); + if (skipLines[0] <= index && index < skipLines[skipLines.length - 1]) { return true; } rootCsvNode.append(value); - if (calculateNumberOfRows(dataRowCount, i, skipDataRows)) { - return false; - } return true; } @@ -148,7 +141,6 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected this.fieldHierarchy = new HashMap<>(recordType.getFields()); this.headerFieldHierarchy = new HashMap<>(recordType.getFields()); this.restType = recordType.getRestFieldType(); - // TODO: check for package ID currentCsvNode = ValueCreator.createRecordValue(recordType.getPackage(), recordType.getName()); traverseCsvMap(csvElement, expectedType, false); break; @@ -157,13 +149,6 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected currentCsvNode = ValueCreator.createMapValue(mapType); traverseCsvMap(csvElement, expectedType, true); break; -// case TypeTags.TABLE_TAG: -// //TODO: Check -// TableType tableType = (TableType) expectedType; -// this.fieldHierarchy = new HashMap<>(); -// currentCsvNode = ValueCreator.createT(tableType); -// traverseCsvMap(csvElement, expectedType, true); -// break; default: throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index a271f95..b94f9ab 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -24,7 +24,8 @@ import io.ballerina.runtime.api.values.*; import io.ballerina.stdlib.data.csvdata.io.DataReaderTask; import io.ballerina.stdlib.data.csvdata.io.DataReaderThreadPool; -import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; +import io.ballerina.stdlib.data.csvdata.utils.Constants; +import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; @@ -38,47 +39,136 @@ * @since 0.1.0 */ public class Native { + public static Object parseStringToRecord(BString csv, BMap options, BTypedesc type) { + try { + return CsvParser.parse(new StringReader(csv.getValue()), + type.getDescribingType(), CsvConfig.createParserToRecordOptions(options)); + } catch (BError e) { + return e; + } catch (Exception e) { + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, type); + } + } - public static Object fromCsvWithType(BArray csv, BMap config, BTypedesc type) { + public static Object parseBytesToRecord(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvUtils.createFromCsvConfiguration(config), type.getDescribingType()); + byte[] bytes = csv.getBytes(); + return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), + type.getDescribingType(), CsvConfig.createParserToRecordOptions(options)); + } catch (BError e) { + return e; } catch (Exception e) { - return DiagnosticLog.getCsvError(e.getMessage()); + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, type); } } - public static Object fromCsvStringWithType(Environment env, Object csv, BMap config, BTypedesc 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)); + 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) { + try { + return CsvParser.parse(new StringReader(csv.getValue()), + type.getDescribingType(), CsvConfig.createParseOptions(options)); + } catch (BError e) { + return e; + } catch (Exception e) { + return DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, type); + } + } + public static Object parseBytesToList(BArray csv, BMap options, BTypedesc type) { try { - Type expType = type.getDescribingType(); - if (csv instanceof BString) { - return CsvParser.parse(new StringReader(((BString) csv).getValue()), - expType, CsvUtils.createFromCsvConfiguration(config)); - } else if (csv instanceof BArray) { - byte[] bytes = ((BArray) csv).getBytes(); + byte[] bytes = csv.getBytes(); return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), - type.getDescribingType(), CsvUtils.createFromCsvConfiguration(config)); - } else if (csv instanceof BStream) { - final BObject iteratorObj = ((BStream) csv).getIteratorObj(); - final Future future = env.markAsync(); - DataReaderTask task = new DataReaderTask(env, iteratorObj, future, - type, CsvUtils.createFromCsvConfiguration(config)); - DataReaderThreadPool.EXECUTOR_SERVICE.submit(task); - return null; - } else { - return DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TYPE, expType); - } + type.getDescribingType(), CsvConfig.createParseOptions(options)); } catch (BError e) { return e; } catch (Exception e) { return DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, type); } } + public static Object parseStreamToList(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.createParseOptions(options)); + 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 toCsv(BArray csv, BMap config, BTypedesc type) { + public static Object parseRecordAsRecordType(BArray csv, BMap options, BTypedesc type) { + try { + return CsvTraversal.traverse(csv, CsvConfig.createToRecordOptions(options), type.getDescribingType()); + } catch (Exception e) { + return DiagnosticLog.getCsvError(e.getMessage()); + } + } + public static Object parseRecordAsListType(BArray csv, BArray customHeaders, + BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvUtils.createToCsvConfiguration(config), type.getDescribingType()); + options.put(Constants.ConfigConstants.CUSTOM_HEADERS, customHeaders); + return CsvTraversal.traverse(csv, CsvConfig.createToRecordOptions(options), type.getDescribingType()); } 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.createToRecordOptions(options), type.getDescribingType()); + } catch (Exception e) { + return DiagnosticLog.getCsvError(e.getMessage()); + } + } + + public static Object parseListAsListType(BArray csv, BMap options, BTypedesc type) { + try { + return CsvTraversal.traverse(csv, CsvConfig.createOptions(options), type.getDescribingType()); + } catch (Exception e) { + return DiagnosticLog.getCsvError(e.getMessage()); + } + } + + // ---------------------------------------------------------------------------------------------------------------------------------------------------------------- + // ---------------------------------------------------------------------------------------------------------------------------------------------------------------- + + +// public static Object fromCsvWithType(BArray csv, BMap config, BTypedesc type) { +// try { +// return CsvTraversal.traverse(csv, CsvUtils.createFromCsvConfiguration(config), type.getDescribingType()); +// } catch (Exception e) { +// return DiagnosticLog.getCsvError(e.getMessage()); +// } +// } + +// +// public static Object toCsv(BArray csv, BMap config, BTypedesc type) { +// try { +// return CsvTraversal.traverse(csv, CsvUtils.createToCsvConfiguration(config), type.getDescribingType()); +// } catch (Exception e) { +// return DiagnosticLog.getCsvError(e.getMessage()); +// } +// } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java deleted file mode 100644 index 88c00eb..0000000 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/QueryParser.java +++ /dev/null @@ -1,115 +0,0 @@ -package io.ballerina.stdlib.data.csvdata.csv; - -import io.ballerina.runtime.api.utils.StringUtils; -import io.ballerina.runtime.api.values.BArray; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -public class QueryParser { - private static String rangeSeparator = ":"; - private static String exclamationCharacter = "!"; - private static String astrix = "*"; - private static String groupingStartCharacter = "("; - private static String groupingEndCharacter = ")"; - private static Object skipColumnQuery = null; - private static Set inclusiveHeaders = new HashSet<>(); - private static Set exclusiveHeaders = new HashSet<>(); - private static ArrayList columns = null; - private static String elementSeparatorRegex = "(?![^(]*\\))"; - private static String alphanumericRegex = "\\w*"; - private static String rangeRegex = "\\w*:\\w*"; - - private void reset() { - inclusiveHeaders = new HashSet<>(); - exclusiveHeaders = new HashSet<>(); - } - - public static String[] parse(Object query, String[] headers) { - //TODO: Need specific error message for all the scenarios - skipColumnQuery = query; - columns = new ArrayList<>(Arrays.asList(headers)); - return parse(); - } - - private static String[] parse() { - if (skipColumnQuery instanceof BArray) { - BArray columns = (BArray) skipColumnQuery; - for (int i = 0; i < columns.size(); i++) { - exclusiveHeaders.add(StringUtils.getStringValue(columns.get(i))); - } - } else if (skipColumnQuery instanceof Long) { - exclusiveHeaders.add(skipColumnQuery.toString()); - } else { - processStringQuery(StringUtils.getStringValue(skipColumnQuery)); - } - - exclusiveHeaders.removeAll(inclusiveHeaders); - columns.removeAll(exclusiveHeaders); - return columns.toArray(new String[columns.size()]); - } - - private static void processStringQuery(String query) { - processStringQuery(query, false); - } - - private static void processStringQuery(String query, boolean exclamation) { - String[] queryElements = query.split(elementSeparatorRegex); - for (String element: queryElements) { - //TODO: Header validations - if (element.matches(alphanumericRegex)) { - addColumn(element, exclamation); - } else if (element.startsWith(groupingStartCharacter)) { - processGroupingElements(element, exclamation); - } else if (element.startsWith(exclamationCharacter)) { - processExcludeColumns(element, !exclamation); - } else if (element.matches(rangeRegex)) { - processRangeExpression(element, exclamation); - } else { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_SKIP_COLUMN_QUERY, skipColumnQuery); - } - } - } - - private static void addColumn(String element, boolean exclamation) { - if (exclamation) { - inclusiveHeaders.add(element); - } - exclusiveHeaders.add(element); - } - - private static void processExcludeColumns(String element, boolean exclamation) { - processStringQuery(element.substring(1), exclamation); - } - - private static void processRangeExpression(String element, boolean exclamation) { - //TODO: Handle if range contains brackets and :/,! - String[] rangeElements = element.split(rangeSeparator); - String rightValue = rangeElements[1]; - int leftIndex = columns.indexOf(rangeElements[0]); - int rightIndex = rightValue.equals(astrix) ? columns.size() - 1 : columns.indexOf(rightValue); - - if (leftIndex == -1 || rightIndex == -1) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_SKIP_COLUMN_QUERY, skipColumnQuery); - } - if (leftIndex > rightIndex) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_SKIP_COLUMN_QUERY, skipColumnQuery); - } - - for (int i = leftIndex; i <= rightIndex; i++) { - addColumn(columns.get(i), exclamation); - } - } - - private static void processGroupingElements(String element, boolean exclamation) { - if (element.endsWith(groupingEndCharacter)) { - processStringQuery(element.substring(0, element.length() - 1), exclamation); - } else { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_SKIP_COLUMN_QUERY, skipColumnQuery); - } - } -} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java index b16b732..46d33fe 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java @@ -24,7 +24,7 @@ import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BTypedesc; -import io.ballerina.stdlib.data.csvdata.csv.CsvConfig; +import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.csv.CsvParser; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java index 15d1490..c14b79f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -5,30 +5,26 @@ public class Constants { public static class ConfigConstants { - public static BString START_NUMBER = StringUtils.fromString("startNumber"); - public static BString HEADER_START_NUMBER = StringUtils.fromString("headerStartNumber"); - public static BString DATA_START_NUMBER = StringUtils.fromString("dataStartNumber"); - public static BString HEADERS = StringUtils.fromString("headers"); - public static BString ESCAPE_CHARACTER = StringUtils.fromString("escapeCharacter"); - public static BString IGNORE_EMPTY_LINES = StringUtils.fromString("ignoreEmptyLines"); - public static BString SEPARATOR = StringUtils.fromString("separator"); - public static BString QUOTE = StringUtils.fromString("quote"); - public static BString SKIP_HEADERS = StringUtils.fromString("skipHeaders"); - public static BString SKIP_DATA_ROWS = StringUtils.fromString("skipdataRows"); - public static BString DATA_ROW_COUNT = StringUtils.fromString("dataRowCount"); - public static BString ORDER_BY = StringUtils.fromString("orderBy"); - public static BString SKIP_COLUMNS = StringUtils.fromString("skipColumns"); - public static BString CUSTOM_HEADER = StringUtils.fromString("customheader"); - public static BString SUPPRESS_ESCAPING = StringUtils.fromString("suppressEscaping"); - public static BString NULL_VALUE = StringUtils.fromString("nullValue"); - public static BString ROOT = StringUtils.fromString("root"); - public static BString LINE_SEPARATOR = StringUtils.fromString("lineSeparator"); + public static BString DELIMITER = StringUtils.fromString("delimiter"); + public static BString TEXT_ENCLOSURE = StringUtils.fromString("textEnclosure"); + public static BString HEADER = StringUtils.fromString("header"); + public static BString ESCAPE_CHAR = StringUtils.fromString("escapeChar"); + public static BString LINE_TERMINATOR = StringUtils.fromString("lineTerminator"); + public static BString SKIP_LINES = StringUtils.fromString("skipLines"); + public static BString NIL_VALUE = StringUtils.fromString("nilValue"); + public static BString COMMENT_CHAR = StringUtils.fromString("comment"); + public static BString LOCALE = StringUtils.fromString("locale"); + public static BString ENCODING = StringUtils.fromString("encoding"); + public static BString NIL_AS_OPTIONAL = StringUtils.fromString("nilAsOptionalField"); + public static BString ABSENT_AS_NILABLE = StringUtils.fromString("absentAsNilableType"); + public static BString ALLOW_DATA_PROJECTION = StringUtils.fromString("allowDataProjection"); + public static BString CUSTOM_HEADERS = StringUtils.fromString("customHeaders"); } - public static class OrderConfigs { - public static BString COLUMN = StringUtils.fromString("column"); - public static BString COLUMN_ORDER = StringUtils.fromString("columnOrder"); - public static BString ASC = StringUtils.fromString("ASC"); - public static BString DESC = StringUtils.fromString("DESC"); + public static class Values { + public static String NULL = "null"; + public static String BALLERINA_NULL = "()"; } + + public static String SKIP_LINE_RANGE_SEP = "-"; } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java new file mode 100644 index 0000000..fe0725e --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java @@ -0,0 +1,154 @@ +package io.ballerina.stdlib.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; + +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.*; + +public class CsvConfig { + public char delimiter = ','; + public char textEnclosure = '\\'; + public Object header = 0; + public char escapeChar = '\\'; + public Object lineTerminator = '\n'; + public Object skipLines = null; + public Object nilValue = null; + public char comment = '#'; + public String locale = "EN/US"; + public String encoding = "UTF-8"; + public boolean nilAsOptionalField = false; + public boolean absentAsNilableType = false; + public boolean allowDataProjection = true; + public Object customHeader = null; + + private CsvConfig(Object skipLines, boolean nilAsOptionalField, + boolean absentAsNilableType, boolean allowDataProjection) { + this.skipLines = skipLines; + this.nilAsOptionalField = nilAsOptionalField; + this.absentAsNilableType = absentAsNilableType; + this.allowDataProjection = allowDataProjection; + } + + 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; + } + + private CsvConfig(char delimiter, char textEnclosure, Object header, + char escapeChar, Object lineTerminator, Object skipLines, + Object nilValue, char comment, String locale, String encoding, + 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 : StringUtils.getStringValue(nilValue); + this.comment = comment; + this.locale = locale; + this.encoding = encoding; + 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, String encoding, + boolean nilAsOptionalField, boolean absentAsNilableType, + boolean allowDataProjection, Object customHeaders) { + this.delimiter = delimiter; + this.textEnclosure = textEnclosure; + this.header = header; + this.escapeChar = escapeChar; + this.lineTerminator = lineTerminator; + this.nilValue = nilValue == null ? null : StringUtils.getStringValue(nilValue); + this.comment = comment; + this.locale = locale; + this.encoding = encoding; + this.nilAsOptionalField = nilAsOptionalField; + this.absentAsNilableType = absentAsNilableType; + this.allowDataProjection = allowDataProjection; + this.skipLines = skipLines; + this.customHeader = customHeaders; + } + + public static CsvConfig createOptions(BMap options) { + updateDataProjectOptions(options); + return new CsvConfig( + options.get(SKIP_LINES), + options.getBooleanValue(NIL_AS_OPTIONAL), + options.getBooleanValue(ABSENT_AS_NILABLE), + options.getBooleanValue(ALLOW_DATA_PROJECTION) + ); + } + + public static CsvConfig createParseOptions(BMap options) { + updateDataProjectOptions(options); + return new CsvConfig( + StringUtils.getStringValue(options.getStringValue(DELIMITER)).charAt(0), + StringUtils.getStringValue(options.getStringValue(TEXT_ENCLOSURE)).charAt(0), + options.get(HEADER), + StringUtils.getStringValue(options.getStringValue(ESCAPE_CHAR)).charAt(0), + options.get(LINE_TERMINATOR), + options.get(SKIP_LINES), + options.get(NIL_VALUE), + StringUtils.getStringValue(options.getStringValue(COMMENT_CHAR)).charAt(0), + StringUtils.getStringValue(options.getStringValue(LOCALE)), + StringUtils.getStringValue(options.getStringValue(ENCODING)), + options.getBooleanValue(NIL_AS_OPTIONAL), + options.getBooleanValue(ABSENT_AS_NILABLE), + options.getBooleanValue(ALLOW_DATA_PROJECTION) + ); + } + + public static CsvConfig createParserToRecordOptions(BMap options) { + updateDataProjectOptions(options); + return new CsvConfig( + StringUtils.getStringValue(options.getStringValue(DELIMITER)).charAt(0), + StringUtils.getStringValue(options.getStringValue(TEXT_ENCLOSURE)).charAt(0), + options.get(HEADER), + StringUtils.getStringValue(options.getStringValue(ESCAPE_CHAR)).charAt(0), + options.get(LINE_TERMINATOR), + options.get(SKIP_LINES), + options.getStringValue(NIL_VALUE), + StringUtils.getStringValue(options.getStringValue(COMMENT_CHAR)).charAt(0), + StringUtils.getStringValue(options.getStringValue(LOCALE)), + StringUtils.getStringValue(options.getStringValue(ENCODING)), + options.getBooleanValue(NIL_AS_OPTIONAL), + options.getBooleanValue(ABSENT_AS_NILABLE), + options.getBooleanValue(ALLOW_DATA_PROJECTION), + options.get(CUSTOM_HEADERS) + ); + } + + public static CsvConfig createToRecordOptions(BMap options) { + updateDataProjectOptions(options); + return new CsvConfig( + options.get(SKIP_LINES), + options.getBooleanValue(NIL_AS_OPTIONAL), + options.getBooleanValue(ABSENT_AS_NILABLE), + options.getBooleanValue(ALLOW_DATA_PROJECTION), + options.get(CUSTOM_HEADERS) + ); + } + + private static void updateDataProjectOptions(BMap options) { + Object allowProjections = options.get(ALLOW_DATA_PROJECTION); + if (allowProjections instanceof Boolean) { + options.put(NIL_AS_OPTIONAL, false); + options.put(ABSENT_AS_NILABLE, false); + return; + } + BMap projections = (BMap) allowProjections; + options.put(ALLOW_DATA_PROJECTION, true); + options.put(NIL_AS_OPTIONAL, projections.getBooleanValue(NIL_AS_OPTIONAL)); + options.put(ABSENT_AS_NILABLE, projections.getBooleanValue(ABSENT_AS_NILABLE)); + } +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index cc10e2d..3396030 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -6,24 +6,14 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.*; -import io.ballerina.stdlib.data.csvdata.csv.CsvConfig; -import io.ballerina.stdlib.data.csvdata.csv.CsvParser; -import io.ballerina.stdlib.data.csvdata.csv.QueryParser; import java.util.Arrays; import java.util.Map; import static io.ballerina.runtime.api.TypeTags.INT_TAG; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.SKIP_LINE_RANGE_SEP; public class CsvUtils { - public static CsvConfig createFromCsvConfiguration(BMap config) { - return CsvConfig.createFromCsvConfiguration(config); - } - - public static CsvConfig createToCsvConfiguration(BMap config) { - return CsvConfig.createToCsvConfiguration(config); - } - public static void validateExpectedArraySize(int size, int currentSize) { if (size != -1 && size > currentSize) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, currentSize); @@ -46,37 +36,6 @@ public static boolean isBasicType(Type type) { } } - public static void sortCsvData(BArray rootCsvNode, CsvConfig config) { - Object orderConfiguration = config.orderBy; - if (orderConfiguration == null) { - return; - } - - Object[] arrayValues = rootCsvNode.getValues(); - Arrays.sort(arrayValues, (value1, value2) -> compareCsvColumns( - value1, value2, constructSortingColumnNames(orderConfiguration)) - ); - } - - public static int compareCsvColumns(Object row1, Object row2, SortConfigurations[] sortConfigurations) { - Object o1,o2; - int value; - for (SortConfigurations sortConfig: sortConfigurations) { - o1 = getRowValueForSort(row1, sortConfig.columnName); - o2 = getRowValueForSort(row2, sortConfig.columnName); - value = compareTwoColumnAndGetValue(o1, o2); - - if (value == 0) { - continue; - } - if (sortConfig.sortOrder.equals(Constants.OrderConfigs.DESC)) { - return -1 * value; - } - return value; - } - return 0; - } - public static Object getRowValueForSort(Object row, Object columnName) { if (row instanceof BMap) { return ((BMap) row).get(columnName); @@ -90,25 +49,6 @@ public static Object getRowValueForSort(Object row, Object columnName) { } } - - public static SortConfigurations[] constructSortingColumnNames(Object orderConfiguration) { - BString columnName = Constants.OrderConfigs.COLUMN; - BString sortOrder = Constants.OrderConfigs.COLUMN_ORDER; - - SortConfigurations[] columns = new SortConfigurations[]{}; - if (orderConfiguration instanceof BMap) { - BMap orderConfigMap = (BMap) orderConfiguration; - columns[0] = new SortConfigurations(orderConfigMap.get(columnName), orderConfigMap.get(sortOrder)); - } else { - BArray orderConfigArray = (BArray) orderConfiguration; - for (int i = 0; i < orderConfigArray.size(); i++) { - BMap orderConfigMap = (BMap) orderConfigArray.get(i); - columns[i] = new SortConfigurations(orderConfigMap.get(columnName), orderConfigMap.get(sortOrder)); - } - } - return columns; - } - public static int compareTwoColumnAndGetValue(Object o1, Object o2) { if (o1 == null && o2 ==null) { return 0; @@ -137,10 +77,6 @@ public static int compareTwoColumnAndGetValue(Object o1, Object o2) { return (StringUtils.getStringValue(o1)).compareTo(StringUtils.getStringValue(o2)); } - public static boolean calculateNumberOfRows(long dataRowCount, int i, long skipDataRows) { - return dataRowCount != -1 && i >= dataRowCount + skipDataRows; - } - public static String[] createHeaders(String[] headers, CsvConfig config) { Object customHeaders = config.customHeader; @@ -157,16 +93,12 @@ public static String[] createHeaders(String[] headers, CsvConfig config) { } } - Object skipColumns = config.skipColumns; - if (skipColumns == null) { - return headers; - } - return QueryParser.parse(config.skipColumns, headers); + return headers; } public static Object convertToBasicType(Object csv, Type targetType, CsvConfig config) { if (csv == null) { - csv = config.nullValue; + csv = config.nilValue; } try { return ValueUtils.convert(csv, targetType); @@ -256,6 +188,45 @@ public static int getTheActualExpectedType(Type type) { } } + public static long[] getSkipLinesFromStringConfigValue(String configValue) { + String[] parts = configValue.split(SKIP_LINE_RANGE_SEP); + if (parts.length != 2) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_RANGE_FOR_SKIPLINES); + } + try { + int start = Integer.parseInt(parts[0]); + int end = Integer.parseInt(parts[1]); + int size = end - start + 1; + if (size <= 0) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_RANGE_FOR_SKIPLINES); + } + long[] result = new long[size]; + for (int i = 0; i < size; i++) { + result[i] = start + i; + } + return result; + } catch (NumberFormatException e) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_VALUE_FOR_SKIPLINES); + } + } + + public static long[] getSkipDataRows(Object skipLines) { + long[] skipDataRows; + if (skipLines instanceof BArray) { + BArray skipLinesArray = (BArray) skipLines; + if (skipLinesArray.getLength() == 0) { + return new long[]{-1}; + } + skipDataRows = (skipLinesArray).getIntArray(); + Arrays.sort(skipDataRows); + return skipDataRows; + } + + skipDataRows = getSkipLinesFromStringConfigValue(StringUtils.getStringValue(skipLines)); + Arrays.sort(skipDataRows); + return skipDataRows; + } + public static class SortConfigurations { protected Object columnName; protected Object sortOrder; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index a816cbb..d0d2032 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -40,7 +40,10 @@ public enum DiagnosticErrorCode { INVALID_TYPE_FOR_ARRAY("BDE_0013", "invalid.type.for.array"), INVALID_CONVERSION_FOR_ARRAY_TO_MAP("BDE_0014", "invalid.conversion.for.array.to.map"), INVALID_CONFIGURATIONS( "BDE_0015", "invalid.configurations"), - EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES("BDE_0016", "expected.type.can.only.contains.basic.types"); + EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES("BDE_0016", "expected.type.can.only.contains.basic.types"), + 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"),; String diagnosticId; String messageKey; diff --git a/native/src/main/java/module-info.java b/native/src/main/java/module-info.java index 5cd8bce..9e77635 100644 --- a/native/src/main/java/module-info.java +++ b/native/src/main/java/module-info.java @@ -22,4 +22,5 @@ requires junit; requires org.apache.commons.lang3; exports io.ballerina.stdlib.data.csvdata.csv; + exports io.ballerina.stdlib.data.csvdata.utils; } diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index 50d77f3..a5edfae 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -67,4 +67,11 @@ error.invalid.conversion.for.array.to.map=\ expected headers are not matching with the ''{0}'' error.invalid.configurations=\ - invalid configurations: ''{0}'' \ No newline at end of file + invalid configurations: ''{0}'' + +error.invalid.format.for.skiplines=\ + "Invalid format for the skipLines field. Expected format: 'start-end'" +error.invalid.range.for.skiplines=\ + Invalid range for the skipLines field. Start value must be less than or equal to end value." +error.invalid.value.for.skiplines=\ + "Invalid input for the skipLines field. Both start and end values must be integers." From 7bc30a5e503e3a82c3e6f5b9d67dc61d4aa15d8b Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 14 May 2024 13:48:15 +0530 Subject: [PATCH 025/147] Add user config tests --- .../tests/parse_record_type_as_list_test.bal | 2 +- ballerina/tests/test_data_values.bal | 4 +- .../user_config_with_parser_options_test.bal | 41 +++++++++++++ ballerina/tests/user_configs.bal | 20 +++++++ ballerina/types.bal | 1 + .../stdlib/data/csvdata/FromString.java | 14 ++--- .../stdlib/data/csvdata/csv/CsvParser.java | 57 ++++++++++--------- .../stdlib/data/csvdata/utils/CsvConfig.java | 4 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 16 ++++++ 9 files changed, 119 insertions(+), 40 deletions(-) create mode 100644 ballerina/tests/user_config_with_parser_options_test.bal create mode 100644 ballerina/tests/user_configs.bal diff --git a/ballerina/tests/parse_record_type_as_list_test.bal b/ballerina/tests/parse_record_type_as_list_test.bal index 2a4e694..8a75d6c 100644 --- a/ballerina/tests/parse_record_type_as_list_test.bal +++ b/ballerina/tests/parse_record_type_as_list_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -boolean enable = true; +// boolean enable = true; // @test:Config {enable: !enable} // function debugTest() { diff --git a/ballerina/tests/test_data_values.bal b/ballerina/tests/test_data_values.bal index 769dabe..ed86306 100644 --- a/ballerina/tests/test_data_values.bal +++ b/ballerina/tests/test_data_values.bal @@ -245,7 +245,7 @@ string csvStringData8 = string ` 1@ stri,ng@ true@ 2.234@ -3.21@ () - 1@ string@ true@ 2.234@ -3.21@ () + 1@ string@ true@ 2.234@ ()@-3.21 1@ string@ true@ 2.234@ -3.21@ null 1@ s,tring@ true@ 2.234@ -3.21@ () @@ -257,6 +257,6 @@ string csvStringData9 = string ` 1@ string@ true@ 2.234@ -3.21@ null 1@ string@ true@ 2.234@ -3.21@ () - 1@ string@ true@ 2.234@ -3.21@ () + 1@ string@ true@ 2.234@ ()@-3.21 1@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal new file mode 100644 index 0000000..5ec1c99 --- /dev/null +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -0,0 +1,41 @@ +import ballerina/test; + +boolean enable = !true; + +@test:Config {enable: !enable} +function debugTest() { + string value = string ` + i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 + ${i1},${i2},${s1},${s2},${b1},${b2},(),(),${f1}, ${f2},${d1},${d2},${b1},${d1},${b2},${d2} + ${i1},${i2},${s1},${s2},${b1},${b2},(),(), ${f1},${f2},${d1},${d2},${b1},${d1},${b2},${d2} + `; + // string value2 = string ` + // i1, s1, b1, n1, f1, d1, j1, a1, s2, s3, j2, a2 + // ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3},${b2}, ${d2} + // `; + // string value3 = string ` + // i1, s1, b1, n1, f1, d1, j1, a1, s2, s3 + // ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3} + // `; + + [int, string, boolean, decimal, float, string][]|CsvConversionError cv1baa = parseStringToList(csvStringData1, option3); + test:assertEquals(cv1baa, [ + [1, "string1", true ,2.234, 2.234, "()"], + [1, "string2", false, 0, 0.0, "null"], + [1, "string3", false, 1.23, 1.23, "()"], + [1, "string4", true, -6.51, -6.51, "()"], + [1, "string5", true, 3, 3.0, "()"] + ]); +} + +@test:Config {enable} +function testFromCsvStringWithParserOptions() { + [int, string, boolean, decimal, float, string][]|CsvConversionError cv1baa = parseStringToList(csvStringData1, option3); + test:assertEquals(cv1baa, [ + [1, "string1", true ,2.234, 2.234, "()"], + [1, "string2", false, 0, 0.0, "null"], + [1, "string3", false, 1.23, 1.23, "()"], + [1, "string4", true, -6.51, -6.51, "()"], + [1, "string5", true, 3, 3.0, "()"] + ]); +} diff --git a/ballerina/tests/user_configs.bal b/ballerina/tests/user_configs.bal new file mode 100644 index 0000000..8cb40fc --- /dev/null +++ b/ballerina/tests/user_configs.bal @@ -0,0 +1,20 @@ +// Valid parser options +ParseOption option1 = {delimiter: "@", nilValue: "null", lineTerminator: [LF]}; +ParseOption option2 = {nilValue: "N/A", lineTerminator: [CR, LF], comment: "//"}; +ParseOption option3 = {nilValue: "()", header: 0, skipLines: [1, 2]}; +ParseOption option4 = {nilValue: "", header: 4, skipLines: "1-5"}; +ParseOption option5 = {nilValue: "", header: 4, skipLines: "1-1"}; + +// Invalid parser options +ParseOption invalidParserOptions1 = {header: 4}; +ParseOption invalidParserOptions2 = {comment: ""}; +ParseOption invalidParserOptions3 = {lineTerminator: CR}; +ParseOption invalidParserOptions4 = {skipLines: [1000, 1001]}; +ParseOption invalidParserOptions5 = {skipLines: "a-b"}; +ParseOption invalidParserOptions6 = {skipLines: "3-1"}; +ParseOption invalidParserOptions7 = {skipLines: "a-5"}; +ParseOption invalidParserOptions8 = {skipLines: "6-a"}; +ParseOption invalidParserOptions9 = {skipLines: "a-5"}; +ParseOption invalidParserOptions10 = {skipLines: "-1-6"}; +ParseOption invalidParserOptions11 = {nilValue: "", header: 4, skipLines: "0-10"}; +ParseOption invalidParserOptions12 = {skipLines: [1, 3, 4, -1]}; diff --git a/ballerina/types.bal b/ballerina/types.bal index e7521c7..5198110 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -15,6 +15,7 @@ public type ParseOption record {| string delimiter = ","; string encoding = "UTF-8"; string locale = "en_US"; +// TODO: Add " for Strings" string textEnclosure = "\""; string escapeChar = "\\"; LineTerminator|LineTerminator[] lineTerminator = [CR, LF, CRLF]; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index 04d7063..2a547d0 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -136,16 +136,14 @@ private static Object stringToBoolean(String value) throws NumberFormatException private static Object stringToNull(String value, CsvConfig config) throws NumberFormatException { Object nullValue = config.nilValue; - if (nullValue != null && StringUtils.getStringValue(nullValue).equalsIgnoreCase(value)) { - return nullValue; - } - if (Constants.Values.NULL.equalsIgnoreCase(value) || Constants.Values.BALLERINA_NULL.equalsIgnoreCase(value)) { - if (nullValue != null) { - return nullValue; - } + if (nullValue == null && (Constants.Values.NULL.equalsIgnoreCase(value) + || Constants.Values.BALLERINA_NULL.equalsIgnoreCase(value))) { return null; } - return returnError(value, Constants.Values.BALLERINA_NULL); + if (nullValue != null && value.equals(StringUtils.getStringValue(nullValue))) { + return nullValue; + } + return returnError(value, nullValue == null ? Constants.Values.BALLERINA_NULL : nullValue.toString()); } private static Object stringToUnion(BString string, UnionType expType, CsvConfig config) throws NumberFormatException { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index fa6053f..0290d96 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -44,7 +44,6 @@ */ public class CsvParser { private static final char CR = 0x000D; - private static final char NEWLINE = 0x000A; private static final char HZ_TAB = 0x0009; private static final char SPACE = 0x0020; private static final char BACKSPACE = 0x0008; @@ -121,8 +120,9 @@ public void reset() { charBuffIndex = 0; } - private static boolean isWhitespace(char ch) { - return ch == SPACE || ch == HZ_TAB || ch == CR || ch == NEWLINE; + private static boolean isWhitespace(char ch, Object lineTerminator) { + return ch == SPACE || ch == HZ_TAB || ch == CR + || isCharContainsInLineTerminatorUserConfig(ch, lineTerminator); } private static void throwExpected(String... chars) throws CsvParserException { @@ -231,7 +231,7 @@ private void append(char ch) { } private boolean isNewLineOrEof(char ch) { - return ch == NEWLINE || ch == EOF; + return ch == EOF || isCharContainsInLineTerminatorUserConfig(ch, config.lineTerminator); } private void growCharBuff() { @@ -264,7 +264,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.lineNumber++; continue; } - if (!(isWhitespace(ch) && sm.isNewLineOrEof(ch))) { + if (!(isWhitespace(ch, sm.config.lineTerminator) && sm.isNewLineOrEof(ch))) { headerStart = true; } if (customHeader != null) { @@ -287,7 +287,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.columnIndex = 0; sm.lineNumber++; state = HEADER_END_STATE; - } else if (StateMachine.isWhitespace(ch)) { + } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { state = this; continue; } else { @@ -373,14 +373,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C ch = buff[i]; sm.processLocation(ch); - if (skipLines[0] <= sm.lineNumber && sm.lineNumber < skipLines[skipLines.length - 1]) { - if (isEndOfTheRow(sm, ch)) { - sm.lineNumber++; - sm.rowIndex++; - } - continue; - } - //TODO: Handle empty values and create again and again if (sm.currentCsvNode == null) { initiateNewRowType(sm); @@ -389,12 +381,12 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C addRowValue(sm); } else if (isEndOfTheRow(sm, ch)) { sm.lineNumber++; - handleCsvRow(sm); + handleCsvRow(sm, skipLines); checkOptionalFieldsAndLogError(sm.fieldHierarchy); if (ch == EOF) { state = ROW_END_STATE; } - } else if (StateMachine.isWhitespace(ch)) { + } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { // ignore } else { sm.append(ch); @@ -404,20 +396,32 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return state; } - private void handleCsvRow(StateMachine sm) throws CsvParserException { - if (ignoreRow(sm.peek())) { - sm.lineNumber++; - sm.rowIndex++; + private void handleCsvRow(StateMachine sm, long[] skipRows) throws CsvParserException { + String value = sm.value(); + if (value.isBlank()) { + updateLineAndColumnIndexes(sm); return; } + addRowValue(sm); + if (ignoreRow(skipRows, sm.rowIndex)) { + updateLineAndColumnIndexes(sm); + return; + } + finalizeTheRow(sm); - sm.columnIndex = 0; + updateLineAndColumnIndexes(sm); + } + + private void updateLineAndColumnIndexes(StateMachine sm) { + sm.lineNumber++; + sm.rowIndex++; sm.currentCsvNode = null; + sm.columnIndex = 0; } - private boolean ignoreRow(String peek) { - return peek.isEmpty(); + private boolean ignoreRow(long[] skipLines, int lineNumber) { + return skipLines[0] <= lineNumber && lineNumber < skipLines[skipLines.length - 1]; } private void initiateNewRowType(StateMachine sm) throws CsvParserException { @@ -428,8 +432,6 @@ private void finalizeTheRow(StateMachine sm) { int rootArraySize = sm.rootArrayType.getSize(); if (rootArraySize == -1 || sm.rowIndex < rootArraySize) { sm.rootCsvNode.add(sm.rowIndex, sm.currentCsvNode); - sm.rowIndex++; - sm.lineNumber++; } } @@ -437,6 +439,7 @@ private void addRowValue(StateMachine sm) throws CsvParserException { // TODO: Can convert all at once by storing in a Object[] Type type; Type exptype = sm.expectedArrayElementType; + String value = sm.value(); if (exptype instanceof RecordType) { type = getExpectedRowTypeOfRecord(sm); @@ -451,7 +454,6 @@ private void addRowValue(StateMachine sm) throws CsvParserException { } if (type != null) { - String value = sm.value(); CsvCreator.convertAndUpdateCurrentJsonNode(sm, StringUtils.fromString(value), type, sm.config, exptype); } @@ -613,7 +615,8 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C state = this.getSourceState(); break; case 'n': - sm.append(NEWLINE); + // TODO: Update this + sm.append('\n'); state = this.getSourceState(); break; case 'r': diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java index fe0725e..dd3d264 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java @@ -49,7 +49,7 @@ private CsvConfig(char delimiter, char textEnclosure, Object header, this.header = header; this.escapeChar = escapeChar; this.lineTerminator = lineTerminator; - this.nilValue = nilValue == null ? null : StringUtils.getStringValue(nilValue); + this.nilValue = nilValue == null ? null : nilValue; this.comment = comment; this.locale = locale; this.encoding = encoding; @@ -68,7 +68,7 @@ private CsvConfig(char delimiter, char textEnclosure, Object header, char escape this.header = header; this.escapeChar = escapeChar; this.lineTerminator = lineTerminator; - this.nilValue = nilValue == null ? null : StringUtils.getStringValue(nilValue); + this.nilValue = nilValue == null ? null : nilValue; this.comment = comment; this.locale = locale; this.encoding = encoding; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 3396030..788a58c 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -227,6 +227,22 @@ public static long[] getSkipDataRows(Object skipLines) { return skipDataRows; } + public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object lineTerminatorObj) { + String stringValue = Character.toString(c); + if (lineTerminatorObj instanceof BArray) { + Object[] lineTerminators = ((BArray) lineTerminatorObj).getValues(); + for (Object lineTerminator: lineTerminators) { + if (lineTerminator != null && lineTerminator.toString().equals(stringValue)) { + return true; + } + } + return false; + } + + String lineTerminator = StringUtils.getStringValue(lineTerminatorObj); + return lineTerminator.equals(stringValue); + } + public static class SortConfigurations { protected Object columnName; protected Object sortOrder; From 9b8c7f7f95e6d95fa1faf8dc9c26e4476cf5d39f Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 6 Jun 2024 08:36:45 +0530 Subject: [PATCH 026/147] Add tests for comments and null configs --- ballerina/Dependencies.toml | 29 +- ballerina/tests/error_test.bal | 24 + .../tests/parse_string_compatibality_test.bal | 16 +- ballerina/tests/test_data_values.bal | 100 ++-- .../user_config_with_parser_options_test.bal | 490 ++++++++++++++++-- ballerina/tests/user_configs.bal | 13 +- ballerina/types.bal | 8 +- .../stdlib/data/csvdata/FromString.java | 4 +- .../stdlib/data/csvdata/csv/CsvCreator.java | 1 + .../stdlib/data/csvdata/csv/CsvParser.java | 160 ++++-- .../stdlib/data/csvdata/utils/CsvUtils.java | 2 - 11 files changed, 699 insertions(+), 148 deletions(-) create mode 100644 ballerina/tests/error_test.bal diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index f95f329..c995088 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.6" +distribution-version = "2201.9.0" [[package]] org = "ballerina" @@ -27,6 +27,26 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + [[package]] org = "ballerina" name = "lang.error" @@ -36,6 +56,12 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + [[package]] org = "ballerina" name = "test" @@ -43,6 +69,7 @@ version = "0.0.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, {org = "ballerina", name = "lang.error"} ] modules = [ diff --git a/ballerina/tests/error_test.bal b/ballerina/tests/error_test.bal new file mode 100644 index 0000000..ba8650e --- /dev/null +++ b/ballerina/tests/error_test.bal @@ -0,0 +1,24 @@ +import ballerina/test; + +// boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() returns error? { +// record{}[]|CsvConversionError csv1op4_3 = parseStringToRecord(csvStringData2, ptOption4); +// test:assertEquals(csv1op4_3, [ +// {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, +// {a: 3, b: "string3", c: 0, d: 1.23, e: 1.23, f: "()"}, +// {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} +// ]); +// } + +function errorTest() returns error? { + // check + + record{}[]|CsvConversionError csv3op3_4 = parseStringToRecord(csvStringData3, {header: 11}); + test:assertEquals(csv3op3_4, []); + + csv3op3_4 = parseStringToRecord(csvStringData3, {header: 3}); + test:assertEquals(csv3op3_4, []); + +} diff --git a/ballerina/tests/parse_string_compatibality_test.bal b/ballerina/tests/parse_string_compatibality_test.bal index a8c4811..a0eb6de 100644 --- a/ballerina/tests/parse_string_compatibality_test.bal +++ b/ballerina/tests/parse_string_compatibality_test.bal @@ -13,17 +13,14 @@ import ballerina/test; @test:Config {enable} function testFromCsvStringWithTypeCompatibility() { - string value = string ` - i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 + string value = string `i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 ${i1},${i2},${s1},${s2},${b1},${b2},(),(),${f1}, ${f2},${d1},${d2},${b1},${d1},${b2},${d2} ${i1},${i2},${s1},${s2},${b1},${b2},(),(), ${f1},${f2},${d1},${d2},${b1},${d1},${b2},${d2} `; - string value2 = string ` - i1, s1, b1, n1, f1, d1, j1, a1, s2, s3, j2, a2 + string value2 = string `i1, s1, b1, n1, f1, d1, j1, a1, s2, s3, j2, a2 ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3},${b2}, ${d2} `; - string value3 = string ` - i1, s1, b1, n1, f1, d1, j1, a1, s2, s3 + string value3 = string `i1, s1, b1, n1, f1, d1, j1, a1, s2, s3 ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3} `; @@ -120,7 +117,7 @@ function testFromCsvStringWithTypeCompatibility() { a, b, c 1, a, 2.3 1, -2, true - hello, -2, hello`); + hello, -2, hello`, {header: 1}); test:assertEquals(irrma, [ {a: 1}, {a: i1, b: i2}, @@ -131,7 +128,7 @@ function testFromCsvStringWithTypeCompatibility() { a, b, c 1, a, () 1, null, () - hello, -2, hello`); + hello, -2, hello`, {header: 1}); test:assertEquals(nrrma, [ {c: ()}, {b: (), c: ()}, @@ -149,8 +146,7 @@ function testFromCsvStringWithTypeCompatibility() { {b: -3.21d, c: f3} ]); - record {|string...;|}[]|CsvConversionError srra = parseStringToRecord(string ` - a, b, c + record {|string...;|}[]|CsvConversionError srra = parseStringToRecord(string `a, b, c 1, a, 2.3 1, -2, true hello, -2, hello`); diff --git a/ballerina/tests/test_data_values.bal b/ballerina/tests/test_data_values.bal index ed86306..c46ac88 100644 --- a/ballerina/tests/test_data_values.bal +++ b/ballerina/tests/test_data_values.bal @@ -121,20 +121,17 @@ var booleanRecordArray2 = [ {},{} ]; -string csvStringWithBooleanValues1 = string ` -b1,b2,b3,b4 +string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 true,false,true,false true,false, true,false true,false,true,false `; -string csvStringWithBooleanValues2 = string ` -b1,b2,b3,b4,b5 +string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 true,false, true,false,true true,false, true,false,true`; -string csvStringWithBooleanValues3 = string ` - b1,b2,b3 +string csvStringWithBooleanValues3 = string `b1,b2,b3 ${" "}${"\t"} true, false,true ${" "} @@ -145,51 +142,48 @@ true, true,FALSE `; -string csvStringWithBooleanValues4 = string ` - b1,b2,b3,b4 +string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 true,(), (),0 1,(), null,false `; -string csvStringWithBooleanValues5 = string ` -b1,b2,b3,b4 +string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 true,false,true,2 true,false,true,3 `; -string csvStringWithBooleanValues6 = string ` -b2,b3 +string csvStringWithBooleanValues6 = string `b2,b3 (),() `; -string csvStringWithBooleanValues7 = string ` -b1,b2,b3,b4 +string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 ${b1},${b2},(),${b4} `; string csvStringData1 = string ` a, b, c, d, e, f 1, string1, true, 2.234, 2.234, () - 1, string2, false, 0, 0, null - 1, string3, 0, 1.23, 1.23, () - 1, string4, 1, -6.51, -6.51, () - 1, string5, true, 3, 3, ()`; + 2, string2, false, 0, 0, null + 3, string3, 0, 1.23, 1.23, () + 4, string4, 1, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; string csvStringData2 = string ` - - + hello, hello, (), 12, true, 12.34 + // comment + a, b, c, d, e, f - + 1, string1, true, 2.234, 2.234, () - 1, string2, false, 0, 0, null - 1, string3, 0, 1.23, 1.23, () - 1, string4, 1, -6.51, -6.51, () - 1, string5, true, 3, 3, ()`; + 2, string2, false, 0, 0, null + 3, string3, 0, 1.23, 1.23, () + 4, string4, 1, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; string csvStringData3 = string ` a, b, c, d, e, f @@ -197,66 +191,66 @@ string csvStringData3 = string ` 1, string1, true, 2.234, 2.234, () - 1, string2, false, 0, 0, null - 1, string3, 0, 1.23, 1.23, () + 2, string2, false, 0, 0, null + 3, string3, 0, 1.23, 1.23, () - 1, string4, 1, -6.51, -6.51, () - 1, string5, true, 3, 3, ()`; + 4, string4, 1, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; string csvStringData4 = string ` 1, string1, true, 2.234, 2.234, () - 1, string2, false, 0, 0, null - 1, string3, 0, 1.23, 1.23, () - 1, string4, 1, -6.51, -6.51, () - 1, string5, true, 3, 3, ()`; + 2, string2, false, 0, 0, null + 3, string3, 0, 1.23, 1.23, () + 4, string4, 1, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; string csvStringData5 = string ` 1, string1, true, 2.234, 2.234, () - 1, string2, false, 0, 0, null + 2, string2, false, 0, 0, null - 1, string3, 0, 1.23, 1.23, () - 1, string4, 1, -6.51, -6.51, () + 3, string3, 0, 1.23, 1.23, () + 4, string4, 1, -6.51, -6.51, () - 1, string5, true, 3, 3, ()`; + 5, string5, true, 3, 3, ()`; string csvStringData6 = string ` 1, string1, true, 2.234, 2.234, () - 1, string2, false, 0, 0, null + 2, string2, false, 0, 0, null - 1, string3, 0, 1.23, 1.23, () - 1, string4, 1, -6.51, -6.51, () + 3, string3, 0, 1.23, 1.23, () + 4, string4, 1, -6.51, -6.51, () - 1, string5, true, 3, 3, ()`; + 5, string5, true, 3, 3, ()`; string csvStringData7 = string ` a@ b@ c@ d@ e@ f 1@ string@ true@ 2.234@ -3.21@ () - 1@ s,tring@ true@ 2.234@ -3.21@ null - 1@ stri,ng@ true@ 2.234@ -3.21@ () - 1@ string@ true@ 2.234@ -3.21@ () - 1@ string@ true@ 2.234@ -3.21@ ()`; + 2@ s,tring@ true@ 2.234@ -3.21@ null + 3@ stri,ng@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; string csvStringData8 = string ` a@ b@ c@ d@ e@ f 1@ stri,ng@ true@ 2.234@ -3.21@ () - 1@ string@ true@ 2.234@ ()@-3.21 - 1@ string@ true@ 2.234@ -3.21@ null + 2@ string@ true@ 2.234@ ()@-3.21 + 3@ string@ true@ 2.234@ -3.21@ null - 1@ s,tring@ true@ 2.234@ -3.21@ () - 1@ string@ true@ 2.234@ -3.21@ ()`; + 4@ s,tring@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; string csvStringData9 = string ` 1@ string@ true@ 2.234@ -3.21@ () - 1@ string@ true@ 2.234@ -3.21@ null + 2@ string@ true@ 2.234@ -3.21@ null - 1@ string@ true@ 2.234@ -3.21@ () - 1@ string@ true@ 2.234@ ()@-3.21 + 3@ string@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ ()@-3.21 - 1@ string@ true@ 2.234@ -3.21@ null`; + 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index 5ec1c99..35147b2 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -1,41 +1,469 @@ import ballerina/test; -boolean enable = !true; +boolean enable = true; @test:Config {enable: !enable} -function debugTest() { - string value = string ` - i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 - ${i1},${i2},${s1},${s2},${b1},${b2},(),(),${f1}, ${f2},${d1},${d2},${b1},${d1},${b2},${d2} - ${i1},${i2},${s1},${s2},${b1},${b2},(),(), ${f1},${f2},${d1},${d2},${b1},${d1},${b2},${d2} - `; - // string value2 = string ` - // i1, s1, b1, n1, f1, d1, j1, a1, s2, s3, j2, a2 - // ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3},${b2}, ${d2} - // `; - // string value3 = string ` - // i1, s1, b1, n1, f1, d1, j1, a1, s2, s3 - // ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3} - // `; - - [int, string, boolean, decimal, float, string][]|CsvConversionError cv1baa = parseStringToList(csvStringData1, option3); - test:assertEquals(cv1baa, [ - [1, "string1", true ,2.234, 2.234, "()"], - [1, "string2", false, 0, 0.0, "null"], - [1, "string3", false, 1.23, 1.23, "()"], - [1, "string4", true, -6.51, -6.51, "()"], - [1, "string5", true, 3, 3.0, "()"] - ]); +function debugTest() returns error? { + record{}[]|CsvConversionError csv2cop3 = parseStringToRecord(csvStringData1, {header: 0, skipLines: "2-5"}); + test:assertEquals(csv2cop3, [{a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}]); } @test:Config {enable} function testFromCsvStringWithParserOptions() { - [int, string, boolean, decimal, float, string][]|CsvConversionError cv1baa = parseStringToList(csvStringData1, option3); - test:assertEquals(cv1baa, [ - [1, "string1", true ,2.234, 2.234, "()"], - [1, "string2", false, 0, 0.0, "null"], - [1, "string3", false, 1.23, 1.23, "()"], - [1, "string4", true, -6.51, -6.51, "()"], - [1, "string5", true, 3, 3.0, "()"] + [int, string, boolean, decimal, float, string][]|CsvConversionError csv1op3 = parseStringToList(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, "()"] + ]); + + record{int a; string b; boolean c;decimal d; float e; string f;}[]|CsvConversionError csv1op3_2 = parseStringToRecord(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: "()"} + ]); + + record{int a; string b; boolean c;decimal d; float e; string f;}[]|CsvConversionError csv1op3_3 = parseStringToRecord(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: "()"} + ]); + + [int, string, boolean, decimal, float, string][]|CsvConversionError csv2op4 = parseStringToList(csvStringData2, option4); + test:assertEquals(csv2op4, []); + + record{}[]|CsvConversionError csv2op4_2 = parseStringToRecord(csvStringData2, ptOption3); + test:assertEquals(csv2op4_2, []); + + record{}[]|CsvConversionError csv2op4_3 = parseStringToRecord(csvStringData2, ptOption4); + test:assertEquals(csv2op4_3, [ + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, + {a: 3, b: "string3", c: 0, d: 1.23, e: 1.23, f: "()"}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} + ]); + + [int, string, boolean, decimal, float, string][]|CsvConversionError csv3op3 = parseStringToList(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, "()"] + ]); + + record{}[]|CsvConversionError csv3op3_2 = parseStringToRecord(csvStringData3, ptOption1); + test:assertEquals(csv3op3_2, [ + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, + {a: 3, b: "string3", c: 0, d: 1.23, e: 1.23, f: "()"}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} + ]); + + record{}[]|CsvConversionError csv3op3_3 = parseStringToRecord(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: "()"} + ]); + + record{}[]|CsvConversionError csv3op3_4 = parseStringToRecord(csvStringData3, {header: 9, skipLines: "2-10"}); + test:assertEquals(csv3op3_4, [ + {'4: 5, string4: "string5", '1: true, "-6.51": 3, "()": null} + ]); +} + +@test:Config {enable} +function testFromCsvStringWithHeaderLessParserOptions() { + [int, string, boolean, decimal, float, ()][]|CsvConversionError csv1op6 = parseStringToList(csvStringData1, option6); + test:assertTrue(csv1op6 is CsvConversionError); + test:assertEquals(( csv1op6).message(), generateErrorMessageForInvalidCast("null", "()")); + + record{}[]|CsvConversionError csv1op5_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + record{}[]|CsvConversionError csv1op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + record{}[]|CsvConversionError csv3op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + record{}[]|CsvConversionError csv4op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + record{}[]|CsvConversionError csv5op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + record{}[]|CsvConversionError csv6op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); + + record{}[]|CsvConversionError csv2op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, + {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} + ]); +} + +@test:Config {enable} +function testHeaderOption() { + record{}[]|CsvConversionError csv2cop1 = parseStringToRecord(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: 0, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: 1, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} + ]); + + record{}[]|CsvConversionError csv2cop2 = parseStringToRecord(csvStringData2, {header: 100}); + test:assertEquals(csv2cop2, []); + + record{}[]|CsvConversionError csv2cop3 = parseStringToRecord(csvStringData2, {header: 11}); + test:assertEquals(csv2cop3, []); + + record{}[]|CsvConversionError csv2cop4 = parseStringToRecord(csvStringData2, {header: 10}); + test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", '1: true, "-6.51": 3, "()": ()}]); +} + +@test:Config {enable} +function testCustomHeaderOption() { + +} + +@test:Config {enable} +function testNullConfigOption() { + string csvValue1 = string `a + ()`; + string csvValue2 = string `a + null`; + string csvValue3 = string `c, a + true, e`; + string csvValue4 = string `a + Null`; + string csvValue5 = string `b, a + bN/Aa,N/A`; + + record{() a;}[]|CsvConversionError cn = parseStringToRecord(csvValue1, {nilValue: ()}); + test:assertEquals(cn, [{a: ()}]); + + cn = parseStringToRecord(csvValue2, {nilValue: ()}); + test:assertEquals(cn, [{a: ()}]); + + cn = parseStringToRecord(csvValue3, {nilValue: ()}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("e", "()")); + + cn = parseStringToRecord(csvValue4, {nilValue: ()}); + test:assertEquals(cn, [{a: ()}]); + + cn = parseStringToRecord(csvValue1, {nilValue: null}); + test:assertEquals(cn, [{a: ()}]); + + cn = parseStringToRecord(csvValue2, {nilValue: null}); + test:assertEquals(cn, [{a: ()}]); + + cn = parseStringToRecord(csvValue3, {nilValue: null}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("e", "()")); + + cn = parseStringToRecord(csvValue4, {nilValue: null}); + test:assertEquals(cn, [{a: ()}]); + + cn = parseStringToRecord(csvValue1, {nilValue: "()"}); + test:assertEquals(cn, [{a: ()}]); + + cn = parseStringToRecord(csvValue2, {nilValue: "()"}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("null", "()")); + + cn = parseStringToRecord(csvValue3, {nilValue: "()"}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("e", "()")); + + cn = parseStringToRecord(csvValue4, {nilValue: "()"}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("Null", "()")); + + cn = parseStringToRecord(csvValue5, {nilValue: "N/A"}); + test:assertEquals(cn, [{b: "bN/Aa", a: ()}]); + + cn = parseStringToRecord(csvValue2, {nilValue: "null"}); + test:assertEquals(cn, [{a: ()}]); + + cn = parseStringToRecord(csvValue4, {nilValue: "null"}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("Null", "()")); + + cn = parseStringToRecord(csvValue1, {nilValue: "null"}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("()", "()")); +} + +@test:Config {enable} +function testCommentConfigOption() { + string csvValue1 = string `a + 1`; + string csvValue2 = string `a # comment + 1`; + string csvValue3 = string `a #, c + 1#, e`; + string csvValue4 = string `a + # comment + 1`; + string csvValue5 = string `a, b + 1,2 + # comment`; + string csvValue6 = string `a, b + 1,2 # comment + # comment`; + string csvValue7 = string `a, b + 1#,2 comment + # comment`; + string csvValue8 = string `a#, b + 1, 2 # comment + # comment`; + string csvValue9 = string `a,# b + 1 ,#2 # comment + # comment`; + + record{int a;}[]|CsvConversionError cn; + + cn = parseStringToRecord(csvValue1); + test:assertEquals(cn, [{a: 1}]); + + cn = parseStringToRecord(csvValue2); + test:assertEquals(cn, [{a: 1}]); + + cn = parseStringToRecord(csvValue3); + test:assertEquals(cn, [{a: 1}]); + + cn = parseStringToRecord(csvValue4); + test:assertEquals(cn, [{a: 1}]); + + cn = parseStringToRecord(csvValue5); + test:assertEquals(cn, [{a: 1, b: 2}]); + + cn = parseStringToRecord(csvValue6); + test:assertEquals(cn, [{a: 1, b: 2}]); + + cn = parseStringToRecord(csvValue7); + test:assertEquals(cn, [{a: 1}]); + + record {|int a; int b;|}[]|CsvConversionError cn2 = parseStringToRecord(csvValue7, {header: 0}); + test:assertEquals(cn2, [{a: 1, b: 0}]); + + cn = parseStringToRecord(csvValue8); + test:assertTrue(cn is CsvConversionError); + // TODO:Fix + // test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("1, 2", "int")); + + cn = parseStringToRecord(csvValue9); + test:assertEquals(cn, [{a: 1}]); +} + +@test:Config {enable} +function testCommentConfigOption2() { + string csvValue1 = string `a + 1`; + string csvValue2 = string `a & comment + 1`; + string csvValue3 = string `a &, c + 1&, e`; + string csvValue4 = string `a + + + + & comment + 1`; + string csvValue5 = string `a&, b + 1, 2 & comment + + + & comment`; + string csvValue6 = string ` + + a,& b + 1 ,&2 & comment + + & comment`; + + record{int a; int b;}[]|CsvConversionError cn; + record{int c;}[]|CsvConversionError cn2; + + cn = parseStringToRecord(csvValue1, {comment: "&"}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + + cn = parseStringToRecord(csvValue2, {comment: "&"}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + + cn = parseStringToRecord(csvValue3, {comment: "&"}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + + cn = parseStringToRecord(csvValue4, {comment: "&"}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + + cn = parseStringToRecord(csvValue5, {comment: "&"}); + test:assertTrue(cn is CsvConversionError); + // TODO: Fix + // test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + + cn = parseStringToRecord(csvValue6, {comment: "&", header: 2}); + test:assertTrue(cn is CsvConversionError); + test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + + cn2 = parseStringToRecord(csvValue1, {comment: "&"}); + test:assertTrue(cn2 is CsvConversionError); + test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + + cn2 = parseStringToRecord(csvValue2, {comment: "&"}); + test:assertTrue(cn2 is CsvConversionError); + test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + + cn2 = parseStringToRecord(csvValue3, {comment: "&"}); + test:assertTrue(cn2 is CsvConversionError); + test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + + cn2 = parseStringToRecord(csvValue4, {comment: "&"}); + test:assertTrue(cn2 is CsvConversionError); + test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + + cn2 = parseStringToRecord(csvValue5, {comment: "&"}); + test:assertTrue(cn2 is CsvConversionError); + // TODO: Fix + // test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + + cn2 = parseStringToRecord(csvValue6, {header: 2, comment: "&"}); + test:assertTrue(cn2 is CsvConversionError); + test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); +} + +@test:Config {enable} +function testSkipLineParserOption() { + [int, string, boolean, decimal, float, ()][]|CsvConversionError csv1cp = parseStringToList(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 = parseStringToList(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 = parseStringToList(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, ()] + ]); + + csv1cp = parseStringToList(csvStringData1, {skipLines: [1, 2, 3, 4, 5], header: 1}); + test:assertEquals(csv1cp, [ + ]); + + csv1cp = parseStringToList(csvStringData1, {skipLines: "1-5", header: 1}); + test:assertEquals(csv1cp, [ + ]); + + csv1cp = parseStringToList(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, ()] + ]); + + csv1cp = parseStringToList(csvStringData1, {skipLines: "2-4", header: 1}); + test:assertEquals(csv1cp, [ + [1, "string1", true, 2.234, 2.234, ()], + [5, "string5", true, 3, 3.0, ()] + ]); + + csv1cp = parseStringToList(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, ()] + ]); + + csv1cp = parseStringToList(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, ()] + ]); + + csv1cp = parseStringToList(csvStringData1, {skipLines: [5, 4, 3, 2, 1], header: 1}); + test:assertEquals(csv1cp, [ + ]); + + csv1cp = parseStringToList(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 = parseStringToList(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 = parseStringToList(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, ()] + ]); + + csv1cp = parseStringToList(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, ()] ]); } diff --git a/ballerina/tests/user_configs.bal b/ballerina/tests/user_configs.bal index 8cb40fc..02f933b 100644 --- a/ballerina/tests/user_configs.bal +++ b/ballerina/tests/user_configs.bal @@ -1,13 +1,20 @@ // Valid parser options ParseOption option1 = {delimiter: "@", nilValue: "null", lineTerminator: [LF]}; -ParseOption option2 = {nilValue: "N/A", lineTerminator: [CR, LF], comment: "//"}; -ParseOption option3 = {nilValue: "()", header: 0, skipLines: [1, 2]}; +ParseOption option2 = {nilValue: "N/A", lineTerminator: [CR, LF], comment: "/"}; +ParseOption option3 = {nilValue: "()", header: 1, skipLines: [1, 2]}; ParseOption option4 = {nilValue: "", header: 4, skipLines: "1-5"}; ParseOption option5 = {nilValue: "", header: 4, skipLines: "1-1"}; +ParseOption option6 = {nilValue: "()", header: false, skipLines: [1, 2]}; + +parseToRecordOption ptOption1 = {nilValue: "", header: 1, skipLines: [2, 4]}; +parseToRecordOption ptOption2 = {nilValue: "", header: 1, skipLines: "2-4"}; +parseToRecordOption ptOption3 = {nilValue: "", header: 4, skipLines: "1-5"}; +parseToRecordOption ptOption4 = {nilValue: "", header: 4, skipLines: [-1, -2, 4, 2]}; +parseToRecordOption ptOption5 = {header: false, skipLines: [-1, -2, 5, 3]}; // Invalid parser options ParseOption invalidParserOptions1 = {header: 4}; -ParseOption invalidParserOptions2 = {comment: ""}; +ParseOption invalidParserOptions2 = {comment: "$"}; ParseOption invalidParserOptions3 = {lineTerminator: CR}; ParseOption invalidParserOptions4 = {skipLines: [1000, 1001]}; ParseOption invalidParserOptions5 = {skipLines: "a-b"}; diff --git a/ballerina/types.bal b/ballerina/types.bal index 5198110..fc2684b 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -12,15 +12,15 @@ public type Options record { public type ParseOption record {| *Options; - string delimiter = ","; + string:Char delimiter = ","; string encoding = "UTF-8"; string locale = "en_US"; // TODO: Add " for Strings" - string textEnclosure = "\""; - string escapeChar = "\\"; + string:Char textEnclosure = "\""; + string:Char escapeChar = "\\"; LineTerminator|LineTerminator[] lineTerminator = [CR, LF, CRLF]; NilValue? nilValue = (); - string comment = "#"; + string:Char comment = "#"; false|int:Unsigned32 header = 0; |}; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index 2a547d0..850eedc 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -136,12 +136,12 @@ private static Object stringToBoolean(String value) throws NumberFormatException private static Object stringToNull(String value, CsvConfig config) throws NumberFormatException { Object nullValue = config.nilValue; - if (nullValue == null && (Constants.Values.NULL.equalsIgnoreCase(value) + if ((nullValue == null) && (Constants.Values.NULL.equalsIgnoreCase(value) || Constants.Values.BALLERINA_NULL.equalsIgnoreCase(value))) { return null; } if (nullValue != null && value.equals(StringUtils.getStringValue(nullValue))) { - return nullValue; + return null; } return returnError(value, nullValue == null ? Constants.Values.BALLERINA_NULL : nullValue.toString()); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index e7a9b07..c7a558e 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -64,6 +64,7 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, BString value, Type type, CsvConfig config, Type exptype) { Object currentCsv = sm.currentCsvNode; Object convertedValue = convertToExpectedType(value, type, config); + sm.isCurrentCsvNodeEmpty = false; if (convertedValue instanceof BError) { if (ignoreIncompatibilityErrorsForMaps(sm, type, exptype)) { return null; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 0290d96..a6c5ed9 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -26,6 +26,8 @@ import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; @@ -91,10 +93,14 @@ static class StateMachine { Type restType; Type expectedArrayElementType; int columnIndex = 0; - int rowIndex = 0; + int rowIndex = 1; int lineNumber = 0; ArrayType rootArrayType = null; CsvConfig config = null; + boolean skipTheRow = false; + boolean insideComment = false; + boolean isCurrentCsvNodeEmpty = true; + boolean isHeaderConfigExceedLineNumber = false; StateMachine() { reset(); } @@ -107,7 +113,7 @@ public void reset() { restType = null; rootCsvNode = null; columnIndex = 0; - rowIndex = 0; + rowIndex = 1; fieldHierarchy.clear(); fieldNames.clear(); rootArrayType = null; @@ -118,6 +124,9 @@ public void reset() { currentEscapeCharacters = new Stack<>(); charBuff = new char[1024]; charBuffIndex = 0; + skipTheRow = false; + isCurrentCsvNodeEmpty = true; + isHeaderConfigExceedLineNumber = false; } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -202,9 +211,10 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError } currentState = currentState.transition(this, new char[] { EOF }, 0, 1); if (currentState != ROW_END_STATE && currentState != HEADER_END_STATE) { - throw new CsvParserException("Invalid token found"); + if (!this.isHeaderConfigExceedLineNumber) { + throw new CsvParserException("Invalid token found"); + } } - return rootCsvNode; } catch (IOException e) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TOKEN, e.getMessage(), line, column); @@ -260,15 +270,19 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); - if (sm.lineNumber < headerStartRowNumber - 1) { - sm.lineNumber++; + if (sm.lineNumber < headerStartRowNumber) { + sm.isHeaderConfigExceedLineNumber = true; + if (sm.isNewLineOrEof(ch)) { + sm.lineNumber++; + } continue; } - if (!(isWhitespace(ch, sm.config.lineTerminator) && sm.isNewLineOrEof(ch))) { - headerStart = true; - } + sm.isHeaderConfigExceedLineNumber = false; +// if (!(isWhitespace(ch, sm.config.lineTerminator) && sm.isNewLineOrEof(ch))) { +// headerStart = true; +// } if (customHeader != null) { - if (headerStart && sm.isNewLineOrEof(ch)) { + if (sm.isNewLineOrEof(ch)) { checkAndAddCustomHeaders(sm, customHeader); sm.lineNumber++; state = HEADER_END_STATE; @@ -277,21 +291,26 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C continue; } - if (ch == separator) { + if (ch == sm.config.comment) { + sm.insideComment = true; + } else if (!sm.insideComment && ch == separator) { addHeader(sm); sm.columnIndex++; continue; - } else if (isEndOfTheRow(sm, ch)) { - addHeader(sm); - finalizeHeaders(sm); - sm.columnIndex = 0; - sm.lineNumber++; + } else if (sm.insideComment && sm.isNewLineOrEof(ch)) { + sm.insideComment = false; + handleEndOfTheHeader(sm); + state = HEADER_END_STATE; + } else if (isEndOfTheHeaderRow(sm, ch)) { + handleEndOfTheHeader(sm); state = HEADER_END_STATE; } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { state = this; continue; } else { - sm.append(ch); + if (!sm.insideComment) { + sm.append(ch); + } state = this; continue; } @@ -301,6 +320,15 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return state; } + private void handleEndOfTheHeader(StateMachine sm) throws CsvParserException { + if (!sm.peek().isBlank()) { + addHeader(sm); + finalizeHeaders(sm); + } + sm.columnIndex = 0; + sm.lineNumber++; + } + private int getHeaderStartRowWhenHeaderIsPresent(Object header) { return ((Long) header).intValue(); } @@ -372,66 +400,110 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (sm.skipTheRow) { +// buff[i-10],buff[i-9],buff[i-8],buff[i-7],buff[i-6],buff[i-5],buff[i-4],buff[i-3],buff[i-2],buff[i-1],buff[i],buff[i+1],buff[i+2],buff[i+3] + if (sm.isEndOfTheRowAndValueIsNotEmpty(sm, ch)) { + sm.insideComment = false; + sm.skipTheRow = false; + sm.clear(); + if (ch == EOF) { + state = ROW_END_STATE; + } + } else { + sm.append(ch); + } + continue; + } //TODO: Handle empty values and create again and again - if (sm.currentCsvNode == null) { + if (sm.isCurrentCsvNodeEmpty) { + if (ignoreRow(skipLines, sm.rowIndex)) { + updateLineAndColumnIndexes(sm); + sm.skipTheRow = true; + continue; + } initiateNewRowType(sm); } - if (ch == separator) { + if (!sm.insideComment && ch == sm.config.comment) { + handleEndOfTheRow(sm, ch); + sm.insideComment = true; + if (ch == EOF) { + state = ROW_END_STATE; + } + } else if (!sm.insideComment && ch == separator) { addRowValue(sm); - } else if (isEndOfTheRow(sm, ch)) { - sm.lineNumber++; - handleCsvRow(sm, skipLines); - checkOptionalFieldsAndLogError(sm.fieldHierarchy); + } else if (sm.insideComment && sm.isNewLineOrEof(ch)) { + sm.insideComment = false; + if (ch == EOF) { + state = ROW_END_STATE; + } + } else if (isEndOfTheRowAndValueIsNotEmpty(sm, ch)) { + handleEndOfTheRow(sm, ch); if (ch == EOF) { state = ROW_END_STATE; } } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { // ignore } else { - sm.append(ch); + if (!sm.insideComment) { + sm.append(ch); + } } } sm.index = i + 1; return state; } - private void handleCsvRow(StateMachine sm, long[] skipRows) throws CsvParserException { - String value = sm.value(); - if (value.isBlank()) { - updateLineAndColumnIndexes(sm); - return; - } + private void handleEndOfTheRow(StateMachine sm, char ch) throws CsvParserException { +// if (sm.peek().isBlank()) { +// updateLineAndColumnIndexesWithoutRowIndexes(sm); +// } else { + handleCsvRow(sm); + checkOptionalFieldsAndLogError(sm.fieldHierarchy); +// } + } - addRowValue(sm); - if (ignoreRow(skipRows, sm.rowIndex)) { - updateLineAndColumnIndexes(sm); - return; + private void handleCsvRow(StateMachine sm) throws CsvParserException { + if (!sm.peek().isBlank()) { + addRowValue(sm); + } + if (!sm.isCurrentCsvNodeEmpty) { + finalizeTheRow(sm); + } else { + updateLineAndColumnIndexesWithoutRowIndexes(sm); } - - finalizeTheRow(sm); updateLineAndColumnIndexes(sm); } private void updateLineAndColumnIndexes(StateMachine sm) { - sm.lineNumber++; sm.rowIndex++; + updateLineAndColumnIndexesWithoutRowIndexes(sm); + } + + private void updateLineAndColumnIndexesWithoutRowIndexes(StateMachine sm) { + sm.lineNumber++; sm.currentCsvNode = null; + sm.isCurrentCsvNodeEmpty = true; sm.columnIndex = 0; } private boolean ignoreRow(long[] skipLines, int lineNumber) { - return skipLines[0] <= lineNumber && lineNumber < skipLines[skipLines.length - 1]; + for (long skipLine: skipLines) { + if (skipLine == lineNumber) { + return true; + } + } + return false; } - private void initiateNewRowType(StateMachine sm) throws CsvParserException { + private void initiateNewRowType(StateMachine sm) { sm.currentCsvNode = CsvCreator.initRowValue(sm.expectedArrayElementType); } private void finalizeTheRow(StateMachine sm) { int rootArraySize = sm.rootArrayType.getSize(); if (rootArraySize == -1 || sm.rowIndex < rootArraySize) { - sm.rootCsvNode.add(sm.rowIndex, sm.currentCsvNode); + sm.rootCsvNode.append(sm.currentCsvNode); } } @@ -637,8 +709,12 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } - public static boolean isEndOfTheRow(CsvParser.StateMachine sm, char ch) { - return (ch == EOF || !sm.peek().isEmpty()) && sm.isNewLineOrEof(ch); + public static boolean isEndOfTheRowAndValueIsNotEmpty(CsvParser.StateMachine sm, char ch) { + return sm.isNewLineOrEof(ch) && (ch == EOF || !(sm.isCurrentCsvNodeEmpty && sm.peek().isBlank())); + } + + public static boolean isEndOfTheHeaderRow(CsvParser.StateMachine sm, char ch) { + return sm.isNewLineOrEof(ch); } public static class CsvParserException extends Exception { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 788a58c..c6a72e2 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -218,12 +218,10 @@ public static long[] getSkipDataRows(Object skipLines) { return new long[]{-1}; } skipDataRows = (skipLinesArray).getIntArray(); - Arrays.sort(skipDataRows); return skipDataRows; } skipDataRows = getSkipLinesFromStringConfigValue(StringUtils.getStringValue(skipLines)); - Arrays.sort(skipDataRows); return skipDataRows; } From f2a4a1a1c5b6f177f3af0e7e3f5133284f5aa100 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 6 Jun 2024 15:12:58 +0530 Subject: [PATCH 027/147] Add tests for customheaders --- ballerina/csv_api.bal | 2 +- .../tests/parse_record_type_as_list_test.bal | 38 ++++++------ ballerina/tests/test_utils.bal | 4 ++ .../user_config_with_parser_options_test.bal | 60 ++++++++++++++++++- ballerina/types.bal | 3 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 16 ++++- .../stdlib/data/csvdata/csv/Native.java | 7 ++- .../stdlib/data/csvdata/utils/CsvConfig.java | 1 + .../stdlib/data/csvdata/utils/CsvUtils.java | 3 + .../csvdata/utils/DiagnosticErrorCode.java | 5 +- native/src/main/resources/error.properties | 17 +++++- 11 files changed, 124 insertions(+), 32 deletions(-) diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index fb526cb..bf8aaba 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -41,7 +41,7 @@ public isolated function parseRecordAsRecordType(record{}[] s, ToRecordOptions options = {}, typedesc t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public isolated function parseRecordAsListType(record{}[] s, string[] customHeaders, +public isolated function parseRecordAsListType(record{}[] s, string[] headerNames, Options options = {}, typedesc t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; diff --git a/ballerina/tests/parse_record_type_as_list_test.bal b/ballerina/tests/parse_record_type_as_list_test.bal index 8a75d6c..9b707b7 100644 --- a/ballerina/tests/parse_record_type_as_list_test.bal +++ b/ballerina/tests/parse_record_type_as_list_test.bal @@ -33,7 +33,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { test:assertTrue(bm3ba is CsvConversionError); test:assertEquals((bm3ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanArrayArray|CsvConversionError bm4ba = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, BooleanArrayArray); + BooleanArrayArray|CsvConversionError bm4ba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanArrayArray); test:assertTrue(bm4ba is CsvConversionError); test:assertEquals((bm4ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); @@ -57,7 +57,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { test:assertTrue(bm3nba is CsvConversionError); test:assertEquals((bm3nba).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanArrayArray|CsvConversionError bm4nba = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableBooleanArrayArray); + NillableBooleanArrayArray|CsvConversionError bm4nba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanArrayArray); test:assertEquals(bm4nba, [ [(), ()], [(), ()] @@ -99,7 +99,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { [true, false, null, false, 1] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm4niouba = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|CsvConversionError bm4niouba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm4niouba, [ [(), ()], [(), ()] @@ -129,7 +129,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { [true, false, null, false, 1] ]); - JsonArray1Array|CsvConversionError bm4ja = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, JsonArray1Array); + JsonArray1Array|CsvConversionError bm4ja = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonArray1Array); test:assertEquals(bm4ja, [ [(), ()], [(), ()] @@ -159,7 +159,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { [true, false, null, false, 1] ]); - AnydataArray1Array|CsvConversionError bm4anyda = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, AnydataArray1Array); + AnydataArray1Array|CsvConversionError bm4anyda = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataArray1Array); test:assertEquals(bm4anyda, [ [(), ()], [(), ()] @@ -183,7 +183,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { test:assertTrue(bm3sa is CsvConversionError); test:assertEquals((bm3sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|CsvConversionError bm4sa = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, StringArray1Array); + StringArray1Array|CsvConversionError bm4sa = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, StringArray1Array); test:assertTrue(bm4sa is CsvConversionError); test:assertEquals((bm4sa).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); @@ -208,7 +208,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { test:assertTrue(bm3bt is CsvConversionError); test:assertEquals((bm3bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple1Array|CsvConversionError bm4bt = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, BooleanTuple1Array); + BooleanTuple1Array|CsvConversionError bm4bt = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple1Array); test:assertTrue(bm4bt is CsvConversionError); test:assertEquals((bm4bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); @@ -234,7 +234,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { [true, false] ]); - BooleanTuple2Array|CsvConversionError bm4b2t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, BooleanTuple2Array); + BooleanTuple2Array|CsvConversionError bm4b2t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple2Array); test:assertTrue(bm4b2t is CsvConversionError); test:assertEquals((bm4b2t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); @@ -258,7 +258,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { test:assertTrue(bm3b3t is CsvConversionError); test:assertEquals((bm3b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple3Array|CsvConversionError bm4b3t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, BooleanTuple3Array); + BooleanTuple3Array|CsvConversionError bm4b3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple3Array); test:assertTrue(bm4b3t is CsvConversionError); test:assertEquals((bm4b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); @@ -280,7 +280,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { test:assertTrue(bm3b4t is CsvConversionError); test:assertEquals((bm3b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple4Array|CsvConversionError bm4b4t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, BooleanTuple4Array); + BooleanTuple4Array|CsvConversionError bm4b4t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple4Array); test:assertTrue(bm4b4t is CsvConversionError); test:assertEquals((bm4b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); @@ -304,7 +304,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { test:assertTrue(bm3nbt is CsvConversionError); test:assertEquals((bm3nbt).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple5Array|CsvConversionError bm4nbt = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|CsvConversionError bm4nbt = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple5Array); test:assertEquals(bm4nbt, [ [(), (), (), (), ()], [(), (), (), (), ()] @@ -334,7 +334,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { [true, false] ]); - NillableBooleanTuple6Array|CsvConversionError bm4nb6t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|CsvConversionError bm4nb6t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple6Array); test:assertEquals(bm4nb6t, [ [(), ()], [(), ()] @@ -362,7 +362,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { test:assertTrue(bm3nb7t is CsvConversionError); test:assertEquals((bm3nb7t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple7Array|CsvConversionError bm4nb7t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|CsvConversionError bm4nb7t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple7Array); test:assertEquals(bm4nb7t, [ [(), ()], [(), ()] @@ -390,7 +390,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { test:assertTrue(bm3nb8t is CsvConversionError); test:assertEquals((bm3nb8t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple8Array|CsvConversionError bm4nb8t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|CsvConversionError bm4nb8t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple8Array); test:assertEquals(bm4nb8t, [ [(), ()], [(), ()] @@ -420,7 +420,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { [true, false, (), false, 1] ]); - NillableIntBooleanTuple9Array|CsvConversionError bm4nb9t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|CsvConversionError bm4nb9t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntBooleanTuple9Array); test:assertEquals(bm4nb9t, [ [(), ()], [(), ()] @@ -444,7 +444,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { test:assertTrue(bm3n3t is CsvConversionError); test:assertEquals((bm3n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|CsvConversionError bm4n3t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, NilTuple3Array); + NilTuple3Array|CsvConversionError bm4n3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NilTuple3Array); test:assertEquals(bm4n3t, [ [(), ()], [(), ()] @@ -476,7 +476,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType2() { [true, false, (), false, 1] ]); - AnydataTuple3Array|CsvConversionError bm4anyd3t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, AnydataTuple3Array); + AnydataTuple3Array|CsvConversionError bm4anyd3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataTuple3Array); test:assertEquals(bm4anyd3t, [ [(), ()], [(), ()] @@ -506,7 +506,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType2() { [true, false, (), false, 1] ]); - JsonTuple3Array|CsvConversionError bm4j3t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, JsonTuple3Array); + JsonTuple3Array|CsvConversionError bm4j3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonTuple3Array); test:assertEquals(bm4j3t, [ [(), ()], [(), ()] @@ -530,7 +530,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType2() { test:assertTrue(bm3s3t is CsvConversionError); test:assertEquals((bm3s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|CsvConversionError bm4s3t = parseRecordAsListType([bm4, bm4], ["n1", "n2"], {}, StringTuple3Array); + StringTuple3Array|CsvConversionError bm4s3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, StringTuple3Array); test:assertTrue(bm4s3t is CsvConversionError); test:assertEquals((bm4s3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); diff --git a/ballerina/tests/test_utils.bal b/ballerina/tests/test_utils.bal index f2d8140..d328643 100644 --- a/ballerina/tests/test_utils.bal +++ b/ballerina/tests/test_utils.bal @@ -17,3 +17,7 @@ function generateErrorMessageForInvalidValueForArrayType(string value, string in function generateErrorMessageForInvalidHeaders(string value, string 'type) returns string{ return string `value '${value}' cannot be cast into '${'type}', because fields in '${'type}' or the provided expected headers are not matching with the '${value}'`; } + +function generateErrorMessageForInvalidCustomHeader(string header) returns string{ + return string `Invalid header value: '${header}'`; +} diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index 35147b2..82bc758 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -3,9 +3,12 @@ import ballerina/test; boolean enable = true; @test:Config {enable: !enable} -function debugTest() returns error? { - record{}[]|CsvConversionError csv2cop3 = parseStringToRecord(csvStringData1, {header: 0, skipLines: "2-5"}); - test:assertEquals(csv2cop3, [{a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}]); +function debugTest() returns error? { + record{}[]|CsvConversionError bm1br = parseListAsRecordType([["a", "1", "true"], []], ["a", "b"], {}); + test:assertEquals(bm1br, [ + [true, false], + [true, false] + ]); } @test:Config {enable} @@ -467,3 +470,54 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); } + +@test:Config {enable} +function testCustomHeaderParserOption() { +// parseListAsRecordType + anydata[][]|CsvConversionError bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}); + test:assertEquals(bm1ba, [ + [true, false], + [true, false] + ]); + + anydata[][]|CsvConversionError bm1ba2 = parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}); + test:assertEquals(bm1ba2, [ + [false, true], + [false, true] + ]); + + anydata[][]|CsvConversionError bm2ba = parseRecordAsListType([bm2, bm2], ["b1", "n1", "b2", "n2", "b3"], {}); + test:assertTrue(bm2ba is CsvConversionError); + test:assertEquals(( bm2ba).message(), generateErrorMessageForInvalidCustomHeader("n2")); + + anydata[][]|CsvConversionError bm3ba = parseRecordAsListType([bm3, bm3], ["b1", "b4", "b2", "n2", "i1"], {}); + test:assertTrue(bm3ba is CsvConversionError); + test:assertEquals(( bm3ba).message(), generateErrorMessageForInvalidCustomHeader("n2")); + + anydata[][]|CsvConversionError bm3ba2 = parseRecordAsListType([bm3, bm3], ["b1", "b3", "b4", "b2", "i2"], {}); + test:assertTrue(bm3ba2 is CsvConversionError); + test:assertEquals(( bm3ba2).message(), generateErrorMessageForInvalidCustomHeader("i2")); + + // TODO: Fix this + // [boolean, boolean][]|CsvConversionError bm3ba3 = parseRecordAsListType([bm3, bm3], ["b1", "b4"], {}); + // test:assertEquals(bm3ba3, [ + // [b1, b4], + // [b1, b4] + // ]); + + [boolean...][]|CsvConversionError bm3ba4 = parseRecordAsListType([bm3, bm3], ["n2"], {}); + test:assertTrue(bm3ba4 is CsvConversionError); + test:assertEquals(( bm3ba4).message(), "Invalid length for the header names"); + + [boolean...][]|CsvConversionError bm3ba5 = parseRecordAsListType([bm3, bm3], [], {}); + test:assertTrue(bm3ba5 is CsvConversionError); + test:assertEquals(( bm3ba5).message(), "Invalid length for the header names"); + + record{}[]|CsvConversionError bm1br = parseListAsRecordType([["a", "1", "true"], []], ["a", "b"], {}); + test:assertTrue(bm1br is CsvConversionError); + test:assertEquals(( bm1br).message(), "Invalid length for the custom headers"); + + record{}[]|CsvConversionError bm1br2 = parseListAsRecordType([["a", "1", "true"], []], ["a", "b"], {}); + test:assertTrue(bm1br2 is CsvConversionError); + test:assertEquals(( bm1br2).message(), "Invalid length for the custom headers"); +} diff --git a/ballerina/types.bal b/ballerina/types.bal index fc2684b..f0d0088 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -20,7 +20,8 @@ public type ParseOption record {| string:Char escapeChar = "\\"; LineTerminator|LineTerminator[] lineTerminator = [CR, LF, CRLF]; NilValue? nilValue = (); - string:Char comment = "#"; + // string commentStartingSequence = "#"; + string comment = "#"; false|int:Unsigned32 header = 0; |}; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 476e32b..5b5312f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -201,17 +201,31 @@ private void constructArrayValuesFromMap(BMap map, Type type, i int size = map.size(); BString[] keys = new BString[size]; int index = 0; - if (config.customHeader == null) { + if (config.headersOrder != null) { + String[] headerOrder = config.headersOrder.getStringArray(); + if (headerOrder.length != size) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_HEADER_NAMES_LENGTH); + } + for (int i = 0; i < size; i++) { + keys[i] = StringUtils.fromString(headerOrder[i]); + } + } else if (config.customHeader == null) { keys = map.getKeys(); } else { if (this.headers == null) { this.headers = createHeaders(new String[size], config); } + if (this.headers.length != size) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); + } for (int i = 0; i < size; i++) { keys[i] = StringUtils.fromString(this.headers[i]); } } for (BString key: keys) { + if (!map.containsKey(key)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER, key); + } Object v = map.get(key); if (index >= expectedSize) { break; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index b94f9ab..276c25a 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -123,11 +123,12 @@ public static Object parseRecordAsRecordType(BArray csv, BMap o return DiagnosticLog.getCsvError(e.getMessage()); } } - public static Object parseRecordAsListType(BArray csv, BArray customHeaders, + public static Object parseRecordAsListType(BArray csv, BArray headers, BMap options, BTypedesc type) { try { - options.put(Constants.ConfigConstants.CUSTOM_HEADERS, customHeaders); - return CsvTraversal.traverse(csv, CsvConfig.createToRecordOptions(options), type.getDescribingType()); + CsvConfig toRecordOptions = CsvConfig.createToRecordOptions(options); + toRecordOptions.headersOrder = headers; + return CsvTraversal.traverse(csv, toRecordOptions, type.getDescribingType()); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java index dd3d264..573043c 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java @@ -22,6 +22,7 @@ public class CsvConfig { public boolean absentAsNilableType = false; public boolean allowDataProjection = true; public Object customHeader = null; + public BArray headersOrder = null; private CsvConfig(Object skipLines, boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index c6a72e2..a72b636 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -88,6 +88,9 @@ public static String[] createHeaders(String[] headers, CsvConfig config) { if (customHeaders instanceof BArray) { BArray array = (BArray) customHeaders; + if (array.size() != headers.length) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); + } for (int i = 0; i < headers.length; i++) { headers[i] = array.get(i).toString(); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index d0d2032..e2f1d03 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -43,7 +43,10 @@ public enum DiagnosticErrorCode { EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES("BDE_0016", "expected.type.can.only.contains.basic.types"), 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_VALUE_FOR_SKIPLINES( "BDE_0019", "invalid.value.for.skiplines"), + INVALID_CUSTOM_HEADER("BDE_0020", "invalid.custom.header"), + INVALID_CUSTOM_HEADER_LENGTH("BDE_0021", "invalid.custom.header.length"), + INVALID_HEADER_NAMES_LENGTH("BDE_0022", "invalid.header.names.length"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index a5edfae..0179367 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -70,8 +70,19 @@ error.invalid.configurations=\ invalid configurations: ''{0}'' error.invalid.format.for.skiplines=\ - "Invalid format for the skipLines field. Expected format: 'start-end'" + Invalid format for the skipLines field. Expected format: 'start-end' + error.invalid.range.for.skiplines=\ - Invalid range for the skipLines field. Start value must be less than or equal to end value." + Invalid range for the skipLines field. Start value must be less than or equal to end value. + error.invalid.value.for.skiplines=\ - "Invalid input for the skipLines field. Both start and end values must be integers." + Invalid input for the skipLines field. Both start and end values must be integers. + +error.invalid.custom.header=\ + Invalid header value: ''{0}'' + +error.invalid.custom.header.length=\ + Invalid length for the custom headers + +error.invalid.header.names.length=\ + Invalid length for the header names From 04388dac5540327d0d6aa21e3a8cad022812e046 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 10 Jun 2024 04:33:59 +0530 Subject: [PATCH 028/147] Add basic text enclosure property --- ballerina/csv_api.bal | 4 +- .../tests/parse_list_type_as_record_test.bal | 52 +- .../tests/parse_string_to_map_tests copy.bal | 6 + .../user_config_with_parser_options_test.bal | 286 +++++++++- ballerina/types.bal | 2 +- .../stdlib/data/csvdata/csv/CsvCreator.java | 3 + .../stdlib/data/csvdata/csv/CsvParser.java | 494 +++++++++++------- .../stdlib/data/csvdata/csv/CsvTraversal.java | 15 +- .../stdlib/data/csvdata/csv/Native.java | 2 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 1 + .../csvdata/utils/DiagnosticErrorCode.java | 3 +- native/src/main/resources/error.properties | 3 + 12 files changed, 655 insertions(+), 216 deletions(-) diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index bf8aaba..c5c63b3 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -16,7 +16,6 @@ import ballerina/jballerina.java; - public isolated function parseStringToRecord(string s, parseToRecordOption options = {}, typedesc t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; @@ -38,7 +37,7 @@ public isolated function parseStreamToList(stream s, returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function parseRecordAsRecordType(record{}[] s, - ToRecordOptions options = {}, typedesc t = <>) + Options options = {}, typedesc t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function parseRecordAsListType(record{}[] s, string[] headerNames, @@ -53,4 +52,3 @@ public isolated function parseListAsListType(string[][] s, Options options = {}, returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - diff --git a/ballerina/tests/parse_list_type_as_record_test.bal b/ballerina/tests/parse_list_type_as_record_test.bal index ba84d2e..1ffc6ae 100644 --- a/ballerina/tests/parse_list_type_as_record_test.bal +++ b/ballerina/tests/parse_list_type_as_record_test.bal @@ -1,13 +1,22 @@ import ballerina/test; -// boolean enable = false; +// boolean enable = true; // @test:Config {enable: !enable} // function debugTest() { -// StringRecord10Array|CsvConversionError st1sr10 = parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); -// test:assertEquals(st1sr10, [ -// {'1: "string", '2: ""}, -// {'1: "string", '2: ""} +// // record{decimal c; boolean d; int e; string f;}[]|CsvConversionError ct1br8 = parseListAsRecordType( +// // [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], +// // ["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 c;}[]|CsvConversionError ct1br8 = parseStringToRecord(string `c +// 1`, {}); +// 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"} // ]); // } @@ -481,6 +490,39 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { ]); } +@test:Config {enable: false} +function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { + record{string a; boolean b; int c;}[]|CsvConversionError ct1br4 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["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;}[]|CsvConversionError ct1br6 = parseListAsRecordType( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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;|}[]|CsvConversionError ct1br7 = parseListAsRecordType( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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;}[]|CsvConversionError ct1br8 = parseListAsRecordType( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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"} + ]); +} + @test:Config {enable} function testFromCsvWithTypeForTupleAndMapAsExpectedType() { StringMapArray|CsvConversionError st1sma = parseListAsRecordType([st1, st1], (), {}, StringMapArray); diff --git a/ballerina/tests/parse_string_to_map_tests copy.bal b/ballerina/tests/parse_string_to_map_tests copy.bal index 88fd2c6..dd850be 100644 --- a/ballerina/tests/parse_string_to_map_tests copy.bal +++ b/ballerina/tests/parse_string_to_map_tests copy.bal @@ -406,4 +406,10 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { test:assertEquals(bv7dsma, [ {} ]); + + //TODO: Fix the test case + // string csvValue1 = string `a, + // 1,,`; + // record{}[]|error a = parseStringToRecord(csvValue1, {}); + // test:assertEquals(a, [{a: 1}]); } diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index 82bc758..d5820b7 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -4,11 +4,8 @@ boolean enable = true; @test:Config {enable: !enable} function debugTest() returns error? { - record{}[]|CsvConversionError bm1br = parseListAsRecordType([["a", "1", "true"], []], ["a", "b"], {}); - test:assertEquals(bm1br, [ - [true, false], - [true, false] - ]); + + } @test:Config {enable} @@ -152,11 +149,10 @@ function testHeaderOption() { record{}[]|CsvConversionError csv2cop4 = parseStringToRecord(csvStringData2, {header: 10}); test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", '1: true, "-6.51": 3, "()": ()}]); -} - -@test:Config {enable} -function testCustomHeaderOption() { + record{}[]|CsvConversionError csv1cop5 = parseStringToRecord(csvStringData1, {}); + test:assertTrue(csv1cop5 is CsvConversionError); + test:assertEquals(( csv1cop5).message(), "The provided header row is empty"); } @test:Config {enable} @@ -472,8 +468,7 @@ function testSkipLineParserOption() { } @test:Config {enable} -function testCustomHeaderParserOption() { -// parseListAsRecordType +function testCustomHeaderOption() { anydata[][]|CsvConversionError bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}); test:assertEquals(bm1ba, [ [true, false], @@ -498,13 +493,6 @@ function testCustomHeaderParserOption() { test:assertTrue(bm3ba2 is CsvConversionError); test:assertEquals(( bm3ba2).message(), generateErrorMessageForInvalidCustomHeader("i2")); - // TODO: Fix this - // [boolean, boolean][]|CsvConversionError bm3ba3 = parseRecordAsListType([bm3, bm3], ["b1", "b4"], {}); - // test:assertEquals(bm3ba3, [ - // [b1, b4], - // [b1, b4] - // ]); - [boolean...][]|CsvConversionError bm3ba4 = parseRecordAsListType([bm3, bm3], ["n2"], {}); test:assertTrue(bm3ba4 is CsvConversionError); test:assertEquals(( bm3ba4).message(), "Invalid length for the header names"); @@ -513,11 +501,261 @@ function testCustomHeaderParserOption() { test:assertTrue(bm3ba5 is CsvConversionError); test:assertEquals(( bm3ba5).message(), "Invalid length for the header names"); - record{}[]|CsvConversionError bm1br = parseListAsRecordType([["a", "1", "true"], []], ["a", "b"], {}); - test:assertTrue(bm1br is CsvConversionError); - test:assertEquals(( bm1br).message(), "Invalid length for the custom headers"); + // ------------------------------------------------------------- + + record{}[]|CsvConversionError ct1br = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); + test:assertTrue(ct1br is CsvConversionError); + test:assertEquals(( ct1br).message(), "Invalid length for the custom headers"); + + record{}[]|CsvConversionError ct1br2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); + test:assertTrue(ct1br2 is CsvConversionError); + test:assertEquals(( ct1br2).message(), "Invalid length for the custom headers"); + + record{}[]|CsvConversionError ct1br2_2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); + test:assertTrue(ct1br2_2 is CsvConversionError); + test:assertEquals(( ct1br2_2).message(), "Invalid length for the custom headers"); + + record{}[]|CsvConversionError ct1br3 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], [], {}); + test:assertTrue(ct1br3 is CsvConversionError); + test:assertEquals(( ct1br3).message(), "Invalid length for the custom headers"); + + record{|string a; string b; string c;|}[]|CsvConversionError ct1br5 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + test:assertTrue(ct1br5 is CsvConversionError); + // TODO: Fix + test:assertEquals(( ct1br5).message(), generateErrorMessageForMissingRequiredField("c")); + + record{string a; string b; string c;}[]|CsvConversionError ct1br6 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + test:assertTrue(ct1br6 is CsvConversionError); + test:assertEquals(( ct1br6).message(), generateErrorMessageForMissingRequiredField("c")); + + record{string a; string b;}[]|CsvConversionError ct1br7 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + test:assertEquals(ct1br7, [ + {a: "a", e: "1", b: "true"}, + {a: "a", e: "1", b: "true"} + ]); + + record{|string a; string b;|}[]|CsvConversionError ct1br8 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + test:assertEquals(ct1br8, [ + {a: "a", b: "true"}, + {a: "a", b: "true"} + ]); + + record{|string...;|}[]|CsvConversionError ct1br9 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + test:assertEquals(ct1br9, [ + {a: "a", b: "true", e: "1"}, + {a: "a", b: "true", e: "1"} + ]); + + record{|string...;|}[]|CsvConversionError ct1br10 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), {}); + test:assertEquals(ct1br10, [ + {'1: "a", '3: "true", '2: "1"}, + {'1: "a", '3: "true", '2: "1"} + ]); +} + +@test:Config {enable} +function testCustomHeaderParserOption2() { + // parseStringToRecord + // parseRecordAsRecordType + + record{}[]|CsvConversionError ct1br = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); + test:assertTrue(ct1br is CsvConversionError); + test:assertEquals(( ct1br).message(), "Invalid length for the custom headers"); + + // record{}[]|CsvConversionError ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b", "aa", "aaa", "aaaaa", "bb", "ccc"]}); + // // TODO: Fix this + // test:assertTrue(ct1br2 is CsvConversionError); + // test:assertEquals(( ct1br2).message(), "Invalid length for the custom headers"); + + record{}[]|CsvConversionError ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: []}); + test:assertTrue(ct1br2 is CsvConversionError); + test:assertEquals(( ct1br2).message(), "Invalid length for the custom headers"); + + record{int a; string b; boolean c; decimal d; float e; () f;}[]|CsvConversionError ct1br3 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); + test:assertTrue(ct1br3 is CsvConversionError); + test:assertEquals(( ct1br3).message(), "Invalid length for the custom headers"); + + record{int a; string b; boolean c; decimal d; float e; () f;}[]|CsvConversionError ct1br4 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["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;}[]|CsvConversionError ct1br5 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["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;}[]|CsvConversionError ct1br5_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["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;}[]|CsvConversionError ct1br5_3 = parseStringToRecord(csvStringData1, {skipLines: [1], customHeaders: ["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;|}[]|CsvConversionError ct1br6 = 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;|}[]|CsvConversionError ct1br7 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["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;|}[]|CsvConversionError ct1br7_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["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;|}[]|CsvConversionError ct1br8 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); + // TODO: Fix + test:assertTrue(ct1br8 is CsvConversionError); + test:assertEquals(( ct1br8).message(), generateErrorMessageForInvalidCast("string1", "boolean")); + + record{|boolean d1; string e1;|}[]|CsvConversionError ct1br9 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["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;|}[]|CsvConversionError ct1br10 = 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;|}[]|CsvConversionError ct1br11 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); + test:assertTrue(ct1br11 is CsvConversionError); + test:assertEquals(( ct1br11).message(), "Invalid length for the custom headers"); + + record{|string d1; string e1;|}[]|CsvConversionError ct1br12 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + test:assertEquals(ct1br12, [ + {e1: "string1", d1: "true"}, + {e1: "string2", d1: "false"}, + {e1: "string3", d1: "0"}, + {e1: "string4", d1: "1"}, + {e1: "string5", d1: "true"} + ]); + + record{|string d1; string e1;|}[]|CsvConversionError ct1br13 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); + test:assertTrue(ct1br13 is CsvConversionError); + test:assertEquals(( ct1br13).message(), generateErrorMessageForMissingRequiredField("d1")); +} + +@test:Config {enable} +function testTextQuotesWithParserOptions() { + string csvValue1 = string ` + a, b, c + 1, "2", "3" + "1", 2, 3 + 1, "2", 3 + + "1", "2", "3"`; + + string csvValue2 = string ` + a, b, c + 1, "2, 3", 3 + 1, "2, 3",3 + 4, 5, 6 + `; + + string csvValue3 = string `a, b, c + "1", ""2"", "3" + 4, "5, 6"b" " a "", ""6""`; + + string csvValue4 = string `a, b, c + 1, '2', 3 + 4, '5, '6'7', 8 + 4, "5", '4, '5"a", ,"," a '6'7'`; + + string csvValue5 = string `a, b, c + 1, "2", "3" + 1, 2, 3 + "1", "2", 3 + 1, "2", "3" + `; + + record {}[]|CsvConversionError cn = parseStringToRecord(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 {}[]|CsvConversionError cn2 = parseStringToRecord(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 {}[]|CsvConversionError cn3 = parseStringToRecord(csvValue3, {}); + test:assertEquals(cn3, [{"a":1,"b":"\"2\"","c":3}, {"a":4,"b":"5, 6\"b\" \" a \"", c:"\"6\""}]); + + record {}[]|CsvConversionError cn4 = parseStringToRecord(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"}]); + + record {}[]|CsvConversionError cn5 = parseStringToRecord(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}]); +} + +@test:Config {enable} +function testHeaderQuotesWithParserOptions() { + string csvValue1 = string ` + "a", b, c + 1, "2", "3" + "1", 2, 3 + 1, "2", 3 + + "1", "2", "3"`; + + string csvValue2 = string ` + "a, b, c", "b,c", "c,d" + 1, "2, 3", 3 + 1, "2, 3",3 + 4, 5, 6 + `; + + string csvValue3 = string `'a '1'a5,6', 'b", " ","""', c + 1, '2', 3 + 4, '5, '6'7', 8 + 4, "5", '4, '5"a", ,"," a '6'7'`; + + record {}[]|CsvConversionError cn = parseStringToRecord(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 {}[]|CsvConversionError cn2 = parseStringToRecord(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}]); - record{}[]|CsvConversionError bm1br2 = parseListAsRecordType([["a", "1", "true"], []], ["a", "b"], {}); - test:assertTrue(bm1br2 is CsvConversionError); - test:assertEquals(( bm1br2).message(), "Invalid length for the custom headers"); + record {}[]|CsvConversionError cn3 = parseStringToRecord(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"}]); } diff --git a/ballerina/types.bal b/ballerina/types.bal index f0d0088..5823af8 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -21,7 +21,7 @@ public type ParseOption record {| LineTerminator|LineTerminator[] lineTerminator = [CR, LF, CRLF]; NilValue? nilValue = (); // string commentStartingSequence = "#"; - string comment = "#"; + string:Char comment = "#"; false|int:Unsigned32 header = 0; |}; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index c7a558e..461b13d 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -105,6 +105,9 @@ public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { } return header; } + if (sm.columnIndex >= sm.headers.size()) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); + } return sm.headers.get(sm.columnIndex); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index a6c5ed9..63a1fbe 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -26,11 +26,10 @@ import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; -import io.ballerina.runtime.api.values.BMap; -import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; +import org.apache.commons.lang3.StringEscapeUtils; import java.io.IOException; import java.io.Reader; @@ -54,6 +53,7 @@ public class CsvParser { private static final char REV_SOL = '\\'; private static final char SOL = '/'; private static final char EOF = (char) -1; + private static final char NEWLINE = 0x000A; private static final ThreadLocal tlStateMachine = ThreadLocal.withInitial(StateMachine::new); @@ -75,8 +75,15 @@ static class StateMachine { private static State HEADER_END_STATE = new HeaderEndState(); private static State ROW_START_STATE = new RowStartState(); private static State ROW_END_STATE = new RowEndState(); - private static State STRING_VALUE_STATE = new StringValueEscapedCharacterProcessingState(); - private static State HEADER_NAME_STATE = new HeaderNameEscapedCharacterProcessingState(); + private static State STRING_ESCAPE_VALUE_STATE = new StringValueEscapedCharacterProcessingState(); + private static State STRING_UNICODE_CHAR_STATE = new StringValueUnicodeHexProcessingState(); + private static State HEADER_UNICODE_CHAR_STATE = new HeaderUnicodeHexProcessingState(); + private static State HEADER_ESCAPE_CHAR_STATE = new HeaderEscapedCharacterProcessingState(); + private static State STRING_QUOTE_CHAR_STATE = new StringQuoteValueState(); + private static State HEADER_QUOTE_CHAR_STATE = new HeaderQuoteValueState(); + + + private static char LINE_BREAK = '\n'; Object currentCsvNode; @@ -101,6 +108,9 @@ static class StateMachine { boolean insideComment = false; boolean isCurrentCsvNodeEmpty = true; boolean isHeaderConfigExceedLineNumber = false; + boolean isQuoteClosed = false; + + private StringBuilder hexBuilder = new StringBuilder(4); StateMachine() { reset(); } @@ -127,6 +137,8 @@ public void reset() { skipTheRow = false; isCurrentCsvNodeEmpty = true; isHeaderConfigExceedLineNumber = false; + hexBuilder = new StringBuilder(4); + isQuoteClosed = false; } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -265,7 +277,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C //TODO: If the header is not present make the headers and fieldnames to be default values char separator = sm.config.delimiter; Object customHeader = sm.config.customHeader; - boolean headerStart = false; int headerStartRowNumber = getHeaderStartRowWhenHeaderIsPresent(sm.config.header); for (; i < count; i++) { ch = buff[i]; @@ -297,11 +308,17 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C addHeader(sm); sm.columnIndex++; continue; + } else if (!sm.insideComment && ch == sm.config.textEnclosure) { + state = HEADER_QUOTE_CHAR_STATE; + break; + } else if (!sm.insideComment && ch == sm.config.escapeChar) { + state = HEADER_ESCAPE_CHAR_STATE; + break; } else if (sm.insideComment && sm.isNewLineOrEof(ch)) { sm.insideComment = false; handleEndOfTheHeader(sm); state = HEADER_END_STATE; - } else if (isEndOfTheHeaderRow(sm, ch)) { + } else if (!sm.insideComment && isEndOfTheHeaderRow(sm, ch)) { handleEndOfTheHeader(sm); state = HEADER_END_STATE; } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { @@ -319,66 +336,69 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.index = i + 1; return state; } + } - private void handleEndOfTheHeader(StateMachine sm) throws CsvParserException { - if (!sm.peek().isBlank()) { - addHeader(sm); - finalizeHeaders(sm); - } - sm.columnIndex = 0; - sm.lineNumber++; - } - - private int getHeaderStartRowWhenHeaderIsPresent(Object header) { - return ((Long) header).intValue(); - } - - private void finalizeHeaders(StateMachine sm) throws CsvParserException { - Type expType = sm.expectedArrayElementType; - if (expType instanceof RecordType) { - validateRemainingRecordFields(sm); - } else if (expType instanceof ArrayType) { - // TODO: Get the other validation into here - //TODO: Replace arraysize -1 with - // TODO: Can remove using fillers - validateExpectedArraySize(((ArrayType) expType).getSize(), sm.headers.size()); - } else if (expType instanceof MapType) { - //ignore - } else if (expType instanceof TupleType) { - validateTupleTypes((TupleType) expType, sm.restType, sm.headers.size()); - } else { - throw new CsvParserException("Invalid expected type"); - } + private static void handleEndOfTheHeader(StateMachine sm) throws CsvParserException { + if (!sm.peek().isBlank()) { + addHeader(sm); } + finalizeHeaders(sm); + sm.columnIndex = 0; + sm.lineNumber++; + } - private void validateTupleTypes(TupleType tupleType, Type restType, int currentSize) { - if (restType != null && tupleType.getTupleTypes().size() > currentSize) { - // TODO: Can remove using fillers - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, currentSize); - } + private static int getHeaderStartRowWhenHeaderIsPresent(Object header) { + return ((Long) header).intValue(); + } + + private static void finalizeHeaders(StateMachine sm) throws CsvParserException { + if (sm.headers.size() == 0) { + throw DiagnosticLog.error(DiagnosticErrorCode.HEADER_CANNOT_BE_EMPTY); + } + Type expType = sm.expectedArrayElementType; + if (expType instanceof RecordType) { + validateRemainingRecordFields(sm); + } else if (expType instanceof ArrayType) { + // TODO: Get the other validation into here + //TODO: Replace arraysize -1 with + // TODO: Can remove using fillers + validateExpectedArraySize(((ArrayType) expType).getSize(), sm.headers.size()); + } else if (expType instanceof MapType) { + //ignore + } else if (expType instanceof TupleType) { + validateTupleTypes((TupleType) expType, sm.restType, sm.headers.size()); + } else { + throw new CsvParserException("Invalid expected type"); } + } - private void validateRemainingRecordFields(StateMachine sm) { - if (sm.restType == null) { - for (Field field : sm.fieldHierarchy.values()) { - if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); - } + private static void validateTupleTypes(TupleType tupleType, Type restType, int currentSize) { + if (restType != null && tupleType.getTupleTypes().size() > currentSize) { + // TODO: Can remove using fillers + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, currentSize); + } + } + + private static void validateRemainingRecordFields(StateMachine sm) { + if (sm.restType == null) { + for (Field field : sm.fieldHierarchy.values()) { + if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); } } } + } - private void addHeader(StateMachine sm) throws CsvParserException { - String value = sm.value(); - if (sm.expectedArrayElementType instanceof RecordType) { - Field field = sm.fieldHierarchy.get(value); - if (field != null) { - sm.fieldNames.put(value, field); - sm.fieldHierarchy.remove(value); - } + private static void addHeader(StateMachine sm) throws CsvParserException { + String value = sm.value(); + if (sm.expectedArrayElementType instanceof RecordType) { + Field field = sm.fieldHierarchy.get(value); + if (field != null) { + sm.fieldNames.put(value, field); + sm.fieldHierarchy.remove(value); } - sm.headers.add(value); } + sm.headers.add(value); } private static class HeaderEndState implements State { @@ -432,15 +452,23 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } } else if (!sm.insideComment && ch == separator) { addRowValue(sm); + } else if (!sm.insideComment && ch == sm.config.textEnclosure) { + state = STRING_QUOTE_CHAR_STATE; + break; + } else if (!sm.insideComment && ch == sm.config.escapeChar) { + state = STRING_ESCAPE_VALUE_STATE; + break; } else if (sm.insideComment && sm.isNewLineOrEof(ch)) { sm.insideComment = false; if (ch == EOF) { state = ROW_END_STATE; + break; } } else if (isEndOfTheRowAndValueIsNotEmpty(sm, ch)) { handleEndOfTheRow(sm, ch); if (ch == EOF) { state = ROW_END_STATE; + break; } } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { // ignore @@ -453,124 +481,124 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.index = i + 1; return state; } + } - private void handleEndOfTheRow(StateMachine sm, char ch) throws CsvParserException { + private static void handleEndOfTheRow(StateMachine sm, char ch) throws CsvParserException { // if (sm.peek().isBlank()) { // updateLineAndColumnIndexesWithoutRowIndexes(sm); // } else { - handleCsvRow(sm); - checkOptionalFieldsAndLogError(sm.fieldHierarchy); + handleCsvRow(sm); + checkOptionalFieldsAndLogError(sm.fieldHierarchy); // } - } + } - private void handleCsvRow(StateMachine sm) throws CsvParserException { - if (!sm.peek().isBlank()) { - addRowValue(sm); - } - if (!sm.isCurrentCsvNodeEmpty) { - finalizeTheRow(sm); - } else { - updateLineAndColumnIndexesWithoutRowIndexes(sm); - } - updateLineAndColumnIndexes(sm); + private static void handleCsvRow(StateMachine sm) throws CsvParserException { + if (!sm.peek().isBlank()) { + addRowValue(sm); } - - private void updateLineAndColumnIndexes(StateMachine sm) { - sm.rowIndex++; + if (!sm.isCurrentCsvNodeEmpty) { + finalizeTheRow(sm); + } else { updateLineAndColumnIndexesWithoutRowIndexes(sm); } + updateLineAndColumnIndexes(sm); + } - private void updateLineAndColumnIndexesWithoutRowIndexes(StateMachine sm) { - sm.lineNumber++; - sm.currentCsvNode = null; - sm.isCurrentCsvNodeEmpty = true; - sm.columnIndex = 0; - } + private static void updateLineAndColumnIndexes(StateMachine sm) { + sm.rowIndex++; + updateLineAndColumnIndexesWithoutRowIndexes(sm); + } - private boolean ignoreRow(long[] skipLines, int lineNumber) { - for (long skipLine: skipLines) { - if (skipLine == lineNumber) { - return true; - } + private static void updateLineAndColumnIndexesWithoutRowIndexes(StateMachine sm) { + sm.lineNumber++; + sm.currentCsvNode = null; + sm.isCurrentCsvNodeEmpty = true; + sm.columnIndex = 0; + } + + private static boolean ignoreRow(long[] skipLines, int lineNumber) { + for (long skipLine: skipLines) { + if (skipLine == lineNumber) { + return true; } - return false; } + return false; + } - private void initiateNewRowType(StateMachine sm) { - sm.currentCsvNode = CsvCreator.initRowValue(sm.expectedArrayElementType); - } + private static void initiateNewRowType(StateMachine sm) { + sm.currentCsvNode = CsvCreator.initRowValue(sm.expectedArrayElementType); + } - private void finalizeTheRow(StateMachine sm) { - int rootArraySize = sm.rootArrayType.getSize(); - if (rootArraySize == -1 || sm.rowIndex < rootArraySize) { - sm.rootCsvNode.append(sm.currentCsvNode); - } + private static void finalizeTheRow(StateMachine sm) { + int rootArraySize = sm.rootArrayType.getSize(); + if (rootArraySize == -1 || sm.rowIndex < rootArraySize) { + sm.rootCsvNode.append(sm.currentCsvNode); } + } - private void addRowValue(StateMachine sm) throws CsvParserException { - // TODO: Can convert all at once by storing in a Object[] - Type type; - Type exptype = sm.expectedArrayElementType; - String value = sm.value(); - - if (exptype instanceof RecordType) { - type = getExpectedRowTypeOfRecord(sm); - } else if (exptype instanceof MapType) { - type = ((MapType) exptype).getConstrainedType(); - } else if (exptype instanceof ArrayType) { - type = getExpectedRowTypeOfArray(sm, (ArrayType) exptype); - } else if (exptype instanceof TupleType) { - type = getExpectedRowTypeOfTuple(sm, (TupleType) exptype); - } else { - throw new CsvParserException("Unexpected expected type"); - } - - if (type != null) { - CsvCreator.convertAndUpdateCurrentJsonNode(sm, - StringUtils.fromString(value), type, sm.config, exptype); - } - sm.columnIndex++; + private static void addRowValue(StateMachine sm) throws CsvParserException { + // TODO: Can convert all at once by storing in a Object[] + Type type; + Type exptype = sm.expectedArrayElementType; + String value = sm.value(); + + if (exptype instanceof RecordType) { + type = getExpectedRowTypeOfRecord(sm); + } else if (exptype instanceof MapType) { + type = ((MapType) exptype).getConstrainedType(); + } else if (exptype instanceof ArrayType) { + type = getExpectedRowTypeOfArray(sm, (ArrayType) exptype); + } else if (exptype instanceof TupleType) { + type = getExpectedRowTypeOfTuple(sm, (TupleType) exptype); + } else { + throw new CsvParserException("Unexpected expected type"); } - private Type getExpectedRowTypeOfTuple(StateMachine sm, TupleType tupleType) { - List tupleTypes = tupleType.getTupleTypes(); - if (tupleTypes.size() > sm.columnIndex) { - return tupleTypes.get(sm.columnIndex); - } else { - Type restType = sm.restType; - if (restType != null) { - return restType; - } else { - sm.charBuffIndex = 0; - return null; - } - } + if (type != null) { + CsvCreator.convertAndUpdateCurrentJsonNode(sm, + StringUtils.fromString(value), type, sm.config, exptype); } + sm.columnIndex++; + } - private Type getExpectedRowTypeOfArray(StateMachine sm, ArrayType arrayType) { - // TODO: add to a constant - if (arrayType.getSize() != -1 && arrayType.getSize() < sm.columnIndex) { + private static Type getExpectedRowTypeOfTuple(StateMachine sm, TupleType tupleType) { + List tupleTypes = tupleType.getTupleTypes(); + if (tupleTypes.size() > sm.columnIndex) { + return tupleTypes.get(sm.columnIndex); + } else { + Type restType = sm.restType; + if (restType != null) { + return restType; + } else { sm.charBuffIndex = 0; return null; } - return arrayType.getElementType(); } + } + + private static Type getExpectedRowTypeOfArray(StateMachine sm, ArrayType arrayType) { + // TODO: add to a constant + if (arrayType.getSize() != -1 && arrayType.getSize() < sm.columnIndex) { + sm.charBuffIndex = 0; + return null; + } + return arrayType.getElementType(); + } - private Type getExpectedRowTypeOfRecord(StateMachine sm) { - // TODO: These can be make as module level variables - String header = CsvCreator.getHeaderValueForColumnIndex(sm); - Map fields = sm.fieldNames; - if (fields.containsKey(header)) { - //TODO: Optimize - return fields.get(header).getFieldType(); + private static Type getExpectedRowTypeOfRecord(StateMachine sm) { + // TODO: These can be make as module level variables + String header = CsvCreator.getHeaderValueForColumnIndex(sm); + Map fields = sm.fieldNames; + if (fields.containsKey(header)) { + //TODO: Optimize + return fields.get(header).getFieldType(); + } else { + Type restType = sm.restType; + if (restType != null) { + return restType; } else { - Type restType = sm.restType; - if (restType != null) { - return restType; - } else { - sm.charBuffIndex = 0; - return null; - } + sm.charBuffIndex = 0; + return null; } } } @@ -582,30 +610,95 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } } - /** - * Represents the state where an escaped character is processed in a string value. - */ - private static class StringValueEscapedCharacterProcessingState extends EscapedCharacterProcessingState { + private static class StringQuoteValueState implements State { @Override - protected State getSourceState() { - return STRING_VALUE_STATE; + public State transition(StateMachine sm, char[] buff, int i, int count) + throws CsvParserException { + State state = this; + char ch; + for (; i < count; i++) { + ch = buff[i]; + sm.processLocation(ch); + if (ch == sm.config.textEnclosure) { + if (sm.isQuoteClosed) { + sm.append(ch); + continue; + } + sm.isQuoteClosed = true; + } else if (ch == sm.config.delimiter && sm.isQuoteClosed) { + addRowValue(sm); + state = ROW_START_STATE; + sm.isQuoteClosed = false; + break; + } else if (sm.isNewLineOrEof(ch) && sm.isQuoteClosed) { + handleEndOfTheRow(sm, ch); + if (ch == EOF) { + state = ROW_END_STATE; + break; + } + state = ROW_START_STATE; + sm.isQuoteClosed = false; + break; + } else if (ch == sm.config.escapeChar) { + state = STRING_ESCAPE_VALUE_STATE; + sm.isQuoteClosed = false; + break; + } else if (!sm.isQuoteClosed && ch == EOF) { + throw new CsvParserException("unexpected end of csv stream"); + } else { + if (!sm.isQuoteClosed) { + sm.append(ch); + } else { + sm.append(sm.config.textEnclosure); + sm.append(ch); + sm.isQuoteClosed = false; + } + state = this; + } + } + sm.index = i + 1; + return state; } + } + + private static class HeaderQuoteValueState 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) + throws CsvParserException { State state = null; char ch; for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); - if (String.valueOf(ch) == sm.currentEscapeCharacters.peek()) { - sm.currentEscapeCharacters.pop(); - state = ROW_START_STATE; - } else if (ch == EOF) { - throw new CsvParserException("unexpected end of JSON document"); + if (ch == sm.config.textEnclosure) { + sm.isQuoteClosed = true; + } else if (ch == sm.config.delimiter && sm.isQuoteClosed) { + addHeader(sm); + sm.columnIndex++; + sm.isQuoteClosed = false; + state = HEADER_START_STATE; + break; + } else if (sm.isNewLineOrEof(ch) && sm.isQuoteClosed) { + handleEndOfTheHeader(sm); + state = HEADER_END_STATE; + sm.isQuoteClosed = false; + break; + } else if (!sm.isQuoteClosed && ch == sm.config.escapeChar) { + sm.isQuoteClosed = false; + state = HEADER_ESCAPE_CHAR_STATE; + break; + } else if (!sm.isQuoteClosed && ch == EOF) { + throw new CsvParserException("unexpected end of csv stream"); } else { - sm.append(ch); + if (!sm.isQuoteClosed) { + sm.append(ch); + } else { + sm.append(sm.config.textEnclosure); + sm.append(ch); + sm.isQuoteClosed = false; + } state = this; continue; } @@ -614,18 +707,35 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.index = i + 1; return state; } + } + + private static class StringValueUnicodeHexProcessingState extends UnicodeHexProcessingState { + + @Override + protected State getSourceState() { + return STRING_UNICODE_CHAR_STATE; + } } /** - * Represents the state where an escaped character is processed in a field name. + * Represents the state where an escaped unicode character in hex format is processed + * from a field name. */ - private static class HeaderNameEscapedCharacterProcessingState extends EscapedCharacterProcessingState { + private static class HeaderUnicodeHexProcessingState extends UnicodeHexProcessingState { @Override protected State getSourceState() { - return HEADER_NAME_STATE; + return HEADER_UNICODE_CHAR_STATE; } + } + + /** + * Represents the state where an escaped unicode character in hex format is processed. + */ + private abstract static class UnicodeHexProcessingState implements State { + + protected abstract State getSourceState(); @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { @@ -634,26 +744,52 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); - if (String.valueOf(ch) == sm.currentEscapeCharacters.peek()) { - sm.currentEscapeCharacters.pop(); - state = HEADER_START_STATE; - } else if (ch == EOF) { - throw new CsvParserException("unexpected end of JSON document"); - } else { - sm.append(ch); + if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) { + sm.hexBuilder.append(ch); + if (sm.hexBuilder.length() >= 4) { + sm.append(this.extractUnicodeChar(sm)); + this.reset(sm); + state = this.getSourceState(); + break; + } state = this; continue; } + this.reset(sm); + StateMachine.throwExpected("hexadecimal value of an unicode character"); break; } sm.index = i + 1; return state; } + + private void reset(StateMachine sm) { + sm.hexBuilder.setLength(0); + } + + private char extractUnicodeChar(StateMachine sm) { + return StringEscapeUtils.unescapeJava("\\u" + sm.hexBuilder.toString()).charAt(0); + } + + } + + private static class HeaderEscapedCharacterProcessingState extends EscapedCharacterProcessingState { + + @Override + protected State getSourceState() { + return HEADER_ESCAPE_CHAR_STATE; + } + + } + + private static class StringValueEscapedCharacterProcessingState extends EscapedCharacterProcessingState { + + @Override + protected State getSourceState() { + return STRING_ESCAPE_VALUE_STATE; + } } - /** - * Represents the state where an escaped character is processed. - */ private abstract static class EscapedCharacterProcessingState implements State { protected abstract State getSourceState(); @@ -687,8 +823,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C state = this.getSourceState(); break; case 'n': - // TODO: Update this - sm.append('\n'); + sm.append(NEWLINE); state = this.getSourceState(); break; case 'r': @@ -699,6 +834,16 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.append(HZ_TAB); state = this.getSourceState(); break; + case 'u': + if (this.getSourceState() == STRING_ESCAPE_VALUE_STATE) { + state = STRING_UNICODE_CHAR_STATE; + } else if (this.getSourceState() == HEADER_ESCAPE_CHAR_STATE) { + state = HEADER_UNICODE_CHAR_STATE; + } else { + throw new CsvParserException("unknown source '" + this.getSourceState() + + "' in escape char processing state"); + } + break; default: StateMachine.throwExpected("escaped characters"); } @@ -706,7 +851,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.index = i + 1; return state; } - } public static boolean isEndOfTheRowAndValueIsNotEmpty(CsvParser.StateMachine sm, char ch) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 5b5312f..7c83e14 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -25,6 +25,7 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.*; +import io.ballerina.stdlib.data.csvdata.FromString; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; @@ -327,12 +328,13 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Typ return true; } - for (int i = 0; i < this.headers.length; i++) { - if (!this.fieldHierarchy.containsKey(this.headers[i])) { - return false; + for (String key: this.fieldHierarchy.keySet()) { + for(String header: this.headers) { + if (key.equals(header)) { + return true; + } } } - return true; } return false; } @@ -345,7 +347,8 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean } boolean headersMatchWithExpType = checkExpectedTypeMatchWithHeaders(expectedType, csvElement, arraySize); if (!headersMatchWithExpType) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONVERSION_FOR_ARRAY_TO_MAP, csvElement, expectedType); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONVERSION_FOR_ARRAY_TO_MAP, + csvElement, expectedType); } // TODO: Add headers from config addValuesToMapType(csvElement, arraySize, mappingType, expectedType); @@ -465,7 +468,7 @@ private void addRestField(Type restFieldType, BString key, Object csvMember) { case TypeTags.STRING_TAG: if (checkTypeCompatibility(restFieldType, csvMember)) { ((BMap) currentCsvNode) - .put(key, convertToBasicType(csvMember, restFieldType, config)); + .put(key, convertToBasicType(csvMember, restFieldType, config)); } break; case TypeTags.UNION_TAG: diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index 276c25a..3a19ff4 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -118,7 +118,7 @@ public static Object parseStreamToList(Environment env, BStream csv, public static Object parseRecordAsRecordType(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvConfig.createToRecordOptions(options), type.getDescribingType()); + return CsvTraversal.traverse(csv, CsvConfig.createOptions(options), type.getDescribingType()); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index a72b636..96f8097 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -6,6 +6,7 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.*; +import io.ballerina.stdlib.data.csvdata.FromString; import java.util.Arrays; import java.util.Map; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index e2f1d03..6fb22fe 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -46,7 +46,8 @@ public enum DiagnosticErrorCode { INVALID_VALUE_FOR_SKIPLINES( "BDE_0019", "invalid.value.for.skiplines"), INVALID_CUSTOM_HEADER("BDE_0020", "invalid.custom.header"), INVALID_CUSTOM_HEADER_LENGTH("BDE_0021", "invalid.custom.header.length"), - INVALID_HEADER_NAMES_LENGTH("BDE_0022", "invalid.header.names.length"); + INVALID_HEADER_NAMES_LENGTH("BDE_0022", "invalid.header.names.length"), + HEADER_CANNOT_BE_EMPTY("BDE_0023", "header.cannot.be.empty"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index 0179367..446be5d 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -86,3 +86,6 @@ error.invalid.custom.header.length=\ error.invalid.header.names.length=\ Invalid length for the header names + +error.header.cannot.be.empty=\ + The provided header row is empty From 090aec4ace0521017c0627af5a47e73926fcf39c Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 10 Jun 2024 06:44:20 +0530 Subject: [PATCH 029/147] Add tests for escape characters and delimiters --- .../user_config_with_parser_options_test.bal | 347 ++++++++++++------ .../stdlib/data/csvdata/csv/CsvParser.java | 10 +- 2 files changed, 231 insertions(+), 126 deletions(-) diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index d5820b7..cc768cd 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -5,7 +5,27 @@ boolean enable = true; @test:Config {enable: !enable} function debugTest() returns error? { + string csvValue1 = string ` + "a", b, c + 1, "2a\t", "3b\n" + "1c\n", 2, 3 + 1, "2a\"", 3 + + "1a\\", "2b\\"", "3"`; + + string csvValue2 = string ` + "a\"", "\tb\t\n", c + 1, "2a\t", "3b\n" + "1c\n", "/2/", 3 + 1, "2a\"", "3" + + "1a\\", "2b\\"", "3"`; + record {}[]|CsvConversionError cn = parseStringToRecord(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 {}[]|CsvConversionError cn2 = parseStringToRecord(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}]); } @test:Config {enable} @@ -17,14 +37,14 @@ function testFromCsvStringWithParserOptions() { [5, "string5", true, 3, 3.0, "()"] ]); - record{int a; string b; boolean c;decimal d; float e; string f;}[]|CsvConversionError csv1op3_2 = parseStringToRecord(csvStringData1, ptOption1); + record {int a; string b; boolean c; decimal d; float e; string f;}[]|CsvConversionError csv1op3_2 = parseStringToRecord(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: "()"} ]); - record{int a; string b; boolean c;decimal d; float e; string f;}[]|CsvConversionError csv1op3_3 = parseStringToRecord(csvStringData1, ptOption2); + record {int a; string b; boolean c; decimal d; float e; string f;}[]|CsvConversionError csv1op3_3 = parseStringToRecord(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: "()"} @@ -33,10 +53,10 @@ function testFromCsvStringWithParserOptions() { [int, string, boolean, decimal, float, string][]|CsvConversionError csv2op4 = parseStringToList(csvStringData2, option4); test:assertEquals(csv2op4, []); - record{}[]|CsvConversionError csv2op4_2 = parseStringToRecord(csvStringData2, ptOption3); + record {}[]|CsvConversionError csv2op4_2 = parseStringToRecord(csvStringData2, ptOption3); test:assertEquals(csv2op4_2, []); - record{}[]|CsvConversionError csv2op4_3 = parseStringToRecord(csvStringData2, ptOption4); + record {}[]|CsvConversionError csv2op4_3 = parseStringToRecord(csvStringData2, ptOption4); test:assertEquals(csv2op4_3, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, {a: 3, b: "string3", c: 0, d: 1.23, e: 1.23, f: "()"}, @@ -50,20 +70,20 @@ function testFromCsvStringWithParserOptions() { [5, "string5", true, 3, 3.0, "()"] ]); - record{}[]|CsvConversionError csv3op3_2 = parseStringToRecord(csvStringData3, ptOption1); + record {}[]|CsvConversionError csv3op3_2 = parseStringToRecord(csvStringData3, ptOption1); test:assertEquals(csv3op3_2, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, {a: 3, b: "string3", c: 0, d: 1.23, e: 1.23, f: "()"}, {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} ]); - record{}[]|CsvConversionError csv3op3_3 = parseStringToRecord(csvStringData3, ptOption2); + record {}[]|CsvConversionError csv3op3_3 = parseStringToRecord(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: "()"} ]); - record{}[]|CsvConversionError csv3op3_4 = parseStringToRecord(csvStringData3, {header: 9, skipLines: "2-10"}); + record {}[]|CsvConversionError csv3op3_4 = parseStringToRecord(csvStringData3, {header: 9, skipLines: "2-10"}); test:assertEquals(csv3op3_4, [ {'4: 5, string4: "string5", '1: true, "-6.51": 3, "()": null} ]); @@ -73,9 +93,9 @@ function testFromCsvStringWithParserOptions() { function testFromCsvStringWithHeaderLessParserOptions() { [int, string, boolean, decimal, float, ()][]|CsvConversionError csv1op6 = parseStringToList(csvStringData1, option6); test:assertTrue(csv1op6 is CsvConversionError); - test:assertEquals(( csv1op6).message(), generateErrorMessageForInvalidCast("null", "()")); + test:assertEquals((csv1op6).message(), generateErrorMessageForInvalidCast("null", "()")); - record{}[]|CsvConversionError csv1op5_2 = parseStringToRecord(csvStringData1, ptOption5); + record {}[]|CsvConversionError csv1op5_2 = parseStringToRecord(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: ()}, @@ -83,7 +103,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record{}[]|CsvConversionError csv1op6_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [3, 5]}); + record {}[]|CsvConversionError csv1op6_2 = parseStringToRecord(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: ()}, @@ -91,35 +111,35 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record{}[]|CsvConversionError csv3op6_2 = parseStringToRecord(csvStringData3, {header: false, skipLines: [1, 3, 5, -1 , 100, 100]}); + record {}[]|CsvConversionError csv3op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record{}[]|CsvConversionError csv4op6_2 = parseStringToRecord(csvStringData4, {header: false, skipLines: [2, 4, -1 , 100, 100]}); + record {}[]|CsvConversionError csv4op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record{}[]|CsvConversionError csv5op6_2 = parseStringToRecord(csvStringData5, {header: false, skipLines: [2, 4, -1 , 100, 100]}); + record {}[]|CsvConversionError csv5op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record{}[]|CsvConversionError csv6op6_2 = parseStringToRecord(csvStringData6, {header: false, skipLines: [2, 4, -1 , 100, 100]}); + record {}[]|CsvConversionError csv6op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '6: ()}, {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record{}[]|CsvConversionError csv2op6_2 = parseStringToRecord(csvStringData2, {header: false, skipLines: [5, 7]}); + record {}[]|CsvConversionError csv2op6_2 = parseStringToRecord(csvStringData2, {header: false, skipLines: [5, 7]}); test:assertEquals(csv2op6_2, [ {'1: "hello", '2: "hello", '3: (), '4: 12, '5: true, '6: 12.34}, {'1: "//comment"}, @@ -132,7 +152,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { @test:Config {enable} function testHeaderOption() { - record{}[]|CsvConversionError csv2cop1 = parseStringToRecord(csvStringData2, {header: 4}); + record {}[]|CsvConversionError csv2cop1 = parseStringToRecord(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: ()}, @@ -141,18 +161,18 @@ function testHeaderOption() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - record{}[]|CsvConversionError csv2cop2 = parseStringToRecord(csvStringData2, {header: 100}); + record {}[]|CsvConversionError csv2cop2 = parseStringToRecord(csvStringData2, {header: 100}); test:assertEquals(csv2cop2, []); - record{}[]|CsvConversionError csv2cop3 = parseStringToRecord(csvStringData2, {header: 11}); + record {}[]|CsvConversionError csv2cop3 = parseStringToRecord(csvStringData2, {header: 11}); test:assertEquals(csv2cop3, []); - record{}[]|CsvConversionError csv2cop4 = parseStringToRecord(csvStringData2, {header: 10}); + record {}[]|CsvConversionError csv2cop4 = parseStringToRecord(csvStringData2, {header: 10}); test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", '1: true, "-6.51": 3, "()": ()}]); - record{}[]|CsvConversionError csv1cop5 = parseStringToRecord(csvStringData1, {}); + record {}[]|CsvConversionError csv1cop5 = parseStringToRecord(csvStringData1, {}); test:assertTrue(csv1cop5 is CsvConversionError); - test:assertEquals(( csv1cop5).message(), "The provided header row is empty"); + test:assertEquals((csv1cop5).message(), "The provided header row is empty"); } @test:Config {enable} @@ -168,7 +188,7 @@ function testNullConfigOption() { string csvValue5 = string `b, a bN/Aa,N/A`; - record{() a;}[]|CsvConversionError cn = parseStringToRecord(csvValue1, {nilValue: ()}); + record {() a;}[]|CsvConversionError cn = parseStringToRecord(csvValue1, {nilValue: ()}); test:assertEquals(cn, [{a: ()}]); cn = parseStringToRecord(csvValue2, {nilValue: ()}); @@ -176,11 +196,11 @@ function testNullConfigOption() { cn = parseStringToRecord(csvValue3, {nilValue: ()}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("e", "()")); + test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("e", "()")); cn = parseStringToRecord(csvValue4, {nilValue: ()}); test:assertEquals(cn, [{a: ()}]); - + cn = parseStringToRecord(csvValue1, {nilValue: null}); test:assertEquals(cn, [{a: ()}]); @@ -189,7 +209,7 @@ function testNullConfigOption() { cn = parseStringToRecord(csvValue3, {nilValue: null}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("e", "()")); + test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("e", "()")); cn = parseStringToRecord(csvValue4, {nilValue: null}); test:assertEquals(cn, [{a: ()}]); @@ -199,15 +219,15 @@ function testNullConfigOption() { cn = parseStringToRecord(csvValue2, {nilValue: "()"}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("null", "()")); + test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("null", "()")); cn = parseStringToRecord(csvValue3, {nilValue: "()"}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("e", "()")); + test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("e", "()")); cn = parseStringToRecord(csvValue4, {nilValue: "()"}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("Null", "()")); + test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("Null", "()")); cn = parseStringToRecord(csvValue5, {nilValue: "N/A"}); test:assertEquals(cn, [{b: "bN/Aa", a: ()}]); @@ -217,11 +237,13 @@ function testNullConfigOption() { cn = parseStringToRecord(csvValue4, {nilValue: "null"}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("Null", "()")); + test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("Null", "()")); cn = parseStringToRecord(csvValue1, {nilValue: "null"}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("()", "()")); + test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("()", "()")); + + // TODO: add nilValue -> "", with str quotes } @test:Config {enable} @@ -251,8 +273,8 @@ function testCommentConfigOption() { 1 ,#2 # comment # comment`; - record{int a;}[]|CsvConversionError cn; - + record {int a;}[]|CsvConversionError cn; + cn = parseStringToRecord(csvValue1); test:assertEquals(cn, [{a: 1}]); @@ -312,24 +334,24 @@ function testCommentConfigOption2() { & comment`; - record{int a; int b;}[]|CsvConversionError cn; - record{int c;}[]|CsvConversionError cn2; + record {int a; int b;}[]|CsvConversionError cn; + record {int c;}[]|CsvConversionError cn2; cn = parseStringToRecord(csvValue1, {comment: "&"}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); cn = parseStringToRecord(csvValue2, {comment: "&"}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); cn = parseStringToRecord(csvValue3, {comment: "&"}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); cn = parseStringToRecord(csvValue4, {comment: "&"}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); cn = parseStringToRecord(csvValue5, {comment: "&"}); test:assertTrue(cn is CsvConversionError); @@ -338,23 +360,23 @@ function testCommentConfigOption2() { cn = parseStringToRecord(csvValue6, {comment: "&", header: 2}); test:assertTrue(cn is CsvConversionError); - test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); cn2 = parseStringToRecord(csvValue1, {comment: "&"}); test:assertTrue(cn2 is CsvConversionError); - test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); cn2 = parseStringToRecord(csvValue2, {comment: "&"}); test:assertTrue(cn2 is CsvConversionError); - test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); cn2 = parseStringToRecord(csvValue3, {comment: "&"}); test:assertTrue(cn2 is CsvConversionError); - test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); cn2 = parseStringToRecord(csvValue4, {comment: "&"}); test:assertTrue(cn2 is CsvConversionError); - test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); cn2 = parseStringToRecord(csvValue5, {comment: "&"}); test:assertTrue(cn2 is CsvConversionError); @@ -363,7 +385,7 @@ function testCommentConfigOption2() { cn2 = parseStringToRecord(csvValue6, {header: 2, comment: "&"}); test:assertTrue(cn2 is CsvConversionError); - test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); } @test:Config {enable} @@ -483,70 +505,70 @@ function testCustomHeaderOption() { anydata[][]|CsvConversionError bm2ba = parseRecordAsListType([bm2, bm2], ["b1", "n1", "b2", "n2", "b3"], {}); test:assertTrue(bm2ba is CsvConversionError); - test:assertEquals(( bm2ba).message(), generateErrorMessageForInvalidCustomHeader("n2")); + test:assertEquals((bm2ba).message(), generateErrorMessageForInvalidCustomHeader("n2")); anydata[][]|CsvConversionError bm3ba = parseRecordAsListType([bm3, bm3], ["b1", "b4", "b2", "n2", "i1"], {}); test:assertTrue(bm3ba is CsvConversionError); - test:assertEquals(( bm3ba).message(), generateErrorMessageForInvalidCustomHeader("n2")); + test:assertEquals((bm3ba).message(), generateErrorMessageForInvalidCustomHeader("n2")); anydata[][]|CsvConversionError bm3ba2 = parseRecordAsListType([bm3, bm3], ["b1", "b3", "b4", "b2", "i2"], {}); test:assertTrue(bm3ba2 is CsvConversionError); - test:assertEquals(( bm3ba2).message(), generateErrorMessageForInvalidCustomHeader("i2")); + test:assertEquals((bm3ba2).message(), generateErrorMessageForInvalidCustomHeader("i2")); [boolean...][]|CsvConversionError bm3ba4 = parseRecordAsListType([bm3, bm3], ["n2"], {}); test:assertTrue(bm3ba4 is CsvConversionError); - test:assertEquals(( bm3ba4).message(), "Invalid length for the header names"); + test:assertEquals((bm3ba4).message(), "Invalid length for the header names"); [boolean...][]|CsvConversionError bm3ba5 = parseRecordAsListType([bm3, bm3], [], {}); test:assertTrue(bm3ba5 is CsvConversionError); - test:assertEquals(( bm3ba5).message(), "Invalid length for the header names"); + test:assertEquals((bm3ba5).message(), "Invalid length for the header names"); // ------------------------------------------------------------- - record{}[]|CsvConversionError ct1br = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); + record {}[]|CsvConversionError ct1br = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); test:assertTrue(ct1br is CsvConversionError); - test:assertEquals(( ct1br).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br).message(), "Invalid length for the custom headers"); - record{}[]|CsvConversionError ct1br2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); + record {}[]|CsvConversionError ct1br2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); test:assertTrue(ct1br2 is CsvConversionError); - test:assertEquals(( ct1br2).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br2).message(), "Invalid length for the custom headers"); - record{}[]|CsvConversionError ct1br2_2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); + record {}[]|CsvConversionError ct1br2_2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); test:assertTrue(ct1br2_2 is CsvConversionError); - test:assertEquals(( ct1br2_2).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br2_2).message(), "Invalid length for the custom headers"); - record{}[]|CsvConversionError ct1br3 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], [], {}); + record {}[]|CsvConversionError ct1br3 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], [], {}); test:assertTrue(ct1br3 is CsvConversionError); - test:assertEquals(( ct1br3).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br3).message(), "Invalid length for the custom headers"); - record{|string a; string b; string c;|}[]|CsvConversionError ct1br5 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + record {|string a; string b; string c;|}[]|CsvConversionError ct1br5 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); test:assertTrue(ct1br5 is CsvConversionError); // TODO: Fix - test:assertEquals(( ct1br5).message(), generateErrorMessageForMissingRequiredField("c")); + test:assertEquals((ct1br5).message(), generateErrorMessageForMissingRequiredField("c")); - record{string a; string b; string c;}[]|CsvConversionError ct1br6 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + record {string a; string b; string c;}[]|CsvConversionError ct1br6 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); test:assertTrue(ct1br6 is CsvConversionError); - test:assertEquals(( ct1br6).message(), generateErrorMessageForMissingRequiredField("c")); + test:assertEquals((ct1br6).message(), generateErrorMessageForMissingRequiredField("c")); - record{string a; string b;}[]|CsvConversionError ct1br7 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); - test:assertEquals(ct1br7, [ + record {string a; string b;}[]|CsvConversionError ct1br7 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + test:assertEquals(ct1br7, [ {a: "a", e: "1", b: "true"}, {a: "a", e: "1", b: "true"} ]); - record{|string a; string b;|}[]|CsvConversionError ct1br8 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + record {|string a; string b;|}[]|CsvConversionError ct1br8 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); test:assertEquals(ct1br8, [ {a: "a", b: "true"}, {a: "a", b: "true"} ]); - record{|string...;|}[]|CsvConversionError ct1br9 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + record {|string...;|}[]|CsvConversionError ct1br9 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); test:assertEquals(ct1br9, [ {a: "a", b: "true", e: "1"}, {a: "a", b: "true", e: "1"} ]); - record{|string...;|}[]|CsvConversionError ct1br10 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), {}); + record {|string...;|}[]|CsvConversionError ct1br10 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), {}); test:assertEquals(ct1br10, [ {'1: "a", '3: "true", '2: "1"}, {'1: "a", '3: "true", '2: "1"} @@ -558,24 +580,24 @@ function testCustomHeaderParserOption2() { // parseStringToRecord // parseRecordAsRecordType - record{}[]|CsvConversionError ct1br = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); + record {}[]|CsvConversionError ct1br = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); test:assertTrue(ct1br is CsvConversionError); - test:assertEquals(( ct1br).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br).message(), "Invalid length for the custom headers"); // record{}[]|CsvConversionError ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b", "aa", "aaa", "aaaaa", "bb", "ccc"]}); // // TODO: Fix this // test:assertTrue(ct1br2 is CsvConversionError); // test:assertEquals(( ct1br2).message(), "Invalid length for the custom headers"); - record{}[]|CsvConversionError ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: []}); + record {}[]|CsvConversionError ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: []}); test:assertTrue(ct1br2 is CsvConversionError); - test:assertEquals(( ct1br2).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br2).message(), "Invalid length for the custom headers"); - record{int a; string b; boolean c; decimal d; float e; () f;}[]|CsvConversionError ct1br3 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); + record {int a; string b; boolean c; decimal d; float e; () f;}[]|CsvConversionError ct1br3 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); test:assertTrue(ct1br3 is CsvConversionError); - test:assertEquals(( ct1br3).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br3).message(), "Invalid length for the custom headers"); - record{int a; string b; boolean c; decimal d; float e; () f;}[]|CsvConversionError ct1br4 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b", "c", "d", "e", "f"]}); + record {int a; string b; boolean c; decimal d; float e; () f;}[]|CsvConversionError ct1br4 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["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: ()}, @@ -584,7 +606,7 @@ function testCustomHeaderParserOption2() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - record{() a; float b; decimal c; boolean d; string e; int f;}[]|CsvConversionError ct1br5 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f", "e", "d", "c", "b", "a"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|CsvConversionError ct1br5 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["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: ()}, @@ -593,7 +615,7 @@ function testCustomHeaderParserOption2() { {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} ]); - record{() a; float b; decimal c; boolean d; string e; int f;}[]|CsvConversionError ct1br5_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f", "e", "d", "c", "b", "a"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|CsvConversionError ct1br5_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["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: ()}, @@ -602,7 +624,7 @@ function testCustomHeaderParserOption2() { {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} ]); - record{() a; float b; decimal c; boolean d; string e; int f;}[]|CsvConversionError ct1br5_3 = parseStringToRecord(csvStringData1, {skipLines: [1], customHeaders: ["f", "e", "d", "c", "b", "a"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|CsvConversionError ct1br5_3 = parseStringToRecord(csvStringData1, {skipLines: [1], customHeaders: ["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: ()}, @@ -611,7 +633,7 @@ function testCustomHeaderParserOption2() { {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} ]); - record{|() a1; float b1; decimal c1; boolean d1; string e1; int f1;|}[]|CsvConversionError ct1br6 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|() a1; float b1; decimal c1; boolean d1; string e1; int f1;|}[]|CsvConversionError ct1br6 = 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: ()}, @@ -620,7 +642,7 @@ function testCustomHeaderParserOption2() { {f1: 5, e1: "string5", d1: true, c1: 3, b1: 3, a1: ()} ]); - record{|boolean d1; string e1;|}[]|CsvConversionError ct1br7 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|CsvConversionError ct1br7 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -629,7 +651,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record{|boolean d1; string e1;|}[]|CsvConversionError ct1br7_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|CsvConversionError ct1br7_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7_2, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -638,50 +660,50 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record{|boolean d1; string e1;|}[]|CsvConversionError ct1br8 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); + record {|boolean d1; string e1;|}[]|CsvConversionError ct1br8 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); // TODO: Fix test:assertTrue(ct1br8 is CsvConversionError); - test:assertEquals(( ct1br8).message(), generateErrorMessageForInvalidCast("string1", "boolean")); + test:assertEquals((ct1br8).message(), generateErrorMessageForInvalidCast("string1", "boolean")); - record{|boolean d1; string e1;|}[]|CsvConversionError ct1br9 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|CsvConversionError ct1br9 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["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} + {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;|}[]|CsvConversionError ct1br10 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "f1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|CsvConversionError ct1br10 = 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} + {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;|}[]|CsvConversionError ct1br11 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); + record {|boolean d1; string e1;|}[]|CsvConversionError ct1br11 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); test:assertTrue(ct1br11 is CsvConversionError); - test:assertEquals(( ct1br11).message(), "Invalid length for the custom headers"); + test:assertEquals((ct1br11).message(), "Invalid length for the custom headers"); - record{|string d1; string e1;|}[]|CsvConversionError ct1br12 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|string d1; string e1;|}[]|CsvConversionError ct1br12 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ - {e1: "string1", d1: "true"}, - {e1: "string2", d1: "false"}, - {e1: "string3", d1: "0"}, - {e1: "string4", d1: "1"}, - {e1: "string5", d1: "true"} + {e1: "string1", d1: "true"}, + {e1: "string2", d1: "false"}, + {e1: "string3", d1: "0"}, + {e1: "string4", d1: "1"}, + {e1: "string5", d1: "true"} ]); - record{|string d1; string e1;|}[]|CsvConversionError ct1br13 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); + record {|string d1; string e1;|}[]|CsvConversionError ct1br13 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); test:assertTrue(ct1br13 is CsvConversionError); - test:assertEquals(( ct1br13).message(), generateErrorMessageForMissingRequiredField("d1")); + test:assertEquals((ct1br13).message(), generateErrorMessageForMissingRequiredField("d1")); } @test:Config {enable} function testTextQuotesWithParserOptions() { - string csvValue1 = string ` + string csvValue1 = string ` a, b, c 1, "2", "3" "1", 2, 3 @@ -689,48 +711,62 @@ function testTextQuotesWithParserOptions() { "1", "2", "3"`; - string csvValue2 = string ` + string csvValue2 = string ` a, b, c 1, "2, 3", 3 1, "2, 3",3 4, 5, 6 `; - string csvValue3 = string `a, b, c + string csvValue3 = string `a, b, c "1", ""2"", "3" 4, "5, 6"b" " a "", ""6""`; - string csvValue4 = string `a, b, c + string csvValue4 = string `a, b, c 1, '2', 3 4, '5, '6'7', 8 4, "5", '4, '5"a", ,"," a '6'7'`; - string csvValue5 = string `a, b, c + string csvValue5 = string `a, b, c 1, "2", "3" 1, 2, 3 "1", "2", 3 1, "2", "3" `; - record {}[]|CsvConversionError cn = parseStringToRecord(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}]); + string csvValue6 = string `a, b, c + 1, "2 a ","", "3" + 1, 2, 3 + "1", "2", 3 + 1, "2", "3" + `; - record {}[]|CsvConversionError cn2 = parseStringToRecord(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 {int a;}[]|CsvConversionError cn = parseStringToRecord(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 {}[]|CsvConversionError cn3 = parseStringToRecord(csvValue3, {}); - test:assertEquals(cn3, [{"a":1,"b":"\"2\"","c":3}, {"a":4,"b":"5, 6\"b\" \" a \"", c:"\"6\""}]); + record {|int c; string...;|}[]|CsvConversionError cn2 = parseStringToRecord(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;|}[]|CsvConversionError cn3 = parseStringToRecord(csvValue3, {}); + test:assertEquals(cn3, [{"b": "\"2\"", "c": "3"}, {"b": "5, 6\"b\" \" a \"", c: "\"6\""}]); record {}[]|CsvConversionError cn4 = parseStringToRecord(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"}]); + 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[][]|CsvConversionError cn4_2 = parseStringToList(csvValue4, {textEnclosure: "'"}); + test:assertEquals(cn4_2, [[1, 2, 3], [4, "5, '6'7", 8], [4, "\"5\"", "4, '5\"a\", ,\",\" a '6'7"]]); record {}[]|CsvConversionError cn5 = parseStringToRecord(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 {}[]|CsvConversionError cn6 = parseStringToRecord(csvValue6, {}); + test:assertTrue(cn6 is CsvConversionError); + test:assertEquals((cn6).message(), "Invalid length for the custom headers"); } @test:Config {enable} function testHeaderQuotesWithParserOptions() { - string csvValue1 = string ` + string csvValue1 = string ` "a", b, c 1, "2", "3" "1", 2, 3 @@ -738,24 +774,93 @@ function testHeaderQuotesWithParserOptions() { "1", "2", "3"`; - string csvValue2 = string ` + string csvValue2 = string ` "a, b, c", "b,c", "c,d" 1, "2, 3", 3 1, "2, 3",3 4, 5, 6 `; - string csvValue3 = string `'a '1'a5,6', 'b", " ","""', c + string csvValue3 = string `'a '1'a5,6', 'b", " ","""', c 1, '2', 3 4, '5, '6'7', 8 4, "5", '4, '5"a", ,"," a '6'7'`; record {}[]|CsvConversionError cn = parseStringToRecord(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}]); + 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 {}[]|CsvConversionError cn2 = parseStringToRecord(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}]); + 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[][]|CsvConversionError cn2_2 = parseStringToList(csvValue2, {header: 1}); + test:assertEquals(cn2_2, [[1, "2, 3", 3], [1, "2, 3", 3], [4, 5, 6]]); record {}[]|CsvConversionError cn3 = parseStringToRecord(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"}]); + 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"}]); +} + +@test:Config {enable} +function testEscapeCharactersWithParserOptions() { + string csvValue1 = string ` + "a", b, c + 1, "2a\t", "3b\n" + "1c\n", 2, 3 + 1, "2a\"", 3 + + "1a\\", "2b\\"", "3"`; + + string csvValue2 = string ` + "a\"", "\tb\t\n", c + 1, "2a\t", "3b\n" + "1c\n", "/2/", 3 + 1, "2a\"", "3" + + "1a\\", "2b\\"", "3"`; + + string csvValue3 = string ` + "a", b, c + 1, "2\t", "3\n" + "1\n", 2, 3 + 1, "2\"", 3 + + "1\\", "2\\"", "3"`; + + record {}[]|CsvConversionError cn = parseStringToRecord(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 {}[]|CsvConversionError cn2 = parseStringToRecord(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 {}[]|CsvConversionError cn3 = parseStringToRecord(csvValue3, {header: 1}); + test:assertEquals(cn3, [{"a": 1, "b": 2.0, "c": 3.0}, {"a": 1.0, "b": 2, "c": 3}, {"a": 1, "b": "2\"", "c": 3}, {"a": "1\\", "b": "2\\\"", "c": 3}]); + + anydata[][]|CsvConversionError cn_2 = parseStringToList(csvValue1, {header: 1}); + test:assertEquals(cn_2, [[1, "2a\t", "3b\n"], ["1c\n", 2, 3], [1, "2a\"", 3], ["1a\\", "2b\\\"", 3]]); + + anydata[][]|CsvConversionError cn2_2 = parseStringToList(csvValue2, {header: 1}); + test:assertEquals(cn2_2, [[1, "2a\t", "3b\n"], ["1c\n", "/2/", 3], [1, "2a\"", 3], ["1a\\", "2b\\\"", 3]]); + + anydata[][]|CsvConversionError cn3_2 = parseStringToList(csvValue3, {header: 1}); + test:assertEquals(cn3_2, [[1, 2.0, 3.0], [1.0, 2, 3], [1, "2\"", 3], ["1\\", "2\\\"", 3]]); +} + +@test:Config {enable} +function testDelimiterWithParserOptions() { + record {}[]|CsvConversionError cn = parseStringToRecord(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[][]|CsvConversionError cn2 = parseStringToList(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, ()] + ]); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 63a1fbe..70c34f8 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -667,7 +667,7 @@ private static class HeaderQuoteValueState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - State state = null; + State state = this; char ch; for (; i < count; i++) { ch = buff[i]; @@ -713,7 +713,7 @@ private static class StringValueUnicodeHexProcessingState extends UnicodeHexProc @Override protected State getSourceState() { - return STRING_UNICODE_CHAR_STATE; + return STRING_QUOTE_CHAR_STATE; } } @@ -726,7 +726,7 @@ private static class HeaderUnicodeHexProcessingState extends UnicodeHexProcessin @Override protected State getSourceState() { - return HEADER_UNICODE_CHAR_STATE; + return HEADER_QUOTE_CHAR_STATE; } } @@ -777,7 +777,7 @@ private static class HeaderEscapedCharacterProcessingState extends EscapedCharac @Override protected State getSourceState() { - return HEADER_ESCAPE_CHAR_STATE; + return HEADER_QUOTE_CHAR_STATE; } } @@ -786,7 +786,7 @@ private static class StringValueEscapedCharacterProcessingState extends EscapedC @Override protected State getSourceState() { - return STRING_ESCAPE_VALUE_STATE; + return STRING_QUOTE_CHAR_STATE; } } From 31f7ab9e447f49469c2aae8fcfad85bebb3fd318 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 10 Jun 2024 07:10:01 +0530 Subject: [PATCH 030/147] Add tests for line terminator --- .../user_config_with_parser_options_test.bal | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index cc768cd..364eba9 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -864,3 +864,26 @@ function testDelimiterWithParserOptions() { [5, "string", true, 2.234, -3.21, ()] ]); } + +@test:Config {enable} +function testLineTerminatorWithParserOptions() { + string csvValue = string `a,b${"\n"} 1,"2\n3"`; + + record {}[]|CsvConversionError cn = parseStringToRecord(csvValue, {header: 0, lineTerminator: LF}); + test:assertEquals(cn, [{a: 1, b: "2\n3"}]); + + cn = parseStringToRecord(csvValue, {header: 0, lineTerminator: [LF]}); + test:assertEquals(cn, [{a: 1, b: "2\n3"}]); + + cn = parseStringToRecord(csvValue, {header: 0, lineTerminator: [CRLF, LF, CR]}); + test:assertEquals(cn, [{a: 1, b: "2\n3"}]); + + anydata[][]|CsvConversionError cn2 = parseStringToList(csvValue, {header: 0, lineTerminator: LF}); + test:assertEquals(cn2, [[1, "2\n3"]]); + + cn2 = parseStringToList(csvValue, {header: 0, lineTerminator: [LF]}); + test:assertEquals(cn2, [[1, "2\n3"]]); + + cn2 = parseStringToList(csvValue, {header: 0, lineTerminator: [CRLF, LF, CR]}); + test:assertEquals(cn2, [[1, "2\n3"]]); +} From 6c4444cf64c10ad877d478266b3caade7ea933d2 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 13 Jun 2024 08:43:26 +0530 Subject: [PATCH 031/147] Add tests for nil config and data projection --- .../tests/user_config_projection_tests.bal | 553 ++++++++++++++++++ .../user_config_with_parser_options_test.bal | 44 +- ballerina/types.bal | 4 +- .../stdlib/data/csvdata/FromString.java | 8 +- .../stdlib/data/csvdata/csv/CsvCreator.java | 17 +- .../stdlib/data/csvdata/csv/CsvParser.java | 58 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 79 ++- .../stdlib/data/csvdata/utils/CsvUtils.java | 27 +- .../csvdata/utils/DiagnosticErrorCode.java | 3 +- native/src/main/resources/error.properties | 3 + 10 files changed, 734 insertions(+), 62 deletions(-) create mode 100644 ballerina/tests/user_config_projection_tests.bal diff --git a/ballerina/tests/user_config_projection_tests.bal b/ballerina/tests/user_config_projection_tests.bal new file mode 100644 index 0000000..f44ac09 --- /dev/null +++ b/ballerina/tests/user_config_projection_tests.bal @@ -0,0 +1,553 @@ +import ballerina/test; + +boolean enable = true; + +@test:Config {enable: !enable} +function debugTest() returns error? { + string csvValue1 = string `a,b + "a",2 + b,4`; + record{}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; + map[] csvValue3 = [{"a": "a", "b": "2"}, {"a": "b", "b": "4"}]; + [string, int][] csvValue4 = [["a", 2], ["b", 4]]; + (string|int)[][] csvValue5 = [["a", 2], ["b", 4]]; + + [string][]|CsvConversionError cn21 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: false + }); + test:assertTrue(cn21 is CsvConversionError); + test:assertEquals((cn21).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); +} + +@test:Config {enable} +function testAbsentAsNilableConfig() returns error? { + record {|int a; int? g; int? h;|}[]|CsvConversionError cn = parseStringToRecord(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?;|}[]|CsvConversionError cn2 = parseStringToRecord(csvStringData1, { + allowDataProjection: {absentAsNilableType: true}, + header: 1, + skipLines: "2-10" + }); + test:assertEquals(cn2, [{a: 1}]); + + record {|int a; int g?;|}[]|CsvConversionError cn3 = parseStringToRecord(csvStringData1, { + allowDataProjection: {absentAsNilableType: true}, + header: 1, + skipLines: "2-10" + }); + test:assertEquals(cn3, [{a: 1}]); + + record {|int a; int g;|}[]|CsvConversionError cn4 = parseStringToRecord(csvStringData1, { + allowDataProjection: {absentAsNilableType: true}, + header: 1, + skipLines: "2-10" + }); + test:assertTrue(cn4 is CsvConversionError); + test:assertEquals((cn4).message(), generateErrorMessageForMissingRequiredField("g")); + + int?[][]|CsvConversionError cn5 = parseStringToList(string ` + a,b,c + 1, 1,1`, { + allowDataProjection: {absentAsNilableType: true}, + header: 1 + }); + test:assertEquals(cn5, [[1, 1, 1]]); + + map[]|CsvConversionError cn6 = parseStringToRecord(string ` + a,b,c + 1, 1,1`, { + allowDataProjection: {absentAsNilableType: true}, + header: 1 + }); + test:assertEquals(cn6, [{a: 1, b: 1, c: 1}]); + + [int, string?, boolean?, decimal?, float?, (), string?][]|CsvConversionError cn7 = parseStringToList(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?][]|CsvConversionError cn8 = parseStringToList(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?][]|CsvConversionError cn9 = parseStringToList(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?][]|CsvConversionError cn10 = parseStringToList(csvStringData1, { + allowDataProjection: {absentAsNilableType: true}, + header: 1, + skipLines: "2-10" + }); + test:assertEquals(cn10, [[1, "string1", true, 2.234, 2.234, null, null]]); +} + +@test:Config {enable} +function testAbsentAsNilableConfig2() returns error? { + record {|int a; int? g; int? h;|}[]|CsvConversionError cn = parseRecordAsRecordType([{"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?;|}[]|CsvConversionError cn2 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + allowDataProjection: {absentAsNilableType: true}, skipLines: [3] + }); + test:assertEquals(cn2, [{a: 1}, {a: 2}]); + + record {|int a; int g?;|}[]|CsvConversionError cn3 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + allowDataProjection: {absentAsNilableType: true}, skipLines: [3] + }); + test:assertEquals(cn3, [{a: 1}, {a: 2}]); + + record {|int a; int g;|}[]|CsvConversionError cn4 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + allowDataProjection: {absentAsNilableType: true}, skipLines: [3] + }); + test:assertTrue(cn4 is CsvConversionError); + test:assertEquals((cn4).message(), generateErrorMessageForMissingRequiredField("g")); + + record {|string a; int? g; int? h;|}[]|CsvConversionError cn5 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + allowDataProjection: {absentAsNilableType: true}, skipLines: [3] + }); + test:assertEquals(cn5, [{a: "a", g: (), h: ()}, {a: "a", g: (), h: ()}]); + + record {|string a; int? g?;|}[]|CsvConversionError cn6 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + allowDataProjection: {absentAsNilableType: true}, skipLines: [3] + }); + test:assertEquals(cn6, [{a: "a"}, {a: "a"}]); + + record {|string a; int g?;|}[]|CsvConversionError cn7 = parseListAsRecordType([["a"], ["a"], ["b"]], ["a"], { + allowDataProjection: {absentAsNilableType: true}, skipLines: [2] + }); + test:assertEquals(cn7, [{a: "a"}, {a: "b"}]); + + record {|string a; int g;|}[]|CsvConversionError cn8 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + allowDataProjection: {absentAsNilableType: true}, skipLines: [3] + }); + test:assertTrue(cn8 is CsvConversionError); + test:assertEquals((cn8).message(), generateErrorMessageForMissingRequiredField("g")); +} + +@test:Config {enable} +function testNilAsOptionalConfig() returns error? { + record {|int a; int f?;|}[]|CsvConversionError cn = parseStringToRecord(csvStringData1, { + allowDataProjection: {nilAsOptionalField: true}, + header: 1 + }); + test:assertEquals(cn, [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]); + + record {|int a; int? f?;|}[]|CsvConversionError cn2 = parseStringToRecord(csvStringData1, { + allowDataProjection: {nilAsOptionalField: true}, + header: 1, + skipLines: "2-10" + }); + test:assertEquals(cn2, [{a: 1, f: ()}]); + + record {|int a; int f?;|}[]|CsvConversionError cn3 = parseStringToRecord(csvStringData1, { + allowDataProjection: {nilAsOptionalField: true}, + header: 1, + skipLines: "2-10" + }); + test:assertEquals(cn3, [{a: 1}]); + + record {|int a; int f;|}[]|CsvConversionError cn4 = parseStringToRecord(csvStringData1, { + allowDataProjection: {nilAsOptionalField: true}, + header: 1, + skipLines: "2-10" + }); + test:assertTrue(cn4 is CsvConversionError); + test:assertEquals((cn4).message(), generateErrorMessageForInvalidCast("()", "int")); + + int?[][]|CsvConversionError cn5 = parseStringToList(string ` + a,b,c + 1, 1,1`, { + allowDataProjection: {nilAsOptionalField: true}, + header: 1 + }); + test:assertEquals(cn5, [[1, 1, 1]]); + + map[]|CsvConversionError cn6 = parseStringToRecord(string ` + a,b,c + 1, 1,1`, { + allowDataProjection: {nilAsOptionalField: true}, + header: 1 + }); + test:assertEquals(cn6, [{a: 1, b: 1, c: 1}]); + + [int, string?, boolean?, decimal?, float?, (), string?][]|CsvConversionError cn7 = parseStringToList(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?][]|CsvConversionError cn8 = parseStringToList(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?][]|CsvConversionError cn9 = parseStringToList(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?][]|CsvConversionError cn10 = parseStringToList(csvStringData1, { + allowDataProjection: {nilAsOptionalField: true}, + header: 1, + skipLines: "2-10" + }); + test:assertEquals(cn10, [[1, "string1", true, 2.234, 2.234, null, null]]); +} + +@test:Config {enable} +function testNilAsOptionalConfig2() returns error? { + record {|int a; int? f;|}[]|CsvConversionError cn = parseRecordAsRecordType([{"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?;|}[]|CsvConversionError cn2 = parseRecordAsRecordType([{"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?;|}[]|CsvConversionError cn3 = parseRecordAsRecordType([{"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;|}[]|CsvConversionError cn4 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] + }); + test:assertTrue(cn4 is CsvConversionError); + test:assertEquals((cn4).message(), generateErrorMessageForInvalidFieldType("null", "f")); + + // TODO: After add string[] => anydata[] + + // record {|string a; int? f;|}[]|CsvConversionError cn5 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + // allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] + // }); + // test:assertEquals(cn5, [{a: "a", f: ()}, {a: "a", f: ()}]); + + // record {|string a; int? f?;|}[]|CsvConversionError cn6 = parseListAsRecordType([["a", ()], ["a", ()], ["a", ()]], ["a", "f"], { + // allowDataProjection: {nilAsOptionalField: true}, skipLines: [3], + // }); + // test:assertEquals(cn6, [{a: "a"}, {a: "a"}]); + + // record {|string a; int f?;|}[]|CsvConversionError cn7 = parseListAsRecordType([["a"], ["a"], ["b"]], ["a"], { + // allowDataProjection: {nilAsOptionalField: true}, skipLines: [2] + // }); + // test:assertEquals(cn7, [{a: "a"}, {a: "b"}]); + + // record {|string a; int f;|}[]|CsvConversionError cn8 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + // allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] + // }); + // test:assertTrue(cn8 is CsvConversionError); + // test:assertEquals((cn8).message(), generateErrorMessageForInvalidCast("()", "int")); +} + +@test:Config {enable} +function testDataProjectionConfig() returns error? { + string csvValue1 = string `a,b + "a",2 + b,4`; + record{}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; + [string, int][] csvValue3 = [["a", 2], ["b", 4]]; + + record{}[]|CsvConversionError cn = parseStringToRecord(csvValue1, { + allowDataProjection: false + }); + test:assertEquals(cn, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); + + record{|string a; int b;|}[]|CsvConversionError cn_2 = parseStringToRecord(csvValue1, { + allowDataProjection: false + }); + test:assertEquals(cn_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); + + record{|string a;|}[]|CsvConversionError cn2 = parseStringToRecord(csvValue1, { + allowDataProjection: false + }); + test:assertTrue(cn2 is CsvConversionError); + test:assertEquals((cn2).message(), "No mapping field in the expected type for header 'b'"); + + record{|string a; int...;|}[]|CsvConversionError cn3 = parseStringToRecord(csvValue1, { + allowDataProjection: false + }); + test:assertEquals(cn3, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); + + record{|string...;|}[]|CsvConversionError cn4 = parseStringToRecord(csvValue1, { + allowDataProjection: false + }); + test:assertEquals(cn4, [{"a": "a", "b": "2"}, {"a": "b", "b": "4"}]); + + record{|string a?;|}[]|CsvConversionError cn5 = parseStringToRecord(csvValue1, { + allowDataProjection: false + }); + test:assertTrue(cn5 is CsvConversionError); + test:assertEquals((cn5).message(), "No mapping field in the expected type for header 'b'"); + + record{|string? a;|}[]|CsvConversionError cn6 = parseStringToRecord(csvValue1, { + allowDataProjection: false + }); + test:assertTrue(cn6 is CsvConversionError); + test:assertEquals((cn6).message(), "No mapping field in the expected type for header 'b'"); + + anydata[][]|CsvConversionError c7 = parseStringToList(csvValue1, { + allowDataProjection: false + }); + test:assertEquals(c7, [["a", 2], ["b", 4]]); + + [string, int][]|CsvConversionError cn7_2 = parseStringToList(csvValue1, { + allowDataProjection: false + }); + test:assertEquals(cn7_2, [["a", 2], ["b", 4]]); + + [string][]|CsvConversionError cn8 = parseStringToList(csvValue1, { + allowDataProjection: false + }); + test:assertTrue(cn8 is CsvConversionError); + test:assertEquals((cn8).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); + + [string][]|CsvConversionError cn8_2 = parseStringToList(csvValue1, { + allowDataProjection: {} + }); + test:assertEquals(cn8_2, [["a"], ["b"]]); + + [int][]|CsvConversionError cn8_3 = parseStringToList(csvValue1, { + allowDataProjection: {} + }); + test:assertTrue(cn8_3 is CsvConversionError); + test:assertEquals((cn8_3).message(), generateErrorMessageForInvalidCast("a", "int")); + + [string, int...][]|CsvConversionError cn9 = parseStringToList(csvValue1, { + allowDataProjection: false + }); + test:assertEquals(cn9, [["a", 2], ["b", 4]]); + + [string...][]|CsvConversionError cn10 = parseStringToList(csvValue1, { + allowDataProjection: false + }); + test:assertEquals(cn10, [["a", "2"], ["b", "4"]]); + + [string, ()][]|CsvConversionError cn11 = parseStringToList(csvValue1, { + allowDataProjection: false + }); + test:assertTrue(cn11 is CsvConversionError); + test:assertEquals((cn11).message(), generateErrorMessageForInvalidCast("2", "()")); + + string[][]|CsvConversionError cn12 = parseStringToList(csvValue1, { + allowDataProjection: false + }); + test:assertEquals(cn12, [["a", "2"], ["b", "4"]]); + + string[][1]|CsvConversionError cn13 = parseStringToList(csvValue1, { + allowDataProjection: false + }); + test:assertTrue(cn13 is CsvConversionError); + test:assertEquals((cn13).message(), "invalid array size for expected array type, cannot be greater than '1'"); + + record{}[]|CsvConversionError cn14 = parseRecordAsRecordType(csvValue2, { + allowDataProjection: false + }); + test:assertEquals(cn14, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); + + record{|string a; int b;|}[]|CsvConversionError cn14_2 = parseRecordAsRecordType(csvValue2, { + allowDataProjection: false + }); + test:assertEquals(cn14_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); + + record{|string a;|}[]|CsvConversionError cn15 = parseRecordAsRecordType(csvValue2, { + allowDataProjection: false + }); + test:assertTrue(cn15 is CsvConversionError); + test:assertEquals((cn15).message(), "No mapping field in the expected type for header 'b'"); + + record{|string a; int...;|}[]|CsvConversionError cn16 = parseRecordAsRecordType(csvValue2, { + allowDataProjection: false + }); + test:assertEquals(cn16, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); + + record{|string...;|}[]|CsvConversionError cn17 = parseRecordAsRecordType(csvValue2, { + allowDataProjection: false + }); + test:assertEquals(cn17, [{"a": "a"}, {"a": "b"}]); + + record{|string a?;|}[]|CsvConversionError cn18 = parseRecordAsRecordType(csvValue2, { + allowDataProjection: false + }); + test:assertTrue(cn18 is CsvConversionError); + test:assertEquals((cn18).message(), "No mapping field in the expected type for header 'b'"); + + record{|string? a;|}[]|CsvConversionError cn19 = parseRecordAsRecordType(csvValue2, { + allowDataProjection: false + }); + test:assertTrue(cn19 is CsvConversionError); + test:assertEquals((cn19).message(), "No mapping field in the expected type for header 'b'"); + + anydata[][]|CsvConversionError c20 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: false + }); + test:assertEquals(c20, [["a", 2], ["b", 4]]); + + [string, int][]|CsvConversionError cn20_2 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: false + }); + test:assertEquals(cn20_2, [["a", 2], ["b", 4]]); + + [string][]|CsvConversionError cn21 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: false + }); + test:assertTrue(cn21 is CsvConversionError); + test:assertEquals((cn21).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); + + [string][]|CsvConversionError cn21_2 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: {} + }); + test:assertEquals(cn21_2, [["a"], ["b"]]); + + [int][]|CsvConversionError cn21_3 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: {} + }); + test:assertTrue(cn21_3 is CsvConversionError); + test:assertEquals((cn21_3).message(), generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); + + [string, int...][]|CsvConversionError cn22 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: false + }); + test:assertEquals(cn22, [["a", 2], ["b", 4]]); + + [string...][]|CsvConversionError cn23 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: false + }); + test:assertTrue(cn23 is CsvConversionError); + test:assertEquals(( cn23).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); + + [string, ()][]|CsvConversionError cn24 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: false + }); + test:assertTrue(cn24 is CsvConversionError); + test:assertEquals((cn24).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "()")); + + string[][]|CsvConversionError cn25 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: false + }); + test:assertTrue(cn25 is CsvConversionError); + test:assertEquals(( cn25).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); + + string[][1]|CsvConversionError cn26 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + allowDataProjection: false + }); + test:assertTrue(cn26 is CsvConversionError); + test:assertEquals((cn26).message(), "invalid array size for expected array type, cannot be greater than '1'"); + + // TODO: After fixing the issue with the anydata[] + + // record{}[]|CsvConversionError cnl14 = parseListAsRecordType(csvValue3, ["a", "b"], { + // allowDataProjection: false + // }); + // test:assertEquals(cnl14, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); + + // record{|string a; int b;|}[]|CsvConversionError cnl14_2 = parseListAsRecordType(csvValue3, ["a", "b"], { + // allowDataProjection: false + // }); + // test:assertEquals(cnl14_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); + + // record{|string a;|}[]|CsvConversionError cnl15 = parseListAsRecordType(csvValue3, ["a", "b"], { + // allowDataProjection: false + // }); + // test:assertTrue(cnl15 is CsvConversionError); + // test:assertEquals((cnl15).message(), "No mapping field in the expected type for header 'b'"); + + // record{|string a; int...;|}[]|CsvConversionError cnl16 = parseListAsRecordType(csvValue3, ["a", "b"], { + // allowDataProjection: false + // }); + // test:assertEquals(cnl16, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); + + // record{|string...;|}[]|CsvConversionError cnl17 = parseListAsRecordType(csvValue3, ["a", "b"], { + // allowDataProjection: false + // }); + // test:assertEquals(cnl17, [{"a": "a"}, {"a": "b"}]); + + // record{|string a?;|}[]|CsvConversionError cnl18 = parseListAsRecordType(csvValue3, ["a", "b"], { + // allowDataProjection: false + // }); + // test:assertTrue(cnl18 is CsvConversionError); + // test:assertEquals((cnl18).message(), "No mapping field in the expected type for header 'b'"); + + // record{|string? a;|}[]|CsvConversionError cnl19 = parseListAsRecordType(csvValue3, ["a", "b"], { + // allowDataProjection: false + // }); + // test:assertTrue(cnl19 is CsvConversionError); + // test:assertEquals((cnl19).message(), "No mapping field in the expected type for header 'b'"); + + // anydata[][]|CsvConversionError cnl20 = parseListAsListType(csvValue3 ,{ + // allowDataProjection: false + // }); + // test:assertEquals(cnl20, [["a", 2], ["b", 4]]); + + // [string, int][]|CsvConversionError cnl20_2 = parseListAsListType(csvValue3 ,{ + // allowDataProjection: false + // }); + // test:assertEquals(cnl20_2, [["a", 2], ["b", 4]]); + + // [string][]|CsvConversionError cnl21 = parseListAsListType(csvValue3 ,{ + // allowDataProjection: false + // }); + // test:assertTrue(cnl21 is CsvConversionError); + // test:assertEquals((cnl21).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); + + // [string][]|CsvConversionError cnl21_2 = parseListAsListType(csvValue3 ,{ + // allowDataProjection: {} + // }); + // test:assertEquals(cnl21_2, [["a"], ["b"]]); + + // [int][]|CsvConversionError cnl21_3 = parseListAsListType(csvValue3 ,{ + // allowDataProjection: {} + // }); + // test:assertTrue(cnl21_3 is CsvConversionError); + // test:assertEquals((cnl21_3).message(), generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); + + // [string, int...][]|CsvConversionError cnl22 = parseListAsListType(csvValue3 ,{ + // allowDataProjection: false + // }); + // test:assertEquals(cnl22, [["a", 2], ["b", 4]]); + + // [string...][]|CsvConversionError cnl23 = parseListAsListType(csvValue3 ,{ + // allowDataProjection: false + // }); + // test:assertTrue(cnl23 is CsvConversionError); + // test:assertEquals(( cnl23).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); + + // [string, ()][]|CsvConversionError cnl24 = parseListAsListType(csvValue3 ,{ + // allowDataProjection: false + // }); + // test:assertTrue(cnl24 is CsvConversionError); + // test:assertEquals((cnl24).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "()")); + + // string[][]|CsvConversionError cnl25 = parseListAsListType(csvValue3 ,{ + // allowDataProjection: false + // }); + // test:assertTrue(cnl25 is CsvConversionError); + // test:assertEquals(( cnl25).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); + + // string[][1]|CsvConversionError cnl26 = parseListAsListType(csvValue3 ,{ + // allowDataProjection: false + // }); + // test:assertTrue(cnl26 is CsvConversionError); + // test:assertEquals((cnl26).message(), "invalid array size for expected array type, cannot be greater than '1'"); +} \ No newline at end of file diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index 364eba9..7495b79 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -1,32 +1,32 @@ import ballerina/test; -boolean enable = true; +// boolean enable = true; -@test:Config {enable: !enable} -function debugTest() returns error? { +// @test:Config {enable: !enable} +// function debugTest() returns error? { - string csvValue1 = string ` - "a", b, c - 1, "2a\t", "3b\n" - "1c\n", 2, 3 - 1, "2a\"", 3 +// string csvValue1 = string ` +// "a", b, c +// 1, "2a\t", "3b\n" +// "1c\n", 2, 3 +// 1, "2a\"", 3 - "1a\\", "2b\\"", "3"`; +// "1a\\", "2b\\"", "3"`; - string csvValue2 = string ` - "a\"", "\tb\t\n", c - 1, "2a\t", "3b\n" - "1c\n", "/2/", 3 - 1, "2a\"", "3" +// string csvValue2 = string ` +// "a\"", "\tb\t\n", c +// 1, "2a\t", "3b\n" +// "1c\n", "/2/", 3 +// 1, "2a\"", "3" - "1a\\", "2b\\"", "3"`; +// "1a\\", "2b\\"", "3"`; - record {}[]|CsvConversionError cn = parseStringToRecord(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 {}[]|CsvConversionError cn = parseStringToRecord(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 {}[]|CsvConversionError cn2 = parseStringToRecord(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 {}[]|CsvConversionError cn2 = parseStringToRecord(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}]); +// } @test:Config {enable} function testFromCsvStringWithParserOptions() { @@ -487,6 +487,8 @@ function testSkipLineParserOption() { [4, "string4", true, -6.51, -6.51, ()], [5, "string5", true, 3, 3.0, ()] ]); + + // Fix:- Add tests for parseType } @test:Config {enable} @@ -863,6 +865,8 @@ function testDelimiterWithParserOptions() { [4, "string", true, 2.234, -3.21, ()], [5, "string", true, 2.234, -3.21, ()] ]); + + //TODO: Add tests for Unicodes } @test:Config {enable} diff --git a/ballerina/types.bal b/ballerina/types.bal index 5823af8..bc33c8b 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -3,9 +3,9 @@ public type CsvConversionError error; public type Options record { record { # If `true`, nil values will be considered as optional fields in the projection. - boolean nilAsOptionalField = false; + boolean nilAsOptionalField = false; // () assign to op # If `true`, absent fields will be considered as nilable types in the projection. - boolean absentAsNilableType = false; + boolean absentAsNilableType = false; // source haven't () && expected type contains op => () }|false allowDataProjection = {}; int[]|string skipLines = []; }; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index 850eedc..2826678 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -40,6 +40,8 @@ import java.util.HashMap; import java.util.List; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.isNullValue; + /** * Native implementation of data:fromStringWithType(string). * @@ -136,11 +138,7 @@ private static Object stringToBoolean(String value) throws NumberFormatException private static Object stringToNull(String value, CsvConfig config) throws NumberFormatException { Object nullValue = config.nilValue; - if ((nullValue == null) && (Constants.Values.NULL.equalsIgnoreCase(value) - || Constants.Values.BALLERINA_NULL.equalsIgnoreCase(value))) { - return null; - } - if (nullValue != null && value.equals(StringUtils.getStringValue(nullValue))) { + if (isNullValue(nullValue, value)) { return null; } return returnError(value, nullValue == null ? Constants.Values.BALLERINA_NULL : nullValue.toString()); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 461b13d..2a87e55 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -21,6 +21,7 @@ import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.*; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; @@ -29,13 +30,12 @@ import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.data.csvdata.FromString; +import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; +import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; import java.util.Map; /** @@ -61,9 +61,16 @@ static Object initRowValue(Type expectedType) { } static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, - BString value, Type type, CsvConfig config, Type exptype) { + String value, Type type, CsvConfig config, Type exptype, + Field currentField) { Object currentCsv = sm.currentCsvNode; - Object convertedValue = convertToExpectedType(value, type, config); + Object nilValue = config.nilValue; + if (sm.config.nilAsOptionalField && !type.isNilable() + && CsvUtils.isNullValue(nilValue, value) + && currentField != null && SymbolFlags.isFlagOn(currentField.getFlags(), SymbolFlags.OPTIONAL)) { + return null; + } + Object convertedValue = convertToExpectedType(StringUtils.fromString(value), type, config); sm.isCurrentCsvNodeEmpty = false; if (convertedValue instanceof BError) { if (ignoreIncompatibilityErrorsForMaps(sm, type, exptype)) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 70c34f8..a8e6e59 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -19,13 +19,17 @@ package io.ballerina.stdlib.data.csvdata.csv; import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; +import io.ballerina.runtime.api.flags.TypeFlags; import io.ballerina.runtime.api.types.*; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; @@ -36,6 +40,7 @@ import java.util.*; import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.checkAndAddCustomHeaders; +import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.getHeaderValueForColumnIndex; import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.*; /** @@ -382,6 +387,9 @@ private static void validateTupleTypes(TupleType tupleType, Type restType, int c private static void validateRemainingRecordFields(StateMachine sm) { if (sm.restType == null) { for (Field field : sm.fieldHierarchy.values()) { + if (sm.config.absentAsNilableType && field.getFieldType().isNilable()) { + return; + } if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); } @@ -484,14 +492,21 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } private static void handleEndOfTheRow(StateMachine sm, char ch) throws CsvParserException { -// if (sm.peek().isBlank()) { -// updateLineAndColumnIndexesWithoutRowIndexes(sm); -// } else { handleCsvRow(sm); - checkOptionalFieldsAndLogError(sm.fieldHierarchy); -// } + checkRequiredFieldsAndLogError(sm.fieldHierarchy, sm.config.absentAsNilableType); } +// public static void updateOptionalFields(StateMachine sm) { +// Object csvNode = sm.currentCsvNode; +// if (sm.config.absentAsNilableType && TypeUtils.getType(csvNode).getTag() == TypeTags.RECORD_TYPE_TAG) { +// sm.fieldHierarchy.values().forEach(field -> { +// if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL)) { +// ((BMap) csvNode).put(StringUtils.fromString(field.getFieldName()), null); +// } +// }); +// } +// } + private static void handleCsvRow(StateMachine sm) throws CsvParserException { if (!sm.peek().isBlank()) { addRowValue(sm); @@ -531,6 +546,7 @@ private static void initiateNewRowType(StateMachine sm) { private static void finalizeTheRow(StateMachine sm) { int rootArraySize = sm.rootArrayType.getSize(); +// updateOptionalFields(sm); if (rootArraySize == -1 || sm.rowIndex < rootArraySize) { sm.rootCsvNode.append(sm.currentCsvNode); } @@ -541,9 +557,11 @@ private static void addRowValue(StateMachine sm) throws CsvParserException { Type type; Type exptype = sm.expectedArrayElementType; String value = sm.value(); + Field currentField = null; if (exptype instanceof RecordType) { type = getExpectedRowTypeOfRecord(sm); + currentField = getCurrentField(sm); } else if (exptype instanceof MapType) { type = ((MapType) exptype).getConstrainedType(); } else if (exptype instanceof ArrayType) { @@ -556,7 +574,7 @@ private static void addRowValue(StateMachine sm) throws CsvParserException { if (type != null) { CsvCreator.convertAndUpdateCurrentJsonNode(sm, - StringUtils.fromString(value), type, sm.config, exptype); + value, type, sm.config, exptype, currentField); } sm.columnIndex++; } @@ -571,23 +589,29 @@ private static Type getExpectedRowTypeOfTuple(StateMachine sm, TupleType tupleTy return restType; } else { sm.charBuffIndex = 0; - return null; + if (sm.config.allowDataProjection) { + return null; + } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, tupleTypes.size()); } } } private static Type getExpectedRowTypeOfArray(StateMachine sm, ArrayType arrayType) { // TODO: add to a constant - if (arrayType.getSize() != -1 && arrayType.getSize() < sm.columnIndex) { + if (arrayType.getSize() != -1 && arrayType.getSize() <= sm.columnIndex) { sm.charBuffIndex = 0; - return null; + if (sm.config.allowDataProjection) { + return null; + } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, arrayType.getSize()); } return arrayType.getElementType(); } private static Type getExpectedRowTypeOfRecord(StateMachine sm) { // TODO: These can be make as module level variables - String header = CsvCreator.getHeaderValueForColumnIndex(sm); + String header = getHeaderValueForColumnIndex(sm); Map fields = sm.fieldNames; if (fields.containsKey(header)) { //TODO: Optimize @@ -598,11 +622,23 @@ private static Type getExpectedRowTypeOfRecord(StateMachine sm) { return restType; } else { sm.charBuffIndex = 0; - return null; + if (sm.config.allowDataProjection) { + return null; + } + throw DiagnosticLog.error(DiagnosticErrorCode.NO_FIELD_FOR_HEADER, header); } } } + private static Field getCurrentField(StateMachine sm) { + String header = getHeaderValueForColumnIndex(sm); + Map fields = sm.fieldNames; + if (fields.containsKey(header)) { + return fields.get(header); + } + return null; + } + private static class RowEndState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 7c83e14..0e9856f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -20,13 +20,17 @@ import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.*; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.*; import io.ballerina.stdlib.data.csvdata.FromString; +import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; +import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; @@ -113,28 +117,45 @@ private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArrayS public void traverseCsvArrayMembersWithMapAsCsvElementType(long length, BArray csv, Type expectedArrayType) { Object rowValue; for (int i = 0; i < length; i++) { + if (ignoreRow(i + 1, config.skipLines)) { + continue; + } rowValue = traverseCsvElementWithMapOrRecord(csv.get(i), expectedArrayType); - checkSkipDataRowsAndAddDataRow(rowValue, i, config.skipLines); + rootCsvNode.append(rowValue); } } public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray csv, Type expectedArrayType) { Object rowValue; for (int i = 0; i < length; i++) { + if (ignoreRow(i + 1, config.skipLines)) { + continue; + } rowValue = traverseCsvElementWithArray(csv.get(i), expectedArrayType); - checkSkipDataRowsAndAddDataRow(rowValue, i, config.skipLines); + rootCsvNode.append(rowValue); } } - private boolean checkSkipDataRowsAndAddDataRow(Object value, int index, Object skipLinesConfig) { + private static boolean ignoreRow(int index, Object skipLinesConfig) { long[] skipLines = getSkipDataRows(skipLinesConfig); - if (skipLines[0] <= index && index < skipLines[skipLines.length - 1]) { - return true; + for (long skipLine: skipLines) { + if (skipLine == index) { + return true; + } } - rootCsvNode.append(value); - return true; + return false; } +// private void checkSkipDataRowsAndAddDataRow(Object value, int index, Object skipLinesConfig) { +// long[] skipLines = getSkipDataRows(skipLinesConfig); +// for (long skipLine: skipLines) { +// if (skipLine == index) { +// return; +// } +// } +// rootCsvNode.append(value); +// } + public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expectedType) { switch (expectedType.getTag()) { case TypeTags.RECORD_TYPE_TAG: @@ -189,7 +210,7 @@ private void traverseArrayValue(Object csvElement, Type type) { private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { int index = 0; for (int i = 0; i < csvElement.getLength(); i++) { - if (index >= expectedSize) { + if (config.allowDataProjection && index >= expectedSize) { break; } addValuesToArrayType(csvElement.get(i), @@ -228,7 +249,7 @@ private void constructArrayValuesFromMap(BMap map, Type type, i throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER, key); } Object v = map.get(key); - if (index >= expectedSize) { + if (config.allowDataProjection && index >= expectedSize) { break; } addValuesToArrayType(v, getArrayOrTupleMemberType(type, index), index, currentCsvNode, config); @@ -245,8 +266,19 @@ private Type getArrayOrTupleMemberType(Type type, int index) { } if (restType != null) { return restType; + } else { + if (config.allowDataProjection) { + return null; + } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, tupleTypes.size()); } - return null; + } + ArrayType arrayType = (ArrayType) type; + if (arrayType.getSize() != -1 && arrayType.getSize() <= index) { + if (config.allowDataProjection) { + return null; + } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, arrayType.getSize()); } return ((ArrayType) type).getElementType(); } @@ -360,7 +392,6 @@ private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappin // TODO: Canges the logic with headers parameter for(int i = 1; i <= arraySize; i++) { -// key = StringUtils.fromString(String.valueOf(i)); key = StringUtils.fromString(this.headers[i - 1]); if (!mappingType) { if (!isKeyBelongsToNonRestType(csvElement.get(i-1), key)) { @@ -373,10 +404,11 @@ private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappin } addCurrentFieldValue(fieldType, csvElement.get(i - 1), key, mappingType); } - checkOptionalFieldsAndLogError(fieldHierarchy); + checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); } - private void traverseMapValueWithMapAsExpectedType(BMap map, boolean mappingType, Type expType) { + private void traverseMapValueWithMapAsExpectedType( + BMap map, boolean mappingType, Type expType) { Type currentFieldType; for (BString key : map.getKeys()) { if (!mappingType) { @@ -392,7 +424,7 @@ private void traverseMapValueWithMapAsExpectedType(BMap map, bo } addCurrentFieldValue(currentFieldType, map.get(key), key, mappingType); } - checkOptionalFieldsAndLogError(fieldHierarchy); + checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); } private boolean isKeyBelongsToNonRestType(Object value, BString key) { @@ -402,8 +434,12 @@ private boolean isKeyBelongsToNonRestType(Object value, BString key) { if (restType != null) { Type restFieldType = TypeUtils.getReferredType(restType); addRestField(restFieldType, key, value); + return false; } - return false; + if (config.allowDataProjection) { + return false; + } + throw DiagnosticLog.error(DiagnosticErrorCode.NO_FIELD_FOR_HEADER, key); } fieldNames.push(currentField.getFieldName()); return true; @@ -415,7 +451,12 @@ private void addFieldInMapType(BString key) { private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BString key, boolean isMapType) { int currentFieldTypeTag = currentFieldType.getTag(); - + Object nilValue = config.nilValue; + if (config.nilAsOptionalField && !currentFieldType.isNilable() + && CsvUtils.isNullValue(nilValue, mapValue) + && currentField != null && SymbolFlags.isFlagOn(currentField.getFlags(), SymbolFlags.OPTIONAL)) { + return; + } switch (currentFieldTypeTag) { case TypeTags.NULL_TAG: case TypeTags.BOOLEAN_TAG: @@ -458,6 +499,12 @@ private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BStrin } private void addRestField(Type restFieldType, BString key, Object csvMember) { + Object nilValue = config.nilValue; + if (config.nilAsOptionalField && !restFieldType.isNilable() + && CsvUtils.isNullValue(nilValue, csvMember) + && currentField != null && SymbolFlags.isFlagOn(currentField.getFlags(), SymbolFlags.OPTIONAL)) { + return; + } switch (restFieldType.getTag()) { case TypeTags.ANYDATA_TAG: case TypeTags.JSON_TAG: diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 96f8097..decef0d 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -111,8 +111,11 @@ public static Object convertToBasicType(Object csv, Type targetType, CsvConfig c } } - public static void checkOptionalFieldsAndLogError(Map currentField) { - currentField.values().forEach(field -> { + public static void checkRequiredFieldsAndLogError(Map filedHierarchy, boolean absentAsNilableType) { + filedHierarchy.values().forEach(field -> { + if (absentAsNilableType && field.getFieldType().isNilable()) { + return; + } if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.REQUIRED)) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_FIELD_IN_CSV, field.getFieldName()); } @@ -229,6 +232,26 @@ public static long[] getSkipDataRows(Object skipLines) { return skipDataRows; } + public static boolean isNullValue(Object nullValue, Object value) { + if (value == null) { + return true; + } + if (value instanceof BString) { + value = StringUtils.getStringValue(value); + } + if (value instanceof String v) { + if ((nullValue == null) && (Constants.Values.NULL.equalsIgnoreCase(v) + || Constants.Values.BALLERINA_NULL.equalsIgnoreCase(v))) { + return true; + } + if (nullValue != null && value.equals(StringUtils.getStringValue(nullValue))) { + return true; + } + return false; + } + return false; + } + public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object lineTerminatorObj) { String stringValue = Character.toString(c); if (lineTerminatorObj instanceof BArray) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index 6fb22fe..03eeb18 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -47,7 +47,8 @@ public enum DiagnosticErrorCode { INVALID_CUSTOM_HEADER("BDE_0020", "invalid.custom.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"); + HEADER_CANNOT_BE_EMPTY("BDE_0023", "header.cannot.be.empty"), + NO_FIELD_FOR_HEADER("BDE_0024", "no.field.for.header"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index 446be5d..2a28898 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -89,3 +89,6 @@ error.invalid.header.names.length=\ error.header.cannot.be.empty=\ The provided header row is empty + +error.no.field.for.header=\ + No mapping field in the expected type for header ''{0}'' From a70c2a8c4a81c5ed7c98a36b57835006e7179486 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 14 Jun 2024 00:45:59 +0530 Subject: [PATCH 032/147] Add tests for name annotation --- .../tests/user_config_projection_tests.bal | 199 ++++++++++++++++-- ballerina/types.bal | 10 + .../stdlib/data/csvdata/csv/CsvCreator.java | 10 +- .../stdlib/data/csvdata/csv/CsvParser.java | 29 +-- .../stdlib/data/csvdata/csv/CsvTraversal.java | 21 +- .../stdlib/data/csvdata/utils/Constants.java | 3 + .../stdlib/data/csvdata/utils/CsvUtils.java | 54 ++++- .../csvdata/utils/DiagnosticErrorCode.java | 3 +- native/src/main/resources/error.properties | 3 + 9 files changed, 282 insertions(+), 50 deletions(-) diff --git a/ballerina/tests/user_config_projection_tests.bal b/ballerina/tests/user_config_projection_tests.bal index f44ac09..b8fd5e1 100644 --- a/ballerina/tests/user_config_projection_tests.bal +++ b/ballerina/tests/user_config_projection_tests.bal @@ -4,19 +4,194 @@ boolean enable = true; @test:Config {enable: !enable} function debugTest() returns error? { - string csvValue1 = string `a,b - "a",2 - b,4`; - record{}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; - map[] csvValue3 = [{"a": "a", "b": "2"}, {"a": "b", "b": "4"}]; - [string, int][] csvValue4 = [["a", 2], ["b", 4]]; - (string|int)[][] csvValue5 = [["a", 2], ["b", 4]]; + RecordWithCustomAnnotation5[]|CsvConversionError cn19 = parseStringToRecord(string ` c,d,a,b + 3,1,4,5`, {}); + test:assertTrue(cn19 is CsvConversionError); + test:assertEquals((cn19).message(), "Duplicate field found in record fields: 'c'"); +} + +type RecordWithCustomAnnotation record { + @Name { + value: "c" + } + int a; + int b; +}; + +type RecordWithCustomAnnotation2 record { + @Name { + value: "c" + } + int a?; + @Name { + value: "d" + } + int? b; +}; + +type RecordWithCustomAnnotation3 record {| + @Name { + value: "c" + } + int a?; + @Name { + value: "d" + } + int? b; +|}; + +type RecordWithCustomAnnotation4 record {| + @Name { + value: "c" + } + int a; + @Name { + value: "d" + } + int b; + boolean...; +|}; + +type RecordWithCustomAnnotation5 record { + @Name { + value: "c" + } + int a; + @Name { + value: "d" + } + int b; + int c?; +}; + +type RecordWithCustomAnnotation6 record { + @Name { + value: "c" + } + int a; + @Name { + value: "d" + } + int b; + @Name { + value: "e" + } + int c; +}; + +type RecordWithCustomAnnotation7 record { + @Name { + value: "c" + } + int a; + @Name { + value: "d" + } + int b; + @Name { + value: "a" + } + int c; +}; + +@test:Config {enable} +function testCustomNameAnnotation() returns error? { + RecordWithCustomAnnotation[]|CsvConversionError cn1 = parseStringToRecord(string `b,c + 1,3`, {}); + test:assertEquals(cn1, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation[]|CsvConversionError cn2 = parseStringToRecord(string `c,b + 3,1`, {}); + test:assertEquals(cn2, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation[]|CsvConversionError cn3 = parseStringToRecord(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[]|CsvConversionError cn4 = parseStringToRecord(string `d,c + 1,3`, {}); + test:assertEquals(cn4, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation2[]|CsvConversionError cn5 = parseStringToRecord(string `c,d + 3,1`, {}); + test:assertEquals(cn5, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation2[]|CsvConversionError cn6 = parseStringToRecord(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[]|CsvConversionError cn7 = parseStringToRecord(string `a,b + 3,1`, {}); + test:assertTrue(cn7 is CsvConversionError); + test:assertEquals((cn7).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation2[]|CsvConversionError cn8 = parseStringToRecord(string ` c,d,a,b + 3,1,4,5`, {}); + test:assertTrue(cn8 is CsvConversionError); + test:assertEquals((cn8).message(), "Duplicate field found in record fields: 'a'"); - [string][]|CsvConversionError cn21 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ - allowDataProjection: false - }); - test:assertTrue(cn21 is CsvConversionError); - test:assertEquals((cn21).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); + RecordWithCustomAnnotation3[]|CsvConversionError cn9 = parseStringToRecord(string `d,c + 1,3`, {}); + test:assertEquals(cn9, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation3[]|CsvConversionError cn10 = parseStringToRecord(string `c,d + 3,1`, {}); + test:assertEquals(cn10, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation3[]|CsvConversionError cn11 = parseStringToRecord(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[]|CsvConversionError cn12 = parseStringToRecord(string `a,b + 3,1`, {}); + test:assertTrue(cn12 is CsvConversionError); + test:assertEquals((cn12).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation3[]|CsvConversionError cn13 = parseStringToRecord(string ` c,d,a,b + 3,1,4,5`, {}); + test:assertTrue(cn13 is CsvConversionError); + test:assertEquals((cn13).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation4[]|CsvConversionError cn14 = parseStringToRecord(string `d,c + 1,3`, {}); + test:assertEquals(cn14, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation4[]|CsvConversionError cn15 = parseStringToRecord(string `c,d + 3,1`, {}); + test:assertEquals(cn15, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation4[]|CsvConversionError cn16 = parseStringToRecord(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[]|CsvConversionError cn17 = parseStringToRecord(string `a,b + 3,1`, {}); + test:assertTrue(cn17 is CsvConversionError); + test:assertEquals((cn17).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation4[]|CsvConversionError cn18 = parseStringToRecord(string ` c,d,a,b + 3,1,4,5`, {}); + test:assertTrue(cn18 is CsvConversionError); + test:assertEquals((cn18).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation5[]|CsvConversionError cn19 = parseStringToRecord(string ` c,d,a,b + 3,1,4,5`, {}); + test:assertTrue(cn19 is CsvConversionError); + test:assertEquals((cn19).message(), "Duplicate field found in record fields: 'c'"); + + RecordWithCustomAnnotation6[]|CsvConversionError cn20 = parseStringToRecord(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}]); + + RecordWithCustomAnnotation7[]|CsvConversionError cn21 = parseStringToRecord(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}]); } @test:Config {enable} diff --git a/ballerina/types.bal b/ballerina/types.bal index bc33c8b..66d998c 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -1,5 +1,15 @@ public type CsvConversionError error; +# Defines the name of the JSON Object key. +# +# + value - The name of the JSON Object key +public type NameConfig record {| + string value; +|}; + +# The annotation is used to overwrite the existing record field name. +public const annotation NameConfig Name on record field; + public type Options record { record { # If `true`, nil values will be considered as optional fields in the projection. diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 2a87e55..ffec40f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -36,8 +36,11 @@ import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; +import java.util.HashMap; import java.util.Map; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getUpdatedHeaders; + /** * Create objects for partially parsed csv. * @@ -73,7 +76,7 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, Object convertedValue = convertToExpectedType(StringUtils.fromString(value), type, config); sm.isCurrentCsvNodeEmpty = false; if (convertedValue instanceof BError) { - if (ignoreIncompatibilityErrorsForMaps(sm, type, exptype)) { + if (ignoreIncompatibilityErrorsForMaps(sm, exptype)) { return null; } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, value, type); @@ -115,7 +118,8 @@ public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { if (sm.columnIndex >= sm.headers.size()) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); } - return sm.headers.get(sm.columnIndex); + String header = sm.headers.get(sm.columnIndex); + return getUpdatedHeaders(sm.updatedRecordFieldNames, header, sm.fieldHierarchy.containsKey(header)); } public static void checkAndAddCustomHeaders(CsvParser.StateMachine sm, Object customHeader) { @@ -136,7 +140,7 @@ public static void checkAndAddCustomHeaders(CsvParser.StateMachine sm, Object cu } } - private static boolean ignoreIncompatibilityErrorsForMaps(CsvParser.StateMachine sm, Type type, Type exptype) { + private static boolean ignoreIncompatibilityErrorsForMaps(CsvParser.StateMachine sm, Type exptype) { if (exptype.getTag() == TypeTags.RECORD_TYPE_TAG) { String header = getHeaderValueForColumnIndex(sm); Map fields = sm.fieldNames; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index a8e6e59..16baabc 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -19,18 +19,17 @@ package io.ballerina.stdlib.data.csvdata.csv; import io.ballerina.runtime.api.TypeTags; -import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; -import io.ballerina.runtime.api.flags.TypeFlags; import io.ballerina.runtime.api.types.*; -import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; +import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; +import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import org.apache.commons.lang3.StringEscapeUtils; @@ -96,6 +95,7 @@ static class StateMachine { ArrayList headers = new ArrayList<>(); BArray rootCsvNode; Map fieldHierarchy = new HashMap<>(); + Map updatedRecordFieldNames = new HashMap<>(); Map fieldNames = new HashMap<>(); private char[] charBuff = new char[1024]; private int charBuffIndex; @@ -130,6 +130,7 @@ public void reset() { columnIndex = 0; rowIndex = 1; fieldHierarchy.clear(); + updatedRecordFieldNames.clear(); fieldNames.clear(); rootArrayType = null; config = null; @@ -194,6 +195,7 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError RecordType recordType = (RecordType) expectedArrayElementType; restType = (recordType).getRestFieldType(); fieldHierarchy = new HashMap<>(recordType.getFields()); + updatedRecordFieldNames = processNameAnnotationsAndBuildCustomFieldMap(recordType, fieldHierarchy); break; case TypeTags.TUPLE_TAG: restType = ((TupleType) expectedArrayElementType).getRestType(); @@ -400,10 +402,13 @@ private static void validateRemainingRecordFields(StateMachine sm) { private static void addHeader(StateMachine sm) throws CsvParserException { String value = sm.value(); if (sm.expectedArrayElementType instanceof RecordType) { - Field field = sm.fieldHierarchy.get(value); + String fieldName = CsvUtils.getUpdatedHeaders( + sm.updatedRecordFieldNames, value, + sm.fieldHierarchy.containsKey(value) || sm.fieldNames.containsKey(value)); + Field field = sm.fieldHierarchy.get(fieldName); if (field != null) { - sm.fieldNames.put(value, field); - sm.fieldHierarchy.remove(value); + sm.fieldNames.put(fieldName, field); + sm.fieldHierarchy.remove(fieldName); } } sm.headers.add(value); @@ -495,18 +500,6 @@ private static void handleEndOfTheRow(StateMachine sm, char ch) throws CsvParser handleCsvRow(sm); checkRequiredFieldsAndLogError(sm.fieldHierarchy, sm.config.absentAsNilableType); } - -// public static void updateOptionalFields(StateMachine sm) { -// Object csvNode = sm.currentCsvNode; -// if (sm.config.absentAsNilableType && TypeUtils.getType(csvNode).getTag() == TypeTags.RECORD_TYPE_TAG) { -// sm.fieldHierarchy.values().forEach(field -> { -// if (SymbolFlags.isFlagOn(field.getFlags(), SymbolFlags.OPTIONAL)) { -// ((BMap) csvNode).put(StringUtils.fromString(field.getFieldName()), null); -// } -// }); -// } -// } - private static void handleCsvRow(StateMachine sm) throws CsvParserException { if (!sm.peek().isBlank()) { addRowValue(sm); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 0e9856f..ca0217b 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -20,15 +20,12 @@ import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; -import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.*; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.*; -import io.ballerina.stdlib.data.csvdata.FromString; -import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; @@ -60,6 +57,7 @@ static class CsvTree { Object currentCsvNode; Field currentField; Map fieldHierarchy = new HashMap<>(); + Map updatedRecordFieldNames = new HashMap<>(); Map headerFieldHierarchy = new HashMap<>(); Type restType; Deque fieldNames = new ArrayDeque<>(); @@ -146,21 +144,13 @@ private static boolean ignoreRow(int index, Object skipLinesConfig) { return false; } -// private void checkSkipDataRowsAndAddDataRow(Object value, int index, Object skipLinesConfig) { -// long[] skipLines = getSkipDataRows(skipLinesConfig); -// for (long skipLine: skipLines) { -// if (skipLine == index) { -// return; -// } -// } -// rootCsvNode.append(value); -// } - public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expectedType) { switch (expectedType.getTag()) { case TypeTags.RECORD_TYPE_TAG: RecordType recordType = (RecordType) expectedType; this.fieldHierarchy = new HashMap<>(recordType.getFields()); + this.updatedRecordFieldNames = + processNameAnnotationsAndBuildCustomFieldMap(recordType, fieldHierarchy); this.headerFieldHierarchy = new HashMap<>(recordType.getFields()); this.restType = recordType.getRestFieldType(); currentCsvNode = ValueCreator.createRecordValue(recordType.getPackage(), recordType.getName()); @@ -428,7 +418,10 @@ private void traverseMapValueWithMapAsExpectedType( } private boolean isKeyBelongsToNonRestType(Object value, BString key) { - currentField = fieldHierarchy.remove(key.toString()); + String keyStr = StringUtils.getStringValue(key); + String fieldName = CsvUtils.getUpdatedHeaders(this.updatedRecordFieldNames, + keyStr, this.fieldHierarchy.containsKey(keyStr)); + currentField = fieldHierarchy.remove(fieldName); if (currentField == null) { // Add to the rest field if (restType != null) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java index c14b79f..7d693df 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -27,4 +27,7 @@ public static class Values { } public static String SKIP_LINE_RANGE_SEP = "-"; + public static final String FIELD = "$field$."; + public static final String NAME = "Name"; + public static final BString VALUE = StringUtils.fromString("value"); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index decef0d..2cfa172 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -6,9 +6,9 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.*; -import io.ballerina.stdlib.data.csvdata.FromString; -import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; import java.util.Map; import static io.ballerina.runtime.api.TypeTags.INT_TAG; @@ -195,6 +195,56 @@ public static int getTheActualExpectedType(Type type) { } } + public static HashMap processNameAnnotationsAndBuildCustomFieldMap(RecordType recordType, + Map fieldHierarchy) { + BMap annotations = recordType.getAnnotations(); + HashMap updatedRecordFieldNames = new HashMap<>(); + HashSet updatedFields = new HashSet<>(); + HashSet updatedValues = new HashSet<>(); + + for (BString annotationsKey : annotations.getKeys()) { + String key = annotationsKey.getValue(); + if (key.contains(Constants.FIELD)) { + BMap annotMap = ((BMap) annotations.get(annotationsKey)); + for (BString mapKey : annotMap.getKeys()) { + if (mapKey.getValue().endsWith(Constants.NAME)) { + String name = ((Map) annotMap.get(mapKey)).get(Constants.VALUE).toString(); + String originalName = key.substring(Constants.FIELD.length()); + if (updatedValues.contains(name) || updatedFields.contains(originalName)) { + throw DiagnosticLog.error(DiagnosticErrorCode.DUPLICATE_FIELD, originalName); + } + updatedFields.add(originalName); + updatedValues.add(name); + updatedRecordFieldNames.put(name, originalName); + break; + } + } + } + } + for (String field : fieldHierarchy.keySet()) { + if (updatedFields.contains(field)) { + continue; + } + if (updatedValues.contains(field) || updatedRecordFieldNames.containsKey(field)) { + throw DiagnosticLog.error(DiagnosticErrorCode.DUPLICATE_FIELD, field); + } + updatedRecordFieldNames.put(field, field); + } + + return updatedRecordFieldNames; + } + + public static String getUpdatedHeaders(Map updatedRecords, String key, boolean isKeyContains) { + String fieldName = updatedRecords.get(key); + if (fieldName != null) { + return fieldName; + } + if (isKeyContains) { + throw DiagnosticLog.error(DiagnosticErrorCode.DUPLICATE_FIELD, key); + } + return key; + } + public static long[] getSkipLinesFromStringConfigValue(String configValue) { String[] parts = configValue.split(SKIP_LINE_RANGE_SEP); if (parts.length != 2) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index 03eeb18..261b1a0 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -48,7 +48,8 @@ public enum DiagnosticErrorCode { 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"); + NO_FIELD_FOR_HEADER("BDE_0024", "no.field.for.header"), + DUPLICATE_FIELD("BDE_0025", "duplicate.field"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index 2a28898..b92a09d 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -92,3 +92,6 @@ error.header.cannot.be.empty=\ error.no.field.for.header=\ No mapping field in the expected type for header ''{0}'' + +error.duplicate.field=\ + Duplicate field found in record fields: ''{0}'' From 45399fee2fec2ae073ef1146c9c2fb824b969da3 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 14 Jun 2024 02:30:10 +0530 Subject: [PATCH 033/147] Add Name config tests for records --- ballerina/tests/types.bal | 99 +++++++ .../tests/user_config_projection_tests.bal | 269 ++++++++++++------ .../stdlib/data/csvdata/csv/CsvCreator.java | 3 +- .../stdlib/data/csvdata/csv/CsvParser.java | 6 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 5 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 5 +- 6 files changed, 291 insertions(+), 96 deletions(-) diff --git a/ballerina/tests/types.bal b/ballerina/tests/types.bal index d3ccc42..6a304ae 100644 --- a/ballerina/tests/types.bal +++ b/ballerina/tests/types.bal @@ -2533,3 +2533,102 @@ type ClosedAnydataMapArray AnydataMap[3]; type CustomMapArray CustomMap[]; type ClosedCustomMapArray CustomMap[3]; + +type RecordWithCustomAnnotation record { + @Name { + value: "c" + } + int a; + int b; +}; + +type RecordWithCustomAnnotation2 record { + @Name { + value: "c" + } + int a?; + @Name { + value: "d" + } + int? b; +}; + +type RecordWithCustomAnnotation3 record {| + @Name { + value: "c" + } + int a?; + @Name { + value: "d" + } + int? b; +|}; + +type RecordWithCustomAnnotation4 record {| + @Name { + value: "c" + } + int a; + @Name { + value: "d" + } + int b; + boolean...; +|}; + +type RecordWithCustomAnnotation5 record { + @Name { + value: "c" + } + int a; + @Name { + value: "d" + } + int b; + int c?; +}; + +type RecordWithCustomAnnotation6 record { + @Name { + value: "c" + } + int a; + @Name { + value: "d" + } + int b; + @Name { + value: "e" + } + int c; +}; + +type RecordWithCustomAnnotation7 record { + @Name { + value: "c" + } + int a; + @Name { + value: "d" + } + int b; + @Name { + value: "a" + } + int c; +}; + +type RecordWithCustomAnnotation8 record { + @Name { + value: "c" + } + int a; + @Name { + value: "c" + } + int b; + @Name { + value: "a" + } + int c; +}; diff --git a/ballerina/tests/user_config_projection_tests.bal b/ballerina/tests/user_config_projection_tests.bal index b8fd5e1..771a552 100644 --- a/ballerina/tests/user_config_projection_tests.bal +++ b/ballerina/tests/user_config_projection_tests.bal @@ -4,96 +4,11 @@ boolean enable = true; @test:Config {enable: !enable} function debugTest() returns error? { - RecordWithCustomAnnotation5[]|CsvConversionError cn19 = parseStringToRecord(string ` c,d,a,b - 3,1,4,5`, {}); - test:assertTrue(cn19 is CsvConversionError); - test:assertEquals((cn19).message(), "Duplicate field found in record fields: 'c'"); + RecordWithCustomAnnotation2[]|CsvConversionError cnrr8 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + test:assertTrue(cnrr8 is CsvConversionError); + test:assertEquals((cnrr8).message(), "Duplicate field found in record fields: 'a'"); } -type RecordWithCustomAnnotation record { - @Name { - value: "c" - } - int a; - int b; -}; - -type RecordWithCustomAnnotation2 record { - @Name { - value: "c" - } - int a?; - @Name { - value: "d" - } - int? b; -}; - -type RecordWithCustomAnnotation3 record {| - @Name { - value: "c" - } - int a?; - @Name { - value: "d" - } - int? b; -|}; - -type RecordWithCustomAnnotation4 record {| - @Name { - value: "c" - } - int a; - @Name { - value: "d" - } - int b; - boolean...; -|}; - -type RecordWithCustomAnnotation5 record { - @Name { - value: "c" - } - int a; - @Name { - value: "d" - } - int b; - int c?; -}; - -type RecordWithCustomAnnotation6 record { - @Name { - value: "c" - } - int a; - @Name { - value: "d" - } - int b; - @Name { - value: "e" - } - int c; -}; - -type RecordWithCustomAnnotation7 record { - @Name { - value: "c" - } - int a; - @Name { - value: "d" - } - int b; - @Name { - value: "a" - } - int c; -}; - @test:Config {enable} function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation[]|CsvConversionError cn1 = parseStringToRecord(string `b,c @@ -155,9 +70,9 @@ function testCustomNameAnnotation() returns error? { test:assertTrue(cn13 is CsvConversionError); test:assertEquals((cn13).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|CsvConversionError cn14 = parseStringToRecord(string `d,c - 1,3`, {}); - test:assertEquals(cn14, [{b: 1, a: 3}]); + RecordWithCustomAnnotation4[]|CsvConversionError cn14 = parseStringToRecord(string `d,c,z + 1,3,true`, {}); + test:assertEquals(cn14, [{b: 1, a: 3, z: true}]); RecordWithCustomAnnotation4[]|CsvConversionError cn15 = parseStringToRecord(string `c,d 3,1`, {}); @@ -192,6 +107,178 @@ function testCustomNameAnnotation() returns error? { 3,1,4 3,1,4`, {}); test:assertEquals(cn21, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); + + RecordWithCustomAnnotation8[]|CsvConversionError cn22 = parseStringToRecord(string ` c,d,a + 3,1,4 + 3,1,4`, {}); + test:assertTrue(cn22 is CsvConversionError); + test:assertEquals((cn22).message(), "Duplicate field found in record fields: 'c'"); + + RecordWithCustomAnnotation[]|CsvConversionError cnrr1 = parseRecordAsRecordType([{"b": 1, "c": 3}], {}); + test:assertEquals(cnrr1, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation[]|CsvConversionError cnrr2 = parseRecordAsRecordType([{"c": 3, "b": 1}], {}); + test:assertEquals(cnrr2, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation[]|CsvConversionError cnrr3 = parseRecordAsRecordType( + [{"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[]|CsvConversionError cnrr4 = parseRecordAsRecordType([{"d": 1, "c": 3}], {}); + test:assertEquals(cnrr4, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation2[]|CsvConversionError cnrr5 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + test:assertEquals(cnrr5, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation2[]|CsvConversionError cnrr6 = parseRecordAsRecordType( + [{"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[]|CsvConversionError cnrr7 = parseRecordAsRecordType([{"a":3, "b": 1}], {}); + test:assertTrue(cnrr7 is CsvConversionError); + test:assertEquals((cnrr7).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation2[]|CsvConversionError cnrr8 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + test:assertTrue(cnrr8 is CsvConversionError); + test:assertEquals((cnrr8).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation3[]|CsvConversionError cnrr9 = parseRecordAsRecordType([{"d": 1, "c": 3}], {}); + test:assertEquals(cnrr9, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation3[]|CsvConversionError cnrr10 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + test:assertEquals(cnrr10, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation3[]|CsvConversionError cnrr11 = parseRecordAsRecordType( + [{"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[]|CsvConversionError cnrr12 = parseRecordAsRecordType([{"a": 3, "b": 1}], {}); + test:assertTrue(cnrr12 is CsvConversionError); + test:assertEquals((cnrr12).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation3[]|CsvConversionError cnrr13 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + test:assertTrue(cnrr13 is CsvConversionError); + test:assertEquals((cnrr13).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation4[]|CsvConversionError cnrr14 = parseRecordAsRecordType([{"d": 1, "c": 3, "z": true}], {}); + test:assertEquals(cnrr14, [{b: 1, a: 3, z: true}]); + + RecordWithCustomAnnotation4[]|CsvConversionError cnrr15 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + test:assertEquals(cnrr15, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation4[]|CsvConversionError cnrr16 = parseRecordAsRecordType( + [{"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}]); + + RecordWithCustomAnnotation4[]|CsvConversionError cnrr17 = parseRecordAsRecordType([{"a": 3, "b": 1}], {}); + test:assertTrue(cnrr17 is CsvConversionError); + test:assertEquals((cnrr17).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation4[]|CsvConversionError cnrr18 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + test:assertTrue(cnrr18 is CsvConversionError); + test:assertEquals((cnrr18).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation5[]|CsvConversionError cnrr19 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + test:assertTrue(cnrr19 is CsvConversionError); + test:assertEquals((cnrr19).message(), "Duplicate field found in record fields: 'c'"); + + RecordWithCustomAnnotation6[]|CsvConversionError cnrr20 = parseRecordAsRecordType( + [{"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}]); + + RecordWithCustomAnnotation7[]|CsvConversionError cnrr21 = parseRecordAsRecordType( + [{"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}]); + + RecordWithCustomAnnotation8[]|CsvConversionError cnrr22 = parseRecordAsRecordType( + [{"c": 3, "d": 1, "a": 4}, {"c": 3, "d": 1, "a": 4}], {}); + test:assertTrue(cnrr22 is CsvConversionError); + test:assertEquals((cnrr22).message(), "Duplicate field found in record fields: 'c'"); +} + +//TODO: Emable after fix tuple proj +@test:Config {enable: false} +function testCustomNameAnnotation2() returns error? { + RecordWithCustomAnnotation[]|CsvConversionError cntr1 = parseListAsRecordType([["1", "3"]], ["b", "c"], {}); + test:assertEquals(cntr1, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation[]|CsvConversionError cntr2 = parseListAsRecordType([["3", "1"]], ["c", "b"], {}); + test:assertEquals(cntr2, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation[]|CsvConversionError cntr3 = parseListAsRecordType( + [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["f", "c", "b", "e"], {}); + test:assertEquals(cntr3, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); + + RecordWithCustomAnnotation2[]|CsvConversionError cntr4 = parseListAsRecordType([["1", "3"]], ["d", "c"], {}); + test:assertEquals(cntr4, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation2[]|CsvConversionError cntr5 = parseListAsRecordType([["3","1"]], ["c", "d"], {}); + test:assertEquals(cntr5, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation2[]|CsvConversionError cntr6 = parseListAsRecordType( + [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); + test:assertEquals(cntr6, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); + + RecordWithCustomAnnotation2[]|CsvConversionError cntr7 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + test:assertTrue(cntr7 is CsvConversionError); + test:assertEquals((cntr7).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation2[]|CsvConversionError cntr8 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr8 is CsvConversionError); + test:assertEquals((cntr8).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation3[]|CsvConversionError cntr9 = parseListAsRecordType([["1", "3"]], ["d", "c"], {}); + test:assertEquals(cntr9, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation3[]|CsvConversionError cntr10 = parseListAsRecordType([["3", "1"]], ["c", "d"], {}); + test:assertEquals(cntr10, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation3[]|CsvConversionError cntr11 = parseListAsRecordType( + [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); + test:assertEquals(cntr11, [{b: 1, a: 3}, {b: 1, a: 3}]); + + RecordWithCustomAnnotation3[]|CsvConversionError cntr12 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + test:assertTrue(cntr12 is CsvConversionError); + test:assertEquals((cntr12).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation3[]|CsvConversionError cntr13 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr13 is CsvConversionError); + test:assertEquals((cntr13).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation4[]|CsvConversionError cntr14 = parseListAsRecordType([["1", "3", "true"]], ["d", "c", "z"], {}); + test:assertEquals(cntr14, [{b: 1, a: 3, z: true}]); + + RecordWithCustomAnnotation4[]|CsvConversionError cntr15 = parseListAsRecordType([["3", "1"]], ["c", "d"], {}); + test:assertEquals(cntr15, [{b: 1, a: 3}]); + + RecordWithCustomAnnotation4[]|CsvConversionError cntr16 = parseListAsRecordType( + [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); + test:assertEquals(cntr16, [{b: 1, a: 3}, {b: 1, a: 3}]); + + RecordWithCustomAnnotation4[]|CsvConversionError cntr17 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + test:assertTrue(cntr17 is CsvConversionError); + test:assertEquals((cntr17).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation4[]|CsvConversionError cntr18 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr18 is CsvConversionError); + test:assertEquals((cntr18).message(), "Duplicate field found in record fields: 'a'"); + + RecordWithCustomAnnotation5[]|CsvConversionError cntr19 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr19 is CsvConversionError); + test:assertEquals((cntr19).message(), "Duplicate field found in record fields: 'c'"); + + RecordWithCustomAnnotation6[]|CsvConversionError cntr20 = parseListAsRecordType( + [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "e"], {}); + test:assertEquals(cntr20, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); + + RecordWithCustomAnnotation7[]|CsvConversionError cntr21 = parseListAsRecordType( + [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "a"], {}); + test:assertEquals(cntr21, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); + + RecordWithCustomAnnotation8[]|CsvConversionError cntr22 = parseListAsRecordType( + [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "a"], {}); + test:assertTrue(cntr22 is CsvConversionError); + test:assertEquals((cntr22).message(), "Duplicate field found in record fields: 'c'"); } @test:Config {enable} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index ffec40f..4bb93fc 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -119,7 +119,8 @@ public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); } String header = sm.headers.get(sm.columnIndex); - return getUpdatedHeaders(sm.updatedRecordFieldNames, header, sm.fieldHierarchy.containsKey(header)); + return getUpdatedHeaders(sm.updatedRecordFieldNames, header, + sm.fields.contains(header)); } public static void checkAndAddCustomHeaders(CsvParser.StateMachine sm, Object customHeader) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 16baabc..55dd63b 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -96,6 +96,7 @@ static class StateMachine { BArray rootCsvNode; Map fieldHierarchy = new HashMap<>(); Map updatedRecordFieldNames = new HashMap<>(); + HashSet fields = new HashSet<>(); Map fieldNames = new HashMap<>(); private char[] charBuff = new char[1024]; private int charBuffIndex; @@ -131,6 +132,7 @@ public void reset() { rowIndex = 1; fieldHierarchy.clear(); updatedRecordFieldNames.clear(); + fields.clear(); fieldNames.clear(); rootArrayType = null; config = null; @@ -195,6 +197,7 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError RecordType recordType = (RecordType) expectedArrayElementType; restType = (recordType).getRestFieldType(); fieldHierarchy = new HashMap<>(recordType.getFields()); + fields = new HashSet<>(recordType.getFields().keySet()); updatedRecordFieldNames = processNameAnnotationsAndBuildCustomFieldMap(recordType, fieldHierarchy); break; case TypeTags.TUPLE_TAG: @@ -403,8 +406,7 @@ private static void addHeader(StateMachine sm) throws CsvParserException { String value = sm.value(); if (sm.expectedArrayElementType instanceof RecordType) { String fieldName = CsvUtils.getUpdatedHeaders( - sm.updatedRecordFieldNames, value, - sm.fieldHierarchy.containsKey(value) || sm.fieldNames.containsKey(value)); + sm.updatedRecordFieldNames, value, sm.fields.contains(value)); Field field = sm.fieldHierarchy.get(fieldName); if (field != null) { sm.fieldNames.put(fieldName, field); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index ca0217b..b3054a8 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -59,6 +59,7 @@ static class CsvTree { Map fieldHierarchy = new HashMap<>(); Map updatedRecordFieldNames = new HashMap<>(); Map headerFieldHierarchy = new HashMap<>(); + HashSet fields = new HashSet<>(); Type restType; Deque fieldNames = new ArrayDeque<>(); BArray rootCsvNode; @@ -72,6 +73,7 @@ void reset() { currentField = null; fieldHierarchy.clear(); headerFieldHierarchy.clear(); + fields.clear();; restType = null; fieldNames.clear(); expectedArrayElementType = null; @@ -149,6 +151,7 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected case TypeTags.RECORD_TYPE_TAG: RecordType recordType = (RecordType) expectedType; this.fieldHierarchy = new HashMap<>(recordType.getFields()); + fields = new HashSet<>(recordType.getFields().keySet()); this.updatedRecordFieldNames = processNameAnnotationsAndBuildCustomFieldMap(recordType, fieldHierarchy); this.headerFieldHierarchy = new HashMap<>(recordType.getFields()); @@ -420,7 +423,7 @@ private void traverseMapValueWithMapAsExpectedType( private boolean isKeyBelongsToNonRestType(Object value, BString key) { String keyStr = StringUtils.getStringValue(key); String fieldName = CsvUtils.getUpdatedHeaders(this.updatedRecordFieldNames, - keyStr, this.fieldHierarchy.containsKey(keyStr)); + keyStr, this.fields.contains(keyStr)); currentField = fieldHierarchy.remove(fieldName); if (currentField == null) { // Add to the rest field diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 2cfa172..0d8b433 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -210,7 +210,10 @@ public static HashMap processNameAnnotationsAndBuildCustomFieldM if (mapKey.getValue().endsWith(Constants.NAME)) { String name = ((Map) annotMap.get(mapKey)).get(Constants.VALUE).toString(); String originalName = key.substring(Constants.FIELD.length()); - if (updatedValues.contains(name) || updatedFields.contains(originalName)) { + if (updatedValues.contains(name)) { + throw DiagnosticLog.error(DiagnosticErrorCode.DUPLICATE_FIELD, name); + } + if (updatedFields.contains(originalName)) { throw DiagnosticLog.error(DiagnosticErrorCode.DUPLICATE_FIELD, originalName); } updatedFields.add(originalName); From f4b386d6707e8526b1e1c9f545727df4095cf65d Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 17 Jun 2024 01:13:28 +0530 Subject: [PATCH 034/147] Add type compatibility for string tuples --- ballerina/Dependencies.toml | 29 +---- ballerina/csv_api.bal | 4 +- .../tests/parse_list_type_as_list_test.bal | 111 ++++++++++++++++-- .../tests/parse_list_type_as_record_test.bal | 109 +++++++++++++---- .../tests/user_config_projection_tests.bal | 44 +++++-- .../user_config_with_parser_options_test.bal | 16 ++- ballerina/types.bal | 5 + .../stdlib/data/csvdata/FromString.java | 1 - .../stdlib/data/csvdata/csv/CsvCreator.java | 2 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 78 ++++++++---- .../stdlib/data/csvdata/csv/Native.java | 4 +- .../stdlib/data/csvdata/utils/Constants.java | 1 + .../stdlib/data/csvdata/utils/CsvConfig.java | 43 +++++++ .../stdlib/data/csvdata/utils/CsvUtils.java | 32 +++-- 14 files changed, 365 insertions(+), 114 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c995088..f95f329 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.0" +distribution-version = "2201.8.6" [[package]] org = "ballerina" @@ -27,26 +27,6 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - [[package]] org = "ballerina" name = "lang.error" @@ -56,12 +36,6 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - [[package]] org = "ballerina" name = "test" @@ -69,7 +43,6 @@ version = "0.0.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, {org = "ballerina", name = "lang.error"} ] modules = [ diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index c5c63b3..f18171c 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -45,10 +45,10 @@ public isolated function parseRecordAsListType(record{}[] s, string[] headerName returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function parseListAsRecordType(string[][] s, string[]? customHeaders = (), - Options options = {}, typedesc t = <>) + ListTypeOption options = {}, typedesc t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public isolated function parseListAsListType(string[][] s, Options options = {}, typedesc t = <>) +public isolated function parseListAsListType(string[][] s, ListTypeOption options = {}, typedesc t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/ballerina/tests/parse_list_type_as_list_test.bal b/ballerina/tests/parse_list_type_as_list_test.bal index 4c0a9b6..0755b3d 100644 --- a/ballerina/tests/parse_list_type_as_list_test.bal +++ b/ballerina/tests/parse_list_type_as_list_test.bal @@ -2,14 +2,14 @@ import ballerina/test; // boolean enable = true; -// // @test:Config {enable: !enable} -// // function debugTest() { -// // BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); -// // test:assertEquals(csvb4br1, [ -// // {b1: true, b2: "()", b3: (), b4: false}, -// // {b1: true, b2: "()", b3: (), b4: false} -// // ]); -// // } +// @test:Config {enable: !enable} +// function debugTest() { +// // NillableStringArrayArray|CsvConversionError st1nsaa = parseListAsListType([st1, st1], {}, NillableStringArrayArray); +// // test:assertEquals(st1nsaa , [ +// // [s1, s2], +// // [s1, s2] +// // ]); +// } @test:Config {enable} function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { @@ -24,6 +24,7 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { [s1, s2, s3, s2], [s1, s2, s3, s2] ]); + StringTuple1Array|CsvConversionError st3st1 = parseListAsListType([st3, st3], {}, StringTuple1Array); test:assertEquals(st3st1, [ [s1, s2, "", ""], @@ -173,8 +174,100 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { test:assertEquals((st4bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); } +@test:Config{enable} +function testFromCsvWithTypeForTupleAndTupleAsExpectedType2() { + [string, boolean, int][]|CsvConversionError ct1bt4 = parseListAsListType([["a", "true", "1"], ["a", "true", "1"]], {}); + test:assertEquals(ct1bt4, [ + ["a", true, 1], + ["a", true, 1] + ]); -@test:Config {enable} + [(), float, decimal, boolean, int, string][]|CsvConversionError ct1bt6 = parseListAsListType( + [["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][]|CsvConversionError ct1bt7 = parseListAsListType( + [["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...][]|CsvConversionError ct1bt8 = parseListAsListType( + [["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...][]|CsvConversionError ct1bt9 = parseListAsListType( + [["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...][]|CsvConversionError ct1bt10 = parseListAsListType( + [["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, ()...][]|CsvConversionError ct1bt11 = parseListAsListType( + [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); + test:assertTrue(ct1bt11 is CsvConversionError); + //TODO: Fix the message + test:assertEquals((ct1bt11).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "decimal")); + + [(), decimal, float, boolean, ()...][]|CsvConversionError ct1bt11_2 = parseListAsListType( + [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); + test:assertTrue(ct1bt11_2 is CsvConversionError); + //TODO: Fix the message + test:assertEquals((ct1bt11_2).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "()")); + + [()...][]|CsvConversionError ct1bt12 = parseListAsListType( + [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); + test:assertTrue(ct1bt12 is CsvConversionError); + test:assertEquals((ct1bt12).message(), generateErrorMessageForInvalidValueForArrayType("2.23", "1", "()")); + + [string...][]|CsvConversionError ct1bt13 = parseListAsListType( + [["1", "a"], ["1", "a"]]); + test:assertEquals(ct1bt13, [ + ["1", "a"], + ["1", "a"] + ]); + + [boolean...][]|CsvConversionError ct1bt14 = parseListAsListType( + [["2.23", "null"], ["7", "()"]]); + test:assertTrue(ct1bt14 is CsvConversionError); + test:assertEquals((ct1bt14).message(), generateErrorMessageForInvalidValueForArrayType("2.23", "0", "boolean")); + + int?[][]|CsvConversionError ct1bt15 = parseListAsListType( + [["1", "()"], ["1", "2"]]); + test:assertEquals(ct1bt15, [ + [1, ()], + [1, 2] + ]); + + int[][]|CsvConversionError ct1bt16 = parseListAsListType( + [["1", "2"], ["1", "()"]]); + test:assertTrue(ct1bt16 is CsvConversionError); + test:assertEquals((ct1bt16).message(), generateErrorMessageForInvalidValueForArrayType("()", "1", "int")); + + int[][]|CsvConversionError ct1bt17 = parseListAsListType( + [["a", "b"], ["a", "b"]]); + test:assertTrue(ct1bt17 is CsvConversionError); + test:assertEquals((ct1bt17).message(), generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); + + // TODO: Add tests with union types, string|boolean => true +} + + +@test:Config {enable: enable} function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { StringArrayArray|CsvConversionError st1saa = parseListAsListType([st1, st1], {}, StringArrayArray); test:assertEquals(st1saa , [ diff --git a/ballerina/tests/parse_list_type_as_record_test.bal b/ballerina/tests/parse_list_type_as_record_test.bal index 1ffc6ae..35bf0f2 100644 --- a/ballerina/tests/parse_list_type_as_record_test.bal +++ b/ballerina/tests/parse_list_type_as_record_test.bal @@ -1,24 +1,17 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// // record{decimal c; boolean d; int e; string f;}[]|CsvConversionError ct1br8 = parseListAsRecordType( -// // [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], -// // ["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 c;}[]|CsvConversionError ct1br8 = parseStringToRecord(string `c -// 1`, {}); -// 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"} -// ]); -// } +boolean enable = true; + +@test:Config {enable: !enable} +function debugTest() { + record{|()...;|}[]|CsvConversionError ct1br12 = parseListAsRecordType( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["f", "e", "d", "c", "b", "a"]); + test:assertEquals(ct1br12, [ + {a: ()}, + {a: ()} + ]); +} @test:Config {enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { @@ -490,7 +483,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { ]); } -@test:Config {enable: false} +@test:Config {enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { record{string a; boolean b; int c;}[]|CsvConversionError ct1br4 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b"], {}); test:assertEquals(ct1br4, [ @@ -518,9 +511,85 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["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...;|}[]|CsvConversionError ct1br9 = parseListAsRecordType( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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"} ]); + +// TODO: Check this + record{|int|() a; float b; decimal? c; string|boolean d; int|string e; string f; string...;|}[]|CsvConversionError ct1br9_2 = parseListAsRecordType( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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"} + ]); + + record{|decimal c; boolean|string d; int e; string f; string...;|}[]|CsvConversionError ct1br10 = parseListAsRecordType( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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; ()...;|}[]|CsvConversionError ct1br11 = parseListAsRecordType( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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{|()...;|}[]|CsvConversionError ct1br12 = parseListAsRecordType( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["f", "e", "d", "c", "b", "a"]); + test:assertEquals(ct1br12, [ + {a: ()}, + {a: ()} + ]); + +// TODO: Add more tests with union types + + record{|string?...;|}[]|CsvConversionError ct1br13 = parseListAsRecordType( + [["a", "1"], ["a", "1"]], + ["f", "e"]); + test:assertEquals(ct1br13, [ + {e: "1", f: "a"}, + {e: "1", f: "a"} + ]); + + record{|boolean...;|}[]|CsvConversionError ct1br14 = parseListAsRecordType( + [["2.23", "null"], ["7", "()"]], + ["b", "a"]); + test:assertEquals(ct1br14, [ + {}, + {} + ]); + + map[]|CsvConversionError ct1br15 = parseListAsRecordType( + [["2", "()"], ["2", "1"], ["()", "2"]], + ["f", "e"]); + test:assertEquals(ct1br15, [ + {e: (), f: 2}, + {e: 1, f: 2}, + {e: 2, f: ()} + ]); + + record{|boolean...;|}[]|CsvConversionError ct1br16 = parseListAsRecordType( + [["2.23", "null"], ["7", "()"]], + ["b", "a"]); + test:assertEquals(ct1br16, [ + {}, + {} + ]); } @test:Config {enable} diff --git a/ballerina/tests/user_config_projection_tests.bal b/ballerina/tests/user_config_projection_tests.bal index 771a552..1a1ac05 100644 --- a/ballerina/tests/user_config_projection_tests.bal +++ b/ballerina/tests/user_config_projection_tests.bal @@ -1,13 +1,39 @@ import ballerina/test; -boolean enable = true; - -@test:Config {enable: !enable} -function debugTest() returns error? { - RecordWithCustomAnnotation2[]|CsvConversionError cnrr8 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); - test:assertTrue(cnrr8 is CsvConversionError); - test:assertEquals((cnrr8).message(), "Duplicate field found in record fields: 'a'"); -} +// boolean enable = !true; + +// @test:Config {enable: !enable} +// function debugTest() returns error? { +// // StringArrayArray|CsvConversionError st1saa = parseListAsListType([st1, st1], {}, StringArrayArray); +// // test:assertEquals(st1saa , [ +// // [s1, s2], +// // [s1, s2] +// // ]); + +// // StringArrayArray|CsvConversionError st2saa = parseListAsListType([st2, st2], {}, StringArrayArray); +// // test:assertEquals(st2saa , [ +// // [s1, s2, s3, s2], +// // [s1, s2, s3, s2] +// // ]); + +// // StringArrayArray|CsvConversionError st3saa = parseListAsListType([st3, st3], {}, StringArrayArray); +// // test:assertEquals(st3saa , [ +// // [s1, s2], +// // [s1, s2] +// // ]); + +// // StringArrayArray|CsvConversionError st4saa = parseListAsListType([st4, st4], {}, StringArrayArray); +// // test:assertEquals(st4saa , [ +// // [s1, s2, s3, s2], +// // [s1, s2, s3, s2] +// // ]); + +// // NillableStringArrayArray|CsvConversionError st1nsaa = parseListAsListType([st1, st1], {}, NillableStringArrayArray); +// // test:assertEquals(st1nsaa , [ +// // [s1, s2], +// // [s1, s2] +// // ]); +// } @test:Config {enable} function testCustomNameAnnotation() returns error? { @@ -694,7 +720,7 @@ function testDataProjectionConfig() returns error? { test:assertEquals(cn22, [["a", 2], ["b", 4]]); [string...][]|CsvConversionError cn23 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ - allowDataProjection: false + allowDataProjection: false }); test:assertTrue(cn23 is CsvConversionError); test:assertEquals(( cn23).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index 7495b79..126de36 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -552,25 +552,33 @@ function testCustomHeaderOption() { test:assertTrue(ct1br6 is CsvConversionError); test:assertEquals((ct1br6).message(), generateErrorMessageForMissingRequiredField("c")); - record {string a; string b;}[]|CsvConversionError ct1br7 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + record {string a; string b;}[]|CsvConversionError ct1br7 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + stringConversion: false + }); test:assertEquals(ct1br7, [ {a: "a", e: "1", b: "true"}, {a: "a", e: "1", b: "true"} ]); - record {|string a; string b;|}[]|CsvConversionError ct1br8 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + record {|string a; string b;|}[]|CsvConversionError ct1br8 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + stringConversion: false + }); test:assertEquals(ct1br8, [ {a: "a", b: "true"}, {a: "a", b: "true"} ]); - record {|string...;|}[]|CsvConversionError ct1br9 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + record {|string...;|}[]|CsvConversionError ct1br9 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + stringConversion: false + }); test:assertEquals(ct1br9, [ {a: "a", b: "true", e: "1"}, {a: "a", b: "true", e: "1"} ]); - record {|string...;|}[]|CsvConversionError ct1br10 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), {}); + record {|string...;|}[]|CsvConversionError ct1br10 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), { + stringConversion: false + }); test:assertEquals(ct1br10, [ {'1: "a", '3: "true", '2: "1"}, {'1: "a", '3: "true", '2: "1"} diff --git a/ballerina/types.bal b/ballerina/types.bal index 66d998c..0b40017 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -49,6 +49,11 @@ public type ToRecordOptions record { string[]? customHeaders = (); }; +public type ListTypeOption record {| + *Options; + boolean stringConversion = true; +|}; + public enum LineTerminator { CR = "\r", LF = "\n", diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index 2826678..3def988 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -72,7 +72,6 @@ public class FromString { public static Object fromStringWithType(BString string, CsvConfig config, BTypedesc typed) { Type expType = typed.getDescribingType(); - try { return fromStringWithType(string, expType, config); } catch (NumberFormatException e) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 4bb93fc..785b2d8 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -155,7 +155,7 @@ private static boolean ignoreIncompatibilityErrorsForMaps(CsvParser.StateMachine return false; } - private static Object convertToExpectedType(BString value, Type type, CsvConfig config) { + public static Object convertToExpectedType(BString value, Type type, CsvConfig config) { if (type.getTag() == TypeTags.ANYDATA_TAG) { return FromString.fromStringWithType(value, PredefinedTypes.TYPE_JSON, config); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index b3054a8..3587062 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -66,19 +66,22 @@ static class CsvTree { Type expectedArrayElementType; Type sourceArrayElementType; CsvConfig config; - String[] headers= null; + String[] headers = null; void reset() { currentCsvNode = null; currentField = null; fieldHierarchy.clear(); + updatedRecordFieldNames.clear(); headerFieldHierarchy.clear(); fields.clear();; restType = null; fieldNames.clear(); + rootCsvNode = null; expectedArrayElementType = null; sourceArrayElementType = null; headers = null; + config = null; } @SuppressWarnings("unchecked") @@ -206,8 +209,11 @@ private void constructArrayValuesFromArray(BArray csvElement, Type type, int exp if (config.allowDataProjection && index >= expectedSize) { break; } - addValuesToArrayType(csvElement.get(i), - getArrayOrTupleMemberType(type, index), index, currentCsvNode, config); + Type memberType = getArrayOrTupleMemberType(type, index); + if (memberType != null) { + addValuesToArrayType(csvElement.get(i), memberType, index, + currentCsvNode, config); + } index++; } } @@ -245,11 +251,22 @@ private void constructArrayValuesFromMap(BMap map, Type type, i if (config.allowDataProjection && index >= expectedSize) { break; } - addValuesToArrayType(v, getArrayOrTupleMemberType(type, index), index, currentCsvNode, config); + Type memberType = getArrayOrTupleMemberType(type, index); + if (memberType != null) { + addValuesToArrayType(v, memberType, index, + currentCsvNode, config); + } index++; } } + private boolean isArrayOrTupleRestTypeMember(Type type, int index) { + if (type instanceof ArrayType) { + return false; + } + return ((TupleType) type).getTupleTypes().size() < index + 1; + } + private Type getArrayOrTupleMemberType(Type type, int index) { if (type instanceof TupleType) { TupleType tupleType = (TupleType) type; @@ -346,10 +363,8 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Tup } private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Type arrayType, int arraySize) { - arrayType = TypeUtils.getReferredType(arrayType); if (expectedType instanceof RecordType) { - if (this.restType != null && (this.restType == arrayType - || this.restType.getTag() == TypeTags.ANYDATA_TAG)) { + if (this.restType != null) { return true; } @@ -462,26 +477,31 @@ private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BStrin case TypeTags.STRING_TAG: case TypeTags.JSON_TAG: case TypeTags.ANYDATA_TAG: - case TypeTags.ANY_TAG: - if (checkTypeCompatibility(currentFieldType, mapValue)) { - ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), - convertToBasicType(mapValue, currentFieldType, config)); - return; + if (checkTypeCompatibility(currentFieldType, mapValue, config.stringConversion)) { + Object value = convertToBasicType(mapValue, currentFieldType, config); + if (!(value instanceof BError)) { + ((BMap) currentCsvNode) + .put(StringUtils.fromString(fieldNames.pop()), value); + return; + } } - if (!isMapType) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); + if (isMapType) { + return; } - return; + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); case TypeTags.UNION_TAG: for (Type memberType: ((UnionType) currentFieldType).getMemberTypes()) { if (!isBasicType(memberType)) { throw DiagnosticLog.error(DiagnosticErrorCode .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); } - if (checkTypeCompatibility(memberType, mapValue)) { - ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), - convertToBasicType(mapValue, memberType, config)); - return; + if (checkTypeCompatibility(memberType, mapValue, config.stringConversion)) { + Object value = convertToBasicType(mapValue, memberType, config); + if (!(value instanceof BError)) { + ((BMap) currentCsvNode) + .put(StringUtils.fromString(fieldNames.pop()), value); + return; + } } } if (isMapType) { @@ -509,9 +529,12 @@ private void addRestField(Type restFieldType, BString key, Object csvMember) { case TypeTags.FLOAT_TAG: case TypeTags.DECIMAL_TAG: case TypeTags.STRING_TAG: - if (checkTypeCompatibility(restFieldType, csvMember)) { - ((BMap) currentCsvNode) - .put(key, convertToBasicType(csvMember, restFieldType, config)); + case TypeTags.NULL_TAG: + if (checkTypeCompatibility(restFieldType, csvMember, config.stringConversion)) { + Object value = convertToBasicType(csvMember, restFieldType, config); + if (!(value instanceof BError)) { + ((BMap) currentCsvNode).put(key, value); + } } break; case TypeTags.UNION_TAG: @@ -520,10 +543,12 @@ private void addRestField(Type restFieldType, BString key, Object csvMember) { throw DiagnosticLog.error(DiagnosticErrorCode .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); } - if (checkTypeCompatibility(memberType, csvMember)) { - ((BMap) currentCsvNode) - .put(key, convertToBasicType(csvMember, memberType, config)); - break; + if (checkTypeCompatibility(memberType, csvMember, config.stringConversion)) { + Object value = convertToBasicType(csvMember, memberType, config); + if (!(value instanceof BError)) { + ((BMap) currentCsvNode).put(key, value); + break; + } } } break; @@ -531,6 +556,7 @@ private void addRestField(Type restFieldType, BString key, Object csvMember) { for (Type memberType: ((IntersectionType) restFieldType).getConstituentTypes()) { // } + break; default: throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, csvMember, key); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index 3a19ff4..eb28766 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -138,7 +138,7 @@ 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.createToRecordOptions(options), type.getDescribingType()); + return CsvTraversal.traverse(csv, CsvConfig.createListAsRecordTypeOptions(options), type.getDescribingType()); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } @@ -146,7 +146,7 @@ public static Object parseListAsRecordType(BArray csv, Object customHeaders, public static Object parseListAsListType(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvConfig.createOptions(options), type.getDescribingType()); + return CsvTraversal.traverse(csv, CsvConfig.createListTypeOptions(options), type.getDescribingType()); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java index 7d693df..10af919 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -19,6 +19,7 @@ public static class ConfigConstants { public static BString ABSENT_AS_NILABLE = StringUtils.fromString("absentAsNilableType"); public static BString ALLOW_DATA_PROJECTION = StringUtils.fromString("allowDataProjection"); public static BString CUSTOM_HEADERS = StringUtils.fromString("customHeaders"); + public static BString STRING_CONVERSION = StringUtils.fromString("stringConversion"); } public static class Values { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java index 573043c..6d9f316 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java @@ -23,6 +23,7 @@ public class CsvConfig { public boolean allowDataProjection = true; public Object customHeader = null; public BArray headersOrder = null; + public boolean stringConversion = false; private CsvConfig(Object skipLines, boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection) { @@ -41,6 +42,48 @@ private CsvConfig(Object skipLines, boolean nilAsOptionalField, this.customHeader = customHeader; } + private CsvConfig(Object skipLines, boolean nilAsOptionalField, + boolean absentAsNilableType, boolean allowDataProjection, boolean stringConversion) { + this.skipLines = skipLines; + 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) { + this.skipLines = skipLines; + this.nilAsOptionalField = nilAsOptionalField; + this.absentAsNilableType = absentAsNilableType; + this.allowDataProjection = allowDataProjection; + this.stringConversion = stringConversion; + this.customHeader = customHeader; + } + + public static CsvConfig createListTypeOptions(BMap options) { + updateDataProjectOptions(options); + return new CsvConfig( + options.get(SKIP_LINES), + options.getBooleanValue(NIL_AS_OPTIONAL).booleanValue(), + options.getBooleanValue(ABSENT_AS_NILABLE).booleanValue(), + options.getBooleanValue(ALLOW_DATA_PROJECTION).booleanValue(), + options.getBooleanValue(STRING_CONVERSION).booleanValue() + ); + } + + public static CsvConfig createListAsRecordTypeOptions(BMap options) { + updateDataProjectOptions(options); + return new CsvConfig( + options.get(SKIP_LINES), + options.getBooleanValue(NIL_AS_OPTIONAL).booleanValue(), + options.getBooleanValue(ABSENT_AS_NILABLE).booleanValue(), + options.getBooleanValue(ALLOW_DATA_PROJECTION).booleanValue(), + options.getBooleanValue(STRING_CONVERSION).booleanValue(), + options.get(CUSTOM_HEADERS) + ); + } + private CsvConfig(char delimiter, char textEnclosure, Object header, char escapeChar, Object lineTerminator, Object skipLines, Object nilValue, char comment, String locale, String encoding, diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 0d8b433..dd22ab6 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -6,6 +6,8 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.*; +import io.ballerina.stdlib.data.csvdata.FromString; +import io.ballerina.stdlib.data.csvdata.csv.CsvCreator; import java.util.HashMap; import java.util.HashSet; @@ -104,11 +106,10 @@ public static Object convertToBasicType(Object csv, Type targetType, CsvConfig c if (csv == null) { csv = config.nilValue; } - try { - return ValueUtils.convert(csv, targetType); - } catch (BError e) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, targetType); + if (config.stringConversion && csv instanceof BString) { + return CsvCreator.convertToExpectedType((BString) csv, targetType, config); } + return ValueUtils.convert(csv, targetType); } public static void checkRequiredFieldsAndLogError(Map filedHierarchy, boolean absentAsNilableType) { @@ -131,9 +132,9 @@ public static boolean isHeaderFieldsEmpty(Map currentField) { return true; } - public static boolean checkTypeCompatibility(Type constraintType, Object csv) { + public static boolean checkTypeCompatibility(Type constraintType, Object csv, boolean stringConversion) { int tag = constraintType.getTag(); - if ((csv instanceof BString && (tag == TypeTags.STRING_TAG || isJsonOrAnyDataOrAny(tag))) + if ((csv instanceof BString && (stringConversion || tag == TypeTags.STRING_TAG || isJsonOrAnyDataOrAny(tag))) || (csv instanceof Long && (tag == INT_TAG || isJsonOrAnyDataOrAny(tag))) || (csv instanceof BDecimal && ((tag == TypeTags.DECIMAL_TAG || tag == TypeTags.FLOAT_TAG) || isJsonOrAnyDataOrAny(tag))) @@ -163,9 +164,12 @@ public static void addValuesToArrayType(Object csvElement, Type arrayElementType case TypeTags.JSON_TAG: case TypeTags.ANYDATA_TAG: case TypeTags.ANY_TAG: - if (checkTypeCompatibility(arrayElementType, csvElement)) { - ((BArray) currentCsvNode).add(index, convertToBasicType(csvElement, arrayElementType, config)); - return; + if (checkTypeCompatibility(arrayElementType, csvElement, config.stringConversion)) { + Object value = convertToBasicType(csvElement, arrayElementType, config); + if (!(value instanceof BError)) { + ((BArray) currentCsvNode).add(index, value); + return; + } } break; case TypeTags.UNION_TAG: @@ -174,11 +178,15 @@ public static void addValuesToArrayType(Object csvElement, Type arrayElementType throw DiagnosticLog.error(DiagnosticErrorCode .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); } - if (checkTypeCompatibility(memberType, csvElement)) { - ((BArray) currentCsvNode).add(index, convertToBasicType(csvElement, memberType, config)); - return; + if (checkTypeCompatibility(memberType, csvElement , config.stringConversion)) { + Object value = convertToBasicType(csvElement, memberType, config); + if (!(value instanceof BError)) { + ((BArray) currentCsvNode).add(index, value); + return; + } } } + break; } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_ARRAY, csvElement, index, arrayElementType); } From b0ee27c8246e0181df77aa0fc30bddbaaa3380e3 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 18 Jun 2024 23:56:08 +0530 Subject: [PATCH 035/147] Add intersection support --- .../tests/parse_list_type_as_list_test.bal | 8 +- .../tests/parse_list_type_as_record_test.bal | 28 +- .../tests/parse_string_to_map_tests copy.bal | 9 +- .../tests/parse_type_compatibility_test.bal | 366 +++++++++++++++++- .../tests/user_config_projection_tests.bal | 46 +-- .../user_config_with_parser_options_test.bal | 26 +- .../stdlib/data/csvdata/FromString.java | 217 +++++++++-- .../stdlib/data/csvdata/csv/CsvCreator.java | 10 +- .../stdlib/data/csvdata/csv/CsvParser.java | 6 - .../stdlib/data/csvdata/csv/CsvTraversal.java | 129 +++--- .../stdlib/data/csvdata/utils/CsvUtils.java | 35 +- native/src/main/resources/error.properties | 2 +- 12 files changed, 692 insertions(+), 190 deletions(-) diff --git a/ballerina/tests/parse_list_type_as_list_test.bal b/ballerina/tests/parse_list_type_as_list_test.bal index 0755b3d..c48da28 100644 --- a/ballerina/tests/parse_list_type_as_list_test.bal +++ b/ballerina/tests/parse_list_type_as_list_test.bal @@ -4,11 +4,9 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// // NillableStringArrayArray|CsvConversionError st1nsaa = parseListAsListType([st1, st1], {}, NillableStringArrayArray); -// // test:assertEquals(st1nsaa , [ -// // [s1, s2], -// // [s1, s2] -// // ]); +// DecimalArray1Array|CsvConversionError st1dda = parseListAsListType([st1, st1], {}, DecimalArray1Array); +// test:assertTrue(st1dda is CsvConversionError); +// test:assertEquals((st1dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); // } @test:Config {enable} diff --git a/ballerina/tests/parse_list_type_as_record_test.bal b/ballerina/tests/parse_list_type_as_record_test.bal index 35bf0f2..11774be 100644 --- a/ballerina/tests/parse_list_type_as_record_test.bal +++ b/ballerina/tests/parse_list_type_as_record_test.bal @@ -1,17 +1,17 @@ import ballerina/test; -boolean enable = true; - -@test:Config {enable: !enable} -function debugTest() { - record{|()...;|}[]|CsvConversionError ct1br12 = parseListAsRecordType( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["f", "e", "d", "c", "b", "a"]); - test:assertEquals(ct1br12, [ - {a: ()}, - {a: ()} - ]); -} +// boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() { +// record{|()...;|}[]|CsvConversionError ct1br12 = parseListAsRecordType( +// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], +// ["f", "e", "d", "c", "b", "a"]); +// test:assertEquals(ct1br12, [ +// {a: ()}, +// {a: ()} +// ]); +// } @test:Config {enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { @@ -528,8 +528,8 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["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"} + {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|string d; int e; string f; string...;|}[]|CsvConversionError ct1br10 = parseListAsRecordType( diff --git a/ballerina/tests/parse_string_to_map_tests copy.bal b/ballerina/tests/parse_string_to_map_tests copy.bal index dd850be..a987ee6 100644 --- a/ballerina/tests/parse_string_to_map_tests copy.bal +++ b/ballerina/tests/parse_string_to_map_tests copy.bal @@ -4,10 +4,11 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); -// test:assertEquals(csvb4br1, [ -// {b1: true, b2: "()", b3: (), b4: false}, -// {b1: true, b2: "()", b3: (), b4: false} +// NillableIntUnionBooleanMapArray|CsvConversionError bv4bniubma = parseStringToRecord(string `a +// 0`); +// test:assertEquals(bv4bniubma, [ +// {b1: true, b2: (), b3: (), b4: 0}, +// {b1: 1, b2: (), b3: (), b4: false} // ]); // } diff --git a/ballerina/tests/parse_type_compatibility_test.bal b/ballerina/tests/parse_type_compatibility_test.bal index f983d08..26da174 100644 --- a/ballerina/tests/parse_type_compatibility_test.bal +++ b/ballerina/tests/parse_type_compatibility_test.bal @@ -4,10 +4,13 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); -// test:assertEquals(csvb4br1, [ -// {b1: true, b2: "()", b3: (), b4: false}, -// {b1: true, b2: "()", b3: (), b4: false} +// record{A a; B b; C c;}[]|CsvConversionError rt12a = 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"} // ]); // } @@ -110,3 +113,358 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {a: f2, b: d2} ]); } + +type A decimal|int; +type A2 int|decimal; +type B readonly & A | C; +type B2 readonly & C | readonly & A2; +type C string|boolean; +type C2 boolean|string; + +@test:Config {enable} +function testFromCsvWithIntersectionTypeCompatibility2() { + record{ + readonly & int a; + readonly & string b; + (readonly & boolean) | (readonly & decimal) c; + }[]|CsvConversionError r1a = parseStringToRecord( 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} + ]); + + record{A a; B b; C c;}[]|CsvConversionError r2a = parseStringToRecord( 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} + ]); + + record{A2 a; B2 b; C2 c;}[]|CsvConversionError r3a = parseStringToRecord( 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} + ]); + + record{|A2 a; B2 b; C2...;|}[]|CsvConversionError r4a = parseStringToRecord( 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"} + ]); + + record{|C2...;|}[]|CsvConversionError r5a = parseStringToRecord( string `a,b,c,d + 1,string,true,string + 2,string2,false,string2 + 3,string3,true,string3`); + + test:assertEquals(r5a , [ + {a: true, 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)][]|CsvConversionError r16a = + parseStringToList( 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] + ]); + + [A, B, C][]|CsvConversionError r17a = parseStringToList( + 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] + ]); + + [A2, B2, C2][]|CsvConversionError r18a = parseStringToList( + 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] + ]); + + [A2, B2, C2...][]|CsvConversionError r19a = parseStringToList( + 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"] + ]); + + [C2...][]|CsvConversionError r20a = parseStringToList( + string `a,b,c,d + 1,string,true,string + 2,string2,false,string2 + 3,string3,true,string3`); + + test:assertEquals(r20a, [[true, "string",true, "string"], + ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); + + + record{A a; B b; C c;}[]|CsvConversionError rt2a = 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; + }[]|CsvConversionError rt1a = 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;}[]|CsvConversionError rt3a = 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...;|}[]|CsvConversionError rt4a = 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...;|}[]|CsvConversionError rt5a = 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)][]|CsvConversionError rt6a = + 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][]|CsvConversionError rt7a = 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][]|CsvConversionError rt8a = 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...][]|CsvConversionError rt9a = 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...][]|CsvConversionError rt10a = 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:assertTrue(rt10a is CsvConversionError); + test:assertEquals((rt10a).message(), generateErrorMessageForInvalidValueForArrayType("1", "0", "data.csv:C2")); + + record{ + readonly & int a; + readonly & string b; + (readonly & boolean) | (readonly & decimal) c; + }[]|CsvConversionError rt11a = 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;}[]|CsvConversionError rt12a = 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;}[]|CsvConversionError rt12a_2 = parseListAsRecordType( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"], {stringConversion: false}); + + test:assertTrue(rt12a_2 is CsvConversionError); + test:assertEquals((rt12a_2).message(), + generateErrorMessageForInvalidFieldType("1", "a")); + + record{string|decimal a; B b; C c;}[]|CsvConversionError rt12a_3 = 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;}[]|CsvConversionError rt13a = 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...;|}[]|CsvConversionError rt14a = 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...;|}[]|CsvConversionError rt15a = parseListAsRecordType( + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] + , ["a", "b", "c", "d"]); + + test:assertEquals(rt15a , [ + {a: true, b: "string", c: true, d: "string"}, + {a: "2", b: "string2", c: false, d: "string2"}, + {a: "3", b: "string3", c: true, d: "string3"} + ]); + + record{|C2...;|}[]|CsvConversionError rt15a_2 = 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)][]|CsvConversionError rt16a = + 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][]|CsvConversionError rt17a = 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][]|CsvConversionError rt17a_2 = parseListAsListType( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {stringConversion: false}); + + test:assertTrue(rt17a_2 is CsvConversionError); + test:assertEquals((rt17a_2).message(), generateErrorMessageForInvalidValueForArrayType("1", "0", "data.csv:A")); + + [A2, B2, C2][]|CsvConversionError rt18a = 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...][]|CsvConversionError rt19a = 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...][]|CsvConversionError rt20a = parseListAsListType( + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); + + test:assertEquals(rt20a, [[true, "string",true, "string"], + ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); +} \ No newline at end of file diff --git a/ballerina/tests/user_config_projection_tests.bal b/ballerina/tests/user_config_projection_tests.bal index 1a1ac05..b0d96d0 100644 --- a/ballerina/tests/user_config_projection_tests.bal +++ b/ballerina/tests/user_config_projection_tests.bal @@ -1,39 +1,13 @@ import ballerina/test; -// boolean enable = !true; - -// @test:Config {enable: !enable} -// function debugTest() returns error? { -// // StringArrayArray|CsvConversionError st1saa = parseListAsListType([st1, st1], {}, StringArrayArray); -// // test:assertEquals(st1saa , [ -// // [s1, s2], -// // [s1, s2] -// // ]); - -// // StringArrayArray|CsvConversionError st2saa = parseListAsListType([st2, st2], {}, StringArrayArray); -// // test:assertEquals(st2saa , [ -// // [s1, s2, s3, s2], -// // [s1, s2, s3, s2] -// // ]); - -// // StringArrayArray|CsvConversionError st3saa = parseListAsListType([st3, st3], {}, StringArrayArray); -// // test:assertEquals(st3saa , [ -// // [s1, s2], -// // [s1, s2] -// // ]); - -// // StringArrayArray|CsvConversionError st4saa = parseListAsListType([st4, st4], {}, StringArrayArray); -// // test:assertEquals(st4saa , [ -// // [s1, s2, s3, s2], -// // [s1, s2, s3, s2] -// // ]); - -// // NillableStringArrayArray|CsvConversionError st1nsaa = parseListAsListType([st1, st1], {}, NillableStringArrayArray); -// // test:assertEquals(st1nsaa , [ -// // [s1, s2], -// // [s1, s2] -// // ]); -// } +boolean enable = true; + +@test:Config {enable: !enable} +function debugTest() returns error? { + RecordWithCustomAnnotation3[]|CsvConversionError cntr12 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + test:assertTrue(cntr12 is CsvConversionError); + test:assertEquals((cntr12).message(), "Duplicate field found in record fields: 'a'"); +} @test:Config {enable} function testCustomNameAnnotation() returns error? { @@ -223,7 +197,7 @@ function testCustomNameAnnotation() returns error? { } //TODO: Emable after fix tuple proj -@test:Config {enable: false} +@test:Config {enable} function testCustomNameAnnotation2() returns error? { RecordWithCustomAnnotation[]|CsvConversionError cntr1 = parseListAsRecordType([["1", "3"]], ["b", "c"], {}); test:assertEquals(cntr1, [{b: 1, a: 3}]); @@ -265,7 +239,7 @@ function testCustomNameAnnotation2() returns error? { RecordWithCustomAnnotation3[]|CsvConversionError cntr12 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); test:assertTrue(cntr12 is CsvConversionError); - test:assertEquals((cntr12).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr12).message(), generateErrorMessageForInvalidHeaders(string `["3","1"]`, "data.csv:RecordWithCustomAnnotation3")); RecordWithCustomAnnotation3[]|CsvConversionError cntr13 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); test:assertTrue(cntr13 is CsvConversionError); diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index 126de36..8b0e786 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -4,28 +4,10 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() returns error? { - -// string csvValue1 = string ` -// "a", b, c -// 1, "2a\t", "3b\n" -// "1c\n", 2, 3 -// 1, "2a\"", 3 - -// "1a\\", "2b\\"", "3"`; - -// string csvValue2 = string ` -// "a\"", "\tb\t\n", c -// 1, "2a\t", "3b\n" -// "1c\n", "/2/", 3 -// 1, "2a\"", "3" - -// "1a\\", "2b\\"", "3"`; - -// record {}[]|CsvConversionError cn = parseStringToRecord(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 {}[]|CsvConversionError cn2 = parseStringToRecord(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 {|int a; int f?;|}[]|CsvConversionError cn3 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { +// allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] +// }); +// test:assertEquals(cn3, [{a: 1}, {a: 2}]); // } @test:Config {enable} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index 3def988..093fcea 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -23,6 +23,8 @@ import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; +import io.ballerina.runtime.api.types.FiniteType; +import io.ballerina.runtime.api.types.IntersectionType; import io.ballerina.runtime.api.types.ReferenceType; import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.types.UnionType; @@ -31,13 +33,13 @@ import io.ballerina.runtime.api.values.BDecimal; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BString; -import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import java.util.ArrayList; import java.util.Comparator; -import java.util.HashMap; import java.util.List; import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.isNullValue; @@ -49,35 +51,36 @@ */ public class FromString { - private static final HashMap TYPE_PRIORITY_ORDER = new HashMap<>() {{ - int precedence = 0; - put(TypeTags.INT_TAG, precedence++); - put(TypeTags.FLOAT_TAG, precedence++); - put(TypeTags.DECIMAL_TAG, precedence++); - put(TypeTags.NULL_TAG, precedence++); - put(TypeTags.BOOLEAN_TAG, precedence++); - put(TypeTags.JSON_TAG, precedence++); - put(TypeTags.STRING_TAG, precedence); - }}; - - private static final ArrayList BASIC_JSON_MEMBER_TYPES = new ArrayList<>() {{ - add(PredefinedTypes.TYPE_NULL); - add(PredefinedTypes.TYPE_BOOLEAN); - add(PredefinedTypes.TYPE_INT); - add(PredefinedTypes.TYPE_FLOAT); - add(PredefinedTypes.TYPE_DECIMAL); - add(PredefinedTypes.TYPE_STRING); - }}; - private static final UnionType JSON_TYPE_WITH_BASIC_TYPES = TypeCreator.createUnionType(BASIC_JSON_MEMBER_TYPES); + private static final List TYPE_PRIORITY_ORDER = List.of( + TypeTags.INT_TAG, + TypeTags.FLOAT_TAG, + TypeTags.DECIMAL_TAG, + TypeTags.NULL_TAG, + TypeTags.BOOLEAN_TAG, + TypeTags.JSON_TAG, + TypeTags.STRING_TAG + ); - public static Object fromStringWithType(BString string, CsvConfig config, BTypedesc typed) { - Type expType = typed.getDescribingType(); - try { - return fromStringWithType(string, expType, config); - } catch (NumberFormatException e) { - return returnError(string.getValue(), expType.toString()); - } - } + private static final List BASIC_JSON_MEMBER_TYPES = List.of( + PredefinedTypes.TYPE_NULL, + PredefinedTypes.TYPE_BOOLEAN, + PredefinedTypes.TYPE_INT, + PredefinedTypes.TYPE_FLOAT, + PredefinedTypes.TYPE_DECIMAL, + PredefinedTypes.TYPE_STRING + ); + private static final UnionType JSON_TYPE_WITH_BASIC_TYPES = TypeCreator.createUnionType(BASIC_JSON_MEMBER_TYPES); + public static final Integer BBYTE_MIN_VALUE = 0; + public static final Integer BBYTE_MAX_VALUE = 255; + public static final Integer SIGNED32_MAX_VALUE = 2147483647; + public static final Integer SIGNED32_MIN_VALUE = -2147483648; + public static final Integer SIGNED16_MAX_VALUE = 32767; + public static final Integer SIGNED16_MIN_VALUE = -32768; + public static final Integer SIGNED8_MAX_VALUE = 127; + public static final Integer SIGNED8_MIN_VALUE = -128; + public static final Long UNSIGNED32_MAX_VALUE = 4294967295L; + public static final Integer UNSIGNED16_MAX_VALUE = 65535; + public static final Integer UNSIGNED8_MAX_VALUE = 255; public static Object fromStringWithType(BString string, Type expType, CsvConfig config) { String value = string.getValue(); @@ -85,22 +88,43 @@ public static Object fromStringWithType(BString string, Type expType, CsvConfig switch (expType.getTag()) { case TypeTags.INT_TAG: return stringToInt(value); + case TypeTags.BYTE_TAG: + return stringToByte(value); + case TypeTags.SIGNED8_INT_TAG: + return stringToSigned8Int(value); + case TypeTags.SIGNED16_INT_TAG: + return stringToSigned16Int(value); + case TypeTags.SIGNED32_INT_TAG: + return stringToSigned32Int(value); + case TypeTags.UNSIGNED8_INT_TAG: + return stringToUnsigned8Int(value); + case TypeTags.UNSIGNED16_INT_TAG: + return stringToUnsigned16Int(value); + case TypeTags.UNSIGNED32_INT_TAG: + return stringToUnsigned32Int(value); case TypeTags.FLOAT_TAG: return stringToFloat(value); case TypeTags.DECIMAL_TAG: return stringToDecimal(value); + case TypeTags.CHAR_STRING_TAG: + return stringToChar(value); case TypeTags.STRING_TAG: return string; case TypeTags.BOOLEAN_TAG: return stringToBoolean(value); case TypeTags.NULL_TAG: return stringToNull(value, config); + case TypeTags.FINITE_TYPE_TAG: + return stringToFiniteType(value, (FiniteType) expType, config); case TypeTags.UNION_TAG: return stringToUnion(string, (UnionType) expType, config); case TypeTags.JSON_TAG: + case TypeTags.ANYDATA_TAG: return stringToUnion(string, JSON_TYPE_WITH_BASIC_TYPES, config); case TypeTags.TYPE_REFERENCED_TYPE_TAG: return fromStringWithType(string, ((ReferenceType) expType).getReferredType(), config); + case TypeTags.INTERSECTION_TAG: + return fromStringWithType(string, ((IntersectionType) expType).getEffectiveType(), config); default: return returnError(value, expType.toString()); } @@ -109,10 +133,93 @@ public static Object fromStringWithType(BString string, Type expType, CsvConfig } } + private static Object stringToFiniteType(String value, FiniteType finiteType, CsvConfig config) { + return finiteType.getValueSpace().stream() + .filter(finiteValue -> !(convertToSingletonValue(value, finiteValue, config) instanceof BError)) + .findFirst() + .orElseGet(() -> returnError(value, finiteType.toString())); + } + + private static Object convertToSingletonValue(String str, Object singletonValue, CsvConfig config) { + String singletonStr = String.valueOf(singletonValue); + if (str.equals(singletonStr)) { + return fromStringWithType(StringUtils.fromString(str), TypeUtils.getType(singletonValue), config); + } else { + return returnError(str, singletonStr); + } + } + private static Long stringToInt(String value) throws NumberFormatException { return Long.parseLong(value); } + private static int stringToByte(String value) throws NumberFormatException { + int intValue = Integer.parseInt(value); + if (!isByteLiteral(intValue)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, PredefinedTypes.TYPE_BYTE, value); + } + return intValue; + } + + private static long stringToSigned8Int(String value) throws NumberFormatException { + long intValue = Long.parseLong(value); + if (!isSigned8LiteralValue(intValue)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, PredefinedTypes.TYPE_INT_SIGNED_8, value); + } + return intValue; + } + + private static long stringToSigned16Int(String value) throws NumberFormatException { + long intValue = Long.parseLong(value); + if (!isSigned16LiteralValue(intValue)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, PredefinedTypes.TYPE_INT_SIGNED_16, value); + } + return intValue; + } + + private static long stringToSigned32Int(String value) throws NumberFormatException { + long intValue = Long.parseLong(value); + if (!isSigned32LiteralValue(intValue)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, PredefinedTypes.TYPE_INT_SIGNED_32, value); + } + return intValue; + } + + private static long stringToUnsigned8Int(String value) throws NumberFormatException { + long intValue = Long.parseLong(value); + if (!isUnsigned8LiteralValue(intValue)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, + PredefinedTypes.TYPE_INT_UNSIGNED_8, value); + } + return intValue; + } + + private static long stringToUnsigned16Int(String value) throws NumberFormatException { + long intValue = Long.parseLong(value); + if (!isUnsigned16LiteralValue(intValue)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, + PredefinedTypes.TYPE_INT_UNSIGNED_16, value); + } + return intValue; + } + + private static long stringToUnsigned32Int(String value) throws NumberFormatException { + long intValue = Long.parseLong(value); + if (!isUnsigned32LiteralValue(intValue)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, + PredefinedTypes.TYPE_INT_UNSIGNED_32, value); + } + return intValue; + } + + private static BString stringToChar(String value) throws NumberFormatException { + if (!isCharLiteralValue(value)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, + PredefinedTypes.TYPE_STRING_CHAR, value); + } + return StringUtils.fromString(value); + } + private static Double stringToFloat(String value) throws NumberFormatException { if (hasFloatOrDecimalLiteralSuffix(value)) { throw new NumberFormatException(); @@ -144,17 +251,15 @@ private static Object stringToNull(String value, CsvConfig config) throws Number } private static Object stringToUnion(BString string, UnionType expType, CsvConfig config) throws NumberFormatException { - List memberTypes = expType.getMemberTypes(); - memberTypes.sort(Comparator.comparingInt(t -> TYPE_PRIORITY_ORDER.getOrDefault( - TypeUtils.getReferredType(t).getTag(), Integer.MAX_VALUE))); - boolean isStringExpType = false; + List memberTypes = new ArrayList<>(expType.getMemberTypes()); + memberTypes.sort(Comparator.comparingInt(t -> { + int index = TYPE_PRIORITY_ORDER.indexOf(TypeUtils.getReferredType(t).getTag()); + return index == -1 ? Integer.MAX_VALUE : index; + })); for (Type memberType : memberTypes) { try { Object result = fromStringWithType(string, memberType, config); - if (result instanceof BString) { - isStringExpType = true; - continue; - } else if (result instanceof BError) { + if (result instanceof BError) { continue; } return result; @@ -162,10 +267,6 @@ private static Object stringToUnion(BString string, UnionType expType, CsvConfig // Skip } } - - if (isStringExpType) { - return string; - } return returnError(string.getValue(), expType.toString()); } @@ -186,6 +287,38 @@ private static boolean hasFloatOrDecimalLiteralSuffix(String value) { } } + private static boolean isByteLiteral(long longValue) { + return (longValue >= BBYTE_MIN_VALUE && longValue <= BBYTE_MAX_VALUE); + } + + private static boolean isSigned32LiteralValue(Long longObject) { + return (longObject >= SIGNED32_MIN_VALUE && longObject <= SIGNED32_MAX_VALUE); + } + + private static boolean isSigned16LiteralValue(Long longObject) { + return (longObject.intValue() >= SIGNED16_MIN_VALUE && longObject.intValue() <= SIGNED16_MAX_VALUE); + } + + private static boolean isSigned8LiteralValue(Long longObject) { + return (longObject.intValue() >= SIGNED8_MIN_VALUE && longObject.intValue() <= SIGNED8_MAX_VALUE); + } + + private static boolean isUnsigned32LiteralValue(Long longObject) { + return (longObject >= 0 && longObject <= UNSIGNED32_MAX_VALUE); + } + + private static boolean isUnsigned16LiteralValue(Long longObject) { + return (longObject.intValue() >= 0 && longObject.intValue() <= UNSIGNED16_MAX_VALUE); + } + + private static boolean isUnsigned8LiteralValue(Long longObject) { + return (longObject.intValue() >= 0 && longObject.intValue() <= UNSIGNED8_MAX_VALUE); + } + + private static boolean isCharLiteralValue(String value) { + return value.codePoints().count() == 1; + } + private static BError returnError(String string, String expType) { return ErrorCreator.createError(StringUtils.fromString("Cannot convert to the exptype")); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 785b2d8..95a5fc7 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -30,17 +30,15 @@ import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.data.csvdata.FromString; -import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; +import org.ballerinalang.langlib.value.CloneReadOnly; -import java.util.HashMap; import java.util.Map; import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getUpdatedHeaders; - /** * Create objects for partially parsed csv. * @@ -75,7 +73,7 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, } Object convertedValue = convertToExpectedType(StringUtils.fromString(value), type, config); sm.isCurrentCsvNodeEmpty = false; - if (convertedValue instanceof BError) { + if (convertedValue instanceof BError || convertedValue instanceof CsvUtils.UnMappedValue) { if (ignoreIncompatibilityErrorsForMaps(sm, exptype)) { return null; } @@ -161,4 +159,8 @@ public static Object convertToExpectedType(BString value, Type type, CsvConfig c } return FromString.fromStringWithType(value, type, config); } + + public static Object constructReadOnlyValue(Object value) { + return CloneReadOnly.cloneReadOnly(value); + } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 55dd63b..e607180 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -25,9 +25,6 @@ import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; -import io.ballerina.runtime.api.values.BMap; -import io.ballerina.runtime.api.values.BString; -import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; @@ -299,9 +296,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C continue; } sm.isHeaderConfigExceedLineNumber = false; -// if (!(isWhitespace(ch, sm.config.lineTerminator) && sm.isNewLineOrEof(ch))) { -// headerStart = true; -// } if (customHeader != null) { if (sm.isNewLineOrEof(ch)) { checkAndAddCustomHeaders(sm, customHeader); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 3587062..c8f7cd7 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -155,8 +155,8 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected RecordType recordType = (RecordType) expectedType; this.fieldHierarchy = new HashMap<>(recordType.getFields()); fields = new HashSet<>(recordType.getFields().keySet()); - this.updatedRecordFieldNames = - processNameAnnotationsAndBuildCustomFieldMap(recordType, fieldHierarchy); + this.updatedRecordFieldNames = processNameAnnotationsAndBuildCustomFieldMap( + recordType, fieldHierarchy); this.headerFieldHierarchy = new HashMap<>(recordType.getFields()); this.restType = recordType.getRestFieldType(); currentCsvNode = ValueCreator.createRecordValue(recordType.getPackage(), recordType.getName()); @@ -353,8 +353,6 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Tup if (isHeaderFieldsEmpty(this.headerFieldHierarchy)) { continue; } - - return false; } return true; @@ -368,9 +366,9 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Typ return true; } - for (String key: this.fieldHierarchy.keySet()) { + for (String key: this.fieldHierarchy.keySet()) { // fh -> a,b | headers -> d,c for(String header: this.headers) { - if (key.equals(header)) { + if (key.equals(this.updatedRecordFieldNames.get(header))) { return true; } } @@ -460,7 +458,7 @@ private void addFieldInMapType(BString key) { fieldNames.push(key.toString()); } - private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BString key, boolean isMapType) { + private void addCurrentFieldValue2(Type currentFieldType, Object mapValue, BString key, boolean isMapType) { int currentFieldTypeTag = currentFieldType.getTag(); Object nilValue = config.nilValue; if (config.nilAsOptionalField && !currentFieldType.isNilable() @@ -514,52 +512,95 @@ private void addCurrentFieldValue(Type currentFieldType, Object mapValue, BStrin } } - private void addRestField(Type restFieldType, BString key, Object csvMember) { + private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { + Type fieldType = TypeUtils.getReferredType(type); Object nilValue = config.nilValue; - if (config.nilAsOptionalField && !restFieldType.isNilable() + if (!isRecursive && config.nilAsOptionalField && !fieldType.isNilable() && CsvUtils.isNullValue(nilValue, csvMember) && currentField != null && SymbolFlags.isFlagOn(currentField.getFlags(), SymbolFlags.OPTIONAL)) { - return; + return SkipMappedValue.createSkippedValue(); } - switch (restFieldType.getTag()) { - case TypeTags.ANYDATA_TAG: - case TypeTags.JSON_TAG: - case TypeTags.BOOLEAN_TAG: - case TypeTags.INT_TAG: - case TypeTags.FLOAT_TAG: - case TypeTags.DECIMAL_TAG: - case TypeTags.STRING_TAG: - case TypeTags.NULL_TAG: - if (checkTypeCompatibility(restFieldType, csvMember, config.stringConversion)) { - Object value = convertToBasicType(csvMember, restFieldType, config); - if (!(value instanceof BError)) { - ((BMap) currentCsvNode).put(key, value); + if (config.stringConversion && csvMember instanceof BString str) { + Object convertedValue = CsvCreator.convertToExpectedType(str, type, config); + if (!(convertedValue instanceof BError)) { + return convertedValue; + } + } else { + switch (fieldType.getTag()) { // type.toString().equals("ballerina/data.csv:0:A") + case TypeTags.NULL_TAG: + case TypeTags.BOOLEAN_TAG: + case TypeTags.INT_TAG: + case TypeTags.FLOAT_TAG: + case TypeTags.DECIMAL_TAG: + case TypeTags.STRING_TAG: + case TypeTags.JSON_TAG: + case TypeTags.ANYDATA_TAG: + if (checkTypeCompatibility(fieldType, csvMember, config.stringConversion)) { + Object value = convertToBasicType(csvMember, fieldType, config); + if (!(value instanceof BError)) { + return value; + } } - } - break; - case TypeTags.UNION_TAG: - for (Type memberType: ((UnionType) restFieldType).getMemberTypes()) { - if (!isBasicType(memberType)) { - throw DiagnosticLog.error(DiagnosticErrorCode - .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); + break; + case TypeTags.UNION_TAG: + for (Type memberType : ((UnionType) fieldType).getMemberTypes()) { + if (!isBasicType(memberType)) { + throw DiagnosticLog.error(DiagnosticErrorCode + .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); + } + Object value = getFieldValue(memberType, csvMember, true); + if (!(value instanceof BError || value instanceof UnMappedValue)) { + return value; + } } - if (checkTypeCompatibility(memberType, csvMember, config.stringConversion)) { - Object value = convertToBasicType(csvMember, memberType, config); - if (!(value instanceof BError)) { - ((BMap) currentCsvNode).put(key, value); - break; + break; + case TypeTags.INTERSECTION_TAG: + Type effectiveType = ((IntersectionType) fieldType).getEffectiveType(); + if (!SymbolFlags.isFlagOn(SymbolFlags.READONLY, effectiveType.getFlags())) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type); + } + for (Type constituentType : ((IntersectionType) fieldType).getConstituentTypes()) { + if (constituentType.getTag() == TypeTags.READONLY_TAG) { + continue; } + return CsvCreator.constructReadOnlyValue(getFieldValue(constituentType, csvMember, true)); } - } - break; - case TypeTags.INTERSECTION_TAG: - for (Type memberType: ((IntersectionType) restFieldType).getConstituentTypes()) { - // - } - break; - default: - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, csvMember, key); + break; + default: + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TYPE, type); + } + } + return UnMappedValue.createUnMappedValue(); + } + + private void addRestField(Type type, BString key, Object csvMember) { + Object value = getFieldValue(type, csvMember, false); + if (!(value instanceof UnMappedValue)) { + ((BMap) currentCsvNode).put(key, value); + } + } + + private void addCurrentFieldValue(Type type, Object RecValue, BString key, boolean isMapType) { + Object value = getFieldValue(type, RecValue, false); + if (!(value instanceof UnMappedValue || value instanceof SkipMappedValue)) { + ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), value); + return; + } + + if (isMapType || value instanceof SkipMappedValue) { + return; + } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, RecValue, key); + } + + public void addValuesToArrayType(Object arrayValue, Type type, int index, + Object currentCsvNode, CsvConfig config) { + Object value = getFieldValue(type, arrayValue, false); + if (!(value instanceof UnMappedValue)) { + ((BArray) currentCsvNode).add(index, value); + return; } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_ARRAY, arrayValue, index, type); } private void setRootCsvNode(Type referredType, Type type) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index dd22ab6..def1d74 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -33,6 +33,8 @@ public static boolean isBasicType(Type type) { case TypeTags.NULL_TAG: case TypeTags.JSON_TAG: case TypeTags.ANYDATA_TAG: + case TypeTags.UNION_TAG: + case TypeTags.INTERSECTION_TAG: return true; default: return false; @@ -106,9 +108,6 @@ public static Object convertToBasicType(Object csv, Type targetType, CsvConfig c if (csv == null) { csv = config.nilValue; } - if (config.stringConversion && csv instanceof BString) { - return CsvCreator.convertToExpectedType((BString) csv, targetType, config); - } return ValueUtils.convert(csv, targetType); } @@ -135,11 +134,12 @@ public static boolean isHeaderFieldsEmpty(Map currentField) { public static boolean checkTypeCompatibility(Type constraintType, Object csv, boolean stringConversion) { int tag = constraintType.getTag(); if ((csv instanceof BString && (stringConversion || tag == TypeTags.STRING_TAG || isJsonOrAnyDataOrAny(tag))) - || (csv instanceof Long && (tag == INT_TAG || isJsonOrAnyDataOrAny(tag))) + || (csv instanceof Long && (tag == INT_TAG || tag == TypeTags.FLOAT_TAG + || tag == TypeTags.DECIMAL_TAG || isJsonOrAnyDataOrAny(tag))) || (csv instanceof BDecimal && ((tag == TypeTags.DECIMAL_TAG - || tag == TypeTags.FLOAT_TAG) || isJsonOrAnyDataOrAny(tag))) + || tag == TypeTags.FLOAT_TAG || tag == INT_TAG) || isJsonOrAnyDataOrAny(tag))) || (csv instanceof Double && ((tag == TypeTags.FLOAT_TAG - || tag == TypeTags.DECIMAL_TAG) || isJsonOrAnyDataOrAny(tag))) + || tag == TypeTags.DECIMAL_TAG || tag == INT_TAG) || isJsonOrAnyDataOrAny(tag))) || (Boolean.class.isInstance(csv) && (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag))) || (csv == null && (tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag)))) { return true; @@ -152,7 +152,7 @@ private static boolean isJsonOrAnyDataOrAny(int tag) { return tag == TypeTags.JSON_TAG || tag == TypeTags.ANYDATA_TAG || tag == TypeTags.ANY_TAG; } - public static void addValuesToArrayType(Object csvElement, Type arrayElementType, int index, + public static void addValuesToArrayType2(Object csvElement, Type arrayElementType, int index, Object currentCsvNode, CsvConfig config) { switch (arrayElementType.getTag()) { case TypeTags.NULL_TAG: @@ -163,7 +163,6 @@ public static void addValuesToArrayType(Object csvElement, Type arrayElementType case TypeTags.STRING_TAG: case TypeTags.JSON_TAG: case TypeTags.ANYDATA_TAG: - case TypeTags.ANY_TAG: if (checkTypeCompatibility(arrayElementType, csvElement, config.stringConversion)) { Object value = convertToBasicType(csvElement, arrayElementType, config); if (!(value instanceof BError)) { @@ -338,4 +337,24 @@ public SortConfigurations(Object columnName, Object sortOrder) { this.sortOrder = sortOrder; } } + + public static class UnMappedValue { + private static UnMappedValue value = null; + public static UnMappedValue createUnMappedValue() { + if (value == null) { + value = new UnMappedValue(); + } + return value; + } + } + + public static class SkipMappedValue { + private static SkipMappedValue value = null; + public static SkipMappedValue createSkippedValue() { + if (value == null) { + value = new SkipMappedValue(); + } + return value; + } + } } diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index b92a09d..041aa25 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -21,7 +21,7 @@ # ------------------------- error.invalid.type=\ - invalid expected type ''{0}'', expected a subtype of (map|anydata)[] + invalid expected type ''{0}'', expected a subtype of (map|anydata[])[] error.union.types.not.allowed.as.expected.type=\ union types are not allowed in the expected type, found ''{0}'' From 360ea4d185e9cbaedd65a7e9c3200486e9c8af50 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 20 Jun 2024 09:43:32 +0530 Subject: [PATCH 036/147] Add constraint validations --- ballerina/Ballerina.toml | 6 ++ ballerina/Dependencies.toml | 13 +++ ballerina/build.gradle | 17 ++++ ballerina/csv_api.bal | 6 +- .../tests/constraint_validation_test.bal | 86 +++++++++++++++++++ .../tests/parse_record_type_as_list_test.bal | 3 + .../tests/user_config_projection_tests.bal | 17 ++-- ballerina/types.bal | 17 ++-- build-config/resources/Ballerina.toml | 6 ++ build.gradle | 1 + gradle.properties | 1 + native/build.gradle | 3 + .../stdlib/data/csvdata/csv/CsvParser.java | 12 ++- .../stdlib/data/csvdata/csv/CsvTraversal.java | 6 +- .../stdlib/data/csvdata/csv/Native.java | 16 ++-- .../data/csvdata/io/DataReaderTask.java | 2 +- .../stdlib/data/csvdata/utils/Constants.java | 2 + .../stdlib/data/csvdata/utils/CsvConfig.java | 44 ++++++++-- .../stdlib/data/csvdata/utils/CsvUtils.java | 79 ----------------- .../stdlib/data/csvdata/utils/DataUtils.java | 28 ++++++ native/src/main/java/module-info.java | 1 + 21 files changed, 247 insertions(+), 119 deletions(-) create mode 100644 ballerina/tests/constraint_validation_test.bal create mode 100644 native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index ecae9dc..f1d6945 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -17,3 +17,9 @@ groupId = "io.ballerina.stdlib" artifactId = "data.csv-native" version = "0.1.0" path = "../native/build/libs/data.csv-native-0.1.0-SNAPSHOT.jar" + +[[platform.java17.dependency]] +groupId = "io.ballerina.stdlib" +artifactId = "constraint-native" +version = "1.5.0" +path = "./lib/constraint-native-1.5.0.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index f95f329..a702bf7 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -7,11 +7,24 @@ dependencies-toml-version = "2" distribution-version = "2201.8.6" +[[package]] +org = "ballerina" +name = "constraint" +version = "1.5.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "constraint", moduleName = "constraint"} +] + [[package]] org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ + {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] diff --git a/ballerina/build.gradle b/ballerina/build.gradle index af94bbb..6d74edf 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -65,10 +65,27 @@ ballerina { langVersion = ballerinaLangVersion } +configurations { + externalJars +} + +dependencies { + externalJars(group: 'io.ballerina.stdlib', name: 'constraint-native', version: "${stdlibConstraintVersion}") { + transitive = false + } +} + task updateTomlFiles { doLast { + def stdlibDependentConstraintNativeVersion = stdlibConstraintVersion + def stdlibDependentConstraintVersion = stripBallerinaExtensionVersion("${stdlibDependentConstraintNativeVersion}") + def newConfig = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version) newConfig = newConfig.replace("@toml.version@", tomlVersion) + + newConfig = newConfig.replace("@stdlib.constraintnative.version@", stdlibDependentConstraintNativeVersion) + newConfig = newConfig.replace("@constraint.version@", stdlibDependentConstraintVersion) + ballerinaTomlFile.text = newConfig // def newCompilerPluginToml = compilerPluginTomlFilePlaceHolder.text.replace("@project.version@", project.version) diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index f18171c..50039b5 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -37,7 +37,7 @@ public isolated function parseStreamToList(stream s, returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function parseRecordAsRecordType(record{}[] s, - Options options = {}, typedesc t = <>) + RecordAsRecordOption options = {}, typedesc t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function parseRecordAsListType(record{}[] s, string[] headerNames, @@ -45,10 +45,10 @@ public isolated function parseRecordAsListType(record{}[] s, string[] headerName returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; public isolated function parseListAsRecordType(string[][] s, string[]? customHeaders = (), - ListTypeOption options = {}, typedesc t = <>) + ListAsRecordOption options = {}, typedesc t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; -public isolated function parseListAsListType(string[][] s, ListTypeOption options = {}, typedesc t = <>) +public isolated function parseListAsListType(string[][] s, ListAsListOption options = {}, typedesc t = <>) returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; // -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- diff --git a/ballerina/tests/constraint_validation_test.bal b/ballerina/tests/constraint_validation_test.bal new file mode 100644 index 0000000..cf25c17 --- /dev/null +++ b/ballerina/tests/constraint_validation_test.bal @@ -0,0 +1,86 @@ +import ballerina/test; +import ballerina/constraint; + +boolean enable = true; + +// TODO: + +@test:Config {enable: !enable} +function debugTest() returns error? { + ConstrainedRec[]|CsvConversionError cRec3 = parseStringToRecord(string `a,b + 4,abc + 5, "d"`); + test:assertEquals(cRec3, ""); +} + +//TODO: Fix the below test cases + // ConstrainedRec[]|CsvConversionError cRec3 = parseStringToRecord(string `a,b + // 4,abc + // 5, "" `); + // test:assertEquals(cRec3, ""); + +// ConstrainedRec[]|CsvConversionError cRec3 = parseStringToRecord(string `a,b +// 4,abc +// 5, "" `); +// test:assertEquals(cRec3, ""); + +type ConstrainedRec record { + @constraint:Int { + minValue: 3, + maxValue: 10 + } + int a?; + @constraint:String { + minLength: 2 + } + string b; +}; + +@test:Config {enable} +function testConstraintWithRecords() returns error? { + ConstrainedRec[]|CsvConversionError cRec1 = parseStringToRecord(string `a,b + 4,abc + 3, cde`); + test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); + + cRec1 = parseStringToRecord(string `a,b + 4,abc + 11, cde`); + test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue((cRec1).message().startsWith("Validation failed") + && (cRec1).message().includes("maxValue")); + + cRec1 = parseStringToRecord(string `a,b + 4,abc + 5, "b"`, {}); + test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue((cRec1).message().startsWith("Validation failed") + && (cRec1).message().includes("minLength")); + + + cRec1 = parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 3, "b": "cde"}], {}); + test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); + + cRec1 = parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 11, "b": "cde"}], {}); + test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue((cRec1).message().startsWith("Validation failed") + && (cRec1).message().includes("maxValue")); + + cRec1 = parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 5, "b": "b"}], {}); + test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue((cRec1).message().startsWith("Validation failed") + && (cRec1).message().includes("minLength")); + + cRec1 = parseListAsRecordType([["4", "abc"], ["3", "cde"]], ["a", "b"]); + test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); + + cRec1 = parseListAsRecordType([["4", "abc"], ["11", "cde"]], ["a", "b"]); + test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue((cRec1).message().startsWith("Validation failed") + && (cRec1).message().includes("maxValue")); + + cRec1 = parseListAsRecordType([["4", "abc"], ["5", "b"]], ["a", "b"]); + test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue((cRec1).message().startsWith("Validation failed") + && (cRec1).message().includes("minLength")); +} \ No newline at end of file diff --git a/ballerina/tests/parse_record_type_as_list_test.bal b/ballerina/tests/parse_record_type_as_list_test.bal index 9b707b7..9e34059 100644 --- a/ballerina/tests/parse_record_type_as_list_test.bal +++ b/ballerina/tests/parse_record_type_as_list_test.bal @@ -373,7 +373,10 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { [true, false, (), true], [true, false, (), true] ]); +} +@test:Config {enable} +function testFromCsvWithTypeForMapAndTupleAsExpectedType2() { NillableBooleanTuple8Array|CsvConversionError bm1nb8t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple8Array); test:assertEquals(bm1nb8t, [ [true, false], diff --git a/ballerina/tests/user_config_projection_tests.bal b/ballerina/tests/user_config_projection_tests.bal index b0d96d0..8e33a39 100644 --- a/ballerina/tests/user_config_projection_tests.bal +++ b/ballerina/tests/user_config_projection_tests.bal @@ -1,13 +1,14 @@ import ballerina/test; -boolean enable = true; - -@test:Config {enable: !enable} -function debugTest() returns error? { - RecordWithCustomAnnotation3[]|CsvConversionError cntr12 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); - test:assertTrue(cntr12 is CsvConversionError); - test:assertEquals((cntr12).message(), "Duplicate field found in record fields: 'a'"); -} +// boolean enable = true; + +// @test:Config {enable: !enable} +// function debugTest() returns error? { +// record {|int a; int? g; int? h;|}[]|CsvConversionError cn = parseStringToRecord(csvStringData1, { +// allowDataProjection: {absentAsNilableType: true}, +// header: 1 +// }); +// } @test:Config {enable} function testCustomNameAnnotation() returns error? { diff --git a/ballerina/types.bal b/ballerina/types.bal index 0b40017..b708124 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -40,17 +40,22 @@ public type parseToRecordOption record {| // if header = false and this value is null, Then compiler time error. string[]? customHeaders = (); + boolean enableConstraintValidation = true; |}; -public type ToRecordOptions record { - *Options; +public type ListAsListOption record {| + *Options; + boolean stringConversion = true; +|}; - // if source is array and this field is null => compile time error - string[]? customHeaders = (); -}; +public type RecordAsRecordOption record {| + *Options; + boolean enableConstraintValidation = true; +|}; -public type ListTypeOption record {| +public type ListAsRecordOption record {| *Options; + boolean enableConstraintValidation = true; boolean stringConversion = true; |}; diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index 3db6b47..ea02379 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -17,3 +17,9 @@ groupId = "io.ballerina.stdlib" artifactId = "data.csv-native" version = "@toml.version@" path = "../native/build/libs/data.csv-native-@project.version@.jar" + +[[platform.java17.dependency]] +groupId = "io.ballerina.stdlib" +artifactId = "constraint-native" +version = "@constraint.version@" +path = "./lib/constraint-native-@stdlib.constraintnative.version@.jar" diff --git a/build.gradle b/build.gradle index ac38747..cca8674 100644 --- a/build.gradle +++ b/build.gradle @@ -68,6 +68,7 @@ subprojects { dependencies { /* Standard libraries */ ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${stdlibIoVersion}" + ballerinaStdLibs "io.ballerina.stdlib:constraint-ballerina:${stdlibConstraintVersion}" } } diff --git a/gradle.properties b/gradle.properties index da791ab..8f5d926 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,3 +13,4 @@ underCouchDownloadVersion=4.0.4 researchgateReleaseVersion=2.8.0 ballerinaGradlePluginVersion=2.0.1 stdlibIoVersion=1.6.0 +stdlibConstraintVersion=1.5.0 diff --git a/native/build.gradle b/native/build.gradle index c1158de..95ca507 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -33,6 +33,9 @@ dependencies { implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}" implementation group: 'org.ballerinalang', name: 'ballerina-runtime', version: "${ballerinaLangVersion}" implementation group: 'org.ballerinalang', name: 'value', version: "${ballerinaLangVersion}" + implementation group: 'org.ballerinalang', name: 'value', version: "${ballerinaLangVersion}" + implementation group: 'io.ballerina.stdlib', name: 'constraint-native', version: "${stdlibConstraintVersion}" + // ballerinaStdLibs "io.ballerina.stdlib:constraint-ballerina:${stdlibConstraintVersion}" } checkstyle { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index e607180..de22caf 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -25,8 +25,10 @@ import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; +import io.ballerina.stdlib.data.csvdata.utils.DataUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; import org.apache.commons.lang3.StringEscapeUtils; @@ -59,11 +61,12 @@ public class CsvParser { private static final ThreadLocal tlStateMachine = ThreadLocal.withInitial(StateMachine::new); - public static Object parse(Reader reader, Type type, CsvConfig config) + public static Object parse(Reader reader, BTypedesc type, CsvConfig config) throws BError { StateMachine sm = tlStateMachine.get(); try { - return sm.execute(reader, TypeUtils.getReferredType(type), config); + Object convertedValue = sm.execute(reader, TypeUtils.getReferredType(type.getDescribingType()), config); + return DataUtils.validateConstraints(convertedValue, type, config.enableConstraintValidation); } finally { // Need to reset the state machine before leaving. Otherwise, references to the created // CSV values will be maintained and the java GC will not happen properly. @@ -165,6 +168,9 @@ private void processLocation(char ch) { } private String value() { + if (this.charBuffIndex == 0) { + return ""; + } String result = new String(this.charBuff, 0, this.charBuffIndex); this.charBuffIndex = 0; return result; @@ -669,7 +675,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) state = STRING_ESCAPE_VALUE_STATE; sm.isQuoteClosed = false; break; - } else if (!sm.isQuoteClosed && ch == EOF) { + } else if (!sm.isQuoteClosed && !sm.peek().isEmpty() && ch == EOF) { throw new CsvParserException("unexpected end of csv stream"); } else { if (!sm.isQuoteClosed) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index c8f7cd7..cfd43ef 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -28,6 +28,7 @@ import io.ballerina.runtime.api.values.*; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; +import io.ballerina.stdlib.data.csvdata.utils.DataUtils; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; @@ -42,10 +43,11 @@ */ public class CsvTraversal { private static final ThreadLocal tlCsvTree = ThreadLocal.withInitial(CsvTree::new); - public static Object traverse(BArray csv, CsvConfig config, Type type) { + public static Object traverse(BArray csv, CsvConfig config, BTypedesc type) { CsvTree csvTree = tlCsvTree.get(); try { - return csvTree.traverseCsv(csv, config, type); + Object convertedValue = csvTree.traverseCsv(csv, config, type.getDescribingType()); + return DataUtils.validateConstraints(convertedValue, type, config.enableConstraintValidation); } catch (BError e) { return e; } finally { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index eb28766..ea1bd11 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -42,7 +42,7 @@ public class Native { public static Object parseStringToRecord(BString csv, BMap options, BTypedesc type) { try { return CsvParser.parse(new StringReader(csv.getValue()), - type.getDescribingType(), CsvConfig.createParserToRecordOptions(options)); + type, CsvConfig.createParserToRecordOptions(options)); } catch (BError e) { return e; } catch (Exception e) { @@ -54,7 +54,7 @@ public static Object parseBytesToRecord(BArray csv, BMap option try { byte[] bytes = csv.getBytes(); return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), - type.getDescribingType(), CsvConfig.createParserToRecordOptions(options)); + type, CsvConfig.createParserToRecordOptions(options)); } catch (BError e) { return e; } catch (Exception e) { @@ -80,7 +80,7 @@ public static Object parseStreamToRecord(Environment env, BStream csv, public static Object parseStringToList(BString csv, BMap options, BTypedesc type) { try { return CsvParser.parse(new StringReader(csv.getValue()), - type.getDescribingType(), CsvConfig.createParseOptions(options)); + type, CsvConfig.createParseOptions(options)); } catch (BError e) { return e; } catch (Exception e) { @@ -91,7 +91,7 @@ public static Object parseBytesToList(BArray csv, BMap options, try { byte[] bytes = csv.getBytes(); return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), - type.getDescribingType(), CsvConfig.createParseOptions(options)); + type, CsvConfig.createParseOptions(options)); } catch (BError e) { return e; } catch (Exception e) { @@ -118,7 +118,7 @@ public static Object parseStreamToList(Environment env, BStream csv, public static Object parseRecordAsRecordType(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvConfig.createOptions(options), type.getDescribingType()); + return CsvTraversal.traverse(csv, CsvConfig.createRecordAsRecordOption(options), type); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } @@ -128,7 +128,7 @@ public static Object parseRecordAsListType(BArray csv, BArray headers, try { CsvConfig toRecordOptions = CsvConfig.createToRecordOptions(options); toRecordOptions.headersOrder = headers; - return CsvTraversal.traverse(csv, toRecordOptions, type.getDescribingType()); + return CsvTraversal.traverse(csv, toRecordOptions, type); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } @@ -138,7 +138,7 @@ 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.getDescribingType()); + return CsvTraversal.traverse(csv, CsvConfig.createListAsRecordTypeOptions(options), type); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } @@ -146,7 +146,7 @@ public static Object parseListAsRecordType(BArray csv, Object customHeaders, public static Object parseListAsListType(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvConfig.createListTypeOptions(options), type.getDescribingType()); + return CsvTraversal.traverse(csv, CsvConfig.createListTypeOptions(options), type); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java index 46d33fe..04ec333 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java @@ -85,7 +85,7 @@ public void run() { try (var byteBlockSteam = new BallerinaByteBlockInputStream(env, iteratorObj, resolveNextMethod(iteratorObj), resolveCloseMethod(iteratorObj), resultConsumer)) { Object result = CsvParser.parse(new InputStreamReader(byteBlockSteam), - typed.getDescribingType(), this.config); + typed, this.config); future.complete(result); } catch (Exception e) { future.complete(DiagnosticLog.getCsvError("Error occurred while reading the stream: " + e.getMessage())); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java index 10af919..ee88c18 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -20,6 +20,8 @@ public static class ConfigConstants { public static BString ALLOW_DATA_PROJECTION = StringUtils.fromString("allowDataProjection"); public static BString CUSTOM_HEADERS = StringUtils.fromString("customHeaders"); public static BString STRING_CONVERSION = StringUtils.fromString("stringConversion"); + public static final BString ENABLE_CONSTRAINT_VALIDATION = StringUtils. + fromString("enableConstraintValidation"); } public static class Values { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java index 6d9f316..98f8432 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java @@ -24,6 +24,7 @@ public class CsvConfig { public Object customHeader = null; public BArray headersOrder = null; public boolean stringConversion = false; + public boolean enableConstraintValidation = false; private CsvConfig(Object skipLines, boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection) { @@ -33,6 +34,15 @@ private CsvConfig(Object skipLines, boolean nilAsOptionalField, this.allowDataProjection = allowDataProjection; } + 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; @@ -51,14 +61,26 @@ private CsvConfig(Object skipLines, boolean nilAsOptionalField, this.stringConversion = stringConversion; } +// private CsvConfig(Object skipLines, boolean nilAsOptionalField, boolean absentAsNilableType, +// boolean allowDataProjection, boolean stringConversion, Object customHeader) { +// this.skipLines = skipLines; +// this.nilAsOptionalField = nilAsOptionalField; +// this.absentAsNilableType = absentAsNilableType; +// this.allowDataProjection = allowDataProjection; +// this.stringConversion = stringConversion; +// this.customHeader = customHeader; +// } + private CsvConfig(Object skipLines, boolean nilAsOptionalField, boolean absentAsNilableType, - boolean allowDataProjection, boolean stringConversion, Object customHeader) { + 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; } public static CsvConfig createListTypeOptions(BMap options) { @@ -80,7 +102,8 @@ public static CsvConfig createListAsRecordTypeOptions(BMap opti options.getBooleanValue(ABSENT_AS_NILABLE).booleanValue(), options.getBooleanValue(ALLOW_DATA_PROJECTION).booleanValue(), options.getBooleanValue(STRING_CONVERSION).booleanValue(), - options.get(CUSTOM_HEADERS) + options.get(CUSTOM_HEADERS), + options.getBooleanValue(ENABLE_CONSTRAINT_VALIDATION).booleanValue() ); } @@ -106,7 +129,7 @@ private CsvConfig(char delimiter, char textEnclosure, Object header, private CsvConfig(char delimiter, char textEnclosure, Object header, char escapeChar, Object lineTerminator, Object skipLines, Object nilValue, char comment, String locale, String encoding, boolean nilAsOptionalField, boolean absentAsNilableType, - boolean allowDataProjection, Object customHeaders) { + boolean allowDataProjection, Object customHeaders, boolean enableConstraintValidation) { this.delimiter = delimiter; this.textEnclosure = textEnclosure; this.header = header; @@ -121,15 +144,17 @@ private CsvConfig(char delimiter, char textEnclosure, Object header, char escape this.allowDataProjection = allowDataProjection; this.skipLines = skipLines; this.customHeader = customHeaders; + this.enableConstraintValidation = enableConstraintValidation; } - public static CsvConfig createOptions(BMap options) { + public static CsvConfig createRecordAsRecordOption(BMap options) { updateDataProjectOptions(options); return new CsvConfig( - options.get(SKIP_LINES), - options.getBooleanValue(NIL_AS_OPTIONAL), - options.getBooleanValue(ABSENT_AS_NILABLE), - options.getBooleanValue(ALLOW_DATA_PROJECTION) + options.getBooleanValue(ENABLE_CONSTRAINT_VALIDATION), + options.get(SKIP_LINES), + options.getBooleanValue(NIL_AS_OPTIONAL), + options.getBooleanValue(ABSENT_AS_NILABLE), + options.getBooleanValue(ALLOW_DATA_PROJECTION) ); } @@ -168,7 +193,8 @@ public static CsvConfig createParserToRecordOptions(BMap option options.getBooleanValue(NIL_AS_OPTIONAL), options.getBooleanValue(ABSENT_AS_NILABLE), options.getBooleanValue(ALLOW_DATA_PROJECTION), - options.get(CUSTOM_HEADERS) + options.get(CUSTOM_HEADERS), + options.getBooleanValue(ENABLE_CONSTRAINT_VALIDATION) ); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index def1d74..b5e9c97 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -41,47 +41,6 @@ public static boolean isBasicType(Type type) { } } - public static Object getRowValueForSort(Object row, Object columnName) { - if (row instanceof BMap) { - return ((BMap) row).get(columnName); - } else { - if (columnName instanceof Long) { - return ((BArray) row).get((long) columnName); - } else { - // TODO: Add a new error - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, "Test", "Test"); - } - } - } - - public static int compareTwoColumnAndGetValue(Object o1, Object o2) { - if (o1 == null && o2 ==null) { - return 0; - } - if (o1 == null) { - return -1; - } - if (o2 == null) { - return 1; - } - if (o1 instanceof Long && o2 instanceof Long) { - return ((Long) o1).compareTo((Long) o2); - } - if (o1 instanceof Boolean && o2 instanceof Boolean) { - return ((Boolean) o1).compareTo((Boolean) o2); - } - if (o1 instanceof BDecimal && o2 instanceof BDecimal) { - return (((BDecimal) o1).decimalValue()).compareTo(((BDecimal) o1).decimalValue()); - } - if (o1 instanceof Float && o2 instanceof Float) { - return ((Float) o1).compareTo((Float) o2); - } - if (o1 instanceof Double && o2 instanceof Double) { - return ((Double) o1).compareTo((Double) o2); - } - return (StringUtils.getStringValue(o1)).compareTo(StringUtils.getStringValue(o2)); - } - public static String[] createHeaders(String[] headers, CsvConfig config) { Object customHeaders = config.customHeader; @@ -152,44 +111,6 @@ private static boolean isJsonOrAnyDataOrAny(int tag) { return tag == TypeTags.JSON_TAG || tag == TypeTags.ANYDATA_TAG || tag == TypeTags.ANY_TAG; } - public static void addValuesToArrayType2(Object csvElement, Type arrayElementType, int index, - Object currentCsvNode, CsvConfig config) { - switch (arrayElementType.getTag()) { - case TypeTags.NULL_TAG: - case TypeTags.BOOLEAN_TAG: - case TypeTags.INT_TAG: - case TypeTags.FLOAT_TAG: - case TypeTags.DECIMAL_TAG: - case TypeTags.STRING_TAG: - case TypeTags.JSON_TAG: - case TypeTags.ANYDATA_TAG: - if (checkTypeCompatibility(arrayElementType, csvElement, config.stringConversion)) { - Object value = convertToBasicType(csvElement, arrayElementType, config); - if (!(value instanceof BError)) { - ((BArray) currentCsvNode).add(index, value); - return; - } - } - break; - case TypeTags.UNION_TAG: - for (Type memberType: ((UnionType) arrayElementType).getMemberTypes()) { - if (!isBasicType(memberType)) { - throw DiagnosticLog.error(DiagnosticErrorCode - .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); - } - if (checkTypeCompatibility(memberType, csvElement , config.stringConversion)) { - Object value = convertToBasicType(csvElement, memberType, config); - if (!(value instanceof BError)) { - ((BArray) currentCsvNode).add(index, value); - return; - } - } - } - break; - } - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_ARRAY, csvElement, index, arrayElementType); - } - public static int getTheActualExpectedType(Type type) { if (type instanceof TupleType) { TupleType tupleType = (TupleType) type; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java new file mode 100644 index 0000000..06c1488 --- /dev/null +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java @@ -0,0 +1,28 @@ +package io.ballerina.stdlib.data.csvdata.utils; + +import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.values.BTypedesc; +import io.ballerina.stdlib.constraint.Constraints; + +public class DataUtils { + public static Object validateConstraints(Object convertedValue, BTypedesc typed, boolean requireValidation) { + if (!requireValidation) { + return convertedValue; + } + + Object result = Constraints.validate(convertedValue, typed); + if (result instanceof BError bError) { + return DiagnosticLog.getCsvError(getPrintableErrorMsg(bError)); + } + return convertedValue; + } + + private static String getPrintableErrorMsg(BError err) { + String errorMsg = err.getMessage() != null ? err.getMessage() : ""; + Object details = err.getDetails(); + if (details != null && !details.toString().equals("{}")) { + errorMsg += !errorMsg.isBlank() ? ", " : "" + details; + } + return errorMsg; + } +} diff --git a/native/src/main/java/module-info.java b/native/src/main/java/module-info.java index 9e77635..dfa31e5 100644 --- a/native/src/main/java/module-info.java +++ b/native/src/main/java/module-info.java @@ -21,6 +21,7 @@ requires io.ballerina.lang.value; requires junit; requires org.apache.commons.lang3; + requires io.ballerina.stdlib.constraint; exports io.ballerina.stdlib.data.csvdata.csv; exports io.ballerina.stdlib.data.csvdata.utils; } From 1f2c816c6cc00fbbd023aa20d0a8e23c45ae8773 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 24 Jun 2024 16:57:34 +0530 Subject: [PATCH 037/147] Add tests for internal union types --- .../tests/constraint_validation_test.bal | 18 +- .../tests/parse_string_compatibality_test.bal | 14 +- .../tests/parse_string_to_array_test.bal | 18 +- .../tests/parse_string_to_map_tests copy.bal | 24 +- .../tests/parse_string_to_record_tests.bal | 6 +- .../tests/parse_string_to_tuple_test.bal | 16 +- .../tests/parse_type_compatibility_test.bal | 8 +- ballerina/tests/test_data_values.bal | 28 +- ballerina/tests/test_with_union_types.bal | 514 ++++++++++++++++++ .../user_config_with_parser_options_test.bal | 30 +- .../stdlib/data/csvdata/FromString.java | 4 +- .../stdlib/data/csvdata/csv/CsvParser.java | 17 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 20 +- .../stdlib/data/csvdata/utils/CsvConfig.java | 21 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 7 +- .../csvdata/utils/DiagnosticErrorCode.java | 3 +- native/src/main/resources/error.properties | 3 + 17 files changed, 653 insertions(+), 98 deletions(-) create mode 100644 ballerina/tests/test_with_union_types.bal diff --git a/ballerina/tests/constraint_validation_test.bal b/ballerina/tests/constraint_validation_test.bal index cf25c17..5b74fe6 100644 --- a/ballerina/tests/constraint_validation_test.bal +++ b/ballerina/tests/constraint_validation_test.bal @@ -1,17 +1,17 @@ import ballerina/test; import ballerina/constraint; -boolean enable = true; +// boolean enable = true; -// TODO: +// // TODO: -@test:Config {enable: !enable} -function debugTest() returns error? { - ConstrainedRec[]|CsvConversionError cRec3 = parseStringToRecord(string `a,b - 4,abc - 5, "d"`); - test:assertEquals(cRec3, ""); -} +// @test:Config {enable: !enable} +// function debugTest() returns error? { +// ConstrainedRec[]|CsvConversionError cRec3 = parseStringToRecord(string `a,b +// 4,abc +// 5, "d"`); +// test:assertEquals(cRec3, ""); +// } //TODO: Fix the below test cases // ConstrainedRec[]|CsvConversionError cRec3 = parseStringToRecord(string `a,b diff --git a/ballerina/tests/parse_string_compatibality_test.bal b/ballerina/tests/parse_string_compatibality_test.bal index a0eb6de..02e6ab5 100644 --- a/ballerina/tests/parse_string_compatibality_test.bal +++ b/ballerina/tests/parse_string_compatibality_test.bal @@ -105,12 +105,12 @@ function testFromCsvStringWithTypeCompatibility() { test:assertTrue(m3rrta is CsvConversionError); test:assertEquals((m3rrta).message(), generateErrorMessageForInvalidCast("1.2", "int")); - [boolean, int][]|CsvConversionError m4rrta = parseStringToList(string `a, b + [boolean|int, int|boolean][]|CsvConversionError m4rrta = parseStringToList(string `a, b 1, 1 0,0`); test:assertEquals(m4rrta, [ - [true, 1], - [false, 0] + [1, 1], + [0, 0] ]); record {|int...;|}[]|CsvConversionError irrma = parseStringToRecord(string ` @@ -193,12 +193,4 @@ function testFromCsvStringWithTypeCompatibility() { 1.2, abc, true,1.0`); test:assertTrue(m3rra is CsvConversionError); test:assertEquals((m3rra).message(), generateErrorMessageForInvalidCast("1.0", "int")); - - record {int b; boolean a;}[]|CsvConversionError m4rra = parseStringToRecord(string `a, b - 1, 1 - 0,0`); - test:assertEquals(m4rra, [ - {a: true, b: 1}, - {a: false, b: 0} - ]); } \ No newline at end of file diff --git a/ballerina/tests/parse_string_to_array_test.bal b/ballerina/tests/parse_string_to_array_test.bal index 92a3a13..f361a91 100644 --- a/ballerina/tests/parse_string_to_array_test.bal +++ b/ballerina/tests/parse_string_to_array_test.bal @@ -108,8 +108,8 @@ function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { NillableIntOrUnionBooleanArrayArray|CsvConversionError cv4niubaa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4niubaa, [ - [true, (), (), 0], - [1, (), (), false] + [true, (), (), false], + [true, (), (), false] ]); NillableIntOrUnionBooleanArrayArray|CsvConversionError cv5niubaa = parseStringToList(csvStringWithBooleanValues5); @@ -150,8 +150,8 @@ function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { StringArray1Array|CsvConversionError cv4saa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4saa, [ - ["true", "()", "()", "0"], - ["1", "()", "null", "false"] + ["true", "()", "()", "false"], + ["true", "()", "null", "false"] ]); StringArray1Array|CsvConversionError cv5saa = parseStringToList(csvStringWithBooleanValues5); @@ -193,7 +193,7 @@ function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { StringArray2Array|CsvConversionError cv4s2aa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4s2aa, [ ["true", "()"], - ["1", "()"] + ["true", "()"] ]); StringArray2Array|CsvConversionError cv5s2aa = parseStringToList(csvStringWithBooleanValues5); @@ -234,8 +234,8 @@ function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { JsonArray1Array|CsvConversionError cv4jaa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4jaa, [ - [true, (), (), 0], - [1, (), (), false] + [true, (), (), false], + [true, (), (), false] ]); JsonArray1Array|CsvConversionError cv5jaa = parseStringToList(csvStringWithBooleanValues5); @@ -276,8 +276,8 @@ function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { AnydataArray1Array|CsvConversionError cv4anydaa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4anydaa, [ - [true, (), (), 0], - [1, (), (), false] + [true, (), (), false], + [true, (), (), false] ]); AnydataArray1Array|CsvConversionError cv5anydaa = parseStringToList(csvStringWithBooleanValues5); diff --git a/ballerina/tests/parse_string_to_map_tests copy.bal b/ballerina/tests/parse_string_to_map_tests copy.bal index a987ee6..81e0b2b 100644 --- a/ballerina/tests/parse_string_to_map_tests copy.bal +++ b/ballerina/tests/parse_string_to_map_tests copy.bal @@ -120,8 +120,8 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { NillableIntUnionBooleanMapArray|CsvConversionError bv4bniubma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bniubma, [ - {b1: true, b2: (), b3: (), b4: 0}, - {b1: 1, b2: (), b3: (), b4: false} + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} ]); NillableIntUnionBooleanMapArray|CsvConversionError bv5bniubma = parseStringToRecord(csvStringWithBooleanValues5); @@ -162,8 +162,8 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { IntUnionBooleanMapArray|CsvConversionError bv4biubma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4biubma, [ - {b1: true, b4: 0}, - {b1: 1, b4: false} + {b1: true, b4: false}, + {b1: true, b4: false} ]); IntUnionBooleanMapArray|CsvConversionError bv5biubma = parseStringToRecord(csvStringWithBooleanValues5); @@ -246,8 +246,8 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { JsonMapArray|CsvConversionError bv4bjma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bjma, [ - {b1: true, b2: (), b3: (), b4: 0}, - {b1: 1, b2: (), b3: (), b4: false} + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} ]); JsonMapArray|CsvConversionError bv5bjma = parseStringToRecord(csvStringWithBooleanValues5); @@ -288,8 +288,8 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { AnydataMapArray|CsvConversionError bv4banydma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4banydma, [ - {b1: true, b2: (), b3: (), b4: 0}, - {b1: 1, b2: (), b3: (), b4: false} + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} ]); AnydataMapArray|CsvConversionError bv5banydma = parseStringToRecord(csvStringWithBooleanValues5); @@ -330,8 +330,8 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { CustomMapArray|CsvConversionError bv4bcma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bcma, [ - {b1: "true", b2: "()", b3: "()", b4: 0}, - {b1: 1, b2: "()", b3: "null", b4: "false"} + {b1: "true", b2: "()", b3: "()", b4: "false"}, + {b1: "true", b2: "()", b3: "null", b4: "false"} ]); CustomMapArray|CsvConversionError bv5bcma = parseStringToRecord(csvStringWithBooleanValues5); @@ -372,8 +372,8 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { StringMapArray|CsvConversionError bv4bsma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bsma, [ - {b1: "true", b2: "()", b3: "()", b4: "0"}, - {b1: "1", b2: "()", b3: "null", b4: "false"} + {b1: "true", b2: "()", b3: "()", b4: "false"}, + {b1: "true", b2: "()", b3: "null", b4: "false"} ]); StringMapArray|CsvConversionError bv5bsma = parseStringToRecord(csvStringWithBooleanValues5); diff --git a/ballerina/tests/parse_string_to_record_tests.bal b/ballerina/tests/parse_string_to_record_tests.bal index 2b21e5e..782b145 100644 --- a/ballerina/tests/parse_string_to_record_tests.bal +++ b/ballerina/tests/parse_string_to_record_tests.bal @@ -140,7 +140,7 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { BooleanRecord4Array|CsvConversionError csvb4br4 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br4, [ - {b1: true, b2: (), b3: (), b4: 0}, + {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); @@ -177,7 +177,7 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { BooleanRecord5Array|CsvConversionError csvb4br5 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br5, [ - {b1: true, b2: (), b3: (), b4: 0, defaultableField: "", nillableField: ()}, + {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} ]); @@ -472,7 +472,7 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { test:assertEquals(csvb1br17, [{}, {}, {}]); BooleanRecord17Array|CsvConversionError csvb4br17 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br17, [{b4: 0}, {b1: 1}]); + test:assertEquals(csvb4br17, [{}, {}]); BooleanRecord17Array|CsvConversionError csvb6br17 = parseStringToRecord(csvStringWithBooleanValues6, {}); test:assertEquals(csvb6br17, [{}]); diff --git a/ballerina/tests/parse_string_to_tuple_test.bal b/ballerina/tests/parse_string_to_tuple_test.bal index adb8985..344b467 100644 --- a/ballerina/tests/parse_string_to_tuple_test.bal +++ b/ballerina/tests/parse_string_to_tuple_test.bal @@ -298,8 +298,8 @@ function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { NillableIntBooleanTuple9Array|CsvConversionError cbv4bt9 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4bt9, [ - [true, (), (), 0], - [1, (), (), false] + [true, (), (), false], + [true, (), (), false] ]); NillableIntBooleanTuple9Array|CsvConversionError cbv5bt9 = parseStringToList(csvStringWithBooleanValues5); @@ -353,8 +353,8 @@ function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { AnydataTuple3Array|CsvConversionError cbv4anyd3 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4anyd3, [ - [true, (), (), 0], - [1, (), (), false] + [true, (), (), false], + [true, (), (), false] ]); AnydataTuple3Array|CsvConversionError cbv5anyd3 = parseStringToList(csvStringWithBooleanValues5); @@ -398,8 +398,8 @@ function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { JsonTuple3Array|CsvConversionError cbv4j3 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4j3, [ - [true, (), (), 0], - [1, (), (), false] + [true, (), (), false], + [true, (), (), false] ]); JsonTuple3Array|CsvConversionError cbv5j3 = parseStringToList(csvStringWithBooleanValues5); @@ -440,8 +440,8 @@ function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { StringTuple3Array|CsvConversionError cbv4s3 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4s3, [ - ["true", "()", "()", "0"], - ["1", "()", "null", "false"] + ["true", "()", "()", "false"], + ["true", "()", "null", "false"] ]); StringTuple3Array|CsvConversionError cbv5s3 = parseStringToList(csvStringWithBooleanValues5); diff --git a/ballerina/tests/parse_type_compatibility_test.bal b/ballerina/tests/parse_type_compatibility_test.bal index 26da174..d0f81f0 100644 --- a/ballerina/tests/parse_type_compatibility_test.bal +++ b/ballerina/tests/parse_type_compatibility_test.bal @@ -178,7 +178,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { 3,string3,true,string3`); test:assertEquals(r5a , [ - {a: true, b: "string", c: true, d: "string"}, + {a: "1", b: "string", c: true, d: "string"}, {a: "2", b: "string2", c: false, d: "string2"}, {a: "3", b: "string3", c: true, d: "string3"} ]); @@ -237,7 +237,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { 2,string2,false,string2 3,string3,true,string3`); - test:assertEquals(r20a, [[true, "string",true, "string"], + test:assertEquals(r20a, [["1", "string",true, "string"], ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); @@ -402,7 +402,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { , ["a", "b", "c", "d"]); test:assertEquals(rt15a , [ - {a: true, b: "string", c: true, d: "string"}, + {a: "1", b: "string", c: true, d: "string"}, {a: "2", b: "string2", c: false, d: "string2"}, {a: "3", b: "string3", c: true, d: "string3"} ]); @@ -465,6 +465,6 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [C2...][]|CsvConversionError rt20a = parseListAsListType( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); - test:assertEquals(rt20a, [[true, "string",true, "string"], + test:assertEquals(rt20a, [["1", "string",true, "string"], ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); } \ No newline at end of file diff --git a/ballerina/tests/test_data_values.bal b/ballerina/tests/test_data_values.bal index c46ac88..360a493 100644 --- a/ballerina/tests/test_data_values.bal +++ b/ballerina/tests/test_data_values.bal @@ -143,8 +143,8 @@ true, true,FALSE `; string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 - true,(), (),0 - 1,(), null,false + true,(), (),false + true,(), null,false `; @@ -168,8 +168,8 @@ string csvStringData1 = string ` a, b, c, d, e, f 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null - 3, string3, 0, 1.23, 1.23, () - 4, string4, 1, -6.51, -6.51, () + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; string csvStringData2 = string ` @@ -181,8 +181,8 @@ string csvStringData2 = string ` 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null - 3, string3, 0, 1.23, 1.23, () - 4, string4, 1, -6.51, -6.51, () + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; string csvStringData3 = string ` @@ -192,16 +192,16 @@ string csvStringData3 = string ` 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null - 3, string3, 0, 1.23, 1.23, () + 3, string3, false, 1.23, 1.23, () - 4, string4, 1, -6.51, -6.51, () + 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; string csvStringData4 = string ` 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null - 3, string3, 0, 1.23, 1.23, () - 4, string4, 1, -6.51, -6.51, () + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; string csvStringData5 = string ` @@ -211,8 +211,8 @@ string csvStringData5 = string ` 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null - 3, string3, 0, 1.23, 1.23, () - 4, string4, 1, -6.51, -6.51, () + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; @@ -221,8 +221,8 @@ string csvStringData6 = string ` 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null - 3, string3, 0, 1.23, 1.23, () - 4, string4, 1, -6.51, -6.51, () + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; diff --git a/ballerina/tests/test_with_union_types.bal b/ballerina/tests/test_with_union_types.bal new file mode 100644 index 0000000..98b5d1f --- /dev/null +++ b/ballerina/tests/test_with_union_types.bal @@ -0,0 +1,514 @@ +import ballerina/test; + +boolean enable = true; + +@test:Config {enable: !enable} +function debugTest() returns error? { + (RecA|RecC)[]|CsvConversionError csv1op3_2 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + 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: ()} + ]); +} + +type RecA record {int a; string b; boolean c; decimal d; float e; () f;}; +type RecB record {|string...;|}; +type RecC record {int a; int b; int c;}; +type TupA [int, string, boolean, decimal, float, ()]; +type TupB [int...]; +type TupC [int, int, int]; + +@test:Config {enable} +function testParseToStringWithUnionExpectedTypes() returns error? { + // TODO: Fix with tests RecA[]|RecC[] + (RecA|RecC)[]|CsvConversionError csv1op1 = parseStringToRecord(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: ()}, + {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.0, f: ()} + ]); + + (RecA|RecC)[]|CsvConversionError csv1op2 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + test:assertTrue(csv1op2 is RecA[]); + test:assertEquals(csv1op2, [ + {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: ()} + ]); + + (RecC|RecA)[]|CsvConversionError csv1op3 = parseStringToRecord(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)[]|CsvConversionError csv1op4 = parseStringToRecord(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)[]|CsvConversionError csv1op5 = parseStringToRecord(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;|})[]|CsvConversionError csv1op6 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + test:assertEquals(csv1op6, [ + {a: 1}, + {a: 3}, + {a: 5} + ]); + + (record{|string b;|}|record{|int a;|})[]|CsvConversionError csv1op7 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + test:assertEquals(csv1op7, [ + {b: "string1"}, + {b: "string3"}, + {b: "string5"} + ]); + + (record{|string...;|}|record{|int...;|})[]|CsvConversionError csv1op8 = parseStringToRecord(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"}, + {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{|int...;|}|record{|string...;|})[]|CsvConversionError csv1op9 = parseStringToRecord(csvStringData1, {header: 1}); + test:assertEquals(csv1op9, [ + {a: 1}, + {a: 2, d: 0, e: 0}, + {a: 3}, + {a: 4}, + {a: 5, d: 3, e: 3} + ]); + + (record{|int a; string...;|}|record{|string a; int...;|})[]|CsvConversionError csv1op10 = parseStringToRecord(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"}, + {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{|string a; int...;|}|record{|int a; string...;|})[]|CsvConversionError csv1op11 = parseStringToRecord(csvStringData1, {header: 1}); + test:assertEquals(csv1op11, [ + {a: "1"}, + {a: "2", d: 0, e: 0}, + {a: "3"}, + {a: "4"}, + {a: "5", d: 3, e: 3} + ]); +} + +@test:Config {enable} +function testParseToStringWithUnionExpectedTypes2() returns error? { + record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, + {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} + ]; + + (RecA|RecC)[]|CsvConversionError csv1op1 = parseRecordAsRecordType(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: ()}, + {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.0, f: ()} + ]); + + (RecA|RecC)[]|CsvConversionError csv1op2 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + test:assertTrue(csv1op2 is RecA[]); + test:assertEquals(csv1op2, [ + {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: ()} + ]); + + (RecC|RecA)[]|CsvConversionError csv1op3 = parseRecordAsRecordType(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)[]|CsvConversionError csv1op4 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + test:assertEquals(csv1op4, [ + {b: "string1"}, + {b: "string3"}, + {b: "string5"} + ]); + + (RecA|RecB)[]|CsvConversionError csv1op5 = parseRecordAsRecordType(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;|})[]|CsvConversionError csv1op6 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + test:assertEquals(csv1op6, [ + {a: 1}, + {a: 3}, + {a: 5} + ]); + + (record{|string b;|}|record{|int a;|})[]|CsvConversionError csv1op7 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + test:assertEquals(csv1op7, [ + {b: "string1"}, + {b: "string3"}, + {b: "string5"} + ]); + + (record{|string...;|}|record{|int...;|})[]|CsvConversionError csv1op8 = parseRecordAsRecordType(value, {}); + test:assertEquals(csv1op8, [ + {b: "string1"}, + {b: "string2"}, + {b: "string3"}, + {b: "string4"}, + {b: "string5"} + ]); + + (record{|int...;|}|record{|string...;|})[]|CsvConversionError csv1op9 = parseRecordAsRecordType(value, {}); + test:assertEquals(csv1op9, [ + {a: 1, d: 2, e: 2}, + {a: 2, d: 0, e: 0}, + {a: 3, d: 1, e: 1}, + {a: 4, d: -7, e: -7}, + {a: 5, d: 3, e: 3} + ]); + + (record{|int a; string...;|}|record{|string a; int...;|})[]|CsvConversionError csv1op10 = parseRecordAsRecordType(value, {}); + test:assertEquals(csv1op10, [ + {a: 1, b: "string1"}, + {a: 2, b: "string2"}, + {a: 3, b: "string3"}, + {a: 4, b: "string4"}, + {a: 5, b: "string5"} + ]); + + (record{|string a; int...;|}|record{|int a; string...;|})[]|CsvConversionError csv1op11 = parseRecordAsRecordType(value, {}); + test:assertEquals(csv1op11, [ + {a: 1, b: "string1"}, + {a: 2, b: "string2"}, + {a: 3, b: "string3"}, + {a: 4, b: "string4"}, + {a: 5, b: "string5"} + ]); + + (record{|string a; int...;|}|record{|string a; string...;|})[]|CsvConversionError csv1op12 = parseRecordAsRecordType(value, {}); + test:assertTrue(csv1op12 is CsvConversionError); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the 'data.csv:record {| string a; string...; |}'"); +} + +@test:Config {enable} +function testParseToStringWithUnionExpectedTypes3() returns error? { + string[][] value = [ + ["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", "()"] + ]; + + (RecA|RecC)[]|CsvConversionError csv1op1 = parseListAsRecordType(value, ["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: ()}, + {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.0, f: ()} + ]); + + (RecA|RecC)[]|CsvConversionError csv1op2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertTrue(csv1op2 is RecA[]); + test:assertEquals(csv1op2, [ + {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: ()} + ]); + + (RecC|RecA)[]|CsvConversionError csv1op3 = parseListAsRecordType(value, ["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)[]|CsvConversionError csv1op4 = parseListAsRecordType(value, ["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)[]|CsvConversionError csv1op5 = parseListAsRecordType(value, ["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;|})[]|CsvConversionError csv1op6 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertEquals(csv1op6, [ + {a: 1}, + {a: 3}, + {a: 5} + ]); + + (record{|string b;|}|record{|int a;|})[]|CsvConversionError csv1op7 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertEquals(csv1op7, [ + {b: "string1"}, + {b: "string3"}, + {b: "string5"} + ]); + + (record{|string...;|}|record{|int...;|})[]|CsvConversionError csv1op8 = parseListAsRecordType(value, ["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...;|})[]|CsvConversionError csv1op9 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); + test:assertEquals(csv1op9, [ + {a: 1}, + {a: 2, d: 0, e: 0}, + {a: 3}, + {a: 4}, + {a: 5, d: 3} + ]); + + (record{|int...;|}|record{|string...;|})[]|CsvConversionError csv1op9_2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + test:assertEquals(csv1op9_2, [ + {}, + {}, + {}, + {}, + {} + ]); + + (record{|int a; string...;|}|record{|string a; int...;|})[]|CsvConversionError csv1op10 = parseListAsRecordType(value, ["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...;|})[]|CsvConversionError csv1op11 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertEquals(csv1op11, [ + {a: "1"}, + {a: "2", d: 0, e: 0}, + {a: "3"}, + {a: "4"}, + {a: "5", d: 3} + ]); + +// Error Message is Wrong, Needs to check + (record{|int a; int...;|}|record{|int a; string...;|})[]|CsvConversionError csv1op12 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + test:assertTrue(csv1op12 is CsvConversionError); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the 'data.csv:record {| int a; string...; |}'"); +} + + +@test:Config {enable} +function testParseToStringWithUnionExpectedTypes4() returns error? { + record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, + {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} + ]; + + (TupA|TupC)[]|CsvConversionError csv1op1 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertEquals(csv1op1, [ + [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, ()] + ]); + + (TupA|TupC)[]|CsvConversionError csv1op2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertTrue(csv1op2 is TupA[]); + test:assertEquals(csv1op2, [ + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); + + (TupC|TupA)[]|CsvConversionError csv1op3 = parseRecordAsListType(value, ["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)[]|CsvConversionError csv1op4 = parseRecordAsListType(value, ["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, ()] + ]); + + // TODO: Change the Error Message + (TupB|[boolean])[]|CsvConversionError csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertTrue(csv1op4_2 is CsvConversionError); + test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '[boolean]'"); + + (TupA|TupB)[]|CsvConversionError csv1op5 = parseRecordAsListType(value, ["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])[]|CsvConversionError csv1op6 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertEquals(csv1op6, [ + [1], + [3], + [5] + ]); + + ([string]|[int])[]|CsvConversionError csv1op7 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertEquals(csv1op7, [ + [1], + [3], + [5] + ]); + + ([string...]|[int...])[]|CsvConversionError csv1op8 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op8 is CsvConversionError); + test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '[int...]'"); + + ([int...]|[string...])[]|CsvConversionError csv1op9 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op9 is CsvConversionError); + test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '[string...]'"); + + ([int, string...]|[string, int...])[]|CsvConversionError csv1op10 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op10 is CsvConversionError); + test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '[string,int...]'"); + + ([string, int...]|[int, string...])[]|CsvConversionError csv1op11 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op11 is CsvConversionError); + test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '[int,string...]'"); + + ([string, int...]|[string, string...])[]|CsvConversionError csv1op12 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op12 is CsvConversionError); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '[string,string...]'"); +} + +@test:Config {enable} +function testParseToStringWithUnionExpectedTypes5() returns error? { + string[][] value = [ + ["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", "()"] + ]; + + (TupA|TupC)[]|CsvConversionError csv1op1 = parseListAsListType(value, {}); + test:assertEquals(csv1op1, [ + [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, ()] + ]); + + (TupA|TupC)[]|CsvConversionError csv1op2 = parseListAsListType(value, {skipLines: [2, 4]}); + test:assertTrue(csv1op2 is TupA[]); + test:assertEquals(csv1op2, [ + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); + + (TupC|TupA)[]|CsvConversionError csv1op3 = parseListAsListType(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)[]|CsvConversionError csv1op4 = parseListAsListType(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, ()] + ]); + + // TODO: Change the Error Message + (TupB|[boolean])[]|CsvConversionError csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); + test:assertTrue(csv1op4_2 is CsvConversionError); + test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '[boolean]'"); + + (TupA|TupB)[]|CsvConversionError csv1op5 = parseListAsListType(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])[]|CsvConversionError csv1op6 = parseListAsListType(value, {skipLines: [2, 4]}); + test:assertEquals(csv1op6, [ + [1], + [3], + [5] + ]); + + ([string]|[int])[]|CsvConversionError csv1op7 = parseListAsListType(value, {skipLines: [2, 4]}); + test:assertEquals(csv1op7, [ + ["1"], + ["3"], + ["5"] + ]); + + ([boolean...]|[int...])[]|CsvConversionError csv1op8 = parseListAsListType(value, {stringConversion: false}); + test:assertTrue(csv1op8 is CsvConversionError); + test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '[int...]'"); + + ([string...]|[int...])[]|CsvConversionError csv1op8_2 = parseListAsListType(value, {}); + test:assertEquals(csv1op8_2, value); + + ([int...]|[string...])[]|CsvConversionError csv1op9 = parseListAsListType(value, {}); + test:assertEquals(csv1op9, value); + + ([int, string...]|[string, int...])[]|CsvConversionError csv1op10 = parseListAsListType(value, {}); + test:assertEquals(csv1op10, [ + [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", "()"] + ]); + + ([string, int...]|[int, string...])[]|CsvConversionError csv1op11 = parseListAsListType(value, {}); + test:assertEquals(csv1op11, [ + [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", "()"] + ]); + + ([string, int...]|[string, string...])[]|CsvConversionError csv1op12 = parseListAsListType(value, {}); + test:assertEquals(csv1op12, value); +} + +//TODO: Add test for intersection type in exp type \ No newline at end of file diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index 8b0e786..4b9e59e 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -41,7 +41,7 @@ function testFromCsvStringWithParserOptions() { record {}[]|CsvConversionError csv2op4_3 = parseStringToRecord(csvStringData2, ptOption4); test:assertEquals(csv2op4_3, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, - {a: 3, b: "string3", c: 0, d: 1.23, e: 1.23, 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: "()"} ]); @@ -55,7 +55,7 @@ function testFromCsvStringWithParserOptions() { record {}[]|CsvConversionError csv3op3_2 = parseStringToRecord(csvStringData3, ptOption1); test:assertEquals(csv3op3_2, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, - {a: 3, b: "string3", c: 0, d: 1.23, e: 1.23, 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: "()"} ]); @@ -67,7 +67,7 @@ function testFromCsvStringWithParserOptions() { record {}[]|CsvConversionError csv3op3_4 = parseStringToRecord(csvStringData3, {header: 9, skipLines: "2-10"}); test:assertEquals(csv3op3_4, [ - {'4: 5, string4: "string5", '1: true, "-6.51": 3, "()": null} + {'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": null} ]); } @@ -81,7 +81,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { 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: 0, '4: 1.23, '5: 1.23, '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: ()} ]); @@ -89,35 +89,35 @@ function testFromCsvStringWithHeaderLessParserOptions() { 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: 0, '4: 1.23, '5: 1.23, '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 {}[]|CsvConversionError csv3op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '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 {}[]|CsvConversionError csv4op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '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 {}[]|CsvConversionError csv5op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '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 {}[]|CsvConversionError csv6op6_2 = parseStringToRecord(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: 0, '4: 1.23, '5: 1.23, '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: ()} ]); @@ -127,7 +127,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'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: 0, '4: 1.23, '5: 1.23, '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: ()} ]); } @@ -138,8 +138,8 @@ function testHeaderOption() { 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: 0, d: 1.23, e: 1.23, f: ()}, - {a: 4, b: "string4", c: 1, d: -6.51, e: -6.51, 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: ()} ]); @@ -150,7 +150,7 @@ function testHeaderOption() { test:assertEquals(csv2cop3, []); record {}[]|CsvConversionError csv2cop4 = parseStringToRecord(csvStringData2, {header: 10}); - test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", '1: true, "-6.51": 3, "()": ()}]); + test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": ()}]); record {}[]|CsvConversionError csv1cop5 = parseStringToRecord(csvStringData1, {}); test:assertTrue(csv1cop5 is CsvConversionError); @@ -683,8 +683,8 @@ function testCustomHeaderParserOption2() { test:assertEquals(ct1br12, [ {e1: "string1", d1: "true"}, {e1: "string2", d1: "false"}, - {e1: "string3", d1: "0"}, - {e1: "string4", d1: "1"}, + {e1: "string3", d1: "false"}, + {e1: "string4", d1: "true"}, {e1: "string5", d1: "true"} ]); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index 093fcea..89d3e69 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -232,11 +232,11 @@ private static BDecimal stringToDecimal(String value) throws NumberFormatExcepti } private static Object stringToBoolean(String value) throws NumberFormatException { - if ("true".equalsIgnoreCase(value) || "TRUE".equalsIgnoreCase(value) || "1".equalsIgnoreCase(value)) { + if ("true".equalsIgnoreCase(value) || "TRUE".equalsIgnoreCase(value)) { return true; } - if ("false".equalsIgnoreCase(value) || "FALSE".equalsIgnoreCase(value) || "0".equalsIgnoreCase(value)) { + if ("false".equalsIgnoreCase(value) || "FALSE".equalsIgnoreCase(value)) { return false; } return returnError(value, "boolean"); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index de22caf..76eb7b1 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -18,13 +18,16 @@ package io.ballerina.stdlib.data.csvdata.csv; +import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.*; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; @@ -65,7 +68,8 @@ public static Object parse(Reader reader, BTypedesc type, CsvConfig config) throws BError { StateMachine sm = tlStateMachine.get(); try { - Object convertedValue = sm.execute(reader, TypeUtils.getReferredType(type.getDescribingType()), config); + Object convertedValue = sm.execute(reader, TypeUtils.getReferredType(type.getDescribingType()), + config, type); return DataUtils.validateConstraints(convertedValue, type, config.enableConstraintValidation); } finally { // Need to reset the state machine before leaving. Otherwise, references to the created @@ -184,7 +188,7 @@ private String peek() { return new String(this.charBuff, 0, this.charBuffIndex); } - public Object execute(Reader reader, Type type, CsvConfig config) throws BError { + public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTypedesc) throws BError { this.config = config; Type referredType = TypeUtils.getReferredType(type); if (referredType.getTag() != TypeTags.ARRAY_TAG) { @@ -210,9 +214,14 @@ public Object execute(Reader reader, Type type, CsvConfig config) throws BError case TypeTags.ARRAY_TAG: break; case TypeTags.UNION_TAG: - throw DiagnosticLog.error(DiagnosticErrorCode.UNION_TYPES_NOT_ALLOWED, expectedArrayElementType); + Object mapValue = execute(reader, TypeCreator.createArrayType( + TypeCreator.createMapType(PredefinedTypes.TYPE_STRING) + ), CsvConfig.createConfigOptionsForUnion(config), bTypedesc); + config.stringConversion = true; + return CsvTraversal.traverse((BArray) mapValue, config, bTypedesc); default: - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); + throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, + expectedArrayElementType); } State currentState; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index cfd43ef..4257cee 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.*; @@ -97,11 +98,12 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { setRootCsvNode(referredType, type); validateExpectedArraySize(expectedArraySize, sourceArraySize); - traverseCsvWithExpectedType(expectedArraySize, sourceArraySize, csv); + traverseCsvWithExpectedType(expectedArraySize, sourceArraySize, csv, config); return rootCsvNode; } - private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArraySize, BArray csv) { + private void traverseCsvWithExpectedType(int expectedArraySize, + int sourceArraySize, BArray csv, CsvConfig config) { switch (expectedArrayElementType.getTag()) { case TypeTags.RECORD_TYPE_TAG: case TypeTags.MAP_TAG: @@ -114,8 +116,20 @@ private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArrayS traverseCsvArrayMembersWithArrayAsCsvElementType(expectedArraySize == -1 ? sourceArraySize : expectedArraySize, csv, expectedArrayElementType); break; + case TypeTags.UNION_TAG: + for (Type memberType : ((UnionType) expectedArrayElementType).getMemberTypes()) { + try { + traverseCsv(csv, config, TypeCreator.createArrayType(memberType)); + return; + } catch (Exception e) { + //ignore + } + } + throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, + expectedArrayElementType); default: - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedArrayElementType); + throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, + expectedArrayElementType); } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java index 98f8432..671e4fb 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java @@ -1,5 +1,6 @@ package io.ballerina.stdlib.data.csvdata.utils; +import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BMap; @@ -10,7 +11,7 @@ public class CsvConfig { public char delimiter = ','; public char textEnclosure = '\\'; - public Object header = 0; + public Object header = (long) 0; public char escapeChar = '\\'; public Object lineTerminator = '\n'; public Object skipLines = null; @@ -26,6 +27,19 @@ public class CsvConfig { public boolean stringConversion = false; public boolean enableConstraintValidation = false; + private CsvConfig(CsvConfig config) { + this.allowDataProjection = false; + this.header = config.header; + this.delimiter = config.delimiter; + this.textEnclosure = config.textEnclosure; + this.escapeChar = config.escapeChar; + this.lineTerminator = config.lineTerminator; + this.nilValue = config.nilValue; + this.comment = config.comment; + this.locale = config.locale; + this.encoding = config.encoding; + } + private CsvConfig(Object skipLines, boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection) { this.skipLines = skipLines; @@ -209,6 +223,11 @@ public static CsvConfig createToRecordOptions(BMap options) { ); } + + public static CsvConfig createConfigOptionsForUnion(CsvConfig config) { + return new CsvConfig(config); + } + private static void updateDataProjectOptions(BMap options) { Object allowProjections = options.get(ALLOW_DATA_PROJECTION); if (allowProjections instanceof Boolean) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index b5e9c97..392799b 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -200,10 +200,13 @@ public static long[] getSkipLinesFromStringConfigValue(String configValue) { public static long[] getSkipDataRows(Object skipLines) { long[] skipDataRows; + if (skipLines == null) { + return new long[]{}; + } if (skipLines instanceof BArray) { BArray skipLinesArray = (BArray) skipLines; if (skipLinesArray.getLength() == 0) { - return new long[]{-1}; + return new long[]{}; } skipDataRows = (skipLinesArray).getIntArray(); return skipDataRows; @@ -245,7 +248,7 @@ public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object li return false; } - String lineTerminator = StringUtils.getStringValue(lineTerminatorObj); + String lineTerminator = StringUtils.getStringValue(StringUtils.fromString(lineTerminatorObj.toString())); return lineTerminator.equals(stringValue); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index 261b1a0..dda7775 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -49,7 +49,8 @@ public enum DiagnosticErrorCode { 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"); + DUPLICATE_FIELD("BDE_0025", "duplicate.field"), + SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE("BDE_0026", "cannot.convert.into.exptype"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/error.properties index 041aa25..dc1471a 100644 --- a/native/src/main/resources/error.properties +++ b/native/src/main/resources/error.properties @@ -95,3 +95,6 @@ error.no.field.for.header=\ error.duplicate.field=\ Duplicate field found in record fields: ''{0}'' + +error.cannot.convert.into.exptype=\ + The source value cannot convert in to the ''{0}'' \ No newline at end of file From 5bcc0d9ecdaeb085564136a465230d51ba6459e5 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 25 Jun 2024 16:34:49 +0530 Subject: [PATCH 038/147] Add tests for union & intertsection types --- .../tests/test_with_intersection_types.bal | 59 ++ ballerina/tests/test_with_union_types.bal | 601 +++++++++++++++++- .../stdlib/data/csvdata/csv/CsvCreator.java | 5 + .../stdlib/data/csvdata/csv/CsvParser.java | 37 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 126 +++- 5 files changed, 772 insertions(+), 56 deletions(-) create mode 100644 ballerina/tests/test_with_intersection_types.bal diff --git a/ballerina/tests/test_with_intersection_types.bal b/ballerina/tests/test_with_intersection_types.bal new file mode 100644 index 0000000..e1ec3fa --- /dev/null +++ b/ballerina/tests/test_with_intersection_types.bal @@ -0,0 +1,59 @@ +import ballerina/test; + +boolean enable = true; + +@test:Config {enable: !enable} +function debugTest() returns error? { + (int[] & readonly)[]|CsvConversionError a = parseStringToList(string `a,b + 1,2 + 4,5`); + test:assertEquals(a, [[1, 2], [4, 5]]); +} + +@test:Config {enable} +function testIntersectionExpectedTypes() returns error? { + (int[] & readonly)[]|CsvConversionError a = parseStringToList(string `a,b + 1,2 + 4,5`); + test:assertEquals(a, [[1, 2], [4, 5]]); + + ([string, string])[] & readonly|CsvConversionError a2 = parseStringToList(string `a,b + a,a + c,c`); + test:assertEquals(a2, [["a", "a"], ["c", "c"]]); + + (record{int a; string b;} & readonly)[]|CsvConversionError a3 = parseStringToRecord(string `a,b + 1,2 + 4,5`); + test:assertEquals(a3, [{a: 1, b: "2"}, {a: 4, b: "5"}]); + + record{|string...;|}[] & readonly|CsvConversionError a4 = parseStringToRecord(string `a,b + a,a + c,c`); + test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); +} + +@test:Config {enable} +function testIntersectionExpectedTypes2() returns error? { + (int[] & readonly)[]|CsvConversionError a = parseStringToList(string `a,b + 1,2 + 4,5`); + test:assertEquals(a, [[1, 2], [4, 5]]); + + ([string, string])[] & readonly|CsvConversionError a2 = parseStringToList(string `a,b + a,a + c,c`); + test:assertEquals(a2, [["a", "a"], ["c", "c"]]); + + (record{int a; string b;} & readonly)[]|CsvConversionError a3 = parseStringToRecord(string `a,b + 1,2 + 4,5`); + test:assertEquals(a3, [{a: 1, b: "2"}, {a: 4, b: "5"}]); + + record{|string...;|}[] & readonly|CsvConversionError a4 = parseStringToRecord(string `a,b + a,a + c,c`); + test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); +} + +// TODO: Add tetsts for Singleton, table \ No newline at end of file diff --git a/ballerina/tests/test_with_union_types.bal b/ballerina/tests/test_with_union_types.bal index 98b5d1f..5c7c2ce 100644 --- a/ballerina/tests/test_with_union_types.bal +++ b/ballerina/tests/test_with_union_types.bal @@ -1,16 +1,19 @@ import ballerina/test; -boolean enable = true; +// boolean enable = true; -@test:Config {enable: !enable} -function debugTest() returns error? { - (RecA|RecC)[]|CsvConversionError csv1op3_2 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); - 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: ()} - ]); -} +// @test:Config {enable: !enable} +// function debugTest() returns error? { +// record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ +// {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, +// {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, +// {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, +// {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, +// {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} +// ]; + +// RecA[]|RecC[]|CsvConversionError csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); +// } type RecA record {int a; string b; boolean c; decimal d; float e; () f;}; type RecB record {|string...;|}; @@ -32,7 +35,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { ]); (RecA|RecC)[]|CsvConversionError csv1op2 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); - test:assertTrue(csv1op2 is RecA[]); + test:assertTrue(csv1op2 is (RecA|RecC)[]); test:assertEquals(csv1op2, [ {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: ()}, @@ -109,6 +112,24 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "4"}, {a: "5", d: 3, e: 3} ]); + + (record{|int a; int b;|}|record{|string a; string...;|})[]|CsvConversionError csv1op12 = parseStringToRecord(string ` + a,b + 1, 2 + a, b`, {header: 1}); + test:assertEquals(csv1op12, [ + {a: 1, b: 2}, + {a: "a", b: "b"} + ]); + + ([int, int]|[string, string])[]|CsvConversionError csv1op13 = parseStringToList(string ` + a,b + 1, 2 + a, b`, {header: 1}); + test:assertEquals(csv1op13, [ + [1, 2], + ["a", "b"] + ]); } @test:Config {enable} @@ -131,7 +152,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { ]); (RecA|RecC)[]|CsvConversionError csv1op2 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); - test:assertTrue(csv1op2 is RecA[]); + test:assertTrue(csv1op2 is (RecA|RecC)[]); test:assertEquals(csv1op2, [ {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: ()}, @@ -211,7 +232,13 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { (record{|string a; int...;|}|record{|string a; string...;|})[]|CsvConversionError csv1op12 = parseRecordAsRecordType(value, {}); test:assertTrue(csv1op12 is CsvConversionError); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the 'data.csv:record {| string a; string...; |}'"); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| string a; int...; |}|data.csv:record {| string a; string...; |})[]'"); + + (record{|int a; int...;|}|record{|string a; string...;|})[]|CsvConversionError csv1op13 = parseRecordAsRecordType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); + test:assertEquals(csv1op13, [ + {a: 1, b: 2}, + {a: "a", b: "b"} + ]); } @test:Config {enable} @@ -234,7 +261,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { ]); (RecA|RecC)[]|CsvConversionError csv1op2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); - test:assertTrue(csv1op2 is RecA[]); + test:assertTrue(csv1op2 is (RecA|RecC)[]); test:assertEquals(csv1op2, [ {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: ()}, @@ -320,7 +347,13 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { // Error Message is Wrong, Needs to check (record{|int a; int...;|}|record{|int a; string...;|})[]|CsvConversionError csv1op12 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); test:assertTrue(csv1op12 is CsvConversionError); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the 'data.csv:record {| int a; string...; |}'"); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| int a; int...; |}|data.csv:record {| int a; string...; |})[]'"); + + (record{|int a; int...;|}|record{|string a; string...;|})[]|CsvConversionError csv1op13 = parseListAsRecordType([["1", "2"], ["a", "b"]], ["a", "b"], {}); + test:assertEquals(csv1op13, [ + {a: 1, b: 2}, + {a: "a", b: "b"} + ]); } @@ -344,7 +377,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { ]); (TupA|TupC)[]|CsvConversionError csv1op2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); - test:assertTrue(csv1op2 is TupA[]); + test:assertTrue(csv1op2 is (TupA|TupC)[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], @@ -368,7 +401,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { // TODO: Change the Error Message (TupB|[boolean])[]|CsvConversionError csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is CsvConversionError); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '[boolean]'"); + test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB|[boolean])[]'"); (TupA|TupB)[]|CsvConversionError csv1op5 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op5, [ @@ -393,23 +426,29 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { ([string...]|[int...])[]|CsvConversionError csv1op8 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertTrue(csv1op8 is CsvConversionError); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '[int...]'"); + test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([string...]|[int...])[]'"); ([int...]|[string...])[]|CsvConversionError csv1op9 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertTrue(csv1op9 is CsvConversionError); - test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '[string...]'"); + test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '([int...]|[string...])[]'"); ([int, string...]|[string, int...])[]|CsvConversionError csv1op10 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertTrue(csv1op10 is CsvConversionError); - test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '[string,int...]'"); + test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '([int,string...]|[string,int...])[]'"); ([string, int...]|[int, string...])[]|CsvConversionError csv1op11 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertTrue(csv1op11 is CsvConversionError); - test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '[int,string...]'"); + test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '([string,int...]|[int,string...])[]'"); ([string, int...]|[string, string...])[]|CsvConversionError csv1op12 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertTrue(csv1op12 is CsvConversionError); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '[string,string...]'"); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...]|[string,string...])[]'"); + + ([int, int...]|[string, string...])[]|CsvConversionError csv1op13 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["a", "b"], {}); + test:assertEquals(csv1op13, [ + [1, 2], + ["a", "b"] + ]); } @test:Config {enable} @@ -432,7 +471,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ]); (TupA|TupC)[]|CsvConversionError csv1op2 = parseListAsListType(value, {skipLines: [2, 4]}); - test:assertTrue(csv1op2 is TupA[]); + test:assertTrue(csv1op2 is (TupA|TupC)[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], @@ -456,7 +495,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { // TODO: Change the Error Message (TupB|[boolean])[]|CsvConversionError csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is CsvConversionError); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '[boolean]'"); + test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB|[boolean])[]'"); (TupA|TupB)[]|CsvConversionError csv1op5 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op5, [ @@ -481,7 +520,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ([boolean...]|[int...])[]|CsvConversionError csv1op8 = parseListAsListType(value, {stringConversion: false}); test:assertTrue(csv1op8 is CsvConversionError); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '[int...]'"); + test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...]|[int...])[]'"); ([string...]|[int...])[]|CsvConversionError csv1op8_2 = parseListAsListType(value, {}); test:assertEquals(csv1op8_2, value); @@ -509,6 +548,518 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ([string, int...]|[string, string...])[]|CsvConversionError csv1op12 = parseListAsListType(value, {}); test:assertEquals(csv1op12, value); + + ([int, int...]|[string, string...])[]|CsvConversionError csv1op13 = parseListAsListType([["1", "2"], ["a", "b"]], {}); + test:assertEquals(csv1op13, [ + [1, 2], + ["a", "b"] + ]); +} + +@test:Config {enable} +function testParseToStringWithUnionExpectedTypes6() returns error? { + // TODO: Fix with tests RecA[]|RecC[] + RecA[]|RecC[]|CsvConversionError csv1op1 = parseStringToRecord(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: ()}, + {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.0, f: ()} + ]); + + RecA[]|RecC[]|CsvConversionError csv1op2 = parseStringToRecord(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: ()}, + {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: ()} + ]); + + RecC[]|RecA[]|CsvConversionError csv1op3 = parseStringToRecord(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[]|CsvConversionError csv1op4 = parseStringToRecord(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[]|CsvConversionError csv1op5 = parseStringToRecord(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;|}[]|CsvConversionError csv1op6 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + test:assertEquals(csv1op6, [ + {a: 1}, + {a: 3}, + {a: 5} + ]); + + record{|string b;|}[]|record{|int a;|}[]|CsvConversionError csv1op7 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + test:assertEquals(csv1op7, [ + {b: "string1"}, + {b: "string3"}, + {b: "string5"} + ]); + + record{|string...;|}[]|record{|int...;|}[]|CsvConversionError csv1op8 = parseStringToRecord(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"}, + {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{|int...;|}[]|record{|string...;|}[]|CsvConversionError csv1op9 = parseStringToRecord(csvStringData1, {header: 1}); + test:assertEquals(csv1op9, [ + {a: 1}, + {a: 2, d: 0, e: 0}, + {a: 3}, + {a: 4}, + {a: 5, d: 3, e: 3} + ]); + + record{|int a; string...;|}[]|record{|string a; int...;|}[]|CsvConversionError csv1op10 = parseStringToRecord(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"}, + {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{|string a; int...;|}[]|record{|int a; string...;|}[]|CsvConversionError csv1op11 = parseStringToRecord(csvStringData1, {header: 1}); + test:assertEquals(csv1op11, [ + {a: "1"}, + {a: "2", d: 0, e: 0}, + {a: "3"}, + {a: "4"}, + {a: "5", d: 3, e: 3} + ]); + + record{|int a; int b;|}[]|record{|string a; string...;|}[]|CsvConversionError csv1op12 = parseStringToRecord(string ` + a,b + 1, 2 + a, b`, {header: 1}); + test:assertEquals(csv1op12, [ + {a: "1", b: "2"}, + {a: "a", b: "b"} + ]); +} + +@test:Config {enable} +function testParseToStringWithUnionExpectedTypes7() returns error? { + record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, + {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} + ]; + + RecA[]|RecC[]|CsvConversionError csv1op1 = parseRecordAsRecordType(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: ()}, + {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.0, f: ()} + ]); + + RecA[]|RecC[]|CsvConversionError csv1op2 = parseRecordAsRecordType(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: ()}, + {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: ()} + ]); + + RecC[]|RecA[]|CsvConversionError csv1op3 = parseRecordAsRecordType(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[]|CsvConversionError csv1op4 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + test:assertEquals(csv1op4, [ + {b: "string1"}, + {b: "string3"}, + {b: "string5"} + ]); + + RecA[]|RecB[]|CsvConversionError csv1op5 = parseRecordAsRecordType(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;|}[]|CsvConversionError csv1op6 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + test:assertEquals(csv1op6, [ + {a: 1}, + {a: 3}, + {a: 5} + ]); + + record{|string b;|}[]|record{|int a;|}[]|CsvConversionError csv1op7 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + test:assertEquals(csv1op7, [ + {b: "string1"}, + {b: "string3"}, + {b: "string5"} + ]); + + record{|string...;|}[]|record{|int...;|}[]|CsvConversionError csv1op8 = parseRecordAsRecordType(value, {}); + test:assertEquals(csv1op8, [ + {b: "string1"}, + {b: "string2"}, + {b: "string3"}, + {b: "string4"}, + {b: "string5"} + ]); + + record{|int...;|}[]|record{|string...;|}[]|CsvConversionError csv1op9 = parseRecordAsRecordType(value, {}); + test:assertEquals(csv1op9, [ + {a: 1, d: 2, e: 2}, + {a: 2, d: 0, e: 0}, + {a: 3, d: 1, e: 1}, + {a: 4, d: -7, e: -7}, + {a: 5, d: 3, e: 3} + ]); + + record{|int a; string...;|}[]|record{|string a; int...;|}[]|CsvConversionError csv1op10 = parseRecordAsRecordType(value, {}); + test:assertEquals(csv1op10, [ + {a: 1, b: "string1"}, + {a: 2, b: "string2"}, + {a: 3, b: "string3"}, + {a: 4, b: "string4"}, + {a: 5, b: "string5"} + ]); + + record{|string a; int...;|}[]|record{|int a; string...;|}[]|CsvConversionError csv1op11 = parseRecordAsRecordType(value, {}); + test:assertEquals(csv1op11, [ + {a: 1, b: "string1"}, + {a: 2, b: "string2"}, + {a: 3, b: "string3"}, + {a: 4, b: "string4"}, + {a: 5, b: "string5"} + ]); + + record{|string a; int...;|}[]|record{|string a; string...;|}[]|CsvConversionError csv1op12 = parseRecordAsRecordType(value, {}); + test:assertTrue(csv1op12 is CsvConversionError); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| string a; int...; |}[]|data.csv:record {| string a; string...; |}[])'"); +} + +@test:Config {enable} +function testParseToStringWithUnionExpectedTypes8() returns error? { + string[][] value = [ + ["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", "()"] + ]; + + RecA[]|RecC[]|CsvConversionError csv1op1 = parseListAsRecordType(value, ["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: ()}, + {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.0, f: ()} + ]); + + RecA[]|RecC[]|CsvConversionError csv1op2 = parseListAsRecordType(value, ["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: ()}, + {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: ()} + ]); + + RecC[]|RecA[]|CsvConversionError csv1op3 = parseListAsRecordType(value, ["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[]|CsvConversionError csv1op4 = parseListAsRecordType(value, ["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[]|CsvConversionError csv1op5 = parseListAsRecordType(value, ["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;|}[]|CsvConversionError csv1op6 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertEquals(csv1op6, [ + {a: 1}, + {a: 3}, + {a: 5} + ]); + + record{|string b;|}[]|record{|int a;|}[]|CsvConversionError csv1op7 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertEquals(csv1op7, [ + {b: "string1"}, + {b: "string3"}, + {b: "string5"} + ]); + + record{|string...;|}[]|record{|int...;|}[]|CsvConversionError csv1op8 = parseListAsRecordType(value, ["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...;|}[]|CsvConversionError csv1op9 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); + test:assertEquals(csv1op9, [ + {a: 1}, + {a: 2, d: 0, e: 0}, + {a: 3}, + {a: 4}, + {a: 5, d: 3} + ]); + + record{|int...;|}[]|record{|string...;|}[]|CsvConversionError csv1op9_2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + test:assertEquals(csv1op9_2, [ + {}, + {}, + {}, + {}, + {} + ]); + + record{|int a; string...;|}[]|record{|string a; int...;|}[]|CsvConversionError csv1op10 = parseListAsRecordType(value, ["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...;|}[]|CsvConversionError csv1op11 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertEquals(csv1op11, [ + {a: "1"}, + {a: "2", d: 0, e: 0}, + {a: "3"}, + {a: "4"}, + {a: "5", d: 3} + ]); + + record{|int a; int...;|}[]|record{|int a; string...;|}[]|CsvConversionError csv1op12 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + test:assertTrue(csv1op12 is CsvConversionError); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| int a; int...; |}[]|data.csv:record {| int a; string...; |}[])'"); + + record{|int a; int...;|}[]|record{|string a; string...;|}[]|CsvConversionError csv1op13 = parseListAsRecordType([["1", "2"], ["a", "b"]], ["a", "b"], {}); + test:assertEquals(csv1op13, [ + {a: "1", b: "2"}, + {a: "a", b: "b"} + ]); +} + + +@test:Config {enable} +function testParseToStringWithUnionExpectedTypes9() returns error? { + record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, + {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} + ]; + + TupA[]|TupC[]|CsvConversionError csv1op1 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertEquals(csv1op1, [ + [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, ()] + ]); + + TupA[]|TupC[]|CsvConversionError csv1op2 = parseRecordAsListType(value, ["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, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); + + TupC[]|TupA[]|CsvConversionError csv1op3 = parseRecordAsListType(value, ["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[]|CsvConversionError csv1op4 = parseRecordAsListType(value, ["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, ()] + ]); + + // TODO: Change the Error Message + TupB[]|[boolean][]|CsvConversionError csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertTrue(csv1op4_2 is CsvConversionError); + test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB[]|[boolean][])'"); + + TupA[]|TupB[]|CsvConversionError csv1op5 = parseRecordAsListType(value, ["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][]|CsvConversionError csv1op6 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertEquals(csv1op6, [ + [1], + [3], + [5] + ]); + + [string][]|[int][]|CsvConversionError csv1op7 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertEquals(csv1op7, [ + [1], + [3], + [5] + ]); + + [string...][]|[int...][]|CsvConversionError csv1op8 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op8 is CsvConversionError); + test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([string...][]|[int...][])'"); + + [int...][]|[string...][]|CsvConversionError csv1op9 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op9 is CsvConversionError); + test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '([int...][]|[string...][])'"); + + [int, string...][]|[string, int...][]|CsvConversionError csv1op10 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op10 is CsvConversionError); + test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '([int,string...][]|[string,int...][])'"); + + [string, int...][]|[int, string...][]|CsvConversionError csv1op11 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op11 is CsvConversionError); + test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '([string,int...][]|[int,string...][])'"); + + [string, int...][]|[string, string...][]|CsvConversionError csv1op12 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op12 is CsvConversionError); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...][]|[string,string...][])'"); +} + +@test:Config {enable} +function testParseToStringWithUnionExpectedTypes10() returns error? { + string[][] value = [ + ["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", "()"] + ]; + + TupA[]|TupC[]|CsvConversionError csv1op1 = parseListAsListType(value, {}); + test:assertEquals(csv1op1, [ + [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, ()] + ]); + + TupA[]|TupC[]|CsvConversionError csv1op2 = parseListAsListType(value, {skipLines: [2, 4]}); + test:assertTrue(csv1op2 is TupA[]|TupC[]); + test:assertEquals(csv1op2, [ + [1, "string1", true, 2.234, 2.234, ()], + [3, "string3", false, 1.23, 1.23, ()], + [5, "string5", true, 3, 3.0, ()] + ]); + + TupC[]|TupA[]|CsvConversionError csv1op3 = parseListAsListType(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[]|CsvConversionError csv1op4 = parseListAsListType(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, ()] + ]); + + // TODO: Change the Error Message + TupB[]|[boolean][]|CsvConversionError csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); + test:assertTrue(csv1op4_2 is CsvConversionError); + test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB[]|[boolean][])'"); + + TupA[]|TupB[]|CsvConversionError csv1op5 = parseListAsListType(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][]|CsvConversionError csv1op6 = parseListAsListType(value, {skipLines: [2, 4]}); + test:assertEquals(csv1op6, [ + [1], + [3], + [5] + ]); + + [string][]|[int][]|CsvConversionError csv1op7 = parseListAsListType(value, {skipLines: [2, 4]}); + test:assertEquals(csv1op7, [ + ["1"], + ["3"], + ["5"] + ]); + + [boolean...][]|[int...][]|CsvConversionError csv1op8 = parseListAsListType(value, {stringConversion: false}); + test:assertTrue(csv1op8 is CsvConversionError); + test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...][]|[int...][])'"); + + [string...][]|[int...][]|CsvConversionError csv1op8_2 = parseListAsListType(value, {}); + test:assertEquals(csv1op8_2, value); + + [int...][]|[string...][]|CsvConversionError csv1op9 = parseListAsListType(value, {}); + test:assertEquals(csv1op9, value); + + [int, string...][]|[string, int...][]|CsvConversionError csv1op10 = parseListAsListType(value, {}); + test:assertEquals(csv1op10, [ + [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", "()"] + ]); + + [string, int...][]|[int, string...][]|CsvConversionError csv1op11 = parseListAsListType(value, {}); + test:assertEquals(csv1op11, [ + [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", "()"] + ]); + + [string, int...][]|[string, string...][]|CsvConversionError csv1op12 = parseListAsListType(value, {}); + test:assertEquals(csv1op12, value); } //TODO: Add test for intersection type in exp type \ No newline at end of file diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 95a5fc7..97b1d42 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -47,6 +47,11 @@ public class CsvCreator { static Object initRowValue(Type expectedType) { + expectedType = TypeUtils.getReferredType(expectedType); + if (expectedType.getTag() == TypeTags.INTERSECTION_TAG) { + expectedType = ((IntersectionType) expectedType).getEffectiveType(); + } + switch (expectedType.getTag()) { case TypeTags.RECORD_TYPE_TAG: return ValueCreator.createRecordValue(expectedType.getPackage(), expectedType.getName()); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 76eb7b1..8574677 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -27,7 +27,6 @@ import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; -import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; @@ -119,7 +118,7 @@ static class StateMachine { boolean isCurrentCsvNodeEmpty = true; boolean isHeaderConfigExceedLineNumber = false; boolean isQuoteClosed = false; - + boolean isIntersectionElementType = false; private StringBuilder hexBuilder = new StringBuilder(4); StateMachine() { reset(); @@ -151,6 +150,7 @@ public void reset() { isHeaderConfigExceedLineNumber = false; hexBuilder = new StringBuilder(4); isQuoteClosed = false; + isIntersectionElementType = false; } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -191,13 +191,25 @@ private String peek() { public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTypedesc) throws BError { this.config = config; Type referredType = TypeUtils.getReferredType(type); - if (referredType.getTag() != TypeTags.ARRAY_TAG) { + if (referredType.getTag() == TypeTags.INTERSECTION_TAG) { + for (Type constituentType : ((IntersectionType) referredType).getConstituentTypes()) { + if (constituentType.getTag() == TypeTags.READONLY_TAG) { + continue; + } + return CsvCreator.constructReadOnlyValue(execute(reader, constituentType, config, bTypedesc)); + } + } + + if (referredType.getTag() == TypeTags.UNION_TAG) { + expectedArrayElementType = referredType; + } else if (referredType.getTag() != TypeTags.ARRAY_TAG) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type); } else { - rootArrayType = (ArrayType) type; + rootArrayType = (ArrayType) referredType; + expectedArrayElementType = TypeUtils.getReferredType(rootArrayType.getElementType()); rootCsvNode = ValueCreator.createArrayValue(rootArrayType); - expectedArrayElementType = TypeUtils.getReferredType(((ArrayType) referredType).getElementType()); } + switch (expectedArrayElementType.getTag()) { // TODO: Handle readonly and singleton type as expType. case TypeTags.RECORD_TYPE_TAG: @@ -213,6 +225,21 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp case TypeTags.MAP_TAG: case TypeTags.ARRAY_TAG: break; + case TypeTags.INTERSECTION_TAG: + for (Type constituentType : ((IntersectionType) expectedArrayElementType).getConstituentTypes()) { + if (constituentType.getTag() == TypeTags.READONLY_TAG) { + continue; + } + Object mapValue = execute(reader, TypeCreator.createArrayType( + TypeCreator.createMapType(PredefinedTypes.TYPE_STRING) + ), CsvConfig.createConfigOptionsForUnion(config), bTypedesc); + config.stringConversion = true; + return CsvCreator.constructReadOnlyValue(CsvTraversal + .traverse((BArray) mapValue, config, bTypedesc, + TypeCreator.createArrayType(constituentType))); + } + throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, + expectedArrayElementType); case TypeTags.UNION_TAG: Object mapValue = execute(reader, TypeCreator.createArrayType( TypeCreator.createMapType(PredefinedTypes.TYPE_STRING) diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 4257cee..ebaba33 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -20,7 +20,6 @@ import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; -import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.*; @@ -56,6 +55,18 @@ public static Object traverse(BArray csv, CsvConfig config, BTypedesc type) { } } + public static Object traverse(BArray csv, CsvConfig config, BTypedesc typed, Type type) { + CsvTree csvTree = tlCsvTree.get(); + try { + Object convertedValue = csvTree.traverseCsv(csv, config, type); + return DataUtils.validateConstraints(convertedValue, typed, config.enableConstraintValidation); + } catch (BError e) { + return e; + } finally { + csvTree.reset(); + } + } + static class CsvTree { Object currentCsvNode; Field currentField; @@ -92,18 +103,48 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { this.config = config; sourceArrayElementType = TypeUtils.getReferredType(csv.getElementType()); Type referredType = TypeUtils.getReferredType(type); - int expectedArraySize = ((ArrayType) referredType).getSize(); int sourceArraySize = (int) csv.getLength(); + if (referredType.getTag() == TypeTags.INTERSECTION_TAG) { + return CsvCreator.constructReadOnlyValue(traverseCsv(csv, config, + ((IntersectionType) referredType).getEffectiveType())); + } - setRootCsvNode(referredType, type); - validateExpectedArraySize(expectedArraySize, sourceArraySize); - - traverseCsvWithExpectedType(expectedArraySize, sourceArraySize, csv, config); + if (referredType.getTag() != TypeTags.UNION_TAG) { + int expectedArraySize = ((ArrayType) referredType).getSize(); + setRootCsvNodeForNonUnionArrays(referredType, type); + validateExpectedArraySize(expectedArraySize, sourceArraySize); + traverseCsvWithExpectedType(expectedArraySize, sourceArraySize, csv, type); + } else { + traverseCsvWithUnionExpectedType(referredType, type, sourceArraySize, csv, config); + } return rootCsvNode; } - private void traverseCsvWithExpectedType(int expectedArraySize, - int sourceArraySize, BArray csv, CsvConfig config) { + private void traverseCsvWithUnionExpectedType(Type referredType, Type type, int sourceArraySize, + BArray csv, CsvConfig config) { + for (Type memberType: ((UnionType) referredType).getMemberTypes()) { + Type mType = TypeUtils.getReferredType(memberType); + if (mType.getTag() == TypeTags.ARRAY_TAG) { + int expectedArraySize = ((ArrayType) mType).getSize(); + try { + setRootCsvNodeForNonUnionArrays(mType, mType); + validateExpectedArraySize(expectedArraySize, sourceArraySize); + traverseCsvWithExpectedType(expectedArraySize, sourceArraySize, csv, type); + return; + } catch (Exception ex) { + // ignore + } + } + } + throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); + } + + private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArraySize, + BArray csv, Type type) { + if (expectedArrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { + expectedArrayElementType = ((IntersectionType) expectedArrayElementType).getEffectiveType(); + } + switch (expectedArrayElementType.getTag()) { case TypeTags.RECORD_TYPE_TAG: case TypeTags.MAP_TAG: @@ -117,19 +158,11 @@ private void traverseCsvWithExpectedType(int expectedArraySize, sourceArraySize : expectedArraySize, csv, expectedArrayElementType); break; case TypeTags.UNION_TAG: - for (Type memberType : ((UnionType) expectedArrayElementType).getMemberTypes()) { - try { - traverseCsv(csv, config, TypeCreator.createArrayType(memberType)); - return; - } catch (Exception e) { - //ignore - } - } - throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, - expectedArrayElementType); + traverseCsvArrayMembersWithUnionAsCsvElementType(expectedArraySize == -1 ? + sourceArraySize : expectedArraySize, csv, (UnionType) expectedArrayElementType, type); + break; default: - throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, - expectedArrayElementType); + throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); } } @@ -155,6 +188,40 @@ public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray } } + public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray csv, + UnionType expectedArrayType, Type type) { + Object rowValue; + for (int i = 0; i < length; i++) { + boolean isCompatible = false; + if (ignoreRow(i + 1, config.skipLines)) { + continue; + } + Object csvData = csv.get(i); + for (Type memberType: expectedArrayType.getMemberTypes()) { + try { + memberType = TypeUtils.getReferredType(memberType); + 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); + } else { + continue; + } + rootCsvNode.append(rowValue); + isCompatible = true; + break; + } catch (Exception e) { + // ignore + } + } + if (!isCompatible) { + throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); + } + } + } + private static boolean ignoreRow(int index, Object skipLinesConfig) { long[] skipLines = getSkipDataRows(skipLinesConfig); for (long skipLine: skipLines) { @@ -166,6 +233,7 @@ private static boolean ignoreRow(int index, Object skipLinesConfig) { } public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expectedType) { + expectedType = TypeUtils.getReferredType(expectedType); switch (expectedType.getTag()) { case TypeTags.RECORD_TYPE_TAG: RecordType recordType = (RecordType) expectedType; @@ -190,6 +258,7 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected } public Object traverseCsvElementWithArray(Object csvElement, Type expectedType) { + expectedType = TypeUtils.getReferredType(expectedType); switch (expectedType.getTag()) { case TypeTags.ARRAY_TAG: ArrayType arrayType = (ArrayType) expectedType; @@ -619,13 +688,18 @@ public void addValuesToArrayType(Object arrayValue, Type type, int index, throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_ARRAY, arrayValue, index, type); } - private void setRootCsvNode(Type referredType, Type type) { - if (referredType.getTag() != TypeTags.ARRAY_TAG) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); - } else { - rootCsvNode = ValueCreator.createArrayValue((ArrayType) referredType); - expectedArrayElementType = TypeUtils.getReferredType(((ArrayType) referredType).getElementType()); + private void setRootCsvNodeForNonUnionArrays(Type referredType, Type type) { + referredType = TypeUtils.getReferredType(referredType); + if (referredType.getTag() == TypeTags.INTERSECTION_TAG) { + referredType = ((IntersectionType) referredType).getEffectiveType(); + } + if (referredType.getTag() == TypeTags.ARRAY_TAG) { + ArrayType arrayType = (ArrayType) referredType; + rootCsvNode = ValueCreator.createArrayValue(arrayType); + expectedArrayElementType = TypeUtils.getReferredType((arrayType).getElementType()); + return; } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); } } } From e291761f5e6eb937c8358676ee2c6e70b3db5e4e Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 26 Jun 2024 23:56:11 +0530 Subject: [PATCH 039/147] Add tests for finite types --- .../tests/test_with_intersection_types.bal | 149 +++++++++++++++--- ballerina/tests/test_with_singleton_test.bal | 55 +++++++ .../stdlib/data/csvdata/csv/CsvCreator.java | 6 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 133 ++++++++-------- .../stdlib/data/csvdata/utils/CsvUtils.java | 22 ++- 5 files changed, 277 insertions(+), 88 deletions(-) create mode 100644 ballerina/tests/test_with_singleton_test.bal diff --git a/ballerina/tests/test_with_intersection_types.bal b/ballerina/tests/test_with_intersection_types.bal index e1ec3fa..131a189 100644 --- a/ballerina/tests/test_with_intersection_types.bal +++ b/ballerina/tests/test_with_intersection_types.bal @@ -1,59 +1,170 @@ import ballerina/test; -boolean enable = true; +// boolean enable = true; -@test:Config {enable: !enable} -function debugTest() returns error? { - (int[] & readonly)[]|CsvConversionError a = parseStringToList(string `a,b - 1,2 - 4,5`); - test:assertEquals(a, [[1, 2], [4, 5]]); -} +// @test:Config {enable: !enable} +// function debugTest() returns error? { +// (int[] & readonly)[]|CsvConversionError a = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); +// test:assertEquals(a, ""); +// } @test:Config {enable} function testIntersectionExpectedTypes() returns error? { (int[] & readonly)[]|CsvConversionError a = parseStringToList(string `a,b 1,2 4,5`); + test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); ([string, string])[] & readonly|CsvConversionError a2 = parseStringToList(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)[]|CsvConversionError a3 = parseStringToRecord(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|CsvConversionError a4 = parseStringToRecord(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"}]); -} -@test:Config {enable} -function testIntersectionExpectedTypes2() returns error? { - (int[] & readonly)[]|CsvConversionError a = parseStringToList(string `a,b + ([int] & readonly)[]|CsvConversionError a5 = parseStringToList(string `a,b 1,2 4,5`); - test:assertEquals(a, [[1, 2], [4, 5]]); + test:assertTrue(a5 is ([int] & readonly)[]); + test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|CsvConversionError a2 = parseStringToList(string `a,b + ([string, string])[] & readonly|CsvConversionError a6 = parseStringToList(string `a,b a,a c,c`); - test:assertEquals(a2, [["a", "a"], ["c", "c"]]); + test:assertTrue(a6 is [string, string][] & readonly); + test:assertEquals(a6, [["a", "a"], ["c", "c"]]); - (record{int a; string b;} & readonly)[]|CsvConversionError a3 = parseStringToRecord(string `a,b + (record{int a; string b;} & readonly)[]|CsvConversionError a7 = parseStringToRecord(string `a,b 1,2 4,5`); - test:assertEquals(a3, [{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"}]); - record{|string...;|}[] & readonly|CsvConversionError a4 = parseStringToRecord(string `a,b + map[] & readonly|CsvConversionError a8 = parseStringToRecord(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)[]|CsvConversionError a9 = parseStringToList(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|CsvConversionError a10 = parseStringToRecord(string `a,b + a,a + 1,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 {enable} +function testIntersectionExpectedTypes2() returns error? { + (int[] & readonly)[]|CsvConversionError a = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); + test:assertTrue(a is (int[] & readonly)[]); + test:assertEquals(a, [[1, 2], [4, 5]]); + + ([string, string])[] & readonly|CsvConversionError a2 = parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); + test:assertTrue(a2 is [string, string][] & readonly); + test:assertEquals(a2, [["a", "a"], ["c", "c"]]); + + (record{int a; string b;} & readonly)[]|CsvConversionError a3 = parseRecordAsRecordType([{"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|CsvConversionError a4 = parseRecordAsRecordType([{"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)[]|CsvConversionError a5 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); + test:assertTrue(a5 is ([int] & readonly)[]); + test:assertEquals(a5, [[1], [4]]); + + ([string, string])[] & readonly|CsvConversionError a6 = parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); + test:assertTrue(a6 is [string, string][] & readonly); + test:assertEquals(a6, [["a", "a"], ["c", "c"]]); + + (record{int a; string b;} & readonly)[]|CsvConversionError a7 = parseRecordAsRecordType([{"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|CsvConversionError a8 = parseRecordAsRecordType([{"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)[]|CsvConversionError a9 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["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|CsvConversionError a10 = parseRecordAsRecordType([{"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 {enable} +function testIntersectionExpectedTypes3() returns error? { + (int[] & readonly)[]|CsvConversionError a = parseListAsListType([["1", "2"], ["4", "5"]], {}); + test:assertTrue(a is (int[] & readonly)[]); + test:assertEquals(a, [[1, 2], [4, 5]]); + + ([string, string])[] & readonly|CsvConversionError a2 = parseListAsListType([["a", "a"], ["c", "c"]], {}); + test:assertTrue(a2 is [string, string][] & readonly); + test:assertEquals(a2, [["a", "a"], ["c", "c"]]); + + (record{int a; string b;} & readonly)[]|CsvConversionError a3 = parseListAsRecordType([["1", "2"], ["4", "5"]], ["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|CsvConversionError a4 = parseListAsRecordType([["a", "a"], ["c", "c"]], ["a", "b"], {}); + test:assertTrue(a4 is record{|string...;|}[] & readonly); test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); + + ([int] & readonly)[]|CsvConversionError a5 = parseListAsListType([["1", "2"], ["4", "5"]], {}); + test:assertTrue(a5 is ([int] & readonly)[]); + test:assertEquals(a5, [[1], [4]]); + + ([string, string])[] & readonly|CsvConversionError a6 = parseListAsListType([["a", "a"], ["c", "c"]], {}); + test:assertTrue(a6 is [string, string][] & readonly); + test:assertEquals(a6, [["a", "a"], ["c", "c"]]); + + (record{int a; string b;} & readonly)[]|CsvConversionError a7 = parseListAsRecordType([["1", "2"], ["4", "5"]], ["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|CsvConversionError a8 = parseListAsRecordType([["a", "a"], ["c", "c"]], ["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)[]|CsvConversionError a9 = parseListAsListType([["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|CsvConversionError a10 = parseListAsRecordType([["a", "a"], ["1", "2"]], ["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|CsvConversionError a11 = parseListAsRecordType([["a", "a"], ["1", "2"]], ["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}]); } -// TODO: Add tetsts for Singleton, table \ No newline at end of file +// TODO: Add tetsts for, table +// Ignore whitespace in certain conditions +// tests for unicodes \ No newline at end of file diff --git a/ballerina/tests/test_with_singleton_test.bal b/ballerina/tests/test_with_singleton_test.bal new file mode 100644 index 0000000..5f01901 --- /dev/null +++ b/ballerina/tests/test_with_singleton_test.bal @@ -0,0 +1,55 @@ +import ballerina/test; + +boolean enable = true; + +@test:Config {enable: !enable} +function debugTest() returns error? { + +} + +type Singleton 1; + +@test:Config {enable} +function testSingletonExpectedTypes() returns error? { + 1[][]|CsvConversionError a = parseStringToList(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;}[]|CsvConversionError a2 = parseStringToRecord(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...;|}[]|CsvConversionError a3 = parseStringToRecord(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...][]|CsvConversionError a4 = parseStringToList(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;|}[]|CsvConversionError a5 = parseStringToRecord(string `a, b, c + 1, 1, 1 + 1, 1,1 `); + test:assertEquals(a5, [{a: 1, b: 1}, {a: 1, b: 1}]); + + [Singleton, Singleton][]|CsvConversionError a6 = parseStringToList(string `a, b, c + 1, 1, 1 + 1, 1,1 `); + test:assertEquals(a6, [[1, 1], [1, 1]]); + + record {|"a"|"c" a; "b" b;|}[]|CsvConversionError a7 = parseStringToRecord(string `a, b, c + a, c, 1 + 1, 1,1 `); + test:assertTrue(a7 is CsvConversionError); + test:assertEquals((a7).message(), generateErrorMessageForInvalidCast("c", "\"b\"")); + + ["a"|"d", "b"][]|CsvConversionError a8 = parseStringToList(string `a, b, c + a, b, 1 + c, b,1 `); + test:assertTrue(a8 is CsvConversionError); + test:assertEquals((a8).message(), generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); +} \ No newline at end of file diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 97b1d42..6be54aa 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -37,6 +37,7 @@ import org.ballerinalang.langlib.value.CloneReadOnly; import java.util.Map; +import java.util.Optional; import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getUpdatedHeaders; /** @@ -49,7 +50,10 @@ public class CsvCreator { static Object initRowValue(Type expectedType) { expectedType = TypeUtils.getReferredType(expectedType); if (expectedType.getTag() == TypeTags.INTERSECTION_TAG) { - expectedType = ((IntersectionType) expectedType).getEffectiveType(); + Optional mutableType = CsvUtils.getMutableType((IntersectionType) expectedType); + if (!mutableType.isEmpty()) { + expectedType = mutableType.get(); + } } switch (expectedType.getTag()) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index ebaba33..8009c5e 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -20,6 +20,7 @@ import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.*; @@ -105,11 +106,26 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { Type referredType = TypeUtils.getReferredType(type); int sourceArraySize = (int) csv.getLength(); if (referredType.getTag() == TypeTags.INTERSECTION_TAG) { - return CsvCreator.constructReadOnlyValue(traverseCsv(csv, config, - ((IntersectionType) referredType).getEffectiveType())); + Optional mutableType = getMutableType((IntersectionType) referredType); + if (mutableType.isPresent()) { + return CsvCreator.constructReadOnlyValue(traverseCsv(csv, config, mutableType.get())); + } } if (referredType.getTag() != TypeTags.UNION_TAG) { + if (referredType.getTag() == TypeTags.ARRAY_TAG) { + Type arrayElementType = TypeUtils.getReferredType(((ArrayType) referredType).getElementType()); + if (arrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { + Optional mutableType = getMutableType((IntersectionType) arrayElementType); + if (mutableType.isPresent()) { + return CsvCreator.constructReadOnlyValue( + traverseCsv(csv, config, TypeCreator.createArrayType( + mutableType.get() + )) + ); + } + } + } int expectedArraySize = ((ArrayType) referredType).getSize(); setRootCsvNodeForNonUnionArrays(referredType, type); validateExpectedArraySize(expectedArraySize, sourceArraySize); @@ -141,8 +157,13 @@ private void traverseCsvWithUnionExpectedType(Type referredType, Type type, int private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArraySize, BArray csv, Type type) { + boolean isIntersection = false; if (expectedArrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { - expectedArrayElementType = ((IntersectionType) expectedArrayElementType).getEffectiveType(); + Optional mutableType = getMutableType((IntersectionType) expectedArrayElementType); + if (mutableType.isPresent()) { + isIntersection = true; + expectedArrayElementType = mutableType.get(); + } } switch (expectedArrayElementType.getTag()) { @@ -150,40 +171,58 @@ private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArrayS case TypeTags.MAP_TAG: case TypeTags.TABLE_TAG: traverseCsvArrayMembersWithMapAsCsvElementType(expectedArraySize == -1 ? - sourceArraySize : expectedArraySize, csv, expectedArrayElementType); + sourceArraySize : expectedArraySize, csv, expectedArrayElementType, isIntersection); break; case TypeTags.ARRAY_TAG: case TypeTags.TUPLE_TAG: traverseCsvArrayMembersWithArrayAsCsvElementType(expectedArraySize == -1 ? - sourceArraySize : expectedArraySize, csv, expectedArrayElementType); + sourceArraySize : expectedArraySize, csv, expectedArrayElementType, isIntersection); break; case TypeTags.UNION_TAG: traverseCsvArrayMembersWithUnionAsCsvElementType(expectedArraySize == -1 ? sourceArraySize : expectedArraySize, csv, (UnionType) expectedArrayElementType, type); break; + case TypeTags.INTERSECTION_TAG: + for (Type constituentType : ((IntersectionType) expectedArrayElementType).getConstituentTypes()) { + if (constituentType.getTag() == TypeTags.READONLY_TAG) { + continue; + } + config.stringConversion = true; + CsvCreator.constructReadOnlyValue(this.traverseCsv( + csv, config, TypeCreator.createArrayType(constituentType))); + } + break; default: throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); } } - public void traverseCsvArrayMembersWithMapAsCsvElementType(long length, BArray csv, Type expectedArrayType) { + public void traverseCsvArrayMembersWithMapAsCsvElementType(long length, BArray csv, Type expectedArrayType, + boolean isIntersection) { Object rowValue; for (int i = 0; i < length; i++) { if (ignoreRow(i + 1, config.skipLines)) { continue; } rowValue = traverseCsvElementWithMapOrRecord(csv.get(i), expectedArrayType); + if (isIntersection) { + rowValue = CsvCreator.constructReadOnlyValue(rowValue); + } rootCsvNode.append(rowValue); } } - public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray csv, Type expectedArrayType) { + public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray csv, Type expectedArrayType, + boolean isIntersection) { Object rowValue; for (int i = 0; i < length; i++) { if (ignoreRow(i + 1, config.skipLines)) { continue; } rowValue = traverseCsvElementWithArray(csv.get(i), expectedArrayType); + if (isIntersection) { + rowValue = CsvCreator.constructReadOnlyValue(rowValue); + } rootCsvNode.append(rowValue); } } @@ -198,8 +237,17 @@ public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray } Object csvData = csv.get(i); for (Type memberType: expectedArrayType.getMemberTypes()) { + boolean isIntersection = false; try { memberType = TypeUtils.getReferredType(memberType); + if (memberType.getTag() == TypeTags.INTERSECTION_TAG) { + Optional mutableType = getMutableType((IntersectionType) memberType); + if (mutableType.isPresent()) { + isIntersection = true; + memberType = mutableType.get(); + } + } + if (memberType.getTag() == TypeTags.MAP_TAG || memberType.getTag() == TypeTags.RECORD_TYPE_TAG) { rowValue = traverseCsvElementWithMapOrRecord(csvData, memberType); @@ -209,11 +257,14 @@ public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray } else { continue; } + if (isIntersection) { + rowValue = CsvCreator.constructReadOnlyValue(rowValue); + } rootCsvNode.append(rowValue); isCompatible = true; break; } catch (Exception e) { - // ignore + int a = 1; } } if (!isCompatible) { @@ -543,60 +594,6 @@ private void addFieldInMapType(BString key) { fieldNames.push(key.toString()); } - private void addCurrentFieldValue2(Type currentFieldType, Object mapValue, BString key, boolean isMapType) { - int currentFieldTypeTag = currentFieldType.getTag(); - Object nilValue = config.nilValue; - if (config.nilAsOptionalField && !currentFieldType.isNilable() - && CsvUtils.isNullValue(nilValue, mapValue) - && currentField != null && SymbolFlags.isFlagOn(currentField.getFlags(), SymbolFlags.OPTIONAL)) { - return; - } - switch (currentFieldTypeTag) { - case TypeTags.NULL_TAG: - case TypeTags.BOOLEAN_TAG: - case TypeTags.INT_TAG: - case TypeTags.FLOAT_TAG: - case TypeTags.DECIMAL_TAG: - case TypeTags.STRING_TAG: - case TypeTags.JSON_TAG: - case TypeTags.ANYDATA_TAG: - if (checkTypeCompatibility(currentFieldType, mapValue, config.stringConversion)) { - Object value = convertToBasicType(mapValue, currentFieldType, config); - if (!(value instanceof BError)) { - ((BMap) currentCsvNode) - .put(StringUtils.fromString(fieldNames.pop()), value); - return; - } - } - if (isMapType) { - return; - } - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); - case TypeTags.UNION_TAG: - for (Type memberType: ((UnionType) currentFieldType).getMemberTypes()) { - if (!isBasicType(memberType)) { - throw DiagnosticLog.error(DiagnosticErrorCode - .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); - } - if (checkTypeCompatibility(memberType, mapValue, config.stringConversion)) { - Object value = convertToBasicType(mapValue, memberType, config); - if (!(value instanceof BError)) { - ((BMap) currentCsvNode) - .put(StringUtils.fromString(fieldNames.pop()), value); - return; - } - } - } - if (isMapType) { - return; - } - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); - default: - // TODO: handle maps and structure values in future - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, mapValue, key); - } - } - private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { Type fieldType = TypeUtils.getReferredType(type); Object nilValue = config.nilValue; @@ -620,6 +617,15 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { case TypeTags.STRING_TAG: case TypeTags.JSON_TAG: case TypeTags.ANYDATA_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: + case TypeTags.FINITE_TYPE_TAG: if (checkTypeCompatibility(fieldType, csvMember, config.stringConversion)) { Object value = convertToBasicType(csvMember, fieldType, config); if (!(value instanceof BError)) { @@ -690,9 +696,6 @@ public void addValuesToArrayType(Object arrayValue, Type type, int index, private void setRootCsvNodeForNonUnionArrays(Type referredType, Type type) { referredType = TypeUtils.getReferredType(referredType); - if (referredType.getTag() == TypeTags.INTERSECTION_TAG) { - referredType = ((IntersectionType) referredType).getEffectiveType(); - } if (referredType.getTag() == TypeTags.ARRAY_TAG) { ArrayType arrayType = (ArrayType) referredType; rootCsvNode = ValueCreator.createArrayValue(arrayType); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 392799b..4bae020 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; +import java.util.Optional; import static io.ballerina.runtime.api.TypeTags.INT_TAG; import static io.ballerina.stdlib.data.csvdata.utils.Constants.SKIP_LINE_RANGE_SEP; @@ -63,6 +64,16 @@ public static String[] createHeaders(String[] headers, CsvConfig config) { return headers; } + public static Optional getMutableType(IntersectionType intersectionType) { + for (Type constituentType : intersectionType.getConstituentTypes()) { + if (constituentType.getTag() == TypeTags.READONLY_TAG) { + continue; + } + return Optional.of(constituentType); + } + return Optional.empty(); + } + public static Object convertToBasicType(Object csv, Type targetType, CsvConfig config) { if (csv == null) { csv = config.nilValue; @@ -92,9 +103,14 @@ public static boolean isHeaderFieldsEmpty(Map currentField) { public static boolean checkTypeCompatibility(Type constraintType, Object csv, boolean stringConversion) { int tag = constraintType.getTag(); - if ((csv instanceof BString && (stringConversion || tag == TypeTags.STRING_TAG || isJsonOrAnyDataOrAny(tag))) - || (csv instanceof Long && (tag == INT_TAG || tag == TypeTags.FLOAT_TAG - || tag == TypeTags.DECIMAL_TAG || isJsonOrAnyDataOrAny(tag))) + if ((csv instanceof BString && (stringConversion || tag == TypeTags.STRING_TAG + || tag == TypeTags.CHAR_STRING_TAG || isJsonOrAnyDataOrAny(tag))) + || (csv instanceof Long && (tag == INT_TAG + || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.BYTE_TAG + || tag == TypeTags.SIGNED8_INT_TAG || tag == TypeTags.SIGNED16_INT_TAG + || tag == TypeTags.SIGNED32_INT_TAG || tag == TypeTags.UNSIGNED8_INT_TAG + || tag == TypeTags.UNSIGNED16_INT_TAG || tag == TypeTags.UNSIGNED32_INT_TAG + || isJsonOrAnyDataOrAny(tag))) || (csv instanceof BDecimal && ((tag == TypeTags.DECIMAL_TAG || tag == TypeTags.FLOAT_TAG || tag == INT_TAG) || isJsonOrAnyDataOrAny(tag))) || (csv instanceof Double && ((tag == TypeTags.FLOAT_TAG From 30fb9e49574fc137ba1fcdcaaa36289e42939849 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 27 Jun 2024 15:57:26 +0530 Subject: [PATCH 040/147] Add implementation and tests for Singleton and subtypes --- .../tests/parse_list_type_as_record_test.bal | 8 +- ballerina/tests/test_with_singleton_test.bal | 174 +++++++++++++++++- .../stdlib/data/csvdata/csv/CsvTraversal.java | 18 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 17 +- 4 files changed, 203 insertions(+), 14 deletions(-) diff --git a/ballerina/tests/parse_list_type_as_record_test.bal b/ballerina/tests/parse_list_type_as_record_test.bal index 11774be..861e0ac 100644 --- a/ballerina/tests/parse_list_type_as_record_test.bal +++ b/ballerina/tests/parse_list_type_as_record_test.bal @@ -229,19 +229,19 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { CustomRecord25Array|CsvConversionError st1cr25 = parseListAsRecordType([st1, st1], (), {}, CustomRecord25Array); test:assertTrue(st1cr25 is CsvConversionError); - test:assertEquals((st1cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:CustomRecord25")); + test:assertEquals((st1cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); CustomRecord25Array|CsvConversionError st2cr25 = parseListAsRecordType([st2, st2], (), {}, CustomRecord25Array); test:assertTrue(st2cr25 is CsvConversionError); - test:assertEquals((st2cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:CustomRecord25")); + test:assertEquals((st2cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); CustomRecord25Array|CsvConversionError st3cr25 = parseListAsRecordType([st3, st3], (), {}, CustomRecord25Array); test:assertTrue(st3cr25 is CsvConversionError); - test:assertEquals((st3cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:CustomRecord25")); + test:assertEquals((st3cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); CustomRecord25Array|CsvConversionError st4cr25 = parseListAsRecordType([st4, st4], (), {}, CustomRecord25Array); test:assertTrue(st4cr25 is CsvConversionError); - test:assertEquals((st4cr25).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:CustomRecord25")); + test:assertEquals((st4cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); CustomRecord26Array|CsvConversionError st1cr26 = parseListAsRecordType([st1, st1], (), {}, CustomRecord26Array); test:assertEquals(st1cr26 , [ diff --git a/ballerina/tests/test_with_singleton_test.bal b/ballerina/tests/test_with_singleton_test.bal index 5f01901..14fadb9 100644 --- a/ballerina/tests/test_with_singleton_test.bal +++ b/ballerina/tests/test_with_singleton_test.bal @@ -4,7 +4,20 @@ boolean enable = true; @test:Config {enable: !enable} function debugTest() returns error? { - + var value1 = [{a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}, + {a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}]; + var value2 = [{a: 1, c: int:MAX_VALUE, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}, + {a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}]; + var value3 = [[1, 1, 1, 1, "a", 1, 1, 1], + [1, 1, 1, 1, "a", 1, 1, 1]]; + var value4 = [["1", "1", "1", "1", "a", "1", "1", "1"], + ["1", "1", "1", "1", "a", "1", "1", "1"]]; + + // SubtypeRecord2[]|CsvConversionError a14 = parseListAsRecordType(value4, + // ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + record {int a; int b;}[]|CsvConversionError a14 = parseListAsRecordType([["1", "2"], ["1", "2"]], + ["a", "b"], {}); + test:assertEquals(a14, [{a: 1, c: 1}, {a: 1, c: 1}]); } type Singleton 1; @@ -52,4 +65,161 @@ function testSingletonExpectedTypes() returns error? { c, b,1 `); test:assertTrue(a8 is CsvConversionError); test:assertEquals((a8).message(), generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); -} \ No newline at end of file +} + +@test:Config {enable} +function testSingletonExpectedTypes2() returns error? { + 1[][]|CsvConversionError a = parseStringToList(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;}[]|CsvConversionError a2 = parseStringToRecord(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...;|}[]|CsvConversionError a3 = parseStringToRecord(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...][]|CsvConversionError a4 = parseStringToList(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;|}[]|CsvConversionError a5 = parseStringToRecord(string `a, b, c + 1, 1, 1 + 1, 1,1 `); + test:assertEquals(a5, [{a: 1, b: 1}, {a: 1, b: 1}]); + + [Singleton, Singleton][]|CsvConversionError a6 = parseStringToList(string `a, b, c + 1, 1, 1 + 1, 1,1 `); + test:assertEquals(a6, [[1, 1], [1, 1]]); + + record {|"a"|"c" a; "b" b;|}[]|CsvConversionError a7 = parseStringToRecord(string `a, b, c + a, c, 1 + 1, 1,1 `); + test:assertTrue(a7 is CsvConversionError); + test:assertEquals((a7).message(), generateErrorMessageForInvalidCast("c", "\"b\"")); + + ["a"|"d", "b"][]|CsvConversionError a8 = parseStringToList(string `a, b, c + a, b, 1 + c, b,1 `); + test:assertTrue(a8 is CsvConversionError); + test:assertEquals((a8).message(), generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); +} + +type SubType byte|int:Signed8|int:Signed16|int:Signed32|string:Char|int:Unsigned8|int:Unsigned16|int:Unsigned32; + +type SubtypeRecord record { + byte a; int:Signed8 c; int:Signed16 d; int:Signed32 e; + string:Char f; int:Unsigned8 g; int:Unsigned16 h; int:Unsigned32 i; +}; + +type SubtypeRecord2 record {| + byte a; int:Signed8 c; +|}; + +type SubtypeRecord3 record {| + SubType...; +|}; + +type SubtypeTuple [ + byte, int:Signed8, int:Signed16, int:Signed32, + string:Char, int:Unsigned8, int:Unsigned16, int:Unsigned32 +]; + +type SubtypeTuple2 [SubType, SubType]; + +type SubtypeTuple3 [SubType...]; + +@test:Config {enable} +function testSubtypeExpectedTypes() returns error? { + var value1 = [{a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}, + {a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}]; + var value2 = [{a: 1, c: int:MAX_VALUE, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}, + {a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}]; + var value3 = [[1, 1, 1, 1, "a", 1, 1, 1], + [1, 1, 1, 1, "a", 1, 1, 1]]; + var value4 = [["1", "1", "1", "1", "a", "1", "1", "1"], + ["1", "1", "1", "1", "a", "1", "1", "1"]]; + + SubtypeRecord[]|CsvConversionError a = parseStringToRecord(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[]|CsvConversionError a2 = parseStringToRecord(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[]|CsvConversionError a3 = parseStringToRecord(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[]|CsvConversionError a4 = parseStringToList(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[]|CsvConversionError a5 = parseStringToList(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[]|CsvConversionError a6 = parseStringToList(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[]|CsvConversionError a7 = parseRecordAsRecordType(value1, {}); + test:assertEquals(a7, value1); + + SubtypeRecord2[]|CsvConversionError a8 = parseRecordAsRecordType(value1, {}); + + test:assertEquals(a8, [{a: 1, c: 1}, {a: 1, c: 1}]); + + SubtypeRecord3[]|CsvConversionError a9 = parseRecordAsRecordType(value1, {}); + test:assertEquals(a9, value1); + + SubtypeTuple[]|CsvConversionError a10 = parseRecordAsListType(value1, + ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + test:assertEquals(a10, value3); + + SubtypeTuple2[]|CsvConversionError a11 = parseRecordAsListType(value1, + ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + test:assertEquals(a11, [[1, 1], [1, 1]]); + + SubtypeTuple3[]|CsvConversionError a12 = parseRecordAsListType(value1, + ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + test:assertEquals(a12, value3); + + SubtypeRecord[]|CsvConversionError a13 = parseListAsRecordType(value4, + ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + test:assertEquals(a13, value1); + + SubtypeRecord2[]|CsvConversionError a14 = parseListAsRecordType(value4, + ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + test:assertEquals(a14, [{a: 1, c: 1}, {a: 1, c: 1}]); + + SubtypeRecord3[]|CsvConversionError a15 = parseListAsRecordType(value4, + ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + test:assertEquals(a15, value1); + + SubtypeTuple[]|CsvConversionError a16 = parseListAsListType(value4, {}); + test:assertEquals(a16, value3); + + SubtypeTuple2[]|CsvConversionError a17 = parseListAsListType(value4, {}); + test:assertEquals(a17, [[1, 1], [1, 1]]); + + SubtypeTuple3[]|CsvConversionError a18 = parseListAsListType(value4, {}); + test:assertEquals(a18, value3); +} + +// Add implementation for source as Tuples \ No newline at end of file diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 8009c5e..b65eb8e 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -102,7 +102,7 @@ void reset() { @SuppressWarnings("unchecked") public Object traverseCsv(BArray csv, CsvConfig config, Type type) { this.config = config; - sourceArrayElementType = TypeUtils.getReferredType(csv.getElementType()); + sourceArrayElementType = TypeUtils.getReferredType(getSourceElementTypeForTupleAndArrays(csv)); Type referredType = TypeUtils.getReferredType(type); int sourceArraySize = (int) csv.getLength(); if (referredType.getTag() == TypeTags.INTERSECTION_TAG) { @@ -476,7 +476,7 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Tup Field field = this.headerFieldHierarchy.remove(header); if (field != null) { - if (type.getTag() != field.getFieldType().getTag()) { + if (!config.stringConversion && type.getTag() != field.getFieldType().getTag()) { return false; } continue; @@ -635,6 +635,7 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { break; case TypeTags.UNION_TAG: for (Type memberType : ((UnionType) fieldType).getMemberTypes()) { + memberType = TypeUtils.getReferredType(memberType); if (!isBasicType(memberType)) { throw DiagnosticLog.error(DiagnosticErrorCode .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); @@ -647,10 +648,12 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { break; case TypeTags.INTERSECTION_TAG: Type effectiveType = ((IntersectionType) fieldType).getEffectiveType(); + effectiveType = TypeUtils.getReferredType(effectiveType); if (!SymbolFlags.isFlagOn(SymbolFlags.READONLY, effectiveType.getFlags())) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type); } for (Type constituentType : ((IntersectionType) fieldType).getConstituentTypes()) { + constituentType = TypeUtils.getReferredType(constituentType); if (constituentType.getTag() == TypeTags.READONLY_TAG) { continue; } @@ -704,5 +707,16 @@ private void setRootCsvNodeForNonUnionArrays(Type referredType, Type type) { } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, type, PredefinedTypes.TYPE_ANYDATA_ARRAY); } + + private Type getSourceElementTypeForTupleAndArrays(BArray csv) { + List memberTypes = new ArrayList<>(); + if (csv.getType() instanceof TupleType tupleType) { + for (Type memberType: tupleType.getTupleTypes()) { + memberTypes.add(memberType); + } + return TypeCreator.createUnionType(memberTypes); + } + return csv.getElementType(); + } } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 4bae020..14f0509 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -6,15 +6,12 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.ValueUtils; import io.ballerina.runtime.api.values.*; -import io.ballerina.stdlib.data.csvdata.FromString; -import io.ballerina.stdlib.data.csvdata.csv.CsvCreator; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Optional; -import static io.ballerina.runtime.api.TypeTags.INT_TAG; import static io.ballerina.stdlib.data.csvdata.utils.Constants.SKIP_LINE_RANGE_SEP; public class CsvUtils { @@ -36,6 +33,14 @@ public static boolean isBasicType(Type type) { 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; @@ -105,16 +110,16 @@ public static boolean checkTypeCompatibility(Type constraintType, Object csv, bo int tag = constraintType.getTag(); if ((csv instanceof BString && (stringConversion || tag == TypeTags.STRING_TAG || tag == TypeTags.CHAR_STRING_TAG || isJsonOrAnyDataOrAny(tag))) - || (csv instanceof Long && (tag == INT_TAG + || (csv instanceof Long && (tag == TypeTags.INT_TAG || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.BYTE_TAG || tag == TypeTags.SIGNED8_INT_TAG || tag == TypeTags.SIGNED16_INT_TAG || tag == TypeTags.SIGNED32_INT_TAG || tag == TypeTags.UNSIGNED8_INT_TAG || tag == TypeTags.UNSIGNED16_INT_TAG || tag == TypeTags.UNSIGNED32_INT_TAG || isJsonOrAnyDataOrAny(tag))) || (csv instanceof BDecimal && ((tag == TypeTags.DECIMAL_TAG - || tag == TypeTags.FLOAT_TAG || tag == INT_TAG) || isJsonOrAnyDataOrAny(tag))) + || tag == TypeTags.FLOAT_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag))) || (csv instanceof Double && ((tag == TypeTags.FLOAT_TAG - || tag == TypeTags.DECIMAL_TAG || tag == INT_TAG) || isJsonOrAnyDataOrAny(tag))) + || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag))) || (Boolean.class.isInstance(csv) && (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag))) || (csv == null && (tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag)))) { return true; From 8b2f2156c8a6486b2ea702b6270af6a79748cbf4 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 2 Jul 2024 11:57:53 +0530 Subject: [PATCH 041/147] Add implementation for compiler plugin --- ballerina/Dependencies.toml | 29 +- ballerina/build.gradle | 19 +- build-config/checkstyle/build.gradle | 4 +- build-config/resources/CompilerPlugin.toml | 6 + build.gradle | 11 +- compiler-plugin-test/build.gradle | 108 +++++ .../csvdata/compiler/CompilerPluginTest.java | 156 +++++++ .../compiler/CompilerPluginTestUtils.java | 46 ++ .../src/test/resources/testng.xml | 27 ++ compiler-plugin/build.gradle | 74 ++++ .../data/csvdata/compiler/Constants.java | 41 ++ .../csvdata/compiler/CsvDataCodeAnalyzer.java | 38 ++ .../compiler/CsvDataCompilerPlugin.java | 35 ++ .../compiler/CsvDataDiagnosticCodes.java | 55 +++ .../compiler/CsvDataTypeValidator.java | 415 ++++++++++++++++++ .../src/main/java/module-info.java | 23 + gradle.properties | 15 +- native/build.gradle | 9 +- .../stdlib/data/csvdata/FromString.java | 3 +- .../stdlib/data/csvdata/csv/CsvCreator.java | 7 +- .../stdlib/data/csvdata/csv/CsvParser.java | 51 ++- .../stdlib/data/csvdata/csv/CsvTraversal.java | 62 ++- .../stdlib/data/csvdata/csv/Native.java | 45 +- .../data/csvdata/io/DataReaderTask.java | 2 +- .../stdlib/data/csvdata/utils/Constants.java | 36 +- .../stdlib/data/csvdata/utils/CsvConfig.java | 18 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 19 +- .../csvdata/utils/DiagnosticErrorCode.java | 8 +- settings.gradle | 28 +- 29 files changed, 1266 insertions(+), 124 deletions(-) create mode 100644 build-config/resources/CompilerPlugin.toml create mode 100644 compiler-plugin-test/build.gradle create mode 100644 compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTest.java create mode 100644 compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTestUtils.java create mode 100644 compiler-plugin-test/src/test/resources/testng.xml create mode 100644 compiler-plugin/build.gradle create mode 100644 compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/Constants.java create mode 100644 compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCodeAnalyzer.java create mode 100644 compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCompilerPlugin.java create mode 100644 compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataDiagnosticCodes.java create mode 100644 compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java create mode 100644 compiler-plugin/src/main/java/module-info.java diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index a702bf7..8441781 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.8.6" +distribution-version = "2201.9.0" [[package]] org = "ballerina" @@ -40,6 +40,26 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + [[package]] org = "ballerina" name = "lang.error" @@ -49,6 +69,12 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + [[package]] org = "ballerina" name = "test" @@ -56,6 +82,7 @@ version = "0.0.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, {org = "ballerina", name = "lang.error"} ] modules = [ diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 6d74edf..a46cca0 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -87,9 +87,6 @@ task updateTomlFiles { newConfig = newConfig.replace("@constraint.version@", stdlibDependentConstraintVersion) ballerinaTomlFile.text = newConfig - - // def newCompilerPluginToml = compilerPluginTomlFilePlaceHolder.text.replace("@project.version@", project.version) - // compilerPluginTomlFile.text = newCompilerPluginToml } } @@ -97,11 +94,11 @@ task commitTomlFiles { doLast { project.exec { ignoreExitValue true - // if (Os.isFamily(Os.FAMILY_WINDOWS)) { - // commandLine 'cmd', '/c', "git commit Ballerina.toml Dependencies.toml CompilerPlugin.toml -m '[Automated] Update the native jar versions'" - // } else { - // commandLine 'sh', '-c', "git commit Ballerina.toml Dependencies.toml CompilerPlugin.toml -m '[Automated] Update the native jar versions'" - // } + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "git commit Ballerina.toml Dependencies.toml CompilerPlugin.toml -m '[Automated] Update the native jar versions'" + } else { + commandLine 'sh', '-c', "git commit Ballerina.toml Dependencies.toml CompilerPlugin.toml -m '[Automated] Update the native jar versions'" + } } } } @@ -136,8 +133,10 @@ updateTomlFiles.dependsOn copyStdlibs build.dependsOn "generatePomFileForMavenPublication" build.dependsOn ":${packageName}-native:build" -//build.dependsOn ":${packageName}-compiler-plugin:build" +build.dependsOn deleteDependencyTomlFiles +build.dependsOn ":${packageName}-compiler-plugin:build" build.dependsOn deleteDependencyTomlFiles test.dependsOn ":${packageName}-native:build" -//test.dependsOn ":${packageName}-compiler-plugin:build" +test.dependsOn ":${packageName}-native:build" +test.dependsOn ":${packageName}-compiler-plugin:build" diff --git a/build-config/checkstyle/build.gradle b/build-config/checkstyle/build.gradle index 6ec1c38..857ad1e 100644 --- a/build-config/checkstyle/build.gradle +++ b/build-config/checkstyle/build.gradle @@ -23,8 +23,8 @@ apply plugin: 'java' task downloadCheckstyleRuleFiles(type: Download) { src([ - 'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/checkstyle.csv', - 'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/suppressions.csv' + 'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/checkstyle.xml', + 'https://raw.githubusercontent.com/wso2/code-quality-tools/v1.4/checkstyle/jdk-17/suppressions.xml' ]) overwrite false onlyIfNewer true diff --git a/build-config/resources/CompilerPlugin.toml b/build-config/resources/CompilerPlugin.toml new file mode 100644 index 0000000..10f4b4a --- /dev/null +++ b/build-config/resources/CompilerPlugin.toml @@ -0,0 +1,6 @@ +[plugin] +id = "constraint-compiler-plugin" +class = "io.ballerina.stdlib.data.csvdata.compiler.CsvDataCompilerPlugin" + +[[dependency]] +path = "../compiler-plugin/build/libs/data.csv-compiler-plugin-@project.version@.jar" diff --git a/build.gradle b/build.gradle index cca8674..dc3d177 100644 --- a/build.gradle +++ b/build.gradle @@ -17,10 +17,10 @@ */ plugins { - id "com.github.spotbugs" version "${githubSpotbugsVersion}" - id "com.github.johnrengelman.shadow" version "${githubJohnrengelmanShadowVersion}" - id "de.undercouch.download" version "${underCouchDownloadVersion}" - id "net.researchgate.release" version "${researchgateReleaseVersion}" + id "com.github.spotbugs" + id "com.github.johnrengelman.shadow" + id "de.undercouch.download" + id "net.researchgate.release" } allprojects { @@ -67,7 +67,10 @@ subprojects { dependencies { /* Standard libraries */ + ballerinaStdLibs "io.ballerina.stdlib:file-ballerina:${stdlibFileVersion}" ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${stdlibIoVersion}" + ballerinaStdLibs "io.ballerina.stdlib:os-ballerina:${stdlibOsVersion}" + ballerinaStdLibs "io.ballerina.stdlib:time-ballerina:${stdlibTimeVersion}" ballerinaStdLibs "io.ballerina.stdlib:constraint-ballerina:${stdlibConstraintVersion}" } } diff --git a/compiler-plugin-test/build.gradle b/compiler-plugin-test/build.gradle new file mode 100644 index 0000000..6d5c7f2 --- /dev/null +++ b/compiler-plugin-test/build.gradle @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +plugins { + id 'java' + id 'checkstyle' + id 'com.github.spotbugs' +} + +description = 'Ballerina - Csv Compiler Plugin Tests' + +dependencies { + checkstyle project(':checkstyle') + checkstyle "com.puppycrawl.tools:checkstyle:${puppycrawlCheckstyleVersion}" + + implementation project(':data.csv-compiler-plugin') + + testImplementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}" + testImplementation group: 'org.ballerinalang', name: 'ballerina-tools-api', version: "${ballerinaLangVersion}" + testImplementation group: 'org.ballerinalang', name: 'ballerina-parser', version: "${ballerinaLangVersion}" + testImplementation group: 'org.testng', name: 'testng', version: "${testngVersion}" +} + +tasks.withType(Checkstyle) { + exclude '**/module-info.java' +} + +checkstyle { + toolVersion "${project.puppycrawlCheckstyleVersion}" + configFile rootProject.file("build-config/checkstyle/build/checkstyle.xml") + configProperties = ["suppressionFile" : file("${rootDir}/build-config/checkstyle/build/suppressions.xml")] +} + +checkstyleTest.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") + +spotbugsTest { + effort "max" + reportLevel "low" + reportsDir = file("$project.buildDir/reports/spotbugs") + reports { + html.enabled true + text.enabled = true + } + def excludeFile = file("${project.projectDir}/spotbugs-exclude.xml") + if(excludeFile.exists()) { + excludeFilter = excludeFile + } +} + +spotbugsMain { + enabled false +} + +checkstyleMain { + enabled false +} + +compileJava { + doFirst { + options.compilerArgs = [ + '--module-path', classpath.asPath, + ] + classpath = files() + } +} + +test { + systemProperty "ballerina.offline.flag", "true" + useTestNG() + finalizedBy jacocoTestReport + + testLogging { + exceptionFormat = "full" + afterSuite { desc, result -> + if (!desc.parent) { // will match the outermost suite + def output = "Compiler Plugin Tests: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)" + def startItem = '| ', endItem = ' |' + def repeatLength = startItem.length() + output.length() + endItem.length() + println('\n' + ('-' * repeatLength) + '\n' + startItem + output + endItem + '\n' + ('-' * repeatLength)) + } + } + } +} + +jacocoTestReport { + dependsOn test + reports { + xml.required = true + } + sourceSets project(':data.csv-compiler-plugin').sourceSets.main +} + +test.dependsOn ":data.csv-ballerina:build" 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 new file mode 100644 index 0000000..bafb736 --- /dev/null +++ b/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTest.java @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.lib.data.csvdata.compiler; + +//import io.ballerina.projects.DiagnosticResult; +//import io.ballerina.tools.diagnostics.Diagnostic; +//import io.ballerina.tools.diagnostics.DiagnosticSeverity; +//import org.testng.Assert; +//import org.testng.annotations.Test; +// +//import java.util.List; +//import java.util.stream.Collectors; + +/** + * This class includes tests for Ballerina Csv Data compiler plugin. + */ +public class CompilerPluginTest { + +// static final String UNSUPPORTED_TYPE = "unsupported type: type is not supported"; +// +// @Test +// public void testInvalidExpectedUnionType1() { +// DiagnosticResult diagnosticResult = +// CompilerPluginTestUtils.loadPackage("sample_package_1").getCompilation().diagnosticResult(); +// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() +// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) +// .collect(Collectors.toList()); +// Assert.assertEquals(errorDiagnosticsList.size(), 1); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); +// } +// +// @Test +// public void testInvalidExpectedUnionType2() { +// DiagnosticResult diagnosticResult = +// CompilerPluginTestUtils.loadPackage("sample_package_2").getCompilation().diagnosticResult(); +// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() +// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) +// .collect(Collectors.toList()); +// Assert.assertEquals(errorDiagnosticsList.size(), 1); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); +// } +// +// @Test +// public void testInvalidRecordFieldType1() { +// DiagnosticResult diagnosticResult = +// CompilerPluginTestUtils.loadPackage("sample_package_3").getCompilation().diagnosticResult(); +// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() +// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) +// .collect(Collectors.toList()); +// Assert.assertEquals(errorDiagnosticsList.size(), 2); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); +// } +// +// @Test +// public void testInvalidRecordFieldType2() { +// DiagnosticResult diagnosticResult = +// CompilerPluginTestUtils.loadPackage("sample_package_4").getCompilation().diagnosticResult(); +// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() +// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) +// .collect(Collectors.toList()); +// Assert.assertEquals(errorDiagnosticsList.size(), 2); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); +// } +// +// @Test +// public void testDuplicateField1() { +// DiagnosticResult diagnosticResult = +// CompilerPluginTestUtils.loadPackage("sample_package_5").getCompilation().diagnosticResult(); +// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() +// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) +// .collect(Collectors.toList()); +// Assert.assertEquals(errorDiagnosticsList.size(), 1); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), +// "invalid field: duplicate field found"); +// } +// +// @Test +// public void testDuplicateField2() { +// DiagnosticResult diagnosticResult = +// CompilerPluginTestUtils.loadPackage("sample_package_6").getCompilation().diagnosticResult(); +// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() +// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) +// .collect(Collectors.toList()); +// Assert.assertEquals(errorDiagnosticsList.size(), 2); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), +// "invalid field: duplicate field found"); +// Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo().messageFormat(), +// "invalid field: duplicate field found"); +// } +// +// @Test +// public void testComplexUnionTypeAsExpectedType() { +// DiagnosticResult diagnosticResult = +// CompilerPluginTestUtils.loadPackage("sample_package_7").getCompilation().diagnosticResult(); +// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() +// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) +// .collect(Collectors.toList()); +// Assert.assertEquals(errorDiagnosticsList.size(), 2); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); +// Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); +// } +// +// @Test +// public void testComplexUnionTypeAsMemberOfIntersection() { +// DiagnosticResult diagnosticResult = +// CompilerPluginTestUtils.loadPackage("sample_package_8").getCompilation().diagnosticResult(); +// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() +// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) +// .collect(Collectors.toList()); +// Assert.assertEquals(errorDiagnosticsList.size(), 1); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); +// } +// +// @Test +// public void testComplexUnionTypeCaseWhenUserDefinedModulePrefix1() { +// DiagnosticResult diagnosticResult = +// CompilerPluginTestUtils.loadPackage("sample_package_9").getCompilation().diagnosticResult(); +// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() +// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) +// .collect(Collectors.toList()); +// Assert.assertEquals(errorDiagnosticsList.size(), 1); +// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), +// UNSUPPORTED_TYPE); +// } +// +// @Test +// public void testComplexUnionTypeCaseWhenUserDefinedModulePrefix2() { +// DiagnosticResult diagnosticResult = +// CompilerPluginTestUtils.loadPackage("sample_package_10").getCompilation().diagnosticResult(); +// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() +// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) +// .collect(Collectors.toList()); +// Assert.assertEquals(errorDiagnosticsList.size(), 3); +// 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); +// } +} diff --git a/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTestUtils.java b/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTestUtils.java new file mode 100644 index 0000000..13c34d1 --- /dev/null +++ b/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTestUtils.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.lib.data.csvdata.compiler; + +import io.ballerina.projects.Package; +import io.ballerina.projects.ProjectEnvironmentBuilder; +import io.ballerina.projects.directory.BuildProject; +import io.ballerina.projects.environment.Environment; +import io.ballerina.projects.environment.EnvironmentBuilder; + +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Utility functions related to compiler plugins tests. + */ +public class CompilerPluginTestUtils { + private static final Path RESOURCE_DIRECTORY = Paths.get("src", "test", "resources", "ballerina_sources") + .toAbsolutePath(); + private static final Path DISTRIBUTION_PATH = Paths.get("../", "target", "ballerina-runtime") + .toAbsolutePath(); + + static Package loadPackage(String path) { + Path projectDirPath = RESOURCE_DIRECTORY.resolve(path); + Environment environment = EnvironmentBuilder.getBuilder().setBallerinaHome(DISTRIBUTION_PATH).build(); + ProjectEnvironmentBuilder projectEnvironmentBuilder = ProjectEnvironmentBuilder.getBuilder(environment); + BuildProject project = BuildProject.load(projectEnvironmentBuilder, projectDirPath); + return project.currentPackage(); + } +} diff --git a/compiler-plugin-test/src/test/resources/testng.xml b/compiler-plugin-test/src/test/resources/testng.xml new file mode 100644 index 0000000..02c1d8e --- /dev/null +++ b/compiler-plugin-test/src/test/resources/testng.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + diff --git a/compiler-plugin/build.gradle b/compiler-plugin/build.gradle new file mode 100644 index 0000000..f30d515 --- /dev/null +++ b/compiler-plugin/build.gradle @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +plugins { + id 'java' + id 'checkstyle' + id 'com.github.spotbugs' +} + +description = 'Ballerina - Csv Data Compiler Plugin' + +dependencies { + checkstyle project(':checkstyle') + checkstyle "com.puppycrawl.tools:checkstyle:${puppycrawlCheckstyleVersion}" + + implementation group: 'org.ballerinalang', name: 'ballerina-lang', version: "${ballerinaLangVersion}" + implementation group: 'org.ballerinalang', name: 'ballerina-tools-api', version: "${ballerinaLangVersion}" + implementation group: 'org.ballerinalang', name: 'ballerina-parser', version: "${ballerinaLangVersion}" +} + +def excludePattern = '**/module-info.java' +tasks.withType(Checkstyle) { + exclude excludePattern +} + +checkstyle { + toolVersion "${project.puppycrawlCheckstyleVersion}" + configFile rootProject.file("build-config/checkstyle/build/checkstyle.xml") + configProperties = ["suppressionFile" : file("${rootDir}/build-config/checkstyle/build/suppressions.xml")] +} + +checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") + +spotbugsMain { + effort "max" + reportLevel "low" + reportsDir = file("$project.buildDir/reports/spotbugs") + reports { + html.enabled true + text.enabled = true + } + def excludeFile = file("${rootDir}/spotbugs-exclude.xml") + if(excludeFile.exists()) { + excludeFilter = excludeFile + } +} + +spotbugsMain { + enabled false +} + +compileJava { + doFirst { + options.compilerArgs = [ + '--module-path', classpath.asPath, + ] + classpath = files() + } +} diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/Constants.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/Constants.java new file mode 100644 index 0000000..9dba404 --- /dev/null +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/Constants.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.compiler; + +/** + * Constants for CsvData's compiler plugin. + * + * @since 0.1.0 + */ +public 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 NAME = "Name"; + static final String CSVDATA = "csv"; + static final String BALLERINA = "ballerina"; + static final String DATA_CSVDATA = "data.csv"; +} diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCodeAnalyzer.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCodeAnalyzer.java new file mode 100644 index 0000000..86d27f1 --- /dev/null +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCodeAnalyzer.java @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.compiler; + +import io.ballerina.compiler.syntax.tree.SyntaxKind; +import io.ballerina.projects.plugins.CodeAnalysisContext; +import io.ballerina.projects.plugins.CodeAnalyzer; + +import java.util.List; + +/** + * Csvdata Code Analyzer. + * + * @since 0.1.0 + */ +public class CsvDataCodeAnalyzer extends CodeAnalyzer { + @Override + public void init(CodeAnalysisContext codeAnalysisContext) { + codeAnalysisContext.addSyntaxNodeAnalysisTask(new CsvDataTypeValidator(), + List.of(SyntaxKind.MODULE_PART)); + } +} diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCompilerPlugin.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCompilerPlugin.java new file mode 100644 index 0000000..865eca3 --- /dev/null +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCompilerPlugin.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.compiler; + +import io.ballerina.projects.plugins.CompilerPlugin; +import io.ballerina.projects.plugins.CompilerPluginContext; + +/** + * Compiler plugin for Csvdata's utils functions. + * + * @since 0.1.0 + */ +public class CsvDataCompilerPlugin extends CompilerPlugin { + + @Override + public void init(CompilerPluginContext compilerPluginContext) { + compilerPluginContext.addCodeAnalyzer(new CsvDataCodeAnalyzer()); + } +} diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataDiagnosticCodes.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataDiagnosticCodes.java new file mode 100644 index 0000000..57c9cac --- /dev/null +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataDiagnosticCodes.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.compiler; + +import io.ballerina.tools.diagnostics.DiagnosticSeverity; + +import static io.ballerina.tools.diagnostics.DiagnosticSeverity.ERROR; + +/** + * Diagnostic codes for Csv data's compiler plugin. + * + * @since 0.1.0 + */ +public enum CsvDataDiagnosticCodes { + DUPLICATE_FIELD("JSON_ERROR_202", "invalid field: duplicate field found", ERROR), + UNSUPPORTED_TYPE("JSON_ERROR_203", "unsupported type: type is not supported", ERROR); + + private final String code; + private final String message; + private final DiagnosticSeverity severity; + + CsvDataDiagnosticCodes(String code, String message, DiagnosticSeverity severity) { + this.code = code; + this.message = message; + this.severity = severity; + } + + public String getCode() { + return code; + } + + public String getMessage() { + return message; + } + + public DiagnosticSeverity getSeverity() { + return severity; + } +} diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java new file mode 100644 index 0000000..519f7e7 --- /dev/null +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java @@ -0,0 +1,415 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.ballerina.stdlib.data.csvdata.compiler; + +import io.ballerina.compiler.api.ModuleID; +import io.ballerina.compiler.api.SemanticModel; +import io.ballerina.compiler.api.symbols.AnnotationAttachmentSymbol; +import io.ballerina.compiler.api.symbols.AnnotationSymbol; +import io.ballerina.compiler.api.symbols.ArrayTypeSymbol; +import io.ballerina.compiler.api.symbols.IntersectionTypeSymbol; +import io.ballerina.compiler.api.symbols.ModuleSymbol; +import io.ballerina.compiler.api.symbols.RecordFieldSymbol; +import io.ballerina.compiler.api.symbols.RecordTypeSymbol; +import io.ballerina.compiler.api.symbols.Symbol; +import io.ballerina.compiler.api.symbols.SymbolKind; +import io.ballerina.compiler.api.symbols.TupleTypeSymbol; +import io.ballerina.compiler.api.symbols.TypeDefinitionSymbol; +import io.ballerina.compiler.api.symbols.TypeDescKind; +import io.ballerina.compiler.api.symbols.TypeReferenceTypeSymbol; +import io.ballerina.compiler.api.symbols.TypeSymbol; +import io.ballerina.compiler.api.symbols.UnionTypeSymbol; +import io.ballerina.compiler.api.symbols.VariableSymbol; +import io.ballerina.compiler.syntax.tree.CheckExpressionNode; +import io.ballerina.compiler.syntax.tree.ChildNodeList; +import io.ballerina.compiler.syntax.tree.ExpressionNode; +import io.ballerina.compiler.syntax.tree.FunctionCallExpressionNode; +import io.ballerina.compiler.syntax.tree.FunctionDefinitionNode; +import io.ballerina.compiler.syntax.tree.ImportDeclarationNode; +import io.ballerina.compiler.syntax.tree.ModuleMemberDeclarationNode; +import io.ballerina.compiler.syntax.tree.ModulePartNode; +import io.ballerina.compiler.syntax.tree.ModuleVariableDeclarationNode; +import io.ballerina.compiler.syntax.tree.NameReferenceNode; +import io.ballerina.compiler.syntax.tree.Node; +import io.ballerina.compiler.syntax.tree.QualifiedNameReferenceNode; +import io.ballerina.compiler.syntax.tree.SyntaxKind; +import io.ballerina.compiler.syntax.tree.TypeDefinitionNode; +import io.ballerina.compiler.syntax.tree.VariableDeclarationNode; +import io.ballerina.projects.plugins.AnalysisTask; +import io.ballerina.projects.plugins.SyntaxNodeAnalysisContext; +import io.ballerina.tools.diagnostics.Diagnostic; +import io.ballerina.tools.diagnostics.DiagnosticFactory; +import io.ballerina.tools.diagnostics.DiagnosticInfo; +import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import io.ballerina.tools.diagnostics.Location; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * CsvData Record Field Validator. + * + * @since 0.1.0 + */ +public class CsvDataTypeValidator implements AnalysisTask { + + private SemanticModel semanticModel; + private final HashMap allDiagnosticInfo = new HashMap<>(); + Location currentLocation; + private String modulePrefix = Constants.CSVDATA; + + @Override + public void perform(SyntaxNodeAnalysisContext ctx) { + semanticModel = ctx.semanticModel(); + List diagnostics = semanticModel.diagnostics(); + boolean erroneousCompilation = diagnostics.stream() + .anyMatch(d -> d.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)); + if (erroneousCompilation) { + reset(); + return; + } + + ModulePartNode rootNode = (ModulePartNode) ctx.node(); + updateModulePrefix(rootNode); + + for (ModuleMemberDeclarationNode member : rootNode.members()) { + switch (member.kind()) { + case FUNCTION_DEFINITION -> processFunctionDefinitionNode((FunctionDefinitionNode) member, ctx); + case MODULE_VAR_DECL -> + processModuleVariableDeclarationNode((ModuleVariableDeclarationNode) member, ctx); + case TYPE_DEFINITION -> + processTypeDefinitionNode((TypeDefinitionNode) member, ctx); + } + } + + reset(); + } + + private void reset() { + semanticModel = null; + allDiagnosticInfo.clear(); + currentLocation = null; + modulePrefix = Constants.CSVDATA; + } + + private void updateModulePrefix(ModulePartNode rootNode) { + for (ImportDeclarationNode importDeclarationNode : rootNode.imports()) { + Optional symbol = semanticModel.symbol(importDeclarationNode); + if (symbol.isPresent() && symbol.get().kind() == SymbolKind.MODULE) { + ModuleSymbol moduleSymbol = (ModuleSymbol) symbol.get(); + if (isCsvdataImport(moduleSymbol)) { + modulePrefix = moduleSymbol.id().modulePrefix(); + break; + } + } + } + } + + private void processFunctionDefinitionNode(FunctionDefinitionNode functionDefinitionNode, + SyntaxNodeAnalysisContext ctx) { + ChildNodeList childNodeList = functionDefinitionNode.functionBody().children(); + for (Node node : childNodeList) { + if (node.kind() != SyntaxKind.LOCAL_VAR_DECL) { + continue; + } + VariableDeclarationNode variableDeclarationNode = (VariableDeclarationNode) node; + Optional initializer = variableDeclarationNode.initializer(); + if (initializer.isEmpty()) { + continue; + } + + currentLocation = variableDeclarationNode.typedBindingPattern().typeDescriptor().location(); + Optional symbol = semanticModel.symbol(variableDeclarationNode.typedBindingPattern()); + if (symbol.isEmpty()) { + continue; + } + + TypeSymbol typeSymbol = ((VariableSymbol) symbol.get()).typeDescriptor(); + if (!isParseFunctionOfStringSource(initializer.get())) { + checkTypeAndDetectDuplicateFields(typeSymbol, ctx); + continue; + } + + validateExpectedType(typeSymbol, ctx); + } + } + + private void checkTypeAndDetectDuplicateFields(TypeSymbol typeSymbol, SyntaxNodeAnalysisContext ctx) { + switch (typeSymbol.typeKind()) { + case RECORD -> detectDuplicateFields((RecordTypeSymbol) typeSymbol, ctx); + case ARRAY -> checkTypeAndDetectDuplicateFields(((ArrayTypeSymbol) typeSymbol).memberTypeDescriptor(), ctx); + case TUPLE -> { + for (TypeSymbol memberType : ((TupleTypeSymbol) typeSymbol).memberTypeDescriptors()) { + checkTypeAndDetectDuplicateFields(memberType, ctx); + } + } + case UNION -> { + for (TypeSymbol memberType : ((UnionTypeSymbol) typeSymbol).memberTypeDescriptors()) { + checkTypeAndDetectDuplicateFields(memberType, ctx); + } + } + case TYPE_REFERENCE -> checkTypeAndDetectDuplicateFields( + ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor(), ctx); + case INTERSECTION -> checkTypeAndDetectDuplicateFields(getRawType(typeSymbol), ctx); + } + } + + private boolean isParseFunctionOfStringSource(ExpressionNode expressionNode) { + if (expressionNode.kind() == SyntaxKind.CHECK_EXPRESSION) { + expressionNode = ((CheckExpressionNode) expressionNode).expression(); + } + + if (expressionNode.kind() != SyntaxKind.FUNCTION_CALL) { + return false; + } + NameReferenceNode nameReferenceNode = ((FunctionCallExpressionNode) expressionNode).functionName(); + if (nameReferenceNode.kind() != SyntaxKind.QUALIFIED_NAME_REFERENCE) { + return false; + } + String prefix = ((QualifiedNameReferenceNode) nameReferenceNode).modulePrefix().text(); + if (!prefix.equals(modulePrefix)) { + 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); + } + + private void validateExpectedType(TypeSymbol typeSymbol, SyntaxNodeAnalysisContext ctx) { + typeSymbol.getLocation().ifPresent(location -> currentLocation = location); + if (!isSupportedExpectedType(typeSymbol)) { + reportDiagnosticInfo(ctx, typeSymbol.getLocation(), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); + return; + } + + switch (typeSymbol.typeKind()) { + case UNION -> validateUnionType((UnionTypeSymbol) typeSymbol, typeSymbol.getLocation(), ctx); + case ARRAY -> validateArrayType((ArrayTypeSymbol) typeSymbol, ctx); + case TYPE_REFERENCE -> validateExpectedType(((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor(), ctx); + case INTERSECTION -> validateExpectedType(getRawType(typeSymbol), ctx); + } + } + + private void validateArrayType(ArrayTypeSymbol typeSymbol, SyntaxNodeAnalysisContext ctx) { + if (!isSupportedArrayMemberType(typeSymbol.memberTypeDescriptor())) { + reportDiagnosticInfo(ctx, typeSymbol.getLocation(), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); + } + } + + private void validateUnionType(UnionTypeSymbol unionTypeSymbol, Optional location, + SyntaxNodeAnalysisContext ctx) { + boolean isHasUnsupportedType = false; + List memberTypeSymbols = unionTypeSymbol.memberTypeDescriptors(); + for (TypeSymbol memberTypeSymbol : memberTypeSymbols) { + if (isSupportedUnionMemberType(getRawType(memberTypeSymbol))) { + continue; + } + isHasUnsupportedType = true; + } + + if (isHasUnsupportedType) { + reportDiagnosticInfo(ctx, location, CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); + } + } + + private boolean isSupportedUnionMemberType(TypeSymbol typeSymbol) { + TypeDescKind kind = typeSymbol.typeKind(); + if (kind == TypeDescKind.TYPE_REFERENCE) { + kind = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor().typeKind(); + } + + switch (kind) { + case ARRAY, INTERSECTION -> { + return true; + } + default -> { + return false; + } + } + } + + private boolean isSupportedArrayMemberType(TypeSymbol typeSymbol) { + TypeDescKind kind = typeSymbol.typeKind(); + if (kind == TypeDescKind.TYPE_REFERENCE) { + kind = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor().typeKind(); + } + + switch (kind) { + case RECORD, ARRAY, TUPLE, MAP -> { + return true; + } + default -> { + return false; + } + } + } + + private boolean isSupportedExpectedType(TypeSymbol typeSymbol) { + TypeDescKind kind = typeSymbol.typeKind(); + if (kind == TypeDescKind.TYPE_REFERENCE) { + kind = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor().typeKind(); + } + + switch (kind) { + case ARRAY, UNION, INTERSECTION -> { + return true; + } + default -> { + return false; + } + } + } + + private boolean isSupportedMemberType(TypeSymbol typeSymbol) { + TypeDescKind kind = typeSymbol.typeKind(); + if (kind == TypeDescKind.TYPE_REFERENCE) { + kind = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor().typeKind(); + } + + switch (kind) { + case TABLE, XML, REGEXP, RECORD, TUPLE, MAP, ARRAY -> { + return false; + } + default -> { + return true; + } + } + } + + public static TypeSymbol getRawType(TypeSymbol typeDescriptor) { + if (typeDescriptor.typeKind() == TypeDescKind.INTERSECTION) { + return getRawType(((IntersectionTypeSymbol) typeDescriptor).effectiveTypeDescriptor()); + } + if (typeDescriptor.typeKind() == TypeDescKind.TYPE_REFERENCE) { + TypeReferenceTypeSymbol typeRef = (TypeReferenceTypeSymbol) typeDescriptor; + if (typeRef.typeDescriptor().typeKind() == TypeDescKind.INTERSECTION) { + return getRawType(((IntersectionTypeSymbol) typeRef.typeDescriptor()).effectiveTypeDescriptor()); + } + TypeSymbol rawType = typeRef.typeDescriptor(); + if (rawType.typeKind() == TypeDescKind.TYPE_REFERENCE) { + return getRawType(rawType); + } + return rawType; + } + return typeDescriptor; + } + + private void reportDiagnosticInfo(SyntaxNodeAnalysisContext ctx, Optional location, + CsvDataDiagnosticCodes diagnosticsCodes) { + Location pos = location.orElseGet(() -> currentLocation); + DiagnosticInfo diagnosticInfo = new DiagnosticInfo(diagnosticsCodes.getCode(), + diagnosticsCodes.getMessage(), diagnosticsCodes.getSeverity()); + if (allDiagnosticInfo.containsKey(pos) && allDiagnosticInfo.get(pos).equals(diagnosticInfo)) { + return; + } + allDiagnosticInfo.put(pos, diagnosticInfo); + ctx.reportDiagnostic(DiagnosticFactory.createDiagnostic(diagnosticInfo, pos)); + } + + private void processModuleVariableDeclarationNode(ModuleVariableDeclarationNode moduleVariableDeclarationNode, + SyntaxNodeAnalysisContext ctx) { + Optional initializer = moduleVariableDeclarationNode.initializer(); + if (initializer.isEmpty() || !isParseFunctionOfStringSource(initializer.get())) { + return; + } + + Optional symbol = semanticModel.symbol(moduleVariableDeclarationNode.typedBindingPattern()); + if (symbol.isEmpty()) { + return; + } + validateExpectedType(((VariableSymbol) symbol.get()).typeDescriptor(), ctx); + } + + private void processTypeDefinitionNode(TypeDefinitionNode typeDefinitionNode, SyntaxNodeAnalysisContext ctx) { + Node typeDescriptor = typeDefinitionNode.typeDescriptor(); + if (typeDescriptor.kind() != SyntaxKind.RECORD_TYPE_DESC) { + return; + } + validateRecordTypeDefinition(typeDefinitionNode, ctx); + } + + private void validateRecordTypeDefinition(TypeDefinitionNode typeDefinitionNode, SyntaxNodeAnalysisContext ctx) { + Optional symbol = semanticModel.symbol(typeDefinitionNode); + if (symbol.isEmpty()) { + return; + } + TypeDefinitionSymbol typeDefinitionSymbol = (TypeDefinitionSymbol) symbol.get(); + detectDuplicateFields((RecordTypeSymbol) typeDefinitionSymbol.typeDescriptor(), ctx); + } + + private void detectDuplicateFields(RecordTypeSymbol recordTypeSymbol, SyntaxNodeAnalysisContext ctx) { + List fieldMembers = new ArrayList<>(); + for (Map.Entry entry : recordTypeSymbol.fieldDescriptors().entrySet()) { + RecordFieldSymbol fieldSymbol = entry.getValue(); + String name = getNameFromAnnotation(entry.getKey(), fieldSymbol.annotAttachments()); + if (fieldMembers.contains(name)) { + reportDiagnosticInfo(ctx, fieldSymbol.getLocation(), CsvDataDiagnosticCodes.DUPLICATE_FIELD); + return; + } + fieldMembers.add(name); + } + } + + private String getNameFromAnnotation(String fieldName, + List annotationAttachments) { + for (AnnotationAttachmentSymbol annotAttSymbol : annotationAttachments) { + AnnotationSymbol annotation = annotAttSymbol.typeDescriptor(); + if (!getAnnotModuleName(annotation).contains(Constants.CSVDATA)) { + continue; + } + Optional nameAnnot = annotation.getName(); + if (nameAnnot.isEmpty()) { + continue; + } + String value = nameAnnot.get(); + if (value.equals(Constants.NAME)) { + return ((LinkedHashMap) annotAttSymbol.attachmentValue().orElseThrow().value()) + .get("value").toString(); + } + } + return fieldName; + } + + private String getAnnotModuleName(AnnotationSymbol annotation) { + Optional moduleSymbol = annotation.getModule(); + if (moduleSymbol.isEmpty()) { + return ""; + } + Optional moduleName = moduleSymbol.get().getName(); + return moduleName.orElse(""); + } + + private boolean isCsvdataImport(ModuleSymbol moduleSymbol) { + ModuleID moduleId = moduleSymbol.id(); + return Constants.BALLERINA.equals(moduleId.orgName()) + && Constants.DATA_CSVDATA.equals(moduleId.moduleName()); + } +} diff --git a/compiler-plugin/src/main/java/module-info.java b/compiler-plugin/src/main/java/module-info.java new file mode 100644 index 0000000..58e15de --- /dev/null +++ b/compiler-plugin/src/main/java/module-info.java @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +module io.ballerina.stdlib.csvdata.compiler { + requires io.ballerina.lang; + requires io.ballerina.tools.api; + requires io.ballerina.parser; +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 8f5d926..ee77c50 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,10 +7,17 @@ checkstyleToolVersion=10.12.0 puppycrawlCheckstyleVersion=10.12.0 testngVersion=7.6.1 slf4jVersion=2.0.7 -githubSpotbugsVersion=5.0.14 -githubJohnrengelmanShadowVersion=8.1.1 -underCouchDownloadVersion=4.0.4 -researchgateReleaseVersion=2.8.0 +spotbugsVersion=5.0.14 +shadowJarPluginVersion=8.1.1 +downloadPluginVersion=4.0.4 +releasePluginVersion=2.8.0 ballerinaGradlePluginVersion=2.0.1 +javaJsonPathVersion=2.9.0 +javaJsonSmartVersion=2.4.11 +javaAccessorsSmartVersion=2.4.7 + +stdlibFileVersion=1.9.0 stdlibIoVersion=1.6.0 +stdlibOsVersion=1.8.0 +stdlibTimeVersion=2.4.0 stdlibConstraintVersion=1.5.0 diff --git a/native/build.gradle b/native/build.gradle index 95ca507..54266fa 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -39,13 +39,12 @@ dependencies { } checkstyle { -// enabled false -// toolVersion "${checkstyleToolVersion}" -// configFile rootProject.file("build-config/checkstyle/build/checkstyle.csv") -// configProperties = ["suppressionFile" : file("${rootDir}/build-config/checkstyle/build/suppressions.csv")] + toolVersion "${checkstyleToolVersion}" + configFile rootProject.file("build-config/checkstyle/build/checkstyle.xml") + configProperties = ["suppressionFile" : file("${rootDir}/build-config/checkstyle/build/suppressions.xml")] } -//checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") +checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") def excludePattern = '**/module-info.java' tasks.withType(Checkstyle) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index 89d3e69..24afea6 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -250,7 +250,8 @@ private static Object stringToNull(String value, CsvConfig config) throws Number return returnError(value, nullValue == null ? Constants.Values.BALLERINA_NULL : nullValue.toString()); } - private static Object stringToUnion(BString string, UnionType expType, CsvConfig config) throws NumberFormatException { + private static Object stringToUnion(BString string, UnionType expType, CsvConfig config) + throws NumberFormatException { List memberTypes = new ArrayList<>(expType.getMemberTypes()); memberTypes.sort(Comparator.comparingInt(t -> { int index = TYPE_PRIORITY_ORDER.indexOf(TypeUtils.getReferredType(t).getTag()); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index 6be54aa..f04e4c6 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -22,7 +22,12 @@ import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; -import io.ballerina.runtime.api.types.*; +import io.ballerina.runtime.api.types.ArrayType; +import io.ballerina.runtime.api.types.Field; +import io.ballerina.runtime.api.types.IntersectionType; +import io.ballerina.runtime.api.types.MapType; +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.values.BArray; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 8574677..de0343b 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -23,7 +23,13 @@ import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; -import io.ballerina.runtime.api.types.*; +import io.ballerina.runtime.api.types.ArrayType; +import io.ballerina.runtime.api.types.Field; +import io.ballerina.runtime.api.types.IntersectionType; +import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.RecordType; +import io.ballerina.runtime.api.types.TupleType; +import io.ballerina.runtime.api.types.Type; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; @@ -31,17 +37,26 @@ import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DataUtils; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import org.apache.commons.lang3.StringEscapeUtils; import java.io.IOException; import java.io.Reader; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Stack; import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.checkAndAddCustomHeaders; import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.getHeaderValueForColumnIndex; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.*; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.checkRequiredFieldsAndLogError; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getSkipDataRows; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.isCharContainsInLineTerminatorUserConfig; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.processNameAnnotationsAndBuildCustomFieldMap; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.validateExpectedArraySize; /** * Convert Csv string to a ballerina record. @@ -61,11 +76,12 @@ public class CsvParser { private static final char NEWLINE = 0x000A; - private static final ThreadLocal tlStateMachine = ThreadLocal.withInitial(StateMachine::new); + private static final ThreadLocal LOCAL_THREAD_STATE_MACHINE + = ThreadLocal.withInitial(StateMachine::new); public static Object parse(Reader reader, BTypedesc type, CsvConfig config) throws BError { - StateMachine sm = tlStateMachine.get(); + StateMachine sm = LOCAL_THREAD_STATE_MACHINE.get(); try { Object convertedValue = sm.execute(reader, TypeUtils.getReferredType(type.getDescribingType()), config, type); @@ -78,20 +94,20 @@ public static Object parse(Reader reader, BTypedesc type, CsvConfig config) } static class StateMachine { - private static State HEADER_START_STATE = new HeaderStartState(); - private static State HEADER_END_STATE = new HeaderEndState(); - private static State ROW_START_STATE = new RowStartState(); - private static State ROW_END_STATE = new RowEndState(); - private static State STRING_ESCAPE_VALUE_STATE = new StringValueEscapedCharacterProcessingState(); - private static State STRING_UNICODE_CHAR_STATE = new StringValueUnicodeHexProcessingState(); - private static State HEADER_UNICODE_CHAR_STATE = new HeaderUnicodeHexProcessingState(); - private static State HEADER_ESCAPE_CHAR_STATE = new HeaderEscapedCharacterProcessingState(); - private static State STRING_QUOTE_CHAR_STATE = new StringQuoteValueState(); - private static State HEADER_QUOTE_CHAR_STATE = new HeaderQuoteValueState(); + private static final State HEADER_START_STATE = new HeaderStartState(); + private static final State HEADER_END_STATE = new HeaderEndState(); + private static final State ROW_START_STATE = new RowStartState(); + private static final State ROW_END_STATE = new RowEndState(); + private static final State STRING_ESCAPE_VALUE_STATE = new StringValueEscapedCharacterProcessingState(); + private static final State STRING_UNICODE_CHAR_STATE = new StringValueUnicodeHexProcessingState(); + private static final State HEADER_UNICODE_CHAR_STATE = new HeaderUnicodeHexProcessingState(); + private static final State HEADER_ESCAPE_CHAR_STATE = new HeaderEscapedCharacterProcessingState(); + private static final State STRING_QUOTE_CHAR_STATE = new StringQuoteValueState(); + private static final State HEADER_QUOTE_CHAR_STATE = new HeaderQuoteValueState(); - private static char LINE_BREAK = '\n'; + private static final char LINE_BREAK = '\n'; Object currentCsvNode; Stack currentEscapeCharacters = new Stack<>(); @@ -472,7 +488,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C ch = buff[i]; sm.processLocation(ch); if (sm.skipTheRow) { -// buff[i-10],buff[i-9],buff[i-8],buff[i-7],buff[i-6],buff[i-5],buff[i-4],buff[i-3],buff[i-2],buff[i-1],buff[i],buff[i+1],buff[i+2],buff[i+3] if (sm.isEndOfTheRowAndValueIsNotEmpty(sm, ch)) { sm.insideComment = false; sm.skipTheRow = false; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index b65eb8e..5fc1686 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -23,19 +23,49 @@ import io.ballerina.runtime.api.creators.TypeCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.flags.SymbolFlags; -import io.ballerina.runtime.api.types.*; +import io.ballerina.runtime.api.types.ArrayType; +import io.ballerina.runtime.api.types.Field; +import io.ballerina.runtime.api.types.IntersectionType; +import io.ballerina.runtime.api.types.MapType; +import io.ballerina.runtime.api.types.RecordType; +import io.ballerina.runtime.api.types.TupleType; +import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.UnionType; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; -import io.ballerina.runtime.api.values.*; +import io.ballerina.runtime.api.values.BArray; +import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BString; +import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DataUtils; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; +import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; -import java.util.*; - -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Deque; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.SkipMappedValue; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.UnMappedValue; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.checkRequiredFieldsAndLogError; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.checkTypeCompatibility; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.convertToBasicType; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.createHeaders; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getMutableType; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getSkipDataRows; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getTheActualExpectedType; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.isBasicType; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.isHeaderFieldsEmpty; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.processNameAnnotationsAndBuildCustomFieldMap; +import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.validateExpectedArraySize; /** * Convert Csv value to a ballerina record. @@ -482,7 +512,7 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Tup continue; } - if ((tupleRestType != null && (type == this.restType ||this.restType == tupleRestType))) { + if ((tupleRestType != null && (type == this.restType || this.restType == tupleRestType))) { continue; } @@ -503,7 +533,7 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Typ } for (String key: this.fieldHierarchy.keySet()) { // fh -> a,b | headers -> d,c - for(String header: this.headers) { + for (String header: this.headers) { if (key.equals(this.updatedRecordFieldNames.get(header))) { return true; } @@ -513,7 +543,8 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Typ return false; } - private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean mappingType, Type expectedType) { + private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, + boolean mappingType, Type expectedType) { int arraySize = csvElement.size(); String[] headers = new String[arraySize]; if (this.headers == null) { @@ -533,10 +564,10 @@ private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappin BString key; // TODO: Canges the logic with headers parameter - for(int i = 1; i <= arraySize; i++) { + for (int i = 1; i <= arraySize; i++) { key = StringUtils.fromString(this.headers[i - 1]); if (!mappingType) { - if (!isKeyBelongsToNonRestType(csvElement.get(i-1), key)) { + if (!isKeyBelongsToNonRestType(csvElement.get(i - 1), key)) { continue; } fieldType = TypeUtils.getReferredType(currentField.getFieldType()); @@ -657,7 +688,8 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { if (constituentType.getTag() == TypeTags.READONLY_TAG) { continue; } - return CsvCreator.constructReadOnlyValue(getFieldValue(constituentType, csvMember, true)); + return CsvCreator.constructReadOnlyValue(getFieldValue(constituentType, + csvMember, true)); } break; default: @@ -674,8 +706,8 @@ private void addRestField(Type type, BString key, Object csvMember) { } } - private void addCurrentFieldValue(Type type, Object RecValue, BString key, boolean isMapType) { - Object value = getFieldValue(type, RecValue, false); + private void addCurrentFieldValue(Type type, Object recValue, BString key, boolean isMapType) { + Object value = getFieldValue(type, recValue, false); if (!(value instanceof UnMappedValue || value instanceof SkipMappedValue)) { ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), value); return; @@ -684,7 +716,7 @@ private void addCurrentFieldValue(Type type, Object RecValue, BString key, boole if (isMapType || value instanceof SkipMappedValue) { return; } - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, RecValue, key); + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, recValue, key); } public void addValuesToArrayType(Object arrayValue, Type type, int index, diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index ea1bd11..dde4144 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -20,8 +20,13 @@ import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Future; -import io.ballerina.runtime.api.types.Type; -import io.ballerina.runtime.api.values.*; +import io.ballerina.runtime.api.values.BArray; +import io.ballerina.runtime.api.values.BError; +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BObject; +import io.ballerina.runtime.api.values.BStream; +import io.ballerina.runtime.api.values.BString; +import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.stdlib.data.csvdata.io.DataReaderTask; import io.ballerina.stdlib.data.csvdata.io.DataReaderThreadPool; import io.ballerina.stdlib.data.csvdata.utils.Constants; @@ -39,6 +44,7 @@ * @since 0.1.0 */ public class Native { + public static Object parseStringToRecord(BString csv, BMap options, BTypedesc type) { try { return CsvParser.parse(new StringReader(csv.getValue()), @@ -53,8 +59,8 @@ public static Object parseStringToRecord(BString csv, BMap opti public static Object parseBytesToRecord(BArray csv, BMap options, BTypedesc type) { try { byte[] bytes = csv.getBytes(); - return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), - type, CsvConfig.createParserToRecordOptions(options)); + return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), + type, CsvConfig.createParserToRecordOptions(options)); } catch (BError e) { return e; } catch (Exception e) { @@ -77,6 +83,7 @@ public static Object parseStreamToRecord(Environment env, BStream csv, return DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, type); } } + public static Object parseStringToList(BString csv, BMap options, BTypedesc type) { try { return CsvParser.parse(new StringReader(csv.getValue()), @@ -87,17 +94,19 @@ public static Object parseStringToList(BString csv, BMap option return DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, type); } } + public static Object parseBytesToList(BArray csv, BMap options, BTypedesc type) { try { byte[] bytes = csv.getBytes(); - return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), - type, CsvConfig.createParseOptions(options)); + return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), + type, CsvConfig.createParseOptions(options)); } catch (BError e) { return e; } catch (Exception e) { return DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, csv, type); } } + public static Object parseStreamToList(Environment env, BStream csv, BMap options, BTypedesc type) { try { @@ -114,8 +123,6 @@ public static Object parseStreamToList(Environment env, BStream csv, } } - // ---------------------------------------------------------------------------------------------------------------------------------------------------------------- - public static Object parseRecordAsRecordType(BArray csv, BMap options, BTypedesc type) { try { return CsvTraversal.traverse(csv, CsvConfig.createRecordAsRecordOption(options), type); @@ -123,6 +130,7 @@ public static Object parseRecordAsRecordType(BArray csv, BMap o return DiagnosticLog.getCsvError(e.getMessage()); } } + public static Object parseRecordAsListType(BArray csv, BArray headers, BMap options, BTypedesc type) { try { @@ -151,25 +159,4 @@ public static Object parseListAsListType(BArray csv, BMap optio return DiagnosticLog.getCsvError(e.getMessage()); } } - - // ---------------------------------------------------------------------------------------------------------------------------------------------------------------- - // ---------------------------------------------------------------------------------------------------------------------------------------------------------------- - - -// public static Object fromCsvWithType(BArray csv, BMap config, BTypedesc type) { -// try { -// return CsvTraversal.traverse(csv, CsvUtils.createFromCsvConfiguration(config), type.getDescribingType()); -// } catch (Exception e) { -// return DiagnosticLog.getCsvError(e.getMessage()); -// } -// } - -// -// public static Object toCsv(BArray csv, BMap config, BTypedesc type) { -// try { -// return CsvTraversal.traverse(csv, CsvUtils.createToCsvConfiguration(config), type.getDescribingType()); -// } catch (Exception e) { -// return DiagnosticLog.getCsvError(e.getMessage()); -// } -// } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java index 04ec333..38cd61c 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java @@ -24,8 +24,8 @@ import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BTypedesc; -import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.csv.CsvParser; +import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import java.io.InputStreamReader; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java index ee88c18..3e39494 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -5,31 +5,31 @@ public class Constants { public static class ConfigConstants { - public static BString DELIMITER = StringUtils.fromString("delimiter"); - public static BString TEXT_ENCLOSURE = StringUtils.fromString("textEnclosure"); - public static BString HEADER = StringUtils.fromString("header"); - public static BString ESCAPE_CHAR = StringUtils.fromString("escapeChar"); - public static BString LINE_TERMINATOR = StringUtils.fromString("lineTerminator"); - public static BString SKIP_LINES = StringUtils.fromString("skipLines"); - public static BString NIL_VALUE = StringUtils.fromString("nilValue"); - public static BString COMMENT_CHAR = StringUtils.fromString("comment"); - public static BString LOCALE = StringUtils.fromString("locale"); - public static BString ENCODING = StringUtils.fromString("encoding"); - public static BString NIL_AS_OPTIONAL = StringUtils.fromString("nilAsOptionalField"); - public static BString ABSENT_AS_NILABLE = StringUtils.fromString("absentAsNilableType"); - public static BString ALLOW_DATA_PROJECTION = StringUtils.fromString("allowDataProjection"); - public static BString CUSTOM_HEADERS = StringUtils.fromString("customHeaders"); - public static BString STRING_CONVERSION = StringUtils.fromString("stringConversion"); + public static final BString DELIMITER = StringUtils.fromString("delimiter"); + public static final BString TEXT_ENCLOSURE = StringUtils.fromString("textEnclosure"); + public static final BString HEADER = StringUtils.fromString("header"); + public static final BString ESCAPE_CHAR = StringUtils.fromString("escapeChar"); + public static final BString LINE_TERMINATOR = StringUtils.fromString("lineTerminator"); + public static final BString SKIP_LINES = StringUtils.fromString("skipLines"); + public static final BString NIL_VALUE = StringUtils.fromString("nilValue"); + public static final BString COMMENT_CHAR = StringUtils.fromString("comment"); + public static final BString LOCALE = StringUtils.fromString("locale"); + public static final BString ENCODING = StringUtils.fromString("encoding"); + 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 class Values { - public static String NULL = "null"; - public static String BALLERINA_NULL = "()"; + public static final String NULL = "null"; + public static final String BALLERINA_NULL = "()"; } - public static String SKIP_LINE_RANGE_SEP = "-"; + public static final String SKIP_LINE_RANGE_SEP = "-"; public static final String FIELD = "$field$."; public static final String NAME = "Name"; public static final BString VALUE = StringUtils.fromString("value"); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java index 671e4fb..3a9c730 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java @@ -1,12 +1,26 @@ package io.ballerina.stdlib.data.csvdata.utils; -import io.ballerina.runtime.api.creators.ValueCreator; 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; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.*; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ABSENT_AS_NILABLE; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ALLOW_DATA_PROJECTION; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.COMMENT_CHAR; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.CUSTOM_HEADERS; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.DELIMITER; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ENCODING; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ESCAPE_CHAR; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.HEADER; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.LINE_TERMINATOR; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.LOCALE; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.NIL_AS_OPTIONAL; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.NIL_VALUE; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.SKIP_LINES; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.STRING_CONVERSION; +import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.TEXT_ENCLOSURE; public class CsvConfig { public char delimiter = ','; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 14f0509..2769ff2 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -2,10 +2,18 @@ import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.flags.SymbolFlags; -import io.ballerina.runtime.api.types.*; +import io.ballerina.runtime.api.types.ArrayType; +import io.ballerina.runtime.api.types.Field; +import io.ballerina.runtime.api.types.IntersectionType; +import io.ballerina.runtime.api.types.RecordType; +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.ValueUtils; -import io.ballerina.runtime.api.values.*; +import io.ballerina.runtime.api.values.BArray; +import io.ballerina.runtime.api.values.BDecimal; +import io.ballerina.runtime.api.values.BMap; +import io.ballerina.runtime.api.values.BString; import java.util.HashMap; import java.util.HashSet; @@ -52,7 +60,7 @@ public static String[] createHeaders(String[] headers, CsvConfig config) { if (customHeaders == null) { for (int i = 0; i < headers.length; i++) { - headers[i] = String.valueOf( i + 1); + headers[i] = String.valueOf(i + 1); } } @@ -144,8 +152,9 @@ public static int getTheActualExpectedType(Type type) { } } - public static HashMap processNameAnnotationsAndBuildCustomFieldMap(RecordType recordType, - Map fieldHierarchy) { + public static HashMap + processNameAnnotationsAndBuildCustomFieldMap(RecordType recordType, + Map fieldHierarchy) { BMap annotations = recordType.getAnnotations(); HashMap updatedRecordFieldNames = new HashMap<>(); HashSet updatedFields = new HashSet<>(); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java index dda7775..20e7ac1 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java @@ -39,11 +39,11 @@ public enum DiagnosticErrorCode { INVALID_TYPE_FOR_FIELD("BDE_0012", "invalid.type.for.field"), INVALID_TYPE_FOR_ARRAY("BDE_0013", "invalid.type.for.array"), INVALID_CONVERSION_FOR_ARRAY_TO_MAP("BDE_0014", "invalid.conversion.for.array.to.map"), - INVALID_CONFIGURATIONS( "BDE_0015", "invalid.configurations"), + INVALID_CONFIGURATIONS("BDE_0015", "invalid.configurations"), EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES("BDE_0016", "expected.type.can.only.contains.basic.types"), - 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_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"), INVALID_CUSTOM_HEADER_LENGTH("BDE_0021", "invalid.custom.header.length"), INVALID_HEADER_NAMES_LENGTH("BDE_0022", "invalid.header.names.length"), diff --git a/settings.gradle b/settings.gradle index 3fa92d3..72b6bfd 100644 --- a/settings.gradle +++ b/settings.gradle @@ -16,6 +16,26 @@ * under the License. */ +pluginManagement { + plugins { + id "com.github.spotbugs" version "${spotbugsVersion}" + id "com.github.johnrengelman.shadow" version "${shadowJarPluginVersion}" + id "de.undercouch.download" version "${downloadPluginVersion}" + id "net.researchgate.release" version "${releasePluginVersion}" + id "io.ballerina.plugin" version "${ballerinaGradlePluginVersion}" + } + repositories { + gradlePluginPortal() + maven { + url = 'https://maven.pkg.github.com/ballerina-platform/*' + credentials { + username System.getenv("packageUser") + password System.getenv("packagePAT") + } + } + } +} + plugins { id "com.gradle.enterprise" version "3.2" } @@ -24,14 +44,14 @@ rootProject.name = 'data.csv' include(':checkstyle') include(':data.csv-native') include(':data.csv-ballerina') -//include(':data.csv-compiler-plugin') -//include(':data.csv-compiler-plugin-tests') +include(':data.csv-compiler-plugin') +include(':data.csv-compiler-plugin-tests') project(':checkstyle').projectDir = file("build-config${File.separator}checkstyle") project(':data.csv-native').projectDir = file('native') project(':data.csv-ballerina').projectDir = file('ballerina') -//project(':data.csv-compiler-plugin').projectDir = file('compiler-plugin') -//project(':data.csv-compiler-plugin-tests').projectDir = file('compiler-plugin-test') +project(':data.csv-compiler-plugin').projectDir = file('compiler-plugin') +project(':data.csv-compiler-plugin-tests').projectDir = file('compiler-plugin-test') gradleEnterprise { buildScan { From 5eb09189ef2fe0e2fb0085dd41999fa551012cc1 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 2 Jul 2024 14:37:36 +0530 Subject: [PATCH 042/147] [Automated] Update the native jar versions --- ballerina/CompilerPlugin.toml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 ballerina/CompilerPlugin.toml diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml new file mode 100644 index 0000000..a3b6b88 --- /dev/null +++ b/ballerina/CompilerPlugin.toml @@ -0,0 +1,6 @@ +[plugin] +id = "constraint-compiler-plugin" +class = "io.ballerina.lib.data.jsondata.compiler.JsondataCompilerPlugin" + +[[dependency]] +path = "../compiler-plugin/build/libs/data.jsondata-compiler-plugin-0.1.0.jar" From 1d21659e8aaaa95dfa8e0a49f20f73d45f12bbe1 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 2 Jul 2024 14:42:20 +0530 Subject: [PATCH 043/147] [Automated] Update the native jar versions --- ballerina/CompilerPlugin.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index a3b6b88..e503c45 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -1,6 +1,6 @@ [plugin] id = "constraint-compiler-plugin" -class = "io.ballerina.lib.data.jsondata.compiler.JsondataCompilerPlugin" +class = "io.ballerina.stdlib.data.csvdata.compiler.CsvDataCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/data.jsondata-compiler-plugin-0.1.0.jar" +path = "../compiler-plugin/build/libs/data.csv-compiler-plugin-0.1.0-SNAPSHOT.jar" From cfd8d2d2b77ea33566c117ff402cfda599739345 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 2 Jul 2024 17:43:42 +0530 Subject: [PATCH 044/147] Add compiler plugin tests --- ballerina/build.gradle | 10 +- .../csvdata/compiler/CompilerPluginTest.java | 170 +++++------------- .../sample_package_1/Ballerina.toml | 6 + .../sample_package_1/main.bal | 20 +++ .../sample_package_2/Ballerina.toml | 6 + .../sample_package_2/main.bal | 7 + .../compiler/CsvDataTypeValidator.java | 33 +--- 7 files changed, 92 insertions(+), 160 deletions(-) create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/main.bal create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/main.bal diff --git a/ballerina/build.gradle b/ballerina/build.gradle index a46cca0..31af8e8 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -40,8 +40,8 @@ def packageOrg = "ballerina" def tomlVersion = stripBallerinaExtensionVersion("${project.version}") def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/Ballerina.toml") def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml") -// def compilerPluginTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/CompilerPlugin.toml") -// def compilerPluginTomlFile = new File("$project.projectDir/CompilerPlugin.toml") + def compilerPluginTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/CompilerPlugin.toml") + def compilerPluginTomlFile = new File("$project.projectDir/CompilerPlugin.toml") def stripBallerinaExtensionVersion(String extVersion) { if (extVersion.matches(project.ext.timestampedVersionRegex)) { @@ -79,14 +79,14 @@ task updateTomlFiles { doLast { def stdlibDependentConstraintNativeVersion = stdlibConstraintVersion def stdlibDependentConstraintVersion = stripBallerinaExtensionVersion("${stdlibDependentConstraintNativeVersion}") - def newConfig = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version) newConfig = newConfig.replace("@toml.version@", tomlVersion) - newConfig = newConfig.replace("@stdlib.constraintnative.version@", stdlibDependentConstraintNativeVersion) newConfig = newConfig.replace("@constraint.version@", stdlibDependentConstraintVersion) - ballerinaTomlFile.text = newConfig + + def newCompilerPluginToml = compilerPluginTomlFilePlaceHolder.text.replace("@project.version@", project.version) + compilerPluginTomlFile.text = newCompilerPluginToml } } 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 bafb736..5d1bd17 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 @@ -18,139 +18,51 @@ package io.ballerina.lib.data.csvdata.compiler; -//import io.ballerina.projects.DiagnosticResult; -//import io.ballerina.tools.diagnostics.Diagnostic; -//import io.ballerina.tools.diagnostics.DiagnosticSeverity; -//import org.testng.Assert; -//import org.testng.annotations.Test; -// -//import java.util.List; -//import java.util.stream.Collectors; +import io.ballerina.projects.DiagnosticResult; +import io.ballerina.tools.diagnostics.Diagnostic; +import io.ballerina.tools.diagnostics.DiagnosticSeverity; +import org.testng.Assert; +import org.testng.annotations.Test; + +import java.util.List; +import java.util.stream.Collectors; /** * This class includes tests for Ballerina Csv Data compiler plugin. */ public class CompilerPluginTest { -// static final String UNSUPPORTED_TYPE = "unsupported type: type is not supported"; -// -// @Test -// public void testInvalidExpectedUnionType1() { -// DiagnosticResult diagnosticResult = -// CompilerPluginTestUtils.loadPackage("sample_package_1").getCompilation().diagnosticResult(); -// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() -// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) -// .collect(Collectors.toList()); -// Assert.assertEquals(errorDiagnosticsList.size(), 1); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); -// } -// -// @Test -// public void testInvalidExpectedUnionType2() { -// DiagnosticResult diagnosticResult = -// CompilerPluginTestUtils.loadPackage("sample_package_2").getCompilation().diagnosticResult(); -// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() -// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) -// .collect(Collectors.toList()); -// Assert.assertEquals(errorDiagnosticsList.size(), 1); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); -// } -// -// @Test -// public void testInvalidRecordFieldType1() { -// DiagnosticResult diagnosticResult = -// CompilerPluginTestUtils.loadPackage("sample_package_3").getCompilation().diagnosticResult(); -// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() -// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) -// .collect(Collectors.toList()); -// Assert.assertEquals(errorDiagnosticsList.size(), 2); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); -// } -// -// @Test -// public void testInvalidRecordFieldType2() { -// DiagnosticResult diagnosticResult = -// CompilerPluginTestUtils.loadPackage("sample_package_4").getCompilation().diagnosticResult(); -// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() -// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) -// .collect(Collectors.toList()); -// Assert.assertEquals(errorDiagnosticsList.size(), 2); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); -// } -// -// @Test -// public void testDuplicateField1() { -// DiagnosticResult diagnosticResult = -// CompilerPluginTestUtils.loadPackage("sample_package_5").getCompilation().diagnosticResult(); -// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() -// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) -// .collect(Collectors.toList()); -// Assert.assertEquals(errorDiagnosticsList.size(), 1); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), -// "invalid field: duplicate field found"); -// } -// -// @Test -// public void testDuplicateField2() { -// DiagnosticResult diagnosticResult = -// CompilerPluginTestUtils.loadPackage("sample_package_6").getCompilation().diagnosticResult(); -// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() -// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) -// .collect(Collectors.toList()); -// Assert.assertEquals(errorDiagnosticsList.size(), 2); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), -// "invalid field: duplicate field found"); -// Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo().messageFormat(), -// "invalid field: duplicate field found"); -// } -// -// @Test -// public void testComplexUnionTypeAsExpectedType() { -// DiagnosticResult diagnosticResult = -// CompilerPluginTestUtils.loadPackage("sample_package_7").getCompilation().diagnosticResult(); -// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() -// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) -// .collect(Collectors.toList()); -// Assert.assertEquals(errorDiagnosticsList.size(), 2); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); -// Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); -// } -// -// @Test -// public void testComplexUnionTypeAsMemberOfIntersection() { -// DiagnosticResult diagnosticResult = -// CompilerPluginTestUtils.loadPackage("sample_package_8").getCompilation().diagnosticResult(); -// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() -// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) -// .collect(Collectors.toList()); -// Assert.assertEquals(errorDiagnosticsList.size(), 1); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); -// } -// -// @Test -// public void testComplexUnionTypeCaseWhenUserDefinedModulePrefix1() { -// DiagnosticResult diagnosticResult = -// CompilerPluginTestUtils.loadPackage("sample_package_9").getCompilation().diagnosticResult(); -// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() -// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) -// .collect(Collectors.toList()); -// Assert.assertEquals(errorDiagnosticsList.size(), 1); -// Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), -// UNSUPPORTED_TYPE); -// } -// -// @Test -// public void testComplexUnionTypeCaseWhenUserDefinedModulePrefix2() { -// DiagnosticResult diagnosticResult = -// CompilerPluginTestUtils.loadPackage("sample_package_10").getCompilation().diagnosticResult(); -// List errorDiagnosticsList = diagnosticResult.diagnostics().stream() -// .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) -// .collect(Collectors.toList()); -// Assert.assertEquals(errorDiagnosticsList.size(), 3); -// 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); -// } + static final String UNSUPPORTED_TYPE = "unsupported type: type is not supported"; + static final String DUPLICATE_FIELD = "invalid field: duplicate field found"; + + @Test + public void testInvalidExpectedUnionType() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_1").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 10); + 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); + Assert.assertEquals(errorDiagnosticsList.get(3).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(4).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(5).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(6).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + 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); + } + + @Test + public void testInvalidRecordFields() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_2").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 1); + Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), DUPLICATE_FIELD); + } } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/Ballerina.toml new file mode 100644 index 0000000..437bf7b --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "admin" +name = "sample_package_1" +version = "0.1.0" +distribution = "2201.9.0" + 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 new file mode 100644 index 0000000..9483153 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/main.bal @@ -0,0 +1,20 @@ +import ballerina/data.csv; + +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([], {}); +} diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/Ballerina.toml new file mode 100644 index 0000000..3b39d28 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/Ballerina.toml @@ -0,0 +1,6 @@ +[package] +org = "admin" +name = "sample_package_2" +version = "0.1.0" +distribution = "2201.9.0" + diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/main.bal new file mode 100644 index 0000000..4670e29 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/main.bal @@ -0,0 +1,7 @@ +import ballerina/data.csv as c; + +type A record { + @c:Name {value: "b"} + int a; + string b; +}; diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java index 519f7e7..7b36726 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java @@ -101,7 +101,6 @@ public void perform(SyntaxNodeAnalysisContext ctx) { processTypeDefinitionNode((TypeDefinitionNode) member, ctx); } } - reset(); } @@ -205,19 +204,20 @@ private boolean isParseFunctionOfStringSource(ExpressionNode expressionNode) { private void validateExpectedType(TypeSymbol typeSymbol, SyntaxNodeAnalysisContext ctx) { typeSymbol.getLocation().ifPresent(location -> currentLocation = location); - if (!isSupportedExpectedType(typeSymbol)) { - reportDiagnosticInfo(ctx, typeSymbol.getLocation(), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); - return; - } switch (typeSymbol.typeKind()) { case UNION -> validateUnionType((UnionTypeSymbol) typeSymbol, typeSymbol.getLocation(), 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); } } + private void validateTupleType(TupleTypeSymbol typeSymbol, SyntaxNodeAnalysisContext ctx) { + reportDiagnosticInfo(ctx, typeSymbol.getLocation(), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); + } + private void validateArrayType(ArrayTypeSymbol typeSymbol, SyntaxNodeAnalysisContext ctx) { if (!isSupportedArrayMemberType(typeSymbol.memberTypeDescriptor())) { reportDiagnosticInfo(ctx, typeSymbol.getLocation(), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); @@ -229,10 +229,7 @@ private void validateUnionType(UnionTypeSymbol unionTypeSymbol, Optional memberTypeSymbols = unionTypeSymbol.memberTypeDescriptors(); for (TypeSymbol memberTypeSymbol : memberTypeSymbols) { - if (isSupportedUnionMemberType(getRawType(memberTypeSymbol))) { - continue; - } - isHasUnsupportedType = true; + validateExpectedType(memberTypeSymbol, ctx); } if (isHasUnsupportedType) { @@ -263,7 +260,7 @@ private boolean isSupportedArrayMemberType(TypeSymbol typeSymbol) { } switch (kind) { - case RECORD, ARRAY, TUPLE, MAP -> { + case RECORD, ARRAY, TUPLE, MAP, UNION, INTERSECTION -> { return true; } default -> { @@ -288,22 +285,6 @@ private boolean isSupportedExpectedType(TypeSymbol typeSymbol) { } } - private boolean isSupportedMemberType(TypeSymbol typeSymbol) { - TypeDescKind kind = typeSymbol.typeKind(); - if (kind == TypeDescKind.TYPE_REFERENCE) { - kind = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor().typeKind(); - } - - switch (kind) { - case TABLE, XML, REGEXP, RECORD, TUPLE, MAP, ARRAY -> { - return false; - } - default -> { - return true; - } - } - } - public static TypeSymbol getRawType(TypeSymbol typeDescriptor) { if (typeDescriptor.typeKind() == TypeDescKind.INTERSECTION) { return getRawType(((IntersectionTypeSymbol) typeDescriptor).effectiveTypeDescriptor()); From 61169f2d3b353bee271660187545232ef2f6e786 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 5 Jul 2024 10:41:24 +0530 Subject: [PATCH 045/147] Update error type --- .gitattributes | 2 +- ballerina/Package.md | 401 +--------------- ballerina/a.txt | 3 - ballerina/build.gradle | 4 +- ballerina/csv_api.bal | 83 +++- .../tests/constraint_validation_test.bal | 20 +- ballerina/tests/error_test.bal | 4 +- .../tests/parse_list_type_as_list_test.bal | 178 ++++---- .../tests/parse_list_type_as_record_test.bal | 332 +++++++------- .../tests/parse_record_type_as_list_test.bal | 332 +++++++------- .../parse_record_type_as_record_test.bal | 432 +++++++++--------- .../tests/parse_string_compatibality_test.bal | 58 +-- .../tests/parse_string_to_array_test.bal | 148 +++--- .../tests/parse_string_to_map_tests copy.bal | 134 +++--- .../tests/parse_string_to_record_tests.bal | 240 +++++----- .../tests/parse_string_to_tuple_test.bal | 246 +++++----- .../tests/parse_type_compatibility_test.bal | 110 ++--- .../tests/test_with_intersection_types.bal | 64 +-- ballerina/tests/test_with_singleton_test.bal | 80 ++-- ballerina/tests/test_with_union_types.bal | 350 +++++++------- .../tests/user_config_projection_tests.bal | 418 ++++++++--------- .../user_config_with_parser_options_test.bal | 252 +++++----- ballerina/types.bal | 2 +- codecov.yml | 8 + .../src/main/java/module-info.java | 2 +- .../data/csvdata/utils/DiagnosticLog.java | 4 +- 26 files changed, 1786 insertions(+), 2121 deletions(-) delete mode 100644 ballerina/a.txt create mode 100644 codecov.yml diff --git a/.gitattributes b/.gitattributes index d13affe..9f44b86 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,2 @@ # Ensure all Java files use LF. -*.java eol=lf +*.java eol=lf \ No newline at end of file diff --git a/ballerina/Package.md b/ballerina/Package.md index ea15954..26878a7 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -1,400 +1 @@ -# Package overview - -This package is designed to facilitate the handling and manipulation of CSV data within Ballerina applications. It streamlines the process of converting CSV data to native Ballerina data types, enabling developers to work with CSV content seamlessly and efficiently. - -This library is the refined successor of the `ballerina/csvdata` module, incorporating enhanced functionalities and improved performance. - -## Features - -- **Versatile CSV Data Input**: Accept CSV data as a csv, a string, byte array, or a stream and convert it into a Record value. -- **CSV to Record Value Conversion**: Transform CSV data into Ballerina records with ease in compliance with OpenAPI 3 standards. -- **Projection Support**: Perform selective conversion of CSV data subsets into Record values through projection. - -## Usage - -### Converting an CSV value to a Record value - -To convert an CSV value to a Record value, you can utilize the `fromCsvWithType` function provided by the library. The example below showcases the transformation of an CSV value into a Record value. - -```ballerina -import ballerina/data.csv as csvdata; -import ballerina/io; - -public function main() returns error? { - csv data = csv ` - 0 - string - string - `; - - Book book = check csvdata:fromCsvWithType(data, Book); - io:println(book); -} - -type Book record { - int id; - string title; - string author; -}; -``` - -### Converting an external CSV document to a Record value - -For transforming CSV content from an external source into a Record value, the `fromCsvStringWithType` function can be used. This external source can be in the form of a string or a byte array/byte 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 as csvdata; -import ballerina/io; - -public function main() returns error? { - string csvContent = check io:fileReadString("path/to/file.csv"); - Book book = check csvdata:fromCsvStringWithType(csvContent, Book); - io:println(book); -} - -type Book record { - int id; - string title; - string author; -}; -``` - -Make sure to handle possible errors that may arise during the file reading or CSV to record conversion process. The `check` keyword is utilized to handle these errors, but more sophisticated error handling can be implemented as per your requirements. - -## CSV to Record Canonical Representation - -The translation of CSV to a Record representation is a fundamental feature of the library. It facilitates a structured and type-safe approach to handling CSV data within Ballerina applications. - -Take for instance the following CSV snippet: - -```csv - - 0 - string - string - -``` - -CSV data is inherently hierarchical, forming a tree structure. In the given example, the root element is `book`, which encompasses three child elements: `id`, `title`, and `author`. The `id` element harbors a numeric value `0`, whereas both the `title` and `author` elements contain string values. - -A straightforward record representation of the above CSV data is: - -```ballerina -type Book record { - int id; - string title; - string author; -}; -``` - -In this representation, the CSV data is efficiently translated into a record value. The `book` element is mapped to a record of type `Book`, and the child elements `id`, `title`, and `author` are converted into record fields of types `int` and `string` correspondingly. - -This record type definition can be further refined through annotations. Moreover, utilizing open and closed records grants control over the translation process, which is elaborated in subsequent sections. - -### CSV Element Names - -The name of the CSV element serves as the name of the record field, altered to fit a valid Ballerina identifier. Notably, the record field name corresponds to the local name of the CSV element, with any namespace prefixes being disregarded. - -Consider the CSV snippet: - -```csv - - 0 - string - string - -``` - -The canonical representation of the above CSV as a Ballerina record is: - -```ballerina -type Book record { - int id; - string 'title\-name'; - string 'author\-name'; -}; -``` - -Observe how the CSV element names `title-name` and `author-name` are represented using delimited identifiers in Ballerina; the `-` characters in the CSV element names are escaped using the `\` character. - -Moreover, the `@Name` annotation can be utilized to explicitly specify the name of the record field, providing control over the translation process: - -```ballerina -import ballerina/data.csv as csvdata; - -type Book record { - int id; - @csvdata:Name { value: "title-name" } - string title; - @csvdata:Name { value: "author-name" } - string author; -}; -``` - -### CSV Attributes - -Similarly to CSV elements, CSV attributes are also represented into record fields within the corresponding parent Record type. The name of the CSV attribute is converted into the name of the record field, ensuring it is a valid Ballerina identifier. It is crucial to emphasize that the record field name aligns with the local name of the CSV attribute, and any namespace prefixes are ignored. - -Consider the following CSV snippet: - -```csv - - 0 - string - string - -``` - -The canonical representation of the above CSV as a Ballerina record is: - -```ballerina -type Book record { - string lang; - decimal price; - int id; - string title; - string author; -}; -``` - -Additionally the `@Attribute` annotation can be utilized to explicitly specify the name of the record field, providing control over the translation process. - -### Child Elements - -Child elements are mapped to record fields, with the type reflecting that of the corresponding child element. - -Examine the CSV snippet below: - -```csv - - 0 - string - - string - string - - -``` - -The canonical representation of the above CSV as a Ballerina record is: - -```ballerina -type Book record { - int id; - string title; - Author author; -}; - -type Author record { - string name; - string country; -}; -``` - -In this transformation, child elements, like the `author` element containing its own sub-elements, are converted into nested records. This maintains the hierarchical structure of the CSV data within the Ballerina type system, enabling intuitive and type-safe data manipulation. - -Alternatively, inline type definitions offer a compact method for representing child elements as records within their parent record. This approach is particularly beneficial when the child record does not require reuse elsewhere and is unique to its parent record. - -Consider the subsequent Ballerina record definition, which employs inline type definition for the `author` field: - -```ballerina -type Book record { - int id; - string title; - record { - string name; - string country; - } author; -}; -``` - -### CSV Text Content - -The transformation of CSV text content into record fields typically involves types like `string`, `boolean`, `int`, `float`, or `decimal`, depending on the textual content. For numeric values where type information is not explicitly defined, the default conversion type is `decimal`. Conversely, for non-numeric content, the default type is `string`. - -Consider the CSV snippet below: - -```csv - - 0 - string - string - true - 10.5 - -``` - -The translation into a Ballerina record would be as follows: - -```ballerina -type Book record { - int id; - string title; - string author; - boolean available; - decimal price; -}; -``` - -In scenarios where the parent CSV element of text content also includes attributes, the CSV text content can be represented by a `string` type field named `#content` within a record type, with the attributes being mapped to their respective fields. - -For instance, examine this CSV: - -```csv - - 0 - string - 10.5 - -``` - -The canonical translation of CSV to a Ballerina record is as such: - -```ballerina -type Book record { - int id; - Title title; - decimal price; -}; - -type Title record { - string \#content; - string lang; -}; -``` - -Modifications to the default behavior for converting numerical values can be achieved by providing `Options` mappings to the respective functions. This enables developers to choose specific data types and exert finer control over the conversion process. - -### CSV Namespaces - -CSV namespaces are accommodated by the library, supporting the translation of CSV data that contains namespace prefixes. However, the presence of CSV namespaces is not mandatory, and the library is capable of processing CSV data without namespaces. Should namespaces be present, they will be utilized to resolve the names of CSV elements and attributes. - -It's important to note that, unlike in the `csvdata` module, the namespace prefixes do not reflect in the record field names, as the record field names align with the local names of the CSV elements. - -Examine the CSV snippet below with default namespaces: - -```csv - - 0 - string - string - -``` - -The translation into a Ballerina record would be: - -```ballerina -type Book record { - int id; - string title; - string author; -}; -``` - -Incorporating namespace validation yields: - -```ballerina -import ballerina/data.csv as csvdata; - -@csvdata:Namespace { - uri: "http://example.com/book" -} -type Book record { - int id; - string title; - string author; -}; -``` - -Here is the same CSV snippet with a namespace prefix: - -```csv - - 0 - string - string - -``` - -The translation into a Ballerina record would be: - -```ballerina -import ballerina/data.csv as csvdata; - -@csvdata:Namespace { - uri: "http://example.com/book", - prefix: "bk" -} -type Book record { - int id; - string title; - string author; -}; -``` - -In these examples, the CSV namespaces are appropriately acknowledged, ensuring the integrity of the CSV structure within the Ballerina records. - -### Working with Arrays - -The library is equipped to handle the transformation of CSV data containing arrays into Ballerina records. - -Take the following CSV snippet as an example: - -```csv - - 0 - string - string - string - string - -``` - -The canonical representation of this CSV as a Ballerina record is: - -```ballerina -type Book record { - int id; - string title; - string[] author; -}; -``` - -### Controlling Which Elements to Convert - -The library allows for selective conversion of CSV elements into records through the use of rest fields. This is beneficial when the CSV data contains elements that are not necessary to be transformed into record fields. - -Take this CSV snippet as an example: - -```csv - - 0 - string - string - 10.5 - -``` - -Suppose that only the book `id`, and `title` elements are needed for conversion into record fields. This can be achieved by defining only the required fields in the record type and omitting the rest field: - -```ballerina -type Book record {| - int id; - string title; -|}; -``` - -However, if the rest field is utilized (or if the record type is defined as an open record), all elements in the CSV data will be transformed into record fields: - -```ballerina -type Book record { - int id; - string title; -}; -``` - -In this instance, all other elements in the CSV data, such as `author` and `price` along with their attributes, will be transformed into `string` type fields with the corresponding element name as the key. - -This behavior extends to arrays as well. - -The process of projecting CSV data into a record supports various use cases, including the filtering out of unnecessary elements. This functionality is anticipated to be enhanced in the future to accommodate more complex scenarios, such as filtering values based on regular expressions, among others. +# Ballerina CSV Data module diff --git a/ballerina/a.txt b/ballerina/a.txt deleted file mode 100644 index efb9823..0000000 --- a/ballerina/a.txt +++ /dev/null @@ -1,3 +0,0 @@ -a,b,c -1,2,3 -4,5,6 \ No newline at end of file diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 31af8e8..6555d1e 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -40,8 +40,8 @@ def packageOrg = "ballerina" def tomlVersion = stripBallerinaExtensionVersion("${project.version}") def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/Ballerina.toml") def ballerinaTomlFile = new File("$project.projectDir/Ballerina.toml") - def compilerPluginTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/CompilerPlugin.toml") - def compilerPluginTomlFile = new File("$project.projectDir/CompilerPlugin.toml") +def compilerPluginTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/CompilerPlugin.toml") +def compilerPluginTomlFile = new File("$project.projectDir/CompilerPlugin.toml") def stripBallerinaExtensionVersion(String extVersion) { if (extVersion.matches(project.ext.timestampedVersionRegex)) { diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 50039b5..68666f2 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -16,39 +16,98 @@ import ballerina/jballerina.java; +# Converts CSV string to subtype of record array. +# +# + 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 parseStringToRecord(string s, parseToRecordOption options = {}, typedesc t = <>) - returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; +# Converts byte[] to subtype of record array. +# +# + 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 parseBytesToRecord(byte[] s, parseToRecordOption options = {}, typedesc t = <>) - returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + +# Converts CSV byte-block-stream to subtype of record array. +# +# + 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 parseStreamToRecord(stream s, parseToRecordOption options = {}, typedesc t = <>) - returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; +# Converts CSV string to subtype of 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|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.stdlib.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|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.stdlib.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|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; +# Convert value of type record{}[] to subtype of record{}[]. +# +# + v - 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|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; +# Convert value of type record{}[] to subtype of anydata[][]. +# +# + v - 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 parseRecordAsListType(record{}[] s, string[] headerNames, Options options = {}, typedesc t = <>) - returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; +# Convert value of type string[][] to subtype of record{}[]. +# +# + v - 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 parseListAsRecordType(string[][] s, string[]? customHeaders = (), ListAsRecordOption options = {}, typedesc t = <>) - returns t|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; +# Convert value of type string[][] to subtype of anydata[][]. +# +# + v - 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|CsvConversionError = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; - -// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + returns t|Error = @java:Method {'class: "io.ballerina.stdlib.data.csvdata.csv.Native"} external; diff --git a/ballerina/tests/constraint_validation_test.bal b/ballerina/tests/constraint_validation_test.bal index 5b74fe6..0f02253 100644 --- a/ballerina/tests/constraint_validation_test.bal +++ b/ballerina/tests/constraint_validation_test.bal @@ -7,19 +7,19 @@ import ballerina/constraint; // @test:Config {enable: !enable} // function debugTest() returns error? { -// ConstrainedRec[]|CsvConversionError cRec3 = parseStringToRecord(string `a,b +// ConstrainedRec[]|Error cRec3 = parseStringToRecord(string `a,b // 4,abc // 5, "d"`); // test:assertEquals(cRec3, ""); // } //TODO: Fix the below test cases - // ConstrainedRec[]|CsvConversionError cRec3 = parseStringToRecord(string `a,b + // ConstrainedRec[]|Error cRec3 = parseStringToRecord(string `a,b // 4,abc // 5, "" `); // test:assertEquals(cRec3, ""); -// ConstrainedRec[]|CsvConversionError cRec3 = parseStringToRecord(string `a,b +// ConstrainedRec[]|Error cRec3 = parseStringToRecord(string `a,b // 4,abc // 5, "" `); // test:assertEquals(cRec3, ""); @@ -38,7 +38,7 @@ type ConstrainedRec record { @test:Config {enable} function testConstraintWithRecords() returns error? { - ConstrainedRec[]|CsvConversionError cRec1 = parseStringToRecord(string `a,b + ConstrainedRec[]|Error cRec1 = parseStringToRecord(string `a,b 4,abc 3, cde`); test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); @@ -46,14 +46,14 @@ function testConstraintWithRecords() returns error? { cRec1 = parseStringToRecord(string `a,b 4,abc 11, cde`); - test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue(cRec1 is Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("maxValue")); cRec1 = parseStringToRecord(string `a,b 4,abc 5, "b"`, {}); - test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue(cRec1 is Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("minLength")); @@ -62,12 +62,12 @@ function testConstraintWithRecords() returns error? { test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); cRec1 = parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 11, "b": "cde"}], {}); - test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue(cRec1 is Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("maxValue")); cRec1 = parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 5, "b": "b"}], {}); - test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue(cRec1 is Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("minLength")); @@ -75,12 +75,12 @@ function testConstraintWithRecords() returns error? { test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); cRec1 = parseListAsRecordType([["4", "abc"], ["11", "cde"]], ["a", "b"]); - test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue(cRec1 is Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("maxValue")); cRec1 = parseListAsRecordType([["4", "abc"], ["5", "b"]], ["a", "b"]); - test:assertTrue(cRec1 is CsvConversionError); + test:assertTrue(cRec1 is Error); test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("minLength")); } \ No newline at end of file diff --git a/ballerina/tests/error_test.bal b/ballerina/tests/error_test.bal index ba8650e..0ca9509 100644 --- a/ballerina/tests/error_test.bal +++ b/ballerina/tests/error_test.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() returns error? { -// record{}[]|CsvConversionError csv1op4_3 = parseStringToRecord(csvStringData2, ptOption4); +// record{}[]|Error csv1op4_3 = parseStringToRecord(csvStringData2, ptOption4); // test:assertEquals(csv1op4_3, [ // {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, // {a: 3, b: "string3", c: 0, d: 1.23, e: 1.23, f: "()"}, @@ -15,7 +15,7 @@ import ballerina/test; function errorTest() returns error? { // check - record{}[]|CsvConversionError csv3op3_4 = parseStringToRecord(csvStringData3, {header: 11}); + record{}[]|Error csv3op3_4 = parseStringToRecord(csvStringData3, {header: 11}); test:assertEquals(csv3op3_4, []); csv3op3_4 = parseStringToRecord(csvStringData3, {header: 3}); diff --git a/ballerina/tests/parse_list_type_as_list_test.bal b/ballerina/tests/parse_list_type_as_list_test.bal index c48da28..7b03d28 100644 --- a/ballerina/tests/parse_list_type_as_list_test.bal +++ b/ballerina/tests/parse_list_type_as_list_test.bal @@ -4,261 +4,261 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// DecimalArray1Array|CsvConversionError st1dda = parseListAsListType([st1, st1], {}, DecimalArray1Array); -// test:assertTrue(st1dda is CsvConversionError); -// test:assertEquals((st1dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); +// DecimalArray1Array|Error st1dda = parseListAsListType([st1, st1], {}, DecimalArray1Array); +// test:assertTrue(st1dda is Error); +// test:assertEquals((st1dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); // } @test:Config {enable} function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { - StringTuple1Array|CsvConversionError st1st1 = parseListAsListType([st1, st1], {}, StringTuple1Array); + StringTuple1Array|Error st1st1 = parseListAsListType([st1, st1], {}, StringTuple1Array); test:assertEquals(st1st1, [ [s1, s2, "", ""], [s1, s2, "", ""] ]); - StringTuple1Array|CsvConversionError st2st1 = parseListAsListType([st2, st2], {}, StringTuple1Array); + StringTuple1Array|Error st2st1 = parseListAsListType([st2, st2], {}, StringTuple1Array); test:assertEquals(st2st1, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringTuple1Array|CsvConversionError st3st1 = parseListAsListType([st3, st3], {}, StringTuple1Array); + StringTuple1Array|Error st3st1 = parseListAsListType([st3, st3], {}, StringTuple1Array); test:assertEquals(st3st1, [ [s1, s2, "", ""], [s1, s2, "", ""] ]); - StringTuple1Array|CsvConversionError st4st1 = parseListAsListType([st4, st4], {}, StringTuple1Array); + StringTuple1Array|Error st4st1 = parseListAsListType([st4, st4], {}, StringTuple1Array); test:assertEquals(st4st1, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringTuple2Array|CsvConversionError st1st2 = parseListAsListType([st1, st1], {}, StringTuple2Array); + StringTuple2Array|Error st1st2 = parseListAsListType([st1, st1], {}, StringTuple2Array); test:assertEquals(st1st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|CsvConversionError st2st2 = parseListAsListType([st2, st2], {}, StringTuple2Array); + StringTuple2Array|Error st2st2 = parseListAsListType([st2, st2], {}, StringTuple2Array); test:assertEquals(st2st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|CsvConversionError st3st2 = parseListAsListType([st3, st3], {}, StringTuple2Array); + StringTuple2Array|Error st3st2 = parseListAsListType([st3, st3], {}, StringTuple2Array); test:assertEquals(st3st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|CsvConversionError st4st2 = parseListAsListType([st4, st4], {}, StringTuple2Array); + StringTuple2Array|Error st4st2 = parseListAsListType([st4, st4], {}, StringTuple2Array); test:assertEquals(st4st2, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|CsvConversionError st1st3 = parseListAsListType([st1, st1], {}, StringTuple3Array); + StringTuple3Array|Error st1st3 = parseListAsListType([st1, st1], {}, StringTuple3Array); test:assertEquals(st1st3, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|CsvConversionError st2st3 = parseListAsListType([st2, st2], {}, StringTuple3Array); + StringTuple3Array|Error st2st3 = parseListAsListType([st2, st2], {}, StringTuple3Array); test:assertEquals(st2st3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringTuple3Array|CsvConversionError st3st3 = parseListAsListType([st3, st3], {}, StringTuple3Array); + StringTuple3Array|Error st3st3 = parseListAsListType([st3, st3], {}, StringTuple3Array); test:assertEquals(st3st3, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|CsvConversionError st4st3 = parseListAsListType([st4, st4], {}, StringTuple3Array); + StringTuple3Array|Error st4st3 = parseListAsListType([st4, st4], {}, StringTuple3Array); test:assertEquals(st4st3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringTuple4Array|CsvConversionError st1st4 = parseListAsListType([st1, st1], {}, StringTuple4Array); + StringTuple4Array|Error st1st4 = parseListAsListType([st1, st1], {}, StringTuple4Array); test:assertEquals(st1st4, [ [s1, s2], [s1, s2] ]); - StringTuple4Array|CsvConversionError st2st4 = parseListAsListType([st2, st2], {}, StringTuple4Array); + StringTuple4Array|Error st2st4 = parseListAsListType([st2, st2], {}, StringTuple4Array); test:assertEquals(st2st4, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringTuple4Array|CsvConversionError st3st4 = parseListAsListType([st3, st3], {}, StringTuple4Array); + StringTuple4Array|Error st3st4 = parseListAsListType([st3, st3], {}, StringTuple4Array); test:assertEquals(st3st4, [ [s1, s2], [s1, s2] ]); - StringTuple4Array|CsvConversionError st4st4 = parseListAsListType([st4, st4], {}, StringTuple4Array); + StringTuple4Array|Error st4st4 = parseListAsListType([st4, st4], {}, StringTuple4Array); test:assertEquals(st4st4, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - AnydataTuple3Array|CsvConversionError st1anydt3 = parseListAsListType([st1, st1], {}, AnydataTuple3Array); + AnydataTuple3Array|Error st1anydt3 = parseListAsListType([st1, st1], {}, AnydataTuple3Array); test:assertEquals(st1anydt3, [ [s1, s2], [s1, s2] ]); - AnydataTuple3Array|CsvConversionError st2anydt3 = parseListAsListType([st2, st2], {}, AnydataTuple3Array); + AnydataTuple3Array|Error st2anydt3 = parseListAsListType([st2, st2], {}, AnydataTuple3Array); test:assertEquals(st2anydt3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - AnydataTuple3Array|CsvConversionError st3anydt3 = parseListAsListType([st3, st3], {}, AnydataTuple3Array); + AnydataTuple3Array|Error st3anydt3 = parseListAsListType([st3, st3], {}, AnydataTuple3Array); test:assertEquals(st3anydt3, [ [s1, s2], [s1, s2] ]); - AnydataTuple3Array|CsvConversionError st4anydt3 = parseListAsListType([st4, st4], {}, AnydataTuple3Array); + AnydataTuple3Array|Error st4anydt3 = parseListAsListType([st4, st4], {}, AnydataTuple3Array); test:assertEquals(st4anydt3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - JsonTuple3Array|CsvConversionError st1jt3 = parseListAsListType([st1, st1], {}, JsonTuple3Array); + JsonTuple3Array|Error st1jt3 = parseListAsListType([st1, st1], {}, JsonTuple3Array); test:assertEquals(st1jt3, [ [s1, s2], [s1, s2] ]); - JsonTuple3Array|CsvConversionError st2jt3 = parseListAsListType([st2, st2], {}, JsonTuple3Array); + JsonTuple3Array|Error st2jt3 = parseListAsListType([st2, st2], {}, JsonTuple3Array); test:assertEquals(st2jt3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - JsonTuple3Array|CsvConversionError st3jt3 = parseListAsListType([st3, st3], {}, JsonTuple3Array); + JsonTuple3Array|Error st3jt3 = parseListAsListType([st3, st3], {}, JsonTuple3Array); test:assertEquals(st3jt3, [ [s1, s2], [s1, s2] ]); - JsonTuple3Array|CsvConversionError st4jt3 = parseListAsListType([st4, st4], {}, JsonTuple3Array); + JsonTuple3Array|Error st4jt3 = parseListAsListType([st4, st4], {}, JsonTuple3Array); test:assertEquals(st4jt3, [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - DecimalTuple4Array|CsvConversionError st1dta = parseListAsListType([st1, st1], {}, DecimalTuple4Array); - test:assertTrue(st1dta is CsvConversionError); - test:assertEquals((st1dta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); + DecimalTuple4Array|Error st1dta = parseListAsListType([st1, st1], {}, DecimalTuple4Array); + test:assertTrue(st1dta is Error); + test:assertEquals((st1dta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); - IntegerTuple3Array|CsvConversionError st2bta = parseListAsListType([st2, st2], {}, IntegerTuple3Array); - test:assertTrue(st2bta is CsvConversionError); - test:assertEquals((st2bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "int")); + IntegerTuple3Array|Error st2bta = parseListAsListType([st2, st2], {}, IntegerTuple3Array); + test:assertTrue(st2bta is Error); + test:assertEquals((st2bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "int")); - NilTuple3Array|CsvConversionError st3nta = parseListAsListType([st3, st3], {}, NilTuple3Array); - test:assertTrue(st3nta is CsvConversionError); - test:assertEquals((st3nta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "()")); + NilTuple3Array|Error st3nta = parseListAsListType([st3, st3], {}, NilTuple3Array); + test:assertTrue(st3nta is Error); + test:assertEquals((st3nta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "()")); - BooleanTuple4Array|CsvConversionError st4bta = parseListAsListType([st4, st4], {}, BooleanTuple4Array); - test:assertTrue(st4bta is CsvConversionError); - test:assertEquals((st4bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); + BooleanTuple4Array|Error st4bta = parseListAsListType([st4, st4], {}, BooleanTuple4Array); + test:assertTrue(st4bta is Error); + test:assertEquals((st4bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); } @test:Config{enable} function testFromCsvWithTypeForTupleAndTupleAsExpectedType2() { - [string, boolean, int][]|CsvConversionError ct1bt4 = parseListAsListType([["a", "true", "1"], ["a", "true", "1"]], {}); + [string, boolean, int][]|Error ct1bt4 = parseListAsListType([["a", "true", "1"], ["a", "true", "1"]], {}); test:assertEquals(ct1bt4, [ ["a", true, 1], ["a", true, 1] ]); - [(), float, decimal, boolean, int, string][]|CsvConversionError ct1bt6 = parseListAsListType( + [(), float, decimal, boolean, int, string][]|Error ct1bt6 = parseListAsListType( [["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][]|CsvConversionError ct1bt7 = parseListAsListType( + [decimal, boolean, int, string][]|Error ct1bt7 = parseListAsListType( [["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...][]|CsvConversionError ct1bt8 = parseListAsListType( + [decimal, boolean, int, string, anydata...][]|Error ct1bt8 = parseListAsListType( [["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...][]|CsvConversionError ct1bt9 = parseListAsListType( + [(), float, decimal, boolean, int, string, string...][]|Error ct1bt9 = parseListAsListType( [["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...][]|CsvConversionError ct1bt10 = parseListAsListType( + [decimal, boolean, int, string, string...][]|Error ct1bt10 = parseListAsListType( [["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, ()...][]|CsvConversionError ct1bt11 = parseListAsListType( + [decimal, boolean, int, string, ()...][]|Error ct1bt11 = parseListAsListType( [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); - test:assertTrue(ct1bt11 is CsvConversionError); + test:assertTrue(ct1bt11 is Error); //TODO: Fix the message test:assertEquals((ct1bt11).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "decimal")); - [(), decimal, float, boolean, ()...][]|CsvConversionError ct1bt11_2 = parseListAsListType( + [(), decimal, float, boolean, ()...][]|Error ct1bt11_2 = parseListAsListType( [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); - test:assertTrue(ct1bt11_2 is CsvConversionError); + test:assertTrue(ct1bt11_2 is Error); //TODO: Fix the message test:assertEquals((ct1bt11_2).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "()")); - [()...][]|CsvConversionError ct1bt12 = parseListAsListType( + [()...][]|Error ct1bt12 = parseListAsListType( [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); - test:assertTrue(ct1bt12 is CsvConversionError); + test:assertTrue(ct1bt12 is Error); test:assertEquals((ct1bt12).message(), generateErrorMessageForInvalidValueForArrayType("2.23", "1", "()")); - [string...][]|CsvConversionError ct1bt13 = parseListAsListType( + [string...][]|Error ct1bt13 = parseListAsListType( [["1", "a"], ["1", "a"]]); test:assertEquals(ct1bt13, [ ["1", "a"], ["1", "a"] ]); - [boolean...][]|CsvConversionError ct1bt14 = parseListAsListType( + [boolean...][]|Error ct1bt14 = parseListAsListType( [["2.23", "null"], ["7", "()"]]); - test:assertTrue(ct1bt14 is CsvConversionError); + test:assertTrue(ct1bt14 is Error); test:assertEquals((ct1bt14).message(), generateErrorMessageForInvalidValueForArrayType("2.23", "0", "boolean")); - int?[][]|CsvConversionError ct1bt15 = parseListAsListType( + int?[][]|Error ct1bt15 = parseListAsListType( [["1", "()"], ["1", "2"]]); test:assertEquals(ct1bt15, [ [1, ()], [1, 2] ]); - int[][]|CsvConversionError ct1bt16 = parseListAsListType( + int[][]|Error ct1bt16 = parseListAsListType( [["1", "2"], ["1", "()"]]); - test:assertTrue(ct1bt16 is CsvConversionError); + test:assertTrue(ct1bt16 is Error); test:assertEquals((ct1bt16).message(), generateErrorMessageForInvalidValueForArrayType("()", "1", "int")); - int[][]|CsvConversionError ct1bt17 = parseListAsListType( + int[][]|Error ct1bt17 = parseListAsListType( [["a", "b"], ["a", "b"]]); - test:assertTrue(ct1bt17 is CsvConversionError); + test:assertTrue(ct1bt17 is Error); test:assertEquals((ct1bt17).message(), generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); // TODO: Add tests with union types, string|boolean => true @@ -267,155 +267,155 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType2() { @test:Config {enable: enable} function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { - StringArrayArray|CsvConversionError st1saa = parseListAsListType([st1, st1], {}, StringArrayArray); + StringArrayArray|Error st1saa = parseListAsListType([st1, st1], {}, StringArrayArray); test:assertEquals(st1saa , [ [s1, s2], [s1, s2] ]); - StringArrayArray|CsvConversionError st2saa = parseListAsListType([st2, st2], {}, StringArrayArray); + StringArrayArray|Error st2saa = parseListAsListType([st2, st2], {}, StringArrayArray); test:assertEquals(st2saa , [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringArrayArray|CsvConversionError st3saa = parseListAsListType([st3, st3], {}, StringArrayArray); + StringArrayArray|Error st3saa = parseListAsListType([st3, st3], {}, StringArrayArray); test:assertEquals(st3saa , [ [s1, s2], [s1, s2] ]); - StringArrayArray|CsvConversionError st4saa = parseListAsListType([st4, st4], {}, StringArrayArray); + StringArrayArray|Error st4saa = parseListAsListType([st4, st4], {}, StringArrayArray); test:assertEquals(st4saa , [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - NillableStringArrayArray|CsvConversionError st1nsaa = parseListAsListType([st1, st1], {}, NillableStringArrayArray); + NillableStringArrayArray|Error st1nsaa = parseListAsListType([st1, st1], {}, NillableStringArrayArray); test:assertEquals(st1nsaa , [ [s1, s2], [s1, s2] ]); - NillableStringArrayArray|CsvConversionError st2nsaa = parseListAsListType([st2, st2], {}, NillableStringArrayArray); + NillableStringArrayArray|Error st2nsaa = parseListAsListType([st2, st2], {}, NillableStringArrayArray); test:assertEquals(st2nsaa , [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - NillableStringArrayArray|CsvConversionError st3nsaa = parseListAsListType([st3, st3], {}, NillableStringArrayArray); + NillableStringArrayArray|Error st3nsaa = parseListAsListType([st3, st3], {}, NillableStringArrayArray); test:assertEquals(st3nsaa , [ [s1, s2], [s1, s2] ]); - NillableStringArrayArray|CsvConversionError st4nsaa = parseListAsListType([st4, st4], {}, NillableStringArrayArray); + NillableStringArrayArray|Error st4nsaa = parseListAsListType([st4, st4], {}, NillableStringArrayArray); test:assertEquals(st4nsaa , [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - NillableIntOrUnionStringArrayArray|CsvConversionError st1nsuiaa = parseListAsListType([st1, st1], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|Error st1nsuiaa = parseListAsListType([st1, st1], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st1nsuiaa , [ [s1, s2], [s1, s2] ]); - NillableIntOrUnionStringArrayArray|CsvConversionError st2nsuiaa = parseListAsListType([st2, st2], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|Error st2nsuiaa = parseListAsListType([st2, st2], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st2nsuiaa , [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - NillableIntOrUnionStringArrayArray|CsvConversionError st3nsuiaa = parseListAsListType([st3, st3], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|Error st3nsuiaa = parseListAsListType([st3, st3], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st3nsuiaa , [ [s1, s2], [s1, s2] ]); - NillableIntOrUnionStringArrayArray|CsvConversionError st4nsuiaa = parseListAsListType([st4, st4], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|Error st4nsuiaa = parseListAsListType([st4, st4], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st4nsuiaa , [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - StringArray2Array|CsvConversionError st1saa2 = parseListAsListType([st1, st1], {}, StringArray2Array); + StringArray2Array|Error st1saa2 = parseListAsListType([st1, st1], {}, StringArray2Array); test:assertEquals(st1saa2 , [ [s1, s2], [s1, s2] ]); - StringArray2Array|CsvConversionError st2saa2 = parseListAsListType([st2, st2], {}, StringArray2Array); + StringArray2Array|Error st2saa2 = parseListAsListType([st2, st2], {}, StringArray2Array); test:assertEquals(st2saa2 , [ [s1, s2], [s1, s2] ]); - StringArray2Array|CsvConversionError st3saa2 = parseListAsListType([st3, st3], {}, StringArray2Array); + StringArray2Array|Error st3saa2 = parseListAsListType([st3, st3], {}, StringArray2Array); test:assertEquals(st3saa2 , [ [s1, s2], [s1, s2] ]); - StringArray2Array|CsvConversionError st4saa2 = parseListAsListType([st4, st4], {}, StringArray2Array); + StringArray2Array|Error st4saa2 = parseListAsListType([st4, st4], {}, StringArray2Array); test:assertEquals(st4saa2 , [ [s1, s2], [s1, s2] ]); - JsonArray1Array|CsvConversionError st1jaa = parseListAsListType([st1, st1], {}, JsonArray1Array); + JsonArray1Array|Error st1jaa = parseListAsListType([st1, st1], {}, JsonArray1Array); test:assertEquals(st1jaa , [ [s1, s2], [s1, s2] ]); - JsonArray1Array|CsvConversionError st2jaa = parseListAsListType([st2, st2], {}, JsonArray1Array); + JsonArray1Array|Error st2jaa = parseListAsListType([st2, st2], {}, JsonArray1Array); test:assertEquals(st2jaa , [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - JsonArray1Array|CsvConversionError st3jaa = parseListAsListType([st3, st3], {}, JsonArray1Array); + JsonArray1Array|Error st3jaa = parseListAsListType([st3, st3], {}, JsonArray1Array); test:assertEquals(st3jaa , [ [s1, s2], [s1, s2] ]); - JsonArray1Array|CsvConversionError st4jaa = parseListAsListType([st4, st4], {}, JsonArray1Array); + JsonArray1Array|Error st4jaa = parseListAsListType([st4, st4], {}, JsonArray1Array); test:assertEquals(st4jaa , [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - AnydataArray1Array|CsvConversionError st1anyda = parseListAsListType([st1, st1], {}, AnydataArray1Array); + AnydataArray1Array|Error st1anyda = parseListAsListType([st1, st1], {}, AnydataArray1Array); test:assertEquals(st1anyda , [ [s1, s2], [s1, s2] ]); - AnydataArray1Array|CsvConversionError st2anyda = parseListAsListType([st2, st2], {}, AnydataArray1Array); + AnydataArray1Array|Error st2anyda = parseListAsListType([st2, st2], {}, AnydataArray1Array); test:assertEquals(st2anyda , [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - AnydataArray1Array|CsvConversionError st3anyda = parseListAsListType([st3, st3], {}, AnydataArray1Array); + AnydataArray1Array|Error st3anyda = parseListAsListType([st3, st3], {}, AnydataArray1Array); test:assertEquals(st3anyda , [ [s1, s2], [s1, s2] ]); - AnydataArray1Array|CsvConversionError st4anyda = parseListAsListType([st4, st4], {}, AnydataArray1Array); + AnydataArray1Array|Error st4anyda = parseListAsListType([st4, st4], {}, AnydataArray1Array); test:assertEquals(st4anyda , [ [s1, s2, s3, s2], [s1, s2, s3, s2] ]); - DecimalArray1Array|CsvConversionError st1dda = parseListAsListType([st1, st1], {}, DecimalArray1Array); - test:assertTrue(st1dda is CsvConversionError); - test:assertEquals((st1dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); + DecimalArray1Array|Error st1dda = parseListAsListType([st1, st1], {}, DecimalArray1Array); + test:assertTrue(st1dda is Error); + test:assertEquals((st1dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); - DecimalArray1Array|CsvConversionError st3dda = parseListAsListType([st3, st3], {}, DecimalArray1Array); - test:assertTrue(st3dda is CsvConversionError); - test:assertEquals((st3dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); + DecimalArray1Array|Error st3dda = parseListAsListType([st3, st3], {}, DecimalArray1Array); + test:assertTrue(st3dda is Error); + test:assertEquals((st3dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); } diff --git a/ballerina/tests/parse_list_type_as_record_test.bal b/ballerina/tests/parse_list_type_as_record_test.bal index 861e0ac..0fb63de 100644 --- a/ballerina/tests/parse_list_type_as_record_test.bal +++ b/ballerina/tests/parse_list_type_as_record_test.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// record{|()...;|}[]|CsvConversionError ct1br12 = parseListAsRecordType( +// record{|()...;|}[]|Error ct1br12 = parseListAsRecordType( // [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], // ["f", "e", "d", "c", "b", "a"]); // test:assertEquals(ct1br12, [ @@ -15,253 +15,253 @@ import ballerina/test; @test:Config {enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { - StringRecord1Array|CsvConversionError st1sr1 = parseListAsRecordType([st1, st1], (), {}, StringRecord1Array); - test:assertTrue(st1sr1 is CsvConversionError); - test:assertEquals((st1sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + StringRecord1Array|Error st1sr1 = parseListAsRecordType([st1, st1], (), {}, StringRecord1Array); + test:assertTrue(st1sr1 is Error); + test:assertEquals((st1sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - StringRecord1Array|CsvConversionError st2sr1 = parseListAsRecordType([st2, st2], (), {}, StringRecord1Array); - test:assertTrue(st2sr1 is CsvConversionError); - test:assertEquals((st2sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + StringRecord1Array|Error st2sr1 = parseListAsRecordType([st2, st2], (), {}, StringRecord1Array); + test:assertTrue(st2sr1 is Error); + test:assertEquals((st2sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - StringRecord2Array|CsvConversionError st1sr2 = parseListAsRecordType([st1, st1], (), {}, StringRecord2Array); - test:assertTrue(st1sr2 is CsvConversionError); - test:assertEquals((st1sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); + StringRecord2Array|Error st1sr2 = parseListAsRecordType([st1, st1], (), {}, StringRecord2Array); + test:assertTrue(st1sr2 is Error); + test:assertEquals((st1sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); - StringRecord2Array|CsvConversionError st2sr2 = parseListAsRecordType([st2, st2], (), {}, StringRecord2Array); - test:assertTrue(st2sr2 is CsvConversionError); - test:assertEquals((st2sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); + StringRecord2Array|Error st2sr2 = parseListAsRecordType([st2, st2], (), {}, StringRecord2Array); + test:assertTrue(st2sr2 is Error); + test:assertEquals((st2sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); - StringRecord9Array|CsvConversionError st1sr9 = parseListAsRecordType([st1, st1], (), {}, StringRecord9Array); - test:assertTrue(st1sr9 is CsvConversionError); - test:assertEquals((st1sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord9")); + StringRecord9Array|Error st1sr9 = parseListAsRecordType([st1, st1], (), {}, StringRecord9Array); + test:assertTrue(st1sr9 is Error); + test:assertEquals((st1sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord9")); - StringRecord9Array|CsvConversionError st2sr9 = parseListAsRecordType([st2, st2], (), {}, StringRecord9Array); - test:assertTrue(st2sr9 is CsvConversionError); - test:assertEquals((st2sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord9")); + StringRecord9Array|Error st2sr9 = parseListAsRecordType([st2, st2], (), {}, StringRecord9Array); + test:assertTrue(st2sr9 is Error); + test:assertEquals((st2sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord9")); - StringRecord10Array|CsvConversionError st1sr10 = parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); + StringRecord10Array|Error st1sr10 = parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); test:assertEquals(st1sr10, [ {'1: "string", '2: ""}, {'1: "string", '2: ""} ]); - StringRecord10Array|CsvConversionError st2sr10 = parseListAsRecordType([st2, st2], (), {}, StringRecord10Array); + StringRecord10Array|Error st2sr10 = parseListAsRecordType([st2, st2], (), {}, StringRecord10Array); test:assertEquals(st2sr10, [ {'1: "string", '2: "", '3: "a", '4: ""}, {'1: "string", '2: "", '3: "a", '4: ""} ]); - StringRecord19Array|CsvConversionError st1sr19 = parseListAsRecordType([st1, st1], (), {}, StringRecord19Array); + StringRecord19Array|Error st1sr19 = parseListAsRecordType([st1, st1], (), {}, StringRecord19Array); test:assertEquals(st1sr19, [ {s1: "", s2: "", "1": s1, "2": s2}, {s1: "", s2: "", "1": s1, "2": s2} ]); - StringRecord19Array|CsvConversionError st2sr19 = parseListAsRecordType([st2, st2], (), {}, StringRecord19Array); + StringRecord19Array|Error st2sr19 = parseListAsRecordType([st2, st2], (), {}, StringRecord19Array); test:assertEquals(st2sr19, [ {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord20Array|CsvConversionError st1sr20 = parseListAsRecordType([st1, st1], (), {}, StringRecord20Array); + StringRecord20Array|Error st1sr20 = parseListAsRecordType([st1, st1], (), {}, StringRecord20Array); test:assertEquals(st1sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} ]); - StringRecord20Array|CsvConversionError st2sr20 = parseListAsRecordType([st2, st2], (), {}, StringRecord20Array); + StringRecord20Array|Error st2sr20 = parseListAsRecordType([st2, st2], (), {}, StringRecord20Array); test:assertEquals(st2sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} ]); - StringRecord21Array|CsvConversionError st1sr21 = parseListAsRecordType([st1, st1], (), {}, StringRecord21Array); + StringRecord21Array|Error st1sr21 = parseListAsRecordType([st1, st1], (), {}, StringRecord21Array); test:assertEquals(st1sr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord21Array|CsvConversionError st2sr21 = parseListAsRecordType([st2, st2], (), {}, StringRecord21Array); + StringRecord21Array|Error st2sr21 = parseListAsRecordType([st2, st2], (), {}, StringRecord21Array); test:assertEquals(st2sr21, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord22Array|CsvConversionError st1sr22 = parseListAsRecordType([st1, st1], (), {}, StringRecord22Array); + StringRecord22Array|Error st1sr22 = parseListAsRecordType([st1, st1], (), {}, StringRecord22Array); test:assertEquals(st1sr22, [ {s1: "", s2: "", "1": s1, "2": s2}, {s1: "", s2: "", "1": s1, "2": s2} ]); - StringRecord22Array|CsvConversionError st2sr22 = parseListAsRecordType([st2, st2], (), {}, StringRecord22Array); + StringRecord22Array|Error st2sr22 = parseListAsRecordType([st2, st2], (), {}, StringRecord22Array); test:assertEquals(st2sr22, [ {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord23Array|CsvConversionError st1sr23 = parseListAsRecordType([st1, st1], (), {}, StringRecord23Array); + StringRecord23Array|Error st1sr23 = parseListAsRecordType([st1, st1], (), {}, StringRecord23Array); test:assertEquals(st1sr23, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord23Array|CsvConversionError st2sr23 = parseListAsRecordType([st2, st2], (), {}, StringRecord23Array); + StringRecord23Array|Error st2sr23 = parseListAsRecordType([st2, st2], (), {}, StringRecord23Array); test:assertEquals(st2sr23, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord15Array|CsvConversionError st1cr15 = parseListAsRecordType([st1, st1], (), {}, CustomRecord15Array); + CustomRecord15Array|Error st1cr15 = parseListAsRecordType([st1, st1], (), {}, CustomRecord15Array); test:assertEquals(st1cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord15Array|CsvConversionError st2cr15 = parseListAsRecordType([st2, st2], (), {}, CustomRecord15Array); + CustomRecord15Array|Error st2cr15 = parseListAsRecordType([st2, st2], (), {}, CustomRecord15Array); test:assertEquals(st2cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord16Array|CsvConversionError st1cr16 = parseListAsRecordType([st1, st1], (), {}, CustomRecord16Array); - test:assertTrue(st1cr16 is CsvConversionError); - test:assertEquals((st1cr16).message(), generateErrorMessageForMissingRequiredField("3")); + CustomRecord16Array|Error st1cr16 = parseListAsRecordType([st1, st1], (), {}, CustomRecord16Array); + test:assertTrue(st1cr16 is Error); + test:assertEquals((st1cr16).message(), generateErrorMessageForMissingRequiredField("3")); - CustomRecord16Array|CsvConversionError st2cr16 = parseListAsRecordType([st2, st2], (), {}, CustomRecord16Array); + CustomRecord16Array|Error st2cr16 = parseListAsRecordType([st2, st2], (), {}, CustomRecord16Array); test:assertEquals(st2cr16, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord17Array|CsvConversionError st1cr17 = parseListAsRecordType([st1, st1], (), {}, CustomRecord17Array); + CustomRecord17Array|Error st1cr17 = parseListAsRecordType([st1, st1], (), {}, CustomRecord17Array); test:assertEquals(st1cr17, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord17Array|CsvConversionError st2cr17 = parseListAsRecordType([st2, st2], (), {}, CustomRecord17Array); + CustomRecord17Array|Error st2cr17 = parseListAsRecordType([st2, st2], (), {}, CustomRecord17Array); test:assertEquals(st2cr17, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord18Array|CsvConversionError st1cr18 = parseListAsRecordType([st1, st1], (), {}, CustomRecord18Array); - test:assertTrue(st1cr18 is CsvConversionError); - test:assertEquals((st1cr18).message(), generateErrorMessageForMissingRequiredField("3")); + CustomRecord18Array|Error st1cr18 = parseListAsRecordType([st1, st1], (), {}, CustomRecord18Array); + test:assertTrue(st1cr18 is Error); + test:assertEquals((st1cr18).message(), generateErrorMessageForMissingRequiredField("3")); - CustomRecord18Array|CsvConversionError st2cr18 = parseListAsRecordType([st2, st2], (), {}, CustomRecord18Array); + CustomRecord18Array|Error st2cr18 = parseListAsRecordType([st2, st2], (), {}, CustomRecord18Array); test:assertEquals(st2cr18, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord19Array|CsvConversionError st1cr19 = parseListAsRecordType([st1, st1], (), {}, CustomRecord19Array); + CustomRecord19Array|Error st1cr19 = parseListAsRecordType([st1, st1], (), {}, CustomRecord19Array); test:assertEquals(st1cr19, [ {'1: s1, '2: s2, '3: "", '4: ""}, {'1: s1, '2: s2, '3: "", '4: ""} ]); - CustomRecord19Array|CsvConversionError st2cr19 = parseListAsRecordType([st2, st2], (), {}, CustomRecord19Array); + CustomRecord19Array|Error st2cr19 = parseListAsRecordType([st2, st2], (), {}, CustomRecord19Array); test:assertEquals(st2cr19, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord20Array|CsvConversionError st1cr20 = parseListAsRecordType([st1, st1], (), {}, CustomRecord20Array); + CustomRecord20Array|Error st1cr20 = parseListAsRecordType([st1, st1], (), {}, CustomRecord20Array); test:assertEquals(st1cr20, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord20Array|CsvConversionError st2cr20 = parseListAsRecordType([st2, st2], (), {}, CustomRecord20Array); + CustomRecord20Array|Error st2cr20 = parseListAsRecordType([st2, st2], (), {}, CustomRecord20Array); test:assertEquals(st2cr20, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord21Array|CsvConversionError st1cr21 = parseListAsRecordType([st1, st1], (), {}, CustomRecord21Array); + CustomRecord21Array|Error st1cr21 = parseListAsRecordType([st1, st1], (), {}, CustomRecord21Array); test:assertEquals(st1cr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord21Array|CsvConversionError st2cr21 = parseListAsRecordType([st2, st2], (), {}, CustomRecord21Array); + CustomRecord21Array|Error st2cr21 = parseListAsRecordType([st2, st2], (), {}, CustomRecord21Array); test:assertEquals(st2cr21, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord22Array|CsvConversionError st1cr22 = parseListAsRecordType([st1, st1], (), {}, CustomRecord22Array); + CustomRecord22Array|Error st1cr22 = parseListAsRecordType([st1, st1], (), {}, CustomRecord22Array); test:assertEquals(st1cr22, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord22Array|CsvConversionError st2cr22 = parseListAsRecordType([st2, st2], (), {}, CustomRecord22Array); + CustomRecord22Array|Error st2cr22 = parseListAsRecordType([st2, st2], (), {}, CustomRecord22Array); test:assertEquals(st2cr22, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord23Array|CsvConversionError st1cr23 = parseListAsRecordType([st1, st1], (), {}, CustomRecord23Array); + CustomRecord23Array|Error st1cr23 = parseListAsRecordType([st1, st1], (), {}, CustomRecord23Array); test:assertEquals(st1cr23, [ {"1": s1, "2": s2, a: ""}, {"1": s1, "2": s2, a: ""} ]); - CustomRecord23Array|CsvConversionError st2cr23 = parseListAsRecordType([st2, st2], (), {}, CustomRecord23Array); + CustomRecord23Array|Error st2cr23 = parseListAsRecordType([st2, st2], (), {}, CustomRecord23Array); test:assertEquals(st2cr23, [ {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} ]); - CustomRecord24Array|CsvConversionError st1cr24 = parseListAsRecordType([st1, st1], (), {}, CustomRecord24Array); + CustomRecord24Array|Error st1cr24 = parseListAsRecordType([st1, st1], (), {}, CustomRecord24Array); test:assertEquals(st1cr24, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord24Array|CsvConversionError st2cr24 = parseListAsRecordType([st2, st2], (), {}, CustomRecord24Array); + CustomRecord24Array|Error st2cr24 = parseListAsRecordType([st2, st2], (), {}, CustomRecord24Array); test:assertEquals(st2cr24, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord25Array|CsvConversionError st1cr25 = parseListAsRecordType([st1, st1], (), {}, CustomRecord25Array); - test:assertTrue(st1cr25 is CsvConversionError); - test:assertEquals((st1cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); + CustomRecord25Array|Error st1cr25 = parseListAsRecordType([st1, st1], (), {}, CustomRecord25Array); + test:assertTrue(st1cr25 is Error); + test:assertEquals((st1cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); - CustomRecord25Array|CsvConversionError st2cr25 = parseListAsRecordType([st2, st2], (), {}, CustomRecord25Array); - test:assertTrue(st2cr25 is CsvConversionError); - test:assertEquals((st2cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); + CustomRecord25Array|Error st2cr25 = parseListAsRecordType([st2, st2], (), {}, CustomRecord25Array); + test:assertTrue(st2cr25 is Error); + test:assertEquals((st2cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); - CustomRecord25Array|CsvConversionError st3cr25 = parseListAsRecordType([st3, st3], (), {}, CustomRecord25Array); - test:assertTrue(st3cr25 is CsvConversionError); - test:assertEquals((st3cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); + CustomRecord25Array|Error st3cr25 = parseListAsRecordType([st3, st3], (), {}, CustomRecord25Array); + test:assertTrue(st3cr25 is Error); + test:assertEquals((st3cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); - CustomRecord25Array|CsvConversionError st4cr25 = parseListAsRecordType([st4, st4], (), {}, CustomRecord25Array); - test:assertTrue(st4cr25 is CsvConversionError); - test:assertEquals((st4cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); + CustomRecord25Array|Error st4cr25 = parseListAsRecordType([st4, st4], (), {}, CustomRecord25Array); + test:assertTrue(st4cr25 is Error); + test:assertEquals((st4cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); - CustomRecord26Array|CsvConversionError st1cr26 = parseListAsRecordType([st1, st1], (), {}, CustomRecord26Array); + CustomRecord26Array|Error st1cr26 = parseListAsRecordType([st1, st1], (), {}, CustomRecord26Array); test:assertEquals(st1cr26 , [ {'1: s1}, {'1: s1} ]); - CustomRecord26Array|CsvConversionError st2cr26 = parseListAsRecordType([st2, st2], (), {}, CustomRecord26Array); + CustomRecord26Array|Error st2cr26 = parseListAsRecordType([st2, st2], (), {}, CustomRecord26Array); test:assertEquals(st2cr26 , [ {'1: s1}, {'1: s1} ]); - CustomRecord26Array|CsvConversionError st3cr26 = parseListAsRecordType([st3, st3], (), {}, CustomRecord26Array); + CustomRecord26Array|Error st3cr26 = parseListAsRecordType([st3, st3], (), {}, CustomRecord26Array); test:assertEquals(st3cr26 , [ {'1: s1}, {'1: s1} ]); - CustomRecord26Array|CsvConversionError st4cr26 = parseListAsRecordType([st4, st4], (), {}, CustomRecord26Array); + CustomRecord26Array|Error st4cr26 = parseListAsRecordType([st4, st4], (), {}, CustomRecord26Array); test:assertEquals(st4cr26 , [ {'1: s1}, {'1: s1} @@ -270,213 +270,213 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { @test:Config {enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { - StringRecord1Array|CsvConversionError st3sr1 = parseListAsRecordType([st3, st3], (), {}, StringRecord1Array); - test:assertTrue(st3sr1 is CsvConversionError); - test:assertEquals((st3sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + StringRecord1Array|Error st3sr1 = parseListAsRecordType([st3, st3], (), {}, StringRecord1Array); + test:assertTrue(st3sr1 is Error); + test:assertEquals((st3sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - StringRecord1Array|CsvConversionError st4sr1 = parseListAsRecordType([st4, st4], (), {}, StringRecord1Array); - test:assertTrue(st4sr1 is CsvConversionError); - test:assertEquals((st4sr1).message(), generateErrorMessageForMissingRequiredField("s3")); + StringRecord1Array|Error st4sr1 = parseListAsRecordType([st4, st4], (), {}, StringRecord1Array); + test:assertTrue(st4sr1 is Error); + test:assertEquals((st4sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - StringRecord2Array|CsvConversionError st3sr2 = parseListAsRecordType([st3, st3], (), {}, StringRecord2Array); - test:assertTrue(st3sr2 is CsvConversionError); - test:assertEquals((st3sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); + StringRecord2Array|Error st3sr2 = parseListAsRecordType([st3, st3], (), {}, StringRecord2Array); + test:assertTrue(st3sr2 is Error); + test:assertEquals((st3sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); - StringRecord2Array|CsvConversionError st4sr2 = parseListAsRecordType([st4, st4], (), {}, StringRecord2Array); - test:assertTrue(st4sr2 is CsvConversionError); - test:assertEquals((st4sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); + StringRecord2Array|Error st4sr2 = parseListAsRecordType([st4, st4], (), {}, StringRecord2Array); + test:assertTrue(st4sr2 is Error); + test:assertEquals((st4sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); - StringRecord9Array|CsvConversionError st3sr9 = parseListAsRecordType([st3, st3], (), {}, StringRecord9Array); - test:assertTrue(st3sr9 is CsvConversionError); - test:assertEquals((st3sr9).message(), generateErrorMessageForMissingRequiredField("s1")); + StringRecord9Array|Error st3sr9 = parseListAsRecordType([st3, st3], (), {}, StringRecord9Array); + test:assertTrue(st3sr9 is Error); + test:assertEquals((st3sr9).message(), generateErrorMessageForMissingRequiredField("s1")); - StringRecord9Array|CsvConversionError st4sr9 = parseListAsRecordType([st4, st4], (), {}, StringRecord9Array); - test:assertTrue(st4sr9 is CsvConversionError); - test:assertEquals((st4sr9).message(), generateErrorMessageForMissingRequiredField("s1")); + StringRecord9Array|Error st4sr9 = parseListAsRecordType([st4, st4], (), {}, StringRecord9Array); + test:assertTrue(st4sr9 is Error); + test:assertEquals((st4sr9).message(), generateErrorMessageForMissingRequiredField("s1")); - StringRecord10Array|CsvConversionError st3sr10 = parseListAsRecordType([st3, st3], (), {}, StringRecord10Array); + StringRecord10Array|Error st3sr10 = parseListAsRecordType([st3, st3], (), {}, StringRecord10Array); test:assertEquals(st3sr10, [ {'1: "string", '2: ""}, {'1: "string", '2: ""} ]); - StringRecord10Array|CsvConversionError st4sr10 = parseListAsRecordType([st4, st4], (), {}, StringRecord10Array); + StringRecord10Array|Error st4sr10 = parseListAsRecordType([st4, st4], (), {}, StringRecord10Array); test:assertEquals(st4sr10, [ {'1: "string", '2: "", '3: "a", '4: ""}, {'1: "string", '2: "", '3: "a", '4: ""} ]); - StringRecord19Array|CsvConversionError st3sr19 = parseListAsRecordType([st3, st3], (), {}, StringRecord19Array); + StringRecord19Array|Error st3sr19 = parseListAsRecordType([st3, st3], (), {}, StringRecord19Array); test:assertEquals(st3sr19, [ {s1: "", s2: "", "1": s1, "2": s2}, {s1: "", s2: "", "1": s1, "2": s2} ]); - StringRecord19Array|CsvConversionError st4sr19 = parseListAsRecordType([st4, st4], (), {}, StringRecord19Array); + StringRecord19Array|Error st4sr19 = parseListAsRecordType([st4, st4], (), {}, StringRecord19Array); test:assertEquals(st4sr19, [ {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord20Array|CsvConversionError st3sr20 = parseListAsRecordType([st3, st3], (), {}, StringRecord20Array); + StringRecord20Array|Error st3sr20 = parseListAsRecordType([st3, st3], (), {}, StringRecord20Array); test:assertEquals(st3sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} ]); - StringRecord20Array|CsvConversionError st4sr20 = parseListAsRecordType([st4, st4], (), {}, StringRecord20Array); + StringRecord20Array|Error st4sr20 = parseListAsRecordType([st4, st4], (), {}, StringRecord20Array); test:assertEquals(st4sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} ]); - StringRecord21Array|CsvConversionError st3sr21 = parseListAsRecordType([st3, st3], (), {}, StringRecord21Array); + StringRecord21Array|Error st3sr21 = parseListAsRecordType([st3, st3], (), {}, StringRecord21Array); test:assertEquals(st3sr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord21Array|CsvConversionError st4sr21 = parseListAsRecordType([st4, st4], (), {}, StringRecord21Array); + StringRecord21Array|Error st4sr21 = parseListAsRecordType([st4, st4], (), {}, StringRecord21Array); test:assertEquals(st4sr21, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord22Array|CsvConversionError st3sr22 = parseListAsRecordType([st3, st3], (), {}, StringRecord22Array); + StringRecord22Array|Error st3sr22 = parseListAsRecordType([st3, st3], (), {}, StringRecord22Array); test:assertEquals(st3sr22, [ {s1: "", s2: "", "1": s1, "2": s2}, {s1: "", s2: "", "1": s1, "2": s2} ]); - StringRecord22Array|CsvConversionError st4sr22 = parseListAsRecordType([st4, st4], (), {}, StringRecord22Array); + StringRecord22Array|Error st4sr22 = parseListAsRecordType([st4, st4], (), {}, StringRecord22Array); test:assertEquals(st4sr22, [ {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} ]); - StringRecord23Array|CsvConversionError st3sr23 = parseListAsRecordType([st3, st3], (), {}, StringRecord23Array); + StringRecord23Array|Error st3sr23 = parseListAsRecordType([st3, st3], (), {}, StringRecord23Array); test:assertEquals(st3sr23, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord23Array|CsvConversionError st4sr23 = parseListAsRecordType([st4, st4], (), {}, StringRecord23Array); + StringRecord23Array|Error st4sr23 = parseListAsRecordType([st4, st4], (), {}, StringRecord23Array); test:assertEquals(st4sr23, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord15Array|CsvConversionError st3cr15 = parseListAsRecordType([st3, st3], (), {}, CustomRecord15Array); + CustomRecord15Array|Error st3cr15 = parseListAsRecordType([st3, st3], (), {}, CustomRecord15Array); test:assertEquals(st3cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord15Array|CsvConversionError st4cr15 = parseListAsRecordType([st4, st4], (), {}, CustomRecord15Array); + CustomRecord15Array|Error st4cr15 = parseListAsRecordType([st4, st4], (), {}, CustomRecord15Array); test:assertEquals(st4cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord16Array|CsvConversionError st3cr16 = parseListAsRecordType([st3, st3], (), {}, CustomRecord16Array); - test:assertTrue(st3cr16 is CsvConversionError); - test:assertEquals((st3cr16).message(), generateErrorMessageForMissingRequiredField("3")); + CustomRecord16Array|Error st3cr16 = parseListAsRecordType([st3, st3], (), {}, CustomRecord16Array); + test:assertTrue(st3cr16 is Error); + test:assertEquals((st3cr16).message(), generateErrorMessageForMissingRequiredField("3")); - CustomRecord16Array|CsvConversionError st4cr16 = parseListAsRecordType([st4, st4], (), {}, CustomRecord16Array); + CustomRecord16Array|Error st4cr16 = parseListAsRecordType([st4, st4], (), {}, CustomRecord16Array); test:assertEquals(st4cr16, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord17Array|CsvConversionError st3cr17 = parseListAsRecordType([st3, st3], (), {}, CustomRecord17Array); + CustomRecord17Array|Error st3cr17 = parseListAsRecordType([st3, st3], (), {}, CustomRecord17Array); test:assertEquals(st3cr17, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord17Array|CsvConversionError st4cr17 = parseListAsRecordType([st4, st4], (), {}, CustomRecord17Array); + CustomRecord17Array|Error st4cr17 = parseListAsRecordType([st4, st4], (), {}, CustomRecord17Array); test:assertEquals(st4cr17, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord18Array|CsvConversionError st3cr18 = parseListAsRecordType([st3, st3], (), {}, CustomRecord18Array); - test:assertTrue(st3cr18 is CsvConversionError); - test:assertEquals((st3cr18).message(), generateErrorMessageForMissingRequiredField("3")); + CustomRecord18Array|Error st3cr18 = parseListAsRecordType([st3, st3], (), {}, CustomRecord18Array); + test:assertTrue(st3cr18 is Error); + test:assertEquals((st3cr18).message(), generateErrorMessageForMissingRequiredField("3")); - CustomRecord18Array|CsvConversionError st4cr18 = parseListAsRecordType([st4, st4], (), {}, CustomRecord18Array); + CustomRecord18Array|Error st4cr18 = parseListAsRecordType([st4, st4], (), {}, CustomRecord18Array); test:assertEquals(st4cr18, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord19Array|CsvConversionError st3cr19 = parseListAsRecordType([st3, st3], (), {}, CustomRecord19Array); + CustomRecord19Array|Error st3cr19 = parseListAsRecordType([st3, st3], (), {}, CustomRecord19Array); test:assertEquals(st3cr19, [ {'1: s1, '2: s2, '3: "", '4: ""}, {'1: s1, '2: s2, '3: "", '4: ""} ]); - CustomRecord19Array|CsvConversionError st4cr19 = parseListAsRecordType([st4, st4], (), {}, CustomRecord19Array); + CustomRecord19Array|Error st4cr19 = parseListAsRecordType([st4, st4], (), {}, CustomRecord19Array); test:assertEquals(st4cr19, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord20Array|CsvConversionError st3cr20 = parseListAsRecordType([st3, st3], (), {}, CustomRecord20Array); + CustomRecord20Array|Error st3cr20 = parseListAsRecordType([st3, st3], (), {}, CustomRecord20Array); test:assertEquals(st3cr20, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord20Array|CsvConversionError st4cr20 = parseListAsRecordType([st4, st4], (), {}, CustomRecord20Array); + CustomRecord20Array|Error st4cr20 = parseListAsRecordType([st4, st4], (), {}, CustomRecord20Array); test:assertEquals(st4cr20, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord21Array|CsvConversionError st3cr21 = parseListAsRecordType([st3, st3], (), {}, CustomRecord21Array); + CustomRecord21Array|Error st3cr21 = parseListAsRecordType([st3, st3], (), {}, CustomRecord21Array); test:assertEquals(st3cr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord21Array|CsvConversionError st4cr21 = parseListAsRecordType([st4, st4], (), {}, CustomRecord21Array); + CustomRecord21Array|Error st4cr21 = parseListAsRecordType([st4, st4], (), {}, CustomRecord21Array); test:assertEquals(st4cr21, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord22Array|CsvConversionError st3cr22 = parseListAsRecordType([st3, st3], (), {}, CustomRecord22Array); + CustomRecord22Array|Error st3cr22 = parseListAsRecordType([st3, st3], (), {}, CustomRecord22Array); test:assertEquals(st3cr22, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord22Array|CsvConversionError st4cr22 = parseListAsRecordType([st4, st4], (), {}, CustomRecord22Array); + CustomRecord22Array|Error st4cr22 = parseListAsRecordType([st4, st4], (), {}, CustomRecord22Array); test:assertEquals(st4cr22, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomRecord23Array|CsvConversionError st3cr23 = parseListAsRecordType([st3, st3], (), {}, CustomRecord23Array); + CustomRecord23Array|Error st3cr23 = parseListAsRecordType([st3, st3], (), {}, CustomRecord23Array); test:assertEquals(st3cr23, [ {"1": s1, "2": s2, a: ""}, {"1": s1, "2": s2, a: ""} ]); - CustomRecord23Array|CsvConversionError st4cr23 = parseListAsRecordType([st4, st4], (), {}, CustomRecord23Array); + CustomRecord23Array|Error st4cr23 = parseListAsRecordType([st4, st4], (), {}, CustomRecord23Array); test:assertEquals(st4cr23, [ {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} ]); - CustomRecord24Array|CsvConversionError st3cr24 = parseListAsRecordType([st3, st3], (), {}, CustomRecord24Array); + CustomRecord24Array|Error st3cr24 = parseListAsRecordType([st3, st3], (), {}, CustomRecord24Array); test:assertEquals(st3cr24, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord24Array|CsvConversionError st4cr24 = parseListAsRecordType([st4, st4], (), {}, CustomRecord24Array); + CustomRecord24Array|Error st4cr24 = parseListAsRecordType([st4, st4], (), {}, CustomRecord24Array); test:assertEquals(st4cr24, [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} @@ -485,13 +485,13 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { @test:Config {enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { - record{string a; boolean b; int c;}[]|CsvConversionError ct1br4 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b"], {}); + record{string a; boolean b; int c;}[]|Error ct1br4 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["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;}[]|CsvConversionError ct1br6 = parseListAsRecordType( + record{() a; float b; decimal c; boolean d; int e; string f;}[]|Error ct1br6 = parseListAsRecordType( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["f", "e", "d", "c", "b", "a"]); test:assertEquals(ct1br6, [ @@ -499,7 +499,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|decimal c; boolean d; int e; string f;|}[]|CsvConversionError ct1br7 = parseListAsRecordType( + record{|decimal c; boolean d; int e; string f;|}[]|Error ct1br7 = parseListAsRecordType( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["f", "e", "d", "c", "b", "a"]); test:assertEquals(ct1br7, [ @@ -507,7 +507,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {c: 2.23, d: true, e: 1, f: "a"} ]); - record{decimal c; boolean d; int e; string f;}[]|CsvConversionError ct1br8 = parseListAsRecordType( + record{decimal c; boolean d; int e; string f;}[]|Error ct1br8 = parseListAsRecordType( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["f", "e", "d", "c", "b", "a"]); test:assertEquals(ct1br8, [ @@ -515,7 +515,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {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...;|}[]|CsvConversionError ct1br9 = parseListAsRecordType( + record{|int|() a; float b; decimal? c; boolean d; int e; string f; string...;|}[]|Error ct1br9 = parseListAsRecordType( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["f", "e", "d", "c", "b", "a"]); test:assertEquals(ct1br9, [ @@ -524,7 +524,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { ]); // TODO: Check this - record{|int|() a; float b; decimal? c; string|boolean d; int|string e; string f; string...;|}[]|CsvConversionError ct1br9_2 = parseListAsRecordType( + record{|int|() a; float b; decimal? c; string|boolean d; int|string e; string f; string...;|}[]|Error ct1br9_2 = parseListAsRecordType( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["f", "e", "d", "c", "b", "a"]); test:assertEquals(ct1br9_2, [ @@ -532,7 +532,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|decimal c; boolean|string d; int e; string f; string...;|}[]|CsvConversionError ct1br10 = parseListAsRecordType( + record{|decimal c; boolean|string d; int e; string f; string...;|}[]|Error ct1br10 = parseListAsRecordType( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["f", "e", "d", "c", "b", "a"]); test:assertEquals(ct1br10, [ @@ -540,7 +540,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {a: "()", b: "0", c: 2.23, d: true, e: 1, f: "a"} ]); - record{|decimal? c; boolean d; int? e; string f; ()...;|}[]|CsvConversionError ct1br11 = parseListAsRecordType( + record{|decimal? c; boolean d; int? e; string f; ()...;|}[]|Error ct1br11 = parseListAsRecordType( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["f", "e", "d", "c", "b", "a"]); test:assertEquals(ct1br11, [ @@ -548,7 +548,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {a: (), c: 2.23, d: true, e: 1, f: "a"} ]); - record{|()...;|}[]|CsvConversionError ct1br12 = parseListAsRecordType( + record{|()...;|}[]|Error ct1br12 = parseListAsRecordType( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["f", "e", "d", "c", "b", "a"]); test:assertEquals(ct1br12, [ @@ -558,7 +558,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { // TODO: Add more tests with union types - record{|string?...;|}[]|CsvConversionError ct1br13 = parseListAsRecordType( + record{|string?...;|}[]|Error ct1br13 = parseListAsRecordType( [["a", "1"], ["a", "1"]], ["f", "e"]); test:assertEquals(ct1br13, [ @@ -566,7 +566,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {e: "1", f: "a"} ]); - record{|boolean...;|}[]|CsvConversionError ct1br14 = parseListAsRecordType( + record{|boolean...;|}[]|Error ct1br14 = parseListAsRecordType( [["2.23", "null"], ["7", "()"]], ["b", "a"]); test:assertEquals(ct1br14, [ @@ -574,7 +574,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {} ]); - map[]|CsvConversionError ct1br15 = parseListAsRecordType( + map[]|Error ct1br15 = parseListAsRecordType( [["2", "()"], ["2", "1"], ["()", "2"]], ["f", "e"]); test:assertEquals(ct1br15, [ @@ -583,7 +583,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {e: 2, f: ()} ]); - record{|boolean...;|}[]|CsvConversionError ct1br16 = parseListAsRecordType( + record{|boolean...;|}[]|Error ct1br16 = parseListAsRecordType( [["2.23", "null"], ["7", "()"]], ["b", "a"]); test:assertEquals(ct1br16, [ @@ -594,169 +594,169 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { @test:Config {enable} function testFromCsvWithTypeForTupleAndMapAsExpectedType() { - StringMapArray|CsvConversionError st1sma = parseListAsRecordType([st1, st1], (), {}, StringMapArray); + StringMapArray|Error st1sma = parseListAsRecordType([st1, st1], (), {}, StringMapArray); test:assertEquals(st1sma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - StringMapArray|CsvConversionError st2sma = parseListAsRecordType([st2, st2], (), {}, StringMapArray); + StringMapArray|Error st2sma = parseListAsRecordType([st2, st2], (), {}, StringMapArray); test:assertEquals(st2sma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - StringMapArray|CsvConversionError st3sma = parseListAsRecordType([st3, st3], (), {}, StringMapArray); + StringMapArray|Error st3sma = parseListAsRecordType([st3, st3], (), {}, StringMapArray); test:assertEquals(st3sma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - StringMapArray|CsvConversionError st4sma = parseListAsRecordType([st4, st4], (), {}, StringMapArray); + StringMapArray|Error st4sma = parseListAsRecordType([st4, st4], (), {}, StringMapArray); test:assertEquals(st4sma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - NillableIntUnionStringMapArray|CsvConversionError st1niusma = parseListAsRecordType([st1, st1], (), {}, NillableIntUnionStringMapArray); + NillableIntUnionStringMapArray|Error st1niusma = parseListAsRecordType([st1, st1], (), {}, NillableIntUnionStringMapArray); test:assertEquals(st1niusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - NillableIntUnionStringMapArray|CsvConversionError st2niusma = parseListAsRecordType([st2, st2], (), {}, NillableIntUnionStringMapArray); + NillableIntUnionStringMapArray|Error st2niusma = parseListAsRecordType([st2, st2], (), {}, NillableIntUnionStringMapArray); test:assertEquals(st2niusma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - NillableIntUnionStringMapArray|CsvConversionError st3niusma = parseListAsRecordType([st3, st3], (), {}, NillableIntUnionStringMapArray); + NillableIntUnionStringMapArray|Error st3niusma = parseListAsRecordType([st3, st3], (), {}, NillableIntUnionStringMapArray); test:assertEquals(st3niusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - NillableIntUnionStringMapArray|CsvConversionError st4niusma = parseListAsRecordType([st4, st4], (), {}, NillableIntUnionStringMapArray); + NillableIntUnionStringMapArray|Error st4niusma = parseListAsRecordType([st4, st4], (), {}, NillableIntUnionStringMapArray); test:assertEquals(st4niusma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - IntUnionStringMapArray|CsvConversionError st1iusma = parseListAsRecordType([st1, st1], (), {}, IntUnionStringMapArray); + IntUnionStringMapArray|Error st1iusma = parseListAsRecordType([st1, st1], (), {}, IntUnionStringMapArray); test:assertEquals(st1iusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - IntUnionStringMapArray|CsvConversionError st2iusma = parseListAsRecordType([st2, st2], (), {}, IntUnionStringMapArray); + IntUnionStringMapArray|Error st2iusma = parseListAsRecordType([st2, st2], (), {}, IntUnionStringMapArray); test:assertEquals(st2iusma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - IntUnionStringMapArray|CsvConversionError st3iusma = parseListAsRecordType([st3, st3], (), {}, IntUnionStringMapArray); + IntUnionStringMapArray|Error st3iusma = parseListAsRecordType([st3, st3], (), {}, IntUnionStringMapArray); test:assertEquals(st3iusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - IntUnionStringMapArray|CsvConversionError st4iusma = parseListAsRecordType([st4, st4], (), {}, IntUnionStringMapArray); + IntUnionStringMapArray|Error st4iusma = parseListAsRecordType([st4, st4], (), {}, IntUnionStringMapArray); test:assertEquals(st4iusma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - JsonMapArray|CsvConversionError st1jma = parseListAsRecordType([st1, st1], (), {}, JsonMapArray); + JsonMapArray|Error st1jma = parseListAsRecordType([st1, st1], (), {}, JsonMapArray); test:assertEquals(st1jma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - JsonMapArray|CsvConversionError st2jma = parseListAsRecordType([st2, st2], (), {}, JsonMapArray); + JsonMapArray|Error st2jma = parseListAsRecordType([st2, st2], (), {}, JsonMapArray); test:assertEquals(st2jma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - JsonMapArray|CsvConversionError st3jma = parseListAsRecordType([st3, st3], (), {}, JsonMapArray); + JsonMapArray|Error st3jma = parseListAsRecordType([st3, st3], (), {}, JsonMapArray); test:assertEquals(st3jma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - JsonMapArray|CsvConversionError st4jma = parseListAsRecordType([st4, st4], (), {}, JsonMapArray); + JsonMapArray|Error st4jma = parseListAsRecordType([st4, st4], (), {}, JsonMapArray); test:assertEquals(st4jma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - AnydataMapArray|CsvConversionError st1anydma = parseListAsRecordType([st1, st1], (), {}, AnydataMapArray); + AnydataMapArray|Error st1anydma = parseListAsRecordType([st1, st1], (), {}, AnydataMapArray); test:assertEquals(st1anydma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - AnydataMapArray|CsvConversionError st2anydma = parseListAsRecordType([st2, st2], (), {}, AnydataMapArray); + AnydataMapArray|Error st2anydma = parseListAsRecordType([st2, st2], (), {}, AnydataMapArray); test:assertEquals(st2anydma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - AnydataMapArray|CsvConversionError st3anydma = parseListAsRecordType([st3, st3], (), {}, AnydataMapArray); + AnydataMapArray|Error st3anydma = parseListAsRecordType([st3, st3], (), {}, AnydataMapArray); test:assertEquals(st3anydma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - AnydataMapArray|CsvConversionError st4anydma = parseListAsRecordType([st4, st4], (), {}, AnydataMapArray); + AnydataMapArray|Error st4anydma = parseListAsRecordType([st4, st4], (), {}, AnydataMapArray); test:assertEquals(st4anydma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomMapArray|CsvConversionError st1cma = parseListAsRecordType([st1, st1], (), {}, CustomMapArray); + CustomMapArray|Error st1cma = parseListAsRecordType([st1, st1], (), {}, CustomMapArray); test:assertEquals(st1cma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - CustomMapArray|CsvConversionError st2cma = parseListAsRecordType([st2, st2], (), {}, CustomMapArray); + CustomMapArray|Error st2cma = parseListAsRecordType([st2, st2], (), {}, CustomMapArray); test:assertEquals(st2cma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - CustomMapArray|CsvConversionError st3cma = parseListAsRecordType([st3, st3], (), {}, CustomMapArray); + CustomMapArray|Error st3cma = parseListAsRecordType([st3, st3], (), {}, CustomMapArray); test:assertEquals(st3cma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - CustomMapArray|CsvConversionError st4cma = parseListAsRecordType([st4, st4], (), {}, CustomMapArray); + CustomMapArray|Error st4cma = parseListAsRecordType([st4, st4], (), {}, CustomMapArray); test:assertEquals(st4cma , [ {'1: s1, '2: s2, '3: s3, '4: s2}, {'1: s1, '2: s2, '3: s3, '4: s2} ]); - NilMapArray|CsvConversionError st1nma = parseListAsRecordType([st1, st1], (), {}, NilMapArray); + NilMapArray|Error st1nma = parseListAsRecordType([st1, st1], (), {}, NilMapArray); test:assertEquals(st1nma, ([ {}, {} ])); - IntegerMapArray|CsvConversionError st2ima = parseListAsRecordType([st2, st2], (), {}, IntegerMapArray); + IntegerMapArray|Error st2ima = parseListAsRecordType([st2, st2], (), {}, IntegerMapArray); test:assertEquals(st2ima, ([ {}, {} ])); - DecimalMapArray|CsvConversionError st3dma = parseListAsRecordType([st3, st3], (), {}, DecimalMapArray); + DecimalMapArray|Error st3dma = parseListAsRecordType([st3, st3], (), {}, DecimalMapArray); test:assertEquals(st3dma, ([ {}, {} ])); - BooleanMapArray|CsvConversionError st4bma = parseListAsRecordType([st4, st4], (), {}, BooleanMapArray); + BooleanMapArray|Error st4bma = parseListAsRecordType([st4, st4], (), {}, BooleanMapArray); test:assertEquals(st4bma, ([ {}, {} diff --git a/ballerina/tests/parse_record_type_as_list_test.bal b/ballerina/tests/parse_record_type_as_list_test.bal index 9e34059..bedd8ea 100644 --- a/ballerina/tests/parse_record_type_as_list_test.bal +++ b/ballerina/tests/parse_record_type_as_list_test.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); // test:assertEquals(csvb4br1, [ // {b1: true, b2: "()", b3: (), b4: false}, // {b1: true, b2: "()", b3: (), b4: false} @@ -13,7 +13,7 @@ import ballerina/test; @test:Config {enable} function testFromCsvWithTypeForMapAndArrayAsExpectedType() { - BooleanArrayArray|CsvConversionError bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanArrayArray); + BooleanArrayArray|Error bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanArrayArray); test:assertEquals(bm1ba, [ [true, false], [true, false] @@ -25,45 +25,45 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { [false, true] ]); - BooleanArrayArray|CsvConversionError bm2ba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanArrayArray); - test:assertTrue(bm2ba is CsvConversionError); - test:assertEquals((bm2ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanArrayArray|Error bm2ba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanArrayArray); + test:assertTrue(bm2ba is Error); + test:assertEquals((bm2ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanArrayArray|CsvConversionError bm3ba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanArrayArray); - test:assertTrue(bm3ba is CsvConversionError); - test:assertEquals((bm3ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanArrayArray|Error bm3ba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanArrayArray); + test:assertTrue(bm3ba is Error); + test:assertEquals((bm3ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanArrayArray|CsvConversionError bm4ba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanArrayArray); - test:assertTrue(bm4ba is CsvConversionError); - test:assertEquals((bm4ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + BooleanArrayArray|Error bm4ba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanArrayArray); + test:assertTrue(bm4ba is Error); + test:assertEquals((bm4ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanArrayArray|CsvConversionError bm5ba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanArrayArray); - test:assertTrue(bm5ba is CsvConversionError); - test:assertEquals((bm5ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanArrayArray|Error bm5ba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanArrayArray); + test:assertTrue(bm5ba is Error); + test:assertEquals((bm5ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - NillableBooleanArrayArray|CsvConversionError bm1nba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanArrayArray); + NillableBooleanArrayArray|Error bm1nba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanArrayArray); test:assertEquals(bm1nba, [ [true, false], [true, false] ]); - NillableBooleanArrayArray|CsvConversionError bm2nba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanArrayArray); + NillableBooleanArrayArray|Error bm2nba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanArrayArray); test:assertEquals(bm2nba, [ [true, false, null, null, null], [true, false, null, null, null] ]); - NillableBooleanArrayArray|CsvConversionError bm3nba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanArrayArray); - test:assertTrue(bm3nba is CsvConversionError); - test:assertEquals((bm3nba).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); + NillableBooleanArrayArray|Error bm3nba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanArrayArray); + test:assertTrue(bm3nba is Error); + test:assertEquals((bm3nba).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanArrayArray|CsvConversionError bm4nba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanArrayArray); + NillableBooleanArrayArray|Error bm4nba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanArrayArray); test:assertEquals(bm4nba, [ [(), ()], [(), ()] ]); - NillableBooleanArrayArray|CsvConversionError bm5nba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanArrayArray); + NillableBooleanArrayArray|Error bm5nba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanArrayArray); test:assertEquals(bm5nba, [ [true, false, (), true], [true, false, (), true] @@ -81,294 +81,294 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { [true, (), false, true] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm1niouba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|Error bm1niouba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm1niouba, [ [true, false], [true, false] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm2niouba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|Error bm2niouba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm2niouba, [ [true, false, null, null, null], [true, false, null, null, null] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm3niouba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|Error bm3niouba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm3niouba, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm4niouba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|Error bm4niouba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm4niouba, [ [(), ()], [(), ()] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError bm5niouba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|Error bm5niouba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm5niouba, [ [true, false, (), true], [true, false, (), true] ]); - JsonArray1Array|CsvConversionError bm1ja = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, JsonArray1Array); + JsonArray1Array|Error bm1ja = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, JsonArray1Array); test:assertEquals(bm1ja, [ [true, false], [true, false] ]); - JsonArray1Array|CsvConversionError bm2ja = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, JsonArray1Array); + JsonArray1Array|Error bm2ja = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, JsonArray1Array); test:assertEquals(bm2ja, [ [true, false, null, null, null], [true, false, null, null, null] ]); - JsonArray1Array|CsvConversionError bm3ja = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, JsonArray1Array); + JsonArray1Array|Error bm3ja = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, JsonArray1Array); test:assertEquals(bm3ja, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - JsonArray1Array|CsvConversionError bm4ja = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonArray1Array); + JsonArray1Array|Error bm4ja = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonArray1Array); test:assertEquals(bm4ja, [ [(), ()], [(), ()] ]); - JsonArray1Array|CsvConversionError bm5ja = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, JsonArray1Array); + JsonArray1Array|Error bm5ja = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, JsonArray1Array); test:assertEquals(bm5ja, [ [true, false, (), true], [true, false, (), true] ]); - AnydataArray1Array|CsvConversionError bm1anyda = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataArray1Array); + AnydataArray1Array|Error bm1anyda = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataArray1Array); test:assertEquals(bm1anyda, [ [true, false], [true, false] ]); - AnydataArray1Array|CsvConversionError bm2anyda = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, AnydataArray1Array); + AnydataArray1Array|Error bm2anyda = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, AnydataArray1Array); test:assertEquals(bm2anyda, [ [true, false, null, null, null], [true, false, null, null, null] ]); - AnydataArray1Array|CsvConversionError bm3anyda = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, AnydataArray1Array); + AnydataArray1Array|Error bm3anyda = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, AnydataArray1Array); test:assertEquals(bm3anyda, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - AnydataArray1Array|CsvConversionError bm4anyda = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataArray1Array); + AnydataArray1Array|Error bm4anyda = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataArray1Array); test:assertEquals(bm4anyda, [ [(), ()], [(), ()] ]); - AnydataArray1Array|CsvConversionError bm5anyda = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, AnydataArray1Array); + AnydataArray1Array|Error bm5anyda = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, AnydataArray1Array); test:assertEquals(bm5anyda, [ [true, false, (), true], [true, false, (), true] ]); - StringArray1Array|CsvConversionError bm1sa = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, StringArray1Array); - test:assertTrue(bm1sa is CsvConversionError); - test:assertEquals((bm1sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + StringArray1Array|Error bm1sa = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, StringArray1Array); + test:assertTrue(bm1sa is Error); + test:assertEquals((bm1sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|CsvConversionError bm2sa = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, StringArray1Array); - test:assertTrue(bm2sa is CsvConversionError); - test:assertEquals((bm2sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + StringArray1Array|Error bm2sa = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, StringArray1Array); + test:assertTrue(bm2sa is Error); + test:assertEquals((bm2sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|CsvConversionError bm3sa = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, StringArray1Array); - test:assertTrue(bm3sa is CsvConversionError); - test:assertEquals((bm3sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + StringArray1Array|Error bm3sa = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, StringArray1Array); + test:assertTrue(bm3sa is Error); + test:assertEquals((bm3sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|CsvConversionError bm4sa = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, StringArray1Array); - test:assertTrue(bm4sa is CsvConversionError); - test:assertEquals((bm4sa).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); + StringArray1Array|Error bm4sa = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, StringArray1Array); + test:assertTrue(bm4sa is Error); + test:assertEquals((bm4sa).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - StringArray1Array|CsvConversionError bm5sa = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, StringArray1Array); - test:assertTrue(bm5sa is CsvConversionError); - test:assertEquals((bm5sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + StringArray1Array|Error bm5sa = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, StringArray1Array); + test:assertTrue(bm5sa is Error); + test:assertEquals((bm5sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } @test:Config {enable} function testFromCsvWithTypeForMapAndTupleAsExpectedType() { - BooleanTuple1Array|CsvConversionError bm1bt = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple1Array); + BooleanTuple1Array|Error bm1bt = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple1Array); test:assertEquals(bm1bt, [ [true, false, false, false], [true, false, false, false] ]); - BooleanTuple1Array|CsvConversionError bm2bt = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple1Array); - test:assertTrue(bm2bt is CsvConversionError); - test:assertEquals((bm2bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanTuple1Array|Error bm2bt = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple1Array); + test:assertTrue(bm2bt is Error); + test:assertEquals((bm2bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple1Array|CsvConversionError bm3bt = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple1Array); - test:assertTrue(bm3bt is CsvConversionError); - test:assertEquals((bm3bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanTuple1Array|Error bm3bt = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple1Array); + test:assertTrue(bm3bt is Error); + test:assertEquals((bm3bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple1Array|CsvConversionError bm4bt = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple1Array); - test:assertTrue(bm4bt is CsvConversionError); - test:assertEquals((bm4bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + BooleanTuple1Array|Error bm4bt = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple1Array); + test:assertTrue(bm4bt is Error); + test:assertEquals((bm4bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple1Array|CsvConversionError bm5bt = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple1Array); - test:assertTrue(bm5bt is CsvConversionError); - test:assertEquals((bm5bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanTuple1Array|Error bm5bt = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple1Array); + test:assertTrue(bm5bt is Error); + test:assertEquals((bm5bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple2Array|CsvConversionError bm1b2t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple2Array); + BooleanTuple2Array|Error bm1b2t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple2Array); test:assertEquals(bm1b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|CsvConversionError bm2b2t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple2Array); + BooleanTuple2Array|Error bm2b2t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple2Array); test:assertEquals(bm2b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|CsvConversionError bm3b2t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple2Array); + BooleanTuple2Array|Error bm3b2t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple2Array); test:assertEquals(bm3b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|CsvConversionError bm4b2t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple2Array); - test:assertTrue(bm4b2t is CsvConversionError); - test:assertEquals((bm4b2t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + BooleanTuple2Array|Error bm4b2t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple2Array); + test:assertTrue(bm4b2t is Error); + test:assertEquals((bm4b2t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple2Array|CsvConversionError bm5b2t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple2Array); + BooleanTuple2Array|Error bm5b2t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple2Array); test:assertEquals(bm5b2t, [ [true, false], [true, false] ]); - BooleanTuple3Array|CsvConversionError bm1b3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple3Array); + BooleanTuple3Array|Error bm1b3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple3Array); test:assertEquals(bm1b3t, [ [true, false], [true, false] ]); - BooleanTuple3Array|CsvConversionError bm2b3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple3Array); - test:assertTrue(bm2b3t is CsvConversionError); - test:assertEquals((bm2b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanTuple3Array|Error bm2b3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple3Array); + test:assertTrue(bm2b3t is Error); + test:assertEquals((bm2b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple3Array|CsvConversionError bm3b3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple3Array); - test:assertTrue(bm3b3t is CsvConversionError); - test:assertEquals((bm3b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanTuple3Array|Error bm3b3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple3Array); + test:assertTrue(bm3b3t is Error); + test:assertEquals((bm3b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple3Array|CsvConversionError bm4b3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple3Array); - test:assertTrue(bm4b3t is CsvConversionError); - test:assertEquals((bm4b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + BooleanTuple3Array|Error bm4b3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple3Array); + test:assertTrue(bm4b3t is Error); + test:assertEquals((bm4b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple3Array|CsvConversionError bm5b3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple3Array); - test:assertTrue(bm5b3t is CsvConversionError); - test:assertEquals((bm5b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanTuple3Array|Error bm5b3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple3Array); + test:assertTrue(bm5b3t is Error); + test:assertEquals((bm5b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple4Array|CsvConversionError bm1b4t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple4Array); + BooleanTuple4Array|Error bm1b4t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple4Array); test:assertEquals(bm1b4t, [ [true, false], [true, false] ]); - BooleanTuple4Array|CsvConversionError bm2b4t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple4Array); - test:assertTrue(bm2b4t is CsvConversionError); - test:assertEquals((bm2b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanTuple4Array|Error bm2b4t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple4Array); + test:assertTrue(bm2b4t is Error); + test:assertEquals((bm2b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple4Array|CsvConversionError bm3b4t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple4Array); - test:assertTrue(bm3b4t is CsvConversionError); - test:assertEquals((bm3b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanTuple4Array|Error bm3b4t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple4Array); + test:assertTrue(bm3b4t is Error); + test:assertEquals((bm3b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple4Array|CsvConversionError bm4b4t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple4Array); - test:assertTrue(bm4b4t is CsvConversionError); - test:assertEquals((bm4b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); + BooleanTuple4Array|Error bm4b4t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple4Array); + test:assertTrue(bm4b4t is Error); + test:assertEquals((bm4b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple4Array|CsvConversionError bm5b4t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple4Array); - test:assertTrue(bm5b4t is CsvConversionError); - test:assertEquals((bm5b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); + BooleanTuple4Array|Error bm5b4t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple4Array); + test:assertTrue(bm5b4t is Error); + test:assertEquals((bm5b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - NillableBooleanTuple5Array|CsvConversionError bm1nbt = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|Error bm1nbt = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple5Array); test:assertEquals(bm1nbt, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple5Array|CsvConversionError bm2nbt = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|Error bm2nbt = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple5Array); test:assertEquals(bm2nbt, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple5Array|CsvConversionError bm3nbt = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple5Array); - test:assertTrue(bm3nbt is CsvConversionError); - test:assertEquals((bm3nbt).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); + NillableBooleanTuple5Array|Error bm3nbt = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple5Array); + test:assertTrue(bm3nbt is Error); + test:assertEquals((bm3nbt).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple5Array|CsvConversionError bm4nbt = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|Error bm4nbt = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple5Array); test:assertEquals(bm4nbt, [ [(), (), (), (), ()], [(), (), (), (), ()] ]); - NillableBooleanTuple5Array|CsvConversionError bm5nbt = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|Error bm5nbt = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple5Array); test:assertEquals(bm5nbt, [ [true, false, (), true, ()], [true, false, (), true, ()] ]); - NillableBooleanTuple6Array|CsvConversionError bm1nb6t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|Error bm1nb6t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple6Array); test:assertEquals(bm1nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|CsvConversionError bm2nb6t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|Error bm2nb6t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple6Array); test:assertEquals(bm2nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|CsvConversionError bm3nb6t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|Error bm3nb6t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple6Array); test:assertEquals(bm3nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|CsvConversionError bm4nb6t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|Error bm4nb6t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple6Array); test:assertEquals(bm4nb6t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple6Array|CsvConversionError bm5nb6t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|Error bm5nb6t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple6Array); test:assertEquals(bm5nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple7Array|CsvConversionError bm1nb7t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|Error bm1nb7t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple7Array); test:assertEquals(bm1nb7t, [ [true, false], [true, false] ]); - NillableBooleanTuple7Array|CsvConversionError bm2nb7t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|Error bm2nb7t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple7Array); test:assertEquals(bm2nb7t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple7Array|CsvConversionError bm3nb7t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple7Array); - test:assertTrue(bm3nb7t is CsvConversionError); - test:assertEquals((bm3nb7t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); + NillableBooleanTuple7Array|Error bm3nb7t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple7Array); + test:assertTrue(bm3nb7t is Error); + test:assertEquals((bm3nb7t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple7Array|CsvConversionError bm4nb7t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|Error bm4nb7t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple7Array); test:assertEquals(bm4nb7t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple7Array|CsvConversionError bm5nb7t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|Error bm5nb7t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple7Array); test:assertEquals(bm5nb7t, [ [true, false, (), true], [true, false, (), true] @@ -377,167 +377,167 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { @test:Config {enable} function testFromCsvWithTypeForMapAndTupleAsExpectedType2() { - NillableBooleanTuple8Array|CsvConversionError bm1nb8t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|Error bm1nb8t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple8Array); test:assertEquals(bm1nb8t, [ [true, false], [true, false] ]); - NillableBooleanTuple8Array|CsvConversionError bm2nb8t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|Error bm2nb8t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple8Array); test:assertEquals(bm2nb8t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple8Array|CsvConversionError bm3nb8t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple8Array); - test:assertTrue(bm3nb8t is CsvConversionError); - test:assertEquals((bm3nb8t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); + NillableBooleanTuple8Array|Error bm3nb8t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple8Array); + test:assertTrue(bm3nb8t is Error); + test:assertEquals((bm3nb8t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple8Array|CsvConversionError bm4nb8t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|Error bm4nb8t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple8Array); test:assertEquals(bm4nb8t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple8Array|CsvConversionError bm5nb8t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|Error bm5nb8t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple8Array); test:assertEquals(bm5nb8t, [ [true, false, (), true], [true, false, (), true] ]); - NillableIntBooleanTuple9Array|CsvConversionError bm1nb9t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|Error bm1nb9t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableIntBooleanTuple9Array); test:assertEquals(bm1nb9t, [ [true, false], [true, false] ]); - NillableIntBooleanTuple9Array|CsvConversionError bm2nb9t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|Error bm2nb9t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableIntBooleanTuple9Array); test:assertEquals(bm2nb9t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableIntBooleanTuple9Array|CsvConversionError bm3nb9t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|Error bm3nb9t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableIntBooleanTuple9Array); test:assertEquals(bm3nb9t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - NillableIntBooleanTuple9Array|CsvConversionError bm4nb9t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|Error bm4nb9t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntBooleanTuple9Array); test:assertEquals(bm4nb9t, [ [(), ()], [(), ()] ]); - NillableIntBooleanTuple9Array|CsvConversionError bm5nb9t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|Error bm5nb9t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableIntBooleanTuple9Array); test:assertEquals(bm5nb9t, [ [true, false, (), true], [true, false, (), true] ]); - NilTuple3Array|CsvConversionError bm1n3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NilTuple3Array); - test:assertTrue(bm1n3t is CsvConversionError); - test:assertEquals((bm1n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + NilTuple3Array|Error bm1n3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NilTuple3Array); + test:assertTrue(bm1n3t is Error); + test:assertEquals((bm1n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|CsvConversionError bm2n3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NilTuple3Array); - test:assertTrue(bm2n3t is CsvConversionError); - test:assertEquals((bm2n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + NilTuple3Array|Error bm2n3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NilTuple3Array); + test:assertTrue(bm2n3t is Error); + test:assertEquals((bm2n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|CsvConversionError bm3n3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NilTuple3Array); - test:assertTrue(bm3n3t is CsvConversionError); - test:assertEquals((bm3n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + NilTuple3Array|Error bm3n3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NilTuple3Array); + test:assertTrue(bm3n3t is Error); + test:assertEquals((bm3n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|CsvConversionError bm4n3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NilTuple3Array); + NilTuple3Array|Error bm4n3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NilTuple3Array); test:assertEquals(bm4n3t, [ [(), ()], [(), ()] ]); - NilTuple3Array|CsvConversionError bm5n3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NilTuple3Array); - test:assertTrue(bm5n3t is CsvConversionError); - test:assertEquals((bm5n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); + NilTuple3Array|Error bm5n3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NilTuple3Array); + test:assertTrue(bm5n3t is Error); + test:assertEquals((bm5n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); } @test:Config {enable} function testFromCsvWithTypeForMapAndArrayAsExpectedType2() { - AnydataTuple3Array|CsvConversionError bm1anyd3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataTuple3Array); + AnydataTuple3Array|Error bm1anyd3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataTuple3Array); test:assertEquals(bm1anyd3t, [ [true, false], [true, false] ]); - AnydataTuple3Array|CsvConversionError bm2anyd3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, AnydataTuple3Array); + AnydataTuple3Array|Error bm2anyd3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, AnydataTuple3Array); test:assertEquals(bm2anyd3t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - AnydataTuple3Array|CsvConversionError bm3anyd3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, AnydataTuple3Array); + AnydataTuple3Array|Error bm3anyd3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, AnydataTuple3Array); test:assertEquals(bm3anyd3t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - AnydataTuple3Array|CsvConversionError bm4anyd3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataTuple3Array); + AnydataTuple3Array|Error bm4anyd3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataTuple3Array); test:assertEquals(bm4anyd3t, [ [(), ()], [(), ()] ]); - AnydataTuple3Array|CsvConversionError bm5anyd3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, AnydataTuple3Array); + AnydataTuple3Array|Error bm5anyd3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, AnydataTuple3Array); test:assertEquals(bm5anyd3t, [ [true, false, (), true], [true, false, (), true] ]); - JsonTuple3Array|CsvConversionError bm1j3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, JsonTuple3Array); + JsonTuple3Array|Error bm1j3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, JsonTuple3Array); test:assertEquals(bm1j3t, [ [true, false], [true, false] ]); - JsonTuple3Array|CsvConversionError bm2j3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, JsonTuple3Array); + JsonTuple3Array|Error bm2j3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, JsonTuple3Array); test:assertEquals(bm2j3t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - JsonTuple3Array|CsvConversionError bm3j3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, JsonTuple3Array); + JsonTuple3Array|Error bm3j3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, JsonTuple3Array); test:assertEquals(bm3j3t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - JsonTuple3Array|CsvConversionError bm4j3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonTuple3Array); + JsonTuple3Array|Error bm4j3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonTuple3Array); test:assertEquals(bm4j3t, [ [(), ()], [(), ()] ]); - JsonTuple3Array|CsvConversionError bm5j3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, JsonTuple3Array); + JsonTuple3Array|Error bm5j3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, JsonTuple3Array); test:assertEquals(bm5j3t, [ [true, false, (), true], [true, false, (), true] ]); - StringTuple3Array|CsvConversionError bm1s3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, StringTuple3Array); - test:assertTrue(bm1s3t is CsvConversionError); - test:assertEquals((bm1s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + StringTuple3Array|Error bm1s3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, StringTuple3Array); + test:assertTrue(bm1s3t is Error); + test:assertEquals((bm1s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|CsvConversionError bm2s3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, StringTuple3Array); - test:assertTrue(bm2s3t is CsvConversionError); - test:assertEquals((bm2s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + StringTuple3Array|Error bm2s3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, StringTuple3Array); + test:assertTrue(bm2s3t is Error); + test:assertEquals((bm2s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|CsvConversionError bm3s3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, StringTuple3Array); - test:assertTrue(bm3s3t is CsvConversionError); - test:assertEquals((bm3s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + StringTuple3Array|Error bm3s3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, StringTuple3Array); + test:assertTrue(bm3s3t is Error); + test:assertEquals((bm3s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|CsvConversionError bm4s3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, StringTuple3Array); - test:assertTrue(bm4s3t is CsvConversionError); - test:assertEquals((bm4s3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); + StringTuple3Array|Error bm4s3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, StringTuple3Array); + test:assertTrue(bm4s3t is Error); + test:assertEquals((bm4s3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - StringTuple3Array|CsvConversionError bm5s3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, StringTuple3Array); - test:assertTrue(bm5s3t is CsvConversionError); - test:assertEquals((bm5s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); + StringTuple3Array|Error bm5s3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, StringTuple3Array); + test:assertTrue(bm5s3t is Error); + test:assertEquals((bm5s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } diff --git a/ballerina/tests/parse_record_type_as_record_test.bal b/ballerina/tests/parse_record_type_as_record_test.bal index be66a07..7f19758 100644 --- a/ballerina/tests/parse_record_type_as_record_test.bal +++ b/ballerina/tests/parse_record_type_as_record_test.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// StringRecord10Array|CsvConversionError st1sr10 = parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); +// StringRecord10Array|Error st1sr10 = parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); // test:assertEquals(st1sr10, [ // {'1: "string", '2: ""}, // {'1: "string", '2: ""} @@ -13,447 +13,447 @@ import ballerina/test; @test:Config {enable} function testFromCsvWithTypeForMapAndRecordAsExpectedType() { - BooleanRecord1Array|CsvConversionError bm1br1 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord1Array); - test:assertTrue(bm1br1 is CsvConversionError); - test:assertEquals((bm1br1).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord1Array|Error bm1br1 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord1Array); + test:assertTrue(bm1br1 is Error); + test:assertEquals((bm1br1).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord1Array|CsvConversionError bm2br1 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord1Array); - test:assertTrue(bm2br1 is CsvConversionError); - test:assertEquals((bm2br1).message(), generateErrorMessageForMissingRequiredField("b4")); + BooleanRecord1Array|Error bm2br1 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord1Array); + test:assertTrue(bm2br1 is Error); + test:assertEquals((bm2br1).message(), generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord1Array|CsvConversionError bm3br1 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord1Array); + BooleanRecord1Array|Error bm3br1 = parseRecordAsRecordType([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|CsvConversionError bm4br1 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord1Array); - test:assertTrue(bm4br1 is CsvConversionError); - test:assertEquals((bm4br1).message(), generateErrorMessageForMissingRequiredField("b2")); + BooleanRecord1Array|Error bm4br1 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord1Array); + test:assertTrue(bm4br1 is Error); + test:assertEquals((bm4br1).message(), generateErrorMessageForMissingRequiredField("b2")); - BooleanRecord1Array|CsvConversionError bm5br1 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord1Array); + BooleanRecord1Array|Error bm5br1 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord1Array); test:assertEquals(bm5br1, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - BooleanRecord2Array|CsvConversionError bm1br2 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord2Array); - test:assertTrue(bm1br2 is CsvConversionError); - test:assertEquals((bm1br2).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord2Array|Error bm1br2 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord2Array); + test:assertTrue(bm1br2 is Error); + test:assertEquals((bm1br2).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord2Array|CsvConversionError bm2br2 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord2Array); - test:assertTrue(bm2br2 is CsvConversionError); - test:assertEquals((bm2br2).message(), generateErrorMessageForMissingRequiredField("b4")); + BooleanRecord2Array|Error bm2br2 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord2Array); + test:assertTrue(bm2br2 is Error); + test:assertEquals((bm2br2).message(), generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord2Array|CsvConversionError bm3br2 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord2Array); + BooleanRecord2Array|Error bm3br2 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord2Array); test:assertEquals(bm3br2, [ {b1: true, b2: false, b3: (), b4: false}, {b1: true, b2: false, b3: (), b4: false} ]); - BooleanRecord2Array|CsvConversionError bm4br2 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord2Array); - test:assertTrue(bm4br2 is CsvConversionError); - test:assertEquals((bm4br2).message(), generateErrorMessageForMissingRequiredField("b2")); + BooleanRecord2Array|Error bm4br2 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord2Array); + test:assertTrue(bm4br2 is Error); + test:assertEquals((bm4br2).message(), generateErrorMessageForMissingRequiredField("b2")); - BooleanRecord2Array|CsvConversionError bm5br2 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord2Array); + BooleanRecord2Array|Error bm5br2 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord2Array); test:assertEquals(bm5br2, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - BooleanRecord3Array|CsvConversionError bm1br3 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord3Array); - test:assertTrue(bm1br3 is CsvConversionError); - test:assertEquals((bm1br3).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord3Array|Error bm1br3 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord3Array); + test:assertTrue(bm1br3 is Error); + test:assertEquals((bm1br3).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord3Array|CsvConversionError bm2br3 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord3Array); + BooleanRecord3Array|Error bm2br3 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord3Array); test:assertEquals(bm2br3, [ {b1: true, b3: ()}, {b1: true, b3: ()} ]); - BooleanRecord3Array|CsvConversionError bm3br3 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord3Array); + BooleanRecord3Array|Error bm3br3 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord3Array); test:assertEquals(bm3br3, [ {b1: true, b3: ()}, {b1: true, b3: ()} ]); - BooleanRecord3Array|CsvConversionError bm4br3 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord3Array); - test:assertTrue(bm4br3 is CsvConversionError); - test:assertEquals((bm4br3).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord3Array|Error bm4br3 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord3Array); + test:assertTrue(bm4br3 is Error); + test:assertEquals((bm4br3).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord3Array|CsvConversionError bm5br3 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord3Array); + BooleanRecord3Array|Error bm5br3 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord3Array); test:assertEquals(bm5br3, [{b1: true, b3: ()}, {b1: true, b3: ()}]); - BooleanRecord4Array|CsvConversionError bm1br4 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord4Array); - test:assertTrue(bm1br4 is CsvConversionError); - test:assertEquals((bm1br4).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord4Array|Error bm1br4 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord4Array); + test:assertTrue(bm1br4 is Error); + test:assertEquals((bm1br4).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord4Array|CsvConversionError bm2br4 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord4Array); + BooleanRecord4Array|Error bm2br4 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord4Array); test:assertEquals(bm2br4, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} ]); - BooleanRecord4Array|CsvConversionError bm3br4 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord4Array); + BooleanRecord4Array|Error bm3br4 = parseRecordAsRecordType([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|CsvConversionError bm4br4 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord4Array); - test:assertTrue(bm4br4 is CsvConversionError); - test:assertEquals((bm4br4).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord4Array|Error bm4br4 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord4Array); + test:assertTrue(bm4br4 is Error); + test:assertEquals((bm4br4).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord4Array|CsvConversionError bm5br4 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord4Array); + BooleanRecord4Array|Error bm5br4 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord4Array); test:assertEquals(bm5br4, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - BooleanRecord5Array|CsvConversionError bm1br5 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord5Array); - test:assertTrue(bm1br5 is CsvConversionError); - test:assertEquals((bm1br5).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord5Array|Error bm1br5 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord5Array); + test:assertTrue(bm1br5 is Error); + test:assertEquals((bm1br5).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord5Array|CsvConversionError bm2br5 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord5Array); + BooleanRecord5Array|Error bm2br5 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord5Array); test:assertEquals(bm2br5, [ {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()}, {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()} ]); - BooleanRecord5Array|CsvConversionError bm3br5 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord5Array); + BooleanRecord5Array|Error bm3br5 = parseRecordAsRecordType([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|CsvConversionError bm4br5 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord5Array); - test:assertTrue(bm4br5 is CsvConversionError); - test:assertEquals((bm4br5).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord5Array|Error bm4br5 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord5Array); + test:assertTrue(bm4br5 is Error); + test:assertEquals((bm4br5).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord5Array|CsvConversionError bm5br5 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord5Array); + BooleanRecord5Array|Error bm5br5 = parseRecordAsRecordType([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|CsvConversionError bm1br6 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord6Array); - test:assertTrue(bm1br6 is CsvConversionError); - test:assertEquals((bm1br6).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord6Array|Error bm1br6 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord6Array); + test:assertTrue(bm1br6 is Error); + test:assertEquals((bm1br6).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord6Array|CsvConversionError bm2br6 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord6Array); + BooleanRecord6Array|Error bm2br6 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord6Array); test:assertEquals(bm2br6, [ {b1: true, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|CsvConversionError bm3br6 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord6Array); + BooleanRecord6Array|Error bm3br6 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord6Array); test:assertEquals(bm3br6, [ {b1: true, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|CsvConversionError bm4br6 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord6Array); - test:assertTrue(bm4br6 is CsvConversionError); - test:assertEquals((bm4br6).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord6Array|Error bm4br6 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord6Array); + test:assertTrue(bm4br6 is Error); + test:assertEquals((bm4br6).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord6Array|CsvConversionError bm5br6 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord6Array); + BooleanRecord6Array|Error bm5br6 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord6Array); test:assertEquals(bm5br6, [ {b1: true, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord7Array|CsvConversionError bm1br7 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord7Array); - test:assertTrue(bm1br7 is CsvConversionError); - test:assertEquals((bm1br7).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord7Array|Error bm1br7 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord7Array); + test:assertTrue(bm1br7 is Error); + test:assertEquals((bm1br7).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord7Array|CsvConversionError bm2br7 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord7Array); - test:assertTrue(bm2br7 is CsvConversionError); - test:assertEquals((bm2br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord7Array|Error bm2br7 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord7Array); + test:assertTrue(bm2br7 is Error); + test:assertEquals((bm2br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord7Array|CsvConversionError bm3br7 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord7Array); - test:assertTrue(bm3br7 is CsvConversionError); - test:assertEquals((bm3br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord7Array|Error bm3br7 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord7Array); + test:assertTrue(bm3br7 is Error); + test:assertEquals((bm3br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord7Array|CsvConversionError bm4br7 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord7Array); - test:assertTrue(bm4br7 is CsvConversionError); - test:assertEquals((bm4br7).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord7Array|Error bm4br7 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord7Array); + test:assertTrue(bm4br7 is Error); + test:assertEquals((bm4br7).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord7Array|CsvConversionError bm5br7 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord7Array); - test:assertTrue(bm5br7 is CsvConversionError); - test:assertEquals((bm5br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord7Array|Error bm5br7 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord7Array); + test:assertTrue(bm5br7 is Error); + test:assertEquals((bm5br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord8Array|CsvConversionError bm1br8 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord8Array); - test:assertTrue(bm1br8 is CsvConversionError); - test:assertEquals((bm1br8).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord8Array|Error bm1br8 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord8Array); + test:assertTrue(bm1br8 is Error); + test:assertEquals((bm1br8).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord8Array|CsvConversionError bm2br8 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord8Array); - test:assertTrue(bm2br8 is CsvConversionError); - test:assertEquals((bm2br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord8Array|Error bm2br8 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord8Array); + test:assertTrue(bm2br8 is Error); + test:assertEquals((bm2br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord8Array|CsvConversionError bm3br8 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord8Array); - test:assertTrue(bm3br8 is CsvConversionError); - test:assertEquals((bm3br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord8Array|Error bm3br8 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord8Array); + test:assertTrue(bm3br8 is Error); + test:assertEquals((bm3br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord8Array|CsvConversionError bm4br8 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord8Array); - test:assertTrue(bm4br8 is CsvConversionError); - test:assertEquals((bm4br8).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord8Array|Error bm4br8 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord8Array); + test:assertTrue(bm4br8 is Error); + test:assertEquals((bm4br8).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord8Array|CsvConversionError bm5br8 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord8Array); - test:assertTrue(bm5br8 is CsvConversionError); - test:assertEquals((bm5br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord8Array|Error bm5br8 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord8Array); + test:assertTrue(bm5br8 is Error); + test:assertEquals((bm5br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); } @test:Config {enable} function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { - BooleanRecord9Array|CsvConversionError bm1br9 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord9Array); - test:assertTrue(bm1br9 is CsvConversionError); - test:assertEquals((bm1br9).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord9Array|Error bm1br9 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord9Array); + test:assertTrue(bm1br9 is Error); + test:assertEquals((bm1br9).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord9Array|CsvConversionError bm2br9 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord9Array); + BooleanRecord9Array|Error bm2br9 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord9Array); test:assertEquals(bm2br9, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} ]); - BooleanRecord9Array|CsvConversionError bm3br9 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord9Array); + BooleanRecord9Array|Error bm3br9 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord9Array); test:assertEquals(bm3br9, [ {b1: true, b2: false, b3: (), b4: false}, {b1: true, b2: false, b3: (), b4: false} ]); - BooleanRecord9Array|CsvConversionError bm4br9 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord9Array); - test:assertTrue(bm4br9 is CsvConversionError); - test:assertEquals((bm4br9).message(), generateErrorMessageForMissingRequiredField("b3")); + BooleanRecord9Array|Error bm4br9 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord9Array); + test:assertTrue(bm4br9 is Error); + test:assertEquals((bm4br9).message(), generateErrorMessageForMissingRequiredField("b3")); - BooleanRecord9Array|CsvConversionError bm5br9 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord9Array); + BooleanRecord9Array|Error bm5br9 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord9Array); test:assertEquals(bm5br9, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - BooleanRecord10Array|CsvConversionError bm1br10 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord10Array); + BooleanRecord10Array|Error bm1br10 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord10Array); test:assertEquals(bm1br10, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanRecord10Array|CsvConversionError bm2br10 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord10Array); + BooleanRecord10Array|Error bm2br10 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord10Array); test:assertEquals(bm2br10, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanRecord10Array|CsvConversionError bm3br10 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord10Array); + BooleanRecord10Array|Error bm3br10 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord10Array); test:assertEquals(bm3br10, [ {b1: true, b2: false, b4: false}, {b1: true, b2: false, b4: false} ]); - BooleanRecord10Array|CsvConversionError bm4br10 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord10Array); + BooleanRecord10Array|Error bm4br10 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord10Array); test:assertEquals(bm4br10, [ {}, {} ]); - BooleanRecord10Array|CsvConversionError bm5br10 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord10Array); + BooleanRecord10Array|Error bm5br10 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord10Array); test:assertEquals(bm5br10, [ {b1: true, b2: false, b4: true}, {b1: true, b2: false, b4: true} ]); - BooleanRecord11Array|CsvConversionError bm1br11 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord11Array); + BooleanRecord11Array|Error bm1br11 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord11Array); test:assertEquals(bm1br11, [ {b1: true, b2: false, defaultableField: "", nillableField :null}, {b1: true, b2: false, defaultableField: "", nillableField :null} ]); - BooleanRecord11Array|CsvConversionError bm2br11 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord11Array); + BooleanRecord11Array|Error bm2br11 = parseRecordAsRecordType([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|CsvConversionError bm3br11 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord11Array); + BooleanRecord11Array|Error bm3br11 = parseRecordAsRecordType([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|CsvConversionError bm4br11 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord11Array); - test:assertTrue(bm4br11 is CsvConversionError); - test:assertEquals((bm4br11).message(), generateErrorMessageForMissingRequiredField("b1")); + BooleanRecord11Array|Error bm4br11 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord11Array); + test:assertTrue(bm4br11 is Error); + test:assertEquals((bm4br11).message(), generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord11Array|CsvConversionError bm5br11 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord11Array); + BooleanRecord11Array|Error bm5br11 = parseRecordAsRecordType([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|CsvConversionError bm1br12 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord12Array); - test:assertTrue(bm1br12 is CsvConversionError); - test:assertEquals((bm1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord12Array|Error bm1br12 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord12Array); + test:assertTrue(bm1br12 is Error); + test:assertEquals((bm1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord12Array|CsvConversionError bm2br12 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord12Array); - test:assertTrue(bm2br12 is CsvConversionError); - test:assertEquals((bm2br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord12Array|Error bm2br12 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord12Array); + test:assertTrue(bm2br12 is Error); + test:assertEquals((bm2br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord12Array|CsvConversionError bm3br12 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord12Array); - test:assertTrue(bm3br12 is CsvConversionError); - test:assertEquals((bm3br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord12Array|Error bm3br12 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord12Array); + test:assertTrue(bm3br12 is Error); + test:assertEquals((bm3br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord12Array|CsvConversionError bm4br12 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord12Array); - test:assertTrue(bm4br12 is CsvConversionError); - test:assertEquals((bm4br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord12Array|Error bm4br12 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord12Array); + test:assertTrue(bm4br12 is Error); + test:assertEquals((bm4br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord12Array|CsvConversionError bm5br12 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord12Array); - test:assertTrue(bm5br12 is CsvConversionError); - test:assertEquals((bm5br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord12Array|Error bm5br12 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord12Array); + test:assertTrue(bm5br12 is Error); + test:assertEquals((bm5br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord13Array|CsvConversionError bm1br13 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord13Array); + BooleanRecord13Array|Error bm1br13 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord13Array); test:assertEquals(bm1br13, [ {b1: true, b2: false, defaultableField: "", nillableField :null}, {b1: true, b2: false, defaultableField: "", nillableField :null} ]); - BooleanRecord13Array|CsvConversionError bm2br13 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord13Array); + BooleanRecord13Array|Error bm2br13 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord13Array); test:assertEquals(bm2br13, [ {b1: true, b2: false, defaultableField: "", nillableField :null}, {b1: true, b2: false, defaultableField: "", nillableField :null} ]); - BooleanRecord13Array|CsvConversionError bm3br13 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord13Array); + BooleanRecord13Array|Error bm3br13 = parseRecordAsRecordType([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|CsvConversionError bm4br13 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord13Array); + BooleanRecord13Array|Error bm4br13 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord13Array); test:assertEquals(bm4br13, [ {defaultableField: "", nillableField :null}, {defaultableField: "", nillableField :null} ]); - BooleanRecord13Array|CsvConversionError bm5br13 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord13Array); + BooleanRecord13Array|Error bm5br13 = parseRecordAsRecordType([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|CsvConversionError bm1br14 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord14Array); - test:assertTrue(bm1br14 is CsvConversionError); - test:assertEquals((bm1br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord14Array|Error bm1br14 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord14Array); + test:assertTrue(bm1br14 is Error); + test:assertEquals((bm1br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord14Array|CsvConversionError bm2br14 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord14Array); - test:assertTrue(bm2br14 is CsvConversionError); - test:assertEquals((bm2br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord14Array|Error bm2br14 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord14Array); + test:assertTrue(bm2br14 is Error); + test:assertEquals((bm2br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord14Array|CsvConversionError bm3br14 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord14Array); - test:assertTrue(bm3br14 is CsvConversionError); - test:assertEquals((bm3br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord14Array|Error bm3br14 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord14Array); + test:assertTrue(bm3br14 is Error); + test:assertEquals((bm3br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord14Array|CsvConversionError bm4br14 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord14Array); - test:assertTrue(bm4br14 is CsvConversionError); - test:assertEquals((bm4br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord14Array|Error bm4br14 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord14Array); + test:assertTrue(bm4br14 is Error); + test:assertEquals((bm4br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord14Array|CsvConversionError bm5br14 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord14Array); - test:assertTrue(bm5br14 is CsvConversionError); - test:assertEquals((bm5br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord14Array|Error bm5br14 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord14Array); + test:assertTrue(bm5br14 is Error); + test:assertEquals((bm5br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord15Array|CsvConversionError bm1br15 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord15Array); - test:assertTrue(bm1br15 is CsvConversionError); - test:assertEquals((bm1br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); + BooleanRecord15Array|Error bm1br15 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord15Array); + test:assertTrue(bm1br15 is Error); + test:assertEquals((bm1br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); - BooleanRecord15Array|CsvConversionError bm3br15 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord15Array); - test:assertTrue(bm3br15 is CsvConversionError); - test:assertEquals((bm3br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); + BooleanRecord15Array|Error bm3br15 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord15Array); + test:assertTrue(bm3br15 is Error); + test:assertEquals((bm3br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); - BooleanRecord15Array|CsvConversionError bm4br15 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord15Array); - test:assertTrue(bm4br15 is CsvConversionError); - test:assertEquals((bm4br15).message(), generateErrorMessageForMissingRequiredField("b1")); + BooleanRecord15Array|Error bm4br15 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord15Array); + test:assertTrue(bm4br15 is Error); + test:assertEquals((bm4br15).message(), generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord16Array|CsvConversionError bm1br16 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord16Array); + BooleanRecord16Array|Error bm1br16 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord16Array); test:assertEquals(bm1br16, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanRecord16Array|CsvConversionError bm2br16 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord16Array); + BooleanRecord16Array|Error bm2br16 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord16Array); test:assertEquals(bm2br16, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} ]); - BooleanRecord16Array|CsvConversionError bm3br16 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord16Array); + BooleanRecord16Array|Error bm3br16 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord16Array); test:assertEquals(bm3br16, [ {b1: true, b2: false, b4: false, b3: ()}, {b1: true, b2: false, b4: false, b3: ()} ]); - BooleanRecord16Array|CsvConversionError bm4br16 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord16Array); + BooleanRecord16Array|Error bm4br16 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord16Array); test:assertEquals(bm4br16, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - BooleanRecord16Array|CsvConversionError bm5br16 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord16Array); + BooleanRecord16Array|Error bm5br16 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord16Array); test:assertEquals(bm5br16, [ {b1: true, b2: false, b4: true, b3: ()}, {b1: true, b2: false, b4: true, b3: ()} ]); - BooleanRecord17Array|CsvConversionError bm1br17 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord17Array); + BooleanRecord17Array|Error bm1br17 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord17Array); test:assertEquals(bm1br17, [ {}, {} ]); - BooleanRecord17Array|CsvConversionError bm2br17 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord17Array); + BooleanRecord17Array|Error bm2br17 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord17Array); test:assertEquals(bm2br17, [ {}, {} ]); - BooleanRecord17Array|CsvConversionError bm3br17 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord17Array); + BooleanRecord17Array|Error bm3br17 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord17Array); test:assertEquals(bm3br17, [ {i1: 1}, {i1: 1} ]); - BooleanRecord17Array|CsvConversionError bm4br17 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord17Array); + BooleanRecord17Array|Error bm4br17 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord17Array); test:assertEquals(bm4br17, [ {}, {} ]); - BooleanRecord17Array|CsvConversionError bm5br17 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord17Array); + BooleanRecord17Array|Error bm5br17 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord17Array); test:assertEquals(bm5br17, [ {}, {} ]); - BooleanRecord18Array|CsvConversionError bm1br18 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord18Array); + BooleanRecord18Array|Error bm1br18 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord18Array); test:assertEquals(bm1br18, [ {b2: false}, {b2: false} ]); - BooleanRecord18Array|CsvConversionError bm2br18 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord18Array); + BooleanRecord18Array|Error bm2br18 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord18Array); test:assertEquals(bm2br18, [ {b2: false, b3: (), n1: (), n3: ()}, {b2: false, b3: (), n1: (), n3: ()} ]); - BooleanRecord18Array|CsvConversionError bm3br18 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord18Array); + BooleanRecord18Array|Error bm3br18 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord18Array); test:assertEquals(bm3br18, [ {b2: false, b3: (), i1: 1}, {b2: false, b3: (), i1: 1} ]); - BooleanRecord18Array|CsvConversionError bm4br18 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord18Array); - test:assertTrue(bm4br18 is CsvConversionError); - test:assertEquals((bm4br18).message(), generateErrorMessageForMissingRequiredField("b2")); + BooleanRecord18Array|Error bm4br18 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord18Array); + test:assertTrue(bm4br18 is Error); + test:assertEquals((bm4br18).message(), generateErrorMessageForMissingRequiredField("b2")); - BooleanRecord18Array|CsvConversionError bm5br18 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord18Array); + BooleanRecord18Array|Error bm5br18 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord18Array); test:assertEquals(bm5br18, [ {b2: false, b3: ()}, {b2: false, b3: ()} @@ -462,270 +462,270 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { @test:Config {enable} function testFromCsvWithTypeForMapAndMapAsExpectedType() { - BooleanMapArray|CsvConversionError bm1bma = parseRecordAsRecordType([bm1, bm1], {}, BooleanMapArray); + BooleanMapArray|Error bm1bma = parseRecordAsRecordType([bm1, bm1], {}, BooleanMapArray); test:assertEquals(bm1bma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanMapArray|CsvConversionError bm2bma = parseRecordAsRecordType([bm2, bm2], {}, BooleanMapArray); + BooleanMapArray|Error bm2bma = parseRecordAsRecordType([bm2, bm2], {}, BooleanMapArray); test:assertEquals(bm2bma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanMapArray|CsvConversionError bm3bma = parseRecordAsRecordType([bm3, bm3], {}, BooleanMapArray); + BooleanMapArray|Error bm3bma = parseRecordAsRecordType([bm3, bm3], {}, BooleanMapArray); test:assertEquals(bm3bma, [ {b1: true, b2: false, b4: false}, {b1: true, b2: false, b4: false} ]); - BooleanMapArray|CsvConversionError bm4bma = parseRecordAsRecordType([bm4, bm4], {}, BooleanMapArray); + BooleanMapArray|Error bm4bma = parseRecordAsRecordType([bm4, bm4], {}, BooleanMapArray); test:assertEquals(bm4bma, [ {}, {} ]); - BooleanMapArray|CsvConversionError bm5bma = parseRecordAsRecordType([bm5, bm5], {}, BooleanMapArray); + BooleanMapArray|Error bm5bma = parseRecordAsRecordType([bm5, bm5], {}, BooleanMapArray); test:assertEquals(bm5bma, [ {b1: true, b2: false, b4: true}, {b1: true, b2: false, b4: true} ]); - NillableBooleanMapArray|CsvConversionError bm1nbma = parseRecordAsRecordType([bm1, bm1], {}, NillableBooleanMapArray); + NillableBooleanMapArray|Error bm1nbma = parseRecordAsRecordType([bm1, bm1], {}, NillableBooleanMapArray); test:assertEquals(bm1nbma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - NillableBooleanMapArray|CsvConversionError bm2nbma = parseRecordAsRecordType([bm2, bm2], {}, NillableBooleanMapArray); + NillableBooleanMapArray|Error bm2nbma = parseRecordAsRecordType([bm2, bm2], {}, NillableBooleanMapArray); test:assertEquals(bm2nbma, [ {b1: true, b2: false, b3:(), n1: (), n3: ()}, {b1: true, b2: false, b3:(), n1: (), n3: ()} ]); - NillableBooleanMapArray|CsvConversionError bm3nbma = parseRecordAsRecordType([bm3, bm3], {}, NillableBooleanMapArray); + NillableBooleanMapArray|Error bm3nbma = parseRecordAsRecordType([bm3, bm3], {}, NillableBooleanMapArray); test:assertEquals(bm3nbma, [ {b1: true, b2: false, b3:(), b4: false}, {b1: true, b2: false, b3:(), b4: false} ]); - NillableBooleanMapArray|CsvConversionError bm4nbma = parseRecordAsRecordType([bm4, bm4], {}, NillableBooleanMapArray); + NillableBooleanMapArray|Error bm4nbma = parseRecordAsRecordType([bm4, bm4], {}, NillableBooleanMapArray); test:assertEquals(bm4nbma, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - NillableBooleanMapArray|CsvConversionError bm5nbma = parseRecordAsRecordType([bm5, bm5], {}, NillableBooleanMapArray); + NillableBooleanMapArray|Error bm5nbma = parseRecordAsRecordType([bm5, bm5], {}, NillableBooleanMapArray); test:assertEquals(bm5nbma, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - NillableIntUnionBooleanMapArray|CsvConversionError bm1niubma = parseRecordAsRecordType([bm1, bm1], {}, NillableIntUnionBooleanMapArray); + NillableIntUnionBooleanMapArray|Error bm1niubma = parseRecordAsRecordType([bm1, bm1], {}, NillableIntUnionBooleanMapArray); test:assertEquals(bm1niubma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - NillableIntUnionBooleanMapArray|CsvConversionError bm2niubma = parseRecordAsRecordType([bm2, bm2], {}, NillableIntUnionBooleanMapArray); + NillableIntUnionBooleanMapArray|Error bm2niubma = parseRecordAsRecordType([bm2, bm2], {}, NillableIntUnionBooleanMapArray); test:assertEquals(bm2niubma, [ {b1: true, b2: false, b3:(), n1: (), n3: ()}, {b1: true, b2: false, b3:(), n1: (), n3: ()} ]); - NillableIntUnionBooleanMapArray|CsvConversionError bm3niubma = parseRecordAsRecordType([bm3, bm3], {}, NillableIntUnionBooleanMapArray); + NillableIntUnionBooleanMapArray|Error bm3niubma = parseRecordAsRecordType([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|CsvConversionError bm4niubma = parseRecordAsRecordType([bm4, bm4], {}, NillableIntUnionBooleanMapArray); + NillableIntUnionBooleanMapArray|Error bm4niubma = parseRecordAsRecordType([bm4, bm4], {}, NillableIntUnionBooleanMapArray); test:assertEquals(bm4niubma, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - NillableIntUnionBooleanMapArray|CsvConversionError bm5niubma = parseRecordAsRecordType([bm5, bm5], {}, NillableIntUnionBooleanMapArray); + NillableIntUnionBooleanMapArray|Error bm5niubma = parseRecordAsRecordType([bm5, bm5], {}, NillableIntUnionBooleanMapArray); test:assertEquals(bm5niubma, [ {b1: true, b2: false, b3: (), b4: true}, {b1: true, b2: false, b3: (), b4: true} ]); - IntUnionBooleanMapArray|CsvConversionError bm1iubma = parseRecordAsRecordType([bm1, bm1], {}, IntUnionBooleanMapArray); + IntUnionBooleanMapArray|Error bm1iubma = parseRecordAsRecordType([bm1, bm1], {}, IntUnionBooleanMapArray); test:assertEquals(bm1iubma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - IntUnionBooleanMapArray|CsvConversionError bm2iubma = parseRecordAsRecordType([bm2, bm2], {}, IntUnionBooleanMapArray); + IntUnionBooleanMapArray|Error bm2iubma = parseRecordAsRecordType([bm2, bm2], {}, IntUnionBooleanMapArray); test:assertEquals(bm2iubma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - IntUnionBooleanMapArray|CsvConversionError bm3iubma = parseRecordAsRecordType([bm3, bm3], {}, IntUnionBooleanMapArray); + IntUnionBooleanMapArray|Error bm3iubma = parseRecordAsRecordType([bm3, bm3], {}, IntUnionBooleanMapArray); test:assertEquals(bm3iubma, [ {b1: true, b2: false, b4: false, i1: 1}, {b1: true, b2: false, b4: false, i1: 1} ]); - IntUnionBooleanMapArray|CsvConversionError bm4iubma = parseRecordAsRecordType([bm4, bm4], {}, IntUnionBooleanMapArray); + IntUnionBooleanMapArray|Error bm4iubma = parseRecordAsRecordType([bm4, bm4], {}, IntUnionBooleanMapArray); test:assertEquals(bm4iubma, [ {}, {} ]); - IntUnionBooleanMapArray|CsvConversionError bm5iubma = parseRecordAsRecordType([bm5, bm5], {}, IntUnionBooleanMapArray); + IntUnionBooleanMapArray|Error bm5iubma = parseRecordAsRecordType([bm5, bm5], {}, IntUnionBooleanMapArray); test:assertEquals(bm5iubma, [ {b1: true, b2: false, b4: true}, {b1: true, b2: false, b4: true} ]); - NilMapArray|CsvConversionError bm1nma = parseRecordAsRecordType([bm1, bm1], {}, NilMapArray); + NilMapArray|Error bm1nma = parseRecordAsRecordType([bm1, bm1], {}, NilMapArray); test:assertEquals(bm1nma, [ {}, {} ]); - NilMapArray|CsvConversionError bm2nma = parseRecordAsRecordType([bm2, bm2], {}, NilMapArray); + NilMapArray|Error bm2nma = parseRecordAsRecordType([bm2, bm2], {}, NilMapArray); test:assertEquals(bm2nma, [ {n1: (), n3: (), b3: ()}, {n1: (), n3: (), b3: ()} ]); - NilMapArray|CsvConversionError bm3nma = parseRecordAsRecordType([bm3, bm3], {}, NilMapArray); + NilMapArray|Error bm3nma = parseRecordAsRecordType([bm3, bm3], {}, NilMapArray); test:assertEquals(bm3nma, [ {b3: ()}, {b3: ()} ]); - NilMapArray|CsvConversionError bm4nma = parseRecordAsRecordType([bm4, bm4], {}, NilMapArray); + NilMapArray|Error bm4nma = parseRecordAsRecordType([bm4, bm4], {}, NilMapArray); test:assertEquals(bm4nma, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - NilMapArray|CsvConversionError bm5nma = parseRecordAsRecordType([bm5, bm5], {}, NilMapArray); + NilMapArray|Error bm5nma = parseRecordAsRecordType([bm5, bm5], {}, NilMapArray); test:assertEquals(bm5nma, [ {b3: ()}, {b3: ()} ]); - JsonMapArray|CsvConversionError bm1jma = parseRecordAsRecordType([bm1, bm1], {}, JsonMapArray); + JsonMapArray|Error bm1jma = parseRecordAsRecordType([bm1, bm1], {}, JsonMapArray); test:assertEquals(bm1jma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - JsonMapArray|CsvConversionError bm2jma = parseRecordAsRecordType([bm2, bm2], {}, JsonMapArray); + JsonMapArray|Error bm2jma = parseRecordAsRecordType([bm2, bm2], {}, JsonMapArray); test:assertEquals(bm2jma, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} ]); - JsonMapArray|CsvConversionError bm3jma = parseRecordAsRecordType([bm3, bm3], {}, JsonMapArray); + JsonMapArray|Error bm3jma = parseRecordAsRecordType([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|CsvConversionError bm4jma = parseRecordAsRecordType([bm4, bm4], {}, JsonMapArray); + JsonMapArray|Error bm4jma = parseRecordAsRecordType([bm4, bm4], {}, JsonMapArray); test:assertEquals(bm4jma, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - JsonMapArray|CsvConversionError bm5jma = parseRecordAsRecordType([bm5, bm5], {}, JsonMapArray); + JsonMapArray|Error bm5jma = parseRecordAsRecordType([bm5, bm5], {}, JsonMapArray); test:assertEquals(bm5jma, [ {b1: true, b2: false, b4: true, b3: ()}, {b1: true, b2: false, b4: true, b3: ()} ]); - AnydataMapArray|CsvConversionError bm1anydma = parseRecordAsRecordType([bm1, bm1], {}, AnydataMapArray); + AnydataMapArray|Error bm1anydma = parseRecordAsRecordType([bm1, bm1], {}, AnydataMapArray); test:assertEquals(bm1anydma, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - AnydataMapArray|CsvConversionError bm2anydma = parseRecordAsRecordType([bm2, bm2], {}, AnydataMapArray); + AnydataMapArray|Error bm2anydma = parseRecordAsRecordType([bm2, bm2], {}, AnydataMapArray); test:assertEquals(bm2anydma, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} ]); - AnydataMapArray|CsvConversionError bm3anydma = parseRecordAsRecordType([bm3, bm3], {}, AnydataMapArray); + AnydataMapArray|Error bm3anydma = parseRecordAsRecordType([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|CsvConversionError bm4anydma = parseRecordAsRecordType([bm4, bm4], {}, AnydataMapArray); + AnydataMapArray|Error bm4anydma = parseRecordAsRecordType([bm4, bm4], {}, AnydataMapArray); test:assertEquals(bm4anydma, [ {n1: (), n3: ()}, {n1: (), n3: ()} ]); - AnydataMapArray|CsvConversionError bm5anydma = parseRecordAsRecordType([bm5, bm5], {}, AnydataMapArray); + AnydataMapArray|Error bm5anydma = parseRecordAsRecordType([bm5, bm5], {}, AnydataMapArray); test:assertEquals(bm5anydma, [ {b1: true, b2: false, b4: true, b3: ()}, {b1: true, b2: false, b4: true, b3: ()} ]); - CustomMapArray|CsvConversionError bm1cma = parseRecordAsRecordType([bm1, bm1], {}, CustomMapArray); + CustomMapArray|Error bm1cma = parseRecordAsRecordType([bm1, bm1], {}, CustomMapArray); test:assertEquals(bm1cma, [ {}, {} ]); - CustomMapArray|CsvConversionError bm2cma = parseRecordAsRecordType([bm2, bm2], {}, CustomMapArray); + CustomMapArray|Error bm2cma = parseRecordAsRecordType([bm2, bm2], {}, CustomMapArray); test:assertEquals(bm2cma, [ {}, {} ]); - CustomMapArray|CsvConversionError bm3cma = parseRecordAsRecordType([bm3, bm3], {}, CustomMapArray); + CustomMapArray|Error bm3cma = parseRecordAsRecordType([bm3, bm3], {}, CustomMapArray); test:assertEquals(bm3cma, [ {i1: 1}, {i1: 1} ]); - CustomMapArray|CsvConversionError bm4cma = parseRecordAsRecordType([bm4, bm4], {}, CustomMapArray); + CustomMapArray|Error bm4cma = parseRecordAsRecordType([bm4, bm4], {}, CustomMapArray); test:assertEquals(bm4cma, [ {}, {} ]); - CustomMapArray|CsvConversionError bm5cma = parseRecordAsRecordType([bm5, bm5], {}, CustomMapArray); + CustomMapArray|Error bm5cma = parseRecordAsRecordType([bm5, bm5], {}, CustomMapArray); test:assertEquals(bm5cma, [ {}, {} ]); - StringMapArray|CsvConversionError bm1sma = parseRecordAsRecordType([bm1, bm1], {}, StringMapArray); + StringMapArray|Error bm1sma = parseRecordAsRecordType([bm1, bm1], {}, StringMapArray); test:assertEquals(bm1sma, [ {}, {} ]); - StringMapArray|CsvConversionError bm2sma = parseRecordAsRecordType([bm2, bm2], {}, StringMapArray); + StringMapArray|Error bm2sma = parseRecordAsRecordType([bm2, bm2], {}, StringMapArray); test:assertEquals(bm2sma, [ {}, {} ]); - StringMapArray|CsvConversionError bm3sma = parseRecordAsRecordType([bm3, bm3], {}, StringMapArray); + StringMapArray|Error bm3sma = parseRecordAsRecordType([bm3, bm3], {}, StringMapArray); test:assertEquals(bm3sma, [ {}, {} ]); - StringMapArray|CsvConversionError bm4sma = parseRecordAsRecordType([bm4, bm4], {}, StringMapArray); + StringMapArray|Error bm4sma = parseRecordAsRecordType([bm4, bm4], {}, StringMapArray); test:assertEquals(bm4sma, [ {}, {} ]); - StringMapArray|CsvConversionError bm5sma = parseRecordAsRecordType([bm5, bm5], {}, StringMapArray); + StringMapArray|Error bm5sma = parseRecordAsRecordType([bm5, bm5], {}, StringMapArray); test:assertEquals(bm5sma, [ {}, {} diff --git a/ballerina/tests/parse_string_compatibality_test.bal b/ballerina/tests/parse_string_compatibality_test.bal index 02e6ab5..9e67d38 100644 --- a/ballerina/tests/parse_string_compatibality_test.bal +++ b/ballerina/tests/parse_string_compatibality_test.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); // test:assertEquals(csvb4br1, [ // {b1: true, b2: "()", b3: (), b4: false}, // {b1: true, b2: "()", b3: (), b4: false} @@ -24,61 +24,61 @@ function testFromCsvStringWithTypeCompatibility() { ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3} `; - AnydataArray1Array|CsvConversionError v3anyd1a = parseStringToList(value); + AnydataArray1Array|Error v3anyd1a = parseStringToList(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|CsvConversionError vcr27a = parseStringToRecord(value, {}, CustomRecord27Array); + CustomRecord27Array|Error vcr27a = parseStringToRecord(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|CsvConversionError v2cr27a = parseStringToRecord(value2, {}, CustomRecord27Array); + CustomRecord27Array|Error v2cr27a = parseStringToRecord(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|CsvConversionError v3cr27a = parseStringToRecord(value3, {}); + CustomRecord27Array|Error v3cr27a = parseStringToRecord(value3, {}); test:assertEquals(v3cr27a, [ {i1, s1, b1, n1, f1, d1, a1: 2.234, j1: b1, defaultableField: "", nillableField: null, s2, s3} ]); - AnydataMapArray|CsvConversionError vanydma = parseStringToRecord(value); + AnydataMapArray|Error vanydma = parseStringToRecord(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|CsvConversionError vjma = parseStringToRecord(value); + JsonMapArray|Error vjma = parseStringToRecord(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|CsvConversionError vsma = parseStringToRecord(value); + StringMapArray|Error vsma = parseStringToRecord(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|CsvConversionError v2ct7a = parseStringToList(value2); + CustomTuple7Array|Error v2ct7a = parseStringToList(value2); test:assertEquals(v2ct7a, [ [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3, "false", "-3.21"] ]); - CustomTuple7Array|CsvConversionError v3ct7a = parseStringToList(value3); + CustomTuple7Array|Error v3ct7a = parseStringToList(value3); test:assertEquals(v3ct7a, [ [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3] ]); - // CustomTuple8Array|CsvConversionError v2ct8a = fromCsvStringWithType(value2); - // test:assertTrue(v2ct8a is CsvConversionError); - // test:assertEquals((v2ct8a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "int")); + // CustomTuple8Array|Error v2ct8a = fromCsvStringWithType(value2); + // test:assertTrue(v2ct8a is Error); + // test:assertEquals((v2ct8a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "int")); - [float, decimal, string][]|CsvConversionError mrrta = parseStringToList(string `a, b,c + [float, decimal, string][]|Error mrrta = parseStringToList(string `a, b,c 1.23, 1.23, 1.23 0,0,0 0.0,0.0,0.0 @@ -90,7 +90,7 @@ function testFromCsvStringWithTypeCompatibility() { [-1.2, -1.2, "-1.2"] ]); - [float, decimal, string, int][]|CsvConversionError m2rrta = parseStringToList(string `a, b,c,d + [float, decimal, string, int][]|Error m2rrta = parseStringToList(string `a, b,c,d 1, 1, 1,1 0,0,0,0 -1,-1,-1,-1`); @@ -100,12 +100,12 @@ function testFromCsvStringWithTypeCompatibility() { [-1, -1, "-1", -1] ]); - [int...][]|CsvConversionError m3rrta = parseStringToList(string `a, b,c,d + [int...][]|Error m3rrta = parseStringToList(string `a, b,c,d 1.2, abc, true,1.0`); - test:assertTrue(m3rrta is CsvConversionError); - test:assertEquals((m3rrta).message(), generateErrorMessageForInvalidCast("1.2", "int")); + test:assertTrue(m3rrta is Error); + test:assertEquals((m3rrta).message(), generateErrorMessageForInvalidCast("1.2", "int")); - [boolean|int, int|boolean][]|CsvConversionError m4rrta = parseStringToList(string `a, b + [boolean|int, int|boolean][]|Error m4rrta = parseStringToList(string `a, b 1, 1 0,0`); test:assertEquals(m4rrta, [ @@ -113,7 +113,7 @@ function testFromCsvStringWithTypeCompatibility() { [0, 0] ]); - record {|int...;|}[]|CsvConversionError irrma = parseStringToRecord(string ` + record {|int...;|}[]|Error irrma = parseStringToRecord(string ` a, b, c 1, a, 2.3 1, -2, true @@ -124,7 +124,7 @@ function testFromCsvStringWithTypeCompatibility() { {b: i2} ]); - record {|()...;|}[]|CsvConversionError nrrma = parseStringToRecord(string ` + record {|()...;|}[]|Error nrrma = parseStringToRecord(string ` a, b, c 1, a, () 1, null, () @@ -135,7 +135,7 @@ function testFromCsvStringWithTypeCompatibility() { {} ]); - record {|decimal...;|}[]|CsvConversionError drra = parseStringToRecord(string `a, b, c + record {|decimal...;|}[]|Error drra = parseStringToRecord(string `a, b, c 2.234, invalid , 1 ${f2}, 0, 2.3d invalid, ${d2}, ${f3}`); @@ -146,7 +146,7 @@ function testFromCsvStringWithTypeCompatibility() { {b: -3.21d, c: f3} ]); - record {|string...;|}[]|CsvConversionError srra = parseStringToRecord(string `a, b, c + record {|string...;|}[]|Error srra = parseStringToRecord(string `a, b, c 1, a, 2.3 1, -2, true hello, -2, hello`); @@ -157,7 +157,7 @@ function testFromCsvStringWithTypeCompatibility() { {a: "hello", b: "-2", c: "hello"} ]); - record {|float...;|}[]|CsvConversionError frra = parseStringToRecord(string `a, b, c + record {|float...;|}[]|Error frra = parseStringToRecord(string `a, b, c 1.2, invalid , 1 ${d2}, ${d3}, true ${d4}, ${f2}, 0.0`); @@ -167,7 +167,7 @@ function testFromCsvStringWithTypeCompatibility() { {a: d4, b: f2, c: 0.0} ]); - record {float a; decimal b; string c;}[]|CsvConversionError mrra = parseStringToRecord(string `a, b,c + record {float a; decimal b; string c;}[]|Error mrra = parseStringToRecord(string `a, b,c 1.23, 1.23, 1.23 0,0,0 0.0,0.0,0.0 @@ -179,7 +179,7 @@ function testFromCsvStringWithTypeCompatibility() { {a: -1.2, b: -1.2, c: "-1.2"} ]); - record {|float a; decimal b; string c; int d;|}[]|CsvConversionError m2rra = parseStringToRecord(string `a, b,c,d + record {|float a; decimal b; string c; int d;|}[]|Error m2rra = parseStringToRecord(string `a, b,c,d 1, 1, 1,1 0,0,0,0 -1,-1,-1,-1`); @@ -189,8 +189,8 @@ function testFromCsvStringWithTypeCompatibility() { {a: -1, b: -1, c: "-1", d: -1} ]); - record {int d;}[]|CsvConversionError m3rra = parseStringToRecord(string `a, b,c,d + record {int d;}[]|Error m3rra = parseStringToRecord(string `a, b,c,d 1.2, abc, true,1.0`); - test:assertTrue(m3rra is CsvConversionError); - test:assertEquals((m3rra).message(), generateErrorMessageForInvalidCast("1.0", "int")); + test:assertTrue(m3rra is Error); + test:assertEquals((m3rra).message(), generateErrorMessageForInvalidCast("1.0", "int")); } \ No newline at end of file diff --git a/ballerina/tests/parse_string_to_array_test.bal b/ballerina/tests/parse_string_to_array_test.bal index f361a91..eaeee3e 100644 --- a/ballerina/tests/parse_string_to_array_test.bal +++ b/ballerina/tests/parse_string_to_array_test.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); // test:assertEquals(csvb4br1, [ // {b1: true, b2: "()", b3: (), b4: false}, // {b1: true, b2: "()", b3: (), b4: false} @@ -13,302 +13,302 @@ import ballerina/test; @test:Config {enable} function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { - BooleanArrayArray|CsvConversionError cv1baa = parseStringToList(csvStringWithBooleanValues1); + BooleanArrayArray|Error cv1baa = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cv1baa, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - BooleanArrayArray|CsvConversionError cv2baa = parseStringToList(csvStringWithBooleanValues2); + BooleanArrayArray|Error cv2baa = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cv2baa, [ [true, false, true, false, true], [true, false, true, false, true] ]); - BooleanArrayArray|CsvConversionError cv3baa = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cv3baa is CsvConversionError); - test:assertEquals((cv3baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanArrayArray|Error cv3baa = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cv3baa is Error); + test:assertEquals((cv3baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanArrayArray|CsvConversionError cv4baa = parseStringToList(csvStringWithBooleanValues4); - test:assertTrue(cv4baa is CsvConversionError); - test:assertEquals((cv4baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanArrayArray|Error cv4baa = parseStringToList(csvStringWithBooleanValues4); + test:assertTrue(cv4baa is Error); + test:assertEquals((cv4baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanArrayArray|CsvConversionError cv5baa = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cv5baa is CsvConversionError); - test:assertEquals((cv5baa).message(), generateErrorMessageForInvalidCast("2", "boolean")); + BooleanArrayArray|Error cv5baa = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cv5baa is Error); + test:assertEquals((cv5baa).message(), generateErrorMessageForInvalidCast("2", "boolean")); - BooleanArrayArray|CsvConversionError cv6baa = parseStringToList(csvStringWithBooleanValues6); - test:assertTrue(cv6baa is CsvConversionError); - test:assertEquals((cv6baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanArrayArray|Error cv6baa = parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cv6baa is Error); + test:assertEquals((cv6baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanArrayArray|CsvConversionError cv7baa = parseStringToList(csvStringWithBooleanValues7); - test:assertTrue(cv7baa is CsvConversionError); - test:assertEquals((cv7baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanArrayArray|Error cv7baa = parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cv7baa is Error); + test:assertEquals((cv7baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - NillableBooleanArrayArray|CsvConversionError cv1nbaa = parseStringToList(csvStringWithBooleanValues1); + NillableBooleanArrayArray|Error cv1nbaa = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cv1nbaa, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - NillableBooleanArrayArray|CsvConversionError cv2nbaa = parseStringToList(csvStringWithBooleanValues2); + NillableBooleanArrayArray|Error cv2nbaa = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cv2nbaa, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableBooleanArrayArray|CsvConversionError cv3nbaa = parseStringToList(csvStringWithBooleanValues3); + NillableBooleanArrayArray|Error cv3nbaa = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cv3nbaa, [ [true, false, true], [true, false, ()], [true, true, false] ]); - NillableBooleanArrayArray|CsvConversionError cv4nbaa = parseStringToList(csvStringWithBooleanValues4); + NillableBooleanArrayArray|Error cv4nbaa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4nbaa, [ [true, (), (), false], [true, (), (), false] ]); - NillableBooleanArrayArray|CsvConversionError cv5nbaa = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cv5nbaa is CsvConversionError); - test:assertEquals((cv5nbaa).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + NillableBooleanArrayArray|Error cv5nbaa = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cv5nbaa is Error); + test:assertEquals((cv5nbaa).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - NillableBooleanArrayArray|CsvConversionError cv6nbaa = parseStringToList(csvStringWithBooleanValues6); + NillableBooleanArrayArray|Error cv6nbaa = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cv6nbaa, [ [(), ()] ]); - NillableBooleanArrayArray|CsvConversionError cv7nbaa = parseStringToList(csvStringWithBooleanValues7); + NillableBooleanArrayArray|Error cv7nbaa = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cv7nbaa, [ [b1, b2, (), b4] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv1niubaa = parseStringToList(csvStringWithBooleanValues1); + NillableIntOrUnionBooleanArrayArray|Error cv1niubaa = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cv1niubaa, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv2niubaa = parseStringToList(csvStringWithBooleanValues2); + NillableIntOrUnionBooleanArrayArray|Error cv2niubaa = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cv2niubaa, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv3niubaa = parseStringToList(csvStringWithBooleanValues3); + NillableIntOrUnionBooleanArrayArray|Error cv3niubaa = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cv3niubaa, [ [true, false, true], [true, false, ()], [true, true, false] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv4niubaa = parseStringToList(csvStringWithBooleanValues4); + NillableIntOrUnionBooleanArrayArray|Error cv4niubaa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4niubaa, [ [true, (), (), false], [true, (), (), false] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv5niubaa = parseStringToList(csvStringWithBooleanValues5); + NillableIntOrUnionBooleanArrayArray|Error cv5niubaa = parseStringToList(csvStringWithBooleanValues5); test:assertEquals(cv5niubaa, [ [true, false, true, 2], [true, false, true, 3] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv6niubaa = parseStringToList(csvStringWithBooleanValues6); + NillableIntOrUnionBooleanArrayArray|Error cv6niubaa = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cv6niubaa, [ [(), ()] ]); - NillableIntOrUnionBooleanArrayArray|CsvConversionError cv7niubaa = parseStringToList(csvStringWithBooleanValues7); + NillableIntOrUnionBooleanArrayArray|Error cv7niubaa = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cv7niubaa, [ [b1, b2, (), b4] ]); - StringArray1Array|CsvConversionError cv1saa = parseStringToList(csvStringWithBooleanValues1); + StringArray1Array|Error cv1saa = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cv1saa, [ ["true", "false", "true", "false"], ["true", "false", "true", "false"], ["true", "false", "true", "false"] ]); - StringArray1Array|CsvConversionError cv2saa = parseStringToList(csvStringWithBooleanValues2); + StringArray1Array|Error cv2saa = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cv2saa, [ ["true", "false", "true", "false", "true"], ["true", "false", "true", "false", "true"] ]); - StringArray1Array|CsvConversionError cv3saa = parseStringToList(csvStringWithBooleanValues3); + StringArray1Array|Error cv3saa = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cv3saa, [ ["true", "false", "true"], ["TRUE", "FALSE", "()"], ["true", "true", "FALSE"] ]); - StringArray1Array|CsvConversionError cv4saa = parseStringToList(csvStringWithBooleanValues4); + StringArray1Array|Error cv4saa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4saa, [ ["true", "()", "()", "false"], ["true", "()", "null", "false"] ]); - StringArray1Array|CsvConversionError cv5saa = parseStringToList(csvStringWithBooleanValues5); + StringArray1Array|Error cv5saa = parseStringToList(csvStringWithBooleanValues5); test:assertEquals(cv5saa, [ ["true", "false", "true", "2"], ["true", "false", "true", "3"] ]); - StringArray1Array|CsvConversionError cv6saa = parseStringToList(csvStringWithBooleanValues6); + StringArray1Array|Error cv6saa = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cv6saa, [ ["()", "()"] ]); - StringArray1Array|CsvConversionError cv7saa = parseStringToList(csvStringWithBooleanValues7); + StringArray1Array|Error cv7saa = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cv7saa, [ ["true", "false", "()", "false"] ]); - StringArray2Array|CsvConversionError cv1s2aa = parseStringToList(csvStringWithBooleanValues1); + StringArray2Array|Error cv1s2aa = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cv1s2aa, [ ["true", "false"], ["true", "false"], ["true", "false"] ]); - StringArray2Array|CsvConversionError cv2s2aa = parseStringToList(csvStringWithBooleanValues2); + StringArray2Array|Error cv2s2aa = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cv2s2aa, [ ["true", "false"], ["true", "false"] ]); - StringArray2Array|CsvConversionError cv3s2aa = parseStringToList(csvStringWithBooleanValues3); + StringArray2Array|Error cv3s2aa = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cv3s2aa, [ ["true", "false"], ["TRUE", "FALSE"], ["true", "true"] ]); - StringArray2Array|CsvConversionError cv4s2aa = parseStringToList(csvStringWithBooleanValues4); + StringArray2Array|Error cv4s2aa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4s2aa, [ ["true", "()"], ["true", "()"] ]); - StringArray2Array|CsvConversionError cv5s2aa = parseStringToList(csvStringWithBooleanValues5); + StringArray2Array|Error cv5s2aa = parseStringToList(csvStringWithBooleanValues5); test:assertEquals(cv5s2aa, [ ["true", "false"], ["true", "false"] ]); - StringArray2Array|CsvConversionError cv6s2aa = parseStringToList(csvStringWithBooleanValues6); + StringArray2Array|Error cv6s2aa = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cv6s2aa, [ ["()", "()"] ]); - StringArray2Array|CsvConversionError cv7s2aa = parseStringToList(csvStringWithBooleanValues7); + StringArray2Array|Error cv7s2aa = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cv7s2aa, [ ["true", "false"] ]); - JsonArray1Array|CsvConversionError cv1jaa = parseStringToList(csvStringWithBooleanValues1); + JsonArray1Array|Error cv1jaa = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cv1jaa, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - JsonArray1Array|CsvConversionError cv2jaa = parseStringToList(csvStringWithBooleanValues2); + JsonArray1Array|Error cv2jaa = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cv2jaa, [ [true, false, true, false, true], [true, false, true, false, true] ]); - JsonArray1Array|CsvConversionError cv3jaa = parseStringToList(csvStringWithBooleanValues3); + JsonArray1Array|Error cv3jaa = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cv3jaa, [ [true, false, true], [true, false, ()], [true, true, false] ]); - JsonArray1Array|CsvConversionError cv4jaa = parseStringToList(csvStringWithBooleanValues4); + JsonArray1Array|Error cv4jaa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4jaa, [ [true, (), (), false], [true, (), (), false] ]); - JsonArray1Array|CsvConversionError cv5jaa = parseStringToList(csvStringWithBooleanValues5); + JsonArray1Array|Error cv5jaa = parseStringToList(csvStringWithBooleanValues5); test:assertEquals(cv5jaa, [ [true, false, true, 2], [true, false, true, 3] ]); - JsonArray1Array|CsvConversionError cv6jaa = parseStringToList(csvStringWithBooleanValues6); + JsonArray1Array|Error cv6jaa = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cv6jaa, [ [(), ()] ]); - JsonArray1Array|CsvConversionError cv7jaa = parseStringToList(csvStringWithBooleanValues7); + JsonArray1Array|Error cv7jaa = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cv7jaa, [ [b1, b2, (), b4] ]); - AnydataArray1Array|CsvConversionError cv1anydaa = parseStringToList(csvStringWithBooleanValues1); + AnydataArray1Array|Error cv1anydaa = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cv1anydaa, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - AnydataArray1Array|CsvConversionError cv2anydaa = parseStringToList(csvStringWithBooleanValues2); + AnydataArray1Array|Error cv2anydaa = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cv2anydaa, [ [true, false, true, false, true], [true, false, true, false, true] ]); - AnydataArray1Array|CsvConversionError cv3anydaa = parseStringToList(csvStringWithBooleanValues3); + AnydataArray1Array|Error cv3anydaa = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cv3anydaa, [ [true, false, true], [true, false, ()], [true, true, false] ]); - AnydataArray1Array|CsvConversionError cv4anydaa = parseStringToList(csvStringWithBooleanValues4); + AnydataArray1Array|Error cv4anydaa = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cv4anydaa, [ [true, (), (), false], [true, (), (), false] ]); - AnydataArray1Array|CsvConversionError cv5anydaa = parseStringToList(csvStringWithBooleanValues5); + AnydataArray1Array|Error cv5anydaa = parseStringToList(csvStringWithBooleanValues5); test:assertEquals(cv5anydaa, [ [true, false, true, 2], [true, false, true, 3] ]); - AnydataArray1Array|CsvConversionError cv6anydaa = parseStringToList(csvStringWithBooleanValues6); + AnydataArray1Array|Error cv6anydaa = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cv6anydaa, [ [(), ()] ]); - AnydataArray1Array|CsvConversionError cv7anydaa = parseStringToList(csvStringWithBooleanValues7); + AnydataArray1Array|Error cv7anydaa = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cv7anydaa, [ [b1, b2, (), b4] ]); - DecimalArray1Array|CsvConversionError cv1daa = parseStringToList(csvStringWithBooleanValues1); - test:assertTrue(cv1daa is CsvConversionError); - test:assertEquals((cv1daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); + DecimalArray1Array|Error cv1daa = parseStringToList(csvStringWithBooleanValues1); + test:assertTrue(cv1daa is Error); + test:assertEquals((cv1daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); - DecimalArray1Array|CsvConversionError cv3daa = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cv3daa is CsvConversionError); - test:assertEquals((cv3daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); + DecimalArray1Array|Error cv3daa = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cv3daa is Error); + test:assertEquals((cv3daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); - DecimalArray1Array|CsvConversionError cv6daa = parseStringToList(csvStringWithBooleanValues6); - test:assertTrue(cv6daa is CsvConversionError); - test:assertEquals((cv6daa).message(), generateErrorMessageForInvalidCast("()", "decimal")); + DecimalArray1Array|Error cv6daa = parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cv6daa is Error); + test:assertEquals((cv6daa).message(), generateErrorMessageForInvalidCast("()", "decimal")); - DecimalArray1Array|CsvConversionError cv7daa = parseStringToList(csvStringWithBooleanValues7); - test:assertTrue(cv7daa is CsvConversionError); - test:assertEquals((cv7daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); + DecimalArray1Array|Error cv7daa = parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cv7daa is Error); + test:assertEquals((cv7daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); } diff --git a/ballerina/tests/parse_string_to_map_tests copy.bal b/ballerina/tests/parse_string_to_map_tests copy.bal index 81e0b2b..58e263f 100644 --- a/ballerina/tests/parse_string_to_map_tests copy.bal +++ b/ballerina/tests/parse_string_to_map_tests copy.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// NillableIntUnionBooleanMapArray|CsvConversionError bv4bniubma = parseStringToRecord(string `a +// NillableIntUnionBooleanMapArray|Error bv4bniubma = parseStringToRecord(string `a // 0`); // test:assertEquals(bv4bniubma, [ // {b1: true, b2: (), b3: (), b4: 0}, @@ -14,396 +14,396 @@ import ballerina/test; @test:Config {enable} function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { - BooleanMapArray|CsvConversionError bv1bma = parseStringToRecord(csvStringWithBooleanValues1); + BooleanMapArray|Error bv1bma = parseStringToRecord(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|CsvConversionError bv2bma = parseStringToRecord(csvStringWithBooleanValues2); + BooleanMapArray|Error bv2bma = parseStringToRecord(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|CsvConversionError bv3bma = parseStringToRecord(csvStringWithBooleanValues3); + BooleanMapArray|Error bv3bma = parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false}, {b1: true, b2: true, b3: false} ]); - BooleanMapArray|CsvConversionError bv4bma = parseStringToRecord(csvStringWithBooleanValues4); + BooleanMapArray|Error bv4bma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bma, [ {b1: true, b4: false}, {b1: true, b4: false} ]); - BooleanMapArray|CsvConversionError bv5bma = parseStringToRecord(csvStringWithBooleanValues5); + BooleanMapArray|Error bv5bma = parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - BooleanMapArray|CsvConversionError bv6bma = parseStringToRecord(csvStringWithBooleanValues6); + BooleanMapArray|Error bv6bma = parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bma, [ {} ]); - BooleanMapArray|CsvConversionError bv7bma = parseStringToRecord(csvStringWithBooleanValues7); + BooleanMapArray|Error bv7bma = parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bma, [ {b1, b2, b4} ]); - NillableBooleanMapArray|CsvConversionError bv1bnbma = parseStringToRecord(csvStringWithBooleanValues1); + NillableBooleanMapArray|Error bv1bnbma = parseStringToRecord(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|CsvConversionError bv2bnbma = parseStringToRecord(csvStringWithBooleanValues2); + NillableBooleanMapArray|Error bv2bnbma = parseStringToRecord(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|CsvConversionError bv3bnbma = parseStringToRecord(csvStringWithBooleanValues3); + NillableBooleanMapArray|Error bv3bnbma = parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bnbma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - NillableBooleanMapArray|CsvConversionError bv4bnbma = parseStringToRecord(csvStringWithBooleanValues4); + NillableBooleanMapArray|Error bv4bnbma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bnbma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - NillableBooleanMapArray|CsvConversionError bv5bnbma = parseStringToRecord(csvStringWithBooleanValues5); + NillableBooleanMapArray|Error bv5bnbma = parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bnbma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - NillableBooleanMapArray|CsvConversionError bv6bnbma = parseStringToRecord(csvStringWithBooleanValues6); + NillableBooleanMapArray|Error bv6bnbma = parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bnbma, [ {b2: (), b3: ()} ]); - NillableBooleanMapArray|CsvConversionError bv7bnbma = parseStringToRecord(csvStringWithBooleanValues7); + NillableBooleanMapArray|Error bv7bnbma = parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bnbma, [ {b1, b2, b3, b4} ]); - NillableIntUnionBooleanMapArray|CsvConversionError bv1bniubma = parseStringToRecord(csvStringWithBooleanValues1); + NillableIntUnionBooleanMapArray|Error bv1bniubma = parseStringToRecord(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|CsvConversionError bv2bniubma = parseStringToRecord(csvStringWithBooleanValues2); + NillableIntUnionBooleanMapArray|Error bv2bniubma = parseStringToRecord(csvStringWithBooleanValues2); test:assertEquals(bv2bniubma, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - NillableIntUnionBooleanMapArray|CsvConversionError bv3bniubma = parseStringToRecord(csvStringWithBooleanValues3); + NillableIntUnionBooleanMapArray|Error bv3bniubma = parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bniubma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - NillableIntUnionBooleanMapArray|CsvConversionError bv4bniubma = parseStringToRecord(csvStringWithBooleanValues4); + NillableIntUnionBooleanMapArray|Error bv4bniubma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bniubma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - NillableIntUnionBooleanMapArray|CsvConversionError bv5bniubma = parseStringToRecord(csvStringWithBooleanValues5); + NillableIntUnionBooleanMapArray|Error bv5bniubma = parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bniubma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - NillableIntUnionBooleanMapArray|CsvConversionError bv6bniubma = parseStringToRecord(csvStringWithBooleanValues6); + NillableIntUnionBooleanMapArray|Error bv6bniubma = parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bniubma, [ {b2: (), b3: ()} ]); - NillableIntUnionBooleanMapArray|CsvConversionError bv7bniubma = parseStringToRecord(csvStringWithBooleanValues7); + NillableIntUnionBooleanMapArray|Error bv7bniubma = parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bniubma, [ {b1, b2, b3, b4} ]); - IntUnionBooleanMapArray|CsvConversionError bv1biubma = parseStringToRecord(csvStringWithBooleanValues1); + IntUnionBooleanMapArray|Error bv1biubma = parseStringToRecord(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|CsvConversionError bv2biubma = parseStringToRecord(csvStringWithBooleanValues2); + IntUnionBooleanMapArray|Error bv2biubma = parseStringToRecord(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|CsvConversionError bv3biubma = parseStringToRecord(csvStringWithBooleanValues3); + IntUnionBooleanMapArray|Error bv3biubma = parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3biubma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false}, {b1: true, b2: true, b3: false} ]); - IntUnionBooleanMapArray|CsvConversionError bv4biubma = parseStringToRecord(csvStringWithBooleanValues4); + IntUnionBooleanMapArray|Error bv4biubma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4biubma, [ {b1: true, b4: false}, {b1: true, b4: false} ]); - IntUnionBooleanMapArray|CsvConversionError bv5biubma = parseStringToRecord(csvStringWithBooleanValues5); + IntUnionBooleanMapArray|Error bv5biubma = parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5biubma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - IntUnionBooleanMapArray|CsvConversionError bv6biubma = parseStringToRecord(csvStringWithBooleanValues6); + IntUnionBooleanMapArray|Error bv6biubma = parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6biubma, [ {} ]); - IntUnionBooleanMapArray|CsvConversionError bv7biubma = parseStringToRecord(csvStringWithBooleanValues7); + IntUnionBooleanMapArray|Error bv7biubma = parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7biubma, [ {b1, b2, b4} ]); - NilMapArray|CsvConversionError bv1bnma = parseStringToRecord(csvStringWithBooleanValues1); + NilMapArray|Error bv1bnma = parseStringToRecord(csvStringWithBooleanValues1); test:assertEquals(bv1bnma, [ {}, {}, {} ]); - NilMapArray|CsvConversionError bv2bnma = parseStringToRecord(csvStringWithBooleanValues2); + NilMapArray|Error bv2bnma = parseStringToRecord(csvStringWithBooleanValues2); test:assertEquals(bv2bnma, [ {}, {} ]); - NilMapArray|CsvConversionError bv3bnma = parseStringToRecord(csvStringWithBooleanValues3); + NilMapArray|Error bv3bnma = parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bnma, [ {}, {b3: ()}, {} ]); - NilMapArray|CsvConversionError bv4bnma = parseStringToRecord(csvStringWithBooleanValues4); + NilMapArray|Error bv4bnma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bnma, [ {b2: (), b3: ()}, {b2: (), b3: ()} ]); - NilMapArray|CsvConversionError bv5bnma = parseStringToRecord(csvStringWithBooleanValues5); + NilMapArray|Error bv5bnma = parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bnma, [ {}, {} ]); - NilMapArray|CsvConversionError bv6bnma = parseStringToRecord(csvStringWithBooleanValues6); + NilMapArray|Error bv6bnma = parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bnma, [ {b2: (), b3: ()} ]); - NilMapArray|CsvConversionError bv7bnma = parseStringToRecord(csvStringWithBooleanValues7); + NilMapArray|Error bv7bnma = parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bnma, [ {b3} ]); - JsonMapArray|CsvConversionError bv1bjma = parseStringToRecord(csvStringWithBooleanValues1); + JsonMapArray|Error bv1bjma = parseStringToRecord(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|CsvConversionError bv2bjma = parseStringToRecord(csvStringWithBooleanValues2); + JsonMapArray|Error bv2bjma = parseStringToRecord(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|CsvConversionError bv3bjma = parseStringToRecord(csvStringWithBooleanValues3); + JsonMapArray|Error bv3bjma = parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bjma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - JsonMapArray|CsvConversionError bv4bjma = parseStringToRecord(csvStringWithBooleanValues4); + JsonMapArray|Error bv4bjma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bjma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - JsonMapArray|CsvConversionError bv5bjma = parseStringToRecord(csvStringWithBooleanValues5); + JsonMapArray|Error bv5bjma = parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bjma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - JsonMapArray|CsvConversionError bv6bjma = parseStringToRecord(csvStringWithBooleanValues6); + JsonMapArray|Error bv6bjma = parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bjma, [ {b2: (), b3: ()} ]); - JsonMapArray|CsvConversionError bv7bjma = parseStringToRecord(csvStringWithBooleanValues7); + JsonMapArray|Error bv7bjma = parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bjma, [ {b1, b2, b3, b4} ]); - AnydataMapArray|CsvConversionError bv1banydma = parseStringToRecord(csvStringWithBooleanValues1); + AnydataMapArray|Error bv1banydma = parseStringToRecord(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|CsvConversionError bv2banydma = parseStringToRecord(csvStringWithBooleanValues2); + AnydataMapArray|Error bv2banydma = parseStringToRecord(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|CsvConversionError bv3banydma = parseStringToRecord(csvStringWithBooleanValues3); + AnydataMapArray|Error bv3banydma = parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3banydma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - AnydataMapArray|CsvConversionError bv4banydma = parseStringToRecord(csvStringWithBooleanValues4); + AnydataMapArray|Error bv4banydma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4banydma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - AnydataMapArray|CsvConversionError bv5banydma = parseStringToRecord(csvStringWithBooleanValues5); + AnydataMapArray|Error bv5banydma = parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5banydma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - AnydataMapArray|CsvConversionError bv6banydma = parseStringToRecord(csvStringWithBooleanValues6); + AnydataMapArray|Error bv6banydma = parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6banydma, [ {b2: (), b3: ()} ]); - AnydataMapArray|CsvConversionError bv7banydma = parseStringToRecord(csvStringWithBooleanValues7); + AnydataMapArray|Error bv7banydma = parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7banydma, [ {b1, b2, b3, b4} ]); - CustomMapArray|CsvConversionError bv1bcma = parseStringToRecord(csvStringWithBooleanValues1); + CustomMapArray|Error bv1bcma = parseStringToRecord(csvStringWithBooleanValues1); test:assertEquals(bv1bcma, [ {b1: "true", b2: "false", b3: "true", b4: "false"}, {b1: "true", b2: "false", b3: "true", b4: "false"}, {b1: "true", b2: "false", b3: "true", b4: "false"} ]); - CustomMapArray|CsvConversionError bv2bcma = parseStringToRecord(csvStringWithBooleanValues2); + CustomMapArray|Error bv2bcma = parseStringToRecord(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|CsvConversionError bv3bcma = parseStringToRecord(csvStringWithBooleanValues3); + CustomMapArray|Error bv3bcma = parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bcma, [ {b1: "true", b2: "false", b3: "true"}, {b1: "TRUE", b2: "FALSE", b3: "()"}, {b1: "true", b2: "true", b3: "FALSE"} ]); - CustomMapArray|CsvConversionError bv4bcma = parseStringToRecord(csvStringWithBooleanValues4); + CustomMapArray|Error bv4bcma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bcma, [ {b1: "true", b2: "()", b3: "()", b4: "false"}, {b1: "true", b2: "()", b3: "null", b4: "false"} ]); - CustomMapArray|CsvConversionError bv5bcma = parseStringToRecord(csvStringWithBooleanValues5); + CustomMapArray|Error bv5bcma = parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bcma, [ {b1: "true", b2: "false", b3: "true", b4: 2}, {b1: "true", b2: "false", b3: "true", b4: 3} ]); - CustomMapArray|CsvConversionError bv6bcma = parseStringToRecord(csvStringWithBooleanValues6); + CustomMapArray|Error bv6bcma = parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bcma, [ {b2: "()", b3: "()"} ]); - CustomMapArray|CsvConversionError bv7bcma = parseStringToRecord(csvStringWithBooleanValues7); + CustomMapArray|Error bv7bcma = parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bcma, [ {b1: "true", b2: "false", b3: "()", b4: "false"} ]); - StringMapArray|CsvConversionError bv1bsma = parseStringToRecord(csvStringWithBooleanValues1); + StringMapArray|Error bv1bsma = parseStringToRecord(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|CsvConversionError bv2bsma = parseStringToRecord(csvStringWithBooleanValues2); + StringMapArray|Error bv2bsma = parseStringToRecord(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|CsvConversionError bv3bsma = parseStringToRecord(csvStringWithBooleanValues3); + StringMapArray|Error bv3bsma = parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bsma, [ {b1: "true", b2: "false", b3: "true"}, {b1: "TRUE", b2: "FALSE", b3: "()"}, {b1: "true", b2: "true", b3: "FALSE"} ]); - StringMapArray|CsvConversionError bv4bsma = parseStringToRecord(csvStringWithBooleanValues4); + StringMapArray|Error bv4bsma = parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bsma, [ {b1: "true", b2: "()", b3: "()", b4: "false"}, {b1: "true", b2: "()", b3: "null", b4: "false"} ]); - StringMapArray|CsvConversionError bv5bsma = parseStringToRecord(csvStringWithBooleanValues5); + StringMapArray|Error bv5bsma = parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bsma, [ {b1: "true", b2: "false", b3: "true", b4: "2"}, {b1: "true", b2: "false", b3: "true", b4: "3"} ]); - StringMapArray|CsvConversionError bv6bsma = parseStringToRecord(csvStringWithBooleanValues6); + StringMapArray|Error bv6bsma = parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bsma, [ {b2: "()", b3: "()"} ]); - StringMapArray|CsvConversionError bv7bsma = parseStringToRecord(csvStringWithBooleanValues7); + StringMapArray|Error bv7bsma = parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bsma, [ {b1: "true", b2: "false", b3: "()", b4: "false"} ]); - DecimalMapArray|CsvConversionError bv1dsma = parseStringToRecord(csvStringWithBooleanValues1); + DecimalMapArray|Error bv1dsma = parseStringToRecord(csvStringWithBooleanValues1); test:assertEquals(bv1dsma, [ {}, {}, {} ]); - DecimalMapArray|CsvConversionError bv6dsma = parseStringToRecord(csvStringWithBooleanValues6); + DecimalMapArray|Error bv6dsma = parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6dsma, [ {} ]); - DecimalMapArray|CsvConversionError bv7dsma = parseStringToRecord(csvStringWithBooleanValues7); + DecimalMapArray|Error bv7dsma = parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7dsma, [ {} ]); diff --git a/ballerina/tests/parse_string_to_record_tests.bal b/ballerina/tests/parse_string_to_record_tests.bal index 782b145..ccb9c56 100644 --- a/ballerina/tests/parse_string_to_record_tests.bal +++ b/ballerina/tests/parse_string_to_record_tests.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); // test:assertEquals(csvb4br1, [ // {b1: true, b2: "()", b3: (), b4: false}, // {b1: true, b2: "()", b3: (), b4: false} @@ -13,484 +13,484 @@ import ballerina/test; @test:Config {enable} function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { - BooleanRecord1Array|CsvConversionError csvb1br1 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord1Array|Error csvb1br1 = parseStringToRecord(csvStringWithBooleanValues1, {}); 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|CsvConversionError csvb2br1 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord1Array|Error csvb2br1 = parseStringToRecord(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|CsvConversionError csvb3br1 = parseStringToRecord(csvStringWithBooleanValues3, {}); - test:assertTrue(csvb3br1 is CsvConversionError); - test:assertEquals((csvb3br1).message(), generateErrorMessageForMissingRequiredField("b4")); + BooleanRecord1Array|Error csvb3br1 = parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertTrue(csvb3br1 is Error); + test:assertEquals((csvb3br1).message(), generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br1, [ {b1: true, b2: "()", b3: (), b4: false}, {b1: true, b2: "()", b3: (), b4: false} ]); - BooleanRecord1Array|CsvConversionError csvb5br1 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertTrue(csvb5br1 is CsvConversionError); - test:assertEquals((csvb5br1).message(), generateErrorMessageForInvalidCast("2", "boolean")); + BooleanRecord1Array|Error csvb5br1 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertTrue(csvb5br1 is Error); + test:assertEquals((csvb5br1).message(), generateErrorMessageForInvalidCast("2", "boolean")); - BooleanRecord1Array|CsvConversionError csvb6br1 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br1 is CsvConversionError); - test:assertEquals((csvb6br1).message(), generateErrorMessageForMissingRequiredField("b4")); + BooleanRecord1Array|Error csvb6br1 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br1 is Error); + test:assertEquals((csvb6br1).message(), generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord1Array|CsvConversionError csvb7br1 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord1Array|Error csvb7br1 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br1, [ {b1, b2, b3: (), b4} ]); - BooleanRecord2Array|CsvConversionError csvb1br2 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord2Array|Error csvb1br2 = parseStringToRecord(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|CsvConversionError csvb2br2 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord2Array|Error csvb2br2 = parseStringToRecord(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br2, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false} ]); - BooleanRecord2Array|CsvConversionError csvb3br2 = parseStringToRecord(csvStringWithBooleanValues3, {}); - test:assertTrue(csvb3br2 is CsvConversionError); - test:assertEquals((csvb3br2).message(), generateErrorMessageForMissingRequiredField("b4")); + BooleanRecord2Array|Error csvb3br2 = parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertTrue(csvb3br2 is Error); + test:assertEquals((csvb3br2).message(), generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord2Array|CsvConversionError csvb4br2 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord2Array|Error csvb4br2 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br2, [ {b1: true, b2: "()", b3: (), b4: false}, {b1: true, b2: "()", b3: (), b4: false} ]); - BooleanRecord2Array|CsvConversionError csvb5br2 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertTrue(csvb5br2 is CsvConversionError); - test:assertEquals((csvb5br2).message(), generateErrorMessageForInvalidCast("2", "boolean")); + BooleanRecord2Array|Error csvb5br2 = parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertTrue(csvb5br2 is Error); + test:assertEquals((csvb5br2).message(), generateErrorMessageForInvalidCast("2", "boolean")); - BooleanRecord2Array|CsvConversionError csvb7br2 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord2Array|Error csvb7br2 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br2, [ {b1, b2, b3: (), b4} ]); - BooleanRecord3Array|CsvConversionError csvb1br3 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord3Array|Error csvb1br3 = parseStringToRecord(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br3, [ {b1: true, b3: true}, {b1: true, b3: true}, {b1: true, b3: true} ]); - BooleanRecord3Array|CsvConversionError csvb2br3 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord3Array|Error csvb2br3 = parseStringToRecord(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br3, [ {b1: true, b3: true}, {b1: true, b3: true} ]); - BooleanRecord3Array|CsvConversionError csvb3br3 = parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord3Array|Error csvb3br3 = parseStringToRecord(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br3, [ {b1: true, b3: true}, {b1: true, b3: ()}, {b1: true, b3: false} ]); - BooleanRecord3Array|CsvConversionError csvb4br3 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord3Array|Error csvb4br3 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br3, [ {b1: true, b3: ()}, {b1: true, b3: ()} ]); - BooleanRecord3Array|CsvConversionError csvb5br3 = parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord3Array|Error csvb5br3 = parseStringToRecord(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br3, [ {b1: true, b3: true}, {b1: true, b3: true} ]); - BooleanRecord3Array|CsvConversionError csvb7br3 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord3Array|Error csvb7br3 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br3, [ {b1, b3: ()} ]); - BooleanRecord4Array|CsvConversionError csvb1br4 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord4Array|Error csvb1br4 = parseStringToRecord(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|CsvConversionError csvb2br4 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord4Array|Error csvb2br4 = parseStringToRecord(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|CsvConversionError csvb3br4 = parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord4Array|Error csvb3br4 = parseStringToRecord(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br4, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: ()}, {b1: true, b2: true, b3: false} ]); - BooleanRecord4Array|CsvConversionError csvb4br4 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord4Array|Error csvb4br4 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br4, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - BooleanRecord4Array|CsvConversionError csvb5br4 = parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord4Array|Error csvb5br4 = parseStringToRecord(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br4, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - BooleanRecord4Array|CsvConversionError csvb7br4 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord4Array|Error csvb7br4 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br4, [ {b1, b2, b3: (), b4} ]); - BooleanRecord5Array|CsvConversionError csvb1br5 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord5Array|Error csvb1br5 = parseStringToRecord(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|CsvConversionError csvb2br5 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord5Array|Error csvb2br5 = parseStringToRecord(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|CsvConversionError csvb3br5 = parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord5Array|Error csvb3br5 = parseStringToRecord(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|CsvConversionError csvb4br5 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord5Array|Error csvb4br5 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br5, [ {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord5Array|CsvConversionError csvb5br5 = parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord5Array|Error csvb5br5 = parseStringToRecord(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|CsvConversionError csvb7br5 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord5Array|Error csvb7br5 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br5, [ {b1, b2, b3: (), b4, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|CsvConversionError csvb1br6 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord6Array|Error csvb1br6 = parseStringToRecord(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br6, [ {b1: true, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b3: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|CsvConversionError csvb2br6 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord6Array|Error csvb2br6 = parseStringToRecord(csvStringWithBooleanValues2, {}); test:assertEquals(csvb2br6, [ {b1: true, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b3: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|CsvConversionError csvb3br6 = parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord6Array|Error csvb3br6 = parseStringToRecord(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br6, [ {b1: true, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b3: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|CsvConversionError csvb4br6 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord6Array|Error csvb4br6 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br6, [ {b1: true, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|CsvConversionError csvb5br6 = parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord6Array|Error csvb5br6 = parseStringToRecord(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br6, [ {b1: true, b3: true, defaultableField: "", nillableField: ()}, {b1: true, b3: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|CsvConversionError csvb7br6 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord6Array|Error csvb7br6 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br6, [ {b1, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord7Array|CsvConversionError csvb1br7 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br7 is CsvConversionError); - test:assertEquals((csvb1br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord7Array|Error csvb1br7 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br7 is Error); + test:assertEquals((csvb1br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord8Array|CsvConversionError csvb1br8 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br8 is CsvConversionError); - test:assertEquals((csvb1br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord8Array|Error csvb1br8 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br8 is Error); + test:assertEquals((csvb1br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord9Array|CsvConversionError csvb1br9 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord9Array|Error csvb1br9 = parseStringToRecord(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|CsvConversionError csvb2br9 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord9Array|Error csvb2br9 = parseStringToRecord(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|CsvConversionError csvb3br9 = parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord9Array|Error csvb3br9 = parseStringToRecord(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br9, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: ()}, {b1: true, b2: true, b3: false} ]); - BooleanRecord9Array|CsvConversionError csvb4br9 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord9Array|Error csvb4br9 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br9, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - BooleanRecord9Array|CsvConversionError csvb5br9 = parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord9Array|Error csvb5br9 = parseStringToRecord(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br9, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - BooleanRecord9Array|CsvConversionError csvb6br9 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br9 is CsvConversionError); - test:assertEquals((csvb6br9).message(), generateErrorMessageForMissingRequiredField("b1")); + BooleanRecord9Array|Error csvb6br9 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br9 is Error); + test:assertEquals((csvb6br9).message(), generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord9Array|CsvConversionError csvb7br9 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord9Array|Error csvb7br9 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br9, [ {b1, b2, b3: (), b4} ]); - BooleanRecord10Array|CsvConversionError csvb1br10 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord10Array|Error csvb1br10 = parseStringToRecord(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|CsvConversionError csvb2br10 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord10Array|Error csvb2br10 = parseStringToRecord(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|CsvConversionError csvb3br10 = parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord10Array|Error csvb3br10 = parseStringToRecord(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br10, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false}, {b1: true, b2: true, b3: false} ]); - BooleanRecord10Array|CsvConversionError csvb4br10 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord10Array|Error csvb4br10 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br10, [ {b1: true, b4: false}, {b1: true, b4: false} ]); - BooleanRecord10Array|CsvConversionError csvb5br10 = parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord10Array|Error csvb5br10 = parseStringToRecord(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br10, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - BooleanRecord10Array|CsvConversionError csvb6br10 = parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord10Array|Error csvb6br10 = parseStringToRecord(csvStringWithBooleanValues6, {}); test:assertEquals(csvb6br10, [ {} ]); - BooleanRecord10Array|CsvConversionError csvb7br10 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord10Array|Error csvb7br10 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br10, [ {b1, b2, b4} ]); - BooleanRecord11Array|CsvConversionError csvb1br11 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord11Array|Error csvb1br11 = parseStringToRecord(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br11, [ {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: ()} ]); - BooleanRecord11Array|CsvConversionError csvb2br11 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord11Array|Error csvb2br11 = parseStringToRecord(csvStringWithBooleanValues2, {}); 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|CsvConversionError csvb3br11 = parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord11Array|Error csvb3br11 = parseStringToRecord(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|CsvConversionError csvb4br11 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord11Array|Error csvb4br11 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br11, [ {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord11Array|CsvConversionError csvb5br11 = parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord11Array|Error csvb5br11 = parseStringToRecord(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br11, [ {b1: true, b2: false, b3: true, b4: "2", defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: "3", defaultableField: "", nillableField: ()} ]); - BooleanRecord11Array|CsvConversionError csvb6br11 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br11 is CsvConversionError); - test:assertEquals((csvb6br11).message(), generateErrorMessageForMissingRequiredField("b1")); + BooleanRecord11Array|Error csvb6br11 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br11 is Error); + test:assertEquals((csvb6br11).message(), generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord11Array|CsvConversionError csvb7br11 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord11Array|Error csvb7br11 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br11, [ {b1, b2, b3, b4, defaultableField: "", nillableField: ()} ]); - BooleanRecord12Array|CsvConversionError csvb1br12 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br12 is CsvConversionError); - test:assertEquals((csvb1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord12Array|Error csvb1br12 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br12 is Error); + test:assertEquals((csvb1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord13Array|CsvConversionError csvb1br13 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord13Array|Error csvb1br13 = parseStringToRecord(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|CsvConversionError csvb2br13 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord13Array|Error csvb2br13 = parseStringToRecord(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|CsvConversionError csvb3br13 = parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord13Array|Error csvb3br13 = parseStringToRecord(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|CsvConversionError csvb4br13 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord13Array|Error csvb4br13 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br13, [ {b1: true, b2: "()", b3: "()", b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: "()", b3: "null", b4: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord13Array|CsvConversionError csvb5br13 = parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord13Array|Error csvb5br13 = parseStringToRecord(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|CsvConversionError csvb6br13 = parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord13Array|Error csvb6br13 = parseStringToRecord(csvStringWithBooleanValues6, {}); test:assertEquals(csvb6br13, [ {b2: "()", b3: "()", defaultableField: "", nillableField: ()} ]); - BooleanRecord13Array|CsvConversionError csvb7br13 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord13Array|Error csvb7br13 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br13, [ {b1, b2, b3: "()", b4, defaultableField: "", nillableField: ()} ]); - BooleanRecord14Array|CsvConversionError csvb7br14 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb7br14 is CsvConversionError); - test:assertEquals((csvb7br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord14Array|Error csvb7br14 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb7br14 is Error); + test:assertEquals((csvb7br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); } @test:Config {enable} function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { - BooleanRecord15Array|CsvConversionError csvb1br15 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br15 is CsvConversionError); - test:assertEquals((csvb1br15).message(), generateErrorMessageForInvalidCast("true", "int")); + BooleanRecord15Array|Error csvb1br15 = parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br15 is Error); + test:assertEquals((csvb1br15).message(), generateErrorMessageForInvalidCast("true", "int")); - BooleanRecord15Array|CsvConversionError csvb6br15 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br15 is CsvConversionError); - test:assertEquals((csvb6br15).message(), generateErrorMessageForMissingRequiredField("b1")); + BooleanRecord15Array|Error csvb6br15 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br15 is Error); + test:assertEquals((csvb6br15).message(), generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord15Array|CsvConversionError csvb7br15 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertTrue(csvb7br15 is CsvConversionError); - test:assertEquals((csvb7br15).message(), generateErrorMessageForInvalidCast("true", "int")); + BooleanRecord15Array|Error csvb7br15 = parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertTrue(csvb7br15 is Error); + test:assertEquals((csvb7br15).message(), generateErrorMessageForInvalidCast("true", "int")); - BooleanRecord16Array|CsvConversionError csvb1br16 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord16Array|Error csvb1br16 = parseStringToRecord(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|CsvConversionError csvb2br16 = parseStringToRecord(csvStringWithBooleanValues2, {}); + BooleanRecord16Array|Error csvb2br16 = parseStringToRecord(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|CsvConversionError csvb3br16 = parseStringToRecord(csvStringWithBooleanValues3, {}); + BooleanRecord16Array|Error csvb3br16 = parseStringToRecord(csvStringWithBooleanValues3, {}); test:assertEquals(csvb3br16, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: ()}, {b1: true, b2: true, b3: false} ]); - BooleanRecord16Array|CsvConversionError csvb4br16 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord16Array|Error csvb4br16 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br16, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - BooleanRecord16Array|CsvConversionError csvb5br16 = parseStringToRecord(csvStringWithBooleanValues5, {}); + BooleanRecord16Array|Error csvb5br16 = parseStringToRecord(csvStringWithBooleanValues5, {}); test:assertEquals(csvb5br16, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - BooleanRecord16Array|CsvConversionError csvb6br16 = parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord16Array|Error csvb6br16 = parseStringToRecord(csvStringWithBooleanValues6, {}); test:assertEquals(csvb6br16, [ {b2: (), b3: ()} ]); - BooleanRecord16Array|CsvConversionError csvb7br16 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord16Array|Error csvb7br16 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br16, [ {b1, b2, b3: (), b4} ]); - BooleanRecord17Array|CsvConversionError csvb1br17 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord17Array|Error csvb1br17 = parseStringToRecord(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br17, [{}, {}, {}]); - BooleanRecord17Array|CsvConversionError csvb4br17 = parseStringToRecord(csvStringWithBooleanValues4, {}); + BooleanRecord17Array|Error csvb4br17 = parseStringToRecord(csvStringWithBooleanValues4, {}); test:assertEquals(csvb4br17, [{}, {}]); - BooleanRecord17Array|CsvConversionError csvb6br17 = parseStringToRecord(csvStringWithBooleanValues6, {}); + BooleanRecord17Array|Error csvb6br17 = parseStringToRecord(csvStringWithBooleanValues6, {}); test:assertEquals(csvb6br17, [{}]); - BooleanRecord17Array|CsvConversionError csvb7br17 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord17Array|Error csvb7br17 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br17, [{}]); - BooleanRecord18Array|CsvConversionError csvb1br18 = parseStringToRecord(csvStringWithBooleanValues1, {}); + BooleanRecord18Array|Error csvb1br18 = parseStringToRecord(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br18, [{b2: false}, {b2: false}, {b2: false}]); - BooleanRecord18Array|CsvConversionError csvb4br18 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertTrue(csvb4br18 is CsvConversionError); - test:assertEquals((csvb4br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanRecord18Array|Error csvb4br18 = parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertTrue(csvb4br18 is Error); + test:assertEquals((csvb4br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanRecord18Array|CsvConversionError csvb6br18 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br18 is CsvConversionError); - test:assertEquals((csvb6br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanRecord18Array|Error csvb6br18 = parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br18 is Error); + test:assertEquals((csvb6br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanRecord18Array|CsvConversionError csvb7br18 = parseStringToRecord(csvStringWithBooleanValues7, {}); + BooleanRecord18Array|Error csvb7br18 = parseStringToRecord(csvStringWithBooleanValues7, {}); test:assertEquals(csvb7br18, [{b2, b3: ()}]); } diff --git a/ballerina/tests/parse_string_to_tuple_test.bal b/ballerina/tests/parse_string_to_tuple_test.bal index 344b467..ff4513c 100644 --- a/ballerina/tests/parse_string_to_tuple_test.bal +++ b/ballerina/tests/parse_string_to_tuple_test.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// BooleanRecord1Array|CsvConversionError csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); +// BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); // test:assertEquals(csvb4br1, [ // {b1: true, b2: "()", b3: (), b4: false}, // {b1: true, b2: "()", b3: (), b4: false} @@ -13,362 +13,362 @@ import ballerina/test; @test:Config {enable} function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { - BooleanTuple1Array|CsvConversionError cbv1bt1 = parseStringToList(csvStringWithBooleanValues1); + BooleanTuple1Array|Error cbv1bt1 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1bt1, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - BooleanTuple1Array|CsvConversionError cbv2bt1 = parseStringToList(csvStringWithBooleanValues2); + BooleanTuple1Array|Error cbv2bt1 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2bt1, [ [true, false, true, false], [true, false, true, false] ]); - BooleanTuple1Array|CsvConversionError cbv3bt1 = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cbv3bt1 is CsvConversionError); - test:assertEquals((cbv3bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanTuple1Array|Error cbv3bt1 = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt1 is Error); + test:assertEquals((cbv3bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple1Array|CsvConversionError cbv5bt1 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt1 is CsvConversionError); - test:assertEquals((cbv5bt1).message(), generateErrorMessageForInvalidCast("2", "boolean")); + BooleanTuple1Array|Error cbv5bt1 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt1 is Error); + test:assertEquals((cbv5bt1).message(), generateErrorMessageForInvalidCast("2", "boolean")); - BooleanTuple1Array|CsvConversionError cbv7bt1 = parseStringToList(csvStringWithBooleanValues7); - test:assertTrue(cbv7bt1 is CsvConversionError); - test:assertEquals((cbv7bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanTuple1Array|Error cbv7bt1 = parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt1 is Error); + test:assertEquals((cbv7bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple2Array|CsvConversionError cbv1bt2 = parseStringToList(csvStringWithBooleanValues1); + BooleanTuple2Array|Error cbv1bt2 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1bt2, [ [true, false], [true, false], [true, false] ]); - BooleanTuple2Array|CsvConversionError cbv2bt2 = parseStringToList(csvStringWithBooleanValues2); + BooleanTuple2Array|Error cbv2bt2 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2bt2, [ [true, false], [true, false] ]); - BooleanTuple2Array|CsvConversionError cbv3bt2 = parseStringToList(csvStringWithBooleanValues3); + BooleanTuple2Array|Error cbv3bt2 = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cbv3bt2, [ [true, false], [true, false], [true, true] ]); - BooleanTuple2Array|CsvConversionError cbv4bt2 = parseStringToList(csvStringWithBooleanValues4); - test:assertTrue(cbv4bt2 is CsvConversionError); - test:assertEquals((cbv4bt2).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanTuple2Array|Error cbv4bt2 = parseStringToList(csvStringWithBooleanValues4); + test:assertTrue(cbv4bt2 is Error); + test:assertEquals((cbv4bt2).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple3Array|CsvConversionError cbv1bt3 = parseStringToList(csvStringWithBooleanValues1); + BooleanTuple3Array|Error cbv1bt3 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1bt3, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - BooleanTuple3Array|CsvConversionError cbv2bt3 = parseStringToList(csvStringWithBooleanValues2); + BooleanTuple3Array|Error cbv2bt3 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2bt3, [ [true, false, true, false, true], [true, false, true, false, true] ]); - BooleanTuple3Array|CsvConversionError cbv3bt3 = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cbv3bt3 is CsvConversionError); - test:assertEquals((cbv3bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanTuple3Array|Error cbv3bt3 = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt3 is Error); + test:assertEquals((cbv3bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple3Array|CsvConversionError cbv5bt3 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt3 is CsvConversionError); - test:assertEquals((cbv5bt3).message(), generateErrorMessageForInvalidCast("2", "boolean")); + BooleanTuple3Array|Error cbv5bt3 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt3 is Error); + test:assertEquals((cbv5bt3).message(), generateErrorMessageForInvalidCast("2", "boolean")); - BooleanTuple3Array|CsvConversionError cbv7bt3 = parseStringToList(csvStringWithBooleanValues7); - test:assertTrue(cbv7bt3 is CsvConversionError); - test:assertEquals((cbv7bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanTuple3Array|Error cbv7bt3 = parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt3 is Error); + test:assertEquals((cbv7bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple4Array|CsvConversionError cbv1bt4 = parseStringToList(csvStringWithBooleanValues1); + BooleanTuple4Array|Error cbv1bt4 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1bt4, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - BooleanTuple4Array|CsvConversionError cbv2bt4 = parseStringToList(csvStringWithBooleanValues2); + BooleanTuple4Array|Error cbv2bt4 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2bt4, [ [true, false, true, false, true], [true, false, true, false, true] ]); - BooleanTuple4Array|CsvConversionError cbv3bt4 = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cbv3bt4 is CsvConversionError); - test:assertEquals((cbv3bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanTuple4Array|Error cbv3bt4 = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt4 is Error); + test:assertEquals((cbv3bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple4Array|CsvConversionError cbv4bt4 = parseStringToList(csvStringWithBooleanValues4); - test:assertTrue(cbv4bt4 is CsvConversionError); - test:assertEquals((cbv4bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanTuple4Array|Error cbv4bt4 = parseStringToList(csvStringWithBooleanValues4); + test:assertTrue(cbv4bt4 is Error); + test:assertEquals((cbv4bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple4Array|CsvConversionError cbv5bt4 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt4 is CsvConversionError); - test:assertEquals((cbv5bt4).message(), generateErrorMessageForInvalidCast("2", "boolean")); + BooleanTuple4Array|Error cbv5bt4 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt4 is Error); + test:assertEquals((cbv5bt4).message(), generateErrorMessageForInvalidCast("2", "boolean")); - BooleanTuple4Array|CsvConversionError cbv6bt4 = parseStringToList(csvStringWithBooleanValues6); - test:assertTrue(cbv6bt4 is CsvConversionError); - test:assertEquals((cbv6bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanTuple4Array|Error cbv6bt4 = parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cbv6bt4 is Error); + test:assertEquals((cbv6bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - BooleanTuple4Array|CsvConversionError cbv7bt4 = parseStringToList(csvStringWithBooleanValues7); - test:assertTrue(cbv7bt4 is CsvConversionError); - test:assertEquals((cbv7bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); + BooleanTuple4Array|Error cbv7bt4 = parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt4 is Error); + test:assertEquals((cbv7bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - NillableBooleanTuple5Array|CsvConversionError cbv1bt5 = parseStringToList(csvStringWithBooleanValues1); + NillableBooleanTuple5Array|Error cbv1bt5 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1bt5, [ [true, false, true, false, null], [true, false, true, false, null], [true, false, true, false, null] ]); - NillableBooleanTuple5Array|CsvConversionError cbv2bt5 = parseStringToList(csvStringWithBooleanValues2); + NillableBooleanTuple5Array|Error cbv2bt5 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2bt5, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableBooleanTuple5Array|CsvConversionError cbv3bt5 = parseStringToList(csvStringWithBooleanValues3); + NillableBooleanTuple5Array|Error cbv3bt5 = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cbv3bt5, [ [true, false, true, null, null], [true, false, (), null, null], [true, true, false, null, null] ]); - NillableBooleanTuple5Array|CsvConversionError cbv4bt5 = parseStringToList(csvStringWithBooleanValues4); + NillableBooleanTuple5Array|Error cbv4bt5 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4bt5, [ [true, (), (), false, null], [true, (), (), false, null] ]); - NillableBooleanTuple5Array|CsvConversionError cbv5bt5 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt5 is CsvConversionError); - test:assertEquals((cbv5bt5).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + NillableBooleanTuple5Array|Error cbv5bt5 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt5 is Error); + test:assertEquals((cbv5bt5).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - NillableBooleanTuple5Array|CsvConversionError cbv6bt5 = parseStringToList(csvStringWithBooleanValues6); + NillableBooleanTuple5Array|Error cbv6bt5 = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cbv6bt5, [ [(), (), null, null, null] ]); - NillableBooleanTuple5Array|CsvConversionError cbv7bt5 = parseStringToList(csvStringWithBooleanValues7); + NillableBooleanTuple5Array|Error cbv7bt5 = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cbv7bt5, [ [b1, b2, (), b4, null] ]); - NillableBooleanTuple6Array|CsvConversionError cbv1bt6 = parseStringToList(csvStringWithBooleanValues1); + NillableBooleanTuple6Array|Error cbv1bt6 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1bt6, [ [true, false], [true, false], [true, false] ]); - NillableBooleanTuple6Array|CsvConversionError cbv2bt6 = parseStringToList(csvStringWithBooleanValues2); + NillableBooleanTuple6Array|Error cbv2bt6 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2bt6, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|CsvConversionError cbv3bt6 = parseStringToList(csvStringWithBooleanValues3); + NillableBooleanTuple6Array|Error cbv3bt6 = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cbv3bt6, [ [true, false], [true, false], [true, true] ]); - NillableBooleanTuple6Array|CsvConversionError cbv4bt6 = parseStringToList(csvStringWithBooleanValues4); + NillableBooleanTuple6Array|Error cbv4bt6 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4bt6, [ [true, ()], [true, ()] ]); - NillableBooleanTuple6Array|CsvConversionError cbv6bt6 = parseStringToList(csvStringWithBooleanValues6); + NillableBooleanTuple6Array|Error cbv6bt6 = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cbv6bt6, [ [(), null] ]); - NillableBooleanTuple6Array|CsvConversionError cbv7bt6 = parseStringToList(csvStringWithBooleanValues7); + NillableBooleanTuple6Array|Error cbv7bt6 = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cbv7bt6, [ [b1, b2] ]); - NillableBooleanTuple7Array|CsvConversionError cbv1bt7 = parseStringToList(csvStringWithBooleanValues1); + NillableBooleanTuple7Array|Error cbv1bt7 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1bt7, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - NillableBooleanTuple7Array|CsvConversionError cbv2bt7 = parseStringToList(csvStringWithBooleanValues2); + NillableBooleanTuple7Array|Error cbv2bt7 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2bt7, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableBooleanTuple7Array|CsvConversionError cbv3bt7 = parseStringToList(csvStringWithBooleanValues3); + NillableBooleanTuple7Array|Error cbv3bt7 = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cbv3bt7, [ [true, false, true], [true, false, ()], [true, true, false] ]); - NillableBooleanTuple7Array|CsvConversionError cbv4bt7 = parseStringToList(csvStringWithBooleanValues4); + NillableBooleanTuple7Array|Error cbv4bt7 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4bt7, [ [true, (), (), false], [true, (), (), false] ]); - NillableBooleanTuple7Array|CsvConversionError cbv5bt7 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt7 is CsvConversionError); - test:assertEquals((cbv5bt7).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + NillableBooleanTuple7Array|Error cbv5bt7 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt7 is Error); + test:assertEquals((cbv5bt7).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - NillableBooleanTuple7Array|CsvConversionError cbv6bt7 = parseStringToList(csvStringWithBooleanValues6); + NillableBooleanTuple7Array|Error cbv6bt7 = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cbv6bt7, [ [(), ()] ]); - NillableBooleanTuple7Array|CsvConversionError cbv7bt7 = parseStringToList(csvStringWithBooleanValues7); + NillableBooleanTuple7Array|Error cbv7bt7 = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cbv7bt7, [ [b1, b2, (), false] ]); - NillableBooleanTuple8Array|CsvConversionError cbv1bt8 = parseStringToList(csvStringWithBooleanValues1); + NillableBooleanTuple8Array|Error cbv1bt8 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1bt8, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - NillableBooleanTuple8Array|CsvConversionError cbv2bt8 = parseStringToList(csvStringWithBooleanValues2); + NillableBooleanTuple8Array|Error cbv2bt8 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2bt8, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableBooleanTuple8Array|CsvConversionError cbv3bt8 = parseStringToList(csvStringWithBooleanValues3); + NillableBooleanTuple8Array|Error cbv3bt8 = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cbv3bt8, [ [true, false, true], [true, false, ()], [true, true, false] ]); - NillableBooleanTuple8Array|CsvConversionError cbv4bt8 = parseStringToList(csvStringWithBooleanValues4); + NillableBooleanTuple8Array|Error cbv4bt8 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4bt8, [ [true, (), (), false], [true, (), (), false] ]); - NillableBooleanTuple8Array|CsvConversionError cbv5bt8 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt8 is CsvConversionError); - test:assertEquals((cbv5bt8).message(), generateErrorMessageForInvalidCast("2", "boolean?")); + NillableBooleanTuple8Array|Error cbv5bt8 = parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt8 is Error); + test:assertEquals((cbv5bt8).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - NillableBooleanTuple8Array|CsvConversionError cbv6bt8 = parseStringToList(csvStringWithBooleanValues6); + NillableBooleanTuple8Array|Error cbv6bt8 = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cbv6bt8, [ [(), ()] ]); - NillableBooleanTuple8Array|CsvConversionError cbv7bt8 = parseStringToList(csvStringWithBooleanValues7); + NillableBooleanTuple8Array|Error cbv7bt8 = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cbv7bt8, [ [b1, b2, (), false] ]); - NillableIntBooleanTuple9Array|CsvConversionError cbv1bt9 = parseStringToList(csvStringWithBooleanValues1); + NillableIntBooleanTuple9Array|Error cbv1bt9 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1bt9, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - NillableIntBooleanTuple9Array|CsvConversionError cbv2bt9 = parseStringToList(csvStringWithBooleanValues2); + NillableIntBooleanTuple9Array|Error cbv2bt9 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2bt9, [ [true, false, true, false, true], [true, false, true, false, true] ]); - NillableIntBooleanTuple9Array|CsvConversionError cbv3bt9 = parseStringToList(csvStringWithBooleanValues3); + NillableIntBooleanTuple9Array|Error cbv3bt9 = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cbv3bt9, [ [true, false, true], [true, false, ()], [true, true, false] ]); - NillableIntBooleanTuple9Array|CsvConversionError cbv4bt9 = parseStringToList(csvStringWithBooleanValues4); + NillableIntBooleanTuple9Array|Error cbv4bt9 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4bt9, [ [true, (), (), false], [true, (), (), false] ]); - NillableIntBooleanTuple9Array|CsvConversionError cbv5bt9 = parseStringToList(csvStringWithBooleanValues5); + NillableIntBooleanTuple9Array|Error cbv5bt9 = parseStringToList(csvStringWithBooleanValues5); test:assertEquals(cbv5bt9, [ [true, false, true, 2], [true, false, true, 3] ]); - NillableIntBooleanTuple9Array|CsvConversionError cbv6bt9 = parseStringToList(csvStringWithBooleanValues6); + NillableIntBooleanTuple9Array|Error cbv6bt9 = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cbv6bt9, [ [(), ()] ]); - NillableIntBooleanTuple9Array|CsvConversionError cbv7bt9 = parseStringToList(csvStringWithBooleanValues7); + NillableIntBooleanTuple9Array|Error cbv7bt9 = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cbv7bt9, [ [b1, b2, (), false] ]); - NilTuple3Array|CsvConversionError cbv1nt3 = parseStringToList(csvStringWithBooleanValues1); - test:assertTrue(cbv1nt3 is CsvConversionError); - test:assertEquals((cbv1nt3).message(), generateErrorMessageForInvalidCast("true", "()")); + NilTuple3Array|Error cbv1nt3 = parseStringToList(csvStringWithBooleanValues1); + test:assertTrue(cbv1nt3 is Error); + test:assertEquals((cbv1nt3).message(), generateErrorMessageForInvalidCast("true", "()")); - NilTuple3Array|CsvConversionError cbv3nt3 = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cbv3nt3 is CsvConversionError); - test:assertEquals((cbv3nt3).message(), generateErrorMessageForInvalidCast("true", "()")); + NilTuple3Array|Error cbv3nt3 = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3nt3 is Error); + test:assertEquals((cbv3nt3).message(), generateErrorMessageForInvalidCast("true", "()")); - NilTuple3Array|CsvConversionError cbv6nt3 = parseStringToList(csvStringWithBooleanValues6); + NilTuple3Array|Error cbv6nt3 = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cbv6nt3, [ [(), ()] ]); - AnydataTuple3Array|CsvConversionError cbv1anyd3 = parseStringToList(csvStringWithBooleanValues1); + AnydataTuple3Array|Error cbv1anyd3 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1anyd3, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - AnydataTuple3Array|CsvConversionError cbv2anyd3 = parseStringToList(csvStringWithBooleanValues2); + AnydataTuple3Array|Error cbv2anyd3 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2anyd3, [ [true, false, true, false, true], [true, false, true, false, true] ]); - AnydataTuple3Array|CsvConversionError cbv3anyd3 = parseStringToList(csvStringWithBooleanValues3); + AnydataTuple3Array|Error cbv3anyd3 = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cbv3anyd3, [ [true, false, true], [true, false, ()], [true, true, false] ]); - AnydataTuple3Array|CsvConversionError cbv4anyd3 = parseStringToList(csvStringWithBooleanValues4); + AnydataTuple3Array|Error cbv4anyd3 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4anyd3, [ [true, (), (), false], [true, (), (), false] ]); - AnydataTuple3Array|CsvConversionError cbv5anyd3 = parseStringToList(csvStringWithBooleanValues5); + AnydataTuple3Array|Error cbv5anyd3 = parseStringToList(csvStringWithBooleanValues5); test:assertEquals(cbv5anyd3, [ [true, false, true, 2], [true, false, true, 3] ]); - AnydataTuple3Array|CsvConversionError cbv6anyd3 = parseStringToList(csvStringWithBooleanValues6); + AnydataTuple3Array|Error cbv6anyd3 = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cbv6anyd3, [ [(), ()] ]); - AnydataTuple3Array|CsvConversionError cbv7anyd3 = parseStringToList(csvStringWithBooleanValues7); + AnydataTuple3Array|Error cbv7anyd3 = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cbv7anyd3, [ [b1, b2, (), false] ]); @@ -376,99 +376,99 @@ function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { @test:Config {enable} function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { - JsonTuple3Array|CsvConversionError cbv1j3 = parseStringToList(csvStringWithBooleanValues1); + JsonTuple3Array|Error cbv1j3 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1j3, [ [true, false, true, false], [true, false, true, false], [true, false, true, false] ]); - JsonTuple3Array|CsvConversionError cbv2j3 = parseStringToList(csvStringWithBooleanValues2); + JsonTuple3Array|Error cbv2j3 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2j3, [ [true, false, true, false, true], [true, false, true, false, true] ]); - JsonTuple3Array|CsvConversionError cbv3j3 = parseStringToList(csvStringWithBooleanValues3); + JsonTuple3Array|Error cbv3j3 = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cbv3j3, [ [true, false, true], [true, false, ()], [true, true, false] ]); - JsonTuple3Array|CsvConversionError cbv4j3 = parseStringToList(csvStringWithBooleanValues4); + JsonTuple3Array|Error cbv4j3 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4j3, [ [true, (), (), false], [true, (), (), false] ]); - JsonTuple3Array|CsvConversionError cbv5j3 = parseStringToList(csvStringWithBooleanValues5); + JsonTuple3Array|Error cbv5j3 = parseStringToList(csvStringWithBooleanValues5); test:assertEquals(cbv5j3, [ [true, false, true, 2], [true, false, true, 3] ]); - JsonTuple3Array|CsvConversionError cbv6j3 = parseStringToList(csvStringWithBooleanValues6); + JsonTuple3Array|Error cbv6j3 = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cbv6j3, [ [(), ()] ]); - JsonTuple3Array|CsvConversionError cbv7j3 = parseStringToList(csvStringWithBooleanValues7); + JsonTuple3Array|Error cbv7j3 = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cbv7j3, [ [b1, b2, (), false] ]); - StringTuple3Array|CsvConversionError cbv1s3 = parseStringToList(csvStringWithBooleanValues1); + StringTuple3Array|Error cbv1s3 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1s3, [ ["true", "false", "true", "false"], ["true", "false", "true", "false"], ["true", "false", "true", "false"] ]); - StringTuple3Array|CsvConversionError cbv2s3 = parseStringToList(csvStringWithBooleanValues2); + StringTuple3Array|Error cbv2s3 = parseStringToList(csvStringWithBooleanValues2); test:assertEquals(cbv2s3, [ ["true", "false", "true", "false", "true"], ["true", "false", "true", "false", "true"] ]); - StringTuple3Array|CsvConversionError cbv3s3 = parseStringToList(csvStringWithBooleanValues3); + StringTuple3Array|Error cbv3s3 = parseStringToList(csvStringWithBooleanValues3); test:assertEquals(cbv3s3, [ ["true", "false", "true"], ["TRUE", "FALSE", "()"], ["true", "true", "FALSE"] ]); - StringTuple3Array|CsvConversionError cbv4s3 = parseStringToList(csvStringWithBooleanValues4); + StringTuple3Array|Error cbv4s3 = parseStringToList(csvStringWithBooleanValues4); test:assertEquals(cbv4s3, [ ["true", "()", "()", "false"], ["true", "()", "null", "false"] ]); - StringTuple3Array|CsvConversionError cbv5s3 = parseStringToList(csvStringWithBooleanValues5); + StringTuple3Array|Error cbv5s3 = parseStringToList(csvStringWithBooleanValues5); test:assertEquals(cbv5s3, [ ["true", "false", "true", "2"], ["true", "false", "true", "3"] ]); - StringTuple3Array|CsvConversionError cbv6s3 = parseStringToList(csvStringWithBooleanValues6); + StringTuple3Array|Error cbv6s3 = parseStringToList(csvStringWithBooleanValues6); test:assertEquals(cbv6s3, [ ["()", "()"] ]); - StringTuple3Array|CsvConversionError cbv7s3 = parseStringToList(csvStringWithBooleanValues7); + StringTuple3Array|Error cbv7s3 = parseStringToList(csvStringWithBooleanValues7); test:assertEquals(cbv7s3, [ ["true", "false", "()", "false"] ]); - DecimalTuple3Array|CsvConversionError cbv1dt3 = parseStringToList(csvStringWithBooleanValues1); - test:assertTrue(cbv1dt3 is CsvConversionError); - test:assertEquals((cbv1dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); + DecimalTuple3Array|Error cbv1dt3 = parseStringToList(csvStringWithBooleanValues1); + test:assertTrue(cbv1dt3 is Error); + test:assertEquals((cbv1dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); - DecimalTuple3Array|CsvConversionError cbv3dt3 = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cbv3dt3 is CsvConversionError); - test:assertEquals((cbv3dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); + DecimalTuple3Array|Error cbv3dt3 = parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3dt3 is Error); + test:assertEquals((cbv3dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); - DecimalTuple3Array|CsvConversionError cbv6dt3 = parseStringToList(csvStringWithBooleanValues6); - test:assertTrue(cbv6dt3 is CsvConversionError); - test:assertEquals((cbv6dt3).message(), generateErrorMessageForInvalidCast("()", "decimal")); + DecimalTuple3Array|Error cbv6dt3 = parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cbv6dt3 is Error); + test:assertEquals((cbv6dt3).message(), generateErrorMessageForInvalidCast("()", "decimal")); } diff --git a/ballerina/tests/parse_type_compatibility_test.bal b/ballerina/tests/parse_type_compatibility_test.bal index d0f81f0..7fc3f64 100644 --- a/ballerina/tests/parse_type_compatibility_test.bal +++ b/ballerina/tests/parse_type_compatibility_test.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() { -// record{A a; B b; C c;}[]|CsvConversionError rt12a = parseListAsRecordType( +// record{A a; B b; C c;}[]|Error rt12a = parseListAsRecordType( // [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); // test:assertEquals(rt12a , [ @@ -20,7 +20,7 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { var value2 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3, j2: b2, a2: d2}; var value3 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3}; - CustomRecord27Array|CsvConversionError vcr27a = parseRecordAsRecordType([value, value, value], {}, CustomRecord27Array); + CustomRecord27Array|Error vcr27a = 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: ()}, @@ -28,46 +28,46 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { ]); // TODO: - // CustomTuple7Array|CsvConversionError v2ct7a = parseRecordAsListType([value2, value2, value2], {}, CustomTuple7Array); - // test:assertTrue(v2ct7a is CsvConversionError); - // test:assertEquals((v2ct7a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "string")); + // CustomTuple7Array|Error v2ct7a = parseRecordAsListType([value2, value2, value2], {}, CustomTuple7Array); + // test:assertTrue(v2ct7a is Error); + // test:assertEquals((v2ct7a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "string")); - // CustomTuple7Array|CsvConversionError v3ct7a = parseRecordAsListType([value3, value3, value3], {}, CustomTuple7Array); + // CustomTuple7Array|Error v3ct7a = parseRecordAsListType([value3, value3, value3], {}, CustomTuple7Array); // test:assertEquals(v3ct7a , [ // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3] // ]); - // AnydataArray1Array|CsvConversionError v3anyd1a = parseRecordAsListType([value3, value3, value3], {}, AnydataArray1Array); + // AnydataArray1Array|Error v3anyd1a = parseRecordAsListType([value3, value3, value3], {}, AnydataArray1Array); // test:assertEquals(v3anyd1a , [ // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3] // ]); - AnydataMapArray|CsvConversionError vanydma = parseRecordAsRecordType([value, value, value], {}, AnydataMapArray); + AnydataMapArray|Error vanydma = parseRecordAsRecordType([value, value, value], {}, AnydataMapArray); test:assertEquals(vanydma , [ value, value, value ]); - JsonMapArray|CsvConversionError vjma = parseRecordAsRecordType([value, value, value], {}, JsonMapArray); + JsonMapArray|Error vjma = parseRecordAsRecordType([value, value, value], {}, JsonMapArray); test:assertEquals(vjma , [ value, value, value ]); - record{|int...;|}[]|CsvConversionError irrma = parseRecordAsRecordType([{"a": 1}, {"a": i1, "b": i2}, {"a": i1, "b": i2, "c": s1}]); + record{|int...;|}[]|Error irrma = 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...;|}[]|CsvConversionError drra = parseRecordAsRecordType([{"a": d1}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1, "d": f3}]); + record{|decimal...;|}[]|Error drra = 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}, @@ -75,21 +75,21 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {a: d4, b: -3.21d, d: f3} ]); - record{|string...;|}[]|CsvConversionError srra = parseRecordAsRecordType([{"a": "string"}, {"c": 1, "a": s1, "b": s2}, {"a": b1, "b": s3, "c": d1}]); + record{|string...;|}[]|Error srra = 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...;|}[]|CsvConversionError frra = parseRecordAsRecordType([{"a": 1.2, "b": 1.2f}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1}]); + record{|float...;|}[]|Error frra = 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;|}[]|CsvConversionError fdc1a = parseRecordAsRecordType([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + record{|float a; decimal b;|}[]|Error fdc1a = 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}, @@ -97,7 +97,7 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {a: f2, b: d2} ]); - record{|float a; decimal ...;|}[]|CsvConversionError fdc2a = parseRecordAsRecordType([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + record{|float a; decimal ...;|}[]|Error fdc2a = 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}, @@ -105,7 +105,7 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {a: f2, b: d2} ]); - record{|decimal b; float...;|}[]|CsvConversionError fdc3a = parseRecordAsRecordType([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + record{|decimal b; float...;|}[]|Error fdc3a = 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}, @@ -127,7 +127,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { readonly & int a; readonly & string b; (readonly & boolean) | (readonly & decimal) c; - }[]|CsvConversionError r1a = parseStringToRecord( string `a,b,c + }[]|Error r1a = parseStringToRecord( string `a,b,c 1,string,true 2,string2,false 3,string3,true`); @@ -138,7 +138,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A a; B b; C c;}[]|CsvConversionError r2a = parseStringToRecord( string `a,b,c + record{A a; B b; C c;}[]|Error r2a = parseStringToRecord( string `a,b,c 1,string,true 2,string2,false 3,string3,true`); @@ -149,7 +149,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A2 a; B2 b; C2 c;}[]|CsvConversionError r3a = parseStringToRecord( string `a,b,c + record{A2 a; B2 b; C2 c;}[]|Error r3a = parseStringToRecord( string `a,b,c 1,string,true 2,string2,false 3,string3,true`); @@ -160,7 +160,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{|A2 a; B2 b; C2...;|}[]|CsvConversionError r4a = parseStringToRecord( string ` + record{|A2 a; B2 b; C2...;|}[]|Error r4a = parseStringToRecord( string ` a,b,c,d 1,string,true,string 2,string2,false,string2 @@ -172,7 +172,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|CsvConversionError r5a = parseStringToRecord( string `a,b,c,d + record{|C2...;|}[]|Error r5a = parseStringToRecord( string `a,b,c,d 1,string,true,string 2,string2,false,string2 3,string3,true,string3`); @@ -183,7 +183,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: "3", b: "string3", c: true, d: "string3"} ]); - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|CsvConversionError r16a = + [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|Error r16a = parseStringToList( string `a,b,c 1,string,true 2,string2,false @@ -195,7 +195,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|CsvConversionError r17a = parseStringToList( + [A, B, C][]|Error r17a = parseStringToList( string `a,b,c 1,string,true 2,string2,false @@ -207,7 +207,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2][]|CsvConversionError r18a = parseStringToList( + [A2, B2, C2][]|Error r18a = parseStringToList( string `a,b,c 1,string,true 2,string2,false @@ -219,7 +219,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2...][]|CsvConversionError r19a = parseStringToList( + [A2, B2, C2...][]|Error r19a = parseStringToList( string `a,b,c,d 1,string,true,string 2,string2,false,string2 @@ -231,7 +231,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true, "string3"] ]); - [C2...][]|CsvConversionError r20a = parseStringToList( + [C2...][]|Error r20a = parseStringToList( string `a,b,c,d 1,string,true,string 2,string2,false,string2 @@ -241,7 +241,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); - record{A a; B b; C c;}[]|CsvConversionError rt2a = parseRecordAsRecordType( + record{A a; B b; C c;}[]|Error rt2a = parseRecordAsRecordType( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); test:assertEquals(rt2a , [ @@ -254,7 +254,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { readonly & int a; readonly & string b; (readonly & boolean) | (readonly & decimal) c; - }[]|CsvConversionError rt1a = parseRecordAsRecordType( + }[]|Error rt1a = parseRecordAsRecordType( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); test:assertEquals(rt1a , [ @@ -263,7 +263,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A2 a; B2 b; C2 c;}[]|CsvConversionError rt3a = parseRecordAsRecordType( + record{A2 a; B2 b; C2 c;}[]|Error rt3a = parseRecordAsRecordType( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}]); test:assertEquals(rt3a , [ @@ -272,7 +272,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{|A2 a; B2 b; C2...;|}[]|CsvConversionError rt4a = parseRecordAsRecordType( + record{|A2 a; B2 b; C2...;|}[]|Error rt4a = 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 , [ @@ -281,7 +281,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|CsvConversionError rt5a = parseRecordAsRecordType( + record{|C2...;|}[]|Error rt5a = 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 , [ @@ -290,7 +290,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {b: "string3", c: true, d: "string3"} ]); - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|CsvConversionError rt6a = + [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|Error rt6a = parseRecordAsListType( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, @@ -303,7 +303,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|CsvConversionError rt7a = parseRecordAsListType( + [A, B, C][]|Error rt7a = parseRecordAsListType( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] , ["a", "b", "c"]); @@ -313,7 +313,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2][]|CsvConversionError rt8a = parseRecordAsListType( + [A2, B2, C2][]|Error rt8a = parseRecordAsListType( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] , ["a", "b", "c"]); @@ -323,7 +323,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2...][]|CsvConversionError rt9a = parseRecordAsListType( + [A2, B2, C2...][]|Error rt9a = 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"]); @@ -333,18 +333,18 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true, "string3"] ]); - [C2...][]|CsvConversionError rt10a = parseRecordAsListType( + [C2...][]|Error rt10a = 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:assertTrue(rt10a is CsvConversionError); - test:assertEquals((rt10a).message(), generateErrorMessageForInvalidValueForArrayType("1", "0", "data.csv:C2")); + test:assertTrue(rt10a is Error); + test:assertEquals((rt10a).message(), generateErrorMessageForInvalidValueForArrayType("1", "0", "data.csv:C2")); record{ readonly & int a; readonly & string b; (readonly & boolean) | (readonly & decimal) c; - }[]|CsvConversionError rt11a = parseListAsRecordType( + }[]|Error rt11a = parseListAsRecordType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); test:assertEquals(rt11a , [ @@ -353,7 +353,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A a; B b; C c;}[]|CsvConversionError rt12a = parseListAsRecordType( + record{A a; B b; C c;}[]|Error rt12a = parseListAsRecordType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); test:assertEquals(rt12a , [ @@ -362,14 +362,14 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A a; B b; C c;}[]|CsvConversionError rt12a_2 = parseListAsRecordType( + record{A a; B b; C c;}[]|Error rt12a_2 = parseListAsRecordType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"], {stringConversion: false}); - test:assertTrue(rt12a_2 is CsvConversionError); - test:assertEquals((rt12a_2).message(), + test:assertTrue(rt12a_2 is Error); + test:assertEquals((rt12a_2).message(), generateErrorMessageForInvalidFieldType("1", "a")); - record{string|decimal a; B b; C c;}[]|CsvConversionError rt12a_3 = parseListAsRecordType( + record{string|decimal a; B b; C c;}[]|Error rt12a_3 = parseListAsRecordType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); test:assertEquals(rt12a_3 , [ @@ -378,7 +378,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A2 a; B2 b; C2 c;}[]|CsvConversionError rt13a = parseListAsRecordType( + record{A2 a; B2 b; C2 c;}[]|Error rt13a = parseListAsRecordType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); test:assertEquals(rt13a , [ @@ -387,7 +387,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{|A2 a; B2 b; C2...;|}[]|CsvConversionError rt14a = parseListAsRecordType( + record{|A2 a; B2 b; C2...;|}[]|Error rt14a = parseListAsRecordType( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] , ["a", "b", "c", "d"]); @@ -397,7 +397,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|CsvConversionError rt15a = parseListAsRecordType( + record{|C2...;|}[]|Error rt15a = parseListAsRecordType( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] , ["a", "b", "c", "d"]); @@ -407,7 +407,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: "3", b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|CsvConversionError rt15a_2 = parseListAsRecordType( + record{|C2...;|}[]|Error rt15a_2 = parseListAsRecordType( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] , ["a", "b", "c", "d"], {stringConversion: false}); @@ -417,7 +417,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: "3",b: "string3", c: "true", d: "string3"} ]); - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|CsvConversionError rt16a = + [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|Error rt16a = parseListAsListType( [["1", "string", "true"], ["2", "string2", "false"], @@ -429,7 +429,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|CsvConversionError rt17a = parseListAsListType( + [A, B, C][]|Error rt17a = parseListAsListType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); test:assertEquals(rt17a , [ @@ -438,13 +438,13 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|CsvConversionError rt17a_2 = parseListAsListType( + [A, B, C][]|Error rt17a_2 = parseListAsListType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {stringConversion: false}); - test:assertTrue(rt17a_2 is CsvConversionError); + test:assertTrue(rt17a_2 is Error); test:assertEquals((rt17a_2).message(), generateErrorMessageForInvalidValueForArrayType("1", "0", "data.csv:A")); - [A2, B2, C2][]|CsvConversionError rt18a = parseListAsListType( + [A2, B2, C2][]|Error rt18a = parseListAsListType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); test:assertEquals(rt18a , [ @@ -453,7 +453,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2...][]|CsvConversionError rt19a = parseListAsListType( + [A2, B2, C2...][]|Error rt19a = parseListAsListType( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); test:assertEquals(rt19a , [ @@ -462,7 +462,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true, "string3"] ]); - [C2...][]|CsvConversionError rt20a = parseListAsListType( + [C2...][]|Error rt20a = parseListAsListType( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); test:assertEquals(rt20a, [["1", "string",true, "string"], diff --git a/ballerina/tests/test_with_intersection_types.bal b/ballerina/tests/test_with_intersection_types.bal index 131a189..cee8a01 100644 --- a/ballerina/tests/test_with_intersection_types.bal +++ b/ballerina/tests/test_with_intersection_types.bal @@ -4,68 +4,68 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() returns error? { -// (int[] & readonly)[]|CsvConversionError a = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); +// (int[] & readonly)[]|Error a = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); // test:assertEquals(a, ""); // } @test:Config {enable} function testIntersectionExpectedTypes() returns error? { - (int[] & readonly)[]|CsvConversionError a = parseStringToList(string `a,b + (int[] & readonly)[]|Error a = parseStringToList(string `a,b 1,2 4,5`); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|CsvConversionError a2 = parseStringToList(string `a,b + ([string, string])[] & readonly|Error a2 = parseStringToList(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)[]|CsvConversionError a3 = parseStringToRecord(string `a,b + (record{int a; string b;} & readonly)[]|Error a3 = parseStringToRecord(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|CsvConversionError a4 = parseStringToRecord(string `a,b + record{|string...;|}[] & readonly|Error a4 = parseStringToRecord(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)[]|CsvConversionError a5 = parseStringToList(string `a,b + ([int] & readonly)[]|Error a5 = parseStringToList(string `a,b 1,2 4,5`); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|CsvConversionError a6 = parseStringToList(string `a,b + ([string, string])[] & readonly|Error a6 = parseStringToList(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)[]|CsvConversionError a7 = parseStringToRecord(string `a,b + (record{int a; string b;} & readonly)[]|Error a7 = parseStringToRecord(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|CsvConversionError a8 = parseStringToRecord(string `a,b + map[] & readonly|Error a8 = parseStringToRecord(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)[]|CsvConversionError a9 = parseStringToList(string `a,b + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|Error a9 = parseStringToList(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|CsvConversionError a10 = parseStringToRecord(string `a,b + & readonly|Error a10 = parseStringToRecord(string `a,b a,a 1,2`); test:assertTrue(a10 is ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly); @@ -74,93 +74,93 @@ function testIntersectionExpectedTypes() returns error? { @test:Config {enable} function testIntersectionExpectedTypes2() returns error? { - (int[] & readonly)[]|CsvConversionError a = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); + (int[] & readonly)[]|Error a = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|CsvConversionError a2 = parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); + ([string, string])[] & readonly|Error a2 = parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); test:assertTrue(a2 is [string, string][] & readonly); test:assertEquals(a2, [["a", "a"], ["c", "c"]]); - (record{int a; string b;} & readonly)[]|CsvConversionError a3 = parseRecordAsRecordType([{"a": 1, "b": "2"}, {"a": 4, "b": "5"}], {}); + (record{int a; string b;} & readonly)[]|Error a3 = parseRecordAsRecordType([{"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|CsvConversionError a4 = parseRecordAsRecordType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {}); + record{|string...;|}[] & readonly|Error a4 = parseRecordAsRecordType([{"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)[]|CsvConversionError a5 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); + ([int] & readonly)[]|Error a5 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|CsvConversionError a6 = parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); + ([string, string])[] & readonly|Error a6 = parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); test:assertTrue(a6 is [string, string][] & readonly); test:assertEquals(a6, [["a", "a"], ["c", "c"]]); - (record{int a; string b;} & readonly)[]|CsvConversionError a7 = parseRecordAsRecordType([{"a": 1, "b": "2"}, {"a": 4, "b": "5"}], {}); + (record{int a; string b;} & readonly)[]|Error a7 = parseRecordAsRecordType([{"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|CsvConversionError a8 = parseRecordAsRecordType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {}); + map[] & readonly|Error a8 = parseRecordAsRecordType([{"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)[]|CsvConversionError a9 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["a", "b"], {}); + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|Error a9 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["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|CsvConversionError a10 = parseRecordAsRecordType([{"a": "a", "b": "a"}, {"a": 1, "b": 2}], {}); + & readonly|Error a10 = parseRecordAsRecordType([{"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 {enable} function testIntersectionExpectedTypes3() returns error? { - (int[] & readonly)[]|CsvConversionError a = parseListAsListType([["1", "2"], ["4", "5"]], {}); + (int[] & readonly)[]|Error a = parseListAsListType([["1", "2"], ["4", "5"]], {}); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|CsvConversionError a2 = parseListAsListType([["a", "a"], ["c", "c"]], {}); + ([string, string])[] & readonly|Error a2 = parseListAsListType([["a", "a"], ["c", "c"]], {}); test:assertTrue(a2 is [string, string][] & readonly); test:assertEquals(a2, [["a", "a"], ["c", "c"]]); - (record{int a; string b;} & readonly)[]|CsvConversionError a3 = parseListAsRecordType([["1", "2"], ["4", "5"]], ["a", "b"], {}); + (record{int a; string b;} & readonly)[]|Error a3 = parseListAsRecordType([["1", "2"], ["4", "5"]], ["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|CsvConversionError a4 = parseListAsRecordType([["a", "a"], ["c", "c"]], ["a", "b"], {}); + record{|string...;|}[] & readonly|Error a4 = parseListAsRecordType([["a", "a"], ["c", "c"]], ["a", "b"], {}); test:assertTrue(a4 is record{|string...;|}[] & readonly); test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - ([int] & readonly)[]|CsvConversionError a5 = parseListAsListType([["1", "2"], ["4", "5"]], {}); + ([int] & readonly)[]|Error a5 = parseListAsListType([["1", "2"], ["4", "5"]], {}); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|CsvConversionError a6 = parseListAsListType([["a", "a"], ["c", "c"]], {}); + ([string, string])[] & readonly|Error a6 = parseListAsListType([["a", "a"], ["c", "c"]], {}); test:assertTrue(a6 is [string, string][] & readonly); test:assertEquals(a6, [["a", "a"], ["c", "c"]]); - (record{int a; string b;} & readonly)[]|CsvConversionError a7 = parseListAsRecordType([["1", "2"], ["4", "5"]], ["a", "b"], {}); + (record{int a; string b;} & readonly)[]|Error a7 = parseListAsRecordType([["1", "2"], ["4", "5"]], ["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|CsvConversionError a8 = parseListAsRecordType([["a", "a"], ["c", "c"]], ["a", "b"], {}); + map[] & readonly|Error a8 = parseListAsRecordType([["a", "a"], ["c", "c"]], ["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)[]|CsvConversionError a9 = parseListAsListType([["1", "2"], ["a", "b"]], {}); + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|Error a9 = parseListAsListType([["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|CsvConversionError a10 = parseListAsRecordType([["a", "a"], ["1", "2"]], ["a", "b"], {}); + & readonly|Error a10 = parseListAsRecordType([["a", "a"], ["1", "2"]], ["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|CsvConversionError a11 = parseListAsRecordType([["a", "a"], ["1", "2"]], ["a", "b"], {}); + & readonly|Error a11 = parseListAsRecordType([["a", "a"], ["1", "2"]], ["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/test_with_singleton_test.bal b/ballerina/tests/test_with_singleton_test.bal index 14fadb9..fd3a10d 100644 --- a/ballerina/tests/test_with_singleton_test.bal +++ b/ballerina/tests/test_with_singleton_test.bal @@ -13,9 +13,9 @@ function debugTest() returns error? { var value4 = [["1", "1", "1", "1", "a", "1", "1", "1"], ["1", "1", "1", "1", "a", "1", "1", "1"]]; - // SubtypeRecord2[]|CsvConversionError a14 = parseListAsRecordType(value4, + // SubtypeRecord2[]|Error a14 = parseListAsRecordType(value4, // ["a", "c", "d", "e", "f", "g", "h", "i"], {}); - record {int a; int b;}[]|CsvConversionError a14 = parseListAsRecordType([["1", "2"], ["1", "2"]], + record {int a; int b;}[]|Error a14 = parseListAsRecordType([["1", "2"], ["1", "2"]], ["a", "b"], {}); test:assertEquals(a14, [{a: 1, c: 1}, {a: 1, c: 1}]); } @@ -24,91 +24,91 @@ type Singleton 1; @test:Config {enable} function testSingletonExpectedTypes() returns error? { - 1[][]|CsvConversionError a = parseStringToList(string `a, b, c + 1[][]|Error a = parseStringToList(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;}[]|CsvConversionError a2 = parseStringToRecord(string `a, b, c + record {1|2 a; 1 b;}[]|Error a2 = parseStringToRecord(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...;|}[]|CsvConversionError a3 = parseStringToRecord(string `a, b, c + record {|1 a; 1|2...;|}[]|Error a3 = parseStringToRecord(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...][]|CsvConversionError a4 = parseStringToList(string `a, b, c + [Singleton, Singleton...][]|Error a4 = parseStringToList(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;|}[]|CsvConversionError a5 = parseStringToRecord(string `a, b, c + record {|1|"a" a; 1 b;|}[]|Error a5 = parseStringToRecord(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a5, [{a: 1, b: 1}, {a: 1, b: 1}]); - [Singleton, Singleton][]|CsvConversionError a6 = parseStringToList(string `a, b, c + [Singleton, Singleton][]|Error a6 = parseStringToList(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a6, [[1, 1], [1, 1]]); - record {|"a"|"c" a; "b" b;|}[]|CsvConversionError a7 = parseStringToRecord(string `a, b, c + record {|"a"|"c" a; "b" b;|}[]|Error a7 = parseStringToRecord(string `a, b, c a, c, 1 1, 1,1 `); - test:assertTrue(a7 is CsvConversionError); + test:assertTrue(a7 is Error); test:assertEquals((a7).message(), generateErrorMessageForInvalidCast("c", "\"b\"")); - ["a"|"d", "b"][]|CsvConversionError a8 = parseStringToList(string `a, b, c + ["a"|"d", "b"][]|Error a8 = parseStringToList(string `a, b, c a, b, 1 c, b,1 `); - test:assertTrue(a8 is CsvConversionError); + test:assertTrue(a8 is Error); test:assertEquals((a8).message(), generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); } @test:Config {enable} function testSingletonExpectedTypes2() returns error? { - 1[][]|CsvConversionError a = parseStringToList(string `a, b, c + 1[][]|Error a = parseStringToList(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;}[]|CsvConversionError a2 = parseStringToRecord(string `a, b, c + record {1|2 a; 1 b;}[]|Error a2 = parseStringToRecord(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...;|}[]|CsvConversionError a3 = parseStringToRecord(string `a, b, c + record {|1 a; 1|2...;|}[]|Error a3 = parseStringToRecord(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...][]|CsvConversionError a4 = parseStringToList(string `a, b, c + [Singleton, Singleton...][]|Error a4 = parseStringToList(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;|}[]|CsvConversionError a5 = parseStringToRecord(string `a, b, c + record {|1|"a" a; 1 b;|}[]|Error a5 = parseStringToRecord(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a5, [{a: 1, b: 1}, {a: 1, b: 1}]); - [Singleton, Singleton][]|CsvConversionError a6 = parseStringToList(string `a, b, c + [Singleton, Singleton][]|Error a6 = parseStringToList(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a6, [[1, 1], [1, 1]]); - record {|"a"|"c" a; "b" b;|}[]|CsvConversionError a7 = parseStringToRecord(string `a, b, c + record {|"a"|"c" a; "b" b;|}[]|Error a7 = parseStringToRecord(string `a, b, c a, c, 1 1, 1,1 `); - test:assertTrue(a7 is CsvConversionError); + test:assertTrue(a7 is Error); test:assertEquals((a7).message(), generateErrorMessageForInvalidCast("c", "\"b\"")); - ["a"|"d", "b"][]|CsvConversionError a8 = parseStringToList(string `a, b, c + ["a"|"d", "b"][]|Error a8 = parseStringToList(string `a, b, c a, b, 1 c, b,1 `); - test:assertTrue(a8 is CsvConversionError); + test:assertTrue(a8 is Error); test:assertEquals((a8).message(), generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); } @@ -147,78 +147,78 @@ function testSubtypeExpectedTypes() returns error? { var value4 = [["1", "1", "1", "1", "a", "1", "1", "1"], ["1", "1", "1", "1", "a", "1", "1", "1"]]; - SubtypeRecord[]|CsvConversionError a = parseStringToRecord(string `a, c, d, e, f, g, h, i + SubtypeRecord[]|Error a = parseStringToRecord(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[]|CsvConversionError a2 = parseStringToRecord(string `a, c, d, e, f, g, h, i + SubtypeRecord2[]|Error a2 = parseStringToRecord(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[]|CsvConversionError a3 = parseStringToRecord(string `a, c, d, e, f, g, h, i + SubtypeRecord3[]|Error a3 = parseStringToRecord(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[]|CsvConversionError a4 = parseStringToList(string `a, c, d, e, f, g, h, i + SubtypeTuple[]|Error a4 = parseStringToList(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[]|CsvConversionError a5 = parseStringToList(string `a, c, d, e, f, g, h, i + SubtypeTuple2[]|Error a5 = parseStringToList(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[]|CsvConversionError a6 = parseStringToList(string `a, c, d, e, f, g, h, i + SubtypeTuple3[]|Error a6 = parseStringToList(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[]|CsvConversionError a7 = parseRecordAsRecordType(value1, {}); + SubtypeRecord[]|Error a7 = parseRecordAsRecordType(value1, {}); test:assertEquals(a7, value1); - SubtypeRecord2[]|CsvConversionError a8 = parseRecordAsRecordType(value1, {}); + SubtypeRecord2[]|Error a8 = parseRecordAsRecordType(value1, {}); test:assertEquals(a8, [{a: 1, c: 1}, {a: 1, c: 1}]); - SubtypeRecord3[]|CsvConversionError a9 = parseRecordAsRecordType(value1, {}); + SubtypeRecord3[]|Error a9 = parseRecordAsRecordType(value1, {}); test:assertEquals(a9, value1); - SubtypeTuple[]|CsvConversionError a10 = parseRecordAsListType(value1, + SubtypeTuple[]|Error a10 = parseRecordAsListType(value1, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a10, value3); - SubtypeTuple2[]|CsvConversionError a11 = parseRecordAsListType(value1, + SubtypeTuple2[]|Error a11 = parseRecordAsListType(value1, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a11, [[1, 1], [1, 1]]); - SubtypeTuple3[]|CsvConversionError a12 = parseRecordAsListType(value1, + SubtypeTuple3[]|Error a12 = parseRecordAsListType(value1, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a12, value3); - SubtypeRecord[]|CsvConversionError a13 = parseListAsRecordType(value4, + SubtypeRecord[]|Error a13 = parseListAsRecordType(value4, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a13, value1); - SubtypeRecord2[]|CsvConversionError a14 = parseListAsRecordType(value4, + SubtypeRecord2[]|Error a14 = parseListAsRecordType(value4, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a14, [{a: 1, c: 1}, {a: 1, c: 1}]); - SubtypeRecord3[]|CsvConversionError a15 = parseListAsRecordType(value4, + SubtypeRecord3[]|Error a15 = parseListAsRecordType(value4, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a15, value1); - SubtypeTuple[]|CsvConversionError a16 = parseListAsListType(value4, {}); + SubtypeTuple[]|Error a16 = parseListAsListType(value4, {}); test:assertEquals(a16, value3); - SubtypeTuple2[]|CsvConversionError a17 = parseListAsListType(value4, {}); + SubtypeTuple2[]|Error a17 = parseListAsListType(value4, {}); test:assertEquals(a17, [[1, 1], [1, 1]]); - SubtypeTuple3[]|CsvConversionError a18 = parseListAsListType(value4, {}); + SubtypeTuple3[]|Error a18 = parseListAsListType(value4, {}); test:assertEquals(a18, value3); } diff --git a/ballerina/tests/test_with_union_types.bal b/ballerina/tests/test_with_union_types.bal index 5c7c2ce..31a8ba8 100644 --- a/ballerina/tests/test_with_union_types.bal +++ b/ballerina/tests/test_with_union_types.bal @@ -12,7 +12,7 @@ import ballerina/test; // {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} // ]; -// RecA[]|RecC[]|CsvConversionError csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); +// RecA[]|RecC[]|Error csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); // } type RecA record {int a; string b; boolean c; decimal d; float e; () f;}; @@ -25,7 +25,7 @@ type TupC [int, int, int]; @test:Config {enable} function testParseToStringWithUnionExpectedTypes() returns error? { // TODO: Fix with tests RecA[]|RecC[] - (RecA|RecC)[]|CsvConversionError csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); + (RecA|RecC)[]|Error csv1op1 = parseStringToRecord(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: ()}, @@ -34,7 +34,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecA|RecC)[]|CsvConversionError csv1op2 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecA|RecC)[]|Error csv1op2 = parseStringToRecord(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: ()}, @@ -42,42 +42,42 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecC|RecA)[]|CsvConversionError csv1op3 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecC|RecA)[]|Error csv1op3 = parseStringToRecord(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)[]|CsvConversionError csv1op4 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecB|RecA)[]|Error csv1op4 = parseStringToRecord(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)[]|CsvConversionError csv1op5 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecA|RecB)[]|Error csv1op5 = parseStringToRecord(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;|})[]|CsvConversionError csv1op6 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (record{|int a;|}|record{|string b;|})[]|Error csv1op6 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|CsvConversionError csv1op7 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (record{|string b;|}|record{|int a;|})[]|Error csv1op7 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|CsvConversionError csv1op8 = parseStringToRecord(csvStringData1, {header: 1}); + (record{|string...;|}|record{|int...;|})[]|Error csv1op8 = parseStringToRecord(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"}, @@ -86,7 +86,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - (record{|int...;|}|record{|string...;|})[]|CsvConversionError csv1op9 = parseStringToRecord(csvStringData1, {header: 1}); + (record{|int...;|}|record{|string...;|})[]|Error csv1op9 = parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -95,7 +95,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, d: 3, e: 3} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|CsvConversionError csv1op10 = parseStringToRecord(csvStringData1, {header: 1}); + (record{|int a; string...;|}|record{|string a; int...;|})[]|Error csv1op10 = parseStringToRecord(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"}, @@ -104,7 +104,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|CsvConversionError csv1op11 = parseStringToRecord(csvStringData1, {header: 1}); + (record{|string a; int...;|}|record{|int a; string...;|})[]|Error csv1op11 = parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -113,7 +113,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "5", d: 3, e: 3} ]); - (record{|int a; int b;|}|record{|string a; string...;|})[]|CsvConversionError csv1op12 = parseStringToRecord(string ` + (record{|int a; int b;|}|record{|string a; string...;|})[]|Error csv1op12 = parseStringToRecord(string ` a,b 1, 2 a, b`, {header: 1}); @@ -122,7 +122,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "a", b: "b"} ]); - ([int, int]|[string, string])[]|CsvConversionError csv1op13 = parseStringToList(string ` + ([int, int]|[string, string])[]|Error csv1op13 = parseStringToList(string ` a,b 1, 2 a, b`, {header: 1}); @@ -142,7 +142,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - (RecA|RecC)[]|CsvConversionError csv1op1 = parseRecordAsRecordType(value, {}); + (RecA|RecC)[]|Error csv1op1 = parseRecordAsRecordType(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: ()}, @@ -151,7 +151,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecA|RecC)[]|CsvConversionError csv1op2 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecA|RecC)[]|Error csv1op2 = parseRecordAsRecordType(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: ()}, @@ -159,42 +159,42 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecC|RecA)[]|CsvConversionError csv1op3 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecC|RecA)[]|Error csv1op3 = parseRecordAsRecordType(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)[]|CsvConversionError csv1op4 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecB|RecA)[]|Error csv1op4 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op4, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (RecA|RecB)[]|CsvConversionError csv1op5 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecA|RecB)[]|Error csv1op5 = parseRecordAsRecordType(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;|})[]|CsvConversionError csv1op6 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (record{|int a;|}|record{|string b;|})[]|Error csv1op6 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|CsvConversionError csv1op7 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (record{|string b;|}|record{|int a;|})[]|Error csv1op7 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|CsvConversionError csv1op8 = parseRecordAsRecordType(value, {}); + (record{|string...;|}|record{|int...;|})[]|Error csv1op8 = parseRecordAsRecordType(value, {}); test:assertEquals(csv1op8, [ {b: "string1"}, {b: "string2"}, @@ -203,7 +203,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {b: "string5"} ]); - (record{|int...;|}|record{|string...;|})[]|CsvConversionError csv1op9 = parseRecordAsRecordType(value, {}); + (record{|int...;|}|record{|string...;|})[]|Error csv1op9 = parseRecordAsRecordType(value, {}); test:assertEquals(csv1op9, [ {a: 1, d: 2, e: 2}, {a: 2, d: 0, e: 0}, @@ -212,7 +212,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, d: 3, e: 3} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|CsvConversionError csv1op10 = parseRecordAsRecordType(value, {}); + (record{|int a; string...;|}|record{|string a; int...;|})[]|Error csv1op10 = parseRecordAsRecordType(value, {}); test:assertEquals(csv1op10, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -221,7 +221,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|CsvConversionError csv1op11 = parseRecordAsRecordType(value, {}); + (record{|string a; int...;|}|record{|int a; string...;|})[]|Error csv1op11 = parseRecordAsRecordType(value, {}); test:assertEquals(csv1op11, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -230,11 +230,11 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5"} ]); - (record{|string a; int...;|}|record{|string a; string...;|})[]|CsvConversionError csv1op12 = parseRecordAsRecordType(value, {}); - test:assertTrue(csv1op12 is CsvConversionError); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| string a; int...; |}|data.csv:record {| string a; string...; |})[]'"); + (record{|string a; int...;|}|record{|string a; string...;|})[]|Error csv1op12 = parseRecordAsRecordType(value, {}); + test:assertTrue(csv1op12 is Error); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| string a; int...; |}|data.csv:record {| string a; string...; |})[]'"); - (record{|int a; int...;|}|record{|string a; string...;|})[]|CsvConversionError csv1op13 = parseRecordAsRecordType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); + (record{|int a; int...;|}|record{|string a; string...;|})[]|Error csv1op13 = parseRecordAsRecordType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, {a: "a", b: "b"} @@ -251,7 +251,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - (RecA|RecC)[]|CsvConversionError csv1op1 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + (RecA|RecC)[]|Error csv1op1 = parseListAsRecordType(value, ["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: ()}, @@ -260,7 +260,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecA|RecC)[]|CsvConversionError csv1op2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecA|RecC)[]|Error csv1op2 = parseListAsRecordType(value, ["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: ()}, @@ -268,49 +268,49 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecC|RecA)[]|CsvConversionError csv1op3 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecC|RecA)[]|Error csv1op3 = parseListAsRecordType(value, ["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)[]|CsvConversionError csv1op4 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecB|RecA)[]|Error csv1op4 = parseListAsRecordType(value, ["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)[]|CsvConversionError csv1op5 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecA|RecB)[]|Error csv1op5 = parseListAsRecordType(value, ["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;|})[]|CsvConversionError csv1op6 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (record{|int a;|}|record{|string b;|})[]|Error csv1op6 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|CsvConversionError csv1op7 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (record{|string b;|}|record{|int a;|})[]|Error csv1op7 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|CsvConversionError csv1op8 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [4, 2]}); + (record{|string...;|}|record{|int...;|})[]|Error csv1op8 = parseListAsRecordType(value, ["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...;|})[]|CsvConversionError csv1op9 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); + (record{|int...;|}|record{|string...;|})[]|Error csv1op9 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -319,7 +319,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, d: 3} ]); - (record{|int...;|}|record{|string...;|})[]|CsvConversionError csv1op9_2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + (record{|int...;|}|record{|string...;|})[]|Error csv1op9_2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); test:assertEquals(csv1op9_2, [ {}, {}, @@ -328,14 +328,14 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|CsvConversionError csv1op10 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, -1, 4]}); + (record{|int a; string...;|}|record{|string a; int...;|})[]|Error csv1op10 = parseListAsRecordType(value, ["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...;|})[]|CsvConversionError csv1op11 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + (record{|string a; int...;|}|record{|int a; string...;|})[]|Error csv1op11 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -345,11 +345,11 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { ]); // Error Message is Wrong, Needs to check - (record{|int a; int...;|}|record{|int a; string...;|})[]|CsvConversionError csv1op12 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); - test:assertTrue(csv1op12 is CsvConversionError); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| int a; int...; |}|data.csv:record {| int a; string...; |})[]'"); + (record{|int a; int...;|}|record{|int a; string...;|})[]|Error csv1op12 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + test:assertTrue(csv1op12 is Error); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| int a; int...; |}|data.csv:record {| int a; string...; |})[]'"); - (record{|int a; int...;|}|record{|string a; string...;|})[]|CsvConversionError csv1op13 = parseListAsRecordType([["1", "2"], ["a", "b"]], ["a", "b"], {}); + (record{|int a; int...;|}|record{|string a; string...;|})[]|Error csv1op13 = parseListAsRecordType([["1", "2"], ["a", "b"]], ["a", "b"], {}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, {a: "a", b: "b"} @@ -367,7 +367,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - (TupA|TupC)[]|CsvConversionError csv1op1 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + (TupA|TupC)[]|Error csv1op1 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -376,7 +376,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupA|TupC)[]|CsvConversionError csv1op2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupA|TupC)[]|Error csv1op2 = parseRecordAsListType(value, ["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,14 +384,14 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupC|TupA)[]|CsvConversionError csv1op3 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupC|TupA)[]|Error csv1op3 = parseRecordAsListType(value, ["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)[]|CsvConversionError csv1op4 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupB|TupA)[]|Error csv1op4 = parseRecordAsListType(value, ["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, ()], @@ -399,52 +399,52 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { ]); // TODO: Change the Error Message - (TupB|[boolean])[]|CsvConversionError csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); - test:assertTrue(csv1op4_2 is CsvConversionError); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB|[boolean])[]'"); + (TupB|[boolean])[]|Error csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertTrue(csv1op4_2 is Error); + test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB|[boolean])[]'"); - (TupA|TupB)[]|CsvConversionError csv1op5 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupA|TupB)[]|Error csv1op5 = parseRecordAsListType(value, ["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])[]|CsvConversionError csv1op6 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + ([int]|[string])[]|Error csv1op6 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - ([string]|[int])[]|CsvConversionError csv1op7 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + ([string]|[int])[]|Error csv1op7 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ [1], [3], [5] ]); - ([string...]|[int...])[]|CsvConversionError csv1op8 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op8 is CsvConversionError); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([string...]|[int...])[]'"); + ([string...]|[int...])[]|Error csv1op8 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op8 is Error); + test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([string...]|[int...])[]'"); - ([int...]|[string...])[]|CsvConversionError csv1op9 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op9 is CsvConversionError); - test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '([int...]|[string...])[]'"); + ([int...]|[string...])[]|Error csv1op9 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op9 is Error); + test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '([int...]|[string...])[]'"); - ([int, string...]|[string, int...])[]|CsvConversionError csv1op10 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op10 is CsvConversionError); - test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '([int,string...]|[string,int...])[]'"); + ([int, string...]|[string, int...])[]|Error csv1op10 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op10 is Error); + test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '([int,string...]|[string,int...])[]'"); - ([string, int...]|[int, string...])[]|CsvConversionError csv1op11 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op11 is CsvConversionError); - test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '([string,int...]|[int,string...])[]'"); + ([string, int...]|[int, string...])[]|Error csv1op11 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op11 is Error); + test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '([string,int...]|[int,string...])[]'"); - ([string, int...]|[string, string...])[]|CsvConversionError csv1op12 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op12 is CsvConversionError); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...]|[string,string...])[]'"); + ([string, int...]|[string, string...])[]|Error csv1op12 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op12 is Error); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...]|[string,string...])[]'"); - ([int, int...]|[string, string...])[]|CsvConversionError csv1op13 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["a", "b"], {}); + ([int, int...]|[string, string...])[]|Error csv1op13 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["a", "b"], {}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] @@ -461,7 +461,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - (TupA|TupC)[]|CsvConversionError csv1op1 = parseListAsListType(value, {}); + (TupA|TupC)[]|Error csv1op1 = parseListAsListType(value, {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -470,7 +470,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupA|TupC)[]|CsvConversionError csv1op2 = parseListAsListType(value, {skipLines: [2, 4]}); + (TupA|TupC)[]|Error csv1op2 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertTrue(csv1op2 is (TupA|TupC)[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -478,14 +478,14 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupC|TupA)[]|CsvConversionError csv1op3 = parseListAsListType(value, {skipLines: [2, 4]}); + (TupC|TupA)[]|Error csv1op3 = parseListAsListType(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)[]|CsvConversionError csv1op4 = parseListAsListType(value, {skipLines: [2, 4]}); + (TupB|TupA)[]|Error csv1op4 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op4, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], @@ -493,42 +493,42 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ]); // TODO: Change the Error Message - (TupB|[boolean])[]|CsvConversionError csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); - test:assertTrue(csv1op4_2 is CsvConversionError); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB|[boolean])[]'"); + (TupB|[boolean])[]|Error csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); + test:assertTrue(csv1op4_2 is Error); + test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB|[boolean])[]'"); - (TupA|TupB)[]|CsvConversionError csv1op5 = parseListAsListType(value, {skipLines: [2, 4]}); + (TupA|TupB)[]|Error csv1op5 = parseListAsListType(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])[]|CsvConversionError csv1op6 = parseListAsListType(value, {skipLines: [2, 4]}); + ([int]|[string])[]|Error csv1op6 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - ([string]|[int])[]|CsvConversionError csv1op7 = parseListAsListType(value, {skipLines: [2, 4]}); + ([string]|[int])[]|Error csv1op7 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ ["1"], ["3"], ["5"] ]); - ([boolean...]|[int...])[]|CsvConversionError csv1op8 = parseListAsListType(value, {stringConversion: false}); - test:assertTrue(csv1op8 is CsvConversionError); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...]|[int...])[]'"); + ([boolean...]|[int...])[]|Error csv1op8 = parseListAsListType(value, {stringConversion: false}); + test:assertTrue(csv1op8 is Error); + test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...]|[int...])[]'"); - ([string...]|[int...])[]|CsvConversionError csv1op8_2 = parseListAsListType(value, {}); + ([string...]|[int...])[]|Error csv1op8_2 = parseListAsListType(value, {}); test:assertEquals(csv1op8_2, value); - ([int...]|[string...])[]|CsvConversionError csv1op9 = parseListAsListType(value, {}); + ([int...]|[string...])[]|Error csv1op9 = parseListAsListType(value, {}); test:assertEquals(csv1op9, value); - ([int, string...]|[string, int...])[]|CsvConversionError csv1op10 = parseListAsListType(value, {}); + ([int, string...]|[string, int...])[]|Error csv1op10 = parseListAsListType(value, {}); test:assertEquals(csv1op10, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -537,7 +537,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - ([string, int...]|[int, string...])[]|CsvConversionError csv1op11 = parseListAsListType(value, {}); + ([string, int...]|[int, string...])[]|Error csv1op11 = parseListAsListType(value, {}); test:assertEquals(csv1op11, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -546,10 +546,10 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - ([string, int...]|[string, string...])[]|CsvConversionError csv1op12 = parseListAsListType(value, {}); + ([string, int...]|[string, string...])[]|Error csv1op12 = parseListAsListType(value, {}); test:assertEquals(csv1op12, value); - ([int, int...]|[string, string...])[]|CsvConversionError csv1op13 = parseListAsListType([["1", "2"], ["a", "b"]], {}); + ([int, int...]|[string, string...])[]|Error csv1op13 = parseListAsListType([["1", "2"], ["a", "b"]], {}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] @@ -559,7 +559,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { @test:Config {enable} function testParseToStringWithUnionExpectedTypes6() returns error? { // TODO: Fix with tests RecA[]|RecC[] - RecA[]|RecC[]|CsvConversionError csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); + RecA[]|RecC[]|Error csv1op1 = parseStringToRecord(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: ()}, @@ -568,7 +568,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|CsvConversionError csv1op2 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecA[]|RecC[]|Error csv1op2 = parseStringToRecord(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: ()}, @@ -576,42 +576,42 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|CsvConversionError csv1op3 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecC[]|RecA[]|Error csv1op3 = parseStringToRecord(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[]|CsvConversionError csv1op4 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecB[]|RecA[]|Error csv1op4 = parseStringToRecord(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[]|CsvConversionError csv1op5 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecA[]|RecB[]|Error csv1op5 = parseStringToRecord(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;|}[]|CsvConversionError csv1op6 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + record{|int a;|}[]|record{|string b;|}[]|Error csv1op6 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|CsvConversionError csv1op7 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + record{|string b;|}[]|record{|int a;|}[]|Error csv1op7 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|CsvConversionError csv1op8 = parseStringToRecord(csvStringData1, {header: 1}); + record{|string...;|}[]|record{|int...;|}[]|Error csv1op8 = parseStringToRecord(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"}, @@ -620,7 +620,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - record{|int...;|}[]|record{|string...;|}[]|CsvConversionError csv1op9 = parseStringToRecord(csvStringData1, {header: 1}); + record{|int...;|}[]|record{|string...;|}[]|Error csv1op9 = parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -629,7 +629,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, d: 3, e: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|CsvConversionError csv1op10 = parseStringToRecord(csvStringData1, {header: 1}); + record{|int a; string...;|}[]|record{|string a; int...;|}[]|Error csv1op10 = parseStringToRecord(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"}, @@ -638,7 +638,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|CsvConversionError csv1op11 = parseStringToRecord(csvStringData1, {header: 1}); + record{|string a; int...;|}[]|record{|int a; string...;|}[]|Error csv1op11 = parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -647,7 +647,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: "5", d: 3, e: 3} ]); - record{|int a; int b;|}[]|record{|string a; string...;|}[]|CsvConversionError csv1op12 = parseStringToRecord(string ` + record{|int a; int b;|}[]|record{|string a; string...;|}[]|Error csv1op12 = parseStringToRecord(string ` a,b 1, 2 a, b`, {header: 1}); @@ -667,7 +667,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - RecA[]|RecC[]|CsvConversionError csv1op1 = parseRecordAsRecordType(value, {}); + RecA[]|RecC[]|Error csv1op1 = parseRecordAsRecordType(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: ()}, @@ -676,7 +676,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|CsvConversionError csv1op2 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecA[]|RecC[]|Error csv1op2 = parseRecordAsRecordType(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: ()}, @@ -684,42 +684,42 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|CsvConversionError csv1op3 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecC[]|RecA[]|Error csv1op3 = parseRecordAsRecordType(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[]|CsvConversionError csv1op4 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecB[]|RecA[]|Error csv1op4 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op4, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - RecA[]|RecB[]|CsvConversionError csv1op5 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecA[]|RecB[]|Error csv1op5 = parseRecordAsRecordType(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;|}[]|CsvConversionError csv1op6 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + record{|int a;|}[]|record{|string b;|}[]|Error csv1op6 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|CsvConversionError csv1op7 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + record{|string b;|}[]|record{|int a;|}[]|Error csv1op7 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|CsvConversionError csv1op8 = parseRecordAsRecordType(value, {}); + record{|string...;|}[]|record{|int...;|}[]|Error csv1op8 = parseRecordAsRecordType(value, {}); test:assertEquals(csv1op8, [ {b: "string1"}, {b: "string2"}, @@ -728,7 +728,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {b: "string5"} ]); - record{|int...;|}[]|record{|string...;|}[]|CsvConversionError csv1op9 = parseRecordAsRecordType(value, {}); + record{|int...;|}[]|record{|string...;|}[]|Error csv1op9 = parseRecordAsRecordType(value, {}); test:assertEquals(csv1op9, [ {a: 1, d: 2, e: 2}, {a: 2, d: 0, e: 0}, @@ -737,7 +737,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, d: 3, e: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|CsvConversionError csv1op10 = parseRecordAsRecordType(value, {}); + record{|int a; string...;|}[]|record{|string a; int...;|}[]|Error csv1op10 = parseRecordAsRecordType(value, {}); test:assertEquals(csv1op10, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -746,7 +746,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|CsvConversionError csv1op11 = parseRecordAsRecordType(value, {}); + record{|string a; int...;|}[]|record{|int a; string...;|}[]|Error csv1op11 = parseRecordAsRecordType(value, {}); test:assertEquals(csv1op11, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -755,9 +755,9 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5"} ]); - record{|string a; int...;|}[]|record{|string a; string...;|}[]|CsvConversionError csv1op12 = parseRecordAsRecordType(value, {}); - test:assertTrue(csv1op12 is CsvConversionError); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| string a; int...; |}[]|data.csv:record {| string a; string...; |}[])'"); + record{|string a; int...;|}[]|record{|string a; string...;|}[]|Error csv1op12 = parseRecordAsRecordType(value, {}); + test:assertTrue(csv1op12 is Error); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| string a; int...; |}[]|data.csv:record {| string a; string...; |}[])'"); } @test:Config {enable} @@ -770,7 +770,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - RecA[]|RecC[]|CsvConversionError csv1op1 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + RecA[]|RecC[]|Error csv1op1 = parseListAsRecordType(value, ["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: ()}, @@ -779,7 +779,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|CsvConversionError csv1op2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecA[]|RecC[]|Error csv1op2 = parseListAsRecordType(value, ["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: ()}, @@ -787,49 +787,49 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|CsvConversionError csv1op3 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecC[]|RecA[]|Error csv1op3 = parseListAsRecordType(value, ["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[]|CsvConversionError csv1op4 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecB[]|RecA[]|Error csv1op4 = parseListAsRecordType(value, ["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[]|CsvConversionError csv1op5 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecA[]|RecB[]|Error csv1op5 = parseListAsRecordType(value, ["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;|}[]|CsvConversionError csv1op6 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + record{|int a;|}[]|record{|string b;|}[]|Error csv1op6 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|CsvConversionError csv1op7 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + record{|string b;|}[]|record{|int a;|}[]|Error csv1op7 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|CsvConversionError csv1op8 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [4, 2]}); + record{|string...;|}[]|record{|int...;|}[]|Error csv1op8 = parseListAsRecordType(value, ["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...;|}[]|CsvConversionError csv1op9 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); + record{|int...;|}[]|record{|string...;|}[]|Error csv1op9 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -838,7 +838,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, d: 3} ]); - record{|int...;|}[]|record{|string...;|}[]|CsvConversionError csv1op9_2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + record{|int...;|}[]|record{|string...;|}[]|Error csv1op9_2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); test:assertEquals(csv1op9_2, [ {}, {}, @@ -847,14 +847,14 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|CsvConversionError csv1op10 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, -1, 4]}); + record{|int a; string...;|}[]|record{|string a; int...;|}[]|Error csv1op10 = parseListAsRecordType(value, ["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...;|}[]|CsvConversionError csv1op11 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + record{|string a; int...;|}[]|record{|int a; string...;|}[]|Error csv1op11 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -863,11 +863,11 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", d: 3} ]); - record{|int a; int...;|}[]|record{|int a; string...;|}[]|CsvConversionError csv1op12 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); - test:assertTrue(csv1op12 is CsvConversionError); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| int a; int...; |}[]|data.csv:record {| int a; string...; |}[])'"); + record{|int a; int...;|}[]|record{|int a; string...;|}[]|Error csv1op12 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + test:assertTrue(csv1op12 is Error); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| int a; int...; |}[]|data.csv:record {| int a; string...; |}[])'"); - record{|int a; int...;|}[]|record{|string a; string...;|}[]|CsvConversionError csv1op13 = parseListAsRecordType([["1", "2"], ["a", "b"]], ["a", "b"], {}); + record{|int a; int...;|}[]|record{|string a; string...;|}[]|Error csv1op13 = parseListAsRecordType([["1", "2"], ["a", "b"]], ["a", "b"], {}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, {a: "a", b: "b"} @@ -885,7 +885,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - TupA[]|TupC[]|CsvConversionError csv1op1 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + TupA[]|TupC[]|Error csv1op1 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -894,7 +894,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupA[]|TupC[]|CsvConversionError csv1op2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupA[]|TupC[]|Error csv1op2 = parseRecordAsListType(value, ["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, ()], @@ -902,14 +902,14 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupC[]|TupA[]|CsvConversionError csv1op3 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupC[]|TupA[]|Error csv1op3 = parseRecordAsListType(value, ["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[]|CsvConversionError csv1op4 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupB[]|TupA[]|Error csv1op4 = parseRecordAsListType(value, ["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, ()], @@ -917,50 +917,50 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { ]); // TODO: Change the Error Message - TupB[]|[boolean][]|CsvConversionError csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); - test:assertTrue(csv1op4_2 is CsvConversionError); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB[]|[boolean][])'"); + TupB[]|[boolean][]|Error csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + test:assertTrue(csv1op4_2 is Error); + test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB[]|[boolean][])'"); - TupA[]|TupB[]|CsvConversionError csv1op5 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupA[]|TupB[]|Error csv1op5 = parseRecordAsListType(value, ["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][]|CsvConversionError csv1op6 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + [int][]|[string][]|Error csv1op6 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - [string][]|[int][]|CsvConversionError csv1op7 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + [string][]|[int][]|Error csv1op7 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ [1], [3], [5] ]); - [string...][]|[int...][]|CsvConversionError csv1op8 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op8 is CsvConversionError); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([string...][]|[int...][])'"); + [string...][]|[int...][]|Error csv1op8 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op8 is Error); + test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([string...][]|[int...][])'"); - [int...][]|[string...][]|CsvConversionError csv1op9 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op9 is CsvConversionError); - test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '([int...][]|[string...][])'"); + [int...][]|[string...][]|Error csv1op9 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op9 is Error); + test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '([int...][]|[string...][])'"); - [int, string...][]|[string, int...][]|CsvConversionError csv1op10 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op10 is CsvConversionError); - test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '([int,string...][]|[string,int...][])'"); + [int, string...][]|[string, int...][]|Error csv1op10 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op10 is Error); + test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '([int,string...][]|[string,int...][])'"); - [string, int...][]|[int, string...][]|CsvConversionError csv1op11 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op11 is CsvConversionError); - test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '([string,int...][]|[int,string...][])'"); + [string, int...][]|[int, string...][]|Error csv1op11 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op11 is Error); + test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '([string,int...][]|[int,string...][])'"); - [string, int...][]|[string, string...][]|CsvConversionError csv1op12 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op12 is CsvConversionError); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...][]|[string,string...][])'"); + [string, int...][]|[string, string...][]|Error csv1op12 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op12 is Error); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...][]|[string,string...][])'"); } @test:Config {enable} @@ -973,7 +973,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - TupA[]|TupC[]|CsvConversionError csv1op1 = parseListAsListType(value, {}); + TupA[]|TupC[]|Error csv1op1 = parseListAsListType(value, {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -982,7 +982,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupA[]|TupC[]|CsvConversionError csv1op2 = parseListAsListType(value, {skipLines: [2, 4]}); + TupA[]|TupC[]|Error csv1op2 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertTrue(csv1op2 is TupA[]|TupC[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -990,14 +990,14 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupC[]|TupA[]|CsvConversionError csv1op3 = parseListAsListType(value, {skipLines: [2, 4]}); + TupC[]|TupA[]|Error csv1op3 = parseListAsListType(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[]|CsvConversionError csv1op4 = parseListAsListType(value, {skipLines: [2, 4]}); + TupB[]|TupA[]|Error csv1op4 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op4, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], @@ -1005,42 +1005,42 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { ]); // TODO: Change the Error Message - TupB[]|[boolean][]|CsvConversionError csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); - test:assertTrue(csv1op4_2 is CsvConversionError); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB[]|[boolean][])'"); + TupB[]|[boolean][]|Error csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); + test:assertTrue(csv1op4_2 is Error); + test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB[]|[boolean][])'"); - TupA[]|TupB[]|CsvConversionError csv1op5 = parseListAsListType(value, {skipLines: [2, 4]}); + TupA[]|TupB[]|Error csv1op5 = parseListAsListType(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][]|CsvConversionError csv1op6 = parseListAsListType(value, {skipLines: [2, 4]}); + [int][]|[string][]|Error csv1op6 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - [string][]|[int][]|CsvConversionError csv1op7 = parseListAsListType(value, {skipLines: [2, 4]}); + [string][]|[int][]|Error csv1op7 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ ["1"], ["3"], ["5"] ]); - [boolean...][]|[int...][]|CsvConversionError csv1op8 = parseListAsListType(value, {stringConversion: false}); - test:assertTrue(csv1op8 is CsvConversionError); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...][]|[int...][])'"); + [boolean...][]|[int...][]|Error csv1op8 = parseListAsListType(value, {stringConversion: false}); + test:assertTrue(csv1op8 is Error); + test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...][]|[int...][])'"); - [string...][]|[int...][]|CsvConversionError csv1op8_2 = parseListAsListType(value, {}); + [string...][]|[int...][]|Error csv1op8_2 = parseListAsListType(value, {}); test:assertEquals(csv1op8_2, value); - [int...][]|[string...][]|CsvConversionError csv1op9 = parseListAsListType(value, {}); + [int...][]|[string...][]|Error csv1op9 = parseListAsListType(value, {}); test:assertEquals(csv1op9, value); - [int, string...][]|[string, int...][]|CsvConversionError csv1op10 = parseListAsListType(value, {}); + [int, string...][]|[string, int...][]|Error csv1op10 = parseListAsListType(value, {}); test:assertEquals(csv1op10, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -1049,7 +1049,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - [string, int...][]|[int, string...][]|CsvConversionError csv1op11 = parseListAsListType(value, {}); + [string, int...][]|[int, string...][]|Error csv1op11 = parseListAsListType(value, {}); test:assertEquals(csv1op11, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -1058,7 +1058,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - [string, int...][]|[string, string...][]|CsvConversionError csv1op12 = parseListAsListType(value, {}); + [string, int...][]|[string, string...][]|Error csv1op12 = parseListAsListType(value, {}); test:assertEquals(csv1op12, value); } diff --git a/ballerina/tests/user_config_projection_tests.bal b/ballerina/tests/user_config_projection_tests.bal index 8e33a39..1013f99 100644 --- a/ballerina/tests/user_config_projection_tests.bal +++ b/ballerina/tests/user_config_projection_tests.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() returns error? { -// record {|int a; int? g; int? h;|}[]|CsvConversionError cn = parseStringToRecord(csvStringData1, { +// record {|int a; int? g; int? h;|}[]|Error cn = parseStringToRecord(csvStringData1, { // allowDataProjection: {absentAsNilableType: true}, // header: 1 // }); @@ -12,307 +12,307 @@ import ballerina/test; @test:Config {enable} function testCustomNameAnnotation() returns error? { - RecordWithCustomAnnotation[]|CsvConversionError cn1 = parseStringToRecord(string `b,c + RecordWithCustomAnnotation[]|Error cn1 = parseStringToRecord(string `b,c 1,3`, {}); test:assertEquals(cn1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|CsvConversionError cn2 = parseStringToRecord(string `c,b + RecordWithCustomAnnotation[]|Error cn2 = parseStringToRecord(string `c,b 3,1`, {}); test:assertEquals(cn2, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|CsvConversionError cn3 = parseStringToRecord(string `f,c,b,e + RecordWithCustomAnnotation[]|Error cn3 = parseStringToRecord(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[]|CsvConversionError cn4 = parseStringToRecord(string `d,c + RecordWithCustomAnnotation2[]|Error cn4 = parseStringToRecord(string `d,c 1,3`, {}); test:assertEquals(cn4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|CsvConversionError cn5 = parseStringToRecord(string `c,d + RecordWithCustomAnnotation2[]|Error cn5 = parseStringToRecord(string `c,d 3,1`, {}); test:assertEquals(cn5, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|CsvConversionError cn6 = parseStringToRecord(string `c,f,d,e + RecordWithCustomAnnotation2[]|Error cn6 = parseStringToRecord(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[]|CsvConversionError cn7 = parseStringToRecord(string `a,b + RecordWithCustomAnnotation2[]|Error cn7 = parseStringToRecord(string `a,b 3,1`, {}); - test:assertTrue(cn7 is CsvConversionError); + test:assertTrue(cn7 is Error); test:assertEquals((cn7).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation2[]|CsvConversionError cn8 = parseStringToRecord(string ` c,d,a,b + RecordWithCustomAnnotation2[]|Error cn8 = parseStringToRecord(string ` c,d,a,b 3,1,4,5`, {}); - test:assertTrue(cn8 is CsvConversionError); + test:assertTrue(cn8 is Error); test:assertEquals((cn8).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation3[]|CsvConversionError cn9 = parseStringToRecord(string `d,c + RecordWithCustomAnnotation3[]|Error cn9 = parseStringToRecord(string `d,c 1,3`, {}); test:assertEquals(cn9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|CsvConversionError cn10 = parseStringToRecord(string `c,d + RecordWithCustomAnnotation3[]|Error cn10 = parseStringToRecord(string `c,d 3,1`, {}); test:assertEquals(cn10, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|CsvConversionError cn11 = parseStringToRecord(string `c,f,d,e + RecordWithCustomAnnotation3[]|Error cn11 = parseStringToRecord(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[]|CsvConversionError cn12 = parseStringToRecord(string `a,b + RecordWithCustomAnnotation3[]|Error cn12 = parseStringToRecord(string `a,b 3,1`, {}); - test:assertTrue(cn12 is CsvConversionError); + test:assertTrue(cn12 is Error); test:assertEquals((cn12).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation3[]|CsvConversionError cn13 = parseStringToRecord(string ` c,d,a,b + RecordWithCustomAnnotation3[]|Error cn13 = parseStringToRecord(string ` c,d,a,b 3,1,4,5`, {}); - test:assertTrue(cn13 is CsvConversionError); + test:assertTrue(cn13 is Error); test:assertEquals((cn13).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|CsvConversionError cn14 = parseStringToRecord(string `d,c,z + RecordWithCustomAnnotation4[]|Error cn14 = parseStringToRecord(string `d,c,z 1,3,true`, {}); test:assertEquals(cn14, [{b: 1, a: 3, z: true}]); - RecordWithCustomAnnotation4[]|CsvConversionError cn15 = parseStringToRecord(string `c,d + RecordWithCustomAnnotation4[]|Error cn15 = parseStringToRecord(string `c,d 3,1`, {}); test:assertEquals(cn15, [{b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|CsvConversionError cn16 = parseStringToRecord(string `c,f,d,e + RecordWithCustomAnnotation4[]|Error cn16 = parseStringToRecord(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[]|CsvConversionError cn17 = parseStringToRecord(string `a,b + RecordWithCustomAnnotation4[]|Error cn17 = parseStringToRecord(string `a,b 3,1`, {}); - test:assertTrue(cn17 is CsvConversionError); + test:assertTrue(cn17 is Error); test:assertEquals((cn17).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|CsvConversionError cn18 = parseStringToRecord(string ` c,d,a,b + RecordWithCustomAnnotation4[]|Error cn18 = parseStringToRecord(string ` c,d,a,b 3,1,4,5`, {}); - test:assertTrue(cn18 is CsvConversionError); + test:assertTrue(cn18 is Error); test:assertEquals((cn18).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation5[]|CsvConversionError cn19 = parseStringToRecord(string ` c,d,a,b + RecordWithCustomAnnotation5[]|Error cn19 = parseStringToRecord(string ` c,d,a,b 3,1,4,5`, {}); - test:assertTrue(cn19 is CsvConversionError); + test:assertTrue(cn19 is Error); test:assertEquals((cn19).message(), "Duplicate field found in record fields: 'c'"); - RecordWithCustomAnnotation6[]|CsvConversionError cn20 = parseStringToRecord(string ` c,d,e + RecordWithCustomAnnotation6[]|Error cn20 = parseStringToRecord(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}]); - RecordWithCustomAnnotation7[]|CsvConversionError cn21 = parseStringToRecord(string ` c,d,a + RecordWithCustomAnnotation7[]|Error cn21 = parseStringToRecord(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}]); - RecordWithCustomAnnotation8[]|CsvConversionError cn22 = parseStringToRecord(string ` c,d,a + RecordWithCustomAnnotation8[]|Error cn22 = parseStringToRecord(string ` c,d,a 3,1,4 3,1,4`, {}); - test:assertTrue(cn22 is CsvConversionError); + test:assertTrue(cn22 is Error); test:assertEquals((cn22).message(), "Duplicate field found in record fields: 'c'"); - RecordWithCustomAnnotation[]|CsvConversionError cnrr1 = parseRecordAsRecordType([{"b": 1, "c": 3}], {}); + RecordWithCustomAnnotation[]|Error cnrr1 = parseRecordAsRecordType([{"b": 1, "c": 3}], {}); test:assertEquals(cnrr1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|CsvConversionError cnrr2 = parseRecordAsRecordType([{"c": 3, "b": 1}], {}); + RecordWithCustomAnnotation[]|Error cnrr2 = parseRecordAsRecordType([{"c": 3, "b": 1}], {}); test:assertEquals(cnrr2, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|CsvConversionError cnrr3 = parseRecordAsRecordType( + RecordWithCustomAnnotation[]|Error cnrr3 = parseRecordAsRecordType( [{"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[]|CsvConversionError cnrr4 = parseRecordAsRecordType([{"d": 1, "c": 3}], {}); + RecordWithCustomAnnotation2[]|Error cnrr4 = parseRecordAsRecordType([{"d": 1, "c": 3}], {}); test:assertEquals(cnrr4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|CsvConversionError cnrr5 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + RecordWithCustomAnnotation2[]|Error cnrr5 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); test:assertEquals(cnrr5, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|CsvConversionError cnrr6 = parseRecordAsRecordType( + RecordWithCustomAnnotation2[]|Error cnrr6 = parseRecordAsRecordType( [{"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[]|CsvConversionError cnrr7 = parseRecordAsRecordType([{"a":3, "b": 1}], {}); - test:assertTrue(cnrr7 is CsvConversionError); + RecordWithCustomAnnotation2[]|Error cnrr7 = parseRecordAsRecordType([{"a":3, "b": 1}], {}); + test:assertTrue(cnrr7 is Error); test:assertEquals((cnrr7).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation2[]|CsvConversionError cnrr8 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); - test:assertTrue(cnrr8 is CsvConversionError); + RecordWithCustomAnnotation2[]|Error cnrr8 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + test:assertTrue(cnrr8 is Error); test:assertEquals((cnrr8).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation3[]|CsvConversionError cnrr9 = parseRecordAsRecordType([{"d": 1, "c": 3}], {}); + RecordWithCustomAnnotation3[]|Error cnrr9 = parseRecordAsRecordType([{"d": 1, "c": 3}], {}); test:assertEquals(cnrr9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|CsvConversionError cnrr10 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + RecordWithCustomAnnotation3[]|Error cnrr10 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); test:assertEquals(cnrr10, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|CsvConversionError cnrr11 = parseRecordAsRecordType( + RecordWithCustomAnnotation3[]|Error cnrr11 = parseRecordAsRecordType( [{"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[]|CsvConversionError cnrr12 = parseRecordAsRecordType([{"a": 3, "b": 1}], {}); - test:assertTrue(cnrr12 is CsvConversionError); + RecordWithCustomAnnotation3[]|Error cnrr12 = parseRecordAsRecordType([{"a": 3, "b": 1}], {}); + test:assertTrue(cnrr12 is Error); test:assertEquals((cnrr12).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation3[]|CsvConversionError cnrr13 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); - test:assertTrue(cnrr13 is CsvConversionError); + RecordWithCustomAnnotation3[]|Error cnrr13 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + test:assertTrue(cnrr13 is Error); test:assertEquals((cnrr13).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|CsvConversionError cnrr14 = parseRecordAsRecordType([{"d": 1, "c": 3, "z": true}], {}); + RecordWithCustomAnnotation4[]|Error cnrr14 = parseRecordAsRecordType([{"d": 1, "c": 3, "z": true}], {}); test:assertEquals(cnrr14, [{b: 1, a: 3, z: true}]); - RecordWithCustomAnnotation4[]|CsvConversionError cnrr15 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + RecordWithCustomAnnotation4[]|Error cnrr15 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); test:assertEquals(cnrr15, [{b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|CsvConversionError cnrr16 = parseRecordAsRecordType( + RecordWithCustomAnnotation4[]|Error cnrr16 = parseRecordAsRecordType( [{"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}]); - RecordWithCustomAnnotation4[]|CsvConversionError cnrr17 = parseRecordAsRecordType([{"a": 3, "b": 1}], {}); - test:assertTrue(cnrr17 is CsvConversionError); + RecordWithCustomAnnotation4[]|Error cnrr17 = parseRecordAsRecordType([{"a": 3, "b": 1}], {}); + test:assertTrue(cnrr17 is Error); test:assertEquals((cnrr17).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|CsvConversionError cnrr18 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); - test:assertTrue(cnrr18 is CsvConversionError); + RecordWithCustomAnnotation4[]|Error cnrr18 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + test:assertTrue(cnrr18 is Error); test:assertEquals((cnrr18).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation5[]|CsvConversionError cnrr19 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); - test:assertTrue(cnrr19 is CsvConversionError); + RecordWithCustomAnnotation5[]|Error cnrr19 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); + test:assertTrue(cnrr19 is Error); test:assertEquals((cnrr19).message(), "Duplicate field found in record fields: 'c'"); - RecordWithCustomAnnotation6[]|CsvConversionError cnrr20 = parseRecordAsRecordType( + RecordWithCustomAnnotation6[]|Error cnrr20 = parseRecordAsRecordType( [{"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}]); - RecordWithCustomAnnotation7[]|CsvConversionError cnrr21 = parseRecordAsRecordType( + RecordWithCustomAnnotation7[]|Error cnrr21 = parseRecordAsRecordType( [{"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}]); - RecordWithCustomAnnotation8[]|CsvConversionError cnrr22 = parseRecordAsRecordType( + RecordWithCustomAnnotation8[]|Error cnrr22 = parseRecordAsRecordType( [{"c": 3, "d": 1, "a": 4}, {"c": 3, "d": 1, "a": 4}], {}); - test:assertTrue(cnrr22 is CsvConversionError); + test:assertTrue(cnrr22 is Error); test:assertEquals((cnrr22).message(), "Duplicate field found in record fields: 'c'"); } //TODO: Emable after fix tuple proj @test:Config {enable} function testCustomNameAnnotation2() returns error? { - RecordWithCustomAnnotation[]|CsvConversionError cntr1 = parseListAsRecordType([["1", "3"]], ["b", "c"], {}); + RecordWithCustomAnnotation[]|Error cntr1 = parseListAsRecordType([["1", "3"]], ["b", "c"], {}); test:assertEquals(cntr1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|CsvConversionError cntr2 = parseListAsRecordType([["3", "1"]], ["c", "b"], {}); + RecordWithCustomAnnotation[]|Error cntr2 = parseListAsRecordType([["3", "1"]], ["c", "b"], {}); test:assertEquals(cntr2, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|CsvConversionError cntr3 = parseListAsRecordType( + RecordWithCustomAnnotation[]|Error cntr3 = parseListAsRecordType( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["f", "c", "b", "e"], {}); test:assertEquals(cntr3, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); - RecordWithCustomAnnotation2[]|CsvConversionError cntr4 = parseListAsRecordType([["1", "3"]], ["d", "c"], {}); + RecordWithCustomAnnotation2[]|Error cntr4 = parseListAsRecordType([["1", "3"]], ["d", "c"], {}); test:assertEquals(cntr4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|CsvConversionError cntr5 = parseListAsRecordType([["3","1"]], ["c", "d"], {}); + RecordWithCustomAnnotation2[]|Error cntr5 = parseListAsRecordType([["3","1"]], ["c", "d"], {}); test:assertEquals(cntr5, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|CsvConversionError cntr6 = parseListAsRecordType( + RecordWithCustomAnnotation2[]|Error cntr6 = parseListAsRecordType( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); test:assertEquals(cntr6, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); - RecordWithCustomAnnotation2[]|CsvConversionError cntr7 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); - test:assertTrue(cntr7 is CsvConversionError); + RecordWithCustomAnnotation2[]|Error cntr7 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + test:assertTrue(cntr7 is Error); test:assertEquals((cntr7).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation2[]|CsvConversionError cntr8 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); - test:assertTrue(cntr8 is CsvConversionError); + RecordWithCustomAnnotation2[]|Error cntr8 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr8 is Error); test:assertEquals((cntr8).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation3[]|CsvConversionError cntr9 = parseListAsRecordType([["1", "3"]], ["d", "c"], {}); + RecordWithCustomAnnotation3[]|Error cntr9 = parseListAsRecordType([["1", "3"]], ["d", "c"], {}); test:assertEquals(cntr9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|CsvConversionError cntr10 = parseListAsRecordType([["3", "1"]], ["c", "d"], {}); + RecordWithCustomAnnotation3[]|Error cntr10 = parseListAsRecordType([["3", "1"]], ["c", "d"], {}); test:assertEquals(cntr10, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|CsvConversionError cntr11 = parseListAsRecordType( + RecordWithCustomAnnotation3[]|Error cntr11 = parseListAsRecordType( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); test:assertEquals(cntr11, [{b: 1, a: 3}, {b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|CsvConversionError cntr12 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); - test:assertTrue(cntr12 is CsvConversionError); + RecordWithCustomAnnotation3[]|Error cntr12 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + test:assertTrue(cntr12 is Error); test:assertEquals((cntr12).message(), generateErrorMessageForInvalidHeaders(string `["3","1"]`, "data.csv:RecordWithCustomAnnotation3")); - RecordWithCustomAnnotation3[]|CsvConversionError cntr13 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); - test:assertTrue(cntr13 is CsvConversionError); + RecordWithCustomAnnotation3[]|Error cntr13 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr13 is Error); test:assertEquals((cntr13).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|CsvConversionError cntr14 = parseListAsRecordType([["1", "3", "true"]], ["d", "c", "z"], {}); + RecordWithCustomAnnotation4[]|Error cntr14 = parseListAsRecordType([["1", "3", "true"]], ["d", "c", "z"], {}); test:assertEquals(cntr14, [{b: 1, a: 3, z: true}]); - RecordWithCustomAnnotation4[]|CsvConversionError cntr15 = parseListAsRecordType([["3", "1"]], ["c", "d"], {}); + RecordWithCustomAnnotation4[]|Error cntr15 = parseListAsRecordType([["3", "1"]], ["c", "d"], {}); test:assertEquals(cntr15, [{b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|CsvConversionError cntr16 = parseListAsRecordType( + RecordWithCustomAnnotation4[]|Error cntr16 = parseListAsRecordType( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); test:assertEquals(cntr16, [{b: 1, a: 3}, {b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|CsvConversionError cntr17 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); - test:assertTrue(cntr17 is CsvConversionError); + RecordWithCustomAnnotation4[]|Error cntr17 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + test:assertTrue(cntr17 is Error); test:assertEquals((cntr17).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|CsvConversionError cntr18 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); - test:assertTrue(cntr18 is CsvConversionError); + RecordWithCustomAnnotation4[]|Error cntr18 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr18 is Error); test:assertEquals((cntr18).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation5[]|CsvConversionError cntr19 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); - test:assertTrue(cntr19 is CsvConversionError); + RecordWithCustomAnnotation5[]|Error cntr19 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr19 is Error); test:assertEquals((cntr19).message(), "Duplicate field found in record fields: 'c'"); - RecordWithCustomAnnotation6[]|CsvConversionError cntr20 = parseListAsRecordType( + RecordWithCustomAnnotation6[]|Error cntr20 = parseListAsRecordType( [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "e"], {}); test:assertEquals(cntr20, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); - RecordWithCustomAnnotation7[]|CsvConversionError cntr21 = parseListAsRecordType( + RecordWithCustomAnnotation7[]|Error cntr21 = parseListAsRecordType( [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "a"], {}); test:assertEquals(cntr21, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); - RecordWithCustomAnnotation8[]|CsvConversionError cntr22 = parseListAsRecordType( + RecordWithCustomAnnotation8[]|Error cntr22 = parseListAsRecordType( [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "a"], {}); - test:assertTrue(cntr22 is CsvConversionError); + test:assertTrue(cntr22 is Error); test:assertEquals((cntr22).message(), "Duplicate field found in record fields: 'c'"); } @test:Config {enable} function testAbsentAsNilableConfig() returns error? { - record {|int a; int? g; int? h;|}[]|CsvConversionError cn = parseStringToRecord(csvStringData1, { + record {|int a; int? g; int? h;|}[]|Error cn = parseStringToRecord(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?;|}[]|CsvConversionError cn2 = parseStringToRecord(csvStringData1, { + record {|int a; int? g?;|}[]|Error cn2 = parseStringToRecord(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn2, [{a: 1}]); - record {|int a; int g?;|}[]|CsvConversionError cn3 = parseStringToRecord(csvStringData1, { + record {|int a; int g?;|}[]|Error cn3 = parseStringToRecord(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn3, [{a: 1}]); - record {|int a; int g;|}[]|CsvConversionError cn4 = parseStringToRecord(csvStringData1, { + record {|int a; int g;|}[]|Error cn4 = parseStringToRecord(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); - test:assertTrue(cn4 is CsvConversionError); + test:assertTrue(cn4 is Error); test:assertEquals((cn4).message(), generateErrorMessageForMissingRequiredField("g")); - int?[][]|CsvConversionError cn5 = parseStringToList(string ` + int?[][]|Error cn5 = parseStringToList(string ` a,b,c 1, 1,1`, { allowDataProjection: {absentAsNilableType: true}, @@ -320,7 +320,7 @@ function testAbsentAsNilableConfig() returns error? { }); test:assertEquals(cn5, [[1, 1, 1]]); - map[]|CsvConversionError cn6 = parseStringToRecord(string ` + map[]|Error cn6 = parseStringToRecord(string ` a,b,c 1, 1,1`, { allowDataProjection: {absentAsNilableType: true}, @@ -328,28 +328,28 @@ function testAbsentAsNilableConfig() returns error? { }); test:assertEquals(cn6, [{a: 1, b: 1, c: 1}]); - [int, string?, boolean?, decimal?, float?, (), string?][]|CsvConversionError cn7 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|Error cn7 = parseStringToList(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?][]|CsvConversionError cn8 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|Error cn8 = parseStringToList(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?][]|CsvConversionError cn9 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|Error cn9 = parseStringToList(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?][]|CsvConversionError cn10 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|Error cn10 = parseStringToList(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" @@ -359,80 +359,80 @@ function testAbsentAsNilableConfig() returns error? { @test:Config {enable} function testAbsentAsNilableConfig2() returns error? { - record {|int a; int? g; int? h;|}[]|CsvConversionError cn = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int? g; int? h;|}[]|Error cn = parseRecordAsRecordType([{"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?;|}[]|CsvConversionError cn2 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int? g?;|}[]|Error cn2 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn2, [{a: 1}, {a: 2}]); - record {|int a; int g?;|}[]|CsvConversionError cn3 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int g?;|}[]|Error cn3 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn3, [{a: 1}, {a: 2}]); - record {|int a; int g;|}[]|CsvConversionError cn4 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int g;|}[]|Error cn4 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); - test:assertTrue(cn4 is CsvConversionError); + test:assertTrue(cn4 is Error); test:assertEquals((cn4).message(), generateErrorMessageForMissingRequiredField("g")); - record {|string a; int? g; int? h;|}[]|CsvConversionError cn5 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int? g; int? h;|}[]|Error cn5 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn5, [{a: "a", g: (), h: ()}, {a: "a", g: (), h: ()}]); - record {|string a; int? g?;|}[]|CsvConversionError cn6 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int? g?;|}[]|Error cn6 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn6, [{a: "a"}, {a: "a"}]); - record {|string a; int g?;|}[]|CsvConversionError cn7 = parseListAsRecordType([["a"], ["a"], ["b"]], ["a"], { + record {|string a; int g?;|}[]|Error cn7 = parseListAsRecordType([["a"], ["a"], ["b"]], ["a"], { allowDataProjection: {absentAsNilableType: true}, skipLines: [2] }); test:assertEquals(cn7, [{a: "a"}, {a: "b"}]); - record {|string a; int g;|}[]|CsvConversionError cn8 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int g;|}[]|Error cn8 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); - test:assertTrue(cn8 is CsvConversionError); + test:assertTrue(cn8 is Error); test:assertEquals((cn8).message(), generateErrorMessageForMissingRequiredField("g")); } @test:Config {enable} function testNilAsOptionalConfig() returns error? { - record {|int a; int f?;|}[]|CsvConversionError cn = parseStringToRecord(csvStringData1, { + record {|int a; int f?;|}[]|Error cn = parseStringToRecord(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1 }); test:assertEquals(cn, [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]); - record {|int a; int? f?;|}[]|CsvConversionError cn2 = parseStringToRecord(csvStringData1, { + record {|int a; int? f?;|}[]|Error cn2 = parseStringToRecord(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn2, [{a: 1, f: ()}]); - record {|int a; int f?;|}[]|CsvConversionError cn3 = parseStringToRecord(csvStringData1, { + record {|int a; int f?;|}[]|Error cn3 = parseStringToRecord(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn3, [{a: 1}]); - record {|int a; int f;|}[]|CsvConversionError cn4 = parseStringToRecord(csvStringData1, { + record {|int a; int f;|}[]|Error cn4 = parseStringToRecord(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); - test:assertTrue(cn4 is CsvConversionError); + test:assertTrue(cn4 is Error); test:assertEquals((cn4).message(), generateErrorMessageForInvalidCast("()", "int")); - int?[][]|CsvConversionError cn5 = parseStringToList(string ` + int?[][]|Error cn5 = parseStringToList(string ` a,b,c 1, 1,1`, { allowDataProjection: {nilAsOptionalField: true}, @@ -440,7 +440,7 @@ function testNilAsOptionalConfig() returns error? { }); test:assertEquals(cn5, [[1, 1, 1]]); - map[]|CsvConversionError cn6 = parseStringToRecord(string ` + map[]|Error cn6 = parseStringToRecord(string ` a,b,c 1, 1,1`, { allowDataProjection: {nilAsOptionalField: true}, @@ -448,28 +448,28 @@ function testNilAsOptionalConfig() returns error? { }); test:assertEquals(cn6, [{a: 1, b: 1, c: 1}]); - [int, string?, boolean?, decimal?, float?, (), string?][]|CsvConversionError cn7 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|Error cn7 = parseStringToList(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?][]|CsvConversionError cn8 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|Error cn8 = parseStringToList(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?][]|CsvConversionError cn9 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|Error cn9 = parseStringToList(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?][]|CsvConversionError cn10 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|Error cn10 = parseStringToList(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" @@ -479,48 +479,48 @@ function testNilAsOptionalConfig() returns error? { @test:Config {enable} function testNilAsOptionalConfig2() returns error? { - record {|int a; int? f;|}[]|CsvConversionError cn = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int? f;|}[]|Error cn = parseRecordAsRecordType([{"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?;|}[]|CsvConversionError cn2 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int? f?;|}[]|Error cn2 = parseRecordAsRecordType([{"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?;|}[]|CsvConversionError cn3 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int f?;|}[]|Error cn3 = parseRecordAsRecordType([{"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;|}[]|CsvConversionError cn4 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int f;|}[]|Error cn4 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] }); - test:assertTrue(cn4 is CsvConversionError); + test:assertTrue(cn4 is Error); test:assertEquals((cn4).message(), generateErrorMessageForInvalidFieldType("null", "f")); // TODO: After add string[] => anydata[] - // record {|string a; int? f;|}[]|CsvConversionError cn5 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + // record {|string a; int? f;|}[]|Error cn5 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { // allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] // }); // test:assertEquals(cn5, [{a: "a", f: ()}, {a: "a", f: ()}]); - // record {|string a; int? f?;|}[]|CsvConversionError cn6 = parseListAsRecordType([["a", ()], ["a", ()], ["a", ()]], ["a", "f"], { + // record {|string a; int? f?;|}[]|Error cn6 = parseListAsRecordType([["a", ()], ["a", ()], ["a", ()]], ["a", "f"], { // allowDataProjection: {nilAsOptionalField: true}, skipLines: [3], // }); // test:assertEquals(cn6, [{a: "a"}, {a: "a"}]); - // record {|string a; int f?;|}[]|CsvConversionError cn7 = parseListAsRecordType([["a"], ["a"], ["b"]], ["a"], { + // record {|string a; int f?;|}[]|Error cn7 = parseListAsRecordType([["a"], ["a"], ["b"]], ["a"], { // allowDataProjection: {nilAsOptionalField: true}, skipLines: [2] // }); // test:assertEquals(cn7, [{a: "a"}, {a: "b"}]); - // record {|string a; int f;|}[]|CsvConversionError cn8 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + // record {|string a; int f;|}[]|Error cn8 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { // allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] // }); - // test:assertTrue(cn8 is CsvConversionError); + // test:assertTrue(cn8 is Error); // test:assertEquals((cn8).message(), generateErrorMessageForInvalidCast("()", "int")); } @@ -532,285 +532,285 @@ function testDataProjectionConfig() returns error? { record{}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; [string, int][] csvValue3 = [["a", 2], ["b", 4]]; - record{}[]|CsvConversionError cn = parseStringToRecord(csvValue1, { + record{}[]|Error cn = parseStringToRecord(csvValue1, { allowDataProjection: false }); test:assertEquals(cn, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a; int b;|}[]|CsvConversionError cn_2 = parseStringToRecord(csvValue1, { + record{|string a; int b;|}[]|Error cn_2 = parseStringToRecord(csvValue1, { allowDataProjection: false }); test:assertEquals(cn_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a;|}[]|CsvConversionError cn2 = parseStringToRecord(csvValue1, { + record{|string a;|}[]|Error cn2 = parseStringToRecord(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn2 is CsvConversionError); + test:assertTrue(cn2 is Error); test:assertEquals((cn2).message(), "No mapping field in the expected type for header 'b'"); - record{|string a; int...;|}[]|CsvConversionError cn3 = parseStringToRecord(csvValue1, { + record{|string a; int...;|}[]|Error cn3 = parseStringToRecord(csvValue1, { allowDataProjection: false }); test:assertEquals(cn3, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string...;|}[]|CsvConversionError cn4 = parseStringToRecord(csvValue1, { + record{|string...;|}[]|Error cn4 = parseStringToRecord(csvValue1, { allowDataProjection: false }); test:assertEquals(cn4, [{"a": "a", "b": "2"}, {"a": "b", "b": "4"}]); - record{|string a?;|}[]|CsvConversionError cn5 = parseStringToRecord(csvValue1, { + record{|string a?;|}[]|Error cn5 = parseStringToRecord(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn5 is CsvConversionError); + test:assertTrue(cn5 is Error); test:assertEquals((cn5).message(), "No mapping field in the expected type for header 'b'"); - record{|string? a;|}[]|CsvConversionError cn6 = parseStringToRecord(csvValue1, { + record{|string? a;|}[]|Error cn6 = parseStringToRecord(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn6 is CsvConversionError); + test:assertTrue(cn6 is Error); test:assertEquals((cn6).message(), "No mapping field in the expected type for header 'b'"); - anydata[][]|CsvConversionError c7 = parseStringToList(csvValue1, { + anydata[][]|Error c7 = parseStringToList(csvValue1, { allowDataProjection: false }); test:assertEquals(c7, [["a", 2], ["b", 4]]); - [string, int][]|CsvConversionError cn7_2 = parseStringToList(csvValue1, { + [string, int][]|Error cn7_2 = parseStringToList(csvValue1, { allowDataProjection: false }); test:assertEquals(cn7_2, [["a", 2], ["b", 4]]); - [string][]|CsvConversionError cn8 = parseStringToList(csvValue1, { + [string][]|Error cn8 = parseStringToList(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn8 is CsvConversionError); + test:assertTrue(cn8 is Error); test:assertEquals((cn8).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); - [string][]|CsvConversionError cn8_2 = parseStringToList(csvValue1, { + [string][]|Error cn8_2 = parseStringToList(csvValue1, { allowDataProjection: {} }); test:assertEquals(cn8_2, [["a"], ["b"]]); - [int][]|CsvConversionError cn8_3 = parseStringToList(csvValue1, { + [int][]|Error cn8_3 = parseStringToList(csvValue1, { allowDataProjection: {} }); - test:assertTrue(cn8_3 is CsvConversionError); + test:assertTrue(cn8_3 is Error); test:assertEquals((cn8_3).message(), generateErrorMessageForInvalidCast("a", "int")); - [string, int...][]|CsvConversionError cn9 = parseStringToList(csvValue1, { + [string, int...][]|Error cn9 = parseStringToList(csvValue1, { allowDataProjection: false }); test:assertEquals(cn9, [["a", 2], ["b", 4]]); - [string...][]|CsvConversionError cn10 = parseStringToList(csvValue1, { + [string...][]|Error cn10 = parseStringToList(csvValue1, { allowDataProjection: false }); test:assertEquals(cn10, [["a", "2"], ["b", "4"]]); - [string, ()][]|CsvConversionError cn11 = parseStringToList(csvValue1, { + [string, ()][]|Error cn11 = parseStringToList(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn11 is CsvConversionError); + test:assertTrue(cn11 is Error); test:assertEquals((cn11).message(), generateErrorMessageForInvalidCast("2", "()")); - string[][]|CsvConversionError cn12 = parseStringToList(csvValue1, { + string[][]|Error cn12 = parseStringToList(csvValue1, { allowDataProjection: false }); test:assertEquals(cn12, [["a", "2"], ["b", "4"]]); - string[][1]|CsvConversionError cn13 = parseStringToList(csvValue1, { + string[][1]|Error cn13 = parseStringToList(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn13 is CsvConversionError); + test:assertTrue(cn13 is Error); test:assertEquals((cn13).message(), "invalid array size for expected array type, cannot be greater than '1'"); - record{}[]|CsvConversionError cn14 = parseRecordAsRecordType(csvValue2, { + record{}[]|Error cn14 = parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); test:assertEquals(cn14, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a; int b;|}[]|CsvConversionError cn14_2 = parseRecordAsRecordType(csvValue2, { + record{|string a; int b;|}[]|Error cn14_2 = parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); test:assertEquals(cn14_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a;|}[]|CsvConversionError cn15 = parseRecordAsRecordType(csvValue2, { + record{|string a;|}[]|Error cn15 = parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); - test:assertTrue(cn15 is CsvConversionError); + test:assertTrue(cn15 is Error); test:assertEquals((cn15).message(), "No mapping field in the expected type for header 'b'"); - record{|string a; int...;|}[]|CsvConversionError cn16 = parseRecordAsRecordType(csvValue2, { + record{|string a; int...;|}[]|Error cn16 = parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); test:assertEquals(cn16, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string...;|}[]|CsvConversionError cn17 = parseRecordAsRecordType(csvValue2, { + record{|string...;|}[]|Error cn17 = parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); test:assertEquals(cn17, [{"a": "a"}, {"a": "b"}]); - record{|string a?;|}[]|CsvConversionError cn18 = parseRecordAsRecordType(csvValue2, { + record{|string a?;|}[]|Error cn18 = parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); - test:assertTrue(cn18 is CsvConversionError); + test:assertTrue(cn18 is Error); test:assertEquals((cn18).message(), "No mapping field in the expected type for header 'b'"); - record{|string? a;|}[]|CsvConversionError cn19 = parseRecordAsRecordType(csvValue2, { + record{|string? a;|}[]|Error cn19 = parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); - test:assertTrue(cn19 is CsvConversionError); + test:assertTrue(cn19 is Error); test:assertEquals((cn19).message(), "No mapping field in the expected type for header 'b'"); - anydata[][]|CsvConversionError c20 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + anydata[][]|Error c20 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); test:assertEquals(c20, [["a", 2], ["b", 4]]); - [string, int][]|CsvConversionError cn20_2 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string, int][]|Error cn20_2 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); test:assertEquals(cn20_2, [["a", 2], ["b", 4]]); - [string][]|CsvConversionError cn21 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string][]|Error cn21 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); - test:assertTrue(cn21 is CsvConversionError); + test:assertTrue(cn21 is Error); test:assertEquals((cn21).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); - [string][]|CsvConversionError cn21_2 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string][]|Error cn21_2 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: {} }); test:assertEquals(cn21_2, [["a"], ["b"]]); - [int][]|CsvConversionError cn21_3 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [int][]|Error cn21_3 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: {} }); - test:assertTrue(cn21_3 is CsvConversionError); + test:assertTrue(cn21_3 is Error); test:assertEquals((cn21_3).message(), generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); - [string, int...][]|CsvConversionError cn22 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string, int...][]|Error cn22 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); test:assertEquals(cn22, [["a", 2], ["b", 4]]); - [string...][]|CsvConversionError cn23 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string...][]|Error cn23 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); - test:assertTrue(cn23 is CsvConversionError); + test:assertTrue(cn23 is Error); test:assertEquals(( cn23).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - [string, ()][]|CsvConversionError cn24 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string, ()][]|Error cn24 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); - test:assertTrue(cn24 is CsvConversionError); + test:assertTrue(cn24 is Error); test:assertEquals((cn24).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "()")); - string[][]|CsvConversionError cn25 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + string[][]|Error cn25 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); - test:assertTrue(cn25 is CsvConversionError); + test:assertTrue(cn25 is Error); test:assertEquals(( cn25).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - string[][1]|CsvConversionError cn26 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + string[][1]|Error cn26 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); - test:assertTrue(cn26 is CsvConversionError); + test:assertTrue(cn26 is Error); test:assertEquals((cn26).message(), "invalid array size for expected array type, cannot be greater than '1'"); // TODO: After fixing the issue with the anydata[] - // record{}[]|CsvConversionError cnl14 = parseListAsRecordType(csvValue3, ["a", "b"], { + // record{}[]|Error cnl14 = parseListAsRecordType(csvValue3, ["a", "b"], { // allowDataProjection: false // }); // test:assertEquals(cnl14, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - // record{|string a; int b;|}[]|CsvConversionError cnl14_2 = parseListAsRecordType(csvValue3, ["a", "b"], { + // record{|string a; int b;|}[]|Error cnl14_2 = parseListAsRecordType(csvValue3, ["a", "b"], { // allowDataProjection: false // }); // test:assertEquals(cnl14_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - // record{|string a;|}[]|CsvConversionError cnl15 = parseListAsRecordType(csvValue3, ["a", "b"], { + // record{|string a;|}[]|Error cnl15 = parseListAsRecordType(csvValue3, ["a", "b"], { // allowDataProjection: false // }); - // test:assertTrue(cnl15 is CsvConversionError); + // test:assertTrue(cnl15 is Error); // test:assertEquals((cnl15).message(), "No mapping field in the expected type for header 'b'"); - // record{|string a; int...;|}[]|CsvConversionError cnl16 = parseListAsRecordType(csvValue3, ["a", "b"], { + // record{|string a; int...;|}[]|Error cnl16 = parseListAsRecordType(csvValue3, ["a", "b"], { // allowDataProjection: false // }); // test:assertEquals(cnl16, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - // record{|string...;|}[]|CsvConversionError cnl17 = parseListAsRecordType(csvValue3, ["a", "b"], { + // record{|string...;|}[]|Error cnl17 = parseListAsRecordType(csvValue3, ["a", "b"], { // allowDataProjection: false // }); // test:assertEquals(cnl17, [{"a": "a"}, {"a": "b"}]); - // record{|string a?;|}[]|CsvConversionError cnl18 = parseListAsRecordType(csvValue3, ["a", "b"], { + // record{|string a?;|}[]|Error cnl18 = parseListAsRecordType(csvValue3, ["a", "b"], { // allowDataProjection: false // }); - // test:assertTrue(cnl18 is CsvConversionError); + // test:assertTrue(cnl18 is Error); // test:assertEquals((cnl18).message(), "No mapping field in the expected type for header 'b'"); - // record{|string? a;|}[]|CsvConversionError cnl19 = parseListAsRecordType(csvValue3, ["a", "b"], { + // record{|string? a;|}[]|Error cnl19 = parseListAsRecordType(csvValue3, ["a", "b"], { // allowDataProjection: false // }); - // test:assertTrue(cnl19 is CsvConversionError); + // test:assertTrue(cnl19 is Error); // test:assertEquals((cnl19).message(), "No mapping field in the expected type for header 'b'"); - // anydata[][]|CsvConversionError cnl20 = parseListAsListType(csvValue3 ,{ + // anydata[][]|Error cnl20 = parseListAsListType(csvValue3 ,{ // allowDataProjection: false // }); // test:assertEquals(cnl20, [["a", 2], ["b", 4]]); - // [string, int][]|CsvConversionError cnl20_2 = parseListAsListType(csvValue3 ,{ + // [string, int][]|Error cnl20_2 = parseListAsListType(csvValue3 ,{ // allowDataProjection: false // }); // test:assertEquals(cnl20_2, [["a", 2], ["b", 4]]); - // [string][]|CsvConversionError cnl21 = parseListAsListType(csvValue3 ,{ + // [string][]|Error cnl21 = parseListAsListType(csvValue3 ,{ // allowDataProjection: false // }); - // test:assertTrue(cnl21 is CsvConversionError); + // test:assertTrue(cnl21 is Error); // test:assertEquals((cnl21).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); - // [string][]|CsvConversionError cnl21_2 = parseListAsListType(csvValue3 ,{ + // [string][]|Error cnl21_2 = parseListAsListType(csvValue3 ,{ // allowDataProjection: {} // }); // test:assertEquals(cnl21_2, [["a"], ["b"]]); - // [int][]|CsvConversionError cnl21_3 = parseListAsListType(csvValue3 ,{ + // [int][]|Error cnl21_3 = parseListAsListType(csvValue3 ,{ // allowDataProjection: {} // }); - // test:assertTrue(cnl21_3 is CsvConversionError); + // test:assertTrue(cnl21_3 is Error); // test:assertEquals((cnl21_3).message(), generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); - // [string, int...][]|CsvConversionError cnl22 = parseListAsListType(csvValue3 ,{ + // [string, int...][]|Error cnl22 = parseListAsListType(csvValue3 ,{ // allowDataProjection: false // }); // test:assertEquals(cnl22, [["a", 2], ["b", 4]]); - // [string...][]|CsvConversionError cnl23 = parseListAsListType(csvValue3 ,{ + // [string...][]|Error cnl23 = parseListAsListType(csvValue3 ,{ // allowDataProjection: false // }); - // test:assertTrue(cnl23 is CsvConversionError); + // test:assertTrue(cnl23 is Error); // test:assertEquals(( cnl23).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - // [string, ()][]|CsvConversionError cnl24 = parseListAsListType(csvValue3 ,{ + // [string, ()][]|Error cnl24 = parseListAsListType(csvValue3 ,{ // allowDataProjection: false // }); - // test:assertTrue(cnl24 is CsvConversionError); + // test:assertTrue(cnl24 is Error); // test:assertEquals((cnl24).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "()")); - // string[][]|CsvConversionError cnl25 = parseListAsListType(csvValue3 ,{ + // string[][]|Error cnl25 = parseListAsListType(csvValue3 ,{ // allowDataProjection: false // }); - // test:assertTrue(cnl25 is CsvConversionError); + // test:assertTrue(cnl25 is Error); // test:assertEquals(( cnl25).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - // string[][1]|CsvConversionError cnl26 = parseListAsListType(csvValue3 ,{ + // string[][1]|Error cnl26 = parseListAsListType(csvValue3 ,{ // allowDataProjection: false // }); - // test:assertTrue(cnl26 is CsvConversionError); + // test:assertTrue(cnl26 is Error); // test:assertEquals((cnl26).message(), "invalid array size for expected array type, cannot be greater than '1'"); } \ No newline at end of file diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index 4b9e59e..5176dbb 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -4,7 +4,7 @@ import ballerina/test; // @test:Config {enable: !enable} // function debugTest() returns error? { -// record {|int a; int f?;|}[]|CsvConversionError cn3 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { +// record {|int a; int f?;|}[]|Error cn3 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { // allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] // }); // test:assertEquals(cn3, [{a: 1}, {a: 2}]); @@ -12,60 +12,60 @@ import ballerina/test; @test:Config {enable} function testFromCsvStringWithParserOptions() { - [int, string, boolean, decimal, float, string][]|CsvConversionError csv1op3 = parseStringToList(csvStringData1, option3); + [int, string, boolean, decimal, float, string][]|Error csv1op3 = parseStringToList(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, "()"] ]); - record {int a; string b; boolean c; decimal d; float e; string f;}[]|CsvConversionError csv1op3_2 = parseStringToRecord(csvStringData1, ptOption1); + record {int a; string b; boolean c; decimal d; float e; string f;}[]|Error csv1op3_2 = parseStringToRecord(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: "()"} ]); - record {int a; string b; boolean c; decimal d; float e; string f;}[]|CsvConversionError csv1op3_3 = parseStringToRecord(csvStringData1, ptOption2); + record {int a; string b; boolean c; decimal d; float e; string f;}[]|Error csv1op3_3 = parseStringToRecord(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: "()"} ]); - [int, string, boolean, decimal, float, string][]|CsvConversionError csv2op4 = parseStringToList(csvStringData2, option4); + [int, string, boolean, decimal, float, string][]|Error csv2op4 = parseStringToList(csvStringData2, option4); test:assertEquals(csv2op4, []); - record {}[]|CsvConversionError csv2op4_2 = parseStringToRecord(csvStringData2, ptOption3); + record {}[]|Error csv2op4_2 = parseStringToRecord(csvStringData2, ptOption3); test:assertEquals(csv2op4_2, []); - record {}[]|CsvConversionError csv2op4_3 = parseStringToRecord(csvStringData2, ptOption4); + record {}[]|Error csv2op4_3 = parseStringToRecord(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: "()"} ]); - [int, string, boolean, decimal, float, string][]|CsvConversionError csv3op3 = parseStringToList(csvStringData3, option3); + [int, string, boolean, decimal, float, string][]|Error csv3op3 = parseStringToList(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, "()"] ]); - record {}[]|CsvConversionError csv3op3_2 = parseStringToRecord(csvStringData3, ptOption1); + record {}[]|Error csv3op3_2 = parseStringToRecord(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: "()"} ]); - record {}[]|CsvConversionError csv3op3_3 = parseStringToRecord(csvStringData3, ptOption2); + record {}[]|Error csv3op3_3 = parseStringToRecord(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: "()"} ]); - record {}[]|CsvConversionError csv3op3_4 = parseStringToRecord(csvStringData3, {header: 9, skipLines: "2-10"}); + record {}[]|Error csv3op3_4 = parseStringToRecord(csvStringData3, {header: 9, skipLines: "2-10"}); test:assertEquals(csv3op3_4, [ {'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": null} ]); @@ -73,11 +73,11 @@ function testFromCsvStringWithParserOptions() { @test:Config {enable} function testFromCsvStringWithHeaderLessParserOptions() { - [int, string, boolean, decimal, float, ()][]|CsvConversionError csv1op6 = parseStringToList(csvStringData1, option6); - test:assertTrue(csv1op6 is CsvConversionError); + [int, string, boolean, decimal, float, ()][]|Error csv1op6 = parseStringToList(csvStringData1, option6); + test:assertTrue(csv1op6 is Error); test:assertEquals((csv1op6).message(), generateErrorMessageForInvalidCast("null", "()")); - record {}[]|CsvConversionError csv1op5_2 = parseStringToRecord(csvStringData1, ptOption5); + record {}[]|Error csv1op5_2 = parseStringToRecord(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: ()}, @@ -85,7 +85,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record {}[]|CsvConversionError csv1op6_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [3, 5]}); + record {}[]|Error csv1op6_2 = parseStringToRecord(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: ()}, @@ -93,35 +93,35 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record {}[]|CsvConversionError csv3op6_2 = parseStringToRecord(csvStringData3, {header: false, skipLines: [1, 3, 5, -1, 100, 100]}); + record {}[]|Error csv3op6_2 = parseStringToRecord(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: ()} ]); - record {}[]|CsvConversionError csv4op6_2 = parseStringToRecord(csvStringData4, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|Error csv4op6_2 = parseStringToRecord(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: ()} ]); - record {}[]|CsvConversionError csv5op6_2 = parseStringToRecord(csvStringData5, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|Error csv5op6_2 = parseStringToRecord(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: ()} ]); - record {}[]|CsvConversionError csv6op6_2 = parseStringToRecord(csvStringData6, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|Error csv6op6_2 = parseStringToRecord(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: ()} ]); - record {}[]|CsvConversionError csv2op6_2 = parseStringToRecord(csvStringData2, {header: false, skipLines: [5, 7]}); + record {}[]|Error csv2op6_2 = parseStringToRecord(csvStringData2, {header: false, skipLines: [5, 7]}); test:assertEquals(csv2op6_2, [ {'1: "hello", '2: "hello", '3: (), '4: 12, '5: true, '6: 12.34}, {'1: "//comment"}, @@ -134,7 +134,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { @test:Config {enable} function testHeaderOption() { - record {}[]|CsvConversionError csv2cop1 = parseStringToRecord(csvStringData2, {header: 4}); + record {}[]|Error csv2cop1 = parseStringToRecord(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: ()}, @@ -143,17 +143,17 @@ function testHeaderOption() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - record {}[]|CsvConversionError csv2cop2 = parseStringToRecord(csvStringData2, {header: 100}); + record {}[]|Error csv2cop2 = parseStringToRecord(csvStringData2, {header: 100}); test:assertEquals(csv2cop2, []); - record {}[]|CsvConversionError csv2cop3 = parseStringToRecord(csvStringData2, {header: 11}); + record {}[]|Error csv2cop3 = parseStringToRecord(csvStringData2, {header: 11}); test:assertEquals(csv2cop3, []); - record {}[]|CsvConversionError csv2cop4 = parseStringToRecord(csvStringData2, {header: 10}); + record {}[]|Error csv2cop4 = parseStringToRecord(csvStringData2, {header: 10}); test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": ()}]); - record {}[]|CsvConversionError csv1cop5 = parseStringToRecord(csvStringData1, {}); - test:assertTrue(csv1cop5 is CsvConversionError); + record {}[]|Error csv1cop5 = parseStringToRecord(csvStringData1, {}); + test:assertTrue(csv1cop5 is Error); test:assertEquals((csv1cop5).message(), "The provided header row is empty"); } @@ -170,14 +170,14 @@ function testNullConfigOption() { string csvValue5 = string `b, a bN/Aa,N/A`; - record {() a;}[]|CsvConversionError cn = parseStringToRecord(csvValue1, {nilValue: ()}); + record {() a;}[]|Error cn = parseStringToRecord(csvValue1, {nilValue: ()}); test:assertEquals(cn, [{a: ()}]); cn = parseStringToRecord(csvValue2, {nilValue: ()}); test:assertEquals(cn, [{a: ()}]); cn = parseStringToRecord(csvValue3, {nilValue: ()}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("e", "()")); cn = parseStringToRecord(csvValue4, {nilValue: ()}); @@ -190,7 +190,7 @@ function testNullConfigOption() { test:assertEquals(cn, [{a: ()}]); cn = parseStringToRecord(csvValue3, {nilValue: null}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("e", "()")); cn = parseStringToRecord(csvValue4, {nilValue: null}); @@ -200,15 +200,15 @@ function testNullConfigOption() { test:assertEquals(cn, [{a: ()}]); cn = parseStringToRecord(csvValue2, {nilValue: "()"}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("null", "()")); cn = parseStringToRecord(csvValue3, {nilValue: "()"}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("e", "()")); cn = parseStringToRecord(csvValue4, {nilValue: "()"}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("Null", "()")); cn = parseStringToRecord(csvValue5, {nilValue: "N/A"}); @@ -218,11 +218,11 @@ function testNullConfigOption() { test:assertEquals(cn, [{a: ()}]); cn = parseStringToRecord(csvValue4, {nilValue: "null"}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("Null", "()")); cn = parseStringToRecord(csvValue1, {nilValue: "null"}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("()", "()")); // TODO: add nilValue -> "", with str quotes @@ -255,7 +255,7 @@ function testCommentConfigOption() { 1 ,#2 # comment # comment`; - record {int a;}[]|CsvConversionError cn; + record {int a;}[]|Error cn; cn = parseStringToRecord(csvValue1); test:assertEquals(cn, [{a: 1}]); @@ -278,11 +278,11 @@ function testCommentConfigOption() { cn = parseStringToRecord(csvValue7); test:assertEquals(cn, [{a: 1}]); - record {|int a; int b;|}[]|CsvConversionError cn2 = parseStringToRecord(csvValue7, {header: 0}); + record {|int a; int b;|}[]|Error cn2 = parseStringToRecord(csvValue7, {header: 0}); test:assertEquals(cn2, [{a: 1, b: 0}]); cn = parseStringToRecord(csvValue8); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); // TODO:Fix // test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("1, 2", "int")); @@ -316,63 +316,63 @@ function testCommentConfigOption2() { & comment`; - record {int a; int b;}[]|CsvConversionError cn; - record {int c;}[]|CsvConversionError cn2; + record {int a; int b;}[]|Error cn; + record {int c;}[]|Error cn2; cn = parseStringToRecord(csvValue1, {comment: "&"}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); cn = parseStringToRecord(csvValue2, {comment: "&"}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); cn = parseStringToRecord(csvValue3, {comment: "&"}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); cn = parseStringToRecord(csvValue4, {comment: "&"}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); cn = parseStringToRecord(csvValue5, {comment: "&"}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); // TODO: Fix // test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); cn = parseStringToRecord(csvValue6, {comment: "&", header: 2}); - test:assertTrue(cn is CsvConversionError); + test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); cn2 = parseStringToRecord(csvValue1, {comment: "&"}); - test:assertTrue(cn2 is CsvConversionError); + test:assertTrue(cn2 is Error); test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); cn2 = parseStringToRecord(csvValue2, {comment: "&"}); - test:assertTrue(cn2 is CsvConversionError); + test:assertTrue(cn2 is Error); test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); cn2 = parseStringToRecord(csvValue3, {comment: "&"}); - test:assertTrue(cn2 is CsvConversionError); + test:assertTrue(cn2 is Error); test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); cn2 = parseStringToRecord(csvValue4, {comment: "&"}); - test:assertTrue(cn2 is CsvConversionError); + test:assertTrue(cn2 is Error); test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); cn2 = parseStringToRecord(csvValue5, {comment: "&"}); - test:assertTrue(cn2 is CsvConversionError); + test:assertTrue(cn2 is Error); // TODO: Fix // test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); cn2 = parseStringToRecord(csvValue6, {header: 2, comment: "&"}); - test:assertTrue(cn2 is CsvConversionError); + test:assertTrue(cn2 is Error); test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); } @test:Config {enable} function testSkipLineParserOption() { - [int, string, boolean, decimal, float, ()][]|CsvConversionError csv1cp = parseStringToList(csvStringData1, {skipLines: [], header: 1}); + [int, string, boolean, decimal, float, ()][]|Error csv1cp = parseStringToList(csvStringData1, {skipLines: [], header: 1}); test:assertEquals(csv1cp, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -475,66 +475,66 @@ function testSkipLineParserOption() { @test:Config {enable} function testCustomHeaderOption() { - anydata[][]|CsvConversionError bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}); + anydata[][]|Error bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - anydata[][]|CsvConversionError bm1ba2 = parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}); + anydata[][]|Error bm1ba2 = parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}); test:assertEquals(bm1ba2, [ [false, true], [false, true] ]); - anydata[][]|CsvConversionError bm2ba = parseRecordAsListType([bm2, bm2], ["b1", "n1", "b2", "n2", "b3"], {}); - test:assertTrue(bm2ba is CsvConversionError); + anydata[][]|Error bm2ba = parseRecordAsListType([bm2, bm2], ["b1", "n1", "b2", "n2", "b3"], {}); + test:assertTrue(bm2ba is Error); test:assertEquals((bm2ba).message(), generateErrorMessageForInvalidCustomHeader("n2")); - anydata[][]|CsvConversionError bm3ba = parseRecordAsListType([bm3, bm3], ["b1", "b4", "b2", "n2", "i1"], {}); - test:assertTrue(bm3ba is CsvConversionError); + anydata[][]|Error bm3ba = parseRecordAsListType([bm3, bm3], ["b1", "b4", "b2", "n2", "i1"], {}); + test:assertTrue(bm3ba is Error); test:assertEquals((bm3ba).message(), generateErrorMessageForInvalidCustomHeader("n2")); - anydata[][]|CsvConversionError bm3ba2 = parseRecordAsListType([bm3, bm3], ["b1", "b3", "b4", "b2", "i2"], {}); - test:assertTrue(bm3ba2 is CsvConversionError); + anydata[][]|Error bm3ba2 = parseRecordAsListType([bm3, bm3], ["b1", "b3", "b4", "b2", "i2"], {}); + test:assertTrue(bm3ba2 is Error); test:assertEquals((bm3ba2).message(), generateErrorMessageForInvalidCustomHeader("i2")); - [boolean...][]|CsvConversionError bm3ba4 = parseRecordAsListType([bm3, bm3], ["n2"], {}); - test:assertTrue(bm3ba4 is CsvConversionError); + [boolean...][]|Error bm3ba4 = parseRecordAsListType([bm3, bm3], ["n2"], {}); + test:assertTrue(bm3ba4 is Error); test:assertEquals((bm3ba4).message(), "Invalid length for the header names"); - [boolean...][]|CsvConversionError bm3ba5 = parseRecordAsListType([bm3, bm3], [], {}); - test:assertTrue(bm3ba5 is CsvConversionError); + [boolean...][]|Error bm3ba5 = parseRecordAsListType([bm3, bm3], [], {}); + test:assertTrue(bm3ba5 is Error); test:assertEquals((bm3ba5).message(), "Invalid length for the header names"); // ------------------------------------------------------------- - record {}[]|CsvConversionError ct1br = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); - test:assertTrue(ct1br is CsvConversionError); + record {}[]|Error ct1br = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); + test:assertTrue(ct1br is Error); test:assertEquals((ct1br).message(), "Invalid length for the custom headers"); - record {}[]|CsvConversionError ct1br2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); - test:assertTrue(ct1br2 is CsvConversionError); + record {}[]|Error ct1br2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); + test:assertTrue(ct1br2 is Error); test:assertEquals((ct1br2).message(), "Invalid length for the custom headers"); - record {}[]|CsvConversionError ct1br2_2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); - test:assertTrue(ct1br2_2 is CsvConversionError); + record {}[]|Error ct1br2_2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); + test:assertTrue(ct1br2_2 is Error); test:assertEquals((ct1br2_2).message(), "Invalid length for the custom headers"); - record {}[]|CsvConversionError ct1br3 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], [], {}); - test:assertTrue(ct1br3 is CsvConversionError); + record {}[]|Error ct1br3 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], [], {}); + test:assertTrue(ct1br3 is Error); test:assertEquals((ct1br3).message(), "Invalid length for the custom headers"); - record {|string a; string b; string c;|}[]|CsvConversionError ct1br5 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); - test:assertTrue(ct1br5 is CsvConversionError); + record {|string a; string b; string c;|}[]|Error ct1br5 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + test:assertTrue(ct1br5 is Error); // TODO: Fix test:assertEquals((ct1br5).message(), generateErrorMessageForMissingRequiredField("c")); - record {string a; string b; string c;}[]|CsvConversionError ct1br6 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); - test:assertTrue(ct1br6 is CsvConversionError); + record {string a; string b; string c;}[]|Error ct1br6 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + test:assertTrue(ct1br6 is Error); test:assertEquals((ct1br6).message(), generateErrorMessageForMissingRequiredField("c")); - record {string a; string b;}[]|CsvConversionError ct1br7 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + record {string a; string b;}[]|Error ct1br7 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { stringConversion: false }); test:assertEquals(ct1br7, [ @@ -542,7 +542,7 @@ function testCustomHeaderOption() { {a: "a", e: "1", b: "true"} ]); - record {|string a; string b;|}[]|CsvConversionError ct1br8 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + record {|string a; string b;|}[]|Error ct1br8 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { stringConversion: false }); test:assertEquals(ct1br8, [ @@ -550,7 +550,7 @@ function testCustomHeaderOption() { {a: "a", b: "true"} ]); - record {|string...;|}[]|CsvConversionError ct1br9 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + record {|string...;|}[]|Error ct1br9 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { stringConversion: false }); test:assertEquals(ct1br9, [ @@ -558,7 +558,7 @@ function testCustomHeaderOption() { {a: "a", b: "true", e: "1"} ]); - record {|string...;|}[]|CsvConversionError ct1br10 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), { + record {|string...;|}[]|Error ct1br10 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), { stringConversion: false }); test:assertEquals(ct1br10, [ @@ -572,24 +572,24 @@ function testCustomHeaderParserOption2() { // parseStringToRecord // parseRecordAsRecordType - record {}[]|CsvConversionError ct1br = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); - test:assertTrue(ct1br is CsvConversionError); + record {}[]|Error ct1br = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); + test:assertTrue(ct1br is Error); test:assertEquals((ct1br).message(), "Invalid length for the custom headers"); - // record{}[]|CsvConversionError ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b", "aa", "aaa", "aaaaa", "bb", "ccc"]}); + // record{}[]|Error ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b", "aa", "aaa", "aaaaa", "bb", "ccc"]}); // // TODO: Fix this - // test:assertTrue(ct1br2 is CsvConversionError); + // test:assertTrue(ct1br2 is Error); // test:assertEquals(( ct1br2).message(), "Invalid length for the custom headers"); - record {}[]|CsvConversionError ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: []}); - test:assertTrue(ct1br2 is CsvConversionError); + record {}[]|Error ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: []}); + test:assertTrue(ct1br2 is Error); test:assertEquals((ct1br2).message(), "Invalid length for the custom headers"); - record {int a; string b; boolean c; decimal d; float e; () f;}[]|CsvConversionError ct1br3 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); - test:assertTrue(ct1br3 is CsvConversionError); + record {int a; string b; boolean c; decimal d; float e; () f;}[]|Error ct1br3 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); + test:assertTrue(ct1br3 is Error); test:assertEquals((ct1br3).message(), "Invalid length for the custom headers"); - record {int a; string b; boolean c; decimal d; float e; () f;}[]|CsvConversionError ct1br4 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b", "c", "d", "e", "f"]}); + record {int a; string b; boolean c; decimal d; float e; () f;}[]|Error ct1br4 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["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: ()}, @@ -598,7 +598,7 @@ function testCustomHeaderParserOption2() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - record {() a; float b; decimal c; boolean d; string e; int f;}[]|CsvConversionError ct1br5 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f", "e", "d", "c", "b", "a"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|Error ct1br5 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["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: ()}, @@ -607,7 +607,7 @@ function testCustomHeaderParserOption2() { {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} ]); - record {() a; float b; decimal c; boolean d; string e; int f;}[]|CsvConversionError ct1br5_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f", "e", "d", "c", "b", "a"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|Error ct1br5_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["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: ()}, @@ -616,7 +616,7 @@ function testCustomHeaderParserOption2() { {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} ]); - record {() a; float b; decimal c; boolean d; string e; int f;}[]|CsvConversionError ct1br5_3 = parseStringToRecord(csvStringData1, {skipLines: [1], customHeaders: ["f", "e", "d", "c", "b", "a"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|Error ct1br5_3 = parseStringToRecord(csvStringData1, {skipLines: [1], customHeaders: ["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: ()}, @@ -625,7 +625,7 @@ function testCustomHeaderParserOption2() { {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} ]); - record {|() a1; float b1; decimal c1; boolean d1; string e1; int f1;|}[]|CsvConversionError ct1br6 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|() a1; float b1; decimal c1; boolean d1; string e1; int f1;|}[]|Error ct1br6 = 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: ()}, @@ -634,7 +634,7 @@ function testCustomHeaderParserOption2() { {f1: 5, e1: "string5", d1: true, c1: 3, b1: 3, a1: ()} ]); - record {|boolean d1; string e1;|}[]|CsvConversionError ct1br7 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|Error ct1br7 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -643,7 +643,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|CsvConversionError ct1br7_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|Error ct1br7_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7_2, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -652,12 +652,12 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|CsvConversionError ct1br8 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); + record {|boolean d1; string e1;|}[]|Error ct1br8 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); // TODO: Fix - test:assertTrue(ct1br8 is CsvConversionError); + test:assertTrue(ct1br8 is Error); test:assertEquals((ct1br8).message(), generateErrorMessageForInvalidCast("string1", "boolean")); - record {|boolean d1; string e1;|}[]|CsvConversionError ct1br9 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|Error ct1br9 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br9, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -666,7 +666,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|CsvConversionError ct1br10 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "f1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|Error ct1br10 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "f1", "b1", "a1"]}); test:assertEquals(ct1br10, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -675,11 +675,11 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|CsvConversionError ct1br11 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); - test:assertTrue(ct1br11 is CsvConversionError); + record {|boolean d1; string e1;|}[]|Error ct1br11 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); + test:assertTrue(ct1br11 is Error); test:assertEquals((ct1br11).message(), "Invalid length for the custom headers"); - record {|string d1; string e1;|}[]|CsvConversionError ct1br12 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|string d1; string e1;|}[]|Error ct1br12 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ {e1: "string1", d1: "true"}, {e1: "string2", d1: "false"}, @@ -688,8 +688,8 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: "true"} ]); - record {|string d1; string e1;|}[]|CsvConversionError ct1br13 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); - test:assertTrue(ct1br13 is CsvConversionError); + record {|string d1; string e1;|}[]|Error ct1br13 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); + test:assertTrue(ct1br13 is Error); test:assertEquals((ct1br13).message(), generateErrorMessageForMissingRequiredField("d1")); } @@ -733,26 +733,26 @@ function testTextQuotesWithParserOptions() { 1, "2", "3" `; - record {int a;}[]|CsvConversionError cn = parseStringToRecord(csvValue1, {header: 1}); + record {int a;}[]|Error cn = parseStringToRecord(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...;|}[]|CsvConversionError cn2 = parseStringToRecord(csvValue2, {header: 1}); + record {|int c; string...;|}[]|Error cn2 = parseStringToRecord(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;|}[]|CsvConversionError cn3 = parseStringToRecord(csvValue3, {}); + record {|string b; string c;|}[]|Error cn3 = parseStringToRecord(csvValue3, {}); test:assertEquals(cn3, [{"b": "\"2\"", "c": "3"}, {"b": "5, 6\"b\" \" a \"", c: "\"6\""}]); - record {}[]|CsvConversionError cn4 = parseStringToRecord(csvValue4, {textEnclosure: "'"}); + record {}[]|Error cn4 = parseStringToRecord(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[][]|CsvConversionError cn4_2 = parseStringToList(csvValue4, {textEnclosure: "'"}); + anydata[][]|Error cn4_2 = parseStringToList(csvValue4, {textEnclosure: "'"}); test:assertEquals(cn4_2, [[1, 2, 3], [4, "5, '6'7", 8], [4, "\"5\"", "4, '5\"a\", ,\",\" a '6'7"]]); - record {}[]|CsvConversionError cn5 = parseStringToRecord(csvValue5, {}); + record {}[]|Error cn5 = parseStringToRecord(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 {}[]|CsvConversionError cn6 = parseStringToRecord(csvValue6, {}); - test:assertTrue(cn6 is CsvConversionError); + record {}[]|Error cn6 = parseStringToRecord(csvValue6, {}); + test:assertTrue(cn6 is Error); test:assertEquals((cn6).message(), "Invalid length for the custom headers"); } @@ -778,16 +778,16 @@ function testHeaderQuotesWithParserOptions() { 4, '5, '6'7', 8 4, "5", '4, '5"a", ,"," a '6'7'`; - record {}[]|CsvConversionError cn = parseStringToRecord(csvValue1, {header: 1}); + record {}[]|Error cn = parseStringToRecord(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 {}[]|CsvConversionError cn2 = parseStringToRecord(csvValue2, {header: 1}); + record {}[]|Error cn2 = parseStringToRecord(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[][]|CsvConversionError cn2_2 = parseStringToList(csvValue2, {header: 1}); + anydata[][]|Error cn2_2 = parseStringToList(csvValue2, {header: 1}); test:assertEquals(cn2_2, [[1, "2, 3", 3], [1, "2, 3", 3], [4, 5, 6]]); - record {}[]|CsvConversionError cn3 = parseStringToRecord(csvValue3, {textEnclosure: "'"}); + record {}[]|Error cn3 = parseStringToRecord(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"}]); } @@ -817,28 +817,28 @@ function testEscapeCharactersWithParserOptions() { "1\\", "2\\"", "3"`; - record {}[]|CsvConversionError cn = parseStringToRecord(csvValue1, {header: 1}); + record {}[]|Error cn = parseStringToRecord(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 {}[]|CsvConversionError cn2 = parseStringToRecord(csvValue2, {header: 1}); + record {}[]|Error cn2 = parseStringToRecord(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 {}[]|CsvConversionError cn3 = parseStringToRecord(csvValue3, {header: 1}); + record {}[]|Error cn3 = parseStringToRecord(csvValue3, {header: 1}); test:assertEquals(cn3, [{"a": 1, "b": 2.0, "c": 3.0}, {"a": 1.0, "b": 2, "c": 3}, {"a": 1, "b": "2\"", "c": 3}, {"a": "1\\", "b": "2\\\"", "c": 3}]); - anydata[][]|CsvConversionError cn_2 = parseStringToList(csvValue1, {header: 1}); + anydata[][]|Error cn_2 = parseStringToList(csvValue1, {header: 1}); test:assertEquals(cn_2, [[1, "2a\t", "3b\n"], ["1c\n", 2, 3], [1, "2a\"", 3], ["1a\\", "2b\\\"", 3]]); - anydata[][]|CsvConversionError cn2_2 = parseStringToList(csvValue2, {header: 1}); + anydata[][]|Error cn2_2 = parseStringToList(csvValue2, {header: 1}); test:assertEquals(cn2_2, [[1, "2a\t", "3b\n"], ["1c\n", "/2/", 3], [1, "2a\"", 3], ["1a\\", "2b\\\"", 3]]); - anydata[][]|CsvConversionError cn3_2 = parseStringToList(csvValue3, {header: 1}); + anydata[][]|Error cn3_2 = parseStringToList(csvValue3, {header: 1}); test:assertEquals(cn3_2, [[1, 2.0, 3.0], [1.0, 2, 3], [1, "2\"", 3], ["1\\", "2\\\"", 3]]); } @test:Config {enable} function testDelimiterWithParserOptions() { - record {}[]|CsvConversionError cn = parseStringToRecord(csvStringData7, {header: 1, delimiter: "@"}); + record {}[]|Error cn = parseStringToRecord(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: ()}, @@ -847,7 +847,7 @@ function testDelimiterWithParserOptions() { {a: 5, b: "string", c: true, d: 2.234, e: -3.21, f: ()} ]); - anydata[][]|CsvConversionError cn2 = parseStringToList(csvStringData7, {header: 1, delimiter: "@"}); + anydata[][]|Error cn2 = parseStringToList(csvStringData7, {header: 1, delimiter: "@"}); test:assertEquals(cn2, [ [1, "string", true, 2.234, -3.21, ()], [2, "s,tring", true, 2.234, -3.21, ()], @@ -863,7 +863,7 @@ function testDelimiterWithParserOptions() { function testLineTerminatorWithParserOptions() { string csvValue = string `a,b${"\n"} 1,"2\n3"`; - record {}[]|CsvConversionError cn = parseStringToRecord(csvValue, {header: 0, lineTerminator: LF}); + record {}[]|Error cn = parseStringToRecord(csvValue, {header: 0, lineTerminator: LF}); test:assertEquals(cn, [{a: 1, b: "2\n3"}]); cn = parseStringToRecord(csvValue, {header: 0, lineTerminator: [LF]}); @@ -872,7 +872,7 @@ function testLineTerminatorWithParserOptions() { cn = parseStringToRecord(csvValue, {header: 0, lineTerminator: [CRLF, LF, CR]}); test:assertEquals(cn, [{a: 1, b: "2\n3"}]); - anydata[][]|CsvConversionError cn2 = parseStringToList(csvValue, {header: 0, lineTerminator: LF}); + anydata[][]|Error cn2 = parseStringToList(csvValue, {header: 0, lineTerminator: LF}); test:assertEquals(cn2, [[1, "2\n3"]]); cn2 = parseStringToList(csvValue, {header: 0, lineTerminator: [LF]}); diff --git a/ballerina/types.bal b/ballerina/types.bal index b708124..11b0c38 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -1,4 +1,4 @@ -public type CsvConversionError error; +public type Error error; # Defines the name of the JSON Object key. # diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 0000000..f60b970 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,8 @@ +coverage: + precision: 2 + round: down + range: "60...80" + status: + project: + default: + target: 80 diff --git a/compiler-plugin/src/main/java/module-info.java b/compiler-plugin/src/main/java/module-info.java index 58e15de..60ac711 100644 --- a/compiler-plugin/src/main/java/module-info.java +++ b/compiler-plugin/src/main/java/module-info.java @@ -20,4 +20,4 @@ requires io.ballerina.lang; requires io.ballerina.tools.api; requires io.ballerina.parser; -} \ No newline at end of file +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java index df57a48..1836d4a 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java @@ -33,8 +33,8 @@ */ public class DiagnosticLog { private static final String ERROR_PREFIX = "error"; - private static final String CSV_CONVERSION_ERROR = "CsvConversionError"; - private static final String UNSUPPORTED_OPERATION_ERROR = "CsvConversionError"; + private static final String CSV_CONVERSION_ERROR = "Error"; + private static final String UNSUPPORTED_OPERATION_ERROR = "Error"; private static final ResourceBundle MESSAGES = ResourceBundle.getBundle("error", Locale.getDefault()); public static BError error(DiagnosticErrorCode code, Object... args) { From 41f02a71b2b8904df16a57d78f15b9c52c22111a Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 5 Jul 2024 11:30:07 +0530 Subject: [PATCH 046/147] Removed resolved comments in ballerina files --- .github/CODEOWNERS | 2 +- ballerina/Ballerina.toml | 2 +- .../tests/constraint_validation_test.bal | 23 --- ballerina/tests/error_test.bal | 24 ---- .../tests/parse_list_type_as_list_test.bal | 12 -- .../tests/parse_list_type_as_record_test.bal | 16 --- .../tests/parse_record_type_as_list_test.bal | 11 -- .../parse_record_type_as_record_test.bal | 11 -- .../tests/parse_string_compatibality_test.bal | 11 -- .../tests/parse_string_to_array_test.bal | 11 -- .../tests/parse_string_to_map_tests copy.bal | 18 --- .../tests/parse_string_to_record_tests.bal | 11 -- .../tests/parse_string_to_tuple_test.bal | 11 -- .../tests/parse_type_compatibility_test.bal | 33 ----- .../tests/test_with_intersection_types.bal | 12 -- ballerina/tests/test_with_singleton_test.bal | 2 - ballerina/tests/test_with_union_types.bal | 24 ---- ballerina/tests/types.bal | 1 - .../tests/user_config_projection_tests.bal | 133 +----------------- .../user_config_with_parser_options_test.bal | 35 +---- ballerina/types.bal | 8 +- native/build.gradle | 2 - .../stdlib/data/csvdata/csv/CsvCreator.java | 1 - .../stdlib/data/csvdata/csv/CsvParser.java | 13 -- .../stdlib/data/csvdata/csv/CsvTraversal.java | 7 +- .../io/BallerinaByteBlockInputStream.java | 1 - .../data/csvdata/io/DataReaderThreadPool.java | 2 - .../stdlib/data/csvdata/utils/CsvConfig.java | 10 -- 28 files changed, 11 insertions(+), 436 deletions(-) delete mode 100644 ballerina/tests/error_test.bal diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index c5ebbcf..d0878e0 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -4,4 +4,4 @@ # See: https://help.github.com/articles/about-codeowners/ # These owners will be the default owners for everything in the repo. -* @hasithaa @prakanth97 +* @hasithaa @SasinduDilshara diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index f1d6945..b5288f5 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -2,7 +2,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" -authors = ["Ballerina"] +authors = ["SasinduDilshara"] keywords = ["csv"] repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" license = ["Apache-2.0"] diff --git a/ballerina/tests/constraint_validation_test.bal b/ballerina/tests/constraint_validation_test.bal index 0f02253..3c99d60 100644 --- a/ballerina/tests/constraint_validation_test.bal +++ b/ballerina/tests/constraint_validation_test.bal @@ -1,29 +1,6 @@ import ballerina/test; import ballerina/constraint; -// boolean enable = true; - -// // TODO: - -// @test:Config {enable: !enable} -// function debugTest() returns error? { -// ConstrainedRec[]|Error cRec3 = parseStringToRecord(string `a,b -// 4,abc -// 5, "d"`); -// test:assertEquals(cRec3, ""); -// } - -//TODO: Fix the below test cases - // ConstrainedRec[]|Error cRec3 = parseStringToRecord(string `a,b - // 4,abc - // 5, "" `); - // test:assertEquals(cRec3, ""); - -// ConstrainedRec[]|Error cRec3 = parseStringToRecord(string `a,b -// 4,abc -// 5, "" `); -// test:assertEquals(cRec3, ""); - type ConstrainedRec record { @constraint:Int { minValue: 3, diff --git a/ballerina/tests/error_test.bal b/ballerina/tests/error_test.bal deleted file mode 100644 index 0ca9509..0000000 --- a/ballerina/tests/error_test.bal +++ /dev/null @@ -1,24 +0,0 @@ -import ballerina/test; - -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() returns error? { -// record{}[]|Error csv1op4_3 = parseStringToRecord(csvStringData2, ptOption4); -// test:assertEquals(csv1op4_3, [ -// {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: "()"}, -// {a: 3, b: "string3", c: 0, d: 1.23, e: 1.23, f: "()"}, -// {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} -// ]); -// } - -function errorTest() returns error? { - // check - - record{}[]|Error csv3op3_4 = parseStringToRecord(csvStringData3, {header: 11}); - test:assertEquals(csv3op3_4, []); - - csv3op3_4 = parseStringToRecord(csvStringData3, {header: 3}); - test:assertEquals(csv3op3_4, []); - -} diff --git a/ballerina/tests/parse_list_type_as_list_test.bal b/ballerina/tests/parse_list_type_as_list_test.bal index 7b03d28..4c4fe30 100644 --- a/ballerina/tests/parse_list_type_as_list_test.bal +++ b/ballerina/tests/parse_list_type_as_list_test.bal @@ -1,14 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// DecimalArray1Array|Error st1dda = parseListAsListType([st1, st1], {}, DecimalArray1Array); -// test:assertTrue(st1dda is Error); -// test:assertEquals((st1dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); -// } - @test:Config {enable} function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { StringTuple1Array|Error st1st1 = parseListAsListType([st1, st1], {}, StringTuple1Array); @@ -224,7 +215,6 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType2() { [(), decimal, float, boolean, ()...][]|Error ct1bt11_2 = parseListAsListType( [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); test:assertTrue(ct1bt11_2 is Error); - //TODO: Fix the message test:assertEquals((ct1bt11_2).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "()")); [()...][]|Error ct1bt12 = parseListAsListType( @@ -260,8 +250,6 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType2() { [["a", "b"], ["a", "b"]]); test:assertTrue(ct1bt17 is Error); test:assertEquals((ct1bt17).message(), generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); - - // TODO: Add tests with union types, string|boolean => true } diff --git a/ballerina/tests/parse_list_type_as_record_test.bal b/ballerina/tests/parse_list_type_as_record_test.bal index 0fb63de..30b7fcd 100644 --- a/ballerina/tests/parse_list_type_as_record_test.bal +++ b/ballerina/tests/parse_list_type_as_record_test.bal @@ -1,18 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// record{|()...;|}[]|Error ct1br12 = parseListAsRecordType( -// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], -// ["f", "e", "d", "c", "b", "a"]); -// test:assertEquals(ct1br12, [ -// {a: ()}, -// {a: ()} -// ]); -// } - @test:Config {enable} function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { StringRecord1Array|Error st1sr1 = parseListAsRecordType([st1, st1], (), {}, StringRecord1Array); @@ -523,7 +510,6 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); -// TODO: Check this record{|int|() a; float b; decimal? c; string|boolean d; int|string e; string f; string...;|}[]|Error ct1br9_2 = parseListAsRecordType( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], ["f", "e", "d", "c", "b", "a"]); @@ -556,8 +542,6 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { {a: ()} ]); -// TODO: Add more tests with union types - record{|string?...;|}[]|Error ct1br13 = parseListAsRecordType( [["a", "1"], ["a", "1"]], ["f", "e"]); diff --git a/ballerina/tests/parse_record_type_as_list_test.bal b/ballerina/tests/parse_record_type_as_list_test.bal index bedd8ea..d94ec92 100644 --- a/ballerina/tests/parse_record_type_as_list_test.bal +++ b/ballerina/tests/parse_record_type_as_list_test.bal @@ -1,16 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); -// test:assertEquals(csvb4br1, [ -// {b1: true, b2: "()", b3: (), b4: false}, -// {b1: true, b2: "()", b3: (), b4: false} -// ]); -// } - @test:Config {enable} function testFromCsvWithTypeForMapAndArrayAsExpectedType() { BooleanArrayArray|Error bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanArrayArray); diff --git a/ballerina/tests/parse_record_type_as_record_test.bal b/ballerina/tests/parse_record_type_as_record_test.bal index 7f19758..26f9e0d 100644 --- a/ballerina/tests/parse_record_type_as_record_test.bal +++ b/ballerina/tests/parse_record_type_as_record_test.bal @@ -1,16 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// StringRecord10Array|Error st1sr10 = parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); -// test:assertEquals(st1sr10, [ -// {'1: "string", '2: ""}, -// {'1: "string", '2: ""} -// ]); -// } - @test:Config {enable} function testFromCsvWithTypeForMapAndRecordAsExpectedType() { BooleanRecord1Array|Error bm1br1 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord1Array); diff --git a/ballerina/tests/parse_string_compatibality_test.bal b/ballerina/tests/parse_string_compatibality_test.bal index 9e67d38..63dd104 100644 --- a/ballerina/tests/parse_string_compatibality_test.bal +++ b/ballerina/tests/parse_string_compatibality_test.bal @@ -1,16 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); -// test:assertEquals(csvb4br1, [ -// {b1: true, b2: "()", b3: (), b4: false}, -// {b1: true, b2: "()", b3: (), b4: false} -// ]); -// } - @test:Config {enable} function testFromCsvStringWithTypeCompatibility() { string value = string `i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 diff --git a/ballerina/tests/parse_string_to_array_test.bal b/ballerina/tests/parse_string_to_array_test.bal index eaeee3e..a7ec080 100644 --- a/ballerina/tests/parse_string_to_array_test.bal +++ b/ballerina/tests/parse_string_to_array_test.bal @@ -1,16 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); -// test:assertEquals(csvb4br1, [ -// {b1: true, b2: "()", b3: (), b4: false}, -// {b1: true, b2: "()", b3: (), b4: false} -// ]); -// } - @test:Config {enable} function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { BooleanArrayArray|Error cv1baa = parseStringToList(csvStringWithBooleanValues1); diff --git a/ballerina/tests/parse_string_to_map_tests copy.bal b/ballerina/tests/parse_string_to_map_tests copy.bal index 58e263f..43a87dc 100644 --- a/ballerina/tests/parse_string_to_map_tests copy.bal +++ b/ballerina/tests/parse_string_to_map_tests copy.bal @@ -1,17 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// NillableIntUnionBooleanMapArray|Error bv4bniubma = parseStringToRecord(string `a -// 0`); -// test:assertEquals(bv4bniubma, [ -// {b1: true, b2: (), b3: (), b4: 0}, -// {b1: 1, b2: (), b3: (), b4: false} -// ]); -// } - @test:Config {enable} function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { BooleanMapArray|Error bv1bma = parseStringToRecord(csvStringWithBooleanValues1); @@ -407,10 +395,4 @@ function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { test:assertEquals(bv7dsma, [ {} ]); - - //TODO: Fix the test case - // string csvValue1 = string `a, - // 1,,`; - // record{}[]|error a = parseStringToRecord(csvValue1, {}); - // test:assertEquals(a, [{a: 1}]); } diff --git a/ballerina/tests/parse_string_to_record_tests.bal b/ballerina/tests/parse_string_to_record_tests.bal index ccb9c56..6cee12d 100644 --- a/ballerina/tests/parse_string_to_record_tests.bal +++ b/ballerina/tests/parse_string_to_record_tests.bal @@ -1,16 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); -// test:assertEquals(csvb4br1, [ -// {b1: true, b2: "()", b3: (), b4: false}, -// {b1: true, b2: "()", b3: (), b4: false} -// ]); -// } - @test:Config {enable} function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { BooleanRecord1Array|Error csvb1br1 = parseStringToRecord(csvStringWithBooleanValues1, {}); diff --git a/ballerina/tests/parse_string_to_tuple_test.bal b/ballerina/tests/parse_string_to_tuple_test.bal index ff4513c..03e463c 100644 --- a/ballerina/tests/parse_string_to_tuple_test.bal +++ b/ballerina/tests/parse_string_to_tuple_test.bal @@ -1,16 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); -// test:assertEquals(csvb4br1, [ -// {b1: true, b2: "()", b3: (), b4: false}, -// {b1: true, b2: "()", b3: (), b4: false} -// ]); -// } - @test:Config {enable} function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { BooleanTuple1Array|Error cbv1bt1 = parseStringToList(csvStringWithBooleanValues1); diff --git a/ballerina/tests/parse_type_compatibility_test.bal b/ballerina/tests/parse_type_compatibility_test.bal index 7fc3f64..e402bd0 100644 --- a/ballerina/tests/parse_type_compatibility_test.bal +++ b/ballerina/tests/parse_type_compatibility_test.bal @@ -1,19 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() { -// record{A a; B b; C c;}[]|Error rt12a = 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"} -// ]); -// } - @test:Config {enable} function testFromCsvWithTypeFunctionWithTypeCompatibility() { var value = {i1, i2, s1, s2, b1, b2, n1, n2, f1, f2, d1, d2, j1: b1, a1: d1, j2: b2, a2: d2}; @@ -27,25 +13,6 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {i1, s1, s2, b1, n1, f1, d1, j1: b1, a1: d1, defaultableField: "", nillableField: ()} ]); - // TODO: - // CustomTuple7Array|Error v2ct7a = parseRecordAsListType([value2, value2, value2], {}, CustomTuple7Array); - // test:assertTrue(v2ct7a is Error); - // test:assertEquals((v2ct7a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "string")); - - // CustomTuple7Array|Error v3ct7a = parseRecordAsListType([value3, value3, value3], {}, CustomTuple7Array); - // test:assertEquals(v3ct7a , [ - // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], - // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], - // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3] - // ]); - - // AnydataArray1Array|Error v3anyd1a = parseRecordAsListType([value3, value3, value3], {}, AnydataArray1Array); - // test:assertEquals(v3anyd1a , [ - // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], - // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3], - // [i1, s1, b1, n1, f1, d1, b1, d1, s2, s3] - // ]); - AnydataMapArray|Error vanydma = parseRecordAsRecordType([value, value, value], {}, AnydataMapArray); test:assertEquals(vanydma , [ value, diff --git a/ballerina/tests/test_with_intersection_types.bal b/ballerina/tests/test_with_intersection_types.bal index cee8a01..a5373cd 100644 --- a/ballerina/tests/test_with_intersection_types.bal +++ b/ballerina/tests/test_with_intersection_types.bal @@ -1,13 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() returns error? { -// (int[] & readonly)[]|Error a = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); -// test:assertEquals(a, ""); -// } - @test:Config {enable} function testIntersectionExpectedTypes() returns error? { (int[] & readonly)[]|Error a = parseStringToList(string `a,b @@ -164,7 +156,3 @@ function testIntersectionExpectedTypes3() returns error? { 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}]); } - -// TODO: Add tetsts for, table -// Ignore whitespace in certain conditions -// tests for unicodes \ No newline at end of file diff --git a/ballerina/tests/test_with_singleton_test.bal b/ballerina/tests/test_with_singleton_test.bal index fd3a10d..853ddda 100644 --- a/ballerina/tests/test_with_singleton_test.bal +++ b/ballerina/tests/test_with_singleton_test.bal @@ -221,5 +221,3 @@ function testSubtypeExpectedTypes() returns error? { SubtypeTuple3[]|Error a18 = parseListAsListType(value4, {}); test:assertEquals(a18, value3); } - -// Add implementation for source as Tuples \ No newline at end of file diff --git a/ballerina/tests/test_with_union_types.bal b/ballerina/tests/test_with_union_types.bal index 31a8ba8..7861667 100644 --- a/ballerina/tests/test_with_union_types.bal +++ b/ballerina/tests/test_with_union_types.bal @@ -1,20 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() returns error? { -// record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ -// {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, -// {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, -// {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, -// {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, -// {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} -// ]; - -// RecA[]|RecC[]|Error csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); -// } - type RecA record {int a; string b; boolean c; decimal d; float e; () f;}; type RecB record {|string...;|}; type RecC record {int a; int b; int c;}; @@ -24,7 +9,6 @@ type TupC [int, int, int]; @test:Config {enable} function testParseToStringWithUnionExpectedTypes() returns error? { - // TODO: Fix with tests RecA[]|RecC[] (RecA|RecC)[]|Error csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op1, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -344,7 +328,6 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", d: 3} ]); -// Error Message is Wrong, Needs to check (record{|int a; int...;|}|record{|int a; string...;|})[]|Error csv1op12 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); test:assertTrue(csv1op12 is Error); test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| int a; int...; |}|data.csv:record {| int a; string...; |})[]'"); @@ -398,7 +381,6 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - // TODO: Change the Error Message (TupB|[boolean])[]|Error csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is Error); test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB|[boolean])[]'"); @@ -492,7 +474,6 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - // TODO: Change the Error Message (TupB|[boolean])[]|Error csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is Error); test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB|[boolean])[]'"); @@ -558,7 +539,6 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { @test:Config {enable} function testParseToStringWithUnionExpectedTypes6() returns error? { - // TODO: Fix with tests RecA[]|RecC[] RecA[]|RecC[]|Error csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op1, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -916,7 +896,6 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - // TODO: Change the Error Message TupB[]|[boolean][]|Error csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is Error); test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB[]|[boolean][])'"); @@ -1004,7 +983,6 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - // TODO: Change the Error Message TupB[]|[boolean][]|Error csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is Error); test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB[]|[boolean][])'"); @@ -1061,5 +1039,3 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [string, int...][]|[string, string...][]|Error csv1op12 = parseListAsListType(value, {}); test:assertEquals(csv1op12, value); } - -//TODO: Add test for intersection type in exp type \ No newline at end of file diff --git a/ballerina/tests/types.bal b/ballerina/tests/types.bal index 6a304ae..ebfe68b 100644 --- a/ballerina/tests/types.bal +++ b/ballerina/tests/types.bal @@ -2094,7 +2094,6 @@ type CustomRecord53Array CustomRecord53[]; type CustomRecord54Array CustomRecord54[]; type CustomRecord55Array CustomRecord55[]; type CustomRecord56Array CustomRecord56[]; -// type CustomRecord57Array CustomRecord57[]; type BooleanTuple1Array BooleanTuple1[]; diff --git a/ballerina/tests/user_config_projection_tests.bal b/ballerina/tests/user_config_projection_tests.bal index 1013f99..68d44d1 100644 --- a/ballerina/tests/user_config_projection_tests.bal +++ b/ballerina/tests/user_config_projection_tests.bal @@ -1,15 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() returns error? { -// record {|int a; int? g; int? h;|}[]|Error cn = parseStringToRecord(csvStringData1, { -// allowDataProjection: {absentAsNilableType: true}, -// header: 1 -// }); -// } - @test:Config {enable} function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation[]|Error cn1 = parseStringToRecord(string `b,c @@ -197,7 +187,6 @@ function testCustomNameAnnotation() returns error? { test:assertEquals((cnrr22).message(), "Duplicate field found in record fields: 'c'"); } -//TODO: Emable after fix tuple proj @test:Config {enable} function testCustomNameAnnotation2() returns error? { RecordWithCustomAnnotation[]|Error cntr1 = parseListAsRecordType([["1", "3"]], ["b", "c"], {}); @@ -499,29 +488,6 @@ function testNilAsOptionalConfig2() returns error? { }); test:assertTrue(cn4 is Error); test:assertEquals((cn4).message(), generateErrorMessageForInvalidFieldType("null", "f")); - - // TODO: After add string[] => anydata[] - - // record {|string a; int? f;|}[]|Error cn5 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { - // allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] - // }); - // test:assertEquals(cn5, [{a: "a", f: ()}, {a: "a", f: ()}]); - - // record {|string a; int? f?;|}[]|Error cn6 = parseListAsRecordType([["a", ()], ["a", ()], ["a", ()]], ["a", "f"], { - // allowDataProjection: {nilAsOptionalField: true}, skipLines: [3], - // }); - // test:assertEquals(cn6, [{a: "a"}, {a: "a"}]); - - // record {|string a; int f?;|}[]|Error cn7 = parseListAsRecordType([["a"], ["a"], ["b"]], ["a"], { - // allowDataProjection: {nilAsOptionalField: true}, skipLines: [2] - // }); - // test:assertEquals(cn7, [{a: "a"}, {a: "b"}]); - - // record {|string a; int f;|}[]|Error cn8 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { - // allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] - // }); - // test:assertTrue(cn8 is Error); - // test:assertEquals((cn8).message(), generateErrorMessageForInvalidCast("()", "int")); } @test:Config {enable} @@ -530,7 +496,6 @@ function testDataProjectionConfig() returns error? { "a",2 b,4`; record{}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; - [string, int][] csvValue3 = [["a", 2], ["b", 4]]; record{}[]|Error cn = parseStringToRecord(csvValue1, { allowDataProjection: false @@ -717,100 +682,4 @@ function testDataProjectionConfig() returns error? { }); test:assertTrue(cn26 is Error); test:assertEquals((cn26).message(), "invalid array size for expected array type, cannot be greater than '1'"); - - // TODO: After fixing the issue with the anydata[] - - // record{}[]|Error cnl14 = parseListAsRecordType(csvValue3, ["a", "b"], { - // allowDataProjection: false - // }); - // test:assertEquals(cnl14, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - - // record{|string a; int b;|}[]|Error cnl14_2 = parseListAsRecordType(csvValue3, ["a", "b"], { - // allowDataProjection: false - // }); - // test:assertEquals(cnl14_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - - // record{|string a;|}[]|Error cnl15 = parseListAsRecordType(csvValue3, ["a", "b"], { - // allowDataProjection: false - // }); - // test:assertTrue(cnl15 is Error); - // test:assertEquals((cnl15).message(), "No mapping field in the expected type for header 'b'"); - - // record{|string a; int...;|}[]|Error cnl16 = parseListAsRecordType(csvValue3, ["a", "b"], { - // allowDataProjection: false - // }); - // test:assertEquals(cnl16, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - - // record{|string...;|}[]|Error cnl17 = parseListAsRecordType(csvValue3, ["a", "b"], { - // allowDataProjection: false - // }); - // test:assertEquals(cnl17, [{"a": "a"}, {"a": "b"}]); - - // record{|string a?;|}[]|Error cnl18 = parseListAsRecordType(csvValue3, ["a", "b"], { - // allowDataProjection: false - // }); - // test:assertTrue(cnl18 is Error); - // test:assertEquals((cnl18).message(), "No mapping field in the expected type for header 'b'"); - - // record{|string? a;|}[]|Error cnl19 = parseListAsRecordType(csvValue3, ["a", "b"], { - // allowDataProjection: false - // }); - // test:assertTrue(cnl19 is Error); - // test:assertEquals((cnl19).message(), "No mapping field in the expected type for header 'b'"); - - // anydata[][]|Error cnl20 = parseListAsListType(csvValue3 ,{ - // allowDataProjection: false - // }); - // test:assertEquals(cnl20, [["a", 2], ["b", 4]]); - - // [string, int][]|Error cnl20_2 = parseListAsListType(csvValue3 ,{ - // allowDataProjection: false - // }); - // test:assertEquals(cnl20_2, [["a", 2], ["b", 4]]); - - // [string][]|Error cnl21 = parseListAsListType(csvValue3 ,{ - // allowDataProjection: false - // }); - // test:assertTrue(cnl21 is Error); - // test:assertEquals((cnl21).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); - - // [string][]|Error cnl21_2 = parseListAsListType(csvValue3 ,{ - // allowDataProjection: {} - // }); - // test:assertEquals(cnl21_2, [["a"], ["b"]]); - - // [int][]|Error cnl21_3 = parseListAsListType(csvValue3 ,{ - // allowDataProjection: {} - // }); - // test:assertTrue(cnl21_3 is Error); - // test:assertEquals((cnl21_3).message(), generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); - - // [string, int...][]|Error cnl22 = parseListAsListType(csvValue3 ,{ - // allowDataProjection: false - // }); - // test:assertEquals(cnl22, [["a", 2], ["b", 4]]); - - // [string...][]|Error cnl23 = parseListAsListType(csvValue3 ,{ - // allowDataProjection: false - // }); - // test:assertTrue(cnl23 is Error); - // test:assertEquals(( cnl23).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - - // [string, ()][]|Error cnl24 = parseListAsListType(csvValue3 ,{ - // allowDataProjection: false - // }); - // test:assertTrue(cnl24 is Error); - // test:assertEquals((cnl24).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "()")); - - // string[][]|Error cnl25 = parseListAsListType(csvValue3 ,{ - // allowDataProjection: false - // }); - // test:assertTrue(cnl25 is Error); - // test:assertEquals(( cnl25).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - - // string[][1]|Error cnl26 = parseListAsListType(csvValue3 ,{ - // allowDataProjection: false - // }); - // test:assertTrue(cnl26 is Error); - // test:assertEquals((cnl26).message(), "invalid array size for expected array type, cannot be greater than '1'"); -} \ No newline at end of file +} diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index 5176dbb..2b3244d 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -1,15 +1,5 @@ import ballerina/test; -// boolean enable = true; - -// @test:Config {enable: !enable} -// function debugTest() returns error? { -// record {|int a; int f?;|}[]|Error cn3 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { -// allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] -// }); -// test:assertEquals(cn3, [{a: 1}, {a: 2}]); -// } - @test:Config {enable} function testFromCsvStringWithParserOptions() { [int, string, boolean, decimal, float, string][]|Error csv1op3 = parseStringToList(csvStringData1, option3); @@ -224,8 +214,6 @@ function testNullConfigOption() { cn = parseStringToRecord(csvValue1, {nilValue: "null"}); test:assertTrue(cn is Error); test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("()", "()")); - - // TODO: add nilValue -> "", with str quotes } @test:Config {enable} @@ -283,7 +271,7 @@ function testCommentConfigOption() { cn = parseStringToRecord(csvValue8); test:assertTrue(cn is Error); - // TODO:Fix + // TODO:Fix the error message // test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("1, 2", "int")); cn = parseStringToRecord(csvValue9); @@ -337,7 +325,7 @@ function testCommentConfigOption2() { cn = parseStringToRecord(csvValue5, {comment: "&"}); test:assertTrue(cn is Error); - // TODO: Fix + // TODO: Fix the error message // test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); cn = parseStringToRecord(csvValue6, {comment: "&", header: 2}); @@ -362,7 +350,7 @@ function testCommentConfigOption2() { cn2 = parseStringToRecord(csvValue5, {comment: "&"}); test:assertTrue(cn2 is Error); - // TODO: Fix + // TODO: Fix the error message // test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); cn2 = parseStringToRecord(csvValue6, {header: 2, comment: "&"}); @@ -469,8 +457,6 @@ function testSkipLineParserOption() { [4, "string4", true, -6.51, -6.51, ()], [5, "string5", true, 3, 3.0, ()] ]); - - // Fix:- Add tests for parseType } @test:Config {enable} @@ -507,8 +493,6 @@ function testCustomHeaderOption() { test:assertTrue(bm3ba5 is Error); test:assertEquals((bm3ba5).message(), "Invalid length for the header names"); - // ------------------------------------------------------------- - record {}[]|Error ct1br = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); test:assertTrue(ct1br is Error); test:assertEquals((ct1br).message(), "Invalid length for the custom headers"); @@ -527,7 +511,7 @@ function testCustomHeaderOption() { record {|string a; string b; string c;|}[]|Error ct1br5 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); test:assertTrue(ct1br5 is Error); - // TODO: Fix + // TODO: Fix the error message test:assertEquals((ct1br5).message(), generateErrorMessageForMissingRequiredField("c")); record {string a; string b; string c;}[]|Error ct1br6 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); @@ -569,18 +553,10 @@ function testCustomHeaderOption() { @test:Config {enable} function testCustomHeaderParserOption2() { - // parseStringToRecord - // parseRecordAsRecordType - record {}[]|Error ct1br = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); test:assertTrue(ct1br is Error); test:assertEquals((ct1br).message(), "Invalid length for the custom headers"); - // record{}[]|Error ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b", "aa", "aaa", "aaaaa", "bb", "ccc"]}); - // // TODO: Fix this - // test:assertTrue(ct1br2 is Error); - // test:assertEquals(( ct1br2).message(), "Invalid length for the custom headers"); - record {}[]|Error ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: []}); test:assertTrue(ct1br2 is Error); test:assertEquals((ct1br2).message(), "Invalid length for the custom headers"); @@ -653,7 +629,6 @@ function testCustomHeaderParserOption2() { ]); record {|boolean d1; string e1;|}[]|Error ct1br8 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); - // TODO: Fix test:assertTrue(ct1br8 is Error); test:assertEquals((ct1br8).message(), generateErrorMessageForInvalidCast("string1", "boolean")); @@ -855,8 +830,6 @@ function testDelimiterWithParserOptions() { [4, "string", true, 2.234, -3.21, ()], [5, "string", true, 2.234, -3.21, ()] ]); - - //TODO: Add tests for Unicodes } @test:Config {enable} diff --git a/ballerina/types.bal b/ballerina/types.bal index 11b0c38..f228311 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -13,9 +13,9 @@ public const annotation NameConfig Name on record field; public type Options record { record { # If `true`, nil values will be considered as optional fields in the projection. - boolean nilAsOptionalField = false; // () assign to op + boolean nilAsOptionalField = false; # If `true`, absent fields will be considered as nilable types in the projection. - boolean absentAsNilableType = false; // source haven't () && expected type contains op => () + boolean absentAsNilableType = false; }|false allowDataProjection = {}; int[]|string skipLines = []; }; @@ -25,20 +25,16 @@ public type ParseOption record {| string:Char delimiter = ","; string encoding = "UTF-8"; string locale = "en_US"; -// TODO: Add " for Strings" string:Char textEnclosure = "\""; string:Char escapeChar = "\\"; LineTerminator|LineTerminator[] lineTerminator = [CR, LF, CRLF]; NilValue? nilValue = (); - // string commentStartingSequence = "#"; string:Char comment = "#"; false|int:Unsigned32 header = 0; |}; public type parseToRecordOption record {| *ParseOption; - - // if header = false and this value is null, Then compiler time error. string[]? customHeaders = (); boolean enableConstraintValidation = true; |}; diff --git a/native/build.gradle b/native/build.gradle index 54266fa..d87213d 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -26,7 +26,6 @@ description = 'Ballerina - Data.CSV Java Utils' dependencies { implementation 'junit:junit:4.13.1' -// checkstyle project(':checkstyle') checkstyle "com.puppycrawl.tools:checkstyle:${puppycrawlCheckstyleVersion}" implementation 'org.apache.commons:commons-lang3:3.6' @@ -35,7 +34,6 @@ dependencies { implementation group: 'org.ballerinalang', name: 'value', version: "${ballerinaLangVersion}" implementation group: 'org.ballerinalang', name: 'value', version: "${ballerinaLangVersion}" implementation group: 'io.ballerina.stdlib', name: 'constraint-native', version: "${stdlibConstraintVersion}" - // ballerinaStdLibs "io.ballerina.stdlib:constraint-ballerina:${stdlibConstraintVersion}" } checkstyle { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java index f04e4c6..77bc61f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java @@ -102,7 +102,6 @@ static Object convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, convertedValue); return currentCsv; case TypeTags.ARRAY_TAG: - // Handle projection in array. ArrayType arrayType = (ArrayType) currentCsvNodeType; if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < sm.columnIndex) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index de0343b..e097751 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -227,7 +227,6 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp } switch (expectedArrayElementType.getTag()) { - // TODO: Handle readonly and singleton type as expType. case TypeTags.RECORD_TYPE_TAG: RecordType recordType = (RecordType) expectedArrayElementType; restType = (recordType).getRestFieldType(); @@ -339,7 +338,6 @@ private static class HeaderStartState implements State { public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { char ch; State state = HEADER_START_STATE; - //TODO: If the header is not present make the headers and fieldnames to be default values char separator = sm.config.delimiter; Object customHeader = sm.config.customHeader; int headerStartRowNumber = getHeaderStartRowWhenHeaderIsPresent(sm.config.header); @@ -421,9 +419,6 @@ private static void finalizeHeaders(StateMachine sm) throws CsvParserException { if (expType instanceof RecordType) { validateRemainingRecordFields(sm); } else if (expType instanceof ArrayType) { - // TODO: Get the other validation into here - //TODO: Replace arraysize -1 with - // TODO: Can remove using fillers validateExpectedArraySize(((ArrayType) expType).getSize(), sm.headers.size()); } else if (expType instanceof MapType) { //ignore @@ -436,7 +431,6 @@ private static void finalizeHeaders(StateMachine sm) throws CsvParserException { private static void validateTupleTypes(TupleType tupleType, Type restType, int currentSize) { if (restType != null && tupleType.getTupleTypes().size() > currentSize) { - // TODO: Can remove using fillers throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, currentSize); } } @@ -483,7 +477,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C char separator = sm.config.delimiter; long[] skipLines = getSkipDataRows(sm.config.skipLines); - // TODO: Ignore this in future for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); @@ -501,7 +494,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C continue; } - //TODO: Handle empty values and create again and again if (sm.isCurrentCsvNodeEmpty) { if (ignoreRow(skipLines, sm.rowIndex)) { updateLineAndColumnIndexes(sm); @@ -592,14 +584,12 @@ private static void initiateNewRowType(StateMachine sm) { private static void finalizeTheRow(StateMachine sm) { int rootArraySize = sm.rootArrayType.getSize(); -// updateOptionalFields(sm); if (rootArraySize == -1 || sm.rowIndex < rootArraySize) { sm.rootCsvNode.append(sm.currentCsvNode); } } private static void addRowValue(StateMachine sm) throws CsvParserException { - // TODO: Can convert all at once by storing in a Object[] Type type; Type exptype = sm.expectedArrayElementType; String value = sm.value(); @@ -644,7 +634,6 @@ private static Type getExpectedRowTypeOfTuple(StateMachine sm, TupleType tupleTy } private static Type getExpectedRowTypeOfArray(StateMachine sm, ArrayType arrayType) { - // TODO: add to a constant if (arrayType.getSize() != -1 && arrayType.getSize() <= sm.columnIndex) { sm.charBuffIndex = 0; if (sm.config.allowDataProjection) { @@ -656,11 +645,9 @@ private static Type getExpectedRowTypeOfArray(StateMachine sm, ArrayType arrayTy } private static Type getExpectedRowTypeOfRecord(StateMachine sm) { - // TODO: These can be make as module level variables String header = getHeaderValueForColumnIndex(sm); Map fields = sm.fieldNames; if (fields.containsKey(header)) { - //TODO: Optimize return fields.get(header).getFieldType(); } else { Type restType = sm.restType; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 5fc1686..03c7467 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -532,7 +532,7 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Typ return true; } - for (String key: this.fieldHierarchy.keySet()) { // fh -> a,b | headers -> d,c + for (String key: this.fieldHierarchy.keySet()) { for (String header: this.headers) { if (key.equals(this.updatedRecordFieldNames.get(header))) { return true; @@ -555,15 +555,12 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONVERSION_FOR_ARRAY_TO_MAP, csvElement, expectedType); } - // TODO: Add headers from config addValuesToMapType(csvElement, arraySize, mappingType, expectedType); } private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappingType, Type expectedType) { Type fieldType; BString key; - - // TODO: Canges the logic with headers parameter for (int i = 1; i <= arraySize; i++) { key = StringUtils.fromString(this.headers[i - 1]); if (!mappingType) { @@ -639,7 +636,7 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { return convertedValue; } } else { - switch (fieldType.getTag()) { // type.toString().equals("ballerina/data.csv:0:A") + switch (fieldType.getTag()) { case TypeTags.NULL_TAG: case TypeTags.BOOLEAN_TAG: case TypeTags.INT_TAG: diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java index 203197a..b6705a2 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java @@ -134,7 +134,6 @@ public void notifyFailure(BError bError) { futureResultConsumer.accept(bError); currentChunk = new byte[0]; semaphore.release(); - // TODO : Should we panic here? } @Override diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java index 35728b7..55e732f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java @@ -29,8 +29,6 @@ * @since 0.1.0 */ public class DataReaderThreadPool { - - // TODO : Make this configurable, in Ballerina Library. private static final int CORE_POOL_SIZE = 0; private static final int MAX_POOL_SIZE = 50; private static final long KEEP_ALIVE_TIME = 60L; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java index 3a9c730..93d19d6 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java @@ -89,16 +89,6 @@ private CsvConfig(Object skipLines, boolean nilAsOptionalField, this.stringConversion = stringConversion; } -// private CsvConfig(Object skipLines, boolean nilAsOptionalField, boolean absentAsNilableType, -// boolean allowDataProjection, boolean stringConversion, Object customHeader) { -// this.skipLines = skipLines; -// this.nilAsOptionalField = nilAsOptionalField; -// this.absentAsNilableType = absentAsNilableType; -// this.allowDataProjection = allowDataProjection; -// this.stringConversion = stringConversion; -// this.customHeader = customHeader; -// } - private CsvConfig(Object skipLines, boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, boolean stringConversion, Object customHeader, boolean enableConstraintValidation) { From fec4c7ba7922191764961d9ba7faa6cef13edc13 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 5 Jul 2024 11:34:08 +0530 Subject: [PATCH 047/147] Remove unwanted debug functions and logs --- .../tests/constraint_validation_test.bal | 2 +- .../tests/parse_list_type_as_list_test.bal | 2 +- .../tests/parse_list_type_as_record_test.bal | 8 +++--- .../tests/parse_record_type_as_list_test.bal | 8 +++--- .../parse_record_type_as_record_test.bal | 6 ++-- .../tests/parse_string_compatibality_test.bal | 6 +--- .../tests/parse_string_to_array_test.bal | 2 +- .../tests/parse_string_to_map_tests copy.bal | 2 +- .../tests/parse_string_to_record_tests.bal | 4 +-- .../tests/parse_string_to_tuple_test.bal | 4 +-- .../tests/parse_type_compatibility_test.bal | 4 +-- .../tests/test_with_intersection_types.bal | 6 ++-- ballerina/tests/test_with_singleton_test.bal | 26 ++--------------- ballerina/tests/test_with_union_types.bal | 20 ++++++------- .../tests/user_config_projection_tests.bal | 14 +++++----- .../user_config_with_parser_options_test.bal | 28 +++++++++---------- 16 files changed, 59 insertions(+), 83 deletions(-) diff --git a/ballerina/tests/constraint_validation_test.bal b/ballerina/tests/constraint_validation_test.bal index 3c99d60..bb57ab7 100644 --- a/ballerina/tests/constraint_validation_test.bal +++ b/ballerina/tests/constraint_validation_test.bal @@ -13,7 +13,7 @@ type ConstrainedRec record { string b; }; -@test:Config {enable} +@test:Config function testConstraintWithRecords() returns error? { ConstrainedRec[]|Error cRec1 = parseStringToRecord(string `a,b 4,abc diff --git a/ballerina/tests/parse_list_type_as_list_test.bal b/ballerina/tests/parse_list_type_as_list_test.bal index 4c4fe30..e3501fd 100644 --- a/ballerina/tests/parse_list_type_as_list_test.bal +++ b/ballerina/tests/parse_list_type_as_list_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { StringTuple1Array|Error st1st1 = parseListAsListType([st1, st1], {}, StringTuple1Array); test:assertEquals(st1st1, [ diff --git a/ballerina/tests/parse_list_type_as_record_test.bal b/ballerina/tests/parse_list_type_as_record_test.bal index 30b7fcd..0fc21ab 100644 --- a/ballerina/tests/parse_list_type_as_record_test.bal +++ b/ballerina/tests/parse_list_type_as_record_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { StringRecord1Array|Error st1sr1 = parseListAsRecordType([st1, st1], (), {}, StringRecord1Array); test:assertTrue(st1sr1 is Error); @@ -255,7 +255,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { ]); } -@test:Config {enable} +@test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { StringRecord1Array|Error st3sr1 = parseListAsRecordType([st3, st3], (), {}, StringRecord1Array); test:assertTrue(st3sr1 is Error); @@ -470,7 +470,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { ]); } -@test:Config {enable} +@test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { record{string a; boolean b; int c;}[]|Error ct1br4 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b"], {}); test:assertEquals(ct1br4, [ @@ -576,7 +576,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { ]); } -@test:Config {enable} +@test:Config function testFromCsvWithTypeForTupleAndMapAsExpectedType() { StringMapArray|Error st1sma = parseListAsRecordType([st1, st1], (), {}, StringMapArray); test:assertEquals(st1sma , [ diff --git a/ballerina/tests/parse_record_type_as_list_test.bal b/ballerina/tests/parse_record_type_as_list_test.bal index d94ec92..4bfa6dc 100644 --- a/ballerina/tests/parse_record_type_as_list_test.bal +++ b/ballerina/tests/parse_record_type_as_list_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType() { BooleanArrayArray|Error bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanArrayArray); test:assertEquals(bm1ba, [ @@ -181,7 +181,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { test:assertEquals((bm5sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } -@test:Config {enable} +@test:Config function testFromCsvWithTypeForMapAndTupleAsExpectedType() { BooleanTuple1Array|Error bm1bt = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple1Array); test:assertEquals(bm1bt, [ @@ -364,7 +364,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType() { ]); } -@test:Config {enable} +@test:Config function testFromCsvWithTypeForMapAndTupleAsExpectedType2() { NillableBooleanTuple8Array|Error bm1nb8t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple8Array); test:assertEquals(bm1nb8t, [ @@ -447,7 +447,7 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType2() { test:assertEquals((bm5n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); } -@test:Config {enable} +@test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType2() { AnydataTuple3Array|Error bm1anyd3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataTuple3Array); diff --git a/ballerina/tests/parse_record_type_as_record_test.bal b/ballerina/tests/parse_record_type_as_record_test.bal index 26f9e0d..a212284 100644 --- a/ballerina/tests/parse_record_type_as_record_test.bal +++ b/ballerina/tests/parse_record_type_as_record_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvWithTypeForMapAndRecordAsExpectedType() { BooleanRecord1Array|Error bm1br1 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord1Array); test:assertTrue(bm1br1 is Error); @@ -192,7 +192,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType() { test:assertEquals((bm5br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); } -@test:Config {enable} +@test:Config function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { BooleanRecord9Array|Error bm1br9 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord9Array); test:assertTrue(bm1br9 is Error); @@ -449,7 +449,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { ]); } -@test:Config {enable} +@test:Config function testFromCsvWithTypeForMapAndMapAsExpectedType() { BooleanMapArray|Error bm1bma = parseRecordAsRecordType([bm1, bm1], {}, BooleanMapArray); test:assertEquals(bm1bma, [ diff --git a/ballerina/tests/parse_string_compatibality_test.bal b/ballerina/tests/parse_string_compatibality_test.bal index 63dd104..628b99d 100644 --- a/ballerina/tests/parse_string_compatibality_test.bal +++ b/ballerina/tests/parse_string_compatibality_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvStringWithTypeCompatibility() { string value = string `i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 ${i1},${i2},${s1},${s2},${b1},${b2},(),(),${f1}, ${f2},${d1},${d2},${b1},${d1},${b2},${d2} @@ -63,10 +63,6 @@ function testFromCsvStringWithTypeCompatibility() { [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3] ]); - // CustomTuple8Array|Error v2ct8a = fromCsvStringWithType(value2); - // test:assertTrue(v2ct8a is Error); - // test:assertEquals((v2ct8a).message(), generateErrorMessageForInvalidValueForArrayType("false", "10", "int")); - [float, decimal, string][]|Error mrrta = parseStringToList(string `a, b,c 1.23, 1.23, 1.23 0,0,0 diff --git a/ballerina/tests/parse_string_to_array_test.bal b/ballerina/tests/parse_string_to_array_test.bal index a7ec080..583c29c 100644 --- a/ballerina/tests/parse_string_to_array_test.bal +++ b/ballerina/tests/parse_string_to_array_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { BooleanArrayArray|Error cv1baa = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cv1baa, [ diff --git a/ballerina/tests/parse_string_to_map_tests copy.bal b/ballerina/tests/parse_string_to_map_tests copy.bal index 43a87dc..0ae1bcd 100644 --- a/ballerina/tests/parse_string_to_map_tests copy.bal +++ b/ballerina/tests/parse_string_to_map_tests copy.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { BooleanMapArray|Error bv1bma = parseStringToRecord(csvStringWithBooleanValues1); test:assertEquals(bv1bma, [ diff --git a/ballerina/tests/parse_string_to_record_tests.bal b/ballerina/tests/parse_string_to_record_tests.bal index 6cee12d..e96ef83 100644 --- a/ballerina/tests/parse_string_to_record_tests.bal +++ b/ballerina/tests/parse_string_to_record_tests.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { BooleanRecord1Array|Error csvb1br1 = parseStringToRecord(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br1, [ @@ -401,7 +401,7 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { test:assertEquals((csvb7br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); } -@test:Config {enable} +@test:Config function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { BooleanRecord15Array|Error csvb1br15 = parseStringToRecord(csvStringWithBooleanValues1, {}); test:assertTrue(csvb1br15 is Error); diff --git a/ballerina/tests/parse_string_to_tuple_test.bal b/ballerina/tests/parse_string_to_tuple_test.bal index 03e463c..f2639d1 100644 --- a/ballerina/tests/parse_string_to_tuple_test.bal +++ b/ballerina/tests/parse_string_to_tuple_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { BooleanTuple1Array|Error cbv1bt1 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1bt1, [ @@ -363,7 +363,7 @@ function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { ]); } -@test:Config {enable} +@test:Config function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { JsonTuple3Array|Error cbv1j3 = parseStringToList(csvStringWithBooleanValues1); test:assertEquals(cbv1j3, [ diff --git a/ballerina/tests/parse_type_compatibility_test.bal b/ballerina/tests/parse_type_compatibility_test.bal index e402bd0..681157a 100644 --- a/ballerina/tests/parse_type_compatibility_test.bal +++ b/ballerina/tests/parse_type_compatibility_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvWithTypeFunctionWithTypeCompatibility() { var value = {i1, i2, s1, s2, b1, b2, n1, n2, f1, f2, d1, d2, j1: b1, a1: d1, j2: b2, a2: d2}; var value2 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3, j2: b2, a2: d2}; @@ -88,7 +88,7 @@ type B2 readonly & C | readonly & A2; type C string|boolean; type C2 boolean|string; -@test:Config {enable} +@test:Config function testFromCsvWithIntersectionTypeCompatibility2() { record{ readonly & int a; diff --git a/ballerina/tests/test_with_intersection_types.bal b/ballerina/tests/test_with_intersection_types.bal index a5373cd..e8b5d9d 100644 --- a/ballerina/tests/test_with_intersection_types.bal +++ b/ballerina/tests/test_with_intersection_types.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testIntersectionExpectedTypes() returns error? { (int[] & readonly)[]|Error a = parseStringToList(string `a,b 1,2 @@ -64,7 +64,7 @@ function testIntersectionExpectedTypes() returns error? { test:assertEquals(a10, [{a: "a", b: "a"}, {a: "1", b: "2"}]); } -@test:Config {enable} +@test:Config function testIntersectionExpectedTypes2() returns error? { (int[] & readonly)[]|Error a = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); test:assertTrue(a is (int[] & readonly)[]); @@ -108,7 +108,7 @@ function testIntersectionExpectedTypes2() returns error? { test:assertEquals(a10, [{a: "a", b: "a"}, {a: 1, b: 2}]); } -@test:Config {enable} +@test:Config function testIntersectionExpectedTypes3() returns error? { (int[] & readonly)[]|Error a = parseListAsListType([["1", "2"], ["4", "5"]], {}); test:assertTrue(a is (int[] & readonly)[]); diff --git a/ballerina/tests/test_with_singleton_test.bal b/ballerina/tests/test_with_singleton_test.bal index 853ddda..2915dac 100644 --- a/ballerina/tests/test_with_singleton_test.bal +++ b/ballerina/tests/test_with_singleton_test.bal @@ -1,28 +1,8 @@ import ballerina/test; -boolean enable = true; - -@test:Config {enable: !enable} -function debugTest() returns error? { - var value1 = [{a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}, - {a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}]; - var value2 = [{a: 1, c: int:MAX_VALUE, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}, - {a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}]; - var value3 = [[1, 1, 1, 1, "a", 1, 1, 1], - [1, 1, 1, 1, "a", 1, 1, 1]]; - var value4 = [["1", "1", "1", "1", "a", "1", "1", "1"], - ["1", "1", "1", "1", "a", "1", "1", "1"]]; - - // SubtypeRecord2[]|Error a14 = parseListAsRecordType(value4, - // ["a", "c", "d", "e", "f", "g", "h", "i"], {}); - record {int a; int b;}[]|Error a14 = parseListAsRecordType([["1", "2"], ["1", "2"]], - ["a", "b"], {}); - test:assertEquals(a14, [{a: 1, c: 1}, {a: 1, c: 1}]); -} - type Singleton 1; -@test:Config {enable} +@test:Config function testSingletonExpectedTypes() returns error? { 1[][]|Error a = parseStringToList(string `a, b, c 1, 1, 1 @@ -67,7 +47,7 @@ function testSingletonExpectedTypes() returns error? { test:assertEquals((a8).message(), generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); } -@test:Config {enable} +@test:Config function testSingletonExpectedTypes2() returns error? { 1[][]|Error a = parseStringToList(string `a, b, c 1, 1, 1 @@ -136,7 +116,7 @@ type SubtypeTuple2 [SubType, SubType]; type SubtypeTuple3 [SubType...]; -@test:Config {enable} +@test:Config function testSubtypeExpectedTypes() returns error? { var value1 = [{a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}, {a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}]; diff --git a/ballerina/tests/test_with_union_types.bal b/ballerina/tests/test_with_union_types.bal index 7861667..5d6f21b 100644 --- a/ballerina/tests/test_with_union_types.bal +++ b/ballerina/tests/test_with_union_types.bal @@ -7,7 +7,7 @@ type TupA [int, string, boolean, decimal, float, ()]; type TupB [int...]; type TupC [int, int, int]; -@test:Config {enable} +@test:Config function testParseToStringWithUnionExpectedTypes() returns error? { (RecA|RecC)[]|Error csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op1, [ @@ -116,7 +116,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { ]); } -@test:Config {enable} +@test:Config function testParseToStringWithUnionExpectedTypes2() returns error? { record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -225,7 +225,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { ]); } -@test:Config {enable} +@test:Config function testParseToStringWithUnionExpectedTypes3() returns error? { string[][] value = [ ["1", "string1", "true", "2.234", "2.234", "()"], @@ -340,7 +340,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { } -@test:Config {enable} +@test:Config function testParseToStringWithUnionExpectedTypes4() returns error? { record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -433,7 +433,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { ]); } -@test:Config {enable} +@test:Config function testParseToStringWithUnionExpectedTypes5() returns error? { string[][] value = [ ["1", "string1", "true", "2.234", "2.234", "()"], @@ -537,7 +537,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ]); } -@test:Config {enable} +@test:Config function testParseToStringWithUnionExpectedTypes6() returns error? { RecA[]|RecC[]|Error csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op1, [ @@ -637,7 +637,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { ]); } -@test:Config {enable} +@test:Config function testParseToStringWithUnionExpectedTypes7() returns error? { record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -740,7 +740,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| string a; int...; |}[]|data.csv:record {| string a; string...; |}[])'"); } -@test:Config {enable} +@test:Config function testParseToStringWithUnionExpectedTypes8() returns error? { string[][] value = [ ["1", "string1", "true", "2.234", "2.234", "()"], @@ -855,7 +855,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { } -@test:Config {enable} +@test:Config function testParseToStringWithUnionExpectedTypes9() returns error? { record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -942,7 +942,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...][]|[string,string...][])'"); } -@test:Config {enable} +@test:Config function testParseToStringWithUnionExpectedTypes10() returns error? { string[][] value = [ ["1", "string1", "true", "2.234", "2.234", "()"], diff --git a/ballerina/tests/user_config_projection_tests.bal b/ballerina/tests/user_config_projection_tests.bal index 68d44d1..d4e5c9e 100644 --- a/ballerina/tests/user_config_projection_tests.bal +++ b/ballerina/tests/user_config_projection_tests.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation[]|Error cn1 = parseStringToRecord(string `b,c 1,3`, {}); @@ -187,7 +187,7 @@ function testCustomNameAnnotation() returns error? { test:assertEquals((cnrr22).message(), "Duplicate field found in record fields: 'c'"); } -@test:Config {enable} +@test:Config function testCustomNameAnnotation2() returns error? { RecordWithCustomAnnotation[]|Error cntr1 = parseListAsRecordType([["1", "3"]], ["b", "c"], {}); test:assertEquals(cntr1, [{b: 1, a: 3}]); @@ -271,7 +271,7 @@ function testCustomNameAnnotation2() returns error? { test:assertEquals((cntr22).message(), "Duplicate field found in record fields: 'c'"); } -@test:Config {enable} +@test:Config function testAbsentAsNilableConfig() returns error? { record {|int a; int? g; int? h;|}[]|Error cn = parseStringToRecord(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, @@ -346,7 +346,7 @@ function testAbsentAsNilableConfig() returns error? { test:assertEquals(cn10, [[1, "string1", true, 2.234, 2.234, null, null]]); } -@test:Config {enable} +@test:Config function testAbsentAsNilableConfig2() returns error? { record {|int a; int? g; int? h;|}[]|Error cn = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] @@ -391,7 +391,7 @@ function testAbsentAsNilableConfig2() returns error? { test:assertEquals((cn8).message(), generateErrorMessageForMissingRequiredField("g")); } -@test:Config {enable} +@test:Config function testNilAsOptionalConfig() returns error? { record {|int a; int f?;|}[]|Error cn = parseStringToRecord(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, @@ -466,7 +466,7 @@ function testNilAsOptionalConfig() returns error? { test:assertEquals(cn10, [[1, "string1", true, 2.234, 2.234, null, null]]); } -@test:Config {enable} +@test:Config function testNilAsOptionalConfig2() returns error? { record {|int a; int? f;|}[]|Error cn = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] @@ -490,7 +490,7 @@ function testNilAsOptionalConfig2() returns error? { test:assertEquals((cn4).message(), generateErrorMessageForInvalidFieldType("null", "f")); } -@test:Config {enable} +@test:Config function testDataProjectionConfig() returns error? { string csvValue1 = string `a,b "a",2 diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina/tests/user_config_with_parser_options_test.bal index 2b3244d..7d7cc9b 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina/tests/user_config_with_parser_options_test.bal @@ -1,6 +1,6 @@ import ballerina/test; -@test:Config {enable} +@test:Config function testFromCsvStringWithParserOptions() { [int, string, boolean, decimal, float, string][]|Error csv1op3 = parseStringToList(csvStringData1, option3); test:assertEquals(csv1op3, [ @@ -61,7 +61,7 @@ function testFromCsvStringWithParserOptions() { ]); } -@test:Config {enable} +@test:Config function testFromCsvStringWithHeaderLessParserOptions() { [int, string, boolean, decimal, float, ()][]|Error csv1op6 = parseStringToList(csvStringData1, option6); test:assertTrue(csv1op6 is Error); @@ -122,7 +122,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { ]); } -@test:Config {enable} +@test:Config function testHeaderOption() { record {}[]|Error csv2cop1 = parseStringToRecord(csvStringData2, {header: 4}); test:assertEquals(csv2cop1, [ @@ -147,7 +147,7 @@ function testHeaderOption() { test:assertEquals((csv1cop5).message(), "The provided header row is empty"); } -@test:Config {enable} +@test:Config function testNullConfigOption() { string csvValue1 = string `a ()`; @@ -216,7 +216,7 @@ function testNullConfigOption() { test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("()", "()")); } -@test:Config {enable} +@test:Config function testCommentConfigOption() { string csvValue1 = string `a 1`; @@ -278,7 +278,7 @@ function testCommentConfigOption() { test:assertEquals(cn, [{a: 1}]); } -@test:Config {enable} +@test:Config function testCommentConfigOption2() { string csvValue1 = string `a 1`; @@ -358,7 +358,7 @@ function testCommentConfigOption2() { test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); } -@test:Config {enable} +@test:Config function testSkipLineParserOption() { [int, string, boolean, decimal, float, ()][]|Error csv1cp = parseStringToList(csvStringData1, {skipLines: [], header: 1}); test:assertEquals(csv1cp, [ @@ -459,7 +459,7 @@ function testSkipLineParserOption() { ]); } -@test:Config {enable} +@test:Config function testCustomHeaderOption() { anydata[][]|Error bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}); test:assertEquals(bm1ba, [ @@ -551,7 +551,7 @@ function testCustomHeaderOption() { ]); } -@test:Config {enable} +@test:Config function testCustomHeaderParserOption2() { record {}[]|Error ct1br = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); test:assertTrue(ct1br is Error); @@ -668,7 +668,7 @@ function testCustomHeaderParserOption2() { test:assertEquals((ct1br13).message(), generateErrorMessageForMissingRequiredField("d1")); } -@test:Config {enable} +@test:Config function testTextQuotesWithParserOptions() { string csvValue1 = string ` a, b, c @@ -731,7 +731,7 @@ function testTextQuotesWithParserOptions() { test:assertEquals((cn6).message(), "Invalid length for the custom headers"); } -@test:Config {enable} +@test:Config function testHeaderQuotesWithParserOptions() { string csvValue1 = string ` "a", b, c @@ -766,7 +766,7 @@ function testHeaderQuotesWithParserOptions() { 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"}]); } -@test:Config {enable} +@test:Config function testEscapeCharactersWithParserOptions() { string csvValue1 = string ` "a", b, c @@ -811,7 +811,7 @@ function testEscapeCharactersWithParserOptions() { test:assertEquals(cn3_2, [[1, 2.0, 3.0], [1.0, 2, 3], [1, "2\"", 3], ["1\\", "2\\\"", 3]]); } -@test:Config {enable} +@test:Config function testDelimiterWithParserOptions() { record {}[]|Error cn = parseStringToRecord(csvStringData7, {header: 1, delimiter: "@"}); test:assertEquals(cn, [ @@ -832,7 +832,7 @@ function testDelimiterWithParserOptions() { ]); } -@test:Config {enable} +@test:Config function testLineTerminatorWithParserOptions() { string csvValue = string `a,b${"\n"} 1,"2\n3"`; From fb6d13bf7a00f46ca58d52f9da71f293bb3f2aa8 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 5 Jul 2024 11:39:26 +0530 Subject: [PATCH 048/147] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index b5288f5..f1d6945 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -2,7 +2,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" -authors = ["SasinduDilshara"] +authors = ["Ballerina"] keywords = ["csv"] repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" license = ["Apache-2.0"] From 85352b2e89d455b8989ae3761850da3a673a4749 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 5 Jul 2024 13:43:36 +0530 Subject: [PATCH 049/147] Add API documentations for public types --- .../tests/parse_list_type_as_list_test.bal | 4 +-- ballerina/types.bal | 30 ++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/ballerina/tests/parse_list_type_as_list_test.bal b/ballerina/tests/parse_list_type_as_list_test.bal index e3501fd..7a774d3 100644 --- a/ballerina/tests/parse_list_type_as_list_test.bal +++ b/ballerina/tests/parse_list_type_as_list_test.bal @@ -163,7 +163,7 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { test:assertEquals((st4bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); } -@test:Config{enable} +@test:Config function testFromCsvWithTypeForTupleAndTupleAsExpectedType2() { [string, boolean, int][]|Error ct1bt4 = parseListAsListType([["a", "true", "1"], ["a", "true", "1"]], {}); test:assertEquals(ct1bt4, [ @@ -253,7 +253,7 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType2() { } -@test:Config {enable: enable} +@test:Config function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { StringArrayArray|Error st1saa = parseListAsListType([st1, st1], {}, StringArrayArray); test:assertEquals(st1saa , [ diff --git a/ballerina/types.bal b/ballerina/types.bal index f228311..3fb527a 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -1,3 +1,7 @@ +# Represents an error. +# +# This type is used to capture error details that occur during the execution of a program. +# It can hold an error message, an optional error cause, and an optional map of additional details. public type Error error; # Defines the name of the JSON Object key. @@ -10,6 +14,7 @@ public type NameConfig record {| # The annotation is used to overwrite the existing record field name. public const annotation NameConfig Name on record field; +# Represents options for data projection. public type Options record { record { # If `true`, nil values will be considered as optional fields in the projection. @@ -17,50 +22,73 @@ public type Options record { # 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 = []; }; +# 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 = [CR, 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 {| *Options; + # If `true`, enables conversion of strings during processing. boolean stringConversion = true; |}; +# Represents options for treating a record as a record. public type RecordAsRecordOption record {| *Options; - boolean enableConstraintValidation = true; + # If `true`, enables validation of constraints during processing. + boolean enableConstraintValidation = true; |}; +# Represents options for treating a list as a record. public type ListAsRecordOption record {| *Options; + # If `true`, enables validation of constraints during processing. boolean enableConstraintValidation = true; + # If `true`, enables conversion of strings during processing. boolean stringConversion = true; |}; +# Enum representing possible line terminators. public enum LineTerminator { CR = "\r", LF = "\n", CRLF = "\r\n" }; +# Enum representing possible nil values. public enum NilValue { NULL = "null", EMPTY_STRING = "", From a1924d1694908c85618569525a0ec0e046f48ec5 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 5 Jul 2024 15:13:18 +0530 Subject: [PATCH 050/147] Remove the ReadMe description --- README.md | 454 ------------------------------------------ ballerina/csv_api.bal | 8 +- 2 files changed, 4 insertions(+), 458 deletions(-) diff --git a/README.md b/README.md index ba9bc60..4021c40 100644 --- a/README.md +++ b/README.md @@ -1,455 +1 @@ # Ballerina CSV Data Library - -The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate the handling and manipulation of CSV data within Ballerina applications. It streamlines the process of converting CSV data to native Ballerina data types, enabling developers to work with CSV content seamlessly and efficiently. - -This library is the refined successor of the `ballerina/csvdata` module, incorporating enhanced functionalities and improved performance. - -## Features - -- **Versatile CSV Data Input**: Accept CSV data as a csv, a string, byte array, or a stream and convert it into a Record value. -- **CSV to Record Value Conversion**: Transform CSV data into Ballerina records with ease in compliance with OpenAPI 3 standards. -- **Projection Support**: Perform selective conversion of CSV data subsets into Record values through projection. - -## Usage - -### Converting an CSV value to a Record value - -To convert an CSV value to a Record value, you can utilize the `fromCsvWithType` function provided by the library. The example below showcases the transformation of an CSV value into a Record value. - -```ballerina -import ballerina/data.csv; -import ballerina/io; - -public function main() returns error? { - csv data = csv ` - 0 - string - string - `; - - Book book = check csvdata:fromCsvWithType(data); - io:println(book); -} - -type Book record {| - int id; - string title; - string author; -|}; -``` - -### Converting an external CSV document to a Record value - -For transforming CSV content from an external source into a Record value, the `fromCsvStringWithType` function can be used. This external source can be in the form of a string or a byte array/byte 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; -import ballerina/io; - -public function main() returns error? { - string csvContent = check io:fileReadString("path/to/file.csv"); - Book book = check csvdata:fromCsvStringWithType(csvContent); - io:println(book); -} - -type Book record {| - int id; - string title; - string author; -|}; -``` - -Make sure to handle possible errors that may arise during the file reading or CSV to record conversion process. The `check` keyword is utilized to handle these errors, but more sophisticated error handling can be implemented as per your requirements. - -## CSV to Record Canonical Representation - -The translation of CSV to a Record representation is a fundamental feature of the library. It facilitates a structured and type-safe approach to handling CSV data within Ballerina applications. - -Take for instance the following CSV snippet: - -```csv - - 0 - string - string - -``` - -CSV data is inherently hierarchical, forming a tree structure. In the given example, the root element is `book`, which encompasses three child elements: `id`, `title`, and `author`. The `id` element harbors a numeric value `0`, whereas both the `title` and `author` elements contain string values. - -A straightforward record representation of the above CSV data is: - -```ballerina -type Book record {| - int id; - string title; - string author; -|}; -``` - -In this representation, the CSV data is efficiently translated into a record value. The `book` element is mapped to a record of type `Book`, and the child elements `id`, `title`, and `author` are converted into record fields of types `int` and `string` correspondingly. - -This record type definition can be further refined through annotations. Moreover, utilizing open and closed records grants control over the translation process, which is elaborated in subsequent sections. - -### CSV Element Names - -The name of the CSV element serves as the name of the record field, altered to fit a valid Ballerina identifier. Notably, the record field name corresponds to the local name of the CSV element, with any namespace prefixes being disregarded. - -Consider the CSV snippet: - -```csv - - 0 - string - string - -``` - -The canonical representation of the above CSV as a Ballerina record is: - -```ballerina -type Book record {| - int id; - string 'title\-name'; - string 'author\-name'; -|}; -``` - -Observe how the CSV element names `title-name` and `author-name` are represented using delimited identifiers in Ballerina; the `-` characters in the CSV element names are escaped using the `\` character. - -Moreover, the `@Name` annotation can be utilized to explicitly specify the name of the record field, providing control over the translation process: - -```ballerina -import ballerina/data.csv; - -type Book record {| - int id; - @csvdata:Name { value: "title-name" } - string title; - @csvdata:Name { value: "author-name" } - string author; -|}; -``` - -### CSV Attributes - -Similarly to CSV elements, CSV attributes are also represented into record fields within the corresponding parent Record type. The name of the CSV attribute is converted into the name of the record field, ensuring it is a valid Ballerina identifier. It is crucial to emphasize that the record field name aligns with the local name of the CSV attribute, and any namespace prefixes are ignored. - -Consider the following CSV snippet: - -```csv - - 0 - string - string - -``` - -The canonical representation of the above CSV as a Ballerina record is: - -```ballerina -type Book record {| - string lang; - decimal price; - int id; - string title; - string author; -|}; -``` - -Additionally the `@Attribute` annotation can be utilized to explicitly specify the name of the record field, providing control over the translation process. - -### Child Elements - -Child elements are mapped to record fields, with the type reflecting that of the corresponding child element. - -Examine the CSV snippet below: - -```csv - - 0 - string - - string - string - - -``` - -The canonical representation of the above CSV as a Ballerina record is: - -```ballerina -type Book record {| - int id; - string title; - Author author; -|}; - -type Author record {| - string name; - string country; -|}; -``` - -In this transformation, child elements, like the `author` element containing its own sub-elements, are converted into nested records. This maintains the hierarchical structure of the CSV data within the Ballerina type system, enabling intuitive and type-safe data manipulation. - -Alternatively, inline type definitions offer a compact method for representing child elements as records within their parent record. This approach is particularly beneficial when the child record does not require reuse elsewhere and is unique to its parent record. - -Consider the subsequent Ballerina record definition, which employs inline type definition for the `author` field: - -```ballerina -type Book record {| - int id; - string title; - record {| - string name; - string country; - |} author; -|}; -``` - -### CSV Text Content - -The transformation of CSV text content into record fields typically involves types like `string`, `boolean`, `int`, `float`, or `decimal`, depending on the textual content. For numeric values where type information is not explicitly defined, the default conversion type is `decimal`. Conversely, for non-numeric content, the default type is `string`. - -Consider the CSV snippet below: - -```csv - - 0 - string - string - true - 10.5 - -``` - -The translation into a Ballerina record would be as follows: - -```ballerina -type Book record {| - int id; - string title; - string author; - boolean available; - decimal price; -|}; -``` - -In scenarios where the parent CSV element of text content also includes attributes, the CSV text content can be represented by a `string` type field named `#content` within a record type, with the attributes being mapped to their respective fields. - -For instance, examine this CSV: - -```csv - - 0 - string - 10.5 - -``` - -The canonical translation of CSV to a Ballerina record is as such: - -```ballerina -type Book record {| - int id; - Title title; - decimal price; -|}; - -type Title record {| - string \#content; - string lang; -|}; -``` - -Modifications to the default behavior for converting numerical values can be achieved by providing `Options` mappings to the respective functions. This enables developers to choose specific data types and exert finer control over the conversion process. - -### CSV Namespaces - -CSV namespaces are accommodated by the library, supporting the translation of CSV data that contains namespace prefixes. However, the presence of CSV namespaces is not mandatory, and the library is capable of processing CSV data without namespaces. Should namespaces be present, they will be utilized to resolve the names of CSV elements and attributes. - -It's important to note that, unlike in the `csvdata` module, the namespace prefixes do not reflect in the record field names, as the record field names align with the local names of the CSV elements. - -Examine the CSV snippet below with default namespaces: - -```csv - - 0 - string - string - -``` - -The translation into a Ballerina record would be: - -```ballerina -type Book record {| - int id; - string title; - string author; -|}; -``` - -Incorporating namespace validation yields: - -```ballerina -import ballerina/data.csv; - -@csvdata:Namespace { - uri: "http://example.com/book" -} -type Book record {| - int id; - string title; - string author; -|}; -``` - -Here is the same CSV snippet with a namespace prefix: - -```csv - - 0 - string - string - -``` - -The translation into a Ballerina record would be: - -```ballerina -import ballerina/data.csv; - -@csvdata:Namespace { - uri: "http://example.com/book", - prefix: "bk" -} -type Book record {| - int id; - string title; - string author; -|}; -``` - -In these examples, the CSV namespaces are appropriately acknowledged, ensuring the integrity of the CSV structure within the Ballerina records. - -### Working with Arrays - -The library is equipped to handle the transformation of CSV data containing arrays into Ballerina records. - -Take the following CSV snippet as an example: - -```csv - - 0 - string - string - string - string - -``` - -The canonical representation of this CSV as a Ballerina record is: - -```ballerina -type Book record {| - int id; - string title; - string[] author; -|}; -``` - -### Controlling Which Elements to Convert - -The library allows for selective conversion of CSV elements into records through the use of rest fields. This is beneficial when the CSV data contains elements that are not necessary to be transformed into record fields. - -Take this CSV snippet as an example: - -```csv - - 0 - string - string - 10.5 - -``` - -Suppose that only the book `id`, and `title` elements are needed for conversion into record fields. This can be achieved by defining only the required fields in the record type and omitting the rest field: - -```ballerina -type Book record {| - int id; - string title; -|}; -``` - -However, if the rest field is utilized (or if the record type is defined as an open record), all elements in the CSV data will be transformed into record fields: - -```ballerina -type Book record {| - int id; - string title; -|}; -``` - -In this instance, all other elements in the CSV data, such as `author` and `price` along with their attributes, will be transformed into `string` type fields with the corresponding element name as the key. - -This behavior extends to arrays as well. - -The process of projecting CSV data into a record supports various use cases, including the filtering out of unnecessary elements. This functionality is anticipated to be enhanced in the future to accommodate more complex scenarios, such as filtering values based on regular expressions, among others. - -## Issues and projects - -Issues and Projects tabs are disabled for this repository as this is part of the Ballerina standard library. To report bugs, request new features, start new discussions, view project boards, etc. please visit Ballerina standard library [parent repository](https://github.com/ballerina-platform/ballerina-standard-library). - -This repository only contains the source code for the package. - -## Building from the source - -### Set up the prerequisites - -1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations). - * [Oracle](https://www.oracle.com/java/technologies/downloads/) - * [OpenJDK](https://adoptium.net/) - -2. Export your GitHub personal access token with the read package permissions as follows. - - export packageUser= - export packagePAT= - -### Building the source - -Execute the commands below to build from source. - -1. To build the library: - - ./gradlew clean build - -2. Publish ZIP artifact to the local `.m2` repository: - - ./gradlew clean build publishToMavenLocal - -3. Publish the generated artifacts to the local Ballerina central repository: - - ./gradlew clean build -PpublishToLocalCentral=true - -4. Publish the generated artifacts to the Ballerina central repository: - - ./gradlew clean build -PpublishToCentral=true - -## Contributing to Ballerina - -As an open source project, Ballerina welcomes contributions from the community. - -For more information, go to the [contribution guidelines](https://github.com/ballerina-platform/ballerina-lang/blob/master/CONTRIBUTING.md). - -## Code of conduct - -All contributors are encouraged to read the [Ballerina code of conduct](https://ballerina.io/code-of-conduct). - -## Useful links - -[//]: # (* For more information go to the [`csvdata` library](https://lib.ballerina.io/ballerina/data.csv/latest).) -* Chat live with us via our [Discord server](https://discord.gg/ballerinalang). -* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag. \ No newline at end of file diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 68666f2..4542f65 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -75,7 +75,7 @@ public isolated function parseStreamToList(stream s, # Convert value of type record{}[] to subtype of record{}[]. # -# + v - Source Ballerina record array value +# + 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. @@ -85,7 +85,7 @@ public isolated function parseRecordAsRecordType(record{}[] s, # Convert value of type record{}[] to subtype of anydata[][]. # -# + v - Source Ballerina record array value +# + 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. @@ -95,7 +95,7 @@ public isolated function parseRecordAsListType(record{}[] s, string[] headerName # Convert value of type string[][] to subtype of record{}[]. # -# + v - Source Ballerina string array of array value +# + s - 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. @@ -105,7 +105,7 @@ public isolated function parseListAsRecordType(string[][] s, string[]? customHea # Convert value of type string[][] to subtype of anydata[][]. # -# + v - Source Ballerina string array of array value +# + s - 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. From e4235af79f3f30e7140488952f1830e03565d3cc Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 5 Jul 2024 16:44:47 +0530 Subject: [PATCH 051/147] Update git attributes for windows --- .gitattributes | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.gitattributes b/.gitattributes index d13affe..57e59ae 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1,11 @@ +# +# https://help.github.com/articles/dealing-with-line-endings/ +# +# Linux start script should use lf +/gradlew text eol=lf + +# These are Windows script files and should use crlf +*.bat text eol=crlf + # Ensure all Java files use LF. *.java eol=lf From 58c4dbfaec0c30ba56bd07468f858fb632adb548 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 8 Jul 2024 11:31:15 +0530 Subject: [PATCH 052/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 65 +------------------------------------ 1 file changed, 1 insertion(+), 64 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 8441781..c07b540 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -7,26 +7,12 @@ dependencies-toml-version = "2" distribution-version = "2201.9.0" -[[package]] -org = "ballerina" -name = "constraint" -version = "1.5.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] -modules = [ - {org = "ballerina", packageName = "constraint", moduleName = "constraint"} -] - [[package]] org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "constraint"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "test"} + {org = "ballerina", name = "jballerina.java"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -40,52 +26,3 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - From 7ead9858129c759a3782536d74a2c8715a979154 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 9 Jul 2024 17:10:03 +0530 Subject: [PATCH 053/147] Restructure the ballerina integration test structure --- .gitattributes | 9 - ballerina-tests/build.gradle | 225 ++ .../constraint-validation-tests/.gitignore | 11 + .../Ballerina.toml | 13 + .../Dependencies.toml | 101 + .../tests/constraint_validation_test.bal | 48 +- ballerina-tests/csv-commons/.gitignore | 11 + ballerina-tests/csv-commons/Ballerina.toml | 4 + ballerina-tests/csv-commons/Dependencies.toml | 17 + ballerina-tests/csv-commons/Package.md | 3 + ballerina-tests/csv-commons/test_utils.bal | 23 + .../parse-list-types-tests/.gitignore | 11 + .../parse-list-types-tests/Ballerina.toml | 13 + .../parse-list-types-tests/Dependencies.toml | 98 + .../tests/parse_list_type_as_list_test.bal | 416 +++ .../tests/parse_list_type_as_record_test.bal | 768 +++++ .../tests/test_data_values.bal | 0 .../parse-list-types-tests}/tests/types.bal | 98 - .../parse-record-types-tests/.gitignore | 11 + .../parse-record-types-tests/Ballerina.toml | 13 + .../Dependencies.toml | 98 + .../tests/parse_record_type_as_list_test.bal | 540 ++++ .../parse_record_type_as_record_test.bal | 733 +++++ .../tests/test_data_values.bal | 256 ++ .../parse-record-types-tests/tests/types.bal | 2534 +++++++++++++++++ .../parse-string-array-types-tests/.gitignore | 11 + .../Ballerina.toml | 13 + .../Dependencies.toml | 98 + .../tests/parse_string_to_array_test.bal | 311 ++ .../tests/parse_string_to_tuple_test.bal | 472 +++ .../tests/test_data_values.bal | 256 ++ .../tests/types.bal | 2534 +++++++++++++++++ .../.gitignore | 11 + .../Ballerina.toml | 13 + .../Dependencies.toml | 98 + .../tests/parse_string_to_map_tests copy.bal | 143 +- .../tests/parse_string_to_record_tests.bal | 496 ++++ .../tests/test_data_values.bal | 256 ++ .../tests/types.bal | 2534 +++++++++++++++++ .../type-compatible-tests/.gitignore | 11 + .../type-compatible-tests/Ballerina.toml | 13 + .../type-compatible-tests/Dependencies.toml | 98 + .../tests/parse_string_compatibality_test.bal | 52 +- .../tests/parse_type_compatibility_test.bal | 110 +- .../tests/test_data_values.bal | 256 ++ .../type-compatible-tests/tests/types.bal | 2534 +++++++++++++++++ ballerina-tests/union-type-tests/.gitignore | 11 + .../union-type-tests/Ballerina.toml | 13 + .../union-type-tests/Dependencies.toml | 98 + .../tests/test_data_values.bal | 256 ++ .../tests/test_with_intersection_types.bal | 63 +- .../tests/test_with_singleton_test.bal | 86 +- .../tests/test_with_union_types.bal | 349 +-- .../union-type-tests/tests/types.bal | 2534 +++++++++++++++++ ballerina-tests/user-config-tests/.gitignore | 11 + .../user-config-tests/Ballerina.toml | 13 + .../user-config-tests/Dependencies.toml | 98 + .../tests/test_data_values.bal | 256 ++ .../user-config-tests/tests/types.bal | 73 + .../tests/user_config_projection_tests.bal | 388 ++- .../user_config_with_parser_options_test.bal | 410 +-- .../user-config-tests/tests/user_configs.bal | 29 + ballerina/build.gradle | 4 + .../tests/parse_list_type_as_list_test.bal | 409 --- .../tests/parse_list_type_as_record_test.bal | 748 ----- .../tests/parse_record_type_as_list_test.bal | 532 ---- .../parse_record_type_as_record_test.bal | 722 ----- .../tests/parse_string_to_array_test.bal | 303 -- .../tests/parse_string_to_record_tests.bal | 485 ---- .../tests/parse_string_to_tuple_test.bal | 463 --- ballerina/tests/test_utils.bal | 23 - ballerina/tests/user_configs.bal | 27 - build-config/resources/BallerinaTest.toml | 13 + build-config/resources/CsvTestCommon.toml | 4 + gradle.properties | 1 + .../stdlib/data/csvdata/csv/CsvParser.java | 27 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 6 +- settings.gradle | 4 + 78 files changed, 20173 insertions(+), 4660 deletions(-) create mode 100644 ballerina-tests/build.gradle create mode 100644 ballerina-tests/constraint-validation-tests/.gitignore create mode 100644 ballerina-tests/constraint-validation-tests/Ballerina.toml create mode 100644 ballerina-tests/constraint-validation-tests/Dependencies.toml rename {ballerina => ballerina-tests/constraint-validation-tests}/tests/constraint_validation_test.bal (58%) create mode 100644 ballerina-tests/csv-commons/.gitignore create mode 100644 ballerina-tests/csv-commons/Ballerina.toml create mode 100644 ballerina-tests/csv-commons/Dependencies.toml create mode 100644 ballerina-tests/csv-commons/Package.md create mode 100644 ballerina-tests/csv-commons/test_utils.bal create mode 100644 ballerina-tests/parse-list-types-tests/.gitignore create mode 100644 ballerina-tests/parse-list-types-tests/Ballerina.toml create mode 100644 ballerina-tests/parse-list-types-tests/Dependencies.toml create mode 100644 ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal create mode 100644 ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_record_test.bal rename {ballerina => ballerina-tests/parse-list-types-tests}/tests/test_data_values.bal (100%) rename {ballerina => ballerina-tests/parse-list-types-tests}/tests/types.bal (97%) create mode 100644 ballerina-tests/parse-record-types-tests/.gitignore create mode 100644 ballerina-tests/parse-record-types-tests/Ballerina.toml create mode 100644 ballerina-tests/parse-record-types-tests/Dependencies.toml create mode 100644 ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal create mode 100644 ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_record_test.bal create mode 100644 ballerina-tests/parse-record-types-tests/tests/test_data_values.bal create mode 100644 ballerina-tests/parse-record-types-tests/tests/types.bal create mode 100644 ballerina-tests/parse-string-array-types-tests/.gitignore create mode 100644 ballerina-tests/parse-string-array-types-tests/Ballerina.toml create mode 100644 ballerina-tests/parse-string-array-types-tests/Dependencies.toml create mode 100644 ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal create mode 100644 ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_tuple_test.bal create mode 100644 ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal create mode 100644 ballerina-tests/parse-string-array-types-tests/tests/types.bal create mode 100644 ballerina-tests/parse-string-record-types-tests/.gitignore create mode 100644 ballerina-tests/parse-string-record-types-tests/Ballerina.toml create mode 100644 ballerina-tests/parse-string-record-types-tests/Dependencies.toml rename {ballerina => ballerina-tests/parse-string-record-types-tests}/tests/parse_string_to_map_tests copy.bal (56%) create mode 100644 ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_record_tests.bal create mode 100644 ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal create mode 100644 ballerina-tests/parse-string-record-types-tests/tests/types.bal create mode 100644 ballerina-tests/type-compatible-tests/.gitignore create mode 100644 ballerina-tests/type-compatible-tests/Ballerina.toml create mode 100644 ballerina-tests/type-compatible-tests/Dependencies.toml rename {ballerina => ballerina-tests/type-compatible-tests}/tests/parse_string_compatibality_test.bal (78%) rename {ballerina => ballerina-tests/type-compatible-tests}/tests/parse_type_compatibility_test.bal (74%) create mode 100644 ballerina-tests/type-compatible-tests/tests/test_data_values.bal create mode 100644 ballerina-tests/type-compatible-tests/tests/types.bal create mode 100644 ballerina-tests/union-type-tests/.gitignore create mode 100644 ballerina-tests/union-type-tests/Ballerina.toml create mode 100644 ballerina-tests/union-type-tests/Dependencies.toml create mode 100644 ballerina-tests/union-type-tests/tests/test_data_values.bal rename {ballerina => ballerina-tests/union-type-tests}/tests/test_with_intersection_types.bal (67%) rename {ballerina => ballerina-tests/union-type-tests}/tests/test_with_singleton_test.bal (66%) rename {ballerina => ballerina-tests/union-type-tests}/tests/test_with_union_types.bal (62%) create mode 100644 ballerina-tests/union-type-tests/tests/types.bal create mode 100644 ballerina-tests/user-config-tests/.gitignore create mode 100644 ballerina-tests/user-config-tests/Ballerina.toml create mode 100644 ballerina-tests/user-config-tests/Dependencies.toml create mode 100644 ballerina-tests/user-config-tests/tests/test_data_values.bal create mode 100644 ballerina-tests/user-config-tests/tests/types.bal rename {ballerina => ballerina-tests/user-config-tests}/tests/user_config_projection_tests.bal (53%) rename {ballerina => ballerina-tests/user-config-tests}/tests/user_config_with_parser_options_test.bal (57%) create mode 100644 ballerina-tests/user-config-tests/tests/user_configs.bal delete mode 100644 ballerina/tests/parse_list_type_as_list_test.bal delete mode 100644 ballerina/tests/parse_list_type_as_record_test.bal delete mode 100644 ballerina/tests/parse_record_type_as_list_test.bal delete mode 100644 ballerina/tests/parse_record_type_as_record_test.bal delete mode 100644 ballerina/tests/parse_string_to_array_test.bal delete mode 100644 ballerina/tests/parse_string_to_record_tests.bal delete mode 100644 ballerina/tests/parse_string_to_tuple_test.bal delete mode 100644 ballerina/tests/test_utils.bal delete mode 100644 ballerina/tests/user_configs.bal create mode 100644 build-config/resources/BallerinaTest.toml create mode 100644 build-config/resources/CsvTestCommon.toml diff --git a/.gitattributes b/.gitattributes index 57e59ae..d13affe 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,11 +1,2 @@ -# -# https://help.github.com/articles/dealing-with-line-endings/ -# -# Linux start script should use lf -/gradlew text eol=lf - -# These are Windows script files and should use crlf -*.bat text eol=crlf - # Ensure all Java files use LF. *.java eol=lf diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle new file mode 100644 index 0000000..524cca8 --- /dev/null +++ b/ballerina-tests/build.gradle @@ -0,0 +1,225 @@ +/* + * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ +plugins { + id 'jacoco' +} + +//apply plugin: 'java' + +import org.apache.tools.ant.taskdefs.condition.Os + +description = 'Ballerina - HTTP/WS Ballerina Tests' + +def packageName = "data.csv" +def packageOrg = "ballerina" +def tomlVersion = stripBallerinaExtensionVersion("${project.version}") +def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/BallerinaTest.toml") +def testCommonTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/CsvTestCommon.toml") +def ballerinaDist = "${project.rootDir}/target/ballerina-runtime" +def distributionBinPath = "${ballerinaDist}/bin" +def testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.stdlib.data.*:ballerina.*" +def testPackages = ["constraint-validation-tests", "parse-list-types-tests", "parse-record-types-tests", + "parse-string-array-types-tests", "parse-string-record-types-tests", "type-compatible-tests", + "union-type-tests", "user-config-tests"] +def testCommonPackage = "csv-commons" + +def stripBallerinaExtensionVersion(String extVersion) { + if (extVersion.matches(project.ext.timestampedVersionRegex)) { + def splitVersion = extVersion.split('-'); + if (splitVersion.length > 3) { + def strippedValues = splitVersion[0..-4] + return strippedValues.join('-') + } else { + return extVersion + } + } else { + return extVersion.replace("${project.ext.snapshotVersion}", "") + } +} + +task clean { + delete "${project.projectDir}/${testCommonPackage}/target" + + testPackages.each { testPackage -> + delete "${project.projectDir}/${testPackage}/target" + } +} + +task updateTomlVersions { + doLast { + testPackages.each { testPackage -> + def ballerinaTomlFile = new File("${project.projectDir}/${testPackage}/Ballerina.toml") + def newBallerinaToml = ballerinaTomlFilePlaceHolder.text.replace("@project.version@", project.version) + newBallerinaToml = newBallerinaToml.replace("@toml.version@", tomlVersion) + newBallerinaToml = newBallerinaToml.replace("@test.common@", testCommonPackage.replaceAll("-", "_")) + newBallerinaToml = newBallerinaToml.replace("@package.name@", testPackage.replaceAll("-", "_")) + ballerinaTomlFile.text = newBallerinaToml + } + + def ballerinaTomlFile = new File("${project.projectDir}/${testCommonPackage}/Ballerina.toml") + def newBallerinaToml = testCommonTomlFilePlaceHolder.text.replace("@project.version@", project.version) + newBallerinaToml = newBallerinaToml.replace("@toml.version@", tomlVersion) + newBallerinaToml = newBallerinaToml.replace("@package.name@", testCommonPackage.replaceAll("-", "_")) + ballerinaTomlFile.text = newBallerinaToml + } +} + +def groupParams = "" +def disableGroups = "" +def windowsDisableGroups = "--disable-groups disabledOnWindows" +def debugParams = "" +def balJavaDebugParam = "" +def testParams = "" +def graalvmFlag = "" +def parallelTestFlag = "" +def skipTests = false + +task deleteDependencyTomlFile { + if (project.hasProperty("deleteDependencies")) { + delete "${project.projectDir}/${testCommonPackage}/Dependencies.toml" + + testPackages.each { testPackage -> + delete "${project.projectDir}/${testPackage}/Dependencies.toml" + } + } +} + +task initializeVariables { + if (project.hasProperty("groups")) { + groupParams = "--groups ${project.findProperty("groups")}" + } + if (project.hasProperty("disable")) { + disableGroups = "--disable-groups ${project.findProperty("disable")}" + } + if (project.hasProperty("debug")) { + debugParams = "--debug ${project.findProperty("debug")}" + } + if (project.hasProperty("balJavaDebug")) { + balJavaDebugParam = "BAL_JAVA_DEBUG=${project.findProperty("balJavaDebug")}" + } + if (project.hasProperty('balGraalVMTest')) { + graalvmFlag = '--graalvm' + } + if (project.hasProperty('balParallelTest')) { + parallelTestFlag = '--parallel' + } + if (project.hasProperty('balTests')) { + testPackages = project.findProperty('balTests').toString().split(",") + } + if (project.hasProperty('skipBalTests')) { + project.findProperty('skipBalTests').toString().split(",").each {testPackage -> + testPackages.remove(testPackage) + } + } + + + gradle.taskGraph.whenReady { graph -> + if (graph.hasTask(":${packageName}-ballerina-tests:test")) { + if (!project.hasProperty('balGraalVMTest')) { + testParams = "${testCoverageParam}" + } + } else { + skipTests = true + } + } +} + +task publishTestCommonPackageToLocal { + dependsOn(":${packageName}-${packageOrg}:build") + dependsOn(updateTomlVersions) + doLast { + if (!skipTests) { + exec { + workingDir "${project.projectDir}/${testCommonPackage}" + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "${distributionBinPath}/bal.bat pack && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', '-c', "${distributionBinPath}/bal pack" + } + } + exec { + workingDir "${project.projectDir}/${testCommonPackage}" + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "${distributionBinPath}/bal.bat push --repository=local" + + " && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', '-c', "${distributionBinPath}/bal push --repository=local" + } + } + } + } +} + +task ballerinaTest { + inputs.dir file(project.projectDir) + dependsOn(":${packageName}-${packageOrg}:build") + dependsOn(updateTomlVersions) + dependsOn(initializeVariables) + dependsOn(publishTestCommonPackageToLocal) + dependsOn(deleteDependencyTomlFile) + + doLast { + testPackages.each { testPackage -> + if (!skipTests) { + exec { + workingDir "${project.projectDir}/${testPackage}" + environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "${balJavaDebugParam} ${distributionBinPath}/bal.bat test ${graalvmFlag}" + + " ${parallelTestFlag} ${testParams} ${groupParams} ${disableGroups} ${windowsDisableGroups}" + + " ${debugParams} && exit %%ERRORLEVEL%%" + } else { + commandLine 'sh', '-c', "${distributionBinPath}/bal test ${graalvmFlag} ${parallelTestFlag} ${testParams}" + + " ${groupParams} ${disableGroups} ${debugParams}" + } + } + if (project.hasProperty('balGraalVMTest')) { + exec { + workingDir "${project.projectDir}/${testPackage}" + environment "JAVA_OPTS", "-DBALLERINA_DEV_COMPILE_BALLERINA_ORG=true" + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "${distributionBinPath}/bal.bat clean" + } else { + commandLine 'sh', '-c', "${distributionBinPath}/bal clean" + } + } + } + } + } + } +} + +publishing { + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/ballerina-platform/module-${packageOrg}-${packageName}") + credentials { + username = System.getenv("packageUser") + password = System.getenv("packagePAT") + } + } + } +} + +task test { + dependsOn(ballerinaTest) +} + +task build { + dependsOn(test) +} diff --git a/ballerina-tests/constraint-validation-tests/.gitignore b/ballerina-tests/constraint-validation-tests/.gitignore new file mode 100644 index 0000000..d5fc29a --- /dev/null +++ b/ballerina-tests/constraint-validation-tests/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/ballerina-tests/constraint-validation-tests/Ballerina.toml b/ballerina-tests/constraint-validation-tests/Ballerina.toml new file mode 100644 index 0000000..c0b0817 --- /dev/null +++ b/ballerina-tests/constraint-validation-tests/Ballerina.toml @@ -0,0 +1,13 @@ +[package] +org = "ballerina" +name = "constraint_validation_tests" +version = "0.1.0" + +[[dependency]] +org = "ballerina" +name = "csv_commons" +repository = "local" +version = "0.1.0" + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina-tests/constraint-validation-tests/Dependencies.toml b/ballerina-tests/constraint-validation-tests/Dependencies.toml new file mode 100644 index 0000000..7f54d3a --- /dev/null +++ b/ballerina-tests/constraint-validation-tests/Dependencies.toml @@ -0,0 +1,101 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0" + +[[package]] +org = "ballerina" +name = "constraint" +version = "1.5.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "constraint", moduleName = "constraint"} +] + +[[package]] +org = "ballerina" +name = "constraint_validation_tests" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "data.csv"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerina", packageName = "constraint_validation_tests", moduleName = "constraint_validation_tests"} +] + +[[package]] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + diff --git a/ballerina/tests/constraint_validation_test.bal b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal similarity index 58% rename from ballerina/tests/constraint_validation_test.bal rename to ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal index bb57ab7..3710770 100644 --- a/ballerina/tests/constraint_validation_test.bal +++ b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal @@ -1,5 +1,6 @@ -import ballerina/test; import ballerina/constraint; +import ballerina/data.csv as csv; +import ballerina/test; type ConstrainedRec record { @constraint:Int { @@ -15,49 +16,48 @@ type ConstrainedRec record { @test:Config function testConstraintWithRecords() returns error? { - ConstrainedRec[]|Error cRec1 = parseStringToRecord(string `a,b + ConstrainedRec[]|csv:Error cRec1 = csv:parseStringToRecord(string `a,b 4,abc 3, cde`); test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); - cRec1 = parseStringToRecord(string `a,b + cRec1 = csv:parseStringToRecord(string `a,b 4,abc 11, cde`); - test:assertTrue(cRec1 is Error); - test:assertTrue((cRec1).message().startsWith("Validation failed") + test:assertTrue(cRec1 is csv:Error); + test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("maxValue")); - cRec1 = parseStringToRecord(string `a,b + cRec1 = csv:parseStringToRecord(string `a,b 4,abc 5, "b"`, {}); - test:assertTrue(cRec1 is Error); - test:assertTrue((cRec1).message().startsWith("Validation failed") + test:assertTrue(cRec1 is csv:Error); + test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("minLength")); - - cRec1 = parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 3, "b": "cde"}], {}); + cRec1 = csv:parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 3, "b": "cde"}], {}); test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); - cRec1 = parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 11, "b": "cde"}], {}); - test:assertTrue(cRec1 is Error); - test:assertTrue((cRec1).message().startsWith("Validation failed") + cRec1 = csv:parseRecordAsRecordType([{"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 = parseRecordAsRecordType([{"a": 4, "b": "abc"}, {"a": 5, "b": "b"}], {}); - test:assertTrue(cRec1 is Error); - test:assertTrue((cRec1).message().startsWith("Validation failed") + cRec1 = csv:parseRecordAsRecordType([{"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 = parseListAsRecordType([["4", "abc"], ["3", "cde"]], ["a", "b"]); + cRec1 = csv:parseListAsRecordType([["4", "abc"], ["3", "cde"]], ["a", "b"]); test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); - cRec1 = parseListAsRecordType([["4", "abc"], ["11", "cde"]], ["a", "b"]); - test:assertTrue(cRec1 is Error); - test:assertTrue((cRec1).message().startsWith("Validation failed") + cRec1 = csv:parseListAsRecordType([["4", "abc"], ["11", "cde"]], ["a", "b"]); + test:assertTrue(cRec1 is csv:Error); + test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("maxValue")); - cRec1 = parseListAsRecordType([["4", "abc"], ["5", "b"]], ["a", "b"]); - test:assertTrue(cRec1 is Error); - test:assertTrue((cRec1).message().startsWith("Validation failed") + cRec1 = csv:parseListAsRecordType([["4", "abc"], ["5", "b"]], ["a", "b"]); + test:assertTrue(cRec1 is csv:Error); + test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("minLength")); -} \ No newline at end of file +} diff --git a/ballerina-tests/csv-commons/.gitignore b/ballerina-tests/csv-commons/.gitignore new file mode 100644 index 0000000..d5fc29a --- /dev/null +++ b/ballerina-tests/csv-commons/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/ballerina-tests/csv-commons/Ballerina.toml b/ballerina-tests/csv-commons/Ballerina.toml new file mode 100644 index 0000000..0b77a15 --- /dev/null +++ b/ballerina-tests/csv-commons/Ballerina.toml @@ -0,0 +1,4 @@ +[package] +org = "ballerina" +name = "csv_commons" +version = "0.1.0" diff --git a/ballerina-tests/csv-commons/Dependencies.toml b/ballerina-tests/csv-commons/Dependencies.toml new file mode 100644 index 0000000..88bd281 --- /dev/null +++ b/ballerina-tests/csv-commons/Dependencies.toml @@ -0,0 +1,17 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0" + +[[package]] +org = "ballerina" +name = "csv_commons" +version = "0.1.0" +modules = [ + {org = "ballerina", packageName = "csv_commons", moduleName = "csv_commons"} +] + diff --git a/ballerina-tests/csv-commons/Package.md b/ballerina-tests/csv-commons/Package.md new file mode 100644 index 0000000..8a7ecb6 --- /dev/null +++ b/ballerina-tests/csv-commons/Package.md @@ -0,0 +1,3 @@ +## Package overview + +This package provides APIs for testing ballerina CSV data module. diff --git a/ballerina-tests/csv-commons/test_utils.bal b/ballerina-tests/csv-commons/test_utils.bal new file mode 100644 index 0000000..64123d1 --- /dev/null +++ b/ballerina-tests/csv-commons/test_utils.bal @@ -0,0 +1,23 @@ +public function generateErrorMessageForMissingRequiredField(string 'field) returns string { + return string `no matching header value is found for the required field '${'field}'`; +} + +public function generateErrorMessageForInvalidCast(string value, string 'type) returns string { + return string `value '${value}' cannot be cast into '${'type}'`; +} + +public function generateErrorMessageForInvalidFieldType(string value, string 'key) returns string { + return string `no mapping type found for value '${value}' in key '${'key}'`; +} + +public function generateErrorMessageForInvalidValueForArrayType(string value, string index, string arrayType) returns string { + return string `value '${value}' in index '${index}' is not compatible with array type '${arrayType}'`; +} + +public function generateErrorMessageForInvalidHeaders(string value, string 'type) returns string{ + 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}'`; +} diff --git a/ballerina-tests/parse-list-types-tests/.gitignore b/ballerina-tests/parse-list-types-tests/.gitignore new file mode 100644 index 0000000..d5fc29a --- /dev/null +++ b/ballerina-tests/parse-list-types-tests/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/ballerina-tests/parse-list-types-tests/Ballerina.toml b/ballerina-tests/parse-list-types-tests/Ballerina.toml new file mode 100644 index 0000000..6374fc7 --- /dev/null +++ b/ballerina-tests/parse-list-types-tests/Ballerina.toml @@ -0,0 +1,13 @@ +[package] +org = "ballerina" +name = "parse_list_types_tests" +version = "0.1.0" + +[[dependency]] +org = "ballerina" +name = "csv_commons" +repository = "local" +version = "0.1.0" + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina-tests/parse-list-types-tests/Dependencies.toml b/ballerina-tests/parse-list-types-tests/Dependencies.toml new file mode 100644 index 0000000..279d0c7 --- /dev/null +++ b/ballerina-tests/parse-list-types-tests/Dependencies.toml @@ -0,0 +1,98 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0" + +[[package]] +org = "ballerina" +name = "csv_commons" +version = "0.1.0" +scope = "testOnly" +modules = [ + {org = "ballerina", packageName = "csv_commons", moduleName = "csv_commons"} +] + +[[package]] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "parse_list_types_tests" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "csv_commons"}, + {org = "ballerina", name = "data.csv"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerina", packageName = "parse_list_types_tests", moduleName = "parse_list_types_tests"} +] + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + 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 new file mode 100644 index 0000000..f3ef889 --- /dev/null +++ b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal @@ -0,0 +1,416 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; +import ballerina/test; + +@test:Config +function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { + StringTuple1Array|csv:Error st1st1 = csv:parseListAsListType([st1, st1], {}, StringTuple1Array); + test:assertEquals(st1st1, [ + [s1, s2, "", ""], + [s1, s2, "", ""] + ]); + + StringTuple1Array|csv:Error st2st1 = csv:parseListAsListType([st2, st2], {}, StringTuple1Array); + test:assertEquals(st2st1, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple1Array|csv:Error st3st1 = csv:parseListAsListType([st3, st3], {}, StringTuple1Array); + test:assertEquals(st3st1, [ + [s1, s2, "", ""], + [s1, s2, "", ""] + ]); + + StringTuple1Array|csv:Error st4st1 = csv:parseListAsListType([st4, st4], {}, StringTuple1Array); + test:assertEquals(st4st1, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple2Array|csv:Error st1st2 = csv:parseListAsListType([st1, st1], {}, StringTuple2Array); + test:assertEquals(st1st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple2Array|csv:Error st2st2 = csv:parseListAsListType([st2, st2], {}, StringTuple2Array); + test:assertEquals(st2st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple2Array|csv:Error st3st2 = csv:parseListAsListType([st3, st3], {}, StringTuple2Array); + test:assertEquals(st3st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple2Array|csv:Error st4st2 = csv:parseListAsListType([st4, st4], {}, StringTuple2Array); + test:assertEquals(st4st2, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple3Array|csv:Error st1st3 = csv:parseListAsListType([st1, st1], {}, StringTuple3Array); + test:assertEquals(st1st3, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple3Array|csv:Error st2st3 = csv:parseListAsListType([st2, st2], {}, StringTuple3Array); + test:assertEquals(st2st3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple3Array|csv:Error st3st3 = csv:parseListAsListType([st3, st3], {}, StringTuple3Array); + test:assertEquals(st3st3, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple3Array|csv:Error st4st3 = csv:parseListAsListType([st4, st4], {}, StringTuple3Array); + test:assertEquals(st4st3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndTupleAsExpectedType2() { + StringTuple4Array|csv:Error st1st4 = csv:parseListAsListType([st1, st1], {}, StringTuple4Array); + test:assertEquals(st1st4, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple4Array|csv:Error st2st4 = csv:parseListAsListType([st2, st2], {}, StringTuple4Array); + test:assertEquals(st2st4, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringTuple4Array|csv:Error st3st4 = csv:parseListAsListType([st3, st3], {}, StringTuple4Array); + test:assertEquals(st3st4, [ + [s1, s2], + [s1, s2] + ]); + + StringTuple4Array|csv:Error st4st4 = csv:parseListAsListType([st4, st4], {}, StringTuple4Array); + test:assertEquals(st4st4, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataTuple3Array|csv:Error st1anydt3 = csv:parseListAsListType([st1, st1], {}, AnydataTuple3Array); + test:assertEquals(st1anydt3, [ + [s1, s2], + [s1, s2] + ]); + + AnydataTuple3Array|csv:Error st2anydt3 = csv:parseListAsListType([st2, st2], {}, AnydataTuple3Array); + test:assertEquals(st2anydt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataTuple3Array|csv:Error st3anydt3 = csv:parseListAsListType([st3, st3], {}, AnydataTuple3Array); + test:assertEquals(st3anydt3, [ + [s1, s2], + [s1, s2] + ]); + + AnydataTuple3Array|csv:Error st4anydt3 = csv:parseListAsListType([st4, st4], {}, AnydataTuple3Array); + test:assertEquals(st4anydt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + JsonTuple3Array|csv:Error st1jt3 = csv:parseListAsListType([st1, st1], {}, JsonTuple3Array); + test:assertEquals(st1jt3, [ + [s1, s2], + [s1, s2] + ]); + + JsonTuple3Array|csv:Error st2jt3 = csv:parseListAsListType([st2, st2], {}, JsonTuple3Array); + test:assertEquals(st2jt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + JsonTuple3Array|csv:Error st3jt3 = csv:parseListAsListType([st3, st3], {}, JsonTuple3Array); + test:assertEquals(st3jt3, [ + [s1, s2], + [s1, s2] + ]); + + JsonTuple3Array|csv:Error st4jt3 = csv:parseListAsListType([st4, st4], {}, JsonTuple3Array); + test:assertEquals(st4jt3, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + DecimalTuple4Array|csv:Error st1dta = csv:parseListAsListType([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); + test:assertTrue(st2bta is csv:Error); + test:assertEquals((st2bta).message(), common:generateErrorMessageForInvalidValueForArrayType("string", "0", "int")); + + NilTuple3Array|csv:Error st3nta = csv:parseListAsListType([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); + 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"]], {}); + test:assertEquals(ct1bt4, [ + ["a", true, 1], + ["a", true, 1] + ]); + + [(), float, decimal, boolean, int, string][]|csv:Error ct1bt6 = csv:parseListAsListType( + [["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( + [["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( + [["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( + [["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( + [["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( + [["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( + [["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( + [["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( + [["1", "a"], ["1", "a"]]); + test:assertEquals(ct1bt13, [ + ["1", "a"], + ["1", "a"] + ]); + + [boolean...][]|csv:Error ct1bt14 = csv:parseListAsListType( + [["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( + [["1", "()"], ["1", "2"]]); + test:assertEquals(ct1bt15, [ + [1, ()], + [1, 2] + ]); + + int[][]|csv:Error ct1bt16 = csv:parseListAsListType( + [["1", "2"], ["1", "()"]]); + test:assertTrue(ct1bt16 is csv:Error); + test:assertEquals((ct1bt16).message(), common:generateErrorMessageForInvalidValueForArrayType("()", "1", "int")); + + int[][]|csv:Error ct1bt17 = csv:parseListAsListType( + [["a", "b"], ["a", "b"]]); + test:assertTrue(ct1bt17 is csv:Error); + test:assertEquals((ct1bt17).message(), common:generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); +} + +@test:Config +function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { + StringArrayArray|csv:Error st1saa = csv:parseListAsListType([st1, st1], {}, StringArrayArray); + test:assertEquals(st1saa, [ + [s1, s2], + [s1, s2] + ]); + + StringArrayArray|csv:Error st2saa = csv:parseListAsListType([st2, st2], {}, StringArrayArray); + test:assertEquals(st2saa, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringArrayArray|csv:Error st3saa = csv:parseListAsListType([st3, st3], {}, StringArrayArray); + test:assertEquals(st3saa, [ + [s1, s2], + [s1, s2] + ]); + + StringArrayArray|csv:Error st4saa = csv:parseListAsListType([st4, st4], {}, StringArrayArray); + test:assertEquals(st4saa, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableStringArrayArray|csv:Error st1nsaa = csv:parseListAsListType([st1, st1], {}, NillableStringArrayArray); + test:assertEquals(st1nsaa, [ + [s1, s2], + [s1, s2] + ]); + + NillableStringArrayArray|csv:Error st2nsaa = csv:parseListAsListType([st2, st2], {}, NillableStringArrayArray); + test:assertEquals(st2nsaa, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableStringArrayArray|csv:Error st3nsaa = csv:parseListAsListType([st3, st3], {}, NillableStringArrayArray); + test:assertEquals(st3nsaa, [ + [s1, s2], + [s1, s2] + ]); + + NillableStringArrayArray|csv:Error st4nsaa = csv:parseListAsListType([st4, st4], {}, NillableStringArrayArray); + test:assertEquals(st4nsaa, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableIntOrUnionStringArrayArray|csv:Error st1nsuiaa = csv:parseListAsListType([st1, st1], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st1nsuiaa, [ + [s1, s2], + [s1, s2] + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndTupleAsExpectedType4() { + NillableIntOrUnionStringArrayArray|csv:Error st2nsuiaa = csv:parseListAsListType([st2, st2], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st2nsuiaa, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + NillableIntOrUnionStringArrayArray|csv:Error st3nsuiaa = csv:parseListAsListType([st3, st3], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st3nsuiaa, [ + [s1, s2], + [s1, s2] + ]); + + NillableIntOrUnionStringArrayArray|csv:Error st4nsuiaa = csv:parseListAsListType([st4, st4], {}, NillableIntOrUnionStringArrayArray); + test:assertEquals(st4nsuiaa, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + StringArray2Array|csv:Error st1saa2 = csv:parseListAsListType([st1, st1], {}, StringArray2Array); + test:assertEquals(st1saa2, [ + [s1, s2], + [s1, s2] + ]); + + StringArray2Array|csv:Error st2saa2 = csv:parseListAsListType([st2, st2], {}, StringArray2Array); + test:assertEquals(st2saa2, [ + [s1, s2], + [s1, s2] + ]); + + StringArray2Array|csv:Error st3saa2 = csv:parseListAsListType([st3, st3], {}, StringArray2Array); + test:assertEquals(st3saa2, [ + [s1, s2], + [s1, s2] + ]); + + StringArray2Array|csv:Error st4saa2 = csv:parseListAsListType([st4, st4], {}, StringArray2Array); + test:assertEquals(st4saa2, [ + [s1, s2], + [s1, s2] + ]); + + JsonArray1Array|csv:Error st1jaa = csv:parseListAsListType([st1, st1], {}, JsonArray1Array); + test:assertEquals(st1jaa, [ + [s1, s2], + [s1, s2] + ]); + + JsonArray1Array|csv:Error st2jaa = csv:parseListAsListType([st2, st2], {}, JsonArray1Array); + test:assertEquals(st2jaa, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + JsonArray1Array|csv:Error st3jaa = csv:parseListAsListType([st3, st3], {}, JsonArray1Array); + test:assertEquals(st3jaa, [ + [s1, s2], + [s1, s2] + ]); + + JsonArray1Array|csv:Error st4jaa = csv:parseListAsListType([st4, st4], {}, JsonArray1Array); + test:assertEquals(st4jaa, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataArray1Array|csv:Error st1anyda = csv:parseListAsListType([st1, st1], {}, AnydataArray1Array); + test:assertEquals(st1anyda, [ + [s1, s2], + [s1, s2] + ]); + + AnydataArray1Array|csv:Error st2anyda = csv:parseListAsListType([st2, st2], {}, AnydataArray1Array); + test:assertEquals(st2anyda, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + AnydataArray1Array|csv:Error st3anyda = csv:parseListAsListType([st3, st3], {}, AnydataArray1Array); + test:assertEquals(st3anyda, [ + [s1, s2], + [s1, s2] + ]); + + AnydataArray1Array|csv:Error st4anyda = csv:parseListAsListType([st4, st4], {}, AnydataArray1Array); + test:assertEquals(st4anyda, [ + [s1, s2, s3, s2], + [s1, s2, s3, s2] + ]); + + DecimalArray1Array|csv:Error st1dda = csv:parseListAsListType([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); + test:assertTrue(st3dda is csv:Error); + test:assertEquals((st3dda).message(), common:generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); +} 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 new file mode 100644 index 0000000..751e756 --- /dev/null +++ b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_record_test.bal @@ -0,0 +1,768 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; +import ballerina/test; + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { + StringRecord1Array|csv:Error st1sr1 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord1Array); + test:assertTrue(st1sr1 is csv:Error); + test:assertEquals((st1sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + + StringRecord1Array|csv:Error st2sr1 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord1Array); + test:assertTrue(st2sr1 is csv:Error); + test:assertEquals((st2sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + + StringRecord2Array|csv:Error st1sr2 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord2Array); + 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); + 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); + 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); + 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); + test:assertEquals(st1sr10, [ + {'1: "string", '2: ""}, + {'1: "string", '2: ""} + ]); + + StringRecord10Array|csv:Error st2sr10 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord10Array); + test:assertEquals(st2sr10, [ + {'1: "string", '2: "", '3: "a", '4: ""}, + {'1: "string", '2: "", '3: "a", '4: ""} + ]); + + StringRecord19Array|csv:Error st1sr19 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord19Array); + test:assertEquals(st1sr19, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord19Array|csv:Error st2sr19 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord19Array); + 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); + test:assertEquals(st1sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { + StringRecord20Array|csv:Error st2sr20 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord20Array); + test:assertEquals(st2sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord21Array|csv:Error st1sr21 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord21Array); + test:assertEquals(st1sr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord21Array|csv:Error st2sr21 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord21Array); + 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); + test:assertEquals(st1sr22, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord22Array|csv:Error st2sr22 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord22Array); + 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); + test:assertEquals(st1sr23, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord23Array|csv:Error st2sr23 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord23Array); + 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); + test:assertEquals(st1cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord15Array|csv:Error st2cr15 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord15Array); + test:assertEquals(st2cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord16Array|csv:Error st1cr16 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord16Array); + test:assertTrue(st1cr16 is csv:Error); + test:assertEquals((st1cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); + + CustomRecord16Array|csv:Error st2cr16 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord16Array); + 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); + test:assertEquals(st1cr17, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { + CustomRecord17Array|csv:Error st2cr17 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord17Array); + 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); + test:assertTrue(st1cr18 is csv:Error); + test:assertEquals((st1cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); + + CustomRecord18Array|csv:Error st2cr18 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord18Array); + 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); + test:assertEquals(st1cr19, [ + {'1: s1, '2: s2, '3: "", '4: ""}, + {'1: s1, '2: s2, '3: "", '4: ""} + ]); + + CustomRecord19Array|csv:Error st2cr19 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord19Array); + 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); + test:assertEquals(st1cr20, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord20Array|csv:Error st2cr20 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord20Array); + 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); + test:assertEquals(st1cr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord21Array|csv:Error st2cr21 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord21Array); + 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); + test:assertEquals(st1cr22, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType4() { + CustomRecord22Array|csv:Error st2cr22 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord22Array); + 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); + test:assertEquals(st1cr23, [ + {"1": s1, "2": s2, a: ""}, + {"1": s1, "2": s2, a: ""} + ]); + + CustomRecord23Array|csv:Error st2cr23 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord23Array); + 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); + test:assertEquals(st1cr24, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord24Array|csv:Error st2cr24 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord24Array); + 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); + test:assertTrue(st1cr25 is csv:Error); + test:assertEquals((st1cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + + CustomRecord25Array|csv:Error st2cr25 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord25Array); + test:assertTrue(st2cr25 is csv:Error); + test:assertEquals((st2cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + + CustomRecord25Array|csv:Error st3cr25 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord25Array); + test:assertTrue(st3cr25 is csv:Error); + test:assertEquals((st3cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + + CustomRecord25Array|csv:Error st4cr25 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord25Array); + test:assertTrue(st4cr25 is csv:Error); + test:assertEquals((st4cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + + CustomRecord26Array|csv:Error st1cr26 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord26Array); + test:assertEquals(st1cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|csv:Error st2cr26 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord26Array); + test:assertEquals(st2cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|csv:Error st3cr26 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord26Array); + test:assertEquals(st3cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|csv:Error st4cr26 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord26Array); + test:assertEquals(st4cr26 , [ + {'1: s1}, + {'1: s1} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType5() { + StringRecord1Array|csv:Error st3sr1 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord1Array); + test:assertTrue(st3sr1 is csv:Error); + test:assertEquals((st3sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + + StringRecord1Array|csv:Error st4sr1 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord1Array); + test:assertTrue(st4sr1 is csv:Error); + test:assertEquals((st4sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + + StringRecord2Array|csv:Error st3sr2 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord2Array); + 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); + 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); + test:assertTrue(st3sr9 is csv:Error); + test:assertEquals((st3sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); + + StringRecord9Array|csv:Error st4sr9 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord9Array); + test:assertTrue(st4sr9 is csv:Error); + test:assertEquals((st4sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); + + StringRecord10Array|csv:Error st3sr10 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord10Array); + test:assertEquals(st3sr10, [ + {'1: "string", '2: ""}, + {'1: "string", '2: ""} + ]); + + StringRecord10Array|csv:Error st4sr10 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord10Array); + test:assertEquals(st4sr10, [ + {'1: "string", '2: "", '3: "a", '4: ""}, + {'1: "string", '2: "", '3: "a", '4: ""} + ]); + + StringRecord19Array|csv:Error st3sr19 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord19Array); + test:assertEquals(st3sr19, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord19Array|csv:Error st4sr19 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord19Array); + 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); + test:assertEquals(st3sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord20Array|csv:Error st4sr20 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord20Array); + test:assertEquals(st4sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord21Array|csv:Error st3sr21 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord21Array); + test:assertEquals(st3sr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord21Array|csv:Error st4sr21 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord21Array); + 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); + test:assertEquals(st3sr22, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord22Array|csv:Error st4sr22 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord22Array); + 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); + test:assertEquals(st3sr23, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord23Array|csv:Error st4sr23 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord23Array); + 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); + test:assertEquals(st3cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType6() { + CustomRecord15Array|csv:Error st4cr15 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord15Array); + test:assertEquals(st4cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord16Array|csv:Error st3cr16 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord16Array); + test:assertTrue(st3cr16 is csv:Error); + test:assertEquals((st3cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); + + CustomRecord16Array|csv:Error st4cr16 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord16Array); + 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); + test:assertEquals(st3cr17, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord17Array|csv:Error st4cr17 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord17Array); + 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); + test:assertTrue(st3cr18 is csv:Error); + test:assertEquals((st3cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); + + CustomRecord18Array|csv:Error st4cr18 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord18Array); + 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); + test:assertEquals(st3cr19, [ + {'1: s1, '2: s2, '3: "", '4: ""}, + {'1: s1, '2: s2, '3: "", '4: ""} + ]); + + CustomRecord19Array|csv:Error st4cr19 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord19Array); + 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); + test:assertEquals(st3cr20, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord20Array|csv:Error st4cr20 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord20Array); + 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); + test:assertEquals(st3cr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord21Array|csv:Error st4cr21 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord21Array); + 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); + test:assertEquals(st3cr22, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord22Array|csv:Error st4cr22 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord22Array); + 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); + test:assertEquals(st3cr23, [ + {"1": s1, "2": s2, a: ""}, + {"1": s1, "2": s2, a: ""} + ]); + + CustomRecord23Array|csv:Error st4cr23 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord23Array); + 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); + test:assertEquals(st3cr24, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord24Array|csv:Error st4cr24 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord24Array); + test:assertEquals(st4cr24, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); +} + +@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"], {}); + 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( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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 testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { + record{|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseListAsRecordType( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["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( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + ["f", "e", "d", "c", "b", "a"]); + test:assertEquals(ct1br12, [ + {a: ()}, + {a: ()} + ]); + + record{|string?...;|}[]|csv:Error ct1br13 = csv:parseListAsRecordType( + [["a", "1"], ["a", "1"]], + ["f", "e"]); + test:assertEquals(ct1br13, [ + {e: "1", f: "a"}, + {e: "1", f: "a"} + ]); + + record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseListAsRecordType( + [["2.23", "null"], ["7", "()"]], + ["b", "a"]); + test:assertEquals(ct1br14, [ + {}, + {} + ]); + + map[]|csv:Error ct1br15 = csv:parseListAsRecordType( + [["2", "()"], ["2", "1"], ["()", "2"]], + ["f", "e"]); + test:assertEquals(ct1br15, [ + {e: (), f: 2}, + {e: 1, f: 2}, + {e: 2, f: ()} + ]); + + record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseListAsRecordType( + [["2.23", "null"], ["7", "()"]], + ["b", "a"]); + test:assertEquals(ct1br16, [ + {}, + {} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndMapAsExpectedType() { + StringMapArray|csv:Error st1sma = csv:parseListAsRecordType([st1, st1], (), {}, StringMapArray); + test:assertEquals(st1sma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + StringMapArray|csv:Error st2sma = csv:parseListAsRecordType([st2, st2], (), {}, StringMapArray); + 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); + test:assertEquals(st3sma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + StringMapArray|csv:Error st4sma = csv:parseListAsRecordType([st4, st4], (), {}, StringMapArray); + 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); + test:assertEquals(st1niusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + NillableIntUnionStringMapArray|csv:Error st2niusma = csv:parseListAsRecordType([st2, st2], (), {}, NillableIntUnionStringMapArray); + 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); + test:assertEquals(st3niusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + NillableIntUnionStringMapArray|csv:Error st4niusma = csv:parseListAsRecordType([st4, st4], (), {}, NillableIntUnionStringMapArray); + 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); + test:assertEquals(st1iusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + IntUnionStringMapArray|csv:Error st2iusma = csv:parseListAsRecordType([st2, st2], (), {}, IntUnionStringMapArray); + 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); + test:assertEquals(st3iusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + IntUnionStringMapArray|csv:Error st4iusma = csv:parseListAsRecordType([st4, st4], (), {}, IntUnionStringMapArray); + 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); + test:assertEquals(st1jma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndMapAsExpectedType2() { + JsonMapArray|csv:Error st2jma = csv:parseListAsRecordType([st2, st2], (), {}, JsonMapArray); + 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); + test:assertEquals(st3jma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + JsonMapArray|csv:Error st4jma = csv:parseListAsRecordType([st4, st4], (), {}, JsonMapArray); + 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); + test:assertEquals(st1anydma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + AnydataMapArray|csv:Error st2anydma = csv:parseListAsRecordType([st2, st2], (), {}, AnydataMapArray); + 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); + test:assertEquals(st3anydma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + AnydataMapArray|csv:Error st4anydma = csv:parseListAsRecordType([st4, st4], (), {}, AnydataMapArray); + 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); + test:assertEquals(st1cma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + CustomMapArray|csv:Error st2cma = csv:parseListAsRecordType([st2, st2], (), {}, CustomMapArray); + 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); + test:assertEquals(st3cma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + CustomMapArray|csv:Error st4cma = csv:parseListAsRecordType([st4, st4], (), {}, CustomMapArray); + 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); + test:assertEquals(st1nma, ([ + {}, + {} + ])); + + IntegerMapArray|csv:Error st2ima = csv:parseListAsRecordType([st2, st2], (), {}, IntegerMapArray); + test:assertEquals(st2ima, ([ + {}, + {} + ])); + + DecimalMapArray|csv:Error st3dma = csv:parseListAsRecordType([st3, st3], (), {}, DecimalMapArray); + test:assertEquals(st3dma, ([ + {}, + {} + ])); + + BooleanMapArray|csv:Error st4bma = csv:parseListAsRecordType([st4, st4], (), {}, BooleanMapArray); + test:assertEquals(st4bma, ([ + {}, + {} + ])); +} diff --git a/ballerina/tests/test_data_values.bal b/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal similarity index 100% rename from ballerina/tests/test_data_values.bal rename to ballerina-tests/parse-list-types-tests/tests/test_data_values.bal diff --git a/ballerina/tests/types.bal b/ballerina-tests/parse-list-types-tests/tests/types.bal similarity index 97% rename from ballerina/tests/types.bal rename to ballerina-tests/parse-list-types-tests/tests/types.bal index ebfe68b..62f8f98 100644 --- a/ballerina/tests/types.bal +++ b/ballerina-tests/parse-list-types-tests/tests/types.bal @@ -2533,101 +2533,3 @@ type CustomMapArray CustomMap[]; type ClosedCustomMapArray CustomMap[3]; -type RecordWithCustomAnnotation record { - @Name { - value: "c" - } - int a; - int b; -}; - -type RecordWithCustomAnnotation2 record { - @Name { - value: "c" - } - int a?; - @Name { - value: "d" - } - int? b; -}; - -type RecordWithCustomAnnotation3 record {| - @Name { - value: "c" - } - int a?; - @Name { - value: "d" - } - int? b; -|}; - -type RecordWithCustomAnnotation4 record {| - @Name { - value: "c" - } - int a; - @Name { - value: "d" - } - int b; - boolean...; -|}; - -type RecordWithCustomAnnotation5 record { - @Name { - value: "c" - } - int a; - @Name { - value: "d" - } - int b; - int c?; -}; - -type RecordWithCustomAnnotation6 record { - @Name { - value: "c" - } - int a; - @Name { - value: "d" - } - int b; - @Name { - value: "e" - } - int c; -}; - -type RecordWithCustomAnnotation7 record { - @Name { - value: "c" - } - int a; - @Name { - value: "d" - } - int b; - @Name { - value: "a" - } - int c; -}; - -type RecordWithCustomAnnotation8 record { - @Name { - value: "c" - } - int a; - @Name { - value: "c" - } - int b; - @Name { - value: "a" - } - int c; -}; diff --git a/ballerina-tests/parse-record-types-tests/.gitignore b/ballerina-tests/parse-record-types-tests/.gitignore new file mode 100644 index 0000000..d5fc29a --- /dev/null +++ b/ballerina-tests/parse-record-types-tests/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/ballerina-tests/parse-record-types-tests/Ballerina.toml b/ballerina-tests/parse-record-types-tests/Ballerina.toml new file mode 100644 index 0000000..508c204 --- /dev/null +++ b/ballerina-tests/parse-record-types-tests/Ballerina.toml @@ -0,0 +1,13 @@ +[package] +org = "ballerina" +name = "parse_record_types_tests" +version = "0.1.0" + +[[dependency]] +org = "ballerina" +name = "csv_commons" +repository = "local" +version = "0.1.0" + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina-tests/parse-record-types-tests/Dependencies.toml b/ballerina-tests/parse-record-types-tests/Dependencies.toml new file mode 100644 index 0000000..54bfd11 --- /dev/null +++ b/ballerina-tests/parse-record-types-tests/Dependencies.toml @@ -0,0 +1,98 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0" + +[[package]] +org = "ballerina" +name = "csv_commons" +version = "0.1.0" +scope = "testOnly" +modules = [ + {org = "ballerina", packageName = "csv_commons", moduleName = "csv_commons"} +] + +[[package]] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "parse_record_types_tests" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "csv_commons"}, + {org = "ballerina", name = "data.csv"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerina", packageName = "parse_record_types_tests", moduleName = "parse_record_types_tests"} +] + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + 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 new file mode 100644 index 0000000..98f980c --- /dev/null +++ b/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal @@ -0,0 +1,540 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; +import ballerina/test; + +@test:Config +function testFromCsvWithTypeForMapAndArrayAsExpectedType() { + BooleanArrayArray|csv:Error bm1ba = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanArrayArray); + test:assertEquals(bm1ba, [ + [true, false], + [true, false] + ]); + + bm1ba = csv:parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}, BooleanArrayArray); + test:assertEquals(bm1ba, [ + [false, true], + [false, true] + ]); + + BooleanArrayArray|csv:Error bm2ba = csv:parseRecordAsListType([bm2, bm2], ["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); + 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); + 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); + 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); + test:assertEquals(bm1nba, [ + [true, false], + [true, false] + ]); + + NillableBooleanArrayArray|csv:Error bm2nba = csv:parseRecordAsListType([bm2, bm2], ["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); + 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); + test:assertEquals(bm4nba, [ + [(), ()], + [(), ()] + ]); + + NillableBooleanArrayArray|csv:Error bm5nba = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanArrayArray); + test:assertEquals(bm5nba, [ + [true, false, (), true], + [true, false, (), true] + ]); + + bm5nba = csv:parseRecordAsListType([bm5, bm5], ["b1", "b3", "b2", "b4"], {}, NillableBooleanArrayArray); + test:assertEquals(bm5nba, [ + [true, (), false, true], + [true, (), false, true] + ]); + + bm5nba = csv:parseRecordAsListType([bm5, bm5], ["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); + test:assertEquals(bm1niouba, [ + [true, false], + [true, false] + ]); + + NillableIntOrUnionBooleanArrayArray|csv:Error bm2niouba = csv:parseRecordAsListType([bm2, bm2], ["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); + test:assertEquals(bm3niouba, [ + [true, false, null, false, 1], + [true, false, null, false, 1] + ]); + + NillableIntOrUnionBooleanArrayArray|csv:Error bm4niouba = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); + test:assertEquals(bm4niouba, [ + [(), ()], + [(), ()] + ]); + + NillableIntOrUnionBooleanArrayArray|csv:Error bm5niouba = csv:parseRecordAsListType([bm5, bm5], ["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); + test:assertEquals(bm1ja, [ + [true, false], + [true, false] + ]); +} + +@test:Config +function testFromCsvWithTypeForMapAndArrayAsExpectedType2() { + JsonArray1Array|csv:Error bm2ja = csv:parseRecordAsListType([bm2, bm2], ["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); + test:assertEquals(bm3ja, [ + [true, false, null, false, 1], + [true, false, null, false, 1] + ]); + + JsonArray1Array|csv:Error bm4ja = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonArray1Array); + test:assertEquals(bm4ja, [ + [(), ()], + [(), ()] + ]); + + JsonArray1Array|csv:Error bm5ja = csv:parseRecordAsListType([bm5, bm5], ["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); + test:assertEquals(bm1anyda, [ + [true, false], + [true, false] + ]); + + AnydataArray1Array|csv:Error bm2anyda = csv:parseRecordAsListType([bm2, bm2], ["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); + test:assertEquals(bm3anyda, [ + [true, false, null, false, 1], + [true, false, null, false, 1] + ]); + + AnydataArray1Array|csv:Error bm4anyda = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataArray1Array); + test:assertEquals(bm4anyda, [ + [(), ()], + [(), ()] + ]); + + AnydataArray1Array|csv:Error bm5anyda = csv:parseRecordAsListType([bm5, bm5], ["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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + test:assertEquals(bm1b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|csv:Error bm2b2t = csv:parseRecordAsListType([bm2, bm2], ["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); + test:assertEquals(bm3b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|csv:Error bm4b2t = csv:parseRecordAsListType([bm4, bm4], ["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); + test:assertEquals(bm5b2t, [ + [true, false], + [true, false] + ]); + + BooleanTuple3Array|csv:Error bm1b3t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple3Array); + test:assertEquals(bm1b3t, [ + [true, false], + [true, false] + ]); + + BooleanTuple3Array|csv:Error bm2b3t = csv:parseRecordAsListType([bm2, bm2], ["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); + 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); + 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); + 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); + test:assertEquals(bm1b4t, [ + [true, false], + [true, false] + ]); + + BooleanTuple4Array|csv:Error bm2b4t = csv:parseRecordAsListType([bm2, bm2], ["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); + 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); + 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); + 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); + test:assertEquals(bm1nbt, [ + [true, false, (), (), ()], + [true, false, (), (), ()] + ]); + + NillableBooleanTuple5Array|csv:Error bm2nbt = csv:parseRecordAsListType([bm2, bm2], ["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); + 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); + test:assertEquals(bm4nbt, [ + [(), (), (), (), ()], + [(), (), (), (), ()] + ]); + + NillableBooleanTuple5Array|csv:Error bm5nbt = csv:parseRecordAsListType([bm5, bm5], ["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); + test:assertEquals(bm1nb6t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|csv:Error bm2nb6t = csv:parseRecordAsListType([bm2, bm2], ["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); + test:assertEquals(bm3nb6t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|csv:Error bm4nb6t = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple6Array); + test:assertEquals(bm4nb6t, [ + [(), ()], + [(), ()] + ]); + + NillableBooleanTuple6Array|csv:Error bm5nb6t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple6Array); + test:assertEquals(bm5nb6t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple7Array|csv:Error bm1nb7t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple7Array); + test:assertEquals(bm1nb7t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple7Array|csv:Error bm2nb7t = csv:parseRecordAsListType([bm2, bm2], ["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); + 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); + test:assertEquals(bm4nb7t, [ + [(), ()], + [(), ()] + ]); + + NillableBooleanTuple7Array|csv:Error bm5nb7t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple7Array); + test:assertEquals(bm5nb7t, [ + [true, false, (), true], + [true, false, (), true] + ]); +} + +@test:Config +function testFromCsvWithTypeForMapAndTupleAsExpectedType3() { + NillableBooleanTuple8Array|csv:Error bm1nb8t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple8Array); + test:assertEquals(bm1nb8t, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple8Array|csv:Error bm2nb8t = csv:parseRecordAsListType([bm2, bm2], ["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); + 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); + test:assertEquals(bm4nb8t, [ + [(), ()], + [(), ()] + ]); + + NillableBooleanTuple8Array|csv:Error bm5nb8t = csv:parseRecordAsListType([bm5, bm5], ["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); + test:assertEquals(bm1nb9t, [ + [true, false], + [true, false] + ]); + + NillableIntBooleanTuple9Array|csv:Error bm2nb9t = csv:parseRecordAsListType([bm2, bm2], ["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); + test:assertEquals(bm3nb9t, [ + [true, false, (), false, 1], + [true, false, (), false, 1] + ]); + + NillableIntBooleanTuple9Array|csv:Error bm4nb9t = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntBooleanTuple9Array); + test:assertEquals(bm4nb9t, [ + [(), ()], + [(), ()] + ]); + + NillableIntBooleanTuple9Array|csv:Error bm5nb9t = csv:parseRecordAsListType([bm5, bm5], ["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); + 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); + 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); + 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); + test:assertEquals(bm4n3t, [ + [(), ()], + [(), ()] + ]); + + NilTuple3Array|csv:Error bm5n3t = csv:parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NilTuple3Array); + test:assertTrue(bm5n3t is csv:Error); + test:assertEquals((bm5n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); +} + +@test:Config +function testFromCsvWithTypeForMapAndArrayAsExpectedType3() { + + AnydataTuple3Array|csv:Error bm1anyd3t = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataTuple3Array); + test:assertEquals(bm1anyd3t, [ + [true, false], + [true, false] + ]); + + AnydataTuple3Array|csv:Error bm2anyd3t = csv:parseRecordAsListType([bm2, bm2], ["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); + test:assertEquals(bm3anyd3t, [ + [true, false, (), false, 1], + [true, false, (), false, 1] + ]); + + AnydataTuple3Array|csv:Error bm4anyd3t = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataTuple3Array); + test:assertEquals(bm4anyd3t, [ + [(), ()], + [(), ()] + ]); + + AnydataTuple3Array|csv:Error bm5anyd3t = csv:parseRecordAsListType([bm5, bm5], ["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); + test:assertEquals(bm1j3t, [ + [true, false], + [true, false] + ]); + + JsonTuple3Array|csv:Error bm2j3t = csv:parseRecordAsListType([bm2, bm2], ["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); + test:assertEquals(bm3j3t, [ + [true, false, (), false, 1], + [true, false, (), false, 1] + ]); + + JsonTuple3Array|csv:Error bm4j3t = csv:parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonTuple3Array); + test:assertEquals(bm4j3t, [ + [(), ()], + [(), ()] + ]); + + JsonTuple3Array|csv:Error bm5j3t = csv:parseRecordAsListType([bm5, bm5], ["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); + 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); + 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); + 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); + 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); + test:assertTrue(bm5s3t is csv:Error); + test:assertEquals((bm5s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); +} 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 new file mode 100644 index 0000000..a1373ae --- /dev/null +++ b/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_record_test.bal @@ -0,0 +1,733 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; +import ballerina/test; + +@test:Config +function testFromCsvWithTypeForMapAndRecordAsExpectedType() { + BooleanRecord1Array|csv:Error bm1br1 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm2br1 is csv:Error); + test:assertEquals((bm2br1).message(), common:generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord1Array|csv:Error bm3br1 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm4br1 is csv:Error); + test:assertEquals((bm4br1).message(), common:generateErrorMessageForMissingRequiredField("b2")); + + BooleanRecord1Array|csv:Error bm5br1 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm1br2 is csv:Error); + test:assertEquals((bm1br2).message(), common:generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord2Array|csv:Error bm2br2 = csv:parseRecordAsRecordType([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); + 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); + test:assertTrue(bm4br2 is csv:Error); + test:assertEquals((bm4br2).message(), common:generateErrorMessageForMissingRequiredField("b2")); + + BooleanRecord2Array|csv:Error bm5br2 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm1br3 is csv:Error); + test:assertEquals((bm1br3).message(), common:generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord3Array|csv:Error bm2br3 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord3Array); + test:assertEquals(bm2br3, [ + {b1: true, b3: ()}, + {b1: true, b3: ()} + ]); + + BooleanRecord3Array|csv:Error bm3br3 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord3Array); + test:assertEquals(bm3br3, [ + {b1: true, b3: ()}, + {b1: true, b3: ()} + ]); + + BooleanRecord3Array|csv:Error bm4br3 = csv:parseRecordAsRecordType([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); + test:assertEquals(bm5br3, [{b1: true, b3: ()}, {b1: true, b3: ()}]); + + BooleanRecord4Array|csv:Error bm1br4 = csv:parseRecordAsRecordType([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); + 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); + 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); + test:assertTrue(bm4br4 is csv:Error); + test:assertEquals((bm4br4).message(), common:generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord4Array|csv:Error bm5br4 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm1br5 is csv:Error); + test:assertEquals((bm1br5).message(), common:generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord5Array|csv:Error bm2br5 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord5Array); + test:assertEquals(bm2br5, [ + {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()} + ]); +} + +@test:Config +function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { + BooleanRecord5Array|csv:Error bm3br5 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm4br5 is csv:Error); + test:assertEquals((bm4br5).message(), common:generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord5Array|csv:Error bm5br5 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm1br6 is csv:Error); + test:assertEquals((bm1br6).message(), common:generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord6Array|csv:Error bm2br6 = csv:parseRecordAsRecordType([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); + test:assertEquals(bm3br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|csv:Error bm4br6 = csv:parseRecordAsRecordType([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); + test:assertEquals(bm5br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord7Array|csv:Error bm1br7 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm2br7 is csv:Error); + test:assertEquals((bm2br7).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord7Array|csv:Error bm3br7 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm4br7 is csv:Error); + test:assertEquals((bm4br7).message(), common:generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord7Array|csv:Error bm5br7 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm1br8 is csv:Error); + test:assertEquals((bm1br8).message(), common:generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord8Array|csv:Error bm2br8 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm3br8 is csv:Error); + test:assertEquals((bm3br8).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord8Array|csv:Error bm4br8 = csv:parseRecordAsRecordType([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); + 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); + test:assertTrue(bm1br9 is csv:Error); + test:assertEquals((bm1br9).message(), common:generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord9Array|csv:Error bm2br9 = csv:parseRecordAsRecordType([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); + 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); + test:assertTrue(bm4br9 is csv:Error); + test:assertEquals((bm4br9).message(), common:generateErrorMessageForMissingRequiredField("b3")); + + BooleanRecord9Array|csv:Error bm5br9 = csv:parseRecordAsRecordType([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); + test:assertEquals(bm1br10, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanRecord10Array|csv:Error bm2br10 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord10Array); + test:assertEquals(bm2br10, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanRecord10Array|csv:Error bm3br10 = csv:parseRecordAsRecordType([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); + test:assertEquals(bm4br10, [ + {}, + {} + ]); + + BooleanRecord10Array|csv:Error bm5br10 = csv:parseRecordAsRecordType([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); + 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); + 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); + 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); + test:assertTrue(bm4br11 is csv:Error); + test:assertEquals((bm4br11).message(), common:generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord11Array|csv:Error bm5br11 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm1br12 is csv:Error); + test:assertEquals((bm1br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord12Array|csv:Error bm2br12 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm3br12 is csv:Error); + test:assertEquals((bm3br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord12Array|csv:Error bm4br12 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm5br12 is csv:Error); + test:assertEquals((bm5br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord13Array|csv:Error bm1br13 = csv:parseRecordAsRecordType([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); + 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); + 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); + test:assertEquals(bm4br13, [ + {defaultableField: "", nillableField :null}, + {defaultableField: "", nillableField :null} + ]); +} + +@test:Config +function testFromCsvWithTypeForMapAndRecordAsExpectedType4() { + BooleanRecord13Array|csv:Error bm5br13 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm1br14 is csv:Error); + test:assertEquals((bm1br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord14Array|csv:Error bm2br14 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm3br14 is csv:Error); + test:assertEquals((bm3br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord14Array|csv:Error bm4br14 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm5br14 is csv:Error); + test:assertEquals((bm5br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord15Array|csv:Error bm1br15 = csv:parseRecordAsRecordType([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); + test:assertTrue(bm3br15 is csv:Error); + test:assertEquals((bm3br15).message(), common:generateErrorMessageForInvalidFieldType("true", "b1")); + + BooleanRecord15Array|csv:Error bm4br15 = csv:parseRecordAsRecordType([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); + test:assertEquals(bm1br16, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanRecord16Array|csv:Error bm2br16 = csv:parseRecordAsRecordType([bm2, bm2], {}, 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); + 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); + test:assertEquals(bm4br16, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + BooleanRecord16Array|csv:Error bm5br16 = csv:parseRecordAsRecordType([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); + test:assertEquals(bm1br17, [ + {}, + {} + ]); + + BooleanRecord17Array|csv:Error bm2br17 = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord17Array); + test:assertEquals(bm2br17, [ + {}, + {} + ]); + + BooleanRecord17Array|csv:Error bm3br17 = csv:parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord17Array); + test:assertEquals(bm3br17, [ + {i1: 1}, + {i1: 1} + ]); + + BooleanRecord17Array|csv:Error bm4br17 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord17Array); + test:assertEquals(bm4br17, [ + {}, + {} + ]); + + BooleanRecord17Array|csv:Error bm5br17 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord17Array); + test:assertEquals(bm5br17, [ + {}, + {} + ]); + + BooleanRecord18Array|csv:Error bm1br18 = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord18Array); + test:assertEquals(bm1br18, [ + {b2: false}, + {b2: false} + ]); + + BooleanRecord18Array|csv:Error bm2br18 = csv:parseRecordAsRecordType([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); + test:assertEquals(bm3br18, [ + {b2: false, b3: (), i1: 1}, + {b2: false, b3: (), i1: 1} + ]); + + BooleanRecord18Array|csv:Error bm4br18 = csv:parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord18Array); + test:assertTrue(bm4br18 is csv:Error); + test:assertEquals((bm4br18).message(), common:generateErrorMessageForMissingRequiredField("b2")); + + BooleanRecord18Array|csv:Error bm5br18 = csv:parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord18Array); + test:assertEquals(bm5br18, [ + {b2: false, b3: ()}, + {b2: false, b3: ()} + ]); +} + +@test:Config +function testFromCsvWithTypeForMapAndMapAsExpectedType() { + BooleanMapArray|csv:Error bm1bma = csv:parseRecordAsRecordType([bm1, bm1], {}, BooleanMapArray); + test:assertEquals(bm1bma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanMapArray|csv:Error bm2bma = csv:parseRecordAsRecordType([bm2, bm2], {}, BooleanMapArray); + test:assertEquals(bm2bma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + BooleanMapArray|csv:Error bm3bma = csv:parseRecordAsRecordType([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); + test:assertEquals(bm4bma, [ + {}, + {} + ]); + + BooleanMapArray|csv:Error bm5bma = csv:parseRecordAsRecordType([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); + test:assertEquals(bm1nbma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + NillableBooleanMapArray|csv:Error bm2nbma = csv:parseRecordAsRecordType([bm2, bm2], {}, 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); + 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); + test:assertEquals(bm4nbma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + NillableBooleanMapArray|csv:Error bm5nbma = csv:parseRecordAsRecordType([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); + test:assertEquals(bm1niubma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + NillableIntUnionBooleanMapArray|csv:Error bm2niubma = csv:parseRecordAsRecordType([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); + 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); + test:assertEquals(bm4niubma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + NillableIntUnionBooleanMapArray|csv:Error bm5niubma = csv:parseRecordAsRecordType([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); + test:assertEquals(bm1iubma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + IntUnionBooleanMapArray|csv:Error bm2iubma = csv:parseRecordAsRecordType([bm2, bm2], {}, IntUnionBooleanMapArray); + test:assertEquals(bm2iubma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + IntUnionBooleanMapArray|csv:Error bm3iubma = csv:parseRecordAsRecordType([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); + test:assertEquals(bm4iubma, [ + {}, + {} + ]); + + IntUnionBooleanMapArray|csv:Error bm5iubma = csv:parseRecordAsRecordType([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); + test:assertEquals(bm1nma, [ + {}, + {} + ]); + + NilMapArray|csv:Error bm2nma = csv:parseRecordAsRecordType([bm2, bm2], {}, NilMapArray); + test:assertEquals(bm2nma, [ + {n1: (), n3: (), b3: ()}, + {n1: (), n3: (), b3: ()} + ]); +} + +@test:Config +function testFromCsvWithTypeForMapAndMapAsExpectedType2() { + NilMapArray|csv:Error bm3nma = csv:parseRecordAsRecordType([bm3, bm3], {}, NilMapArray); + test:assertEquals(bm3nma, [ + {b3: ()}, + {b3: ()} + ]); + + NilMapArray|csv:Error bm4nma = csv:parseRecordAsRecordType([bm4, bm4], {}, NilMapArray); + test:assertEquals(bm4nma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + NilMapArray|csv:Error bm5nma = csv:parseRecordAsRecordType([bm5, bm5], {}, NilMapArray); + test:assertEquals(bm5nma, [ + {b3: ()}, + {b3: ()} + ]); + + JsonMapArray|csv:Error bm1jma = csv:parseRecordAsRecordType([bm1, bm1], {}, JsonMapArray); + test:assertEquals(bm1jma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + JsonMapArray|csv:Error bm2jma = csv:parseRecordAsRecordType([bm2, bm2], {}, 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); + 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); + test:assertEquals(bm4jma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + JsonMapArray|csv:Error bm5jma = csv:parseRecordAsRecordType([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); + test:assertEquals(bm1anydma, [ + {b1: true, b2: false}, + {b1: true, b2: false} + ]); + + AnydataMapArray|csv:Error bm2anydma = csv:parseRecordAsRecordType([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); + 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); + test:assertEquals(bm4anydma, [ + {n1: (), n3: ()}, + {n1: (), n3: ()} + ]); + + AnydataMapArray|csv:Error bm5anydma = csv:parseRecordAsRecordType([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); + test:assertEquals(bm1cma, [ + {}, + {} + ]); + + CustomMapArray|csv:Error bm2cma = csv:parseRecordAsRecordType([bm2, bm2], {}, CustomMapArray); + test:assertEquals(bm2cma, [ + {}, + {} + ]); + + CustomMapArray|csv:Error bm3cma = csv:parseRecordAsRecordType([bm3, bm3], {}, CustomMapArray); + test:assertEquals(bm3cma, [ + {i1: 1}, + {i1: 1} + ]); + + CustomMapArray|csv:Error bm4cma = csv:parseRecordAsRecordType([bm4, bm4], {}, CustomMapArray); + test:assertEquals(bm4cma, [ + {}, + {} + ]); + + CustomMapArray|csv:Error bm5cma = csv:parseRecordAsRecordType([bm5, bm5], {}, CustomMapArray); + test:assertEquals(bm5cma, [ + {}, + {} + ]); + + StringMapArray|csv:Error bm1sma = csv:parseRecordAsRecordType([bm1, bm1], {}, StringMapArray); + test:assertEquals(bm1sma, [ + {}, + {} + ]); + + StringMapArray|csv:Error bm2sma = csv:parseRecordAsRecordType([bm2, bm2], {}, StringMapArray); + test:assertEquals(bm2sma, [ + {}, + {} + ]); + + StringMapArray|csv:Error bm3sma = csv:parseRecordAsRecordType([bm3, bm3], {}, StringMapArray); + test:assertEquals(bm3sma, [ + {}, + {} + ]); + + StringMapArray|csv:Error bm4sma = csv:parseRecordAsRecordType([bm4, bm4], {}, StringMapArray); + test:assertEquals(bm4sma, [ + {}, + {} + ]); + + StringMapArray|csv:Error bm5sma = csv:parseRecordAsRecordType([bm5, bm5], {}, StringMapArray); + test:assertEquals(bm5sma, [ + {}, + {} + ]); +} diff --git a/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal new file mode 100644 index 0000000..360a493 --- /dev/null +++ b/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal @@ -0,0 +1,256 @@ +boolean b1 = true; +false b2 = false; +boolean? b3 = (); +boolean|int b4 = false; + +() n1 = (); +int? n2 = (); +() n3 = null; + +int i1 = 1; +int i2 = -2; +int i3 = int:MAX_VALUE; +int i4 = int:MIN_VALUE; +int i5 = 0; +2 i6 = 2; +int? i7 = (); +int|string i8 = 100; + +float f1 = 2.234; +float f2 = -3.21f; +float f3 = 0; +float f4 = float:Infinity; +float f5 = -float:Infinity; +float f6 = float:NaN; +2.3f f7 = 2.3; +float? f8 = (); +float|decimal f9 = 1.21; + +decimal d1 = 2.234; +decimal d2 = -3.21d; +decimal d3 = 0; +2.3d d4 = 2.3; +decimal? d5 = (); +decimal|int d6 = 1.21; + +string s1 = "string"; +string s2 = ""; +string:Char s3 = "a"; + +map bm1 = {b1, b2}; +map bm2 = {b1, b2, b3, n1, n3}; +map bm3 = {b1, b2, b3, b4, i1}; +map<()> bm4 = {n1, n3}; +map bm5 = {b1, b2, b3, b4:true}; + +map m5 = {i1, i2, i3, i4, i5, i6}; +map m6 = {f1, f2, f3, f4, f5, f6, f7}; +map m7 = {d1, d2, d3, d4}; +map m8 = {d1, f1, f9, f10: 1.23}; +map m9 = {s1, s2, s3}; +map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; +map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; + +boolean[] arr1 = [b1, b2]; +boolean?[] arr2 = [b1, b2, b3, n1, n3]; +(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; +()[] arr4 = [n1, n3]; +int[] arr5 = [i1, i2, i3, i4, i5, i6]; +float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; +decimal[] arr7 = [d1, d2, d3, d4]; +(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; +string[] arr9 = [s1, s2, s3]; +anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; + +[boolean, boolean] bt1 = [b1, b2]; +[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; +[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; +[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; +[boolean...] bt5 = [b1, b2]; + +[string, string] st1 = [s1, s2]; +[string, string, string, string] st2 = [s1, s2, s3, s2]; +[string...] st3 = [s1, s2]; +[string, string, string...] st4 = [s1, s2, s3, s2]; + +[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; +[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; +[string?...] st7 = [s1, s2]; +[string...] st8 = []; +[string, string, string] st9 = [s1, s2, s3]; + +[(), ()] tup4 = [n1, n3]; +[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; +[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; +[string, string, string] tup9 = [s1, s2, s3]; +[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, + n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, json] tup11 = + [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, + f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 +]; + +[boolean, boolean...] restTup1 = [b1, b2]; +[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; +[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; +[(), ()...] restTup4 = [n1, n3]; +[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; +[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal...] restTup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; +[string...] restTup9 = [s1, s2, s3]; +[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 +]; + +var booleanRecordArray = [ + {b1, b2, b3, b4}, {b1, b2, b3, b4} +]; + +var booleanRecordArray2 = [ + {},{} +]; + +string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 +true,false,true,false +true,false, true,false +true,false,true,false +`; + +string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 +true,false, true,false,true +true,false, true,false,true`; + +string csvStringWithBooleanValues3 = string `b1,b2,b3 +${" "}${"\t"} +true, false,true +${" "} + TRUE, FALSE,() +${" "} + +true, true,FALSE + +`; + +string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 + true,(), (),false + true,(), null,false + +`; + +string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 + +true,false,true,2 + +true,false,true,3 +`; + +string csvStringWithBooleanValues6 = string `b2,b3 +(),() + +`; + +string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 +${b1},${b2},(),${b4} +`; + +string csvStringData1 = string ` + a, b, c, d, e, f + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData2 = string ` + hello, hello, (), 12, true, 12.34 + // comment + + a, b, c, d, e, f + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData3 = string ` + a, b, c, d, e, f + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData4 = string ` + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData5 = string ` + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData6 = string ` + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData7 = string ` + a@ b@ c@ d@ e@ f + 1@ string@ true@ 2.234@ -3.21@ () + 2@ s,tring@ true@ 2.234@ -3.21@ null + 3@ stri,ng@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; +string csvStringData8 = string ` + a@ b@ c@ d@ e@ f + + + + 1@ stri,ng@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ ()@-3.21 + 3@ string@ true@ 2.234@ -3.21@ null + + 4@ s,tring@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; + +string csvStringData9 = string ` + + 1@ string@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ -3.21@ null + + 3@ string@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ ()@-3.21 + + 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina-tests/parse-record-types-tests/tests/types.bal b/ballerina-tests/parse-record-types-tests/tests/types.bal new file mode 100644 index 0000000..a2b4b2b --- /dev/null +++ b/ballerina-tests/parse-record-types-tests/tests/types.bal @@ -0,0 +1,2534 @@ +type BooleanRecord1 record { + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +}; + +type BooleanRecord2 record {| + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +|}; + +type BooleanRecord3 record {| + boolean b1; + boolean? b3; +|}; + +type BooleanRecord4 record { + boolean b1; + boolean? b3; +}; + +type BooleanRecord5 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +}; + +type BooleanRecord6 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +|}; + +type BooleanRecord7 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type BooleanRecord8 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type BooleanRecord9 record {| + boolean b1; + boolean? b3; + boolean?...; +|}; + +type BooleanRecord10 record {| + boolean...; +|}; + +type BooleanRecord11 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + boolean?|string...; +|}; + +type BooleanRecord12 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string|boolean...; +|}; + +type BooleanRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord15 record {| + int b1; + string defaultableField = ""; + string? nillableField = (); + boolean?...; +|}; + +type BooleanRecord16 record {| + boolean?...; +|}; + +type BooleanRecord17 record {| + int...; +|}; + +type BooleanRecord18 record {| + boolean b2; + int?...; +|}; + +type NilRecord1 record { + () n1; + () n2; + () n3; +}; + +type NilRecord2 record {| + () n1; + () n2; + () n3; +|}; + +type NilRecord3 record {| + () n1; + () n4; +|}; + +type NilRecord4 record { + () n1; + () n4; +}; + +type NilRecord5 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +}; + +type NilRecord6 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type NilRecord7 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type NilRecord8 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type NilRecord9 record {| + () n1; + () n2; + ()...; +|}; + +type NilRecord10 record {| + ()...; +|}; + +type NilRecord11 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord12 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type NilRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type IntegerRecord1 record { + int i1; + int i2; + int i3; + int? i4; + int? i5; + int i6; + int i7; + int? i8; +}; + +type IntegerRecord2 record {| + int i1; + int? i2; + int i3; + int i4; + int? i5; + int i6; + int i7; + int? i8; +|}; + +type IntegerRecord3 record {| + int i1; + int i4; + int i6; +|}; + +type IntegerRecord4 record { + int i1; + int i4; + int i6; +}; + +type IntegerRecord5 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +}; + +type IntegerRecord6 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +|}; + +type IntegerRecord7 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type IntegerRecord8 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type IntegerRecord9 record {| + int i1; + int i2; + int...; +|}; + +type IntegerRecord10 record {| + int...; +|}; + +type IntegerRecord11 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord12 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type IntegerRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type FloatRecord1 record { + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +}; + +type FloatRecord2 record {| + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +|}; + +type FloatRecord3 record {| + float f1; + float f4; + float f7; +|}; + +type FloatRecord4 record { + float f1; + float f4; + float f7; +}; + +type FloatRecord5 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +}; + +type FloatRecord6 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type FloatRecord7 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type FloatRecord8 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type FloatRecord9 record {| + float f1; + float f2; + float...; +|}; + +type FloatRecord10 record {| + float...; +|}; + +type FloatRecord11 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord12 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type FloatRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type DecimalRecord1 record { + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +}; + +type DecimalRecord2 record {| + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +|}; + +type DecimalRecord3 record {| + decimal d1; + decimal d4; + decimal d7; +|}; + +type DecimalRecord4 record { + decimal d1; + decimal d4; + decimal d7; +}; + +type DecimalRecord5 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +}; + +type DecimalRecord6 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type DecimalRecord7 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type DecimalRecord8 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type DecimalRecord9 record {| + decimal d1; + decimal d2; + decimal...; +|}; + +type DecimalRecord10 record {| + decimal...; +|}; + +type DecimalRecord11 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord12 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type DecimalRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type StringRecord1 record { + string s1; + string s2; + string s3; +}; + +type StringRecord2 record {| + string s1; + string s2; + string s3; +|}; + +type StringRecord3 record {| + string s1; + string s4; +|}; + +type StringRecord4 record { + string s1; + string s4; +}; + +type StringRecord5 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +}; + +type StringRecord6 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type StringRecord7 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type StringRecord8 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type StringRecord9 record {| + string s1; + string s2; + string...; +|}; + +type StringRecord10 record {| + string...; +|}; + +type StringRecord11 record {| + string s1; + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord12 record {| + string d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord15 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord16 record {| + string?...; +|}; + +type StringRecord17 record {| + int...; +|}; + +type StringRecord18 record {| + string b2; + int?...; +|}; + +type StringRecord19 record { + string s1 = ""; + string s2 = ""; +}; + +type StringRecord20 record {| + string s1 = ""; + string s2 = ""; +|}; + +type StringRecord21 record { +}; + +type StringRecord22 record {| + string s1 = ""; + string s2 = ""; + json...; +|}; + +type StringRecord23 record {| + json...; +|}; + +type JsonRecord1 record { + json j1; + json j2; + json j3; +}; + +type JsonRecord2 record {| + json j1; + json j2; + json j3; +|}; + +type JsonRecord3 record {| + json j1; + json j4; +|}; + +type JsonRecord4 record { + json j1; + json j4; +}; + +type JsonRecord5 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +}; + +type JsonRecord6 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +|}; + +type JsonRecord7 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +}; + +type JsonRecord8 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +|}; + +type JsonRecord9 record {| + json j1; + json j2; + json...; +|}; + +type JsonRecord10 record {| + json...; +|}; + +type JsonRecord11 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord12 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type JsonRecord13 record {| + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord14 record {| + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type AnydataRecord1 record { + anydata anydata1; + anydata anydata2; + anydata anydata3; +}; + +type AnydataRecord2 record {| + anydata anydata1; + anydata anydata2; + anydata anydata3; +|}; + +type AnydataRecord3 record {| + anydata anydata1; + anydata anydata4; +|}; + +type AnydataRecord4 record { + anydata anydata1; + anydata anydata4; +}; + +type AnydataRecord5 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +}; + +type AnydataRecord6 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type AnydataRecord7 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type AnydataRecord8 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type AnydataRecord9 record {| + anydata anydata1; + anydata anydata2; + anydata...; +|}; + +type AnydataRecord10 record {| + anydata...; +|}; + +type AnydataRecord11 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord12 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type AnydataRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type CustomRecord1 record { + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +}; + +type CustomRecord2 record {| + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +|}; + +type CustomRecord3 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +|}; + +type CustomRecord4 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +}; + +type CustomRecord5 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string defaultableField = ""; + string? nillableField = (); +}; + +type CustomRecord6 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type CustomRecord7 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type CustomRecord8 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type CustomRecord9 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string...; +|}; + +type CustomRecord10 record {| + string...; +|}; + +type CustomRecord11 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord12 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomRecord15 record {| + string '1; + string '2; +|}; + +type CustomRecord16 record {| + string '1; + string '2; + string '3; + string '4; +|}; + +type CustomRecord17 record { + string '1; + string '2; +}; + +type CustomRecord18 record { + string '1; + string '2; + string '3; + string '4; +}; + +type CustomRecord19 record { + string '1; + string '2; + string '3 = ""; + string '4 = ""; +}; + +type CustomRecord20 record { + string '1; +}; + +type CustomRecord21 record {| + string '1; + json...; +|}; + +type CustomRecord22 record {| + string '1; + string...; +|}; + +type CustomRecord23 record {| + string '1; + string a = ""; + string...; +|}; + +type CustomRecord24 record {| + string '1; + string '2 = ""; + string...; +|}; + +type CustomRecord25 record {| + int '1; + string...; +|}; + +type CustomRecord26 record {| + string '1; + int...; +|}; + +type CustomRecord27 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata a1; + json j1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord28 record { + string '1; +}; + +type CustomRecord29 record { + int '1; +}; + +type CustomRecord30 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord31 record {| + string '1; + string '6; +|}; + +type CustomRecord32 record {| + int '1; +|}; + +type CustomRecord33 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord34 record { + string '1; + string '6; + string '5 = ""; +}; + +type CustomRecord35 record { + string '1; + string '6; + string '9 = ""; +}; + +type CustomRecord36 record {| + string '1; + string '6; + string '9 = ""; +|}; + +type CustomRecord37 record {| + string '1; + string '6; + string '5 = ""; +|}; + +type CustomRecord38 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + string ...; +|}; + +type CustomRecord39 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + json ...; +|}; + +type CustomRecord40 record {| + string '5; + string '6; + json ...; +|}; + +type CustomRecord41 record {| + json ...; +|}; + +type CustomRecord42 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +|}; + +type CustomRecord43 record { + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +}; + +type CustomRecord44 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; + string ...; +|}; + +type CustomRecord45 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +|}; + +type CustomRecord46 record { + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +}; + +type CustomRecord47 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; + string ...; +|}; + +type CustomRecord48 record { + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +}; + +type CustomRecord49 record {| + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +|}; + +type CustomRecord50 record { + int H1; + float H4; +}; + +type CustomRecord51 record {| + int H1; + float H4; +|}; + +type CustomRecord52 record {| + string H1; + string H4; + string ...; +|}; + +type CustomRecord53 record {| + int H1; + float H4; + decimal ...; +|}; + +type CustomRecord54 record {| + string H1 = ""; + string H4; + string '1; +|}; + +type CustomRecord55 record {| + string H1 = ""; + string H4 = ""; + int '1 = 10; +|}; + +type CustomRecord56 record { + string H1 = ""; + string H4 = ""; + anydata '1 = 10; +}; + +type BooleanTuple1 [boolean, boolean, boolean, boolean]; + +type BooleanTuple2 [boolean, boolean]; + +type BooleanTuple3 [boolean, boolean...]; + +type BooleanTuple4 [boolean...]; + +type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; + +type NillableBooleanTuple6 [boolean?, boolean?]; + +type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; + +type NillableBooleanTuple8 [boolean?...]; + +type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; + +type NilTuple1 [(), (), ()]; + +type NilTuple2 [(), ()]; + +type NilTuple3 [(), ()...]; + +type NilTuple4 [()...]; + +type IntegerTuple1 [int, int, int, int, int, int]; + +type IntegerTuple2 [int, int]; + +type IntegerTuple3 [int, int...]; + +type IntegerTuple4 [int...]; + +type FloatTuple1 [float, float, float, float, float, float, float]; + +type FloatTuple2 [float, float]; + +type FloatTuple3 [float, float...]; + +type FloatTuple4 [float...]; + +type DecimalTuple1 [decimal, decimal, decimal, decimal]; + +type DecimalTuple2 [decimal, decimal]; + +type DecimalTuple3 [decimal, decimal...]; + +type DecimalTuple4 [decimal...]; + +type StringTuple1 [string, string, string, string]; + +type StringTuple2 [string, string]; + +type StringTuple3 [string, string...]; + +type StringTuple4 [string...]; + +type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata]; + +type AnydataTuple2 [anydata, anydata]; + +type AnydataTuple3 [anydata, anydata...]; + +type AnydataTuple4 [anydata...]; + +type JsonTuple1 [json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json]; + +type JsonTuple2 [json, json]; + +type JsonTuple3 [json, json...]; + +type JsonTuple4 [json...]; + +type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; + +type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; + +type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; + +type CustomTuple4 [string...]; + +type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; + +type CustomTuple6 [anydata...]; + +type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; + +type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; + +type IntegerArray1 int[]; + +type IntegerArray2 int[2]; + +type IntegerArray3 int[]; + +type IntegerArray4 int[2]; + +type IntegerArray5 int[3]; + +type IntegerArray6 int[4]; + +type StringArray string[]; + +type NillableStringArray string?[]; + +type NillableIntOrUnionStringArray (int|string?)[]; + +type StringArray1 string[]; + +type StringArray2 string[2]; + +type StringArray3 string[]; + +type StringArray4 string[2]; + +type StringArray5 string[3]; + +type StringArray6 string[4]; + +type FloatArray1 float[]; + +type FloatArray2 float[2]; + +type FloatArray3 float[]; + +type FloatArray4 float[2]; + +type FloatArray5 float[3]; + +type FloatArray6 float[4]; + +type DecimalArray1 decimal[]; + +type DecimalArray2 decimal[2]; + +type DecimalArray3 decimal[]; + +type DecimalArray4 decimal[2]; + +type DecimalArray5 decimal[3]; + +type DecimalArray6 decimal[4]; + +type BooleanArray boolean[]; + +type NillableBooleanArray boolean?[]; + +type NillableIntOrUnionBooleanArray (int|boolean?)[]; + +type BooleanArray2 boolean[2]; + +type BooleanArray3 boolean[3]; + +type BooleanArray4 boolean[]; + +type BooleanArray5 boolean[2]; + +type BooleanArray6 boolean[4]; + +type NilArray1 ()[]; + +type NilArray2 ()[2]; + +type NilArray3 ()[]; + +type NilArray4 ()[2]; + +type NilArray5 ()[3]; + +type NilArray6 ()[4]; + +type JsonArray1 json[]; + +type JsonArray2 json[2]; + +type JsonArray3 json[]; + +type JsonArray4 json[2]; + +type JsonArray5 json[3]; + +type JsonArray6 json[4]; + +type AnydataArray1 anydata[]; + +type AnydataArray2 anydata[2]; + +type AnydataArray3 anydata[]; + +type AnydataArray4 anydata[2]; + +type AnydataArray5 anydata[3]; + +type AnydataArray6 anydata[4]; + +type CustomArray1 CustomTuple2[]; + +type CustomArray2 CustomTuple2[2]; + +type CustomArray3 CustomTuple2[]; + +type CustomArray4 CustomTuple2[2]; + +type CustomArray5 CustomTuple2[3]; + +type CustomArray6 CustomTuple2[4]; + +type IntegerMap map; + +type StringMap map; + +type NillableIntUnionStringMap map; + +type IntUnionStringMap map; + +type DecimalMap map; + +type FloatMap map; + +type BooleanMap map; + +type NillableBooleanMap map; + +type NillableIntUnionBooleanMap map; + +type IntUnionBooleanMap map; + +type NilMap map<()>; + +type JsonMap map; + +type AnydataMap map; + +type CustomMap map; + +type BooleanRecord1Array BooleanRecord1[]; + +type ClosedBooleanRecord1Array BooleanRecord1[3]; + +type BooleanRecord2Array BooleanRecord2[]; + +type ClosedBooleanRecord2Array BooleanRecord2[3]; + +type BooleanRecord3Array BooleanRecord3[]; + +type ClosedBooleanRecord3Array BooleanRecord3[3]; + +type BooleanRecord4Array BooleanRecord4[]; + +type ClosedBooleanRecord4Array BooleanRecord4[3]; + +type BooleanRecord5Array BooleanRecord5[]; + +type ClosedBooleanRecord5Array BooleanRecord5[3]; + +type BooleanRecord6Array BooleanRecord6[]; + +type ClosedBooleanRecord6Array BooleanRecord6[3]; + +type BooleanRecord7Array BooleanRecord7[]; + +type ClosedBooleanRecord7Array BooleanRecord7[3]; + +type BooleanRecord8Array BooleanRecord8[]; + +type ClosedBooleanRecord8Array BooleanRecord8[3]; + +type BooleanRecord9Array BooleanRecord9[]; + +type ClosedBooleanRecord9Array BooleanRecord9[3]; + +type BooleanRecord10Array BooleanRecord10[]; + +type ClosedBooleanRecord10Array BooleanRecord10[3]; + +type BooleanRecord11Array BooleanRecord11[]; + +type ClosedBooleanRecord11Array BooleanRecord11[3]; + +type BooleanRecord12Array BooleanRecord12[]; + +type ClosedBooleanRecord12Array BooleanRecord12[3]; + +type BooleanRecord13Array BooleanRecord13[]; + +type ClosedBooleanRecord13Array BooleanRecord13[3]; + +type BooleanRecord14Array BooleanRecord14[]; + +type ClosedBooleanRecord14Array BooleanRecord14[3]; + +type BooleanRecord15Array BooleanRecord15[]; + +type ClosedBooleanRecord15Array BooleanRecord15[3]; + +type BooleanRecord16Array BooleanRecord16[]; + +type ClosedBooleanRecord16Array BooleanRecord16[3]; + +type BooleanRecord17Array BooleanRecord17[]; + +type ClosedBooleanRecord17Array BooleanRecord17[3]; + +type BooleanRecord18Array BooleanRecord18[]; + +type ClosedBooleanRecord18Array BooleanRecord18[3]; + +type NilRecord1Array NilRecord1[]; + +type ClosedNilRecord1Array NilRecord1[3]; + +type NilRecord2Array NilRecord2[]; + +type ClosedNilRecord2Array NilRecord2[3]; + +type NilRecord3Array NilRecord3[]; + +type ClosedNilRecord3Array NilRecord3[3]; + +type NilRecord4Array NilRecord4[]; + +type ClosedNilRecord4Array NilRecord4[3]; + +type NilRecord5Array NilRecord5[]; + +type ClosedNilRecord5Array NilRecord5[3]; + +type NilRecord6Array NilRecord6[]; + +type ClosedNilRecord6Array NilRecord6[3]; + +type NilRecord7Array NilRecord7[]; + +type ClosedNilRecord7Array NilRecord7[3]; + +type NilRecord8Array NilRecord8[]; + +type ClosedNilRecord8Array NilRecord8[3]; + +type NilRecord9Array NilRecord9[]; + +type ClosedNilRecord9Array NilRecord9[3]; + +type NilRecord10Array NilRecord10[]; + +type ClosedNilRecord10Array NilRecord10[3]; + +type NilRecord11Array NilRecord11[]; + +type ClosedNilRecord11Array NilRecord11[3]; + +type NilRecord12Array NilRecord12[]; + +type ClosedNilRecord12Array NilRecord12[3]; + +type NilRecord13Array NilRecord13[]; + +type ClosedNilRecord13Array NilRecord13[3]; + +type NilRecord14Array NilRecord14[]; + +type ClosedNilRecord14Array NilRecord14[3]; + +type IntegerRecord1Array IntegerRecord1[]; + +type ClosedIntegerRecord1Array IntegerRecord1[3]; + +type IntegerRecord2Array IntegerRecord2[]; + +type ClosedIntegerRecord2Array IntegerRecord2[3]; + +type IntegerRecord3Array IntegerRecord3[]; + +type ClosedIntegerRecord3Array IntegerRecord3[3]; + +type IntegerRecord4Array IntegerRecord4[]; + +type ClosedIntegerRecord4Array IntegerRecord4[3]; + +type IntegerRecord5Array IntegerRecord5[]; + +type ClosedIntegerRecord5Array IntegerRecord5[3]; + +type IntegerRecord6Array IntegerRecord6[]; + +type ClosedIntegerRecord6Array IntegerRecord6[3]; + +type IntegerRecord7Array IntegerRecord7[]; + +type ClosedIntegerRecord7Array IntegerRecord7[3]; + +type IntegerRecord8Array IntegerRecord8[]; + +type ClosedIntegerRecord8Array IntegerRecord8[3]; + +type IntegerRecord9Array IntegerRecord9[]; + +type ClosedIntegerRecord9Array IntegerRecord9[3]; + +type IntegerRecord10Array IntegerRecord10[]; + +type ClosedIntegerRecord10Array IntegerRecord10[3]; + +type IntegerRecord11Array IntegerRecord11[]; + +type ClosedIntegerRecord11Array IntegerRecord11[3]; + +type IntegerRecord12Array IntegerRecord12[]; + +type ClosedIntegerRecord12Array IntegerRecord12[3]; + +type IntegerRecord13Array IntegerRecord13[]; + +type ClosedIntegerRecord13Array IntegerRecord13[3]; + +type IntegerRecord14Array IntegerRecord14[]; + +type ClosedIntegerRecord14Array IntegerRecord14[3]; + +type FloatRecord1Array FloatRecord1[]; + +type ClosedFloatRecord1Array FloatRecord1[3]; + +type FloatRecord2Array FloatRecord2[]; + +type ClosedFloatRecord2Array FloatRecord2[3]; + +type FloatRecord3Array FloatRecord3[]; + +type ClosedFloatRecord3Array FloatRecord3[3]; + +type FloatRecord4Array FloatRecord4[]; + +type ClosedFloatRecord4Array FloatRecord4[3]; + +type FloatRecord5Array FloatRecord5[]; + +type ClosedFloatRecord5Array FloatRecord5[3]; + +type FloatRecord6Array FloatRecord6[]; + +type ClosedFloatRecord6Array FloatRecord6[3]; + +type FloatRecord7Array FloatRecord7[]; + +type ClosedFloatRecord7Array FloatRecord7[3]; + +type FloatRecord8Array FloatRecord8[]; + +type ClosedFloatRecord8Array FloatRecord8[3]; + +type FloatRecord9Array FloatRecord9[]; + +type ClosedFloatRecord9Array FloatRecord9[3]; + +type FloatRecord10Array FloatRecord10[]; + +type ClosedFloatRecord10Array FloatRecord10[3]; + +type FloatRecord11Array FloatRecord11[]; + +type ClosedFloatRecord11Array FloatRecord11[3]; + +type FloatRecord12Array FloatRecord12[]; + +type ClosedFloatRecord12Array FloatRecord12[3]; + +type FloatRecord13Array FloatRecord13[]; + +type ClosedFloatRecord13Array FloatRecord13[3]; + +type FloatRecord14Array FloatRecord14[]; + +type ClosedFloatRecord14Array FloatRecord14[3]; + +type DecimalRecord1Array DecimalRecord1[]; + +type ClosedDecimalRecord1Array DecimalRecord1[3]; + +type DecimalRecord2Array DecimalRecord2[]; + +type ClosedDecimalRecord2Array DecimalRecord2[3]; + +type DecimalRecord3Array DecimalRecord3[]; + +type ClosedDecimalRecord3Array DecimalRecord3[3]; + +type DecimalRecord4Array DecimalRecord4[]; + +type ClosedDecimalRecord4Array DecimalRecord4[3]; + +type DecimalRecord5Array DecimalRecord5[]; + +type ClosedDecimalRecord5Array DecimalRecord5[3]; + +type DecimalRecord6Array DecimalRecord6[]; + +type ClosedDecimalRecord6Array DecimalRecord6[3]; + +type DecimalRecord7Array DecimalRecord7[]; + +type ClosedDecimalRecord7Array DecimalRecord7[3]; + +type DecimalRecord8Array DecimalRecord8[]; + +type ClosedDecimalRecord8Array DecimalRecord8[3]; + +type DecimalRecord9Array DecimalRecord9[]; + +type ClosedDecimalRecord9Array DecimalRecord9[3]; + +type DecimalRecord10Array DecimalRecord10[]; + +type ClosedDecimalRecord10Array DecimalRecord10[3]; + +type DecimalRecord11Array DecimalRecord11[]; + +type ClosedDecimalRecord11Array DecimalRecord11[3]; + +type DecimalRecord12Array DecimalRecord12[]; + +type ClosedDecimalRecord12Array DecimalRecord12[3]; + +type DecimalRecord13Array DecimalRecord13[]; + +type ClosedDecimalRecord13Array DecimalRecord13[3]; + +type DecimalRecord14Array DecimalRecord14[]; + +type ClosedDecimalRecord14Array DecimalRecord14[3]; + +type StringRecord1Array StringRecord1[]; + +type ClosedStringRecord1Array StringRecord1[3]; + +type StringRecord2Array StringRecord2[]; + +type ClosedStringRecord2Array StringRecord2[3]; + +type StringRecord3Array StringRecord3[]; + +type ClosedStringRecord3Array StringRecord3[3]; + +type StringRecord4Array StringRecord4[]; + +type ClosedStringRecord4Array StringRecord4[3]; + +type StringRecord5Array StringRecord5[]; + +type ClosedStringRecord5Array StringRecord5[3]; + +type StringRecord6Array StringRecord6[]; + +type ClosedStringRecord6Array StringRecord6[3]; + +type StringRecord7Array StringRecord7[]; + +type ClosedStringRecord7Array StringRecord7[3]; + +type StringRecord8Array StringRecord8[]; + +type ClosedStringRecord8Array StringRecord8[3]; + +type StringRecord9Array StringRecord9[]; + +type ClosedStringRecord9Array StringRecord9[3]; + +type StringRecord10Array StringRecord10[]; + +type ClosedStringRecord10Array StringRecord10[3]; + +type StringRecord11Array StringRecord11[]; + +type ClosedStringRecord11Array StringRecord11[3]; + +type StringRecord12Array StringRecord12[]; + +type ClosedStringRecord12Array StringRecord12[3]; + +type StringRecord13Array StringRecord13[]; + +type ClosedStringRecord13Array StringRecord13[3]; + +type StringRecord14Array StringRecord14[]; + +type ClosedStringRecord14Array StringRecord14[3]; + +type StringRecord15Array StringRecord15[]; + +type StringRecord16Array StringRecord16[]; + +type StringRecord17Array StringRecord17[]; + +type StringRecord18Array StringRecord18[]; + +type StringRecord19Array StringRecord19[]; + +type StringRecord20Array StringRecord20[]; + +type StringRecord21Array StringRecord21[]; + +type StringRecord22Array StringRecord22[]; + +type StringRecord23Array StringRecord23[]; + +type JsonRecord1Array JsonRecord1[]; + +type ClosedJsonRecord1Array JsonRecord1[3]; + +type JsonRecord2Array JsonRecord2[]; + +type ClosedJsonRecord2Array JsonRecord2[3]; + +type JsonRecord3Array JsonRecord3[]; + +type ClosedJsonRecord3Array JsonRecord3[3]; + +type JsonRecord4Array JsonRecord4[]; + +type ClosedJsonRecord4Array JsonRecord4[3]; + +type JsonRecord5Array JsonRecord5[]; + +type ClosedJsonRecord5Array JsonRecord5[3]; + +type JsonRecord6Array JsonRecord6[]; + +type ClosedJsonRecord6Array JsonRecord6[3]; + +type JsonRecord7Array JsonRecord7[]; + +type ClosedJsonRecord7Array JsonRecord7[3]; + +type JsonRecord8Array JsonRecord8[]; + +type ClosedJsonRecord8Array JsonRecord8[3]; + +type JsonRecord9Array JsonRecord9[]; + +type ClosedJsonRecord9Array JsonRecord9[3]; + +type JsonRecord10Array JsonRecord10[]; + +type ClosedJsonRecord10Array JsonRecord10[3]; + +type JsonRecord11Array JsonRecord11[]; + +type ClosedJsonRecord11Array JsonRecord11[3]; + +type JsonRecord12Array JsonRecord12[]; + +type ClosedJsonRecord12Array JsonRecord12[3]; + +type JsonRecord13Array JsonRecord13[]; + +type ClosedJsonRecord13Array JsonRecord13[3]; + +type JsonRecord14Array JsonRecord14[]; + +type ClosedJsonRecord14Array JsonRecord14[3]; + +type AnydataRecord1Array AnydataRecord1[]; + +type ClosedAnydataRecord1Array AnydataRecord1[3]; + +type AnydataRecord2Array AnydataRecord2[]; + +type ClosedAnydataRecord2Array AnydataRecord2[3]; + +type AnydataRecord3Array AnydataRecord3[]; + +type ClosedAnydataRecord3Array AnydataRecord3[3]; + +type AnydataRecord4Array AnydataRecord4[]; + +type ClosedAnydataRecord4Array AnydataRecord4[3]; + +type AnydataRecord5Array AnydataRecord5[]; + +type ClosedAnydataRecord5Array AnydataRecord5[3]; + +type AnydataRecord6Array AnydataRecord6[]; + +type ClosedAnydataRecord6Array AnydataRecord6[3]; + +type AnydataRecord7Array AnydataRecord7[]; + +type ClosedAnydataRecord7Array AnydataRecord7[3]; + +type AnydataRecord8Array AnydataRecord8[]; + +type ClosedAnydataRecord8Array AnydataRecord8[3]; + +type AnydataRecord9Array AnydataRecord9[]; + +type ClosedAnydataRecord9Array AnydataRecord9[3]; + +type AnydataRecord10Array AnydataRecord10[]; + +type ClosedAnydataRecord10Array AnydataRecord10[3]; + +type AnydataRecord11Array AnydataRecord11[]; + +type ClosedAnydataRecord11Array AnydataRecord11[3]; + +type AnydataRecord12Array AnydataRecord12[]; + +type ClosedAnydataRecord12Array AnydataRecord12[3]; + +type AnydataRecord13Array AnydataRecord13[]; + +type ClosedAnydataRecord13Array AnydataRecord13[3]; + +type AnydataRecord14Array AnydataRecord14[]; + +type ClosedAnydataRecord14Array AnydataRecord14[3]; + +type CustomRecord1Array CustomRecord1[]; + +type ClosedCustomRecord1Array CustomRecord1[3]; + +type CustomRecord2Array CustomRecord2[]; + +type ClosedCustomRecord2Array CustomRecord2[3]; + +type CustomRecord3Array CustomRecord3[]; + +type ClosedCustomRecord3Array CustomRecord3[3]; + +type CustomRecord4Array CustomRecord4[]; + +type ClosedCustomRecord4Array CustomRecord4[3]; + +type CustomRecord5Array CustomRecord5[]; + +type ClosedCustomRecord5Array CustomRecord5[3]; + +type CustomRecord6Array CustomRecord6[]; + +type ClosedCustomRecord6Array CustomRecord6[3]; + +type CustomRecord7Array CustomRecord7[]; + +type ClosedCustomRecord7Array CustomRecord7[3]; + +type CustomRecord8Array CustomRecord8[]; + +type ClosedCustomRecord8Array CustomRecord8[3]; + +type CustomRecord9Array CustomRecord9[]; + +type ClosedCustomRecord9Array CustomRecord9[3]; + +type CustomRecord10Array CustomRecord10[]; + +type ClosedCustomRecord10Array CustomRecord10[3]; + +type CustomRecord11Array CustomRecord11[]; + +type ClosedCustomRecord11Array CustomRecord11[3]; + +type CustomRecord12Array CustomRecord12[]; + +type ClosedCustomRecord12Array CustomRecord12[3]; + +type CustomRecord13Array CustomRecord13[]; + +type ClosedCustomRecord13Array CustomRecord13[3]; + +type CustomRecord14Array CustomRecord14[]; + +type ClosedCustomRecord14Array CustomRecord14[3]; + +type CustomRecord15Array CustomRecord15[]; + +type CustomRecord16Array CustomRecord16[]; + +type CustomRecord17Array CustomRecord17[]; + +type CustomRecord18Array CustomRecord18[]; + +type CustomRecord19Array CustomRecord19[]; + +type CustomRecord20Array CustomRecord20[]; + +type CustomRecord21Array CustomRecord21[]; + +type CustomRecord22Array CustomRecord22[]; + +type CustomRecord23Array CustomRecord23[]; + +type CustomRecord24Array CustomRecord24[]; + +type CustomRecord25Array CustomRecord25[]; + +type CustomRecord26Array CustomRecord26[]; + +type CustomRecord27Array CustomRecord27[]; +type CustomRecord28Array CustomRecord28[]; +type CustomRecord29Array CustomRecord29[]; +type CustomRecord30Array CustomRecord30[]; +type CustomRecord31Array CustomRecord31[]; +type CustomRecord32Array CustomRecord32[]; +type CustomRecord33Array CustomRecord33[]; +type CustomRecord34Array CustomRecord34[]; +type CustomRecord35Array CustomRecord35[]; +type CustomRecord36Array CustomRecord36[]; +type CustomRecord37Array CustomRecord37[]; +type CustomRecord38Array CustomRecord38[]; +type CustomRecord39Array CustomRecord39[]; +type CustomRecord40Array CustomRecord40[]; +type CustomRecord41Array CustomRecord41[]; +type CustomRecord42Array CustomRecord42[]; +type CustomRecord43Array CustomRecord43[]; +type CustomRecord44Array CustomRecord44[]; +type CustomRecord45Array CustomRecord45[]; +type CustomRecord46Array CustomRecord46[]; +type CustomRecord47Array CustomRecord47[]; +type CustomRecord48Array CustomRecord48[]; +type CustomRecord49Array CustomRecord49[]; +type CustomRecord50Array CustomRecord50[]; +type CustomRecord51Array CustomRecord51[]; +type CustomRecord52Array CustomRecord52[]; +type CustomRecord53Array CustomRecord53[]; +type CustomRecord54Array CustomRecord54[]; +type CustomRecord55Array CustomRecord55[]; +type CustomRecord56Array CustomRecord56[]; + +type BooleanTuple1Array BooleanTuple1[]; + +type ClosedBooleanTuple1Array BooleanTuple1[3]; + +type BooleanTuple2Array BooleanTuple2[]; + +type ClosedBooleanTuple2Array BooleanTuple2[3]; + +type BooleanTuple3Array BooleanTuple3[]; + +type ClosedBooleanTuple3Array BooleanTuple3[3]; + +type BooleanTuple4Array BooleanTuple4[]; + +type ClosedBooleanTuple4Array BooleanTuple4[3]; + +type NillableBooleanTuple5Array NillableBooleanTuple5[]; + +type NillableBooleanTuple6Array NillableBooleanTuple6[]; + +type NillableBooleanTuple7Array NillableBooleanTuple7[]; + +type NillableBooleanTuple8Array NillableBooleanTuple8[]; + +type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; + +type NilTuple1Array NilTuple1[]; + +type ClosedNilTuple1Array NilTuple1[3]; + +type NilTuple2Array NilTuple2[]; + +type ClosedNilTuple2Array NilTuple2[3]; + +type NilTuple3Array NilTuple3[]; + +type ClosedNilTuple3Array NilTuple3[3]; + +type NilTuple4Array NilTuple4[]; + +type ClosedNilTuple4Array NilTuple4[3]; + +type IntegerTuple1Array IntegerTuple1[]; + +type ClosedIntegerTuple1Array IntegerTuple1[3]; + +type IntegerTuple2Array IntegerTuple2[]; + +type ClosedIntegerTuple2Array IntegerTuple2[3]; + +type IntegerTuple3Array IntegerTuple3[]; + +type ClosedIntegerTuple3Array IntegerTuple3[3]; + +type IntegerTuple4Array IntegerTuple4[]; + +type ClosedIntegerTuple4Array IntegerTuple4[3]; + +type FloatTuple1Array FloatTuple1[]; + +type ClosedFloatTuple1Array FloatTuple1[3]; + +type FloatTuple2Array FloatTuple2[]; + +type ClosedFloatTuple2Array FloatTuple2[3]; + +type FloatTuple3Array FloatTuple3[]; + +type ClosedFloatTuple3Array FloatTuple3[3]; + +type FloatTuple4Array FloatTuple4[]; + +type ClosedFloatTuple4Array FloatTuple4[3]; + +type DecimalTuple1Array DecimalTuple1[]; + +type ClosedDecimalTuple1Array DecimalTuple1[3]; + +type DecimalTuple2Array DecimalTuple2[]; + +type ClosedDecimalTuple2Array DecimalTuple2[3]; + +type DecimalTuple3Array DecimalTuple3[]; + +type ClosedDecimalTuple3Array DecimalTuple3[3]; + +type DecimalTuple4Array DecimalTuple4[]; + +type ClosedDecimalTuple4Array DecimalTuple4[3]; + +type StringTuple1Array StringTuple1[]; + +type ClosedStringTuple1Array StringTuple1[3]; + +type StringTuple2Array StringTuple2[]; + +type ClosedStringTuple2Array StringTuple2[3]; + +type StringTuple3Array StringTuple3[]; + +type ClosedStringTuple3Array StringTuple3[3]; + +type StringTuple4Array StringTuple4[]; + +type ClosedStringTuple4Array StringTuple4[3]; + +type AnydataTuple1Array AnydataTuple1[]; + +type ClosedAnydataTuple1Array AnydataTuple1[3]; + +type AnydataTuple2Array AnydataTuple2[]; + +type ClosedAnydataTuple2Array AnydataTuple2[3]; + +type AnydataTuple3Array AnydataTuple3[]; + +type ClosedAnydataTuple3Array AnydataTuple3[3]; + +type AnydataTuple4Array AnydataTuple4[]; + +type ClosedAnydataTuple4Array AnydataTuple4[3]; + +type JsonTuple1Array JsonTuple1[]; + +type ClosedJsonTuple1Array JsonTuple1[3]; + +type JsonTuple2Array JsonTuple2[]; + +type ClosedJsonTuple2Array JsonTuple2[3]; + +type JsonTuple3Array JsonTuple3[]; + +type ClosedJsonTuple3Array JsonTuple3[3]; + +type JsonTuple4Array JsonTuple4[]; + +type ClosedJsonTuple4Array JsonTuple4[3]; + +type CustomTuple1Array CustomTuple1[]; + +type ClosedCustomTuple1Array CustomTuple1[3]; + +type CustomTuple2Array CustomTuple2[]; + +type ClosedCustomTuple2Array CustomTuple2[3]; + +type CustomTuple3Array CustomTuple3[]; + +type ClosedCustomTuple3Array CustomTuple3[3]; + +type CustomTuple4Array CustomTuple4[]; + +type ClosedCustomTuple4Array CustomTuple4[3]; + +type CustomTuple5Array CustomTuple5[]; + +type ClosedCustomTuple5Array CustomTuple5[3]; + +type CustomTuple6Array CustomTuple6[]; + +type CustomTuple7Array CustomTuple7[]; + +type CustomTuple8Array CustomTuple8[]; + +type ClosedCustomTuple6Array CustomTuple6[3]; + +type IntegerArray1Array IntegerArray1[]; + +type ClosedIntegerArray1Array IntegerArray1[3]; + +type IntegerArray2Array IntegerArray2[]; + +type ClosedIntegerArray2Array IntegerArray2[3]; + +type IntegerArray3Array IntegerArray3[]; + +type ClosedIntegerArray3Array IntegerArray3[3]; + +type IntegerArray4Array IntegerArray4[]; + +type ClosedIntegerArray4Array IntegerArray4[3]; + +type IntegerArray5Array IntegerArray5[]; + +type ClosedIntegerArray5Array IntegerArray5[3]; + +type IntegerArray6Array IntegerArray5[]; + +type ClosedIntegerArray6Array IntegerArray5[3]; + +type StringArray1Array StringArray1[]; + +type StringArrayArray StringArray[]; + +type NillableStringArrayArray NillableStringArray[]; + +type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; + +type ClosedStringArray1Array StringArray1[3]; + +type StringArray2Array StringArray2[]; + +type ClosedStringArray2Array StringArray2[3]; + +type StringArray3Array StringArray3[]; + +type ClosedStringArray3Array StringArray3[3]; + +type StringArray4Array StringArray4[]; + +type ClosedStringArray4Array StringArray4[3]; + +type StringArray5Array StringArray5[]; + +type ClosedStringArray5Array StringArray5[3]; + +type StringArray6Array StringArray5[]; + +type ClosedStringArray6Array StringArray5[3]; + +type FloatArray1Array FloatArray1[]; + +type ClosedFloatArray1Array FloatArray1[3]; + +type FloatArray2Array FloatArray2[]; + +type ClosedFloatArray2Array FloatArray2[3]; + +type FloatArray3Array FloatArray3[]; + +type ClosedFloatArray3Array FloatArray3[3]; + +type FloatArray4Array FloatArray4[]; + +type ClosedFloatArray4Array FloatArray4[3]; + +type FloatArray5Array FloatArray5[]; + +type ClosedFloatArray5Array FloatArray5[3]; + +type FloatArray6Array FloatArray5[]; + +type ClosedFloatArray6Array FloatArray5[3]; + +type DecimalArray1Array DecimalArray1[]; + +type ClosedDecimalArray1Array DecimalArray1[3]; + +type DecimalArray2Array DecimalArray2[]; + +type ClosedDecimalArray2Array DecimalArray2[3]; + +type DecimalArray3Array DecimalArray3[]; + +type ClosedDecimalArray3Array DecimalArray3[3]; + +type DecimalArray4Array DecimalArray4[]; + +type ClosedDecimalArray4Array DecimalArray4[3]; + +type DecimalArray5Array DecimalArray5[]; + +type ClosedDecimalArray5Array DecimalArray5[3]; + +type DecimalArray6Array DecimalArray5[]; + +type ClosedDecimalArray6Array DecimalArray5[3]; + +type BooleanArrayArray BooleanArray[]; + +type ClosedBooleanArrayArray BooleanArray[3]; + +type NillableBooleanArrayArray NillableBooleanArray[]; + +type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; + +type BooleanArray2Array BooleanArray2[]; + +type ClosedBooleanArray2Array BooleanArray2[3]; + +type BooleanArray3Array BooleanArray3[]; + +type ClosedBooleanArray3Array BooleanArray3[3]; + +type BooleanArray4Array BooleanArray4[]; + +type ClosedBooleanArray4Array BooleanArray4[3]; + +type BooleanArray5Array BooleanArray5[]; + +type ClosedBooleanArray5Array BooleanArray5[3]; + +type BooleanArray6Array BooleanArray5[]; + +type ClosedBooleanArray6Array BooleanArray5[3]; + +type NilArray1Array NilArray1[]; + +type ClosedNilArray1Array NilArray1[3]; + +type NilArray2Array NilArray2[]; + +type ClosedNilArray2Array NilArray2[3]; + +type NilArray3Array NilArray3[]; + +type ClosedNilArray3Array NilArray3[3]; + +type NilArray4Array NilArray4[]; + +type ClosedNilArray4Array NilArray4[3]; + +type NilArray5Array NilArray5[]; + +type ClosedNilArray5Array NilArray5[3]; + +type NilArray6Array NilArray5[]; + +type ClosedNilArray6Array NilArray5[3]; + +type JsonArray1Array JsonArray1[]; + +type ClosedJsonArray1Array JsonArray1[3]; + +type JsonArray2Array JsonArray2[]; + +type ClosedJsonArray2Array JsonArray2[3]; + +type JsonArray3Array JsonArray3[]; + +type ClosedJsonArray3Array JsonArray3[3]; + +type JsonArray4Array JsonArray4[]; + +type ClosedJsonArray4Array JsonArray4[3]; + +type JsonArray5Array JsonArray5[]; + +type ClosedJsonArray5Array JsonArray5[3]; + +type JsonArray6Array JsonArray5[]; + +type ClosedJsonArray6Array JsonArray5[3]; + +type AnydataArray1Array AnydataArray1[]; + +type ClosedAnydataArray1Array AnydataArray1[3]; + +type AnydataArray2Array AnydataArray2[]; + +type ClosedAnydataArray2Array AnydataArray2[3]; + +type AnydataArray3Array AnydataArray3[]; + +type ClosedAnydataArray3Array AnydataArray3[3]; + +type AnydataArray4Array AnydataArray4[]; + +type ClosedAnydataArray4Array AnydataArray4[3]; + +type AnydataArray5Array AnydataArray5[]; + +type ClosedAnydataArray5Array AnydataArray5[3]; + +type AnydataArray6Array AnydataArray5[]; + +type ClosedAnydataArray6Array AnydataArray5[3]; + +type CustomArray1Array CustomArray1[]; + +type ClosedCustomArray1Array CustomArray1[3]; + +type CustomArray2Array CustomArray2[]; + +type ClosedCustomArray2Array CustomArray2[3]; + +type CustomArray3Array CustomArray3[]; + +type ClosedCustomArray3Array CustomArray3[3]; + +type CustomArray4Array CustomArray4[]; + +type ClosedCustomArray4Array CustomArray4[3]; + +type CustomArray5Array CustomArray5[]; + +type ClosedCustomArray5Array CustomArray5[3]; + +type CustomArray6Array CustomArray5[]; + +type ClosedCustomArray6Array CustomArray5[3]; + +type IntegerMapArray IntegerMap[]; + +type ClosedIntegerMapArray IntegerMap[3]; + +type StringMapArray StringMap[]; + +type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; + +type IntUnionStringMapArray IntUnionStringMap[]; + +type ClosedStringMapArray StringMap[3]; + +type DecimalMapArray DecimalMap[]; + +type ClosedDecimalMapArray DecimalMap[3]; + +type FloatMapArray FloatMap[]; + +type ClosedFloatMapArray FloatMap[3]; + +type BooleanMapArray BooleanMap[]; + +type NillableBooleanMapArray NillableBooleanMap[]; + +type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; + +type IntUnionBooleanMapArray IntUnionBooleanMap[]; + +type ClosedBooleanMapArray BooleanMap[3]; + +type NilMapArray NilMap[]; + +type ClosedNilMapArray NilMap[3]; + +type JsonMapArray JsonMap[]; + +type ClosedJsonMapArray JsonMap[3]; + +type AnydataMapArray AnydataMap[]; + +type ClosedAnydataMapArray AnydataMap[3]; + +type CustomMapArray CustomMap[]; + +type ClosedCustomMapArray CustomMap[3]; diff --git a/ballerina-tests/parse-string-array-types-tests/.gitignore b/ballerina-tests/parse-string-array-types-tests/.gitignore new file mode 100644 index 0000000..d5fc29a --- /dev/null +++ b/ballerina-tests/parse-string-array-types-tests/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/ballerina-tests/parse-string-array-types-tests/Ballerina.toml b/ballerina-tests/parse-string-array-types-tests/Ballerina.toml new file mode 100644 index 0000000..256e0d0 --- /dev/null +++ b/ballerina-tests/parse-string-array-types-tests/Ballerina.toml @@ -0,0 +1,13 @@ +[package] +org = "ballerina" +name = "parse_string_array_types_tests" +version = "0.1.0" + +[[dependency]] +org = "ballerina" +name = "csv_commons" +repository = "local" +version = "0.1.0" + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina-tests/parse-string-array-types-tests/Dependencies.toml b/ballerina-tests/parse-string-array-types-tests/Dependencies.toml new file mode 100644 index 0000000..81c0d40 --- /dev/null +++ b/ballerina-tests/parse-string-array-types-tests/Dependencies.toml @@ -0,0 +1,98 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0" + +[[package]] +org = "ballerina" +name = "csv_commons" +version = "0.1.0" +scope = "testOnly" +modules = [ + {org = "ballerina", packageName = "csv_commons", moduleName = "csv_commons"} +] + +[[package]] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "parse_string_array_types_tests" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "csv_commons"}, + {org = "ballerina", name = "data.csv"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerina", packageName = "parse_string_array_types_tests", moduleName = "parse_string_array_types_tests"} +] + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + 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 new file mode 100644 index 0000000..eec62d6 --- /dev/null +++ b/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal @@ -0,0 +1,311 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; +import ballerina/test; + +@test:Config +function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { + BooleanArrayArray|csv:Error cv1baa = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1baa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanArrayArray|csv:Error cv2baa = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2baa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + BooleanArrayArray|csv:Error cv3baa = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cv3baa is csv:Error); + test:assertEquals((cv3baa).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanArrayArray|csv:Error cv4baa = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertTrue(cv4baa is csv:Error); + test:assertEquals((cv4baa).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanArrayArray|csv:Error cv5baa = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cv5baa is csv:Error); + test:assertEquals((cv5baa).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanArrayArray|csv:Error cv6baa = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cv6baa is csv:Error); + test:assertEquals((cv6baa).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanArrayArray|csv:Error cv7baa = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cv7baa is csv:Error); + test:assertEquals((cv7baa).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + NillableBooleanArrayArray|csv:Error cv1nbaa = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1nbaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableBooleanArrayArray|csv:Error cv2nbaa = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2nbaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanArrayArray|csv:Error cv3nbaa = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3nbaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableBooleanArrayArray|csv:Error cv4nbaa = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4nbaa, [ + [true, (), (), false], + [true, (), (), false] + ]); + + NillableBooleanArrayArray|csv:Error cv5nbaa = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cv5nbaa is csv:Error); + test:assertEquals((cv5nbaa).message(), common:generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanArrayArray|csv:Error cv6nbaa = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6nbaa, [ + [(), ()] + ]); + + NillableBooleanArrayArray|csv:Error cv7nbaa = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7nbaa, [ + [b1, b2, (), b4] + ]); + + NillableIntOrUnionBooleanArrayArray|csv:Error cv1niubaa = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1niubaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableIntOrUnionBooleanArrayArray|csv:Error cv2niubaa = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2niubaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableIntOrUnionBooleanArrayArray|csv:Error cv3niubaa = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3niubaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableIntOrUnionBooleanArrayArray|csv:Error cv4niubaa = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4niubaa, [ + [true, (), (), false], + [true, (), (), false] + ]); + + NillableIntOrUnionBooleanArrayArray|csv:Error cv5niubaa = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cv5niubaa, [ + [true, false, true, 2], + [true, false, true, 3] + ]); +} + +@test:Config +function testFromCsvStringWithTypeForStringAndArrayAsExpectedType2() { + NillableIntOrUnionBooleanArrayArray|csv:Error cv6niubaa = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6niubaa, [ + [(), ()] + ]); + + NillableIntOrUnionBooleanArrayArray|csv:Error cv7niubaa = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7niubaa, [ + [b1, b2, (), b4] + ]); + + StringArray1Array|csv:Error cv1saa = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1saa, [ + ["true", "false", "true", "false"], + ["true", "false", "true", "false"], + ["true", "false", "true", "false"] + ]); + + StringArray1Array|csv:Error cv2saa = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2saa, [ + ["true", "false", "true", "false", "true"], + ["true", "false", "true", "false", "true"] + ]); + + StringArray1Array|csv:Error cv3saa = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3saa, [ + ["true", "false", "true"], + ["TRUE", "FALSE", "()"], + ["true", "true", "FALSE"] + ]); + + StringArray1Array|csv:Error cv4saa = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4saa, [ + ["true", "()", "()", "false"], + ["true", "()", "null", "false"] + ]); + + StringArray1Array|csv:Error cv5saa = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cv5saa, [ + ["true", "false", "true", "2"], + ["true", "false", "true", "3"] + ]); + + StringArray1Array|csv:Error cv6saa = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6saa, [ + ["()", "()"] + ]); + + StringArray1Array|csv:Error cv7saa = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7saa, [ + ["true", "false", "()", "false"] + ]); + + StringArray2Array|csv:Error cv1s2aa = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1s2aa, [ + ["true", "false"], + ["true", "false"], + ["true", "false"] + ]); + + StringArray2Array|csv:Error cv2s2aa = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2s2aa, [ + ["true", "false"], + ["true", "false"] + ]); + + StringArray2Array|csv:Error cv3s2aa = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3s2aa, [ + ["true", "false"], + ["TRUE", "FALSE"], + ["true", "true"] + ]); + + StringArray2Array|csv:Error cv4s2aa = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4s2aa, [ + ["true", "()"], + ["true", "()"] + ]); + + StringArray2Array|csv:Error cv5s2aa = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cv5s2aa, [ + ["true", "false"], + ["true", "false"] + ]); + + StringArray2Array|csv:Error cv6s2aa = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6s2aa, [ + ["()", "()"] + ]); + + StringArray2Array|csv:Error cv7s2aa = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7s2aa, [ + ["true", "false"] + ]); + + JsonArray1Array|csv:Error cv1jaa = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1jaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); +} + +@test:Config +function testFromCsvStringWithTypeForStringAndArrayAsExpectedType3() { + JsonArray1Array|csv:Error cv2jaa = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2jaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + JsonArray1Array|csv:Error cv3jaa = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3jaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + JsonArray1Array|csv:Error cv4jaa = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4jaa, [ + [true, (), (), false], + [true, (), (), false] + ]); + + JsonArray1Array|csv:Error cv5jaa = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cv5jaa, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + JsonArray1Array|csv:Error cv6jaa = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6jaa, [ + [(), ()] + ]); + + JsonArray1Array|csv:Error cv7jaa = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7jaa, [ + [b1, b2, (), b4] + ]); + + AnydataArray1Array|csv:Error cv1anydaa = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cv1anydaa, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + AnydataArray1Array|csv:Error cv2anydaa = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cv2anydaa, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + AnydataArray1Array|csv:Error cv3anydaa = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cv3anydaa, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + AnydataArray1Array|csv:Error cv4anydaa = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cv4anydaa, [ + [true, (), (), false], + [true, (), (), false] + ]); + + AnydataArray1Array|csv:Error cv5anydaa = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cv5anydaa, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + AnydataArray1Array|csv:Error cv6anydaa = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cv6anydaa, [ + [(), ()] + ]); + + AnydataArray1Array|csv:Error cv7anydaa = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cv7anydaa, [ + [b1, b2, (), b4] + ]); + + DecimalArray1Array|csv:Error cv1daa = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertTrue(cv1daa is csv:Error); + test:assertEquals((cv1daa).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); + + DecimalArray1Array|csv:Error cv3daa = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cv3daa is csv:Error); + test:assertEquals((cv3daa).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); + + DecimalArray1Array|csv:Error cv6daa = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cv6daa is csv:Error); + test:assertEquals((cv6daa).message(), common:generateErrorMessageForInvalidCast("()", "decimal")); + + DecimalArray1Array|csv:Error cv7daa = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cv7daa is csv:Error); + test:assertEquals((cv7daa).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); +} 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 new file mode 100644 index 0000000..7cc5087 --- /dev/null +++ b/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_tuple_test.bal @@ -0,0 +1,472 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; +import ballerina/test; + +@test:Config +function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { + BooleanTuple1Array|csv:Error cbv1bt1 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt1, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple1Array|csv:Error cbv2bt1 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt1, [ + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple1Array|csv:Error cbv3bt1 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt1 is csv:Error); + test:assertEquals((cbv3bt1).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple1Array|csv:Error cbv5bt1 = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt1 is csv:Error); + test:assertEquals((cbv5bt1).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanTuple1Array|csv:Error cbv7bt1 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt1 is csv:Error); + test:assertEquals((cbv7bt1).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple2Array|csv:Error cbv1bt2 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt2, [ + [true, false], + [true, false], + [true, false] + ]); + + BooleanTuple2Array|csv:Error cbv2bt2 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt2, [ + [true, false], + [true, false] + ]); + + BooleanTuple2Array|csv:Error cbv3bt2 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt2, [ + [true, false], + [true, false], + [true, true] + ]); + + BooleanTuple2Array|csv:Error cbv4bt2 = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertTrue(cbv4bt2 is csv:Error); + test:assertEquals((cbv4bt2).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple3Array|csv:Error cbv1bt3 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt3, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple3Array|csv:Error cbv2bt3 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt3, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + BooleanTuple3Array|csv:Error cbv3bt3 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt3 is csv:Error); + test:assertEquals((cbv3bt3).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple3Array|csv:Error cbv5bt3 = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt3 is csv:Error); + test:assertEquals((cbv5bt3).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanTuple3Array|csv:Error cbv7bt3 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt3 is csv:Error); + test:assertEquals((cbv7bt3).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|csv:Error cbv1bt4 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt4, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + BooleanTuple4Array|csv:Error cbv2bt4 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt4, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + BooleanTuple4Array|csv:Error cbv3bt4 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3bt4 is csv:Error); + test:assertEquals((cbv3bt4).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|csv:Error cbv4bt4 = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertTrue(cbv4bt4 is csv:Error); + test:assertEquals((cbv4bt4).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanTuple4Array|csv:Error cbv5bt4 = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt4 is csv:Error); + test:assertEquals((cbv5bt4).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanTuple4Array|csv:Error cbv6bt4 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cbv6bt4 is csv:Error); + test:assertEquals((cbv6bt4).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + +} + +@test:Config +function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { + BooleanTuple4Array|csv:Error cbv7bt4 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertTrue(cbv7bt4 is csv:Error); + test:assertEquals((cbv7bt4).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + NillableBooleanTuple5Array|csv:Error cbv1bt5 = csv:parseStringToList(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); + test:assertEquals(cbv2bt5, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanTuple5Array|csv:Error cbv3bt5 = csv:parseStringToList(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); + test:assertEquals(cbv4bt5, [ + [true, (), (), false, null], + [true, (), (), false, null] + ]); + + NillableBooleanTuple5Array|csv:Error cbv5bt5 = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt5 is csv:Error); + test:assertEquals((cbv5bt5).message(), common:generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanTuple5Array|csv:Error cbv6bt5 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt5, [ + [(), (), null, null, null] + ]); + + NillableBooleanTuple5Array|csv:Error cbv7bt5 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt5, [ + [b1, b2, (), b4, null] + ]); + + NillableBooleanTuple6Array|csv:Error cbv1bt6 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt6, [ + [true, false], + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|csv:Error cbv2bt6 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt6, [ + [true, false], + [true, false] + ]); + + NillableBooleanTuple6Array|csv:Error cbv3bt6 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt6, [ + [true, false], + [true, false], + [true, true] + ]); + + NillableBooleanTuple6Array|csv:Error cbv4bt6 = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt6, [ + [true, ()], + [true, ()] + ]); + + NillableBooleanTuple6Array|csv:Error cbv6bt6 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt6, [ + [(), null] + ]); + + NillableBooleanTuple6Array|csv:Error cbv7bt6 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt6, [ + [b1, b2] + ]); + + NillableBooleanTuple7Array|csv:Error cbv1bt7 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt7, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableBooleanTuple7Array|csv:Error cbv2bt7 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt7, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanTuple7Array|csv:Error cbv3bt7 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt7, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableBooleanTuple7Array|csv:Error cbv4bt7 = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt7, [ + [true, (), (), false], + [true, (), (), false] + ]); + +} +@test:Config +function testFromCsvStringWithTypeForStringAndTupleAsExpectedType3() { + NillableBooleanTuple7Array|csv:Error cbv5bt7 = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt7 is csv:Error); + test:assertEquals((cbv5bt7).message(), common:generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanTuple7Array|csv:Error cbv6bt7 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt7, [ + [(), ()] + ]); + + NillableBooleanTuple7Array|csv:Error cbv7bt7 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt7, [ + [b1, b2, (), false] + ]); + + NillableBooleanTuple8Array|csv:Error cbv1bt8 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt8, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableBooleanTuple8Array|csv:Error cbv2bt8 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt8, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableBooleanTuple8Array|csv:Error cbv3bt8 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt8, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableBooleanTuple8Array|csv:Error cbv4bt8 = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt8, [ + [true, (), (), false], + [true, (), (), false] + ]); + + NillableBooleanTuple8Array|csv:Error cbv5bt8 = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertTrue(cbv5bt8 is csv:Error); + test:assertEquals((cbv5bt8).message(), common:generateErrorMessageForInvalidCast("2", "boolean?")); + + NillableBooleanTuple8Array|csv:Error cbv6bt8 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt8, [ + [(), ()] + ]); + + NillableBooleanTuple8Array|csv:Error cbv7bt8 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt8, [ + [b1, b2, (), false] + ]); + + NillableIntBooleanTuple9Array|csv:Error cbv1bt9 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1bt9, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + NillableIntBooleanTuple9Array|csv:Error cbv2bt9 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2bt9, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + NillableIntBooleanTuple9Array|csv:Error cbv3bt9 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3bt9, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + NillableIntBooleanTuple9Array|csv:Error cbv4bt9 = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4bt9, [ + [true, (), (), false], + [true, (), (), false] + ]); + + NillableIntBooleanTuple9Array|csv:Error cbv5bt9 = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cbv5bt9, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + NillableIntBooleanTuple9Array|csv:Error cbv6bt9 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6bt9, [ + [(), ()] + ]); + + NillableIntBooleanTuple9Array|csv:Error cbv7bt9 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7bt9, [ + [b1, b2, (), false] + ]); + + NilTuple3Array|csv:Error cbv1nt3 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertTrue(cbv1nt3 is csv:Error); + test:assertEquals((cbv1nt3).message(), common:generateErrorMessageForInvalidCast("true", "()")); + + NilTuple3Array|csv:Error cbv3nt3 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3nt3 is csv:Error); + test:assertEquals((cbv3nt3).message(), common:generateErrorMessageForInvalidCast("true", "()")); + + NilTuple3Array|csv:Error cbv6nt3 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6nt3, [ + [(), ()] + ]); + + AnydataTuple3Array|csv:Error cbv1anyd3 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1anyd3, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + AnydataTuple3Array|csv:Error cbv2anyd3 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2anyd3, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + AnydataTuple3Array|csv:Error cbv3anyd3 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3anyd3, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + AnydataTuple3Array|csv:Error cbv4anyd3 = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4anyd3, [ + [true, (), (), false], + [true, (), (), false] + ]); + + AnydataTuple3Array|csv:Error cbv5anyd3 = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cbv5anyd3, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + AnydataTuple3Array|csv:Error cbv6anyd3 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6anyd3, [ + [(), ()] + ]); + + AnydataTuple3Array|csv:Error cbv7anyd3 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7anyd3, [ + [b1, b2, (), false] + ]); +} + +@test:Config +function testFromCsvStringWithTypeForStringAndTupleAsExpectedType4() { + JsonTuple3Array|csv:Error cbv1j3 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1j3, [ + [true, false, true, false], + [true, false, true, false], + [true, false, true, false] + ]); + + JsonTuple3Array|csv:Error cbv2j3 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2j3, [ + [true, false, true, false, true], + [true, false, true, false, true] + ]); + + JsonTuple3Array|csv:Error cbv3j3 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3j3, [ + [true, false, true], + [true, false, ()], + [true, true, false] + ]); + + JsonTuple3Array|csv:Error cbv4j3 = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4j3, [ + [true, (), (), false], + [true, (), (), false] + ]); + + JsonTuple3Array|csv:Error cbv5j3 = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cbv5j3, [ + [true, false, true, 2], + [true, false, true, 3] + ]); + + JsonTuple3Array|csv:Error cbv6j3 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6j3, [ + [(), ()] + ]); + + JsonTuple3Array|csv:Error cbv7j3 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7j3, [ + [b1, b2, (), false] + ]); + + StringTuple3Array|csv:Error cbv1s3 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertEquals(cbv1s3, [ + ["true", "false", "true", "false"], + ["true", "false", "true", "false"], + ["true", "false", "true", "false"] + ]); + + StringTuple3Array|csv:Error cbv2s3 = csv:parseStringToList(csvStringWithBooleanValues2); + test:assertEquals(cbv2s3, [ + ["true", "false", "true", "false", "true"], + ["true", "false", "true", "false", "true"] + ]); + + StringTuple3Array|csv:Error cbv3s3 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertEquals(cbv3s3, [ + ["true", "false", "true"], + ["TRUE", "FALSE", "()"], + ["true", "true", "FALSE"] + ]); + + StringTuple3Array|csv:Error cbv4s3 = csv:parseStringToList(csvStringWithBooleanValues4); + test:assertEquals(cbv4s3, [ + ["true", "()", "()", "false"], + ["true", "()", "null", "false"] + ]); + + StringTuple3Array|csv:Error cbv5s3 = csv:parseStringToList(csvStringWithBooleanValues5); + test:assertEquals(cbv5s3, [ + ["true", "false", "true", "2"], + ["true", "false", "true", "3"] + ]); + + StringTuple3Array|csv:Error cbv6s3 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertEquals(cbv6s3, [ + ["()", "()"] + ]); + + StringTuple3Array|csv:Error cbv7s3 = csv:parseStringToList(csvStringWithBooleanValues7); + test:assertEquals(cbv7s3, [ + ["true", "false", "()", "false"] + ]); + + DecimalTuple3Array|csv:Error cbv1dt3 = csv:parseStringToList(csvStringWithBooleanValues1); + test:assertTrue(cbv1dt3 is csv:Error); + test:assertEquals((cbv1dt3).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); + + DecimalTuple3Array|csv:Error cbv3dt3 = csv:parseStringToList(csvStringWithBooleanValues3); + test:assertTrue(cbv3dt3 is csv:Error); + test:assertEquals((cbv3dt3).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); + + DecimalTuple3Array|csv:Error cbv6dt3 = csv:parseStringToList(csvStringWithBooleanValues6); + test:assertTrue(cbv6dt3 is csv:Error); + test:assertEquals((cbv6dt3).message(), common:generateErrorMessageForInvalidCast("()", "decimal")); +} diff --git a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal new file mode 100644 index 0000000..360a493 --- /dev/null +++ b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal @@ -0,0 +1,256 @@ +boolean b1 = true; +false b2 = false; +boolean? b3 = (); +boolean|int b4 = false; + +() n1 = (); +int? n2 = (); +() n3 = null; + +int i1 = 1; +int i2 = -2; +int i3 = int:MAX_VALUE; +int i4 = int:MIN_VALUE; +int i5 = 0; +2 i6 = 2; +int? i7 = (); +int|string i8 = 100; + +float f1 = 2.234; +float f2 = -3.21f; +float f3 = 0; +float f4 = float:Infinity; +float f5 = -float:Infinity; +float f6 = float:NaN; +2.3f f7 = 2.3; +float? f8 = (); +float|decimal f9 = 1.21; + +decimal d1 = 2.234; +decimal d2 = -3.21d; +decimal d3 = 0; +2.3d d4 = 2.3; +decimal? d5 = (); +decimal|int d6 = 1.21; + +string s1 = "string"; +string s2 = ""; +string:Char s3 = "a"; + +map bm1 = {b1, b2}; +map bm2 = {b1, b2, b3, n1, n3}; +map bm3 = {b1, b2, b3, b4, i1}; +map<()> bm4 = {n1, n3}; +map bm5 = {b1, b2, b3, b4:true}; + +map m5 = {i1, i2, i3, i4, i5, i6}; +map m6 = {f1, f2, f3, f4, f5, f6, f7}; +map m7 = {d1, d2, d3, d4}; +map m8 = {d1, f1, f9, f10: 1.23}; +map m9 = {s1, s2, s3}; +map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; +map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; + +boolean[] arr1 = [b1, b2]; +boolean?[] arr2 = [b1, b2, b3, n1, n3]; +(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; +()[] arr4 = [n1, n3]; +int[] arr5 = [i1, i2, i3, i4, i5, i6]; +float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; +decimal[] arr7 = [d1, d2, d3, d4]; +(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; +string[] arr9 = [s1, s2, s3]; +anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; + +[boolean, boolean] bt1 = [b1, b2]; +[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; +[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; +[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; +[boolean...] bt5 = [b1, b2]; + +[string, string] st1 = [s1, s2]; +[string, string, string, string] st2 = [s1, s2, s3, s2]; +[string...] st3 = [s1, s2]; +[string, string, string...] st4 = [s1, s2, s3, s2]; + +[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; +[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; +[string?...] st7 = [s1, s2]; +[string...] st8 = []; +[string, string, string] st9 = [s1, s2, s3]; + +[(), ()] tup4 = [n1, n3]; +[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; +[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; +[string, string, string] tup9 = [s1, s2, s3]; +[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, + n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, json] tup11 = + [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, + f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 +]; + +[boolean, boolean...] restTup1 = [b1, b2]; +[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; +[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; +[(), ()...] restTup4 = [n1, n3]; +[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; +[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal...] restTup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; +[string...] restTup9 = [s1, s2, s3]; +[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 +]; + +var booleanRecordArray = [ + {b1, b2, b3, b4}, {b1, b2, b3, b4} +]; + +var booleanRecordArray2 = [ + {},{} +]; + +string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 +true,false,true,false +true,false, true,false +true,false,true,false +`; + +string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 +true,false, true,false,true +true,false, true,false,true`; + +string csvStringWithBooleanValues3 = string `b1,b2,b3 +${" "}${"\t"} +true, false,true +${" "} + TRUE, FALSE,() +${" "} + +true, true,FALSE + +`; + +string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 + true,(), (),false + true,(), null,false + +`; + +string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 + +true,false,true,2 + +true,false,true,3 +`; + +string csvStringWithBooleanValues6 = string `b2,b3 +(),() + +`; + +string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 +${b1},${b2},(),${b4} +`; + +string csvStringData1 = string ` + a, b, c, d, e, f + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData2 = string ` + hello, hello, (), 12, true, 12.34 + // comment + + a, b, c, d, e, f + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData3 = string ` + a, b, c, d, e, f + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData4 = string ` + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData5 = string ` + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData6 = string ` + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData7 = string ` + a@ b@ c@ d@ e@ f + 1@ string@ true@ 2.234@ -3.21@ () + 2@ s,tring@ true@ 2.234@ -3.21@ null + 3@ stri,ng@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; +string csvStringData8 = string ` + a@ b@ c@ d@ e@ f + + + + 1@ stri,ng@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ ()@-3.21 + 3@ string@ true@ 2.234@ -3.21@ null + + 4@ s,tring@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; + +string csvStringData9 = string ` + + 1@ string@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ -3.21@ null + + 3@ string@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ ()@-3.21 + + 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina-tests/parse-string-array-types-tests/tests/types.bal b/ballerina-tests/parse-string-array-types-tests/tests/types.bal new file mode 100644 index 0000000..a2b4b2b --- /dev/null +++ b/ballerina-tests/parse-string-array-types-tests/tests/types.bal @@ -0,0 +1,2534 @@ +type BooleanRecord1 record { + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +}; + +type BooleanRecord2 record {| + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +|}; + +type BooleanRecord3 record {| + boolean b1; + boolean? b3; +|}; + +type BooleanRecord4 record { + boolean b1; + boolean? b3; +}; + +type BooleanRecord5 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +}; + +type BooleanRecord6 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +|}; + +type BooleanRecord7 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type BooleanRecord8 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type BooleanRecord9 record {| + boolean b1; + boolean? b3; + boolean?...; +|}; + +type BooleanRecord10 record {| + boolean...; +|}; + +type BooleanRecord11 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + boolean?|string...; +|}; + +type BooleanRecord12 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string|boolean...; +|}; + +type BooleanRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord15 record {| + int b1; + string defaultableField = ""; + string? nillableField = (); + boolean?...; +|}; + +type BooleanRecord16 record {| + boolean?...; +|}; + +type BooleanRecord17 record {| + int...; +|}; + +type BooleanRecord18 record {| + boolean b2; + int?...; +|}; + +type NilRecord1 record { + () n1; + () n2; + () n3; +}; + +type NilRecord2 record {| + () n1; + () n2; + () n3; +|}; + +type NilRecord3 record {| + () n1; + () n4; +|}; + +type NilRecord4 record { + () n1; + () n4; +}; + +type NilRecord5 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +}; + +type NilRecord6 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type NilRecord7 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type NilRecord8 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type NilRecord9 record {| + () n1; + () n2; + ()...; +|}; + +type NilRecord10 record {| + ()...; +|}; + +type NilRecord11 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord12 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type NilRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type IntegerRecord1 record { + int i1; + int i2; + int i3; + int? i4; + int? i5; + int i6; + int i7; + int? i8; +}; + +type IntegerRecord2 record {| + int i1; + int? i2; + int i3; + int i4; + int? i5; + int i6; + int i7; + int? i8; +|}; + +type IntegerRecord3 record {| + int i1; + int i4; + int i6; +|}; + +type IntegerRecord4 record { + int i1; + int i4; + int i6; +}; + +type IntegerRecord5 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +}; + +type IntegerRecord6 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +|}; + +type IntegerRecord7 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type IntegerRecord8 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type IntegerRecord9 record {| + int i1; + int i2; + int...; +|}; + +type IntegerRecord10 record {| + int...; +|}; + +type IntegerRecord11 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord12 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type IntegerRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type FloatRecord1 record { + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +}; + +type FloatRecord2 record {| + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +|}; + +type FloatRecord3 record {| + float f1; + float f4; + float f7; +|}; + +type FloatRecord4 record { + float f1; + float f4; + float f7; +}; + +type FloatRecord5 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +}; + +type FloatRecord6 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type FloatRecord7 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type FloatRecord8 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type FloatRecord9 record {| + float f1; + float f2; + float...; +|}; + +type FloatRecord10 record {| + float...; +|}; + +type FloatRecord11 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord12 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type FloatRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type DecimalRecord1 record { + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +}; + +type DecimalRecord2 record {| + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +|}; + +type DecimalRecord3 record {| + decimal d1; + decimal d4; + decimal d7; +|}; + +type DecimalRecord4 record { + decimal d1; + decimal d4; + decimal d7; +}; + +type DecimalRecord5 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +}; + +type DecimalRecord6 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type DecimalRecord7 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type DecimalRecord8 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type DecimalRecord9 record {| + decimal d1; + decimal d2; + decimal...; +|}; + +type DecimalRecord10 record {| + decimal...; +|}; + +type DecimalRecord11 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord12 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type DecimalRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type StringRecord1 record { + string s1; + string s2; + string s3; +}; + +type StringRecord2 record {| + string s1; + string s2; + string s3; +|}; + +type StringRecord3 record {| + string s1; + string s4; +|}; + +type StringRecord4 record { + string s1; + string s4; +}; + +type StringRecord5 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +}; + +type StringRecord6 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type StringRecord7 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type StringRecord8 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type StringRecord9 record {| + string s1; + string s2; + string...; +|}; + +type StringRecord10 record {| + string...; +|}; + +type StringRecord11 record {| + string s1; + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord12 record {| + string d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord15 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord16 record {| + string?...; +|}; + +type StringRecord17 record {| + int...; +|}; + +type StringRecord18 record {| + string b2; + int?...; +|}; + +type StringRecord19 record { + string s1 = ""; + string s2 = ""; +}; + +type StringRecord20 record {| + string s1 = ""; + string s2 = ""; +|}; + +type StringRecord21 record { +}; + +type StringRecord22 record {| + string s1 = ""; + string s2 = ""; + json...; +|}; + +type StringRecord23 record {| + json...; +|}; + +type JsonRecord1 record { + json j1; + json j2; + json j3; +}; + +type JsonRecord2 record {| + json j1; + json j2; + json j3; +|}; + +type JsonRecord3 record {| + json j1; + json j4; +|}; + +type JsonRecord4 record { + json j1; + json j4; +}; + +type JsonRecord5 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +}; + +type JsonRecord6 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +|}; + +type JsonRecord7 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +}; + +type JsonRecord8 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +|}; + +type JsonRecord9 record {| + json j1; + json j2; + json...; +|}; + +type JsonRecord10 record {| + json...; +|}; + +type JsonRecord11 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord12 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type JsonRecord13 record {| + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord14 record {| + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type AnydataRecord1 record { + anydata anydata1; + anydata anydata2; + anydata anydata3; +}; + +type AnydataRecord2 record {| + anydata anydata1; + anydata anydata2; + anydata anydata3; +|}; + +type AnydataRecord3 record {| + anydata anydata1; + anydata anydata4; +|}; + +type AnydataRecord4 record { + anydata anydata1; + anydata anydata4; +}; + +type AnydataRecord5 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +}; + +type AnydataRecord6 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type AnydataRecord7 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type AnydataRecord8 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type AnydataRecord9 record {| + anydata anydata1; + anydata anydata2; + anydata...; +|}; + +type AnydataRecord10 record {| + anydata...; +|}; + +type AnydataRecord11 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord12 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type AnydataRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type CustomRecord1 record { + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +}; + +type CustomRecord2 record {| + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +|}; + +type CustomRecord3 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +|}; + +type CustomRecord4 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +}; + +type CustomRecord5 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string defaultableField = ""; + string? nillableField = (); +}; + +type CustomRecord6 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type CustomRecord7 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type CustomRecord8 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type CustomRecord9 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string...; +|}; + +type CustomRecord10 record {| + string...; +|}; + +type CustomRecord11 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord12 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomRecord15 record {| + string '1; + string '2; +|}; + +type CustomRecord16 record {| + string '1; + string '2; + string '3; + string '4; +|}; + +type CustomRecord17 record { + string '1; + string '2; +}; + +type CustomRecord18 record { + string '1; + string '2; + string '3; + string '4; +}; + +type CustomRecord19 record { + string '1; + string '2; + string '3 = ""; + string '4 = ""; +}; + +type CustomRecord20 record { + string '1; +}; + +type CustomRecord21 record {| + string '1; + json...; +|}; + +type CustomRecord22 record {| + string '1; + string...; +|}; + +type CustomRecord23 record {| + string '1; + string a = ""; + string...; +|}; + +type CustomRecord24 record {| + string '1; + string '2 = ""; + string...; +|}; + +type CustomRecord25 record {| + int '1; + string...; +|}; + +type CustomRecord26 record {| + string '1; + int...; +|}; + +type CustomRecord27 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata a1; + json j1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord28 record { + string '1; +}; + +type CustomRecord29 record { + int '1; +}; + +type CustomRecord30 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord31 record {| + string '1; + string '6; +|}; + +type CustomRecord32 record {| + int '1; +|}; + +type CustomRecord33 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord34 record { + string '1; + string '6; + string '5 = ""; +}; + +type CustomRecord35 record { + string '1; + string '6; + string '9 = ""; +}; + +type CustomRecord36 record {| + string '1; + string '6; + string '9 = ""; +|}; + +type CustomRecord37 record {| + string '1; + string '6; + string '5 = ""; +|}; + +type CustomRecord38 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + string ...; +|}; + +type CustomRecord39 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + json ...; +|}; + +type CustomRecord40 record {| + string '5; + string '6; + json ...; +|}; + +type CustomRecord41 record {| + json ...; +|}; + +type CustomRecord42 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +|}; + +type CustomRecord43 record { + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +}; + +type CustomRecord44 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; + string ...; +|}; + +type CustomRecord45 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +|}; + +type CustomRecord46 record { + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +}; + +type CustomRecord47 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; + string ...; +|}; + +type CustomRecord48 record { + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +}; + +type CustomRecord49 record {| + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +|}; + +type CustomRecord50 record { + int H1; + float H4; +}; + +type CustomRecord51 record {| + int H1; + float H4; +|}; + +type CustomRecord52 record {| + string H1; + string H4; + string ...; +|}; + +type CustomRecord53 record {| + int H1; + float H4; + decimal ...; +|}; + +type CustomRecord54 record {| + string H1 = ""; + string H4; + string '1; +|}; + +type CustomRecord55 record {| + string H1 = ""; + string H4 = ""; + int '1 = 10; +|}; + +type CustomRecord56 record { + string H1 = ""; + string H4 = ""; + anydata '1 = 10; +}; + +type BooleanTuple1 [boolean, boolean, boolean, boolean]; + +type BooleanTuple2 [boolean, boolean]; + +type BooleanTuple3 [boolean, boolean...]; + +type BooleanTuple4 [boolean...]; + +type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; + +type NillableBooleanTuple6 [boolean?, boolean?]; + +type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; + +type NillableBooleanTuple8 [boolean?...]; + +type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; + +type NilTuple1 [(), (), ()]; + +type NilTuple2 [(), ()]; + +type NilTuple3 [(), ()...]; + +type NilTuple4 [()...]; + +type IntegerTuple1 [int, int, int, int, int, int]; + +type IntegerTuple2 [int, int]; + +type IntegerTuple3 [int, int...]; + +type IntegerTuple4 [int...]; + +type FloatTuple1 [float, float, float, float, float, float, float]; + +type FloatTuple2 [float, float]; + +type FloatTuple3 [float, float...]; + +type FloatTuple4 [float...]; + +type DecimalTuple1 [decimal, decimal, decimal, decimal]; + +type DecimalTuple2 [decimal, decimal]; + +type DecimalTuple3 [decimal, decimal...]; + +type DecimalTuple4 [decimal...]; + +type StringTuple1 [string, string, string, string]; + +type StringTuple2 [string, string]; + +type StringTuple3 [string, string...]; + +type StringTuple4 [string...]; + +type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata]; + +type AnydataTuple2 [anydata, anydata]; + +type AnydataTuple3 [anydata, anydata...]; + +type AnydataTuple4 [anydata...]; + +type JsonTuple1 [json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json]; + +type JsonTuple2 [json, json]; + +type JsonTuple3 [json, json...]; + +type JsonTuple4 [json...]; + +type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; + +type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; + +type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; + +type CustomTuple4 [string...]; + +type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; + +type CustomTuple6 [anydata...]; + +type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; + +type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; + +type IntegerArray1 int[]; + +type IntegerArray2 int[2]; + +type IntegerArray3 int[]; + +type IntegerArray4 int[2]; + +type IntegerArray5 int[3]; + +type IntegerArray6 int[4]; + +type StringArray string[]; + +type NillableStringArray string?[]; + +type NillableIntOrUnionStringArray (int|string?)[]; + +type StringArray1 string[]; + +type StringArray2 string[2]; + +type StringArray3 string[]; + +type StringArray4 string[2]; + +type StringArray5 string[3]; + +type StringArray6 string[4]; + +type FloatArray1 float[]; + +type FloatArray2 float[2]; + +type FloatArray3 float[]; + +type FloatArray4 float[2]; + +type FloatArray5 float[3]; + +type FloatArray6 float[4]; + +type DecimalArray1 decimal[]; + +type DecimalArray2 decimal[2]; + +type DecimalArray3 decimal[]; + +type DecimalArray4 decimal[2]; + +type DecimalArray5 decimal[3]; + +type DecimalArray6 decimal[4]; + +type BooleanArray boolean[]; + +type NillableBooleanArray boolean?[]; + +type NillableIntOrUnionBooleanArray (int|boolean?)[]; + +type BooleanArray2 boolean[2]; + +type BooleanArray3 boolean[3]; + +type BooleanArray4 boolean[]; + +type BooleanArray5 boolean[2]; + +type BooleanArray6 boolean[4]; + +type NilArray1 ()[]; + +type NilArray2 ()[2]; + +type NilArray3 ()[]; + +type NilArray4 ()[2]; + +type NilArray5 ()[3]; + +type NilArray6 ()[4]; + +type JsonArray1 json[]; + +type JsonArray2 json[2]; + +type JsonArray3 json[]; + +type JsonArray4 json[2]; + +type JsonArray5 json[3]; + +type JsonArray6 json[4]; + +type AnydataArray1 anydata[]; + +type AnydataArray2 anydata[2]; + +type AnydataArray3 anydata[]; + +type AnydataArray4 anydata[2]; + +type AnydataArray5 anydata[3]; + +type AnydataArray6 anydata[4]; + +type CustomArray1 CustomTuple2[]; + +type CustomArray2 CustomTuple2[2]; + +type CustomArray3 CustomTuple2[]; + +type CustomArray4 CustomTuple2[2]; + +type CustomArray5 CustomTuple2[3]; + +type CustomArray6 CustomTuple2[4]; + +type IntegerMap map; + +type StringMap map; + +type NillableIntUnionStringMap map; + +type IntUnionStringMap map; + +type DecimalMap map; + +type FloatMap map; + +type BooleanMap map; + +type NillableBooleanMap map; + +type NillableIntUnionBooleanMap map; + +type IntUnionBooleanMap map; + +type NilMap map<()>; + +type JsonMap map; + +type AnydataMap map; + +type CustomMap map; + +type BooleanRecord1Array BooleanRecord1[]; + +type ClosedBooleanRecord1Array BooleanRecord1[3]; + +type BooleanRecord2Array BooleanRecord2[]; + +type ClosedBooleanRecord2Array BooleanRecord2[3]; + +type BooleanRecord3Array BooleanRecord3[]; + +type ClosedBooleanRecord3Array BooleanRecord3[3]; + +type BooleanRecord4Array BooleanRecord4[]; + +type ClosedBooleanRecord4Array BooleanRecord4[3]; + +type BooleanRecord5Array BooleanRecord5[]; + +type ClosedBooleanRecord5Array BooleanRecord5[3]; + +type BooleanRecord6Array BooleanRecord6[]; + +type ClosedBooleanRecord6Array BooleanRecord6[3]; + +type BooleanRecord7Array BooleanRecord7[]; + +type ClosedBooleanRecord7Array BooleanRecord7[3]; + +type BooleanRecord8Array BooleanRecord8[]; + +type ClosedBooleanRecord8Array BooleanRecord8[3]; + +type BooleanRecord9Array BooleanRecord9[]; + +type ClosedBooleanRecord9Array BooleanRecord9[3]; + +type BooleanRecord10Array BooleanRecord10[]; + +type ClosedBooleanRecord10Array BooleanRecord10[3]; + +type BooleanRecord11Array BooleanRecord11[]; + +type ClosedBooleanRecord11Array BooleanRecord11[3]; + +type BooleanRecord12Array BooleanRecord12[]; + +type ClosedBooleanRecord12Array BooleanRecord12[3]; + +type BooleanRecord13Array BooleanRecord13[]; + +type ClosedBooleanRecord13Array BooleanRecord13[3]; + +type BooleanRecord14Array BooleanRecord14[]; + +type ClosedBooleanRecord14Array BooleanRecord14[3]; + +type BooleanRecord15Array BooleanRecord15[]; + +type ClosedBooleanRecord15Array BooleanRecord15[3]; + +type BooleanRecord16Array BooleanRecord16[]; + +type ClosedBooleanRecord16Array BooleanRecord16[3]; + +type BooleanRecord17Array BooleanRecord17[]; + +type ClosedBooleanRecord17Array BooleanRecord17[3]; + +type BooleanRecord18Array BooleanRecord18[]; + +type ClosedBooleanRecord18Array BooleanRecord18[3]; + +type NilRecord1Array NilRecord1[]; + +type ClosedNilRecord1Array NilRecord1[3]; + +type NilRecord2Array NilRecord2[]; + +type ClosedNilRecord2Array NilRecord2[3]; + +type NilRecord3Array NilRecord3[]; + +type ClosedNilRecord3Array NilRecord3[3]; + +type NilRecord4Array NilRecord4[]; + +type ClosedNilRecord4Array NilRecord4[3]; + +type NilRecord5Array NilRecord5[]; + +type ClosedNilRecord5Array NilRecord5[3]; + +type NilRecord6Array NilRecord6[]; + +type ClosedNilRecord6Array NilRecord6[3]; + +type NilRecord7Array NilRecord7[]; + +type ClosedNilRecord7Array NilRecord7[3]; + +type NilRecord8Array NilRecord8[]; + +type ClosedNilRecord8Array NilRecord8[3]; + +type NilRecord9Array NilRecord9[]; + +type ClosedNilRecord9Array NilRecord9[3]; + +type NilRecord10Array NilRecord10[]; + +type ClosedNilRecord10Array NilRecord10[3]; + +type NilRecord11Array NilRecord11[]; + +type ClosedNilRecord11Array NilRecord11[3]; + +type NilRecord12Array NilRecord12[]; + +type ClosedNilRecord12Array NilRecord12[3]; + +type NilRecord13Array NilRecord13[]; + +type ClosedNilRecord13Array NilRecord13[3]; + +type NilRecord14Array NilRecord14[]; + +type ClosedNilRecord14Array NilRecord14[3]; + +type IntegerRecord1Array IntegerRecord1[]; + +type ClosedIntegerRecord1Array IntegerRecord1[3]; + +type IntegerRecord2Array IntegerRecord2[]; + +type ClosedIntegerRecord2Array IntegerRecord2[3]; + +type IntegerRecord3Array IntegerRecord3[]; + +type ClosedIntegerRecord3Array IntegerRecord3[3]; + +type IntegerRecord4Array IntegerRecord4[]; + +type ClosedIntegerRecord4Array IntegerRecord4[3]; + +type IntegerRecord5Array IntegerRecord5[]; + +type ClosedIntegerRecord5Array IntegerRecord5[3]; + +type IntegerRecord6Array IntegerRecord6[]; + +type ClosedIntegerRecord6Array IntegerRecord6[3]; + +type IntegerRecord7Array IntegerRecord7[]; + +type ClosedIntegerRecord7Array IntegerRecord7[3]; + +type IntegerRecord8Array IntegerRecord8[]; + +type ClosedIntegerRecord8Array IntegerRecord8[3]; + +type IntegerRecord9Array IntegerRecord9[]; + +type ClosedIntegerRecord9Array IntegerRecord9[3]; + +type IntegerRecord10Array IntegerRecord10[]; + +type ClosedIntegerRecord10Array IntegerRecord10[3]; + +type IntegerRecord11Array IntegerRecord11[]; + +type ClosedIntegerRecord11Array IntegerRecord11[3]; + +type IntegerRecord12Array IntegerRecord12[]; + +type ClosedIntegerRecord12Array IntegerRecord12[3]; + +type IntegerRecord13Array IntegerRecord13[]; + +type ClosedIntegerRecord13Array IntegerRecord13[3]; + +type IntegerRecord14Array IntegerRecord14[]; + +type ClosedIntegerRecord14Array IntegerRecord14[3]; + +type FloatRecord1Array FloatRecord1[]; + +type ClosedFloatRecord1Array FloatRecord1[3]; + +type FloatRecord2Array FloatRecord2[]; + +type ClosedFloatRecord2Array FloatRecord2[3]; + +type FloatRecord3Array FloatRecord3[]; + +type ClosedFloatRecord3Array FloatRecord3[3]; + +type FloatRecord4Array FloatRecord4[]; + +type ClosedFloatRecord4Array FloatRecord4[3]; + +type FloatRecord5Array FloatRecord5[]; + +type ClosedFloatRecord5Array FloatRecord5[3]; + +type FloatRecord6Array FloatRecord6[]; + +type ClosedFloatRecord6Array FloatRecord6[3]; + +type FloatRecord7Array FloatRecord7[]; + +type ClosedFloatRecord7Array FloatRecord7[3]; + +type FloatRecord8Array FloatRecord8[]; + +type ClosedFloatRecord8Array FloatRecord8[3]; + +type FloatRecord9Array FloatRecord9[]; + +type ClosedFloatRecord9Array FloatRecord9[3]; + +type FloatRecord10Array FloatRecord10[]; + +type ClosedFloatRecord10Array FloatRecord10[3]; + +type FloatRecord11Array FloatRecord11[]; + +type ClosedFloatRecord11Array FloatRecord11[3]; + +type FloatRecord12Array FloatRecord12[]; + +type ClosedFloatRecord12Array FloatRecord12[3]; + +type FloatRecord13Array FloatRecord13[]; + +type ClosedFloatRecord13Array FloatRecord13[3]; + +type FloatRecord14Array FloatRecord14[]; + +type ClosedFloatRecord14Array FloatRecord14[3]; + +type DecimalRecord1Array DecimalRecord1[]; + +type ClosedDecimalRecord1Array DecimalRecord1[3]; + +type DecimalRecord2Array DecimalRecord2[]; + +type ClosedDecimalRecord2Array DecimalRecord2[3]; + +type DecimalRecord3Array DecimalRecord3[]; + +type ClosedDecimalRecord3Array DecimalRecord3[3]; + +type DecimalRecord4Array DecimalRecord4[]; + +type ClosedDecimalRecord4Array DecimalRecord4[3]; + +type DecimalRecord5Array DecimalRecord5[]; + +type ClosedDecimalRecord5Array DecimalRecord5[3]; + +type DecimalRecord6Array DecimalRecord6[]; + +type ClosedDecimalRecord6Array DecimalRecord6[3]; + +type DecimalRecord7Array DecimalRecord7[]; + +type ClosedDecimalRecord7Array DecimalRecord7[3]; + +type DecimalRecord8Array DecimalRecord8[]; + +type ClosedDecimalRecord8Array DecimalRecord8[3]; + +type DecimalRecord9Array DecimalRecord9[]; + +type ClosedDecimalRecord9Array DecimalRecord9[3]; + +type DecimalRecord10Array DecimalRecord10[]; + +type ClosedDecimalRecord10Array DecimalRecord10[3]; + +type DecimalRecord11Array DecimalRecord11[]; + +type ClosedDecimalRecord11Array DecimalRecord11[3]; + +type DecimalRecord12Array DecimalRecord12[]; + +type ClosedDecimalRecord12Array DecimalRecord12[3]; + +type DecimalRecord13Array DecimalRecord13[]; + +type ClosedDecimalRecord13Array DecimalRecord13[3]; + +type DecimalRecord14Array DecimalRecord14[]; + +type ClosedDecimalRecord14Array DecimalRecord14[3]; + +type StringRecord1Array StringRecord1[]; + +type ClosedStringRecord1Array StringRecord1[3]; + +type StringRecord2Array StringRecord2[]; + +type ClosedStringRecord2Array StringRecord2[3]; + +type StringRecord3Array StringRecord3[]; + +type ClosedStringRecord3Array StringRecord3[3]; + +type StringRecord4Array StringRecord4[]; + +type ClosedStringRecord4Array StringRecord4[3]; + +type StringRecord5Array StringRecord5[]; + +type ClosedStringRecord5Array StringRecord5[3]; + +type StringRecord6Array StringRecord6[]; + +type ClosedStringRecord6Array StringRecord6[3]; + +type StringRecord7Array StringRecord7[]; + +type ClosedStringRecord7Array StringRecord7[3]; + +type StringRecord8Array StringRecord8[]; + +type ClosedStringRecord8Array StringRecord8[3]; + +type StringRecord9Array StringRecord9[]; + +type ClosedStringRecord9Array StringRecord9[3]; + +type StringRecord10Array StringRecord10[]; + +type ClosedStringRecord10Array StringRecord10[3]; + +type StringRecord11Array StringRecord11[]; + +type ClosedStringRecord11Array StringRecord11[3]; + +type StringRecord12Array StringRecord12[]; + +type ClosedStringRecord12Array StringRecord12[3]; + +type StringRecord13Array StringRecord13[]; + +type ClosedStringRecord13Array StringRecord13[3]; + +type StringRecord14Array StringRecord14[]; + +type ClosedStringRecord14Array StringRecord14[3]; + +type StringRecord15Array StringRecord15[]; + +type StringRecord16Array StringRecord16[]; + +type StringRecord17Array StringRecord17[]; + +type StringRecord18Array StringRecord18[]; + +type StringRecord19Array StringRecord19[]; + +type StringRecord20Array StringRecord20[]; + +type StringRecord21Array StringRecord21[]; + +type StringRecord22Array StringRecord22[]; + +type StringRecord23Array StringRecord23[]; + +type JsonRecord1Array JsonRecord1[]; + +type ClosedJsonRecord1Array JsonRecord1[3]; + +type JsonRecord2Array JsonRecord2[]; + +type ClosedJsonRecord2Array JsonRecord2[3]; + +type JsonRecord3Array JsonRecord3[]; + +type ClosedJsonRecord3Array JsonRecord3[3]; + +type JsonRecord4Array JsonRecord4[]; + +type ClosedJsonRecord4Array JsonRecord4[3]; + +type JsonRecord5Array JsonRecord5[]; + +type ClosedJsonRecord5Array JsonRecord5[3]; + +type JsonRecord6Array JsonRecord6[]; + +type ClosedJsonRecord6Array JsonRecord6[3]; + +type JsonRecord7Array JsonRecord7[]; + +type ClosedJsonRecord7Array JsonRecord7[3]; + +type JsonRecord8Array JsonRecord8[]; + +type ClosedJsonRecord8Array JsonRecord8[3]; + +type JsonRecord9Array JsonRecord9[]; + +type ClosedJsonRecord9Array JsonRecord9[3]; + +type JsonRecord10Array JsonRecord10[]; + +type ClosedJsonRecord10Array JsonRecord10[3]; + +type JsonRecord11Array JsonRecord11[]; + +type ClosedJsonRecord11Array JsonRecord11[3]; + +type JsonRecord12Array JsonRecord12[]; + +type ClosedJsonRecord12Array JsonRecord12[3]; + +type JsonRecord13Array JsonRecord13[]; + +type ClosedJsonRecord13Array JsonRecord13[3]; + +type JsonRecord14Array JsonRecord14[]; + +type ClosedJsonRecord14Array JsonRecord14[3]; + +type AnydataRecord1Array AnydataRecord1[]; + +type ClosedAnydataRecord1Array AnydataRecord1[3]; + +type AnydataRecord2Array AnydataRecord2[]; + +type ClosedAnydataRecord2Array AnydataRecord2[3]; + +type AnydataRecord3Array AnydataRecord3[]; + +type ClosedAnydataRecord3Array AnydataRecord3[3]; + +type AnydataRecord4Array AnydataRecord4[]; + +type ClosedAnydataRecord4Array AnydataRecord4[3]; + +type AnydataRecord5Array AnydataRecord5[]; + +type ClosedAnydataRecord5Array AnydataRecord5[3]; + +type AnydataRecord6Array AnydataRecord6[]; + +type ClosedAnydataRecord6Array AnydataRecord6[3]; + +type AnydataRecord7Array AnydataRecord7[]; + +type ClosedAnydataRecord7Array AnydataRecord7[3]; + +type AnydataRecord8Array AnydataRecord8[]; + +type ClosedAnydataRecord8Array AnydataRecord8[3]; + +type AnydataRecord9Array AnydataRecord9[]; + +type ClosedAnydataRecord9Array AnydataRecord9[3]; + +type AnydataRecord10Array AnydataRecord10[]; + +type ClosedAnydataRecord10Array AnydataRecord10[3]; + +type AnydataRecord11Array AnydataRecord11[]; + +type ClosedAnydataRecord11Array AnydataRecord11[3]; + +type AnydataRecord12Array AnydataRecord12[]; + +type ClosedAnydataRecord12Array AnydataRecord12[3]; + +type AnydataRecord13Array AnydataRecord13[]; + +type ClosedAnydataRecord13Array AnydataRecord13[3]; + +type AnydataRecord14Array AnydataRecord14[]; + +type ClosedAnydataRecord14Array AnydataRecord14[3]; + +type CustomRecord1Array CustomRecord1[]; + +type ClosedCustomRecord1Array CustomRecord1[3]; + +type CustomRecord2Array CustomRecord2[]; + +type ClosedCustomRecord2Array CustomRecord2[3]; + +type CustomRecord3Array CustomRecord3[]; + +type ClosedCustomRecord3Array CustomRecord3[3]; + +type CustomRecord4Array CustomRecord4[]; + +type ClosedCustomRecord4Array CustomRecord4[3]; + +type CustomRecord5Array CustomRecord5[]; + +type ClosedCustomRecord5Array CustomRecord5[3]; + +type CustomRecord6Array CustomRecord6[]; + +type ClosedCustomRecord6Array CustomRecord6[3]; + +type CustomRecord7Array CustomRecord7[]; + +type ClosedCustomRecord7Array CustomRecord7[3]; + +type CustomRecord8Array CustomRecord8[]; + +type ClosedCustomRecord8Array CustomRecord8[3]; + +type CustomRecord9Array CustomRecord9[]; + +type ClosedCustomRecord9Array CustomRecord9[3]; + +type CustomRecord10Array CustomRecord10[]; + +type ClosedCustomRecord10Array CustomRecord10[3]; + +type CustomRecord11Array CustomRecord11[]; + +type ClosedCustomRecord11Array CustomRecord11[3]; + +type CustomRecord12Array CustomRecord12[]; + +type ClosedCustomRecord12Array CustomRecord12[3]; + +type CustomRecord13Array CustomRecord13[]; + +type ClosedCustomRecord13Array CustomRecord13[3]; + +type CustomRecord14Array CustomRecord14[]; + +type ClosedCustomRecord14Array CustomRecord14[3]; + +type CustomRecord15Array CustomRecord15[]; + +type CustomRecord16Array CustomRecord16[]; + +type CustomRecord17Array CustomRecord17[]; + +type CustomRecord18Array CustomRecord18[]; + +type CustomRecord19Array CustomRecord19[]; + +type CustomRecord20Array CustomRecord20[]; + +type CustomRecord21Array CustomRecord21[]; + +type CustomRecord22Array CustomRecord22[]; + +type CustomRecord23Array CustomRecord23[]; + +type CustomRecord24Array CustomRecord24[]; + +type CustomRecord25Array CustomRecord25[]; + +type CustomRecord26Array CustomRecord26[]; + +type CustomRecord27Array CustomRecord27[]; +type CustomRecord28Array CustomRecord28[]; +type CustomRecord29Array CustomRecord29[]; +type CustomRecord30Array CustomRecord30[]; +type CustomRecord31Array CustomRecord31[]; +type CustomRecord32Array CustomRecord32[]; +type CustomRecord33Array CustomRecord33[]; +type CustomRecord34Array CustomRecord34[]; +type CustomRecord35Array CustomRecord35[]; +type CustomRecord36Array CustomRecord36[]; +type CustomRecord37Array CustomRecord37[]; +type CustomRecord38Array CustomRecord38[]; +type CustomRecord39Array CustomRecord39[]; +type CustomRecord40Array CustomRecord40[]; +type CustomRecord41Array CustomRecord41[]; +type CustomRecord42Array CustomRecord42[]; +type CustomRecord43Array CustomRecord43[]; +type CustomRecord44Array CustomRecord44[]; +type CustomRecord45Array CustomRecord45[]; +type CustomRecord46Array CustomRecord46[]; +type CustomRecord47Array CustomRecord47[]; +type CustomRecord48Array CustomRecord48[]; +type CustomRecord49Array CustomRecord49[]; +type CustomRecord50Array CustomRecord50[]; +type CustomRecord51Array CustomRecord51[]; +type CustomRecord52Array CustomRecord52[]; +type CustomRecord53Array CustomRecord53[]; +type CustomRecord54Array CustomRecord54[]; +type CustomRecord55Array CustomRecord55[]; +type CustomRecord56Array CustomRecord56[]; + +type BooleanTuple1Array BooleanTuple1[]; + +type ClosedBooleanTuple1Array BooleanTuple1[3]; + +type BooleanTuple2Array BooleanTuple2[]; + +type ClosedBooleanTuple2Array BooleanTuple2[3]; + +type BooleanTuple3Array BooleanTuple3[]; + +type ClosedBooleanTuple3Array BooleanTuple3[3]; + +type BooleanTuple4Array BooleanTuple4[]; + +type ClosedBooleanTuple4Array BooleanTuple4[3]; + +type NillableBooleanTuple5Array NillableBooleanTuple5[]; + +type NillableBooleanTuple6Array NillableBooleanTuple6[]; + +type NillableBooleanTuple7Array NillableBooleanTuple7[]; + +type NillableBooleanTuple8Array NillableBooleanTuple8[]; + +type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; + +type NilTuple1Array NilTuple1[]; + +type ClosedNilTuple1Array NilTuple1[3]; + +type NilTuple2Array NilTuple2[]; + +type ClosedNilTuple2Array NilTuple2[3]; + +type NilTuple3Array NilTuple3[]; + +type ClosedNilTuple3Array NilTuple3[3]; + +type NilTuple4Array NilTuple4[]; + +type ClosedNilTuple4Array NilTuple4[3]; + +type IntegerTuple1Array IntegerTuple1[]; + +type ClosedIntegerTuple1Array IntegerTuple1[3]; + +type IntegerTuple2Array IntegerTuple2[]; + +type ClosedIntegerTuple2Array IntegerTuple2[3]; + +type IntegerTuple3Array IntegerTuple3[]; + +type ClosedIntegerTuple3Array IntegerTuple3[3]; + +type IntegerTuple4Array IntegerTuple4[]; + +type ClosedIntegerTuple4Array IntegerTuple4[3]; + +type FloatTuple1Array FloatTuple1[]; + +type ClosedFloatTuple1Array FloatTuple1[3]; + +type FloatTuple2Array FloatTuple2[]; + +type ClosedFloatTuple2Array FloatTuple2[3]; + +type FloatTuple3Array FloatTuple3[]; + +type ClosedFloatTuple3Array FloatTuple3[3]; + +type FloatTuple4Array FloatTuple4[]; + +type ClosedFloatTuple4Array FloatTuple4[3]; + +type DecimalTuple1Array DecimalTuple1[]; + +type ClosedDecimalTuple1Array DecimalTuple1[3]; + +type DecimalTuple2Array DecimalTuple2[]; + +type ClosedDecimalTuple2Array DecimalTuple2[3]; + +type DecimalTuple3Array DecimalTuple3[]; + +type ClosedDecimalTuple3Array DecimalTuple3[3]; + +type DecimalTuple4Array DecimalTuple4[]; + +type ClosedDecimalTuple4Array DecimalTuple4[3]; + +type StringTuple1Array StringTuple1[]; + +type ClosedStringTuple1Array StringTuple1[3]; + +type StringTuple2Array StringTuple2[]; + +type ClosedStringTuple2Array StringTuple2[3]; + +type StringTuple3Array StringTuple3[]; + +type ClosedStringTuple3Array StringTuple3[3]; + +type StringTuple4Array StringTuple4[]; + +type ClosedStringTuple4Array StringTuple4[3]; + +type AnydataTuple1Array AnydataTuple1[]; + +type ClosedAnydataTuple1Array AnydataTuple1[3]; + +type AnydataTuple2Array AnydataTuple2[]; + +type ClosedAnydataTuple2Array AnydataTuple2[3]; + +type AnydataTuple3Array AnydataTuple3[]; + +type ClosedAnydataTuple3Array AnydataTuple3[3]; + +type AnydataTuple4Array AnydataTuple4[]; + +type ClosedAnydataTuple4Array AnydataTuple4[3]; + +type JsonTuple1Array JsonTuple1[]; + +type ClosedJsonTuple1Array JsonTuple1[3]; + +type JsonTuple2Array JsonTuple2[]; + +type ClosedJsonTuple2Array JsonTuple2[3]; + +type JsonTuple3Array JsonTuple3[]; + +type ClosedJsonTuple3Array JsonTuple3[3]; + +type JsonTuple4Array JsonTuple4[]; + +type ClosedJsonTuple4Array JsonTuple4[3]; + +type CustomTuple1Array CustomTuple1[]; + +type ClosedCustomTuple1Array CustomTuple1[3]; + +type CustomTuple2Array CustomTuple2[]; + +type ClosedCustomTuple2Array CustomTuple2[3]; + +type CustomTuple3Array CustomTuple3[]; + +type ClosedCustomTuple3Array CustomTuple3[3]; + +type CustomTuple4Array CustomTuple4[]; + +type ClosedCustomTuple4Array CustomTuple4[3]; + +type CustomTuple5Array CustomTuple5[]; + +type ClosedCustomTuple5Array CustomTuple5[3]; + +type CustomTuple6Array CustomTuple6[]; + +type CustomTuple7Array CustomTuple7[]; + +type CustomTuple8Array CustomTuple8[]; + +type ClosedCustomTuple6Array CustomTuple6[3]; + +type IntegerArray1Array IntegerArray1[]; + +type ClosedIntegerArray1Array IntegerArray1[3]; + +type IntegerArray2Array IntegerArray2[]; + +type ClosedIntegerArray2Array IntegerArray2[3]; + +type IntegerArray3Array IntegerArray3[]; + +type ClosedIntegerArray3Array IntegerArray3[3]; + +type IntegerArray4Array IntegerArray4[]; + +type ClosedIntegerArray4Array IntegerArray4[3]; + +type IntegerArray5Array IntegerArray5[]; + +type ClosedIntegerArray5Array IntegerArray5[3]; + +type IntegerArray6Array IntegerArray5[]; + +type ClosedIntegerArray6Array IntegerArray5[3]; + +type StringArray1Array StringArray1[]; + +type StringArrayArray StringArray[]; + +type NillableStringArrayArray NillableStringArray[]; + +type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; + +type ClosedStringArray1Array StringArray1[3]; + +type StringArray2Array StringArray2[]; + +type ClosedStringArray2Array StringArray2[3]; + +type StringArray3Array StringArray3[]; + +type ClosedStringArray3Array StringArray3[3]; + +type StringArray4Array StringArray4[]; + +type ClosedStringArray4Array StringArray4[3]; + +type StringArray5Array StringArray5[]; + +type ClosedStringArray5Array StringArray5[3]; + +type StringArray6Array StringArray5[]; + +type ClosedStringArray6Array StringArray5[3]; + +type FloatArray1Array FloatArray1[]; + +type ClosedFloatArray1Array FloatArray1[3]; + +type FloatArray2Array FloatArray2[]; + +type ClosedFloatArray2Array FloatArray2[3]; + +type FloatArray3Array FloatArray3[]; + +type ClosedFloatArray3Array FloatArray3[3]; + +type FloatArray4Array FloatArray4[]; + +type ClosedFloatArray4Array FloatArray4[3]; + +type FloatArray5Array FloatArray5[]; + +type ClosedFloatArray5Array FloatArray5[3]; + +type FloatArray6Array FloatArray5[]; + +type ClosedFloatArray6Array FloatArray5[3]; + +type DecimalArray1Array DecimalArray1[]; + +type ClosedDecimalArray1Array DecimalArray1[3]; + +type DecimalArray2Array DecimalArray2[]; + +type ClosedDecimalArray2Array DecimalArray2[3]; + +type DecimalArray3Array DecimalArray3[]; + +type ClosedDecimalArray3Array DecimalArray3[3]; + +type DecimalArray4Array DecimalArray4[]; + +type ClosedDecimalArray4Array DecimalArray4[3]; + +type DecimalArray5Array DecimalArray5[]; + +type ClosedDecimalArray5Array DecimalArray5[3]; + +type DecimalArray6Array DecimalArray5[]; + +type ClosedDecimalArray6Array DecimalArray5[3]; + +type BooleanArrayArray BooleanArray[]; + +type ClosedBooleanArrayArray BooleanArray[3]; + +type NillableBooleanArrayArray NillableBooleanArray[]; + +type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; + +type BooleanArray2Array BooleanArray2[]; + +type ClosedBooleanArray2Array BooleanArray2[3]; + +type BooleanArray3Array BooleanArray3[]; + +type ClosedBooleanArray3Array BooleanArray3[3]; + +type BooleanArray4Array BooleanArray4[]; + +type ClosedBooleanArray4Array BooleanArray4[3]; + +type BooleanArray5Array BooleanArray5[]; + +type ClosedBooleanArray5Array BooleanArray5[3]; + +type BooleanArray6Array BooleanArray5[]; + +type ClosedBooleanArray6Array BooleanArray5[3]; + +type NilArray1Array NilArray1[]; + +type ClosedNilArray1Array NilArray1[3]; + +type NilArray2Array NilArray2[]; + +type ClosedNilArray2Array NilArray2[3]; + +type NilArray3Array NilArray3[]; + +type ClosedNilArray3Array NilArray3[3]; + +type NilArray4Array NilArray4[]; + +type ClosedNilArray4Array NilArray4[3]; + +type NilArray5Array NilArray5[]; + +type ClosedNilArray5Array NilArray5[3]; + +type NilArray6Array NilArray5[]; + +type ClosedNilArray6Array NilArray5[3]; + +type JsonArray1Array JsonArray1[]; + +type ClosedJsonArray1Array JsonArray1[3]; + +type JsonArray2Array JsonArray2[]; + +type ClosedJsonArray2Array JsonArray2[3]; + +type JsonArray3Array JsonArray3[]; + +type ClosedJsonArray3Array JsonArray3[3]; + +type JsonArray4Array JsonArray4[]; + +type ClosedJsonArray4Array JsonArray4[3]; + +type JsonArray5Array JsonArray5[]; + +type ClosedJsonArray5Array JsonArray5[3]; + +type JsonArray6Array JsonArray5[]; + +type ClosedJsonArray6Array JsonArray5[3]; + +type AnydataArray1Array AnydataArray1[]; + +type ClosedAnydataArray1Array AnydataArray1[3]; + +type AnydataArray2Array AnydataArray2[]; + +type ClosedAnydataArray2Array AnydataArray2[3]; + +type AnydataArray3Array AnydataArray3[]; + +type ClosedAnydataArray3Array AnydataArray3[3]; + +type AnydataArray4Array AnydataArray4[]; + +type ClosedAnydataArray4Array AnydataArray4[3]; + +type AnydataArray5Array AnydataArray5[]; + +type ClosedAnydataArray5Array AnydataArray5[3]; + +type AnydataArray6Array AnydataArray5[]; + +type ClosedAnydataArray6Array AnydataArray5[3]; + +type CustomArray1Array CustomArray1[]; + +type ClosedCustomArray1Array CustomArray1[3]; + +type CustomArray2Array CustomArray2[]; + +type ClosedCustomArray2Array CustomArray2[3]; + +type CustomArray3Array CustomArray3[]; + +type ClosedCustomArray3Array CustomArray3[3]; + +type CustomArray4Array CustomArray4[]; + +type ClosedCustomArray4Array CustomArray4[3]; + +type CustomArray5Array CustomArray5[]; + +type ClosedCustomArray5Array CustomArray5[3]; + +type CustomArray6Array CustomArray5[]; + +type ClosedCustomArray6Array CustomArray5[3]; + +type IntegerMapArray IntegerMap[]; + +type ClosedIntegerMapArray IntegerMap[3]; + +type StringMapArray StringMap[]; + +type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; + +type IntUnionStringMapArray IntUnionStringMap[]; + +type ClosedStringMapArray StringMap[3]; + +type DecimalMapArray DecimalMap[]; + +type ClosedDecimalMapArray DecimalMap[3]; + +type FloatMapArray FloatMap[]; + +type ClosedFloatMapArray FloatMap[3]; + +type BooleanMapArray BooleanMap[]; + +type NillableBooleanMapArray NillableBooleanMap[]; + +type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; + +type IntUnionBooleanMapArray IntUnionBooleanMap[]; + +type ClosedBooleanMapArray BooleanMap[3]; + +type NilMapArray NilMap[]; + +type ClosedNilMapArray NilMap[3]; + +type JsonMapArray JsonMap[]; + +type ClosedJsonMapArray JsonMap[3]; + +type AnydataMapArray AnydataMap[]; + +type ClosedAnydataMapArray AnydataMap[3]; + +type CustomMapArray CustomMap[]; + +type ClosedCustomMapArray CustomMap[3]; diff --git a/ballerina-tests/parse-string-record-types-tests/.gitignore b/ballerina-tests/parse-string-record-types-tests/.gitignore new file mode 100644 index 0000000..d5fc29a --- /dev/null +++ b/ballerina-tests/parse-string-record-types-tests/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/ballerina-tests/parse-string-record-types-tests/Ballerina.toml b/ballerina-tests/parse-string-record-types-tests/Ballerina.toml new file mode 100644 index 0000000..a9d8337 --- /dev/null +++ b/ballerina-tests/parse-string-record-types-tests/Ballerina.toml @@ -0,0 +1,13 @@ +[package] +org = "ballerina" +name = "parse_string_record_types_tests" +version = "0.1.0" + +[[dependency]] +org = "ballerina" +name = "csv_commons" +repository = "local" +version = "0.1.0" + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina-tests/parse-string-record-types-tests/Dependencies.toml b/ballerina-tests/parse-string-record-types-tests/Dependencies.toml new file mode 100644 index 0000000..7e5d364 --- /dev/null +++ b/ballerina-tests/parse-string-record-types-tests/Dependencies.toml @@ -0,0 +1,98 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0" + +[[package]] +org = "ballerina" +name = "csv_commons" +version = "0.1.0" +scope = "testOnly" +modules = [ + {org = "ballerina", packageName = "csv_commons", moduleName = "csv_commons"} +] + +[[package]] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "parse_string_record_types_tests" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "csv_commons"}, + {org = "ballerina", name = "data.csv"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerina", packageName = "parse_string_record_types_tests", moduleName = "parse_string_record_types_tests"} +] + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + diff --git a/ballerina/tests/parse_string_to_map_tests copy.bal b/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests copy.bal similarity index 56% rename from ballerina/tests/parse_string_to_map_tests copy.bal rename to ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests copy.bal index 0ae1bcd..8e95f6a 100644 --- a/ballerina/tests/parse_string_to_map_tests copy.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests copy.bal @@ -1,397 +1,408 @@ +import ballerina/data.csv as csv; import ballerina/test; @test:Config function testFromCsvStringWithTypeForStringAndMapAsExpectedType() { - BooleanMapArray|Error bv1bma = parseStringToRecord(csvStringWithBooleanValues1); + BooleanMapArray|csv:Error bv1bma = csv:parseStringToRecord(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|Error bv2bma = parseStringToRecord(csvStringWithBooleanValues2); + BooleanMapArray|csv:Error bv2bma = csv:parseStringToRecord(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|Error bv3bma = parseStringToRecord(csvStringWithBooleanValues3); + BooleanMapArray|csv:Error bv3bma = csv:parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false}, {b1: true, b2: true, b3: false} ]); - BooleanMapArray|Error bv4bma = parseStringToRecord(csvStringWithBooleanValues4); + BooleanMapArray|csv:Error bv4bma = csv:parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bma, [ {b1: true, b4: false}, {b1: true, b4: false} ]); - BooleanMapArray|Error bv5bma = parseStringToRecord(csvStringWithBooleanValues5); + BooleanMapArray|csv:Error bv5bma = csv:parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - BooleanMapArray|Error bv6bma = parseStringToRecord(csvStringWithBooleanValues6); + BooleanMapArray|csv:Error bv6bma = csv:parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bma, [ {} ]); - BooleanMapArray|Error bv7bma = parseStringToRecord(csvStringWithBooleanValues7); + BooleanMapArray|csv:Error bv7bma = csv:parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bma, [ {b1, b2, b4} ]); - NillableBooleanMapArray|Error bv1bnbma = parseStringToRecord(csvStringWithBooleanValues1); + NillableBooleanMapArray|csv:Error bv1bnbma = csv:parseStringToRecord(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|Error bv2bnbma = parseStringToRecord(csvStringWithBooleanValues2); + NillableBooleanMapArray|csv:Error bv2bnbma = csv:parseStringToRecord(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|Error bv3bnbma = parseStringToRecord(csvStringWithBooleanValues3); + NillableBooleanMapArray|csv:Error bv3bnbma = csv:parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bnbma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - NillableBooleanMapArray|Error bv4bnbma = parseStringToRecord(csvStringWithBooleanValues4); + NillableBooleanMapArray|csv:Error bv4bnbma = csv:parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bnbma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - NillableBooleanMapArray|Error bv5bnbma = parseStringToRecord(csvStringWithBooleanValues5); + NillableBooleanMapArray|csv:Error bv5bnbma = csv:parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bnbma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: true} ]); - NillableBooleanMapArray|Error bv6bnbma = parseStringToRecord(csvStringWithBooleanValues6); + NillableBooleanMapArray|csv:Error bv6bnbma = csv:parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bnbma, [ {b2: (), b3: ()} ]); - NillableBooleanMapArray|Error bv7bnbma = parseStringToRecord(csvStringWithBooleanValues7); + NillableBooleanMapArray|csv:Error bv7bnbma = csv:parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bnbma, [ {b1, b2, b3, b4} ]); - NillableIntUnionBooleanMapArray|Error bv1bniubma = parseStringToRecord(csvStringWithBooleanValues1); + NillableIntUnionBooleanMapArray|csv:Error bv1bniubma = csv:parseStringToRecord(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|Error bv2bniubma = parseStringToRecord(csvStringWithBooleanValues2); + NillableIntUnionBooleanMapArray|csv:Error bv2bniubma = csv:parseStringToRecord(csvStringWithBooleanValues2); test:assertEquals(bv2bniubma, [ {b1: true, b2: false, b3: true, b4: false, b5: true}, {b1: true, b2: false, b3: true, b4: false, b5: true} ]); - NillableIntUnionBooleanMapArray|Error bv3bniubma = parseStringToRecord(csvStringWithBooleanValues3); +} + +@test:Config +function testFromCsvStringWithTypeForStringAndMapAsExpectedType2() { + NillableIntUnionBooleanMapArray|csv:Error bv3bniubma = csv:parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bniubma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - NillableIntUnionBooleanMapArray|Error bv4bniubma = parseStringToRecord(csvStringWithBooleanValues4); + NillableIntUnionBooleanMapArray|csv:Error bv4bniubma = csv:parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bniubma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - NillableIntUnionBooleanMapArray|Error bv5bniubma = parseStringToRecord(csvStringWithBooleanValues5); + NillableIntUnionBooleanMapArray|csv:Error bv5bniubma = csv:parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bniubma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - NillableIntUnionBooleanMapArray|Error bv6bniubma = parseStringToRecord(csvStringWithBooleanValues6); + NillableIntUnionBooleanMapArray|csv:Error bv6bniubma = csv:parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bniubma, [ {b2: (), b3: ()} ]); - NillableIntUnionBooleanMapArray|Error bv7bniubma = parseStringToRecord(csvStringWithBooleanValues7); + NillableIntUnionBooleanMapArray|csv:Error bv7bniubma = csv:parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bniubma, [ {b1, b2, b3, b4} ]); - IntUnionBooleanMapArray|Error bv1biubma = parseStringToRecord(csvStringWithBooleanValues1); + IntUnionBooleanMapArray|csv:Error bv1biubma = csv:parseStringToRecord(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|Error bv2biubma = parseStringToRecord(csvStringWithBooleanValues2); + IntUnionBooleanMapArray|csv:Error bv2biubma = csv:parseStringToRecord(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|Error bv3biubma = parseStringToRecord(csvStringWithBooleanValues3); + IntUnionBooleanMapArray|csv:Error bv3biubma = csv:parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3biubma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false}, {b1: true, b2: true, b3: false} ]); - IntUnionBooleanMapArray|Error bv4biubma = parseStringToRecord(csvStringWithBooleanValues4); + IntUnionBooleanMapArray|csv:Error bv4biubma = csv:parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4biubma, [ {b1: true, b4: false}, {b1: true, b4: false} ]); - IntUnionBooleanMapArray|Error bv5biubma = parseStringToRecord(csvStringWithBooleanValues5); + IntUnionBooleanMapArray|csv:Error bv5biubma = csv:parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5biubma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - IntUnionBooleanMapArray|Error bv6biubma = parseStringToRecord(csvStringWithBooleanValues6); + IntUnionBooleanMapArray|csv:Error bv6biubma = csv:parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6biubma, [ {} ]); - IntUnionBooleanMapArray|Error bv7biubma = parseStringToRecord(csvStringWithBooleanValues7); + IntUnionBooleanMapArray|csv:Error bv7biubma = csv:parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7biubma, [ {b1, b2, b4} ]); - NilMapArray|Error bv1bnma = parseStringToRecord(csvStringWithBooleanValues1); + NilMapArray|csv:Error bv1bnma = csv:parseStringToRecord(csvStringWithBooleanValues1); test:assertEquals(bv1bnma, [ {}, {}, {} ]); - NilMapArray|Error bv2bnma = parseStringToRecord(csvStringWithBooleanValues2); + NilMapArray|csv:Error bv2bnma = csv:parseStringToRecord(csvStringWithBooleanValues2); test:assertEquals(bv2bnma, [ {}, {} ]); - NilMapArray|Error bv3bnma = parseStringToRecord(csvStringWithBooleanValues3); + NilMapArray|csv:Error bv3bnma = csv:parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bnma, [ {}, {b3: ()}, {} ]); - NilMapArray|Error bv4bnma = parseStringToRecord(csvStringWithBooleanValues4); + NilMapArray|csv:Error bv4bnma = csv:parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bnma, [ {b2: (), b3: ()}, {b2: (), b3: ()} ]); - NilMapArray|Error bv5bnma = parseStringToRecord(csvStringWithBooleanValues5); + NilMapArray|csv:Error bv5bnma = csv:parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bnma, [ {}, {} ]); +} - NilMapArray|Error bv6bnma = parseStringToRecord(csvStringWithBooleanValues6); +@test:Config +function testFromCsvStringWithTypeForStringAndMapAsExpectedType3() { + NilMapArray|csv:Error bv6bnma = csv:parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bnma, [ {b2: (), b3: ()} ]); - NilMapArray|Error bv7bnma = parseStringToRecord(csvStringWithBooleanValues7); + NilMapArray|csv:Error bv7bnma = csv:parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bnma, [ {b3} ]); - JsonMapArray|Error bv1bjma = parseStringToRecord(csvStringWithBooleanValues1); + JsonMapArray|csv:Error bv1bjma = csv:parseStringToRecord(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|Error bv2bjma = parseStringToRecord(csvStringWithBooleanValues2); + JsonMapArray|csv:Error bv2bjma = csv:parseStringToRecord(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|Error bv3bjma = parseStringToRecord(csvStringWithBooleanValues3); + JsonMapArray|csv:Error bv3bjma = csv:parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bjma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - JsonMapArray|Error bv4bjma = parseStringToRecord(csvStringWithBooleanValues4); + JsonMapArray|csv:Error bv4bjma = csv:parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bjma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - JsonMapArray|Error bv5bjma = parseStringToRecord(csvStringWithBooleanValues5); + JsonMapArray|csv:Error bv5bjma = csv:parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bjma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - JsonMapArray|Error bv6bjma = parseStringToRecord(csvStringWithBooleanValues6); + JsonMapArray|csv:Error bv6bjma = csv:parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bjma, [ {b2: (), b3: ()} ]); - JsonMapArray|Error bv7bjma = parseStringToRecord(csvStringWithBooleanValues7); + JsonMapArray|csv:Error bv7bjma = csv:parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bjma, [ {b1, b2, b3, b4} ]); - AnydataMapArray|Error bv1banydma = parseStringToRecord(csvStringWithBooleanValues1); + AnydataMapArray|csv:Error bv1banydma = csv:parseStringToRecord(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|Error bv2banydma = parseStringToRecord(csvStringWithBooleanValues2); + AnydataMapArray|csv:Error bv2banydma = csv:parseStringToRecord(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|Error bv3banydma = parseStringToRecord(csvStringWithBooleanValues3); + AnydataMapArray|csv:Error bv3banydma = csv:parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3banydma, [ {b1: true, b2: false, b3: true}, {b1: true, b2: false, b3: null}, {b1: true, b2: true, b3: false} ]); - AnydataMapArray|Error bv4banydma = parseStringToRecord(csvStringWithBooleanValues4); + AnydataMapArray|csv:Error bv4banydma = csv:parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4banydma, [ {b1: true, b2: (), b3: (), b4: false}, {b1: true, b2: (), b3: (), b4: false} ]); - AnydataMapArray|Error bv5banydma = parseStringToRecord(csvStringWithBooleanValues5); + AnydataMapArray|csv:Error bv5banydma = csv:parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5banydma, [ {b1: true, b2: false, b3: true, b4: 2}, {b1: true, b2: false, b3: true, b4: 3} ]); - AnydataMapArray|Error bv6banydma = parseStringToRecord(csvStringWithBooleanValues6); + AnydataMapArray|csv:Error bv6banydma = csv:parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6banydma, [ {b2: (), b3: ()} ]); - AnydataMapArray|Error bv7banydma = parseStringToRecord(csvStringWithBooleanValues7); + AnydataMapArray|csv:Error bv7banydma = csv:parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7banydma, [ {b1, b2, b3, b4} ]); - CustomMapArray|Error bv1bcma = parseStringToRecord(csvStringWithBooleanValues1); + CustomMapArray|csv:Error bv1bcma = csv:parseStringToRecord(csvStringWithBooleanValues1); test:assertEquals(bv1bcma, [ {b1: "true", b2: "false", b3: "true", b4: "false"}, {b1: "true", b2: "false", b3: "true", b4: "false"}, {b1: "true", b2: "false", b3: "true", b4: "false"} ]); +} - CustomMapArray|Error bv2bcma = parseStringToRecord(csvStringWithBooleanValues2); +@test:Config +function testFromCsvStringWithTypeForStringAndMapAsExpectedType4() { + CustomMapArray|csv:Error bv2bcma = csv:parseStringToRecord(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|Error bv3bcma = parseStringToRecord(csvStringWithBooleanValues3); + CustomMapArray|csv:Error bv3bcma = csv:parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bcma, [ {b1: "true", b2: "false", b3: "true"}, {b1: "TRUE", b2: "FALSE", b3: "()"}, {b1: "true", b2: "true", b3: "FALSE"} ]); - CustomMapArray|Error bv4bcma = parseStringToRecord(csvStringWithBooleanValues4); + CustomMapArray|csv:Error bv4bcma = csv:parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bcma, [ {b1: "true", b2: "()", b3: "()", b4: "false"}, {b1: "true", b2: "()", b3: "null", b4: "false"} ]); - CustomMapArray|Error bv5bcma = parseStringToRecord(csvStringWithBooleanValues5); + CustomMapArray|csv:Error bv5bcma = csv:parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bcma, [ {b1: "true", b2: "false", b3: "true", b4: 2}, {b1: "true", b2: "false", b3: "true", b4: 3} ]); - CustomMapArray|Error bv6bcma = parseStringToRecord(csvStringWithBooleanValues6); + CustomMapArray|csv:Error bv6bcma = csv:parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bcma, [ {b2: "()", b3: "()"} ]); - CustomMapArray|Error bv7bcma = parseStringToRecord(csvStringWithBooleanValues7); + CustomMapArray|csv:Error bv7bcma = csv:parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bcma, [ {b1: "true", b2: "false", b3: "()", b4: "false"} ]); - StringMapArray|Error bv1bsma = parseStringToRecord(csvStringWithBooleanValues1); + StringMapArray|csv:Error bv1bsma = csv:parseStringToRecord(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|Error bv2bsma = parseStringToRecord(csvStringWithBooleanValues2); + StringMapArray|csv:Error bv2bsma = csv:parseStringToRecord(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|Error bv3bsma = parseStringToRecord(csvStringWithBooleanValues3); + StringMapArray|csv:Error bv3bsma = csv:parseStringToRecord(csvStringWithBooleanValues3); test:assertEquals(bv3bsma, [ {b1: "true", b2: "false", b3: "true"}, {b1: "TRUE", b2: "FALSE", b3: "()"}, {b1: "true", b2: "true", b3: "FALSE"} ]); - StringMapArray|Error bv4bsma = parseStringToRecord(csvStringWithBooleanValues4); + StringMapArray|csv:Error bv4bsma = csv:parseStringToRecord(csvStringWithBooleanValues4); test:assertEquals(bv4bsma, [ {b1: "true", b2: "()", b3: "()", b4: "false"}, {b1: "true", b2: "()", b3: "null", b4: "false"} ]); - StringMapArray|Error bv5bsma = parseStringToRecord(csvStringWithBooleanValues5); + StringMapArray|csv:Error bv5bsma = csv:parseStringToRecord(csvStringWithBooleanValues5); test:assertEquals(bv5bsma, [ {b1: "true", b2: "false", b3: "true", b4: "2"}, {b1: "true", b2: "false", b3: "true", b4: "3"} ]); - StringMapArray|Error bv6bsma = parseStringToRecord(csvStringWithBooleanValues6); + StringMapArray|csv:Error bv6bsma = csv:parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6bsma, [ {b2: "()", b3: "()"} ]); - StringMapArray|Error bv7bsma = parseStringToRecord(csvStringWithBooleanValues7); + StringMapArray|csv:Error bv7bsma = csv:parseStringToRecord(csvStringWithBooleanValues7); test:assertEquals(bv7bsma, [ {b1: "true", b2: "false", b3: "()", b4: "false"} ]); - DecimalMapArray|Error bv1dsma = parseStringToRecord(csvStringWithBooleanValues1); + DecimalMapArray|csv:Error bv1dsma = csv:parseStringToRecord(csvStringWithBooleanValues1); test:assertEquals(bv1dsma, [ {}, {}, {} ]); - DecimalMapArray|Error bv6dsma = parseStringToRecord(csvStringWithBooleanValues6); + DecimalMapArray|csv:Error bv6dsma = csv:parseStringToRecord(csvStringWithBooleanValues6); test:assertEquals(bv6dsma, [ {} ]); - DecimalMapArray|Error bv7dsma = parseStringToRecord(csvStringWithBooleanValues7); + DecimalMapArray|csv:Error bv7dsma = csv:parseStringToRecord(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 new file mode 100644 index 0000000..2383f72 --- /dev/null +++ b/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_record_tests.bal @@ -0,0 +1,496 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; +import ballerina/test; + +@test:Config +function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { + BooleanRecord1Array|csv:Error csvb1br1 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + 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, {}); + 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, {}); + test:assertTrue(csvb3br1 is csv:Error); + test:assertEquals((csvb3br1).message(), common:generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord1Array|csv:Error csvb4br1 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br1, [ + {b1: true, b2: "()", b3: (), b4: false}, + {b1: true, b2: "()", b3: (), b4: false} + ]); + + BooleanRecord1Array|csv:Error csvb5br1 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertTrue(csvb5br1 is csv:Error); + test:assertEquals((csvb5br1).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanRecord1Array|csv:Error csvb6br1 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br1 is csv:Error); + test:assertEquals((csvb6br1).message(), common:generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord1Array|csv:Error csvb7br1 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br1, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord2Array|csv:Error csvb1br2 = csv:parseStringToRecord(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, {}); + 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, {}); + test:assertTrue(csvb3br2 is csv:Error); + test:assertEquals((csvb3br2).message(), common:generateErrorMessageForMissingRequiredField("b4")); + + BooleanRecord2Array|csv:Error csvb4br2 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br2, [ + {b1: true, b2: "()", b3: (), b4: false}, + {b1: true, b2: "()", b3: (), b4: false} + ]); + + BooleanRecord2Array|csv:Error csvb5br2 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertTrue(csvb5br2 is csv:Error); + test:assertEquals((csvb5br2).message(), common:generateErrorMessageForInvalidCast("2", "boolean")); + + BooleanRecord2Array|csv:Error csvb7br2 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br2, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord3Array|csv:Error csvb1br3 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br3, [ + {b1: true, b3: true}, + {b1: true, b3: true}, + {b1: true, b3: true} + ]); + + BooleanRecord3Array|csv:Error csvb2br3 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + test:assertEquals(csvb2br3, [ + {b1: true, b3: true}, + {b1: true, b3: true} + ]); + + BooleanRecord3Array|csv:Error csvb3br3 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br3, [ + {b1: true, b3: true}, + {b1: true, b3: ()}, + {b1: true, b3: false} + ]); + + BooleanRecord3Array|csv:Error csvb4br3 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br3, [ + {b1: true, b3: ()}, + {b1: true, b3: ()} + ]); + + BooleanRecord3Array|csv:Error csvb5br3 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br3, [ + {b1: true, b3: true}, + {b1: true, b3: true} + ]); +} + +@test:Config +function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { + BooleanRecord3Array|csv:Error csvb7br3 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br3, [ + {b1, b3: ()} + ]); + + BooleanRecord4Array|csv:Error csvb1br4 = csv:parseStringToRecord(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, {}); + 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, {}); + 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, {}); + test:assertEquals(csvb4br4, [ + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} + ]); + + BooleanRecord4Array|csv:Error csvb5br4 = csv:parseStringToRecord(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, {}); + test:assertEquals(csvb7br4, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord5Array|csv:Error csvb1br5 = csv:parseStringToRecord(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, {}); + 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, {}); + 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, {}); + 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, {}); + 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, {}); + test:assertEquals(csvb7br5, [ + {b1, b2, b3: (), b4, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|csv:Error csvb1br6 = csv:parseStringToRecord(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, {}); + test:assertEquals(csvb2br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: true, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|csv:Error csvb3br6 = csv:parseStringToRecord(csvStringWithBooleanValues3, {}); + test:assertEquals(csvb3br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: false, defaultableField: "", nillableField: ()} + ]); +} + +@test:Config +function testFromCsvStringWithTypeForStringAndRecordAsExpectedType3() { + BooleanRecord6Array|csv:Error csvb4br6 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br6, [ + {b1: true, b3: (), defaultableField: "", nillableField: ()}, + {b1: true, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|csv:Error csvb5br6 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br6, [ + {b1: true, b3: true, defaultableField: "", nillableField: ()}, + {b1: true, b3: true, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord6Array|csv:Error csvb7br6 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br6, [ + {b1, b3: (), defaultableField: "", nillableField: ()} + ]); + + BooleanRecord7Array|csv:Error csvb1br7 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br7 is csv:Error); + test:assertEquals((csvb1br7).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord8Array|csv:Error csvb1br8 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br8 is csv:Error); + test:assertEquals((csvb1br8).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord9Array|csv:Error csvb1br9 = csv:parseStringToRecord(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, {}); + 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, {}); + 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, {}); + test:assertEquals(csvb4br9, [ + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} + ]); + + BooleanRecord9Array|csv:Error csvb5br9 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br9, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + BooleanRecord9Array|csv:Error csvb6br9 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br9 is csv:Error); + test:assertEquals((csvb6br9).message(), common:generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord9Array|csv:Error csvb7br9 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br9, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord10Array|csv:Error csvb1br10 = csv:parseStringToRecord(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, {}); + 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, {}); + 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, {}); + test:assertEquals(csvb4br10, [ + {b1: true, b4: false}, + {b1: true, b4: false} + ]); + + BooleanRecord10Array|csv:Error csvb5br10 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br10, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + BooleanRecord10Array|csv:Error csvb6br10 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br10, [ + {} + ]); + + BooleanRecord10Array|csv:Error csvb7br10 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br10, [ + {b1, b2, b4} + ]); + + BooleanRecord11Array|csv:Error csvb1br11 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br11, [ + {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: ()} + ]); +} + +@test:Config +function testFromCsvStringWithTypeForStringAndRecordAsExpectedType4() { + BooleanRecord11Array|csv:Error csvb2br11 = csv:parseStringToRecord(csvStringWithBooleanValues2, {}); + 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, {}); + 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, {}); + 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, {}); + 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, {}); + test:assertTrue(csvb6br11 is csv:Error); + test:assertEquals((csvb6br11).message(), common:generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord11Array|csv:Error csvb7br11 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br11, [ + {b1, b2, b3, b4, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord12Array|csv:Error csvb1br12 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertTrue(csvb1br12 is csv:Error); + test:assertEquals((csvb1br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + + BooleanRecord13Array|csv:Error csvb1br13 = csv:parseStringToRecord(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, {}); + 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, {}); + 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, {}); + 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, {}); + 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, {}); + test:assertEquals(csvb6br13, [ + {b2: "()", b3: "()", defaultableField: "", nillableField: ()} + ]); + + BooleanRecord13Array|csv:Error csvb7br13 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br13, [ + {b1, b2, b3: "()", b4, defaultableField: "", nillableField: ()} + ]); + + BooleanRecord14Array|csv:Error csvb7br14 = csv:parseStringToRecord(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, {}); + test:assertTrue(csvb1br15 is csv:Error); + test:assertEquals((csvb1br15).message(), common:generateErrorMessageForInvalidCast("true", "int")); + + BooleanRecord15Array|csv:Error csvb6br15 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br15 is csv:Error); + test:assertEquals((csvb6br15).message(), common:generateErrorMessageForMissingRequiredField("b1")); + + BooleanRecord15Array|csv:Error csvb7br15 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertTrue(csvb7br15 is csv:Error); + test:assertEquals((csvb7br15).message(), common:generateErrorMessageForInvalidCast("true", "int")); + + BooleanRecord16Array|csv:Error csvb1br16 = csv:parseStringToRecord(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, {}); + 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, {}); + 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, {}); + test:assertEquals(csvb4br16, [ + {b1: true, b2: (), b3: (), b4: false}, + {b1: true, b2: (), b3: (), b4: false} + ]); + + BooleanRecord16Array|csv:Error csvb5br16 = csv:parseStringToRecord(csvStringWithBooleanValues5, {}); + test:assertEquals(csvb5br16, [ + {b1: true, b2: false, b3: true}, + {b1: true, b2: false, b3: true} + ]); + + BooleanRecord16Array|csv:Error csvb6br16 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br16, [ + {b2: (), b3: ()} + ]); + + BooleanRecord16Array|csv:Error csvb7br16 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br16, [ + {b1, b2, b3: (), b4} + ]); + + BooleanRecord17Array|csv:Error csvb1br17 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br17, [{}, {}, {}]); + + BooleanRecord17Array|csv:Error csvb4br17 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertEquals(csvb4br17, [{}, {}]); + + BooleanRecord17Array|csv:Error csvb6br17 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertEquals(csvb6br17, [{}]); + + BooleanRecord17Array|csv:Error csvb7br17 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br17, [{}]); + + BooleanRecord18Array|csv:Error csvb1br18 = csv:parseStringToRecord(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br18, [{b2: false}, {b2: false}, {b2: false}]); + + BooleanRecord18Array|csv:Error csvb4br18 = csv:parseStringToRecord(csvStringWithBooleanValues4, {}); + test:assertTrue(csvb4br18 is csv:Error); + test:assertEquals((csvb4br18).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanRecord18Array|csv:Error csvb6br18 = csv:parseStringToRecord(csvStringWithBooleanValues6, {}); + test:assertTrue(csvb6br18 is csv:Error); + test:assertEquals((csvb6br18).message(), common:generateErrorMessageForInvalidCast("()", "boolean")); + + BooleanRecord18Array|csv:Error csvb7br18 = csv:parseStringToRecord(csvStringWithBooleanValues7, {}); + test:assertEquals(csvb7br18, [{b2, b3: ()}]); +} diff --git a/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal new file mode 100644 index 0000000..360a493 --- /dev/null +++ b/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal @@ -0,0 +1,256 @@ +boolean b1 = true; +false b2 = false; +boolean? b3 = (); +boolean|int b4 = false; + +() n1 = (); +int? n2 = (); +() n3 = null; + +int i1 = 1; +int i2 = -2; +int i3 = int:MAX_VALUE; +int i4 = int:MIN_VALUE; +int i5 = 0; +2 i6 = 2; +int? i7 = (); +int|string i8 = 100; + +float f1 = 2.234; +float f2 = -3.21f; +float f3 = 0; +float f4 = float:Infinity; +float f5 = -float:Infinity; +float f6 = float:NaN; +2.3f f7 = 2.3; +float? f8 = (); +float|decimal f9 = 1.21; + +decimal d1 = 2.234; +decimal d2 = -3.21d; +decimal d3 = 0; +2.3d d4 = 2.3; +decimal? d5 = (); +decimal|int d6 = 1.21; + +string s1 = "string"; +string s2 = ""; +string:Char s3 = "a"; + +map bm1 = {b1, b2}; +map bm2 = {b1, b2, b3, n1, n3}; +map bm3 = {b1, b2, b3, b4, i1}; +map<()> bm4 = {n1, n3}; +map bm5 = {b1, b2, b3, b4:true}; + +map m5 = {i1, i2, i3, i4, i5, i6}; +map m6 = {f1, f2, f3, f4, f5, f6, f7}; +map m7 = {d1, d2, d3, d4}; +map m8 = {d1, f1, f9, f10: 1.23}; +map m9 = {s1, s2, s3}; +map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; +map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; + +boolean[] arr1 = [b1, b2]; +boolean?[] arr2 = [b1, b2, b3, n1, n3]; +(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; +()[] arr4 = [n1, n3]; +int[] arr5 = [i1, i2, i3, i4, i5, i6]; +float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; +decimal[] arr7 = [d1, d2, d3, d4]; +(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; +string[] arr9 = [s1, s2, s3]; +anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; + +[boolean, boolean] bt1 = [b1, b2]; +[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; +[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; +[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; +[boolean...] bt5 = [b1, b2]; + +[string, string] st1 = [s1, s2]; +[string, string, string, string] st2 = [s1, s2, s3, s2]; +[string...] st3 = [s1, s2]; +[string, string, string...] st4 = [s1, s2, s3, s2]; + +[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; +[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; +[string?...] st7 = [s1, s2]; +[string...] st8 = []; +[string, string, string] st9 = [s1, s2, s3]; + +[(), ()] tup4 = [n1, n3]; +[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; +[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; +[string, string, string] tup9 = [s1, s2, s3]; +[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, + n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, json] tup11 = + [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, + f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 +]; + +[boolean, boolean...] restTup1 = [b1, b2]; +[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; +[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; +[(), ()...] restTup4 = [n1, n3]; +[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; +[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal...] restTup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; +[string...] restTup9 = [s1, s2, s3]; +[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 +]; + +var booleanRecordArray = [ + {b1, b2, b3, b4}, {b1, b2, b3, b4} +]; + +var booleanRecordArray2 = [ + {},{} +]; + +string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 +true,false,true,false +true,false, true,false +true,false,true,false +`; + +string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 +true,false, true,false,true +true,false, true,false,true`; + +string csvStringWithBooleanValues3 = string `b1,b2,b3 +${" "}${"\t"} +true, false,true +${" "} + TRUE, FALSE,() +${" "} + +true, true,FALSE + +`; + +string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 + true,(), (),false + true,(), null,false + +`; + +string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 + +true,false,true,2 + +true,false,true,3 +`; + +string csvStringWithBooleanValues6 = string `b2,b3 +(),() + +`; + +string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 +${b1},${b2},(),${b4} +`; + +string csvStringData1 = string ` + a, b, c, d, e, f + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData2 = string ` + hello, hello, (), 12, true, 12.34 + // comment + + a, b, c, d, e, f + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData3 = string ` + a, b, c, d, e, f + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData4 = string ` + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData5 = string ` + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData6 = string ` + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData7 = string ` + a@ b@ c@ d@ e@ f + 1@ string@ true@ 2.234@ -3.21@ () + 2@ s,tring@ true@ 2.234@ -3.21@ null + 3@ stri,ng@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; +string csvStringData8 = string ` + a@ b@ c@ d@ e@ f + + + + 1@ stri,ng@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ ()@-3.21 + 3@ string@ true@ 2.234@ -3.21@ null + + 4@ s,tring@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; + +string csvStringData9 = string ` + + 1@ string@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ -3.21@ null + + 3@ string@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ ()@-3.21 + + 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina-tests/parse-string-record-types-tests/tests/types.bal b/ballerina-tests/parse-string-record-types-tests/tests/types.bal new file mode 100644 index 0000000..a2b4b2b --- /dev/null +++ b/ballerina-tests/parse-string-record-types-tests/tests/types.bal @@ -0,0 +1,2534 @@ +type BooleanRecord1 record { + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +}; + +type BooleanRecord2 record {| + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +|}; + +type BooleanRecord3 record {| + boolean b1; + boolean? b3; +|}; + +type BooleanRecord4 record { + boolean b1; + boolean? b3; +}; + +type BooleanRecord5 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +}; + +type BooleanRecord6 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +|}; + +type BooleanRecord7 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type BooleanRecord8 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type BooleanRecord9 record {| + boolean b1; + boolean? b3; + boolean?...; +|}; + +type BooleanRecord10 record {| + boolean...; +|}; + +type BooleanRecord11 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + boolean?|string...; +|}; + +type BooleanRecord12 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string|boolean...; +|}; + +type BooleanRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord15 record {| + int b1; + string defaultableField = ""; + string? nillableField = (); + boolean?...; +|}; + +type BooleanRecord16 record {| + boolean?...; +|}; + +type BooleanRecord17 record {| + int...; +|}; + +type BooleanRecord18 record {| + boolean b2; + int?...; +|}; + +type NilRecord1 record { + () n1; + () n2; + () n3; +}; + +type NilRecord2 record {| + () n1; + () n2; + () n3; +|}; + +type NilRecord3 record {| + () n1; + () n4; +|}; + +type NilRecord4 record { + () n1; + () n4; +}; + +type NilRecord5 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +}; + +type NilRecord6 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type NilRecord7 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type NilRecord8 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type NilRecord9 record {| + () n1; + () n2; + ()...; +|}; + +type NilRecord10 record {| + ()...; +|}; + +type NilRecord11 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord12 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type NilRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type IntegerRecord1 record { + int i1; + int i2; + int i3; + int? i4; + int? i5; + int i6; + int i7; + int? i8; +}; + +type IntegerRecord2 record {| + int i1; + int? i2; + int i3; + int i4; + int? i5; + int i6; + int i7; + int? i8; +|}; + +type IntegerRecord3 record {| + int i1; + int i4; + int i6; +|}; + +type IntegerRecord4 record { + int i1; + int i4; + int i6; +}; + +type IntegerRecord5 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +}; + +type IntegerRecord6 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +|}; + +type IntegerRecord7 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type IntegerRecord8 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type IntegerRecord9 record {| + int i1; + int i2; + int...; +|}; + +type IntegerRecord10 record {| + int...; +|}; + +type IntegerRecord11 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord12 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type IntegerRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type FloatRecord1 record { + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +}; + +type FloatRecord2 record {| + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +|}; + +type FloatRecord3 record {| + float f1; + float f4; + float f7; +|}; + +type FloatRecord4 record { + float f1; + float f4; + float f7; +}; + +type FloatRecord5 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +}; + +type FloatRecord6 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type FloatRecord7 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type FloatRecord8 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type FloatRecord9 record {| + float f1; + float f2; + float...; +|}; + +type FloatRecord10 record {| + float...; +|}; + +type FloatRecord11 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord12 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type FloatRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type DecimalRecord1 record { + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +}; + +type DecimalRecord2 record {| + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +|}; + +type DecimalRecord3 record {| + decimal d1; + decimal d4; + decimal d7; +|}; + +type DecimalRecord4 record { + decimal d1; + decimal d4; + decimal d7; +}; + +type DecimalRecord5 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +}; + +type DecimalRecord6 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type DecimalRecord7 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type DecimalRecord8 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type DecimalRecord9 record {| + decimal d1; + decimal d2; + decimal...; +|}; + +type DecimalRecord10 record {| + decimal...; +|}; + +type DecimalRecord11 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord12 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type DecimalRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type StringRecord1 record { + string s1; + string s2; + string s3; +}; + +type StringRecord2 record {| + string s1; + string s2; + string s3; +|}; + +type StringRecord3 record {| + string s1; + string s4; +|}; + +type StringRecord4 record { + string s1; + string s4; +}; + +type StringRecord5 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +}; + +type StringRecord6 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type StringRecord7 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type StringRecord8 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type StringRecord9 record {| + string s1; + string s2; + string...; +|}; + +type StringRecord10 record {| + string...; +|}; + +type StringRecord11 record {| + string s1; + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord12 record {| + string d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord15 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord16 record {| + string?...; +|}; + +type StringRecord17 record {| + int...; +|}; + +type StringRecord18 record {| + string b2; + int?...; +|}; + +type StringRecord19 record { + string s1 = ""; + string s2 = ""; +}; + +type StringRecord20 record {| + string s1 = ""; + string s2 = ""; +|}; + +type StringRecord21 record { +}; + +type StringRecord22 record {| + string s1 = ""; + string s2 = ""; + json...; +|}; + +type StringRecord23 record {| + json...; +|}; + +type JsonRecord1 record { + json j1; + json j2; + json j3; +}; + +type JsonRecord2 record {| + json j1; + json j2; + json j3; +|}; + +type JsonRecord3 record {| + json j1; + json j4; +|}; + +type JsonRecord4 record { + json j1; + json j4; +}; + +type JsonRecord5 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +}; + +type JsonRecord6 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +|}; + +type JsonRecord7 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +}; + +type JsonRecord8 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +|}; + +type JsonRecord9 record {| + json j1; + json j2; + json...; +|}; + +type JsonRecord10 record {| + json...; +|}; + +type JsonRecord11 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord12 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type JsonRecord13 record {| + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord14 record {| + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type AnydataRecord1 record { + anydata anydata1; + anydata anydata2; + anydata anydata3; +}; + +type AnydataRecord2 record {| + anydata anydata1; + anydata anydata2; + anydata anydata3; +|}; + +type AnydataRecord3 record {| + anydata anydata1; + anydata anydata4; +|}; + +type AnydataRecord4 record { + anydata anydata1; + anydata anydata4; +}; + +type AnydataRecord5 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +}; + +type AnydataRecord6 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type AnydataRecord7 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type AnydataRecord8 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type AnydataRecord9 record {| + anydata anydata1; + anydata anydata2; + anydata...; +|}; + +type AnydataRecord10 record {| + anydata...; +|}; + +type AnydataRecord11 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord12 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type AnydataRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type CustomRecord1 record { + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +}; + +type CustomRecord2 record {| + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +|}; + +type CustomRecord3 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +|}; + +type CustomRecord4 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +}; + +type CustomRecord5 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string defaultableField = ""; + string? nillableField = (); +}; + +type CustomRecord6 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type CustomRecord7 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type CustomRecord8 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type CustomRecord9 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string...; +|}; + +type CustomRecord10 record {| + string...; +|}; + +type CustomRecord11 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord12 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomRecord15 record {| + string '1; + string '2; +|}; + +type CustomRecord16 record {| + string '1; + string '2; + string '3; + string '4; +|}; + +type CustomRecord17 record { + string '1; + string '2; +}; + +type CustomRecord18 record { + string '1; + string '2; + string '3; + string '4; +}; + +type CustomRecord19 record { + string '1; + string '2; + string '3 = ""; + string '4 = ""; +}; + +type CustomRecord20 record { + string '1; +}; + +type CustomRecord21 record {| + string '1; + json...; +|}; + +type CustomRecord22 record {| + string '1; + string...; +|}; + +type CustomRecord23 record {| + string '1; + string a = ""; + string...; +|}; + +type CustomRecord24 record {| + string '1; + string '2 = ""; + string...; +|}; + +type CustomRecord25 record {| + int '1; + string...; +|}; + +type CustomRecord26 record {| + string '1; + int...; +|}; + +type CustomRecord27 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata a1; + json j1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord28 record { + string '1; +}; + +type CustomRecord29 record { + int '1; +}; + +type CustomRecord30 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord31 record {| + string '1; + string '6; +|}; + +type CustomRecord32 record {| + int '1; +|}; + +type CustomRecord33 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord34 record { + string '1; + string '6; + string '5 = ""; +}; + +type CustomRecord35 record { + string '1; + string '6; + string '9 = ""; +}; + +type CustomRecord36 record {| + string '1; + string '6; + string '9 = ""; +|}; + +type CustomRecord37 record {| + string '1; + string '6; + string '5 = ""; +|}; + +type CustomRecord38 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + string ...; +|}; + +type CustomRecord39 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + json ...; +|}; + +type CustomRecord40 record {| + string '5; + string '6; + json ...; +|}; + +type CustomRecord41 record {| + json ...; +|}; + +type CustomRecord42 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +|}; + +type CustomRecord43 record { + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +}; + +type CustomRecord44 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; + string ...; +|}; + +type CustomRecord45 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +|}; + +type CustomRecord46 record { + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +}; + +type CustomRecord47 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; + string ...; +|}; + +type CustomRecord48 record { + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +}; + +type CustomRecord49 record {| + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +|}; + +type CustomRecord50 record { + int H1; + float H4; +}; + +type CustomRecord51 record {| + int H1; + float H4; +|}; + +type CustomRecord52 record {| + string H1; + string H4; + string ...; +|}; + +type CustomRecord53 record {| + int H1; + float H4; + decimal ...; +|}; + +type CustomRecord54 record {| + string H1 = ""; + string H4; + string '1; +|}; + +type CustomRecord55 record {| + string H1 = ""; + string H4 = ""; + int '1 = 10; +|}; + +type CustomRecord56 record { + string H1 = ""; + string H4 = ""; + anydata '1 = 10; +}; + +type BooleanTuple1 [boolean, boolean, boolean, boolean]; + +type BooleanTuple2 [boolean, boolean]; + +type BooleanTuple3 [boolean, boolean...]; + +type BooleanTuple4 [boolean...]; + +type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; + +type NillableBooleanTuple6 [boolean?, boolean?]; + +type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; + +type NillableBooleanTuple8 [boolean?...]; + +type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; + +type NilTuple1 [(), (), ()]; + +type NilTuple2 [(), ()]; + +type NilTuple3 [(), ()...]; + +type NilTuple4 [()...]; + +type IntegerTuple1 [int, int, int, int, int, int]; + +type IntegerTuple2 [int, int]; + +type IntegerTuple3 [int, int...]; + +type IntegerTuple4 [int...]; + +type FloatTuple1 [float, float, float, float, float, float, float]; + +type FloatTuple2 [float, float]; + +type FloatTuple3 [float, float...]; + +type FloatTuple4 [float...]; + +type DecimalTuple1 [decimal, decimal, decimal, decimal]; + +type DecimalTuple2 [decimal, decimal]; + +type DecimalTuple3 [decimal, decimal...]; + +type DecimalTuple4 [decimal...]; + +type StringTuple1 [string, string, string, string]; + +type StringTuple2 [string, string]; + +type StringTuple3 [string, string...]; + +type StringTuple4 [string...]; + +type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata]; + +type AnydataTuple2 [anydata, anydata]; + +type AnydataTuple3 [anydata, anydata...]; + +type AnydataTuple4 [anydata...]; + +type JsonTuple1 [json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json]; + +type JsonTuple2 [json, json]; + +type JsonTuple3 [json, json...]; + +type JsonTuple4 [json...]; + +type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; + +type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; + +type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; + +type CustomTuple4 [string...]; + +type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; + +type CustomTuple6 [anydata...]; + +type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; + +type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; + +type IntegerArray1 int[]; + +type IntegerArray2 int[2]; + +type IntegerArray3 int[]; + +type IntegerArray4 int[2]; + +type IntegerArray5 int[3]; + +type IntegerArray6 int[4]; + +type StringArray string[]; + +type NillableStringArray string?[]; + +type NillableIntOrUnionStringArray (int|string?)[]; + +type StringArray1 string[]; + +type StringArray2 string[2]; + +type StringArray3 string[]; + +type StringArray4 string[2]; + +type StringArray5 string[3]; + +type StringArray6 string[4]; + +type FloatArray1 float[]; + +type FloatArray2 float[2]; + +type FloatArray3 float[]; + +type FloatArray4 float[2]; + +type FloatArray5 float[3]; + +type FloatArray6 float[4]; + +type DecimalArray1 decimal[]; + +type DecimalArray2 decimal[2]; + +type DecimalArray3 decimal[]; + +type DecimalArray4 decimal[2]; + +type DecimalArray5 decimal[3]; + +type DecimalArray6 decimal[4]; + +type BooleanArray boolean[]; + +type NillableBooleanArray boolean?[]; + +type NillableIntOrUnionBooleanArray (int|boolean?)[]; + +type BooleanArray2 boolean[2]; + +type BooleanArray3 boolean[3]; + +type BooleanArray4 boolean[]; + +type BooleanArray5 boolean[2]; + +type BooleanArray6 boolean[4]; + +type NilArray1 ()[]; + +type NilArray2 ()[2]; + +type NilArray3 ()[]; + +type NilArray4 ()[2]; + +type NilArray5 ()[3]; + +type NilArray6 ()[4]; + +type JsonArray1 json[]; + +type JsonArray2 json[2]; + +type JsonArray3 json[]; + +type JsonArray4 json[2]; + +type JsonArray5 json[3]; + +type JsonArray6 json[4]; + +type AnydataArray1 anydata[]; + +type AnydataArray2 anydata[2]; + +type AnydataArray3 anydata[]; + +type AnydataArray4 anydata[2]; + +type AnydataArray5 anydata[3]; + +type AnydataArray6 anydata[4]; + +type CustomArray1 CustomTuple2[]; + +type CustomArray2 CustomTuple2[2]; + +type CustomArray3 CustomTuple2[]; + +type CustomArray4 CustomTuple2[2]; + +type CustomArray5 CustomTuple2[3]; + +type CustomArray6 CustomTuple2[4]; + +type IntegerMap map; + +type StringMap map; + +type NillableIntUnionStringMap map; + +type IntUnionStringMap map; + +type DecimalMap map; + +type FloatMap map; + +type BooleanMap map; + +type NillableBooleanMap map; + +type NillableIntUnionBooleanMap map; + +type IntUnionBooleanMap map; + +type NilMap map<()>; + +type JsonMap map; + +type AnydataMap map; + +type CustomMap map; + +type BooleanRecord1Array BooleanRecord1[]; + +type ClosedBooleanRecord1Array BooleanRecord1[3]; + +type BooleanRecord2Array BooleanRecord2[]; + +type ClosedBooleanRecord2Array BooleanRecord2[3]; + +type BooleanRecord3Array BooleanRecord3[]; + +type ClosedBooleanRecord3Array BooleanRecord3[3]; + +type BooleanRecord4Array BooleanRecord4[]; + +type ClosedBooleanRecord4Array BooleanRecord4[3]; + +type BooleanRecord5Array BooleanRecord5[]; + +type ClosedBooleanRecord5Array BooleanRecord5[3]; + +type BooleanRecord6Array BooleanRecord6[]; + +type ClosedBooleanRecord6Array BooleanRecord6[3]; + +type BooleanRecord7Array BooleanRecord7[]; + +type ClosedBooleanRecord7Array BooleanRecord7[3]; + +type BooleanRecord8Array BooleanRecord8[]; + +type ClosedBooleanRecord8Array BooleanRecord8[3]; + +type BooleanRecord9Array BooleanRecord9[]; + +type ClosedBooleanRecord9Array BooleanRecord9[3]; + +type BooleanRecord10Array BooleanRecord10[]; + +type ClosedBooleanRecord10Array BooleanRecord10[3]; + +type BooleanRecord11Array BooleanRecord11[]; + +type ClosedBooleanRecord11Array BooleanRecord11[3]; + +type BooleanRecord12Array BooleanRecord12[]; + +type ClosedBooleanRecord12Array BooleanRecord12[3]; + +type BooleanRecord13Array BooleanRecord13[]; + +type ClosedBooleanRecord13Array BooleanRecord13[3]; + +type BooleanRecord14Array BooleanRecord14[]; + +type ClosedBooleanRecord14Array BooleanRecord14[3]; + +type BooleanRecord15Array BooleanRecord15[]; + +type ClosedBooleanRecord15Array BooleanRecord15[3]; + +type BooleanRecord16Array BooleanRecord16[]; + +type ClosedBooleanRecord16Array BooleanRecord16[3]; + +type BooleanRecord17Array BooleanRecord17[]; + +type ClosedBooleanRecord17Array BooleanRecord17[3]; + +type BooleanRecord18Array BooleanRecord18[]; + +type ClosedBooleanRecord18Array BooleanRecord18[3]; + +type NilRecord1Array NilRecord1[]; + +type ClosedNilRecord1Array NilRecord1[3]; + +type NilRecord2Array NilRecord2[]; + +type ClosedNilRecord2Array NilRecord2[3]; + +type NilRecord3Array NilRecord3[]; + +type ClosedNilRecord3Array NilRecord3[3]; + +type NilRecord4Array NilRecord4[]; + +type ClosedNilRecord4Array NilRecord4[3]; + +type NilRecord5Array NilRecord5[]; + +type ClosedNilRecord5Array NilRecord5[3]; + +type NilRecord6Array NilRecord6[]; + +type ClosedNilRecord6Array NilRecord6[3]; + +type NilRecord7Array NilRecord7[]; + +type ClosedNilRecord7Array NilRecord7[3]; + +type NilRecord8Array NilRecord8[]; + +type ClosedNilRecord8Array NilRecord8[3]; + +type NilRecord9Array NilRecord9[]; + +type ClosedNilRecord9Array NilRecord9[3]; + +type NilRecord10Array NilRecord10[]; + +type ClosedNilRecord10Array NilRecord10[3]; + +type NilRecord11Array NilRecord11[]; + +type ClosedNilRecord11Array NilRecord11[3]; + +type NilRecord12Array NilRecord12[]; + +type ClosedNilRecord12Array NilRecord12[3]; + +type NilRecord13Array NilRecord13[]; + +type ClosedNilRecord13Array NilRecord13[3]; + +type NilRecord14Array NilRecord14[]; + +type ClosedNilRecord14Array NilRecord14[3]; + +type IntegerRecord1Array IntegerRecord1[]; + +type ClosedIntegerRecord1Array IntegerRecord1[3]; + +type IntegerRecord2Array IntegerRecord2[]; + +type ClosedIntegerRecord2Array IntegerRecord2[3]; + +type IntegerRecord3Array IntegerRecord3[]; + +type ClosedIntegerRecord3Array IntegerRecord3[3]; + +type IntegerRecord4Array IntegerRecord4[]; + +type ClosedIntegerRecord4Array IntegerRecord4[3]; + +type IntegerRecord5Array IntegerRecord5[]; + +type ClosedIntegerRecord5Array IntegerRecord5[3]; + +type IntegerRecord6Array IntegerRecord6[]; + +type ClosedIntegerRecord6Array IntegerRecord6[3]; + +type IntegerRecord7Array IntegerRecord7[]; + +type ClosedIntegerRecord7Array IntegerRecord7[3]; + +type IntegerRecord8Array IntegerRecord8[]; + +type ClosedIntegerRecord8Array IntegerRecord8[3]; + +type IntegerRecord9Array IntegerRecord9[]; + +type ClosedIntegerRecord9Array IntegerRecord9[3]; + +type IntegerRecord10Array IntegerRecord10[]; + +type ClosedIntegerRecord10Array IntegerRecord10[3]; + +type IntegerRecord11Array IntegerRecord11[]; + +type ClosedIntegerRecord11Array IntegerRecord11[3]; + +type IntegerRecord12Array IntegerRecord12[]; + +type ClosedIntegerRecord12Array IntegerRecord12[3]; + +type IntegerRecord13Array IntegerRecord13[]; + +type ClosedIntegerRecord13Array IntegerRecord13[3]; + +type IntegerRecord14Array IntegerRecord14[]; + +type ClosedIntegerRecord14Array IntegerRecord14[3]; + +type FloatRecord1Array FloatRecord1[]; + +type ClosedFloatRecord1Array FloatRecord1[3]; + +type FloatRecord2Array FloatRecord2[]; + +type ClosedFloatRecord2Array FloatRecord2[3]; + +type FloatRecord3Array FloatRecord3[]; + +type ClosedFloatRecord3Array FloatRecord3[3]; + +type FloatRecord4Array FloatRecord4[]; + +type ClosedFloatRecord4Array FloatRecord4[3]; + +type FloatRecord5Array FloatRecord5[]; + +type ClosedFloatRecord5Array FloatRecord5[3]; + +type FloatRecord6Array FloatRecord6[]; + +type ClosedFloatRecord6Array FloatRecord6[3]; + +type FloatRecord7Array FloatRecord7[]; + +type ClosedFloatRecord7Array FloatRecord7[3]; + +type FloatRecord8Array FloatRecord8[]; + +type ClosedFloatRecord8Array FloatRecord8[3]; + +type FloatRecord9Array FloatRecord9[]; + +type ClosedFloatRecord9Array FloatRecord9[3]; + +type FloatRecord10Array FloatRecord10[]; + +type ClosedFloatRecord10Array FloatRecord10[3]; + +type FloatRecord11Array FloatRecord11[]; + +type ClosedFloatRecord11Array FloatRecord11[3]; + +type FloatRecord12Array FloatRecord12[]; + +type ClosedFloatRecord12Array FloatRecord12[3]; + +type FloatRecord13Array FloatRecord13[]; + +type ClosedFloatRecord13Array FloatRecord13[3]; + +type FloatRecord14Array FloatRecord14[]; + +type ClosedFloatRecord14Array FloatRecord14[3]; + +type DecimalRecord1Array DecimalRecord1[]; + +type ClosedDecimalRecord1Array DecimalRecord1[3]; + +type DecimalRecord2Array DecimalRecord2[]; + +type ClosedDecimalRecord2Array DecimalRecord2[3]; + +type DecimalRecord3Array DecimalRecord3[]; + +type ClosedDecimalRecord3Array DecimalRecord3[3]; + +type DecimalRecord4Array DecimalRecord4[]; + +type ClosedDecimalRecord4Array DecimalRecord4[3]; + +type DecimalRecord5Array DecimalRecord5[]; + +type ClosedDecimalRecord5Array DecimalRecord5[3]; + +type DecimalRecord6Array DecimalRecord6[]; + +type ClosedDecimalRecord6Array DecimalRecord6[3]; + +type DecimalRecord7Array DecimalRecord7[]; + +type ClosedDecimalRecord7Array DecimalRecord7[3]; + +type DecimalRecord8Array DecimalRecord8[]; + +type ClosedDecimalRecord8Array DecimalRecord8[3]; + +type DecimalRecord9Array DecimalRecord9[]; + +type ClosedDecimalRecord9Array DecimalRecord9[3]; + +type DecimalRecord10Array DecimalRecord10[]; + +type ClosedDecimalRecord10Array DecimalRecord10[3]; + +type DecimalRecord11Array DecimalRecord11[]; + +type ClosedDecimalRecord11Array DecimalRecord11[3]; + +type DecimalRecord12Array DecimalRecord12[]; + +type ClosedDecimalRecord12Array DecimalRecord12[3]; + +type DecimalRecord13Array DecimalRecord13[]; + +type ClosedDecimalRecord13Array DecimalRecord13[3]; + +type DecimalRecord14Array DecimalRecord14[]; + +type ClosedDecimalRecord14Array DecimalRecord14[3]; + +type StringRecord1Array StringRecord1[]; + +type ClosedStringRecord1Array StringRecord1[3]; + +type StringRecord2Array StringRecord2[]; + +type ClosedStringRecord2Array StringRecord2[3]; + +type StringRecord3Array StringRecord3[]; + +type ClosedStringRecord3Array StringRecord3[3]; + +type StringRecord4Array StringRecord4[]; + +type ClosedStringRecord4Array StringRecord4[3]; + +type StringRecord5Array StringRecord5[]; + +type ClosedStringRecord5Array StringRecord5[3]; + +type StringRecord6Array StringRecord6[]; + +type ClosedStringRecord6Array StringRecord6[3]; + +type StringRecord7Array StringRecord7[]; + +type ClosedStringRecord7Array StringRecord7[3]; + +type StringRecord8Array StringRecord8[]; + +type ClosedStringRecord8Array StringRecord8[3]; + +type StringRecord9Array StringRecord9[]; + +type ClosedStringRecord9Array StringRecord9[3]; + +type StringRecord10Array StringRecord10[]; + +type ClosedStringRecord10Array StringRecord10[3]; + +type StringRecord11Array StringRecord11[]; + +type ClosedStringRecord11Array StringRecord11[3]; + +type StringRecord12Array StringRecord12[]; + +type ClosedStringRecord12Array StringRecord12[3]; + +type StringRecord13Array StringRecord13[]; + +type ClosedStringRecord13Array StringRecord13[3]; + +type StringRecord14Array StringRecord14[]; + +type ClosedStringRecord14Array StringRecord14[3]; + +type StringRecord15Array StringRecord15[]; + +type StringRecord16Array StringRecord16[]; + +type StringRecord17Array StringRecord17[]; + +type StringRecord18Array StringRecord18[]; + +type StringRecord19Array StringRecord19[]; + +type StringRecord20Array StringRecord20[]; + +type StringRecord21Array StringRecord21[]; + +type StringRecord22Array StringRecord22[]; + +type StringRecord23Array StringRecord23[]; + +type JsonRecord1Array JsonRecord1[]; + +type ClosedJsonRecord1Array JsonRecord1[3]; + +type JsonRecord2Array JsonRecord2[]; + +type ClosedJsonRecord2Array JsonRecord2[3]; + +type JsonRecord3Array JsonRecord3[]; + +type ClosedJsonRecord3Array JsonRecord3[3]; + +type JsonRecord4Array JsonRecord4[]; + +type ClosedJsonRecord4Array JsonRecord4[3]; + +type JsonRecord5Array JsonRecord5[]; + +type ClosedJsonRecord5Array JsonRecord5[3]; + +type JsonRecord6Array JsonRecord6[]; + +type ClosedJsonRecord6Array JsonRecord6[3]; + +type JsonRecord7Array JsonRecord7[]; + +type ClosedJsonRecord7Array JsonRecord7[3]; + +type JsonRecord8Array JsonRecord8[]; + +type ClosedJsonRecord8Array JsonRecord8[3]; + +type JsonRecord9Array JsonRecord9[]; + +type ClosedJsonRecord9Array JsonRecord9[3]; + +type JsonRecord10Array JsonRecord10[]; + +type ClosedJsonRecord10Array JsonRecord10[3]; + +type JsonRecord11Array JsonRecord11[]; + +type ClosedJsonRecord11Array JsonRecord11[3]; + +type JsonRecord12Array JsonRecord12[]; + +type ClosedJsonRecord12Array JsonRecord12[3]; + +type JsonRecord13Array JsonRecord13[]; + +type ClosedJsonRecord13Array JsonRecord13[3]; + +type JsonRecord14Array JsonRecord14[]; + +type ClosedJsonRecord14Array JsonRecord14[3]; + +type AnydataRecord1Array AnydataRecord1[]; + +type ClosedAnydataRecord1Array AnydataRecord1[3]; + +type AnydataRecord2Array AnydataRecord2[]; + +type ClosedAnydataRecord2Array AnydataRecord2[3]; + +type AnydataRecord3Array AnydataRecord3[]; + +type ClosedAnydataRecord3Array AnydataRecord3[3]; + +type AnydataRecord4Array AnydataRecord4[]; + +type ClosedAnydataRecord4Array AnydataRecord4[3]; + +type AnydataRecord5Array AnydataRecord5[]; + +type ClosedAnydataRecord5Array AnydataRecord5[3]; + +type AnydataRecord6Array AnydataRecord6[]; + +type ClosedAnydataRecord6Array AnydataRecord6[3]; + +type AnydataRecord7Array AnydataRecord7[]; + +type ClosedAnydataRecord7Array AnydataRecord7[3]; + +type AnydataRecord8Array AnydataRecord8[]; + +type ClosedAnydataRecord8Array AnydataRecord8[3]; + +type AnydataRecord9Array AnydataRecord9[]; + +type ClosedAnydataRecord9Array AnydataRecord9[3]; + +type AnydataRecord10Array AnydataRecord10[]; + +type ClosedAnydataRecord10Array AnydataRecord10[3]; + +type AnydataRecord11Array AnydataRecord11[]; + +type ClosedAnydataRecord11Array AnydataRecord11[3]; + +type AnydataRecord12Array AnydataRecord12[]; + +type ClosedAnydataRecord12Array AnydataRecord12[3]; + +type AnydataRecord13Array AnydataRecord13[]; + +type ClosedAnydataRecord13Array AnydataRecord13[3]; + +type AnydataRecord14Array AnydataRecord14[]; + +type ClosedAnydataRecord14Array AnydataRecord14[3]; + +type CustomRecord1Array CustomRecord1[]; + +type ClosedCustomRecord1Array CustomRecord1[3]; + +type CustomRecord2Array CustomRecord2[]; + +type ClosedCustomRecord2Array CustomRecord2[3]; + +type CustomRecord3Array CustomRecord3[]; + +type ClosedCustomRecord3Array CustomRecord3[3]; + +type CustomRecord4Array CustomRecord4[]; + +type ClosedCustomRecord4Array CustomRecord4[3]; + +type CustomRecord5Array CustomRecord5[]; + +type ClosedCustomRecord5Array CustomRecord5[3]; + +type CustomRecord6Array CustomRecord6[]; + +type ClosedCustomRecord6Array CustomRecord6[3]; + +type CustomRecord7Array CustomRecord7[]; + +type ClosedCustomRecord7Array CustomRecord7[3]; + +type CustomRecord8Array CustomRecord8[]; + +type ClosedCustomRecord8Array CustomRecord8[3]; + +type CustomRecord9Array CustomRecord9[]; + +type ClosedCustomRecord9Array CustomRecord9[3]; + +type CustomRecord10Array CustomRecord10[]; + +type ClosedCustomRecord10Array CustomRecord10[3]; + +type CustomRecord11Array CustomRecord11[]; + +type ClosedCustomRecord11Array CustomRecord11[3]; + +type CustomRecord12Array CustomRecord12[]; + +type ClosedCustomRecord12Array CustomRecord12[3]; + +type CustomRecord13Array CustomRecord13[]; + +type ClosedCustomRecord13Array CustomRecord13[3]; + +type CustomRecord14Array CustomRecord14[]; + +type ClosedCustomRecord14Array CustomRecord14[3]; + +type CustomRecord15Array CustomRecord15[]; + +type CustomRecord16Array CustomRecord16[]; + +type CustomRecord17Array CustomRecord17[]; + +type CustomRecord18Array CustomRecord18[]; + +type CustomRecord19Array CustomRecord19[]; + +type CustomRecord20Array CustomRecord20[]; + +type CustomRecord21Array CustomRecord21[]; + +type CustomRecord22Array CustomRecord22[]; + +type CustomRecord23Array CustomRecord23[]; + +type CustomRecord24Array CustomRecord24[]; + +type CustomRecord25Array CustomRecord25[]; + +type CustomRecord26Array CustomRecord26[]; + +type CustomRecord27Array CustomRecord27[]; +type CustomRecord28Array CustomRecord28[]; +type CustomRecord29Array CustomRecord29[]; +type CustomRecord30Array CustomRecord30[]; +type CustomRecord31Array CustomRecord31[]; +type CustomRecord32Array CustomRecord32[]; +type CustomRecord33Array CustomRecord33[]; +type CustomRecord34Array CustomRecord34[]; +type CustomRecord35Array CustomRecord35[]; +type CustomRecord36Array CustomRecord36[]; +type CustomRecord37Array CustomRecord37[]; +type CustomRecord38Array CustomRecord38[]; +type CustomRecord39Array CustomRecord39[]; +type CustomRecord40Array CustomRecord40[]; +type CustomRecord41Array CustomRecord41[]; +type CustomRecord42Array CustomRecord42[]; +type CustomRecord43Array CustomRecord43[]; +type CustomRecord44Array CustomRecord44[]; +type CustomRecord45Array CustomRecord45[]; +type CustomRecord46Array CustomRecord46[]; +type CustomRecord47Array CustomRecord47[]; +type CustomRecord48Array CustomRecord48[]; +type CustomRecord49Array CustomRecord49[]; +type CustomRecord50Array CustomRecord50[]; +type CustomRecord51Array CustomRecord51[]; +type CustomRecord52Array CustomRecord52[]; +type CustomRecord53Array CustomRecord53[]; +type CustomRecord54Array CustomRecord54[]; +type CustomRecord55Array CustomRecord55[]; +type CustomRecord56Array CustomRecord56[]; + +type BooleanTuple1Array BooleanTuple1[]; + +type ClosedBooleanTuple1Array BooleanTuple1[3]; + +type BooleanTuple2Array BooleanTuple2[]; + +type ClosedBooleanTuple2Array BooleanTuple2[3]; + +type BooleanTuple3Array BooleanTuple3[]; + +type ClosedBooleanTuple3Array BooleanTuple3[3]; + +type BooleanTuple4Array BooleanTuple4[]; + +type ClosedBooleanTuple4Array BooleanTuple4[3]; + +type NillableBooleanTuple5Array NillableBooleanTuple5[]; + +type NillableBooleanTuple6Array NillableBooleanTuple6[]; + +type NillableBooleanTuple7Array NillableBooleanTuple7[]; + +type NillableBooleanTuple8Array NillableBooleanTuple8[]; + +type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; + +type NilTuple1Array NilTuple1[]; + +type ClosedNilTuple1Array NilTuple1[3]; + +type NilTuple2Array NilTuple2[]; + +type ClosedNilTuple2Array NilTuple2[3]; + +type NilTuple3Array NilTuple3[]; + +type ClosedNilTuple3Array NilTuple3[3]; + +type NilTuple4Array NilTuple4[]; + +type ClosedNilTuple4Array NilTuple4[3]; + +type IntegerTuple1Array IntegerTuple1[]; + +type ClosedIntegerTuple1Array IntegerTuple1[3]; + +type IntegerTuple2Array IntegerTuple2[]; + +type ClosedIntegerTuple2Array IntegerTuple2[3]; + +type IntegerTuple3Array IntegerTuple3[]; + +type ClosedIntegerTuple3Array IntegerTuple3[3]; + +type IntegerTuple4Array IntegerTuple4[]; + +type ClosedIntegerTuple4Array IntegerTuple4[3]; + +type FloatTuple1Array FloatTuple1[]; + +type ClosedFloatTuple1Array FloatTuple1[3]; + +type FloatTuple2Array FloatTuple2[]; + +type ClosedFloatTuple2Array FloatTuple2[3]; + +type FloatTuple3Array FloatTuple3[]; + +type ClosedFloatTuple3Array FloatTuple3[3]; + +type FloatTuple4Array FloatTuple4[]; + +type ClosedFloatTuple4Array FloatTuple4[3]; + +type DecimalTuple1Array DecimalTuple1[]; + +type ClosedDecimalTuple1Array DecimalTuple1[3]; + +type DecimalTuple2Array DecimalTuple2[]; + +type ClosedDecimalTuple2Array DecimalTuple2[3]; + +type DecimalTuple3Array DecimalTuple3[]; + +type ClosedDecimalTuple3Array DecimalTuple3[3]; + +type DecimalTuple4Array DecimalTuple4[]; + +type ClosedDecimalTuple4Array DecimalTuple4[3]; + +type StringTuple1Array StringTuple1[]; + +type ClosedStringTuple1Array StringTuple1[3]; + +type StringTuple2Array StringTuple2[]; + +type ClosedStringTuple2Array StringTuple2[3]; + +type StringTuple3Array StringTuple3[]; + +type ClosedStringTuple3Array StringTuple3[3]; + +type StringTuple4Array StringTuple4[]; + +type ClosedStringTuple4Array StringTuple4[3]; + +type AnydataTuple1Array AnydataTuple1[]; + +type ClosedAnydataTuple1Array AnydataTuple1[3]; + +type AnydataTuple2Array AnydataTuple2[]; + +type ClosedAnydataTuple2Array AnydataTuple2[3]; + +type AnydataTuple3Array AnydataTuple3[]; + +type ClosedAnydataTuple3Array AnydataTuple3[3]; + +type AnydataTuple4Array AnydataTuple4[]; + +type ClosedAnydataTuple4Array AnydataTuple4[3]; + +type JsonTuple1Array JsonTuple1[]; + +type ClosedJsonTuple1Array JsonTuple1[3]; + +type JsonTuple2Array JsonTuple2[]; + +type ClosedJsonTuple2Array JsonTuple2[3]; + +type JsonTuple3Array JsonTuple3[]; + +type ClosedJsonTuple3Array JsonTuple3[3]; + +type JsonTuple4Array JsonTuple4[]; + +type ClosedJsonTuple4Array JsonTuple4[3]; + +type CustomTuple1Array CustomTuple1[]; + +type ClosedCustomTuple1Array CustomTuple1[3]; + +type CustomTuple2Array CustomTuple2[]; + +type ClosedCustomTuple2Array CustomTuple2[3]; + +type CustomTuple3Array CustomTuple3[]; + +type ClosedCustomTuple3Array CustomTuple3[3]; + +type CustomTuple4Array CustomTuple4[]; + +type ClosedCustomTuple4Array CustomTuple4[3]; + +type CustomTuple5Array CustomTuple5[]; + +type ClosedCustomTuple5Array CustomTuple5[3]; + +type CustomTuple6Array CustomTuple6[]; + +type CustomTuple7Array CustomTuple7[]; + +type CustomTuple8Array CustomTuple8[]; + +type ClosedCustomTuple6Array CustomTuple6[3]; + +type IntegerArray1Array IntegerArray1[]; + +type ClosedIntegerArray1Array IntegerArray1[3]; + +type IntegerArray2Array IntegerArray2[]; + +type ClosedIntegerArray2Array IntegerArray2[3]; + +type IntegerArray3Array IntegerArray3[]; + +type ClosedIntegerArray3Array IntegerArray3[3]; + +type IntegerArray4Array IntegerArray4[]; + +type ClosedIntegerArray4Array IntegerArray4[3]; + +type IntegerArray5Array IntegerArray5[]; + +type ClosedIntegerArray5Array IntegerArray5[3]; + +type IntegerArray6Array IntegerArray5[]; + +type ClosedIntegerArray6Array IntegerArray5[3]; + +type StringArray1Array StringArray1[]; + +type StringArrayArray StringArray[]; + +type NillableStringArrayArray NillableStringArray[]; + +type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; + +type ClosedStringArray1Array StringArray1[3]; + +type StringArray2Array StringArray2[]; + +type ClosedStringArray2Array StringArray2[3]; + +type StringArray3Array StringArray3[]; + +type ClosedStringArray3Array StringArray3[3]; + +type StringArray4Array StringArray4[]; + +type ClosedStringArray4Array StringArray4[3]; + +type StringArray5Array StringArray5[]; + +type ClosedStringArray5Array StringArray5[3]; + +type StringArray6Array StringArray5[]; + +type ClosedStringArray6Array StringArray5[3]; + +type FloatArray1Array FloatArray1[]; + +type ClosedFloatArray1Array FloatArray1[3]; + +type FloatArray2Array FloatArray2[]; + +type ClosedFloatArray2Array FloatArray2[3]; + +type FloatArray3Array FloatArray3[]; + +type ClosedFloatArray3Array FloatArray3[3]; + +type FloatArray4Array FloatArray4[]; + +type ClosedFloatArray4Array FloatArray4[3]; + +type FloatArray5Array FloatArray5[]; + +type ClosedFloatArray5Array FloatArray5[3]; + +type FloatArray6Array FloatArray5[]; + +type ClosedFloatArray6Array FloatArray5[3]; + +type DecimalArray1Array DecimalArray1[]; + +type ClosedDecimalArray1Array DecimalArray1[3]; + +type DecimalArray2Array DecimalArray2[]; + +type ClosedDecimalArray2Array DecimalArray2[3]; + +type DecimalArray3Array DecimalArray3[]; + +type ClosedDecimalArray3Array DecimalArray3[3]; + +type DecimalArray4Array DecimalArray4[]; + +type ClosedDecimalArray4Array DecimalArray4[3]; + +type DecimalArray5Array DecimalArray5[]; + +type ClosedDecimalArray5Array DecimalArray5[3]; + +type DecimalArray6Array DecimalArray5[]; + +type ClosedDecimalArray6Array DecimalArray5[3]; + +type BooleanArrayArray BooleanArray[]; + +type ClosedBooleanArrayArray BooleanArray[3]; + +type NillableBooleanArrayArray NillableBooleanArray[]; + +type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; + +type BooleanArray2Array BooleanArray2[]; + +type ClosedBooleanArray2Array BooleanArray2[3]; + +type BooleanArray3Array BooleanArray3[]; + +type ClosedBooleanArray3Array BooleanArray3[3]; + +type BooleanArray4Array BooleanArray4[]; + +type ClosedBooleanArray4Array BooleanArray4[3]; + +type BooleanArray5Array BooleanArray5[]; + +type ClosedBooleanArray5Array BooleanArray5[3]; + +type BooleanArray6Array BooleanArray5[]; + +type ClosedBooleanArray6Array BooleanArray5[3]; + +type NilArray1Array NilArray1[]; + +type ClosedNilArray1Array NilArray1[3]; + +type NilArray2Array NilArray2[]; + +type ClosedNilArray2Array NilArray2[3]; + +type NilArray3Array NilArray3[]; + +type ClosedNilArray3Array NilArray3[3]; + +type NilArray4Array NilArray4[]; + +type ClosedNilArray4Array NilArray4[3]; + +type NilArray5Array NilArray5[]; + +type ClosedNilArray5Array NilArray5[3]; + +type NilArray6Array NilArray5[]; + +type ClosedNilArray6Array NilArray5[3]; + +type JsonArray1Array JsonArray1[]; + +type ClosedJsonArray1Array JsonArray1[3]; + +type JsonArray2Array JsonArray2[]; + +type ClosedJsonArray2Array JsonArray2[3]; + +type JsonArray3Array JsonArray3[]; + +type ClosedJsonArray3Array JsonArray3[3]; + +type JsonArray4Array JsonArray4[]; + +type ClosedJsonArray4Array JsonArray4[3]; + +type JsonArray5Array JsonArray5[]; + +type ClosedJsonArray5Array JsonArray5[3]; + +type JsonArray6Array JsonArray5[]; + +type ClosedJsonArray6Array JsonArray5[3]; + +type AnydataArray1Array AnydataArray1[]; + +type ClosedAnydataArray1Array AnydataArray1[3]; + +type AnydataArray2Array AnydataArray2[]; + +type ClosedAnydataArray2Array AnydataArray2[3]; + +type AnydataArray3Array AnydataArray3[]; + +type ClosedAnydataArray3Array AnydataArray3[3]; + +type AnydataArray4Array AnydataArray4[]; + +type ClosedAnydataArray4Array AnydataArray4[3]; + +type AnydataArray5Array AnydataArray5[]; + +type ClosedAnydataArray5Array AnydataArray5[3]; + +type AnydataArray6Array AnydataArray5[]; + +type ClosedAnydataArray6Array AnydataArray5[3]; + +type CustomArray1Array CustomArray1[]; + +type ClosedCustomArray1Array CustomArray1[3]; + +type CustomArray2Array CustomArray2[]; + +type ClosedCustomArray2Array CustomArray2[3]; + +type CustomArray3Array CustomArray3[]; + +type ClosedCustomArray3Array CustomArray3[3]; + +type CustomArray4Array CustomArray4[]; + +type ClosedCustomArray4Array CustomArray4[3]; + +type CustomArray5Array CustomArray5[]; + +type ClosedCustomArray5Array CustomArray5[3]; + +type CustomArray6Array CustomArray5[]; + +type ClosedCustomArray6Array CustomArray5[3]; + +type IntegerMapArray IntegerMap[]; + +type ClosedIntegerMapArray IntegerMap[3]; + +type StringMapArray StringMap[]; + +type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; + +type IntUnionStringMapArray IntUnionStringMap[]; + +type ClosedStringMapArray StringMap[3]; + +type DecimalMapArray DecimalMap[]; + +type ClosedDecimalMapArray DecimalMap[3]; + +type FloatMapArray FloatMap[]; + +type ClosedFloatMapArray FloatMap[3]; + +type BooleanMapArray BooleanMap[]; + +type NillableBooleanMapArray NillableBooleanMap[]; + +type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; + +type IntUnionBooleanMapArray IntUnionBooleanMap[]; + +type ClosedBooleanMapArray BooleanMap[3]; + +type NilMapArray NilMap[]; + +type ClosedNilMapArray NilMap[3]; + +type JsonMapArray JsonMap[]; + +type ClosedJsonMapArray JsonMap[3]; + +type AnydataMapArray AnydataMap[]; + +type ClosedAnydataMapArray AnydataMap[3]; + +type CustomMapArray CustomMap[]; + +type ClosedCustomMapArray CustomMap[3]; diff --git a/ballerina-tests/type-compatible-tests/.gitignore b/ballerina-tests/type-compatible-tests/.gitignore new file mode 100644 index 0000000..d5fc29a --- /dev/null +++ b/ballerina-tests/type-compatible-tests/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/ballerina-tests/type-compatible-tests/Ballerina.toml b/ballerina-tests/type-compatible-tests/Ballerina.toml new file mode 100644 index 0000000..2d5ec74 --- /dev/null +++ b/ballerina-tests/type-compatible-tests/Ballerina.toml @@ -0,0 +1,13 @@ +[package] +org = "ballerina" +name = "type_compatible_tests" +version = "0.1.0" + +[[dependency]] +org = "ballerina" +name = "csv_commons" +repository = "local" +version = "0.1.0" + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina-tests/type-compatible-tests/Dependencies.toml b/ballerina-tests/type-compatible-tests/Dependencies.toml new file mode 100644 index 0000000..2e33529 --- /dev/null +++ b/ballerina-tests/type-compatible-tests/Dependencies.toml @@ -0,0 +1,98 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0" + +[[package]] +org = "ballerina" +name = "csv_commons" +version = "0.1.0" +scope = "testOnly" +modules = [ + {org = "ballerina", packageName = "csv_commons", moduleName = "csv_commons"} +] + +[[package]] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + +[[package]] +org = "ballerina" +name = "type_compatible_tests" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "csv_commons"}, + {org = "ballerina", name = "data.csv"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerina", packageName = "type_compatible_tests", moduleName = "type_compatible_tests"} +] + diff --git a/ballerina/tests/parse_string_compatibality_test.bal b/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal similarity index 78% rename from ballerina/tests/parse_string_compatibality_test.bal rename to ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal index 628b99d..c36c4c8 100644 --- a/ballerina/tests/parse_string_compatibality_test.bal +++ b/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal @@ -1,3 +1,5 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; import ballerina/test; @test:Config @@ -13,57 +15,57 @@ function testFromCsvStringWithTypeCompatibility() { ${i1}, ${s1},${b1}, null,${f1}, ${d1},${b1}, ${d1},${s2}, ${s3} `; - AnydataArray1Array|Error v3anyd1a = parseStringToList(value); + AnydataArray1Array|csv:Error v3anyd1a = csv:parseStringToList(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|Error vcr27a = parseStringToRecord(value, {}, CustomRecord27Array); + CustomRecord27Array|csv:Error vcr27a = csv:parseStringToRecord(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|Error v2cr27a = parseStringToRecord(value2, {}, CustomRecord27Array); + CustomRecord27Array|csv:Error v2cr27a = csv:parseStringToRecord(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|Error v3cr27a = parseStringToRecord(value3, {}); + CustomRecord27Array|csv:Error v3cr27a = csv:parseStringToRecord(value3, {}); test:assertEquals(v3cr27a, [ {i1, s1, b1, n1, f1, d1, a1: 2.234, j1: b1, defaultableField: "", nillableField: null, s2, s3} ]); - AnydataMapArray|Error vanydma = parseStringToRecord(value); + AnydataMapArray|csv:Error vanydma = csv:parseStringToRecord(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|Error vjma = parseStringToRecord(value); + JsonMapArray|csv:Error vjma = csv:parseStringToRecord(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|Error vsma = parseStringToRecord(value); + StringMapArray|csv:Error vsma = csv:parseStringToRecord(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|Error v2ct7a = parseStringToList(value2); + CustomTuple7Array|csv:Error v2ct7a = csv:parseStringToList(value2); test:assertEquals(v2ct7a, [ [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3, "false", "-3.21"] ]); - CustomTuple7Array|Error v3ct7a = parseStringToList(value3); + CustomTuple7Array|csv:Error v3ct7a = csv:parseStringToList(value3); test:assertEquals(v3ct7a, [ [i1, s1, b1, n1, 2.234, 2.234, b1, 2.234, s2, s3] ]); - [float, decimal, string][]|Error mrrta = parseStringToList(string `a, b,c + [float, decimal, string][]|csv:Error mrrta = csv:parseStringToList(string `a, b,c 1.23, 1.23, 1.23 0,0,0 0.0,0.0,0.0 @@ -75,7 +77,7 @@ function testFromCsvStringWithTypeCompatibility() { [-1.2, -1.2, "-1.2"] ]); - [float, decimal, string, int][]|Error m2rrta = parseStringToList(string `a, b,c,d + [float, decimal, string, int][]|csv:Error m2rrta = csv:parseStringToList(string `a, b,c,d 1, 1, 1,1 0,0,0,0 -1,-1,-1,-1`); @@ -85,12 +87,12 @@ function testFromCsvStringWithTypeCompatibility() { [-1, -1, "-1", -1] ]); - [int...][]|Error m3rrta = parseStringToList(string `a, b,c,d + [int...][]|csv:Error m3rrta = csv:parseStringToList(string `a, b,c,d 1.2, abc, true,1.0`); - test:assertTrue(m3rrta is Error); - test:assertEquals((m3rrta).message(), generateErrorMessageForInvalidCast("1.2", "int")); + test:assertTrue(m3rrta is csv:Error); + test:assertEquals((m3rrta).message(), common:generateErrorMessageForInvalidCast("1.2", "int")); - [boolean|int, int|boolean][]|Error m4rrta = parseStringToList(string `a, b + [boolean|int, int|boolean][]|csv:Error m4rrta = csv:parseStringToList(string `a, b 1, 1 0,0`); test:assertEquals(m4rrta, [ @@ -98,7 +100,7 @@ function testFromCsvStringWithTypeCompatibility() { [0, 0] ]); - record {|int...;|}[]|Error irrma = parseStringToRecord(string ` + record {|int...;|}[]|csv:Error irrma = csv:parseStringToRecord(string ` a, b, c 1, a, 2.3 1, -2, true @@ -109,7 +111,7 @@ function testFromCsvStringWithTypeCompatibility() { {b: i2} ]); - record {|()...;|}[]|Error nrrma = parseStringToRecord(string ` + record {|()...;|}[]|csv:Error nrrma = csv:parseStringToRecord(string ` a, b, c 1, a, () 1, null, () @@ -120,7 +122,7 @@ function testFromCsvStringWithTypeCompatibility() { {} ]); - record {|decimal...;|}[]|Error drra = parseStringToRecord(string `a, b, c + record {|decimal...;|}[]|csv:Error drra = csv:parseStringToRecord(string `a, b, c 2.234, invalid , 1 ${f2}, 0, 2.3d invalid, ${d2}, ${f3}`); @@ -131,7 +133,7 @@ function testFromCsvStringWithTypeCompatibility() { {b: -3.21d, c: f3} ]); - record {|string...;|}[]|Error srra = parseStringToRecord(string `a, b, c + record {|string...;|}[]|csv:Error srra = csv:parseStringToRecord(string `a, b, c 1, a, 2.3 1, -2, true hello, -2, hello`); @@ -142,7 +144,7 @@ function testFromCsvStringWithTypeCompatibility() { {a: "hello", b: "-2", c: "hello"} ]); - record {|float...;|}[]|Error frra = parseStringToRecord(string `a, b, c + record {|float...;|}[]|csv:Error frra = csv:parseStringToRecord(string `a, b, c 1.2, invalid , 1 ${d2}, ${d3}, true ${d4}, ${f2}, 0.0`); @@ -152,7 +154,7 @@ function testFromCsvStringWithTypeCompatibility() { {a: d4, b: f2, c: 0.0} ]); - record {float a; decimal b; string c;}[]|Error mrra = parseStringToRecord(string `a, b,c + record {float a; decimal b; string c;}[]|csv:Error mrra = csv:parseStringToRecord(string `a, b,c 1.23, 1.23, 1.23 0,0,0 0.0,0.0,0.0 @@ -164,7 +166,7 @@ function testFromCsvStringWithTypeCompatibility() { {a: -1.2, b: -1.2, c: "-1.2"} ]); - record {|float a; decimal b; string c; int d;|}[]|Error m2rra = parseStringToRecord(string `a, b,c,d + record {|float a; decimal b; string c; int d;|}[]|csv:Error m2rra = csv:parseStringToRecord(string `a, b,c,d 1, 1, 1,1 0,0,0,0 -1,-1,-1,-1`); @@ -174,8 +176,8 @@ function testFromCsvStringWithTypeCompatibility() { {a: -1, b: -1, c: "-1", d: -1} ]); - record {int d;}[]|Error m3rra = parseStringToRecord(string `a, b,c,d + record {int d;}[]|csv:Error m3rra = csv:parseStringToRecord(string `a, b,c,d 1.2, abc, true,1.0`); - test:assertTrue(m3rra is Error); - test:assertEquals((m3rra).message(), generateErrorMessageForInvalidCast("1.0", "int")); + test:assertTrue(m3rra is csv:Error); + test:assertEquals((m3rra).message(), common:generateErrorMessageForInvalidCast("1.0", "int")); } \ No newline at end of file diff --git a/ballerina/tests/parse_type_compatibility_test.bal b/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal similarity index 74% rename from ballerina/tests/parse_type_compatibility_test.bal rename to ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal index 681157a..d8ac07f 100644 --- a/ballerina/tests/parse_type_compatibility_test.bal +++ b/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal @@ -1,3 +1,5 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; import ballerina/test; @test:Config @@ -6,35 +8,35 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { var value2 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3, j2: b2, a2: d2}; var value3 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3}; - CustomRecord27Array|Error vcr27a = parseRecordAsRecordType([value, value, value], {}, CustomRecord27Array); + 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|Error vanydma = parseRecordAsRecordType([value, value, value], {}, AnydataMapArray); + AnydataMapArray|csv:Error vanydma = csv:parseRecordAsRecordType([value, value, value], {}, AnydataMapArray); test:assertEquals(vanydma , [ value, value, value ]); - JsonMapArray|Error vjma = parseRecordAsRecordType([value, value, value], {}, JsonMapArray); + JsonMapArray|csv:Error vjma = csv:parseRecordAsRecordType([value, value, value], {}, JsonMapArray); test:assertEquals(vjma , [ value, value, value ]); - record{|int...;|}[]|Error irrma = parseRecordAsRecordType([{"a": 1}, {"a": i1, "b": i2}, {"a": i1, "b": i2, "c": s1}]); + 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...;|}[]|Error drra = parseRecordAsRecordType([{"a": d1}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1, "d": f3}]); + 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}, @@ -42,21 +44,21 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {a: d4, b: -3.21d, d: f3} ]); - record{|string...;|}[]|Error srra = parseRecordAsRecordType([{"a": "string"}, {"c": 1, "a": s1, "b": s2}, {"a": b1, "b": s3, "c": d1}]); + 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...;|}[]|Error frra = parseRecordAsRecordType([{"a": 1.2, "b": 1.2f}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1}]); + 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;|}[]|Error fdc1a = parseRecordAsRecordType([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + 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}, @@ -64,7 +66,7 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {a: f2, b: d2} ]); - record{|float a; decimal ...;|}[]|Error fdc2a = parseRecordAsRecordType([{"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}, @@ -72,7 +74,7 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {a: f2, b: d2} ]); - record{|decimal b; float...;|}[]|Error fdc3a = parseRecordAsRecordType([{"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}, @@ -94,7 +96,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { readonly & int a; readonly & string b; (readonly & boolean) | (readonly & decimal) c; - }[]|Error r1a = parseStringToRecord( string `a,b,c + }[]|csv:Error r1a = csv:parseStringToRecord( string `a,b,c 1,string,true 2,string2,false 3,string3,true`); @@ -105,7 +107,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A a; B b; C c;}[]|Error r2a = parseStringToRecord( string `a,b,c + record{A a; B b; C c;}[]|csv:Error r2a = csv:parseStringToRecord( string `a,b,c 1,string,true 2,string2,false 3,string3,true`); @@ -116,7 +118,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A2 a; B2 b; C2 c;}[]|Error r3a = parseStringToRecord( string `a,b,c + record{A2 a; B2 b; C2 c;}[]|csv:Error r3a = csv:parseStringToRecord( string `a,b,c 1,string,true 2,string2,false 3,string3,true`); @@ -127,7 +129,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{|A2 a; B2 b; C2...;|}[]|Error r4a = parseStringToRecord( string ` + record{|A2 a; B2 b; C2...;|}[]|csv:Error r4a = csv:parseStringToRecord( string ` a,b,c,d 1,string,true,string 2,string2,false,string2 @@ -139,7 +141,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|Error r5a = parseStringToRecord( string `a,b,c,d + record{|C2...;|}[]|csv:Error r5a = csv:parseStringToRecord( string `a,b,c,d 1,string,true,string 2,string2,false,string2 3,string3,true,string3`); @@ -150,8 +152,8 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: "3", b: "string3", c: true, d: "string3"} ]); - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|Error r16a = - parseStringToList( string `a,b,c + [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error r16a = + csv:parseStringToList( string `a,b,c 1,string,true 2,string2,false 3,string3,true`); @@ -162,7 +164,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|Error r17a = parseStringToList( + [A, B, C][]|csv:Error r17a = csv:parseStringToList( string `a,b,c 1,string,true 2,string2,false @@ -174,7 +176,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2][]|Error r18a = parseStringToList( + [A2, B2, C2][]|csv:Error r18a = csv:parseStringToList( string `a,b,c 1,string,true 2,string2,false @@ -186,7 +188,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2...][]|Error r19a = parseStringToList( + [A2, B2, C2...][]|csv:Error r19a = csv:parseStringToList( string `a,b,c,d 1,string,true,string 2,string2,false,string2 @@ -198,7 +200,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true, "string3"] ]); - [C2...][]|Error r20a = parseStringToList( + [C2...][]|csv:Error r20a = csv:parseStringToList( string `a,b,c,d 1,string,true,string 2,string2,false,string2 @@ -208,7 +210,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); - record{A a; B b; C c;}[]|Error rt2a = parseRecordAsRecordType( + 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 , [ @@ -221,7 +223,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { readonly & int a; readonly & string b; (readonly & boolean) | (readonly & decimal) c; - }[]|Error rt1a = parseRecordAsRecordType( + }[]|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 , [ @@ -230,7 +232,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A2 a; B2 b; C2 c;}[]|Error rt3a = parseRecordAsRecordType( + 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 , [ @@ -239,7 +241,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{|A2 a; B2 b; C2...;|}[]|Error rt4a = parseRecordAsRecordType( + 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 , [ @@ -248,7 +250,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|Error rt5a = parseRecordAsRecordType( + 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 , [ @@ -257,8 +259,8 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {b: "string3", c: true, d: "string3"} ]); - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|Error rt6a = - parseRecordAsListType( + [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} @@ -270,7 +272,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|Error rt7a = parseRecordAsListType( + [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"]); @@ -280,7 +282,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2][]|Error rt8a = parseRecordAsListType( + [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"]); @@ -290,7 +292,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2...][]|Error rt9a = parseRecordAsListType( + [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"]); @@ -300,18 +302,18 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true, "string3"] ]); - [C2...][]|Error rt10a = parseRecordAsListType( + [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:assertTrue(rt10a is Error); - test:assertEquals((rt10a).message(), generateErrorMessageForInvalidValueForArrayType("1", "0", "data.csv:C2")); + 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; - }[]|Error rt11a = parseListAsRecordType( + }[]|csv:Error rt11a = csv:parseListAsRecordType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); test:assertEquals(rt11a , [ @@ -320,7 +322,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A a; B b; C c;}[]|Error rt12a = parseListAsRecordType( + 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 , [ @@ -329,14 +331,14 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A a; B b; C c;}[]|Error rt12a_2 = parseListAsRecordType( + 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 Error); - test:assertEquals((rt12a_2).message(), - generateErrorMessageForInvalidFieldType("1", "a")); + test:assertTrue(rt12a_2 is csv:Error); + test:assertEquals((rt12a_2).message(), + common:generateErrorMessageForInvalidFieldType("1", "a")); - record{string|decimal a; B b; C c;}[]|Error rt12a_3 = parseListAsRecordType( + 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 , [ @@ -345,7 +347,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A2 a; B2 b; C2 c;}[]|Error rt13a = parseListAsRecordType( + 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 , [ @@ -354,7 +356,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{|A2 a; B2 b; C2...;|}[]|Error rt14a = parseListAsRecordType( + 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"]); @@ -364,7 +366,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|Error rt15a = parseListAsRecordType( + record{|C2...;|}[]|csv:Error rt15a = csv:parseListAsRecordType( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] , ["a", "b", "c", "d"]); @@ -374,7 +376,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: "3", b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|Error rt15a_2 = parseListAsRecordType( + 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}); @@ -384,8 +386,8 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: "3",b: "string3", c: "true", d: "string3"} ]); - [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|Error rt16a = - parseListAsListType( + [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error rt16a = + csv:parseListAsListType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); @@ -396,7 +398,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|Error rt17a = parseListAsListType( + [A, B, C][]|csv:Error rt17a = csv:parseListAsListType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); test:assertEquals(rt17a , [ @@ -405,13 +407,13 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|Error rt17a_2 = parseListAsListType( + [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 Error); - test:assertEquals((rt17a_2).message(), generateErrorMessageForInvalidValueForArrayType("1", "0", "data.csv:A")); + test:assertTrue(rt17a_2 is csv:Error); + test:assertEquals((rt17a_2).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "0", "type_compatible_tests:A")); - [A2, B2, C2][]|Error rt18a = parseListAsListType( + [A2, B2, C2][]|csv:Error rt18a = csv:parseListAsListType( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); test:assertEquals(rt18a , [ @@ -420,7 +422,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2...][]|Error rt19a = parseListAsListType( + [A2, B2, C2...][]|csv:Error rt19a = csv:parseListAsListType( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); test:assertEquals(rt19a , [ @@ -429,7 +431,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true, "string3"] ]); - [C2...][]|Error rt20a = parseListAsListType( + [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"], diff --git a/ballerina-tests/type-compatible-tests/tests/test_data_values.bal b/ballerina-tests/type-compatible-tests/tests/test_data_values.bal new file mode 100644 index 0000000..360a493 --- /dev/null +++ b/ballerina-tests/type-compatible-tests/tests/test_data_values.bal @@ -0,0 +1,256 @@ +boolean b1 = true; +false b2 = false; +boolean? b3 = (); +boolean|int b4 = false; + +() n1 = (); +int? n2 = (); +() n3 = null; + +int i1 = 1; +int i2 = -2; +int i3 = int:MAX_VALUE; +int i4 = int:MIN_VALUE; +int i5 = 0; +2 i6 = 2; +int? i7 = (); +int|string i8 = 100; + +float f1 = 2.234; +float f2 = -3.21f; +float f3 = 0; +float f4 = float:Infinity; +float f5 = -float:Infinity; +float f6 = float:NaN; +2.3f f7 = 2.3; +float? f8 = (); +float|decimal f9 = 1.21; + +decimal d1 = 2.234; +decimal d2 = -3.21d; +decimal d3 = 0; +2.3d d4 = 2.3; +decimal? d5 = (); +decimal|int d6 = 1.21; + +string s1 = "string"; +string s2 = ""; +string:Char s3 = "a"; + +map bm1 = {b1, b2}; +map bm2 = {b1, b2, b3, n1, n3}; +map bm3 = {b1, b2, b3, b4, i1}; +map<()> bm4 = {n1, n3}; +map bm5 = {b1, b2, b3, b4:true}; + +map m5 = {i1, i2, i3, i4, i5, i6}; +map m6 = {f1, f2, f3, f4, f5, f6, f7}; +map m7 = {d1, d2, d3, d4}; +map m8 = {d1, f1, f9, f10: 1.23}; +map m9 = {s1, s2, s3}; +map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; +map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; + +boolean[] arr1 = [b1, b2]; +boolean?[] arr2 = [b1, b2, b3, n1, n3]; +(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; +()[] arr4 = [n1, n3]; +int[] arr5 = [i1, i2, i3, i4, i5, i6]; +float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; +decimal[] arr7 = [d1, d2, d3, d4]; +(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; +string[] arr9 = [s1, s2, s3]; +anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; + +[boolean, boolean] bt1 = [b1, b2]; +[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; +[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; +[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; +[boolean...] bt5 = [b1, b2]; + +[string, string] st1 = [s1, s2]; +[string, string, string, string] st2 = [s1, s2, s3, s2]; +[string...] st3 = [s1, s2]; +[string, string, string...] st4 = [s1, s2, s3, s2]; + +[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; +[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; +[string?...] st7 = [s1, s2]; +[string...] st8 = []; +[string, string, string] st9 = [s1, s2, s3]; + +[(), ()] tup4 = [n1, n3]; +[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; +[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; +[string, string, string] tup9 = [s1, s2, s3]; +[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, + n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, json] tup11 = + [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, + f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 +]; + +[boolean, boolean...] restTup1 = [b1, b2]; +[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; +[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; +[(), ()...] restTup4 = [n1, n3]; +[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; +[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal...] restTup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; +[string...] restTup9 = [s1, s2, s3]; +[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 +]; + +var booleanRecordArray = [ + {b1, b2, b3, b4}, {b1, b2, b3, b4} +]; + +var booleanRecordArray2 = [ + {},{} +]; + +string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 +true,false,true,false +true,false, true,false +true,false,true,false +`; + +string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 +true,false, true,false,true +true,false, true,false,true`; + +string csvStringWithBooleanValues3 = string `b1,b2,b3 +${" "}${"\t"} +true, false,true +${" "} + TRUE, FALSE,() +${" "} + +true, true,FALSE + +`; + +string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 + true,(), (),false + true,(), null,false + +`; + +string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 + +true,false,true,2 + +true,false,true,3 +`; + +string csvStringWithBooleanValues6 = string `b2,b3 +(),() + +`; + +string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 +${b1},${b2},(),${b4} +`; + +string csvStringData1 = string ` + a, b, c, d, e, f + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData2 = string ` + hello, hello, (), 12, true, 12.34 + // comment + + a, b, c, d, e, f + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData3 = string ` + a, b, c, d, e, f + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData4 = string ` + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData5 = string ` + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData6 = string ` + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData7 = string ` + a@ b@ c@ d@ e@ f + 1@ string@ true@ 2.234@ -3.21@ () + 2@ s,tring@ true@ 2.234@ -3.21@ null + 3@ stri,ng@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; +string csvStringData8 = string ` + a@ b@ c@ d@ e@ f + + + + 1@ stri,ng@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ ()@-3.21 + 3@ string@ true@ 2.234@ -3.21@ null + + 4@ s,tring@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; + +string csvStringData9 = string ` + + 1@ string@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ -3.21@ null + + 3@ string@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ ()@-3.21 + + 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina-tests/type-compatible-tests/tests/types.bal b/ballerina-tests/type-compatible-tests/tests/types.bal new file mode 100644 index 0000000..a2b4b2b --- /dev/null +++ b/ballerina-tests/type-compatible-tests/tests/types.bal @@ -0,0 +1,2534 @@ +type BooleanRecord1 record { + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +}; + +type BooleanRecord2 record {| + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +|}; + +type BooleanRecord3 record {| + boolean b1; + boolean? b3; +|}; + +type BooleanRecord4 record { + boolean b1; + boolean? b3; +}; + +type BooleanRecord5 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +}; + +type BooleanRecord6 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +|}; + +type BooleanRecord7 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type BooleanRecord8 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type BooleanRecord9 record {| + boolean b1; + boolean? b3; + boolean?...; +|}; + +type BooleanRecord10 record {| + boolean...; +|}; + +type BooleanRecord11 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + boolean?|string...; +|}; + +type BooleanRecord12 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string|boolean...; +|}; + +type BooleanRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord15 record {| + int b1; + string defaultableField = ""; + string? nillableField = (); + boolean?...; +|}; + +type BooleanRecord16 record {| + boolean?...; +|}; + +type BooleanRecord17 record {| + int...; +|}; + +type BooleanRecord18 record {| + boolean b2; + int?...; +|}; + +type NilRecord1 record { + () n1; + () n2; + () n3; +}; + +type NilRecord2 record {| + () n1; + () n2; + () n3; +|}; + +type NilRecord3 record {| + () n1; + () n4; +|}; + +type NilRecord4 record { + () n1; + () n4; +}; + +type NilRecord5 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +}; + +type NilRecord6 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type NilRecord7 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type NilRecord8 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type NilRecord9 record {| + () n1; + () n2; + ()...; +|}; + +type NilRecord10 record {| + ()...; +|}; + +type NilRecord11 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord12 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type NilRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type IntegerRecord1 record { + int i1; + int i2; + int i3; + int? i4; + int? i5; + int i6; + int i7; + int? i8; +}; + +type IntegerRecord2 record {| + int i1; + int? i2; + int i3; + int i4; + int? i5; + int i6; + int i7; + int? i8; +|}; + +type IntegerRecord3 record {| + int i1; + int i4; + int i6; +|}; + +type IntegerRecord4 record { + int i1; + int i4; + int i6; +}; + +type IntegerRecord5 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +}; + +type IntegerRecord6 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +|}; + +type IntegerRecord7 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type IntegerRecord8 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type IntegerRecord9 record {| + int i1; + int i2; + int...; +|}; + +type IntegerRecord10 record {| + int...; +|}; + +type IntegerRecord11 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord12 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type IntegerRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type FloatRecord1 record { + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +}; + +type FloatRecord2 record {| + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +|}; + +type FloatRecord3 record {| + float f1; + float f4; + float f7; +|}; + +type FloatRecord4 record { + float f1; + float f4; + float f7; +}; + +type FloatRecord5 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +}; + +type FloatRecord6 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type FloatRecord7 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type FloatRecord8 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type FloatRecord9 record {| + float f1; + float f2; + float...; +|}; + +type FloatRecord10 record {| + float...; +|}; + +type FloatRecord11 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord12 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type FloatRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type DecimalRecord1 record { + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +}; + +type DecimalRecord2 record {| + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +|}; + +type DecimalRecord3 record {| + decimal d1; + decimal d4; + decimal d7; +|}; + +type DecimalRecord4 record { + decimal d1; + decimal d4; + decimal d7; +}; + +type DecimalRecord5 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +}; + +type DecimalRecord6 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type DecimalRecord7 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type DecimalRecord8 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type DecimalRecord9 record {| + decimal d1; + decimal d2; + decimal...; +|}; + +type DecimalRecord10 record {| + decimal...; +|}; + +type DecimalRecord11 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord12 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type DecimalRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type StringRecord1 record { + string s1; + string s2; + string s3; +}; + +type StringRecord2 record {| + string s1; + string s2; + string s3; +|}; + +type StringRecord3 record {| + string s1; + string s4; +|}; + +type StringRecord4 record { + string s1; + string s4; +}; + +type StringRecord5 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +}; + +type StringRecord6 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type StringRecord7 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type StringRecord8 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type StringRecord9 record {| + string s1; + string s2; + string...; +|}; + +type StringRecord10 record {| + string...; +|}; + +type StringRecord11 record {| + string s1; + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord12 record {| + string d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord15 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord16 record {| + string?...; +|}; + +type StringRecord17 record {| + int...; +|}; + +type StringRecord18 record {| + string b2; + int?...; +|}; + +type StringRecord19 record { + string s1 = ""; + string s2 = ""; +}; + +type StringRecord20 record {| + string s1 = ""; + string s2 = ""; +|}; + +type StringRecord21 record { +}; + +type StringRecord22 record {| + string s1 = ""; + string s2 = ""; + json...; +|}; + +type StringRecord23 record {| + json...; +|}; + +type JsonRecord1 record { + json j1; + json j2; + json j3; +}; + +type JsonRecord2 record {| + json j1; + json j2; + json j3; +|}; + +type JsonRecord3 record {| + json j1; + json j4; +|}; + +type JsonRecord4 record { + json j1; + json j4; +}; + +type JsonRecord5 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +}; + +type JsonRecord6 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +|}; + +type JsonRecord7 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +}; + +type JsonRecord8 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +|}; + +type JsonRecord9 record {| + json j1; + json j2; + json...; +|}; + +type JsonRecord10 record {| + json...; +|}; + +type JsonRecord11 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord12 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type JsonRecord13 record {| + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord14 record {| + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type AnydataRecord1 record { + anydata anydata1; + anydata anydata2; + anydata anydata3; +}; + +type AnydataRecord2 record {| + anydata anydata1; + anydata anydata2; + anydata anydata3; +|}; + +type AnydataRecord3 record {| + anydata anydata1; + anydata anydata4; +|}; + +type AnydataRecord4 record { + anydata anydata1; + anydata anydata4; +}; + +type AnydataRecord5 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +}; + +type AnydataRecord6 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type AnydataRecord7 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type AnydataRecord8 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type AnydataRecord9 record {| + anydata anydata1; + anydata anydata2; + anydata...; +|}; + +type AnydataRecord10 record {| + anydata...; +|}; + +type AnydataRecord11 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord12 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type AnydataRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type CustomRecord1 record { + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +}; + +type CustomRecord2 record {| + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +|}; + +type CustomRecord3 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +|}; + +type CustomRecord4 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +}; + +type CustomRecord5 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string defaultableField = ""; + string? nillableField = (); +}; + +type CustomRecord6 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type CustomRecord7 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type CustomRecord8 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type CustomRecord9 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string...; +|}; + +type CustomRecord10 record {| + string...; +|}; + +type CustomRecord11 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord12 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomRecord15 record {| + string '1; + string '2; +|}; + +type CustomRecord16 record {| + string '1; + string '2; + string '3; + string '4; +|}; + +type CustomRecord17 record { + string '1; + string '2; +}; + +type CustomRecord18 record { + string '1; + string '2; + string '3; + string '4; +}; + +type CustomRecord19 record { + string '1; + string '2; + string '3 = ""; + string '4 = ""; +}; + +type CustomRecord20 record { + string '1; +}; + +type CustomRecord21 record {| + string '1; + json...; +|}; + +type CustomRecord22 record {| + string '1; + string...; +|}; + +type CustomRecord23 record {| + string '1; + string a = ""; + string...; +|}; + +type CustomRecord24 record {| + string '1; + string '2 = ""; + string...; +|}; + +type CustomRecord25 record {| + int '1; + string...; +|}; + +type CustomRecord26 record {| + string '1; + int...; +|}; + +type CustomRecord27 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata a1; + json j1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord28 record { + string '1; +}; + +type CustomRecord29 record { + int '1; +}; + +type CustomRecord30 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord31 record {| + string '1; + string '6; +|}; + +type CustomRecord32 record {| + int '1; +|}; + +type CustomRecord33 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord34 record { + string '1; + string '6; + string '5 = ""; +}; + +type CustomRecord35 record { + string '1; + string '6; + string '9 = ""; +}; + +type CustomRecord36 record {| + string '1; + string '6; + string '9 = ""; +|}; + +type CustomRecord37 record {| + string '1; + string '6; + string '5 = ""; +|}; + +type CustomRecord38 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + string ...; +|}; + +type CustomRecord39 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + json ...; +|}; + +type CustomRecord40 record {| + string '5; + string '6; + json ...; +|}; + +type CustomRecord41 record {| + json ...; +|}; + +type CustomRecord42 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +|}; + +type CustomRecord43 record { + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +}; + +type CustomRecord44 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; + string ...; +|}; + +type CustomRecord45 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +|}; + +type CustomRecord46 record { + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +}; + +type CustomRecord47 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; + string ...; +|}; + +type CustomRecord48 record { + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +}; + +type CustomRecord49 record {| + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +|}; + +type CustomRecord50 record { + int H1; + float H4; +}; + +type CustomRecord51 record {| + int H1; + float H4; +|}; + +type CustomRecord52 record {| + string H1; + string H4; + string ...; +|}; + +type CustomRecord53 record {| + int H1; + float H4; + decimal ...; +|}; + +type CustomRecord54 record {| + string H1 = ""; + string H4; + string '1; +|}; + +type CustomRecord55 record {| + string H1 = ""; + string H4 = ""; + int '1 = 10; +|}; + +type CustomRecord56 record { + string H1 = ""; + string H4 = ""; + anydata '1 = 10; +}; + +type BooleanTuple1 [boolean, boolean, boolean, boolean]; + +type BooleanTuple2 [boolean, boolean]; + +type BooleanTuple3 [boolean, boolean...]; + +type BooleanTuple4 [boolean...]; + +type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; + +type NillableBooleanTuple6 [boolean?, boolean?]; + +type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; + +type NillableBooleanTuple8 [boolean?...]; + +type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; + +type NilTuple1 [(), (), ()]; + +type NilTuple2 [(), ()]; + +type NilTuple3 [(), ()...]; + +type NilTuple4 [()...]; + +type IntegerTuple1 [int, int, int, int, int, int]; + +type IntegerTuple2 [int, int]; + +type IntegerTuple3 [int, int...]; + +type IntegerTuple4 [int...]; + +type FloatTuple1 [float, float, float, float, float, float, float]; + +type FloatTuple2 [float, float]; + +type FloatTuple3 [float, float...]; + +type FloatTuple4 [float...]; + +type DecimalTuple1 [decimal, decimal, decimal, decimal]; + +type DecimalTuple2 [decimal, decimal]; + +type DecimalTuple3 [decimal, decimal...]; + +type DecimalTuple4 [decimal...]; + +type StringTuple1 [string, string, string, string]; + +type StringTuple2 [string, string]; + +type StringTuple3 [string, string...]; + +type StringTuple4 [string...]; + +type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata]; + +type AnydataTuple2 [anydata, anydata]; + +type AnydataTuple3 [anydata, anydata...]; + +type AnydataTuple4 [anydata...]; + +type JsonTuple1 [json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json]; + +type JsonTuple2 [json, json]; + +type JsonTuple3 [json, json...]; + +type JsonTuple4 [json...]; + +type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; + +type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; + +type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; + +type CustomTuple4 [string...]; + +type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; + +type CustomTuple6 [anydata...]; + +type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; + +type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; + +type IntegerArray1 int[]; + +type IntegerArray2 int[2]; + +type IntegerArray3 int[]; + +type IntegerArray4 int[2]; + +type IntegerArray5 int[3]; + +type IntegerArray6 int[4]; + +type StringArray string[]; + +type NillableStringArray string?[]; + +type NillableIntOrUnionStringArray (int|string?)[]; + +type StringArray1 string[]; + +type StringArray2 string[2]; + +type StringArray3 string[]; + +type StringArray4 string[2]; + +type StringArray5 string[3]; + +type StringArray6 string[4]; + +type FloatArray1 float[]; + +type FloatArray2 float[2]; + +type FloatArray3 float[]; + +type FloatArray4 float[2]; + +type FloatArray5 float[3]; + +type FloatArray6 float[4]; + +type DecimalArray1 decimal[]; + +type DecimalArray2 decimal[2]; + +type DecimalArray3 decimal[]; + +type DecimalArray4 decimal[2]; + +type DecimalArray5 decimal[3]; + +type DecimalArray6 decimal[4]; + +type BooleanArray boolean[]; + +type NillableBooleanArray boolean?[]; + +type NillableIntOrUnionBooleanArray (int|boolean?)[]; + +type BooleanArray2 boolean[2]; + +type BooleanArray3 boolean[3]; + +type BooleanArray4 boolean[]; + +type BooleanArray5 boolean[2]; + +type BooleanArray6 boolean[4]; + +type NilArray1 ()[]; + +type NilArray2 ()[2]; + +type NilArray3 ()[]; + +type NilArray4 ()[2]; + +type NilArray5 ()[3]; + +type NilArray6 ()[4]; + +type JsonArray1 json[]; + +type JsonArray2 json[2]; + +type JsonArray3 json[]; + +type JsonArray4 json[2]; + +type JsonArray5 json[3]; + +type JsonArray6 json[4]; + +type AnydataArray1 anydata[]; + +type AnydataArray2 anydata[2]; + +type AnydataArray3 anydata[]; + +type AnydataArray4 anydata[2]; + +type AnydataArray5 anydata[3]; + +type AnydataArray6 anydata[4]; + +type CustomArray1 CustomTuple2[]; + +type CustomArray2 CustomTuple2[2]; + +type CustomArray3 CustomTuple2[]; + +type CustomArray4 CustomTuple2[2]; + +type CustomArray5 CustomTuple2[3]; + +type CustomArray6 CustomTuple2[4]; + +type IntegerMap map; + +type StringMap map; + +type NillableIntUnionStringMap map; + +type IntUnionStringMap map; + +type DecimalMap map; + +type FloatMap map; + +type BooleanMap map; + +type NillableBooleanMap map; + +type NillableIntUnionBooleanMap map; + +type IntUnionBooleanMap map; + +type NilMap map<()>; + +type JsonMap map; + +type AnydataMap map; + +type CustomMap map; + +type BooleanRecord1Array BooleanRecord1[]; + +type ClosedBooleanRecord1Array BooleanRecord1[3]; + +type BooleanRecord2Array BooleanRecord2[]; + +type ClosedBooleanRecord2Array BooleanRecord2[3]; + +type BooleanRecord3Array BooleanRecord3[]; + +type ClosedBooleanRecord3Array BooleanRecord3[3]; + +type BooleanRecord4Array BooleanRecord4[]; + +type ClosedBooleanRecord4Array BooleanRecord4[3]; + +type BooleanRecord5Array BooleanRecord5[]; + +type ClosedBooleanRecord5Array BooleanRecord5[3]; + +type BooleanRecord6Array BooleanRecord6[]; + +type ClosedBooleanRecord6Array BooleanRecord6[3]; + +type BooleanRecord7Array BooleanRecord7[]; + +type ClosedBooleanRecord7Array BooleanRecord7[3]; + +type BooleanRecord8Array BooleanRecord8[]; + +type ClosedBooleanRecord8Array BooleanRecord8[3]; + +type BooleanRecord9Array BooleanRecord9[]; + +type ClosedBooleanRecord9Array BooleanRecord9[3]; + +type BooleanRecord10Array BooleanRecord10[]; + +type ClosedBooleanRecord10Array BooleanRecord10[3]; + +type BooleanRecord11Array BooleanRecord11[]; + +type ClosedBooleanRecord11Array BooleanRecord11[3]; + +type BooleanRecord12Array BooleanRecord12[]; + +type ClosedBooleanRecord12Array BooleanRecord12[3]; + +type BooleanRecord13Array BooleanRecord13[]; + +type ClosedBooleanRecord13Array BooleanRecord13[3]; + +type BooleanRecord14Array BooleanRecord14[]; + +type ClosedBooleanRecord14Array BooleanRecord14[3]; + +type BooleanRecord15Array BooleanRecord15[]; + +type ClosedBooleanRecord15Array BooleanRecord15[3]; + +type BooleanRecord16Array BooleanRecord16[]; + +type ClosedBooleanRecord16Array BooleanRecord16[3]; + +type BooleanRecord17Array BooleanRecord17[]; + +type ClosedBooleanRecord17Array BooleanRecord17[3]; + +type BooleanRecord18Array BooleanRecord18[]; + +type ClosedBooleanRecord18Array BooleanRecord18[3]; + +type NilRecord1Array NilRecord1[]; + +type ClosedNilRecord1Array NilRecord1[3]; + +type NilRecord2Array NilRecord2[]; + +type ClosedNilRecord2Array NilRecord2[3]; + +type NilRecord3Array NilRecord3[]; + +type ClosedNilRecord3Array NilRecord3[3]; + +type NilRecord4Array NilRecord4[]; + +type ClosedNilRecord4Array NilRecord4[3]; + +type NilRecord5Array NilRecord5[]; + +type ClosedNilRecord5Array NilRecord5[3]; + +type NilRecord6Array NilRecord6[]; + +type ClosedNilRecord6Array NilRecord6[3]; + +type NilRecord7Array NilRecord7[]; + +type ClosedNilRecord7Array NilRecord7[3]; + +type NilRecord8Array NilRecord8[]; + +type ClosedNilRecord8Array NilRecord8[3]; + +type NilRecord9Array NilRecord9[]; + +type ClosedNilRecord9Array NilRecord9[3]; + +type NilRecord10Array NilRecord10[]; + +type ClosedNilRecord10Array NilRecord10[3]; + +type NilRecord11Array NilRecord11[]; + +type ClosedNilRecord11Array NilRecord11[3]; + +type NilRecord12Array NilRecord12[]; + +type ClosedNilRecord12Array NilRecord12[3]; + +type NilRecord13Array NilRecord13[]; + +type ClosedNilRecord13Array NilRecord13[3]; + +type NilRecord14Array NilRecord14[]; + +type ClosedNilRecord14Array NilRecord14[3]; + +type IntegerRecord1Array IntegerRecord1[]; + +type ClosedIntegerRecord1Array IntegerRecord1[3]; + +type IntegerRecord2Array IntegerRecord2[]; + +type ClosedIntegerRecord2Array IntegerRecord2[3]; + +type IntegerRecord3Array IntegerRecord3[]; + +type ClosedIntegerRecord3Array IntegerRecord3[3]; + +type IntegerRecord4Array IntegerRecord4[]; + +type ClosedIntegerRecord4Array IntegerRecord4[3]; + +type IntegerRecord5Array IntegerRecord5[]; + +type ClosedIntegerRecord5Array IntegerRecord5[3]; + +type IntegerRecord6Array IntegerRecord6[]; + +type ClosedIntegerRecord6Array IntegerRecord6[3]; + +type IntegerRecord7Array IntegerRecord7[]; + +type ClosedIntegerRecord7Array IntegerRecord7[3]; + +type IntegerRecord8Array IntegerRecord8[]; + +type ClosedIntegerRecord8Array IntegerRecord8[3]; + +type IntegerRecord9Array IntegerRecord9[]; + +type ClosedIntegerRecord9Array IntegerRecord9[3]; + +type IntegerRecord10Array IntegerRecord10[]; + +type ClosedIntegerRecord10Array IntegerRecord10[3]; + +type IntegerRecord11Array IntegerRecord11[]; + +type ClosedIntegerRecord11Array IntegerRecord11[3]; + +type IntegerRecord12Array IntegerRecord12[]; + +type ClosedIntegerRecord12Array IntegerRecord12[3]; + +type IntegerRecord13Array IntegerRecord13[]; + +type ClosedIntegerRecord13Array IntegerRecord13[3]; + +type IntegerRecord14Array IntegerRecord14[]; + +type ClosedIntegerRecord14Array IntegerRecord14[3]; + +type FloatRecord1Array FloatRecord1[]; + +type ClosedFloatRecord1Array FloatRecord1[3]; + +type FloatRecord2Array FloatRecord2[]; + +type ClosedFloatRecord2Array FloatRecord2[3]; + +type FloatRecord3Array FloatRecord3[]; + +type ClosedFloatRecord3Array FloatRecord3[3]; + +type FloatRecord4Array FloatRecord4[]; + +type ClosedFloatRecord4Array FloatRecord4[3]; + +type FloatRecord5Array FloatRecord5[]; + +type ClosedFloatRecord5Array FloatRecord5[3]; + +type FloatRecord6Array FloatRecord6[]; + +type ClosedFloatRecord6Array FloatRecord6[3]; + +type FloatRecord7Array FloatRecord7[]; + +type ClosedFloatRecord7Array FloatRecord7[3]; + +type FloatRecord8Array FloatRecord8[]; + +type ClosedFloatRecord8Array FloatRecord8[3]; + +type FloatRecord9Array FloatRecord9[]; + +type ClosedFloatRecord9Array FloatRecord9[3]; + +type FloatRecord10Array FloatRecord10[]; + +type ClosedFloatRecord10Array FloatRecord10[3]; + +type FloatRecord11Array FloatRecord11[]; + +type ClosedFloatRecord11Array FloatRecord11[3]; + +type FloatRecord12Array FloatRecord12[]; + +type ClosedFloatRecord12Array FloatRecord12[3]; + +type FloatRecord13Array FloatRecord13[]; + +type ClosedFloatRecord13Array FloatRecord13[3]; + +type FloatRecord14Array FloatRecord14[]; + +type ClosedFloatRecord14Array FloatRecord14[3]; + +type DecimalRecord1Array DecimalRecord1[]; + +type ClosedDecimalRecord1Array DecimalRecord1[3]; + +type DecimalRecord2Array DecimalRecord2[]; + +type ClosedDecimalRecord2Array DecimalRecord2[3]; + +type DecimalRecord3Array DecimalRecord3[]; + +type ClosedDecimalRecord3Array DecimalRecord3[3]; + +type DecimalRecord4Array DecimalRecord4[]; + +type ClosedDecimalRecord4Array DecimalRecord4[3]; + +type DecimalRecord5Array DecimalRecord5[]; + +type ClosedDecimalRecord5Array DecimalRecord5[3]; + +type DecimalRecord6Array DecimalRecord6[]; + +type ClosedDecimalRecord6Array DecimalRecord6[3]; + +type DecimalRecord7Array DecimalRecord7[]; + +type ClosedDecimalRecord7Array DecimalRecord7[3]; + +type DecimalRecord8Array DecimalRecord8[]; + +type ClosedDecimalRecord8Array DecimalRecord8[3]; + +type DecimalRecord9Array DecimalRecord9[]; + +type ClosedDecimalRecord9Array DecimalRecord9[3]; + +type DecimalRecord10Array DecimalRecord10[]; + +type ClosedDecimalRecord10Array DecimalRecord10[3]; + +type DecimalRecord11Array DecimalRecord11[]; + +type ClosedDecimalRecord11Array DecimalRecord11[3]; + +type DecimalRecord12Array DecimalRecord12[]; + +type ClosedDecimalRecord12Array DecimalRecord12[3]; + +type DecimalRecord13Array DecimalRecord13[]; + +type ClosedDecimalRecord13Array DecimalRecord13[3]; + +type DecimalRecord14Array DecimalRecord14[]; + +type ClosedDecimalRecord14Array DecimalRecord14[3]; + +type StringRecord1Array StringRecord1[]; + +type ClosedStringRecord1Array StringRecord1[3]; + +type StringRecord2Array StringRecord2[]; + +type ClosedStringRecord2Array StringRecord2[3]; + +type StringRecord3Array StringRecord3[]; + +type ClosedStringRecord3Array StringRecord3[3]; + +type StringRecord4Array StringRecord4[]; + +type ClosedStringRecord4Array StringRecord4[3]; + +type StringRecord5Array StringRecord5[]; + +type ClosedStringRecord5Array StringRecord5[3]; + +type StringRecord6Array StringRecord6[]; + +type ClosedStringRecord6Array StringRecord6[3]; + +type StringRecord7Array StringRecord7[]; + +type ClosedStringRecord7Array StringRecord7[3]; + +type StringRecord8Array StringRecord8[]; + +type ClosedStringRecord8Array StringRecord8[3]; + +type StringRecord9Array StringRecord9[]; + +type ClosedStringRecord9Array StringRecord9[3]; + +type StringRecord10Array StringRecord10[]; + +type ClosedStringRecord10Array StringRecord10[3]; + +type StringRecord11Array StringRecord11[]; + +type ClosedStringRecord11Array StringRecord11[3]; + +type StringRecord12Array StringRecord12[]; + +type ClosedStringRecord12Array StringRecord12[3]; + +type StringRecord13Array StringRecord13[]; + +type ClosedStringRecord13Array StringRecord13[3]; + +type StringRecord14Array StringRecord14[]; + +type ClosedStringRecord14Array StringRecord14[3]; + +type StringRecord15Array StringRecord15[]; + +type StringRecord16Array StringRecord16[]; + +type StringRecord17Array StringRecord17[]; + +type StringRecord18Array StringRecord18[]; + +type StringRecord19Array StringRecord19[]; + +type StringRecord20Array StringRecord20[]; + +type StringRecord21Array StringRecord21[]; + +type StringRecord22Array StringRecord22[]; + +type StringRecord23Array StringRecord23[]; + +type JsonRecord1Array JsonRecord1[]; + +type ClosedJsonRecord1Array JsonRecord1[3]; + +type JsonRecord2Array JsonRecord2[]; + +type ClosedJsonRecord2Array JsonRecord2[3]; + +type JsonRecord3Array JsonRecord3[]; + +type ClosedJsonRecord3Array JsonRecord3[3]; + +type JsonRecord4Array JsonRecord4[]; + +type ClosedJsonRecord4Array JsonRecord4[3]; + +type JsonRecord5Array JsonRecord5[]; + +type ClosedJsonRecord5Array JsonRecord5[3]; + +type JsonRecord6Array JsonRecord6[]; + +type ClosedJsonRecord6Array JsonRecord6[3]; + +type JsonRecord7Array JsonRecord7[]; + +type ClosedJsonRecord7Array JsonRecord7[3]; + +type JsonRecord8Array JsonRecord8[]; + +type ClosedJsonRecord8Array JsonRecord8[3]; + +type JsonRecord9Array JsonRecord9[]; + +type ClosedJsonRecord9Array JsonRecord9[3]; + +type JsonRecord10Array JsonRecord10[]; + +type ClosedJsonRecord10Array JsonRecord10[3]; + +type JsonRecord11Array JsonRecord11[]; + +type ClosedJsonRecord11Array JsonRecord11[3]; + +type JsonRecord12Array JsonRecord12[]; + +type ClosedJsonRecord12Array JsonRecord12[3]; + +type JsonRecord13Array JsonRecord13[]; + +type ClosedJsonRecord13Array JsonRecord13[3]; + +type JsonRecord14Array JsonRecord14[]; + +type ClosedJsonRecord14Array JsonRecord14[3]; + +type AnydataRecord1Array AnydataRecord1[]; + +type ClosedAnydataRecord1Array AnydataRecord1[3]; + +type AnydataRecord2Array AnydataRecord2[]; + +type ClosedAnydataRecord2Array AnydataRecord2[3]; + +type AnydataRecord3Array AnydataRecord3[]; + +type ClosedAnydataRecord3Array AnydataRecord3[3]; + +type AnydataRecord4Array AnydataRecord4[]; + +type ClosedAnydataRecord4Array AnydataRecord4[3]; + +type AnydataRecord5Array AnydataRecord5[]; + +type ClosedAnydataRecord5Array AnydataRecord5[3]; + +type AnydataRecord6Array AnydataRecord6[]; + +type ClosedAnydataRecord6Array AnydataRecord6[3]; + +type AnydataRecord7Array AnydataRecord7[]; + +type ClosedAnydataRecord7Array AnydataRecord7[3]; + +type AnydataRecord8Array AnydataRecord8[]; + +type ClosedAnydataRecord8Array AnydataRecord8[3]; + +type AnydataRecord9Array AnydataRecord9[]; + +type ClosedAnydataRecord9Array AnydataRecord9[3]; + +type AnydataRecord10Array AnydataRecord10[]; + +type ClosedAnydataRecord10Array AnydataRecord10[3]; + +type AnydataRecord11Array AnydataRecord11[]; + +type ClosedAnydataRecord11Array AnydataRecord11[3]; + +type AnydataRecord12Array AnydataRecord12[]; + +type ClosedAnydataRecord12Array AnydataRecord12[3]; + +type AnydataRecord13Array AnydataRecord13[]; + +type ClosedAnydataRecord13Array AnydataRecord13[3]; + +type AnydataRecord14Array AnydataRecord14[]; + +type ClosedAnydataRecord14Array AnydataRecord14[3]; + +type CustomRecord1Array CustomRecord1[]; + +type ClosedCustomRecord1Array CustomRecord1[3]; + +type CustomRecord2Array CustomRecord2[]; + +type ClosedCustomRecord2Array CustomRecord2[3]; + +type CustomRecord3Array CustomRecord3[]; + +type ClosedCustomRecord3Array CustomRecord3[3]; + +type CustomRecord4Array CustomRecord4[]; + +type ClosedCustomRecord4Array CustomRecord4[3]; + +type CustomRecord5Array CustomRecord5[]; + +type ClosedCustomRecord5Array CustomRecord5[3]; + +type CustomRecord6Array CustomRecord6[]; + +type ClosedCustomRecord6Array CustomRecord6[3]; + +type CustomRecord7Array CustomRecord7[]; + +type ClosedCustomRecord7Array CustomRecord7[3]; + +type CustomRecord8Array CustomRecord8[]; + +type ClosedCustomRecord8Array CustomRecord8[3]; + +type CustomRecord9Array CustomRecord9[]; + +type ClosedCustomRecord9Array CustomRecord9[3]; + +type CustomRecord10Array CustomRecord10[]; + +type ClosedCustomRecord10Array CustomRecord10[3]; + +type CustomRecord11Array CustomRecord11[]; + +type ClosedCustomRecord11Array CustomRecord11[3]; + +type CustomRecord12Array CustomRecord12[]; + +type ClosedCustomRecord12Array CustomRecord12[3]; + +type CustomRecord13Array CustomRecord13[]; + +type ClosedCustomRecord13Array CustomRecord13[3]; + +type CustomRecord14Array CustomRecord14[]; + +type ClosedCustomRecord14Array CustomRecord14[3]; + +type CustomRecord15Array CustomRecord15[]; + +type CustomRecord16Array CustomRecord16[]; + +type CustomRecord17Array CustomRecord17[]; + +type CustomRecord18Array CustomRecord18[]; + +type CustomRecord19Array CustomRecord19[]; + +type CustomRecord20Array CustomRecord20[]; + +type CustomRecord21Array CustomRecord21[]; + +type CustomRecord22Array CustomRecord22[]; + +type CustomRecord23Array CustomRecord23[]; + +type CustomRecord24Array CustomRecord24[]; + +type CustomRecord25Array CustomRecord25[]; + +type CustomRecord26Array CustomRecord26[]; + +type CustomRecord27Array CustomRecord27[]; +type CustomRecord28Array CustomRecord28[]; +type CustomRecord29Array CustomRecord29[]; +type CustomRecord30Array CustomRecord30[]; +type CustomRecord31Array CustomRecord31[]; +type CustomRecord32Array CustomRecord32[]; +type CustomRecord33Array CustomRecord33[]; +type CustomRecord34Array CustomRecord34[]; +type CustomRecord35Array CustomRecord35[]; +type CustomRecord36Array CustomRecord36[]; +type CustomRecord37Array CustomRecord37[]; +type CustomRecord38Array CustomRecord38[]; +type CustomRecord39Array CustomRecord39[]; +type CustomRecord40Array CustomRecord40[]; +type CustomRecord41Array CustomRecord41[]; +type CustomRecord42Array CustomRecord42[]; +type CustomRecord43Array CustomRecord43[]; +type CustomRecord44Array CustomRecord44[]; +type CustomRecord45Array CustomRecord45[]; +type CustomRecord46Array CustomRecord46[]; +type CustomRecord47Array CustomRecord47[]; +type CustomRecord48Array CustomRecord48[]; +type CustomRecord49Array CustomRecord49[]; +type CustomRecord50Array CustomRecord50[]; +type CustomRecord51Array CustomRecord51[]; +type CustomRecord52Array CustomRecord52[]; +type CustomRecord53Array CustomRecord53[]; +type CustomRecord54Array CustomRecord54[]; +type CustomRecord55Array CustomRecord55[]; +type CustomRecord56Array CustomRecord56[]; + +type BooleanTuple1Array BooleanTuple1[]; + +type ClosedBooleanTuple1Array BooleanTuple1[3]; + +type BooleanTuple2Array BooleanTuple2[]; + +type ClosedBooleanTuple2Array BooleanTuple2[3]; + +type BooleanTuple3Array BooleanTuple3[]; + +type ClosedBooleanTuple3Array BooleanTuple3[3]; + +type BooleanTuple4Array BooleanTuple4[]; + +type ClosedBooleanTuple4Array BooleanTuple4[3]; + +type NillableBooleanTuple5Array NillableBooleanTuple5[]; + +type NillableBooleanTuple6Array NillableBooleanTuple6[]; + +type NillableBooleanTuple7Array NillableBooleanTuple7[]; + +type NillableBooleanTuple8Array NillableBooleanTuple8[]; + +type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; + +type NilTuple1Array NilTuple1[]; + +type ClosedNilTuple1Array NilTuple1[3]; + +type NilTuple2Array NilTuple2[]; + +type ClosedNilTuple2Array NilTuple2[3]; + +type NilTuple3Array NilTuple3[]; + +type ClosedNilTuple3Array NilTuple3[3]; + +type NilTuple4Array NilTuple4[]; + +type ClosedNilTuple4Array NilTuple4[3]; + +type IntegerTuple1Array IntegerTuple1[]; + +type ClosedIntegerTuple1Array IntegerTuple1[3]; + +type IntegerTuple2Array IntegerTuple2[]; + +type ClosedIntegerTuple2Array IntegerTuple2[3]; + +type IntegerTuple3Array IntegerTuple3[]; + +type ClosedIntegerTuple3Array IntegerTuple3[3]; + +type IntegerTuple4Array IntegerTuple4[]; + +type ClosedIntegerTuple4Array IntegerTuple4[3]; + +type FloatTuple1Array FloatTuple1[]; + +type ClosedFloatTuple1Array FloatTuple1[3]; + +type FloatTuple2Array FloatTuple2[]; + +type ClosedFloatTuple2Array FloatTuple2[3]; + +type FloatTuple3Array FloatTuple3[]; + +type ClosedFloatTuple3Array FloatTuple3[3]; + +type FloatTuple4Array FloatTuple4[]; + +type ClosedFloatTuple4Array FloatTuple4[3]; + +type DecimalTuple1Array DecimalTuple1[]; + +type ClosedDecimalTuple1Array DecimalTuple1[3]; + +type DecimalTuple2Array DecimalTuple2[]; + +type ClosedDecimalTuple2Array DecimalTuple2[3]; + +type DecimalTuple3Array DecimalTuple3[]; + +type ClosedDecimalTuple3Array DecimalTuple3[3]; + +type DecimalTuple4Array DecimalTuple4[]; + +type ClosedDecimalTuple4Array DecimalTuple4[3]; + +type StringTuple1Array StringTuple1[]; + +type ClosedStringTuple1Array StringTuple1[3]; + +type StringTuple2Array StringTuple2[]; + +type ClosedStringTuple2Array StringTuple2[3]; + +type StringTuple3Array StringTuple3[]; + +type ClosedStringTuple3Array StringTuple3[3]; + +type StringTuple4Array StringTuple4[]; + +type ClosedStringTuple4Array StringTuple4[3]; + +type AnydataTuple1Array AnydataTuple1[]; + +type ClosedAnydataTuple1Array AnydataTuple1[3]; + +type AnydataTuple2Array AnydataTuple2[]; + +type ClosedAnydataTuple2Array AnydataTuple2[3]; + +type AnydataTuple3Array AnydataTuple3[]; + +type ClosedAnydataTuple3Array AnydataTuple3[3]; + +type AnydataTuple4Array AnydataTuple4[]; + +type ClosedAnydataTuple4Array AnydataTuple4[3]; + +type JsonTuple1Array JsonTuple1[]; + +type ClosedJsonTuple1Array JsonTuple1[3]; + +type JsonTuple2Array JsonTuple2[]; + +type ClosedJsonTuple2Array JsonTuple2[3]; + +type JsonTuple3Array JsonTuple3[]; + +type ClosedJsonTuple3Array JsonTuple3[3]; + +type JsonTuple4Array JsonTuple4[]; + +type ClosedJsonTuple4Array JsonTuple4[3]; + +type CustomTuple1Array CustomTuple1[]; + +type ClosedCustomTuple1Array CustomTuple1[3]; + +type CustomTuple2Array CustomTuple2[]; + +type ClosedCustomTuple2Array CustomTuple2[3]; + +type CustomTuple3Array CustomTuple3[]; + +type ClosedCustomTuple3Array CustomTuple3[3]; + +type CustomTuple4Array CustomTuple4[]; + +type ClosedCustomTuple4Array CustomTuple4[3]; + +type CustomTuple5Array CustomTuple5[]; + +type ClosedCustomTuple5Array CustomTuple5[3]; + +type CustomTuple6Array CustomTuple6[]; + +type CustomTuple7Array CustomTuple7[]; + +type CustomTuple8Array CustomTuple8[]; + +type ClosedCustomTuple6Array CustomTuple6[3]; + +type IntegerArray1Array IntegerArray1[]; + +type ClosedIntegerArray1Array IntegerArray1[3]; + +type IntegerArray2Array IntegerArray2[]; + +type ClosedIntegerArray2Array IntegerArray2[3]; + +type IntegerArray3Array IntegerArray3[]; + +type ClosedIntegerArray3Array IntegerArray3[3]; + +type IntegerArray4Array IntegerArray4[]; + +type ClosedIntegerArray4Array IntegerArray4[3]; + +type IntegerArray5Array IntegerArray5[]; + +type ClosedIntegerArray5Array IntegerArray5[3]; + +type IntegerArray6Array IntegerArray5[]; + +type ClosedIntegerArray6Array IntegerArray5[3]; + +type StringArray1Array StringArray1[]; + +type StringArrayArray StringArray[]; + +type NillableStringArrayArray NillableStringArray[]; + +type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; + +type ClosedStringArray1Array StringArray1[3]; + +type StringArray2Array StringArray2[]; + +type ClosedStringArray2Array StringArray2[3]; + +type StringArray3Array StringArray3[]; + +type ClosedStringArray3Array StringArray3[3]; + +type StringArray4Array StringArray4[]; + +type ClosedStringArray4Array StringArray4[3]; + +type StringArray5Array StringArray5[]; + +type ClosedStringArray5Array StringArray5[3]; + +type StringArray6Array StringArray5[]; + +type ClosedStringArray6Array StringArray5[3]; + +type FloatArray1Array FloatArray1[]; + +type ClosedFloatArray1Array FloatArray1[3]; + +type FloatArray2Array FloatArray2[]; + +type ClosedFloatArray2Array FloatArray2[3]; + +type FloatArray3Array FloatArray3[]; + +type ClosedFloatArray3Array FloatArray3[3]; + +type FloatArray4Array FloatArray4[]; + +type ClosedFloatArray4Array FloatArray4[3]; + +type FloatArray5Array FloatArray5[]; + +type ClosedFloatArray5Array FloatArray5[3]; + +type FloatArray6Array FloatArray5[]; + +type ClosedFloatArray6Array FloatArray5[3]; + +type DecimalArray1Array DecimalArray1[]; + +type ClosedDecimalArray1Array DecimalArray1[3]; + +type DecimalArray2Array DecimalArray2[]; + +type ClosedDecimalArray2Array DecimalArray2[3]; + +type DecimalArray3Array DecimalArray3[]; + +type ClosedDecimalArray3Array DecimalArray3[3]; + +type DecimalArray4Array DecimalArray4[]; + +type ClosedDecimalArray4Array DecimalArray4[3]; + +type DecimalArray5Array DecimalArray5[]; + +type ClosedDecimalArray5Array DecimalArray5[3]; + +type DecimalArray6Array DecimalArray5[]; + +type ClosedDecimalArray6Array DecimalArray5[3]; + +type BooleanArrayArray BooleanArray[]; + +type ClosedBooleanArrayArray BooleanArray[3]; + +type NillableBooleanArrayArray NillableBooleanArray[]; + +type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; + +type BooleanArray2Array BooleanArray2[]; + +type ClosedBooleanArray2Array BooleanArray2[3]; + +type BooleanArray3Array BooleanArray3[]; + +type ClosedBooleanArray3Array BooleanArray3[3]; + +type BooleanArray4Array BooleanArray4[]; + +type ClosedBooleanArray4Array BooleanArray4[3]; + +type BooleanArray5Array BooleanArray5[]; + +type ClosedBooleanArray5Array BooleanArray5[3]; + +type BooleanArray6Array BooleanArray5[]; + +type ClosedBooleanArray6Array BooleanArray5[3]; + +type NilArray1Array NilArray1[]; + +type ClosedNilArray1Array NilArray1[3]; + +type NilArray2Array NilArray2[]; + +type ClosedNilArray2Array NilArray2[3]; + +type NilArray3Array NilArray3[]; + +type ClosedNilArray3Array NilArray3[3]; + +type NilArray4Array NilArray4[]; + +type ClosedNilArray4Array NilArray4[3]; + +type NilArray5Array NilArray5[]; + +type ClosedNilArray5Array NilArray5[3]; + +type NilArray6Array NilArray5[]; + +type ClosedNilArray6Array NilArray5[3]; + +type JsonArray1Array JsonArray1[]; + +type ClosedJsonArray1Array JsonArray1[3]; + +type JsonArray2Array JsonArray2[]; + +type ClosedJsonArray2Array JsonArray2[3]; + +type JsonArray3Array JsonArray3[]; + +type ClosedJsonArray3Array JsonArray3[3]; + +type JsonArray4Array JsonArray4[]; + +type ClosedJsonArray4Array JsonArray4[3]; + +type JsonArray5Array JsonArray5[]; + +type ClosedJsonArray5Array JsonArray5[3]; + +type JsonArray6Array JsonArray5[]; + +type ClosedJsonArray6Array JsonArray5[3]; + +type AnydataArray1Array AnydataArray1[]; + +type ClosedAnydataArray1Array AnydataArray1[3]; + +type AnydataArray2Array AnydataArray2[]; + +type ClosedAnydataArray2Array AnydataArray2[3]; + +type AnydataArray3Array AnydataArray3[]; + +type ClosedAnydataArray3Array AnydataArray3[3]; + +type AnydataArray4Array AnydataArray4[]; + +type ClosedAnydataArray4Array AnydataArray4[3]; + +type AnydataArray5Array AnydataArray5[]; + +type ClosedAnydataArray5Array AnydataArray5[3]; + +type AnydataArray6Array AnydataArray5[]; + +type ClosedAnydataArray6Array AnydataArray5[3]; + +type CustomArray1Array CustomArray1[]; + +type ClosedCustomArray1Array CustomArray1[3]; + +type CustomArray2Array CustomArray2[]; + +type ClosedCustomArray2Array CustomArray2[3]; + +type CustomArray3Array CustomArray3[]; + +type ClosedCustomArray3Array CustomArray3[3]; + +type CustomArray4Array CustomArray4[]; + +type ClosedCustomArray4Array CustomArray4[3]; + +type CustomArray5Array CustomArray5[]; + +type ClosedCustomArray5Array CustomArray5[3]; + +type CustomArray6Array CustomArray5[]; + +type ClosedCustomArray6Array CustomArray5[3]; + +type IntegerMapArray IntegerMap[]; + +type ClosedIntegerMapArray IntegerMap[3]; + +type StringMapArray StringMap[]; + +type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; + +type IntUnionStringMapArray IntUnionStringMap[]; + +type ClosedStringMapArray StringMap[3]; + +type DecimalMapArray DecimalMap[]; + +type ClosedDecimalMapArray DecimalMap[3]; + +type FloatMapArray FloatMap[]; + +type ClosedFloatMapArray FloatMap[3]; + +type BooleanMapArray BooleanMap[]; + +type NillableBooleanMapArray NillableBooleanMap[]; + +type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; + +type IntUnionBooleanMapArray IntUnionBooleanMap[]; + +type ClosedBooleanMapArray BooleanMap[3]; + +type NilMapArray NilMap[]; + +type ClosedNilMapArray NilMap[3]; + +type JsonMapArray JsonMap[]; + +type ClosedJsonMapArray JsonMap[3]; + +type AnydataMapArray AnydataMap[]; + +type ClosedAnydataMapArray AnydataMap[3]; + +type CustomMapArray CustomMap[]; + +type ClosedCustomMapArray CustomMap[3]; diff --git a/ballerina-tests/union-type-tests/.gitignore b/ballerina-tests/union-type-tests/.gitignore new file mode 100644 index 0000000..d5fc29a --- /dev/null +++ b/ballerina-tests/union-type-tests/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/ballerina-tests/union-type-tests/Ballerina.toml b/ballerina-tests/union-type-tests/Ballerina.toml new file mode 100644 index 0000000..5d819d3 --- /dev/null +++ b/ballerina-tests/union-type-tests/Ballerina.toml @@ -0,0 +1,13 @@ +[package] +org = "ballerina" +name = "union_type_tests" +version = "0.1.0" + +[[dependency]] +org = "ballerina" +name = "csv_commons" +repository = "local" +version = "0.1.0" + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina-tests/union-type-tests/Dependencies.toml b/ballerina-tests/union-type-tests/Dependencies.toml new file mode 100644 index 0000000..3eb4395 --- /dev/null +++ b/ballerina-tests/union-type-tests/Dependencies.toml @@ -0,0 +1,98 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0" + +[[package]] +org = "ballerina" +name = "csv_commons" +version = "0.1.0" +scope = "testOnly" +modules = [ + {org = "ballerina", packageName = "csv_commons", moduleName = "csv_commons"} +] + +[[package]] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + +[[package]] +org = "ballerina" +name = "union_type_tests" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "csv_commons"}, + {org = "ballerina", name = "data.csv"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerina", packageName = "union_type_tests", moduleName = "union_type_tests"} +] + diff --git a/ballerina-tests/union-type-tests/tests/test_data_values.bal b/ballerina-tests/union-type-tests/tests/test_data_values.bal new file mode 100644 index 0000000..360a493 --- /dev/null +++ b/ballerina-tests/union-type-tests/tests/test_data_values.bal @@ -0,0 +1,256 @@ +boolean b1 = true; +false b2 = false; +boolean? b3 = (); +boolean|int b4 = false; + +() n1 = (); +int? n2 = (); +() n3 = null; + +int i1 = 1; +int i2 = -2; +int i3 = int:MAX_VALUE; +int i4 = int:MIN_VALUE; +int i5 = 0; +2 i6 = 2; +int? i7 = (); +int|string i8 = 100; + +float f1 = 2.234; +float f2 = -3.21f; +float f3 = 0; +float f4 = float:Infinity; +float f5 = -float:Infinity; +float f6 = float:NaN; +2.3f f7 = 2.3; +float? f8 = (); +float|decimal f9 = 1.21; + +decimal d1 = 2.234; +decimal d2 = -3.21d; +decimal d3 = 0; +2.3d d4 = 2.3; +decimal? d5 = (); +decimal|int d6 = 1.21; + +string s1 = "string"; +string s2 = ""; +string:Char s3 = "a"; + +map bm1 = {b1, b2}; +map bm2 = {b1, b2, b3, n1, n3}; +map bm3 = {b1, b2, b3, b4, i1}; +map<()> bm4 = {n1, n3}; +map bm5 = {b1, b2, b3, b4:true}; + +map m5 = {i1, i2, i3, i4, i5, i6}; +map m6 = {f1, f2, f3, f4, f5, f6, f7}; +map m7 = {d1, d2, d3, d4}; +map m8 = {d1, f1, f9, f10: 1.23}; +map m9 = {s1, s2, s3}; +map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; +map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; + +boolean[] arr1 = [b1, b2]; +boolean?[] arr2 = [b1, b2, b3, n1, n3]; +(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; +()[] arr4 = [n1, n3]; +int[] arr5 = [i1, i2, i3, i4, i5, i6]; +float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; +decimal[] arr7 = [d1, d2, d3, d4]; +(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; +string[] arr9 = [s1, s2, s3]; +anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; + +[boolean, boolean] bt1 = [b1, b2]; +[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; +[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; +[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; +[boolean...] bt5 = [b1, b2]; + +[string, string] st1 = [s1, s2]; +[string, string, string, string] st2 = [s1, s2, s3, s2]; +[string...] st3 = [s1, s2]; +[string, string, string...] st4 = [s1, s2, s3, s2]; + +[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; +[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; +[string?...] st7 = [s1, s2]; +[string...] st8 = []; +[string, string, string] st9 = [s1, s2, s3]; + +[(), ()] tup4 = [n1, n3]; +[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; +[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; +[string, string, string] tup9 = [s1, s2, s3]; +[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, + n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, json] tup11 = + [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, + f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 +]; + +[boolean, boolean...] restTup1 = [b1, b2]; +[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; +[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; +[(), ()...] restTup4 = [n1, n3]; +[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; +[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal...] restTup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; +[string...] restTup9 = [s1, s2, s3]; +[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 +]; + +var booleanRecordArray = [ + {b1, b2, b3, b4}, {b1, b2, b3, b4} +]; + +var booleanRecordArray2 = [ + {},{} +]; + +string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 +true,false,true,false +true,false, true,false +true,false,true,false +`; + +string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 +true,false, true,false,true +true,false, true,false,true`; + +string csvStringWithBooleanValues3 = string `b1,b2,b3 +${" "}${"\t"} +true, false,true +${" "} + TRUE, FALSE,() +${" "} + +true, true,FALSE + +`; + +string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 + true,(), (),false + true,(), null,false + +`; + +string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 + +true,false,true,2 + +true,false,true,3 +`; + +string csvStringWithBooleanValues6 = string `b2,b3 +(),() + +`; + +string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 +${b1},${b2},(),${b4} +`; + +string csvStringData1 = string ` + a, b, c, d, e, f + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData2 = string ` + hello, hello, (), 12, true, 12.34 + // comment + + a, b, c, d, e, f + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData3 = string ` + a, b, c, d, e, f + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData4 = string ` + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData5 = string ` + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData6 = string ` + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData7 = string ` + a@ b@ c@ d@ e@ f + 1@ string@ true@ 2.234@ -3.21@ () + 2@ s,tring@ true@ 2.234@ -3.21@ null + 3@ stri,ng@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; +string csvStringData8 = string ` + a@ b@ c@ d@ e@ f + + + + 1@ stri,ng@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ ()@-3.21 + 3@ string@ true@ 2.234@ -3.21@ null + + 4@ s,tring@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; + +string csvStringData9 = string ` + + 1@ string@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ -3.21@ null + + 3@ string@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ ()@-3.21 + + 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina/tests/test_with_intersection_types.bal b/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal similarity index 67% rename from ballerina/tests/test_with_intersection_types.bal rename to ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal index e8b5d9d..141fce7 100644 --- a/ballerina/tests/test_with_intersection_types.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal @@ -1,63 +1,64 @@ +import ballerina/data.csv as csv; import ballerina/test; @test:Config function testIntersectionExpectedTypes() returns error? { - (int[] & readonly)[]|Error a = parseStringToList(string `a,b + (int[] & readonly)[]|csv:Error a = csv:parseStringToList(string `a,b 1,2 4,5`); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|Error a2 = parseStringToList(string `a,b + ([string, string])[] & readonly|csv:Error a2 = csv:parseStringToList(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)[]|Error a3 = parseStringToRecord(string `a,b + (record{int a; string b;} & readonly)[]|csv:Error a3 = csv:parseStringToRecord(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|Error a4 = parseStringToRecord(string `a,b + record{|string...;|}[] & readonly|csv:Error a4 = csv:parseStringToRecord(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)[]|Error a5 = parseStringToList(string `a,b + ([int] & readonly)[]|csv:Error a5 = csv:parseStringToList(string `a,b 1,2 4,5`); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|Error a6 = parseStringToList(string `a,b + ([string, string])[] & readonly|csv:Error a6 = csv:parseStringToList(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)[]|Error a7 = parseStringToRecord(string `a,b + (record{int a; string b;} & readonly)[]|csv:Error a7 = csv:parseStringToRecord(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|Error a8 = parseStringToRecord(string `a,b + map[] & readonly|csv:Error a8 = csv:parseStringToRecord(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)[]|Error a9 = parseStringToList(string `a,b + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:parseStringToList(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|Error a10 = parseStringToRecord(string `a,b + & readonly|csv:Error a10 = csv:parseStringToRecord(string `a,b a,a 1,2`); test:assertTrue(a10 is ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly); @@ -66,93 +67,93 @@ function testIntersectionExpectedTypes() returns error? { @test:Config function testIntersectionExpectedTypes2() returns error? { - (int[] & readonly)[]|Error a = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); + (int[] & readonly)[]|csv:Error a = csv:parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|Error a2 = parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); + ([string, string])[] & readonly|csv:Error a2 = csv:parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); test:assertTrue(a2 is [string, string][] & readonly); test:assertEquals(a2, [["a", "a"], ["c", "c"]]); - (record{int a; string b;} & readonly)[]|Error a3 = parseRecordAsRecordType([{"a": 1, "b": "2"}, {"a": 4, "b": "5"}], {}); + (record{int a; string b;} & readonly)[]|csv:Error a3 = csv:parseRecordAsRecordType([{"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|Error a4 = parseRecordAsRecordType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {}); + record{|string...;|}[] & readonly|csv:Error a4 = csv:parseRecordAsRecordType([{"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)[]|Error a5 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); + ([int] & readonly)[]|csv:Error a5 = csv:parseRecordAsListType([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["a", "b"], {}); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|Error a6 = parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); + ([string, string])[] & readonly|csv:Error a6 = csv:parseRecordAsListType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], ["a", "b"], {}); test:assertTrue(a6 is [string, string][] & readonly); test:assertEquals(a6, [["a", "a"], ["c", "c"]]); - (record{int a; string b;} & readonly)[]|Error a7 = parseRecordAsRecordType([{"a": 1, "b": "2"}, {"a": 4, "b": "5"}], {}); + (record{int a; string b;} & readonly)[]|csv:Error a7 = csv:parseRecordAsRecordType([{"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|Error a8 = parseRecordAsRecordType([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {}); + map[] & readonly|csv:Error a8 = csv:parseRecordAsRecordType([{"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)[]|Error a9 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["a", "b"], {}); + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["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|Error a10 = parseRecordAsRecordType([{"a": "a", "b": "a"}, {"a": 1, "b": 2}], {}); + & readonly|csv:Error a10 = csv:parseRecordAsRecordType([{"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)[]|Error a = parseListAsListType([["1", "2"], ["4", "5"]], {}); + (int[] & readonly)[]|csv:Error a = csv:parseListAsListType([["1", "2"], ["4", "5"]], {}); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|Error a2 = parseListAsListType([["a", "a"], ["c", "c"]], {}); + ([string, string])[] & readonly|csv:Error a2 = csv:parseListAsListType([["a", "a"], ["c", "c"]], {}); test:assertTrue(a2 is [string, string][] & readonly); test:assertEquals(a2, [["a", "a"], ["c", "c"]]); - (record{int a; string b;} & readonly)[]|Error a3 = parseListAsRecordType([["1", "2"], ["4", "5"]], ["a", "b"], {}); + (record{int a; string b;} & readonly)[]|csv:Error a3 = csv:parseListAsRecordType([["1", "2"], ["4", "5"]], ["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|Error a4 = parseListAsRecordType([["a", "a"], ["c", "c"]], ["a", "b"], {}); + record{|string...;|}[] & readonly|csv:Error a4 = csv:parseListAsRecordType([["a", "a"], ["c", "c"]], ["a", "b"], {}); test:assertTrue(a4 is record{|string...;|}[] & readonly); test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - ([int] & readonly)[]|Error a5 = parseListAsListType([["1", "2"], ["4", "5"]], {}); + ([int] & readonly)[]|csv:Error a5 = csv:parseListAsListType([["1", "2"], ["4", "5"]], {}); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|Error a6 = parseListAsListType([["a", "a"], ["c", "c"]], {}); + ([string, string])[] & readonly|csv:Error a6 = csv:parseListAsListType([["a", "a"], ["c", "c"]], {}); test:assertTrue(a6 is [string, string][] & readonly); test:assertEquals(a6, [["a", "a"], ["c", "c"]]); - (record{int a; string b;} & readonly)[]|Error a7 = parseListAsRecordType([["1", "2"], ["4", "5"]], ["a", "b"], {}); + (record{int a; string b;} & readonly)[]|csv:Error a7 = csv:parseListAsRecordType([["1", "2"], ["4", "5"]], ["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|Error a8 = parseListAsRecordType([["a", "a"], ["c", "c"]], ["a", "b"], {}); + map[] & readonly|csv:Error a8 = csv:parseListAsRecordType([["a", "a"], ["c", "c"]], ["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)[]|Error a9 = parseListAsListType([["1", "2"], ["a", "b"]], {}); + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:parseListAsListType([["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|Error a10 = parseListAsRecordType([["a", "a"], ["1", "2"]], ["a", "b"], {}); + & readonly|csv:Error a10 = csv:parseListAsRecordType([["a", "a"], ["1", "2"]], ["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|Error a11 = parseListAsRecordType([["a", "a"], ["1", "2"]], ["a", "b"], {}); + & readonly|csv:Error a11 = csv:parseListAsRecordType([["a", "a"], ["1", "2"]], ["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/test_with_singleton_test.bal b/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal similarity index 66% rename from ballerina/tests/test_with_singleton_test.bal rename to ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal index 2915dac..56bd093 100644 --- a/ballerina/tests/test_with_singleton_test.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal @@ -1,95 +1,97 @@ +import ballerina/data.csv as csv; import ballerina/test; +import ballerina/csv_commons as common; type Singleton 1; @test:Config function testSingletonExpectedTypes() returns error? { - 1[][]|Error a = parseStringToList(string `a, b, c + 1[][]|csv:Error a = csv:parseStringToList(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;}[]|Error a2 = parseStringToRecord(string `a, b, c + record {1|2 a; 1 b;}[]|csv:Error a2 = csv:parseStringToRecord(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...;|}[]|Error a3 = parseStringToRecord(string `a, b, c + record {|1 a; 1|2...;|}[]|csv:Error a3 = csv:parseStringToRecord(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...][]|Error a4 = parseStringToList(string `a, b, c + [Singleton, Singleton...][]|csv:Error a4 = csv:parseStringToList(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;|}[]|Error a5 = parseStringToRecord(string `a, b, c + record {|1|"a" a; 1 b;|}[]|csv:Error a5 = csv:parseStringToRecord(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a5, [{a: 1, b: 1}, {a: 1, b: 1}]); - [Singleton, Singleton][]|Error a6 = parseStringToList(string `a, b, c + [Singleton, Singleton][]|csv:Error a6 = csv:parseStringToList(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a6, [[1, 1], [1, 1]]); - record {|"a"|"c" a; "b" b;|}[]|Error a7 = parseStringToRecord(string `a, b, c + record {|"a"|"c" a; "b" b;|}[]|csv:Error a7 = csv:parseStringToRecord(string `a, b, c a, c, 1 1, 1,1 `); - test:assertTrue(a7 is Error); - test:assertEquals((a7).message(), generateErrorMessageForInvalidCast("c", "\"b\"")); + test:assertTrue(a7 is csv:Error); + test:assertEquals((a7).message(), common:generateErrorMessageForInvalidCast("c", "\"b\"")); - ["a"|"d", "b"][]|Error a8 = parseStringToList(string `a, b, c + ["a"|"d", "b"][]|csv:Error a8 = csv:parseStringToList(string `a, b, c a, b, 1 c, b,1 `); - test:assertTrue(a8 is Error); - test:assertEquals((a8).message(), generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); + test:assertTrue(a8 is csv:Error); + test:assertEquals((a8).message(), common:generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); } @test:Config function testSingletonExpectedTypes2() returns error? { - 1[][]|Error a = parseStringToList(string `a, b, c + 1[][]|csv:Error a = csv:parseStringToList(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;}[]|Error a2 = parseStringToRecord(string `a, b, c + record {1|2 a; 1 b;}[]|csv:Error a2 = csv:parseStringToRecord(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...;|}[]|Error a3 = parseStringToRecord(string `a, b, c + record {|1 a; 1|2...;|}[]|csv:Error a3 = csv:parseStringToRecord(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...][]|Error a4 = parseStringToList(string `a, b, c + [Singleton, Singleton...][]|csv:Error a4 = csv:parseStringToList(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;|}[]|Error a5 = parseStringToRecord(string `a, b, c + record {|1|"a" a; 1 b;|}[]|csv:Error a5 = csv:parseStringToRecord(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a5, [{a: 1, b: 1}, {a: 1, b: 1}]); - [Singleton, Singleton][]|Error a6 = parseStringToList(string `a, b, c + [Singleton, Singleton][]|csv:Error a6 = csv:parseStringToList(string `a, b, c 1, 1, 1 1, 1,1 `); test:assertEquals(a6, [[1, 1], [1, 1]]); - record {|"a"|"c" a; "b" b;|}[]|Error a7 = parseStringToRecord(string `a, b, c + record {|"a"|"c" a; "b" b;|}[]|csv:Error a7 = csv:parseStringToRecord(string `a, b, c a, c, 1 1, 1,1 `); - test:assertTrue(a7 is Error); - test:assertEquals((a7).message(), generateErrorMessageForInvalidCast("c", "\"b\"")); + test:assertTrue(a7 is csv:Error); + test:assertEquals((a7).message(), common:generateErrorMessageForInvalidCast("c", "\"b\"")); - ["a"|"d", "b"][]|Error a8 = parseStringToList(string `a, b, c + ["a"|"d", "b"][]|csv:Error a8 = csv:parseStringToList(string `a, b, c a, b, 1 c, b,1 `); - test:assertTrue(a8 is Error); - test:assertEquals((a8).message(), generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); + test:assertTrue(a8 is csv:Error); + test:assertEquals((a8).message(), common:generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); } type SubType byte|int:Signed8|int:Signed16|int:Signed32|string:Char|int:Unsigned8|int:Unsigned16|int:Unsigned32; @@ -127,77 +129,77 @@ function testSubtypeExpectedTypes() returns error? { var value4 = [["1", "1", "1", "1", "a", "1", "1", "1"], ["1", "1", "1", "1", "a", "1", "1", "1"]]; - SubtypeRecord[]|Error a = parseStringToRecord(string `a, c, d, e, f, g, h, i + SubtypeRecord[]|csv:Error a = csv:parseStringToRecord(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[]|Error a2 = parseStringToRecord(string `a, c, d, e, f, g, h, i + SubtypeRecord2[]|csv:Error a2 = csv:parseStringToRecord(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[]|Error a3 = parseStringToRecord(string `a, c, d, e, f, g, h, i + SubtypeRecord3[]|csv:Error a3 = csv:parseStringToRecord(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[]|Error a4 = parseStringToList(string `a, c, d, e, f, g, h, i + SubtypeTuple[]|csv:Error a4 = csv:parseStringToList(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[]|Error a5 = parseStringToList(string `a, c, d, e, f, g, h, i + SubtypeTuple2[]|csv:Error a5 = csv:parseStringToList(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[]|Error a6 = parseStringToList(string `a, c, d, e, f, g, h, i + SubtypeTuple3[]|csv:Error a6 = csv:parseStringToList(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[]|Error a7 = parseRecordAsRecordType(value1, {}); + SubtypeRecord[]|csv:Error a7 = csv:parseRecordAsRecordType(value1, {}); test:assertEquals(a7, value1); - SubtypeRecord2[]|Error a8 = parseRecordAsRecordType(value1, {}); + SubtypeRecord2[]|csv:Error a8 = csv:parseRecordAsRecordType(value1, {}); test:assertEquals(a8, [{a: 1, c: 1}, {a: 1, c: 1}]); - SubtypeRecord3[]|Error a9 = parseRecordAsRecordType(value1, {}); + SubtypeRecord3[]|csv:Error a9 = csv:parseRecordAsRecordType(value1, {}); test:assertEquals(a9, value1); - SubtypeTuple[]|Error a10 = parseRecordAsListType(value1, + SubtypeTuple[]|csv:Error a10 = csv:parseRecordAsListType(value1, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a10, value3); - SubtypeTuple2[]|Error a11 = parseRecordAsListType(value1, + SubtypeTuple2[]|csv:Error a11 = csv:parseRecordAsListType(value1, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a11, [[1, 1], [1, 1]]); - SubtypeTuple3[]|Error a12 = parseRecordAsListType(value1, + SubtypeTuple3[]|csv:Error a12 = csv:parseRecordAsListType(value1, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a12, value3); - SubtypeRecord[]|Error a13 = parseListAsRecordType(value4, + SubtypeRecord[]|csv:Error a13 = csv:parseListAsRecordType(value4, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a13, value1); - SubtypeRecord2[]|Error a14 = parseListAsRecordType(value4, + SubtypeRecord2[]|csv:Error a14 = csv:parseListAsRecordType(value4, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a14, [{a: 1, c: 1}, {a: 1, c: 1}]); - SubtypeRecord3[]|Error a15 = parseListAsRecordType(value4, + SubtypeRecord3[]|csv:Error a15 = csv:parseListAsRecordType(value4, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a15, value1); - SubtypeTuple[]|Error a16 = parseListAsListType(value4, {}); + SubtypeTuple[]|csv:Error a16 = csv:parseListAsListType(value4, {}); test:assertEquals(a16, value3); - SubtypeTuple2[]|Error a17 = parseListAsListType(value4, {}); + SubtypeTuple2[]|csv:Error a17 = csv:parseListAsListType(value4, {}); test:assertEquals(a17, [[1, 1], [1, 1]]); - SubtypeTuple3[]|Error a18 = parseListAsListType(value4, {}); + SubtypeTuple3[]|csv:Error a18 = csv:parseListAsListType(value4, {}); test:assertEquals(a18, value3); } diff --git a/ballerina/tests/test_with_union_types.bal b/ballerina-tests/union-type-tests/tests/test_with_union_types.bal similarity index 62% rename from ballerina/tests/test_with_union_types.bal rename to ballerina-tests/union-type-tests/tests/test_with_union_types.bal index 5d6f21b..10fc22a 100644 --- a/ballerina/tests/test_with_union_types.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_union_types.bal @@ -1,3 +1,4 @@ +import ballerina/data.csv as csv; import ballerina/test; type RecA record {int a; string b; boolean c; decimal d; float e; () f;}; @@ -9,7 +10,7 @@ type TupC [int, int, int]; @test:Config function testParseToStringWithUnionExpectedTypes() returns error? { - (RecA|RecC)[]|Error csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); + (RecA|RecC)[]|csv:Error csv1op1 = csv:parseStringToRecord(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: ()}, @@ -18,7 +19,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecA|RecC)[]|Error csv1op2 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecA|RecC)[]|csv:Error csv1op2 = csv:parseStringToRecord(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: ()}, @@ -26,42 +27,42 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecC|RecA)[]|Error csv1op3 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecC|RecA)[]|csv:Error csv1op3 = csv:parseStringToRecord(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)[]|Error csv1op4 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecB|RecA)[]|csv:Error csv1op4 = csv:parseStringToRecord(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)[]|Error csv1op5 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (RecA|RecB)[]|csv:Error csv1op5 = csv:parseStringToRecord(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;|})[]|Error csv1op6 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|Error csv1op7 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|Error csv1op8 = parseStringToRecord(csvStringData1, {header: 1}); + (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:parseStringToRecord(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"}, @@ -70,7 +71,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - (record{|int...;|}|record{|string...;|})[]|Error csv1op9 = parseStringToRecord(csvStringData1, {header: 1}); + (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -79,7 +80,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, d: 3, e: 3} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|Error csv1op10 = parseStringToRecord(csvStringData1, {header: 1}); + (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseStringToRecord(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"}, @@ -88,7 +89,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|Error csv1op11 = parseStringToRecord(csvStringData1, {header: 1}); + (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -97,7 +98,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "5", d: 3, e: 3} ]); - (record{|int a; int b;|}|record{|string a; string...;|})[]|Error csv1op12 = parseStringToRecord(string ` + (record{|int a; int b;|}|record{|string a; string...;|})[]|csv:Error csv1op12 = csv:parseStringToRecord(string ` a,b 1, 2 a, b`, {header: 1}); @@ -106,7 +107,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "a", b: "b"} ]); - ([int, int]|[string, string])[]|Error csv1op13 = parseStringToList(string ` + ([int, int]|[string, string])[]|csv:Error csv1op13 = csv:parseStringToList(string ` a,b 1, 2 a, b`, {header: 1}); @@ -126,7 +127,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - (RecA|RecC)[]|Error csv1op1 = parseRecordAsRecordType(value, {}); + (RecA|RecC)[]|csv:Error csv1op1 = csv:parseRecordAsRecordType(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: ()}, @@ -135,7 +136,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecA|RecC)[]|Error csv1op2 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecA|RecC)[]|csv:Error csv1op2 = csv:parseRecordAsRecordType(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: ()}, @@ -143,42 +144,42 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecC|RecA)[]|Error csv1op3 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecC|RecA)[]|csv:Error csv1op3 = csv:parseRecordAsRecordType(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)[]|Error csv1op4 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecB|RecA)[]|csv:Error csv1op4 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op4, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (RecA|RecB)[]|Error csv1op5 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (RecA|RecB)[]|csv:Error csv1op5 = csv:parseRecordAsRecordType(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;|})[]|Error csv1op6 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|Error csv1op7 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|Error csv1op8 = parseRecordAsRecordType(value, {}); + (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:parseRecordAsRecordType(value, {}); test:assertEquals(csv1op8, [ {b: "string1"}, {b: "string2"}, @@ -187,7 +188,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {b: "string5"} ]); - (record{|int...;|}|record{|string...;|})[]|Error csv1op9 = parseRecordAsRecordType(value, {}); + (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseRecordAsRecordType(value, {}); test:assertEquals(csv1op9, [ {a: 1, d: 2, e: 2}, {a: 2, d: 0, e: 0}, @@ -196,7 +197,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, d: 3, e: 3} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|Error csv1op10 = parseRecordAsRecordType(value, {}); + (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseRecordAsRecordType(value, {}); test:assertEquals(csv1op10, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -205,7 +206,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|Error csv1op11 = parseRecordAsRecordType(value, {}); + (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:parseRecordAsRecordType(value, {}); test:assertEquals(csv1op11, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -214,11 +215,11 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5"} ]); - (record{|string a; int...;|}|record{|string a; string...;|})[]|Error csv1op12 = parseRecordAsRecordType(value, {}); - test:assertTrue(csv1op12 is Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| string a; int...; |}|data.csv:record {| string a; string...; |})[]'"); + (record{|string a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op12 = csv:parseRecordAsRecordType(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...;|})[]|Error csv1op13 = parseRecordAsRecordType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); + (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op13 = csv:parseRecordAsRecordType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, {a: "a", b: "b"} @@ -235,7 +236,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - (RecA|RecC)[]|Error csv1op1 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + (RecA|RecC)[]|csv:Error csv1op1 = csv:parseListAsRecordType(value, ["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: ()}, @@ -244,7 +245,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecA|RecC)[]|Error csv1op2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecA|RecC)[]|csv:Error csv1op2 = csv:parseListAsRecordType(value, ["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: ()}, @@ -252,49 +253,49 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (RecC|RecA)[]|Error csv1op3 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecC|RecA)[]|csv:Error csv1op3 = csv:parseListAsRecordType(value, ["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)[]|Error csv1op4 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecB|RecA)[]|csv:Error csv1op4 = csv:parseListAsRecordType(value, ["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)[]|Error csv1op5 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecA|RecB)[]|csv:Error csv1op5 = csv:parseListAsRecordType(value, ["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;|})[]|Error csv1op6 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|Error csv1op7 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|Error csv1op8 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [4, 2]}); + (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:parseListAsRecordType(value, ["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...;|})[]|Error csv1op9 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); + (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -303,7 +304,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, d: 3} ]); - (record{|int...;|}|record{|string...;|})[]|Error csv1op9_2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9_2 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); test:assertEquals(csv1op9_2, [ {}, {}, @@ -312,14 +313,14 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|Error csv1op10 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, -1, 4]}); + (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseListAsRecordType(value, ["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...;|})[]|Error csv1op11 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -328,11 +329,11 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", d: 3} ]); - (record{|int a; int...;|}|record{|int a; string...;|})[]|Error csv1op12 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); - test:assertTrue(csv1op12 is Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| int a; int...; |}|data.csv:record {| int a; string...; |})[]'"); + (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...;|})[]|Error csv1op13 = parseListAsRecordType([["1", "2"], ["a", "b"]], ["a", "b"], {}); + (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op13 = csv:parseListAsRecordType([["1", "2"], ["a", "b"]], ["a", "b"], {}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, {a: "a", b: "b"} @@ -350,7 +351,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - (TupA|TupC)[]|Error csv1op1 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + (TupA|TupC)[]|csv:Error csv1op1 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -359,7 +360,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupA|TupC)[]|Error csv1op2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupA|TupC)[]|csv:Error csv1op2 = csv:parseRecordAsListType(value, ["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, ()], @@ -367,66 +368,66 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupC|TupA)[]|Error csv1op3 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupC|TupA)[]|csv:Error csv1op3 = csv:parseRecordAsListType(value, ["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)[]|Error csv1op4 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupB|TupA)[]|csv:Error csv1op4 = csv:parseRecordAsListType(value, ["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])[]|Error csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); - test:assertTrue(csv1op4_2 is Error); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB|[boolean])[]'"); + (TupB|[boolean])[]|csv:Error csv1op4_2 = csv:parseRecordAsListType(value, ["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)[]|Error csv1op5 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (TupA|TupB)[]|csv:Error csv1op5 = csv:parseRecordAsListType(value, ["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])[]|Error csv1op6 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + ([int]|[string])[]|csv:Error csv1op6 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - ([string]|[int])[]|Error csv1op7 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + ([string]|[int])[]|csv:Error csv1op7 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ [1], [3], [5] ]); - ([string...]|[int...])[]|Error csv1op8 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op8 is Error); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([string...]|[int...])[]'"); + ([string...]|[int...])[]|csv:Error csv1op8 = csv:parseRecordAsListType(value, ["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...])[]|Error csv1op9 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op9 is Error); - test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '([int...]|[string...])[]'"); + ([int...]|[string...])[]|csv:Error csv1op9 = csv:parseRecordAsListType(value, ["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...])[]|Error csv1op10 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op10 is Error); - test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '([int,string...]|[string,int...])[]'"); + ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:parseRecordAsListType(value, ["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...])[]|Error csv1op11 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op11 is Error); - test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '([string,int...]|[int,string...])[]'"); + ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:parseRecordAsListType(value, ["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...])[]|Error csv1op12 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op12 is Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...]|[string,string...])[]'"); + ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:parseRecordAsListType(value, ["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...])[]|Error csv1op13 = parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["a", "b"], {}); + ([int, int...]|[string, string...])[]|csv:Error csv1op13 = csv:parseRecordAsListType([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["a", "b"], {}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] @@ -443,7 +444,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - (TupA|TupC)[]|Error csv1op1 = parseListAsListType(value, {}); + (TupA|TupC)[]|csv:Error csv1op1 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -452,7 +453,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupA|TupC)[]|Error csv1op2 = parseListAsListType(value, {skipLines: [2, 4]}); + (TupA|TupC)[]|csv:Error csv1op2 = csv:parseListAsListType(value, {skipLines: [2, 4]}); test:assertTrue(csv1op2 is (TupA|TupC)[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -460,56 +461,56 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupC|TupA)[]|Error csv1op3 = parseListAsListType(value, {skipLines: [2, 4]}); + (TupC|TupA)[]|csv:Error csv1op3 = csv:parseListAsListType(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)[]|Error csv1op4 = parseListAsListType(value, {skipLines: [2, 4]}); + (TupB|TupA)[]|csv:Error csv1op4 = csv:parseListAsListType(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])[]|Error csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); - test:assertTrue(csv1op4_2 is Error); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB|[boolean])[]'"); + (TupB|[boolean])[]|csv:Error csv1op4_2 = csv:parseListAsListType(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)[]|Error csv1op5 = parseListAsListType(value, {skipLines: [2, 4]}); + (TupA|TupB)[]|csv:Error csv1op5 = csv:parseListAsListType(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])[]|Error csv1op6 = parseListAsListType(value, {skipLines: [2, 4]}); + ([int]|[string])[]|csv:Error csv1op6 = csv:parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - ([string]|[int])[]|Error csv1op7 = parseListAsListType(value, {skipLines: [2, 4]}); + ([string]|[int])[]|csv:Error csv1op7 = csv:parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ ["1"], ["3"], ["5"] ]); - ([boolean...]|[int...])[]|Error csv1op8 = parseListAsListType(value, {stringConversion: false}); - test:assertTrue(csv1op8 is Error); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...]|[int...])[]'"); + ([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...])[]|Error csv1op8_2 = parseListAsListType(value, {}); + ([string...]|[int...])[]|csv:Error csv1op8_2 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op8_2, value); - ([int...]|[string...])[]|Error csv1op9 = parseListAsListType(value, {}); + ([int...]|[string...])[]|csv:Error csv1op9 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op9, value); - ([int, string...]|[string, int...])[]|Error csv1op10 = parseListAsListType(value, {}); + ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op10, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -518,7 +519,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - ([string, int...]|[int, string...])[]|Error csv1op11 = parseListAsListType(value, {}); + ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op11, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -527,10 +528,10 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - ([string, int...]|[string, string...])[]|Error csv1op12 = parseListAsListType(value, {}); + ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op12, value); - ([int, int...]|[string, string...])[]|Error csv1op13 = parseListAsListType([["1", "2"], ["a", "b"]], {}); + ([int, int...]|[string, string...])[]|csv:Error csv1op13 = csv:parseListAsListType([["1", "2"], ["a", "b"]], {}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] @@ -539,7 +540,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { @test:Config function testParseToStringWithUnionExpectedTypes6() returns error? { - RecA[]|RecC[]|Error csv1op1 = parseStringToRecord(csvStringData1, {header: 1}); + RecA[]|RecC[]|csv:Error csv1op1 = csv:parseStringToRecord(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: ()}, @@ -548,7 +549,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|Error csv1op2 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecA[]|RecC[]|csv:Error csv1op2 = csv:parseStringToRecord(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: ()}, @@ -556,42 +557,42 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|Error csv1op3 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecC[]|RecA[]|csv:Error csv1op3 = csv:parseStringToRecord(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[]|Error csv1op4 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecB[]|RecA[]|csv:Error csv1op4 = csv:parseStringToRecord(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[]|Error csv1op5 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + RecA[]|RecB[]|csv:Error csv1op5 = csv:parseStringToRecord(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;|}[]|Error csv1op6 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|Error csv1op7 = parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); + record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:parseStringToRecord(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|Error csv1op8 = parseStringToRecord(csvStringData1, {header: 1}); + record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:parseStringToRecord(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"}, @@ -600,7 +601,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - record{|int...;|}[]|record{|string...;|}[]|Error csv1op9 = parseStringToRecord(csvStringData1, {header: 1}); + record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -609,7 +610,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, d: 3, e: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|Error csv1op10 = parseStringToRecord(csvStringData1, {header: 1}); + record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseStringToRecord(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"}, @@ -618,7 +619,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|Error csv1op11 = parseStringToRecord(csvStringData1, {header: 1}); + record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseStringToRecord(csvStringData1, {header: 1}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -627,7 +628,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: "5", d: 3, e: 3} ]); - record{|int a; int b;|}[]|record{|string a; string...;|}[]|Error csv1op12 = parseStringToRecord(string ` + record{|int a; int b;|}[]|record{|string a; string...;|}[]|csv:Error csv1op12 = csv:parseStringToRecord(string ` a,b 1, 2 a, b`, {header: 1}); @@ -647,7 +648,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - RecA[]|RecC[]|Error csv1op1 = parseRecordAsRecordType(value, {}); + RecA[]|RecC[]|csv:Error csv1op1 = csv:parseRecordAsRecordType(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: ()}, @@ -656,7 +657,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|Error csv1op2 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecA[]|RecC[]|csv:Error csv1op2 = csv:parseRecordAsRecordType(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: ()}, @@ -664,42 +665,42 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|Error csv1op3 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecC[]|RecA[]|csv:Error csv1op3 = csv:parseRecordAsRecordType(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[]|Error csv1op4 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecB[]|RecA[]|csv:Error csv1op4 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op4, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - RecA[]|RecB[]|Error csv1op5 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + RecA[]|RecB[]|csv:Error csv1op5 = csv:parseRecordAsRecordType(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;|}[]|Error csv1op6 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|Error csv1op7 = parseRecordAsRecordType(value, {skipLines: [2, 4]}); + record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:parseRecordAsRecordType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|Error csv1op8 = parseRecordAsRecordType(value, {}); + record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:parseRecordAsRecordType(value, {}); test:assertEquals(csv1op8, [ {b: "string1"}, {b: "string2"}, @@ -708,7 +709,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {b: "string5"} ]); - record{|int...;|}[]|record{|string...;|}[]|Error csv1op9 = parseRecordAsRecordType(value, {}); + record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseRecordAsRecordType(value, {}); test:assertEquals(csv1op9, [ {a: 1, d: 2, e: 2}, {a: 2, d: 0, e: 0}, @@ -717,7 +718,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, d: 3, e: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|Error csv1op10 = parseRecordAsRecordType(value, {}); + record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseRecordAsRecordType(value, {}); test:assertEquals(csv1op10, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -726,7 +727,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|Error csv1op11 = parseRecordAsRecordType(value, {}); + record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseRecordAsRecordType(value, {}); test:assertEquals(csv1op11, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -735,9 +736,9 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5"} ]); - record{|string a; int...;|}[]|record{|string a; string...;|}[]|Error csv1op12 = parseRecordAsRecordType(value, {}); - test:assertTrue(csv1op12 is Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| string a; int...; |}[]|data.csv:record {| string a; string...; |}[])'"); + record{|string a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op12 = csv:parseRecordAsRecordType(value, {}); + test:assertTrue(csv1op12 is csv:Error); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(union_type_tests:record {| string a; int...; |}[]|union_type_tests:record {| string a; string...; |}[])'"); } @test:Config @@ -750,7 +751,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - RecA[]|RecC[]|Error csv1op1 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + RecA[]|RecC[]|csv:Error csv1op1 = csv:parseListAsRecordType(value, ["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: ()}, @@ -759,7 +760,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|Error csv1op2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecA[]|RecC[]|csv:Error csv1op2 = csv:parseListAsRecordType(value, ["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: ()}, @@ -767,49 +768,49 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|Error csv1op3 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecC[]|RecA[]|csv:Error csv1op3 = csv:parseListAsRecordType(value, ["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[]|Error csv1op4 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecB[]|RecA[]|csv:Error csv1op4 = csv:parseListAsRecordType(value, ["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[]|Error csv1op5 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecA[]|RecB[]|csv:Error csv1op5 = csv:parseListAsRecordType(value, ["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;|}[]|Error csv1op6 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|Error csv1op7 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|Error csv1op8 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [4, 2]}); + record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:parseListAsRecordType(value, ["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...;|}[]|Error csv1op9 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); + record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -818,7 +819,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, d: 3} ]); - record{|int...;|}[]|record{|string...;|}[]|Error csv1op9_2 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9_2 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); test:assertEquals(csv1op9_2, [ {}, {}, @@ -827,14 +828,14 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|Error csv1op10 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, -1, 4]}); + record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseListAsRecordType(value, ["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...;|}[]|Error csv1op11 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); + record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -843,11 +844,11 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", d: 3} ]); - record{|int a; int...;|}[]|record{|int a; string...;|}[]|Error csv1op12 = parseListAsRecordType(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); - test:assertTrue(csv1op12 is Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(data.csv:record {| int a; int...; |}[]|data.csv:record {| int a; string...; |}[])'"); + 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...;|}[]|Error csv1op13 = parseListAsRecordType([["1", "2"], ["a", "b"]], ["a", "b"], {}); + record{|int a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op13 = csv:parseListAsRecordType([["1", "2"], ["a", "b"]], ["a", "b"], {}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, {a: "a", b: "b"} @@ -865,7 +866,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - TupA[]|TupC[]|Error csv1op1 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + TupA[]|TupC[]|csv:Error csv1op1 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -874,7 +875,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupA[]|TupC[]|Error csv1op2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupA[]|TupC[]|csv:Error csv1op2 = csv:parseRecordAsListType(value, ["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, ()], @@ -882,64 +883,64 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupC[]|TupA[]|Error csv1op3 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupC[]|TupA[]|csv:Error csv1op3 = csv:parseRecordAsListType(value, ["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[]|Error csv1op4 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupB[]|TupA[]|csv:Error csv1op4 = csv:parseRecordAsListType(value, ["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][]|Error csv1op4_2 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); - test:assertTrue(csv1op4_2 is Error); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB[]|[boolean][])'"); + TupB[]|[boolean][]|csv:Error csv1op4_2 = csv:parseRecordAsListType(value, ["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[]|Error csv1op5 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + TupA[]|TupB[]|csv:Error csv1op5 = csv:parseRecordAsListType(value, ["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][]|Error csv1op6 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + [int][]|[string][]|csv:Error csv1op6 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - [string][]|[int][]|Error csv1op7 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + [string][]|[int][]|csv:Error csv1op7 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ [1], [3], [5] ]); - [string...][]|[int...][]|Error csv1op8 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op8 is Error); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([string...][]|[int...][])'"); + [string...][]|[int...][]|csv:Error csv1op8 = csv:parseRecordAsListType(value, ["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...][]|Error csv1op9 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op9 is Error); - test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '([int...][]|[string...][])'"); + [int...][]|[string...][]|csv:Error csv1op9 = csv:parseRecordAsListType(value, ["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...][]|Error csv1op10 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op10 is Error); - test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '([int,string...][]|[string,int...][])'"); + [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:parseRecordAsListType(value, ["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...][]|Error csv1op11 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op11 is Error); - test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '([string,int...][]|[int,string...][])'"); + [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:parseRecordAsListType(value, ["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...][]|Error csv1op12 = parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); - test:assertTrue(csv1op12 is Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...][]|[string,string...][])'"); + [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:parseRecordAsListType(value, ["a", "b", "c", "d", "e", "f"], {}); + test:assertTrue(csv1op12 is csv:Error); + test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...][]|[string,string...][])'"); } @test:Config @@ -952,7 +953,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - TupA[]|TupC[]|Error csv1op1 = parseListAsListType(value, {}); + TupA[]|TupC[]|csv:Error csv1op1 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -961,7 +962,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupA[]|TupC[]|Error csv1op2 = parseListAsListType(value, {skipLines: [2, 4]}); + TupA[]|TupC[]|csv:Error csv1op2 = csv:parseListAsListType(value, {skipLines: [2, 4]}); test:assertTrue(csv1op2 is TupA[]|TupC[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -969,56 +970,56 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupC[]|TupA[]|Error csv1op3 = parseListAsListType(value, {skipLines: [2, 4]}); + TupC[]|TupA[]|csv:Error csv1op3 = csv:parseListAsListType(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[]|Error csv1op4 = parseListAsListType(value, {skipLines: [2, 4]}); + TupB[]|TupA[]|csv:Error csv1op4 = csv:parseListAsListType(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][]|Error csv1op4_2 = parseListAsListType(value, {skipLines: [2, 4]}); - test:assertTrue(csv1op4_2 is Error); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(data.csv:TupB[]|[boolean][])'"); + TupB[]|[boolean][]|csv:Error csv1op4_2 = csv:parseListAsListType(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[]|Error csv1op5 = parseListAsListType(value, {skipLines: [2, 4]}); + TupA[]|TupB[]|csv:Error csv1op5 = csv:parseListAsListType(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][]|Error csv1op6 = parseListAsListType(value, {skipLines: [2, 4]}); + [int][]|[string][]|csv:Error csv1op6 = csv:parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - [string][]|[int][]|Error csv1op7 = parseListAsListType(value, {skipLines: [2, 4]}); + [string][]|[int][]|csv:Error csv1op7 = csv:parseListAsListType(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ ["1"], ["3"], ["5"] ]); - [boolean...][]|[int...][]|Error csv1op8 = parseListAsListType(value, {stringConversion: false}); - test:assertTrue(csv1op8 is Error); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([boolean...][]|[int...][])'"); + [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...][]|Error csv1op8_2 = parseListAsListType(value, {}); + [string...][]|[int...][]|csv:Error csv1op8_2 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op8_2, value); - [int...][]|[string...][]|Error csv1op9 = parseListAsListType(value, {}); + [int...][]|[string...][]|csv:Error csv1op9 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op9, value); - [int, string...][]|[string, int...][]|Error csv1op10 = parseListAsListType(value, {}); + [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op10, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -1027,7 +1028,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - [string, int...][]|[int, string...][]|Error csv1op11 = parseListAsListType(value, {}); + [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op11, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -1036,6 +1037,6 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - [string, int...][]|[string, string...][]|Error csv1op12 = parseListAsListType(value, {}); + [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:parseListAsListType(value, {}); test:assertEquals(csv1op12, value); } diff --git a/ballerina-tests/union-type-tests/tests/types.bal b/ballerina-tests/union-type-tests/tests/types.bal new file mode 100644 index 0000000..a2b4b2b --- /dev/null +++ b/ballerina-tests/union-type-tests/tests/types.bal @@ -0,0 +1,2534 @@ +type BooleanRecord1 record { + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +}; + +type BooleanRecord2 record {| + boolean b1; + boolean|string b2; + boolean|string? b3; + boolean b4; +|}; + +type BooleanRecord3 record {| + boolean b1; + boolean? b3; +|}; + +type BooleanRecord4 record { + boolean b1; + boolean? b3; +}; + +type BooleanRecord5 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +}; + +type BooleanRecord6 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); +|}; + +type BooleanRecord7 record { + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type BooleanRecord8 record {| + boolean b1; + boolean? b3; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type BooleanRecord9 record {| + boolean b1; + boolean? b3; + boolean?...; +|}; + +type BooleanRecord10 record {| + boolean...; +|}; + +type BooleanRecord11 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + boolean?|string...; +|}; + +type BooleanRecord12 record {| + boolean b1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string|boolean...; +|}; + +type BooleanRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + boolean...; +|}; + +type BooleanRecord15 record {| + int b1; + string defaultableField = ""; + string? nillableField = (); + boolean?...; +|}; + +type BooleanRecord16 record {| + boolean?...; +|}; + +type BooleanRecord17 record {| + int...; +|}; + +type BooleanRecord18 record {| + boolean b2; + int?...; +|}; + +type NilRecord1 record { + () n1; + () n2; + () n3; +}; + +type NilRecord2 record {| + () n1; + () n2; + () n3; +|}; + +type NilRecord3 record {| + () n1; + () n4; +|}; + +type NilRecord4 record { + () n1; + () n4; +}; + +type NilRecord5 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +}; + +type NilRecord6 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type NilRecord7 record { + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type NilRecord8 record {| + () n1; + () n4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type NilRecord9 record {| + () n1; + () n2; + ()...; +|}; + +type NilRecord10 record {| + ()...; +|}; + +type NilRecord11 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord12 record {| + () n1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type NilRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + ()...; +|}; + +type NilRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + ()...; +|}; + +type IntegerRecord1 record { + int i1; + int i2; + int i3; + int? i4; + int? i5; + int i6; + int i7; + int? i8; +}; + +type IntegerRecord2 record {| + int i1; + int? i2; + int i3; + int i4; + int? i5; + int i6; + int i7; + int? i8; +|}; + +type IntegerRecord3 record {| + int i1; + int i4; + int i6; +|}; + +type IntegerRecord4 record { + int i1; + int i4; + int i6; +}; + +type IntegerRecord5 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +}; + +type IntegerRecord6 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); +|}; + +type IntegerRecord7 record { + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type IntegerRecord8 record {| + int i1; + int i4; + int i6; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type IntegerRecord9 record {| + int i1; + int i2; + int...; +|}; + +type IntegerRecord10 record {| + int...; +|}; + +type IntegerRecord11 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord12 record {| + int i1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type IntegerRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + int...; +|}; + +type IntegerRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + int...; +|}; + +type FloatRecord1 record { + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +}; + +type FloatRecord2 record {| + float f1; + float f2; + float f3; + float f4; + float f5; + float f6; + float f7; + float f8; +|}; + +type FloatRecord3 record {| + float f1; + float f4; + float f7; +|}; + +type FloatRecord4 record { + float f1; + float f4; + float f7; +}; + +type FloatRecord5 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +}; + +type FloatRecord6 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type FloatRecord7 record { + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type FloatRecord8 record {| + float f1; + float f4; + float f7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type FloatRecord9 record {| + float f1; + float f2; + float...; +|}; + +type FloatRecord10 record {| + float...; +|}; + +type FloatRecord11 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord12 record {| + float f1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type FloatRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + float...; +|}; + +type FloatRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + float...; +|}; + +type DecimalRecord1 record { + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +}; + +type DecimalRecord2 record {| + decimal d1; + decimal d2; + decimal d3; + decimal d4; + decimal d5; + decimal d6; + decimal d7; + decimal d8; +|}; + +type DecimalRecord3 record {| + decimal d1; + decimal d4; + decimal d7; +|}; + +type DecimalRecord4 record { + decimal d1; + decimal d4; + decimal d7; +}; + +type DecimalRecord5 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +}; + +type DecimalRecord6 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); +|}; + +type DecimalRecord7 record { + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type DecimalRecord8 record {| + decimal d1; + decimal d4; + decimal d7; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type DecimalRecord9 record {| + decimal d1; + decimal d2; + decimal...; +|}; + +type DecimalRecord10 record {| + decimal...; +|}; + +type DecimalRecord11 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord12 record {| + decimal d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type DecimalRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + decimal...; +|}; + +type DecimalRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + decimal...; +|}; + +type StringRecord1 record { + string s1; + string s2; + string s3; +}; + +type StringRecord2 record {| + string s1; + string s2; + string s3; +|}; + +type StringRecord3 record {| + string s1; + string s4; +|}; + +type StringRecord4 record { + string s1; + string s4; +}; + +type StringRecord5 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +}; + +type StringRecord6 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); +|}; + +type StringRecord7 record { + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +}; + +type StringRecord8 record {| + string s1; + string s4; + string defaultableField = ""; + string? nillableField = (); + string requiredField; +|}; + +type StringRecord9 record {| + string s1; + string s2; + string...; +|}; + +type StringRecord10 record {| + string...; +|}; + +type StringRecord11 record {| + string s1; + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord12 record {| + string d1; + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + string...; +|}; + +type StringRecord14 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord15 record {| + string defaultableField = ""; + string? nillableField = (); + string requiredField; + string...; +|}; + +type StringRecord16 record {| + string?...; +|}; + +type StringRecord17 record {| + int...; +|}; + +type StringRecord18 record {| + string b2; + int?...; +|}; + +type StringRecord19 record { + string s1 = ""; + string s2 = ""; +}; + +type StringRecord20 record {| + string s1 = ""; + string s2 = ""; +|}; + +type StringRecord21 record { +}; + +type StringRecord22 record {| + string s1 = ""; + string s2 = ""; + json...; +|}; + +type StringRecord23 record {| + json...; +|}; + +type JsonRecord1 record { + json j1; + json j2; + json j3; +}; + +type JsonRecord2 record {| + json j1; + json j2; + json j3; +|}; + +type JsonRecord3 record {| + json j1; + json j4; +|}; + +type JsonRecord4 record { + json j1; + json j4; +}; + +type JsonRecord5 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +}; + +type JsonRecord6 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); +|}; + +type JsonRecord7 record { + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +}; + +type JsonRecord8 record {| + json j1; + json j4; + json defaultableField = ""; + json? nillableField = (); + json requiredField; +|}; + +type JsonRecord9 record {| + json j1; + json j2; + json...; +|}; + +type JsonRecord10 record {| + json...; +|}; + +type JsonRecord11 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord12 record {| + json j1; + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type JsonRecord13 record {| + json defaultableField = ""; + json? nillableField = (); + json...; +|}; + +type JsonRecord14 record {| + json defaultableField = ""; + json? nillableField = (); + json requiredField; + json...; +|}; + +type AnydataRecord1 record { + anydata anydata1; + anydata anydata2; + anydata anydata3; +}; + +type AnydataRecord2 record {| + anydata anydata1; + anydata anydata2; + anydata anydata3; +|}; + +type AnydataRecord3 record {| + anydata anydata1; + anydata anydata4; +|}; + +type AnydataRecord4 record { + anydata anydata1; + anydata anydata4; +}; + +type AnydataRecord5 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +}; + +type AnydataRecord6 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type AnydataRecord7 record { + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type AnydataRecord8 record {| + anydata anydata1; + anydata anydata4; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type AnydataRecord9 record {| + anydata anydata1; + anydata anydata2; + anydata...; +|}; + +type AnydataRecord10 record {| + anydata...; +|}; + +type AnydataRecord11 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord12 record {| + anydata anydata1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type AnydataRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata...; +|}; + +type AnydataRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + anydata...; +|}; + +type CustomRecord1 record { + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +}; + +type CustomRecord2 record {| + int i1; + int i2; + string s1; + string s2; + boolean b1; + boolean b2; + () n1; + () n2; + float f1; + float f2; + decimal d1; + decimal d2; +|}; + +type CustomRecord3 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +|}; + +type CustomRecord4 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; +}; + +type CustomRecord5 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string defaultableField = ""; + string? nillableField = (); +}; + +type CustomRecord6 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); +|}; + +type CustomRecord7 record { + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +}; + +type CustomRecord8 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; +|}; + +type CustomRecord9 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + string...; +|}; + +type CustomRecord10 record {| + string...; +|}; + +type CustomRecord11 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord12 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomRecord13 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord14 record {| + anydata defaultableField = ""; + anydata? nillableField = (); + anydata requiredField; + string...; +|}; + +type CustomRecord15 record {| + string '1; + string '2; +|}; + +type CustomRecord16 record {| + string '1; + string '2; + string '3; + string '4; +|}; + +type CustomRecord17 record { + string '1; + string '2; +}; + +type CustomRecord18 record { + string '1; + string '2; + string '3; + string '4; +}; + +type CustomRecord19 record { + string '1; + string '2; + string '3 = ""; + string '4 = ""; +}; + +type CustomRecord20 record { + string '1; +}; + +type CustomRecord21 record {| + string '1; + json...; +|}; + +type CustomRecord22 record {| + string '1; + string...; +|}; + +type CustomRecord23 record {| + string '1; + string a = ""; + string...; +|}; + +type CustomRecord24 record {| + string '1; + string '2 = ""; + string...; +|}; + +type CustomRecord25 record {| + int '1; + string...; +|}; + +type CustomRecord26 record {| + string '1; + int...; +|}; + +type CustomRecord27 record {| + int i1; + string s1; + boolean b1; + () n1; + float f1; + decimal d1; + anydata a1; + json j1; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; +|}; + +type CustomRecord28 record { + string '1; +}; + +type CustomRecord29 record { + int '1; +}; + +type CustomRecord30 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord31 record {| + string '1; + string '6; +|}; + +type CustomRecord32 record {| + int '1; +|}; + +type CustomRecord33 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; +|}; + +type CustomRecord34 record { + string '1; + string '6; + string '5 = ""; +}; + +type CustomRecord35 record { + string '1; + string '6; + string '9 = ""; +}; + +type CustomRecord36 record {| + string '1; + string '6; + string '9 = ""; +|}; + +type CustomRecord37 record {| + string '1; + string '6; + string '5 = ""; +|}; + +type CustomRecord38 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + string ...; +|}; + +type CustomRecord39 record {| + string '1; + string '2; + string '3; + string '4; + string '5; + string '6; + json ...; +|}; + +type CustomRecord40 record {| + string '5; + string '6; + json ...; +|}; + +type CustomRecord41 record {| + json ...; +|}; + +type CustomRecord42 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +|}; + +type CustomRecord43 record { + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; +}; + +type CustomRecord44 record {| + int '1; + string '2; + boolean '3; + decimal '4; + float '5; + () '6; + string ...; +|}; + +type CustomRecord45 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +|}; + +type CustomRecord46 record { + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; +}; + +type CustomRecord47 record {| + int H1; + string H2; + boolean H3; + decimal H4; + float H5; + () H6; + string ...; +|}; + +type CustomRecord48 record { + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +}; + +type CustomRecord49 record {| + string H1; + string H2; + string H3; + string H4; + string H5; + string H6; +|}; + +type CustomRecord50 record { + int H1; + float H4; +}; + +type CustomRecord51 record {| + int H1; + float H4; +|}; + +type CustomRecord52 record {| + string H1; + string H4; + string ...; +|}; + +type CustomRecord53 record {| + int H1; + float H4; + decimal ...; +|}; + +type CustomRecord54 record {| + string H1 = ""; + string H4; + string '1; +|}; + +type CustomRecord55 record {| + string H1 = ""; + string H4 = ""; + int '1 = 10; +|}; + +type CustomRecord56 record { + string H1 = ""; + string H4 = ""; + anydata '1 = 10; +}; + +type BooleanTuple1 [boolean, boolean, boolean, boolean]; + +type BooleanTuple2 [boolean, boolean]; + +type BooleanTuple3 [boolean, boolean...]; + +type BooleanTuple4 [boolean...]; + +type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; + +type NillableBooleanTuple6 [boolean?, boolean?]; + +type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; + +type NillableBooleanTuple8 [boolean?...]; + +type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; + +type NilTuple1 [(), (), ()]; + +type NilTuple2 [(), ()]; + +type NilTuple3 [(), ()...]; + +type NilTuple4 [()...]; + +type IntegerTuple1 [int, int, int, int, int, int]; + +type IntegerTuple2 [int, int]; + +type IntegerTuple3 [int, int...]; + +type IntegerTuple4 [int...]; + +type FloatTuple1 [float, float, float, float, float, float, float]; + +type FloatTuple2 [float, float]; + +type FloatTuple3 [float, float...]; + +type FloatTuple4 [float...]; + +type DecimalTuple1 [decimal, decimal, decimal, decimal]; + +type DecimalTuple2 [decimal, decimal]; + +type DecimalTuple3 [decimal, decimal...]; + +type DecimalTuple4 [decimal...]; + +type StringTuple1 [string, string, string, string]; + +type StringTuple2 [string, string]; + +type StringTuple3 [string, string...]; + +type StringTuple4 [string...]; + +type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata]; + +type AnydataTuple2 [anydata, anydata]; + +type AnydataTuple3 [anydata, anydata...]; + +type AnydataTuple4 [anydata...]; + +type JsonTuple1 [json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json]; + +type JsonTuple2 [json, json]; + +type JsonTuple3 [json, json...]; + +type JsonTuple4 [json...]; + +type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; + +type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; + +type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; + +type CustomTuple4 [string...]; + +type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; + +type CustomTuple6 [anydata...]; + +type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; + +type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; + +type IntegerArray1 int[]; + +type IntegerArray2 int[2]; + +type IntegerArray3 int[]; + +type IntegerArray4 int[2]; + +type IntegerArray5 int[3]; + +type IntegerArray6 int[4]; + +type StringArray string[]; + +type NillableStringArray string?[]; + +type NillableIntOrUnionStringArray (int|string?)[]; + +type StringArray1 string[]; + +type StringArray2 string[2]; + +type StringArray3 string[]; + +type StringArray4 string[2]; + +type StringArray5 string[3]; + +type StringArray6 string[4]; + +type FloatArray1 float[]; + +type FloatArray2 float[2]; + +type FloatArray3 float[]; + +type FloatArray4 float[2]; + +type FloatArray5 float[3]; + +type FloatArray6 float[4]; + +type DecimalArray1 decimal[]; + +type DecimalArray2 decimal[2]; + +type DecimalArray3 decimal[]; + +type DecimalArray4 decimal[2]; + +type DecimalArray5 decimal[3]; + +type DecimalArray6 decimal[4]; + +type BooleanArray boolean[]; + +type NillableBooleanArray boolean?[]; + +type NillableIntOrUnionBooleanArray (int|boolean?)[]; + +type BooleanArray2 boolean[2]; + +type BooleanArray3 boolean[3]; + +type BooleanArray4 boolean[]; + +type BooleanArray5 boolean[2]; + +type BooleanArray6 boolean[4]; + +type NilArray1 ()[]; + +type NilArray2 ()[2]; + +type NilArray3 ()[]; + +type NilArray4 ()[2]; + +type NilArray5 ()[3]; + +type NilArray6 ()[4]; + +type JsonArray1 json[]; + +type JsonArray2 json[2]; + +type JsonArray3 json[]; + +type JsonArray4 json[2]; + +type JsonArray5 json[3]; + +type JsonArray6 json[4]; + +type AnydataArray1 anydata[]; + +type AnydataArray2 anydata[2]; + +type AnydataArray3 anydata[]; + +type AnydataArray4 anydata[2]; + +type AnydataArray5 anydata[3]; + +type AnydataArray6 anydata[4]; + +type CustomArray1 CustomTuple2[]; + +type CustomArray2 CustomTuple2[2]; + +type CustomArray3 CustomTuple2[]; + +type CustomArray4 CustomTuple2[2]; + +type CustomArray5 CustomTuple2[3]; + +type CustomArray6 CustomTuple2[4]; + +type IntegerMap map; + +type StringMap map; + +type NillableIntUnionStringMap map; + +type IntUnionStringMap map; + +type DecimalMap map; + +type FloatMap map; + +type BooleanMap map; + +type NillableBooleanMap map; + +type NillableIntUnionBooleanMap map; + +type IntUnionBooleanMap map; + +type NilMap map<()>; + +type JsonMap map; + +type AnydataMap map; + +type CustomMap map; + +type BooleanRecord1Array BooleanRecord1[]; + +type ClosedBooleanRecord1Array BooleanRecord1[3]; + +type BooleanRecord2Array BooleanRecord2[]; + +type ClosedBooleanRecord2Array BooleanRecord2[3]; + +type BooleanRecord3Array BooleanRecord3[]; + +type ClosedBooleanRecord3Array BooleanRecord3[3]; + +type BooleanRecord4Array BooleanRecord4[]; + +type ClosedBooleanRecord4Array BooleanRecord4[3]; + +type BooleanRecord5Array BooleanRecord5[]; + +type ClosedBooleanRecord5Array BooleanRecord5[3]; + +type BooleanRecord6Array BooleanRecord6[]; + +type ClosedBooleanRecord6Array BooleanRecord6[3]; + +type BooleanRecord7Array BooleanRecord7[]; + +type ClosedBooleanRecord7Array BooleanRecord7[3]; + +type BooleanRecord8Array BooleanRecord8[]; + +type ClosedBooleanRecord8Array BooleanRecord8[3]; + +type BooleanRecord9Array BooleanRecord9[]; + +type ClosedBooleanRecord9Array BooleanRecord9[3]; + +type BooleanRecord10Array BooleanRecord10[]; + +type ClosedBooleanRecord10Array BooleanRecord10[3]; + +type BooleanRecord11Array BooleanRecord11[]; + +type ClosedBooleanRecord11Array BooleanRecord11[3]; + +type BooleanRecord12Array BooleanRecord12[]; + +type ClosedBooleanRecord12Array BooleanRecord12[3]; + +type BooleanRecord13Array BooleanRecord13[]; + +type ClosedBooleanRecord13Array BooleanRecord13[3]; + +type BooleanRecord14Array BooleanRecord14[]; + +type ClosedBooleanRecord14Array BooleanRecord14[3]; + +type BooleanRecord15Array BooleanRecord15[]; + +type ClosedBooleanRecord15Array BooleanRecord15[3]; + +type BooleanRecord16Array BooleanRecord16[]; + +type ClosedBooleanRecord16Array BooleanRecord16[3]; + +type BooleanRecord17Array BooleanRecord17[]; + +type ClosedBooleanRecord17Array BooleanRecord17[3]; + +type BooleanRecord18Array BooleanRecord18[]; + +type ClosedBooleanRecord18Array BooleanRecord18[3]; + +type NilRecord1Array NilRecord1[]; + +type ClosedNilRecord1Array NilRecord1[3]; + +type NilRecord2Array NilRecord2[]; + +type ClosedNilRecord2Array NilRecord2[3]; + +type NilRecord3Array NilRecord3[]; + +type ClosedNilRecord3Array NilRecord3[3]; + +type NilRecord4Array NilRecord4[]; + +type ClosedNilRecord4Array NilRecord4[3]; + +type NilRecord5Array NilRecord5[]; + +type ClosedNilRecord5Array NilRecord5[3]; + +type NilRecord6Array NilRecord6[]; + +type ClosedNilRecord6Array NilRecord6[3]; + +type NilRecord7Array NilRecord7[]; + +type ClosedNilRecord7Array NilRecord7[3]; + +type NilRecord8Array NilRecord8[]; + +type ClosedNilRecord8Array NilRecord8[3]; + +type NilRecord9Array NilRecord9[]; + +type ClosedNilRecord9Array NilRecord9[3]; + +type NilRecord10Array NilRecord10[]; + +type ClosedNilRecord10Array NilRecord10[3]; + +type NilRecord11Array NilRecord11[]; + +type ClosedNilRecord11Array NilRecord11[3]; + +type NilRecord12Array NilRecord12[]; + +type ClosedNilRecord12Array NilRecord12[3]; + +type NilRecord13Array NilRecord13[]; + +type ClosedNilRecord13Array NilRecord13[3]; + +type NilRecord14Array NilRecord14[]; + +type ClosedNilRecord14Array NilRecord14[3]; + +type IntegerRecord1Array IntegerRecord1[]; + +type ClosedIntegerRecord1Array IntegerRecord1[3]; + +type IntegerRecord2Array IntegerRecord2[]; + +type ClosedIntegerRecord2Array IntegerRecord2[3]; + +type IntegerRecord3Array IntegerRecord3[]; + +type ClosedIntegerRecord3Array IntegerRecord3[3]; + +type IntegerRecord4Array IntegerRecord4[]; + +type ClosedIntegerRecord4Array IntegerRecord4[3]; + +type IntegerRecord5Array IntegerRecord5[]; + +type ClosedIntegerRecord5Array IntegerRecord5[3]; + +type IntegerRecord6Array IntegerRecord6[]; + +type ClosedIntegerRecord6Array IntegerRecord6[3]; + +type IntegerRecord7Array IntegerRecord7[]; + +type ClosedIntegerRecord7Array IntegerRecord7[3]; + +type IntegerRecord8Array IntegerRecord8[]; + +type ClosedIntegerRecord8Array IntegerRecord8[3]; + +type IntegerRecord9Array IntegerRecord9[]; + +type ClosedIntegerRecord9Array IntegerRecord9[3]; + +type IntegerRecord10Array IntegerRecord10[]; + +type ClosedIntegerRecord10Array IntegerRecord10[3]; + +type IntegerRecord11Array IntegerRecord11[]; + +type ClosedIntegerRecord11Array IntegerRecord11[3]; + +type IntegerRecord12Array IntegerRecord12[]; + +type ClosedIntegerRecord12Array IntegerRecord12[3]; + +type IntegerRecord13Array IntegerRecord13[]; + +type ClosedIntegerRecord13Array IntegerRecord13[3]; + +type IntegerRecord14Array IntegerRecord14[]; + +type ClosedIntegerRecord14Array IntegerRecord14[3]; + +type FloatRecord1Array FloatRecord1[]; + +type ClosedFloatRecord1Array FloatRecord1[3]; + +type FloatRecord2Array FloatRecord2[]; + +type ClosedFloatRecord2Array FloatRecord2[3]; + +type FloatRecord3Array FloatRecord3[]; + +type ClosedFloatRecord3Array FloatRecord3[3]; + +type FloatRecord4Array FloatRecord4[]; + +type ClosedFloatRecord4Array FloatRecord4[3]; + +type FloatRecord5Array FloatRecord5[]; + +type ClosedFloatRecord5Array FloatRecord5[3]; + +type FloatRecord6Array FloatRecord6[]; + +type ClosedFloatRecord6Array FloatRecord6[3]; + +type FloatRecord7Array FloatRecord7[]; + +type ClosedFloatRecord7Array FloatRecord7[3]; + +type FloatRecord8Array FloatRecord8[]; + +type ClosedFloatRecord8Array FloatRecord8[3]; + +type FloatRecord9Array FloatRecord9[]; + +type ClosedFloatRecord9Array FloatRecord9[3]; + +type FloatRecord10Array FloatRecord10[]; + +type ClosedFloatRecord10Array FloatRecord10[3]; + +type FloatRecord11Array FloatRecord11[]; + +type ClosedFloatRecord11Array FloatRecord11[3]; + +type FloatRecord12Array FloatRecord12[]; + +type ClosedFloatRecord12Array FloatRecord12[3]; + +type FloatRecord13Array FloatRecord13[]; + +type ClosedFloatRecord13Array FloatRecord13[3]; + +type FloatRecord14Array FloatRecord14[]; + +type ClosedFloatRecord14Array FloatRecord14[3]; + +type DecimalRecord1Array DecimalRecord1[]; + +type ClosedDecimalRecord1Array DecimalRecord1[3]; + +type DecimalRecord2Array DecimalRecord2[]; + +type ClosedDecimalRecord2Array DecimalRecord2[3]; + +type DecimalRecord3Array DecimalRecord3[]; + +type ClosedDecimalRecord3Array DecimalRecord3[3]; + +type DecimalRecord4Array DecimalRecord4[]; + +type ClosedDecimalRecord4Array DecimalRecord4[3]; + +type DecimalRecord5Array DecimalRecord5[]; + +type ClosedDecimalRecord5Array DecimalRecord5[3]; + +type DecimalRecord6Array DecimalRecord6[]; + +type ClosedDecimalRecord6Array DecimalRecord6[3]; + +type DecimalRecord7Array DecimalRecord7[]; + +type ClosedDecimalRecord7Array DecimalRecord7[3]; + +type DecimalRecord8Array DecimalRecord8[]; + +type ClosedDecimalRecord8Array DecimalRecord8[3]; + +type DecimalRecord9Array DecimalRecord9[]; + +type ClosedDecimalRecord9Array DecimalRecord9[3]; + +type DecimalRecord10Array DecimalRecord10[]; + +type ClosedDecimalRecord10Array DecimalRecord10[3]; + +type DecimalRecord11Array DecimalRecord11[]; + +type ClosedDecimalRecord11Array DecimalRecord11[3]; + +type DecimalRecord12Array DecimalRecord12[]; + +type ClosedDecimalRecord12Array DecimalRecord12[3]; + +type DecimalRecord13Array DecimalRecord13[]; + +type ClosedDecimalRecord13Array DecimalRecord13[3]; + +type DecimalRecord14Array DecimalRecord14[]; + +type ClosedDecimalRecord14Array DecimalRecord14[3]; + +type StringRecord1Array StringRecord1[]; + +type ClosedStringRecord1Array StringRecord1[3]; + +type StringRecord2Array StringRecord2[]; + +type ClosedStringRecord2Array StringRecord2[3]; + +type StringRecord3Array StringRecord3[]; + +type ClosedStringRecord3Array StringRecord3[3]; + +type StringRecord4Array StringRecord4[]; + +type ClosedStringRecord4Array StringRecord4[3]; + +type StringRecord5Array StringRecord5[]; + +type ClosedStringRecord5Array StringRecord5[3]; + +type StringRecord6Array StringRecord6[]; + +type ClosedStringRecord6Array StringRecord6[3]; + +type StringRecord7Array StringRecord7[]; + +type ClosedStringRecord7Array StringRecord7[3]; + +type StringRecord8Array StringRecord8[]; + +type ClosedStringRecord8Array StringRecord8[3]; + +type StringRecord9Array StringRecord9[]; + +type ClosedStringRecord9Array StringRecord9[3]; + +type StringRecord10Array StringRecord10[]; + +type ClosedStringRecord10Array StringRecord10[3]; + +type StringRecord11Array StringRecord11[]; + +type ClosedStringRecord11Array StringRecord11[3]; + +type StringRecord12Array StringRecord12[]; + +type ClosedStringRecord12Array StringRecord12[3]; + +type StringRecord13Array StringRecord13[]; + +type ClosedStringRecord13Array StringRecord13[3]; + +type StringRecord14Array StringRecord14[]; + +type ClosedStringRecord14Array StringRecord14[3]; + +type StringRecord15Array StringRecord15[]; + +type StringRecord16Array StringRecord16[]; + +type StringRecord17Array StringRecord17[]; + +type StringRecord18Array StringRecord18[]; + +type StringRecord19Array StringRecord19[]; + +type StringRecord20Array StringRecord20[]; + +type StringRecord21Array StringRecord21[]; + +type StringRecord22Array StringRecord22[]; + +type StringRecord23Array StringRecord23[]; + +type JsonRecord1Array JsonRecord1[]; + +type ClosedJsonRecord1Array JsonRecord1[3]; + +type JsonRecord2Array JsonRecord2[]; + +type ClosedJsonRecord2Array JsonRecord2[3]; + +type JsonRecord3Array JsonRecord3[]; + +type ClosedJsonRecord3Array JsonRecord3[3]; + +type JsonRecord4Array JsonRecord4[]; + +type ClosedJsonRecord4Array JsonRecord4[3]; + +type JsonRecord5Array JsonRecord5[]; + +type ClosedJsonRecord5Array JsonRecord5[3]; + +type JsonRecord6Array JsonRecord6[]; + +type ClosedJsonRecord6Array JsonRecord6[3]; + +type JsonRecord7Array JsonRecord7[]; + +type ClosedJsonRecord7Array JsonRecord7[3]; + +type JsonRecord8Array JsonRecord8[]; + +type ClosedJsonRecord8Array JsonRecord8[3]; + +type JsonRecord9Array JsonRecord9[]; + +type ClosedJsonRecord9Array JsonRecord9[3]; + +type JsonRecord10Array JsonRecord10[]; + +type ClosedJsonRecord10Array JsonRecord10[3]; + +type JsonRecord11Array JsonRecord11[]; + +type ClosedJsonRecord11Array JsonRecord11[3]; + +type JsonRecord12Array JsonRecord12[]; + +type ClosedJsonRecord12Array JsonRecord12[3]; + +type JsonRecord13Array JsonRecord13[]; + +type ClosedJsonRecord13Array JsonRecord13[3]; + +type JsonRecord14Array JsonRecord14[]; + +type ClosedJsonRecord14Array JsonRecord14[3]; + +type AnydataRecord1Array AnydataRecord1[]; + +type ClosedAnydataRecord1Array AnydataRecord1[3]; + +type AnydataRecord2Array AnydataRecord2[]; + +type ClosedAnydataRecord2Array AnydataRecord2[3]; + +type AnydataRecord3Array AnydataRecord3[]; + +type ClosedAnydataRecord3Array AnydataRecord3[3]; + +type AnydataRecord4Array AnydataRecord4[]; + +type ClosedAnydataRecord4Array AnydataRecord4[3]; + +type AnydataRecord5Array AnydataRecord5[]; + +type ClosedAnydataRecord5Array AnydataRecord5[3]; + +type AnydataRecord6Array AnydataRecord6[]; + +type ClosedAnydataRecord6Array AnydataRecord6[3]; + +type AnydataRecord7Array AnydataRecord7[]; + +type ClosedAnydataRecord7Array AnydataRecord7[3]; + +type AnydataRecord8Array AnydataRecord8[]; + +type ClosedAnydataRecord8Array AnydataRecord8[3]; + +type AnydataRecord9Array AnydataRecord9[]; + +type ClosedAnydataRecord9Array AnydataRecord9[3]; + +type AnydataRecord10Array AnydataRecord10[]; + +type ClosedAnydataRecord10Array AnydataRecord10[3]; + +type AnydataRecord11Array AnydataRecord11[]; + +type ClosedAnydataRecord11Array AnydataRecord11[3]; + +type AnydataRecord12Array AnydataRecord12[]; + +type ClosedAnydataRecord12Array AnydataRecord12[3]; + +type AnydataRecord13Array AnydataRecord13[]; + +type ClosedAnydataRecord13Array AnydataRecord13[3]; + +type AnydataRecord14Array AnydataRecord14[]; + +type ClosedAnydataRecord14Array AnydataRecord14[3]; + +type CustomRecord1Array CustomRecord1[]; + +type ClosedCustomRecord1Array CustomRecord1[3]; + +type CustomRecord2Array CustomRecord2[]; + +type ClosedCustomRecord2Array CustomRecord2[3]; + +type CustomRecord3Array CustomRecord3[]; + +type ClosedCustomRecord3Array CustomRecord3[3]; + +type CustomRecord4Array CustomRecord4[]; + +type ClosedCustomRecord4Array CustomRecord4[3]; + +type CustomRecord5Array CustomRecord5[]; + +type ClosedCustomRecord5Array CustomRecord5[3]; + +type CustomRecord6Array CustomRecord6[]; + +type ClosedCustomRecord6Array CustomRecord6[3]; + +type CustomRecord7Array CustomRecord7[]; + +type ClosedCustomRecord7Array CustomRecord7[3]; + +type CustomRecord8Array CustomRecord8[]; + +type ClosedCustomRecord8Array CustomRecord8[3]; + +type CustomRecord9Array CustomRecord9[]; + +type ClosedCustomRecord9Array CustomRecord9[3]; + +type CustomRecord10Array CustomRecord10[]; + +type ClosedCustomRecord10Array CustomRecord10[3]; + +type CustomRecord11Array CustomRecord11[]; + +type ClosedCustomRecord11Array CustomRecord11[3]; + +type CustomRecord12Array CustomRecord12[]; + +type ClosedCustomRecord12Array CustomRecord12[3]; + +type CustomRecord13Array CustomRecord13[]; + +type ClosedCustomRecord13Array CustomRecord13[3]; + +type CustomRecord14Array CustomRecord14[]; + +type ClosedCustomRecord14Array CustomRecord14[3]; + +type CustomRecord15Array CustomRecord15[]; + +type CustomRecord16Array CustomRecord16[]; + +type CustomRecord17Array CustomRecord17[]; + +type CustomRecord18Array CustomRecord18[]; + +type CustomRecord19Array CustomRecord19[]; + +type CustomRecord20Array CustomRecord20[]; + +type CustomRecord21Array CustomRecord21[]; + +type CustomRecord22Array CustomRecord22[]; + +type CustomRecord23Array CustomRecord23[]; + +type CustomRecord24Array CustomRecord24[]; + +type CustomRecord25Array CustomRecord25[]; + +type CustomRecord26Array CustomRecord26[]; + +type CustomRecord27Array CustomRecord27[]; +type CustomRecord28Array CustomRecord28[]; +type CustomRecord29Array CustomRecord29[]; +type CustomRecord30Array CustomRecord30[]; +type CustomRecord31Array CustomRecord31[]; +type CustomRecord32Array CustomRecord32[]; +type CustomRecord33Array CustomRecord33[]; +type CustomRecord34Array CustomRecord34[]; +type CustomRecord35Array CustomRecord35[]; +type CustomRecord36Array CustomRecord36[]; +type CustomRecord37Array CustomRecord37[]; +type CustomRecord38Array CustomRecord38[]; +type CustomRecord39Array CustomRecord39[]; +type CustomRecord40Array CustomRecord40[]; +type CustomRecord41Array CustomRecord41[]; +type CustomRecord42Array CustomRecord42[]; +type CustomRecord43Array CustomRecord43[]; +type CustomRecord44Array CustomRecord44[]; +type CustomRecord45Array CustomRecord45[]; +type CustomRecord46Array CustomRecord46[]; +type CustomRecord47Array CustomRecord47[]; +type CustomRecord48Array CustomRecord48[]; +type CustomRecord49Array CustomRecord49[]; +type CustomRecord50Array CustomRecord50[]; +type CustomRecord51Array CustomRecord51[]; +type CustomRecord52Array CustomRecord52[]; +type CustomRecord53Array CustomRecord53[]; +type CustomRecord54Array CustomRecord54[]; +type CustomRecord55Array CustomRecord55[]; +type CustomRecord56Array CustomRecord56[]; + +type BooleanTuple1Array BooleanTuple1[]; + +type ClosedBooleanTuple1Array BooleanTuple1[3]; + +type BooleanTuple2Array BooleanTuple2[]; + +type ClosedBooleanTuple2Array BooleanTuple2[3]; + +type BooleanTuple3Array BooleanTuple3[]; + +type ClosedBooleanTuple3Array BooleanTuple3[3]; + +type BooleanTuple4Array BooleanTuple4[]; + +type ClosedBooleanTuple4Array BooleanTuple4[3]; + +type NillableBooleanTuple5Array NillableBooleanTuple5[]; + +type NillableBooleanTuple6Array NillableBooleanTuple6[]; + +type NillableBooleanTuple7Array NillableBooleanTuple7[]; + +type NillableBooleanTuple8Array NillableBooleanTuple8[]; + +type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; + +type NilTuple1Array NilTuple1[]; + +type ClosedNilTuple1Array NilTuple1[3]; + +type NilTuple2Array NilTuple2[]; + +type ClosedNilTuple2Array NilTuple2[3]; + +type NilTuple3Array NilTuple3[]; + +type ClosedNilTuple3Array NilTuple3[3]; + +type NilTuple4Array NilTuple4[]; + +type ClosedNilTuple4Array NilTuple4[3]; + +type IntegerTuple1Array IntegerTuple1[]; + +type ClosedIntegerTuple1Array IntegerTuple1[3]; + +type IntegerTuple2Array IntegerTuple2[]; + +type ClosedIntegerTuple2Array IntegerTuple2[3]; + +type IntegerTuple3Array IntegerTuple3[]; + +type ClosedIntegerTuple3Array IntegerTuple3[3]; + +type IntegerTuple4Array IntegerTuple4[]; + +type ClosedIntegerTuple4Array IntegerTuple4[3]; + +type FloatTuple1Array FloatTuple1[]; + +type ClosedFloatTuple1Array FloatTuple1[3]; + +type FloatTuple2Array FloatTuple2[]; + +type ClosedFloatTuple2Array FloatTuple2[3]; + +type FloatTuple3Array FloatTuple3[]; + +type ClosedFloatTuple3Array FloatTuple3[3]; + +type FloatTuple4Array FloatTuple4[]; + +type ClosedFloatTuple4Array FloatTuple4[3]; + +type DecimalTuple1Array DecimalTuple1[]; + +type ClosedDecimalTuple1Array DecimalTuple1[3]; + +type DecimalTuple2Array DecimalTuple2[]; + +type ClosedDecimalTuple2Array DecimalTuple2[3]; + +type DecimalTuple3Array DecimalTuple3[]; + +type ClosedDecimalTuple3Array DecimalTuple3[3]; + +type DecimalTuple4Array DecimalTuple4[]; + +type ClosedDecimalTuple4Array DecimalTuple4[3]; + +type StringTuple1Array StringTuple1[]; + +type ClosedStringTuple1Array StringTuple1[3]; + +type StringTuple2Array StringTuple2[]; + +type ClosedStringTuple2Array StringTuple2[3]; + +type StringTuple3Array StringTuple3[]; + +type ClosedStringTuple3Array StringTuple3[3]; + +type StringTuple4Array StringTuple4[]; + +type ClosedStringTuple4Array StringTuple4[3]; + +type AnydataTuple1Array AnydataTuple1[]; + +type ClosedAnydataTuple1Array AnydataTuple1[3]; + +type AnydataTuple2Array AnydataTuple2[]; + +type ClosedAnydataTuple2Array AnydataTuple2[3]; + +type AnydataTuple3Array AnydataTuple3[]; + +type ClosedAnydataTuple3Array AnydataTuple3[3]; + +type AnydataTuple4Array AnydataTuple4[]; + +type ClosedAnydataTuple4Array AnydataTuple4[3]; + +type JsonTuple1Array JsonTuple1[]; + +type ClosedJsonTuple1Array JsonTuple1[3]; + +type JsonTuple2Array JsonTuple2[]; + +type ClosedJsonTuple2Array JsonTuple2[3]; + +type JsonTuple3Array JsonTuple3[]; + +type ClosedJsonTuple3Array JsonTuple3[3]; + +type JsonTuple4Array JsonTuple4[]; + +type ClosedJsonTuple4Array JsonTuple4[3]; + +type CustomTuple1Array CustomTuple1[]; + +type ClosedCustomTuple1Array CustomTuple1[3]; + +type CustomTuple2Array CustomTuple2[]; + +type ClosedCustomTuple2Array CustomTuple2[3]; + +type CustomTuple3Array CustomTuple3[]; + +type ClosedCustomTuple3Array CustomTuple3[3]; + +type CustomTuple4Array CustomTuple4[]; + +type ClosedCustomTuple4Array CustomTuple4[3]; + +type CustomTuple5Array CustomTuple5[]; + +type ClosedCustomTuple5Array CustomTuple5[3]; + +type CustomTuple6Array CustomTuple6[]; + +type CustomTuple7Array CustomTuple7[]; + +type CustomTuple8Array CustomTuple8[]; + +type ClosedCustomTuple6Array CustomTuple6[3]; + +type IntegerArray1Array IntegerArray1[]; + +type ClosedIntegerArray1Array IntegerArray1[3]; + +type IntegerArray2Array IntegerArray2[]; + +type ClosedIntegerArray2Array IntegerArray2[3]; + +type IntegerArray3Array IntegerArray3[]; + +type ClosedIntegerArray3Array IntegerArray3[3]; + +type IntegerArray4Array IntegerArray4[]; + +type ClosedIntegerArray4Array IntegerArray4[3]; + +type IntegerArray5Array IntegerArray5[]; + +type ClosedIntegerArray5Array IntegerArray5[3]; + +type IntegerArray6Array IntegerArray5[]; + +type ClosedIntegerArray6Array IntegerArray5[3]; + +type StringArray1Array StringArray1[]; + +type StringArrayArray StringArray[]; + +type NillableStringArrayArray NillableStringArray[]; + +type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; + +type ClosedStringArray1Array StringArray1[3]; + +type StringArray2Array StringArray2[]; + +type ClosedStringArray2Array StringArray2[3]; + +type StringArray3Array StringArray3[]; + +type ClosedStringArray3Array StringArray3[3]; + +type StringArray4Array StringArray4[]; + +type ClosedStringArray4Array StringArray4[3]; + +type StringArray5Array StringArray5[]; + +type ClosedStringArray5Array StringArray5[3]; + +type StringArray6Array StringArray5[]; + +type ClosedStringArray6Array StringArray5[3]; + +type FloatArray1Array FloatArray1[]; + +type ClosedFloatArray1Array FloatArray1[3]; + +type FloatArray2Array FloatArray2[]; + +type ClosedFloatArray2Array FloatArray2[3]; + +type FloatArray3Array FloatArray3[]; + +type ClosedFloatArray3Array FloatArray3[3]; + +type FloatArray4Array FloatArray4[]; + +type ClosedFloatArray4Array FloatArray4[3]; + +type FloatArray5Array FloatArray5[]; + +type ClosedFloatArray5Array FloatArray5[3]; + +type FloatArray6Array FloatArray5[]; + +type ClosedFloatArray6Array FloatArray5[3]; + +type DecimalArray1Array DecimalArray1[]; + +type ClosedDecimalArray1Array DecimalArray1[3]; + +type DecimalArray2Array DecimalArray2[]; + +type ClosedDecimalArray2Array DecimalArray2[3]; + +type DecimalArray3Array DecimalArray3[]; + +type ClosedDecimalArray3Array DecimalArray3[3]; + +type DecimalArray4Array DecimalArray4[]; + +type ClosedDecimalArray4Array DecimalArray4[3]; + +type DecimalArray5Array DecimalArray5[]; + +type ClosedDecimalArray5Array DecimalArray5[3]; + +type DecimalArray6Array DecimalArray5[]; + +type ClosedDecimalArray6Array DecimalArray5[3]; + +type BooleanArrayArray BooleanArray[]; + +type ClosedBooleanArrayArray BooleanArray[3]; + +type NillableBooleanArrayArray NillableBooleanArray[]; + +type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; + +type BooleanArray2Array BooleanArray2[]; + +type ClosedBooleanArray2Array BooleanArray2[3]; + +type BooleanArray3Array BooleanArray3[]; + +type ClosedBooleanArray3Array BooleanArray3[3]; + +type BooleanArray4Array BooleanArray4[]; + +type ClosedBooleanArray4Array BooleanArray4[3]; + +type BooleanArray5Array BooleanArray5[]; + +type ClosedBooleanArray5Array BooleanArray5[3]; + +type BooleanArray6Array BooleanArray5[]; + +type ClosedBooleanArray6Array BooleanArray5[3]; + +type NilArray1Array NilArray1[]; + +type ClosedNilArray1Array NilArray1[3]; + +type NilArray2Array NilArray2[]; + +type ClosedNilArray2Array NilArray2[3]; + +type NilArray3Array NilArray3[]; + +type ClosedNilArray3Array NilArray3[3]; + +type NilArray4Array NilArray4[]; + +type ClosedNilArray4Array NilArray4[3]; + +type NilArray5Array NilArray5[]; + +type ClosedNilArray5Array NilArray5[3]; + +type NilArray6Array NilArray5[]; + +type ClosedNilArray6Array NilArray5[3]; + +type JsonArray1Array JsonArray1[]; + +type ClosedJsonArray1Array JsonArray1[3]; + +type JsonArray2Array JsonArray2[]; + +type ClosedJsonArray2Array JsonArray2[3]; + +type JsonArray3Array JsonArray3[]; + +type ClosedJsonArray3Array JsonArray3[3]; + +type JsonArray4Array JsonArray4[]; + +type ClosedJsonArray4Array JsonArray4[3]; + +type JsonArray5Array JsonArray5[]; + +type ClosedJsonArray5Array JsonArray5[3]; + +type JsonArray6Array JsonArray5[]; + +type ClosedJsonArray6Array JsonArray5[3]; + +type AnydataArray1Array AnydataArray1[]; + +type ClosedAnydataArray1Array AnydataArray1[3]; + +type AnydataArray2Array AnydataArray2[]; + +type ClosedAnydataArray2Array AnydataArray2[3]; + +type AnydataArray3Array AnydataArray3[]; + +type ClosedAnydataArray3Array AnydataArray3[3]; + +type AnydataArray4Array AnydataArray4[]; + +type ClosedAnydataArray4Array AnydataArray4[3]; + +type AnydataArray5Array AnydataArray5[]; + +type ClosedAnydataArray5Array AnydataArray5[3]; + +type AnydataArray6Array AnydataArray5[]; + +type ClosedAnydataArray6Array AnydataArray5[3]; + +type CustomArray1Array CustomArray1[]; + +type ClosedCustomArray1Array CustomArray1[3]; + +type CustomArray2Array CustomArray2[]; + +type ClosedCustomArray2Array CustomArray2[3]; + +type CustomArray3Array CustomArray3[]; + +type ClosedCustomArray3Array CustomArray3[3]; + +type CustomArray4Array CustomArray4[]; + +type ClosedCustomArray4Array CustomArray4[3]; + +type CustomArray5Array CustomArray5[]; + +type ClosedCustomArray5Array CustomArray5[3]; + +type CustomArray6Array CustomArray5[]; + +type ClosedCustomArray6Array CustomArray5[3]; + +type IntegerMapArray IntegerMap[]; + +type ClosedIntegerMapArray IntegerMap[3]; + +type StringMapArray StringMap[]; + +type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; + +type IntUnionStringMapArray IntUnionStringMap[]; + +type ClosedStringMapArray StringMap[3]; + +type DecimalMapArray DecimalMap[]; + +type ClosedDecimalMapArray DecimalMap[3]; + +type FloatMapArray FloatMap[]; + +type ClosedFloatMapArray FloatMap[3]; + +type BooleanMapArray BooleanMap[]; + +type NillableBooleanMapArray NillableBooleanMap[]; + +type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; + +type IntUnionBooleanMapArray IntUnionBooleanMap[]; + +type ClosedBooleanMapArray BooleanMap[3]; + +type NilMapArray NilMap[]; + +type ClosedNilMapArray NilMap[3]; + +type JsonMapArray JsonMap[]; + +type ClosedJsonMapArray JsonMap[3]; + +type AnydataMapArray AnydataMap[]; + +type ClosedAnydataMapArray AnydataMap[3]; + +type CustomMapArray CustomMap[]; + +type ClosedCustomMapArray CustomMap[3]; diff --git a/ballerina-tests/user-config-tests/.gitignore b/ballerina-tests/user-config-tests/.gitignore new file mode 100644 index 0000000..d5fc29a --- /dev/null +++ b/ballerina-tests/user-config-tests/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/ballerina-tests/user-config-tests/Ballerina.toml b/ballerina-tests/user-config-tests/Ballerina.toml new file mode 100644 index 0000000..05c5773 --- /dev/null +++ b/ballerina-tests/user-config-tests/Ballerina.toml @@ -0,0 +1,13 @@ +[package] +org = "ballerina" +name = "user_config_tests" +version = "0.1.0" + +[[dependency]] +org = "ballerina" +name = "csv_commons" +repository = "local" +version = "0.1.0" + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina-tests/user-config-tests/Dependencies.toml b/ballerina-tests/user-config-tests/Dependencies.toml new file mode 100644 index 0000000..beb3621 --- /dev/null +++ b/ballerina-tests/user-config-tests/Dependencies.toml @@ -0,0 +1,98 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0" + +[[package]] +org = "ballerina" +name = "csv_commons" +version = "0.1.0" +scope = "testOnly" +modules = [ + {org = "ballerina", packageName = "csv_commons", moduleName = "csv_commons"} +] + +[[package]] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + +[[package]] +org = "ballerina" +name = "user_config_tests" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "csv_commons"}, + {org = "ballerina", name = "data.csv"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerina", packageName = "user_config_tests", moduleName = "user_config_tests"} +] + diff --git a/ballerina-tests/user-config-tests/tests/test_data_values.bal b/ballerina-tests/user-config-tests/tests/test_data_values.bal new file mode 100644 index 0000000..360a493 --- /dev/null +++ b/ballerina-tests/user-config-tests/tests/test_data_values.bal @@ -0,0 +1,256 @@ +boolean b1 = true; +false b2 = false; +boolean? b3 = (); +boolean|int b4 = false; + +() n1 = (); +int? n2 = (); +() n3 = null; + +int i1 = 1; +int i2 = -2; +int i3 = int:MAX_VALUE; +int i4 = int:MIN_VALUE; +int i5 = 0; +2 i6 = 2; +int? i7 = (); +int|string i8 = 100; + +float f1 = 2.234; +float f2 = -3.21f; +float f3 = 0; +float f4 = float:Infinity; +float f5 = -float:Infinity; +float f6 = float:NaN; +2.3f f7 = 2.3; +float? f8 = (); +float|decimal f9 = 1.21; + +decimal d1 = 2.234; +decimal d2 = -3.21d; +decimal d3 = 0; +2.3d d4 = 2.3; +decimal? d5 = (); +decimal|int d6 = 1.21; + +string s1 = "string"; +string s2 = ""; +string:Char s3 = "a"; + +map bm1 = {b1, b2}; +map bm2 = {b1, b2, b3, n1, n3}; +map bm3 = {b1, b2, b3, b4, i1}; +map<()> bm4 = {n1, n3}; +map bm5 = {b1, b2, b3, b4:true}; + +map m5 = {i1, i2, i3, i4, i5, i6}; +map m6 = {f1, f2, f3, f4, f5, f6, f7}; +map m7 = {d1, d2, d3, d4}; +map m8 = {d1, f1, f9, f10: 1.23}; +map m9 = {s1, s2, s3}; +map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; +map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; + +boolean[] arr1 = [b1, b2]; +boolean?[] arr2 = [b1, b2, b3, n1, n3]; +(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; +()[] arr4 = [n1, n3]; +int[] arr5 = [i1, i2, i3, i4, i5, i6]; +float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; +decimal[] arr7 = [d1, d2, d3, d4]; +(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; +string[] arr9 = [s1, s2, s3]; +anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; + +[boolean, boolean] bt1 = [b1, b2]; +[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; +[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; +[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; +[boolean...] bt5 = [b1, b2]; + +[string, string] st1 = [s1, s2]; +[string, string, string, string] st2 = [s1, s2, s3, s2]; +[string...] st3 = [s1, s2]; +[string, string, string...] st4 = [s1, s2, s3, s2]; + +[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; +[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; +[string?...] st7 = [s1, s2]; +[string...] st8 = []; +[string, string, string] st9 = [s1, s2, s3]; + +[(), ()] tup4 = [n1, n3]; +[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; +[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; +[string, string, string] tup9 = [s1, s2, s3]; +[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, + anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, + n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json, json, json, json, json, json, json, json, json, json, + json, json, json, json, json, json, json, json, json, json, json] tup11 = + [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, + f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 +]; + +[boolean, boolean...] restTup1 = [b1, b2]; +[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; +[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; +[(), ()...] restTup4 = [n1, n3]; +[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; +[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; +[decimal...] restTup7 = [d1, d2, d3, d4]; +[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; +[string...] restTup9 = [s1, s2, s3]; +[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; +[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ + s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 +]; + +var booleanRecordArray = [ + {b1, b2, b3, b4}, {b1, b2, b3, b4} +]; + +var booleanRecordArray2 = [ + {},{} +]; + +string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 +true,false,true,false +true,false, true,false +true,false,true,false +`; + +string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 +true,false, true,false,true +true,false, true,false,true`; + +string csvStringWithBooleanValues3 = string `b1,b2,b3 +${" "}${"\t"} +true, false,true +${" "} + TRUE, FALSE,() +${" "} + +true, true,FALSE + +`; + +string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 + true,(), (),false + true,(), null,false + +`; + +string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 + +true,false,true,2 + +true,false,true,3 +`; + +string csvStringWithBooleanValues6 = string `b2,b3 +(),() + +`; + +string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 +${b1},${b2},(),${b4} +`; + +string csvStringData1 = string ` + a, b, c, d, e, f + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData2 = string ` + hello, hello, (), 12, true, 12.34 + // comment + + a, b, c, d, e, f + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData3 = string ` + a, b, c, d, e, f + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData4 = string ` + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + 5, string5, true, 3, 3, ()`; + +string csvStringData5 = string ` + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData6 = string ` + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.51, () + + 5, string5, true, 3, 3, ()`; + +string csvStringData7 = string ` + a@ b@ c@ d@ e@ f + 1@ string@ true@ 2.234@ -3.21@ () + 2@ s,tring@ true@ 2.234@ -3.21@ null + 3@ stri,ng@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; +string csvStringData8 = string ` + a@ b@ c@ d@ e@ f + + + + 1@ stri,ng@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ ()@-3.21 + 3@ string@ true@ 2.234@ -3.21@ null + + 4@ s,tring@ true@ 2.234@ -3.21@ () + 5@ string@ true@ 2.234@ -3.21@ ()`; + +string csvStringData9 = string ` + + 1@ string@ true@ 2.234@ -3.21@ () + 2@ string@ true@ 2.234@ -3.21@ null + + 3@ string@ true@ 2.234@ -3.21@ () + 4@ string@ true@ 2.234@ ()@-3.21 + + 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina-tests/user-config-tests/tests/types.bal b/ballerina-tests/user-config-tests/tests/types.bal new file mode 100644 index 0000000..7587492 --- /dev/null +++ b/ballerina-tests/user-config-tests/tests/types.bal @@ -0,0 +1,73 @@ +import ballerina/data.csv as csv; + +type RecordWithCustomAnnotation record { + @csv:Name { + value: "c" + } + int a; + int b; +}; + +type RecordWithCustomAnnotation2 record { + @csv:Name { + value: "c" + } + int a?; + @csv:Name { + value: "d" + } + int? b; +}; + +type RecordWithCustomAnnotation3 record {| + @csv:Name { + value: "c" + } + int a?; + @csv:Name { + value: "d" + } + int? b; +|}; + +type RecordWithCustomAnnotation4 record {| + @csv:Name { + value: "c" + } + int a; + @csv:Name { + value: "d" + } + int b; + boolean...; +|}; + +type RecordWithCustomAnnotation5 record { + @csv:Name { + value: "c" + } + int a; + @csv:Name { + value: "d" + } + int b; + @csv:Name { + value: "e" + } + int c; +}; + +type RecordWithCustomAnnotation6 record { + @csv:Name { + value: "c" + } + int a; + @csv:Name { + value: "d" + } + int b; + @csv:Name { + value: "a" + } + int c; +}; diff --git a/ballerina/tests/user_config_projection_tests.bal b/ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal similarity index 53% rename from ballerina/tests/user_config_projection_tests.bal rename to ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal index d4e5c9e..331ca64 100644 --- a/ballerina/tests/user_config_projection_tests.bal +++ b/ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal @@ -1,307 +1,281 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; import ballerina/test; @test:Config function testCustomNameAnnotation() returns error? { - RecordWithCustomAnnotation[]|Error cn1 = parseStringToRecord(string `b,c + RecordWithCustomAnnotation[]|csv:Error cn1 = csv:parseStringToRecord(string `b,c 1,3`, {}); test:assertEquals(cn1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|Error cn2 = parseStringToRecord(string `c,b + RecordWithCustomAnnotation[]|csv:Error cn2 = csv:parseStringToRecord(string `c,b 3,1`, {}); test:assertEquals(cn2, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|Error cn3 = parseStringToRecord(string `f,c,b,e + RecordWithCustomAnnotation[]|csv:Error cn3 = csv:parseStringToRecord(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[]|Error cn4 = parseStringToRecord(string `d,c + RecordWithCustomAnnotation2[]|csv:Error cn4 = csv:parseStringToRecord(string `d,c 1,3`, {}); test:assertEquals(cn4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|Error cn5 = parseStringToRecord(string `c,d + RecordWithCustomAnnotation2[]|csv:Error cn5 = csv:parseStringToRecord(string `c,d 3,1`, {}); test:assertEquals(cn5, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|Error cn6 = parseStringToRecord(string `c,f,d,e + RecordWithCustomAnnotation2[]|csv:Error cn6 = csv:parseStringToRecord(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[]|Error cn7 = parseStringToRecord(string `a,b + RecordWithCustomAnnotation2[]|csv:Error cn7 = csv:parseStringToRecord(string `a,b 3,1`, {}); - test:assertTrue(cn7 is Error); + test:assertTrue(cn7 is csv:Error); test:assertEquals((cn7).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation2[]|Error cn8 = parseStringToRecord(string ` c,d,a,b + RecordWithCustomAnnotation2[]|csv:Error cn8 = csv:parseStringToRecord(string ` c,d,a,b 3,1,4,5`, {}); - test:assertTrue(cn8 is Error); + test:assertTrue(cn8 is csv:Error); test:assertEquals((cn8).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation3[]|Error cn9 = parseStringToRecord(string `d,c + RecordWithCustomAnnotation3[]|csv:Error cn9 = csv:parseStringToRecord(string `d,c 1,3`, {}); test:assertEquals(cn9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|Error cn10 = parseStringToRecord(string `c,d + RecordWithCustomAnnotation3[]|csv:Error cn10 = csv:parseStringToRecord(string `c,d 3,1`, {}); test:assertEquals(cn10, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|Error cn11 = parseStringToRecord(string `c,f,d,e + RecordWithCustomAnnotation3[]|csv:Error cn11 = csv:parseStringToRecord(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[]|Error cn12 = parseStringToRecord(string `a,b + RecordWithCustomAnnotation3[]|csv:Error cn12 = csv:parseStringToRecord(string `a,b 3,1`, {}); - test:assertTrue(cn12 is Error); + test:assertTrue(cn12 is csv:Error); test:assertEquals((cn12).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation3[]|Error cn13 = parseStringToRecord(string ` c,d,a,b + RecordWithCustomAnnotation3[]|csv:Error cn13 = csv:parseStringToRecord(string ` c,d,a,b 3,1,4,5`, {}); - test:assertTrue(cn13 is Error); + test:assertTrue(cn13 is csv:Error); test:assertEquals((cn13).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|Error cn14 = parseStringToRecord(string `d,c,z + RecordWithCustomAnnotation4[]|csv:Error cn14 = csv:parseStringToRecord(string `d,c,z 1,3,true`, {}); test:assertEquals(cn14, [{b: 1, a: 3, z: true}]); - RecordWithCustomAnnotation4[]|Error cn15 = parseStringToRecord(string `c,d + RecordWithCustomAnnotation4[]|csv:Error cn15 = csv:parseStringToRecord(string `c,d 3,1`, {}); test:assertEquals(cn15, [{b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|Error cn16 = parseStringToRecord(string `c,f,d,e + RecordWithCustomAnnotation4[]|csv:Error cn16 = csv:parseStringToRecord(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[]|Error cn17 = parseStringToRecord(string `a,b + RecordWithCustomAnnotation4[]|csv:Error cn17 = csv:parseStringToRecord(string `a,b 3,1`, {}); - test:assertTrue(cn17 is Error); + test:assertTrue(cn17 is csv:Error); test:assertEquals((cn17).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|Error cn18 = parseStringToRecord(string ` c,d,a,b + RecordWithCustomAnnotation4[]|csv:Error cn18 = csv:parseStringToRecord(string ` c,d,a,b 3,1,4,5`, {}); - test:assertTrue(cn18 is Error); + test:assertTrue(cn18 is csv:Error); test:assertEquals((cn18).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation5[]|Error cn19 = parseStringToRecord(string ` c,d,a,b + RecordWithCustomAnnotation5[]|csv:Error cn19 = csv:parseStringToRecord(string ` c,d,a,b 3,1,4,5`, {}); - test:assertTrue(cn19 is Error); - test:assertEquals((cn19).message(), "Duplicate field found in record fields: 'c'"); + test:assertTrue(cn19 is csv:Error); + test:assertEquals((cn19).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation6[]|Error cn20 = parseStringToRecord(string ` c,d,e + RecordWithCustomAnnotation5[]|csv:Error cn20 = csv:parseStringToRecord(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}]); - RecordWithCustomAnnotation7[]|Error cn21 = parseStringToRecord(string ` c,d,a + RecordWithCustomAnnotation6[]|csv:Error cn21 = csv:parseStringToRecord(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}]); - RecordWithCustomAnnotation8[]|Error cn22 = parseStringToRecord(string ` c,d,a - 3,1,4 - 3,1,4`, {}); - test:assertTrue(cn22 is Error); - test:assertEquals((cn22).message(), "Duplicate field found in record fields: 'c'"); - - RecordWithCustomAnnotation[]|Error cnrr1 = parseRecordAsRecordType([{"b": 1, "c": 3}], {}); + RecordWithCustomAnnotation[]|csv:Error cnrr1 = csv:parseRecordAsRecordType([{"b": 1, "c": 3}], {}); test:assertEquals(cnrr1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|Error cnrr2 = parseRecordAsRecordType([{"c": 3, "b": 1}], {}); + RecordWithCustomAnnotation[]|csv:Error cnrr2 = csv:parseRecordAsRecordType([{"c": 3, "b": 1}], {}); test:assertEquals(cnrr2, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|Error cnrr3 = parseRecordAsRecordType( + RecordWithCustomAnnotation[]|csv:Error cnrr3 = csv:parseRecordAsRecordType( [{"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[]|Error cnrr4 = parseRecordAsRecordType([{"d": 1, "c": 3}], {}); + RecordWithCustomAnnotation2[]|csv:Error cnrr4 = csv:parseRecordAsRecordType([{"d": 1, "c": 3}], {}); test:assertEquals(cnrr4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|Error cnrr5 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + RecordWithCustomAnnotation2[]|csv:Error cnrr5 = csv:parseRecordAsRecordType([{"c": 3, "d": 1}], {}); test:assertEquals(cnrr5, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|Error cnrr6 = parseRecordAsRecordType( + RecordWithCustomAnnotation2[]|csv:Error cnrr6 = csv:parseRecordAsRecordType( [{"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[]|Error cnrr7 = parseRecordAsRecordType([{"a":3, "b": 1}], {}); - test:assertTrue(cnrr7 is Error); + RecordWithCustomAnnotation2[]|csv:Error cnrr7 = csv:parseRecordAsRecordType([{"a":3, "b": 1}], {}); + test:assertTrue(cnrr7 is csv:Error); test:assertEquals((cnrr7).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation2[]|Error cnrr8 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); - test:assertTrue(cnrr8 is Error); + RecordWithCustomAnnotation2[]|csv:Error cnrr8 = csv:parseRecordAsRecordType([{"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[]|Error cnrr9 = parseRecordAsRecordType([{"d": 1, "c": 3}], {}); + RecordWithCustomAnnotation3[]|csv:Error cnrr9 = csv:parseRecordAsRecordType([{"d": 1, "c": 3}], {}); test:assertEquals(cnrr9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|Error cnrr10 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + RecordWithCustomAnnotation3[]|csv:Error cnrr10 = csv:parseRecordAsRecordType([{"c": 3, "d": 1}], {}); test:assertEquals(cnrr10, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|Error cnrr11 = parseRecordAsRecordType( + RecordWithCustomAnnotation3[]|csv:Error cnrr11 = csv:parseRecordAsRecordType( [{"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[]|Error cnrr12 = parseRecordAsRecordType([{"a": 3, "b": 1}], {}); - test:assertTrue(cnrr12 is Error); + RecordWithCustomAnnotation3[]|csv:Error cnrr12 = csv:parseRecordAsRecordType([{"a": 3, "b": 1}], {}); + test:assertTrue(cnrr12 is csv:Error); test:assertEquals((cnrr12).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation3[]|Error cnrr13 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); - test:assertTrue(cnrr13 is Error); + RecordWithCustomAnnotation3[]|csv:Error cnrr13 = csv:parseRecordAsRecordType([{"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[]|Error cnrr14 = parseRecordAsRecordType([{"d": 1, "c": 3, "z": true}], {}); + RecordWithCustomAnnotation4[]|csv:Error cnrr14 = csv:parseRecordAsRecordType([{"d": 1, "c": 3, "z": true}], {}); test:assertEquals(cnrr14, [{b: 1, a: 3, z: true}]); - RecordWithCustomAnnotation4[]|Error cnrr15 = parseRecordAsRecordType([{"c": 3, "d": 1}], {}); + RecordWithCustomAnnotation4[]|csv:Error cnrr15 = csv:parseRecordAsRecordType([{"c": 3, "d": 1}], {}); test:assertEquals(cnrr15, [{b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|Error cnrr16 = parseRecordAsRecordType( + RecordWithCustomAnnotation4[]|csv:Error cnrr16 = csv:parseRecordAsRecordType( [{"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}]); - RecordWithCustomAnnotation4[]|Error cnrr17 = parseRecordAsRecordType([{"a": 3, "b": 1}], {}); - test:assertTrue(cnrr17 is Error); - test:assertEquals((cnrr17).message(), "Duplicate field found in record fields: 'a'"); - - RecordWithCustomAnnotation4[]|Error cnrr18 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); - test:assertTrue(cnrr18 is Error); - test:assertEquals((cnrr18).message(), "Duplicate field found in record fields: 'a'"); - - RecordWithCustomAnnotation5[]|Error cnrr19 = parseRecordAsRecordType([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); - test:assertTrue(cnrr19 is Error); - test:assertEquals((cnrr19).message(), "Duplicate field found in record fields: 'c'"); - - RecordWithCustomAnnotation6[]|Error cnrr20 = parseRecordAsRecordType( + RecordWithCustomAnnotation5[]|csv:Error cnrr20 = csv:parseRecordAsRecordType( [{"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}]); - RecordWithCustomAnnotation7[]|Error cnrr21 = parseRecordAsRecordType( + RecordWithCustomAnnotation6[]|csv:Error cnrr21 = csv:parseRecordAsRecordType( [{"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}]); - - RecordWithCustomAnnotation8[]|Error cnrr22 = parseRecordAsRecordType( - [{"c": 3, "d": 1, "a": 4}, {"c": 3, "d": 1, "a": 4}], {}); - test:assertTrue(cnrr22 is Error); - test:assertEquals((cnrr22).message(), "Duplicate field found in record fields: 'c'"); } @test:Config function testCustomNameAnnotation2() returns error? { - RecordWithCustomAnnotation[]|Error cntr1 = parseListAsRecordType([["1", "3"]], ["b", "c"], {}); + RecordWithCustomAnnotation[]|csv:Error cntr1 = csv:parseListAsRecordType([["1", "3"]], ["b", "c"], {}); test:assertEquals(cntr1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|Error cntr2 = parseListAsRecordType([["3", "1"]], ["c", "b"], {}); + RecordWithCustomAnnotation[]|csv:Error cntr2 = csv:parseListAsRecordType([["3", "1"]], ["c", "b"], {}); test:assertEquals(cntr2, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|Error cntr3 = parseListAsRecordType( + RecordWithCustomAnnotation[]|csv:Error cntr3 = csv:parseListAsRecordType( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["f", "c", "b", "e"], {}); test:assertEquals(cntr3, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); - RecordWithCustomAnnotation2[]|Error cntr4 = parseListAsRecordType([["1", "3"]], ["d", "c"], {}); + RecordWithCustomAnnotation2[]|csv:Error cntr4 = csv:parseListAsRecordType([["1", "3"]], ["d", "c"], {}); test:assertEquals(cntr4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|Error cntr5 = parseListAsRecordType([["3","1"]], ["c", "d"], {}); + RecordWithCustomAnnotation2[]|csv:Error cntr5 = csv:parseListAsRecordType([["3","1"]], ["c", "d"], {}); test:assertEquals(cntr5, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|Error cntr6 = parseListAsRecordType( + RecordWithCustomAnnotation2[]|csv:Error cntr6 = csv:parseListAsRecordType( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); test:assertEquals(cntr6, [{b: 1, a: 3, f: 3, e: "cde"}, {b: 1, a: 3, f: 3, e: "cde"}]); - RecordWithCustomAnnotation2[]|Error cntr7 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); - test:assertTrue(cntr7 is Error); + RecordWithCustomAnnotation2[]|csv:Error cntr7 = csv:parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + test:assertTrue(cntr7 is csv:Error); test:assertEquals((cntr7).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation2[]|Error cntr8 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); - test:assertTrue(cntr8 is Error); + RecordWithCustomAnnotation2[]|csv:Error cntr8 = csv:parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr8 is csv:Error); test:assertEquals((cntr8).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation3[]|Error cntr9 = parseListAsRecordType([["1", "3"]], ["d", "c"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr9 = csv:parseListAsRecordType([["1", "3"]], ["d", "c"], {}); test:assertEquals(cntr9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|Error cntr10 = parseListAsRecordType([["3", "1"]], ["c", "d"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr10 = csv:parseListAsRecordType([["3", "1"]], ["c", "d"], {}); test:assertEquals(cntr10, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|Error cntr11 = parseListAsRecordType( + RecordWithCustomAnnotation3[]|csv:Error cntr11 = csv:parseListAsRecordType( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); test:assertEquals(cntr11, [{b: 1, a: 3}, {b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|Error cntr12 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); - test:assertTrue(cntr12 is Error); - test:assertEquals((cntr12).message(), generateErrorMessageForInvalidHeaders(string `["3","1"]`, "data.csv:RecordWithCustomAnnotation3")); + RecordWithCustomAnnotation3[]|csv:Error cntr12 = csv:parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + test:assertTrue(cntr12 is csv:Error); + test:assertEquals((cntr12).message(), common:generateErrorMessageForInvalidHeaders(string `["3","1"]`, "user_config_tests:RecordWithCustomAnnotation3")); - RecordWithCustomAnnotation3[]|Error cntr13 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); - test:assertTrue(cntr13 is Error); + RecordWithCustomAnnotation3[]|csv:Error cntr13 = csv:parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr13 is csv:Error); test:assertEquals((cntr13).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|Error cntr14 = parseListAsRecordType([["1", "3", "true"]], ["d", "c", "z"], {}); + RecordWithCustomAnnotation4[]|csv:Error cntr14 = csv:parseListAsRecordType([["1", "3", "true"]], ["d", "c", "z"], {}); test:assertEquals(cntr14, [{b: 1, a: 3, z: true}]); - RecordWithCustomAnnotation4[]|Error cntr15 = parseListAsRecordType([["3", "1"]], ["c", "d"], {}); + RecordWithCustomAnnotation4[]|csv:Error cntr15 = csv:parseListAsRecordType([["3", "1"]], ["c", "d"], {}); test:assertEquals(cntr15, [{b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|Error cntr16 = parseListAsRecordType( + RecordWithCustomAnnotation4[]|csv:Error cntr16 = csv:parseListAsRecordType( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); test:assertEquals(cntr16, [{b: 1, a: 3}, {b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|Error cntr17 = parseListAsRecordType([["3", "1"]], ["a", "b"], {}); - test:assertTrue(cntr17 is Error); + RecordWithCustomAnnotation4[]|csv:Error cntr17 = csv:parseListAsRecordType([["3", "1"]], ["a", "b"], {}); + test:assertTrue(cntr17 is csv:Error); test:assertEquals((cntr17).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation4[]|Error cntr18 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); - test:assertTrue(cntr18 is Error); + RecordWithCustomAnnotation4[]|csv:Error cntr18 = csv:parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr18 is csv:Error); test:assertEquals((cntr18).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation5[]|Error cntr19 = parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); - test:assertTrue(cntr19 is Error); - test:assertEquals((cntr19).message(), "Duplicate field found in record fields: 'c'"); + RecordWithCustomAnnotation5[]|csv:Error cntr19 = csv:parseListAsRecordType([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + test:assertTrue(cntr19 is csv:Error); + test:assertEquals((cntr19).message(), "Duplicate field found in record fields: 'a'"); - RecordWithCustomAnnotation6[]|Error cntr20 = parseListAsRecordType( + RecordWithCustomAnnotation5[]|csv:Error cntr20 = csv:parseListAsRecordType( [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "e"], {}); test:assertEquals(cntr20, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); - RecordWithCustomAnnotation7[]|Error cntr21 = parseListAsRecordType( + RecordWithCustomAnnotation6[]|csv:Error cntr21 = csv:parseListAsRecordType( [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "a"], {}); test:assertEquals(cntr21, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); - - RecordWithCustomAnnotation8[]|Error cntr22 = parseListAsRecordType( - [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "a"], {}); - test:assertTrue(cntr22 is Error); - test:assertEquals((cntr22).message(), "Duplicate field found in record fields: 'c'"); } @test:Config function testAbsentAsNilableConfig() returns error? { - record {|int a; int? g; int? h;|}[]|Error cn = parseStringToRecord(csvStringData1, { + record {|int a; int? g; int? h;|}[]|csv:Error cn = csv:parseStringToRecord(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?;|}[]|Error cn2 = parseStringToRecord(csvStringData1, { + record {|int a; int? g?;|}[]|csv:Error cn2 = csv:parseStringToRecord(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn2, [{a: 1}]); - record {|int a; int g?;|}[]|Error cn3 = parseStringToRecord(csvStringData1, { + record {|int a; int g?;|}[]|csv:Error cn3 = csv:parseStringToRecord(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn3, [{a: 1}]); - record {|int a; int g;|}[]|Error cn4 = parseStringToRecord(csvStringData1, { + record {|int a; int g;|}[]|csv:Error cn4 = csv:parseStringToRecord(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" }); - test:assertTrue(cn4 is Error); - test:assertEquals((cn4).message(), generateErrorMessageForMissingRequiredField("g")); + test:assertTrue(cn4 is csv:Error); + test:assertEquals((cn4).message(), common:generateErrorMessageForMissingRequiredField("g")); - int?[][]|Error cn5 = parseStringToList(string ` + int?[][]|csv:Error cn5 = csv:parseStringToList(string ` a,b,c 1, 1,1`, { allowDataProjection: {absentAsNilableType: true}, @@ -309,7 +283,7 @@ function testAbsentAsNilableConfig() returns error? { }); test:assertEquals(cn5, [[1, 1, 1]]); - map[]|Error cn6 = parseStringToRecord(string ` + map[]|csv:Error cn6 = csv:parseStringToRecord(string ` a,b,c 1, 1,1`, { allowDataProjection: {absentAsNilableType: true}, @@ -317,28 +291,28 @@ function testAbsentAsNilableConfig() returns error? { }); test:assertEquals(cn6, [{a: 1, b: 1, c: 1}]); - [int, string?, boolean?, decimal?, float?, (), string?][]|Error cn7 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn7 = csv:parseStringToList(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?][]|Error cn8 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn8 = csv:parseStringToList(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?][]|Error cn9 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn9 = csv:parseStringToList(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?][]|Error cn10 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn10 = csv:parseStringToList(csvStringData1, { allowDataProjection: {absentAsNilableType: true}, header: 1, skipLines: "2-10" @@ -348,80 +322,80 @@ function testAbsentAsNilableConfig() returns error? { @test:Config function testAbsentAsNilableConfig2() returns error? { - record {|int a; int? g; int? h;|}[]|Error cn = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int? g; int? h;|}[]|csv:Error cn = csv:parseRecordAsRecordType([{"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?;|}[]|Error cn2 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int? g?;|}[]|csv:Error cn2 = csv:parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn2, [{a: 1}, {a: 2}]); - record {|int a; int g?;|}[]|Error cn3 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int g?;|}[]|csv:Error cn3 = csv:parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn3, [{a: 1}, {a: 2}]); - record {|int a; int g;|}[]|Error cn4 = parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { + record {|int a; int g;|}[]|csv:Error cn4 = csv:parseRecordAsRecordType([{"a": 1}, {"a": 2}, {"a": 3}], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); - test:assertTrue(cn4 is Error); - test:assertEquals((cn4).message(), generateErrorMessageForMissingRequiredField("g")); + test:assertTrue(cn4 is csv:Error); + test:assertEquals((cn4).message(), common:generateErrorMessageForMissingRequiredField("g")); - record {|string a; int? g; int? h;|}[]|Error cn5 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int? g; int? h;|}[]|csv:Error cn5 = csv:parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn5, [{a: "a", g: (), h: ()}, {a: "a", g: (), h: ()}]); - record {|string a; int? g?;|}[]|Error cn6 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int? g?;|}[]|csv:Error cn6 = csv:parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertEquals(cn6, [{a: "a"}, {a: "a"}]); - record {|string a; int g?;|}[]|Error cn7 = parseListAsRecordType([["a"], ["a"], ["b"]], ["a"], { + record {|string a; int g?;|}[]|csv:Error cn7 = csv:parseListAsRecordType([["a"], ["a"], ["b"]], ["a"], { allowDataProjection: {absentAsNilableType: true}, skipLines: [2] }); test:assertEquals(cn7, [{a: "a"}, {a: "b"}]); - record {|string a; int g;|}[]|Error cn8 = parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int g;|}[]|csv:Error cn8 = csv:parseListAsRecordType([["a"], ["a"], ["a"]], ["a"], { allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); - test:assertTrue(cn8 is Error); - test:assertEquals((cn8).message(), generateErrorMessageForMissingRequiredField("g")); + test:assertTrue(cn8 is csv:Error); + test:assertEquals((cn8).message(), common:generateErrorMessageForMissingRequiredField("g")); } @test:Config function testNilAsOptionalConfig() returns error? { - record {|int a; int f?;|}[]|Error cn = parseStringToRecord(csvStringData1, { + record {|int a; int f?;|}[]|csv:Error cn = csv:parseStringToRecord(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1 }); test:assertEquals(cn, [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]); - record {|int a; int? f?;|}[]|Error cn2 = parseStringToRecord(csvStringData1, { + record {|int a; int? f?;|}[]|csv:Error cn2 = csv:parseStringToRecord(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn2, [{a: 1, f: ()}]); - record {|int a; int f?;|}[]|Error cn3 = parseStringToRecord(csvStringData1, { + record {|int a; int f?;|}[]|csv:Error cn3 = csv:parseStringToRecord(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); test:assertEquals(cn3, [{a: 1}]); - record {|int a; int f;|}[]|Error cn4 = parseStringToRecord(csvStringData1, { + record {|int a; int f;|}[]|csv:Error cn4 = csv:parseStringToRecord(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" }); - test:assertTrue(cn4 is Error); - test:assertEquals((cn4).message(), generateErrorMessageForInvalidCast("()", "int")); + test:assertTrue(cn4 is csv:Error); + test:assertEquals((cn4).message(), common:generateErrorMessageForInvalidCast("()", "int")); - int?[][]|Error cn5 = parseStringToList(string ` + int?[][]|csv:Error cn5 = csv:parseStringToList(string ` a,b,c 1, 1,1`, { allowDataProjection: {nilAsOptionalField: true}, @@ -429,7 +403,7 @@ function testNilAsOptionalConfig() returns error? { }); test:assertEquals(cn5, [[1, 1, 1]]); - map[]|Error cn6 = parseStringToRecord(string ` + map[]|csv:Error cn6 = csv:parseStringToRecord(string ` a,b,c 1, 1,1`, { allowDataProjection: {nilAsOptionalField: true}, @@ -437,28 +411,28 @@ function testNilAsOptionalConfig() returns error? { }); test:assertEquals(cn6, [{a: 1, b: 1, c: 1}]); - [int, string?, boolean?, decimal?, float?, (), string?][]|Error cn7 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn7 = csv:parseStringToList(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?][]|Error cn8 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn8 = csv:parseStringToList(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?][]|Error cn9 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn9 = csv:parseStringToList(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?][]|Error cn10 = parseStringToList(csvStringData1, { + [int, string?, boolean?, decimal?, float?, (), string?][]|csv:Error cn10 = csv:parseStringToList(csvStringData1, { allowDataProjection: {nilAsOptionalField: true}, header: 1, skipLines: "2-10" @@ -468,26 +442,26 @@ function testNilAsOptionalConfig() returns error? { @test:Config function testNilAsOptionalConfig2() returns error? { - record {|int a; int? f;|}[]|Error cn = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int? f;|}[]|csv:Error cn = csv:parseRecordAsRecordType([{"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?;|}[]|Error cn2 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int? f?;|}[]|csv:Error cn2 = csv:parseRecordAsRecordType([{"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?;|}[]|Error cn3 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int f?;|}[]|csv:Error cn3 = csv:parseRecordAsRecordType([{"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;|}[]|Error cn4 = parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { + record {|int a; int f;|}[]|csv:Error cn4 = csv:parseRecordAsRecordType([{"a": 1, "f": ()}, {"a": 2, "f": ()}, {"a": 3, "f": ()}], { allowDataProjection: {nilAsOptionalField: true}, skipLines: [3] }); - test:assertTrue(cn4 is Error); - test:assertEquals((cn4).message(), generateErrorMessageForInvalidFieldType("null", "f")); + test:assertTrue(cn4 is csv:Error); + test:assertEquals((cn4).message(), common:generateErrorMessageForInvalidFieldType("null", "f")); } @test:Config @@ -497,189 +471,189 @@ function testDataProjectionConfig() returns error? { b,4`; record{}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; - record{}[]|Error cn = parseStringToRecord(csvValue1, { + record{}[]|csv:Error cn = csv:parseStringToRecord(csvValue1, { allowDataProjection: false }); test:assertEquals(cn, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a; int b;|}[]|Error cn_2 = parseStringToRecord(csvValue1, { + record{|string a; int b;|}[]|csv:Error cn_2 = csv:parseStringToRecord(csvValue1, { allowDataProjection: false }); test:assertEquals(cn_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a;|}[]|Error cn2 = parseStringToRecord(csvValue1, { + record{|string a;|}[]|csv:Error cn2 = csv:parseStringToRecord(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn2 is Error); + test:assertTrue(cn2 is csv:Error); test:assertEquals((cn2).message(), "No mapping field in the expected type for header 'b'"); - record{|string a; int...;|}[]|Error cn3 = parseStringToRecord(csvValue1, { + record{|string a; int...;|}[]|csv:Error cn3 = csv:parseStringToRecord(csvValue1, { allowDataProjection: false }); test:assertEquals(cn3, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string...;|}[]|Error cn4 = parseStringToRecord(csvValue1, { + record{|string...;|}[]|csv:Error cn4 = csv:parseStringToRecord(csvValue1, { allowDataProjection: false }); test:assertEquals(cn4, [{"a": "a", "b": "2"}, {"a": "b", "b": "4"}]); - record{|string a?;|}[]|Error cn5 = parseStringToRecord(csvValue1, { + record{|string a?;|}[]|csv:Error cn5 = csv:parseStringToRecord(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn5 is Error); + test:assertTrue(cn5 is csv:Error); test:assertEquals((cn5).message(), "No mapping field in the expected type for header 'b'"); - record{|string? a;|}[]|Error cn6 = parseStringToRecord(csvValue1, { + record{|string? a;|}[]|csv:Error cn6 = csv:parseStringToRecord(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn6 is Error); + test:assertTrue(cn6 is csv:Error); test:assertEquals((cn6).message(), "No mapping field in the expected type for header 'b'"); - anydata[][]|Error c7 = parseStringToList(csvValue1, { + anydata[][]|csv:Error c7 = csv:parseStringToList(csvValue1, { allowDataProjection: false }); test:assertEquals(c7, [["a", 2], ["b", 4]]); - [string, int][]|Error cn7_2 = parseStringToList(csvValue1, { + [string, int][]|csv:Error cn7_2 = csv:parseStringToList(csvValue1, { allowDataProjection: false }); test:assertEquals(cn7_2, [["a", 2], ["b", 4]]); - [string][]|Error cn8 = parseStringToList(csvValue1, { + [string][]|csv:Error cn8 = csv:parseStringToList(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn8 is Error); + test:assertTrue(cn8 is csv:Error); test:assertEquals((cn8).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); - [string][]|Error cn8_2 = parseStringToList(csvValue1, { + [string][]|csv:Error cn8_2 = csv:parseStringToList(csvValue1, { allowDataProjection: {} }); test:assertEquals(cn8_2, [["a"], ["b"]]); - [int][]|Error cn8_3 = parseStringToList(csvValue1, { + [int][]|csv:Error cn8_3 = csv:parseStringToList(csvValue1, { allowDataProjection: {} }); - test:assertTrue(cn8_3 is Error); - test:assertEquals((cn8_3).message(), generateErrorMessageForInvalidCast("a", "int")); + test:assertTrue(cn8_3 is csv:Error); + test:assertEquals((cn8_3).message(), common:generateErrorMessageForInvalidCast("a", "int")); - [string, int...][]|Error cn9 = parseStringToList(csvValue1, { + [string, int...][]|csv:Error cn9 = csv:parseStringToList(csvValue1, { allowDataProjection: false }); test:assertEquals(cn9, [["a", 2], ["b", 4]]); - [string...][]|Error cn10 = parseStringToList(csvValue1, { + [string...][]|csv:Error cn10 = csv:parseStringToList(csvValue1, { allowDataProjection: false }); test:assertEquals(cn10, [["a", "2"], ["b", "4"]]); - [string, ()][]|Error cn11 = parseStringToList(csvValue1, { + [string, ()][]|csv:Error cn11 = csv:parseStringToList(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn11 is Error); - test:assertEquals((cn11).message(), generateErrorMessageForInvalidCast("2", "()")); + test:assertTrue(cn11 is csv:Error); + test:assertEquals((cn11).message(), common:generateErrorMessageForInvalidCast("2", "()")); - string[][]|Error cn12 = parseStringToList(csvValue1, { + string[][]|csv:Error cn12 = csv:parseStringToList(csvValue1, { allowDataProjection: false }); test:assertEquals(cn12, [["a", "2"], ["b", "4"]]); - string[][1]|Error cn13 = parseStringToList(csvValue1, { + string[][1]|csv:Error cn13 = csv:parseStringToList(csvValue1, { allowDataProjection: false }); - test:assertTrue(cn13 is Error); + test:assertTrue(cn13 is csv:Error); test:assertEquals((cn13).message(), "invalid array size for expected array type, cannot be greater than '1'"); - record{}[]|Error cn14 = parseRecordAsRecordType(csvValue2, { + record{}[]|csv:Error cn14 = csv:parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); test:assertEquals(cn14, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a; int b;|}[]|Error cn14_2 = parseRecordAsRecordType(csvValue2, { + record{|string a; int b;|}[]|csv:Error cn14_2 = csv:parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); test:assertEquals(cn14_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a;|}[]|Error cn15 = parseRecordAsRecordType(csvValue2, { + record{|string a;|}[]|csv:Error cn15 = csv:parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); - test:assertTrue(cn15 is Error); + test:assertTrue(cn15 is csv:Error); test:assertEquals((cn15).message(), "No mapping field in the expected type for header 'b'"); - record{|string a; int...;|}[]|Error cn16 = parseRecordAsRecordType(csvValue2, { + record{|string a; int...;|}[]|csv:Error cn16 = csv:parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); test:assertEquals(cn16, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string...;|}[]|Error cn17 = parseRecordAsRecordType(csvValue2, { + record{|string...;|}[]|csv:Error cn17 = csv:parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); test:assertEquals(cn17, [{"a": "a"}, {"a": "b"}]); - record{|string a?;|}[]|Error cn18 = parseRecordAsRecordType(csvValue2, { + record{|string a?;|}[]|csv:Error cn18 = csv:parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); - test:assertTrue(cn18 is Error); + test:assertTrue(cn18 is csv:Error); test:assertEquals((cn18).message(), "No mapping field in the expected type for header 'b'"); - record{|string? a;|}[]|Error cn19 = parseRecordAsRecordType(csvValue2, { + record{|string? a;|}[]|csv:Error cn19 = csv:parseRecordAsRecordType(csvValue2, { allowDataProjection: false }); - test:assertTrue(cn19 is Error); + test:assertTrue(cn19 is csv:Error); test:assertEquals((cn19).message(), "No mapping field in the expected type for header 'b'"); - anydata[][]|Error c20 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + anydata[][]|csv:Error c20 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); test:assertEquals(c20, [["a", 2], ["b", 4]]); - [string, int][]|Error cn20_2 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string, int][]|csv:Error cn20_2 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); test:assertEquals(cn20_2, [["a", 2], ["b", 4]]); - [string][]|Error cn21 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string][]|csv:Error cn21 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); - test:assertTrue(cn21 is Error); + test:assertTrue(cn21 is csv:Error); test:assertEquals((cn21).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); - [string][]|Error cn21_2 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string][]|csv:Error cn21_2 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: {} }); test:assertEquals(cn21_2, [["a"], ["b"]]); - [int][]|Error cn21_3 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [int][]|csv:Error cn21_3 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: {} }); - test:assertTrue(cn21_3 is Error); - test:assertEquals((cn21_3).message(), generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); + test:assertTrue(cn21_3 is csv:Error); + test:assertEquals((cn21_3).message(), common:generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); - [string, int...][]|Error cn22 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string, int...][]|csv:Error cn22 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); test:assertEquals(cn22, [["a", 2], ["b", 4]]); - [string...][]|Error cn23 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string...][]|csv:Error cn23 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); - test:assertTrue(cn23 is Error); - test:assertEquals(( cn23).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); + test:assertTrue(cn23 is csv:Error); + test:assertEquals(( cn23).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - [string, ()][]|Error cn24 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + [string, ()][]|csv:Error cn24 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); - test:assertTrue(cn24 is Error); - test:assertEquals((cn24).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "()")); + test:assertTrue(cn24 is csv:Error); + test:assertEquals((cn24).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "()")); - string[][]|Error cn25 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + string[][]|csv:Error cn25 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); - test:assertTrue(cn25 is Error); - test:assertEquals(( cn25).message(), generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); + test:assertTrue(cn25 is csv:Error); + test:assertEquals(( cn25).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - string[][1]|Error cn26 = parseRecordAsListType(csvValue2, ["a", "b"] ,{ + string[][1]|csv:Error cn26 = csv:parseRecordAsListType(csvValue2, ["a", "b"] ,{ allowDataProjection: false }); - test:assertTrue(cn26 is Error); + test:assertTrue(cn26 is csv:Error); test:assertEquals((cn26).message(), "invalid array size for expected array type, cannot be greater than '1'"); } diff --git a/ballerina/tests/user_config_with_parser_options_test.bal b/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal similarity index 57% rename from ballerina/tests/user_config_with_parser_options_test.bal rename to ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal index 7d7cc9b..06148a9 100644 --- a/ballerina/tests/user_config_with_parser_options_test.bal +++ b/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal @@ -1,61 +1,63 @@ +import ballerina/csv_commons as common; +import ballerina/data.csv as csv; import ballerina/test; @test:Config function testFromCsvStringWithParserOptions() { - [int, string, boolean, decimal, float, string][]|Error csv1op3 = parseStringToList(csvStringData1, option3); + [int, string, boolean, decimal, float, string][]|csv:Error csv1op3 = csv:parseStringToList(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, "()"] ]); - record {int a; string b; boolean c; decimal d; float e; string f;}[]|Error csv1op3_2 = parseStringToRecord(csvStringData1, ptOption1); + record {int a; string b; boolean c; decimal d; float e; string f;}[]|csv:Error csv1op3_2 = csv:parseStringToRecord(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: "()"} ]); - record {int a; string b; boolean c; decimal d; float e; string f;}[]|Error csv1op3_3 = parseStringToRecord(csvStringData1, ptOption2); + record {int a; string b; boolean c; decimal d; float e; string f;}[]|csv:Error csv1op3_3 = csv:parseStringToRecord(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: "()"} ]); - [int, string, boolean, decimal, float, string][]|Error csv2op4 = parseStringToList(csvStringData2, option4); + [int, string, boolean, decimal, float, string][]|csv:Error csv2op4 = csv:parseStringToList(csvStringData2, option4); test:assertEquals(csv2op4, []); - record {}[]|Error csv2op4_2 = parseStringToRecord(csvStringData2, ptOption3); + record {}[]|csv:Error csv2op4_2 = csv:parseStringToRecord(csvStringData2, ptOption3); test:assertEquals(csv2op4_2, []); - record {}[]|Error csv2op4_3 = parseStringToRecord(csvStringData2, ptOption4); + record {}[]|csv:Error csv2op4_3 = csv:parseStringToRecord(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: "()"} ]); - [int, string, boolean, decimal, float, string][]|Error csv3op3 = parseStringToList(csvStringData3, option3); + [int, string, boolean, decimal, float, string][]|csv:Error csv3op3 = csv:parseStringToList(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, "()"] ]); - record {}[]|Error csv3op3_2 = parseStringToRecord(csvStringData3, ptOption1); + record {}[]|csv:Error csv3op3_2 = csv:parseStringToRecord(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: "()"} ]); - record {}[]|Error csv3op3_3 = parseStringToRecord(csvStringData3, ptOption2); + record {}[]|csv:Error csv3op3_3 = csv:parseStringToRecord(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: "()"} ]); - record {}[]|Error csv3op3_4 = parseStringToRecord(csvStringData3, {header: 9, skipLines: "2-10"}); + record {}[]|csv:Error csv3op3_4 = csv:parseStringToRecord(csvStringData3, {header: 9, skipLines: "2-10"}); test:assertEquals(csv3op3_4, [ {'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": null} ]); @@ -63,11 +65,11 @@ function testFromCsvStringWithParserOptions() { @test:Config function testFromCsvStringWithHeaderLessParserOptions() { - [int, string, boolean, decimal, float, ()][]|Error csv1op6 = parseStringToList(csvStringData1, option6); - test:assertTrue(csv1op6 is Error); - test:assertEquals((csv1op6).message(), generateErrorMessageForInvalidCast("null", "()")); + [int, string, boolean, decimal, float, ()][]|csv:Error csv1op6 = csv:parseStringToList(csvStringData1, option6); + test:assertTrue(csv1op6 is csv:Error); + test:assertEquals((csv1op6).message(), common:generateErrorMessageForInvalidCast("null", "()")); - record {}[]|Error csv1op5_2 = parseStringToRecord(csvStringData1, ptOption5); + record {}[]|csv:Error csv1op5_2 = csv:parseStringToRecord(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: ()}, @@ -75,7 +77,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record {}[]|Error csv1op6_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [3, 5]}); + record {}[]|csv:Error csv1op6_2 = csv:parseStringToRecord(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: ()}, @@ -83,35 +85,35 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record {}[]|Error csv3op6_2 = parseStringToRecord(csvStringData3, {header: false, skipLines: [1, 3, 5, -1, 100, 100]}); + record {}[]|csv:Error csv3op6_2 = csv:parseStringToRecord(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: ()} ]); - record {}[]|Error csv4op6_2 = parseStringToRecord(csvStringData4, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|csv:Error csv4op6_2 = csv:parseStringToRecord(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: ()} ]); - record {}[]|Error csv5op6_2 = parseStringToRecord(csvStringData5, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|csv:Error csv5op6_2 = csv:parseStringToRecord(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: ()} ]); - record {}[]|Error csv6op6_2 = parseStringToRecord(csvStringData6, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|csv:Error csv6op6_2 = csv:parseStringToRecord(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: ()} ]); - record {}[]|Error csv2op6_2 = parseStringToRecord(csvStringData2, {header: false, skipLines: [5, 7]}); + record {}[]|csv:Error csv2op6_2 = csv:parseStringToRecord(csvStringData2, {header: false, skipLines: [5, 7]}); test:assertEquals(csv2op6_2, [ {'1: "hello", '2: "hello", '3: (), '4: 12, '5: true, '6: 12.34}, {'1: "//comment"}, @@ -124,7 +126,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { @test:Config function testHeaderOption() { - record {}[]|Error csv2cop1 = parseStringToRecord(csvStringData2, {header: 4}); + record {}[]|csv:Error csv2cop1 = csv:parseStringToRecord(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: ()}, @@ -133,17 +135,17 @@ function testHeaderOption() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - record {}[]|Error csv2cop2 = parseStringToRecord(csvStringData2, {header: 100}); + record {}[]|csv:Error csv2cop2 = csv:parseStringToRecord(csvStringData2, {header: 100}); test:assertEquals(csv2cop2, []); - record {}[]|Error csv2cop3 = parseStringToRecord(csvStringData2, {header: 11}); + record {}[]|csv:Error csv2cop3 = csv:parseStringToRecord(csvStringData2, {header: 11}); test:assertEquals(csv2cop3, []); - record {}[]|Error csv2cop4 = parseStringToRecord(csvStringData2, {header: 10}); + record {}[]|csv:Error csv2cop4 = csv:parseStringToRecord(csvStringData2, {header: 10}); test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": ()}]); - record {}[]|Error csv1cop5 = parseStringToRecord(csvStringData1, {}); - test:assertTrue(csv1cop5 is Error); + record {}[]|csv:Error csv1cop5 = csv:parseStringToRecord(csvStringData1, {}); + test:assertTrue(csv1cop5 is csv:Error); test:assertEquals((csv1cop5).message(), "The provided header row is empty"); } @@ -160,60 +162,60 @@ function testNullConfigOption() { string csvValue5 = string `b, a bN/Aa,N/A`; - record {() a;}[]|Error cn = parseStringToRecord(csvValue1, {nilValue: ()}); + record {() a;}[]|csv:Error cn = csv:parseStringToRecord(csvValue1, {nilValue: ()}); test:assertEquals(cn, [{a: ()}]); - cn = parseStringToRecord(csvValue2, {nilValue: ()}); + cn = csv:parseStringToRecord(csvValue2, {nilValue: ()}); test:assertEquals(cn, [{a: ()}]); - cn = parseStringToRecord(csvValue3, {nilValue: ()}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("e", "()")); + cn = csv:parseStringToRecord(csvValue3, {nilValue: ()}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("e", "()")); - cn = parseStringToRecord(csvValue4, {nilValue: ()}); + cn = csv:parseStringToRecord(csvValue4, {nilValue: ()}); test:assertEquals(cn, [{a: ()}]); - cn = parseStringToRecord(csvValue1, {nilValue: null}); + cn = csv:parseStringToRecord(csvValue1, {nilValue: null}); test:assertEquals(cn, [{a: ()}]); - cn = parseStringToRecord(csvValue2, {nilValue: null}); + cn = csv:parseStringToRecord(csvValue2, {nilValue: null}); test:assertEquals(cn, [{a: ()}]); - cn = parseStringToRecord(csvValue3, {nilValue: null}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("e", "()")); + cn = csv:parseStringToRecord(csvValue3, {nilValue: null}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("e", "()")); - cn = parseStringToRecord(csvValue4, {nilValue: null}); + cn = csv:parseStringToRecord(csvValue4, {nilValue: null}); test:assertEquals(cn, [{a: ()}]); - cn = parseStringToRecord(csvValue1, {nilValue: "()"}); + cn = csv:parseStringToRecord(csvValue1, {nilValue: "()"}); test:assertEquals(cn, [{a: ()}]); - cn = parseStringToRecord(csvValue2, {nilValue: "()"}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("null", "()")); + cn = csv:parseStringToRecord(csvValue2, {nilValue: "()"}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("null", "()")); - cn = parseStringToRecord(csvValue3, {nilValue: "()"}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("e", "()")); + cn = csv:parseStringToRecord(csvValue3, {nilValue: "()"}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("e", "()")); - cn = parseStringToRecord(csvValue4, {nilValue: "()"}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("Null", "()")); + cn = csv:parseStringToRecord(csvValue4, {nilValue: "()"}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("Null", "()")); - cn = parseStringToRecord(csvValue5, {nilValue: "N/A"}); + cn = csv:parseStringToRecord(csvValue5, {nilValue: "N/A"}); test:assertEquals(cn, [{b: "bN/Aa", a: ()}]); - cn = parseStringToRecord(csvValue2, {nilValue: "null"}); + cn = csv:parseStringToRecord(csvValue2, {nilValue: "null"}); test:assertEquals(cn, [{a: ()}]); - cn = parseStringToRecord(csvValue4, {nilValue: "null"}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("Null", "()")); + cn = csv:parseStringToRecord(csvValue4, {nilValue: "null"}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("Null", "()")); - cn = parseStringToRecord(csvValue1, {nilValue: "null"}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForInvalidCast("()", "()")); + cn = csv:parseStringToRecord(csvValue1, {nilValue: "null"}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("()", "()")); } @test:Config @@ -243,38 +245,38 @@ function testCommentConfigOption() { 1 ,#2 # comment # comment`; - record {int a;}[]|Error cn; + record {int a;}[]|csv:Error cn; - cn = parseStringToRecord(csvValue1); + cn = csv:parseStringToRecord(csvValue1); test:assertEquals(cn, [{a: 1}]); - cn = parseStringToRecord(csvValue2); + cn = csv:parseStringToRecord(csvValue2); test:assertEquals(cn, [{a: 1}]); - cn = parseStringToRecord(csvValue3); + cn = csv:parseStringToRecord(csvValue3); test:assertEquals(cn, [{a: 1}]); - cn = parseStringToRecord(csvValue4); + cn = csv:parseStringToRecord(csvValue4); test:assertEquals(cn, [{a: 1}]); - cn = parseStringToRecord(csvValue5); + cn = csv:parseStringToRecord(csvValue5); test:assertEquals(cn, [{a: 1, b: 2}]); - cn = parseStringToRecord(csvValue6); + cn = csv:parseStringToRecord(csvValue6); test:assertEquals(cn, [{a: 1, b: 2}]); - cn = parseStringToRecord(csvValue7); + cn = csv:parseStringToRecord(csvValue7); test:assertEquals(cn, [{a: 1}]); - record {|int a; int b;|}[]|Error cn2 = parseStringToRecord(csvValue7, {header: 0}); + record {|int a; int b;|}[]|csv:Error cn2 = csv:parseStringToRecord(csvValue7, {header: 0}); test:assertEquals(cn2, [{a: 1, b: 0}]); - cn = parseStringToRecord(csvValue8); - test:assertTrue(cn is Error); + cn = csv:parseStringToRecord(csvValue8); + test:assertTrue(cn is csv:Error); // TODO:Fix the error message - // test:assertEquals(( cn).message(), generateErrorMessageForInvalidCast("1, 2", "int")); + // test:assertEquals(( cn).message(), common:generateErrorMessageForInvalidCast("1, 2", "int")); - cn = parseStringToRecord(csvValue9); + cn = csv:parseStringToRecord(csvValue9); test:assertEquals(cn, [{a: 1}]); } @@ -304,63 +306,63 @@ function testCommentConfigOption2() { & comment`; - record {int a; int b;}[]|Error cn; - record {int c;}[]|Error cn2; + record {int a; int b;}[]|csv:Error cn; + record {int c;}[]|csv:Error cn2; - cn = parseStringToRecord(csvValue1, {comment: "&"}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); + cn = csv:parseStringToRecord(csvValue1, {comment: "&"}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn = parseStringToRecord(csvValue2, {comment: "&"}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); + cn = csv:parseStringToRecord(csvValue2, {comment: "&"}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn = parseStringToRecord(csvValue3, {comment: "&"}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); + cn = csv:parseStringToRecord(csvValue3, {comment: "&"}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn = parseStringToRecord(csvValue4, {comment: "&"}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); + cn = csv:parseStringToRecord(csvValue4, {comment: "&"}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn = parseStringToRecord(csvValue5, {comment: "&"}); - test:assertTrue(cn is Error); + cn = csv:parseStringToRecord(csvValue5, {comment: "&"}); + test:assertTrue(cn is csv:Error); // TODO: Fix the error message - // test:assertEquals(( cn).message(), generateErrorMessageForMissingRequiredField("b")); + // test:assertEquals(( cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn = parseStringToRecord(csvValue6, {comment: "&", header: 2}); - test:assertTrue(cn is Error); - test:assertEquals((cn).message(), generateErrorMessageForMissingRequiredField("b")); + cn = csv:parseStringToRecord(csvValue6, {comment: "&", header: 2}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); - cn2 = parseStringToRecord(csvValue1, {comment: "&"}); - test:assertTrue(cn2 is Error); - test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); + cn2 = csv:parseStringToRecord(csvValue1, {comment: "&"}); + test:assertTrue(cn2 is csv:Error); + test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); - cn2 = parseStringToRecord(csvValue2, {comment: "&"}); - test:assertTrue(cn2 is Error); - test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); + cn2 = csv:parseStringToRecord(csvValue2, {comment: "&"}); + test:assertTrue(cn2 is csv:Error); + test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); - cn2 = parseStringToRecord(csvValue3, {comment: "&"}); - test:assertTrue(cn2 is Error); - test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); + cn2 = csv:parseStringToRecord(csvValue3, {comment: "&"}); + test:assertTrue(cn2 is csv:Error); + test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); - cn2 = parseStringToRecord(csvValue4, {comment: "&"}); - test:assertTrue(cn2 is Error); - test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); + cn2 = csv:parseStringToRecord(csvValue4, {comment: "&"}); + test:assertTrue(cn2 is csv:Error); + test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); - cn2 = parseStringToRecord(csvValue5, {comment: "&"}); - test:assertTrue(cn2 is Error); + cn2 = csv:parseStringToRecord(csvValue5, {comment: "&"}); + test:assertTrue(cn2 is csv:Error); // TODO: Fix the error message - // test:assertEquals(( cn2).message(), generateErrorMessageForMissingRequiredField("c")); + // test:assertEquals(( cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); - cn2 = parseStringToRecord(csvValue6, {header: 2, comment: "&"}); - test:assertTrue(cn2 is Error); - test:assertEquals((cn2).message(), generateErrorMessageForMissingRequiredField("c")); + cn2 = csv:parseStringToRecord(csvValue6, {header: 2, comment: "&"}); + test:assertTrue(cn2 is csv:Error); + test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); } @test:Config function testSkipLineParserOption() { - [int, string, boolean, decimal, float, ()][]|Error csv1cp = parseStringToList(csvStringData1, {skipLines: [], header: 1}); + [int, string, boolean, decimal, float, ()][]|csv:Error csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [], header: 1}); test:assertEquals(csv1cp, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -369,7 +371,7 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: [0], header: 1}); + csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [0], header: 1}); test:assertEquals(csv1cp, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -378,7 +380,7 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: [0, 4, 10], header: 1}); + csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [0, 4, 10], header: 1}); test:assertEquals(csv1cp, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -386,46 +388,46 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: [1, 2, 3, 4, 5], header: 1}); + csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [1, 2, 3, 4, 5], header: 1}); test:assertEquals(csv1cp, [ ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: "1-5", header: 1}); + csv1cp = csv:parseStringToList(csvStringData1, {skipLines: "1-5", header: 1}); test:assertEquals(csv1cp, [ ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: [4, 2], header: 1}); + csv1cp = csv:parseStringToList(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, ()] ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: "2-4", header: 1}); + csv1cp = csv:parseStringToList(csvStringData1, {skipLines: "2-4", header: 1}); test:assertEquals(csv1cp, [ [1, "string1", true, 2.234, 2.234, ()], [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: [4, 2, -1], header: 1}); + csv1cp = csv:parseStringToList(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, ()] ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: [4, -1, 2], header: 1}); + csv1cp = csv:parseStringToList(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, ()] ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: [5, 4, 3, 2, 1], header: 1}); + csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [5, 4, 3, 2, 1], header: 1}); test:assertEquals(csv1cp, [ ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: [10], header: 1}); + csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [10], header: 1}); test:assertEquals(csv1cp, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -434,7 +436,7 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: [-2], header: 1}); + csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [-2], header: 1}); test:assertEquals(csv1cp, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -443,7 +445,7 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: [-2, 0, 2], header: 1}); + csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [-2, 0, 2], header: 1}); test:assertEquals(csv1cp, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], @@ -451,7 +453,7 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = parseStringToList(csvStringData1, {skipLines: "0-2", header: 1}); + csv1cp = csv:parseStringToList(csvStringData1, {skipLines: "0-2", header: 1}); test:assertEquals(csv1cp, [ [3, "string3", false, 1.23, 1.23, ()], [4, "string4", true, -6.51, -6.51, ()], @@ -461,64 +463,64 @@ function testSkipLineParserOption() { @test:Config function testCustomHeaderOption() { - anydata[][]|Error bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}); + anydata[][]|csv:Error bm1ba = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - anydata[][]|Error bm1ba2 = parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}); + anydata[][]|csv:Error bm1ba2 = csv:parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}); test:assertEquals(bm1ba2, [ [false, true], [false, true] ]); - anydata[][]|Error bm2ba = parseRecordAsListType([bm2, bm2], ["b1", "n1", "b2", "n2", "b3"], {}); - test:assertTrue(bm2ba is Error); - test:assertEquals((bm2ba).message(), generateErrorMessageForInvalidCustomHeader("n2")); + anydata[][]|csv:Error bm2ba = csv:parseRecordAsListType([bm2, bm2], ["b1", "n1", "b2", "n2", "b3"], {}); + test:assertTrue(bm2ba is csv:Error); + test:assertEquals((bm2ba).message(), common:generateErrorMessageForInvalidCustomHeader("n2")); - anydata[][]|Error bm3ba = parseRecordAsListType([bm3, bm3], ["b1", "b4", "b2", "n2", "i1"], {}); - test:assertTrue(bm3ba is Error); - test:assertEquals((bm3ba).message(), generateErrorMessageForInvalidCustomHeader("n2")); + anydata[][]|csv:Error bm3ba = csv:parseRecordAsListType([bm3, bm3], ["b1", "b4", "b2", "n2", "i1"], {}); + test:assertTrue(bm3ba is csv:Error); + test:assertEquals((bm3ba).message(), common:generateErrorMessageForInvalidCustomHeader("n2")); - anydata[][]|Error bm3ba2 = parseRecordAsListType([bm3, bm3], ["b1", "b3", "b4", "b2", "i2"], {}); - test:assertTrue(bm3ba2 is Error); - test:assertEquals((bm3ba2).message(), generateErrorMessageForInvalidCustomHeader("i2")); + anydata[][]|csv:Error bm3ba2 = csv:parseRecordAsListType([bm3, bm3], ["b1", "b3", "b4", "b2", "i2"], {}); + test:assertTrue(bm3ba2 is csv:Error); + test:assertEquals((bm3ba2).message(), common:generateErrorMessageForInvalidCustomHeader("i2")); - [boolean...][]|Error bm3ba4 = parseRecordAsListType([bm3, bm3], ["n2"], {}); - test:assertTrue(bm3ba4 is Error); + [boolean...][]|csv:Error bm3ba4 = csv:parseRecordAsListType([bm3, bm3], ["n2"], {}); + test:assertTrue(bm3ba4 is csv:Error); test:assertEquals((bm3ba4).message(), "Invalid length for the header names"); - [boolean...][]|Error bm3ba5 = parseRecordAsListType([bm3, bm3], [], {}); - test:assertTrue(bm3ba5 is Error); + [boolean...][]|csv:Error bm3ba5 = csv:parseRecordAsListType([bm3, bm3], [], {}); + test:assertTrue(bm3ba5 is csv:Error); test:assertEquals((bm3ba5).message(), "Invalid length for the header names"); - record {}[]|Error ct1br = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); - test:assertTrue(ct1br is Error); + record {}[]|csv:Error ct1br = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); + test:assertTrue(ct1br is csv:Error); test:assertEquals((ct1br).message(), "Invalid length for the custom headers"); - record {}[]|Error ct1br2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); - test:assertTrue(ct1br2 is Error); + record {}[]|csv:Error ct1br2 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); + test:assertTrue(ct1br2 is csv:Error); test:assertEquals((ct1br2).message(), "Invalid length for the custom headers"); - record {}[]|Error ct1br2_2 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); - test:assertTrue(ct1br2_2 is Error); + record {}[]|csv:Error ct1br2_2 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); + test:assertTrue(ct1br2_2 is csv:Error); test:assertEquals((ct1br2_2).message(), "Invalid length for the custom headers"); - record {}[]|Error ct1br3 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], [], {}); - test:assertTrue(ct1br3 is Error); + record {}[]|csv:Error ct1br3 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], [], {}); + test:assertTrue(ct1br3 is csv:Error); test:assertEquals((ct1br3).message(), "Invalid length for the custom headers"); - record {|string a; string b; string c;|}[]|Error ct1br5 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); - test:assertTrue(ct1br5 is Error); + record {|string a; string b; string c;|}[]|csv:Error ct1br5 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + test:assertTrue(ct1br5 is csv:Error); // TODO: Fix the error message - test:assertEquals((ct1br5).message(), generateErrorMessageForMissingRequiredField("c")); + test:assertEquals((ct1br5).message(), common:generateErrorMessageForMissingRequiredField("c")); - record {string a; string b; string c;}[]|Error ct1br6 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); - test:assertTrue(ct1br6 is Error); - test:assertEquals((ct1br6).message(), generateErrorMessageForMissingRequiredField("c")); + record {string a; string b; string c;}[]|csv:Error ct1br6 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + test:assertTrue(ct1br6 is csv:Error); + test:assertEquals((ct1br6).message(), common:generateErrorMessageForMissingRequiredField("c")); - record {string a; string b;}[]|Error ct1br7 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + record {string a; string b;}[]|csv:Error ct1br7 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { stringConversion: false }); test:assertEquals(ct1br7, [ @@ -526,7 +528,7 @@ function testCustomHeaderOption() { {a: "a", e: "1", b: "true"} ]); - record {|string a; string b;|}[]|Error ct1br8 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + record {|string a; string b;|}[]|csv:Error ct1br8 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { stringConversion: false }); test:assertEquals(ct1br8, [ @@ -534,7 +536,7 @@ function testCustomHeaderOption() { {a: "a", b: "true"} ]); - record {|string...;|}[]|Error ct1br9 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + record {|string...;|}[]|csv:Error ct1br9 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { stringConversion: false }); test:assertEquals(ct1br9, [ @@ -542,7 +544,7 @@ function testCustomHeaderOption() { {a: "a", b: "true", e: "1"} ]); - record {|string...;|}[]|Error ct1br10 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), { + record {|string...;|}[]|csv:Error ct1br10 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), { stringConversion: false }); test:assertEquals(ct1br10, [ @@ -553,19 +555,19 @@ function testCustomHeaderOption() { @test:Config function testCustomHeaderParserOption2() { - record {}[]|Error ct1br = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); - test:assertTrue(ct1br is Error); + 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 {}[]|Error ct1br2 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: []}); - test:assertTrue(ct1br2 is Error); + record {}[]|csv:Error ct1br2 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: []}); + test:assertTrue(ct1br2 is csv:Error); test:assertEquals((ct1br2).message(), "Invalid length for the custom headers"); - record {int a; string b; boolean c; decimal d; float e; () f;}[]|Error ct1br3 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); - test:assertTrue(ct1br3 is Error); + record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br3 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); + test:assertTrue(ct1br3 is csv:Error); test:assertEquals((ct1br3).message(), "Invalid length for the custom headers"); - record {int a; string b; boolean c; decimal d; float e; () f;}[]|Error ct1br4 = 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:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["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: ()}, @@ -574,7 +576,7 @@ function testCustomHeaderParserOption2() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - record {() a; float b; decimal c; boolean d; string e; int f;}[]|Error ct1br5 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f", "e", "d", "c", "b", "a"]}); + 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"]}); 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: ()}, @@ -583,7 +585,7 @@ function testCustomHeaderParserOption2() { {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} ]); - record {() a; float b; decimal c; boolean d; string e; int f;}[]|Error ct1br5_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f", "e", "d", "c", "b", "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"]}); 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: ()}, @@ -592,7 +594,7 @@ function testCustomHeaderParserOption2() { {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} ]); - record {() a; float b; decimal c; boolean d; string e; int f;}[]|Error ct1br5_3 = parseStringToRecord(csvStringData1, {skipLines: [1], customHeaders: ["f", "e", "d", "c", "b", "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"]}); 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: ()}, @@ -601,7 +603,7 @@ function testCustomHeaderParserOption2() { {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} ]); - record {|() a1; float b1; decimal c1; boolean d1; string e1; int f1;|}[]|Error ct1br6 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + 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: ()}, @@ -610,7 +612,7 @@ function testCustomHeaderParserOption2() { {f1: 5, e1: "string5", d1: true, c1: 3, b1: 3, a1: ()} ]); - record {|boolean d1; string e1;|}[]|Error ct1br7 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br7 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -619,7 +621,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|Error ct1br7_2 = parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br7_2 = csv:parseStringToRecord(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7_2, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -628,11 +630,11 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|Error ct1br8 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); - test:assertTrue(ct1br8 is Error); - test:assertEquals((ct1br8).message(), generateErrorMessageForInvalidCast("string1", "boolean")); + record {|boolean d1; string e1;|}[]|csv:Error ct1br8 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); + test:assertTrue(ct1br8 is csv:Error); + test:assertEquals((ct1br8).message(), common:generateErrorMessageForInvalidCast("string1", "boolean")); - record {|boolean d1; string e1;|}[]|Error ct1br9 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br9 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br9, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -641,7 +643,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|Error ct1br10 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "f1", "b1", "a1"]}); + 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}, @@ -650,11 +652,11 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|Error ct1br11 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); - test:assertTrue(ct1br11 is Error); + record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); + test:assertTrue(ct1br11 is csv:Error); test:assertEquals((ct1br11).message(), "Invalid length for the custom headers"); - record {|string d1; string e1;|}[]|Error ct1br12 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ {e1: "string1", d1: "true"}, {e1: "string2", d1: "false"}, @@ -663,9 +665,9 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: "true"} ]); - record {|string d1; string e1;|}[]|Error ct1br13 = parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); - test:assertTrue(ct1br13 is Error); - test:assertEquals((ct1br13).message(), generateErrorMessageForMissingRequiredField("d1")); + record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); + test:assertTrue(ct1br13 is csv:Error); + test:assertEquals((ct1br13).message(), common:generateErrorMessageForMissingRequiredField("d1")); } @test:Config @@ -708,26 +710,26 @@ function testTextQuotesWithParserOptions() { 1, "2", "3" `; - record {int a;}[]|Error cn = parseStringToRecord(csvValue1, {header: 1}); + record {int a;}[]|csv:Error cn = csv:parseStringToRecord(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...;|}[]|Error cn2 = parseStringToRecord(csvValue2, {header: 1}); + record {|int c; string...;|}[]|csv:Error cn2 = csv:parseStringToRecord(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;|}[]|Error cn3 = parseStringToRecord(csvValue3, {}); + record {|string b; string c;|}[]|csv:Error cn3 = csv:parseStringToRecord(csvValue3, {}); test:assertEquals(cn3, [{"b": "\"2\"", "c": "3"}, {"b": "5, 6\"b\" \" a \"", c: "\"6\""}]); - record {}[]|Error cn4 = parseStringToRecord(csvValue4, {textEnclosure: "'"}); + record {}[]|csv:Error cn4 = csv:parseStringToRecord(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[][]|Error cn4_2 = parseStringToList(csvValue4, {textEnclosure: "'"}); + anydata[][]|csv:Error cn4_2 = csv:parseStringToList(csvValue4, {textEnclosure: "'"}); test:assertEquals(cn4_2, [[1, 2, 3], [4, "5, '6'7", 8], [4, "\"5\"", "4, '5\"a\", ,\",\" a '6'7"]]); - record {}[]|Error cn5 = parseStringToRecord(csvValue5, {}); + record {}[]|csv:Error cn5 = csv:parseStringToRecord(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 {}[]|Error cn6 = parseStringToRecord(csvValue6, {}); - test:assertTrue(cn6 is Error); + record {}[]|csv:Error cn6 = csv:parseStringToRecord(csvValue6, {}); + test:assertTrue(cn6 is csv:Error); test:assertEquals((cn6).message(), "Invalid length for the custom headers"); } @@ -753,16 +755,16 @@ function testHeaderQuotesWithParserOptions() { 4, '5, '6'7', 8 4, "5", '4, '5"a", ,"," a '6'7'`; - record {}[]|Error cn = parseStringToRecord(csvValue1, {header: 1}); + record {}[]|csv:Error cn = csv:parseStringToRecord(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 {}[]|Error cn2 = parseStringToRecord(csvValue2, {header: 1}); + record {}[]|csv:Error cn2 = csv:parseStringToRecord(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[][]|Error cn2_2 = parseStringToList(csvValue2, {header: 1}); + anydata[][]|csv:Error cn2_2 = csv:parseStringToList(csvValue2, {header: 1}); test:assertEquals(cn2_2, [[1, "2, 3", 3], [1, "2, 3", 3], [4, 5, 6]]); - record {}[]|Error cn3 = parseStringToRecord(csvValue3, {textEnclosure: "'"}); + record {}[]|csv:Error cn3 = csv:parseStringToRecord(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"}]); } @@ -792,28 +794,28 @@ function testEscapeCharactersWithParserOptions() { "1\\", "2\\"", "3"`; - record {}[]|Error cn = parseStringToRecord(csvValue1, {header: 1}); + record {}[]|csv:Error cn = csv:parseStringToRecord(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 {}[]|Error cn2 = parseStringToRecord(csvValue2, {header: 1}); + record {}[]|csv:Error cn2 = csv:parseStringToRecord(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 {}[]|Error cn3 = parseStringToRecord(csvValue3, {header: 1}); + record {}[]|csv:Error cn3 = csv:parseStringToRecord(csvValue3, {header: 1}); test:assertEquals(cn3, [{"a": 1, "b": 2.0, "c": 3.0}, {"a": 1.0, "b": 2, "c": 3}, {"a": 1, "b": "2\"", "c": 3}, {"a": "1\\", "b": "2\\\"", "c": 3}]); - anydata[][]|Error cn_2 = parseStringToList(csvValue1, {header: 1}); + anydata[][]|csv:Error cn_2 = csv:parseStringToList(csvValue1, {header: 1}); test:assertEquals(cn_2, [[1, "2a\t", "3b\n"], ["1c\n", 2, 3], [1, "2a\"", 3], ["1a\\", "2b\\\"", 3]]); - anydata[][]|Error cn2_2 = parseStringToList(csvValue2, {header: 1}); + anydata[][]|csv:Error cn2_2 = csv:parseStringToList(csvValue2, {header: 1}); test:assertEquals(cn2_2, [[1, "2a\t", "3b\n"], ["1c\n", "/2/", 3], [1, "2a\"", 3], ["1a\\", "2b\\\"", 3]]); - anydata[][]|Error cn3_2 = parseStringToList(csvValue3, {header: 1}); + anydata[][]|csv:Error cn3_2 = csv:parseStringToList(csvValue3, {header: 1}); test:assertEquals(cn3_2, [[1, 2.0, 3.0], [1.0, 2, 3], [1, "2\"", 3], ["1\\", "2\\\"", 3]]); } @test:Config function testDelimiterWithParserOptions() { - record {}[]|Error cn = parseStringToRecord(csvStringData7, {header: 1, delimiter: "@"}); + record {}[]|csv:Error cn = csv:parseStringToRecord(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: ()}, @@ -822,7 +824,7 @@ function testDelimiterWithParserOptions() { {a: 5, b: "string", c: true, d: 2.234, e: -3.21, f: ()} ]); - anydata[][]|Error cn2 = parseStringToList(csvStringData7, {header: 1, delimiter: "@"}); + anydata[][]|csv:Error cn2 = csv:parseStringToList(csvStringData7, {header: 1, delimiter: "@"}); test:assertEquals(cn2, [ [1, "string", true, 2.234, -3.21, ()], [2, "s,tring", true, 2.234, -3.21, ()], @@ -836,21 +838,21 @@ function testDelimiterWithParserOptions() { function testLineTerminatorWithParserOptions() { string csvValue = string `a,b${"\n"} 1,"2\n3"`; - record {}[]|Error cn = parseStringToRecord(csvValue, {header: 0, lineTerminator: LF}); + record {}[]|csv:Error cn = csv:parseStringToRecord(csvValue, {header: 0, lineTerminator: csv:LF}); test:assertEquals(cn, [{a: 1, b: "2\n3"}]); - cn = parseStringToRecord(csvValue, {header: 0, lineTerminator: [LF]}); + cn = csv:parseStringToRecord(csvValue, {header: 0, lineTerminator: [csv:LF]}); test:assertEquals(cn, [{a: 1, b: "2\n3"}]); - cn = parseStringToRecord(csvValue, {header: 0, lineTerminator: [CRLF, LF, CR]}); + cn = csv:parseStringToRecord(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn, [{a: 1, b: "2\n3"}]); - anydata[][]|Error cn2 = parseStringToList(csvValue, {header: 0, lineTerminator: LF}); + anydata[][]|csv:Error cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: csv:LF}); test:assertEquals(cn2, [[1, "2\n3"]]); - cn2 = parseStringToList(csvValue, {header: 0, lineTerminator: [LF]}); + cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: [csv:LF]}); test:assertEquals(cn2, [[1, "2\n3"]]); - cn2 = parseStringToList(csvValue, {header: 0, lineTerminator: [CRLF, LF, CR]}); + cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn2, [[1, "2\n3"]]); } diff --git a/ballerina-tests/user-config-tests/tests/user_configs.bal b/ballerina-tests/user-config-tests/tests/user_configs.bal new file mode 100644 index 0000000..c5f08a9 --- /dev/null +++ b/ballerina-tests/user-config-tests/tests/user_configs.bal @@ -0,0 +1,29 @@ +import ballerina/data.csv as csv; + +// Valid parser options +csv:ParseOption option1 = {delimiter: "@", nilValue: "null", lineTerminator: [csv:LF]}; +csv:ParseOption option2 = {nilValue: "N/A", lineTerminator: [csv:CR, 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: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]}; + +// Invalid parser options +csv:ParseOption invalidParserOptions1 = {header: 4}; +csv:ParseOption invalidParserOptions2 = {comment: "$"}; +csv:ParseOption invalidParserOptions3 = {lineTerminator: csv:CR}; +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]}; diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 8bf4889..7a1da6b 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -137,10 +137,14 @@ build.dependsOn ":${packageName}-native:build" build.dependsOn deleteDependencyTomlFiles build.dependsOn ":${packageName}-compiler-plugin:build" build.dependsOn deleteDependencyTomlFiles +build.finalizedBy ":${packageName}-ballerina-tests:build" + +//build.finalizedBy ":${packageName}-ballerina-tests:ballerinaTest" test.dependsOn ":${packageName}-native:build" test.dependsOn ":${packageName}-native:build" test.dependsOn ":${packageName}-compiler-plugin:build" +test.finalizedBy ":${packageName}-ballerina-tests:build" publish.dependsOn build publishToMavenLocal.dependsOn build diff --git a/ballerina/tests/parse_list_type_as_list_test.bal b/ballerina/tests/parse_list_type_as_list_test.bal deleted file mode 100644 index 7a774d3..0000000 --- a/ballerina/tests/parse_list_type_as_list_test.bal +++ /dev/null @@ -1,409 +0,0 @@ -import ballerina/test; - -@test:Config -function testFromCsvWithTypeForTupleAndTupleAsExpectedType() { - StringTuple1Array|Error st1st1 = parseListAsListType([st1, st1], {}, StringTuple1Array); - test:assertEquals(st1st1, [ - [s1, s2, "", ""], - [s1, s2, "", ""] - ]); - - StringTuple1Array|Error st2st1 = parseListAsListType([st2, st2], {}, StringTuple1Array); - test:assertEquals(st2st1, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringTuple1Array|Error st3st1 = parseListAsListType([st3, st3], {}, StringTuple1Array); - test:assertEquals(st3st1, [ - [s1, s2, "", ""], - [s1, s2, "", ""] - ]); - - StringTuple1Array|Error st4st1 = parseListAsListType([st4, st4], {}, StringTuple1Array); - test:assertEquals(st4st1, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringTuple2Array|Error st1st2 = parseListAsListType([st1, st1], {}, StringTuple2Array); - test:assertEquals(st1st2, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple2Array|Error st2st2 = parseListAsListType([st2, st2], {}, StringTuple2Array); - test:assertEquals(st2st2, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple2Array|Error st3st2 = parseListAsListType([st3, st3], {}, StringTuple2Array); - test:assertEquals(st3st2, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple2Array|Error st4st2 = parseListAsListType([st4, st4], {}, StringTuple2Array); - test:assertEquals(st4st2, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple3Array|Error st1st3 = parseListAsListType([st1, st1], {}, StringTuple3Array); - test:assertEquals(st1st3, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple3Array|Error st2st3 = parseListAsListType([st2, st2], {}, StringTuple3Array); - test:assertEquals(st2st3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringTuple3Array|Error st3st3 = parseListAsListType([st3, st3], {}, StringTuple3Array); - test:assertEquals(st3st3, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple3Array|Error st4st3 = parseListAsListType([st4, st4], {}, StringTuple3Array); - test:assertEquals(st4st3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringTuple4Array|Error st1st4 = parseListAsListType([st1, st1], {}, StringTuple4Array); - test:assertEquals(st1st4, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple4Array|Error st2st4 = parseListAsListType([st2, st2], {}, StringTuple4Array); - test:assertEquals(st2st4, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringTuple4Array|Error st3st4 = parseListAsListType([st3, st3], {}, StringTuple4Array); - test:assertEquals(st3st4, [ - [s1, s2], - [s1, s2] - ]); - - StringTuple4Array|Error st4st4 = parseListAsListType([st4, st4], {}, StringTuple4Array); - test:assertEquals(st4st4, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - AnydataTuple3Array|Error st1anydt3 = parseListAsListType([st1, st1], {}, AnydataTuple3Array); - test:assertEquals(st1anydt3, [ - [s1, s2], - [s1, s2] - ]); - - AnydataTuple3Array|Error st2anydt3 = parseListAsListType([st2, st2], {}, AnydataTuple3Array); - test:assertEquals(st2anydt3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - AnydataTuple3Array|Error st3anydt3 = parseListAsListType([st3, st3], {}, AnydataTuple3Array); - test:assertEquals(st3anydt3, [ - [s1, s2], - [s1, s2] - ]); - - AnydataTuple3Array|Error st4anydt3 = parseListAsListType([st4, st4], {}, AnydataTuple3Array); - test:assertEquals(st4anydt3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - JsonTuple3Array|Error st1jt3 = parseListAsListType([st1, st1], {}, JsonTuple3Array); - test:assertEquals(st1jt3, [ - [s1, s2], - [s1, s2] - ]); - - JsonTuple3Array|Error st2jt3 = parseListAsListType([st2, st2], {}, JsonTuple3Array); - test:assertEquals(st2jt3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - JsonTuple3Array|Error st3jt3 = parseListAsListType([st3, st3], {}, JsonTuple3Array); - test:assertEquals(st3jt3, [ - [s1, s2], - [s1, s2] - ]); - - JsonTuple3Array|Error st4jt3 = parseListAsListType([st4, st4], {}, JsonTuple3Array); - test:assertEquals(st4jt3, [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - DecimalTuple4Array|Error st1dta = parseListAsListType([st1, st1], {}, DecimalTuple4Array); - test:assertTrue(st1dta is Error); - test:assertEquals((st1dta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); - - IntegerTuple3Array|Error st2bta = parseListAsListType([st2, st2], {}, IntegerTuple3Array); - test:assertTrue(st2bta is Error); - test:assertEquals((st2bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "int")); - - NilTuple3Array|Error st3nta = parseListAsListType([st3, st3], {}, NilTuple3Array); - test:assertTrue(st3nta is Error); - test:assertEquals((st3nta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "()")); - - BooleanTuple4Array|Error st4bta = parseListAsListType([st4, st4], {}, BooleanTuple4Array); - test:assertTrue(st4bta is Error); - test:assertEquals((st4bta).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "boolean")); -} - -@test:Config -function testFromCsvWithTypeForTupleAndTupleAsExpectedType2() { - [string, boolean, int][]|Error ct1bt4 = parseListAsListType([["a", "true", "1"], ["a", "true", "1"]], {}); - test:assertEquals(ct1bt4, [ - ["a", true, 1], - ["a", true, 1] - ]); - - [(), float, decimal, boolean, int, string][]|Error ct1bt6 = parseListAsListType( - [["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][]|Error ct1bt7 = parseListAsListType( - [["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...][]|Error ct1bt8 = parseListAsListType( - [["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...][]|Error ct1bt9 = parseListAsListType( - [["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...][]|Error ct1bt10 = parseListAsListType( - [["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, ()...][]|Error ct1bt11 = parseListAsListType( - [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); - test:assertTrue(ct1bt11 is Error); - //TODO: Fix the message - test:assertEquals((ct1bt11).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "decimal")); - - [(), decimal, float, boolean, ()...][]|Error ct1bt11_2 = parseListAsListType( - [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); - test:assertTrue(ct1bt11_2 is Error); - test:assertEquals((ct1bt11_2).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "()")); - - [()...][]|Error ct1bt12 = parseListAsListType( - [["null", "2.23", "0", "true", "1", "a"], ["null", "0", "2.23", "true", "1", "a"]]); - test:assertTrue(ct1bt12 is Error); - test:assertEquals((ct1bt12).message(), generateErrorMessageForInvalidValueForArrayType("2.23", "1", "()")); - - [string...][]|Error ct1bt13 = parseListAsListType( - [["1", "a"], ["1", "a"]]); - test:assertEquals(ct1bt13, [ - ["1", "a"], - ["1", "a"] - ]); - - [boolean...][]|Error ct1bt14 = parseListAsListType( - [["2.23", "null"], ["7", "()"]]); - test:assertTrue(ct1bt14 is Error); - test:assertEquals((ct1bt14).message(), generateErrorMessageForInvalidValueForArrayType("2.23", "0", "boolean")); - - int?[][]|Error ct1bt15 = parseListAsListType( - [["1", "()"], ["1", "2"]]); - test:assertEquals(ct1bt15, [ - [1, ()], - [1, 2] - ]); - - int[][]|Error ct1bt16 = parseListAsListType( - [["1", "2"], ["1", "()"]]); - test:assertTrue(ct1bt16 is Error); - test:assertEquals((ct1bt16).message(), generateErrorMessageForInvalidValueForArrayType("()", "1", "int")); - - int[][]|Error ct1bt17 = parseListAsListType( - [["a", "b"], ["a", "b"]]); - test:assertTrue(ct1bt17 is Error); - test:assertEquals((ct1bt17).message(), generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); -} - - -@test:Config -function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { - StringArrayArray|Error st1saa = parseListAsListType([st1, st1], {}, StringArrayArray); - test:assertEquals(st1saa , [ - [s1, s2], - [s1, s2] - ]); - - StringArrayArray|Error st2saa = parseListAsListType([st2, st2], {}, StringArrayArray); - test:assertEquals(st2saa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringArrayArray|Error st3saa = parseListAsListType([st3, st3], {}, StringArrayArray); - test:assertEquals(st3saa , [ - [s1, s2], - [s1, s2] - ]); - - StringArrayArray|Error st4saa = parseListAsListType([st4, st4], {}, StringArrayArray); - test:assertEquals(st4saa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - NillableStringArrayArray|Error st1nsaa = parseListAsListType([st1, st1], {}, NillableStringArrayArray); - test:assertEquals(st1nsaa , [ - [s1, s2], - [s1, s2] - ]); - - NillableStringArrayArray|Error st2nsaa = parseListAsListType([st2, st2], {}, NillableStringArrayArray); - test:assertEquals(st2nsaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - NillableStringArrayArray|Error st3nsaa = parseListAsListType([st3, st3], {}, NillableStringArrayArray); - test:assertEquals(st3nsaa , [ - [s1, s2], - [s1, s2] - ]); - - NillableStringArrayArray|Error st4nsaa = parseListAsListType([st4, st4], {}, NillableStringArrayArray); - test:assertEquals(st4nsaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - NillableIntOrUnionStringArrayArray|Error st1nsuiaa = parseListAsListType([st1, st1], {}, NillableIntOrUnionStringArrayArray); - test:assertEquals(st1nsuiaa , [ - [s1, s2], - [s1, s2] - ]); - - NillableIntOrUnionStringArrayArray|Error st2nsuiaa = parseListAsListType([st2, st2], {}, NillableIntOrUnionStringArrayArray); - test:assertEquals(st2nsuiaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - NillableIntOrUnionStringArrayArray|Error st3nsuiaa = parseListAsListType([st3, st3], {}, NillableIntOrUnionStringArrayArray); - test:assertEquals(st3nsuiaa , [ - [s1, s2], - [s1, s2] - ]); - - NillableIntOrUnionStringArrayArray|Error st4nsuiaa = parseListAsListType([st4, st4], {}, NillableIntOrUnionStringArrayArray); - test:assertEquals(st4nsuiaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - StringArray2Array|Error st1saa2 = parseListAsListType([st1, st1], {}, StringArray2Array); - test:assertEquals(st1saa2 , [ - [s1, s2], - [s1, s2] - ]); - - StringArray2Array|Error st2saa2 = parseListAsListType([st2, st2], {}, StringArray2Array); - test:assertEquals(st2saa2 , [ - [s1, s2], - [s1, s2] - ]); - - StringArray2Array|Error st3saa2 = parseListAsListType([st3, st3], {}, StringArray2Array); - test:assertEquals(st3saa2 , [ - [s1, s2], - [s1, s2] - ]); - - StringArray2Array|Error st4saa2 = parseListAsListType([st4, st4], {}, StringArray2Array); - test:assertEquals(st4saa2 , [ - [s1, s2], - [s1, s2] - ]); - - JsonArray1Array|Error st1jaa = parseListAsListType([st1, st1], {}, JsonArray1Array); - test:assertEquals(st1jaa , [ - [s1, s2], - [s1, s2] - ]); - - JsonArray1Array|Error st2jaa = parseListAsListType([st2, st2], {}, JsonArray1Array); - test:assertEquals(st2jaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - JsonArray1Array|Error st3jaa = parseListAsListType([st3, st3], {}, JsonArray1Array); - test:assertEquals(st3jaa , [ - [s1, s2], - [s1, s2] - ]); - - JsonArray1Array|Error st4jaa = parseListAsListType([st4, st4], {}, JsonArray1Array); - test:assertEquals(st4jaa , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - AnydataArray1Array|Error st1anyda = parseListAsListType([st1, st1], {}, AnydataArray1Array); - test:assertEquals(st1anyda , [ - [s1, s2], - [s1, s2] - ]); - - AnydataArray1Array|Error st2anyda = parseListAsListType([st2, st2], {}, AnydataArray1Array); - test:assertEquals(st2anyda , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - AnydataArray1Array|Error st3anyda = parseListAsListType([st3, st3], {}, AnydataArray1Array); - test:assertEquals(st3anyda , [ - [s1, s2], - [s1, s2] - ]); - - AnydataArray1Array|Error st4anyda = parseListAsListType([st4, st4], {}, AnydataArray1Array); - test:assertEquals(st4anyda , [ - [s1, s2, s3, s2], - [s1, s2, s3, s2] - ]); - - DecimalArray1Array|Error st1dda = parseListAsListType([st1, st1], {}, DecimalArray1Array); - test:assertTrue(st1dda is Error); - test:assertEquals((st1dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); - - DecimalArray1Array|Error st3dda = parseListAsListType([st3, st3], {}, DecimalArray1Array); - test:assertTrue(st3dda is Error); - test:assertEquals((st3dda).message(), generateErrorMessageForInvalidValueForArrayType("string", "0", "decimal")); -} diff --git a/ballerina/tests/parse_list_type_as_record_test.bal b/ballerina/tests/parse_list_type_as_record_test.bal deleted file mode 100644 index 0fc21ab..0000000 --- a/ballerina/tests/parse_list_type_as_record_test.bal +++ /dev/null @@ -1,748 +0,0 @@ -import ballerina/test; - -@test:Config -function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { - StringRecord1Array|Error st1sr1 = parseListAsRecordType([st1, st1], (), {}, StringRecord1Array); - test:assertTrue(st1sr1 is Error); - test:assertEquals((st1sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - - StringRecord1Array|Error st2sr1 = parseListAsRecordType([st2, st2], (), {}, StringRecord1Array); - test:assertTrue(st2sr1 is Error); - test:assertEquals((st2sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - - StringRecord2Array|Error st1sr2 = parseListAsRecordType([st1, st1], (), {}, StringRecord2Array); - test:assertTrue(st1sr2 is Error); - test:assertEquals((st1sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); - - StringRecord2Array|Error st2sr2 = parseListAsRecordType([st2, st2], (), {}, StringRecord2Array); - test:assertTrue(st2sr2 is Error); - test:assertEquals((st2sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); - - StringRecord9Array|Error st1sr9 = parseListAsRecordType([st1, st1], (), {}, StringRecord9Array); - test:assertTrue(st1sr9 is Error); - test:assertEquals((st1sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord9")); - - StringRecord9Array|Error st2sr9 = parseListAsRecordType([st2, st2], (), {}, StringRecord9Array); - test:assertTrue(st2sr9 is Error); - test:assertEquals((st2sr9).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord9")); - - StringRecord10Array|Error st1sr10 = parseListAsRecordType([st1, st1], (), {}, StringRecord10Array); - test:assertEquals(st1sr10, [ - {'1: "string", '2: ""}, - {'1: "string", '2: ""} - ]); - - StringRecord10Array|Error st2sr10 = parseListAsRecordType([st2, st2], (), {}, StringRecord10Array); - test:assertEquals(st2sr10, [ - {'1: "string", '2: "", '3: "a", '4: ""}, - {'1: "string", '2: "", '3: "a", '4: ""} - ]); - - StringRecord19Array|Error st1sr19 = parseListAsRecordType([st1, st1], (), {}, StringRecord19Array); - test:assertEquals(st1sr19, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord19Array|Error st2sr19 = parseListAsRecordType([st2, st2], (), {}, StringRecord19Array); - test:assertEquals(st2sr19, [ - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord20Array|Error st1sr20 = parseListAsRecordType([st1, st1], (), {}, StringRecord20Array); - test:assertEquals(st1sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord20Array|Error st2sr20 = parseListAsRecordType([st2, st2], (), {}, StringRecord20Array); - test:assertEquals(st2sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord21Array|Error st1sr21 = parseListAsRecordType([st1, st1], (), {}, StringRecord21Array); - test:assertEquals(st1sr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord21Array|Error st2sr21 = parseListAsRecordType([st2, st2], (), {}, StringRecord21Array); - test:assertEquals(st2sr21, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord22Array|Error st1sr22 = parseListAsRecordType([st1, st1], (), {}, StringRecord22Array); - test:assertEquals(st1sr22, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord22Array|Error st2sr22 = parseListAsRecordType([st2, st2], (), {}, StringRecord22Array); - test:assertEquals(st2sr22, [ - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord23Array|Error st1sr23 = parseListAsRecordType([st1, st1], (), {}, StringRecord23Array); - test:assertEquals(st1sr23, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord23Array|Error st2sr23 = parseListAsRecordType([st2, st2], (), {}, StringRecord23Array); - test:assertEquals(st2sr23, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord15Array|Error st1cr15 = parseListAsRecordType([st1, st1], (), {}, CustomRecord15Array); - test:assertEquals(st1cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord15Array|Error st2cr15 = parseListAsRecordType([st2, st2], (), {}, CustomRecord15Array); - test:assertEquals(st2cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord16Array|Error st1cr16 = parseListAsRecordType([st1, st1], (), {}, CustomRecord16Array); - test:assertTrue(st1cr16 is Error); - test:assertEquals((st1cr16).message(), generateErrorMessageForMissingRequiredField("3")); - - CustomRecord16Array|Error st2cr16 = parseListAsRecordType([st2, st2], (), {}, CustomRecord16Array); - test:assertEquals(st2cr16, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord17Array|Error st1cr17 = parseListAsRecordType([st1, st1], (), {}, CustomRecord17Array); - test:assertEquals(st1cr17, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord17Array|Error st2cr17 = parseListAsRecordType([st2, st2], (), {}, CustomRecord17Array); - test:assertEquals(st2cr17, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord18Array|Error st1cr18 = parseListAsRecordType([st1, st1], (), {}, CustomRecord18Array); - test:assertTrue(st1cr18 is Error); - test:assertEquals((st1cr18).message(), generateErrorMessageForMissingRequiredField("3")); - - CustomRecord18Array|Error st2cr18 = parseListAsRecordType([st2, st2], (), {}, CustomRecord18Array); - test:assertEquals(st2cr18, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord19Array|Error st1cr19 = parseListAsRecordType([st1, st1], (), {}, CustomRecord19Array); - test:assertEquals(st1cr19, [ - {'1: s1, '2: s2, '3: "", '4: ""}, - {'1: s1, '2: s2, '3: "", '4: ""} - ]); - - CustomRecord19Array|Error st2cr19 = parseListAsRecordType([st2, st2], (), {}, CustomRecord19Array); - test:assertEquals(st2cr19, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord20Array|Error st1cr20 = parseListAsRecordType([st1, st1], (), {}, CustomRecord20Array); - test:assertEquals(st1cr20, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord20Array|Error st2cr20 = parseListAsRecordType([st2, st2], (), {}, CustomRecord20Array); - test:assertEquals(st2cr20, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord21Array|Error st1cr21 = parseListAsRecordType([st1, st1], (), {}, CustomRecord21Array); - test:assertEquals(st1cr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord21Array|Error st2cr21 = parseListAsRecordType([st2, st2], (), {}, CustomRecord21Array); - test:assertEquals(st2cr21, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord22Array|Error st1cr22 = parseListAsRecordType([st1, st1], (), {}, CustomRecord22Array); - test:assertEquals(st1cr22, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord22Array|Error st2cr22 = parseListAsRecordType([st2, st2], (), {}, CustomRecord22Array); - test:assertEquals(st2cr22, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord23Array|Error st1cr23 = parseListAsRecordType([st1, st1], (), {}, CustomRecord23Array); - test:assertEquals(st1cr23, [ - {"1": s1, "2": s2, a: ""}, - {"1": s1, "2": s2, a: ""} - ]); - - CustomRecord23Array|Error st2cr23 = parseListAsRecordType([st2, st2], (), {}, CustomRecord23Array); - test:assertEquals(st2cr23, [ - {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, - {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} - ]); - - CustomRecord24Array|Error st1cr24 = parseListAsRecordType([st1, st1], (), {}, CustomRecord24Array); - test:assertEquals(st1cr24, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord24Array|Error st2cr24 = parseListAsRecordType([st2, st2], (), {}, CustomRecord24Array); - test:assertEquals(st2cr24, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord25Array|Error st1cr25 = parseListAsRecordType([st1, st1], (), {}, CustomRecord25Array); - test:assertTrue(st1cr25 is Error); - test:assertEquals((st1cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); - - CustomRecord25Array|Error st2cr25 = parseListAsRecordType([st2, st2], (), {}, CustomRecord25Array); - test:assertTrue(st2cr25 is Error); - test:assertEquals((st2cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); - - CustomRecord25Array|Error st3cr25 = parseListAsRecordType([st3, st3], (), {}, CustomRecord25Array); - test:assertTrue(st3cr25 is Error); - test:assertEquals((st3cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); - - CustomRecord25Array|Error st4cr25 = parseListAsRecordType([st4, st4], (), {}, CustomRecord25Array); - test:assertTrue(st4cr25 is Error); - test:assertEquals((st4cr25).message(), generateErrorMessageForInvalidFieldType("string", "1")); - - CustomRecord26Array|Error st1cr26 = parseListAsRecordType([st1, st1], (), {}, CustomRecord26Array); - test:assertEquals(st1cr26 , [ - {'1: s1}, - {'1: s1} - ]); - - CustomRecord26Array|Error st2cr26 = parseListAsRecordType([st2, st2], (), {}, CustomRecord26Array); - test:assertEquals(st2cr26 , [ - {'1: s1}, - {'1: s1} - ]); - - CustomRecord26Array|Error st3cr26 = parseListAsRecordType([st3, st3], (), {}, CustomRecord26Array); - test:assertEquals(st3cr26 , [ - {'1: s1}, - {'1: s1} - ]); - - CustomRecord26Array|Error st4cr26 = parseListAsRecordType([st4, st4], (), {}, CustomRecord26Array); - test:assertEquals(st4cr26 , [ - {'1: s1}, - {'1: s1} - ]); -} - -@test:Config -function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { - StringRecord1Array|Error st3sr1 = parseListAsRecordType([st3, st3], (), {}, StringRecord1Array); - test:assertTrue(st3sr1 is Error); - test:assertEquals((st3sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - - StringRecord1Array|Error st4sr1 = parseListAsRecordType([st4, st4], (), {}, StringRecord1Array); - test:assertTrue(st4sr1 is Error); - test:assertEquals((st4sr1).message(), generateErrorMessageForMissingRequiredField("s3")); - - StringRecord2Array|Error st3sr2 = parseListAsRecordType([st3, st3], (), {}, StringRecord2Array); - test:assertTrue(st3sr2 is Error); - test:assertEquals((st3sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "data.csv:StringRecord2")); - - StringRecord2Array|Error st4sr2 = parseListAsRecordType([st4, st4], (), {}, StringRecord2Array); - test:assertTrue(st4sr2 is Error); - test:assertEquals((st4sr2).message(), generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","data.csv:StringRecord2")); - - StringRecord9Array|Error st3sr9 = parseListAsRecordType([st3, st3], (), {}, StringRecord9Array); - test:assertTrue(st3sr9 is Error); - test:assertEquals((st3sr9).message(), generateErrorMessageForMissingRequiredField("s1")); - - StringRecord9Array|Error st4sr9 = parseListAsRecordType([st4, st4], (), {}, StringRecord9Array); - test:assertTrue(st4sr9 is Error); - test:assertEquals((st4sr9).message(), generateErrorMessageForMissingRequiredField("s1")); - - StringRecord10Array|Error st3sr10 = parseListAsRecordType([st3, st3], (), {}, StringRecord10Array); - test:assertEquals(st3sr10, [ - {'1: "string", '2: ""}, - {'1: "string", '2: ""} - ]); - - StringRecord10Array|Error st4sr10 = parseListAsRecordType([st4, st4], (), {}, StringRecord10Array); - test:assertEquals(st4sr10, [ - {'1: "string", '2: "", '3: "a", '4: ""}, - {'1: "string", '2: "", '3: "a", '4: ""} - ]); - - StringRecord19Array|Error st3sr19 = parseListAsRecordType([st3, st3], (), {}, StringRecord19Array); - test:assertEquals(st3sr19, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord19Array|Error st4sr19 = parseListAsRecordType([st4, st4], (), {}, StringRecord19Array); - test:assertEquals(st4sr19, [ - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord20Array|Error st3sr20 = parseListAsRecordType([st3, st3], (), {}, StringRecord20Array); - test:assertEquals(st3sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord20Array|Error st4sr20 = parseListAsRecordType([st4, st4], (), {}, StringRecord20Array); - test:assertEquals(st4sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord21Array|Error st3sr21 = parseListAsRecordType([st3, st3], (), {}, StringRecord21Array); - test:assertEquals(st3sr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord21Array|Error st4sr21 = parseListAsRecordType([st4, st4], (), {}, StringRecord21Array); - test:assertEquals(st4sr21, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord22Array|Error st3sr22 = parseListAsRecordType([st3, st3], (), {}, StringRecord22Array); - test:assertEquals(st3sr22, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord22Array|Error st4sr22 = parseListAsRecordType([st4, st4], (), {}, StringRecord22Array); - test:assertEquals(st4sr22, [ - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2}, - {s1: "", s2: "", '1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringRecord23Array|Error st3sr23 = parseListAsRecordType([st3, st3], (), {}, StringRecord23Array); - test:assertEquals(st3sr23, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord23Array|Error st4sr23 = parseListAsRecordType([st4, st4], (), {}, StringRecord23Array); - test:assertEquals(st4sr23, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord15Array|Error st3cr15 = parseListAsRecordType([st3, st3], (), {}, CustomRecord15Array); - test:assertEquals(st3cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord15Array|Error st4cr15 = parseListAsRecordType([st4, st4], (), {}, CustomRecord15Array); - test:assertEquals(st4cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord16Array|Error st3cr16 = parseListAsRecordType([st3, st3], (), {}, CustomRecord16Array); - test:assertTrue(st3cr16 is Error); - test:assertEquals((st3cr16).message(), generateErrorMessageForMissingRequiredField("3")); - - CustomRecord16Array|Error st4cr16 = parseListAsRecordType([st4, st4], (), {}, CustomRecord16Array); - test:assertEquals(st4cr16, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord17Array|Error st3cr17 = parseListAsRecordType([st3, st3], (), {}, CustomRecord17Array); - test:assertEquals(st3cr17, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord17Array|Error st4cr17 = parseListAsRecordType([st4, st4], (), {}, CustomRecord17Array); - test:assertEquals(st4cr17, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord18Array|Error st3cr18 = parseListAsRecordType([st3, st3], (), {}, CustomRecord18Array); - test:assertTrue(st3cr18 is Error); - test:assertEquals((st3cr18).message(), generateErrorMessageForMissingRequiredField("3")); - - CustomRecord18Array|Error st4cr18 = parseListAsRecordType([st4, st4], (), {}, CustomRecord18Array); - test:assertEquals(st4cr18, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord19Array|Error st3cr19 = parseListAsRecordType([st3, st3], (), {}, CustomRecord19Array); - test:assertEquals(st3cr19, [ - {'1: s1, '2: s2, '3: "", '4: ""}, - {'1: s1, '2: s2, '3: "", '4: ""} - ]); - - CustomRecord19Array|Error st4cr19 = parseListAsRecordType([st4, st4], (), {}, CustomRecord19Array); - test:assertEquals(st4cr19, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord20Array|Error st3cr20 = parseListAsRecordType([st3, st3], (), {}, CustomRecord20Array); - test:assertEquals(st3cr20, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord20Array|Error st4cr20 = parseListAsRecordType([st4, st4], (), {}, CustomRecord20Array); - test:assertEquals(st4cr20, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord21Array|Error st3cr21 = parseListAsRecordType([st3, st3], (), {}, CustomRecord21Array); - test:assertEquals(st3cr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord21Array|Error st4cr21 = parseListAsRecordType([st4, st4], (), {}, CustomRecord21Array); - test:assertEquals(st4cr21, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord22Array|Error st3cr22 = parseListAsRecordType([st3, st3], (), {}, CustomRecord22Array); - test:assertEquals(st3cr22, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord22Array|Error st4cr22 = parseListAsRecordType([st4, st4], (), {}, CustomRecord22Array); - test:assertEquals(st4cr22, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomRecord23Array|Error st3cr23 = parseListAsRecordType([st3, st3], (), {}, CustomRecord23Array); - test:assertEquals(st3cr23, [ - {"1": s1, "2": s2, a: ""}, - {"1": s1, "2": s2, a: ""} - ]); - - CustomRecord23Array|Error st4cr23 = parseListAsRecordType([st4, st4], (), {}, CustomRecord23Array); - test:assertEquals(st4cr23, [ - {'1: s1, '2: s2, '3: s3, '4: s2, a: ""}, - {'1: s1, '2: s2, '3: s3, '4: s2, a: ""} - ]); - - CustomRecord24Array|Error st3cr24 = parseListAsRecordType([st3, st3], (), {}, CustomRecord24Array); - test:assertEquals(st3cr24, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord24Array|Error st4cr24 = parseListAsRecordType([st4, st4], (), {}, CustomRecord24Array); - test:assertEquals(st4cr24, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); -} - -@test:Config -function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { - record{string a; boolean b; int c;}[]|Error ct1br4 = parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["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;}[]|Error ct1br6 = parseListAsRecordType( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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;|}[]|Error ct1br7 = parseListAsRecordType( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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;}[]|Error ct1br8 = parseListAsRecordType( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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...;|}[]|Error ct1br9 = parseListAsRecordType( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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...;|}[]|Error ct1br9_2 = parseListAsRecordType( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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"} - ]); - - record{|decimal c; boolean|string d; int e; string f; string...;|}[]|Error ct1br10 = parseListAsRecordType( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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; ()...;|}[]|Error ct1br11 = parseListAsRecordType( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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{|()...;|}[]|Error ct1br12 = parseListAsRecordType( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["f", "e", "d", "c", "b", "a"]); - test:assertEquals(ct1br12, [ - {a: ()}, - {a: ()} - ]); - - record{|string?...;|}[]|Error ct1br13 = parseListAsRecordType( - [["a", "1"], ["a", "1"]], - ["f", "e"]); - test:assertEquals(ct1br13, [ - {e: "1", f: "a"}, - {e: "1", f: "a"} - ]); - - record{|boolean...;|}[]|Error ct1br14 = parseListAsRecordType( - [["2.23", "null"], ["7", "()"]], - ["b", "a"]); - test:assertEquals(ct1br14, [ - {}, - {} - ]); - - map[]|Error ct1br15 = parseListAsRecordType( - [["2", "()"], ["2", "1"], ["()", "2"]], - ["f", "e"]); - test:assertEquals(ct1br15, [ - {e: (), f: 2}, - {e: 1, f: 2}, - {e: 2, f: ()} - ]); - - record{|boolean...;|}[]|Error ct1br16 = parseListAsRecordType( - [["2.23", "null"], ["7", "()"]], - ["b", "a"]); - test:assertEquals(ct1br16, [ - {}, - {} - ]); -} - -@test:Config -function testFromCsvWithTypeForTupleAndMapAsExpectedType() { - StringMapArray|Error st1sma = parseListAsRecordType([st1, st1], (), {}, StringMapArray); - test:assertEquals(st1sma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - StringMapArray|Error st2sma = parseListAsRecordType([st2, st2], (), {}, StringMapArray); - test:assertEquals(st2sma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - StringMapArray|Error st3sma = parseListAsRecordType([st3, st3], (), {}, StringMapArray); - test:assertEquals(st3sma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - StringMapArray|Error st4sma = parseListAsRecordType([st4, st4], (), {}, StringMapArray); - test:assertEquals(st4sma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - NillableIntUnionStringMapArray|Error st1niusma = parseListAsRecordType([st1, st1], (), {}, NillableIntUnionStringMapArray); - test:assertEquals(st1niusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - NillableIntUnionStringMapArray|Error st2niusma = parseListAsRecordType([st2, st2], (), {}, NillableIntUnionStringMapArray); - test:assertEquals(st2niusma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - NillableIntUnionStringMapArray|Error st3niusma = parseListAsRecordType([st3, st3], (), {}, NillableIntUnionStringMapArray); - test:assertEquals(st3niusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - NillableIntUnionStringMapArray|Error st4niusma = parseListAsRecordType([st4, st4], (), {}, NillableIntUnionStringMapArray); - test:assertEquals(st4niusma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - IntUnionStringMapArray|Error st1iusma = parseListAsRecordType([st1, st1], (), {}, IntUnionStringMapArray); - test:assertEquals(st1iusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - IntUnionStringMapArray|Error st2iusma = parseListAsRecordType([st2, st2], (), {}, IntUnionStringMapArray); - test:assertEquals(st2iusma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - IntUnionStringMapArray|Error st3iusma = parseListAsRecordType([st3, st3], (), {}, IntUnionStringMapArray); - test:assertEquals(st3iusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - IntUnionStringMapArray|Error st4iusma = parseListAsRecordType([st4, st4], (), {}, IntUnionStringMapArray); - test:assertEquals(st4iusma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - JsonMapArray|Error st1jma = parseListAsRecordType([st1, st1], (), {}, JsonMapArray); - test:assertEquals(st1jma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - JsonMapArray|Error st2jma = parseListAsRecordType([st2, st2], (), {}, JsonMapArray); - test:assertEquals(st2jma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - JsonMapArray|Error st3jma = parseListAsRecordType([st3, st3], (), {}, JsonMapArray); - test:assertEquals(st3jma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - JsonMapArray|Error st4jma = parseListAsRecordType([st4, st4], (), {}, JsonMapArray); - test:assertEquals(st4jma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - AnydataMapArray|Error st1anydma = parseListAsRecordType([st1, st1], (), {}, AnydataMapArray); - test:assertEquals(st1anydma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - AnydataMapArray|Error st2anydma = parseListAsRecordType([st2, st2], (), {}, AnydataMapArray); - test:assertEquals(st2anydma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - AnydataMapArray|Error st3anydma = parseListAsRecordType([st3, st3], (), {}, AnydataMapArray); - test:assertEquals(st3anydma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - AnydataMapArray|Error st4anydma = parseListAsRecordType([st4, st4], (), {}, AnydataMapArray); - test:assertEquals(st4anydma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomMapArray|Error st1cma = parseListAsRecordType([st1, st1], (), {}, CustomMapArray); - test:assertEquals(st1cma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - CustomMapArray|Error st2cma = parseListAsRecordType([st2, st2], (), {}, CustomMapArray); - test:assertEquals(st2cma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - CustomMapArray|Error st3cma = parseListAsRecordType([st3, st3], (), {}, CustomMapArray); - test:assertEquals(st3cma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - CustomMapArray|Error st4cma = parseListAsRecordType([st4, st4], (), {}, CustomMapArray); - test:assertEquals(st4cma , [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); - - NilMapArray|Error st1nma = parseListAsRecordType([st1, st1], (), {}, NilMapArray); - test:assertEquals(st1nma, ([ - {}, - {} - ])); - - IntegerMapArray|Error st2ima = parseListAsRecordType([st2, st2], (), {}, IntegerMapArray); - test:assertEquals(st2ima, ([ - {}, - {} - ])); - - DecimalMapArray|Error st3dma = parseListAsRecordType([st3, st3], (), {}, DecimalMapArray); - test:assertEquals(st3dma, ([ - {}, - {} - ])); - - BooleanMapArray|Error st4bma = parseListAsRecordType([st4, st4], (), {}, BooleanMapArray); - test:assertEquals(st4bma, ([ - {}, - {} - ])); -} diff --git a/ballerina/tests/parse_record_type_as_list_test.bal b/ballerina/tests/parse_record_type_as_list_test.bal deleted file mode 100644 index 4bfa6dc..0000000 --- a/ballerina/tests/parse_record_type_as_list_test.bal +++ /dev/null @@ -1,532 +0,0 @@ -import ballerina/test; - -@test:Config -function testFromCsvWithTypeForMapAndArrayAsExpectedType() { - BooleanArrayArray|Error bm1ba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanArrayArray); - test:assertEquals(bm1ba, [ - [true, false], - [true, false] - ]); - - bm1ba = parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}, BooleanArrayArray); - test:assertEquals(bm1ba, [ - [false, true], - [false, true] - ]); - - BooleanArrayArray|Error bm2ba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanArrayArray); - test:assertTrue(bm2ba is Error); - test:assertEquals((bm2ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanArrayArray|Error bm3ba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanArrayArray); - test:assertTrue(bm3ba is Error); - test:assertEquals((bm3ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanArrayArray|Error bm4ba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanArrayArray); - test:assertTrue(bm4ba is Error); - test:assertEquals((bm4ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - - BooleanArrayArray|Error bm5ba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanArrayArray); - test:assertTrue(bm5ba is Error); - test:assertEquals((bm5ba).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - NillableBooleanArrayArray|Error bm1nba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanArrayArray); - test:assertEquals(bm1nba, [ - [true, false], - [true, false] - ]); - - NillableBooleanArrayArray|Error bm2nba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanArrayArray); - test:assertEquals(bm2nba, [ - [true, false, null, null, null], - [true, false, null, null, null] - ]); - - NillableBooleanArrayArray|Error bm3nba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanArrayArray); - test:assertTrue(bm3nba is Error); - test:assertEquals((bm3nba).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - - NillableBooleanArrayArray|Error bm4nba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanArrayArray); - test:assertEquals(bm4nba, [ - [(), ()], - [(), ()] - ]); - - NillableBooleanArrayArray|Error bm5nba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanArrayArray); - test:assertEquals(bm5nba, [ - [true, false, (), true], - [true, false, (), true] - ]); - - bm5nba = parseRecordAsListType([bm5, bm5], ["b1", "b3", "b2", "b4"], {}, NillableBooleanArrayArray); - test:assertEquals(bm5nba, [ - [true, (), false, true], - [true, (), false, true] - ]); - - bm5nba = parseRecordAsListType([bm5, bm5], ["b4", "b3", "b2", "b1"], {}, NillableBooleanArrayArray); - test:assertEquals(bm5nba, [ - [true, (), false, true], - [true, (), false, true] - ]); - - NillableIntOrUnionBooleanArrayArray|Error bm1niouba = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableIntOrUnionBooleanArrayArray); - test:assertEquals(bm1niouba, [ - [true, false], - [true, false] - ]); - - NillableIntOrUnionBooleanArrayArray|Error bm2niouba = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); - test:assertEquals(bm2niouba, [ - [true, false, null, null, null], - [true, false, null, null, null] - ]); - - NillableIntOrUnionBooleanArrayArray|Error bm3niouba = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableIntOrUnionBooleanArrayArray); - test:assertEquals(bm3niouba, [ - [true, false, null, false, 1], - [true, false, null, false, 1] - ]); - - NillableIntOrUnionBooleanArrayArray|Error bm4niouba = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntOrUnionBooleanArrayArray); - test:assertEquals(bm4niouba, [ - [(), ()], - [(), ()] - ]); - - NillableIntOrUnionBooleanArrayArray|Error bm5niouba = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableIntOrUnionBooleanArrayArray); - test:assertEquals(bm5niouba, [ - [true, false, (), true], - [true, false, (), true] - ]); - - JsonArray1Array|Error bm1ja = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, JsonArray1Array); - test:assertEquals(bm1ja, [ - [true, false], - [true, false] - ]); - - JsonArray1Array|Error bm2ja = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, JsonArray1Array); - test:assertEquals(bm2ja, [ - [true, false, null, null, null], - [true, false, null, null, null] - ]); - - JsonArray1Array|Error bm3ja = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, JsonArray1Array); - test:assertEquals(bm3ja, [ - [true, false, null, false, 1], - [true, false, null, false, 1] - ]); - - JsonArray1Array|Error bm4ja = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonArray1Array); - test:assertEquals(bm4ja, [ - [(), ()], - [(), ()] - ]); - - JsonArray1Array|Error bm5ja = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, JsonArray1Array); - test:assertEquals(bm5ja, [ - [true, false, (), true], - [true, false, (), true] - ]); - - AnydataArray1Array|Error bm1anyda = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataArray1Array); - test:assertEquals(bm1anyda, [ - [true, false], - [true, false] - ]); - - AnydataArray1Array|Error bm2anyda = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, AnydataArray1Array); - test:assertEquals(bm2anyda, [ - [true, false, null, null, null], - [true, false, null, null, null] - ]); - - AnydataArray1Array|Error bm3anyda = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, AnydataArray1Array); - test:assertEquals(bm3anyda, [ - [true, false, null, false, 1], - [true, false, null, false, 1] - ]); - - AnydataArray1Array|Error bm4anyda = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataArray1Array); - test:assertEquals(bm4anyda, [ - [(), ()], - [(), ()] - ]); - - AnydataArray1Array|Error bm5anyda = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, AnydataArray1Array); - test:assertEquals(bm5anyda, [ - [true, false, (), true], - [true, false, (), true] - ]); - - StringArray1Array|Error bm1sa = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, StringArray1Array); - test:assertTrue(bm1sa is Error); - test:assertEquals((bm1sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringArray1Array|Error bm2sa = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, StringArray1Array); - test:assertTrue(bm2sa is Error); - test:assertEquals((bm2sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringArray1Array|Error bm3sa = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, StringArray1Array); - test:assertTrue(bm3sa is Error); - test:assertEquals((bm3sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringArray1Array|Error bm4sa = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, StringArray1Array); - test:assertTrue(bm4sa is Error); - test:assertEquals((bm4sa).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - - StringArray1Array|Error bm5sa = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, StringArray1Array); - test:assertTrue(bm5sa is Error); - test:assertEquals((bm5sa).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); -} - -@test:Config -function testFromCsvWithTypeForMapAndTupleAsExpectedType() { - BooleanTuple1Array|Error bm1bt = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple1Array); - test:assertEquals(bm1bt, [ - [true, false, false, false], - [true, false, false, false] - ]); - - BooleanTuple1Array|Error bm2bt = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple1Array); - test:assertTrue(bm2bt is Error); - test:assertEquals((bm2bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple1Array|Error bm3bt = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple1Array); - test:assertTrue(bm3bt is Error); - test:assertEquals((bm3bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple1Array|Error bm4bt = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple1Array); - test:assertTrue(bm4bt is Error); - test:assertEquals((bm4bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - - BooleanTuple1Array|Error bm5bt = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple1Array); - test:assertTrue(bm5bt is Error); - test:assertEquals((bm5bt).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple2Array|Error bm1b2t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple2Array); - test:assertEquals(bm1b2t, [ - [true, false], - [true, false] - ]); - - BooleanTuple2Array|Error bm2b2t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple2Array); - test:assertEquals(bm2b2t, [ - [true, false], - [true, false] - ]); - - BooleanTuple2Array|Error bm3b2t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple2Array); - test:assertEquals(bm3b2t, [ - [true, false], - [true, false] - ]); - - BooleanTuple2Array|Error bm4b2t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple2Array); - test:assertTrue(bm4b2t is Error); - test:assertEquals((bm4b2t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - - BooleanTuple2Array|Error bm5b2t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple2Array); - test:assertEquals(bm5b2t, [ - [true, false], - [true, false] - ]); - - BooleanTuple3Array|Error bm1b3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple3Array); - test:assertEquals(bm1b3t, [ - [true, false], - [true, false] - ]); - - BooleanTuple3Array|Error bm2b3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple3Array); - test:assertTrue(bm2b3t is Error); - test:assertEquals((bm2b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple3Array|Error bm3b3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple3Array); - test:assertTrue(bm3b3t is Error); - test:assertEquals((bm3b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple3Array|Error bm4b3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple3Array); - test:assertTrue(bm4b3t is Error); - test:assertEquals((bm4b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - - BooleanTuple3Array|Error bm5b3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple3Array); - test:assertTrue(bm5b3t is Error); - test:assertEquals((bm5b3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple4Array|Error bm1b4t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, BooleanTuple4Array); - test:assertEquals(bm1b4t, [ - [true, false], - [true, false] - ]); - - BooleanTuple4Array|Error bm2b4t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, BooleanTuple4Array); - test:assertTrue(bm2b4t is Error); - test:assertEquals((bm2b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple4Array|Error bm3b4t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, BooleanTuple4Array); - test:assertTrue(bm3b4t is Error); - test:assertEquals((bm3b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - BooleanTuple4Array|Error bm4b4t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, BooleanTuple4Array); - test:assertTrue(bm4b4t is Error); - test:assertEquals((bm4b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - - BooleanTuple4Array|Error bm5b4t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, BooleanTuple4Array); - test:assertTrue(bm5b4t is Error); - test:assertEquals((bm5b4t).message(), generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - - NillableBooleanTuple5Array|Error bm1nbt = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple5Array); - test:assertEquals(bm1nbt, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - NillableBooleanTuple5Array|Error bm2nbt = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple5Array); - test:assertEquals(bm2nbt, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - NillableBooleanTuple5Array|Error bm3nbt = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple5Array); - test:assertTrue(bm3nbt is Error); - test:assertEquals((bm3nbt).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - - NillableBooleanTuple5Array|Error bm4nbt = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple5Array); - test:assertEquals(bm4nbt, [ - [(), (), (), (), ()], - [(), (), (), (), ()] - ]); - - NillableBooleanTuple5Array|Error bm5nbt = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple5Array); - test:assertEquals(bm5nbt, [ - [true, false, (), true, ()], - [true, false, (), true, ()] - ]); - - NillableBooleanTuple6Array|Error bm1nb6t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple6Array); - test:assertEquals(bm1nb6t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple6Array|Error bm2nb6t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple6Array); - test:assertEquals(bm2nb6t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple6Array|Error bm3nb6t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple6Array); - test:assertEquals(bm3nb6t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple6Array|Error bm4nb6t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple6Array); - test:assertEquals(bm4nb6t, [ - [(), ()], - [(), ()] - ]); - - NillableBooleanTuple6Array|Error bm5nb6t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple6Array); - test:assertEquals(bm5nb6t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple7Array|Error bm1nb7t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple7Array); - test:assertEquals(bm1nb7t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple7Array|Error bm2nb7t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple7Array); - test:assertEquals(bm2nb7t, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - NillableBooleanTuple7Array|Error bm3nb7t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple7Array); - test:assertTrue(bm3nb7t is Error); - test:assertEquals((bm3nb7t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - - NillableBooleanTuple7Array|Error bm4nb7t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple7Array); - test:assertEquals(bm4nb7t, [ - [(), ()], - [(), ()] - ]); - - NillableBooleanTuple7Array|Error bm5nb7t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple7Array); - test:assertEquals(bm5nb7t, [ - [true, false, (), true], - [true, false, (), true] - ]); -} - -@test:Config -function testFromCsvWithTypeForMapAndTupleAsExpectedType2() { - NillableBooleanTuple8Array|Error bm1nb8t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableBooleanTuple8Array); - test:assertEquals(bm1nb8t, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple8Array|Error bm2nb8t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableBooleanTuple8Array); - test:assertEquals(bm2nb8t, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - NillableBooleanTuple8Array|Error bm3nb8t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableBooleanTuple8Array); - test:assertTrue(bm3nb8t is Error); - test:assertEquals((bm3nb8t).message(), generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - - NillableBooleanTuple8Array|Error bm4nb8t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableBooleanTuple8Array); - test:assertEquals(bm4nb8t, [ - [(), ()], - [(), ()] - ]); - - NillableBooleanTuple8Array|Error bm5nb8t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableBooleanTuple8Array); - test:assertEquals(bm5nb8t, [ - [true, false, (), true], - [true, false, (), true] - ]); - - NillableIntBooleanTuple9Array|Error bm1nb9t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NillableIntBooleanTuple9Array); - test:assertEquals(bm1nb9t, [ - [true, false], - [true, false] - ]); - - NillableIntBooleanTuple9Array|Error bm2nb9t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NillableIntBooleanTuple9Array); - test:assertEquals(bm2nb9t, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - NillableIntBooleanTuple9Array|Error bm3nb9t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NillableIntBooleanTuple9Array); - test:assertEquals(bm3nb9t, [ - [true, false, (), false, 1], - [true, false, (), false, 1] - ]); - - NillableIntBooleanTuple9Array|Error bm4nb9t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NillableIntBooleanTuple9Array); - test:assertEquals(bm4nb9t, [ - [(), ()], - [(), ()] - ]); - - NillableIntBooleanTuple9Array|Error bm5nb9t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NillableIntBooleanTuple9Array); - test:assertEquals(bm5nb9t, [ - [true, false, (), true], - [true, false, (), true] - ]); - - NilTuple3Array|Error bm1n3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, NilTuple3Array); - test:assertTrue(bm1n3t is Error); - test:assertEquals((bm1n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - - NilTuple3Array|Error bm2n3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, NilTuple3Array); - test:assertTrue(bm2n3t is Error); - test:assertEquals((bm2n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - - NilTuple3Array|Error bm3n3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, NilTuple3Array); - test:assertTrue(bm3n3t is Error); - test:assertEquals((bm3n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - - NilTuple3Array|Error bm4n3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, NilTuple3Array); - test:assertEquals(bm4n3t, [ - [(), ()], - [(), ()] - ]); - - NilTuple3Array|Error bm5n3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, NilTuple3Array); - test:assertTrue(bm5n3t is Error); - test:assertEquals((bm5n3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); -} - -@test:Config -function testFromCsvWithTypeForMapAndArrayAsExpectedType2() { - - AnydataTuple3Array|Error bm1anyd3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, AnydataTuple3Array); - test:assertEquals(bm1anyd3t, [ - [true, false], - [true, false] - ]); - - AnydataTuple3Array|Error bm2anyd3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, AnydataTuple3Array); - test:assertEquals(bm2anyd3t, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - AnydataTuple3Array|Error bm3anyd3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, AnydataTuple3Array); - test:assertEquals(bm3anyd3t, [ - [true, false, (), false, 1], - [true, false, (), false, 1] - ]); - - AnydataTuple3Array|Error bm4anyd3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, AnydataTuple3Array); - test:assertEquals(bm4anyd3t, [ - [(), ()], - [(), ()] - ]); - - AnydataTuple3Array|Error bm5anyd3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, AnydataTuple3Array); - test:assertEquals(bm5anyd3t, [ - [true, false, (), true], - [true, false, (), true] - ]); - - JsonTuple3Array|Error bm1j3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, JsonTuple3Array); - test:assertEquals(bm1j3t, [ - [true, false], - [true, false] - ]); - - JsonTuple3Array|Error bm2j3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, JsonTuple3Array); - test:assertEquals(bm2j3t, [ - [true, false, (), (), ()], - [true, false, (), (), ()] - ]); - - JsonTuple3Array|Error bm3j3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, JsonTuple3Array); - test:assertEquals(bm3j3t, [ - [true, false, (), false, 1], - [true, false, (), false, 1] - ]); - - JsonTuple3Array|Error bm4j3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, JsonTuple3Array); - test:assertEquals(bm4j3t, [ - [(), ()], - [(), ()] - ]); - - JsonTuple3Array|Error bm5j3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, JsonTuple3Array); - test:assertEquals(bm5j3t, [ - [true, false, (), true], - [true, false, (), true] - ]); - - StringTuple3Array|Error bm1s3t = parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}, StringTuple3Array); - test:assertTrue(bm1s3t is Error); - test:assertEquals((bm1s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringTuple3Array|Error bm2s3t = parseRecordAsListType([bm2, bm2], ["b1", "b2", "b3", "n1", "n3"], {}, StringTuple3Array); - test:assertTrue(bm2s3t is Error); - test:assertEquals((bm2s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringTuple3Array|Error bm3s3t = parseRecordAsListType([bm3, bm3], ["b1", "b2", "b3", "b4", "i1"], {}, StringTuple3Array); - test:assertTrue(bm3s3t is Error); - test:assertEquals((bm3s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - - StringTuple3Array|Error bm4s3t = parseRecordAsListType([bm4, bm4], ["n1", "n3"], {}, StringTuple3Array); - test:assertTrue(bm4s3t is Error); - test:assertEquals((bm4s3t).message(), generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - - StringTuple3Array|Error bm5s3t = parseRecordAsListType([bm5, bm5], ["b1", "b2", "b3", "b4"], {}, StringTuple3Array); - test:assertTrue(bm5s3t is Error); - test:assertEquals((bm5s3t).message(), generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); -} diff --git a/ballerina/tests/parse_record_type_as_record_test.bal b/ballerina/tests/parse_record_type_as_record_test.bal deleted file mode 100644 index a212284..0000000 --- a/ballerina/tests/parse_record_type_as_record_test.bal +++ /dev/null @@ -1,722 +0,0 @@ -import ballerina/test; - -@test:Config -function testFromCsvWithTypeForMapAndRecordAsExpectedType() { - BooleanRecord1Array|Error bm1br1 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord1Array); - test:assertTrue(bm1br1 is Error); - test:assertEquals((bm1br1).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord1Array|Error bm2br1 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord1Array); - test:assertTrue(bm2br1 is Error); - test:assertEquals((bm2br1).message(), generateErrorMessageForMissingRequiredField("b4")); - - BooleanRecord1Array|Error bm3br1 = parseRecordAsRecordType([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|Error bm4br1 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord1Array); - test:assertTrue(bm4br1 is Error); - test:assertEquals((bm4br1).message(), generateErrorMessageForMissingRequiredField("b2")); - - BooleanRecord1Array|Error bm5br1 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord1Array); - test:assertEquals(bm5br1, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - BooleanRecord2Array|Error bm1br2 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord2Array); - test:assertTrue(bm1br2 is Error); - test:assertEquals((bm1br2).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord2Array|Error bm2br2 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord2Array); - test:assertTrue(bm2br2 is Error); - test:assertEquals((bm2br2).message(), generateErrorMessageForMissingRequiredField("b4")); - - BooleanRecord2Array|Error bm3br2 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord2Array); - test:assertEquals(bm3br2, [ - {b1: true, b2: false, b3: (), b4: false}, - {b1: true, b2: false, b3: (), b4: false} - ]); - - BooleanRecord2Array|Error bm4br2 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord2Array); - test:assertTrue(bm4br2 is Error); - test:assertEquals((bm4br2).message(), generateErrorMessageForMissingRequiredField("b2")); - - BooleanRecord2Array|Error bm5br2 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord2Array); - test:assertEquals(bm5br2, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - BooleanRecord3Array|Error bm1br3 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord3Array); - test:assertTrue(bm1br3 is Error); - test:assertEquals((bm1br3).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord3Array|Error bm2br3 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord3Array); - test:assertEquals(bm2br3, [ - {b1: true, b3: ()}, - {b1: true, b3: ()} - ]); - - BooleanRecord3Array|Error bm3br3 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord3Array); - test:assertEquals(bm3br3, [ - {b1: true, b3: ()}, - {b1: true, b3: ()} - ]); - - BooleanRecord3Array|Error bm4br3 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord3Array); - test:assertTrue(bm4br3 is Error); - test:assertEquals((bm4br3).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord3Array|Error bm5br3 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord3Array); - test:assertEquals(bm5br3, [{b1: true, b3: ()}, {b1: true, b3: ()}]); - - BooleanRecord4Array|Error bm1br4 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord4Array); - test:assertTrue(bm1br4 is Error); - test:assertEquals((bm1br4).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord4Array|Error bm2br4 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord4Array); - test:assertEquals(bm2br4, [ - {b1: true, b2: false, b3: (), n1: (), n3: ()}, - {b1: true, b2: false, b3: (), n1: (), n3: ()} - ]); - - BooleanRecord4Array|Error bm3br4 = parseRecordAsRecordType([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|Error bm4br4 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord4Array); - test:assertTrue(bm4br4 is Error); - test:assertEquals((bm4br4).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord4Array|Error bm5br4 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord4Array); - test:assertEquals(bm5br4, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - BooleanRecord5Array|Error bm1br5 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord5Array); - test:assertTrue(bm1br5 is Error); - test:assertEquals((bm1br5).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord5Array|Error bm2br5 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord5Array); - test:assertEquals(bm2br5, [ - {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: (), b2: false, n1: (), n3: ()} - ]); - - BooleanRecord5Array|Error bm3br5 = parseRecordAsRecordType([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|Error bm4br5 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord5Array); - test:assertTrue(bm4br5 is Error); - test:assertEquals((bm4br5).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord5Array|Error bm5br5 = parseRecordAsRecordType([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|Error bm1br6 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord6Array); - test:assertTrue(bm1br6 is Error); - test:assertEquals((bm1br6).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord6Array|Error bm2br6 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord6Array); - test:assertEquals(bm2br6, [ - {b1: true, b3: (), defaultableField: "", nillableField: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|Error bm3br6 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord6Array); - test:assertEquals(bm3br6, [ - {b1: true, b3: (), defaultableField: "", nillableField: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|Error bm4br6 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord6Array); - test:assertTrue(bm4br6 is Error); - test:assertEquals((bm4br6).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord6Array|Error bm5br6 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord6Array); - test:assertEquals(bm5br6, [ - {b1: true, b3: (), defaultableField: "", nillableField: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: ()} - ]); - - BooleanRecord7Array|Error bm1br7 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord7Array); - test:assertTrue(bm1br7 is Error); - test:assertEquals((bm1br7).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord7Array|Error bm2br7 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord7Array); - test:assertTrue(bm2br7 is Error); - test:assertEquals((bm2br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord7Array|Error bm3br7 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord7Array); - test:assertTrue(bm3br7 is Error); - test:assertEquals((bm3br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord7Array|Error bm4br7 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord7Array); - test:assertTrue(bm4br7 is Error); - test:assertEquals((bm4br7).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord7Array|Error bm5br7 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord7Array); - test:assertTrue(bm5br7 is Error); - test:assertEquals((bm5br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord8Array|Error bm1br8 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord8Array); - test:assertTrue(bm1br8 is Error); - test:assertEquals((bm1br8).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord8Array|Error bm2br8 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord8Array); - test:assertTrue(bm2br8 is Error); - test:assertEquals((bm2br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord8Array|Error bm3br8 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord8Array); - test:assertTrue(bm3br8 is Error); - test:assertEquals((bm3br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord8Array|Error bm4br8 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord8Array); - test:assertTrue(bm4br8 is Error); - test:assertEquals((bm4br8).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord8Array|Error bm5br8 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord8Array); - test:assertTrue(bm5br8 is Error); - test:assertEquals((bm5br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); -} - -@test:Config -function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { - BooleanRecord9Array|Error bm1br9 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord9Array); - test:assertTrue(bm1br9 is Error); - test:assertEquals((bm1br9).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord9Array|Error bm2br9 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord9Array); - test:assertEquals(bm2br9, [ - {b1: true, b2: false, b3: (), n1: (), n3: ()}, - {b1: true, b2: false, b3: (), n1: (), n3: ()} - ]); - - BooleanRecord9Array|Error bm3br9 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord9Array); - test:assertEquals(bm3br9, [ - {b1: true, b2: false, b3: (), b4: false}, - {b1: true, b2: false, b3: (), b4: false} - ]); - - BooleanRecord9Array|Error bm4br9 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord9Array); - test:assertTrue(bm4br9 is Error); - test:assertEquals((bm4br9).message(), generateErrorMessageForMissingRequiredField("b3")); - - BooleanRecord9Array|Error bm5br9 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord9Array); - test:assertEquals(bm5br9, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - BooleanRecord10Array|Error bm1br10 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord10Array); - test:assertEquals(bm1br10, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - BooleanRecord10Array|Error bm2br10 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord10Array); - test:assertEquals(bm2br10, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - BooleanRecord10Array|Error bm3br10 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord10Array); - test:assertEquals(bm3br10, [ - {b1: true, b2: false, b4: false}, - {b1: true, b2: false, b4: false} - ]); - - BooleanRecord10Array|Error bm4br10 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord10Array); - test:assertEquals(bm4br10, [ - {}, - {} - ]); - - BooleanRecord10Array|Error bm5br10 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord10Array); - test:assertEquals(bm5br10, [ - {b1: true, b2: false, b4: true}, - {b1: true, b2: false, b4: true} - ]); - - BooleanRecord11Array|Error bm1br11 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord11Array); - test:assertEquals(bm1br11, [ - {b1: true, b2: false, defaultableField: "", nillableField :null}, - {b1: true, b2: false, defaultableField: "", nillableField :null} - ]); - - BooleanRecord11Array|Error bm2br11 = parseRecordAsRecordType([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|Error bm3br11 = parseRecordAsRecordType([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|Error bm4br11 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord11Array); - test:assertTrue(bm4br11 is Error); - test:assertEquals((bm4br11).message(), generateErrorMessageForMissingRequiredField("b1")); - - BooleanRecord11Array|Error bm5br11 = parseRecordAsRecordType([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|Error bm1br12 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord12Array); - test:assertTrue(bm1br12 is Error); - test:assertEquals((bm1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord12Array|Error bm2br12 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord12Array); - test:assertTrue(bm2br12 is Error); - test:assertEquals((bm2br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord12Array|Error bm3br12 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord12Array); - test:assertTrue(bm3br12 is Error); - test:assertEquals((bm3br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord12Array|Error bm4br12 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord12Array); - test:assertTrue(bm4br12 is Error); - test:assertEquals((bm4br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord12Array|Error bm5br12 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord12Array); - test:assertTrue(bm5br12 is Error); - test:assertEquals((bm5br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord13Array|Error bm1br13 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord13Array); - test:assertEquals(bm1br13, [ - {b1: true, b2: false, defaultableField: "", nillableField :null}, - {b1: true, b2: false, defaultableField: "", nillableField :null} - ]); - - BooleanRecord13Array|Error bm2br13 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord13Array); - test:assertEquals(bm2br13, [ - {b1: true, b2: false, defaultableField: "", nillableField :null}, - {b1: true, b2: false, defaultableField: "", nillableField :null} - ]); - - BooleanRecord13Array|Error bm3br13 = parseRecordAsRecordType([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|Error bm4br13 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord13Array); - test:assertEquals(bm4br13, [ - {defaultableField: "", nillableField :null}, - {defaultableField: "", nillableField :null} - ]); - - BooleanRecord13Array|Error bm5br13 = parseRecordAsRecordType([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|Error bm1br14 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord14Array); - test:assertTrue(bm1br14 is Error); - test:assertEquals((bm1br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord14Array|Error bm2br14 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord14Array); - test:assertTrue(bm2br14 is Error); - test:assertEquals((bm2br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord14Array|Error bm3br14 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord14Array); - test:assertTrue(bm3br14 is Error); - test:assertEquals((bm3br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord14Array|Error bm4br14 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord14Array); - test:assertTrue(bm4br14 is Error); - test:assertEquals((bm4br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord14Array|Error bm5br14 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord14Array); - test:assertTrue(bm5br14 is Error); - test:assertEquals((bm5br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord15Array|Error bm1br15 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord15Array); - test:assertTrue(bm1br15 is Error); - test:assertEquals((bm1br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); - - BooleanRecord15Array|Error bm3br15 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord15Array); - test:assertTrue(bm3br15 is Error); - test:assertEquals((bm3br15).message(), generateErrorMessageForInvalidFieldType("true", "b1")); - - BooleanRecord15Array|Error bm4br15 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord15Array); - test:assertTrue(bm4br15 is Error); - test:assertEquals((bm4br15).message(), generateErrorMessageForMissingRequiredField("b1")); - - BooleanRecord16Array|Error bm1br16 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord16Array); - test:assertEquals(bm1br16, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - BooleanRecord16Array|Error bm2br16 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord16Array); - test:assertEquals(bm2br16, [ - {b1: true, b2: false, b3: (), n1: (), n3: ()}, - {b1: true, b2: false, b3: (), n1: (), n3: ()} - ]); - - BooleanRecord16Array|Error bm3br16 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord16Array); - test:assertEquals(bm3br16, [ - {b1: true, b2: false, b4: false, b3: ()}, - {b1: true, b2: false, b4: false, b3: ()} - ]); - - BooleanRecord16Array|Error bm4br16 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord16Array); - test:assertEquals(bm4br16, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - - BooleanRecord16Array|Error bm5br16 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord16Array); - test:assertEquals(bm5br16, [ - {b1: true, b2: false, b4: true, b3: ()}, - {b1: true, b2: false, b4: true, b3: ()} - ]); - - BooleanRecord17Array|Error bm1br17 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord17Array); - test:assertEquals(bm1br17, [ - {}, - {} - ]); - - BooleanRecord17Array|Error bm2br17 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord17Array); - test:assertEquals(bm2br17, [ - {}, - {} - ]); - - BooleanRecord17Array|Error bm3br17 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord17Array); - test:assertEquals(bm3br17, [ - {i1: 1}, - {i1: 1} - ]); - - BooleanRecord17Array|Error bm4br17 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord17Array); - test:assertEquals(bm4br17, [ - {}, - {} - ]); - - BooleanRecord17Array|Error bm5br17 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord17Array); - test:assertEquals(bm5br17, [ - {}, - {} - ]); - - BooleanRecord18Array|Error bm1br18 = parseRecordAsRecordType([bm1, bm1], {}, BooleanRecord18Array); - test:assertEquals(bm1br18, [ - {b2: false}, - {b2: false} - ]); - - BooleanRecord18Array|Error bm2br18 = parseRecordAsRecordType([bm2, bm2], {}, BooleanRecord18Array); - test:assertEquals(bm2br18, [ - {b2: false, b3: (), n1: (), n3: ()}, - {b2: false, b3: (), n1: (), n3: ()} - ]); - - BooleanRecord18Array|Error bm3br18 = parseRecordAsRecordType([bm3, bm3], {}, BooleanRecord18Array); - test:assertEquals(bm3br18, [ - {b2: false, b3: (), i1: 1}, - {b2: false, b3: (), i1: 1} - ]); - - BooleanRecord18Array|Error bm4br18 = parseRecordAsRecordType([bm4, bm4], {}, BooleanRecord18Array); - test:assertTrue(bm4br18 is Error); - test:assertEquals((bm4br18).message(), generateErrorMessageForMissingRequiredField("b2")); - - BooleanRecord18Array|Error bm5br18 = parseRecordAsRecordType([bm5, bm5], {}, BooleanRecord18Array); - test:assertEquals(bm5br18, [ - {b2: false, b3: ()}, - {b2: false, b3: ()} - ]); -} - -@test:Config -function testFromCsvWithTypeForMapAndMapAsExpectedType() { - BooleanMapArray|Error bm1bma = parseRecordAsRecordType([bm1, bm1], {}, BooleanMapArray); - test:assertEquals(bm1bma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - BooleanMapArray|Error bm2bma = parseRecordAsRecordType([bm2, bm2], {}, BooleanMapArray); - test:assertEquals(bm2bma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - BooleanMapArray|Error bm3bma = parseRecordAsRecordType([bm3, bm3], {}, BooleanMapArray); - test:assertEquals(bm3bma, [ - {b1: true, b2: false, b4: false}, - {b1: true, b2: false, b4: false} - ]); - - BooleanMapArray|Error bm4bma = parseRecordAsRecordType([bm4, bm4], {}, BooleanMapArray); - test:assertEquals(bm4bma, [ - {}, - {} - ]); - - BooleanMapArray|Error bm5bma = parseRecordAsRecordType([bm5, bm5], {}, BooleanMapArray); - test:assertEquals(bm5bma, [ - {b1: true, b2: false, b4: true}, - {b1: true, b2: false, b4: true} - ]); - - NillableBooleanMapArray|Error bm1nbma = parseRecordAsRecordType([bm1, bm1], {}, NillableBooleanMapArray); - test:assertEquals(bm1nbma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - NillableBooleanMapArray|Error bm2nbma = parseRecordAsRecordType([bm2, bm2], {}, NillableBooleanMapArray); - test:assertEquals(bm2nbma, [ - {b1: true, b2: false, b3:(), n1: (), n3: ()}, - {b1: true, b2: false, b3:(), n1: (), n3: ()} - ]); - - NillableBooleanMapArray|Error bm3nbma = parseRecordAsRecordType([bm3, bm3], {}, NillableBooleanMapArray); - test:assertEquals(bm3nbma, [ - {b1: true, b2: false, b3:(), b4: false}, - {b1: true, b2: false, b3:(), b4: false} - ]); - - NillableBooleanMapArray|Error bm4nbma = parseRecordAsRecordType([bm4, bm4], {}, NillableBooleanMapArray); - test:assertEquals(bm4nbma, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - - NillableBooleanMapArray|Error bm5nbma = parseRecordAsRecordType([bm5, bm5], {}, NillableBooleanMapArray); - test:assertEquals(bm5nbma, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - NillableIntUnionBooleanMapArray|Error bm1niubma = parseRecordAsRecordType([bm1, bm1], {}, NillableIntUnionBooleanMapArray); - test:assertEquals(bm1niubma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - NillableIntUnionBooleanMapArray|Error bm2niubma = parseRecordAsRecordType([bm2, bm2], {}, NillableIntUnionBooleanMapArray); - test:assertEquals(bm2niubma, [ - {b1: true, b2: false, b3:(), n1: (), n3: ()}, - {b1: true, b2: false, b3:(), n1: (), n3: ()} - ]); - - NillableIntUnionBooleanMapArray|Error bm3niubma = parseRecordAsRecordType([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|Error bm4niubma = parseRecordAsRecordType([bm4, bm4], {}, NillableIntUnionBooleanMapArray); - test:assertEquals(bm4niubma, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - - NillableIntUnionBooleanMapArray|Error bm5niubma = parseRecordAsRecordType([bm5, bm5], {}, NillableIntUnionBooleanMapArray); - test:assertEquals(bm5niubma, [ - {b1: true, b2: false, b3: (), b4: true}, - {b1: true, b2: false, b3: (), b4: true} - ]); - - IntUnionBooleanMapArray|Error bm1iubma = parseRecordAsRecordType([bm1, bm1], {}, IntUnionBooleanMapArray); - test:assertEquals(bm1iubma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - IntUnionBooleanMapArray|Error bm2iubma = parseRecordAsRecordType([bm2, bm2], {}, IntUnionBooleanMapArray); - test:assertEquals(bm2iubma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - IntUnionBooleanMapArray|Error bm3iubma = parseRecordAsRecordType([bm3, bm3], {}, IntUnionBooleanMapArray); - test:assertEquals(bm3iubma, [ - {b1: true, b2: false, b4: false, i1: 1}, - {b1: true, b2: false, b4: false, i1: 1} - ]); - - IntUnionBooleanMapArray|Error bm4iubma = parseRecordAsRecordType([bm4, bm4], {}, IntUnionBooleanMapArray); - test:assertEquals(bm4iubma, [ - {}, - {} - ]); - - IntUnionBooleanMapArray|Error bm5iubma = parseRecordAsRecordType([bm5, bm5], {}, IntUnionBooleanMapArray); - test:assertEquals(bm5iubma, [ - {b1: true, b2: false, b4: true}, - {b1: true, b2: false, b4: true} - ]); - - NilMapArray|Error bm1nma = parseRecordAsRecordType([bm1, bm1], {}, NilMapArray); - test:assertEquals(bm1nma, [ - {}, - {} - ]); - - NilMapArray|Error bm2nma = parseRecordAsRecordType([bm2, bm2], {}, NilMapArray); - test:assertEquals(bm2nma, [ - {n1: (), n3: (), b3: ()}, - {n1: (), n3: (), b3: ()} - ]); - - NilMapArray|Error bm3nma = parseRecordAsRecordType([bm3, bm3], {}, NilMapArray); - test:assertEquals(bm3nma, [ - {b3: ()}, - {b3: ()} - ]); - - NilMapArray|Error bm4nma = parseRecordAsRecordType([bm4, bm4], {}, NilMapArray); - test:assertEquals(bm4nma, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - NilMapArray|Error bm5nma = parseRecordAsRecordType([bm5, bm5], {}, NilMapArray); - test:assertEquals(bm5nma, [ - {b3: ()}, - {b3: ()} - ]); - - JsonMapArray|Error bm1jma = parseRecordAsRecordType([bm1, bm1], {}, JsonMapArray); - test:assertEquals(bm1jma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - JsonMapArray|Error bm2jma = parseRecordAsRecordType([bm2, bm2], {}, JsonMapArray); - test:assertEquals(bm2jma, [ - {b1: true, b2: false, b3: (), n1: (), n3: ()}, - {b1: true, b2: false, b3: (), n1: (), n3: ()} - ]); - - JsonMapArray|Error bm3jma = parseRecordAsRecordType([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|Error bm4jma = parseRecordAsRecordType([bm4, bm4], {}, JsonMapArray); - test:assertEquals(bm4jma, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - - JsonMapArray|Error bm5jma = parseRecordAsRecordType([bm5, bm5], {}, JsonMapArray); - test:assertEquals(bm5jma, [ - {b1: true, b2: false, b4: true, b3: ()}, - {b1: true, b2: false, b4: true, b3: ()} - ]); - - AnydataMapArray|Error bm1anydma = parseRecordAsRecordType([bm1, bm1], {}, AnydataMapArray); - test:assertEquals(bm1anydma, [ - {b1: true, b2: false}, - {b1: true, b2: false} - ]); - - AnydataMapArray|Error bm2anydma = parseRecordAsRecordType([bm2, bm2], {}, AnydataMapArray); - test:assertEquals(bm2anydma, [ - {b1: true, b2: false, b3: (), n1: (), n3: ()}, - {b1: true, b2: false, b3: (), n1: (), n3: ()} - ]); - - AnydataMapArray|Error bm3anydma = parseRecordAsRecordType([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|Error bm4anydma = parseRecordAsRecordType([bm4, bm4], {}, AnydataMapArray); - test:assertEquals(bm4anydma, [ - {n1: (), n3: ()}, - {n1: (), n3: ()} - ]); - - AnydataMapArray|Error bm5anydma = parseRecordAsRecordType([bm5, bm5], {}, AnydataMapArray); - test:assertEquals(bm5anydma, [ - {b1: true, b2: false, b4: true, b3: ()}, - {b1: true, b2: false, b4: true, b3: ()} - ]); - - CustomMapArray|Error bm1cma = parseRecordAsRecordType([bm1, bm1], {}, CustomMapArray); - test:assertEquals(bm1cma, [ - {}, - {} - ]); - - CustomMapArray|Error bm2cma = parseRecordAsRecordType([bm2, bm2], {}, CustomMapArray); - test:assertEquals(bm2cma, [ - {}, - {} - ]); - - CustomMapArray|Error bm3cma = parseRecordAsRecordType([bm3, bm3], {}, CustomMapArray); - test:assertEquals(bm3cma, [ - {i1: 1}, - {i1: 1} - ]); - - CustomMapArray|Error bm4cma = parseRecordAsRecordType([bm4, bm4], {}, CustomMapArray); - test:assertEquals(bm4cma, [ - {}, - {} - ]); - - CustomMapArray|Error bm5cma = parseRecordAsRecordType([bm5, bm5], {}, CustomMapArray); - test:assertEquals(bm5cma, [ - {}, - {} - ]); - - StringMapArray|Error bm1sma = parseRecordAsRecordType([bm1, bm1], {}, StringMapArray); - test:assertEquals(bm1sma, [ - {}, - {} - ]); - - StringMapArray|Error bm2sma = parseRecordAsRecordType([bm2, bm2], {}, StringMapArray); - test:assertEquals(bm2sma, [ - {}, - {} - ]); - - StringMapArray|Error bm3sma = parseRecordAsRecordType([bm3, bm3], {}, StringMapArray); - test:assertEquals(bm3sma, [ - {}, - {} - ]); - - StringMapArray|Error bm4sma = parseRecordAsRecordType([bm4, bm4], {}, StringMapArray); - test:assertEquals(bm4sma, [ - {}, - {} - ]); - - StringMapArray|Error bm5sma = parseRecordAsRecordType([bm5, bm5], {}, StringMapArray); - test:assertEquals(bm5sma, [ - {}, - {} - ]); -} diff --git a/ballerina/tests/parse_string_to_array_test.bal b/ballerina/tests/parse_string_to_array_test.bal deleted file mode 100644 index 583c29c..0000000 --- a/ballerina/tests/parse_string_to_array_test.bal +++ /dev/null @@ -1,303 +0,0 @@ -import ballerina/test; - -@test:Config -function testFromCsvStringWithTypeForStringAndArrayAsExpectedType() { - BooleanArrayArray|Error cv1baa = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cv1baa, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - BooleanArrayArray|Error cv2baa = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cv2baa, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - BooleanArrayArray|Error cv3baa = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cv3baa is Error); - test:assertEquals((cv3baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanArrayArray|Error cv4baa = parseStringToList(csvStringWithBooleanValues4); - test:assertTrue(cv4baa is Error); - test:assertEquals((cv4baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanArrayArray|Error cv5baa = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cv5baa is Error); - test:assertEquals((cv5baa).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanArrayArray|Error cv6baa = parseStringToList(csvStringWithBooleanValues6); - test:assertTrue(cv6baa is Error); - test:assertEquals((cv6baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanArrayArray|Error cv7baa = parseStringToList(csvStringWithBooleanValues7); - test:assertTrue(cv7baa is Error); - test:assertEquals((cv7baa).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - NillableBooleanArrayArray|Error cv1nbaa = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cv1nbaa, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - NillableBooleanArrayArray|Error cv2nbaa = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cv2nbaa, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableBooleanArrayArray|Error cv3nbaa = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cv3nbaa, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - NillableBooleanArrayArray|Error cv4nbaa = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cv4nbaa, [ - [true, (), (), false], - [true, (), (), false] - ]); - - NillableBooleanArrayArray|Error cv5nbaa = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cv5nbaa is Error); - test:assertEquals((cv5nbaa).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - - NillableBooleanArrayArray|Error cv6nbaa = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cv6nbaa, [ - [(), ()] - ]); - - NillableBooleanArrayArray|Error cv7nbaa = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cv7nbaa, [ - [b1, b2, (), b4] - ]); - - NillableIntOrUnionBooleanArrayArray|Error cv1niubaa = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cv1niubaa, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - NillableIntOrUnionBooleanArrayArray|Error cv2niubaa = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cv2niubaa, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableIntOrUnionBooleanArrayArray|Error cv3niubaa = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cv3niubaa, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - NillableIntOrUnionBooleanArrayArray|Error cv4niubaa = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cv4niubaa, [ - [true, (), (), false], - [true, (), (), false] - ]); - - NillableIntOrUnionBooleanArrayArray|Error cv5niubaa = parseStringToList(csvStringWithBooleanValues5); - test:assertEquals(cv5niubaa, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - NillableIntOrUnionBooleanArrayArray|Error cv6niubaa = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cv6niubaa, [ - [(), ()] - ]); - - NillableIntOrUnionBooleanArrayArray|Error cv7niubaa = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cv7niubaa, [ - [b1, b2, (), b4] - ]); - - StringArray1Array|Error cv1saa = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cv1saa, [ - ["true", "false", "true", "false"], - ["true", "false", "true", "false"], - ["true", "false", "true", "false"] - ]); - - StringArray1Array|Error cv2saa = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cv2saa, [ - ["true", "false", "true", "false", "true"], - ["true", "false", "true", "false", "true"] - ]); - - StringArray1Array|Error cv3saa = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cv3saa, [ - ["true", "false", "true"], - ["TRUE", "FALSE", "()"], - ["true", "true", "FALSE"] - ]); - - StringArray1Array|Error cv4saa = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cv4saa, [ - ["true", "()", "()", "false"], - ["true", "()", "null", "false"] - ]); - - StringArray1Array|Error cv5saa = parseStringToList(csvStringWithBooleanValues5); - test:assertEquals(cv5saa, [ - ["true", "false", "true", "2"], - ["true", "false", "true", "3"] - ]); - - StringArray1Array|Error cv6saa = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cv6saa, [ - ["()", "()"] - ]); - - StringArray1Array|Error cv7saa = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cv7saa, [ - ["true", "false", "()", "false"] - ]); - - StringArray2Array|Error cv1s2aa = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cv1s2aa, [ - ["true", "false"], - ["true", "false"], - ["true", "false"] - ]); - - StringArray2Array|Error cv2s2aa = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cv2s2aa, [ - ["true", "false"], - ["true", "false"] - ]); - - StringArray2Array|Error cv3s2aa = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cv3s2aa, [ - ["true", "false"], - ["TRUE", "FALSE"], - ["true", "true"] - ]); - - StringArray2Array|Error cv4s2aa = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cv4s2aa, [ - ["true", "()"], - ["true", "()"] - ]); - - StringArray2Array|Error cv5s2aa = parseStringToList(csvStringWithBooleanValues5); - test:assertEquals(cv5s2aa, [ - ["true", "false"], - ["true", "false"] - ]); - - StringArray2Array|Error cv6s2aa = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cv6s2aa, [ - ["()", "()"] - ]); - - StringArray2Array|Error cv7s2aa = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cv7s2aa, [ - ["true", "false"] - ]); - - JsonArray1Array|Error cv1jaa = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cv1jaa, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - JsonArray1Array|Error cv2jaa = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cv2jaa, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - JsonArray1Array|Error cv3jaa = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cv3jaa, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - JsonArray1Array|Error cv4jaa = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cv4jaa, [ - [true, (), (), false], - [true, (), (), false] - ]); - - JsonArray1Array|Error cv5jaa = parseStringToList(csvStringWithBooleanValues5); - test:assertEquals(cv5jaa, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - JsonArray1Array|Error cv6jaa = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cv6jaa, [ - [(), ()] - ]); - - JsonArray1Array|Error cv7jaa = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cv7jaa, [ - [b1, b2, (), b4] - ]); - - AnydataArray1Array|Error cv1anydaa = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cv1anydaa, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - AnydataArray1Array|Error cv2anydaa = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cv2anydaa, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - AnydataArray1Array|Error cv3anydaa = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cv3anydaa, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - AnydataArray1Array|Error cv4anydaa = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cv4anydaa, [ - [true, (), (), false], - [true, (), (), false] - ]); - - AnydataArray1Array|Error cv5anydaa = parseStringToList(csvStringWithBooleanValues5); - test:assertEquals(cv5anydaa, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - AnydataArray1Array|Error cv6anydaa = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cv6anydaa, [ - [(), ()] - ]); - - AnydataArray1Array|Error cv7anydaa = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cv7anydaa, [ - [b1, b2, (), b4] - ]); - - DecimalArray1Array|Error cv1daa = parseStringToList(csvStringWithBooleanValues1); - test:assertTrue(cv1daa is Error); - test:assertEquals((cv1daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); - - DecimalArray1Array|Error cv3daa = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cv3daa is Error); - test:assertEquals((cv3daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); - - DecimalArray1Array|Error cv6daa = parseStringToList(csvStringWithBooleanValues6); - test:assertTrue(cv6daa is Error); - test:assertEquals((cv6daa).message(), generateErrorMessageForInvalidCast("()", "decimal")); - - DecimalArray1Array|Error cv7daa = parseStringToList(csvStringWithBooleanValues7); - test:assertTrue(cv7daa is Error); - test:assertEquals((cv7daa).message(), generateErrorMessageForInvalidCast("true", "decimal")); -} diff --git a/ballerina/tests/parse_string_to_record_tests.bal b/ballerina/tests/parse_string_to_record_tests.bal deleted file mode 100644 index e96ef83..0000000 --- a/ballerina/tests/parse_string_to_record_tests.bal +++ /dev/null @@ -1,485 +0,0 @@ -import ballerina/test; - -@test:Config -function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { - BooleanRecord1Array|Error csvb1br1 = parseStringToRecord(csvStringWithBooleanValues1, {}); - 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|Error csvb2br1 = parseStringToRecord(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|Error csvb3br1 = parseStringToRecord(csvStringWithBooleanValues3, {}); - test:assertTrue(csvb3br1 is Error); - test:assertEquals((csvb3br1).message(), generateErrorMessageForMissingRequiredField("b4")); - - BooleanRecord1Array|Error csvb4br1 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br1, [ - {b1: true, b2: "()", b3: (), b4: false}, - {b1: true, b2: "()", b3: (), b4: false} - ]); - - BooleanRecord1Array|Error csvb5br1 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertTrue(csvb5br1 is Error); - test:assertEquals((csvb5br1).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanRecord1Array|Error csvb6br1 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br1 is Error); - test:assertEquals((csvb6br1).message(), generateErrorMessageForMissingRequiredField("b4")); - - BooleanRecord1Array|Error csvb7br1 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br1, [ - {b1, b2, b3: (), b4} - ]); - - BooleanRecord2Array|Error csvb1br2 = parseStringToRecord(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|Error csvb2br2 = parseStringToRecord(csvStringWithBooleanValues2, {}); - test:assertEquals(csvb2br2, [ - {b1: true, b2: false, b3: true, b4: false}, - {b1: true, b2: false, b3: true, b4: false} - ]); - - BooleanRecord2Array|Error csvb3br2 = parseStringToRecord(csvStringWithBooleanValues3, {}); - test:assertTrue(csvb3br2 is Error); - test:assertEquals((csvb3br2).message(), generateErrorMessageForMissingRequiredField("b4")); - - BooleanRecord2Array|Error csvb4br2 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br2, [ - {b1: true, b2: "()", b3: (), b4: false}, - {b1: true, b2: "()", b3: (), b4: false} - ]); - - BooleanRecord2Array|Error csvb5br2 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertTrue(csvb5br2 is Error); - test:assertEquals((csvb5br2).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanRecord2Array|Error csvb7br2 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br2, [ - {b1, b2, b3: (), b4} - ]); - - BooleanRecord3Array|Error csvb1br3 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertEquals(csvb1br3, [ - {b1: true, b3: true}, - {b1: true, b3: true}, - {b1: true, b3: true} - ]); - - BooleanRecord3Array|Error csvb2br3 = parseStringToRecord(csvStringWithBooleanValues2, {}); - test:assertEquals(csvb2br3, [ - {b1: true, b3: true}, - {b1: true, b3: true} - ]); - - BooleanRecord3Array|Error csvb3br3 = parseStringToRecord(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br3, [ - {b1: true, b3: true}, - {b1: true, b3: ()}, - {b1: true, b3: false} - ]); - - BooleanRecord3Array|Error csvb4br3 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br3, [ - {b1: true, b3: ()}, - {b1: true, b3: ()} - ]); - - BooleanRecord3Array|Error csvb5br3 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br3, [ - {b1: true, b3: true}, - {b1: true, b3: true} - ]); - - BooleanRecord3Array|Error csvb7br3 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br3, [ - {b1, b3: ()} - ]); - - BooleanRecord4Array|Error csvb1br4 = parseStringToRecord(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|Error csvb2br4 = parseStringToRecord(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|Error csvb3br4 = parseStringToRecord(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br4, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: ()}, - {b1: true, b2: true, b3: false} - ]); - - BooleanRecord4Array|Error csvb4br4 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br4, [ - {b1: true, b2: (), b3: (), b4: false}, - {b1: true, b2: (), b3: (), b4: false} - ]); - - BooleanRecord4Array|Error csvb5br4 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br4, [ - {b1: true, b2: false, b3: true, b4: 2}, - {b1: true, b2: false, b3: true, b4: 3} - ]); - - BooleanRecord4Array|Error csvb7br4 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br4, [ - {b1, b2, b3: (), b4} - ]); - - BooleanRecord5Array|Error csvb1br5 = parseStringToRecord(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|Error csvb2br5 = parseStringToRecord(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|Error csvb3br5 = parseStringToRecord(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|Error csvb4br5 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br5, [ - {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()}, - {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord5Array|Error csvb5br5 = parseStringToRecord(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|Error csvb7br5 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br5, [ - {b1, b2, b3: (), b4, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|Error csvb1br6 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertEquals(csvb1br6, [ - {b1: true, b3: true, defaultableField: "", nillableField: ()}, - {b1: true, b3: true, defaultableField: "", nillableField: ()}, - {b1: true, b3: true, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|Error csvb2br6 = parseStringToRecord(csvStringWithBooleanValues2, {}); - test:assertEquals(csvb2br6, [ - {b1: true, b3: true, defaultableField: "", nillableField: ()}, - {b1: true, b3: true, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|Error csvb3br6 = parseStringToRecord(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br6, [ - {b1: true, b3: true, defaultableField: "", nillableField: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: ()}, - {b1: true, b3: false, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|Error csvb4br6 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br6, [ - {b1: true, b3: (), defaultableField: "", nillableField: ()}, - {b1: true, b3: (), defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|Error csvb5br6 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br6, [ - {b1: true, b3: true, defaultableField: "", nillableField: ()}, - {b1: true, b3: true, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord6Array|Error csvb7br6 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br6, [ - {b1, b3: (), defaultableField: "", nillableField: ()} - ]); - - BooleanRecord7Array|Error csvb1br7 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br7 is Error); - test:assertEquals((csvb1br7).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord8Array|Error csvb1br8 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br8 is Error); - test:assertEquals((csvb1br8).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord9Array|Error csvb1br9 = parseStringToRecord(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|Error csvb2br9 = parseStringToRecord(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|Error csvb3br9 = parseStringToRecord(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br9, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: ()}, - {b1: true, b2: true, b3: false} - ]); - - BooleanRecord9Array|Error csvb4br9 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br9, [ - {b1: true, b2: (), b3: (), b4: false}, - {b1: true, b2: (), b3: (), b4: false} - ]); - - BooleanRecord9Array|Error csvb5br9 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br9, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: true} - ]); - - BooleanRecord9Array|Error csvb6br9 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br9 is Error); - test:assertEquals((csvb6br9).message(), generateErrorMessageForMissingRequiredField("b1")); - - BooleanRecord9Array|Error csvb7br9 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br9, [ - {b1, b2, b3: (), b4} - ]); - - BooleanRecord10Array|Error csvb1br10 = parseStringToRecord(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|Error csvb2br10 = parseStringToRecord(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|Error csvb3br10 = parseStringToRecord(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br10, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false}, - {b1: true, b2: true, b3: false} - ]); - - BooleanRecord10Array|Error csvb4br10 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br10, [ - {b1: true, b4: false}, - {b1: true, b4: false} - ]); - - BooleanRecord10Array|Error csvb5br10 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br10, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: true} - ]); - - BooleanRecord10Array|Error csvb6br10 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertEquals(csvb6br10, [ - {} - ]); - - BooleanRecord10Array|Error csvb7br10 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br10, [ - {b1, b2, b4} - ]); - - BooleanRecord11Array|Error csvb1br11 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertEquals(csvb1br11, [ - {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: ()} - ]); - - BooleanRecord11Array|Error csvb2br11 = parseStringToRecord(csvStringWithBooleanValues2, {}); - 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|Error csvb3br11 = parseStringToRecord(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|Error csvb4br11 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br11, [ - {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()}, - {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord11Array|Error csvb5br11 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br11, [ - {b1: true, b2: false, b3: true, b4: "2", defaultableField: "", nillableField: ()}, - {b1: true, b2: false, b3: true, b4: "3", defaultableField: "", nillableField: ()} - ]); - - BooleanRecord11Array|Error csvb6br11 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br11 is Error); - test:assertEquals((csvb6br11).message(), generateErrorMessageForMissingRequiredField("b1")); - - BooleanRecord11Array|Error csvb7br11 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br11, [ - {b1, b2, b3, b4, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord12Array|Error csvb1br12 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br12 is Error); - test:assertEquals((csvb1br12).message(), generateErrorMessageForMissingRequiredField("requiredField")); - - BooleanRecord13Array|Error csvb1br13 = parseStringToRecord(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|Error csvb2br13 = parseStringToRecord(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|Error csvb3br13 = parseStringToRecord(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|Error csvb4br13 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br13, [ - {b1: true, b2: "()", b3: "()", b4: false, defaultableField: "", nillableField: ()}, - {b1: true, b2: "()", b3: "null", b4: false, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord13Array|Error csvb5br13 = parseStringToRecord(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|Error csvb6br13 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertEquals(csvb6br13, [ - {b2: "()", b3: "()", defaultableField: "", nillableField: ()} - ]); - - BooleanRecord13Array|Error csvb7br13 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br13, [ - {b1, b2, b3: "()", b4, defaultableField: "", nillableField: ()} - ]); - - BooleanRecord14Array|Error csvb7br14 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb7br14 is Error); - test:assertEquals((csvb7br14).message(), generateErrorMessageForMissingRequiredField("requiredField")); -} - -@test:Config -function testFromCsvStringWithTypeForStringAndRecordAsExpectedType2() { - BooleanRecord15Array|Error csvb1br15 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertTrue(csvb1br15 is Error); - test:assertEquals((csvb1br15).message(), generateErrorMessageForInvalidCast("true", "int")); - - BooleanRecord15Array|Error csvb6br15 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br15 is Error); - test:assertEquals((csvb6br15).message(), generateErrorMessageForMissingRequiredField("b1")); - - BooleanRecord15Array|Error csvb7br15 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertTrue(csvb7br15 is Error); - test:assertEquals((csvb7br15).message(), generateErrorMessageForInvalidCast("true", "int")); - - BooleanRecord16Array|Error csvb1br16 = parseStringToRecord(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|Error csvb2br16 = parseStringToRecord(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|Error csvb3br16 = parseStringToRecord(csvStringWithBooleanValues3, {}); - test:assertEquals(csvb3br16, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: ()}, - {b1: true, b2: true, b3: false} - ]); - - BooleanRecord16Array|Error csvb4br16 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br16, [ - {b1: true, b2: (), b3: (), b4: false}, - {b1: true, b2: (), b3: (), b4: false} - ]); - - BooleanRecord16Array|Error csvb5br16 = parseStringToRecord(csvStringWithBooleanValues5, {}); - test:assertEquals(csvb5br16, [ - {b1: true, b2: false, b3: true}, - {b1: true, b2: false, b3: true} - ]); - - BooleanRecord16Array|Error csvb6br16 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertEquals(csvb6br16, [ - {b2: (), b3: ()} - ]); - - BooleanRecord16Array|Error csvb7br16 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br16, [ - {b1, b2, b3: (), b4} - ]); - - BooleanRecord17Array|Error csvb1br17 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertEquals(csvb1br17, [{}, {}, {}]); - - BooleanRecord17Array|Error csvb4br17 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertEquals(csvb4br17, [{}, {}]); - - BooleanRecord17Array|Error csvb6br17 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertEquals(csvb6br17, [{}]); - - BooleanRecord17Array|Error csvb7br17 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br17, [{}]); - - BooleanRecord18Array|Error csvb1br18 = parseStringToRecord(csvStringWithBooleanValues1, {}); - test:assertEquals(csvb1br18, [{b2: false}, {b2: false}, {b2: false}]); - - BooleanRecord18Array|Error csvb4br18 = parseStringToRecord(csvStringWithBooleanValues4, {}); - test:assertTrue(csvb4br18 is Error); - test:assertEquals((csvb4br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanRecord18Array|Error csvb6br18 = parseStringToRecord(csvStringWithBooleanValues6, {}); - test:assertTrue(csvb6br18 is Error); - test:assertEquals((csvb6br18).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanRecord18Array|Error csvb7br18 = parseStringToRecord(csvStringWithBooleanValues7, {}); - test:assertEquals(csvb7br18, [{b2, b3: ()}]); -} diff --git a/ballerina/tests/parse_string_to_tuple_test.bal b/ballerina/tests/parse_string_to_tuple_test.bal deleted file mode 100644 index f2639d1..0000000 --- a/ballerina/tests/parse_string_to_tuple_test.bal +++ /dev/null @@ -1,463 +0,0 @@ -import ballerina/test; - -@test:Config -function testFromCsvStringWithTypeForStringAndTupleAsExpectedType() { - BooleanTuple1Array|Error cbv1bt1 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt1, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - BooleanTuple1Array|Error cbv2bt1 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt1, [ - [true, false, true, false], - [true, false, true, false] - ]); - - BooleanTuple1Array|Error cbv3bt1 = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cbv3bt1 is Error); - test:assertEquals((cbv3bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple1Array|Error cbv5bt1 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt1 is Error); - test:assertEquals((cbv5bt1).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanTuple1Array|Error cbv7bt1 = parseStringToList(csvStringWithBooleanValues7); - test:assertTrue(cbv7bt1 is Error); - test:assertEquals((cbv7bt1).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple2Array|Error cbv1bt2 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt2, [ - [true, false], - [true, false], - [true, false] - ]); - - BooleanTuple2Array|Error cbv2bt2 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt2, [ - [true, false], - [true, false] - ]); - - BooleanTuple2Array|Error cbv3bt2 = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt2, [ - [true, false], - [true, false], - [true, true] - ]); - - BooleanTuple2Array|Error cbv4bt2 = parseStringToList(csvStringWithBooleanValues4); - test:assertTrue(cbv4bt2 is Error); - test:assertEquals((cbv4bt2).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple3Array|Error cbv1bt3 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt3, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - BooleanTuple3Array|Error cbv2bt3 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt3, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - BooleanTuple3Array|Error cbv3bt3 = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cbv3bt3 is Error); - test:assertEquals((cbv3bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple3Array|Error cbv5bt3 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt3 is Error); - test:assertEquals((cbv5bt3).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanTuple3Array|Error cbv7bt3 = parseStringToList(csvStringWithBooleanValues7); - test:assertTrue(cbv7bt3 is Error); - test:assertEquals((cbv7bt3).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple4Array|Error cbv1bt4 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt4, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - BooleanTuple4Array|Error cbv2bt4 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt4, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - BooleanTuple4Array|Error cbv3bt4 = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cbv3bt4 is Error); - test:assertEquals((cbv3bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple4Array|Error cbv4bt4 = parseStringToList(csvStringWithBooleanValues4); - test:assertTrue(cbv4bt4 is Error); - test:assertEquals((cbv4bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple4Array|Error cbv5bt4 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt4 is Error); - test:assertEquals((cbv5bt4).message(), generateErrorMessageForInvalidCast("2", "boolean")); - - BooleanTuple4Array|Error cbv6bt4 = parseStringToList(csvStringWithBooleanValues6); - test:assertTrue(cbv6bt4 is Error); - test:assertEquals((cbv6bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - BooleanTuple4Array|Error cbv7bt4 = parseStringToList(csvStringWithBooleanValues7); - test:assertTrue(cbv7bt4 is Error); - test:assertEquals((cbv7bt4).message(), generateErrorMessageForInvalidCast("()", "boolean")); - - NillableBooleanTuple5Array|Error cbv1bt5 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt5, [ - [true, false, true, false, null], - [true, false, true, false, null], - [true, false, true, false, null] - ]); - - NillableBooleanTuple5Array|Error cbv2bt5 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt5, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableBooleanTuple5Array|Error cbv3bt5 = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt5, [ - [true, false, true, null, null], - [true, false, (), null, null], - [true, true, false, null, null] - ]); - - NillableBooleanTuple5Array|Error cbv4bt5 = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cbv4bt5, [ - [true, (), (), false, null], - [true, (), (), false, null] - ]); - - NillableBooleanTuple5Array|Error cbv5bt5 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt5 is Error); - test:assertEquals((cbv5bt5).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - - NillableBooleanTuple5Array|Error cbv6bt5 = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cbv6bt5, [ - [(), (), null, null, null] - ]); - - NillableBooleanTuple5Array|Error cbv7bt5 = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cbv7bt5, [ - [b1, b2, (), b4, null] - ]); - - NillableBooleanTuple6Array|Error cbv1bt6 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt6, [ - [true, false], - [true, false], - [true, false] - ]); - - NillableBooleanTuple6Array|Error cbv2bt6 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt6, [ - [true, false], - [true, false] - ]); - - NillableBooleanTuple6Array|Error cbv3bt6 = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt6, [ - [true, false], - [true, false], - [true, true] - ]); - - NillableBooleanTuple6Array|Error cbv4bt6 = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cbv4bt6, [ - [true, ()], - [true, ()] - ]); - - NillableBooleanTuple6Array|Error cbv6bt6 = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cbv6bt6, [ - [(), null] - ]); - - NillableBooleanTuple6Array|Error cbv7bt6 = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cbv7bt6, [ - [b1, b2] - ]); - - NillableBooleanTuple7Array|Error cbv1bt7 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt7, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - NillableBooleanTuple7Array|Error cbv2bt7 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt7, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableBooleanTuple7Array|Error cbv3bt7 = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt7, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - NillableBooleanTuple7Array|Error cbv4bt7 = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cbv4bt7, [ - [true, (), (), false], - [true, (), (), false] - ]); - - NillableBooleanTuple7Array|Error cbv5bt7 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt7 is Error); - test:assertEquals((cbv5bt7).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - - NillableBooleanTuple7Array|Error cbv6bt7 = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cbv6bt7, [ - [(), ()] - ]); - - NillableBooleanTuple7Array|Error cbv7bt7 = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cbv7bt7, [ - [b1, b2, (), false] - ]); - - NillableBooleanTuple8Array|Error cbv1bt8 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt8, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - NillableBooleanTuple8Array|Error cbv2bt8 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt8, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableBooleanTuple8Array|Error cbv3bt8 = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt8, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - NillableBooleanTuple8Array|Error cbv4bt8 = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cbv4bt8, [ - [true, (), (), false], - [true, (), (), false] - ]); - - NillableBooleanTuple8Array|Error cbv5bt8 = parseStringToList(csvStringWithBooleanValues5); - test:assertTrue(cbv5bt8 is Error); - test:assertEquals((cbv5bt8).message(), generateErrorMessageForInvalidCast("2", "boolean?")); - - NillableBooleanTuple8Array|Error cbv6bt8 = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cbv6bt8, [ - [(), ()] - ]); - - NillableBooleanTuple8Array|Error cbv7bt8 = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cbv7bt8, [ - [b1, b2, (), false] - ]); - - NillableIntBooleanTuple9Array|Error cbv1bt9 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1bt9, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - NillableIntBooleanTuple9Array|Error cbv2bt9 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2bt9, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - NillableIntBooleanTuple9Array|Error cbv3bt9 = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cbv3bt9, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - NillableIntBooleanTuple9Array|Error cbv4bt9 = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cbv4bt9, [ - [true, (), (), false], - [true, (), (), false] - ]); - - NillableIntBooleanTuple9Array|Error cbv5bt9 = parseStringToList(csvStringWithBooleanValues5); - test:assertEquals(cbv5bt9, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - NillableIntBooleanTuple9Array|Error cbv6bt9 = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cbv6bt9, [ - [(), ()] - ]); - - NillableIntBooleanTuple9Array|Error cbv7bt9 = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cbv7bt9, [ - [b1, b2, (), false] - ]); - - NilTuple3Array|Error cbv1nt3 = parseStringToList(csvStringWithBooleanValues1); - test:assertTrue(cbv1nt3 is Error); - test:assertEquals((cbv1nt3).message(), generateErrorMessageForInvalidCast("true", "()")); - - NilTuple3Array|Error cbv3nt3 = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cbv3nt3 is Error); - test:assertEquals((cbv3nt3).message(), generateErrorMessageForInvalidCast("true", "()")); - - NilTuple3Array|Error cbv6nt3 = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cbv6nt3, [ - [(), ()] - ]); - - AnydataTuple3Array|Error cbv1anyd3 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1anyd3, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - AnydataTuple3Array|Error cbv2anyd3 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2anyd3, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - AnydataTuple3Array|Error cbv3anyd3 = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cbv3anyd3, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - AnydataTuple3Array|Error cbv4anyd3 = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cbv4anyd3, [ - [true, (), (), false], - [true, (), (), false] - ]); - - AnydataTuple3Array|Error cbv5anyd3 = parseStringToList(csvStringWithBooleanValues5); - test:assertEquals(cbv5anyd3, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - AnydataTuple3Array|Error cbv6anyd3 = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cbv6anyd3, [ - [(), ()] - ]); - - AnydataTuple3Array|Error cbv7anyd3 = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cbv7anyd3, [ - [b1, b2, (), false] - ]); -} - -@test:Config -function testFromCsvStringWithTypeForStringAndTupleAsExpectedType2() { - JsonTuple3Array|Error cbv1j3 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1j3, [ - [true, false, true, false], - [true, false, true, false], - [true, false, true, false] - ]); - - JsonTuple3Array|Error cbv2j3 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2j3, [ - [true, false, true, false, true], - [true, false, true, false, true] - ]); - - JsonTuple3Array|Error cbv3j3 = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cbv3j3, [ - [true, false, true], - [true, false, ()], - [true, true, false] - ]); - - JsonTuple3Array|Error cbv4j3 = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cbv4j3, [ - [true, (), (), false], - [true, (), (), false] - ]); - - JsonTuple3Array|Error cbv5j3 = parseStringToList(csvStringWithBooleanValues5); - test:assertEquals(cbv5j3, [ - [true, false, true, 2], - [true, false, true, 3] - ]); - - JsonTuple3Array|Error cbv6j3 = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cbv6j3, [ - [(), ()] - ]); - - JsonTuple3Array|Error cbv7j3 = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cbv7j3, [ - [b1, b2, (), false] - ]); - - StringTuple3Array|Error cbv1s3 = parseStringToList(csvStringWithBooleanValues1); - test:assertEquals(cbv1s3, [ - ["true", "false", "true", "false"], - ["true", "false", "true", "false"], - ["true", "false", "true", "false"] - ]); - - StringTuple3Array|Error cbv2s3 = parseStringToList(csvStringWithBooleanValues2); - test:assertEquals(cbv2s3, [ - ["true", "false", "true", "false", "true"], - ["true", "false", "true", "false", "true"] - ]); - - StringTuple3Array|Error cbv3s3 = parseStringToList(csvStringWithBooleanValues3); - test:assertEquals(cbv3s3, [ - ["true", "false", "true"], - ["TRUE", "FALSE", "()"], - ["true", "true", "FALSE"] - ]); - - StringTuple3Array|Error cbv4s3 = parseStringToList(csvStringWithBooleanValues4); - test:assertEquals(cbv4s3, [ - ["true", "()", "()", "false"], - ["true", "()", "null", "false"] - ]); - - StringTuple3Array|Error cbv5s3 = parseStringToList(csvStringWithBooleanValues5); - test:assertEquals(cbv5s3, [ - ["true", "false", "true", "2"], - ["true", "false", "true", "3"] - ]); - - StringTuple3Array|Error cbv6s3 = parseStringToList(csvStringWithBooleanValues6); - test:assertEquals(cbv6s3, [ - ["()", "()"] - ]); - - StringTuple3Array|Error cbv7s3 = parseStringToList(csvStringWithBooleanValues7); - test:assertEquals(cbv7s3, [ - ["true", "false", "()", "false"] - ]); - - DecimalTuple3Array|Error cbv1dt3 = parseStringToList(csvStringWithBooleanValues1); - test:assertTrue(cbv1dt3 is Error); - test:assertEquals((cbv1dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); - - DecimalTuple3Array|Error cbv3dt3 = parseStringToList(csvStringWithBooleanValues3); - test:assertTrue(cbv3dt3 is Error); - test:assertEquals((cbv3dt3).message(), generateErrorMessageForInvalidCast("true", "decimal")); - - DecimalTuple3Array|Error cbv6dt3 = parseStringToList(csvStringWithBooleanValues6); - test:assertTrue(cbv6dt3 is Error); - test:assertEquals((cbv6dt3).message(), generateErrorMessageForInvalidCast("()", "decimal")); -} diff --git a/ballerina/tests/test_utils.bal b/ballerina/tests/test_utils.bal deleted file mode 100644 index d328643..0000000 --- a/ballerina/tests/test_utils.bal +++ /dev/null @@ -1,23 +0,0 @@ -function generateErrorMessageForMissingRequiredField(string 'field) returns string { - return string `no matching header value is found for the required field '${'field}'`; -} - -function generateErrorMessageForInvalidCast(string value, string 'type) returns string { - return string `value '${value}' cannot be cast into '${'type}'`; -} - -function generateErrorMessageForInvalidFieldType(string value, string 'key) returns string { - return string `no mapping type found for value '${value}' in key '${'key}'`; -} - -function generateErrorMessageForInvalidValueForArrayType(string value, string index, string arrayType) returns string { - return string `value '${value}' in index '${index}' is not compatible with array type '${arrayType}'`; -} - -function generateErrorMessageForInvalidHeaders(string value, string 'type) returns string{ - return string `value '${value}' cannot be cast into '${'type}', because fields in '${'type}' or the provided expected headers are not matching with the '${value}'`; -} - -function generateErrorMessageForInvalidCustomHeader(string header) returns string{ - return string `Invalid header value: '${header}'`; -} diff --git a/ballerina/tests/user_configs.bal b/ballerina/tests/user_configs.bal deleted file mode 100644 index 02f933b..0000000 --- a/ballerina/tests/user_configs.bal +++ /dev/null @@ -1,27 +0,0 @@ -// Valid parser options -ParseOption option1 = {delimiter: "@", nilValue: "null", lineTerminator: [LF]}; -ParseOption option2 = {nilValue: "N/A", lineTerminator: [CR, LF], comment: "/"}; -ParseOption option3 = {nilValue: "()", header: 1, skipLines: [1, 2]}; -ParseOption option4 = {nilValue: "", header: 4, skipLines: "1-5"}; -ParseOption option5 = {nilValue: "", header: 4, skipLines: "1-1"}; -ParseOption option6 = {nilValue: "()", header: false, skipLines: [1, 2]}; - -parseToRecordOption ptOption1 = {nilValue: "", header: 1, skipLines: [2, 4]}; -parseToRecordOption ptOption2 = {nilValue: "", header: 1, skipLines: "2-4"}; -parseToRecordOption ptOption3 = {nilValue: "", header: 4, skipLines: "1-5"}; -parseToRecordOption ptOption4 = {nilValue: "", header: 4, skipLines: [-1, -2, 4, 2]}; -parseToRecordOption ptOption5 = {header: false, skipLines: [-1, -2, 5, 3]}; - -// Invalid parser options -ParseOption invalidParserOptions1 = {header: 4}; -ParseOption invalidParserOptions2 = {comment: "$"}; -ParseOption invalidParserOptions3 = {lineTerminator: CR}; -ParseOption invalidParserOptions4 = {skipLines: [1000, 1001]}; -ParseOption invalidParserOptions5 = {skipLines: "a-b"}; -ParseOption invalidParserOptions6 = {skipLines: "3-1"}; -ParseOption invalidParserOptions7 = {skipLines: "a-5"}; -ParseOption invalidParserOptions8 = {skipLines: "6-a"}; -ParseOption invalidParserOptions9 = {skipLines: "a-5"}; -ParseOption invalidParserOptions10 = {skipLines: "-1-6"}; -ParseOption invalidParserOptions11 = {nilValue: "", header: 4, skipLines: "0-10"}; -ParseOption invalidParserOptions12 = {skipLines: [1, 3, 4, -1]}; diff --git a/build-config/resources/BallerinaTest.toml b/build-config/resources/BallerinaTest.toml new file mode 100644 index 0000000..05b0322 --- /dev/null +++ b/build-config/resources/BallerinaTest.toml @@ -0,0 +1,13 @@ +[package] +org = "ballerina" +name = "@package.name@" +version = "@toml.version@" + +[[dependency]] +org = "ballerina" +name = "@test.common@" +repository = "local" +version = "@toml.version@" + +[platform.java17] +graalvmCompatible = true diff --git a/build-config/resources/CsvTestCommon.toml b/build-config/resources/CsvTestCommon.toml new file mode 100644 index 0000000..91de9a7 --- /dev/null +++ b/build-config/resources/CsvTestCommon.toml @@ -0,0 +1,4 @@ +[package] +org = "ballerina" +name = "@package.name@" +version = "@toml.version@" diff --git a/gradle.properties b/gradle.properties index ee77c50..9ef82e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,6 +2,7 @@ org.gradle.caching=true group=io.ballerina.stdlib version=0.1.0-SNAPSHOT ballerinaLangVersion=2201.9.0 +ballerinaTomlParserVersion=1.2.2 checkstyleToolVersion=10.12.0 puppycrawlCheckstyleVersion=10.12.0 diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index e097751..777b954 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -141,32 +141,33 @@ static class StateMachine { } public void reset() { - index = 0; currentCsvNode = null; - line = 1; - column = 0; - restType = null; + currentEscapeCharacters.clear(); + headers.clear(); rootCsvNode = null; - columnIndex = 0; - rowIndex = 1; fieldHierarchy.clear(); updatedRecordFieldNames.clear(); fields.clear(); fieldNames.clear(); - rootArrayType = null; - config = null; - lineNumber = 0; - expectedArrayElementType = null; - headers = new ArrayList<>(); - currentEscapeCharacters = new Stack<>(); charBuff = new char[1024]; charBuffIndex = 0; + index = 0; + line = 1; + column = 0; + restType = null; + expectedArrayElementType = null; + columnIndex = 0; + rowIndex = 1; + lineNumber = 0; + rootArrayType = null; + config = null; skipTheRow = false; + insideComment = false; isCurrentCsvNodeEmpty = true; isHeaderConfigExceedLineNumber = false; - hexBuilder = new StringBuilder(4); isQuoteClosed = false; isIntersectionElementType = false; + hexBuilder = new StringBuilder(4); } private static boolean isWhitespace(char ch, Object lineTerminator) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 03c7467..0f6090f 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -125,8 +125,12 @@ void reset() { rootCsvNode = null; expectedArrayElementType = null; sourceArrayElementType = null; - headers = null; config = null; + headers = null; + } + + CsvTree() { + reset(); } @SuppressWarnings("unchecked") diff --git a/settings.gradle b/settings.gradle index 72b6bfd..3a376ae 100644 --- a/settings.gradle +++ b/settings.gradle @@ -46,12 +46,14 @@ include(':data.csv-native') include(':data.csv-ballerina') include(':data.csv-compiler-plugin') include(':data.csv-compiler-plugin-tests') +include(':data.csv-ballerina-tests') project(':checkstyle').projectDir = file("build-config${File.separator}checkstyle") project(':data.csv-native').projectDir = file('native') project(':data.csv-ballerina').projectDir = file('ballerina') project(':data.csv-compiler-plugin').projectDir = file('compiler-plugin') project(':data.csv-compiler-plugin-tests').projectDir = file('compiler-plugin-test') +project(':data.csv-ballerina-tests').projectDir = file('ballerina-tests') gradleEnterprise { buildScan { @@ -59,3 +61,5 @@ gradleEnterprise { termsOfServiceAgree = 'yes' } } +include 'ballerina-tests' + From e4ae6d22ac5d902efdef9afda917871bdd4c5323 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 10 Jul 2024 11:14:26 +0530 Subject: [PATCH 054/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 65 ++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c07b540..8441781 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -7,12 +7,26 @@ dependencies-toml-version = "2" distribution-version = "2201.9.0" +[[package]] +org = "ballerina" +name = "constraint" +version = "1.5.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "constraint", moduleName = "constraint"} +] + [[package]] org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"} + {org = "ballerina", name = "constraint"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "test"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -26,3 +40,52 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + From c7d0602f0781039497646bb4507824ad991a64ef Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 10 Jul 2024 11:29:15 +0530 Subject: [PATCH 055/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 65 +------------------------------------ 1 file changed, 1 insertion(+), 64 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 8441781..c07b540 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -7,26 +7,12 @@ dependencies-toml-version = "2" distribution-version = "2201.9.0" -[[package]] -org = "ballerina" -name = "constraint" -version = "1.5.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] -modules = [ - {org = "ballerina", packageName = "constraint", moduleName = "constraint"} -] - [[package]] org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "constraint"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "test"} + {org = "ballerina", name = "jballerina.java"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -40,52 +26,3 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - From be14fe27ef167d79f60b676aab97fd8784544da3 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 10 Jul 2024 13:23:12 +0530 Subject: [PATCH 056/147] Fix new line character related issu in wiondows build --- .../user_config_with_parser_options_test.bal | 47 ++++++------- .../user-config-tests/tests/user_configs.bal | 4 +- ballerina/types.bal | 3 +- .../stdlib/data/csvdata/csv/CsvParser.java | 68 +++++++++++++++---- .../stdlib/data/csvdata/utils/Constants.java | 6 ++ .../stdlib/data/csvdata/utils/CsvUtils.java | 49 +++++++++---- 6 files changed, 123 insertions(+), 54 deletions(-) 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 06148a9..5649d3d 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 @@ -153,11 +153,11 @@ function testHeaderOption() { function testNullConfigOption() { string csvValue1 = string `a ()`; - string csvValue2 = string `a + string csvValue2 = string `a null`; - string csvValue3 = string `c, a + string csvValue3 = string `c, a true, e`; - string csvValue4 = string `a + string csvValue4 = string `a Null`; string csvValue5 = string `b, a bN/Aa,N/A`; @@ -224,9 +224,9 @@ function testCommentConfigOption() { 1`; string csvValue2 = string `a # comment 1`; - string csvValue3 = string `a #, c + string csvValue3 = string `a #, c 1#, e`; - string csvValue4 = string `a + string csvValue4 = string `a # comment 1`; string csvValue5 = string `a, b @@ -286,21 +286,21 @@ function testCommentConfigOption2() { 1`; string csvValue2 = string `a & comment 1`; - string csvValue3 = string `a &, c + string csvValue3 = string `a &, c 1&, e`; - string csvValue4 = string `a - - - + string csvValue4 = string `a + + + & comment 1`; string csvValue5 = string `a&, b 1, 2 & comment - - + + & comment`; string csvValue6 = string ` - + a,& b 1 ,&2 & comment @@ -677,7 +677,7 @@ function testTextQuotesWithParserOptions() { 1, "2", "3" "1", 2, 3 1, "2", 3 - + "1", "2", "3"`; string csvValue2 = string ` @@ -740,7 +740,7 @@ function testHeaderQuotesWithParserOptions() { 1, "2", "3" "1", 2, 3 1, "2", 3 - + "1", "2", "3"`; string csvValue2 = string ` @@ -775,7 +775,7 @@ function testEscapeCharactersWithParserOptions() { 1, "2a\t", "3b\n" "1c\n", 2, 3 1, "2a\"", 3 - + "1a\\", "2b\\"", "3"`; string csvValue2 = string ` @@ -783,7 +783,7 @@ function testEscapeCharactersWithParserOptions() { 1, "2a\t", "3b\n" "1c\n", "/2/", 3 1, "2a\"", "3" - + "1a\\", "2b\\"", "3"`; string csvValue3 = string ` @@ -791,7 +791,7 @@ function testEscapeCharactersWithParserOptions() { 1, "2\t", "3\n" "1\n", 2, 3 1, "2\"", 3 - + "1\\", "2\\"", "3"`; record {}[]|csv:Error cn = csv:parseStringToRecord(csvValue1, {header: 1}); @@ -836,21 +836,22 @@ function testDelimiterWithParserOptions() { @test:Config function testLineTerminatorWithParserOptions() { - string csvValue = string `a,b${"\n"} 1,"2\n3"`; + string csvValue = string `a,b + 1,"2\n3"`; - record {}[]|csv:Error cn = csv:parseStringToRecord(csvValue, {header: 0, lineTerminator: csv:LF}); + record {}[]|csv:Error cn = csv:parseStringToRecord(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn, [{a: 1, b: "2\n3"}]); - cn = csv:parseStringToRecord(csvValue, {header: 0, lineTerminator: [csv:LF]}); + cn = csv:parseStringToRecord(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]}); test:assertEquals(cn, [{a: 1, b: "2\n3"}]); - anydata[][]|csv:Error cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: csv:LF}); + anydata[][]|csv:Error cn2 = csv:parseStringToList(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:parseStringToList(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]}); diff --git a/ballerina-tests/user-config-tests/tests/user_configs.bal b/ballerina-tests/user-config-tests/tests/user_configs.bal index c5f08a9..8e85183 100644 --- a/ballerina-tests/user-config-tests/tests/user_configs.bal +++ b/ballerina-tests/user-config-tests/tests/user_configs.bal @@ -2,7 +2,7 @@ import ballerina/data.csv as csv; // Valid parser options csv:ParseOption option1 = {delimiter: "@", nilValue: "null", lineTerminator: [csv:LF]}; -csv:ParseOption option2 = {nilValue: "N/A", lineTerminator: [csv:CR, csv:LF], comment: "/"}; +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"}; @@ -17,7 +17,7 @@ csv:parseToRecordOption 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:CR}; +csv:ParseOption invalidParserOptions3 = {lineTerminator: csv:CRLF}; csv:ParseOption invalidParserOptions4 = {skipLines: [1000, 1001]}; csv:ParseOption invalidParserOptions5 = {skipLines: "a-b"}; csv:ParseOption invalidParserOptions6 = {skipLines: "3-1"}; diff --git a/ballerina/types.bal b/ballerina/types.bal index 0cc44fc..1bee776 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -47,7 +47,7 @@ public type ParseOption record {| # The character used for escaping. string:Char escapeChar = "\\"; # The line terminator(s) used in the data. - LineTerminator|LineTerminator[] lineTerminator = [CR, LF, CRLF]; + LineTerminator|LineTerminator[] lineTerminator = [LF, CRLF]; # The value to represent nil. NilValue? nilValue = (); # The character used to indicate comments in the data. @@ -90,7 +90,6 @@ public type ListAsRecordOption record {| # Enum representing possible line terminators. public enum LineTerminator { - CR = "\r", LF = "\n", CRLF = "\r\n" }; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 777b954..3f026c5 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -34,6 +34,7 @@ import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BTypedesc; +import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import io.ballerina.stdlib.data.csvdata.utils.DataUtils; @@ -141,33 +142,32 @@ static class StateMachine { } public void reset() { - currentCsvNode = null; - currentEscapeCharacters.clear(); - headers.clear(); - rootCsvNode = null; - fieldHierarchy.clear(); - updatedRecordFieldNames.clear(); - fields.clear(); - fieldNames.clear(); - charBuff = new char[1024]; - charBuffIndex = 0; index = 0; + currentCsvNode = null; line = 1; column = 0; restType = null; - expectedArrayElementType = null; + rootCsvNode = null; columnIndex = 0; rowIndex = 1; - lineNumber = 0; + fieldHierarchy.clear(); + updatedRecordFieldNames.clear(); + fields.clear(); + fieldNames.clear(); rootArrayType = null; config = null; + lineNumber = 0; + expectedArrayElementType = null; + headers = new ArrayList<>(); + currentEscapeCharacters = new Stack<>(); + charBuff = new char[1024]; + charBuffIndex = 0; skipTheRow = false; - insideComment = false; isCurrentCsvNodeEmpty = true; isHeaderConfigExceedLineNumber = false; + hexBuilder = new StringBuilder(4); isQuoteClosed = false; isIntersectionElementType = false; - hexBuilder = new StringBuilder(4); } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -345,6 +345,13 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (ch == Constants.LineTerminator.CR) { + CsvUtils.setCarriageTokenPresent(true); + continue; + } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + CsvUtils.setCarriageTokenPresent(false); + } + if (sm.lineNumber < headerStartRowNumber) { sm.isHeaderConfigExceedLineNumber = true; if (sm.isNewLineOrEof(ch)) { @@ -481,6 +488,13 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (ch == Constants.LineTerminator.CR) { + CsvUtils.setCarriageTokenPresent(true); + continue; + } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + CsvUtils.setCarriageTokenPresent(false); + } + if (sm.skipTheRow) { if (sm.isEndOfTheRowAndValueIsNotEmpty(sm, ch)) { sm.insideComment = false; @@ -690,6 +704,13 @@ public State transition(StateMachine sm, char[] buff, int i, int count) for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (ch == Constants.LineTerminator.CR) { + CsvUtils.setCarriageTokenPresent(true); + continue; + } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + CsvUtils.setCarriageTokenPresent(false); + } + if (ch == sm.config.textEnclosure) { if (sm.isQuoteClosed) { sm.append(ch); @@ -742,6 +763,13 @@ public State transition(StateMachine sm, char[] buff, int i, int count) for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (ch == Constants.LineTerminator.CR) { + CsvUtils.setCarriageTokenPresent(true); + continue; + } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + CsvUtils.setCarriageTokenPresent(false); + } + if (ch == sm.config.textEnclosure) { sm.isQuoteClosed = true; } else if (ch == sm.config.delimiter && sm.isQuoteClosed) { @@ -814,6 +842,13 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (ch == Constants.LineTerminator.CR) { + CsvUtils.setCarriageTokenPresent(true); + continue; + } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + CsvUtils.setCarriageTokenPresent(false); + } + if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) { sm.hexBuilder.append(ch); if (sm.hexBuilder.length() >= 4) { @@ -871,6 +906,11 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C if (i < count) { ch = buff[i]; sm.processLocation(ch); + if (ch == Constants.LineTerminator.CR) { + CsvUtils.setCarriageTokenPresent(true); + } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + CsvUtils.setCarriageTokenPresent(false); + } switch (ch) { case '"': sm.append(QUOTES); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java index 3e39494..ef16c39 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -29,6 +29,12 @@ public static class Values { public static final String BALLERINA_NULL = "()"; } + public static class LineTerminator { + public static final char LF = '\n'; + public static final char CR = '\r'; + public static final String CRLF = "\r\n"; + } + public static final String SKIP_LINE_RANGE_SEP = "-"; public static final String FIELD = "$field$."; public static final String NAME = "Name"; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 2769ff2..3f67f06 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -23,6 +23,12 @@ import static io.ballerina.stdlib.data.csvdata.utils.Constants.SKIP_LINE_RANGE_SEP; public class CsvUtils { + public static boolean isCarriageTokenPresent = false; + + public static void setCarriageTokenPresent(boolean isCarriageTokenPresent) { + CsvUtils.isCarriageTokenPresent = isCarriageTokenPresent; + } + public static void validateExpectedArraySize(int size, int currentSize) { if (size != -1 && size > currentSize) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, currentSize); @@ -117,17 +123,17 @@ public static boolean isHeaderFieldsEmpty(Map currentField) { public static boolean checkTypeCompatibility(Type constraintType, Object csv, boolean stringConversion) { int tag = constraintType.getTag(); if ((csv instanceof BString && (stringConversion || tag == TypeTags.STRING_TAG - || tag == TypeTags.CHAR_STRING_TAG || isJsonOrAnyDataOrAny(tag))) + || tag == TypeTags.CHAR_STRING_TAG || isJsonOrAnyDataOrAny(tag))) || (csv instanceof Long && (tag == TypeTags.INT_TAG - || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.BYTE_TAG - || tag == TypeTags.SIGNED8_INT_TAG || tag == TypeTags.SIGNED16_INT_TAG - || tag == TypeTags.SIGNED32_INT_TAG || tag == TypeTags.UNSIGNED8_INT_TAG - || tag == TypeTags.UNSIGNED16_INT_TAG || tag == TypeTags.UNSIGNED32_INT_TAG - || isJsonOrAnyDataOrAny(tag))) + || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.BYTE_TAG + || tag == TypeTags.SIGNED8_INT_TAG || tag == TypeTags.SIGNED16_INT_TAG + || tag == TypeTags.SIGNED32_INT_TAG || tag == TypeTags.UNSIGNED8_INT_TAG + || tag == TypeTags.UNSIGNED16_INT_TAG || tag == TypeTags.UNSIGNED32_INT_TAG + || isJsonOrAnyDataOrAny(tag))) || (csv instanceof BDecimal && ((tag == TypeTags.DECIMAL_TAG - || tag == TypeTags.FLOAT_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag))) + || tag == TypeTags.FLOAT_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag))) || (csv instanceof Double && ((tag == TypeTags.FLOAT_TAG - || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag))) + || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag))) || (Boolean.class.isInstance(csv) && (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag))) || (csv == null && (tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag)))) { return true; @@ -153,8 +159,8 @@ public static int getTheActualExpectedType(Type type) { } public static HashMap - processNameAnnotationsAndBuildCustomFieldMap(RecordType recordType, - Map fieldHierarchy) { + processNameAnnotationsAndBuildCustomFieldMap(RecordType recordType, + Map fieldHierarchy) { BMap annotations = recordType.getAnnotations(); HashMap updatedRecordFieldNames = new HashMap<>(); HashSet updatedFields = new HashSet<>(); @@ -267,11 +273,17 @@ public static boolean isNullValue(Object nullValue, Object value) { } public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object lineTerminatorObj) { - String stringValue = Character.toString(c); if (lineTerminatorObj instanceof BArray) { Object[] lineTerminators = ((BArray) lineTerminatorObj).getValues(); for (Object lineTerminator: lineTerminators) { - if (lineTerminator != null && lineTerminator.toString().equals(stringValue)) { + if (lineTerminator != null && c == Constants.LineTerminator.LF) { + String lineTerminatorString = lineTerminator.toString(); + if (isCarriageTokenPresent) { + if (lineTerminatorString.equals(Constants.LineTerminator.CRLF)) { + return true; + } + continue; + } return true; } } @@ -279,7 +291,18 @@ public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object li } String lineTerminator = StringUtils.getStringValue(StringUtils.fromString(lineTerminatorObj.toString())); - return lineTerminator.equals(stringValue); + if (c == Constants.LineTerminator.LF) { + if (lineTerminator != null) { + if (lineTerminator.equals(Constants.LineTerminator.CRLF)) { + if (isCarriageTokenPresent) { + return true; + } + return false; + } + return true; + } + } + return false; } public static class SortConfigurations { From 0ca601b0e2931dd0f9a758045483dcf09b8ef94e Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 10 Jul 2024 13:48:27 +0530 Subject: [PATCH 057/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c07b540..c995088 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,7 +12,8 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"} + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "test"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -26,3 +27,52 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + From fe50cfa107bb8527ef551d5ddf4f0b3cfaca997c Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 11 Jul 2024 13:47:31 +0530 Subject: [PATCH 058/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c995088..9f46b2e 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,6 +12,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] @@ -19,6 +20,19 @@ modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} ] +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -62,6 +76,15 @@ name = "lang.object" version = "0.0.0" scope = "testOnly" +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "test" From f20fd85a6e027dc01c494c3657b757e24c59ff85 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 11 Jul 2024 14:21:18 +0530 Subject: [PATCH 059/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 9f46b2e..c995088 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,7 +12,6 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] @@ -20,19 +19,6 @@ modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} ] -[[package]] -org = "ballerina" -name = "io" -version = "1.6.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -76,15 +62,6 @@ name = "lang.object" version = "0.0.0" scope = "testOnly" -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - [[package]] org = "ballerina" name = "test" From f4f07cace70da8d292c779627de00500229223fd Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 12 Jul 2024 13:05:03 +0530 Subject: [PATCH 060/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 +------------------------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c995088..c07b540 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,8 +12,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "test"} + {org = "ballerina", name = "jballerina.java"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -27,52 +26,3 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - From 1eb6cf9f7a9a802bdcfa96ec9e8926574dbf31ff Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 12 Jul 2024 13:11:51 +0530 Subject: [PATCH 061/147] Add tests for byte and byte streams --- .../workflows/build-with-bal-test-graalvm.yml | 2 + ballerina-tests/build.gradle | 5 +- .../tests/csv_content.txt | 4 + .../tests/parse_string_compatibality_test.bal | 53 ++++++- .../tests/parse_type_compatibility_test.bal | 2 - ballerina-tests/unicode-tests/.gitignore | 11 ++ ballerina-tests/unicode-tests/Ballerina.toml | 13 ++ .../tests/escape_character_test.bal | 55 +++++++ .../tests/test_with_singleton_test.bal | 18 +-- .../user_config_with_parser_options_test.bal | 5 +- .../stdlib/data/csvdata/csv/CsvParser.java | 145 +++++++++++++----- 11 files changed, 259 insertions(+), 54 deletions(-) create mode 100644 ballerina-tests/type-compatible-tests/tests/csv_content.txt create mode 100644 ballerina-tests/unicode-tests/.gitignore create mode 100644 ballerina-tests/unicode-tests/Ballerina.toml create mode 100644 ballerina-tests/unicode-tests/tests/escape_character_test.bal diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 291054d..77a583e 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -35,3 +35,5 @@ jobs: lang_tag: ${{ inputs.lang_tag }} lang_version: ${{ inputs.lang_version }} native_image_options: '-J-Xmx7G ${{ inputs.native_image_options }}' + # TODO : Enable after fixing this issue : https://github.com/ballerina-platform/ballerina-lang/issues/38882 + additional_windows_build_flags: '-x test' diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index 524cca8..07f7576 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -32,9 +32,8 @@ 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.stdlib.data.*:ballerina.*" -def testPackages = ["constraint-validation-tests", "parse-list-types-tests", "parse-record-types-tests", - "parse-string-array-types-tests", "parse-string-record-types-tests", "type-compatible-tests", - "union-type-tests", "user-config-tests"] +def testPackages = ["user-config-tests", "type-compatible-tests", "unicode-tests", "constraint-validation-tests", "parse-list-types-tests", "parse-record-types-tests", + "parse-string-array-types-tests", "parse-string-record-types-tests", "union-type-tests"] def testCommonPackage = "csv-commons" def stripBallerinaExtensionVersion(String extVersion) { diff --git a/ballerina-tests/type-compatible-tests/tests/csv_content.txt b/ballerina-tests/type-compatible-tests/tests/csv_content.txt new file mode 100644 index 0000000..2917073 --- /dev/null +++ b/ballerina-tests/type-compatible-tests/tests/csv_content.txt @@ -0,0 +1,4 @@ +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 \ No newline at end of file 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 c36c4c8..8cb60fd 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 @@ -1,7 +1,10 @@ import ballerina/csv_commons as common; import ballerina/data.csv as csv; +import ballerina/io; import ballerina/test; +const string filepath = "tests/csv_content.txt"; + @test:Config function testFromCsvStringWithTypeCompatibility() { string value = string `i1,i2,s1,s2, b1,b2,n1,n2,f1,f2, d1,d2,j1,a1,j2,a2 @@ -180,4 +183,52 @@ function testFromCsvStringWithTypeCompatibility() { 1.2, abc, true,1.0`); test:assertTrue(m3rra is csv:Error); test:assertEquals((m3rra).message(), common:generateErrorMessageForInvalidCast("1.0", "int")); -} \ No newline at end of file +} + +@test:Config +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); + test:assertEquals(rec, [ + {"a b":"Hello world","b d e":" Hi I am ","f":"\"Hi I am \""}]); +} + +@test:Config +function testParseBytes() returns error? { + byte[] csvBytes = check io:fileReadBytes(filepath); + + record{}[]|csv:Error rec = csv:parseBytesToRecord(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, {}); + test:assertEquals(rec2, [ + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"] + ]); +} + +@test:Config +function testParseStream() returns error? { + stream csvByteStream = check io:fileReadBlocksAsStream(filepath); + record{}[]|csv:Error rec = csv:parseStreamToRecord(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); + string[][]|csv:Error rec2 = csv:parseStreamToList(csvByteStream, {}); + test:assertEquals(rec2, [ + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"], + ["Hello World", "\"Hello World\"", "Hello World", "2"] + ]); +} 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 d8ac07f..ed41a81 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 @@ -5,8 +5,6 @@ import ballerina/test; @test:Config function testFromCsvWithTypeFunctionWithTypeCompatibility() { var value = {i1, i2, s1, s2, b1, b2, n1, n2, f1, f2, d1, d2, j1: b1, a1: d1, j2: b2, a2: d2}; - var value2 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3, j2: b2, a2: d2}; - var value3 = {i1, s1, b1, n1, f1, d1, j1: b1, a1: d1, s2, s3}; CustomRecord27Array|csv:Error vcr27a = csv:parseRecordAsRecordType([value, value, value], {}, CustomRecord27Array); test:assertEquals(vcr27a , [ diff --git a/ballerina-tests/unicode-tests/.gitignore b/ballerina-tests/unicode-tests/.gitignore new file mode 100644 index 0000000..d5fc29a --- /dev/null +++ b/ballerina-tests/unicode-tests/.gitignore @@ -0,0 +1,11 @@ +# Ballerina generates this directory during the compilation of a package. +# It contains compiler-generated artifacts and the final executable if this is an application package. +target/ + +# Ballerina maintains the compiler-generated source code here. +# Remove this if you want to commit generated sources. +generated/ + +# Contains configuration values used during development time. +# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. +Config.toml diff --git a/ballerina-tests/unicode-tests/Ballerina.toml b/ballerina-tests/unicode-tests/Ballerina.toml new file mode 100644 index 0000000..b2ec347 --- /dev/null +++ b/ballerina-tests/unicode-tests/Ballerina.toml @@ -0,0 +1,13 @@ +[package] +org = "ballerina" +name = "unicode_tests" +version = "0.1.0" + +[[dependency]] +org = "ballerina" +name = "csv_commons" +repository = "local" +version = "0.1.0" + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina-tests/unicode-tests/tests/escape_character_test.bal b/ballerina-tests/unicode-tests/tests/escape_character_test.bal new file mode 100644 index 0000000..cee018f --- /dev/null +++ b/ballerina-tests/unicode-tests/tests/escape_character_test.bal @@ -0,0 +1,55 @@ +import ballerina/data.csv as csv; +import ballerina/test; + +@test:Config +function testEscapedCharactres() returns error? { + string csvString = string `a, b + quote\"\"quoted\"quote, 1 + backslash\\backslash, 2 + newline\nnewline, 3 + tab\ttab, 5 + unicode\u0061unicode, 6 + slash\/slash, 9 + quoted string \\'abc\\', 10`; + + record{string a; int b;}[]|csv:Error rec = csv:parseStringToRecord(csvString); + test:assertEquals(rec, [ + {a: string `quote""quoted"quote`, b: 1}, + {a: string `backslash${"\\"}backslash`, b: 2}, + {a: string `newline${"\n"}newline`, b: 3}, + {a: string `tab${"\t"}tab`, b: 5}, + {a: string `unicodeaunicode`, b: 6}, + {a: string `slash/slash`, b: 9}, + {a: string `quoted string \'abc\'`, b: 10} + ]); +} + +@test:Config +function testEscapedCharactres2() returns error? { + string csvString = string `a, b + backspace\bbackspace, 7`; + + record{string a; int b;}[]|csv:Error rec = csv:parseStringToRecord(csvString); + test:assertTrue(rec is record{string a; int b;}[]); +} + +@test:Config +function testEscapedCharactres3() returns error? { + string csvString = string ` a c, b + carriage return\r carriage return, 4`; + + record{}[]|csv:Error rec = csv:parseStringToRecord(csvString); + test:assertEquals(rec, [ + {"a c": string `carriage return${"\r"} carriage return`, b: 4} + ]); +} + +@test:Config +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); + test:assertTrue(rec is record {string a; int b;}[]); + // TODO: Add tests after supports \f by Ballerina +} diff --git a/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal b/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal index 56bd093..495180a 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 @@ -122,12 +122,10 @@ type SubtypeTuple3 [SubType...]; function testSubtypeExpectedTypes() returns error? { var value1 = [{a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}, {a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}]; - var value2 = [{a: 1, c: int:MAX_VALUE, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}, - {a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}]; + var value2 = [["1", "1", "1", "1", "a", "1", "1", "1"], + ["1", "1", "1", "1", "a", "1", "1", "1"]]; var value3 = [[1, 1, 1, 1, "a", 1, 1, 1], [1, 1, 1, 1, "a", 1, 1, 1]]; - var value4 = [["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 1, 1, 1, 1, a, 1, 1, 1 @@ -182,24 +180,24 @@ function testSubtypeExpectedTypes() returns error? { ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a12, value3); - SubtypeRecord[]|csv:Error a13 = csv:parseListAsRecordType(value4, + SubtypeRecord[]|csv:Error a13 = csv:parseListAsRecordType(value2, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a13, value1); - SubtypeRecord2[]|csv:Error a14 = csv:parseListAsRecordType(value4, + SubtypeRecord2[]|csv:Error a14 = csv:parseListAsRecordType(value2, ["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(value4, + SubtypeRecord3[]|csv:Error a15 = csv:parseListAsRecordType(value2, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a15, value1); - SubtypeTuple[]|csv:Error a16 = csv:parseListAsListType(value4, {}); + SubtypeTuple[]|csv:Error a16 = csv:parseListAsListType(value2, {}); test:assertEquals(a16, value3); - SubtypeTuple2[]|csv:Error a17 = csv:parseListAsListType(value4, {}); + SubtypeTuple2[]|csv:Error a17 = csv:parseListAsListType(value2, {}); test:assertEquals(a17, [[1, 1], [1, 1]]); - SubtypeTuple3[]|csv:Error a18 = csv:parseListAsListType(value4, {}); + SubtypeTuple3[]|csv:Error a18 = csv:parseListAsListType(value2, {}); test:assertEquals(a18, value3); } 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 5649d3d..250fcc4 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 @@ -116,7 +116,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { record {}[]|csv:Error csv2op6_2 = csv:parseStringToRecord(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: "// 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: ()}, @@ -136,7 +136,8 @@ function testHeaderOption() { ]); record {}[]|csv:Error csv2cop2 = csv:parseStringToRecord(csvStringData2, {header: 100}); - test:assertEquals(csv2cop2, []); + test:assertTrue(csv2cop2 is csv:Error); + test:assertEquals(( csv2cop2).message(), "The provided header row is empty"); record {}[]|csv:Error csv2cop3 = csv:parseStringToRecord(csvStringData2, {header: 11}); test:assertEquals(csv2cop3, []); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 3f026c5..d583314 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -137,6 +137,8 @@ static class StateMachine { boolean isQuoteClosed = false; boolean isIntersectionElementType = false; private StringBuilder hexBuilder = new StringBuilder(4); + boolean isValueStart = false; + State prevState; StateMachine() { reset(); } @@ -168,6 +170,7 @@ public void reset() { hexBuilder = new StringBuilder(4); isQuoteClosed = false; isIntersectionElementType = false; + prevState = null; } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -345,6 +348,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (ch == EOF) { + handleEndOfTheHeader(sm); + return HEADER_END_STATE; + } if (ch == Constants.LineTerminator.CR) { CsvUtils.setCarriageTokenPresent(true); continue; @@ -367,6 +374,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C state = HEADER_END_STATE; break; } + state = this; continue; } @@ -375,11 +383,14 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } else if (!sm.insideComment && ch == separator) { addHeader(sm); sm.columnIndex++; + state = this; continue; } else if (!sm.insideComment && ch == sm.config.textEnclosure) { + sm.prevState = this; state = HEADER_QUOTE_CHAR_STATE; break; } else if (!sm.insideComment && ch == sm.config.escapeChar) { + sm.prevState = this; state = HEADER_ESCAPE_CHAR_STATE; break; } else if (sm.insideComment && sm.isNewLineOrEof(ch)) { @@ -390,11 +401,15 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C handleEndOfTheHeader(sm); state = HEADER_END_STATE; } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { + if (sm.isValueStart) { + sm.append(ch); + } state = this; continue; } else { if (!sm.insideComment) { sm.append(ch); + sm.isValueStart = true; } state = this; continue; @@ -407,8 +422,13 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } private static void handleEndOfTheHeader(StateMachine sm) throws CsvParserException { + handleEndOfTheHeader(sm, true); + } + + private static void handleEndOfTheHeader(StateMachine sm, boolean trim) throws CsvParserException { + sm.isValueStart = false; if (!sm.peek().isBlank()) { - addHeader(sm); + addHeader(sm, trim); } finalizeHeaders(sm); sm.columnIndex = 0; @@ -456,8 +476,16 @@ private static void validateRemainingRecordFields(StateMachine sm) { } } - private static void addHeader(StateMachine sm) throws CsvParserException { + private static void addHeader(StateMachine sm) { + addHeader(sm, true); + } + + private static void addHeader(StateMachine sm, boolean trim) { + sm.isValueStart = false; String value = sm.value(); + if (trim) { + value = value.trim(); + } if (sm.expectedArrayElementType instanceof RecordType) { String fieldName = CsvUtils.getUpdatedHeaders( sm.updatedRecordFieldNames, value, sm.fields.contains(value)); @@ -472,16 +500,17 @@ private static void addHeader(StateMachine sm) throws CsvParserException { private static class HeaderEndState 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) { return ROW_START_STATE; } } private static class RowStartState implements State { + char ch; + State state = ROW_START_STATE; + @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { - char ch; - State state = ROW_START_STATE; char separator = sm.config.delimiter; long[] skipLines = getSkipDataRows(sm.config.skipLines); @@ -505,6 +534,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } } else { sm.append(ch); + sm.isValueStart = true; } continue; } @@ -518,7 +548,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C initiateNewRowType(sm); } if (!sm.insideComment && ch == sm.config.comment) { - handleEndOfTheRow(sm, ch); + handleEndOfTheRow(sm); sm.insideComment = true; if (ch == EOF) { state = ROW_END_STATE; @@ -526,9 +556,11 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } else if (!sm.insideComment && ch == separator) { addRowValue(sm); } else if (!sm.insideComment && ch == sm.config.textEnclosure) { + sm.prevState = this; state = STRING_QUOTE_CHAR_STATE; break; } else if (!sm.insideComment && ch == sm.config.escapeChar) { + sm.prevState = this; state = STRING_ESCAPE_VALUE_STATE; break; } else if (sm.insideComment && sm.isNewLineOrEof(ch)) { @@ -538,16 +570,21 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C break; } } else if (isEndOfTheRowAndValueIsNotEmpty(sm, ch)) { - handleEndOfTheRow(sm, ch); + handleEndOfTheRow(sm); if (ch == EOF) { state = ROW_END_STATE; break; } } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { + if (sm.isValueStart) { + sm.append(ch); + } + state = this; // ignore } else { if (!sm.insideComment) { sm.append(ch); + sm.isValueStart = true; } } } @@ -556,13 +593,23 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } } - private static void handleEndOfTheRow(StateMachine sm, char ch) throws CsvParserException { - handleCsvRow(sm); + private static void handleEndOfTheRow(StateMachine sm) throws CsvParserException { + handleEndOfTheRow(sm, true); + } + + private static void handleEndOfTheRow(StateMachine sm, boolean trim) throws CsvParserException { + sm.isValueStart = false; + handleCsvRow(sm, trim); checkRequiredFieldsAndLogError(sm.fieldHierarchy, sm.config.absentAsNilableType); } - private static void handleCsvRow(StateMachine sm) throws CsvParserException { - if (!sm.peek().isBlank()) { - addRowValue(sm); + + private static void handleCsvRow(StateMachine sm, boolean trim) throws CsvParserException { + String value = sm.peek(); + if (trim) { + value = value.trim(); + } + if (!value.isBlank()) { + addRowValue(sm, trim); } if (!sm.isCurrentCsvNodeEmpty) { finalizeTheRow(sm); @@ -605,10 +652,18 @@ private static void finalizeTheRow(StateMachine sm) { } private static void addRowValue(StateMachine sm) throws CsvParserException { + addRowValue(sm, true); + } + + private static void addRowValue(StateMachine sm, boolean trim) throws CsvParserException { Type type; + Field currentField = null; + sm.isValueStart = false; Type exptype = sm.expectedArrayElementType; String value = sm.value(); - Field currentField = null; + if (trim) { + value = value.trim(); + } if (exptype instanceof RecordType) { type = getExpectedRowTypeOfRecord(sm); @@ -689,7 +744,7 @@ private static Field getCurrentField(StateMachine sm) { private static class RowEndState 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) { return ROW_END_STATE; } } @@ -704,6 +759,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (ch == EOF) { + handleEndOfTheRow(sm, false); + return ROW_END_STATE; + } if (ch == Constants.LineTerminator.CR) { CsvUtils.setCarriageTokenPresent(true); continue; @@ -714,25 +773,23 @@ public State transition(StateMachine sm, char[] buff, int i, int count) if (ch == sm.config.textEnclosure) { if (sm.isQuoteClosed) { sm.append(ch); + sm.isValueStart = true; continue; } sm.isQuoteClosed = true; } else if (ch == sm.config.delimiter && sm.isQuoteClosed) { - addRowValue(sm); + addRowValue(sm, false); state = ROW_START_STATE; sm.isQuoteClosed = false; break; } else if (sm.isNewLineOrEof(ch) && sm.isQuoteClosed) { - handleEndOfTheRow(sm, ch); - if (ch == EOF) { - state = ROW_END_STATE; - break; - } + handleEndOfTheRow(sm, false); state = ROW_START_STATE; sm.isQuoteClosed = false; break; } else if (ch == sm.config.escapeChar) { state = STRING_ESCAPE_VALUE_STATE; + sm.prevState = this; sm.isQuoteClosed = false; break; } else if (!sm.isQuoteClosed && !sm.peek().isEmpty() && ch == EOF) { @@ -745,6 +802,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) sm.append(ch); sm.isQuoteClosed = false; } + sm.isValueStart = true; state = this; } } @@ -763,6 +821,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (ch == EOF) { + handleEndOfTheRow(sm); + return ROW_END_STATE; + } if (ch == Constants.LineTerminator.CR) { CsvUtils.setCarriageTokenPresent(true); continue; @@ -773,18 +835,19 @@ public State transition(StateMachine sm, char[] buff, int i, int count) if (ch == sm.config.textEnclosure) { sm.isQuoteClosed = true; } else if (ch == sm.config.delimiter && sm.isQuoteClosed) { - addHeader(sm); + addHeader(sm, false); sm.columnIndex++; sm.isQuoteClosed = false; state = HEADER_START_STATE; break; } else if (sm.isNewLineOrEof(ch) && sm.isQuoteClosed) { - handleEndOfTheHeader(sm); + handleEndOfTheHeader(sm, false); state = HEADER_END_STATE; sm.isQuoteClosed = false; break; } else if (!sm.isQuoteClosed && ch == sm.config.escapeChar) { sm.isQuoteClosed = false; + sm.prevState = this; state = HEADER_ESCAPE_CHAR_STATE; break; } else if (!sm.isQuoteClosed && ch == EOF) { @@ -797,6 +860,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) sm.append(ch); sm.isQuoteClosed = false; } + sm.isValueStart = true; state = this; continue; } @@ -811,7 +875,7 @@ private static class StringValueUnicodeHexProcessingState extends UnicodeHexProc @Override protected State getSourceState() { - return STRING_QUOTE_CHAR_STATE; + return STRING_UNICODE_CHAR_STATE; } } @@ -824,7 +888,7 @@ private static class HeaderUnicodeHexProcessingState extends UnicodeHexProcessin @Override protected State getSourceState() { - return HEADER_QUOTE_CHAR_STATE; + return HEADER_UNICODE_CHAR_STATE; } } @@ -842,6 +906,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (ch == EOF) { + handleEndOfTheRow(sm); + return ROW_END_STATE; + } if (ch == Constants.LineTerminator.CR) { CsvUtils.setCarriageTokenPresent(true); continue; @@ -851,10 +919,12 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) { sm.hexBuilder.append(ch); + sm.isValueStart = true; if (sm.hexBuilder.length() >= 4) { sm.append(this.extractUnicodeChar(sm)); this.reset(sm); - state = this.getSourceState(); + state = sm.prevState; + sm.prevState = this; break; } state = this; @@ -882,16 +952,15 @@ private static class HeaderEscapedCharacterProcessingState extends EscapedCharac @Override protected State getSourceState() { - return HEADER_QUOTE_CHAR_STATE; + return HEADER_ESCAPE_CHAR_STATE; } - } private static class StringValueEscapedCharacterProcessingState extends EscapedCharacterProcessingState { @Override protected State getSourceState() { - return STRING_QUOTE_CHAR_STATE; + return STRING_ESCAPE_VALUE_STATE; } } @@ -911,38 +980,42 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { CsvUtils.setCarriageTokenPresent(false); } + if (ch == EOF) { + handleEndOfTheRow(sm); + return ROW_END_STATE; + } switch (ch) { case '"': sm.append(QUOTES); - state = this.getSourceState(); + state = sm.prevState; break; case '\\': sm.append(REV_SOL); - state = this.getSourceState(); + state = sm.prevState; break; case '/': sm.append(SOL); - state = this.getSourceState(); + state = sm.prevState; break; case 'b': sm.append(BACKSPACE); - state = this.getSourceState(); + state = sm.prevState; break; case 'f': sm.append(FORMFEED); - state = this.getSourceState(); + state = sm.prevState; break; case 'n': sm.append(NEWLINE); - state = this.getSourceState(); + state = sm.prevState; break; case 'r': sm.append(CR); - state = this.getSourceState(); + state = sm.prevState; break; case 't': sm.append(HZ_TAB); - state = this.getSourceState(); + state = sm.prevState; break; case 'u': if (this.getSourceState() == STRING_ESCAPE_VALUE_STATE) { From 916eff1a2d4e8ed8e876d4eed735ee58db978a5a Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 12 Jul 2024 13:25:39 +0530 Subject: [PATCH 062/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c07b540..c995088 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,7 +12,8 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"} + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "test"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -26,3 +27,52 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + From fba132a51f947c1fa286723c271785af85587eb7 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Sat, 13 Jul 2024 02:40:34 +0530 Subject: [PATCH 063/147] Add tests for array indexes --- ballerina-tests/build.gradle | 4 +- .../tests/parse_string_to_array_test.bal | 125 ++++++++++++++++++ .../stdlib/data/csvdata/csv/CsvParser.java | 7 +- .../stdlib/data/csvdata/csv/CsvTraversal.java | 81 +++++++++--- 4 files changed, 197 insertions(+), 20 deletions(-) diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index 07f7576..2f401db 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -32,8 +32,8 @@ 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.stdlib.data.*:ballerina.*" -def testPackages = ["user-config-tests", "type-compatible-tests", "unicode-tests", "constraint-validation-tests", "parse-list-types-tests", "parse-record-types-tests", - "parse-string-array-types-tests", "parse-string-record-types-tests", "union-type-tests"] +def testPackages = ["parse-string-array-types-tests", "user-config-tests", "type-compatible-tests", "unicode-tests", "constraint-validation-tests", + "parse-list-types-tests", "parse-record-types-tests", "parse-string-record-types-tests", "union-type-tests"] def testCommonPackage = "csv-commons" def stripBallerinaExtensionVersion(String extVersion) { 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 eec62d6..ce7d4c5 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 @@ -309,3 +309,128 @@ function testFromCsvStringWithTypeForStringAndArrayAsExpectedType3() { test:assertTrue(cv7daa is csv:Error); test:assertEquals((cv7daa).message(), common:generateErrorMessageForInvalidCast("true", "decimal")); } + +@test:Config +function testArrayIndexes() { + string csv = string `a, b + 1, 2 + 3, 4 + 5, 6 + 7, 8`; + + string csv2 = string `a, b + 1, 2, 3 + 3, 4, 5 + 5, 6, 7 + 7, 8, 9`; + + record {}[2]|error rec = csv:parseStringToRecord(csv); + test:assertEquals(rec, [ + {a: 1, b: 2}, + {a: 3, b: 4} + ]); + + map[2]|error rec_2 = csv:parseStringToRecord(csv); + test:assertEquals(rec_2, [ + {a: 1, b: 2}, + {a: 3, b: 4} + ]); + + record {|int a;|}[2]|error rec2 = csv:parseStringToRecord(csv, {skipLines: [2]}); + test:assertEquals(rec2, [ + {a: 1}, + {a: 5} + ]); + + record {|int a;|}[5]|error rec2_2 = csv:parseStringToRecord(csv, {skipLines: [2]}); + test:assertTrue(rec2_2 is csv:Error); + + int[][2]|error rec3 = csv:parseStringToList(csv2); + test:assertEquals(rec3, [ + [1, 2], + [3, 4], + [5, 6], + [7, 8] + ]); + + [int, int][2]|error rec3_2 = csv:parseStringToList(csv2); + test:assertEquals(rec3_2, [ + [1, 2], + [3, 4] + ]); + + [int...][2]|error rec3_3 = csv:parseStringToList(csv2); + test:assertEquals(rec3_3, [ + [1, 2, 3], + [3, 4, 5] + ]); + + int[1][2]|error rec4 = csv:parseStringToList(csv2, {skipLines: [2]}); + test:assertEquals(rec4, [ + [1, 2] + ]); + + int[2][]|error rec5 = csv:parseStringToList(csv2); + test:assertEquals(rec5, [ + [1, 2, 3], + [3, 4, 5] + ]); +} + +@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]|error rec = csv:parseRecordAsRecordType(csv); + test:assertEquals(rec, [ + {a: 1, b: 2}, + {a: 3, b: 4} + ]); + + map[2]|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} + ]); + + record {|int a;|}[2]|error rec2 = csv:parseRecordAsRecordType(csv, {skipLines: [2]}); + test:assertEquals(rec2, [ + {a: 1}, + {a: 5} + ]); + + record {|int a;|}[5]|error rec2_2 = csv:parseRecordAsRecordType(csv, {skipLines: [2]}); + test:assertTrue(rec2_2 is csv:Error); + + int[][2]|error rec3 = csv:parseRecordAsListType(csv, ["a", "b"]); + test:assertEquals(rec3, [ + [1, 2], + [3, 4], + [5, 6], + [7, 8] + ]); + + [int, int][2]|error rec3_2 = csv:parseListAsListType(csv2); + test:assertEquals(rec3_2, [ + [1, 2], + [3, 4] + ]); + + [int...][2]|error rec3_3 = csv:parseRecordAsListType(csv, ["a", "b"], {skipLines: [1]}); + test:assertEquals(rec3_3, [ + [3, 4], + [5, 6] + ]); + + int[1][2]|error rec4 = csv:parseRecordAsListType(csv, ["a", "b"], {skipLines: [2]}); + test:assertEquals(rec4, [ + [1, 2] + ]); + + int[2][]|error rec5 = csv:parseListAsListType(csv2); + test:assertEquals(rec5, [ + [1, 2, 3], + [3, 4, 5] + ]); +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index d583314..7041ebe 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -139,6 +139,7 @@ static class StateMachine { private StringBuilder hexBuilder = new StringBuilder(4); boolean isValueStart = false; State prevState; + int arraySize = 0; StateMachine() { reset(); } @@ -171,6 +172,7 @@ public void reset() { isQuoteClosed = false; isIntersectionElementType = false; prevState = null; + arraySize = 0; } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -646,9 +648,12 @@ private static void initiateNewRowType(StateMachine sm) { private static void finalizeTheRow(StateMachine sm) { int rootArraySize = sm.rootArrayType.getSize(); - if (rootArraySize == -1 || sm.rowIndex < rootArraySize) { + if (rootArraySize == -1) { sm.rootCsvNode.append(sm.currentCsvNode); + } else if (sm.arraySize < rootArraySize) { + sm.rootCsvNode.add(sm.arraySize, sm.currentCsvNode); } + sm.arraySize++; } private static void addRowValue(StateMachine sm) throws CsvParserException { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java index 0f6090f..091a4b8 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java @@ -112,6 +112,7 @@ static class CsvTree { Type sourceArrayElementType; CsvConfig config; String[] headers = null; + int arraySize = 0; void reset() { currentCsvNode = null; @@ -127,6 +128,23 @@ void reset() { sourceArrayElementType = null; config = null; headers = null; + arraySize = 0; + } + + + void resetForUnionTypes() { + currentCsvNode = null; + currentField = null; + fieldHierarchy.clear(); + updatedRecordFieldNames.clear(); + headerFieldHierarchy.clear(); + fields.clear();; + restType = null; + fieldNames.clear(); + rootCsvNode = null; + expectedArrayElementType = null; + headers = null; + arraySize = 0; } CsvTree() { @@ -163,23 +181,24 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { int expectedArraySize = ((ArrayType) referredType).getSize(); setRootCsvNodeForNonUnionArrays(referredType, type); validateExpectedArraySize(expectedArraySize, sourceArraySize); - traverseCsvWithExpectedType(expectedArraySize, sourceArraySize, csv, type); + traverseCsvWithExpectedType(sourceArraySize, csv, type); } else { - traverseCsvWithUnionExpectedType(referredType, type, sourceArraySize, csv, config); + traverseCsvWithUnionExpectedType(referredType, type, sourceArraySize, csv); } return rootCsvNode; } private void traverseCsvWithUnionExpectedType(Type referredType, Type type, int sourceArraySize, - BArray csv, CsvConfig config) { + BArray csv) { for (Type memberType: ((UnionType) referredType).getMemberTypes()) { Type mType = TypeUtils.getReferredType(memberType); if (mType.getTag() == TypeTags.ARRAY_TAG) { int expectedArraySize = ((ArrayType) mType).getSize(); + resetForUnionTypes(); try { setRootCsvNodeForNonUnionArrays(mType, mType); validateExpectedArraySize(expectedArraySize, sourceArraySize); - traverseCsvWithExpectedType(expectedArraySize, sourceArraySize, csv, type); + traverseCsvWithExpectedType(sourceArraySize, csv, type); return; } catch (Exception ex) { // ignore @@ -189,7 +208,7 @@ private void traverseCsvWithUnionExpectedType(Type referredType, Type type, int throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); } - private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArraySize, + private void traverseCsvWithExpectedType(int sourceArraySize, BArray csv, Type type) { boolean isIntersection = false; if (expectedArrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { @@ -203,18 +222,17 @@ private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArrayS switch (expectedArrayElementType.getTag()) { case TypeTags.RECORD_TYPE_TAG: case TypeTags.MAP_TAG: - case TypeTags.TABLE_TAG: - traverseCsvArrayMembersWithMapAsCsvElementType(expectedArraySize == -1 ? - sourceArraySize : expectedArraySize, csv, expectedArrayElementType, isIntersection); + traverseCsvArrayMembersWithMapAsCsvElementType(sourceArraySize, csv, + expectedArrayElementType, isIntersection); break; case TypeTags.ARRAY_TAG: case TypeTags.TUPLE_TAG: - traverseCsvArrayMembersWithArrayAsCsvElementType(expectedArraySize == -1 ? - sourceArraySize : expectedArraySize, csv, expectedArrayElementType, isIntersection); + traverseCsvArrayMembersWithArrayAsCsvElementType(sourceArraySize, csv, + expectedArrayElementType, isIntersection); break; case TypeTags.UNION_TAG: - traverseCsvArrayMembersWithUnionAsCsvElementType(expectedArraySize == -1 ? - sourceArraySize : expectedArraySize, csv, (UnionType) expectedArrayElementType, type); + traverseCsvArrayMembersWithUnionAsCsvElementType(sourceArraySize, csv, + (UnionType) expectedArrayElementType, type); break; case TypeTags.INTERSECTION_TAG: for (Type constituentType : ((IntersectionType) expectedArrayElementType).getConstituentTypes()) { @@ -234,41 +252,61 @@ private void traverseCsvWithExpectedType(int expectedArraySize, int sourceArrayS public void traverseCsvArrayMembersWithMapAsCsvElementType(long length, BArray csv, Type expectedArrayType, boolean isIntersection) { Object rowValue; + ArrayType arrayType = (ArrayType) rootCsvNode.getType(); 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 = traverseCsvElementWithMapOrRecord(csv.get(i), expectedArrayType); if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } - rootCsvNode.append(rowValue); + rootCsvNode.add(this.arraySize, rowValue); + this.arraySize++; } } public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray csv, Type expectedArrayType, boolean isIntersection) { Object rowValue; + ArrayType arrayType = (ArrayType) rootCsvNode.getType(); 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); if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } - rootCsvNode.append(rowValue); + rootCsvNode.add(this.arraySize, rowValue); + this.arraySize++; } } public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray csv, UnionType expectedArrayType, Type type) { Object rowValue; + ArrayType arrayType = (ArrayType) rootCsvNode.getType(); for (int i = 0; i < length; i++) { boolean isCompatible = false; if (ignoreRow(i + 1, config.skipLines)) { continue; } + if (arrayType.getState() == ArrayType.ArrayState.CLOSED && + arrayType.getSize() - 1 < this.arraySize) { + break; + } + Object csvData = csv.get(i); for (Type memberType: expectedArrayType.getMemberTypes()) { boolean isIntersection = false; @@ -294,7 +332,8 @@ public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } - rootCsvNode.append(rowValue); + rootCsvNode.add(this.arraySize, rowValue); + this.arraySize++; isCompatible = true; break; } catch (Exception e) { @@ -484,7 +523,7 @@ private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, BArray csvE if (type instanceof TupleType) { return checkExpectedTypeMatchWithHeadersForTuple(expectedType, (TupleType) type); } else { - return checkExpectedTypeMatchWithHeadersForArray(expectedType, csvElement.getElementType(), arraySize); + return checkExpectedTypeMatchWithHeadersForArray(expectedType); } } @@ -530,7 +569,7 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Tup return false; } - private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType, Type arrayType, int arraySize) { + private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType) { if (expectedType instanceof RecordType) { if (this.restType != null) { return true; @@ -723,7 +762,15 @@ private void addCurrentFieldValue(Type type, Object recValue, BString key, boole public void addValuesToArrayType(Object arrayValue, Type type, int index, Object currentCsvNode, CsvConfig config) { Object value = getFieldValue(type, arrayValue, false); + boolean isArrayType = type instanceof ArrayType; if (!(value instanceof UnMappedValue)) { + if (isArrayType) { + ArrayType arrayType = (ArrayType) TypeUtils.getType(type); + if (arrayType.getState() == ArrayType.ArrayState.CLOSED && + arrayType.getSize() - 1 < index) { + return; + } + } ((BArray) currentCsvNode).add(index, value); return; } From 6c1c4053627968cc674c29c8124324ad61ddce5d Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Sat, 13 Jul 2024 02:43:06 +0530 Subject: [PATCH 064/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 +------------------------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c995088..c07b540 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,8 +12,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "test"} + {org = "ballerina", name = "jballerina.java"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -27,52 +26,3 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - From faa687a9feb09b54533f9d12a91e42bd3926be79 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 15 Jul 2024 23:29:24 +0530 Subject: [PATCH 065/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c07b540..c995088 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,7 +12,8 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"} + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "test"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -26,3 +27,52 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + From efeba4019e0e57acc86524c456a2088e0fcda24e Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 15 Jul 2024 23:55:39 +0530 Subject: [PATCH 066/147] Update state parameter for default states --- .../stdlib/data/csvdata/csv/CsvParser.java | 61 ++++++++++++------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 7041ebe..683cf1e 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -49,7 +49,6 @@ import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Stack; import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.checkAndAddCustomHeaders; import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.getHeaderValueForColumnIndex; @@ -111,7 +110,6 @@ static class StateMachine { private static final char LINE_BREAK = '\n'; Object currentCsvNode; - Stack currentEscapeCharacters = new Stack<>(); ArrayList headers = new ArrayList<>(); BArray rootCsvNode; Map fieldHierarchy = new HashMap<>(); @@ -135,42 +133,42 @@ static class StateMachine { boolean isCurrentCsvNodeEmpty = true; boolean isHeaderConfigExceedLineNumber = false; boolean isQuoteClosed = false; - boolean isIntersectionElementType = false; private StringBuilder hexBuilder = new StringBuilder(4); boolean isValueStart = false; State prevState; int arraySize = 0; + StateMachine() { reset(); } public void reset() { - index = 0; currentCsvNode = null; - line = 1; - column = 0; - restType = null; + headers = new ArrayList<>(); rootCsvNode = null; - columnIndex = 0; - rowIndex = 1; fieldHierarchy.clear(); updatedRecordFieldNames.clear(); fields.clear(); fieldNames.clear(); - rootArrayType = null; - config = null; - lineNumber = 0; - expectedArrayElementType = null; - headers = new ArrayList<>(); - currentEscapeCharacters = new Stack<>(); charBuff = new char[1024]; charBuffIndex = 0; + index = 0; + line = 1; + column = 0; + restType = null; + expectedArrayElementType = null; + columnIndex = 0; + rowIndex = 1; + lineNumber = 0; + rootArrayType = null; + config = null; skipTheRow = false; + insideComment = false; isCurrentCsvNodeEmpty = true; isHeaderConfigExceedLineNumber = false; - hexBuilder = new StringBuilder(4); isQuoteClosed = false; - isIntersectionElementType = false; + hexBuilder = new StringBuilder(4); + isValueStart = false; prevState = null; arraySize = 0; } @@ -382,6 +380,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C if (ch == sm.config.comment) { sm.insideComment = true; + state = this; } else if (!sm.insideComment && ch == separator) { addHeader(sm); sm.columnIndex++; @@ -418,6 +417,9 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } break; } + if (state == null) { + state = this; + } sm.index = i + 1; return state; } @@ -532,7 +534,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.skipTheRow = false; sm.clear(); if (ch == EOF) { - state = ROW_END_STATE; + return ROW_END_STATE; } } else { sm.append(ch); @@ -552,11 +554,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C if (!sm.insideComment && ch == sm.config.comment) { handleEndOfTheRow(sm); sm.insideComment = true; - if (ch == EOF) { - state = ROW_END_STATE; - } + state = this; } else if (!sm.insideComment && ch == separator) { addRowValue(sm); + state = this; } else if (!sm.insideComment && ch == sm.config.textEnclosure) { sm.prevState = this; state = STRING_QUOTE_CHAR_STATE; @@ -588,8 +589,12 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.append(ch); sm.isValueStart = true; } + state = this; } } + if (state == null) { + state = this; + } sm.index = i + 1; return state; } @@ -615,10 +620,10 @@ private static void handleCsvRow(StateMachine sm, boolean trim) throws CsvParser } if (!sm.isCurrentCsvNodeEmpty) { finalizeTheRow(sm); + updateLineAndColumnIndexes(sm); } else { updateLineAndColumnIndexesWithoutRowIndexes(sm); } - updateLineAndColumnIndexes(sm); } private static void updateLineAndColumnIndexes(StateMachine sm) { @@ -811,6 +816,9 @@ public State transition(StateMachine sm, char[] buff, int i, int count) state = this; } } + if (state == null) { + state = this; + } sm.index = i + 1; return state; } @@ -871,6 +879,9 @@ public State transition(StateMachine sm, char[] buff, int i, int count) } break; } + if (state == null) { + state = this; + } sm.index = i + 1; return state; } @@ -939,6 +950,9 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C StateMachine.throwExpected("hexadecimal value of an unicode character"); break; } + if (state == null) { + state = this; + } sm.index = i + 1; return state; } @@ -1036,6 +1050,9 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C StateMachine.throwExpected("escaped characters"); } } + if (state == null) { + state = this; + } sm.index = i + 1; return state; } From 8e7ce817acd758b58219302dbea253fe29e23385 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 19 Jul 2024 09:47:50 +0530 Subject: [PATCH 067/147] Add ReadMe file for the csv data module --- README.md | 198 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 197 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4021c40..784c665 100644 --- a/README.md +++ b/README.md @@ -1 +1,197 @@ -# Ballerina CSV Data Library +# Ballerina CSV Data Library + +[![Build](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-timestamped-master.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-timestamped-master.yml) +[![codecov](https://codecov.io/gh/ballerina-platform/module-ballerina-data.csv/branch/main/graph/badge.svg)](https://codecov.io/gh/ballerina-platform/module-ballerina-data.csv) +[![Trivy](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/trivy-scan.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/trivy-scan.yml) +[![GraalVM Check](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-with-bal-test-graalvm.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-with-bal-test-graalvm.yml) +[![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerina-data.csv.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/commits/master) +[![Github issues](https://img.shields.io/github/issues/ballerina-platform/ballerina-standard-library/module/data.csv.svg?label=Open%20Issues)](https://github.com/ballerina-platform/ballerina-standard-library/labels/module%2Fdata.csv) + +The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate the handling and manipulation of CSV data within Ballerina applications. It streamlines the process of converting CSV data to native Ballerina data types, enabling developers to work with CSV content seamlessly and efficiently. + +## 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. + +## Usage + +### Converting CSV string to a record array + +To convert an CSV document value to a record value, you can utilize the `parseStringToRecord` function provided by the library. The example below showcases the transformation of a CSV document into a record array. + +```ballerina +import ballerina/data.csv; +import ballerina/io; + +type Book record { + string name; + string author; + int year; +}; + +public function main() returns error? { + string csvString = string `name,author,year + Clean Code,Robert C. Martin,2008 + The Pragmatic Programmer,Andrew Hunt and David Thomas,1999`; + + Book[] books = check csv:parseStringToRecord(csvString); + foreach var book in books { + io:println(book); + } +} +``` + +### 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. + +```ballerina +import ballerina/data.csv; +import ballerina/io; + +type Book record { + string name; + string author; + int year; +}; + +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); + 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); + io:println(book2); +} +``` + +Make sure to handle possible errors that may arise during the file reading or CSV to record/array conversion process. The `check` keyword is utilized to handle these errors, but more sophisticated error handling can be implemented as per your requirements. + +## 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. + +```ballerina +import ballerina/data.csv; +import ballerina/io; + +type Book record { + string name; + int year; +}; + +public function main() returns error? { + string[][] bookArray = [["Clean Code","2008"],["Clean Architecture","2017"]]; + + Book[] author = check csv:parseListAsRecordType(bookArray, customHeaders = ["name", "year"]); + io:println(author); +} +``` + +### Controlling the CSV value to record array conversion + +The library allows for selective conversion of CSV into closed record arrays. This is beneficial when the CSV data contains headers that are not necessary to be transformed into record fields. + +```ballerina +import ballerina/data.csv; +import ballerina/io; + +type Book record {| + string name; + string author; +|}; + +public function main() returns error? { + record{}[] csvContent = [{ + "name": "Clean Code", + "author": "Robert C. Martin", + "year": 2008, + "publisher": "Prentice Hall" + }, { + "name": "The Pragmatic Programmer", + "author": "Andrew Hunt and David Thomas", + "year": 1999, + "publisher": "Addison-Wesley" + }]; + + // 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); + io:println(book); +} +``` + +However, if the rest field is utilized (or if the record type is defined as an open record), all members in the CSV data will be transformed into record fields: + +```ballerina +type Book record { + string name; + string author; +} +``` + +In this instance, all other CSV header values, such as `year` and `publisher` will be transformed into `anydata-typed` fields with the corresponding CSV header as the key-value pair. + +This behavior extends to arrays as well. + +The process of projecting CSV data into a record supports various use cases, including the filtering out of unnecessary members. This functionality is anticipated to be enhanced in the future to accommodate more complex scenarios, such as filtering values based on regular expressions, among others. + +## Issues and projects + +Issues and Projects tabs are disabled for this repository as this is part of the Ballerina library. To report bugs, request new features, start new discussions, view project boards, etc. please visit Ballerina library [parent repository](https://github.com/ballerina-platform/ballerina-library). + +This repository only contains the source code for the package. + +## Building from the source + +### Set up the prerequisites + +1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations). + * [Oracle](https://www.oracle.com/java/technologies/downloads/) + * [OpenJDK](https://adoptium.net/) + +2. Export your GitHub personal access token with the read package permissions as follows. + + export packageUser= + export packagePAT= + +### Building the source + +Execute the commands below to build from source. + +1. To build the library: + + ./gradlew clean build + +2. Publish ZIP artifact to the local `.m2` repository: + + ./gradlew clean build publishToMavenLocal + +3. Publish the generated artifacts to the local Ballerina central repository: + + ./gradlew clean build -PpublishToLocalCentral=true + +4. Publish the generated artifacts to the Ballerina central repository: + + ./gradlew clean build -PpublishToCentral=true + +## Contributing to Ballerina + +As an open source project, Ballerina welcomes contributions from the community. + +For more information, go to the [contribution guidelines](https://github.com/ballerina-platform/ballerina-lang/blob/master/CONTRIBUTING.md). + +## Code of conduct + +All contributors are encouraged to read the [Ballerina code of conduct](https://ballerina.io/code-of-conduct). + +## Useful links + +* Chat live with us via our [Discord server](https://discord.gg/ballerinalang). +* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag. \ No newline at end of file From ba2810d273f1a5ddacd0f5f7d6d1f1935db9d7d9 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 23 Jul 2024 10:06:50 +0530 Subject: [PATCH 068/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 +------------------------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c995088..c07b540 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,8 +12,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "test"} + {org = "ballerina", name = "jballerina.java"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -27,52 +26,3 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - From 66a468f50bbba89a0d1551e9b6681dc1089c5d15 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 23 Jul 2024 10:24:22 +0530 Subject: [PATCH 069/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c07b540..c995088 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,7 +12,8 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"} + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "test"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -26,3 +27,52 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + From d17568b5ed82299ecc7d782e57104b8623bb9938 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 23 Jul 2024 10:28:04 +0530 Subject: [PATCH 070/147] Add locale support for csv data --- ballerina-tests/build.gradle | 2 +- .../user_config_with_parser_options_test.bal | 34 ++- .../stdlib/data/csvdata/FromString.java | 271 ++++++++++-------- .../stdlib/data/csvdata/csv/CsvParser.java | 6 +- .../stdlib/data/csvdata/csv/Native.java | 13 +- .../data/csvdata/io/DataReaderTask.java | 12 +- .../stdlib/data/csvdata/utils/Constants.java | 1 + .../stdlib/data/csvdata/utils/CsvConfig.java | 11 +- .../stdlib/data/csvdata/utils/CsvUtils.java | 13 + 9 files changed, 226 insertions(+), 137 deletions(-) diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index 2f401db..5f973bf 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -32,7 +32,7 @@ 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.stdlib.data.*:ballerina.*" -def testPackages = ["parse-string-array-types-tests", "user-config-tests", "type-compatible-tests", "unicode-tests", "constraint-validation-tests", +def testPackages = ["user-config-tests", "parse-string-array-types-tests", "type-compatible-tests", "unicode-tests", "constraint-validation-tests", "parse-list-types-tests", "parse-record-types-tests", "parse-string-record-types-tests", "union-type-tests"] def testCommonPackage = "csv-commons" 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 250fcc4..26ed7bd 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 @@ -802,7 +802,7 @@ function testEscapeCharactersWithParserOptions() { 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}); - test:assertEquals(cn3, [{"a": 1, "b": 2.0, "c": 3.0}, {"a": 1.0, "b": 2, "c": 3}, {"a": 1, "b": "2\"", "c": 3}, {"a": "1\\", "b": "2\\\"", "c": 3}]); + 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}); test:assertEquals(cn_2, [[1, "2a\t", "3b\n"], ["1c\n", 2, 3], [1, "2a\"", 3], ["1a\\", "2b\\\"", 3]]); @@ -811,7 +811,7 @@ function testEscapeCharactersWithParserOptions() { 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}); - test:assertEquals(cn3_2, [[1, 2.0, 3.0], [1.0, 2, 3], [1, "2\"", 3], ["1\\", "2\\\"", 3]]); + test:assertEquals(cn3_2, [[1, "2\t", "3\n"], ["1\n", 2, 3], [1, "2\"", 3], ["1\\", "2\\\"", 3]]); } @test:Config @@ -858,3 +858,33 @@ function testLineTerminatorWithParserOptions() { cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn2, [[1, "2\n3"]]); } + +@test:Config +function testCSVLocale() { + record {|string name; decimal completed\ tasks; string city;|}[]|csv:Error rec; + + rec = csv:parseStringToRecord(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:Config +function testCSVEncoding() returns error? { + record {}[]|csv:Error rec; + + string csvStr = string `value + Alice + 2πr + €123`; + byte[] csvBytes = string:toBytes(csvStr); + + rec = csv:parseBytesToRecord(csvBytes, {locale: "fr_FR", encoding: "ISO-8859-1"}); + test:assertEquals((check rec)[0], {value: "Alice"}); +} diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java index 24afea6..9ae99bf 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java @@ -35,12 +35,16 @@ import io.ballerina.runtime.api.values.BString; import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; +import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; +import java.math.BigDecimal; +import java.text.DecimalFormatSymbols; +import java.text.NumberFormat; +import java.text.ParseException; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Locale; import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.isNullValue; @@ -50,6 +54,29 @@ * @since 0.1.0 */ public class FromString { + private static Locale locale = null; + private static String intRegex = "^[-+]?[0-9]+$"; + private static String doubleRegex = "^[-+]?[0-9]+(\\.[0-9]*)?(e[+-]?[0-9]+)?$"; + + public static void reset() { + FromString.locale = null; + } + + private static Locale getLocale(CsvConfig config) { + if (locale == null) { + locale = CsvUtils.createLocaleFromString(config.locale); + DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale); + char decimalSeparator = dfs.getDecimalSeparator(); + char minusSign = dfs.getMinusSign(); + char zeroDigit = dfs.getZeroDigit(); + String exponentSeparator = dfs.getExponentSeparator(); + intRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+$"; + doubleRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+(" + + (decimalSeparator == '.' ? "\\." : decimalSeparator) + + "[" + zeroDigit + "-9]*)?(" + exponentSeparator + "[+-]?[" + zeroDigit + "-9]+)?$"; + } + return locale; + } private static final List TYPE_PRIORITY_ORDER = List.of( TypeTags.INT_TAG, @@ -85,50 +112,32 @@ public class FromString { public static Object fromStringWithType(BString string, Type expType, CsvConfig config) { String value = string.getValue(); try { - switch (expType.getTag()) { - case TypeTags.INT_TAG: - return stringToInt(value); - case TypeTags.BYTE_TAG: - return stringToByte(value); - case TypeTags.SIGNED8_INT_TAG: - return stringToSigned8Int(value); - case TypeTags.SIGNED16_INT_TAG: - return stringToSigned16Int(value); - case TypeTags.SIGNED32_INT_TAG: - return stringToSigned32Int(value); - case TypeTags.UNSIGNED8_INT_TAG: - return stringToUnsigned8Int(value); - case TypeTags.UNSIGNED16_INT_TAG: - return stringToUnsigned16Int(value); - case TypeTags.UNSIGNED32_INT_TAG: - return stringToUnsigned32Int(value); - case TypeTags.FLOAT_TAG: - return stringToFloat(value); - case TypeTags.DECIMAL_TAG: - return stringToDecimal(value); - case TypeTags.CHAR_STRING_TAG: - return stringToChar(value); - case TypeTags.STRING_TAG: - return string; - case TypeTags.BOOLEAN_TAG: - return stringToBoolean(value); - case TypeTags.NULL_TAG: - return stringToNull(value, config); - case TypeTags.FINITE_TYPE_TAG: - return stringToFiniteType(value, (FiniteType) expType, config); - case TypeTags.UNION_TAG: - return stringToUnion(string, (UnionType) expType, config); - case TypeTags.JSON_TAG: - case TypeTags.ANYDATA_TAG: - return stringToUnion(string, JSON_TYPE_WITH_BASIC_TYPES, config); - case TypeTags.TYPE_REFERENCED_TYPE_TAG: - return fromStringWithType(string, ((ReferenceType) expType).getReferredType(), config); - case TypeTags.INTERSECTION_TAG: - return fromStringWithType(string, ((IntersectionType) expType).getEffectiveType(), config); - default: - return returnError(value, expType.toString()); - } - } catch (NumberFormatException e) { + return switch (expType.getTag()) { + case TypeTags.INT_TAG -> stringToInt(value, config); + case TypeTags.BYTE_TAG -> stringToByte(value, config); + case TypeTags.SIGNED8_INT_TAG -> stringToSigned8Int(value, config); + case TypeTags.SIGNED16_INT_TAG -> stringToSigned16Int(value, config); + case TypeTags.SIGNED32_INT_TAG -> stringToSigned32Int(value, config); + case TypeTags.UNSIGNED8_INT_TAG -> stringToUnsigned8Int(value, config); + case TypeTags.UNSIGNED16_INT_TAG -> stringToUnsigned16Int(value, config); + case TypeTags.UNSIGNED32_INT_TAG -> stringToUnsigned32Int(value, config); + case TypeTags.FLOAT_TAG -> stringToFloat(value, config); + case TypeTags.DECIMAL_TAG -> stringToDecimal(value, config); + case TypeTags.CHAR_STRING_TAG -> stringToChar(value); + case TypeTags.STRING_TAG -> string; + case TypeTags.BOOLEAN_TAG -> stringToBoolean(value); + case TypeTags.NULL_TAG -> stringToNull(value, config); + case TypeTags.FINITE_TYPE_TAG -> stringToFiniteType(value, (FiniteType) expType, config); + case TypeTags.UNION_TAG -> stringToUnion(string, (UnionType) expType, config); + case TypeTags.JSON_TAG, TypeTags.ANYDATA_TAG -> + stringToUnion(string, JSON_TYPE_WITH_BASIC_TYPES, config); + case TypeTags.TYPE_REFERENCED_TYPE_TAG -> + fromStringWithType(string, ((ReferenceType) expType).getReferredType(), config); + case TypeTags.INTERSECTION_TAG -> + fromStringWithType(string, ((IntersectionType) expType).getEffectiveType(), config); + default -> returnError(value, expType.toString()); + }; + } catch (NumberFormatException | ParseException e) { return returnError(value, expType.toString()); } } @@ -149,86 +158,121 @@ private static Object convertToSingletonValue(String str, Object singletonValue, } } - private static Long stringToInt(String value) throws NumberFormatException { - return Long.parseLong(value); + private static Long stringToInt(String value, CsvConfig config) throws NumberFormatException, ParseException { + Number number = parseNumberValue(value, config); + if (isIntegerValue(value, number)) { + return number.longValue(); + } + throw new NumberFormatException(); } - private static int stringToByte(String value) throws NumberFormatException { - int intValue = Integer.parseInt(value); - if (!isByteLiteral(intValue)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, PredefinedTypes.TYPE_BYTE, value); + private static int stringToByte(String value, CsvConfig config) throws NumberFormatException, ParseException { + Number number = parseNumberValue(value, config); + if (isIntegerValue(value, number)) { + int intValue = parseNumberValue(value, config).intValue(); + if (isByteLiteral(intValue)) { + return intValue; + } } - return intValue; + throw new NumberFormatException(); } - private static long stringToSigned8Int(String value) throws NumberFormatException { - long intValue = Long.parseLong(value); - if (!isSigned8LiteralValue(intValue)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, PredefinedTypes.TYPE_INT_SIGNED_8, value); + private static long stringToSigned8Int(String value, CsvConfig config) throws NumberFormatException, + ParseException { + Number number = parseNumberValue(value, config); + if (isIntegerValue(value, number)) { + long intValue = parseNumberValue(value, config).longValue(); + if (isSigned8LiteralValue(intValue)) { + return intValue; + } } - return intValue; + throw new NumberFormatException(); } - private static long stringToSigned16Int(String value) throws NumberFormatException { - long intValue = Long.parseLong(value); - if (!isSigned16LiteralValue(intValue)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, PredefinedTypes.TYPE_INT_SIGNED_16, value); + private static long stringToSigned16Int(String value, CsvConfig config) throws NumberFormatException, + ParseException { + + Number number = parseNumberValue(value, config); + if (isIntegerValue(value, number)) { + long intValue = parseNumberValue(value, config).longValue(); + if (isSigned16LiteralValue(intValue)) { + return intValue; + } } - return intValue; + throw new NumberFormatException(); } - private static long stringToSigned32Int(String value) throws NumberFormatException { - long intValue = Long.parseLong(value); - if (!isSigned32LiteralValue(intValue)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, PredefinedTypes.TYPE_INT_SIGNED_32, value); + private static long stringToSigned32Int(String value, CsvConfig config) throws NumberFormatException, + ParseException { + Number number = parseNumberValue(value, config); + if (isIntegerValue(value, number)) { + long intValue = parseNumberValue(value, config).longValue(); + if (isSigned32LiteralValue(intValue)) { + return intValue; + } } - return intValue; + throw new NumberFormatException(); } - private static long stringToUnsigned8Int(String value) throws NumberFormatException { - long intValue = Long.parseLong(value); - if (!isUnsigned8LiteralValue(intValue)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, - PredefinedTypes.TYPE_INT_UNSIGNED_8, value); + private static long stringToUnsigned8Int(String value, CsvConfig config) + throws NumberFormatException, ParseException { + Number number = parseNumberValue(value, config); + if (isIntegerValue(value, number)) { + long intValue = parseNumberValue(value, config).longValue(); + if (isUnsigned8LiteralValue(intValue)) { + return intValue; + } } - return intValue; + throw new NumberFormatException(); } - private static long stringToUnsigned16Int(String value) throws NumberFormatException { - long intValue = Long.parseLong(value); - if (!isUnsigned16LiteralValue(intValue)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, - PredefinedTypes.TYPE_INT_UNSIGNED_16, value); + private static long stringToUnsigned16Int(String value, CsvConfig config) + throws NumberFormatException, ParseException { + Number number = parseNumberValue(value, config); + if (isIntegerValue(value, number)) { + long intValue = parseNumberValue(value, config).longValue(); + if (isUnsigned16LiteralValue(intValue)) { + return intValue; + } } - return intValue; + throw new NumberFormatException(); } - private static long stringToUnsigned32Int(String value) throws NumberFormatException { - long intValue = Long.parseLong(value); - if (!isUnsigned32LiteralValue(intValue)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, - PredefinedTypes.TYPE_INT_UNSIGNED_32, value); + private static long stringToUnsigned32Int(String value, CsvConfig config) + throws NumberFormatException, ParseException { + Number number = parseNumberValue(value, config); + if (isIntegerValue(value, number)) { + long intValue = parseNumberValue(value, config).longValue(); + if (isUnsigned32LiteralValue(intValue)) { + return intValue; + } } - return intValue; + throw new NumberFormatException(); } private static BString stringToChar(String value) throws NumberFormatException { - if (!isCharLiteralValue(value)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CAST, - PredefinedTypes.TYPE_STRING_CHAR, value); + if (isCharLiteralValue(value)) { + return StringUtils.fromString(value); } - return StringUtils.fromString(value); + throw new NumberFormatException(); } - private static Double stringToFloat(String value) throws NumberFormatException { - if (hasFloatOrDecimalLiteralSuffix(value)) { - throw new NumberFormatException(); + private static Double stringToFloat(String value, CsvConfig config) throws NumberFormatException, ParseException { + Number number = parseNumberValue(value, config); + if (isDoubleValue(value, number)) { + return number.doubleValue(); } - return Double.parseDouble(value); + throw new NumberFormatException(); } - private static BDecimal stringToDecimal(String value) throws NumberFormatException { - return ValueCreator.createDecimalValue(value); + private static BDecimal stringToDecimal(String value, CsvConfig config) throws NumberFormatException, + ParseException { + Number number = parseNumberValue(value, config); + if (isDoubleValue(value, number)) { + BigDecimal decimalValue = BigDecimal.valueOf(number.doubleValue()); + return ValueCreator.createDecimalValue(decimalValue); + } + throw new NumberFormatException(); } private static Object stringToBoolean(String value) throws NumberFormatException { @@ -271,23 +315,6 @@ private static Object stringToUnion(BString string, UnionType expType, CsvConfig return returnError(string.getValue(), expType.toString()); } - private static boolean hasFloatOrDecimalLiteralSuffix(String value) { - int length = value.length(); - if (length == 0) { - return false; - } - - switch (value.charAt(length - 1)) { - case 'F': - case 'f': - case 'D': - case 'd': - return true; - default: - return false; - } - } - private static boolean isByteLiteral(long longValue) { return (longValue >= BBYTE_MIN_VALUE && longValue <= BBYTE_MAX_VALUE); } @@ -320,7 +347,21 @@ private static boolean isCharLiteralValue(String value) { return value.codePoints().count() == 1; } - private static BError returnError(String string, String expType) { - return ErrorCreator.createError(StringUtils.fromString("Cannot convert to the exptype")); + private static boolean isIntegerValue(String value, Number number) { + return number instanceof Long && value.matches(intRegex); + } + + private static boolean isDoubleValue(String value, Number number) { + return (number instanceof Double || number instanceof Long) && value.matches(doubleRegex); + } + + private static BError returnError(String value, String expType) { + return ErrorCreator.createError(StringUtils + .fromString("Cannot convert " + value + " to the expected type: " + expType)); + } + + private static Number parseNumberValue(String numberString, CsvConfig config) throws ParseException { + NumberFormat numberFormat = NumberFormat.getInstance(getLocale(config)); + return numberFormat.parse(numberString); } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java index 683cf1e..8d42d56 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java @@ -34,6 +34,7 @@ import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BTypedesc; +import io.ballerina.stdlib.data.csvdata.FromString; import io.ballerina.stdlib.data.csvdata.utils.Constants; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; @@ -171,6 +172,7 @@ public void reset() { isValueStart = false; prevState = null; arraySize = 0; + FromString.reset(); } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -296,9 +298,7 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp } } return rootCsvNode; - } catch (IOException e) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TOKEN, e.getMessage(), line, column); - } catch (CsvParserException e) { + } catch (IOException | CsvParserException e) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TOKEN, e.getMessage(), line, column); } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java index dde4144..98f5b3a 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java @@ -37,6 +37,7 @@ import java.io.ByteArrayInputStream; import java.io.InputStreamReader; import java.io.StringReader; +import java.nio.charset.Charset; /** * Csv conversion. @@ -59,7 +60,8 @@ public static Object parseStringToRecord(BString csv, BMap opti public static Object parseBytesToRecord(BArray csv, BMap options, BTypedesc type) { try { byte[] bytes = csv.getBytes(); - return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), + 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; @@ -74,7 +76,8 @@ public static Object parseStreamToRecord(Environment env, BStream csv, final BObject iteratorObj = csv.getIteratorObj(); final Future future = env.markAsync(); DataReaderTask task = new DataReaderTask(env, iteratorObj, future, type, - CsvConfig.createParserToRecordOptions(options)); + CsvConfig.createParserToRecordOptions(options), + options.getStringValue(Constants.ConfigConstants.ENCODING)); DataReaderThreadPool.EXECUTOR_SERVICE.submit(task); return null; } catch (BError e) { @@ -98,7 +101,8 @@ public static Object parseStringToList(BString csv, BMap option public static Object parseBytesToList(BArray csv, BMap options, BTypedesc type) { try { byte[] bytes = csv.getBytes(); - return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes)), + return CsvParser.parse(new InputStreamReader(new ByteArrayInputStream(bytes), + Charset.forName(options.getStringValue(Constants.ConfigConstants.ENCODING).toString())), type, CsvConfig.createParseOptions(options)); } catch (BError e) { return e; @@ -113,7 +117,8 @@ public static Object parseStreamToList(Environment env, BStream csv, final BObject iteratorObj = csv.getIteratorObj(); final Future future = env.markAsync(); DataReaderTask task = new DataReaderTask(env, iteratorObj, future, type, - CsvConfig.createParseOptions(options)); + CsvConfig.createParseOptions(options), + options.getStringValue(Constants.ConfigConstants.ENCODING)); DataReaderThreadPool.EXECUTOR_SERVICE.submit(task); return null; } catch (BError e) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java index 38cd61c..0f9e278 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java @@ -23,12 +23,14 @@ import io.ballerina.runtime.api.types.ObjectType; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BObject; +import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.stdlib.data.csvdata.csv.CsvParser; import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import java.io.InputStreamReader; +import java.nio.charset.Charset; import java.util.function.Consumer; /** @@ -46,13 +48,16 @@ public class DataReaderTask implements Runnable { private final Future future; private final BTypedesc typed; private final CsvConfig config; + private final BString encoding; - public DataReaderTask(Environment env, BObject iteratorObj, Future future, BTypedesc typed, CsvConfig config) { + public DataReaderTask(Environment env, BObject iteratorObj, Future future, BTypedesc typed, + CsvConfig config, BString encoding) { this.env = env; this.iteratorObj = iteratorObj; this.future = future; this.typed = typed; this.config = config; + this.encoding = encoding; } static MethodType resolveNextMethod(BObject iterator) { @@ -84,8 +89,9 @@ public void run() { ResultConsumer resultConsumer = new ResultConsumer<>(future); try (var byteBlockSteam = new BallerinaByteBlockInputStream(env, iteratorObj, resolveNextMethod(iteratorObj), resolveCloseMethod(iteratorObj), resultConsumer)) { - Object result = CsvParser.parse(new InputStreamReader(byteBlockSteam), - typed, this.config); + Object result = CsvParser.parse(new InputStreamReader(byteBlockSteam, + Charset.forName(this.encoding.toString())), + typed, this.config); future.complete(result); } catch (Exception e) { future.complete(DiagnosticLog.getCsvError("Error occurred while reading the stream: " + e.getMessage())); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java index ef16c39..a9dec36 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java @@ -39,4 +39,5 @@ public static class LineTerminator { public static final String FIELD = "$field$."; public static final String NAME = "Name"; public static final BString VALUE = StringUtils.fromString("value"); + public static final String UNDERSCORE = "_"; } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java index 93d19d6..8e772e1 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java @@ -11,7 +11,6 @@ import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.CUSTOM_HEADERS; import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.DELIMITER; import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ENCODING; import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ESCAPE_CHAR; import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.HEADER; import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.LINE_TERMINATOR; @@ -32,7 +31,6 @@ public class CsvConfig { public Object nilValue = null; public char comment = '#'; public String locale = "EN/US"; - public String encoding = "UTF-8"; public boolean nilAsOptionalField = false; public boolean absentAsNilableType = false; public boolean allowDataProjection = true; @@ -51,7 +49,6 @@ private CsvConfig(CsvConfig config) { this.nilValue = config.nilValue; this.comment = config.comment; this.locale = config.locale; - this.encoding = config.encoding; } private CsvConfig(Object skipLines, boolean nilAsOptionalField, @@ -127,7 +124,7 @@ public static CsvConfig createListAsRecordTypeOptions(BMap opti private CsvConfig(char delimiter, char textEnclosure, Object header, char escapeChar, Object lineTerminator, Object skipLines, - Object nilValue, char comment, String locale, String encoding, + Object nilValue, char comment, String locale, boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection) { this.delimiter = delimiter; this.textEnclosure = textEnclosure; @@ -137,7 +134,6 @@ private CsvConfig(char delimiter, char textEnclosure, Object header, this.nilValue = nilValue == null ? null : nilValue; this.comment = comment; this.locale = locale; - this.encoding = encoding; this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; @@ -145,7 +141,7 @@ private CsvConfig(char delimiter, char textEnclosure, Object header, } private CsvConfig(char delimiter, char textEnclosure, Object header, char escapeChar, Object lineTerminator, - Object skipLines, Object nilValue, char comment, String locale, String encoding, + Object skipLines, Object nilValue, char comment, String locale, boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, Object customHeaders, boolean enableConstraintValidation) { this.delimiter = delimiter; @@ -156,7 +152,6 @@ private CsvConfig(char delimiter, char textEnclosure, Object header, char escape this.nilValue = nilValue == null ? null : nilValue; this.comment = comment; this.locale = locale; - this.encoding = encoding; this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; @@ -188,7 +183,6 @@ public static CsvConfig createParseOptions(BMap options) { options.get(NIL_VALUE), StringUtils.getStringValue(options.getStringValue(COMMENT_CHAR)).charAt(0), StringUtils.getStringValue(options.getStringValue(LOCALE)), - StringUtils.getStringValue(options.getStringValue(ENCODING)), options.getBooleanValue(NIL_AS_OPTIONAL), options.getBooleanValue(ABSENT_AS_NILABLE), options.getBooleanValue(ALLOW_DATA_PROJECTION) @@ -207,7 +201,6 @@ public static CsvConfig createParserToRecordOptions(BMap option options.getStringValue(NIL_VALUE), StringUtils.getStringValue(options.getStringValue(COMMENT_CHAR)).charAt(0), StringUtils.getStringValue(options.getStringValue(LOCALE)), - StringUtils.getStringValue(options.getStringValue(ENCODING)), options.getBooleanValue(NIL_AS_OPTIONAL), options.getBooleanValue(ABSENT_AS_NILABLE), options.getBooleanValue(ALLOW_DATA_PROJECTION), diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java index 3f67f06..1a927b5 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java @@ -17,6 +17,7 @@ import java.util.HashMap; import java.util.HashSet; +import java.util.Locale; import java.util.Map; import java.util.Optional; @@ -334,4 +335,16 @@ public static SkipMappedValue createSkippedValue() { return value; } } + + public static Locale createLocaleFromString(String localeString) { + // Split the string into language, country, and variant + String[] parts = localeString.split(Constants.UNDERSCORE); + if (parts.length == 3) { + return new Locale(parts[0], parts[1], parts[2]); + } else if (parts.length == 2) { + return new Locale(parts[0], parts[1]); + } else { + return new Locale(parts[0]); // Only language + } + } } From 16a0ef22f9ee57970e5421fb4f6e272d3d795726 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 26 Jul 2024 11:11:32 +0530 Subject: [PATCH 071/147] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 2 +- ballerina/Dependencies.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index f1d6945..b0a4931 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -6,7 +6,7 @@ authors = ["Ballerina"] keywords = ["csv"] repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" license = ["Apache-2.0"] -distribution = "2201.9.0" +distribution = "2201.10.0-SNAPSHOT" export = ["data.csv"] [platform.java17] diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c995088..18d4435 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.0" +distribution-version = "2201.10.0-SNAPSHOT" [[package]] org = "ballerina" From d7bc2e59a01c1e66f3d80bb3268d9b2e49f0d4fb Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 26 Jul 2024 15:35:03 +0530 Subject: [PATCH 072/147] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 2 +- ballerina/Dependencies.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index b0a4931..f1d6945 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -6,7 +6,7 @@ authors = ["Ballerina"] keywords = ["csv"] repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" license = ["Apache-2.0"] -distribution = "2201.10.0-SNAPSHOT" +distribution = "2201.9.0" export = ["data.csv"] [platform.java17] diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 18d4435..c995088 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0-SNAPSHOT" +distribution-version = "2201.9.0" [[package]] org = "ballerina" From dd4ca57699577fec1687995a920b47101494902e Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 26 Jul 2024 15:42:01 +0530 Subject: [PATCH 073/147] Add french locale to graalvm build options --- ballerina-tests/user-config-tests/Ballerina.toml | 3 +++ ballerina/build.gradle | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ballerina-tests/user-config-tests/Ballerina.toml b/ballerina-tests/user-config-tests/Ballerina.toml index 05c5773..b4d56ea 100644 --- a/ballerina-tests/user-config-tests/Ballerina.toml +++ b/ballerina-tests/user-config-tests/Ballerina.toml @@ -11,3 +11,6 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 7a1da6b..13aed2b 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -129,7 +129,6 @@ task deleteDependencyTomlFiles { } } - updateTomlFiles.dependsOn copyStdlibs build.dependsOn "generatePomFileForMavenPublication" @@ -139,8 +138,6 @@ build.dependsOn ":${packageName}-compiler-plugin:build" build.dependsOn deleteDependencyTomlFiles build.finalizedBy ":${packageName}-ballerina-tests:build" -//build.finalizedBy ":${packageName}-ballerina-tests:ballerinaTest" - test.dependsOn ":${packageName}-native:build" test.dependsOn ":${packageName}-native:build" test.dependsOn ":${packageName}-compiler-plugin:build" From 4659b4350cc5b196381abd657c0a458c50f220bb Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 26 Jul 2024 17:16:45 +0530 Subject: [PATCH 074/147] Add locale build option for build config toml --- build-config/resources/BallerinaTest.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/build-config/resources/BallerinaTest.toml b/build-config/resources/BallerinaTest.toml index 05b0322..2b8bad6 100644 --- a/build-config/resources/BallerinaTest.toml +++ b/build-config/resources/BallerinaTest.toml @@ -11,3 +11,6 @@ version = "@toml.version@" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" From b92cb2c359eb895b81b27c605b8b33897bab2bfc Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 26 Jul 2024 17:27:36 +0530 Subject: [PATCH 075/147] Remove locale configs from user config tests --- ballerina-tests/user-config-tests/Ballerina.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/ballerina-tests/user-config-tests/Ballerina.toml b/ballerina-tests/user-config-tests/Ballerina.toml index b4d56ea..05c5773 100644 --- a/ballerina-tests/user-config-tests/Ballerina.toml +++ b/ballerina-tests/user-config-tests/Ballerina.toml @@ -11,6 +11,3 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true - -[build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" From 04f2e779a8b0da7fadbd01c68fb5b0b2846e0eaf Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 29 Jul 2024 11:48:54 +0530 Subject: [PATCH 076/147] [Automated] Update the native jar versions --- ballerina/CompilerPlugin.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index e503c45..e8419c1 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -1,6 +1,6 @@ [plugin] id = "constraint-compiler-plugin" -class = "io.ballerina.stdlib.data.csvdata.compiler.CsvDataCompilerPlugin" +class = "compiler.io.ballerina.lib.data.csvdata.CsvDataCompilerPlugin" [[dependency]] path = "../compiler-plugin/build/libs/data.csv-compiler-plugin-0.1.0-SNAPSHOT.jar" From 8efea672684678b5bc90787b2078830c85f7b2ea Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 29 Jul 2024 11:52:03 +0530 Subject: [PATCH 077/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 +------------------------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c995088..c07b540 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,8 +12,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "test"} + {org = "ballerina", name = "jballerina.java"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -27,52 +26,3 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - From e370a8536b80701e76f02e2f1ee601249cafd379 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 29 Jul 2024 11:55:25 +0530 Subject: [PATCH 078/147] [Automated] Update the native jar versions --- ballerina/CompilerPlugin.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index e8419c1..c4af7c4 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -1,6 +1,6 @@ [plugin] id = "constraint-compiler-plugin" -class = "compiler.io.ballerina.lib.data.csvdata.CsvDataCompilerPlugin" +class = "io.ballerina.lib.data.csvdata.compiler.CsvDataCompilerPlugin" [[dependency]] path = "../compiler-plugin/build/libs/data.csv-compiler-plugin-0.1.0-SNAPSHOT.jar" From 15c281104180caf46214b2e2eb03e50593fb5536 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 29 Jul 2024 13:54:47 +0530 Subject: [PATCH 079/147] Add licenses for tests & add java17 features for native --- .vscode/launch.json | 28 --- README.md | 4 +- ballerina-tests/build.gradle | 4 +- .../Ballerina.toml | 3 + .../tests/constraint_validation_test.bal | 18 +- ballerina-tests/csv-commons/Ballerina.toml | 3 + ballerina-tests/csv-commons/test_utils.bal | 16 ++ .../parse-list-types-tests/Ballerina.toml | 3 + .../tests/parse_list_type_as_list_test.bal | 18 +- .../tests/parse_list_type_as_record_test.bal | 18 +- .../tests/test_data_values.bal | 16 ++ .../parse-list-types-tests/tests/types.bal | 16 ++ .../parse-record-types-tests/Ballerina.toml | 3 + .../tests/parse_record_type_as_list_test.bal | 18 +- .../parse_record_type_as_record_test.bal | 18 +- .../tests/test_data_values.bal | 16 ++ .../parse-record-types-tests/tests/types.bal | 16 ++ .../Ballerina.toml | 3 + .../tests/parse_string_to_array_test.bal | 18 +- .../tests/parse_string_to_tuple_test.bal | 18 +- .../tests/test_data_values.bal | 16 ++ .../tests/types.bal | 16 ++ .../Ballerina.toml | 3 + ...copy.bal => parse_string_to_map_tests.bal} | 18 +- .../tests/parse_string_to_record_tests.bal | 18 +- .../tests/test_data_values.bal | 16 ++ .../tests/types.bal | 16 ++ .../type-compatible-tests/Ballerina.toml | 3 + .../type-compatible-tests/Dependencies.toml | 23 ++ .../tests/parse_string_compatibality_test.bal | 18 +- .../tests/parse_type_compatibility_test.bal | 18 +- .../tests/test_data_values.bal | 16 ++ .../type-compatible-tests/tests/types.bal | 16 ++ ballerina-tests/unicode-tests/Ballerina.toml | 3 + .../unicode-tests/Dependencies.toml | 88 ++++++++ .../tests/escape_character_test.bal | 18 +- .../union-type-tests/Ballerina.toml | 3 + .../tests/test_data_values.bal | 16 ++ .../tests/test_with_intersection_types.bal | 18 +- .../tests/test_with_singleton_test.bal | 18 +- .../tests/test_with_union_types.bal | 18 +- .../union-type-tests/tests/types.bal | 16 ++ .../user-config-tests/Ballerina.toml | 3 + .../tests/test_data_values.bal | 16 ++ .../user-config-tests/tests/types.bal | 18 +- .../tests/user_config_projection_tests.bal | 18 +- .../user_config_with_parser_options_test.bal | 18 +- .../user-config-tests/tests/user_configs.bal | 18 +- ballerina/Package.md | 198 +++++++++++++++++- ballerina/csv_api.bal | 20 +- ballerina/init.bal | 2 +- build-config/checkstyle/build.gradle | 2 +- build-config/resources/CompilerPlugin.toml | 2 +- build-config/resources/CsvTestCommon.toml | 3 + .../csvdata/compiler/CompilerPluginTest.java | 2 + .../compiler/CompilerPluginTestUtils.java | 2 + .../data/csvdata/compiler/Constants.java | 7 +- .../csvdata/compiler/CsvDataCodeAnalyzer.java | 2 +- .../compiler/CsvDataCompilerPlugin.java | 2 +- .../compiler/CsvDataDiagnosticCodes.java | 6 +- .../compiler/CsvDataTypeValidator.java | 47 +---- .../data/csvdata/FromString.java | 41 ++-- .../data/csvdata/csv/CsvCreator.java | 21 +- .../data/csvdata/csv/CsvParser.java | 162 +++++++------- .../data/csvdata/csv/CsvTraversal.java | 118 +++++------ .../data/csvdata/csv/Native.java | 14 +- .../io/BallerinaByteBlockInputStream.java | 4 +- .../data/csvdata/io/DataReaderTask.java | 8 +- .../data/csvdata/io/DataReaderThreadPool.java | 7 +- .../data/csvdata/utils/Constants.java | 14 +- .../data/csvdata/utils/CsvConfig.java | 130 +++++------- .../data/csvdata/utils/CsvUtils.java | 78 ++++--- .../data/csvdata/utils/DataUtils.java | 2 +- .../csvdata/utils/DiagnosticErrorCode.java | 2 +- .../data/csvdata/utils/DiagnosticLog.java | 4 +- .../data/csvdata/utils/ModuleUtils.java | 2 +- native/src/main/java/module-info.java | 4 +- 77 files changed, 1242 insertions(+), 407 deletions(-) delete mode 100644 .vscode/launch.json rename ballerina-tests/parse-string-record-types-tests/tests/{parse_string_to_map_tests copy.bal => parse_string_to_map_tests.bal} (95%) create mode 100644 ballerina-tests/unicode-tests/Dependencies.toml rename compiler-plugin/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/compiler/Constants.java (93%) rename compiler-plugin/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/compiler/CsvDataCodeAnalyzer.java (95%) rename compiler-plugin/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/compiler/CsvDataCompilerPlugin.java (95%) rename compiler-plugin/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/compiler/CsvDataDiagnosticCodes.java (86%) rename compiler-plugin/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/compiler/CsvDataTypeValidator.java (92%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/FromString.java (92%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/csv/CsvCreator.java (92%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/csv/CsvParser.java (89%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/csv/CsvTraversal.java (87%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/csv/Native.java (94%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/io/BallerinaByteBlockInputStream.java (98%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/io/DataReaderTask.java (94%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/io/DataReaderThreadPool.java (93%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/utils/Constants.java (79%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/utils/CsvConfig.java (63%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/utils/CsvUtils.java (83%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/utils/DataUtils.java (95%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/utils/DiagnosticErrorCode.java (98%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/utils/DiagnosticLog.java (92%) rename native/src/main/java/io/ballerina/{stdlib => lib}/data/csvdata/utils/ModuleUtils.java (96%) diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index 85f0dfd..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,28 +0,0 @@ -{ - "configurations": [ - { - "name": "Ballerina Debug", - "type": "ballerina", - "request": "launch", - "programArgs": [], - "commandOptions": [], - "env": {} - }, - { - "name": "Ballerina Test", - "type": "ballerina", - "request": "launch", - "debugTests": true, - "programArgs": [], - "commandOptions": [], - "env": {} - }, - { - "name": "Ballerina Remote", - "type": "ballerina", - "request": "attach", - "debuggeeHost": "127.0.0.1", - "debuggeePort": "5005" - } - ] -} \ No newline at end of file diff --git a/README.md b/README.md index 784c665..22ff65d 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate ### Converting CSV string to a record array -To convert an CSV document value to a record value, you can utilize the `parseStringToRecord` function provided by the library. The example below showcases the transformation of a CSV document into 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. ```ballerina import ballerina/data.csv; @@ -194,4 +194,4 @@ All contributors are encouraged to read the [Ballerina code of conduct](https:// ## Useful links * Chat live with us via our [Discord server](https://discord.gg/ballerinalang). -* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag. \ No newline at end of file +* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag. diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index 5f973bf..fec5a92 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,8 +18,6 @@ plugins { id 'jacoco' } -//apply plugin: 'java' - import org.apache.tools.ant.taskdefs.condition.Os description = 'Ballerina - HTTP/WS Ballerina Tests' diff --git a/ballerina-tests/constraint-validation-tests/Ballerina.toml b/ballerina-tests/constraint-validation-tests/Ballerina.toml index c0b0817..32c446c 100644 --- a/ballerina-tests/constraint-validation-tests/Ballerina.toml +++ b/ballerina-tests/constraint-validation-tests/Ballerina.toml @@ -11,3 +11,6 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" 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 3710770..fe017b0 100644 --- a/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal +++ b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/constraint; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; type ConstrainedRec record { diff --git a/ballerina-tests/csv-commons/Ballerina.toml b/ballerina-tests/csv-commons/Ballerina.toml index 0b77a15..13c0bc8 100644 --- a/ballerina-tests/csv-commons/Ballerina.toml +++ b/ballerina-tests/csv-commons/Ballerina.toml @@ -2,3 +2,6 @@ org = "ballerina" name = "csv_commons" version = "0.1.0" + +[platform.java17] +graalvmCompatible = true diff --git a/ballerina-tests/csv-commons/test_utils.bal b/ballerina-tests/csv-commons/test_utils.bal index 64123d1..b4b0447 100644 --- a/ballerina-tests/csv-commons/test_utils.bal +++ b/ballerina-tests/csv-commons/test_utils.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + public function generateErrorMessageForMissingRequiredField(string 'field) returns string { return string `no matching header value is found for the required field '${'field}'`; } diff --git a/ballerina-tests/parse-list-types-tests/Ballerina.toml b/ballerina-tests/parse-list-types-tests/Ballerina.toml index 6374fc7..fed1b89 100644 --- a/ballerina-tests/parse-list-types-tests/Ballerina.toml +++ b/ballerina-tests/parse-list-types-tests/Ballerina.toml @@ -11,3 +11,6 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" 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 f3ef889..548b42c 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; @test:Config 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 751e756..0893c54 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; @test:Config diff --git a/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal index 360a493..a9698aa 100644 --- a/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + boolean b1 = true; false b2 = false; boolean? b3 = (); diff --git a/ballerina-tests/parse-list-types-tests/tests/types.bal b/ballerina-tests/parse-list-types-tests/tests/types.bal index 62f8f98..2c7c117 100644 --- a/ballerina-tests/parse-list-types-tests/tests/types.bal +++ b/ballerina-tests/parse-list-types-tests/tests/types.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + type BooleanRecord1 record { boolean b1; boolean|string b2; diff --git a/ballerina-tests/parse-record-types-tests/Ballerina.toml b/ballerina-tests/parse-record-types-tests/Ballerina.toml index 508c204..bd4f487 100644 --- a/ballerina-tests/parse-record-types-tests/Ballerina.toml +++ b/ballerina-tests/parse-record-types-tests/Ballerina.toml @@ -11,3 +11,6 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" 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 98f980c..6ddef47 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; @test:Config 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 a1373ae..50dde64 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; @test:Config diff --git a/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal index 360a493..a9698aa 100644 --- a/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + boolean b1 = true; false b2 = false; boolean? b3 = (); diff --git a/ballerina-tests/parse-record-types-tests/tests/types.bal b/ballerina-tests/parse-record-types-tests/tests/types.bal index a2b4b2b..b496d60 100644 --- a/ballerina-tests/parse-record-types-tests/tests/types.bal +++ b/ballerina-tests/parse-record-types-tests/tests/types.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + type BooleanRecord1 record { boolean b1; boolean|string b2; diff --git a/ballerina-tests/parse-string-array-types-tests/Ballerina.toml b/ballerina-tests/parse-string-array-types-tests/Ballerina.toml index 256e0d0..bfffdb6 100644 --- a/ballerina-tests/parse-string-array-types-tests/Ballerina.toml +++ b/ballerina-tests/parse-string-array-types-tests/Ballerina.toml @@ -11,3 +11,6 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" 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 ce7d4c5..0a6c492 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; @test:Config 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 7cc5087..efc268b 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; @test:Config diff --git a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal index 360a493..a9698aa 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + boolean b1 = true; false b2 = false; boolean? b3 = (); diff --git a/ballerina-tests/parse-string-array-types-tests/tests/types.bal b/ballerina-tests/parse-string-array-types-tests/tests/types.bal index a2b4b2b..b496d60 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/types.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/types.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + type BooleanRecord1 record { boolean b1; boolean|string b2; diff --git a/ballerina-tests/parse-string-record-types-tests/Ballerina.toml b/ballerina-tests/parse-string-record-types-tests/Ballerina.toml index a9d8337..3775e98 100644 --- a/ballerina-tests/parse-string-record-types-tests/Ballerina.toml +++ b/ballerina-tests/parse-string-record-types-tests/Ballerina.toml @@ -11,3 +11,6 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" diff --git a/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests copy.bal b/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests.bal similarity index 95% rename from ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests copy.bal rename to ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests.bal index 8e95f6a..c15191a 100644 --- a/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests copy.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/parse_string_to_map_tests.bal @@ -1,4 +1,20 @@ -import ballerina/data.csv as csv; +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/data.csv; import ballerina/test; @test:Config 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 2383f72..de15f81 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; @test:Config diff --git a/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal index 360a493..a9698aa 100644 --- a/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + boolean b1 = true; false b2 = false; boolean? b3 = (); diff --git a/ballerina-tests/parse-string-record-types-tests/tests/types.bal b/ballerina-tests/parse-string-record-types-tests/tests/types.bal index a2b4b2b..b496d60 100644 --- a/ballerina-tests/parse-string-record-types-tests/tests/types.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/types.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + type BooleanRecord1 record { boolean b1; boolean|string b2; diff --git a/ballerina-tests/type-compatible-tests/Ballerina.toml b/ballerina-tests/type-compatible-tests/Ballerina.toml index 2d5ec74..cfdb846 100644 --- a/ballerina-tests/type-compatible-tests/Ballerina.toml +++ b/ballerina-tests/type-compatible-tests/Ballerina.toml @@ -11,3 +11,6 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" diff --git a/ballerina-tests/type-compatible-tests/Dependencies.toml b/ballerina-tests/type-compatible-tests/Dependencies.toml index 2e33529..5cc76ac 100644 --- a/ballerina-tests/type-compatible-tests/Dependencies.toml +++ b/ballerina-tests/type-compatible-tests/Dependencies.toml @@ -28,6 +28,19 @@ modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} ] +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -69,6 +82,15 @@ name = "lang.object" version = "0.0.0" scope = "testOnly" +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "test" @@ -90,6 +112,7 @@ version = "0.1.0" dependencies = [ {org = "ballerina", name = "csv_commons"}, {org = "ballerina", name = "data.csv"}, + {org = "ballerina", name = "io"}, {org = "ballerina", name = "test"} ] modules = [ 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 8cb60fd..82418ee 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/io; import ballerina/test; 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 ed41a81..250dc69 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; @test:Config diff --git a/ballerina-tests/type-compatible-tests/tests/test_data_values.bal b/ballerina-tests/type-compatible-tests/tests/test_data_values.bal index 360a493..a9698aa 100644 --- a/ballerina-tests/type-compatible-tests/tests/test_data_values.bal +++ b/ballerina-tests/type-compatible-tests/tests/test_data_values.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + boolean b1 = true; false b2 = false; boolean? b3 = (); diff --git a/ballerina-tests/type-compatible-tests/tests/types.bal b/ballerina-tests/type-compatible-tests/tests/types.bal index a2b4b2b..b496d60 100644 --- a/ballerina-tests/type-compatible-tests/tests/types.bal +++ b/ballerina-tests/type-compatible-tests/tests/types.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + type BooleanRecord1 record { boolean b1; boolean|string b2; diff --git a/ballerina-tests/unicode-tests/Ballerina.toml b/ballerina-tests/unicode-tests/Ballerina.toml index b2ec347..5dba598 100644 --- a/ballerina-tests/unicode-tests/Ballerina.toml +++ b/ballerina-tests/unicode-tests/Ballerina.toml @@ -11,3 +11,6 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" diff --git a/ballerina-tests/unicode-tests/Dependencies.toml b/ballerina-tests/unicode-tests/Dependencies.toml new file mode 100644 index 0000000..9497389 --- /dev/null +++ b/ballerina-tests/unicode-tests/Dependencies.toml @@ -0,0 +1,88 @@ +# AUTO-GENERATED FILE. DO NOT MODIFY. + +# This file is auto-generated by Ballerina for managing dependency versions. +# It should not be modified by hand. + +[ballerina] +dependencies-toml-version = "2" +distribution-version = "2201.9.0" + +[[package]] +org = "ballerina" +name = "data.csv" +version = "0.1.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] +modules = [ + {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} +] + +[[package]] +org = "ballerina" +name = "jballerina.java" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + +[[package]] +org = "ballerina" +name = "unicode_tests" +version = "0.1.0" +dependencies = [ + {org = "ballerina", name = "data.csv"}, + {org = "ballerina", name = "test"} +] +modules = [ + {org = "ballerina", packageName = "unicode_tests", moduleName = "unicode_tests"} +] + diff --git a/ballerina-tests/unicode-tests/tests/escape_character_test.bal b/ballerina-tests/unicode-tests/tests/escape_character_test.bal index cee018f..297fa87 100644 --- a/ballerina-tests/unicode-tests/tests/escape_character_test.bal +++ b/ballerina-tests/unicode-tests/tests/escape_character_test.bal @@ -1,4 +1,20 @@ -import ballerina/data.csv as csv; +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/data.csv; import ballerina/test; @test:Config diff --git a/ballerina-tests/union-type-tests/Ballerina.toml b/ballerina-tests/union-type-tests/Ballerina.toml index 5d819d3..1480b52 100644 --- a/ballerina-tests/union-type-tests/Ballerina.toml +++ b/ballerina-tests/union-type-tests/Ballerina.toml @@ -11,3 +11,6 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" diff --git a/ballerina-tests/union-type-tests/tests/test_data_values.bal b/ballerina-tests/union-type-tests/tests/test_data_values.bal index 360a493..a9698aa 100644 --- a/ballerina-tests/union-type-tests/tests/test_data_values.bal +++ b/ballerina-tests/union-type-tests/tests/test_data_values.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + boolean b1 = true; false b2 = false; boolean? b3 = (); 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 141fce7..299397e 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 @@ -1,4 +1,20 @@ -import ballerina/data.csv as csv; +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/data.csv; import ballerina/test; @test:Config diff --git a/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal b/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal index 495180a..3aa7369 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 @@ -1,4 +1,20 @@ -import ballerina/data.csv as csv; +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/data.csv; import ballerina/test; import ballerina/csv_commons as common; 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 10fc22a..4ed231a 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 @@ -1,4 +1,20 @@ -import ballerina/data.csv as csv; +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/data.csv; import ballerina/test; type RecA record {int a; string b; boolean c; decimal d; float e; () f;}; diff --git a/ballerina-tests/union-type-tests/tests/types.bal b/ballerina-tests/union-type-tests/tests/types.bal index a2b4b2b..b496d60 100644 --- a/ballerina-tests/union-type-tests/tests/types.bal +++ b/ballerina-tests/union-type-tests/tests/types.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + type BooleanRecord1 record { boolean b1; boolean|string b2; diff --git a/ballerina-tests/user-config-tests/Ballerina.toml b/ballerina-tests/user-config-tests/Ballerina.toml index 05c5773..b4d56ea 100644 --- a/ballerina-tests/user-config-tests/Ballerina.toml +++ b/ballerina-tests/user-config-tests/Ballerina.toml @@ -11,3 +11,6 @@ version = "0.1.0" [platform.java17] graalvmCompatible = true + +[build-options] +graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" diff --git a/ballerina-tests/user-config-tests/tests/test_data_values.bal b/ballerina-tests/user-config-tests/tests/test_data_values.bal index 360a493..a9698aa 100644 --- a/ballerina-tests/user-config-tests/tests/test_data_values.bal +++ b/ballerina-tests/user-config-tests/tests/test_data_values.bal @@ -1,3 +1,19 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + boolean b1 = true; false b2 = false; boolean? b3 = (); diff --git a/ballerina-tests/user-config-tests/tests/types.bal b/ballerina-tests/user-config-tests/tests/types.bal index 7587492..f3b94e7 100644 --- a/ballerina-tests/user-config-tests/tests/types.bal +++ b/ballerina-tests/user-config-tests/tests/types.bal @@ -1,4 +1,20 @@ -import ballerina/data.csv as csv; +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/data.csv; type RecordWithCustomAnnotation record { @csv:Name { 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 331ca64..662cb9f 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; @test:Config 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 26ed7bd..4453312 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 @@ -1,5 +1,21 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + import ballerina/csv_commons as common; -import ballerina/data.csv as csv; +import ballerina/data.csv; import ballerina/test; @test:Config diff --git a/ballerina-tests/user-config-tests/tests/user_configs.bal b/ballerina-tests/user-config-tests/tests/user_configs.bal index 8e85183..deb2b4f 100644 --- a/ballerina-tests/user-config-tests/tests/user_configs.bal +++ b/ballerina-tests/user-config-tests/tests/user_configs.bal @@ -1,4 +1,20 @@ -import ballerina/data.csv as csv; +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/data.csv; // Valid parser options csv:ParseOption option1 = {delimiter: "@", nilValue: "null", lineTerminator: [csv:LF]}; diff --git a/ballerina/Package.md b/ballerina/Package.md index 26878a7..22ff65d 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -1 +1,197 @@ -# Ballerina CSV Data module +# Ballerina CSV Data Library + +[![Build](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-timestamped-master.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-timestamped-master.yml) +[![codecov](https://codecov.io/gh/ballerina-platform/module-ballerina-data.csv/branch/main/graph/badge.svg)](https://codecov.io/gh/ballerina-platform/module-ballerina-data.csv) +[![Trivy](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/trivy-scan.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/trivy-scan.yml) +[![GraalVM Check](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-with-bal-test-graalvm.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-with-bal-test-graalvm.yml) +[![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerina-data.csv.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/commits/master) +[![Github issues](https://img.shields.io/github/issues/ballerina-platform/ballerina-standard-library/module/data.csv.svg?label=Open%20Issues)](https://github.com/ballerina-platform/ballerina-standard-library/labels/module%2Fdata.csv) + +The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate the handling and manipulation of CSV data within Ballerina applications. It streamlines the process of converting CSV data to native Ballerina data types, enabling developers to work with CSV content seamlessly and efficiently. + +## 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. + +## 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. + +```ballerina +import ballerina/data.csv; +import ballerina/io; + +type Book record { + string name; + string author; + int year; +}; + +public function main() returns error? { + string csvString = string `name,author,year + Clean Code,Robert C. Martin,2008 + The Pragmatic Programmer,Andrew Hunt and David Thomas,1999`; + + Book[] books = check csv:parseStringToRecord(csvString); + foreach var book in books { + io:println(book); + } +} +``` + +### 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. + +```ballerina +import ballerina/data.csv; +import ballerina/io; + +type Book record { + string name; + string author; + int year; +}; + +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); + 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); + io:println(book2); +} +``` + +Make sure to handle possible errors that may arise during the file reading or CSV to record/array conversion process. The `check` keyword is utilized to handle these errors, but more sophisticated error handling can be implemented as per your requirements. + +## 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. + +```ballerina +import ballerina/data.csv; +import ballerina/io; + +type Book record { + string name; + int year; +}; + +public function main() returns error? { + string[][] bookArray = [["Clean Code","2008"],["Clean Architecture","2017"]]; + + Book[] author = check csv:parseListAsRecordType(bookArray, customHeaders = ["name", "year"]); + io:println(author); +} +``` + +### Controlling the CSV value to record array conversion + +The library allows for selective conversion of CSV into closed record arrays. This is beneficial when the CSV data contains headers that are not necessary to be transformed into record fields. + +```ballerina +import ballerina/data.csv; +import ballerina/io; + +type Book record {| + string name; + string author; +|}; + +public function main() returns error? { + record{}[] csvContent = [{ + "name": "Clean Code", + "author": "Robert C. Martin", + "year": 2008, + "publisher": "Prentice Hall" + }, { + "name": "The Pragmatic Programmer", + "author": "Andrew Hunt and David Thomas", + "year": 1999, + "publisher": "Addison-Wesley" + }]; + + // 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); + io:println(book); +} +``` + +However, if the rest field is utilized (or if the record type is defined as an open record), all members in the CSV data will be transformed into record fields: + +```ballerina +type Book record { + string name; + string author; +} +``` + +In this instance, all other CSV header values, such as `year` and `publisher` will be transformed into `anydata-typed` fields with the corresponding CSV header as the key-value pair. + +This behavior extends to arrays as well. + +The process of projecting CSV data into a record supports various use cases, including the filtering out of unnecessary members. This functionality is anticipated to be enhanced in the future to accommodate more complex scenarios, such as filtering values based on regular expressions, among others. + +## Issues and projects + +Issues and Projects tabs are disabled for this repository as this is part of the Ballerina library. To report bugs, request new features, start new discussions, view project boards, etc. please visit Ballerina library [parent repository](https://github.com/ballerina-platform/ballerina-library). + +This repository only contains the source code for the package. + +## Building from the source + +### Set up the prerequisites + +1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations). + * [Oracle](https://www.oracle.com/java/technologies/downloads/) + * [OpenJDK](https://adoptium.net/) + +2. Export your GitHub personal access token with the read package permissions as follows. + + export packageUser= + export packagePAT= + +### Building the source + +Execute the commands below to build from source. + +1. To build the library: + + ./gradlew clean build + +2. Publish ZIP artifact to the local `.m2` repository: + + ./gradlew clean build publishToMavenLocal + +3. Publish the generated artifacts to the local Ballerina central repository: + + ./gradlew clean build -PpublishToLocalCentral=true + +4. Publish the generated artifacts to the Ballerina central repository: + + ./gradlew clean build -PpublishToCentral=true + +## Contributing to Ballerina + +As an open source project, Ballerina welcomes contributions from the community. + +For more information, go to the [contribution guidelines](https://github.com/ballerina-platform/ballerina-lang/blob/master/CONTRIBUTING.md). + +## Code of conduct + +All contributors are encouraged to read the [Ballerina code of conduct](https://ballerina.io/code-of-conduct). + +## Useful links + +* Chat live with us via our [Discord server](https://discord.gg/ballerinalang). +* Post all technical questions on Stack Overflow with the [#ballerina](https://stackoverflow.com/questions/tagged/ballerina) tag. diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 7355b09..3a51ab1 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -23,7 +23,7 @@ import ballerina/jballerina.java; # + 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.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Converts byte[] to subtype of record array. # @@ -32,7 +32,7 @@ public isolated function parseStringToRecord(string s, parseToRecordOption optio # + 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.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Converts CSV byte-block-stream to subtype of record array. # @@ -42,7 +42,7 @@ public isolated function parseBytesToRecord(byte[] s, parseToRecordOption option # + 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.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Converts CSV string to subtype of anydata[][]. # @@ -51,7 +51,7 @@ public isolated function parseStreamToRecord(stream s, # + 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.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Converts byte[] to subtype of anydata[][]. # @@ -60,7 +60,7 @@ public isolated function parseStringToList(string s, ParseOption options = {}, t # + 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.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Converts CSV byte-block-stream to subtype of anydata[][]. # @@ -70,7 +70,7 @@ public isolated function parseBytesToList(byte[] s, ParseOption options = {}, ty # + 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.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Convert value of type record{}[] to subtype of record{}[]. # @@ -80,7 +80,7 @@ public isolated function parseStreamToList(stream s, # + 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.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Convert value of type record{}[] to subtype of anydata[][]. # @@ -91,7 +91,7 @@ public isolated function parseRecordAsRecordType(record{}[] s, # + 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.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Convert value of type string[][] to subtype of record{}[]. # @@ -102,7 +102,7 @@ public isolated function parseRecordAsListType(record{}[] s, string[] headerName # + 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.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Convert value of type string[][] to subtype of anydata[][]. # @@ -111,4 +111,4 @@ public isolated function parseListAsRecordType(string[][] s, string[]? customHea # + 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.stdlib.data.csvdata.csv.Native"} external; + returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; diff --git a/ballerina/init.bal b/ballerina/init.bal index a0a98cb..02fa1d9 100644 --- a/ballerina/init.bal +++ b/ballerina/init.bal @@ -21,5 +21,5 @@ isolated function init() { } isolated function setModule() = @java:Method { - 'class: "io.ballerina.stdlib.data.csvdata.utils.ModuleUtils" + 'class: "io.ballerina.lib.data.csvdata.utils.ModuleUtils" } external; diff --git a/build-config/checkstyle/build.gradle b/build-config/checkstyle/build.gradle index 857ad1e..62780e5 100644 --- a/build-config/checkstyle/build.gradle +++ b/build-config/checkstyle/build.gradle @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/build-config/resources/CompilerPlugin.toml b/build-config/resources/CompilerPlugin.toml index 10f4b4a..dd833b5 100644 --- a/build-config/resources/CompilerPlugin.toml +++ b/build-config/resources/CompilerPlugin.toml @@ -1,6 +1,6 @@ [plugin] id = "constraint-compiler-plugin" -class = "io.ballerina.stdlib.data.csvdata.compiler.CsvDataCompilerPlugin" +class = "io.ballerina.lib.data.csvdata.compiler.CsvDataCompilerPlugin" [[dependency]] path = "../compiler-plugin/build/libs/data.csv-compiler-plugin-@project.version@.jar" diff --git a/build-config/resources/CsvTestCommon.toml b/build-config/resources/CsvTestCommon.toml index 91de9a7..38b069a 100644 --- a/build-config/resources/CsvTestCommon.toml +++ b/build-config/resources/CsvTestCommon.toml @@ -2,3 +2,6 @@ org = "ballerina" name = "@package.name@" version = "@toml.version@" + +[platform.java17] +graalvmCompatible = true 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 5d1bd17..b1a7189 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 @@ -29,6 +29,8 @@ /** * This class includes tests for Ballerina Csv Data compiler plugin. + * + * @since 0.1.0 */ public class CompilerPluginTest { diff --git a/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTestUtils.java b/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTestUtils.java index 13c34d1..a3f15c4 100644 --- a/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTestUtils.java +++ b/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTestUtils.java @@ -29,6 +29,8 @@ /** * Utility functions related to compiler plugins tests. + * + * @since 0.1.0 */ public class CompilerPluginTestUtils { private static final Path RESOURCE_DIRECTORY = Paths.get("src", "test", "resources", "ballerina_sources") diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/Constants.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java similarity index 93% rename from compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/Constants.java rename to compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java index 9dba404..00b8863 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/Constants.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java @@ -16,14 +16,14 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.compiler; +package io.ballerina.lib.data.csvdata.compiler; /** * Constants for CsvData's compiler plugin. * * @since 0.1.0 */ -public class Constants { +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"; @@ -38,4 +38,7 @@ public class Constants { static final String CSVDATA = "csv"; static final String BALLERINA = "ballerina"; static final String DATA_CSVDATA = "data.csv"; + + private Constants() { + } } diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCodeAnalyzer.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataCodeAnalyzer.java similarity index 95% rename from compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCodeAnalyzer.java rename to compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataCodeAnalyzer.java index 86d27f1..1e67372 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCodeAnalyzer.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataCodeAnalyzer.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.compiler; +package io.ballerina.lib.data.csvdata.compiler; import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.projects.plugins.CodeAnalysisContext; diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCompilerPlugin.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataCompilerPlugin.java similarity index 95% rename from compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCompilerPlugin.java rename to compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataCompilerPlugin.java index 865eca3..430091e 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataCompilerPlugin.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataCompilerPlugin.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.compiler; +package io.ballerina.lib.data.csvdata.compiler; import io.ballerina.projects.plugins.CompilerPlugin; import io.ballerina.projects.plugins.CompilerPluginContext; diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataDiagnosticCodes.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java similarity index 86% rename from compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataDiagnosticCodes.java rename to compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java index 57c9cac..c47482b 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataDiagnosticCodes.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.compiler; +package io.ballerina.lib.data.csvdata.compiler; import io.ballerina.tools.diagnostics.DiagnosticSeverity; @@ -28,8 +28,8 @@ * @since 0.1.0 */ public enum CsvDataDiagnosticCodes { - DUPLICATE_FIELD("JSON_ERROR_202", "invalid field: duplicate field found", ERROR), - UNSUPPORTED_TYPE("JSON_ERROR_203", "unsupported type: type is not supported", ERROR); + DUPLICATE_FIELD("CSV_ERROR_1", "invalid field: duplicate field found", ERROR), + UNSUPPORTED_TYPE("CSV_ERROR_2", "unsupported type: type is not supported", ERROR); private final String code; private final String message; diff --git a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java similarity index 92% rename from compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java rename to compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java index 7b36726..878e30c 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/data/csvdata/compiler/CsvDataTypeValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.compiler; +package io.ballerina.lib.data.csvdata.compiler; import io.ballerina.compiler.api.ModuleID; import io.ballerina.compiler.api.SemanticModel; @@ -114,13 +114,11 @@ private void reset() { private void updateModulePrefix(ModulePartNode rootNode) { for (ImportDeclarationNode importDeclarationNode : rootNode.imports()) { Optional symbol = semanticModel.symbol(importDeclarationNode); - if (symbol.isPresent() && symbol.get().kind() == SymbolKind.MODULE) { - ModuleSymbol moduleSymbol = (ModuleSymbol) symbol.get(); - if (isCsvdataImport(moduleSymbol)) { - modulePrefix = moduleSymbol.id().modulePrefix(); - break; - } - } + symbol.filter(moduleSymbol -> moduleSymbol.kind() == SymbolKind.MODULE) + .filter(moduleSymbol -> isCsvdataImport((ModuleSymbol) moduleSymbol)) + .ifPresent(moduleSymbol -> { + modulePrefix = ((ModuleSymbol) moduleSymbol).id().modulePrefix(); + }); } } @@ -206,7 +204,7 @@ private void validateExpectedType(TypeSymbol typeSymbol, SyntaxNodeAnalysisConte typeSymbol.getLocation().ifPresent(location -> currentLocation = location); switch (typeSymbol.typeKind()) { - case UNION -> validateUnionType((UnionTypeSymbol) typeSymbol, typeSymbol.getLocation(), ctx); + 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); @@ -224,33 +222,12 @@ private void validateArrayType(ArrayTypeSymbol typeSymbol, SyntaxNodeAnalysisCon } } - private void validateUnionType(UnionTypeSymbol unionTypeSymbol, Optional location, + private void validateUnionType(UnionTypeSymbol unionTypeSymbol, SyntaxNodeAnalysisContext ctx) { - boolean isHasUnsupportedType = false; List memberTypeSymbols = unionTypeSymbol.memberTypeDescriptors(); for (TypeSymbol memberTypeSymbol : memberTypeSymbols) { validateExpectedType(memberTypeSymbol, ctx); } - - if (isHasUnsupportedType) { - reportDiagnosticInfo(ctx, location, CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); - } - } - - private boolean isSupportedUnionMemberType(TypeSymbol typeSymbol) { - TypeDescKind kind = typeSymbol.typeKind(); - if (kind == TypeDescKind.TYPE_REFERENCE) { - kind = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor().typeKind(); - } - - switch (kind) { - case ARRAY, INTERSECTION -> { - return true; - } - default -> { - return false; - } - } } private boolean isSupportedArrayMemberType(TypeSymbol typeSymbol) { @@ -308,7 +285,8 @@ private void reportDiagnosticInfo(SyntaxNodeAnalysisContext ctx, Optional currentLocation); DiagnosticInfo diagnosticInfo = new DiagnosticInfo(diagnosticsCodes.getCode(), diagnosticsCodes.getMessage(), diagnosticsCodes.getSeverity()); - if (allDiagnosticInfo.containsKey(pos) && allDiagnosticInfo.get(pos).equals(diagnosticInfo)) { + DiagnosticInfo posDiagnosticInfo = allDiagnosticInfo.get(pos); + if (posDiagnosticInfo != null && posDiagnosticInfo.equals(diagnosticInfo)) { return; } allDiagnosticInfo.put(pos, diagnosticInfo); @@ -323,10 +301,7 @@ private void processModuleVariableDeclarationNode(ModuleVariableDeclarationNode } Optional symbol = semanticModel.symbol(moduleVariableDeclarationNode.typedBindingPattern()); - if (symbol.isEmpty()) { - return; - } - validateExpectedType(((VariableSymbol) symbol.get()).typeDescriptor(), ctx); + symbol.map(s -> (VariableSymbol) s).map(s -> s.typeDescriptor()).ifPresent(s -> validateExpectedType(s, ctx)); } private void processTypeDefinitionNode(TypeDefinitionNode typeDefinitionNode, SyntaxNodeAnalysisContext ctx) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java similarity index 92% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java index 9ae99bf..63b8341 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java @@ -16,8 +16,11 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata; +package io.ballerina.lib.data.csvdata; +import io.ballerina.lib.data.csvdata.utils.Constants; +import io.ballerina.lib.data.csvdata.utils.CsvConfig; +import io.ballerina.lib.data.csvdata.utils.CsvUtils; import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ErrorCreator; @@ -33,9 +36,6 @@ import io.ballerina.runtime.api.values.BDecimal; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BString; -import io.ballerina.stdlib.data.csvdata.utils.Constants; -import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; -import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; import java.math.BigDecimal; import java.text.DecimalFormatSymbols; @@ -46,35 +46,29 @@ import java.util.List; import java.util.Locale; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.isNullValue; - /** * Native implementation of data:fromStringWithType(string). * * @since 0.1.0 */ -public class FromString { - private static Locale locale = null; +public final class FromString { private static String intRegex = "^[-+]?[0-9]+$"; private static String doubleRegex = "^[-+]?[0-9]+(\\.[0-9]*)?(e[+-]?[0-9]+)?$"; - public static void reset() { - FromString.locale = null; + private FromString() { } private static Locale getLocale(CsvConfig config) { - if (locale == null) { - locale = CsvUtils.createLocaleFromString(config.locale); - DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale); - char decimalSeparator = dfs.getDecimalSeparator(); - char minusSign = dfs.getMinusSign(); - char zeroDigit = dfs.getZeroDigit(); - String exponentSeparator = dfs.getExponentSeparator(); - intRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+$"; - doubleRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+(" + - (decimalSeparator == '.' ? "\\." : decimalSeparator) - + "[" + zeroDigit + "-9]*)?(" + exponentSeparator + "[+-]?[" + zeroDigit + "-9]+)?$"; - } + Locale locale = CsvUtils.createLocaleFromString(config.locale); + DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale); + char decimalSeparator = dfs.getDecimalSeparator(); + char minusSign = dfs.getMinusSign(); + char zeroDigit = dfs.getZeroDigit(); + String exponentSeparator = dfs.getExponentSeparator(); + intRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+$"; + doubleRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+(" + + (decimalSeparator == '.' ? "\\." : decimalSeparator) + + "[" + zeroDigit + "-9]*)?(" + exponentSeparator + "[+-]?[" + zeroDigit + "-9]+)?$"; return locale; } @@ -111,6 +105,7 @@ private static Locale getLocale(CsvConfig config) { public static Object fromStringWithType(BString string, Type expType, CsvConfig config) { String value = string.getValue(); + try { return switch (expType.getTag()) { case TypeTags.INT_TAG -> stringToInt(value, config); @@ -288,7 +283,7 @@ private static Object stringToBoolean(String value) throws NumberFormatException private static Object stringToNull(String value, CsvConfig config) throws NumberFormatException { Object nullValue = config.nilValue; - if (isNullValue(nullValue, value)) { + if (CsvUtils.isNullValue(nullValue, value)) { return null; } return returnError(value, nullValue == null ? Constants.Values.BALLERINA_NULL : nullValue.toString()); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java similarity index 92% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java index 77bc61f..2160923 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java @@ -16,8 +16,13 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.csv; +package io.ballerina.lib.data.csvdata.csv; +import io.ballerina.lib.data.csvdata.FromString; +import io.ballerina.lib.data.csvdata.utils.CsvConfig; +import io.ballerina.lib.data.csvdata.utils.CsvUtils; +import io.ballerina.lib.data.csvdata.utils.DiagnosticErrorCode; +import io.ballerina.lib.data.csvdata.utils.DiagnosticLog; import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ValueCreator; @@ -34,23 +39,21 @@ import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; -import io.ballerina.stdlib.data.csvdata.FromString; -import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; -import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import org.ballerinalang.langlib.value.CloneReadOnly; import java.util.Map; import java.util.Optional; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getUpdatedHeaders; +import static io.ballerina.lib.data.csvdata.utils.CsvUtils.getUpdatedHeaders; + /** * Create objects for partially parsed csv. * * @since 0.1.0 */ -public class CsvCreator { +public final class CsvCreator { + private CsvCreator() { + } static Object initRowValue(Type expectedType) { expectedType = TypeUtils.getReferredType(expectedType); @@ -134,7 +137,7 @@ public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { sm.fields.contains(header)); } - public static void checkAndAddCustomHeaders(CsvParser.StateMachine sm, Object customHeader) { + public static void addCustomHeadersIfNotNull(CsvParser.StateMachine sm, Object customHeader) { if (customHeader == null) { return; } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java similarity index 89% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java index 8d42d56..d276d86 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java @@ -16,8 +16,14 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.csv; - +package io.ballerina.lib.data.csvdata.csv; + +import io.ballerina.lib.data.csvdata.utils.Constants; +import io.ballerina.lib.data.csvdata.utils.CsvConfig; +import io.ballerina.lib.data.csvdata.utils.CsvUtils; +import io.ballerina.lib.data.csvdata.utils.DataUtils; +import io.ballerina.lib.data.csvdata.utils.DiagnosticErrorCode; +import io.ballerina.lib.data.csvdata.utils.DiagnosticLog; import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; @@ -34,13 +40,6 @@ import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BTypedesc; -import io.ballerina.stdlib.data.csvdata.FromString; -import io.ballerina.stdlib.data.csvdata.utils.Constants; -import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; -import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; -import io.ballerina.stdlib.data.csvdata.utils.DataUtils; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import org.apache.commons.lang3.StringEscapeUtils; import java.io.IOException; @@ -51,20 +50,22 @@ import java.util.List; import java.util.Map; -import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.checkAndAddCustomHeaders; -import static io.ballerina.stdlib.data.csvdata.csv.CsvCreator.getHeaderValueForColumnIndex; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.checkRequiredFieldsAndLogError; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getSkipDataRows; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.isCharContainsInLineTerminatorUserConfig; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.processNameAnnotationsAndBuildCustomFieldMap; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.validateExpectedArraySize; +import static io.ballerina.lib.data.csvdata.utils.Constants.EscapeChar.BACKSLASH_CHAR; +import static io.ballerina.lib.data.csvdata.utils.Constants.EscapeChar.BACKSPACE_CHAR; +import static io.ballerina.lib.data.csvdata.utils.Constants.EscapeChar.CARRIAGE_RETURN_CHAR; +import static io.ballerina.lib.data.csvdata.utils.Constants.EscapeChar.DOUBLE_QUOTES_CHAR; +import static io.ballerina.lib.data.csvdata.utils.Constants.EscapeChar.FORM_FEED_CHAR; +import static io.ballerina.lib.data.csvdata.utils.Constants.EscapeChar.NEWLINE_CHAR; +import static io.ballerina.lib.data.csvdata.utils.Constants.EscapeChar.SLASH_CHAR; +import static io.ballerina.lib.data.csvdata.utils.Constants.EscapeChar.TAB_CHAR; +import static io.ballerina.lib.data.csvdata.utils.Constants.EscapeChar.UNICODE_START_CHAR; /** * Convert Csv string to a ballerina record. * * @since 0.1.0 */ -public class CsvParser { +public final class CsvParser { private static final char CR = 0x000D; private static final char HZ_TAB = 0x0009; private static final char SPACE = 0x0020; @@ -76,6 +77,8 @@ public class CsvParser { private static final char EOF = (char) -1; private static final char NEWLINE = 0x000A; + private CsvParser() { + } private static final ThreadLocal LOCAL_THREAD_STATE_MACHINE = ThreadLocal.withInitial(StateMachine::new); @@ -94,6 +97,10 @@ public static Object parse(Reader reader, BTypedesc type, CsvConfig config) } } + /** + * Represents the state machine used for CSV parsing. + */ + static class StateMachine { private static final State HEADER_START_STATE = new HeaderStartState(); private static final State HEADER_END_STATE = new HeaderEndState(); @@ -172,12 +179,11 @@ public void reset() { isValueStart = false; prevState = null; arraySize = 0; - FromString.reset(); } private static boolean isWhitespace(char ch, Object lineTerminator) { return ch == SPACE || ch == HZ_TAB || ch == CR - || isCharContainsInLineTerminatorUserConfig(ch, lineTerminator); + || CsvUtils.isCharContainsInLineTerminatorUserConfig(ch, lineTerminator); } private static void throwExpected(String... chars) throws CsvParserException { @@ -238,7 +244,8 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp restType = (recordType).getRestFieldType(); fieldHierarchy = new HashMap<>(recordType.getFields()); fields = new HashSet<>(recordType.getFields().keySet()); - updatedRecordFieldNames = processNameAnnotationsAndBuildCustomFieldMap(recordType, fieldHierarchy); + updatedRecordFieldNames = CsvUtils + .processNameAnnotationsAndBuildCustomFieldMap(recordType, fieldHierarchy); break; case TypeTags.TUPLE_TAG: restType = ((TupleType) expectedArrayElementType).getRestType(); @@ -277,7 +284,7 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp currentState = HEADER_START_STATE; } else { if (config.customHeader != null) { - checkAndAddCustomHeaders(this, config.customHeader); + CsvCreator.addCustomHeadersIfNotNull(this, config.customHeader); } currentState = ROW_START_STATE; addFieldNamesForNonHeaderState(); @@ -321,7 +328,7 @@ private void append(char ch) { } private boolean isNewLineOrEof(char ch) { - return ch == EOF || isCharContainsInLineTerminatorUserConfig(ch, config.lineTerminator); + return ch == EOF || CsvUtils.isCharContainsInLineTerminatorUserConfig(ch, config.lineTerminator); } private void growCharBuff() { @@ -331,12 +338,15 @@ private void growCharBuff() { } /** - * A specific state in the Csv parsing state machine. + * A specific state in the CSV parsing state machine. */ interface State { State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException; } + /** + * Represents the CSV header start state. + */ private static class HeaderStartState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { @@ -369,7 +379,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C sm.isHeaderConfigExceedLineNumber = false; if (customHeader != null) { if (sm.isNewLineOrEof(ch)) { - checkAndAddCustomHeaders(sm, customHeader); + CsvCreator.addCustomHeadersIfNotNull(sm, customHeader); sm.lineNumber++; state = HEADER_END_STATE; break; @@ -450,12 +460,12 @@ private static void finalizeHeaders(StateMachine sm) throws CsvParserException { Type expType = sm.expectedArrayElementType; if (expType instanceof RecordType) { validateRemainingRecordFields(sm); - } else if (expType instanceof ArrayType) { - validateExpectedArraySize(((ArrayType) expType).getSize(), sm.headers.size()); + } else if (expType instanceof ArrayType arrayType) { + CsvUtils.validateExpectedArraySize(arrayType.getSize(), sm.headers.size()); } else if (expType instanceof MapType) { //ignore - } else if (expType instanceof TupleType) { - validateTupleTypes((TupleType) expType, sm.restType, sm.headers.size()); + } else if (expType instanceof TupleType tupleType) { + validateTupleTypes(tupleType, sm.restType, sm.headers.size()); } else { throw new CsvParserException("Invalid expected type"); } @@ -502,6 +512,9 @@ private static void addHeader(StateMachine sm, boolean trim) { sm.headers.add(value); } + /** + * Represents the CSV header end state. + */ private static class HeaderEndState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) { @@ -509,6 +522,9 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { } } + /** + * Represents the CSV row start state. + */ private static class RowStartState implements State { char ch; State state = ROW_START_STATE; @@ -516,7 +532,7 @@ private static class RowStartState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { char separator = sm.config.delimiter; - long[] skipLines = getSkipDataRows(sm.config.skipLines); + long[] skipLines = CsvUtils.getSkipDataRows(sm.config.skipLines); for (; i < count; i++) { ch = buff[i]; @@ -607,7 +623,7 @@ private static void handleEndOfTheRow(StateMachine sm) throws CsvParserException private static void handleEndOfTheRow(StateMachine sm, boolean trim) throws CsvParserException { sm.isValueStart = false; handleCsvRow(sm, trim); - checkRequiredFieldsAndLogError(sm.fieldHierarchy, sm.config.absentAsNilableType); + CsvUtils.checkRequiredFieldsAndLogError(sm.fieldHierarchy, sm.config.absentAsNilableType); } private static void handleCsvRow(StateMachine sm, boolean trim) throws CsvParserException { @@ -678,12 +694,12 @@ private static void addRowValue(StateMachine sm, boolean trim) throws CsvParserE if (exptype instanceof RecordType) { type = getExpectedRowTypeOfRecord(sm); currentField = getCurrentField(sm); - } else if (exptype instanceof MapType) { - type = ((MapType) exptype).getConstrainedType(); - } else if (exptype instanceof ArrayType) { - type = getExpectedRowTypeOfArray(sm, (ArrayType) exptype); - } else if (exptype instanceof TupleType) { - type = getExpectedRowTypeOfTuple(sm, (TupleType) exptype); + } 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); } else { throw new CsvParserException("Unexpected expected type"); } @@ -725,7 +741,7 @@ private static Type getExpectedRowTypeOfArray(StateMachine sm, ArrayType arrayTy } private static Type getExpectedRowTypeOfRecord(StateMachine sm) { - String header = getHeaderValueForColumnIndex(sm); + String header = CsvCreator.getHeaderValueForColumnIndex(sm); Map fields = sm.fieldNames; if (fields.containsKey(header)) { return fields.get(header).getFieldType(); @@ -744,7 +760,7 @@ private static Type getExpectedRowTypeOfRecord(StateMachine sm) { } private static Field getCurrentField(StateMachine sm) { - String header = getHeaderValueForColumnIndex(sm); + String header = CsvCreator.getHeaderValueForColumnIndex(sm); Map fields = sm.fieldNames; if (fields.containsKey(header)) { return fields.get(header); @@ -752,6 +768,9 @@ private static Field getCurrentField(StateMachine sm) { return null; } + /** + * Represents the CSV row end state. + */ private static class RowEndState implements State { @Override public State transition(StateMachine sm, char[] buff, int i, int count) { @@ -759,6 +778,9 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { } } + /** + * Represents the CSV row value with quote state. + */ private static class StringQuoteValueState implements State { @Override @@ -823,7 +845,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) return state; } } - + + /** + * Represents the CSV header value with quote state. + */ private static class HeaderQuoteValueState implements State { @Override @@ -887,6 +912,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) } } + /** + * Represents the state where an escaped unicode character in hex format is processed + * from a row value. + */ private static class StringValueUnicodeHexProcessingState extends UnicodeHexProcessingState { @Override @@ -898,7 +927,7 @@ protected State getSourceState() { /** * Represents the state where an escaped unicode character in hex format is processed - * from a field name. + * from a header name. */ private static class HeaderUnicodeHexProcessingState extends UnicodeHexProcessingState { @@ -967,6 +996,9 @@ private char extractUnicodeChar(StateMachine sm) { } + /** + * Represents the state where an escaped character is processed in a header value. + */ private static class HeaderEscapedCharacterProcessingState extends EscapedCharacterProcessingState { @Override @@ -975,6 +1007,9 @@ protected State getSourceState() { } } + /** + * Represents the state where an escaped character is processed in a row value. + */ private static class StringValueEscapedCharacterProcessingState extends EscapedCharacterProcessingState { @Override @@ -983,7 +1018,13 @@ protected State getSourceState() { } } + /** + * Represents the state where an escaped character is processed in a header or row value. + */ private abstract static class EscapedCharacterProcessingState implements State { + static final Map ESCAPE_CHAR_MAP = Map.of(DOUBLE_QUOTES_CHAR, QUOTES, + BACKSLASH_CHAR, REV_SOL, SLASH_CHAR, SOL, BACKSPACE_CHAR, BACKSPACE, FORM_FEED_CHAR, + FORMFEED, NEWLINE_CHAR, NEWLINE, CARRIAGE_RETURN_CHAR, CR, TAB_CHAR, HZ_TAB); protected abstract State getSourceState(); @@ -1004,39 +1045,18 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return ROW_END_STATE; } switch (ch) { - case '"': - sm.append(QUOTES); - state = sm.prevState; - break; - case '\\': - sm.append(REV_SOL); - state = sm.prevState; - break; - case '/': - sm.append(SOL); - state = sm.prevState; - break; - case 'b': - sm.append(BACKSPACE); - state = sm.prevState; - break; - case 'f': - sm.append(FORMFEED); - state = sm.prevState; - break; - case 'n': - sm.append(NEWLINE); - state = sm.prevState; - break; - case 'r': - sm.append(CR); - state = sm.prevState; - break; - case 't': - sm.append(HZ_TAB); + case DOUBLE_QUOTES_CHAR: + case BACKSLASH_CHAR: + case SLASH_CHAR: + case BACKSPACE_CHAR: + case FORM_FEED_CHAR: + case NEWLINE_CHAR: + case CARRIAGE_RETURN_CHAR: + case TAB_CHAR: + sm.append(ESCAPE_CHAR_MAP.get(ch)); state = sm.prevState; break; - case 'u': + case UNICODE_START_CHAR: if (this.getSourceState() == STRING_ESCAPE_VALUE_STATE) { state = STRING_UNICODE_CHAR_STATE; } else if (this.getSourceState() == HEADER_ESCAPE_CHAR_STATE) { diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java similarity index 87% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java index 091a4b8..421c3c0 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java @@ -16,8 +16,13 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.csv; +package io.ballerina.lib.data.csvdata.csv; +import io.ballerina.lib.data.csvdata.utils.CsvConfig; +import io.ballerina.lib.data.csvdata.utils.CsvUtils; +import io.ballerina.lib.data.csvdata.utils.DataUtils; +import io.ballerina.lib.data.csvdata.utils.DiagnosticErrorCode; +import io.ballerina.lib.data.csvdata.utils.DiagnosticLog; import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.TypeCreator; @@ -38,11 +43,6 @@ import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; -import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; -import io.ballerina.stdlib.data.csvdata.utils.CsvUtils; -import io.ballerina.stdlib.data.csvdata.utils.DataUtils; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import java.util.ArrayDeque; import java.util.ArrayList; @@ -53,27 +53,17 @@ import java.util.Map; import java.util.Optional; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.SkipMappedValue; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.UnMappedValue; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.checkRequiredFieldsAndLogError; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.checkTypeCompatibility; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.convertToBasicType; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.createHeaders; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getMutableType; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getSkipDataRows; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.getTheActualExpectedType; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.isBasicType; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.isHeaderFieldsEmpty; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.processNameAnnotationsAndBuildCustomFieldMap; -import static io.ballerina.stdlib.data.csvdata.utils.CsvUtils.validateExpectedArraySize; - /** * Convert Csv value to a ballerina record. * * @since 0.1.0 */ -public class CsvTraversal { +public final class CsvTraversal { private static final ThreadLocal tlCsvTree = ThreadLocal.withInitial(CsvTree::new); + + private CsvTraversal() { + } + public static Object traverse(BArray csv, CsvConfig config, BTypedesc type) { CsvTree csvTree = tlCsvTree.get(); try { @@ -158,7 +148,7 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { Type referredType = TypeUtils.getReferredType(type); int sourceArraySize = (int) csv.getLength(); if (referredType.getTag() == TypeTags.INTERSECTION_TAG) { - Optional mutableType = getMutableType((IntersectionType) referredType); + Optional mutableType = CsvUtils.getMutableType((IntersectionType) referredType); if (mutableType.isPresent()) { return CsvCreator.constructReadOnlyValue(traverseCsv(csv, config, mutableType.get())); } @@ -168,19 +158,16 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { if (referredType.getTag() == TypeTags.ARRAY_TAG) { Type arrayElementType = TypeUtils.getReferredType(((ArrayType) referredType).getElementType()); if (arrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { - Optional mutableType = getMutableType((IntersectionType) arrayElementType); + Optional mutableType = CsvUtils.getMutableType((IntersectionType) arrayElementType); if (mutableType.isPresent()) { - return CsvCreator.constructReadOnlyValue( - traverseCsv(csv, config, TypeCreator.createArrayType( - mutableType.get() - )) - ); + return CsvCreator.constructReadOnlyValue(traverseCsv(csv, + config, TypeCreator.createArrayType(mutableType.get()))); } } } int expectedArraySize = ((ArrayType) referredType).getSize(); setRootCsvNodeForNonUnionArrays(referredType, type); - validateExpectedArraySize(expectedArraySize, sourceArraySize); + CsvUtils.validateExpectedArraySize(expectedArraySize, sourceArraySize); traverseCsvWithExpectedType(sourceArraySize, csv, type); } else { traverseCsvWithUnionExpectedType(referredType, type, sourceArraySize, csv); @@ -197,7 +184,7 @@ private void traverseCsvWithUnionExpectedType(Type referredType, Type type, int resetForUnionTypes(); try { setRootCsvNodeForNonUnionArrays(mType, mType); - validateExpectedArraySize(expectedArraySize, sourceArraySize); + CsvUtils.validateExpectedArraySize(expectedArraySize, sourceArraySize); traverseCsvWithExpectedType(sourceArraySize, csv, type); return; } catch (Exception ex) { @@ -212,7 +199,7 @@ private void traverseCsvWithExpectedType(int sourceArraySize, BArray csv, Type type) { boolean isIntersection = false; if (expectedArrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { - Optional mutableType = getMutableType((IntersectionType) expectedArrayElementType); + Optional mutableType = CsvUtils.getMutableType((IntersectionType) expectedArrayElementType); if (mutableType.isPresent()) { isIntersection = true; expectedArrayElementType = mutableType.get(); @@ -313,7 +300,7 @@ public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray try { memberType = TypeUtils.getReferredType(memberType); if (memberType.getTag() == TypeTags.INTERSECTION_TAG) { - Optional mutableType = getMutableType((IntersectionType) memberType); + Optional mutableType = CsvUtils.getMutableType((IntersectionType) memberType); if (mutableType.isPresent()) { isIntersection = true; memberType = mutableType.get(); @@ -347,7 +334,7 @@ public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray } private static boolean ignoreRow(int index, Object skipLinesConfig) { - long[] skipLines = getSkipDataRows(skipLinesConfig); + long[] skipLines = CsvUtils.getSkipDataRows(skipLinesConfig); for (long skipLine: skipLines) { if (skipLine == index) { return true; @@ -363,7 +350,7 @@ public Object traverseCsvElementWithMapOrRecord(Object csvElement, Type expected RecordType recordType = (RecordType) expectedType; this.fieldHierarchy = new HashMap<>(recordType.getFields()); fields = new HashSet<>(recordType.getFields().keySet()); - this.updatedRecordFieldNames = processNameAnnotationsAndBuildCustomFieldMap( + this.updatedRecordFieldNames = CsvUtils.processNameAnnotationsAndBuildCustomFieldMap( recordType, fieldHierarchy); this.headerFieldHierarchy = new HashMap<>(recordType.getFields()); this.restType = recordType.getRestFieldType(); @@ -402,12 +389,10 @@ public Object traverseCsvElementWithArray(Object csvElement, Type expectedType) } private void traverseArrayValue(Object csvElement, Type type) { - int expectedTypeSize = getTheActualExpectedType(type); - if (csvElement instanceof BMap) { - BMap map = (BMap) csvElement; + int expectedTypeSize = CsvUtils.getTheActualExpectedType(type); + if (csvElement instanceof BMap map) { constructArrayValuesFromMap(map, type, expectedTypeSize == -1 ? map.size() : expectedTypeSize); - } else if (csvElement instanceof BArray) { - BArray array = (BArray) csvElement; + } else if (csvElement instanceof BArray array) { constructArrayValuesFromArray(array, type, expectedTypeSize == -1 ? array.size() : expectedTypeSize); } } @@ -443,7 +428,7 @@ private void constructArrayValuesFromMap(BMap map, Type type, i keys = map.getKeys(); } else { if (this.headers == null) { - this.headers = createHeaders(new String[size], config); + this.headers = CsvUtils.createHeaders(new String[size], config); } if (this.headers.length != size) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); @@ -469,16 +454,8 @@ private void constructArrayValuesFromMap(BMap map, Type type, i } } - private boolean isArrayOrTupleRestTypeMember(Type type, int index) { - if (type instanceof ArrayType) { - return false; - } - return ((TupleType) type).getTupleTypes().size() < index + 1; - } - private Type getArrayOrTupleMemberType(Type type, int index) { - if (type instanceof TupleType) { - TupleType tupleType = (TupleType) type; + if (type instanceof TupleType tupleType) { List tupleTypes = tupleType.getTupleTypes(); if (tupleTypes.size() >= index + 1) { return tupleTypes.get(index); @@ -492,21 +469,21 @@ private Type getArrayOrTupleMemberType(Type type, int index) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, tupleTypes.size()); } } - ArrayType arrayType = (ArrayType) type; + ArrayType arrayType = (ArrayType) type; if (arrayType.getSize() != -1 && arrayType.getSize() <= index) { if (config.allowDataProjection) { return null; } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, arrayType.getSize()); } - return ((ArrayType) type).getElementType(); + 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) { - traverseArrayValueWithMapAsExpectedType((BArray) csvElement, mappingType, expectedType); + } else if (csvElement instanceof BArray array) { + traverseArrayValueWithMapAsExpectedType(array, mappingType, expectedType); } else { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CSV_DATA_FORMAT); } @@ -520,8 +497,8 @@ private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, BArray csvE return true; } Type type = csvElement.getType(); - if (type instanceof TupleType) { - return checkExpectedTypeMatchWithHeadersForTuple(expectedType, (TupleType) type); + if (type instanceof TupleType tupleType) { + return checkExpectedTypeMatchWithHeadersForTuple(expectedType, tupleType); } else { return checkExpectedTypeMatchWithHeadersForArray(expectedType); } @@ -559,7 +536,7 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Tup continue; } - if (isHeaderFieldsEmpty(this.headerFieldHierarchy)) { + if (CsvUtils.isHeaderFieldsEmpty(this.headerFieldHierarchy)) { continue; } return false; @@ -591,7 +568,7 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, int arraySize = csvElement.size(); String[] headers = new String[arraySize]; if (this.headers == null) { - this.headers = createHeaders(headers, config); + this.headers = CsvUtils.createHeaders(headers, config); } boolean headersMatchWithExpType = checkExpectedTypeMatchWithHeaders(expectedType, csvElement, arraySize); if (!headersMatchWithExpType) { @@ -617,7 +594,7 @@ private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappin } addCurrentFieldValue(fieldType, csvElement.get(i - 1), key, mappingType); } - checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); + CsvUtils.checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); } private void traverseMapValueWithMapAsExpectedType( @@ -637,7 +614,7 @@ private void traverseMapValueWithMapAsExpectedType( } addCurrentFieldValue(currentFieldType, map.get(key), key, mappingType); } - checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); + CsvUtils.checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); } private boolean isKeyBelongsToNonRestType(Object value, BString key) { @@ -671,7 +648,7 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { if (!isRecursive && config.nilAsOptionalField && !fieldType.isNilable() && CsvUtils.isNullValue(nilValue, csvMember) && currentField != null && SymbolFlags.isFlagOn(currentField.getFlags(), SymbolFlags.OPTIONAL)) { - return SkipMappedValue.createSkippedValue(); + return CsvUtils.SkipMappedValue.createSkippedValue(); } if (config.stringConversion && csvMember instanceof BString str) { Object convertedValue = CsvCreator.convertToExpectedType(str, type, config); @@ -697,8 +674,8 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { case TypeTags.UNSIGNED16_INT_TAG: case TypeTags.UNSIGNED32_INT_TAG: case TypeTags.FINITE_TYPE_TAG: - if (checkTypeCompatibility(fieldType, csvMember, config.stringConversion)) { - Object value = convertToBasicType(csvMember, fieldType, config); + if (CsvUtils.checkTypeCompatibility(fieldType, csvMember, config.stringConversion)) { + Object value = CsvUtils.convertToBasicType(csvMember, fieldType, config); if (!(value instanceof BError)) { return value; } @@ -707,12 +684,12 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { case TypeTags.UNION_TAG: for (Type memberType : ((UnionType) fieldType).getMemberTypes()) { memberType = TypeUtils.getReferredType(memberType); - if (!isBasicType(memberType)) { + if (!CsvUtils.isBasicType(memberType)) { throw DiagnosticLog.error(DiagnosticErrorCode .EXPECTED_TYPE_CAN_ONLY_CONTAIN_BASIC_TYPES, memberType); } Object value = getFieldValue(memberType, csvMember, true); - if (!(value instanceof BError || value instanceof UnMappedValue)) { + if (!(value instanceof BError || value instanceof CsvUtils.UnMappedValue)) { return value; } } @@ -736,24 +713,24 @@ private Object getFieldValue(Type type, Object csvMember, boolean isRecursive) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TYPE, type); } } - return UnMappedValue.createUnMappedValue(); + return CsvUtils.UnMappedValue.createUnMappedValue(); } private void addRestField(Type type, BString key, Object csvMember) { Object value = getFieldValue(type, csvMember, false); - if (!(value instanceof UnMappedValue)) { + 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); - if (!(value instanceof UnMappedValue || value instanceof SkipMappedValue)) { + if (!(value instanceof CsvUtils.UnMappedValue || value instanceof CsvUtils.SkipMappedValue)) { ((BMap) currentCsvNode).put(StringUtils.fromString(fieldNames.pop()), value); return; } - if (isMapType || value instanceof SkipMappedValue) { + if (isMapType || value instanceof CsvUtils.SkipMappedValue) { return; } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, recValue, key); @@ -763,7 +740,7 @@ public void addValuesToArrayType(Object arrayValue, Type type, int index, Object currentCsvNode, CsvConfig config) { Object value = getFieldValue(type, arrayValue, false); boolean isArrayType = type instanceof ArrayType; - if (!(value instanceof UnMappedValue)) { + if (!(value instanceof CsvUtils.UnMappedValue)) { if (isArrayType) { ArrayType arrayType = (ArrayType) TypeUtils.getType(type); if (arrayType.getState() == ArrayType.ArrayState.CLOSED && @@ -779,8 +756,7 @@ public void addValuesToArrayType(Object arrayValue, Type type, int index, private void setRootCsvNodeForNonUnionArrays(Type referredType, Type type) { referredType = TypeUtils.getReferredType(referredType); - if (referredType.getTag() == TypeTags.ARRAY_TAG) { - ArrayType arrayType = (ArrayType) referredType; + if (referredType instanceof ArrayType arrayType) { rootCsvNode = ValueCreator.createArrayValue(arrayType); expectedArrayElementType = TypeUtils.getReferredType((arrayType).getElementType()); return; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java similarity index 94% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java index 98f5b3a..35a92bd 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/csv/Native.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/Native.java @@ -16,8 +16,14 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.csv; +package io.ballerina.lib.data.csvdata.csv; +import io.ballerina.lib.data.csvdata.io.DataReaderTask; +import io.ballerina.lib.data.csvdata.io.DataReaderThreadPool; +import io.ballerina.lib.data.csvdata.utils.Constants; +import io.ballerina.lib.data.csvdata.utils.CsvConfig; +import io.ballerina.lib.data.csvdata.utils.DiagnosticErrorCode; +import io.ballerina.lib.data.csvdata.utils.DiagnosticLog; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.values.BArray; @@ -27,12 +33,6 @@ import io.ballerina.runtime.api.values.BStream; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; -import io.ballerina.stdlib.data.csvdata.io.DataReaderTask; -import io.ballerina.stdlib.data.csvdata.io.DataReaderThreadPool; -import io.ballerina.stdlib.data.csvdata.utils.Constants; -import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticErrorCode; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import java.io.ByteArrayInputStream; import java.io.InputStreamReader; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java b/native/src/main/java/io/ballerina/lib/data/csvdata/io/BallerinaByteBlockInputStream.java similarity index 98% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/io/BallerinaByteBlockInputStream.java index b6705a2..63c3945 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/BallerinaByteBlockInputStream.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/io/BallerinaByteBlockInputStream.java @@ -16,8 +16,9 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.io; +package io.ballerina.lib.data.csvdata.io; +import io.ballerina.lib.data.csvdata.utils.DiagnosticLog; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.async.Callback; import io.ballerina.runtime.api.async.StrandMetadata; @@ -28,7 +29,6 @@ import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BString; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import java.io.IOException; import java.io.InputStream; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java b/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderTask.java similarity index 94% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderTask.java index 0f9e278..b4186bf 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderTask.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderTask.java @@ -15,8 +15,11 @@ * specific language governing permissions and limitations * under the License. */ -package io.ballerina.stdlib.data.csvdata.io; +package io.ballerina.lib.data.csvdata.io; +import io.ballerina.lib.data.csvdata.csv.CsvParser; +import io.ballerina.lib.data.csvdata.utils.CsvConfig; +import io.ballerina.lib.data.csvdata.utils.DiagnosticLog; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.types.MethodType; @@ -25,9 +28,6 @@ import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BString; import io.ballerina.runtime.api.values.BTypedesc; -import io.ballerina.stdlib.data.csvdata.csv.CsvParser; -import io.ballerina.stdlib.data.csvdata.utils.CsvConfig; -import io.ballerina.stdlib.data.csvdata.utils.DiagnosticLog; import java.io.InputStreamReader; import java.nio.charset.Charset; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java b/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java similarity index 93% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java index 55e732f..ae54392 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/io/DataReaderThreadPool.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package io.ballerina.stdlib.data.csvdata.io; +package io.ballerina.lib.data.csvdata.io; import java.util.concurrent.ExecutorService; import java.util.concurrent.SynchronousQueue; @@ -28,7 +28,7 @@ * * @since 0.1.0 */ -public class DataReaderThreadPool { +public final class DataReaderThreadPool { private static final int CORE_POOL_SIZE = 0; private static final int MAX_POOL_SIZE = 50; private static final long KEEP_ALIVE_TIME = 60L; @@ -36,6 +36,9 @@ public class DataReaderThreadPool { public static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS, new SynchronousQueue<>(), new DataThreadFactory()); + private DataReaderThreadPool() { + } + /** * Thread factory for data reader. */ diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java similarity index 79% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java index a9dec36..987cc2b 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java @@ -1,4 +1,4 @@ -package io.ballerina.stdlib.data.csvdata.utils; +package io.ballerina.lib.data.csvdata.utils; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BString; @@ -35,6 +35,18 @@ public static class LineTerminator { public static final String CRLF = "\r\n"; } + public static class EscapeChar { + public static final char DOUBLE_QUOTES_CHAR = '"'; + public static final char BACKSLASH_CHAR = '\\'; + public static final char SLASH_CHAR = '/'; + public static final char BACKSPACE_CHAR = 'b'; + public static final char FORM_FEED_CHAR = 'f'; + public static final char NEWLINE_CHAR = 'n'; + public static final char CARRIAGE_RETURN_CHAR = 'r'; + public static final char TAB_CHAR = 't'; + public static final char UNICODE_START_CHAR = 'u'; + } + public static final String SKIP_LINE_RANGE_SEP = "-"; public static final String FIELD = "$field$."; public static final String NAME = "Name"; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java similarity index 63% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java index 8e772e1..abfc9a5 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java @@ -1,26 +1,10 @@ -package io.ballerina.stdlib.data.csvdata.utils; +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; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ABSENT_AS_NILABLE; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ALLOW_DATA_PROJECTION; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.COMMENT_CHAR; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.CUSTOM_HEADERS; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.DELIMITER; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.ESCAPE_CHAR; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.HEADER; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.LINE_TERMINATOR; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.LOCALE; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.NIL_AS_OPTIONAL; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.NIL_VALUE; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.SKIP_LINES; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.STRING_CONVERSION; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.ConfigConstants.TEXT_ENCLOSURE; - public class CsvConfig { public char delimiter = ','; public char textEnclosure = '\\'; @@ -30,7 +14,7 @@ public class CsvConfig { public Object skipLines = null; public Object nilValue = null; public char comment = '#'; - public String locale = "EN/US"; + public String locale = "en_US"; public boolean nilAsOptionalField = false; public boolean absentAsNilableType = false; public boolean allowDataProjection = true; @@ -101,24 +85,24 @@ private CsvConfig(Object skipLines, boolean nilAsOptionalField, boolean absentAs public static CsvConfig createListTypeOptions(BMap options) { updateDataProjectOptions(options); return new CsvConfig( - options.get(SKIP_LINES), - options.getBooleanValue(NIL_AS_OPTIONAL).booleanValue(), - options.getBooleanValue(ABSENT_AS_NILABLE).booleanValue(), - options.getBooleanValue(ALLOW_DATA_PROJECTION).booleanValue(), - options.getBooleanValue(STRING_CONVERSION).booleanValue() + 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) { updateDataProjectOptions(options); return new CsvConfig( - options.get(SKIP_LINES), - options.getBooleanValue(NIL_AS_OPTIONAL).booleanValue(), - options.getBooleanValue(ABSENT_AS_NILABLE).booleanValue(), - options.getBooleanValue(ALLOW_DATA_PROJECTION).booleanValue(), - options.getBooleanValue(STRING_CONVERSION).booleanValue(), - options.get(CUSTOM_HEADERS), - options.getBooleanValue(ENABLE_CONSTRAINT_VALIDATION).booleanValue() + 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() ); } @@ -163,60 +147,60 @@ private CsvConfig(char delimiter, char textEnclosure, Object header, char escape public static CsvConfig createRecordAsRecordOption(BMap options) { updateDataProjectOptions(options); return new CsvConfig( - options.getBooleanValue(ENABLE_CONSTRAINT_VALIDATION), - options.get(SKIP_LINES), - options.getBooleanValue(NIL_AS_OPTIONAL), - options.getBooleanValue(ABSENT_AS_NILABLE), - options.getBooleanValue(ALLOW_DATA_PROJECTION) + 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( - StringUtils.getStringValue(options.getStringValue(DELIMITER)).charAt(0), - StringUtils.getStringValue(options.getStringValue(TEXT_ENCLOSURE)).charAt(0), - options.get(HEADER), - StringUtils.getStringValue(options.getStringValue(ESCAPE_CHAR)).charAt(0), - options.get(LINE_TERMINATOR), - options.get(SKIP_LINES), - options.get(NIL_VALUE), - StringUtils.getStringValue(options.getStringValue(COMMENT_CHAR)).charAt(0), - StringUtils.getStringValue(options.getStringValue(LOCALE)), - options.getBooleanValue(NIL_AS_OPTIONAL), - options.getBooleanValue(ABSENT_AS_NILABLE), - options.getBooleanValue(ALLOW_DATA_PROJECTION) + 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.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(DELIMITER)).charAt(0), - StringUtils.getStringValue(options.getStringValue(TEXT_ENCLOSURE)).charAt(0), - options.get(HEADER), - StringUtils.getStringValue(options.getStringValue(ESCAPE_CHAR)).charAt(0), - options.get(LINE_TERMINATOR), - options.get(SKIP_LINES), - options.getStringValue(NIL_VALUE), - StringUtils.getStringValue(options.getStringValue(COMMENT_CHAR)).charAt(0), - StringUtils.getStringValue(options.getStringValue(LOCALE)), - options.getBooleanValue(NIL_AS_OPTIONAL), - options.getBooleanValue(ABSENT_AS_NILABLE), - options.getBooleanValue(ALLOW_DATA_PROJECTION), - options.get(CUSTOM_HEADERS), - options.getBooleanValue(ENABLE_CONSTRAINT_VALIDATION) + 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) ); } public static CsvConfig createToRecordOptions(BMap options) { updateDataProjectOptions(options); return new CsvConfig( - options.get(SKIP_LINES), - options.getBooleanValue(NIL_AS_OPTIONAL), - options.getBooleanValue(ABSENT_AS_NILABLE), - options.getBooleanValue(ALLOW_DATA_PROJECTION), - options.get(CUSTOM_HEADERS) + 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) ); } @@ -226,15 +210,17 @@ public static CsvConfig createConfigOptionsForUnion(CsvConfig config) { } private static void updateDataProjectOptions(BMap options) { - Object allowProjections = options.get(ALLOW_DATA_PROJECTION); + Object allowProjections = options.get(Constants.ConfigConstants.ALLOW_DATA_PROJECTION); if (allowProjections instanceof Boolean) { - options.put(NIL_AS_OPTIONAL, false); - options.put(ABSENT_AS_NILABLE, false); + options.put(Constants.ConfigConstants.NIL_AS_OPTIONAL, false); + options.put(Constants.ConfigConstants.ABSENT_AS_NILABLE, false); return; } BMap projections = (BMap) allowProjections; - options.put(ALLOW_DATA_PROJECTION, true); - options.put(NIL_AS_OPTIONAL, projections.getBooleanValue(NIL_AS_OPTIONAL)); - options.put(ABSENT_AS_NILABLE, projections.getBooleanValue(ABSENT_AS_NILABLE)); + options.put(Constants.ConfigConstants.ALLOW_DATA_PROJECTION, true); + options.put(Constants.ConfigConstants.NIL_AS_OPTIONAL, projections.getBooleanValue( + Constants.ConfigConstants.NIL_AS_OPTIONAL)); + options.put(Constants.ConfigConstants.ABSENT_AS_NILABLE, projections.getBooleanValue( + Constants.ConfigConstants.ABSENT_AS_NILABLE)); } } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java similarity index 83% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java index 1a927b5..c35a900 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java @@ -1,4 +1,4 @@ -package io.ballerina.stdlib.data.csvdata.utils; +package io.ballerina.lib.data.csvdata.utils; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.flags.SymbolFlags; @@ -21,9 +21,10 @@ import java.util.Map; import java.util.Optional; -import static io.ballerina.stdlib.data.csvdata.utils.Constants.SKIP_LINE_RANGE_SEP; +import static io.ballerina.lib.data.csvdata.utils.Constants.SKIP_LINE_RANGE_SEP; public class CsvUtils { + private static final long[] EMPTY_LONG_ARRAY = new long[]{}; public static boolean isCarriageTokenPresent = false; public static void setCarriageTokenPresent(boolean isCarriageTokenPresent) { @@ -123,24 +124,45 @@ public static boolean isHeaderFieldsEmpty(Map currentField) { public static boolean checkTypeCompatibility(Type constraintType, Object csv, boolean stringConversion) { int tag = constraintType.getTag(); - if ((csv instanceof BString && (stringConversion || tag == TypeTags.STRING_TAG - || tag == TypeTags.CHAR_STRING_TAG || isJsonOrAnyDataOrAny(tag))) - || (csv instanceof Long && (tag == TypeTags.INT_TAG - || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.BYTE_TAG - || tag == TypeTags.SIGNED8_INT_TAG || tag == TypeTags.SIGNED16_INT_TAG - || tag == TypeTags.SIGNED32_INT_TAG || tag == TypeTags.UNSIGNED8_INT_TAG - || tag == TypeTags.UNSIGNED16_INT_TAG || tag == TypeTags.UNSIGNED32_INT_TAG - || isJsonOrAnyDataOrAny(tag))) - || (csv instanceof BDecimal && ((tag == TypeTags.DECIMAL_TAG - || tag == TypeTags.FLOAT_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag))) - || (csv instanceof Double && ((tag == TypeTags.FLOAT_TAG - || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag))) - || (Boolean.class.isInstance(csv) && (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag))) - || (csv == null && (tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag)))) { - return true; - } else { - return false; + if (csv instanceof BString) { + if (stringConversion || tag == TypeTags.STRING_TAG + || tag == TypeTags.CHAR_STRING_TAG || isJsonOrAnyDataOrAny(tag)) { + return true; + } + } + if (csv instanceof Long) { + if (tag == TypeTags.INT_TAG + || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.BYTE_TAG + || tag == TypeTags.SIGNED8_INT_TAG || tag == TypeTags.SIGNED16_INT_TAG + || tag == TypeTags.SIGNED32_INT_TAG || tag == TypeTags.UNSIGNED8_INT_TAG + || tag == TypeTags.UNSIGNED16_INT_TAG || tag == TypeTags.UNSIGNED32_INT_TAG + || isJsonOrAnyDataOrAny(tag)) { + return true; + } + } + if (csv instanceof BDecimal) { + if ((tag == TypeTags.DECIMAL_TAG + || tag == TypeTags.FLOAT_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag)) { + return true; + } } + if (csv instanceof Double) { + if ((tag == TypeTags.FLOAT_TAG + || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag)) { + return true; + } + } + if (Boolean.class.isInstance(csv)) { + if (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag)) { + return true; + } + } + if (csv == null) { + if (tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag)) { + return true; + } + } + return false; } private static boolean isJsonOrAnyDataOrAny(int tag) { @@ -159,8 +181,7 @@ public static int getTheActualExpectedType(Type type) { } } - public static HashMap - processNameAnnotationsAndBuildCustomFieldMap(RecordType recordType, + public static Map processNameAnnotationsAndBuildCustomFieldMap(RecordType recordType, Map fieldHierarchy) { BMap annotations = recordType.getAnnotations(); HashMap updatedRecordFieldNames = new HashMap<>(); @@ -240,12 +261,11 @@ public static long[] getSkipDataRows(Object skipLines) { if (skipLines == null) { return new long[]{}; } - if (skipLines instanceof BArray) { - BArray skipLinesArray = (BArray) skipLines; + if (skipLines instanceof BArray skipLinesArray) { if (skipLinesArray.getLength() == 0) { - return new long[]{}; + return EMPTY_LONG_ARRAY; } - skipDataRows = (skipLinesArray).getIntArray(); + skipDataRows = skipLinesArray.getIntArray(); return skipDataRows; } @@ -257,8 +277,8 @@ public static boolean isNullValue(Object nullValue, Object value) { if (value == null) { return true; } - if (value instanceof BString) { - value = StringUtils.getStringValue(value); + if (value instanceof BString bString) { + value = StringUtils.getStringValue(bString); } if (value instanceof String v) { if ((nullValue == null) && (Constants.Values.NULL.equalsIgnoreCase(v) @@ -274,8 +294,8 @@ public static boolean isNullValue(Object nullValue, Object value) { } public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object lineTerminatorObj) { - if (lineTerminatorObj instanceof BArray) { - Object[] lineTerminators = ((BArray) lineTerminatorObj).getValues(); + if (lineTerminatorObj instanceof BArray array) { + Object[] lineTerminators = array.getValues(); for (Object lineTerminator: lineTerminators) { if (lineTerminator != null && c == Constants.LineTerminator.LF) { String lineTerminatorString = lineTerminator.toString(); diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java similarity index 95% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java index 06c1488..d3ce960 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DataUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java @@ -1,4 +1,4 @@ -package io.ballerina.stdlib.data.csvdata.utils; +package io.ballerina.lib.data.csvdata.utils; import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BTypedesc; diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java similarity index 98% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java index 20e7ac1..ce669fd 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.utils; +package io.ballerina.lib.data.csvdata.utils; /** * Represents a diagnostic error code. diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java similarity index 92% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java index 1836d4a..e4687d5 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/DiagnosticLog.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.utils; +package io.ballerina.lib.data.csvdata.utils; import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.api.utils.StringUtils; @@ -48,7 +48,7 @@ private static String formatMessage(DiagnosticErrorCode code, Object[] args) { } public static BError getCsvError(String message, String errorType) { - return ErrorCreator.createError(io.ballerina.stdlib.data.csvdata.utils.ModuleUtils.getModule(), + return ErrorCreator.createError(ModuleUtils.getModule(), errorType, StringUtils.fromString(message), null, null); } diff --git a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/ModuleUtils.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/ModuleUtils.java similarity index 96% rename from native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/ModuleUtils.java rename to native/src/main/java/io/ballerina/lib/data/csvdata/utils/ModuleUtils.java index d9de709..486c9f3 100644 --- a/native/src/main/java/io/ballerina/stdlib/data/csvdata/utils/ModuleUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/ModuleUtils.java @@ -16,7 +16,7 @@ * under the License. */ -package io.ballerina.stdlib.data.csvdata.utils; +package io.ballerina.lib.data.csvdata.utils; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Module; diff --git a/native/src/main/java/module-info.java b/native/src/main/java/module-info.java index dfa31e5..de54042 100644 --- a/native/src/main/java/module-info.java +++ b/native/src/main/java/module-info.java @@ -22,6 +22,6 @@ requires junit; requires org.apache.commons.lang3; requires io.ballerina.stdlib.constraint; - exports io.ballerina.stdlib.data.csvdata.csv; - exports io.ballerina.stdlib.data.csvdata.utils; + exports io.ballerina.lib.data.csvdata.csv; + exports io.ballerina.lib.data.csvdata.utils; } From b6017982ab700bbd176bf15cceacdd993bee648f Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 29 Jul 2024 22:46:23 +0530 Subject: [PATCH 080/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 75 ++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c07b540..9f46b2e 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,12 +12,27 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"} + {org = "ballerina", name = "io"}, + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "test"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} ] +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -26,3 +41,61 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + From 08d583f2813eb4138ca46c1634425355a3a899c2 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 29 Jul 2024 22:48:52 +0530 Subject: [PATCH 081/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 75 +------------------------------------ 1 file changed, 1 insertion(+), 74 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 9f46b2e..c07b540 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,27 +12,12 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "io"}, - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "test"} + {org = "ballerina", name = "jballerina.java"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} ] -[[package]] -org = "ballerina" -name = "io" -version = "1.6.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -41,61 +26,3 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - From e4184a62013f160e662528b5dd333bfcbc68aaf1 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 29 Jul 2024 23:56:30 +0530 Subject: [PATCH 082/147] Add more tests for compiler plugin tests --- ballerina-tests/build.gradle | 2 +- .../tests/csv_error_content.txt | 2 + .../tests/parse_string_compatibality_test.bal | 49 ++++++++++++ ballerina/build.gradle | 2 +- .../csvdata/compiler/CompilerPluginTest.java | 40 ++++++++++ .../sample_package_1/Ballerina.toml | 3 +- .../sample_package_2/Ballerina.toml | 5 +- .../sample_package_3/Ballerina.toml | 5 ++ .../sample_package_3/main.bal | 5 ++ .../sample_package_4/Ballerina.toml | 5 ++ .../sample_package_4/main.bal | 17 ++++ .../sample_package_5/Ballerina.toml | 5 ++ .../sample_package_5/main.bal | 3 + .../compiler/CsvDataTypeValidator.java | 5 +- .../lib/data/csvdata/FromString.java | 79 +++++++++++-------- .../lib/data/csvdata/csv/CsvParser.java | 9 +-- .../lib/data/csvdata/csv/CsvTraversal.java | 51 ++++++------ .../lib/data/csvdata/utils/CsvUtils.java | 47 +++++++---- 18 files changed, 243 insertions(+), 91 deletions(-) create mode 100644 ballerina-tests/type-compatible-tests/tests/csv_error_content.txt create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_3/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_3/main.bal create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/main.bal create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/main.bal diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index fec5a92..03df5cf 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -30,7 +30,7 @@ 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.stdlib.data.*:ballerina.*" -def testPackages = ["user-config-tests", "parse-string-array-types-tests", "type-compatible-tests", "unicode-tests", "constraint-validation-tests", +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 testCommonPackage = "csv-commons" diff --git a/ballerina-tests/type-compatible-tests/tests/csv_error_content.txt b/ballerina-tests/type-compatible-tests/tests/csv_error_content.txt new file mode 100644 index 0000000..d2335d3 --- /dev/null +++ b/ballerina-tests/type-compatible-tests/tests/csv_error_content.txt @@ -0,0 +1,2 @@ +a, b, c d, e +"Hello W \ No newline at end of file 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 82418ee..35bf23e 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 @@ -20,6 +20,7 @@ import ballerina/io; import ballerina/test; const string filepath = "tests/csv_content.txt"; +const string errorFilepath = "tests/csv_error_content.txt"; @test:Config function testFromCsvStringWithTypeCompatibility() { @@ -228,6 +229,14 @@ function testParseBytes() returns error? { ["Hello World", "\"Hello World\"", "Hello World", "2"], ["Hello World", "\"Hello World\"", "Hello World", "2"] ]); + + int[][]|csv:Error rec3 = csv:parseBytesToList(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, {}); + test:assertTrue(rec4 is csv:Error); + test:assertEquals(( rec4).message(), common:generateErrorMessageForInvalidCast("Hello World", "int")); } @test:Config @@ -247,4 +256,44 @@ function testParseStream() returns error? { ["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:parseStreamToRecord(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, {}); + test:assertTrue(rec4 is csv:Error); + test:assertEquals(( rec4).message(), "Error occurred while reading the stream: " + + common:generateErrorMessageForInvalidCast("Hello World", "int")); +} + +@test:Config +function testErrorParseBytes() returns error? { + byte[] csvBytes = check io:fileReadBytes(errorFilepath); + + int[][]|csv:Error rec3 = csv:parseBytesToList(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, {}); + test:assertTrue(rec4 is csv:Error); + test:assertTrue(( rec3).message().includes("cannot be cast into")); +} + +@test:Config +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, {}); + 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, {}); + test:assertTrue(rec4 is csv:Error); + test:assertTrue(( rec4).message().includes("cannot be cast into")); } diff --git a/ballerina/build.gradle b/ballerina/build.gradle index 13aed2b..efa4833 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -60,7 +60,7 @@ def stripBallerinaExtensionVersion(String extVersion) { apply plugin: 'io.ballerina.plugin' ballerina { - testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.stdlib.data.*:ballerina.*" + testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.lib.data.*:ballerina.*" packageOrganization = packageOrg module = packageName langVersion = ballerinaLangVersion 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 b1a7189..d2d6664 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 @@ -67,4 +67,44 @@ public void testInvalidRecordFields() { Assert.assertEquals(errorDiagnosticsList.size(), 1); Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), DUPLICATE_FIELD); } + + @Test + public void testInvalidProgram() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_3").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 1); + } + + @Test + public void testModuleLevelInvalidExpectedUnionType() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_4").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 10); + 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); + Assert.assertEquals(errorDiagnosticsList.get(3).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(4).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(5).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(6).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + 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); + } + + @Test + public void testEmptyProject() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_5").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 0); + } } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/Ballerina.toml index 437bf7b..80bcadd 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/Ballerina.toml +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/Ballerina.toml @@ -1,6 +1,5 @@ [package] -org = "admin" +org = "ballerina" name = "sample_package_1" version = "0.1.0" distribution = "2201.9.0" - diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/Ballerina.toml index 3b39d28..80bcadd 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/Ballerina.toml +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/Ballerina.toml @@ -1,6 +1,5 @@ [package] -org = "admin" -name = "sample_package_2" +org = "ballerina" +name = "sample_package_1" version = "0.1.0" distribution = "2201.9.0" - diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_3/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_3/Ballerina.toml new file mode 100644 index 0000000..ee11d8e --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_3/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "ballerina" +name = "sample_package_3" +version = "0.1.0" +distribution = "2201.9.0" diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_3/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_3/main.bal new file mode 100644 index 0000000..3253727 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_3/main.bal @@ -0,0 +1,5 @@ +// test when there is a compiler time error. +type A [[int1, string], [int, string]]; + +public function main() returns error? { +} diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/Ballerina.toml new file mode 100644 index 0000000..b42c32c --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "ballerina" +name = "sample_package_4" +version = "0.1.0" +distribution = "2201.9.0" 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 new file mode 100644 index 0000000..a8d1eb0 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/main.bal @@ -0,0 +1,17 @@ +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([], {}); diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/Ballerina.toml new file mode 100644 index 0000000..d3bf9e5 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "ballerina" +name = "sample_package_5" +version = "0.1.0" +distribution = "2201.9.0" diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/main.bal new file mode 100644 index 0000000..0ecaab9 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/main.bal @@ -0,0 +1,3 @@ +public function main() { + // test scenario without module import +} 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 878e30c..0efc318 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 @@ -285,8 +285,7 @@ private void reportDiagnosticInfo(SyntaxNodeAnalysisContext ctx, Optional currentLocation); DiagnosticInfo diagnosticInfo = new DiagnosticInfo(diagnosticsCodes.getCode(), diagnosticsCodes.getMessage(), diagnosticsCodes.getSeverity()); - DiagnosticInfo posDiagnosticInfo = allDiagnosticInfo.get(pos); - if (posDiagnosticInfo != null && posDiagnosticInfo.equals(diagnosticInfo)) { + if (pos == null || (allDiagnosticInfo.containsKey(pos) && allDiagnosticInfo.get(pos).equals(diagnosticInfo))) { return; } allDiagnosticInfo.put(pos, diagnosticInfo); @@ -296,6 +295,7 @@ private void reportDiagnosticInfo(SyntaxNodeAnalysisContext ctx, Optional initializer = moduleVariableDeclarationNode.initializer(); + currentLocation = moduleVariableDeclarationNode.typedBindingPattern().typeDescriptor().location(); if (initializer.isEmpty() || !isParseFunctionOfStringSource(initializer.get())) { return; } @@ -306,6 +306,7 @@ private void processModuleVariableDeclarationNode(ModuleVariableDeclarationNode private void processTypeDefinitionNode(TypeDefinitionNode typeDefinitionNode, SyntaxNodeAnalysisContext ctx) { Node typeDescriptor = typeDefinitionNode.typeDescriptor(); + currentLocation = typeDefinitionNode.typeDescriptor().location(); if (typeDescriptor.kind() != SyntaxKind.RECORD_TYPE_DESC) { return; } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java index 63b8341..bbea231 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java @@ -45,6 +45,7 @@ import java.util.Comparator; import java.util.List; import java.util.Locale; +import java.util.WeakHashMap; /** * Native implementation of data:fromStringWithType(string). @@ -52,25 +53,7 @@ * @since 0.1.0 */ public final class FromString { - private static String intRegex = "^[-+]?[0-9]+$"; - private static String doubleRegex = "^[-+]?[0-9]+(\\.[0-9]*)?(e[+-]?[0-9]+)?$"; - - private FromString() { - } - - private static Locale getLocale(CsvConfig config) { - Locale locale = CsvUtils.createLocaleFromString(config.locale); - DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale); - char decimalSeparator = dfs.getDecimalSeparator(); - char minusSign = dfs.getMinusSign(); - char zeroDigit = dfs.getZeroDigit(); - String exponentSeparator = dfs.getExponentSeparator(); - intRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+$"; - doubleRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+(" + - (decimalSeparator == '.' ? "\\." : decimalSeparator) - + "[" + zeroDigit + "-9]*)?(" + exponentSeparator + "[+-]?[" + zeroDigit + "-9]+)?$"; - return locale; - } + private static WeakHashMap localeAttributes = new WeakHashMap<>(); private static final List TYPE_PRIORITY_ORDER = List.of( TypeTags.INT_TAG, @@ -103,6 +86,9 @@ private static Locale getLocale(CsvConfig config) { public static final Integer UNSIGNED16_MAX_VALUE = 65535; public static final Integer UNSIGNED8_MAX_VALUE = 255; + private FromString() { + } + public static Object fromStringWithType(BString string, Type expType, CsvConfig config) { String value = string.getValue(); @@ -155,7 +141,7 @@ private static Object convertToSingletonValue(String str, Object singletonValue, private static Long stringToInt(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); - if (isIntegerValue(value, number)) { + if (isIntegerValue(value, number, config.locale)) { return number.longValue(); } throw new NumberFormatException(); @@ -163,7 +149,7 @@ private static Long stringToInt(String value, CsvConfig config) throws NumberFor private static int stringToByte(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); - if (isIntegerValue(value, number)) { + if (isIntegerValue(value, number, config.locale)) { int intValue = parseNumberValue(value, config).intValue(); if (isByteLiteral(intValue)) { return intValue; @@ -175,7 +161,7 @@ private static int stringToByte(String value, CsvConfig config) throws NumberFor private static long stringToSigned8Int(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); - if (isIntegerValue(value, number)) { + if (isIntegerValue(value, number, config.locale)) { long intValue = parseNumberValue(value, config).longValue(); if (isSigned8LiteralValue(intValue)) { return intValue; @@ -188,7 +174,7 @@ private static long stringToSigned16Int(String value, CsvConfig config) throws N ParseException { Number number = parseNumberValue(value, config); - if (isIntegerValue(value, number)) { + if (isIntegerValue(value, number, config.locale)) { long intValue = parseNumberValue(value, config).longValue(); if (isSigned16LiteralValue(intValue)) { return intValue; @@ -200,7 +186,7 @@ private static long stringToSigned16Int(String value, CsvConfig config) throws N private static long stringToSigned32Int(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); - if (isIntegerValue(value, number)) { + if (isIntegerValue(value, number, config.locale)) { long intValue = parseNumberValue(value, config).longValue(); if (isSigned32LiteralValue(intValue)) { return intValue; @@ -212,7 +198,7 @@ private static long stringToSigned32Int(String value, CsvConfig config) throws N private static long stringToUnsigned8Int(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); - if (isIntegerValue(value, number)) { + if (isIntegerValue(value, number, config.locale)) { long intValue = parseNumberValue(value, config).longValue(); if (isUnsigned8LiteralValue(intValue)) { return intValue; @@ -224,7 +210,7 @@ private static long stringToUnsigned8Int(String value, CsvConfig config) private static long stringToUnsigned16Int(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); - if (isIntegerValue(value, number)) { + if (isIntegerValue(value, number, config.locale)) { long intValue = parseNumberValue(value, config).longValue(); if (isUnsigned16LiteralValue(intValue)) { return intValue; @@ -236,7 +222,7 @@ private static long stringToUnsigned16Int(String value, CsvConfig config) private static long stringToUnsigned32Int(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); - if (isIntegerValue(value, number)) { + if (isIntegerValue(value, number, config.locale)) { long intValue = parseNumberValue(value, config).longValue(); if (isUnsigned32LiteralValue(intValue)) { return intValue; @@ -254,7 +240,7 @@ private static BString stringToChar(String value) throws NumberFormatException { private static Double stringToFloat(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); - if (isDoubleValue(value, number)) { + if (isDoubleValue(value, number, config.locale)) { return number.doubleValue(); } throw new NumberFormatException(); @@ -263,7 +249,7 @@ private static Double stringToFloat(String value, CsvConfig config) throws Numbe private static BDecimal stringToDecimal(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); - if (isDoubleValue(value, number)) { + if (isDoubleValue(value, number, config.locale)) { BigDecimal decimalValue = BigDecimal.valueOf(number.doubleValue()); return ValueCreator.createDecimalValue(decimalValue); } @@ -342,12 +328,13 @@ private static boolean isCharLiteralValue(String value) { return value.codePoints().count() == 1; } - private static boolean isIntegerValue(String value, Number number) { - return number instanceof Long && value.matches(intRegex); + private static boolean isIntegerValue(String value, Number number, String localeStr) { + return number instanceof Long && value.matches(getLocale(localeStr).intRegex()); } - private static boolean isDoubleValue(String value, Number number) { - return (number instanceof Double || number instanceof Long) && value.matches(doubleRegex); + private static boolean isDoubleValue(String value, Number number, String localeStr) { + return (number instanceof Double || number instanceof Long) + && value.matches(getLocale(localeStr).doubleRegex()); } private static BError returnError(String value, String expType) { @@ -356,7 +343,31 @@ private static BError returnError(String value, String expType) { } private static Number parseNumberValue(String numberString, CsvConfig config) throws ParseException { - NumberFormat numberFormat = NumberFormat.getInstance(getLocale(config)); + NumberFormat numberFormat = NumberFormat.getInstance(getLocale(config.locale).locale()); return numberFormat.parse(numberString); } + + private static LocaleInfo getLocale(String localeStr) { + if (!localeAttributes.containsKey(localeStr)) { + localeAttributes.put(localeStr, computeLocaleIfAbsent(localeStr)); + } + return localeAttributes.get(localeStr); + } + + private static LocaleInfo computeLocaleIfAbsent(String localeStr) { + Locale locale = CsvUtils.createLocaleFromString(localeStr); + DecimalFormatSymbols dfs = new DecimalFormatSymbols(locale); + char decimalSeparator = dfs.getDecimalSeparator(); + char minusSign = dfs.getMinusSign(); + char zeroDigit = dfs.getZeroDigit(); + String exponentSeparator = dfs.getExponentSeparator(); + String intRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+$"; + String doubleRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+(" + + (decimalSeparator == '.' ? "\\." : decimalSeparator) + + "[" + zeroDigit + "-9]*)?(" + exponentSeparator + "[+-]?[" + zeroDigit + "-9]+)?$"; + return new LocaleInfo(locale, intRegex, doubleRegex); + } + + private record LocaleInfo(Locale locale, String intRegex, String doubleRegex) { + } } 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 d276d86..6b8f60d 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 @@ -311,9 +311,7 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp } private void addFieldNamesForNonHeaderState() { - for (Map.Entry entry: this.fieldHierarchy.entrySet()) { - this.fieldNames.put(entry.getKey(), entry.getValue()); - } + this.fieldNames.putAll(this.fieldHierarchy); } private void append(char ch) { @@ -427,9 +425,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } break; } - if (state == null) { - state = this; - } sm.index = i + 1; return state; } @@ -454,7 +449,7 @@ private static int getHeaderStartRowWhenHeaderIsPresent(Object header) { } private static void finalizeHeaders(StateMachine sm) throws CsvParserException { - if (sm.headers.size() == 0) { + if (sm.headers.isEmpty()) { throw DiagnosticLog.error(DiagnosticErrorCode.HEADER_CANNOT_BE_EMPTY); } Type expType = sm.expectedArrayElementType; 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 421c3c0..5e2c630 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 @@ -110,7 +110,7 @@ void reset() { fieldHierarchy.clear(); updatedRecordFieldNames.clear(); headerFieldHierarchy.clear(); - fields.clear();; + fields.clear(); restType = null; fieldNames.clear(); rootCsvNode = null; @@ -128,7 +128,7 @@ void resetForUnionTypes() { fieldHierarchy.clear(); updatedRecordFieldNames.clear(); headerFieldHierarchy.clear(); - fields.clear();; + fields.clear(); restType = null; fieldNames.clear(); rootCsvNode = null; @@ -155,15 +155,9 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { } if (referredType.getTag() != TypeTags.UNION_TAG) { - if (referredType.getTag() == TypeTags.ARRAY_TAG) { - Type arrayElementType = TypeUtils.getReferredType(((ArrayType) referredType).getElementType()); - if (arrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { - Optional mutableType = CsvUtils.getMutableType((IntersectionType) arrayElementType); - if (mutableType.isPresent()) { - return CsvCreator.constructReadOnlyValue(traverseCsv(csv, - config, TypeCreator.createArrayType(mutableType.get()))); - } - } + Optional intersectionValue = handleNonUnionIntersection(referredType, csv, config); + if (intersectionValue.isPresent()) { + return intersectionValue.get(); } int expectedArraySize = ((ArrayType) referredType).getSize(); setRootCsvNodeForNonUnionArrays(referredType, type); @@ -175,6 +169,20 @@ public Object traverseCsv(BArray csv, CsvConfig config, Type type) { return rootCsvNode; } + private Optional handleNonUnionIntersection(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) { + Optional mutableType = CsvUtils.getMutableType((IntersectionType) arrayElementType); + if (mutableType.isPresent()) { + return Optional.of(CsvCreator.constructReadOnlyValue(traverseCsv(csv, + config, TypeCreator.createArrayType(mutableType.get())))); + } + } + } + return Optional.empty(); + } + private void traverseCsvWithUnionExpectedType(Type referredType, Type type, int sourceArraySize, BArray csv) { for (Type memberType: ((UnionType) referredType).getMemberTypes()) { @@ -324,7 +332,7 @@ public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray isCompatible = true; break; } catch (Exception e) { - int a = 1; + // ignore } } if (!isCompatible) { @@ -405,8 +413,7 @@ private void constructArrayValuesFromArray(BArray csvElement, Type type, int exp } Type memberType = getArrayOrTupleMemberType(type, index); if (memberType != null) { - addValuesToArrayType(csvElement.get(i), memberType, index, - currentCsvNode, config); + addValuesToArrayType(csvElement.get(i), memberType, index, currentCsvNode); } index++; } @@ -447,8 +454,7 @@ private void constructArrayValuesFromMap(BMap map, Type type, i } Type memberType = getArrayOrTupleMemberType(type, index); if (memberType != null) { - addValuesToArrayType(v, memberType, index, - currentCsvNode, config); + addValuesToArrayType(v, memberType, index, currentCsvNode); } index++; } @@ -526,7 +532,8 @@ private boolean checkExpectedTypeMatchWithHeadersForTuple(Type expectedType, Tup Field field = this.headerFieldHierarchy.remove(header); if (field != null) { - if (!config.stringConversion && type.getTag() != field.getFieldType().getTag()) { + if (!config.stringConversion && type != null + && type.getTag() != field.getFieldType().getTag()) { return false; } continue; @@ -590,7 +597,7 @@ private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappin fieldType = TypeUtils.getReferredType(currentField.getFieldType()); } else { addFieldInMapType(key); - fieldType = ((MapType) expectedType).getConstrainedType();; + fieldType = ((MapType) expectedType).getConstrainedType(); } addCurrentFieldValue(fieldType, csvElement.get(i - 1), key, mappingType); } @@ -736,8 +743,7 @@ 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, CsvConfig config) { + public void addValuesToArrayType(Object arrayValue, Type type, int index, Object currentCsvNode) { Object value = getFieldValue(type, arrayValue, false); boolean isArrayType = type instanceof ArrayType; if (!(value instanceof CsvUtils.UnMappedValue)) { @@ -765,11 +771,8 @@ private void setRootCsvNodeForNonUnionArrays(Type referredType, Type type) { } private Type getSourceElementTypeForTupleAndArrays(BArray csv) { - List memberTypes = new ArrayList<>(); if (csv.getType() instanceof TupleType tupleType) { - for (Type memberType: tupleType.getTupleTypes()) { - memberTypes.add(memberType); - } + List memberTypes = new ArrayList<>(tupleType.getTupleTypes()); return TypeCreator.createUnionType(memberTypes); } return csv.getElementType(); 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 c35a900..6a306dd 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 @@ -281,14 +281,18 @@ public static boolean isNullValue(Object nullValue, Object value) { value = StringUtils.getStringValue(bString); } if (value instanceof String v) { - if ((nullValue == null) && (Constants.Values.NULL.equalsIgnoreCase(v) - || Constants.Values.BALLERINA_NULL.equalsIgnoreCase(v))) { - return true; - } - if (nullValue != null && value.equals(StringUtils.getStringValue(nullValue))) { - return true; - } - return false; + return handleStringNullValue(nullValue, v, value); + } + return false; + } + + private static boolean handleStringNullValue(Object nullValue, String v, Object value) { + if ((nullValue == null) && (Constants.Values.NULL.equalsIgnoreCase(v) + || Constants.Values.BALLERINA_NULL.equalsIgnoreCase(v))) { + return true; + } + if (nullValue != null && value.equals(StringUtils.getStringValue(nullValue))) { + return true; } return false; } @@ -297,16 +301,11 @@ public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object li if (lineTerminatorObj instanceof BArray array) { Object[] lineTerminators = array.getValues(); for (Object lineTerminator: lineTerminators) { - if (lineTerminator != null && c == Constants.LineTerminator.LF) { - String lineTerminatorString = lineTerminator.toString(); - if (isCarriageTokenPresent) { - if (lineTerminatorString.equals(Constants.LineTerminator.CRLF)) { - return true; - } - continue; - } - return true; + Optional value = handleLineTerminator(lineTerminator, c); + if (value.isEmpty()) { + continue; } + return value.get(); } return false; } @@ -326,6 +325,20 @@ public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object li return false; } + private static Optional handleLineTerminator(Object lineTerminator, char c) { + if (lineTerminator != null && c == Constants.LineTerminator.LF) { + String lineTerminatorString = lineTerminator.toString(); + if (isCarriageTokenPresent) { + if (lineTerminatorString.equals(Constants.LineTerminator.CRLF)) { + return Optional.of(true); + } + return Optional.empty(); + } + return Optional.of(true); + } + return Optional.empty(); + } + public static class SortConfigurations { protected Object columnName; protected Object sortOrder; From 42b2c5b72d0be778f32bb41339fb96d88e58b49a Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 30 Jul 2024 00:49:58 +0530 Subject: [PATCH 083/147] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index f1d6945..bce49a1 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -13,7 +13,7 @@ export = ["data.csv"] graalvmCompatible = true [[platform.java17.dependency]] -groupId = "io.ballerina.stdlib" +groupId = "io.ballerina.lib" artifactId = "data.csv-native" version = "0.1.0" path = "../native/build/libs/data.csv-native-0.1.0-SNAPSHOT.jar" From 4ad18c38be3e126d47460e0f3facd3346475e85b Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 30 Jul 2024 02:17:09 +0530 Subject: [PATCH 084/147] Change package path to lib & refactor test variables --- ballerina-tests/build.gradle | 2 +- .../tests/constraint_validation_test.bal | 5 + .../tests/test_data_values.bal | 250 +- .../parse-list-types-tests/tests/types.bal | 2424 +--------------- .../tests/test_data_values.bal | 241 -- .../parse-record-types-tests/tests/types.bal | 2313 +-------------- .../tests/parse_string_to_array_test.bal | 36 +- .../tests/test_data_values.bal | 210 -- .../tests/types.bal | 2527 +--------------- .../tests/test_data_values.bal | 209 -- .../tests/types.bal | 2401 +--------------- .../tests/test_data_values.bal | 218 -- .../type-compatible-tests/tests/types.bal | 2541 +--------------- .../tests/test_data_values.bal | 249 -- .../union-type-tests/tests/types.bal | 2550 ----------------- .../tests/test_data_values.bal | 149 - build-config/resources/Ballerina.toml | 2 +- .../src/test/resources/testng.xml | 2 +- .../src/main/java/module-info.java | 2 +- gradle.properties | 2 +- native/src/main/java/module-info.java | 2 +- 21 files changed, 276 insertions(+), 16059 deletions(-) delete mode 100644 ballerina-tests/union-type-tests/tests/types.bal diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index 03df5cf..d99084e 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -29,7 +29,7 @@ def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/res def testCommonTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/CsvTestCommon.toml") def ballerinaDist = "${project.rootDir}/target/ballerina-runtime" def distributionBinPath = "${ballerinaDist}/bin" -def testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.stdlib.data.*:ballerina.*" +def testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.lib.data.*: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 testCommonPackage = "csv-commons" 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 fe017b0..e732ac4 100644 --- a/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal +++ b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal @@ -37,6 +37,11 @@ function testConstraintWithRecords() returns error? { 3, cde`); test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); + ConstrainedRec[]|csv:Error cRec1_2 = csv:parseStringToRecord(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 4,abc 11, cde`); diff --git a/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal index a9698aa..3a50795 100644 --- a/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal @@ -14,259 +14,11 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean? b3 = (); -boolean|int b4 = false; - -() n1 = (); -int? n2 = (); -() n3 = null; - -int i1 = 1; -int i2 = -2; -int i3 = int:MAX_VALUE; -int i4 = int:MIN_VALUE; -int i5 = 0; -2 i6 = 2; -int? i7 = (); -int|string i8 = 100; - -float f1 = 2.234; -float f2 = -3.21f; -float f3 = 0; -float f4 = float:Infinity; -float f5 = -float:Infinity; -float f6 = float:NaN; -2.3f f7 = 2.3; -float? f8 = (); -float|decimal f9 = 1.21; - -decimal d1 = 2.234; -decimal d2 = -3.21d; -decimal d3 = 0; -2.3d d4 = 2.3; -decimal? d5 = (); -decimal|int d6 = 1.21; - string s1 = "string"; string s2 = ""; string:Char s3 = "a"; -map bm1 = {b1, b2}; -map bm2 = {b1, b2, b3, n1, n3}; -map bm3 = {b1, b2, b3, b4, i1}; -map<()> bm4 = {n1, n3}; -map bm5 = {b1, b2, b3, b4:true}; - -map m5 = {i1, i2, i3, i4, i5, i6}; -map m6 = {f1, f2, f3, f4, f5, f6, f7}; -map m7 = {d1, d2, d3, d4}; -map m8 = {d1, f1, f9, f10: 1.23}; -map m9 = {s1, s2, s3}; -map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; -map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; - -boolean[] arr1 = [b1, b2]; -boolean?[] arr2 = [b1, b2, b3, n1, n3]; -(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; -()[] arr4 = [n1, n3]; -int[] arr5 = [i1, i2, i3, i4, i5, i6]; -float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; -decimal[] arr7 = [d1, d2, d3, d4]; -(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; -string[] arr9 = [s1, s2, s3]; -anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; - -[boolean, boolean] bt1 = [b1, b2]; -[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; -[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; -[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; -[boolean...] bt5 = [b1, b2]; - [string, string] st1 = [s1, s2]; [string, string, string, string] st2 = [s1, s2, s3, s2]; [string...] st3 = [s1, s2]; -[string, string, string...] st4 = [s1, s2, s3, s2]; - -[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; -[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; -[string?...] st7 = [s1, s2]; -[string...] st8 = []; -[string, string, string] st9 = [s1, s2, s3]; - -[(), ()] tup4 = [n1, n3]; -[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; -[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; -[string, string, string] tup9 = [s1, s2, s3]; -[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, - n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, json] tup11 = - [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, - f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 -]; - -[boolean, boolean...] restTup1 = [b1, b2]; -[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; -[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; -[(), ()...] restTup4 = [n1, n3]; -[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; -[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal...] restTup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; -[string...] restTup9 = [s1, s2, s3]; -[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 -]; - -var booleanRecordArray = [ - {b1, b2, b3, b4}, {b1, b2, b3, b4} -]; - -var booleanRecordArray2 = [ - {},{} -]; - -string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 -true,false,true,false -true,false, true,false -true,false,true,false -`; - -string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 -true,false, true,false,true -true,false, true,false,true`; - -string csvStringWithBooleanValues3 = string `b1,b2,b3 -${" "}${"\t"} -true, false,true -${" "} - TRUE, FALSE,() -${" "} - -true, true,FALSE - -`; - -string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 - true,(), (),false - true,(), null,false - -`; - -string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 - -true,false,true,2 - -true,false,true,3 -`; - -string csvStringWithBooleanValues6 = string `b2,b3 -(),() - -`; - -string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 -${b1},${b2},(),${b4} -`; - -string csvStringData1 = string ` - a, b, c, d, e, f - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData2 = string ` - hello, hello, (), 12, true, 12.34 - // comment - - a, b, c, d, e, f - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData3 = string ` - a, b, c, d, e, f - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData4 = string ` - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData5 = string ` - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData6 = string ` - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData7 = string ` - a@ b@ c@ d@ e@ f - 1@ string@ true@ 2.234@ -3.21@ () - 2@ s,tring@ true@ 2.234@ -3.21@ null - 3@ stri,ng@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; -string csvStringData8 = string ` - a@ b@ c@ d@ e@ f - - - - 1@ stri,ng@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ ()@-3.21 - 3@ string@ true@ 2.234@ -3.21@ null - - 4@ s,tring@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; - -string csvStringData9 = string ` - - 1@ string@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ -3.21@ null - - 3@ string@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ ()@-3.21 - - 5@ string@ true@ 2.234@ -3.21@ null`; +[string, string, string...] st4 = [s1, s2, s3, s2]; diff --git a/ballerina-tests/parse-list-types-tests/tests/types.bal b/ballerina-tests/parse-list-types-tests/tests/types.bal index 2c7c117..930205f 100644 --- a/ballerina-tests/parse-list-types-tests/tests/types.bal +++ b/ballerina-tests/parse-list-types-tests/tests/types.bal @@ -14,526 +14,6 @@ // specific language governing permissions and limitations // under the License. -type BooleanRecord1 record { - boolean b1; - boolean|string b2; - boolean|string? b3; - boolean b4; -}; - -type BooleanRecord2 record {| - boolean b1; - boolean|string b2; - boolean|string? b3; - boolean b4; -|}; - -type BooleanRecord3 record {| - boolean b1; - boolean? b3; -|}; - -type BooleanRecord4 record { - boolean b1; - boolean? b3; -}; - -type BooleanRecord5 record { - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); -}; - -type BooleanRecord6 record {| - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); -|}; - -type BooleanRecord7 record { - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type BooleanRecord8 record {| - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type BooleanRecord9 record {| - boolean b1; - boolean? b3; - boolean?...; -|}; - -type BooleanRecord10 record {| - boolean...; -|}; - -type BooleanRecord11 record {| - boolean b1; - string defaultableField = ""; - string? nillableField = (); - boolean?|string...; -|}; - -type BooleanRecord12 record {| - boolean b1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - boolean...; -|}; - -type BooleanRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - string|boolean...; -|}; - -type BooleanRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - boolean...; -|}; - -type BooleanRecord15 record {| - int b1; - string defaultableField = ""; - string? nillableField = (); - boolean?...; -|}; - -type BooleanRecord16 record {| - boolean?...; -|}; - -type BooleanRecord17 record {| - int...; -|}; - -type BooleanRecord18 record {| - boolean b2; - int?...; -|}; - -type NilRecord1 record { - () n1; - () n2; - () n3; -}; - -type NilRecord2 record {| - () n1; - () n2; - () n3; -|}; - -type NilRecord3 record {| - () n1; - () n4; -|}; - -type NilRecord4 record { - () n1; - () n4; -}; - -type NilRecord5 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -}; - -type NilRecord6 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type NilRecord7 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type NilRecord8 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type NilRecord9 record {| - () n1; - () n2; - ()...; -|}; - -type NilRecord10 record {| - ()...; -|}; - -type NilRecord11 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord12 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type NilRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type IntegerRecord1 record { - int i1; - int i2; - int i3; - int? i4; - int? i5; - int i6; - int i7; - int? i8; -}; - -type IntegerRecord2 record {| - int i1; - int? i2; - int i3; - int i4; - int? i5; - int i6; - int i7; - int? i8; -|}; - -type IntegerRecord3 record {| - int i1; - int i4; - int i6; -|}; - -type IntegerRecord4 record { - int i1; - int i4; - int i6; -}; - -type IntegerRecord5 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -}; - -type IntegerRecord6 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -|}; - -type IntegerRecord7 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type IntegerRecord8 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type IntegerRecord9 record {| - int i1; - int i2; - int...; -|}; - -type IntegerRecord10 record {| - int...; -|}; - -type IntegerRecord11 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord12 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type IntegerRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type FloatRecord1 record { - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -}; - -type FloatRecord2 record {| - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -|}; - -type FloatRecord3 record {| - float f1; - float f4; - float f7; -|}; - -type FloatRecord4 record { - float f1; - float f4; - float f7; -}; - -type FloatRecord5 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -}; - -type FloatRecord6 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type FloatRecord7 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type FloatRecord8 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type FloatRecord9 record {| - float f1; - float f2; - float...; -|}; - -type FloatRecord10 record {| - float...; -|}; - -type FloatRecord11 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord12 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type FloatRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type DecimalRecord1 record { - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -}; - -type DecimalRecord2 record {| - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -|}; - -type DecimalRecord3 record {| - decimal d1; - decimal d4; - decimal d7; -|}; - -type DecimalRecord4 record { - decimal d1; - decimal d4; - decimal d7; -}; - -type DecimalRecord5 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -}; - -type DecimalRecord6 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type DecimalRecord7 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type DecimalRecord8 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type DecimalRecord9 record {| - decimal d1; - decimal d2; - decimal...; -|}; - -type DecimalRecord10 record {| - decimal...; -|}; - -type DecimalRecord11 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord12 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type DecimalRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - type StringRecord1 record { string s1; string s2; @@ -546,46 +26,6 @@ type StringRecord2 record {| string s3; |}; -type StringRecord3 record {| - string s1; - string s4; -|}; - -type StringRecord4 record { - string s1; - string s4; -}; - -type StringRecord5 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -}; - -type StringRecord6 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type StringRecord7 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type StringRecord8 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - type StringRecord9 record {| string s1; string s2; @@ -596,54 +36,6 @@ type StringRecord10 record {| string...; |}; -type StringRecord11 record {| - string s1; - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord12 record {| - string d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord15 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord16 record {| - string?...; -|}; - -type StringRecord17 record {| - int...; -|}; - -type StringRecord18 record {| - string b2; - int?...; -|}; - type StringRecord19 record { string s1 = ""; string s2 = ""; @@ -667,354 +59,28 @@ type StringRecord23 record {| json...; |}; -type JsonRecord1 record { - json j1; - json j2; - json j3; -}; - -type JsonRecord2 record {| - json j1; - json j2; - json j3; -|}; - -type JsonRecord3 record {| - json j1; - json j4; -|}; - -type JsonRecord4 record { - json j1; - json j4; -}; - -type JsonRecord5 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -}; - -type JsonRecord6 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -|}; - -type JsonRecord7 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -}; - -type JsonRecord8 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -|}; - -type JsonRecord9 record {| - json j1; - json j2; - json...; -|}; - -type JsonRecord10 record {| - json...; -|}; - -type JsonRecord11 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord12 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type JsonRecord13 record {| - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord14 record {| - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type AnydataRecord1 record { - anydata anydata1; - anydata anydata2; - anydata anydata3; -}; - -type AnydataRecord2 record {| - anydata anydata1; - anydata anydata2; - anydata anydata3; +type CustomRecord15 record {| + string '1; + string '2; |}; -type AnydataRecord3 record {| - anydata anydata1; - anydata anydata4; +type CustomRecord16 record {| + string '1; + string '2; + string '3; + string '4; |}; -type AnydataRecord4 record { - anydata anydata1; - anydata anydata4; -}; - -type AnydataRecord5 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); +type CustomRecord17 record { + string '1; + string '2; }; -type AnydataRecord6 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type AnydataRecord7 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type AnydataRecord8 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type AnydataRecord9 record {| - anydata anydata1; - anydata anydata2; - anydata...; -|}; - -type AnydataRecord10 record {| - anydata...; -|}; - -type AnydataRecord11 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord12 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type AnydataRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type CustomRecord1 record { - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -}; - -type CustomRecord2 record {| - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -|}; - -type CustomRecord3 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -|}; - -type CustomRecord4 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -}; - -type CustomRecord5 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string defaultableField = ""; - string? nillableField = (); -}; - -type CustomRecord6 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type CustomRecord7 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type CustomRecord8 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type CustomRecord9 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string...; -|}; - -type CustomRecord10 record {| - string...; -|}; - -type CustomRecord11 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord12 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord15 record {| - string '1; - string '2; -|}; - -type CustomRecord16 record {| - string '1; - string '2; - string '3; - string '4; -|}; - -type CustomRecord17 record { - string '1; - string '2; -}; - -type CustomRecord18 record { - string '1; - string '2; - string '3; - string '4; +type CustomRecord18 record { + string '1; + string '2; + string '3; + string '4; }; type CustomRecord19 record { @@ -1022,1039 +88,131 @@ type CustomRecord19 record { string '2; string '3 = ""; string '4 = ""; -}; - -type CustomRecord20 record { - string '1; -}; - -type CustomRecord21 record {| - string '1; - json...; -|}; - -type CustomRecord22 record {| - string '1; - string...; -|}; - -type CustomRecord23 record {| - string '1; - string a = ""; - string...; -|}; - -type CustomRecord24 record {| - string '1; - string '2 = ""; - string...; -|}; - -type CustomRecord25 record {| - int '1; - string...; -|}; - -type CustomRecord26 record {| - string '1; - int...; -|}; - -type CustomRecord27 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata a1; - json j1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord28 record { - string '1; -}; - -type CustomRecord29 record { - int '1; -}; - -type CustomRecord30 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord31 record {| - string '1; - string '6; -|}; - -type CustomRecord32 record {| - int '1; -|}; - -type CustomRecord33 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord34 record { - string '1; - string '6; - string '5 = ""; -}; - -type CustomRecord35 record { - string '1; - string '6; - string '9 = ""; -}; - -type CustomRecord36 record {| - string '1; - string '6; - string '9 = ""; -|}; - -type CustomRecord37 record {| - string '1; - string '6; - string '5 = ""; -|}; - -type CustomRecord38 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - string ...; -|}; - -type CustomRecord39 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - json ...; -|}; - -type CustomRecord40 record {| - string '5; - string '6; - json ...; -|}; - -type CustomRecord41 record {| - json ...; -|}; - -type CustomRecord42 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -|}; - -type CustomRecord43 record { - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -}; - -type CustomRecord44 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; - string ...; -|}; - -type CustomRecord45 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -|}; - -type CustomRecord46 record { - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -}; - -type CustomRecord47 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; - string ...; -|}; - -type CustomRecord48 record { - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -}; - -type CustomRecord49 record {| - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -|}; - -type CustomRecord50 record { - int H1; - float H4; -}; - -type CustomRecord51 record {| - int H1; - float H4; -|}; - -type CustomRecord52 record {| - string H1; - string H4; - string ...; -|}; - -type CustomRecord53 record {| - int H1; - float H4; - decimal ...; -|}; - -type CustomRecord54 record {| - string H1 = ""; - string H4; - string '1; -|}; - -type CustomRecord55 record {| - string H1 = ""; - string H4 = ""; - int '1 = 10; -|}; - -type CustomRecord56 record { - string H1 = ""; - string H4 = ""; - anydata '1 = 10; -}; - -type BooleanTuple1 [boolean, boolean, boolean, boolean]; - -type BooleanTuple2 [boolean, boolean]; - -type BooleanTuple3 [boolean, boolean...]; - -type BooleanTuple4 [boolean...]; - -type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; - -type NillableBooleanTuple6 [boolean?, boolean?]; - -type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; - -type NillableBooleanTuple8 [boolean?...]; - -type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; - -type NilTuple1 [(), (), ()]; - -type NilTuple2 [(), ()]; - -type NilTuple3 [(), ()...]; - -type NilTuple4 [()...]; - -type IntegerTuple1 [int, int, int, int, int, int]; - -type IntegerTuple2 [int, int]; - -type IntegerTuple3 [int, int...]; - -type IntegerTuple4 [int...]; - -type FloatTuple1 [float, float, float, float, float, float, float]; - -type FloatTuple2 [float, float]; - -type FloatTuple3 [float, float...]; - -type FloatTuple4 [float...]; - -type DecimalTuple1 [decimal, decimal, decimal, decimal]; - -type DecimalTuple2 [decimal, decimal]; - -type DecimalTuple3 [decimal, decimal...]; - -type DecimalTuple4 [decimal...]; - -type StringTuple1 [string, string, string, string]; - -type StringTuple2 [string, string]; - -type StringTuple3 [string, string...]; - -type StringTuple4 [string...]; - -type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata]; - -type AnydataTuple2 [anydata, anydata]; - -type AnydataTuple3 [anydata, anydata...]; - -type AnydataTuple4 [anydata...]; - -type JsonTuple1 [json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json]; - -type JsonTuple2 [json, json]; - -type JsonTuple3 [json, json...]; - -type JsonTuple4 [json...]; - -type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; - -type CustomTuple4 [string...]; - -type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; - -type CustomTuple6 [anydata...]; - -type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; - -type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; - -type IntegerArray1 int[]; - -type IntegerArray2 int[2]; - -type IntegerArray3 int[]; - -type IntegerArray4 int[2]; - -type IntegerArray5 int[3]; - -type IntegerArray6 int[4]; - -type StringArray string[]; - -type NillableStringArray string?[]; - -type NillableIntOrUnionStringArray (int|string?)[]; - -type StringArray1 string[]; - -type StringArray2 string[2]; - -type StringArray3 string[]; - -type StringArray4 string[2]; - -type StringArray5 string[3]; - -type StringArray6 string[4]; - -type FloatArray1 float[]; - -type FloatArray2 float[2]; - -type FloatArray3 float[]; - -type FloatArray4 float[2]; - -type FloatArray5 float[3]; - -type FloatArray6 float[4]; - -type DecimalArray1 decimal[]; - -type DecimalArray2 decimal[2]; - -type DecimalArray3 decimal[]; - -type DecimalArray4 decimal[2]; - -type DecimalArray5 decimal[3]; - -type DecimalArray6 decimal[4]; - -type BooleanArray boolean[]; - -type NillableBooleanArray boolean?[]; - -type NillableIntOrUnionBooleanArray (int|boolean?)[]; - -type BooleanArray2 boolean[2]; - -type BooleanArray3 boolean[3]; - -type BooleanArray4 boolean[]; - -type BooleanArray5 boolean[2]; - -type BooleanArray6 boolean[4]; - -type NilArray1 ()[]; - -type NilArray2 ()[2]; - -type NilArray3 ()[]; - -type NilArray4 ()[2]; - -type NilArray5 ()[3]; - -type NilArray6 ()[4]; - -type JsonArray1 json[]; - -type JsonArray2 json[2]; - -type JsonArray3 json[]; - -type JsonArray4 json[2]; - -type JsonArray5 json[3]; - -type JsonArray6 json[4]; - -type AnydataArray1 anydata[]; - -type AnydataArray2 anydata[2]; - -type AnydataArray3 anydata[]; - -type AnydataArray4 anydata[2]; - -type AnydataArray5 anydata[3]; - -type AnydataArray6 anydata[4]; - -type CustomArray1 CustomTuple2[]; - -type CustomArray2 CustomTuple2[2]; - -type CustomArray3 CustomTuple2[]; - -type CustomArray4 CustomTuple2[2]; - -type CustomArray5 CustomTuple2[3]; - -type CustomArray6 CustomTuple2[4]; - -type IntegerMap map; - -type StringMap map; - -type NillableIntUnionStringMap map; - -type IntUnionStringMap map; - -type DecimalMap map; - -type FloatMap map; - -type BooleanMap map; - -type NillableBooleanMap map; - -type NillableIntUnionBooleanMap map; - -type IntUnionBooleanMap map; - -type NilMap map<()>; - -type JsonMap map; - -type AnydataMap map; - -type CustomMap map; - -type BooleanRecord1Array BooleanRecord1[]; - -type ClosedBooleanRecord1Array BooleanRecord1[3]; - -type BooleanRecord2Array BooleanRecord2[]; - -type ClosedBooleanRecord2Array BooleanRecord2[3]; - -type BooleanRecord3Array BooleanRecord3[]; - -type ClosedBooleanRecord3Array BooleanRecord3[3]; - -type BooleanRecord4Array BooleanRecord4[]; - -type ClosedBooleanRecord4Array BooleanRecord4[3]; - -type BooleanRecord5Array BooleanRecord5[]; - -type ClosedBooleanRecord5Array BooleanRecord5[3]; - -type BooleanRecord6Array BooleanRecord6[]; - -type ClosedBooleanRecord6Array BooleanRecord6[3]; - -type BooleanRecord7Array BooleanRecord7[]; - -type ClosedBooleanRecord7Array BooleanRecord7[3]; - -type BooleanRecord8Array BooleanRecord8[]; - -type ClosedBooleanRecord8Array BooleanRecord8[3]; - -type BooleanRecord9Array BooleanRecord9[]; - -type ClosedBooleanRecord9Array BooleanRecord9[3]; - -type BooleanRecord10Array BooleanRecord10[]; - -type ClosedBooleanRecord10Array BooleanRecord10[3]; - -type BooleanRecord11Array BooleanRecord11[]; - -type ClosedBooleanRecord11Array BooleanRecord11[3]; - -type BooleanRecord12Array BooleanRecord12[]; - -type ClosedBooleanRecord12Array BooleanRecord12[3]; - -type BooleanRecord13Array BooleanRecord13[]; - -type ClosedBooleanRecord13Array BooleanRecord13[3]; - -type BooleanRecord14Array BooleanRecord14[]; - -type ClosedBooleanRecord14Array BooleanRecord14[3]; - -type BooleanRecord15Array BooleanRecord15[]; - -type ClosedBooleanRecord15Array BooleanRecord15[3]; - -type BooleanRecord16Array BooleanRecord16[]; - -type ClosedBooleanRecord16Array BooleanRecord16[3]; - -type BooleanRecord17Array BooleanRecord17[]; - -type ClosedBooleanRecord17Array BooleanRecord17[3]; - -type BooleanRecord18Array BooleanRecord18[]; - -type ClosedBooleanRecord18Array BooleanRecord18[3]; - -type NilRecord1Array NilRecord1[]; - -type ClosedNilRecord1Array NilRecord1[3]; - -type NilRecord2Array NilRecord2[]; - -type ClosedNilRecord2Array NilRecord2[3]; - -type NilRecord3Array NilRecord3[]; - -type ClosedNilRecord3Array NilRecord3[3]; - -type NilRecord4Array NilRecord4[]; - -type ClosedNilRecord4Array NilRecord4[3]; - -type NilRecord5Array NilRecord5[]; - -type ClosedNilRecord5Array NilRecord5[3]; - -type NilRecord6Array NilRecord6[]; - -type ClosedNilRecord6Array NilRecord6[3]; - -type NilRecord7Array NilRecord7[]; - -type ClosedNilRecord7Array NilRecord7[3]; - -type NilRecord8Array NilRecord8[]; - -type ClosedNilRecord8Array NilRecord8[3]; - -type NilRecord9Array NilRecord9[]; - -type ClosedNilRecord9Array NilRecord9[3]; - -type NilRecord10Array NilRecord10[]; - -type ClosedNilRecord10Array NilRecord10[3]; - -type NilRecord11Array NilRecord11[]; - -type ClosedNilRecord11Array NilRecord11[3]; - -type NilRecord12Array NilRecord12[]; - -type ClosedNilRecord12Array NilRecord12[3]; - -type NilRecord13Array NilRecord13[]; - -type ClosedNilRecord13Array NilRecord13[3]; - -type NilRecord14Array NilRecord14[]; - -type ClosedNilRecord14Array NilRecord14[3]; - -type IntegerRecord1Array IntegerRecord1[]; - -type ClosedIntegerRecord1Array IntegerRecord1[3]; - -type IntegerRecord2Array IntegerRecord2[]; - -type ClosedIntegerRecord2Array IntegerRecord2[3]; - -type IntegerRecord3Array IntegerRecord3[]; - -type ClosedIntegerRecord3Array IntegerRecord3[3]; - -type IntegerRecord4Array IntegerRecord4[]; - -type ClosedIntegerRecord4Array IntegerRecord4[3]; - -type IntegerRecord5Array IntegerRecord5[]; - -type ClosedIntegerRecord5Array IntegerRecord5[3]; - -type IntegerRecord6Array IntegerRecord6[]; - -type ClosedIntegerRecord6Array IntegerRecord6[3]; - -type IntegerRecord7Array IntegerRecord7[]; - -type ClosedIntegerRecord7Array IntegerRecord7[3]; - -type IntegerRecord8Array IntegerRecord8[]; - -type ClosedIntegerRecord8Array IntegerRecord8[3]; - -type IntegerRecord9Array IntegerRecord9[]; - -type ClosedIntegerRecord9Array IntegerRecord9[3]; - -type IntegerRecord10Array IntegerRecord10[]; - -type ClosedIntegerRecord10Array IntegerRecord10[3]; - -type IntegerRecord11Array IntegerRecord11[]; - -type ClosedIntegerRecord11Array IntegerRecord11[3]; - -type IntegerRecord12Array IntegerRecord12[]; - -type ClosedIntegerRecord12Array IntegerRecord12[3]; - -type IntegerRecord13Array IntegerRecord13[]; - -type ClosedIntegerRecord13Array IntegerRecord13[3]; - -type IntegerRecord14Array IntegerRecord14[]; - -type ClosedIntegerRecord14Array IntegerRecord14[3]; - -type FloatRecord1Array FloatRecord1[]; - -type ClosedFloatRecord1Array FloatRecord1[3]; - -type FloatRecord2Array FloatRecord2[]; - -type ClosedFloatRecord2Array FloatRecord2[3]; - -type FloatRecord3Array FloatRecord3[]; - -type ClosedFloatRecord3Array FloatRecord3[3]; - -type FloatRecord4Array FloatRecord4[]; - -type ClosedFloatRecord4Array FloatRecord4[3]; - -type FloatRecord5Array FloatRecord5[]; - -type ClosedFloatRecord5Array FloatRecord5[3]; - -type FloatRecord6Array FloatRecord6[]; - -type ClosedFloatRecord6Array FloatRecord6[3]; - -type FloatRecord7Array FloatRecord7[]; - -type ClosedFloatRecord7Array FloatRecord7[3]; - -type FloatRecord8Array FloatRecord8[]; - -type ClosedFloatRecord8Array FloatRecord8[3]; - -type FloatRecord9Array FloatRecord9[]; - -type ClosedFloatRecord9Array FloatRecord9[3]; - -type FloatRecord10Array FloatRecord10[]; - -type ClosedFloatRecord10Array FloatRecord10[3]; - -type FloatRecord11Array FloatRecord11[]; - -type ClosedFloatRecord11Array FloatRecord11[3]; - -type FloatRecord12Array FloatRecord12[]; - -type ClosedFloatRecord12Array FloatRecord12[3]; - -type FloatRecord13Array FloatRecord13[]; - -type ClosedFloatRecord13Array FloatRecord13[3]; - -type FloatRecord14Array FloatRecord14[]; - -type ClosedFloatRecord14Array FloatRecord14[3]; - -type DecimalRecord1Array DecimalRecord1[]; - -type ClosedDecimalRecord1Array DecimalRecord1[3]; - -type DecimalRecord2Array DecimalRecord2[]; - -type ClosedDecimalRecord2Array DecimalRecord2[3]; - -type DecimalRecord3Array DecimalRecord3[]; - -type ClosedDecimalRecord3Array DecimalRecord3[3]; - -type DecimalRecord4Array DecimalRecord4[]; - -type ClosedDecimalRecord4Array DecimalRecord4[3]; - -type DecimalRecord5Array DecimalRecord5[]; - -type ClosedDecimalRecord5Array DecimalRecord5[3]; - -type DecimalRecord6Array DecimalRecord6[]; - -type ClosedDecimalRecord6Array DecimalRecord6[3]; - -type DecimalRecord7Array DecimalRecord7[]; - -type ClosedDecimalRecord7Array DecimalRecord7[3]; - -type DecimalRecord8Array DecimalRecord8[]; - -type ClosedDecimalRecord8Array DecimalRecord8[3]; - -type DecimalRecord9Array DecimalRecord9[]; - -type ClosedDecimalRecord9Array DecimalRecord9[3]; - -type DecimalRecord10Array DecimalRecord10[]; - -type ClosedDecimalRecord10Array DecimalRecord10[3]; - -type DecimalRecord11Array DecimalRecord11[]; - -type ClosedDecimalRecord11Array DecimalRecord11[3]; - -type DecimalRecord12Array DecimalRecord12[]; - -type ClosedDecimalRecord12Array DecimalRecord12[3]; - -type DecimalRecord13Array DecimalRecord13[]; - -type ClosedDecimalRecord13Array DecimalRecord13[3]; - -type DecimalRecord14Array DecimalRecord14[]; - -type ClosedDecimalRecord14Array DecimalRecord14[3]; - -type StringRecord1Array StringRecord1[]; - -type ClosedStringRecord1Array StringRecord1[3]; - -type StringRecord2Array StringRecord2[]; - -type ClosedStringRecord2Array StringRecord2[3]; - -type StringRecord3Array StringRecord3[]; - -type ClosedStringRecord3Array StringRecord3[3]; - -type StringRecord4Array StringRecord4[]; - -type ClosedStringRecord4Array StringRecord4[3]; - -type StringRecord5Array StringRecord5[]; - -type ClosedStringRecord5Array StringRecord5[3]; - -type StringRecord6Array StringRecord6[]; - -type ClosedStringRecord6Array StringRecord6[3]; - -type StringRecord7Array StringRecord7[]; - -type ClosedStringRecord7Array StringRecord7[3]; - -type StringRecord8Array StringRecord8[]; - -type ClosedStringRecord8Array StringRecord8[3]; - -type StringRecord9Array StringRecord9[]; - -type ClosedStringRecord9Array StringRecord9[3]; - -type StringRecord10Array StringRecord10[]; - -type ClosedStringRecord10Array StringRecord10[3]; - -type StringRecord11Array StringRecord11[]; - -type ClosedStringRecord11Array StringRecord11[3]; - -type StringRecord12Array StringRecord12[]; - -type ClosedStringRecord12Array StringRecord12[3]; - -type StringRecord13Array StringRecord13[]; - -type ClosedStringRecord13Array StringRecord13[3]; - -type StringRecord14Array StringRecord14[]; - -type ClosedStringRecord14Array StringRecord14[3]; - -type StringRecord15Array StringRecord15[]; - -type StringRecord16Array StringRecord16[]; - -type StringRecord17Array StringRecord17[]; - -type StringRecord18Array StringRecord18[]; - -type StringRecord19Array StringRecord19[]; - -type StringRecord20Array StringRecord20[]; - -type StringRecord21Array StringRecord21[]; - -type StringRecord22Array StringRecord22[]; - -type StringRecord23Array StringRecord23[]; - -type JsonRecord1Array JsonRecord1[]; - -type ClosedJsonRecord1Array JsonRecord1[3]; - -type JsonRecord2Array JsonRecord2[]; - -type ClosedJsonRecord2Array JsonRecord2[3]; - -type JsonRecord3Array JsonRecord3[]; - -type ClosedJsonRecord3Array JsonRecord3[3]; - -type JsonRecord4Array JsonRecord4[]; - -type ClosedJsonRecord4Array JsonRecord4[3]; - -type JsonRecord5Array JsonRecord5[]; - -type ClosedJsonRecord5Array JsonRecord5[3]; - -type JsonRecord6Array JsonRecord6[]; - -type ClosedJsonRecord6Array JsonRecord6[3]; - -type JsonRecord7Array JsonRecord7[]; - -type ClosedJsonRecord7Array JsonRecord7[3]; - -type JsonRecord8Array JsonRecord8[]; - -type ClosedJsonRecord8Array JsonRecord8[3]; - -type JsonRecord9Array JsonRecord9[]; - -type ClosedJsonRecord9Array JsonRecord9[3]; - -type JsonRecord10Array JsonRecord10[]; - -type ClosedJsonRecord10Array JsonRecord10[3]; - -type JsonRecord11Array JsonRecord11[]; - -type ClosedJsonRecord11Array JsonRecord11[3]; - -type JsonRecord12Array JsonRecord12[]; - -type ClosedJsonRecord12Array JsonRecord12[3]; - -type JsonRecord13Array JsonRecord13[]; - -type ClosedJsonRecord13Array JsonRecord13[3]; - -type JsonRecord14Array JsonRecord14[]; - -type ClosedJsonRecord14Array JsonRecord14[3]; - -type AnydataRecord1Array AnydataRecord1[]; - -type ClosedAnydataRecord1Array AnydataRecord1[3]; - -type AnydataRecord2Array AnydataRecord2[]; - -type ClosedAnydataRecord2Array AnydataRecord2[3]; - -type AnydataRecord3Array AnydataRecord3[]; +}; -type ClosedAnydataRecord3Array AnydataRecord3[3]; +type CustomRecord20 record { + string '1; +}; -type AnydataRecord4Array AnydataRecord4[]; +type CustomRecord21 record {| + string '1; + json...; +|}; -type ClosedAnydataRecord4Array AnydataRecord4[3]; +type CustomRecord22 record {| + string '1; + string...; +|}; -type AnydataRecord5Array AnydataRecord5[]; +type CustomRecord23 record {| + string '1; + string a = ""; + string...; +|}; -type ClosedAnydataRecord5Array AnydataRecord5[3]; +type CustomRecord24 record {| + string '1; + string '2 = ""; + string...; +|}; -type AnydataRecord6Array AnydataRecord6[]; +type CustomRecord25 record {| + int '1; + string...; +|}; -type ClosedAnydataRecord6Array AnydataRecord6[3]; +type CustomRecord26 record {| + string '1; + int...; +|}; -type AnydataRecord7Array AnydataRecord7[]; +type BooleanTuple4 [boolean...]; -type ClosedAnydataRecord7Array AnydataRecord7[3]; +type NilTuple3 [(), ()...]; -type AnydataRecord8Array AnydataRecord8[]; +type IntegerTuple3 [int, int...]; -type ClosedAnydataRecord8Array AnydataRecord8[3]; +type IntegerTuple4 [int...]; -type AnydataRecord9Array AnydataRecord9[]; +type DecimalTuple4 [decimal...]; -type ClosedAnydataRecord9Array AnydataRecord9[3]; +type StringTuple1 [string, string, string, string]; -type AnydataRecord10Array AnydataRecord10[]; +type StringTuple2 [string, string]; -type ClosedAnydataRecord10Array AnydataRecord10[3]; +type StringTuple3 [string, string...]; -type AnydataRecord11Array AnydataRecord11[]; +type StringTuple4 [string...]; -type ClosedAnydataRecord11Array AnydataRecord11[3]; +type AnydataTuple3 [anydata, anydata...]; -type AnydataRecord12Array AnydataRecord12[]; +type JsonTuple3 [json, json...]; -type ClosedAnydataRecord12Array AnydataRecord12[3]; +type IntegerArray1 int[]; -type AnydataRecord13Array AnydataRecord13[]; +type IntegerArray2 int[2]; -type ClosedAnydataRecord13Array AnydataRecord13[3]; +type IntegerArray3 int[]; -type AnydataRecord14Array AnydataRecord14[]; +type IntegerArray4 int[2]; -type ClosedAnydataRecord14Array AnydataRecord14[3]; +type IntegerArray5 int[3]; -type CustomRecord1Array CustomRecord1[]; +type IntegerArray6 int[4]; -type ClosedCustomRecord1Array CustomRecord1[3]; +type StringArray string[]; -type CustomRecord2Array CustomRecord2[]; +type NillableStringArray string?[]; -type ClosedCustomRecord2Array CustomRecord2[3]; +type NillableIntOrUnionStringArray (int|string?)[]; -type CustomRecord3Array CustomRecord3[]; +type StringArray1 string[]; -type ClosedCustomRecord3Array CustomRecord3[3]; +type StringArray2 string[2]; -type CustomRecord4Array CustomRecord4[]; +type DecimalArray1 decimal[]; -type ClosedCustomRecord4Array CustomRecord4[3]; +type JsonArray1 json[]; -type CustomRecord5Array CustomRecord5[]; +type AnydataArray1 anydata[]; -type ClosedCustomRecord5Array CustomRecord5[3]; +type IntegerMap map; -type CustomRecord6Array CustomRecord6[]; +type StringMap map; -type ClosedCustomRecord6Array CustomRecord6[3]; +type NillableIntUnionStringMap map; -type CustomRecord7Array CustomRecord7[]; +type IntUnionStringMap map; -type ClosedCustomRecord7Array CustomRecord7[3]; +type DecimalMap map; -type CustomRecord8Array CustomRecord8[]; +type BooleanMap map; -type ClosedCustomRecord8Array CustomRecord8[3]; +type NilMap map<()>; -type CustomRecord9Array CustomRecord9[]; +type JsonMap map; -type ClosedCustomRecord9Array CustomRecord9[3]; +type AnydataMap map; -type CustomRecord10Array CustomRecord10[]; +type CustomMap map; -type ClosedCustomRecord10Array CustomRecord10[3]; +type StringRecord1Array StringRecord1[]; -type CustomRecord11Array CustomRecord11[]; +type StringRecord2Array StringRecord2[]; -type ClosedCustomRecord11Array CustomRecord11[3]; +type StringRecord9Array StringRecord9[]; -type CustomRecord12Array CustomRecord12[]; +type StringRecord10Array StringRecord10[]; -type ClosedCustomRecord12Array CustomRecord12[3]; +type StringRecord19Array StringRecord19[]; -type CustomRecord13Array CustomRecord13[]; +type StringRecord20Array StringRecord20[]; -type ClosedCustomRecord13Array CustomRecord13[3]; +type StringRecord21Array StringRecord21[]; -type CustomRecord14Array CustomRecord14[]; +type StringRecord22Array StringRecord22[]; -type ClosedCustomRecord14Array CustomRecord14[3]; +type StringRecord23Array StringRecord23[]; type CustomRecord15Array CustomRecord15[]; @@ -2080,227 +238,39 @@ type CustomRecord25Array CustomRecord25[]; type CustomRecord26Array CustomRecord26[]; -type CustomRecord27Array CustomRecord27[]; -type CustomRecord28Array CustomRecord28[]; -type CustomRecord29Array CustomRecord29[]; -type CustomRecord30Array CustomRecord30[]; -type CustomRecord31Array CustomRecord31[]; -type CustomRecord32Array CustomRecord32[]; -type CustomRecord33Array CustomRecord33[]; -type CustomRecord34Array CustomRecord34[]; -type CustomRecord35Array CustomRecord35[]; -type CustomRecord36Array CustomRecord36[]; -type CustomRecord37Array CustomRecord37[]; -type CustomRecord38Array CustomRecord38[]; -type CustomRecord39Array CustomRecord39[]; -type CustomRecord40Array CustomRecord40[]; -type CustomRecord41Array CustomRecord41[]; -type CustomRecord42Array CustomRecord42[]; -type CustomRecord43Array CustomRecord43[]; -type CustomRecord44Array CustomRecord44[]; -type CustomRecord45Array CustomRecord45[]; -type CustomRecord46Array CustomRecord46[]; -type CustomRecord47Array CustomRecord47[]; -type CustomRecord48Array CustomRecord48[]; -type CustomRecord49Array CustomRecord49[]; -type CustomRecord50Array CustomRecord50[]; -type CustomRecord51Array CustomRecord51[]; -type CustomRecord52Array CustomRecord52[]; -type CustomRecord53Array CustomRecord53[]; -type CustomRecord54Array CustomRecord54[]; -type CustomRecord55Array CustomRecord55[]; -type CustomRecord56Array CustomRecord56[]; - -type BooleanTuple1Array BooleanTuple1[]; - -type ClosedBooleanTuple1Array BooleanTuple1[3]; - -type BooleanTuple2Array BooleanTuple2[]; - -type ClosedBooleanTuple2Array BooleanTuple2[3]; - -type BooleanTuple3Array BooleanTuple3[]; - -type ClosedBooleanTuple3Array BooleanTuple3[3]; - type BooleanTuple4Array BooleanTuple4[]; -type ClosedBooleanTuple4Array BooleanTuple4[3]; - -type NillableBooleanTuple5Array NillableBooleanTuple5[]; - -type NillableBooleanTuple6Array NillableBooleanTuple6[]; - -type NillableBooleanTuple7Array NillableBooleanTuple7[]; - -type NillableBooleanTuple8Array NillableBooleanTuple8[]; - -type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; - -type NilTuple1Array NilTuple1[]; - -type ClosedNilTuple1Array NilTuple1[3]; - -type NilTuple2Array NilTuple2[]; - -type ClosedNilTuple2Array NilTuple2[3]; - type NilTuple3Array NilTuple3[]; - -type ClosedNilTuple3Array NilTuple3[3]; - -type NilTuple4Array NilTuple4[]; - -type ClosedNilTuple4Array NilTuple4[3]; - -type IntegerTuple1Array IntegerTuple1[]; - -type ClosedIntegerTuple1Array IntegerTuple1[3]; - -type IntegerTuple2Array IntegerTuple2[]; - -type ClosedIntegerTuple2Array IntegerTuple2[3]; - type IntegerTuple3Array IntegerTuple3[]; -type ClosedIntegerTuple3Array IntegerTuple3[3]; - type IntegerTuple4Array IntegerTuple4[]; -type ClosedIntegerTuple4Array IntegerTuple4[3]; - -type FloatTuple1Array FloatTuple1[]; - -type ClosedFloatTuple1Array FloatTuple1[3]; - -type FloatTuple2Array FloatTuple2[]; - -type ClosedFloatTuple2Array FloatTuple2[3]; - -type FloatTuple3Array FloatTuple3[]; - -type ClosedFloatTuple3Array FloatTuple3[3]; - -type FloatTuple4Array FloatTuple4[]; - -type ClosedFloatTuple4Array FloatTuple4[3]; - -type DecimalTuple1Array DecimalTuple1[]; - -type ClosedDecimalTuple1Array DecimalTuple1[3]; - -type DecimalTuple2Array DecimalTuple2[]; - -type ClosedDecimalTuple2Array DecimalTuple2[3]; - -type DecimalTuple3Array DecimalTuple3[]; - -type ClosedDecimalTuple3Array DecimalTuple3[3]; - type DecimalTuple4Array DecimalTuple4[]; -type ClosedDecimalTuple4Array DecimalTuple4[3]; - type StringTuple1Array StringTuple1[]; -type ClosedStringTuple1Array StringTuple1[3]; - type StringTuple2Array StringTuple2[]; -type ClosedStringTuple2Array StringTuple2[3]; - type StringTuple3Array StringTuple3[]; -type ClosedStringTuple3Array StringTuple3[3]; - type StringTuple4Array StringTuple4[]; -type ClosedStringTuple4Array StringTuple4[3]; - -type AnydataTuple1Array AnydataTuple1[]; - -type ClosedAnydataTuple1Array AnydataTuple1[3]; - -type AnydataTuple2Array AnydataTuple2[]; - -type ClosedAnydataTuple2Array AnydataTuple2[3]; - type AnydataTuple3Array AnydataTuple3[]; -type ClosedAnydataTuple3Array AnydataTuple3[3]; - -type AnydataTuple4Array AnydataTuple4[]; - -type ClosedAnydataTuple4Array AnydataTuple4[3]; - -type JsonTuple1Array JsonTuple1[]; - -type ClosedJsonTuple1Array JsonTuple1[3]; - -type JsonTuple2Array JsonTuple2[]; - -type ClosedJsonTuple2Array JsonTuple2[3]; - type JsonTuple3Array JsonTuple3[]; -type ClosedJsonTuple3Array JsonTuple3[3]; - -type JsonTuple4Array JsonTuple4[]; - -type ClosedJsonTuple4Array JsonTuple4[3]; - -type CustomTuple1Array CustomTuple1[]; - -type ClosedCustomTuple1Array CustomTuple1[3]; - -type CustomTuple2Array CustomTuple2[]; - -type ClosedCustomTuple2Array CustomTuple2[3]; - -type CustomTuple3Array CustomTuple3[]; - -type ClosedCustomTuple3Array CustomTuple3[3]; - -type CustomTuple4Array CustomTuple4[]; - -type ClosedCustomTuple4Array CustomTuple4[3]; - -type CustomTuple5Array CustomTuple5[]; - -type ClosedCustomTuple5Array CustomTuple5[3]; - -type CustomTuple6Array CustomTuple6[]; - -type CustomTuple7Array CustomTuple7[]; - -type CustomTuple8Array CustomTuple8[]; - -type ClosedCustomTuple6Array CustomTuple6[3]; - type IntegerArray1Array IntegerArray1[]; -type ClosedIntegerArray1Array IntegerArray1[3]; - type IntegerArray2Array IntegerArray2[]; -type ClosedIntegerArray2Array IntegerArray2[3]; - type IntegerArray3Array IntegerArray3[]; -type ClosedIntegerArray3Array IntegerArray3[3]; - type IntegerArray4Array IntegerArray4[]; -type ClosedIntegerArray4Array IntegerArray4[3]; - type IntegerArray5Array IntegerArray5[]; -type ClosedIntegerArray5Array IntegerArray5[3]; - type IntegerArray6Array IntegerArray5[]; -type ClosedIntegerArray6Array IntegerArray5[3]; - type StringArray1Array StringArray1[]; type StringArrayArray StringArray[]; @@ -2309,243 +279,29 @@ type NillableStringArrayArray NillableStringArray[]; type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; -type ClosedStringArray1Array StringArray1[3]; - type StringArray2Array StringArray2[]; - -type ClosedStringArray2Array StringArray2[3]; - -type StringArray3Array StringArray3[]; - -type ClosedStringArray3Array StringArray3[3]; - -type StringArray4Array StringArray4[]; - -type ClosedStringArray4Array StringArray4[3]; - -type StringArray5Array StringArray5[]; - -type ClosedStringArray5Array StringArray5[3]; - -type StringArray6Array StringArray5[]; - -type ClosedStringArray6Array StringArray5[3]; - -type FloatArray1Array FloatArray1[]; - -type ClosedFloatArray1Array FloatArray1[3]; - -type FloatArray2Array FloatArray2[]; - -type ClosedFloatArray2Array FloatArray2[3]; - -type FloatArray3Array FloatArray3[]; - -type ClosedFloatArray3Array FloatArray3[3]; - -type FloatArray4Array FloatArray4[]; - -type ClosedFloatArray4Array FloatArray4[3]; - -type FloatArray5Array FloatArray5[]; - -type ClosedFloatArray5Array FloatArray5[3]; - -type FloatArray6Array FloatArray5[]; - -type ClosedFloatArray6Array FloatArray5[3]; - type DecimalArray1Array DecimalArray1[]; -type ClosedDecimalArray1Array DecimalArray1[3]; - -type DecimalArray2Array DecimalArray2[]; - -type ClosedDecimalArray2Array DecimalArray2[3]; - -type DecimalArray3Array DecimalArray3[]; - -type ClosedDecimalArray3Array DecimalArray3[3]; - -type DecimalArray4Array DecimalArray4[]; - -type ClosedDecimalArray4Array DecimalArray4[3]; - -type DecimalArray5Array DecimalArray5[]; - -type ClosedDecimalArray5Array DecimalArray5[3]; - -type DecimalArray6Array DecimalArray5[]; - -type ClosedDecimalArray6Array DecimalArray5[3]; - -type BooleanArrayArray BooleanArray[]; - -type ClosedBooleanArrayArray BooleanArray[3]; - -type NillableBooleanArrayArray NillableBooleanArray[]; - -type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; - -type BooleanArray2Array BooleanArray2[]; - -type ClosedBooleanArray2Array BooleanArray2[3]; - -type BooleanArray3Array BooleanArray3[]; - -type ClosedBooleanArray3Array BooleanArray3[3]; - -type BooleanArray4Array BooleanArray4[]; - -type ClosedBooleanArray4Array BooleanArray4[3]; - -type BooleanArray5Array BooleanArray5[]; - -type ClosedBooleanArray5Array BooleanArray5[3]; - -type BooleanArray6Array BooleanArray5[]; - -type ClosedBooleanArray6Array BooleanArray5[3]; - -type NilArray1Array NilArray1[]; - -type ClosedNilArray1Array NilArray1[3]; - -type NilArray2Array NilArray2[]; - -type ClosedNilArray2Array NilArray2[3]; - -type NilArray3Array NilArray3[]; - -type ClosedNilArray3Array NilArray3[3]; - -type NilArray4Array NilArray4[]; - -type ClosedNilArray4Array NilArray4[3]; - -type NilArray5Array NilArray5[]; - -type ClosedNilArray5Array NilArray5[3]; - -type NilArray6Array NilArray5[]; - -type ClosedNilArray6Array NilArray5[3]; - type JsonArray1Array JsonArray1[]; -type ClosedJsonArray1Array JsonArray1[3]; - -type JsonArray2Array JsonArray2[]; - -type ClosedJsonArray2Array JsonArray2[3]; - -type JsonArray3Array JsonArray3[]; - -type ClosedJsonArray3Array JsonArray3[3]; - -type JsonArray4Array JsonArray4[]; - -type ClosedJsonArray4Array JsonArray4[3]; - -type JsonArray5Array JsonArray5[]; - -type ClosedJsonArray5Array JsonArray5[3]; - -type JsonArray6Array JsonArray5[]; - -type ClosedJsonArray6Array JsonArray5[3]; - type AnydataArray1Array AnydataArray1[]; -type ClosedAnydataArray1Array AnydataArray1[3]; - -type AnydataArray2Array AnydataArray2[]; - -type ClosedAnydataArray2Array AnydataArray2[3]; - -type AnydataArray3Array AnydataArray3[]; - -type ClosedAnydataArray3Array AnydataArray3[3]; - -type AnydataArray4Array AnydataArray4[]; - -type ClosedAnydataArray4Array AnydataArray4[3]; - -type AnydataArray5Array AnydataArray5[]; - -type ClosedAnydataArray5Array AnydataArray5[3]; - -type AnydataArray6Array AnydataArray5[]; - -type ClosedAnydataArray6Array AnydataArray5[3]; - -type CustomArray1Array CustomArray1[]; - -type ClosedCustomArray1Array CustomArray1[3]; - -type CustomArray2Array CustomArray2[]; - -type ClosedCustomArray2Array CustomArray2[3]; - -type CustomArray3Array CustomArray3[]; - -type ClosedCustomArray3Array CustomArray3[3]; - -type CustomArray4Array CustomArray4[]; - -type ClosedCustomArray4Array CustomArray4[3]; - -type CustomArray5Array CustomArray5[]; - -type ClosedCustomArray5Array CustomArray5[3]; - -type CustomArray6Array CustomArray5[]; - -type ClosedCustomArray6Array CustomArray5[3]; - type IntegerMapArray IntegerMap[]; -type ClosedIntegerMapArray IntegerMap[3]; - type StringMapArray StringMap[]; type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; type IntUnionStringMapArray IntUnionStringMap[]; -type ClosedStringMapArray StringMap[3]; - type DecimalMapArray DecimalMap[]; -type ClosedDecimalMapArray DecimalMap[3]; - -type FloatMapArray FloatMap[]; - -type ClosedFloatMapArray FloatMap[3]; - type BooleanMapArray BooleanMap[]; -type NillableBooleanMapArray NillableBooleanMap[]; - -type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; - -type IntUnionBooleanMapArray IntUnionBooleanMap[]; - -type ClosedBooleanMapArray BooleanMap[3]; - type NilMapArray NilMap[]; -type ClosedNilMapArray NilMap[3]; - type JsonMapArray JsonMap[]; -type ClosedJsonMapArray JsonMap[3]; - type AnydataMapArray AnydataMap[]; -type ClosedAnydataMapArray AnydataMap[3]; - type CustomMapArray CustomMap[]; - -type ClosedCustomMapArray CustomMap[3]; - diff --git a/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal index a9698aa..08845c7 100644 --- a/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal @@ -24,249 +24,8 @@ int? n2 = (); () n3 = null; int i1 = 1; -int i2 = -2; -int i3 = int:MAX_VALUE; -int i4 = int:MIN_VALUE; -int i5 = 0; -2 i6 = 2; -int? i7 = (); -int|string i8 = 100; - -float f1 = 2.234; -float f2 = -3.21f; -float f3 = 0; -float f4 = float:Infinity; -float f5 = -float:Infinity; -float f6 = float:NaN; -2.3f f7 = 2.3; -float? f8 = (); -float|decimal f9 = 1.21; - -decimal d1 = 2.234; -decimal d2 = -3.21d; -decimal d3 = 0; -2.3d d4 = 2.3; -decimal? d5 = (); -decimal|int d6 = 1.21; - -string s1 = "string"; -string s2 = ""; -string:Char s3 = "a"; - map bm1 = {b1, b2}; map bm2 = {b1, b2, b3, n1, n3}; map bm3 = {b1, b2, b3, b4, i1}; map<()> bm4 = {n1, n3}; map bm5 = {b1, b2, b3, b4:true}; - -map m5 = {i1, i2, i3, i4, i5, i6}; -map m6 = {f1, f2, f3, f4, f5, f6, f7}; -map m7 = {d1, d2, d3, d4}; -map m8 = {d1, f1, f9, f10: 1.23}; -map m9 = {s1, s2, s3}; -map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; -map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; - -boolean[] arr1 = [b1, b2]; -boolean?[] arr2 = [b1, b2, b3, n1, n3]; -(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; -()[] arr4 = [n1, n3]; -int[] arr5 = [i1, i2, i3, i4, i5, i6]; -float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; -decimal[] arr7 = [d1, d2, d3, d4]; -(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; -string[] arr9 = [s1, s2, s3]; -anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; - -[boolean, boolean] bt1 = [b1, b2]; -[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; -[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; -[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; -[boolean...] bt5 = [b1, b2]; - -[string, string] st1 = [s1, s2]; -[string, string, string, string] st2 = [s1, s2, s3, s2]; -[string...] st3 = [s1, s2]; -[string, string, string...] st4 = [s1, s2, s3, s2]; - -[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; -[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; -[string?...] st7 = [s1, s2]; -[string...] st8 = []; -[string, string, string] st9 = [s1, s2, s3]; - -[(), ()] tup4 = [n1, n3]; -[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; -[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; -[string, string, string] tup9 = [s1, s2, s3]; -[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, - n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, json] tup11 = - [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, - f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 -]; - -[boolean, boolean...] restTup1 = [b1, b2]; -[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; -[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; -[(), ()...] restTup4 = [n1, n3]; -[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; -[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal...] restTup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; -[string...] restTup9 = [s1, s2, s3]; -[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 -]; - -var booleanRecordArray = [ - {b1, b2, b3, b4}, {b1, b2, b3, b4} -]; - -var booleanRecordArray2 = [ - {},{} -]; - -string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 -true,false,true,false -true,false, true,false -true,false,true,false -`; - -string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 -true,false, true,false,true -true,false, true,false,true`; - -string csvStringWithBooleanValues3 = string `b1,b2,b3 -${" "}${"\t"} -true, false,true -${" "} - TRUE, FALSE,() -${" "} - -true, true,FALSE - -`; - -string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 - true,(), (),false - true,(), null,false - -`; - -string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 - -true,false,true,2 - -true,false,true,3 -`; - -string csvStringWithBooleanValues6 = string `b2,b3 -(),() - -`; - -string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 -${b1},${b2},(),${b4} -`; - -string csvStringData1 = string ` - a, b, c, d, e, f - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData2 = string ` - hello, hello, (), 12, true, 12.34 - // comment - - a, b, c, d, e, f - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData3 = string ` - a, b, c, d, e, f - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData4 = string ` - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData5 = string ` - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData6 = string ` - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData7 = string ` - a@ b@ c@ d@ e@ f - 1@ string@ true@ 2.234@ -3.21@ () - 2@ s,tring@ true@ 2.234@ -3.21@ null - 3@ stri,ng@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; -string csvStringData8 = string ` - a@ b@ c@ d@ e@ f - - - - 1@ stri,ng@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ ()@-3.21 - 3@ string@ true@ 2.234@ -3.21@ null - - 4@ s,tring@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; - -string csvStringData9 = string ` - - 1@ string@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ -3.21@ null - - 3@ string@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ ()@-3.21 - - 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina-tests/parse-record-types-tests/tests/types.bal b/ballerina-tests/parse-record-types-tests/tests/types.bal index b496d60..1d0a8ba 100644 --- a/ballerina-tests/parse-record-types-tests/tests/types.bal +++ b/ballerina-tests/parse-record-types-tests/tests/types.bal @@ -126,1990 +126,145 @@ type BooleanRecord18 record {| int?...; |}; -type NilRecord1 record { - () n1; - () n2; - () n3; -}; - -type NilRecord2 record {| - () n1; - () n2; - () n3; -|}; - -type NilRecord3 record {| - () n1; - () n4; -|}; - -type NilRecord4 record { - () n1; - () n4; -}; - -type NilRecord5 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -}; - -type NilRecord6 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type NilRecord7 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type NilRecord8 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type NilRecord9 record {| - () n1; - () n2; - ()...; -|}; - -type NilRecord10 record {| - ()...; -|}; - -type NilRecord11 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord12 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type NilRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type IntegerRecord1 record { - int i1; - int i2; - int i3; - int? i4; - int? i5; - int i6; - int i7; - int? i8; -}; - -type IntegerRecord2 record {| - int i1; - int? i2; - int i3; - int i4; - int? i5; - int i6; - int i7; - int? i8; -|}; - -type IntegerRecord3 record {| - int i1; - int i4; - int i6; -|}; - -type IntegerRecord4 record { - int i1; - int i4; - int i6; -}; - -type IntegerRecord5 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -}; - -type IntegerRecord6 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -|}; - -type IntegerRecord7 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type IntegerRecord8 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type IntegerRecord9 record {| - int i1; - int i2; - int...; -|}; - -type IntegerRecord10 record {| - int...; -|}; - -type IntegerRecord11 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord12 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type IntegerRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type FloatRecord1 record { - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -}; - -type FloatRecord2 record {| - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -|}; - -type FloatRecord3 record {| - float f1; - float f4; - float f7; -|}; - -type FloatRecord4 record { - float f1; - float f4; - float f7; -}; - -type FloatRecord5 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -}; - -type FloatRecord6 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type FloatRecord7 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type FloatRecord8 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type FloatRecord9 record {| - float f1; - float f2; - float...; -|}; - -type FloatRecord10 record {| - float...; -|}; - -type FloatRecord11 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord12 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type FloatRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type DecimalRecord1 record { - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -}; - -type DecimalRecord2 record {| - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -|}; - -type DecimalRecord3 record {| - decimal d1; - decimal d4; - decimal d7; -|}; - -type DecimalRecord4 record { - decimal d1; - decimal d4; - decimal d7; -}; - -type DecimalRecord5 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -}; - -type DecimalRecord6 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type DecimalRecord7 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type DecimalRecord8 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type DecimalRecord9 record {| - decimal d1; - decimal d2; - decimal...; -|}; - -type DecimalRecord10 record {| - decimal...; -|}; - -type DecimalRecord11 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord12 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type DecimalRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type StringRecord1 record { - string s1; - string s2; - string s3; -}; - -type StringRecord2 record {| - string s1; - string s2; - string s3; -|}; - -type StringRecord3 record {| - string s1; - string s4; -|}; - -type StringRecord4 record { - string s1; - string s4; -}; - -type StringRecord5 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -}; - -type StringRecord6 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type StringRecord7 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type StringRecord8 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type StringRecord9 record {| - string s1; - string s2; - string...; -|}; - -type StringRecord10 record {| - string...; -|}; - -type StringRecord11 record {| - string s1; - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord12 record {| - string d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord15 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord16 record {| - string?...; -|}; - -type StringRecord17 record {| - int...; -|}; - -type StringRecord18 record {| - string b2; - int?...; -|}; - -type StringRecord19 record { - string s1 = ""; - string s2 = ""; -}; - -type StringRecord20 record {| - string s1 = ""; - string s2 = ""; -|}; - -type StringRecord21 record { -}; - -type StringRecord22 record {| - string s1 = ""; - string s2 = ""; - json...; -|}; - -type StringRecord23 record {| - json...; -|}; - -type JsonRecord1 record { - json j1; - json j2; - json j3; -}; - -type JsonRecord2 record {| - json j1; - json j2; - json j3; -|}; - -type JsonRecord3 record {| - json j1; - json j4; -|}; - -type JsonRecord4 record { - json j1; - json j4; -}; - -type JsonRecord5 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -}; - -type JsonRecord6 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -|}; - -type JsonRecord7 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -}; - -type JsonRecord8 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -|}; - -type JsonRecord9 record {| - json j1; - json j2; - json...; -|}; - -type JsonRecord10 record {| - json...; -|}; - -type JsonRecord11 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord12 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type JsonRecord13 record {| - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord14 record {| - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type AnydataRecord1 record { - anydata anydata1; - anydata anydata2; - anydata anydata3; -}; - -type AnydataRecord2 record {| - anydata anydata1; - anydata anydata2; - anydata anydata3; -|}; - -type AnydataRecord3 record {| - anydata anydata1; - anydata anydata4; -|}; - -type AnydataRecord4 record { - anydata anydata1; - anydata anydata4; -}; - -type AnydataRecord5 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -}; - -type AnydataRecord6 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type AnydataRecord7 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type AnydataRecord8 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type AnydataRecord9 record {| - anydata anydata1; - anydata anydata2; - anydata...; -|}; - -type AnydataRecord10 record {| - anydata...; -|}; - -type AnydataRecord11 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord12 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type AnydataRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type CustomRecord1 record { - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -}; - -type CustomRecord2 record {| - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -|}; - -type CustomRecord3 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -|}; - -type CustomRecord4 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -}; - -type CustomRecord5 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string defaultableField = ""; - string? nillableField = (); -}; - -type CustomRecord6 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type CustomRecord7 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type CustomRecord8 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type CustomRecord9 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string...; -|}; - -type CustomRecord10 record {| - string...; -|}; - -type CustomRecord11 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord12 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord15 record {| - string '1; - string '2; -|}; - -type CustomRecord16 record {| - string '1; - string '2; - string '3; - string '4; -|}; - -type CustomRecord17 record { - string '1; - string '2; -}; - -type CustomRecord18 record { - string '1; - string '2; - string '3; - string '4; -}; - -type CustomRecord19 record { - string '1; - string '2; - string '3 = ""; - string '4 = ""; -}; - -type CustomRecord20 record { - string '1; -}; - -type CustomRecord21 record {| - string '1; - json...; -|}; - -type CustomRecord22 record {| - string '1; - string...; -|}; - -type CustomRecord23 record {| - string '1; - string a = ""; - string...; -|}; - -type CustomRecord24 record {| - string '1; - string '2 = ""; - string...; -|}; - -type CustomRecord25 record {| - int '1; - string...; -|}; - -type CustomRecord26 record {| - string '1; - int...; -|}; - -type CustomRecord27 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata a1; - json j1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord28 record { - string '1; -}; - -type CustomRecord29 record { - int '1; -}; - -type CustomRecord30 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord31 record {| - string '1; - string '6; -|}; - -type CustomRecord32 record {| - int '1; -|}; - -type CustomRecord33 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord34 record { - string '1; - string '6; - string '5 = ""; -}; - -type CustomRecord35 record { - string '1; - string '6; - string '9 = ""; -}; - -type CustomRecord36 record {| - string '1; - string '6; - string '9 = ""; -|}; - -type CustomRecord37 record {| - string '1; - string '6; - string '5 = ""; -|}; - -type CustomRecord38 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - string ...; -|}; - -type CustomRecord39 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - json ...; -|}; - -type CustomRecord40 record {| - string '5; - string '6; - json ...; -|}; - -type CustomRecord41 record {| - json ...; -|}; - -type CustomRecord42 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -|}; - -type CustomRecord43 record { - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -}; - -type CustomRecord44 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; - string ...; -|}; - -type CustomRecord45 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -|}; - -type CustomRecord46 record { - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -}; - -type CustomRecord47 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; - string ...; -|}; - -type CustomRecord48 record { - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -}; - -type CustomRecord49 record {| - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -|}; - -type CustomRecord50 record { - int H1; - float H4; -}; - -type CustomRecord51 record {| - int H1; - float H4; -|}; - -type CustomRecord52 record {| - string H1; - string H4; - string ...; -|}; - -type CustomRecord53 record {| - int H1; - float H4; - decimal ...; -|}; - -type CustomRecord54 record {| - string H1 = ""; - string H4; - string '1; -|}; - -type CustomRecord55 record {| - string H1 = ""; - string H4 = ""; - int '1 = 10; -|}; - -type CustomRecord56 record { - string H1 = ""; - string H4 = ""; - anydata '1 = 10; -}; - -type BooleanTuple1 [boolean, boolean, boolean, boolean]; - -type BooleanTuple2 [boolean, boolean]; - -type BooleanTuple3 [boolean, boolean...]; - -type BooleanTuple4 [boolean...]; - -type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; - -type NillableBooleanTuple6 [boolean?, boolean?]; - -type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; - -type NillableBooleanTuple8 [boolean?...]; - -type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; - -type NilTuple1 [(), (), ()]; - -type NilTuple2 [(), ()]; - -type NilTuple3 [(), ()...]; - -type NilTuple4 [()...]; - -type IntegerTuple1 [int, int, int, int, int, int]; - -type IntegerTuple2 [int, int]; - -type IntegerTuple3 [int, int...]; - -type IntegerTuple4 [int...]; - -type FloatTuple1 [float, float, float, float, float, float, float]; - -type FloatTuple2 [float, float]; - -type FloatTuple3 [float, float...]; - -type FloatTuple4 [float...]; - -type DecimalTuple1 [decimal, decimal, decimal, decimal]; - -type DecimalTuple2 [decimal, decimal]; - -type DecimalTuple3 [decimal, decimal...]; - -type DecimalTuple4 [decimal...]; - -type StringTuple1 [string, string, string, string]; - -type StringTuple2 [string, string]; - -type StringTuple3 [string, string...]; - -type StringTuple4 [string...]; - -type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata]; - -type AnydataTuple2 [anydata, anydata]; - -type AnydataTuple3 [anydata, anydata...]; - -type AnydataTuple4 [anydata...]; - -type JsonTuple1 [json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json]; - -type JsonTuple2 [json, json]; - -type JsonTuple3 [json, json...]; - -type JsonTuple4 [json...]; - -type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; - -type CustomTuple4 [string...]; - -type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; - -type CustomTuple6 [anydata...]; - -type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; - -type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; - -type IntegerArray1 int[]; - -type IntegerArray2 int[2]; - -type IntegerArray3 int[]; - -type IntegerArray4 int[2]; - -type IntegerArray5 int[3]; - -type IntegerArray6 int[4]; - -type StringArray string[]; - -type NillableStringArray string?[]; - -type NillableIntOrUnionStringArray (int|string?)[]; - -type StringArray1 string[]; - -type StringArray2 string[2]; - -type StringArray3 string[]; - -type StringArray4 string[2]; - -type StringArray5 string[3]; - -type StringArray6 string[4]; - -type FloatArray1 float[]; - -type FloatArray2 float[2]; - -type FloatArray3 float[]; - -type FloatArray4 float[2]; - -type FloatArray5 float[3]; - -type FloatArray6 float[4]; - -type DecimalArray1 decimal[]; - -type DecimalArray2 decimal[2]; - -type DecimalArray3 decimal[]; - -type DecimalArray4 decimal[2]; - -type DecimalArray5 decimal[3]; - -type DecimalArray6 decimal[4]; - -type BooleanArray boolean[]; - -type NillableBooleanArray boolean?[]; - -type NillableIntOrUnionBooleanArray (int|boolean?)[]; - -type BooleanArray2 boolean[2]; - -type BooleanArray3 boolean[3]; - -type BooleanArray4 boolean[]; - -type BooleanArray5 boolean[2]; - -type BooleanArray6 boolean[4]; - -type NilArray1 ()[]; - -type NilArray2 ()[2]; - -type NilArray3 ()[]; - -type NilArray4 ()[2]; - -type NilArray5 ()[3]; - -type NilArray6 ()[4]; - -type JsonArray1 json[]; - -type JsonArray2 json[2]; - -type JsonArray3 json[]; - -type JsonArray4 json[2]; - -type JsonArray5 json[3]; - -type JsonArray6 json[4]; - -type AnydataArray1 anydata[]; - -type AnydataArray2 anydata[2]; - -type AnydataArray3 anydata[]; - -type AnydataArray4 anydata[2]; - -type AnydataArray5 anydata[3]; - -type AnydataArray6 anydata[4]; - -type CustomArray1 CustomTuple2[]; - -type CustomArray2 CustomTuple2[2]; - -type CustomArray3 CustomTuple2[]; - -type CustomArray4 CustomTuple2[2]; - -type CustomArray5 CustomTuple2[3]; - -type CustomArray6 CustomTuple2[4]; - -type IntegerMap map; - -type StringMap map; - -type NillableIntUnionStringMap map; - -type IntUnionStringMap map; - -type DecimalMap map; - -type FloatMap map; - -type BooleanMap map; - -type NillableBooleanMap map; - -type NillableIntUnionBooleanMap map; - -type IntUnionBooleanMap map; - -type NilMap map<()>; - -type JsonMap map; - -type AnydataMap map; - -type CustomMap map; - -type BooleanRecord1Array BooleanRecord1[]; - -type ClosedBooleanRecord1Array BooleanRecord1[3]; - -type BooleanRecord2Array BooleanRecord2[]; - -type ClosedBooleanRecord2Array BooleanRecord2[3]; - -type BooleanRecord3Array BooleanRecord3[]; - -type ClosedBooleanRecord3Array BooleanRecord3[3]; - -type BooleanRecord4Array BooleanRecord4[]; - -type ClosedBooleanRecord4Array BooleanRecord4[3]; - -type BooleanRecord5Array BooleanRecord5[]; - -type ClosedBooleanRecord5Array BooleanRecord5[3]; - -type BooleanRecord6Array BooleanRecord6[]; - -type ClosedBooleanRecord6Array BooleanRecord6[3]; - -type BooleanRecord7Array BooleanRecord7[]; - -type ClosedBooleanRecord7Array BooleanRecord7[3]; - -type BooleanRecord8Array BooleanRecord8[]; - -type ClosedBooleanRecord8Array BooleanRecord8[3]; - -type BooleanRecord9Array BooleanRecord9[]; - -type ClosedBooleanRecord9Array BooleanRecord9[3]; - -type BooleanRecord10Array BooleanRecord10[]; - -type ClosedBooleanRecord10Array BooleanRecord10[3]; - -type BooleanRecord11Array BooleanRecord11[]; - -type ClosedBooleanRecord11Array BooleanRecord11[3]; - -type BooleanRecord12Array BooleanRecord12[]; - -type ClosedBooleanRecord12Array BooleanRecord12[3]; - -type BooleanRecord13Array BooleanRecord13[]; - -type ClosedBooleanRecord13Array BooleanRecord13[3]; - -type BooleanRecord14Array BooleanRecord14[]; - -type ClosedBooleanRecord14Array BooleanRecord14[3]; - -type BooleanRecord15Array BooleanRecord15[]; - -type ClosedBooleanRecord15Array BooleanRecord15[3]; - -type BooleanRecord16Array BooleanRecord16[]; - -type ClosedBooleanRecord16Array BooleanRecord16[3]; - -type BooleanRecord17Array BooleanRecord17[]; - -type ClosedBooleanRecord17Array BooleanRecord17[3]; - -type BooleanRecord18Array BooleanRecord18[]; - -type ClosedBooleanRecord18Array BooleanRecord18[3]; - -type NilRecord1Array NilRecord1[]; - -type ClosedNilRecord1Array NilRecord1[3]; - -type NilRecord2Array NilRecord2[]; - -type ClosedNilRecord2Array NilRecord2[3]; - -type NilRecord3Array NilRecord3[]; - -type ClosedNilRecord3Array NilRecord3[3]; - -type NilRecord4Array NilRecord4[]; - -type ClosedNilRecord4Array NilRecord4[3]; - -type NilRecord5Array NilRecord5[]; - -type ClosedNilRecord5Array NilRecord5[3]; - -type NilRecord6Array NilRecord6[]; - -type ClosedNilRecord6Array NilRecord6[3]; - -type NilRecord7Array NilRecord7[]; - -type ClosedNilRecord7Array NilRecord7[3]; - -type NilRecord8Array NilRecord8[]; - -type ClosedNilRecord8Array NilRecord8[3]; - -type NilRecord9Array NilRecord9[]; - -type ClosedNilRecord9Array NilRecord9[3]; - -type NilRecord10Array NilRecord10[]; - -type ClosedNilRecord10Array NilRecord10[3]; - -type NilRecord11Array NilRecord11[]; - -type ClosedNilRecord11Array NilRecord11[3]; - -type NilRecord12Array NilRecord12[]; - -type ClosedNilRecord12Array NilRecord12[3]; - -type NilRecord13Array NilRecord13[]; - -type ClosedNilRecord13Array NilRecord13[3]; - -type NilRecord14Array NilRecord14[]; - -type ClosedNilRecord14Array NilRecord14[3]; - -type IntegerRecord1Array IntegerRecord1[]; - -type ClosedIntegerRecord1Array IntegerRecord1[3]; - -type IntegerRecord2Array IntegerRecord2[]; - -type ClosedIntegerRecord2Array IntegerRecord2[3]; - -type IntegerRecord3Array IntegerRecord3[]; - -type ClosedIntegerRecord3Array IntegerRecord3[3]; - -type IntegerRecord4Array IntegerRecord4[]; - -type ClosedIntegerRecord4Array IntegerRecord4[3]; - -type IntegerRecord5Array IntegerRecord5[]; - -type ClosedIntegerRecord5Array IntegerRecord5[3]; - -type IntegerRecord6Array IntegerRecord6[]; - -type ClosedIntegerRecord6Array IntegerRecord6[3]; - -type IntegerRecord7Array IntegerRecord7[]; - -type ClosedIntegerRecord7Array IntegerRecord7[3]; - -type IntegerRecord8Array IntegerRecord8[]; - -type ClosedIntegerRecord8Array IntegerRecord8[3]; - -type IntegerRecord9Array IntegerRecord9[]; - -type ClosedIntegerRecord9Array IntegerRecord9[3]; - -type IntegerRecord10Array IntegerRecord10[]; - -type ClosedIntegerRecord10Array IntegerRecord10[3]; - -type IntegerRecord11Array IntegerRecord11[]; - -type ClosedIntegerRecord11Array IntegerRecord11[3]; - -type IntegerRecord12Array IntegerRecord12[]; - -type ClosedIntegerRecord12Array IntegerRecord12[3]; - -type IntegerRecord13Array IntegerRecord13[]; - -type ClosedIntegerRecord13Array IntegerRecord13[3]; - -type IntegerRecord14Array IntegerRecord14[]; - -type ClosedIntegerRecord14Array IntegerRecord14[3]; - -type FloatRecord1Array FloatRecord1[]; - -type ClosedFloatRecord1Array FloatRecord1[3]; - -type FloatRecord2Array FloatRecord2[]; - -type ClosedFloatRecord2Array FloatRecord2[3]; - -type FloatRecord3Array FloatRecord3[]; - -type ClosedFloatRecord3Array FloatRecord3[3]; - -type FloatRecord4Array FloatRecord4[]; - -type ClosedFloatRecord4Array FloatRecord4[3]; - -type FloatRecord5Array FloatRecord5[]; - -type ClosedFloatRecord5Array FloatRecord5[3]; - -type FloatRecord6Array FloatRecord6[]; - -type ClosedFloatRecord6Array FloatRecord6[3]; - -type FloatRecord7Array FloatRecord7[]; - -type ClosedFloatRecord7Array FloatRecord7[3]; - -type FloatRecord8Array FloatRecord8[]; - -type ClosedFloatRecord8Array FloatRecord8[3]; - -type FloatRecord9Array FloatRecord9[]; - -type ClosedFloatRecord9Array FloatRecord9[3]; - -type FloatRecord10Array FloatRecord10[]; - -type ClosedFloatRecord10Array FloatRecord10[3]; - -type FloatRecord11Array FloatRecord11[]; - -type ClosedFloatRecord11Array FloatRecord11[3]; - -type FloatRecord12Array FloatRecord12[]; - -type ClosedFloatRecord12Array FloatRecord12[3]; - -type FloatRecord13Array FloatRecord13[]; - -type ClosedFloatRecord13Array FloatRecord13[3]; - -type FloatRecord14Array FloatRecord14[]; - -type ClosedFloatRecord14Array FloatRecord14[3]; - -type DecimalRecord1Array DecimalRecord1[]; - -type ClosedDecimalRecord1Array DecimalRecord1[3]; - -type DecimalRecord2Array DecimalRecord2[]; - -type ClosedDecimalRecord2Array DecimalRecord2[3]; - -type DecimalRecord3Array DecimalRecord3[]; - -type ClosedDecimalRecord3Array DecimalRecord3[3]; - -type DecimalRecord4Array DecimalRecord4[]; - -type ClosedDecimalRecord4Array DecimalRecord4[3]; - -type DecimalRecord5Array DecimalRecord5[]; - -type ClosedDecimalRecord5Array DecimalRecord5[3]; - -type DecimalRecord6Array DecimalRecord6[]; - -type ClosedDecimalRecord6Array DecimalRecord6[3]; - -type DecimalRecord7Array DecimalRecord7[]; - -type ClosedDecimalRecord7Array DecimalRecord7[3]; - -type DecimalRecord8Array DecimalRecord8[]; - -type ClosedDecimalRecord8Array DecimalRecord8[3]; - -type DecimalRecord9Array DecimalRecord9[]; - -type ClosedDecimalRecord9Array DecimalRecord9[3]; - -type DecimalRecord10Array DecimalRecord10[]; - -type ClosedDecimalRecord10Array DecimalRecord10[3]; - -type DecimalRecord11Array DecimalRecord11[]; - -type ClosedDecimalRecord11Array DecimalRecord11[3]; - -type DecimalRecord12Array DecimalRecord12[]; - -type ClosedDecimalRecord12Array DecimalRecord12[3]; - -type DecimalRecord13Array DecimalRecord13[]; - -type ClosedDecimalRecord13Array DecimalRecord13[3]; - -type DecimalRecord14Array DecimalRecord14[]; - -type ClosedDecimalRecord14Array DecimalRecord14[3]; - -type StringRecord1Array StringRecord1[]; - -type ClosedStringRecord1Array StringRecord1[3]; - -type StringRecord2Array StringRecord2[]; - -type ClosedStringRecord2Array StringRecord2[3]; - -type StringRecord3Array StringRecord3[]; - -type ClosedStringRecord3Array StringRecord3[3]; - -type StringRecord4Array StringRecord4[]; - -type ClosedStringRecord4Array StringRecord4[3]; - -type StringRecord5Array StringRecord5[]; - -type ClosedStringRecord5Array StringRecord5[3]; - -type StringRecord6Array StringRecord6[]; - -type ClosedStringRecord6Array StringRecord6[3]; - -type StringRecord7Array StringRecord7[]; - -type ClosedStringRecord7Array StringRecord7[3]; - -type StringRecord8Array StringRecord8[]; - -type ClosedStringRecord8Array StringRecord8[3]; - -type StringRecord9Array StringRecord9[]; - -type ClosedStringRecord9Array StringRecord9[3]; - -type StringRecord10Array StringRecord10[]; - -type ClosedStringRecord10Array StringRecord10[3]; - -type StringRecord11Array StringRecord11[]; - -type ClosedStringRecord11Array StringRecord11[3]; - -type StringRecord12Array StringRecord12[]; - -type ClosedStringRecord12Array StringRecord12[3]; - -type StringRecord13Array StringRecord13[]; - -type ClosedStringRecord13Array StringRecord13[3]; - -type StringRecord14Array StringRecord14[]; - -type ClosedStringRecord14Array StringRecord14[3]; - -type StringRecord15Array StringRecord15[]; - -type StringRecord16Array StringRecord16[]; - -type StringRecord17Array StringRecord17[]; - -type StringRecord18Array StringRecord18[]; - -type StringRecord19Array StringRecord19[]; - -type StringRecord20Array StringRecord20[]; - -type StringRecord21Array StringRecord21[]; - -type StringRecord22Array StringRecord22[]; - -type StringRecord23Array StringRecord23[]; - -type JsonRecord1Array JsonRecord1[]; - -type ClosedJsonRecord1Array JsonRecord1[3]; - -type JsonRecord2Array JsonRecord2[]; - -type ClosedJsonRecord2Array JsonRecord2[3]; - -type JsonRecord3Array JsonRecord3[]; - -type ClosedJsonRecord3Array JsonRecord3[3]; - -type JsonRecord4Array JsonRecord4[]; - -type ClosedJsonRecord4Array JsonRecord4[3]; - -type JsonRecord5Array JsonRecord5[]; - -type ClosedJsonRecord5Array JsonRecord5[3]; - -type JsonRecord6Array JsonRecord6[]; - -type ClosedJsonRecord6Array JsonRecord6[3]; - -type JsonRecord7Array JsonRecord7[]; - -type ClosedJsonRecord7Array JsonRecord7[3]; - -type JsonRecord8Array JsonRecord8[]; - -type ClosedJsonRecord8Array JsonRecord8[3]; - -type JsonRecord9Array JsonRecord9[]; - -type ClosedJsonRecord9Array JsonRecord9[3]; - -type JsonRecord10Array JsonRecord10[]; - -type ClosedJsonRecord10Array JsonRecord10[3]; - -type JsonRecord11Array JsonRecord11[]; - -type ClosedJsonRecord11Array JsonRecord11[3]; - -type JsonRecord12Array JsonRecord12[]; - -type ClosedJsonRecord12Array JsonRecord12[3]; - -type JsonRecord13Array JsonRecord13[]; - -type ClosedJsonRecord13Array JsonRecord13[3]; - -type JsonRecord14Array JsonRecord14[]; - -type ClosedJsonRecord14Array JsonRecord14[3]; +type BooleanTuple1 [boolean, boolean, boolean, boolean]; -type AnydataRecord1Array AnydataRecord1[]; +type BooleanTuple2 [boolean, boolean]; -type ClosedAnydataRecord1Array AnydataRecord1[3]; +type BooleanTuple3 [boolean, boolean...]; -type AnydataRecord2Array AnydataRecord2[]; +type BooleanTuple4 [boolean...]; -type ClosedAnydataRecord2Array AnydataRecord2[3]; +type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; -type AnydataRecord3Array AnydataRecord3[]; +type NillableBooleanTuple6 [boolean?, boolean?]; -type ClosedAnydataRecord3Array AnydataRecord3[3]; +type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; -type AnydataRecord4Array AnydataRecord4[]; +type NillableBooleanTuple8 [boolean?...]; -type ClosedAnydataRecord4Array AnydataRecord4[3]; +type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; -type AnydataRecord5Array AnydataRecord5[]; +type NilTuple3 [(), ()...]; -type ClosedAnydataRecord5Array AnydataRecord5[3]; +type StringTuple3 [string, string...]; -type AnydataRecord6Array AnydataRecord6[]; +type AnydataTuple3 [anydata, anydata...]; -type ClosedAnydataRecord6Array AnydataRecord6[3]; +type JsonTuple3 [json, json...]; -type AnydataRecord7Array AnydataRecord7[]; +type StringArray string[]; -type ClosedAnydataRecord7Array AnydataRecord7[3]; +type StringArray1 string[]; -type AnydataRecord8Array AnydataRecord8[]; +type BooleanArray boolean[]; -type ClosedAnydataRecord8Array AnydataRecord8[3]; +type NillableBooleanArray boolean?[]; -type AnydataRecord9Array AnydataRecord9[]; +type NillableIntOrUnionBooleanArray (int|boolean?)[]; -type ClosedAnydataRecord9Array AnydataRecord9[3]; +type JsonArray1 json[]; -type AnydataRecord10Array AnydataRecord10[]; +type AnydataArray1 anydata[]; -type ClosedAnydataRecord10Array AnydataRecord10[3]; +type IntegerMap map; -type AnydataRecord11Array AnydataRecord11[]; +type StringMap map; -type ClosedAnydataRecord11Array AnydataRecord11[3]; +type NillableIntUnionStringMap map; -type AnydataRecord12Array AnydataRecord12[]; +type IntUnionStringMap map; -type ClosedAnydataRecord12Array AnydataRecord12[3]; +type DecimalMap map; -type AnydataRecord13Array AnydataRecord13[]; +type FloatMap map; -type ClosedAnydataRecord13Array AnydataRecord13[3]; +type BooleanMap map; -type AnydataRecord14Array AnydataRecord14[]; +type NillableBooleanMap map; -type ClosedAnydataRecord14Array AnydataRecord14[3]; +type NillableIntUnionBooleanMap map; -type CustomRecord1Array CustomRecord1[]; +type IntUnionBooleanMap map; -type ClosedCustomRecord1Array CustomRecord1[3]; +type NilMap map<()>; -type CustomRecord2Array CustomRecord2[]; +type JsonMap map; -type ClosedCustomRecord2Array CustomRecord2[3]; +type AnydataMap map; -type CustomRecord3Array CustomRecord3[]; +type CustomMap map; -type ClosedCustomRecord3Array CustomRecord3[3]; +type BooleanRecord1Array BooleanRecord1[]; -type CustomRecord4Array CustomRecord4[]; +type ClosedBooleanRecord1Array BooleanRecord1[3]; -type ClosedCustomRecord4Array CustomRecord4[3]; +type BooleanRecord2Array BooleanRecord2[]; -type CustomRecord5Array CustomRecord5[]; +type ClosedBooleanRecord2Array BooleanRecord2[3]; -type ClosedCustomRecord5Array CustomRecord5[3]; +type BooleanRecord3Array BooleanRecord3[]; -type CustomRecord6Array CustomRecord6[]; +type ClosedBooleanRecord3Array BooleanRecord3[3]; -type ClosedCustomRecord6Array CustomRecord6[3]; +type BooleanRecord4Array BooleanRecord4[]; -type CustomRecord7Array CustomRecord7[]; +type ClosedBooleanRecord4Array BooleanRecord4[3]; -type ClosedCustomRecord7Array CustomRecord7[3]; +type BooleanRecord5Array BooleanRecord5[]; -type CustomRecord8Array CustomRecord8[]; +type ClosedBooleanRecord5Array BooleanRecord5[3]; -type ClosedCustomRecord8Array CustomRecord8[3]; +type BooleanRecord6Array BooleanRecord6[]; -type CustomRecord9Array CustomRecord9[]; +type ClosedBooleanRecord6Array BooleanRecord6[3]; -type ClosedCustomRecord9Array CustomRecord9[3]; +type BooleanRecord7Array BooleanRecord7[]; -type CustomRecord10Array CustomRecord10[]; +type ClosedBooleanRecord7Array BooleanRecord7[3]; -type ClosedCustomRecord10Array CustomRecord10[3]; +type BooleanRecord8Array BooleanRecord8[]; -type CustomRecord11Array CustomRecord11[]; +type ClosedBooleanRecord8Array BooleanRecord8[3]; -type ClosedCustomRecord11Array CustomRecord11[3]; +type BooleanRecord9Array BooleanRecord9[]; -type CustomRecord12Array CustomRecord12[]; +type ClosedBooleanRecord9Array BooleanRecord9[3]; -type ClosedCustomRecord12Array CustomRecord12[3]; +type BooleanRecord10Array BooleanRecord10[]; -type CustomRecord13Array CustomRecord13[]; +type ClosedBooleanRecord10Array BooleanRecord10[3]; -type ClosedCustomRecord13Array CustomRecord13[3]; +type BooleanRecord11Array BooleanRecord11[]; -type CustomRecord14Array CustomRecord14[]; +type ClosedBooleanRecord11Array BooleanRecord11[3]; -type ClosedCustomRecord14Array CustomRecord14[3]; +type BooleanRecord12Array BooleanRecord12[]; -type CustomRecord15Array CustomRecord15[]; +type ClosedBooleanRecord12Array BooleanRecord12[3]; -type CustomRecord16Array CustomRecord16[]; +type BooleanRecord13Array BooleanRecord13[]; -type CustomRecord17Array CustomRecord17[]; +type ClosedBooleanRecord13Array BooleanRecord13[3]; -type CustomRecord18Array CustomRecord18[]; +type BooleanRecord14Array BooleanRecord14[]; -type CustomRecord19Array CustomRecord19[]; +type ClosedBooleanRecord14Array BooleanRecord14[3]; -type CustomRecord20Array CustomRecord20[]; +type BooleanRecord15Array BooleanRecord15[]; -type CustomRecord21Array CustomRecord21[]; +type ClosedBooleanRecord15Array BooleanRecord15[3]; -type CustomRecord22Array CustomRecord22[]; +type BooleanRecord16Array BooleanRecord16[]; -type CustomRecord23Array CustomRecord23[]; +type ClosedBooleanRecord16Array BooleanRecord16[3]; -type CustomRecord24Array CustomRecord24[]; +type BooleanRecord17Array BooleanRecord17[]; -type CustomRecord25Array CustomRecord25[]; +type ClosedBooleanRecord17Array BooleanRecord17[3]; -type CustomRecord26Array CustomRecord26[]; +type BooleanRecord18Array BooleanRecord18[]; -type CustomRecord27Array CustomRecord27[]; -type CustomRecord28Array CustomRecord28[]; -type CustomRecord29Array CustomRecord29[]; -type CustomRecord30Array CustomRecord30[]; -type CustomRecord31Array CustomRecord31[]; -type CustomRecord32Array CustomRecord32[]; -type CustomRecord33Array CustomRecord33[]; -type CustomRecord34Array CustomRecord34[]; -type CustomRecord35Array CustomRecord35[]; -type CustomRecord36Array CustomRecord36[]; -type CustomRecord37Array CustomRecord37[]; -type CustomRecord38Array CustomRecord38[]; -type CustomRecord39Array CustomRecord39[]; -type CustomRecord40Array CustomRecord40[]; -type CustomRecord41Array CustomRecord41[]; -type CustomRecord42Array CustomRecord42[]; -type CustomRecord43Array CustomRecord43[]; -type CustomRecord44Array CustomRecord44[]; -type CustomRecord45Array CustomRecord45[]; -type CustomRecord46Array CustomRecord46[]; -type CustomRecord47Array CustomRecord47[]; -type CustomRecord48Array CustomRecord48[]; -type CustomRecord49Array CustomRecord49[]; -type CustomRecord50Array CustomRecord50[]; -type CustomRecord51Array CustomRecord51[]; -type CustomRecord52Array CustomRecord52[]; -type CustomRecord53Array CustomRecord53[]; -type CustomRecord54Array CustomRecord54[]; -type CustomRecord55Array CustomRecord55[]; -type CustomRecord56Array CustomRecord56[]; +type ClosedBooleanRecord18Array BooleanRecord18[3]; type BooleanTuple1Array BooleanTuple1[]; @@ -2137,248 +292,28 @@ type NillableBooleanTuple8Array NillableBooleanTuple8[]; type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; -type NilTuple1Array NilTuple1[]; - -type ClosedNilTuple1Array NilTuple1[3]; - -type NilTuple2Array NilTuple2[]; - -type ClosedNilTuple2Array NilTuple2[3]; - type NilTuple3Array NilTuple3[]; type ClosedNilTuple3Array NilTuple3[3]; -type NilTuple4Array NilTuple4[]; - -type ClosedNilTuple4Array NilTuple4[3]; - -type IntegerTuple1Array IntegerTuple1[]; - -type ClosedIntegerTuple1Array IntegerTuple1[3]; - -type IntegerTuple2Array IntegerTuple2[]; - -type ClosedIntegerTuple2Array IntegerTuple2[3]; - -type IntegerTuple3Array IntegerTuple3[]; - -type ClosedIntegerTuple3Array IntegerTuple3[3]; - -type IntegerTuple4Array IntegerTuple4[]; - -type ClosedIntegerTuple4Array IntegerTuple4[3]; - -type FloatTuple1Array FloatTuple1[]; - -type ClosedFloatTuple1Array FloatTuple1[3]; - -type FloatTuple2Array FloatTuple2[]; - -type ClosedFloatTuple2Array FloatTuple2[3]; - -type FloatTuple3Array FloatTuple3[]; - -type ClosedFloatTuple3Array FloatTuple3[3]; - -type FloatTuple4Array FloatTuple4[]; - -type ClosedFloatTuple4Array FloatTuple4[3]; - -type DecimalTuple1Array DecimalTuple1[]; - -type ClosedDecimalTuple1Array DecimalTuple1[3]; - -type DecimalTuple2Array DecimalTuple2[]; - -type ClosedDecimalTuple2Array DecimalTuple2[3]; - -type DecimalTuple3Array DecimalTuple3[]; - -type ClosedDecimalTuple3Array DecimalTuple3[3]; - -type DecimalTuple4Array DecimalTuple4[]; - -type ClosedDecimalTuple4Array DecimalTuple4[3]; - -type StringTuple1Array StringTuple1[]; - -type ClosedStringTuple1Array StringTuple1[3]; - -type StringTuple2Array StringTuple2[]; - -type ClosedStringTuple2Array StringTuple2[3]; - type StringTuple3Array StringTuple3[]; type ClosedStringTuple3Array StringTuple3[3]; -type StringTuple4Array StringTuple4[]; - -type ClosedStringTuple4Array StringTuple4[3]; - -type AnydataTuple1Array AnydataTuple1[]; - -type ClosedAnydataTuple1Array AnydataTuple1[3]; - -type AnydataTuple2Array AnydataTuple2[]; - -type ClosedAnydataTuple2Array AnydataTuple2[3]; - type AnydataTuple3Array AnydataTuple3[]; type ClosedAnydataTuple3Array AnydataTuple3[3]; -type AnydataTuple4Array AnydataTuple4[]; - -type ClosedAnydataTuple4Array AnydataTuple4[3]; - -type JsonTuple1Array JsonTuple1[]; - -type ClosedJsonTuple1Array JsonTuple1[3]; - -type JsonTuple2Array JsonTuple2[]; - -type ClosedJsonTuple2Array JsonTuple2[3]; - type JsonTuple3Array JsonTuple3[]; type ClosedJsonTuple3Array JsonTuple3[3]; -type JsonTuple4Array JsonTuple4[]; - -type ClosedJsonTuple4Array JsonTuple4[3]; - -type CustomTuple1Array CustomTuple1[]; - -type ClosedCustomTuple1Array CustomTuple1[3]; - -type CustomTuple2Array CustomTuple2[]; - -type ClosedCustomTuple2Array CustomTuple2[3]; - -type CustomTuple3Array CustomTuple3[]; - -type ClosedCustomTuple3Array CustomTuple3[3]; - -type CustomTuple4Array CustomTuple4[]; - -type ClosedCustomTuple4Array CustomTuple4[3]; - -type CustomTuple5Array CustomTuple5[]; - -type ClosedCustomTuple5Array CustomTuple5[3]; - -type CustomTuple6Array CustomTuple6[]; - -type CustomTuple7Array CustomTuple7[]; - -type CustomTuple8Array CustomTuple8[]; - -type ClosedCustomTuple6Array CustomTuple6[3]; - -type IntegerArray1Array IntegerArray1[]; - -type ClosedIntegerArray1Array IntegerArray1[3]; - -type IntegerArray2Array IntegerArray2[]; - -type ClosedIntegerArray2Array IntegerArray2[3]; - -type IntegerArray3Array IntegerArray3[]; - -type ClosedIntegerArray3Array IntegerArray3[3]; - -type IntegerArray4Array IntegerArray4[]; - -type ClosedIntegerArray4Array IntegerArray4[3]; - -type IntegerArray5Array IntegerArray5[]; - -type ClosedIntegerArray5Array IntegerArray5[3]; - -type IntegerArray6Array IntegerArray5[]; - -type ClosedIntegerArray6Array IntegerArray5[3]; - type StringArray1Array StringArray1[]; type StringArrayArray StringArray[]; -type NillableStringArrayArray NillableStringArray[]; - -type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; - type ClosedStringArray1Array StringArray1[3]; -type StringArray2Array StringArray2[]; - -type ClosedStringArray2Array StringArray2[3]; - -type StringArray3Array StringArray3[]; - -type ClosedStringArray3Array StringArray3[3]; - -type StringArray4Array StringArray4[]; - -type ClosedStringArray4Array StringArray4[3]; - -type StringArray5Array StringArray5[]; - -type ClosedStringArray5Array StringArray5[3]; - -type StringArray6Array StringArray5[]; - -type ClosedStringArray6Array StringArray5[3]; - -type FloatArray1Array FloatArray1[]; - -type ClosedFloatArray1Array FloatArray1[3]; - -type FloatArray2Array FloatArray2[]; - -type ClosedFloatArray2Array FloatArray2[3]; - -type FloatArray3Array FloatArray3[]; - -type ClosedFloatArray3Array FloatArray3[3]; - -type FloatArray4Array FloatArray4[]; - -type ClosedFloatArray4Array FloatArray4[3]; - -type FloatArray5Array FloatArray5[]; - -type ClosedFloatArray5Array FloatArray5[3]; - -type FloatArray6Array FloatArray5[]; - -type ClosedFloatArray6Array FloatArray5[3]; - -type DecimalArray1Array DecimalArray1[]; - -type ClosedDecimalArray1Array DecimalArray1[3]; - -type DecimalArray2Array DecimalArray2[]; - -type ClosedDecimalArray2Array DecimalArray2[3]; - -type DecimalArray3Array DecimalArray3[]; - -type ClosedDecimalArray3Array DecimalArray3[3]; - -type DecimalArray4Array DecimalArray4[]; - -type ClosedDecimalArray4Array DecimalArray4[3]; - -type DecimalArray5Array DecimalArray5[]; - -type ClosedDecimalArray5Array DecimalArray5[3]; - -type DecimalArray6Array DecimalArray5[]; - -type ClosedDecimalArray6Array DecimalArray5[3]; - type BooleanArrayArray BooleanArray[]; type ClosedBooleanArrayArray BooleanArray[3]; @@ -2387,122 +322,14 @@ type NillableBooleanArrayArray NillableBooleanArray[]; type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; -type BooleanArray2Array BooleanArray2[]; - -type ClosedBooleanArray2Array BooleanArray2[3]; - -type BooleanArray3Array BooleanArray3[]; - -type ClosedBooleanArray3Array BooleanArray3[3]; - -type BooleanArray4Array BooleanArray4[]; - -type ClosedBooleanArray4Array BooleanArray4[3]; - -type BooleanArray5Array BooleanArray5[]; - -type ClosedBooleanArray5Array BooleanArray5[3]; - -type BooleanArray6Array BooleanArray5[]; - -type ClosedBooleanArray6Array BooleanArray5[3]; - -type NilArray1Array NilArray1[]; - -type ClosedNilArray1Array NilArray1[3]; - -type NilArray2Array NilArray2[]; - -type ClosedNilArray2Array NilArray2[3]; - -type NilArray3Array NilArray3[]; - -type ClosedNilArray3Array NilArray3[3]; - -type NilArray4Array NilArray4[]; - -type ClosedNilArray4Array NilArray4[3]; - -type NilArray5Array NilArray5[]; - -type ClosedNilArray5Array NilArray5[3]; - -type NilArray6Array NilArray5[]; - -type ClosedNilArray6Array NilArray5[3]; - type JsonArray1Array JsonArray1[]; type ClosedJsonArray1Array JsonArray1[3]; -type JsonArray2Array JsonArray2[]; - -type ClosedJsonArray2Array JsonArray2[3]; - -type JsonArray3Array JsonArray3[]; - -type ClosedJsonArray3Array JsonArray3[3]; - -type JsonArray4Array JsonArray4[]; - -type ClosedJsonArray4Array JsonArray4[3]; - -type JsonArray5Array JsonArray5[]; - -type ClosedJsonArray5Array JsonArray5[3]; - -type JsonArray6Array JsonArray5[]; - -type ClosedJsonArray6Array JsonArray5[3]; - type AnydataArray1Array AnydataArray1[]; type ClosedAnydataArray1Array AnydataArray1[3]; -type AnydataArray2Array AnydataArray2[]; - -type ClosedAnydataArray2Array AnydataArray2[3]; - -type AnydataArray3Array AnydataArray3[]; - -type ClosedAnydataArray3Array AnydataArray3[3]; - -type AnydataArray4Array AnydataArray4[]; - -type ClosedAnydataArray4Array AnydataArray4[3]; - -type AnydataArray5Array AnydataArray5[]; - -type ClosedAnydataArray5Array AnydataArray5[3]; - -type AnydataArray6Array AnydataArray5[]; - -type ClosedAnydataArray6Array AnydataArray5[3]; - -type CustomArray1Array CustomArray1[]; - -type ClosedCustomArray1Array CustomArray1[3]; - -type CustomArray2Array CustomArray2[]; - -type ClosedCustomArray2Array CustomArray2[3]; - -type CustomArray3Array CustomArray3[]; - -type ClosedCustomArray3Array CustomArray3[3]; - -type CustomArray4Array CustomArray4[]; - -type ClosedCustomArray4Array CustomArray4[3]; - -type CustomArray5Array CustomArray5[]; - -type ClosedCustomArray5Array CustomArray5[3]; - -type CustomArray6Array CustomArray5[]; - -type ClosedCustomArray6Array CustomArray5[3]; - type IntegerMapArray IntegerMap[]; type ClosedIntegerMapArray IntegerMap[3]; 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 0a6c492..9050847 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal @@ -340,28 +340,28 @@ function testArrayIndexes() { 5, 6, 7 7, 8, 9`; - record {}[2]|error rec = csv:parseStringToRecord(csv); + record {}[2]|csv:Error rec = csv:parseStringToRecord(csv); test:assertEquals(rec, [ {a: 1, b: 2}, {a: 3, b: 4} ]); - map[2]|error rec_2 = csv:parseStringToRecord(csv); + map[2]|csv:Error rec_2 = csv:parseStringToRecord(csv); test:assertEquals(rec_2, [ {a: 1, b: 2}, {a: 3, b: 4} ]); - record {|int a;|}[2]|error rec2 = csv:parseStringToRecord(csv, {skipLines: [2]}); + record {|int a;|}[2]|csv:Error rec2 = csv:parseStringToRecord(csv, {skipLines: [2]}); test:assertEquals(rec2, [ {a: 1}, {a: 5} ]); - record {|int a;|}[5]|error rec2_2 = csv:parseStringToRecord(csv, {skipLines: [2]}); + record {|int a;|}[5]|csv:Error rec2_2 = csv:parseStringToRecord(csv, {skipLines: [2]}); test:assertTrue(rec2_2 is csv:Error); - int[][2]|error rec3 = csv:parseStringToList(csv2); + int[][2]|csv:Error rec3 = csv:parseStringToList(csv2); test:assertEquals(rec3, [ [1, 2], [3, 4], @@ -369,24 +369,24 @@ function testArrayIndexes() { [7, 8] ]); - [int, int][2]|error rec3_2 = csv:parseStringToList(csv2); + [int, int][2]|csv:Error rec3_2 = csv:parseStringToList(csv2); test:assertEquals(rec3_2, [ [1, 2], [3, 4] ]); - [int...][2]|error rec3_3 = csv:parseStringToList(csv2); + [int...][2]|csv:Error rec3_3 = csv:parseStringToList(csv2); test:assertEquals(rec3_3, [ [1, 2, 3], [3, 4, 5] ]); - int[1][2]|error rec4 = csv:parseStringToList(csv2, {skipLines: [2]}); + int[1][2]|csv:Error rec4 = csv:parseStringToList(csv2, {skipLines: [2]}); test:assertEquals(rec4, [ [1, 2] ]); - int[2][]|error rec5 = csv:parseStringToList(csv2); + int[2][]|csv:Error rec5 = csv:parseStringToList(csv2); test:assertEquals(rec5, [ [1, 2, 3], [3, 4, 5] @@ -398,28 +398,28 @@ 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]|error rec = csv:parseRecordAsRecordType(csv); + record {}[2]|csv:Error rec = csv:parseRecordAsRecordType(csv); test:assertEquals(rec, [ {a: 1, b: 2}, {a: 3, b: 4} ]); - map[2]|error rec_2 = csv:parseListAsRecordType(csv2, ["a", "b", "c"]); + 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} ]); - record {|int a;|}[2]|error rec2 = csv:parseRecordAsRecordType(csv, {skipLines: [2]}); + record {|int a;|}[2]|csv:Error rec2 = csv:parseRecordAsRecordType(csv, {skipLines: [2]}); test:assertEquals(rec2, [ {a: 1}, {a: 5} ]); - record {|int a;|}[5]|error rec2_2 = csv:parseRecordAsRecordType(csv, {skipLines: [2]}); + record {|int a;|}[5]|csv:Error rec2_2 = csv:parseRecordAsRecordType(csv, {skipLines: [2]}); test:assertTrue(rec2_2 is csv:Error); - int[][2]|error rec3 = csv:parseRecordAsListType(csv, ["a", "b"]); + int[][2]|csv:Error rec3 = csv:parseRecordAsListType(csv, ["a", "b"]); test:assertEquals(rec3, [ [1, 2], [3, 4], @@ -427,24 +427,24 @@ function testArrayIndexes2() { [7, 8] ]); - [int, int][2]|error rec3_2 = csv:parseListAsListType(csv2); + [int, int][2]|csv:Error rec3_2 = csv:parseListAsListType(csv2); test:assertEquals(rec3_2, [ [1, 2], [3, 4] ]); - [int...][2]|error rec3_3 = csv:parseRecordAsListType(csv, ["a", "b"], {skipLines: [1]}); + [int...][2]|csv:Error rec3_3 = csv:parseRecordAsListType(csv, ["a", "b"], {skipLines: [1]}); test:assertEquals(rec3_3, [ [3, 4], [5, 6] ]); - int[1][2]|error rec4 = csv:parseRecordAsListType(csv, ["a", "b"], {skipLines: [2]}); + int[1][2]|csv:Error rec4 = csv:parseRecordAsListType(csv, ["a", "b"], {skipLines: [2]}); test:assertEquals(rec4, [ [1, 2] ]); - int[2][]|error rec5 = csv:parseListAsListType(csv2); + int[2][]|csv:Error rec5 = csv:parseListAsListType(csv2); test:assertEquals(rec5, [ [1, 2, 3], [3, 4, 5] diff --git a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal index a9698aa..4060a59 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal @@ -16,127 +16,8 @@ boolean b1 = true; false b2 = false; -boolean? b3 = (); boolean|int b4 = false; -() n1 = (); -int? n2 = (); -() n3 = null; - -int i1 = 1; -int i2 = -2; -int i3 = int:MAX_VALUE; -int i4 = int:MIN_VALUE; -int i5 = 0; -2 i6 = 2; -int? i7 = (); -int|string i8 = 100; - -float f1 = 2.234; -float f2 = -3.21f; -float f3 = 0; -float f4 = float:Infinity; -float f5 = -float:Infinity; -float f6 = float:NaN; -2.3f f7 = 2.3; -float? f8 = (); -float|decimal f9 = 1.21; - -decimal d1 = 2.234; -decimal d2 = -3.21d; -decimal d3 = 0; -2.3d d4 = 2.3; -decimal? d5 = (); -decimal|int d6 = 1.21; - -string s1 = "string"; -string s2 = ""; -string:Char s3 = "a"; - -map bm1 = {b1, b2}; -map bm2 = {b1, b2, b3, n1, n3}; -map bm3 = {b1, b2, b3, b4, i1}; -map<()> bm4 = {n1, n3}; -map bm5 = {b1, b2, b3, b4:true}; - -map m5 = {i1, i2, i3, i4, i5, i6}; -map m6 = {f1, f2, f3, f4, f5, f6, f7}; -map m7 = {d1, d2, d3, d4}; -map m8 = {d1, f1, f9, f10: 1.23}; -map m9 = {s1, s2, s3}; -map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; -map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; - -boolean[] arr1 = [b1, b2]; -boolean?[] arr2 = [b1, b2, b3, n1, n3]; -(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; -()[] arr4 = [n1, n3]; -int[] arr5 = [i1, i2, i3, i4, i5, i6]; -float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; -decimal[] arr7 = [d1, d2, d3, d4]; -(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; -string[] arr9 = [s1, s2, s3]; -anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; - -[boolean, boolean] bt1 = [b1, b2]; -[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; -[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; -[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; -[boolean...] bt5 = [b1, b2]; - -[string, string] st1 = [s1, s2]; -[string, string, string, string] st2 = [s1, s2, s3, s2]; -[string...] st3 = [s1, s2]; -[string, string, string...] st4 = [s1, s2, s3, s2]; - -[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; -[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; -[string?...] st7 = [s1, s2]; -[string...] st8 = []; -[string, string, string] st9 = [s1, s2, s3]; - -[(), ()] tup4 = [n1, n3]; -[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; -[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; -[string, string, string] tup9 = [s1, s2, s3]; -[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, - n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, json] tup11 = - [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, - f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 -]; - -[boolean, boolean...] restTup1 = [b1, b2]; -[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; -[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; -[(), ()...] restTup4 = [n1, n3]; -[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; -[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal...] restTup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; -[string...] restTup9 = [s1, s2, s3]; -[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 -]; - -var booleanRecordArray = [ - {b1, b2, b3, b4}, {b1, b2, b3, b4} -]; - -var booleanRecordArray2 = [ - {},{} -]; - string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 true,false,true,false true,false, true,false @@ -179,94 +60,3 @@ string csvStringWithBooleanValues6 = string `b2,b3 string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 ${b1},${b2},(),${b4} `; - -string csvStringData1 = string ` - a, b, c, d, e, f - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData2 = string ` - hello, hello, (), 12, true, 12.34 - // comment - - a, b, c, d, e, f - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData3 = string ` - a, b, c, d, e, f - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData4 = string ` - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData5 = string ` - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData6 = string ` - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData7 = string ` - a@ b@ c@ d@ e@ f - 1@ string@ true@ 2.234@ -3.21@ () - 2@ s,tring@ true@ 2.234@ -3.21@ null - 3@ stri,ng@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; -string csvStringData8 = string ` - a@ b@ c@ d@ e@ f - - - - 1@ stri,ng@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ ()@-3.21 - 3@ string@ true@ 2.234@ -3.21@ null - - 4@ s,tring@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; - -string csvStringData9 = string ` - - 1@ string@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ -3.21@ null - - 3@ string@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ ()@-3.21 - - 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina-tests/parse-string-array-types-tests/tests/types.bal b/ballerina-tests/parse-string-array-types-tests/tests/types.bal index b496d60..411b2b0 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/types.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/types.bal @@ -14,2537 +14,50 @@ // specific language governing permissions and limitations // under the License. -type BooleanRecord1 record { - boolean b1; - boolean|string b2; - boolean|string? b3; - boolean b4; -}; - -type BooleanRecord2 record {| - boolean b1; - boolean|string b2; - boolean|string? b3; - boolean b4; -|}; - -type BooleanRecord3 record {| - boolean b1; - boolean? b3; -|}; - -type BooleanRecord4 record { - boolean b1; - boolean? b3; -}; - -type BooleanRecord5 record { - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); -}; - -type BooleanRecord6 record {| - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); -|}; - -type BooleanRecord7 record { - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type BooleanRecord8 record {| - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type BooleanRecord9 record {| - boolean b1; - boolean? b3; - boolean?...; -|}; - -type BooleanRecord10 record {| - boolean...; -|}; - -type BooleanRecord11 record {| - boolean b1; - string defaultableField = ""; - string? nillableField = (); - boolean?|string...; -|}; - -type BooleanRecord12 record {| - boolean b1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - boolean...; -|}; - -type BooleanRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - string|boolean...; -|}; - -type BooleanRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - boolean...; -|}; - -type BooleanRecord15 record {| - int b1; - string defaultableField = ""; - string? nillableField = (); - boolean?...; -|}; - -type BooleanRecord16 record {| - boolean?...; -|}; - -type BooleanRecord17 record {| - int...; -|}; - -type BooleanRecord18 record {| - boolean b2; - int?...; -|}; - -type NilRecord1 record { - () n1; - () n2; - () n3; -}; - -type NilRecord2 record {| - () n1; - () n2; - () n3; -|}; - -type NilRecord3 record {| - () n1; - () n4; -|}; - -type NilRecord4 record { - () n1; - () n4; -}; - -type NilRecord5 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -}; - -type NilRecord6 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type NilRecord7 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type NilRecord8 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type NilRecord9 record {| - () n1; - () n2; - ()...; -|}; - -type NilRecord10 record {| - ()...; -|}; - -type NilRecord11 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord12 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type NilRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type IntegerRecord1 record { - int i1; - int i2; - int i3; - int? i4; - int? i5; - int i6; - int i7; - int? i8; -}; - -type IntegerRecord2 record {| - int i1; - int? i2; - int i3; - int i4; - int? i5; - int i6; - int i7; - int? i8; -|}; - -type IntegerRecord3 record {| - int i1; - int i4; - int i6; -|}; - -type IntegerRecord4 record { - int i1; - int i4; - int i6; -}; - -type IntegerRecord5 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -}; - -type IntegerRecord6 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -|}; - -type IntegerRecord7 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type IntegerRecord8 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type IntegerRecord9 record {| - int i1; - int i2; - int...; -|}; - -type IntegerRecord10 record {| - int...; -|}; - -type IntegerRecord11 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord12 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type IntegerRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type FloatRecord1 record { - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -}; - -type FloatRecord2 record {| - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -|}; - -type FloatRecord3 record {| - float f1; - float f4; - float f7; -|}; - -type FloatRecord4 record { - float f1; - float f4; - float f7; -}; - -type FloatRecord5 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -}; - -type FloatRecord6 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type FloatRecord7 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type FloatRecord8 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type FloatRecord9 record {| - float f1; - float f2; - float...; -|}; - -type FloatRecord10 record {| - float...; -|}; - -type FloatRecord11 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord12 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type FloatRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type DecimalRecord1 record { - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -}; - -type DecimalRecord2 record {| - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -|}; - -type DecimalRecord3 record {| - decimal d1; - decimal d4; - decimal d7; -|}; - -type DecimalRecord4 record { - decimal d1; - decimal d4; - decimal d7; -}; - -type DecimalRecord5 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -}; - -type DecimalRecord6 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type DecimalRecord7 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type DecimalRecord8 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type DecimalRecord9 record {| - decimal d1; - decimal d2; - decimal...; -|}; - -type DecimalRecord10 record {| - decimal...; -|}; - -type DecimalRecord11 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord12 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type DecimalRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type StringRecord1 record { - string s1; - string s2; - string s3; -}; - -type StringRecord2 record {| - string s1; - string s2; - string s3; -|}; - -type StringRecord3 record {| - string s1; - string s4; -|}; - -type StringRecord4 record { - string s1; - string s4; -}; - -type StringRecord5 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -}; - -type StringRecord6 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type StringRecord7 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type StringRecord8 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type StringRecord9 record {| - string s1; - string s2; - string...; -|}; - -type StringRecord10 record {| - string...; -|}; - -type StringRecord11 record {| - string s1; - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord12 record {| - string d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord15 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord16 record {| - string?...; -|}; - -type StringRecord17 record {| - int...; -|}; - -type StringRecord18 record {| - string b2; - int?...; -|}; - -type StringRecord19 record { - string s1 = ""; - string s2 = ""; -}; - -type StringRecord20 record {| - string s1 = ""; - string s2 = ""; -|}; - -type StringRecord21 record { -}; - -type StringRecord22 record {| - string s1 = ""; - string s2 = ""; - json...; -|}; - -type StringRecord23 record {| - json...; -|}; - -type JsonRecord1 record { - json j1; - json j2; - json j3; -}; - -type JsonRecord2 record {| - json j1; - json j2; - json j3; -|}; - -type JsonRecord3 record {| - json j1; - json j4; -|}; - -type JsonRecord4 record { - json j1; - json j4; -}; - -type JsonRecord5 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -}; - -type JsonRecord6 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -|}; - -type JsonRecord7 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -}; - -type JsonRecord8 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -|}; - -type JsonRecord9 record {| - json j1; - json j2; - json...; -|}; - -type JsonRecord10 record {| - json...; -|}; - -type JsonRecord11 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord12 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type JsonRecord13 record {| - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord14 record {| - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type AnydataRecord1 record { - anydata anydata1; - anydata anydata2; - anydata anydata3; -}; - -type AnydataRecord2 record {| - anydata anydata1; - anydata anydata2; - anydata anydata3; -|}; - -type AnydataRecord3 record {| - anydata anydata1; - anydata anydata4; -|}; - -type AnydataRecord4 record { - anydata anydata1; - anydata anydata4; -}; - -type AnydataRecord5 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -}; - -type AnydataRecord6 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type AnydataRecord7 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type AnydataRecord8 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type AnydataRecord9 record {| - anydata anydata1; - anydata anydata2; - anydata...; -|}; - -type AnydataRecord10 record {| - anydata...; -|}; - -type AnydataRecord11 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord12 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type AnydataRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type CustomRecord1 record { - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -}; - -type CustomRecord2 record {| - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -|}; - -type CustomRecord3 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -|}; - -type CustomRecord4 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -}; - -type CustomRecord5 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string defaultableField = ""; - string? nillableField = (); -}; - -type CustomRecord6 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type CustomRecord7 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type CustomRecord8 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type CustomRecord9 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string...; -|}; - -type CustomRecord10 record {| - string...; -|}; - -type CustomRecord11 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord12 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord15 record {| - string '1; - string '2; -|}; - -type CustomRecord16 record {| - string '1; - string '2; - string '3; - string '4; -|}; - -type CustomRecord17 record { - string '1; - string '2; -}; - -type CustomRecord18 record { - string '1; - string '2; - string '3; - string '4; -}; - -type CustomRecord19 record { - string '1; - string '2; - string '3 = ""; - string '4 = ""; -}; - -type CustomRecord20 record { - string '1; -}; - -type CustomRecord21 record {| - string '1; - json...; -|}; - -type CustomRecord22 record {| - string '1; - string...; -|}; - -type CustomRecord23 record {| - string '1; - string a = ""; - string...; -|}; - -type CustomRecord24 record {| - string '1; - string '2 = ""; - string...; -|}; - -type CustomRecord25 record {| - int '1; - string...; -|}; - -type CustomRecord26 record {| - string '1; - int...; -|}; - -type CustomRecord27 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata a1; - json j1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord28 record { - string '1; -}; - -type CustomRecord29 record { - int '1; -}; - -type CustomRecord30 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord31 record {| - string '1; - string '6; -|}; - -type CustomRecord32 record {| - int '1; -|}; - -type CustomRecord33 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord34 record { - string '1; - string '6; - string '5 = ""; -}; - -type CustomRecord35 record { - string '1; - string '6; - string '9 = ""; -}; - -type CustomRecord36 record {| - string '1; - string '6; - string '9 = ""; -|}; - -type CustomRecord37 record {| - string '1; - string '6; - string '5 = ""; -|}; - -type CustomRecord38 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - string ...; -|}; - -type CustomRecord39 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - json ...; -|}; - -type CustomRecord40 record {| - string '5; - string '6; - json ...; -|}; - -type CustomRecord41 record {| - json ...; -|}; - -type CustomRecord42 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -|}; - -type CustomRecord43 record { - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -}; - -type CustomRecord44 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; - string ...; -|}; - -type CustomRecord45 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -|}; - -type CustomRecord46 record { - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -}; - -type CustomRecord47 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; - string ...; -|}; - -type CustomRecord48 record { - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -}; - -type CustomRecord49 record {| - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -|}; - -type CustomRecord50 record { - int H1; - float H4; -}; - -type CustomRecord51 record {| - int H1; - float H4; -|}; - -type CustomRecord52 record {| - string H1; - string H4; - string ...; -|}; - -type CustomRecord53 record {| - int H1; - float H4; - decimal ...; -|}; - -type CustomRecord54 record {| - string H1 = ""; - string H4; - string '1; -|}; - -type CustomRecord55 record {| - string H1 = ""; - string H4 = ""; - int '1 = 10; -|}; - -type CustomRecord56 record { - string H1 = ""; - string H4 = ""; - anydata '1 = 10; -}; - +type BooleanArray boolean[]; +type BooleanArrayArray BooleanArray[]; +type NillableIntOrUnionBooleanArray (int|boolean?)[]; +type StringArray1 string[]; +type StringArray2 string[2]; +type JsonArray1 json[]; +type AnydataArray1 anydata[]; type BooleanTuple1 [boolean, boolean, boolean, boolean]; - type BooleanTuple2 [boolean, boolean]; - type BooleanTuple3 [boolean, boolean...]; - type BooleanTuple4 [boolean...]; - type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; - type NillableBooleanTuple6 [boolean?, boolean?]; - type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; - type NillableBooleanTuple8 [boolean?...]; - type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; - -type NilTuple1 [(), (), ()]; - -type NilTuple2 [(), ()]; - type NilTuple3 [(), ()...]; - -type NilTuple4 [()...]; - -type IntegerTuple1 [int, int, int, int, int, int]; - -type IntegerTuple2 [int, int]; - -type IntegerTuple3 [int, int...]; - -type IntegerTuple4 [int...]; - -type FloatTuple1 [float, float, float, float, float, float, float]; - -type FloatTuple2 [float, float]; - -type FloatTuple3 [float, float...]; - -type FloatTuple4 [float...]; - -type DecimalTuple1 [decimal, decimal, decimal, decimal]; - -type DecimalTuple2 [decimal, decimal]; - type DecimalTuple3 [decimal, decimal...]; - -type DecimalTuple4 [decimal...]; - -type StringTuple1 [string, string, string, string]; - -type StringTuple2 [string, string]; - type StringTuple3 [string, string...]; - -type StringTuple4 [string...]; - -type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata]; - -type AnydataTuple2 [anydata, anydata]; - type AnydataTuple3 [anydata, anydata...]; - -type AnydataTuple4 [anydata...]; - -type JsonTuple1 [json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json]; - -type JsonTuple2 [json, json]; - type JsonTuple3 [json, json...]; +type DecimalArray1 decimal[]; -type JsonTuple4 [json...]; - -type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; - -type CustomTuple4 [string...]; - -type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; - -type CustomTuple6 [anydata...]; - -type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; - -type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; - -type IntegerArray1 int[]; - -type IntegerArray2 int[2]; - -type IntegerArray3 int[]; - -type IntegerArray4 int[2]; - -type IntegerArray5 int[3]; - -type IntegerArray6 int[4]; - -type StringArray string[]; - -type NillableStringArray string?[]; - -type NillableIntOrUnionStringArray (int|string?)[]; - -type StringArray1 string[]; +type NilTuple3Array NilTuple3[]; +type DecimalTuple3Array DecimalTuple3[]; +type StringTuple3Array StringTuple3[]; +type AnydataTuple3Array AnydataTuple3[]; +type JsonTuple3Array JsonTuple3[]; -type StringArray2 string[2]; - -type StringArray3 string[]; - -type StringArray4 string[2]; - -type StringArray5 string[3]; - -type StringArray6 string[4]; - -type FloatArray1 float[]; - -type FloatArray2 float[2]; - -type FloatArray3 float[]; - -type FloatArray4 float[2]; - -type FloatArray5 float[3]; - -type FloatArray6 float[4]; - -type DecimalArray1 decimal[]; - -type DecimalArray2 decimal[2]; - -type DecimalArray3 decimal[]; - -type DecimalArray4 decimal[2]; - -type DecimalArray5 decimal[3]; - -type DecimalArray6 decimal[4]; - -type BooleanArray boolean[]; - -type NillableBooleanArray boolean?[]; - -type NillableIntOrUnionBooleanArray (int|boolean?)[]; - -type BooleanArray2 boolean[2]; - -type BooleanArray3 boolean[3]; - -type BooleanArray4 boolean[]; - -type BooleanArray5 boolean[2]; - -type BooleanArray6 boolean[4]; - -type NilArray1 ()[]; - -type NilArray2 ()[2]; - -type NilArray3 ()[]; - -type NilArray4 ()[2]; - -type NilArray5 ()[3]; - -type NilArray6 ()[4]; - -type JsonArray1 json[]; - -type JsonArray2 json[2]; - -type JsonArray3 json[]; - -type JsonArray4 json[2]; - -type JsonArray5 json[3]; - -type JsonArray6 json[4]; - -type AnydataArray1 anydata[]; - -type AnydataArray2 anydata[2]; - -type AnydataArray3 anydata[]; - -type AnydataArray4 anydata[2]; - -type AnydataArray5 anydata[3]; - -type AnydataArray6 anydata[4]; - -type CustomArray1 CustomTuple2[]; - -type CustomArray2 CustomTuple2[2]; - -type CustomArray3 CustomTuple2[]; - -type CustomArray4 CustomTuple2[2]; - -type CustomArray5 CustomTuple2[3]; - -type CustomArray6 CustomTuple2[4]; - -type IntegerMap map; - -type StringMap map; - -type NillableIntUnionStringMap map; - -type IntUnionStringMap map; - -type DecimalMap map; - -type FloatMap map; - -type BooleanMap map; - -type NillableBooleanMap map; - -type NillableIntUnionBooleanMap map; - -type IntUnionBooleanMap map; - -type NilMap map<()>; - -type JsonMap map; - -type AnydataMap map; - -type CustomMap map; - -type BooleanRecord1Array BooleanRecord1[]; - -type ClosedBooleanRecord1Array BooleanRecord1[3]; - -type BooleanRecord2Array BooleanRecord2[]; - -type ClosedBooleanRecord2Array BooleanRecord2[3]; - -type BooleanRecord3Array BooleanRecord3[]; - -type ClosedBooleanRecord3Array BooleanRecord3[3]; - -type BooleanRecord4Array BooleanRecord4[]; - -type ClosedBooleanRecord4Array BooleanRecord4[3]; - -type BooleanRecord5Array BooleanRecord5[]; - -type ClosedBooleanRecord5Array BooleanRecord5[3]; - -type BooleanRecord6Array BooleanRecord6[]; - -type ClosedBooleanRecord6Array BooleanRecord6[3]; - -type BooleanRecord7Array BooleanRecord7[]; - -type ClosedBooleanRecord7Array BooleanRecord7[3]; - -type BooleanRecord8Array BooleanRecord8[]; - -type ClosedBooleanRecord8Array BooleanRecord8[3]; - -type BooleanRecord9Array BooleanRecord9[]; - -type ClosedBooleanRecord9Array BooleanRecord9[3]; - -type BooleanRecord10Array BooleanRecord10[]; - -type ClosedBooleanRecord10Array BooleanRecord10[3]; - -type BooleanRecord11Array BooleanRecord11[]; - -type ClosedBooleanRecord11Array BooleanRecord11[3]; - -type BooleanRecord12Array BooleanRecord12[]; - -type ClosedBooleanRecord12Array BooleanRecord12[3]; - -type BooleanRecord13Array BooleanRecord13[]; - -type ClosedBooleanRecord13Array BooleanRecord13[3]; - -type BooleanRecord14Array BooleanRecord14[]; - -type ClosedBooleanRecord14Array BooleanRecord14[3]; - -type BooleanRecord15Array BooleanRecord15[]; - -type ClosedBooleanRecord15Array BooleanRecord15[3]; - -type BooleanRecord16Array BooleanRecord16[]; - -type ClosedBooleanRecord16Array BooleanRecord16[3]; - -type BooleanRecord17Array BooleanRecord17[]; - -type ClosedBooleanRecord17Array BooleanRecord17[3]; - -type BooleanRecord18Array BooleanRecord18[]; - -type ClosedBooleanRecord18Array BooleanRecord18[3]; - -type NilRecord1Array NilRecord1[]; - -type ClosedNilRecord1Array NilRecord1[3]; - -type NilRecord2Array NilRecord2[]; - -type ClosedNilRecord2Array NilRecord2[3]; - -type NilRecord3Array NilRecord3[]; - -type ClosedNilRecord3Array NilRecord3[3]; - -type NilRecord4Array NilRecord4[]; - -type ClosedNilRecord4Array NilRecord4[3]; - -type NilRecord5Array NilRecord5[]; - -type ClosedNilRecord5Array NilRecord5[3]; - -type NilRecord6Array NilRecord6[]; - -type ClosedNilRecord6Array NilRecord6[3]; - -type NilRecord7Array NilRecord7[]; - -type ClosedNilRecord7Array NilRecord7[3]; - -type NilRecord8Array NilRecord8[]; - -type ClosedNilRecord8Array NilRecord8[3]; - -type NilRecord9Array NilRecord9[]; - -type ClosedNilRecord9Array NilRecord9[3]; - -type NilRecord10Array NilRecord10[]; - -type ClosedNilRecord10Array NilRecord10[3]; - -type NilRecord11Array NilRecord11[]; - -type ClosedNilRecord11Array NilRecord11[3]; - -type NilRecord12Array NilRecord12[]; - -type ClosedNilRecord12Array NilRecord12[3]; - -type NilRecord13Array NilRecord13[]; - -type ClosedNilRecord13Array NilRecord13[3]; - -type NilRecord14Array NilRecord14[]; - -type ClosedNilRecord14Array NilRecord14[3]; - -type IntegerRecord1Array IntegerRecord1[]; - -type ClosedIntegerRecord1Array IntegerRecord1[3]; - -type IntegerRecord2Array IntegerRecord2[]; - -type ClosedIntegerRecord2Array IntegerRecord2[3]; - -type IntegerRecord3Array IntegerRecord3[]; - -type ClosedIntegerRecord3Array IntegerRecord3[3]; - -type IntegerRecord4Array IntegerRecord4[]; - -type ClosedIntegerRecord4Array IntegerRecord4[3]; - -type IntegerRecord5Array IntegerRecord5[]; - -type ClosedIntegerRecord5Array IntegerRecord5[3]; - -type IntegerRecord6Array IntegerRecord6[]; - -type ClosedIntegerRecord6Array IntegerRecord6[3]; - -type IntegerRecord7Array IntegerRecord7[]; - -type ClosedIntegerRecord7Array IntegerRecord7[3]; - -type IntegerRecord8Array IntegerRecord8[]; - -type ClosedIntegerRecord8Array IntegerRecord8[3]; - -type IntegerRecord9Array IntegerRecord9[]; - -type ClosedIntegerRecord9Array IntegerRecord9[3]; - -type IntegerRecord10Array IntegerRecord10[]; - -type ClosedIntegerRecord10Array IntegerRecord10[3]; - -type IntegerRecord11Array IntegerRecord11[]; - -type ClosedIntegerRecord11Array IntegerRecord11[3]; - -type IntegerRecord12Array IntegerRecord12[]; - -type ClosedIntegerRecord12Array IntegerRecord12[3]; - -type IntegerRecord13Array IntegerRecord13[]; - -type ClosedIntegerRecord13Array IntegerRecord13[3]; - -type IntegerRecord14Array IntegerRecord14[]; - -type ClosedIntegerRecord14Array IntegerRecord14[3]; - -type FloatRecord1Array FloatRecord1[]; - -type ClosedFloatRecord1Array FloatRecord1[3]; - -type FloatRecord2Array FloatRecord2[]; - -type ClosedFloatRecord2Array FloatRecord2[3]; - -type FloatRecord3Array FloatRecord3[]; - -type ClosedFloatRecord3Array FloatRecord3[3]; - -type FloatRecord4Array FloatRecord4[]; - -type ClosedFloatRecord4Array FloatRecord4[3]; - -type FloatRecord5Array FloatRecord5[]; - -type ClosedFloatRecord5Array FloatRecord5[3]; - -type FloatRecord6Array FloatRecord6[]; - -type ClosedFloatRecord6Array FloatRecord6[3]; - -type FloatRecord7Array FloatRecord7[]; - -type ClosedFloatRecord7Array FloatRecord7[3]; - -type FloatRecord8Array FloatRecord8[]; - -type ClosedFloatRecord8Array FloatRecord8[3]; - -type FloatRecord9Array FloatRecord9[]; - -type ClosedFloatRecord9Array FloatRecord9[3]; - -type FloatRecord10Array FloatRecord10[]; - -type ClosedFloatRecord10Array FloatRecord10[3]; - -type FloatRecord11Array FloatRecord11[]; - -type ClosedFloatRecord11Array FloatRecord11[3]; - -type FloatRecord12Array FloatRecord12[]; - -type ClosedFloatRecord12Array FloatRecord12[3]; - -type FloatRecord13Array FloatRecord13[]; - -type ClosedFloatRecord13Array FloatRecord13[3]; - -type FloatRecord14Array FloatRecord14[]; - -type ClosedFloatRecord14Array FloatRecord14[3]; - -type DecimalRecord1Array DecimalRecord1[]; - -type ClosedDecimalRecord1Array DecimalRecord1[3]; - -type DecimalRecord2Array DecimalRecord2[]; - -type ClosedDecimalRecord2Array DecimalRecord2[3]; - -type DecimalRecord3Array DecimalRecord3[]; - -type ClosedDecimalRecord3Array DecimalRecord3[3]; - -type DecimalRecord4Array DecimalRecord4[]; - -type ClosedDecimalRecord4Array DecimalRecord4[3]; - -type DecimalRecord5Array DecimalRecord5[]; - -type ClosedDecimalRecord5Array DecimalRecord5[3]; - -type DecimalRecord6Array DecimalRecord6[]; - -type ClosedDecimalRecord6Array DecimalRecord6[3]; - -type DecimalRecord7Array DecimalRecord7[]; - -type ClosedDecimalRecord7Array DecimalRecord7[3]; - -type DecimalRecord8Array DecimalRecord8[]; - -type ClosedDecimalRecord8Array DecimalRecord8[3]; - -type DecimalRecord9Array DecimalRecord9[]; - -type ClosedDecimalRecord9Array DecimalRecord9[3]; - -type DecimalRecord10Array DecimalRecord10[]; - -type ClosedDecimalRecord10Array DecimalRecord10[3]; - -type DecimalRecord11Array DecimalRecord11[]; - -type ClosedDecimalRecord11Array DecimalRecord11[3]; - -type DecimalRecord12Array DecimalRecord12[]; - -type ClosedDecimalRecord12Array DecimalRecord12[3]; - -type DecimalRecord13Array DecimalRecord13[]; - -type ClosedDecimalRecord13Array DecimalRecord13[3]; - -type DecimalRecord14Array DecimalRecord14[]; - -type ClosedDecimalRecord14Array DecimalRecord14[3]; - -type StringRecord1Array StringRecord1[]; - -type ClosedStringRecord1Array StringRecord1[3]; - -type StringRecord2Array StringRecord2[]; - -type ClosedStringRecord2Array StringRecord2[3]; - -type StringRecord3Array StringRecord3[]; - -type ClosedStringRecord3Array StringRecord3[3]; - -type StringRecord4Array StringRecord4[]; - -type ClosedStringRecord4Array StringRecord4[3]; - -type StringRecord5Array StringRecord5[]; - -type ClosedStringRecord5Array StringRecord5[3]; - -type StringRecord6Array StringRecord6[]; - -type ClosedStringRecord6Array StringRecord6[3]; - -type StringRecord7Array StringRecord7[]; - -type ClosedStringRecord7Array StringRecord7[3]; - -type StringRecord8Array StringRecord8[]; - -type ClosedStringRecord8Array StringRecord8[3]; - -type StringRecord9Array StringRecord9[]; - -type ClosedStringRecord9Array StringRecord9[3]; - -type StringRecord10Array StringRecord10[]; - -type ClosedStringRecord10Array StringRecord10[3]; - -type StringRecord11Array StringRecord11[]; - -type ClosedStringRecord11Array StringRecord11[3]; - -type StringRecord12Array StringRecord12[]; - -type ClosedStringRecord12Array StringRecord12[3]; - -type StringRecord13Array StringRecord13[]; - -type ClosedStringRecord13Array StringRecord13[3]; - -type StringRecord14Array StringRecord14[]; - -type ClosedStringRecord14Array StringRecord14[3]; - -type StringRecord15Array StringRecord15[]; - -type StringRecord16Array StringRecord16[]; - -type StringRecord17Array StringRecord17[]; - -type StringRecord18Array StringRecord18[]; - -type StringRecord19Array StringRecord19[]; - -type StringRecord20Array StringRecord20[]; - -type StringRecord21Array StringRecord21[]; - -type StringRecord22Array StringRecord22[]; - -type StringRecord23Array StringRecord23[]; - -type JsonRecord1Array JsonRecord1[]; - -type ClosedJsonRecord1Array JsonRecord1[3]; - -type JsonRecord2Array JsonRecord2[]; - -type ClosedJsonRecord2Array JsonRecord2[3]; - -type JsonRecord3Array JsonRecord3[]; - -type ClosedJsonRecord3Array JsonRecord3[3]; - -type JsonRecord4Array JsonRecord4[]; - -type ClosedJsonRecord4Array JsonRecord4[3]; - -type JsonRecord5Array JsonRecord5[]; - -type ClosedJsonRecord5Array JsonRecord5[3]; - -type JsonRecord6Array JsonRecord6[]; - -type ClosedJsonRecord6Array JsonRecord6[3]; - -type JsonRecord7Array JsonRecord7[]; - -type ClosedJsonRecord7Array JsonRecord7[3]; - -type JsonRecord8Array JsonRecord8[]; - -type ClosedJsonRecord8Array JsonRecord8[3]; - -type JsonRecord9Array JsonRecord9[]; - -type ClosedJsonRecord9Array JsonRecord9[3]; - -type JsonRecord10Array JsonRecord10[]; - -type ClosedJsonRecord10Array JsonRecord10[3]; - -type JsonRecord11Array JsonRecord11[]; - -type ClosedJsonRecord11Array JsonRecord11[3]; - -type JsonRecord12Array JsonRecord12[]; - -type ClosedJsonRecord12Array JsonRecord12[3]; - -type JsonRecord13Array JsonRecord13[]; - -type ClosedJsonRecord13Array JsonRecord13[3]; - -type JsonRecord14Array JsonRecord14[]; - -type ClosedJsonRecord14Array JsonRecord14[3]; - -type AnydataRecord1Array AnydataRecord1[]; - -type ClosedAnydataRecord1Array AnydataRecord1[3]; - -type AnydataRecord2Array AnydataRecord2[]; - -type ClosedAnydataRecord2Array AnydataRecord2[3]; - -type AnydataRecord3Array AnydataRecord3[]; - -type ClosedAnydataRecord3Array AnydataRecord3[3]; - -type AnydataRecord4Array AnydataRecord4[]; - -type ClosedAnydataRecord4Array AnydataRecord4[3]; - -type AnydataRecord5Array AnydataRecord5[]; - -type ClosedAnydataRecord5Array AnydataRecord5[3]; - -type AnydataRecord6Array AnydataRecord6[]; - -type ClosedAnydataRecord6Array AnydataRecord6[3]; - -type AnydataRecord7Array AnydataRecord7[]; - -type ClosedAnydataRecord7Array AnydataRecord7[3]; - -type AnydataRecord8Array AnydataRecord8[]; - -type ClosedAnydataRecord8Array AnydataRecord8[3]; - -type AnydataRecord9Array AnydataRecord9[]; - -type ClosedAnydataRecord9Array AnydataRecord9[3]; - -type AnydataRecord10Array AnydataRecord10[]; - -type ClosedAnydataRecord10Array AnydataRecord10[3]; - -type AnydataRecord11Array AnydataRecord11[]; - -type ClosedAnydataRecord11Array AnydataRecord11[3]; - -type AnydataRecord12Array AnydataRecord12[]; - -type ClosedAnydataRecord12Array AnydataRecord12[3]; - -type AnydataRecord13Array AnydataRecord13[]; - -type ClosedAnydataRecord13Array AnydataRecord13[3]; - -type AnydataRecord14Array AnydataRecord14[]; - -type ClosedAnydataRecord14Array AnydataRecord14[3]; - -type CustomRecord1Array CustomRecord1[]; - -type ClosedCustomRecord1Array CustomRecord1[3]; - -type CustomRecord2Array CustomRecord2[]; - -type ClosedCustomRecord2Array CustomRecord2[3]; - -type CustomRecord3Array CustomRecord3[]; - -type ClosedCustomRecord3Array CustomRecord3[3]; - -type CustomRecord4Array CustomRecord4[]; - -type ClosedCustomRecord4Array CustomRecord4[3]; - -type CustomRecord5Array CustomRecord5[]; - -type ClosedCustomRecord5Array CustomRecord5[3]; - -type CustomRecord6Array CustomRecord6[]; - -type ClosedCustomRecord6Array CustomRecord6[3]; - -type CustomRecord7Array CustomRecord7[]; - -type ClosedCustomRecord7Array CustomRecord7[3]; - -type CustomRecord8Array CustomRecord8[]; - -type ClosedCustomRecord8Array CustomRecord8[3]; - -type CustomRecord9Array CustomRecord9[]; - -type ClosedCustomRecord9Array CustomRecord9[3]; - -type CustomRecord10Array CustomRecord10[]; - -type ClosedCustomRecord10Array CustomRecord10[3]; - -type CustomRecord11Array CustomRecord11[]; - -type ClosedCustomRecord11Array CustomRecord11[3]; - -type CustomRecord12Array CustomRecord12[]; - -type ClosedCustomRecord12Array CustomRecord12[3]; - -type CustomRecord13Array CustomRecord13[]; - -type ClosedCustomRecord13Array CustomRecord13[3]; - -type CustomRecord14Array CustomRecord14[]; - -type ClosedCustomRecord14Array CustomRecord14[3]; - -type CustomRecord15Array CustomRecord15[]; - -type CustomRecord16Array CustomRecord16[]; - -type CustomRecord17Array CustomRecord17[]; - -type CustomRecord18Array CustomRecord18[]; - -type CustomRecord19Array CustomRecord19[]; - -type CustomRecord20Array CustomRecord20[]; - -type CustomRecord21Array CustomRecord21[]; - -type CustomRecord22Array CustomRecord22[]; - -type CustomRecord23Array CustomRecord23[]; - -type CustomRecord24Array CustomRecord24[]; - -type CustomRecord25Array CustomRecord25[]; - -type CustomRecord26Array CustomRecord26[]; - -type CustomRecord27Array CustomRecord27[]; -type CustomRecord28Array CustomRecord28[]; -type CustomRecord29Array CustomRecord29[]; -type CustomRecord30Array CustomRecord30[]; -type CustomRecord31Array CustomRecord31[]; -type CustomRecord32Array CustomRecord32[]; -type CustomRecord33Array CustomRecord33[]; -type CustomRecord34Array CustomRecord34[]; -type CustomRecord35Array CustomRecord35[]; -type CustomRecord36Array CustomRecord36[]; -type CustomRecord37Array CustomRecord37[]; -type CustomRecord38Array CustomRecord38[]; -type CustomRecord39Array CustomRecord39[]; -type CustomRecord40Array CustomRecord40[]; -type CustomRecord41Array CustomRecord41[]; -type CustomRecord42Array CustomRecord42[]; -type CustomRecord43Array CustomRecord43[]; -type CustomRecord44Array CustomRecord44[]; -type CustomRecord45Array CustomRecord45[]; -type CustomRecord46Array CustomRecord46[]; -type CustomRecord47Array CustomRecord47[]; -type CustomRecord48Array CustomRecord48[]; -type CustomRecord49Array CustomRecord49[]; -type CustomRecord50Array CustomRecord50[]; -type CustomRecord51Array CustomRecord51[]; -type CustomRecord52Array CustomRecord52[]; -type CustomRecord53Array CustomRecord53[]; -type CustomRecord54Array CustomRecord54[]; -type CustomRecord55Array CustomRecord55[]; -type CustomRecord56Array CustomRecord56[]; +type NillableBooleanArray boolean?[]; +type NillableBooleanArrayArray NillableBooleanArray[]; +type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; +type StringArray1Array StringArray1[]; +type StringArray2Array StringArray2[]; +type JsonArray1Array JsonArray1[]; +type AnydataArray1Array AnydataArray1[]; type BooleanTuple1Array BooleanTuple1[]; - -type ClosedBooleanTuple1Array BooleanTuple1[3]; - type BooleanTuple2Array BooleanTuple2[]; - -type ClosedBooleanTuple2Array BooleanTuple2[3]; - type BooleanTuple3Array BooleanTuple3[]; - -type ClosedBooleanTuple3Array BooleanTuple3[3]; - type BooleanTuple4Array BooleanTuple4[]; - -type ClosedBooleanTuple4Array BooleanTuple4[3]; - type NillableBooleanTuple5Array NillableBooleanTuple5[]; - type NillableBooleanTuple6Array NillableBooleanTuple6[]; - type NillableBooleanTuple7Array NillableBooleanTuple7[]; - type NillableBooleanTuple8Array NillableBooleanTuple8[]; - type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; - -type NilTuple1Array NilTuple1[]; - -type ClosedNilTuple1Array NilTuple1[3]; - -type NilTuple2Array NilTuple2[]; - -type ClosedNilTuple2Array NilTuple2[3]; - -type NilTuple3Array NilTuple3[]; - -type ClosedNilTuple3Array NilTuple3[3]; - -type NilTuple4Array NilTuple4[]; - -type ClosedNilTuple4Array NilTuple4[3]; - -type IntegerTuple1Array IntegerTuple1[]; - -type ClosedIntegerTuple1Array IntegerTuple1[3]; - -type IntegerTuple2Array IntegerTuple2[]; - -type ClosedIntegerTuple2Array IntegerTuple2[3]; - -type IntegerTuple3Array IntegerTuple3[]; - -type ClosedIntegerTuple3Array IntegerTuple3[3]; - -type IntegerTuple4Array IntegerTuple4[]; - -type ClosedIntegerTuple4Array IntegerTuple4[3]; - -type FloatTuple1Array FloatTuple1[]; - -type ClosedFloatTuple1Array FloatTuple1[3]; - -type FloatTuple2Array FloatTuple2[]; - -type ClosedFloatTuple2Array FloatTuple2[3]; - -type FloatTuple3Array FloatTuple3[]; - -type ClosedFloatTuple3Array FloatTuple3[3]; - -type FloatTuple4Array FloatTuple4[]; - -type ClosedFloatTuple4Array FloatTuple4[3]; - -type DecimalTuple1Array DecimalTuple1[]; - -type ClosedDecimalTuple1Array DecimalTuple1[3]; - -type DecimalTuple2Array DecimalTuple2[]; - -type ClosedDecimalTuple2Array DecimalTuple2[3]; - -type DecimalTuple3Array DecimalTuple3[]; - -type ClosedDecimalTuple3Array DecimalTuple3[3]; - -type DecimalTuple4Array DecimalTuple4[]; - -type ClosedDecimalTuple4Array DecimalTuple4[3]; - -type StringTuple1Array StringTuple1[]; - -type ClosedStringTuple1Array StringTuple1[3]; - -type StringTuple2Array StringTuple2[]; - -type ClosedStringTuple2Array StringTuple2[3]; - -type StringTuple3Array StringTuple3[]; - -type ClosedStringTuple3Array StringTuple3[3]; - -type StringTuple4Array StringTuple4[]; - -type ClosedStringTuple4Array StringTuple4[3]; - -type AnydataTuple1Array AnydataTuple1[]; - -type ClosedAnydataTuple1Array AnydataTuple1[3]; - -type AnydataTuple2Array AnydataTuple2[]; - -type ClosedAnydataTuple2Array AnydataTuple2[3]; - -type AnydataTuple3Array AnydataTuple3[]; - -type ClosedAnydataTuple3Array AnydataTuple3[3]; - -type AnydataTuple4Array AnydataTuple4[]; - -type ClosedAnydataTuple4Array AnydataTuple4[3]; - -type JsonTuple1Array JsonTuple1[]; - -type ClosedJsonTuple1Array JsonTuple1[3]; - -type JsonTuple2Array JsonTuple2[]; - -type ClosedJsonTuple2Array JsonTuple2[3]; - -type JsonTuple3Array JsonTuple3[]; - -type ClosedJsonTuple3Array JsonTuple3[3]; - -type JsonTuple4Array JsonTuple4[]; - -type ClosedJsonTuple4Array JsonTuple4[3]; - -type CustomTuple1Array CustomTuple1[]; - -type ClosedCustomTuple1Array CustomTuple1[3]; - -type CustomTuple2Array CustomTuple2[]; - -type ClosedCustomTuple2Array CustomTuple2[3]; - -type CustomTuple3Array CustomTuple3[]; - -type ClosedCustomTuple3Array CustomTuple3[3]; - -type CustomTuple4Array CustomTuple4[]; - -type ClosedCustomTuple4Array CustomTuple4[3]; - -type CustomTuple5Array CustomTuple5[]; - -type ClosedCustomTuple5Array CustomTuple5[3]; - -type CustomTuple6Array CustomTuple6[]; - -type CustomTuple7Array CustomTuple7[]; - -type CustomTuple8Array CustomTuple8[]; - -type ClosedCustomTuple6Array CustomTuple6[3]; - -type IntegerArray1Array IntegerArray1[]; - -type ClosedIntegerArray1Array IntegerArray1[3]; - -type IntegerArray2Array IntegerArray2[]; - -type ClosedIntegerArray2Array IntegerArray2[3]; - -type IntegerArray3Array IntegerArray3[]; - -type ClosedIntegerArray3Array IntegerArray3[3]; - -type IntegerArray4Array IntegerArray4[]; - -type ClosedIntegerArray4Array IntegerArray4[3]; - -type IntegerArray5Array IntegerArray5[]; - -type ClosedIntegerArray5Array IntegerArray5[3]; - -type IntegerArray6Array IntegerArray5[]; - -type ClosedIntegerArray6Array IntegerArray5[3]; - -type StringArray1Array StringArray1[]; - -type StringArrayArray StringArray[]; - -type NillableStringArrayArray NillableStringArray[]; - -type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; - -type ClosedStringArray1Array StringArray1[3]; - -type StringArray2Array StringArray2[]; - -type ClosedStringArray2Array StringArray2[3]; - -type StringArray3Array StringArray3[]; - -type ClosedStringArray3Array StringArray3[3]; - -type StringArray4Array StringArray4[]; - -type ClosedStringArray4Array StringArray4[3]; - -type StringArray5Array StringArray5[]; - -type ClosedStringArray5Array StringArray5[3]; - -type StringArray6Array StringArray5[]; - -type ClosedStringArray6Array StringArray5[3]; - -type FloatArray1Array FloatArray1[]; - -type ClosedFloatArray1Array FloatArray1[3]; - -type FloatArray2Array FloatArray2[]; - -type ClosedFloatArray2Array FloatArray2[3]; - -type FloatArray3Array FloatArray3[]; - -type ClosedFloatArray3Array FloatArray3[3]; - -type FloatArray4Array FloatArray4[]; - -type ClosedFloatArray4Array FloatArray4[3]; - -type FloatArray5Array FloatArray5[]; - -type ClosedFloatArray5Array FloatArray5[3]; - -type FloatArray6Array FloatArray5[]; - -type ClosedFloatArray6Array FloatArray5[3]; - type DecimalArray1Array DecimalArray1[]; - -type ClosedDecimalArray1Array DecimalArray1[3]; - -type DecimalArray2Array DecimalArray2[]; - -type ClosedDecimalArray2Array DecimalArray2[3]; - -type DecimalArray3Array DecimalArray3[]; - -type ClosedDecimalArray3Array DecimalArray3[3]; - -type DecimalArray4Array DecimalArray4[]; - -type ClosedDecimalArray4Array DecimalArray4[3]; - -type DecimalArray5Array DecimalArray5[]; - -type ClosedDecimalArray5Array DecimalArray5[3]; - -type DecimalArray6Array DecimalArray5[]; - -type ClosedDecimalArray6Array DecimalArray5[3]; - -type BooleanArrayArray BooleanArray[]; - -type ClosedBooleanArrayArray BooleanArray[3]; - -type NillableBooleanArrayArray NillableBooleanArray[]; - -type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; - -type BooleanArray2Array BooleanArray2[]; - -type ClosedBooleanArray2Array BooleanArray2[3]; - -type BooleanArray3Array BooleanArray3[]; - -type ClosedBooleanArray3Array BooleanArray3[3]; - -type BooleanArray4Array BooleanArray4[]; - -type ClosedBooleanArray4Array BooleanArray4[3]; - -type BooleanArray5Array BooleanArray5[]; - -type ClosedBooleanArray5Array BooleanArray5[3]; - -type BooleanArray6Array BooleanArray5[]; - -type ClosedBooleanArray6Array BooleanArray5[3]; - -type NilArray1Array NilArray1[]; - -type ClosedNilArray1Array NilArray1[3]; - -type NilArray2Array NilArray2[]; - -type ClosedNilArray2Array NilArray2[3]; - -type NilArray3Array NilArray3[]; - -type ClosedNilArray3Array NilArray3[3]; - -type NilArray4Array NilArray4[]; - -type ClosedNilArray4Array NilArray4[3]; - -type NilArray5Array NilArray5[]; - -type ClosedNilArray5Array NilArray5[3]; - -type NilArray6Array NilArray5[]; - -type ClosedNilArray6Array NilArray5[3]; - -type JsonArray1Array JsonArray1[]; - -type ClosedJsonArray1Array JsonArray1[3]; - -type JsonArray2Array JsonArray2[]; - -type ClosedJsonArray2Array JsonArray2[3]; - -type JsonArray3Array JsonArray3[]; - -type ClosedJsonArray3Array JsonArray3[3]; - -type JsonArray4Array JsonArray4[]; - -type ClosedJsonArray4Array JsonArray4[3]; - -type JsonArray5Array JsonArray5[]; - -type ClosedJsonArray5Array JsonArray5[3]; - -type JsonArray6Array JsonArray5[]; - -type ClosedJsonArray6Array JsonArray5[3]; - -type AnydataArray1Array AnydataArray1[]; - -type ClosedAnydataArray1Array AnydataArray1[3]; - -type AnydataArray2Array AnydataArray2[]; - -type ClosedAnydataArray2Array AnydataArray2[3]; - -type AnydataArray3Array AnydataArray3[]; - -type ClosedAnydataArray3Array AnydataArray3[3]; - -type AnydataArray4Array AnydataArray4[]; - -type ClosedAnydataArray4Array AnydataArray4[3]; - -type AnydataArray5Array AnydataArray5[]; - -type ClosedAnydataArray5Array AnydataArray5[3]; - -type AnydataArray6Array AnydataArray5[]; - -type ClosedAnydataArray6Array AnydataArray5[3]; - -type CustomArray1Array CustomArray1[]; - -type ClosedCustomArray1Array CustomArray1[3]; - -type CustomArray2Array CustomArray2[]; - -type ClosedCustomArray2Array CustomArray2[3]; - -type CustomArray3Array CustomArray3[]; - -type ClosedCustomArray3Array CustomArray3[3]; - -type CustomArray4Array CustomArray4[]; - -type ClosedCustomArray4Array CustomArray4[3]; - -type CustomArray5Array CustomArray5[]; - -type ClosedCustomArray5Array CustomArray5[3]; - -type CustomArray6Array CustomArray5[]; - -type ClosedCustomArray6Array CustomArray5[3]; - -type IntegerMapArray IntegerMap[]; - -type ClosedIntegerMapArray IntegerMap[3]; - -type StringMapArray StringMap[]; - -type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; - -type IntUnionStringMapArray IntUnionStringMap[]; - -type ClosedStringMapArray StringMap[3]; - -type DecimalMapArray DecimalMap[]; - -type ClosedDecimalMapArray DecimalMap[3]; - -type FloatMapArray FloatMap[]; - -type ClosedFloatMapArray FloatMap[3]; - -type BooleanMapArray BooleanMap[]; - -type NillableBooleanMapArray NillableBooleanMap[]; - -type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; - -type IntUnionBooleanMapArray IntUnionBooleanMap[]; - -type ClosedBooleanMapArray BooleanMap[3]; - -type NilMapArray NilMap[]; - -type ClosedNilMapArray NilMap[3]; - -type JsonMapArray JsonMap[]; - -type ClosedJsonMapArray JsonMap[3]; - -type AnydataMapArray AnydataMap[]; - -type ClosedAnydataMapArray AnydataMap[3]; - -type CustomMapArray CustomMap[]; - -type ClosedCustomMapArray CustomMap[3]; diff --git a/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal index a9698aa..80cea06 100644 --- a/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal @@ -19,124 +19,6 @@ false b2 = false; boolean? b3 = (); boolean|int b4 = false; -() n1 = (); -int? n2 = (); -() n3 = null; - -int i1 = 1; -int i2 = -2; -int i3 = int:MAX_VALUE; -int i4 = int:MIN_VALUE; -int i5 = 0; -2 i6 = 2; -int? i7 = (); -int|string i8 = 100; - -float f1 = 2.234; -float f2 = -3.21f; -float f3 = 0; -float f4 = float:Infinity; -float f5 = -float:Infinity; -float f6 = float:NaN; -2.3f f7 = 2.3; -float? f8 = (); -float|decimal f9 = 1.21; - -decimal d1 = 2.234; -decimal d2 = -3.21d; -decimal d3 = 0; -2.3d d4 = 2.3; -decimal? d5 = (); -decimal|int d6 = 1.21; - -string s1 = "string"; -string s2 = ""; -string:Char s3 = "a"; - -map bm1 = {b1, b2}; -map bm2 = {b1, b2, b3, n1, n3}; -map bm3 = {b1, b2, b3, b4, i1}; -map<()> bm4 = {n1, n3}; -map bm5 = {b1, b2, b3, b4:true}; - -map m5 = {i1, i2, i3, i4, i5, i6}; -map m6 = {f1, f2, f3, f4, f5, f6, f7}; -map m7 = {d1, d2, d3, d4}; -map m8 = {d1, f1, f9, f10: 1.23}; -map m9 = {s1, s2, s3}; -map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; -map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; - -boolean[] arr1 = [b1, b2]; -boolean?[] arr2 = [b1, b2, b3, n1, n3]; -(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; -()[] arr4 = [n1, n3]; -int[] arr5 = [i1, i2, i3, i4, i5, i6]; -float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; -decimal[] arr7 = [d1, d2, d3, d4]; -(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; -string[] arr9 = [s1, s2, s3]; -anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; - -[boolean, boolean] bt1 = [b1, b2]; -[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; -[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; -[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; -[boolean...] bt5 = [b1, b2]; - -[string, string] st1 = [s1, s2]; -[string, string, string, string] st2 = [s1, s2, s3, s2]; -[string...] st3 = [s1, s2]; -[string, string, string...] st4 = [s1, s2, s3, s2]; - -[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; -[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; -[string?...] st7 = [s1, s2]; -[string...] st8 = []; -[string, string, string] st9 = [s1, s2, s3]; - -[(), ()] tup4 = [n1, n3]; -[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; -[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; -[string, string, string] tup9 = [s1, s2, s3]; -[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, - n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, json] tup11 = - [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, - f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 -]; - -[boolean, boolean...] restTup1 = [b1, b2]; -[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; -[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; -[(), ()...] restTup4 = [n1, n3]; -[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; -[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal...] restTup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; -[string...] restTup9 = [s1, s2, s3]; -[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 -]; - -var booleanRecordArray = [ - {b1, b2, b3, b4}, {b1, b2, b3, b4} -]; - -var booleanRecordArray2 = [ - {},{} -]; - string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 true,false,true,false true,false, true,false @@ -179,94 +61,3 @@ string csvStringWithBooleanValues6 = string `b2,b3 string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 ${b1},${b2},(),${b4} `; - -string csvStringData1 = string ` - a, b, c, d, e, f - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData2 = string ` - hello, hello, (), 12, true, 12.34 - // comment - - a, b, c, d, e, f - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData3 = string ` - a, b, c, d, e, f - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData4 = string ` - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData5 = string ` - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData6 = string ` - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData7 = string ` - a@ b@ c@ d@ e@ f - 1@ string@ true@ 2.234@ -3.21@ () - 2@ s,tring@ true@ 2.234@ -3.21@ null - 3@ stri,ng@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; -string csvStringData8 = string ` - a@ b@ c@ d@ e@ f - - - - 1@ stri,ng@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ ()@-3.21 - 3@ string@ true@ 2.234@ -3.21@ null - - 4@ s,tring@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; - -string csvStringData9 = string ` - - 1@ string@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ -3.21@ null - - 3@ string@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ ()@-3.21 - - 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina-tests/parse-string-record-types-tests/tests/types.bal b/ballerina-tests/parse-string-record-types-tests/tests/types.bal index b496d60..6c50a58 100644 --- a/ballerina-tests/parse-string-record-types-tests/tests/types.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/types.bal @@ -126,2402 +126,97 @@ type BooleanRecord18 record {| int?...; |}; -type NilRecord1 record { - () n1; - () n2; - () n3; -}; - -type NilRecord2 record {| - () n1; - () n2; - () n3; -|}; - -type NilRecord3 record {| - () n1; - () n4; -|}; - -type NilRecord4 record { - () n1; - () n4; -}; - -type NilRecord5 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -}; - -type NilRecord6 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type NilRecord7 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type NilRecord8 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type NilRecord9 record {| - () n1; - () n2; - ()...; -|}; - -type NilRecord10 record {| - ()...; -|}; - -type NilRecord11 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord12 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type NilRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type IntegerRecord1 record { - int i1; - int i2; - int i3; - int? i4; - int? i5; - int i6; - int i7; - int? i8; -}; - -type IntegerRecord2 record {| - int i1; - int? i2; - int i3; - int i4; - int? i5; - int i6; - int i7; - int? i8; -|}; - -type IntegerRecord3 record {| - int i1; - int i4; - int i6; -|}; - -type IntegerRecord4 record { - int i1; - int i4; - int i6; -}; - -type IntegerRecord5 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -}; - -type IntegerRecord6 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -|}; - -type IntegerRecord7 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type IntegerRecord8 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type IntegerRecord9 record {| - int i1; - int i2; - int...; -|}; - -type IntegerRecord10 record {| - int...; -|}; - -type IntegerRecord11 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord12 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type IntegerRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type FloatRecord1 record { - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -}; - -type FloatRecord2 record {| - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -|}; - -type FloatRecord3 record {| - float f1; - float f4; - float f7; -|}; - -type FloatRecord4 record { - float f1; - float f4; - float f7; -}; - -type FloatRecord5 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -}; - -type FloatRecord6 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type FloatRecord7 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type FloatRecord8 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type FloatRecord9 record {| - float f1; - float f2; - float...; -|}; - -type FloatRecord10 record {| - float...; -|}; - -type FloatRecord11 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord12 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type FloatRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type DecimalRecord1 record { - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -}; - -type DecimalRecord2 record {| - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -|}; - -type DecimalRecord3 record {| - decimal d1; - decimal d4; - decimal d7; -|}; - -type DecimalRecord4 record { - decimal d1; - decimal d4; - decimal d7; -}; - -type DecimalRecord5 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -}; - -type DecimalRecord6 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type DecimalRecord7 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type DecimalRecord8 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type DecimalRecord9 record {| - decimal d1; - decimal d2; - decimal...; -|}; - -type DecimalRecord10 record {| - decimal...; -|}; - -type DecimalRecord11 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord12 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type DecimalRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type StringRecord1 record { - string s1; - string s2; - string s3; -}; - -type StringRecord2 record {| - string s1; - string s2; - string s3; -|}; - -type StringRecord3 record {| - string s1; - string s4; -|}; - -type StringRecord4 record { - string s1; - string s4; -}; - -type StringRecord5 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -}; - -type StringRecord6 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type StringRecord7 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type StringRecord8 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type StringRecord9 record {| - string s1; - string s2; - string...; -|}; - -type StringRecord10 record {| - string...; -|}; - -type StringRecord11 record {| - string s1; - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord12 record {| - string d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord15 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord16 record {| - string?...; -|}; - -type StringRecord17 record {| - int...; -|}; - -type StringRecord18 record {| - string b2; - int?...; -|}; - -type StringRecord19 record { - string s1 = ""; - string s2 = ""; -}; - -type StringRecord20 record {| - string s1 = ""; - string s2 = ""; -|}; - -type StringRecord21 record { -}; - -type StringRecord22 record {| - string s1 = ""; - string s2 = ""; - json...; -|}; - -type StringRecord23 record {| - json...; -|}; - -type JsonRecord1 record { - json j1; - json j2; - json j3; -}; - -type JsonRecord2 record {| - json j1; - json j2; - json j3; -|}; - -type JsonRecord3 record {| - json j1; - json j4; -|}; - -type JsonRecord4 record { - json j1; - json j4; -}; - -type JsonRecord5 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -}; - -type JsonRecord6 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -|}; - -type JsonRecord7 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -}; - -type JsonRecord8 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -|}; - -type JsonRecord9 record {| - json j1; - json j2; - json...; -|}; - -type JsonRecord10 record {| - json...; -|}; - -type JsonRecord11 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord12 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type JsonRecord13 record {| - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord14 record {| - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type AnydataRecord1 record { - anydata anydata1; - anydata anydata2; - anydata anydata3; -}; - -type AnydataRecord2 record {| - anydata anydata1; - anydata anydata2; - anydata anydata3; -|}; - -type AnydataRecord3 record {| - anydata anydata1; - anydata anydata4; -|}; - -type AnydataRecord4 record { - anydata anydata1; - anydata anydata4; -}; - -type AnydataRecord5 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -}; - -type AnydataRecord6 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type AnydataRecord7 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type AnydataRecord8 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type AnydataRecord9 record {| - anydata anydata1; - anydata anydata2; - anydata...; -|}; - -type AnydataRecord10 record {| - anydata...; -|}; - -type AnydataRecord11 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord12 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type AnydataRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type CustomRecord1 record { - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -}; - -type CustomRecord2 record {| - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -|}; - -type CustomRecord3 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -|}; - -type CustomRecord4 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -}; - -type CustomRecord5 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string defaultableField = ""; - string? nillableField = (); -}; - -type CustomRecord6 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type CustomRecord7 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type CustomRecord8 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type CustomRecord9 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string...; -|}; - -type CustomRecord10 record {| - string...; -|}; - -type CustomRecord11 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord12 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord15 record {| - string '1; - string '2; -|}; - -type CustomRecord16 record {| - string '1; - string '2; - string '3; - string '4; -|}; - -type CustomRecord17 record { - string '1; - string '2; -}; - -type CustomRecord18 record { - string '1; - string '2; - string '3; - string '4; -}; - -type CustomRecord19 record { - string '1; - string '2; - string '3 = ""; - string '4 = ""; -}; - -type CustomRecord20 record { - string '1; -}; - -type CustomRecord21 record {| - string '1; - json...; -|}; - -type CustomRecord22 record {| - string '1; - string...; -|}; - -type CustomRecord23 record {| - string '1; - string a = ""; - string...; -|}; - -type CustomRecord24 record {| - string '1; - string '2 = ""; - string...; -|}; - -type CustomRecord25 record {| - int '1; - string...; -|}; - -type CustomRecord26 record {| - string '1; - int...; -|}; - -type CustomRecord27 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata a1; - json j1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord28 record { - string '1; -}; - -type CustomRecord29 record { - int '1; -}; - -type CustomRecord30 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord31 record {| - string '1; - string '6; -|}; - -type CustomRecord32 record {| - int '1; -|}; - -type CustomRecord33 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord34 record { - string '1; - string '6; - string '5 = ""; -}; - -type CustomRecord35 record { - string '1; - string '6; - string '9 = ""; -}; - -type CustomRecord36 record {| - string '1; - string '6; - string '9 = ""; -|}; - -type CustomRecord37 record {| - string '1; - string '6; - string '5 = ""; -|}; - -type CustomRecord38 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - string ...; -|}; - -type CustomRecord39 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - json ...; -|}; - -type CustomRecord40 record {| - string '5; - string '6; - json ...; -|}; - -type CustomRecord41 record {| - json ...; -|}; - -type CustomRecord42 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -|}; - -type CustomRecord43 record { - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -}; - -type CustomRecord44 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; - string ...; -|}; - -type CustomRecord45 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -|}; - -type CustomRecord46 record { - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -}; - -type CustomRecord47 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; - string ...; -|}; - -type CustomRecord48 record { - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -}; - -type CustomRecord49 record {| - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -|}; - -type CustomRecord50 record { - int H1; - float H4; -}; - -type CustomRecord51 record {| - int H1; - float H4; -|}; - -type CustomRecord52 record {| - string H1; - string H4; - string ...; -|}; - -type CustomRecord53 record {| - int H1; - float H4; - decimal ...; -|}; - -type CustomRecord54 record {| - string H1 = ""; - string H4; - string '1; -|}; - -type CustomRecord55 record {| - string H1 = ""; - string H4 = ""; - int '1 = 10; -|}; - -type CustomRecord56 record { - string H1 = ""; - string H4 = ""; - anydata '1 = 10; -}; - -type BooleanTuple1 [boolean, boolean, boolean, boolean]; - -type BooleanTuple2 [boolean, boolean]; - -type BooleanTuple3 [boolean, boolean...]; - -type BooleanTuple4 [boolean...]; - -type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; - -type NillableBooleanTuple6 [boolean?, boolean?]; - -type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; - -type NillableBooleanTuple8 [boolean?...]; - -type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; - -type NilTuple1 [(), (), ()]; - -type NilTuple2 [(), ()]; - -type NilTuple3 [(), ()...]; - -type NilTuple4 [()...]; - -type IntegerTuple1 [int, int, int, int, int, int]; - -type IntegerTuple2 [int, int]; - -type IntegerTuple3 [int, int...]; - -type IntegerTuple4 [int...]; - -type FloatTuple1 [float, float, float, float, float, float, float]; - -type FloatTuple2 [float, float]; - -type FloatTuple3 [float, float...]; - -type FloatTuple4 [float...]; - -type DecimalTuple1 [decimal, decimal, decimal, decimal]; - -type DecimalTuple2 [decimal, decimal]; - -type DecimalTuple3 [decimal, decimal...]; - -type DecimalTuple4 [decimal...]; - -type StringTuple1 [string, string, string, string]; - -type StringTuple2 [string, string]; - -type StringTuple3 [string, string...]; - -type StringTuple4 [string...]; - -type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata]; - -type AnydataTuple2 [anydata, anydata]; - -type AnydataTuple3 [anydata, anydata...]; - -type AnydataTuple4 [anydata...]; - -type JsonTuple1 [json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json]; - -type JsonTuple2 [json, json]; - -type JsonTuple3 [json, json...]; - -type JsonTuple4 [json...]; - -type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; - -type CustomTuple4 [string...]; - -type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; - -type CustomTuple6 [anydata...]; - -type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; - -type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; - -type IntegerArray1 int[]; - -type IntegerArray2 int[2]; - -type IntegerArray3 int[]; - -type IntegerArray4 int[2]; - -type IntegerArray5 int[3]; - -type IntegerArray6 int[4]; - -type StringArray string[]; - -type NillableStringArray string?[]; - -type NillableIntOrUnionStringArray (int|string?)[]; - -type StringArray1 string[]; - -type StringArray2 string[2]; - -type StringArray3 string[]; - -type StringArray4 string[2]; - -type StringArray5 string[3]; - -type StringArray6 string[4]; - -type FloatArray1 float[]; - -type FloatArray2 float[2]; - -type FloatArray3 float[]; - -type FloatArray4 float[2]; - -type FloatArray5 float[3]; - -type FloatArray6 float[4]; - -type DecimalArray1 decimal[]; - -type DecimalArray2 decimal[2]; - -type DecimalArray3 decimal[]; - -type DecimalArray4 decimal[2]; - -type DecimalArray5 decimal[3]; - -type DecimalArray6 decimal[4]; - -type BooleanArray boolean[]; - -type NillableBooleanArray boolean?[]; - -type NillableIntOrUnionBooleanArray (int|boolean?)[]; - -type BooleanArray2 boolean[2]; - -type BooleanArray3 boolean[3]; - -type BooleanArray4 boolean[]; - -type BooleanArray5 boolean[2]; - -type BooleanArray6 boolean[4]; - -type NilArray1 ()[]; - -type NilArray2 ()[2]; - -type NilArray3 ()[]; - -type NilArray4 ()[2]; - -type NilArray5 ()[3]; - -type NilArray6 ()[4]; - -type JsonArray1 json[]; - -type JsonArray2 json[2]; - -type JsonArray3 json[]; - -type JsonArray4 json[2]; - -type JsonArray5 json[3]; - -type JsonArray6 json[4]; - -type AnydataArray1 anydata[]; - -type AnydataArray2 anydata[2]; - -type AnydataArray3 anydata[]; - -type AnydataArray4 anydata[2]; - -type AnydataArray5 anydata[3]; - -type AnydataArray6 anydata[4]; - -type CustomArray1 CustomTuple2[]; - -type CustomArray2 CustomTuple2[2]; - -type CustomArray3 CustomTuple2[]; - -type CustomArray4 CustomTuple2[2]; - -type CustomArray5 CustomTuple2[3]; - -type CustomArray6 CustomTuple2[4]; - -type IntegerMap map; - -type StringMap map; - -type NillableIntUnionStringMap map; - -type IntUnionStringMap map; - -type DecimalMap map; - -type FloatMap map; - -type BooleanMap map; - -type NillableBooleanMap map; - -type NillableIntUnionBooleanMap map; - -type IntUnionBooleanMap map; - -type NilMap map<()>; - -type JsonMap map; - -type AnydataMap map; - -type CustomMap map; - -type BooleanRecord1Array BooleanRecord1[]; - -type ClosedBooleanRecord1Array BooleanRecord1[3]; - -type BooleanRecord2Array BooleanRecord2[]; - -type ClosedBooleanRecord2Array BooleanRecord2[3]; - -type BooleanRecord3Array BooleanRecord3[]; - -type ClosedBooleanRecord3Array BooleanRecord3[3]; - -type BooleanRecord4Array BooleanRecord4[]; - -type ClosedBooleanRecord4Array BooleanRecord4[3]; - -type BooleanRecord5Array BooleanRecord5[]; - -type ClosedBooleanRecord5Array BooleanRecord5[3]; - -type BooleanRecord6Array BooleanRecord6[]; - -type ClosedBooleanRecord6Array BooleanRecord6[3]; - -type BooleanRecord7Array BooleanRecord7[]; - -type ClosedBooleanRecord7Array BooleanRecord7[3]; - -type BooleanRecord8Array BooleanRecord8[]; - -type ClosedBooleanRecord8Array BooleanRecord8[3]; - -type BooleanRecord9Array BooleanRecord9[]; - -type ClosedBooleanRecord9Array BooleanRecord9[3]; - -type BooleanRecord10Array BooleanRecord10[]; - -type ClosedBooleanRecord10Array BooleanRecord10[3]; - -type BooleanRecord11Array BooleanRecord11[]; - -type ClosedBooleanRecord11Array BooleanRecord11[3]; - -type BooleanRecord12Array BooleanRecord12[]; - -type ClosedBooleanRecord12Array BooleanRecord12[3]; - -type BooleanRecord13Array BooleanRecord13[]; - -type ClosedBooleanRecord13Array BooleanRecord13[3]; - -type BooleanRecord14Array BooleanRecord14[]; - -type ClosedBooleanRecord14Array BooleanRecord14[3]; - -type BooleanRecord15Array BooleanRecord15[]; - -type ClosedBooleanRecord15Array BooleanRecord15[3]; - -type BooleanRecord16Array BooleanRecord16[]; - -type ClosedBooleanRecord16Array BooleanRecord16[3]; - -type BooleanRecord17Array BooleanRecord17[]; - -type ClosedBooleanRecord17Array BooleanRecord17[3]; - -type BooleanRecord18Array BooleanRecord18[]; - -type ClosedBooleanRecord18Array BooleanRecord18[3]; - -type NilRecord1Array NilRecord1[]; - -type ClosedNilRecord1Array NilRecord1[3]; - -type NilRecord2Array NilRecord2[]; - -type ClosedNilRecord2Array NilRecord2[3]; - -type NilRecord3Array NilRecord3[]; - -type ClosedNilRecord3Array NilRecord3[3]; - -type NilRecord4Array NilRecord4[]; - -type ClosedNilRecord4Array NilRecord4[3]; - -type NilRecord5Array NilRecord5[]; - -type ClosedNilRecord5Array NilRecord5[3]; - -type NilRecord6Array NilRecord6[]; - -type ClosedNilRecord6Array NilRecord6[3]; - -type NilRecord7Array NilRecord7[]; - -type ClosedNilRecord7Array NilRecord7[3]; - -type NilRecord8Array NilRecord8[]; - -type ClosedNilRecord8Array NilRecord8[3]; - -type NilRecord9Array NilRecord9[]; - -type ClosedNilRecord9Array NilRecord9[3]; - -type NilRecord10Array NilRecord10[]; - -type ClosedNilRecord10Array NilRecord10[3]; - -type NilRecord11Array NilRecord11[]; - -type ClosedNilRecord11Array NilRecord11[3]; - -type NilRecord12Array NilRecord12[]; - -type ClosedNilRecord12Array NilRecord12[3]; - -type NilRecord13Array NilRecord13[]; - -type ClosedNilRecord13Array NilRecord13[3]; - -type NilRecord14Array NilRecord14[]; - -type ClosedNilRecord14Array NilRecord14[3]; - -type IntegerRecord1Array IntegerRecord1[]; - -type ClosedIntegerRecord1Array IntegerRecord1[3]; - -type IntegerRecord2Array IntegerRecord2[]; - -type ClosedIntegerRecord2Array IntegerRecord2[3]; - -type IntegerRecord3Array IntegerRecord3[]; - -type ClosedIntegerRecord3Array IntegerRecord3[3]; - -type IntegerRecord4Array IntegerRecord4[]; - -type ClosedIntegerRecord4Array IntegerRecord4[3]; - -type IntegerRecord5Array IntegerRecord5[]; - -type ClosedIntegerRecord5Array IntegerRecord5[3]; - -type IntegerRecord6Array IntegerRecord6[]; - -type ClosedIntegerRecord6Array IntegerRecord6[3]; - -type IntegerRecord7Array IntegerRecord7[]; - -type ClosedIntegerRecord7Array IntegerRecord7[3]; - -type IntegerRecord8Array IntegerRecord8[]; - -type ClosedIntegerRecord8Array IntegerRecord8[3]; - -type IntegerRecord9Array IntegerRecord9[]; - -type ClosedIntegerRecord9Array IntegerRecord9[3]; - -type IntegerRecord10Array IntegerRecord10[]; - -type ClosedIntegerRecord10Array IntegerRecord10[3]; - -type IntegerRecord11Array IntegerRecord11[]; - -type ClosedIntegerRecord11Array IntegerRecord11[3]; - -type IntegerRecord12Array IntegerRecord12[]; - -type ClosedIntegerRecord12Array IntegerRecord12[3]; - -type IntegerRecord13Array IntegerRecord13[]; - -type ClosedIntegerRecord13Array IntegerRecord13[3]; - -type IntegerRecord14Array IntegerRecord14[]; - -type ClosedIntegerRecord14Array IntegerRecord14[3]; - -type FloatRecord1Array FloatRecord1[]; - -type ClosedFloatRecord1Array FloatRecord1[3]; - -type FloatRecord2Array FloatRecord2[]; - -type ClosedFloatRecord2Array FloatRecord2[3]; - -type FloatRecord3Array FloatRecord3[]; - -type ClosedFloatRecord3Array FloatRecord3[3]; - -type FloatRecord4Array FloatRecord4[]; - -type ClosedFloatRecord4Array FloatRecord4[3]; - -type FloatRecord5Array FloatRecord5[]; - -type ClosedFloatRecord5Array FloatRecord5[3]; - -type FloatRecord6Array FloatRecord6[]; - -type ClosedFloatRecord6Array FloatRecord6[3]; - -type FloatRecord7Array FloatRecord7[]; - -type ClosedFloatRecord7Array FloatRecord7[3]; - -type FloatRecord8Array FloatRecord8[]; - -type ClosedFloatRecord8Array FloatRecord8[3]; - -type FloatRecord9Array FloatRecord9[]; - -type ClosedFloatRecord9Array FloatRecord9[3]; - -type FloatRecord10Array FloatRecord10[]; - -type ClosedFloatRecord10Array FloatRecord10[3]; - -type FloatRecord11Array FloatRecord11[]; - -type ClosedFloatRecord11Array FloatRecord11[3]; - -type FloatRecord12Array FloatRecord12[]; - -type ClosedFloatRecord12Array FloatRecord12[3]; - -type FloatRecord13Array FloatRecord13[]; - -type ClosedFloatRecord13Array FloatRecord13[3]; - -type FloatRecord14Array FloatRecord14[]; - -type ClosedFloatRecord14Array FloatRecord14[3]; - -type DecimalRecord1Array DecimalRecord1[]; - -type ClosedDecimalRecord1Array DecimalRecord1[3]; - -type DecimalRecord2Array DecimalRecord2[]; - -type ClosedDecimalRecord2Array DecimalRecord2[3]; - -type DecimalRecord3Array DecimalRecord3[]; - -type ClosedDecimalRecord3Array DecimalRecord3[3]; - -type DecimalRecord4Array DecimalRecord4[]; - -type ClosedDecimalRecord4Array DecimalRecord4[3]; - -type DecimalRecord5Array DecimalRecord5[]; - -type ClosedDecimalRecord5Array DecimalRecord5[3]; - -type DecimalRecord6Array DecimalRecord6[]; - -type ClosedDecimalRecord6Array DecimalRecord6[3]; - -type DecimalRecord7Array DecimalRecord7[]; - -type ClosedDecimalRecord7Array DecimalRecord7[3]; - -type DecimalRecord8Array DecimalRecord8[]; - -type ClosedDecimalRecord8Array DecimalRecord8[3]; - -type DecimalRecord9Array DecimalRecord9[]; - -type ClosedDecimalRecord9Array DecimalRecord9[3]; - -type DecimalRecord10Array DecimalRecord10[]; - -type ClosedDecimalRecord10Array DecimalRecord10[3]; - -type DecimalRecord11Array DecimalRecord11[]; - -type ClosedDecimalRecord11Array DecimalRecord11[3]; - -type DecimalRecord12Array DecimalRecord12[]; - -type ClosedDecimalRecord12Array DecimalRecord12[3]; - -type DecimalRecord13Array DecimalRecord13[]; - -type ClosedDecimalRecord13Array DecimalRecord13[3]; - -type DecimalRecord14Array DecimalRecord14[]; - -type ClosedDecimalRecord14Array DecimalRecord14[3]; - -type StringRecord1Array StringRecord1[]; - -type ClosedStringRecord1Array StringRecord1[3]; - -type StringRecord2Array StringRecord2[]; - -type ClosedStringRecord2Array StringRecord2[3]; - -type StringRecord3Array StringRecord3[]; - -type ClosedStringRecord3Array StringRecord3[3]; - -type StringRecord4Array StringRecord4[]; - -type ClosedStringRecord4Array StringRecord4[3]; - -type StringRecord5Array StringRecord5[]; - -type ClosedStringRecord5Array StringRecord5[3]; - -type StringRecord6Array StringRecord6[]; - -type ClosedStringRecord6Array StringRecord6[3]; - -type StringRecord7Array StringRecord7[]; - -type ClosedStringRecord7Array StringRecord7[3]; - -type StringRecord8Array StringRecord8[]; - -type ClosedStringRecord8Array StringRecord8[3]; - -type StringRecord9Array StringRecord9[]; - -type ClosedStringRecord9Array StringRecord9[3]; - -type StringRecord10Array StringRecord10[]; - -type ClosedStringRecord10Array StringRecord10[3]; - -type StringRecord11Array StringRecord11[]; - -type ClosedStringRecord11Array StringRecord11[3]; - -type StringRecord12Array StringRecord12[]; - -type ClosedStringRecord12Array StringRecord12[3]; - -type StringRecord13Array StringRecord13[]; - -type ClosedStringRecord13Array StringRecord13[3]; - -type StringRecord14Array StringRecord14[]; - -type ClosedStringRecord14Array StringRecord14[3]; - -type StringRecord15Array StringRecord15[]; - -type StringRecord16Array StringRecord16[]; - -type StringRecord17Array StringRecord17[]; - -type StringRecord18Array StringRecord18[]; - -type StringRecord19Array StringRecord19[]; - -type StringRecord20Array StringRecord20[]; - -type StringRecord21Array StringRecord21[]; - -type StringRecord22Array StringRecord22[]; - -type StringRecord23Array StringRecord23[]; - -type JsonRecord1Array JsonRecord1[]; - -type ClosedJsonRecord1Array JsonRecord1[3]; - -type JsonRecord2Array JsonRecord2[]; - -type ClosedJsonRecord2Array JsonRecord2[3]; - -type JsonRecord3Array JsonRecord3[]; - -type ClosedJsonRecord3Array JsonRecord3[3]; - -type JsonRecord4Array JsonRecord4[]; - -type ClosedJsonRecord4Array JsonRecord4[3]; - -type JsonRecord5Array JsonRecord5[]; - -type ClosedJsonRecord5Array JsonRecord5[3]; - -type JsonRecord6Array JsonRecord6[]; - -type ClosedJsonRecord6Array JsonRecord6[3]; - -type JsonRecord7Array JsonRecord7[]; - -type ClosedJsonRecord7Array JsonRecord7[3]; - -type JsonRecord8Array JsonRecord8[]; - -type ClosedJsonRecord8Array JsonRecord8[3]; - -type JsonRecord9Array JsonRecord9[]; - -type ClosedJsonRecord9Array JsonRecord9[3]; - -type JsonRecord10Array JsonRecord10[]; - -type ClosedJsonRecord10Array JsonRecord10[3]; - -type JsonRecord11Array JsonRecord11[]; - -type ClosedJsonRecord11Array JsonRecord11[3]; - -type JsonRecord12Array JsonRecord12[]; - -type ClosedJsonRecord12Array JsonRecord12[3]; - -type JsonRecord13Array JsonRecord13[]; - -type ClosedJsonRecord13Array JsonRecord13[3]; - -type JsonRecord14Array JsonRecord14[]; - -type ClosedJsonRecord14Array JsonRecord14[3]; - -type AnydataRecord1Array AnydataRecord1[]; - -type ClosedAnydataRecord1Array AnydataRecord1[3]; - -type AnydataRecord2Array AnydataRecord2[]; - -type ClosedAnydataRecord2Array AnydataRecord2[3]; - -type AnydataRecord3Array AnydataRecord3[]; - -type ClosedAnydataRecord3Array AnydataRecord3[3]; - -type AnydataRecord4Array AnydataRecord4[]; - -type ClosedAnydataRecord4Array AnydataRecord4[3]; - -type AnydataRecord5Array AnydataRecord5[]; - -type ClosedAnydataRecord5Array AnydataRecord5[3]; - -type AnydataRecord6Array AnydataRecord6[]; - -type ClosedAnydataRecord6Array AnydataRecord6[3]; - -type AnydataRecord7Array AnydataRecord7[]; - -type ClosedAnydataRecord7Array AnydataRecord7[3]; - -type AnydataRecord8Array AnydataRecord8[]; - -type ClosedAnydataRecord8Array AnydataRecord8[3]; - -type AnydataRecord9Array AnydataRecord9[]; - -type ClosedAnydataRecord9Array AnydataRecord9[3]; - -type AnydataRecord10Array AnydataRecord10[]; - -type ClosedAnydataRecord10Array AnydataRecord10[3]; - -type AnydataRecord11Array AnydataRecord11[]; - -type ClosedAnydataRecord11Array AnydataRecord11[3]; - -type AnydataRecord12Array AnydataRecord12[]; - -type ClosedAnydataRecord12Array AnydataRecord12[3]; - -type AnydataRecord13Array AnydataRecord13[]; - -type ClosedAnydataRecord13Array AnydataRecord13[3]; - -type AnydataRecord14Array AnydataRecord14[]; - -type ClosedAnydataRecord14Array AnydataRecord14[3]; - -type CustomRecord1Array CustomRecord1[]; - -type ClosedCustomRecord1Array CustomRecord1[3]; - -type CustomRecord2Array CustomRecord2[]; - -type ClosedCustomRecord2Array CustomRecord2[3]; - -type CustomRecord3Array CustomRecord3[]; - -type ClosedCustomRecord3Array CustomRecord3[3]; - -type CustomRecord4Array CustomRecord4[]; - -type ClosedCustomRecord4Array CustomRecord4[3]; - -type CustomRecord5Array CustomRecord5[]; - -type ClosedCustomRecord5Array CustomRecord5[3]; - -type CustomRecord6Array CustomRecord6[]; - -type ClosedCustomRecord6Array CustomRecord6[3]; - -type CustomRecord7Array CustomRecord7[]; - -type ClosedCustomRecord7Array CustomRecord7[3]; - -type CustomRecord8Array CustomRecord8[]; - -type ClosedCustomRecord8Array CustomRecord8[3]; - -type CustomRecord9Array CustomRecord9[]; - -type ClosedCustomRecord9Array CustomRecord9[3]; - -type CustomRecord10Array CustomRecord10[]; - -type ClosedCustomRecord10Array CustomRecord10[3]; - -type CustomRecord11Array CustomRecord11[]; - -type ClosedCustomRecord11Array CustomRecord11[3]; - -type CustomRecord12Array CustomRecord12[]; - -type ClosedCustomRecord12Array CustomRecord12[3]; - -type CustomRecord13Array CustomRecord13[]; - -type ClosedCustomRecord13Array CustomRecord13[3]; - -type CustomRecord14Array CustomRecord14[]; - -type ClosedCustomRecord14Array CustomRecord14[3]; - -type CustomRecord15Array CustomRecord15[]; - -type CustomRecord16Array CustomRecord16[]; - -type CustomRecord17Array CustomRecord17[]; - -type CustomRecord18Array CustomRecord18[]; - -type CustomRecord19Array CustomRecord19[]; - -type CustomRecord20Array CustomRecord20[]; - -type CustomRecord21Array CustomRecord21[]; - -type CustomRecord22Array CustomRecord22[]; - -type CustomRecord23Array CustomRecord23[]; - -type CustomRecord24Array CustomRecord24[]; - -type CustomRecord25Array CustomRecord25[]; - -type CustomRecord26Array CustomRecord26[]; - -type CustomRecord27Array CustomRecord27[]; -type CustomRecord28Array CustomRecord28[]; -type CustomRecord29Array CustomRecord29[]; -type CustomRecord30Array CustomRecord30[]; -type CustomRecord31Array CustomRecord31[]; -type CustomRecord32Array CustomRecord32[]; -type CustomRecord33Array CustomRecord33[]; -type CustomRecord34Array CustomRecord34[]; -type CustomRecord35Array CustomRecord35[]; -type CustomRecord36Array CustomRecord36[]; -type CustomRecord37Array CustomRecord37[]; -type CustomRecord38Array CustomRecord38[]; -type CustomRecord39Array CustomRecord39[]; -type CustomRecord40Array CustomRecord40[]; -type CustomRecord41Array CustomRecord41[]; -type CustomRecord42Array CustomRecord42[]; -type CustomRecord43Array CustomRecord43[]; -type CustomRecord44Array CustomRecord44[]; -type CustomRecord45Array CustomRecord45[]; -type CustomRecord46Array CustomRecord46[]; -type CustomRecord47Array CustomRecord47[]; -type CustomRecord48Array CustomRecord48[]; -type CustomRecord49Array CustomRecord49[]; -type CustomRecord50Array CustomRecord50[]; -type CustomRecord51Array CustomRecord51[]; -type CustomRecord52Array CustomRecord52[]; -type CustomRecord53Array CustomRecord53[]; -type CustomRecord54Array CustomRecord54[]; -type CustomRecord55Array CustomRecord55[]; -type CustomRecord56Array CustomRecord56[]; - -type BooleanTuple1Array BooleanTuple1[]; - -type ClosedBooleanTuple1Array BooleanTuple1[3]; - -type BooleanTuple2Array BooleanTuple2[]; - -type ClosedBooleanTuple2Array BooleanTuple2[3]; - -type BooleanTuple3Array BooleanTuple3[]; - -type ClosedBooleanTuple3Array BooleanTuple3[3]; - -type BooleanTuple4Array BooleanTuple4[]; - -type ClosedBooleanTuple4Array BooleanTuple4[3]; - -type NillableBooleanTuple5Array NillableBooleanTuple5[]; - -type NillableBooleanTuple6Array NillableBooleanTuple6[]; - -type NillableBooleanTuple7Array NillableBooleanTuple7[]; - -type NillableBooleanTuple8Array NillableBooleanTuple8[]; - -type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; - -type NilTuple1Array NilTuple1[]; - -type ClosedNilTuple1Array NilTuple1[3]; - -type NilTuple2Array NilTuple2[]; - -type ClosedNilTuple2Array NilTuple2[3]; - -type NilTuple3Array NilTuple3[]; - -type ClosedNilTuple3Array NilTuple3[3]; - -type NilTuple4Array NilTuple4[]; - -type ClosedNilTuple4Array NilTuple4[3]; - -type IntegerTuple1Array IntegerTuple1[]; - -type ClosedIntegerTuple1Array IntegerTuple1[3]; - -type IntegerTuple2Array IntegerTuple2[]; - -type ClosedIntegerTuple2Array IntegerTuple2[3]; - -type IntegerTuple3Array IntegerTuple3[]; - -type ClosedIntegerTuple3Array IntegerTuple3[3]; - -type IntegerTuple4Array IntegerTuple4[]; - -type ClosedIntegerTuple4Array IntegerTuple4[3]; - -type FloatTuple1Array FloatTuple1[]; - -type ClosedFloatTuple1Array FloatTuple1[3]; - -type FloatTuple2Array FloatTuple2[]; - -type ClosedFloatTuple2Array FloatTuple2[3]; - -type FloatTuple3Array FloatTuple3[]; - -type ClosedFloatTuple3Array FloatTuple3[3]; - -type FloatTuple4Array FloatTuple4[]; - -type ClosedFloatTuple4Array FloatTuple4[3]; - -type DecimalTuple1Array DecimalTuple1[]; - -type ClosedDecimalTuple1Array DecimalTuple1[3]; - -type DecimalTuple2Array DecimalTuple2[]; - -type ClosedDecimalTuple2Array DecimalTuple2[3]; - -type DecimalTuple3Array DecimalTuple3[]; - -type ClosedDecimalTuple3Array DecimalTuple3[3]; - -type DecimalTuple4Array DecimalTuple4[]; - -type ClosedDecimalTuple4Array DecimalTuple4[3]; - -type StringTuple1Array StringTuple1[]; - -type ClosedStringTuple1Array StringTuple1[3]; - -type StringTuple2Array StringTuple2[]; - -type ClosedStringTuple2Array StringTuple2[3]; - -type StringTuple3Array StringTuple3[]; - -type ClosedStringTuple3Array StringTuple3[3]; - -type StringTuple4Array StringTuple4[]; - -type ClosedStringTuple4Array StringTuple4[3]; - -type AnydataTuple1Array AnydataTuple1[]; - -type ClosedAnydataTuple1Array AnydataTuple1[3]; - -type AnydataTuple2Array AnydataTuple2[]; - -type ClosedAnydataTuple2Array AnydataTuple2[3]; - -type AnydataTuple3Array AnydataTuple3[]; - -type ClosedAnydataTuple3Array AnydataTuple3[3]; - -type AnydataTuple4Array AnydataTuple4[]; - -type ClosedAnydataTuple4Array AnydataTuple4[3]; - -type JsonTuple1Array JsonTuple1[]; - -type ClosedJsonTuple1Array JsonTuple1[3]; - -type JsonTuple2Array JsonTuple2[]; - -type ClosedJsonTuple2Array JsonTuple2[3]; - -type JsonTuple3Array JsonTuple3[]; - -type ClosedJsonTuple3Array JsonTuple3[3]; - -type JsonTuple4Array JsonTuple4[]; - -type ClosedJsonTuple4Array JsonTuple4[3]; - -type CustomTuple1Array CustomTuple1[]; - -type ClosedCustomTuple1Array CustomTuple1[3]; - -type CustomTuple2Array CustomTuple2[]; - -type ClosedCustomTuple2Array CustomTuple2[3]; - -type CustomTuple3Array CustomTuple3[]; - -type ClosedCustomTuple3Array CustomTuple3[3]; - -type CustomTuple4Array CustomTuple4[]; - -type ClosedCustomTuple4Array CustomTuple4[3]; - -type CustomTuple5Array CustomTuple5[]; - -type ClosedCustomTuple5Array CustomTuple5[3]; - -type CustomTuple6Array CustomTuple6[]; - -type CustomTuple7Array CustomTuple7[]; - -type CustomTuple8Array CustomTuple8[]; - -type ClosedCustomTuple6Array CustomTuple6[3]; - -type IntegerArray1Array IntegerArray1[]; - -type ClosedIntegerArray1Array IntegerArray1[3]; - -type IntegerArray2Array IntegerArray2[]; - -type ClosedIntegerArray2Array IntegerArray2[3]; - -type IntegerArray3Array IntegerArray3[]; - -type ClosedIntegerArray3Array IntegerArray3[3]; - -type IntegerArray4Array IntegerArray4[]; - -type ClosedIntegerArray4Array IntegerArray4[3]; - -type IntegerArray5Array IntegerArray5[]; - -type ClosedIntegerArray5Array IntegerArray5[3]; - -type IntegerArray6Array IntegerArray5[]; - -type ClosedIntegerArray6Array IntegerArray5[3]; - -type StringArray1Array StringArray1[]; - -type StringArrayArray StringArray[]; - -type NillableStringArrayArray NillableStringArray[]; - -type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; - -type ClosedStringArray1Array StringArray1[3]; - -type StringArray2Array StringArray2[]; - -type ClosedStringArray2Array StringArray2[3]; - -type StringArray3Array StringArray3[]; - -type ClosedStringArray3Array StringArray3[3]; - -type StringArray4Array StringArray4[]; - -type ClosedStringArray4Array StringArray4[3]; - -type StringArray5Array StringArray5[]; - -type ClosedStringArray5Array StringArray5[3]; - -type StringArray6Array StringArray5[]; - -type ClosedStringArray6Array StringArray5[3]; - -type FloatArray1Array FloatArray1[]; - -type ClosedFloatArray1Array FloatArray1[3]; - -type FloatArray2Array FloatArray2[]; - -type ClosedFloatArray2Array FloatArray2[3]; - -type FloatArray3Array FloatArray3[]; - -type ClosedFloatArray3Array FloatArray3[3]; - -type FloatArray4Array FloatArray4[]; - -type ClosedFloatArray4Array FloatArray4[3]; - -type FloatArray5Array FloatArray5[]; - -type ClosedFloatArray5Array FloatArray5[3]; - -type FloatArray6Array FloatArray5[]; - -type ClosedFloatArray6Array FloatArray5[3]; - -type DecimalArray1Array DecimalArray1[]; - -type ClosedDecimalArray1Array DecimalArray1[3]; - -type DecimalArray2Array DecimalArray2[]; - -type ClosedDecimalArray2Array DecimalArray2[3]; - -type DecimalArray3Array DecimalArray3[]; - -type ClosedDecimalArray3Array DecimalArray3[3]; - -type DecimalArray4Array DecimalArray4[]; - -type ClosedDecimalArray4Array DecimalArray4[3]; - -type DecimalArray5Array DecimalArray5[]; - -type ClosedDecimalArray5Array DecimalArray5[3]; - -type DecimalArray6Array DecimalArray5[]; - -type ClosedDecimalArray6Array DecimalArray5[3]; - -type BooleanArrayArray BooleanArray[]; - -type ClosedBooleanArrayArray BooleanArray[3]; - -type NillableBooleanArrayArray NillableBooleanArray[]; - -type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; - -type BooleanArray2Array BooleanArray2[]; - -type ClosedBooleanArray2Array BooleanArray2[3]; - -type BooleanArray3Array BooleanArray3[]; - -type ClosedBooleanArray3Array BooleanArray3[3]; - -type BooleanArray4Array BooleanArray4[]; - -type ClosedBooleanArray4Array BooleanArray4[3]; - -type BooleanArray5Array BooleanArray5[]; - -type ClosedBooleanArray5Array BooleanArray5[3]; - -type BooleanArray6Array BooleanArray5[]; - -type ClosedBooleanArray6Array BooleanArray5[3]; - -type NilArray1Array NilArray1[]; - -type ClosedNilArray1Array NilArray1[3]; - -type NilArray2Array NilArray2[]; - -type ClosedNilArray2Array NilArray2[3]; - -type NilArray3Array NilArray3[]; - -type ClosedNilArray3Array NilArray3[3]; - -type NilArray4Array NilArray4[]; - -type ClosedNilArray4Array NilArray4[3]; - -type NilArray5Array NilArray5[]; - -type ClosedNilArray5Array NilArray5[3]; - -type NilArray6Array NilArray5[]; - -type ClosedNilArray6Array NilArray5[3]; - -type JsonArray1Array JsonArray1[]; +type StringMap map; -type ClosedJsonArray1Array JsonArray1[3]; +type DecimalMap map; -type JsonArray2Array JsonArray2[]; +type BooleanMap map; -type ClosedJsonArray2Array JsonArray2[3]; +type NillableBooleanMap map; -type JsonArray3Array JsonArray3[]; +type NillableIntUnionBooleanMap map; -type ClosedJsonArray3Array JsonArray3[3]; +type IntUnionBooleanMap map; -type JsonArray4Array JsonArray4[]; +type NilMap map<()>; -type ClosedJsonArray4Array JsonArray4[3]; +type JsonMap map; -type JsonArray5Array JsonArray5[]; +type AnydataMap map; -type ClosedJsonArray5Array JsonArray5[3]; +type CustomMap map; -type JsonArray6Array JsonArray5[]; +type BooleanRecord1Array BooleanRecord1[]; -type ClosedJsonArray6Array JsonArray5[3]; +type ClosedBooleanRecord1Array BooleanRecord1[3]; -type AnydataArray1Array AnydataArray1[]; +type BooleanRecord2Array BooleanRecord2[]; -type ClosedAnydataArray1Array AnydataArray1[3]; +type ClosedBooleanRecord2Array BooleanRecord2[3]; -type AnydataArray2Array AnydataArray2[]; +type BooleanRecord3Array BooleanRecord3[]; -type ClosedAnydataArray2Array AnydataArray2[3]; +type ClosedBooleanRecord3Array BooleanRecord3[3]; -type AnydataArray3Array AnydataArray3[]; +type BooleanRecord4Array BooleanRecord4[]; -type ClosedAnydataArray3Array AnydataArray3[3]; +type ClosedBooleanRecord4Array BooleanRecord4[3]; -type AnydataArray4Array AnydataArray4[]; +type BooleanRecord5Array BooleanRecord5[]; -type ClosedAnydataArray4Array AnydataArray4[3]; +type ClosedBooleanRecord5Array BooleanRecord5[3]; -type AnydataArray5Array AnydataArray5[]; +type BooleanRecord6Array BooleanRecord6[]; -type ClosedAnydataArray5Array AnydataArray5[3]; +type ClosedBooleanRecord6Array BooleanRecord6[3]; -type AnydataArray6Array AnydataArray5[]; +type BooleanRecord7Array BooleanRecord7[]; -type ClosedAnydataArray6Array AnydataArray5[3]; +type ClosedBooleanRecord7Array BooleanRecord7[3]; -type CustomArray1Array CustomArray1[]; +type BooleanRecord8Array BooleanRecord8[]; -type ClosedCustomArray1Array CustomArray1[3]; +type ClosedBooleanRecord8Array BooleanRecord8[3]; -type CustomArray2Array CustomArray2[]; +type BooleanRecord9Array BooleanRecord9[]; -type ClosedCustomArray2Array CustomArray2[3]; +type ClosedBooleanRecord9Array BooleanRecord9[3]; -type CustomArray3Array CustomArray3[]; +type BooleanRecord10Array BooleanRecord10[]; -type ClosedCustomArray3Array CustomArray3[3]; +type ClosedBooleanRecord10Array BooleanRecord10[3]; -type CustomArray4Array CustomArray4[]; +type BooleanRecord11Array BooleanRecord11[]; -type ClosedCustomArray4Array CustomArray4[3]; +type ClosedBooleanRecord11Array BooleanRecord11[3]; -type CustomArray5Array CustomArray5[]; +type BooleanRecord12Array BooleanRecord12[]; -type ClosedCustomArray5Array CustomArray5[3]; +type ClosedBooleanRecord12Array BooleanRecord12[3]; -type CustomArray6Array CustomArray5[]; +type BooleanRecord13Array BooleanRecord13[]; -type ClosedCustomArray6Array CustomArray5[3]; +type ClosedBooleanRecord13Array BooleanRecord13[3]; -type IntegerMapArray IntegerMap[]; +type BooleanRecord14Array BooleanRecord14[]; -type ClosedIntegerMapArray IntegerMap[3]; +type ClosedBooleanRecord14Array BooleanRecord14[3]; -type StringMapArray StringMap[]; +type BooleanRecord15Array BooleanRecord15[]; -type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; +type ClosedBooleanRecord15Array BooleanRecord15[3]; -type IntUnionStringMapArray IntUnionStringMap[]; +type BooleanRecord16Array BooleanRecord16[]; -type ClosedStringMapArray StringMap[3]; +type ClosedBooleanRecord16Array BooleanRecord16[3]; -type DecimalMapArray DecimalMap[]; +type BooleanRecord17Array BooleanRecord17[]; -type ClosedDecimalMapArray DecimalMap[3]; +type ClosedBooleanRecord17Array BooleanRecord17[3]; -type FloatMapArray FloatMap[]; +type BooleanRecord18Array BooleanRecord18[]; -type ClosedFloatMapArray FloatMap[3]; +type ClosedBooleanRecord18Array BooleanRecord18[3]; type BooleanMapArray BooleanMap[]; @@ -2535,6 +230,10 @@ type ClosedBooleanMapArray BooleanMap[3]; type NilMapArray NilMap[]; +type DecimalMapArray DecimalMap[]; + +type StringMapArray StringMap[]; + type ClosedNilMapArray NilMap[3]; type JsonMapArray JsonMap[]; diff --git a/ballerina-tests/type-compatible-tests/tests/test_data_values.bal b/ballerina-tests/type-compatible-tests/tests/test_data_values.bal index a9698aa..5993176 100644 --- a/ballerina-tests/type-compatible-tests/tests/test_data_values.bal +++ b/ballerina-tests/type-compatible-tests/tests/test_data_values.bal @@ -52,221 +52,3 @@ decimal|int d6 = 1.21; string s1 = "string"; string s2 = ""; string:Char s3 = "a"; - -map bm1 = {b1, b2}; -map bm2 = {b1, b2, b3, n1, n3}; -map bm3 = {b1, b2, b3, b4, i1}; -map<()> bm4 = {n1, n3}; -map bm5 = {b1, b2, b3, b4:true}; - -map m5 = {i1, i2, i3, i4, i5, i6}; -map m6 = {f1, f2, f3, f4, f5, f6, f7}; -map m7 = {d1, d2, d3, d4}; -map m8 = {d1, f1, f9, f10: 1.23}; -map m9 = {s1, s2, s3}; -map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; -map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; - -boolean[] arr1 = [b1, b2]; -boolean?[] arr2 = [b1, b2, b3, n1, n3]; -(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; -()[] arr4 = [n1, n3]; -int[] arr5 = [i1, i2, i3, i4, i5, i6]; -float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; -decimal[] arr7 = [d1, d2, d3, d4]; -(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; -string[] arr9 = [s1, s2, s3]; -anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; - -[boolean, boolean] bt1 = [b1, b2]; -[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; -[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; -[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; -[boolean...] bt5 = [b1, b2]; - -[string, string] st1 = [s1, s2]; -[string, string, string, string] st2 = [s1, s2, s3, s2]; -[string...] st3 = [s1, s2]; -[string, string, string...] st4 = [s1, s2, s3, s2]; - -[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; -[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; -[string?...] st7 = [s1, s2]; -[string...] st8 = []; -[string, string, string] st9 = [s1, s2, s3]; - -[(), ()] tup4 = [n1, n3]; -[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; -[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; -[string, string, string] tup9 = [s1, s2, s3]; -[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, - n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, json] tup11 = - [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, - f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 -]; - -[boolean, boolean...] restTup1 = [b1, b2]; -[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; -[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; -[(), ()...] restTup4 = [n1, n3]; -[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; -[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal...] restTup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; -[string...] restTup9 = [s1, s2, s3]; -[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 -]; - -var booleanRecordArray = [ - {b1, b2, b3, b4}, {b1, b2, b3, b4} -]; - -var booleanRecordArray2 = [ - {},{} -]; - -string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 -true,false,true,false -true,false, true,false -true,false,true,false -`; - -string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 -true,false, true,false,true -true,false, true,false,true`; - -string csvStringWithBooleanValues3 = string `b1,b2,b3 -${" "}${"\t"} -true, false,true -${" "} - TRUE, FALSE,() -${" "} - -true, true,FALSE - -`; - -string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 - true,(), (),false - true,(), null,false - -`; - -string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 - -true,false,true,2 - -true,false,true,3 -`; - -string csvStringWithBooleanValues6 = string `b2,b3 -(),() - -`; - -string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 -${b1},${b2},(),${b4} -`; - -string csvStringData1 = string ` - a, b, c, d, e, f - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData2 = string ` - hello, hello, (), 12, true, 12.34 - // comment - - a, b, c, d, e, f - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData3 = string ` - a, b, c, d, e, f - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData4 = string ` - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData5 = string ` - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData6 = string ` - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData7 = string ` - a@ b@ c@ d@ e@ f - 1@ string@ true@ 2.234@ -3.21@ () - 2@ s,tring@ true@ 2.234@ -3.21@ null - 3@ stri,ng@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; -string csvStringData8 = string ` - a@ b@ c@ d@ e@ f - - - - 1@ stri,ng@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ ()@-3.21 - 3@ string@ true@ 2.234@ -3.21@ null - - 4@ s,tring@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; - -string csvStringData9 = string ` - - 1@ string@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ -3.21@ null - - 3@ string@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ ()@-3.21 - - 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina-tests/type-compatible-tests/tests/types.bal b/ballerina-tests/type-compatible-tests/tests/types.bal index b496d60..2d6ed41 100644 --- a/ballerina-tests/type-compatible-tests/tests/types.bal +++ b/ballerina-tests/type-compatible-tests/tests/types.bal @@ -14,2537 +14,28 @@ // specific language governing permissions and limitations // under the License. -type BooleanRecord1 record { - boolean b1; - boolean|string b2; - boolean|string? b3; - boolean b4; -}; - -type BooleanRecord2 record {| - boolean b1; - boolean|string b2; - boolean|string? b3; - boolean b4; -|}; - -type BooleanRecord3 record {| - boolean b1; - boolean? b3; -|}; - -type BooleanRecord4 record { - boolean b1; - boolean? b3; -}; - -type BooleanRecord5 record { - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); -}; - -type BooleanRecord6 record {| - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); -|}; - -type BooleanRecord7 record { - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type BooleanRecord8 record {| - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type BooleanRecord9 record {| - boolean b1; - boolean? b3; - boolean?...; -|}; - -type BooleanRecord10 record {| - boolean...; -|}; - -type BooleanRecord11 record {| - boolean b1; - string defaultableField = ""; - string? nillableField = (); - boolean?|string...; -|}; - -type BooleanRecord12 record {| +type AnydataArray1 anydata[]; +type CustomRecord27 record {| + int i1; + string s1; boolean b1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - boolean...; -|}; - -type BooleanRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - string|boolean...; -|}; - -type BooleanRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - boolean...; -|}; - -type BooleanRecord15 record {| - int b1; - string defaultableField = ""; - string? nillableField = (); - boolean?...; -|}; - -type BooleanRecord16 record {| - boolean?...; -|}; - -type BooleanRecord17 record {| - int...; -|}; - -type BooleanRecord18 record {| - boolean b2; - int?...; -|}; - -type NilRecord1 record { - () n1; - () n2; - () n3; -}; - -type NilRecord2 record {| - () n1; - () n2; - () n3; -|}; - -type NilRecord3 record {| - () n1; - () n4; -|}; - -type NilRecord4 record { - () n1; - () n4; -}; - -type NilRecord5 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -}; - -type NilRecord6 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type NilRecord7 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type NilRecord8 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type NilRecord9 record {| - () n1; - () n2; - ()...; -|}; - -type NilRecord10 record {| - ()...; -|}; - -type NilRecord11 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord12 record {| () n1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type NilRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type IntegerRecord1 record { - int i1; - int i2; - int i3; - int? i4; - int? i5; - int i6; - int i7; - int? i8; -}; - -type IntegerRecord2 record {| - int i1; - int? i2; - int i3; - int i4; - int? i5; - int i6; - int i7; - int? i8; -|}; - -type IntegerRecord3 record {| - int i1; - int i4; - int i6; -|}; - -type IntegerRecord4 record { - int i1; - int i4; - int i6; -}; - -type IntegerRecord5 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -}; - -type IntegerRecord6 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -|}; - -type IntegerRecord7 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type IntegerRecord8 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type IntegerRecord9 record {| - int i1; - int i2; - int...; -|}; - -type IntegerRecord10 record {| - int...; -|}; - -type IntegerRecord11 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord12 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type IntegerRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type FloatRecord1 record { - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -}; - -type FloatRecord2 record {| - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -|}; - -type FloatRecord3 record {| - float f1; - float f4; - float f7; -|}; - -type FloatRecord4 record { - float f1; - float f4; - float f7; -}; - -type FloatRecord5 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -}; - -type FloatRecord6 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type FloatRecord7 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type FloatRecord8 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type FloatRecord9 record {| - float f1; - float f2; - float...; -|}; - -type FloatRecord10 record {| - float...; -|}; - -type FloatRecord11 record {| float f1; - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord12 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type FloatRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type DecimalRecord1 record { - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -}; - -type DecimalRecord2 record {| - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -|}; - -type DecimalRecord3 record {| - decimal d1; - decimal d4; - decimal d7; -|}; - -type DecimalRecord4 record { - decimal d1; - decimal d4; - decimal d7; -}; - -type DecimalRecord5 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -}; - -type DecimalRecord6 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type DecimalRecord7 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type DecimalRecord8 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type DecimalRecord9 record {| - decimal d1; - decimal d2; - decimal...; -|}; - -type DecimalRecord10 record {| - decimal...; -|}; - -type DecimalRecord11 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord12 record {| decimal d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type DecimalRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type StringRecord1 record { - string s1; - string s2; - string s3; -}; - -type StringRecord2 record {| - string s1; - string s2; - string s3; -|}; - -type StringRecord3 record {| - string s1; - string s4; -|}; - -type StringRecord4 record { - string s1; - string s4; -}; - -type StringRecord5 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -}; - -type StringRecord6 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type StringRecord7 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type StringRecord8 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type StringRecord9 record {| - string s1; - string s2; - string...; -|}; - -type StringRecord10 record {| - string...; -|}; - -type StringRecord11 record {| - string s1; - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord12 record {| - string d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord15 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord16 record {| - string?...; -|}; - -type StringRecord17 record {| - int...; -|}; - -type StringRecord18 record {| - string b2; - int?...; -|}; - -type StringRecord19 record { - string s1 = ""; - string s2 = ""; -}; - -type StringRecord20 record {| - string s1 = ""; - string s2 = ""; -|}; - -type StringRecord21 record { -}; - -type StringRecord22 record {| - string s1 = ""; - string s2 = ""; - json...; -|}; - -type StringRecord23 record {| - json...; -|}; - -type JsonRecord1 record { - json j1; - json j2; - json j3; -}; - -type JsonRecord2 record {| - json j1; - json j2; - json j3; -|}; - -type JsonRecord3 record {| + anydata a1; json j1; - json j4; + anydata defaultableField = ""; + anydata? nillableField = (); + string...; |}; - -type JsonRecord4 record { - json j1; - json j4; -}; - -type JsonRecord5 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -}; - -type JsonRecord6 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -|}; - -type JsonRecord7 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -}; - -type JsonRecord8 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -|}; - -type JsonRecord9 record {| - json j1; - json j2; - json...; -|}; - -type JsonRecord10 record {| - json...; -|}; - -type JsonRecord11 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord12 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type JsonRecord13 record {| - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord14 record {| - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type AnydataRecord1 record { - anydata anydata1; - anydata anydata2; - anydata anydata3; -}; - -type AnydataRecord2 record {| - anydata anydata1; - anydata anydata2; - anydata anydata3; -|}; - -type AnydataRecord3 record {| - anydata anydata1; - anydata anydata4; -|}; - -type AnydataRecord4 record { - anydata anydata1; - anydata anydata4; -}; - -type AnydataRecord5 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -}; - -type AnydataRecord6 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type AnydataRecord7 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type AnydataRecord8 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type AnydataRecord9 record {| - anydata anydata1; - anydata anydata2; - anydata...; -|}; - -type AnydataRecord10 record {| - anydata...; -|}; - -type AnydataRecord11 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord12 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type AnydataRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type CustomRecord1 record { - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -}; - -type CustomRecord2 record {| - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -|}; - -type CustomRecord3 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -|}; - -type CustomRecord4 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -}; - -type CustomRecord5 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string defaultableField = ""; - string? nillableField = (); -}; - -type CustomRecord6 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type CustomRecord7 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type CustomRecord8 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type CustomRecord9 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string...; -|}; - -type CustomRecord10 record {| - string...; -|}; - -type CustomRecord11 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord12 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord15 record {| - string '1; - string '2; -|}; - -type CustomRecord16 record {| - string '1; - string '2; - string '3; - string '4; -|}; - -type CustomRecord17 record { - string '1; - string '2; -}; - -type CustomRecord18 record { - string '1; - string '2; - string '3; - string '4; -}; - -type CustomRecord19 record { - string '1; - string '2; - string '3 = ""; - string '4 = ""; -}; - -type CustomRecord20 record { - string '1; -}; - -type CustomRecord21 record {| - string '1; - json...; -|}; - -type CustomRecord22 record {| - string '1; - string...; -|}; - -type CustomRecord23 record {| - string '1; - string a = ""; - string...; -|}; - -type CustomRecord24 record {| - string '1; - string '2 = ""; - string...; -|}; - -type CustomRecord25 record {| - int '1; - string...; -|}; - -type CustomRecord26 record {| - string '1; - int...; -|}; - -type CustomRecord27 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata a1; - json j1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord28 record { - string '1; -}; - -type CustomRecord29 record { - int '1; -}; - -type CustomRecord30 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord31 record {| - string '1; - string '6; -|}; - -type CustomRecord32 record {| - int '1; -|}; - -type CustomRecord33 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord34 record { - string '1; - string '6; - string '5 = ""; -}; - -type CustomRecord35 record { - string '1; - string '6; - string '9 = ""; -}; - -type CustomRecord36 record {| - string '1; - string '6; - string '9 = ""; -|}; - -type CustomRecord37 record {| - string '1; - string '6; - string '5 = ""; -|}; - -type CustomRecord38 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - string ...; -|}; - -type CustomRecord39 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - json ...; -|}; - -type CustomRecord40 record {| - string '5; - string '6; - json ...; -|}; - -type CustomRecord41 record {| - json ...; -|}; - -type CustomRecord42 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -|}; - -type CustomRecord43 record { - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -}; - -type CustomRecord44 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; - string ...; -|}; - -type CustomRecord45 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -|}; - -type CustomRecord46 record { - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -}; - -type CustomRecord47 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; - string ...; -|}; - -type CustomRecord48 record { - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -}; - -type CustomRecord49 record {| - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -|}; - -type CustomRecord50 record { - int H1; - float H4; -}; - -type CustomRecord51 record {| - int H1; - float H4; -|}; - -type CustomRecord52 record {| - string H1; - string H4; - string ...; -|}; - -type CustomRecord53 record {| - int H1; - float H4; - decimal ...; -|}; - -type CustomRecord54 record {| - string H1 = ""; - string H4; - string '1; -|}; - -type CustomRecord55 record {| - string H1 = ""; - string H4 = ""; - int '1 = 10; -|}; - -type CustomRecord56 record { - string H1 = ""; - string H4 = ""; - anydata '1 = 10; -}; - -type BooleanTuple1 [boolean, boolean, boolean, boolean]; - -type BooleanTuple2 [boolean, boolean]; - -type BooleanTuple3 [boolean, boolean...]; - -type BooleanTuple4 [boolean...]; - -type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; - -type NillableBooleanTuple6 [boolean?, boolean?]; - -type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; - -type NillableBooleanTuple8 [boolean?...]; - -type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; - -type NilTuple1 [(), (), ()]; - -type NilTuple2 [(), ()]; - -type NilTuple3 [(), ()...]; - -type NilTuple4 [()...]; - -type IntegerTuple1 [int, int, int, int, int, int]; - -type IntegerTuple2 [int, int]; - -type IntegerTuple3 [int, int...]; - -type IntegerTuple4 [int...]; - -type FloatTuple1 [float, float, float, float, float, float, float]; - -type FloatTuple2 [float, float]; - -type FloatTuple3 [float, float...]; - -type FloatTuple4 [float...]; - -type DecimalTuple1 [decimal, decimal, decimal, decimal]; - -type DecimalTuple2 [decimal, decimal]; - -type DecimalTuple3 [decimal, decimal...]; - -type DecimalTuple4 [decimal...]; - -type StringTuple1 [string, string, string, string]; - -type StringTuple2 [string, string]; - -type StringTuple3 [string, string...]; - -type StringTuple4 [string...]; - -type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata]; - -type AnydataTuple2 [anydata, anydata]; - -type AnydataTuple3 [anydata, anydata...]; - -type AnydataTuple4 [anydata...]; - -type JsonTuple1 [json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json]; - -type JsonTuple2 [json, json]; - -type JsonTuple3 [json, json...]; - -type JsonTuple4 [json...]; - -type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; - -type CustomTuple4 [string...]; - -type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; - -type CustomTuple6 [anydata...]; - -type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; - -type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; - -type IntegerArray1 int[]; - -type IntegerArray2 int[2]; - -type IntegerArray3 int[]; - -type IntegerArray4 int[2]; - -type IntegerArray5 int[3]; - -type IntegerArray6 int[4]; - -type StringArray string[]; - -type NillableStringArray string?[]; - -type NillableIntOrUnionStringArray (int|string?)[]; - -type StringArray1 string[]; - -type StringArray2 string[2]; - -type StringArray3 string[]; - -type StringArray4 string[2]; - -type StringArray5 string[3]; - -type StringArray6 string[4]; - -type FloatArray1 float[]; - -type FloatArray2 float[2]; - -type FloatArray3 float[]; - -type FloatArray4 float[2]; - -type FloatArray5 float[3]; - -type FloatArray6 float[4]; - -type DecimalArray1 decimal[]; - -type DecimalArray2 decimal[2]; - -type DecimalArray3 decimal[]; - -type DecimalArray4 decimal[2]; - -type DecimalArray5 decimal[3]; - -type DecimalArray6 decimal[4]; - -type BooleanArray boolean[]; - -type NillableBooleanArray boolean?[]; - -type NillableIntOrUnionBooleanArray (int|boolean?)[]; - -type BooleanArray2 boolean[2]; - -type BooleanArray3 boolean[3]; - -type BooleanArray4 boolean[]; - -type BooleanArray5 boolean[2]; - -type BooleanArray6 boolean[4]; - -type NilArray1 ()[]; - -type NilArray2 ()[2]; - -type NilArray3 ()[]; - -type NilArray4 ()[2]; - -type NilArray5 ()[3]; - -type NilArray6 ()[4]; - -type JsonArray1 json[]; - -type JsonArray2 json[2]; - -type JsonArray3 json[]; - -type JsonArray4 json[2]; - -type JsonArray5 json[3]; - -type JsonArray6 json[4]; - -type AnydataArray1 anydata[]; - -type AnydataArray2 anydata[2]; - -type AnydataArray3 anydata[]; - -type AnydataArray4 anydata[2]; - -type AnydataArray5 anydata[3]; - -type AnydataArray6 anydata[4]; - -type CustomArray1 CustomTuple2[]; - -type CustomArray2 CustomTuple2[2]; - -type CustomArray3 CustomTuple2[]; - -type CustomArray4 CustomTuple2[2]; - -type CustomArray5 CustomTuple2[3]; - -type CustomArray6 CustomTuple2[4]; - -type IntegerMap map; - -type StringMap map; - -type NillableIntUnionStringMap map; - -type IntUnionStringMap map; - -type DecimalMap map; - -type FloatMap map; - -type BooleanMap map; - -type NillableBooleanMap map; - -type NillableIntUnionBooleanMap map; - -type IntUnionBooleanMap map; - -type NilMap map<()>; - -type JsonMap map; - -type AnydataMap map; - -type CustomMap map; - -type BooleanRecord1Array BooleanRecord1[]; - -type ClosedBooleanRecord1Array BooleanRecord1[3]; - -type BooleanRecord2Array BooleanRecord2[]; - -type ClosedBooleanRecord2Array BooleanRecord2[3]; - -type BooleanRecord3Array BooleanRecord3[]; - -type ClosedBooleanRecord3Array BooleanRecord3[3]; - -type BooleanRecord4Array BooleanRecord4[]; - -type ClosedBooleanRecord4Array BooleanRecord4[3]; - -type BooleanRecord5Array BooleanRecord5[]; - -type ClosedBooleanRecord5Array BooleanRecord5[3]; - -type BooleanRecord6Array BooleanRecord6[]; - -type ClosedBooleanRecord6Array BooleanRecord6[3]; - -type BooleanRecord7Array BooleanRecord7[]; - -type ClosedBooleanRecord7Array BooleanRecord7[3]; - -type BooleanRecord8Array BooleanRecord8[]; - -type ClosedBooleanRecord8Array BooleanRecord8[3]; - -type BooleanRecord9Array BooleanRecord9[]; - -type ClosedBooleanRecord9Array BooleanRecord9[3]; - -type BooleanRecord10Array BooleanRecord10[]; - -type ClosedBooleanRecord10Array BooleanRecord10[3]; - -type BooleanRecord11Array BooleanRecord11[]; - -type ClosedBooleanRecord11Array BooleanRecord11[3]; - -type BooleanRecord12Array BooleanRecord12[]; - -type ClosedBooleanRecord12Array BooleanRecord12[3]; - -type BooleanRecord13Array BooleanRecord13[]; - -type ClosedBooleanRecord13Array BooleanRecord13[3]; - -type BooleanRecord14Array BooleanRecord14[]; - -type ClosedBooleanRecord14Array BooleanRecord14[3]; - -type BooleanRecord15Array BooleanRecord15[]; - -type ClosedBooleanRecord15Array BooleanRecord15[3]; - -type BooleanRecord16Array BooleanRecord16[]; - -type ClosedBooleanRecord16Array BooleanRecord16[3]; - -type BooleanRecord17Array BooleanRecord17[]; - -type ClosedBooleanRecord17Array BooleanRecord17[3]; - -type BooleanRecord18Array BooleanRecord18[]; - -type ClosedBooleanRecord18Array BooleanRecord18[3]; - -type NilRecord1Array NilRecord1[]; - -type ClosedNilRecord1Array NilRecord1[3]; - -type NilRecord2Array NilRecord2[]; - -type ClosedNilRecord2Array NilRecord2[3]; - -type NilRecord3Array NilRecord3[]; - -type ClosedNilRecord3Array NilRecord3[3]; - -type NilRecord4Array NilRecord4[]; - -type ClosedNilRecord4Array NilRecord4[3]; - -type NilRecord5Array NilRecord5[]; - -type ClosedNilRecord5Array NilRecord5[3]; - -type NilRecord6Array NilRecord6[]; - -type ClosedNilRecord6Array NilRecord6[3]; - -type NilRecord7Array NilRecord7[]; - -type ClosedNilRecord7Array NilRecord7[3]; - -type NilRecord8Array NilRecord8[]; - -type ClosedNilRecord8Array NilRecord8[3]; - -type NilRecord9Array NilRecord9[]; - -type ClosedNilRecord9Array NilRecord9[3]; - -type NilRecord10Array NilRecord10[]; - -type ClosedNilRecord10Array NilRecord10[3]; - -type NilRecord11Array NilRecord11[]; - -type ClosedNilRecord11Array NilRecord11[3]; - -type NilRecord12Array NilRecord12[]; - -type ClosedNilRecord12Array NilRecord12[3]; - -type NilRecord13Array NilRecord13[]; - -type ClosedNilRecord13Array NilRecord13[3]; - -type NilRecord14Array NilRecord14[]; - -type ClosedNilRecord14Array NilRecord14[3]; - -type IntegerRecord1Array IntegerRecord1[]; - -type ClosedIntegerRecord1Array IntegerRecord1[3]; - -type IntegerRecord2Array IntegerRecord2[]; - -type ClosedIntegerRecord2Array IntegerRecord2[3]; - -type IntegerRecord3Array IntegerRecord3[]; - -type ClosedIntegerRecord3Array IntegerRecord3[3]; - -type IntegerRecord4Array IntegerRecord4[]; - -type ClosedIntegerRecord4Array IntegerRecord4[3]; - -type IntegerRecord5Array IntegerRecord5[]; - -type ClosedIntegerRecord5Array IntegerRecord5[3]; - -type IntegerRecord6Array IntegerRecord6[]; - -type ClosedIntegerRecord6Array IntegerRecord6[3]; - -type IntegerRecord7Array IntegerRecord7[]; - -type ClosedIntegerRecord7Array IntegerRecord7[3]; - -type IntegerRecord8Array IntegerRecord8[]; - -type ClosedIntegerRecord8Array IntegerRecord8[3]; - -type IntegerRecord9Array IntegerRecord9[]; - -type ClosedIntegerRecord9Array IntegerRecord9[3]; - -type IntegerRecord10Array IntegerRecord10[]; - -type ClosedIntegerRecord10Array IntegerRecord10[3]; - -type IntegerRecord11Array IntegerRecord11[]; - -type ClosedIntegerRecord11Array IntegerRecord11[3]; - -type IntegerRecord12Array IntegerRecord12[]; - -type ClosedIntegerRecord12Array IntegerRecord12[3]; - -type IntegerRecord13Array IntegerRecord13[]; - -type ClosedIntegerRecord13Array IntegerRecord13[3]; - -type IntegerRecord14Array IntegerRecord14[]; - -type ClosedIntegerRecord14Array IntegerRecord14[3]; - -type FloatRecord1Array FloatRecord1[]; - -type ClosedFloatRecord1Array FloatRecord1[3]; - -type FloatRecord2Array FloatRecord2[]; - -type ClosedFloatRecord2Array FloatRecord2[3]; - -type FloatRecord3Array FloatRecord3[]; - -type ClosedFloatRecord3Array FloatRecord3[3]; - -type FloatRecord4Array FloatRecord4[]; - -type ClosedFloatRecord4Array FloatRecord4[3]; - -type FloatRecord5Array FloatRecord5[]; - -type ClosedFloatRecord5Array FloatRecord5[3]; - -type FloatRecord6Array FloatRecord6[]; - -type ClosedFloatRecord6Array FloatRecord6[3]; - -type FloatRecord7Array FloatRecord7[]; - -type ClosedFloatRecord7Array FloatRecord7[3]; - -type FloatRecord8Array FloatRecord8[]; - -type ClosedFloatRecord8Array FloatRecord8[3]; - -type FloatRecord9Array FloatRecord9[]; - -type ClosedFloatRecord9Array FloatRecord9[3]; - -type FloatRecord10Array FloatRecord10[]; - -type ClosedFloatRecord10Array FloatRecord10[3]; - -type FloatRecord11Array FloatRecord11[]; - -type ClosedFloatRecord11Array FloatRecord11[3]; - -type FloatRecord12Array FloatRecord12[]; - -type ClosedFloatRecord12Array FloatRecord12[3]; - -type FloatRecord13Array FloatRecord13[]; - -type ClosedFloatRecord13Array FloatRecord13[3]; - -type FloatRecord14Array FloatRecord14[]; - -type ClosedFloatRecord14Array FloatRecord14[3]; - -type DecimalRecord1Array DecimalRecord1[]; - -type ClosedDecimalRecord1Array DecimalRecord1[3]; - -type DecimalRecord2Array DecimalRecord2[]; - -type ClosedDecimalRecord2Array DecimalRecord2[3]; - -type DecimalRecord3Array DecimalRecord3[]; - -type ClosedDecimalRecord3Array DecimalRecord3[3]; - -type DecimalRecord4Array DecimalRecord4[]; - -type ClosedDecimalRecord4Array DecimalRecord4[3]; - -type DecimalRecord5Array DecimalRecord5[]; - -type ClosedDecimalRecord5Array DecimalRecord5[3]; - -type DecimalRecord6Array DecimalRecord6[]; - -type ClosedDecimalRecord6Array DecimalRecord6[3]; - -type DecimalRecord7Array DecimalRecord7[]; - -type ClosedDecimalRecord7Array DecimalRecord7[3]; - -type DecimalRecord8Array DecimalRecord8[]; - -type ClosedDecimalRecord8Array DecimalRecord8[3]; - -type DecimalRecord9Array DecimalRecord9[]; - -type ClosedDecimalRecord9Array DecimalRecord9[3]; - -type DecimalRecord10Array DecimalRecord10[]; - -type ClosedDecimalRecord10Array DecimalRecord10[3]; - -type DecimalRecord11Array DecimalRecord11[]; - -type ClosedDecimalRecord11Array DecimalRecord11[3]; - -type DecimalRecord12Array DecimalRecord12[]; - -type ClosedDecimalRecord12Array DecimalRecord12[3]; - -type DecimalRecord13Array DecimalRecord13[]; - -type ClosedDecimalRecord13Array DecimalRecord13[3]; - -type DecimalRecord14Array DecimalRecord14[]; - -type ClosedDecimalRecord14Array DecimalRecord14[3]; - -type StringRecord1Array StringRecord1[]; - -type ClosedStringRecord1Array StringRecord1[3]; - -type StringRecord2Array StringRecord2[]; - -type ClosedStringRecord2Array StringRecord2[3]; - -type StringRecord3Array StringRecord3[]; - -type ClosedStringRecord3Array StringRecord3[3]; - -type StringRecord4Array StringRecord4[]; - -type ClosedStringRecord4Array StringRecord4[3]; - -type StringRecord5Array StringRecord5[]; - -type ClosedStringRecord5Array StringRecord5[3]; - -type StringRecord6Array StringRecord6[]; - -type ClosedStringRecord6Array StringRecord6[3]; - -type StringRecord7Array StringRecord7[]; - -type ClosedStringRecord7Array StringRecord7[3]; - -type StringRecord8Array StringRecord8[]; - -type ClosedStringRecord8Array StringRecord8[3]; - -type StringRecord9Array StringRecord9[]; - -type ClosedStringRecord9Array StringRecord9[3]; - -type StringRecord10Array StringRecord10[]; - -type ClosedStringRecord10Array StringRecord10[3]; - -type StringRecord11Array StringRecord11[]; - -type ClosedStringRecord11Array StringRecord11[3]; - -type StringRecord12Array StringRecord12[]; - -type ClosedStringRecord12Array StringRecord12[3]; - -type StringRecord13Array StringRecord13[]; - -type ClosedStringRecord13Array StringRecord13[3]; - -type StringRecord14Array StringRecord14[]; - -type ClosedStringRecord14Array StringRecord14[3]; - -type StringRecord15Array StringRecord15[]; - -type StringRecord16Array StringRecord16[]; - -type StringRecord17Array StringRecord17[]; - -type StringRecord18Array StringRecord18[]; - -type StringRecord19Array StringRecord19[]; - -type StringRecord20Array StringRecord20[]; - -type StringRecord21Array StringRecord21[]; - -type StringRecord22Array StringRecord22[]; - -type StringRecord23Array StringRecord23[]; - -type JsonRecord1Array JsonRecord1[]; - -type ClosedJsonRecord1Array JsonRecord1[3]; - -type JsonRecord2Array JsonRecord2[]; - -type ClosedJsonRecord2Array JsonRecord2[3]; - -type JsonRecord3Array JsonRecord3[]; - -type ClosedJsonRecord3Array JsonRecord3[3]; - -type JsonRecord4Array JsonRecord4[]; - -type ClosedJsonRecord4Array JsonRecord4[3]; - -type JsonRecord5Array JsonRecord5[]; - -type ClosedJsonRecord5Array JsonRecord5[3]; - -type JsonRecord6Array JsonRecord6[]; - -type ClosedJsonRecord6Array JsonRecord6[3]; - -type JsonRecord7Array JsonRecord7[]; - -type ClosedJsonRecord7Array JsonRecord7[3]; - -type JsonRecord8Array JsonRecord8[]; - -type ClosedJsonRecord8Array JsonRecord8[3]; - -type JsonRecord9Array JsonRecord9[]; - -type ClosedJsonRecord9Array JsonRecord9[3]; - -type JsonRecord10Array JsonRecord10[]; - -type ClosedJsonRecord10Array JsonRecord10[3]; - -type JsonRecord11Array JsonRecord11[]; - -type ClosedJsonRecord11Array JsonRecord11[3]; - -type JsonRecord12Array JsonRecord12[]; - -type ClosedJsonRecord12Array JsonRecord12[3]; - -type JsonRecord13Array JsonRecord13[]; - -type ClosedJsonRecord13Array JsonRecord13[3]; - -type JsonRecord14Array JsonRecord14[]; - -type ClosedJsonRecord14Array JsonRecord14[3]; - -type AnydataRecord1Array AnydataRecord1[]; - -type ClosedAnydataRecord1Array AnydataRecord1[3]; - -type AnydataRecord2Array AnydataRecord2[]; - -type ClosedAnydataRecord2Array AnydataRecord2[3]; - -type AnydataRecord3Array AnydataRecord3[]; - -type ClosedAnydataRecord3Array AnydataRecord3[3]; - -type AnydataRecord4Array AnydataRecord4[]; - -type ClosedAnydataRecord4Array AnydataRecord4[3]; - -type AnydataRecord5Array AnydataRecord5[]; - -type ClosedAnydataRecord5Array AnydataRecord5[3]; - -type AnydataRecord6Array AnydataRecord6[]; - -type ClosedAnydataRecord6Array AnydataRecord6[3]; - -type AnydataRecord7Array AnydataRecord7[]; - -type ClosedAnydataRecord7Array AnydataRecord7[3]; - -type AnydataRecord8Array AnydataRecord8[]; - -type ClosedAnydataRecord8Array AnydataRecord8[3]; - -type AnydataRecord9Array AnydataRecord9[]; - -type ClosedAnydataRecord9Array AnydataRecord9[3]; - -type AnydataRecord10Array AnydataRecord10[]; - -type ClosedAnydataRecord10Array AnydataRecord10[3]; - -type AnydataRecord11Array AnydataRecord11[]; - -type ClosedAnydataRecord11Array AnydataRecord11[3]; - -type AnydataRecord12Array AnydataRecord12[]; - -type ClosedAnydataRecord12Array AnydataRecord12[3]; - -type AnydataRecord13Array AnydataRecord13[]; - -type ClosedAnydataRecord13Array AnydataRecord13[3]; - -type AnydataRecord14Array AnydataRecord14[]; - -type ClosedAnydataRecord14Array AnydataRecord14[3]; - -type CustomRecord1Array CustomRecord1[]; - -type ClosedCustomRecord1Array CustomRecord1[3]; - -type CustomRecord2Array CustomRecord2[]; - -type ClosedCustomRecord2Array CustomRecord2[3]; - -type CustomRecord3Array CustomRecord3[]; - -type ClosedCustomRecord3Array CustomRecord3[3]; - -type CustomRecord4Array CustomRecord4[]; - -type ClosedCustomRecord4Array CustomRecord4[3]; - -type CustomRecord5Array CustomRecord5[]; - -type ClosedCustomRecord5Array CustomRecord5[3]; - -type CustomRecord6Array CustomRecord6[]; - -type ClosedCustomRecord6Array CustomRecord6[3]; - -type CustomRecord7Array CustomRecord7[]; - -type ClosedCustomRecord7Array CustomRecord7[3]; - -type CustomRecord8Array CustomRecord8[]; - -type ClosedCustomRecord8Array CustomRecord8[3]; - -type CustomRecord9Array CustomRecord9[]; - -type ClosedCustomRecord9Array CustomRecord9[3]; - -type CustomRecord10Array CustomRecord10[]; - -type ClosedCustomRecord10Array CustomRecord10[3]; - -type CustomRecord11Array CustomRecord11[]; - -type ClosedCustomRecord11Array CustomRecord11[3]; - -type CustomRecord12Array CustomRecord12[]; - -type ClosedCustomRecord12Array CustomRecord12[3]; - -type CustomRecord13Array CustomRecord13[]; - -type ClosedCustomRecord13Array CustomRecord13[3]; - -type CustomRecord14Array CustomRecord14[]; - -type ClosedCustomRecord14Array CustomRecord14[3]; - -type CustomRecord15Array CustomRecord15[]; - -type CustomRecord16Array CustomRecord16[]; - -type CustomRecord17Array CustomRecord17[]; - -type CustomRecord18Array CustomRecord18[]; - -type CustomRecord19Array CustomRecord19[]; - -type CustomRecord20Array CustomRecord20[]; - -type CustomRecord21Array CustomRecord21[]; - -type CustomRecord22Array CustomRecord22[]; - -type CustomRecord23Array CustomRecord23[]; - -type CustomRecord24Array CustomRecord24[]; - -type CustomRecord25Array CustomRecord25[]; - -type CustomRecord26Array CustomRecord26[]; - -type CustomRecord27Array CustomRecord27[]; -type CustomRecord28Array CustomRecord28[]; -type CustomRecord29Array CustomRecord29[]; -type CustomRecord30Array CustomRecord30[]; -type CustomRecord31Array CustomRecord31[]; -type CustomRecord32Array CustomRecord32[]; -type CustomRecord33Array CustomRecord33[]; -type CustomRecord34Array CustomRecord34[]; -type CustomRecord35Array CustomRecord35[]; -type CustomRecord36Array CustomRecord36[]; -type CustomRecord37Array CustomRecord37[]; -type CustomRecord38Array CustomRecord38[]; -type CustomRecord39Array CustomRecord39[]; -type CustomRecord40Array CustomRecord40[]; -type CustomRecord41Array CustomRecord41[]; -type CustomRecord42Array CustomRecord42[]; -type CustomRecord43Array CustomRecord43[]; -type CustomRecord44Array CustomRecord44[]; -type CustomRecord45Array CustomRecord45[]; -type CustomRecord46Array CustomRecord46[]; -type CustomRecord47Array CustomRecord47[]; -type CustomRecord48Array CustomRecord48[]; -type CustomRecord49Array CustomRecord49[]; -type CustomRecord50Array CustomRecord50[]; -type CustomRecord51Array CustomRecord51[]; -type CustomRecord52Array CustomRecord52[]; -type CustomRecord53Array CustomRecord53[]; -type CustomRecord54Array CustomRecord54[]; -type CustomRecord55Array CustomRecord55[]; -type CustomRecord56Array CustomRecord56[]; - -type BooleanTuple1Array BooleanTuple1[]; - -type ClosedBooleanTuple1Array BooleanTuple1[3]; - -type BooleanTuple2Array BooleanTuple2[]; - -type ClosedBooleanTuple2Array BooleanTuple2[3]; - -type BooleanTuple3Array BooleanTuple3[]; - -type ClosedBooleanTuple3Array BooleanTuple3[3]; - -type BooleanTuple4Array BooleanTuple4[]; - -type ClosedBooleanTuple4Array BooleanTuple4[3]; - -type NillableBooleanTuple5Array NillableBooleanTuple5[]; - -type NillableBooleanTuple6Array NillableBooleanTuple6[]; - -type NillableBooleanTuple7Array NillableBooleanTuple7[]; - -type NillableBooleanTuple8Array NillableBooleanTuple8[]; - -type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; - -type NilTuple1Array NilTuple1[]; - -type ClosedNilTuple1Array NilTuple1[3]; - -type NilTuple2Array NilTuple2[]; - -type ClosedNilTuple2Array NilTuple2[3]; - -type NilTuple3Array NilTuple3[]; - -type ClosedNilTuple3Array NilTuple3[3]; - -type NilTuple4Array NilTuple4[]; - -type ClosedNilTuple4Array NilTuple4[3]; - -type IntegerTuple1Array IntegerTuple1[]; - -type ClosedIntegerTuple1Array IntegerTuple1[3]; - -type IntegerTuple2Array IntegerTuple2[]; - -type ClosedIntegerTuple2Array IntegerTuple2[3]; - -type IntegerTuple3Array IntegerTuple3[]; - -type ClosedIntegerTuple3Array IntegerTuple3[3]; - -type IntegerTuple4Array IntegerTuple4[]; - -type ClosedIntegerTuple4Array IntegerTuple4[3]; - -type FloatTuple1Array FloatTuple1[]; - -type ClosedFloatTuple1Array FloatTuple1[3]; - -type FloatTuple2Array FloatTuple2[]; - -type ClosedFloatTuple2Array FloatTuple2[3]; - -type FloatTuple3Array FloatTuple3[]; - -type ClosedFloatTuple3Array FloatTuple3[3]; - -type FloatTuple4Array FloatTuple4[]; - -type ClosedFloatTuple4Array FloatTuple4[3]; - -type DecimalTuple1Array DecimalTuple1[]; - -type ClosedDecimalTuple1Array DecimalTuple1[3]; - -type DecimalTuple2Array DecimalTuple2[]; - -type ClosedDecimalTuple2Array DecimalTuple2[3]; - -type DecimalTuple3Array DecimalTuple3[]; - -type ClosedDecimalTuple3Array DecimalTuple3[3]; - -type DecimalTuple4Array DecimalTuple4[]; - -type ClosedDecimalTuple4Array DecimalTuple4[3]; - -type StringTuple1Array StringTuple1[]; - -type ClosedStringTuple1Array StringTuple1[3]; - -type StringTuple2Array StringTuple2[]; - -type ClosedStringTuple2Array StringTuple2[3]; - -type StringTuple3Array StringTuple3[]; - -type ClosedStringTuple3Array StringTuple3[3]; - -type StringTuple4Array StringTuple4[]; - -type ClosedStringTuple4Array StringTuple4[3]; - -type AnydataTuple1Array AnydataTuple1[]; - -type ClosedAnydataTuple1Array AnydataTuple1[3]; - -type AnydataTuple2Array AnydataTuple2[]; - -type ClosedAnydataTuple2Array AnydataTuple2[3]; - -type AnydataTuple3Array AnydataTuple3[]; - -type ClosedAnydataTuple3Array AnydataTuple3[3]; - -type AnydataTuple4Array AnydataTuple4[]; - -type ClosedAnydataTuple4Array AnydataTuple4[3]; - -type JsonTuple1Array JsonTuple1[]; - -type ClosedJsonTuple1Array JsonTuple1[3]; - -type JsonTuple2Array JsonTuple2[]; - -type ClosedJsonTuple2Array JsonTuple2[3]; - -type JsonTuple3Array JsonTuple3[]; - -type ClosedJsonTuple3Array JsonTuple3[3]; - -type JsonTuple4Array JsonTuple4[]; - -type ClosedJsonTuple4Array JsonTuple4[3]; - -type CustomTuple1Array CustomTuple1[]; - -type ClosedCustomTuple1Array CustomTuple1[3]; - -type CustomTuple2Array CustomTuple2[]; - -type ClosedCustomTuple2Array CustomTuple2[3]; - -type CustomTuple3Array CustomTuple3[]; - -type ClosedCustomTuple3Array CustomTuple3[3]; - -type CustomTuple4Array CustomTuple4[]; - -type ClosedCustomTuple4Array CustomTuple4[3]; - -type CustomTuple5Array CustomTuple5[]; - -type ClosedCustomTuple5Array CustomTuple5[3]; - -type CustomTuple6Array CustomTuple6[]; - -type CustomTuple7Array CustomTuple7[]; - -type CustomTuple8Array CustomTuple8[]; - -type ClosedCustomTuple6Array CustomTuple6[3]; - -type IntegerArray1Array IntegerArray1[]; - -type ClosedIntegerArray1Array IntegerArray1[3]; - -type IntegerArray2Array IntegerArray2[]; - -type ClosedIntegerArray2Array IntegerArray2[3]; - -type IntegerArray3Array IntegerArray3[]; - -type ClosedIntegerArray3Array IntegerArray3[3]; - -type IntegerArray4Array IntegerArray4[]; - -type ClosedIntegerArray4Array IntegerArray4[3]; - -type IntegerArray5Array IntegerArray5[]; - -type ClosedIntegerArray5Array IntegerArray5[3]; - -type IntegerArray6Array IntegerArray5[]; - -type ClosedIntegerArray6Array IntegerArray5[3]; - -type StringArray1Array StringArray1[]; - -type StringArrayArray StringArray[]; - -type NillableStringArrayArray NillableStringArray[]; - -type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; - -type ClosedStringArray1Array StringArray1[3]; - -type StringArray2Array StringArray2[]; - -type ClosedStringArray2Array StringArray2[3]; - -type StringArray3Array StringArray3[]; - -type ClosedStringArray3Array StringArray3[3]; - -type StringArray4Array StringArray4[]; - -type ClosedStringArray4Array StringArray4[3]; - -type StringArray5Array StringArray5[]; - -type ClosedStringArray5Array StringArray5[3]; - -type StringArray6Array StringArray5[]; - -type ClosedStringArray6Array StringArray5[3]; - -type FloatArray1Array FloatArray1[]; - -type ClosedFloatArray1Array FloatArray1[3]; - -type FloatArray2Array FloatArray2[]; - -type ClosedFloatArray2Array FloatArray2[3]; - -type FloatArray3Array FloatArray3[]; - -type ClosedFloatArray3Array FloatArray3[3]; - -type FloatArray4Array FloatArray4[]; - -type ClosedFloatArray4Array FloatArray4[3]; - -type FloatArray5Array FloatArray5[]; - -type ClosedFloatArray5Array FloatArray5[3]; - -type FloatArray6Array FloatArray5[]; - -type ClosedFloatArray6Array FloatArray5[3]; - -type DecimalArray1Array DecimalArray1[]; - -type ClosedDecimalArray1Array DecimalArray1[3]; - -type DecimalArray2Array DecimalArray2[]; - -type ClosedDecimalArray2Array DecimalArray2[3]; - -type DecimalArray3Array DecimalArray3[]; - -type ClosedDecimalArray3Array DecimalArray3[3]; - -type DecimalArray4Array DecimalArray4[]; - -type ClosedDecimalArray4Array DecimalArray4[3]; - -type DecimalArray5Array DecimalArray5[]; - -type ClosedDecimalArray5Array DecimalArray5[3]; - -type DecimalArray6Array DecimalArray5[]; - -type ClosedDecimalArray6Array DecimalArray5[3]; - -type BooleanArrayArray BooleanArray[]; - -type ClosedBooleanArrayArray BooleanArray[3]; - -type NillableBooleanArrayArray NillableBooleanArray[]; - -type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; - -type BooleanArray2Array BooleanArray2[]; - -type ClosedBooleanArray2Array BooleanArray2[3]; - -type BooleanArray3Array BooleanArray3[]; - -type ClosedBooleanArray3Array BooleanArray3[3]; - -type BooleanArray4Array BooleanArray4[]; - -type ClosedBooleanArray4Array BooleanArray4[3]; - -type BooleanArray5Array BooleanArray5[]; - -type ClosedBooleanArray5Array BooleanArray5[3]; - -type BooleanArray6Array BooleanArray5[]; - -type ClosedBooleanArray6Array BooleanArray5[3]; - -type NilArray1Array NilArray1[]; - -type ClosedNilArray1Array NilArray1[3]; - -type NilArray2Array NilArray2[]; - -type ClosedNilArray2Array NilArray2[3]; - -type NilArray3Array NilArray3[]; - -type ClosedNilArray3Array NilArray3[3]; - -type NilArray4Array NilArray4[]; - -type ClosedNilArray4Array NilArray4[3]; - -type NilArray5Array NilArray5[]; - -type ClosedNilArray5Array NilArray5[3]; - -type NilArray6Array NilArray5[]; - -type ClosedNilArray6Array NilArray5[3]; - -type JsonArray1Array JsonArray1[]; - -type ClosedJsonArray1Array JsonArray1[3]; - -type JsonArray2Array JsonArray2[]; - -type ClosedJsonArray2Array JsonArray2[3]; - -type JsonArray3Array JsonArray3[]; - -type ClosedJsonArray3Array JsonArray3[3]; - -type JsonArray4Array JsonArray4[]; - -type ClosedJsonArray4Array JsonArray4[3]; - -type JsonArray5Array JsonArray5[]; - -type ClosedJsonArray5Array JsonArray5[3]; - -type JsonArray6Array JsonArray5[]; - -type ClosedJsonArray6Array JsonArray5[3]; +type AnydataMap map; +type JsonMap map; +type StringMap map; +type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; type AnydataArray1Array AnydataArray1[]; - -type ClosedAnydataArray1Array AnydataArray1[3]; - -type AnydataArray2Array AnydataArray2[]; - -type ClosedAnydataArray2Array AnydataArray2[3]; - -type AnydataArray3Array AnydataArray3[]; - -type ClosedAnydataArray3Array AnydataArray3[3]; - -type AnydataArray4Array AnydataArray4[]; - -type ClosedAnydataArray4Array AnydataArray4[3]; - -type AnydataArray5Array AnydataArray5[]; - -type ClosedAnydataArray5Array AnydataArray5[3]; - -type AnydataArray6Array AnydataArray5[]; - -type ClosedAnydataArray6Array AnydataArray5[3]; - -type CustomArray1Array CustomArray1[]; - -type ClosedCustomArray1Array CustomArray1[3]; - -type CustomArray2Array CustomArray2[]; - -type ClosedCustomArray2Array CustomArray2[3]; - -type CustomArray3Array CustomArray3[]; - -type ClosedCustomArray3Array CustomArray3[3]; - -type CustomArray4Array CustomArray4[]; - -type ClosedCustomArray4Array CustomArray4[3]; - -type CustomArray5Array CustomArray5[]; - -type ClosedCustomArray5Array CustomArray5[3]; - -type CustomArray6Array CustomArray5[]; - -type ClosedCustomArray6Array CustomArray5[3]; - -type IntegerMapArray IntegerMap[]; - -type ClosedIntegerMapArray IntegerMap[3]; - -type StringMapArray StringMap[]; - -type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; - -type IntUnionStringMapArray IntUnionStringMap[]; - -type ClosedStringMapArray StringMap[3]; - -type DecimalMapArray DecimalMap[]; - -type ClosedDecimalMapArray DecimalMap[3]; - -type FloatMapArray FloatMap[]; - -type ClosedFloatMapArray FloatMap[3]; - -type BooleanMapArray BooleanMap[]; - -type NillableBooleanMapArray NillableBooleanMap[]; - -type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; - -type IntUnionBooleanMapArray IntUnionBooleanMap[]; - -type ClosedBooleanMapArray BooleanMap[3]; - -type NilMapArray NilMap[]; - -type ClosedNilMapArray NilMap[3]; - -type JsonMapArray JsonMap[]; - -type ClosedJsonMapArray JsonMap[3]; - +type CustomRecord27Array CustomRecord27[]; type AnydataMapArray AnydataMap[]; - -type ClosedAnydataMapArray AnydataMap[3]; - -type CustomMapArray CustomMap[]; - -type ClosedCustomMapArray CustomMap[3]; +type JsonMapArray JsonMap[]; +type StringMapArray StringMap[]; +type CustomTuple7Array CustomTuple7[]; diff --git a/ballerina-tests/union-type-tests/tests/test_data_values.bal b/ballerina-tests/union-type-tests/tests/test_data_values.bal index a9698aa..7d88394 100644 --- a/ballerina-tests/union-type-tests/tests/test_data_values.bal +++ b/ballerina-tests/union-type-tests/tests/test_data_values.bal @@ -14,172 +14,6 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean? b3 = (); -boolean|int b4 = false; - -() n1 = (); -int? n2 = (); -() n3 = null; - -int i1 = 1; -int i2 = -2; -int i3 = int:MAX_VALUE; -int i4 = int:MIN_VALUE; -int i5 = 0; -2 i6 = 2; -int? i7 = (); -int|string i8 = 100; - -float f1 = 2.234; -float f2 = -3.21f; -float f3 = 0; -float f4 = float:Infinity; -float f5 = -float:Infinity; -float f6 = float:NaN; -2.3f f7 = 2.3; -float? f8 = (); -float|decimal f9 = 1.21; - -decimal d1 = 2.234; -decimal d2 = -3.21d; -decimal d3 = 0; -2.3d d4 = 2.3; -decimal? d5 = (); -decimal|int d6 = 1.21; - -string s1 = "string"; -string s2 = ""; -string:Char s3 = "a"; - -map bm1 = {b1, b2}; -map bm2 = {b1, b2, b3, n1, n3}; -map bm3 = {b1, b2, b3, b4, i1}; -map<()> bm4 = {n1, n3}; -map bm5 = {b1, b2, b3, b4:true}; - -map m5 = {i1, i2, i3, i4, i5, i6}; -map m6 = {f1, f2, f3, f4, f5, f6, f7}; -map m7 = {d1, d2, d3, d4}; -map m8 = {d1, f1, f9, f10: 1.23}; -map m9 = {s1, s2, s3}; -map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; -map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; - -boolean[] arr1 = [b1, b2]; -boolean?[] arr2 = [b1, b2, b3, n1, n3]; -(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; -()[] arr4 = [n1, n3]; -int[] arr5 = [i1, i2, i3, i4, i5, i6]; -float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; -decimal[] arr7 = [d1, d2, d3, d4]; -(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; -string[] arr9 = [s1, s2, s3]; -anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; - -[boolean, boolean] bt1 = [b1, b2]; -[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; -[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; -[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; -[boolean...] bt5 = [b1, b2]; - -[string, string] st1 = [s1, s2]; -[string, string, string, string] st2 = [s1, s2, s3, s2]; -[string...] st3 = [s1, s2]; -[string, string, string...] st4 = [s1, s2, s3, s2]; - -[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; -[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; -[string?...] st7 = [s1, s2]; -[string...] st8 = []; -[string, string, string] st9 = [s1, s2, s3]; - -[(), ()] tup4 = [n1, n3]; -[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; -[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; -[string, string, string] tup9 = [s1, s2, s3]; -[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, - n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, json] tup11 = - [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, - f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 -]; - -[boolean, boolean...] restTup1 = [b1, b2]; -[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; -[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; -[(), ()...] restTup4 = [n1, n3]; -[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; -[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal...] restTup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; -[string...] restTup9 = [s1, s2, s3]; -[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 -]; - -var booleanRecordArray = [ - {b1, b2, b3, b4}, {b1, b2, b3, b4} -]; - -var booleanRecordArray2 = [ - {},{} -]; - -string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 -true,false,true,false -true,false, true,false -true,false,true,false -`; - -string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 -true,false, true,false,true -true,false, true,false,true`; - -string csvStringWithBooleanValues3 = string `b1,b2,b3 -${" "}${"\t"} -true, false,true -${" "} - TRUE, FALSE,() -${" "} - -true, true,FALSE - -`; - -string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 - true,(), (),false - true,(), null,false - -`; - -string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 - -true,false,true,2 - -true,false,true,3 -`; - -string csvStringWithBooleanValues6 = string `b2,b3 -(),() - -`; - -string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 -${b1},${b2},(),${b4} -`; - string csvStringData1 = string ` a, b, c, d, e, f 1, string1, true, 2.234, 2.234, () @@ -187,86 +21,3 @@ string csvStringData1 = string ` 3, string3, false, 1.23, 1.23, () 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; - -string csvStringData2 = string ` - hello, hello, (), 12, true, 12.34 - // comment - - a, b, c, d, e, f - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData3 = string ` - a, b, c, d, e, f - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData4 = string ` - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - 5, string5, true, 3, 3, ()`; - -string csvStringData5 = string ` - - - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData6 = string ` - - 1, string1, true, 2.234, 2.234, () - 2, string2, false, 0, 0, null - - 3, string3, false, 1.23, 1.23, () - 4, string4, true, -6.51, -6.51, () - - 5, string5, true, 3, 3, ()`; - -string csvStringData7 = string ` - a@ b@ c@ d@ e@ f - 1@ string@ true@ 2.234@ -3.21@ () - 2@ s,tring@ true@ 2.234@ -3.21@ null - 3@ stri,ng@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; -string csvStringData8 = string ` - a@ b@ c@ d@ e@ f - - - - 1@ stri,ng@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ ()@-3.21 - 3@ string@ true@ 2.234@ -3.21@ null - - 4@ s,tring@ true@ 2.234@ -3.21@ () - 5@ string@ true@ 2.234@ -3.21@ ()`; - -string csvStringData9 = string ` - - 1@ string@ true@ 2.234@ -3.21@ () - 2@ string@ true@ 2.234@ -3.21@ null - - 3@ string@ true@ 2.234@ -3.21@ () - 4@ string@ true@ 2.234@ ()@-3.21 - - 5@ string@ true@ 2.234@ -3.21@ null`; diff --git a/ballerina-tests/union-type-tests/tests/types.bal b/ballerina-tests/union-type-tests/tests/types.bal deleted file mode 100644 index b496d60..0000000 --- a/ballerina-tests/union-type-tests/tests/types.bal +++ /dev/null @@ -1,2550 +0,0 @@ -// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// -// WSO2 LLC. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -type BooleanRecord1 record { - boolean b1; - boolean|string b2; - boolean|string? b3; - boolean b4; -}; - -type BooleanRecord2 record {| - boolean b1; - boolean|string b2; - boolean|string? b3; - boolean b4; -|}; - -type BooleanRecord3 record {| - boolean b1; - boolean? b3; -|}; - -type BooleanRecord4 record { - boolean b1; - boolean? b3; -}; - -type BooleanRecord5 record { - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); -}; - -type BooleanRecord6 record {| - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); -|}; - -type BooleanRecord7 record { - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type BooleanRecord8 record {| - boolean b1; - boolean? b3; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type BooleanRecord9 record {| - boolean b1; - boolean? b3; - boolean?...; -|}; - -type BooleanRecord10 record {| - boolean...; -|}; - -type BooleanRecord11 record {| - boolean b1; - string defaultableField = ""; - string? nillableField = (); - boolean?|string...; -|}; - -type BooleanRecord12 record {| - boolean b1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - boolean...; -|}; - -type BooleanRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - string|boolean...; -|}; - -type BooleanRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - boolean...; -|}; - -type BooleanRecord15 record {| - int b1; - string defaultableField = ""; - string? nillableField = (); - boolean?...; -|}; - -type BooleanRecord16 record {| - boolean?...; -|}; - -type BooleanRecord17 record {| - int...; -|}; - -type BooleanRecord18 record {| - boolean b2; - int?...; -|}; - -type NilRecord1 record { - () n1; - () n2; - () n3; -}; - -type NilRecord2 record {| - () n1; - () n2; - () n3; -|}; - -type NilRecord3 record {| - () n1; - () n4; -|}; - -type NilRecord4 record { - () n1; - () n4; -}; - -type NilRecord5 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -}; - -type NilRecord6 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type NilRecord7 record { - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type NilRecord8 record {| - () n1; - () n4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type NilRecord9 record {| - () n1; - () n2; - ()...; -|}; - -type NilRecord10 record {| - ()...; -|}; - -type NilRecord11 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord12 record {| - () n1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type NilRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - ()...; -|}; - -type NilRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - ()...; -|}; - -type IntegerRecord1 record { - int i1; - int i2; - int i3; - int? i4; - int? i5; - int i6; - int i7; - int? i8; -}; - -type IntegerRecord2 record {| - int i1; - int? i2; - int i3; - int i4; - int? i5; - int i6; - int i7; - int? i8; -|}; - -type IntegerRecord3 record {| - int i1; - int i4; - int i6; -|}; - -type IntegerRecord4 record { - int i1; - int i4; - int i6; -}; - -type IntegerRecord5 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -}; - -type IntegerRecord6 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); -|}; - -type IntegerRecord7 record { - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type IntegerRecord8 record {| - int i1; - int i4; - int i6; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type IntegerRecord9 record {| - int i1; - int i2; - int...; -|}; - -type IntegerRecord10 record {| - int...; -|}; - -type IntegerRecord11 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord12 record {| - int i1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type IntegerRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - int...; -|}; - -type IntegerRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - int...; -|}; - -type FloatRecord1 record { - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -}; - -type FloatRecord2 record {| - float f1; - float f2; - float f3; - float f4; - float f5; - float f6; - float f7; - float f8; -|}; - -type FloatRecord3 record {| - float f1; - float f4; - float f7; -|}; - -type FloatRecord4 record { - float f1; - float f4; - float f7; -}; - -type FloatRecord5 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -}; - -type FloatRecord6 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type FloatRecord7 record { - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type FloatRecord8 record {| - float f1; - float f4; - float f7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type FloatRecord9 record {| - float f1; - float f2; - float...; -|}; - -type FloatRecord10 record {| - float...; -|}; - -type FloatRecord11 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord12 record {| - float f1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type FloatRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - float...; -|}; - -type FloatRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - float...; -|}; - -type DecimalRecord1 record { - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -}; - -type DecimalRecord2 record {| - decimal d1; - decimal d2; - decimal d3; - decimal d4; - decimal d5; - decimal d6; - decimal d7; - decimal d8; -|}; - -type DecimalRecord3 record {| - decimal d1; - decimal d4; - decimal d7; -|}; - -type DecimalRecord4 record { - decimal d1; - decimal d4; - decimal d7; -}; - -type DecimalRecord5 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -}; - -type DecimalRecord6 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); -|}; - -type DecimalRecord7 record { - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type DecimalRecord8 record {| - decimal d1; - decimal d4; - decimal d7; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type DecimalRecord9 record {| - decimal d1; - decimal d2; - decimal...; -|}; - -type DecimalRecord10 record {| - decimal...; -|}; - -type DecimalRecord11 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord12 record {| - decimal d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type DecimalRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - decimal...; -|}; - -type DecimalRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - decimal...; -|}; - -type StringRecord1 record { - string s1; - string s2; - string s3; -}; - -type StringRecord2 record {| - string s1; - string s2; - string s3; -|}; - -type StringRecord3 record {| - string s1; - string s4; -|}; - -type StringRecord4 record { - string s1; - string s4; -}; - -type StringRecord5 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -}; - -type StringRecord6 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); -|}; - -type StringRecord7 record { - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -}; - -type StringRecord8 record {| - string s1; - string s4; - string defaultableField = ""; - string? nillableField = (); - string requiredField; -|}; - -type StringRecord9 record {| - string s1; - string s2; - string...; -|}; - -type StringRecord10 record {| - string...; -|}; - -type StringRecord11 record {| - string s1; - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord12 record {| - string d1; - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord13 record {| - string defaultableField = ""; - string? nillableField = (); - string...; -|}; - -type StringRecord14 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord15 record {| - string defaultableField = ""; - string? nillableField = (); - string requiredField; - string...; -|}; - -type StringRecord16 record {| - string?...; -|}; - -type StringRecord17 record {| - int...; -|}; - -type StringRecord18 record {| - string b2; - int?...; -|}; - -type StringRecord19 record { - string s1 = ""; - string s2 = ""; -}; - -type StringRecord20 record {| - string s1 = ""; - string s2 = ""; -|}; - -type StringRecord21 record { -}; - -type StringRecord22 record {| - string s1 = ""; - string s2 = ""; - json...; -|}; - -type StringRecord23 record {| - json...; -|}; - -type JsonRecord1 record { - json j1; - json j2; - json j3; -}; - -type JsonRecord2 record {| - json j1; - json j2; - json j3; -|}; - -type JsonRecord3 record {| - json j1; - json j4; -|}; - -type JsonRecord4 record { - json j1; - json j4; -}; - -type JsonRecord5 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -}; - -type JsonRecord6 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); -|}; - -type JsonRecord7 record { - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -}; - -type JsonRecord8 record {| - json j1; - json j4; - json defaultableField = ""; - json? nillableField = (); - json requiredField; -|}; - -type JsonRecord9 record {| - json j1; - json j2; - json...; -|}; - -type JsonRecord10 record {| - json...; -|}; - -type JsonRecord11 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord12 record {| - json j1; - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type JsonRecord13 record {| - json defaultableField = ""; - json? nillableField = (); - json...; -|}; - -type JsonRecord14 record {| - json defaultableField = ""; - json? nillableField = (); - json requiredField; - json...; -|}; - -type AnydataRecord1 record { - anydata anydata1; - anydata anydata2; - anydata anydata3; -}; - -type AnydataRecord2 record {| - anydata anydata1; - anydata anydata2; - anydata anydata3; -|}; - -type AnydataRecord3 record {| - anydata anydata1; - anydata anydata4; -|}; - -type AnydataRecord4 record { - anydata anydata1; - anydata anydata4; -}; - -type AnydataRecord5 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -}; - -type AnydataRecord6 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type AnydataRecord7 record { - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type AnydataRecord8 record {| - anydata anydata1; - anydata anydata4; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type AnydataRecord9 record {| - anydata anydata1; - anydata anydata2; - anydata...; -|}; - -type AnydataRecord10 record {| - anydata...; -|}; - -type AnydataRecord11 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord12 record {| - anydata anydata1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type AnydataRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata...; -|}; - -type AnydataRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - anydata...; -|}; - -type CustomRecord1 record { - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -}; - -type CustomRecord2 record {| - int i1; - int i2; - string s1; - string s2; - boolean b1; - boolean b2; - () n1; - () n2; - float f1; - float f2; - decimal d1; - decimal d2; -|}; - -type CustomRecord3 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -|}; - -type CustomRecord4 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; -}; - -type CustomRecord5 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string defaultableField = ""; - string? nillableField = (); -}; - -type CustomRecord6 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); -|}; - -type CustomRecord7 record { - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -}; - -type CustomRecord8 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; -|}; - -type CustomRecord9 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - string...; -|}; - -type CustomRecord10 record {| - string...; -|}; - -type CustomRecord11 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord12 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord13 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord14 record {| - anydata defaultableField = ""; - anydata? nillableField = (); - anydata requiredField; - string...; -|}; - -type CustomRecord15 record {| - string '1; - string '2; -|}; - -type CustomRecord16 record {| - string '1; - string '2; - string '3; - string '4; -|}; - -type CustomRecord17 record { - string '1; - string '2; -}; - -type CustomRecord18 record { - string '1; - string '2; - string '3; - string '4; -}; - -type CustomRecord19 record { - string '1; - string '2; - string '3 = ""; - string '4 = ""; -}; - -type CustomRecord20 record { - string '1; -}; - -type CustomRecord21 record {| - string '1; - json...; -|}; - -type CustomRecord22 record {| - string '1; - string...; -|}; - -type CustomRecord23 record {| - string '1; - string a = ""; - string...; -|}; - -type CustomRecord24 record {| - string '1; - string '2 = ""; - string...; -|}; - -type CustomRecord25 record {| - int '1; - string...; -|}; - -type CustomRecord26 record {| - string '1; - int...; -|}; - -type CustomRecord27 record {| - int i1; - string s1; - boolean b1; - () n1; - float f1; - decimal d1; - anydata a1; - json j1; - anydata defaultableField = ""; - anydata? nillableField = (); - string...; -|}; - -type CustomRecord28 record { - string '1; -}; - -type CustomRecord29 record { - int '1; -}; - -type CustomRecord30 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord31 record {| - string '1; - string '6; -|}; - -type CustomRecord32 record {| - int '1; -|}; - -type CustomRecord33 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; -|}; - -type CustomRecord34 record { - string '1; - string '6; - string '5 = ""; -}; - -type CustomRecord35 record { - string '1; - string '6; - string '9 = ""; -}; - -type CustomRecord36 record {| - string '1; - string '6; - string '9 = ""; -|}; - -type CustomRecord37 record {| - string '1; - string '6; - string '5 = ""; -|}; - -type CustomRecord38 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - string ...; -|}; - -type CustomRecord39 record {| - string '1; - string '2; - string '3; - string '4; - string '5; - string '6; - json ...; -|}; - -type CustomRecord40 record {| - string '5; - string '6; - json ...; -|}; - -type CustomRecord41 record {| - json ...; -|}; - -type CustomRecord42 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -|}; - -type CustomRecord43 record { - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; -}; - -type CustomRecord44 record {| - int '1; - string '2; - boolean '3; - decimal '4; - float '5; - () '6; - string ...; -|}; - -type CustomRecord45 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -|}; - -type CustomRecord46 record { - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; -}; - -type CustomRecord47 record {| - int H1; - string H2; - boolean H3; - decimal H4; - float H5; - () H6; - string ...; -|}; - -type CustomRecord48 record { - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -}; - -type CustomRecord49 record {| - string H1; - string H2; - string H3; - string H4; - string H5; - string H6; -|}; - -type CustomRecord50 record { - int H1; - float H4; -}; - -type CustomRecord51 record {| - int H1; - float H4; -|}; - -type CustomRecord52 record {| - string H1; - string H4; - string ...; -|}; - -type CustomRecord53 record {| - int H1; - float H4; - decimal ...; -|}; - -type CustomRecord54 record {| - string H1 = ""; - string H4; - string '1; -|}; - -type CustomRecord55 record {| - string H1 = ""; - string H4 = ""; - int '1 = 10; -|}; - -type CustomRecord56 record { - string H1 = ""; - string H4 = ""; - anydata '1 = 10; -}; - -type BooleanTuple1 [boolean, boolean, boolean, boolean]; - -type BooleanTuple2 [boolean, boolean]; - -type BooleanTuple3 [boolean, boolean...]; - -type BooleanTuple4 [boolean...]; - -type NillableBooleanTuple5 [boolean?, boolean?, boolean?, boolean?, boolean?]; - -type NillableBooleanTuple6 [boolean?, boolean?]; - -type NillableBooleanTuple7 [boolean?, boolean?, boolean?...]; - -type NillableBooleanTuple8 [boolean?...]; - -type NillableIntBooleanTuple9 [int|boolean?, int|boolean?...]; - -type NilTuple1 [(), (), ()]; - -type NilTuple2 [(), ()]; - -type NilTuple3 [(), ()...]; - -type NilTuple4 [()...]; - -type IntegerTuple1 [int, int, int, int, int, int]; - -type IntegerTuple2 [int, int]; - -type IntegerTuple3 [int, int...]; - -type IntegerTuple4 [int...]; - -type FloatTuple1 [float, float, float, float, float, float, float]; - -type FloatTuple2 [float, float]; - -type FloatTuple3 [float, float...]; - -type FloatTuple4 [float...]; - -type DecimalTuple1 [decimal, decimal, decimal, decimal]; - -type DecimalTuple2 [decimal, decimal]; - -type DecimalTuple3 [decimal, decimal...]; - -type DecimalTuple4 [decimal...]; - -type StringTuple1 [string, string, string, string]; - -type StringTuple2 [string, string]; - -type StringTuple3 [string, string...]; - -type StringTuple4 [string...]; - -type AnydataTuple1 [anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata]; - -type AnydataTuple2 [anydata, anydata]; - -type AnydataTuple3 [anydata, anydata...]; - -type AnydataTuple4 [anydata...]; - -type JsonTuple1 [json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json]; - -type JsonTuple2 [json, json]; - -type JsonTuple3 [json, json...]; - -type JsonTuple4 [json...]; - -type CustomTuple1 [string, int, decimal, float, (), boolean, anydata, json, string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple2 [string, int, decimal, float, (), boolean, anydata, json]; - -type CustomTuple3 [string, int, decimal, float, (), boolean, anydata, json, string...]; - -type CustomTuple4 [string...]; - -type CustomTuple5 [string, int, decimal, float, (), boolean, anydata, json, anydata...]; - -type CustomTuple6 [anydata...]; - -type CustomTuple7 [int, string, boolean, (), float, decimal, json, anydata, string...]; - -type CustomTuple8 [int, string, boolean, (), float, decimal, json, anydata, int...]; - -type IntegerArray1 int[]; - -type IntegerArray2 int[2]; - -type IntegerArray3 int[]; - -type IntegerArray4 int[2]; - -type IntegerArray5 int[3]; - -type IntegerArray6 int[4]; - -type StringArray string[]; - -type NillableStringArray string?[]; - -type NillableIntOrUnionStringArray (int|string?)[]; - -type StringArray1 string[]; - -type StringArray2 string[2]; - -type StringArray3 string[]; - -type StringArray4 string[2]; - -type StringArray5 string[3]; - -type StringArray6 string[4]; - -type FloatArray1 float[]; - -type FloatArray2 float[2]; - -type FloatArray3 float[]; - -type FloatArray4 float[2]; - -type FloatArray5 float[3]; - -type FloatArray6 float[4]; - -type DecimalArray1 decimal[]; - -type DecimalArray2 decimal[2]; - -type DecimalArray3 decimal[]; - -type DecimalArray4 decimal[2]; - -type DecimalArray5 decimal[3]; - -type DecimalArray6 decimal[4]; - -type BooleanArray boolean[]; - -type NillableBooleanArray boolean?[]; - -type NillableIntOrUnionBooleanArray (int|boolean?)[]; - -type BooleanArray2 boolean[2]; - -type BooleanArray3 boolean[3]; - -type BooleanArray4 boolean[]; - -type BooleanArray5 boolean[2]; - -type BooleanArray6 boolean[4]; - -type NilArray1 ()[]; - -type NilArray2 ()[2]; - -type NilArray3 ()[]; - -type NilArray4 ()[2]; - -type NilArray5 ()[3]; - -type NilArray6 ()[4]; - -type JsonArray1 json[]; - -type JsonArray2 json[2]; - -type JsonArray3 json[]; - -type JsonArray4 json[2]; - -type JsonArray5 json[3]; - -type JsonArray6 json[4]; - -type AnydataArray1 anydata[]; - -type AnydataArray2 anydata[2]; - -type AnydataArray3 anydata[]; - -type AnydataArray4 anydata[2]; - -type AnydataArray5 anydata[3]; - -type AnydataArray6 anydata[4]; - -type CustomArray1 CustomTuple2[]; - -type CustomArray2 CustomTuple2[2]; - -type CustomArray3 CustomTuple2[]; - -type CustomArray4 CustomTuple2[2]; - -type CustomArray5 CustomTuple2[3]; - -type CustomArray6 CustomTuple2[4]; - -type IntegerMap map; - -type StringMap map; - -type NillableIntUnionStringMap map; - -type IntUnionStringMap map; - -type DecimalMap map; - -type FloatMap map; - -type BooleanMap map; - -type NillableBooleanMap map; - -type NillableIntUnionBooleanMap map; - -type IntUnionBooleanMap map; - -type NilMap map<()>; - -type JsonMap map; - -type AnydataMap map; - -type CustomMap map; - -type BooleanRecord1Array BooleanRecord1[]; - -type ClosedBooleanRecord1Array BooleanRecord1[3]; - -type BooleanRecord2Array BooleanRecord2[]; - -type ClosedBooleanRecord2Array BooleanRecord2[3]; - -type BooleanRecord3Array BooleanRecord3[]; - -type ClosedBooleanRecord3Array BooleanRecord3[3]; - -type BooleanRecord4Array BooleanRecord4[]; - -type ClosedBooleanRecord4Array BooleanRecord4[3]; - -type BooleanRecord5Array BooleanRecord5[]; - -type ClosedBooleanRecord5Array BooleanRecord5[3]; - -type BooleanRecord6Array BooleanRecord6[]; - -type ClosedBooleanRecord6Array BooleanRecord6[3]; - -type BooleanRecord7Array BooleanRecord7[]; - -type ClosedBooleanRecord7Array BooleanRecord7[3]; - -type BooleanRecord8Array BooleanRecord8[]; - -type ClosedBooleanRecord8Array BooleanRecord8[3]; - -type BooleanRecord9Array BooleanRecord9[]; - -type ClosedBooleanRecord9Array BooleanRecord9[3]; - -type BooleanRecord10Array BooleanRecord10[]; - -type ClosedBooleanRecord10Array BooleanRecord10[3]; - -type BooleanRecord11Array BooleanRecord11[]; - -type ClosedBooleanRecord11Array BooleanRecord11[3]; - -type BooleanRecord12Array BooleanRecord12[]; - -type ClosedBooleanRecord12Array BooleanRecord12[3]; - -type BooleanRecord13Array BooleanRecord13[]; - -type ClosedBooleanRecord13Array BooleanRecord13[3]; - -type BooleanRecord14Array BooleanRecord14[]; - -type ClosedBooleanRecord14Array BooleanRecord14[3]; - -type BooleanRecord15Array BooleanRecord15[]; - -type ClosedBooleanRecord15Array BooleanRecord15[3]; - -type BooleanRecord16Array BooleanRecord16[]; - -type ClosedBooleanRecord16Array BooleanRecord16[3]; - -type BooleanRecord17Array BooleanRecord17[]; - -type ClosedBooleanRecord17Array BooleanRecord17[3]; - -type BooleanRecord18Array BooleanRecord18[]; - -type ClosedBooleanRecord18Array BooleanRecord18[3]; - -type NilRecord1Array NilRecord1[]; - -type ClosedNilRecord1Array NilRecord1[3]; - -type NilRecord2Array NilRecord2[]; - -type ClosedNilRecord2Array NilRecord2[3]; - -type NilRecord3Array NilRecord3[]; - -type ClosedNilRecord3Array NilRecord3[3]; - -type NilRecord4Array NilRecord4[]; - -type ClosedNilRecord4Array NilRecord4[3]; - -type NilRecord5Array NilRecord5[]; - -type ClosedNilRecord5Array NilRecord5[3]; - -type NilRecord6Array NilRecord6[]; - -type ClosedNilRecord6Array NilRecord6[3]; - -type NilRecord7Array NilRecord7[]; - -type ClosedNilRecord7Array NilRecord7[3]; - -type NilRecord8Array NilRecord8[]; - -type ClosedNilRecord8Array NilRecord8[3]; - -type NilRecord9Array NilRecord9[]; - -type ClosedNilRecord9Array NilRecord9[3]; - -type NilRecord10Array NilRecord10[]; - -type ClosedNilRecord10Array NilRecord10[3]; - -type NilRecord11Array NilRecord11[]; - -type ClosedNilRecord11Array NilRecord11[3]; - -type NilRecord12Array NilRecord12[]; - -type ClosedNilRecord12Array NilRecord12[3]; - -type NilRecord13Array NilRecord13[]; - -type ClosedNilRecord13Array NilRecord13[3]; - -type NilRecord14Array NilRecord14[]; - -type ClosedNilRecord14Array NilRecord14[3]; - -type IntegerRecord1Array IntegerRecord1[]; - -type ClosedIntegerRecord1Array IntegerRecord1[3]; - -type IntegerRecord2Array IntegerRecord2[]; - -type ClosedIntegerRecord2Array IntegerRecord2[3]; - -type IntegerRecord3Array IntegerRecord3[]; - -type ClosedIntegerRecord3Array IntegerRecord3[3]; - -type IntegerRecord4Array IntegerRecord4[]; - -type ClosedIntegerRecord4Array IntegerRecord4[3]; - -type IntegerRecord5Array IntegerRecord5[]; - -type ClosedIntegerRecord5Array IntegerRecord5[3]; - -type IntegerRecord6Array IntegerRecord6[]; - -type ClosedIntegerRecord6Array IntegerRecord6[3]; - -type IntegerRecord7Array IntegerRecord7[]; - -type ClosedIntegerRecord7Array IntegerRecord7[3]; - -type IntegerRecord8Array IntegerRecord8[]; - -type ClosedIntegerRecord8Array IntegerRecord8[3]; - -type IntegerRecord9Array IntegerRecord9[]; - -type ClosedIntegerRecord9Array IntegerRecord9[3]; - -type IntegerRecord10Array IntegerRecord10[]; - -type ClosedIntegerRecord10Array IntegerRecord10[3]; - -type IntegerRecord11Array IntegerRecord11[]; - -type ClosedIntegerRecord11Array IntegerRecord11[3]; - -type IntegerRecord12Array IntegerRecord12[]; - -type ClosedIntegerRecord12Array IntegerRecord12[3]; - -type IntegerRecord13Array IntegerRecord13[]; - -type ClosedIntegerRecord13Array IntegerRecord13[3]; - -type IntegerRecord14Array IntegerRecord14[]; - -type ClosedIntegerRecord14Array IntegerRecord14[3]; - -type FloatRecord1Array FloatRecord1[]; - -type ClosedFloatRecord1Array FloatRecord1[3]; - -type FloatRecord2Array FloatRecord2[]; - -type ClosedFloatRecord2Array FloatRecord2[3]; - -type FloatRecord3Array FloatRecord3[]; - -type ClosedFloatRecord3Array FloatRecord3[3]; - -type FloatRecord4Array FloatRecord4[]; - -type ClosedFloatRecord4Array FloatRecord4[3]; - -type FloatRecord5Array FloatRecord5[]; - -type ClosedFloatRecord5Array FloatRecord5[3]; - -type FloatRecord6Array FloatRecord6[]; - -type ClosedFloatRecord6Array FloatRecord6[3]; - -type FloatRecord7Array FloatRecord7[]; - -type ClosedFloatRecord7Array FloatRecord7[3]; - -type FloatRecord8Array FloatRecord8[]; - -type ClosedFloatRecord8Array FloatRecord8[3]; - -type FloatRecord9Array FloatRecord9[]; - -type ClosedFloatRecord9Array FloatRecord9[3]; - -type FloatRecord10Array FloatRecord10[]; - -type ClosedFloatRecord10Array FloatRecord10[3]; - -type FloatRecord11Array FloatRecord11[]; - -type ClosedFloatRecord11Array FloatRecord11[3]; - -type FloatRecord12Array FloatRecord12[]; - -type ClosedFloatRecord12Array FloatRecord12[3]; - -type FloatRecord13Array FloatRecord13[]; - -type ClosedFloatRecord13Array FloatRecord13[3]; - -type FloatRecord14Array FloatRecord14[]; - -type ClosedFloatRecord14Array FloatRecord14[3]; - -type DecimalRecord1Array DecimalRecord1[]; - -type ClosedDecimalRecord1Array DecimalRecord1[3]; - -type DecimalRecord2Array DecimalRecord2[]; - -type ClosedDecimalRecord2Array DecimalRecord2[3]; - -type DecimalRecord3Array DecimalRecord3[]; - -type ClosedDecimalRecord3Array DecimalRecord3[3]; - -type DecimalRecord4Array DecimalRecord4[]; - -type ClosedDecimalRecord4Array DecimalRecord4[3]; - -type DecimalRecord5Array DecimalRecord5[]; - -type ClosedDecimalRecord5Array DecimalRecord5[3]; - -type DecimalRecord6Array DecimalRecord6[]; - -type ClosedDecimalRecord6Array DecimalRecord6[3]; - -type DecimalRecord7Array DecimalRecord7[]; - -type ClosedDecimalRecord7Array DecimalRecord7[3]; - -type DecimalRecord8Array DecimalRecord8[]; - -type ClosedDecimalRecord8Array DecimalRecord8[3]; - -type DecimalRecord9Array DecimalRecord9[]; - -type ClosedDecimalRecord9Array DecimalRecord9[3]; - -type DecimalRecord10Array DecimalRecord10[]; - -type ClosedDecimalRecord10Array DecimalRecord10[3]; - -type DecimalRecord11Array DecimalRecord11[]; - -type ClosedDecimalRecord11Array DecimalRecord11[3]; - -type DecimalRecord12Array DecimalRecord12[]; - -type ClosedDecimalRecord12Array DecimalRecord12[3]; - -type DecimalRecord13Array DecimalRecord13[]; - -type ClosedDecimalRecord13Array DecimalRecord13[3]; - -type DecimalRecord14Array DecimalRecord14[]; - -type ClosedDecimalRecord14Array DecimalRecord14[3]; - -type StringRecord1Array StringRecord1[]; - -type ClosedStringRecord1Array StringRecord1[3]; - -type StringRecord2Array StringRecord2[]; - -type ClosedStringRecord2Array StringRecord2[3]; - -type StringRecord3Array StringRecord3[]; - -type ClosedStringRecord3Array StringRecord3[3]; - -type StringRecord4Array StringRecord4[]; - -type ClosedStringRecord4Array StringRecord4[3]; - -type StringRecord5Array StringRecord5[]; - -type ClosedStringRecord5Array StringRecord5[3]; - -type StringRecord6Array StringRecord6[]; - -type ClosedStringRecord6Array StringRecord6[3]; - -type StringRecord7Array StringRecord7[]; - -type ClosedStringRecord7Array StringRecord7[3]; - -type StringRecord8Array StringRecord8[]; - -type ClosedStringRecord8Array StringRecord8[3]; - -type StringRecord9Array StringRecord9[]; - -type ClosedStringRecord9Array StringRecord9[3]; - -type StringRecord10Array StringRecord10[]; - -type ClosedStringRecord10Array StringRecord10[3]; - -type StringRecord11Array StringRecord11[]; - -type ClosedStringRecord11Array StringRecord11[3]; - -type StringRecord12Array StringRecord12[]; - -type ClosedStringRecord12Array StringRecord12[3]; - -type StringRecord13Array StringRecord13[]; - -type ClosedStringRecord13Array StringRecord13[3]; - -type StringRecord14Array StringRecord14[]; - -type ClosedStringRecord14Array StringRecord14[3]; - -type StringRecord15Array StringRecord15[]; - -type StringRecord16Array StringRecord16[]; - -type StringRecord17Array StringRecord17[]; - -type StringRecord18Array StringRecord18[]; - -type StringRecord19Array StringRecord19[]; - -type StringRecord20Array StringRecord20[]; - -type StringRecord21Array StringRecord21[]; - -type StringRecord22Array StringRecord22[]; - -type StringRecord23Array StringRecord23[]; - -type JsonRecord1Array JsonRecord1[]; - -type ClosedJsonRecord1Array JsonRecord1[3]; - -type JsonRecord2Array JsonRecord2[]; - -type ClosedJsonRecord2Array JsonRecord2[3]; - -type JsonRecord3Array JsonRecord3[]; - -type ClosedJsonRecord3Array JsonRecord3[3]; - -type JsonRecord4Array JsonRecord4[]; - -type ClosedJsonRecord4Array JsonRecord4[3]; - -type JsonRecord5Array JsonRecord5[]; - -type ClosedJsonRecord5Array JsonRecord5[3]; - -type JsonRecord6Array JsonRecord6[]; - -type ClosedJsonRecord6Array JsonRecord6[3]; - -type JsonRecord7Array JsonRecord7[]; - -type ClosedJsonRecord7Array JsonRecord7[3]; - -type JsonRecord8Array JsonRecord8[]; - -type ClosedJsonRecord8Array JsonRecord8[3]; - -type JsonRecord9Array JsonRecord9[]; - -type ClosedJsonRecord9Array JsonRecord9[3]; - -type JsonRecord10Array JsonRecord10[]; - -type ClosedJsonRecord10Array JsonRecord10[3]; - -type JsonRecord11Array JsonRecord11[]; - -type ClosedJsonRecord11Array JsonRecord11[3]; - -type JsonRecord12Array JsonRecord12[]; - -type ClosedJsonRecord12Array JsonRecord12[3]; - -type JsonRecord13Array JsonRecord13[]; - -type ClosedJsonRecord13Array JsonRecord13[3]; - -type JsonRecord14Array JsonRecord14[]; - -type ClosedJsonRecord14Array JsonRecord14[3]; - -type AnydataRecord1Array AnydataRecord1[]; - -type ClosedAnydataRecord1Array AnydataRecord1[3]; - -type AnydataRecord2Array AnydataRecord2[]; - -type ClosedAnydataRecord2Array AnydataRecord2[3]; - -type AnydataRecord3Array AnydataRecord3[]; - -type ClosedAnydataRecord3Array AnydataRecord3[3]; - -type AnydataRecord4Array AnydataRecord4[]; - -type ClosedAnydataRecord4Array AnydataRecord4[3]; - -type AnydataRecord5Array AnydataRecord5[]; - -type ClosedAnydataRecord5Array AnydataRecord5[3]; - -type AnydataRecord6Array AnydataRecord6[]; - -type ClosedAnydataRecord6Array AnydataRecord6[3]; - -type AnydataRecord7Array AnydataRecord7[]; - -type ClosedAnydataRecord7Array AnydataRecord7[3]; - -type AnydataRecord8Array AnydataRecord8[]; - -type ClosedAnydataRecord8Array AnydataRecord8[3]; - -type AnydataRecord9Array AnydataRecord9[]; - -type ClosedAnydataRecord9Array AnydataRecord9[3]; - -type AnydataRecord10Array AnydataRecord10[]; - -type ClosedAnydataRecord10Array AnydataRecord10[3]; - -type AnydataRecord11Array AnydataRecord11[]; - -type ClosedAnydataRecord11Array AnydataRecord11[3]; - -type AnydataRecord12Array AnydataRecord12[]; - -type ClosedAnydataRecord12Array AnydataRecord12[3]; - -type AnydataRecord13Array AnydataRecord13[]; - -type ClosedAnydataRecord13Array AnydataRecord13[3]; - -type AnydataRecord14Array AnydataRecord14[]; - -type ClosedAnydataRecord14Array AnydataRecord14[3]; - -type CustomRecord1Array CustomRecord1[]; - -type ClosedCustomRecord1Array CustomRecord1[3]; - -type CustomRecord2Array CustomRecord2[]; - -type ClosedCustomRecord2Array CustomRecord2[3]; - -type CustomRecord3Array CustomRecord3[]; - -type ClosedCustomRecord3Array CustomRecord3[3]; - -type CustomRecord4Array CustomRecord4[]; - -type ClosedCustomRecord4Array CustomRecord4[3]; - -type CustomRecord5Array CustomRecord5[]; - -type ClosedCustomRecord5Array CustomRecord5[3]; - -type CustomRecord6Array CustomRecord6[]; - -type ClosedCustomRecord6Array CustomRecord6[3]; - -type CustomRecord7Array CustomRecord7[]; - -type ClosedCustomRecord7Array CustomRecord7[3]; - -type CustomRecord8Array CustomRecord8[]; - -type ClosedCustomRecord8Array CustomRecord8[3]; - -type CustomRecord9Array CustomRecord9[]; - -type ClosedCustomRecord9Array CustomRecord9[3]; - -type CustomRecord10Array CustomRecord10[]; - -type ClosedCustomRecord10Array CustomRecord10[3]; - -type CustomRecord11Array CustomRecord11[]; - -type ClosedCustomRecord11Array CustomRecord11[3]; - -type CustomRecord12Array CustomRecord12[]; - -type ClosedCustomRecord12Array CustomRecord12[3]; - -type CustomRecord13Array CustomRecord13[]; - -type ClosedCustomRecord13Array CustomRecord13[3]; - -type CustomRecord14Array CustomRecord14[]; - -type ClosedCustomRecord14Array CustomRecord14[3]; - -type CustomRecord15Array CustomRecord15[]; - -type CustomRecord16Array CustomRecord16[]; - -type CustomRecord17Array CustomRecord17[]; - -type CustomRecord18Array CustomRecord18[]; - -type CustomRecord19Array CustomRecord19[]; - -type CustomRecord20Array CustomRecord20[]; - -type CustomRecord21Array CustomRecord21[]; - -type CustomRecord22Array CustomRecord22[]; - -type CustomRecord23Array CustomRecord23[]; - -type CustomRecord24Array CustomRecord24[]; - -type CustomRecord25Array CustomRecord25[]; - -type CustomRecord26Array CustomRecord26[]; - -type CustomRecord27Array CustomRecord27[]; -type CustomRecord28Array CustomRecord28[]; -type CustomRecord29Array CustomRecord29[]; -type CustomRecord30Array CustomRecord30[]; -type CustomRecord31Array CustomRecord31[]; -type CustomRecord32Array CustomRecord32[]; -type CustomRecord33Array CustomRecord33[]; -type CustomRecord34Array CustomRecord34[]; -type CustomRecord35Array CustomRecord35[]; -type CustomRecord36Array CustomRecord36[]; -type CustomRecord37Array CustomRecord37[]; -type CustomRecord38Array CustomRecord38[]; -type CustomRecord39Array CustomRecord39[]; -type CustomRecord40Array CustomRecord40[]; -type CustomRecord41Array CustomRecord41[]; -type CustomRecord42Array CustomRecord42[]; -type CustomRecord43Array CustomRecord43[]; -type CustomRecord44Array CustomRecord44[]; -type CustomRecord45Array CustomRecord45[]; -type CustomRecord46Array CustomRecord46[]; -type CustomRecord47Array CustomRecord47[]; -type CustomRecord48Array CustomRecord48[]; -type CustomRecord49Array CustomRecord49[]; -type CustomRecord50Array CustomRecord50[]; -type CustomRecord51Array CustomRecord51[]; -type CustomRecord52Array CustomRecord52[]; -type CustomRecord53Array CustomRecord53[]; -type CustomRecord54Array CustomRecord54[]; -type CustomRecord55Array CustomRecord55[]; -type CustomRecord56Array CustomRecord56[]; - -type BooleanTuple1Array BooleanTuple1[]; - -type ClosedBooleanTuple1Array BooleanTuple1[3]; - -type BooleanTuple2Array BooleanTuple2[]; - -type ClosedBooleanTuple2Array BooleanTuple2[3]; - -type BooleanTuple3Array BooleanTuple3[]; - -type ClosedBooleanTuple3Array BooleanTuple3[3]; - -type BooleanTuple4Array BooleanTuple4[]; - -type ClosedBooleanTuple4Array BooleanTuple4[3]; - -type NillableBooleanTuple5Array NillableBooleanTuple5[]; - -type NillableBooleanTuple6Array NillableBooleanTuple6[]; - -type NillableBooleanTuple7Array NillableBooleanTuple7[]; - -type NillableBooleanTuple8Array NillableBooleanTuple8[]; - -type NillableIntBooleanTuple9Array NillableIntBooleanTuple9[]; - -type NilTuple1Array NilTuple1[]; - -type ClosedNilTuple1Array NilTuple1[3]; - -type NilTuple2Array NilTuple2[]; - -type ClosedNilTuple2Array NilTuple2[3]; - -type NilTuple3Array NilTuple3[]; - -type ClosedNilTuple3Array NilTuple3[3]; - -type NilTuple4Array NilTuple4[]; - -type ClosedNilTuple4Array NilTuple4[3]; - -type IntegerTuple1Array IntegerTuple1[]; - -type ClosedIntegerTuple1Array IntegerTuple1[3]; - -type IntegerTuple2Array IntegerTuple2[]; - -type ClosedIntegerTuple2Array IntegerTuple2[3]; - -type IntegerTuple3Array IntegerTuple3[]; - -type ClosedIntegerTuple3Array IntegerTuple3[3]; - -type IntegerTuple4Array IntegerTuple4[]; - -type ClosedIntegerTuple4Array IntegerTuple4[3]; - -type FloatTuple1Array FloatTuple1[]; - -type ClosedFloatTuple1Array FloatTuple1[3]; - -type FloatTuple2Array FloatTuple2[]; - -type ClosedFloatTuple2Array FloatTuple2[3]; - -type FloatTuple3Array FloatTuple3[]; - -type ClosedFloatTuple3Array FloatTuple3[3]; - -type FloatTuple4Array FloatTuple4[]; - -type ClosedFloatTuple4Array FloatTuple4[3]; - -type DecimalTuple1Array DecimalTuple1[]; - -type ClosedDecimalTuple1Array DecimalTuple1[3]; - -type DecimalTuple2Array DecimalTuple2[]; - -type ClosedDecimalTuple2Array DecimalTuple2[3]; - -type DecimalTuple3Array DecimalTuple3[]; - -type ClosedDecimalTuple3Array DecimalTuple3[3]; - -type DecimalTuple4Array DecimalTuple4[]; - -type ClosedDecimalTuple4Array DecimalTuple4[3]; - -type StringTuple1Array StringTuple1[]; - -type ClosedStringTuple1Array StringTuple1[3]; - -type StringTuple2Array StringTuple2[]; - -type ClosedStringTuple2Array StringTuple2[3]; - -type StringTuple3Array StringTuple3[]; - -type ClosedStringTuple3Array StringTuple3[3]; - -type StringTuple4Array StringTuple4[]; - -type ClosedStringTuple4Array StringTuple4[3]; - -type AnydataTuple1Array AnydataTuple1[]; - -type ClosedAnydataTuple1Array AnydataTuple1[3]; - -type AnydataTuple2Array AnydataTuple2[]; - -type ClosedAnydataTuple2Array AnydataTuple2[3]; - -type AnydataTuple3Array AnydataTuple3[]; - -type ClosedAnydataTuple3Array AnydataTuple3[3]; - -type AnydataTuple4Array AnydataTuple4[]; - -type ClosedAnydataTuple4Array AnydataTuple4[3]; - -type JsonTuple1Array JsonTuple1[]; - -type ClosedJsonTuple1Array JsonTuple1[3]; - -type JsonTuple2Array JsonTuple2[]; - -type ClosedJsonTuple2Array JsonTuple2[3]; - -type JsonTuple3Array JsonTuple3[]; - -type ClosedJsonTuple3Array JsonTuple3[3]; - -type JsonTuple4Array JsonTuple4[]; - -type ClosedJsonTuple4Array JsonTuple4[3]; - -type CustomTuple1Array CustomTuple1[]; - -type ClosedCustomTuple1Array CustomTuple1[3]; - -type CustomTuple2Array CustomTuple2[]; - -type ClosedCustomTuple2Array CustomTuple2[3]; - -type CustomTuple3Array CustomTuple3[]; - -type ClosedCustomTuple3Array CustomTuple3[3]; - -type CustomTuple4Array CustomTuple4[]; - -type ClosedCustomTuple4Array CustomTuple4[3]; - -type CustomTuple5Array CustomTuple5[]; - -type ClosedCustomTuple5Array CustomTuple5[3]; - -type CustomTuple6Array CustomTuple6[]; - -type CustomTuple7Array CustomTuple7[]; - -type CustomTuple8Array CustomTuple8[]; - -type ClosedCustomTuple6Array CustomTuple6[3]; - -type IntegerArray1Array IntegerArray1[]; - -type ClosedIntegerArray1Array IntegerArray1[3]; - -type IntegerArray2Array IntegerArray2[]; - -type ClosedIntegerArray2Array IntegerArray2[3]; - -type IntegerArray3Array IntegerArray3[]; - -type ClosedIntegerArray3Array IntegerArray3[3]; - -type IntegerArray4Array IntegerArray4[]; - -type ClosedIntegerArray4Array IntegerArray4[3]; - -type IntegerArray5Array IntegerArray5[]; - -type ClosedIntegerArray5Array IntegerArray5[3]; - -type IntegerArray6Array IntegerArray5[]; - -type ClosedIntegerArray6Array IntegerArray5[3]; - -type StringArray1Array StringArray1[]; - -type StringArrayArray StringArray[]; - -type NillableStringArrayArray NillableStringArray[]; - -type NillableIntOrUnionStringArrayArray NillableIntOrUnionStringArray[]; - -type ClosedStringArray1Array StringArray1[3]; - -type StringArray2Array StringArray2[]; - -type ClosedStringArray2Array StringArray2[3]; - -type StringArray3Array StringArray3[]; - -type ClosedStringArray3Array StringArray3[3]; - -type StringArray4Array StringArray4[]; - -type ClosedStringArray4Array StringArray4[3]; - -type StringArray5Array StringArray5[]; - -type ClosedStringArray5Array StringArray5[3]; - -type StringArray6Array StringArray5[]; - -type ClosedStringArray6Array StringArray5[3]; - -type FloatArray1Array FloatArray1[]; - -type ClosedFloatArray1Array FloatArray1[3]; - -type FloatArray2Array FloatArray2[]; - -type ClosedFloatArray2Array FloatArray2[3]; - -type FloatArray3Array FloatArray3[]; - -type ClosedFloatArray3Array FloatArray3[3]; - -type FloatArray4Array FloatArray4[]; - -type ClosedFloatArray4Array FloatArray4[3]; - -type FloatArray5Array FloatArray5[]; - -type ClosedFloatArray5Array FloatArray5[3]; - -type FloatArray6Array FloatArray5[]; - -type ClosedFloatArray6Array FloatArray5[3]; - -type DecimalArray1Array DecimalArray1[]; - -type ClosedDecimalArray1Array DecimalArray1[3]; - -type DecimalArray2Array DecimalArray2[]; - -type ClosedDecimalArray2Array DecimalArray2[3]; - -type DecimalArray3Array DecimalArray3[]; - -type ClosedDecimalArray3Array DecimalArray3[3]; - -type DecimalArray4Array DecimalArray4[]; - -type ClosedDecimalArray4Array DecimalArray4[3]; - -type DecimalArray5Array DecimalArray5[]; - -type ClosedDecimalArray5Array DecimalArray5[3]; - -type DecimalArray6Array DecimalArray5[]; - -type ClosedDecimalArray6Array DecimalArray5[3]; - -type BooleanArrayArray BooleanArray[]; - -type ClosedBooleanArrayArray BooleanArray[3]; - -type NillableBooleanArrayArray NillableBooleanArray[]; - -type NillableIntOrUnionBooleanArrayArray NillableIntOrUnionBooleanArray[]; - -type BooleanArray2Array BooleanArray2[]; - -type ClosedBooleanArray2Array BooleanArray2[3]; - -type BooleanArray3Array BooleanArray3[]; - -type ClosedBooleanArray3Array BooleanArray3[3]; - -type BooleanArray4Array BooleanArray4[]; - -type ClosedBooleanArray4Array BooleanArray4[3]; - -type BooleanArray5Array BooleanArray5[]; - -type ClosedBooleanArray5Array BooleanArray5[3]; - -type BooleanArray6Array BooleanArray5[]; - -type ClosedBooleanArray6Array BooleanArray5[3]; - -type NilArray1Array NilArray1[]; - -type ClosedNilArray1Array NilArray1[3]; - -type NilArray2Array NilArray2[]; - -type ClosedNilArray2Array NilArray2[3]; - -type NilArray3Array NilArray3[]; - -type ClosedNilArray3Array NilArray3[3]; - -type NilArray4Array NilArray4[]; - -type ClosedNilArray4Array NilArray4[3]; - -type NilArray5Array NilArray5[]; - -type ClosedNilArray5Array NilArray5[3]; - -type NilArray6Array NilArray5[]; - -type ClosedNilArray6Array NilArray5[3]; - -type JsonArray1Array JsonArray1[]; - -type ClosedJsonArray1Array JsonArray1[3]; - -type JsonArray2Array JsonArray2[]; - -type ClosedJsonArray2Array JsonArray2[3]; - -type JsonArray3Array JsonArray3[]; - -type ClosedJsonArray3Array JsonArray3[3]; - -type JsonArray4Array JsonArray4[]; - -type ClosedJsonArray4Array JsonArray4[3]; - -type JsonArray5Array JsonArray5[]; - -type ClosedJsonArray5Array JsonArray5[3]; - -type JsonArray6Array JsonArray5[]; - -type ClosedJsonArray6Array JsonArray5[3]; - -type AnydataArray1Array AnydataArray1[]; - -type ClosedAnydataArray1Array AnydataArray1[3]; - -type AnydataArray2Array AnydataArray2[]; - -type ClosedAnydataArray2Array AnydataArray2[3]; - -type AnydataArray3Array AnydataArray3[]; - -type ClosedAnydataArray3Array AnydataArray3[3]; - -type AnydataArray4Array AnydataArray4[]; - -type ClosedAnydataArray4Array AnydataArray4[3]; - -type AnydataArray5Array AnydataArray5[]; - -type ClosedAnydataArray5Array AnydataArray5[3]; - -type AnydataArray6Array AnydataArray5[]; - -type ClosedAnydataArray6Array AnydataArray5[3]; - -type CustomArray1Array CustomArray1[]; - -type ClosedCustomArray1Array CustomArray1[3]; - -type CustomArray2Array CustomArray2[]; - -type ClosedCustomArray2Array CustomArray2[3]; - -type CustomArray3Array CustomArray3[]; - -type ClosedCustomArray3Array CustomArray3[3]; - -type CustomArray4Array CustomArray4[]; - -type ClosedCustomArray4Array CustomArray4[3]; - -type CustomArray5Array CustomArray5[]; - -type ClosedCustomArray5Array CustomArray5[3]; - -type CustomArray6Array CustomArray5[]; - -type ClosedCustomArray6Array CustomArray5[3]; - -type IntegerMapArray IntegerMap[]; - -type ClosedIntegerMapArray IntegerMap[3]; - -type StringMapArray StringMap[]; - -type NillableIntUnionStringMapArray NillableIntUnionStringMap[]; - -type IntUnionStringMapArray IntUnionStringMap[]; - -type ClosedStringMapArray StringMap[3]; - -type DecimalMapArray DecimalMap[]; - -type ClosedDecimalMapArray DecimalMap[3]; - -type FloatMapArray FloatMap[]; - -type ClosedFloatMapArray FloatMap[3]; - -type BooleanMapArray BooleanMap[]; - -type NillableBooleanMapArray NillableBooleanMap[]; - -type NillableIntUnionBooleanMapArray NillableIntUnionBooleanMap[]; - -type IntUnionBooleanMapArray IntUnionBooleanMap[]; - -type ClosedBooleanMapArray BooleanMap[3]; - -type NilMapArray NilMap[]; - -type ClosedNilMapArray NilMap[3]; - -type JsonMapArray JsonMap[]; - -type ClosedJsonMapArray JsonMap[3]; - -type AnydataMapArray AnydataMap[]; - -type ClosedAnydataMapArray AnydataMap[3]; - -type CustomMapArray CustomMap[]; - -type ClosedCustomMapArray CustomMap[3]; diff --git a/ballerina-tests/user-config-tests/tests/test_data_values.bal b/ballerina-tests/user-config-tests/tests/test_data_values.bal index a9698aa..f067976 100644 --- a/ballerina-tests/user-config-tests/tests/test_data_values.bal +++ b/ballerina-tests/user-config-tests/tests/test_data_values.bal @@ -24,34 +24,6 @@ int? n2 = (); () n3 = null; int i1 = 1; -int i2 = -2; -int i3 = int:MAX_VALUE; -int i4 = int:MIN_VALUE; -int i5 = 0; -2 i6 = 2; -int? i7 = (); -int|string i8 = 100; - -float f1 = 2.234; -float f2 = -3.21f; -float f3 = 0; -float f4 = float:Infinity; -float f5 = -float:Infinity; -float f6 = float:NaN; -2.3f f7 = 2.3; -float? f8 = (); -float|decimal f9 = 1.21; - -decimal d1 = 2.234; -decimal d2 = -3.21d; -decimal d3 = 0; -2.3d d4 = 2.3; -decimal? d5 = (); -decimal|int d6 = 1.21; - -string s1 = "string"; -string s2 = ""; -string:Char s3 = "a"; map bm1 = {b1, b2}; map bm2 = {b1, b2, b3, n1, n3}; @@ -59,127 +31,6 @@ map bm3 = {b1, b2, b3, b4, i1}; map<()> bm4 = {n1, n3}; map bm5 = {b1, b2, b3, b4:true}; -map m5 = {i1, i2, i3, i4, i5, i6}; -map m6 = {f1, f2, f3, f4, f5, f6, f7}; -map m7 = {d1, d2, d3, d4}; -map m8 = {d1, f1, f9, f10: 1.23}; -map m9 = {s1, s2, s3}; -map m10 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; -map m11 = {b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8}; - -boolean[] arr1 = [b1, b2]; -boolean?[] arr2 = [b1, b2, b3, n1, n3]; -(boolean|int?)[] arr3 = [b1, b2, b3, b4, i1]; -()[] arr4 = [n1, n3]; -int[] arr5 = [i1, i2, i3, i4, i5, i6]; -float[] arr6 = [f1, f2, f3, f4, f5, f6, f7]; -decimal[] arr7 = [d1, d2, d3, d4]; -(decimal|float)[] arr8 = [d1, f1, f9, 1.23]; -string[] arr9 = [s1, s2, s3]; -anydata[] arr10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -json[] arr11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; - -[boolean, boolean] bt1 = [b1, b2]; -[boolean, boolean, boolean, boolean] bt2 = [b1, b2, b1, b2]; -[boolean?, boolean?, boolean?, boolean?, boolean?] bt3 = [b1, b2, b3, n1, n3]; -[boolean|int?, boolean|int?, boolean|int?, boolean|int?, boolean|int?] bt4 = [b1, b2, b3, b4, i1]; -[boolean...] bt5 = [b1, b2]; - -[string, string] st1 = [s1, s2]; -[string, string, string, string] st2 = [s1, s2, s3, s2]; -[string...] st3 = [s1, s2]; -[string, string, string...] st4 = [s1, s2, s3, s2]; - -[string?, string?, string?, string?, string?] st5 = [s1, s2, s3, n1, n3]; -[string|int?, string|int?, string|int?, string|int?, string|int?] st6 = [s1, s2, s3, n1, i1]; -[string?...] st7 = [s1, s2]; -[string...] st8 = []; -[string, string, string] st9 = [s1, s2, s3]; - -[(), ()] tup4 = [n1, n3]; -[int, int, int, int, int, int] tup5 = [i1, i2, i3, i4, i5, i6]; -[float, float, float, float, float, float, float] tup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal, decimal, decimal, decimal] tup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float, decimal|float, decimal|float] tup8 = [d1, f1, f9, 1.23]; -[string, string, string] tup9 = [s1, s2, s3]; -[anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata, anydata, - anydata, anydata, anydata, anydata, anydata, anydata, anydata] tup10 = [b1, b2, b3, b4, - n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json, json, json, json, json, json, json, json, json, json, - json, json, json, json, json, json, json, json, json, json, json] tup11 = - [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, - f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float] tup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2 -]; - -[boolean, boolean...] restTup1 = [b1, b2]; -[boolean?, boolean?, boolean?...] restTup2 = [b1, b2, b3, n1, n3]; -[boolean|int?...] restTup3 = [b1, b2, b3, b4, i1]; -[(), ()...] restTup4 = [n1, n3]; -[int...] restTup5 = [i1, i2, i3, i4, i5, i6]; -[float...] restTup6 = [f1, f2, f3, f4, f5, f6, f7]; -[decimal...] restTup7 = [d1, d2, d3, d4]; -[decimal|float, decimal|float...] restTup8 = [d1, f1, f9, 1.23]; -[string...] restTup9 = [s1, s2, s3]; -[anydata...] restTup10 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[json, json, json...] restTup11 = [b1, b2, b3, b4, n1, n2, n3, i1, i2, i3, i4, i5, i6, i7, i8, f1, f2, f3, f4, f5, f6, f7, f8]; -[string, string, int, int, boolean, boolean, (), (), decimal, decimal, float, float...] restTup12 = [ - s1, s2, i1, i2, b1, b2, n1, n3, d1, d2, f1, f2, f2, f2 -]; - -var booleanRecordArray = [ - {b1, b2, b3, b4}, {b1, b2, b3, b4} -]; - -var booleanRecordArray2 = [ - {},{} -]; - -string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 -true,false,true,false -true,false, true,false -true,false,true,false -`; - -string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 -true,false, true,false,true -true,false, true,false,true`; - -string csvStringWithBooleanValues3 = string `b1,b2,b3 -${" "}${"\t"} -true, false,true -${" "} - TRUE, FALSE,() -${" "} - -true, true,FALSE - -`; - -string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 - true,(), (),false - true,(), null,false - -`; - -string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 - -true,false,true,2 - -true,false,true,3 -`; - -string csvStringWithBooleanValues6 = string `b2,b3 -(),() - -`; - -string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 -${b1},${b2},(),${b4} -`; - string csvStringData1 = string ` a, b, c, d, e, f 1, string1, true, 2.234, 2.234, () diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index ea02379..08110a8 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -13,7 +13,7 @@ export = ["data.csv"] graalvmCompatible = true [[platform.java17.dependency]] -groupId = "io.ballerina.stdlib" +groupId = "io.ballerina.lib" artifactId = "data.csv-native" version = "@toml.version@" path = "../native/build/libs/data.csv-native-@project.version@.jar" diff --git a/compiler-plugin-test/src/test/resources/testng.xml b/compiler-plugin-test/src/test/resources/testng.xml index 02c1d8e..9ab3a2f 100644 --- a/compiler-plugin-test/src/test/resources/testng.xml +++ b/compiler-plugin-test/src/test/resources/testng.xml @@ -21,7 +21,7 @@ - + diff --git a/compiler-plugin/src/main/java/module-info.java b/compiler-plugin/src/main/java/module-info.java index 60ac711..cf8cc26 100644 --- a/compiler-plugin/src/main/java/module-info.java +++ b/compiler-plugin/src/main/java/module-info.java @@ -16,7 +16,7 @@ * under the License. */ -module io.ballerina.stdlib.csvdata.compiler { +module io.ballerina.lib.csvdata.compiler { requires io.ballerina.lang; requires io.ballerina.tools.api; requires io.ballerina.parser; diff --git a/gradle.properties b/gradle.properties index 9ef82e1..7404bdb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ org.gradle.caching=true -group=io.ballerina.stdlib +group=io.ballerina.lib version=0.1.0-SNAPSHOT ballerinaLangVersion=2201.9.0 ballerinaTomlParserVersion=1.2.2 diff --git a/native/src/main/java/module-info.java b/native/src/main/java/module-info.java index de54042..27c1c99 100644 --- a/native/src/main/java/module-info.java +++ b/native/src/main/java/module-info.java @@ -16,7 +16,7 @@ * under the License. */ -module io.ballerina.stdlib.data { +module io.ballerina.lib.data { requires io.ballerina.runtime; requires io.ballerina.lang.value; requires junit; From c19365665b047ee3092851cd97f1db9547974db5 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 30 Jul 2024 10:05:58 +0530 Subject: [PATCH 085/147] Add type cast for consitions --- .../java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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 6a306dd..d3e0817 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 @@ -152,7 +152,7 @@ public static boolean checkTypeCompatibility(Type constraintType, Object csv, bo return true; } } - if (Boolean.class.isInstance(csv)) { + if (csv instanceof Boolean) { if (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag)) { return true; } @@ -170,8 +170,7 @@ private static boolean isJsonOrAnyDataOrAny(int tag) { } public static int getTheActualExpectedType(Type type) { - if (type instanceof TupleType) { - TupleType tupleType = (TupleType) type; + if (type instanceof TupleType tupleType) { if (tupleType.getRestType() != null) { return -1; } From 6f549a09e30707d5cdd86029132836c9d1e453e6 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 30 Jul 2024 11:26:43 +0530 Subject: [PATCH 086/147] Add ballerina files to code coverage tests --- ballerina/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/build.gradle b/ballerina/build.gradle index efa4833..e6a4092 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -60,7 +60,7 @@ def stripBallerinaExtensionVersion(String extVersion) { apply plugin: 'io.ballerina.plugin' ballerina { - testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.lib.data.*:ballerina.*" + testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.lib.data.csvdata.*:ballerina.*" packageOrganization = packageOrg module = packageName langVersion = ballerinaLangVersion From 2a8548300941c9e62a5af02f791ae4488e2aee2d Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 30 Jul 2024 14:46:22 +0530 Subject: [PATCH 087/147] Update graalvm properties --- build-config/resources/BallerinaTest.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-config/resources/BallerinaTest.toml b/build-config/resources/BallerinaTest.toml index 2b8bad6..5b44930 100644 --- a/build-config/resources/BallerinaTest.toml +++ b/build-config/resources/BallerinaTest.toml @@ -13,4 +13,4 @@ version = "@toml.version@" graalvmCompatible = true [build-options] -graalvmBuildOptions = "-H:IncludeLocales=en_US,fr_FR" +graalvmBuildOptions = "-H:+IncludeAllLocales" From 4b0e9d283f84c0643f263d290ddc0bfb877aa022 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 30 Jul 2024 14:46:36 +0530 Subject: [PATCH 088/147] Update test function for locale --- .../user_config_with_parser_options_test.bal | 74 +++++++++---------- 1 file changed, 37 insertions(+), 37 deletions(-) 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 4453312..9ec2c09 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 @@ -19,6 +19,36 @@ import ballerina/data.csv; import ballerina/test; @test:Config +function testCSVLocale() { + record {|string name; decimal completed\ tasks; string city;|}[]|csv:Error rec; + + rec = csv:parseStringToRecord(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:Config +function testCSVEncoding() returns error? { + record {}[]|csv:Error rec; + + string csvStr = string `value + Alice + 2πr + €123`; + byte[] csvBytes = string:toBytes(csvStr); + + rec = csv:parseBytesToRecord(csvBytes, {locale: "fr_FR", encoding: "ISO-8859-1"}); + test:assertEquals((check rec)[0], {value: "Alice"}); +} + +@test:Config {dependsOn: [testCSVLocale]} function testFromCsvStringWithParserOptions() { [int, string, boolean, decimal, float, string][]|csv:Error csv1op3 = csv:parseStringToList(csvStringData1, option3); test:assertEquals(csv1op3, [ @@ -79,7 +109,7 @@ function testFromCsvStringWithParserOptions() { ]); } -@test:Config +@test:Config {dependsOn: [testCSVLocale]} function testFromCsvStringWithHeaderLessParserOptions() { [int, string, boolean, decimal, float, ()][]|csv:Error csv1op6 = csv:parseStringToList(csvStringData1, option6); test:assertTrue(csv1op6 is csv:Error); @@ -140,7 +170,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { ]); } -@test:Config +@test:Config {dependsOn: [testCSVLocale]} function testHeaderOption() { record {}[]|csv:Error csv2cop1 = csv:parseStringToRecord(csvStringData2, {header: 4}); test:assertEquals(csv2cop1, [ @@ -166,7 +196,7 @@ function testHeaderOption() { test:assertEquals((csv1cop5).message(), "The provided header row is empty"); } -@test:Config +@test:Config {dependsOn: [testCSVLocale]} function testNullConfigOption() { string csvValue1 = string `a ()`; @@ -235,7 +265,7 @@ function testNullConfigOption() { test:assertEquals((cn).message(), common:generateErrorMessageForInvalidCast("()", "()")); } -@test:Config +@test:Config {dependsOn: [testCSVLocale]} function testCommentConfigOption() { string csvValue1 = string `a 1`; @@ -297,7 +327,7 @@ function testCommentConfigOption() { test:assertEquals(cn, [{a: 1}]); } -@test:Config +@test:Config {dependsOn: [testCSVLocale]} function testCommentConfigOption2() { string csvValue1 = string `a 1`; @@ -377,7 +407,7 @@ function testCommentConfigOption2() { test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); } -@test:Config +@test:Config {dependsOn: [testCSVLocale]} function testSkipLineParserOption() { [int, string, boolean, decimal, float, ()][]|csv:Error csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [], header: 1}); test:assertEquals(csv1cp, [ @@ -478,7 +508,7 @@ function testSkipLineParserOption() { ]); } -@test:Config +@test:Config {dependsOn: [testCSVLocale]} function testCustomHeaderOption() { anydata[][]|csv:Error bm1ba = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}); test:assertEquals(bm1ba, [ @@ -874,33 +904,3 @@ function testLineTerminatorWithParserOptions() { cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn2, [[1, "2\n3"]]); } - -@test:Config -function testCSVLocale() { - record {|string name; decimal completed\ tasks; string city;|}[]|csv:Error rec; - - rec = csv:parseStringToRecord(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:Config -function testCSVEncoding() returns error? { - record {}[]|csv:Error rec; - - string csvStr = string `value - Alice - 2πr - €123`; - byte[] csvBytes = string:toBytes(csvStr); - - rec = csv:parseBytesToRecord(csvBytes, {locale: "fr_FR", encoding: "ISO-8859-1"}); - test:assertEquals((check rec)[0], {value: "Alice"}); -} From dc585b75453bbdb8102f3c38766bf7bc293984ab Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 30 Jul 2024 21:39:02 +0530 Subject: [PATCH 089/147] Add tests for compiler plugin --- .../csvdata/compiler/CompilerPluginTest.java | 20 +++++++++++++++ .../sample_package_5/main.bal | 5 ++++ .../sample_package_6/Ballerina.toml | 5 ++++ .../sample_package_6/main.bal | 25 +++++++++++++++++++ .../compiler/CsvDataTypeValidator.java | 20 ++------------- 5 files changed, 57 insertions(+), 18 deletions(-) create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/main.bal 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 d2d6664..71982b5 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 @@ -107,4 +107,24 @@ public void testEmptyProject() { .collect(Collectors.toList()); Assert.assertEquals(errorDiagnosticsList.size(), 0); } + + @Test + public void testInvalidExpectedUnionType2() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_6").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 10); + 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); + Assert.assertEquals(errorDiagnosticsList.get(3).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(4).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(5).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + Assert.assertEquals(errorDiagnosticsList.get(6).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); + 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); + } } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/main.bal index 0ecaab9..62dcecc 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_5/main.bal @@ -1,3 +1,8 @@ public function main() { // test scenario without module import + test(); +} + +function test() { + } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/Ballerina.toml new file mode 100644 index 0000000..c49ff82 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/Ballerina.toml @@ -0,0 +1,5 @@ +[package] +org = "admin" +name = "sample_package_6" +version = "0.1.0" +distribution = "2201.9.0" 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 new file mode 100644 index 0000000..926d428 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/main.bal @@ -0,0 +1,25 @@ +import ballerina/io; +import ballerina/data.csv; + +public function main() { + test(); +} + +type A [[int, string], [int, string]]; + +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([], {}); +} \ No newline at end of file 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 0efc318..acbc445 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 @@ -115,7 +115,7 @@ private void updateModulePrefix(ModulePartNode rootNode) { for (ImportDeclarationNode importDeclarationNode : rootNode.imports()) { Optional symbol = semanticModel.symbol(importDeclarationNode); symbol.filter(moduleSymbol -> moduleSymbol.kind() == SymbolKind.MODULE) - .filter(moduleSymbol -> isCsvdataImport((ModuleSymbol) moduleSymbol)) + .filter(moduleSymbol -> isCsvDataImport((ModuleSymbol) moduleSymbol)) .ifPresent(moduleSymbol -> { modulePrefix = ((ModuleSymbol) moduleSymbol).id().modulePrefix(); }); @@ -246,22 +246,6 @@ private boolean isSupportedArrayMemberType(TypeSymbol typeSymbol) { } } - private boolean isSupportedExpectedType(TypeSymbol typeSymbol) { - TypeDescKind kind = typeSymbol.typeKind(); - if (kind == TypeDescKind.TYPE_REFERENCE) { - kind = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor().typeKind(); - } - - switch (kind) { - case ARRAY, UNION, INTERSECTION -> { - return true; - } - default -> { - return false; - } - } - } - public static TypeSymbol getRawType(TypeSymbol typeDescriptor) { if (typeDescriptor.typeKind() == TypeDescKind.INTERSECTION) { return getRawType(((IntersectionTypeSymbol) typeDescriptor).effectiveTypeDescriptor()); @@ -364,7 +348,7 @@ private String getAnnotModuleName(AnnotationSymbol annotation) { return moduleName.orElse(""); } - private boolean isCsvdataImport(ModuleSymbol moduleSymbol) { + private boolean isCsvDataImport(ModuleSymbol moduleSymbol) { ModuleID moduleId = moduleSymbol.id(); return Constants.BALLERINA.equals(moduleId.orgName()) && Constants.DATA_CSVDATA.equals(moduleId.moduleName()); From 96fe8b47c820db7de292ce5c37402c8af31cf5e1 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 30 Jul 2024 21:47:44 +0530 Subject: [PATCH 090/147] Remove unused imports in compiler plugin testsd --- .../ballerina_sources/sample_package_6/main.bal | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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 926d428..7c615e9 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 @@ -1,12 +1,11 @@ -import ballerina/io; import ballerina/data.csv; -public function main() { - test(); -} - type A [[int, string], [int, string]]; +public function main() returns error? { + check test(); +} + public function test() returns error? { stream s = ( [[1, 2, 3, 4, 5]]).toStream(); @@ -22,4 +21,4 @@ public function test() returns error? { [record{}, record{}, record{}, record{}] val10 = check csv:parseListAsRecordType([], [], {}); record{}[2] val11 = check csv:parseListAsRecordType([], [], {}); int[3][2] val12 = check csv:parseListAsListType([], {}); -} \ No newline at end of file +} From 72a9f413b02390740fbfeb1d5056b49c3ba5c88e Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 31 Jul 2024 11:47:37 +0530 Subject: [PATCH 091/147] Add more tests to locale --- .../user_config_with_parser_options_test.bal | 49 ++++++++++++++----- .../lib/data/csvdata/csv/CsvCreator.java | 12 ----- .../lib/data/csvdata/csv/CsvParser.java | 7 +-- .../lib/data/csvdata/csv/CsvTraversal.java | 21 +------- .../lib/data/csvdata/utils/Constants.java | 25 ++++++++-- .../lib/data/csvdata/utils/CsvConfig.java | 8 --- .../lib/data/csvdata/utils/CsvUtils.java | 10 ---- .../lib/data/csvdata/utils/DataUtils.java | 5 +- .../lib/data/csvdata/utils/DiagnosticLog.java | 5 +- 9 files changed, 67 insertions(+), 75 deletions(-) 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 9ec2c09..1dfcbc0 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 @@ -18,6 +18,20 @@ import ballerina/csv_commons as common; import ballerina/data.csv; import ballerina/test; +@test:Config +function testCSVEncoding() returns error? { + record {}[]|csv:Error rec; + + string csvStr = string `value + Alice + 2πr + €123`; + byte[] csvBytes = string:toBytes(csvStr); + + rec = csv:parseBytesToRecord(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; @@ -32,20 +46,28 @@ function testCSVLocale() { {name: "Bob", "completed tasks": 1.234, city: "London"}, {name: "€123", "completed tasks": 12.34, city: "Berlin"} ]); -} - -@test:Config -function testCSVEncoding() returns error? { - record {}[]|csv:Error rec; - string csvStr = string `value - Alice - 2πr - €123`; - byte[] csvBytes = string:toBytes(csvStr); + rec = csv:parseStringToRecord(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"} + ]); - rec = csv:parseBytesToRecord(csvBytes, {locale: "fr_FR", encoding: "ISO-8859-1"}); - test:assertEquals((check rec)[0], {value: "Alice"}); + rec = csv:parseStringToRecord(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:Config {dependsOn: [testCSVLocale]} @@ -903,4 +925,7 @@ function testLineTerminatorWithParserOptions() { cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: [csv:CRLF, csv:LF]}); test:assertEquals(cn2, [[1, "2\n3"]]); + + cn2 = csv:parseStringToList(csvValue, {header: 0, lineTerminator: csv:LF}); + test:assertEquals(cn2, [[1, "2\n3"]]); } 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 2160923..3a4a534 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 @@ -29,7 +29,6 @@ import io.ballerina.runtime.api.flags.SymbolFlags; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.Field; -import io.ballerina.runtime.api.types.IntersectionType; import io.ballerina.runtime.api.types.MapType; import io.ballerina.runtime.api.types.TupleType; import io.ballerina.runtime.api.types.Type; @@ -42,7 +41,6 @@ import org.ballerinalang.langlib.value.CloneReadOnly; import java.util.Map; -import java.util.Optional; import static io.ballerina.lib.data.csvdata.utils.CsvUtils.getUpdatedHeaders; @@ -57,12 +55,6 @@ private CsvCreator() { static Object initRowValue(Type expectedType) { expectedType = TypeUtils.getReferredType(expectedType); - if (expectedType.getTag() == TypeTags.INTERSECTION_TAG) { - Optional mutableType = CsvUtils.getMutableType((IntersectionType) expectedType); - if (!mutableType.isEmpty()) { - expectedType = mutableType.get(); - } - } switch (expectedType.getTag()) { case TypeTags.RECORD_TYPE_TAG: @@ -138,10 +130,6 @@ public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { } public static void addCustomHeadersIfNotNull(CsvParser.StateMachine sm, Object customHeader) { - if (customHeader == null) { - return; - } - BArray customHeaders = (BArray) customHeader; for (int i = 0; i < customHeaders.size(); i++) { String header = StringUtils.getStringValue(customHeaders.get(i)); 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 6b8f60d..7616d1a 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 @@ -677,7 +677,7 @@ private static void addRowValue(StateMachine sm) throws CsvParserException { } private static void addRowValue(StateMachine sm, boolean trim) throws CsvParserException { - Type type; + Type type = null; Field currentField = null; sm.isValueStart = false; Type exptype = sm.expectedArrayElementType; @@ -695,8 +695,6 @@ private static void addRowValue(StateMachine sm, boolean trim) throws CsvParserE type = getExpectedRowTypeOfArray(sm, arrayType); } else if (exptype instanceof TupleType tupleType) { type = getExpectedRowTypeOfTuple(sm, tupleType); - } else { - throw new CsvParserException("Unexpected expected type"); } if (type != null) { @@ -899,9 +897,6 @@ public State transition(StateMachine sm, char[] buff, int i, int count) } break; } - if (state == null) { - state = this; - } sm.index = i + 1; return state; } 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 5e2c630..441664e 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 @@ -229,16 +229,6 @@ private void traverseCsvWithExpectedType(int sourceArraySize, traverseCsvArrayMembersWithUnionAsCsvElementType(sourceArraySize, csv, (UnionType) expectedArrayElementType, type); break; - case TypeTags.INTERSECTION_TAG: - for (Type constituentType : ((IntersectionType) expectedArrayElementType).getConstituentTypes()) { - if (constituentType.getTag() == TypeTags.READONLY_TAG) { - continue; - } - config.stringConversion = true; - CsvCreator.constructReadOnlyValue(this.traverseCsv( - csv, config, TypeCreator.createArrayType(constituentType))); - } - break; default: throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); } @@ -433,17 +423,8 @@ private void constructArrayValuesFromMap(BMap map, Type type, i } } else if (config.customHeader == null) { keys = map.getKeys(); - } else { - if (this.headers == null) { - this.headers = CsvUtils.createHeaders(new String[size], config); - } - if (this.headers.length != size) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); - } - for (int i = 0; i < size; i++) { - keys[i] = StringUtils.fromString(this.headers[i]); - } } + for (BString key: keys) { if (!map.containsKey(key)) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER, key); 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 987cc2b..02122fd 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 @@ -3,8 +3,8 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BString; -public class Constants { - public static class ConfigConstants { +public final class Constants { + public final class ConfigConstants { public static final BString DELIMITER = StringUtils.fromString("delimiter"); public static final BString TEXT_ENCLOSURE = StringUtils.fromString("textEnclosure"); public static final BString HEADER = StringUtils.fromString("header"); @@ -22,20 +22,29 @@ public static class ConfigConstants { public static final BString STRING_CONVERSION = StringUtils.fromString("stringConversion"); public static final BString ENABLE_CONSTRAINT_VALIDATION = StringUtils. fromString("enableConstraintValidation"); + + private ConfigConstants() { + } } - public static class Values { + public final class Values { public static final String NULL = "null"; public static final String BALLERINA_NULL = "()"; + + private Values() { + } } - public static class LineTerminator { + public final class LineTerminator { public static final char LF = '\n'; public static final char CR = '\r'; public static final String CRLF = "\r\n"; + + private LineTerminator() { + } } - public static class EscapeChar { + public final class EscapeChar { public static final char DOUBLE_QUOTES_CHAR = '"'; public static final char BACKSLASH_CHAR = '\\'; public static final char SLASH_CHAR = '/'; @@ -45,6 +54,9 @@ public static class EscapeChar { public static final char CARRIAGE_RETURN_CHAR = 'r'; public static final char TAB_CHAR = 't'; public static final char UNICODE_START_CHAR = 'u'; + + private EscapeChar() { + } } public static final String SKIP_LINE_RANGE_SEP = "-"; @@ -52,4 +64,7 @@ public static class EscapeChar { public static final String NAME = "Name"; public static final BString VALUE = StringUtils.fromString("value"); public static final String UNDERSCORE = "_"; + + private Constants() { + } } 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 abfc9a5..c4ed44e 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 @@ -35,14 +35,6 @@ private CsvConfig(CsvConfig config) { this.locale = config.locale; } - private CsvConfig(Object skipLines, boolean nilAsOptionalField, - boolean absentAsNilableType, boolean allowDataProjection) { - this.skipLines = skipLines; - this.nilAsOptionalField = nilAsOptionalField; - this.absentAsNilableType = absentAsNilableType; - this.allowDataProjection = allowDataProjection; - } - private CsvConfig(boolean enableConstraintValidation, Object skipLines, boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection) { this.skipLines = skipLines; 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 d3e0817..b5291c6 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 @@ -338,16 +338,6 @@ private static Optional handleLineTerminator(Object lineTerminator, cha return Optional.empty(); } - public static class SortConfigurations { - protected Object columnName; - protected Object sortOrder; - - public SortConfigurations(Object columnName, Object sortOrder) { - this.columnName = columnName; - this.sortOrder = sortOrder; - } - } - public static class UnMappedValue { private static UnMappedValue value = null; public static UnMappedValue createUnMappedValue() { diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java index d3ce960..c303b69 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java @@ -4,7 +4,10 @@ import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.stdlib.constraint.Constraints; -public class DataUtils { +public final class DataUtils { + private DataUtils() { + } + public static Object validateConstraints(Object convertedValue, BTypedesc typed, boolean requireValidation) { if (!requireValidation) { return convertedValue; diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java index e4687d5..e7569df 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java @@ -31,12 +31,15 @@ * * @since 0.1.0 */ -public class DiagnosticLog { +public final class DiagnosticLog { private static final String ERROR_PREFIX = "error"; private static final String CSV_CONVERSION_ERROR = "Error"; private static final String UNSUPPORTED_OPERATION_ERROR = "Error"; private static final ResourceBundle MESSAGES = ResourceBundle.getBundle("error", Locale.getDefault()); + private DiagnosticLog() { + } + public static BError error(DiagnosticErrorCode code, Object... args) { String msg = formatMessage(code, args); return getCsvError(msg); From 68a02609b170bbf200f1348c32352c5a8573e154 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 31 Jul 2024 14:31:50 +0530 Subject: [PATCH 092/147] Remove .gitignore files and add codecov configs --- .gitignore | 1 + ballerina-tests/build.gradle | 4 +- .../constraint-validation-tests/.gitignore | 11 ---- ballerina-tests/csv-commons/.gitignore | 11 ---- .../parse-list-types-tests/.gitignore | 11 ---- .../parse-record-types-tests/.gitignore | 11 ---- .../parse-string-array-types-tests/.gitignore | 11 ---- .../.gitignore | 11 ---- .../type-compatible-tests/.gitignore | 11 ---- ballerina-tests/unicode-tests/.gitignore | 11 ---- ballerina-tests/union-type-tests/.gitignore | 11 ---- .../tests/test_with_intersection_types.bal | 57 +++++++++---------- ballerina-tests/user-config-tests/.gitignore | 11 ---- settings.gradle | 2 - 14 files changed, 31 insertions(+), 143 deletions(-) delete mode 100644 ballerina-tests/constraint-validation-tests/.gitignore delete mode 100644 ballerina-tests/csv-commons/.gitignore delete mode 100644 ballerina-tests/parse-list-types-tests/.gitignore delete mode 100644 ballerina-tests/parse-record-types-tests/.gitignore delete mode 100644 ballerina-tests/parse-string-array-types-tests/.gitignore delete mode 100644 ballerina-tests/parse-string-record-types-tests/.gitignore delete mode 100644 ballerina-tests/type-compatible-tests/.gitignore delete mode 100644 ballerina-tests/unicode-tests/.gitignore delete mode 100644 ballerina-tests/union-type-tests/.gitignore delete mode 100644 ballerina-tests/user-config-tests/.gitignore diff --git a/.gitignore b/.gitignore index 1d2a7ee..38d72e0 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ *.zip *.tar.gz *.rar +*.deb # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.csv hs_err_pid* diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index d99084e..39f08c5 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -20,7 +20,7 @@ plugins { import org.apache.tools.ant.taskdefs.condition.Os -description = 'Ballerina - HTTP/WS Ballerina Tests' +description = 'Ballerina - CSV data module Ballerina Tests' def packageName = "data.csv" def packageOrg = "ballerina" @@ -29,7 +29,7 @@ def ballerinaTomlFilePlaceHolder = new File("${project.rootDir}/build-config/res def testCommonTomlFilePlaceHolder = new File("${project.rootDir}/build-config/resources/CsvTestCommon.toml") def ballerinaDist = "${project.rootDir}/target/ballerina-runtime" def distributionBinPath = "${ballerinaDist}/bin" -def testCoverageParam = "--code-coverage --coverage-format=xml --includes=io.ballerina.lib.data.*:ballerina.*" +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 testCommonPackage = "csv-commons" diff --git a/ballerina-tests/constraint-validation-tests/.gitignore b/ballerina-tests/constraint-validation-tests/.gitignore deleted file mode 100644 index d5fc29a..0000000 --- a/ballerina-tests/constraint-validation-tests/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml diff --git a/ballerina-tests/csv-commons/.gitignore b/ballerina-tests/csv-commons/.gitignore deleted file mode 100644 index d5fc29a..0000000 --- a/ballerina-tests/csv-commons/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml diff --git a/ballerina-tests/parse-list-types-tests/.gitignore b/ballerina-tests/parse-list-types-tests/.gitignore deleted file mode 100644 index d5fc29a..0000000 --- a/ballerina-tests/parse-list-types-tests/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml diff --git a/ballerina-tests/parse-record-types-tests/.gitignore b/ballerina-tests/parse-record-types-tests/.gitignore deleted file mode 100644 index d5fc29a..0000000 --- a/ballerina-tests/parse-record-types-tests/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml diff --git a/ballerina-tests/parse-string-array-types-tests/.gitignore b/ballerina-tests/parse-string-array-types-tests/.gitignore deleted file mode 100644 index d5fc29a..0000000 --- a/ballerina-tests/parse-string-array-types-tests/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml diff --git a/ballerina-tests/parse-string-record-types-tests/.gitignore b/ballerina-tests/parse-string-record-types-tests/.gitignore deleted file mode 100644 index d5fc29a..0000000 --- a/ballerina-tests/parse-string-record-types-tests/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml diff --git a/ballerina-tests/type-compatible-tests/.gitignore b/ballerina-tests/type-compatible-tests/.gitignore deleted file mode 100644 index d5fc29a..0000000 --- a/ballerina-tests/type-compatible-tests/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml diff --git a/ballerina-tests/unicode-tests/.gitignore b/ballerina-tests/unicode-tests/.gitignore deleted file mode 100644 index d5fc29a..0000000 --- a/ballerina-tests/unicode-tests/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml diff --git a/ballerina-tests/union-type-tests/.gitignore b/ballerina-tests/union-type-tests/.gitignore deleted file mode 100644 index d5fc29a..0000000 --- a/ballerina-tests/union-type-tests/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml 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 299397e..be41c23 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 @@ -13,7 +13,6 @@ // KIND, either express or implied. See the License for the // specific language governing permissions and limitations // under the License. - import ballerina/data.csv; import ballerina/test; @@ -22,25 +21,25 @@ function testIntersectionExpectedTypes() returns error? { (int[] & readonly)[]|csv:Error a = csv:parseStringToList(string `a,b 1,2 4,5`); - test:assertTrue(a is (int[] & readonly)[]); + test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); ([string, string])[] & readonly|csv:Error a2 = csv:parseStringToList(string `a,b a,a c,c`); - test:assertTrue(a2 is [string, string][] & readonly); + 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:parseStringToRecord(string `a,b 1,2 4,5`); - test:assertTrue(a3 is (record{int a; string b;} & readonly)[]); + 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:parseStringToRecord(string `a,b a,a c,c`); - test:assertTrue(a4 is record{|string...;|}[] & readonly); + 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 @@ -55,10 +54,10 @@ function testIntersectionExpectedTypes() returns error? { 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:parseStringToRecord(string `a,b 1,2 4,5`); - test:assertTrue(a7 is record{int a; string b;}[] & readonly); + 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 @@ -73,7 +72,7 @@ function testIntersectionExpectedTypes() returns error? { 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))[] + ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly|csv:Error a10 = csv:parseStringToRecord(string `a,b a,a 1,2`); @@ -84,19 +83,19 @@ 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"], {}); - test:assertTrue(a is (int[] & readonly)[]); + 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"], {}); - test:assertTrue(a2 is [string, string][] & readonly); + 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"}], {}); - test:assertTrue(a3 is (record{int a; string b;} & readonly)[]); + (record {int a; string b;} & readonly)[]|csv:Error a3 = csv:parseRecordAsRecordType([{"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"}], {}); - test:assertTrue(a4 is record{|string...;|}[] & readonly); + record {|string...;|}[] & readonly|csv:Error a4 = csv:parseRecordAsRecordType([{"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"], {}); @@ -107,8 +106,8 @@ function testIntersectionExpectedTypes2() returns error? { 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"}], {}); - test:assertTrue(a7 is record{int a; string b;}[] & readonly); + (record {int a; string b;} & readonly)[]|csv:Error a7 = csv:parseRecordAsRecordType([{"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"}], {}); @@ -119,7 +118,7 @@ function testIntersectionExpectedTypes2() returns error? { 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))[] + ((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}], {}); 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}]); @@ -128,19 +127,19 @@ function testIntersectionExpectedTypes2() returns error? { @test:Config function testIntersectionExpectedTypes3() returns error? { (int[] & readonly)[]|csv:Error a = csv:parseListAsListType([["1", "2"], ["4", "5"]], {}); - test:assertTrue(a is (int[] & readonly)[]); + 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"]], {}); - test:assertTrue(a2 is [string, string][] & readonly); + 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"], {}); - test:assertTrue(a3 is (record{int a; string b;} & readonly)[]); + (record {int a; string b;} & readonly)[]|csv:Error a3 = csv:parseListAsRecordType([["1", "2"], ["4", "5"]], ["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"], {}); - test:assertTrue(a4 is record{|string...;|}[] & readonly); + record {|string...;|}[] & readonly|csv:Error a4 = csv:parseListAsRecordType([["a", "a"], ["c", "c"]], ["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"]], {}); @@ -151,8 +150,8 @@ function testIntersectionExpectedTypes3() returns error? { 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"], {}); - test:assertTrue(a7 is record{int a; string b;}[] & readonly); + (record {int a; string b;} & readonly)[]|csv:Error a7 = csv:parseListAsRecordType([["1", "2"], ["4", "5"]], ["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"], {}); @@ -163,12 +162,12 @@ function testIntersectionExpectedTypes3() returns error? { 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))[] + ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly|csv:Error a10 = csv:parseListAsRecordType([["a", "a"], ["1", "2"]], ["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))[] + ((record {int a; int b;} & readonly)|(record {string a; string b;} & readonly))[] & readonly|csv:Error a11 = csv:parseListAsRecordType([["a", "a"], ["1", "2"]], ["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/user-config-tests/.gitignore b/ballerina-tests/user-config-tests/.gitignore deleted file mode 100644 index d5fc29a..0000000 --- a/ballerina-tests/user-config-tests/.gitignore +++ /dev/null @@ -1,11 +0,0 @@ -# Ballerina generates this directory during the compilation of a package. -# It contains compiler-generated artifacts and the final executable if this is an application package. -target/ - -# Ballerina maintains the compiler-generated source code here. -# Remove this if you want to commit generated sources. -generated/ - -# Contains configuration values used during development time. -# See https://ballerina.io/learn/provide-values-to-configurable-variables/ for more details. -Config.toml diff --git a/settings.gradle b/settings.gradle index 3a376ae..ab6d512 100644 --- a/settings.gradle +++ b/settings.gradle @@ -61,5 +61,3 @@ gradleEnterprise { termsOfServiceAgree = 'yes' } } -include 'ballerina-tests' - From 9ce93c446fa5f28d42cde04b6f4449e9f9b84c34 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 31 Jul 2024 17:13:12 +0530 Subject: [PATCH 093/147] Update api docs in user configs --- ballerina/types.bal | 2 -- 1 file changed, 2 deletions(-) diff --git a/ballerina/types.bal b/ballerina/types.bal index 1bee776..eb7029f 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -19,8 +19,6 @@ 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: - # - `nilAsOptionalField`: If `true`, nil values will be considered as optional fields in the projection. - # - `absentAsNilableType`: If `true`, absent fields will be considered as nilable types in the projection. # 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. From d7ee80fa4cc3f945a92d9dcd0736e139b10c9f21 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 09:35:53 +0530 Subject: [PATCH 094/147] Add codecov configurations for codecov yaml --- codecov.yml | 7 +++++ .../lib/data/csvdata/csv/CsvParser.java | 26 +++++++++++-------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/codecov.yml b/codecov.yml index f60b970..25b7030 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,3 +1,10 @@ +fixes: + - "ballerina/data.csv/**/::../ballerina/" + +ignore: + - "ballerina-tests" + - "test-utils" + coverage: precision: 2 round: down 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 7616d1a..8f9bddf 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 @@ -66,6 +66,7 @@ * @since 0.1.0 */ public final class CsvParser { + private static final char CR = 0x000D; private static final char HZ_TAB = 0x0009; private static final char SPACE = 0x0020; @@ -102,6 +103,7 @@ public static Object parse(Reader reader, BTypedesc type, CsvConfig config) */ static class StateMachine { + private static final State HEADER_START_STATE = new HeaderStartState(); private static final State HEADER_END_STATE = new HeaderEndState(); private static final State ROW_START_STATE = new RowStartState(); @@ -112,9 +114,6 @@ static class StateMachine { private static final State HEADER_ESCAPE_CHAR_STATE = new HeaderEscapedCharacterProcessingState(); private static final State STRING_QUOTE_CHAR_STATE = new StringQuoteValueState(); private static final State HEADER_QUOTE_CHAR_STATE = new HeaderQuoteValueState(); - - - private static final char LINE_BREAK = '\n'; Object currentCsvNode; @@ -298,7 +297,7 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp currentState = currentState.transition(this, buff, this.index, count); } } - currentState = currentState.transition(this, new char[] { EOF }, 0, 1); + currentState = currentState.transition(this, new char[]{EOF}, 0, 1); if (currentState != ROW_END_STATE && currentState != HEADER_END_STATE) { if (!this.isHeaderConfigExceedLineNumber) { throw new CsvParserException("Invalid token found"); @@ -310,7 +309,7 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp } } - private void addFieldNamesForNonHeaderState() { + private void addFieldNamesForNonHeaderState() { this.fieldNames.putAll(this.fieldHierarchy); } @@ -339,6 +338,7 @@ private void growCharBuff() { * A specific state in the CSV parsing state machine. */ interface State { + State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException; } @@ -346,6 +346,7 @@ interface State { * Represents the CSV header start state. */ private static class HeaderStartState implements State { + @Override public State transition(StateMachine sm, char[] buff, int i, int count) throws CsvParserException { char ch; @@ -511,6 +512,7 @@ private static void addHeader(StateMachine sm, boolean trim) { * Represents the CSV header end state. */ private static class HeaderEndState implements State { + @Override public State transition(StateMachine sm, char[] buff, int i, int count) { return ROW_START_STATE; @@ -521,6 +523,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { * Represents the CSV row start state. */ private static class RowStartState implements State { + char ch; State state = ROW_START_STATE; @@ -650,7 +653,7 @@ private static void updateLineAndColumnIndexesWithoutRowIndexes(StateMachine sm) } private static boolean ignoreRow(long[] skipLines, int lineNumber) { - for (long skipLine: skipLines) { + for (long skipLine : skipLines) { if (skipLine == lineNumber) { return true; } @@ -765,6 +768,7 @@ private static Field getCurrentField(StateMachine sm) { * Represents the CSV row end state. */ private static class RowEndState implements State { + @Override public State transition(StateMachine sm, char[] buff, int i, int count) { return ROW_END_STATE; @@ -838,7 +842,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) return state; } } - + /** * Represents the CSV header value with quote state. */ @@ -903,8 +907,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) } /** - * Represents the state where an escaped unicode character in hex format is processed - * from a row value. + * Represents the state where an escaped unicode character in hex format is processed from a row value. */ private static class StringValueUnicodeHexProcessingState extends UnicodeHexProcessingState { @@ -916,8 +919,7 @@ protected State getSourceState() { } /** - * Represents the state where an escaped unicode character in hex format is processed - * from a header name. + * Represents the state where an escaped unicode character in hex format is processed from a header name. */ private static class HeaderUnicodeHexProcessingState extends UnicodeHexProcessingState { @@ -1012,6 +1014,7 @@ protected State getSourceState() { * Represents the state where an escaped character is processed in a header or row value. */ private abstract static class EscapedCharacterProcessingState implements State { + static final Map ESCAPE_CHAR_MAP = Map.of(DOUBLE_QUOTES_CHAR, QUOTES, BACKSLASH_CHAR, REV_SOL, SLASH_CHAR, SOL, BACKSPACE_CHAR, BACKSPACE, FORM_FEED_CHAR, FORMFEED, NEWLINE_CHAR, NEWLINE, CARRIAGE_RETURN_CHAR, CR, TAB_CHAR, HZ_TAB); @@ -1077,6 +1080,7 @@ public static boolean isEndOfTheHeaderRow(CsvParser.StateMachine sm, char ch) { } public static class CsvParserException extends Exception { + public CsvParserException(String msg) { super(msg); } From db2d25edb593c37d349b1fab64e0793ab0f4a19f Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 10:16:35 +0530 Subject: [PATCH 095/147] Use module level constant vars for constant values --- .../lib/data/csvdata/csv/CsvTraversal.java | 17 +++++++++++++---- .../lib/data/csvdata/utils/CsvUtils.java | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) 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 441664e..f99bd95 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 @@ -396,14 +396,13 @@ private void traverseArrayValue(Object csvElement, Type type) { } private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { - int index = 0; - for (int i = 0; i < csvElement.getLength(); i++) { + for (int index = 0; index < csvElement.getLength(); index++) { if (config.allowDataProjection && index >= expectedSize) { break; } Type memberType = getArrayOrTupleMemberType(type, index); if (memberType != null) { - addValuesToArrayType(csvElement.get(i), memberType, index, currentCsvNode); + addValuesToArrayType(csvElement.get(index), memberType, index, currentCsvNode); } index++; } @@ -412,7 +411,6 @@ private void constructArrayValuesFromArray(BArray csvElement, Type type, int exp private void constructArrayValuesFromMap(BMap map, Type type, int expectedSize) { int size = map.size(); BString[] keys = new BString[size]; - int index = 0; if (config.headersOrder != null) { String[] headerOrder = config.headersOrder.getStringArray(); if (headerOrder.length != size) { @@ -423,8 +421,19 @@ private void constructArrayValuesFromMap(BMap map, Type type, i } } else if (config.customHeader == null) { keys = map.getKeys(); + } else { + if (this.headers == null) { + this.headers = CsvUtils.createHeaders(new String[size], config); + } + if (this.headers.length != size) { + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); + } + for (int i = 0; i < size; i++) { + keys[i] = StringUtils.fromString(this.headers[i]); + } } + int index = 0; for (BString key: keys) { if (!map.containsKey(key)) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER, key); 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 b5291c6..08b5fed 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 @@ -258,7 +258,7 @@ public static long[] getSkipLinesFromStringConfigValue(String configValue) { public static long[] getSkipDataRows(Object skipLines) { long[] skipDataRows; if (skipLines == null) { - return new long[]{}; + return EMPTY_LONG_ARRAY; } if (skipLines instanceof BArray skipLinesArray) { if (skipLinesArray.getLength() == 0) { From 32aa1aee91e6d6468ecef56ce0e75716921245fe Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 10:34:00 +0530 Subject: [PATCH 096/147] Revert changes done for constructArrayValuesFromArray --- .../java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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 f99bd95..72d4493 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 @@ -396,13 +396,14 @@ private void traverseArrayValue(Object csvElement, Type type) { } private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { - for (int index = 0; index < csvElement.getLength(); index++) { + int index = 0; + for (int i = 0; i < csvElement.getLength(); i++) { if (config.allowDataProjection && index >= expectedSize) { break; } Type memberType = getArrayOrTupleMemberType(type, index); if (memberType != null) { - addValuesToArrayType(csvElement.get(index), memberType, index, currentCsvNode); + addValuesToArrayType(csvElement.get(i), memberType, index, currentCsvNode); } index++; } From 679e418ee27ade3f30111a91b135edcbdbffaa6a Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 11:11:23 +0530 Subject: [PATCH 097/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index c07b540..0bfd723 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/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" From e80669f7557ba272fa197d16cae0ff26b5551a6a Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 11:27:07 +0530 Subject: [PATCH 098/147] Update lang version into update 10 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 7404bdb..d7c11be 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.lib version=0.1.0-SNAPSHOT -ballerinaLangVersion=2201.9.0 +ballerinaLangVersion=2201.10.0-20240801-104200-87df251c ballerinaTomlParserVersion=1.2.2 checkstyleToolVersion=10.12.0 From 0aadbbce44675458f7e73f95ef4a1c15f06bf7d7 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 11:51:31 +0530 Subject: [PATCH 099/147] Change the module name in publishing release workflow --- .github/workflows/publish-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 9454d4e..0edaae9 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -12,5 +12,5 @@ jobs: uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main secrets: inherit with: - package-name: data.jsondata + package-name: data.csv package-org: ballerina From 1dbf1a527e62a3fcbb1994968c7bcd9466d459fa Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 14:22:34 +0530 Subject: [PATCH 100/147] Add package md as the readme file --- ballerina/Ballerina.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index bce49a1..07bed5f 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -8,6 +8,7 @@ repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" license = ["Apache-2.0"] distribution = "2201.9.0" export = ["data.csv"] +readme = "Package.md" [platform.java17] graalvmCompatible = true From ea628f75abfd0f55dcf1ae49af00de662c58300b Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 14:47:20 +0530 Subject: [PATCH 101/147] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 07bed5f..bce49a1 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -8,7 +8,6 @@ repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" license = ["Apache-2.0"] distribution = "2201.9.0" export = ["data.csv"] -readme = "Package.md" [platform.java17] graalvmCompatible = true From b0d7055a873659788d755e9496738330db4695d0 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 15:13:16 +0530 Subject: [PATCH 102/147] publish native package for the maven central --- native/build.gradle | 22 +++++++++++++++++++ .../lib/data/csvdata/utils/DiagnosticLog.java | 2 +- .../data/csvdata-native/resource-config.json | 2 +- ...{error.properties => csv_error.properties} | 0 4 files changed, 24 insertions(+), 2 deletions(-) rename native/src/main/resources/{error.properties => csv_error.properties} (100%) diff --git a/native/build.gradle b/native/build.gradle index d87213d..2fef0f3 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -68,6 +68,28 @@ spotbugsTest { enabled = false } +publishing { + publications { + mavenJava(MavenPublication) { + groupId project.group + artifactId "data.csv-native" + version = project.version + artifact jar + } + } + + repositories { + maven { + name = "GitHubPackages" + url = uri("https://maven.pkg.github.com/ballerina-platform/module-ballerina-data.csv") + credentials { + username = System.getenv("publishUser") + password = System.getenv("publishPAT") + } + } + } +} + compileJava { doFirst { options.compilerArgs = [ diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java index e7569df..6de4ee3 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticLog.java @@ -35,7 +35,7 @@ public final class DiagnosticLog { private static final String ERROR_PREFIX = "error"; private static final String CSV_CONVERSION_ERROR = "Error"; private static final String UNSUPPORTED_OPERATION_ERROR = "Error"; - private static final ResourceBundle MESSAGES = ResourceBundle.getBundle("error", Locale.getDefault()); + private static final ResourceBundle MESSAGES = ResourceBundle.getBundle("csv_error", Locale.getDefault()); private DiagnosticLog() { } diff --git a/native/src/main/resources/META-INF/native-image/io.ballerina.stdlib/data/csvdata-native/resource-config.json b/native/src/main/resources/META-INF/native-image/io.ballerina.stdlib/data/csvdata-native/resource-config.json index befe09e..fea4f2b 100644 --- a/native/src/main/resources/META-INF/native-image/io.ballerina.stdlib/data/csvdata-native/resource-config.json +++ b/native/src/main/resources/META-INF/native-image/io.ballerina.stdlib/data/csvdata-native/resource-config.json @@ -1,6 +1,6 @@ { "bundles":[{ - "name":"error", + "name":"csv_error", "locales":[""] }] } diff --git a/native/src/main/resources/error.properties b/native/src/main/resources/csv_error.properties similarity index 100% rename from native/src/main/resources/error.properties rename to native/src/main/resources/csv_error.properties From 3e449724bc435148b7a4a21f711969f7aa285b73 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 15:19:33 +0530 Subject: [PATCH 103/147] Change the parser option field names --- .../user-config-tests/tests/user_configs.bal | 10 +++++----- ballerina/csv_api.bal | 6 +++--- ballerina/types.bal | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ballerina-tests/user-config-tests/tests/user_configs.bal b/ballerina-tests/user-config-tests/tests/user_configs.bal index deb2b4f..f968a9e 100644 --- a/ballerina-tests/user-config-tests/tests/user_configs.bal +++ b/ballerina-tests/user-config-tests/tests/user_configs.bal @@ -24,11 +24,11 @@ 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: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: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]}; // Invalid parser options csv:ParseOption invalidParserOptions1 = {header: 4}; diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 3a51ab1..fbf5036 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -22,7 +22,7 @@ import ballerina/jballerina.java; # + 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 = <>) +public isolated function parseStringToRecord(string s, ParseToRecordOption options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Converts byte[] to subtype of record array. @@ -31,7 +31,7 @@ public isolated function parseStringToRecord(string s, parseToRecordOption optio # + 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 = <>) +public isolated function parseBytesToRecord(byte[] s, ParseToRecordOption 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. @@ -41,7 +41,7 @@ public isolated function parseBytesToRecord(byte[] s, parseToRecordOption option # + 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 = <>) + ParseToRecordOption options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Converts CSV string to subtype of anydata[][]. diff --git a/ballerina/types.bal b/ballerina/types.bal index eb7029f..3129d7c 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -55,7 +55,7 @@ public type ParseOption record {| |}; # Represents options for parsing data into records. -public type parseToRecordOption record {| +public type ParseToRecordOption record {| *ParseOption; # Custom headers for the data, if any. string[]? customHeaders = (); From 7ecdfba6d1c0ec54f075a70d9973f467b8209c41 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 15:26:54 +0530 Subject: [PATCH 104/147] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index bce49a1..07bed5f 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -8,6 +8,7 @@ repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" license = ["Apache-2.0"] distribution = "2201.9.0" export = ["data.csv"] +readme = "Package.md" [platform.java17] graalvmCompatible = true From 82ab586fbae177383a5b20a5dbef59b4e45981af Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 1 Aug 2024 16:37:01 +0530 Subject: [PATCH 105/147] Add javadoc comments for the public java classes --- ballerina/Package.md | 50 ------------------- build-config/resources/Ballerina.toml | 1 + .../lib/data/csvdata/csv/Native.java | 4 +- .../lib/data/csvdata/utils/Constants.java | 5 ++ .../lib/data/csvdata/utils/CsvConfig.java | 5 ++ .../lib/data/csvdata/utils/CsvUtils.java | 5 ++ .../lib/data/csvdata/utils/DataUtils.java | 5 ++ 7 files changed, 24 insertions(+), 51 deletions(-) diff --git a/ballerina/Package.md b/ballerina/Package.md index 22ff65d..1a20e65 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -1,12 +1,5 @@ # Ballerina CSV Data Library -[![Build](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-timestamped-master.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-timestamped-master.yml) -[![codecov](https://codecov.io/gh/ballerina-platform/module-ballerina-data.csv/branch/main/graph/badge.svg)](https://codecov.io/gh/ballerina-platform/module-ballerina-data.csv) -[![Trivy](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/trivy-scan.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/trivy-scan.yml) -[![GraalVM Check](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-with-bal-test-graalvm.yml/badge.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/actions/workflows/build-with-bal-test-graalvm.yml) -[![GitHub Last Commit](https://img.shields.io/github/last-commit/ballerina-platform/module-ballerina-data.csv.svg)](https://github.com/ballerina-platform/module-ballerina-data.csv/commits/master) -[![Github issues](https://img.shields.io/github/issues/ballerina-platform/ballerina-standard-library/module/data.csv.svg?label=Open%20Issues)](https://github.com/ballerina-platform/ballerina-standard-library/labels/module%2Fdata.csv) - The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate the handling and manipulation of CSV data within Ballerina applications. It streamlines the process of converting CSV data to native Ballerina data types, enabling developers to work with CSV content seamlessly and efficiently. ## Features @@ -148,49 +141,6 @@ Issues and Projects tabs are disabled for this repository as this is part of the This repository only contains the source code for the package. -## Building from the source - -### Set up the prerequisites - -1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations). - * [Oracle](https://www.oracle.com/java/technologies/downloads/) - * [OpenJDK](https://adoptium.net/) - -2. Export your GitHub personal access token with the read package permissions as follows. - - export packageUser= - export packagePAT= - -### Building the source - -Execute the commands below to build from source. - -1. To build the library: - - ./gradlew clean build - -2. Publish ZIP artifact to the local `.m2` repository: - - ./gradlew clean build publishToMavenLocal - -3. Publish the generated artifacts to the local Ballerina central repository: - - ./gradlew clean build -PpublishToLocalCentral=true - -4. Publish the generated artifacts to the Ballerina central repository: - - ./gradlew clean build -PpublishToCentral=true - -## Contributing to Ballerina - -As an open source project, Ballerina welcomes contributions from the community. - -For more information, go to the [contribution guidelines](https://github.com/ballerina-platform/ballerina-lang/blob/master/CONTRIBUTING.md). - -## Code of conduct - -All contributors are encouraged to read the [Ballerina code of conduct](https://ballerina.io/code-of-conduct). - ## Useful links * Chat live with us via our [Discord server](https://discord.gg/ballerinalang). diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index 08110a8..d846308 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -8,6 +8,7 @@ repository = "https://github.com/ballerina-platform/module-ballerina-data.csv" license = ["Apache-2.0"] distribution = "2201.9.0" export = ["data.csv"] +readme = "Package.md" [platform.java17] graalvmCompatible = true 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 35a92bd..35dd9eb 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 @@ -44,7 +44,9 @@ * * @since 0.1.0 */ -public class Native { +public final class Native { + private Native() { + } public static Object parseStringToRecord(BString csv, BMap options, BTypedesc type) { try { 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 02122fd..1cb88d5 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 @@ -3,6 +3,11 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BString; +/* + * Constants used in the CSV data module. + * + * @since 0.1.0 + */ public final class Constants { public final class ConfigConstants { public static final BString DELIMITER = StringUtils.fromString("delimiter"); 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 c4ed44e..fdfc08c 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 @@ -5,6 +5,11 @@ import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BString; +/* + * Configuration for CSV operations. + * + * @since 0.1.0 + */ public class CsvConfig { public char delimiter = ','; public char textEnclosure = '\\'; 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 08b5fed..fd4c849 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 @@ -23,6 +23,11 @@ import static io.ballerina.lib.data.csvdata.utils.Constants.SKIP_LINE_RANGE_SEP; +/* + * Utility functions used in the CSV data module. + * + * @since 0.1.0 + */ public class CsvUtils { private static final long[] EMPTY_LONG_ARRAY = new long[]{}; public static boolean isCarriageTokenPresent = false; diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java index c303b69..00258d3 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java @@ -4,6 +4,11 @@ import io.ballerina.runtime.api.values.BTypedesc; import io.ballerina.stdlib.constraint.Constraints; +/* + * Utility functions used in the CSV data module. + * + * @since 0.1.0 + */ public final class DataUtils { private DataUtils() { } From 25847cef65c76077b07e366036435aab49c676d0 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Tue, 6 Aug 2024 10:10:11 +0530 Subject: [PATCH 106/147] Add API related changes for arrays and custom headers --- ballerina/csv_api.bal | 104 ++-------- ballerina/types.bal | 121 ++++++----- .../lib/data/csvdata/csv/CsvCreator.java | 41 ++-- .../lib/data/csvdata/csv/CsvParser.java | 71 +++++-- .../lib/data/csvdata/csv/CsvTraversal.java | 44 ++-- .../lib/data/csvdata/csv/Native.java | 79 +------ .../lib/data/csvdata/utils/Constants.java | 7 +- .../lib/data/csvdata/utils/CsvConfig.java | 192 ++++++------------ .../lib/data/csvdata/utils/CsvUtils.java | 27 ++- .../csvdata/utils/DiagnosticErrorCode.java | 5 +- .../src/main/resources/csv_error.properties | 11 +- 11 files changed, 273 insertions(+), 429 deletions(-) diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index fbf5036..ddc749d 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -16,99 +16,19 @@ import ballerina/jballerina.java; -# Converts CSV string to subtype of record array. -# -# + 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 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 s, 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. -# -# + 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 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[] s, 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. -# -# + 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 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 s, + 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[][]. -# -# + 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; +public isolated function transform(record{}[] s, + TransformOptions 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 -# + 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; - -# Convert value of type string[][] to subtype of anydata[][]. -# -# + s - 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 parseLists(string[][] s, ParseListsOptions 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..e2dba0d 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -12,90 +12,85 @@ 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 acceptable if the expected type is 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; +public type ParseOptions 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; + # Custom headers for the data, if headers are absent. + string[]? customHeadersIfHeaderAbsent = (); |}; -# Represents options for treating a list as a list. -public type ListAsListOption record {| +# Represents options for treating a list as a record. +public type ParseListsOptions record {| *Options; # If `true`, enables conversion of strings during processing. boolean stringConversion = true; -|}; - -# Represents options for treating a record as a record. -public type RecordAsRecordOption record {| - *Options; - # If `true`, enables validation of constraints during processing. - boolean enableConstraintValidation = true; + # If `0`, all the sources will treat as data rows. + # Otherwise specify the header rows(Starts from 1) + 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", + EMPTY_STRING = "", + NOT_APPLICABLE = "N/A", + BAL_NULL = "()" }; 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..d088622 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,25 +91,24 @@ 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)) { 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..8114a49 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) { @@ -282,8 +284,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 +355,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 +378,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; @@ -543,7 +535,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 +556,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); @@ -665,6 +658,17 @@ private static void initiateNewRowType(StateMachine sm) { sm.currentCsvNode = CsvCreator.initRowValue(sm.expectedArrayElementType); } + private static void addHeadersAsTheFirstElementForArraysIfApplicable(StateMachine sm) { + if (!sm.addHeadersForOutput && sm.config.outputWithHeaders) { + for (int i = 0; i < sm.headers.size(); i++) { + addHeaderAsRowValue(sm, sm.headers.get(i)); + } + finalizeTheRow(sm); + initiateNewRowType(sm); + sm.addHeadersForOutput = true; + } + } + private static void finalizeTheRow(StateMachine sm) { int rootArraySize = sm.rootArrayType.getSize(); if (rootArraySize == -1) { @@ -680,7 +684,6 @@ private static void addRowValue(StateMachine sm) throws CsvParserException { } private static void addRowValue(StateMachine sm, boolean trim) throws CsvParserException { - Type type = null; Field currentField = null; sm.isValueStart = false; Type exptype = sm.expectedArrayElementType; @@ -689,15 +692,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 +705,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) { 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..07a5916 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 @@ -103,6 +103,8 @@ static class CsvTree { CsvConfig config; String[] headers = null; int arraySize = 0; + BString[] headersForArrayConversion = null; + boolean addHeadersForOutput = false; void reset() { currentCsvNode = null; @@ -119,6 +121,8 @@ void reset() { config = null; headers = null; arraySize = 0; + headersForArrayConversion = null; + addHeadersForOutput = false; } @@ -135,6 +139,8 @@ void resetForUnionTypes() { expectedArrayElementType = null; headers = null; arraySize = 0; + headersForArrayConversion = null; + addHeadersForOutput = false; } CsvTree() { @@ -397,6 +403,16 @@ private void traverseArrayValue(Object csvElement, Type type) { private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { int index = 0; + if (this.headers == null) { + this.headers = CsvUtils.createHeadersForParseLists(csvElement, headers, config); + } + if (!addHeadersForOutput && config.outputWithHeaders) { + for (int i = 0; i < this.headers.length; i++) { + Type memberType = getArrayOrTupleMemberType(type, i); + addValuesToArrayType(StringUtils.getStringValue(headers[i]), memberType, i, currentCsvNode); + } + addHeadersForOutput = true; + } for (int i = 0; i < csvElement.getLength(); i++) { if (config.allowDataProjection && index >= expectedSize) { break; @@ -412,32 +428,34 @@ private void constructArrayValuesFromArray(BArray csvElement, Type type, int exp 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(); + Object headersOrder = config.headersOrder; + if (headersOrder != null) { + String[] headerOrder = ((BArray) headersOrder).getStringArray(); if (headerOrder.length != size) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_HEADER_NAMES_LENGTH); } for (int i = 0; i < size; i++) { keys[i] = StringUtils.fromString(headerOrder[i]); } - } else if (config.customHeader == null) { - keys = map.getKeys(); } else { - if (this.headers == null) { - this.headers = CsvUtils.createHeaders(new String[size], config); + if (headersForArrayConversion == null) { + headersForArrayConversion = map.getKeys(); } - if (this.headers.length != size) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); - } - for (int i = 0; i < size; i++) { - keys[i] = StringUtils.fromString(this.headers[i]); + keys = headersForArrayConversion; + } + + if (!addHeadersForOutput && config.outputWithHeaders) { + for (int i = 0; i < keys.length; i++) { + Type memberType = getArrayOrTupleMemberType(type, i); + addValuesToArrayType(StringUtils.getStringValue(keys[i]), memberType, i, currentCsvNode); } + addHeadersForOutput = true; } int index = 0; for (BString key: keys) { if (!map.containsKey(key)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER, key); + throw DiagnosticLog.error(DiagnosticErrorCode.INCONSISTENT_HEADER, key); } Object v = map.get(key); if (config.allowDataProjection && index >= expectedSize) { @@ -566,7 +584,7 @@ private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, int arraySize = csvElement.size(); String[] headers = new String[arraySize]; if (this.headers == null) { - this.headers = CsvUtils.createHeaders(headers, config); + this.headers = CsvUtils.createHeadersForParseLists(csvElement, headers, config); } boolean headersMatchWithExpType = checkExpectedTypeMatchWithHeaders(expectedType, csvElement, arraySize); if (!headersMatchWithExpType) { 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..f7811c1 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,16 @@ 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 parseLists(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvConfig.createListTypeOptions(options), type); + return CsvTraversal.traverse(csv, CsvConfig.createParseListsOptions(options), 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..9893d02 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,102 @@ 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 createParseListsOptions(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.getBooleanValue(Constants.ConfigConstants.STRING_CONVERSION), + 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, + boolean stringConversion, 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.stringConversion = stringConversion; + 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..78d0ca5 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 @@ -68,25 +68,32 @@ public static boolean isBasicType(Type type) { } } - public static String[] createHeaders(String[] headers, CsvConfig config) { - Object customHeaders = config.customHeader; + public static String[] createHeadersForParseLists(BArray csvElement, String[] headers, CsvConfig config) { + Object customHeaders = config.customHeaders; + long headerRows = config.headerRows; - if (customHeaders == null) { - for (int i = 0; i < headers.length; i++) { - headers[i] = String.valueOf(i + 1); - } - } - - if (customHeaders instanceof BArray) { - BArray array = (BArray) customHeaders; + if (customHeaders instanceof BArray array) { if (array.size() != headers.length) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CUSTOM_HEADER_LENGTH); } for (int i = 0; i < headers.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 < headers.length; i++) { + headers[i] = String.valueOf(i + 1); + } return headers; } 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..9295f8a 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,14 @@ 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", "ç.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"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/csv_error.properties b/native/src/main/resources/csv_error.properties index 5424a8e..e6fef96 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 previous 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,6 @@ error.duplicate.field=\ error.cannot.convert.into.exptype=\ The source value cannot convert in to the ''{0}'' + +error.no.custom.header.provided=\ + Custom header should be provided \ No newline at end of file From e0a0ad9caa655a727f8acb8db38dc7d2dbe87287 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Tue, 6 Aug 2024 12:11:14 +0530 Subject: [PATCH 107/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 0bfd723..ed49c87 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,7 +12,8 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"} + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "test"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -26,3 +27,52 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + From bcd52015566b3d93d3c7af779e48b0f75302d710 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Tue, 6 Aug 2024 15:23:54 +0530 Subject: [PATCH 108/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ed49c87..bebac93 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,6 +12,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ + {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] @@ -19,6 +20,19 @@ modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} ] +[[package]] +org = "ballerina" +name = "io" +version = "1.6.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.value"} +] +modules = [ + {org = "ballerina", packageName = "io", moduleName = "io"} +] + [[package]] org = "ballerina" name = "jballerina.java" @@ -62,6 +76,15 @@ name = "lang.object" version = "0.0.0" scope = "testOnly" +[[package]] +org = "ballerina" +name = "lang.value" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + [[package]] org = "ballerina" name = "test" From a747e71b8dcd4c55a6eb2534f4f48b88139e3f58 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Tue, 6 Aug 2024 21:29:41 +0530 Subject: [PATCH 109/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index bebac93..ed49c87 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,7 +12,6 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "test"} ] @@ -20,19 +19,6 @@ modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} ] -[[package]] -org = "ballerina" -name = "io" -version = "1.6.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.value"} -] -modules = [ - {org = "ballerina", packageName = "io", moduleName = "io"} -] - [[package]] org = "ballerina" name = "jballerina.java" @@ -76,15 +62,6 @@ name = "lang.object" version = "0.0.0" scope = "testOnly" -[[package]] -org = "ballerina" -name = "lang.value" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - [[package]] org = "ballerina" name = "test" From 1246a4ea46a27dad2f1bcdd2f02fe23870fe2371 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Tue, 6 Aug 2024 21:33:41 +0530 Subject: [PATCH 110/147] Add outputheader param for parse strings, parse list to list APIs --- README.md | 14 +- ballerina-tests/build.gradle | 21 +- .../Ballerina.toml | 2 +- .../tests/constraint_validation_test.bal | 20 +- ballerina-tests/csv-commons/Dependencies.toml | 2 +- .../parse-list-types-tests/Ballerina.toml | 2 +- .../parse-list-types-tests/Dependencies.toml | 2 +- .../tests/parse_list_type_as_list_test.bal | 300 +++- .../tests/parse_list_type_as_record_test.bal | 1579 +++++++++-------- .../parse-record-types-tests/Ballerina.toml | 2 +- .../tests/parse_record_type_as_list_test.bal | 220 ++- .../parse_record_type_as_record_test.bal | 286 +-- .../Ballerina.toml | 2 +- .../Dependencies.toml | 2 +- .../tests/parse_string_to_array_test.bal | 235 +-- .../tests/parse_string_to_tuple_test.bal | 164 +- .../Ballerina.toml | 2 +- .../Dependencies.toml | 2 +- .../tests/parse_string_to_map_tests.bal | 132 +- .../tests/parse_string_to_record_tests.bal | 174 +- .../type-compatible-tests/Ballerina.toml | 2 +- .../tests/parse_string_compatibality_test.bal | 68 +- .../tests/parse_type_compatibility_test.bal | 88 +- ballerina-tests/unicode-tests/Ballerina.toml | 2 +- .../tests/escape_character_test.bal | 8 +- .../union-type-tests/Ballerina.toml | 2 +- .../tests/test_with_intersection_types.bal | 62 +- .../tests/test_with_singleton_test.bal | 68 +- .../tests/test_with_union_types.bal | 268 +-- .../user-config-tests/Ballerina.toml | 2 +- .../tests/user_config_projection_tests.bal | 252 +-- .../user_config_with_parser_options_test.bal | 276 +-- .../user-config-tests/tests/user_configs.bal | 46 +- ballerina/Package.md | 14 +- .../csvdata/compiler/CompilerPluginTest.java | 12 +- .../sample_package_1/main.bal | 24 +- .../sample_package_4/main.bal | 24 +- .../sample_package_6/main.bal | 24 +- .../lib/data/csvdata/compiler/Constants.java | 20 +- .../lib/data/csvdata/csv/CsvCreator.java | 9 + .../lib/data/csvdata/csv/CsvParser.java | 17 +- .../lib/data/csvdata/csv/CsvTraversal.java | 60 +- .../lib/data/csvdata/utils/CsvUtils.java | 7 +- .../src/main/resources/csv_error.properties | 2 +- 44 files changed, 2413 insertions(+), 2107 deletions(-) diff --git a/README.md b/README.md index 22ff65d..08f9f82 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate ### 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 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`, `parseStream`, `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); } ``` @@ -89,7 +89,7 @@ type Book record { public function main() returns error? { string[][] bookArray = [["Clean Code","2008"],["Clean Architecture","2017"]]; - Book[] author = check csv:parseListAsRecordType(bookArray, customHeaders = ["name", "year"]); + Book[] author = check csv:parseLists(bookArray, customHeaders = ["name", "year"]); io:println(author); } ``` @@ -122,7 +122,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..41d8c38 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -30,8 +30,25 @@ 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 = [ +// "parse-string-record-types-tests" +// , +// "parse-string-array-types-tests" +// , +"parse-list-types-tests" +// , +// "parse-record-types-tests" +// , +// "user-config-tests" +// , +// "type-compatible-tests" +// , +// "unicode-tests" +// , +// "constraint-validation-tests" +// , +// "union-type-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..a308c12 100644 --- a/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal +++ b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal @@ -32,52 +32,52 @@ type ConstrainedRec record { @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:parseLists([["4", "abc"], ["3", "cde"]], ["a", "b"]); test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); - cRec1 = csv:parseListAsRecordType([["4", "abc"], ["11", "cde"]], ["a", "b"]); + cRec1 = csv:parseLists([["4", "abc"], ["11", "cde"]], ["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:parseLists([["4", "abc"], ["5", "b"]], ["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/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..9829251 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:parseLists([st1, st1], {}, StringTuple1Array); test:assertEquals(st1st1, [ [s1, s2, "", ""], [s1, s2, "", ""] ]); - StringTuple1Array|csv:Error st2st1 = csv:parseListAsListType([st2, st2], {}, StringTuple1Array); + StringTuple1Array|csv:Error st2st1 = csv:parseLists([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:parseLists([st3, st3], {}, StringTuple1Array); test:assertEquals(st3st1, [ [s1, s2, "", ""], [s1, s2, "", ""] ]); - StringTuple1Array|csv:Error st4st1 = csv:parseListAsListType([st4, st4], {}, StringTuple1Array); + StringTuple1Array|csv:Error st4st1 = csv:parseLists([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:parseLists([st1, st1], {}, StringTuple2Array); test:assertEquals(st1st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|csv:Error st2st2 = csv:parseListAsListType([st2, st2], {}, StringTuple2Array); + StringTuple2Array|csv:Error st2st2 = csv:parseLists([st2, st2], {}, StringTuple2Array); test:assertEquals(st2st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|csv:Error st3st2 = csv:parseListAsListType([st3, st3], {}, StringTuple2Array); + StringTuple2Array|csv:Error st3st2 = csv:parseLists([st3, st3], {}, StringTuple2Array); test:assertEquals(st3st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|csv:Error st4st2 = csv:parseListAsListType([st4, st4], {}, StringTuple2Array); + StringTuple2Array|csv:Error st4st2 = csv:parseLists([st4, st4], {}, StringTuple2Array); test:assertEquals(st4st2, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|csv:Error st1st3 = csv:parseListAsListType([st1, st1], {}, StringTuple3Array); + StringTuple3Array|csv:Error st1st3 = csv:parseLists([st1, st1], {}, StringTuple3Array); test:assertEquals(st1st3, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|csv:Error st2st3 = csv:parseListAsListType([st2, st2], {}, StringTuple3Array); + StringTuple3Array|csv:Error st2st3 = csv:parseLists([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:parseLists([st3, st3], {}, StringTuple3Array); test:assertEquals(st3st3, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|csv:Error st4st3 = csv:parseListAsListType([st4, st4], {}, StringTuple3Array); + StringTuple3Array|csv:Error st4st3 = csv:parseLists([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:parseLists([st1, st1], {}, StringTuple4Array); test:assertEquals(st1st4, [ [s1, s2], [s1, s2] ]); - StringTuple4Array|csv:Error st2st4 = csv:parseListAsListType([st2, st2], {}, StringTuple4Array); + StringTuple4Array|csv:Error st2st4 = csv:parseLists([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:parseLists([st3, st3], {}, StringTuple4Array); test:assertEquals(st3st4, [ [s1, s2], [s1, s2] ]); - StringTuple4Array|csv:Error st4st4 = csv:parseListAsListType([st4, st4], {}, StringTuple4Array); + StringTuple4Array|csv:Error st4st4 = csv:parseLists([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:parseLists([st1, st1], {}, AnydataTuple3Array); test:assertEquals(st1anydt3, [ [s1, s2], [s1, s2] ]); - AnydataTuple3Array|csv:Error st2anydt3 = csv:parseListAsListType([st2, st2], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error st2anydt3 = csv:parseLists([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:parseLists([st3, st3], {}, AnydataTuple3Array); test:assertEquals(st3anydt3, [ [s1, s2], [s1, s2] ]); - AnydataTuple3Array|csv:Error st4anydt3 = csv:parseListAsListType([st4, st4], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error st4anydt3 = csv:parseLists([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:parseLists([st1, st1], {}, JsonTuple3Array); test:assertEquals(st1jt3, [ [s1, s2], [s1, s2] ]); - JsonTuple3Array|csv:Error st2jt3 = csv:parseListAsListType([st2, st2], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error st2jt3 = csv:parseLists([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:parseLists([st3, st3], {}, JsonTuple3Array); test:assertEquals(st3jt3, [ [s1, s2], [s1, s2] ]); - JsonTuple3Array|csv:Error st4jt3 = csv:parseListAsListType([st4, st4], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error st4jt3 = csv:parseLists([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:parseLists([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:parseLists([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:parseLists([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:parseLists([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:parseLists([["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:parseLists( [["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:parseLists( [["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:parseLists( [["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:parseLists( [["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:parseLists( [["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:parseLists( [["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:parseLists( [["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:parseLists( [["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:parseLists( [["1", "a"], ["1", "a"]]); test:assertEquals(ct1bt13, [ ["1", "a"], ["1", "a"] ]); - [boolean...][]|csv:Error ct1bt14 = csv:parseListAsListType( + [boolean...][]|csv:Error ct1bt14 = csv:parseLists( [["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:parseLists( [["1", "()"], ["1", "2"]]); test:assertEquals(ct1bt15, [ [1, ()], [1, 2] ]); - int[][]|csv:Error ct1bt16 = csv:parseListAsListType( + int[][]|csv:Error ct1bt16 = csv:parseLists( [["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:parseLists( [["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:parseLists([st1, st1], {}, StringArrayArray); test:assertEquals(st1saa, [ [s1, s2], [s1, s2] ]); - StringArrayArray|csv:Error st2saa = csv:parseListAsListType([st2, st2], {}, StringArrayArray); + StringArrayArray|csv:Error st2saa = csv:parseLists([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:parseLists([st3, st3], {}, StringArrayArray); test:assertEquals(st3saa, [ [s1, s2], [s1, s2] ]); - StringArrayArray|csv:Error st4saa = csv:parseListAsListType([st4, st4], {}, StringArrayArray); + StringArrayArray|csv:Error st4saa = csv:parseLists([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:parseLists([st1, st1], {}, NillableStringArrayArray); test:assertEquals(st1nsaa, [ [s1, s2], [s1, s2] ]); - NillableStringArrayArray|csv:Error st2nsaa = csv:parseListAsListType([st2, st2], {}, NillableStringArrayArray); + NillableStringArrayArray|csv:Error st2nsaa = csv:parseLists([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:parseLists([st3, st3], {}, NillableStringArrayArray); test:assertEquals(st3nsaa, [ [s1, s2], [s1, s2] ]); - NillableStringArrayArray|csv:Error st4nsaa = csv:parseListAsListType([st4, st4], {}, NillableStringArrayArray); + NillableStringArrayArray|csv:Error st4nsaa = csv:parseLists([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:parseLists([st1, st1], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st1nsuiaa, [ [s1, s2], [s1, s2] @@ -332,101 +332,265 @@ function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { @test:Config function testFromCsvWithTypeForTupleAndTupleAsExpectedType4() { - NillableIntOrUnionStringArrayArray|csv:Error st2nsuiaa = csv:parseListAsListType([st2, st2], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|csv:Error st2nsuiaa = csv:parseLists([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:parseLists([st3, st3], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st3nsuiaa, [ [s1, s2], [s1, s2] ]); - NillableIntOrUnionStringArrayArray|csv:Error st4nsuiaa = csv:parseListAsListType([st4, st4], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|csv:Error st4nsuiaa = csv:parseLists([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:parseLists([st1, st1], {}, StringArray2Array); test:assertEquals(st1saa2, [ [s1, s2], [s1, s2] ]); - StringArray2Array|csv:Error st2saa2 = csv:parseListAsListType([st2, st2], {}, StringArray2Array); + StringArray2Array|csv:Error st2saa2 = csv:parseLists([st2, st2], {}, StringArray2Array); test:assertEquals(st2saa2, [ [s1, s2], [s1, s2] ]); - StringArray2Array|csv:Error st3saa2 = csv:parseListAsListType([st3, st3], {}, StringArray2Array); + StringArray2Array|csv:Error st3saa2 = csv:parseLists([st3, st3], {}, StringArray2Array); test:assertEquals(st3saa2, [ [s1, s2], [s1, s2] ]); - StringArray2Array|csv:Error st4saa2 = csv:parseListAsListType([st4, st4], {}, StringArray2Array); + StringArray2Array|csv:Error st4saa2 = csv:parseLists([st4, st4], {}, StringArray2Array); test:assertEquals(st4saa2, [ [s1, s2], [s1, s2] ]); - JsonArray1Array|csv:Error st1jaa = csv:parseListAsListType([st1, st1], {}, JsonArray1Array); + JsonArray1Array|csv:Error st1jaa = csv:parseLists([st1, st1], {}, JsonArray1Array); test:assertEquals(st1jaa, [ [s1, s2], [s1, s2] ]); - JsonArray1Array|csv:Error st2jaa = csv:parseListAsListType([st2, st2], {}, JsonArray1Array); + JsonArray1Array|csv:Error st2jaa = csv:parseLists([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:parseLists([st3, st3], {}, JsonArray1Array); test:assertEquals(st3jaa, [ [s1, s2], [s1, s2] ]); - JsonArray1Array|csv:Error st4jaa = csv:parseListAsListType([st4, st4], {}, JsonArray1Array); + JsonArray1Array|csv:Error st4jaa = csv:parseLists([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:parseLists([st1, st1], {}, AnydataArray1Array); test:assertEquals(st1anyda, [ [s1, s2], [s1, s2] ]); - AnydataArray1Array|csv:Error st2anyda = csv:parseListAsListType([st2, st2], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error st2anyda = csv:parseLists([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:parseLists([st3, st3], {}, AnydataArray1Array); test:assertEquals(st3anyda, [ [s1, s2], [s1, s2] ]); - AnydataArray1Array|csv:Error st4anyda = csv:parseListAsListType([st4, st4], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error st4anyda = csv:parseLists([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:parseLists([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:parseLists([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:parseLists(csv); + test:assertEquals(rec3_2, [ + [1, 2], + [3, 4] + ]); + + int[2][]|csv:Error rec5 = csv:parseLists(csv); + test:assertEquals(rec5, [ + [1, 2, 3], + [3, 4, 5] + ]); +} + +@test:Config +function testParseListsWithOutputHeaders() { + [string, boolean, int][]|csv:Error ct1bt1 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); + test:assertEquals(ct1bt1, [ + ["a", true, 1] + ]); + + ct1bt1 = csv:parseLists([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); + test:assertEquals(ct1bt1, []); + + ct1bt1 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); + test:assertEquals(ct1bt1, [ + ["a", true, 1] + ]); + + ct1bt1 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); + test:assertEquals(ct1bt1, [ + ["a", true, 1], + ["a", true, 1] + ]); + + ct1bt1 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21}); + test:assertEquals(ct1bt1, []); + + (string|boolean|int)[][]|csv:Error ct1bt1_2 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); + test:assertEquals(ct1bt1_2, [ + ["a", true, 1] + ]); + + ct1bt1_2 = csv:parseLists([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); + test:assertEquals(ct1bt1_2, []); + + ct1bt1_2 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); + test:assertEquals(ct1bt1_2, [ + ["a", true, 1] + ]); + + ct1bt1_2 = csv:parseLists([["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:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21}); + test:assertEquals(ct1bt1_2, []); + + [string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); + test:assertEquals(ct1bt1_3, [ + ["a", true, 1], + ["a", true, 1] + ]); + + ct1bt1_3 = csv:parseLists([["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:parseLists([["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:parseLists([["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:parseLists([["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:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21, outputWithHeaders: true}); + test:assertEquals(ct1bt1_3, []); + + string[][]|csv:Error ct1bt1_4 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); + test:assertEquals(ct1bt1_4, [ + ["a", "b", "c"], + ["a", "true", "1"] + ]); + + ct1bt1_4 = csv:parseLists([["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:parseLists([["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:parseLists([["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:parseLists([["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:parseLists([["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:parseLists([["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:parseLists([["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:parseLists([["1", "a"], ["1", "a"]]); + test:assertEquals(ct1bt2, [ + ["1", "a"], + ["1", "a"] + ]); + + [string, boolean|string, int|string...][]|csv:Error ct1bt2_2 = csv:parseLists([["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:parseLists([["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:parseLists([["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] + ]); +} 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..e8bb1b8 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 @@ -1,784 +1,795 @@ -// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// -// WSO2 LLC. licenses this file to you under the Apache License, -// Version 2.0 (the "License"); you may not use this file except -// in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -import ballerina/csv_commons as common; -import ballerina/data.csv; -import ballerina/test; - -@test:Config -function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { - StringRecord1Array|csv:Error st1sr1 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord1Array); - test:assertTrue(st1sr1 is csv:Error); - test:assertEquals((st1sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - - StringRecord1Array|csv:Error st2sr1 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord1Array); - test:assertTrue(st2sr1 is csv:Error); - test:assertEquals((st2sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - - StringRecord2Array|csv:Error st1sr2 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord2Array); - 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); - 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); - 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); - 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); - test:assertEquals(st1sr10, [ - {'1: "string", '2: ""}, - {'1: "string", '2: ""} - ]); - - StringRecord10Array|csv:Error st2sr10 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord10Array); - test:assertEquals(st2sr10, [ - {'1: "string", '2: "", '3: "a", '4: ""}, - {'1: "string", '2: "", '3: "a", '4: ""} - ]); - - StringRecord19Array|csv:Error st1sr19 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord19Array); - test:assertEquals(st1sr19, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord19Array|csv:Error st2sr19 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord19Array); - 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); - test:assertEquals(st1sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); -} - -@test:Config -function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { - StringRecord20Array|csv:Error st2sr20 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord20Array); - test:assertEquals(st2sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord21Array|csv:Error st1sr21 = csv:parseListAsRecordType([st1, st1], (), {}, StringRecord21Array); - test:assertEquals(st1sr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord21Array|csv:Error st2sr21 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord21Array); - 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); - test:assertEquals(st1sr22, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord22Array|csv:Error st2sr22 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord22Array); - 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); - test:assertEquals(st1sr23, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord23Array|csv:Error st2sr23 = csv:parseListAsRecordType([st2, st2], (), {}, StringRecord23Array); - 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); - test:assertEquals(st1cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord15Array|csv:Error st2cr15 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord15Array); - test:assertEquals(st2cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord16Array|csv:Error st1cr16 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord16Array); - test:assertTrue(st1cr16 is csv:Error); - test:assertEquals((st1cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); - - CustomRecord16Array|csv:Error st2cr16 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord16Array); - 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); - test:assertEquals(st1cr17, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); -} - -@test:Config -function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { - CustomRecord17Array|csv:Error st2cr17 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord17Array); - 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); - test:assertTrue(st1cr18 is csv:Error); - test:assertEquals((st1cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); - - CustomRecord18Array|csv:Error st2cr18 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord18Array); - 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); - test:assertEquals(st1cr19, [ - {'1: s1, '2: s2, '3: "", '4: ""}, - {'1: s1, '2: s2, '3: "", '4: ""} - ]); - - CustomRecord19Array|csv:Error st2cr19 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord19Array); - 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); - test:assertEquals(st1cr20, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord20Array|csv:Error st2cr20 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord20Array); - 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); - test:assertEquals(st1cr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord21Array|csv:Error st2cr21 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord21Array); - 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); - test:assertEquals(st1cr22, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); -} - -@test:Config -function testFromCsvWithTypeForTupleAndRecordAsExpectedType4() { - CustomRecord22Array|csv:Error st2cr22 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord22Array); - 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); - test:assertEquals(st1cr23, [ - {"1": s1, "2": s2, a: ""}, - {"1": s1, "2": s2, a: ""} - ]); - - CustomRecord23Array|csv:Error st2cr23 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord23Array); - 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); - test:assertEquals(st1cr24, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord24Array|csv:Error st2cr24 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord24Array); - 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); - test:assertTrue(st1cr25 is csv:Error); - test:assertEquals((st1cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - - CustomRecord25Array|csv:Error st2cr25 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord25Array); - test:assertTrue(st2cr25 is csv:Error); - test:assertEquals((st2cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - - CustomRecord25Array|csv:Error st3cr25 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord25Array); - test:assertTrue(st3cr25 is csv:Error); - test:assertEquals((st3cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - - CustomRecord25Array|csv:Error st4cr25 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord25Array); - test:assertTrue(st4cr25 is csv:Error); - test:assertEquals((st4cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - - CustomRecord26Array|csv:Error st1cr26 = csv:parseListAsRecordType([st1, st1], (), {}, CustomRecord26Array); - test:assertEquals(st1cr26 , [ - {'1: s1}, - {'1: s1} - ]); - - CustomRecord26Array|csv:Error st2cr26 = csv:parseListAsRecordType([st2, st2], (), {}, CustomRecord26Array); - test:assertEquals(st2cr26 , [ - {'1: s1}, - {'1: s1} - ]); - - CustomRecord26Array|csv:Error st3cr26 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord26Array); - test:assertEquals(st3cr26 , [ - {'1: s1}, - {'1: s1} - ]); - - CustomRecord26Array|csv:Error st4cr26 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord26Array); - test:assertEquals(st4cr26 , [ - {'1: s1}, - {'1: s1} - ]); -} - -@test:Config -function testFromCsvWithTypeForTupleAndRecordAsExpectedType5() { - StringRecord1Array|csv:Error st3sr1 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord1Array); - test:assertTrue(st3sr1 is csv:Error); - test:assertEquals((st3sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - - StringRecord1Array|csv:Error st4sr1 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord1Array); - test:assertTrue(st4sr1 is csv:Error); - test:assertEquals((st4sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - - StringRecord2Array|csv:Error st3sr2 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord2Array); - 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); - 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); - test:assertTrue(st3sr9 is csv:Error); - test:assertEquals((st3sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); - - StringRecord9Array|csv:Error st4sr9 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord9Array); - test:assertTrue(st4sr9 is csv:Error); - test:assertEquals((st4sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); - - StringRecord10Array|csv:Error st3sr10 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord10Array); - test:assertEquals(st3sr10, [ - {'1: "string", '2: ""}, - {'1: "string", '2: ""} - ]); - - StringRecord10Array|csv:Error st4sr10 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord10Array); - test:assertEquals(st4sr10, [ - {'1: "string", '2: "", '3: "a", '4: ""}, - {'1: "string", '2: "", '3: "a", '4: ""} - ]); - - StringRecord19Array|csv:Error st3sr19 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord19Array); - test:assertEquals(st3sr19, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord19Array|csv:Error st4sr19 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord19Array); - 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); - test:assertEquals(st3sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord20Array|csv:Error st4sr20 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord20Array); - test:assertEquals(st4sr20, [ - {s1: "", s2: ""}, - {s1: "", s2: ""} - ]); - - StringRecord21Array|csv:Error st3sr21 = csv:parseListAsRecordType([st3, st3], (), {}, StringRecord21Array); - test:assertEquals(st3sr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord21Array|csv:Error st4sr21 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord21Array); - 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); - test:assertEquals(st3sr22, [ - {s1: "", s2: "", "1": s1, "2": s2}, - {s1: "", s2: "", "1": s1, "2": s2} - ]); - - StringRecord22Array|csv:Error st4sr22 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord22Array); - 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); - test:assertEquals(st3sr23, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - StringRecord23Array|csv:Error st4sr23 = csv:parseListAsRecordType([st4, st4], (), {}, StringRecord23Array); - 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); - test:assertEquals(st3cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); -} - -@test:Config -function testFromCsvWithTypeForTupleAndRecordAsExpectedType6() { - CustomRecord15Array|csv:Error st4cr15 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord15Array); - test:assertEquals(st4cr15, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord16Array|csv:Error st3cr16 = csv:parseListAsRecordType([st3, st3], (), {}, CustomRecord16Array); - test:assertTrue(st3cr16 is csv:Error); - test:assertEquals((st3cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); - - CustomRecord16Array|csv:Error st4cr16 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord16Array); - 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); - test:assertEquals(st3cr17, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord17Array|csv:Error st4cr17 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord17Array); - 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); - test:assertTrue(st3cr18 is csv:Error); - test:assertEquals((st3cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); - - CustomRecord18Array|csv:Error st4cr18 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord18Array); - 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); - test:assertEquals(st3cr19, [ - {'1: s1, '2: s2, '3: "", '4: ""}, - {'1: s1, '2: s2, '3: "", '4: ""} - ]); - - CustomRecord19Array|csv:Error st4cr19 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord19Array); - 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); - test:assertEquals(st3cr20, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord20Array|csv:Error st4cr20 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord20Array); - 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); - test:assertEquals(st3cr21, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord21Array|csv:Error st4cr21 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord21Array); - 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); - test:assertEquals(st3cr22, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord22Array|csv:Error st4cr22 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord22Array); - 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); - test:assertEquals(st3cr23, [ - {"1": s1, "2": s2, a: ""}, - {"1": s1, "2": s2, a: ""} - ]); - - CustomRecord23Array|csv:Error st4cr23 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord23Array); - 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); - test:assertEquals(st3cr24, [ - {"1": s1, "2": s2}, - {"1": s1, "2": s2} - ]); - - CustomRecord24Array|csv:Error st4cr24 = csv:parseListAsRecordType([st4, st4], (), {}, CustomRecord24Array); - test:assertEquals(st4cr24, [ - {'1: s1, '2: s2, '3: s3, '4: s2}, - {'1: s1, '2: s2, '3: s3, '4: s2} - ]); -} - -@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"], {}); - 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( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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 testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { - record{|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseListAsRecordType( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["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( - [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], - ["f", "e", "d", "c", "b", "a"]); - test:assertEquals(ct1br12, [ - {a: ()}, - {a: ()} - ]); - - record{|string?...;|}[]|csv:Error ct1br13 = csv:parseListAsRecordType( - [["a", "1"], ["a", "1"]], - ["f", "e"]); - test:assertEquals(ct1br13, [ - {e: "1", f: "a"}, - {e: "1", f: "a"} - ]); - - record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseListAsRecordType( - [["2.23", "null"], ["7", "()"]], - ["b", "a"]); - test:assertEquals(ct1br14, [ - {}, - {} - ]); - - map[]|csv:Error ct1br15 = csv:parseListAsRecordType( - [["2", "()"], ["2", "1"], ["()", "2"]], - ["f", "e"]); - test:assertEquals(ct1br15, [ - {e: (), f: 2}, - {e: 1, f: 2}, - {e: 2, f: ()} - ]); - - record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseListAsRecordType( - [["2.23", "null"], ["7", "()"]], - ["b", "a"]); - test:assertEquals(ct1br16, [ - {}, - {} - ]); -} - -@test:Config -function testFromCsvWithTypeForTupleAndMapAsExpectedType() { - StringMapArray|csv:Error st1sma = csv:parseListAsRecordType([st1, st1], (), {}, StringMapArray); - test:assertEquals(st1sma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - StringMapArray|csv:Error st2sma = csv:parseListAsRecordType([st2, st2], (), {}, StringMapArray); - 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); - test:assertEquals(st3sma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - StringMapArray|csv:Error st4sma = csv:parseListAsRecordType([st4, st4], (), {}, StringMapArray); - 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); - test:assertEquals(st1niusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - NillableIntUnionStringMapArray|csv:Error st2niusma = csv:parseListAsRecordType([st2, st2], (), {}, NillableIntUnionStringMapArray); - 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); - test:assertEquals(st3niusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - NillableIntUnionStringMapArray|csv:Error st4niusma = csv:parseListAsRecordType([st4, st4], (), {}, NillableIntUnionStringMapArray); - 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); - test:assertEquals(st1iusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - IntUnionStringMapArray|csv:Error st2iusma = csv:parseListAsRecordType([st2, st2], (), {}, IntUnionStringMapArray); - 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); - test:assertEquals(st3iusma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - IntUnionStringMapArray|csv:Error st4iusma = csv:parseListAsRecordType([st4, st4], (), {}, IntUnionStringMapArray); - 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); - test:assertEquals(st1jma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); -} - -@test:Config -function testFromCsvWithTypeForTupleAndMapAsExpectedType2() { - JsonMapArray|csv:Error st2jma = csv:parseListAsRecordType([st2, st2], (), {}, JsonMapArray); - 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); - test:assertEquals(st3jma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - JsonMapArray|csv:Error st4jma = csv:parseListAsRecordType([st4, st4], (), {}, JsonMapArray); - 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); - test:assertEquals(st1anydma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - AnydataMapArray|csv:Error st2anydma = csv:parseListAsRecordType([st2, st2], (), {}, AnydataMapArray); - 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); - test:assertEquals(st3anydma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - AnydataMapArray|csv:Error st4anydma = csv:parseListAsRecordType([st4, st4], (), {}, AnydataMapArray); - 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); - test:assertEquals(st1cma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - CustomMapArray|csv:Error st2cma = csv:parseListAsRecordType([st2, st2], (), {}, CustomMapArray); - 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); - test:assertEquals(st3cma , [ - {'1: s1, '2: s2}, - {'1: s1, '2: s2} - ]); - - CustomMapArray|csv:Error st4cma = csv:parseListAsRecordType([st4, st4], (), {}, CustomMapArray); - 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); - test:assertEquals(st1nma, ([ - {}, - {} - ])); - - IntegerMapArray|csv:Error st2ima = csv:parseListAsRecordType([st2, st2], (), {}, IntegerMapArray); - test:assertEquals(st2ima, ([ - {}, - {} - ])); - - DecimalMapArray|csv:Error st3dma = csv:parseListAsRecordType([st3, st3], (), {}, DecimalMapArray); - test:assertEquals(st3dma, ([ - {}, - {} - ])); - - BooleanMapArray|csv:Error st4bma = csv:parseListAsRecordType([st4, st4], (), {}, BooleanMapArray); - test:assertEquals(st4bma, ([ - {}, - {} - ])); -} +// // Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// // +// // WSO2 LLC. licenses this file to you under the Apache License, +// // Version 2.0 (the "License"); you may not use this file except +// // in compliance with the License. +// // You may obtain a copy of the License at +// // +// // http://www.apache.org/licenses/LICENSE-2.0 +// // +// // Unless required by applicable law or agreed to in writing, +// // software distributed under the License is distributed on an +// // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// // KIND, either express or implied. See the License for the +// // specific language governing permissions and limitations +// // under the License. + +// import ballerina/csv_commons as common; +// import ballerina/data.csv; +// import ballerina/test; + +// @test:Config +// function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { +// StringRecord1Array|csv:Error st1sr1 = csv:parseLists([st1, st1], (), {}, StringRecord1Array); +// test:assertTrue(st1sr1 is csv:Error); +// test:assertEquals((st1sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + +// StringRecord1Array|csv:Error st2sr1 = csv:parseLists([st2, st2], (), {}, StringRecord1Array); +// test:assertTrue(st2sr1 is csv:Error); +// test:assertEquals((st2sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + +// StringRecord2Array|csv:Error st1sr2 = csv:parseLists([st1, st1], (), {}, StringRecord2Array); +// test:assertTrue(st1sr2 is csv:Error); +// test:assertEquals((st1sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "parse_list_types_tests:StringRecord2")); + +// StringRecord2Array|csv:Error st2sr2 = csv:parseLists([st2, st2], (), {}, StringRecord2Array); +// test:assertTrue(st2sr2 is csv:Error); +// test:assertEquals((st2sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","parse_list_types_tests:StringRecord2")); + +// StringRecord9Array|csv:Error st1sr9 = csv:parseLists([st1, st1], (), {}, StringRecord9Array); +// test:assertTrue(st1sr9 is csv:Error); +// test:assertEquals((st1sr9).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "parse_list_types_tests:StringRecord9")); + +// StringRecord9Array|csv:Error st2sr9 = csv:parseLists([st2, st2], (), {}, StringRecord9Array); +// test:assertTrue(st2sr9 is csv:Error); +// test:assertEquals((st2sr9).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","parse_list_types_tests:StringRecord9")); + +// StringRecord10Array|csv:Error st1sr10 = csv:parseLists([st1, st1], (), {}, StringRecord10Array); +// test:assertEquals(st1sr10, [ +// {'1: "string", '2: ""}, +// {'1: "string", '2: ""} +// ]); + +// StringRecord10Array|csv:Error st2sr10 = csv:parseLists([st2, st2], (), {}, StringRecord10Array); +// test:assertEquals(st2sr10, [ +// {'1: "string", '2: "", '3: "a", '4: ""}, +// {'1: "string", '2: "", '3: "a", '4: ""} +// ]); + +// StringRecord19Array|csv:Error st1sr19 = csv:parseLists([st1, st1], (), {}, StringRecord19Array); +// test:assertEquals(st1sr19, [ +// {s1: "", s2: "", "1": s1, "2": s2}, +// {s1: "", s2: "", "1": s1, "2": s2} +// ]); + +// StringRecord19Array|csv:Error st2sr19 = csv:parseLists([st2, st2], (), {}, StringRecord19Array); +// 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:parseLists([st1, st1], (), {}, StringRecord20Array); +// test:assertEquals(st1sr20, [ +// {s1: "", s2: ""}, +// {s1: "", s2: ""} +// ]); +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { +// StringRecord20Array|csv:Error st2sr20 = csv:parseLists([st2, st2], (), {}, StringRecord20Array); +// test:assertEquals(st2sr20, [ +// {s1: "", s2: ""}, +// {s1: "", s2: ""} +// ]); + +// StringRecord21Array|csv:Error st1sr21 = csv:parseLists([st1, st1], (), {}, StringRecord21Array); +// test:assertEquals(st1sr21, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// StringRecord21Array|csv:Error st2sr21 = csv:parseLists([st2, st2], (), {}, StringRecord21Array); +// test:assertEquals(st2sr21, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// StringRecord22Array|csv:Error st1sr22 = csv:parseLists([st1, st1], (), {}, StringRecord22Array); +// test:assertEquals(st1sr22, [ +// {s1: "", s2: "", "1": s1, "2": s2}, +// {s1: "", s2: "", "1": s1, "2": s2} +// ]); + +// StringRecord22Array|csv:Error st2sr22 = csv:parseLists([st2, st2], (), {}, StringRecord22Array); +// 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:parseLists([st1, st1], (), {}, StringRecord23Array); +// test:assertEquals(st1sr23, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// StringRecord23Array|csv:Error st2sr23 = csv:parseLists([st2, st2], (), {}, StringRecord23Array); +// test:assertEquals(st2sr23, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord15Array|csv:Error st1cr15 = csv:parseLists([st1, st1], (), {}, CustomRecord15Array); +// test:assertEquals(st1cr15, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord15Array|csv:Error st2cr15 = csv:parseLists([st2, st2], (), {}, CustomRecord15Array); +// test:assertEquals(st2cr15, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord16Array|csv:Error st1cr16 = csv:parseLists([st1, st1], (), {}, CustomRecord16Array); +// test:assertTrue(st1cr16 is csv:Error); +// test:assertEquals((st1cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); + +// CustomRecord16Array|csv:Error st2cr16 = csv:parseLists([st2, st2], (), {}, CustomRecord16Array); +// test:assertEquals(st2cr16, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord17Array|csv:Error st1cr17 = csv:parseLists([st1, st1], (), {}, CustomRecord17Array); +// test:assertEquals(st1cr17, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { +// CustomRecord17Array|csv:Error st2cr17 = csv:parseLists([st2, st2], (), {}, CustomRecord17Array); +// test:assertEquals(st2cr17, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord18Array|csv:Error st1cr18 = csv:parseLists([st1, st1], (), {}, CustomRecord18Array); +// test:assertTrue(st1cr18 is csv:Error); +// test:assertEquals((st1cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); + +// CustomRecord18Array|csv:Error st2cr18 = csv:parseLists([st2, st2], (), {}, CustomRecord18Array); +// test:assertEquals(st2cr18, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord19Array|csv:Error st1cr19 = csv:parseLists([st1, st1], (), {}, CustomRecord19Array); +// test:assertEquals(st1cr19, [ +// {'1: s1, '2: s2, '3: "", '4: ""}, +// {'1: s1, '2: s2, '3: "", '4: ""} +// ]); + +// CustomRecord19Array|csv:Error st2cr19 = csv:parseLists([st2, st2], (), {}, CustomRecord19Array); +// test:assertEquals(st2cr19, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord20Array|csv:Error st1cr20 = csv:parseLists([st1, st1], (), {}, CustomRecord20Array); +// test:assertEquals(st1cr20, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord20Array|csv:Error st2cr20 = csv:parseLists([st2, st2], (), {}, CustomRecord20Array); +// test:assertEquals(st2cr20, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord21Array|csv:Error st1cr21 = csv:parseLists([st1, st1], (), {}, CustomRecord21Array); +// test:assertEquals(st1cr21, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord21Array|csv:Error st2cr21 = csv:parseLists([st2, st2], (), {}, CustomRecord21Array); +// test:assertEquals(st2cr21, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord22Array|csv:Error st1cr22 = csv:parseLists([st1, st1], (), {}, CustomRecord22Array); +// test:assertEquals(st1cr22, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndRecordAsExpectedType4() { +// CustomRecord22Array|csv:Error st2cr22 = csv:parseLists([st2, st2], (), {}, CustomRecord22Array); +// test:assertEquals(st2cr22, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord23Array|csv:Error st1cr23 = csv:parseLists([st1, st1], (), {}, CustomRecord23Array); +// test:assertEquals(st1cr23, [ +// {"1": s1, "2": s2, a: ""}, +// {"1": s1, "2": s2, a: ""} +// ]); + +// CustomRecord23Array|csv:Error st2cr23 = csv:parseLists([st2, st2], (), {}, CustomRecord23Array); +// 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:parseLists([st1, st1], (), {}, CustomRecord24Array); +// test:assertEquals(st1cr24, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord24Array|csv:Error st2cr24 = csv:parseLists([st2, st2], (), {}, CustomRecord24Array); +// test:assertEquals(st2cr24, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord25Array|csv:Error st1cr25 = csv:parseLists([st1, st1], (), {}, CustomRecord25Array); +// test:assertTrue(st1cr25 is csv:Error); +// test:assertEquals((st1cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + +// CustomRecord25Array|csv:Error st2cr25 = csv:parseLists([st2, st2], (), {}, CustomRecord25Array); +// test:assertTrue(st2cr25 is csv:Error); +// test:assertEquals((st2cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + +// CustomRecord25Array|csv:Error st3cr25 = csv:parseLists([st3, st3], (), {}, CustomRecord25Array); +// test:assertTrue(st3cr25 is csv:Error); +// test:assertEquals((st3cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + +// CustomRecord25Array|csv:Error st4cr25 = csv:parseLists([st4, st4], (), {}, CustomRecord25Array); +// test:assertTrue(st4cr25 is csv:Error); +// test:assertEquals((st4cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + +// CustomRecord26Array|csv:Error st1cr26 = csv:parseLists([st1, st1], (), {}, CustomRecord26Array); +// test:assertEquals(st1cr26 , [ +// {'1: s1}, +// {'1: s1} +// ]); + +// CustomRecord26Array|csv:Error st2cr26 = csv:parseLists([st2, st2], (), {}, CustomRecord26Array); +// test:assertEquals(st2cr26 , [ +// {'1: s1}, +// {'1: s1} +// ]); + +// CustomRecord26Array|csv:Error st3cr26 = csv:parseLists([st3, st3], (), {}, CustomRecord26Array); +// test:assertEquals(st3cr26 , [ +// {'1: s1}, +// {'1: s1} +// ]); + +// CustomRecord26Array|csv:Error st4cr26 = csv:parseLists([st4, st4], (), {}, CustomRecord26Array); +// test:assertEquals(st4cr26 , [ +// {'1: s1}, +// {'1: s1} +// ]); +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndRecordAsExpectedType5() { +// StringRecord1Array|csv:Error st3sr1 = csv:parseLists([st3, st3], (), {}, StringRecord1Array); +// test:assertTrue(st3sr1 is csv:Error); +// test:assertEquals((st3sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + +// StringRecord1Array|csv:Error st4sr1 = csv:parseLists([st4, st4], (), {}, StringRecord1Array); +// test:assertTrue(st4sr1 is csv:Error); +// test:assertEquals((st4sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + +// StringRecord2Array|csv:Error st3sr2 = csv:parseLists([st3, st3], (), {}, StringRecord2Array); +// test:assertTrue(st3sr2 is csv:Error); +// test:assertEquals((st3sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "parse_list_types_tests:StringRecord2")); + +// StringRecord2Array|csv:Error st4sr2 = csv:parseLists([st4, st4], (), {}, StringRecord2Array); +// test:assertTrue(st4sr2 is csv:Error); +// test:assertEquals((st4sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","parse_list_types_tests:StringRecord2")); + +// StringRecord9Array|csv:Error st3sr9 = csv:parseLists([st3, st3], (), {}, StringRecord9Array); +// test:assertTrue(st3sr9 is csv:Error); +// test:assertEquals((st3sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); + +// StringRecord9Array|csv:Error st4sr9 = csv:parseLists([st4, st4], (), {}, StringRecord9Array); +// test:assertTrue(st4sr9 is csv:Error); +// test:assertEquals((st4sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); + +// StringRecord10Array|csv:Error st3sr10 = csv:parseLists([st3, st3], (), {}, StringRecord10Array); +// test:assertEquals(st3sr10, [ +// {'1: "string", '2: ""}, +// {'1: "string", '2: ""} +// ]); + +// StringRecord10Array|csv:Error st4sr10 = csv:parseLists([st4, st4], (), {}, StringRecord10Array); +// test:assertEquals(st4sr10, [ +// {'1: "string", '2: "", '3: "a", '4: ""}, +// {'1: "string", '2: "", '3: "a", '4: ""} +// ]); + +// StringRecord19Array|csv:Error st3sr19 = csv:parseLists([st3, st3], (), {}, StringRecord19Array); +// test:assertEquals(st3sr19, [ +// {s1: "", s2: "", "1": s1, "2": s2}, +// {s1: "", s2: "", "1": s1, "2": s2} +// ]); + +// StringRecord19Array|csv:Error st4sr19 = csv:parseLists([st4, st4], (), {}, StringRecord19Array); +// 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:parseLists([st3, st3], (), {}, StringRecord20Array); +// test:assertEquals(st3sr20, [ +// {s1: "", s2: ""}, +// {s1: "", s2: ""} +// ]); + +// StringRecord20Array|csv:Error st4sr20 = csv:parseLists([st4, st4], (), {}, StringRecord20Array); +// test:assertEquals(st4sr20, [ +// {s1: "", s2: ""}, +// {s1: "", s2: ""} +// ]); + +// StringRecord21Array|csv:Error st3sr21 = csv:parseLists([st3, st3], (), {}, StringRecord21Array); +// test:assertEquals(st3sr21, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// StringRecord21Array|csv:Error st4sr21 = csv:parseLists([st4, st4], (), {}, StringRecord21Array); +// test:assertEquals(st4sr21, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// StringRecord22Array|csv:Error st3sr22 = csv:parseLists([st3, st3], (), {}, StringRecord22Array); +// test:assertEquals(st3sr22, [ +// {s1: "", s2: "", "1": s1, "2": s2}, +// {s1: "", s2: "", "1": s1, "2": s2} +// ]); + +// StringRecord22Array|csv:Error st4sr22 = csv:parseLists([st4, st4], (), {}, StringRecord22Array); +// 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:parseLists([st3, st3], (), {}, StringRecord23Array); +// test:assertEquals(st3sr23, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// StringRecord23Array|csv:Error st4sr23 = csv:parseLists([st4, st4], (), {}, StringRecord23Array); +// test:assertEquals(st4sr23, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord15Array|csv:Error st3cr15 = csv:parseLists([st3, st3], (), {}, CustomRecord15Array); +// test:assertEquals(st3cr15, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndRecordAsExpectedType6() { +// CustomRecord15Array|csv:Error st4cr15 = csv:parseLists([st4, st4], (), {}, CustomRecord15Array); +// test:assertEquals(st4cr15, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord16Array|csv:Error st3cr16 = csv:parseLists([st3, st3], (), {}, CustomRecord16Array); +// test:assertTrue(st3cr16 is csv:Error); +// test:assertEquals((st3cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); + +// CustomRecord16Array|csv:Error st4cr16 = csv:parseLists([st4, st4], (), {}, CustomRecord16Array); +// test:assertEquals(st4cr16, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord17Array|csv:Error st3cr17 = csv:parseLists([st3, st3], (), {}, CustomRecord17Array); +// test:assertEquals(st3cr17, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord17Array|csv:Error st4cr17 = csv:parseLists([st4, st4], (), {}, CustomRecord17Array); +// test:assertEquals(st4cr17, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord18Array|csv:Error st3cr18 = csv:parseLists([st3, st3], (), {}, CustomRecord18Array); +// test:assertTrue(st3cr18 is csv:Error); +// test:assertEquals((st3cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); + +// CustomRecord18Array|csv:Error st4cr18 = csv:parseLists([st4, st4], (), {}, CustomRecord18Array); +// test:assertEquals(st4cr18, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord19Array|csv:Error st3cr19 = csv:parseLists([st3, st3], (), {}, CustomRecord19Array); +// test:assertEquals(st3cr19, [ +// {'1: s1, '2: s2, '3: "", '4: ""}, +// {'1: s1, '2: s2, '3: "", '4: ""} +// ]); + +// CustomRecord19Array|csv:Error st4cr19 = csv:parseLists([st4, st4], (), {}, CustomRecord19Array); +// test:assertEquals(st4cr19, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord20Array|csv:Error st3cr20 = csv:parseLists([st3, st3], (), {}, CustomRecord20Array); +// test:assertEquals(st3cr20, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord20Array|csv:Error st4cr20 = csv:parseLists([st4, st4], (), {}, CustomRecord20Array); +// test:assertEquals(st4cr20, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord21Array|csv:Error st3cr21 = csv:parseLists([st3, st3], (), {}, CustomRecord21Array); +// test:assertEquals(st3cr21, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord21Array|csv:Error st4cr21 = csv:parseLists([st4, st4], (), {}, CustomRecord21Array); +// test:assertEquals(st4cr21, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord22Array|csv:Error st3cr22 = csv:parseLists([st3, st3], (), {}, CustomRecord22Array); +// test:assertEquals(st3cr22, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord22Array|csv:Error st4cr22 = csv:parseLists([st4, st4], (), {}, CustomRecord22Array); +// test:assertEquals(st4cr22, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomRecord23Array|csv:Error st3cr23 = csv:parseLists([st3, st3], (), {}, CustomRecord23Array); +// test:assertEquals(st3cr23, [ +// {"1": s1, "2": s2, a: ""}, +// {"1": s1, "2": s2, a: ""} +// ]); + +// CustomRecord23Array|csv:Error st4cr23 = csv:parseLists([st4, st4], (), {}, CustomRecord23Array); +// 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:parseLists([st3, st3], (), {}, CustomRecord24Array); +// test:assertEquals(st3cr24, [ +// {"1": s1, "2": s2}, +// {"1": s1, "2": s2} +// ]); + +// CustomRecord24Array|csv:Error st4cr24 = csv:parseLists([st4, st4], (), {}, CustomRecord24Array); +// test:assertEquals(st4cr24, [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { +// record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["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:parseLists( +// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], +// ["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:parseLists( +// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], +// ["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:parseLists( +// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], +// ["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:parseLists( +// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], +// ["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:parseLists( +// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], +// ["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 testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { +// record{|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseLists( +// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], +// ["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:parseLists( +// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], +// ["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:parseLists( +// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], +// ["f", "e", "d", "c", "b", "a"]); +// test:assertEquals(ct1br12, [ +// {a: ()}, +// {a: ()} +// ]); + +// record{|string?...;|}[]|csv:Error ct1br13 = csv:parseLists( +// [["a", "1"], ["a", "1"]], +// ["f", "e"]); +// test:assertEquals(ct1br13, [ +// {e: "1", f: "a"}, +// {e: "1", f: "a"} +// ]); + +// record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseLists( +// [["2.23", "null"], ["7", "()"]], +// ["b", "a"]); +// test:assertEquals(ct1br14, [ +// {}, +// {} +// ]); + +// map[]|csv:Error ct1br15 = csv:parseLists( +// [["2", "()"], ["2", "1"], ["()", "2"]], +// ["f", "e"]); +// test:assertEquals(ct1br15, [ +// {e: (), f: 2}, +// {e: 1, f: 2}, +// {e: 2, f: ()} +// ]); + +// record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseLists( +// [["2.23", "null"], ["7", "()"]], +// ["b", "a"]); +// test:assertEquals(ct1br16, [ +// {}, +// {} +// ]); +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndMapAsExpectedType() { +// StringMapArray|csv:Error st1sma = csv:parseLists([st1, st1], (), {}, StringMapArray); +// test:assertEquals(st1sma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// StringMapArray|csv:Error st2sma = csv:parseLists([st2, st2], (), {}, StringMapArray); +// test:assertEquals(st2sma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// StringMapArray|csv:Error st3sma = csv:parseLists([st3, st3], (), {}, StringMapArray); +// test:assertEquals(st3sma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// StringMapArray|csv:Error st4sma = csv:parseLists([st4, st4], (), {}, StringMapArray); +// test:assertEquals(st4sma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// NillableIntUnionStringMapArray|csv:Error st1niusma = csv:parseLists([st1, st1], (), {}, NillableIntUnionStringMapArray); +// test:assertEquals(st1niusma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// NillableIntUnionStringMapArray|csv:Error st2niusma = csv:parseLists([st2, st2], (), {}, NillableIntUnionStringMapArray); +// test:assertEquals(st2niusma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// NillableIntUnionStringMapArray|csv:Error st3niusma = csv:parseLists([st3, st3], (), {}, NillableIntUnionStringMapArray); +// test:assertEquals(st3niusma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// NillableIntUnionStringMapArray|csv:Error st4niusma = csv:parseLists([st4, st4], (), {}, NillableIntUnionStringMapArray); +// test:assertEquals(st4niusma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// IntUnionStringMapArray|csv:Error st1iusma = csv:parseLists([st1, st1], (), {}, IntUnionStringMapArray); +// test:assertEquals(st1iusma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// IntUnionStringMapArray|csv:Error st2iusma = csv:parseLists([st2, st2], (), {}, IntUnionStringMapArray); +// test:assertEquals(st2iusma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// IntUnionStringMapArray|csv:Error st3iusma = csv:parseLists([st3, st3], (), {}, IntUnionStringMapArray); +// test:assertEquals(st3iusma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// IntUnionStringMapArray|csv:Error st4iusma = csv:parseLists([st4, st4], (), {}, IntUnionStringMapArray); +// test:assertEquals(st4iusma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// JsonMapArray|csv:Error st1jma = csv:parseLists([st1, st1], (), {}, JsonMapArray); +// test:assertEquals(st1jma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); +// } + +// @test:Config +// function testFromCsvWithTypeForTupleAndMapAsExpectedType2() { +// JsonMapArray|csv:Error st2jma = csv:parseLists([st2, st2], (), {}, JsonMapArray); +// test:assertEquals(st2jma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// JsonMapArray|csv:Error st3jma = csv:parseLists([st3, st3], (), {}, JsonMapArray); +// test:assertEquals(st3jma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// JsonMapArray|csv:Error st4jma = csv:parseLists([st4, st4], (), {}, JsonMapArray); +// test:assertEquals(st4jma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// AnydataMapArray|csv:Error st1anydma = csv:parseLists([st1, st1], (), {}, AnydataMapArray); +// test:assertEquals(st1anydma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// AnydataMapArray|csv:Error st2anydma = csv:parseLists([st2, st2], (), {}, AnydataMapArray); +// test:assertEquals(st2anydma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// AnydataMapArray|csv:Error st3anydma = csv:parseLists([st3, st3], (), {}, AnydataMapArray); +// test:assertEquals(st3anydma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// AnydataMapArray|csv:Error st4anydma = csv:parseLists([st4, st4], (), {}, AnydataMapArray); +// test:assertEquals(st4anydma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomMapArray|csv:Error st1cma = csv:parseLists([st1, st1], (), {}, CustomMapArray); +// test:assertEquals(st1cma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// CustomMapArray|csv:Error st2cma = csv:parseLists([st2, st2], (), {}, CustomMapArray); +// test:assertEquals(st2cma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// CustomMapArray|csv:Error st3cma = csv:parseLists([st3, st3], (), {}, CustomMapArray); +// test:assertEquals(st3cma , [ +// {'1: s1, '2: s2}, +// {'1: s1, '2: s2} +// ]); + +// CustomMapArray|csv:Error st4cma = csv:parseLists([st4, st4], (), {}, CustomMapArray); +// test:assertEquals(st4cma , [ +// {'1: s1, '2: s2, '3: s3, '4: s2}, +// {'1: s1, '2: s2, '3: s3, '4: s2} +// ]); + +// NilMapArray|csv:Error st1nma = csv:parseLists([st1, st1], (), {}, NilMapArray); +// test:assertEquals(st1nma, ([ +// {}, +// {} +// ])); + +// IntegerMapArray|csv:Error st2ima = csv:parseLists([st2, st2], (), {}, IntegerMapArray); +// test:assertEquals(st2ima, ([ +// {}, +// {} +// ])); + +// DecimalMapArray|csv:Error st3dma = csv:parseLists([st3, st3], (), {}, DecimalMapArray); +// test:assertEquals(st3dma, ([ +// {}, +// {} +// ])); + +// BooleanMapArray|csv:Error st4bma = csv:parseLists([st4, st4], (), {}, BooleanMapArray); +// test:assertEquals(st4bma, ([ +// {}, +// {} +// ])); +// } + +// @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:parseLists(csv, ["a", "b", "c"]); +// test:assertEquals(rec_2, [ +// {a: 1, b: 2, c: 3}, +// {a: 3, b: 4, c: 5} +// ]); +// } 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..ac27ba8 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], ["b1", "b2"], {}, BooleanArrayArray); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - bm1ba = csv:parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}, BooleanArrayArray); + bm1ba = csv:transform([bm1, bm1], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["b1", "b2", "b3", "b4"], {}, NilTuple3Array); test:assertTrue(bm5n3t is csv:Error); test:assertEquals((bm5n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); } @@ -474,83 +474,107 @@ 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], ["b1", "b2"], {}, 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], ["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], ["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], ["n1", "n3"], {}, 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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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], ["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, ["a", "b"]); + test:assertEquals(rec3, [ + [1, 2], + [3, 4], + [5, 6], + [7, 8] + ]); + + [int...][2]|csv:Error rec3_3 = csv:transform(csv, ["a", "b"], {skipLines: [1]}); + test:assertEquals(rec3_3, [ + [3, 4], + [5, 6] + ]); + + int[1][2]|csv:Error rec4 = csv:transform(csv, ["a", "b"], {skipLines: [2]}); + test:assertEquals(rec4, [ + [1, 2] + ]); +} \ No newline at end of file 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..cb7ed9f 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], {}, 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], {}, 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], {}, 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], {}, 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], {}, 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], {}, 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], {}, 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], {}, 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], {}, 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], {}, 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], {}, 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], {}, 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 testArrayIndexes() { + 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]}); + 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..66c4537 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,25 @@ 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, {}); + 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, {}); + 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 +242,7 @@ 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}, @@ -250,7 +250,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 +258,13 @@ function testParseStream() returns error? { ]); csvByteStream = check io:fileReadBlocksAsStream(filepath); - 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: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 +274,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 +288,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..37beb57 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,35 +22,35 @@ 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); + 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:parseRecordAsRecordType([value, value, value], {}, AnydataMapArray); + AnydataMapArray|csv:Error vanydma = csv:transform([value, value, value], {}, AnydataMapArray); test:assertEquals(vanydma , [ value, value, value ]); - JsonMapArray|csv:Error vjma = csv:parseRecordAsRecordType([value, value, value], {}, JsonMapArray); + JsonMapArray|csv:Error vjma = csv:transform([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}]); + 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:parseRecordAsRecordType([{"a": d1}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1, "d": f3}]); + 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}, @@ -58,21 +58,21 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {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}]); + 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:parseRecordAsRecordType([{"a": 1.2, "b": 1.2f}, {"a": d2, "b": d3}, {"a": d4, "b": f2, "c": s1}]); + 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:parseRecordAsRecordType([{"a": d1, "b": d2}, {"a": f1, "b": f2}, {"a": d2, "b": f2}, {"a": f2, "b": d2}]); + 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}, @@ -80,7 +80,7 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {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}]); + 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}, @@ -88,7 +88,7 @@ function testFromCsvWithTypeFunctionWithTypeCompatibility() { {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}]); + 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}, @@ -110,7 +110,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { readonly & int a; readonly & string b; (readonly & boolean) | (readonly & decimal) c; - }[]|csv:Error r1a = csv:parseStringToRecord( string `a,b,c + }[]|csv:Error r1a = csv:parseString( string `a,b,c 1,string,true 2,string2,false 3,string3,true`); @@ -121,7 +121,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {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`); @@ -132,7 +132,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {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`); @@ -143,7 +143,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {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 @@ -155,7 +155,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {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`); @@ -167,7 +167,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ]); [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error r16a = - csv:parseStringToList( string `a,b,c + csv:parseString( string `a,b,c 1,string,true 2,string2,false 3,string3,true`); @@ -178,7 +178,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|csv:Error r17a = csv:parseStringToList( + [A, B, C][]|csv:Error r17a = csv:parseString( string `a,b,c 1,string,true 2,string2,false @@ -190,7 +190,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2][]|csv:Error r18a = csv:parseStringToList( + [A2, B2, C2][]|csv:Error r18a = csv:parseString( string `a,b,c 1,string,true 2,string2,false @@ -202,7 +202,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2...][]|csv:Error r19a = csv:parseStringToList( + [A2, B2, C2...][]|csv:Error r19a = csv:parseString( string `a,b,c,d 1,string,true,string 2,string2,false,string2 @@ -214,7 +214,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true, "string3"] ]); - [C2...][]|csv:Error r20a = csv:parseStringToList( + [C2...][]|csv:Error r20a = csv:parseString( string `a,b,c,d 1,string,true,string 2,string2,false,string2 @@ -224,7 +224,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ["2", "string2", false, "string2"], ["3", "string3",true, "string3"]]); - record{A a; B b; C c;}[]|csv:Error rt2a = csv:parseRecordAsRecordType( + 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 , [ @@ -237,7 +237,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { readonly & int a; readonly & string b; (readonly & boolean) | (readonly & decimal) c; - }[]|csv:Error rt1a = csv:parseRecordAsRecordType( + }[]|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 , [ @@ -246,7 +246,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A2 a; B2 b; C2 c;}[]|csv:Error rt3a = csv:parseRecordAsRecordType( + 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 , [ @@ -255,7 +255,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{|A2 a; B2 b; C2...;|}[]|csv:Error rt4a = csv:parseRecordAsRecordType( + 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 , [ @@ -264,7 +264,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|csv:Error rt5a = csv:parseRecordAsRecordType( + 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 , [ @@ -274,7 +274,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ]); [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error rt6a = - csv:parseRecordAsListType( + csv:transform( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true} @@ -286,7 +286,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|csv:Error rt7a = csv:parseRecordAsListType( + [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}] , ["a", "b", "c"]); @@ -296,7 +296,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2][]|csv:Error rt8a = csv:parseRecordAsListType( + [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}] , ["a", "b", "c"]); @@ -306,7 +306,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2...][]|csv:Error rt9a = csv:parseRecordAsListType( + [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"}] , ["a", "b", "c", "d"]); @@ -316,7 +316,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true, "string3"] ]); - [C2...][]|csv:Error rt10a = csv:parseRecordAsListType( + [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"}] , ["a", "b", "c", "d"]); @@ -327,7 +327,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { readonly & int a; readonly & string b; (readonly & boolean) | (readonly & decimal) c; - }[]|csv:Error rt11a = csv:parseListAsRecordType( + }[]|csv:Error rt11a = csv:parseLists( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); test:assertEquals(rt11a , [ @@ -336,7 +336,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A a; B b; C c;}[]|csv:Error rt12a = csv:parseListAsRecordType( + record{A a; B b; C c;}[]|csv:Error rt12a = csv:parseLists( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); test:assertEquals(rt12a , [ @@ -345,14 +345,14 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A a; B b; C c;}[]|csv:Error rt12a_2 = csv:parseListAsRecordType( + record{A a; B b; C c;}[]|csv:Error rt12a_2 = csv:parseLists( [["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( + record{string|decimal a; B b; C c;}[]|csv:Error rt12a_3 = csv:parseLists( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); test:assertEquals(rt12a_3 , [ @@ -361,7 +361,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A2 a; B2 b; C2 c;}[]|csv:Error rt13a = csv:parseListAsRecordType( + record{A2 a; B2 b; C2 c;}[]|csv:Error rt13a = csv:parseLists( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); test:assertEquals(rt13a , [ @@ -370,7 +370,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{|A2 a; B2 b; C2...;|}[]|csv:Error rt14a = csv:parseListAsRecordType( + record{|A2 a; B2 b; C2...;|}[]|csv:Error rt14a = csv:parseLists( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] , ["a", "b", "c", "d"]); @@ -380,7 +380,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|csv:Error rt15a = csv:parseListAsRecordType( + record{|C2...;|}[]|csv:Error rt15a = csv:parseLists( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] , ["a", "b", "c", "d"]); @@ -390,7 +390,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: "3", b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|csv:Error rt15a_2 = csv:parseListAsRecordType( + record{|C2...;|}[]|csv:Error rt15a_2 = csv:parseLists( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] , ["a", "b", "c", "d"], {stringConversion: false}); @@ -401,7 +401,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ]); [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error rt16a = - csv:parseListAsListType( + csv:parseLists( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); @@ -412,7 +412,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|csv:Error rt17a = csv:parseListAsListType( + [A, B, C][]|csv:Error rt17a = csv:parseLists( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); test:assertEquals(rt17a , [ @@ -421,13 +421,13 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|csv:Error rt17a_2 = csv:parseListAsListType( + [A, B, C][]|csv:Error rt17a_2 = csv:parseLists( [["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( + [A2, B2, C2][]|csv:Error rt18a = csv:parseLists( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); test:assertEquals(rt18a , [ @@ -436,7 +436,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2...][]|csv:Error rt19a = csv:parseListAsListType( + [A2, B2, C2...][]|csv:Error rt19a = csv:parseLists( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); test:assertEquals(rt19a , [ @@ -445,7 +445,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true, "string3"] ]); - [C2...][]|csv:Error rt20a = csv:parseListAsListType( + [C2...][]|csv:Error rt20a = csv:parseLists( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); test:assertEquals(rt20a, [["1", "string",true, "string"], 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_with_intersection_types.bal b/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal index be41c23..d7008a3 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}], ["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"}], ["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}], ["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"}], ["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"}], ["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:parseLists([["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:parseLists([["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:parseLists([["1", "2"], ["4", "5"]], ["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:parseLists([["a", "a"], ["c", "c"]], ["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:parseLists([["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:parseLists([["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:parseLists([["1", "2"], ["4", "5"]], ["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:parseLists([["a", "a"], ["c", "c"]], ["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:parseLists([["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:parseLists([["a", "a"], ["1", "2"]], ["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:parseLists([["a", "a"], ["1", "2"]], ["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..b97c004 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,77 @@ 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, + SubtypeTuple[]|csv:Error a10 = csv:transform(value1, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a10, value3); - SubtypeTuple2[]|csv:Error a11 = csv:parseRecordAsListType(value1, + SubtypeTuple2[]|csv:Error a11 = csv:transform(value1, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a11, [[1, 1], [1, 1]]); - SubtypeTuple3[]|csv:Error a12 = csv:parseRecordAsListType(value1, + SubtypeTuple3[]|csv:Error a12 = csv:transform(value1, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a12, value3); - SubtypeRecord[]|csv:Error a13 = csv:parseListAsRecordType(value2, + SubtypeRecord[]|csv:Error a13 = csv:parseLists(value2, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a13, value1); - SubtypeRecord2[]|csv:Error a14 = csv:parseListAsRecordType(value2, + SubtypeRecord2[]|csv:Error a14 = csv:parseLists(value2, ["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, + SubtypeRecord3[]|csv:Error a15 = csv:parseLists(value2, ["a", "c", "d", "e", "f", "g", "h", "i"], {}); test:assertEquals(a15, value1); - SubtypeTuple[]|csv:Error a16 = csv:parseListAsListType(value2, {}); + SubtypeTuple[]|csv:Error a16 = csv:parseLists(value2, {}); test:assertEquals(a16, value3); - SubtypeTuple2[]|csv:Error a17 = csv:parseListAsListType(value2, {}); + SubtypeTuple2[]|csv:Error a17 = csv:parseLists(value2, {}); test:assertEquals(a17, [[1, 1], [1, 1]]); - SubtypeTuple3[]|csv:Error a18 = csv:parseListAsListType(value2, {}); + SubtypeTuple3[]|csv:Error a18 = csv:parseLists(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..efcdc50 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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -320,7 +320,7 @@ 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}); + (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9_2 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); test:assertEquals(csv1op9_2, [ {}, {}, @@ -329,14 +329,14 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {} ]); - (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:parseLists(value, ["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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -345,11 +345,11 @@ 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}); + (record{|int a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op12 = csv:parseLists(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:parseLists([["1", "2"], ["a", "b"]], ["a", "b"], {}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, {a: "a", b: "b"} @@ -367,7 +367,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, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -376,7 +376,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, ["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 +384,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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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"}], ["a", "b"], {}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] @@ -460,7 +460,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:parseLists(value, {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -469,7 +469,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:parseLists(value, {skipLines: [2, 4]}); test:assertTrue(csv1op2 is (TupA|TupC)[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -477,56 +477,56 @@ 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:parseLists(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:parseLists(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:parseLists(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:parseLists(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:parseLists(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:parseLists(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ ["1"], ["3"], ["5"] ]); - ([boolean...]|[int...])[]|csv:Error csv1op8 = csv:parseListAsListType(value, {stringConversion: false}); + ([boolean...]|[int...])[]|csv:Error csv1op8 = csv:parseLists(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:parseLists(value, {}); test:assertEquals(csv1op8_2, value); - ([int...]|[string...])[]|csv:Error csv1op9 = csv:parseListAsListType(value, {}); + ([int...]|[string...])[]|csv:Error csv1op9 = csv:parseLists(value, {}); test:assertEquals(csv1op9, value); - ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:parseListAsListType(value, {}); + ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:parseLists(value, {}); test:assertEquals(csv1op10, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -535,7 +535,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:parseLists(value, {}); test:assertEquals(csv1op11, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -544,10 +544,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:parseLists(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:parseLists([["1", "2"], ["a", "b"]], {}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] @@ -556,7 +556,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 +565,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 +573,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 +617,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 +626,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 +635,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 +644,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 +664,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 +673,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 +681,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 +725,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 +734,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 +743,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 +752,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 +767,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:parseLists(value, ["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 +776,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:parseLists(value, ["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 +784,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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -835,7 +835,7 @@ 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}); + record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9_2 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); test:assertEquals(csv1op9_2, [ {}, {}, @@ -844,14 +844,14 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {} ]); - 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:parseLists(value, ["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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -860,11 +860,11 @@ 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}); + record{|int a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op12 = csv:parseLists(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:parseLists([["1", "2"], ["a", "b"]], ["a", "b"], {}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, {a: "a", b: "b"} @@ -882,7 +882,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, ["a", "b", "c", "d", "e", "f"], {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -891,7 +891,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, ["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 +899,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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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 +969,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:parseLists(value, {}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -978,7 +978,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:parseLists(value, {skipLines: [2, 4]}); test:assertTrue(csv1op2 is TupA[]|TupC[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -986,56 +986,56 @@ 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:parseLists(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:parseLists(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:parseLists(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:parseLists(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:parseLists(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:parseLists(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ ["1"], ["3"], ["5"] ]); - [boolean...][]|[int...][]|csv:Error csv1op8 = csv:parseListAsListType(value, {stringConversion: false}); + [boolean...][]|[int...][]|csv:Error csv1op8 = csv:parseLists(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:parseLists(value, {}); test:assertEquals(csv1op8_2, value); - [int...][]|[string...][]|csv:Error csv1op9 = csv:parseListAsListType(value, {}); + [int...][]|[string...][]|csv:Error csv1op9 = csv:parseLists(value, {}); test:assertEquals(csv1op9, value); - [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:parseListAsListType(value, {}); + [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:parseLists(value, {}); test:assertEquals(csv1op10, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -1044,7 +1044,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:parseLists(value, {}); test:assertEquals(csv1op11, [ [1, "string1", "true", "2.234", "2.234", "()"], [2, "string2", "false", "0", "0", "()"], @@ -1053,6 +1053,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:parseLists(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..c5aa914 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:parseLists([["1", "3"]], ["b", "c"], {}); test:assertEquals(cntr1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|csv:Error cntr2 = csv:parseListAsRecordType([["3", "1"]], ["c", "b"], {}); + RecordWithCustomAnnotation[]|csv:Error cntr2 = csv:parseLists([["3", "1"]], ["c", "b"], {}); test:assertEquals(cntr2, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|csv:Error cntr3 = csv:parseListAsRecordType( + RecordWithCustomAnnotation[]|csv:Error cntr3 = csv:parseLists( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["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:parseLists([["1", "3"]], ["d", "c"], {}); test:assertEquals(cntr4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|csv:Error cntr5 = csv:parseListAsRecordType([["3","1"]], ["c", "d"], {}); + RecordWithCustomAnnotation2[]|csv:Error cntr5 = csv:parseLists([["3","1"]], ["c", "d"], {}); test:assertEquals(cntr5, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|csv:Error cntr6 = csv:parseListAsRecordType( + RecordWithCustomAnnotation2[]|csv:Error cntr6 = csv:parseLists( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["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:parseLists([["3", "1"]], ["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:parseLists([["3", "1", "4", "5"]], ["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:parseLists([["1", "3"]], ["d", "c"], {}); test:assertEquals(cntr9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cntr10 = csv:parseListAsRecordType([["3", "1"]], ["c", "d"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr10 = csv:parseLists([["3", "1"]], ["c", "d"], {}); test:assertEquals(cntr10, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cntr11 = csv:parseListAsRecordType( + RecordWithCustomAnnotation3[]|csv:Error cntr11 = csv:parseLists( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["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:parseLists([["3", "1"]], ["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:parseLists([["3", "1", "4", "5"]], ["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:parseLists([["1", "3", "true"]], ["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:parseLists([["3", "1"]], ["c", "d"], {}); test:assertEquals(cntr15, [{b: 1, a: 3}]); - RecordWithCustomAnnotation4[]|csv:Error cntr16 = csv:parseListAsRecordType( + RecordWithCustomAnnotation4[]|csv:Error cntr16 = csv:parseLists( [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["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:parseLists([["3", "1"]], ["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:parseLists([["3", "1", "4", "5"]], ["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:parseLists([["3", "1", "4", "5"]], ["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( + RecordWithCustomAnnotation5[]|csv:Error cntr20 = csv:parseLists( [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "e"], {}); test:assertEquals(cntr20, [{a: 3, b: 1, c: 4}, {a: 3, b: 1, c: 4}]); - RecordWithCustomAnnotation6[]|csv:Error cntr21 = csv:parseListAsRecordType( + RecordWithCustomAnnotation6[]|csv:Error cntr21 = csv:parseLists( [["3", "1", "4"], ["3", "1", "4"]], ["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:parseLists([["a"], ["a"], ["a"]], ["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:parseLists([["a"], ["a"], ["a"]], ["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:parseLists([["a"], ["a"], ["b"]], ["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:parseLists([["a"], ["a"], ["a"]], ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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, ["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..b3525ed 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 @@ -28,7 +28,7 @@ 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"}); } @@ -36,7 +36,7 @@ function testCSVEncoding() returns error? { function testCSVLocale() { 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 @@ -47,7 +47,7 @@ function testCSVLocale() { {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 @@ -58,7 +58,7 @@ function testCSVLocale() { {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 @@ -72,60 +72,60 @@ function testCSVLocale() { @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, "()"] ]); - 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: "()"} ]); - 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: "()"} ]); - [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: "()"} ]); - [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, "()"] ]); - 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: "()"} ]); - 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: "()"} ]); - 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} ]); @@ -133,11 +133,11 @@ function testFromCsvStringWithParserOptions() { @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: ()}, @@ -145,7 +145,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'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: ()}, @@ -153,35 +153,35 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'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: ()} ]); - 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: ()} ]); - 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: ()} ]); - 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: ()} ]); - 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"}, @@ -194,7 +194,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { @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: ()}, @@ -203,17 +203,17 @@ function testHeaderOption() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - record {}[]|csv:Error csv2cop2 = csv:parseStringToRecord(csvStringData2, {header: 100}); + 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"); - 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,60 +378,60 @@ 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, ()], @@ -440,7 +440,7 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [0], header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: [0], header: 1}); test:assertEquals(csv1cp, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -449,7 +449,7 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [0, 4, 10], header: 1}); + 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, ()], @@ -457,46 +457,46 @@ function testSkipLineParserOption() { [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, ()] ]); - 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, ()] ]); - 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, ()] ]); - 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, ()] ]); - 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, ()], @@ -505,7 +505,7 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [-2], header: 1}); + csv1cp = csv:parseString(csvStringData1, {skipLines: [-2], header: 1}); test:assertEquals(csv1cp, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -514,7 +514,7 @@ function testSkipLineParserOption() { [5, "string5", true, 3, 3.0, ()] ]); - csv1cp = csv:parseStringToList(csvStringData1, {skipLines: [-2, 0, 2], header: 1}); + 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, ()], @@ -522,7 +522,7 @@ function testSkipLineParserOption() { [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, ()], @@ -532,64 +532,64 @@ function testSkipLineParserOption() { @test:Config {dependsOn: [testCSVLocale]} function testCustomHeaderOption() { - anydata[][]|csv:Error bm1ba = csv:parseRecordAsListType([bm1, bm1], ["b1", "b2"], {}); + anydata[][]|csv:Error bm1ba = csv:transform([bm1, bm1], ["b1", "b2"], {}); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - anydata[][]|csv:Error bm1ba2 = csv:parseRecordAsListType([bm1, bm1], ["b2", "b1"], {}); + anydata[][]|csv:Error bm1ba2 = csv:transform([bm1, bm1], ["b2", "b1"], {}); test:assertEquals(bm1ba2, [ [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], ["b1", "n1", "b2", "n2", "b3"], {}); test:assertTrue(bm2ba is csv:Error); test:assertEquals((bm2ba).message(), common:generateErrorMessageForInvalidCustomHeader("n2")); - anydata[][]|csv:Error bm3ba = csv:parseRecordAsListType([bm3, bm3], ["b1", "b4", "b2", "n2", "i1"], {}); + anydata[][]|csv:Error bm3ba = csv:transform([bm3, bm3], ["b1", "b4", "b2", "n2", "i1"], {}); test:assertTrue(bm3ba is csv:Error); test:assertEquals((bm3ba).message(), common:generateErrorMessageForInvalidCustomHeader("n2")); - anydata[][]|csv:Error bm3ba2 = csv:parseRecordAsListType([bm3, bm3], ["b1", "b3", "b4", "b2", "i2"], {}); + anydata[][]|csv:Error bm3ba2 = csv:transform([bm3, bm3], ["b1", "b3", "b4", "b2", "i2"], {}); test:assertTrue(bm3ba2 is csv:Error); test:assertEquals((bm3ba2).message(), common:generateErrorMessageForInvalidCustomHeader("i2")); - [boolean...][]|csv:Error bm3ba4 = csv:parseRecordAsListType([bm3, bm3], ["n2"], {}); + [boolean...][]|csv:Error bm3ba4 = csv:transform([bm3, bm3], ["n2"], {}); test:assertTrue(bm3ba4 is csv:Error); test:assertEquals((bm3ba4).message(), "Invalid length for the header names"); - [boolean...][]|csv:Error bm3ba5 = csv:parseRecordAsListType([bm3, bm3], [], {}); + [boolean...][]|csv:Error bm3ba5 = csv:transform([bm3, bm3], [], {}); test:assertTrue(bm3ba5 is csv:Error); test:assertEquals((bm3ba5).message(), "Invalid length for the header names"); - record {}[]|csv:Error ct1br = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); + record {}[]|csv:Error ct1br = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); test:assertTrue(ct1br is csv:Error); test:assertEquals((ct1br).message(), "Invalid length for the custom headers"); - record {}[]|csv:Error ct1br2 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); + record {}[]|csv:Error ct1br2 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); test:assertTrue(ct1br2 is csv:Error); test:assertEquals((ct1br2).message(), "Invalid length for the custom headers"); - record {}[]|csv:Error ct1br2_2 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); + record {}[]|csv:Error ct1br2_2 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); test:assertTrue(ct1br2_2 is csv:Error); test:assertEquals((ct1br2_2).message(), "Invalid length for the custom headers"); - record {}[]|csv:Error ct1br3 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], [], {}); + record {}[]|csv:Error ct1br3 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], [], {}); test:assertTrue(ct1br3 is csv:Error); test:assertEquals((ct1br3).message(), "Invalid length for the custom 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:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["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:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["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"], { + record {string a; string b;}[]|csv:Error ct1br7 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { stringConversion: false }); test:assertEquals(ct1br7, [ @@ -597,7 +597,7 @@ function testCustomHeaderOption() { {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"], { + record {|string a; string b;|}[]|csv:Error ct1br8 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { stringConversion: false }); test:assertEquals(ct1br8, [ @@ -605,7 +605,7 @@ function testCustomHeaderOption() { {a: "a", b: "true"} ]); - record {|string...;|}[]|csv:Error ct1br9 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + record {|string...;|}[]|csv:Error ct1br9 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { stringConversion: false }); test:assertEquals(ct1br9, [ @@ -613,7 +613,7 @@ function testCustomHeaderOption() { {a: "a", b: "true", e: "1"} ]); - record {|string...;|}[]|csv:Error ct1br10 = csv:parseListAsRecordType([["a", "1", "true"], ["a", "1", "true"]], (), { + record {|string...;|}[]|csv:Error ct1br10 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], (), { stringConversion: false }); test:assertEquals(ct1br10, [ @@ -624,19 +624,19 @@ function testCustomHeaderOption() { @test:Config function testCustomHeaderParserOption2() { - record {}[]|csv:Error ct1br = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); + record {}[]|csv:Error ct1br = csv:parseString(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 ct1br2 = csv:parseString(csvStringData1, {header: 1, customHeaders: []}); test:assertTrue(ct1br2 is csv:Error); test:assertEquals((ct1br2).message(), "Invalid length for the custom 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(csvStringData1, {header: 1, customHeaders: ["a", "b"]}); test:assertTrue(ct1br3 is csv:Error); test:assertEquals((ct1br3).message(), "Invalid length for the custom 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, customHeaders: ["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: ()}, @@ -645,7 +645,7 @@ function testCustomHeaderParserOption2() { {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"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5 = csv:parseString(csvStringData1, {header: 1, customHeaders: ["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: ()}, @@ -654,7 +654,7 @@ function testCustomHeaderParserOption2() { {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"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_2 = csv:parseString(csvStringData1, {header: false, skipLines: [1], customHeaders: ["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: ()}, @@ -663,7 +663,7 @@ function testCustomHeaderParserOption2() { {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"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_3 = csv:parseString(csvStringData1, {skipLines: [1], customHeaders: ["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: ()}, @@ -672,7 +672,7 @@ function testCustomHeaderParserOption2() { {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"]}); + record {|() a1; float b1; decimal c1; boolean d1; string e1; int f1;|}[]|csv:Error ct1br6 = csv:parseString(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: ()}, @@ -681,7 +681,7 @@ function testCustomHeaderParserOption2() { {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"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br7 = csv:parseString(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -690,7 +690,7 @@ function testCustomHeaderParserOption2() { {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"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br7_2 = csv:parseString(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7_2, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -699,11 +699,11 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br8 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br8 = csv:parseString(csvStringData1, {header: 1, customHeaders: ["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(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br9, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -712,7 +712,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br10 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "f1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br10 = csv:parseString(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "f1", "b1", "a1"]}); test:assertEquals(ct1br10, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -721,11 +721,11 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseString(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); test:assertTrue(ct1br11 is csv:Error); test:assertEquals((ct1br11).message(), "Invalid length for the custom 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(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ {e1: "string1", d1: "true"}, {e1: "string2", d1: "false"}, @@ -734,7 +734,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: "true"} ]); - record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseStringToRecord(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); + record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseString(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); test:assertTrue(ct1br13 is csv:Error); test:assertEquals((ct1br13).message(), common:generateErrorMessageForMissingRequiredField("d1")); } @@ -779,25 +779,25 @@ 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 custom headers"); } @@ -824,16 +824,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,28 +863,28 @@ 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: ()}, @@ -893,7 +893,7 @@ function testDelimiterWithParserOptions() { {a: 5, b: "string", c: true, d: 2.234, e: -3.21, f: ()} ]); - anydata[][]|csv:Error cn2 = csv:parseStringToList(csvStringData7, {header: 1, delimiter: "@"}); + 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, ()], @@ -908,24 +908,24 @@ 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"]]); } diff --git a/ballerina-tests/user-config-tests/tests/user_configs.bal b/ballerina-tests/user-config-tests/tests/user_configs.bal index f968a9e..988e203 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:TransformOptions ptOption1 = {nilValue: "", header: 1, skipLines: [2, 4]}; +csv:TransformOptions ptOption2 = {nilValue: "", header: 1, skipLines: "2-4"}; +csv:TransformOptions ptOption3 = {nilValue: "", header: 4, skipLines: "1-5"}; +csv:TransformOptions ptOption4 = {nilValue: "", header: 4, skipLines: [-1, -2, 4, 2]}; +csv:TransformOptions 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..1af609a 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -12,7 +12,7 @@ The Ballerina CSV Data Library is a comprehensive toolkit designed to facilitate ### 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 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`, `parseStream`, `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); } ``` @@ -82,7 +82,7 @@ type Book record { public function main() returns error? { string[][] bookArray = [["Clean Code","2008"],["Clean Architecture","2017"]]; - Book[] author = check csv:parseListAsRecordType(bookArray, customHeaders = ["name", "year"]); + Book[] author = check csv:parseLists(bookArray, customHeaders = ["name", "year"]); io:println(author); } ``` @@ -115,7 +115,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/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..90ed76f 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 @@ -37,7 +37,7 @@ public class CompilerPluginTest { static final String UNSUPPORTED_TYPE = "unsupported type: type is not supported"; static final String DUPLICATE_FIELD = "invalid field: duplicate field found"; - @Test + @Test(enabled = false) public void testInvalidExpectedUnionType() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_1").getCompilation().diagnosticResult(); @@ -57,7 +57,7 @@ public void testInvalidExpectedUnionType() { Assert.assertEquals(errorDiagnosticsList.get(9).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); } - @Test + @Test(enabled = false) public void testInvalidRecordFields() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_2").getCompilation().diagnosticResult(); @@ -68,7 +68,7 @@ public void testInvalidRecordFields() { Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), DUPLICATE_FIELD); } - @Test + @Test(enabled = false) public void testInvalidProgram() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_3").getCompilation().diagnosticResult(); @@ -78,7 +78,7 @@ public void testInvalidProgram() { Assert.assertEquals(errorDiagnosticsList.size(), 1); } - @Test + @Test(enabled = false) public void testModuleLevelInvalidExpectedUnionType() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_4").getCompilation().diagnosticResult(); @@ -98,7 +98,7 @@ public void testModuleLevelInvalidExpectedUnionType() { Assert.assertEquals(errorDiagnosticsList.get(9).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); } - @Test + @Test(enabled = false) public void testEmptyProject() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_5").getCompilation().diagnosticResult(); @@ -108,7 +108,7 @@ public void testEmptyProject() { Assert.assertEquals(errorDiagnosticsList.size(), 0); } - @Test + @Test(enabled = false) public void testInvalidExpectedUnionType2() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_6").getCompilation().diagnosticResult(); 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..c7be3c5 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 @@ -5,16 +5,16 @@ 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]] 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:parseLists([], {}); + [record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); + [record{}, record{}, record{}, record{}] val10 = check csv:parseLists([], [], {}); + record{}[2] val11 = check csv:parseLists([], [], {}); + int[3][2] val12 = check csv:parseLists([], {}); } 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..e544c52 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:parseLists([], {}); +[record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); +[record{}, record{}, record{}, record{}] val10 = check csv:parseLists([], [], {}); +record{}[2] val11 = check csv:parseLists([], [], {}); +int[3][2] val12 = check csv:parseLists([], {}); 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..feb1a8c 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:parseLists([], {}); + [record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); + [record{}, record{}, record{}, record{}] val10 = check csv:parseLists([], [], {}); + record{}[2] val11 = check csv:parseLists([], [], {}); + int[3][2] val12 = check csv:parseLists([], {}); } 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..36ce88e 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,16 @@ * @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_TO_RECORD = "parseString"; + static final String PARSE_BYTES_TO_RECORD = "parseBytes"; + static final String PARSE_STREAM_TO_RECORD = "parseStream"; + static final String PARSE_STRING_TO_LIST = "parseString"; + static final String PARSE_BYTES_TO_LIST = "parseBytes"; + static final String PARSE_STREAM_TO_LIST = "parseStream"; + static final String PARSE_RECORD_AS_RECORD_TYPE = "transform"; + static final String PARSE_RECORD_AS_LIST_TYPE = "transform"; + static final String PARSE_LIST_AS_RECORD_TYPE = "parseLists"; + static final String PARSE_LIST_AS_LIST_TYPE = "parseLists"; static final String NAME = "Name"; static final String CSVDATA = "csv"; static final String BALLERINA = "ballerina"; 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 d088622..9b37f5b 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 @@ -66,6 +66,15 @@ static Object initRowValue(Type expectedType) { }; } + static boolean isExpectedTypeIsArray(Type expectedType) { + expectedType = TypeUtils.getReferredType(expectedType); + + return switch (expectedType.getTag()) { + case TypeTags.TUPLE_TAG, TypeTags.ARRAY_TAG -> true; + default -> false; + }; + } + static void convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, String value, Type type, CsvConfig config, Type exptype, Field currentField) { 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 8114a49..1329238 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 @@ -659,13 +659,20 @@ private static void initiateNewRowType(StateMachine sm) { } private static void addHeadersAsTheFirstElementForArraysIfApplicable(StateMachine sm) { - if (!sm.addHeadersForOutput && sm.config.outputWithHeaders) { - for (int i = 0; i < sm.headers.size(); i++) { - addHeaderAsRowValue(sm, sm.headers.get(i)); + if (!sm.addHeadersForOutput && CsvCreator + .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); + } } - finalizeTheRow(sm); - initiateNewRowType(sm); sm.addHeadersForOutput = true; + sm.columnIndex = 0; } } 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 07a5916..69ac797 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 @@ -53,6 +53,8 @@ import java.util.Map; import java.util.Optional; +import static io.ballerina.lib.data.csvdata.csv.CsvCreator.isExpectedTypeIsArray; + /** * Convert Csv value to a ballerina record. * @@ -265,6 +267,7 @@ public void traverseCsvArrayMembersWithMapAsCsvElementType(long length, BArray c public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray csv, Type expectedArrayType, boolean isIntersection) { Object rowValue; + expectedArrayType = TypeUtils.getReferredType(expectedArrayType); ArrayType arrayType = (ArrayType) rootCsvNode.getType(); for (int i = 0; i < length; i++) { if (ignoreRow(i + 1, config.skipLines)) { @@ -275,7 +278,17 @@ public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray break; } - rowValue = traverseCsvElementWithArray(csv.get(i), expectedArrayType); + Object o = csv.get(i); + if (!addHeadersForOutput && config.outputWithHeaders + && (config.customHeaders != null || i == config.headerRows - 1)) { + // Headers will add to the list only in the first iteration + addHeadersForTheListIfApplicable(o, expectedArrayType); + } + if (i < config.headerRows) { + continue; + } + + rowValue = traverseCsvElementWithArray(o, expectedArrayType); if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } @@ -316,6 +329,9 @@ public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray rowValue = traverseCsvElementWithMapOrRecord(csvData, memberType); } else if (memberType.getTag() == TypeTags.TUPLE_TAG || memberType.getTag() == TypeTags.ARRAY_TAG) { + if (i < config.headerRows) { + continue; + } rowValue = traverseCsvElementWithArray(csvData, memberType); } else { continue; @@ -401,18 +417,35 @@ private void traverseArrayValue(Object csvElement, Type type) { } } - private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { - int index = 0; - if (this.headers == null) { - this.headers = CsvUtils.createHeadersForParseLists(csvElement, headers, config); - } - if (!addHeadersForOutput && config.outputWithHeaders) { + private void addHeadersForTheListIfApplicable(Object obj, Type type) { + if (config.outputWithHeaders + && obj instanceof BArray array && isExpectedTypeIsArray(type)) { + if (this.headers == null) { + String[] headers = new String[array.size()]; + this.headers = CsvUtils.createHeadersForParseLists(array, headers, config); + } + + 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 = getArrayOrTupleMemberType(type, i); - addValuesToArrayType(StringUtils.getStringValue(headers[i]), memberType, i, currentCsvNode); + if (memberType != null) { + addValuesToArrayType(StringUtils.fromString(headers[i]), memberType, i, headersArray); + } } + rootCsvNode.add(this.arraySize, headersArray); + this.arraySize++; addHeadersForOutput = true; } + } + + private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { + int index = 0; for (int i = 0; i < csvElement.getLength(); i++) { if (config.allowDataProjection && index >= expectedSize) { break; @@ -447,7 +480,9 @@ private void constructArrayValuesFromMap(BMap map, Type type, i if (!addHeadersForOutput && config.outputWithHeaders) { for (int i = 0; i < keys.length; i++) { Type memberType = getArrayOrTupleMemberType(type, i); - addValuesToArrayType(StringUtils.getStringValue(keys[i]), memberType, i, currentCsvNode); + if (memberType != null) { + addValuesToArrayType(keys[i], memberType, i, currentCsvNode); + } } addHeadersForOutput = true; } @@ -475,8 +510,9 @@ private Type getArrayOrTupleMemberType(Type type, int index) { 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; @@ -582,7 +618,7 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType) { private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, boolean mappingType, Type expectedType) { int arraySize = csvElement.size(); - String[] headers = new String[arraySize]; + String[] headers = new String[csvElement.size()]; if (this.headers == null) { this.headers = CsvUtils.createHeadersForParseLists(csvElement, headers, 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 78d0ca5..e0adecb 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 @@ -72,11 +72,12 @@ public static String[] createHeadersForParseLists(BArray csvElement, String[] he Object customHeaders = config.customHeaders; long headerRows = config.headerRows; + int length = headers.length; if (customHeaders instanceof BArray array) { - if (array.size() != headers.length) { + 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; @@ -91,7 +92,7 @@ public static String[] createHeadersForParseLists(BArray csvElement, String[] he } // when headerRows = 0 and customHeaders = null - for (int i = 0; i < headers.length; i++) { + for (int i = 0; i < length; i++) { headers[i] = String.valueOf(i + 1); } return headers; diff --git a/native/src/main/resources/csv_error.properties b/native/src/main/resources/csv_error.properties index e6fef96..1808ef1 100644 --- a/native/src/main/resources/csv_error.properties +++ b/native/src/main/resources/csv_error.properties @@ -100,4 +100,4 @@ error.cannot.convert.into.exptype=\ The source value cannot convert in to the ''{0}'' error.no.custom.header.provided=\ - Custom header should be provided \ No newline at end of file + Custom headers should be provided \ No newline at end of file From 37ca852e1d2e5f3c49272c0b774471643c908615 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Wed, 7 Aug 2024 09:59:49 +0530 Subject: [PATCH 111/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 +------------------------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ed49c87..0bfd723 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,8 +12,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "test"} + {org = "ballerina", name = "jballerina.java"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -27,52 +26,3 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - From 43bdb322ca6654ac4823bb6c63eebeadb2062937 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Wed, 7 Aug 2024 10:15:44 +0530 Subject: [PATCH 112/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 0bfd723..ed49c87 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,7 +12,8 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"} + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "test"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -26,3 +27,52 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + From fb27c7d7882642436474f27b4b59714e1389c074 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Wed, 7 Aug 2024 14:08:19 +0530 Subject: [PATCH 113/147] Update the record and array basic operations with new design --- .../tests/parse_list_type_as_list_test.bal | 40 +- .../tests/parse_list_type_as_record_test.bal | 1718 +++++++++-------- .../tests/parse_record_type_as_list_test.bal | 262 ++- .../parse_record_type_as_record_test.bal | 28 +- .../lib/data/csvdata/csv/CsvTraversal.java | 257 +-- .../csvdata/utils/DiagnosticErrorCode.java | 2 +- .../src/main/resources/csv_error.properties | 2 +- 7 files changed, 1270 insertions(+), 1039 deletions(-) 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 9829251..8a1a61a 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 @@ -525,12 +525,12 @@ function testParseListsWithOutputHeaders() { ["a", "true", "1"] ]); - ct1bt1_4 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); - test:assertEquals(ct1bt1_4, [ + ct1bt1_4 = csv:parseLists([["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:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_4_2, [ @@ -556,18 +556,18 @@ function testParseListsWithOutputHeaders() { ["a", true, 1] ]); - ct1bt1_5 = csv:parseLists([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); - test:assertEquals(ct1bt1_5, [ + ct1bt1_5 = csv:parseLists([["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:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); - test:assertEquals(ct1bt1_5, [ + ct1bt1_5 = csv:parseLists([["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:parseLists([["1", "a"], ["1", "a"]]); test:assertEquals(ct1bt2, [ @@ -581,16 +581,30 @@ function testParseListsWithOutputHeaders() { ["a", true, 1] ]); - [string...][]|csv:Error ct1bt2_3 = csv:parseLists([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); - test:assertEquals(ct1bt2_3, [ + [string...][]|csv:Error ct1bt2_3 = csv:parseLists([["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:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); - test:assertEquals(ct1bt2_2, [ + ct1bt2_2 = csv:parseLists([["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:parseLists([["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:parseLists([["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:parseLists([["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 e8bb1b8..decf586 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 @@ -1,795 +1,923 @@ -// // Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). -// // -// // WSO2 LLC. licenses this file to you under the Apache License, -// // Version 2.0 (the "License"); you may not use this file except -// // in compliance with the License. -// // You may obtain a copy of the License at -// // -// // http://www.apache.org/licenses/LICENSE-2.0 -// // -// // Unless required by applicable law or agreed to in writing, -// // software distributed under the License is distributed on an -// // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// // KIND, either express or implied. See the License for the -// // specific language governing permissions and limitations -// // under the License. - -// import ballerina/csv_commons as common; -// import ballerina/data.csv; -// import ballerina/test; - -// @test:Config -// function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { -// StringRecord1Array|csv:Error st1sr1 = csv:parseLists([st1, st1], (), {}, StringRecord1Array); -// test:assertTrue(st1sr1 is csv:Error); -// test:assertEquals((st1sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - -// StringRecord1Array|csv:Error st2sr1 = csv:parseLists([st2, st2], (), {}, StringRecord1Array); -// test:assertTrue(st2sr1 is csv:Error); -// test:assertEquals((st2sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - -// StringRecord2Array|csv:Error st1sr2 = csv:parseLists([st1, st1], (), {}, StringRecord2Array); -// test:assertTrue(st1sr2 is csv:Error); -// test:assertEquals((st1sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "parse_list_types_tests:StringRecord2")); - -// StringRecord2Array|csv:Error st2sr2 = csv:parseLists([st2, st2], (), {}, StringRecord2Array); -// test:assertTrue(st2sr2 is csv:Error); -// test:assertEquals((st2sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","parse_list_types_tests:StringRecord2")); - -// StringRecord9Array|csv:Error st1sr9 = csv:parseLists([st1, st1], (), {}, StringRecord9Array); -// test:assertTrue(st1sr9 is csv:Error); -// test:assertEquals((st1sr9).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "parse_list_types_tests:StringRecord9")); - -// StringRecord9Array|csv:Error st2sr9 = csv:parseLists([st2, st2], (), {}, StringRecord9Array); -// test:assertTrue(st2sr9 is csv:Error); -// test:assertEquals((st2sr9).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","parse_list_types_tests:StringRecord9")); - -// StringRecord10Array|csv:Error st1sr10 = csv:parseLists([st1, st1], (), {}, StringRecord10Array); -// test:assertEquals(st1sr10, [ -// {'1: "string", '2: ""}, -// {'1: "string", '2: ""} -// ]); - -// StringRecord10Array|csv:Error st2sr10 = csv:parseLists([st2, st2], (), {}, StringRecord10Array); -// test:assertEquals(st2sr10, [ -// {'1: "string", '2: "", '3: "a", '4: ""}, -// {'1: "string", '2: "", '3: "a", '4: ""} -// ]); - -// StringRecord19Array|csv:Error st1sr19 = csv:parseLists([st1, st1], (), {}, StringRecord19Array); -// test:assertEquals(st1sr19, [ -// {s1: "", s2: "", "1": s1, "2": s2}, -// {s1: "", s2: "", "1": s1, "2": s2} -// ]); - -// StringRecord19Array|csv:Error st2sr19 = csv:parseLists([st2, st2], (), {}, StringRecord19Array); -// 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:parseLists([st1, st1], (), {}, StringRecord20Array); -// test:assertEquals(st1sr20, [ -// {s1: "", s2: ""}, -// {s1: "", s2: ""} -// ]); -// } - -// @test:Config -// function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { -// StringRecord20Array|csv:Error st2sr20 = csv:parseLists([st2, st2], (), {}, StringRecord20Array); -// test:assertEquals(st2sr20, [ -// {s1: "", s2: ""}, -// {s1: "", s2: ""} -// ]); - -// StringRecord21Array|csv:Error st1sr21 = csv:parseLists([st1, st1], (), {}, StringRecord21Array); -// test:assertEquals(st1sr21, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// StringRecord21Array|csv:Error st2sr21 = csv:parseLists([st2, st2], (), {}, StringRecord21Array); -// test:assertEquals(st2sr21, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// StringRecord22Array|csv:Error st1sr22 = csv:parseLists([st1, st1], (), {}, StringRecord22Array); -// test:assertEquals(st1sr22, [ -// {s1: "", s2: "", "1": s1, "2": s2}, -// {s1: "", s2: "", "1": s1, "2": s2} -// ]); - -// StringRecord22Array|csv:Error st2sr22 = csv:parseLists([st2, st2], (), {}, StringRecord22Array); -// 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:parseLists([st1, st1], (), {}, StringRecord23Array); -// test:assertEquals(st1sr23, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// StringRecord23Array|csv:Error st2sr23 = csv:parseLists([st2, st2], (), {}, StringRecord23Array); -// test:assertEquals(st2sr23, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord15Array|csv:Error st1cr15 = csv:parseLists([st1, st1], (), {}, CustomRecord15Array); -// test:assertEquals(st1cr15, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord15Array|csv:Error st2cr15 = csv:parseLists([st2, st2], (), {}, CustomRecord15Array); -// test:assertEquals(st2cr15, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord16Array|csv:Error st1cr16 = csv:parseLists([st1, st1], (), {}, CustomRecord16Array); -// test:assertTrue(st1cr16 is csv:Error); -// test:assertEquals((st1cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); - -// CustomRecord16Array|csv:Error st2cr16 = csv:parseLists([st2, st2], (), {}, CustomRecord16Array); -// test:assertEquals(st2cr16, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord17Array|csv:Error st1cr17 = csv:parseLists([st1, st1], (), {}, CustomRecord17Array); -// test:assertEquals(st1cr17, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); -// } - -// @test:Config -// function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { -// CustomRecord17Array|csv:Error st2cr17 = csv:parseLists([st2, st2], (), {}, CustomRecord17Array); -// test:assertEquals(st2cr17, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord18Array|csv:Error st1cr18 = csv:parseLists([st1, st1], (), {}, CustomRecord18Array); -// test:assertTrue(st1cr18 is csv:Error); -// test:assertEquals((st1cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); - -// CustomRecord18Array|csv:Error st2cr18 = csv:parseLists([st2, st2], (), {}, CustomRecord18Array); -// test:assertEquals(st2cr18, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord19Array|csv:Error st1cr19 = csv:parseLists([st1, st1], (), {}, CustomRecord19Array); -// test:assertEquals(st1cr19, [ -// {'1: s1, '2: s2, '3: "", '4: ""}, -// {'1: s1, '2: s2, '3: "", '4: ""} -// ]); - -// CustomRecord19Array|csv:Error st2cr19 = csv:parseLists([st2, st2], (), {}, CustomRecord19Array); -// test:assertEquals(st2cr19, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord20Array|csv:Error st1cr20 = csv:parseLists([st1, st1], (), {}, CustomRecord20Array); -// test:assertEquals(st1cr20, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord20Array|csv:Error st2cr20 = csv:parseLists([st2, st2], (), {}, CustomRecord20Array); -// test:assertEquals(st2cr20, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord21Array|csv:Error st1cr21 = csv:parseLists([st1, st1], (), {}, CustomRecord21Array); -// test:assertEquals(st1cr21, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord21Array|csv:Error st2cr21 = csv:parseLists([st2, st2], (), {}, CustomRecord21Array); -// test:assertEquals(st2cr21, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord22Array|csv:Error st1cr22 = csv:parseLists([st1, st1], (), {}, CustomRecord22Array); -// test:assertEquals(st1cr22, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); -// } - -// @test:Config -// function testFromCsvWithTypeForTupleAndRecordAsExpectedType4() { -// CustomRecord22Array|csv:Error st2cr22 = csv:parseLists([st2, st2], (), {}, CustomRecord22Array); -// test:assertEquals(st2cr22, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord23Array|csv:Error st1cr23 = csv:parseLists([st1, st1], (), {}, CustomRecord23Array); -// test:assertEquals(st1cr23, [ -// {"1": s1, "2": s2, a: ""}, -// {"1": s1, "2": s2, a: ""} -// ]); - -// CustomRecord23Array|csv:Error st2cr23 = csv:parseLists([st2, st2], (), {}, CustomRecord23Array); -// 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:parseLists([st1, st1], (), {}, CustomRecord24Array); -// test:assertEquals(st1cr24, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord24Array|csv:Error st2cr24 = csv:parseLists([st2, st2], (), {}, CustomRecord24Array); -// test:assertEquals(st2cr24, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord25Array|csv:Error st1cr25 = csv:parseLists([st1, st1], (), {}, CustomRecord25Array); -// test:assertTrue(st1cr25 is csv:Error); -// test:assertEquals((st1cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - -// CustomRecord25Array|csv:Error st2cr25 = csv:parseLists([st2, st2], (), {}, CustomRecord25Array); -// test:assertTrue(st2cr25 is csv:Error); -// test:assertEquals((st2cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - -// CustomRecord25Array|csv:Error st3cr25 = csv:parseLists([st3, st3], (), {}, CustomRecord25Array); -// test:assertTrue(st3cr25 is csv:Error); -// test:assertEquals((st3cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - -// CustomRecord25Array|csv:Error st4cr25 = csv:parseLists([st4, st4], (), {}, CustomRecord25Array); -// test:assertTrue(st4cr25 is csv:Error); -// test:assertEquals((st4cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); - -// CustomRecord26Array|csv:Error st1cr26 = csv:parseLists([st1, st1], (), {}, CustomRecord26Array); -// test:assertEquals(st1cr26 , [ -// {'1: s1}, -// {'1: s1} -// ]); - -// CustomRecord26Array|csv:Error st2cr26 = csv:parseLists([st2, st2], (), {}, CustomRecord26Array); -// test:assertEquals(st2cr26 , [ -// {'1: s1}, -// {'1: s1} -// ]); - -// CustomRecord26Array|csv:Error st3cr26 = csv:parseLists([st3, st3], (), {}, CustomRecord26Array); -// test:assertEquals(st3cr26 , [ -// {'1: s1}, -// {'1: s1} -// ]); - -// CustomRecord26Array|csv:Error st4cr26 = csv:parseLists([st4, st4], (), {}, CustomRecord26Array); -// test:assertEquals(st4cr26 , [ -// {'1: s1}, -// {'1: s1} -// ]); -// } - -// @test:Config -// function testFromCsvWithTypeForTupleAndRecordAsExpectedType5() { -// StringRecord1Array|csv:Error st3sr1 = csv:parseLists([st3, st3], (), {}, StringRecord1Array); -// test:assertTrue(st3sr1 is csv:Error); -// test:assertEquals((st3sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - -// StringRecord1Array|csv:Error st4sr1 = csv:parseLists([st4, st4], (), {}, StringRecord1Array); -// test:assertTrue(st4sr1 is csv:Error); -// test:assertEquals((st4sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); - -// StringRecord2Array|csv:Error st3sr2 = csv:parseLists([st3, st3], (), {}, StringRecord2Array); -// test:assertTrue(st3sr2 is csv:Error); -// test:assertEquals((st3sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\"]", "parse_list_types_tests:StringRecord2")); - -// StringRecord2Array|csv:Error st4sr2 = csv:parseLists([st4, st4], (), {}, StringRecord2Array); -// test:assertTrue(st4sr2 is csv:Error); -// test:assertEquals((st4sr2).message(), common:generateErrorMessageForInvalidHeaders("[\"string\",\"\",\"a\",\"\"]","parse_list_types_tests:StringRecord2")); - -// StringRecord9Array|csv:Error st3sr9 = csv:parseLists([st3, st3], (), {}, StringRecord9Array); -// test:assertTrue(st3sr9 is csv:Error); -// test:assertEquals((st3sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); - -// StringRecord9Array|csv:Error st4sr9 = csv:parseLists([st4, st4], (), {}, StringRecord9Array); -// test:assertTrue(st4sr9 is csv:Error); -// test:assertEquals((st4sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); - -// StringRecord10Array|csv:Error st3sr10 = csv:parseLists([st3, st3], (), {}, StringRecord10Array); -// test:assertEquals(st3sr10, [ -// {'1: "string", '2: ""}, -// {'1: "string", '2: ""} -// ]); - -// StringRecord10Array|csv:Error st4sr10 = csv:parseLists([st4, st4], (), {}, StringRecord10Array); -// test:assertEquals(st4sr10, [ -// {'1: "string", '2: "", '3: "a", '4: ""}, -// {'1: "string", '2: "", '3: "a", '4: ""} -// ]); - -// StringRecord19Array|csv:Error st3sr19 = csv:parseLists([st3, st3], (), {}, StringRecord19Array); -// test:assertEquals(st3sr19, [ -// {s1: "", s2: "", "1": s1, "2": s2}, -// {s1: "", s2: "", "1": s1, "2": s2} -// ]); - -// StringRecord19Array|csv:Error st4sr19 = csv:parseLists([st4, st4], (), {}, StringRecord19Array); -// 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:parseLists([st3, st3], (), {}, StringRecord20Array); -// test:assertEquals(st3sr20, [ -// {s1: "", s2: ""}, -// {s1: "", s2: ""} -// ]); - -// StringRecord20Array|csv:Error st4sr20 = csv:parseLists([st4, st4], (), {}, StringRecord20Array); -// test:assertEquals(st4sr20, [ -// {s1: "", s2: ""}, -// {s1: "", s2: ""} -// ]); - -// StringRecord21Array|csv:Error st3sr21 = csv:parseLists([st3, st3], (), {}, StringRecord21Array); -// test:assertEquals(st3sr21, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// StringRecord21Array|csv:Error st4sr21 = csv:parseLists([st4, st4], (), {}, StringRecord21Array); -// test:assertEquals(st4sr21, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// StringRecord22Array|csv:Error st3sr22 = csv:parseLists([st3, st3], (), {}, StringRecord22Array); -// test:assertEquals(st3sr22, [ -// {s1: "", s2: "", "1": s1, "2": s2}, -// {s1: "", s2: "", "1": s1, "2": s2} -// ]); - -// StringRecord22Array|csv:Error st4sr22 = csv:parseLists([st4, st4], (), {}, StringRecord22Array); -// 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:parseLists([st3, st3], (), {}, StringRecord23Array); -// test:assertEquals(st3sr23, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// StringRecord23Array|csv:Error st4sr23 = csv:parseLists([st4, st4], (), {}, StringRecord23Array); -// test:assertEquals(st4sr23, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord15Array|csv:Error st3cr15 = csv:parseLists([st3, st3], (), {}, CustomRecord15Array); -// test:assertEquals(st3cr15, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); -// } - -// @test:Config -// function testFromCsvWithTypeForTupleAndRecordAsExpectedType6() { -// CustomRecord15Array|csv:Error st4cr15 = csv:parseLists([st4, st4], (), {}, CustomRecord15Array); -// test:assertEquals(st4cr15, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord16Array|csv:Error st3cr16 = csv:parseLists([st3, st3], (), {}, CustomRecord16Array); -// test:assertTrue(st3cr16 is csv:Error); -// test:assertEquals((st3cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); - -// CustomRecord16Array|csv:Error st4cr16 = csv:parseLists([st4, st4], (), {}, CustomRecord16Array); -// test:assertEquals(st4cr16, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord17Array|csv:Error st3cr17 = csv:parseLists([st3, st3], (), {}, CustomRecord17Array); -// test:assertEquals(st3cr17, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord17Array|csv:Error st4cr17 = csv:parseLists([st4, st4], (), {}, CustomRecord17Array); -// test:assertEquals(st4cr17, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord18Array|csv:Error st3cr18 = csv:parseLists([st3, st3], (), {}, CustomRecord18Array); -// test:assertTrue(st3cr18 is csv:Error); -// test:assertEquals((st3cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); - -// CustomRecord18Array|csv:Error st4cr18 = csv:parseLists([st4, st4], (), {}, CustomRecord18Array); -// test:assertEquals(st4cr18, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord19Array|csv:Error st3cr19 = csv:parseLists([st3, st3], (), {}, CustomRecord19Array); -// test:assertEquals(st3cr19, [ -// {'1: s1, '2: s2, '3: "", '4: ""}, -// {'1: s1, '2: s2, '3: "", '4: ""} -// ]); - -// CustomRecord19Array|csv:Error st4cr19 = csv:parseLists([st4, st4], (), {}, CustomRecord19Array); -// test:assertEquals(st4cr19, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord20Array|csv:Error st3cr20 = csv:parseLists([st3, st3], (), {}, CustomRecord20Array); -// test:assertEquals(st3cr20, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord20Array|csv:Error st4cr20 = csv:parseLists([st4, st4], (), {}, CustomRecord20Array); -// test:assertEquals(st4cr20, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord21Array|csv:Error st3cr21 = csv:parseLists([st3, st3], (), {}, CustomRecord21Array); -// test:assertEquals(st3cr21, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord21Array|csv:Error st4cr21 = csv:parseLists([st4, st4], (), {}, CustomRecord21Array); -// test:assertEquals(st4cr21, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord22Array|csv:Error st3cr22 = csv:parseLists([st3, st3], (), {}, CustomRecord22Array); -// test:assertEquals(st3cr22, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord22Array|csv:Error st4cr22 = csv:parseLists([st4, st4], (), {}, CustomRecord22Array); -// test:assertEquals(st4cr22, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomRecord23Array|csv:Error st3cr23 = csv:parseLists([st3, st3], (), {}, CustomRecord23Array); -// test:assertEquals(st3cr23, [ -// {"1": s1, "2": s2, a: ""}, -// {"1": s1, "2": s2, a: ""} -// ]); - -// CustomRecord23Array|csv:Error st4cr23 = csv:parseLists([st4, st4], (), {}, CustomRecord23Array); -// 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:parseLists([st3, st3], (), {}, CustomRecord24Array); -// test:assertEquals(st3cr24, [ -// {"1": s1, "2": s2}, -// {"1": s1, "2": s2} -// ]); - -// CustomRecord24Array|csv:Error st4cr24 = csv:parseLists([st4, st4], (), {}, CustomRecord24Array); -// test:assertEquals(st4cr24, [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); -// } - -// @test:Config -// function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { -// record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["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:parseLists( -// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], -// ["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:parseLists( -// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], -// ["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:parseLists( -// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], -// ["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:parseLists( -// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], -// ["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:parseLists( -// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], -// ["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 testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { -// record{|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseLists( -// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], -// ["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:parseLists( -// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], -// ["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:parseLists( -// [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], -// ["f", "e", "d", "c", "b", "a"]); -// test:assertEquals(ct1br12, [ -// {a: ()}, -// {a: ()} -// ]); - -// record{|string?...;|}[]|csv:Error ct1br13 = csv:parseLists( -// [["a", "1"], ["a", "1"]], -// ["f", "e"]); -// test:assertEquals(ct1br13, [ -// {e: "1", f: "a"}, -// {e: "1", f: "a"} -// ]); - -// record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseLists( -// [["2.23", "null"], ["7", "()"]], -// ["b", "a"]); -// test:assertEquals(ct1br14, [ -// {}, -// {} -// ]); - -// map[]|csv:Error ct1br15 = csv:parseLists( -// [["2", "()"], ["2", "1"], ["()", "2"]], -// ["f", "e"]); -// test:assertEquals(ct1br15, [ -// {e: (), f: 2}, -// {e: 1, f: 2}, -// {e: 2, f: ()} -// ]); - -// record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseLists( -// [["2.23", "null"], ["7", "()"]], -// ["b", "a"]); -// test:assertEquals(ct1br16, [ -// {}, -// {} -// ]); -// } - -// @test:Config -// function testFromCsvWithTypeForTupleAndMapAsExpectedType() { -// StringMapArray|csv:Error st1sma = csv:parseLists([st1, st1], (), {}, StringMapArray); -// test:assertEquals(st1sma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// StringMapArray|csv:Error st2sma = csv:parseLists([st2, st2], (), {}, StringMapArray); -// test:assertEquals(st2sma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// StringMapArray|csv:Error st3sma = csv:parseLists([st3, st3], (), {}, StringMapArray); -// test:assertEquals(st3sma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// StringMapArray|csv:Error st4sma = csv:parseLists([st4, st4], (), {}, StringMapArray); -// test:assertEquals(st4sma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// NillableIntUnionStringMapArray|csv:Error st1niusma = csv:parseLists([st1, st1], (), {}, NillableIntUnionStringMapArray); -// test:assertEquals(st1niusma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// NillableIntUnionStringMapArray|csv:Error st2niusma = csv:parseLists([st2, st2], (), {}, NillableIntUnionStringMapArray); -// test:assertEquals(st2niusma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// NillableIntUnionStringMapArray|csv:Error st3niusma = csv:parseLists([st3, st3], (), {}, NillableIntUnionStringMapArray); -// test:assertEquals(st3niusma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// NillableIntUnionStringMapArray|csv:Error st4niusma = csv:parseLists([st4, st4], (), {}, NillableIntUnionStringMapArray); -// test:assertEquals(st4niusma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// IntUnionStringMapArray|csv:Error st1iusma = csv:parseLists([st1, st1], (), {}, IntUnionStringMapArray); -// test:assertEquals(st1iusma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// IntUnionStringMapArray|csv:Error st2iusma = csv:parseLists([st2, st2], (), {}, IntUnionStringMapArray); -// test:assertEquals(st2iusma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// IntUnionStringMapArray|csv:Error st3iusma = csv:parseLists([st3, st3], (), {}, IntUnionStringMapArray); -// test:assertEquals(st3iusma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// IntUnionStringMapArray|csv:Error st4iusma = csv:parseLists([st4, st4], (), {}, IntUnionStringMapArray); -// test:assertEquals(st4iusma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// JsonMapArray|csv:Error st1jma = csv:parseLists([st1, st1], (), {}, JsonMapArray); -// test:assertEquals(st1jma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); -// } - -// @test:Config -// function testFromCsvWithTypeForTupleAndMapAsExpectedType2() { -// JsonMapArray|csv:Error st2jma = csv:parseLists([st2, st2], (), {}, JsonMapArray); -// test:assertEquals(st2jma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// JsonMapArray|csv:Error st3jma = csv:parseLists([st3, st3], (), {}, JsonMapArray); -// test:assertEquals(st3jma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// JsonMapArray|csv:Error st4jma = csv:parseLists([st4, st4], (), {}, JsonMapArray); -// test:assertEquals(st4jma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// AnydataMapArray|csv:Error st1anydma = csv:parseLists([st1, st1], (), {}, AnydataMapArray); -// test:assertEquals(st1anydma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// AnydataMapArray|csv:Error st2anydma = csv:parseLists([st2, st2], (), {}, AnydataMapArray); -// test:assertEquals(st2anydma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// AnydataMapArray|csv:Error st3anydma = csv:parseLists([st3, st3], (), {}, AnydataMapArray); -// test:assertEquals(st3anydma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// AnydataMapArray|csv:Error st4anydma = csv:parseLists([st4, st4], (), {}, AnydataMapArray); -// test:assertEquals(st4anydma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomMapArray|csv:Error st1cma = csv:parseLists([st1, st1], (), {}, CustomMapArray); -// test:assertEquals(st1cma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// CustomMapArray|csv:Error st2cma = csv:parseLists([st2, st2], (), {}, CustomMapArray); -// test:assertEquals(st2cma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// CustomMapArray|csv:Error st3cma = csv:parseLists([st3, st3], (), {}, CustomMapArray); -// test:assertEquals(st3cma , [ -// {'1: s1, '2: s2}, -// {'1: s1, '2: s2} -// ]); - -// CustomMapArray|csv:Error st4cma = csv:parseLists([st4, st4], (), {}, CustomMapArray); -// test:assertEquals(st4cma , [ -// {'1: s1, '2: s2, '3: s3, '4: s2}, -// {'1: s1, '2: s2, '3: s3, '4: s2} -// ]); - -// NilMapArray|csv:Error st1nma = csv:parseLists([st1, st1], (), {}, NilMapArray); -// test:assertEquals(st1nma, ([ -// {}, -// {} -// ])); - -// IntegerMapArray|csv:Error st2ima = csv:parseLists([st2, st2], (), {}, IntegerMapArray); -// test:assertEquals(st2ima, ([ -// {}, -// {} -// ])); - -// DecimalMapArray|csv:Error st3dma = csv:parseLists([st3, st3], (), {}, DecimalMapArray); -// test:assertEquals(st3dma, ([ -// {}, -// {} -// ])); - -// BooleanMapArray|csv:Error st4bma = csv:parseLists([st4, st4], (), {}, BooleanMapArray); -// test:assertEquals(st4bma, ([ -// {}, -// {} -// ])); -// } - -// @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:parseLists(csv, ["a", "b", "c"]); -// test:assertEquals(rec_2, [ -// {a: 1, b: 2, c: 3}, -// {a: 3, b: 4, c: 5} -// ]); -// } +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +import ballerina/csv_commons as common; +import ballerina/data.csv; +import ballerina/test; + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType() { + StringRecord1Array|csv:Error st1sr1 = csv:parseLists([st1, st1], {}); + test:assertTrue(st1sr1 is csv:Error); + test:assertEquals((st1sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + + StringRecord1Array|csv:Error st2sr1 = csv:parseLists([st2, st2], {}); + test:assertTrue(st2sr1 is csv:Error); + test:assertEquals((st2sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + + StringRecord2Array|csv:Error st1sr2 = csv:parseLists([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:parseLists([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:parseLists([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:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1sr10, [ + {'1: "string", '2: ""}, + {'1: "string", '2: ""} + ]); + + StringRecord10Array|csv:Error st2sr10 = csv:parseLists([st2, st2], {}); + test:assertEquals(st2sr10, [ + {'1: "string", '2: "", '3: "a", '4: ""}, + {'1: "string", '2: "", '3: "a", '4: ""} + ]); + + StringRecord19Array|csv:Error st1sr19 = csv:parseLists([st1, st1], {}); + test:assertEquals(st1sr19, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord19Array|csv:Error st2sr19 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType2() { + StringRecord20Array|csv:Error st2sr20 = csv:parseLists([st2, st2], {}); + test:assertEquals(st2sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord21Array|csv:Error st1sr21 = csv:parseLists([st1, st1], {}); + test:assertEquals(st1sr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord21Array|csv:Error st2sr21 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1sr22, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord22Array|csv:Error st2sr22 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1sr23, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord23Array|csv:Error st2sr23 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord15Array|csv:Error st2cr15 = csv:parseLists([st2, st2], {}); + test:assertEquals(st2cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord16Array|csv:Error st1cr16 = csv:parseLists([st1, st1], {}); + test:assertTrue(st1cr16 is csv:Error); + test:assertEquals((st1cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); + + CustomRecord16Array|csv:Error st2cr16 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1cr17, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType3() { + CustomRecord17Array|csv:Error st2cr17 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertTrue(st1cr18 is csv:Error); + test:assertEquals((st1cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); + + CustomRecord18Array|csv:Error st2cr18 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1cr19, [ + {'1: s1, '2: s2, '3: "", '4: ""}, + {'1: s1, '2: s2, '3: "", '4: ""} + ]); + + CustomRecord19Array|csv:Error st2cr19 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1cr20, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord20Array|csv:Error st2cr20 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1cr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord21Array|csv:Error st2cr21 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1cr22, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType4() { + CustomRecord22Array|csv:Error st2cr22 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1cr23, [ + {"1": s1, "2": s2, a: ""}, + {"1": s1, "2": s2, a: ""} + ]); + + CustomRecord23Array|csv:Error st2cr23 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1cr24, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord24Array|csv:Error st2cr24 = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertTrue(st1cr25 is csv:Error); + test:assertEquals((st1cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + + CustomRecord25Array|csv:Error st2cr25 = csv:parseLists([st2, st2], {}); + test:assertTrue(st2cr25 is csv:Error); + test:assertEquals((st2cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + + CustomRecord25Array|csv:Error st3cr25 = csv:parseLists([st3, st3], {}); + test:assertTrue(st3cr25 is csv:Error); + test:assertEquals((st3cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + + CustomRecord25Array|csv:Error st4cr25 = csv:parseLists([st4, st4], {}); + test:assertTrue(st4cr25 is csv:Error); + test:assertEquals((st4cr25).message(), common:generateErrorMessageForInvalidFieldType("string", "1")); + + CustomRecord26Array|csv:Error st1cr26 = csv:parseLists([st1, st1], {}); + test:assertEquals(st1cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|csv:Error st2cr26 = csv:parseLists([st2, st2], {}); + test:assertEquals(st2cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|csv:Error st3cr26 = csv:parseLists([st3, st3], {}); + test:assertEquals(st3cr26 , [ + {'1: s1}, + {'1: s1} + ]); + + CustomRecord26Array|csv:Error st4cr26 = csv:parseLists([st4, st4], {}); + test:assertEquals(st4cr26 , [ + {'1: s1}, + {'1: s1} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType5() { + StringRecord1Array|csv:Error st3sr1 = csv:parseLists([st3, st3], {}); + test:assertTrue(st3sr1 is csv:Error); + test:assertEquals((st3sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + + StringRecord1Array|csv:Error st4sr1 = csv:parseLists([st4, st4], {}); + test:assertTrue(st4sr1 is csv:Error); + test:assertEquals((st4sr1).message(), common:generateErrorMessageForMissingRequiredField("s3")); + + StringRecord2Array|csv:Error st3sr2 = csv:parseLists([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:parseLists([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:parseLists([st3, st3], {}); + test:assertTrue(st3sr9 is csv:Error); + test:assertEquals((st3sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); + + StringRecord9Array|csv:Error st4sr9 = csv:parseLists([st4, st4], {}); + test:assertTrue(st4sr9 is csv:Error); + test:assertEquals((st4sr9).message(), common:generateErrorMessageForMissingRequiredField("s1")); + + StringRecord10Array|csv:Error st3sr10 = csv:parseLists([st3, st3], {}); + test:assertEquals(st3sr10, [ + {'1: "string", '2: ""}, + {'1: "string", '2: ""} + ]); + + StringRecord10Array|csv:Error st4sr10 = csv:parseLists([st4, st4], {}); + test:assertEquals(st4sr10, [ + {'1: "string", '2: "", '3: "a", '4: ""}, + {'1: "string", '2: "", '3: "a", '4: ""} + ]); + + StringRecord19Array|csv:Error st3sr19 = csv:parseLists([st3, st3], {}); + test:assertEquals(st3sr19, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord19Array|csv:Error st4sr19 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord20Array|csv:Error st4sr20 = csv:parseLists([st4, st4], {}); + test:assertEquals(st4sr20, [ + {s1: "", s2: ""}, + {s1: "", s2: ""} + ]); + + StringRecord21Array|csv:Error st3sr21 = csv:parseLists([st3, st3], {}); + test:assertEquals(st3sr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord21Array|csv:Error st4sr21 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3sr22, [ + {s1: "", s2: "", "1": s1, "2": s2}, + {s1: "", s2: "", "1": s1, "2": s2} + ]); + + StringRecord22Array|csv:Error st4sr22 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3sr23, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + StringRecord23Array|csv:Error st4sr23 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType6() { + CustomRecord15Array|csv:Error st4cr15 = csv:parseLists([st4, st4], {}); + test:assertEquals(st4cr15, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord16Array|csv:Error st3cr16 = csv:parseLists([st3, st3], {}); + test:assertTrue(st3cr16 is csv:Error); + test:assertEquals((st3cr16).message(), common:generateErrorMessageForMissingRequiredField("3")); + + CustomRecord16Array|csv:Error st4cr16 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3cr17, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord17Array|csv:Error st4cr17 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertTrue(st3cr18 is csv:Error); + test:assertEquals((st3cr18).message(), common:generateErrorMessageForMissingRequiredField("3")); + + CustomRecord18Array|csv:Error st4cr18 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3cr19, [ + {'1: s1, '2: s2, '3: "", '4: ""}, + {'1: s1, '2: s2, '3: "", '4: ""} + ]); + + CustomRecord19Array|csv:Error st4cr19 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3cr20, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord20Array|csv:Error st4cr20 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3cr21, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord21Array|csv:Error st4cr21 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3cr22, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord22Array|csv:Error st4cr22 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3cr23, [ + {"1": s1, "2": s2, a: ""}, + {"1": s1, "2": s2, a: ""} + ]); + + CustomRecord23Array|csv:Error st4cr23 = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3cr24, [ + {"1": s1, "2": s2}, + {"1": s1, "2": s2} + ]); + + CustomRecord24Array|csv:Error st4cr24 = csv:parseLists([st4, st4], {}); + test:assertEquals(st4cr24, [ + {'1: s1, '2: s2, '3: s3, '4: s2}, + {'1: s1, '2: s2, '3: s3, '4: s2} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { + record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseLists([["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:parseLists( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + {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:parseLists( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + {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:parseLists( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + {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:parseLists( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + {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:parseLists( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + {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:parseLists([["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:parseLists([["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:parseLists([["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["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:parseLists([["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:parseLists([["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["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:parseLists( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + {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:parseLists( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + {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:parseLists( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + {customHeaders: ["f", "e", "d", "c", "b", "a"]}); + test:assertEquals(ct1br12, [ + {a: ()}, + {a: ()} + ]); + + record{|string?...;|}[]|csv:Error ct1br13 = csv:parseLists( + [["a", "1"], ["a", "1"]], + {customHeaders: ["f", "e"]}); + test:assertEquals(ct1br13, [ + {e: "1", f: "a"}, + {e: "1", f: "a"} + ]); + + record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseLists( + [["2.23", "null"], ["7", "()"]], + {customHeaders: ["b", "a"]}); + test:assertEquals(ct1br14, [ + {}, + {} + ]); + + map[]|csv:Error ct1br15 = csv:parseLists( + [["2", "()"], ["2", "1"], ["()", "2"]], + {customHeaders: ["f", "e"]}); + test:assertEquals(ct1br15, [ + {e: (), f: 2}, + {e: 1, f: 2}, + {e: 2, f: ()} + ]); + + record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseLists( + [["2.23", "null"], ["7", "()"]], + {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:parseLists(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:parseLists([st1, st1], {}); + test:assertEquals(st1sma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + StringMapArray|csv:Error st2sma = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3sma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + StringMapArray|csv:Error st4sma = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1niusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + NillableIntUnionStringMapArray|csv:Error st2niusma = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3niusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + NillableIntUnionStringMapArray|csv:Error st4niusma = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1iusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + IntUnionStringMapArray|csv:Error st2iusma = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3iusma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + IntUnionStringMapArray|csv:Error st4iusma = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1jma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); +} + +@test:Config +function testFromCsvWithTypeForTupleAndMapAsExpectedType2() { + JsonMapArray|csv:Error st2jma = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3jma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + JsonMapArray|csv:Error st4jma = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1anydma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + AnydataMapArray|csv:Error st2anydma = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3anydma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + AnydataMapArray|csv:Error st4anydma = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1cma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + CustomMapArray|csv:Error st2cma = csv:parseLists([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:parseLists([st3, st3], {}); + test:assertEquals(st3cma , [ + {'1: s1, '2: s2}, + {'1: s1, '2: s2} + ]); + + CustomMapArray|csv:Error st4cma = csv:parseLists([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:parseLists([st1, st1], {}); + test:assertEquals(st1nma, ([ + {}, + {} + ])); + + IntegerMapArray|csv:Error st2ima = csv:parseLists([st2, st2], {}); + test:assertEquals(st2ima, ([ + {}, + {} + ])); + + DecimalMapArray|csv:Error st3dma = csv:parseLists([st3, st3], {}); + test:assertEquals(st3dma, ([ + {}, + {} + ])); + + BooleanMapArray|csv:Error st4bma = csv:parseLists([st4, st4], {}); + test:assertEquals(st4bma, ([ + {}, + {} + ])); +} 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 ac27ba8..2d73ce5 100644 --- a/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal +++ b/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal @@ -20,105 +20,105 @@ import ballerina/test; @test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType() { - BooleanArrayArray|csv:Error bm1ba = csv:transform([bm1, bm1], ["b1", "b2"], {}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanArrayArray); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - bm1ba = csv:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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,83 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType3() { @test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType3() { - AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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:transform([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")); } @@ -559,7 +559,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType3() { function testArrayIndexes() { map[] csv = [{a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}, {a: 7, b: 8}]; - int[][2]|csv:Error rec3 = csv:transform(csv, ["a", "b"]); + int[][2]|csv:Error rec3 = csv:transform(csv, {headersOrder: ["a", "b"]}); test:assertEquals(rec3, [ [1, 2], [3, 4], @@ -567,14 +567,72 @@ function testArrayIndexes() { [7, 8] ]); - [int...][2]|csv:Error rec3_3 = csv:transform(csv, ["a", "b"], {skipLines: [1]}); + [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, ["a", "b"], {skipLines: [2]}); + int[1][2]|csv:Error rec4 = csv:transform(csv, {headersOrder: ["a", "b"], skipLines: [2]}); test:assertEquals(rec4, [ [1, 2] ]); -} \ No newline at end of file +} + +@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(), "Header 'n2' cannot be find in data rows"); + + 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(), "Header 'n2' cannot be find in data rows"); +} 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 cb7ed9f..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 @@ -58,7 +58,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType() { {b1: true, b2: false, b3: (), b4: false} ]); - BooleanRecord2Array|csv:Error bm4br2 = csv:transform([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")); @@ -146,7 +146,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { {b1: true, b2: false, b3: (), b4: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error bm1br6 = csv:transform([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")); @@ -156,7 +156,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { {b1: true, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error bm3br6 = csv:transform([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: ()} @@ -247,7 +247,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType3() { {b1: true, b2: false} ]); - BooleanRecord10Array|csv:Error bm2br10 = csv:transform([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} @@ -325,7 +325,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType3() { {b1: true, b2: false, defaultableField: "", nillableField :null} ]); - BooleanRecord13Array|csv:Error bm2br13 = csv:transform([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} @@ -368,7 +368,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType4() { test:assertTrue(bm4br14 is csv:Error); test:assertEquals((bm4br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord14Array|csv:Error bm5br14 = csv:transform([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")); @@ -384,13 +384,13 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType4() { test:assertTrue(bm4br15 is csv:Error); test:assertEquals((bm4br15).message(), common:generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord16Array|csv:Error bm1br16 = csv:transform([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:transform([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: ()} @@ -462,7 +462,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType4() { {b2: false, b3: (), i1: 1} ]); - BooleanRecord18Array|csv:Error bm4br18 = csv:transform([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")); @@ -511,7 +511,7 @@ function testFromCsvWithTypeForMapAndMapAsExpectedType() { {b1: true, b2: false} ]); - NillableBooleanMapArray|csv:Error bm2nbma = csv:transform([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: ()} @@ -633,7 +633,7 @@ function testFromCsvWithTypeForMapAndMapAsExpectedType2() { {b1: true, b2: false} ]); - JsonMapArray|csv:Error bm2jma = csv:transform([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: ()} @@ -717,7 +717,7 @@ function testFromCsvWithTypeForMapAndMapAsExpectedType2() { {} ]); - StringMapArray|csv:Error bm1sma = csv:transform([bm1, bm1], {}, StringMapArray); + StringMapArray|csv:Error bm1sma = csv:transform([bm1, bm1], {outputWithHeaders: false}, StringMapArray); test:assertEquals(bm1sma, [ {}, {} @@ -749,7 +749,7 @@ function testFromCsvWithTypeForMapAndMapAsExpectedType2() { } @test:Config -function testArrayIndexes() { +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); @@ -764,6 +764,6 @@ function testArrayIndexes() { {a: 5} ]); - record {|int a;|}[5]|csv:Error rec2_2 = csv:transform(csv, {skipLines: [2]}); + 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/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 69ac797..a516c5a 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 @@ -90,7 +90,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<>(); @@ -107,6 +107,7 @@ static class CsvTree { int arraySize = 0; BString[] headersForArrayConversion = null; boolean addHeadersForOutput = false; + boolean isFirstRowIsHeader = false; void reset() { currentCsvNode = null; @@ -125,6 +126,7 @@ void reset() { arraySize = 0; headersForArrayConversion = null; addHeadersForOutput = false; + isFirstRowIsHeader = false; } @@ -214,6 +216,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()) { @@ -225,16 +228,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: @@ -242,8 +245,8 @@ 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(); for (int i = 0; i < length; i++) { @@ -254,18 +257,26 @@ public void traverseCsvArrayMembersWithMapAsCsvElementType(long length, BArray c 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); + rowValue = traverseCsvElementWithMapOrRecord(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++; + } } } - 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(); @@ -280,7 +291,7 @@ public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray Object o = csv.get(i); if (!addHeadersForOutput && config.outputWithHeaders - && (config.customHeaders != null || i == config.headerRows - 1)) { + && (o instanceof BMap || (config.customHeaders != null || i == config.headerRows - 1))) { // Headers will add to the list only in the first iteration addHeadersForTheListIfApplicable(o, expectedArrayType); } @@ -292,13 +303,15 @@ public void traverseCsvArrayMembersWithArrayAsCsvElementType(long length, BArray if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } - rootCsvNode.add(this.arraySize, rowValue); - this.arraySize++; + if (!this.isFirstRowIsHeader) { + rootCsvNode.add(this.arraySize, rowValue); + this.arraySize++; + } } } - 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(); for (int i = 0; i < length; i++) { @@ -311,7 +324,16 @@ public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray break; } - Object csvData = csv.get(i); + Object o = csv.get(i); + if (!addHeadersForOutput && config.outputWithHeaders + && (config.customHeaders != null || i == config.headerRows - 1)) { + // Headers will add to the list only in the first iteration + addHeadersForTheListIfApplicable(o, expectedArrayType); + } + if (i < config.headerRows) { + continue; + } + for (Type memberType: expectedArrayType.getMemberTypes()) { boolean isIntersection = false; try { @@ -326,21 +348,24 @@ public void traverseCsvArrayMembersWithUnionAsCsvElementType(long length, BArray if (memberType.getTag() == TypeTags.MAP_TAG || memberType.getTag() == TypeTags.RECORD_TYPE_TAG) { - rowValue = traverseCsvElementWithMapOrRecord(csvData, memberType); + rowValue = traverseCsvElementWithMapOrRecord(o, memberType); } else if (memberType.getTag() == TypeTags.TUPLE_TAG || memberType.getTag() == TypeTags.ARRAY_TAG) { if (i < config.headerRows) { continue; } - rowValue = traverseCsvElementWithArray(csvData, memberType); + rowValue = traverseCsvElementWithArray(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) { @@ -417,13 +442,102 @@ private void traverseArrayValue(Object csvElement, Type type) { } } + private void constructArrayValuesFromMap(BMap map, Type type, int expectedSize) { + int index = 0; + BString[] keys = createHeadersForBMap(map, config.headersOrder, map.size()); + for (BString key: keys) { + if (!map.containsKey(key)) { + throw DiagnosticLog.error(DiagnosticErrorCode.INCONSISTENT_HEADER, key); + } + Object v = map.get(key); + if (config.allowDataProjection && index >= expectedSize) { + break; + } + Type memberType = getArrayOrTupleMemberType(type, index); + if (memberType != null) { + addValuesToArrayType(v, memberType, index, currentCsvNode); + } + index++; + } + } + + private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { + int index = 0; + for (int i = 0; i < csvElement.getLength(); i++) { + if (config.allowDataProjection && index >= expectedSize) { + break; + } + Type memberType = getArrayOrTupleMemberType(type, index); + if (memberType != null) { + addValuesToArrayType(csvElement.get(i), memberType, index, currentCsvNode); + } + index++; + } + } + + 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 void traverseArrayValueWithMapAsExpectedType(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 (config.headerRows >= 1) { + // To skip the row at the position [config.headerRows - 1] from being added to the result. + this.isFirstRowIsHeader = true; + return; + } + } + 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 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); + } + CsvUtils.checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); + } + private void addHeadersForTheListIfApplicable(Object obj, Type type) { - if (config.outputWithHeaders - && obj instanceof BArray array && isExpectedTypeIsArray(type)) { - if (this.headers == null) { + if (config.outputWithHeaders && isExpectedTypeIsArray(type)) { + if (this.headers == null && obj instanceof BArray array) { String[] headers = new String[array.size()]; this.headers = CsvUtils.createHeadersForParseLists(array, headers, config); } + if (obj instanceof BMap) { + if (config.headersOrder == null) { + return; + } + this.headers = ((BArray) config.headersOrder).getStringArray(); + } BArray headersArray; if (type instanceof ArrayType arrayType) { @@ -438,30 +552,17 @@ && obj instanceof BArray array && isExpectedTypeIsArray(type)) { addValuesToArrayType(StringUtils.fromString(headers[i]), memberType, i, headersArray); } } - rootCsvNode.add(this.arraySize, headersArray); - this.arraySize++; - addHeadersForOutput = true; - } - } - private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { - int index = 0; - for (int i = 0; i < csvElement.getLength(); i++) { - if (config.allowDataProjection && index >= expectedSize) { - break; + if (!this.isFirstRowIsHeader) { + rootCsvNode.add(this.arraySize, headersArray); + this.arraySize++; + addHeadersForOutput = true; } - Type memberType = getArrayOrTupleMemberType(type, index); - if (memberType != null) { - addValuesToArrayType(csvElement.get(i), memberType, index, currentCsvNode); - } - index++; } } - private void constructArrayValuesFromMap(BMap map, Type type, int expectedSize) { - int size = map.size(); + private BString[] createHeadersForBMap(BMap map, Object headersOrder, int size) { BString[] keys = new BString[size]; - Object headersOrder = config.headersOrder; if (headersOrder != null) { String[] headerOrder = ((BArray) headersOrder).getStringArray(); if (headerOrder.length != size) { @@ -476,32 +577,7 @@ private void constructArrayValuesFromMap(BMap map, Type type, i } keys = headersForArrayConversion; } - - if (!addHeadersForOutput && config.outputWithHeaders) { - for (int i = 0; i < keys.length; i++) { - Type memberType = getArrayOrTupleMemberType(type, i); - if (memberType != null) { - addValuesToArrayType(keys[i], memberType, i, currentCsvNode); - } - } - addHeadersForOutput = true; - } - - int index = 0; - for (BString key: keys) { - if (!map.containsKey(key)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INCONSISTENT_HEADER, key); - } - Object v = map.get(key); - if (config.allowDataProjection && index >= expectedSize) { - break; - } - Type memberType = getArrayOrTupleMemberType(type, index); - if (memberType != null) { - addValuesToArrayType(v, memberType, index, currentCsvNode); - } - index++; - } + return keys; } private Type getArrayOrTupleMemberType(Type type, int index) { @@ -530,16 +606,6 @@ 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) { if (arraySize < this.headers.length) { return false; @@ -615,21 +681,6 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType) { return false; } - private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, - boolean mappingType, Type expectedType) { - int arraySize = csvElement.size(); - String[] headers = new String[csvElement.size()]; - if (this.headers == null) { - this.headers = CsvUtils.createHeadersForParseLists(csvElement, 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) { Type fieldType; BString key; @@ -649,26 +700,6 @@ private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappin 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); - } - CsvUtils.checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); - } - private boolean isKeyBelongsToNonRestType(Object value, BString key) { String keyStr = StringUtils.getStringValue(key); String fieldName = CsvUtils.getUpdatedHeaders(this.updatedRecordFieldNames, 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 9295f8a..08cb899 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,7 +44,7 @@ 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"), - INCONSISTENT_HEADER("BDE_0020", "ç.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"), diff --git a/native/src/main/resources/csv_error.properties b/native/src/main/resources/csv_error.properties index 1808ef1..525ad49 100644 --- a/native/src/main/resources/csv_error.properties +++ b/native/src/main/resources/csv_error.properties @@ -79,7 +79,7 @@ error.invalid.value.for.skiplines=\ Invalid input for the skipLines field. Both start and end values must be integers. error.inconsistent.header=\ - Header ''{0}'' cannot be find in previous data rows + Header ''{0}'' cannot be find in data rows error.invalid.custom.header.length=\ Invalid length for the headers From 8dee10016933a807fe444d9e585a24b497b81a46 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Wed, 7 Aug 2024 23:52:22 +0530 Subject: [PATCH 114/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ed49c87..fb9f48d 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0-20240801-104200-87df251c" +distribution-version = "2201.9.2" [[package]] org = "ballerina" From ebecb3adc2b4bec561593ccafd13e70529089911 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Wed, 7 Aug 2024 23:53:22 +0530 Subject: [PATCH 115/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index fb9f48d..ed49c87 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.2" +distribution-version = "2201.10.0-20240801-104200-87df251c" [[package]] org = "ballerina" From 08311d15597172bf9f2cbbc740cfd97eb9ce73fd Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Thu, 8 Aug 2024 00:17:00 +0530 Subject: [PATCH 116/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 +------------------------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ed49c87..0bfd723 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,8 +12,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "test"} + {org = "ballerina", name = "jballerina.java"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -27,52 +26,3 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - From 10ebeeaf08bb1756be346a9abc76c737b4398f1b Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Thu, 8 Aug 2024 00:42:44 +0530 Subject: [PATCH 117/147] Add list related header param changes for transform api --- .../tests/constraint_validation_test.bal | 6 +- ballerina-tests/csv-commons/test_utils.bal | 4 +- .../tests/parse_record_type_as_list_test.bal | 48 ++++- .../tests/parse_string_compatibality_test.bal | 60 ++++++ .../tests/parse_type_compatibility_test.bal | 28 +-- .../tests/test_union_types_with_headers.bal | 157 ++++++++++++++ .../tests/test_with_intersection_types.bal | 22 +- .../tests/test_with_singleton_test.bal | 18 +- .../tests/test_with_union_types.bal | 110 +++++----- .../tests/user_config_projection_tests.bal | 70 +++--- .../user_config_with_parser_options_test.bal | 200 ++++++++++++------ .../user-config-tests/tests/user_configs.bal | 10 +- .../lib/data/csvdata/csv/CsvTraversal.java | 50 +++-- .../csvdata/utils/DiagnosticErrorCode.java | 4 +- .../src/main/resources/csv_error.properties | 5 +- 15 files changed, 569 insertions(+), 223 deletions(-) create mode 100644 ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal 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 a308c12..e58c5c1 100644 --- a/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal +++ b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal @@ -69,15 +69,15 @@ function testConstraintWithRecords() returns error? { test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("minLength")); - cRec1 = csv:parseLists([["4", "abc"], ["3", "cde"]], ["a", "b"]); + cRec1 = csv:parseLists([["4", "abc"], ["3", "cde"]], {customHeaders: ["a", "b"]}); test:assertEquals(cRec1, [{a: 4, b: "abc"}, {a: 3, b: "cde"}]); - cRec1 = csv:parseLists([["4", "abc"], ["11", "cde"]], ["a", "b"]); + cRec1 = csv:parseLists([["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:parseLists([["4", "abc"], ["5", "b"]], ["a", "b"]); + cRec1 = csv:parseLists([["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/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-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 2d73ce5..7909d26 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 @@ -630,9 +630,53 @@ function testParseRecordsAsListsWithHeaderOutput() { 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(), "Header 'n2' cannot be find in data rows"); + 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(), "Header 'n2' cannot be find in data rows"); + 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:parseLists([["a", "b"], ["c", "d", "e"]], {outputWithHeaders: true}); + test:assertEquals(bm3anyd3t_3, [["a", "b"], ["c", "d", "e"]]); + + bm3anyd3t_4 = csv:parseLists([["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/type-compatible-tests/tests/parse_string_compatibality_test.bal b/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal index 66c4537..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 @@ -223,6 +223,13 @@ function testParseBytes() returns error? { {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}] ); + 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"], @@ -230,6 +237,27 @@ function testParseBytes() returns error? { ["Hello World", "\"Hello World\"", "Hello World", "2"] ]); + 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")); @@ -249,6 +277,14 @@ function testParseStream() returns error? { {"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}, + {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}] + ); + csvByteStream = check io:fileReadBlocksAsStream(filepath); string[][]|csv:Error rec2 = csv:parseStream(csvByteStream, {}); test:assertEquals(rec2, [ @@ -257,6 +293,30 @@ function testParseStream() returns error? { ["Hello World", "\"Hello World\"", "Hello World", "2"] ]); + csvByteStream = check io:fileReadBlocksAsStream(filepath); + 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); 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 37beb57..b75d0a9 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 @@ -278,7 +278,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true} - ], ["a", "b", "c"]); + ], {headersOrder: ["a", "b", "c"]}); test:assertEquals(rt6a , [ [1, "string", true], @@ -288,7 +288,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [A, B, C][]|csv:Error rt7a = csv:transform( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] - , ["a", "b", "c"]); + , {headersOrder: ["a", "b", "c"]}); test:assertEquals(rt7a , [ [1, "string", true], @@ -298,7 +298,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [A2, B2, C2][]|csv:Error rt8a = csv:transform( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] - , ["a", "b", "c"]); + , {headersOrder: ["a", "b", "c"]}); test:assertEquals(rt8a , [ [1, "string", true], @@ -308,7 +308,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [A2, B2, C2...][]|csv:Error rt9a = csv:transform( [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] - , ["a", "b", "c", "d"]); + , {headersOrder: ["a", "b", "c", "d"]}); test:assertEquals(rt9a , [ [1, "string", true, "string"], @@ -318,7 +318,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [C2...][]|csv:Error rt10a = csv:transform( [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] - , ["a", "b", "c", "d"]); + , {headersOrder: ["a", "b", "c", "d"]}); test:assertTrue(rt10a is csv:Error); test:assertEquals((rt10a).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "0", "type_compatible_tests:C2")); @@ -328,7 +328,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { readonly & string b; (readonly & boolean) | (readonly & decimal) c; }[]|csv:Error rt11a = csv:parseLists( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); test:assertEquals(rt11a , [ {a: 1, b: "string", c: true}, @@ -337,7 +337,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ]); record{A a; B b; C c;}[]|csv:Error rt12a = csv:parseLists( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); test:assertEquals(rt12a , [ {a: 1, b: "string", c: true}, @@ -346,14 +346,14 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ]); record{A a; B b; C c;}[]|csv:Error rt12a_2 = csv:parseLists( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"], {stringConversion: false}); + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["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:parseLists( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); test:assertEquals(rt12a_3 , [ {a: 1, b: "string", c: true}, @@ -362,7 +362,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ]); record{A2 a; B2 b; C2 c;}[]|csv:Error rt13a = csv:parseLists( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], ["a", "b", "c"]); + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); test:assertEquals(rt13a , [ {a: 1, b: "string", c: true}, @@ -372,7 +372,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { record{|A2 a; B2 b; C2...;|}[]|csv:Error rt14a = csv:parseLists( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] - , ["a", "b", "c", "d"]); + , {customHeaders: ["a", "b", "c", "d"]}); test:assertEquals(rt14a , [ {a: 1, b: "string", c: true, d: "string"}, @@ -382,7 +382,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { record{|C2...;|}[]|csv:Error rt15a = csv:parseLists( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] - , ["a", "b", "c", "d"]); + , {customHeaders: ["a", "b", "c", "d"]}); test:assertEquals(rt15a , [ {a: "1", b: "string", c: true, d: "string"}, @@ -391,8 +391,8 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ]); record{|C2...;|}[]|csv:Error rt15a_2 = csv:parseLists( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] - , ["a", "b", "c", "d"], {stringConversion: false}); + [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]], + {stringConversion: false, customHeaders: ["a", "b", "c", "d"]}); test:assertEquals(rt15a_2 , [ {a: "1", b: "string", c: "true", d: "string"}, 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..98a1138 --- /dev/null +++ b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal @@ -0,0 +1,157 @@ +// 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:ParseListsOptions op6 = {outputWithHeaders: true}; +// csv:ParseListsOptions op7 = {outputWithHeaders: true, headerRows: 1}; +// csv:ParseListsOptions op8 = {outputWithHeaders: true, headerRows: 2}; +// csv:ParseListsOptions op9 = {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b", "c", "d"]}; +// csv:ParseListsOptions op10 = {outputWithHeaders: true, headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +// csv:ParseListsOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", "c", "d"]}; +// csv:ParseListsOptions op12 = {headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +// csv:ParseListsOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; + +// type UnionType1 string[][]|float[][]; + +// type UnionType2 float[][]|string[][]; + +// type UnionType3 (float|string)[][]; + +// type UnionType4 [string...][]|[boolean, string, string, string][]; + +// type UnionType5 [string, string, string, string][]|[string...][]; + +// type UnionType6 ([string...][]|[string, string, string, string])[]; + +// type UnionType7 string[][]|[string...][]; + +// type UnionType8 ([boolean...]|string[])[]; + +// type UnionType9 record {}[]|record {int d1;}[]; + +// type UnionType10 record {int d1;}[]|record {}[]; + +// type UnionType11 (record {int d1;}|record {})[]; + +// type UnionType12 map[]|map[]; + +// type UnionType13 map[]|map[]; + +// type UnionType14 (map|map)[]; + +// type UnionType15 (map|map)[]; + +// var 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 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"]]; + +// @test:Config +// function testParseStringWithMapWithOutputHeaders() { +// UnionType9|csv:Error psu9 = csv:parseString(csv3); +// test:assertEquals(psu9, result2); + +// psu9 = csv:parseString(csv3, op5); +// test:assertEquals(psu9, result2); + +// UnionType10|csv:Error psu10 = csv:parseString(csv3); +// test:assertEquals(psu10, result2); + +// psu10 = csv:parseString(csv3, op5); +// test:assertEquals(psu10, result2); + +// UnionType11|csv:Error psu11 = csv:parseString(csv3); +// test:assertEquals(psu11, result2); + +// psu11 = csv:parseString(csv3, op5); +// test:assertEquals(psu11, result2); + +// UnionType12|csv:Error psu12 = csv:parseString(csv3); +// test:assertEquals(psu12, result2); + +// psu12 = csv:parseString(csv3, op5); +// test:assertEquals(psu12, result2); + +// UnionType13|csv:Error psu13 = csv:parseString(csv3); +// test:assertEquals(psu13, result2); + +// psu13 = csv:parseString(csv3, op5); +// test:assertEquals(psu13, result2); + +// UnionType14|csv:Error psu14 = csv:parseString(csv3); +// test:assertEquals(psu14, result2); + +// psu14 = csv:parseString(csv3, op5); +// test:assertEquals(psu14, result2); + +// UnionType15|csv:Error psu15 = csv:parseString(csv3); +// test:assertEquals(psu15, result2); + +// psu15 = csv:parseString(csv3, op5); +// test:assertEquals(psu15, result2); +// } + +// @test:Config +// function testParseStringWithListWithOutputHeaders() { +// UnionType1|csv:Error psu1 = csv:parseString(csv3); +// test:assertEquals(psu1, result4); + +// psu1 = csv:parseString(csv3, op5); +// test:assertEquals(psu1, result4); + +// UnionType2|csv:Error psu2 = csv:parseString(csv3); +// test:assertEquals(psu2, result4); + +// psu2 = csv:parseString(csv3, op5); +// test:assertEquals(psu2, result4); + +// UnionType3|csv:Error psu3 = csv:parseString(csv3); +// test:assertEquals(psu3, result4); + +// psu3 = csv:parseString(csv3, op5); +// test:assertEquals(psu3, result4); + +// UnionType4|csv:Error psu4 = csv:parseString(csv3); +// test:assertEquals(psu4, result4); + +// psu4 = csv:parseString(csv3, op5); +// test:assertEquals(psu4, result4); + +// UnionType5|csv:Error psu5 = csv:parseString(csv3); +// test:assertEquals(psu5, result4); + +// psu5 = csv:parseString(csv3, op5); +// test:assertEquals(psu5, result4); + +// UnionType6|csv:Error psu6 = csv:parseString(csv3); +// test:assertEquals(psu6, result4); + +// psu6 = csv:parseString(csv3, op5); +// test:assertEquals(psu6, result4); + +// UnionType7|csv:Error psu7 = csv:parseString(csv3); +// test:assertEquals(psu7, result4); + +// psu7 = csv:parseString(csv3, op5); +// test:assertEquals(psu7, result4); + +// UnionType8|csv:Error psu8 = csv:parseString(csv3); +// test:assertEquals(psu8, result4); + +// psu8 = csv:parseString(csv3, op5); +// test:assertEquals(psu8, result4); +// } 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 d7008a3..66a06fa 100644 --- a/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal @@ -82,11 +82,11 @@ function testIntersectionExpectedTypes() returns error? { @test:Config function testIntersectionExpectedTypes2() returns error? { - (int[] & readonly)[]|csv:Error a = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["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:transform([{"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"]]); @@ -98,11 +98,11 @@ function testIntersectionExpectedTypes2() returns error? { test:assertTrue(a4 is record {|string...;|}[] & readonly); test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - ([int] & readonly)[]|csv:Error a5 = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], ["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:transform([{"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"]]); @@ -114,7 +114,7 @@ function testIntersectionExpectedTypes2() returns error? { test:assertTrue(a8 is map[] & readonly); test:assertEquals(a8, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], ["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"]]); @@ -134,11 +134,11 @@ function testIntersectionExpectedTypes3() returns error? { test:assertTrue(a2 is [string, string][] & readonly); test:assertEquals(a2, [["a", "a"], ["c", "c"]]); - (record {int a; string b;} & readonly)[]|csv:Error a3 = csv:parseLists([["1", "2"], ["4", "5"]], ["a", "b"], {}); + (record {int a; string b;} & readonly)[]|csv:Error a3 = csv:parseLists([["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:parseLists([["a", "a"], ["c", "c"]], ["a", "b"], {}); + record {|string...;|}[] & readonly|csv:Error a4 = csv:parseLists([["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"}]); @@ -150,11 +150,11 @@ function testIntersectionExpectedTypes3() returns error? { test:assertTrue(a6 is [string, string][] & readonly); test:assertEquals(a6, [["a", "a"], ["c", "c"]]); - (record {int a; string b;} & readonly)[]|csv:Error a7 = csv:parseLists([["1", "2"], ["4", "5"]], ["a", "b"], {}); + (record {int a; string b;} & readonly)[]|csv:Error a7 = csv:parseLists([["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:parseLists([["a", "a"], ["c", "c"]], ["a", "b"], {}); + map[] & readonly|csv:Error a8 = csv:parseLists([["a", "a"], ["c", "c"]], {customHeaders: ["a", "b"]}); test:assertTrue(a8 is map[] & readonly); test:assertEquals(a8, [{a: "a", b: "a"}, {a: "c", b: "c"}]); @@ -163,12 +163,12 @@ function testIntersectionExpectedTypes3() returns error? { test:assertEquals(a9, [[1, 2], ["a", "b"]]); ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] - & readonly|csv:Error a10 = csv:parseLists([["a", "a"], ["1", "2"]], ["a", "b"], {}); + & readonly|csv:Error a10 = csv:parseLists([["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:parseLists([["a", "a"], ["1", "2"]], ["a", "b"], {}); + & readonly|csv:Error a11 = csv:parseLists([["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 b97c004..f0ca784 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 @@ -184,28 +184,22 @@ function testSubtypeExpectedTypes() returns error? { SubtypeRecord3[]|csv:Error a9 = csv:transform(value1, {}); test:assertEquals(a9, value1); - SubtypeTuple[]|csv:Error a10 = csv:transform(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:transform(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:transform(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:parseLists(value2, - ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + SubtypeRecord[]|csv:Error a13 = csv:parseLists(value2, {customHeaders: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a13, value1); - SubtypeRecord2[]|csv:Error a14 = csv:parseLists(value2, - ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + SubtypeRecord2[]|csv:Error a14 = csv:parseLists(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:parseLists(value2, - ["a", "c", "d", "e", "f", "g", "h", "i"], {}); + SubtypeRecord3[]|csv:Error a15 = csv:parseLists(value2, {customHeaders: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a15, value1); SubtypeTuple[]|csv:Error a16 = csv:parseLists(value2, {}); 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 efcdc50..0e5ccf4 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 @@ -252,7 +252,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - (RecA|RecC)[]|csv:Error csv1op1 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {}); + (RecA|RecC)[]|csv:Error csv1op1 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecA|RecC)[]|csv:Error csv1op2 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecC|RecA)[]|csv:Error csv1op3 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecB|RecA)[]|csv:Error csv1op4 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (RecA|RecB)[]|csv:Error csv1op5 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [4, 2]}); + (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); + (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: true}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -320,7 +320,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, d: 3} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9_2 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9_2 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); test:assertEquals(csv1op9_2, [ {}, {}, @@ -329,14 +329,14 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, -1, 4]}); + (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {}); + (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -345,11 +345,11 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", d: 3} ]); - (record{|int a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op12 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + (record{|int a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op12 = csv:parseLists(value, {customHeaders: ["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:parseLists([["1", "2"], ["a", "b"]], ["a", "b"], {}); + (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op13 = csv:parseLists([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, {a: "a", b: "b"} @@ -367,7 +367,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - (TupA|TupC)[]|csv:Error csv1op1 = csv:transform(value, ["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 +376,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupA|TupC)[]|csv:Error csv1op2 = csv:transform(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 +384,66 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupC|TupA)[]|csv:Error csv1op3 = csv:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform([{"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"] @@ -767,7 +767,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - RecA[]|RecC[]|csv:Error csv1op1 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {}); + RecA[]|RecC[]|csv:Error csv1op1 = csv:parseLists(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 +776,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|csv:Error csv1op2 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecA[]|RecC[]|csv:Error csv1op2 = csv:parseLists(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 +784,49 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|csv:Error csv1op3 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecC[]|RecA[]|csv:Error csv1op3 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecB[]|RecA[]|csv:Error csv1op4 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + RecA[]|RecB[]|csv:Error csv1op5 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, 4]}); + record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [4, 2]}); + record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: true}); + record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: true}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -835,7 +835,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, d: 3} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9_2 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9_2 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); test:assertEquals(csv1op9_2, [ {}, {}, @@ -844,14 +844,14 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {skipLines: [2, -1, 4]}); + record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseLists(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:parseLists(value, ["a", "b", "c", "d", "e", "f"], {}); + record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -860,11 +860,11 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", d: 3} ]); - record{|int a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op12 = csv:parseLists(value, ["a", "b", "c", "d", "e", "f"], {stringConversion: false}); + record{|int a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op12 = csv:parseLists(value, {customHeaders: ["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:parseLists([["1", "2"], ["a", "b"]], ["a", "b"], {}); + record{|int a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op13 = csv:parseLists([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, {a: "a", b: "b"} @@ -882,7 +882,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - TupA[]|TupC[]|csv:Error csv1op1 = csv:transform(value, ["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 +891,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupA[]|TupC[]|csv:Error csv1op2 = csv:transform(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 +899,62 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupC[]|TupA[]|csv:Error csv1op3 = csv:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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...][])'"); } 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 c5aa914..cf2b6da 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 @@ -184,80 +184,80 @@ function testCustomNameAnnotation() returns error? { @test:Config function testCustomNameAnnotation2() returns error? { - RecordWithCustomAnnotation[]|csv:Error cntr1 = csv:parseLists([["1", "3"]], ["b", "c"], {}); + RecordWithCustomAnnotation[]|csv:Error cntr1 = csv:parseLists([["1", "3"]], {customHeaders: ["b", "c"]}); test:assertEquals(cntr1, [{b: 1, a: 3}]); - RecordWithCustomAnnotation[]|csv:Error cntr2 = csv:parseLists([["3", "1"]], ["c", "b"], {}); + RecordWithCustomAnnotation[]|csv:Error cntr2 = csv:parseLists([["3", "1"]], {customHeaders: ["c", "b"]}); test:assertEquals(cntr2, [{b: 1, a: 3}]); RecordWithCustomAnnotation[]|csv:Error cntr3 = csv:parseLists( - [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["f", "c", "b", "e"], {}); + [["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:parseLists([["1", "3"]], ["d", "c"], {}); + RecordWithCustomAnnotation2[]|csv:Error cntr4 = csv:parseLists([["1", "3"]], {customHeaders: ["d", "c"]}); test:assertEquals(cntr4, [{b: 1, a: 3}]); - RecordWithCustomAnnotation2[]|csv:Error cntr5 = csv:parseLists([["3","1"]], ["c", "d"], {}); + RecordWithCustomAnnotation2[]|csv:Error cntr5 = csv:parseLists([["3","1"]], {customHeaders: ["c", "d"]}); test:assertEquals(cntr5, [{b: 1, a: 3}]); RecordWithCustomAnnotation2[]|csv:Error cntr6 = csv:parseLists( - [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); + [["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:parseLists([["3", "1"]], ["a", "b"], {}); + RecordWithCustomAnnotation2[]|csv:Error cntr7 = csv:parseLists([["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:parseLists([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + RecordWithCustomAnnotation2[]|csv:Error cntr8 = csv:parseLists([["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:parseLists([["1", "3"]], ["d", "c"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr9 = csv:parseLists([["1", "3"]], {customHeaders: ["d", "c"]}); test:assertEquals(cntr9, [{b: 1, a: 3}]); - RecordWithCustomAnnotation3[]|csv:Error cntr10 = csv:parseLists([["3", "1"]], ["c", "d"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr10 = csv:parseLists([["3", "1"]], {customHeaders: ["c", "d"]}); test:assertEquals(cntr10, [{b: 1, a: 3}]); RecordWithCustomAnnotation3[]|csv:Error cntr11 = csv:parseLists( - [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); + [["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:parseLists([["3", "1"]], ["a", "b"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr12 = csv:parseLists([["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:parseLists([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + RecordWithCustomAnnotation3[]|csv:Error cntr13 = csv:parseLists([["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:parseLists([["1", "3", "true"]], ["d", "c", "z"], {}); + RecordWithCustomAnnotation4[]|csv:Error cntr14 = csv:parseLists([["1", "3", "true"]], {customHeaders: ["d", "c", "z"]}); test:assertEquals(cntr14, [{b: 1, a: 3, z: true}]); - RecordWithCustomAnnotation4[]|csv:Error cntr15 = csv:parseLists([["3", "1"]], ["c", "d"], {}); + RecordWithCustomAnnotation4[]|csv:Error cntr15 = csv:parseLists([["3", "1"]], {customHeaders: ["c", "d"]}); test:assertEquals(cntr15, [{b: 1, a: 3}]); RecordWithCustomAnnotation4[]|csv:Error cntr16 = csv:parseLists( - [["3", "3", "1", "cde"], ["3", "3", "1", "cde"]], ["c", "f", "d", "e"], {}); + [["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:parseLists([["3", "1"]], ["a", "b"], {}); + RecordWithCustomAnnotation4[]|csv:Error cntr17 = csv:parseLists([["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:parseLists([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + RecordWithCustomAnnotation4[]|csv:Error cntr18 = csv:parseLists([["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:parseLists([["3", "1", "4", "5"]], ["c", "d", "a", "b"], {}); + RecordWithCustomAnnotation5[]|csv:Error cntr19 = csv:parseLists([["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:parseLists( - [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "e"], {}); + [["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:parseLists( - [["3", "1", "4"], ["3", "1", "4"]], ["c", "d", "a"], {}); + [["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}]); } @@ -359,22 +359,22 @@ function testAbsentAsNilableConfig2() returns error? { test:assertTrue(cn4 is csv:Error); test:assertEquals((cn4).message(), common:generateErrorMessageForMissingRequiredField("g")); - record {|string a; int? g; int? h;|}[]|csv:Error cn5 = csv:parseLists([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int? g; int? h;|}[]|csv:Error cn5 = csv:parseLists([["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:parseLists([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int? g?;|}[]|csv:Error cn6 = csv:parseLists([["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:parseLists([["a"], ["a"], ["b"]], ["a"], { + record {|string a; int g?;|}[]|csv:Error cn7 = csv:parseLists([["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:parseLists([["a"], ["a"], ["a"]], ["a"], { + record {|string a; int g;|}[]|csv:Error cn8 = csv:parseLists([["a"], ["a"], ["a"]], {customHeaders: ["a"], allowDataProjection: {absentAsNilableType: true}, skipLines: [3] }); test:assertTrue(cn8 is csv:Error); @@ -617,57 +617,57 @@ function testDataProjectionConfig() returns error? { 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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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:transform(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 b3525ed..23cd58e 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 @@ -532,64 +532,64 @@ function testSkipLineParserOption() { @test:Config {dependsOn: [testCSVLocale]} function testCustomHeaderOption() { - anydata[][]|csv:Error bm1ba = csv:transform([bm1, bm1], ["b1", "b2"], {}); + anydata[][]|csv:Error bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - anydata[][]|csv:Error bm1ba2 = csv:transform([bm1, bm1], ["b2", "b1"], {}); + anydata[][]|csv:Error bm1ba2 = csv:transform([bm1, bm1], {headersOrder: ["b2", "b1"]}); test:assertEquals(bm1ba2, [ [false, true], [false, true] ]); - anydata[][]|csv:Error bm2ba = csv:transform([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:transform([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:transform([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:transform([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:transform([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:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "b"], {}); + record {}[]|csv:Error ct1br = csv:parseLists([["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:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "b", "c", "d"], {}); + record {}[]|csv:Error ct1br2 = csv:parseLists([["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:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "c", "b", "d"], {}); + record {}[]|csv:Error ct1br2_2 = csv:parseLists([["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:parseLists([["a", "1", "true"], ["a", "1", "true"]], [], {}); + record {}[]|csv:Error ct1br3 = csv:parseLists([["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:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + record {|string a; string b; string c;|}[]|csv:Error ct1br5 = csv:parseLists([["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:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], {}); + record {string a; string b; string c;}[]|csv:Error ct1br6 = csv:parseLists([["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:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + record {string a; string b;}[]|csv:Error ct1br7 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], stringConversion: false }); test:assertEquals(ct1br7, [ @@ -597,7 +597,7 @@ function testCustomHeaderOption() { {a: "a", e: "1", b: "true"} ]); - record {|string a; string b;|}[]|csv:Error ct1br8 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + record {|string a; string b;|}[]|csv:Error ct1br8 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], stringConversion: false }); test:assertEquals(ct1br8, [ @@ -605,7 +605,7 @@ function testCustomHeaderOption() { {a: "a", b: "true"} ]); - record {|string...;|}[]|csv:Error ct1br9 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], ["a", "e", "b"], { + record {|string...;|}[]|csv:Error ct1br9 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], stringConversion: false }); test:assertEquals(ct1br9, [ @@ -613,7 +613,7 @@ function testCustomHeaderOption() { {a: "a", b: "true", e: "1"} ]); - record {|string...;|}[]|csv:Error ct1br10 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], (), { + record {|string...;|}[]|csv:Error ct1br10 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], { stringConversion: false }); test:assertEquals(ct1br10, [ @@ -624,19 +624,42 @@ function testCustomHeaderOption() { @test:Config function testCustomHeaderParserOption2() { - record {}[]|csv:Error ct1br = csv:parseString(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 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: ()} + ]); - record {}[]|csv:Error ct1br2 = csv:parseString(csvStringData1, {header: 1, customHeaders: []}); + 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:parseString(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:parseString(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: ()}, @@ -645,7 +668,10 @@ function testCustomHeaderParserOption2() { {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(csvStringData1, {header: 1, customHeaders: ["f", "e", "d", "c", "b", "a"]}); + 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: ()}, @@ -654,34 +680,23 @@ function testCustomHeaderParserOption2() { {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(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f", "e", "d", "c", "b", "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:parseString(csvStringData1, {skipLines: [1], customHeaders: ["f", "e", "d", "c", "b", "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:parseString(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:parseString(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + 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}, @@ -690,20 +705,19 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br7_2 = csv:parseString(csvStringData1, {header: false, skipLines: [1], customHeaders: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + 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:parseString(csvStringData1, {header: 1, customHeaders: ["e1", "d1"]}); + 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:parseString(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}, @@ -712,20 +726,11 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br10 = csv:parseString(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:parseString(csvStringData1, {header: 1, customHeaders: ["f1", "e1"]}); + 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:parseString(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"}, @@ -734,7 +739,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: "true"} ]); - record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseString(csvStringData1, {header: 1, customHeaders: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); + 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")); } @@ -799,7 +804,12 @@ function testTextQuotesWithParserOptions() { record {}[]|csv:Error cn6 = csv:parseString(csvValue6, {}); 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"); + + 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 headers"); } @test:Config @@ -929,3 +939,59 @@ function testLineTerminatorWithParserOptions() { 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:parseLists(csv2, {outputWithHeaders: true, skipLines: "2-3", customHeaders: ["a", "b"]}); + test:assertEquals(result, [{a: 1, b: 2}, {a: 4, b: 5}]); + + result2 = csv:parseLists(csv2, {outputWithHeaders: true, skipLines: "2-3", customHeaders: ["a", "b"]}); + test:assertEquals(result2, [["a", "b"], [1, 2], [4, 5]]); + + result = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + test:assertEquals(result, [{a: 2, b: 3}]); + + result2 = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + test:assertEquals(result2, [["a", "b"], [2, 3]]); + + result = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); + test:assertEquals(result, [{a: 3, b: 4}]); + + result2 = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); + test:assertEquals(result2, [["a", "b"], [3, 4]]); + + result = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3"}); + test:assertEquals(result, [{'1: 2, '2: 3}]); + + result2 = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3"}); + test:assertEquals(result2, [[1, 2], [2, 3]]); + + result2 = csv:parseLists(csv2, {outputWithHeaders: false, headerRows: 1, skipLines: "2-3"}); + test:assertEquals(result2, [[2, 3]]); + + result = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); + test:assertEquals(result, [{a: 3, b: 4}]); + + result2 = csv:parseLists(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 988e203..de47edf 100644 --- a/ballerina-tests/user-config-tests/tests/user_configs.bal +++ b/ballerina-tests/user-config-tests/tests/user_configs.bal @@ -24,11 +24,11 @@ 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:TransformOptions ptOption1 = {nilValue: "", header: 1, skipLines: [2, 4]}; -csv:TransformOptions ptOption2 = {nilValue: "", header: 1, skipLines: "2-4"}; -csv:TransformOptions ptOption3 = {nilValue: "", header: 4, skipLines: "1-5"}; -csv:TransformOptions ptOption4 = {nilValue: "", header: 4, skipLines: [-1, -2, 4, 2]}; -csv:TransformOptions 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:ParseOptions invalidParserOptions1 = {header: 4}; 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 a516c5a..cb2cedd 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 @@ -249,10 +249,8 @@ public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type e 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; @@ -263,6 +261,11 @@ public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type e continue; } + if (i >= config.headerRows && ignoreRow(rowNumber + 1, config.skipLines)) { + rowNumber++; + continue; + } + rowValue = traverseCsvElementWithMapOrRecord(o, expectedArrayType); if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); @@ -272,6 +275,9 @@ public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type e rootCsvNode.add(this.arraySize, rowValue); this.arraySize++; } + if (i >= config.headerRows) { + rowNumber++; + } } } @@ -280,10 +286,8 @@ public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expe 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; @@ -299,6 +303,11 @@ public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expe continue; } + if (ignoreRow(rowNumber + 1, config.skipLines)) { + rowNumber++; + continue; + } + rowValue = traverseCsvElementWithArray(o, expectedArrayType); if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); @@ -307,6 +316,7 @@ public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expe rootCsvNode.add(this.arraySize, rowValue); this.arraySize++; } + rowNumber++; } } @@ -314,11 +324,9 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, UnionType expectedArrayType, Type type) { Object rowValue; ArrayType arrayType = (ArrayType) rootCsvNode.getType(); + int rowNumber = 0; for (int i = 0; i < length; i++) { boolean isCompatible = false; - if (ignoreRow(i + 1, config.skipLines)) { - continue; - } if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < this.arraySize) { break; @@ -333,6 +341,10 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, if (i < config.headerRows) { continue; } + if (ignoreRow(rowNumber + 1, config.skipLines)) { + rowNumber++; + continue; + } for (Type memberType: expectedArrayType.getMemberTypes()) { boolean isIntersection = false; @@ -375,6 +387,7 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, if (!isCompatible) { throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); } + rowNumber++; } } @@ -447,7 +460,7 @@ private void constructArrayValuesFromMap(BMap map, Type type, BString[] keys = createHeadersForBMap(map, config.headersOrder, map.size()); for (BString key: keys) { if (!map.containsKey(key)) { - throw DiagnosticLog.error(DiagnosticErrorCode.INCONSISTENT_HEADER, key); + throw DiagnosticLog.error(DiagnosticErrorCode.HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED, key); } Object v = map.get(key); if (config.allowDataProjection && index >= expectedSize) { @@ -532,11 +545,14 @@ private void addHeadersForTheListIfApplicable(Object obj, Type type) { String[] headers = new String[array.size()]; this.headers = CsvUtils.createHeadersForParseLists(array, headers, config); } - if (obj instanceof BMap) { - if (config.headersOrder == null) { - return; + if (this.headers == null && obj instanceof BMap) { + BMap map = (BMap) obj; + int size = map.size(); + BString[] headerArray = createHeadersForBMap(map, config.headersOrder, size); + this.headers = new String[size]; + for (int i = 0; i < headerArray.length; i++) { + this.headers[i] = StringUtils.getStringValue(headerArray[i]); } - this.headers = ((BArray) config.headersOrder).getStringArray(); } BArray headersArray; @@ -608,7 +624,7 @@ private Type getArrayOrTupleMemberType(Type type, int index) { private boolean checkExpectedTypeMatchWithHeaders(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; @@ -684,6 +700,10 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType) { private void addValuesToMapType(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) { 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 08cb899..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 @@ -51,7 +51,9 @@ public enum DiagnosticErrorCode { 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"), - NO_CUSTOM_HEADER_PROVIDED("BDE_0027", "no.custom.header.provided"); + 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 525ad49..d653d87 100644 --- a/native/src/main/resources/csv_error.properties +++ b/native/src/main/resources/csv_error.properties @@ -100,4 +100,7 @@ error.cannot.convert.into.exptype=\ The source value cannot convert in to the ''{0}'' error.no.custom.header.provided=\ - Custom headers should be provided \ No newline at end of file + 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 From 9a06dd82a7bdb5e6172ab4cf6d2150416ed5151b Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Thu, 8 Aug 2024 01:05:28 +0530 Subject: [PATCH 118/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 ++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 0bfd723..ed49c87 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,7 +12,8 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"} + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "test"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -26,3 +27,52 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] +[[package]] +org = "ballerina" +name = "lang.__internal" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + +[[package]] +org = "ballerina" +name = "lang.array" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.__internal"} +] + +[[package]] +org = "ballerina" +name = "lang.error" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"} +] + +[[package]] +org = "ballerina" +name = "lang.object" +version = "0.0.0" +scope = "testOnly" + +[[package]] +org = "ballerina" +name = "test" +version = "0.0.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.array"}, + {org = "ballerina", name = "lang.error"} +] +modules = [ + {org = "ballerina", packageName = "test", moduleName = "test"} +] + From 8aaffb8de14bf202e25ffcdc083270f669394024 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Thu, 8 Aug 2024 02:31:11 +0530 Subject: [PATCH 119/147] Add union tests with headers for string source --- ballerina-tests/build.gradle | 22 +- .../tests/test_union_types_with_headers.bal | 216 +++++++++--------- .../lib/data/csvdata/csv/CsvCreator.java | 9 + .../lib/data/csvdata/csv/CsvParser.java | 9 + .../lib/data/csvdata/csv/CsvTraversal.java | 57 +++-- 5 files changed, 170 insertions(+), 143 deletions(-) diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index 41d8c38..42807ca 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -30,25 +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 = [ -// "parse-string-record-types-tests" -// , -// "parse-string-array-types-tests" -// , -"parse-list-types-tests" -// , -// "parse-record-types-tests" -// , -// "user-config-tests" -// , -// "type-compatible-tests" -// , -// "unicode-tests" -// , -// "constraint-validation-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/union-type-tests/tests/test_union_types_with_headers.bal b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal index 98a1138..0ac3844 100644 --- a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal +++ b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal @@ -1,157 +1,159 @@ -// import ballerina/data.csv; -// import ballerina/test; +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: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:ParseOptions op5 = {outputWithHeaders: true}; -// csv:ParseListsOptions op6 = {outputWithHeaders: true}; -// csv:ParseListsOptions op7 = {outputWithHeaders: true, headerRows: 1}; -// csv:ParseListsOptions op8 = {outputWithHeaders: true, headerRows: 2}; -// csv:ParseListsOptions op9 = {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b", "c", "d"]}; -// csv:ParseListsOptions op10 = {outputWithHeaders: true, headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; -// csv:ParseListsOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", "c", "d"]}; -// csv:ParseListsOptions op12 = {headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; -// csv:ParseListsOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListsOptions op6 = {outputWithHeaders: true}; +csv:ParseListsOptions op7 = {outputWithHeaders: true, headerRows: 1}; +csv:ParseListsOptions op8 = {outputWithHeaders: true, headerRows: 2}; +csv:ParseListsOptions op9 = {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListsOptions op10 = {outputWithHeaders: true, headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListsOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListsOptions op12 = {headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListsOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; -// type UnionType1 string[][]|float[][]; +type UnionType1 string[][]|boolean[][]; -// type UnionType2 float[][]|string[][]; +type UnionType2 boolean[][]|string[][]; -// type UnionType3 (float|string)[][]; +type UnionType3 (boolean|string)[][]; -// type UnionType4 [string...][]|[boolean, string, string, string][]; +type UnionType4 [string...][]|[boolean, string, string, string][]; -// type UnionType5 [string, string, string, string][]|[string...][]; +type UnionType5 [string, string, string, string][]|[string...][]; -// type UnionType6 ([string...][]|[string, string, string, string])[]; +type UnionType6 ([string...][]|[string, string, string, string])[]; -// type UnionType7 string[][]|[string...][]; +type UnionType7 string[][]|[string...][]; -// type UnionType8 ([boolean...]|string[])[]; +type UnionType8 ([boolean...]|string[])[]; -// type UnionType9 record {}[]|record {int d1;}[]; +type UnionType9 record {}[]|record {int d1;}[]; -// type UnionType10 record {int d1;}[]|record {}[]; +type UnionType10 record {int d1;}[]|record {}[]; -// type UnionType11 (record {int d1;}|record {})[]; +type UnionType11 (record {int d1;}|record {})[]; -// type UnionType12 map[]|map[]; +type UnionType12 map[]|record {int d1;}[]; -// type UnionType13 map[]|map[]; +type UnionType13 record {int d1;}[]|map[]; -// type UnionType14 (map|map)[]; +type UnionType14 (map|map)[]; -// type UnionType15 (map|map)[]; +type UnionType15 (record {int d1;}|map)[]; -// var 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 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 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 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"]]; -// @test:Config -// function testParseStringWithMapWithOutputHeaders() { -// UnionType9|csv:Error psu9 = csv:parseString(csv3); -// test:assertEquals(psu9, result2); +@test:Config +function testParseStringWithMapWithOutputHeaders() { + UnionType9|csv:Error psu9 = csv:parseString(csv3); + test:assertEquals(psu9, result2); -// psu9 = csv:parseString(csv3, op5); -// test:assertEquals(psu9, result2); + psu9 = csv:parseString(csv3, op5); + test:assertEquals(psu9, result2); -// UnionType10|csv:Error psu10 = csv:parseString(csv3); -// test:assertEquals(psu10, result2); + UnionType10|csv:Error psu10 = csv:parseString(csv3); + test:assertEquals(psu10, result2); -// psu10 = csv:parseString(csv3, op5); -// test:assertEquals(psu10, result2); + psu10 = csv:parseString(csv3, op5); + test:assertEquals(psu10, result2); -// UnionType11|csv:Error psu11 = csv:parseString(csv3); -// test:assertEquals(psu11, result2); + UnionType11|csv:Error psu11 = csv:parseString(csv3); + test:assertEquals(psu11, result2); -// psu11 = csv:parseString(csv3, op5); -// test:assertEquals(psu11, result2); + psu11 = csv:parseString(csv3, op5); + test:assertEquals(psu11, result2); -// UnionType12|csv:Error psu12 = csv:parseString(csv3); -// test:assertEquals(psu12, result2); + UnionType12|csv:Error psu12 = csv:parseString(csv3); + test:assertEquals(psu12, result3); -// psu12 = csv:parseString(csv3, op5); -// test:assertEquals(psu12, result2); + psu12 = csv:parseString(csv3, op5); + test:assertEquals(psu12, result3); -// UnionType13|csv:Error psu13 = csv:parseString(csv3); -// test:assertEquals(psu13, result2); + UnionType13|csv:Error psu13 = csv:parseString(csv3); + test:assertEquals(psu13, result3); -// psu13 = csv:parseString(csv3, op5); -// test:assertEquals(psu13, result2); + psu13 = csv:parseString(csv3, op5); + test:assertEquals(psu13, result3); -// UnionType14|csv:Error psu14 = csv:parseString(csv3); -// test:assertEquals(psu14, result2); + UnionType14|csv:Error psu14 = csv:parseString(csv3); + test:assertEquals(psu14, result3); -// psu14 = csv:parseString(csv3, op5); -// test:assertEquals(psu14, result2); + psu14 = csv:parseString(csv3, op5); + test:assertEquals(psu14, result3); -// UnionType15|csv:Error psu15 = csv:parseString(csv3); -// test:assertEquals(psu15, result2); + UnionType15|csv:Error psu15 = csv:parseString(csv3); + test:assertEquals(psu15, result3); -// psu15 = csv:parseString(csv3, op5); -// test:assertEquals(psu15, result2); -// } + psu15 = csv:parseString(csv3, op5); + test:assertEquals(psu15, result3); +} -// @test:Config -// function testParseStringWithListWithOutputHeaders() { -// UnionType1|csv:Error psu1 = csv:parseString(csv3); -// test:assertEquals(psu1, result4); +@test:Config +function testParseStringWithListWithOutputHeaders() { + UnionType1|csv:Error psu1 = csv:parseString(csv3); + test:assertEquals(psu1, result4); -// psu1 = csv:parseString(csv3, op5); -// test:assertEquals(psu1, result4); + psu1 = csv:parseString(csv3, op5); + test:assertEquals(psu1, result6); -// UnionType2|csv:Error psu2 = csv:parseString(csv3); -// test:assertEquals(psu2, result4); + UnionType2|csv:Error psu2 = csv:parseString(csv3); + test:assertEquals(psu2, result4); -// psu2 = csv:parseString(csv3, op5); -// test:assertEquals(psu2, result4); + psu2 = csv:parseString(csv3, op5); + test:assertEquals(psu2, result6); -// UnionType3|csv:Error psu3 = csv:parseString(csv3); -// test:assertEquals(psu3, result4); + UnionType3|csv:Error psu3 = csv:parseString(csv3); + test:assertEquals(psu3, result4); -// psu3 = csv:parseString(csv3, op5); -// test:assertEquals(psu3, result4); + psu3 = csv:parseString(csv3, op5); + test:assertEquals(psu3, result6); -// UnionType4|csv:Error psu4 = csv:parseString(csv3); -// test:assertEquals(psu4, result4); + UnionType4|csv:Error psu4 = csv:parseString(csv3); + test:assertEquals(psu4, result4); -// psu4 = csv:parseString(csv3, op5); -// test:assertEquals(psu4, result4); + psu4 = csv:parseString(csv3, op5); + test:assertEquals(psu4, result6); -// UnionType5|csv:Error psu5 = csv:parseString(csv3); -// test:assertEquals(psu5, result4); + UnionType5|csv:Error psu5 = csv:parseString(csv3); + test:assertEquals(psu5, result4); -// psu5 = csv:parseString(csv3, op5); -// test:assertEquals(psu5, result4); + psu5 = csv:parseString(csv3, op5); + test:assertEquals(psu5, result6); -// UnionType6|csv:Error psu6 = csv:parseString(csv3); -// test:assertEquals(psu6, result4); + UnionType6|csv:Error psu6 = csv:parseString(csv3); + test:assertEquals(psu6, result4); -// psu6 = csv:parseString(csv3, op5); -// test:assertEquals(psu6, result4); + psu6 = csv:parseString(csv3, op5); + test:assertEquals(psu6, result6); -// UnionType7|csv:Error psu7 = csv:parseString(csv3); -// test:assertEquals(psu7, result4); + UnionType7|csv:Error psu7 = csv:parseString(csv3); + test:assertEquals(psu7, result4); -// psu7 = csv:parseString(csv3, op5); -// test:assertEquals(psu7, result4); + psu7 = csv:parseString(csv3, op5); + test:assertEquals(psu7, result6); -// UnionType8|csv:Error psu8 = csv:parseString(csv3); -// test:assertEquals(psu8, result4); + UnionType8|csv:Error psu8 = csv:parseString(csv3); + test:assertEquals(psu8, result4); -// psu8 = csv:parseString(csv3, op5); -// test:assertEquals(psu8, result4); -// } + psu8 = csv:parseString(csv3, op5); + test:assertEquals(psu8, result6); +} 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 9b37f5b..f468829 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 @@ -75,6 +75,15 @@ static boolean isExpectedTypeIsArray(Type expectedType) { }; } + static boolean isExpectedTypeIsMap(Type expectedType) { + expectedType = TypeUtils.getReferredType(expectedType); + + return switch (expectedType.getTag()) { + case TypeTags.MAP_TAG, TypeTags.RECORD_TYPE_TAG -> true; + default -> false; + }; + } + static void convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, String value, Type type, CsvConfig config, Type exptype, Field currentField) { 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 1329238..5ef1a01 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 @@ -270,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, 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 cb2cedd..767e9a8 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 @@ -145,6 +145,20 @@ void resetForUnionTypes() { arraySize = 0; headersForArrayConversion = null; addHeadersForOutput = false; + isFirstRowIsHeader = false; + } + + void resetForUnionMemberTypes() { + currentCsvNode = null; + currentField = null; + fieldHierarchy.clear(); + updatedRecordFieldNames.clear(); + headerFieldHierarchy.clear(); + fields.clear(); + restType = null; + fieldNames.clear(); + headers = null; + headersForArrayConversion = null; } CsvTree() { @@ -325,6 +339,8 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, Object rowValue; ArrayType arrayType = (ArrayType) rootCsvNode.getType(); int rowNumber = 0; + + outerLoop: for (int i = 0; i < length; i++) { boolean isCompatible = false; if (arrayType.getState() == ArrayType.ArrayState.CLOSED && @@ -333,21 +349,10 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, } Object o = csv.get(i); - if (!addHeadersForOutput && config.outputWithHeaders - && (config.customHeaders != null || i == config.headerRows - 1)) { - // Headers will add to the list only in the first iteration - addHeadersForTheListIfApplicable(o, expectedArrayType); - } - if (i < config.headerRows) { - continue; - } - if (ignoreRow(rowNumber + 1, config.skipLines)) { - rowNumber++; - continue; - } for (Type memberType: expectedArrayType.getMemberTypes()) { boolean isIntersection = false; + resetForUnionMemberTypes(); try { memberType = TypeUtils.getReferredType(memberType); if (memberType.getTag() == TypeTags.INTERSECTION_TAG) { @@ -358,18 +363,36 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, } } - if (memberType.getTag() == TypeTags.MAP_TAG - || memberType.getTag() == TypeTags.RECORD_TYPE_TAG) { + if (CsvCreator.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 = traverseCsvElementWithMapOrRecord(o, memberType); - } else if (memberType.getTag() == TypeTags.TUPLE_TAG - || memberType.getTag() == TypeTags.ARRAY_TAG) { + } else if (CsvCreator.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 + addHeadersForTheListIfApplicable(o, memberType); + } if (i < config.headerRows) { - continue; + continue outerLoop; + } + + if (ignoreRow(rowNumber + 1, config.skipLines)) { + rowNumber++; + continue outerLoop; } rowValue = traverseCsvElementWithArray(o, memberType); } else { continue; } + if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } From 26f2aa4bbc822bfa46d379c51de9a791c2cc4c72 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Thu, 8 Aug 2024 03:16:19 +0530 Subject: [PATCH 120/147] Add union tests for transform api --- .../tests/test_union_types_with_headers.bal | 212 ++++++++++++++++++ 1 file changed, 212 insertions(+) diff --git a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal index 0ac3844..f22bd10 100644 --- a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal +++ b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal @@ -54,6 +54,7 @@ var csv3 = string `a,b,c,d 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}]; @@ -157,3 +158,214 @@ function testParseStringWithListWithOutputHeaders() { psu8 = csv:parseString(csv3, op5); test:assertEquals(psu8, result6); } + +@test:Config +function testTransformWithMapWithOutputHeaders() { + UnionType9|csv:Error psu9 = csv:transform(csv2); + test:assertEquals(psu9, result2); + + psu9 = csv:transform(csv2, op1); + test:assertEquals(psu9, result2); + + psu9 = csv:transform(csv2, op2); + test:assertEquals(psu9, result2); + + psu9 = csv:transform(csv2, op3); + test:assertEquals(psu9, result2); + + psu9 = csv:transform(csv2, op4); + test:assertEquals(psu9, result2); + + UnionType10|csv:Error psu10 = csv:transform(csv2); + test:assertEquals(psu10, result2); + + psu10 = csv:transform(csv2, op1); + test:assertEquals(psu10, result2); + + psu10 = csv:transform(csv2, op2); + test:assertEquals(psu10, result2); + + psu10 = csv:transform(csv2, op3); + test:assertEquals(psu10, result2); + + psu10 = csv:transform(csv2, op4); + test:assertEquals(psu10, result2); + + UnionType11|csv:Error psu11 = csv:transform(csv2); + test:assertEquals(psu11, result2); + + psu11 = csv:transform(csv2, op1); + test:assertEquals(psu11, result2); + + psu11 = csv:transform(csv2, op2); + test:assertEquals(psu11, result2); + + psu11 = csv:transform(csv2, op3); + test:assertEquals(psu11, result2); + + psu11 = csv:transform(csv2, op4); + test:assertEquals(psu11, result2); + + UnionType12|csv:Error psu12 = csv:transform(csv4); + test:assertEquals(psu12, result3); + + psu12 = csv:transform(csv4, op1); + test:assertEquals(psu12, result3); + + psu12 = csv:transform(csv4, op2); + test:assertEquals(psu12, result3); + + psu12 = csv:transform(csv4, op3); + test:assertEquals(psu12, result3); + + psu12 = csv:transform(csv4, op4); + test:assertEquals(psu12, result3); + + UnionType13|csv:Error psu13 = csv:transform(csv4); + test:assertEquals(psu13, result3); + + psu13 = csv:transform(csv4, op1); + test:assertEquals(psu13, result3); + + psu13 = csv:transform(csv4, op2); + test:assertEquals(psu13, result3); + + psu13 = csv:transform(csv4, op3); + test:assertEquals(psu13, result3); + + psu13 = csv:transform(csv4, op4); + test:assertEquals(psu13, result3); + + UnionType14|csv:Error psu14 = csv:transform(csv4); + test:assertEquals(psu14, result3); + + psu14 = csv:transform(csv4, op1); + test:assertEquals(psu14, result3); + + psu14 = csv:transform(csv4, op2); + test:assertEquals(psu14, result3); + + psu14 = csv:transform(csv4, op3); + test:assertEquals(psu14, result3); + + psu14 = csv:transform(csv4, op4); + test:assertEquals(psu14, result3); + + UnionType15|csv:Error psu15 = csv:transform(csv4); + test:assertEquals(psu15, result3); + + psu15 = csv:transform(csv4, op1); + test:assertEquals(psu15, result3); + + psu15 = csv:transform(csv4, op2); + test:assertEquals(psu15, result3); + + psu15 = csv:transform(csv4, op3); + test:assertEquals(psu15, result3); + + psu15 = csv:transform(csv4, op4); + test:assertEquals(psu15, 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); + + psu1 = csv:transform(csv4, op4); + test:assertTrue(psu1 is csv:Error); + test:assertEquals((psu1).message(), "The source value cannot convert in to the 'union_type_tests:UnionType1'"); + + 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); + + UnionType3|csv:Error psu3 = csv:transform(csv4); + test:assertEquals(psu3, result4); + + psu3 = csv:transform(csv4, op1); + test:assertEquals(psu3, result4); + + psu3 = csv:transform(csv4, op2); + test:assertEquals(psu3, result6); + + psu3 = csv:transform(csv4, op3); + test:assertEquals(psu3, result6); + + UnionType4|csv:Error psu4 = csv:transform(csv4); + test:assertEquals(psu4, result4); + + psu4 = csv:transform(csv4, op1); + test:assertEquals(psu4, result4); + + psu4 = csv:transform(csv4, op2); + test:assertEquals(psu4, result6); + + psu4 = csv:transform(csv4, op3); + test:assertEquals(psu4, result6); + + UnionType5|csv:Error psu5 = csv:transform(csv4); + test:assertEquals(psu5, result4); + + psu5 = csv:transform(csv4, op1); + test:assertEquals(psu5, result4); + + psu5 = csv:transform(csv4, op2); + test:assertEquals(psu5, result6); + + psu5 = csv:transform(csv4, op3); + test:assertEquals(psu5, result6); + + UnionType6|csv:Error psu6 = csv:transform(csv4); + test:assertEquals(psu6, result4); + + psu6 = csv:transform(csv4, op1); + test:assertEquals(psu6, result4); + + psu6 = csv:transform(csv4, op2); + test:assertEquals(psu6, result6); + + psu6 = csv:transform(csv4, op3); + test:assertEquals(psu6, result6); + + UnionType7|csv:Error psu7 = csv:transform(csv4); + test:assertEquals(psu7, result4); + + psu7 = csv:transform(csv4, op1); + test:assertEquals(psu7, result4); + + psu7 = csv:transform(csv4, op2); + test:assertEquals(psu7, result6); + + psu7 = csv:transform(csv4, op3); + test:assertEquals(psu7, result6); + + UnionType8|csv:Error psu8 = csv:transform(csv4); + test:assertEquals(psu8, result4); + + psu8 = csv:transform(csv4, op1); + test:assertEquals(psu8, result4); + + psu8 = csv:transform(csv4, op2); + test:assertEquals(psu8, result6); + + psu8 = csv:transform(csv4, op3); + test:assertEquals(psu8, result6); +} From 126092a85d0c0892a6c16388e2069a2c74fbb54f Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Thu, 8 Aug 2024 23:46:43 +0530 Subject: [PATCH 121/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 52 +------------------------------------ 1 file changed, 1 insertion(+), 51 deletions(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ed49c87..0bfd723 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -12,8 +12,7 @@ org = "ballerina" name = "data.csv" version = "0.1.0" dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "test"} + {org = "ballerina", name = "jballerina.java"} ] modules = [ {org = "ballerina", packageName = "data.csv", moduleName = "data.csv"} @@ -27,52 +26,3 @@ modules = [ {org = "ballerina", packageName = "jballerina.java", moduleName = "jballerina.java"} ] -[[package]] -org = "ballerina" -name = "lang.__internal" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.object"} -] - -[[package]] -org = "ballerina" -name = "lang.array" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.__internal"} -] - -[[package]] -org = "ballerina" -name = "lang.error" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"} -] - -[[package]] -org = "ballerina" -name = "lang.object" -version = "0.0.0" -scope = "testOnly" - -[[package]] -org = "ballerina" -name = "test" -version = "0.0.0" -scope = "testOnly" -dependencies = [ - {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "lang.array"}, - {org = "ballerina", name = "lang.error"} -] -modules = [ - {org = "ballerina", packageName = "test", moduleName = "test"} -] - From 63531e69f2d2375bee201cca4d59a8a203bc4044 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Thu, 8 Aug 2024 23:59:26 +0530 Subject: [PATCH 122/147] Add tests for union types --- .../tests/test_union_types_with_headers.bal | 379 ++++++------------ .../lib/data/csvdata/csv/CsvCreator.java | 31 +- .../lib/data/csvdata/csv/CsvParser.java | 21 +- .../lib/data/csvdata/csv/CsvTraversal.java | 141 +++---- .../lib/data/csvdata/utils/CsvUtils.java | 64 ++- 5 files changed, 244 insertions(+), 392 deletions(-) diff --git a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal index f22bd10..b02000f 100644 --- a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal +++ b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal @@ -17,37 +17,15 @@ csv:ParseListsOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", csv:ParseListsOptions op12 = {headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; csv:ParseListsOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; -type UnionType1 string[][]|boolean[][]; +type UnionType1 boolean[][]|string[][]; -type UnionType2 boolean[][]|string[][]; +type UnionType2 ([boolean...]|[string, string...])[]; -type UnionType3 (boolean|string)[][]; +type UnionType3 record {int d1;}[]|record {}[]; -type UnionType4 [string...][]|[boolean, string, string, string][]; +type UnionType4 (map|map)[]; -type UnionType5 [string, string, string, string][]|[string...][]; - -type UnionType6 ([string...][]|[string, string, string, string])[]; - -type UnionType7 string[][]|[string...][]; - -type UnionType8 ([boolean...]|string[])[]; - -type UnionType9 record {}[]|record {int d1;}[]; - -type UnionType10 record {int d1;}[]|record {}[]; - -type UnionType11 (record {int d1;}|record {})[]; - -type UnionType12 map[]|record {int d1;}[]; - -type UnionType13 record {int d1;}[]|map[]; - -type UnionType14 (map|map)[]; - -type UnionType15 (record {int d1;}|map)[]; - -var csv1 = [["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; +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 @@ -62,50 +40,22 @@ var result3 = [{a: "1", b: "2", c: "3", d: "4"}, {a: "5", b: "6", c: "7", d: "8" 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() { - UnionType9|csv:Error psu9 = csv:parseString(csv3); - test:assertEquals(psu9, result2); - - psu9 = csv:parseString(csv3, op5); - test:assertEquals(psu9, result2); - - UnionType10|csv:Error psu10 = csv:parseString(csv3); - test:assertEquals(psu10, result2); - - psu10 = csv:parseString(csv3, op5); - test:assertEquals(psu10, result2); - - UnionType11|csv:Error psu11 = csv:parseString(csv3); - test:assertEquals(psu11, result2); - - psu11 = csv:parseString(csv3, op5); - test:assertEquals(psu11, result2); - - UnionType12|csv:Error psu12 = csv:parseString(csv3); - test:assertEquals(psu12, result3); - - psu12 = csv:parseString(csv3, op5); - test:assertEquals(psu12, result3); - - UnionType13|csv:Error psu13 = csv:parseString(csv3); - test:assertEquals(psu13, result3); - - psu13 = csv:parseString(csv3, op5); - test:assertEquals(psu13, result3); - - UnionType14|csv:Error psu14 = csv:parseString(csv3); - test:assertEquals(psu14, result3); + UnionType3|csv:Error psu3 = csv:parseString(csv3); + test:assertEquals(psu3, result2); - psu14 = csv:parseString(csv3, op5); - test:assertEquals(psu14, result3); + psu3 = csv:parseString(csv3, op5); + test:assertEquals(psu3, result2); - UnionType15|csv:Error psu15 = csv:parseString(csv3); - test:assertEquals(psu15, result3); + UnionType4|csv:Error psu4 = csv:parseString(csv3); + test:assertEquals(psu4, result3); - psu15 = csv:parseString(csv3, op5); - test:assertEquals(psu15, result3); + psu4 = csv:parseString(csv3, op5); + test:assertEquals(psu4, result3); } @test:Config @@ -121,150 +71,39 @@ function testParseStringWithListWithOutputHeaders() { psu2 = csv:parseString(csv3, op5); test:assertEquals(psu2, result6); - - UnionType3|csv:Error psu3 = csv:parseString(csv3); - test:assertEquals(psu3, result4); - - psu3 = csv:parseString(csv3, op5); - test:assertEquals(psu3, result6); - - UnionType4|csv:Error psu4 = csv:parseString(csv3); - test:assertEquals(psu4, result4); - - psu4 = csv:parseString(csv3, op5); - test:assertEquals(psu4, result6); - - UnionType5|csv:Error psu5 = csv:parseString(csv3); - test:assertEquals(psu5, result4); - - psu5 = csv:parseString(csv3, op5); - test:assertEquals(psu5, result6); - - UnionType6|csv:Error psu6 = csv:parseString(csv3); - test:assertEquals(psu6, result4); - - psu6 = csv:parseString(csv3, op5); - test:assertEquals(psu6, result6); - - UnionType7|csv:Error psu7 = csv:parseString(csv3); - test:assertEquals(psu7, result4); - - psu7 = csv:parseString(csv3, op5); - test:assertEquals(psu7, result6); - - UnionType8|csv:Error psu8 = csv:parseString(csv3); - test:assertEquals(psu8, result4); - - psu8 = csv:parseString(csv3, op5); - test:assertEquals(psu8, result6); } @test:Config function testTransformWithMapWithOutputHeaders() { - UnionType9|csv:Error psu9 = csv:transform(csv2); - test:assertEquals(psu9, result2); - - psu9 = csv:transform(csv2, op1); - test:assertEquals(psu9, result2); - - psu9 = csv:transform(csv2, op2); - test:assertEquals(psu9, result2); - - psu9 = csv:transform(csv2, op3); - test:assertEquals(psu9, result2); - - psu9 = csv:transform(csv2, op4); - test:assertEquals(psu9, result2); - - UnionType10|csv:Error psu10 = csv:transform(csv2); - test:assertEquals(psu10, result2); - - psu10 = csv:transform(csv2, op1); - test:assertEquals(psu10, result2); - - psu10 = csv:transform(csv2, op2); - test:assertEquals(psu10, result2); - - psu10 = csv:transform(csv2, op3); - test:assertEquals(psu10, result2); - - psu10 = csv:transform(csv2, op4); - test:assertEquals(psu10, result2); - - UnionType11|csv:Error psu11 = csv:transform(csv2); - test:assertEquals(psu11, result2); - - psu11 = csv:transform(csv2, op1); - test:assertEquals(psu11, result2); - - psu11 = csv:transform(csv2, op2); - test:assertEquals(psu11, result2); + UnionType3|csv:Error psu3 = csv:transform(csv2); + test:assertEquals(psu3, result2); - psu11 = csv:transform(csv2, op3); - test:assertEquals(psu11, result2); + psu3 = csv:transform(csv2, op1); + test:assertEquals(psu3, result2); - psu11 = csv:transform(csv2, op4); - test:assertEquals(psu11, result2); + psu3 = csv:transform(csv2, op2); + test:assertEquals(psu3, result2); - UnionType12|csv:Error psu12 = csv:transform(csv4); - test:assertEquals(psu12, result3); + psu3 = csv:transform(csv2, op3); + test:assertEquals(psu3, result2); - psu12 = csv:transform(csv4, op1); - test:assertEquals(psu12, result3); + psu3 = csv:transform(csv2, op4); + test:assertEquals(psu3, result2); - psu12 = csv:transform(csv4, op2); - test:assertEquals(psu12, result3); - - psu12 = csv:transform(csv4, op3); - test:assertEquals(psu12, result3); - - psu12 = csv:transform(csv4, op4); - test:assertEquals(psu12, result3); - - UnionType13|csv:Error psu13 = csv:transform(csv4); - test:assertEquals(psu13, result3); - - psu13 = csv:transform(csv4, op1); - test:assertEquals(psu13, result3); - - psu13 = csv:transform(csv4, op2); - test:assertEquals(psu13, result3); - - psu13 = csv:transform(csv4, op3); - test:assertEquals(psu13, result3); - - psu13 = csv:transform(csv4, op4); - test:assertEquals(psu13, result3); - - UnionType14|csv:Error psu14 = csv:transform(csv4); - test:assertEquals(psu14, result3); - - psu14 = csv:transform(csv4, op1); - test:assertEquals(psu14, result3); - - psu14 = csv:transform(csv4, op2); - test:assertEquals(psu14, result3); - - psu14 = csv:transform(csv4, op3); - test:assertEquals(psu14, result3); - - psu14 = csv:transform(csv4, op4); - test:assertEquals(psu14, result3); - - UnionType15|csv:Error psu15 = csv:transform(csv4); - test:assertEquals(psu15, result3); + UnionType4|csv:Error psu4 = csv:transform(csv4); + test:assertEquals(psu4, result3); - psu15 = csv:transform(csv4, op1); - test:assertEquals(psu15, result3); + psu4 = csv:transform(csv4, op1); + test:assertEquals(psu4, result3); - psu15 = csv:transform(csv4, op2); - test:assertEquals(psu15, result3); + psu4 = csv:transform(csv4, op2); + test:assertEquals(psu4, result3); - psu15 = csv:transform(csv4, op3); - test:assertEquals(psu15, result3); + psu4 = csv:transform(csv4, op3); + test:assertEquals(psu4, result3); - psu15 = csv:transform(csv4, op4); - test:assertEquals(psu15, result3); + psu4 = csv:transform(csv4, op4); + test:assertEquals(psu4, result3); } @test:Config @@ -281,10 +120,6 @@ function testTransformWithListWithOutputHeaders() { psu1 = csv:transform(csv4, op3); test:assertEquals(psu1, result6); - psu1 = csv:transform(csv4, op4); - test:assertTrue(psu1 is csv:Error); - test:assertEquals((psu1).message(), "The source value cannot convert in to the 'union_type_tests:UnionType1'"); - UnionType2|csv:Error psu2 = csv:transform(csv4); test:assertEquals(psu2, result4); @@ -296,76 +131,124 @@ function testTransformWithListWithOutputHeaders() { psu2 = csv:transform(csv4, op3); test:assertEquals(psu2, result6); +} - UnionType3|csv:Error psu3 = csv:transform(csv4); - test:assertEquals(psu3, result4); +@test:Config +function testParseListWithMapWithOutputHeaders() { + UnionType3|csv:Error psu3 = csv:parseLists(csv1); + test:assertEquals(psu3, result7); - psu3 = csv:transform(csv4, op1); - test:assertEquals(psu3, result4); + psu3 = csv:parseLists(csv1, op6); + test:assertEquals(psu3, result7); - psu3 = csv:transform(csv4, op2); - test:assertEquals(psu3, result6); + psu3 = csv:parseLists(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:transform(csv4, op3); - test:assertEquals(psu3, result6); + psu3 = csv:parseLists(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:transform(csv4); - test:assertEquals(psu4, result4); + UnionType4|csv:Error psu4 = csv:parseLists(csv1); + test:assertEquals(psu4, result8); - psu4 = csv:transform(csv4, op1); - test:assertEquals(psu4, result4); + psu4 = csv:parseLists(csv1, op6); + test:assertEquals(psu4, result8); - psu4 = csv:transform(csv4, op2); - test:assertEquals(psu4, result6); + psu4 = csv:parseLists(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:transform(csv4, op3); - test:assertEquals(psu4, result6); + psu4 = csv:parseLists(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:parseLists(csv1); + test:assertEquals(psu1, result4); + + psu1 = csv:parseLists(csv1, op6); + test:assertEquals(psu1, result4); + + psu1 = csv:parseLists(csv1, op7); + test:assertEquals(psu1, result4); + + psu1 = csv:parseLists(csv1, op9); + test:assertEquals(psu1, [["a","b","c","d"],["9","10","11","12"],["13","14","15","16"]]); + + UnionType2|csv:Error psu2 = csv:parseLists(csv1); + test:assertEquals(psu2, result4); + + psu2 = csv:parseLists(csv1, op6); + test:assertEquals(psu2, result4); + + psu2 = csv:parseLists(csv1, op7); + test:assertEquals(psu2, result4); - UnionType5|csv:Error psu5 = csv:transform(csv4); - test:assertEquals(psu5, result4); + psu2 = csv:parseLists(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:parseLists(csv1); + test:assertEquals(psu3, result7); - psu5 = csv:transform(csv4, op1); - test:assertEquals(psu5, result4); + psu3 = csv:parseLists(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}]); - psu5 = csv:transform(csv4, op2); - test:assertEquals(psu5, result6); + psu3 = csv:parseLists(csv1, op11); + test:assertEquals(psu3, result2); - psu5 = csv:transform(csv4, op3); - test:assertEquals(psu5, result6); + psu3 = csv:parseLists(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}]); - UnionType6|csv:Error psu6 = csv:transform(csv4); - test:assertEquals(psu6, result4); + psu3 = csv:parseLists(csv1, op13); + test:assertEquals(psu3, result2); - psu6 = csv:transform(csv4, op1); - test:assertEquals(psu6, result4); + UnionType4|csv:Error psu4 = csv:parseLists(csv1); + test:assertEquals(psu4, result8); - psu6 = csv:transform(csv4, op2); - test:assertEquals(psu6, result6); + psu4 = csv:parseLists(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"}]); - psu6 = csv:transform(csv4, op3); - test:assertEquals(psu6, result6); + psu4 = csv:parseLists(csv1, op11); + test:assertEquals(psu4, result3); - UnionType7|csv:Error psu7 = csv:transform(csv4); - test:assertEquals(psu7, result4); + psu4 = csv:parseLists(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"}]); - psu7 = csv:transform(csv4, op1); - test:assertEquals(psu7, result4); + psu4 = csv:parseLists(csv1, op13); + test:assertEquals(psu4, result3); +} + +@test:Config +function testParseListWithListWithOutputHeaders2() { + UnionType1|csv:Error psu1 = csv:parseLists(csv1); + test:assertEquals(psu1, result4); - psu7 = csv:transform(csv4, op2); - test:assertEquals(psu7, result6); + psu1 = csv:parseLists(csv1, op10); + test:assertEquals(psu1, [["a","b","c","d"],["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); - psu7 = csv:transform(csv4, op3); - test:assertEquals(psu7, result6); + psu1 = csv:parseLists(csv1, op11); + test:assertEquals(psu1, result6); + + psu1 = csv:parseLists(csv1, op12); + test:assertEquals(psu1, [["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); + + psu1 = csv:parseLists(csv1, op13); + test:assertEquals(psu1, result4); + + UnionType2|csv:Error psu2 = csv:parseLists(csv1); + test:assertEquals(psu2, result4); - UnionType8|csv:Error psu8 = csv:transform(csv4); - test:assertEquals(psu8, result4); + psu2 = csv:parseLists(csv1, op10); + test:assertEquals(psu2, [["a","b","c","d"],["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); - psu8 = csv:transform(csv4, op1); - test:assertEquals(psu8, result4); + psu2 = csv:parseLists(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"]]); - psu8 = csv:transform(csv4, op2); - test:assertEquals(psu8, result6); + psu2 = csv:parseLists(csv1, op12); + test:assertEquals(psu2, [["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); - psu8 = csv:transform(csv4, op3); - test:assertEquals(psu8, result6); + psu2 = csv:parseLists(csv1, op13); + test:assertEquals(psu2, [["1", "2", "3", "4"],["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); } 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 f468829..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 @@ -66,24 +66,6 @@ static Object initRowValue(Type expectedType) { }; } - static boolean isExpectedTypeIsArray(Type expectedType) { - expectedType = TypeUtils.getReferredType(expectedType); - - return switch (expectedType.getTag()) { - case TypeTags.TUPLE_TAG, TypeTags.ARRAY_TAG -> true; - default -> false; - }; - } - - static boolean isExpectedTypeIsMap(Type expectedType) { - expectedType = TypeUtils.getReferredType(expectedType); - - return switch (expectedType.getTag()) { - case TypeTags.MAP_TAG, TypeTags.RECORD_TYPE_TAG -> true; - default -> false; - }; - } - static void convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, String value, Type type, CsvConfig config, Type exptype, Field currentField) { @@ -129,9 +111,7 @@ public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { 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()) { @@ -160,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 5ef1a01..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 @@ -529,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); @@ -616,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(); @@ -668,7 +668,7 @@ private static void initiateNewRowType(StateMachine sm) { } private static void addHeadersAsTheFirstElementForArraysIfApplicable(StateMachine sm) { - if (!sm.addHeadersForOutput && CsvCreator + if (!sm.addHeadersForOutput && CsvUtils .isExpectedTypeIsArray(sm.expectedArrayElementType) && sm.config.outputWithHeaders) { ArrayList headers = sm.headers; if (!headers.isEmpty()) { @@ -695,11 +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 { + private static void addRowValue(StateMachine sm, boolean trim) { Field currentField = null; sm.isValueStart = false; Type exptype = sm.expectedArrayElementType; @@ -824,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++) { @@ -864,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); @@ -928,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 767e9a8..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 @@ -53,8 +53,6 @@ import java.util.Map; import java.util.Optional; -import static io.ballerina.lib.data.csvdata.csv.CsvCreator.isExpectedTypeIsArray; - /** * Convert Csv value to a ballerina record. * @@ -108,6 +106,7 @@ private static class CsvTree { BString[] headersForArrayConversion = null; boolean addHeadersForOutput = false; boolean isFirstRowIsHeader = false; + boolean isFirstRowInserted = false; void reset() { currentCsvNode = null; @@ -127,6 +126,7 @@ void reset() { headersForArrayConversion = null; addHeadersForOutput = false; isFirstRowIsHeader = false; + isFirstRowInserted = false; } @@ -146,6 +146,7 @@ void resetForUnionTypes() { headersForArrayConversion = null; addHeadersForOutput = false; isFirstRowIsHeader = false; + isFirstRowInserted = false; } void resetForUnionMemberTypes() { @@ -168,7 +169,7 @@ void resetForUnionMemberTypes() { @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) { @@ -179,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(); } @@ -193,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) { @@ -280,7 +281,7 @@ public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type e continue; } - rowValue = traverseCsvElementWithMapOrRecord(o, expectedArrayType); + rowValue = initStatesForCsvRowWithMappingAsExpectedType(o, expectedArrayType); if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } @@ -311,7 +312,7 @@ public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expe 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 - addHeadersForTheListIfApplicable(o, expectedArrayType); + insertHeaderValuesForTheCsvIfApplicable(o, expectedArrayType); } if (i < config.headerRows) { continue; @@ -322,7 +323,7 @@ public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expe continue; } - rowValue = traverseCsvElementWithArray(o, expectedArrayType); + rowValue = initStatesForCsvRowWithListAsExpectedType(o, expectedArrayType); if (isIntersection) { rowValue = CsvCreator.constructReadOnlyValue(rowValue); } @@ -343,6 +344,7 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, outerLoop: for (int i = 0; i < length; i++) { boolean isCompatible = false; + this.isFirstRowIsHeader = false; if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < this.arraySize) { break; @@ -352,7 +354,6 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, for (Type memberType: expectedArrayType.getMemberTypes()) { boolean isIntersection = false; - resetForUnionMemberTypes(); try { memberType = TypeUtils.getReferredType(memberType); if (memberType.getTag() == TypeTags.INTERSECTION_TAG) { @@ -363,7 +364,7 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, } } - if (CsvCreator.isExpectedTypeIsMap(memberType)) { + if (CsvUtils.isExpectedTypeIsMap(memberType)) { if (i < config.headerRows && i != config.headerRows - 1) { continue outerLoop; } @@ -372,13 +373,13 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, rowNumber++; continue outerLoop; } - rowValue = traverseCsvElementWithMapOrRecord(o, memberType); - } else if (CsvCreator.isExpectedTypeIsArray(memberType)) { + 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 - addHeadersForTheListIfApplicable(o, memberType); + insertHeaderValuesForTheCsvIfApplicable(o, memberType); } if (i < config.headerRows) { continue outerLoop; @@ -388,7 +389,7 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, rowNumber++; continue outerLoop; } - rowValue = traverseCsvElementWithArray(o, memberType); + rowValue = initStatesForCsvRowWithListAsExpectedType(o, memberType); } else { continue; } @@ -404,7 +405,7 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, isCompatible = true; break; } catch (Exception e) { - // ignore + resetForUnionMemberTypes(); } } if (!isCompatible) { @@ -424,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: @@ -436,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); @@ -449,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); @@ -469,18 +470,18 @@ 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 constructArrayValuesFromMap(BMap map, Type type, int expectedSize) { + private void constructCsvArrayFromMapping(BMap map, Type type, int expectedSize) { int index = 0; - BString[] keys = createHeadersForBMap(map, config.headersOrder, map.size()); + 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); @@ -489,65 +490,67 @@ private void constructArrayValuesFromMap(BMap map, Type type, if (config.allowDataProjection && index >= expectedSize) { break; } - Type memberType = getArrayOrTupleMemberType(type, index); + Type memberType = getTheElementTypeFromList(type, index); if (memberType != null) { - addValuesToArrayType(v, memberType, index, currentCsvNode); + insertValuesIntoList(v, memberType, index, currentCsvNode); } index++; } } - private void constructArrayValuesFromArray(BArray csvElement, Type type, int expectedSize) { + 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; } - Type memberType = getArrayOrTupleMemberType(type, index); + Type memberType = getTheElementTypeFromList(type, index); if (memberType != null) { - addValuesToArrayType(csvElement.get(i), memberType, index, currentCsvNode); + insertValuesIntoList(csvElement.get(i), memberType, index, currentCsvNode); } index++; } } - private void traverseCsvMap(Object csvElement, Type expectedType, boolean mappingType) { + private void traverseCsvRowWithMappingAsExpectedType(Object csvElement, + Type expectedType, boolean mappingType) { if (csvElement instanceof BMap map) { - traverseMapValueWithMapAsExpectedType(map, mappingType, expectedType); + constructCsvMapFromMapping(map, mappingType, expectedType); } else if (csvElement instanceof BArray array) { - traverseArrayValueWithMapAsExpectedType(array, mappingType, expectedType); + constructCsvMapFromNonMapping(array, mappingType, expectedType); } else { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CSV_DATA_FORMAT); } } - private void traverseArrayValueWithMapAsExpectedType(BArray csvElement, - boolean mappingType, Type expectedType) { + 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 (config.headerRows >= 1) { + 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 = checkExpectedTypeMatchWithHeaders(expectedType, csvElement, arraySize); + boolean headersMatchWithExpType = validateHeaders(expectedType, csvElement, arraySize); if (!headersMatchWithExpType) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONVERSION_FOR_ARRAY_TO_MAP, csvElement, expectedType); } - addValuesToMapType(csvElement, arraySize, mappingType, expectedType); + constructCsvMappingRow(csvElement, arraySize, mappingType, expectedType); } - private void traverseMapValueWithMapAsExpectedType( + private void constructCsvMapFromMapping( BMap map, boolean mappingType, Type expType) { Type currentFieldType; for (BString key : map.getKeys()) { if (!mappingType) { - if (!isKeyBelongsToNonRestType(map.get(key), key)) { + if (!isMappingKeyBelongsToNonRestType(map.get(key), key)) { continue; } currentFieldType = TypeUtils.getReferredType(currentField.getFieldType()); @@ -557,13 +560,13 @@ private void traverseMapValueWithMapAsExpectedType( ((MapType) expType).getConstrainedType() ); } - addCurrentFieldValue(currentFieldType, map.get(key), key, mappingType); + insertCurrentFieldMemberIntoMapping(currentFieldType, map.get(key), key, mappingType); } CsvUtils.checkRequiredFieldsAndLogError(fieldHierarchy, config.absentAsNilableType); } - private void addHeadersForTheListIfApplicable(Object obj, Type type) { - if (config.outputWithHeaders && isExpectedTypeIsArray(type)) { + 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); @@ -571,7 +574,7 @@ private void addHeadersForTheListIfApplicable(Object obj, Type type) { if (this.headers == null && obj instanceof BMap) { BMap map = (BMap) obj; int size = map.size(); - BString[] headerArray = createHeadersForBMap(map, config.headersOrder, 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]); @@ -586,9 +589,9 @@ private void addHeadersForTheListIfApplicable(Object obj, Type type) { } for (int i = 0; i < this.headers.length; i++) { - Type memberType = getArrayOrTupleMemberType(type, i); + Type memberType = getTheElementTypeFromList(type, i); if (memberType != null) { - addValuesToArrayType(StringUtils.fromString(headers[i]), memberType, i, headersArray); + insertValuesIntoList(StringUtils.fromString(headers[i]), memberType, i, headersArray); } } @@ -600,7 +603,7 @@ private void addHeadersForTheListIfApplicable(Object obj, Type type) { } } - private BString[] createHeadersForBMap(BMap map, Object headersOrder, int size) { + private BString[] generateCsvHeadersForMappingRow(BMap map, Object headersOrder, int size) { BString[] keys = new BString[size]; if (headersOrder != null) { String[] headerOrder = ((BArray) headersOrder).getStringArray(); @@ -619,7 +622,7 @@ private BString[] createHeadersForBMap(BMap map, Object headers 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) { @@ -645,7 +648,7 @@ private Type getArrayOrTupleMemberType(Type type, int index) { return arrayType.getElementType(); } - private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, BArray csvElement, int arraySize) { + private boolean validateHeaders(Type expectedType, BArray csvElement, int arraySize) { if (arraySize < this.headers.length) { throw DiagnosticLog.error(DiagnosticErrorCode.HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED); } @@ -654,13 +657,13 @@ private boolean checkExpectedTypeMatchWithHeaders(Type expectedType, BArray csvE } 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(); @@ -703,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; @@ -720,7 +723,7 @@ private boolean checkExpectedTypeMatchWithHeadersForArray(Type expectedType) { return false; } - 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) { @@ -730,7 +733,7 @@ private void addValuesToMapType(BArray csvElement, int arraySize, boolean mappin 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()); @@ -738,12 +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); + 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)); @@ -752,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) { @@ -768,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() @@ -814,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; } @@ -831,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; @@ -842,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; @@ -862,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) { @@ -889,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/utils/CsvUtils.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java index e0adecb..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,30 +43,33 @@ public static void validateExpectedArraySize(int size, int currentSize) { } } + 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 boolean isExpectedTypeIsMap(Type expectedType) { + expectedType = TypeUtils.getReferredType(expectedType); + + return switch (expectedType.getTag()) { + case TypeTags.MAP_TAG, TypeTags.RECORD_TYPE_TAG -> true; + default -> false; + }; + } + 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; - } + 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) { @@ -171,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; } @@ -303,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) { @@ -326,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; } From b17d86a1eabdee92adaf4d9527ed0dabc9508672 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Fri, 9 Aug 2024 02:16:20 +0530 Subject: [PATCH 123/147] Update compiler plugin tests with new api changes --- .../csvdata/compiler/CompilerPluginTest.java | 35 ++++-- .../sample_package_1/main.bal | 38 ++++-- .../sample_package_4/main.bal | 6 +- .../sample_package_6/main.bal | 6 +- .../lib/data/csvdata/compiler/Constants.java | 15 +-- .../compiler/CsvDataDiagnosticCodes.java | 6 +- .../compiler/CsvDataTypeValidator.java | 116 +++++++++++++----- 7 files changed, 153 insertions(+), 69 deletions(-) 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 90ed76f..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,15 +39,19 @@ 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(enabled = false) + @Test public void testInvalidExpectedUnionType() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_1").getCompilation().diagnosticResult(); 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,9 +62,23 @@ 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(enabled = false) + @Test public void testInvalidRecordFields() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_2").getCompilation().diagnosticResult(); @@ -68,7 +89,7 @@ public void testInvalidRecordFields() { Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), DUPLICATE_FIELD); } - @Test(enabled = false) + @Test public void testInvalidProgram() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_3").getCompilation().diagnosticResult(); @@ -78,7 +99,7 @@ public void testInvalidProgram() { Assert.assertEquals(errorDiagnosticsList.size(), 1); } - @Test(enabled = false) + @Test public void testModuleLevelInvalidExpectedUnionType() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_4").getCompilation().diagnosticResult(); @@ -98,7 +119,7 @@ public void testModuleLevelInvalidExpectedUnionType() { Assert.assertEquals(errorDiagnosticsList.get(9).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); } - @Test(enabled = false) + @Test public void testEmptyProject() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_5").getCompilation().diagnosticResult(); @@ -108,7 +129,7 @@ public void testEmptyProject() { Assert.assertEquals(errorDiagnosticsList.size(), 0); } - @Test(enabled = false) + @Test public void testInvalidExpectedUnionType2() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_6").getCompilation().diagnosticResult(); 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 c7be3c5..8943e55 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: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:parseLists([], {}); - [record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); - [record{}, record{}, record{}, record{}] val10 = check csv:parseLists([], [], {}); - record{}[2] val11 = check csv:parseLists([], [], {}); - int[3][2] val12 = check csv:parseLists([], {}); + [[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:parseLists([], {}); + [record{}, record{}, record{}, record{}] _ = check csv:transform([{}], {}); + [record{}, record{}, record{}, record{}] _ = check csv:parseLists([], {}); + record{record{} a;}[] _ = check csv:parseLists([], {}); + record{int[] a;}[] _ = check csv:parseLists([], {}); + record{[int...] a;}[] _ = check csv:parseLists([], {}); + record{[int...] a;}[] _ = check csv:parseLists([], {}); + record{record{} a;}[] _ = check csv:parseLists([], {}); + record{xml a; regexp:RegExp b;}[] _ = check csv:parseLists([], {}); + [xml, xml][] _ = check csv:parseLists([], {}); + [regexp:RegExp, xml, int[]][] _ = check csv:parseLists([], {}); + [regexp:RegExp, xml, int[]][]|int[][] _ = check csv:parseLists([], {}); + int[][]|[regexp:RegExp, xml, int[]][] _ = check csv:parseLists([], {}); + int[][]|[record{}|regexp:RegExp][] _ = check csv:parseLists([], {}); + record{}[]|int[][] _ = check csv:parseLists([], {}); + record{}[2] _ = check csv:parseLists([], {}); + int[3][2] _ = check csv:parseLists([], {}); } 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 e544c52..bfeeb9f 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 @@ -9,9 +9,9 @@ stream s = ( [[1, 2, 3, 4, 5]]).toStream(); [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[][]|[[int, string], [int, string]] val7 = check csv:transform([{}], {}); [[int, string], [int, string]] val8 = check csv:parseLists([], {}); [record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); -[record{}, record{}, record{}, record{}] val10 = check csv:parseLists([], [], {}); -record{}[2] val11 = check csv:parseLists([], [], {}); +[record{}, record{}, record{}, record{}] val10 = check csv:parseLists([], {}); +record{}[2] val11 = check csv:parseLists([], {}); int[3][2] val12 = check csv:parseLists([], {}); 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 feb1a8c..b5ec5a8 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 @@ -15,10 +15,10 @@ public function test() returns error? { [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[][]|[[int, string], [int, string]] val7 = check csv:transform([{}], {}); [[int, string], [int, string]] val8 = check csv:parseLists([], {}); [record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); - [record{}, record{}, record{}, record{}] val10 = check csv:parseLists([], [], {}); - record{}[2] val11 = check csv:parseLists([], [], {}); + [record{}, record{}, record{}, record{}] val10 = check csv:parseLists([], {}); + record{}[2] val11 = check csv:parseLists([], {}); int[3][2] val12 = check csv:parseLists([], {}); } 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 36ce88e..348a97f 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 = "parseString"; - static final String PARSE_BYTES_TO_RECORD = "parseBytes"; - static final String PARSE_STREAM_TO_RECORD = "parseStream"; - static final String PARSE_STRING_TO_LIST = "parseString"; - static final String PARSE_BYTES_TO_LIST = "parseBytes"; - static final String PARSE_STREAM_TO_LIST = "parseStream"; - static final String PARSE_RECORD_AS_RECORD_TYPE = "transform"; - static final String PARSE_RECORD_AS_LIST_TYPE = "transform"; - static final String PARSE_LIST_AS_RECORD_TYPE = "parseLists"; - static final String PARSE_LIST_AS_LIST_TYPE = "parseLists"; + 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 = "parseLists"; 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..d3fa376 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,102 @@ 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) { 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) { + TupleTypeSymbol tupleTypeSymbol = (TupleTypeSymbol) typeSymbol; + List typeSymbols = tupleTypeSymbol.memberTypeDescriptors(); + tupleTypeSymbol.restTypeDescriptor().ifPresent(typeSymbols::add); + typeSymbols.forEach(symbol -> validateNestedTypeSymbols(ctx, currentLocation, symbol, false)); + } + + private void validateRecordFields(SyntaxNodeAnalysisContext ctx, Location currentLocation, TypeSymbol typeSymbol) { + 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 +323,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) { @@ -353,4 +392,17 @@ private boolean isCsvDataImport(ModuleSymbol moduleSymbol) { return Constants.BALLERINA.equals(moduleId.orgName()) && Constants.DATA_CSVDATA.equals(moduleId.moduleName()); } + + private boolean isComplexSymbolKind(TypeDescKind kind) { + 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 -> { + return true; + } + default -> { + return false; + } + } + } } From e336a7a0b412e63be238ce225be9039a7f467534 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Fri, 9 Aug 2024 03:07:32 +0530 Subject: [PATCH 124/147] Add constrained validation tests for lists --- .../tests/constraint_validation_test.bal | 46 +++++++++++++++++++ .../compiler/CsvDataTypeValidator.java | 32 ++++++------- 2 files changed, 62 insertions(+), 16 deletions(-) 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 e58c5c1..c1266b6 100644 --- a/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal +++ b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal @@ -30,6 +30,52 @@ 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:parseLists([["1"], ["2"], ["3"], ["4"]], {customHeaders: ["a", "b", "c", "d"]}); + test:assertEquals(cList1, [[1], [2], [3], [4]]); + + cList1 = csv:parseLists([["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:parseString(string `a,b 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 d3fa376..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 @@ -226,6 +226,9 @@ private void validateUnionType(UnionTypeSymbol unionTypeSymbol, 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(); @@ -245,13 +248,23 @@ private boolean isSupportedArrayMemberType(SyntaxNodeAnalysisContext ctx, } private void validateTupleMembers(SyntaxNodeAnalysisContext ctx, Location currentLocation, TypeSymbol typeSymbol) { + if (typeSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { + typeSymbol = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor(); + } TupleTypeSymbol tupleTypeSymbol = (TupleTypeSymbol) typeSymbol; - List typeSymbols = tupleTypeSymbol.memberTypeDescriptors(); - tupleTypeSymbol.restTypeDescriptor().ifPresent(typeSymbols::add); - typeSymbols.forEach(symbol -> validateNestedTypeSymbols(ctx, currentLocation, symbol, false)); + 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 -> @@ -392,17 +405,4 @@ private boolean isCsvDataImport(ModuleSymbol moduleSymbol) { return Constants.BALLERINA.equals(moduleId.orgName()) && Constants.DATA_CSVDATA.equals(moduleId.moduleName()); } - - private boolean isComplexSymbolKind(TypeDescKind kind) { - 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 -> { - return true; - } - default -> { - return false; - } - } - } } From 91d9a3d02fb92e5b25b8893c860228fc74d9dc2c Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Fri, 9 Aug 2024 03:25:46 +0530 Subject: [PATCH 125/147] Rename parse list api --- README.md | 2 +- .../tests/constraint_validation_test.bal | 10 +- .../tests/parse_list_type_as_list_test.bal | 202 ++++++------ .../tests/parse_list_type_as_record_test.bal | 290 +++++++++--------- .../tests/parse_record_type_as_list_test.bal | 4 +- .../tests/parse_type_compatibility_test.bal | 28 +- .../tests/test_union_types_with_headers.bal | 88 +++--- .../tests/test_with_intersection_types.bal | 22 +- .../tests/test_with_singleton_test.bal | 12 +- .../tests/test_with_union_types.bal | 114 +++---- .../tests/user_config_projection_tests.bal | 50 +-- .../user_config_with_parser_options_test.bal | 42 +-- ballerina/Package.md | 2 +- ballerina/csv_api.bal | 10 +- ballerina/types.bal | 5 +- .../sample_package_1/main.bal | 32 +- .../sample_package_4/main.bal | 8 +- .../sample_package_6/main.bal | 8 +- .../lib/data/csvdata/compiler/Constants.java | 2 +- .../lib/data/csvdata/csv/Native.java | 4 +- 20 files changed, 468 insertions(+), 467 deletions(-) diff --git a/README.md b/README.md index 08f9f82..181d189 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ type Book record { public function main() returns error? { string[][] bookArray = [["Clean Code","2008"],["Clean Architecture","2017"]]; - Book[] author = check csv:parseLists(bookArray, customHeaders = ["name", "year"]); + Book[] author = check csv:parseList(bookArray, customHeaders = ["name", "year"]); io:println(author); } ``` 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 c1266b6..de74848 100644 --- a/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal +++ b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal @@ -67,10 +67,10 @@ function testConstraintWithLists() returns error? { test:assertTrue((cList1).message().startsWith("Validation failed") && (cList1).message().includes("length")); - cList1 = csv:parseLists([["1"], ["2"], ["3"], ["4"]], {customHeaders: ["a", "b", "c", "d"]}); + cList1 = csv:parseList([["1"], ["2"], ["3"], ["4"]], {customHeaders: ["a", "b", "c", "d"]}); test:assertEquals(cList1, [[1], [2], [3], [4]]); - cList1 = csv:parseLists([["1"], ["2"], ["3"], ["4"], ["5"], ["6"]], {customHeaders: ["a", "b", "c", "d"]}); + 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")); @@ -115,15 +115,15 @@ function testConstraintWithRecords() returns error? { test:assertTrue((cRec1).message().startsWith("Validation failed") && (cRec1).message().includes("minLength")); - cRec1 = csv:parseLists([["4", "abc"], ["3", "cde"]], {customHeaders: ["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:parseLists([["4", "abc"], ["11", "cde"]], {customHeaders: ["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:parseLists([["4", "abc"], ["5", "b"]], {customHeaders: ["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/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 8a1a61a..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:parseLists([st1, st1], {}, StringTuple1Array); + StringTuple1Array|csv:Error st1st1 = csv:parseList([st1, st1], {}, StringTuple1Array); test:assertEquals(st1st1, [ [s1, s2, "", ""], [s1, s2, "", ""] ]); - StringTuple1Array|csv:Error st2st1 = csv:parseLists([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:parseLists([st3, st3], {}, StringTuple1Array); + StringTuple1Array|csv:Error st3st1 = csv:parseList([st3, st3], {}, StringTuple1Array); test:assertEquals(st3st1, [ [s1, s2, "", ""], [s1, s2, "", ""] ]); - StringTuple1Array|csv:Error st4st1 = csv:parseLists([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:parseLists([st1, st1], {}, StringTuple2Array); + StringTuple2Array|csv:Error st1st2 = csv:parseList([st1, st1], {}, StringTuple2Array); test:assertEquals(st1st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|csv:Error st2st2 = csv:parseLists([st2, st2], {}, StringTuple2Array); + StringTuple2Array|csv:Error st2st2 = csv:parseList([st2, st2], {}, StringTuple2Array); test:assertEquals(st2st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|csv:Error st3st2 = csv:parseLists([st3, st3], {}, StringTuple2Array); + StringTuple2Array|csv:Error st3st2 = csv:parseList([st3, st3], {}, StringTuple2Array); test:assertEquals(st3st2, [ [s1, s2], [s1, s2] ]); - StringTuple2Array|csv:Error st4st2 = csv:parseLists([st4, st4], {}, StringTuple2Array); + StringTuple2Array|csv:Error st4st2 = csv:parseList([st4, st4], {}, StringTuple2Array); test:assertEquals(st4st2, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|csv:Error st1st3 = csv:parseLists([st1, st1], {}, StringTuple3Array); + StringTuple3Array|csv:Error st1st3 = csv:parseList([st1, st1], {}, StringTuple3Array); test:assertEquals(st1st3, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|csv:Error st2st3 = csv:parseLists([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:parseLists([st3, st3], {}, StringTuple3Array); + StringTuple3Array|csv:Error st3st3 = csv:parseList([st3, st3], {}, StringTuple3Array); test:assertEquals(st3st3, [ [s1, s2], [s1, s2] ]); - StringTuple3Array|csv:Error st4st3 = csv:parseLists([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:parseLists([st1, st1], {}, StringTuple4Array); + StringTuple4Array|csv:Error st1st4 = csv:parseList([st1, st1], {}, StringTuple4Array); test:assertEquals(st1st4, [ [s1, s2], [s1, s2] ]); - StringTuple4Array|csv:Error st2st4 = csv:parseLists([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:parseLists([st3, st3], {}, StringTuple4Array); + StringTuple4Array|csv:Error st3st4 = csv:parseList([st3, st3], {}, StringTuple4Array); test:assertEquals(st3st4, [ [s1, s2], [s1, s2] ]); - StringTuple4Array|csv:Error st4st4 = csv:parseLists([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:parseLists([st1, st1], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error st1anydt3 = csv:parseList([st1, st1], {}, AnydataTuple3Array); test:assertEquals(st1anydt3, [ [s1, s2], [s1, s2] ]); - AnydataTuple3Array|csv:Error st2anydt3 = csv:parseLists([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:parseLists([st3, st3], {}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error st3anydt3 = csv:parseList([st3, st3], {}, AnydataTuple3Array); test:assertEquals(st3anydt3, [ [s1, s2], [s1, s2] ]); - AnydataTuple3Array|csv:Error st4anydt3 = csv:parseLists([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:parseLists([st1, st1], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error st1jt3 = csv:parseList([st1, st1], {}, JsonTuple3Array); test:assertEquals(st1jt3, [ [s1, s2], [s1, s2] ]); - JsonTuple3Array|csv:Error st2jt3 = csv:parseLists([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:parseLists([st3, st3], {}, JsonTuple3Array); + JsonTuple3Array|csv:Error st3jt3 = csv:parseList([st3, st3], {}, JsonTuple3Array); test:assertEquals(st3jt3, [ [s1, s2], [s1, s2] ]); - JsonTuple3Array|csv:Error st4jt3 = csv:parseLists([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:parseLists([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:parseLists([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:parseLists([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:parseLists([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:parseLists([["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:parseLists( + [(), 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:parseLists( + [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:parseLists( + [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:parseLists( + [(), 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:parseLists( + [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:parseLists( + [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:parseLists( + [(), 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:parseLists( + [()...][]|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:parseLists( + [string...][]|csv:Error ct1bt13 = csv:parseList( [["1", "a"], ["1", "a"]]); test:assertEquals(ct1bt13, [ ["1", "a"], ["1", "a"] ]); - [boolean...][]|csv:Error ct1bt14 = csv:parseLists( + [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:parseLists( + int?[][]|csv:Error ct1bt15 = csv:parseList( [["1", "()"], ["1", "2"]]); test:assertEquals(ct1bt15, [ [1, ()], [1, 2] ]); - int[][]|csv:Error ct1bt16 = csv:parseLists( + 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:parseLists( + 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:parseLists([st1, st1], {}, StringArrayArray); + StringArrayArray|csv:Error st1saa = csv:parseList([st1, st1], {}, StringArrayArray); test:assertEquals(st1saa, [ [s1, s2], [s1, s2] ]); - StringArrayArray|csv:Error st2saa = csv:parseLists([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:parseLists([st3, st3], {}, StringArrayArray); + StringArrayArray|csv:Error st3saa = csv:parseList([st3, st3], {}, StringArrayArray); test:assertEquals(st3saa, [ [s1, s2], [s1, s2] ]); - StringArrayArray|csv:Error st4saa = csv:parseLists([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:parseLists([st1, st1], {}, NillableStringArrayArray); + NillableStringArrayArray|csv:Error st1nsaa = csv:parseList([st1, st1], {}, NillableStringArrayArray); test:assertEquals(st1nsaa, [ [s1, s2], [s1, s2] ]); - NillableStringArrayArray|csv:Error st2nsaa = csv:parseLists([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:parseLists([st3, st3], {}, NillableStringArrayArray); + NillableStringArrayArray|csv:Error st3nsaa = csv:parseList([st3, st3], {}, NillableStringArrayArray); test:assertEquals(st3nsaa, [ [s1, s2], [s1, s2] ]); - NillableStringArrayArray|csv:Error st4nsaa = csv:parseLists([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:parseLists([st1, st1], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|csv:Error st1nsuiaa = csv:parseList([st1, st1], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st1nsuiaa, [ [s1, s2], [s1, s2] @@ -332,101 +332,101 @@ function testFromCsvWithTypeForTupleAndArrayAsExpectedType() { @test:Config function testFromCsvWithTypeForTupleAndTupleAsExpectedType4() { - NillableIntOrUnionStringArrayArray|csv:Error st2nsuiaa = csv:parseLists([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:parseLists([st3, st3], {}, NillableIntOrUnionStringArrayArray); + NillableIntOrUnionStringArrayArray|csv:Error st3nsuiaa = csv:parseList([st3, st3], {}, NillableIntOrUnionStringArrayArray); test:assertEquals(st3nsuiaa, [ [s1, s2], [s1, s2] ]); - NillableIntOrUnionStringArrayArray|csv:Error st4nsuiaa = csv:parseLists([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:parseLists([st1, st1], {}, StringArray2Array); + StringArray2Array|csv:Error st1saa2 = csv:parseList([st1, st1], {}, StringArray2Array); test:assertEquals(st1saa2, [ [s1, s2], [s1, s2] ]); - StringArray2Array|csv:Error st2saa2 = csv:parseLists([st2, st2], {}, StringArray2Array); + StringArray2Array|csv:Error st2saa2 = csv:parseList([st2, st2], {}, StringArray2Array); test:assertEquals(st2saa2, [ [s1, s2], [s1, s2] ]); - StringArray2Array|csv:Error st3saa2 = csv:parseLists([st3, st3], {}, StringArray2Array); + StringArray2Array|csv:Error st3saa2 = csv:parseList([st3, st3], {}, StringArray2Array); test:assertEquals(st3saa2, [ [s1, s2], [s1, s2] ]); - StringArray2Array|csv:Error st4saa2 = csv:parseLists([st4, st4], {}, StringArray2Array); + StringArray2Array|csv:Error st4saa2 = csv:parseList([st4, st4], {}, StringArray2Array); test:assertEquals(st4saa2, [ [s1, s2], [s1, s2] ]); - JsonArray1Array|csv:Error st1jaa = csv:parseLists([st1, st1], {}, JsonArray1Array); + JsonArray1Array|csv:Error st1jaa = csv:parseList([st1, st1], {}, JsonArray1Array); test:assertEquals(st1jaa, [ [s1, s2], [s1, s2] ]); - JsonArray1Array|csv:Error st2jaa = csv:parseLists([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:parseLists([st3, st3], {}, JsonArray1Array); + JsonArray1Array|csv:Error st3jaa = csv:parseList([st3, st3], {}, JsonArray1Array); test:assertEquals(st3jaa, [ [s1, s2], [s1, s2] ]); - JsonArray1Array|csv:Error st4jaa = csv:parseLists([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:parseLists([st1, st1], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error st1anyda = csv:parseList([st1, st1], {}, AnydataArray1Array); test:assertEquals(st1anyda, [ [s1, s2], [s1, s2] ]); - AnydataArray1Array|csv:Error st2anyda = csv:parseLists([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:parseLists([st3, st3], {}, AnydataArray1Array); + AnydataArray1Array|csv:Error st3anyda = csv:parseList([st3, st3], {}, AnydataArray1Array); test:assertEquals(st3anyda, [ [s1, s2], [s1, s2] ]); - AnydataArray1Array|csv:Error st4anyda = csv:parseLists([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:parseLists([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:parseLists([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")); } @@ -435,13 +435,13 @@ function testFromCsvWithTypeForTupleAndTupleAsExpectedType4() { function testArrayIndexes() { string[][] csv = [["1", "2", "3"], ["3", "4", "5"], ["5", "6", "7"], ["7", "8", "9"]]; - [int, int][2]|csv:Error rec3_2 = csv:parseLists(csv); + [int, int][2]|csv:Error rec3_2 = csv:parseList(csv); test:assertEquals(rec3_2, [ [1, 2], [3, 4] ]); - int[2][]|csv:Error rec5 = csv:parseLists(csv); + int[2][]|csv:Error rec5 = csv:parseList(csv); test:assertEquals(rec5, [ [1, 2, 3], [3, 4, 5] @@ -450,160 +450,160 @@ function testArrayIndexes() { @test:Config function testParseListsWithOutputHeaders() { - [string, boolean, int][]|csv:Error ct1bt1 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); + [string, boolean, int][]|csv:Error ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); test:assertEquals(ct1bt1, [ ["a", true, 1] ]); - ct1bt1 = csv:parseLists([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); + ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); test:assertEquals(ct1bt1, []); - ct1bt1 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1, [ ["a", true, 1] ]); - ct1bt1 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21}); + ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21}); test:assertEquals(ct1bt1, []); - (string|boolean|int)[][]|csv:Error ct1bt1_2 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); + (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:parseLists([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); + ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); test:assertEquals(ct1bt1_2, []); - ct1bt1_2 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1_2, [ ["a", true, 1] ]); - ct1bt1_2 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1_2, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1_2 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21}); + ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21}); test:assertEquals(ct1bt1_2, []); - [string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); + [string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_3, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1_3 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, outputWithHeaders: true}); + 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:parseLists([["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), "Custom headers should be provided"); - ct1bt1_3 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean")); - ct1bt1_3 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean")); - ct1bt1_3 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21, outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21, outputWithHeaders: true}); test:assertEquals(ct1bt1_3, []); - string[][]|csv:Error ct1bt1_4 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); + string[][]|csv:Error ct1bt1_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_4, [ ["a", "b", "c"], ["a", "true", "1"] ]); - ct1bt1_4 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_4 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_4, [ ["h1", "h2", "h3"], ["a", "true", "1"], ["a", "true", "1"] ]); - (int|boolean|string)[][]|csv:Error ct1bt1_4_2 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); + (int|boolean|string)[][]|csv:Error ct1bt1_4_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_4_2, [ ["a", "b", "c"], ["a", true, 1] ]); - string[][]|csv:Error ct1bt1_4_3 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + string[][]|csv:Error ct1bt1_4_3 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {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:parseLists([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + (int|boolean|string)[][]|csv:Error ct1bt1_4_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {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:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string, boolean|string, int|string][]|csv:Error ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - ct1bt1_5 = csv:parseLists([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_5 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - ct1bt1_5 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1], ["a", true, 1] ]); - [string...][]|csv:Error ct1bt2 = csv:parseLists([["1", "a"], ["1", "a"]]); + [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:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string, boolean|string, int|string...][]|csv:Error ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt2_2, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - [string...][]|csv:Error ct1bt2_3 = csv:parseLists([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string...][]|csv:Error ct1bt2_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt2_3, [ ["h1", "h2", "h3"], ["a", "true", "1"] ]); - ct1bt2_2 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt2_2, [ ["h1", "h2", "h3"], ["a", true, 1], ["a", true, 1] ]); - string[2][1]|csv:Error ct1bt6 = csv:parseLists([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + string[2][1]|csv:Error ct1bt6 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt6, [ ["h1"], ["a"] ]); - [string, boolean|string, int|string...][1]|csv:Error ct1bt6_2 = csv:parseLists([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string, boolean|string, int|string...][1]|csv:Error ct1bt6_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt6_2, [ ["h1", "h2", "h3"] ]); - [string...][1]|csv:Error ct1bt6_3 = csv:parseLists([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string...][1]|csv:Error ct1bt6_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {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 decf586..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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + StringRecord10Array|csv:Error st1sr10 = csv:parseList([st1, st1], {}); test:assertEquals(st1sr10, [ {'1: "string", '2: ""}, {'1: "string", '2: ""} ]); - StringRecord10Array|csv:Error st2sr10 = csv:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + StringRecord20Array|csv:Error st2sr20 = csv:parseList([st2, st2], {}); test:assertEquals(st2sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} ]); - StringRecord21Array|csv:Error st1sr21 = csv:parseLists([st1, st1], {}); + StringRecord21Array|csv:Error st1sr21 = csv:parseList([st1, st1], {}); test:assertEquals(st1sr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord21Array|csv:Error st2sr21 = csv:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + StringRecord23Array|csv:Error st1sr23 = csv:parseList([st1, st1], {}); test:assertEquals(st1sr23, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord23Array|csv:Error st2sr23 = csv:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + CustomRecord15Array|csv:Error st1cr15 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord15Array|csv:Error st2cr15 = csv:parseLists([st2, st2], {}); + CustomRecord15Array|csv:Error st2cr15 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord16Array|csv:Error st1cr16 = csv:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + CustomRecord20Array|csv:Error st1cr20 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr20, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord20Array|csv:Error st2cr20 = csv:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + CustomRecord21Array|csv:Error st1cr21 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord21Array|csv:Error st2cr21 = csv:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + CustomRecord24Array|csv:Error st1cr24 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr24, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord24Array|csv:Error st2cr24 = csv:parseLists([st2, st2], {}); + 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:parseLists([st1, st1], {}); + 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:parseLists([st2, st2], {}); + 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:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + 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:parseLists([st1, st1], {}); + CustomRecord26Array|csv:Error st1cr26 = csv:parseList([st1, st1], {}); test:assertEquals(st1cr26 , [ {'1: s1}, {'1: s1} ]); - CustomRecord26Array|csv:Error st2cr26 = csv:parseLists([st2, st2], {}); + CustomRecord26Array|csv:Error st2cr26 = csv:parseList([st2, st2], {}); test:assertEquals(st2cr26 , [ {'1: s1}, {'1: s1} ]); - CustomRecord26Array|csv:Error st3cr26 = csv:parseLists([st3, st3], {}); + CustomRecord26Array|csv:Error st3cr26 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr26 , [ {'1: s1}, {'1: s1} ]); - CustomRecord26Array|csv:Error st4cr26 = csv:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + StringRecord10Array|csv:Error st3sr10 = csv:parseList([st3, st3], {}); test:assertEquals(st3sr10, [ {'1: "string", '2: ""}, {'1: "string", '2: ""} ]); - StringRecord10Array|csv:Error st4sr10 = csv:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + StringRecord20Array|csv:Error st3sr20 = csv:parseList([st3, st3], {}); test:assertEquals(st3sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} ]); - StringRecord20Array|csv:Error st4sr20 = csv:parseLists([st4, st4], {}); + StringRecord20Array|csv:Error st4sr20 = csv:parseList([st4, st4], {}); test:assertEquals(st4sr20, [ {s1: "", s2: ""}, {s1: "", s2: ""} ]); - StringRecord21Array|csv:Error st3sr21 = csv:parseLists([st3, st3], {}); + StringRecord21Array|csv:Error st3sr21 = csv:parseList([st3, st3], {}); test:assertEquals(st3sr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord21Array|csv:Error st4sr21 = csv:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + StringRecord23Array|csv:Error st3sr23 = csv:parseList([st3, st3], {}); test:assertEquals(st3sr23, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - StringRecord23Array|csv:Error st4sr23 = csv:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + CustomRecord15Array|csv:Error st4cr15 = csv:parseList([st4, st4], {}); test:assertEquals(st4cr15, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord16Array|csv:Error st3cr16 = csv:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + CustomRecord17Array|csv:Error st3cr17 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr17, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord17Array|csv:Error st4cr17 = csv:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + CustomRecord20Array|csv:Error st3cr20 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr20, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord20Array|csv:Error st4cr20 = csv:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + CustomRecord21Array|csv:Error st3cr21 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr21, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord21Array|csv:Error st4cr21 = csv:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + CustomRecord22Array|csv:Error st3cr22 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr22, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord22Array|csv:Error st4cr22 = csv:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + 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:parseLists([st4, st4], {}); + 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:parseLists([st3, st3], {}); + CustomRecord24Array|csv:Error st3cr24 = csv:parseList([st3, st3], {}); test:assertEquals(st3cr24, [ {"1": s1, "2": s2}, {"1": s1, "2": s2} ]); - CustomRecord24Array|csv:Error st4cr24 = csv:parseLists([st4, st4], {}); + 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,13 +502,13 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType6() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { - record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "c", "b"]}); + record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - record{() a; float b; decimal c; boolean d; int e; string f;}[]|csv:Error ct1br6 = csv:parseLists( + record{() a; float b; decimal c; boolean d; int e; string f;}[]|csv:Error ct1br6 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br6, [ @@ -516,7 +516,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|decimal c; boolean d; int e; string f;|}[]|csv:Error ct1br7 = csv:parseLists( + record{|decimal c; boolean d; int e; string f;|}[]|csv:Error ct1br7 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br7, [ @@ -524,7 +524,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {c: 2.23, d: true, e: 1, f: "a"} ]); - record{decimal c; boolean d; int e; string f;}[]|csv:Error ct1br8 = csv:parseLists( + record{decimal c; boolean d; int e; string f;}[]|csv:Error ct1br8 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br8, [ @@ -532,7 +532,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|int|() a; float b; decimal? c; boolean d; int e; string f; string...;|}[]|csv:Error ct1br9 = csv:parseLists( + record{|int|() a; float b; decimal? c; boolean d; int e; string f; string...;|}[]|csv:Error ct1br9 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br9, [ @@ -540,7 +540,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|int|() a; float b; decimal? c; string|boolean d; int|string e; string f; string...;|}[]|csv:Error ct1br9_2 = csv:parseLists( + record{|int|() a; float b; decimal? c; string|boolean d; int|string e; string f; string...;|}[]|csv:Error ct1br9_2 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br9_2, [ @@ -551,80 +551,80 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { - record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 0, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + 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:parseLists([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, customHeaders: ["a", "c", "b"]}); + record{string a; boolean b; int c;}[]|csv:Error ct1br4_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4_2, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - record{string a; boolean b; int c;}[]|csv:Error ct1br4_3 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + 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:parseLists( + 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:parseLists( + 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:parseLists( + 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:parseLists( + 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:parseLists([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + 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:parseLists([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 3, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + 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:parseLists( + 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:parseLists( + 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:parseLists( + 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:parseLists( + 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:parseLists( + 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"}, @@ -632,7 +632,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { {"a": "a", "1": "1", "true": "true"} ]); - map[]|csv:Error ct2br4_8_2 = csv:parseLists( + 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"}, @@ -640,7 +640,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { {"a": "a", "1": "1", "true": "true"} ]); - map[]|csv:Error ct2br4_9 = csv:parseLists( + 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"}, @@ -649,7 +649,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { {a: "a", b: "true", c: "5"} ]); - map[]|csv:Error ct2br4_10 = csv:parseLists( + 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}, @@ -658,7 +658,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { {a: "a", c: true, b: 5} ]); - map[]|csv:Error ct2br4_10_2 = csv:parseLists( + 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}, @@ -667,7 +667,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { {a: "a", c: true, b: 5} ]); - ct2br4_10_2 = csv:parseLists( + 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}, @@ -679,7 +679,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { - record{|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseLists( + record{|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br10, [ @@ -687,7 +687,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {a: "()", b: "0", c: 2.23, d: true, e: 1, f: "a"} ]); - record{|decimal? c; boolean d; int? e; string f; ()...;|}[]|csv:Error ct1br11 = csv:parseLists( + record{|decimal? c; boolean d; int? e; string f; ()...;|}[]|csv:Error ct1br11 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br11, [ @@ -695,7 +695,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {a: (), c: 2.23, d: true, e: 1, f: "a"} ]); - record{|()...;|}[]|csv:Error ct1br12 = csv:parseLists( + record{|()...;|}[]|csv:Error ct1br12 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br12, [ @@ -703,7 +703,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {a: ()} ]); - record{|string?...;|}[]|csv:Error ct1br13 = csv:parseLists( + record{|string?...;|}[]|csv:Error ct1br13 = csv:parseList( [["a", "1"], ["a", "1"]], {customHeaders: ["f", "e"]}); test:assertEquals(ct1br13, [ @@ -711,7 +711,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {e: "1", f: "a"} ]); - record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseLists( + record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseList( [["2.23", "null"], ["7", "()"]], {customHeaders: ["b", "a"]}); test:assertEquals(ct1br14, [ @@ -719,7 +719,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {} ]); - map[]|csv:Error ct1br15 = csv:parseLists( + map[]|csv:Error ct1br15 = csv:parseList( [["2", "()"], ["2", "1"], ["()", "2"]], {customHeaders: ["f", "e"]}); test:assertEquals(ct1br15, [ @@ -728,7 +728,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {e: 2, f: ()} ]); - record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseLists( + record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseList( [["2.23", "null"], ["7", "()"]], {customHeaders: ["b", "a"]}); test:assertEquals(ct1br16, [ @@ -741,7 +741,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { function testArrayIndexesWithRecordAsExpectedType() { string[][] csv = [["1", "2", "3"], ["3", "4", "5"], ["5", "6", "7"], ["7", "8", "9"]]; - map[2]|csv:Error rec_2 = csv:parseLists(csv, {customHeaders: ["a", "b", "c"]}); + 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} @@ -750,79 +750,79 @@ function testArrayIndexesWithRecordAsExpectedType() { @test:Config function testFromCsvWithTypeForTupleAndMapAsExpectedType() { - StringMapArray|csv:Error st1sma = csv:parseLists([st1, st1], {}); + StringMapArray|csv:Error st1sma = csv:parseList([st1, st1], {}); test:assertEquals(st1sma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - StringMapArray|csv:Error st2sma = csv:parseLists([st2, st2], {}); + 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:parseLists([st3, st3], {}); + StringMapArray|csv:Error st3sma = csv:parseList([st3, st3], {}); test:assertEquals(st3sma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - StringMapArray|csv:Error st4sma = csv:parseLists([st4, st4], {}); + 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:parseLists([st1, st1], {}); + NillableIntUnionStringMapArray|csv:Error st1niusma = csv:parseList([st1, st1], {}); test:assertEquals(st1niusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - NillableIntUnionStringMapArray|csv:Error st2niusma = csv:parseLists([st2, st2], {}); + 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:parseLists([st3, st3], {}); + NillableIntUnionStringMapArray|csv:Error st3niusma = csv:parseList([st3, st3], {}); test:assertEquals(st3niusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - NillableIntUnionStringMapArray|csv:Error st4niusma = csv:parseLists([st4, st4], {}); + 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:parseLists([st1, st1], {}); + IntUnionStringMapArray|csv:Error st1iusma = csv:parseList([st1, st1], {}); test:assertEquals(st1iusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - IntUnionStringMapArray|csv:Error st2iusma = csv:parseLists([st2, st2], {}); + 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:parseLists([st3, st3], {}); + IntUnionStringMapArray|csv:Error st3iusma = csv:parseList([st3, st3], {}); test:assertEquals(st3iusma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - IntUnionStringMapArray|csv:Error st4iusma = csv:parseLists([st4, st4], {}); + 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:parseLists([st1, st1], {}); + JsonMapArray|csv:Error st1jma = csv:parseList([st1, st1], {}); test:assertEquals(st1jma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} @@ -831,91 +831,91 @@ function testFromCsvWithTypeForTupleAndMapAsExpectedType() { @test:Config function testFromCsvWithTypeForTupleAndMapAsExpectedType2() { - JsonMapArray|csv:Error st2jma = csv:parseLists([st2, st2], {}); + 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:parseLists([st3, st3], {}); + JsonMapArray|csv:Error st3jma = csv:parseList([st3, st3], {}); test:assertEquals(st3jma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - JsonMapArray|csv:Error st4jma = csv:parseLists([st4, st4], {}); + 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:parseLists([st1, st1], {}); + AnydataMapArray|csv:Error st1anydma = csv:parseList([st1, st1], {}); test:assertEquals(st1anydma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - AnydataMapArray|csv:Error st2anydma = csv:parseLists([st2, st2], {}); + 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:parseLists([st3, st3], {}); + AnydataMapArray|csv:Error st3anydma = csv:parseList([st3, st3], {}); test:assertEquals(st3anydma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - AnydataMapArray|csv:Error st4anydma = csv:parseLists([st4, st4], {}); + 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:parseLists([st1, st1], {}); + CustomMapArray|csv:Error st1cma = csv:parseList([st1, st1], {}); test:assertEquals(st1cma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - CustomMapArray|csv:Error st2cma = csv:parseLists([st2, st2], {}); + 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:parseLists([st3, st3], {}); + CustomMapArray|csv:Error st3cma = csv:parseList([st3, st3], {}); test:assertEquals(st3cma , [ {'1: s1, '2: s2}, {'1: s1, '2: s2} ]); - CustomMapArray|csv:Error st4cma = csv:parseLists([st4, st4], {}); + 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:parseLists([st1, st1], {}); + NilMapArray|csv:Error st1nma = csv:parseList([st1, st1], {}); test:assertEquals(st1nma, ([ {}, {} ])); - IntegerMapArray|csv:Error st2ima = csv:parseLists([st2, st2], {}); + IntegerMapArray|csv:Error st2ima = csv:parseList([st2, st2], {}); test:assertEquals(st2ima, ([ {}, {} ])); - DecimalMapArray|csv:Error st3dma = csv:parseLists([st3, st3], {}); + DecimalMapArray|csv:Error st3dma = csv:parseList([st3, st3], {}); test:assertEquals(st3dma, ([ {}, {} ])); - BooleanMapArray|csv:Error st4bma = csv:parseLists([st4, st4], {}); + BooleanMapArray|csv:Error st4bma = csv:parseList([st4, st4], {}); test:assertEquals(st4bma, ([ {}, {} 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 7909d26..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 @@ -673,10 +673,10 @@ function testsRecordsOutputWithHeadrs() { 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:parseLists([["a", "b"], ["c", "d", "e"]], {outputWithHeaders: true}); + bm3anyd3t_3 = csv:parseList([["a", "b"], ["c", "d", "e"]], {outputWithHeaders: true}); test:assertEquals(bm3anyd3t_3, [["a", "b"], ["c", "d", "e"]]); - bm3anyd3t_4 = csv:parseLists([["a", "b"], ["c", "d", "e"]], {outputWithHeaders: true}); + 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/type-compatible-tests/tests/parse_type_compatibility_test.bal b/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal index b75d0a9..6fdd4fe 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 @@ -327,7 +327,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { readonly & int a; readonly & string b; (readonly & boolean) | (readonly & decimal) c; - }[]|csv:Error rt11a = csv:parseLists( + }[]|csv:Error rt11a = csv:parseList( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); test:assertEquals(rt11a , [ @@ -336,7 +336,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A a; B b; C c;}[]|csv:Error rt12a = csv:parseLists( + 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 , [ @@ -345,14 +345,14 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A a; B b; C c;}[]|csv:Error rt12a_2 = csv:parseLists( + record{A a; B b; C c;}[]|csv:Error rt12a_2 = csv:parseList( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["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:parseLists( + 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 , [ @@ -361,7 +361,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{A2 a; B2 b; C2 c;}[]|csv:Error rt13a = csv:parseLists( + 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 , [ @@ -370,7 +370,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true} ]); - record{|A2 a; B2 b; C2...;|}[]|csv:Error rt14a = csv:parseLists( + 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"]}); @@ -380,7 +380,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: 3, b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|csv:Error rt15a = csv:parseLists( + record{|C2...;|}[]|csv:Error rt15a = csv:parseList( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]] , {customHeaders: ["a", "b", "c", "d"]}); @@ -390,7 +390,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {a: "3", b: "string3", c: true, d: "string3"} ]); - record{|C2...;|}[]|csv:Error rt15a_2 = csv:parseLists( + record{|C2...;|}[]|csv:Error rt15a_2 = csv:parseList( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]], {stringConversion: false, customHeaders: ["a", "b", "c", "d"]}); @@ -401,7 +401,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ]); [readonly & int, readonly & string, (readonly & boolean) | (readonly & decimal)][]|csv:Error rt16a = - csv:parseLists( + csv:parseList( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); @@ -412,7 +412,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|csv:Error rt17a = csv:parseLists( + [A, B, C][]|csv:Error rt17a = csv:parseList( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); test:assertEquals(rt17a , [ @@ -421,13 +421,13 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A, B, C][]|csv:Error rt17a_2 = csv:parseLists( + [A, B, C][]|csv:Error rt17a_2 = csv:parseList( [["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:parseLists( + [A2, B2, C2][]|csv:Error rt18a = csv:parseList( [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); test:assertEquals(rt18a , [ @@ -436,7 +436,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true] ]); - [A2, B2, C2...][]|csv:Error rt19a = csv:parseLists( + [A2, B2, C2...][]|csv:Error rt19a = csv:parseList( [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]]); test:assertEquals(rt19a , [ @@ -445,7 +445,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [3, "string3", true, "string3"] ]); - [C2...][]|csv:Error rt20a = csv:parseLists( + [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"], diff --git a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal index b02000f..7066c6d 100644 --- a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal +++ b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal @@ -8,14 +8,14 @@ csv:TransformOptions op4 = {headersOrder: ["a", "b"], outputWithHeaders: true}; csv:ParseOptions op5 = {outputWithHeaders: true}; -csv:ParseListsOptions op6 = {outputWithHeaders: true}; -csv:ParseListsOptions op7 = {outputWithHeaders: true, headerRows: 1}; -csv:ParseListsOptions op8 = {outputWithHeaders: true, headerRows: 2}; -csv:ParseListsOptions op9 = {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListsOptions op10 = {outputWithHeaders: true, headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListsOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListsOptions op12 = {headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListsOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; +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[][]; @@ -135,120 +135,120 @@ function testTransformWithListWithOutputHeaders() { @test:Config function testParseListWithMapWithOutputHeaders() { - UnionType3|csv:Error psu3 = csv:parseLists(csv1); + UnionType3|csv:Error psu3 = csv:parseList(csv1); test:assertEquals(psu3, result7); - psu3 = csv:parseLists(csv1, op6); + psu3 = csv:parseList(csv1, op6); test:assertEquals(psu3, result7); - psu3 = csv:parseLists(csv1, op7); + 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:parseLists(csv1, op9); + 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:parseLists(csv1); + UnionType4|csv:Error psu4 = csv:parseList(csv1); test:assertEquals(psu4, result8); - psu4 = csv:parseLists(csv1, op6); + psu4 = csv:parseList(csv1, op6); test:assertEquals(psu4, result8); - psu4 = csv:parseLists(csv1, op7); + 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:parseLists(csv1, op9); + 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:parseLists(csv1); + UnionType1|csv:Error psu1 = csv:parseList(csv1); test:assertEquals(psu1, result4); - psu1 = csv:parseLists(csv1, op6); + psu1 = csv:parseList(csv1, op6); test:assertEquals(psu1, result4); - psu1 = csv:parseLists(csv1, op7); + psu1 = csv:parseList(csv1, op7); test:assertEquals(psu1, result4); - psu1 = csv:parseLists(csv1, op9); + 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:parseLists(csv1); + UnionType2|csv:Error psu2 = csv:parseList(csv1); test:assertEquals(psu2, result4); - psu2 = csv:parseLists(csv1, op6); + psu2 = csv:parseList(csv1, op6); test:assertEquals(psu2, result4); - psu2 = csv:parseLists(csv1, op7); + psu2 = csv:parseList(csv1, op7); test:assertEquals(psu2, result4); - psu2 = csv:parseLists(csv1, op9); + 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:parseLists(csv1); + UnionType3|csv:Error psu3 = csv:parseList(csv1); test:assertEquals(psu3, result7); - psu3 = csv:parseLists(csv1, op10); + 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:parseLists(csv1, op11); + psu3 = csv:parseList(csv1, op11); test:assertEquals(psu3, result2); - psu3 = csv:parseLists(csv1, op12); + 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:parseLists(csv1, op13); + psu3 = csv:parseList(csv1, op13); test:assertEquals(psu3, result2); - UnionType4|csv:Error psu4 = csv:parseLists(csv1); + UnionType4|csv:Error psu4 = csv:parseList(csv1); test:assertEquals(psu4, result8); - psu4 = csv:parseLists(csv1, op10); + 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:parseLists(csv1, op11); + psu4 = csv:parseList(csv1, op11); test:assertEquals(psu4, result3); - psu4 = csv:parseLists(csv1, op12); + 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:parseLists(csv1, op13); + psu4 = csv:parseList(csv1, op13); test:assertEquals(psu4, result3); } @test:Config function testParseListWithListWithOutputHeaders2() { - UnionType1|csv:Error psu1 = csv:parseLists(csv1); + UnionType1|csv:Error psu1 = csv:parseList(csv1); test:assertEquals(psu1, result4); - psu1 = csv:parseLists(csv1, op10); + 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:parseLists(csv1, op11); + psu1 = csv:parseList(csv1, op11); test:assertEquals(psu1, result6); - psu1 = csv:parseLists(csv1, op12); + psu1 = csv:parseList(csv1, op12); test:assertEquals(psu1, [["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); - psu1 = csv:parseLists(csv1, op13); + psu1 = csv:parseList(csv1, op13); test:assertEquals(psu1, result4); - UnionType2|csv:Error psu2 = csv:parseLists(csv1); + UnionType2|csv:Error psu2 = csv:parseList(csv1); test:assertEquals(psu2, result4); - psu2 = csv:parseLists(csv1, op10); + 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:parseLists(csv1, op11); + 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:parseLists(csv1, op12); + psu2 = csv:parseList(csv1, op12); test:assertEquals(psu2, [["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]]); - psu2 = csv:parseLists(csv1, op13); + 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 66a06fa..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 @@ -126,49 +126,49 @@ function testIntersectionExpectedTypes2() returns error? { @test:Config function testIntersectionExpectedTypes3() returns error? { - (int[] & readonly)[]|csv:Error a = csv:parseLists([["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:parseLists([["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:parseLists([["1", "2"], ["4", "5"]], {customHeaders: ["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:parseLists([["a", "a"], ["c", "c"]], {customHeaders: ["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:parseLists([["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:parseLists([["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:parseLists([["1", "2"], ["4", "5"]], {customHeaders: ["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:parseLists([["a", "a"], ["c", "c"]], {customHeaders: ["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:parseLists([["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:parseLists([["a", "a"], ["1", "2"]], {customHeaders: ["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:parseLists([["a", "a"], ["1", "2"]], {customHeaders: ["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 f0ca784..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 @@ -193,21 +193,21 @@ function testSubtypeExpectedTypes() returns error? { 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:parseLists(value2, {customHeaders: ["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:parseLists(value2, {customHeaders: ["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:parseLists(value2, {customHeaders: ["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:parseLists(value2, {}); + SubtypeTuple[]|csv:Error a16 = csv:parseList(value2, {}); test:assertEquals(a16, value3); - SubtypeTuple2[]|csv:Error a17 = csv:parseLists(value2, {}); + SubtypeTuple2[]|csv:Error a17 = csv:parseList(value2, {}); test:assertEquals(a17, [[1, 1], [1, 1]]); - SubtypeTuple3[]|csv:Error a18 = csv:parseLists(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 0e5ccf4..0d216d2 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 @@ -252,7 +252,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - (RecA|RecC)[]|csv:Error csv1op1 = csv:parseLists(value, {customHeaders: ["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:parseLists(value, {customHeaders: ["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:parseLists(value, {customHeaders: ["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:parseLists(value, {customHeaders: ["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:parseLists(value, {customHeaders: ["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:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); + (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); test:assertEquals(csv1op8, [ {a: "1", b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: "3", b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: "5", b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseLists(value, {customHeaders: ["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"], stringConversion: true}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -320,7 +320,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, d: 3} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9_2 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); + (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9_2 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); test:assertEquals(csv1op9_2, [ {}, {}, @@ -329,14 +329,14 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); + (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: 3, b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: 5, b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); + (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -345,11 +345,11 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", d: 3} ]); - (record{|int a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op12 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); + (record{|int a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op12 = csv:parseList(value, {customHeaders: ["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:parseLists([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); + (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, {a: "a", b: "b"} @@ -460,7 +460,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - (TupA|TupC)[]|csv:Error csv1op1 = csv:parseLists(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 +469,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupA|TupC)[]|csv:Error csv1op2 = csv:parseLists(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 +477,56 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupC|TupA)[]|csv:Error csv1op3 = csv:parseLists(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:parseLists(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:parseLists(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:parseLists(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:parseLists(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:parseLists(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:parseLists(value, {stringConversion: false}); + ([boolean...]|[int...])[]|csv:Error csv1op8 = csv:parseList(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:parseLists(value, {}); + ([string...]|[int...])[]|csv:Error csv1op8_2 = csv:parseList(value, {}); test:assertEquals(csv1op8_2, value); - ([int...]|[string...])[]|csv:Error csv1op9 = csv:parseLists(value, {}); + ([int...]|[string...])[]|csv:Error csv1op9 = csv:parseList(value, {}); test:assertEquals(csv1op9, value); - ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:parseLists(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 +535,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:parseLists(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 +544,10 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:parseLists(value, {}); + ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:parseList(value, {}); test:assertEquals(csv1op12, value); - ([int, int...]|[string, string...])[]|csv:Error csv1op13 = csv:parseLists([["1", "2"], ["a", "b"]], {}); + ([int, int...]|[string, string...])[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] @@ -767,7 +767,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - RecA[]|RecC[]|csv:Error csv1op1 = csv:parseLists(value, {customHeaders: ["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 +776,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecA[]|RecC[]|csv:Error csv1op2 = csv:parseLists(value, {customHeaders: ["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 +784,49 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - RecC[]|RecA[]|csv:Error csv1op3 = csv:parseLists(value, {customHeaders: ["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:parseLists(value, {customHeaders: ["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:parseLists(value, {customHeaders: ["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:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); + record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); test:assertEquals(csv1op8, [ {a: "1", b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: "3", b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: "5", b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseLists(value, {customHeaders: ["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"], stringConversion: true}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -835,7 +835,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, d: 3} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9_2 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); + record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9_2 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); test:assertEquals(csv1op9_2, [ {}, {}, @@ -844,14 +844,14 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); + record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: 3, b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: 5, b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); + record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -860,11 +860,11 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", d: 3} ]); - record{|int a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op12 = csv:parseLists(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); + record{|int a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op12 = csv:parseList(value, {customHeaders: ["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:parseLists([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); + record{|int a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, {a: "a", b: "b"} @@ -969,7 +969,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { ["5", "string5", "true", "3", "3.0", "()"] ]; - TupA[]|TupC[]|csv:Error csv1op1 = csv:parseLists(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 +978,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupA[]|TupC[]|csv:Error csv1op2 = csv:parseLists(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 +986,56 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupC[]|TupA[]|csv:Error csv1op3 = csv:parseLists(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:parseLists(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:parseLists(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:parseLists(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:parseLists(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:parseLists(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:parseLists(value, {stringConversion: false}); + [boolean...][]|[int...][]|csv:Error csv1op8 = csv:parseList(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:parseLists(value, {}); + [string...][]|[int...][]|csv:Error csv1op8_2 = csv:parseList(value, {}); test:assertEquals(csv1op8_2, value); - [int...][]|[string...][]|csv:Error csv1op9 = csv:parseLists(value, {}); + [int...][]|[string...][]|csv:Error csv1op9 = csv:parseList(value, {}); test:assertEquals(csv1op9, value); - [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:parseLists(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 +1044,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:parseLists(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 +1053,6 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [5, "string5", "true", "3", "3.0", "()"] ]); - [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:parseLists(value, {}); + [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:parseList(value, {}); test:assertEquals(csv1op12, value); } 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 cf2b6da..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 @@ -184,79 +184,79 @@ function testCustomNameAnnotation() returns error? { @test:Config function testCustomNameAnnotation2() returns error? { - RecordWithCustomAnnotation[]|csv:Error cntr1 = csv:parseLists([["1", "3"]], {customHeaders: ["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:parseLists([["3", "1"]], {customHeaders: ["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:parseLists( + 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:parseLists([["1", "3"]], {customHeaders: ["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:parseLists([["3","1"]], {customHeaders: ["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:parseLists( + 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:parseLists([["3", "1"]], {customHeaders: ["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:parseLists([["3", "1", "4", "5"]], {customHeaders: ["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:parseLists([["1", "3"]], {customHeaders: ["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:parseLists([["3", "1"]], {customHeaders: ["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:parseLists( + 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:parseLists([["3", "1"]], {customHeaders: ["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:parseLists([["3", "1", "4", "5"]], {customHeaders: ["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:parseLists([["1", "3", "true"]], {customHeaders: ["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:parseLists([["3", "1"]], {customHeaders: ["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:parseLists( + 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:parseLists([["3", "1"]], {customHeaders: ["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:parseLists([["3", "1", "4", "5"]], {customHeaders: ["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:parseLists([["3", "1", "4", "5"]], {customHeaders: ["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:parseLists( + 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:parseLists( + 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}]); } @@ -359,22 +359,22 @@ function testAbsentAsNilableConfig2() returns error? { test:assertTrue(cn4 is csv:Error); test:assertEquals((cn4).message(), common:generateErrorMessageForMissingRequiredField("g")); - record {|string a; int? g; int? h;|}[]|csv:Error cn5 = csv:parseLists([["a"], ["a"], ["a"]], {customHeaders: ["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:parseLists([["a"], ["a"], ["a"]], {customHeaders: ["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:parseLists([["a"], ["a"], ["b"]], {customHeaders: ["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:parseLists([["a"], ["a"], ["a"]], {customHeaders: ["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); 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 23cd58e..895a90a 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 @@ -564,32 +564,32 @@ function testCustomHeaderOption() { test:assertTrue(bm3ba5 is csv:Error); test:assertEquals((bm3ba5).message(), "Invalid number of headers"); - record {}[]|csv:Error ct1br = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["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 headers"); - record {}[]|csv:Error ct1br2 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["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 headers"); - record {}[]|csv:Error ct1br2_2 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["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 headers"); - record {}[]|csv:Error ct1br3 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: []}); + 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 headers"); - record {|string a; string b; string c;|}[]|csv:Error ct1br5 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["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:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["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:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], + record {string a; string b;}[]|csv:Error ct1br7 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], stringConversion: false }); test:assertEquals(ct1br7, [ @@ -597,7 +597,7 @@ function testCustomHeaderOption() { {a: "a", e: "1", b: "true"} ]); - record {|string a; string b;|}[]|csv:Error ct1br8 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], + record {|string a; string b;|}[]|csv:Error ct1br8 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], stringConversion: false }); test:assertEquals(ct1br8, [ @@ -605,7 +605,7 @@ function testCustomHeaderOption() { {a: "a", b: "true"} ]); - record {|string...;|}[]|csv:Error ct1br9 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], + record {|string...;|}[]|csv:Error ct1br9 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"], stringConversion: false }); test:assertEquals(ct1br9, [ @@ -613,7 +613,7 @@ function testCustomHeaderOption() { {a: "a", b: "true", e: "1"} ]); - record {|string...;|}[]|csv:Error ct1br10 = csv:parseLists([["a", "1", "true"], ["a", "1", "true"]], { + record {|string...;|}[]|csv:Error ct1br10 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], { stringConversion: false }); test:assertEquals(ct1br10, [ @@ -962,36 +962,36 @@ function testSkipLineParameterWithOutputHeaderConfig() { result2 = csv:transform(csv1, {outputWithHeaders: true, skipLines: "2-3"}); test:assertEquals(result2, [["a", "b"], [1, 2], [4, 5]]); - result = csv:parseLists(csv2, {outputWithHeaders: true, skipLines: "2-3", customHeaders: ["a", "b"]}); + 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:parseLists(csv2, {outputWithHeaders: true, skipLines: "2-3", customHeaders: ["a", "b"]}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [1, 2], [4, 5]]); - result = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + result = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result, [{a: 2, b: 3}]); - result2 = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [2, 3]]); - result = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); + result = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result, [{a: 3, b: 4}]); - result2 = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [3, 4]]); - result = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3"}); + result = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3"}); test:assertEquals(result, [{'1: 2, '2: 3}]); - result2 = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3"}); test:assertEquals(result2, [[1, 2], [2, 3]]); - result2 = csv:parseLists(csv2, {outputWithHeaders: false, headerRows: 1, skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: false, headerRows: 1, skipLines: "2-3"}); test:assertEquals(result2, [[2, 3]]); - result = csv:parseLists(csv2, {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b"], skipLines: "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:parseLists(csv2, {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); test:assertEquals(result2, [["a", "b"], [3, 4]]); } diff --git a/ballerina/Package.md b/ballerina/Package.md index 1af609a..5de4753 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -82,7 +82,7 @@ type Book record { public function main() returns error? { string[][] bookArray = [["Clean Code","2008"],["Clean Architecture","2017"]]; - Book[] author = check csv:parseLists(bookArray, customHeaders = ["name", "year"]); + Book[] author = check csv:parseList(bookArray, customHeaders = ["name", "year"]); io:println(author); } ``` diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index ddc749d..acf0012 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -16,19 +16,19 @@ import ballerina/jballerina.java; -public isolated function parseString(string s, ParseOptions options = {}, typedesc t = <>) +public isolated function parseString(string csvString, ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -public isolated function parseBytes(byte[] s, ParseOptions options = {}, typedesc t = <>) +public isolated function parseBytes(byte[] csvBytes, ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -public isolated function parseStream(stream s, +public isolated function parseStream(stream csvByteStream, ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -public isolated function transform(record{}[] s, +public isolated function transform(record{}[] csvRecords, TransformOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -public isolated function parseLists(string[][] s, ParseListsOptions options = {}, typedesc t = <>) +public isolated function parseList(string[][] csvList, ParseListOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; diff --git a/ballerina/types.bal b/ballerina/types.bal index e2dba0d..4ce205d 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -29,7 +29,8 @@ public type Options record { # 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. + boolean enableConstraintValidation = true; + # If `true`, the resulted CSV contains the headers as the first row. # This field is only acceptable if the expected type is subset of `anydata[][]` boolean outputWithHeaders = false; }; @@ -60,7 +61,7 @@ public type ParseOptions record {| |}; # Represents options for treating a list as a record. -public type ParseListsOptions record {| +public type ParseListOptions record {| *Options; # If `true`, enables conversion of strings during processing. boolean stringConversion = true; 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 8943e55..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 @@ -12,21 +12,21 @@ public function main() returns error? { 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:parseLists([], {}); + [[int, string], [int, string]] _ = check csv:parseList([], {}); [record{}, record{}, record{}, record{}] _ = check csv:transform([{}], {}); - [record{}, record{}, record{}, record{}] _ = check csv:parseLists([], {}); - record{record{} a;}[] _ = check csv:parseLists([], {}); - record{int[] a;}[] _ = check csv:parseLists([], {}); - record{[int...] a;}[] _ = check csv:parseLists([], {}); - record{[int...] a;}[] _ = check csv:parseLists([], {}); - record{record{} a;}[] _ = check csv:parseLists([], {}); - record{xml a; regexp:RegExp b;}[] _ = check csv:parseLists([], {}); - [xml, xml][] _ = check csv:parseLists([], {}); - [regexp:RegExp, xml, int[]][] _ = check csv:parseLists([], {}); - [regexp:RegExp, xml, int[]][]|int[][] _ = check csv:parseLists([], {}); - int[][]|[regexp:RegExp, xml, int[]][] _ = check csv:parseLists([], {}); - int[][]|[record{}|regexp:RegExp][] _ = check csv:parseLists([], {}); - record{}[]|int[][] _ = check csv:parseLists([], {}); - record{}[2] _ = check csv:parseLists([], {}); - int[3][2] _ = check csv:parseLists([], {}); + [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 bfeeb9f..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 @@ -10,8 +10,8 @@ stream s = ( [[1, 2, 3, 4, 5]]).toStream(); 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:parseLists([], {}); +[[int, string], [int, string]] val8 = check csv:parseList([], {}); [record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); -[record{}, record{}, record{}, record{}] val10 = check csv:parseLists([], {}); -record{}[2] val11 = check csv:parseLists([], {}); -int[3][2] val12 = check csv:parseLists([], {}); +[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 b5ec5a8..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 @@ -16,9 +16,9 @@ public function test() returns error? { 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:parseLists([], {}); + [[int, string], [int, string]] val8 = check csv:parseList([], {}); [record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); - [record{}, record{}, record{}, record{}] val10 = check csv:parseLists([], {}); - record{}[2] val11 = check csv:parseLists([], {}); - int[3][2] val12 = check csv:parseLists([], {}); + [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 348a97f..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 @@ -28,7 +28,7 @@ public final class Constants { static final String PARSE_BYTES = "parseBytes"; static final String PARSE_STREAM = "parseStream"; static final String TRANSFORM = "transform"; - static final String PARSE_LISTS = "parseLists"; + static final String PARSE_LISTS = "parseList"; static final String NAME = "Name"; static final String CSVDATA = "csv"; static final String BALLERINA = "ballerina"; 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 f7811c1..49fb17c 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 @@ -96,9 +96,9 @@ public static Object transform(BArray csv, BMap options, BTyped return DiagnosticLog.getCsvError(e.getMessage()); } } - public static Object parseLists(BArray csv, BMap options, BTypedesc type) { + public static Object parseList(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvConfig.createParseListsOptions(options), type); + return CsvTraversal.traverse(csv, CsvConfig.createParseListOptions(options), type); } catch (Exception e) { return DiagnosticLog.getCsvError(e.getMessage()); } From dfba0c84ea9274c40fa1e6f40f8b207670e9588d Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Fri, 9 Aug 2024 03:57:16 +0530 Subject: [PATCH 126/147] Remove string conversion parameter --- .../tests/parse_type_compatibility_test.bal | 650 +++++++++--------- .../tests/test_with_union_types.bal | 38 +- .../user_config_with_parser_options_test.bal | 495 +++++++------ ballerina/types.bal | 3 - .../lib/data/csvdata/csv/Native.java | 4 +- .../lib/data/csvdata/utils/CsvConfig.java | 6 +- 6 files changed, 574 insertions(+), 622 deletions(-) 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 6fdd4fe..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 @@ -23,431 +23,421 @@ 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: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: ()} - ]); + 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 - ]); + 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} - ]); + 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:parseString( 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:parseString( 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:parseString( 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:parseString( 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:parseString( 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:parseString( 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:parseString( - string `a,b,c + 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:parseString( - string `a,b,c + 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:parseString( - string `a,b,c,d + 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:parseString( - string `a,b,c,d + 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: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; + 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 = + [{"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": 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"]}); + [{"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] - ]); + 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"]}); + [{"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] - ]); + 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"]}); + [{"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"] - ]); + 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"]}); + [{"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; + 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{A a; B b; C c;}[]|csv:Error rt12a_2 = csv:parseList( - [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["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: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"} - ]); - - record{|C2...;|}[]|csv:Error rt15a_2 = csv:parseList( - [["1", "string", "true", "string"], ["2", "string2", "false", "string2"], ["3", "string3", "true", "string3"]], - {stringConversion: false, customHeaders: ["a", "b", "c", "d"]}); - - 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 = + [["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] - ]); + [ + ["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"]]); + [["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:parseList( - [["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")); + 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"]]); + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); - test:assertEquals(rt18a , [ - [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"]]); + [["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"] - ]); + 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"]]); + [["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 + test:assertEquals(rt20a, [ + ["1", "string", true, "string"], + ["2", "string2", false, "string2"], + ["3", "string3", true, "string3"] + ]); +} 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 0d216d2..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 @@ -311,7 +311,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], 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,15 +320,6 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, d: 3} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9_2 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); - test:assertEquals(csv1op9_2, [ - {}, - {}, - {}, - {}, - {} - ]); - (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: "()"}, @@ -345,10 +336,6 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", d: 3} ]); - (record{|int a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op12 = csv:parseList(value, {customHeaders: ["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:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, @@ -516,10 +503,6 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ["5"] ]); - ([boolean...]|[int...])[]|csv:Error csv1op8 = csv:parseList(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:parseList(value, {}); test:assertEquals(csv1op8_2, value); @@ -826,7 +809,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], 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,15 +818,6 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, d: 3} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9_2 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], stringConversion: false}); - test:assertEquals(csv1op9_2, [ - {}, - {}, - {}, - {}, - {} - ]); - 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: "()"}, @@ -860,10 +834,6 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", d: 3} ]); - record{|int a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op12 = csv:parseList(value, {customHeaders: ["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:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, @@ -1025,10 +995,6 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { ["5"] ]); - [boolean...][]|[int...][]|csv:Error csv1op8 = csv:parseList(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:parseList(value, {}); test:assertEquals(csv1op8_2, value); 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 895a90a..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 @@ -34,63 +34,63 @@ function testCSVEncoding() returns error? { @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:parseString(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:parseString(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:parseString(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: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: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: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:parseString(csvStringData2, option4); test:assertEquals(csv2op4, []); @@ -100,35 +100,35 @@ function testFromCsvStringWithParserOptions() { 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: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: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: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: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]} @@ -139,73 +139,73 @@ function testFromCsvStringWithHeaderLessParserOptions() { 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: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: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: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: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: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: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: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: ()} - ]); + {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:parseString(csvStringData2, {header: 11}); test:assertEquals(csv2cop3, []); @@ -433,116 +433,116 @@ function testCommentConfigOption2() { function testSkipLineParserOption() { [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, ()] - ]); + [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, ()] - ]); + [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:parseString(csvStringData1, {skipLines: [1, 2, 3, 4, 5], header: 1}); test:assertEquals(csv1cp, [ - ]); + ]); csv1cp = csv:parseString(csvStringData1, {skipLines: "1-5", header: 1}); test:assertEquals(csv1cp, [ - ]); + ]); 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: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: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: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:parseString(csvStringData1, {skipLines: [5, 4, 3, 2, 1], header: 1}); test:assertEquals(csv1cp, [ - ]); + ]); 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, ()] - ]); + [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, ()] - ]); + [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: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:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}); test:assertEquals(bm1ba, [ - [true, false], - [true, false] - ]); + [true, false], + [true, false] + ]); 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:transform([bm2, bm2], {headersOrder: ["b1", "n1", "b2", "n2", "b3"]}); test:assertTrue(bm2ba is csv:Error); @@ -589,67 +589,66 @@ function testCustomHeaderOption() { test:assertTrue(ct1br6 is csv:Error); test:assertEquals((ct1br6).message(), common:generateErrorMessageForMissingRequiredField("c")); - record {string a; string b;}[]|csv:Error ct1br7 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["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:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["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:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["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:parseList([["a", "1", "true"], ["a", "1", "true"]], { - stringConversion: false - }); + }); 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: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: ()} - ]); + {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: ()} - ]); + {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: ()} - ]); + {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); @@ -661,57 +660,57 @@ function testCustomHeaderParserOption2() { 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: ()} - ]); + {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: ()} - ]); + {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: 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: ()} - ]); + {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: 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: ()} - ]); + {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} - ]); + {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: "string2", d1: false}, - {e1: "string3", d1: false}, - {e1: "string4", d1: true}, - {e1: "string5", 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:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["e1", "d1"]}); test:assertTrue(ct1br8 is csv:Error); @@ -719,12 +718,12 @@ function testCustomHeaderParserOption2() { 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} - ]); + {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); @@ -732,12 +731,12 @@ function testCustomHeaderParserOption2() { 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"} - ]); + {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); @@ -896,21 +895,21 @@ function testEscapeCharactersWithParserOptions() { function testDelimiterWithParserOptions() { 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: ()} - ]); + {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 @@ -950,7 +949,7 @@ function testSkipLineParameterWithOutputHeaderConfig() { 3,4 4,5`; - record{}[]|csv:Error result = csv:parseString(csv3, {outputWithHeaders: true, skipLines: "2-3"}); + 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"}); diff --git a/ballerina/types.bal b/ballerina/types.bal index 4ce205d..24096a1 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -63,8 +63,6 @@ public type ParseOptions record {| # Represents options for treating a list as a record. public type ParseListOptions record {| *Options; - # If `true`, enables conversion of strings during processing. - boolean stringConversion = true; # If `0`, all the sources will treat as data rows. # Otherwise specify the header rows(Starts from 1) int:Unsigned32 headerRows = 0; @@ -91,7 +89,6 @@ public enum LineTerminator { # Enum representing possible nil values. public enum NilValue { NULL = "null", - EMPTY_STRING = "", NOT_APPLICABLE = "N/A", BAL_NULL = "()" }; 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 49fb17c..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 @@ -98,7 +98,9 @@ public static Object transform(BArray csv, BMap options, BTyped } public static Object parseList(BArray csv, BMap options, BTypedesc type) { try { - return CsvTraversal.traverse(csv, CsvConfig.createParseListOptions(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/CsvConfig.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java index 9893d02..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 @@ -42,7 +42,7 @@ private CsvConfig(CsvConfig config) { this.locale = config.locale; } - public static CsvConfig createParseListsOptions(BMap options) { + public static CsvConfig createParseListOptions(BMap options) { updateDataProjectOptions(options); return new CsvConfig( options.getBooleanValue(Constants.ConfigConstants.NIL_AS_OPTIONAL), @@ -51,7 +51,6 @@ public static CsvConfig createParseListsOptions(BMap options) { options.get(Constants.ConfigConstants.SKIP_LINES), options.getBooleanValue(Constants.ConfigConstants.ENABLE_CONSTRAINT_VALIDATION), options.getBooleanValue(Constants.ConfigConstants.OUTPUT_WITH_HEADERS), - options.getBooleanValue(Constants.ConfigConstants.STRING_CONVERSION), options.getIntValue(Constants.ConfigConstants.HEADER_ROWS), options.get(Constants.ConfigConstants.CUSTOM_HEADERS) ); @@ -59,14 +58,13 @@ public static CsvConfig createParseListsOptions(BMap options) { public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, Object skipLines, boolean enableConstraintValidation, boolean outputWithHeaders, - boolean stringConversion, long headerRows, Object headers) { + long headerRows, Object headers) { this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; this.skipLines = skipLines; this.enableConstraintValidation = enableConstraintValidation; this.outputWithHeaders = outputWithHeaders; - this.stringConversion = stringConversion; this.headerRows = headerRows; this.customHeaders = headers; } From a87e7abb0aead2077f8c3d28f6848ed39ee17495 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Fri, 9 Aug 2024 04:14:45 +0530 Subject: [PATCH 127/147] Update public apis in Ballerina --- ballerina/csv_api.bal | 30 ++++++++++++++++++++++++++++++ ballerina/types.bal | 6 +++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index acf0012..b4089e1 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -16,19 +16,49 @@ import ballerina/jballerina.java; +# Converts CSV string to subtype of `record{}[]` or `anydata[][]`. +# +# + csvString - Source CSV string value +# + options - Options to be used for filtering in the projection +# + t - Target type +# + return - On success, value belonging to the given target type, else returns an `csv:Error` value. public isolated function parseString(string csvString, ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; +# Converts byte[] to subtype of `record{}[]` or `anydata[][]`. +# +# + csvBytes - Source CSV byte array +# + options - Options to be used for filtering in the projection +# + t - Target type +# + return - On success, value belonging to the given target type, else returns an `csv:Error` value. public isolated function parseBytes(byte[] csvBytes, ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; +# Converts CSV byte-block-stream to subtype of `record{}[]` or `anydata[][]`. +# +# + csvByteStream - Source CSV byte-block-stream +# + options - Options to be used for filtering in the projection +# + t - Target type +# + return - On success, value belonging to the given target type, else returns an `csv:Error` value. public isolated function parseStream(stream csvByteStream, ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; +# Convert value of type record{}[] to subtype of `record{}[]` or `anydata[][]`. +# +# + csvRecords - Source Ballerina record array value +# + options - Options to be used for filtering in the projection +# + t - Target type +# + return - On success, returns value belonging to the given target type, else returns an `csv:Error` value. public isolated function transform(record{}[] csvRecords, TransformOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; +# Convert value of type string array of array to subtype of `record{}[]` or `anydata[][]`. +# +# + csvList - Source Ballerina string array of array value +# + options - Options to be used for filtering in the projection +# + t - Target type +# + return - On success, returns value belonging to the given target type, else returns an `csv:Error` value. public isolated function parseList(string[][] csvList, ParseListOptions options = {}, typedesc t = <>) 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 24096a1..56c0e64 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -31,7 +31,7 @@ public type Options record { # 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 acceptable if the expected type is subset of `anydata[][]` + # This field is only considered if the expected type is a subset of `anydata[][]` boolean outputWithHeaders = false; }; @@ -63,8 +63,8 @@ public type ParseOptions record {| # Represents options for treating a list as a record. public type ParseListOptions record {| *Options; - # If `0`, all the sources will treat as data rows. - # Otherwise specify the header rows(Starts from 1) + # 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. From 6e5e613f29f3d9c48d3883d510e118808b8cdf66 Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Fri, 9 Aug 2024 05:08:08 +0530 Subject: [PATCH 128/147] Update the ReadMe file --- README.md | 26 ++++++++++++++++++-------- ballerina/Package.md | 26 ++++++++++++++++++-------- ballerina/types.bal | 1 + 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 181d189..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 `parseString` 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; @@ -45,7 +45,7 @@ public function main() returns error? { ### Converting external CSV document to a record value -For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes`, `parseStream`, `parseString`, `parseBytes`and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. +For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. ```ballerina import ballerina/data.csv; @@ -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:parseList(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); } ``` diff --git a/ballerina/Package.md b/ballerina/Package.md index 5de4753..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 `parseString` 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; @@ -38,7 +38,7 @@ public function main() returns error? { ### Converting external CSV document to a record value -For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes`, `parseStream`, `parseString`, `parseBytes`and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. +For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. ```ballerina import ballerina/data.csv; @@ -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:parseList(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); } ``` diff --git a/ballerina/types.bal b/ballerina/types.bal index 56c0e64..030adb9 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -90,5 +90,6 @@ public enum LineTerminator { public enum NilValue { NULL = "null", NOT_APPLICABLE = "N/A", + EMPTY_STRING = "", BAL_NULL = "()" }; From 19288040f48177559b43d2e600276c7acc9de19e Mon Sep 17 00:00:00 2001 From: SasinduDilshara Date: Mon, 12 Aug 2024 10:19:13 +0530 Subject: [PATCH 129/147] Allow empty strings to represent nil values using configs --- .../tests/parse_string_to_array_test.bal | 10 ++-- .../tests/test_data_values.bal | 6 ++ .../tests/csv_content_2.txt | 4 ++ .../tests/nill_type_test.bal | 58 +++++++++++++++++++ .../tests/parse_string_compatibality_test.bal | 33 ++++++----- .../tests/test_data_values.bal | 25 ++++++++ .../user_config_with_parser_options_test.bal | 50 +++++++++++++--- .../lib/data/csvdata/csv/CsvCreator.java | 9 ++- .../lib/data/csvdata/csv/CsvParser.java | 21 ++++--- .../csvdata/utils/DiagnosticErrorCode.java | 4 +- .../src/main/resources/csv_error.properties | 8 ++- 11 files changed, 187 insertions(+), 41 deletions(-) create mode 100644 ballerina-tests/type-compatible-tests/tests/csv_content_2.txt create mode 100644 ballerina-tests/type-compatible-tests/tests/nill_type_test.bal 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 46a49c0..dfeaf58 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 @@ -437,14 +437,12 @@ function testParseStringArrayAsExpectedTypeWithOutputHeaders() { ]); string[][]|csv:Error cv1baa_5 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true, header: 2}); - test:assertEquals(cv1baa_5, [ - ["true", "false", "true", "false"], - ["true", "false", "true", "false"] - ]); + test:assertTrue(cv1baa_5 is csv:Error); + test:assertEquals((cv1baa_5).message(), "Duplicate header found: 'true'"); - string[][]|csv:Error cv1baa_6 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: false, header: 2}); + string[][]|csv:Error cv1baa_6 = csv:parseString(csvStringWithBooleanValues8, {outputWithHeaders: false, header: 2}); test:assertEquals(cv1baa_6, [ - ["true", "false", "true", "false"] + ["true", "false", "true1", "false1"] ]); [string, string, string, string, string][]|csv:Error cv2baa_7 = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); diff --git a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal index 4060a59..e4d152b 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal @@ -60,3 +60,9 @@ string csvStringWithBooleanValues6 = string `b2,b3 string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 ${b1},${b2},(),${b4} `; + +string csvStringWithBooleanValues8 = string `b1,b2,b3,b4 +true,false,true1,false1 +true,false, true1,false1 +true,false,true1,false1 +`; diff --git a/ballerina-tests/type-compatible-tests/tests/csv_content_2.txt b/ballerina-tests/type-compatible-tests/tests/csv_content_2.txt new file mode 100644 index 0000000..c2d88ba --- /dev/null +++ b/ballerina-tests/type-compatible-tests/tests/csv_content_2.txt @@ -0,0 +1,4 @@ +a, b, c d, e +"Hello World1", \"Hello World2\", Hello World3, 21 +"Hello World1", \"Hello World2\", Hello World3, 22 +"Hello World1", \"Hello World2\", Hello World3, 23 \ No newline at end of file diff --git a/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal b/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal new file mode 100644 index 0000000..728d683 --- /dev/null +++ b/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal @@ -0,0 +1,58 @@ +import ballerina/data.csv; +import ballerina/test; + +type Book1 record { + ()|string name; + ()|string author; + ()|string year; +}; + +string csvString1 = string `name,author,year + ,b,c + a,,c + a,b,`; + +@test:Config{} +function testEmptyStringWithNilConfig() { + Book1[]|error books1 = csv:parseString(csvString1, {nilValue: ""}); + test:assertEquals(books1, [ + {name: null, author: "b", year: "c"}, + {name: "a", author: null, year: "c"}, + {name: "a", author: "b", year: null} + ]); + + Book1[]|error books2 = csv:parseString(csvString1); + test:assertEquals(books2, [ + {name: "", author: "b", year: "c"}, + {name: "a", author: "", year: "c"}, + {name: "a", author: "b", year: ""} + ]); + + (boolean|()|string|int)[][]|error arrbooks1 = csv:parseString(csvString1, {nilValue: ""}); + test:assertEquals(arrbooks1, [ + [null, "b", "c"], + ["a", null, "c"], + ["a", "b", null] + ]); + + (boolean|()|string|int)[][2]|error arrbooks2 = csv:parseString(csvString1, {nilValue: ""}); + test:assertEquals(arrbooks2, [ + [null, "b"], + ["a", null], + ["a", "b"] + ]); + + (boolean|()|string|int)[][]|error arrbooks3 = csv:parseString(csvString1); + test:assertEquals(arrbooks3, [ + ["", "b", "c"], + ["a", "", "c"], + ["a", "b", ""] + ]); + + (boolean|()|string|int)[][2]|error arrbooks4 = csv:parseString(csvString1); + test:assertEquals(arrbooks4, [ + ["", "b"], + ["a", ""], + ["a", "b"] + ]); +} 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 bacada9..3aca53a 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 @@ -20,6 +20,7 @@ import ballerina/io; import ballerina/test; const string filepath = "tests/csv_content.txt"; +const string filepath2 = "tests/csv_content_2.txt"; const string errorFilepath = "tests/csv_error_content.txt"; @test:Config @@ -215,6 +216,7 @@ function testSpaceBetweendData() { @test:Config function testParseBytes() returns error? { byte[] csvBytes = check io:fileReadBytes(filepath); + byte[] csvBytes2 = check io:fileReadBytes(filepath2); record{}[]|csv:Error rec = csv:parseBytes(csvBytes, {}); test:assertEquals(rec, [ @@ -245,17 +247,17 @@ function testParseBytes() returns error? { ["Hello World", "\"Hello World\"", "Hello World", "2"] ]); - rec2 = csv:parseBytes(csvBytes, {outputWithHeaders: true, header: 1}); + rec2 = csv:parseBytes(csvBytes2, {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"] + ["Hello World1", "\"Hello World2\"", "Hello World3", "21"], + ["Hello World1", "\"Hello World2\"", "Hello World3", "22"], + ["Hello World1", "\"Hello World2\"", "Hello World3", "23"] ]); - rec2 = csv:parseBytes(csvBytes, { header: 1}); + rec2 = csv:parseBytes(csvBytes2, { header: 1}); test:assertEquals(rec2, [ - ["Hello World", "\"Hello World\"", "Hello World", "2"], - ["Hello World", "\"Hello World\"", "Hello World", "2"] + ["Hello World1", "\"Hello World2\"", "Hello World3", "22"], + ["Hello World1", "\"Hello World2\"", "Hello World3", "23"] ]); int[][]|csv:Error rec3 = csv:parseBytes(csvBytes, {}); @@ -270,6 +272,8 @@ function testParseBytes() returns error? { @test:Config function testParseStream() returns error? { stream csvByteStream = check io:fileReadBlocksAsStream(filepath); + stream csvByteStream2 = check io:fileReadBlocksAsStream(filepath2); + record{}[]|csv:Error rec = csv:parseStream(csvByteStream, {}); test:assertEquals(rec, [ {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}, @@ -293,12 +297,11 @@ function testParseStream() returns error? { ["Hello World", "\"Hello World\"", "Hello World", "2"] ]); - csvByteStream = check io:fileReadBlocksAsStream(filepath); - rec2 = csv:parseStream(csvByteStream, {header: 1, outputWithHeaders: true}); + rec2 = csv:parseStream(csvByteStream2, {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"] + ["Hello World1", "\"Hello World2\"", "Hello World3", "21"], + ["Hello World1", "\"Hello World2\"", "Hello World3", "22"], + ["Hello World1", "\"Hello World2\"", "Hello World3", "23"] ]); csvByteStream = check io:fileReadBlocksAsStream(filepath); @@ -310,11 +313,11 @@ function testParseStream() returns error? { ["Hello World", "\"Hello World\"", "Hello World", "2"] ]); - csvByteStream = check io:fileReadBlocksAsStream(filepath); + csvByteStream = check io:fileReadBlocksAsStream(filepath2); rec2 = csv:parseStream(csvByteStream, {header: 1}); test:assertEquals(rec2, [ - ["Hello World", "\"Hello World\"", "Hello World", "2"], - ["Hello World", "\"Hello World\"", "Hello World", "2"] + ["Hello World1", "\"Hello World2\"", "Hello World3", "22"], + ["Hello World1", "\"Hello World2\"", "Hello World3", "23"] ]); csvByteStream = check io:fileReadBlocksAsStream(filepath); diff --git a/ballerina-tests/user-config-tests/tests/test_data_values.bal b/ballerina-tests/user-config-tests/tests/test_data_values.bal index f067976..bf329ff 100644 --- a/ballerina-tests/user-config-tests/tests/test_data_values.bal +++ b/ballerina-tests/user-config-tests/tests/test_data_values.bal @@ -121,3 +121,28 @@ string csvStringData9 = string ` 4@ string@ true@ 2.234@ ()@-3.21 5@ string@ true@ 2.234@ -3.21@ null`; + +string csvStringData10 = string ` + hello, hello, (), 12, true, 12.34 + // comment + + a, b, c, d, e, f + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + 4, string4, true, -6.51, -6.52, () + 5, string5, true, 3, 31, ()`; + +string csvStringData11 = string ` + a, b, c, d, e, f + + + + 1, string1, true, 2.234, 2.234, () + 2, string2, false, 0, 0, null + 3, string3, false, 1.23, 1.23, () + + 4, string4, true, -6.51, -6.52, () + 5, string5, true, 3, 3, ()`; 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 10a83a9..6be4c25 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 @@ -125,9 +125,9 @@ function testFromCsvStringWithParserOptions() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: "()"} ]); - record {}[]|csv:Error csv3op3_4 = csv:parseString(csvStringData3, {header: 9, skipLines: "2-10"}); + record {}[]|csv:Error csv3op3_4 = csv:parseString(csvStringData11, {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, "-6.52": 3, "()": null} ]); } @@ -203,15 +203,19 @@ function testHeaderOption() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - record {}[]|csv:Error csv2cop2 = csv:parseString(csvStringData2, {header: 100}); + record {}[]|csv:Error csv2cop2 = csv:parseString(csvStringData10, {header: 100}); test:assertTrue(csv2cop2 is csv:Error); test:assertEquals((csv2cop2).message(), "The provided header row is empty"); - record {}[]|csv:Error csv2cop3 = csv:parseString(csvStringData2, {header: 11}); + record {}[]|csv:Error csv2cop3 = csv:parseString(csvStringData10, {header: 11}); test:assertEquals(csv2cop3, []); - record {}[]|csv:Error csv2cop4 = csv:parseString(csvStringData2, {header: 10}); - test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", "true": true, "-6.51": 3, "()": ()}]); + record {}[]|csv:Error csv2cop3_2 = csv:parseString(csvStringData10, {header: 9}); + test:assertTrue(csv2cop3_2 is csv:Error); + test:assertEquals((csv2cop3_2).message(), "Duplicate header found: '1.23'"); + + record {}[]|csv:Error csv2cop4 = csv:parseString(csvStringData10, {header: 10}); + test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", "true": true, "-6.51": 3, "-6.52": 31, "()": ()}]); record {}[]|csv:Error csv1cop5 = csv:parseString(csvStringData1, {}); test:assertTrue(csv1cop5 is csv:Error); @@ -313,6 +317,9 @@ function testCommentConfigOption() { string csvValue9 = string `a,# b 1 ,#2 # comment # comment`; + string csvValue10 = string `a# b + 1 ,#2 # comment + # comment`; record {int a;}[]|csv:Error cn; @@ -345,8 +352,13 @@ function testCommentConfigOption() { // TODO:Fix the error message // test:assertEquals(( cn).message(), common:generateErrorMessageForInvalidCast("1, 2", "int")); + cn = csv:parseString(csvValue10); + test:assertTrue(cn is csv:Error); + test:assertEquals(( cn).message(), "Invalid length for the headers"); + cn = csv:parseString(csvValue9); - test:assertEquals(cn, [{a: 1}]); + test:assertTrue(cn is csv:Error); + test:assertEquals(( cn).message(), "The provided header row is empty"); } @test:Config {dependsOn: [testCSVLocale]} @@ -375,6 +387,20 @@ function testCommentConfigOption2() { & comment`; + string csvValue7 = string ` + + a& b + 1 ,&2 & comment + + & comment`; + + string csvValue8 = string ` + + a,e& b + 1 ,&2 & comment + + & comment`; + record {int a; int b;}[]|csv:Error cn; record {int c;}[]|csv:Error cn2; @@ -401,8 +427,16 @@ function testCommentConfigOption2() { cn = csv:parseString(csvValue6, {comment: "&", header: 2}); test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), "The provided header row is empty"); + + cn = csv:parseString(csvValue8, {comment: "&", header: 2}); + test:assertTrue(cn is csv:Error); test:assertEquals((cn).message(), common:generateErrorMessageForMissingRequiredField("b")); + cn = csv:parseString(csvValue7, {comment: "&", header: 2}); + test:assertTrue(cn is csv:Error); + test:assertEquals((cn).message(), "Invalid length for the headers"); + cn2 = csv:parseString(csvValue1, {comment: "&"}); test:assertTrue(cn2 is csv:Error); test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); @@ -426,7 +460,7 @@ function testCommentConfigOption2() { cn2 = csv:parseString(csvValue6, {header: 2, comment: "&"}); test:assertTrue(cn2 is csv:Error); - test:assertEquals((cn2).message(), common:generateErrorMessageForMissingRequiredField("c")); + test:assertEquals((cn2).message(), "The provided header row is empty"); } @test:Config {dependsOn: [testCSVLocale]} 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 c7a2c4c..174e97c 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 @@ -66,9 +66,9 @@ static Object initRowValue(Type expectedType) { }; } - static void convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, - String value, Type type, CsvConfig config, Type exptype, - Field currentField) { + static void convertAndUpdateCurrentCsvNode(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() @@ -91,6 +91,7 @@ static void convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, case TypeTags.RECORD_TYPE_TAG: ((BMap) currentCsv).put(StringUtils.fromString(getHeaderValueForColumnIndex(sm)), convertedValue); + sm.currentCsvNodeLength++; return; case TypeTags.ARRAY_TAG: ArrayType arrayType = (ArrayType) currentCsvNodeType; @@ -99,9 +100,11 @@ static void convertAndUpdateCurrentJsonNode(CsvParser.StateMachine sm, return; } ((BArray) currentCsv).add(sm.columnIndex, convertedValue); + sm.currentCsvNodeLength++; return; case TypeTags.TUPLE_TAG: ((BArray) currentCsv).add(sm.columnIndex, convertedValue); + sm.currentCsvNodeLength++; return; default: } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java index d353eb2..cf7aaa8 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 @@ -145,6 +145,7 @@ static class StateMachine { State prevState; int arraySize = 0; boolean addHeadersForOutput = false; + int currentCsvNodeLength = 0; StateMachine() { reset(); @@ -180,6 +181,7 @@ public void reset() { prevState = null; arraySize = 0; addHeadersForOutput = false; + currentCsvNodeLength = 0; } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -438,9 +440,7 @@ private static void handleEndOfTheHeader(StateMachine sm) throws CsvParserExcept private static void handleEndOfTheHeader(StateMachine sm, boolean trim) throws CsvParserException { sm.isValueStart = false; - if (!sm.peek().isBlank()) { - addHeader(sm, trim); - } + addHeader(sm, trim); finalizeHeaders(sm); sm.columnIndex = 0; sm.lineNumber++; @@ -497,6 +497,9 @@ private static void addHeader(StateMachine sm, boolean trim) { if (trim) { value = value.trim(); } + if (value.isEmpty()) { + throw DiagnosticLog.error(DiagnosticErrorCode.HEADER_CANNOT_BE_EMPTY); + } if (sm.expectedArrayElementType instanceof RecordType) { String fieldName = CsvUtils.getUpdatedHeaders( sm.updatedRecordFieldNames, value, sm.fields.contains(value)); @@ -506,6 +509,9 @@ private static void addHeader(StateMachine sm, boolean trim) { sm.fieldHierarchy.remove(fieldName); } } + if (sm.headers.contains(value)) { + throw DiagnosticLog.error(DiagnosticErrorCode.DUPLICATE_HEADER, value); + } sm.headers.add(value); } @@ -631,7 +637,7 @@ private static void handleCsvRow(StateMachine sm, boolean trim) { if (trim) { value = value.trim(); } - if (!value.isBlank()) { + if (!(value.isBlank() && sm.currentCsvNodeLength == 0)) { addRowValue(sm, trim); } if (!sm.isCurrentCsvNodeEmpty) { @@ -652,6 +658,7 @@ private static void updateLineAndColumnIndexesWithoutRowIndexes(StateMachine sm) sm.currentCsvNode = null; sm.isCurrentCsvNodeEmpty = true; sm.columnIndex = 0; + sm.clear(); } private static boolean ignoreRow(long[] skipLines, int lineNumber) { @@ -693,6 +700,7 @@ private static void finalizeTheRow(StateMachine sm) { sm.rootCsvNode.add(sm.arraySize, sm.currentCsvNode); } sm.arraySize++; + sm.currentCsvNodeLength = 0; } private static void addRowValue(StateMachine sm) { @@ -715,7 +723,7 @@ private static void addRowValue(StateMachine sm, boolean trim) { } if (type != null) { - CsvCreator.convertAndUpdateCurrentJsonNode(sm, + CsvCreator.convertAndUpdateCurrentCsvNode(sm, value, type, sm.config, exptype, currentField); } sm.columnIndex++; @@ -731,7 +739,7 @@ private static void addHeaderAsRowValue(StateMachine sm, String value) { } if (type != null) { - CsvCreator.convertAndUpdateCurrentJsonNode(sm, + CsvCreator.convertAndUpdateCurrentCsvNode(sm, value, type, sm.config, exptype, currentField); } sm.columnIndex++; @@ -1023,7 +1031,6 @@ private void reset(StateMachine sm) { private char extractUnicodeChar(StateMachine sm) { return StringEscapeUtils.unescapeJava("\\u" + sm.hexBuilder.toString()).charAt(0); } - } /** 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 32e9941..82df3a5 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java @@ -53,7 +53,9 @@ public enum DiagnosticErrorCode { 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"); + "headers.with.varying.length.not.supported"), + HEADER_VALUE_CANNOT_BE_EMPTY("BDE_0028", "header.value.cannot.be.empty"), + DUPLICATE_HEADER("BDE_0029", "duplicate.header"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/csv_error.properties b/native/src/main/resources/csv_error.properties index d653d87..ff9a22e 100644 --- a/native/src/main/resources/csv_error.properties +++ b/native/src/main/resources/csv_error.properties @@ -103,4 +103,10 @@ 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 + CSV data rows with varying headers are not yet supported + +error.header.value.cannot.be.empty=\ + Header cannot be empty + +error.duplicate.header=\ + Duplicate header found: ''{0}'' From 40eef579819f654f26ad1b55fd4311cee3cc3b6e Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 12 Aug 2024 11:48:46 +0530 Subject: [PATCH 130/147] Refactor user configuration parameter --- .../tests/constraint_validation_test.bal | 6 +- .../tests/parse_list_type_as_list_test.bal | 60 +++++++++---------- .../tests/parse_list_type_as_record_test.bal | 38 ++++++------ .../tests/test_union_types_with_headers.bal | 10 ++-- .../user_config_with_parser_options_test.bal | 52 ++++++++-------- ballerina/types.bal | 35 ++++++++--- .../lib/data/csvdata/csv/CsvCreator.java | 2 +- .../lib/data/csvdata/csv/CsvParser.java | 12 ++-- .../lib/data/csvdata/csv/CsvTraversal.java | 28 ++++----- .../lib/data/csvdata/utils/Constants.java | 4 +- .../lib/data/csvdata/utils/CsvConfig.java | 12 ++-- .../lib/data/csvdata/utils/CsvUtils.java | 8 +-- 12 files changed, 143 insertions(+), 124 deletions(-) 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 de74848..56db0c6 100644 --- a/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal +++ b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal @@ -38,7 +38,7 @@ function testConstraintWithLists() returns error? { ConstrainedList|csv:Error cList1 = csv:parseString(string `1 2 3 - 4`, {header: false, customHeadersIfHeaderAbsent: ["a", "b", "c", "d"]}); + 4`, {header: false, customHeadersIfHeadersAbsent: ["a", "b", "c", "d"]}); test:assertEquals(cList1, [[1], [2], [3], [4]]); cList1 = csv:parseString(string `1 @@ -46,7 +46,7 @@ function testConstraintWithLists() returns error? { 3 4 5 - 6`, {header: false, customHeadersIfHeaderAbsent: ["a", "b", "c", "d", "e", "f"]}); + 6`, {header: false, customHeadersIfHeadersAbsent: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(cList1 is csv:Error); test:assertTrue((cList1).message().startsWith("Validation failed") && (cList1).message().includes("length")); @@ -56,7 +56,7 @@ function testConstraintWithLists() returns error? { 3 4 5 - 6`, {header: false, customHeadersIfHeaderAbsent: ["a", "b", "c", "d", "e", "f"], enableConstraintValidation: false}); + 6`, {header: false, customHeadersIfHeadersAbsent: ["a", "b", "c", "d", "e", "f"], enableConstraintValidation: false}); test:assertEquals(cList1, [[1], [2], [3], [4], [5], [6]]); cList1 = csv:transform([{"a": 1}, {"a": 1}, {"a": 1}, {"a": 1}], {}); 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 1bd498c..086e760 100644 --- a/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal +++ b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal @@ -450,119 +450,119 @@ function testArrayIndexes() { @test:Config function testParseListsWithOutputHeaders() { - [string, boolean, int][]|csv:Error ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); + [string, boolean, int][]|csv:Error ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1}); test:assertEquals(ct1bt1, [ ["a", true, 1] ]); - ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); + ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headersRows: 2}); test:assertEquals(ct1bt1, []); - ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1, [ ["a", true, 1] ]); - ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21}); + ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21}); test:assertEquals(ct1bt1, []); - (string|boolean|int)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); + (string|boolean|int)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1}); test:assertEquals(ct1bt1_2, [ ["a", true, 1] ]); - ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); + ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headersRows: 2}); test:assertEquals(ct1bt1_2, []); - ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1_2, [ ["a", true, 1] ]); - ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1_2, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21}); + ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21}); test:assertEquals(ct1bt1_2, []); - [string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); + [string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_3, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 2, outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), "Custom headers should be provided"); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headersRows: 2, outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), "Custom headers should be provided"); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean")); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean")); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21, outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21, outputWithHeaders: true}); test:assertEquals(ct1bt1_3, []); - string[][]|csv:Error ct1bt1_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); + string[][]|csv:Error ct1bt1_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_4, [ ["a", "b", "c"], ["a", "true", "1"] ]); - ct1bt1_4 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_4 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_4, [ ["h1", "h2", "h3"], ["a", "true", "1"], ["a", "true", "1"] ]); - (int|boolean|string)[][]|csv:Error ct1bt1_4_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); + (int|boolean|string)[][]|csv:Error ct1bt1_4_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_4_2, [ ["a", "b", "c"], ["a", true, 1] ]); - string[][]|csv:Error ct1bt1_4_3 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + string[][]|csv:Error ct1bt1_4_3 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headersRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_4_3, [ ["h1", "h2", "h3"], ["a", "true", "1"], ["a", "true", "1"] ]); - (int|boolean|string)[][]|csv:Error ct1bt1_4_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + (int|boolean|string)[][]|csv:Error ct1bt1_4_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_4_4, [ ["h1", "h2", "h3"] ]); - [string, boolean|string, int|string][]|csv:Error ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string, boolean|string, int|string][]|csv:Error ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - ct1bt1_5 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_5 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1], @@ -575,35 +575,35 @@ function testParseListsWithOutputHeaders() { ["1", "a"] ]); - [string, boolean|string, int|string...][]|csv:Error ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string, boolean|string, int|string...][]|csv:Error ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt2_2, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - [string...][]|csv:Error ct1bt2_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string...][]|csv:Error ct1bt2_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt2_3, [ ["h1", "h2", "h3"], ["a", "true", "1"] ]); - ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt2_2, [ ["h1", "h2", "h3"], ["a", true, 1], ["a", true, 1] ]); - string[2][1]|csv:Error ct1bt6 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + string[2][1]|csv:Error ct1bt6 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headersRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt6, [ ["h1"], ["a"] ]); - [string, boolean|string, int|string...][1]|csv:Error ct1bt6_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string, boolean|string, int|string...][1]|csv:Error ct1bt6_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt6_2, [ ["h1", "h2", "h3"] ]); - [string...][1]|csv:Error ct1bt6_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string...][1]|csv:Error ct1bt6_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt6_3, [ ["h1", "h2", "h3"] ]); 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 d1c2fa1..848e76e 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 @@ -551,20 +551,20 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { - record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 0, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 0, customHeaders: ["a", "c", "b"], 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"]}); + record{string a; boolean b; int c;}[]|csv:Error ct1br4_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"]}); 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}); + record{string a; boolean b; int c;}[]|csv:Error ct1br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); test:assertEquals(ct1br4_3, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} @@ -572,60 +572,60 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { 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}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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}); + map[]|csv:Error ct2br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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}); + map[]|csv:Error ct2br4_3_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, outputWithHeaders: true}); test:assertEquals(ct2br4_8, [ {"a": "a", "1": "1", "true": "true"}, {"a": "a", "1": "1", "true": "true"}, @@ -633,7 +633,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_8_2 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, outputWithHeaders: false}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, outputWithHeaders: false}); test:assertEquals(ct2br4_8_2, [ {"a": "a", "1": "1", "true": "true"}, {"a": "a", "1": "1", "true": "true"}, @@ -641,7 +641,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_9 = csv:parseList( - [["a", "c", "b"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1, outputWithHeaders: true}); + [["a", "c", "b"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1, outputWithHeaders: true}); test:assertEquals(ct2br4_9, [ {a: "a", b: "true", c: "2"}, {a: "a", b: "true", c: "3"}, @@ -650,7 +650,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_10 = csv:parseList( - [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1, outputWithHeaders: true}); + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1, outputWithHeaders: true}); test:assertEquals(ct2br4_10, [ {a: "a", c: true, b: 2}, {a: "a", c: true, b: 3}, @@ -659,7 +659,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_10_2 = csv:parseList( - [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1, outputWithHeaders: false}); + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1, outputWithHeaders: false}); test:assertEquals(ct2br4_10_2, [ {a: "a", c: true, b: 2}, {a: "a", c: true, b: 3}, @@ -668,7 +668,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); 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}); + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1, customHeaders: ["c", "d", "e"], outputWithHeaders: false}); test:assertEquals(ct2br4_10_2, [ {c: "a", e: true, d: 2}, {c: "a", e: true, d: 3}, diff --git a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal index 7066c6d..9b03961 100644 --- a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal +++ b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal @@ -9,12 +9,12 @@ 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 op7 = {outputWithHeaders: true, headersRows: 1}; +csv:ParseListOptions op8 = {outputWithHeaders: true, headersRows: 2}; +csv:ParseListOptions op9 = {outputWithHeaders: true, headersRows: 2, customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListOptions op10 = {outputWithHeaders: true, headersRows: 1, customHeaders: ["a", "b", "c", "d"]}; csv:ParseListOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListOptions op12 = {headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +csv:ParseListOptions op12 = {headersRows: 1, customHeaders: ["a", "b", "c", "d"]}; csv:ParseListOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; type UnionType1 boolean[][]|string[][]; 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 6be4c25..91d84f2 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 @@ -657,7 +657,7 @@ function testCustomHeaderOption() { @test:Config function testCustomHeaderParserOption2() { - record {}[]|csv:Error ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["a", "b"]}); + record {}[]|csv:Error ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeadersAbsent: ["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: ()}, @@ -666,7 +666,7 @@ function testCustomHeaderParserOption2() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["f", "e", "d", "c", "b", "a"]}); + ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeadersAbsent: ["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: ()}, @@ -675,7 +675,7 @@ function testCustomHeaderParserOption2() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeaderAbsent: ["b", "a"]}); + ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeadersAbsent: ["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: ()}, @@ -684,15 +684,15 @@ function testCustomHeaderParserOption2() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - record {}[]|csv:Error ct1br2 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: []}); + record {}[]|csv:Error ct1br2 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: []}); test:assertTrue(ct1br2 is csv:Error); 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:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["a", "b"]}); + record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br3 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); test:assertTrue(ct1br3 is csv:Error); test:assertEquals((ct1br3).message(), "Invalid length for the headers"); - 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"]}); + record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br4 = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeadersAbsent: ["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: ()}, @@ -701,10 +701,10 @@ function testCustomHeaderParserOption2() { {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"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5 = csv:parseString(csvStringData4, {header: 1, customHeadersIfHeadersAbsent: ["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"]}); + ct1br5 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["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: ()}, @@ -713,7 +713,7 @@ function testCustomHeaderParserOption2() { {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"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_2 = csv:parseString(csvStringData4, {header: false, skipLines: [1], customHeadersIfHeadersAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br5_2, [ {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, @@ -721,7 +721,7 @@ function testCustomHeaderParserOption2() { {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"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_3 = csv:parseString(csvStringData4, {skipLines: [1], header: false, customHeadersIfHeadersAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br5_3, [ {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, @@ -729,7 +729,7 @@ function testCustomHeaderParserOption2() { {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"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br7 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -738,7 +738,7 @@ function testCustomHeaderParserOption2() { {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"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br7_2 = csv:parseString(csvStringData4, {header: false, skipLines: [1], customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7_2, [ {e1: "string2", d1: false}, {e1: "string3", d1: false}, @@ -746,11 +746,11 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br8 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["e1", "d1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br8 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["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:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br9 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br9, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -759,11 +759,11 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1"]}); test:assertTrue(ct1br11 is csv:Error); test:assertEquals((ct1br11).message(), "Invalid length for the headers"); - record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ {e1: "string1", d1: "true"}, {e1: "string2", d1: "false"}, @@ -772,7 +772,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: "true"} ]); - record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeaderAbsent: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); + record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); test:assertTrue(ct1br13 is csv:Error); test:assertEquals((ct1br13).message(), common:generateErrorMessageForMissingRequiredField("d1")); } @@ -1001,30 +1001,30 @@ function testSkipLineParameterWithOutputHeaderConfig() { result2 = csv:parseList(csv2, {outputWithHeaders: true, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [1, 2], [4, 5]]); - result = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + result = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 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"]}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 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"]}); + result = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 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"]}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 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"}); + result = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 1, skipLines: "2-3"}); test:assertEquals(result, [{'1: 2, '2: 3}]); - result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 1, skipLines: "2-3"}); test:assertEquals(result2, [[1, 2], [2, 3]]); - result2 = csv:parseList(csv2, {outputWithHeaders: false, headerRows: 1, skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: false, headersRows: 1, skipLines: "2-3"}); test:assertEquals(result2, [[2, 3]]); - result = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); + result = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 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"}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); test:assertEquals(result2, [["a", "b"], [3, 4]]); } diff --git a/ballerina/types.bal b/ballerina/types.bal index 030adb9..c825679 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -1,7 +1,20 @@ +// Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +// +// WSO2 LLC. licenses this file to you under the Apache License, +// Version 2.0 (the "License"); you may not use this file except +// in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + # Represents an error. -# -# This type is used to capture error details that occur during the execution of a program. -# It can hold an error message, an optional error cause, and an optional map of additional details. public type Error error; # Defines the name of the JSON Object key. @@ -18,7 +31,8 @@ public const annotation NameConfig Name on record field; 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: + # This configuration can be either a record or a boolean. + # If it's a record, it contains `nilAsOptionalField` and `absentAsNilableType` options. # If it's set to `false`, data projection is not allowed. record { # If `true`, nil values will be considered as optional fields in the projection. @@ -30,8 +44,7 @@ public type Options record { 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[][]` + # If `true`, when the result is a list it will contain headers as the first row. boolean outputWithHeaders = false; }; @@ -57,7 +70,7 @@ public type ParseOptions record {| # 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 = (); + string[]? customHeadersIfHeadersAbsent = (); |}; # Represents options for treating a list as a record. @@ -65,7 +78,7 @@ public type ParseListOptions record {| *Options; # If `0`, all the source data will treat as data rows. # Otherwise specify the header rows(Starts from 1) in the source data. - int:Unsigned32 headerRows = 0; + int:Unsigned32 headersRows = 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. @@ -82,14 +95,20 @@ public type TransformOptions record {| # Enum representing possible line terminators. public enum LineTerminator { + # Line Feed (LF) line terminator: `\n` LF = "\n", + # Carriage Return and Line Feed (CRLF) line terminator: `\r\n` CRLF = "\r\n" }; # Enum representing possible nil values. public enum NilValue { + # Represents a nil value as the string "null". NULL = "null", + # Represents a nil value as "N/A". NOT_APPLICABLE = "N/A", + # Represents an empty string as a nil value. EMPTY_STRING = "", + # Represents a nil value as Ballerina nil value `()`. BAL_NULL = "()" }; 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 174e97c..06741f4 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 @@ -111,7 +111,7 @@ static void convertAndUpdateCurrentCsvNode(CsvParser.StateMachine sm, } public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { - if (sm.config.customHeadersIfHeaderAbsent == null && (sm.config.header == Boolean.FALSE)) { + if (sm.config.customHeadersIfHeadersAbsent == null && (sm.config.header == Boolean.FALSE)) { String header = String.valueOf(sm.columnIndex + 1); Map fieldHierarchy = sm.fieldHierarchy; fieldHierarchy.remove(header); 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 cf7aaa8..7cb9684 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 @@ -273,17 +273,17 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp expectedArrayElementType); case TypeTags.UNION_TAG: boolean outputHeaders = config.outputWithHeaders; - Object customHeaders = config.customHeadersIfHeaderAbsent; + Object customHeaders = config.customHeadersIfHeadersAbsent; 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; + config.customHeadersIfHeadersAbsent = this.headers; } if (customHeaders != null) { - config.customHeadersIfHeaderAbsent = customHeaders; + config.customHeadersIfHeadersAbsent = customHeaders; } return CsvTraversal.traverse((BArray) mapValue, config, bTypedesc); default: @@ -295,9 +295,9 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp if (config.header != Boolean.FALSE) { currentState = HEADER_START_STATE; } else { - Object customHeadersIfHeaderAbsent = config.customHeadersIfHeaderAbsent; - if (customHeadersIfHeaderAbsent != null) { - CsvCreator.addCustomHeadersIfNotNull(this, customHeadersIfHeaderAbsent); + Object customHeadersIfHeadersAbsent = config.customHeadersIfHeadersAbsent; + if (customHeadersIfHeadersAbsent != null) { + CsvCreator.addCustomHeadersIfNotNull(this, customHeadersIfHeadersAbsent); } currentState = ROW_START_STATE; addFieldNamesForNonHeaderState(); 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 4c03daa..211ee64 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 @@ -272,11 +272,11 @@ public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type e } Object o = csv.get(i); - if (i < config.headerRows && i != config.headerRows - 1) { + if (i < config.headersRows && i != config.headersRows - 1) { continue; } - if (i >= config.headerRows && ignoreRow(rowNumber + 1, config.skipLines)) { + if (i >= config.headersRows && ignoreRow(rowNumber + 1, config.skipLines)) { rowNumber++; continue; } @@ -290,7 +290,7 @@ public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type e rootCsvNode.add(this.arraySize, rowValue); this.arraySize++; } - if (i >= config.headerRows) { + if (i >= config.headersRows) { rowNumber++; } } @@ -310,11 +310,11 @@ public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expe Object o = csv.get(i); if (!addHeadersForOutput && config.outputWithHeaders - && (o instanceof BMap || (config.customHeaders != null || i == config.headerRows - 1))) { + && (o instanceof BMap || (config.customHeaders != null || i == config.headersRows - 1))) { // Headers will add to the list only in the first iteration insertHeaderValuesForTheCsvIfApplicable(o, expectedArrayType); } - if (i < config.headerRows) { + if (i < config.headersRows) { continue; } @@ -365,11 +365,11 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, } if (CsvUtils.isExpectedTypeIsMap(memberType)) { - if (i < config.headerRows && i != config.headerRows - 1) { + if (i < config.headersRows && i != config.headersRows - 1) { continue outerLoop; } - if (i >= config.headerRows && ignoreRow(rowNumber + 1, config.skipLines)) { + if (i >= config.headersRows && ignoreRow(rowNumber + 1, config.skipLines)) { rowNumber++; continue outerLoop; } @@ -377,11 +377,11 @@ public void traverseCsvWithUnionExpectedType(long length, BArray csv, } else if (CsvUtils.isExpectedTypeIsArray(memberType)) { if (!addHeadersForOutput && config.outputWithHeaders && (o instanceof BMap || (config.customHeaders != null - || i == config.headerRows - 1))) { + || i == config.headersRows - 1))) { // Headers will add to the list only in the first iteration insertHeaderValuesForTheCsvIfApplicable(o, memberType); } - if (i < config.headerRows) { + if (i < config.headersRows) { continue outerLoop; } @@ -530,8 +530,8 @@ private void constructCsvMapFromNonMapping(BArray csvElement, String[] headers = new String[csvElement.size()]; if (this.headers == null) { this.headers = CsvUtils.createHeadersForParseLists(csvElement, headers, config); - if (!this.isFirstRowInserted && config.headerRows >= 1) { - // To skip the row at the position [config.headerRows - 1] from being added to the result. + if (!this.isFirstRowInserted && config.headersRows >= 1) { + // To skip the row at the position [config.headersRows - 1] from being added to the result. this.isFirstRowIsHeader = true; this.isFirstRowInserted = true; return; @@ -606,12 +606,12 @@ private void insertHeaderValuesForTheCsvIfApplicable(Object obj, Type type) { 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) { + String[] order = ((BArray) headersOrder).getStringArray(); + if (order.length != size) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_HEADER_NAMES_LENGTH); } for (int i = 0; i < size; i++) { - keys[i] = StringUtils.fromString(headerOrder[i]); + keys[i] = StringUtils.fromString(order[i]); } } else { if (headersForArrayConversion == null) { 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 3205e02..8b12602 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java @@ -27,9 +27,9 @@ public final class ConfigConstants { public static final BString ENABLE_CONSTRAINT_VALIDATION = StringUtils. fromString("enableConstraintValidation"); public static final BString OUTPUT_WITH_HEADERS = StringUtils.fromString("outputWithHeaders"); - public static final BString HEADER_ROWS = StringUtils.fromString("headerRows"); + public static final BString HEADER_ROWS = StringUtils.fromString("headersRows"); public static final BString CUSTOM_HEADERS_IF_HEADER_ABSENT = - StringUtils.fromString("customHeadersIfHeaderAbsent"); + StringUtils.fromString("customHeadersIfHeadersAbsent"); public static final BString CUSTOM_HEADERS = StringUtils.fromString("customHeaders"); public static final BString HEADERS_ORDER = StringUtils.fromString("headersOrder"); 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 dd6bd56..eae6a63 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 @@ -26,8 +26,8 @@ public class CsvConfig { public boolean stringConversion = false; public boolean enableConstraintValidation = false; public boolean outputWithHeaders = false; - public Object customHeadersIfHeaderAbsent = null; - public long headerRows = 0; + public Object customHeadersIfHeadersAbsent = null; + public long headersRows = 0; public Object customHeaders = null; private CsvConfig(CsvConfig config) { @@ -58,14 +58,14 @@ public static CsvConfig createParseListOptions(BMap options) { public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, Object skipLines, boolean enableConstraintValidation, boolean outputWithHeaders, - long headerRows, Object headers) { + long headersRows, Object headers) { this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; this.skipLines = skipLines; this.enableConstraintValidation = enableConstraintValidation; this.outputWithHeaders = outputWithHeaders; - this.headerRows = headerRows; + this.headersRows = headersRows; this.customHeaders = headers; } @@ -118,7 +118,7 @@ public static CsvConfig createParseOptions(BMap options) { 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) { + Object nilValue, char comment, Object header, Object customHeadersIfHeadersAbsent) { this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; @@ -133,7 +133,7 @@ public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolea this.nilValue = nilValue; this.comment = comment; this.header = header; - this.customHeadersIfHeaderAbsent = customHeadersIfHeaderAbsent; + this.customHeadersIfHeadersAbsent = customHeadersIfHeadersAbsent; } public static CsvConfig createConfigOptionsForUnion(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 b7ff4c6..f891145 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 @@ -74,7 +74,7 @@ public static boolean isBasicType(Type type) { public static String[] createHeadersForParseLists(BArray csvElement, String[] headers, CsvConfig config) { Object customHeaders = config.customHeaders; - long headerRows = config.headerRows; + long headersRows = config.headersRows; int length = headers.length; if (customHeaders instanceof BArray array) { @@ -87,15 +87,15 @@ public static String[] createHeadersForParseLists(BArray csvElement, String[] he return headers; } - if (headerRows == 1) { + if (headersRows == 1) { return csvElement.getStringArray(); } - if (headerRows > 1) { + if (headersRows > 1) { throw DiagnosticLog.error(DiagnosticErrorCode.NO_CUSTOM_HEADER_PROVIDED); } - // when headerRows = 0 and customHeaders = null + // when headersRows = 0 and customHeaders = null for (int i = 0; i < length; i++) { headers[i] = String.valueOf(i + 1); } From 23f2145495e4606727f72ee5d27fb7d48d47ae82 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 12 Aug 2024 23:53:21 +0530 Subject: [PATCH 131/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 0bfd723..7516162 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0-20240801-104200-87df251c" +distribution-version = "2201.9.2" [[package]] org = "ballerina" From dae0fe5c400cdb18623e1daebe31dab9e964c2ea Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 12 Aug 2024 23:53:39 +0530 Subject: [PATCH 132/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 7516162..0bfd723 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.2" +distribution-version = "2201.10.0-20240801-104200-87df251c" [[package]] org = "ballerina" From 563d7e8e61d5359c4daa08fe3dad63153a4b5b27 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 13 Aug 2024 01:55:38 +0530 Subject: [PATCH 133/147] Add compiler errors for ignored parameters --- .../csvdata/compiler/CompilerPluginTest.java | 108 ++++++++ .../sample_package_10/Ballerina.toml | 8 + .../sample_package_10/main.bal | 58 +++++ .../sample_package_7/Ballerina.toml | 8 + .../sample_package_7/main.bal | 56 +++++ .../sample_package_8/Ballerina.toml | 8 + .../sample_package_8/main.bal | 18 ++ .../sample_package_9/Ballerina.toml | 8 + .../sample_package_9/main.bal | 22 ++ .../lib/data/csvdata/compiler/Constants.java | 15 ++ .../compiler/CsvDataDiagnosticCodes.java | 10 +- .../compiler/CsvDataTypeValidator.java | 238 ++++++++++++++++-- 12 files changed, 530 insertions(+), 27 deletions(-) create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal 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 942f770..aa23f67 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 @@ -43,6 +43,14 @@ public class CompilerPluginTest { "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."; + static final String IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY = "The option 'outputWithHeaders' will be ignored" + + " since the expected type is a subtype record array."; + static final String IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY = "The option 'headersOrder' will be ignored" + + " since the expected type is a subtype record array."; + static final String IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT = "The option " + + "'customHeadersIfHeadersAbsent' will be ignored since the header is present."; + static final String CUSTOM_HEADERS_SHOULD_BE_PROVIDED = "customHeaders parameter should be provided since the" + + " headerRows larger than 1."; @Test public void testInvalidExpectedUnionType() { @@ -148,4 +156,104 @@ public void testInvalidExpectedUnionType2() { Assert.assertEquals(errorDiagnosticsList.get(8).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); Assert.assertEquals(errorDiagnosticsList.get(9).diagnosticInfo().messageFormat(), UNSUPPORTED_TYPE); } + + @Test + public void testIgnoredCustomHeaderIfAbsentOptions() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_7").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 3); + Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(2).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + } + + @Test + public void testIgnoredOutputHeaderOptions() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_8").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 8); + Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(2).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(3).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(4).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(5).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(6).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(7).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + } + + @Test + public void testIgnoredHeadersOrderOptions() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_9").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 7); + Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo() + .messageFormat(), IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(2).diagnosticInfo() + .messageFormat(), IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(3).diagnosticInfo() + .messageFormat(), IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(4).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(5).diagnosticInfo() + .messageFormat(), IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(6).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + } + + @Test + public void testIgnoredCustomHeaderOptions() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_10").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 12); + Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(2).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(3).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(4).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(5).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(6).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(7).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(8).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(9).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + Assert.assertEquals(errorDiagnosticsList.get(10).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(11).diagnosticInfo() + .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + } } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/Ballerina.toml new file mode 100644 index 0000000..5c24b99 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "sample_package_10" +version = "0.1.0" +distribution = "2201.9.2" + +[build-options] +observabilityIncluded = true diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal new file mode 100644 index 0000000..70bbb6e --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal @@ -0,0 +1,58 @@ +import ballerina/data.csv; + +string[]? headers = (); + +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: false}); +record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); + +public function main() returns error? { + record{}[] val = check csv:parseList([["1", "2"]], {headersRows: 0}); + val = check csv:parseList([["1", "2"]], {headersRows: 0}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); + val = check csv:parseList([["1", "2"]], {headersRows: 1}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); + val = check csv:parseList([["1", "2"]], {headersRows: 2}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); + val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); + + record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); +} diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/Ballerina.toml new file mode 100644 index 0000000..1bd2166 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "sample_package_7" +version = "0.1.0" +distribution = "2201.9.2" + +[build-options] +observabilityIncluded = true diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal new file mode 100644 index 0000000..a3cc62c --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal @@ -0,0 +1,56 @@ +import ballerina/data.csv; + +string[] customHeaders = ["a", "b"]; +int:Unsigned32 header = 0; +false header2 = false; + +record{}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); +record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); +record{}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); +record{}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); +record{}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); +record{}[] val6 = check csv:parseString(string `a, b`, {header: false}); +record{}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); +record{}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); +record{}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); +record{}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); +record{}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); +record{}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); + +public function main() returns error? { + record{}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + val = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + + record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); + val2 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ()}); + + record{}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); + val3 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); + + record{}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); + val4 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ()}); + + record{}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); + val5 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ()}); + + record{}[] val6 = check csv:parseString(string `a, b`, {header: false}); + val6 = check csv:parseString(string ``, {header: false}); + + record{}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); + val7 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ["a", "b"]}); + + record{}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); + val8 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: null}); + + record{}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); + val9 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: null}); + + record{}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); + val10 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); + + record{}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); + val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); + + record{}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); + val11 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); +} diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/Ballerina.toml new file mode 100644 index 0000000..52d54d8 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "sample_package_8" +version = "0.1.0" +distribution = "2201.9.2" + +[build-options] +observabilityIncluded = true diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal new file mode 100644 index 0000000..ee021b2 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal @@ -0,0 +1,18 @@ +import ballerina/data.csv; + +boolean o = false; +record{}[] val = check csv:parseString(string `a, b`, {outputWithHeaders: false}); +record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: true}); +record{}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); +record{}[] val4 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); + +public function main() returns error? { + record{}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"], outputWithHeaders: false}); + val = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"], outputWithHeaders: true}); + + record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: false}); + val2 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: true}); + + record{}[] val3 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); + val3 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); +} diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/Ballerina.toml new file mode 100644 index 0000000..9f56b33 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "sample_package_9" +version = "0.1.0" +distribution = "2201.9.2" + +[build-options] +observabilityIncluded = true diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal new file mode 100644 index 0000000..669fe19 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal @@ -0,0 +1,22 @@ +import ballerina/data.csv; + +boolean o = false; +string[] headersOrder = ["a", "b"]; +record{}[] val = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"], outputWithHeaders: false}); +record{}[] val2 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"]}); +record{}[] val3 = check csv:transform([{"a": 1, "b": 2}], {"header": false, headersOrder: headersOrder}); +record{}[] val4 = check csv:transform([{"a": 1, "b": 2}], {outputWithHeaders: o, headersOrder: ()}); + +public function main() returns error? { + record{}[] val = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ()}); + val = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ()}); + + record{}[] val2 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"], outputWithHeaders: false}); + val2 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"], outputWithHeaders: true}); + + record{}[] val3 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: null}); + val3 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: null}); + + record{}[] val4 = check csv:transform([{"a": 1, "b": 2}], {headersOrder}); + val4 = check csv:transform([{"a": 1, "b": 2}], {headersOrder}); +} 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 c1cb305..d768a0c 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 @@ -33,6 +33,21 @@ public final class Constants { static final String CSVDATA = "csv"; static final String BALLERINA = "ballerina"; static final String DATA_CSVDATA = "data.csv"; + static final String FALSE = "false"; + static final String BAL_NULL = "()"; + static final String NULL = "null"; + + static class UserConfigurations { + private UserConfigurations() { + } + + static final String OUTPUT_WITH_HEADERS = "outputWithHeaders"; + static final String HEADERS_ORDER = "headersOrder"; + static final String HEADER = "header"; + static final String CUSTOM_HEADERS = "customHeaders"; + static final String HEADERS_ROWS = "headersRows"; + static final String CUSTOM_HEADERS_IF_ABSENT = "customHeadersIfHeadersAbsent"; + } private Constants() { } 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 a5e5cca..e6137e0 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 @@ -33,7 +33,15 @@ public enum CsvDataDiagnosticCodes { 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); + "be basic types, other types are not supported.", ERROR), + IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'outputWithHeaders' will be ignored since the " + + "expected type is a subtype record array.", ERROR), + IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'headersOrder' will be ignored " + + "since the expected type is a subtype record array.", ERROR), + IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT("CSV_ERROR_6", + "The option 'customHeadersIfHeadersAbsent' will be ignored since the header is present.", ERROR), + CUSTOM_HEADERS_SHOULD_BE_PROVIDED("CSV_ERROR_7", + "customHeaders parameter should be provided since the headerRows larger than 1.", 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 b13cf27..3b666ea 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 @@ -36,18 +36,30 @@ import io.ballerina.compiler.api.symbols.TypeSymbol; import io.ballerina.compiler.api.symbols.UnionTypeSymbol; import io.ballerina.compiler.api.symbols.VariableSymbol; +import io.ballerina.compiler.syntax.tree.AssignmentStatementNode; +import io.ballerina.compiler.syntax.tree.BasicLiteralNode; import io.ballerina.compiler.syntax.tree.CheckExpressionNode; import io.ballerina.compiler.syntax.tree.ChildNodeList; import io.ballerina.compiler.syntax.tree.ExpressionNode; +import io.ballerina.compiler.syntax.tree.FunctionArgumentNode; import io.ballerina.compiler.syntax.tree.FunctionCallExpressionNode; import io.ballerina.compiler.syntax.tree.FunctionDefinitionNode; +import io.ballerina.compiler.syntax.tree.IdentifierToken; import io.ballerina.compiler.syntax.tree.ImportDeclarationNode; +import io.ballerina.compiler.syntax.tree.ListConstructorExpressionNode; +import io.ballerina.compiler.syntax.tree.MappingConstructorExpressionNode; +import io.ballerina.compiler.syntax.tree.MappingFieldNode; import io.ballerina.compiler.syntax.tree.ModuleMemberDeclarationNode; import io.ballerina.compiler.syntax.tree.ModulePartNode; import io.ballerina.compiler.syntax.tree.ModuleVariableDeclarationNode; import io.ballerina.compiler.syntax.tree.NameReferenceNode; +import io.ballerina.compiler.syntax.tree.NamedArgumentNode; +import io.ballerina.compiler.syntax.tree.NilLiteralNode; import io.ballerina.compiler.syntax.tree.Node; +import io.ballerina.compiler.syntax.tree.PositionalArgumentNode; import io.ballerina.compiler.syntax.tree.QualifiedNameReferenceNode; +import io.ballerina.compiler.syntax.tree.SeparatedNodeList; +import io.ballerina.compiler.syntax.tree.SpecificFieldNode; import io.ballerina.compiler.syntax.tree.SyntaxKind; import io.ballerina.compiler.syntax.tree.TypeDefinitionNode; import io.ballerina.compiler.syntax.tree.VariableDeclarationNode; @@ -124,29 +136,50 @@ private void processFunctionDefinitionNode(FunctionDefinitionNode functionDefini SyntaxNodeAnalysisContext ctx) { ChildNodeList childNodeList = functionDefinitionNode.functionBody().children(); for (Node node : childNodeList) { - if (node.kind() != SyntaxKind.LOCAL_VAR_DECL) { - continue; - } - VariableDeclarationNode variableDeclarationNode = (VariableDeclarationNode) node; - Optional initializer = variableDeclarationNode.initializer(); - if (initializer.isEmpty()) { - continue; + if (node.kind() == SyntaxKind.LOCAL_VAR_DECL) { + processLocalVarDeclNode((VariableDeclarationNode) node, ctx); + } else if (node.kind() == SyntaxKind.ASSIGNMENT_STATEMENT) { + processAssignmentStmtNode((AssignmentStatementNode) node, ctx); } + } + } - currentLocation = variableDeclarationNode.typedBindingPattern().typeDescriptor().location(); - Optional symbol = semanticModel.symbol(variableDeclarationNode.typedBindingPattern()); - if (symbol.isEmpty()) { - continue; - } + private void processAssignmentStmtNode(AssignmentStatementNode assignmentStatementNode, + SyntaxNodeAnalysisContext ctx) { + ExpressionNode expressionNode = assignmentStatementNode.expression(); + if (!isParseFunctionOfStringSource(expressionNode)) { + return; + } + currentLocation = assignmentStatementNode.location(); + Optional symbol = semanticModel.symbol(assignmentStatementNode.varRef()); + if (symbol.isEmpty()) { + return; + } + TypeSymbol typeSymbol = ((VariableSymbol) symbol.get()).typeDescriptor(); + validateFunctionParameterTypes(expressionNode, typeSymbol, currentLocation, ctx); + } - TypeSymbol typeSymbol = ((VariableSymbol) symbol.get()).typeDescriptor(); - if (!isParseFunctionOfStringSource(initializer.get())) { - checkTypeAndDetectDuplicateFields(typeSymbol, ctx); - continue; - } + private void processLocalVarDeclNode(VariableDeclarationNode variableDeclarationNode, + SyntaxNodeAnalysisContext ctx) { + Optional initializer = variableDeclarationNode.initializer(); + if (initializer.isEmpty()) { + return; + } - validateExpectedType(typeSymbol, currentLocation, ctx); + currentLocation = variableDeclarationNode.typedBindingPattern().typeDescriptor().location(); + Optional symbol = semanticModel.symbol(variableDeclarationNode.typedBindingPattern()); + if (symbol.isEmpty()) { + return; + } + + TypeSymbol typeSymbol = ((VariableSymbol) symbol.get()).typeDescriptor(); + ExpressionNode expressionNode = initializer.get(); + if (!isParseFunctionOfStringSource(expressionNode)) { + checkTypeAndDetectDuplicateFields(typeSymbol, ctx); + return; } + validateExpectedType(typeSymbol, currentLocation, ctx); + validateFunctionParameterTypes(expressionNode, typeSymbol, expressionNode.location(), ctx); } private void checkTypeAndDetectDuplicateFields(TypeSymbol typeSymbol, SyntaxNodeAnalysisContext ctx) { @@ -169,23 +202,36 @@ private void checkTypeAndDetectDuplicateFields(TypeSymbol typeSymbol, SyntaxNode } } - private boolean isParseFunctionOfStringSource(ExpressionNode expressionNode) { + private FunctionCallExpressionNode getFunctionCallExpressionNodeIfPresent(ExpressionNode expressionNode) { if (expressionNode.kind() == SyntaxKind.CHECK_EXPRESSION) { expressionNode = ((CheckExpressionNode) expressionNode).expression(); } if (expressionNode.kind() != SyntaxKind.FUNCTION_CALL) { - return false; + return null; } - NameReferenceNode nameReferenceNode = ((FunctionCallExpressionNode) expressionNode).functionName(); + return ((FunctionCallExpressionNode) expressionNode); + } + + private String getFunctionName(FunctionCallExpressionNode node) { + NameReferenceNode nameReferenceNode = node.functionName(); if (nameReferenceNode.kind() != SyntaxKind.QUALIFIED_NAME_REFERENCE) { - return false; + return ""; } - String prefix = ((QualifiedNameReferenceNode) nameReferenceNode).modulePrefix().text(); + QualifiedNameReferenceNode qualifiedNameReferenceNode = (QualifiedNameReferenceNode) nameReferenceNode; + String prefix = qualifiedNameReferenceNode.modulePrefix().text(); if (!prefix.equals(modulePrefix)) { + return ""; + } + return qualifiedNameReferenceNode.identifier().text(); + } + + private boolean isParseFunctionOfStringSource(ExpressionNode expressionNode) { + FunctionCallExpressionNode node = getFunctionCallExpressionNodeIfPresent(expressionNode); + if (node == null) { return false; } - String functionName = ((FunctionCallExpressionNode) expressionNode).functionName().toString().trim(); + String functionName = getFunctionName(node); return functionName.contains(Constants.PARSE_STRING) || functionName.contains(Constants.PARSE_BYTES) || functionName.contains(Constants.PARSE_STREAM) || @@ -193,6 +239,139 @@ private boolean isParseFunctionOfStringSource(ExpressionNode expressionNode) { functionName.contains(Constants.PARSE_LISTS); } + private void validateFunctionParameterTypes(ExpressionNode expressionNode, + TypeSymbol expType, + Location currentLocation, SyntaxNodeAnalysisContext ctx) { + FunctionCallExpressionNode node = getFunctionCallExpressionNodeIfPresent(expressionNode); + if (node == null) { + return; + } + String functionName = getFunctionName(node); + SeparatedNodeList args = node.arguments(); + validateFunctionParameterTypesWithExpType(expType, currentLocation, ctx, functionName, args); + } + + private void validateFunctionParameterTypesWithExpType(TypeSymbol expType, Location currentLocation, + SyntaxNodeAnalysisContext ctx, String functionName, + SeparatedNodeList args) { + switch (expType.typeKind()) { + case ARRAY -> validateFunctionParameterTypesWithArrayType( + (ArrayTypeSymbol) expType, currentLocation, ctx, functionName, args); + case TYPE_REFERENCE -> validateFunctionParameterTypesWithExpType( + ((TypeReferenceTypeSymbol) expType).typeDescriptor(), currentLocation, ctx, functionName, args); + case INTERSECTION -> validateFunctionParameterTypesWithExpType( + getRawType(expType), currentLocation, ctx, functionName, args); + } + } + + private void validateFunctionParameterTypesWithArrayType(ArrayTypeSymbol expType, Location currentLocation, + SyntaxNodeAnalysisContext ctx, String functionName, + SeparatedNodeList args) { + TypeSymbol memberTypeSymbol = expType.memberTypeDescriptor(); + if (memberTypeSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { + memberTypeSymbol = ((TypeReferenceTypeSymbol) memberTypeSymbol).typeDescriptor(); + } + switch (memberTypeSymbol.typeKind()) { + case RECORD, MAP -> validateFunctionParameterTypesWithMappingArray( + currentLocation, ctx, functionName, args); + } + } + + private void validateFunctionParameterTypesWithMappingArray(Location currentLocation, + SyntaxNodeAnalysisContext ctx, String functionName, SeparatedNodeList args) { + ExpressionNode expression; + SeparatedNodeList fields; + String header = null, headersRows = null, customHeaders = null, + customHeadersIfHeaderAbsent = null, outputWithHeaders = null, headersOrder = null; + boolean isCustomHeaderPresent = false; + for (FunctionArgumentNode arg : args) { + if (arg instanceof PositionalArgumentNode positionalArgumentNode) { + expression = positionalArgumentNode.expression(); + } else if (arg instanceof NamedArgumentNode namedArgumentNode) { + expression = namedArgumentNode.expression(); + } else { + continue; + } + if (expression instanceof MappingConstructorExpressionNode mappingConstructorExpressionNode) { + fields = mappingConstructorExpressionNode.fields(); + for (MappingFieldNode field : fields) { + if (field instanceof SpecificFieldNode specificFieldNode) { + Node node = specificFieldNode.fieldName(); + if (node instanceof IdentifierToken identifierToken) { + String fieldName = identifierToken.text(); + if (fieldName.equals(Constants.UserConfigurations.HEADER)) { + header = getTheValueOfTheUserConfigOption(specificFieldNode); + } + if (fieldName.equals(Constants.UserConfigurations.CUSTOM_HEADERS_IF_ABSENT)) { + customHeadersIfHeaderAbsent = getTheValueOfTheUserConfigOption(specificFieldNode); + } + if (fieldName.equals(Constants.UserConfigurations.HEADERS_ROWS)) { + headersRows = getTheValueOfTheUserConfigOption(specificFieldNode); + } + if (fieldName.equals(Constants.UserConfigurations.CUSTOM_HEADERS)) { + customHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); + isCustomHeaderPresent = true; + } + if (fieldName.equals(Constants.UserConfigurations.HEADERS_ORDER)) { + headersOrder = getTheValueOfTheUserConfigOption(specificFieldNode); + } + if (fieldName.equals(Constants.UserConfigurations.OUTPUT_WITH_HEADERS)) { + outputWithHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); + } + } + } + } + } + } + throwErrorsIfIgnoredFieldFoundForRecordOutputs(header, customHeadersIfHeaderAbsent, headersRows, + customHeaders, isCustomHeaderPresent, headersOrder, + outputWithHeaders, ctx, currentLocation, functionName); + } + + private void throwErrorsIfIgnoredFieldFoundForRecordOutputs(String header, String customHeadersIfHeaderAbsent, + String headersRows, String customHeaders, boolean isCustomHeaderPresent, String headersOrder, + String outputWithHeaders, SyntaxNodeAnalysisContext ctx, Location currentLocation, String functionName) { + if (functionName.equals(Constants.PARSE_STRING) && header != null && !header.equals(Constants.FALSE) + && customHeadersIfHeaderAbsent != null && !customHeadersIfHeaderAbsent.equals(Constants.BAL_NULL) + && !customHeadersIfHeaderAbsent.equals(Constants.NULL)) { + reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), + CsvDataDiagnosticCodes.IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + } + if (functionName.equals(Constants.PARSE_LISTS) && headersRows != null + && !headersRows.equals("0") && !headersRows.equals("1") && + (!isCustomHeaderPresent || (customHeaders != null && (customHeaders.equals(Constants.BAL_NULL) + || customHeaders.equals(Constants.NULL))))) { + reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), + CsvDataDiagnosticCodes.CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + } + if (functionName.equals(Constants.TRANSFORM) && headersOrder != null + && !headersOrder.equals(Constants.BAL_NULL) && !headersOrder.equals(Constants.NULL)) { + reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), + CsvDataDiagnosticCodes.IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY); + } + if (outputWithHeaders != null) { + reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), + CsvDataDiagnosticCodes.IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); + } + } + + private String getTheValueOfTheUserConfigOption(SpecificFieldNode specificFieldNode) { + Optional optExpNode = specificFieldNode.valueExpr(); + if (optExpNode.isPresent()) { + ExpressionNode expNode = optExpNode.get(); + if (expNode instanceof BasicLiteralNode basicLiteralNode) { + return basicLiteralNode.literalToken().text(); + } + if (expNode instanceof ListConstructorExpressionNode listConstructorExpressionNode) { + return listConstructorExpressionNode.expressions().toString(); + } + if (expNode instanceof NilLiteralNode) { + return Constants.BAL_NULL; + } + } + return null; + } + private void validateExpectedType(TypeSymbol typeSymbol, Location currentLocation, SyntaxNodeAnalysisContext ctx) { switch (typeSymbol.typeKind()) { case UNION -> validateUnionType((UnionTypeSymbol) typeSymbol, currentLocation, ctx); @@ -331,13 +510,20 @@ private void processModuleVariableDeclarationNode(ModuleVariableDeclarationNode SyntaxNodeAnalysisContext ctx) { Optional initializer = moduleVariableDeclarationNode.initializer(); currentLocation = moduleVariableDeclarationNode.typedBindingPattern().typeDescriptor().location(); - if (initializer.isEmpty() || !isParseFunctionOfStringSource(initializer.get())) { + if (initializer.isEmpty()) { + return; + } + ExpressionNode expressionNode = initializer.get(); + if (!isParseFunctionOfStringSource(expressionNode)) { return; } Optional symbol = semanticModel.symbol(moduleVariableDeclarationNode.typedBindingPattern()); symbol.map(s -> (VariableSymbol) s).map(VariableSymbol::typeDescriptor) - .ifPresent(s -> validateExpectedType(s, currentLocation, ctx)); + .ifPresent(s -> { + validateExpectedType(s, currentLocation, ctx); + validateFunctionParameterTypes(expressionNode, s, expressionNode.location(), ctx); + }); } private void processTypeDefinitionNode(TypeDefinitionNode typeDefinitionNode, SyntaxNodeAnalysisContext ctx) { From b02b9fb14bceb9badd5a00856f30c0f324c3f962 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 13 Aug 2024 02:11:43 +0530 Subject: [PATCH 134/147] Add test for a non-csv scenario --- .../csvdata/compiler/CompilerPluginTest.java | 10 ++++++++++ .../sample_package_11/Ballerina.toml | 8 ++++++++ .../ballerina_sources/sample_package_11/main.bal | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal 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 aa23f67..a61bdde 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 @@ -256,4 +256,14 @@ public void testIgnoredCustomHeaderOptions() { Assert.assertEquals(errorDiagnosticsList.get(11).diagnosticInfo() .messageFormat(), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); } + + @Test + public void testNonCsvFunctionCall() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_11").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 0); + } } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/Ballerina.toml new file mode 100644 index 0000000..26a2006 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "sample_package_11" +version = "0.1.0" +distribution = "2201.9.2" + +[build-options] +observabilityIncluded = true diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal new file mode 100644 index 0000000..d25595b --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal @@ -0,0 +1,16 @@ +import ballerina/data.csv; + +type A record { + int:Unsigned32 headerRows = 0; + string[] customHeaders = []; + boolean outputWithHeaders = false; +}; + +public function main() returns error? { + record {}[] a = check csv:parseString(string `a,b`, {}); + record {}[] b = test({headerRows: 2, outputWithHeaders: false}); +} + +function test(A a) returns record{}[] { + return [{}]; +} From 78aabf2a9961d6e029f51da32fbf353d918b5a80 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 14 Aug 2024 14:04:53 +0530 Subject: [PATCH 135/147] Update the order of union types --- .../tests/parse_list_type_as_list_test.bal | 2 +- .../tests/parse_list_type_as_record_test.bal | 10 +- .../tests/parse_string_to_array_test.bal | 11 +- .../tests/parse_string_to_record_tests.bal | 7 + .../tests/types.bal | 6 + .../tests/parse_type_compatibility_test.bal | 45 ++- .../tests/test_with_intersection_types.bal | 23 +- .../tests/test_with_singleton_test.bal | 26 +- .../tests/test_with_union_types.bal | 316 ++++++++++++++++-- .../sample_package_11/main.bal | 16 +- .../compiler/CsvDataTypeValidator.java | 3 + .../lib/data/csvdata/FromString.java | 21 +- .../lib/data/csvdata/csv/CsvCreator.java | 1 + .../lib/data/csvdata/csv/CsvParser.java | 10 +- .../lib/data/csvdata/csv/CsvTraversal.java | 109 ++---- .../csvdata/utils/DiagnosticErrorCode.java | 3 +- .../src/main/resources/csv_error.properties | 3 + 17 files changed, 464 insertions(+), 148 deletions(-) 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 086e760..834f854 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 @@ -472,7 +472,7 @@ function testParseListsWithOutputHeaders() { ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21}); test:assertEquals(ct1bt1, []); - (string|boolean|int)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1}); + (boolean|int|string)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1}); test:assertEquals(ct1bt1_2, [ ["a", true, 1] ]); 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 848e76e..28bd953 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 @@ -544,6 +544,14 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {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"} + ]); + + record{|int|() a; float b; decimal? c; boolean|string d; int|string e; string f; string...;|}[]|csv:Error ct1br9_3 = csv:parseList( + [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], + {customHeaders: ["f", "e", "d", "c", "b", "a"]}); + test:assertEquals(ct1br9_3, [ {a: (), b: 2.23, c: 0, d: true, e: 1, f: "a"}, {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); @@ -593,7 +601,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { 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"]], {headersRows: 1, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + map[]|csv:Error ct2br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); test:assertEquals(ct2br4_3, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} 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 dfeaf58..e6b3565 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 @@ -407,20 +407,27 @@ function testParseStringArrayAsExpectedTypeWithOutputHeaders() { ["true", "false", "true", "false"] ]); - (string|boolean)[][]|csv:Error cv2baa = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); + (boolean|string)[][]|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] ]); - [string...][]|csv:Error cv2baa_2 = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); + (string|boolean)[][]|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"] ]); + [string...][]|csv:Error cv2baa_2_2 = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); + test:assertEquals(cv2baa_2_2, [ + ["b1", "b2", "b3", "b4", "b5"], + ["true", "false", "true", "false", "true"], + ["true", "false", "true", "false", "true"] + ]); + [boolean|string...][]|csv:Error cv2baa_3 = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); test:assertEquals(cv2baa_3, [ ["b1", "b2", "b3", "b4", "b5"], 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 3a212dc..1d18803 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 @@ -381,6 +381,13 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType4() { test:assertTrue(csvb1br12 is csv:Error); test:assertEquals((csvb1br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); + BooleanRecord13_2[]|csv:Error csvb1br13_2 = csv:parseString(csvStringWithBooleanValues1, {}); + test:assertEquals(csvb1br13_2, [ + {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 csvb1br13 = csv:parseString(csvStringWithBooleanValues1, {}); test:assertEquals(csvb1br13, [ {b1: true, b2: false, b3: true, b4: false, defaultableField: "", nillableField: ()}, diff --git a/ballerina-tests/parse-string-record-types-tests/tests/types.bal b/ballerina-tests/parse-string-record-types-tests/tests/types.bal index 6c50a58..0a189a3 100644 --- a/ballerina-tests/parse-string-record-types-tests/tests/types.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/types.bal @@ -94,6 +94,12 @@ type BooleanRecord12 record {| |}; type BooleanRecord13 record {| + string defaultableField = ""; + string? nillableField = (); + boolean|string...; +|}; + +type BooleanRecord13_2 record {| string defaultableField = ""; string? nillableField = (); string|boolean...; 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 cedf454..325109a 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 @@ -132,9 +132,9 @@ function testFromCsvWithIntersectionTypeCompatibility2() { 3,string3,true`); test:assertEquals(r2a, [ - {a: 1, b: "string", c: true}, - {a: 2, b: "string2", c: false}, - {a: 3, b: "string3", c: true} + {a: 1d, b: "string", c: "true"}, + {a: 2d, b: "string2", c: "false"}, + {a: 3d, b: "string3", c: "true"} ]); record {A2 a; B2 b; C2 c;}[]|csv:Error r3a = csv:parseString(string `a,b,c @@ -190,9 +190,9 @@ function testFromCsvWithIntersectionTypeCompatibility2() { 3,string3,true`); test:assertEquals(r17a, [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] + [1d, "string", "true"], + [2d, "string2", "false"], + [3d, "string3", "true"] ]); [A2, B2, C2][]|csv:Error r18a = csv:parseString( @@ -299,9 +299,9 @@ function testFromCsvWithIntersectionTypeCompatibility2() { , {headersOrder: ["a", "b", "c"]}); test:assertEquals(rt7a, [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] + [1d, "string", true], + [2d, "string2", false], + [3d, "string3", true] ]); [A2, B2, C2][]|csv:Error rt8a = csv:transform( @@ -348,18 +348,27 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [["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} + {a: 1d, b: "string", c: "true"}, + {a: 2d, b: "string2", c: "false"}, + {a: 3d, 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} + {a: "1", b: "string", c: "true"}, + {a: "2", b: "string2", c: "false"}, + {a: "3", b: "string3", c: "true"} + ]); + + record {decimal|string a; B b; C c;}[]|csv:Error rt12a_4 = csv:parseList( + [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]], {customHeaders: ["a", "b", "c"]}); + + test:assertEquals(rt12a_4, [ + {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( @@ -409,9 +418,9 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [["1", "string", "true"], ["2", "string2", "false"], ["3", "string3", "true"]]); test:assertEquals(rt17a, [ - [1, "string", true], - [2, "string2", false], - [3, "string3", true] + [1d, "string", "true"], + [2d, "string2", "false"], + [3d, "string3", "true"] ]); [A2, B2, C2][]|csv:Error rt18a = csv:parseList( 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 5d37b8b..726ef47 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 @@ -70,7 +70,7 @@ function testIntersectionExpectedTypes() returns error? { 1,2 a,a`); test:assertTrue(a9 is (((int[] & readonly)|([string, string] & readonly)) & readonly)[]); - test:assertEquals(a9, [[1, 2], ["a", "a"]]); + test:assertEquals(a9, [["1", "2"], ["a", "a"]]); ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly|csv:Error a10 = csv:parseString(string `a,b @@ -115,13 +115,22 @@ function testIntersectionExpectedTypes2() returns error? { test:assertEquals(a8, [{a: "a", b: "a"}, {a: "c", b: "c"}]); (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); - test:assertTrue(a9 is (((int[] & readonly)|([string, string] & readonly)) & readonly)[]); - test:assertEquals(a9, [[1, 2], ["a", "b"]]); + test:assertTrue(a9 is error); + test:assertEquals(( a9).message(), "The CSV cannot be converted into any of the uniform union types in '((int[] & readonly)|([string,string] & readonly))[]'"); + + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9_2 = csv:transform([{"a": "1", "b": "2"}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + test:assertTrue(a9_2 is (((int[] & readonly)|([string, string] & readonly)) & readonly)[]); + test:assertEquals(a9_2, [["1", "2"], ["a", "b"]]); ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] - & readonly|csv:Error a10 = csv:transform([{"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:assertEquals(a10, [{a: "a", b: "a"}, {a: "1", b: "2"}]); + + ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] + & readonly|csv:Error a10_2 = csv:transform([{"a": "a", "b": "a"}, {"a": 1, "b": 2}], {}); + test:assertTrue(a10_2 is error); + test:assertEquals(( a10_2).message(), "The CSV cannot be converted into any of the uniform union types in '((union_type_tests:record {| string a; string b; anydata...; |} & readonly)|(union_type_tests:record {| int a; int b; anydata...; |} & readonly))[]'"); } @test:Config @@ -160,7 +169,7 @@ function testIntersectionExpectedTypes3() returns error? { (((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"]]); + test:assertEquals(a9, [["1", "2"], ["a", "b"]]); ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly|csv:Error a10 = csv:parseList([["a", "a"], ["1", "2"]], {customHeaders: ["a", "b"]}); @@ -170,5 +179,5 @@ function testIntersectionExpectedTypes3() returns error? { ((record {int a; int b;} & readonly)|(record {string a; string b;} & readonly))[] & 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}]); + 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 cf6a55a..4bf4c7f 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 @@ -110,7 +110,7 @@ function testSingletonExpectedTypes2() returns error? { test:assertEquals((a8).message(), common:generateErrorMessageForInvalidCast("c", "(\"a\"|\"d\")")); } -type SubType byte|int:Signed8|int:Signed16|int:Signed32|string:Char|int:Unsigned8|int:Unsigned16|int:Unsigned32; +type SubType byte|int:Signed8|int:Signed16|int:Signed32|int:Unsigned8|int:Unsigned16|int:Unsigned32|string:Char; type SubtypeRecord record { byte a; int:Signed8 c; int:Signed16 d; int:Signed32 e; @@ -142,6 +142,14 @@ function testSubtypeExpectedTypes() returns error? { ["1", "1", "1", "1", "a", "1", "1", "1"]]; var value3 = [[1, 1, 1, 1, "a", 1, 1, 1], [1, 1, 1, 1, "a", 1, 1, 1]]; + var value4 = [[1, 1, 1, 1, "a", 1, 1, 1], + [1, 1, 1, 1, "a", 1, 1, 1]]; + var value5 = [{a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}, + {a: 1, c: 1, d: 1, e: 1, f: "a", g: 1, h: 1, i: 1}]; + var value6 = [[1, 1, 1, 1, 1, 1, 1], + [1, 1, 1, 1, 1, 1, 1]]; + var value7 = [{a: 1, c: 1, d: 1, e: 1, g: 1, h: 1, i: 1}, + {a: 1, c: 1, d: 1, e: 1, g: 1, h: 1, i: 1}]; SubtypeRecord[]|csv:Error a = csv:parseString(string `a, c, d, e, f, g, h, i 1, 1, 1, 1, a, 1, 1, 1 @@ -154,10 +162,15 @@ function testSubtypeExpectedTypes() returns error? { test:assertEquals(a2, [{a: 1, c: 1}, {a: 1, c: 1}]); - SubtypeRecord3[]|csv:Error a3 = csv:parseString(string `a, c, d, e, f, g, h, i + SubtypeRecord3[]|csv:Error a3 = csv:parseString(string `a, c, d, e, g, h, i + 1, 1, 1, 1, 1, 1, 1 + 1, 1, 1, 1, 1, 1, 1 `); + test:assertEquals(a3, value7); + + SubtypeRecord3[]|csv:Error a3_2 = 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); + test:assertEquals(a3_2, value5); SubtypeTuple[]|csv:Error a4 = csv:parseString(string `a, c, d, e, f, g, h, i 1, 1, 1, 1, a, 1, 1, 1 @@ -172,7 +185,12 @@ function testSubtypeExpectedTypes() returns error? { 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); + test:assertEquals(a6, value4); + + SubtypeTuple3[]|csv:Error a6_2 = csv:parseString(string `a, c, d, e, g, h, i + 1, 1, 1, 1, 1, 1, 1 + 1, 1, 1, 1, 1, 1, 1 `); + test:assertEquals(a6_2, value6); SubtypeRecord[]|csv:Error a7 = csv:transform(value1, {}); test:assertEquals(a7, value1); 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 f7dda6b..f9246ce 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 @@ -119,30 +119,30 @@ function testParseToStringWithUnionExpectedTypes() returns error? { 1, 2 a, b`, {header: 1}); test:assertEquals(csv1op12, [ - {a: 1, b: 2}, + {a: "1", b: "2"}, {a: "a", b: "b"} ]); - ([int, int]|[string, string])[]|csv:Error csv1op13 = csv:parseString(string ` + ([int, int]|[string|int, string|int])[]|csv:Error csv1op13 = csv:parseString(string ` a,b 1, 2 a, b`, {header: 1}); test:assertEquals(csv1op13, [ - [1, 2], + ["1", "2"], ["a", "b"] ]); } +record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, + {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, + {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, + {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, + {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} +]; + @test:Config function testParseToStringWithUnionExpectedTypes2() returns error? { - record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ - {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, - {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, - {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, - {a: 4, b: "string4", c: true, d: -6.51, e: -6.51, f: ()}, - {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} - ]; - (RecA|RecC)[]|csv:Error csv1op1 = csv:transform(value, {}); test:assertEquals(csv1op1, [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, @@ -233,13 +233,17 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { (record{|string a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op12 = csv:transform(value, {}); test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(union_type_tests:record {| string a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); + test:assertEquals((csv1op12).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:record {| string a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); - (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); + (record{|int a; int...;|}|record{|int|string a; int|string...;|})[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, {a: "a", b: "b"} ]); + + (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op14 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); + test:assertTrue(csv1op14 is csv:Error); + test:assertEquals((csv1op14).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:record {| int a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); } @test:Config @@ -338,7 +342,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { (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: "1", b: "2"}, {a: "a", b: "b"} ]); } @@ -387,7 +391,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { (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])[]'"); + test:assertEquals((csv1op4_2).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:TupB|[boolean])[]'"); (TupA|TupB)[]|csv:Error csv1op5 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op5, [ @@ -412,29 +416,33 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { ([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...])[]'"); + test:assertEquals((csv1op8).message(), "The CSV cannot be converted into any of the uniform union types in '([string...]|[int...])[]'"); ([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...])[]'"); + test:assertEquals((csv1op9).message(), "The CSV cannot be converted into any of the uniform union types in '([int...]|[string...])[]'"); ([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...])[]'"); + test:assertEquals((csv1op10).message(), "The CSV cannot be converted into any of the uniform union types in '([int,string...]|[string,int...])[]'"); ([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...])[]'"); + test:assertEquals((csv1op11).message(), "The CSV cannot be converted into any of the uniform union types in '([string,int...]|[int,string...])[]'"); ([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...])[]'"); + test:assertEquals((csv1op12).message(), "The CSV cannot be converted into any of the uniform union types in '([string,int...]|[string,string...])[]'"); - ([int, int...]|[string, string...])[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + ([string, string...]|[int|string, int|string...])[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] ]); + + ([int, int...]|[string, string...])[]|csv:Error csv1op14 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + test:assertTrue(csv1op14 is csv:Error); + test:assertEquals((csv1op14).message(), "The CSV cannot be converted into any of the uniform union types in '([int,int...]|[string,string...])[]'"); } @test:Config @@ -480,7 +488,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { (TupB|[boolean])[]|csv:Error csv1op4_2 = csv:parseList(value, {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is csv:Error); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(union_type_tests:TupB|[boolean])[]'"); + test:assertEquals((csv1op4_2).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:TupB|[boolean])[]'"); (TupA|TupB)[]|csv:Error csv1op5 = csv:parseList(value, {skipLines: [2, 4]}); test:assertEquals(csv1op5, [ @@ -532,7 +540,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { ([int, int...]|[string, string...])[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {}); test:assertEquals(csv1op13, [ - [1, 2], + ["1", "2"], ["a", "b"] ]); } @@ -1022,3 +1030,265 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:parseList(value, {}); test:assertEquals(csv1op12, value); } + +@test:Config +function testUnionTypeWithOrdering() returns error? { + string[][] value1 = [["1", "1.0", "true", "a"], ["2", "2.0", "false", "b"]]; + string value2 = string `a,b, c, d + 1, 1.0, true, a + 2, 2.0, false, b`; + record{}[] value3 = [{"a": 1, "b": 1.0, "c": true, "d": "a"}, {"a": 2, "b": 2.0, "c": false, "d":"b"}]; + + string[][]|anydata[][]|error csv1op1 = csv:parseList(value1); + test:assertEquals(csv1op1, [ + ["1", "1.0", "true", "a"], + ["2", "2.0", "false", "b"] + ]); + + anydata[][]|string[][]|error csv1op2 = csv:parseList(value1); + test:assertEquals(csv1op2, [ + [1, 1.0, true, "a"], + [2, 2.0, false, "b"] + ]); + + string[][2]|float[][2]|error csv1op1_2 = csv:parseList(value1); + test:assertEquals(csv1op1_2, [ + ["1", "1.0"], + ["2", "2.0"] + ]); + + float[][2]|string[][2]|error csv1op2_2 = csv:parseList(value1); + test:assertEquals(csv1op2_2, [ + [1f, 1.0], + [2f, 2.0] + ]); + + (string|anydata)[][]|error csv1op1_3 = csv:parseList(value1); + test:assertEquals(csv1op1_3, [ + ["1", "1.0", "true", "a"], + ["2", "2.0", "false", "b"] + ]); + + (anydata|string)[][]|error csv1op2_3 = csv:parseList(value1); + test:assertEquals(csv1op2_3, [ + [1, 1.0, true, "a"], + [2, 2.0, false, "b"] + ]); + + (string|float)[][2]|error csv1op1_4 = csv:parseList(value1); + test:assertEquals(csv1op1_4, [ + ["1", "1.0"], + ["2", "2.0"] + ]); + + (float|string)[][2]|error csv1op2_4 = csv:parseList(value1); + test:assertEquals(csv1op2_4, [ + [1f, 1.0], + [2f, 2.0] + ]); + + string[][]|anydata[][]|error recCsv1op1 = csv:transform(value3); + test:assertEquals(recCsv1op1, [ + [1, 1.0, true, "a"], + [2, 2.0, false, "b"] + ]); + + anydata[][]|string[][]|error recCsv1op2 = csv:transform(value3); + test:assertEquals(recCsv1op2, [ + [1, 1.0, true, "a"], + [2, 2.0, false, "b"] + ]); + + string[][2]|float[][2]|error recCsv1op1_2 = csv:transform(value3); + test:assertEquals(recCsv1op1_2, [ + [1f, 1.0], + [2f, 2.0] + ]); + + float[][2]|string[][2]|error recCsv1op2_2 = csv:transform(value3); + test:assertEquals(recCsv1op2_2, [ + [1f, 1.0], + [2f, 2.0] + ]); + + (string|anydata)[][]|error recCsv1op1_3 = csv:transform(value3); + test:assertEquals(recCsv1op1_3, [ + [1, 1.0, true, "a"], + [2, 2.0, false, "b"] + ]); + + (anydata|string)[][]|error recCsv1op2_3 = csv:transform(value3); + test:assertEquals(recCsv1op2_3, [ + [1, 1.0, true, "a"], + [2, 2.0, false, "b"] + ]); + + (string|float)[][2]|error recCsv1op1_4 = csv:transform(value3); + test:assertEquals(recCsv1op1_4, [ + [1f, 1.0], + [2f, 2.0] + ]); + + (float|string)[][2]|error recCsv1op2_4 = csv:transform(value3); + test:assertEquals(recCsv1op2_4, [ + [1f, 1.0], + [2f, 2.0] + ]); + + string[][]|anydata[][]|error parseStrCsv1op1 = csv:parseString(value2); + test:assertEquals(parseStrCsv1op1, [ + ["1", "1.0", "true", "a"], + ["2", "2.0", "false", "b"] + ]); + + anydata[][]|string[][]|error parseStrCsv1op2 = csv:parseString(value2); + test:assertEquals(parseStrCsv1op2, [ + [1, 1.0, true, "a"], + [2, 2.0, false, "b"] + ]); + + string[][2]|float[][2]|error parseStrCsv1op1_2 = csv:parseString(value2); + test:assertEquals(parseStrCsv1op1_2, [ + ["1", "1.0"], + ["2", "2.0"] + ]); + + float[][2]|string[][2]|error parseStrCsv1op2_2 = csv:parseString(value2); + test:assertEquals(parseStrCsv1op2_2, [ + [1f, 1.0], + [2f, 2.0] + ]); + + (string|anydata)[][]|error parseStrCsv1op1_3 = csv:parseString(value2); + test:assertEquals(parseStrCsv1op1_3, [ + ["1", "1.0", "true", "a"], + ["2", "2.0", "false", "b"] + ]); + + (anydata|string)[][]|error parseStrCsv1op2_3 = csv:parseString(value2); + test:assertEquals(parseStrCsv1op2_3, [ + [1, 1.0, true, "a"], + [2, 2.0, false, "b"] + ]); + + (string|float)[][2]|error parseStrCsv1op1_4 = csv:parseString(value2); + test:assertEquals(parseStrCsv1op1_4, [ + ["1", "1.0"], + ["2", "2.0"] + ]); + + (float|string)[][2]|error parseStrCsv1op2_4 = csv:parseString(value2); + test:assertEquals(parseStrCsv1op2_4, [ + [1f, 1.0], + [2f, 2.0] + ]); +} + +@test:Config +function testUnionTypeWithNull() returns error? { + string[][] value1 = [["1", "()", "true", "a"], ["2", "()", "false", "b"]]; + string value2 = string `a,b, c, d + 1, (), true, a + 2, (), false, b`; + record{}[] value3 = [{"a": 1, "b": (), "c": true, "d": "a"}, {"a": 2, "b": (), "c": false, "d":"b"}]; + string value4 = string `a,b, c, d + 1, , true, a + 2, , false, b`; + string value5 = string `a,b, c, d + 1, null, true, a + 2, null, false, b`; + string value6 = string `a,b, c, d + 1, N/A, true, a + 2, N/A, false, b`; + string[][] value7 = [["1", "null", "true", "a"], ["2", "null", "false", "b"]]; + + string?[][2]|float[][2]|error csv1op1_2 = csv:parseList(value1); + test:assertEquals(csv1op1_2, [ + ["1", ()], + ["2", ()] + ]); + + csv1op1_2 = csv:parseList(value7); + test:assertEquals(csv1op1_2, [ + ["1", ()], + ["2", ()] + ]); + + float[][2]|string?[][2]|error csv1op2_2 = csv:parseList(value1); + test:assertEquals(csv1op2_2, [ + ["1", ()], + ["2", ()] + ]); + + csv1op2_2 = csv:parseList(value7); + test:assertEquals(csv1op2_2, [ + ["1", ()], + ["2", ()] + ]); + + (string|float?)[][2]|error csv1op1_4 = csv:parseList(value1); + test:assertEquals(csv1op1_4, [ + ["1", ()], + ["2", ()] + ]); + + csv1op1_4 = csv:parseList(value7); + test:assertEquals(csv1op1_4, [ + ["1", ()], + ["2", ()] + ]); + + (float|string?)[][2]|error csv1op2_4 = csv:parseList(value1); + test:assertEquals(csv1op2_4, [ + [1f, ()], + [2f, ()] + ]); + + csv1op2_4 = csv:parseList(value7); + test:assertEquals(csv1op2_4, [ + [1f, ()], + [2f, ()] + ]); + + int?[][2]|float[][2]|error recCsv1op1_2 = csv:transform(value3); + test:assertEquals(recCsv1op1_2, [ + [1, ()], + [2, ()] + ]); + + float?[][2]|int?[][2]|error recCsv1op2_2 = csv:transform(value3); + test:assertEquals(recCsv1op2_2, [ + [1f, ()], + [2f, ()] + ]); + + (float|string?)[][2]|error recCsv1op2_4 = csv:transform(value3); + test:assertEquals(recCsv1op2_4, [ + [1f, ()], + [2f, ()] + ]); + + string?[][2]|float[][2]|error parseStrCsv1op1_2 = csv:parseString(value2); + test:assertEquals(parseStrCsv1op1_2, [ + ["1", ()], + ["2", ()] + ]); + + float[][2]|string?[][2]|error parseStrCsv1op2_2 = csv:parseString(value4, {nilValue: ""}); + test:assertEquals(parseStrCsv1op2_2, [ + ["1", ()], + ["2", ()] + ]); + + (string|float?)[][2]|error parseStrCsv1op1_4 = csv:parseString(value5, {nilValue: "null"}); + test:assertEquals(parseStrCsv1op1_4, [ + ["1", ()], + ["2", ()] + ]); + + (float|string)?[][2]|error parseStrCsv1op2_4 = csv:parseString(value6, {nilValue: "N/A"}); + test:assertEquals(parseStrCsv1op2_4, [ + [1f, ()], + [2f, ()] + ]); +} diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal index d25595b..b548c58 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal @@ -7,10 +7,20 @@ type A record { }; public function main() returns error? { - record {}[] a = check csv:parseString(string `a,b`, {}); - record {}[] b = test({headerRows: 2, outputWithHeaders: false}); + record {}[] _ = check csv:parseString(string `a,b`, {}); + record {}[] _ = test1({headerRows: 2, outputWithHeaders: false}); + [int...][] _ = test2({headerRows: 2, outputWithHeaders: false}); + record {} _ = test3({headerRows: 2, outputWithHeaders: false}); } -function test(A a) returns record{}[] { +function test1(A a) returns record{}[] { return [{}]; } + +function test2(A a) returns [int...][] { + return []; +} + +function test3(A a) returns record{} { + return {}; +} 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 3b666ea..9b42862 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 @@ -408,6 +408,9 @@ private boolean isSupportedArrayMemberType(SyntaxNodeAnalysisContext ctx, if (typeSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { typeSymbol = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor(); } + if (typeSymbol.typeKind() == TypeDescKind.INTERSECTION) { + typeSymbol = getRawType(typeSymbol); + } TypeDescKind kind = typeSymbol.typeKind(); if (kind == TypeDescKind.TYPE_REFERENCE) { kind = ((TypeReferenceTypeSymbol) typeSymbol).typeDescriptor().typeKind(); diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java index bbea231..8b22db5 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java @@ -109,9 +109,9 @@ public static Object fromStringWithType(BString string, Type expType, CsvConfig case TypeTags.BOOLEAN_TAG -> stringToBoolean(value); case TypeTags.NULL_TAG -> stringToNull(value, config); case TypeTags.FINITE_TYPE_TAG -> stringToFiniteType(value, (FiniteType) expType, config); - case TypeTags.UNION_TAG -> stringToUnion(string, (UnionType) expType, config); + case TypeTags.UNION_TAG -> stringToUnion(string, (UnionType) expType, config, false); case TypeTags.JSON_TAG, TypeTags.ANYDATA_TAG -> - stringToUnion(string, JSON_TYPE_WITH_BASIC_TYPES, config); + stringToUnion(string, JSON_TYPE_WITH_BASIC_TYPES, config, true); case TypeTags.TYPE_REFERENCED_TYPE_TAG -> fromStringWithType(string, ((ReferenceType) expType).getReferredType(), config); case TypeTags.INTERSECTION_TAG -> @@ -275,13 +275,20 @@ private static Object stringToNull(String value, CsvConfig config) throws Number return returnError(value, nullValue == null ? Constants.Values.BALLERINA_NULL : nullValue.toString()); } - private static Object stringToUnion(BString string, UnionType expType, CsvConfig config) + private static Object stringToUnion(BString string, UnionType expType, CsvConfig config, boolean isJsonOrAnydata) throws NumberFormatException { List memberTypes = new ArrayList<>(expType.getMemberTypes()); - memberTypes.sort(Comparator.comparingInt(t -> { - int index = TYPE_PRIORITY_ORDER.indexOf(TypeUtils.getReferredType(t).getTag()); - return index == -1 ? Integer.MAX_VALUE : index; - })); + if (isJsonOrAnydata) { + memberTypes.sort(Comparator.comparingInt(t -> { + int index = TYPE_PRIORITY_ORDER.indexOf(TypeUtils.getReferredType(t).getTag()); + return index == -1 ? Integer.MAX_VALUE : index; + })); + } else { + memberTypes.sort(Comparator.comparingInt(t -> { + int tag = TypeUtils.getReferredType(t).getTag(); + return tag == TypeTags.NULL_TAG ? Integer.MIN_VALUE : memberTypes.indexOf(t); + })); + } for (Type memberType : memberTypes) { try { Object result = fromStringWithType(string, memberType, config); 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 06741f4..081155d 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 @@ -97,6 +97,7 @@ static void convertAndUpdateCurrentCsvNode(CsvParser.StateMachine sm, ArrayType arrayType = (ArrayType) currentCsvNodeType; if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < sm.columnIndex) { + sm.earlyReturn = true; return; } ((BArray) currentCsv).add(sm.columnIndex, convertedValue); 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 7cb9684..0c22193 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 @@ -146,6 +146,7 @@ static class StateMachine { int arraySize = 0; boolean addHeadersForOutput = false; int currentCsvNodeLength = 0; + boolean earlyReturn = false; StateMachine() { reset(); @@ -182,6 +183,7 @@ public void reset() { arraySize = 0; addHeadersForOutput = false; currentCsvNodeLength = 0; + earlyReturn = false; } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -637,7 +639,7 @@ private static void handleCsvRow(StateMachine sm, boolean trim) { if (trim) { value = value.trim(); } - if (!(value.isBlank() && sm.currentCsvNodeLength == 0)) { + if (!(value.isBlank() && sm.currentCsvNodeLength == 0) && !sm.earlyReturn) { addRowValue(sm, trim); } if (!sm.isCurrentCsvNodeEmpty) { @@ -658,6 +660,7 @@ private static void updateLineAndColumnIndexesWithoutRowIndexes(StateMachine sm) sm.currentCsvNode = null; sm.isCurrentCsvNodeEmpty = true; sm.columnIndex = 0; + sm.earlyReturn = false; sm.clear(); } @@ -708,6 +711,9 @@ private static void addRowValue(StateMachine sm) { } private static void addRowValue(StateMachine sm, boolean trim) { + if (sm.earlyReturn) { + return; + } Field currentField = null; sm.isValueStart = false; Type exptype = sm.expectedArrayElementType; @@ -769,6 +775,7 @@ private static Type getExpectedRowTypeOfTuple(StateMachine sm, TupleType tupleTy } else { sm.charBuffIndex = 0; if (sm.config.allowDataProjection) { + sm.earlyReturn = true; return null; } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, tupleTypes.size()); @@ -780,6 +787,7 @@ private static Type getExpectedRowTypeOfArray(StateMachine sm, ArrayType arrayTy if (arrayType.getSize() != -1 && arrayType.getSize() <= sm.columnIndex) { sm.charBuffIndex = 0; if (sm.config.allowDataProjection) { + sm.earlyReturn = true; return null; } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, arrayType.getSize()); 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 211ee64..46176dc 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 @@ -253,7 +253,7 @@ private void traverseCsvWithExpectedType(int sourceArraySize, break; case TypeTags.UNION_TAG: traverseCsvWithUnionExpectedType(sourceArraySize, csv, - (UnionType) expectedArrayElementType, type); + (UnionType) expectedArrayElementType, type, isIntersection); break; default: throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); @@ -336,83 +336,20 @@ public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expe } 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; - this.isFirstRowIsHeader = false; - if (arrayType.getState() == ArrayType.ArrayState.CLOSED && - arrayType.getSize() - 1 < this.arraySize) { - break; - } - - Object o = csv.get(i); - - for (Type memberType: expectedArrayType.getMemberTypes()) { - boolean isIntersection = false; - try { - memberType = TypeUtils.getReferredType(memberType); - if (memberType.getTag() == TypeTags.INTERSECTION_TAG) { - Optional mutableType = CsvUtils.getMutableType((IntersectionType) memberType); - if (mutableType.isPresent()) { - isIntersection = true; - memberType = mutableType.get(); - } - } - - if (CsvUtils.isExpectedTypeIsMap(memberType)) { - if (i < config.headersRows && i != config.headersRows - 1) { - continue outerLoop; - } - - if (i >= config.headersRows && 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.headersRows - 1))) { - // Headers will add to the list only in the first iteration - insertHeaderValuesForTheCsvIfApplicable(o, memberType); - } - if (i < config.headersRows) { - continue outerLoop; - } + UnionType expectedArrayType, Type type, boolean isIntersection) { - if (ignoreRow(rowNumber + 1, config.skipLines)) { - rowNumber++; - continue outerLoop; - } - rowValue = initStatesForCsvRowWithListAsExpectedType(o, memberType); - } else { - continue; - } - - if (isIntersection) { - rowValue = CsvCreator.constructReadOnlyValue(rowValue); - } - - if (!this.isFirstRowIsHeader) { - rootCsvNode.add(this.arraySize, rowValue); - this.arraySize++; - } - isCompatible = true; - break; - } catch (Exception e) { - resetForUnionMemberTypes(); + for (Type memberType: expectedArrayType.getMemberTypes()) { + try { + memberType = TypeCreator.createArrayType(TypeUtils.getReferredType(memberType)); + if (CsvUtils.isExpectedTypeIsMap(memberType) || CsvUtils.isExpectedTypeIsArray(memberType)) { + traverseCsv(csv, config, memberType); + return; } + } catch (Exception ex) { + resetForUnionTypes(); } - if (!isCompatible) { - throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); - } - rowNumber++; } + throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_UNION_CONVERSION, type); } private static boolean ignoreRow(int index, Object skipLinesConfig) { @@ -492,7 +429,10 @@ private void constructCsvArrayFromMapping(BMap map, Type type, } Type memberType = getTheElementTypeFromList(type, index); if (memberType != null) { - insertValuesIntoList(v, memberType, index, currentCsvNode); + boolean isArrayActive = insertToListAndReturnFalseIfListEnds(v, memberType, index, currentCsvNode); + if (!isArrayActive) { + return; + } } index++; } @@ -506,7 +446,11 @@ private void constructCsvArrayFromNonMapping(BArray csvElement, Type type, int e } Type memberType = getTheElementTypeFromList(type, index); if (memberType != null) { - insertValuesIntoList(csvElement.get(i), memberType, index, currentCsvNode); + boolean isArrayActive = insertToListAndReturnFalseIfListEnds( + csvElement.get(i), memberType, index, currentCsvNode); + if (!isArrayActive) { + return; + } } index++; } @@ -591,7 +535,11 @@ private void insertHeaderValuesForTheCsvIfApplicable(Object obj, Type 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); + boolean isArrayActive = insertToListAndReturnFalseIfListEnds(StringUtils.fromString( + headers[i]), memberType, i, headersArray); + if (!isArrayActive) { + break; + } } } @@ -865,7 +813,8 @@ private void insertCurrentFieldMemberIntoMapping(Type type, Object recValue, BSt throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_FIELD, recValue, key); } - public void insertValuesIntoList(Object arrayValue, Type type, int index, Object currentCsvNode) { + public boolean insertToListAndReturnFalseIfListEnds(Object arrayValue, + Type type, int index, Object currentCsvNode) { Object value = convertCsvValueIntoExpectedType(type, arrayValue, false); boolean isArrayType = type instanceof ArrayType; if (!(value instanceof CsvUtils.UnMappedValue)) { @@ -873,11 +822,11 @@ public void insertValuesIntoList(Object arrayValue, Type type, int index, Object ArrayType arrayType = (ArrayType) TypeUtils.getType(type); if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < index) { - return; + return false; } } ((BArray) currentCsvNode).add(index, value); - return; + return true; } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE_FOR_ARRAY, arrayValue, index, type); } 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 82df3a5..f29bced 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java @@ -55,7 +55,8 @@ public enum DiagnosticErrorCode { HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED("BDE_0027", "headers.with.varying.length.not.supported"), HEADER_VALUE_CANNOT_BE_EMPTY("BDE_0028", "header.value.cannot.be.empty"), - DUPLICATE_HEADER("BDE_0029", "duplicate.header"); + DUPLICATE_HEADER("BDE_0029", "duplicate.header"), + INVALID_UNION_CONVERSION("BDE_0029", "invalid.union.conversion"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/csv_error.properties b/native/src/main/resources/csv_error.properties index ff9a22e..6fa91e0 100644 --- a/native/src/main/resources/csv_error.properties +++ b/native/src/main/resources/csv_error.properties @@ -110,3 +110,6 @@ error.header.value.cannot.be.empty=\ error.duplicate.header=\ Duplicate header found: ''{0}'' + +error.invalid.union.conversion=\ + The CSV cannot be converted into any of the uniform union types in ''{0}'' From 145ca8affc3f87d77316b2417ddf6e86e3890e1e Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 14 Aug 2024 14:58:44 +0530 Subject: [PATCH 136/147] Add tests for slice operations --- .../tests/parse_string_to_array_test.bal | 2 +- .../tests/parse_type_compatibility_test.bal | 58 +++++++++++++++++++ .../user_config_with_parser_options_test.bal | 22 +++---- .../lib/data/csvdata/csv/CsvCreator.java | 2 +- .../lib/data/csvdata/csv/CsvParser.java | 27 ++++++--- .../lib/data/csvdata/csv/CsvTraversal.java | 2 +- .../src/main/resources/csv_error.properties | 2 +- 7 files changed, 93 insertions(+), 22 deletions(-) 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 e6b3565..e764c8e 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal @@ -340,7 +340,7 @@ function testArrayIndexes() { 5, 6, 7 7, 8, 9`; - record {}[2]|csv:Error rec = csv:parseString(csv); + record{}[2]|csv:Error rec = csv:parseString(csv); test:assertEquals(rec, [ {a: 1, b: 2}, {a: 3, b: 4} 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 325109a..06b36a7 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 @@ -450,3 +450,61 @@ function testFromCsvWithIntersectionTypeCompatibility2() { ["3", "string3", true, "string3"] ]); } + +@test:Config +function testSliceOperation() { + string[][] v = [["1", "2"], ["3", "4"], ["a", "b"]]; + var v2 = [{a: 1, b: 2}, {a: 3, b: 4}, {a: "a", b: "b"}]; + string v3 = string `a,b + 1,2 + 3,4 + a,b`; + + int[2][]|error c = csv:parseList(v); + test:assertEquals(c, [[1, 2], [3, 4]]); + + record{|int...;|}[2]|error c2 = csv:parseList(v, {customHeaders: ["a", "b"]}); + test:assertEquals(c2, [{a: 1, b: 2}, {a: 3, b: 4}]); + + int[2][]|error c3 = csv:transform(v2, {headersOrder: ["a", "b"]}); + test:assertEquals(c3, [[1, 2], [3, 4]]); + + record{|int...;|}[2]|error c4 = csv:transform(v2); + test:assertEquals(c4, [{a: 1, b: 2}, {a: 3, b: 4}]); + + int[2][]|error c5 = csv:parseString(v3); + test:assertEquals(c5, [[1, 2], [3, 4]]); + + record{|int...;|}[2]|error c6 = csv:parseString(v3); + test:assertEquals(c6, [{a: 1, b: 2}, {a: 3, b: 4}]); +} + +@test:Config +function testSliceOperation2() { + string[][] v = [["c", "c", "c"], ["1", "2", "a"], ["c", "c", "c"], ["3", "4", "a"], ["a", "b", "a"]]; + var v2 = [{a: "c", b: "c", c: "c"}, {a: 1, b: 2, c: "c"}, {a: "c", b: "c", c: "c"}, {a: 3, b: 4, c: "c"}, {a: "a", b: "b", c: "c"}]; + string v3 = string `a,b, c + c,c,c + 1,2,c + c,c,c + 3,4,c + a,b,c`; + + int[2][2]|error c = csv:parseList(v, {skipLines: [1, 3]}); + test:assertEquals(c, [[1, 2], [3, 4]]); + + record{|int...;|}[2]|error c2 = csv:parseList(v, {customHeaders: ["a", "b", "c"], skipLines: [1, 3]}); + test:assertEquals(c2, [{a: 1, b: 2}, {a: 3, b: 4}]); + + int[2][2]|error c3 = csv:transform(v2, {headersOrder: ["a", "b", "c"], skipLines: [1, 3]}); + test:assertEquals(c3, [[1, 2], [3, 4]]); + + record{|int...;|}[2]|error c4 = csv:transform(v2, {skipLines: [1, 3]}); + test:assertEquals(c4, [{a: 1, b: 2}, {a: 3, b: 4}]); + + int[2][2]|error c5 = csv:parseString(v3, {skipLines: [1, 3]}); + test:assertEquals(c5, [[1, 2], [3, 4]]); + + record{|int...;|}[2]|error c6 = csv:parseString(v3, {skipLines: [1, 3]}); + test:assertEquals(c6, [{a: 1, b: 2}, {a: 3, b: 4}]); +} \ No newline at end of file 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 91d84f2..b510840 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 @@ -354,7 +354,7 @@ function testCommentConfigOption() { cn = csv:parseString(csvValue10); test:assertTrue(cn is csv:Error); - test:assertEquals(( cn).message(), "Invalid length for the headers"); + test:assertEquals(( cn).message(), "Invalid number of headers"); cn = csv:parseString(csvValue9); test:assertTrue(cn is csv:Error); @@ -435,7 +435,7 @@ function testCommentConfigOption2() { cn = csv:parseString(csvValue7, {comment: "&", header: 2}); test:assertTrue(cn is csv:Error); - test:assertEquals((cn).message(), "Invalid length for the headers"); + test:assertEquals((cn).message(), "Invalid number of headers"); cn2 = csv:parseString(csvValue1, {comment: "&"}); test:assertTrue(cn2 is csv:Error); @@ -600,19 +600,19 @@ function testCustomHeaderOption() { 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 headers"); + test:assertEquals((ct1br).message(), "Invalid number of headers"); record {}[]|csv:Error ct1br2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "b", "c", "d"]}); test:assertTrue(ct1br2 is csv:Error); - test:assertEquals((ct1br2).message(), "Invalid length for the headers"); + test:assertEquals((ct1br2).message(), "Invalid number of headers"); record {}[]|csv:Error ct1br2_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "c", "b", "d"]}); test:assertTrue(ct1br2_2 is csv:Error); - test:assertEquals((ct1br2_2).message(), "Invalid length for the headers"); + test:assertEquals((ct1br2_2).message(), "Invalid number of headers"); record {}[]|csv:Error ct1br3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: []}); test:assertTrue(ct1br3 is csv:Error); - test:assertEquals((ct1br3).message(), "Invalid length for the headers"); + test:assertEquals((ct1br3).message(), "Invalid number of headers"); record {|string a; string b; string c;|}[]|csv:Error ct1br5 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"]}); test:assertTrue(ct1br5 is csv:Error); @@ -686,11 +686,11 @@ function testCustomHeaderParserOption2() { record {}[]|csv:Error ct1br2 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: []}); test:assertTrue(ct1br2 is csv:Error); - test:assertEquals((ct1br2).message(), "Invalid length for the headers"); + test:assertEquals((ct1br2).message(), "Invalid number of headers"); record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br3 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); test:assertTrue(ct1br3 is csv:Error); - test:assertEquals((ct1br3).message(), "Invalid length for the headers"); + test:assertEquals((ct1br3).message(), "Invalid number of headers"); record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br4 = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeadersAbsent: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(ct1br4, [ @@ -761,7 +761,7 @@ function testCustomHeaderParserOption2() { record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1"]}); test:assertTrue(ct1br11 is csv:Error); - test:assertEquals((ct1br11).message(), "Invalid length for the headers"); + test:assertEquals((ct1br11).message(), "Invalid number of headers"); record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ @@ -837,12 +837,12 @@ function testTextQuotesWithParserOptions() { record {}[]|csv:Error cn6 = csv:parseString(csvValue6, {}); test:assertTrue(cn6 is csv:Error); - test:assertEquals((cn6).message(), "Invalid length for the headers"); + test:assertEquals((cn6).message(), "Invalid number of headers"); cn6 = csv:parseString(string `a,b,c,d 1,1,1,1,1`, {}); test:assertTrue(cn6 is csv:Error); - test:assertEquals((cn6).message(), "Invalid length for the headers"); + test:assertEquals((cn6).message(), "Invalid number of headers"); } @test:Config 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 081155d..05f3ecf 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 @@ -97,7 +97,7 @@ static void convertAndUpdateCurrentCsvNode(CsvParser.StateMachine sm, ArrayType arrayType = (ArrayType) currentCsvNodeType; if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < sm.columnIndex) { - sm.earlyReturn = true; + sm.isColumnMaxSizeReached = true; return; } ((BArray) currentCsv).add(sm.columnIndex, convertedValue); 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 0c22193..239a024 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 @@ -146,7 +146,8 @@ static class StateMachine { int arraySize = 0; boolean addHeadersForOutput = false; int currentCsvNodeLength = 0; - boolean earlyReturn = false; + boolean isColumnMaxSizeReached = false; + boolean isRowMaxSizeReached = false; StateMachine() { reset(); @@ -183,7 +184,8 @@ public void reset() { arraySize = 0; addHeadersForOutput = false; currentCsvNodeLength = 0; - earlyReturn = false; + isColumnMaxSizeReached = false; + isRowMaxSizeReached = false; } private static boolean isWhitespace(char ch, Object lineTerminator) { @@ -544,6 +546,13 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { for (; i < count; i++) { ch = buff[i]; sm.processLocation(ch); + if (sm.isRowMaxSizeReached) { + if (ch == EOF) { + state = ROW_END_STATE; + break; + } + continue; + } if (ch == Constants.LineTerminator.CR) { CsvUtils.setCarriageTokenPresent(true); continue; @@ -639,7 +648,8 @@ private static void handleCsvRow(StateMachine sm, boolean trim) { if (trim) { value = value.trim(); } - if (!(value.isBlank() && sm.currentCsvNodeLength == 0) && !sm.earlyReturn) { + if (!(value.isBlank() && sm.currentCsvNodeLength == 0) + && !sm.isColumnMaxSizeReached && !sm.isRowMaxSizeReached) { addRowValue(sm, trim); } if (!sm.isCurrentCsvNodeEmpty) { @@ -660,7 +670,7 @@ private static void updateLineAndColumnIndexesWithoutRowIndexes(StateMachine sm) sm.currentCsvNode = null; sm.isCurrentCsvNodeEmpty = true; sm.columnIndex = 0; - sm.earlyReturn = false; + sm.isColumnMaxSizeReached = false; sm.clear(); } @@ -704,6 +714,9 @@ private static void finalizeTheRow(StateMachine sm) { } sm.arraySize++; sm.currentCsvNodeLength = 0; + if (sm.arraySize == rootArraySize) { + sm.isRowMaxSizeReached = true; + } } private static void addRowValue(StateMachine sm) { @@ -711,7 +724,7 @@ private static void addRowValue(StateMachine sm) { } private static void addRowValue(StateMachine sm, boolean trim) { - if (sm.earlyReturn) { + if (sm.isColumnMaxSizeReached || sm.isRowMaxSizeReached) { return; } Field currentField = null; @@ -775,7 +788,7 @@ private static Type getExpectedRowTypeOfTuple(StateMachine sm, TupleType tupleTy } else { sm.charBuffIndex = 0; if (sm.config.allowDataProjection) { - sm.earlyReturn = true; + sm.isColumnMaxSizeReached = true; return null; } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TUPLE_SIZE, tupleTypes.size()); @@ -787,7 +800,7 @@ private static Type getExpectedRowTypeOfArray(StateMachine sm, ArrayType arrayTy if (arrayType.getSize() != -1 && arrayType.getSize() <= sm.columnIndex) { sm.charBuffIndex = 0; if (sm.config.allowDataProjection) { - sm.earlyReturn = true; + sm.isColumnMaxSizeReached = true; return null; } throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_ARRAY_SIZE, arrayType.getSize()); 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 46176dc..e551ac5 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 @@ -475,7 +475,7 @@ private void constructCsvMapFromNonMapping(BArray csvElement, if (this.headers == null) { this.headers = CsvUtils.createHeadersForParseLists(csvElement, headers, config); if (!this.isFirstRowInserted && config.headersRows >= 1) { - // To skip the row at the position [config.headersRows - 1] from being added to the result. + // To skip the row at the position [config.headersRows - 1] from being aded to the result. this.isFirstRowIsHeader = true; this.isFirstRowInserted = true; return; diff --git a/native/src/main/resources/csv_error.properties b/native/src/main/resources/csv_error.properties index 6fa91e0..2afb2e2 100644 --- a/native/src/main/resources/csv_error.properties +++ b/native/src/main/resources/csv_error.properties @@ -82,7 +82,7 @@ error.inconsistent.header=\ Header ''{0}'' cannot be find in data rows error.invalid.custom.header.length=\ - Invalid length for the headers + Invalid number of headers error.invalid.header.names.length=\ Invalid number of headers From 821b0b03a1261aeebbe073887e6c4dda20590c4c Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Wed, 14 Aug 2024 18:03:50 +0530 Subject: [PATCH 137/147] [Automated] Update the native jar versions --- ballerina/CompilerPlugin.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index c4af7c4..e7c869f 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -1,5 +1,5 @@ [plugin] -id = "constraint-compiler-plugin" +id = "data.csv-compiler-plugin" class = "io.ballerina.lib.data.csvdata.compiler.CsvDataCompilerPlugin" [[dependency]] From 55ef4460a1c505a708ea3a2142f68108aff47b03 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 15 Aug 2024 14:23:36 +0530 Subject: [PATCH 138/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 0bfd723..7516162 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0-20240801-104200-87df251c" +distribution-version = "2201.9.2" [[package]] org = "ballerina" From 978a6d067ae45c5cf2b265b14ac6333594e3635e Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 15 Aug 2024 14:26:03 +0530 Subject: [PATCH 139/147] [Automated] Update the native jar versions --- ballerina/Dependencies.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 7516162..0bfd723 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,7 +5,7 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.9.2" +distribution-version = "2201.10.0-20240801-104200-87df251c" [[package]] org = "ballerina" From 0914feaab691911cadf92879a0dac2365c23123c Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Thu, 15 Aug 2024 16:22:13 +0530 Subject: [PATCH 140/147] Update gradle scripts and compiler plugin errors --- .gitignore | 2 +- ballerina-tests/build.gradle | 33 +++++++-- .../tests/parse_list_type_as_list_test.bal | 26 ++----- .../tests/parse_list_type_as_record_test.bal | 42 ++++++------ .../tests/parse_record_type_as_list_test.bal | 6 +- .../parse_record_type_as_record_test.bal | 26 +++---- .../tests/parse_string_to_record_tests.bal | 16 ++--- .../tests/parse_string_compatibality_test.bal | 5 +- .../user_config_with_parser_options_test.bal | 24 +++---- ballerina/build.gradle | 8 +-- build-config/resources/CompilerPlugin.toml | 2 +- build.gradle | 6 +- compiler-plugin-test/build.gradle | 4 ++ .../csvdata/compiler/CompilerPluginTest.java | 62 +++++++++++++++-- .../sample_package_1/main.bal | 5 +- .../sample_package_12/Ballerina.toml | 8 +++ .../sample_package_12/main.bal | 58 ++++++++++++++++ .../sample_package_2/main.bal | 35 ++++++++++ .../sample_package_7/main.bal | 65 ++++++++++++++++++ .../src/test/resources/testng.xml | 2 +- .../compiler/CsvDataTypeValidator.java | 68 +++++++++++++++---- .../lib/data/csvdata/csv/CsvParser.java | 1 + .../lib/data/csvdata/csv/CsvTraversal.java | 1 + .../lib/data/csvdata/utils/CsvUtils.java | 6 ++ 24 files changed, 396 insertions(+), 115 deletions(-) create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/Ballerina.toml create mode 100644 compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal diff --git a/.gitignore b/.gitignore index 38d72e0..e8bcae9 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,7 @@ target bin/ # IDEA Files -.idea/ +.idea2/ *.iml *.ipr *.iws diff --git a/ballerina-tests/build.gradle b/ballerina-tests/build.gradle index 42807ca..c83dd9d 100644 --- a/ballerina-tests/build.gradle +++ b/ballerina-tests/build.gradle @@ -16,6 +16,7 @@ */ plugins { id 'jacoco' + id 'groovy' } import org.apache.tools.ant.taskdefs.condition.Os @@ -49,7 +50,7 @@ def stripBallerinaExtensionVersion(String extVersion) { } } -task clean { +clean { delete "${project.projectDir}/${testCommonPackage}/target" testPackages.each { testPackage -> @@ -162,13 +163,25 @@ task publishTestCommonPackageToLocal { } } +task commitTomlFiles { + doLast { + project.exec { + ignoreExitValue true + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine 'cmd', '/c', "git commit -m \"[Automated] Update the native jar versions\" Ballerina.toml Dependencies.toml" + } else { + commandLine 'sh', '-c', "git commit -m '[Automated] Update the native jar versions' Ballerina.toml Dependencies.toml" + } + } + } +} + task ballerinaTest { - inputs.dir file(project.projectDir) dependsOn(":${packageName}-${packageOrg}:build") dependsOn(updateTomlVersions) dependsOn(initializeVariables) dependsOn(publishTestCommonPackageToLocal) - dependsOn(deleteDependencyTomlFile) + finalizedBy(commitTomlFiles) doLast { testPackages.each { testPackage -> @@ -214,10 +227,16 @@ publishing { } } -task test { +test { dependsOn(ballerinaTest) } -task build { - dependsOn(test) -} +build.dependsOn ":${packageName}-ballerina:build" +build.dependsOn ":${packageName}-compiler-plugin:build" + +test.dependsOn ":${packageName}-ballerina:build" +test.dependsOn ":${packageName}-compiler-plugin:build" +test.dependsOn ":${packageName}-compiler-plugin-tests:test" + +publishToMavenLocal.dependsOn build +publish.dependsOn build 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 086e760..2101347 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 @@ -455,8 +455,9 @@ function testParseListsWithOutputHeaders() { ["a", true, 1] ]); - ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headersRows: 2}); - test:assertEquals(ct1bt1, []); + [string, boolean, int][]|[anydata...][]|csv:Error ct1bt1_union = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headersRows: 2}); + test:assertTrue(ct1bt1_union is csv:Error); + test:assertEquals((ct1bt1_union).message(), "Custom headers should be provided"); ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1, [ @@ -469,7 +470,7 @@ function testParseListsWithOutputHeaders() { ["a", true, 1] ]); - ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21}); + ct1bt1 = csv:parseList([["a", "true", "1"]], {headersRows: 1}); test:assertEquals(ct1bt1, []); (string|boolean|int)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1}); @@ -477,9 +478,6 @@ function testParseListsWithOutputHeaders() { ["a", true, 1] ]); - ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headersRows: 2}); - test:assertEquals(ct1bt1_2, []); - ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1_2, [ ["a", true, 1] @@ -491,23 +489,12 @@ function testParseListsWithOutputHeaders() { ["a", true, 1] ]); - ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21}); - test:assertEquals(ct1bt1_2, []); - [string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_3, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 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"]], {headersRows: 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"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean")); @@ -516,8 +503,9 @@ function testParseListsWithOutputHeaders() { test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean")); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21, outputWithHeaders: true}); - test:assertEquals(ct1bt1_3, []); + [string, boolean, int|string][]|[anydata...][]|csv:Error ct1bt1_3_with_union = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21, outputWithHeaders: true}); + test:assertTrue(ct1bt1_3_with_union is csv:Error); + test:assertEquals((ct1bt1_3_with_union).message(), "Custom headers should be provided"); string[][]|csv:Error ct1bt1_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_4, [ 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 848e76e..053e4d3 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 @@ -551,7 +551,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { - record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 0, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 0, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1}, @@ -564,7 +564,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { {a: "a", b: true, c: 1} ]); - record{string a; boolean b; int c;}[]|csv:Error ct1br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + record{string a; boolean b; int c;}[]|csv:Error ct1br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4_3, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} @@ -572,60 +572,60 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { record{string a; boolean b; int c;}[]|csv:Error ct1br4_4 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); 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"]], {headersRows: 2, outputWithHeaders: true}); + record{string a; boolean b; int c;}[]|record{}[]|csv:Error ct1br4_5 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2}); 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"]], {headersRows: 2, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); 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"]], {headersRows: 2, outputWithHeaders: true}); + record{|string a; boolean b; int...;|}[]|record{}[]|csv:Error ct1br4_5_2 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2}); 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"]], {headersRows: 1, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + map[]|csv:Error ct2br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_3, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - map[]|csv:Error ct2br4_3_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 3, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + map[]|csv:Error ct2br4_3_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 3, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_3_2, []); map[]|csv:Error ct2br4_4 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_4, [ {a: "a", b: true, c: 1} ]); map[]|csv:Error ct2br4_5 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_5, [ {a: "a", b: "true", c: "1"}, {a: "a", b: "true", c: "1"} ]); - map[]|csv:Error ct2br4_7 = csv:parseList( + map[]|record{}[]|csv:Error ct2br4_7 = csv:parseList( [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 4, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); test:assertEquals(ct2br4_7, []); - map[]|csv:Error ct2br4_6 = csv:parseList( + map[]|record{}[]|csv:Error ct2br4_6 = csv:parseList( [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 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"]], {headersRows: 1, outputWithHeaders: true}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1}); test:assertEquals(ct2br4_8, [ {"a": "a", "1": "1", "true": "true"}, {"a": "a", "1": "1", "true": "true"}, @@ -633,7 +633,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_8_2 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, outputWithHeaders: false}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1}); test:assertEquals(ct2br4_8_2, [ {"a": "a", "1": "1", "true": "true"}, {"a": "a", "1": "1", "true": "true"}, @@ -641,7 +641,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_9 = csv:parseList( - [["a", "c", "b"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1, outputWithHeaders: true}); + [["a", "c", "b"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1}); test:assertEquals(ct2br4_9, [ {a: "a", b: "true", c: "2"}, {a: "a", b: "true", c: "3"}, @@ -650,7 +650,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_10 = csv:parseList( - [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1, outputWithHeaders: true}); + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1}); test:assertEquals(ct2br4_10, [ {a: "a", c: true, b: 2}, {a: "a", c: true, b: 3}, @@ -659,7 +659,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_10_2 = csv:parseList( - [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1, outputWithHeaders: false}); + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1}); test:assertEquals(ct2br4_10_2, [ {a: "a", c: true, b: 2}, {a: "a", c: true, b: 3}, @@ -667,9 +667,9 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { {a: "a", c: true, b: 5} ]); - ct2br4_10_2 = csv:parseList( + map[]|record{}[]|csv:Error ct2br4_10_3 = csv:parseList( [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1, customHeaders: ["c", "d", "e"], outputWithHeaders: false}); - test:assertEquals(ct2br4_10_2, [ + test:assertEquals(ct2br4_10_3, [ {c: "a", e: true, d: 2}, {c: "a", e: true, d: 3}, {c: "a", e: true, d: 4}, 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 93b4e74..23a4317 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 @@ -667,16 +667,16 @@ function testsRecordsOutputWithHeadrs() { test:assertTrue(bm3anyd3t_3 is csv:Error); test:assertEquals(( bm3anyd3t_3).message(), "CSV data rows with varying headers are not yet supported"); - record{}[]|csv:Error bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"a": 3, "b": 4}], {outputWithHeaders: true}); + record{}[]|csv:Error bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"a": 3, "b": 4}]); test:assertEquals(bm3anyd3t_4, [{"a": 1, "b": 2}, {"a": 3, "b": 4}]); - bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"c": 3, "d": 4}], {outputWithHeaders: true}); + bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"c": 3, "d": 4}]); 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}); + bm3anyd3t_4 = csv:parseList([["a", "b"], ["c", "d", "e"]]); 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 3c603e6..172ec9d 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 @@ -58,7 +58,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType() { {b1: true, b2: false, b3: (), b4: false} ]); - BooleanRecord2Array|csv:Error bm4br2 = csv:transform([bm4, bm4], {outputWithHeaders: false}, BooleanRecord2Array); + BooleanRecord2Array|csv:Error bm4br2 = csv:transform([bm4, bm4], {}, BooleanRecord2Array); test:assertTrue(bm4br2 is csv:Error); test:assertEquals((bm4br2).message(), common:generateErrorMessageForMissingRequiredField("b2")); @@ -146,7 +146,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { {b1: true, b2: false, b3: (), b4: true, defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error bm1br6 = csv:transform([bm1, bm1], {outputWithHeaders: false}, BooleanRecord6Array); + BooleanRecord6Array|csv:Error bm1br6 = csv:transform([bm1, bm1], {}, BooleanRecord6Array); test:assertTrue(bm1br6 is csv:Error); test:assertEquals((bm1br6).message(), common:generateErrorMessageForMissingRequiredField("b3")); @@ -156,7 +156,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType2() { {b1: true, b3: (), defaultableField: "", nillableField: ()} ]); - BooleanRecord6Array|csv:Error bm3br6 = csv:transform([bm3, bm3], {outputWithHeaders: false}, BooleanRecord6Array); + BooleanRecord6Array|csv:Error bm3br6 = csv:transform([bm3, bm3], {}, BooleanRecord6Array); test:assertEquals(bm3br6, [ {b1: true, b3: (), defaultableField: "", nillableField: ()}, {b1: true, b3: (), defaultableField: "", nillableField: ()} @@ -247,7 +247,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType3() { {b1: true, b2: false} ]); - BooleanRecord10Array|csv:Error bm2br10 = csv:transform([bm2, bm2], {outputWithHeaders: false}, BooleanRecord10Array); + BooleanRecord10Array|csv:Error bm2br10 = csv:transform([bm2, bm2], {}, BooleanRecord10Array); test:assertEquals(bm2br10, [ {b1: true, b2: false}, {b1: true, b2: false} @@ -325,7 +325,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType3() { {b1: true, b2: false, defaultableField: "", nillableField :null} ]); - BooleanRecord13Array|csv:Error bm2br13 = csv:transform([bm2, bm2], {outputWithHeaders: false}, BooleanRecord13Array); + BooleanRecord13Array|csv:Error bm2br13 = csv:transform([bm2, bm2], {}, BooleanRecord13Array); test:assertEquals(bm2br13, [ {b1: true, b2: false, defaultableField: "", nillableField :null}, {b1: true, b2: false, defaultableField: "", nillableField :null} @@ -368,7 +368,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType4() { test:assertTrue(bm4br14 is csv:Error); test:assertEquals((bm4br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); - BooleanRecord14Array|csv:Error bm5br14 = csv:transform([bm5, bm5], {outputWithHeaders: false}, BooleanRecord14Array); + BooleanRecord14Array|csv:Error bm5br14 = csv:transform([bm5, bm5], {}, BooleanRecord14Array); test:assertTrue(bm5br14 is csv:Error); test:assertEquals((bm5br14).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); @@ -384,13 +384,13 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType4() { test:assertTrue(bm4br15 is csv:Error); test:assertEquals((bm4br15).message(), common:generateErrorMessageForMissingRequiredField("b1")); - BooleanRecord16Array|csv:Error bm1br16 = csv:transform([bm1, bm1], {headersOrder: ["b2", "b1"]}, BooleanRecord16Array); + BooleanRecord16Array|csv:Error bm1br16 = csv:transform([bm1, bm1], {}, BooleanRecord16Array); test:assertEquals(bm1br16, [ {b1: true, b2: false}, {b1: true, b2: false} ]); - BooleanRecord16Array|csv:Error bm2br16 = csv:transform([bm2, bm2], {outputWithHeaders: false}, BooleanRecord16Array); + BooleanRecord16Array|csv:Error bm2br16 = csv:transform([bm2, bm2], {}, BooleanRecord16Array); test:assertEquals(bm2br16, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} @@ -462,7 +462,7 @@ function testFromCsvWithTypeForMapAndRecordAsExpectedType4() { {b2: false, b3: (), i1: 1} ]); - BooleanRecord18Array|csv:Error bm4br18 = csv:transform([bm4, bm4], {outputWithHeaders: false}, BooleanRecord18Array); + BooleanRecord18Array|csv:Error bm4br18 = csv:transform([bm4, bm4], {}, BooleanRecord18Array); test:assertTrue(bm4br18 is csv:Error); test:assertEquals((bm4br18).message(), common:generateErrorMessageForMissingRequiredField("b2")); @@ -511,7 +511,7 @@ function testFromCsvWithTypeForMapAndMapAsExpectedType() { {b1: true, b2: false} ]); - NillableBooleanMapArray|csv:Error bm2nbma = csv:transform([bm2, bm2], {outputWithHeaders: false}, NillableBooleanMapArray); + NillableBooleanMapArray|csv:Error bm2nbma = csv:transform([bm2, bm2], {}, NillableBooleanMapArray); test:assertEquals(bm2nbma, [ {b1: true, b2: false, b3:(), n1: (), n3: ()}, {b1: true, b2: false, b3:(), n1: (), n3: ()} @@ -633,7 +633,7 @@ function testFromCsvWithTypeForMapAndMapAsExpectedType2() { {b1: true, b2: false} ]); - JsonMapArray|csv:Error bm2jma = csv:transform([bm2, bm2], {outputWithHeaders: false, headersOrder: []}, JsonMapArray); + JsonMapArray|csv:Error bm2jma = csv:transform([bm2, bm2], {}, JsonMapArray); test:assertEquals(bm2jma, [ {b1: true, b2: false, b3: (), n1: (), n3: ()}, {b1: true, b2: false, b3: (), n1: (), n3: ()} @@ -717,7 +717,7 @@ function testFromCsvWithTypeForMapAndMapAsExpectedType2() { {} ]); - StringMapArray|csv:Error bm1sma = csv:transform([bm1, bm1], {outputWithHeaders: false}, StringMapArray); + StringMapArray|csv:Error bm1sma = csv:transform([bm1, bm1], {}, StringMapArray); test:assertEquals(bm1sma, [ {}, {} @@ -764,6 +764,6 @@ function testArrayIndexesInRecords() { {a: 5} ]); - record {|int a;|}[5]|csv:Error rec2_2 = csv:transform(csv, {skipLines: [2], outputWithHeaders: false, headersOrder: ["a", "b"]}); + record {|int a;|}[5]|csv:Error rec2_2 = csv:transform(csv, {skipLines: [2]}); test:assertTrue(rec2_2 is csv:Error); } \ No newline at end of file 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 3a212dc..b27aea0 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,7 +20,7 @@ import ballerina/test; @test:Config function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { - BooleanRecord1Array|csv:Error csvb1br1 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true}); + BooleanRecord1Array|csv:Error csvb1br1 = csv:parseString(csvStringWithBooleanValues1); test:assertEquals(csvb1br1, [ {b1: true, b2: false, b3: true, b4: false}, {b1: true, b2: false, b3: true, b4: false}, @@ -69,11 +69,11 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType() { {b1: true, b2: false, b3: true, b4: false} ]); - BooleanRecord2Array|csv:Error csvb3br2 = csv:parseString(csvStringWithBooleanValues3, {outputWithHeaders: true}); + BooleanRecord2Array|csv:Error csvb3br2 = csv:parseString(csvStringWithBooleanValues3); test:assertTrue(csvb3br2 is csv:Error); test:assertEquals((csvb3br2).message(), common:generateErrorMessageForMissingRequiredField("b4")); - BooleanRecord2Array|csv:Error csvb4br2 = csv:parseString(csvStringWithBooleanValues4, {outputWithHeaders: true}); + BooleanRecord2Array|csv:Error csvb4br2 = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(csvb4br2, [ {b1: true, b2: "()", b3: (), b4: false}, {b1: true, b2: "()", b3: (), b4: false} @@ -343,7 +343,7 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType3() { @test:Config function testFromCsvStringWithTypeForStringAndRecordAsExpectedType4() { - BooleanRecord11Array|csv:Error csvb2br11 = csv:parseString(csvStringWithBooleanValues2, {outputWithHeaders: true}); + BooleanRecord11Array|csv:Error csvb2br11 = csv:parseString(csvStringWithBooleanValues2); 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: ()} @@ -362,7 +362,7 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType4() { {b1: true, b2: (), b3: (), b4: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord11Array|csv:Error csvb5br11 = csv:parseString(csvStringWithBooleanValues5, {outputWithHeaders: false}); + BooleanRecord11Array|csv:Error csvb5br11 = csv:parseString(csvStringWithBooleanValues5); test:assertEquals(csvb5br11, [ {b1: true, b2: false, b3: true, b4: "2", defaultableField: "", nillableField: ()}, {b1: true, b2: false, b3: true, b4: "3", defaultableField: "", nillableField: ()} @@ -377,7 +377,7 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType4() { {b1, b2, b3, b4, defaultableField: "", nillableField: ()} ]); - BooleanRecord12Array|csv:Error csvb1br12 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true}); + BooleanRecord12Array|csv:Error csvb1br12 = csv:parseString(csvStringWithBooleanValues1); test:assertTrue(csvb1br12 is csv:Error); test:assertEquals((csvb1br12).message(), common:generateErrorMessageForMissingRequiredField("requiredField")); @@ -401,7 +401,7 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType4() { {b1: true, b2: true, b3: false, defaultableField: "", nillableField: ()} ]); - BooleanRecord13Array|csv:Error csvb4br13 = csv:parseString(csvStringWithBooleanValues4, {outputWithHeaders: true}); + BooleanRecord13Array|csv:Error csvb4br13 = csv:parseString(csvStringWithBooleanValues4); test:assertEquals(csvb4br13, [ {b1: true, b2: "()", b3: "()", b4: false, defaultableField: "", nillableField: ()}, {b1: true, b2: "()", b3: "null", b4: false, defaultableField: "", nillableField: ()} @@ -418,7 +418,7 @@ function testFromCsvStringWithTypeForStringAndRecordAsExpectedType4() { {b2: "()", b3: "()", defaultableField: "", nillableField: ()} ]); - BooleanRecord13Array|csv:Error csvb7br13 = csv:parseString(csvStringWithBooleanValues7, {outputWithHeaders: true}); + BooleanRecord13Array|csv:Error csvb7br13 = csv:parseString(csvStringWithBooleanValues7); test:assertEquals(csvb7br13, [ {b1, b2, b3: "()", b4, defaultableField: "", nillableField: ()} ]); 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 3aca53a..b4a361a 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 @@ -225,7 +225,7 @@ function testParseBytes() returns error? { {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}] ); - rec = csv:parseBytes(csvBytes, {outputWithHeaders: true}); + 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}, @@ -282,7 +282,7 @@ function testParseStream() returns error? { ); csvByteStream = check io:fileReadBlocksAsStream(filepath); - rec = csv:parseStream(csvByteStream, {outputWithHeaders: true}); + 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}, @@ -348,7 +348,6 @@ function testErrorParseBytes() returns error? { @test:Config function testErrorParseStream() returns error? { - byte[] csvBytes = check io:fileReadBytes(errorFilepath); stream csvByteStream = check io:fileReadBlocksAsStream(errorFilepath); record{int a;}[]|csv:Error rec3 = csv:parseStream(csvByteStream, {}); 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 91d84f2..732b1ed 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 @@ -657,7 +657,7 @@ function testCustomHeaderOption() { @test:Config function testCustomHeaderParserOption2() { - record {}[]|csv:Error ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[]|csv:Error ct1br = csv:parseString(csvStringData1, {header: 1}); 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: ()}, @@ -666,7 +666,7 @@ function testCustomHeaderParserOption2() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeadersAbsent: ["f", "e", "d", "c", "b", "a"]}); + ct1br = csv:parseString(csvStringData1, {header: 1}); 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: ()}, @@ -675,7 +675,7 @@ function testCustomHeaderParserOption2() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - ct1br = csv:parseString(csvStringData1, {header: 1, customHeadersIfHeadersAbsent: ["b", "a"]}); + ct1br = csv:parseString(csvStringData1, {header: 1}); 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: ()}, @@ -692,7 +692,7 @@ function testCustomHeaderParserOption2() { test:assertTrue(ct1br3 is csv:Error); 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:parseString(csvStringData1, {header: 1, customHeadersIfHeadersAbsent: ["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}); 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: ()}, @@ -701,7 +701,7 @@ function testCustomHeaderParserOption2() { {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, customHeadersIfHeadersAbsent: ["f", "e", "d", "c", "b", "a"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5 = csv:parseString(csvStringData4, {header: 1}); test:assertTrue(ct1br5 is csv:Error); ct1br5 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f", "e", "d", "c", "b", "a"]}); @@ -983,37 +983,37 @@ function testSkipLineParameterWithOutputHeaderConfig() { 3,4 4,5`; - record {}[]|csv:Error result = csv:parseString(csv3, {outputWithHeaders: true, skipLines: "2-3"}); + record {}[]|csv:Error result = csv:parseString(csv3, {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"}); + result = csv:transform(csv1, {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"]}); + result = csv:parseList(csv2, {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, headersRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + result = csv:parseList(csv2, {headersRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result, [{a: 2, b: 3}]); result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [2, 3]]); - result = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); + result = csv:parseList(csv2, {headersRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result, [{a: 3, b: 4}]); result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [3, 4]]); - result = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 1, skipLines: "2-3"}); + result = csv:parseList(csv2, {headersRows: 1, skipLines: "2-3"}); test:assertEquals(result, [{'1: 2, '2: 3}]); result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 1, skipLines: "2-3"}); @@ -1022,7 +1022,7 @@ function testSkipLineParameterWithOutputHeaderConfig() { result2 = csv:parseList(csv2, {outputWithHeaders: false, headersRows: 1, skipLines: "2-3"}); test:assertEquals(result2, [[2, 3]]); - result = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); + result = csv:parseList(csv2, {headersRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); test:assertEquals(result, [{a: 3, b: 4}]); result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); diff --git a/ballerina/build.gradle b/ballerina/build.gradle index e6a4092..7cac14a 100644 --- a/ballerina/build.gradle +++ b/ballerina/build.gradle @@ -132,16 +132,14 @@ task deleteDependencyTomlFiles { updateTomlFiles.dependsOn copyStdlibs build.dependsOn "generatePomFileForMavenPublication" -build.dependsOn ":${packageName}-native:build" build.dependsOn deleteDependencyTomlFiles +build.dependsOn ":${packageName}-native:build" build.dependsOn ":${packageName}-compiler-plugin:build" -build.dependsOn deleteDependencyTomlFiles -build.finalizedBy ":${packageName}-ballerina-tests:build" -test.dependsOn ":${packageName}-native:build" +test.dependsOn "generatePomFileForMavenPublication" +test.dependsOn deleteDependencyTomlFiles test.dependsOn ":${packageName}-native:build" test.dependsOn ":${packageName}-compiler-plugin:build" -test.finalizedBy ":${packageName}-ballerina-tests:build" publish.dependsOn build publishToMavenLocal.dependsOn build diff --git a/build-config/resources/CompilerPlugin.toml b/build-config/resources/CompilerPlugin.toml index dd833b5..e814d75 100644 --- a/build-config/resources/CompilerPlugin.toml +++ b/build-config/resources/CompilerPlugin.toml @@ -1,5 +1,5 @@ [plugin] -id = "constraint-compiler-plugin" +id = "data.csv-compiler-plugin" class = "io.ballerina.lib.data.csvdata.compiler.CsvDataCompilerPlugin" [[dependency]] diff --git a/build.gradle b/build.gradle index dc3d177..d020275 100644 --- a/build.gradle +++ b/build.gradle @@ -92,5 +92,9 @@ release { } task build { - dependsOn('data.csv-ballerina:build') + dependsOn(':data.csv-compiler-plugin:build') + dependsOn(':data.csv-native:build') + dependsOn(':data.csv-ballerina:build') + dependsOn(':data.csv-compiler-plugin-tests:test') + dependsOn(':data.csv-ballerina-tests:test') } diff --git a/compiler-plugin-test/build.gradle b/compiler-plugin-test/build.gradle index 6d5c7f2..1ad7000 100644 --- a/compiler-plugin-test/build.gradle +++ b/compiler-plugin-test/build.gradle @@ -105,4 +105,8 @@ jacocoTestReport { sourceSets project(':data.csv-compiler-plugin').sourceSets.main } +build { + dependsOn(test) +} + test.dependsOn ":data.csv-ballerina:build" 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 a61bdde..ea9a7eb 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 @@ -59,7 +59,7 @@ public void testInvalidExpectedUnionType() { List errorDiagnosticsList = diagnosticResult.diagnostics().stream() .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) .collect(Collectors.toList()); - Assert.assertEquals(errorDiagnosticsList.size(), 20); + Assert.assertEquals(errorDiagnosticsList.size(), 21); 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); @@ -70,20 +70,21 @@ 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(10).diagnosticInfo().messageFormat(), UNSUPPORTED_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(16).diagnosticInfo().messageFormat(), UNSUPPORTED_FIELD_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); + Assert.assertEquals(errorDiagnosticsList.get(20). + diagnosticInfo().messageFormat(), UNSUPPORTED_TUPLE_MEMBER_TYPE); } @Test @@ -93,8 +94,11 @@ public void testInvalidRecordFields() { List errorDiagnosticsList = diagnosticResult.diagnostics().stream() .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) .collect(Collectors.toList()); - Assert.assertEquals(errorDiagnosticsList.size(), 1); + Assert.assertEquals(errorDiagnosticsList.size(), 4); Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo().messageFormat(), DUPLICATE_FIELD); + Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo().messageFormat(), DUPLICATE_FIELD); + Assert.assertEquals(errorDiagnosticsList.get(2).diagnosticInfo().messageFormat(), DUPLICATE_FIELD); + Assert.assertEquals(errorDiagnosticsList.get(3).diagnosticInfo().messageFormat(), DUPLICATE_FIELD); } @Test @@ -164,13 +168,31 @@ public void testIgnoredCustomHeaderIfAbsentOptions() { List errorDiagnosticsList = diagnosticResult.diagnostics().stream() .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) .collect(Collectors.toList()); - Assert.assertEquals(errorDiagnosticsList.size(), 3); + Assert.assertEquals(errorDiagnosticsList.size(), 12); Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo() .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo() .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); Assert.assertEquals(errorDiagnosticsList.get(2).diagnosticInfo() .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(3).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(4).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(5).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(6).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(7).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(8).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(9).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(10).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + Assert.assertEquals(errorDiagnosticsList.get(11).diagnosticInfo() + .messageFormat(), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); } @Test @@ -266,4 +288,32 @@ public void testNonCsvFunctionCall() { .collect(Collectors.toList()); Assert.assertEquals(errorDiagnosticsList.size(), 0); } + + @Test + public void testIgnoredCustomHeaderOptions2() { + DiagnosticResult diagnosticResult = + CompilerPluginTestUtils.loadPackage("sample_package_12").getCompilation().diagnosticResult(); + List errorDiagnosticsList = diagnosticResult.diagnostics().stream() + .filter(r -> r.diagnosticInfo().severity().equals(DiagnosticSeverity.ERROR)) + .collect(Collectors.toList()); + Assert.assertEquals(errorDiagnosticsList.size(), 9); + Assert.assertEquals(errorDiagnosticsList.get(0).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(1).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(2).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(3).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(4).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(5).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(6).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(7).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + Assert.assertEquals(errorDiagnosticsList.get(8).diagnosticInfo() + .messageFormat(), CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + } } 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 4adb715..e4a416c 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 @@ -5,7 +5,8 @@ type A [[int, string], [int, string]]; public function main() returns error? { stream s = ( [[1, 2, 3, 4, 5]]).toStream(); - [[int, string], [int, string]] _ = check csv:parseString(string `a,b`, {}); + [[int, string], [int, string]]|error v = csv:parseString(string `a,b`, {}); + [[int, string], [int, string]]|[anydata...][]|error a = csv:parseString(string `a,b`, {}); [record{}, record{}, record{}, record{}] _ = check csv:parseString(string `a,b`, {}); [[int, string], [int, string]] _ = check csv:parseStream(s, {}); [record{}, record{}, record{}, record{}] _ = check csv:parseStream(s, {}); @@ -22,7 +23,7 @@ public function main() returns error? { 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[]][]|csv:Error v2 = csv:parseList([], {}); [regexp:RegExp, xml, int[]][]|int[][] _ = check csv:parseList([], {}); int[][]|[regexp:RegExp, xml, int[]][] _ = check csv:parseList([], {}); int[][]|[record{}|regexp:RegExp][] _ = check csv:parseList([], {}); diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/Ballerina.toml b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/Ballerina.toml new file mode 100644 index 0000000..4c5b968 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/Ballerina.toml @@ -0,0 +1,8 @@ +[package] +org = "wso2" +name = "sample_package_12" +version = "0.1.0" +distribution = "2201.9.2" + +[build-options] +observabilityIncluded = true diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal new file mode 100644 index 0000000..f1ca8d8 --- /dev/null +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal @@ -0,0 +1,58 @@ +import ballerina/data.csv; + +string[]? headers = (); + +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: false}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); + +public function main() returns error? { + [anydata...][] val = check csv:parseList([["1", "2"]], {headersRows: 0}); + val = check csv:parseList([["1", "2"]], {headersRows: 0}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); + val = check csv:parseList([["1", "2"]], {headersRows: 1}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); + val = check csv:parseList([["1", "2"]], {headersRows: 2}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); + val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); + + [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); +} diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/main.bal index 4670e29..3de2239 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_2/main.bal @@ -5,3 +5,38 @@ type A record { int a; string b; }; + +type B record { + @c:Name {value: "b"} + int a; + @c:Name {value: "a"} + string b; +}; + +type B2 record { + @c:Name {value: "b"} + int a; + @c:Name {value: "b"} + string b; +}; + +type B3 record { + @c:Name {value: "a"} + int a; + @c:Name {value: "a"} + string b2; +}; + +type B4 record { + @c:Name {value: "b"} + int a; + @c:Name {value: "a"} + string b2; +}; + +type C record { + @c:Name {value: "x"} + int a; + @c:Name {value: "x"} + string b; +}; diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal index a3cc62c..e9a1acb 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal @@ -16,11 +16,34 @@ record{}[] val9 = check csv:parseString(string `a, b`, {header: false, customHea record{}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); record{}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); record{}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); +record{}[]|error val13 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); +record{}[]|[int...][]|error val14 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + +anydata[][] arrVal = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); +anydata[][] arrVal2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); +anydata[][] arrVal3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); +anydata[][] arrVal4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); +anydata[][] arrVal5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); +anydata[][] arrVal6 = check csv:parseString(string `a, b`, {header: false}); +anydata[][] arrVal7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); +anydata[][] arrVal8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); +anydata[][] arrVal9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); +anydata[][] arrVal10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); +anydata[][] arrVal11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); +anydata[][] arrVal12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); +anydata[][]|error arrVal13 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); +anydata[][]|[int...][]|error arrVal14 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); public function main() returns error? { record{}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); val = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + record{}[]|error val_2 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + val_2 = csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + + record{}[]|record{int a;}[]|error val_3 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + val_3 = csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); val2 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ()}); @@ -53,4 +76,46 @@ public function main() returns error? { record{}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); val11 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); + + anydata[][] arrVal = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + val = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + + anydata[][]|error arrVal_2 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + arrVal_2 = csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + + anydata[][]|[anydata...][]|error arrVal_3 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + arrVal_3 = csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + + anydata[][] arrVal2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); + val2 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ()}); + + anydata[][] arrVal3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); + val3 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); + + anydata[][] arrVal4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); + val4 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ()}); + + anydata[][] arrVal5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); + val5 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ()}); + + anydata[][] arrVal6 = check csv:parseString(string `a, b`, {header: false}); + val6 = check csv:parseString(string ``, {header: false}); + + anydata[][] arrVal7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); + val7 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ["a", "b"]}); + + anydata[][] arrVal8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); + val8 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: null}); + + anydata[][] arrVal9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); + val9 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: null}); + + anydata[][] arrVal10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); + val10 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); + + anydata[][] arrVal11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); + val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); + + anydata[][] arrVal12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); + val11 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); } diff --git a/compiler-plugin-test/src/test/resources/testng.xml b/compiler-plugin-test/src/test/resources/testng.xml index 9ab3a2f..e5f9421 100644 --- a/compiler-plugin-test/src/test/resources/testng.xml +++ b/compiler-plugin-test/src/test/resources/testng.xml @@ -21,7 +21,7 @@ - + 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 3b666ea..c8dbc2e 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 @@ -261,7 +261,48 @@ private void validateFunctionParameterTypesWithExpType(TypeSymbol expType, Locat ((TypeReferenceTypeSymbol) expType).typeDescriptor(), currentLocation, ctx, functionName, args); case INTERSECTION -> validateFunctionParameterTypesWithExpType( getRawType(expType), currentLocation, ctx, functionName, args); + case UNION -> { + List memberTypes = ((UnionTypeSymbol) expType).memberTypeDescriptors(); + + // only handles the A|error scenarios + if (isUnionContainsError(memberTypes)) { + if (memberTypes.size() == 2) { + TypeSymbol nonErrorTypeSymbol = ignoreErrorTypeFromUnionTypeSymbolAndReturn(memberTypes); + if (nonErrorTypeSymbol != null) { + validateFunctionParameterTypesWithExpType(nonErrorTypeSymbol, currentLocation, + ctx, functionName, args); + } + } + } + } + } + } + + private boolean isUnionContainsError(List memberTypes) { + for (TypeSymbol memberSymbol : memberTypes) { + if (memberSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { + memberSymbol = ((TypeReferenceTypeSymbol) memberSymbol).typeDescriptor(); + } + if (memberSymbol.typeKind() == TypeDescKind.ERROR) { + // ignore error type + return true; + } } + return false; + } + + private TypeSymbol ignoreErrorTypeFromUnionTypeSymbolAndReturn(List memberTypes) { + for (TypeSymbol memberSymbol : memberTypes) { + if (memberSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { + memberSymbol = ((TypeReferenceTypeSymbol) memberSymbol).typeDescriptor(); + } + if (memberSymbol.typeKind() == TypeDescKind.ERROR) { + // ignore error type + continue; + } + return memberSymbol; + } + return null; } private void validateFunctionParameterTypesWithArrayType(ArrayTypeSymbol expType, Location currentLocation, @@ -272,13 +313,15 @@ private void validateFunctionParameterTypesWithArrayType(ArrayTypeSymbol expType memberTypeSymbol = ((TypeReferenceTypeSymbol) memberTypeSymbol).typeDescriptor(); } switch (memberTypeSymbol.typeKind()) { - case RECORD, MAP -> validateFunctionParameterTypesWithMappingArray( - currentLocation, ctx, functionName, args); + case RECORD, MAP -> validateFunctionParameterTypesWithOptions( + currentLocation, ctx, functionName, args, true); + case ARRAY, TUPLE -> validateFunctionParameterTypesWithOptions( + currentLocation, ctx, functionName, args, false); } } - private void validateFunctionParameterTypesWithMappingArray(Location currentLocation, - SyntaxNodeAnalysisContext ctx, String functionName, SeparatedNodeList args) { + private void validateFunctionParameterTypesWithOptions(Location currentLocation, SyntaxNodeAnalysisContext ctx, + String functionName, SeparatedNodeList args, boolean isRecord) { ExpressionNode expression; SeparatedNodeList fields; String header = null, headersRows = null, customHeaders = null, @@ -312,10 +355,10 @@ private void validateFunctionParameterTypesWithMappingArray(Location currentLoca customHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); isCustomHeaderPresent = true; } - if (fieldName.equals(Constants.UserConfigurations.HEADERS_ORDER)) { + if (isRecord && fieldName.equals(Constants.UserConfigurations.HEADERS_ORDER)) { headersOrder = getTheValueOfTheUserConfigOption(specificFieldNode); } - if (fieldName.equals(Constants.UserConfigurations.OUTPUT_WITH_HEADERS)) { + if (isRecord && fieldName.equals(Constants.UserConfigurations.OUTPUT_WITH_HEADERS)) { outputWithHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); } } @@ -323,14 +366,15 @@ private void validateFunctionParameterTypesWithMappingArray(Location currentLoca } } } - throwErrorsIfIgnoredFieldFoundForRecordOutputs(header, customHeadersIfHeaderAbsent, headersRows, + throwErrorsIfIgnoredFieldFoundForOutputs(header, customHeadersIfHeaderAbsent, headersRows, customHeaders, isCustomHeaderPresent, headersOrder, - outputWithHeaders, ctx, currentLocation, functionName); + outputWithHeaders, ctx, currentLocation, functionName, isRecord); } - private void throwErrorsIfIgnoredFieldFoundForRecordOutputs(String header, String customHeadersIfHeaderAbsent, + private void throwErrorsIfIgnoredFieldFoundForOutputs(String header, String customHeadersIfHeaderAbsent, String headersRows, String customHeaders, boolean isCustomHeaderPresent, String headersOrder, - String outputWithHeaders, SyntaxNodeAnalysisContext ctx, Location currentLocation, String functionName) { + String outputWithHeaders, SyntaxNodeAnalysisContext ctx, Location currentLocation, + String functionName, boolean isRecord) { if (functionName.equals(Constants.PARSE_STRING) && header != null && !header.equals(Constants.FALSE) && customHeadersIfHeaderAbsent != null && !customHeadersIfHeaderAbsent.equals(Constants.BAL_NULL) && !customHeadersIfHeaderAbsent.equals(Constants.NULL)) { @@ -344,12 +388,12 @@ private void throwErrorsIfIgnoredFieldFoundForRecordOutputs(String header, Strin reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.CUSTOM_HEADERS_SHOULD_BE_PROVIDED); } - if (functionName.equals(Constants.TRANSFORM) && headersOrder != null + if (isRecord && functionName.equals(Constants.TRANSFORM) && headersOrder != null && !headersOrder.equals(Constants.BAL_NULL) && !headersOrder.equals(Constants.NULL)) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY); } - if (outputWithHeaders != null) { + if (isRecord && outputWithHeaders != null) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY); } 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 7cb9684..a70b82b 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 @@ -88,6 +88,7 @@ public static Object parse(Reader reader, BTypedesc type, CsvConfig config) throws BError { StateMachine sm = LOCAL_THREAD_STATE_MACHINE.get(); try { + CsvUtils.validateConfigs(config); Object convertedValue = sm.execute(reader, TypeUtils.getReferredType(type.getDescribingType()), config, type); return DataUtils.validateConstraints(convertedValue, type, config.enableConstraintValidation); 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 211ee64..273bb95 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 @@ -67,6 +67,7 @@ private CsvTraversal() { public static Object traverse(BArray csv, CsvConfig config, BTypedesc type) { CsvTree csvTree = tlCsvTree.get(); try { + CsvUtils.validateConfigs(config); Object convertedValue = csvTree.traverseCsv(csv, config, type.getDescribingType()); return DataUtils.validateConstraints(convertedValue, type, config.enableConstraintValidation); } catch (BError e) { 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 f891145..70ff154 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 @@ -378,4 +378,10 @@ public static Locale createLocaleFromString(String localeString) { return new Locale(parts[0]); // Only language } } + + public static void validateConfigs(CsvConfig config) { + if (config.headersRows > 1 && config.customHeaders == null) { + throw DiagnosticLog.error(DiagnosticErrorCode.NO_CUSTOM_HEADER_PROVIDED); + } + } } From 1df716970e9109f6d5e93660f2f2819daa229953 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Fri, 16 Aug 2024 10:13:59 +0530 Subject: [PATCH 141/147] Add examples for api documentation --- ballerina/csv_api.bal | 42 ++++++++++++++++++- .../csvdata/compiler/CompilerPluginTest.java | 6 +-- .../compiler/CsvDataDiagnosticCodes.java | 11 ++--- .../lib/data/csvdata/csv/CsvTraversal.java | 14 +++---- .../lib/data/csvdata/utils/Constants.java | 8 ++-- .../lib/data/csvdata/utils/CsvUtils.java | 9 ---- 6 files changed, 59 insertions(+), 31 deletions(-) diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index b4089e1..292e335 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -17,6 +17,15 @@ import ballerina/jballerina.java; # Converts CSV string to subtype of `record{}[]` or `anydata[][]`. +# ```ballerina +# string csvString = string `id,name +# 1,John +# 3,Jane`; +# record{int id; string name;}[] csv1 = check csv:parseString(csvString); +# [int, string][] csv2 = check csv:parseString(csvString); +# record{|int id;|}[] csv3 = check csv:parseString(csvString); +# record{int id;}[] csv4 = check csv:parseString(csvString, {skipLines: [1]}); +# ``` # # + csvString - Source CSV string value # + options - Options to be used for filtering in the projection @@ -26,6 +35,13 @@ public isolated function parseString(string csvString, ParseOptions options = {} returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Converts byte[] to subtype of `record{}[]` or `anydata[][]`. +# ```ballerina +# byte[] csvBytes = check io:fileReadBytes("example.csv"); +# record{int id; string name;}[] csv1 = check csv:parseBytes(csvBytes); +# [int, string][] csv2 = check csv:parseBytes(csvBytes); +# record{|int id;|}[] csv3 = check csv:parseBytes(csvBytes); +# record{int id;}[] csv4 = check csv:parseBytes(csvBytes, {skipLines: [1]}); +# ``` # # + csvBytes - Source CSV byte array # + options - Options to be used for filtering in the projection @@ -35,7 +51,17 @@ public isolated function parseBytes(byte[] csvBytes, ParseOptions options = {}, returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Converts CSV byte-block-stream to subtype of `record{}[]` or `anydata[][]`. -# +# ```ballerina +# stream csvByteStream = check io:fileReadBlocksAsStream("example.csv"); +# record{int id; string name;}[] csv1 = check csv:parseStream(csvByteStream); +# stream csvByteStream2 = check io:fileReadBlocksAsStream("example.csv"); +# [int, string][] csv2 = check csv:parseStream(csvByteStream2); +# stream csvByteStream3 = check io:fileReadBlocksAsStream("example.csv"); +# record{|int id;|}[] csv3 = check csv:parseStream(csvByteStream3); +# stream csvByteStream4 = check io:fileReadBlocksAsStream("example.csv"); +# record{int id;}[] csv4 = check csv:parseStream(csvByteStream4, {skipLines: [1]}); +# ``` +# # + csvByteStream - Source CSV byte-block-stream # + options - Options to be used for filtering in the projection # + t - Target type @@ -45,6 +71,12 @@ public isolated function parseStream(stream csvByteStream, returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Convert value of type record{}[] to subtype of `record{}[]` or `anydata[][]`. +# ```ballerina +# record{int id; string name;}[] csvRecords = [{id: 1, name: "John"}, {id: 2, name: "Jane"}]; +# [int, string][] csv1 = check csv:transform(csvRecords); +# record{|int id;|}[] csv2 = check csv:transform(csvRecords); +# record{int id;}[] csv3 = check csv:transform(csvRecords, {skipLines: [1]}); +# ``` # # + csvRecords - Source Ballerina record array value # + options - Options to be used for filtering in the projection @@ -55,7 +87,13 @@ public isolated function transform(record{}[] csvRecords, returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; # Convert value of type string array of array to subtype of `record{}[]` or `anydata[][]`. -# +# ```ballerina +# string[][] csvList = [["1", "John"], ["2", "Jane"]]; +# [int, string][] csv1 = check csv:parseList(csvList); +# record{|int id;|}[] csv2 = check csv:parseList(csvList, {customHeaders: ["id", "name"]}); +# record{int id;}[] csv3 = check csv:parseList(csvList, {skipLines: [1], customHeaders: ["id", "name"]}); +# ``` +# # + csvList - Source Ballerina string array of array value # + options - Options to be used for filtering in the projection # + t - Target type 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 ea9a7eb..5c73016 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 @@ -43,12 +43,12 @@ public class CompilerPluginTest { "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."; - static final String IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY = "The option 'outputWithHeaders' will be ignored" + + static final String IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY = "The option 'outputWithHeaders' will be not allowed" + " since the expected type is a subtype record array."; - static final String IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY = "The option 'headersOrder' will be ignored" + + static final String IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY = "The option 'headersOrder' will be not allowed" + " since the expected type is a subtype record array."; static final String IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT = "The option " + - "'customHeadersIfHeadersAbsent' will be ignored since the header is present."; + "'customHeadersIfHeadersAbsent' will be not allowed since the header is present."; static final String CUSTOM_HEADERS_SHOULD_BE_PROVIDED = "customHeaders parameter should be provided since the" + " headerRows larger than 1."; 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 e6137e0..5104c40 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 @@ -34,12 +34,13 @@ public enum CsvDataDiagnosticCodes { "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), - IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'outputWithHeaders' will be ignored since the " + - "expected type is a subtype record array.", ERROR), - IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'headersOrder' will be ignored " + - "since the expected type is a subtype record array.", ERROR), + IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'outputWithHeaders' will " + + "be not allowed since the expected type is a subtype record array.", ERROR), + IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'headersOrder' will " + + "be not allowed since the expected type is a subtype record array.", ERROR), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT("CSV_ERROR_6", - "The option 'customHeadersIfHeadersAbsent' will be ignored since the header is present.", ERROR), + "The option 'customHeadersIfHeadersAbsent' will be not " + + "allowed since the header is present.", ERROR), CUSTOM_HEADERS_SHOULD_BE_PROVIDED("CSV_ERROR_7", "customHeaders parameter should be provided since the headerRows larger than 1.", ERROR); 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 c06fb7d..625ceea 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 @@ -253,8 +253,8 @@ private void traverseCsvWithExpectedType(int sourceArraySize, expectedArrayElementType, isIntersection); break; case TypeTags.UNION_TAG: - traverseCsvWithUnionExpectedType(sourceArraySize, csv, - (UnionType) expectedArrayElementType, type, isIntersection); + traverseCsvWithUnionExpectedType(csv, + (UnionType) expectedArrayElementType, type); break; default: throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); @@ -336,16 +336,14 @@ public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expe } } - public void traverseCsvWithUnionExpectedType(long length, BArray csv, - UnionType expectedArrayType, Type type, boolean isIntersection) { + public void traverseCsvWithUnionExpectedType(BArray csv, + UnionType expectedArrayType, Type type) { for (Type memberType: expectedArrayType.getMemberTypes()) { try { memberType = TypeCreator.createArrayType(TypeUtils.getReferredType(memberType)); - if (CsvUtils.isExpectedTypeIsMap(memberType) || CsvUtils.isExpectedTypeIsArray(memberType)) { - traverseCsv(csv, config, memberType); - return; - } + traverseCsv(csv, config, memberType); + return; } catch (Exception ex) { resetForUnionTypes(); } 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 8b12602..4cd1749 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 @@ -9,7 +9,7 @@ * @since 0.1.0 */ public final class Constants { - public final class ConfigConstants { + public static final class ConfigConstants { public static final BString DELIMITER = StringUtils.fromString("delimiter"); public static final BString TEXT_ENCLOSURE = StringUtils.fromString("textEnclosure"); public static final BString HEADER = StringUtils.fromString("header"); @@ -37,7 +37,7 @@ private ConfigConstants() { } } - public final class Values { + public static final class Values { public static final String NULL = "null"; public static final String BALLERINA_NULL = "()"; @@ -45,7 +45,7 @@ private Values() { } } - public final class LineTerminator { + public static final class LineTerminator { public static final char LF = '\n'; public static final char CR = '\r'; public static final String CRLF = "\r\n"; @@ -54,7 +54,7 @@ private LineTerminator() { } } - public final class EscapeChar { + public static final class EscapeChar { public static final char DOUBLE_QUOTES_CHAR = '"'; public static final char BACKSLASH_CHAR = '\\'; public static final char SLASH_CHAR = '/'; 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 70ff154..917771f 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 @@ -52,15 +52,6 @@ public static boolean isExpectedTypeIsArray(Type expectedType) { }; } - public static boolean isExpectedTypeIsMap(Type expectedType) { - expectedType = TypeUtils.getReferredType(expectedType); - - 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, From 67530ea661ae2a887a6bd621953183fa6b6e5fd6 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 20 Aug 2024 10:13:43 +0530 Subject: [PATCH 142/147] Update csv api doc comments --- ballerina/csv_api.bal | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 292e335..66527eb 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -37,6 +37,7 @@ public isolated function parseString(string csvString, ParseOptions options = {} # Converts byte[] to subtype of `record{}[]` or `anydata[][]`. # ```ballerina # byte[] csvBytes = check io:fileReadBytes("example.csv"); +# # record{int id; string name;}[] csv1 = check csv:parseBytes(csvBytes); # [int, string][] csv2 = check csv:parseBytes(csvBytes); # record{|int id;|}[] csv3 = check csv:parseBytes(csvBytes); @@ -54,10 +55,13 @@ public isolated function parseBytes(byte[] csvBytes, ParseOptions options = {}, # ```ballerina # stream csvByteStream = check io:fileReadBlocksAsStream("example.csv"); # record{int id; string name;}[] csv1 = check csv:parseStream(csvByteStream); +# # stream csvByteStream2 = check io:fileReadBlocksAsStream("example.csv"); # [int, string][] csv2 = check csv:parseStream(csvByteStream2); +# # stream csvByteStream3 = check io:fileReadBlocksAsStream("example.csv"); # record{|int id;|}[] csv3 = check csv:parseStream(csvByteStream3); +# # stream csvByteStream4 = check io:fileReadBlocksAsStream("example.csv"); # record{int id;}[] csv4 = check csv:parseStream(csvByteStream4, {skipLines: [1]}); # ``` From c84fd71f769456769a426de314bf364219c18730 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 20 Aug 2024 13:22:40 +0530 Subject: [PATCH 143/147] Update gradle plugin version --- .gitignore | 2 +- build.gradle | 6 +++++- gradle.properties | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index e8bcae9..38d72e0 100644 --- a/.gitignore +++ b/.gitignore @@ -34,7 +34,7 @@ target bin/ # IDEA Files -.idea2/ +.idea/ *.iml *.ipr *.iws diff --git a/build.gradle b/build.gradle index d020275..44c60de 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ allprojects { } maven { - url = 'https://maven.pkg.github.com/ballerina-platform/ballerina-lang' + url = 'https://maven.pkg.github.com/ballerina-platform/*' credentials { username System.getenv("packageUser") password System.getenv("packagePAT") @@ -63,9 +63,13 @@ subprojects { configurations { ballerinaStdLibs + jbalTools } dependencies { + jbalTools ("org.ballerinalang:jballerina-tools:${ballerinaLangVersion}") { + transitive = false + } /* Standard libraries */ ballerinaStdLibs "io.ballerina.stdlib:file-ballerina:${stdlibFileVersion}" ballerinaStdLibs "io.ballerina.stdlib:io-ballerina:${stdlibIoVersion}" diff --git a/gradle.properties b/gradle.properties index d7c11be..cda8444 100644 --- a/gradle.properties +++ b/gradle.properties @@ -12,7 +12,7 @@ spotbugsVersion=5.0.14 shadowJarPluginVersion=8.1.1 downloadPluginVersion=4.0.4 releasePluginVersion=2.8.0 -ballerinaGradlePluginVersion=2.0.1 +ballerinaGradlePluginVersion=2.2.6 javaJsonPathVersion=2.9.0 javaJsonSmartVersion=2.4.11 javaAccessorsSmartVersion=2.4.7 From 6ab339a2f7440721ee693efb0980175c4bec7eb7 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 3 Sep 2024 10:32:17 +0530 Subject: [PATCH 144/147] Refactor APIs and API docs --- README.md | 4 +- ballerina-tests/csv-commons/test_utils.bal | 2 +- .../tests/parse_list_type_as_list_test.bal | 56 ++--- .../tests/parse_list_type_as_record_test.bal | 84 +++---- .../tests/test_data_values.bal | 14 +- .../tests/parse_record_type_as_list_test.bal | 222 +++++++++--------- .../tests/test_data_values.bal | 26 +- .../tests/parse_string_to_array_test.bal | 4 +- .../tests/test_data_values.bal | 22 +- .../tests/test_data_values.bal | 22 +- .../tests/nill_type_test.bal | 12 +- .../tests/parse_string_compatibality_test.bal | 14 +- .../tests/parse_type_compatibility_test.bal | 26 +- .../tests/test_data_values.bal | 66 +++--- .../tests/escape_character_test.bal | 10 +- .../tests/test_data_values.bal | 2 +- .../tests/test_union_types_with_headers.bal | 56 ++--- .../tests/test_with_intersection_types.bal | 16 +- .../tests/test_with_singleton_test.bal | 6 +- .../tests/test_with_union_types.bal | 192 +++++++-------- .../tests/test_data_values.bal | 48 ++-- .../tests/user_config_projection_tests.bal | 96 ++++---- .../user_config_with_parser_options_test.bal | 70 +++--- .../user-config-tests/tests/user_configs.bal | 46 ++-- ballerina/Package.md | 4 +- ballerina/csv_api.bal | 57 +++-- ballerina/types.bal | 16 +- .../csvdata/compiler/CompilerPluginTest.java | 4 +- .../sample_package_1/main.bal | 28 +-- .../sample_package_10/main.bal | 78 +++--- .../sample_package_11/main.bal | 4 +- .../sample_package_12/main.bal | 78 +++--- .../sample_package_4/main.bal | 12 +- .../sample_package_6/main.bal | 12 +- .../sample_package_7/main.bal | 56 ++--- .../sample_package_8/main.bal | 14 +- .../sample_package_9/main.bal | 26 +- .../lib/data/csvdata/compiler/Constants.java | 6 +- .../compiler/CsvDataDiagnosticCodes.java | 2 +- .../compiler/CsvDataTypeValidator.java | 66 +++--- .../lib/data/csvdata/FromString.java | 4 +- .../lib/data/csvdata/csv/CsvCreator.java | 15 +- .../lib/data/csvdata/csv/CsvParser.java | 50 ++-- .../lib/data/csvdata/csv/CsvTraversal.java | 38 ++- .../lib/data/csvdata/utils/Constants.java | 4 +- .../lib/data/csvdata/utils/CsvConfig.java | 12 +- .../lib/data/csvdata/utils/CsvUtils.java | 73 +++--- .../lib/data/csvdata/utils/DataUtils.java | 6 +- .../csvdata/utils/DiagnosticErrorCode.java | 3 +- .../src/main/resources/csv_error.properties | 29 +-- 50 files changed, 908 insertions(+), 905 deletions(-) diff --git a/README.md b/README.md index 3381745..4236cc1 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ public function main() returns error? { ### Converting external CSV document to a record value -For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. +For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte block stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. ```ballerina import ballerina/data.csv; @@ -118,7 +118,7 @@ type Book record {| |}; public function main() returns error? { - record{}[] csvContent = [{ + record {}[] csvContent = [{ "name": "Clean Code", "author": "Robert C. Martin", "year": 2008, diff --git a/ballerina-tests/csv-commons/test_utils.bal b/ballerina-tests/csv-commons/test_utils.bal index ef482bf..2609cd9 100644 --- a/ballerina-tests/csv-commons/test_utils.bal +++ b/ballerina-tests/csv-commons/test_utils.bal @@ -35,5 +35,5 @@ public function generateErrorMessageForInvalidHeaders(string value, string 'type } public function generateErrorMessageForInvalidCustomHeader(string header) returns string { - return string `Header '${header}' cannot be find in data rows`; + return string `Header '${header}' cannot be found in data rows`; } diff --git a/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal index 6602f30..a094cdf 100644 --- a/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal +++ b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_list_test.bal @@ -450,107 +450,107 @@ function testArrayIndexes() { @test:Config function testParseListsWithOutputHeaders() { - [string, boolean, int][]|csv:Error ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1}); + [string, boolean, int][]|csv:Error ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); test:assertEquals(ct1bt1, [ ["a", true, 1] ]); - [string, boolean, int][]|[anydata...][]|csv:Error ct1bt1_union = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headersRows: 2}); + [string, boolean, int][]|[anydata...][]|csv:Error ct1bt1_union = csv:parseList([["a", "b", "c"], ["a", "b", "c"]], {headerRows: 2}); test:assertTrue(ct1bt1_union is csv:Error); - test:assertEquals((ct1bt1_union).message(), "Custom headers should be provided"); + test:assertEquals((ct1bt1_union).message(), "custom headers should be provided"); - ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1, [ ["a", true, 1] ]); - ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1 = csv:parseList([["a", "true", "1"]], {headersRows: 1}); + ct1bt1 = csv:parseList([["a", "true", "1"]], {headerRows: 1}); test:assertEquals(ct1bt1, []); - (boolean|int|string)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1}); + (boolean|int|string)[][]|csv:Error ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1}); test:assertEquals(ct1bt1_2, [ ["a", true, 1] ]); - ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1_2, [ ["a", true, 1] ]); - ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"]}); + ct1bt1_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"]}); test:assertEquals(ct1bt1_2, [ ["a", true, 1], ["a", true, 1] ]); - [string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true}); + [string, boolean, int][]|csv:Error ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_3, [ ["a", true, 1], ["a", true, 1] ]); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean")); - ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_3 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertTrue(ct1bt1_3 is csv:Error); test:assertEquals((ct1bt1_3).message(), common:generateErrorMessageForInvalidValueForArrayType("h2", "1", "boolean")); - [string, boolean, int|string][]|[anydata...][]|csv:Error ct1bt1_3_with_union = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 21, outputWithHeaders: true}); + [string, boolean, int|string][]|[anydata...][]|csv:Error ct1bt1_3_with_union = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 21, outputWithHeaders: true}); test:assertTrue(ct1bt1_3_with_union is csv:Error); - test:assertEquals((ct1bt1_3_with_union).message(), "Custom headers should be provided"); + test:assertEquals((ct1bt1_3_with_union).message(), "custom headers should be provided"); - string[][]|csv:Error ct1bt1_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true}); + string[][]|csv:Error ct1bt1_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_4, [ ["a", "b", "c"], ["a", "true", "1"] ]); - ct1bt1_4 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_4 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_4, [ ["h1", "h2", "h3"], ["a", "true", "1"], ["a", "true", "1"] ]); - (int|boolean|string)[][]|csv:Error ct1bt1_4_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 1, outputWithHeaders: true}); + (int|boolean|string)[][]|csv:Error ct1bt1_4_2 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 1, outputWithHeaders: true}); test:assertEquals(ct1bt1_4_2, [ ["a", "b", "c"], ["a", true, 1] ]); - string[][]|csv:Error ct1bt1_4_3 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headersRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + string[][]|csv:Error ct1bt1_4_3 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_4_3, [ ["h1", "h2", "h3"], ["a", "true", "1"], ["a", "true", "1"] ]); - (int|boolean|string)[][]|csv:Error ct1bt1_4_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headersRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + (int|boolean|string)[][]|csv:Error ct1bt1_4_4 = csv:parseList([["a", "b", "c"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_4_4, [ ["h1", "h2", "h3"] ]); - [string, boolean|string, int|string][]|csv:Error ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string, boolean|string, int|string][]|csv:Error ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - ct1bt1_5 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_5 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt1_5 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt1_5, [ ["h1", "h2", "h3"], ["a", true, 1], @@ -563,35 +563,35 @@ function testParseListsWithOutputHeaders() { ["1", "a"] ]); - [string, boolean|string, int|string...][]|csv:Error ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string, boolean|string, int|string...][]|csv:Error ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt2_2, [ ["h1", "h2", "h3"], ["a", true, 1] ]); - [string...][]|csv:Error ct1bt2_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string...][]|csv:Error ct1bt2_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt2_3, [ ["h1", "h2", "h3"], ["a", "true", "1"] ]); - ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + ct1bt2_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 0, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt2_2, [ ["h1", "h2", "h3"], ["a", true, 1], ["a", true, 1] ]); - string[2][1]|csv:Error ct1bt6 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headersRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + string[2][1]|csv:Error ct1bt6 = csv:parseList([["a", "b", "c"], ["a", "true", "1"], ["a", "true", "1"], ["a", "true", "1"]], {headerRows: 2, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt6, [ ["h1"], ["a"] ]); - [string, boolean|string, int|string...][1]|csv:Error ct1bt6_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string, boolean|string, int|string...][1]|csv:Error ct1bt6_2 = csv:parseList([["a", "true", "1"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt6_2, [ ["h1", "h2", "h3"] ]); - [string...][1]|csv:Error ct1bt6_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headersRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); + [string...][1]|csv:Error ct1bt6_3 = csv:parseList([["a", "true", "2"], ["a", "true", "1"]], {headerRows: 1, customHeaders: ["h1", "h2", "h3"], outputWithHeaders: true}); test:assertEquals(ct1bt6_3, [ ["h1", "h2", "h3"] ]); diff --git a/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_record_test.bal b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_record_test.bal index f51feb6..79162d7 100644 --- a/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_record_test.bal +++ b/ballerina-tests/parse-list-types-tests/tests/parse_list_type_as_record_test.bal @@ -502,13 +502,13 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType6() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { - record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "c", "b"]}); + record {string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - record{() a; float b; decimal c; boolean d; int e; string f;}[]|csv:Error ct1br6 = csv:parseList( + record {() a; float b; decimal c; boolean d; int e; string f;}[]|csv:Error ct1br6 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br6, [ @@ -516,7 +516,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|decimal c; boolean d; int e; string f;|}[]|csv:Error ct1br7 = csv:parseList( + record {|decimal c; boolean d; int e; string f;|}[]|csv:Error ct1br7 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br7, [ @@ -524,7 +524,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {c: 2.23, d: true, e: 1, f: "a"} ]); - record{decimal c; boolean d; int e; string f;}[]|csv:Error ct1br8 = csv:parseList( + record {decimal c; boolean d; int e; string f;}[]|csv:Error ct1br8 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br8, [ @@ -532,7 +532,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|int|() a; float b; decimal? c; boolean d; int e; string f; string...;|}[]|csv:Error ct1br9 = csv:parseList( + record {|int|() a; float b; decimal? c; boolean d; int e; string f; string...;|}[]|csv:Error ct1br9 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br9, [ @@ -540,7 +540,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: true, e: 1, f: "a"} ]); - record{|int|() a; float b; decimal? c; string|boolean d; int|string e; string f; string...;|}[]|csv:Error ct1br9_2 = csv:parseList( + record {|int|() a; float b; decimal? c; string|boolean d; int|string e; string f; string...;|}[]|csv:Error ct1br9_2 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br9_2, [ @@ -548,7 +548,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { {a: (), b: 0, c: 2.23, d: "true", e: 1, f: "a"} ]); - record{|int|() a; float b; decimal? c; boolean|string d; int|string e; string f; string...;|}[]|csv:Error ct1br9_3 = csv:parseList( + record {|int|() a; float b; decimal? c; boolean|string d; int|string e; string f; string...;|}[]|csv:Error ct1br9_3 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br9_3, [ @@ -559,81 +559,81 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType7() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { - record{string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 0, customHeaders: ["a", "c", "b"]}); + record {string a; boolean b; int c;}[]|csv:Error ct1br4 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 0, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - record{string a; boolean b; int c;}[]|csv:Error ct1br4_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"]}); + record {string a; boolean b; int c;}[]|csv:Error ct1br4_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4_2, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - record{string a; boolean b; int c;}[]|csv:Error ct1br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"]}); + record {string a; boolean b; int c;}[]|csv:Error ct1br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4_3, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - record{string a; boolean b; int c;}[]|csv:Error ct1br4_4 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); + record {string a; boolean b; int c;}[]|csv:Error ct1br4_4 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4_4, [ {a: "a", b: true, c: 1} ]); - record{string a; boolean b; int c;}[]|record{}[]|csv:Error ct1br4_5 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2}); + record {string a; boolean b; int c;}[]|record {}[]|csv:Error ct1br4_5 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2}); test:assertTrue(ct1br4_5 is csv:Error); - test:assertEquals((ct1br4_5).message(), "Custom headers should be provided"); + test:assertEquals((ct1br4_5).message(), "custom headers should be provided"); - record{|string a; boolean b; int...;|}[]|csv:Error ct1br4_4_2 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); + record {|string a; boolean b; int...;|}[]|csv:Error ct1br4_4_2 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct1br4_4_2, [ {a: "a", b: true, c: 1} ]); - record{|string a; boolean b; int...;|}[]|record{}[]|csv:Error ct1br4_5_2 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2}); + record {|string a; boolean b; int...;|}[]|record {}[]|csv:Error ct1br4_5_2 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2}); test:assertTrue(ct1br4_5_2 is csv:Error); - test:assertEquals((ct1br4_5).message(), "Custom headers should be provided"); + test:assertEquals((ct1br4_5).message(), "custom headers should be provided"); - map[]|csv:Error ct2br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1, customHeaders: ["a", "c", "b"]}); + map[]|csv:Error ct2br4_3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_3, [ {a: "a", b: true, c: 1}, {a: "a", b: true, c: 1} ]); - map[]|csv:Error ct2br4_3_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 3, customHeaders: ["a", "c", "b"]}); + map[]|csv:Error ct2br4_3_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 3, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_3_2, []); map[]|csv:Error ct2br4_4 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_4, [ {a: "a", b: true, c: 1} ]); map[]|csv:Error ct2br4_5 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, customHeaders: ["a", "c", "b"]}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, customHeaders: ["a", "c", "b"]}); test:assertEquals(ct2br4_5, [ {a: "a", b: "true", c: "1"}, {a: "a", b: "true", c: "1"} ]); - map[]|record{}[]|csv:Error ct2br4_7 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 4, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); + map[]|record {}[]|csv:Error ct2br4_7 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 4, customHeaders: ["a", "c", "b"], outputWithHeaders: true}); test:assertEquals(ct2br4_7, []); - map[]|record{}[]|csv:Error ct2br4_6 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 2, outputWithHeaders: true}); + map[]|record {}[]|csv:Error ct2br4_6 = csv:parseList( + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 2, outputWithHeaders: true}); test:assertTrue(ct2br4_6 is csv:Error); - test:assertEquals((ct1br4_5).message(), "Custom headers should be provided"); + test:assertEquals((ct1br4_5).message(), "custom headers should be provided"); map[]|csv:Error ct2br4_8 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1}); test:assertEquals(ct2br4_8, [ {"a": "a", "1": "1", "true": "true"}, {"a": "a", "1": "1", "true": "true"}, @@ -641,7 +641,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_8_2 = csv:parseList( - [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headersRows: 1}); + [["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"], ["a", "1", "true"]], {headerRows: 1}); test:assertEquals(ct2br4_8_2, [ {"a": "a", "1": "1", "true": "true"}, {"a": "a", "1": "1", "true": "true"}, @@ -649,7 +649,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_9 = csv:parseList( - [["a", "c", "b"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1}); + [["a", "c", "b"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1}); test:assertEquals(ct2br4_9, [ {a: "a", b: "true", c: "2"}, {a: "a", b: "true", c: "3"}, @@ -658,7 +658,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_10 = csv:parseList( - [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1}); + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1}); test:assertEquals(ct2br4_10, [ {a: "a", c: true, b: 2}, {a: "a", c: true, b: 3}, @@ -667,7 +667,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { ]); map[]|csv:Error ct2br4_10_2 = csv:parseList( - [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1}); + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1}); test:assertEquals(ct2br4_10_2, [ {a: "a", c: true, b: 2}, {a: "a", c: true, b: 3}, @@ -675,8 +675,8 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { {a: "a", c: true, b: 5} ]); - map[]|record{}[]|csv:Error ct2br4_10_3 = csv:parseList( - [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headersRows: 1, customHeaders: ["c", "d", "e"], outputWithHeaders: false}); + map[]|record {}[]|csv:Error ct2br4_10_3 = csv:parseList( + [["a", "b", "c"], ["a", "2", "true"], ["a", "3", "true"], ["a", "4", "true"], ["a", "5", "true"]], {headerRows: 1, customHeaders: ["c", "d", "e"], outputWithHeaders: false}); test:assertEquals(ct2br4_10_3, [ {c: "a", e: true, d: 2}, {c: "a", e: true, d: 3}, @@ -687,7 +687,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedTypeWithHeaders() { @test:Config function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { - record{|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseList( + record {|decimal c; boolean|string d; int e; string f; string...;|}[]|csv:Error ct1br10 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br10, [ @@ -695,7 +695,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {a: "()", b: "0", c: 2.23, d: true, e: 1, f: "a"} ]); - record{|decimal? c; boolean d; int? e; string f; ()...;|}[]|csv:Error ct1br11 = csv:parseList( + record {|decimal? c; boolean d; int? e; string f; ()...;|}[]|csv:Error ct1br11 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br11, [ @@ -703,7 +703,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {a: (), c: 2.23, d: true, e: 1, f: "a"} ]); - record{|()...;|}[]|csv:Error ct1br12 = csv:parseList( + record {|()...;|}[]|csv:Error ct1br12 = csv:parseList( [["a", "1", "true", "0", "2.23", "null"], ["a", "1", "true", "2.23", "0", "()"]], {customHeaders: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br12, [ @@ -711,7 +711,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {a: ()} ]); - record{|string?...;|}[]|csv:Error ct1br13 = csv:parseList( + record {|string?...;|}[]|csv:Error ct1br13 = csv:parseList( [["a", "1"], ["a", "1"]], {customHeaders: ["f", "e"]}); test:assertEquals(ct1br13, [ @@ -719,7 +719,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {e: "1", f: "a"} ]); - record{|boolean...;|}[]|csv:Error ct1br14 = csv:parseList( + record {|boolean...;|}[]|csv:Error ct1br14 = csv:parseList( [["2.23", "null"], ["7", "()"]], {customHeaders: ["b", "a"]}); test:assertEquals(ct1br14, [ @@ -736,7 +736,7 @@ function testFromCsvWithTypeForTupleAndRecordAsExpectedType8() { {e: 2, f: ()} ]); - record{|boolean...;|}[]|csv:Error ct1br16 = csv:parseList( + record {|boolean...;|}[]|csv:Error ct1br16 = csv:parseList( [["2.23", "null"], ["7", "()"]], {customHeaders: ["b", "a"]}); test:assertEquals(ct1br16, [ diff --git a/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal index 3a50795..b2bc041 100644 --- a/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-list-types-tests/tests/test_data_values.bal @@ -14,11 +14,11 @@ // specific language governing permissions and limitations // under the License. -string s1 = "string"; -string s2 = ""; -string:Char s3 = "a"; +final string s1 = "string"; +final string s2 = ""; +final string:Char s3 = "a"; -[string, string] st1 = [s1, s2]; -[string, string, string, string] st2 = [s1, s2, s3, s2]; -[string...] st3 = [s1, s2]; -[string, string, string...] st4 = [s1, s2, s3, s2]; +final [string, string] st1 = [s1, s2]; +final [string, string, string, string] st2 = [s1, s2, s3, s2]; +final [string...] st3 = [s1, s2]; +final [string, string, string...] st4 = [s1, s2, s3, s2]; diff --git a/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal b/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal index 23a4317..51a1840 100644 --- a/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal +++ b/ballerina-tests/parse-record-types-tests/tests/parse_record_type_as_list_test.bal @@ -20,105 +20,105 @@ import ballerina/test; @test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType() { - BooleanArrayArray|csv:Error bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm1ba = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, BooleanArrayArray); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b2", "b1"]}, BooleanArrayArray); + bm1ba = csv:transform([bm1, bm1], {headerOrder: ["b2", "b1"]}, BooleanArrayArray); test:assertEquals(bm1ba, [ [false, true], [false, true] ]); - BooleanArrayArray|csv:Error bm2ba = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm2ba = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanArrayArray); test:assertTrue(bm2ba is csv:Error); test:assertEquals((bm2ba).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanArrayArray|csv:Error bm3ba = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm3ba = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanArrayArray); test:assertTrue(bm3ba is csv:Error); test:assertEquals((bm3ba).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanArrayArray|csv:Error bm4ba = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm4ba = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, BooleanArrayArray); test:assertTrue(bm4ba is csv:Error); test:assertEquals((bm4ba).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanArrayArray|csv:Error bm5ba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanArrayArray); + BooleanArrayArray|csv:Error bm5ba = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, BooleanArrayArray); test:assertTrue(bm5ba is csv:Error); test:assertEquals((bm5ba).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - NillableBooleanArrayArray|csv:Error bm1nba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm1nba = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableBooleanArrayArray); test:assertEquals(bm1nba, [ [true, false], [true, false] ]); - NillableBooleanArrayArray|csv:Error bm2nba = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm2nba = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanArrayArray); test:assertEquals(bm2nba, [ [true, false, null, null, null], [true, false, null, null, null] ]); - NillableBooleanArrayArray|csv:Error bm3nba = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm3nba = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanArrayArray); test:assertTrue(bm3nba is csv:Error); test:assertEquals((bm3nba).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanArrayArray|csv:Error bm4nba = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm4nba = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableBooleanArrayArray); test:assertEquals(bm4nba, [ [(), ()], [(), ()] ]); - NillableBooleanArrayArray|csv:Error bm5nba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanArrayArray); + NillableBooleanArrayArray|csv:Error bm5nba = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanArrayArray); test:assertEquals(bm5nba, [ [true, false, (), true], [true, false, (), true] ]); - bm5nba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b3", "b2", "b4"]}, NillableBooleanArrayArray); + bm5nba = csv:transform([bm5, bm5], {headerOrder: ["b1", "b3", "b2", "b4"]}, NillableBooleanArrayArray); test:assertEquals(bm5nba, [ [true, (), false, true], [true, (), false, true] ]); - bm5nba = csv:transform([bm5, bm5], {headersOrder: ["b4", "b3", "b2", "b1"]}, NillableBooleanArrayArray); + bm5nba = csv:transform([bm5, bm5], {headerOrder: ["b4", "b3", "b2", "b1"]}, NillableBooleanArrayArray); test:assertEquals(bm5nba, [ [true, (), false, true], [true, (), false, true] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm1niouba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm1niouba = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm1niouba, [ [true, false], [true, false] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm2niouba = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm2niouba = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm2niouba, [ [true, false, null, null, null], [true, false, null, null, null] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm3niouba = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm3niouba = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm3niouba, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm4niouba = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm4niouba = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm4niouba, [ [(), ()], [(), ()] ]); - NillableIntOrUnionBooleanArrayArray|csv:Error bm5niouba = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableIntOrUnionBooleanArrayArray); + NillableIntOrUnionBooleanArrayArray|csv:Error bm5niouba = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableIntOrUnionBooleanArrayArray); test:assertEquals(bm5niouba, [ [true, false, (), true], [true, false, (), true] ]); - JsonArray1Array|csv:Error bm1ja = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, JsonArray1Array); + JsonArray1Array|csv:Error bm1ja = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, JsonArray1Array); test:assertEquals(bm1ja, [ [true, false], [true, false] @@ -127,261 +127,261 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType() { @test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType2() { - JsonArray1Array|csv:Error bm2ja = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, JsonArray1Array); + JsonArray1Array|csv:Error bm2ja = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, JsonArray1Array); test:assertEquals(bm2ja, [ [true, false, null, null, null], [true, false, null, null, null] ]); - JsonArray1Array|csv:Error bm3ja = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, JsonArray1Array); + JsonArray1Array|csv:Error bm3ja = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, JsonArray1Array); test:assertEquals(bm3ja, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - JsonArray1Array|csv:Error bm4ja = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, JsonArray1Array); + JsonArray1Array|csv:Error bm4ja = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, JsonArray1Array); test:assertEquals(bm4ja, [ [(), ()], [(), ()] ]); - JsonArray1Array|csv:Error bm5ja = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, JsonArray1Array); + JsonArray1Array|csv:Error bm5ja = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, JsonArray1Array); test:assertEquals(bm5ja, [ [true, false, (), true], [true, false, (), true] ]); - AnydataArray1Array|csv:Error bm1anyda = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm1anyda = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, AnydataArray1Array); test:assertEquals(bm1anyda, [ [true, false], [true, false] ]); - AnydataArray1Array|csv:Error bm2anyda = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm2anyda = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, AnydataArray1Array); test:assertEquals(bm2anyda, [ [true, false, null, null, null], [true, false, null, null, null] ]); - AnydataArray1Array|csv:Error bm3anyda = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm3anyda = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, AnydataArray1Array); test:assertEquals(bm3anyda, [ [true, false, null, false, 1], [true, false, null, false, 1] ]); - AnydataArray1Array|csv:Error bm4anyda = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm4anyda = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, AnydataArray1Array); test:assertEquals(bm4anyda, [ [(), ()], [(), ()] ]); - AnydataArray1Array|csv:Error bm5anyda = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, AnydataArray1Array); + AnydataArray1Array|csv:Error bm5anyda = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, AnydataArray1Array); test:assertEquals(bm5anyda, [ [true, false, (), true], [true, false, (), true] ]); - StringArray1Array|csv:Error bm1sa = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, StringArray1Array); + StringArray1Array|csv:Error bm1sa = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, StringArray1Array); test:assertTrue(bm1sa is csv:Error); test:assertEquals((bm1sa).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|csv:Error bm2sa = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, StringArray1Array); + StringArray1Array|csv:Error bm2sa = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, StringArray1Array); test:assertTrue(bm2sa is csv:Error); test:assertEquals((bm2sa).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|csv:Error bm3sa = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, StringArray1Array); + StringArray1Array|csv:Error bm3sa = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, StringArray1Array); test:assertTrue(bm3sa is csv:Error); test:assertEquals((bm3sa).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringArray1Array|csv:Error bm4sa = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, StringArray1Array); + StringArray1Array|csv:Error bm4sa = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, StringArray1Array); test:assertTrue(bm4sa is csv:Error); test:assertEquals((bm4sa).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - StringArray1Array|csv:Error bm5sa = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, StringArray1Array); + StringArray1Array|csv:Error bm5sa = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, StringArray1Array); test:assertTrue(bm5sa is csv:Error); test:assertEquals((bm5sa).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } @test:Config function testFromCsvWithTypeForMapAndTupleAsExpectedType() { - BooleanTuple1Array|csv:Error bm1bt = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm1bt = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, BooleanTuple1Array); test:assertEquals(bm1bt, [ [true, false, false, false], [true, false, false, false] ]); - BooleanTuple1Array|csv:Error bm2bt = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm2bt = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple1Array); test:assertTrue(bm2bt is csv:Error); test:assertEquals((bm2bt).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple1Array|csv:Error bm3bt = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm3bt = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple1Array); test:assertTrue(bm3bt is csv:Error); test:assertEquals((bm3bt).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple1Array|csv:Error bm4bt = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm4bt = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, BooleanTuple1Array); test:assertTrue(bm4bt is csv:Error); test:assertEquals((bm4bt).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple1Array|csv:Error bm5bt = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple1Array); + BooleanTuple1Array|csv:Error bm5bt = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple1Array); test:assertTrue(bm5bt is csv:Error); test:assertEquals((bm5bt).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple2Array|csv:Error bm1b2t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm1b2t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, BooleanTuple2Array); test:assertEquals(bm1b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error bm2b2t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm2b2t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple2Array); test:assertEquals(bm2b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error bm3b2t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm3b2t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple2Array); test:assertEquals(bm3b2t, [ [true, false], [true, false] ]); - BooleanTuple2Array|csv:Error bm4b2t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm4b2t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, BooleanTuple2Array); test:assertTrue(bm4b2t is csv:Error); test:assertEquals((bm4b2t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple2Array|csv:Error bm5b2t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple2Array); + BooleanTuple2Array|csv:Error bm5b2t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple2Array); test:assertEquals(bm5b2t, [ [true, false], [true, false] ]); - BooleanTuple3Array|csv:Error bm1b3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm1b3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, BooleanTuple3Array); test:assertEquals(bm1b3t, [ [true, false], [true, false] ]); - BooleanTuple3Array|csv:Error bm2b3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm2b3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple3Array); test:assertTrue(bm2b3t is csv:Error); test:assertEquals((bm2b3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple3Array|csv:Error bm3b3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm3b3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple3Array); test:assertTrue(bm3b3t is csv:Error); test:assertEquals((bm3b3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple3Array|csv:Error bm4b3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm4b3t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, BooleanTuple3Array); test:assertTrue(bm4b3t is csv:Error); test:assertEquals((bm4b3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple3Array|csv:Error bm5b3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple3Array); + BooleanTuple3Array|csv:Error bm5b3t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple3Array); test:assertTrue(bm5b3t is csv:Error); test:assertEquals((bm5b3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple4Array|csv:Error bm1b4t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm1b4t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, BooleanTuple4Array); test:assertEquals(bm1b4t, [ [true, false], [true, false] ]); - BooleanTuple4Array|csv:Error bm2b4t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm2b4t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, BooleanTuple4Array); test:assertTrue(bm2b4t is csv:Error); test:assertEquals((bm2b4t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); } @test:Config function testFromCsvWithTypeForMapAndTupleAsExpectedType2() { - BooleanTuple4Array|csv:Error bm3b4t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm3b4t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, BooleanTuple4Array); test:assertTrue(bm3b4t is csv:Error); test:assertEquals((bm3b4t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - BooleanTuple4Array|csv:Error bm4b4t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm4b4t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, BooleanTuple4Array); test:assertTrue(bm4b4t is csv:Error); test:assertEquals((bm4b4t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "boolean")); - BooleanTuple4Array|csv:Error bm5b4t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple4Array); + BooleanTuple4Array|csv:Error bm5b4t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, BooleanTuple4Array); test:assertTrue(bm5b4t is csv:Error); test:assertEquals((bm5b4t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "2", "boolean")); - NillableBooleanTuple5Array|csv:Error bm1nbt = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm1nbt = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableBooleanTuple5Array); test:assertEquals(bm1nbt, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple5Array|csv:Error bm2nbt = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm2nbt = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple5Array); test:assertEquals(bm2nbt, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple5Array|csv:Error bm3nbt = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm3nbt = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple5Array); test:assertTrue(bm3nbt is csv:Error); test:assertEquals((bm3nbt).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple5Array|csv:Error bm4nbt = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm4nbt = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableBooleanTuple5Array); test:assertEquals(bm4nbt, [ [(), (), (), (), ()], [(), (), (), (), ()] ]); - NillableBooleanTuple5Array|csv:Error bm5nbt = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple5Array); + NillableBooleanTuple5Array|csv:Error bm5nbt = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple5Array); test:assertEquals(bm5nbt, [ [true, false, (), true, ()], [true, false, (), true, ()] ]); - NillableBooleanTuple6Array|csv:Error bm1nb6t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm1nb6t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableBooleanTuple6Array); test:assertEquals(bm1nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error bm2nb6t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm2nb6t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple6Array); test:assertEquals(bm2nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error bm3nb6t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm3nb6t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple6Array); test:assertEquals(bm3nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple6Array|csv:Error bm4nb6t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm4nb6t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableBooleanTuple6Array); test:assertEquals(bm4nb6t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple6Array|csv:Error bm5nb6t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple6Array); + NillableBooleanTuple6Array|csv:Error bm5nb6t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple6Array); test:assertEquals(bm5nb6t, [ [true, false], [true, false] ]); - NillableBooleanTuple7Array|csv:Error bm1nb7t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm1nb7t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableBooleanTuple7Array); test:assertEquals(bm1nb7t, [ [true, false], [true, false] ]); - NillableBooleanTuple7Array|csv:Error bm2nb7t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm2nb7t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple7Array); test:assertEquals(bm2nb7t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple7Array|csv:Error bm3nb7t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm3nb7t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple7Array); test:assertTrue(bm3nb7t is csv:Error); test:assertEquals((bm3nb7t).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple7Array|csv:Error bm4nb7t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm4nb7t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableBooleanTuple7Array); test:assertEquals(bm4nb7t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple7Array|csv:Error bm5nb7t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple7Array); + NillableBooleanTuple7Array|csv:Error bm5nb7t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple7Array); test:assertEquals(bm5nb7t, [ [true, false, (), true], [true, false, (), true] @@ -390,83 +390,83 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType2() { @test:Config function testFromCsvWithTypeForMapAndTupleAsExpectedType3() { - NillableBooleanTuple8Array|csv:Error bm1nb8t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm1nb8t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableBooleanTuple8Array); test:assertEquals(bm1nb8t, [ [true, false], [true, false] ]); - NillableBooleanTuple8Array|csv:Error bm2nb8t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm2nb8t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableBooleanTuple8Array); test:assertEquals(bm2nb8t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableBooleanTuple8Array|csv:Error bm3nb8t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm3nb8t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableBooleanTuple8Array); test:assertTrue(bm3nb8t is csv:Error); test:assertEquals((bm3nb8t).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "4", "boolean?")); - NillableBooleanTuple8Array|csv:Error bm4nb8t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm4nb8t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableBooleanTuple8Array); test:assertEquals(bm4nb8t, [ [(), ()], [(), ()] ]); - NillableBooleanTuple8Array|csv:Error bm5nb8t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple8Array); + NillableBooleanTuple8Array|csv:Error bm5nb8t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableBooleanTuple8Array); test:assertEquals(bm5nb8t, [ [true, false, (), true], [true, false, (), true] ]); - NillableIntBooleanTuple9Array|csv:Error bm1nb9t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm1nb9t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm1nb9t, [ [true, false], [true, false] ]); - NillableIntBooleanTuple9Array|csv:Error bm2nb9t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm2nb9t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm2nb9t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - NillableIntBooleanTuple9Array|csv:Error bm3nb9t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm3nb9t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm3nb9t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - NillableIntBooleanTuple9Array|csv:Error bm4nb9t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm4nb9t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm4nb9t, [ [(), ()], [(), ()] ]); - NillableIntBooleanTuple9Array|csv:Error bm5nb9t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NillableIntBooleanTuple9Array); + NillableIntBooleanTuple9Array|csv:Error bm5nb9t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NillableIntBooleanTuple9Array); test:assertEquals(bm5nb9t, [ [true, false, (), true], [true, false, (), true] ]); - NilTuple3Array|csv:Error bm1n3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, NilTuple3Array); + NilTuple3Array|csv:Error bm1n3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, NilTuple3Array); test:assertTrue(bm1n3t is csv:Error); test:assertEquals((bm1n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|csv:Error bm2n3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, NilTuple3Array); + NilTuple3Array|csv:Error bm2n3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, NilTuple3Array); test:assertTrue(bm2n3t is csv:Error); test:assertEquals((bm2n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|csv:Error bm3n3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, NilTuple3Array); + NilTuple3Array|csv:Error bm3n3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, NilTuple3Array); test:assertTrue(bm3n3t is csv:Error); test:assertEquals((bm3n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); - NilTuple3Array|csv:Error bm4n3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, NilTuple3Array); + NilTuple3Array|csv:Error bm4n3t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, NilTuple3Array); test:assertEquals(bm4n3t, [ [(), ()], [(), ()] ]); - NilTuple3Array|csv:Error bm5n3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, NilTuple3Array); + NilTuple3Array|csv:Error bm5n3t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, NilTuple3Array); test:assertTrue(bm5n3t is csv:Error); test:assertEquals((bm5n3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "()")); } @@ -474,83 +474,83 @@ function testFromCsvWithTypeForMapAndTupleAsExpectedType3() { @test:Config function testFromCsvWithTypeForMapAndArrayAsExpectedType3() { - AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"], outputWithHeaders: false}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"], outputWithHeaders: false}, AnydataTuple3Array); test:assertEquals(bm1anyd3t, [ [true, false], [true, false] ]); - AnydataTuple3Array|csv:Error bm2anyd3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm2anyd3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, AnydataTuple3Array); test:assertEquals(bm2anyd3t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - AnydataTuple3Array|csv:Error bm3anyd3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm3anyd3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, AnydataTuple3Array); test:assertEquals(bm3anyd3t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - AnydataTuple3Array|csv:Error bm4anyd3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"], outputWithHeaders: false}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm4anyd3t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"], outputWithHeaders: false}, AnydataTuple3Array); test:assertEquals(bm4anyd3t, [ [(), ()], [(), ()] ]); - AnydataTuple3Array|csv:Error bm5anyd3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, AnydataTuple3Array); + AnydataTuple3Array|csv:Error bm5anyd3t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, AnydataTuple3Array); test:assertEquals(bm5anyd3t, [ [true, false, (), true], [true, false, (), true] ]); - JsonTuple3Array|csv:Error bm1j3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm1j3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, JsonTuple3Array); test:assertEquals(bm1j3t, [ [true, false], [true, false] ]); - JsonTuple3Array|csv:Error bm2j3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm2j3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, JsonTuple3Array); test:assertEquals(bm2j3t, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - JsonTuple3Array|csv:Error bm3j3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm3j3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, JsonTuple3Array); test:assertEquals(bm3j3t, [ [true, false, (), false, 1], [true, false, (), false, 1] ]); - JsonTuple3Array|csv:Error bm4j3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm4j3t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, JsonTuple3Array); test:assertEquals(bm4j3t, [ [(), ()], [(), ()] ]); - JsonTuple3Array|csv:Error bm5j3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, JsonTuple3Array); + JsonTuple3Array|csv:Error bm5j3t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, JsonTuple3Array); test:assertEquals(bm5j3t, [ [true, false, (), true], [true, false, (), true] ]); - StringTuple3Array|csv:Error bm1s3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}, StringTuple3Array); + StringTuple3Array|csv:Error bm1s3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}, StringTuple3Array); test:assertTrue(bm1s3t is csv:Error); test:assertEquals((bm1s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|csv:Error bm2s3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"]}, StringTuple3Array); + StringTuple3Array|csv:Error bm2s3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"]}, StringTuple3Array); test:assertTrue(bm2s3t is csv:Error); test:assertEquals((bm2s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|csv:Error bm3s3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"]}, StringTuple3Array); + StringTuple3Array|csv:Error bm3s3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"]}, StringTuple3Array); test:assertTrue(bm3s3t is csv:Error); test:assertEquals((bm3s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); - StringTuple3Array|csv:Error bm4s3t = csv:transform([bm4, bm4], {headersOrder: ["n1", "n3"]}, StringTuple3Array); + StringTuple3Array|csv:Error bm4s3t = csv:transform([bm4, bm4], {headerOrder: ["n1", "n3"]}, StringTuple3Array); test:assertTrue(bm4s3t is csv:Error); test:assertEquals((bm4s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("null", "0", "string")); - StringTuple3Array|csv:Error bm5s3t = csv:transform([bm5, bm5], {headersOrder: ["b1", "b2", "b3", "b4"]}, StringTuple3Array); + StringTuple3Array|csv:Error bm5s3t = csv:transform([bm5, bm5], {headerOrder: ["b1", "b2", "b3", "b4"]}, StringTuple3Array); test:assertTrue(bm5s3t is csv:Error); test:assertEquals((bm5s3t).message(), common:generateErrorMessageForInvalidValueForArrayType("true", "0", "string")); } @@ -559,7 +559,7 @@ function testFromCsvWithTypeForMapAndArrayAsExpectedType3() { function testArrayIndexes() { map[] csv = [{a: 1, b: 2}, {a: 3, b: 4}, {a: 5, b: 6}, {a: 7, b: 8}]; - int[][2]|csv:Error rec3 = csv:transform(csv, {headersOrder: ["a", "b"]}); + int[][2]|csv:Error rec3 = csv:transform(csv, {headerOrder: ["a", "b"]}); test:assertEquals(rec3, [ [1, 2], [3, 4], @@ -567,13 +567,13 @@ function testArrayIndexes() { [7, 8] ]); - [int...][2]|csv:Error rec3_3 = csv:transform(csv, {headersOrder: ["a", "b"], skipLines: [1]}); + [int...][2]|csv:Error rec3_3 = csv:transform(csv, {headerOrder: ["a", "b"], skipLines: [1]}); test:assertEquals(rec3_3, [ [3, 4], [5, 6] ]); - int[1][2]|csv:Error rec4 = csv:transform(csv, {headersOrder: ["a", "b"], skipLines: [2]}); + int[1][2]|csv:Error rec4 = csv:transform(csv, {headerOrder: ["a", "b"], skipLines: [2]}); test:assertEquals(rec4, [ [1, 2] ]); @@ -581,58 +581,58 @@ function testArrayIndexes() { @test:Config function testParseRecordsAsListsWithHeaderOutput() { - AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"], outputWithHeaders: true}); + AnydataTuple3Array|csv:Error bm1anyd3t = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"], outputWithHeaders: true}); test:assertEquals(bm1anyd3t, [ ["b1", "b2"], [true, false], [true, false] ]); - AnydataTuple3Array|csv:Error bm2anyd3t = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: true}); + AnydataTuple3Array|csv:Error bm2anyd3t = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: true}); test:assertEquals(bm2anyd3t, [ ["b1", "b2", "b3", "n1", "n3"], [true, false, (), (), ()], [true, false, (), (), ()] ]); - AnydataTuple3Array|csv:Error bm3anyd3t = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"], outputWithHeaders: true}); + AnydataTuple3Array|csv:Error bm3anyd3t = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"], outputWithHeaders: true}); test:assertEquals(bm3anyd3t, [ ["b1", "b2", "b3", "b4", "i1"], [true, false, (), false, 1], [true, false, (), false, 1] ]); - anydata[][]|csv:Error bm1anyd3t_2 = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"], outputWithHeaders: true}); + anydata[][]|csv:Error bm1anyd3t_2 = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"], outputWithHeaders: true}); test:assertEquals(bm1anyd3t_2, [ ["b1", "b2"], [true, false], [true, false] ]); - anydata[][]|csv:Error bm2anyd3t_2 = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: true}); + anydata[][]|csv:Error bm2anyd3t_2 = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: true}); test:assertEquals(bm2anyd3t_2, [ ["b1", "b2", "b3", "n1", "n3"], [true, false, (), (), ()], [true, false, (), (), ()] ]); - anydata[2][3]|csv:Error bm3anyd3t_2 = csv:transform([bm3, bm3], {headersOrder: ["b1", "b2", "b3", "b4", "i1"], outputWithHeaders: true}); + anydata[2][3]|csv:Error bm3anyd3t_2 = csv:transform([bm3, bm3], {headerOrder: ["b1", "b2", "b3", "b4", "i1"], outputWithHeaders: true}); test:assertEquals(bm3anyd3t_2, [ ["b1", "b2", "b3"], [true, false, ()] ]); - anydata[][]|csv:Error bm2anyd3t_3 = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: false}); + anydata[][]|csv:Error bm2anyd3t_3 = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n1", "n3"], outputWithHeaders: false}); test:assertEquals(bm2anyd3t_3, [ [true, false, (), (), ()], [true, false, (), (), ()] ]); - anydata[][]|csv:Error bm2anyd3t_4 = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n2", "n3"], outputWithHeaders: false}); + anydata[][]|csv:Error bm2anyd3t_4 = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n2", "n3"], outputWithHeaders: false}); test:assertTrue(bm2anyd3t_4 is csv:Error); test:assertEquals(( bm2anyd3t_4).message(), "CSV data rows with varying headers are not yet supported"); - bm2anyd3t_4 = csv:transform([bm2, bm2], {headersOrder: ["b1", "b2", "b3", "n2", "n3"], outputWithHeaders: true}); + bm2anyd3t_4 = csv:transform([bm2, bm2], {headerOrder: ["b1", "b2", "b3", "n2", "n3"], outputWithHeaders: true}); test:assertTrue(bm2anyd3t_4 is csv:Error); test:assertEquals(( bm2anyd3t_4).message(), "CSV data rows with varying headers are not yet supported"); } @@ -667,7 +667,7 @@ function testsRecordsOutputWithHeadrs() { test:assertTrue(bm3anyd3t_3 is csv:Error); test:assertEquals(( bm3anyd3t_3).message(), "CSV data rows with varying headers are not yet supported"); - record{}[]|csv:Error bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"a": 3, "b": 4}]); + record {}[]|csv:Error bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"a": 3, "b": 4}]); test:assertEquals(bm3anyd3t_4, [{"a": 1, "b": 2}, {"a": 3, "b": 4}]); bm3anyd3t_4 = csv:transform([{"a": 1, "b": 2}, {"c": 3, "d": 4}]); diff --git a/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal index 08845c7..547a3cb 100644 --- a/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-record-types-tests/tests/test_data_values.bal @@ -14,18 +14,18 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean? b3 = (); -boolean|int b4 = false; +final boolean b1 = true; +final false b2 = false; +final boolean? b3 = (); +final boolean|int b4 = false; -() n1 = (); -int? n2 = (); -() n3 = null; +final () n1 = (); +final int? n2 = (); +final () n3 = null; -int i1 = 1; -map bm1 = {b1, b2}; -map bm2 = {b1, b2, b3, n1, n3}; -map bm3 = {b1, b2, b3, b4, i1}; -map<()> bm4 = {n1, n3}; -map bm5 = {b1, b2, b3, b4:true}; +final int i1 = 1; +final map bm1 = {b1, b2}; +final map bm2 = {b1, b2, b3, n1, n3}; +final map bm3 = {b1, b2, b3, b4, i1}; +final map<()> bm4 = {n1, n3}; +final map bm5 = {b1, b2, b3, b4:true}; diff --git a/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal b/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal index e764c8e..10e3859 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/parse_string_to_array_test.bal @@ -340,7 +340,7 @@ function testArrayIndexes() { 5, 6, 7 7, 8, 9`; - record{}[2]|csv:Error rec = csv:parseString(csv); + record {}[2]|csv:Error rec = csv:parseString(csv); test:assertEquals(rec, [ {a: 1, b: 2}, {a: 3, b: 4} @@ -445,7 +445,7 @@ function testParseStringArrayAsExpectedTypeWithOutputHeaders() { string[][]|csv:Error cv1baa_5 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true, header: 2}); test:assertTrue(cv1baa_5 is csv:Error); - test:assertEquals((cv1baa_5).message(), "Duplicate header found: 'true'"); + test:assertEquals((cv1baa_5).message(), "duplicate header found: 'true'"); string[][]|csv:Error cv1baa_6 = csv:parseString(csvStringWithBooleanValues8, {outputWithHeaders: false, header: 2}); test:assertEquals(cv1baa_6, [ diff --git a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal index e4d152b..b39e526 100644 --- a/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-string-array-types-tests/tests/test_data_values.bal @@ -14,21 +14,21 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean|int b4 = false; +final boolean b1 = true; +final false b2 = false; +final boolean|int b4 = false; -string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 true,false,true,false true,false, true,false true,false,true,false `; -string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 +final string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 true,false, true,false,true true,false, true,false,true`; -string csvStringWithBooleanValues3 = string `b1,b2,b3 +final string csvStringWithBooleanValues3 = string `b1,b2,b3 ${" "}${"\t"} true, false,true ${" "} @@ -39,29 +39,29 @@ true, true,FALSE `; -string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 true,(), (),false true,(), null,false `; -string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 true,false,true,2 true,false,true,3 `; -string csvStringWithBooleanValues6 = string `b2,b3 +final string csvStringWithBooleanValues6 = string `b2,b3 (),() `; -string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 ${b1},${b2},(),${b4} `; -string csvStringWithBooleanValues8 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues8 = string `b1,b2,b3,b4 true,false,true1,false1 true,false, true1,false1 true,false,true1,false1 diff --git a/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal b/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal index 80cea06..db0814f 100644 --- a/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal +++ b/ballerina-tests/parse-string-record-types-tests/tests/test_data_values.bal @@ -14,22 +14,22 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean? b3 = (); -boolean|int b4 = false; +final boolean b1 = true; +final false b2 = false; +final boolean? b3 = (); +final boolean|int b4 = false; -string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues1 = string `b1,b2,b3,b4 true,false,true,false true,false, true,false true,false,true,false `; -string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 +final string csvStringWithBooleanValues2 = string `b1,b2,b3,b4,b5 true,false, true,false,true true,false, true,false,true`; -string csvStringWithBooleanValues3 = string `b1,b2,b3 +final string csvStringWithBooleanValues3 = string `b1,b2,b3 ${" "}${"\t"} true, false,true ${" "} @@ -40,24 +40,24 @@ true, true,FALSE `; -string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues4 = string `b1,b2,b3,b4 true,(), (),false true,(), null,false `; -string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues5 = string `b1,b2,b3,b4 true,false,true,2 true,false,true,3 `; -string csvStringWithBooleanValues6 = string `b2,b3 +final string csvStringWithBooleanValues6 = string `b2,b3 (),() `; -string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 +final string csvStringWithBooleanValues7 = string `b1,b2,b3,b4 ${b1},${b2},(),${b4} `; diff --git a/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal b/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal index 728d683..49a00e6 100644 --- a/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal +++ b/ballerina-tests/type-compatible-tests/tests/nill_type_test.bal @@ -7,13 +7,13 @@ type Book1 record { ()|string year; }; -string csvString1 = string `name,author,year - ,b,c - a,,c - a,b,`; - -@test:Config{} +@test:Config function testEmptyStringWithNilConfig() { + string csvString1 = string `name,author,year + ,b,c + a,,c + a,b,`; + Book1[]|error books1 = csv:parseString(csvString1, {nilValue: ""}); test:assertEquals(books1, [ {name: null, author: "b", year: "c"}, diff --git a/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal b/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal index b4a361a..6199175 100644 --- a/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal +++ b/ballerina-tests/type-compatible-tests/tests/parse_string_compatibality_test.bal @@ -208,7 +208,7 @@ function testSpaceBetweendData() { string csv = string `a b, b d e, f "Hello world", " Hi I am ", \" Hi I am \"`; - record{|string...;|}[]|csv:Error rec = csv:parseString(csv); + record {|string...;|}[]|csv:Error rec = csv:parseString(csv); test:assertEquals(rec, [ {"a b":"Hello world","b d e":" Hi I am ","f":"\"Hi I am \""}]); } @@ -218,7 +218,7 @@ function testParseBytes() returns error? { byte[] csvBytes = check io:fileReadBytes(filepath); byte[] csvBytes2 = check io:fileReadBytes(filepath2); - record{}[]|csv:Error rec = csv:parseBytes(csvBytes, {}); + record {}[]|csv:Error rec = csv:parseBytes(csvBytes, {}); test:assertEquals(rec, [ {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}, {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}, @@ -264,7 +264,7 @@ function testParseBytes() returns error? { test:assertTrue(rec3 is csv:Error); test:assertEquals(( rec3).message(), common:generateErrorMessageForInvalidCast("Hello World", "int")); - record{int a;}[]|csv:Error rec4 = csv:parseBytes(csvBytes, {}); + record {int a;}[]|csv:Error rec4 = csv:parseBytes(csvBytes, {}); test:assertTrue(rec4 is csv:Error); test:assertEquals(( rec4).message(), common:generateErrorMessageForInvalidCast("Hello World", "int")); } @@ -274,7 +274,7 @@ function testParseStream() returns error? { stream csvByteStream = check io:fileReadBlocksAsStream(filepath); stream csvByteStream2 = check io:fileReadBlocksAsStream(filepath2); - record{}[]|csv:Error rec = csv:parseStream(csvByteStream, {}); + record {}[]|csv:Error rec = csv:parseStream(csvByteStream, {}); test:assertEquals(rec, [ {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}, {"a":"Hello World","b":"\"Hello World\"","c d":"Hello World","e":2}, @@ -321,7 +321,7 @@ function testParseStream() returns error? { ]); csvByteStream = check io:fileReadBlocksAsStream(filepath); - record{int a;}[]|csv:Error rec3 = csv:parseStream(csvByteStream, {}); + record {int a;}[]|csv:Error rec3 = csv:parseStream(csvByteStream, {}); test:assertTrue(rec3 is csv:Error); test:assertEquals(( rec3).message(), "Error occurred while reading the stream: " + common:generateErrorMessageForInvalidCast("Hello World", "int")); @@ -341,7 +341,7 @@ function testErrorParseBytes() returns error? { test:assertTrue(rec3 is csv:Error); test:assertTrue(( rec3).message().includes("cannot be cast into")); - record{int a;}[]|csv:Error rec4 = csv:parseBytes(csvBytes, {}); + record {int a;}[]|csv:Error rec4 = csv:parseBytes(csvBytes, {}); test:assertTrue(rec4 is csv:Error); test:assertTrue(( rec3).message().includes("cannot be cast into")); } @@ -350,7 +350,7 @@ function testErrorParseBytes() returns error? { function testErrorParseStream() returns error? { stream csvByteStream = check io:fileReadBlocksAsStream(errorFilepath); - record{int a;}[]|csv:Error rec3 = csv:parseStream(csvByteStream, {}); + record {int a;}[]|csv:Error rec3 = csv:parseStream(csvByteStream, {}); test:assertTrue(rec3 is csv:Error); test:assertTrue(( rec3).message().includes("cannot be cast into")); diff --git a/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal b/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal index 06b36a7..1cf12ca 100644 --- a/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal +++ b/ballerina-tests/type-compatible-tests/tests/parse_type_compatibility_test.bal @@ -286,7 +286,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { {"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true} - ], {headersOrder: ["a", "b", "c"]}); + ], {headerOrder: ["a", "b", "c"]}); test:assertEquals(rt6a, [ [1, "string", true], @@ -296,7 +296,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [A, B, C][]|csv:Error rt7a = csv:transform( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] - , {headersOrder: ["a", "b", "c"]}); + , {headerOrder: ["a", "b", "c"]}); test:assertEquals(rt7a, [ [1d, "string", true], @@ -306,7 +306,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [A2, B2, C2][]|csv:Error rt8a = csv:transform( [{"a": 1, "b": "string", "c": true}, {"a": 2, "b": "string2", "c": false}, {"a": 3, "b": "string3", "c": true}] - , {headersOrder: ["a", "b", "c"]}); + , {headerOrder: ["a", "b", "c"]}); test:assertEquals(rt8a, [ [1, "string", true], @@ -316,7 +316,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [A2, B2, C2...][]|csv:Error rt9a = csv:transform( [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] - , {headersOrder: ["a", "b", "c", "d"]}); + , {headerOrder: ["a", "b", "c", "d"]}); test:assertEquals(rt9a, [ [1, "string", true, "string"], @@ -326,7 +326,7 @@ function testFromCsvWithIntersectionTypeCompatibility2() { [C2...][]|csv:Error rt10a = csv:transform( [{"a": 1, "b": "string", "c": true, "d": "string"}, {"a": 2, "b": "string2", "c": false, "d": "string2"}, {"a": 3, "b": "string3", "c": true, "d": "string3"}] - , {headersOrder: ["a", "b", "c", "d"]}); + , {headerOrder: ["a", "b", "c", "d"]}); test:assertTrue(rt10a is csv:Error); test:assertEquals((rt10a).message(), common:generateErrorMessageForInvalidValueForArrayType("1", "0", "type_compatible_tests:C2")); @@ -463,19 +463,19 @@ function testSliceOperation() { int[2][]|error c = csv:parseList(v); test:assertEquals(c, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c2 = csv:parseList(v, {customHeaders: ["a", "b"]}); + record {|int...;|}[2]|error c2 = csv:parseList(v, {customHeaders: ["a", "b"]}); test:assertEquals(c2, [{a: 1, b: 2}, {a: 3, b: 4}]); - int[2][]|error c3 = csv:transform(v2, {headersOrder: ["a", "b"]}); + int[2][]|error c3 = csv:transform(v2, {headerOrder: ["a", "b"]}); test:assertEquals(c3, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c4 = csv:transform(v2); + record {|int...;|}[2]|error c4 = csv:transform(v2); test:assertEquals(c4, [{a: 1, b: 2}, {a: 3, b: 4}]); int[2][]|error c5 = csv:parseString(v3); test:assertEquals(c5, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c6 = csv:parseString(v3); + record {|int...;|}[2]|error c6 = csv:parseString(v3); test:assertEquals(c6, [{a: 1, b: 2}, {a: 3, b: 4}]); } @@ -493,18 +493,18 @@ function testSliceOperation2() { int[2][2]|error c = csv:parseList(v, {skipLines: [1, 3]}); test:assertEquals(c, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c2 = csv:parseList(v, {customHeaders: ["a", "b", "c"], skipLines: [1, 3]}); + record {|int...;|}[2]|error c2 = csv:parseList(v, {customHeaders: ["a", "b", "c"], skipLines: [1, 3]}); test:assertEquals(c2, [{a: 1, b: 2}, {a: 3, b: 4}]); - int[2][2]|error c3 = csv:transform(v2, {headersOrder: ["a", "b", "c"], skipLines: [1, 3]}); + int[2][2]|error c3 = csv:transform(v2, {headerOrder: ["a", "b", "c"], skipLines: [1, 3]}); test:assertEquals(c3, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c4 = csv:transform(v2, {skipLines: [1, 3]}); + record {|int...;|}[2]|error c4 = csv:transform(v2, {skipLines: [1, 3]}); test:assertEquals(c4, [{a: 1, b: 2}, {a: 3, b: 4}]); int[2][2]|error c5 = csv:parseString(v3, {skipLines: [1, 3]}); test:assertEquals(c5, [[1, 2], [3, 4]]); - record{|int...;|}[2]|error c6 = csv:parseString(v3, {skipLines: [1, 3]}); + record {|int...;|}[2]|error c6 = csv:parseString(v3, {skipLines: [1, 3]}); test:assertEquals(c6, [{a: 1, b: 2}, {a: 3, b: 4}]); } \ No newline at end of file diff --git a/ballerina-tests/type-compatible-tests/tests/test_data_values.bal b/ballerina-tests/type-compatible-tests/tests/test_data_values.bal index 5993176..5838ec6 100644 --- a/ballerina-tests/type-compatible-tests/tests/test_data_values.bal +++ b/ballerina-tests/type-compatible-tests/tests/test_data_values.bal @@ -14,41 +14,41 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean? b3 = (); -boolean|int b4 = false; +final boolean b1 = true; +final false b2 = false; +final boolean? b3 = (); +final boolean|int b4 = false; -() n1 = (); -int? n2 = (); -() n3 = null; +final () n1 = (); +final int? n2 = (); +final () n3 = null; -int i1 = 1; -int i2 = -2; -int i3 = int:MAX_VALUE; -int i4 = int:MIN_VALUE; -int i5 = 0; -2 i6 = 2; -int? i7 = (); -int|string i8 = 100; +final int i1 = 1; +final int i2 = -2; +final int i3 = int:MAX_VALUE; +final int i4 = int:MIN_VALUE; +final int i5 = 0; +final 2 i6 = 2; +final int? i7 = (); +final int|string i8 = 100; -float f1 = 2.234; -float f2 = -3.21f; -float f3 = 0; -float f4 = float:Infinity; -float f5 = -float:Infinity; -float f6 = float:NaN; -2.3f f7 = 2.3; -float? f8 = (); -float|decimal f9 = 1.21; +final float f1 = 2.234; +final float f2 = -3.21f; +final float f3 = 0; +final float f4 = float:Infinity; +final float f5 = -float:Infinity; +final float f6 = float:NaN; +final 2.3f f7 = 2.3; +final float? f8 = (); +final float|decimal f9 = 1.21; -decimal d1 = 2.234; -decimal d2 = -3.21d; -decimal d3 = 0; -2.3d d4 = 2.3; -decimal? d5 = (); -decimal|int d6 = 1.21; +final decimal d1 = 2.234; +final decimal d2 = -3.21d; +final decimal d3 = 0; +final 2.3d d4 = 2.3; +final decimal? d5 = (); +final decimal|int d6 = 1.21; -string s1 = "string"; -string s2 = ""; -string:Char s3 = "a"; +final string s1 = "string"; +final string s2 = ""; +final string:Char s3 = "a"; diff --git a/ballerina-tests/unicode-tests/tests/escape_character_test.bal b/ballerina-tests/unicode-tests/tests/escape_character_test.bal index 9114e1b..5ed18d1 100644 --- a/ballerina-tests/unicode-tests/tests/escape_character_test.bal +++ b/ballerina-tests/unicode-tests/tests/escape_character_test.bal @@ -28,7 +28,7 @@ function testEscapedCharactres() returns error? { slash\/slash, 9 quoted string \\'abc\\', 10`; - record{string a; int b;}[]|csv:Error rec = csv:parseString(csvString); + record {string a; int b;}[]|csv:Error rec = csv:parseString(csvString); test:assertEquals(rec, [ {a: string `quote""quoted"quote`, b: 1}, {a: string `backslash${"\\"}backslash`, b: 2}, @@ -45,8 +45,8 @@ function testEscapedCharactres2() returns error? { string csvString = string `a, b backspace\bbackspace, 7`; - record{string a; int b;}[]|csv:Error rec = csv:parseString(csvString); - test:assertTrue(rec is record{string a; int b;}[]); + record {string a; int b;}[]|csv:Error rec = csv:parseString(csvString); + test:assertTrue(rec is record {string a; int b;}[]); } @test:Config @@ -54,7 +54,7 @@ function testEscapedCharactres3() returns error? { string csvString = string ` a c, b carriage return\r carriage return, 4`; - record{}[]|csv:Error rec = csv:parseString(csvString); + record {}[]|csv:Error rec = csv:parseString(csvString); test:assertEquals(rec, [ {"a c": string `carriage return${"\r"} carriage return`, b: 4} ]); @@ -65,7 +65,7 @@ function testEscapedCharactres4() returns error? { string csvString = string `a, b form feed\f form feed, 8`; - record{string a; int b;}[]|csv:Error rec = csv:parseString(csvString); + record {string a; int b;}[]|csv:Error rec = csv:parseString(csvString); test:assertTrue(rec is record {string a; int b;}[]); // TODO: Add tests after supports \f by Ballerina } diff --git a/ballerina-tests/union-type-tests/tests/test_data_values.bal b/ballerina-tests/union-type-tests/tests/test_data_values.bal index 7d88394..23c0be9 100644 --- a/ballerina-tests/union-type-tests/tests/test_data_values.bal +++ b/ballerina-tests/union-type-tests/tests/test_data_values.bal @@ -14,7 +14,7 @@ // specific language governing permissions and limitations // under the License. -string csvStringData1 = string ` +final string csvStringData1 = string ` a, b, c, d, e, f 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null diff --git a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal index 9b03961..85a4f8c 100644 --- a/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal +++ b/ballerina-tests/union-type-tests/tests/test_union_types_with_headers.bal @@ -1,21 +1,21 @@ import ballerina/data.csv; import ballerina/test; -csv:TransformOptions op1 = {headersOrder: ["a", "b", "c", "d"], outputWithHeaders: false}; -csv:TransformOptions op2 = {headersOrder: ["a", "b", "c", "d"], outputWithHeaders: true}; -csv:TransformOptions op3 = {outputWithHeaders: true}; -csv:TransformOptions op4 = {headersOrder: ["a", "b"], outputWithHeaders: true}; - -csv:ParseOptions op5 = {outputWithHeaders: true}; - -csv:ParseListOptions op6 = {outputWithHeaders: true}; -csv:ParseListOptions op7 = {outputWithHeaders: true, headersRows: 1}; -csv:ParseListOptions op8 = {outputWithHeaders: true, headersRows: 2}; -csv:ParseListOptions op9 = {outputWithHeaders: true, headersRows: 2, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListOptions op10 = {outputWithHeaders: true, headersRows: 1, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListOptions op12 = {headersRows: 1, customHeaders: ["a", "b", "c", "d"]}; -csv:ParseListOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; +final csv:TransformOptions op1 = {headerOrder: ["a", "b", "c", "d"], outputWithHeaders: false}; +final csv:TransformOptions op2 = {headerOrder: ["a", "b", "c", "d"], outputWithHeaders: true}; +final csv:TransformOptions op3 = {outputWithHeaders: true}; +final csv:TransformOptions op4 = {headerOrder: ["a", "b"], outputWithHeaders: true}; + +final csv:ParseOptions op5 = {outputWithHeaders: true}; + +final csv:ParseListOptions op6 = {outputWithHeaders: true}; +final csv:ParseListOptions op7 = {outputWithHeaders: true, headerRows: 1}; +final csv:ParseListOptions op8 = {outputWithHeaders: true, headerRows: 2}; +final csv:ParseListOptions op9 = {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b", "c", "d"]}; +final csv:ParseListOptions op10 = {outputWithHeaders: true, headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +final csv:ParseListOptions op11 = {outputWithHeaders: true, customHeaders: ["a", "b", "c", "d"]}; +final csv:ParseListOptions op12 = {headerRows: 1, customHeaders: ["a", "b", "c", "d"]}; +final csv:ParseListOptions op13 = {customHeaders: ["a", "b", "c", "d"]}; type UnionType1 boolean[][]|string[][]; @@ -25,23 +25,23 @@ type UnionType3 record {int d1;}[]|record {}[]; type UnionType4 (map|map)[]; -string[][] csv1 = [["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; -var csv2 = [{a: 1, b: 2, c: 3, d: 4}, {a: 5, b: 6, c: 7, d: 8}, {a: 9, b: 10, c: 11, d: 12}, {a: 13, b: 14, c: 15, d: 16}]; -var csv3 = string `a,b,c,d +final string[][] csv1 = [["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; +final var csv2 = [{a: 1, b: 2, c: 3, d: 4}, {a: 5, b: 6, c: 7, d: 8}, {a: 9, b: 10, c: 11, d: 12}, {a: 13, b: 14, c: 15, d: 16}]; +final var csv3 = string `a,b,c,d 1,2,3,4 5,6,7,8 9,10,11,12 13,14,15,16`; -var csv4 = [{a: "1", b: "2", c: "3", d: "4"}, {a: "5", b: "6", c: "7", d: "8"}, {a: "9", b: "10", c: "11", d: "12"}, {a: "13", b: "14", c: "15", d: "16"}]; - -var result1 = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]; -var result2 = [{a: 1, b: 2, c: 3, d: 4}, {a: 5, b: 6, c: 7, d: 8}, {a: 9, b: 10, c: 11, d: 12}, {a: 13, b: 14, c: 15, d: 16}]; -var result3 = [{a: "1", b: "2", c: "3", d: "4"}, {a: "5", b: "6", c: "7", d: "8"}, {a: "9", b: "10", c: "11", d: "12"}, {a: "13", b: "14", c: "15", d: "16"}]; -var result4 = [["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; -var result5 = [["a", "b", "c", "d"], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]; -var result6 = [["a", "b", "c", "d"], ["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; -var result7 = [{'1: 1, '2: 2, '3: 3, '4: 4}, {'1: 5, '2: 6, '3: 7, '4: 8}, {'1: 9, '2: 10, '3: 11, '4: 12}, {'1: 13, '2: 14, '3: 15, '4: 16}]; -var result8 = [{'1: "1", '2: "2", '3: "3", '4: "4"}, {'1: "5", '2: "6", '3: "7", '4: "8"}, {'1: "9", '2: "10", '3: "11", '4: "12"}, {'1: "13", '2: "14", '3: "15", '4: "16"}]; +final var csv4 = [{a: "1", b: "2", c: "3", d: "4"}, {a: "5", b: "6", c: "7", d: "8"}, {a: "9", b: "10", c: "11", d: "12"}, {a: "13", b: "14", c: "15", d: "16"}]; + +final var result1 = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]; +final var result2 = [{a: 1, b: 2, c: 3, d: 4}, {a: 5, b: 6, c: 7, d: 8}, {a: 9, b: 10, c: 11, d: 12}, {a: 13, b: 14, c: 15, d: 16}]; +final var result3 = [{a: "1", b: "2", c: "3", d: "4"}, {a: "5", b: "6", c: "7", d: "8"}, {a: "9", b: "10", c: "11", d: "12"}, {a: "13", b: "14", c: "15", d: "16"}]; +final var result4 = [["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; +final var result5 = [["a", "b", "c", "d"], [1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]; +final var result6 = [["a", "b", "c", "d"], ["1", "2", "3", "4"], ["5", "6", "7", "8"], ["9", "10", "11", "12"], ["13", "14", "15", "16"]]; +final var result7 = [{'1: 1, '2: 2, '3: 3, '4: 4}, {'1: 5, '2: 6, '3: 7, '4: 8}, {'1: 9, '2: 10, '3: 11, '4: 12}, {'1: 13, '2: 14, '3: 15, '4: 16}]; +final var result8 = [{'1: "1", '2: "2", '3: "3", '4: "4"}, {'1: "5", '2: "6", '3: "7", '4: "8"}, {'1: "9", '2: "10", '3: "11", '4: "12"}, {'1: "13", '2: "14", '3: "15", '4: "16"}]; @test:Config function testParseStringWithMapWithOutputHeaders() { diff --git a/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal b/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal index 726ef47..7661513 100644 --- a/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_intersection_types.bal @@ -82,11 +82,11 @@ function testIntersectionExpectedTypes() returns error? { @test:Config function testIntersectionExpectedTypes2() returns error? { - (int[] & readonly)[]|csv:Error a = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], {headersOrder: ["a", "b"]}); + (int[] & readonly)[]|csv:Error a = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], {headerOrder: ["a", "b"]}); test:assertTrue(a is (int[] & readonly)[]); test:assertEquals(a, [[1, 2], [4, 5]]); - ([string, string])[] & readonly|csv:Error a2 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {headersOrder: ["a", "b"]}); + ([string, string])[] & readonly|csv:Error a2 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {headerOrder: ["a", "b"]}); test:assertTrue(a2 is [string, string][] & readonly); test:assertEquals(a2, [["a", "a"], ["c", "c"]]); @@ -98,11 +98,11 @@ function testIntersectionExpectedTypes2() returns error? { test:assertTrue(a4 is record {|string...;|}[] & readonly); test:assertEquals(a4, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - ([int] & readonly)[]|csv:Error a5 = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], {headersOrder: ["a", "b"]}); + ([int] & readonly)[]|csv:Error a5 = csv:transform([{"a": 1, "b": 2}, {"a": 4, "b": 5}], {headerOrder: ["a", "b"]}); test:assertTrue(a5 is ([int] & readonly)[]); test:assertEquals(a5, [[1], [4]]); - ([string, string])[] & readonly|csv:Error a6 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {headersOrder: ["a", "b"]}); + ([string, string])[] & readonly|csv:Error a6 = csv:transform([{"a": "a", "b": "a"}, {"a": "c", "b": "c"}], {headerOrder: ["a", "b"]}); test:assertTrue(a6 is [string, string][] & readonly); test:assertEquals(a6, [["a", "a"], ["c", "c"]]); @@ -114,11 +114,11 @@ function testIntersectionExpectedTypes2() returns error? { test:assertTrue(a8 is map[] & readonly); test:assertEquals(a8, [{a: "a", b: "a"}, {a: "c", b: "c"}]); - (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headerOrder: ["a", "b"]}); test:assertTrue(a9 is error); - test:assertEquals(( a9).message(), "The CSV cannot be converted into any of the uniform union types in '((int[] & readonly)|([string,string] & readonly))[]'"); + test:assertEquals(( a9).message(), "source value cannot converted in to the '((int[] & readonly)|([string,string] & readonly))[]'"); - (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9_2 = csv:transform([{"a": "1", "b": "2"}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + (((int[] & readonly)|([string, string] & readonly)) & readonly)[]|csv:Error a9_2 = csv:transform([{"a": "1", "b": "2"}, {"a": "a", "b": "b"}], {headerOrder: ["a", "b"]}); test:assertTrue(a9_2 is (((int[] & readonly)|([string, string] & readonly)) & readonly)[]); test:assertEquals(a9_2, [["1", "2"], ["a", "b"]]); @@ -130,7 +130,7 @@ function testIntersectionExpectedTypes2() returns error? { ((record {string a; string b;} & readonly)|(record {int a; int b;} & readonly))[] & readonly|csv:Error a10_2 = csv:transform([{"a": "a", "b": "a"}, {"a": 1, "b": 2}], {}); test:assertTrue(a10_2 is error); - test:assertEquals(( a10_2).message(), "The CSV cannot be converted into any of the uniform union types in '((union_type_tests:record {| string a; string b; anydata...; |} & readonly)|(union_type_tests:record {| int a; int b; anydata...; |} & readonly))[]'"); + test:assertEquals(( a10_2).message(), "source value cannot converted in to the '((union_type_tests:record {| string a; string b; anydata...; |} & readonly)|(union_type_tests:record {| int a; int b; anydata...; |} & readonly))[]'"); } @test:Config diff --git a/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal b/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal index 4bf4c7f..57bfa05 100644 --- a/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_singleton_test.bal @@ -202,13 +202,13 @@ function testSubtypeExpectedTypes() returns error? { SubtypeRecord3[]|csv:Error a9 = csv:transform(value1, {}); test:assertEquals(a9, value1); - SubtypeTuple[]|csv:Error a10 = csv:transform(value1, {headersOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); + SubtypeTuple[]|csv:Error a10 = csv:transform(value1, {headerOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a10, value3); - SubtypeTuple2[]|csv:Error a11 = csv:transform(value1, {headersOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); + SubtypeTuple2[]|csv:Error a11 = csv:transform(value1, {headerOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a11, [[1, 1], [1, 1]]); - SubtypeTuple3[]|csv:Error a12 = csv:transform(value1, {headersOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); + SubtypeTuple3[]|csv:Error a12 = csv:transform(value1, {headerOrder: ["a", "c", "d", "e", "f", "g", "h", "i"]}); test:assertEquals(a12, value3); SubtypeRecord[]|csv:Error a13 = csv:parseList(value2, {customHeaders: ["a", "c", "d", "e", "f", "g", "h", "i"]}); diff --git a/ballerina-tests/union-type-tests/tests/test_with_union_types.bal b/ballerina-tests/union-type-tests/tests/test_with_union_types.bal index f9246ce..594401b 100644 --- a/ballerina-tests/union-type-tests/tests/test_with_union_types.bal +++ b/ballerina-tests/union-type-tests/tests/test_with_union_types.bal @@ -64,21 +64,21 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); + (record {|int a;|}|record {|string b;|})[]|csv:Error csv1op6 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); + (record {|string b;|}|record {|int a;|})[]|csv:Error csv1op7 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:parseString(csvStringData1, {header: 1}); + (record {|string...;|}|record {|int...;|})[]|csv:Error csv1op8 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op8, [ {a: "1", b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: "2", b: "string2", c: "false", d: "0", e: "0", f: "null"}, @@ -87,7 +87,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseString(csvStringData1, {header: 1}); + (record {|int...;|}|record {|string...;|})[]|csv:Error csv1op9 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -96,7 +96,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, d: 3, e: 3} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseString(csvStringData1, {header: 1}); + (record {|int a; string...;|}|record {|string a; int...;|})[]|csv:Error csv1op10 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: 2, b: "string2", c: "false", d: "0", e: "0", f: "null"}, @@ -105,7 +105,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: 5, b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:parseString(csvStringData1, {header: 1}); + (record {|string a; int...;|}|record {|int a; string...;|})[]|csv:Error csv1op11 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -114,7 +114,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { {a: "5", d: 3, e: 3} ]); - (record{|int a; int b;|}|record{|string a; string...;|})[]|csv:Error csv1op12 = csv:parseString(string ` + (record {|int a; int b;|}|record {|string a; string...;|})[]|csv:Error csv1op12 = csv:parseString(string ` a,b 1, 2 a, b`, {header: 1}); @@ -133,7 +133,7 @@ function testParseToStringWithUnionExpectedTypes() returns error? { ]); } -record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ +record {int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, @@ -181,21 +181,21 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:transform(value, {skipLines: [2, 4]}); + (record {|int a;|}|record {|string b;|})[]|csv:Error csv1op6 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:transform(value, {skipLines: [2, 4]}); + (record {|string b;|}|record {|int a;|})[]|csv:Error csv1op7 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:transform(value, {}); + (record {|string...;|}|record {|int...;|})[]|csv:Error csv1op8 = csv:transform(value, {}); test:assertEquals(csv1op8, [ {b: "string1"}, {b: "string2"}, @@ -204,7 +204,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {b: "string5"} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:transform(value, {}); + (record {|int...;|}|record {|string...;|})[]|csv:Error csv1op9 = csv:transform(value, {}); test:assertEquals(csv1op9, [ {a: 1, d: 2, e: 2}, {a: 2, d: 0, e: 0}, @@ -213,7 +213,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, d: 3, e: 3} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:transform(value, {}); + (record {|int a; string...;|}|record {|string a; int...;|})[]|csv:Error csv1op10 = csv:transform(value, {}); test:assertEquals(csv1op10, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -222,7 +222,7 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:transform(value, {}); + (record {|string a; int...;|}|record {|int a; string...;|})[]|csv:Error csv1op11 = csv:transform(value, {}); test:assertEquals(csv1op11, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -231,19 +231,19 @@ function testParseToStringWithUnionExpectedTypes2() returns error? { {a: 5, b: "string5"} ]); - (record{|string a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op12 = csv:transform(value, {}); + (record {|string a; int...;|}|record {|string a; string...;|})[]|csv:Error csv1op12 = csv:transform(value, {}); test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:record {| string a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); + test:assertEquals((csv1op12).message(), "source value cannot converted in to the '(union_type_tests:record {| string a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); - (record{|int a; int...;|}|record{|int|string a; int|string...;|})[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); + (record {|int a; int...;|}|record {|int|string a; int|string...;|})[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); test:assertEquals(csv1op13, [ {a: 1, b: 2}, {a: "a", b: "b"} ]); - (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op14 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); + (record {|int a; int...;|}|record {|string a; string...;|})[]|csv:Error csv1op14 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {}); test:assertTrue(csv1op14 is csv:Error); - test:assertEquals((csv1op14).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:record {| int a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); + test:assertEquals((csv1op14).message(), "source value cannot converted in to the '(union_type_tests:record {| int a; int...; |}|union_type_tests:record {| string a; string...; |})[]'"); } @test:Config @@ -294,28 +294,28 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - (record{|int a;|}|record{|string b;|})[]|csv:Error csv1op6 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (record {|int a;|}|record {|string b;|})[]|csv:Error csv1op6 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - (record{|string b;|}|record{|int a;|})[]|csv:Error csv1op7 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (record {|string b;|}|record {|int a;|})[]|csv:Error csv1op7 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - (record{|string...;|}|record{|int...;|})[]|csv:Error csv1op8 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); + (record {|string...;|}|record {|int...;|})[]|csv:Error csv1op8 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); test:assertEquals(csv1op8, [ {a: "1", b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: "3", b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: "5", b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - (record{|int...;|}|record{|string...;|})[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); + (record {|int...;|}|record {|string...;|})[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -324,14 +324,14 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: 5, d: 3} ]); - (record{|int a; string...;|}|record{|string a; int...;|})[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); + (record {|int a; string...;|}|record {|string a; int...;|})[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: 3, b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: 5, b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - (record{|string a; int...;|}|record{|int a; string...;|})[]|csv:Error csv1op11 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); + (record {|string a; int...;|}|record {|int a; string...;|})[]|csv:Error csv1op11 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -340,7 +340,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { {a: "5", d: 3} ]); - (record{|int a; int...;|}|record{|string a; string...;|})[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); + (record {|int a; int...;|}|record {|string a; string...;|})[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, {a: "a", b: "b"} @@ -350,7 +350,7 @@ function testParseToStringWithUnionExpectedTypes3() returns error? { @test:Config function testParseToStringWithUnionExpectedTypes4() returns error? { - record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + record {int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, @@ -358,7 +358,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - (TupA|TupC)[]|csv:Error csv1op1 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + (TupA|TupC)[]|csv:Error csv1op1 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -367,7 +367,7 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupA|TupC)[]|csv:Error csv1op2 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (TupA|TupC)[]|csv:Error csv1op2 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertTrue(csv1op2 is (TupA|TupC)[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -375,74 +375,74 @@ function testParseToStringWithUnionExpectedTypes4() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - (TupC|TupA)[]|csv:Error csv1op3 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (TupC|TupA)[]|csv:Error csv1op3 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op3, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - (TupB|TupA)[]|csv:Error csv1op4 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (TupB|TupA)[]|csv:Error csv1op4 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op4, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - (TupB|[boolean])[]|csv:Error csv1op4_2 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (TupB|[boolean])[]|csv:Error csv1op4_2 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is csv:Error); - test:assertEquals((csv1op4_2).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:TupB|[boolean])[]'"); + test:assertEquals((csv1op4_2).message(), "source value cannot converted in to the '(union_type_tests:TupB|[boolean])[]'"); - (TupA|TupB)[]|csv:Error csv1op5 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + (TupA|TupB)[]|csv:Error csv1op5 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op5, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - ([int]|[string])[]|csv:Error csv1op6 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + ([int]|[string])[]|csv:Error csv1op6 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - ([string]|[int])[]|csv:Error csv1op7 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + ([string]|[int])[]|csv:Error csv1op7 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ [1], [3], [5] ]); - ([string...]|[int...])[]|csv:Error csv1op8 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + ([string...]|[int...])[]|csv:Error csv1op8 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op8 is csv:Error); - test:assertEquals((csv1op8).message(), "The CSV cannot be converted into any of the uniform union types in '([string...]|[int...])[]'"); + test:assertEquals((csv1op8).message(), "source value cannot converted in to the '([string...]|[int...])[]'"); - ([int...]|[string...])[]|csv:Error csv1op9 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + ([int...]|[string...])[]|csv:Error csv1op9 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op9 is csv:Error); - test:assertEquals((csv1op9).message(), "The CSV cannot be converted into any of the uniform union types in '([int...]|[string...])[]'"); + test:assertEquals((csv1op9).message(), "source value cannot converted in to the '([int...]|[string...])[]'"); - ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + ([int, string...]|[string, int...])[]|csv:Error csv1op10 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op10 is csv:Error); - test:assertEquals((csv1op10).message(), "The CSV cannot be converted into any of the uniform union types in '([int,string...]|[string,int...])[]'"); + test:assertEquals((csv1op10).message(), "source value cannot converted in to the '([int,string...]|[string,int...])[]'"); - ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + ([string, int...]|[int, string...])[]|csv:Error csv1op11 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op11 is csv:Error); - test:assertEquals((csv1op11).message(), "The CSV cannot be converted into any of the uniform union types in '([string,int...]|[int,string...])[]'"); + test:assertEquals((csv1op11).message(), "source value cannot converted in to the '([string,int...]|[int,string...])[]'"); - ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + ([string, int...]|[string, string...])[]|csv:Error csv1op12 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The CSV cannot be converted into any of the uniform union types in '([string,int...]|[string,string...])[]'"); + test:assertEquals((csv1op12).message(), "source value cannot converted in to the '([string,int...]|[string,string...])[]'"); - ([string, string...]|[int|string, int|string...])[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + ([string, string...]|[int|string, int|string...])[]|csv:Error csv1op13 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headerOrder: ["a", "b"]}); test:assertEquals(csv1op13, [ [1, 2], ["a", "b"] ]); - ([int, int...]|[string, string...])[]|csv:Error csv1op14 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headersOrder: ["a", "b"]}); + ([int, int...]|[string, string...])[]|csv:Error csv1op14 = csv:transform([{"a": 1, "b": 2}, {"a": "a", "b": "b"}], {headerOrder: ["a", "b"]}); test:assertTrue(csv1op14 is csv:Error); - test:assertEquals((csv1op14).message(), "The CSV cannot be converted into any of the uniform union types in '([int,int...]|[string,string...])[]'"); + test:assertEquals((csv1op14).message(), "source value cannot converted in to the '([int,int...]|[string,string...])[]'"); } @test:Config @@ -488,7 +488,7 @@ function testParseToStringWithUnionExpectedTypes5() returns error? { (TupB|[boolean])[]|csv:Error csv1op4_2 = csv:parseList(value, {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is csv:Error); - test:assertEquals((csv1op4_2).message(), "The CSV cannot be converted into any of the uniform union types in '(union_type_tests:TupB|[boolean])[]'"); + test:assertEquals((csv1op4_2).message(), "source value cannot converted in to the '(union_type_tests:TupB|[boolean])[]'"); (TupA|TupB)[]|csv:Error csv1op5 = csv:parseList(value, {skipLines: [2, 4]}); test:assertEquals(csv1op5, [ @@ -585,21 +585,21 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); + record {|int a;|}[]|record {|string b;|}[]|csv:Error csv1op6 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); + record {|string b;|}[]|record {|int a;|}[]|csv:Error csv1op7 = csv:parseString(csvStringData1, {header: 1, skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:parseString(csvStringData1, {header: 1}); + record {|string...;|}[]|record {|int...;|}[]|csv:Error csv1op8 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op8, [ {a: "1", b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: "2", b: "string2", c: "false", d: "0", e: "0", f: "null"}, @@ -608,7 +608,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: "5", b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseString(csvStringData1, {header: 1}); + record {|int...;|}[]|record {|string...;|}[]|csv:Error csv1op9 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -617,7 +617,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, d: 3, e: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseString(csvStringData1, {header: 1}); + record {|int a; string...;|}[]|record {|string a; int...;|}[]|csv:Error csv1op10 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: 2, b: "string2", c: "false", d: "0", e: "0", f: "null"}, @@ -626,7 +626,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: 5, b: "string5", c: "true", d: "3", e: "3", f: "()"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseString(csvStringData1, {header: 1}); + record {|string a; int...;|}[]|record {|int a; string...;|}[]|csv:Error csv1op11 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -635,7 +635,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { {a: "5", d: 3, e: 3} ]); - record{|int a; int b;|}[]|record{|string a; string...;|}[]|csv:Error csv1op12 = csv:parseString(string ` + record {|int a; int b;|}[]|record {|string a; string...;|}[]|csv:Error csv1op12 = csv:parseString(string ` a,b 1, 2 a, b`, {header: 1}); @@ -647,7 +647,7 @@ function testParseToStringWithUnionExpectedTypes6() returns error? { @test:Config function testParseToStringWithUnionExpectedTypes7() returns error? { - record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + record {int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, @@ -693,21 +693,21 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:transform(value, {skipLines: [2, 4]}); + record {|int a;|}[]|record {|string b;|}[]|csv:Error csv1op6 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:transform(value, {skipLines: [2, 4]}); + record {|string b;|}[]|record {|int a;|}[]|csv:Error csv1op7 = csv:transform(value, {skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:transform(value, {}); + record {|string...;|}[]|record {|int...;|}[]|csv:Error csv1op8 = csv:transform(value, {}); test:assertEquals(csv1op8, [ {b: "string1"}, {b: "string2"}, @@ -716,7 +716,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {b: "string5"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:transform(value, {}); + record {|int...;|}[]|record {|string...;|}[]|csv:Error csv1op9 = csv:transform(value, {}); test:assertEquals(csv1op9, [ {a: 1, d: 2, e: 2}, {a: 2, d: 0, e: 0}, @@ -725,7 +725,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, d: 3, e: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:transform(value, {}); + record {|int a; string...;|}[]|record {|string a; int...;|}[]|csv:Error csv1op10 = csv:transform(value, {}); test:assertEquals(csv1op10, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -734,7 +734,7 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:transform(value, {}); + record {|string a; int...;|}[]|record {|int a; string...;|}[]|csv:Error csv1op11 = csv:transform(value, {}); test:assertEquals(csv1op11, [ {a: 1, b: "string1"}, {a: 2, b: "string2"}, @@ -743,9 +743,9 @@ function testParseToStringWithUnionExpectedTypes7() returns error? { {a: 5, b: "string5"} ]); - record{|string a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op12 = csv:transform(value, {}); + record {|string a; int...;|}[]|record {|string a; string...;|}[]|csv:Error csv1op12 = csv:transform(value, {}); test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '(union_type_tests:record {| string a; int...; |}[]|union_type_tests:record {| string a; string...; |}[])'"); + test:assertEquals((csv1op12).message(), "source value cannot converted in to the '(union_type_tests:record {| string a; int...; |}[]|union_type_tests:record {| string a; string...; |}[])'"); } @test:Config @@ -796,28 +796,28 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]); - record{|int a;|}[]|record{|string b;|}[]|csv:Error csv1op6 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + record {|int a;|}[]|record {|string b;|}[]|csv:Error csv1op6 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ {a: 1}, {a: 3}, {a: 5} ]); - record{|string b;|}[]|record{|int a;|}[]|csv:Error csv1op7 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + record {|string b;|}[]|record {|int a;|}[]|csv:Error csv1op7 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ {b: "string1"}, {b: "string3"}, {b: "string5"} ]); - record{|string...;|}[]|record{|int...;|}[]|csv:Error csv1op8 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); + record {|string...;|}[]|record {|int...;|}[]|csv:Error csv1op8 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [4, 2]}); test:assertEquals(csv1op8, [ {a: "1", b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: "3", b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: "5", b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - record{|int...;|}[]|record{|string...;|}[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); + record {|int...;|}[]|record {|string...;|}[]|csv:Error csv1op9 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op9, [ {a: 1}, {a: 2, d: 0, e: 0}, @@ -826,14 +826,14 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: 5, d: 3} ]); - record{|int a; string...;|}[]|record{|string a; int...;|}[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); + record {|int a; string...;|}[]|record {|string a; int...;|}[]|csv:Error csv1op10 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"], skipLines: [2, -1, 4]}); test:assertEquals(csv1op10, [ {a: 1, b: "string1", c: "true", d: "2.234", e: "2.234", f: "()"}, {a: 3, b: "string3", c: "false", d: "1.23", e: "1.23", f: "()"}, {a: 5, b: "string5", c: "true", d: "3", e: "3.0", f: "()"} ]); - record{|string a; int...;|}[]|record{|int a; string...;|}[]|csv:Error csv1op11 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); + record {|string a; int...;|}[]|record {|int a; string...;|}[]|csv:Error csv1op11 = csv:parseList(value, {customHeaders: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op11, [ {a: "1"}, {a: "2", d: 0, e: 0}, @@ -842,7 +842,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { {a: "5", d: 3} ]); - record{|int a; int...;|}[]|record{|string a; string...;|}[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); + record {|int a; int...;|}[]|record {|string a; string...;|}[]|csv:Error csv1op13 = csv:parseList([["1", "2"], ["a", "b"]], {customHeaders: ["a", "b"]}); test:assertEquals(csv1op13, [ {a: "1", b: "2"}, {a: "a", b: "b"} @@ -852,7 +852,7 @@ function testParseToStringWithUnionExpectedTypes8() returns error? { @test:Config function testParseToStringWithUnionExpectedTypes9() returns error? { - record{int a; string b; boolean c; decimal d; float e; () f;}[] value = [ + record {int a; string b; boolean c; decimal d; float e; () f;}[] value = [ {a: 1, b: "string1", c: true, d: 2.234, e: 2.234, f: ()}, {a: 2, b: "string2", c: false, d: 0, e: 0, f: ()}, {a: 3, b: "string3", c: false, d: 1.23, e: 1.23, f: ()}, @@ -860,7 +860,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { {a: 5, b: "string5", c: true, d: 3, e: 3.0, f: ()} ]; - TupA[]|TupC[]|csv:Error csv1op1 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + TupA[]|TupC[]|csv:Error csv1op1 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertEquals(csv1op1, [ [1, "string1", true, 2.234, 2.234, ()], [2, "string2", false, 0, 0, ()], @@ -869,7 +869,7 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupA[]|TupC[]|csv:Error csv1op2 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + TupA[]|TupC[]|csv:Error csv1op2 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertTrue(csv1op2 is TupA[]|TupC[]); test:assertEquals(csv1op2, [ [1, "string1", true, 2.234, 2.234, ()], @@ -877,64 +877,64 @@ function testParseToStringWithUnionExpectedTypes9() returns error? { [5, "string5", true, 3, 3.0, ()] ]); - TupC[]|TupA[]|csv:Error csv1op3 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + TupC[]|TupA[]|csv:Error csv1op3 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op3, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - TupB[]|TupA[]|csv:Error csv1op4 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + TupB[]|TupA[]|csv:Error csv1op4 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op4, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - TupB[]|[boolean][]|csv:Error csv1op4_2 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + TupB[]|[boolean][]|csv:Error csv1op4_2 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is csv:Error); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(union_type_tests:TupB[]|[boolean][])'"); + test:assertEquals((csv1op4_2).message(), "source value cannot converted in to the '(union_type_tests:TupB[]|[boolean][])'"); - TupA[]|TupB[]|csv:Error csv1op5 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + TupA[]|TupB[]|csv:Error csv1op5 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op5, [ [1, "string1", true, 2.234, 2.234, ()], [3, "string3", false, 1.23, 1.23, ()], [5, "string5", true, 3, 3.0, ()] ]); - [int][]|[string][]|csv:Error csv1op6 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + [int][]|[string][]|csv:Error csv1op6 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op6, [ [1], [3], [5] ]); - [string][]|[int][]|csv:Error csv1op7 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); + [string][]|[int][]|csv:Error csv1op7 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"], skipLines: [2, 4]}); test:assertEquals(csv1op7, [ [1], [3], [5] ]); - [string...][]|[int...][]|csv:Error csv1op8 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + [string...][]|[int...][]|csv:Error csv1op8 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op8 is csv:Error); - test:assertEquals((csv1op8).message(), "The source value cannot convert in to the '([string...][]|[int...][])'"); + test:assertEquals((csv1op8).message(), "source value cannot converted in to the '([string...][]|[int...][])'"); - [int...][]|[string...][]|csv:Error csv1op9 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + [int...][]|[string...][]|csv:Error csv1op9 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op9 is csv:Error); - test:assertEquals((csv1op9).message(), "The source value cannot convert in to the '([int...][]|[string...][])'"); + test:assertEquals((csv1op9).message(), "source value cannot converted in to the '([int...][]|[string...][])'"); - [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + [int, string...][]|[string, int...][]|csv:Error csv1op10 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op10 is csv:Error); - test:assertEquals((csv1op10).message(), "The source value cannot convert in to the '([int,string...][]|[string,int...][])'"); + test:assertEquals((csv1op10).message(), "source value cannot converted in to the '([int,string...][]|[string,int...][])'"); - [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + [string, int...][]|[int, string...][]|csv:Error csv1op11 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op11 is csv:Error); - test:assertEquals((csv1op11).message(), "The source value cannot convert in to the '([string,int...][]|[int,string...][])'"); + test:assertEquals((csv1op11).message(), "source value cannot converted in to the '([string,int...][]|[int,string...][])'"); - [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:transform(value, {headersOrder: ["a", "b", "c", "d", "e", "f"]}); + [string, int...][]|[string, string...][]|csv:Error csv1op12 = csv:transform(value, {headerOrder: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(csv1op12 is csv:Error); - test:assertEquals((csv1op12).message(), "The source value cannot convert in to the '([string,int...][]|[string,string...][])'"); + test:assertEquals((csv1op12).message(), "source value cannot converted in to the '([string,int...][]|[string,string...][])'"); } @test:Config @@ -980,7 +980,7 @@ function testParseToStringWithUnionExpectedTypes10() returns error? { TupB[]|[boolean][]|csv:Error csv1op4_2 = csv:parseList(value, {skipLines: [2, 4]}); test:assertTrue(csv1op4_2 is csv:Error); - test:assertEquals((csv1op4_2).message(), "The source value cannot convert in to the '(union_type_tests:TupB[]|[boolean][])'"); + test:assertEquals((csv1op4_2).message(), "source value cannot converted in to the '(union_type_tests:TupB[]|[boolean][])'"); TupA[]|TupB[]|csv:Error csv1op5 = csv:parseList(value, {skipLines: [2, 4]}); test:assertEquals(csv1op5, [ @@ -1037,7 +1037,7 @@ function testUnionTypeWithOrdering() returns error? { string value2 = string `a,b, c, d 1, 1.0, true, a 2, 2.0, false, b`; - record{}[] value3 = [{"a": 1, "b": 1.0, "c": true, "d": "a"}, {"a": 2, "b": 2.0, "c": false, "d":"b"}]; + record {}[] value3 = [{"a": 1, "b": 1.0, "c": true, "d": "a"}, {"a": 2, "b": 2.0, "c": false, "d":"b"}]; string[][]|anydata[][]|error csv1op1 = csv:parseList(value1); test:assertEquals(csv1op1, [ @@ -1190,7 +1190,7 @@ function testUnionTypeWithNull() returns error? { string value2 = string `a,b, c, d 1, (), true, a 2, (), false, b`; - record{}[] value3 = [{"a": 1, "b": (), "c": true, "d": "a"}, {"a": 2, "b": (), "c": false, "d":"b"}]; + record {}[] value3 = [{"a": 1, "b": (), "c": true, "d": "a"}, {"a": 2, "b": (), "c": false, "d":"b"}]; string value4 = string `a,b, c, d 1, , true, a 2, , false, b`; diff --git a/ballerina-tests/user-config-tests/tests/test_data_values.bal b/ballerina-tests/user-config-tests/tests/test_data_values.bal index bf329ff..666d717 100644 --- a/ballerina-tests/user-config-tests/tests/test_data_values.bal +++ b/ballerina-tests/user-config-tests/tests/test_data_values.bal @@ -14,24 +14,24 @@ // specific language governing permissions and limitations // under the License. -boolean b1 = true; -false b2 = false; -boolean? b3 = (); -boolean|int b4 = false; +final boolean b1 = true; +final false b2 = false; +final boolean? b3 = (); +final boolean|int b4 = false; -() n1 = (); -int? n2 = (); -() n3 = null; +final () n1 = (); +final int? n2 = (); +final () n3 = null; -int i1 = 1; +final int i1 = 1; -map bm1 = {b1, b2}; -map bm2 = {b1, b2, b3, n1, n3}; -map bm3 = {b1, b2, b3, b4, i1}; -map<()> bm4 = {n1, n3}; -map bm5 = {b1, b2, b3, b4:true}; +final map bm1 = {b1, b2}; +final map bm2 = {b1, b2, b3, n1, n3}; +final map bm3 = {b1, b2, b3, b4, i1}; +final map<()> bm4 = {n1, n3}; +final map bm5 = {b1, b2, b3, b4:true}; -string csvStringData1 = string ` +final string csvStringData1 = string ` a, b, c, d, e, f 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null @@ -39,7 +39,7 @@ string csvStringData1 = string ` 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; -string csvStringData2 = string ` +final string csvStringData2 = string ` hello, hello, (), 12, true, 12.34 // comment @@ -52,7 +52,7 @@ string csvStringData2 = string ` 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; -string csvStringData3 = string ` +final string csvStringData3 = string ` a, b, c, d, e, f @@ -64,14 +64,14 @@ string csvStringData3 = string ` 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; -string csvStringData4 = string ` +final string csvStringData4 = string ` 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null 3, string3, false, 1.23, 1.23, () 4, string4, true, -6.51, -6.51, () 5, string5, true, 3, 3, ()`; -string csvStringData5 = string ` +final string csvStringData5 = string ` @@ -83,7 +83,7 @@ string csvStringData5 = string ` 5, string5, true, 3, 3, ()`; -string csvStringData6 = string ` +final string csvStringData6 = string ` 1, string1, true, 2.234, 2.234, () 2, string2, false, 0, 0, null @@ -93,14 +93,14 @@ string csvStringData6 = string ` 5, string5, true, 3, 3, ()`; -string csvStringData7 = string ` +final string csvStringData7 = string ` a@ b@ c@ d@ e@ f 1@ string@ true@ 2.234@ -3.21@ () 2@ s,tring@ true@ 2.234@ -3.21@ null 3@ stri,ng@ true@ 2.234@ -3.21@ () 4@ string@ true@ 2.234@ -3.21@ () 5@ string@ true@ 2.234@ -3.21@ ()`; -string csvStringData8 = string ` +final string csvStringData8 = string ` a@ b@ c@ d@ e@ f @@ -112,7 +112,7 @@ string csvStringData8 = string ` 4@ s,tring@ true@ 2.234@ -3.21@ () 5@ string@ true@ 2.234@ -3.21@ ()`; -string csvStringData9 = string ` +final string csvStringData9 = string ` 1@ string@ true@ 2.234@ -3.21@ () 2@ string@ true@ 2.234@ -3.21@ null @@ -122,7 +122,7 @@ string csvStringData9 = string ` 5@ string@ true@ 2.234@ -3.21@ null`; -string csvStringData10 = string ` +final string csvStringData10 = string ` hello, hello, (), 12, true, 12.34 // comment @@ -135,7 +135,7 @@ string csvStringData10 = string ` 4, string4, true, -6.51, -6.52, () 5, string5, true, 3, 31, ()`; -string csvStringData11 = string ` +final string csvStringData11 = string ` a, b, c, d, e, f diff --git a/ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal b/ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal index 2ad8e88..e6dd846 100644 --- a/ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal +++ b/ballerina-tests/user-config-tests/tests/user_config_projection_tests.bal @@ -49,12 +49,12 @@ function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation2[]|csv:Error cn7 = csv:parseString(string `a,b 3,1`, {}); test:assertTrue(cn7 is csv:Error); - test:assertEquals((cn7).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn7).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation2[]|csv:Error cn8 = csv:parseString(string ` c,d,a,b 3,1,4,5`, {}); test:assertTrue(cn8 is csv:Error); - test:assertEquals((cn8).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn8).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation3[]|csv:Error cn9 = csv:parseString(string `d,c 1,3`, {}); @@ -72,12 +72,12 @@ function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation3[]|csv:Error cn12 = csv:parseString(string `a,b 3,1`, {}); test:assertTrue(cn12 is csv:Error); - test:assertEquals((cn12).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn12).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation3[]|csv:Error cn13 = csv:parseString(string ` c,d,a,b 3,1,4,5`, {}); test:assertTrue(cn13 is csv:Error); - test:assertEquals((cn13).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn13).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation4[]|csv:Error cn14 = csv:parseString(string `d,c,z 1,3,true`, {}); @@ -95,17 +95,17 @@ function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation4[]|csv:Error cn17 = csv:parseString(string `a,b 3,1`, {}); test:assertTrue(cn17 is csv:Error); - test:assertEquals((cn17).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn17).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation4[]|csv:Error cn18 = csv:parseString(string ` c,d,a,b 3,1,4,5`, {}); test:assertTrue(cn18 is csv:Error); - test:assertEquals((cn18).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn18).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation5[]|csv:Error cn19 = csv:parseString(string ` c,d,a,b 3,1,4,5`, {}); test:assertTrue(cn19 is csv:Error); - test:assertEquals((cn19).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cn19).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation5[]|csv:Error cn20 = csv:parseString(string ` c,d,e 3,1,4 @@ -139,11 +139,11 @@ function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation2[]|csv:Error cnrr7 = csv:transform([{"a":3, "b": 1}], {}); test:assertTrue(cnrr7 is csv:Error); - test:assertEquals((cnrr7).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cnrr7).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation2[]|csv:Error cnrr8 = csv:transform([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); test:assertTrue(cnrr8 is csv:Error); - test:assertEquals((cnrr8).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cnrr8).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation3[]|csv:Error cnrr9 = csv:transform([{"d": 1, "c": 3}], {}); test:assertEquals(cnrr9, [{b: 1, a: 3}]); @@ -157,11 +157,11 @@ function testCustomNameAnnotation() returns error? { RecordWithCustomAnnotation3[]|csv:Error cnrr12 = csv:transform([{"a": 3, "b": 1}], {}); test:assertTrue(cnrr12 is csv:Error); - test:assertEquals((cnrr12).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cnrr12).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation3[]|csv:Error cnrr13 = csv:transform([{"c": 3, "d": 1, "a": 4, "b": 5}], {}); test:assertTrue(cnrr13 is csv:Error); - test:assertEquals((cnrr13).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cnrr13).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation4[]|csv:Error cnrr14 = csv:transform([{"d": 1, "c": 3, "z": true}], {}); test:assertEquals(cnrr14, [{b: 1, a: 3, z: true}]); @@ -206,11 +206,11 @@ function testCustomNameAnnotation2() returns error? { RecordWithCustomAnnotation2[]|csv:Error cntr7 = csv:parseList([["3", "1"]], {customHeaders: ["a", "b"]}); test:assertTrue(cntr7 is csv:Error); - test:assertEquals((cntr7).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr7).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation2[]|csv:Error cntr8 = csv:parseList([["3", "1", "4", "5"]], {customHeaders: ["c", "d", "a", "b"]}); test:assertTrue(cntr8 is csv:Error); - test:assertEquals((cntr8).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr8).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation3[]|csv:Error cntr9 = csv:parseList([["1", "3"]], {customHeaders: ["d", "c"]}); test:assertEquals(cntr9, [{b: 1, a: 3}]); @@ -228,7 +228,7 @@ function testCustomNameAnnotation2() returns error? { RecordWithCustomAnnotation3[]|csv:Error cntr13 = csv:parseList([["3", "1", "4", "5"]], {customHeaders: ["c", "d", "a", "b"]}); test:assertTrue(cntr13 is csv:Error); - test:assertEquals((cntr13).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr13).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation4[]|csv:Error cntr14 = csv:parseList([["1", "3", "true"]], {customHeaders: ["d", "c", "z"]}); test:assertEquals(cntr14, [{b: 1, a: 3, z: true}]); @@ -242,15 +242,15 @@ function testCustomNameAnnotation2() returns error? { RecordWithCustomAnnotation4[]|csv:Error cntr17 = csv:parseList([["3", "1"]], {customHeaders: ["a", "b"]}); test:assertTrue(cntr17 is csv:Error); - test:assertEquals((cntr17).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr17).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation4[]|csv:Error cntr18 = csv:parseList([["3", "1", "4", "5"]], {customHeaders: ["c", "d", "a", "b"]}); test:assertTrue(cntr18 is csv:Error); - test:assertEquals((cntr18).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr18).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation5[]|csv:Error cntr19 = csv:parseList([["3", "1", "4", "5"]], {customHeaders: ["c", "d", "a", "b"]}); test:assertTrue(cntr19 is csv:Error); - test:assertEquals((cntr19).message(), "Duplicate field found in record fields: 'a'"); + test:assertEquals((cntr19).message(), "duplicate field found in record fields: 'a'"); RecordWithCustomAnnotation5[]|csv:Error cntr20 = csv:parseList( [["3", "1", "4"], ["3", "1", "4"]], {customHeaders: ["c", "d", "e"]}); @@ -485,45 +485,45 @@ function testDataProjectionConfig() returns error? { string csvValue1 = string `a,b "a",2 b,4`; - record{}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; + record {}[] csvValue2 = [{"a": "a", "b": 2}, {"a": "b", "b": 4}]; - record{}[]|csv:Error cn = csv:parseString(csvValue1, { + record {}[]|csv:Error cn = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a; int b;|}[]|csv:Error cn_2 = csv:parseString(csvValue1, { + record {|string a; int b;|}[]|csv:Error cn_2 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a;|}[]|csv:Error cn2 = csv:parseString(csvValue1, { + record {|string a;|}[]|csv:Error cn2 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertTrue(cn2 is csv:Error); - test:assertEquals((cn2).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn2).message(), "no mapping field in the expected type for header 'b'"); - record{|string a; int...;|}[]|csv:Error cn3 = csv:parseString(csvValue1, { + record {|string a; int...;|}[]|csv:Error cn3 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn3, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string...;|}[]|csv:Error cn4 = csv:parseString(csvValue1, { + record {|string...;|}[]|csv:Error cn4 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertEquals(cn4, [{"a": "a", "b": "2"}, {"a": "b", "b": "4"}]); - record{|string a?;|}[]|csv:Error cn5 = csv:parseString(csvValue1, { + record {|string a?;|}[]|csv:Error cn5 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertTrue(cn5 is csv:Error); - test:assertEquals((cn5).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn5).message(), "no mapping field in the expected type for header 'b'"); - record{|string? a;|}[]|csv:Error cn6 = csv:parseString(csvValue1, { + record {|string? a;|}[]|csv:Error cn6 = csv:parseString(csvValue1, { allowDataProjection: false }); test:assertTrue(cn6 is csv:Error); - test:assertEquals((cn6).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn6).message(), "no mapping field in the expected type for header 'b'"); anydata[][]|csv:Error c7 = csv:parseString(csvValue1, { allowDataProjection: false @@ -579,95 +579,95 @@ function testDataProjectionConfig() returns error? { test:assertTrue(cn13 is csv:Error); test:assertEquals((cn13).message(), "invalid array size for expected array type, cannot be greater than '1'"); - record{}[]|csv:Error cn14 = csv:transform(csvValue2, { + record {}[]|csv:Error cn14 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertEquals(cn14, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a; int b;|}[]|csv:Error cn14_2 = csv:transform(csvValue2, { + record {|string a; int b;|}[]|csv:Error cn14_2 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertEquals(cn14_2, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string a;|}[]|csv:Error cn15 = csv:transform(csvValue2, { + record {|string a;|}[]|csv:Error cn15 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertTrue(cn15 is csv:Error); - test:assertEquals((cn15).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn15).message(), "no mapping field in the expected type for header 'b'"); - record{|string a; int...;|}[]|csv:Error cn16 = csv:transform(csvValue2, { + record {|string a; int...;|}[]|csv:Error cn16 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertEquals(cn16, [{"a": "a", "b": 2}, {"a": "b", "b": 4}]); - record{|string...;|}[]|csv:Error cn17 = csv:transform(csvValue2, { + record {|string...;|}[]|csv:Error cn17 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertEquals(cn17, [{"a": "a"}, {"a": "b"}]); - record{|string a?;|}[]|csv:Error cn18 = csv:transform(csvValue2, { + record {|string a?;|}[]|csv:Error cn18 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertTrue(cn18 is csv:Error); - test:assertEquals((cn18).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn18).message(), "no mapping field in the expected type for header 'b'"); - record{|string? a;|}[]|csv:Error cn19 = csv:transform(csvValue2, { + record {|string? a;|}[]|csv:Error cn19 = csv:transform(csvValue2, { allowDataProjection: false }); test:assertTrue(cn19 is csv:Error); - test:assertEquals((cn19).message(), "No mapping field in the expected type for header 'b'"); + test:assertEquals((cn19).message(), "no mapping field in the expected type for header 'b'"); - anydata[][]|csv:Error c20 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + anydata[][]|csv:Error c20 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertEquals(c20, [["a", 2], ["b", 4]]); - [string, int][]|csv:Error cn20_2 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string, int][]|csv:Error cn20_2 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertEquals(cn20_2, [["a", 2], ["b", 4]]); - [string][]|csv:Error cn21 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string][]|csv:Error cn21 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn21 is csv:Error); test:assertEquals((cn21).message(), "invalid array size for expected tuple type, cannot be greater than '1'"); - [string][]|csv:Error cn21_2 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string][]|csv:Error cn21_2 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: {} }); test:assertEquals(cn21_2, [["a"], ["b"]]); - [int][]|csv:Error cn21_3 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [int][]|csv:Error cn21_3 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: {} }); test:assertTrue(cn21_3 is csv:Error); test:assertEquals((cn21_3).message(), common:generateErrorMessageForInvalidValueForArrayType("a", "0", "int")); - [string, int...][]|csv:Error cn22 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string, int...][]|csv:Error cn22 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertEquals(cn22, [["a", 2], ["b", 4]]); - [string...][]|csv:Error cn23 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string...][]|csv:Error cn23 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn23 is csv:Error); test:assertEquals(( cn23).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - [string, ()][]|csv:Error cn24 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + [string, ()][]|csv:Error cn24 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn24 is csv:Error); test:assertEquals((cn24).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "()")); - string[][]|csv:Error cn25 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + string[][]|csv:Error cn25 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn25 is csv:Error); test:assertEquals(( cn25).message(), common:generateErrorMessageForInvalidValueForArrayType("2", "1", "string")); - string[][1]|csv:Error cn26 = csv:transform(csvValue2, {headersOrder: ["a", "b"], + string[][1]|csv:Error cn26 = csv:transform(csvValue2, {headerOrder: ["a", "b"], allowDataProjection: false }); test:assertTrue(cn26 is csv:Error); diff --git a/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal b/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal index dfbd53b..8bd7397 100644 --- a/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal +++ b/ballerina-tests/user-config-tests/tests/user_config_with_parser_options_test.bal @@ -205,21 +205,21 @@ function testHeaderOption() { record {}[]|csv:Error csv2cop2 = csv:parseString(csvStringData10, {header: 100}); test:assertTrue(csv2cop2 is csv:Error); - test:assertEquals((csv2cop2).message(), "The provided header row is empty"); + test:assertEquals((csv2cop2).message(), "provided header row is empty"); record {}[]|csv:Error csv2cop3 = csv:parseString(csvStringData10, {header: 11}); test:assertEquals(csv2cop3, []); record {}[]|csv:Error csv2cop3_2 = csv:parseString(csvStringData10, {header: 9}); test:assertTrue(csv2cop3_2 is csv:Error); - test:assertEquals((csv2cop3_2).message(), "Duplicate header found: '1.23'"); + test:assertEquals((csv2cop3_2).message(), "duplicate header found: '1.23'"); record {}[]|csv:Error csv2cop4 = csv:parseString(csvStringData10, {header: 10}); test:assertEquals(csv2cop4, [{'4: 5, string4: "string5", "true": true, "-6.51": 3, "-6.52": 31, "()": ()}]); record {}[]|csv:Error csv1cop5 = csv:parseString(csvStringData1, {}); test:assertTrue(csv1cop5 is csv:Error); - test:assertEquals((csv1cop5).message(), "The provided header row is empty"); + test:assertEquals((csv1cop5).message(), "provided header row is empty"); } @test:Config {dependsOn: [testCSVLocale]} @@ -354,11 +354,11 @@ function testCommentConfigOption() { cn = csv:parseString(csvValue10); test:assertTrue(cn is csv:Error); - test:assertEquals(( cn).message(), "Invalid number of headers"); + test:assertEquals(( cn).message(), "invalid number of headers"); cn = csv:parseString(csvValue9); test:assertTrue(cn is csv:Error); - test:assertEquals(( cn).message(), "The provided header row is empty"); + test:assertEquals(( cn).message(), "provided header row is empty"); } @test:Config {dependsOn: [testCSVLocale]} @@ -427,7 +427,7 @@ function testCommentConfigOption2() { cn = csv:parseString(csvValue6, {comment: "&", header: 2}); test:assertTrue(cn is csv:Error); - test:assertEquals((cn).message(), "The provided header row is empty"); + test:assertEquals((cn).message(), "provided header row is empty"); cn = csv:parseString(csvValue8, {comment: "&", header: 2}); test:assertTrue(cn is csv:Error); @@ -435,7 +435,7 @@ function testCommentConfigOption2() { cn = csv:parseString(csvValue7, {comment: "&", header: 2}); test:assertTrue(cn is csv:Error); - test:assertEquals((cn).message(), "Invalid number of headers"); + test:assertEquals((cn).message(), "invalid number of headers"); cn2 = csv:parseString(csvValue1, {comment: "&"}); test:assertTrue(cn2 is csv:Error); @@ -460,7 +460,7 @@ function testCommentConfigOption2() { cn2 = csv:parseString(csvValue6, {header: 2, comment: "&"}); test:assertTrue(cn2 is csv:Error); - test:assertEquals((cn2).message(), "The provided header row is empty"); + test:assertEquals((cn2).message(), "provided header row is empty"); } @test:Config {dependsOn: [testCSVLocale]} @@ -566,53 +566,53 @@ function testSkipLineParserOption() { @test:Config {dependsOn: [testCSVLocale]} function testCustomHeaderOption() { - anydata[][]|csv:Error bm1ba = csv:transform([bm1, bm1], {headersOrder: ["b1", "b2"]}); + anydata[][]|csv:Error bm1ba = csv:transform([bm1, bm1], {headerOrder: ["b1", "b2"]}); test:assertEquals(bm1ba, [ [true, false], [true, false] ]); - anydata[][]|csv:Error bm1ba2 = csv:transform([bm1, bm1], {headersOrder: ["b2", "b1"]}); + anydata[][]|csv:Error bm1ba2 = csv:transform([bm1, bm1], {headerOrder: ["b2", "b1"]}); test:assertEquals(bm1ba2, [ [false, true], [false, true] ]); - anydata[][]|csv:Error bm2ba = csv:transform([bm2, bm2], {headersOrder: ["b1", "n1", "b2", "n2", "b3"]}); + anydata[][]|csv:Error bm2ba = csv:transform([bm2, bm2], {headerOrder: ["b1", "n1", "b2", "n2", "b3"]}); test:assertTrue(bm2ba is csv:Error); test:assertEquals((bm2ba).message(), "CSV data rows with varying headers are not yet supported"); - anydata[][]|csv:Error bm3ba = csv:transform([bm3, bm3], {headersOrder: ["b1", "b4", "b2", "n2", "i1"]}); + anydata[][]|csv:Error bm3ba = csv:transform([bm3, bm3], {headerOrder: ["b1", "b4", "b2", "n2", "i1"]}); test:assertTrue(bm3ba is csv:Error); test:assertEquals((bm3ba).message(), "CSV data rows with varying headers are not yet supported"); - anydata[][]|csv:Error bm3ba2 = csv:transform([bm3, bm3], {headersOrder: ["b1", "b3", "b4", "b2", "i2"]}); + anydata[][]|csv:Error bm3ba2 = csv:transform([bm3, bm3], {headerOrder: ["b1", "b3", "b4", "b2", "i2"]}); test:assertTrue(bm3ba2 is csv:Error); test:assertEquals((bm3ba2).message(), "CSV data rows with varying headers are not yet supported"); - [boolean...][]|csv:Error bm3ba4 = csv:transform([bm3, bm3], {headersOrder: ["n2"]}); + [boolean...][]|csv:Error bm3ba4 = csv:transform([bm3, bm3], {headerOrder: ["n2"]}); test:assertTrue(bm3ba4 is csv:Error); - test:assertEquals((bm3ba4).message(), "Invalid number of headers"); + test:assertEquals((bm3ba4).message(), "invalid number of headers"); - [boolean...][]|csv:Error bm3ba5 = csv:transform([bm3, bm3], {headersOrder: []}); + [boolean...][]|csv:Error bm3ba5 = csv:transform([bm3, bm3], {headerOrder: []}); test:assertTrue(bm3ba5 is csv:Error); - test:assertEquals((bm3ba5).message(), "Invalid number of headers"); + test:assertEquals((bm3ba5).message(), "invalid number of headers"); record {}[]|csv:Error ct1br = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "b"]}); test:assertTrue(ct1br is csv:Error); - test:assertEquals((ct1br).message(), "Invalid number of headers"); + test:assertEquals((ct1br).message(), "invalid number of headers"); record {}[]|csv:Error ct1br2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "b", "c", "d"]}); test:assertTrue(ct1br2 is csv:Error); - test:assertEquals((ct1br2).message(), "Invalid number of headers"); + test:assertEquals((ct1br2).message(), "invalid number of headers"); record {}[]|csv:Error ct1br2_2 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "c", "b", "d"]}); test:assertTrue(ct1br2_2 is csv:Error); - test:assertEquals((ct1br2_2).message(), "Invalid number of headers"); + test:assertEquals((ct1br2_2).message(), "invalid number of headers"); record {}[]|csv:Error ct1br3 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: []}); test:assertTrue(ct1br3 is csv:Error); - test:assertEquals((ct1br3).message(), "Invalid number of headers"); + test:assertEquals((ct1br3).message(), "invalid number of headers"); record {|string a; string b; string c;|}[]|csv:Error ct1br5 = csv:parseList([["a", "1", "true"], ["a", "1", "true"]], {customHeaders: ["a", "e", "b"]}); test:assertTrue(ct1br5 is csv:Error); @@ -686,11 +686,11 @@ function testCustomHeaderParserOption2() { record {}[]|csv:Error ct1br2 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: []}); test:assertTrue(ct1br2 is csv:Error); - test:assertEquals((ct1br2).message(), "Invalid number of headers"); + test:assertEquals((ct1br2).message(), "invalid number of headers"); record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br3 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); test:assertTrue(ct1br3 is csv:Error); - test:assertEquals((ct1br3).message(), "Invalid number of headers"); + test:assertEquals((ct1br3).message(), "invalid number of headers"); record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br4 = csv:parseString(csvStringData1, {header: 1}); test:assertEquals(ct1br4, [ @@ -761,7 +761,7 @@ function testCustomHeaderParserOption2() { record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1"]}); test:assertTrue(ct1br11 is csv:Error); - test:assertEquals((ct1br11).message(), "Invalid number of headers"); + test:assertEquals((ct1br11).message(), "invalid number of headers"); record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ @@ -837,12 +837,12 @@ function testTextQuotesWithParserOptions() { record {}[]|csv:Error cn6 = csv:parseString(csvValue6, {}); test:assertTrue(cn6 is csv:Error); - test:assertEquals((cn6).message(), "Invalid number of headers"); + test:assertEquals((cn6).message(), "invalid number of headers"); cn6 = csv:parseString(string `a,b,c,d 1,1,1,1,1`, {}); test:assertTrue(cn6 is csv:Error); - test:assertEquals((cn6).message(), "Invalid number of headers"); + test:assertEquals((cn6).message(), "invalid number of headers"); } @test:Config @@ -1001,30 +1001,30 @@ function testSkipLineParameterWithOutputHeaderConfig() { result2 = csv:parseList(csv2, {outputWithHeaders: true, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [1, 2], [4, 5]]); - result = csv:parseList(csv2, {headersRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + result = csv:parseList(csv2, {headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result, [{a: 2, b: 3}]); - result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [2, 3]]); - result = csv:parseList(csv2, {headersRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); + result = csv:parseList(csv2, {headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result, [{a: 3, b: 4}]); - result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 2, skipLines: "2-3", customHeaders: ["a", "b"]}); test:assertEquals(result2, [["a", "b"], [3, 4]]); - result = csv:parseList(csv2, {headersRows: 1, skipLines: "2-3"}); + result = csv:parseList(csv2, {headerRows: 1, skipLines: "2-3"}); test:assertEquals(result, [{'1: 2, '2: 3}]); - result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 1, skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 1, skipLines: "2-3"}); test:assertEquals(result2, [[1, 2], [2, 3]]); - result2 = csv:parseList(csv2, {outputWithHeaders: false, headersRows: 1, skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: false, headerRows: 1, skipLines: "2-3"}); test:assertEquals(result2, [[2, 3]]); - result = csv:parseList(csv2, {headersRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); + result = csv:parseList(csv2, {headerRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); test:assertEquals(result, [{a: 3, b: 4}]); - result2 = csv:parseList(csv2, {outputWithHeaders: true, headersRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); + result2 = csv:parseList(csv2, {outputWithHeaders: true, headerRows: 2, customHeaders: ["a", "b"], skipLines: "2-3"}); test:assertEquals(result2, [["a", "b"], [3, 4]]); } diff --git a/ballerina-tests/user-config-tests/tests/user_configs.bal b/ballerina-tests/user-config-tests/tests/user_configs.bal index de47edf..8a38db6 100644 --- a/ballerina-tests/user-config-tests/tests/user_configs.bal +++ b/ballerina-tests/user-config-tests/tests/user_configs.bal @@ -17,29 +17,29 @@ import ballerina/data.csv; // Valid parser options -csv:ParseOptions option1 = {delimiter: "@", nilValue: "null", lineTerminator: [csv:LF]}; -csv:ParseOptions option2 = {nilValue: "N/A", lineTerminator: [csv:CRLF, csv:LF], comment: "/"}; -csv:ParseOptions option3 = {nilValue: "()", header: 1, skipLines: [1, 2]}; -csv:ParseOptions option4 = {nilValue: "", header: 4, skipLines: "1-5"}; -csv:ParseOptions option5 = {nilValue: "", header: 4, skipLines: "1-1"}; -csv:ParseOptions option6 = {nilValue: "()", header: false, skipLines: [1, 2]}; +final csv:ParseOptions option1 = {delimiter: "@", nilValue: "null", lineTerminator: [csv:LF]}; +final csv:ParseOptions option2 = {nilValue: "N/A", lineTerminator: [csv:CRLF, csv:LF], comment: "/"}; +final csv:ParseOptions option3 = {nilValue: "()", header: 1, skipLines: [1, 2]}; +final csv:ParseOptions option4 = {nilValue: "", header: 4, skipLines: "1-5"}; +final csv:ParseOptions option5 = {nilValue: "", header: 4, skipLines: "1-1"}; +final csv:ParseOptions option6 = {nilValue: "()", header: false, skipLines: [1, 2]}; -csv:ParseOptions ptOption1 = {nilValue: "", header: 1, skipLines: [2, 4]}; -csv:ParseOptions ptOption2 = {nilValue: "", header: 1, skipLines: "2-4"}; -csv:ParseOptions ptOption3 = {nilValue: "", header: 4, skipLines: "1-5"}; -csv:ParseOptions ptOption4 = {nilValue: "", header: 4, skipLines: [-1, -2, 4, 2]}; -csv:ParseOptions ptOption5 = {header: false, skipLines: [-1, -2, 5, 3]}; +final csv:ParseOptions ptOption1 = {nilValue: "", header: 1, skipLines: [2, 4]}; +final csv:ParseOptions ptOption2 = {nilValue: "", header: 1, skipLines: "2-4"}; +final csv:ParseOptions ptOption3 = {nilValue: "", header: 4, skipLines: "1-5"}; +final csv:ParseOptions ptOption4 = {nilValue: "", header: 4, skipLines: [-1, -2, 4, 2]}; +final csv:ParseOptions ptOption5 = {header: false, skipLines: [-1, -2, 5, 3]}; // Invalid parser options -csv:ParseOptions invalidParserOptions1 = {header: 4}; -csv:ParseOptions invalidParserOptions2 = {comment: "$"}; -csv:ParseOptions invalidParserOptions3 = {lineTerminator: csv:CRLF}; -csv:ParseOptions invalidParserOptions4 = {skipLines: [1000, 1001]}; -csv:ParseOptions invalidParserOptions5 = {skipLines: "a-b"}; -csv:ParseOptions invalidParserOptions6 = {skipLines: "3-1"}; -csv:ParseOptions invalidParserOptions7 = {skipLines: "a-5"}; -csv:ParseOptions invalidParserOptions8 = {skipLines: "6-a"}; -csv:ParseOptions invalidParserOptions9 = {skipLines: "a-5"}; -csv:ParseOptions invalidParserOptions10 = {skipLines: "-1-6"}; -csv:ParseOptions invalidParserOptions11 = {nilValue: "", header: 4, skipLines: "0-10"}; -csv:ParseOptions invalidParserOptions12 = {skipLines: [1, 3, 4, -1]}; +final csv:ParseOptions invalidParserOptions1 = {header: 4}; +final csv:ParseOptions invalidParserOptions2 = {comment: "$"}; +final csv:ParseOptions invalidParserOptions3 = {lineTerminator: csv:CRLF}; +final csv:ParseOptions invalidParserOptions4 = {skipLines: [1000, 1001]}; +final csv:ParseOptions invalidParserOptions5 = {skipLines: "a-b"}; +final csv:ParseOptions invalidParserOptions6 = {skipLines: "3-1"}; +final csv:ParseOptions invalidParserOptions7 = {skipLines: "a-5"}; +final csv:ParseOptions invalidParserOptions8 = {skipLines: "6-a"}; +final csv:ParseOptions invalidParserOptions9 = {skipLines: "a-5"}; +final csv:ParseOptions invalidParserOptions10 = {skipLines: "-1-6"}; +final csv:ParseOptions invalidParserOptions11 = {nilValue: "", header: 4, skipLines: "0-10"}; +final csv:ParseOptions invalidParserOptions12 = {skipLines: [1, 3, 4, -1]}; diff --git a/ballerina/Package.md b/ballerina/Package.md index ff1deb2..79dcd39 100644 --- a/ballerina/Package.md +++ b/ballerina/Package.md @@ -38,7 +38,7 @@ public function main() returns error? { ### Converting external CSV document to a record value -For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte-block-stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. +For transforming CSV content from an external source into a record value, the `parseString`, `parseBytes` and `parseStream` functions can be used. This external source can be in the form of a string or a byte array/byte block stream that houses the CSV data. This is commonly extracted from files or network sockets. The example below demonstrates the conversion of an CSV value from an external source into a record value. ```ballerina import ballerina/data.csv; @@ -111,7 +111,7 @@ type Book record {| |}; public function main() returns error? { - record{}[] csvContent = [{ + record {}[] csvContent = [{ "name": "Clean Code", "author": "Robert C. Martin", "year": 2008, diff --git a/ballerina/csv_api.bal b/ballerina/csv_api.bal index 66527eb..e39b2ce 100644 --- a/ballerina/csv_api.bal +++ b/ballerina/csv_api.bal @@ -16,91 +16,96 @@ import ballerina/jballerina.java; -# Converts CSV string to subtype of `record{}[]` or `anydata[][]`. +# Parse a CSV string as a subtype of `record {}[]` or `anydata[][]`. +# # ```ballerina # string csvString = string `id,name # 1,John # 3,Jane`; -# record{int id; string name;}[] csv1 = check csv:parseString(csvString); +# record {int id; string name;}[] csv1 = check csv:parseString(csvString); # [int, string][] csv2 = check csv:parseString(csvString); -# record{|int id;|}[] csv3 = check csv:parseString(csvString); -# record{int id;}[] csv4 = check csv:parseString(csvString, {skipLines: [1]}); +# record {|int id;|}[] csv3 = check csv:parseString(csvString); +# record {int id;}[] csv4 = check csv:parseString(csvString, {skipLines: [1]}); # ``` # # + csvString - Source CSV string value # + options - Options to be used for filtering in the projection # + t - Target type # + return - On success, value belonging to the given target type, else returns an `csv:Error` value. -public isolated function parseString(string csvString, ParseOptions options = {}, typedesc t = <>) +public isolated function parseString(string csvString, ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -# Converts byte[] to subtype of `record{}[]` or `anydata[][]`. +# Parse a byte[] as a subtype of `record {}[]` or `anydata[][]`. +# # ```ballerina # byte[] csvBytes = check io:fileReadBytes("example.csv"); # -# record{int id; string name;}[] csv1 = check csv:parseBytes(csvBytes); +# record {int id; string name;}[] csv1 = check csv:parseBytes(csvBytes); # [int, string][] csv2 = check csv:parseBytes(csvBytes); -# record{|int id;|}[] csv3 = check csv:parseBytes(csvBytes); -# record{int id;}[] csv4 = check csv:parseBytes(csvBytes, {skipLines: [1]}); +# record {|int id;|}[] csv3 = check csv:parseBytes(csvBytes); +# record {int id;}[] csv4 = check csv:parseBytes(csvBytes, {skipLines: [1]}); # ``` # # + csvBytes - Source CSV byte array # + options - Options to be used for filtering in the projection # + t - Target type # + return - On success, value belonging to the given target type, else returns an `csv:Error` value. -public isolated function parseBytes(byte[] csvBytes, ParseOptions options = {}, typedesc t = <>) +public isolated function parseBytes(byte[] csvBytes, ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -# Converts CSV byte-block-stream to subtype of `record{}[]` or `anydata[][]`. +# Parse a CSV byte block stream as a subtype of `record {}[]` or `anydata[][]`. +# # ```ballerina # stream csvByteStream = check io:fileReadBlocksAsStream("example.csv"); -# record{int id; string name;}[] csv1 = check csv:parseStream(csvByteStream); +# record {int id; string name;}[] csv1 = check csv:parseStream(csvByteStream); # # stream csvByteStream2 = check io:fileReadBlocksAsStream("example.csv"); # [int, string][] csv2 = check csv:parseStream(csvByteStream2); # # stream csvByteStream3 = check io:fileReadBlocksAsStream("example.csv"); -# record{|int id;|}[] csv3 = check csv:parseStream(csvByteStream3); +# record {|int id;|}[] csv3 = check csv:parseStream(csvByteStream3); # # stream csvByteStream4 = check io:fileReadBlocksAsStream("example.csv"); -# record{int id;}[] csv4 = check csv:parseStream(csvByteStream4, {skipLines: [1]}); +# record {int id;}[] csv4 = check csv:parseStream(csvByteStream4, {skipLines: [1]}); # ``` # -# + csvByteStream - Source CSV byte-block-stream +# + csvByteStream - Source CSV byte block stream # + options - Options to be used for filtering in the projection # + t - Target type # + return - On success, value belonging to the given target type, else returns an `csv:Error` value. public isolated function parseStream(stream csvByteStream, - ParseOptions options = {}, typedesc t = <>) + ParseOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -# Convert value of type record{}[] to subtype of `record{}[]` or `anydata[][]`. +# Transform value of type record {}[] to subtype of `record {}[]` or `anydata[][]`. +# # ```ballerina -# record{int id; string name;}[] csvRecords = [{id: 1, name: "John"}, {id: 2, name: "Jane"}]; +# record {int id; string name;}[] csvRecords = [{id: 1, name: "John"}, {id: 2, name: "Jane"}]; # [int, string][] csv1 = check csv:transform(csvRecords); -# record{|int id;|}[] csv2 = check csv:transform(csvRecords); -# record{int id;}[] csv3 = check csv:transform(csvRecords, {skipLines: [1]}); +# record {|int id;|}[] csv2 = check csv:transform(csvRecords); +# record {int id;}[] csv3 = check csv:transform(csvRecords, {skipLines: [1]}); # ``` # # + csvRecords - Source Ballerina record array value # + options - Options to be used for filtering in the projection # + t - Target type # + return - On success, returns value belonging to the given target type, else returns an `csv:Error` value. -public isolated function transform(record{}[] csvRecords, - TransformOptions options = {}, typedesc t = <>) +public isolated function transform(record {}[] csvRecords, + TransformOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; -# Convert value of type string array of array to subtype of `record{}[]` or `anydata[][]`. +# Parse a string array of array as a subtype of `record {}[]` or `anydata[][]`. +# # ```ballerina # string[][] csvList = [["1", "John"], ["2", "Jane"]]; # [int, string][] csv1 = check csv:parseList(csvList); -# record{|int id;|}[] csv2 = check csv:parseList(csvList, {customHeaders: ["id", "name"]}); -# record{int id;}[] csv3 = check csv:parseList(csvList, {skipLines: [1], customHeaders: ["id", "name"]}); +# record {|int id;|}[] csv2 = check csv:parseList(csvList, {customHeaders: ["id", "name"]}); +# record {int id;}[] csv3 = check csv:parseList(csvList, {skipLines: [1], customHeaders: ["id", "name"]}); # ``` # # + csvList - Source Ballerina string array of array value # + options - Options to be used for filtering in the projection # + t - Target type # + return - On success, returns value belonging to the given target type, else returns an `csv:Error` value. -public isolated function parseList(string[][] csvList, ParseListOptions options = {}, typedesc t = <>) +public isolated function parseList(string[][] csvList, ParseListOptions options = {}, typedesc t = <>) returns t|Error = @java:Method {'class: "io.ballerina.lib.data.csvdata.csv.Native"} external; diff --git a/ballerina/types.bal b/ballerina/types.bal index c825679..84b5502 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -31,9 +31,9 @@ public const annotation NameConfig Name on record field; public type Options record { # Allows data projection with specific settings. # - # This configuration can be either a record or a boolean. - # If it's a record, it contains `nilAsOptionalField` and `absentAsNilableType` options. - # If it's set to `false`, data projection is not allowed. + # This configuration can be either a record or false. + # If it is a record, it contains `nilAsOptionalField` and `absentAsNilableType` options. + # If it is set to `false`, data projection is not allowed. record { # If `true`, nil values will be considered as optional fields in the projection. boolean nilAsOptionalField = false; @@ -78,19 +78,19 @@ public type ParseListOptions record {| *Options; # If `0`, all the source data will treat as data rows. # Otherwise specify the header rows(Starts from 1) in the source data. - int:Unsigned32 headersRows = 0; + int:Unsigned32 headerRows = 0; # Specify the header names of the source data. # This field will overwrite the header values in the header rows. # This will be mandatory if the header row parameter is larger than one. - string[]? customHeaders = (); + string[] customHeaders?; |}; # Represents options for treating a list as a record. public type TransformOptions record {| *Options; # Specify the order of the headers in the source data. - # If the expected type is a subset of `record{}[]` this parameter will be ignored. - string[]? headersOrder = (); + # If the expected type is a subset of `record {}[]` this parameter will be ignored. + string[]? headerOrder = (); |}; # Enum representing possible line terminators. @@ -110,5 +110,5 @@ public enum NilValue { # Represents an empty string as a nil value. EMPTY_STRING = "", # Represents a nil value as Ballerina nil value `()`. - BAL_NULL = "()" + NIL = "()" }; diff --git a/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTest.java b/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTest.java index 5c73016..086355b 100644 --- a/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTest.java +++ b/compiler-plugin-test/src/test/java/io/ballerina/lib/data/csvdata/compiler/CompilerPluginTest.java @@ -45,7 +45,7 @@ public class CompilerPluginTest { "Tuple members can only be basic types, other types are not supported."; static final String IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY = "The option 'outputWithHeaders' will be not allowed" + " since the expected type is a subtype record array."; - static final String IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY = "The option 'headersOrder' will be not allowed" + + static final String IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY = "The option 'headerOrder' will be not allowed" + " since the expected type is a subtype record array."; static final String IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT = "The option " + "'customHeadersIfHeadersAbsent' will be not allowed since the header is present."; @@ -222,7 +222,7 @@ public void testIgnoredOutputHeaderOptions() { } @Test - public void testIgnoredHeadersOrderOptions() { + public void testIgnoredheaderOrderOptions() { DiagnosticResult diagnosticResult = CompilerPluginTestUtils.loadPackage("sample_package_9").getCompilation().diagnosticResult(); List errorDiagnosticsList = diagnosticResult.diagnostics().stream() diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/main.bal index e4a416c..9052621 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_1/main.bal @@ -7,27 +7,27 @@ public function main() returns error? { [[int, string], [int, string]]|error v = csv:parseString(string `a,b`, {}); [[int, string], [int, string]]|[anydata...][]|error a = csv:parseString(string `a,b`, {}); - [record{}, record{}, record{}, record{}] _ = check csv:parseString(string `a,b`, {}); + [record {}, record {}, record {}, record {}] _ = check csv:parseString(string `a,b`, {}); [[int, string], [int, string]] _ = check csv:parseStream(s, {}); - [record{}, record{}, record{}, record{}] _ = check csv:parseStream(s, {}); + [record {}, record {}, record {}, record {}] _ = check csv:parseStream(s, {}); A _ = check csv:parseBytes([1,2,3], {}); - record{}[]|[record{}, record{}, record{}, record{}] _ = check csv:parseBytes([1,2,3], {}); + record {}[]|[record {}, record {}, record {}, record {}] _ = check csv:parseBytes([1,2,3], {}); int[][]|[[int, string], [int, string]] _ = check csv:transform([{}], {}); [[int, string], [int, string]] _ = check csv:parseList([], {}); - [record{}, record{}, record{}, record{}] _ = check csv:transform([{}], {}); - [record{}, record{}, record{}, record{}] _ = check csv:parseList([], {}); - record{record{} a;}[] _ = check csv:parseList([], {}); - record{int[] a;}[] _ = check csv:parseList([], {}); - record{[int...] a;}[] _ = check csv:parseList([], {}); - record{[int...] a;}[] _ = check csv:parseList([], {}); - record{record{} a;}[] _ = check csv:parseList([], {}); - record{xml a; regexp:RegExp b;}[] _ = check csv:parseList([], {}); + [record {}, record {}, record {}, record {}] _ = check csv:transform([{}], {}); + [record {}, record {}, record {}, record {}] _ = check csv:parseList([], {}); + record {record {} a;}[] _ = check csv:parseList([], {}); + record {int[] a;}[] _ = check csv:parseList([], {}); + record {[int...] a;}[] _ = check csv:parseList([], {}); + record {[int...] a;}[] _ = check csv:parseList([], {}); + record {record {} a;}[] _ = check csv:parseList([], {}); + record {xml a; regexp:RegExp b;}[] _ = check csv:parseList([], {}); [xml, xml][] _ = check csv:parseList([], {}); [regexp:RegExp, xml, int[]][]|csv:Error v2 = csv:parseList([], {}); [regexp:RegExp, xml, int[]][]|int[][] _ = check csv:parseList([], {}); int[][]|[regexp:RegExp, xml, int[]][] _ = check csv:parseList([], {}); - int[][]|[record{}|regexp:RegExp][] _ = check csv:parseList([], {}); - record{}[]|int[][] _ = check csv:parseList([], {}); - record{}[2] _ = check csv:parseList([], {}); + int[][]|[record {}|regexp:RegExp][] _ = check csv:parseList([], {}); + record {}[]|int[][] _ = check csv:parseList([], {}); + record {}[2] _ = check csv:parseList([], {}); int[3][2] _ = check csv:parseList([], {}); } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal index 70bbb6e..666f10f 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_10/main.bal @@ -2,57 +2,57 @@ import ballerina/data.csv; string[]? headers = (); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: false}); -record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: false}); +record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); public function main() returns error? { - record{}[] val = check csv:parseList([["1", "2"]], {headersRows: 0}); - val = check csv:parseList([["1", "2"]], {headersRows: 0}); + record {}[] val = check csv:parseList([["1", "2"]], {headerRows: 0}); + val = check csv:parseList([["1", "2"]], {headerRows: 0}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); - val = check csv:parseList([["1", "2"]], {headersRows: 1}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1}); + val = check csv:parseList([["1", "2"]], {headerRows: 1}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); - val = check csv:parseList([["1", "2"]], {headersRows: 2}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2}); + val = check csv:parseList([["1", "2"]], {headerRows: 2}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: true}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: true}); - record{}[] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); + record {}[] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal index b548c58..d40a261 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_11/main.bal @@ -13,7 +13,7 @@ public function main() returns error? { record {} _ = test3({headerRows: 2, outputWithHeaders: false}); } -function test1(A a) returns record{}[] { +function test1(A a) returns record {}[] { return [{}]; } @@ -21,6 +21,6 @@ function test2(A a) returns [int...][] { return []; } -function test3(A a) returns record{} { +function test3(A a) returns record {} { return {}; } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal index f1ca8d8..a7a5241 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_12/main.bal @@ -2,57 +2,57 @@ import ballerina/data.csv; string[]? headers = (); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: false}); -[anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: false}); +[anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); public function main() returns error? { - [anydata...][] val = check csv:parseList([["1", "2"]], {headersRows: 0}); - val = check csv:parseList([["1", "2"]], {headersRows: 0}); + [anydata...][] val = check csv:parseList([["1", "2"]], {headerRows: 0}); + val = check csv:parseList([["1", "2"]], {headerRows: 0}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ["a", "b"]}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ["a", "b"]}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: ()}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: ()}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 0, customHeaders: headers}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 0, customHeaders: headers}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1}); - val = check csv:parseList([["1", "2"]], {headersRows: 1}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1}); + val = check csv:parseList([["1", "2"]], {headerRows: 1}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ["a", "b"]}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ["a", "b"]}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: ()}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: ()}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 1, customHeaders: headers}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 1, customHeaders: headers}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2}); - val = check csv:parseList([["1", "2"]], {headersRows: 2}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2}); + val = check csv:parseList([["1", "2"]], {headerRows: 2}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ["a", "b"]}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ["a", "b"]}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: ()}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: ()}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: null, outputWithHeaders: true}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: true}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: null, outputWithHeaders: true}); - [anydata...][] _ = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); - val = check csv:parseList([["1", "2"]], {headersRows: 2, customHeaders: headers}); + [anydata...][] _ = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); + val = check csv:parseList([["1", "2"]], {headerRows: 2, customHeaders: headers}); } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/main.bal index 08aeee3..ebad20f 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_4/main.bal @@ -4,14 +4,14 @@ type A [[int, string], [int, string]]; stream s = ( [[1, 2, 3, 4, 5]]).toStream(); [[int, string], [int, string]] val = check csv:parseString(string `a,b`, {}); -[record{}, record{}, record{}, record{}] val2 = check csv:parseString(string `a,b`, {}); +[record {}, record {}, record {}, record {}] val2 = check csv:parseString(string `a,b`, {}); [[int, string], [int, string]] val3 = check csv:parseStream(s, {}); -[record{}, record{}, record{}, record{}] val4 = check csv:parseStream(s, {}); +[record {}, record {}, record {}, record {}] val4 = check csv:parseStream(s, {}); A val5 = check csv:parseBytes([1,2,3], {}); -record{}[]|[record{}, record{}, record{}, record{}] val6 = check csv:parseBytes([1,2,3], {}); +record {}[]|[record {}, record {}, record {}, record {}] val6 = check csv:parseBytes([1,2,3], {}); int[][]|[[int, string], [int, string]] val7 = check csv:transform([{}], {}); [[int, string], [int, string]] val8 = check csv:parseList([], {}); -[record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); -[record{}, record{}, record{}, record{}] val10 = check csv:parseList([], {}); -record{}[2] val11 = check csv:parseList([], {}); +[record {}, record {}, record {}, record {}] val9 = check csv:transform([{}], {}); +[record {}, record {}, record {}, record {}] val10 = check csv:parseList([], {}); +record {}[2] val11 = check csv:parseList([], {}); int[3][2] val12 = check csv:parseList([], {}); diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/main.bal index 0d1fa56..2574a7f 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_6/main.bal @@ -10,15 +10,15 @@ public function test() returns error? { stream s = ( [[1, 2, 3, 4, 5]]).toStream(); [[int, string], [int, string]] val = check csv:parseString(string `a,b`, {}); - [record{}, record{}, record{}, record{}] val2 = check csv:parseString(string `a,b`, {}); + [record {}, record {}, record {}, record {}] val2 = check csv:parseString(string `a,b`, {}); [[int, string], [int, string]] val3 = check csv:parseStream(s, {}); - [record{}, record{}, record{}, record{}] val4 = check csv:parseStream(s, {}); + [record {}, record {}, record {}, record {}] val4 = check csv:parseStream(s, {}); A val5 = check csv:parseBytes([1,2,3], {}); - record{}[]|[record{}, record{}, record{}, record{}] val6 = check csv:parseBytes([1,2,3], {}); + record {}[]|[record {}, record {}, record {}, record {}] val6 = check csv:parseBytes([1,2,3], {}); int[][]|[[int, string], [int, string]] val7 = check csv:transform([{}], {}); [[int, string], [int, string]] val8 = check csv:parseList([], {}); - [record{}, record{}, record{}, record{}] val9 = check csv:transform([{}], {}); - [record{}, record{}, record{}, record{}] val10 = check csv:parseList([], {}); - record{}[2] val11 = check csv:parseList([], {}); + [record {}, record {}, record {}, record {}] val9 = check csv:transform([{}], {}); + [record {}, record {}, record {}, record {}] val10 = check csv:parseList([], {}); + record {}[2] val11 = check csv:parseList([], {}); int[3][2] val12 = check csv:parseList([], {}); } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal index e9a1acb..1251720 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal @@ -4,20 +4,20 @@ string[] customHeaders = ["a", "b"]; int:Unsigned32 header = 0; false header2 = false; -record{}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); -record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); -record{}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); -record{}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); -record{}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); -record{}[] val6 = check csv:parseString(string `a, b`, {header: false}); -record{}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); -record{}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); -record{}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); -record{}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); -record{}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); -record{}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); -record{}[]|error val13 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); -record{}[]|[int...][]|error val14 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); +record {}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); +record {}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); +record {}[] val6 = check csv:parseString(string `a, b`, {header: false}); +record {}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); +record {}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); +record {}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); +record {}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); +record {}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); +record {}[]|error val13 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[]|[int...][]|error val14 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); anydata[][] arrVal = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); anydata[][] arrVal2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); @@ -35,46 +35,46 @@ anydata[][]|error arrVal13 = csv:parseString(string `a, b`, {header: 0, customHe anydata[][]|[int...][]|error arrVal14 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); public function main() returns error? { - record{}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); val = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); - record{}[]|error val_2 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[]|error val_2 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); val_2 = csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); - record{}[]|record{int a;}[]|error val_3 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[]|record {int a;}[]|error val_3 = csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); val_3 = csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); - record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); + record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); val2 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ()}); - record{}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); val3 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); - record{}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); + record {}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); val4 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ()}); - record{}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); + record {}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); val5 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ()}); - record{}[] val6 = check csv:parseString(string `a, b`, {header: false}); + record {}[] val6 = check csv:parseString(string `a, b`, {header: false}); val6 = check csv:parseString(string ``, {header: false}); - record{}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); val7 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ["a", "b"]}); - record{}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); + record {}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); val8 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: null}); - record{}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); + record {}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); val9 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: null}); - record{}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); + record {}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); val10 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); - record{}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); + record {}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); - record{}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); + record {}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); val11 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); anydata[][] arrVal = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal index ee021b2..92ae689 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal @@ -1,18 +1,18 @@ import ballerina/data.csv; boolean o = false; -record{}[] val = check csv:parseString(string `a, b`, {outputWithHeaders: false}); -record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: true}); -record{}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); -record{}[] val4 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); +record {}[] val = check csv:parseString(string `a, b`, {outputWithHeaders: false}); +record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: true}); +record {}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val4 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); public function main() returns error? { - record{}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"], outputWithHeaders: false}); + record {}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"], outputWithHeaders: false}); val = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"], outputWithHeaders: true}); - record{}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: false}); + record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: false}); val2 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: true}); - record{}[] val3 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); + record {}[] val3 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); val3 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); } diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal index 669fe19..2a4dedf 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_9/main.bal @@ -1,22 +1,22 @@ import ballerina/data.csv; boolean o = false; -string[] headersOrder = ["a", "b"]; -record{}[] val = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"], outputWithHeaders: false}); -record{}[] val2 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"]}); -record{}[] val3 = check csv:transform([{"a": 1, "b": 2}], {"header": false, headersOrder: headersOrder}); -record{}[] val4 = check csv:transform([{"a": 1, "b": 2}], {outputWithHeaders: o, headersOrder: ()}); +string[] headerOrder = ["a", "b"]; +record {}[] val = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ["a", "b"], outputWithHeaders: false}); +record {}[] val2 = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ["a", "b"]}); +record {}[] val3 = check csv:transform([{"a": 1, "b": 2}], {"header": false, headerOrder: headerOrder}); +record {}[] val4 = check csv:transform([{"a": 1, "b": 2}], {outputWithHeaders: o, headerOrder: ()}); public function main() returns error? { - record{}[] val = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ()}); - val = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ()}); + record {}[] val = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ()}); + val = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ()}); - record{}[] val2 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"], outputWithHeaders: false}); - val2 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: ["a", "b"], outputWithHeaders: true}); + record {}[] val2 = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ["a", "b"], outputWithHeaders: false}); + val2 = check csv:transform([{"a": 1, "b": 2}], {headerOrder: ["a", "b"], outputWithHeaders: true}); - record{}[] val3 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: null}); - val3 = check csv:transform([{"a": 1, "b": 2}], {headersOrder: null}); + record {}[] val3 = check csv:transform([{"a": 1, "b": 2}], {headerOrder: null}); + val3 = check csv:transform([{"a": 1, "b": 2}], {headerOrder: null}); - record{}[] val4 = check csv:transform([{"a": 1, "b": 2}], {headersOrder}); - val4 = check csv:transform([{"a": 1, "b": 2}], {headersOrder}); + record {}[] val4 = check csv:transform([{"a": 1, "b": 2}], {headerOrder}); + val4 = check csv:transform([{"a": 1, "b": 2}], {headerOrder}); } diff --git a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java index d768a0c..93e396d 100644 --- a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/Constants.java @@ -34,7 +34,7 @@ public final class Constants { static final String BALLERINA = "ballerina"; static final String DATA_CSVDATA = "data.csv"; static final String FALSE = "false"; - static final String BAL_NULL = "()"; + static final String NIL = "()"; static final String NULL = "null"; static class UserConfigurations { @@ -42,10 +42,10 @@ private UserConfigurations() { } static final String OUTPUT_WITH_HEADERS = "outputWithHeaders"; - static final String HEADERS_ORDER = "headersOrder"; + static final String HEADERS_ORDER = "headerOrder"; static final String HEADER = "header"; static final String CUSTOM_HEADERS = "customHeaders"; - static final String HEADERS_ROWS = "headersRows"; + static final String HEADERS_ROWS = "headerRows"; static final String CUSTOM_HEADERS_IF_ABSENT = "customHeadersIfHeadersAbsent"; } diff --git a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java index 5104c40..5361b38 100644 --- a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataDiagnosticCodes.java @@ -36,7 +36,7 @@ public enum CsvDataDiagnosticCodes { "be basic types, other types are not supported.", ERROR), IGNORE_OUTPUT_HEADERS_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'outputWithHeaders' will " + "be not allowed since the expected type is a subtype record array.", ERROR), - IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'headersOrder' will " + + IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY("CSV_ERROR_5", "The option 'headerOrder' will " + "be not allowed since the expected type is a subtype record array.", ERROR), IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT("CSV_ERROR_6", "The option 'customHeadersIfHeadersAbsent' will be not " + diff --git a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java index 3892956..7d33b08 100644 --- a/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/lib/data/csvdata/compiler/CsvDataTypeValidator.java @@ -71,12 +71,13 @@ import io.ballerina.tools.diagnostics.DiagnosticSeverity; import io.ballerina.tools.diagnostics.Location; -import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; /** * CsvData Record Field Validator. @@ -203,14 +204,12 @@ private void checkTypeAndDetectDuplicateFields(TypeSymbol typeSymbol, SyntaxNode } private FunctionCallExpressionNode getFunctionCallExpressionNodeIfPresent(ExpressionNode expressionNode) { - if (expressionNode.kind() == SyntaxKind.CHECK_EXPRESSION) { - expressionNode = ((CheckExpressionNode) expressionNode).expression(); - } - - if (expressionNode.kind() != SyntaxKind.FUNCTION_CALL) { - return null; - } - return ((FunctionCallExpressionNode) expressionNode); + return switch(expressionNode.kind()) { + case CHECK_EXPRESSION -> getFunctionCallExpressionNodeIfPresent( + ((CheckExpressionNode) expressionNode).expression()); + case FUNCTION_CALL -> (FunctionCallExpressionNode) expressionNode; + default -> null; + }; } private String getFunctionName(FunctionCallExpressionNode node) { @@ -265,8 +264,8 @@ private void validateFunctionParameterTypesWithExpType(TypeSymbol expType, Locat List memberTypes = ((UnionTypeSymbol) expType).memberTypeDescriptors(); // only handles the A|error scenarios - if (isUnionContainsError(memberTypes)) { - if (memberTypes.size() == 2) { + if (memberTypes.size() == 2) { + if (isUnionContainsError(memberTypes)) { TypeSymbol nonErrorTypeSymbol = ignoreErrorTypeFromUnionTypeSymbolAndReturn(memberTypes); if (nonErrorTypeSymbol != null) { validateFunctionParameterTypesWithExpType(nonErrorTypeSymbol, currentLocation, @@ -307,7 +306,7 @@ private TypeSymbol ignoreErrorTypeFromUnionTypeSymbolAndReturn(List private void validateFunctionParameterTypesWithArrayType(ArrayTypeSymbol expType, Location currentLocation, SyntaxNodeAnalysisContext ctx, String functionName, - SeparatedNodeList args) { + SeparatedNodeList args) { TypeSymbol memberTypeSymbol = expType.memberTypeDescriptor(); if (memberTypeSymbol.typeKind() == TypeDescKind.TYPE_REFERENCE) { memberTypeSymbol = ((TypeReferenceTypeSymbol) memberTypeSymbol).typeDescriptor(); @@ -324,10 +323,11 @@ private void validateFunctionParameterTypesWithOptions(Location currentLocation, String functionName, SeparatedNodeList args, boolean isRecord) { ExpressionNode expression; SeparatedNodeList fields; - String header = null, headersRows = null, customHeaders = null, - customHeadersIfHeaderAbsent = null, outputWithHeaders = null, headersOrder = null; + String header = null, headerRows = null, customHeaders = null, + customHeadersIfHeaderAbsent = null, outputWithHeaders = null, headerOrder = null; boolean isCustomHeaderPresent = false; for (FunctionArgumentNode arg : args) { + int mappingConstructorExprNodeCount = 0; if (arg instanceof PositionalArgumentNode positionalArgumentNode) { expression = positionalArgumentNode.expression(); } else if (arg instanceof NamedArgumentNode namedArgumentNode) { @@ -336,6 +336,7 @@ private void validateFunctionParameterTypesWithOptions(Location currentLocation, continue; } if (expression instanceof MappingConstructorExpressionNode mappingConstructorExpressionNode) { + checkAndAssertMappingConstructorArguments(mappingConstructorExprNodeCount); fields = mappingConstructorExpressionNode.fields(); for (MappingFieldNode field : fields) { if (field instanceof SpecificFieldNode specificFieldNode) { @@ -349,14 +350,14 @@ private void validateFunctionParameterTypesWithOptions(Location currentLocation, customHeadersIfHeaderAbsent = getTheValueOfTheUserConfigOption(specificFieldNode); } if (fieldName.equals(Constants.UserConfigurations.HEADERS_ROWS)) { - headersRows = getTheValueOfTheUserConfigOption(specificFieldNode); + headerRows = getTheValueOfTheUserConfigOption(specificFieldNode); } if (fieldName.equals(Constants.UserConfigurations.CUSTOM_HEADERS)) { customHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); isCustomHeaderPresent = true; } if (isRecord && fieldName.equals(Constants.UserConfigurations.HEADERS_ORDER)) { - headersOrder = getTheValueOfTheUserConfigOption(specificFieldNode); + headerOrder = getTheValueOfTheUserConfigOption(specificFieldNode); } if (isRecord && fieldName.equals(Constants.UserConfigurations.OUTPUT_WITH_HEADERS)) { outputWithHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); @@ -366,30 +367,37 @@ private void validateFunctionParameterTypesWithOptions(Location currentLocation, } } } - throwErrorsIfIgnoredFieldFoundForOutputs(header, customHeadersIfHeaderAbsent, headersRows, - customHeaders, isCustomHeaderPresent, headersOrder, + throwErrorsIfIgnoredFieldFoundForOutputs(header, customHeadersIfHeaderAbsent, headerRows, + customHeaders, isCustomHeaderPresent, headerOrder, outputWithHeaders, ctx, currentLocation, functionName, isRecord); } + private void checkAndAssertMappingConstructorArguments(int mappingConstructorExprNodeCount) { + if (mappingConstructorExprNodeCount > 1) { + assert false : "MappingConstructorExpressionNode count in the function " + + "arguments should be less than or equal to 1"; + } + } + private void throwErrorsIfIgnoredFieldFoundForOutputs(String header, String customHeadersIfHeaderAbsent, - String headersRows, String customHeaders, boolean isCustomHeaderPresent, String headersOrder, + String headerRows, String customHeaders, boolean isCustomHeaderPresent, String headerOrder, String outputWithHeaders, SyntaxNodeAnalysisContext ctx, Location currentLocation, String functionName, boolean isRecord) { if (functionName.equals(Constants.PARSE_STRING) && header != null && !header.equals(Constants.FALSE) - && customHeadersIfHeaderAbsent != null && !customHeadersIfHeaderAbsent.equals(Constants.BAL_NULL) + && customHeadersIfHeaderAbsent != null && !customHeadersIfHeaderAbsent.equals(Constants.NIL) && !customHeadersIfHeaderAbsent.equals(Constants.NULL)) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); } - if (functionName.equals(Constants.PARSE_LISTS) && headersRows != null - && !headersRows.equals("0") && !headersRows.equals("1") && - (!isCustomHeaderPresent || (customHeaders != null && (customHeaders.equals(Constants.BAL_NULL) + if (functionName.equals(Constants.PARSE_LISTS) && headerRows != null + && !headerRows.equals("0") && !headerRows.equals("1") && + (!isCustomHeaderPresent || (customHeaders != null && (customHeaders.equals(Constants.NIL) || customHeaders.equals(Constants.NULL))))) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.CUSTOM_HEADERS_SHOULD_BE_PROVIDED); } - if (isRecord && functionName.equals(Constants.TRANSFORM) && headersOrder != null - && !headersOrder.equals(Constants.BAL_NULL) && !headersOrder.equals(Constants.NULL)) { + if (isRecord && functionName.equals(Constants.TRANSFORM) && headerOrder != null + && !headerOrder.equals(Constants.NIL) && !headerOrder.equals(Constants.NULL)) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY); } @@ -410,7 +418,7 @@ private String getTheValueOfTheUserConfigOption(SpecificFieldNode specificFieldN return listConstructorExpressionNode.expressions().toString(); } if (expNode instanceof NilLiteralNode) { - return Constants.BAL_NULL; + return Constants.NIL; } } return null; @@ -432,8 +440,8 @@ private void validateTupleType(Location currentLocation, SyntaxNodeAnalysisConte reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); } - private void validateArrayType(ArrayTypeSymbol typeSymbol, Location currentLocation - , SyntaxNodeAnalysisContext ctx) { + private void validateArrayType(ArrayTypeSymbol typeSymbol, + Location currentLocation, SyntaxNodeAnalysisContext ctx) { if (!isSupportedArrayMemberType(ctx, currentLocation, typeSymbol.memberTypeDescriptor())) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), CsvDataDiagnosticCodes.UNSUPPORTED_TYPE); } @@ -592,7 +600,7 @@ private void validateRecordTypeDefinition(TypeDefinitionNode typeDefinitionNode, } private void detectDuplicateFields(RecordTypeSymbol recordTypeSymbol, SyntaxNodeAnalysisContext ctx) { - List fieldMembers = new ArrayList<>(); + Set fieldMembers = new HashSet<>(); for (Map.Entry entry : recordTypeSymbol.fieldDescriptors().entrySet()) { RecordFieldSymbol fieldSymbol = entry.getValue(); String name = getNameFromAnnotation(entry.getKey(), fieldSymbol.annotAttachments()); diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java index 8b22db5..16bdeee 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java @@ -257,11 +257,11 @@ private static BDecimal stringToDecimal(String value, CsvConfig config) throws N } private static Object stringToBoolean(String value) throws NumberFormatException { - if ("true".equalsIgnoreCase(value) || "TRUE".equalsIgnoreCase(value)) { + if ("true".equals(value) || "TRUE".equals(value)) { return true; } - if ("false".equalsIgnoreCase(value) || "FALSE".equalsIgnoreCase(value)) { + if ("false".equals(value) || "FALSE".equals(value)) { return false; } return returnError(value, "boolean"); diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java index 05f3ecf..23b054d 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvCreator.java @@ -87,27 +87,24 @@ static void convertAndUpdateCurrentCsvNode(CsvParser.StateMachine sm, Type currentCsvNodeType = TypeUtils.getType(currentCsv); switch (currentCsvNodeType.getTag()) { - case TypeTags.MAP_TAG: - case TypeTags.RECORD_TYPE_TAG: + case TypeTags.MAP_TAG, TypeTags.RECORD_TYPE_TAG -> { ((BMap) currentCsv).put(StringUtils.fromString(getHeaderValueForColumnIndex(sm)), convertedValue); sm.currentCsvNodeLength++; - return; - case TypeTags.ARRAY_TAG: + } + case TypeTags.ARRAY_TAG -> { ArrayType arrayType = (ArrayType) currentCsvNodeType; if (arrayType.getState() == ArrayType.ArrayState.CLOSED && arrayType.getSize() - 1 < sm.columnIndex) { sm.isColumnMaxSizeReached = true; - return; } ((BArray) currentCsv).add(sm.columnIndex, convertedValue); sm.currentCsvNodeLength++; - return; - case TypeTags.TUPLE_TAG: + } + case TypeTags.TUPLE_TAG -> { ((BArray) currentCsv).add(sm.columnIndex, convertedValue); sm.currentCsvNodeLength++; - return; - default: + } } } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java index 5916908..7f0ee66 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvParser.java @@ -150,6 +150,8 @@ static class StateMachine { boolean isColumnMaxSizeReached = false; boolean isRowMaxSizeReached = false; + boolean isCarriageTokenPresent = false; + StateMachine() { reset(); } @@ -187,11 +189,12 @@ public void reset() { currentCsvNodeLength = 0; isColumnMaxSizeReached = false; isRowMaxSizeReached = false; + isCarriageTokenPresent = false; } - private static boolean isWhitespace(char ch, Object lineTerminator) { + private boolean isWhitespace(char ch, Object lineTerminator) { return ch == SPACE || ch == HZ_TAB || ch == CR - || CsvUtils.isCharContainsInLineTerminatorUserConfig(ch, lineTerminator); + || CsvUtils.isCharContainsInLineTerminatorUserConfig(ch, lineTerminator, isCarriageTokenPresent); } private static void throwExpected(String... chars) throws CsvParserException { @@ -344,7 +347,8 @@ private void append(char ch) { } private boolean isNewLineOrEof(char ch) { - return ch == EOF || CsvUtils.isCharContainsInLineTerminatorUserConfig(ch, config.lineTerminator); + return ch == EOF || CsvUtils.isCharContainsInLineTerminatorUserConfig(ch, + config.lineTerminator, isCarriageTokenPresent); } private void growCharBuff() { @@ -380,10 +384,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return HEADER_END_STATE; } if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); + sm.isCarriageTokenPresent = true; continue; - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = true; } if (sm.lineNumber < headerStartRowNumber) { @@ -418,7 +422,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C } else if (!sm.insideComment && isEndOfTheHeaderRow(sm, ch)) { handleEndOfTheHeader(sm); state = HEADER_END_STATE; - } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { + } else if (sm.isWhitespace(ch, sm.config.lineTerminator)) { if (sm.isValueStart) { sm.append(ch); } @@ -555,10 +559,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { continue; } if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); + sm.isCarriageTokenPresent = true; continue; - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = false; } if (sm.skipTheRow) { @@ -612,7 +616,7 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { state = ROW_END_STATE; break; } - } else if (StateMachine.isWhitespace(ch, sm.config.lineTerminator)) { + } else if (sm.isWhitespace(ch, sm.config.lineTerminator)) { if (sm.isValueStart) { sm.append(ch); } @@ -865,10 +869,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) { return ROW_END_STATE; } if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); + sm.isCarriageTokenPresent = true; continue; - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = false; } if (ch == sm.config.textEnclosure) { @@ -931,10 +935,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) return ROW_END_STATE; } if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); + sm.isCarriageTokenPresent = true; continue; - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = false; } if (ch == sm.config.textEnclosure) { @@ -1016,10 +1020,10 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C return ROW_END_STATE; } if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); + sm.isCarriageTokenPresent = true; continue; - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = false; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) { @@ -1096,9 +1100,9 @@ public State transition(StateMachine sm, char[] buff, int i, int count) throws C ch = buff[i]; sm.processLocation(ch); if (ch == Constants.LineTerminator.CR) { - CsvUtils.setCarriageTokenPresent(true); - } else if (!(CsvUtils.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { - CsvUtils.setCarriageTokenPresent(false); + sm.isCarriageTokenPresent = true; + } else if (!(sm.isCarriageTokenPresent && ch == Constants.LineTerminator.LF)) { + sm.isCarriageTokenPresent = false; } if (ch == EOF) { handleEndOfTheRow(sm); diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java index 625ceea..61e4a4c 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/csv/CsvTraversal.java @@ -199,11 +199,9 @@ private Optional handleNonUnionIntersections(Type referredType, BArray c if (referredType.getTag() == TypeTags.ARRAY_TAG) { Type arrayElementType = TypeUtils.getReferredType(((ArrayType) referredType).getElementType()); if (arrayElementType.getTag() == TypeTags.INTERSECTION_TAG) { - Optional mutableType = CsvUtils.getMutableType((IntersectionType) arrayElementType); - if (mutableType.isPresent()) { - return Optional.of(CsvCreator.constructReadOnlyValue(traverseCsv(csv, - config, TypeCreator.createArrayType(mutableType.get())))); - } + return CsvUtils.getMutableType((IntersectionType) arrayElementType) + .map(mutableType -> CsvCreator.constructReadOnlyValue( + traverseCsv(csv, config, TypeCreator.createArrayType(mutableType)))); } } return Optional.empty(); @@ -273,11 +271,11 @@ public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type e } Object o = csv.get(i); - if (i < config.headersRows && i != config.headersRows - 1) { + if (i < config.headerRows && i != config.headerRows - 1) { continue; } - if (i >= config.headersRows && ignoreRow(rowNumber + 1, config.skipLines)) { + if (i >= config.headerRows && ignoreRow(rowNumber + 1, config.skipLines)) { rowNumber++; continue; } @@ -291,7 +289,7 @@ public void traverseCsvWithMappingAsExpectedType(long length, BArray csv, Type e rootCsvNode.add(this.arraySize, rowValue); this.arraySize++; } - if (i >= config.headersRows) { + if (i >= config.headerRows) { rowNumber++; } } @@ -311,11 +309,11 @@ public void traverseCsvWithListAsExpectedType(long length, BArray csv, Type expe Object o = csv.get(i); if (!addHeadersForOutput && config.outputWithHeaders - && (o instanceof BMap || (config.customHeaders != null || i == config.headersRows - 1))) { + && (o instanceof BMap || (config.customHeaders != null || i == config.headerRows - 1))) { // Headers will add to the list only in the first iteration insertHeaderValuesForTheCsvIfApplicable(o, expectedArrayType); } - if (i < config.headersRows) { + if (i < config.headerRows) { continue; } @@ -348,7 +346,7 @@ public void traverseCsvWithUnionExpectedType(BArray csv, resetForUnionTypes(); } } - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_UNION_CONVERSION, type); + throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); } private static boolean ignoreRow(int index, Object skipLinesConfig) { @@ -417,7 +415,7 @@ private void traverseCsvRowWithListAsExpectedType(Object csvElement, Type type) private void constructCsvArrayFromMapping(BMap map, Type type, int expectedSize) { int index = 0; - BString[] keys = generateCsvHeadersForMappingRow(map, config.headersOrder, map.size()); + BString[] keys = generateCsvHeadersForMappingRow(map, config.headerOrder, map.size()); for (BString key: keys) { if (!map.containsKey(key)) { throw DiagnosticLog.error(DiagnosticErrorCode.HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED, key); @@ -473,8 +471,8 @@ private void constructCsvMapFromNonMapping(BArray csvElement, String[] headers = new String[csvElement.size()]; if (this.headers == null) { this.headers = CsvUtils.createHeadersForParseLists(csvElement, headers, config); - if (!this.isFirstRowInserted && config.headersRows >= 1) { - // To skip the row at the position [config.headersRows - 1] from being aded to the result. + if (!this.isFirstRowInserted && config.headerRows >= 1) { + // To skip the row at the position [config.headerRows - 1] from being aded to the result. this.isFirstRowIsHeader = true; this.isFirstRowInserted = true; return; @@ -485,7 +483,7 @@ private void constructCsvMapFromNonMapping(BArray csvElement, throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_CONVERSION_FOR_ARRAY_TO_MAP, csvElement, expectedType); } - constructCsvMappingRow(csvElement, arraySize, mappingType, expectedType); + insertCsvMappingRow(csvElement, arraySize, mappingType, expectedType); } private void constructCsvMapFromMapping( @@ -517,7 +515,7 @@ private void insertHeaderValuesForTheCsvIfApplicable(Object obj, Type type) { if (this.headers == null && obj instanceof BMap) { BMap map = (BMap) obj; int size = map.size(); - BString[] headerArray = generateCsvHeadersForMappingRow(map, config.headersOrder, size); + BString[] headerArray = generateCsvHeadersForMappingRow(map, config.headerOrder, size); this.headers = new String[size]; for (int i = 0; i < headerArray.length; i++) { this.headers[i] = StringUtils.getStringValue(headerArray[i]); @@ -550,10 +548,10 @@ private void insertHeaderValuesForTheCsvIfApplicable(Object obj, Type type) { } } - private BString[] generateCsvHeadersForMappingRow(BMap map, Object headersOrder, int size) { + private BString[] generateCsvHeadersForMappingRow(BMap map, Object headerOrder, int size) { BString[] keys = new BString[size]; - if (headersOrder != null) { - String[] order = ((BArray) headersOrder).getStringArray(); + if (headerOrder != null) { + String[] order = ((BArray) headerOrder).getStringArray(); if (order.length != size) { throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_HEADER_NAMES_LENGTH); } @@ -670,7 +668,7 @@ private boolean validateHeadersWithArrayDataRows(Type expectedType) { return false; } - private void constructCsvMappingRow(BArray csvElement, int arraySize, boolean mappingType, Type expectedType) { + private void insertCsvMappingRow(BArray csvElement, int arraySize, boolean mappingType, Type expectedType) { Type fieldType; BString key; if (arraySize != this.headers.length) { diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java index 4cd1749..f2ad47b 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/Constants.java @@ -27,11 +27,11 @@ public static final class ConfigConstants { public static final BString ENABLE_CONSTRAINT_VALIDATION = StringUtils. fromString("enableConstraintValidation"); public static final BString OUTPUT_WITH_HEADERS = StringUtils.fromString("outputWithHeaders"); - public static final BString HEADER_ROWS = StringUtils.fromString("headersRows"); + public static final BString HEADER_ROWS = StringUtils.fromString("headerRows"); public static final BString CUSTOM_HEADERS_IF_HEADER_ABSENT = StringUtils.fromString("customHeadersIfHeadersAbsent"); public static final BString CUSTOM_HEADERS = StringUtils.fromString("customHeaders"); - public static final BString HEADERS_ORDER = StringUtils.fromString("headersOrder"); + public static final BString HEADERS_ORDER = StringUtils.fromString("headerOrder"); private ConfigConstants() { } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java index eae6a63..cf1c64c 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvConfig.java @@ -22,12 +22,12 @@ public class CsvConfig { public boolean nilAsOptionalField = false; public boolean absentAsNilableType = false; public boolean allowDataProjection = true; - public Object headersOrder = null; + public Object headerOrder = null; public boolean stringConversion = false; public boolean enableConstraintValidation = false; public boolean outputWithHeaders = false; public Object customHeadersIfHeadersAbsent = null; - public long headersRows = 0; + public long headerRows = 0; public Object customHeaders = null; private CsvConfig(CsvConfig config) { @@ -58,14 +58,14 @@ public static CsvConfig createParseListOptions(BMap options) { public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, Object skipLines, boolean enableConstraintValidation, boolean outputWithHeaders, - long headersRows, Object headers) { + long headerRows, Object headers) { this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; this.skipLines = skipLines; this.enableConstraintValidation = enableConstraintValidation; this.outputWithHeaders = outputWithHeaders; - this.headersRows = headersRows; + this.headerRows = headerRows; this.customHeaders = headers; } @@ -84,14 +84,14 @@ public static CsvConfig createTransformOptions(BMap options) { public CsvConfig(boolean nilAsOptionalField, boolean absentAsNilableType, boolean allowDataProjection, Object skipLines, boolean enableConstraintValidation, boolean outputWithHeaders, - Object headersOrder) { + Object headerOrder) { this.nilAsOptionalField = nilAsOptionalField; this.absentAsNilableType = absentAsNilableType; this.allowDataProjection = allowDataProjection; this.skipLines = skipLines; this.enableConstraintValidation = enableConstraintValidation; this.outputWithHeaders = outputWithHeaders; - this.headersOrder = headersOrder; + this.headerOrder = headerOrder; } public static CsvConfig createParseOptions(BMap options) { diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java index 917771f..2c63f34 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/CsvUtils.java @@ -31,11 +31,6 @@ */ public class CsvUtils { private static final long[] EMPTY_LONG_ARRAY = new long[]{}; - public static boolean isCarriageTokenPresent = false; - - public static void setCarriageTokenPresent(boolean isCarriageTokenPresent) { - CsvUtils.isCarriageTokenPresent = isCarriageTokenPresent; - } public static void validateExpectedArraySize(int size, int currentSize) { if (size != -1 && size > currentSize) { @@ -65,7 +60,7 @@ public static boolean isBasicType(Type type) { public static String[] createHeadersForParseLists(BArray csvElement, String[] headers, CsvConfig config) { Object customHeaders = config.customHeaders; - long headersRows = config.headersRows; + long headerRows = config.headerRows; int length = headers.length; if (customHeaders instanceof BArray array) { @@ -78,15 +73,15 @@ public static String[] createHeadersForParseLists(BArray csvElement, String[] he return headers; } - if (headersRows == 1) { + if (headerRows == 1) { return csvElement.getStringArray(); } - if (headersRows > 1) { + if (headerRows > 1) { throw DiagnosticLog.error(DiagnosticErrorCode.NO_CUSTOM_HEADER_PROVIDED); } - // when headersRows = 0 and customHeaders = null + // when headerRows = 0 and customHeaders = null for (int i = 0; i < length; i++) { headers[i] = String.valueOf(i + 1); } @@ -133,37 +128,36 @@ public static boolean isHeaderFieldsEmpty(Map currentField) { public static boolean checkTypeCompatibility(Type constraintType, Object csv, boolean stringConversion) { int tag = constraintType.getTag(); if (csv instanceof BString) { - if (stringConversion || tag == TypeTags.STRING_TAG - || tag == TypeTags.CHAR_STRING_TAG || isJsonOrAnyDataOrAny(tag)) { + if (stringConversion || TypeTags.isStringTypeTag(tag) || isJsonOrAnyDataOrAny(tag)) { return true; } + return false; } if (csv instanceof Long) { - if (tag == TypeTags.INT_TAG - || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.BYTE_TAG - || tag == TypeTags.SIGNED8_INT_TAG || tag == TypeTags.SIGNED16_INT_TAG - || tag == TypeTags.SIGNED32_INT_TAG || tag == TypeTags.UNSIGNED8_INT_TAG - || tag == TypeTags.UNSIGNED16_INT_TAG || tag == TypeTags.UNSIGNED32_INT_TAG - || isJsonOrAnyDataOrAny(tag)) { + if (TypeTags.isIntegerTypeTag(tag) || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG + || tag == TypeTags.BYTE_TAG || isJsonOrAnyDataOrAny(tag)) { return true; } + return false; } if (csv instanceof BDecimal) { if ((tag == TypeTags.DECIMAL_TAG - || tag == TypeTags.FLOAT_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag)) { + || tag == TypeTags.FLOAT_TAG || TypeTags.isIntegerTypeTag(tag)) || isJsonOrAnyDataOrAny(tag)) { return true; } } if (csv instanceof Double) { if ((tag == TypeTags.FLOAT_TAG - || tag == TypeTags.DECIMAL_TAG || tag == TypeTags.INT_TAG) || isJsonOrAnyDataOrAny(tag)) { + || tag == TypeTags.DECIMAL_TAG || TypeTags.isIntegerTypeTag(tag)) || isJsonOrAnyDataOrAny(tag)) { return true; } + return false; } if (csv instanceof Boolean) { if (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag)) { return true; } + return false; } if (csv == null) { return tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag); @@ -262,20 +256,18 @@ public static long[] getSkipLinesFromStringConfigValue(String configValue) { } public static long[] getSkipDataRows(Object skipLines) { - long[] skipDataRows; if (skipLines == null) { return EMPTY_LONG_ARRAY; } + if (skipLines instanceof BArray skipLinesArray) { if (skipLinesArray.getLength() == 0) { return EMPTY_LONG_ARRAY; } - skipDataRows = skipLinesArray.getIntArray(); - return skipDataRows; + return skipLinesArray.getIntArray(); } - skipDataRows = getSkipLinesFromStringConfigValue(StringUtils.getStringValue(skipLines)); - return skipDataRows; + return getSkipLinesFromStringConfigValue(StringUtils.getStringValue(skipLines)); } public static boolean isNullValue(Object nullValue, Object value) { @@ -299,11 +291,12 @@ private static boolean handleStringNullValue(Object nullValue, String v, Object return nullValue != null && value.equals(StringUtils.getStringValue(nullValue)); } - public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object lineTerminatorObj) { + public static boolean isCharContainsInLineTerminatorUserConfig(char c, + Object lineTerminatorObj, boolean isCarriageTokenPresent) { if (lineTerminatorObj instanceof BArray array) { Object[] lineTerminators = array.getValues(); for (Object lineTerminator: lineTerminators) { - Optional value = handleLineTerminator(lineTerminator, c); + Optional value = handleLineTerminator(lineTerminator, c, isCarriageTokenPresent); if (value.isEmpty()) { continue; } @@ -324,18 +317,19 @@ public static boolean isCharContainsInLineTerminatorUserConfig(char c, Object li return false; } - private static Optional handleLineTerminator(Object lineTerminator, char c) { - if (lineTerminator != null && c == Constants.LineTerminator.LF) { - String lineTerminatorString = lineTerminator.toString(); - if (isCarriageTokenPresent) { - if (lineTerminatorString.equals(Constants.LineTerminator.CRLF)) { - return Optional.of(true); - } - return Optional.empty(); + private static Optional handleLineTerminator(Object lineTerminator, + char c, boolean isCarriageTokenPresent) { + if (lineTerminator == null || c != Constants.LineTerminator.LF) { + return Optional.empty(); + } + String lineTerminatorString = lineTerminator.toString(); + if (isCarriageTokenPresent) { + if (lineTerminatorString.equals(Constants.LineTerminator.CRLF)) { + return Optional.of(true); } - return Optional.of(true); + return Optional.empty(); } - return Optional.empty(); + return Optional.of(true); } public static class UnMappedValue { @@ -361,9 +355,10 @@ public static SkipMappedValue createSkippedValue() { public static Locale createLocaleFromString(String localeString) { // Split the string into language, country, and variant String[] parts = localeString.split(Constants.UNDERSCORE); - if (parts.length == 3) { + int length = parts.length; + if (length == 3) { return new Locale(parts[0], parts[1], parts[2]); - } else if (parts.length == 2) { + } else if (length == 2) { return new Locale(parts[0], parts[1]); } else { return new Locale(parts[0]); // Only language @@ -371,7 +366,7 @@ public static Locale createLocaleFromString(String localeString) { } public static void validateConfigs(CsvConfig config) { - if (config.headersRows > 1 && config.customHeaders == null) { + if (config.headerRows > 1 && config.customHeaders == null) { throw DiagnosticLog.error(DiagnosticErrorCode.NO_CUSTOM_HEADER_PROVIDED); } } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java index 00258d3..b509a24 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DataUtils.java @@ -26,11 +26,11 @@ public static Object validateConstraints(Object convertedValue, BTypedesc typed, } private static String getPrintableErrorMsg(BError err) { - String errorMsg = err.getMessage() != null ? err.getMessage() : ""; + StringBuilder errorBuilder = new StringBuilder(err.getMessage() != null ? err.getMessage() : ""); Object details = err.getDetails(); if (details != null && !details.toString().equals("{}")) { - errorMsg += !errorMsg.isBlank() ? ", " : "" + details; + errorBuilder.append(!errorBuilder.isEmpty() ? ", " : "" + details); } - return errorMsg; + return errorBuilder.toString(); } } diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java index f29bced..82df3a5 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/utils/DiagnosticErrorCode.java @@ -55,8 +55,7 @@ public enum DiagnosticErrorCode { HEADERS_WITH_VARYING_LENGTH_NOT_SUPPORTED("BDE_0027", "headers.with.varying.length.not.supported"), HEADER_VALUE_CANNOT_BE_EMPTY("BDE_0028", "header.value.cannot.be.empty"), - DUPLICATE_HEADER("BDE_0029", "duplicate.header"), - INVALID_UNION_CONVERSION("BDE_0029", "invalid.union.conversion"); + DUPLICATE_HEADER("BDE_0029", "duplicate.header"); String diagnosticId; String messageKey; diff --git a/native/src/main/resources/csv_error.properties b/native/src/main/resources/csv_error.properties index 2afb2e2..96cc250 100644 --- a/native/src/main/resources/csv_error.properties +++ b/native/src/main/resources/csv_error.properties @@ -70,46 +70,43 @@ error.invalid.configurations=\ invalid configurations: ''{0}'' error.invalid.format.for.skiplines=\ - Invalid format for the skipLines field. Expected format: 'start-end' + invalid format for the skipLines field. Expected format: 'start-end' error.invalid.range.for.skiplines=\ - Invalid range for the skipLines field. Start value must be less than or equal to end value. + invalid range for the skipLines field. Start value must be less than or equal to end value. error.invalid.value.for.skiplines=\ - Invalid input for the skipLines field. Both start and end values must be integers. + invalid input for the skipLines field. Both start and end values must be integers. error.inconsistent.header=\ - Header ''{0}'' cannot be find in data rows + header ''{0}'' cannot be found in data rows error.invalid.custom.header.length=\ - Invalid number of headers + invalid number of headers error.invalid.header.names.length=\ - Invalid number of headers + invalid number of headers error.header.cannot.be.empty=\ - The provided header row is empty + provided header row is empty error.no.field.for.header=\ - No mapping field in the expected type for header ''{0}'' + no mapping field in the expected type for header ''{0}'' error.duplicate.field=\ - Duplicate field found in record fields: ''{0}'' + duplicate field found in record fields: ''{0}'' error.cannot.convert.into.exptype=\ - The source value cannot convert in to the ''{0}'' + source value cannot converted in to the ''{0}'' error.no.custom.header.provided=\ - Custom headers should be provided + custom headers should be provided error.headers.with.varying.length.not.supported=\ CSV data rows with varying headers are not yet supported error.header.value.cannot.be.empty=\ - Header cannot be empty + header cannot be empty error.duplicate.header=\ - Duplicate header found: ''{0}'' - -error.invalid.union.conversion=\ - The CSV cannot be converted into any of the uniform union types in ''{0}'' + duplicate header found: ''{0}'' From 6794717fb91461c4f2ee83590dea5a20c583d417 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Mon, 9 Sep 2024 12:05:33 +0530 Subject: [PATCH 145/147] Update header parameter to be in nillable type --- .../tests/constraint_validation_test.bal | 6 +- .../tests/parse_string_to_array_test.bal | 10 +- .../user_config_with_parser_options_test.bal | 36 ++-- .../user-config-tests/tests/user_configs.bal | 4 +- ballerina/types.bal | 2 +- .../sample_package_7/main.bal | 50 ++--- .../sample_package_8/main.bal | 2 +- .../lib/data/csvdata/compiler/Constants.java | 1 - .../compiler/CsvDataTypeValidator.java | 171 +++++++++--------- .../lib/data/csvdata/FromString.java | 42 +++-- .../lib/data/csvdata/csv/CsvCreator.java | 2 +- .../lib/data/csvdata/csv/CsvParser.java | 2 +- .../lib/data/csvdata/csv/CsvTraversal.java | 58 +++--- .../lib/data/csvdata/utils/CsvUtils.java | 66 ++----- 14 files changed, 207 insertions(+), 245 deletions(-) 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 56db0c6..577f783 100644 --- a/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal +++ b/ballerina-tests/constraint-validation-tests/tests/constraint_validation_test.bal @@ -38,7 +38,7 @@ function testConstraintWithLists() returns error? { ConstrainedList|csv:Error cList1 = csv:parseString(string `1 2 3 - 4`, {header: false, customHeadersIfHeadersAbsent: ["a", "b", "c", "d"]}); + 4`, {header: (), customHeadersIfHeadersAbsent: ["a", "b", "c", "d"]}); test:assertEquals(cList1, [[1], [2], [3], [4]]); cList1 = csv:parseString(string `1 @@ -46,7 +46,7 @@ function testConstraintWithLists() returns error? { 3 4 5 - 6`, {header: false, customHeadersIfHeadersAbsent: ["a", "b", "c", "d", "e", "f"]}); + 6`, {header: null, customHeadersIfHeadersAbsent: ["a", "b", "c", "d", "e", "f"]}); test:assertTrue(cList1 is csv:Error); test:assertTrue((cList1).message().startsWith("Validation failed") && (cList1).message().includes("length")); @@ -56,7 +56,7 @@ function testConstraintWithLists() returns error? { 3 4 5 - 6`, {header: false, customHeadersIfHeadersAbsent: ["a", "b", "c", "d", "e", "f"], enableConstraintValidation: false}); + 6`, {header: (), customHeadersIfHeadersAbsent: ["a", "b", "c", "d", "e", "f"], enableConstraintValidation: false}); test:assertEquals(cList1, [[1], [2], [3], [4], [5], [6]]); cList1 = csv:transform([{"a": 1}, {"a": 1}, {"a": 1}, {"a": 1}], {}); 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 10e3859..96612e2 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 @@ -435,7 +435,7 @@ function testParseStringArrayAsExpectedTypeWithOutputHeaders() { [true, false, true, false, true] ]); - string[][]|csv:Error cv1baa_4 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true, header: false}); + string[][]|csv:Error cv1baa_4 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true}); test:assertEquals(cv1baa_4, [ ["b1", "b2", "b3", "b4"], ["true", "false", "true", "false"], @@ -466,7 +466,13 @@ function testParseStringArrayAsExpectedTypeWithOutputHeaders() { [true, false, true, false, true] ]); - string[2][2]|csv:Error cv1baa_9 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true, header: false}); + string[2][2]|csv:Error cv1baa_9 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true, header: ()}); + test:assertEquals(cv1baa_9, [ + ["b1", "b2"], + ["true", "false"] + ]); + + cv1baa_9 = csv:parseString(csvStringWithBooleanValues1, {outputWithHeaders: true, header: null}); test:assertEquals(cv1baa_9, [ ["b1", "b2"], ["true", "false"] 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 8bd7397..503a922 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 @@ -145,7 +145,7 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record {}[]|csv:Error csv1op6_2 = csv:parseString(csvStringData1, {header: false, skipLines: [3, 5]}); + record {}[]|csv:Error csv1op6_2 = csv:parseString(csvStringData1, {header: null, 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: ()}, @@ -153,35 +153,35 @@ function testFromCsvStringWithHeaderLessParserOptions() { {'1: 5, '2: "string5", '3: true, '4: 3, '5: 3, '6: ()} ]); - record {}[]|csv:Error csv3op6_2 = csv:parseString(csvStringData3, {header: false, skipLines: [1, 3, 5, -1, 100, 100]}); + record {}[]|csv:Error csv3op6_2 = csv:parseString(csvStringData3, {header: (), 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: ()} ]); - record {}[]|csv:Error csv4op6_2 = csv:parseString(csvStringData4, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|csv:Error csv4op6_2 = csv:parseString(csvStringData4, {header: (), 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: ()} ]); - record {}[]|csv:Error csv5op6_2 = csv:parseString(csvStringData5, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|csv:Error csv5op6_2 = csv:parseString(csvStringData5, {header: null, 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: ()} ]); - record {}[]|csv:Error csv6op6_2 = csv:parseString(csvStringData6, {header: false, skipLines: [2, 4, -1, 100, 100]}); + record {}[]|csv:Error csv6op6_2 = csv:parseString(csvStringData6, {header: (), 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: ()} ]); - record {}[]|csv:Error csv2op6_2 = csv:parseString(csvStringData2, {header: false, skipLines: [5, 7]}); + record {}[]|csv:Error csv2op6_2 = csv:parseString(csvStringData2, {header: (), skipLines: [5, 7]}); test:assertEquals(csv2op6_2, [ {'1: "hello", '2: "hello", '3: (), '4: 12, '5: true, '6: 12.34}, {'1: "// comment"}, @@ -684,11 +684,11 @@ function testCustomHeaderParserOption2() { {a: 5, b: "string5", c: true, d: 3, e: 3, f: ()} ]); - record {}[]|csv:Error ct1br2 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: []}); + record {}[]|csv:Error ct1br2 = csv:parseString(csvStringData4, {header: (), customHeadersIfHeadersAbsent: []}); test:assertTrue(ct1br2 is csv:Error); test:assertEquals((ct1br2).message(), "invalid number of headers"); - record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br3 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {int a; string b; boolean c; decimal d; float e; () f;}[]|csv:Error ct1br3 = csv:parseString(csvStringData4, {header: null, customHeadersIfHeadersAbsent: ["a", "b"]}); test:assertTrue(ct1br3 is csv:Error); test:assertEquals((ct1br3).message(), "invalid number of headers"); @@ -704,7 +704,7 @@ function testCustomHeaderParserOption2() { record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5 = csv:parseString(csvStringData4, {header: 1}); test:assertTrue(ct1br5 is csv:Error); - ct1br5 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f", "e", "d", "c", "b", "a"]}); + ct1br5 = csv:parseString(csvStringData4, {header: (), customHeadersIfHeadersAbsent: ["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: ()}, @@ -713,7 +713,7 @@ function testCustomHeaderParserOption2() { {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], customHeadersIfHeadersAbsent: ["f", "e", "d", "c", "b", "a"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_2 = csv:parseString(csvStringData4, {header: null, skipLines: [1], customHeadersIfHeadersAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br5_2, [ {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, @@ -721,7 +721,7 @@ function testCustomHeaderParserOption2() { {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, customHeadersIfHeadersAbsent: ["f", "e", "d", "c", "b", "a"]}); + record {() a; float b; decimal c; boolean d; string e; int f;}[]|csv:Error ct1br5_3 = csv:parseString(csvStringData4, {skipLines: [1], header: (), customHeadersIfHeadersAbsent: ["f", "e", "d", "c", "b", "a"]}); test:assertEquals(ct1br5_3, [ {f: 2, e: "string2", d: false, c: 0, b: 0, a: ()}, {f: 3, e: "string3", d: false, c: 1.23, b: 1.23, a: ()}, @@ -729,7 +729,7 @@ function testCustomHeaderParserOption2() { {f: 5, e: "string5", d: true, c: 3, b: 3, a: ()} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br7 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br7 = csv:parseString(csvStringData4, {header: (), customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -738,7 +738,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br7_2 = csv:parseString(csvStringData4, {header: false, skipLines: [1], customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br7_2 = csv:parseString(csvStringData4, {header: null, skipLines: [1], customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br7_2, [ {e1: "string2", d1: false}, {e1: "string3", d1: false}, @@ -746,11 +746,11 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br8 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["e1", "d1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br8 = csv:parseString(csvStringData4, {header: (), customHeadersIfHeadersAbsent: ["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:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br9 = csv:parseString(csvStringData4, {header: (), customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br9, [ {e1: "string1", d1: true}, {e1: "string2", d1: false}, @@ -759,11 +759,11 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: true} ]); - record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1"]}); + record {|boolean d1; string e1;|}[]|csv:Error ct1br11 = csv:parseString(csvStringData1, {header: (), customHeadersIfHeadersAbsent: ["f1", "e1"]}); test:assertTrue(ct1br11 is csv:Error); test:assertEquals((ct1br11).message(), "invalid number of headers"); - record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseString(csvStringData4, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); + record {|string d1; string e1;|}[]|csv:Error ct1br12 = csv:parseString(csvStringData4, {header: null, customHeadersIfHeadersAbsent: ["f1", "e1", "d1", "c1", "b1", "a1"]}); test:assertEquals(ct1br12, [ {e1: "string1", d1: "true"}, {e1: "string2", d1: "false"}, @@ -772,7 +772,7 @@ function testCustomHeaderParserOption2() { {e1: "string5", d1: "true"} ]); - record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseString(csvStringData1, {header: false, customHeadersIfHeadersAbsent: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); + record {|string d1; string e1;|}[]|csv:Error ct1br13 = csv:parseString(csvStringData1, {header: (), customHeadersIfHeadersAbsent: ["f1", "e1", "dd1", "c1", "b1", "a1"]}); test:assertTrue(ct1br13 is csv:Error); test:assertEquals((ct1br13).message(), common:generateErrorMessageForMissingRequiredField("d1")); } diff --git a/ballerina-tests/user-config-tests/tests/user_configs.bal b/ballerina-tests/user-config-tests/tests/user_configs.bal index 8a38db6..43312a5 100644 --- a/ballerina-tests/user-config-tests/tests/user_configs.bal +++ b/ballerina-tests/user-config-tests/tests/user_configs.bal @@ -22,13 +22,13 @@ final csv:ParseOptions option2 = {nilValue: "N/A", lineTerminator: [csv:CRLF, cs final csv:ParseOptions option3 = {nilValue: "()", header: 1, skipLines: [1, 2]}; final csv:ParseOptions option4 = {nilValue: "", header: 4, skipLines: "1-5"}; final csv:ParseOptions option5 = {nilValue: "", header: 4, skipLines: "1-1"}; -final csv:ParseOptions option6 = {nilValue: "()", header: false, skipLines: [1, 2]}; +final csv:ParseOptions option6 = {nilValue: "()", header: (), skipLines: [1, 2]}; final csv:ParseOptions ptOption1 = {nilValue: "", header: 1, skipLines: [2, 4]}; final csv:ParseOptions ptOption2 = {nilValue: "", header: 1, skipLines: "2-4"}; final csv:ParseOptions ptOption3 = {nilValue: "", header: 4, skipLines: "1-5"}; final csv:ParseOptions ptOption4 = {nilValue: "", header: 4, skipLines: [-1, -2, 4, 2]}; -final csv:ParseOptions ptOption5 = {header: false, skipLines: [-1, -2, 5, 3]}; +final csv:ParseOptions ptOption5 = {header: (), skipLines: [-1, -2, 5, 3]}; // Invalid parser options final csv:ParseOptions invalidParserOptions1 = {header: 4}; diff --git a/ballerina/types.bal b/ballerina/types.bal index 84b5502..c1f1095 100644 --- a/ballerina/types.bal +++ b/ballerina/types.bal @@ -68,7 +68,7 @@ public type ParseOptions record {| # 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; + int:Unsigned32? header = 0; # Custom headers for the data, if headers are absent. string[]? customHeadersIfHeadersAbsent = (); |}; diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal index 1251720..e56e0d0 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_7/main.bal @@ -2,17 +2,17 @@ import ballerina/data.csv; string[] customHeaders = ["a", "b"]; int:Unsigned32 header = 0; -false header2 = false; +()|null header2 = null; record {}[] val = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); -record {}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); -record {}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); +record {}[] val3 = check csv:parseString(string `a, b`, {header: (), customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val4 = check csv:parseString(string `a, b`, {header: null, customHeadersIfHeadersAbsent: ()}); record {}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); -record {}[] val6 = check csv:parseString(string `a, b`, {header: false}); +record {}[] val6 = check csv:parseString(string `a, b`, {header: ()}); record {}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); record {}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); -record {}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); +record {}[] val9 = check csv:parseString(string `a, b`, {header: (), customHeadersIfHeadersAbsent: null}); record {}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); record {}[] val11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); record {}[] val12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); @@ -21,13 +21,13 @@ record {}[]|[int...][]|error val14 = csv:parseString(string `a, b`, {header: 0, anydata[][] arrVal = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ["a", "b"]}); anydata[][] arrVal2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); -anydata[][] arrVal3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); -anydata[][] arrVal4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); +anydata[][] arrVal3 = check csv:parseString(string `a, b`, {header: null, customHeadersIfHeadersAbsent: ["a", "b"]}); +anydata[][] arrVal4 = check csv:parseString(string `a, b`, {header: (), customHeadersIfHeadersAbsent: ()}); anydata[][] arrVal5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); -anydata[][] arrVal6 = check csv:parseString(string `a, b`, {header: false}); +anydata[][] arrVal6 = check csv:parseString(string `a, b`, {header: ()}); anydata[][] arrVal7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); anydata[][] arrVal8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); -anydata[][] arrVal9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); +anydata[][] arrVal9 = check csv:parseString(string `a, b`, {header: null, customHeadersIfHeadersAbsent: null}); anydata[][] arrVal10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); anydata[][] arrVal11 = check csv:parseString(string `a, b`, {header: header, customHeadersIfHeadersAbsent: customHeaders}); anydata[][] arrVal12 = check csv:parseString(string ``, {header: header2, customHeadersIfHeadersAbsent: customHeaders}); @@ -47,17 +47,17 @@ public function main() returns error? { record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); val2 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ()}); - record {}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); - val3 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); + record {}[] val3 = check csv:parseString(string `a, b`, {header: (), customHeadersIfHeadersAbsent: ["a", "b"]}); + val3 = check csv:parseString(string ``, {header: (), customHeadersIfHeadersAbsent: ["a", "b"]}); - record {}[] val4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); - val4 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ()}); + record {}[] val4 = check csv:parseString(string `a, b`, {header: (), customHeadersIfHeadersAbsent: ()}); + val4 = check csv:parseString(string ``, {header: null, customHeadersIfHeadersAbsent: ()}); record {}[] val5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); val5 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ()}); - record {}[] val6 = check csv:parseString(string `a, b`, {header: false}); - val6 = check csv:parseString(string ``, {header: false}); + record {}[] val6 = check csv:parseString(string `a, b`, {header: null}); + val6 = check csv:parseString(string ``, {header: ()}); record {}[] val7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); val7 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ["a", "b"]}); @@ -65,8 +65,8 @@ public function main() returns error? { record {}[] val8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); val8 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: null}); - record {}[] val9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); - val9 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: null}); + record {}[] val9 = check csv:parseString(string `a, b`, {header: (), customHeadersIfHeadersAbsent: null}); + val9 = check csv:parseString(string ``, {header: (), customHeadersIfHeadersAbsent: null}); record {}[] val10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); val10 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); @@ -89,17 +89,17 @@ public function main() returns error? { anydata[][] arrVal2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: ()}); val2 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: ()}); - anydata[][] arrVal3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); - val3 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); + anydata[][] arrVal3 = check csv:parseString(string `a, b`, {header: (), customHeadersIfHeadersAbsent: ["a", "b"]}); + val3 = check csv:parseString(string ``, {header: (), customHeadersIfHeadersAbsent: ["a", "b"]}); - anydata[][] arrVal4 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ()}); - val4 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: ()}); + anydata[][] arrVal4 = check csv:parseString(string `a, b`, {header: (), customHeadersIfHeadersAbsent: ()}); + val4 = check csv:parseString(string ``, {header: (), customHeadersIfHeadersAbsent: ()}); anydata[][] arrVal5 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ()}); val5 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ()}); - anydata[][] arrVal6 = check csv:parseString(string `a, b`, {header: false}); - val6 = check csv:parseString(string ``, {header: false}); + anydata[][] arrVal6 = check csv:parseString(string `a, b`, {header: ()}); + val6 = check csv:parseString(string ``, {header: null}); anydata[][] arrVal7 = check csv:parseString(string `a, b`, {customHeadersIfHeadersAbsent: ["a", "b"]}); val7 = check csv:parseString(string ``, {customHeadersIfHeadersAbsent: ["a", "b"]}); @@ -107,8 +107,8 @@ public function main() returns error? { anydata[][] arrVal8 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: null}); val8 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: null}); - anydata[][] arrVal9 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: null}); - val9 = check csv:parseString(string ``, {header: false, customHeadersIfHeadersAbsent: null}); + anydata[][] arrVal9 = check csv:parseString(string `a, b`, {header: null, customHeadersIfHeadersAbsent: null}); + val9 = check csv:parseString(string ``, {header: (), customHeadersIfHeadersAbsent: null}); anydata[][] arrVal10 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); val10 = check csv:parseString(string ``, {header: 0, customHeadersIfHeadersAbsent: customHeaders}); diff --git a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal index 92ae689..6e0de16 100644 --- a/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal +++ b/compiler-plugin-test/src/test/resources/ballerina_sources/sample_package_8/main.bal @@ -3,7 +3,7 @@ import ballerina/data.csv; boolean o = false; record {}[] val = check csv:parseString(string `a, b`, {outputWithHeaders: false}); record {}[] val2 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: true}); -record {}[] val3 = check csv:parseString(string `a, b`, {header: false, customHeadersIfHeadersAbsent: ["a", "b"]}); +record {}[] val3 = check csv:parseString(string `a, b`, {header: (), customHeadersIfHeadersAbsent: ["a", "b"]}); record {}[] val4 = check csv:parseString(string `a, b`, {header: 0, customHeadersIfHeadersAbsent: (), outputWithHeaders: o}); public function main() returns error? { 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 93e396d..738e715 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 @@ -33,7 +33,6 @@ public final class Constants { static final String CSVDATA = "csv"; static final String BALLERINA = "ballerina"; static final String DATA_CSVDATA = "data.csv"; - static final String FALSE = "false"; static final String NIL = "()"; static final String NULL = "null"; 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 7d33b08..1bab458 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 @@ -76,6 +76,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; @@ -126,8 +127,8 @@ private void reset() { private void updateModulePrefix(ModulePartNode rootNode) { for (ImportDeclarationNode importDeclarationNode : rootNode.imports()) { - Optional symbol = semanticModel.symbol(importDeclarationNode); - symbol.filter(moduleSymbol -> moduleSymbol.kind() == SymbolKind.MODULE) + semanticModel.symbol(importDeclarationNode) + .filter(moduleSymbol -> moduleSymbol.kind() == SymbolKind.MODULE) .filter(moduleSymbol -> isCsvDataImport((ModuleSymbol) moduleSymbol)) .ifPresent(moduleSymbol -> modulePrefix = ((ModuleSymbol) moduleSymbol).id().modulePrefix()); } @@ -152,12 +153,9 @@ private void processAssignmentStmtNode(AssignmentStatementNode assignmentStateme return; } currentLocation = assignmentStatementNode.location(); - Optional symbol = semanticModel.symbol(assignmentStatementNode.varRef()); - if (symbol.isEmpty()) { - return; - } - TypeSymbol typeSymbol = ((VariableSymbol) symbol.get()).typeDescriptor(); - validateFunctionParameterTypes(expressionNode, typeSymbol, currentLocation, ctx); + semanticModel.symbol(assignmentStatementNode.varRef()) + .map(symbol -> ((VariableSymbol) symbol).typeDescriptor()) + .ifPresent(typeSymbol -> validateFunctionParameterTypes(expressionNode, typeSymbol, currentLocation, ctx)); } private void processLocalVarDeclNode(VariableDeclarationNode variableDeclarationNode, @@ -212,17 +210,17 @@ private FunctionCallExpressionNode getFunctionCallExpressionNodeIfPresent(Expres }; } - private String getFunctionName(FunctionCallExpressionNode node) { + private Optional getFunctionName(FunctionCallExpressionNode node) { NameReferenceNode nameReferenceNode = node.functionName(); if (nameReferenceNode.kind() != SyntaxKind.QUALIFIED_NAME_REFERENCE) { - return ""; + return Optional.empty(); } QualifiedNameReferenceNode qualifiedNameReferenceNode = (QualifiedNameReferenceNode) nameReferenceNode; String prefix = qualifiedNameReferenceNode.modulePrefix().text(); if (!prefix.equals(modulePrefix)) { - return ""; + return Optional.empty(); } - return qualifiedNameReferenceNode.identifier().text(); + return Optional.of(qualifiedNameReferenceNode.identifier().text()); } private boolean isParseFunctionOfStringSource(ExpressionNode expressionNode) { @@ -230,12 +228,12 @@ private boolean isParseFunctionOfStringSource(ExpressionNode expressionNode) { if (node == null) { return false; } - String functionName = getFunctionName(node); - 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); + Optional functionName = getFunctionName(node); + return functionName + .map(fn -> fn.contains(Constants.PARSE_STRING) || fn.contains(Constants.PARSE_BYTES) || + fn.contains(Constants.PARSE_STREAM) || fn.contains(Constants.TRANSFORM) || + fn.contains(Constants.PARSE_LISTS)) + .orElse(false); } private void validateFunctionParameterTypes(ExpressionNode expressionNode, @@ -245,9 +243,10 @@ private void validateFunctionParameterTypes(ExpressionNode expressionNode, if (node == null) { return; } - String functionName = getFunctionName(node); + Optional functionName = getFunctionName(node); SeparatedNodeList args = node.arguments(); - validateFunctionParameterTypesWithExpType(expType, currentLocation, ctx, functionName, args); + functionName.ifPresent(fn -> + validateFunctionParameterTypesWithExpType(expType, currentLocation, ctx, fn, args)); } private void validateFunctionParameterTypesWithExpType(TypeSymbol expType, Location currentLocation, @@ -343,24 +342,28 @@ private void validateFunctionParameterTypesWithOptions(Location currentLocation, Node node = specificFieldNode.fieldName(); if (node instanceof IdentifierToken identifierToken) { String fieldName = identifierToken.text(); - if (fieldName.equals(Constants.UserConfigurations.HEADER)) { - header = getTheValueOfTheUserConfigOption(specificFieldNode); - } - if (fieldName.equals(Constants.UserConfigurations.CUSTOM_HEADERS_IF_ABSENT)) { - customHeadersIfHeaderAbsent = getTheValueOfTheUserConfigOption(specificFieldNode); - } - if (fieldName.equals(Constants.UserConfigurations.HEADERS_ROWS)) { - headerRows = getTheValueOfTheUserConfigOption(specificFieldNode); - } - if (fieldName.equals(Constants.UserConfigurations.CUSTOM_HEADERS)) { - customHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); - isCustomHeaderPresent = true; - } - if (isRecord && fieldName.equals(Constants.UserConfigurations.HEADERS_ORDER)) { - headerOrder = getTheValueOfTheUserConfigOption(specificFieldNode); - } - if (isRecord && fieldName.equals(Constants.UserConfigurations.OUTPUT_WITH_HEADERS)) { - outputWithHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); + switch (fieldName) { + case Constants.UserConfigurations.HEADER -> + header = getTheValueOfTheUserConfigOption(specificFieldNode); + case Constants.UserConfigurations.CUSTOM_HEADERS_IF_ABSENT -> + customHeadersIfHeaderAbsent = + getTheValueOfTheUserConfigOption(specificFieldNode); + case Constants.UserConfigurations.HEADERS_ROWS -> + headerRows = getTheValueOfTheUserConfigOption(specificFieldNode); + case Constants.UserConfigurations.CUSTOM_HEADERS -> { + customHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); + isCustomHeaderPresent = true; + } + case Constants.UserConfigurations.HEADERS_ORDER -> { + if (isRecord) { + headerOrder = getTheValueOfTheUserConfigOption(specificFieldNode); + } + } + case Constants.UserConfigurations.OUTPUT_WITH_HEADERS -> { + if (isRecord) { + outputWithHeaders = getTheValueOfTheUserConfigOption(specificFieldNode); + } + } } } } @@ -383,23 +386,30 @@ private void throwErrorsIfIgnoredFieldFoundForOutputs(String header, String cust String headerRows, String customHeaders, boolean isCustomHeaderPresent, String headerOrder, String outputWithHeaders, SyntaxNodeAnalysisContext ctx, Location currentLocation, String functionName, boolean isRecord) { - if (functionName.equals(Constants.PARSE_STRING) && header != null && !header.equals(Constants.FALSE) - && customHeadersIfHeaderAbsent != null && !customHeadersIfHeaderAbsent.equals(Constants.NIL) - && !customHeadersIfHeaderAbsent.equals(Constants.NULL)) { - reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), - CsvDataDiagnosticCodes.IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); - } - if (functionName.equals(Constants.PARSE_LISTS) && headerRows != null - && !headerRows.equals("0") && !headerRows.equals("1") && - (!isCustomHeaderPresent || (customHeaders != null && (customHeaders.equals(Constants.NIL) - || customHeaders.equals(Constants.NULL))))) { - reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), - CsvDataDiagnosticCodes.CUSTOM_HEADERS_SHOULD_BE_PROVIDED); - } - if (isRecord && functionName.equals(Constants.TRANSFORM) && headerOrder != null - && !headerOrder.equals(Constants.NIL) && !headerOrder.equals(Constants.NULL)) { - reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), - CsvDataDiagnosticCodes.IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY); + switch (functionName) { + case Constants.PARSE_STRING -> { + if (header != null && !(header.equals(Constants.NIL) || header.equals(Constants.NULL)) + && customHeadersIfHeaderAbsent != null && !customHeadersIfHeaderAbsent.equals(Constants.NIL) + && !customHeadersIfHeaderAbsent.equals(Constants.NULL)) { + reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), + CsvDataDiagnosticCodes.IGNORE_CUSTOM_HEADERS_PARAMETER_WHEN_HEADER_PRESENT); + } + } + case Constants.PARSE_LISTS -> { + if (headerRows != null && !headerRows.equals("0") && !headerRows.equals("1") + && (!isCustomHeaderPresent || (customHeaders != null && + (customHeaders.equals(Constants.NIL) || customHeaders.equals(Constants.NULL))))) { + reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), + CsvDataDiagnosticCodes.CUSTOM_HEADERS_SHOULD_BE_PROVIDED); + } + } + case Constants.TRANSFORM -> { + if (isRecord && headerOrder != null && !headerOrder.equals(Constants.NIL) + && !headerOrder.equals(Constants.NULL)) { + reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), + CsvDataDiagnosticCodes.IGNORE_HEADERS_ORDER_FOR_RECORD_ARRAY); + } + } } if (isRecord && outputWithHeaders != null) { reportDiagnosticInfo(ctx, Optional.ofNullable(currentLocation), @@ -408,9 +418,7 @@ private void throwErrorsIfIgnoredFieldFoundForOutputs(String header, String cust } private String getTheValueOfTheUserConfigOption(SpecificFieldNode specificFieldNode) { - Optional optExpNode = specificFieldNode.valueExpr(); - if (optExpNode.isPresent()) { - ExpressionNode expNode = optExpNode.get(); + return specificFieldNode.valueExpr().map(expNode -> { if (expNode instanceof BasicLiteralNode basicLiteralNode) { return basicLiteralNode.literalToken().text(); } @@ -420,8 +428,8 @@ private String getTheValueOfTheUserConfigOption(SpecificFieldNode specificFieldN if (expNode instanceof NilLiteralNode) { return Constants.NIL; } - } - return null; + return null; + }).orElse(null); } private void validateExpectedType(TypeSymbol typeSymbol, Location currentLocation, SyntaxNodeAnalysisContext ctx) { @@ -507,11 +515,8 @@ private void validateRecordFields(SyntaxNodeAnalysisContext ctx, Location curren 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); - } + recordTypeSymbol.restTypeDescriptor().ifPresent(restSym -> + validateNestedTypeSymbols(ctx, currentLocation, restSym, true)); } private void validateNestedTypeSymbols(SyntaxNodeAnalysisContext ctx, @@ -537,14 +542,11 @@ public static TypeSymbol getRawType(TypeSymbol typeDescriptor) { } if (typeDescriptor.typeKind() == TypeDescKind.TYPE_REFERENCE) { TypeReferenceTypeSymbol typeRef = (TypeReferenceTypeSymbol) typeDescriptor; - if (typeRef.typeDescriptor().typeKind() == TypeDescKind.INTERSECTION) { - return getRawType(((IntersectionTypeSymbol) typeRef.typeDescriptor()).effectiveTypeDescriptor()); - } - TypeSymbol rawType = typeRef.typeDescriptor(); - if (rawType.typeKind() == TypeDescKind.TYPE_REFERENCE) { - return getRawType(rawType); - } - return rawType; + TypeSymbol refType = typeRef.typeDescriptor(); + return switch (refType.typeKind()) { + case TYPE_REFERENCE, INTERSECTION -> getRawType(refType); + default -> refType; + }; } return typeDescriptor; } @@ -554,9 +556,10 @@ private void reportDiagnosticInfo(SyntaxNodeAnalysisContext ctx, Optional currentLocation); DiagnosticInfo diagnosticInfo = new DiagnosticInfo(diagnosticsCodes.getCode(), diagnosticsCodes.getMessage(), diagnosticsCodes.getSeverity()); - if (pos == null || (allDiagnosticInfo.containsKey(pos) && allDiagnosticInfo.get(pos).equals(diagnosticInfo))) { + if (pos == null || Objects.equals(allDiagnosticInfo.get(pos), diagnosticInfo)) { return; } + allDiagnosticInfo.put(pos, diagnosticInfo); ctx.reportDiagnostic(DiagnosticFactory.createDiagnostic(diagnosticInfo, pos)); } @@ -591,12 +594,10 @@ private void processTypeDefinitionNode(TypeDefinitionNode typeDefinitionNode, Sy } private void validateRecordTypeDefinition(TypeDefinitionNode typeDefinitionNode, SyntaxNodeAnalysisContext ctx) { - Optional symbol = semanticModel.symbol(typeDefinitionNode); - if (symbol.isEmpty()) { - return; - } - TypeDefinitionSymbol typeDefinitionSymbol = (TypeDefinitionSymbol) symbol.get(); - detectDuplicateFields((RecordTypeSymbol) typeDefinitionSymbol.typeDescriptor(), ctx); + semanticModel.symbol(typeDefinitionNode) + .map(symbol -> (TypeDefinitionSymbol) symbol) + .ifPresent(typeDefinitionSymbol -> + detectDuplicateFields((RecordTypeSymbol) typeDefinitionSymbol.typeDescriptor(), ctx)); } private void detectDuplicateFields(RecordTypeSymbol recordTypeSymbol, SyntaxNodeAnalysisContext ctx) { @@ -604,11 +605,10 @@ private void detectDuplicateFields(RecordTypeSymbol recordTypeSymbol, SyntaxNode for (Map.Entry entry : recordTypeSymbol.fieldDescriptors().entrySet()) { RecordFieldSymbol fieldSymbol = entry.getValue(); String name = getNameFromAnnotation(entry.getKey(), fieldSymbol.annotAttachments()); - if (fieldMembers.contains(name)) { + if (!fieldMembers.add(name)) { reportDiagnosticInfo(ctx, fieldSymbol.getLocation(), CsvDataDiagnosticCodes.DUPLICATE_FIELD); return; } - fieldMembers.add(name); } } @@ -633,12 +633,7 @@ private String getNameFromAnnotation(String fieldName, } private String getAnnotModuleName(AnnotationSymbol annotation) { - Optional moduleSymbol = annotation.getModule(); - if (moduleSymbol.isEmpty()) { - return ""; - } - Optional moduleName = moduleSymbol.get().getName(); - return moduleName.orElse(""); + return annotation.getModule().flatMap(ms -> ms.getName()).orElse(""); } private boolean isCsvDataImport(ModuleSymbol moduleSymbol) { diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java index 16bdeee..c831bf9 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/FromString.java @@ -118,7 +118,7 @@ public static Object fromStringWithType(BString string, Type expType, CsvConfig fromStringWithType(string, ((IntersectionType) expType).getEffectiveType(), config); default -> returnError(value, expType.toString()); }; - } catch (NumberFormatException | ParseException e) { + } catch (ParseException | RuntimeException e) { return returnError(value, expType.toString()); } } @@ -150,7 +150,7 @@ private static Long stringToInt(String value, CsvConfig config) throws NumberFor private static int stringToByte(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); if (isIntegerValue(value, number, config.locale)) { - int intValue = parseNumberValue(value, config).intValue(); + int intValue = number.intValue(); if (isByteLiteral(intValue)) { return intValue; } @@ -162,7 +162,7 @@ private static long stringToSigned8Int(String value, CsvConfig config) throws Nu ParseException { Number number = parseNumberValue(value, config); if (isIntegerValue(value, number, config.locale)) { - long intValue = parseNumberValue(value, config).longValue(); + long intValue = number.longValue(); if (isSigned8LiteralValue(intValue)) { return intValue; } @@ -175,7 +175,7 @@ private static long stringToSigned16Int(String value, CsvConfig config) throws N Number number = parseNumberValue(value, config); if (isIntegerValue(value, number, config.locale)) { - long intValue = parseNumberValue(value, config).longValue(); + long intValue = number.longValue(); if (isSigned16LiteralValue(intValue)) { return intValue; } @@ -187,7 +187,7 @@ private static long stringToSigned32Int(String value, CsvConfig config) throws N ParseException { Number number = parseNumberValue(value, config); if (isIntegerValue(value, number, config.locale)) { - long intValue = parseNumberValue(value, config).longValue(); + long intValue = number.longValue(); if (isSigned32LiteralValue(intValue)) { return intValue; } @@ -199,7 +199,7 @@ private static long stringToUnsigned8Int(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); if (isIntegerValue(value, number, config.locale)) { - long intValue = parseNumberValue(value, config).longValue(); + long intValue = number.longValue(); if (isUnsigned8LiteralValue(intValue)) { return intValue; } @@ -211,7 +211,7 @@ private static long stringToUnsigned16Int(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); if (isIntegerValue(value, number, config.locale)) { - long intValue = parseNumberValue(value, config).longValue(); + long intValue = number.longValue(); if (isUnsigned16LiteralValue(intValue)) { return intValue; } @@ -223,7 +223,7 @@ private static long stringToUnsigned32Int(String value, CsvConfig config) throws NumberFormatException, ParseException { Number number = parseNumberValue(value, config); if (isIntegerValue(value, number, config.locale)) { - long intValue = parseNumberValue(value, config).longValue(); + long intValue = number.longValue(); if (isUnsigned32LiteralValue(intValue)) { return intValue; } @@ -231,11 +231,11 @@ private static long stringToUnsigned32Int(String value, CsvConfig config) throw new NumberFormatException(); } - private static BString stringToChar(String value) throws NumberFormatException { + private static BString stringToChar(String value) throws RuntimeException { if (isCharLiteralValue(value)) { return StringUtils.fromString(value); } - throw new NumberFormatException(); + throw new RuntimeException(); } private static Double stringToFloat(String value, CsvConfig config) throws NumberFormatException, ParseException { @@ -257,11 +257,11 @@ private static BDecimal stringToDecimal(String value, CsvConfig config) throws N } private static Object stringToBoolean(String value) throws NumberFormatException { - if ("true".equals(value) || "TRUE".equals(value)) { + if ("true".equalsIgnoreCase(value)) { return true; } - if ("false".equals(value) || "FALSE".equals(value)) { + if ("false".equalsIgnoreCase(value)) { return false; } return returnError(value, "boolean"); @@ -336,11 +336,11 @@ private static boolean isCharLiteralValue(String value) { } private static boolean isIntegerValue(String value, Number number, String localeStr) { - return number instanceof Long && value.matches(getLocale(localeStr).intRegex()); + return isNumericType(number) && value.matches(getLocale(localeStr).intRegex()); } private static boolean isDoubleValue(String value, Number number, String localeStr) { - return (number instanceof Double || number instanceof Long) + return (number instanceof Double || isNumericType(number)) && value.matches(getLocale(localeStr).doubleRegex()); } @@ -367,14 +367,20 @@ private static LocaleInfo computeLocaleIfAbsent(String localeStr) { char decimalSeparator = dfs.getDecimalSeparator(); char minusSign = dfs.getMinusSign(); char zeroDigit = dfs.getZeroDigit(); + String numRange = "[" + zeroDigit + "-9]"; String exponentSeparator = dfs.getExponentSeparator(); - String intRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+$"; - String doubleRegex = "^[" + minusSign + "+]?[" + zeroDigit + "-9]+(" + - (decimalSeparator == '.' ? "\\." : decimalSeparator) - + "[" + zeroDigit + "-9]*)?(" + exponentSeparator + "[+-]?[" + zeroDigit + "-9]+)?$"; + String intRegex = "^[" + minusSign + "+]?" + numRange + "+$"; + String doubleRegex = "^[" + minusSign + "+]?" + numRange + "+(" + + (decimalSeparator == '.' ? "\\." : decimalSeparator) + + numRange + "*)?(" + exponentSeparator + "[+-]?" + numRange + "+)?$"; return new LocaleInfo(locale, intRegex, doubleRegex); } + private static boolean isNumericType(Object value) { + return value instanceof Integer || value instanceof Long || + value instanceof Short || value instanceof Byte; + } + private record LocaleInfo(Locale locale, String intRegex, String doubleRegex) { } } 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 23b054d..7411e3e 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 @@ -109,7 +109,7 @@ static void convertAndUpdateCurrentCsvNode(CsvParser.StateMachine sm, } public static String getHeaderValueForColumnIndex(CsvParser.StateMachine sm) { - if (sm.config.customHeadersIfHeadersAbsent == null && (sm.config.header == Boolean.FALSE)) { + if (sm.config.customHeadersIfHeadersAbsent == null && (sm.config.header == null)) { String header = String.valueOf(sm.columnIndex + 1); Map fieldHierarchy = sm.fieldHierarchy; fieldHierarchy.remove(header); 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 7f0ee66..a68e2d9 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 @@ -300,7 +300,7 @@ public Object execute(Reader reader, Type type, CsvConfig config, BTypedesc bTyp } State currentState; - if (config.header != Boolean.FALSE) { + if (config.header != null) { currentState = HEADER_START_STATE; } else { Object customHeadersIfHeadersAbsent = config.customHeadersIfHeadersAbsent; 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 61e4a4c..cc80b24 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 @@ -240,22 +240,14 @@ private void traverseCsvWithExpectedType(int sourceArraySize, } switch (expectedArrayElementType.getTag()) { - case TypeTags.RECORD_TYPE_TAG: - case TypeTags.MAP_TAG: - traverseCsvWithMappingAsExpectedType(sourceArraySize, csv, - expectedArrayElementType, isIntersection); - break; - case TypeTags.ARRAY_TAG: - case TypeTags.TUPLE_TAG: - traverseCsvWithListAsExpectedType(sourceArraySize, csv, - expectedArrayElementType, isIntersection); - break; - case TypeTags.UNION_TAG: - traverseCsvWithUnionExpectedType(csv, - (UnionType) expectedArrayElementType, type); - break; - default: - throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); + case TypeTags.RECORD_TYPE_TAG, TypeTags.MAP_TAG -> + traverseCsvWithMappingAsExpectedType(sourceArraySize, csv, + expectedArrayElementType, isIntersection); + case TypeTags.ARRAY_TAG, TypeTags.TUPLE_TAG -> traverseCsvWithListAsExpectedType(sourceArraySize, csv, + expectedArrayElementType, isIntersection); + case TypeTags.UNION_TAG -> traverseCsvWithUnionExpectedType(csv, + (UnionType) expectedArrayElementType, type); + default -> throw DiagnosticLog.error(DiagnosticErrorCode.SOURCE_CANNOT_CONVERT_INTO_EXP_TYPE, type); } } @@ -362,7 +354,7 @@ private static boolean ignoreRow(int index, Object skipLinesConfig) { public Object initStatesForCsvRowWithMappingAsExpectedType(Object csvElement, Type expectedType) { expectedType = TypeUtils.getReferredType(expectedType); switch (expectedType.getTag()) { - case TypeTags.RECORD_TYPE_TAG: + case TypeTags.RECORD_TYPE_TAG -> { RecordType recordType = (RecordType) expectedType; this.fieldHierarchy = new HashMap<>(recordType.getFields()); fields = new HashSet<>(recordType.getFields().keySet()); @@ -372,14 +364,13 @@ public Object initStatesForCsvRowWithMappingAsExpectedType(Object csvElement, Ty this.restType = recordType.getRestFieldType(); currentCsvNode = ValueCreator.createRecordValue(recordType.getPackage(), recordType.getName()); traverseCsvRowWithMappingAsExpectedType(csvElement, expectedType, false); - break; - case TypeTags.MAP_TAG: + } + case TypeTags.MAP_TAG -> { MapType mapType = (MapType) expectedType; currentCsvNode = ValueCreator.createMapValue(mapType); traverseCsvRowWithMappingAsExpectedType(csvElement, expectedType, true); - break; - default: - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); + } + default -> throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } return currentCsvNode; } @@ -387,25 +378,24 @@ public Object initStatesForCsvRowWithMappingAsExpectedType(Object csvElement, Ty public Object initStatesForCsvRowWithListAsExpectedType(Object csvElement, Type expectedType) { expectedType = TypeUtils.getReferredType(expectedType); switch (expectedType.getTag()) { - case TypeTags.ARRAY_TAG: + case TypeTags.ARRAY_TAG -> { ArrayType arrayType = (ArrayType) expectedType; currentCsvNode = ValueCreator.createArrayValue(arrayType); traverseCsvRowWithListAsExpectedType(csvElement, arrayType); - break; - case TypeTags.TUPLE_TAG: + } + case TypeTags.TUPLE_TAG -> { TupleType tupleType = (TupleType) expectedType; this.restType = tupleType.getRestType(); currentCsvNode = ValueCreator.createTupleValue(tupleType); traverseCsvRowWithListAsExpectedType(csvElement, tupleType); - break; - default: - throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); + } + default -> throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_TYPE, expectedType); } return currentCsvNode; } private void traverseCsvRowWithListAsExpectedType(Object csvElement, Type type) { - int expectedTypeSize = CsvUtils.getTheActualExpectedType(type); + int expectedTypeSize = CsvUtils.getTheExpectedArraySize(type); if (csvElement instanceof BMap map) { constructCsvArrayFromMapping(map, type, expectedTypeSize == -1 ? map.size() : expectedTypeSize); } else if (csvElement instanceof BArray array) { @@ -468,9 +458,8 @@ 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); + this.headers = CsvUtils.createHeadersForParseLists(csvElement, csvElement.size(), config); if (!this.isFirstRowInserted && config.headerRows >= 1) { // To skip the row at the position [config.headerRows - 1] from being aded to the result. this.isFirstRowIsHeader = true; @@ -509,8 +498,7 @@ private void constructCsvMapFromMapping( 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); + this.headers = CsvUtils.createHeadersForParseLists(array, array.size(), config); } if (this.headers == null && obj instanceof BMap) { BMap map = (BMap) obj; @@ -722,7 +710,7 @@ private Object convertCsvValueIntoExpectedType(Type type, Object csvMember, bool if (!isRecursive && config.nilAsOptionalField && !fieldType.isNilable() && CsvUtils.isNullValue(nilValue, csvMember) && currentField != null && SymbolFlags.isFlagOn(currentField.getFlags(), SymbolFlags.OPTIONAL)) { - return CsvUtils.SkipMappedValue.createSkippedValue(); + return CsvUtils.SkipMappedValue.VALUE; } if (config.stringConversion && csvMember instanceof BString str) { Object convertedValue = CsvCreator.convertToExpectedType(str, type, config); @@ -787,7 +775,7 @@ private Object convertCsvValueIntoExpectedType(Type type, Object csvMember, bool throw DiagnosticLog.error(DiagnosticErrorCode.INVALID_EXPECTED_TYPE, type); } } - return CsvUtils.UnMappedValue.createUnMappedValue(); + return CsvUtils.UnMappedValue.VALUE; } private void insertRestFieldMemberIntoMapping(Type type, BString key, Object csvMember) { 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 2c63f34..73f8dc1 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 @@ -58,7 +58,8 @@ public static boolean isBasicType(Type type) { }; } - public static String[] createHeadersForParseLists(BArray csvElement, String[] headers, CsvConfig config) { + public static String[] createHeadersForParseLists(BArray csvElement, int headerSize, CsvConfig config) { + String[] headers = new String[headerSize]; Object customHeaders = config.customHeaders; long headerRows = config.headerRows; @@ -128,17 +129,11 @@ public static boolean isHeaderFieldsEmpty(Map currentField) { public static boolean checkTypeCompatibility(Type constraintType, Object csv, boolean stringConversion) { int tag = constraintType.getTag(); if (csv instanceof BString) { - if (stringConversion || TypeTags.isStringTypeTag(tag) || isJsonOrAnyDataOrAny(tag)) { - return true; - } - return false; + return stringConversion || TypeTags.isStringTypeTag(tag) || isJsonOrAnyDataOrAny(tag); } if (csv instanceof Long) { - if (TypeTags.isIntegerTypeTag(tag) || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG - || tag == TypeTags.BYTE_TAG || isJsonOrAnyDataOrAny(tag)) { - return true; - } - return false; + return TypeTags.isIntegerTypeTag(tag) || tag == TypeTags.FLOAT_TAG || tag == TypeTags.DECIMAL_TAG + || tag == TypeTags.BYTE_TAG || isJsonOrAnyDataOrAny(tag); } if (csv instanceof BDecimal) { if ((tag == TypeTags.DECIMAL_TAG @@ -147,17 +142,11 @@ public static boolean checkTypeCompatibility(Type constraintType, Object csv, bo } } if (csv instanceof Double) { - if ((tag == TypeTags.FLOAT_TAG - || tag == TypeTags.DECIMAL_TAG || TypeTags.isIntegerTypeTag(tag)) || isJsonOrAnyDataOrAny(tag)) { - return true; - } - return false; + return (tag == TypeTags.FLOAT_TAG + || tag == TypeTags.DECIMAL_TAG || TypeTags.isIntegerTypeTag(tag)) || isJsonOrAnyDataOrAny(tag); } if (csv instanceof Boolean) { - if (tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag)) { - return true; - } - return false; + return tag == TypeTags.BOOLEAN_TAG || isJsonOrAnyDataOrAny(tag); } if (csv == null) { return tag == TypeTags.NULL_TAG || isJsonOrAnyDataOrAny(tag); @@ -169,7 +158,7 @@ private static boolean isJsonOrAnyDataOrAny(int tag) { return tag == TypeTags.JSON_TAG || tag == TypeTags.ANYDATA_TAG || tag == TypeTags.ANY_TAG; } - public static int getTheActualExpectedType(Type type) { + public static int getTheExpectedArraySize(Type type) { if (type instanceof TupleType tupleType) { if (tupleType.getRestType() != null) { return -1; @@ -305,16 +294,11 @@ public static boolean isCharContainsInLineTerminatorUserConfig(char c, return false; } - String lineTerminator = StringUtils.getStringValue(StringUtils.fromString(lineTerminatorObj.toString())); - if (c == Constants.LineTerminator.LF) { - if (lineTerminator != null) { - if (lineTerminator.equals(Constants.LineTerminator.CRLF)) { - return isCarriageTokenPresent; - } - return true; - } + Optional value = handleLineTerminator(lineTerminatorObj, c, isCarriageTokenPresent); + if (value.isEmpty()) { + return false; } - return false; + return value.get(); } private static Optional handleLineTerminator(Object lineTerminator, @@ -322,34 +306,18 @@ private static Optional handleLineTerminator(Object lineTerminator, if (lineTerminator == null || c != Constants.LineTerminator.LF) { return Optional.empty(); } - String lineTerminatorString = lineTerminator.toString(); - if (isCarriageTokenPresent) { - if (lineTerminatorString.equals(Constants.LineTerminator.CRLF)) { - return Optional.of(true); - } - return Optional.empty(); + if (lineTerminator.equals(Constants.LineTerminator.CRLF)) { + return Optional.of(isCarriageTokenPresent); } return Optional.of(true); } public static class UnMappedValue { - private static UnMappedValue value = null; - public static UnMappedValue createUnMappedValue() { - if (value == null) { - value = new UnMappedValue(); - } - return value; - } + public static final UnMappedValue VALUE = new UnMappedValue(); } public static class SkipMappedValue { - private static SkipMappedValue value = null; - public static SkipMappedValue createSkippedValue() { - if (value == null) { - value = new SkipMappedValue(); - } - return value; - } + public static final SkipMappedValue VALUE = new SkipMappedValue(); } public static Locale createLocaleFromString(String localeString) { From b740397abe090fc12918f243ba6847ae28111b39 Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 1 Oct 2024 10:45:05 +0530 Subject: [PATCH 146/147] Add unique id for thrad pool threads --- .../data/csvdata/compiler/CsvDataTypeValidator.java | 10 +++------- .../lib/data/csvdata/io/DataReaderThreadPool.java | 2 +- 2 files changed, 4 insertions(+), 8 deletions(-) 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 1bab458..49ff126 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 @@ -250,8 +250,7 @@ private void validateFunctionParameterTypes(ExpressionNode expressionNode, } private void validateFunctionParameterTypesWithExpType(TypeSymbol expType, Location currentLocation, - SyntaxNodeAnalysisContext ctx, String functionName, - SeparatedNodeList args) { + SyntaxNodeAnalysisContext ctx, String functionName, SeparatedNodeList args) { switch (expType.typeKind()) { case ARRAY -> validateFunctionParameterTypesWithArrayType( (ArrayTypeSymbol) expType, currentLocation, ctx, functionName, args); @@ -496,11 +495,8 @@ private void validateTupleMembers(SyntaxNodeAnalysisContext ctx, Location curren 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); - } + tupleTypeSymbol.restTypeDescriptor().ifPresent(restSym -> + validateNestedTypeSymbols(ctx, currentLocation, restSym, false)); } private void validateRecordFields(SyntaxNodeAnalysisContext ctx, Location currentLocation, TypeSymbol typeSymbol) { diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java b/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java index ae54392..35b8290 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java @@ -47,7 +47,7 @@ static class DataThreadFactory implements ThreadFactory { @Override public Thread newThread(Runnable runnable) { Thread ballerinaData = new Thread(runnable); - ballerinaData.setName(THREAD_NAME); + ballerinaData.setName(THREAD_NAME + "-" + ballerinaData.getId()); return ballerinaData; } } From 3acca4fadb7ca49cb4ba45f1229ed7307098fcfa Mon Sep 17 00:00:00 2001 From: Sasindu Alahakoon Date: Tue, 1 Oct 2024 11:30:41 +0530 Subject: [PATCH 147/147] Add a atomic integer as a thread id --- .../io/ballerina/lib/data/csvdata/csv/CsvParser.java | 9 ++++++--- .../lib/data/csvdata/io/DataReaderThreadPool.java | 4 +++- 2 files changed, 9 insertions(+), 4 deletions(-) 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 a68e2d9..1f9f650 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 @@ -81,12 +81,15 @@ public final class CsvParser { private CsvParser() { } - private static final ThreadLocal LOCAL_THREAD_STATE_MACHINE - = ThreadLocal.withInitial(StateMachine::new); + // TODO: Add this implementation after creating the object pool implementation + // private static final ThreadLocal LOCAL_THREAD_STATE_MACHINE + // = ThreadLocal.withInitial(StateMachine::new); public static Object parse(Reader reader, BTypedesc type, CsvConfig config) throws BError { - StateMachine sm = LOCAL_THREAD_STATE_MACHINE.get(); + // TODO: Add this implementation after creating the object pool implementation + // StateMachine sm = LOCAL_THREAD_STATE_MACHINE.get(); + StateMachine sm = new StateMachine(); try { CsvUtils.validateConfigs(config); Object convertedValue = sm.execute(reader, TypeUtils.getReferredType(type.getDescribingType()), diff --git a/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java b/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java index 35b8290..379a6e3 100644 --- a/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java +++ b/native/src/main/java/io/ballerina/lib/data/csvdata/io/DataReaderThreadPool.java @@ -22,6 +22,7 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicLong; /** * Thread pool for data reader. @@ -33,6 +34,7 @@ public final class DataReaderThreadPool { private static final int MAX_POOL_SIZE = 50; private static final long KEEP_ALIVE_TIME = 60L; private static final String THREAD_NAME = "bal-data-csv-thread"; + private static final AtomicLong THREAD_ID = new AtomicLong(1); public static final ExecutorService EXECUTOR_SERVICE = new ThreadPoolExecutor(CORE_POOL_SIZE, MAX_POOL_SIZE, KEEP_ALIVE_TIME, TimeUnit.SECONDS, new SynchronousQueue<>(), new DataThreadFactory()); @@ -47,7 +49,7 @@ static class DataThreadFactory implements ThreadFactory { @Override public Thread newThread(Runnable runnable) { Thread ballerinaData = new Thread(runnable); - ballerinaData.setName(THREAD_NAME + "-" + ballerinaData.getId()); + ballerinaData.setName(THREAD_NAME + "-" + THREAD_ID.getAndIncrement()); return ballerinaData; } }