about summary refs log tree commit diff
path: root/lib/tests/misc.nix
diff options
context:
space:
mode:
authorMykola Orliuk <virkony@gmail.com>2023-04-09 22:21:36 +0200
committerMykola Orliuk <virkony@gmail.com>2023-04-23 01:07:58 +0200
commit4ec4c6fda90cec38b0878bf6e601f5df82ae5a8f (patch)
treec56e2d0cdcec4d7a03217c076b70453dad3f3c31 /lib/tests/misc.nix
parentc1c73f72a6982646522bf6d676d734b68820b47d (diff)
lib/generators: add toLua/mkLuaInline
Suitable to simplify Lua-based configurations like neovim-lspconfig that
might need to interpolate Nix package paths.
Diffstat (limited to 'lib/tests/misc.nix')
-rw-r--r--lib/tests/misc.nix61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index baa382f3e589c..682b1a379fc35 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -915,6 +915,67 @@ runTests {
   };
 
 
+  testToLuaEmptyAttrSet = {
+    expr = generators.toLua {} {};
+    expected = ''{}'';
+  };
+
+  testToLuaEmptyList = {
+    expr = generators.toLua {} [];
+    expected = ''{}'';
+  };
+
+  testToLuaListOfVariousTypes = {
+    expr = generators.toLua {} [ null 43 3.14159 true ];
+    expected = ''
+      {
+        nil,
+        43,
+        3.14159,
+        true
+      }'';
+  };
+
+  testToLuaString = {
+    expr = generators.toLua {} ''double-quote (") and single quotes (')'';
+    expected = ''"double-quote (\") and single quotes (')"'';
+  };
+
+  testToLuaAttrsetWithLuaInline = {
+    expr = generators.toLua {} { x = generators.mkLuaInline ''"abc" .. "def"''; };
+    expected = ''
+      {
+        ["x"] = ("abc" .. "def")
+      }'';
+  };
+
+  testToLuaAttrsetWithSpaceInKey = {
+    expr = generators.toLua {} { "some space and double-quote (\")" = generators.mkLuaInline ''"abc" .. "def"''; };
+    expected = ''
+      {
+        ["some space and double-quote (\")"] = ("abc" .. "def")
+      }'';
+  };
+
+  testToLuaBasicExample = {
+    expr = generators.toLua {} {
+      cmd = [ "typescript-language-server" "--stdio" ];
+      settings.workspace.library = generators.mkLuaInline ''vim.api.nvim_get_runtime_file("", true)'';
+    };
+    expected = ''
+      {
+        ["cmd"] = {
+          "typescript-language-server",
+          "--stdio"
+        },
+        ["settings"] = {
+          ["workspace"] = {
+            ["library"] = (vim.api.nvim_get_runtime_file("", true))
+          }
+        }
+      }'';
+  };
+
 # CLI
 
   testToGNUCommandLine = {