2021-05-10 02:32:27 +08:00
|
|
|
#include <gtest/gtest-message.h> // for Message
|
|
|
|
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl, TestPartResult
|
2021-08-09 06:27:37 +08:00
|
|
|
#include <string> // for allocator, string
|
2021-05-02 02:40:35 +08:00
|
|
|
|
2021-08-09 06:27:37 +08:00
|
|
|
#include "ftxui/dom/elements.hpp" // for text, operator|, border, Element
|
|
|
|
#include "ftxui/dom/node.hpp" // for Render
|
|
|
|
#include "ftxui/screen/box.hpp" // for ftxui
|
|
|
|
#include "ftxui/screen/screen.hpp" // for Screen
|
|
|
|
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
using namespace ftxui;
|
2018-09-18 14:48:40 +08:00
|
|
|
|
|
|
|
TEST(TextTest, ScreenHeightSmaller) {
|
2021-08-09 06:27:37 +08:00
|
|
|
auto element = text("test");
|
2018-09-18 14:48:40 +08:00
|
|
|
Screen screen(2, 0);
|
2020-05-21 03:23:59 +08:00
|
|
|
Render(screen, element);
|
2018-09-18 14:48:40 +08:00
|
|
|
|
|
|
|
EXPECT_EQ("", screen.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TextTest, ScreenSmaller) {
|
2021-08-09 06:27:37 +08:00
|
|
|
auto element = text("test");
|
2018-09-18 14:48:40 +08:00
|
|
|
Screen screen(2, 1);
|
2020-05-21 03:23:59 +08:00
|
|
|
Render(screen, element);
|
2018-09-18 14:48:40 +08:00
|
|
|
|
|
|
|
EXPECT_EQ("te", screen.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TextTest, ScreenFit) {
|
2021-08-09 06:27:37 +08:00
|
|
|
auto element = text("test");
|
2018-09-18 14:48:40 +08:00
|
|
|
Screen screen(4, 1);
|
2020-05-21 03:23:59 +08:00
|
|
|
Render(screen, element);
|
2018-09-18 14:48:40 +08:00
|
|
|
|
|
|
|
EXPECT_EQ("test", screen.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TextTest, ScreenBigger) {
|
2021-08-09 06:27:37 +08:00
|
|
|
auto element = text("test");
|
2018-09-18 14:48:40 +08:00
|
|
|
Screen screen(6, 1);
|
2020-05-21 03:23:59 +08:00
|
|
|
Render(screen, element);
|
2018-09-18 14:48:40 +08:00
|
|
|
|
|
|
|
EXPECT_EQ("test ", screen.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TextTest, ScreenBigger2) {
|
2021-08-09 06:27:37 +08:00
|
|
|
auto element = text("test");
|
2018-09-18 14:48:40 +08:00
|
|
|
Screen screen(6, 2);
|
2020-05-21 03:23:59 +08:00
|
|
|
Render(screen, element);
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2021-03-22 05:54:39 +08:00
|
|
|
EXPECT_EQ("test \r\n ", screen.ToString());
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
2019-06-25 05:39:37 +08:00
|
|
|
|
|
|
|
// See https://github.com/ArthurSonzogni/FTXUI/issues/2#issuecomment-504871456
|
|
|
|
TEST(TextTest, CJK) {
|
2021-08-09 06:27:37 +08:00
|
|
|
auto element = text("测试") | border;
|
2019-06-25 05:39:37 +08:00
|
|
|
Screen screen(6, 3);
|
2020-05-21 03:23:59 +08:00
|
|
|
Render(screen, element);
|
2019-06-25 05:39:37 +08:00
|
|
|
EXPECT_EQ(
|
2021-08-08 04:30:55 +08:00
|
|
|
"╭────╮\r\n"
|
2021-03-22 05:54:39 +08:00
|
|
|
"│测试│\r\n"
|
2021-08-08 04:30:55 +08:00
|
|
|
"╰────╯",
|
2019-06-25 05:39:37 +08:00
|
|
|
screen.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
// See https://github.com/ArthurSonzogni/FTXUI/issues/2#issuecomment-504871456
|
|
|
|
TEST(TextTest, CJK_2) {
|
2021-08-09 06:27:37 +08:00
|
|
|
auto element = text("测试") | border;
|
2019-06-25 05:39:37 +08:00
|
|
|
Screen screen(5, 3);
|
2020-05-21 03:23:59 +08:00
|
|
|
Render(screen, element);
|
2019-06-25 05:39:37 +08:00
|
|
|
EXPECT_EQ(
|
2021-08-08 04:30:55 +08:00
|
|
|
"╭───╮\r\n"
|
2021-03-22 05:54:39 +08:00
|
|
|
"│测试\r\n"
|
2021-08-08 04:30:55 +08:00
|
|
|
"╰───╯",
|
2019-06-25 05:39:37 +08:00
|
|
|
screen.ToString());
|
|
|
|
}
|
|
|
|
|
|
|
|
// See https://github.com/ArthurSonzogni/FTXUI/issues/2#issuecomment-504871456
|
|
|
|
TEST(TextTest, CJK_3) {
|
2021-08-09 06:27:37 +08:00
|
|
|
auto element = text("测试") | border;
|
2019-06-25 05:39:37 +08:00
|
|
|
Screen screen(4, 3);
|
2020-05-21 03:23:59 +08:00
|
|
|
Render(screen, element);
|
2019-06-25 05:39:37 +08:00
|
|
|
EXPECT_EQ(
|
2021-08-08 04:30:55 +08:00
|
|
|
"╭──╮\r\n"
|
2021-03-22 05:54:39 +08:00
|
|
|
"│测│\r\n"
|
2021-08-08 04:30:55 +08:00
|
|
|
"╰──╯",
|
2019-06-25 05:39:37 +08:00
|
|
|
screen.ToString());
|
|
|
|
}
|
2020-08-16 06:24:18 +08:00
|
|
|
|
2021-06-26 07:32:27 +08:00
|
|
|
TEST(TextTest, CombiningCharacters) {
|
2021-08-09 06:27:37 +08:00
|
|
|
const std::string t =
|
2021-06-26 07:32:27 +08:00
|
|
|
// Combining above:
|
2021-08-09 06:27:37 +08:00
|
|
|
"ā à á â ã ā a̅ ă ȧ ä ả å a̋ ǎ a̍ a̎ ȁ a̐ ȃ a̒ a̔ a̕ a̚ a̛ a̽ a̾ a̿ à á a͂ a͆ a͊ a͋ a͌ a͐ "
|
|
|
|
"a͑ a͒ a͗ a͘ a͛ a͝ a͞ a͠ a͡ aͣ aͤ aͥ aͦ aͧ aͨ aͩ aͪ aͫ aͬ aͭ aͮ aͯ a᷀ a᷁ a᷃ a᷄ a᷅ a᷆ a᷇ a᷈ a᷉ a᷾ a⃐ a⃑ a⃔ "
|
|
|
|
"a⃕ a⃖ a⃗ a⃛ a⃜ a⃡ a⃩ a⃰ a︠ a︡ a︢ a︣"
|
2021-06-26 07:32:27 +08:00
|
|
|
// Combining middle:
|
2021-08-09 06:27:37 +08:00
|
|
|
"a̴ a̵ a̶ a̷ a̸ a⃒ a⃓ a⃘ a⃙ a⃚ a⃝ a⃞ a⃟ a⃥ a⃦"
|
2021-06-26 07:32:27 +08:00
|
|
|
// Combining below:
|
2021-08-09 06:27:37 +08:00
|
|
|
"a̗ a̘ a̙ a̜ a̝ a̞ a̟ a̠ a̡ a̢ ạ ḁ a̦ a̧ ą a̩ a̪ a̫ a̬ a̭ a̮ a̯ a̰ a̱ a̲ a̳ a̹ a̺ a̻ a̼ aͅ a͇ a͈ a͉ a͍ "
|
|
|
|
"a͎ a͓ a͔ a͕ a͖ a͙ a͚ a͜ a͟ a͢ a᷂ a᷊ a᷿ a⃨";
|
2021-06-26 07:32:27 +08:00
|
|
|
auto element = text(t);
|
|
|
|
Screen screen(290, 1);
|
|
|
|
Render(screen, element);
|
2021-08-09 06:27:37 +08:00
|
|
|
EXPECT_EQ(t, screen.ToString());
|
2021-06-26 07:32:27 +08:00
|
|
|
}
|
|
|
|
|
2020-08-16 06:24:18 +08:00
|
|
|
// 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.
|