From 04c11f9536463efa563174dc12e454c6750c20b9 Mon Sep 17 00:00:00 2001 From: ywang Date: Thu, 5 Aug 2021 13:26:20 +0200 Subject: Add scheduling commands --- advtrains/spec/atcjit_spec.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'advtrains/spec/atcjit_spec.lua') diff --git a/advtrains/spec/atcjit_spec.lua b/advtrains/spec/atcjit_spec.lua index 638e5c8..62896e4 100644 --- a/advtrains/spec/atcjit_spec.lua +++ b/advtrains/spec/atcjit_spec.lua @@ -1,10 +1,17 @@ package.path = "../?.lua;" .. package.path advtrains = {} +minetest = {} _G.advtrains = advtrains +_G.minetest = minetest function _G.attrans(...) return ... end function advtrains.invert_train() end function advtrains.train_ensure_init() end +local on_mods_loaded = function() end +function minetest.register_on_mods_loaded(f) + on_mods_loaded = f +end + local atcjit = require("atcjit") local function assert_atc(train, warn, err, res) @@ -176,4 +183,36 @@ describe("ATC track that sets ARS modes", function() thisatc("should enable ARS on the train with A1", t, {}, nil, {atc_wait_finish=true, ars_disable=false, atc_command="AFWAT"}) thisatc("should disable ARS on the train with AF", t, {}, nil, {atc_wait_finish=true, ars_disable=true, atc_command="AT"}) thisatc("should enable ARS on the train with AT", t, {}, nil, {atc_wait_finish=true, ars_disable=false,}) +end) + +insulate("ATC scheduling commands without line automation", function() + _G.os.time = function() return 12 end + local t = {atc_command = "Ds+5Ds20+10W"} + thisatc("should do the same as D5", t, {}, nil, {atc_delay=5, atc_command="Ds20+10W"}) + thisatc("should do the same as D15", t, {}, nil, {atc_delay=18, atc_command="W"}) +end) + +insulate("ATC scheduling commands with line automation", function() + advtrains.lines = { + rwt = mock{ + now = function() return 12 end, + next_rpt = function(n, i, o) return n+i-(n-o)%i end, + }, + sched = mock{ + enqueue = function() end, + enqueue_in = function() end, + register_callback = function() end, + }, + } + local rwt, sched = advtrains.lines.rwt, advtrains.lines.sched + on_mods_loaded() + it("should have line automation modules loaded", function() assert.stub(sched.register_callback).was.called() end) + it("should schedule the train in 0;05", function() + assert_atc({id="foo", atc_command="Ds+5W", atc_arrow = true}, {}, nil, {id="foo", atc_arrow=true}) + assert.stub(sched.enqueue_in).was.called_with(5, "atcjit", {trainid="foo", cmd="W", arrow=true}, "atcjit-foo", 1) + end) + it("should schedule the train at 0;25", function() + assert_atc({id="bar", atc_command="Ds20+5W", atc_arrow = true}, {}, nil, {id="bar", atc_arrow=true}) + assert.stub(sched.enqueue).was.called_with(25, "atcjit", {trainid="bar", cmd="W", arrow=true}, "atcjit-bar", 1) + end) end) \ No newline at end of file -- cgit v1.2.3