From 5342429193f05394513ec2a4f5b0c4d4287983b4 Mon Sep 17 00:00:00 2001 From: derped Date: Sat, 30 Nov 2024 17:21:47 +0100 Subject: [PATCH] Add keyBind tests. --- tests/lazyUtils.nix | 67 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/tests/lazyUtils.nix b/tests/lazyUtils.nix index 1ca9e9f..07e4f44 100644 --- a/tests/lazyUtils.nix +++ b/tests/lazyUtils.nix @@ -12,6 +12,12 @@ let builder = "test"; system = "test"; }; + minBind = { + bind = ""; + cmd = null; + cmdIsFunction = false; + opts = null; + }; in { helpers = { @@ -41,7 +47,66 @@ in }; }; }; - getKey = { }; + 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";