aboutsummaryrefslogtreecommitdiff
path: root/advtrains_interlocking/spec
diff options
context:
space:
mode:
Diffstat (limited to 'advtrains_interlocking/spec')
l---------advtrains_interlocking/spec/fixtures/advtrains_helpers.lua1
-rw-r--r--advtrains_interlocking/spec/mineunit.conf0
-rw-r--r--advtrains_interlocking/spec/signal_api_spec.lua50
3 files changed, 51 insertions, 0 deletions
diff --git a/advtrains_interlocking/spec/fixtures/advtrains_helpers.lua b/advtrains_interlocking/spec/fixtures/advtrains_helpers.lua
new file mode 120000
index 0000000..9b0ab67
--- /dev/null
+++ b/advtrains_interlocking/spec/fixtures/advtrains_helpers.lua
@@ -0,0 +1 @@
+../../../advtrains/helpers.lua \ No newline at end of file
diff --git a/advtrains_interlocking/spec/mineunit.conf b/advtrains_interlocking/spec/mineunit.conf
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/advtrains_interlocking/spec/mineunit.conf
diff --git a/advtrains_interlocking/spec/signal_api_spec.lua b/advtrains_interlocking/spec/signal_api_spec.lua
new file mode 100644
index 0000000..2659380
--- /dev/null
+++ b/advtrains_interlocking/spec/signal_api_spec.lua
@@ -0,0 +1,50 @@
+require("mineunit")
+
+mineunit("core")
+
+_G.advtrains = {
+ interlocking = {
+ aspects = sourcefile("signal_aspects"),
+ --aspects = fixture("../../signal_aspects"),
+ },
+ ndb = {
+ get_node = minetest.get_node,
+ }
+}
+
+fixture("advtrains_helpers")
+fixture("../../database")
+sourcefile("signal_api")
+
+local stub_aspect_t1 = { main = math.random() }
+local stub_pos_t1 = {x = 1, y = 0, z = 1}
+
+minetest.register_node(":stubsignal_t1", {
+ advtrains = {
+ supported_aspects = {},
+ get_aspect = function () return stub_aspect_t1 end,
+ set_aspect = function () end,
+ },
+ groups = { advtrains_signal = 2 },
+})
+
+world.layout {
+ {stub_pos_t1, "stubsignal_t1"},
+}
+
+describe("API for supposed signal aspects", function()
+ it("should load and save data properly", function()
+ local tbl = {_foo = true}
+ advtrains.interlocking.load_supposed_aspects(tbl)
+ assert.same(tbl, advtrains.interlocking.save_supposed_aspects())
+ end)
+ it("should set and get type 1 signals properly", function ()
+ local pos = stub_pos_t1
+ local asp = stub_aspect_t1
+ local newasp = { dst = math.random() }
+ assert.same(asp, advtrains.interlocking.signal_get_aspect(pos))
+ advtrains.interlocking.signal_set_aspect(pos, newasp)
+ assert.same(newasp, advtrains.interlocking.signal_get_aspect(pos))
+ assert.same(asp, advtrains.interlocking.signal_get_real_aspect(pos))
+ end)
+end)