Now off catch2 and on my own testing fuc2.
This commit is contained in:
parent
4f3fa59793
commit
1d11c8b162
10 changed files with 177 additions and 98 deletions
107
tests/lel.cpp
107
tests/lel.cpp
|
|
@ -1,61 +1,72 @@
|
|||
#include "guecs/lel.hpp"
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
#include <fmt/core.h>
|
||||
#include <string>
|
||||
#include <fuc2/testing.hpp>
|
||||
|
||||
TEST_CASE("test basic ops", "[lel]") {
|
||||
lel::Parser parser(0, 0, 500, 500);
|
||||
using namespace fuc2;
|
||||
|
||||
bool good = parser.parse(
|
||||
"[ label_1 | label3 | test1]"
|
||||
"[ *(300,300)text1 | %(150)people | ^test2]"
|
||||
"[ >label2 | _ | .test3]"
|
||||
"[ =message | buttons | test4]");
|
||||
namespace lel_tests {
|
||||
void test_basic_ops() {
|
||||
lel::Parser parser(0, 0, 500, 500);
|
||||
|
||||
REQUIRE(good);
|
||||
bool good = parser.parse(
|
||||
"[ label_1 | label3 | test1]"
|
||||
"[ *(300,300)text1 | %(150)people | ^test2]"
|
||||
"[ >label2 | _ | .test3]"
|
||||
"[ =message | buttons | test4]");
|
||||
|
||||
for(size_t rowcount = 0; rowcount < parser.grid.size(); rowcount++) {
|
||||
auto& row = parser.grid[rowcount];
|
||||
CHECK(good);
|
||||
|
||||
for(size_t colcount = 0; colcount < row.size(); colcount++) {
|
||||
auto &name = row[colcount];
|
||||
if(name == "_") {
|
||||
REQUIRE(!parser.cells.contains(name));
|
||||
} else if(name == "_MAIN") {
|
||||
// it's the main cell which covers the whole area
|
||||
auto &cell = parser.cells.at(name);
|
||||
REQUIRE(cell.row == 0);
|
||||
REQUIRE(cell.col == 0);
|
||||
REQUIRE(cell.x == parser.grid_x);
|
||||
REQUIRE(cell.y == parser.grid_y);
|
||||
REQUIRE(cell.w == parser.grid_w);
|
||||
REQUIRE(cell.h == parser.grid_h);
|
||||
} else {
|
||||
auto &cell = parser.cells.at(name);
|
||||
REQUIRE(cell.row == int(rowcount));
|
||||
REQUIRE(cell.col == int(colcount));
|
||||
for(size_t rowcount = 0; rowcount < parser.grid.size(); rowcount++) {
|
||||
auto& row = parser.grid[rowcount];
|
||||
|
||||
for(size_t colcount = 0; colcount < row.size(); colcount++) {
|
||||
auto &name = row[colcount];
|
||||
if(name == "_") {
|
||||
CHECK(!parser.cells.contains(name));
|
||||
} else if(name == "_MAIN") {
|
||||
// it's the main cell which covers the whole area
|
||||
auto &cell = parser.cells.at(name);
|
||||
CHECK(cell.row == 0);
|
||||
CHECK(cell.col == 0);
|
||||
CHECK(cell.x == parser.grid_x);
|
||||
CHECK(cell.y == parser.grid_y);
|
||||
CHECK(cell.w == parser.grid_w);
|
||||
CHECK(cell.h == parser.grid_h);
|
||||
} else {
|
||||
auto &cell = parser.cells.at(name);
|
||||
CHECK(cell.row == int(rowcount));
|
||||
CHECK(cell.col == int(colcount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CHECK(parser.cells.size() == 11);
|
||||
CHECK(parser.cells.at("label2").right == true);
|
||||
CHECK(parser.cells.at("text1").expand == true);
|
||||
CHECK(parser.cells.at("text1").w == 300);
|
||||
CHECK(parser.cells.at("text1").h == 300);
|
||||
CHECK(parser.cells.at("people").expand == false);
|
||||
CHECK(parser.cells.at("message").expand == false);
|
||||
CHECK(parser.cells.at("message").center == true);
|
||||
|
||||
for(auto& [name, cell] : parser.cells) {
|
||||
CHECK(cell.w > 0);
|
||||
CHECK(cell.h > 0);
|
||||
}
|
||||
|
||||
auto hit = parser.hit(10, 10);
|
||||
CHECK(*hit == "label_1");
|
||||
|
||||
auto nohit = parser.hit(1000, 1000);
|
||||
CHECK(!nohit);
|
||||
CHECK(nohit == std::nullopt);
|
||||
}
|
||||
|
||||
REQUIRE(parser.cells.size() == 11);
|
||||
REQUIRE(parser.cells.at("label2").right == true);
|
||||
REQUIRE(parser.cells.at("text1").expand == true);
|
||||
REQUIRE(parser.cells.at("text1").w == 300);
|
||||
REQUIRE(parser.cells.at("text1").h == 300);
|
||||
REQUIRE(parser.cells.at("people").expand == false);
|
||||
REQUIRE(parser.cells.at("message").expand == false);
|
||||
REQUIRE(parser.cells.at("message").center == true);
|
||||
|
||||
for(auto& [name, cell] : parser.cells) {
|
||||
REQUIRE(cell.w > 0);
|
||||
REQUIRE(cell.h > 0);
|
||||
}
|
||||
|
||||
auto hit = parser.hit(10, 10);
|
||||
REQUIRE(*hit == "label_1");
|
||||
|
||||
auto nohit = parser.hit(1000, 1000);
|
||||
REQUIRE(!nohit);
|
||||
REQUIRE(nohit == std::nullopt);
|
||||
fuc2::Set TESTS{
|
||||
.name="lel parser tests",
|
||||
.tests={
|
||||
{"test_basic_ops", test_basic_ops},
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue