From 14025771e9f9aea8e12154eeaf5cc58c4d653c24 Mon Sep 17 00:00:00 2001 From: Thomas Harning Jr Date: Tue, 23 Jun 2009 23:42:37 -0400 Subject: [PATCH] tests: adds encoding test for circular/non-circular duplicate values Reporter: Marcus Irven --- tests/lunit-encoding.lua | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 tests/lunit-encoding.lua diff --git a/tests/lunit-encoding.lua b/tests/lunit-encoding.lua new file mode 100644 index 0000000..bdeb1c2 --- /dev/null +++ b/tests/lunit-encoding.lua @@ -0,0 +1,52 @@ +local json = require("json") +local lunit = require("lunit") + +module("lunit-encoding", lunit.testcase, package.seeall) + +function test_cloned_array_sibling() + local obj = {} + assert_pass(function() + json.encode({obj, obj}) + end) +end + +function test_cloned_object_sibling() + local obj = {} + assert_pass(function() + json.encode({x = obj, y = obj}) + end) +end + +function test_cloned_array_deep_sibling() + local obj = {} + assert_pass(function() + json.encode({ + {obj}, {obj} + }) + end) +end + +function test_cloned_array_multilevel_sibling() + local obj = {} + assert_pass(function() + json.encode({ + {obj, {obj}} + }) + end) +end + +function test_recursive_object() + local obj = {} + obj.x = obj + assert_error(function() + json.encode(obj) + end) +end + +function test_recursive_array() + local obj = {} + obj[1] = obj + assert_error(function() + json.encode(obj) + end) +end -- 2.11.4.GIT