summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
authorLéo Gaspard <leo@gaspard.io>2018-10-14 02:55:00 +0900
committerProfpatsch <mail@profpatsch.de>2018-10-15 14:03:16 +0200
commit455e0ed88527d69a9c4a52e1238d35ec61556257 (patch)
treeec36a00446e8ec504496d14e175ca7c7af4c9fba /lib
parent5b343e7e8b5bd0132546bde40a0e3b6b639347eb (diff)
downloadnixlib-455e0ed88527d69a9c4a52e1238d35ec61556257.tar
nixlib-455e0ed88527d69a9c4a52e1238d35ec61556257.tar.gz
nixlib-455e0ed88527d69a9c4a52e1238d35ec61556257.tar.bz2
nixlib-455e0ed88527d69a9c4a52e1238d35ec61556257.tar.lz
nixlib-455e0ed88527d69a9c4a52e1238d35ec61556257.tar.xz
nixlib-455e0ed88527d69a9c4a52e1238d35ec61556257.tar.zst
nixlib-455e0ed88527d69a9c4a52e1238d35ec61556257.zip
generators: make toPretty handle floats correctly
Diffstat (limited to 'lib')
-rw-r--r--lib/generators.nix1
-rw-r--r--lib/tests/misc.nix2
2 files changed, 3 insertions, 0 deletions
diff --git a/lib/generators.nix b/lib/generators.nix
index f5faf7007860..863ba847423e 100644
--- a/lib/generators.nix
+++ b/lib/generators.nix
@@ -143,6 +143,7 @@ rec {
   }@args: v: with builtins;
     let     isPath   = v: typeOf v == "path";
     in if   isInt      v then toString v
+    else if isFloat    v then "~${toString v}"
     else if isString   v then ''"${libStr.escape [''"''] v}"''
     else if true  ==   v then "true"
     else if false ==   v then "false"
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix
index d89bcfde4819..853d911cdc81 100644
--- a/lib/tests/misc.nix
+++ b/lib/tests/misc.nix
@@ -369,6 +369,7 @@ runTests {
   testToPretty = {
     expr = mapAttrs (const (generators.toPretty {})) rec {
       int = 42;
+      float = 0.1337;
       bool = true;
       string = ''fno"rd'';
       path = /. + "/foo";
@@ -381,6 +382,7 @@ runTests {
     };
     expected = rec {
       int = "42";
+      float = "~0.133700";
       bool = "true";
       string = ''"fno\"rd"'';
       path = "/foo";