Skip to content

Commit 9b867f1

Browse files
committed
tests/lazyloading/lazy: reduce repetition
1 parent 832693b commit 9b867f1

File tree

1 file changed

+45
-41
lines changed
  • tests/test-sources/plugins/lazyloading

1 file changed

+45
-41
lines changed

tests/test-sources/plugins/lazyloading/lazy.nix

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
let
2+
getFirstLazyPlugin =
3+
config:
4+
let
5+
inherit (config.plugins.lazy) plugins;
6+
in
7+
if plugins == [ ] then null else builtins.head plugins;
8+
9+
getPluginKeys = plugin: if plugin != null && builtins.isList plugin.keys then plugin.keys else [ ];
10+
getPluginCmd = plugin: if plugin != null && builtins.isList plugin.cmd then plugin.cmd else [ ];
11+
in
112
{
213
lazy-load-neovim-plugin-configured =
314
{ config, lib, ... }:
@@ -18,31 +29,25 @@
1829
};
1930
};
2031

21-
assertions = [
22-
{
23-
assertion = (builtins.length config.plugins.lazy.plugins) == 1;
24-
message = "`lazy.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
25-
}
26-
{
27-
assertion =
28-
let
29-
plugins = config.plugins.lazy.plugins or [ ];
30-
plugin = if builtins.length plugins > 0 then builtins.head plugins else null;
31-
cmd = if plugin != null && builtins.isList plugin.cmd then plugin.cmd else [ ];
32-
in
33-
(builtins.length cmd) == 1;
34-
message = "`lazy.plugins[0].cmd` should have contained a configuration.";
35-
}
36-
{
37-
assertion =
38-
let
39-
plugins = config.plugins.lazy.plugins or [ ];
40-
plugin = if builtins.length plugins > 0 then builtins.head plugins else null;
41-
in
42-
plugin != null && config.plugins.neotest.settings == plugin.opts;
43-
message = "`lazy.plugins[0].opts` should have contained `neotest` settings.";
44-
}
45-
];
32+
assertions =
33+
let
34+
plugin = getFirstLazyPlugin config;
35+
cmd = getPluginCmd plugin;
36+
in
37+
[
38+
{
39+
assertion = (builtins.length config.plugins.lazy.plugins) == 1;
40+
message = "`lazy.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
41+
}
42+
{
43+
assertion = (builtins.length cmd) == 1;
44+
message = "`lazy.plugins[0].cmd` should have contained a configuration.";
45+
}
46+
{
47+
assertion = plugin != null && config.plugins.neotest.settings == plugin.opts;
48+
message = "`lazy.plugins[0].opts` should have contained `neotest` settings.";
49+
}
50+
];
4651
};
4752

4853
dont-lazy-load-unconfigured =
@@ -85,21 +90,20 @@
8590
};
8691
};
8792

88-
assertions = [
89-
{
90-
assertion = (builtins.length config.plugins.lazy.plugins) == 1;
91-
message = "`lazy.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
92-
}
93-
{
94-
assertion =
95-
let
96-
plugins = config.plugins.lazy.plugins or [ ];
97-
plugin = if builtins.length plugins > 0 then builtins.head plugins else null;
98-
cmd = if plugin != null && builtins.isList plugin.cmd then plugin.cmd else [ ];
99-
in
100-
(builtins.length cmd) == 1;
101-
message = "`lazy.plugins[0].cmd` should have contained a configuration.";
102-
}
103-
];
93+
assertions =
94+
let
95+
plugin = getFirstLazyPlugin config;
96+
cmd = getPluginCmd plugin;
97+
in
98+
[
99+
{
100+
assertion = (builtins.length config.plugins.lazy.plugins) == 1;
101+
message = "`lazy.plugins` should have contained a single plugin configuration, but contained ${builtins.toJSON config.plugins.lz-n.plugins}";
102+
}
103+
{
104+
assertion = (builtins.length cmd) == 1;
105+
message = "`lazy.plugins[0].cmd` should have contained a configuration.";
106+
}
107+
];
104108
};
105109
}

0 commit comments

Comments
 (0)