Update examples to use std::string. (#182)

In examples and tests, use std::string.

In addtion:
1. Address follow-up from:
https://github.com/ArthurSonzogni/FTXUI/pull/179
2. Fix a bug when Input is used with std::string.
This commit is contained in:
Arthur Sonzogni
2021-08-09 00:27:37 +02:00
committed by GitHub
parent 3b4ab618a3
commit 9a54528bca
60 changed files with 817 additions and 836 deletions

View File

@@ -1,3 +1,4 @@
#include <iostream>
//#include "ftxui/component/event.hpp"
//#include "ftxui/component/receiver.hpp"
#include <vector>
@@ -17,15 +18,21 @@ bool GeneratorBool(const char*& data, size_t& size) {
return out;
}
std::wstring GeneratorString(const char*& data, size_t& size) {
std::string GeneratorString(const char*& data, size_t& size) {
int index = 0;
while (index < size && data[index])
++index;
auto out = std::wstring(data, data + index);
data += index;
size -= index;
return std::move(out);
try {
auto out = std::string(data, data + index);
auto w_out = to_wstring(out);
data += index;
size -= index;
return std::move(out);
} catch (...) {
// The input component do not support invalid UTF8 yet.
return "0";
}
}
int GeneratorInt(const char* data, size_t size) {
@@ -39,7 +46,7 @@ int GeneratorInt(const char* data, size_t size) {
bool g_bool;
int g_int;
std::vector<std::wstring> g_list;
std::vector<std::string> g_list;
Components GeneratorComponents(const char*& data, size_t& size, int depth);
@@ -114,7 +121,7 @@ extern "C" int LLVMFuzzerTestOneInput(const char* data, size_t size) {
g_bool = GeneratorBool(data, size);
g_int = GeneratorInt(data, size);
g_list = {
L"test_1", L"test_2", L"test_3", L"test_4", L"test_5",
"test_1", "test_2", "test_3", "test_4", "test_5",
};
int depth = 10;
@@ -123,6 +130,12 @@ extern "C" int LLVMFuzzerTestOneInput(const char* data, size_t size) {
int width = GeneratorInt(data, size);
int height = GeneratorInt(data, size);
width %= 500;
width += 500;
height %= 500;
height += 500;
auto screen =
Screen::Create(Dimension::Fixed(width), Dimension::Fixed(height));

View File

@@ -11,7 +11,7 @@
using namespace ftxui;
Component Focusable() {
return Button(L"", [] {});
return Button("", [] {});
}
Component NonFocusable() {
return Container::Horizontal({});

View File

@@ -200,7 +200,7 @@ class InputBase : public ComponentBase {
bool OnEvent(Event event) override {
wrapped_content_ = to_wstring(*content_);
if (wrapped_input_.OnEvent(event)) {
content_ = to_string(wrapped_content_);
*content_ = to_string(wrapped_content_);
return true;
}
return false;

View File

@@ -1,12 +1,12 @@
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver, TestFactoryImpl
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
#include <string> // for wstring
#include <string> // for string
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Input
#include "ftxui/component/component_base.hpp" // for ComponentBase, Component
#include "ftxui/component/component_options.hpp" // for InputOption
#include "ftxui/component/deprecated.hpp" // for Input
#include "ftxui/component/event.hpp" // for Event, Event::ArrowLeft, Event::ArrowRight, Event::Backspace, Event::Delete, Event::End, Event::Home
#include "ftxui/dom/elements.hpp" // for Fit
#include "ftxui/dom/node.hpp" // for Render
@@ -17,8 +17,8 @@
using namespace ftxui;
TEST(InputTest, Init) {
std::wstring content;
std::wstring placeholder;
std::string content;
std::string placeholder;
auto option = InputOption();
Component input = Input(&content, &placeholder, &option);
@@ -26,17 +26,17 @@ TEST(InputTest, Init) {
}
TEST(InputTest, Type) {
std::wstring content;
std::wstring placeholder;
std::string content;
std::string placeholder;
auto option = InputOption();
Component input = Input(&content, &placeholder, &option);
input->OnEvent(Event::Character('a'));
EXPECT_EQ(content, L"a");
input->OnEvent(Event::Character("a"));
EXPECT_EQ(content, "a");
EXPECT_EQ(option.cursor_position(), 1u);
input->OnEvent(Event::Character('b'));
EXPECT_EQ(content, L"ab");
EXPECT_EQ(content, "ab");
EXPECT_EQ(option.cursor_position(), 2u);
auto document = input->Render();
@@ -47,18 +47,18 @@ TEST(InputTest, Type) {
}
TEST(InputTest, TypePassword) {
std::wstring content;
std::wstring placeholder;
std::string content;
std::string placeholder;
auto option = InputOption();
option.password = true;
Component input = Input(&content, &placeholder, &option);
input->OnEvent(Event::Character('a'));
EXPECT_EQ(content, L"a");
EXPECT_EQ(content, "a");
EXPECT_EQ(option.cursor_position(), 1u);
input->OnEvent(Event::Character('b'));
EXPECT_EQ(content, L"ab");
EXPECT_EQ(content, "ab");
EXPECT_EQ(option.cursor_position(), 2u);
auto document = input->Render();
@@ -69,8 +69,8 @@ TEST(InputTest, TypePassword) {
}
TEST(InputTest, Arrow) {
std::wstring content;
std::wstring placeholder;
std::string content;
std::string placeholder;
auto option = InputOption();
auto input = Input(&content, &placeholder, &option);
@@ -106,53 +106,53 @@ TEST(InputTest, Arrow) {
}
TEST(InputTest, Insert) {
std::wstring content;
std::wstring placeholder;
std::string content;
std::string placeholder;
Component input = Input(&content, &placeholder);
input->OnEvent(Event::Character('a'));
input->OnEvent(Event::Character('b'));
input->OnEvent(Event::Character('c'));
EXPECT_EQ(content, L"abc");
EXPECT_EQ(content, "abc");
input->OnEvent(Event::ArrowLeft);
input->OnEvent(Event::ArrowLeft);
input->OnEvent(Event::Character('-'));
EXPECT_EQ(content, L"a-bc");
EXPECT_EQ(content, "a-bc");
input->OnEvent(Event::ArrowLeft);
input->OnEvent(Event::Character('-'));
EXPECT_EQ(content, L"a--bc");
EXPECT_EQ(content, "a--bc");
input->OnEvent(Event::ArrowLeft);
input->OnEvent(Event::ArrowLeft);
input->OnEvent(Event::ArrowLeft);
input->OnEvent(Event::Character('-'));
EXPECT_EQ(content, L"-a--bc");
EXPECT_EQ(content, "-a--bc");
}
TEST(InputTest, Home) {
std::wstring content;
std::wstring placeholder;
std::string content;
std::string placeholder;
auto option = InputOption();
auto input = Input(&content, &placeholder, &option);
input->OnEvent(Event::Character('a'));
input->OnEvent(Event::Character('b'));
input->OnEvent(Event::Character('c'));
EXPECT_EQ(content, L"abc");
EXPECT_EQ(content, "abc");
EXPECT_EQ(option.cursor_position(), 3u);
input->OnEvent(Event::Home);
EXPECT_EQ(option.cursor_position(), 0u);
input->OnEvent(Event::Character('-'));
EXPECT_EQ(content, L"-abc");
EXPECT_EQ(content, "-abc");
}
TEST(InputTest, End) {
std::wstring content;
std::wstring placeholder;
std::string content;
std::string placeholder;
auto option = InputOption();
auto input = Input(&content, &placeholder, &option);
@@ -169,8 +169,8 @@ TEST(InputTest, End) {
}
TEST(InputTest, Delete) {
std::wstring content;
std::wstring placeholder;
std::string content;
std::string placeholder;
auto option = InputOption();
auto input = Input(&content, &placeholder, &option);
@@ -179,21 +179,21 @@ TEST(InputTest, Delete) {
input->OnEvent(Event::Character('c'));
input->OnEvent(Event::ArrowLeft);
EXPECT_EQ(content, L"abc");
EXPECT_EQ(content, "abc");
EXPECT_EQ(option.cursor_position(), 2u);
input->OnEvent(Event::Delete);
EXPECT_EQ(content, L"ab");
EXPECT_EQ(content, "ab");
EXPECT_EQ(option.cursor_position(), 2u);
input->OnEvent(Event::Delete);
EXPECT_EQ(content, L"ab");
EXPECT_EQ(content, "ab");
EXPECT_EQ(option.cursor_position(), 2u);
}
TEST(InputTest, Backspace) {
std::wstring content;
std::wstring placeholder;
std::string content;
std::string placeholder;
auto option = InputOption();
auto input = Input(&content, &placeholder, &option);
@@ -202,19 +202,19 @@ TEST(InputTest, Backspace) {
input->OnEvent(Event::Character('c'));
input->OnEvent(Event::ArrowLeft);
EXPECT_EQ(content, L"abc");
EXPECT_EQ(content, "abc");
EXPECT_EQ(option.cursor_position(), 2u);
input->OnEvent(Event::Backspace);
EXPECT_EQ(content, L"ac");
EXPECT_EQ(content, "ac");
EXPECT_EQ(option.cursor_position(), 1u);
input->OnEvent(Event::Backspace);
EXPECT_EQ(content, L"c");
EXPECT_EQ(content, "c");
EXPECT_EQ(option.cursor_position(), 0u);
input->OnEvent(Event::Backspace);
EXPECT_EQ(content, L"c");
EXPECT_EQ(content, "c");
EXPECT_EQ(option.cursor_position(), 0u);
}

View File

@@ -1,7 +1,7 @@
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver, TestFactoryImpl
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
#include <string> // for wstring, basic_string
#include <string> // for string, basic_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
@@ -14,7 +14,7 @@ using namespace ftxui;
TEST(RadioboxTest, Navigation) {
int selected = 0;
std::vector<std::wstring> entries = {L"1", L"2", L"3"};
std::vector<std::string> entries = {"1", "2", "3"};
auto radiobox = Radiobox(&entries, &selected);
// With arrow key.
@@ -60,7 +60,7 @@ TEST(RadioboxTest, Navigation) {
EXPECT_EQ(selected, 0);
// With more entries
entries = {L"1", L"2", L"3"};
entries = {"1", "2", "3"};
EXPECT_EQ(selected, 0);
radiobox->OnEvent(Event::ArrowDown);
radiobox->OnEvent(Event::Return);

View File

@@ -4,9 +4,8 @@
#include "ftxui/component/component.hpp" // for Renderer
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for Element
#include "gtest/gtest_pred_impl.h" // for Test, TEST, EXPECT_EQ
#include "ftxui/dom/elements.hpp" // for text, Element
#include "gtest/gtest_pred_impl.h" // for Test, TEST, EXPECT_EQ
using namespace ftxui;
@@ -18,7 +17,7 @@ bool TestSignal(int signal) {
called++;
std::raise(signal);
called++;
return text(L"");
return text("");
});
auto screen = ScreenInteractive::FitComponent();

View File

@@ -2,7 +2,7 @@
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver, TestFactoryImpl
#include <functional> // for function
#include <memory> // for __shared_ptr_access, shared_ptr, allocator
#include <string> // for wstring, basic_string
#include <string> // for string, basic_string
#include <vector> // for vector
#include "ftxui/component/captured_mouse.hpp" // for ftxui
@@ -15,7 +15,7 @@
using namespace ftxui;
TEST(ToggleTest, leftRightArrow) {
std::vector<std::wstring> entries = {L"On", L"Off"};
std::vector<std::string> entries = {"On", "Off"};
int selected = 0;
auto toggle = Toggle(&entries, &selected);
@@ -42,7 +42,7 @@ TEST(ToggleTest, leftRightArrow) {
EXPECT_EQ(selected, 0);
// With more entries
entries = {L"1", L"2", L"3"};
entries = {"1", "2", "3"};
EXPECT_EQ(selected, 0);
toggle->OnEvent(Event::ArrowRight);
EXPECT_EQ(selected, 1);
@@ -59,7 +59,7 @@ TEST(ToggleTest, leftRightArrow) {
}
TEST(ToggleTest, Tab) {
std::vector<std::wstring> entries = {L"1", L"2", L"3"};
std::vector<std::string> entries = {"1", "2", "3"};
int selected = 0;
auto toggle = Toggle(&entries, &selected);
@@ -86,7 +86,7 @@ TEST(ToggleTest, Tab) {
}
TEST(ToggleTest, OnChange) {
std::vector<std::wstring> entries = {L"1", L"2", L"3"};
std::vector<std::string> entries = {"1", "2", "3"};
int selected = 0;
int counter = 0;
auto option = ToggleOption();
@@ -115,7 +115,7 @@ TEST(ToggleTest, OnChange) {
}
TEST(ToggleTest, OnEnter) {
std::vector<std::wstring> entries = {L"1", L"2", L"3"};
std::vector<std::string> entries = {"1", "2", "3"};
int selected = 0;
int counter = 0;

View File

@@ -9,14 +9,17 @@
namespace ftxui {
static std::string charset[] =
static std::string charset[] = {
#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
// Microsoft's terminals often use fonts not handling the 8 unicode
// characters for representing the whole gauge. Fallback with less.
{" ", " ", " ", " ", "", "", "", "", "", ""};
" ", " ", " ", " ", "", "", "", "", "", "",
#else
{" ", " ", "", "", "", "", "", "", "", ""};
" ", " ", "", "", "", "", "", "", "", "",
#endif
// An extra character in case when the fuzzer manage to have:
// int(9 * (limit - limit_int) = 9
""};
class Gauge : public Node {
public:

View File

@@ -3,8 +3,7 @@
#include <string> // for allocator, basic_string, string
#include <vector> // for vector
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for operator|, Element, flex_grow, flex_shrink, hbox
#include "ftxui/dom/elements.hpp" // for text, operator|, Element, flex_grow, flex_shrink, hbox
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/screen.hpp" // for Screen
@@ -15,9 +14,9 @@ using namespace ftxui;
TEST(HBoxTest, NoFlex_NoFlex_NoFlex) {
auto root = hbox({
text(L"012"),
text(L"abc"),
text(L"ABC"),
text("012"),
text("abc"),
text("ABC"),
});
std::vector<std::string> expectations = {
@@ -43,9 +42,9 @@ TEST(HBoxTest, NoFlex_NoFlex_NoFlex) {
TEST(HBoxTest, FlexGrow_NoFlex_NoFlex) {
auto root = hbox({
text(L"012") | flex_grow,
text(L"abc"),
text(L"ABC"),
text("012") | flex_grow,
text("abc"),
text("ABC"),
});
std::vector<std::string> expectations = {
@@ -71,9 +70,9 @@ TEST(HBoxTest, FlexGrow_NoFlex_NoFlex) {
TEST(HBoxTest, NoFlex_FlexGrow_NoFlex) {
auto root = hbox({
text(L"012"),
text(L"abc") | flex_grow,
text(L"ABC"),
text("012"),
text("abc") | flex_grow,
text("ABC"),
});
std::vector<std::string> expectations = {
@@ -99,9 +98,9 @@ TEST(HBoxTest, NoFlex_FlexGrow_NoFlex) {
TEST(HBoxTest, NoFlex_NoFlex_FlexGrow) {
auto root = hbox({
text(L"012"),
text(L"abc"),
text(L"ABC") | flex_grow,
text("012"),
text("abc"),
text("ABC") | flex_grow,
});
std::vector<std::string> expectations = {
@@ -127,9 +126,9 @@ TEST(HBoxTest, NoFlex_NoFlex_FlexGrow) {
TEST(HBoxTest, FlexGrow_NoFlex_FlexGrow) {
auto root = hbox({
text(L"012") | flex_grow,
text(L"abc"),
text(L"ABC") | flex_grow,
text("012") | flex_grow,
text("abc"),
text("ABC") | flex_grow,
});
std::vector<std::string> expectations = {
@@ -157,9 +156,9 @@ TEST(HBoxTest, FlexGrow_NoFlex_FlexGrow) {
TEST(HBoxTest, FlexGrow_FlexGrow_FlexGrow) {
auto root = hbox({
text(L"012") | flex_grow,
text(L"abc") | flex_grow,
text(L"ABC") | flex_grow,
text("012") | flex_grow,
text("abc") | flex_grow,
text("ABC") | flex_grow,
});
std::vector<std::string> expectations = {
@@ -191,9 +190,9 @@ TEST(HBoxTest, FlexGrow_FlexGrow_FlexGrow) {
TEST(HBoxTest, FlexShrink_NoFlex_NoFlex) {
auto root = hbox({
text(L"012") | flex_shrink,
text(L"abc"),
text(L"ABC"),
text("012") | flex_shrink,
text("abc"),
text("ABC"),
});
std::vector<std::string> expectations = {
@@ -219,9 +218,9 @@ TEST(HBoxTest, FlexShrink_NoFlex_NoFlex) {
TEST(HBoxTest, NoFlex_FlexShrink_NoFlex) {
auto root = hbox({
text(L"012"),
text(L"abc") | flex_shrink,
text(L"ABC"),
text("012"),
text("abc") | flex_shrink,
text("ABC"),
});
std::vector<std::string> expectations = {
@@ -247,9 +246,9 @@ TEST(HBoxTest, NoFlex_FlexShrink_NoFlex) {
TEST(HBoxTest, NoFlex_NoFlex_FlexShrink) {
auto root = hbox({
text(L"012"),
text(L"abc"),
text(L"ABC") | flex_shrink,
text("012"),
text("abc"),
text("ABC") | flex_shrink,
});
std::vector<std::string> expectations = {
@@ -275,9 +274,9 @@ TEST(HBoxTest, NoFlex_NoFlex_FlexShrink) {
TEST(HBoxTest, FlexShrink_NoFlex_FlexShrink) {
auto root = hbox({
text(L"012") | flex_shrink,
text(L"abc"),
text(L"ABC") | flex_shrink,
text("012") | flex_shrink,
text("abc"),
text("ABC") | flex_shrink,
});
std::vector<std::string> expectations = {
@@ -302,9 +301,9 @@ TEST(HBoxTest, FlexShrink_NoFlex_FlexShrink) {
TEST(HBoxTest, FlexShrink_FlexShrink_FlexShrink) {
auto root = hbox({
text(L"012") | flex_shrink,
text(L"abc") | flex_shrink,
text(L"ABC") | flex_shrink,
text("012") | flex_shrink,
text("abc") | flex_shrink,
text("ABC") | flex_shrink,
});
std::vector<std::string> expectations = {
@@ -331,9 +330,9 @@ TEST(HBoxTest, FlexShrink_FlexShrink_FlexShrink) {
TEST(HBoxTest, FlexGrow_NoFlex_FlewShrink) {
auto root = hbox({
text(L"012") | flex_grow,
text(L"abc"),
text(L"ABC") | flex_shrink,
text("012") | flex_grow,
text("abc"),
text("ABC") | flex_shrink,
});
std::vector<std::string> expectations = {

View File

@@ -68,8 +68,8 @@ class HFlow : public Node {
///
/// ```cpp
/// hbox({
/// text(L"Left"),
/// text(L"Right"),
/// text("Left"),
/// text("Right"),
/// });
/// ```
Element hflow(Elements children) {

View File

@@ -1,6 +1,7 @@
#include <memory> // for make_shared
#include <string> // for string
#include <vector> // for vector
#include <algorithm> // for min
#include <memory> // for make_shared
#include <string> // for string, wstring
#include <vector> // for vector
#include "ftxui/dom/deprecated.hpp" // for text, vtext
#include "ftxui/dom/elements.hpp" // for Element, text, vtext
@@ -87,7 +88,7 @@ Element text(std::string text) {
return std::make_shared<Text>(text);
}
/// @brief Display a piece of UTF16 encoded unicode text.
/// @brief Display a piece of unicode text.
/// @ingroup dom
/// @see ftxui::to_wstring
///
@@ -136,7 +137,7 @@ Element vtext(std::string text) {
return std::make_shared<VText>(text);
}
/// @brief Display a piece of UTF16 encoded unicode text vertically.
/// @brief Display a piece unicode text vertically.
/// @ingroup dom
/// @see ftxui::to_wstring
///

View File

@@ -1,19 +1,17 @@
#include <gtest/gtest-message.h> // for Message
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl, TestPartResult
#include <string> // for allocator, wstring
#include <string> // for allocator, string
#include "ftxui/dom/deprecated.hpp" // for text
#include "ftxui/dom/elements.hpp" // for 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 "ftxui/screen/string.hpp" // for to_string
#include "gtest/gtest_pred_impl.h" // for Test, EXPECT_EQ, TEST
#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
using namespace ftxui;
TEST(TextTest, ScreenHeightSmaller) {
auto element = text(L"test");
auto element = text("test");
Screen screen(2, 0);
Render(screen, element);
@@ -21,7 +19,7 @@ TEST(TextTest, ScreenHeightSmaller) {
}
TEST(TextTest, ScreenSmaller) {
auto element = text(L"test");
auto element = text("test");
Screen screen(2, 1);
Render(screen, element);
@@ -29,7 +27,7 @@ TEST(TextTest, ScreenSmaller) {
}
TEST(TextTest, ScreenFit) {
auto element = text(L"test");
auto element = text("test");
Screen screen(4, 1);
Render(screen, element);
@@ -37,7 +35,7 @@ TEST(TextTest, ScreenFit) {
}
TEST(TextTest, ScreenBigger) {
auto element = text(L"test");
auto element = text("test");
Screen screen(6, 1);
Render(screen, element);
@@ -45,7 +43,7 @@ TEST(TextTest, ScreenBigger) {
}
TEST(TextTest, ScreenBigger2) {
auto element = text(L"test");
auto element = text("test");
Screen screen(6, 2);
Render(screen, element);
@@ -54,7 +52,7 @@ TEST(TextTest, ScreenBigger2) {
// See https://github.com/ArthurSonzogni/FTXUI/issues/2#issuecomment-504871456
TEST(TextTest, CJK) {
auto element = text(L"测试") | border;
auto element = text("测试") | border;
Screen screen(6, 3);
Render(screen, element);
EXPECT_EQ(
@@ -66,7 +64,7 @@ TEST(TextTest, CJK) {
// See https://github.com/ArthurSonzogni/FTXUI/issues/2#issuecomment-504871456
TEST(TextTest, CJK_2) {
auto element = text(L"测试") | border;
auto element = text("测试") | border;
Screen screen(5, 3);
Render(screen, element);
EXPECT_EQ(
@@ -78,7 +76,7 @@ TEST(TextTest, CJK_2) {
// See https://github.com/ArthurSonzogni/FTXUI/issues/2#issuecomment-504871456
TEST(TextTest, CJK_3) {
auto element = text(L"测试") | border;
auto element = text("测试") | border;
Screen screen(4, 3);
Render(screen, element);
EXPECT_EQ(
@@ -89,20 +87,20 @@ TEST(TextTest, CJK_3) {
}
TEST(TextTest, CombiningCharacters) {
const std::wstring t =
const std::string t =
// Combining above:
L"ā à á â ã ā a̅ ă ȧ ä ả å a̋ ǎ a̍ a̎ ȁ a̐ ȃ a̒ a̔ a̕ a̚ a̛ a̽ a̾ a̿ à á a͂ a͆ a͊ a͋ a͌ a͐ "
L"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⃔ "
L"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⃔ "
"a⃕ a⃖ a⃗ a⃛ a⃜ a⃡ a⃩ a⃰ a︠ a︡ a︢ a︣"
// Combining middle:
L"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⃦"
// Combining below:
L"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͍ "
L"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⃨";
auto element = text(t);
Screen screen(290, 1);
Render(screen, element);
EXPECT_EQ(to_string(t), screen.ToString());
EXPECT_EQ(t, screen.ToString());
}
// Copyright 2020 Arthur Sonzogni. All rights reserved.

View File

@@ -4,8 +4,7 @@
#include <string> // for allocator, basic_string, string
#include <vector> // for vector
#include "ftxui/dom/deprecated.hpp" // for vtext
#include "ftxui/dom/elements.hpp" // for operator|, Element, flex_grow, flex_shrink, vbox
#include "ftxui/dom/elements.hpp" // for vtext, operator|, Element, flex_grow, flex_shrink, vbox
#include "ftxui/dom/node.hpp" // for Render
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/screen.hpp" // for Screen
@@ -22,9 +21,9 @@ std::string rotate(std::string str) {
TEST(VBoxText, NoFlex_NoFlex_NoFlex) {
auto root = vbox({
vtext(L"012"),
vtext(L"abc"),
vtext(L"ABC"),
vtext("012"),
vtext("abc"),
vtext("ABC"),
});
std::vector<std::string> expectations = {
@@ -50,9 +49,9 @@ TEST(VBoxText, NoFlex_NoFlex_NoFlex) {
TEST(VBoxText, FlexGrow_NoFlex_NoFlex) {
auto root = vbox({
vtext(L"012") | flex_grow,
vtext(L"abc"),
vtext(L"ABC"),
vtext("012") | flex_grow,
vtext("abc"),
vtext("ABC"),
});
std::vector<std::string> expectations = {
@@ -78,9 +77,9 @@ TEST(VBoxText, FlexGrow_NoFlex_NoFlex) {
TEST(VBoxText, NoFlex_FlexGrow_NoFlex) {
auto root = vbox({
vtext(L"012"),
vtext(L"abc") | flex_grow,
vtext(L"ABC"),
vtext("012"),
vtext("abc") | flex_grow,
vtext("ABC"),
});
std::vector<std::string> expectations = {
@@ -106,9 +105,9 @@ TEST(VBoxText, NoFlex_FlexGrow_NoFlex) {
TEST(VBoxText, NoFlex_NoFlex_FlexGrow) {
auto root = vbox({
vtext(L"012"),
vtext(L"abc"),
vtext(L"ABC") | flex_grow,
vtext("012"),
vtext("abc"),
vtext("ABC") | flex_grow,
});
std::vector<std::string> expectations = {
@@ -134,9 +133,9 @@ TEST(VBoxText, NoFlex_NoFlex_FlexGrow) {
TEST(VBoxText, FlexGrow_NoFlex_FlexGrow) {
auto root = vbox({
vtext(L"012") | flex_grow,
vtext(L"abc"),
vtext(L"ABC") | flex_grow,
vtext("012") | flex_grow,
vtext("abc"),
vtext("ABC") | flex_grow,
});
std::vector<std::string> expectations = {
@@ -164,9 +163,9 @@ TEST(VBoxText, FlexGrow_NoFlex_FlexGrow) {
TEST(VBoxText, FlexGrow_FlexGrow_FlexGrow) {
auto root = vbox({
vtext(L"012") | flex_grow,
vtext(L"abc") | flex_grow,
vtext(L"ABC") | flex_grow,
vtext("012") | flex_grow,
vtext("abc") | flex_grow,
vtext("ABC") | flex_grow,
});
std::vector<std::string> expectations = {
@@ -198,9 +197,9 @@ TEST(VBoxText, FlexGrow_FlexGrow_FlexGrow) {
TEST(VBoxText, FlexShrink_NoFlex_NoFlex) {
auto root = vbox({
vtext(L"012") | flex_shrink,
vtext(L"abc"),
vtext(L"ABC"),
vtext("012") | flex_shrink,
vtext("abc"),
vtext("ABC"),
});
std::vector<std::string> expectations = {
@@ -226,9 +225,9 @@ TEST(VBoxText, FlexShrink_NoFlex_NoFlex) {
TEST(VBoxText, NoFlex_FlexShrink_NoFlex) {
auto root = vbox({
vtext(L"012"),
vtext(L"abc") | flex_shrink,
vtext(L"ABC"),
vtext("012"),
vtext("abc") | flex_shrink,
vtext("ABC"),
});
std::vector<std::string> expectations = {
@@ -254,9 +253,9 @@ TEST(VBoxText, NoFlex_FlexShrink_NoFlex) {
TEST(VBoxText, NoFlex_NoFlex_FlexShrink) {
auto root = vbox({
vtext(L"012"),
vtext(L"abc"),
vtext(L"ABC") | flex_shrink,
vtext("012"),
vtext("abc"),
vtext("ABC") | flex_shrink,
});
std::vector<std::string> expectations = {
@@ -282,9 +281,9 @@ TEST(VBoxText, NoFlex_NoFlex_FlexShrink) {
TEST(VBoxText, FlexShrink_NoFlex_FlexShrink) {
auto root = vbox({
vtext(L"012") | flex_shrink,
vtext(L"abc"),
vtext(L"ABC") | flex_shrink,
vtext("012") | flex_shrink,
vtext("abc"),
vtext("ABC") | flex_shrink,
});
std::vector<std::string> expectations = {
@@ -309,9 +308,9 @@ TEST(VBoxText, FlexShrink_NoFlex_FlexShrink) {
TEST(VBoxText, FlexShrink_FlexShrink_FlexShrink) {
auto root = vbox({
vtext(L"012") | flex_shrink,
vtext(L"abc") | flex_shrink,
vtext(L"ABC") | flex_shrink,
vtext("012") | flex_shrink,
vtext("abc") | flex_shrink,
vtext("ABC") | flex_shrink,
});
std::vector<std::string> expectations = {
@@ -338,9 +337,9 @@ TEST(VBoxText, FlexShrink_FlexShrink_FlexShrink) {
TEST(VBoxText, FlexGrow_NoFlex_FlewShrink) {
auto root = vbox({
vtext(L"012") | flex_grow,
vtext(L"abc"),
vtext(L"ABC") | flex_shrink,
vtext("012") | flex_grow,
vtext("abc"),
vtext("ABC") | flex_shrink,
});
std::vector<std::string> expectations = {

View File

@@ -13,6 +13,8 @@
#include <locale> // for wstring_convert
#include <string> // for string, basic_string, wstring, allocator
#include "ftxui/screen/deprecated.hpp" // for wchar_width, wstring_width
namespace {
struct Interval {