This source file includes following definitions.
- test_u8_grapheme_breaks
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <config.h>
20
21
22 #include <unigbrk.h>
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27
28 #include "macros.h"
29
30 static void
31 test_u8_grapheme_breaks (const char *input, const char *expected)
32 {
33 const uint8_t *s = (const uint8_t *) input;
34 size_t n = strlen (expected);
35 char *breaks;
36 size_t i;
37
38 breaks = malloc (n);
39 if (!breaks)
40 abort ();
41 memset (breaks, 0xcc, n);
42
43 u8_grapheme_breaks (s, n, breaks);
44 for (i = 0; i < n; i++)
45 if (breaks[i] != (expected[i] == '#'))
46 {
47 size_t j;
48
49 fprintf (stderr, "wrong grapheme breaks:\n");
50
51 fprintf (stderr, " input:");
52 for (j = 0; j < n; j++)
53 fprintf (stderr, " %02x", s[j]);
54 putc ('\n', stderr);
55
56 fprintf (stderr, "expected:");
57 for (j = 0; j < n; j++)
58 fprintf (stderr, " %d", expected[j] == '#');
59 putc ('\n', stderr);
60
61 fprintf (stderr, " actual:");
62 for (j = 0; j < n; j++)
63 fprintf (stderr, " %d", breaks[j]);
64 putc ('\n', stderr);
65
66 abort ();
67 }
68
69 free (breaks);
70 }
71
72 int
73 main (void)
74 {
75
76 test_u8_grapheme_breaks ("a", "#");
77 test_u8_grapheme_breaks ("ab", "##");
78 test_u8_grapheme_breaks ("abc", "###");
79
80
81 #define HIRAGANA_A "\343\201\202"
82 test_u8_grapheme_breaks (HIRAGANA_A, "#__");
83 test_u8_grapheme_breaks (HIRAGANA_A"x", "#__#");
84 test_u8_grapheme_breaks (HIRAGANA_A HIRAGANA_A, "#__#__");
85
86
87 #define GRAVE "\314\200"
88 #define ACUTE "\314\201"
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, "#__#__");
93
94 return 0;
95 }