diff --git a/error_test.go b/error_test.go index 48f558b4..8f404075 100644 --- a/error_test.go +++ b/error_test.go @@ -43,7 +43,7 @@ At line 9, column 3-8: 8 | # This table conflicts with the previous table 9 | [fruit.variety] ^^^^^`}, - {"datetime/trailing-t.toml", ` + {"local-date/trailing-t.toml", ` toml: error: invalid datetime: "2006-01-30T" At line 2, column 4-15: diff --git a/internal/toml-test/COPYING b/internal/toml-test/COPYING deleted file mode 100644 index 93b22020..00000000 --- a/internal/toml-test/COPYING +++ /dev/null @@ -1,21 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2018 TOML authors - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. diff --git a/internal/toml-test/README.md b/internal/toml-test/README.md deleted file mode 100644 index 616b73e2..00000000 --- a/internal/toml-test/README.md +++ /dev/null @@ -1,296 +0,0 @@ -`toml-test` is a language-agnostic test suite to verify the correctness of -[TOML][t] parsers and writers. - -Tests are divided into two groups: "invalid" and "valid". Decoders or encoders -that reject "invalid" tests pass the tests, and decoders that accept "valid" -tests and output precisely what is expected pass the tests. The output format is -JSON, described below. - -Both encoders and decoders share valid tests, except an encoder accepts JSON and -outputs TOML rather than the reverse. The TOML representations are read with a -blessed decoder and is compared. The JSON given to a TOML encoder is in the same -format as the JSON that a TOML decoder should output. - -Compatible with TOML version [v1.0.0][v1]. - -[t]: https://toml.io -[v1]: https://toml.io/en/v1.0.0 - -Installation ------------- -There are binaries on the [release page][r]; these are statically compiled and -should run in most environments. It's recommended you use a binary, or a tagged -release if you build from source especially in CI environments. This prevents -your tests from breaking on changes to tests in this tool. - -To compile from source you will need Go 1.18 or newer: - - $ go install github.com/toml-lang/toml-test/cmd/toml-test@latest - -This will build a `./toml-test` binary. - -[r]: https://github.com/toml-lang/toml-test/releases - -Usage ------ -`toml-test` accepts an encoder or decoder as the first positional argument, for -example: - - $ toml-test my-toml-decoder - $ toml-test my-toml-encoder -encoder - -The `-encoder` flag is used to signal that this is an encoder rather than a -decoder. - -For example, to run the tests against the Go TOML library: - - # Install my parser - $ go install github.com/BurntSushi/toml/cmd/toml-test-decoder@master - $ go install github.com/BurntSushi/toml/cmd/toml-test-encoder@master - - $ toml-test toml-test-decoder - toml-test [toml-test-decoder]: using embeded tests: 278 passed - - $ toml-test -encoder toml-test-encoder - toml-test [toml-test-encoder]: using embeded tests: 94 passed, 0 failed - -The default is to use the tests compiled in the binary; you can use `-testdir` -to load tests from the filesystem. You can use `-run [name]` or `-skip [name]` -to run or skip specific tests. Both flags can be given more than once and accept -glob patterns: `-run 'valid/string/*'`. - -See `toml-test -help` for detailed usage. - -### Implementing a decoder -For your decoder to be compatible with `toml-test` it **must** satisfy the -expected interface: - -- Your decoder **must** accept TOML data on `stdin`. -- If the TOML data is invalid, your decoder **must** return with a non-zero - exit code, indicating an error. -- If the TOML data is valid, your decoder **must** output a JSON encoding of - that data on `stdout` and return with a zero exit code, indicating success. - -An example in pseudocode: - - toml_data = read_stdin() - - parsed_toml = decode_toml(toml_data) - - if error_parsing_toml(): - print_error_to_stderr() - exit(1) - - print_as_tagged_json(parsed_toml) - exit(0) - -Details on the tagged JSON is explained below in "JSON encoding". - -### Implementing an encoder -For your encoder to be compatible with `toml-test`, it **must** satisfy the -expected interface: - -- Your encoder **must** accept JSON data on `stdin`. -- If the JSON data cannot be converted to a valid TOML representation, your - encoder **must** return with a non-zero exit code, indicating an error. -- If the JSON data can be converted to a valid TOML representation, your encoder - **must** output a TOML encoding of that data on `stdout` and return with a - zero exit code, indicating success. - -An example in pseudocode: - - json_data = read_stdin() - - parsed_json_with_tags = decode_json(json_data) - - if error_parsing_json(): - print_error_to_stderr() - exit(1) - - print_as_toml(parsed_json_with_tags) - exit(0) - -JSON encoding -------------- -The following JSON encoding applies equally to both encoders and decoders: - -- TOML tables correspond to JSON objects. -- TOML table arrays correspond to JSON arrays. -- TOML values correspond to a special JSON object of the form: - `{"type": "{TOML_TYPE}", "value": "{TOML_VALUE}"}` - -In the above, `TOML_TYPE` may be one of: - -- string -- integer -- float -- bool -- datetime -- datetime-local -- date-local -- time-local - -`TOML_VALUE` is always a JSON string. - -Empty hashes correspond to empty JSON objects (`{}`) and empty arrays correspond -to empty JSON arrays (`[]`). - -Offset datetimes should be encoded in RFC 3339; Local datetimes should be -encoded following RFC 3339 without the offset part. Local dates should be -encoded as the date part of RFC 3339 and Local times as the time part. - -Examples: - - TOML JSON - - a = 42 {"type": "integer": "value": "42"} - - - - [tbl] {"tbl": { - a = 42 "a": {"type": "integer": "value": "42"} - }} - - - - a = ["a", 2] {"a": [ - {"type": "string", "value": "1"}, - {"type": "integer": "value": "2"} - ]} - -Or a more complex example: - -```toml -best-day-ever = 1987-07-05T17:45:00Z - -[numtheory] -boring = false -perfection = [6, 28, 496] -``` - -And the JSON encoding expected by `toml-test` is: - -```json -{ - "best-day-ever": {"type": "datetime", "value": "1987-07-05T17:45:00Z"}, - "numtheory": { - "boring": {"type": "bool", "value": "false"}, - "perfection": [ - {"type": "integer", "value": "6"}, - {"type": "integer", "value": "28"}, - {"type": "integer", "value": "496"} - ] - } -} -``` - -Note that the only JSON values ever used are objects, arrays and strings. - -An example implementation can be found in the BurnSushi/toml: - -- [Add tags](https://github.com/BurntSushi/toml/blob/master/internal/tag/add.go) -- [Remove tags](https://github.com/BurntSushi/toml/blob/master/internal/tag/rm.go) - -Implementation-defined behaviour --------------------------------- -This only tests behaviour that's should be true for every encoder implementing -TOML; a few things are left up to implementations, and are not tested here. - -- Millisecond precision (3 digits) is required for datetimes and times, and - further precision is implementation-specific, and any greater precision than - is supported must be truncated (not rounded). - - This tests only millisecond precision, and not any further precision or the - truncation of it. - -Assumptions of Truth --------------------- -The following are taken as ground truths by `toml-test`: - -- All tests classified as `invalid` **are** invalid. -- All tests classified as `valid` **are** valid. -- All expected outputs in `valid/test-name.json` are exactly correct. -- The Go standard library package `encoding/json` decodes JSON correctly. -- When testing encoders the - [BurntSushi/toml](https://github.com/BurntSushi/toml) TOML decoder is assumed - to be correct. (Note that this assumption is not made when testing decoders!) - -Of particular note is that **no TOML decoder** is taken as ground truth when -testing decoders. This means that most changes to the spec will only require an -update of the tests in `toml-test`. (Bigger changes may require an adjustment of -how two things are considered equal. Particularly if a new type of data is -added.) Obviously, this advantage does not apply to testing TOML encoders since -there must exist a TOML decoder that conforms to the specification in order to -read the output of a TOML encoder. - -Usage without `toml-test` binary --------------------------------- -While the `toml-test` tool is a convenient way to run the tests, you can also -re-implement its behaviour in your own language's test-suite, which may be an -easier way to run the tests. - -Because multiple TOML versions are supported, not all tests are valid for every -version of TOML; for example the 1.0.0 tests contain a test that trailing commas -in tables are invalid, but in 1.1.0 this should be considered valid. - -In short: you can't "just" copy all .toml and .json files from the tests/ -directory. The [tests/files-toml-1.0.0] and [tests/files-toml-1.1.0] files -contain a list of files you should run for that TOML version. - -You can use those lists to determine which tests to run, or include only those -tests in your library by copying them with something like: - -