You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
2.2 KiB
110 lines
2.2 KiB
|
3 weeks ago
|
#include <fmt/core.h>
|
||
|
|
#include <deque>
|
||
|
|
#include <string>
|
||
|
|
#include <fuc2/testing.hpp>
|
||
|
|
#define SOL_ALL_SAFETIES_ON 1
|
||
|
|
#include <sol/sol.hpp>
|
||
|
|
|
||
|
|
using namespace fuc2;
|
||
|
|
|
||
|
|
enum class NodeType {
|
||
|
|
TEXT,
|
||
|
|
H1,
|
||
|
|
IMAGE,
|
||
|
|
UL
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Node {
|
||
|
|
std::unordered_map<std::string, std::string> config;
|
||
|
|
NodeType type = NodeType::TEXT;
|
||
|
|
std::string content = "";
|
||
|
|
|
||
|
|
Node(NodeType type) {}
|
||
|
|
|
||
|
|
void addText(const std::string& text) {
|
||
|
|
content += text;
|
||
|
|
}
|
||
|
|
|
||
|
|
void addConfig(const std::string& key, const std::string& val) {
|
||
|
|
config.try_emplace(key, val);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Slide {
|
||
|
|
std::unordered_map<std::string, std::string> config;
|
||
|
|
std::vector<Node> content;
|
||
|
|
|
||
|
|
void addNode(const Node& n) {
|
||
|
|
content.push_back(n);
|
||
|
|
}
|
||
|
|
|
||
|
|
void addConfig(const std::string& key, const std::string& val) {
|
||
|
|
config.try_emplace(key, val);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Deck {
|
||
|
|
std::unordered_map<std::string, std::string> config;
|
||
|
|
std::vector<Slide> slides;
|
||
|
|
|
||
|
|
void addSlide(const Slide& slide) {
|
||
|
|
slides.push_back(slide);
|
||
|
|
}
|
||
|
|
|
||
|
|
void addConfig(const std::string& key, const std::string& val) {
|
||
|
|
config.try_emplace(key, val);
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
namespace build_self_tests {
|
||
|
|
|
||
|
|
void test_load_slides() {
|
||
|
|
using L = sol::lib;
|
||
|
|
sol::state lua;
|
||
|
|
lua.open_libraries(
|
||
|
|
L::base,
|
||
|
|
L::package,
|
||
|
|
L::coroutine,
|
||
|
|
L::string,
|
||
|
|
L::os,
|
||
|
|
L::math,
|
||
|
|
L::table,
|
||
|
|
L::debug,
|
||
|
|
L::io,
|
||
|
|
L::ffi,
|
||
|
|
L::jit);
|
||
|
|
|
||
|
|
lua.new_enum<NodeType>("NodeType",{
|
||
|
|
{"TEXT", NodeType::TEXT},
|
||
|
|
{"H1", NodeType::H1},
|
||
|
|
{"IMAGE", NodeType::IMAGE},
|
||
|
|
{"UL", NodeType::UL}
|
||
|
|
});
|
||
|
|
|
||
|
|
lua.new_usertype<Node>("Node",
|
||
|
|
sol::constructors<Node(NodeType)>(),
|
||
|
|
"type", &Node::type,
|
||
|
|
"content", &Node::content,
|
||
|
|
"addText", &Node::addText,
|
||
|
|
"addConfig", &Node::addConfig);
|
||
|
|
|
||
|
|
lua.new_usertype<Slide>("Slide",
|
||
|
|
"addConfig", &Slide::addConfig,
|
||
|
|
"addNode", &Slide::addNode);
|
||
|
|
|
||
|
|
lua.new_usertype<Deck>("Deck",
|
||
|
|
"addSlide", &Deck::addSlide,
|
||
|
|
"addConfig", &Deck::addConfig);
|
||
|
|
|
||
|
|
lua.script_file("lua/test.lua");
|
||
|
|
}
|
||
|
|
|
||
|
|
fuc2::Set TESTS{
|
||
|
|
.name="slides",
|
||
|
|
.options={ .fail_fast=false },
|
||
|
|
.tests={
|
||
|
|
TEST(test_load_slides),
|
||
|
|
}
|
||
|
|
};
|
||
|
|
}
|