Skip to content

Conversation

@davidlehn
Copy link
Contributor

  • Improving the test coverage for use useNativeTypes algorithm in 8.5.2 2.4.
  • Remove the "True" and "False" boolean tests that can cause confusion that those words are special values.
  • Add tests using a value of "notnative" typed to boolean, integer, and double. These test that the type will be preserved when a native conversion does not happen.

I was fixing jsonld.js for fromRdf#t0027 and thought the tests could use some work to increase covearge.

https://github.com/w3c/json-ld-api/blob/main/tests/fromRdf/0027-in.nq
https://github.com/w3c/json-ld-api/blob/main/tests/fromRdf/0027-out.jsonld

I initially mistakenly tried to add specific support for the "True"/"False" tests:

<http://example.com/boolean-object> <http://example.com/example> "True"^^<http://www.w3.org/2001/XMLSchema#boolean> .
<http://example.com/boolean-object> <http://example.com/example> "False"^^<http://www.w3.org/2001/XMLSchema#boolean> .

But those are, I think, just testing that any not-native value is passed through even though it may not match semantics of the type. I think some other value text should be used to avoid confusion. For consistency, it probably makes sense to have similar tests for integers and doubles. jsonld.js was dropping the type for non-integers typed as integers.

There might be other edge cases that should be tested here too. This does seem like an incremental improvement.

Possible relevant references:
https://w3c.github.io/json-ld-api/#algorithm-16
#555
#656
#619
#625
#662

- Improving the test coverage for use useNativeTypes algorithm in 8.5.2
  2.4.
- Remove the "True" and "False" boolean tests that can cause confusion
  that those words are special values.
- Add tests using a value of "notnative" typed to boolean, integer, and
  double. These test that the type will be preserved when a native
  conversion does not happen.
@filip26
Copy link
Contributor

filip26 commented Oct 29, 2025

I see it now, the original test suite only considered "true" and "false" as valid values for xsd:boolean, but since xsd:boolean also accepts "0" and "1", the test was later updated accordingly.

I would keep the "True" and "False" tests, as they ensure that no implementation is performing a case-insensitive comparison like:

"true".equalsIgnoreCase(object)

which could incorrectly coerce capitalized "True" or "False" into the native boolean type. These values are not valid according to the xsd:boolean definition and therefore should remain as-is, without conversion.

Restoring True and False tests to check only strict lexical values are
converted to native values.
@davidlehn
Copy link
Contributor Author

I would keep the "True" and "False" tests, as they ensure that no implementation is performing a case-insensitive comparison like: [...]

Ok. More tests are always good. Hopefully others don't get confused like I did and try to special case those values.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants