mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-10-01 17:29:07 +08:00
Feature: Add multi-line input. (#630)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "ftxui/screen/string.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
#include <string> // for allocator, string
|
||||
#include "ftxui/screen/string_internal.hpp"
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
@@ -61,41 +62,41 @@ TEST(StringTest, GlyphCount) {
|
||||
EXPECT_EQ(GlyphCount("a\1a"), 2);
|
||||
}
|
||||
|
||||
TEST(StringTest, GlyphPosition) {
|
||||
TEST(StringTest, GlyphIterate) {
|
||||
// Basic:
|
||||
EXPECT_EQ(GlyphPosition("", -1), 0);
|
||||
EXPECT_EQ(GlyphPosition("", 0), 0);
|
||||
EXPECT_EQ(GlyphPosition("", 1), 0);
|
||||
EXPECT_EQ(GlyphPosition("a", 0), 0);
|
||||
EXPECT_EQ(GlyphPosition("a", 1), 1);
|
||||
EXPECT_EQ(GlyphPosition("ab", 0), 0);
|
||||
EXPECT_EQ(GlyphPosition("ab", 1), 1);
|
||||
EXPECT_EQ(GlyphPosition("ab", 2), 2);
|
||||
EXPECT_EQ(GlyphPosition("abc", 0), 0);
|
||||
EXPECT_EQ(GlyphPosition("abc", 1), 1);
|
||||
EXPECT_EQ(GlyphPosition("abc", 2), 2);
|
||||
EXPECT_EQ(GlyphPosition("abc", 3), 3);
|
||||
EXPECT_EQ(GlyphIterate("", -1), 0);
|
||||
EXPECT_EQ(GlyphIterate("", 0), 0);
|
||||
EXPECT_EQ(GlyphIterate("", 1), 0);
|
||||
EXPECT_EQ(GlyphIterate("a", 0), 0);
|
||||
EXPECT_EQ(GlyphIterate("a", 1), 1);
|
||||
EXPECT_EQ(GlyphIterate("ab", 0), 0);
|
||||
EXPECT_EQ(GlyphIterate("ab", 1), 1);
|
||||
EXPECT_EQ(GlyphIterate("ab", 2), 2);
|
||||
EXPECT_EQ(GlyphIterate("abc", 0), 0);
|
||||
EXPECT_EQ(GlyphIterate("abc", 1), 1);
|
||||
EXPECT_EQ(GlyphIterate("abc", 2), 2);
|
||||
EXPECT_EQ(GlyphIterate("abc", 3), 3);
|
||||
// Fullwidth glyphs:
|
||||
EXPECT_EQ(GlyphPosition("测", 0), 0);
|
||||
EXPECT_EQ(GlyphPosition("测", 1), 3);
|
||||
EXPECT_EQ(GlyphPosition("测试", 0), 0);
|
||||
EXPECT_EQ(GlyphPosition("测试", 1), 3);
|
||||
EXPECT_EQ(GlyphPosition("测试", 2), 6);
|
||||
EXPECT_EQ(GlyphPosition("测试", 1, 3), 6);
|
||||
EXPECT_EQ(GlyphPosition("测试", 1, 0), 3);
|
||||
EXPECT_EQ(GlyphIterate("测", 0), 0);
|
||||
EXPECT_EQ(GlyphIterate("测", 1), 3);
|
||||
EXPECT_EQ(GlyphIterate("测试", 0), 0);
|
||||
EXPECT_EQ(GlyphIterate("测试", 1), 3);
|
||||
EXPECT_EQ(GlyphIterate("测试", 2), 6);
|
||||
EXPECT_EQ(GlyphIterate("测试", 1, 3), 6);
|
||||
EXPECT_EQ(GlyphIterate("测试", 1, 0), 3);
|
||||
// Combining characters:
|
||||
EXPECT_EQ(GlyphPosition("ā", 0), 0);
|
||||
EXPECT_EQ(GlyphPosition("ā", 1), 3);
|
||||
EXPECT_EQ(GlyphPosition("a⃒a̗ā", 0), 0);
|
||||
EXPECT_EQ(GlyphPosition("a⃒a̗ā", 1), 4);
|
||||
EXPECT_EQ(GlyphPosition("a⃒a̗ā", 2), 7);
|
||||
EXPECT_EQ(GlyphPosition("a⃒a̗ā", 3), 10);
|
||||
EXPECT_EQ(GlyphIterate("ā", 0), 0);
|
||||
EXPECT_EQ(GlyphIterate("ā", 1), 3);
|
||||
EXPECT_EQ(GlyphIterate("a⃒a̗ā", 0), 0);
|
||||
EXPECT_EQ(GlyphIterate("a⃒a̗ā", 1), 4);
|
||||
EXPECT_EQ(GlyphIterate("a⃒a̗ā", 2), 7);
|
||||
EXPECT_EQ(GlyphIterate("a⃒a̗ā", 3), 10);
|
||||
// Control characters:
|
||||
EXPECT_EQ(GlyphPosition("\1", 0), 0);
|
||||
EXPECT_EQ(GlyphPosition("\1", 1), 1);
|
||||
EXPECT_EQ(GlyphPosition("a\1a", 0), 0);
|
||||
EXPECT_EQ(GlyphPosition("a\1a", 1), 2);
|
||||
EXPECT_EQ(GlyphPosition("a\1a", 2), 3);
|
||||
EXPECT_EQ(GlyphIterate("\1", 0), 0);
|
||||
EXPECT_EQ(GlyphIterate("\1", 1), 1);
|
||||
EXPECT_EQ(GlyphIterate("a\1a", 0), 0);
|
||||
EXPECT_EQ(GlyphIterate("a\1a", 1), 2);
|
||||
EXPECT_EQ(GlyphIterate("a\1a", 2), 3);
|
||||
}
|
||||
|
||||
TEST(StringTest, CellToGlyphIndex) {
|
||||
@@ -135,7 +136,7 @@ TEST(StringTest, Utf8ToWordBreakProperty) {
|
||||
EXPECT_EQ(Utf8ToWordBreakProperty(":"), T({P::MidLetter}));
|
||||
EXPECT_EQ(Utf8ToWordBreakProperty("."), T({P::MidNumLet}));
|
||||
EXPECT_EQ(Utf8ToWordBreakProperty("\r"), T({})); // FIXME
|
||||
EXPECT_EQ(Utf8ToWordBreakProperty("\n"), T({})); // FIXME
|
||||
EXPECT_EQ(Utf8ToWordBreakProperty("\n"), T({P::LF}));
|
||||
}
|
||||
|
||||
TEST(StringTest, to_string) {
|
||||
|
Reference in New Issue
Block a user