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

ci: configure build and test #19

Merged
merged 6 commits into from
May 19, 2024
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
65 changes: 65 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build
on:
push:
branches:
- mistress
pull_request:

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 22
cache: pnpm
- run: pnpm install
- run: pnpm run build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist

vitest:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [18, 20, 22]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
cache: pnpm
- run: pnpm install
- run: pnpm run test

toml-test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node: [18, 20, 22]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/setup-go@v4
with:
go-version: '^1.22.3'
- run: go install github.com/toml-lang/toml-test/cmd/toml-test@master

- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: dist
path: dist
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- run: ./run-toml-test.bash
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
54 changes: 47 additions & 7 deletions run-toml-test.bash
Original file line number Diff line number Diff line change
@@ -1,20 +1,60 @@
#!/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=(
skip_decode=(
# 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'
-skip='invalid/string/bad-uni-esc-6'

# JS uses floats for numbers
# 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'
-skip='invalid/local-datetime/feb-29'
-skip='invalid/datetime/feb-29'
-skip='invalid/local-date/feb-30'
-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'
)

e=0
toml-test -int-as-float ${skip[@]} ./toml-test-parse.mjs || e=1
toml-test -int-as-float -encoder ${skip[@]} ./toml-test-encode.mjs || e=1
# -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)
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
2 changes: 1 addition & 1 deletion src/date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class TomlDate extends Date {
} else {
offset = match[3] || null
date = date.toUpperCase()
if (!offset) date += 'Z'
if (!offset && hasTime) date += 'Z'
}
} else {
date = ''
Expand Down
8 changes: 3 additions & 5 deletions toml-test-encode.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,16 @@ function untagObject (obj) {
case 'bool':
return obj.value === 'true'
case 'integer':
return BigInt(obj.value)
// TODO: add an option to always serialize numbers as floats
// return BigInt(obj.value)
return Number(obj.value)
case 'float':
if (obj.value === 'nan') return NaN
if (obj.value === '+nan') return NaN
if (obj.value === '-nan') return NaN
if (obj.value === 'inf') return Infinity
if (obj.value === '+inf') return Infinity
if (obj.value === '-inf') return -Infinity

if (obj.value === 'Inf') return Infinity
if (obj.value === '+Inf') return Infinity
if (obj.value === '-Inf') return -Infinity
return Number(obj.value)
case 'datetime':
case 'datetime-local':
Expand Down
Loading