diff options
author | benaryorg <binary@benary.org> | 2024-01-25 22:09:23 +0000 |
---|---|---|
committer | benaryorg <binary@benary.org> | 2024-02-12 17:58:48 +0000 |
commit | 8b2d86b982c5d5c6f4c7402546d32b17eb6b07f8 (patch) | |
tree | 69953aec302762d8b48a6c908828aa84d181436d /pkgs/pkgs-lib/tests | |
parent | 3e72e7c01483666a4465abfeefbcd4c668c79865 (diff) |
pkgs.formats: toINIWithGlobalSection wrapper
The new format is based on the existing wrapper and generates an INI file with an unnamed global section at the top as is used by *stunnel* for instance. Technically the INI format is a subset of this however testing, type checking, and API guarantees profit from two separate generators. Co-authored-by: tim-tx <tim-tx@users.noreply.github.com> Signed-off-by: benaryorg <binary@benary.org>
Diffstat (limited to 'pkgs/pkgs-lib/tests')
-rw-r--r-- | pkgs/pkgs-lib/tests/formats.nix | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/pkgs/pkgs-lib/tests/formats.nix b/pkgs/pkgs-lib/tests/formats.nix index 72994803d5844..3243f4058e680 100644 --- a/pkgs/pkgs-lib/tests/formats.nix +++ b/pkgs/pkgs-lib/tests/formats.nix @@ -222,6 +222,101 @@ in runBuildTests { ''; }; + iniWithGlobalNoSections = shouldPass { + format = formats.iniWithGlobalSection {}; + input = {}; + expected = ""; + }; + + iniWithGlobalOnlySections = shouldPass { + format = formats.iniWithGlobalSection {}; + input = { + sections = { + foo = { + bar = "baz"; + }; + }; + }; + expected = '' + [foo] + bar=baz + ''; + }; + + iniWithGlobalOnlyGlobal = shouldPass { + format = formats.iniWithGlobalSection {}; + input = { + globalSection = { + bar = "baz"; + }; + }; + expected = '' + bar=baz + + ''; + }; + + iniWithGlobalWrongSections = shouldFail { + format = formats.iniWithGlobalSection {}; + input = { + foo = {}; + }; + }; + + iniWithGlobalEverything = shouldPass { + format = formats.iniWithGlobalSection {}; + input = { + globalSection = { + bar = true; + }; + sections = { + foo = { + bool = true; + int = 10; + float = 3.141; + str = "string"; + }; + }; + }; + expected = '' + bar=true + + [foo] + bool=true + float=3.141000 + int=10 + str=string + ''; + }; + + iniWithGlobalListToValue = shouldPass { + format = formats.iniWithGlobalSection { listToValue = lib.concatMapStringsSep ", " (lib.generators.mkValueStringDefault {}); }; + input = { + globalSection = { + bar = [ null true "test" 1.2 10 ]; + baz = false; + qux = "qux"; + }; + sections = { + foo = { + bar = [ null true "test" 1.2 10 ]; + baz = false; + qux = "qux"; + }; + }; + }; + expected = '' + bar=null, true, test, 1.200000, 10 + baz=false + qux=qux + + [foo] + bar=null, true, test, 1.200000, 10 + baz=false + qux=qux + ''; + }; + keyValueAtoms = shouldPass { format = formats.keyValue {}; input = { |