FTXUI/src/ftxui/screen/string_test.cpp

48 lines
1.6 KiB
C++
Raw Normal View History

#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(""));
// 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(""), T({""}));
// 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.