You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm running the Go port of JSONata against the jsonata-js test suite and a few tests are failing because of assumptions that hold true in JavaScript but not in Go. As the test suite aims to be language-agnostic, it would be good to resolve these issues.
The Problem
The underlying problem is object traversal. When you iterate over an object in JavaScript, the values come back in source order. This code, for example, always outputs "a", "b", and "c" in that order.
This isn't an issue in JSONata itself. The JSON spec defines an object as an unordered list of name/value pairs and that's exactly how Go maps work. However some of the tests in the test suite rely on JavaScript-style object traversal.
Affected Tests
The following tests all traverse objects and put the items into an array. The resulting array is assumed to be in a particular order. This order is not guaranteed in Go (or implied by the JSON spec).
The following tests do the same thing but add a predicate to retrieve a specific item from the array. Again, this relies on the items being in a known order.
The first group of issues could be fixed by adding a flag to the test case JSON. Setting this flag to true would indicate that the order of the test results is unspecified. Or maybe we need a more general field that indicates the type of comparison to use for a test. Unordered array comparison could be one such type.
The second group is more tricky. Combining a predicate with a wildcard like this is non-deterministic in Go. I would recommend moving these tests out of the language-agnostic test suite.
I don't have a suggestion for the last issue but it's the least important of the ones here. I can live with that test failing.
The text was updated successfully, but these errors were encountered:
I'm running the Go port of JSONata against the jsonata-js test suite and a few tests are failing because of assumptions that hold true in JavaScript but not in Go. As the test suite aims to be language-agnostic, it would be good to resolve these issues.
The Problem
The underlying problem is object traversal. When you iterate over an object in JavaScript, the values come back in source order. This code, for example, always outputs "a", "b", and "c" in that order.
In Go, object traversal is randomised. The equivalent Go code returns the same values, but the order is scrambled each time it runs.
This isn't an issue in JSONata itself. The JSON spec defines an object as an unordered list of name/value pairs and that's exactly how Go maps work. However some of the tests in the test suite rely on JavaScript-style object traversal.
Affected Tests
The following tests all traverse objects and put the items into an array. The resulting array is assumed to be in a particular order. This order is not guaranteed in Go (or implied by the JSON spec).
$each(Address, λ($v, $k) {$k & ": " & $v})
$keys(Account)
$keys(Account.Order.Product)
$spread((Account.Order.Product.Description))
foo.*
*[type="home"]
The following tests do the same thing but add a predicate to retrieve a specific item from the array. Again, this relies on the items being in a known order.
foo.*[0]
**[2]
Finally, converting an object to a string can fall foul of the same issue. What order should the fields appear in?
$string({"string": "hello", "number": 78.8 / 2, "null": null, "boolean": false, "function": $sum, "lambda": function(){true}, "object": {"str": "another", "lambda2": function($n){$n}}, "array": []})
Possible Fixes
The first group of issues could be fixed by adding a flag to the test case JSON. Setting this flag to true would indicate that the order of the test results is unspecified. Or maybe we need a more general field that indicates the type of comparison to use for a test. Unordered array comparison could be one such type.
The second group is more tricky. Combining a predicate with a wildcard like this is non-deterministic in Go. I would recommend moving these tests out of the language-agnostic test suite.
I don't have a suggestion for the last issue but it's the least important of the ones here. I can live with that test failing.
The text was updated successfully, but these errors were encountered: