forked from dannydark/unifiedinventory
-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathunittests.lua
More file actions
72 lines (61 loc) · 1.58 KB
/
Copy pathunittests.lua
File metadata and controls
72 lines (61 loc) · 1.58 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
core.log("error", "[unified_inventory] Unittests are enabled!")
local ui = unified_inventory
core.register_craftitem(":uitest:leaves", {
description = "UITEST Leaves",
inventory_image = "default_leaves.png",
})
core.register_craftitem(":uitest:apple", {
description = "UITEST Apple",
inventory_image = "default_apple.png",
})
core.register_craftitem(":uitest:stick", {
description = "UITEST Stick",
inventory_image = "default_stick.png",
})
do
ui.register_craft({
type = "digging_chance",
items = {"uitest:leaves"},
output = ItemStack("uitest:apple 2"),
width = 0,
})
ui.register_craft({
type = "digging_chance",
items = {"uitest:leaves"},
output = { ItemStack("uitest:apple 1"), "uitest:stick 3" },
width = 0,
})
end
local function find_recipe_output(recipes, output)
for _, recipe in ipairs(recipes) do
if type(recipe.output) == "table" then
-- get_recipe_list2(..)
for _, itemstack in ipairs(recipe.output) do
if itemstack:to_string() == output then
return recipe
end
end
else
-- get_recipe_list(..)
if recipe.output == output then
return recipe
end
end
end
return nil
end
local function run_tests()
local list, match
list = ui.get_recipe_list2("uitest:apple")
assert(#list == 2)
match = assert(find_recipe_output(list, "uitest:stick 3"))
assert(match.items[1] == "uitest:leaves")
-- Backwards compat
list = ui.get_recipe_list("uitest:apple")
assert(#list == 1)
match = assert(find_recipe_output(list, "uitest:apple 2"))
assert(match.items[1] == "uitest:leaves")
-- Done
error("Tests passed!")
end
core.after(1, run_tests)