sile / jsone

Erlang JSON library
MIT License
291 stars 71 forks source link

Tests Assuming `maps:to_list/1` Order Are Failing #84

Closed dw-kihara closed 3 months ago

dw-kihara commented 3 months ago

The function maps:to_list/1 documentation states that it returns key-value pairs in an arbitrary order. However, some tests assume a specific order and hard-code the resulting JSON with a definite order. This causes the tests to fail when the order is different.

When I tried OTP27, the eunit tests failed as follows.

Test code (one example):

?assertEqual({ok, <<"{\"a\": 1, \"b\": 2}">>}, jsone_encode:encode(?OBJ2(a, 1, b, 2), [{space, 1}])),

Result:

...
  1) jsone_encode_tests:-encode_test_/0-anonymous-37-/0: space
     Failure/Error: ?assertEqual({ok,<<123,34,97,34,58,32,49,44,32,34,98,34,58,32,50,125>>}, jsone_encode : encode ( ? OBJ2 ( a , 1 , b , 2 ) , [ { space , 1 } ] ))
       expected: {ok,<<"{\"a\": 1, \"b\": 2}">>}
            got: {ok,<<"{\"b\": 2, \"a\": 1}">>}
     %% eunit_proc.erl:583:in `eunit_proc:run_group/2`
     Output:
     Output:
...

I'm sorry I don't know what is the best way to fix it, so I wrote this issue instead of writing a pull request.

sile commented 3 months ago

Thank you for creating this issue. I'll fix the failures soon.

dw-kihara commented 3 months ago

Thank you for fixing!