]> git.lizzy.rs Git - dragonfireclient.git/blob - games/devtest/mods/unittests/itemdescription.lua
Merge pull request #59 from PrairieAstronomer/readme_irrlicht_change
[dragonfireclient.git] / games / devtest / mods / unittests / itemdescription.lua
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",
5 })
6
7 minetest.register_chatcommand("item_description", {
8         param = "",
9         description = "Show the short and full description of the wielded item.",
10         func = function(name)
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())
15         end
16 })
17
18 local function test_short_desc()
19         local function get_short_description(item)
20                 return ItemStack(item):get_short_description()
21         end
22
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)
29
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")
35
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")
39
40         return true
41 end
42 unittests.register("test_short_desc", test_short_desc)