forked from skystrife/cpptoml
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
82 lines (72 loc) · 2.11 KB
/
test.cpp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#include "tomlpp/orm.hpp"
#include <cstdlib>
#include <filesystem>
using namespace std;
namespace fs = std::filesystem;
#define TOML_D(...) __VA_ARGS__, #__VA_ARGS__
struct dep : public toml::orm::table {
template<typename Define>
void parse(Define& defn) {
name = defn.name();
defn.if_value(TOML_D(version))
.element(TOML_D(level), 0)
.element(TOML_D(on), false)
.remains(remains);
}
std::string name;
opt<int> level;
string version;
opt<bool> on;
opt<nested<string>> remains;
};
struct deps : public toml::orm::table {
template<typename Define>
void parse(Define& d) {
d.for_each([this](auto p) {
dep table;
list = list ? std::move(list) : arr<dep>(); // require init
auto ptr = toml::orm::table_or_value(p.second, table.level);
auto ac = toml::orm::access(ptr, p.first);
table.parse(ac);
list->emplace_back(std::move(table));
});
}
opt<arr<dep>> list;
};
struct tg : public toml::orm::table {
template<typename Define>
void parse(Define& defn) {
defn.element(TOML_D(name))
.element(TOML_D(level), 10);
type = defn.name();
}
string name;
string type;
opt<int> level;
};
struct config: public toml::orm::table {
template<typename Define>
void parse(Define& defn) {
opt<tg> lib;
defn.element(TOML_D(name))
.element(TOML_D(nums))
.element(tgs, "bin")
.element(TOML_D(lib))
.element(TOML_D(tt), "ss")
.element(TOML_D(deps))
.no_remains();
if(lib) {tgs->push_back(lib.value());}
}
string name;
opt<std::list<dep>> deps;
opt<arr<int64_t>> nums;
opt<arr<tg>> tgs;
opt<string> tt;
};
TEST_CASE("Get env test", "[test env]") {
auto conf = std::make_optional<config>();
auto path = fs::current_path();
REQUIRE((path/"../test/test.toml").lexically_normal() == "/Users/nieel/dev/cppm/libs/tomlpp/test/test.toml");
}