blob: b4c218c987cda689f8557252a61611b816a68000 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
local full_description = "Description Test Item\nFor testing item decription"
minetest.register_tool("unittests:description_test", {
description = full_description,
inventory_image = "unittests_description_test.png",
})
minetest.register_chatcommand("item_description", {
param = "",
description = "Show the short and full description of the wielded item.",
func = function(name)
local player = minetest.get_player_by_name(name)
local item = player:get_wielded_item()
return true, string.format("short_description: %s\ndescription: %s",
item:get_short_description(), item:get_description())
end
})
local function test_short_desc()
local function get_short_description(item)
return ItemStack(item):get_short_description()
end
local stack = ItemStack("unittests:description_test")
assert(stack:get_short_description() == "Description Test Item")
assert(get_short_description("unittests:description_test") == "Description Test Item")
assert(minetest.registered_items["unittests:description_test"].short_description == nil)
assert(stack:get_description() == full_description)
assert(stack:get_description() == minetest.registered_items["unittests:description_test"].description)
stack:get_meta():set_string("description", "Hello World")
assert(stack:get_short_description() == "Hello World")
assert(stack:get_description() == "Hello World")
assert(get_short_description(stack) == "Hello World")
assert(get_short_description("unittests:description_test") == "Description Test Item")
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
unittests.register("test_short_desc", test_short_desc)
|