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

Portable test data set #51

Open
tokuhirom opened this issue Mar 5, 2014 · 6 comments
Open

Portable test data set #51

tokuhirom opened this issue Mar 5, 2014 · 6 comments

Comments

@tokuhirom
Copy link

I want to port JSON5 to another programming language.
Is there a portable test data set?

@aeisenberg
Copy link
Collaborator

There is none. But my recommendation would be to take a look at the
existing test cases and adapt them to the new implementation. I've thought
about creating a proper spec and TCK, but that's not something I've had
time to do.

What language are you looking at and do you have any implementation yet?

On Tue, Mar 4, 2014 at 9:48 PM, Tokuhiro Matsuno
notifications@github.comwrote:

I want to port JSON5 to another programming language.
Is there a portable test data set?

Reply to this email directly or view it on GitHubhttps://github.com//issues/51
.

@rlidwka
Copy link
Contributor

rlidwka commented Mar 5, 2014

When I was implementing tests for my json5 parser, I took this approach:

  1. got existing json5 tests and tweaked them a bit
  2. got existing v8 json tests and tweaked them a bit
  3. threw a bunch of random data and made sure that JSON5.parse(JSON5.stringify(x)) == x
  4. threw a bunch of random strings and made sure that for each of my tests results are equal to at least one of these functions:
    • JSON.parse(something)
    • eval('(function(){return ('+String(something)+'\n)\n})()')

You can do the same thing, just compare your output with the existing json5 parsers.

PS: is there a portable test data set for a classic JSON?

@aeisenberg
Copy link
Collaborator

This looks like a good approach.

On Wed, Mar 5, 2014 at 7:55 AM, Alex Kocharin notifications@github.comwrote:

When I was implementing tests for my json5 parserhttps://github.com/rlidwka/jju,
I took this approach:

  1. got existing json5 tests and tweaked them a bit
  2. got existing v8 json tests and tweaked them a bit, since
  3. threw a bunch of random data and made sure that JSON5.parse(JSON5.stringify(x))
    == x
  4. threw a bunch of random strings and made sure that for each of my
    tests results are equal to at least one of these functions:
    • JSON.parse(something)
    • eval('(function(){return ('+String(something)+'\n)\n})()')

Reply to this email directly or view it on GitHubhttps://github.com//issues/51#issuecomment-36756901
.

@rlidwka
Copy link
Contributor

rlidwka commented Mar 27, 2014

Is there a portable test data set?

I just created one here: https://github.com/rlidwka/jju/blob/master/test/portable-json5-tests.yaml

About a hundred tests, should cover pretty much anything about literals notation in ES5 spec.

@aeisenberg
Copy link
Collaborator

Nice. I had a brief look and found a couple of inconsistencies:

  1. Lines 95 and 100: I think you have object and array mixed up
  2. JSON will stringify NaN and Infinity to null. Eg-

    JSON.stringify(NaN)
    'null'
    Your tests show something different. Perhaps I'm not understanding how
    these tests are supposed to run.

On Thu, Mar 27, 2014 at 3:03 PM, Alex Kocharin notifications@github.comwrote:

Is there a portable test data set?

I just created one here:
https://github.com/rlidwka/jju/blob/master/test/portable-json5-tests.yaml

About a hundred tests, should cover pretty much anything about literals
notation in ES5 spec.

Reply to this email directly or view it on GitHubhttps://github.com//issues/51#issuecomment-38866573
.

@rlidwka
Copy link
Contributor

rlidwka commented Mar 28, 2014

  1. Lines 95 and 100: I think you have object and array mixed up

oops... you're right :)

  1. JSON will stringify NaN and Infinity to null.

Yeah, initially I wanted to write "this is json5, this is corresponding json", but I got this exact issue. Then I thought "hey, I'm using yaml anyway, so why do I need json at all"?

So tests are written using YAML. It supports infinity using +.inf syntax, so if target platform supports yaml, you can just compare output with the result of JSON5.parse(input), and it should work.

If someone converts it all to json, NaN's would be lost of course, so it would be a special case. Maybe do a JSON.stringify(JSON5.parse(input)) == JSON.stringify(output) check or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants