Remove obsolete stuffs

This commit is contained in:
leokhoa
2025-10-05 17:33:37 +02:00
parent 71b1fe4850
commit 1c759708e4
15680 changed files with 4890893 additions and 139873 deletions

View File

@@ -0,0 +1,84 @@
local color = require('color')
describe("color module", function()
it("should define color constants", function()
assert.are.equals(color.BLACK, 0)
assert.are.equals(color.RED, 1)
assert.are.equals(color.GREEN, 2)
assert.are.equals(color.YELLOW, 3)
assert.are.equals(color.BLUE, 4)
assert.are.equals(color.MAGENTA, 5)
assert.are.equals(color.CYAN, 6)
assert.are.equals(color.WHITE, 7)
assert.are.equals(color.DEFAULT, 9)
assert.are.equals(color.BOLD, 1)
end)
it("should export methods", function()
assert.are.equal(type(color.set_color), 'function')
assert.are.equal(type(color.get_clink_color), 'function')
assert.are.equal(type(color.color_text), 'function')
end)
describe("'set_color' method", function ()
local VALID_COLOR_STRING = "^\x1b%[(3%d);(%d%d?);(4%d)m$"
it("should accept numeric arguments and return string", function ()
assert.are.equal(type(color.set_color(1, 2, 3)), "string")
end)
it("should accept nil arguments and still return string", function ()
assert.are.equal(type(color.set_color()), "string")
end)
it("should throw if first two arguments are not a numbers or nil", function ()
assert.has.error(function() color.set_color('a', 2, 3) end)
assert.has.error(function() color.set_color(1, 'a', 3) end)
end)
it("should throw if arguments is out of range", function ()
assert.has.error(function() color.set_color(100, 1, 1) end)
assert.has.error(function() color.set_color(1, 200, 1) end)
end)
it("should return valid ANSI color code", function ()
-- TODO: either find appropriate assert or invent custom one
-- assert_match(VALID_COLOR_STRING, color.set_color(3, 2, 1))
end)
it("should set color to DEFAULT if no corresponding argument was passed", function ()
local _, _, fore, bold, back = string.find(color.set_color(), VALID_COLOR_STRING)
assert.are.equals(fore, "39");
assert.are.equals(back, "49");
assert.are.equals(bold, "22");
end)
end)
describe("'get_clink_color' method", function ()
it("should do nothing since Clink support is only available in actual Clink", function ()
assert.are.equals(color.get_clink_color('color.git.star'), "")
end)
end)
describe("'color_text' method", function ()
local TEST_STRING = "abc"
local VALID_COLOR_STRING = "\x1b%[3%d;%d%d?;4%dm"
it("should wrap string into valid ANSI codes", function ()
-- TODO: either find appropriate assert or invent custom one
-- assert_match("^"..VALID_COLOR_STRING..TEST_STRING..VALID_COLOR_STRING.."$",
-- color.color_text(TEST_STRING, 1, 2, 3))
end)
it("should reset color to default", function ()
local _,_, color_suffix = string.find(color.color_text(TEST_STRING, 1, 2, 3),
"^"..VALID_COLOR_STRING..TEST_STRING.."("..VALID_COLOR_STRING..")$")
assert.are.equals(color_suffix, color.set_color())
end)
end)
end)

View File

