1 /* Next grapheme cluster length test.
2 Copyright (C) 2010-2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify it
5 under the terms of the GNU Lesser General Public License as published
6 by the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Ben Pfaff <blp@cs.stanford.edu>, 2010. */
31 test_u32_grapheme_next (size_t len
, ...)
42 int unit
= va_arg (args
, int);
45 else if (n
>= sizeof s
/ sizeof *s
)
52 next
= u32_grapheme_next (s
, s
+ n
);
58 fputs ("u32_grapheme_next returned NULL", stderr
);
60 fprintf (stderr
, "u32_grapheme_next skipped %zu units", next
- s
);
61 fprintf (stderr
, ", expected %zu:\n", len
);
62 for (i
= 0; i
< n
; i
++)
63 fprintf (stderr
, " %04x", s
[i
]);
72 static const uint32_t s
[] = { 'a', 'b', 'c' };
75 ASSERT (u32_grapheme_next (NULL
, NULL
) == NULL
);
76 ASSERT (u32_grapheme_next (s
, s
) == NULL
);
78 /* Standalone 1-unit graphemes. */
79 test_u32_grapheme_next (1, 'a', -1);
80 test_u32_grapheme_next (1, 'a', 'b', -1);
81 test_u32_grapheme_next (1, 'a', 'b', 'c', -1);
83 /* Multi-unit, single code point graphemes. */
84 #define HIRAGANA_A 0x3042 /* あ: Hiragana letter 'a'. */
85 test_u32_grapheme_next (1, HIRAGANA_A
, -1);
86 test_u32_grapheme_next (1, HIRAGANA_A
, 'x', -1);
87 test_u32_grapheme_next (1, HIRAGANA_A
, HIRAGANA_A
, -1);
89 /* Combining accents. */
90 #define GRAVE 0x0300 /* Combining grave accent. */
91 #define ACUTE 0x0301 /* Combining acute accent. */
92 test_u32_grapheme_next (2, 'e', ACUTE
, -1);
93 test_u32_grapheme_next (3, 'e', ACUTE
, GRAVE
, -1);
94 test_u32_grapheme_next (2, 'e', ACUTE
, 'x', -1);
95 test_u32_grapheme_next (2, 'e', ACUTE
, 'e', ACUTE
, -1);
98 #define NEUTRAL_FACE 0x1f610 /* 😐: neutral face. */
99 test_u32_grapheme_next (1, NEUTRAL_FACE
, -1);
100 test_u32_grapheme_next (2, NEUTRAL_FACE
, GRAVE
, -1);