133 lines
3.2 KiB
Nix
133 lines
3.2 KiB
Nix
{ lazyUtils }:
|
|
|
|
let
|
|
nullPlugin = {
|
|
name = null;
|
|
short = null;
|
|
dir = null;
|
|
};
|
|
miniDrv = builtins.derivation {
|
|
name = "test";
|
|
pname = "test";
|
|
builder = "test";
|
|
system = "test";
|
|
};
|
|
minBind = {
|
|
bind = "<leader>";
|
|
cmd = null;
|
|
cmdIsFunction = false;
|
|
opts = null;
|
|
};
|
|
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 +\\{\\}";
|
|
};
|
|
};
|
|
};
|
|
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";
|
|
};
|
|
};
|
|
pluginWrapper = {
|
|
testShort = {
|
|
expr = lazyUtils.helpers.pluginWrapper "test";
|
|
expected = {
|
|
short = "test";
|
|
};
|
|
};
|
|
testDrv = {
|
|
expr = lazyUtils.helpers.pluginWrapper miniDrv;
|
|
expected = {
|
|
dir = miniDrv;
|
|
};
|
|
};
|
|
testSet = {
|
|
expr = lazyUtils.helpers.pluginWrapper { };
|
|
expected = { };
|
|
};
|
|
testInvalidInput = {
|
|
expr = lazyUtils.helpers.pluginWrapper null;
|
|
expectedError.type = "AssertionError";
|
|
};
|
|
};
|
|
};
|
|
}
|