diff options
author | orwell <orwell@bleipb.de> | 2024-11-11 20:50:28 +0100 |
---|---|---|
committer | orwell <orwell@bleipb.de> | 2024-11-11 20:50:28 +0100 |
commit | 380c26f7a851f4b4edb3879b544a542e7bfbb490 (patch) | |
tree | 158ac366c93a8581f5792f95eba6932bafe4c325 /advtrains/spec/wagons_spec.lua | |
parent | 29180f0f60871f92889f686fe666c029ac07861a (diff) | |
parent | 3d2d19f6f7eba90f0d19b002824b2ff466567608 (diff) | |
download | advtrains-380c26f7a851f4b4edb3879b544a542e7bfbb490.tar.gz advtrains-380c26f7a851f4b4edb3879b544a542e7bfbb490.tar.bz2 advtrains-380c26f7a851f4b4edb3879b544a542e7bfbb490.zip |
Merge branch 'master' into route_prog_rework
Diffstat (limited to 'advtrains/spec/wagons_spec.lua')
-rw-r--r-- | advtrains/spec/wagons_spec.lua | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/advtrains/spec/wagons_spec.lua b/advtrains/spec/wagons_spec.lua new file mode 100644 index 0000000..df0687b --- /dev/null +++ b/advtrains/spec/wagons_spec.lua @@ -0,0 +1,40 @@ +require "mineunit" +mineunit "core" + +_G.advtrains = { + wagon_load_range = 32 +} +sourcefile "wagons" + +local myproto = {_test = true} +advtrains.register_wagon(":mywagon", myproto, "My wagon", "", false) +advtrains.register_wagon_alias(":myalias", ":mywagon") +advtrains.register_wagon_alias(":myotheralias", ":myalias") + +local myotherproto = {_other = true} +advtrains.register_wagon(":noalias", myotherproto, "Not aliased wagon", "", false) +advtrains.register_wagon_alias(":noalias", ":mywagon") + +advtrains.register_wagon_alias(":nilalias", ":nil") + +advtrains.register_wagon_alias(":R1", ":R2") +advtrains.register_wagon_alias(":R2", ":R3") +advtrains.register_wagon_alias(":R3", ":R1") + +describe("wagon alias system", function() + it("should work", function() + assert.same({":mywagon", myproto}, {advtrains.resolve_wagon_alias(":myalias")}) + assert.equal(myproto, advtrains.wagon_prototypes[":myalias"]) + assert.same({":mywagon", myproto}, {advtrains.resolve_wagon_alias(":myotheralias")}) + end) + it("should respect wagon registration", function() + assert.same({":noalias", myotherproto}, {advtrains.resolve_wagon_alias(":noalias")}) + end) + it("should handle recursive loops", function() + assert.same({}, {advtrains.resolve_wagon_alias(":R1")}) + end) + it("should return nil for missing entries", function() + assert.same({}, {advtrains.resolve_wagon_alias(":what")}) + assert.same({}, {advtrains.resolve_wagon_alias(":nilalias")}) + end) +end) |