summary refs log tree commit diff
path: root/lib/tests/misc.nix
diff options
context:
space:
mode:
authorProfpatsch <mail@profpatsch.de>2017-06-06 22:41:22 +0200
committerProfpatsch <mail@profpatsch.de>2017-06-22 00:58:59 +0200
commitb1ffe5e4c029c9f5675bcc42997413fd1b21fbf1 (patch)
treef8569d068102606b54724713c1c6a51cc4f539dc /lib/tests/misc.nix
parentdd3f2e648a6ee5dc7ba88bf2e3d13b6b47686350 (diff)
downloadnixpkgs-b1ffe5e4c029c9f5675bcc42997413fd1b21fbf1.tar
nixpkgs-b1ffe5e4c029c9f5675bcc42997413fd1b21fbf1.tar.gz
nixpkgs-b1ffe5e4c029c9f5675bcc42997413fd1b21fbf1.tar.bz2
nixpkgs-b1ffe5e4c029c9f5675bcc42997413fd1b21fbf1.tar.lz
nixpkgs-b1ffe5e4c029c9f5675bcc42997413fd1b21fbf1.tar.xz
nixpkgs-b1ffe5e4c029c9f5675bcc42997413fd1b21fbf1.tar.zst
nixpkgs-b1ffe5e4c029c9f5675bcc42997413fd1b21fbf1.zip
lib/generators: toPretty
`toPretty` implements a pretty printer for nix values.
Diffstat (limited to 'lib/tests/misc.nix')
-rw-r--r--lib/tests/misc.nix30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index 22557bdfeef..f40036274e8 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -285,6 +285,36 @@ runTests {
       expected = builtins.toJSON val;
   };
 
+  testToPretty = {
+    expr = mapAttrs (const (generators.toPretty {})) rec {
+      int = 42;
+      bool = true;
+      string = "fnord";
+      null_ = null;
+      function = x: x;
+      list = [ 3 4 function [ false ] ];
+      attrs = { foo = null; "foo bar" = "baz"; };
+      drv = derivation { name = "test"; system = builtins.currentSystem; };
+    };
+    expected = rec {
+      int = "42";
+      bool = "true";
+      string = "\"fnord\"";
+      null_ = "null";
+      function = "<λ>";
+      list = "[ 3 4 ${function} [ false ] ]";
+      attrs = "{ \"foo\" = null; \"foo bar\" = \"baz\"; }";
+      drv = "<δ>";
+    };
+  };
+
+  testToPrettyAllowPrettyValues = {
+    expr = generators.toPretty { allowPrettyValues = true; }
+             { __pretty = v: "«" + v + "»"; val = "foo"; };
+    expected  = "«foo»";
+  };
+
+
 # MISC
 
   testOverridableDelayableArgsTest = {