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

JSON value s11n unit tests #603

Merged
merged 1 commit into from
Sep 11, 2018
Merged

JSON value s11n unit tests #603

merged 1 commit into from
Sep 11, 2018

Conversation

tjanc
Copy link
Contributor

@tjanc tjanc commented Sep 10, 2018

Includes minor fixes; not all corner cases are covered by integration tests.

}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add tests for Nan and Inf

Copy link
Contributor

Choose a reason for hiding this comment

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

For NumberElement

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use the JSON definition of number, Nan and Inf are not numbers.

Copy link
Contributor

Choose a reason for hiding this comment

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

But you can set value of NumberElement to Nan/Inf, isn't it?
There should be, at least, defined bahavior for this case

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can theoretically construct a NumberElement with any string now, as the check for JSON Number is in Serialize.cc. But it will have undefined behaviour, so I'm not sure what to test against. Finding something non-numberish in a NumberElement could be handled as an assert in JsonValue.cc.

Copy link
Contributor

Choose a reason for hiding this comment

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

On other side refract is not strictly for JSON, so we should define what happens. e.g. conversion to zero?
Not sure, just idea

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is the relevant issue on the MSON spec not being spec enough: apiaryio/mson#93
In API Elements ("refract") we are pretty clear: https://github.com/apiaryio/api-elements/blob/master/docs/element-definitions.md#values
We could add a debug build run time check during JSON serialization (not JSON value serialization), although I don't deem that necessary. Here are the tests currently covering your worries: https://github.com/apiaryio/drafter/blob/master/test/test-Serialize.cc#L931

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok. Let it pass for now and create issue to resolve this

@klokane
Copy link
Contributor

klokane commented Sep 11, 2018

👍 great coverage of testcases

@tjanc tjanc merged commit 3b79d8e into master Sep 11, 2018
@tjanc tjanc deleted the tjanc/json-value-tests branch September 11, 2018 14:58
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.

None yet

2 participants