mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-22 10:40:00 +08:00
Add additional coverage tests.
This commit is contained in:
parent
001dd0a8c3
commit
84d6e6b3dd
@ -38,14 +38,17 @@ add_executable(tests
|
||||
src/ftxui/dom/bold_test.cpp
|
||||
src/ftxui/dom/border_test.cpp
|
||||
src/ftxui/dom/canvas_test.cpp
|
||||
src/ftxui/dom/separator_test.cpp
|
||||
src/ftxui/dom/color_test.cpp
|
||||
src/ftxui/dom/dbox_test.cpp
|
||||
src/ftxui/dom/dim_test.cpp
|
||||
src/ftxui/dom/flexbox_helper_test.cpp
|
||||
src/ftxui/dom/flexbox_test.cpp
|
||||
src/ftxui/dom/gauge_test.cpp
|
||||
src/ftxui/dom/gridbox_test.cpp
|
||||
src/ftxui/dom/hbox_test.cpp
|
||||
src/ftxui/dom/scroll_indicator_test.cpp
|
||||
src/ftxui/dom/separator_test.cpp
|
||||
src/ftxui/dom/spinner_test.cpp
|
||||
src/ftxui/dom/table_test.cpp
|
||||
src/ftxui/dom/text_test.cpp
|
||||
src/ftxui/dom/underlined_test.cpp
|
||||
|
@ -15,8 +15,8 @@ namespace ftxui {
|
||||
|
||||
using Charset = std::array<std::string, 6>; // NOLINT
|
||||
using Charsets = std::array<Charset, 6>; // NOLINT
|
||||
static Charsets simple_border_charset = // NOLINT
|
||||
{
|
||||
// NOLINTNEXTLINE
|
||||
static Charsets simple_border_charset = {
|
||||
Charset{"┌", "┐", "└", "┘", "─", "│"},
|
||||
Charset{"┏", "┓", "┗", "┛", "━", "┃"},
|
||||
Charset{"╔", "╗", "╚", "╝", "═", "║"},
|
||||
|
@ -8,16 +8,17 @@
|
||||
namespace ftxui {
|
||||
|
||||
namespace {
|
||||
int Hash(const std::string s) {
|
||||
int hash = 0;
|
||||
uint32_t Hash(const std::string s) {
|
||||
uint32_t hash = 0;
|
||||
for (auto c : s) {
|
||||
hash += c;
|
||||
hash *= 7;
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
TEST(BorderTest, GoldPoint) {
|
||||
TEST(CanvasTest, GoldPoint) {
|
||||
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||
auto element = canvas([](Canvas& c) { //
|
||||
c.DrawPoint(3, 3, 1);
|
||||
@ -32,10 +33,25 @@ TEST(BorderTest, GoldPoint) {
|
||||
});
|
||||
Screen screen(30, 10);
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(Hash(screen.ToString()), 1069);
|
||||
EXPECT_EQ(Hash(screen.ToString()), -1195891837);
|
||||
}
|
||||
|
||||
TEST(BorderTest, GoldBlock) {
|
||||
TEST(CanvasTest, GoldPointColor) {
|
||||
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||
auto element = canvas([](Canvas& c) { //
|
||||
c.DrawPoint(3, 3, 1, Color::Red);
|
||||
c.DrawPointLine(3, 7, 10, 19,Color::Blue);
|
||||
c.DrawPointCircle(10, 5, 3, Color::Yellow);
|
||||
c.DrawPointCircleFilled(20, 5, 3, Color::White);
|
||||
c.DrawPointEllipse(10, 10, 5, 2, Color::Black);
|
||||
c.DrawPointEllipseFilled(10, 20, 5, 2, Color::Cyan);
|
||||
});
|
||||
Screen screen(30, 10);
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(Hash(screen.ToString()), 1109533029);
|
||||
}
|
||||
|
||||
TEST(CanvasTest, GoldBlock) {
|
||||
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||
auto element = canvas([](Canvas& c) { //
|
||||
c.DrawBlock(3, 3, 1);
|
||||
@ -50,10 +66,26 @@ TEST(BorderTest, GoldBlock) {
|
||||
});
|
||||
Screen screen(30, 10);
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(Hash(screen.ToString()), 472);
|
||||
EXPECT_EQ(Hash(screen.ToString()), 817159424);
|
||||
}
|
||||
|
||||
TEST(BorderTest, GoldText) {
|
||||
TEST(CanvasTest, GoldBlockColor) {
|
||||
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||
auto element = canvas([](Canvas& c) { //
|
||||
c.DrawBlock(3, 3, 1, Color::Red);
|
||||
c.DrawBlockLine(3, 7, 10, 19, Color::Green);
|
||||
c.DrawBlockCircle(10, 5, 3, Color::Blue);
|
||||
c.DrawBlockCircleFilled(20, 5, 3, Color::Yellow);
|
||||
c.DrawBlockEllipse(10, 10, 5, 2, Color::White);
|
||||
c.DrawBlockEllipseFilled(10, 20, 5, 2, Color::Black);
|
||||
});
|
||||
Screen screen(30, 10);
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(Hash(screen.ToString()), 2869205941);
|
||||
}
|
||||
|
||||
|
||||
TEST(CanvasTest, GoldText) {
|
||||
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||
Canvas c(10, 10);
|
||||
c.DrawText(0, 0, "test");
|
||||
@ -62,7 +94,7 @@ TEST(BorderTest, GoldText) {
|
||||
auto element = canvas(c);
|
||||
Screen screen(30, 10);
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(Hash(screen.ToString()), 10447);
|
||||
EXPECT_EQ(Hash(screen.ToString()), 1074960375);
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
40
src/ftxui/dom/dbox_test.cpp
Normal file
40
src/ftxui/dom/dbox_test.cpp
Normal file
@ -0,0 +1,40 @@
|
||||
#include <gtest/gtest-message.h> // for Message
|
||||
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl, TestPartResult
|
||||
#include <algorithm> // for remove
|
||||
#include <string> // for allocator, basic_string, string
|
||||
#include <vector> // for vector
|
||||
|
||||
#include "ftxui/dom/elements.hpp" // for vtext, operator|, Element, flex_grow, flex_shrink, vbox
|
||||
#include "ftxui/dom/node.hpp" // for Render
|
||||
#include "ftxui/screen/color.hpp" // for ftxui
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
TEST(DBoxTest, Basic) {
|
||||
auto root = dbox({
|
||||
hbox({
|
||||
text("test") | border,
|
||||
filler(),
|
||||
}),
|
||||
vbox({
|
||||
text("test") | border,
|
||||
filler(),
|
||||
}),
|
||||
});
|
||||
|
||||
Screen screen(8, 4);
|
||||
Render(screen, root);
|
||||
EXPECT_EQ(screen.ToString(),
|
||||
"╭────┬─╮\r\n"
|
||||
"│test│ │\r\n"
|
||||
"╰────┴─╯\r\n"
|
||||
"╰────╯ ");
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
// Copyright 2020 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
109
src/ftxui/dom/scroll_indicator_test.cpp
Normal file
109
src/ftxui/dom/scroll_indicator_test.cpp
Normal file
@ -0,0 +1,109 @@
|
||||
#include <gtest/gtest-message.h> // for Message
|
||||
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl, TestPartResult
|
||||
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
|
||||
#include <string> // for allocator
|
||||
#include "ftxui/dom/elements.hpp" // for text, flexbox
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
namespace {
|
||||
Element MakeList(int focused_index, int n) {
|
||||
Elements list;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
auto element = text(std::to_string(i));
|
||||
if (i == focused_index) {
|
||||
element |= focus;
|
||||
}
|
||||
list.push_back(element);
|
||||
}
|
||||
return vbox(std::move(list)) | vscroll_indicator | frame | border;
|
||||
}
|
||||
|
||||
std::string Print(int focused_index, int n) {
|
||||
auto element = MakeList(focused_index, n);
|
||||
Screen screen(6, 6);
|
||||
Render(screen, element);
|
||||
return screen.ToString();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST(ScrollIndicator, Basic) {
|
||||
EXPECT_EQ(Print(0, 10),
|
||||
"╭────╮\r\n"
|
||||
"│0 ┃│\r\n"
|
||||
"│1 ┃│\r\n"
|
||||
"│2 │\r\n"
|
||||
"│3 │\r\n"
|
||||
"╰────╯");
|
||||
EXPECT_EQ(Print(1, 10),
|
||||
"╭────╮\r\n"
|
||||
"│0 ┃│\r\n"
|
||||
"│1 ┃│\r\n"
|
||||
"│2 │\r\n"
|
||||
"│3 │\r\n"
|
||||
"╰────╯");
|
||||
EXPECT_EQ(Print(2, 10),
|
||||
"╭────╮\r\n"
|
||||
"│1 ┃│\r\n"
|
||||
"│2 ┃│\r\n"
|
||||
"│3 │\r\n"
|
||||
"│4 │\r\n"
|
||||
"╰────╯");
|
||||
EXPECT_EQ(Print(3, 10),
|
||||
"╭────╮\r\n"
|
||||
"│2 ╻│\r\n"
|
||||
"│3 ┃│\r\n"
|
||||
"│4 ╹│\r\n"
|
||||
"│5 │\r\n"
|
||||
"╰────╯");
|
||||
EXPECT_EQ(Print(4, 10),
|
||||
"╭────╮\r\n"
|
||||
"│3 │\r\n"
|
||||
"│4 ┃│\r\n"
|
||||
"│5 ┃│\r\n"
|
||||
"│6 │\r\n"
|
||||
"╰────╯");
|
||||
EXPECT_EQ(Print(5, 10),
|
||||
"╭────╮\r\n"
|
||||
"│4 │\r\n"
|
||||
"│5 ╻│\r\n"
|
||||
"│6 ┃│\r\n"
|
||||
"│7 ╹│\r\n"
|
||||
"╰────╯");
|
||||
EXPECT_EQ(Print(6, 10),
|
||||
"╭────╮\r\n"
|
||||
"│5 │\r\n"
|
||||
"│6 │\r\n"
|
||||
"│7 ┃│\r\n"
|
||||
"│8 ┃│\r\n"
|
||||
"╰────╯");
|
||||
EXPECT_EQ(Print(7, 10),
|
||||
"╭────╮\r\n"
|
||||
"│6 │\r\n"
|
||||
"│7 │\r\n"
|
||||
"│8 ┃│\r\n"
|
||||
"│9 ┃│\r\n"
|
||||
"╰────╯");
|
||||
EXPECT_EQ(Print(8, 10),
|
||||
"╭────╮\r\n"
|
||||
"│6 │\r\n"
|
||||
"│7 │\r\n"
|
||||
"│8 ┃│\r\n"
|
||||
"│9 ┃│\r\n"
|
||||
"╰────╯");
|
||||
EXPECT_EQ(Print(9, 10),
|
||||
"╭────╮\r\n"
|
||||
"│6 │\r\n"
|
||||
"│7 │\r\n"
|
||||
"│8 ┃│\r\n"
|
||||
"│9 ┃│\r\n"
|
||||
"╰────╯");
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
@ -17,8 +17,8 @@ using ftxui::Screen;
|
||||
|
||||
using Charset = std::array<std::string, 2>; // NOLINT
|
||||
using Charsets = std::array<Charset, 5>; // NOLINT
|
||||
const Charsets charsets = // NOLINT
|
||||
{
|
||||
// NOLINTNEXTLINE
|
||||
const Charsets charsets = {
|
||||
Charset{"│", "─"}, //
|
||||
Charset{"┃", "━"}, //
|
||||
Charset{"║", "═"}, //
|
||||
|
42
src/ftxui/dom/spinner_test.cpp
Normal file
42
src/ftxui/dom/spinner_test.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
#include <gtest/gtest-message.h> // for Message
|
||||
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl, TestPartResult
|
||||
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
|
||||
#include <string> // for allocator
|
||||
#include "ftxui/dom/elements.hpp" // for text, flexbox
|
||||
#include "ftxui/screen/screen.hpp" // for Screen
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
TEST(SpinnerTest, Spinner1) {
|
||||
auto element = spinner(1, 0);
|
||||
Screen screen(4, 1);
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(screen.ToString(), ". ");
|
||||
}
|
||||
|
||||
TEST(SpinnerTest, Spinner2) {
|
||||
auto element = spinner(1, 1);
|
||||
Screen screen(4, 1);
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(screen.ToString(), ".. ");
|
||||
}
|
||||
|
||||
TEST(SpinnerTest, Spinner3) {
|
||||
auto element = spinner(1, 2);
|
||||
Screen screen(4, 1);
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(screen.ToString(), "... ");
|
||||
}
|
||||
|
||||
TEST(SpinnerTest, Spinner4) {
|
||||
auto element = spinner(1, 3);
|
||||
Screen screen(4, 1);
|
||||
Render(screen, element);
|
||||
EXPECT_EQ(screen.ToString(), ". ");
|
||||
}
|
||||
|
||||
} // namespace ftxui
|
||||
|
||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||
// Use of this source code is governed by the MIT license that can be found in
|
||||
// the LICENSE file.
|
Loading…
Reference in New Issue
Block a user