17#if defined(SK_UNICODE_ICU_IMPLEMENTATION)
20#if defined(SK_UNICODE_LIBGRAPHEME_IMPLEMENTATION)
23#if defined(SK_UNICODE_ICU4X_IMPLEMENTATION)
26#if defined(SK_UNICODE_CLIENT_IMPLEMENTATION)
32#ifdef SK_UNICODE_ICU_IMPLEMENTATION
33#define DEF_TEST_ICU(name, reporter) \
34 DEF_TEST(name##ICU, reporter) { name(reporter, SkUnicodes::ICU::Make()); }
36#define DEF_TEST_ICU(name, reporter)
39#ifdef SK_UNICODE_ICU4X_IMPLEMENTATION
40#define DEF_TEST_ICU4X(name, reporter) \
41 DEF_TEST(name##ICU4X, reporter) { name(reporter, SkUnicodes::ICU4X::Make()); }
43#define DEF_TEST_ICU4X(name, reporter)
46#ifdef SK_UNICODE_LIBGRAPHEME_IMPLEMENTATION
47#define DEF_TEST_LIBGRAPHEME(name, reporter) \
48 DEF_TEST(name##LIBGRAPHEME, reporter) { name(reporter, SkUnicodes::Libgrapheme::Make()); }
50#define DEF_TEST_LIBGRAPHEME(name, reporter)
53#define DEF_TEST_NOIMPL(name, reporter)
55#define DEF_TEST_UNICODES(name, reporter) \
56 static void name(skiatest::Reporter* reporter, sk_sp<SkUnicode> unicode); \
57 DEF_TEST_ICU(name, reporter) \
58 DEF_TEST_ICU4X(name, reporter) \
59 DEF_TEST_LIBGRAPHEME(name, reporter) \
60 DEF_TEST_NOIMPL(name, reporter) \
61 void name(skiatest::Reporter* reporter, sk_sp<SkUnicode> unicode)
63#define DEF_TEST_ICU_UNICODES(name, reporter) \
64 static void name(skiatest::Reporter* reporter, sk_sp<SkUnicode> unicode); \
65 DEF_TEST_ICU(name, reporter) \
66 DEF_TEST_ICU4X(name, reporter) \
67 DEF_TEST_NOIMPL(name, reporter) \
68 void name(skiatest::Reporter* reporter, sk_sp<SkUnicode> unicode)
72#ifdef SK_UNICODE_CLIENT_IMPLEMENTATION
74 std::u16string
text = u
"\U000f2008";
79 client->computeCodeUnitFlags(
utf8.data(),
utf8.size(),
false, &results);
81 for (
auto flag : results) {
87#if defined(SK_UNICODE_ICU_IMPLEMENTATION)
94 std::u16string
text = u
"\U000f2008";
97 icu->computeCodeUnitFlags(
utf8.data(),
utf8.size(),
false, &results);
98 for (
auto flag : results) {
104#if defined(SK_UNICODE_LIBGRAPHEME_IMPLEMENTATION)
107 std::vector<SkUnicode::Position> expected = { 0, 1, 2, 4, 5, 8, 9, 13, 14, 19, 20, 26, 27, 34 };
109 std::vector<SkUnicode::Position> results;
110 auto result = libgrapheme->getUtf8Words(
text.data(),
text.size(),
"en", &results);
113 for (
auto i = 0ul;
i < results.size(); ++
i) {
119#if defined(SK_UNICODE_ICU_IMPLEMENTATION)
126 SkString text(
"Hello world! Hello world? Hello world... Not a sentence end: 3.1415926");
127 std::vector<SkUnicode::Position> expected = {0, 13, 26, 41, 70};
128 std::vector<SkUnicode::Position> results;
129 auto result = icu->getSentences(
text.data(),
text.size(),
nullptr, &results);
132 for (
auto i = 0ul;
i < results.size(); ++
i) {
148 std::vector<SkUnicode::BidiRegion> results;
156 results[0].
end ==
text.size() &&
157 results[0].level == 0);
164 SkString text(
"الهيمنة على العالم عبارة قبيحة ، أفضل أن أسميها تحسين العالم.");
165 std::vector<SkUnicode::BidiRegion> results;
173 results[0].
end ==
text.size() &&
174 results[0].level == 1);
183 std::vector<SkUnicode::BidiRegion> expected = {
198 std::vector<SkUnicode::BidiRegion> results;
205 for (
auto i = 0ul;
i < results.size(); ++
i) {
207 results[
i].
end == expected[
i].
end &&
217 SkString text(
"World ЛТР Domination هي عبارة قبيحة ، أفضل أن أسميها World ЛТР Optimization.");
218 std::vector<SkUnicode::BidiRegion> expected = {
223 std::vector<SkUnicode::BidiRegion> results;
230 for (
auto i = 0ul;
i < results.size(); ++
i) {
232 results[
i].
end == expected[
i].
end &&
244 SkString upper(
"ABCDEFGHIJKLMNOPQRSTUVWXYZ");
247 auto icu_result2 =
unicode->toUpper(upper);
265 for (
auto i = 0;
i < results.
size(); ++
i) {
267 auto expected = SkUnicode::CodeUnitFlags::kGraphemeStart;
272 expected |= SkUnicode::CodeUnitFlags::kHardLineBreakBefore;
274 if (
i == 1 ||
i == 4 ||
i == 8 ||
i == 13 ||
i == 19 ||
i == 26) {
275 expected |= SkUnicode::CodeUnitFlags::kPartOfWhiteSpaceBreak;
276 expected |= SkUnicode::CodeUnitFlags::kPartOfIntraWordBreak;
278 if (
i == 0 ||
i == 2 ||
i == 5 ||
i == 9 ||
i == 14 ||
i == 20
279 ||
i == 27 ||
i == 34) {
280 expected |= SkUnicode::CodeUnitFlags::kSoftLineBreakBefore;
290 auto reorder = [&](std::vector<SkUnicode::BidiLevel> levels,
291 std::vector<int32_t> expected) {
292 std::vector<int32_t> logicalOrder(levels.size());
293 unicode->reorderVisual(levels.data(), levels.size(), logicalOrder.data());
294 for (
auto i = 0ul;
i < levels.size(); ++
i) {
301 reorder({0, 1, 0, 1}, {0, 1, 2, 3});
305 std::u32string emojis(
U"😄😁😆😅😂🤣");
306 std::u32string not_emojis(
U"満毎行昼本可");
307 for (
auto e : emojis) {
310 for (
auto n: not_emojis) {
315#ifdef SK_UNICODE_ICU_IMPLEMENTATION
326#ifdef SK_UNICODE_ICU4X_IMPLEMENTATION
338 std::u32string ideographic(
U"満毎行昼本可");
339 std::u32string not_ideographic(
U"😄😁😆😅😂🤣");
340 for (
auto i : ideographic) {
343 for (
auto n: not_ideographic) {
348#ifdef SK_UNICODE_ICU_IMPLEMENTATION
359#ifdef SK_UNICODE_ICU4X_IMPLEMENTATION
constexpr int16_t SkToS16(S x)
#define DEF_TEST_ICU_UNICODES(name, reporter)
static void SkUnicode_Emoji(SkUnicode *icu, skiatest::Reporter *reporter)
static void SkUnicode_Ideographic(SkUnicode *icu, skiatest::Reporter *reporter)
bool hasWordFlag(SkUnicode::CodeUnitFlags flags)
#define DEF_TEST_UNICODES(name, reporter)
#define REPORTER_ASSERT(r, cond,...)
virtual bool isIdeographic(SkUnichar utf8)=0
static bool hasPartOfWhiteSpaceBreakFlag(SkUnicode::CodeUnitFlags flags)
static SkString convertUtf16ToUtf8(const char16_t *utf16, int utf16Units)
virtual bool isEmoji(SkUnichar utf8)=0
FlutterSemanticsFlag flag
FlutterSemanticsFlag flags
SKUNICODE_API sk_sp< SkUnicode > Make(SkSpan< char > text, std::vector< SkUnicode::Position > words, std::vector< SkUnicode::Position > graphemeBreaks, std::vector< SkUnicode::LineBreakBefore > lineBreaks)
SKUNICODE_API sk_sp< SkUnicode > Make()
SKUNICODE_API sk_sp< SkUnicode > Make()
SKUNICODE_API sk_sp< SkUnicode > Make()