Basic config system from a json file but it's got serious issues. Can't copy construct it because of the variable blocking copying, and it can't even be put into the dinkyecs in any way.
This commit is contained in:
parent
24b1e4a500
commit
0ba789697a
7 changed files with 93 additions and 5 deletions
|
@ -59,10 +59,6 @@ TEST_CASE("test out ragel parser", "[gui]") {
|
|||
|
||||
bool good = parser.parse(colors, [&](sf::Color bgcolor, sf::Color color, wchar_t ch) {
|
||||
bool correct_char = ch == '#' || ch == ' ' || ch == '\n' || ch == '\r';
|
||||
// println("FG: {},{},{},{}; BG: {},{},{},{}; ch: {}",
|
||||
// color.r, color.g, color.b, color.a,
|
||||
// bgcolor.r, bgcolor.g, bgcolor.b, bgcolor.a,
|
||||
// int(ch));
|
||||
REQUIRE(correct_char);
|
||||
});
|
||||
|
||||
|
|
43
tests/config.cpp
Normal file
43
tests/config.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
#include "config.hpp"
|
||||
#include <any>
|
||||
#include "dinkyecs.hpp"
|
||||
|
||||
using namespace fmt;
|
||||
using std::string;
|
||||
|
||||
TEST_CASE("basic configuration system", "[config]") {
|
||||
Config config("./tests/config.json");
|
||||
|
||||
auto not_found = config["types"]["NOTFOUND"];
|
||||
REQUIRE(not_found == nullptr);
|
||||
|
||||
auto test_string = config["types"]["STRING"];
|
||||
REQUIRE(test_string == L"\u2849█Ω♣");
|
||||
|
||||
std::wstring test_wstring = config.wstring("types", "STRING");
|
||||
REQUIRE(test_wstring == L"\u2849█Ω♣");
|
||||
|
||||
wchar_t chr0 = test_wstring[0];
|
||||
REQUIRE(chr0 == L'\u2849');
|
||||
|
||||
auto test_num = config["types"]["NUMBER"];
|
||||
REQUIRE(test_num == 1234);
|
||||
|
||||
auto test_float = config["types"]["FLOAT"];
|
||||
REQUIRE(test_num >= 0.1233f);
|
||||
|
||||
auto test_obj = config["types"]["OBJECT"];
|
||||
REQUIRE(test_obj["name"] == "Zed");
|
||||
}
|
||||
|
||||
void test_func(Config &ref) {
|
||||
REQUIRE(ref["types"]["OBJECT"]["name"] == "Zed");
|
||||
}
|
||||
|
||||
TEST_CASE("store config in any", "[config]") {
|
||||
Config config("./tests/config.json");
|
||||
test_func(config);
|
||||
}
|
10
tests/config.json
Normal file
10
tests/config.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"types": {
|
||||
"NUMBER": 1234,
|
||||
"STRING": "\u2849█Ω♣",
|
||||
"FLOAT": 0.1234,
|
||||
"OBJECT": {
|
||||
"name": "Zed"
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue