From f3a4607d6a722a862af0eb9747a15dcdf624b6fb Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Sun, 3 Nov 2019 00:18:10 +0200 Subject: Drop boost dependency - wrote not-invented-here config file parser and conf class - spent obscene amount of time plugging in said conf class --- test/conf/main.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++ test/conf/meson.build | 6 ++++++ test/conf/smolbote.cfg | 5 +++++ 3 files changed, 65 insertions(+) create mode 100644 test/conf/main.cpp create mode 100644 test/conf/meson.build create mode 100644 test/conf/smolbote.cfg (limited to 'test/conf') diff --git a/test/conf/main.cpp b/test/conf/main.cpp new file mode 100644 index 0000000..e499a4d --- /dev/null +++ b/test/conf/main.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include "configuration.h" +#include + +int main(int, char**) +{ + std::fstream fs; + fs.open("smolbote.cfg", std::fstream::in); + assert(fs.is_open()); + + { + auto value_map = std::make_unique>>({ + { "test", std::string("unknown") }, + { "integer-1", 20 }, + { "integer-2", 30 } + }); + value_map->read(fs); + + Configuration::move_global(std::move(value_map)); + fs.close(); + } + + { + Configuration g; + assert(g.value("test") == "value"); + assert(g.value("plugins.path") == "/usr/local/lib/smolbote/plugins"); + assert(g.value("integer-1") == 20); + assert(g.value("integer-2") == 22); + } + +/* + { + const Configuration conf(std::move(value_map)); + + assert(conf.value("test") == "value"); + assert(conf.value("plugins.path") == "/usr/local/lib/smolbote/plugins"); + assert(conf.value("integer-1") == 20); + assert(conf.value("integer-2") == 22); + } +*/ + // Configuration is now destroyed + + + // This should be a compiler warning + //const Configuration c(std::move(value_map)); + //assert(c.value("test") == "value"); + + // This should be a compiler warning and runtime error + //assert(value_map.value("test").value() == "value"); + + return 0; +} diff --git a/test/conf/meson.build b/test/conf/meson.build new file mode 100644 index 0000000..de67db7 --- /dev/null +++ b/test/conf/meson.build @@ -0,0 +1,6 @@ +e = executable('conf_test', + dependencies: [dep_qt5, dep_configuration], + sources: 'main.cpp' +) + +test('conf_test', e, workdir : meson.source_root()/'test/conf') diff --git a/test/conf/smolbote.cfg b/test/conf/smolbote.cfg new file mode 100644 index 0000000..25467ef --- /dev/null +++ b/test/conf/smolbote.cfg @@ -0,0 +1,5 @@ +# this is a comment +test = value +plugins.path = /usr/local/lib/smolbote/plugins + +integer-2 = 22 -- cgit v1.2.1