Software /
code /
prosody
Changeset
13245:ffe4adbd2af9
util.array: Fix new() library function
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 22 Jul 2023 16:31:05 +0200 |
parents | 13244:2902c54f45a6 |
children | 13246:2e04d54fb013 |
files | spec/util_array_spec.lua util/array.lua |
diffstat | 2 files changed, 10 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/spec/util_array_spec.lua Sat Jul 22 16:20:36 2023 +0200 +++ b/spec/util_array_spec.lua Sat Jul 22 16:31:05 2023 +0200 @@ -1,6 +1,13 @@ local array = require "util.array"; describe("util.array", function () describe("creation", function () + describe("new", function () + it("works", function () + local a = array.new({"a", "b", "c"}); + assert.same({"a", "b", "c"}, a); + end); + end); + describe("from table", function () it("works", function () local a = array({"a", "b", "c"});
--- a/util/array.lua Sat Jul 22 16:20:36 2023 +0200 +++ b/util/array.lua Sat Jul 22 16:31:05 2023 +0200 @@ -36,7 +36,9 @@ return setmetatable(t or {}, array_mt); end -array.new = new_array; +function array.new(t) + return setmetatable(t or {}, array_mt); +end function array_mt.__add(a1, a2) local res = new_array();