Coverage decorator (#384)

Add code coverage for colors and decorators.
This commit is contained in:
Arthur Sonzogni
2022-04-26 17:04:34 +02:00
committed by GitHub
parent 764c24ef40
commit 04b36df567
14 changed files with 410 additions and 12 deletions

View File

@@ -0,0 +1,21 @@
#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(BlinkTest, Basic) {
auto element = text("text") | blink;
Screen screen(5, 1);
Render(screen, element);
EXPECT_TRUE(screen.PixelAt(0,0).blink);
}
} // 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.

View File

@@ -0,0 +1,21 @@
#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(BoldTest, Basic) {
auto element = text("text") | bold;
Screen screen(5, 1);
Render(screen, element);
EXPECT_TRUE(screen.PixelAt(0,0).bold);
}
} // 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.

View File

@@ -0,0 +1,96 @@
#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(BorderTest, Default) {
auto element = text("text") | border;
Screen screen(5, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"╭───╮\r\n"
"│tex│\r\n"
"╰───╯");
}
TEST(BorderTest, Light) {
auto element = text("text") | borderLight;
Screen screen(5, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"┌───┐\r\n"
"│tex│\r\n"
"└───┘");
}
TEST(BorderTest, Double) {
auto element = text("text") | borderDouble;
Screen screen(5, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"╔═══╗\r\n"
"║tex║\r\n"
"╚═══╝");
}
TEST(BorderTest, Rounded) {
auto element = text("text") | borderRounded;
Screen screen(5, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"╭───╮\r\n"
"│tex│\r\n"
"╰───╯");
}
TEST(BorderTest, Heavy) {
auto element = text("text") | borderHeavy;
Screen screen(5, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"┏━━━┓\r\n"
"┃tex┃\r\n"
"┗━━━┛");
}
TEST(BorderTest, Empty) {
auto element = text("text") | borderEmpty;
Screen screen(5, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
" \r\n"
" tex \r\n"
" ");
}
TEST(BorderTest, Styled) {
auto element = text("text") | borderStyled(DOUBLE);
Screen screen(5, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"╔═══╗\r\n"
"║tex║\r\n"
"╚═══╝");
}
TEST(BorderTest, WithPixel) {
Pixel pixel;
pixel.character = "o";
auto element = text("text") | borderWith(pixel);
Screen screen(5, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"ooooo\r\n"
"otexo\r\n"
"ooooo");
}
} // 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.

View File

@@ -0,0 +1,30 @@
#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(ColorTest, Foreground) {
auto element = text("text") | color(Color::Red);
Screen screen(5, 1);
Render(screen, element);
EXPECT_EQ(screen.PixelAt(0, 0).foreground_color, Color::Red);
EXPECT_EQ(screen.PixelAt(0, 0).background_color, Color());
}
TEST(ColorTest, Background) {
auto element = text("text") | bgcolor(Color::Red);
Screen screen(5, 1);
Render(screen, element);
EXPECT_EQ(screen.PixelAt(0, 0).foreground_color, Color());
EXPECT_EQ(screen.PixelAt(0, 0).background_color, Color::Red);
}
} // 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.

View File

@@ -0,0 +1,21 @@
#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(DimTest, Basic) {
auto element = text("text") | dim;
Screen screen(5, 1);
Render(screen, element);
EXPECT_TRUE(screen.PixelAt(0,0).dim);
}
} // 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.

View File

@@ -0,0 +1,114 @@
#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(SeparatorTest, Default) {
auto element = vbox({
text("top"),
separator(),
text("down"),
});
Screen screen(4, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"top \r\n"
"────\r\n"
"down");
}
TEST(SeparatorTest, Light) {
auto element = vbox({
text("top"),
separatorLight(),
text("down"),
});
Screen screen(4, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"top \r\n"
"────\r\n"
"down");
}
TEST(SeparatorTest, Double) {
auto element = vbox({
text("top"),
separatorDouble(),
text("down"),
});
Screen screen(4, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"top \r\n"
"════\r\n"
"down");
}
TEST(SeparatorTest, Heavy) {
auto element = vbox({
text("top"),
separatorHeavy(),
text("down"),
});
Screen screen(4, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"top \r\n"
"━━━━\r\n"
"down");
}
TEST(SeparatorTest, Empty) {
auto element = vbox({
text("top"),
separatorEmpty(),
text("down"),
});
Screen screen(4, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"top \r\n"
" \r\n"
"down");
}
TEST(SeparatorTest, Styled) {
auto element = vbox({
text("top"),
separatorStyled(DOUBLE),
text("down"),
});
Screen screen(4, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"top \r\n"
"════\r\n"
"down");
}
TEST(SeparatorTest, WithPixel) {
Pixel pixel;
pixel.character = "o";
auto element = vbox({
text("top"),
separator(pixel),
text("down"),
});
Screen screen(4, 3);
Render(screen, element);
EXPECT_EQ(screen.ToString(),
"top \r\n"
"oooo\r\n"
"down");
}
} // 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.

View File

@@ -0,0 +1,21 @@
#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(UnderlinedTest, Basic) {
auto element = text("text") | underlined;
Screen screen(5, 1);
Render(screen, element);
EXPECT_TRUE(screen.PixelAt(0,0).underlined);
}
} // 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.