aboutsummaryrefslogtreecommitdiffstats
path: root/tests/core/functional/table_spec.lua
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-07-06 19:41:43 +0200
committerWilliam Boman <william@redwill.se>2022-07-07 00:39:59 +0200
commit5f634e0c37e723fc0c33e06b4fd5c2180178db40 (patch)
treefa4f09363adefa8259e23e4d1ea036db628b1243 /tests/core/functional/table_spec.lua
parentfeat(health): use stderr for java version, also check for JAVA_HOME (#765) (diff)
downloadmason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar.gz
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar.bz2
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar.lz
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar.xz
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.tar.zst
mason-5f634e0c37e723fc0c33e06b4fd5c2180178db40.zip
mason.nvim
Diffstat (limited to 'tests/core/functional/table_spec.lua')
-rw-r--r--tests/core/functional/table_spec.lua46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/core/functional/table_spec.lua b/tests/core/functional/table_spec.lua
index 25adff59..b10527f1 100644
--- a/tests/core/functional/table_spec.lua
+++ b/tests/core/functional/table_spec.lua
@@ -1,7 +1,51 @@
-local _ = require "nvim-lsp-installer.core.functional"
+local _ = require "mason.core.functional"
describe("functional: table", function()
it("retrieves property of table", function()
assert.equals("hello", _.prop("a", { a = "hello" }))
end)
+
+ it("picks properties of table", function()
+ local function fn() end
+ assert.same(
+ {
+ ["key1"] = 1,
+ [fn] = 2,
+ },
+ _.pick({ "key1", fn }, {
+ ["key1"] = 1,
+ [fn] = 2,
+ [3] = 3,
+ })
+ )
+ end)
+
+ it("converts table to pairs", function()
+ assert.same(
+ _.sort_by(_.nth(1), {
+ {
+ "skies",
+ "cloudy",
+ },
+ {
+ "temperature",
+ "20°",
+ },
+ }),
+ _.sort_by(_.nth(1), _.to_pairs { skies = "cloudy", temperature = "20°" })
+ )
+ end)
+
+ it("should invert tables", function()
+ assert.same(
+ {
+ val1 = "key1",
+ val2 = "key2",
+ },
+ _.invert {
+ key1 = "val1",
+ key2 = "val2",
+ }
+ )
+ end)
end)