diff options
| author | OpportunityLiu <[email protected]> | 2019-07-24 18:36:49 +0800 |
|---|---|---|
| committer | OpportunityLiu <[email protected]> | 2019-07-25 15:25:40 +0800 |
| commit | 9774a017a3baadd3caf3b442f4a22a0bf151d4c9 (patch) | |
| tree | 3df07f70ec715cf98fb3f43e1e8cb89a878a72f8 /tests/modules/string/serialize/test.lua | |
| parent | 5727deff9988a851f528308c1c6a941f3cab56f3 (diff) | |
Improve string.serialize; add unit test
Diffstat (limited to 'tests/modules/string/serialize/test.lua')
| -rw-r--r-- | tests/modules/string/serialize/test.lua | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/modules/string/serialize/test.lua b/tests/modules/string/serialize/test.lua new file mode 100644 index 000000000..8d13f6fee --- /dev/null +++ b/tests/modules/string/serialize/test.lua @@ -0,0 +1,36 @@ + +function roundtrip(v) + return string.serialize(v):deserialize() +end + +function test_number(t) + t:are_equal(roundtrip(12), 12) + t:are_equal(roundtrip(0), 0) + t:are_equal(roundtrip(-1), -1) + t:are_equal(roundtrip(7.25), 7.25) + t:are_equal(roundtrip(math.huge), math.huge) + t:are_equal(roundtrip(-math.huge), -math.huge) + t:are_equal(roundtrip(math.nan), math.nan) +end + +function test_boolean(t) + t:are_equal(roundtrip(true), true) + t:are_equal(roundtrip(false), false) +end + +function test_nil(t) + t:are_equal(roundtrip(nil), nil) +end + +function test_table(t) + t:are_equal(roundtrip({}), {}) + t:are_equal(roundtrip({1, 2, 3}), {1, 2, 3}) + t:are_equal(roundtrip({1, "", 3}), {1, "", 3}) + --t:are_equal(roundtrip({{1, 2, 3, nil, 4}}), {{1, 2, 3, nil, 4}}) +end + +function test_function(t) + t:are_equal(roundtrip(function() return {} end)(), {}) + t:are_equal(roundtrip(function() return {1, 2, 3} end)(), {1, 2, 3}) + t:are_equal(roundtrip(function() return {{1, 2, 3, nil, 4}} end)(), {{1, 2, 3, nil, 4}}) +end |
