From 58edf03aaf964d526e02af120fe4955a6e784706 Mon Sep 17 00:00:00 2001 From: Jude Melton-Houghton Date: Sun, 5 Jun 2022 15:06:50 -0400 Subject: [PATCH] Add screwdriver test --- .test_fixtures/mesecons.lua | 1 + mesecons/spec/service_spec.lua | 46 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/.test_fixtures/mesecons.lua b/.test_fixtures/mesecons.lua index 302ea3f..c07cfb3 100644 --- a/.test_fixtures/mesecons.lua +++ b/.test_fixtures/mesecons.lua @@ -93,6 +93,7 @@ do }} mesecon.register_node("mesecons:test_conductor_rot", { description = "Rotatable Test Conductor", + on_rotate = mesecon.on_rotate_horiz, }, {mesecons = off_spec}, {mesecons = on_spec}) end diff --git a/mesecons/spec/service_spec.lua b/mesecons/spec/service_spec.lua index dc6ed18..097c285 100644 --- a/mesecons/spec/service_spec.lua +++ b/mesecons/spec/service_spec.lua @@ -1,6 +1,7 @@ require("mineunit") fixture("mesecons") +fixture("screwdriver") describe("placement/digging service", function() local layout = { @@ -138,3 +139,48 @@ describe("overheating service", function() assert.equal(0, mesecon.get_heat(layout[2][1])) end) end) + +describe("screwdriver service", function() + local layout = { + {{x = 0, y = 0, z = 0}, "mesecons:test_conductor_rot_on"}, + {{x = 1, y = 0, z = 0}, "mesecons:test_receptor_on"}, + {{x = -1, y = 0, z = 0}, "mesecons:test_conductor_on"}, + {{x = 0, y = 0, z = 1}, "mesecons:test_receptor_on"}, + {{x = 0, y = 0, z = -1}, "mesecons:test_conductor_off"}, + } + + local function rotate(new_param2) + local pos = layout[1][1] + local node = world.get_node(pos) + local on_rotate = minetest.registered_nodes[node.name].on_rotate + on_rotate(pos, node, nil, screwdriver.ROTATE_FACE, new_param2) + end + + before_each(function() + world.layout(layout) + end) + + after_each(function() + mesecon._test_reset() + world.clear() + end) + + it("updates conductors", function() + rotate(1) + mineunit:execute_globalstep() + assert.equal("mesecons:test_conductor_off", world.get_node(layout[3][1]).name) + assert.equal("mesecons:test_conductor_on", world.get_node(layout[5][1]).name) + rotate(2) + mineunit:execute_globalstep() + assert.equal("mesecons:test_conductor_on", world.get_node(layout[3][1]).name) + assert.equal("mesecons:test_conductor_off", world.get_node(layout[5][1]).name) + rotate(3) + mineunit:execute_globalstep() + assert.equal("mesecons:test_conductor_off", world.get_node(layout[3][1]).name) + assert.equal("mesecons:test_conductor_on", world.get_node(layout[5][1]).name) + rotate(0) + mineunit:execute_globalstep() + assert.equal("mesecons:test_conductor_on", world.get_node(layout[3][1]).name) + assert.equal("mesecons:test_conductor_off", world.get_node(layout[5][1]).name) + end) +end)