diff options
Diffstat (limited to 'gettext-tools/tests')
-rw-r--r-- | gettext-tools/tests/ChangeLog | 10 | ||||
-rw-r--r-- | gettext-tools/tests/Makefile.am | 9 | ||||
-rw-r--r-- | gettext-tools/tests/sentence.c | 85 | ||||
-rwxr-xr-x | gettext-tools/tests/xgettext-14 | 98 |
4 files changed, 199 insertions, 3 deletions
diff --git a/gettext-tools/tests/ChangeLog b/gettext-tools/tests/ChangeLog index 380b937..1ba2935 100644 --- a/gettext-tools/tests/ChangeLog +++ b/gettext-tools/tests/ChangeLog @@ -1,3 +1,13 @@ +2015-03-03 Daiki Ueno <ueno@gnu.org> + + * xgettext-14: New file. + * sentence.c: New file + * Makefile.am (TESTS): Add new tests. + (noinst_PROGRAMS): Add 'sentence'. + (sentence_SOURCES): New variable. + (sentence_CPPFLAGS): New variable. + (sentence_LDADD): New variable. + 2015-02-06 Daiki Ueno <ueno@gnu.org> tests: Fix "broken pipe" error in msgfilter-7 diff --git a/gettext-tools/tests/Makefile.am b/gettext-tools/tests/Makefile.am index 32bc192..ea8bfa9 100644 --- a/gettext-tools/tests/Makefile.am +++ b/gettext-tools/tests/Makefile.am @@ -72,7 +72,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \ recode-sr-latin-1 recode-sr-latin-2 \ xgettext-2 xgettext-3 xgettext-4 xgettext-5 xgettext-6 \ xgettext-7 xgettext-8 xgettext-9 xgettext-10 xgettext-11 xgettext-12 \ - xgettext-13 \ + xgettext-13 xgettext-14 \ xgettext-awk-1 xgettext-awk-2 \ xgettext-c-2 xgettext-c-3 xgettext-c-4 xgettext-c-5 \ xgettext-c-6 xgettext-c-7 xgettext-c-8 xgettext-c-9 xgettext-c-10 \ @@ -137,7 +137,7 @@ TESTS = gettext-1 gettext-2 gettext-3 gettext-4 gettext-5 gettext-6 gettext-7 \ format-lua-1 format-lua-2 \ format-javascript-1 format-javascript-2 \ plural-1 plural-2 \ - gettextpo-1 \ + gettextpo-1 sentence \ lang-c lang-c++ lang-objc lang-sh lang-bash lang-python-1 \ lang-python-2 lang-clisp lang-elisp lang-librep lang-guile \ lang-smalltalk lang-java lang-csharp lang-gawk lang-pascal \ @@ -211,7 +211,7 @@ DEFS = -DLOCALEDIR=\"$(localedir)\" @DEFS@ LDADD = $(LDADD_@USE_INCLUDED_LIBINTL@) @INTL_MACOSX_LIBS@ LDADD_yes = ../intl/libintl.la @LTLIBTHREAD@ LDADD_no = ../intl/libgnuintl.la @LTLIBTHREAD@ @LTLIBINTL@ -noinst_PROGRAMS = tstgettext tstngettext testlocale gettext-3-prg gettext-4-prg gettext-5-prg gettext-6-prg gettext-7-prg gettext-8-prg cake fc3 fc4 fc5 gettextpo-1-prg +noinst_PROGRAMS = tstgettext tstngettext testlocale gettext-3-prg gettext-4-prg gettext-5-prg gettext-6-prg gettext-7-prg gettext-8-prg cake fc3 fc4 fc5 gettextpo-1-prg sentence tstgettext_SOURCES = tstgettext.c setlocale.c tstgettext_CFLAGS = -DINSTALLDIR=\".\" tstgettext_LDADD = ../gnulib-lib/libgettextlib.la $(LDADD) @@ -255,6 +255,9 @@ gettextpo_1_prg_CPPFLAGS = \ # Don't add more libraries here. This test must check whether libgettextpo is # self contained. gettextpo_1_prg_LDADD = ../libgettextpo/libgettextpo.la $(LDADD) +sentence_SOURCES = sentence.c +sentence_CPPFLAGS = -I../src -I../gnulib-lib +sentence_LDADD = ../src/libgettextsrc.la $(LDADD) # Clean up after Solaris cc. clean-local: diff --git a/gettext-tools/tests/sentence.c b/gettext-tools/tests/sentence.c new file mode 100644 index 0000000..839f6c8 --- /dev/null +++ b/gettext-tools/tests/sentence.c @@ -0,0 +1,85 @@ +/* Test of sentence handling. + Copyright (C) 2015 Free Software Foundation, Inc. + Written by Daiki Ueno <ueno@gnu.org>, 2015. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include "sentence.h" + +#include <assert.h> +#include <string.h> + +#define PRIMARY "This is a primary sentence" +#define SECONDARY "This is a secondary sentence" + +#define SIZEOF(x) (sizeof (x) / sizeof (*x)) + +struct data +{ + int required_spaces; + const char *input; + + const char *expected_prefix; + ucs4_t expected_ending_char; +}; + +const struct data data[] = + { + { 1, PRIMARY, PRIMARY, 0xfffd }, + { 1, PRIMARY ".", PRIMARY, '.' }, + { 1, PRIMARY ".x", PRIMARY ".x", 0xfffd }, + { 2, PRIMARY ". " SECONDARY, PRIMARY, '.' }, + { 1, PRIMARY ". " SECONDARY, PRIMARY, '.' }, + { 1, PRIMARY ".' " SECONDARY, PRIMARY, '.' }, + { 3, PRIMARY ". " SECONDARY, PRIMARY ". " SECONDARY, 0xfffd }, + { 2, PRIMARY ".' " SECONDARY, PRIMARY, '.' }, + { 2, PRIMARY ".'x " SECONDARY, PRIMARY ".'x " SECONDARY, 0xfffd }, + { 2, PRIMARY ".''x " SECONDARY, PRIMARY ".''x " SECONDARY, 0xfffd }, + { 2, PRIMARY ".\n" SECONDARY, PRIMARY, '.' }, + { 2, PRIMARY ". \n" SECONDARY, PRIMARY, '.' }, + { 2, PRIMARY ".\xc2\xa0\n" SECONDARY, PRIMARY, '.' }, + { 2, PRIMARY ".\t" SECONDARY, PRIMARY, '.' }, + { 2, PRIMARY ".'\t" SECONDARY, PRIMARY, '.' }, + { 2, PRIMARY ".'\n" SECONDARY, PRIMARY, '.' } + }; + +static void +check_sentence_end (const struct data *d) +{ + int saved_required_spaces = sentence_end_required_spaces; + const char *result; + ucs4_t ending_char; + + sentence_end_required_spaces = d->required_spaces; + result = sentence_end (d->input, &ending_char); + sentence_end_required_spaces = saved_required_spaces; + + assert (result == d->input + strlen (d->expected_prefix)); + assert (ending_char == d->expected_ending_char); +} + +int +main (int argc, char **argv) +{ + int i; + + for (i = 0; i < SIZEOF (data); i++) + check_sentence_end (&data[i]); + + return 0; +} diff --git a/gettext-tools/tests/xgettext-14 b/gettext-tools/tests/xgettext-14 new file mode 100755 index 0000000..b769b2f --- /dev/null +++ b/gettext-tools/tests/xgettext-14 @@ -0,0 +1,98 @@ +#!/bin/sh +. "${srcdir=.}/init.sh"; path_prepend_ . ../src + +# Test for --check option. + +# --check=ellipsis-unicode +cat <<\EOF > xg-ellipsis-u.c +gettext ("This is a sentence..."); + +ngettext ("This is a sentence", "These are sentences...", 2); + +/* xgettext: no-ellipsis-unicode-check */ +gettext ("This is another sentence..."); + +gettext ("This is a multi-sentence example. This is the first sentence. " + "This is the second..., no it's not, this is the second sentence...\n" + "This is the third sentence...? Perhaps.\n"); +EOF + +: ${XGETTEXT=xgettext} +LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=ellipsis-unicode -d xg-ellipsis-u.tmp xg-ellipsis-u.c 2>xg-ellipsis-u.err + +test `grep -c 'ASCII ellipsis' xg-ellipsis-u.err` = 4 || exit 1 + +LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=ellipsis-unicode --sentence-end=double-space -d xg-ellipsis-ud.tmp xg-ellipsis-u.c 2>xg-ellipsis-ud.err + +test `grep -c 'ASCII ellipsis' xg-ellipsis-ud.err` = 3 || exit 1 + +# --check=space-ellipsis +cat <<\EOF > xg-space-e.c +gettext ("This is a sentence ..."); + +/* xgettext: no-space-ellipsis-check, no-ellipsis-unicode-check */ +gettext ("This is another sentence ..."); + +gettext ("This is a multi-sentence example. This is the first sentence. " + "This is the second..., no it's not, this is the second sentence ...\n" + "This is the third sentence \u2026? Perhaps.\n"); +EOF + +LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=space-ellipsis -d xg-space-e.tmp xg-space-e.c 2>xg-space-e.err + +test `grep -c 'space before ellipsis' xg-space-e.err` = 3 || exit 1 + +# --check=quote-unicode +cat <<\EOF > xg-quote-u.c +gettext ("\"double quoted\""); + +/* xgettext: no-quote-unicode-check */ +gettext ("\"double quoted but ignored\""); + +gettext ("double quoted but empty \"\""); + +gettext ("\"\" double quoted but empty"); + +gettext ("\"foo\" \"bar\" \"baz\""); + +gettext ("'single quoted'"); + +/* xgettext: no-quote-unicode-check */ +gettext ("'single quoted but ignored'"); + +gettext ("'foo' 'bar' 'baz'"); + +gettext ("prefix'single quoted without surrounding spaces'suffix"); + +gettext ("prefix 'single quoted with surrounding spaces' suffix"); + +gettext ("single quoted with apostrophe, empty '' "); + +gettext ("'single quoted at the beginning of string' "); + +gettext (" 'single quoted at the end of string'"); + +gettext ("line 1\n" +"'single quoted at the beginning of line' \n" +"line 3"); + +gettext ("line 1\n" +" 'single quoted at the end of line'\n" +"line 3"); + +gettext ("`single quoted with grave'"); + +/* xgettext: no-quote-unicode-check */ +gettext ("`single quoted with grave but ignored'"); + +gettext ("single quoted with grave, empty `'"); + +gettext ("`' single quoted with grave, empty"); + +gettext ("`double grave`"); +EOF + +LANGUAGE= LC_ALL=C ${XGETTEXT} --omit-header --add-comments --check=quote-unicode -d xg-quote-u.tmp xg-quote-u.c 2>xg-quote-u.err + +test `grep -c 'ASCII double quote' xg-quote-u.err` = 4 || exit 1 +test `grep -c 'ASCII single quote' xg-quote-u.err` = 12 || exit 1 |