diff options
| author | Florian Fischer <florian.fischer@muhq.space> | 2025-01-26 22:22:20 +0100 |
|---|---|---|
| committer | Florian Fischer <florian.fischer@muhq.space> | 2025-05-16 09:04:17 -0600 |
| commit | e3551e1ab54b6220047b005947d99380b2b7dfde (patch) | |
| tree | 9cbb00de31f748a8110101eb9d2c617c0fb6c85f /util_test.lua | |
| parent | cef8b428cff4cfb3fa07f30eab644cba1540b4b2 (diff) | |
| download | vis-lspc-e3551e1ab54b6220047b005947d99380b2b7dfde.tar.gz vis-lspc-e3551e1ab54b6220047b005947d99380b2b7dfde.zip | |
add table helper utility functions
Diffstat (limited to 'util_test.lua')
| -rwxr-xr-x | util_test.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/util_test.lua b/util_test.lua index fd6570d..9f34d3c 100755 --- a/util_test.lua +++ b/util_test.lua @@ -15,4 +15,42 @@ function test_dirname() -- luacheck: ignore 111 lunatest.assert_equal('/', util.dirname('/')) end +function test_table_deep_copy() -- luacheck: ignore 111 + local t = {1, 2, 3, foo = {4, 5, bar = 'bar'}} + local cpy = util.table.deep_copy(t) + + lunatest.assert_table(cpy) + lunatest.assert_len(3, cpy) + lunatest.assert_table(cpy.foo) + lunatest.assert_len(2, cpy.foo) + for i, v in ipairs(t) do + lunatest.assert_equal(v, cpy[i]) + end + + t[2] = 12 + lunatest.assert_not_equal(t[2], cpy[2]) + t.foo[2] = 13 + lunatest.assert_not_equal(t.foo[2], cpy.foo[2]) +end + +function test_table_merge() -- luacheck: ignore 111 + local t = {1, 2, foo = {bar = {nose = 'nose'}}} + local t2 = {3, foo = {4, 5, bar = {bar = 'bar'}}} + lunatest.assert_table(t) + lunatest.assert_table(t2) + + util.table.merge(t, t2) + + lunatest.assert_table(t) + lunatest.assert_len(2, t) + lunatest.assert_table(t.foo) + lunatest.assert_len(2, t.foo) + + lunatest.assert_equal(t[1], t2[1]) + lunatest.assert_equal(t[2], 2) + + lunatest.assert_equal(t.foo.bar.bar, 'bar') + lunatest.assert_equal(t.foo.bar.nose, 'nose') +end + lunatest.run() |
