1 /* Test of sentence handling.
2 Copyright (C) 2015 Free Software Foundation, Inc.
3 Written by Daiki Ueno <ueno@gnu.org>, 2015.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 #define PRIMARY "This is a primary sentence"
28 #define SECONDARY "This is a secondary sentence"
30 #define SIZEOF(x) (sizeof (x) / sizeof (*x))
37 const char *expected_prefix;
38 ucs4_t expected_ending_char;
41 const struct data data[] =
43 { 1, PRIMARY, PRIMARY, 0xfffd },
44 { 1, PRIMARY ".", PRIMARY, '.' },
45 { 1, PRIMARY ".x", PRIMARY ".x", 0xfffd },
46 { 2, PRIMARY ". " SECONDARY, PRIMARY, '.' },
47 { 1, PRIMARY ". " SECONDARY, PRIMARY, '.' },
48 { 1, PRIMARY ".' " SECONDARY, PRIMARY, '.' },
49 { 3, PRIMARY ". " SECONDARY, PRIMARY ". " SECONDARY, 0xfffd },
50 { 2, PRIMARY ".' " SECONDARY, PRIMARY, '.' },
51 { 2, PRIMARY ".'x " SECONDARY, PRIMARY ".'x " SECONDARY, 0xfffd },
52 { 2, PRIMARY ".''x " SECONDARY, PRIMARY ".''x " SECONDARY, 0xfffd },
53 { 2, PRIMARY ".\n" SECONDARY, PRIMARY, '.' },
54 { 2, PRIMARY ". \n" SECONDARY, PRIMARY, '.' },
55 { 2, PRIMARY ".\xc2\xa0\n" SECONDARY, PRIMARY, '.' },
56 { 2, PRIMARY ".\t" SECONDARY, PRIMARY, '.' },
57 { 2, PRIMARY ".'\t" SECONDARY, PRIMARY, '.' },
58 { 2, PRIMARY ".'\n" SECONDARY, PRIMARY, '.' }
62 check_sentence_end (const struct data *d)
64 int saved_required_spaces = sentence_end_required_spaces;
68 sentence_end_required_spaces = d->required_spaces;
69 result = sentence_end (d->input, &ending_char);
70 sentence_end_required_spaces = saved_required_spaces;
72 assert (result == d->input + strlen (d->expected_prefix));
73 assert (ending_char == d->expected_ending_char);
77 main (int argc, char **argv)
81 for (i = 0; i < SIZEOF (data); i++)
82 check_sentence_end (&data[i]);