aboutsummaryrefslogtreecommitdiff
path: root/games/devtest/mods/unittests/async_env.lua
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-05-10 16:37:33 -0400
committerGitHub <noreply@github.com>2022-05-10 22:37:33 +0200
commit7f58887ae33893c981fbdff23d4e1fa4a11c32e4 (patch)
tree5705ee5c5f6c2f1b3c1380d0fba2d01205c5455d /games/devtest/mods/unittests/async_env.lua
parentd17d7eba14f6a1328a3b58ee086df5ffa56304d6 (diff)
downloadminetest-7f58887ae33893c981fbdff23d4e1fa4a11c32e4.tar.gz
minetest-7f58887ae33893c981fbdff23d4e1fa4a11c32e4.tar.bz2
minetest-7f58887ae33893c981fbdff23d4e1fa4a11c32e4.zip
Support packing arbitrary graphs (#12289)
Diffstat (limited to 'games/devtest/mods/unittests/async_env.lua')
-rw-r--r--games/devtest/mods/unittests/async_env.lua37
1 files changed, 28 insertions, 9 deletions
diff --git a/games/devtest/mods/unittests/async_env.lua b/games/devtest/mods/unittests/async_env.lua
index aff1fc4d9..3a21bd9e2 100644
--- a/games/devtest/mods/unittests/async_env.lua
+++ b/games/devtest/mods/unittests/async_env.lua
@@ -60,15 +60,34 @@ local function test_object_passing()
local tmp = core.serialize_roundtrip(test_object)
assert(deepequal(test_object, tmp))
- -- Circular key, should error
- tmp = {"foo", "bar"}
- tmp[tmp] = true
- assert(not pcall(core.serialize_roundtrip, tmp))
-
- -- Circular value, should error
- tmp = {"foo"}
- tmp[2] = tmp
- assert(not pcall(core.serialize_roundtrip, tmp))
+ local circular_key = {"foo", "bar"}
+ circular_key[circular_key] = true
+ tmp = core.serialize_roundtrip(circular_key)
+ assert(tmp[1] == "foo")
+ assert(tmp[2] == "bar")
+ assert(tmp[tmp] == true)
+
+ local circular_value = {"foo"}
+ circular_value[2] = circular_value
+ tmp = core.serialize_roundtrip(circular_value)
+ assert(tmp[1] == "foo")
+ assert(tmp[2] == tmp)
+
+ -- Two-segment cycle
+ local cycle_seg_1, cycle_seg_2 = {}, {}
+ cycle_seg_1[1] = cycle_seg_2
+ cycle_seg_2[1] = cycle_seg_1
+ tmp = core.serialize_roundtrip(cycle_seg_1)
+ assert(tmp[1][1] == tmp)
+
+ -- Duplicated value without a cycle
+ local acyclic_dup_holder = {}
+ tmp = ItemStack("")
+ acyclic_dup_holder[tmp] = tmp
+ tmp = core.serialize_roundtrip(acyclic_dup_holder)
+ for k, v in pairs(tmp) do
+ assert(rawequal(k, v))
+ end
end
unittests.register("test_object_passing", test_object_passing)