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:
parent
d0d62836e3
commit
e86d474c7c
14 changed files with 188 additions and 8 deletions
75
tests/panel.cpp
Normal file
75
tests/panel.cpp
Normal 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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue