diff options
author | Profpatsch <mail@profpatsch.de> | 2022-03-14 10:14:18 +0100 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2022-03-14 10:21:15 +0100 |
commit | ab03ddc8f441a11644a4ce3d29eb290fa02b11e3 (patch) | |
tree | 70b3a3752412e3caf6ca215f199e384f21b0d477 /lib/tests | |
parent | 31961f641557fb4b9c96250e68f520a768d5e303 (diff) |
lib.generators: add toINIWithGlobalSection
As discussed in https://github.com/NixOS/nixpkgs/pull/118925#issuecomment-821112723, this is the best way of adding global sections to `toINI` without employing heuristics (i.e. checking whether something is an attrset).
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/misc.nix | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lib/tests/misc.nix b/lib/tests/misc.nix index 5fa95828df691..6687b9bebaeeb 100644 --- a/lib/tests/misc.nix +++ b/lib/tests/misc.nix @@ -471,6 +471,66 @@ runTests { ''; }; + testToINIWithGlobalSectionEmpty = { + expr = generators.toINIWithGlobalSection {} { + globalSection = { + }; + sections = { + }; + }; + expected = '' + ''; + }; + + testToINIWithGlobalSectionGlobalEmptyIsTheSameAsToINI = + let + sections = { + "section 1" = { + attribute1 = 5; + x = "Me-se JarJar Binx"; + }; + "foo" = { + "he\\h=he" = "this is okay"; + }; + }; + in { + expr = + generators.toINIWithGlobalSection {} { + globalSection = {}; + sections = sections; + }; + expected = generators.toINI {} sections; + }; + + testToINIWithGlobalSectionFull = { + expr = generators.toINIWithGlobalSection {} { + globalSection = { + foo = "bar"; + test = false; + }; + sections = { + "section 1" = { + attribute1 = 5; + x = "Me-se JarJar Binx"; + }; + "foo" = { + "he\\h=he" = "this is okay"; + }; + }; + }; + expected = '' + foo=bar + test=false + + [foo] + he\h\=he=this is okay + + [section 1] + attribute1=5 + x=Me-se JarJar Binx + ''; + }; + /* right now only invocation check */ testToJSONSimple = let val = { |