diff options
| author | ruki <[email protected]> | 2020-12-24 21:48:22 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-12-24 21:48:22 +0800 |
| commit | 95cfe53e0e9963b1c791f3bd3a3a9b7eda3b3b10 (patch) | |
| tree | 137fac8018667ad280eb6f2bb7a1171c02ae8d6a /tests/modules | |
| parent | 9d1ea2ecbc19153c1fcc2355aab3e6e09cbe7b12 (diff) | |
| parent | 3118b46c20edbdade2aed0b50b7ed668e4301d70 (diff) | |
Merge pull request #1152 from xmake-io/cache
Improve cache
Diffstat (limited to 'tests/modules')
| -rw-r--r-- | tests/modules/cache/test.lua | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/modules/cache/test.lua b/tests/modules/cache/test.lua new file mode 100644 index 000000000..0096f0f03 --- /dev/null +++ b/tests/modules/cache/test.lua @@ -0,0 +1,42 @@ +import("core.cache.memcache") +import("core.cache.localcache") +import("core.cache.globalcache") + +function test_memcache(t) + memcache.set("mycache", "xyz", {1, 2, 3}) + memcache.set2("mycache", "foo", "bar", "1") + t:are_equal(memcache.get("mycache", "xyz"), {1, 2, 3}) + t:are_equal(memcache.get2("mycache", "foo", "bar"), "1") + memcache.clear("mycache") + t:are_equal(memcache.get2("mycache", "foo", "bar"), nil) + memcache.set2("mycache", "foo", "bar", "1") + memcache.clear() + t:are_equal(memcache.get("mycache", "xyz"), nil) + t:are_equal(memcache.get2("mycache", "foo", "bar"), nil) +end + +function test_localcache(t) + localcache.set("mycache", "xyz", {1, 2, 3}) + localcache.set2("mycache", "foo", "bar", "1") + t:are_equal(localcache.get("mycache", "xyz"), {1, 2, 3}) + t:are_equal(localcache.get2("mycache", "foo", "bar"), "1") + localcache.clear("mycache") + t:are_equal(localcache.get2("mycache", "foo", "bar"), nil) + localcache.set2("mycache", "foo", "bar", "1") + localcache.clear() + t:are_equal(localcache.get("mycache", "xyz"), nil) + t:are_equal(localcache.get2("mycache", "foo", "bar"), nil) +end + +function test_globalcache(t) + globalcache.set("mycache", "xyz", {1, 2, 3}) + globalcache.set2("mycache", "foo", "bar", "1") + t:are_equal(globalcache.get("mycache", "xyz"), {1, 2, 3}) + t:are_equal(globalcache.get2("mycache", "foo", "bar"), "1") + globalcache.clear("mycache") + t:are_equal(globalcache.get2("mycache", "foo", "bar"), nil) + globalcache.set2("mycache", "foo", "bar", "1") + globalcache.clear() + t:are_equal(globalcache.get("mycache", "xyz"), nil) + t:are_equal(globalcache.get2("mycache", "foo", "bar"), nil) +end |
