Debian Codegraph @

eutils/eutils_test.go

raw
1 package eutils
2
3 import "testing"
4
5 type stringTable struct {
6 input string
7 expected string
8 }
9
10 func stringTestMatch(t *testing.T, name string, proc func(str string) string, data []stringTable) {
11
12 for _, test := range data {
13 actual := proc(test.input)
14 if actual != test.expected {
15 t.Errorf("%s(%s) = %s, expected %s", name, test.input, actual, test.expected)
16 }
17 }
18 }
19
20 func policyTestMatch(t *testing.T, name string, proc func(str string, policy int) string, data []stringTable) {
21
22 for _, test := range data {
23 actual := proc(test.input, NOMARKUP)
24 if actual != test.expected {
25 t.Errorf("%s(%s) = %s, expected %s", name, test.input, actual, test.expected)
26 }
27 }
28 }
29
30 func spaceTestMatch(t *testing.T, name string, proc func(str string, policy int) string, data []stringTable) {
31
32 for _, test := range data {
33 actual := proc(test.input, SPACE)
34 if actual != test.expected {
35 t.Errorf("%s(%s) = %s, expected %s", name, test.input, actual, test.expected)
36 }
37 }
38 }
39
40 func TestCleanupAuthor(t *testing.T) {
41
42 stringTestMatch(t, "CleanupAuthor,",
43 func(str string) string { return CleanupAuthor(str, false) },
44 []stringTable{
45 {"Savel'ev", "Savel'ev"},
46 {"O'Mullane", "O'Mullane"},
47 {"Rählmann Köhler Sebastião", "Rahlmann Kohler Sebastiao"},
48 {"Jolín Høglend Çağıl Ertuğrul", "Jolin Hoglend Cagil Ertugrul"},
49 })
50 }
51
52 func TestCleanupBadSpaces(t *testing.T) {
53
54 stringTestMatch(t, "CleanupBadSpaces,",
55 CleanupBadSpaces,
56 []stringTable{
57 {"nonbreaking space", "nonbreaking space"},
58 })
59 }
60
61 func TestCleanupEncodedMarkup(t *testing.T) {
62
63 stringTestMatch(t, "CleanupEncodedMarkup,",
64 CleanupEncodedMarkup,
65 []stringTable{
66 {"&lt;sup&gt;", "<sup>"},
67 {"&amp;#181;", "&#181;"},
68 {"&amp;amp;amp;amp;amp;amp;amp;lt;", "&lt;"},
69 {"CO</sub><sub>2", "CO2"},
70 })
71 }
72
73 func TestCleanupSimple(t *testing.T) {
74
75 stringTestMatch(t, "CleanupSimple,",
76 func(str string) string { return CleanupSimple(str, false) },
77 []stringTable{
78 {"lycopene β-cyclase", "lycopene beta-cyclase"},
79 {"kinase cβ", "kinase cbeta"},
80 {"NF-κB", "NF-kappaB"},
81 {"Fbw7β", "Fbw7beta"},
82 {"Behçet disease", "Behcet disease"},
83 {"Montréal", "Montreal"},
84 {"à la santé", "a la sante"},
85 {"Möbius", "Mobius"},
86 {"(32-35 °C)", "(32-35 degrees C)"},
87 {"FRAX ™ tool", "FRAX (tm) tool"},
88 {"ColoSure™ test", "ColoSure (tm) test"},
89 {"Ciklavit®.", "Ciklavit (reg) ."},
90 {"Privigen(®)", "Privigen((reg))"},
91 {"(Tevagrastim®)", "(Tevagrastim (reg))"},
92 {"D&lt;sub&gt;2&lt;/sub&gt;-like", "D2-like"},
93 {"&lt;i&gt;DAPHNE GENKWA&lt;/i&gt;", "DAPHNE GENKWA"},
94 })
95 }
96
97 func TestCompressRunsOfSpaces(t *testing.T) {
98
99 stringTestMatch(t, "CompressRunsOfSpaces,",
100 CompressRunsOfSpaces,
101 []stringTable{
102 {"double spaces", "double spaces"},
103 })
104 }
105
106 func TestConvertSlash(t *testing.T) {
107
108 stringTestMatch(t, "ConvertSlash,",
109 ConvertSlash,
110 []stringTable{
111 {"first\\tsecond\\n", "first\tsecond\n"},
112 })
113 }
114
115 func TestDoTrimFlankingHTML(t *testing.T) {
116
117 stringTestMatch(t, "DoTrimFlankingHTML,",
118 DoTrimFlankingHTML,
119 []stringTable{
120 {"</i>Escherichia coli<i>", "Escherichia coli"},
121 })
122 }
123
124 func TestFixSpecialCases(t *testing.T) {
125
126 stringTestMatch(t, "FixSpecialCases,",
127 FixSpecialCases,
128 []stringTable{
129 {"5'ATGTGA", "5_prime ATGTGA"},
130 })
131 }
132
133 func TestGenBankToMedlineAuthors(t *testing.T) {
134
135 stringTestMatch(t, "GenBankToMedlineAuthors,",
136 GenBankToMedlineAuthors,
137 []stringTable{
138 {"Smith-Jones,J.-P.", "Smith-Jones JP"},
139 })
140 }
141
142 func TestNcbi2naToIupac(t *testing.T) {
143
144 stringTestMatch(t, "Ncbi2naToIupac,",
145 Ncbi2naToIupac,
146 []stringTable{
147 {"6BE7EAFF30", "CGGTTGCTTGGGTTTTATAA"},
148 })
149 }
150
151 func TestNcbi4naToIupac(t *testing.T) {
152
153 stringTestMatch(t, "Ncbi4naToIupac,",
154 Ncbi4naToIupac,
155 []stringTable{
156 {"4418845814", "GGATTGRTAG"},
157 })
158 }
159
160 func TestNormalizeAuthor(t *testing.T) {
161
162 stringTestMatch(t, "NormalizeAuthor,",
163 NormalizeAuthor,
164 []stringTable{
165 {"Smith, PA", "Smith P"},
166 })
167 }
168
169 func TestNormalizeJournal(t *testing.T) {
170
171 stringTestMatch(t, "NormalizeJournal,",
172 NormalizeJournal,
173 []stringTable{
174 {"Proc. natl. acad sci", "Proc Natl Acad Sci"},
175 {"PNAS", "PNAS"},
176 {"PLoS Biol", "PLoS Biol"},
177 {"journal of immunology", "Journal of Immunology"},
178 })
179 }
180
181 func TestNormalizePage(t *testing.T) {
182
183 stringTestMatch(t, "NormalizePage,",
184 NormalizePage,
185 []stringTable{
186 {"1904-14", "1904"},
187 })
188 }
189
190 func TestNormalizeTitle(t *testing.T) {
191
192 stringTestMatch(t, "NormalizeTitle,",
193 NormalizeTitle,
194 []stringTable{
195 {"17β-estradiol", "17 beta -estradiol"},
196 {"Charité Humboldt", "Charite Humboldt"},
197 })
198 }
199
200 func TestRelaxString(t *testing.T) {
201
202 stringTestMatch(t, "RelaxString,",
203 RelaxString,
204 []stringTable{
205 {"amber (UAG) codon", "amber UAG codon"},
206 })
207 }
208
209 func TestRemoveEmbeddedMarkup(t *testing.T) {
210
211 policyTestMatch(t, "RemoveEmbeddedMarkup,",
212 RemoveEmbeddedMarkup,
213 []stringTable{
214 {"using <i>Escherichia coli</i> bacteria", "using Escherichia coli bacteria"},
215 {"sulfuric H<sub>2</sub>SO<sub>4</sub> formula", "sulfuric H2SO4 formula"},
216 })
217
218 spaceTestMatch(t, "RemoveEmbeddedMarkup,",
219 RemoveEmbeddedMarkup,
220 []stringTable{
221 {"emission E<sub>direct</sub> spectrum", "emission E direct spectrum"},
222 {"tritiated CO<sub>2</sub><sup>3</sup>H carboxyl", "tritiated CO2 3H carboxyl"},
223 })
224 }
225
226 func TestRemoveCommaOrSemicolon(t *testing.T) {
227
228 stringTestMatch(t, "RemoveCommaOrSemicolon,",
229 RemoveCommaOrSemicolon,
230 []stringTable{
231 {"Hello, world", "hello world"},
232 })
233 }
234
235 func TestRemoveExtraSpaces(t *testing.T) {
236
237 stringTestMatch(t, "RemoveExtraSpaces,",
238 RemoveExtraSpaces,
239 []stringTable{
240 {"( south , east, north- west )", "(south, east, north-west)"},
241 })
242 }
243
244 func TestRemoveHTMLDecorations(t *testing.T) {
245
246 stringTestMatch(t, "RemoveHTMLDecorations,",
247 RemoveHTMLDecorations,
248 []stringTable{
249 {"&lt;b&gt;", ""},
250 {"&#181;", "µ"},
251 {"&#x3C;", "<"},
252 {"R&#xe9;animation", "Réanimation"},
253 })
254 }
255
256 func TestSortStringByWords(t *testing.T) {
257
258 stringTestMatch(t, "SortStringByWords",
259 SortStringByWords,
260 []stringTable{
261 {"now is the time for all good men", "all for good is men now the time"},
262 {"one two three", "one three two"},
263 })
264 }
265
266 func TestTightenParentheses(t *testing.T) {
267
268 stringTestMatch(t, "TightenParentheses,",
269 TightenParentheses,
270 []stringTable{
271 {" ( before after ) ", " (before after) "},
272 })
273 }
274
275 func TestTransformAccents(t *testing.T) {
276
277 stringTestMatch(t, "TransformAccents,",
278 func(str string) string { return TransformAccents(str, true, false) },
279 []stringTable{
280 {"ván", "van"},
281 {"nüt", "nut"},
282 {"těc", "tec"},
283 {"β-c", "beta-c"},
284 {"8 > 5", "8 > 5"},
285 {"8 &gt; 5", "8 &gt; 5"},
286 })
287
288 stringTestMatch(t, "TransformAccents,",
289 func(str string) string { return TransformAccents(str, false, false) },
290 []stringTable{
291 {"β-c", " beta -c"},
292 })
293
294 stringTestMatch(t, "TransformAccents,",
295 func(str string) string { return TransformAccents(str, true, true) },
296 []stringTable{
297 {"8 > 5", "8 &gt; 5"},
298 {"8 &gt; 5", "8 &amp;gt; 5"},
299 })
300 }
301
302 func TestUnicodeToASCII(t *testing.T) {
303
304 stringTestMatch(t, "UnicodeToASCII,",
305 UnicodeToASCII,
306 []stringTable{
307 {"µ", "&#xB5;"},
308 })
309 }
310
311 /*
312 func TestCleanCombiningAccents(t *testing.T) {
313
314 type table struct {
315 input string
316 expected string
317 }
318
319 combining := []table{
320 {"R&#xe9;animation", "Reanimation"},
321 }
322
323 for _, test := range combining {
324 actual := CleanCombiningAccent(test.input)
325 if actual != test.expected {
326 t.Errorf("TransformAccents(%s) = %s, expected %s", test.input, actual, test.expected)
327 }
328 }
329 }
330 */