Commit 39ac5697 authored by Michal 'vorner' Vaner's avatar Michal 'vorner' Vaner

lua: lines2set

New module for misc utilities, currently containing function to split
text into lines and provide them as a set.
parent 469fb142
--[[
Copyright 2016, CZ.NIC z.s.p.o. (http://www.nic.cz/)
This file is part of the turris updater.
Updater is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Updater is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Updater. If not, see <http://www.gnu.org/licenses/>.
]]--
module "utils"
-- Convert provided text into set of lines. Doesn't care about the order.
function lines2set(lines)
local result = {}
for line in lines:gmatch("[^\n]+") do
result[line] = true
end
return result
end
return _M
......@@ -19,7 +19,8 @@ C_TESTS := \
LUA_TESTS := \
backend \
events \
interpreter
interpreter \
utils
define DO_C_TEST
......
......@@ -19,6 +19,9 @@ along with Updater. If not, see <http://www.gnu.org/licenses/>.
require 'lunit'
local B = require 'backend'
require 'utils'
local lines2set = utils.lines2set
module("backend-tests", package.seeall, lunit.testcase)
......@@ -233,15 +236,6 @@ local orig_status_file = B.status_file
local orig_info_dir = B.info_dir
local tmp_dirs = {}
-- Convert provided text into set of lines. Doesn't care about the order.
local function lines2set(lines)
local result = {}
for line in lines:gmatch("[^\n]+") do
result[line] = true
end
return result
end
function test_pkg_unpack()
local fname = (os.getenv("S") or ".") .. "/tests/data/updater.ipk"
local f = io.open(fname)
......
--[[
Copyright 2016, CZ.NIC z.s.p.o. (http://www.nic.cz/)
This file is part of the turris updater.
Updater is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Updater is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Updater. If not, see <http://www.gnu.org/licenses/>.
]]--
require "lunit"
local U = require "utils"
module("utils-tests", package.seeall, lunit.testcase)
function test_lines2set()
local treq = {
line = true,
another = true
}
assert_table_equal(treq, U.lines2set([[line
another]]))
assert_table_equal(treq, U.lines2set([[another
line]]))
assert_table_equal(treq, U.lines2set([[line
another
line]]))
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment