chiark / gitweb /
Start on 'settings' window. Currently disabled as it's not very
[disorder] / lib / t-words.c
CommitLineData
b90f122b
RK
1/*
2 * This file is part of DisOrder.
3 * Copyright (C) 2005, 2007, 2008 Richard Kettlewell
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 2 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, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18 * USA
19 */
20#include "test.h"
21
22struct {
23 const char *in;
24 const char *expect[10];
25} wtest[] = {
26 /* Empty string */
27 { "", { 0 } },
28 /* Only whitespace and punctuation */
29 { " ", { 0 } },
30 { " ' ", { 0 } },
31 { " ! ", { 0 } },
32 { " \"\" ", { 0 } },
33 { " @ ", { 0 } },
34 /* Basics */
35 { "wibble", { "wibble", 0 } },
36 { " wibble", { "wibble", 0 } },
37 { " wibble ", { "wibble", 0 } },
38 { "wibble ", { "wibble", 0 } },
39 { "wibble spong", { "wibble", "spong", 0 } },
40 { " wibble spong", { "wibble", "spong", 0 } },
41 { " wibble spong ", { "wibble", "spong", 0 } },
42 { "wibble spong ", { "wibble", "spong", 0 } },
43 { "wibble spong splat foo zot ", { "wibble", "spong", "splat", "foo", "zot", 0 } },
44 /* Apostrophes */
45 { "wibble 'spong", { "wibble", "spong", 0 } },
46 { " wibble's", { "wibble's", 0 } },
47 { " wibblespong' ", { "wibblespong", 0 } },
48 { "wibble sp''ong ", { "wibble", "sp", "ong", 0 } },
49};
50#define NWTEST (sizeof wtest / sizeof *wtest)
51
52void test_words(void) {
53 size_t t, nexpect, ngot, i;
54 int right;
55
56 fprintf(stderr, "test_words\n");
57 for(t = 0; t < NWTEST; ++t) {
58 char **got = utf8_word_split(wtest[t].in, strlen(wtest[t].in), &ngot, 0);
59
60 for(nexpect = 0; wtest[t].expect[nexpect]; ++nexpect)
61 ;
62 if(nexpect == ngot) {
63 for(i = 0; i < ngot; ++i)
64 if(strcmp(wtest[t].expect[i], got[i]))
65 break;
66 right = i == ngot;
67 } else
68 right = 0;
69 if(!right) {
70 fprintf(stderr, "word split %zu failed\n", t);
71 fprintf(stderr, "input: %s\n", wtest[t].in);
72 fprintf(stderr, " | %-30s | %-30s\n",
73 "expected", "got");
74 for(i = 0; i < nexpect || i < ngot; ++i) {
75 const char *e = i < nexpect ? wtest[t].expect[i] : "<none>";
76 const char *g = i < ngot ? got[i] : "<none>";
77 fprintf(stderr, " %2zu | %-30s | %-30s\n", i, e, g);
78 }
79 count_error();
80 }
81 ++tests;
82 }
83}
84
85/*
86Local Variables:
87c-basic-offset:2
88comment-column:40
89fill-column:79
90indent-tabs-mode:nil
91End:
92*/