Skip to content

Commit

Permalink
tests/lazyloading: reduce repetition
Browse files Browse the repository at this point in the history
  • Loading branch information
khaneliman committed Dec 9, 2024
1 parent 5f00c8d commit 2f8a47a
Showing 1 changed file with 103 additions and 122 deletions.
225 changes: 103 additions & 122 deletions tests/test-sources/plugins/lazyloading/lz-n.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
let
getFirstLznPlugin =
config:
let
inherit (config.plugins.lz-n) plugins;
in
if plugins == [ ] then null else builtins.head plugins;

getPluginKeys = plugin: if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ];
in
{
lazy-load-neovim-plugin-configured =
{ config, lib, ... }:
Expand All @@ -24,31 +34,26 @@
};
};

assertions = [
{
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion =
let
inherit (config.plugins.lz-n) plugins;
plugin = if plugins == [ ] then null else builtins.head plugins;
keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ];
in
(builtins.length keys) == 1;
message = "`lz-n.plugins[0].keys` should have contained a configuration.";
}
{
assertion =
let
inherit (config.plugins.lz-n) plugins;
plugin = if plugins == [ ] then null else builtins.head plugins;
in
plugin != null && lib.hasInfix config.plugins.neotest.luaConfig.content plugin.after.__raw;
message = "`lz-n.plugins[0].after` should have contained `neotest` lua content.";
}
];
assertions =
let
plugin = getFirstLznPlugin config;
keys = getPluginKeys plugin;
in
[
{
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion = (builtins.length keys) == 1;
message = "`lz-n.plugins[0].keys` should have contained a configuration.";
}
{
assertion =
plugin != null && lib.hasInfix config.plugins.neotest.luaConfig.content plugin.after.__raw;
message = "`lz-n.plugins[0].after` should have contained `neotest` lua content.";
}
];
};

lazy-load-lz-n-configured =
Expand Down Expand Up @@ -104,47 +109,31 @@
];
};
};
assertions = [
{
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion =
let
plugin = builtins.head config.plugins.lz-n.plugins;
keys = if builtins.isList plugin.keys then plugin.keys else [ ];
in
(builtins.length keys) == 4;
message =
let
plugin = builtins.head config.plugins.lz-n.plugins;
in
"`lz-n.plugins[0].keys` should have contained 4 key configurations, but contained ${builtins.toJSON plugin.keys}";
}
{
assertion =
let
plugin = builtins.head config.plugins.lz-n.plugins;
cmd = plugin.cmd or null;
cmd' = lib.optionals (builtins.isList cmd) cmd;
in
(builtins.length cmd') == 4;
message =
let
plugin = builtins.head config.plugins.lz-n.plugins;
in
"`lz-n.plugins[0].cmd` should have contained 4 cmd configurations, but contained ${builtins.toJSON plugin.cmd}";
}
{
assertion =
let
plugin = builtins.head config.plugins.lz-n.plugins;
in
lib.hasInfix config.plugins.codesnap.luaConfig.content plugin.after.__raw;
message = "`lz-n.plugins[0].after` should have contained `codesnap` lua content.";
}
];
assertions =
let
plugin = getFirstLznPlugin config;
keys = getPluginKeys plugin;
cmd = plugin.cmd or null;
cmd' = lib.optionals (builtins.isList cmd) cmd;
in
[
{
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion = (builtins.length keys) == 4;
message = "`lz-n.plugins[0].keys` should have contained 4 key configurations, but contained ${builtins.toJSON plugin.keys}";
}
{
assertion = (builtins.length cmd') == 4;
message = "`lz-n.plugins[0].cmd` should have contained 4 cmd configurations, but contained ${builtins.toJSON plugin.cmd}";
}
{
assertion = lib.hasInfix config.plugins.codesnap.luaConfig.content plugin.after.__raw;
message = "`lz-n.plugins[0].after` should have contained `codesnap` lua content.";
}
];
};

dont-lazy-load-colorscheme-automatically =
Expand Down Expand Up @@ -201,32 +190,24 @@
};
};

assertions = [
{
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
message = "`lz-n.plugins` should have contained no plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion =
let
plugin = builtins.head config.plugins.lz-n.plugins;
in
plugin.colorscheme == "catppuccin";
message =
let
plugin = builtins.head config.plugins.lz-n.plugins;
in
"`lz-n.plugins[0].colorscheme` should have been `catppuccin`, but contained ${builtins.toJSON plugin.colorscheme}";
}
{
assertion =
let
plugin = builtins.head config.plugins.lz-n.plugins;
in
lib.hasInfix config.colorschemes.catppuccin.luaConfig.content plugin.after.__raw;
message = "`lz-n.plugins[0].after` should have contained `catppuccin` lua content.";
}
];
assertions =
let
plugin = getFirstLznPlugin config;
in
[
{
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
message = "`lz-n.plugins` should have contained no plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion = plugin.colorscheme == "catppuccin";
message = "`lz-n.plugins[0].colorscheme` should have been `catppuccin`, but contained ${builtins.toJSON plugin.colorscheme}";
}
{
assertion = lib.hasInfix config.colorschemes.catppuccin.luaConfig.content plugin.after.__raw;
message = "`lz-n.plugins[0].after` should have contained `catppuccin` lua content.";
}
];
};

lazy-load-enabled-automatically =
Expand All @@ -253,22 +234,21 @@
};
};

assertions = [
{
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion =
let
inherit (config.plugins.lz-n) plugins;
plugin = if plugins == [ ] then null else builtins.head plugins;
keys = if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ];
in
(builtins.length keys) == 1;
message = "`lz-n.plugins[0].keys` should have contained a configuration.";
}
];
assertions =
let
plugin = getFirstLznPlugin config;
keys = getPluginKeys plugin;
in
[
{
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion = (builtins.length keys) == 1;
message = "`lz-n.plugins[0].keys` should have contained a configuration.";
}
];
};

wrap-functionless-luaConfig =
Expand All @@ -290,19 +270,20 @@
};
};

assertions = [
{
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion =
let
plugin = builtins.head config.plugins.lz-n.plugins;
in
plugin.after.__raw == "function()\n " + config.plugins.telescope.luaConfig.content + " \nend";
message = "`lz-n.plugins[0].after` should have contained a function wrapped `telescope` lua content.";
}
];
assertions =
let
plugin = getFirstLznPlugin config;
in
[
{
assertion = (builtins.length config.plugins.lz-n.plugins) == 1;
message = "`lz-n.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
}
{
assertion =
plugin.after.__raw == "function()\n " + config.plugins.telescope.luaConfig.content + " \nend";
message = "`lz-n.plugins[0].after` should have contained a function wrapped `telescope` lua content.";
}
];
};
}

0 comments on commit 2f8a47a

Please sign in to comment.