mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-05-08 19:21:14 +08:00
48 lines
1.6 KiB
C++
48 lines
1.6 KiB
C++
![]() |
#include <gtest/gtest-message.h> // for Message
|
||
|
#include <gtest/gtest-test-part.h> // for TestPartResult, SuiteApiResolver, TestFactoryImpl
|
||
|
#include <string> // for allocator, string
|
||
|
|
||
|
#include "ftxui/screen/string.hpp"
|
||
|
#include "gtest/gtest_pred_impl.h" // for EXPECT_EQ, Test, TEST
|
||
|
|
||
|
using namespace ftxui;
|
||
|
|
||
|
TEST(StringTest, StringWidth) {
|
||
|
// Basic:
|
||
|
EXPECT_EQ(0, string_width(""));
|
||
|
EXPECT_EQ(1, string_width("a"));
|
||
|
EXPECT_EQ(2, string_width("ab"));
|
||
|
// Fullwidth glyphs:
|
||
|
EXPECT_EQ(2, string_width("测"));
|
||
|
EXPECT_EQ(4, string_width("测试"));
|
||
|
// Combining characters:
|
||
|
EXPECT_EQ(1, string_width("ā"));
|
||
|
EXPECT_EQ(1, string_width("a⃒"));
|
||
|
EXPECT_EQ(1, string_width("a̗"));
|
||
|
// Control characters:
|
||
|
EXPECT_EQ(0, string_width("\1"));
|
||
|
EXPECT_EQ(2, string_width("a\1a"));
|
||
|
}
|
||
|
|
||
|
TEST(StringTest, Utf8ToGlyphs) {
|
||
|
using T = std::vector<std::string>;
|
||
|
// Basic:
|
||
|
EXPECT_EQ(Utf8ToGlyphs(""), T({}));
|
||
|
EXPECT_EQ(Utf8ToGlyphs("a"), T({"a"}));
|
||
|
EXPECT_EQ(Utf8ToGlyphs("ab"), T({"a", "b"}));
|
||
|
// Fullwidth glyphs:
|
||
|
EXPECT_EQ(Utf8ToGlyphs("测"), T({"测", ""}));
|
||
|
EXPECT_EQ(Utf8ToGlyphs("测试"), T({"测", "", "试", ""}));
|
||
|
// Combining characters:
|
||
|
EXPECT_EQ(Utf8ToGlyphs("ā"), T({"ā"}));
|
||
|
EXPECT_EQ(Utf8ToGlyphs("a⃒"), T({"a⃒"}));
|
||
|
EXPECT_EQ(Utf8ToGlyphs("a̗"), T({"a̗"}));
|
||
|
// Control characters:
|
||
|
EXPECT_EQ(Utf8ToGlyphs("\1"), T({}));
|
||
|
EXPECT_EQ(Utf8ToGlyphs("a\1a"), T({"a", "a"}));
|
||
|
}
|
||
|
|
||
|
// 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.
|