aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/functional/relation_spec.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tests/mason-core/functional/relation_spec.lua')
-rw-r--r--tests/mason-core/functional/relation_spec.lua36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/mason-core/functional/relation_spec.lua b/tests/mason-core/functional/relation_spec.lua
new file mode 100644
index 00000000..a3eee722
--- /dev/null
+++ b/tests/mason-core/functional/relation_spec.lua
@@ -0,0 +1,36 @@
+local _ = require "mason-core.functional"
+
+describe("functional: relation", function()
+ it("should check equality", function()
+ local tbl = {}
+ local is_tbl = _.equals(tbl)
+ local is_a = _.equals "a"
+ local is_42 = _.equals(42)
+
+ assert.is_true(is_tbl(tbl))
+ assert.is_true(is_a "a")
+ assert.is_true(is_42(42))
+ assert.is_false(is_a "b")
+ assert.is_false(is_42(32))
+ end)
+
+ it("should check property equality", function()
+ local fn_key = function() end
+ local tbl = { a = "a", b = "b", number = 42, [fn_key] = "fun" }
+ assert.is_true(_.prop_eq("a", "a", tbl))
+ assert.is_true(_.prop_eq(fn_key, "fun", tbl))
+ assert.is_true(_.prop_eq(fn_key) "fun"(tbl))
+ end)
+
+ it("should check whether property satisfies predicate", function()
+ local obj = {
+ low = 0,
+ med = 10,
+ high = 15,
+ }
+
+ assert.is_false(_.prop_satisfies(_.gt(10), "low", obj))
+ assert.is_false(_.prop_satisfies(_.gt(10), "med")(obj))
+ assert.is_true(_.prop_satisfies(_.gt(10)) "high"(obj))
+ end)
+end)