From fa71407f3656b0bf65d40e94a20513d56bcf3c61 Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Mon, 26 Mar 2018 17:31:05 +0200 Subject: lib/generators: introduce a sane default for `mkValueString` So far, `mkValueString` defaulted to `toString`, which is a bad match for most configuration file formats, especially because how booleans are formatted. This also improves error messages for unsupported types. Add a test to codify the formatting. --- lib/tests/misc.nix | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'lib/tests') diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index e10aea48e48e..5f19dd63f2d8 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -207,6 +207,29 @@ runTests { expected = ''f\:oo:bar''; }; + testMkValueString = { + expr = let + vals = { + int = 42; + string = ''fo"o''; + bool = true; + bool2 = false; + null = null; + # float = 42.23; # floats are strange + }; + in mapAttrs + (const (generators.mkValueStringDefault {})) + vals; + expected = { + int = "42"; + string = ''fo"o''; + bool = "true"; + bool2 = "false"; + null = "null"; + # float = "42.23" true false [ "bar" ] ]''; + }; + }; + testToKeyValue = { expr = generators.toKeyValue {} { key = "value"; @@ -249,6 +272,8 @@ runTests { "section 1" = { attribute1 = 5; x = "Me-se JarJar Binx"; + # booleans are converted verbatim by default + boolean = false; }; "foo[]" = { "he\\h=he" = "this is okay"; @@ -260,6 +285,7 @@ runTests { [section 1] attribute1=5 + boolean=false x=Me-se JarJar Binx ''; }; -- cgit 1.4.1