This source file includes following definitions.
- graphemebreakproperty_to_string
- test_uc_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 const char *
31 graphemebreakproperty_to_string (int gbp)
32 {
33 printf ("%d\n", gbp);
34 switch (gbp)
35 {
36 #define CASE(VALUE) case GBP_##VALUE: return #VALUE;
37 CASE(OTHER)
38 CASE(CR)
39 CASE(LF)
40 CASE(CONTROL)
41 CASE(EXTEND)
42 CASE(PREPEND)
43 CASE(SPACINGMARK)
44 CASE(L)
45 CASE(V)
46 CASE(T)
47 CASE(LV)
48 CASE(LVT)
49 CASE(RI)
50 CASE(ZWJ)
51 CASE(EB)
52 CASE(EM)
53 CASE(GAZ)
54 CASE(EBG)
55 }
56 abort ();
57 }
58
59 static void
60 test_uc_grapheme_breaks (const char *expected, ucs4_t *s, size_t n,
61 const char *filename, int lineno)
62 {
63 char breaks[16];
64 size_t i;
65
66 ASSERT (n <= 16);
67
68 uc_grapheme_breaks (s, n, breaks);
69 for (i = 0; i < n; i++)
70 if (breaks[i] != (expected[i] == '#'))
71 {
72 size_t j;
73
74 fprintf (stderr, "wrong grapheme breaks:\n");
75
76 fprintf (stderr, " input:");
77 for (j = 0; j < n; j++)
78 fprintf (stderr, " %02x", s[j]);
79 putc ('\n', stderr);
80
81 fprintf (stderr, "expected:");
82 for (j = 0; j < n; j++)
83 fprintf (stderr, " %d", expected[j] == '#');
84 putc ('\n', stderr);
85
86 fprintf (stderr, " actual:");
87 for (j = 0; j < n; j++)
88 fprintf (stderr, " %d", breaks[j]);
89 putc ('\n', stderr);
90
91 abort ();
92 }
93 }
94
95 int
96 main (int argc, char *argv[])
97 {
98 const char *filename;
99 char line[1024];
100 int exit_code;
101 FILE *stream;
102 int lineno;
103
104 if (argc != 2)
105 {
106 fprintf (stderr, "usage: %s FILENAME\n"
107 "where FILENAME is the location of the GraphemeBreakTest.txt\n"
108 "test file.\n", argv[0]);
109 exit (1);
110 }
111
112 filename = argv[1];
113 stream = fopen (filename, "r");
114 if (stream == NULL)
115 {
116 fprintf (stderr, "error during fopen of '%s'\n", filename);
117 exit (1);
118 }
119
120 exit_code = 0;
121 lineno = 0;
122 while (fgets (line, sizeof line, stream))
123 {
124 char *comment;
125 const char *p;
126 ucs4_t s[16];
127 char breaks[16];
128 size_t i = 0;
129
130 lineno++;
131
132 comment = strchr (line, '#');
133 if (comment != NULL)
134 *comment = '\0';
135 if (line[strspn (line, " \t\r\n")] == '\0')
136 continue;
137
138 s[0] = 0;
139 p = line;
140 do
141 {
142 p += strspn (p, " \t\r\n");
143 if (!strncmp (p, "\303\267" , 2))
144 {
145 breaks[i] = '#';
146 p += 2;
147 }
148 else if (!strncmp (p, "\303\227" , 2))
149 {
150 breaks[i] = '_';
151 p += 2;
152 }
153 else
154 {
155 fprintf (stderr, "%s:%d.%d: syntax error expecting '÷' or '×'\n",
156 filename, lineno, (int) (p - line + 1));
157 exit (1);
158 }
159
160 p += strspn (p, " \t\r\n");
161 if (*p == '\0')
162 s[i] = 0;
163 else
164 {
165 unsigned int next_int;
166 int n;
167
168 if (sscanf (p, "%x%n", &next_int, &n) != 1)
169 {
170 fprintf (stderr, "%s:%d.%d: syntax error at '%s' "
171 "expecting hexadecimal Unicode code point number\n",
172 filename, lineno, (int) (p - line + 1), p);
173 exit (1);
174 }
175 p += n;
176
177 s[i] = next_int;
178 }
179 p += strspn (p, " \t\r\n");
180 i++;
181 }
182 while (*p != '\0');
183
184 if (i > 0)
185 test_uc_grapheme_breaks (breaks, s, i, filename, lineno);
186 }
187
188 return exit_code;
189 }