Now have more test for the base functionality but need to push render tests and find a way to test the GUI. I've also brought in sol2 for lua integration but not sure what to do with it.

This commit is contained in:
Zed A. Shaw 2024-11-30 10:43:25 -05:00
parent d0d62836e3
commit e86d474c7c
14 changed files with 188 additions and 8 deletions

View file

@ -60,9 +60,6 @@ TEST_CASE("test out ragel parser", "[gui]") {
std::string colors = generate_colors();
std::wstring colors_utf = $converter.from_bytes(colors);
std::cout << colors;
bool good = ansi.parse(colors_utf,
[&](sf::Color color, sf::Color bgcolor){
// ignore color

View file

@ -58,6 +58,8 @@ TEST_CASE("confirm basic collision operations", "[collision]") {
REQUIRE(collider.occupied({12,12}));
REQUIRE(collider.occupied({21,21}));
REQUIRE(!collider.occupied({1,10}));
REQUIRE(collider.get({12,12}) == player);
}

View file

@ -68,6 +68,12 @@ TEST_CASE("lighting test", "[map]") {
map.clear_light_target(light1);
map.clear_light_target(light2);
const auto &lighting = map.lighting();
// confirm light is set at least at and around the two points
REQUIRE(lighting[light1.y][light1.x] == lighting::LEVELS[source1.strength]);
REQUIRE(lighting[light2.y][light2.x] == lighting::LEVELS[source2.strength]);
}
TEST_CASE("camera control", "[map]") {

75
tests/panel.cpp Normal file
View file

@ -0,0 +1,75 @@
#include <catch2/catch_test_macros.hpp>
#include <fmt/core.h>
#include <ftxui/screen/terminal.hpp> // for ColorSupport, Color, Palette16, Palette256, TrueColor
#include <ftxui/dom/elements.hpp> // for hflow, paragraph, separator, hbox, vbox, filler, operator|, border, Element
#include "panel.hpp"
#include "ansi_parser.hpp"
using namespace ftxui;
using namespace fmt;
using std::string;
void test_ansi_parsing(Panel &panel) {
sf::Color default_fg(0,0,0);
sf::Color default_bg(100,100,100);
// this sets the Truecolor so need to do it first
ANSIParser ansi(default_fg, default_bg);
bool good = ansi.parse(panel.to_string(),
[&](sf::Color color, sf::Color bgcolor){
// ignore color
},
[&](wchar_t ch) {
// ignore char
});
REQUIRE(good == true);
}
TEST_CASE("can render a simple text panel", "[panel]") {
ftxui::Terminal::SetColorSupport(ftxui::Terminal::Color::TrueColor);
Panel text_panel(0, 0, 20, 5);
bool show_modal = false;
auto buttons = Container::Horizontal({
Button("OK", [&]{ show_modal = false; }),
Button("CANCEL", [&]{ show_modal = false; }),
});
auto text_box = Renderer([buttons]{
return hbox({
hflow(
vbox(text("I AM TEXT")),
buttons->Render()
)});
});
text_panel.set_renderer(text_box);
text_panel.add(buttons);
text_panel.resize(10,10);
text_panel.render();
test_ansi_parsing(text_panel);
const Screen &screen = text_panel.screen();
REQUIRE(screen.dimx() == 10);
REQUIRE(screen.dimx() == 10);
}
TEST_CASE("can render a simple grid panel", "[panel]") {
Terminal::SetColorSupport(Terminal::Color::TrueColor);
Panel grid_panel(20, 20, 20, 5, true);
auto text_box = Renderer([]{
return hbox({
hflow(vbox(text("I AM TEXT")))});
});
grid_panel.set_renderer(text_box);
grid_panel.resize(10,10);
grid_panel.render();
test_ansi_parsing(grid_panel);
}

38
tests/render.cpp Normal file
View file

@ -0,0 +1,38 @@
#include <catch2/catch_test_macros.hpp>
#include <fmt/core.h>
#include "render.hpp"
#include "panel.hpp"
using namespace ftxui;
using namespace fmt;
using std::string;
void run_renderer(SFMLRender &renderer, Panel &panel) {
panel.render();
renderer.display();
REQUIRE(renderer.is_open() == true);
renderer.clear();
renderer.draw(panel);
}
TEST_CASE("can render a text or grid panel", "[render]") {
SFMLRender renderer;
Panel panel(0, 0, 20, 5);
Panel grid(200, 200, 20, 5, true);
auto text_box = Renderer([]{
return hbox({
hflow(
vbox(text("I AM TEXT"))
)});
});
panel.set_renderer(text_box);
grid.set_renderer(text_box);
run_renderer(renderer, panel);
run_renderer(renderer, grid);
renderer.close();
}

View file

@ -66,6 +66,7 @@ TEST_CASE("basic save a world", "[save]") {
world.set<Motion>(player.entity, {0, 0});
world.set<Combat>(player.entity, {100, 10});
world.set<Tile>(player.entity, {"@"});
world.set<Inventory>(player.entity, {102});
save::to_file("./savetest.world", world, map);
@ -95,4 +96,7 @@ TEST_CASE("basic save a world", "[save]") {
REQUIRE(map.height() == in_map.height());
REQUIRE(map.$walls == in_map.$walls);
REQUIRE(map.$input_map == in_map.$input_map);
Inventory &inv = world.get<Inventory>(player.entity);
REQUIRE(inv.gold == 102);
}