mirror of
https://github.com/lune-org/lune.git
synced 2025-04-15 01:13:55 +01:00
Remove global from state_module test
This commit is contained in:
parent
9804a6abfe
commit
5c983b56b5
2 changed files with 6 additions and 10 deletions
|
@ -1,16 +1,14 @@
|
||||||
-- the idea of this test is that state_module stores some state in one of its local variable
|
-- the idea of this test is that state_module stores some state in one of its local
|
||||||
-- we also set a global in the module to ensure the change we would have expected happens
|
-- variable
|
||||||
local state_module = require("./state_module")
|
local state_module = require("./state_module")
|
||||||
|
|
||||||
-- we confirm that without anything happening, the initial value is what we ecpect
|
-- we confirm that without anything happening, the initial value is what we ecpect
|
||||||
assert(_state_test_global == 10)
|
|
||||||
assert(state_module.state == 10)
|
assert(state_module.state == 10)
|
||||||
|
|
||||||
-- this second file also requires state_module and calls a function that changes both the local state and the global to 11
|
-- this second file also requires state_module and calls a function that changes the local
|
||||||
|
-- state to 11
|
||||||
require("./state_second")
|
require("./state_second")
|
||||||
|
|
||||||
-- if this also fails then there is either a problem with globals, or state_second is not doing what we expect it to
|
-- with correct module caching, we should see the change done in state_secone reflected
|
||||||
assert(_state_test_global == 11)
|
-- here
|
||||||
-- with correct module caching, we should see the change done in state_secone reflected here
|
|
||||||
assert(state_module.state == 11)
|
assert(state_module.state == 11)
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
M.state = 10
|
M.state = 10
|
||||||
_state_test_global = 10
|
|
||||||
|
|
||||||
function M.set_state(n: number)
|
function M.set_state(n: number)
|
||||||
M.state = n
|
M.state = n
|
||||||
_state_test_global = n
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Add table
Reference in a new issue