1 /* Grapheme cluster length test.
2 Copyright (C) 2010, 2011 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. */
30 ASSERT (u8_grapheme_len ("", 0) == 0);
32 /* Standalone 1-unit graphemes. */
33 ASSERT (u8_grapheme_len ("a", 1) == 1);
34 ASSERT (u8_grapheme_len ("ab", 2) == 1);
35 ASSERT (u8_grapheme_len ("abc", 3) == 1);
37 /* Multi-unit, single code point graphemes. */
38 #define HIRAGANA_A "\343\201\202" /* あ: Hiragana letter 'a'. */
39 ASSERT (u8_grapheme_len (HIRAGANA_A, 3) == 3);
40 ASSERT (u8_grapheme_len (HIRAGANA_A"x", 4) == 3);
41 ASSERT (u8_grapheme_len (HIRAGANA_A HIRAGANA_A, 6) == 3);
43 /* Combining accents. */
44 #define GRAVE "\314\200" /* Combining grave accent. */
45 #define ACUTE "\314\201" /* Combining acute accent. */
46 ASSERT (u8_grapheme_len ("e"ACUTE, 3) == 3);
47 ASSERT (u8_grapheme_len ("e"ACUTE GRAVE, 5) == 5);
48 ASSERT (u8_grapheme_len ("e"ACUTE"x", 4) == 3);
49 ASSERT (u8_grapheme_len ("e"ACUTE "e"ACUTE, 6) == 3);