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

Add 262 JSON tests #662

Merged
merged 13 commits into from
Jun 11, 2024
Merged

Conversation

saulecabrera
Copy link
Member

Description of the change

This PR is a follow up to #651
This PR is best reviewed commit by commit.

In general, this PR introduces tests (and updates) to Javy's custom JSON.{parse,stringify} implementation to ensure compliance with the official JSON test suite. There are a couple of tests, 3 to be exact, that are marked as ignored, refer to the comments on each test for more details.

Why am I making this change?

To ensure compliance with the official JSON test suite for JavaScript.

Checklist

  • I've updated the relevant CHANGELOG files if necessary. Changes to javy-cli and javy-core do not require updating CHANGELOG files.
  • I've updated the relevant crate versions if necessary. Versioning policy for library crates
  • I've updated documentation including crate documentation if necessary.

This commit introduces the `javy-test-macros` crate to the existing
family of crates.

This crate is intended to be a dev-dependency crate used to test javy
through the embedding API.

As of this commit, this crate exposes the bare minimum functionality to
test the implementation of JSON.{parse,stringify} introduced in
bytecodealliance#651.
This commit adds `javy-test-macros` as a development dependency in the
`javy` crate and adds 262 test for Javy's custom implementation of
`JSON.{parse,stringigy}`.

The 262 suite is pulled in as a submodule.

In order to test the custom implementation, this commit explicitly calls
`config.override_json_parse_and_stringify` when creating the default
runtime used in Javy. The override configuration was introduced in
bytecodealliance#651.
This was added for development purposes.
@saulecabrera saulecabrera requested a review from jeffcharles June 10, 2024 18:20
There's nothing in the spec stating that the key must be a string.
Copy link
Collaborator

@jeffcharles jeffcharles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to take msgpack or other serde supported non-JSON formats into account with the changes we're making to the serde trait implementations?

crates/javy-test-macros/src/lib.rs Outdated Show resolved Hide resolved
crates/javy-test-macros/src/lib.rs Outdated Show resolved Hide resolved
crates/javy-test-macros/src/lib.rs Outdated Show resolved Hide resolved
crates/javy-test-macros/src/lib.rs Outdated Show resolved Hide resolved
crates/javy-test-macros/src/lib.rs Show resolved Hide resolved
crates/javy/src/apis/json.rs Show resolved Hide resolved
crates/javy/src/apis/json.rs Outdated Show resolved Hide resolved
crates/javy/src/lib.rs Show resolved Hide resolved
crates/javy/src/serde/de.rs Show resolved Hide resolved
crates/javy/src/serde/de.rs Outdated Show resolved Hide resolved
@saulecabrera
Copy link
Member Author

Do we need to take msgpack or other serde supported non-JSON formats into account with the changes we're making to the serde trait implementations?

Ah yeah, good question. To ensure that it's correct, we'd probably need to hook the spec test for msgpack, similar to what's done in this PR for JSON. I suspect that the in-the-wild usage for the msgpack ser/deserializer is close to none, so my preference would be to deprecate this feature instead. Also, these serializers have been in "experimental" state since I initially wrote them, until now, in which we're upgrading the status of JSON. I'll do the deprecation in a follow up though.

@saulecabrera saulecabrera requested a review from jeffcharles June 10, 2024 20:16
Copy link
Collaborator

@jeffcharles jeffcharles left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good to me! Just noticed the error messages not including the type of error while seeing what the error message with the unbalanced double-quote looked like.

Re non-JSON formats, I agree that the msgpack transcoding probably isn't used widely. However, we were publicly exporting the Serializer and Deserializer from the quickjs-wasm-rs crate and someone could've been using those for any format (I also don't have any evidence they were in use) but it also looks like we're not exporting them from the Javy crate so I guess we're probably fine since they wouldn't be able to continue to use the serializer or deserializer anyway. I guess if someone complains, we can figure out options to support their use case at if that happens.

crates/javy/src/apis/json.rs Outdated Show resolved Hide resolved
crates/javy/src/serde/err.rs Show resolved Hide resolved
@saulecabrera saulecabrera requested a review from jeffcharles June 10, 2024 21:49
@saulecabrera saulecabrera merged commit 0b8cc19 into bytecodealliance:main Jun 11, 2024
14 checks passed
@saulecabrera saulecabrera deleted the json-262-tests branch June 11, 2024 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants