This source file includes following definitions.
- test_u32_grapheme_next
- 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 <stdarg.h>
26 #include <stdlib.h>
27
28 #include "macros.h"
29
30 static void
31 test_u32_grapheme_next (size_t len, ...)
32 {
33 const uint32_t *next;
34 uint32_t s[32];
35 va_list args;
36 size_t n;
37
38 va_start (args, len);
39 n = 0;
40 for (;;)
41 {
42 int unit = va_arg (args, int);
43 if (unit == -1)
44 break;
45 else if (n >= sizeof s / sizeof *s)
46 abort ();
47
48 s[n++] = unit;
49 }
50 va_end (args);
51
52 next = u32_grapheme_next (s, s + n);
53 if (next != s + len)
54 {
55 size_t i;
56
57 if (next == NULL)
58 fputs ("u32_grapheme_next returned NULL", stderr);
59 else
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]);
64 putc ('\n', stderr);
65 abort ();
66 }
67 }
68
69 int
70 main (void)
71 {
72 static const uint32_t s[] = { 'a', 'b', 'c' };
73
74
75 ASSERT (u32_grapheme_next (NULL, NULL) == NULL);
76 ASSERT (u32_grapheme_next (s, s) == NULL);
77
78
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);
82
83
84 #define HIRAGANA_A 0x3042
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);
88
89
90 #define GRAVE 0x0300
91 #define ACUTE 0x0301
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);
96
97
98 #define NEUTRAL_FACE 0x1f610
99 test_u32_grapheme_next (1, NEUTRAL_FACE, -1);
100 test_u32_grapheme_next (2, NEUTRAL_FACE, GRAVE, -1);
101
102 return 0;
103 }