diff options
| author | William Boman <william@redwill.se> | 2022-12-08 02:06:23 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-08 01:06:23 +0000 |
| commit | 9394bcc5c582e737f0ff6bba1e411f97ee9c8c5d (patch) | |
| tree | 9729e9a1dfc493dbc7a0b2a4dfb359856c9de192 /tests | |
| parent | feat(functional): add more functions (#741) (diff) | |
| download | mason-9394bcc5c582e737f0ff6bba1e411f97ee9c8c5d.tar mason-9394bcc5c582e737f0ff6bba1e411f97ee9c8c5d.tar.gz mason-9394bcc5c582e737f0ff6bba1e411f97ee9c8c5d.tar.bz2 mason-9394bcc5c582e737f0ff6bba1e411f97ee9c8c5d.tar.lz mason-9394bcc5c582e737f0ff6bba1e411f97ee9c8c5d.tar.xz mason-9394bcc5c582e737f0ff6bba1e411f97ee9c8c5d.tar.zst mason-9394bcc5c582e737f0ff6bba1e411f97ee9c8c5d.zip | |
test(functional): add some tests (#742)
Forgot to include these in the last commit.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/mason-core/functional/function_spec.lua | 14 | ||||
| -rw-r--r-- | tests/mason-core/functional/list_spec.lua | 14 | ||||
| -rw-r--r-- | tests/mason-core/functional/relation_spec.lua | 22 | ||||
| -rw-r--r-- | tests/mason-core/functional/table_spec.lua | 4 |
4 files changed, 54 insertions, 0 deletions
diff --git a/tests/mason-core/functional/function_spec.lua b/tests/mason-core/functional/function_spec.lua index 28abce20..23af1933 100644 --- a/tests/mason-core/functional/function_spec.lua +++ b/tests/mason-core/functional/function_spec.lua @@ -146,4 +146,18 @@ describe("functional: function", function() assert.spy(fn).was_called() assert.spy(fn).was_called_with(42) end) + + it("should apply value to function", function() + local agent = spy.new() + _.apply_to("007", agent) + assert.spy(agent).was_called(1) + assert.spy(agent).was_called_with "007" + end) + + it("should converge on function", function() + local target = spy.new() + _.converge(target, { _.head, _.last }, { "These", "Are", "Some", "Words", "Ain't", "That", "Pretty", "Nuts" }) + assert.spy(target).was_called(1) + assert.spy(target).was_called_with("These", "Nuts") + end) end) diff --git a/tests/mason-core/functional/list_spec.lua b/tests/mason-core/functional/list_spec.lua index bbc60763..f9de9fdc 100644 --- a/tests/mason-core/functional/list_spec.lua +++ b/tests/mason-core/functional/list_spec.lua @@ -211,4 +211,18 @@ describe("functional: list", function() it("should return last", function() assert.equals("Last", _.last { "Head", "List", "Last" }) end) + + it("should take n items", function() + local list = { "First", "Second", "Third", "I", "Have", "Poor", "Imagination" } + assert.same({ "First", "Second", "Third" }, _.take(3, list)) + assert.same({}, _.take(0, list)) + assert.same({ "First", "Second", "Third", "I", "Have", "Poor", "Imagination" }, _.take(10000, list)) + end) + + it("should drop n items", function() + local list = { "First", "Second", "Third", "I", "Have", "Poor", "Imagination" } + assert.same({ "I", "Have", "Poor", "Imagination" }, _.drop(3, list)) + assert.same({ "First", "Second", "Third", "I", "Have", "Poor", "Imagination" }, _.drop(0, list)) + assert.same({}, _.drop(10000, list)) + end) end) diff --git a/tests/mason-core/functional/relation_spec.lua b/tests/mason-core/functional/relation_spec.lua index a3eee722..a8207b55 100644 --- a/tests/mason-core/functional/relation_spec.lua +++ b/tests/mason-core/functional/relation_spec.lua @@ -33,4 +33,26 @@ describe("functional: relation", function() assert.is_false(_.prop_satisfies(_.gt(10), "med")(obj)) assert.is_true(_.prop_satisfies(_.gt(10)) "high"(obj)) end) + + it("should check whether nested property satisfies predicate", function() + local obj = { + low = { value = 0 }, + med = { value = 10 }, + high = { value = 15 }, + } + + assert.is_false(_.path_satisfies(_.gt(10), { "low", "value" }, obj)) + assert.is_false(_.path_satisfies(_.gt(10), { "med", "value" })(obj)) + assert.is_true(_.path_satisfies(_.gt(10)) { "high", "value" }(obj)) + end) + + it("should subtract numbers", function() + assert.equals(42, _.min(42, 84)) + assert.equals(-1, _.min(11, 10)) + end) + + it("should add numbers", function() + assert.equals(1337, _.add(1300, 37)) + assert.equals(-10, _.add(90, -100)) + end) end) diff --git a/tests/mason-core/functional/table_spec.lua b/tests/mason-core/functional/table_spec.lua index 7516e33a..c897b5ca 100644 --- a/tests/mason-core/functional/table_spec.lua +++ b/tests/mason-core/functional/table_spec.lua @@ -5,6 +5,10 @@ describe("functional: table", function() assert.equals("hello", _.prop("a", { a = "hello" })) end) + it("retrieves nested property of table", function() + assert.equals("hello", _.path({ "a", "greeting" }, { a = { greeting = "hello" } })) + end) + it("picks properties of table", function() local function fn() end assert.same( |
