1 /* Grapheme cluster breaks test.
2 Copyright (C) 2010-2013 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 <http://www.gnu.org/licenses/>. */
17 /* Written by Ben Pfaff <blp@cs.stanford.edu>, 2010. */
31 test_u8_grapheme_breaks (const char *input, const char *expected)
33 const uint8_t *s = (const uint8_t *) input;
34 size_t n = strlen (expected);
41 memset (breaks, 0xcc, n);
43 u8_grapheme_breaks (s, n, breaks);
44 for (i = 0; i < n; i++)
45 if (breaks[i] != (expected[i] == '#'))
49 fprintf (stderr, "wrong grapheme breaks:\n");
51 fprintf (stderr, " input:");
52 for (j = 0; j < n; j++)
53 fprintf (stderr, " %02x", s[j]);
56 fprintf (stderr, "expected:");
57 for (j = 0; j < n; j++)
58 fprintf (stderr, " %d", expected[j] == '#');
61 fprintf (stderr, " actual:");
62 for (j = 0; j < n; j++)
63 fprintf (stderr, " %d", breaks[j]);
75 /* Standalone 1-unit graphemes. */
76 test_u8_grapheme_breaks ("a", "#");
77 test_u8_grapheme_breaks ("ab", "##");
78 test_u8_grapheme_breaks ("abc", "###");
80 /* Multi-unit, single code point graphemes. */
81 #define HIRAGANA_A "\343\201\202" /* あ: Hiragana letter 'a'. */
82 test_u8_grapheme_breaks (HIRAGANA_A, "#__");
83 test_u8_grapheme_breaks (HIRAGANA_A"x", "#__#");
84 test_u8_grapheme_breaks (HIRAGANA_A HIRAGANA_A, "#__#__");
86 /* Combining accents. */
87 #define GRAVE "\314\200" /* Combining grave accent. */
88 #define ACUTE "\314\201" /* Combining acute accent. */
89 test_u8_grapheme_breaks ("e"ACUTE, "#__");
90 test_u8_grapheme_breaks ("e"ACUTE GRAVE, "#____");
91 test_u8_grapheme_breaks ("e"ACUTE"x", "#__#");
92 test_u8_grapheme_breaks ("e"ACUTE "e"ACUTE, "#__#__");