squash_space.c
6.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/* liblouis Braille Translation and Back-Translation Library
Copyright (C) 2012 Swiss Library for the Blind, Visually Impaired and Print Disabled
Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved. This file is offered as-is,
without any warranty. */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "liblouis.h"
#include "brl_checks.h"
int main(int argc, char **argv)
{
int i;
int result = 0;
const char *tests[] = {
/* first column is the text, the second is the expected value */
" ", " ",
/* the usual case */
" ", " ",
/* a very long string */
" " \
" " \
" " \
" " \
" " \
" ", " ",
/* an even longer string */
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" ", " ",
/* a string containing tabs */
" \t", " \t",
" \t ", " \t ",
"\t ", "\t ",
/* Strings containing newlines */
" \n", " \n",
" \n ", " \n ",
"\n ", "\n "
};
/* A number of strings that we want to squash, i.e. they should all
result in an output of one space */
const char *strings[] = {
/* a simple space */
" ",
/* a long string */
" ",
/* a very long string */
" " \
" " \
" " \
" " \
" " \
" ",
/* an even longer string */
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" " \
" ",
/* a couple of strings containing tabs */
" \t",
" \t ",
"\t ",
/* Strings containing newlines */
" \n",
" \n ",
"\n ",
/* All mixed */
" \n \t \n \t\t \n\n\n\t\t ",
};
const char *expected = " ";
int tests_len = sizeof(tests)/sizeof(char*);
for (i = 0; i < tests_len; i += 2)
result |= check_translation("squash_space_with_repeated.utb", tests[i], NULL, tests[i+1]);
tests_len = sizeof(strings)/sizeof(char*);
for (i = 0; i < tests_len; i++)
result |= check_translation("squash_space_with_correct.utb", strings[i], NULL, expected);
for (i = 0; i < tests_len; i++)
result |= check_translation("squash_space_with_context_1.utb", strings[i], NULL, expected);
for (i = 0; i < tests_len; i++)
result |= check_translation("squash_space_with_context_2.utb", strings[i], NULL, expected);
lou_free();
return result;
}