2021-08-09 05:25:20 +08:00
|
|
|
#include <gtest/gtest-message.h> // for Message
|
|
|
|
#include <gtest/gtest-test-part.h> // for SuiteApiResolver, TestFactoryImpl, TestPartResult
|
2021-05-02 02:40:35 +08:00
|
|
|
#include <string> // for allocator, basic_string, string
|
|
|
|
#include <vector> // for vector
|
|
|
|
|
2021-08-09 05:25:20 +08:00
|
|
|
#include "ftxui/dom/deprecated.hpp" // for text
|
|
|
|
#include "ftxui/dom/elements.hpp" // for operator|, Element, flex_grow, flex_shrink, hbox
|
2021-05-02 02:40:35 +08:00
|
|
|
#include "ftxui/dom/node.hpp" // for Render
|
|
|
|
#include "ftxui/screen/box.hpp" // for ftxui
|
|
|
|
#include "ftxui/screen/screen.hpp" // for Screen
|
2021-08-09 05:25:20 +08:00
|
|
|
#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;
|
|
|
|
using namespace ftxui;
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
TEST(HBoxTest, NoFlex_NoFlex_NoFlex) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012"),
|
|
|
|
text(L"abc"),
|
|
|
|
text(L"ABC"),
|
|
|
|
});
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"0", //
|
|
|
|
"0a", //
|
|
|
|
"0aA", //
|
|
|
|
"01aA", //
|
|
|
|
"01abA", //
|
|
|
|
"01abAB", //
|
|
|
|
"012abAB", //
|
|
|
|
"012abcAB", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012abcABC ", //
|
|
|
|
"012abcABC ", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
TEST(HBoxTest, FlexGrow_NoFlex_NoFlex) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012") | flex_grow,
|
|
|
|
text(L"abc"),
|
|
|
|
text(L"ABC"),
|
|
|
|
});
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"0", //
|
|
|
|
"0a", //
|
|
|
|
"0aA", //
|
|
|
|
"01aA", //
|
|
|
|
"01abA", //
|
|
|
|
"01abAB", //
|
|
|
|
"012abAB", //
|
|
|
|
"012abcAB", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012 abcABC", //
|
|
|
|
"012 abcABC", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
TEST(HBoxTest, NoFlex_FlexGrow_NoFlex) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012"),
|
|
|
|
text(L"abc") | flex_grow,
|
|
|
|
text(L"ABC"),
|
|
|
|
});
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"0", //
|
|
|
|
"0a", //
|
|
|
|
"0aA", //
|
|
|
|
"01aA", //
|
|
|
|
"01abA", //
|
|
|
|
"01abAB", //
|
|
|
|
"012abAB", //
|
|
|
|
"012abcAB", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012abc ABC", //
|
|
|
|
"012abc ABC", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
TEST(HBoxTest, NoFlex_NoFlex_FlexGrow) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012"),
|
|
|
|
text(L"abc"),
|
|
|
|
text(L"ABC") | flex_grow,
|
|
|
|
});
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"0", //
|
|
|
|
"0a", //
|
|
|
|
"0aA", //
|
|
|
|
"01aA", //
|
|
|
|
"01abA", //
|
|
|
|
"01abAB", //
|
|
|
|
"012abAB", //
|
|
|
|
"012abcAB", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012abcABC ", //
|
|
|
|
"012abcABC ", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
TEST(HBoxTest, FlexGrow_NoFlex_FlexGrow) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012") | flex_grow,
|
|
|
|
text(L"abc"),
|
|
|
|
text(L"ABC") | flex_grow,
|
|
|
|
});
|
|
|
|
|
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"0", //
|
|
|
|
"0a", //
|
|
|
|
"0aA", //
|
|
|
|
"01aA", //
|
|
|
|
"01abA", //
|
|
|
|
"01abAB", //
|
|
|
|
"012abAB", //
|
|
|
|
"012abcAB", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012abcABC ", //
|
|
|
|
"012 abcABC ", //
|
|
|
|
"012 abcABC ", //
|
|
|
|
"012 abcABC ", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(HBoxTest, FlexGrow_FlexGrow_FlexGrow) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012") | flex_grow,
|
|
|
|
text(L"abc") | flex_grow,
|
|
|
|
text(L"ABC") | flex_grow,
|
|
|
|
});
|
|
|
|
|
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"0", //
|
|
|
|
"0a", //
|
|
|
|
"0aA", //
|
|
|
|
"01aA", //
|
|
|
|
"01abA", //
|
|
|
|
"01abAB", //
|
|
|
|
"012abAB", //
|
|
|
|
"012abcAB", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012abcABC ", //
|
|
|
|
"012abc ABC ", //
|
|
|
|
"012 abc ABC ", //
|
|
|
|
"012 abc ABC ", //
|
|
|
|
"012 abc ABC ", //
|
|
|
|
"012 abc ABC ", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------
|
|
|
|
|
|
|
|
TEST(HBoxTest, FlexShrink_NoFlex_NoFlex) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012") | flex_shrink,
|
|
|
|
text(L"abc"),
|
|
|
|
text(L"ABC"),
|
|
|
|
});
|
|
|
|
|
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"a", //
|
|
|
|
"aA", //
|
|
|
|
"abA", //
|
|
|
|
"abAB", //
|
|
|
|
"abcAB", //
|
|
|
|
"abcABC", //
|
|
|
|
"0abcABC", //
|
|
|
|
"01abcABC", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012abcABC ", //
|
|
|
|
"012abcABC ", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
TEST(HBoxTest, NoFlex_FlexShrink_NoFlex) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012"),
|
|
|
|
text(L"abc") | flex_shrink,
|
|
|
|
text(L"ABC"),
|
|
|
|
});
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"0", //
|
|
|
|
"0A", //
|
|
|
|
"01A", //
|
|
|
|
"01AB", //
|
|
|
|
"012AB", //
|
|
|
|
"012ABC", //
|
|
|
|
"012aABC", //
|
|
|
|
"012abABC", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012abcABC ", //
|
|
|
|
"012abcABC ", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
TEST(HBoxTest, NoFlex_NoFlex_FlexShrink) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012"),
|
|
|
|
text(L"abc"),
|
|
|
|
text(L"ABC") | flex_shrink,
|
|
|
|
});
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"0", //
|
|
|
|
"0a", //
|
|
|
|
"01a", //
|
|
|
|
"01ab", //
|
|
|
|
"012ab", //
|
|
|
|
"012abc", //
|
|
|
|
"012abcA", //
|
|
|
|
"012abcAB", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012abcABC ", //
|
|
|
|
"012abcABC ", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
TEST(HBoxTest, FlexShrink_NoFlex_FlexShrink) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012") | flex_shrink,
|
|
|
|
text(L"abc"),
|
|
|
|
text(L"ABC") | flex_shrink,
|
|
|
|
});
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"a", //
|
|
|
|
"ab", //
|
|
|
|
"abc", //
|
|
|
|
"0abc", //
|
|
|
|
"0abcA", //
|
|
|
|
"01abcA", //
|
|
|
|
"01abcAB", //
|
|
|
|
"012abcAB", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012abcABC ", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
TEST(HBoxTest, FlexShrink_FlexShrink_FlexShrink) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012") | flex_shrink,
|
|
|
|
text(L"abc") | flex_shrink,
|
|
|
|
text(L"ABC") | flex_shrink,
|
|
|
|
});
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"0", //
|
|
|
|
"0a", //
|
|
|
|
"0aA", //
|
|
|
|
"01aA", //
|
|
|
|
"01abA", //
|
|
|
|
"01abAB", //
|
|
|
|
"012abAB", //
|
|
|
|
"012abcAB", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012abcABC ", //
|
|
|
|
"012abcABC ", //
|
|
|
|
"012abcABC ", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
2018-09-18 14:48:40 +08:00
|
|
|
}
|
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
TEST(HBoxTest, FlexGrow_NoFlex_FlewShrink) {
|
|
|
|
auto root = hbox({
|
|
|
|
text(L"012") | flex_grow,
|
|
|
|
text(L"abc"),
|
|
|
|
text(L"ABC") | flex_shrink,
|
|
|
|
});
|
2018-09-18 14:48:40 +08:00
|
|
|
|
2020-06-02 05:40:32 +08:00
|
|
|
std::vector<std::string> expectations = {
|
|
|
|
"", //
|
|
|
|
"0", //
|
|
|
|
"0a", //
|
|
|
|
"01a", //
|
|
|
|
"01ab", //
|
|
|
|
"012ab", //
|
|
|
|
"012abc", //
|
|
|
|
"012abcA", //
|
|
|
|
"012abcAB", //
|
|
|
|
"012abcABC", //
|
|
|
|
"012 abcABC", //
|
|
|
|
"012 abcABC", //
|
|
|
|
"012 abcABC", //
|
|
|
|
};
|
|
|
|
for (int i = 0; i < expectations.size(); ++i) {
|
|
|
|
Screen screen(i, 1);
|
|
|
|
Render(screen, root);
|
|
|
|
EXPECT_EQ(expectations[i], screen.ToString());
|
|
|
|
}
|
2018-09-18 14:48:40 +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.
|