aboutsummaryrefslogtreecommitdiff
path: root/games/devtest
diff options
context:
space:
mode:
author20kdc <asdd2808@gmail.com>2022-09-28 14:06:14 +0100
committerGitHub <noreply@github.com>2022-09-28 09:06:14 -0400
commitb1233056b76aa803123cc304d323887ad5fdfbae (patch)
treee8e1417a20614347f2ca9bee32f12c7d63294825 /games/devtest
parent0251b01da66a67ed84f8d27c33aa35f34aaca237 (diff)
downloadminetest-b1233056b76aa803123cc304d323887ad5fdfbae.tar.xz
Add zstd compression support (#12515)
Diffstat (limited to 'games/devtest')
-rw-r--r--games/devtest/mods/unittests/misc.lua23
1 files changed, 23 insertions, 0 deletions
diff --git a/games/devtest/mods/unittests/misc.lua b/games/devtest/mods/unittests/misc.lua
index 4811c8008..8ac3ed110 100644
--- a/games/devtest/mods/unittests/misc.lua
+++ b/games/devtest/mods/unittests/misc.lua
@@ -80,3 +80,26 @@ unittests.register("test_punch_node", function(_, pos)
minetest.remove_node(pos)
-- currently failing: assert(on_punch_called)
end, {map=true})
+
+local function test_compress()
+ -- This text should be compressible, to make sure the results are... normal
+ local text = "The\000 icey canoe couldn't move very well on the\128 lake. The\000 ice was too stiff and the icey canoe's paddles simply wouldn't punch through."
+ local methods = {
+ "deflate",
+ "zstd",
+ -- "noodle", -- for warning alarm test
+ }
+ local zstd_magic = string.char(0x28, 0xB5, 0x2F, 0xFD)
+ for _, method in ipairs(methods) do
+ local compressed = core.compress(text, method)
+ assert(core.decompress(compressed, method) == text, "input/output mismatch for compression method " .. method)
+ local has_zstd_magic = compressed:sub(1, 4) == zstd_magic
+ if method == "zstd" then
+ assert(has_zstd_magic, "zstd magic number not in zstd method")
+ else
+ assert(not has_zstd_magic, "zstd magic number in method " .. method .. " (which is not zstd)")
+ end
+ end
+end
+unittests.register("test_compress", test_compress)
+