aboutsummaryrefslogtreecommitdiffstats
path: root/tests/data_spec.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-04-21 12:09:59 +0200
committerGitHub <noreply@github.com>2022-04-21 12:09:59 +0200
commitb68fcc6bb2c770495ff8e2508c06dfdd49abcc80 (patch)
treedf7c71efb59958deb21a18eeccf3e3c43c4cd704 /tests/data_spec.lua
parentrun autogen_metadata.lua (diff)
downloadmason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.gz
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.bz2
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.lz
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.xz
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.tar.zst
mason-b68fcc6bb2c770495ff8e2508c06dfdd49abcc80.zip
chore: refactor remaining installers to async impl (#616)
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)