aboutsummaryrefslogtreecommitdiff
path: root/games/minimal/mods
diff options
context:
space:
mode:
Diffstat (limited to 'games/minimal/mods')
-rw-r--r--games/minimal/mods/test/crafting.lua71
-rw-r--r--games/minimal/mods/test/init.lua6
-rw-r--r--games/minimal/mods/test/player.lua48
3 files changed, 75 insertions, 50 deletions
diff --git a/games/minimal/mods/test/crafting.lua b/games/minimal/mods/test/crafting.lua
new file mode 100644
index 000000000..8964bd25a
--- /dev/null
+++ b/games/minimal/mods/test/crafting.lua
@@ -0,0 +1,71 @@
+local function test_clear_craft()
+ minetest.log("info", "Testing clear_craft")
+ -- Clearing by output
+ minetest.register_craft({
+ output = "foo",
+ recipe = {{"bar"}}
+ })
+ minetest.register_craft({
+ output = "foo 4",
+ recipe = {{"foo", "bar"}}
+ })
+ assert(#minetest.get_all_craft_recipes("foo") == 2)
+ minetest.clear_craft({output="foo"})
+ assert(minetest.get_all_craft_recipes("foo") == nil)
+ -- Clearing by input
+ minetest.register_craft({
+ output = "foo 4",
+ recipe = {{"foo", "bar"}}
+ })
+ assert(#minetest.get_all_craft_recipes("foo") == 1)
+ minetest.clear_craft({recipe={{"foo", "bar"}}})
+ assert(minetest.get_all_craft_recipes("foo") == nil)
+end
+test_clear_craft()
+
+local function test_get_craft_result()
+ minetest.log("info", "test_get_craft_result()")
+ -- normal
+ local input = {
+ method = "normal",
+ width = 2,
+ items = {"", "default:coal_lump", "", "default:stick"}
+ }
+ minetest.log("info", "torch crafting input: "..dump(input))
+ local output, decremented_input = minetest.get_craft_result(input)
+ minetest.log("info", "torch crafting output: "..dump(output))
+ minetest.log("info", "torch crafting decremented input: "..dump(decremented_input))
+ assert(output.item)
+ minetest.log("info", "torch crafting output.item:to_table(): "..dump(output.item:to_table()))
+ assert(output.item:get_name() == "default:torch")
+ assert(output.item:get_count() == 4)
+ -- fuel
+ local input = {
+ method = "fuel",
+ width = 1,
+ items = {"default:coal_lump"}
+ }
+ minetest.log("info", "coal fuel input: "..dump(input))
+ local output, decremented_input = minetest.get_craft_result(input)
+ minetest.log("info", "coal fuel output: "..dump(output))
+ minetest.log("info", "coal fuel decremented input: "..dump(decremented_input))
+ assert(output.time)
+ assert(output.time > 0)
+ -- cook
+ local input = {
+ method = "cooking",
+ width = 1,
+ items = {"default:cobble"}
+ }
+ minetest.log("info", "cobble cooking input: "..dump(output))
+ local output, decremented_input = minetest.get_craft_result(input)
+ minetest.log("info", "cobble cooking output: "..dump(output))
+ minetest.log("info", "cobble cooking decremented input: "..dump(decremented_input))
+ assert(output.time)
+ assert(output.time > 0)
+ assert(output.item)
+ minetest.log("info", "cobble cooking output.item:to_table(): "..dump(output.item:to_table()))
+ assert(output.item:get_name() == "default:stone")
+ assert(output.item:get_count() == 1)
+end
+test_get_craft_result()
diff --git a/games/minimal/mods/test/init.lua b/games/minimal/mods/test/init.lua
index 73fb6e6b5..4e2a51086 100644
--- a/games/minimal/mods/test/init.lua
+++ b/games/minimal/mods/test/init.lua
@@ -9,5 +9,7 @@ pseudo = PseudoRandom(13)
assert(pseudo:next() == 22290)
assert(pseudo:next() == 13854)
-dofile(minetest.get_modpath("test") .. "/player.lua")
-dofile(minetest.get_modpath("test") .. "/formspec.lua")
+local modpath = minetest.get_modpath("test")
+dofile(modpath .. "/player.lua")
+dofile(modpath .. "/formspec.lua")
+dofile(modpath .. "/crafting.lua")
diff --git a/games/minimal/mods/test/player.lua b/games/minimal/mods/test/player.lua
index e66539eac..563d0d985 100644
--- a/games/minimal/mods/test/player.lua
+++ b/games/minimal/mods/test/player.lua
@@ -74,51 +74,3 @@ local function run_player_tests(player)
minetest.chat_send_all("All tests pass!")
end
minetest.register_on_joinplayer(run_player_tests)
-
-
-local function test_get_craft_result()
- minetest.log("info", "test_get_craft_result()")
- -- normal
- local input = {
- method = "normal",
- width = 2,
- items = {"", "default:coal_lump", "", "default:stick"}
- }
- minetest.log("info", "torch crafting input: "..dump(input))
- local output, decremented_input = minetest.get_craft_result(input)
- minetest.log("info", "torch crafting output: "..dump(output))
- minetest.log("info", "torch crafting decremented input: "..dump(decremented_input))
- assert(output.item)
- minetest.log("info", "torch crafting output.item:to_table(): "..dump(output.item:to_table()))
- assert(output.item:get_name() == "default:torch")
- assert(output.item:get_count() == 4)
- -- fuel
- local input = {
- method = "fuel",
- width = 1,
- items = {"default:coal_lump"}
- }
- minetest.log("info", "coal fuel input: "..dump(input))
- local output, decremented_input = minetest.get_craft_result(input)
- minetest.log("info", "coal fuel output: "..dump(output))
- minetest.log("info", "coal fuel decremented input: "..dump(decremented_input))
- assert(output.time)
- assert(output.time > 0)
- -- cook
- local input = {
- method = "cooking",
- width = 1,
- items = {"default:cobble"}
- }
- minetest.log("info", "cobble cooking input: "..dump(output))
- local output, decremented_input = minetest.get_craft_result(input)
- minetest.log("info", "cobble cooking output: "..dump(output))
- minetest.log("info", "cobble cooking decremented input: "..dump(decremented_input))
- assert(output.time)
- assert(output.time > 0)
- assert(output.item)
- minetest.log("info", "cobble cooking output.item:to_table(): "..dump(output.item:to_table()))
- assert(output.item:get_name() == "default:stone")
- assert(output.item:get_count() == 1)
-end
-test_get_craft_result()