Skip to content
Snippets Groups Projects
Commit 038dec8e authored by Jean-Paul Calderone's avatar Jean-Paul Calderone
Browse files

more tests for ini.nix and some fixes too

parent 0cd296f5
No related branches found
No related tags found
1 merge request!1Basic NixOS Private Storage service module
{ pkgs ? import <nixpkgs> { } }:
let lib = pkgs.lib;
in rec {
# Get the .ini-file-appropriate string representation of a simple value.
#
# toINIString "hello" -> "hello"
# toINIString true -> "true"
toINIString = v:
if builtins.isBool v then builtins.toJSON v
else builtins.toString v;
# Map a function over an attrset and concatenate the string results.
#
# concatMapAttrsToList (n: v: "${n} = ${v}\n") { a = "b"; c = "d"; } -> "a = b\nc = d\n"
......@@ -11,7 +19,7 @@ in rec {
#
# oneConfigItemText "foo" "bar" -> "foo = bar\n"
oneConfigItemText = name: value:
"${name} = ${builtins.toString value}\n";
"${name} = ${toINIString value}\n";
# Generate all lines of configuration defining all items in one section.
#
......@@ -25,8 +33,7 @@ in rec {
# oneConfigSectionText "foo" { bar = "baz"; } -> "[foo]\nbar = baz\n"
oneConfigSectionText = name: value: ''
[${name}]
${allConfigItemsText value}
'';
${allConfigItemsText value}'';
# Generate all lines of configuration for all sections, headers
# and items included.
......
let
pkgs = import <nixpkgs> { };
ini = import ../ini.nix { inherit pkgs; };
in
pkgs.lib.runTests
ini:
{ test_empty =
{ name = "test_empty";
expected = "";
{ expected = "";
expr = ini.allConfigSectionsText { };
};
test_one_section =
{ name = "test_one_empty_section";
expected = ''
test_one_empty_section =
{ expected = ''
[foo]
'';
expr = ini.allConfigSectionsText { foo = { }; };
};
test_one_section_one_item =
{ expected = ''
[foo]
bar = baz
'';
expr = ini.allConfigSectionsText { foo = { bar = "baz"; }; };
};
test_one_section_two_items =
{ expected = ''
[foo]
bar = baz
foobar = quux
'';
expr = ini.allConfigSectionsText { foo = { bar = "baz"; foobar = "quux"; }; };
};
test_two_sections =
{ expected = ''
[alpha]
beta = gamma
[foo]
bar = baz
foobar = quux
'';
expr = ini.allConfigSectionsText
{ foo = { bar = "baz"; foobar = "quux"; };
alpha = { beta = "gamma"; };
};
};
test_true =
{ expected = "x = true\n";
expr = ini.oneConfigItemText "x" true;
};
test_false =
{ expected = "x = false\n";
expr = ini.oneConfigItemText "x" false;
};
test_integer =
{ expected = "x = 12345\n";
expr = ini.oneConfigItemText "x" 12345;
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment