Skip to content

Commit

Permalink
docs: update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
cyyynthia committed May 19, 2024
1 parent f8c40e9 commit 7b3761f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
[![TOML 1.0.0](https://img.shields.io/badge/TOML-1.0.0-9c4221?style=flat-square)](https://toml.io/en/v1.0.0)
[![License](https://img.shields.io/github/license/squirrelchat/smol-toml.svg?style=flat-square)](https://github.com/squirrelchat/smol-toml/blob/mistress/LICENSE)
[![npm](https://img.shields.io/npm/v/smol-toml?style=flat-square)](https://npm.im/smol-toml)
[![Build](https://img.shields.io/github/actions/workflow/status/squirrelchat/smol-toml/build.yml?style=flat-square&logo=github)](https://github.com/squirrelchat/smol-toml/actions/workflows/build.yml)

A small, fast, and correct TOML parser and serializer. smol-toml is fully(ish) spec-compliant with TOML v1.0.0.

Expand All @@ -16,9 +17,15 @@ smol-toml passes most of the tests from the [`toml-test` suite](https://github.c
it doesn't pass certain tests, namely:
- Invalid UTF-8 strings are not rejected
- Certain invalid UTF-8 codepoints are not rejected
- Certain invalid dates are not rejected
- For instance, `2023-02-30` would be accepted and parsed as `2023-03-02`. While additional checks could be performed
to reject these, they've not been added for performance reasons.
- 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)`.

You can see a list of all tests smol-toml fails (and the reason why it fails these) in the list of skipped tests in
`run-toml-test.bash`. Note that some failures are *not* specification violations per-se. For instance, the TOML spec
does not require 64-bit integer range support or sub-millisecond time precision, but are included in the `toml-test`
suite. See https://github.com/toml-lang/toml-test/issues/154 and https://github.com/toml-lang/toml-test/issues/155

## Installation
```
Expand Down
22 changes: 14 additions & 8 deletions run-toml-test.bash
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/usr/bin/env bash
#
# Requires toml-test from https://github.com/toml-lang/toml-test, commit 78f8c61
# or newer (Oct 2023).
# Requires toml-test from https://github.com/toml-lang/toml-test, commit 78f8c61 or newer (Oct 2023).

skip_decode=(
# Invalid UTF-8 strings are not rejected
Expand All @@ -11,9 +9,10 @@ skip_decode=(
-skip='invalid/encoding/bad-codepoint'
-skip='invalid/string/bad-uni-esc-6'

# JS doesn't reject invalid dates, but interprets extra days such as "Feb 30" as "Feb 28 +2d" gracefully
# This behavior is implementation specific, although this should hold true for all major JS engines out there.
# See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse#non-standard_date_strings
# JS* doesn't reject invalid dates, but interprets extra days such as "Feb 30 2023" as "Feb 28 2023 +2d" gracefully.
#
# *This is true for V8, SpiderMonkey, and JavaScriptCore. Note that this behavior is implementation specific and
# certain flavors of engines may behave differently.
#
# While smol-toml could implement additional checks, this has not been done for performance reasons
-skip='invalid/local-date/feb-29'
Expand All @@ -23,24 +22,31 @@ skip_decode=(
-skip='invalid/local-datetime/feb-30'
-skip='invalid/datetime/feb-30'

# smol-toml does not support the entire 64-bit integer range
# This is not required by the specification, and smol-toml throws an appropriate error
# https://github.com/toml-lang/toml-test/issues/154
-skip='valid/integer/long'
)

skip_encode=(
# smol-toml does not support sub-millisecond time precision
# This is not required by the specification, and smol-toml performs appropriate *truncation*, not rounding
# https://github.com/toml-lang/toml-test/issues/155
-skip='valid/spec/offset-date-time-0'
-skip='valid/spec/local-date-time-0'
-skip='valid/spec/local-time-0'

# Some more Float <> Integer shenanigans
# -int-as-float can't help us here, so we have to skip these :(
-skip='valid/inline-table/spaces'
-skip='valid/float/zero'
-skip='valid/float/underscore'
-skip='valid/float/exponent'
-skip='valid/comment/tricky'
-skip='valid/spec/float-0'

# smol-toml does not support the entire 64-bit integer range
# This is not required by the specification, and smol-toml throws an appropriate error
# https://github.com/toml-lang/toml-test/issues/154
-skip='valid/integer/long'
)
Expand All @@ -49,6 +55,6 @@ e=0
# -int-as-float as there is no way to distinguish between them at this time.
# For the encoder, distinction is made between floats and integers using JS bigint, however
# due to the lack of option to always serialize plain numbers as floats, some tests fail (and are therefore skipped)
~/go/bin/toml-test -int-as-float ${skip_decode[@]} ./toml-test-parse.mjs || e=1
~/go/bin/toml-test -encoder ${skip_encode[@]} ./toml-test-encode.mjs || e=1
toml-test -int-as-float ${skip_decode[@]} ./toml-test-parse.mjs || e=1
toml-test -encoder ${skip_encode[@]} ./toml-test-encode.mjs || e=1
exit $e

0 comments on commit 7b3761f

Please sign in to comment.