diff options
| author | William Boman <william@redwill.se> | 2022-12-20 08:42:58 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-12-20 07:42:58 +0000 |
| commit | 25313762aac8fc313b769f20298bd4e6473cc6dd (patch) | |
| tree | e46fee667753f4fd7d16b2eac085348d3ecf821f /tests/mason-core/functional/table_spec.lua | |
| parent | feat: add expr module (#775) (diff) | |
| download | mason-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/functional/table_spec.lua')
| -rw-r--r-- | tests/mason-core/functional/table_spec.lua | 32 |
1 files changed, 32 insertions, 0 deletions
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) |
