aboutsummaryrefslogtreecommitdiff
path: root/advtrains/tests
diff options
context:
space:
mode:
authorywang <yw05@forksworld.de>2021-02-02 17:13:04 +0100
committerywang <yw05@forksworld.de>2021-08-04 21:25:19 +0200
commit2c4e4f80c89f403f6387358568d66a3dd5db8000 (patch)
tree9f213815fc37ee12fae317e994d2bb8d30d6a91b /advtrains/tests
parent4989da3663cbc91ccd283a20f40bb4031687aacf (diff)
downloadadvtrains-2c4e4f80c89f403f6387358568d66a3dd5db8000.tar.gz
advtrains-2c4e4f80c89f403f6387358568d66a3dd5db8000.tar.bz2
advtrains-2c4e4f80c89f403f6387358568d66a3dd5db8000.zip
JIT-compile ATC commands
Diffstat (limited to 'advtrains/tests')
-rw-r--r--advtrains/tests/atcjit_spec.lua156
1 files changed, 156 insertions, 0 deletions
diff --git a/advtrains/tests/atcjit_spec.lua b/advtrains/tests/atcjit_spec.lua
new file mode 100644
index 0000000..8e2a8b7
--- /dev/null
+++ b/advtrains/tests/atcjit_spec.lua
@@ -0,0 +1,156 @@
+package.path = "../?.lua;" .. package.path
+advtrains = {}
+_G.advtrains = advtrains
+function _G.attrans(...) return ... end
+function advtrains.invert_train() end
+function advtrains.train_ensure_init() end
+
+local atcjit = require("atcjit")
+
+local function assert_atc(train, warn, err, res)
+ local w, e = atcjit.execute(train.id,train)
+ assert.same(err, e)
+ if w then assert.same(warn, w) end
+ assert.same(res, train)
+end
+
+local function thisatc(desc, train, warn, err, res)
+ it(desc, function() assert_atc(train, warn, err, res) end)
+end
+
+describe("simple ATC track", function()
+ local t = {
+ atc_arrow = true,
+ atc_command = " B12WB8WBBWOLD15ORD15OCD1RS10WSM",
+ door_open = 0,
+ max_speed = 20,
+ tarvelocity = 10,
+ velocity = 0,
+ }
+ thisatc("should make the train slow down to 12", t, {}, nil,{
+ atc_arrow = true,
+ atc_brake_target = 12,
+ atc_command = "B8WBBWOLD15ORD15OCD1RS10WSM",
+ atc_wait_finish = true,
+ door_open = 0,
+ max_speed = 20,
+ tarvelocity = 10,
+ velocity = 0,
+ })
+ thisatc("should make the train brake to 8", t, {}, nil, {
+ atc_arrow = true,
+ atc_brake_target = 8,
+ atc_command = "BBWOLD15ORD15OCD1RS10WSM",
+ atc_wait_finish = true,
+ door_open = 0,
+ max_speed = 20,
+ tarvelocity = 8,
+ velocity = 0,
+ })
+ thisatc("should make the train stop", t, {}, nil, {
+ atc_arrow = true,
+ atc_brake_target = -1,
+ atc_command = "OLD15ORD15OCD1RS10WSM",
+ atc_wait_finish = true,
+ door_open = 0,
+ max_speed = 20,
+ tarvelocity = 0,
+ velocity = 0,
+ })
+ thisatc("should make the train open its left doors", t, {}, nil, {
+ atc_arrow = true,
+ atc_brake_target = -1,
+ atc_command = "ORD15OCD1RS10WSM",
+ atc_delay = 15,
+ atc_wait_finish = true,
+ door_open = -1,
+ max_speed = 20,
+ tarvelocity = 0,
+ velocity = 0,
+ })
+ thisatc("should make the train open its right doors", t, {}, nil,{
+ atc_arrow = true,
+ atc_brake_target = -1,
+ atc_command = "OCD1RS10WSM",
+ atc_delay = 15,
+ atc_wait_finish = true,
+ door_open = 1,
+ max_speed = 20,
+ tarvelocity = 0,
+ velocity = 0,
+ })
+ thisatc("should make the train close its doors", t, {}, nil, {
+ atc_arrow = true,
+ atc_brake_target = -1,
+ atc_command = "RS10WSM",
+ atc_delay = 1,
+ atc_wait_finish = true,
+ door_open = 0,
+ max_speed = 20,
+ tarvelocity = 0,
+ velocity = 0,
+ })
+ thisatc("should make the train depart and accelerate to 10", t, {}, nil, {
+ atc_arrow = true,
+ atc_brake_target = -1,
+ atc_command = "SM",
+ atc_delay = 1,
+ atc_wait_finish = true,
+ door_open = 0,
+ max_speed = 20,
+ tarvelocity = 10,
+ velocity = 0,
+ })
+ thisatc("should make the train accelerate to 20", t, {}, nil, {
+ atc_arrow = true,
+ atc_brake_target = -1,
+ atc_delay = 1,
+ atc_wait_finish = true,
+ door_open = 0,
+ max_speed = 20,
+ tarvelocity = 20,
+ velocity = 0,
+ })
+end)
+
+describe("ATC track with whitespaces", function()
+ local t = {
+ atc_command = " \t\n OC \n S20 \r "
+ }
+ thisatc("should not cause errors", t, {}, nil, {
+ door_open = 0,
+ tarvelocity = 20,
+ })
+end)
+
+describe("empty ATC track", function()
+ local t = {atc_command = ""}
+ thisatc("should not do anything", t, {}, nil, {})
+end)
+
+describe("ATC track with nested I statements", function()
+ local t = {
+ atc_arrow = false,
+ atc_command = "I+OREI>5I<=10S16WORES12;D15;;OC",
+ velocity = 10,
+ door_open = 0,
+ }
+ thisatc("should make the train accelerate to 16", t, {}, nil,{
+ atc_arrow = false,
+ atc_command = "ORD15OC",
+ atc_wait_finish = true,
+ velocity = 10,
+ door_open = 0,
+ tarvelocity = 16,
+ })
+end)
+
+describe("ATC track with invalid statement", function()
+ local t = { atc_command = "Ifoo" }
+ thisatc("should report an error", t, {}, "Invalid command or malformed I statement: Ifoo", t)
+end)
+
+describe("ATC track with invalid I condition", function()
+ local t = { atc_command = "I?;" }
+ thisatc("should report an error", t, {}, "Invalid I statement", t)
+end)