2024-05-18 11:36:22 +02:00
|
|
|
{ lazyUtils }:
|
|
|
|
|
|
|
|
let
|
|
|
|
nullPlugin = {
|
|
|
|
name = null;
|
|
|
|
short = null;
|
|
|
|
dir = null;
|
|
|
|
};
|
|
|
|
miniDrv = builtins.derivation {
|
|
|
|
name = "test";
|
|
|
|
pname = "test";
|
|
|
|
builder = "test";
|
|
|
|
system = "test";
|
|
|
|
};
|
2024-11-30 17:21:47 +01:00
|
|
|
minBind = {
|
|
|
|
bind = "<leader>";
|
|
|
|
cmd = null;
|
|
|
|
cmdIsFunction = false;
|
|
|
|
opts = null;
|
|
|
|
};
|
2024-05-18 11:36:22 +02:00
|
|
|
in
|
|
|
|
{
|
|
|
|
helpers = {
|
|
|
|
getName = {
|
|
|
|
testName = {
|
|
|
|
expr = lazyUtils.helpers.getName (nullPlugin // { name = "nameTest"; });
|
|
|
|
expected = "nameTest";
|
|
|
|
};
|
|
|
|
testShort = {
|
|
|
|
expr = lazyUtils.helpers.getName (nullPlugin // { short = "shortTest"; });
|
|
|
|
expected = "shortTest";
|
|
|
|
};
|
|
|
|
testDir = {
|
|
|
|
expr = lazyUtils.helpers.getName (nullPlugin // { dir = ./empty.txt; });
|
|
|
|
expected = "empty.txt";
|
|
|
|
};
|
|
|
|
testDrv = {
|
|
|
|
expr = lazyUtils.helpers.getName (nullPlugin // { dir = miniDrv; });
|
|
|
|
expected = "test";
|
|
|
|
};
|
|
|
|
testInvalidInput = {
|
|
|
|
expr = lazyUtils.helpers.getName { };
|
|
|
|
expectedError = {
|
|
|
|
type = "ThrownError";
|
|
|
|
# For some reason there is whitespace after the newline
|
|
|
|
msg = "Could not determine a plugin name.\n +\\{\\}";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-11-30 17:21:47 +01:00
|
|
|
getKey = {
|
|
|
|
testBind = {
|
|
|
|
expr = lazyUtils.helpers.getKey minBind;
|
|
|
|
expected = [
|
|
|
|
minBind.bind
|
|
|
|
];
|
|
|
|
};
|
|
|
|
testCmd = {
|
|
|
|
expr = lazyUtils.helpers.getKey (minBind // { cmd = "testCmd"; });
|
|
|
|
expected = [
|
|
|
|
minBind.bind
|
|
|
|
"testCmd"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
testFnNoCmd = {
|
|
|
|
expr = lazyUtils.helpers.getKey (minBind // { cmdIsFunction = true; });
|
|
|
|
expected = [
|
|
|
|
minBind.bind
|
|
|
|
];
|
|
|
|
};
|
|
|
|
testFn = {
|
|
|
|
expr =
|
|
|
|
let
|
|
|
|
result = lazyUtils.helpers.getKey (
|
|
|
|
minBind
|
|
|
|
// {
|
|
|
|
cmd = "testCmd";
|
|
|
|
cmdIsFunction = true;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
in
|
|
|
|
assert builtins.isFunction (builtins.elemAt result 1);
|
|
|
|
map (val: if builtins.isFunction val then val null else val) result;
|
|
|
|
expected = [
|
|
|
|
minBind.bind
|
|
|
|
"testCmd"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
testOpts = {
|
|
|
|
expr = lazyUtils.helpers.getKey (
|
|
|
|
minBind
|
|
|
|
// {
|
|
|
|
opts = {
|
|
|
|
description = "A test keybind.";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
expected = [
|
|
|
|
minBind.bind
|
|
|
|
{
|
|
|
|
__unpack = true;
|
|
|
|
description = "A test keybind.";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
};
|
|
|
|
testInvalid = {
|
|
|
|
expr = lazyUtils.helpers.getKey (minBind // { cmdIsFunction = null; });
|
|
|
|
expectedError.type = "AssertionError";
|
|
|
|
};
|
|
|
|
};
|
2024-05-18 11:36:22 +02:00
|
|
|
pluginWrapper = {
|
|
|
|
testShort = {
|
|
|
|
expr = lazyUtils.helpers.pluginWrapper "test";
|
|
|
|
expected = {
|
|
|
|
short = "test";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
testDrv = {
|
|
|
|
expr = lazyUtils.helpers.pluginWrapper miniDrv;
|
|
|
|
expected = {
|
|
|
|
dir = miniDrv;
|
|
|
|
};
|
|
|
|
};
|
2024-11-30 17:22:51 +01:00
|
|
|
testFn = {
|
|
|
|
expr = (lazyUtils.helpers.pluginWrapper (_: "test")).dir null;
|
|
|
|
expected = "test";
|
|
|
|
};
|
2024-05-18 11:36:22 +02:00
|
|
|
testSet = {
|
|
|
|
expr = lazyUtils.helpers.pluginWrapper { };
|
|
|
|
expected = { };
|
|
|
|
};
|
|
|
|
testInvalidInput = {
|
|
|
|
expr = lazyUtils.helpers.pluginWrapper null;
|
|
|
|
expectedError.type = "AssertionError";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-11-30 17:22:51 +01:00
|
|
|
lazyPluginClosure = {
|
|
|
|
testShort = {
|
|
|
|
expr = lazyUtils.lazyPluginClosure "pluginName";
|
|
|
|
expected = ''{"pluginName",name = "pluginName"}'';
|
|
|
|
};
|
|
|
|
testDrv = {
|
|
|
|
expr = lazyUtils.lazyPluginClosure miniDrv;
|
|
|
|
expected = ''{dir = "${miniDrv.outPath}",name = "${miniDrv.name}"}'';
|
|
|
|
};
|
|
|
|
};
|
2024-05-18 11:36:22 +02:00
|
|
|
}
|