From 609105e091b0853b68e24770674993dc18acc111 Mon Sep 17 00:00:00 2001 From: Nils Dagsson Moskopp Date: Mon, 6 Dec 2021 03:34:44 +0100 Subject: [PATCH] Add test cases for get_tool_name() --- mods/HUD/mcl_death_messages/init.lua | 92 ++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index 837238b5..2f115823 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -11,6 +11,98 @@ local function get_tool_name(item) return sanitized_name end +local test_tool_1a = { + get_meta = function() + return { + get_string = function() + return "foo 1a" + end + } + end +} + +assert( get_tool_name(test_tool_1a) == "foo 1a" ) + +local test_tool_1b = { + get_meta = function() + return { + get_string = function() + return "bar\rbaz\n1b" + end + } + end +} + +assert( get_tool_name(test_tool_1b) == "bar baz 1b" ) + +local test_tool_2a = { + get_definition = function() + return { + _tt_original_description = "foo 2a" + } + end, + get_meta = function() + return { + get_string = function() + return "" + end + } + end +} + +assert( get_tool_name(test_tool_2a) == "foo 2a" ) + +local test_tool_2b = { + get_definition = function() + return { + _tt_original_description = "bar\rbaz\n2b" + } + end, + get_meta = function() + return { + get_string = function() + return "" + end + } + end +} + +assert( get_tool_name(test_tool_2b) == "bar baz 2b" ) + +local test_tool_3a = { + get_definition = function() + return { + description = "foo 3a" + } + end, + get_meta = function() + return { + get_string = function() + return "" + end + } + end +} + +assert( get_tool_name(test_tool_3a) == "foo 3a" ) + +local test_tool_3b = { + get_definition = function() + return { + description = "bar\rbaz\n3b" + } + end, + get_meta = function() + return { + get_string = function() + return "" + end + } + end +} + +assert( get_tool_name(test_tool_3b) == "bar baz 3b" ) + mcl_death_messages = {} -- Death messages