Compare commits

...

3 Commits

Author SHA1 Message Date
Starbeamrainbowlabs 8f03c6473b
test makeset 2022-09-24 13:45:50 +01:00
Starbeamrainbowlabs bdaedf0e7a
fixup 2022-09-24 13:42:00 +01:00
Starbeamrainbowlabs 38a72468d9
utils: rename folder tables → table to match API 2022-09-24 13:41:44 +01:00
17 changed files with 61 additions and 29 deletions

View File

@ -1,7 +1,7 @@
_G.worldeditadditions_core = {
split = require("worldeditadditions_core.utils.strings.split"),
table = {
contains = require("worldeditadditions_core.utils.tables.table_contains")
contains = require("worldeditadditions_core.utils.table.table_contains")
}
}
local parse_map = require("worldeditadditions_core.utils.parse.map")

View File

@ -0,0 +1,32 @@
local makeset = require("worldeditadditions_core.utils.table.makeset")
describe("table.makeset", function()
it("should work with a single item", function()
local result = makeset({ "apples" })
assert.are.same(
{ apples = true },
result
)
end)
it("should work with 2 items", function()
local result = makeset({ "apples", "orange" })
assert.are.same(
{ apples = true, orange = true },
result
)
end)
it("should work with duplicate items", function()
local result = makeset({ "apples", "apples" })
assert.are.same(
{ apples = true },
result
)
end)
it("should work with duplicate items and non-duplicate items", function()
local result = makeset({ "apples", "oranges", "apples" })
assert.are.same(
{ apples = true, oranges = true },
result
)
end)
end)

View File

@ -44,7 +44,7 @@ wea_c.terrain = dofile(wea_c.modpath.."/utils/terrain/init.lua")
dofile(wea_c.modpath.."/utils/strings/init.lua")
dofile(wea_c.modpath.."/utils/format/init.lua")
dofile(wea_c.modpath.."/utils/parse/init.lua")
dofile(wea_c.modpath.."/utils/tables/init.lua")
dofile(wea_c.modpath.."/utils/table/init.lua")
dofile(wea_c.modpath.."/utils/numbers.lua")
dofile(wea_c.modpath.."/utils/nodes.lua")

View File

@ -1,6 +1,6 @@
-- worldeditadditions_core = { modpath="/home/sbrl/.minetest/worlds/Mod-Sandbox/worldmods/WorldEditAdditions/worldeditadditions_core/" }
local wea_c = worldeditadditions_core
local table_map = dofile(wea_c.modpath.."/utils/tables/table_map.lua")
local table_map = dofile(wea_c.modpath.."/utils/table/table_map.lua")
local function is_whitespace(char)
return char:match("%s")

View File

@ -0,0 +1,25 @@
-- ████████ █████ ██████ ██ ███████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ███████ ██████ ██ █████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██ ██████ ███████ ███████ ███████
-- Functions that operate on tables.
-- Lua doesn't exactly come with batteries included, so this is quite an
-- extensive collection of functions :P
local wea_c = worldeditadditions_core
wea_c.table = {
apply = dofile(wea_c.modpath.."/utils/table/table_apply.lua"),
contains = dofile(wea_c.modpath.."/utils/table/table_contains.lua"),
deepcopy = dofile(wea_c.modpath.."/utils/table/deepcopy.lua"),
filter = dofile(wea_c.modpath.."/utils/table/table_filter.lua"),
get_last = dofile(wea_c.modpath.."/utils/table/table_get_last.lua"),
makeset = dofile(wea_c.modpath.."/utils/table/makeset.lua"),
map = dofile(wea_c.modpath.."/utils/table/table_map.lua"),
shallowcopy = dofile(wea_c.modpath.."/utils/table/shallowcopy.lua"),
tostring = dofile(wea_c.modpath.."/utils/table/table_tostring.lua"),
unique = dofile(wea_c.modpath.."/utils/table/table_unique.lua"),
unpack = dofile(wea_c.modpath.."/utils/table/table_unpack.lua"),
}

View File

@ -1,6 +1,6 @@
local wea_c = worldeditadditions_core
local table_unpack = dofile(wea_c.modpath.."/utils/tables/table_unpack.lua")
local table_unpack = dofile(wea_c.modpath.."/utils/table/table_unpack.lua")
--- Returns only the last count items in a given numerical table-based list.

View File

@ -1,25 +0,0 @@
-- ████████ █████ ██████ ██ ███████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ███████ ██████ ██ █████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██ ██████ ███████ ███████ ███████
-- Functions that operate on tables.
-- Lua doesn't exactly come with batteries included, so this is quite an
-- extensive collection of functions :P
local wea_c = worldeditadditions_core
wea_c.table = {
apply = dofile(wea_c.modpath.."/utils/tables/table_apply.lua"),
contains = dofile(wea_c.modpath.."/utils/tables/table_contains.lua"),
deepcopy = dofile(wea_c.modpath.."/utils/tables/deepcopy.lua"),
filter = dofile(wea_c.modpath.."/utils/tables/table_filter.lua"),
get_last = dofile(wea_c.modpath.."/utils/tables/table_get_last.lua"),
makeset = dofile(wea_c.modpath.."/utils/tables/makeset.lua"),
map = dofile(wea_c.modpath.."/utils/tables/table_map.lua"),
shallowcopy = dofile(wea_c.modpath.."/utils/tables/shallowcopy.lua"),
tostring = dofile(wea_c.modpath.."/utils/tables/table_tostring.lua"),
unique = dofile(wea_c.modpath.."/utils/tables/table_unique.lua"),
unpack = dofile(wea_c.modpath.."/utils/tables/table_unpack.lua"),
}