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-29 18:35:07 +0200
committerMykola Orliuk <virkony@gmail.com>2023-04-29 19:26:35 +0200
commit7287c0e076c3fd69d55e96cdc5c46e951bed01d4 (patch)
tree0771cf865182ff9597e46f4a10b7805df1ff5a30 /lib/tests/misc.nix
parent25f8a3f2763ac89f5124176627b22181d883a053 (diff)
downloadnixlib-7287c0e076c3fd69d55e96cdc5c46e951bed01d4.tar
nixlib-7287c0e076c3fd69d55e96cdc5c46e951bed01d4.tar.gz
nixlib-7287c0e076c3fd69d55e96cdc5c46e951bed01d4.tar.bz2
nixlib-7287c0e076c3fd69d55e96cdc5c46e951bed01d4.tar.lz
nixlib-7287c0e076c3fd69d55e96cdc5c46e951bed01d4.tar.xz
nixlib-7287c0e076c3fd69d55e96cdc5c46e951bed01d4.tar.zst
nixlib-7287c0e076c3fd69d55e96cdc5c46e951bed01d4.zip
lib.generators.toLua: asBindings option
Allows to generate code block for setting of global variables
Diffstat (limited to 'lib/tests/misc.nix')
-rw-r--r--lib/tests/misc.nix40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index 49336b8b9630..ea3548b9514e 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -4,6 +4,11 @@
 with import ../default.nix;
 
 let
+  testingThrow = expr: {
+    expr = (builtins.tryEval (builtins.seq expr "didn't throw"));
+    expected = { success = false; value = false; };
+  };
+  testingDeepThrow = expr: testingThrow (builtins.deepSeq expr expr);
 
   testSanitizeDerivationName = { name, expected }:
   let
@@ -962,6 +967,41 @@ runTests {
     expected = ''{ 41, 43 }'';
   };
 
+  testToLuaEmptyBindings = {
+    expr = generators.toLua { asBindings = true; } {};
+    expected = "";
+  };
+
+  testToLuaBindings = {
+    expr = generators.toLua { asBindings = true; } { x1 = 41; _y = { a = 43; }; };
+    expected = ''
+      _y = {
+        ["a"] = 43
+      }
+      x1 = 41
+    '';
+  };
+
+  testToLuaPartialTableBindings = {
+    expr = generators.toLua { asBindings = true; } { "x.y" = 42; };
+    expected = ''
+      x.y = 42
+    '';
+  };
+
+  testToLuaIndentedBindings = {
+    expr = generators.toLua { asBindings = true; indent = "  "; } { x = { y = 42; }; };
+    expected = "  x = {\n    [\"y\"] = 42\n  }\n";
+  };
+
+  testToLuaBindingsWithSpace = testingThrow (
+    generators.toLua { asBindings = true; } { "with space" = 42; }
+  );
+
+  testToLuaBindingsWithLeadingDigit = testingThrow (
+    generators.toLua { asBindings = true; } { "11eleven" = 42; }
+  );
+
   testToLuaBasicExample = {
     expr = generators.toLua {} {
       cmd = [ "typescript-language-server" "--stdio" ];