diff options
| author | OpportunityLiu <[email protected]> | 2019-07-26 16:37:45 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-28 14:45:01 +0800 |
| commit | 3be7a9e64378782f90854f3b00f5af8de409ae10 (patch) | |
| tree | 46266829e3fef7b80b3f7c72e24d35ddef1a845a /tests/modules/string/serialize/test.lua | |
| parent | d3667d71c86861ffb910af8ba8ecd930f75bf9e7 (diff) | |
add unit test of serialize function
Diffstat (limited to 'tests/modules/string/serialize/test.lua')
| -rw-r--r-- | tests/modules/string/serialize/test.lua | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/modules/string/serialize/test.lua b/tests/modules/string/serialize/test.lua index 66b216566..0d72e721e 100644 --- a/tests/modules/string/serialize/test.lua +++ b/tests/modules/string/serialize/test.lua @@ -43,8 +43,24 @@ function test_function(t) t:are_equal(roundtrip({function() return {{1, 2, 3, nil, 4}} end})[1](), {{1, 2, 3, nil, 4}}) t:are_equal(roundtrip({{function() return {{1, 2, 3, nil, 4}} end}})[1][1](), {{1, 2, 3, nil, 4}}) - t:will_raise(function() string.serialize({io.open}):deserialize()[1]("test.lua") end, "attempt to call global 'setmetatable' (a nil value)") - t:will_raise(function() string.serialize({io.open}):deserialize()[1]("not/a/file") end, "failed to open file: not/a/file") + -- x in fenv + x = {} + -- return x in fenv + function f() return x end + -- fenv will restore + t:are_same(roundtrip(f)(), x) + + y = {} + -- y in fenv + local g_y = y + -- y in upvalue + local y = {} + -- return y in upvalue + function g() return y end + -- upvalue will not restore if striped + t:are_same(roundtrip(g)(), nil) + -- upvalue will be restored by fenv, so y in fenv is returned + t:are_same(string.serialize(g):deserialize()(), g_y) end function test_refloop(t) |
