diff options
author | lijunlong <lijunlong@openresty.com> | 2023-02-22 11:28:15 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-22 11:28:15 +0800 |
commit | de93a78d3002ee72bb1c7e3a629d67e19623a4ae (patch) | |
tree | fddd9ba083aae1c3f58868e313aa0540885951b8 /tests | |
parent | 1dff61d9bf390372124c13443e0131a96383f5bc (diff) | |
download | lua-cjson-de93a78d3002ee72bb1c7e3a629d67e19623a4ae.tar.gz lua-cjson-de93a78d3002ee72bb1c7e3a629d67e19623a4ae.tar.bz2 lua-cjson-de93a78d3002ee72bb1c7e3a629d67e19623a4ae.zip |
feature: Add option to skip invalid value types.
Co-authored-by: Jesper Lundgren <jesperlundgren@exosite.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/agentzh.t | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/agentzh.t b/tests/agentzh.t index 2e7c8ce..552630a 100644 --- a/tests/agentzh.t +++ b/tests/agentzh.t | |||
@@ -306,3 +306,29 @@ print(b) | |||
306 | {"test":"http:\/\/google.com\/google"} | 306 | {"test":"http:\/\/google.com\/google"} |
307 | {"test":"http://google.com/google"} | 307 | {"test":"http://google.com/google"} |
308 | {"test":"http:\/\/google.com\/google"} | 308 | {"test":"http:\/\/google.com\/google"} |
309 | |||
310 | |||
311 | |||
312 | === TEST 22: disable error on invalid type | ||
313 | --- lua | ||
314 | local cjson = require "cjson" | ||
315 | local f = function (x) return 2*x end | ||
316 | local res, err = pcall(cjson.encode, f) | ||
317 | print(err) | ||
318 | local t = {f = f, valid = "valid"} | ||
319 | local res, err = pcall(cjson.encode, t) | ||
320 | print(err) | ||
321 | local arr = {"one", "two", f, "three"} | ||
322 | local res, err = pcall(cjson.encode, arr) | ||
323 | print(err) | ||
324 | cjson.encode_skip_unsupported_value_types(true) | ||
325 | print(cjson.encode(f)) | ||
326 | print(cjson.encode(t)) | ||
327 | print(cjson.encode(arr)) | ||
328 | --- out | ||
329 | Cannot serialise function: type not supported | ||
330 | Cannot serialise function: type not supported | ||
331 | Cannot serialise function: type not supported | ||
332 | |||
333 | {"valid":"valid"} | ||
334 | ["one","two","three"] | ||