about summary refs log tree commit diff
path: root/lib/tests/modules
diff options
context:
space:
mode:
authorRobert Hensing <robert@roberthensing.nl>2024-01-28 00:30:36 +0100
committerRobert Hensing <robert@roberthensing.nl>2024-02-11 18:44:52 +0100
commitca81a89839176c2e0d0b0fb01a931a4a65404fa6 (patch)
tree8d7dadb36f44c65a3d347ad67ca823db6993e652 /lib/tests/modules
parent80afdbf97f304771dd09f38ce8bc4d44627e7ad2 (diff)
lib.types.attrTag: init
Diffstat (limited to 'lib/tests/modules')
-rw-r--r--lib/tests/modules/types-attrTag.nix64
1 files changed, 64 insertions, 0 deletions
diff --git a/lib/tests/modules/types-attrTag.nix b/lib/tests/modules/types-attrTag.nix
new file mode 100644
index 0000000000000..08854ca73f566
--- /dev/null
+++ b/lib/tests/modules/types-attrTag.nix
@@ -0,0 +1,64 @@
+{ lib, config, ... }:
+let
+  inherit (lib) mkOption types;
+  forceDeep = x: builtins.deepSeq x x;
+in
+{
+  options = {
+    intStrings = mkOption {
+      type = types.attrsOf
+        (types.attrTag {
+          left = types.int;
+          right = types.str;
+        });
+    };
+    nested = mkOption {
+      type = types.attrTag {
+        left = types.int;
+        right = types.attrTag {
+          left = types.int;
+          right = types.str;
+        };
+      };
+    };
+    merged = mkOption {
+      type = types.attrsOf (
+        types.attrTag {
+          yay = types.int;
+        }
+      );
+    };
+    okChecks = mkOption {};
+  };
+  imports = [
+    {
+      options.merged = mkOption {
+        type = types.attrsOf (
+          types.attrTag {
+            nay = types.bool;
+          }
+        );
+      };
+    }
+  ];
+  config = {
+    intStrings.syntaxError = 1;
+    intStrings.syntaxError2 = {};
+    intStrings.syntaxError3 = { a = true; b = true; };
+    intStrings.syntaxError4 = lib.mkMerge [ { a = true; } { b = true; } ];
+    intStrings.mergeError = lib.mkMerge [ { int = throw "do not eval"; } { string = throw "do not eval"; } ];
+    intStrings.badTagError.rite = throw "do not eval";
+    intStrings.badTagTypeError.left = "bad";
+    intStrings.numberOne.left = 1;
+    intStrings.hello.right = "hello world";
+    nested.right.left = "not a number";
+    merged.negative.nay = false;
+    merged.positive.yay = 100;
+    okChecks =
+      assert config.intStrings.hello.right == "hello world";
+      assert config.intStrings.numberOne.left == 1;
+      assert config.merged.negative.nay == false;
+      assert config.merged.positive.yay == 100;
+      true;
+  };
+}