Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve toml-test integration #11

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified LICENSE
100755 → 100644
Empty file.
24 changes: 3 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,15 @@ parser didn't feel too out of place.

*[insert xkcd 927]*

smol-toml passes most of the tests from [BurntSushi's `toml-test` suite](https://github.com/BurntSushi/toml-test).
However, due to the nature of JavaScript and the limits of the language, it doesn't pass certain tests, namely:
smol-toml passes most of the tests from the [`toml-test` suite](https://github.com/toml-lang/toml-test); use the
`run-toml-test.bash` script to run the tests. Due to the nature of JavaScript and the limits of the language,
it doesn't pass certain tests, namely:
- Invalid UTF-8 strings are not rejected
- Certain invalid UTF-8 codepoints are not rejected
- smol-toml doesn't preserve type information between integers and floats (in JS, everything is a float)
- smol-toml doesn't support the whole 64-bit range for integers (but does throw an appropriate error)
- As all numbers are floats in JS, the safe range is `2**53 - 1` <=> `-(2**53 - 1)`.

smol-toml also passes all of the tests in https://github.com/iarna/toml-spec-tests.

<details>
<summary>List of failed `toml-test` cases</summary>

These tests were done by modifying `primitive.ts` and make the implementation return bigints for integers. This allows
verifying the parser correctly intents a number to be an integer or a float.

*Ideally, this becomes an option of the library, but for now...*

The following parse tests are failing:
- invalid/encoding/bad-utf8-in-comment
- invalid/encoding/bad-utf8-in-multiline-literal
- invalid/encoding/bad-utf8-in-multiline
- invalid/encoding/bad-utf8-in-string-literal
- invalid/encoding/bad-utf8-in-string
- invalid/string/bad-codepoint
</details>

## Installation
```
[pnpm | yarn | npm] i smol-toml
Expand Down
20 changes: 20 additions & 0 deletions run-toml-test.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env bash
#
# Requires toml-test from https://github.com/toml-lang/toml-test, commit 78f8c61
# or newer (Oct 2023).

skip=(
# Invalid UTF-8 strings are not rejected
-skip='invalid/encoding/bad-utf8-*'

# Certain invalid UTF-8 codepoints are not rejected
-skip='invalid/encoding/bad-codepoint'

# JS uses floats for numbers
-skip='valid/integer/long'
)

e=0
toml-test -int-as-float ${skip[@]} ./toml-test-parse.js || e=1
toml-test -int-as-float -encoder ${skip[@]} ./toml-test-encode.js || e=1
exit $e
3 changes: 2 additions & 1 deletion toml-test-encode.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
/*!
* Copyright (c) Squirrel Chat et al., All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
Expand Down Expand Up @@ -26,7 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// Script for https://github.com/BurntSushi/toml-test
// Script for https://github.com/toml-lang/toml-test

import { TomlDate, stringify } from './dist/index.js'

Expand Down
3 changes: 2 additions & 1 deletion toml-test-parse.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env node
/*!
* Copyright (c) Squirrel Chat et al., All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
Expand Down Expand Up @@ -26,7 +27,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

// Script for https://github.com/BurntSushi/toml-test
// Script for https://github.com/toml-lang/toml-test

import { TomlDate, parse } from './dist/index.js'

Expand Down
Empty file modified tsconfig.json
100755 → 100644
Empty file.