aboutsummaryrefslogtreecommitdiff
path: root/test/conf/main.cpp
blob: e499a4daa20cfeb19cd8cba78b01d629b958d146 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <fstream>
#include <iostream>
#include <string>
#include "configuration.h"
#include <cassert>

int main(int, char**)
{
    std::fstream fs;
    fs.open("smolbote.cfg", std::fstream::in);
    assert(fs.is_open());

    {
    auto value_map = std::make_unique<Configuration, std::initializer_list<std::pair<std::string, conf_value_t>>>({
        { "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<std::string>("test") == "value");
        assert(g.value<std::string>("plugins.path") == "/usr/local/lib/smolbote/plugins");
        assert(g.value<int>("integer-1") == 20);
        assert(g.value<int>("integer-2") == 22);
    }

/*
    {
    const Configuration conf(std::move(value_map));

    assert(conf.value<std::string>("test") == "value");
    assert(conf.value<std::string>("plugins.path") == "/usr/local/lib/smolbote/plugins");
    assert(conf.value<int>("integer-1") == 20);
    assert(conf.value<int>("integer-2") == 22);
    }
*/
    // Configuration is now destroyed


    // This should be a compiler warning
    //const Configuration c(std::move(value_map));
    //assert(c.value<std::string>("test") == "value");

    // This should be a compiler warning and runtime error
    //assert(value_map.value<std::string>("test").value() == "value");

    return 0;
}