From 5ccd1d1b17093c39931acb4be6971e4fa0955d11 Mon Sep 17 00:00:00 2001 From: Martin Tournoij Date: Wed, 18 Oct 2023 19:42:58 +0200 Subject: [PATCH] chore: improve toml-test integration (#11) Make the scripts executable and add hashbang; this way it can be run a bit easier: % toml-test -int-as-float ./toml-test-parse.js | tail -n3 toml-test v2023-10-18 [./toml-test-parse.js]: using embedded tests valid tests: 163 passed, 3 failed invalid tests: 342 passed, 13 failed % toml-test ./toml-test-encode.js -encoder | tail -n2 toml-test v2023-10-18 [./toml-test-encode.js]: using embedded tests encoder tests: 157 passed, 9 failed Also add a run-toml-test.bash script to the root, with the correct flags to run the tests and skipping known failures; this way it's easy to test for regressions. --- LICENSE | 0 README.md | 24 +++--------------------- run-toml-test.bash | 20 ++++++++++++++++++++ toml-test-encode.js | 3 ++- toml-test-parse.js | 3 ++- tsconfig.json | 0 6 files changed, 27 insertions(+), 23 deletions(-) mode change 100755 => 100644 LICENSE create mode 100755 run-toml-test.bash mode change 100644 => 100755 toml-test-encode.js mode change 100644 => 100755 toml-test-parse.js mode change 100755 => 100644 tsconfig.json diff --git a/LICENSE b/LICENSE old mode 100755 new mode 100644 diff --git a/README.md b/README.md index dae8c56..f567630 100644 --- a/README.md +++ b/README.md @@ -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. - -
-List of failed `toml-test` cases - -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 -
- ## Installation ``` [pnpm | yarn | npm] i smol-toml diff --git a/run-toml-test.bash b/run-toml-test.bash new file mode 100755 index 0000000..2dd13d7 --- /dev/null +++ b/run-toml-test.bash @@ -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 diff --git a/toml-test-encode.js b/toml-test-encode.js old mode 100644 new mode 100755 index 0467969..02e52c6 --- a/toml-test-encode.js +++ b/toml-test-encode.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node /*! * Copyright (c) Squirrel Chat et al., All rights reserved. * SPDX-License-Identifier: BSD-3-Clause @@ -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' diff --git a/toml-test-parse.js b/toml-test-parse.js old mode 100644 new mode 100755 index 288267b..c9da253 --- a/toml-test-parse.js +++ b/toml-test-parse.js @@ -1,3 +1,4 @@ +#!/usr/bin/env node /*! * Copyright (c) Squirrel Chat et al., All rights reserved. * SPDX-License-Identifier: BSD-3-Clause @@ -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' diff --git a/tsconfig.json b/tsconfig.json old mode 100755 new mode 100644