From 4d60fa2a08523a2bdd767f1889cc2a1ac5224282 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Wed, 13 Feb 2013 21:54:09 -0800 Subject: [PATCH] add special number tests for floats and integers that have different representation in erlang and json --- src/jsx_decoder.erl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/jsx_decoder.erl b/src/jsx_decoder.erl index 2faf5db..b5c7069 100644 --- a/src/jsx_decoder.erl +++ b/src/jsx_decoder.erl @@ -1024,6 +1024,41 @@ done(Bin, Handler, Stack, Config) -> ?error([Bin, Handler, Stack, Config]). -include_lib("eunit/include/eunit.hrl"). +%% all these numbers have different representation in erlang than in javascript and +%% do not roundtrip like most integers/floats +special_number_test_() -> + [ + {"-0", ?_assertEqual( + [{integer, 0}, end_json], + start(<<"-0">>, {jsx, []}, [], #config{}) + )}, + {"-0.0", ?_assertEqual( + [{float, 0.0}, end_json], + start(<<"-0.0">>, {jsx, []}, [], #config{}) + )}, + {"0e0", ?_assertEqual( + [{float, 0.0}, end_json], + start(<<"0e0">>, {jsx, []}, [], #config{}) + )}, + {"0e4", ?_assertEqual( + [{float, 0.0}, end_json], + start(<<"0e4">>, {jsx, []}, [], #config{}) + )}, + {"1e0", ?_assertEqual( + [{float, 1.0}, end_json], + start(<<"1e0">>, {jsx, []}, [], #config{}) + )}, + {"-1e0", ?_assertEqual( + [{float, -1.0}, end_json], + start(<<"-1e0">>, {jsx, []}, [], #config{}) + )}, + {"1e4", ?_assertEqual( + [{float, 1.0e4}, end_json], + start(<<"1e4">>, {jsx, []}, [], #config{}) + )} + ]. + + xcode(Bin) -> xcode(Bin, []). xcode(Bin, Config) ->