diff options
author | Profpatsch <mail@profpatsch.de> | 2018-03-26 17:31:05 +0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2018-03-29 16:53:06 +0200 |
commit | fa71407f3656b0bf65d40e94a20513d56bcf3c61 (patch) | |
tree | 6983417618af26bb11f5c63f6c7dd6bb240c7b79 /lib/tests | |
parent | a7e45fdd8eddca06c2c5db013fe8f9dc4475e1b5 (diff) |
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.
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/misc.nix | 26 |
1 files changed, 26 insertions, 0 deletions
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 ''; }; |