aboutsummaryrefslogtreecommitdiffstats
path: root/tests/data_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/data_spec.lua')
-rw-r--r--tests/data_spec.lua17
1 files changed, 17 insertions, 0 deletions
diff --git a/tests/data_spec.lua b/tests/data_spec.lua
index 0e13d44c..6a7e409c 100644
--- a/tests/data_spec.lua
+++ b/tests/data_spec.lua
@@ -1,5 +1,6 @@
local Data = require "nvim-lsp-installer.data"
local spy = require "luassert.spy"
+local match = require "luassert.match"
describe("data", function()
it("creates enums", function()
@@ -132,4 +133,20 @@ describe("data", function()
assert.equal("key1key3", memoized_fn("key1", "key3"))
assert.spy(expensive_function).was_called(2)
end)
+
+ it("should evaluate functions lazily", function()
+ local impl = spy.new(function()
+ return {}, {}
+ end)
+ local lazy_fn = Data.lazy(impl)
+ assert.spy(impl).was_called(0)
+ local a, b = lazy_fn()
+ assert.spy(impl).was_called(1)
+ assert.is_true(match.is_table()(a))
+ assert.is_true(match.is_table()(b))
+ local new_a, new_b = lazy_fn()
+ assert.spy(impl).was_called(1)
+ assert.is_true(match.is_ref(a)(new_a))
+ assert.is_true(match.is_ref(b)(new_b))
+ end)
end)