mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-09-22 01:04:01 +00:00
Address review on the test framework
- The registry is a Suite, created around the environment factory it runs its tests with, so the plugin's env.lua reads as: build environments, hand the test files a suite of them. The suite returned there becomes `...` in each test file, which is now said where it happens. - pass and fail are the primitives every other check goes through. eq and deep_eq assert rather than compare, failing with both values in the detail. - Stubs are extended through extend_requires, extend_script, extend_game and extend_defines, a recursive merge which raises when a value already exists, rather than by mutating the tables. The strict labels carry the factorio class names. - The stubs record registered metatables and can save and load the script data the way factorio does: functions are refused and only registered metatables survive. env.save_load() uses it, and a new on_load test shows role methods and held roles surviving the round trip, which only passes because the module registers its metatable. - The names helper moved out of the shared framework, it is role specific. - Tests are named after the function or method they cover, on both sides: the lua tests read as "role:assign applies locally and is sent", and the javascript files wrap their tests in the class they exercise with subtests per method. module.test.js is control.test.js, after the file it covers. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
24d36db601
commit
7adcdde9dc
@@ -1,28 +1,58 @@
|
||||
--- Role lookup, decoding, and comparisons
|
||||
local Env = ...
|
||||
local Test = Env.Test
|
||||
local test, check, eq = Test.test, Test.check, Test.eq
|
||||
--- Tests for the role lookup functions of module/control.lua
|
||||
local Suite = ... --- The suite this file adds its tests to, see test/lua/framework.lua
|
||||
local test, check, eq = Suite.test, Suite.check, Suite.eq
|
||||
|
||||
test("roles are ordered most privileged first", function(env)
|
||||
test("get_role returns the role with the given clusterio id", function(env)
|
||||
env.initialise{}
|
||||
check(eq(Test.names(env.Roles.get_ordered_roles()), { "Cluster Admin", "Moderator", "Regular", "Jail", "Player" }),
|
||||
"ordered roles follow their order with deleted roles skipped")
|
||||
check(#env.Roles.get_roles() == 5, "get_roles returns every role")
|
||||
|
||||
local sorted = env.Roles.sort_roles{ env.R("Player"), env.R("Cluster Admin"), env.R("Regular") }
|
||||
check(eq(Test.names(sorted), { "Cluster Admin", "Regular", "Player" }), "sort_roles orders most privileged first")
|
||||
end)
|
||||
|
||||
test("roles are looked up by id", function(env)
|
||||
env.initialise{}
|
||||
check(env.Roles.get_role(6).name == "Regular", "get_role looks up by clusterio id")
|
||||
check(env.Roles.get_role_by_name("Moderator").id == 5, "get_role_by_name searches the roles")
|
||||
check(env.Roles.get_role(6).name == "Regular", "the role is found by id")
|
||||
check(env.Roles.get_role(env.R("Jail").id) == env.R("Jail"), "lookups return the same object")
|
||||
check(env.Roles.get_role(9) == nil and env.Roles.get_role_by_name("Gone") == nil, "deleted roles are not known")
|
||||
check(env.Roles.get_default_role() == env.R("Player"), "the default role comes from is_default")
|
||||
check(env.Roles.get_role(9) == nil, "deleted roles are not known")
|
||||
end)
|
||||
|
||||
test("role records are decoded", function(env)
|
||||
test("get_role_by_name searches the roles", function(env)
|
||||
env.initialise{}
|
||||
check(env.Roles.get_role_by_name("Moderator").id == 5, "the role is found by name")
|
||||
check(env.Roles.get_role_by_name("Gone") == nil, "deleted roles are not known")
|
||||
end)
|
||||
|
||||
test("get_roles returns every role", function(env)
|
||||
env.initialise{}
|
||||
check(#env.Roles.get_roles() == 5, "every role is returned with deleted roles skipped")
|
||||
end)
|
||||
|
||||
test("get_ordered_roles returns the most privileged first", function(env)
|
||||
env.initialise{}
|
||||
eq(env.names(env.Roles.get_ordered_roles()), { "Cluster Admin", "Moderator", "Regular", "Jail", "Player" },
|
||||
"roles follow their order")
|
||||
end)
|
||||
|
||||
test("sort_roles orders most privileged first", function(env)
|
||||
env.initialise{}
|
||||
local sorted = env.Roles.sort_roles{ env.R("Player"), env.R("Cluster Admin"), env.R("Regular") }
|
||||
eq(env.names(sorted), { "Cluster Admin", "Regular", "Player" }, "the list is sorted in place")
|
||||
end)
|
||||
|
||||
test("get_default_role follows is_default", function(env)
|
||||
env.initialise{}
|
||||
check(env.Roles.get_default_role() == env.R("Player"), "the default role is known")
|
||||
end)
|
||||
|
||||
test("get_higher_roles and get_lower_roles include the role and exclude the default", function(env)
|
||||
env.initialise{}
|
||||
eq(Suite.sorted(env.names(env.Roles.get_higher_roles(env.R("Regular")))),
|
||||
{ "Cluster Admin", "Moderator", "Regular" }, "higher roles")
|
||||
eq(Suite.sorted(env.names(env.Roles.get_lower_roles(env.R("Regular")))),
|
||||
{ "Jail", "Regular" }, "lower roles")
|
||||
end)
|
||||
|
||||
test("role:is_higher_than and role:is_lower_than compare on order", function(env)
|
||||
env.initialise{}
|
||||
check(env.R("Moderator"):is_higher_than(env.R("Player")), "a lower order is more privileged")
|
||||
check(env.R("Player"):is_lower_than(env.R("Moderator")), "is_lower_than is the reverse")
|
||||
check(not env.R("Moderator"):is_higher_than(env.R("Moderator")), "a role is not higher than itself")
|
||||
end)
|
||||
|
||||
test("initialise decodes the role records", function(env)
|
||||
env.initialise{}
|
||||
check(env.R("Cluster Admin").short_hand == "SYS", "short hand decoded")
|
||||
check(env.R("Moderator").short_hand == "Moderator", "short hand falls back to the name")
|
||||
@@ -30,19 +60,4 @@ test("role records are decoded", function(env)
|
||||
check(env.R("Jail").priority == 1 and env.R("Jail").block_auto_assign, "priority and block auto assign decoded")
|
||||
end)
|
||||
|
||||
test("roles compare on their order", function(env)
|
||||
env.initialise{}
|
||||
check(env.R("Moderator"):is_higher_than(env.R("Player")), "a lower order is more privileged")
|
||||
check(env.R("Player"):is_lower_than(env.R("Moderator")), "is_lower_than is the reverse")
|
||||
check(not env.R("Moderator"):is_higher_than(env.R("Moderator")), "a role is not higher than itself")
|
||||
end)
|
||||
|
||||
test("higher and lower roles", function(env)
|
||||
env.initialise{}
|
||||
check(eq(Test.sorted(Test.names(env.Roles.get_higher_roles(env.R("Regular")))), { "Cluster Admin", "Moderator", "Regular" }),
|
||||
"higher roles include the role itself and exclude the default role")
|
||||
check(eq(Test.sorted(Test.names(env.Roles.get_lower_roles(env.R("Regular")))), { "Jail", "Regular" }),
|
||||
"lower roles include the role itself and exclude the default role")
|
||||
end)
|
||||
|
||||
return Env.finish()
|
||||
return Suite.run()
|
||||
|
||||
Reference in New Issue
Block a user