@@ -0,0 +1,146 @@
local map = require('funclib').map
local concat = require('funclib').concat
local filter = require('funclib').filter
local reduce = require('funclib').reduce
describe("funclib module", function()
it("should export some methods", function()
local methods_count = 0
-- iterate through table to count keys rather than `use #... notation
for _,_ in pairs(require("funclib")) do
methods_count = methods_count + 1 end
assert.are.equals(methods_count, 4)
end)
describe("'filter' function", function ()
local test_table = {"a", "b", nil, false}
it("should exist", function()
assert.are.equals(type(filter), "function")
end)
it("should accept nil arguments", function()
assert.has_no.errors(filter)
end)
it("should return empty table if input table is not specified", function()
assert.are.same(filter(), {})
end)
it("should throw if first argument is not a table", function()
assert.has_error(function() filter("aaa") end)
end)
it("should throw if second argument is not a function", function()
assert.has_error(function() filter({"a", "b"}, "a") end)
-- TODO: uncomment this
-- assert.has_error(function() filter({}, "a") end)
end)
it("should filter out falsy values if no filter function specified", function()
assert.are.same(filter(test_table), {"a", "b"})
end)
it("should filter out values which doesn't satisfy filter function", function()
local function test_filter1(a) return a == "a" end
local function test_filter2(a) return a == nil end
assert.are.same(filter(test_table, test_filter1), {"a"})
assert.are.same(filter(test_table, test_filter2), {nil})
end)
end)
describe("'map' function", function ()
local test_table = {"a", "b", "c"}
it("should exist", function()
assert.are.equals(type(map), "function")
end)
it("should accept nil arguments", function()
assert.has_no.errors(map)
end)
it("should return empty table if input table is not specified", function()
assert.are.same(map(), {})
end)
it("should throw if first argument is not a table", function()
assert.has_error(function() map("aaa") end)
end)
it("should throw if second argument is not a function", function()
assert.has_error(function() map(test_table, "a") end)
end)
it("should return original table if no map function specified", function()
assert.are.same(map(test_table), test_table)
end)
it("should apply map function to all values", function()
local function test_map(a) return a == "a" end
assert.are.same(map(test_table, test_map), {true, false, false})
end)
end)
describe("'reduce' function", function ()
local test_table = {1, 2, 3}
local _noop = function() end
it("should exist", function()
assert.are.equals(type(reduce), "function")
end)
it("should accept nil arguments (except reduce func)", function()
assert.has_no.errors(function() reduce(nil, nil, _noop) end)
end)
it("should return accumulator if input table is not specified", function()
assert.are.equals(reduce("accum", nil, _noop), "accum")
end)
it("should throw if second argument (source table) is not a table", function()
assert.has_error(function() reduce({}, "aaa", _noop) end)
end)
it("should throw if third argument (reduce func) is not a function", function()
assert.has_error(function() reduce({}, {}, "a") end)
-- TODO: uncomment this
-- assert.has_error(reduce)
end)
it("should apply reduce func to each element of source table", function()
local function test_reduce(a, v) table.insert(a, v+1) return a end
assert.are.same(reduce({}, test_table, test_reduce), {2, 3, 4})
end)
end)
describe("'concat' function", function ()
it("should exist", function()
assert.are.equals(type(concat), "function")
end)
it("should accept nil arguments", function()
assert.has_no.errors(concat)
end)
it("should return empty table if no input arguments specified", function()
assert.are.same(concat(), {})
end)
it("should wrap non-table parameter into a table", function()
local ret = concat("a")
assert.is_not.equals(ret, {})
assert.are.equals(type(ret), "table")
end)
it("should omit nil arguments", function()
assert.are.same(concat("a", nil, "b"), {"a", "b"})
end)
it("should copy values from table params into result", function()
assert.are.same(concat("a", {nil}, {"b"}), {"a", "b"})
end)
end)
end)

View File

@@ -0,0 +1,24 @@
local path = require('path')
describe("path module", function()
describe("is_absolute", function ()
it("should return true for absolute paths", function ()
assert.is_true(path.is_absolute("c:/foo.bar"))
assert.is_true(path.is_absolute("c:/foo.bar/baz"))
assert.is_true(path.is_absolute("c:\\foo.bar"))
assert.is_true(path.is_absolute("c:\\foo.bar\\baz"))
assert.is_true(path.is_absolute("z:/baz\\foo.bar"))
assert.is_true(path.is_absolute("z:\\baz/foo.bar"))
assert.is_true(path.is_absolute("c:/quux/..\\baz/foo.bar"))
end)
it("should return false for relative paths", function ()
assert.is_false(path.is_absolute("./foo.bar"))
assert.is_false(path.is_absolute(".\\baz"))
assert.is_false(path.is_absolute("foo.bar"))
assert.is_false(path.is_absolute(".\\foo.bar\\baz"))
assert.is_false(path.is_absolute("./baz\\foo.bar"))
assert.is_false(path.is_absolute("..\\baz/foo.bar"))
end)
end)
end)