aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2022-12-20 08:42:58 +0100
committerGitHub <noreply@github.com>2022-12-20 07:42:58 +0000
commit25313762aac8fc313b769f20298bd4e6473cc6dd (patch)
treee46fee667753f4fd7d16b2eac085348d3ecf821f /tests/mason-core
parentfeat: add expr module (#775) (diff)
downloadmason-25313762aac8fc313b769f20298bd4e6473cc6dd.tar
mason-25313762aac8fc313b769f20298bd4e6473cc6dd.tar.gz
mason-25313762aac8fc313b769f20298bd4e6473cc6dd.tar.bz2
mason-25313762aac8fc313b769f20298bd4e6473cc6dd.tar.lz
mason-25313762aac8fc313b769f20298bd4e6473cc6dd.tar.xz
mason-25313762aac8fc313b769f20298bd4e6473cc6dd.tar.zst
mason-25313762aac8fc313b769f20298bd4e6473cc6dd.zip
feat(functional): add trim_start and assoc (#779)
Diffstat (limited to 'tests/mason-core')
-rw-r--r--tests/mason-core/functional/list_spec.lua36
-rw-r--r--tests/mason-core/functional/string_spec.lua8
-rw-r--r--tests/mason-core/functional/table_spec.lua32
3 files changed, 76 insertions, 0 deletions
diff --git a/tests/mason-core/functional/list_spec.lua b/tests/mason-core/functional/list_spec.lua
index 7c3d8cfb..6c14e5a9 100644
--- a/tests/mason-core/functional/list_spec.lua
+++ b/tests/mason-core/functional/list_spec.lua
@@ -265,3 +265,39 @@ describe("functional: list", function()
assert.spy(add).was_called_with(10, 5)
end)
end)
+
+describe("list immutability", function()
+ it("should not mutate lists", function()
+ local og_list = setmetatable({ "a", "b", "c" }, {
+ __newindex = function()
+ error "Tried to newindex"
+ end,
+ })
+
+ _.reverse(og_list)
+ _.list_copy(og_list)
+ _.filter(_.F, og_list)
+ _.map(_.to_upper, og_list)
+ _.filter_map(_.always(Optional.empty()), og_list)
+ _.each(_.length, og_list)
+ _.concat(og_list, { "d", "e" })
+ _.append("d", og_list)
+ _.prepend("0", og_list)
+ _.zip_table({ "first", "second", "third" }, og_list)
+ _.nth(1, og_list)
+ _.head(og_list)
+ _.last(og_list)
+ _.length(og_list)
+ _.flatten(og_list)
+ _.sort_by(_.identity, og_list)
+ _.uniq_by(_.identity, og_list)
+ _.join(".", og_list)
+ _.partition(_.equals "a", og_list)
+ _.take(2, og_list)
+ _.drop(2, og_list)
+ _.drop_last(2, og_list)
+ _.reduce(_.concat, "", og_list)
+
+ assert.same({ "a", "b", "c" }, og_list)
+ end)
+end)
diff --git a/tests/mason-core/functional/string_spec.lua b/tests/mason-core/functional/string_spec.lua
index 7bbe06c5..02062f4c 100644
--- a/tests/mason-core/functional/string_spec.lua
+++ b/tests/mason-core/functional/string_spec.lua
@@ -50,4 +50,12 @@ Ipsum
assert.equals("HELLO!", _.to_upper "Hello!")
assert.equals("hello!", _.to_lower "Hello!")
end)
+
+ it("trim strings", function()
+ assert.equals("HELLO!", _.trim " HELLO! ")
+ end)
+
+ it("trim_starts strings", function()
+ assert.equals("HELLO! ", _.trim_start("%s", " HELLO! "))
+ end)
end)
diff --git a/tests/mason-core/functional/table_spec.lua b/tests/mason-core/functional/table_spec.lua
index 357f7120..8ffedeb1 100644
--- a/tests/mason-core/functional/table_spec.lua
+++ b/tests/mason-core/functional/table_spec.lua
@@ -111,4 +111,36 @@ describe("functional: table", function()
c = "c",
}, _.dissoc("b", { a = "a", b = "b", c = "c" }))
end)
+
+ it("should assoc keys", function()
+ assert.same({
+ a = "a",
+ b = "b",
+ c = "c",
+ }, _.assoc("b", "b", { a = "a", c = "c" }))
+ end)
+end)
+
+describe("table immutability", function()
+ it("should not mutate tables", function()
+ local og_table = setmetatable({ key = "value", imagination = "poor", hotel = "trivago" }, {
+ __newindex = function()
+ error "Tried to newindex"
+ end,
+ })
+
+ _.prop("hotel", og_table)
+ _.path({ "hotel" }, og_table)
+ _.pick({ "hotel" }, og_table)
+ _.keys(og_table)
+ _.size(og_table)
+ _.from_pairs(_.to_pairs(og_table))
+ _.invert(og_table)
+ _.evolve({ hotel = _.to_upper }, og_table)
+ _.merge_left(og_table, {})
+ _.assoc("new", "value", og_table)
+ _.dissoc("hotel", og_table)
+
+ assert.same({ key = "value", imagination = "poor", hotel = "trivago" }, og_table)
+ end)
end)