2022-04-24 23:48:50 +02:00
|
|
|
local full_description = "Description Test Item\nFor testing item decription"
|
2024-10-28 15:57:54 +01:00
|
|
|
core.register_tool("unittests:description_test", {
|
2020-10-09 20:11:21 +02:00
|
|
|
description = full_description,
|
2022-04-24 23:48:50 +02:00
|
|
|
inventory_image = "unittests_description_test.png",
|
2022-10-09 14:05:22 +02:00
|
|
|
groups = { dummy = 1 },
|
2020-10-09 20:11:21 +02:00
|
|
|
})
|
|
|
|
|
2024-10-28 15:57:54 +01:00
|
|
|
core.register_chatcommand("item_description", {
|
2020-10-09 20:11:21 +02:00
|
|
|
param = "",
|
|
|
|
description = "Show the short and full description of the wielded item.",
|
|
|
|
func = function(name)
|
2024-10-28 15:57:54 +01:00
|
|
|
local player = core.get_player_by_name(name)
|
2020-10-09 20:11:21 +02:00
|
|
|
local item = player:get_wielded_item()
|
|
|
|
return true, string.format("short_description: %s\ndescription: %s",
|
|
|
|
item:get_short_description(), item:get_description())
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2021-12-18 20:36:43 +01:00
|
|
|
local function test_short_desc()
|
2021-02-17 19:53:44 +01:00
|
|
|
local function get_short_description(item)
|
|
|
|
return ItemStack(item):get_short_description()
|
|
|
|
end
|
|
|
|
|
2022-04-24 23:48:50 +02:00
|
|
|
local stack = ItemStack("unittests:description_test")
|
|
|
|
assert(stack:get_short_description() == "Description Test Item")
|
|
|
|
assert(get_short_description("unittests:description_test") == "Description Test Item")
|
2024-10-28 15:57:54 +01:00
|
|
|
assert(core.registered_items["unittests:description_test"].short_description == nil)
|
2020-10-09 20:11:21 +02:00
|
|
|
assert(stack:get_description() == full_description)
|
2024-10-28 15:57:54 +01:00
|
|
|
assert(stack:get_description() == core.registered_items["unittests:description_test"].description)
|
2020-10-09 20:11:21 +02:00
|
|
|
|
|
|
|
stack:get_meta():set_string("description", "Hello World")
|
2021-02-17 19:53:44 +01:00
|
|
|
assert(stack:get_short_description() == "Hello World")
|
2020-10-09 20:11:21 +02:00
|
|
|
assert(stack:get_description() == "Hello World")
|
2021-02-17 19:53:44 +01:00
|
|
|
assert(get_short_description(stack) == "Hello World")
|
2022-04-24 23:48:50 +02:00
|
|
|
assert(get_short_description("unittests:description_test") == "Description Test Item")
|
2020-10-09 20:11:21 +02:00
|
|
|
|
|
|
|
stack:get_meta():set_string("short_description", "Foo Bar")
|
|
|
|
assert(stack:get_short_description() == "Foo Bar")
|
|
|
|
assert(stack:get_description() == "Hello World")
|
|
|
|
|
|
|
|
return true
|
|
|
|
end
|
2021-12-18 20:36:43 +01:00
|
|
|
unittests.register("test_short_desc", test_short_desc)
|