1 /* Word break function test, using test data from UCD.
2 Copyright (C) 2010-2016 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 <http://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;
59 main (int argc, char *argv[])
69 fprintf (stderr, "usage: %s FILENAME\n"
70 "where FILENAME is the location of the WordBreakTest.txt\n"
71 "test file.\n", argv[0]);
76 stream = fopen (filename, "r");
79 fprintf (stderr, "error during fopen of '%s'\n", filename);
85 while (fgets (line, sizeof line, stream))
91 char breaks_expected[101];
96 memset (breaks, 0, sizeof (breaks));
97 memset (breaks_expected, 0, sizeof (breaks_expected));
99 comment = strchr (line, '#');
102 if (line[strspn (line, " \t\r\n")] == '\0')
109 p += strspn (p, " \t\r\n");
110 if (!strncmp (p, "\303\267" /* ÷ */, 2))
112 breaks_expected[i] = 1;
115 else if (!strncmp (p, "\303\227" /* × */, 2))
117 breaks_expected[i] = 0;
122 fprintf (stderr, "%s:%d.%d: syntax error expecting '÷' or '×'\n",
123 filename, lineno, (int) (p - line + 1));
127 p += strspn (p, " \t\r\n");
130 unsigned int next_int;
133 if (sscanf (p, "%x%n", &next_int, &n) != 1)
135 fprintf (stderr, "%s:%d.%d: syntax error at '%s' "
136 "expecting hexadecimal Unicode code point number\n",
137 filename, lineno, (int) (p - line + 1), p);
145 p += strspn (p, " \t\r\n");
150 u32_wordbreaks (input, i - 1, breaks);
152 /* u32_wordbreaks always set BREAKS[0] to 0. */
153 breaks[0] = breaks_expected[0] = 1;
154 if (memcmp (breaks, breaks_expected, i - 1) != 0)
158 fprintf (stderr, "%s:%d: expected: ", filename, lineno);
159 for (j = 0; j < i - 1; j++)
161 int input_wbp = uc_wordbreak_property (input[j]);
162 fprintf (stderr, "%s U+%04X (%s) ",
163 breaks_expected[j] == 1 ? "\303\267" : "\303\227",
164 input[j], wordbreakproperty_to_string (input_wbp));
166 fprintf (stderr, "\n");
167 fprintf (stderr, "%s:%d: actual: ", filename, lineno);
168 for (j = 0; j < i - 1; j++)
170 int input_wbp = uc_wordbreak_property (input[j]);
171 fprintf (stderr, "%s U+%04X (%s) ",
172 breaks[j] == 1 ? "\303\267" : "\303\227",
173 input[j], wordbreakproperty_to_string (input_wbp));
175 fprintf (stderr, "\n");