1 local full_description = "Description Test Item\nFor testing item decription"
2 minetest.register_tool("unittests:description_test", {
3 description = full_description,
4 inventory_image = "unittests_description_test.png",
7 minetest.register_chatcommand("item_description", {
9 description = "Show the short and full description of the wielded item.",
11 local player = minetest.get_player_by_name(name)
12 local item = player:get_wielded_item()
13 return true, string.format("short_description: %s\ndescription: %s",
14 item:get_short_description(), item:get_description())
18 local function test_short_desc()
19 local function get_short_description(item)
20 return ItemStack(item):get_short_description()
23 local stack = ItemStack("unittests:description_test")
24 assert(stack:get_short_description() == "Description Test Item")
25 assert(get_short_description("unittests:description_test") == "Description Test Item")
26 assert(minetest.registered_items["unittests:description_test"].short_description == nil)
27 assert(stack:get_description() == full_description)
28 assert(stack:get_description() == minetest.registered_items["unittests:description_test"].description)
30 stack:get_meta():set_string("description", "Hello World")
31 assert(stack:get_short_description() == "Hello World")
32 assert(stack:get_description() == "Hello World")
33 assert(get_short_description(stack) == "Hello World")
34 assert(get_short_description("unittests:description_test") == "Description Test Item")
36 stack:get_meta():set_string("short_description", "Foo Bar")
37 assert(stack:get_short_description() == "Foo Bar")
38 assert(stack:get_description() == "Hello World")
42 unittests.register("test_short_desc", test_short_desc)