diff --git a/mods/HUD/mcl_death_messages/init.lua b/mods/HUD/mcl_death_messages/init.lua index aed8c770..2f115823 100644 --- a/mods/HUD/mcl_death_messages/init.lua +++ b/mods/HUD/mcl_death_messages/init.lua @@ -7,9 +7,102 @@ local function get_tool_name(item) local def = item:get_definition() name=def._tt_original_description or def.description end - return name:gsub("[\r\n]"," ") + local sanitized_name, substitution_count = name:gsub("[\r\n]"," ") + 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