unigbrk: New modules for grapheme clusters.
[gnulib.git] / tests / unigbrk / test-u8-grapheme-len.c
1 /* Grapheme cluster length test.
2    Copyright (C) 2010, 2011 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>.  */
16
17 /* Written by Ben Pfaff <blp@cs.stanford.edu>, 2010. */
18
19 #include <config.h>
20
21 /* Specification. */
22 #include <unigbrk.h>
23
24 #include "macros.h"
25
26 int
27 main (void)
28 {
29   /* Empty string. */
30   ASSERT (u8_grapheme_len ("", 0) == 0);
31
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);
36
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);
42
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);
50
51   return 0;
52 }