From b68fcc6bb2c770495ff8e2508c06dfdd49abcc80 Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 21 Apr 2022 12:09:59 +0200 Subject: chore: refactor remaining installers to async impl (#616) --- tests/data_spec.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tests/data_spec.lua') 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) -- cgit v1.2.3-70-g09d2