aboutsummaryrefslogtreecommitdiffstats
path: root/tests/platform_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/platform_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/platform_spec.lua')
-rw-r--r--tests/platform_spec.lua137
1 files changed, 137 insertions, 0 deletions
diff --git a/tests/platform_spec.lua b/tests/platform_spec.lua
new file mode 100644
index 00000000..916b240b
--- /dev/null
+++ b/tests/platform_spec.lua
@@ -0,0 +1,137 @@
+local stub = require "luassert.stub"
+local spy = require "luassert.spy"
+local match = require "luassert.match"
+
+describe("platform", function()
+ local function platform()
+ package.loaded["nvim-lsp-installer.platform"] = nil
+ return require "nvim-lsp-installer.platform"
+ end
+
+ local function stub_mac()
+ stub(vim.fn, "has")
+ vim.fn.has.on_call_with("mac").returns(1)
+ vim.fn.has.on_call_with("unix").returns(1)
+ vim.fn.has.on_call_with(match._).returns(0)
+ end
+
+ local function stub_linux()
+ stub(vim.fn, "has")
+ vim.fn.has.on_call_with("mac").returns(0)
+ vim.fn.has.on_call_with("unix").returns(1)
+ vim.fn.has.on_call_with(match._).returns(0)
+ end
+
+ local function stub_windows()
+ stub(vim.fn, "has")
+ vim.fn.has.on_call_with("win32").returns(1)
+ vim.fn.has.on_call_with(match._).returns(0)
+ end
+
+ it("should be able to detect macos", function()
+ stub_mac()
+ assert.is_true(platform().is_mac)
+ assert.is_true(platform().is_unix)
+ assert.is_false(platform().is_linux)
+ assert.is_false(platform().is_win)
+ end)
+
+ it("should be able to detect linux", function()
+ stub_linux()
+ assert.is_false(platform().is_mac)
+ assert.is_true(platform().is_unix)
+ assert.is_true(platform().is_linux)
+ assert.is_false(platform().is_win)
+ end)
+
+ it("should be able to detect windows", function()
+ stub_windows()
+ assert.is_false(platform().is_mac)
+ assert.is_false(platform().is_unix)
+ assert.is_false(platform().is_linux)
+ assert.is_true(platform().is_win)
+ end)
+
+ it("should run correct case on linux", function()
+ local unix = spy.new()
+ local win = spy.new()
+ local mac = spy.new()
+ local linux = spy.new()
+
+ stub_linux()
+ platform().when {
+ unix = unix,
+ win = win,
+ linux = linux,
+ mac = mac,
+ }
+ assert.spy(unix).was_not_called()
+ assert.spy(mac).was_not_called()
+ assert.spy(win).was_not_called()
+ assert.spy(linux).was_called(1)
+ end)
+
+ it("should run correct case on mac", function()
+ local unix = spy.new()
+ local win = spy.new()
+ local mac = spy.new()
+ local linux = spy.new()
+
+ stub_mac()
+ platform().when {
+ unix = unix,
+ win = win,
+ linux = linux,
+ mac = mac,
+ }
+ assert.spy(unix).was_not_called()
+ assert.spy(mac).was_called(1)
+ assert.spy(win).was_not_called()
+ assert.spy(linux).was_not_called()
+ end)
+
+ it("should run correct case on windows", function()
+ local unix = spy.new()
+ local win = spy.new()
+ local mac = spy.new()
+ local linux = spy.new()
+
+ stub_windows()
+ platform().when {
+ unix = unix,
+ win = win,
+ linux = linux,
+ mac = mac,
+ }
+ assert.spy(unix).was_not_called()
+ assert.spy(mac).was_not_called()
+ assert.spy(win).was_called(1)
+ assert.spy(linux).was_not_called()
+ end)
+
+ it("should run correct case on mac (unix)", function()
+ local unix = spy.new()
+ local win = spy.new()
+
+ stub_mac()
+ platform().when {
+ unix = unix,
+ win = win,
+ }
+ assert.spy(unix).was_called(1)
+ assert.spy(win).was_not_called()
+ end)
+
+ it("should run correct case on linux (unix)", function()
+ local unix = spy.new()
+ local win = spy.new()
+
+ stub_linux()
+ platform().when {
+ unix = unix,
+ win = win,
+ }
+ assert.spy(unix).was_called(1)
+ assert.spy(win).was_not_called()
+ end)
+end)