mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-25 20:27:31 +08:00
Add coverage for colors (extended) (#385)
This commit is contained in:
parent
04b36df567
commit
06ed8567b8
4
.github/workflows/build.yaml
vendored
4
.github/workflows/build.yaml
vendored
@ -77,7 +77,7 @@ jobs:
|
|||||||
if: runner.os != 'Windows'
|
if: runner.os != 'Windows'
|
||||||
working-directory: ./build
|
working-directory: ./build
|
||||||
run: >
|
run: >
|
||||||
ctest -C Debug;
|
ctest -C Debug --rerun-failed --output-on-failure;
|
||||||
gcovr
|
gcovr
|
||||||
-j ${{env.nproc}}
|
-j ${{env.nproc}}
|
||||||
--delete
|
--delete
|
||||||
@ -99,7 +99,7 @@ jobs:
|
|||||||
--export_type cobertura:coverage.xml
|
--export_type cobertura:coverage.xml
|
||||||
--cover_children
|
--cover_children
|
||||||
--
|
--
|
||||||
ctest -C Debug
|
ctest -C Debug --rerun-failed --output-on-failure;
|
||||||
|
|
||||||
- name: Publish to codecov
|
- name: Publish to codecov
|
||||||
uses: codecov/codecov-action@v2
|
uses: codecov/codecov-action@v2
|
||||||
|
@ -35,6 +35,7 @@ add_executable(tests
|
|||||||
src/ftxui/dom/blink_test.cpp
|
src/ftxui/dom/blink_test.cpp
|
||||||
src/ftxui/dom/bold_test.cpp
|
src/ftxui/dom/bold_test.cpp
|
||||||
src/ftxui/dom/border_test.cpp
|
src/ftxui/dom/border_test.cpp
|
||||||
|
src/ftxui/dom/canvas_test.cpp
|
||||||
src/ftxui/dom/separator_test.cpp
|
src/ftxui/dom/separator_test.cpp
|
||||||
src/ftxui/dom/color_test.cpp
|
src/ftxui/dom/color_test.cpp
|
||||||
src/ftxui/dom/dim_test.cpp
|
src/ftxui/dom/dim_test.cpp
|
||||||
|
@ -89,6 +89,16 @@ TEST(BorderTest, WithPixel) {
|
|||||||
"ooooo");
|
"ooooo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(BorderTest, Window) {
|
||||||
|
auto element = window(text("title"), text("content"));
|
||||||
|
Screen screen(10, 3);
|
||||||
|
Render(screen, element);
|
||||||
|
EXPECT_EQ(screen.ToString(),
|
||||||
|
"╭title───╮\r\n"
|
||||||
|
"│content │\r\n"
|
||||||
|
"╰────────╯");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
|
|
||||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||||
|
56
src/ftxui/dom/canvas_test.cpp
Normal file
56
src/ftxui/dom/canvas_test.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#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 {
|
||||||
|
int Hash(const std::string s) {
|
||||||
|
int hash = 0;
|
||||||
|
for (auto c : s) {
|
||||||
|
hash += c;
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BorderTest, GoldPoint) {
|
||||||
|
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||||
|
auto element = canvas([](Canvas& c) { //
|
||||||
|
c.DrawPoint(3, 3, 1, Color::Red);
|
||||||
|
c.DrawPointToggle(2, 8);
|
||||||
|
c.DrawPointLine(3, 7, 10, 19, Color::Blue);
|
||||||
|
c.DrawPointCircle(10, 5, 3, Color::Yellow);
|
||||||
|
c.DrawPointCircleFilled(20, 5, 3, Color::Green);
|
||||||
|
c.DrawPointEllipse(10, 10, 5, 2, Color::Blue);
|
||||||
|
c.DrawPointEllipseFilled(10, 20, 5, 2, Color::DarkGreen);
|
||||||
|
});
|
||||||
|
Screen screen(30, 10);
|
||||||
|
Render(screen, element);
|
||||||
|
EXPECT_EQ(Hash(screen.ToString()), 17651);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(BorderTest, GoldBlock) {
|
||||||
|
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||||
|
auto element = canvas([](Canvas& c) { //
|
||||||
|
c.DrawBlock(3, 3, 1, Color::Red);
|
||||||
|
c.DrawBlockToggle(2, 8);
|
||||||
|
c.DrawBlockLine(3, 7, 10, 19, Color::Blue);
|
||||||
|
c.DrawBlockCircle(10, 5, 3, Color::Yellow);
|
||||||
|
c.DrawBlockCircleFilled(20, 5, 3, Color::Green);
|
||||||
|
c.DrawBlockEllipse(10, 10, 5, 2, Color::Blue);
|
||||||
|
c.DrawBlockEllipseFilled(10, 20, 5, 2, Color::DarkGreen);
|
||||||
|
});
|
||||||
|
Screen screen(30, 10);
|
||||||
|
Render(screen, element);
|
||||||
|
EXPECT_EQ(Hash(screen.ToString()), 14383);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // 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.
|
@ -170,7 +170,8 @@ Color Color::HSV(uint8_t h, uint8_t s, uint8_t v) {
|
|||||||
|
|
||||||
// static
|
// static
|
||||||
Color Color::Interpolate(float t, const Color& a, const Color& b) {
|
Color Color::Interpolate(float t, const Color& a, const Color& b) {
|
||||||
if (a.type_ == ColorType::Palette1) {
|
if (a.type_ == ColorType::Palette1 || //
|
||||||
|
b.type_ == ColorType::Palette1) {
|
||||||
if (t < 0.5F) { // NOLINT
|
if (t < 0.5F) { // NOLINT
|
||||||
return a;
|
return a;
|
||||||
} else {
|
} else {
|
||||||
@ -178,14 +179,6 @@ Color Color::Interpolate(float t, const Color& a, const Color& b) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (b.type_ == ColorType::Palette1) {
|
|
||||||
if (t > 0.5F) { // NOLINT
|
|
||||||
return a;
|
|
||||||
} else {
|
|
||||||
return b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
auto get_color = [](const Color& color, //
|
auto get_color = [](const Color& color, //
|
||||||
uint8_t* red, uint8_t* green, uint8_t* blue) {
|
uint8_t* red, uint8_t* green, uint8_t* blue) {
|
||||||
switch (color.type_) {
|
switch (color.type_) {
|
||||||
|
@ -40,6 +40,48 @@ TEST(ColorTest, FallbackTo16) {
|
|||||||
EXPECT_EQ(Color::RGB(1,2,3).Print(false), "30");
|
EXPECT_EQ(Color::RGB(1,2,3).Print(false), "30");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(ColorTest, Litterals) {
|
||||||
|
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||||
|
using namespace ftxui::literals;
|
||||||
|
EXPECT_EQ(Color(0xABCDEF_rgb).Print(false), "38;2;171;205;239");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ColorTest, Interpolate) {
|
||||||
|
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||||
|
|
||||||
|
EXPECT_EQ(Color::Interpolate(0.3f, Color(), Color()).Print(false), "39");
|
||||||
|
EXPECT_EQ(Color::Interpolate(0.3f, Color::Red, Color()).Print(false), "31");
|
||||||
|
EXPECT_EQ(Color::Interpolate(0.7f, Color::Red, Color()).Print(false), "39");
|
||||||
|
EXPECT_EQ(Color::Interpolate(0.3f, Color(), Color::Red).Print(false), "39");
|
||||||
|
EXPECT_EQ(Color::Interpolate(0.7f, Color(), Color::Red).Print(false), "31");
|
||||||
|
|
||||||
|
EXPECT_EQ(Color::Interpolate(0.3f, //
|
||||||
|
Color::RGB(1, 2, 3), //
|
||||||
|
Color::RGB(244, 244, 123)) //
|
||||||
|
.Print(false),
|
||||||
|
"38;2;73;74;39");
|
||||||
|
EXPECT_EQ(Color::Interpolate(0.7f, //
|
||||||
|
Color::RGB(1, 2, 3), //
|
||||||
|
Color::RGB(244, 244, 123)) //
|
||||||
|
.Print(false),
|
||||||
|
"38;2;171;171;87");
|
||||||
|
EXPECT_EQ(Color::Interpolate(0.7f, //
|
||||||
|
Color(Color::Red), //
|
||||||
|
Color::RGB(244, 244, 123)) //
|
||||||
|
.Print(false),
|
||||||
|
"38;2;209;170;86");
|
||||||
|
EXPECT_EQ(Color::Interpolate(0.7f, //
|
||||||
|
Color::RGB(244, 244, 123), //
|
||||||
|
Color(Color::Plum1)) //
|
||||||
|
.Print(false),
|
||||||
|
"38;2;251;195;215");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(ColorTest, HSV) {
|
||||||
|
Terminal::SetColorSupport(Terminal::Color::TrueColor);
|
||||||
|
EXPECT_EQ(Color::HSV(0, 255, 255).Print(false), "38;2;255;0;0");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ftxui
|
} // namespace ftxui
|
||||||
|
|
||||||
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
// Copyright 2022 Arthur Sonzogni. All rights reserved.
|
||||||
|
Loading…
Reference in New Issue
Block a user