2022-04-27 00:00:05 +08:00
|
|
|
#include <gtest/gtest-message.h> // for Message
|
|
|
|
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl, TestPartResult
|
2022-04-28 16:43:31 +08:00
|
|
|
#include <stdint.h> // for uint32_t
|
|
|
|
#include <string> // for allocator, string
|
|
|
|
|
|
|
|
#include "ftxui/dom/canvas.hpp" // for Canvas
|
|
|
|
#include "ftxui/dom/elements.hpp" // for canvas
|
|
|
|
#include "ftxui/dom/node.hpp" // for Render
|
|
|
|
#include "ftxui/screen/color.hpp" // for Color, Color::Black, Color::Blue, Color::Red, Color::White, Color::Yellow, Color::Cyan, Color::Green
|
|
|
|
#include "ftxui/screen/screen.hpp" // for Screen
|
|
|
|
#include "ftxui/screen/terminal.hpp" // for SetColorSupport, Color, TrueColor
|
|
|
|
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
|
2022-04-27 00:00:05 +08:00
|
|
|
|
|
|
|
namespace ftxui {
|
|
|
|
|
|
|
|
namespace {
|
2022-04-27 20:00:46 +08:00
|
|
|
uint32_t Hash(const std::string s) {
|
|
|
|
uint32_t hash = 0;
|
2022-04-27 00:00:05 +08:00
|
|
|
for (auto c : s) {
|
|
|
|
hash += c;
|
2022-04-27 20:00:46 +08:00
|
|
|
hash *= 7;
|
2022-04-27 00:00:05 +08:00
|
|
|
}
|
|
|
|
return hash;
|
|
|
|
}
|
2022-04-28 00:57:48 +08:00
|
|
|
} // namespace
|
2022-04-27 00:00:05 +08:00
|
|
|
|
2022-04-27 20:00:46 +08:00
|
|
|
TEST(CanvasTest, GoldPoint) {
|
2022-04-27 00:00:05 +08:00
|
|
|
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
|
|
|
auto element = canvas([](Canvas& c) { //
|
2022-04-27 17:11:32 +08:00
|
|
|
c.DrawPoint(3, 3, 1);
|
2022-04-27 00:00:05 +08:00
|
|
|
c.DrawPointToggle(2, 8);
|
2022-04-27 17:11:32 +08:00
|
|
|
c.DrawPointToggle(2, 8);
|
|
|
|
c.DrawPointToggle(2, 8);
|
|
|
|
c.DrawPointLine(3, 7, 10, 19);
|
|
|
|
c.DrawPointCircle(10, 5, 3);
|
|
|
|
c.DrawPointCircleFilled(20, 5, 3);
|
|
|
|
c.DrawPointEllipse(10, 10, 5, 2);
|
|
|
|
c.DrawPointEllipseFilled(10, 20, 5, 2);
|
2022-04-27 00:00:05 +08:00
|
|
|
});
|
|
|
|
Screen screen(30, 10);
|
|
|
|
Render(screen, element);
|
2022-04-27 20:00:46 +08:00
|
|
|
EXPECT_EQ(Hash(screen.ToString()), -1195891837);
|
2022-04-27 00:00:05 +08:00
|
|
|
}
|
|
|
|
|
2022-04-27 20:00:46 +08:00
|
|
|
TEST(CanvasTest, GoldPointColor) {
|
|
|
|
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
|
|
|
auto element = canvas([](Canvas& c) { //
|
|
|
|
c.DrawPoint(3, 3, 1, Color::Red);
|
2022-04-28 00:57:48 +08:00
|
|
|
c.DrawPointLine(3, 7, 10, 19, Color::Blue);
|
2022-04-27 20:00:46 +08:00
|
|
|
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) {
|
2022-04-27 00:00:05 +08:00
|
|
|
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
|
|
|
auto element = canvas([](Canvas& c) { //
|
2022-04-27 17:11:32 +08:00
|
|
|
c.DrawBlock(3, 3, 1);
|
|
|
|
c.DrawBlockToggle(2, 8);
|
2022-04-27 00:00:05 +08:00
|
|
|
c.DrawBlockToggle(2, 8);
|
2022-04-27 17:11:32 +08:00
|
|
|
c.DrawBlockToggle(2, 8);
|
|
|
|
c.DrawBlockLine(3, 7, 10, 19);
|
|
|
|
c.DrawBlockCircle(10, 5, 3);
|
|
|
|
c.DrawBlockCircleFilled(20, 5, 3);
|
|
|
|
c.DrawBlockEllipse(10, 10, 5, 2);
|
|
|
|
c.DrawBlockEllipseFilled(10, 20, 5, 2);
|
2022-04-27 00:00:05 +08:00
|
|
|
});
|
|
|
|
Screen screen(30, 10);
|
|
|
|
Render(screen, element);
|
2022-04-27 20:00:46 +08:00
|
|
|
EXPECT_EQ(Hash(screen.ToString()), 817159424);
|
2022-04-27 17:11:32 +08:00
|
|
|
}
|
|
|
|
|
2022-04-27 20:00:46 +08:00
|
|
|
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) {
|
2022-04-27 17:11:32 +08:00
|
|
|
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
|
|
|
Canvas c(10, 10);
|
|
|
|
c.DrawText(0, 0, "test");
|
|
|
|
c.DrawText(0, 5, "test");
|
|
|
|
c.DrawText(0, 10, "test");
|
|
|
|
auto element = canvas(c);
|
|
|
|
Screen screen(30, 10);
|
|
|
|
Render(screen, element);
|
2022-04-27 20:00:46 +08:00
|
|
|
EXPECT_EQ(Hash(screen.ToString()), 1074960375);
|
2022-04-27 00:00:05 +08:00
|
|
|
}
|
|
|
|
|
2022-04-28 00:57:48 +08:00
|
|
|
} // namespace ftxui
|
2022-04-27 00:00:05 +08:00
|
|
|
|
|
|
|
// 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.
|