1 /* Word break function test, using test data from UCD.
2 Copyright (C) 2010-2025 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 <https://www.gnu.org/licenses/>. */
17 /* Written by Daiki Ueno <ueno@gnu.org>, 2014.
19 Largely based on unigbrk/test-uc-is-grapheme-break.c,
20 written by Ben Pfaff <blp@cs.stanford.edu>, 2010. */
32 wordbreakproperty_to_string (int wbp
)
36 #define CASE(VALUE) case WBP_##VALUE: return #VALUE;
65 main (int argc
, char *argv
[])
75 fprintf (stderr
, "usage: %s FILENAME\n"
76 "where FILENAME is the location of the WordBreakTest.txt\n"
77 "test file.\n", argv
[0]);
82 stream
= fopen (filename
, "r");
85 fprintf (stderr
, "error during fopen of '%s'\n", filename
);
91 while (fgets (line
, sizeof (line
), stream
))
95 /* Cut off the trailing comment, if any. */
96 char *comment
= strchr (line
, '#');
99 /* Is the remaining line blank? */
100 if (line
[strspn (line
, " \t\r\n")] == '\0')
106 char breaks_expected
[101];
113 p
+= strspn (p
, " \t\r\n");
114 if (!strncmp (p
, "\303\267" /* ÷ */, 2))
116 breaks_expected
[i
] = 1;
119 else if (!strncmp (p
, "\303\227" /* × */, 2))
121 breaks_expected
[i
] = 0;
126 fprintf (stderr
, "%s:%d.%d: syntax error expecting '÷' or '×'\n",
127 filename
, lineno
, (int) (p
- line
+ 1));
131 p
+= strspn (p
, " \t\r\n");
134 unsigned int next_int
;
137 if (sscanf (p
, "%x%n", &next_int
, &n
) != 1)
139 fprintf (stderr
, "%s:%d.%d: syntax error at '%s' "
140 "expecting hexadecimal Unicode code point number\n",
141 filename
, lineno
, (int) (p
- line
+ 1), p
);
149 p
+= strspn (p
, " \t\r\n");
154 u32_wordbreaks (input
, i
- 1, breaks
);
156 /* u32_wordbreaks always set BREAKS[0] to 0. */
157 breaks
[0] = breaks_expected
[0] = 1;
158 if (memcmp (breaks
, breaks_expected
, i
- 1) != 0)
162 fprintf (stderr
, "%s:%d: expected: ", filename
, lineno
);
163 for (j
= 0; j
< i
- 1; j
++)
165 int input_wbp
= uc_wordbreak_property (input
[j
]);
166 fprintf (stderr
, "%s U+%04X (%s) ",
167 breaks_expected
[j
] == 1 ? "\303\267" : "\303\227",
168 input
[j
], wordbreakproperty_to_string (input_wbp
));
170 fprintf (stderr
, "\n");
171 fprintf (stderr
, "%s:%d: actual: ", filename
, lineno
);
172 for (j
= 0; j
< i
- 1; j
++)
174 int input_wbp
= uc_wordbreak_property (input
[j
]);
175 fprintf (stderr
, "%s U+%04X (%s) ",
176 breaks
[j
] == 1 ? "\303\267" : "\303\227",
177 input
[j
], wordbreakproperty_to_string (input_wbp
));
179 fprintf (stderr
, "\n");