mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2026-09-22 17:24:01 +00:00
Type the test environments for autocomplete
Building on the class annotations from the smoke test changes: - The suite is generic over its environment: Framework.suite is @generic T : Stubs with the extension returning T, and Suite<T> passes T to every test function. A test file declares `local Suite = ... --- @type Suite<ExpRoles.TestEnv>` and env autocompletes from there. - The stubs declare their recorded fields, add_player returns Stubs.Player, and the server is one. - ExpRoles.TestEnv : Stubs declares the extension fields, so env.R returns ExpRoles.Role and env.Roles is the module. The typing immediately paid for itself by flagging real drift in the tests, now fixed: _script_data is package private so the env exposes script_data() instead, the join event carries its name and tick, the assignment record type admits is_deleted, admin_state is a file local rather than an undeclared field, and the event assertions which indexed [1] without a nil check compare the whole event list. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
59df8bdff3
commit
08fe6b688e
@@ -1,5 +1,5 @@
|
||||
--- Tests for listing and printing to the players who hold a role
|
||||
local Suite = ... --- @type Suite The suite this file adds its tests to, see test/lua/framework.lua
|
||||
local Suite = ... --- @type Suite<ExpRoles.TestEnv> The suite this file adds its tests to, see test/lua/framework.lua
|
||||
local test, check, eq = Suite.test, Suite.check, Suite.eq
|
||||
|
||||
--- alice and dave are moderators with dave offline, zed has never joined
|
||||
@@ -30,7 +30,7 @@ test(".get_player_names() counts a player in both lists once", function(env)
|
||||
env.R("Regular"):assign(players.alice, { silent = true, local_only = true })
|
||||
env.Roles.receive_assignment_updates{ env.assignment("alice", { "Moderator", "Regular" }) }
|
||||
|
||||
local sd = env.Roles._script_data()
|
||||
local sd = env.script_data()
|
||||
check(sd.local_players.alice ~= nil and sd.synced_players.alice ~= nil, "the role is held in both lists")
|
||||
eq(Suite.sorted(env.R("Regular"):get_player_names()), { "alice", "bob" }, "the player is counted once")
|
||||
end)
|
||||
|
||||
Reference in New Issue
Block a user