diff options
-rw-r--r-- | lua_cjson.c | 2 | ||||
-rw-r--r-- | tests/agentzh.t | 15 | ||||
-rwxr-xr-x | tests/test.lua | 2 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lua_cjson.c b/lua_cjson.c index 97f2350..5ff3bf7 100644 --- a/lua_cjson.c +++ b/lua_cjson.c | |||
@@ -299,7 +299,7 @@ static int json_cfg_encode_number_precision(lua_State *l) | |||
299 | { | 299 | { |
300 | json_config_t *cfg = json_arg_init(l, 1); | 300 | json_config_t *cfg = json_arg_init(l, 1); |
301 | 301 | ||
302 | return json_integer_option(l, 1, &cfg->encode_number_precision, 1, 14); | 302 | return json_integer_option(l, 1, &cfg->encode_number_precision, 1, 16); |
303 | } | 303 | } |
304 | 304 | ||
305 | /* Configures how to treat empty table when encode lua table */ | 305 | /* Configures how to treat empty table when encode lua table */ |
diff --git a/tests/agentzh.t b/tests/agentzh.t index e65288f..0b546ff 100644 --- a/tests/agentzh.t +++ b/tests/agentzh.t | |||
@@ -50,3 +50,18 @@ print(cjson.encode(b)) | |||
50 | --- out | 50 | --- out |
51 | ["a=1&b=2"] | 51 | ["a=1&b=2"] |
52 | 52 | ||
53 | |||
54 | |||
55 | === TEST 5: default and max precision | ||
56 | --- lua | ||
57 | local math = require "math" | ||
58 | local cjson = require "cjson" | ||
59 | local double = math.pow(2, 53) | ||
60 | print(cjson.encode(double)) | ||
61 | cjson.encode_number_precision(16) | ||
62 | print(cjson.encode(double)) | ||
63 | print(string.format("%16.0f", cjson.decode("9007199254740992"))) | ||
64 | --- out | ||
65 | 9.007199254741e+15 | ||
66 | 9007199254740992 | ||
67 | 9007199254740992 | ||
diff --git a/tests/test.lua b/tests/test.lua index b8fce84..c96dd3d 100755 --- a/tests/test.lua +++ b/tests/test.lua | |||
@@ -361,7 +361,7 @@ local cjson_tests = { | |||
361 | -- Function is listed as '?' due to pcall | 361 | -- Function is listed as '?' due to pcall |
362 | { "Set encode_number_precision(0) [throw error]", | 362 | { "Set encode_number_precision(0) [throw error]", |
363 | json.encode_number_precision, { 0 }, | 363 | json.encode_number_precision, { 0 }, |
364 | false, { "bad argument #1 to '?' (expected integer between 1 and 14)" } }, | 364 | false, { "bad argument #1 to '?' (expected integer between 1 and 16)" } }, |
365 | { "Set encode_number_precision(\"five\") [throw error]", | 365 | { "Set encode_number_precision(\"five\") [throw error]", |
366 | json.encode_number_precision, { "five" }, | 366 | json.encode_number_precision, { "five" }, |
367 | false, { "bad argument #1 to '?' (number expected, got string)" } }, | 367 | false, { "bad argument #1 to '?' (number expected, got string)" } }, |