Imported Upstream version 0.19.7
[platform/upstream/gettext.git] / gettext-tools / tests / sentence.c
1 /* Test of sentence handling.
2    Copyright (C) 2015 Free Software Foundation, Inc.
3    Written by Daiki Ueno <ueno@gnu.org>, 2015.
4
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.
9
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.
14
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/>.  */
17
18 #ifdef HAVE_CONFIG_H
19 #include <config.h>
20 #endif
21
22 #include "sentence.h"
23
24 #include <assert.h>
25 #include <string.h>
26
27 #define PRIMARY "This is a primary sentence"
28 #define SECONDARY "This is a secondary sentence"
29
30 #define SIZEOF(x) (sizeof (x) / sizeof (*x))
31
32 struct data
33 {
34   int required_spaces;
35   const char *input;
36
37   const char *expected_prefix;
38   ucs4_t expected_ending_char;
39 };
40
41 const struct data data[] =
42   {
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, '.' }
59   };
60
61 static void
62 check_sentence_end (const struct data *d)
63 {
64   int saved_required_spaces = sentence_end_required_spaces;
65   const char *result;
66   ucs4_t ending_char;
67
68   sentence_end_required_spaces = d->required_spaces;
69   result = sentence_end (d->input, &ending_char);
70   sentence_end_required_spaces = saved_required_spaces;
71
72   assert (result == d->input + strlen (d->expected_prefix));
73   assert (ending_char == d->expected_ending_char);
74 }
75
76 int
77 main (int argc, char **argv)
78 {
79   int i;
80
81   for (i = 0; i < SIZEOF (data); i++)
82     check_sentence_end (&data[i]);
83
84   return 0;
85 }