Extract XCUI text editing core and window seam headers
This commit is contained in:
@@ -6,6 +6,7 @@ set(UI_TEST_SOURCES
|
||||
test_ui_core.cpp
|
||||
test_layout_engine.cpp
|
||||
test_ui_runtime.cpp
|
||||
test_ui_text_editing.cpp
|
||||
)
|
||||
|
||||
add_executable(core_ui_tests ${UI_TEST_SOURCES})
|
||||
|
||||
59
tests/Core/UI/test_ui_text_editing.cpp
Normal file
59
tests/Core/UI/test_ui_text_editing.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <XCEngine/UI/Text/UITextEditing.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace {
|
||||
|
||||
namespace UIText = XCEngine::UI::Text;
|
||||
|
||||
TEST(UITextEditingTest, Utf8CountingAndCaretOffsetsRespectCodepointBoundaries) {
|
||||
const std::string text = std::string("A") + "\xE4\xBD\xA0" + "B";
|
||||
|
||||
EXPECT_EQ(UIText::CountUtf8Codepoints(text), 3u);
|
||||
EXPECT_EQ(UIText::AdvanceUtf8Offset(text, 0u), 1u);
|
||||
EXPECT_EQ(UIText::AdvanceUtf8Offset(text, 1u), 4u);
|
||||
EXPECT_EQ(UIText::AdvanceUtf8Offset(text, 4u), 5u);
|
||||
EXPECT_EQ(UIText::RetreatUtf8Offset(text, text.size()), 4u);
|
||||
EXPECT_EQ(UIText::RetreatUtf8Offset(text, 4u), 1u);
|
||||
EXPECT_EQ(UIText::RetreatUtf8Offset(text, 1u), 0u);
|
||||
}
|
||||
|
||||
TEST(UITextEditingTest, AppendUtf8CodepointEncodesCharactersAndSkipsInvalidSurrogates) {
|
||||
std::string text = {};
|
||||
UIText::AppendUtf8Codepoint(text, 'A');
|
||||
UIText::AppendUtf8Codepoint(text, 0x4F60u);
|
||||
UIText::AppendUtf8Codepoint(text, 0x1F642u);
|
||||
UIText::AppendUtf8Codepoint(text, 0xD800u);
|
||||
|
||||
EXPECT_EQ(text, std::string("A") + "\xE4\xBD\xA0" + "\xF0\x9F\x99\x82");
|
||||
EXPECT_EQ(UIText::CountUtf8Codepoints(text), 3u);
|
||||
}
|
||||
|
||||
TEST(UITextEditingTest, SplitLinesAndLineHelpersTrackMultilineRanges) {
|
||||
const std::string text = "alpha\nbeta\n";
|
||||
|
||||
const auto lines = UIText::SplitLines(text);
|
||||
ASSERT_EQ(lines.size(), 3u);
|
||||
EXPECT_EQ(lines[0], "alpha");
|
||||
EXPECT_EQ(lines[1], "beta");
|
||||
EXPECT_EQ(lines[2], "");
|
||||
EXPECT_EQ(UIText::CountTextLines(text), 3u);
|
||||
EXPECT_EQ(UIText::CountUtf8CodepointsInRange(text, 6u, 10u), 4u);
|
||||
EXPECT_EQ(UIText::FindLineStartOffset(text, 7u), 6u);
|
||||
EXPECT_EQ(UIText::FindLineEndOffset(text, 7u), 10u);
|
||||
}
|
||||
|
||||
TEST(UITextEditingTest, MoveCaretVerticallyPreservesUtf8ColumnWhenPossible) {
|
||||
const std::string text = std::string("A") + "\xE4\xBD\xA0" + "Z\nBC\n";
|
||||
const std::size_t secondColumnCaret = UIText::AdvanceUtf8Offset(text, 1u);
|
||||
|
||||
const std::size_t movedDown = UIText::MoveCaretVertically(text, secondColumnCaret, 1);
|
||||
const std::size_t movedBackUp = UIText::MoveCaretVertically(text, movedDown, -1);
|
||||
|
||||
EXPECT_EQ(movedDown, 8u);
|
||||
EXPECT_EQ(movedBackUp, secondColumnCaret);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
Reference in New Issue
Block a user