2023-03-23 23:26:02 +00:00
|
|
|
import readconf;
|
2023-03-27 12:37:37 +00:00
|
|
|
import std.conv;
|
2023-03-23 23:26:02 +00:00
|
|
|
|
|
|
|
unittest
|
|
|
|
{
|
2023-03-27 12:37:37 +00:00
|
|
|
rc.read("./tests/settings.conf", "old");
|
|
|
|
rc.read("./tests/database.conf", "pgconf");
|
|
|
|
|
|
|
|
assert(rc.cf("old").sn.key("value1") == "text without quotes");
|
2023-03-27 15:32:29 +00:00
|
|
|
assert(rc["old"][""]["value2"] == "Yes!");
|
2023-03-27 12:37:37 +00:00
|
|
|
assert(rc.cf("old").sn.key("value3") == "value in apostrophes");
|
|
|
|
assert(rc.cf("old").sn.key("value4") == "1000");
|
|
|
|
assert(rc.cf("old").sn.key("value5") == "0.000");
|
|
|
|
assert(rc.cf("old").sn.key("value7") == "//path");
|
|
|
|
assert(rc.cf("old").sn.key("value8") == "\"Hey!\"");
|
|
|
|
assert(rc.cf("old").sn("part2").key("value1") == "this value will be in the new section");
|
|
|
|
assert(rc.cf("old").sn("part2").key("value3") == "good value!");
|
|
|
|
assert(rc.cf("old").sn("part3").key("value1") == "-2");
|
|
|
|
assert(rc.cf("old").sn("part3").key("value3") == "100");
|
|
|
|
|
|
|
|
auto pgconf = rc.cf("pgconf").sn("postgres");
|
|
|
|
|
|
|
|
assert(pgconf.key("host") == "//myhost");
|
|
|
|
assert(pgconf.key("port").to!int == 5432);
|
|
|
|
assert(pgconf.key("name") == "mydatabase");
|
|
|
|
assert(pgconf.key("password") == "/&#BD&@MXLE");
|
|
|
|
|
|
|
|
auto pgconf2 = rc.cf("pgconf");
|
|
|
|
|
2023-03-27 15:32:29 +00:00
|
|
|
assert(pgconf2[]["host"] == "//myhost");
|
2023-03-27 12:37:37 +00:00
|
|
|
assert(pgconf2.sn.key("port").to!int == 5432);
|
|
|
|
assert(pgconf2.sn.key("name") == "mydatabase");
|
|
|
|
assert(pgconf2.sn.key("password") == "/&#BD&@MXLE");
|
2023-03-23 23:26:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// void main()
|
|
|
|
// {
|
|
|
|
// import std.stdio;
|
2023-03-26 00:26:31 +00:00
|
|
|
// rc.read("./tests/settings.conf");
|
|
|
|
|
|
|
|
// foreach (key, param; rc.sn.keys())
|
|
|
|
// writefln("%s => %s", key, param);
|
|
|
|
|
|
|
|
// writeln(rc.sn.key("value1"));
|
2023-03-23 23:26:02 +00:00
|
|
|
|
2023-03-26 00:26:31 +00:00
|
|
|
// foreach (key, param; rc.sn("part2").keys())
|
2023-03-23 23:26:02 +00:00
|
|
|
// writefln("%s => %s", key, param);
|
|
|
|
|
2023-03-26 00:26:31 +00:00
|
|
|
// writeln(rc.sn("part2").key("value1"));
|
2023-03-23 23:26:02 +00:00
|
|
|
// }
|