aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-12-10 19:55:41 +0100
committerGitHub <noreply@github.com>2022-12-10 18:55:41 +0000
commitfbc72a0c2fe16a93b18ce8facdc9b66e7183f75d (patch)
treebe37b4bd7b0320dbfa3e08dae8c90540c0eaa335 /tests
parentchore: update generated code (#754) (diff)
downloadmason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar.gz
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar.bz2
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar.lz
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar.xz
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.tar.zst
mason-fbc72a0c2fe16a93b18ce8facdc9b66e7183f75d.zip
feat(functional): add some more functions (#755)
Diffstat (limited to 'tests')
-rw-r--r--tests/mason-core/functional/function_spec.lua17
-rw-r--r--tests/mason-core/functional/list_spec.lua28
-rw-r--r--tests/mason-core/functional/string_spec.lua5
-rw-r--r--tests/mason-core/functional/table_spec.lua43
4 files changed, 93 insertions, 0 deletions
diff --git a/tests/mason-core/functional/function_spec.lua b/tests/mason-core/functional/function_spec.lua
index 23af1933..6b36b53b 100644
--- a/tests/mason-core/functional/function_spec.lua
+++ b/tests/mason-core/functional/function_spec.lua
@@ -160,4 +160,21 @@ describe("functional: function", function()
assert.spy(target).was_called(1)
assert.spy(target).was_called_with("These", "Nuts")
end)
+
+ it("should apply spec", function()
+ local apply = _.apply_spec {
+ sum = _.add(2),
+ list = { _.add(2), _.add(6) },
+ nested = {
+ sum = _.min(2),
+ },
+ }
+ assert.same({
+ sum = 4,
+ list = { 4, 8 },
+ nested = {
+ sum = 0,
+ },
+ }, apply(2))
+ end)
end)
diff --git a/tests/mason-core/functional/list_spec.lua b/tests/mason-core/functional/list_spec.lua
index f9de9fdc..a53da4ac 100644
--- a/tests/mason-core/functional/list_spec.lua
+++ b/tests/mason-core/functional/list_spec.lua
@@ -94,6 +94,27 @@ describe("functional: list", function()
assert.spy(predicate).was.called(2)
end)
+ it("should check that all items in list fulfills predicate", function()
+ assert.is_true(_.all(_.is "string", {
+ "Where",
+ "On Earth",
+ "Is",
+ "Waldo",
+ "?",
+ }))
+
+ local predicate = spy.new(_.is "string")
+
+ assert.is_false(_.all(predicate, {
+ "Five",
+ "Plus",
+ 42,
+ "Equals",
+ 47,
+ }))
+ assert.spy(predicate).was_called(3)
+ end)
+
it("should iterate list in .each", function()
local list = { "BLUE", "YELLOW", "RED" }
local iterate_fn = spy.new()
@@ -225,4 +246,11 @@ describe("functional: list", function()
assert.same({ "First", "Second", "Third", "I", "Have", "Poor", "Imagination" }, _.drop(0, list))
assert.same({}, _.drop(10000, list))
end)
+
+ it("should drop last n items", function()
+ local list = { "First", "Second", "Third", "I", "Have", "Poor", "Imagination" }
+ assert.same({ "First", "Second", "Third" }, _.drop_last(4, list))
+ assert.same({ "First", "Second", "Third", "I", "Have", "Poor", "Imagination" }, _.drop_last(0, list))
+ assert.same({}, _.drop_last(10000, list))
+ end)
end)
diff --git a/tests/mason-core/functional/string_spec.lua b/tests/mason-core/functional/string_spec.lua
index 6fb99c45..7bbe06c5 100644
--- a/tests/mason-core/functional/string_spec.lua
+++ b/tests/mason-core/functional/string_spec.lua
@@ -45,4 +45,9 @@ Ipsum
]]
)
end)
+
+ it("should transform casing", function()
+ assert.equals("HELLO!", _.to_upper "Hello!")
+ assert.equals("hello!", _.to_lower "Hello!")
+ end)
end)
diff --git a/tests/mason-core/functional/table_spec.lua b/tests/mason-core/functional/table_spec.lua
index c897b5ca..357f7120 100644
--- a/tests/mason-core/functional/table_spec.lua
+++ b/tests/mason-core/functional/table_spec.lua
@@ -68,4 +68,47 @@ describe("functional: table", function()
}
)
end)
+
+ it("should evolve table", function()
+ assert.same(
+ {
+ non_existent = nil,
+ firstname = "JOHN",
+ lastname = "DOE",
+ age = 42,
+ },
+ _.evolve({
+ non_existent = _.always "hello",
+ firstname = _.to_upper,
+ lastname = _.to_upper,
+ age = _.add(2),
+ }, {
+ firstname = "John",
+ lastname = "Doe",
+ age = 40,
+ })
+ )
+ end)
+
+ it("should merge left", function()
+ assert.same(
+ {
+ firstname = "John",
+ lastname = "Doe",
+ },
+ _.merge_left({
+ firstname = "John",
+ }, {
+ firstname = "Jane",
+ lastname = "Doe",
+ })
+ )
+ end)
+
+ it("should dissoc keys", function()
+ assert.same({
+ a = "a",
+ c = "c",
+ }, _.dissoc("b", { a = "a", b = "b", c = "c" }))
+ end)
end)