lib: add ini configuration generator
Many configurations are INI-style files. Attribute sets can be mapped rather painlessly to the INI format. This adds a function toINI inside a new generators library section. Also, unit tests for the default values are provided.
This commit is contained in:
@@ -130,4 +130,55 @@ runTests {
|
||||
expected = false;
|
||||
};
|
||||
|
||||
|
||||
/* Generator tests */
|
||||
# these tests assume attributes are converted to lists
|
||||
# in alphabetical order
|
||||
|
||||
testToINIEmpty = {
|
||||
expr = generators.toINI {} {};
|
||||
expected = "";
|
||||
};
|
||||
|
||||
testToINIEmptySection = {
|
||||
expr = generators.toINI {} { foo = {}; bar = {}; };
|
||||
expected = ''
|
||||
[bar]
|
||||
|
||||
[foo]
|
||||
'';
|
||||
};
|
||||
|
||||
testToINIDefaultEscapes = {
|
||||
expr = generators.toINI {} {
|
||||
"no [ and ] allowed unescaped" = {
|
||||
"and also no = in keys" = 42;
|
||||
};
|
||||
};
|
||||
expected = ''
|
||||
[no \[ and \] allowed unescaped]
|
||||
and also no \= in keys=42
|
||||
'';
|
||||
};
|
||||
|
||||
testToINIDefaultFull = {
|
||||
expr = generators.toINI {} {
|
||||
"section 1" = {
|
||||
attribute1 = 5;
|
||||
x = "Me-se JarJar Binx";
|
||||
};
|
||||
"foo[]" = {
|
||||
"he\\h=he" = "this is okay";
|
||||
};
|
||||
};
|
||||
expected = ''
|
||||
[foo\[\]]
|
||||
he\h\=he=this is okay
|
||||
|
||||
[section 1]
|
||||
attribute1=5
|
||||
x=Me-se JarJar Binx
|
||||
'';
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user