This repository has been archived by the owner on Nov 29, 2018. It is now read-only.
/
string_test.go
137 lines (114 loc) · 3.38 KB
/
string_test.go
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
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2016-2018 Shulhan <ms@kilabit.info>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tekstus_test
import (
"github.com/shuLhan/tekstus"
"testing"
)
var dataStringTrimNonAlnum = []struct {
text string
exp string
}{
{"[[alpha]]", "alpha"},
{"[[alpha", "alpha"},
{"alpha]]", "alpha"},
{"alpha", "alpha"},
{"alpha0", "alpha0"},
{"1alpha", "1alpha"},
{"1alpha0", "1alpha0"},
{"[][][]", ""},
}
func TestStringTrimNonAlnum(t *testing.T) {
for _, td := range dataStringTrimNonAlnum {
got := tekstus.StringTrimNonAlnum(td.text)
assert(t, td.exp, got, true)
}
}
var dataStringSplitWords = []struct {
text string
exp []string
}{
{
dataLines[0],
[]string{"Copyright", "2016-2018", "Shulhan",
"ms@kilabit.info", "All", "rights", "reserved"},
},
{
dataLines[4],
[]string{"The", "United", "States", "has", "regularly",
"voted", "alone", "and", "against", "international",
"consensus", "using", "its", "Nations", "Security",
"Council", "veto", "power|veto", "power", "to",
"block", "adoption", "of", "proposed", "UN",
"resolutions", "supporting", "PLO", "calling",
"for", "a", "two-state", "solution",
"Israeli-Palestinian", "conflict",
},
},
}
func TestStringSplitWords(t *testing.T) {
for _, td := range dataStringSplitWords {
got := tekstus.StringSplitWords(td.text, true, true)
assert(t, td.exp, got, true)
}
}
var dataStringRemoveURI = []struct {
text string
exp string
}{
{
dataLines[3],
" The [[United States]] has regularly voted alone and against international consensus, using its [[United Nations Security Council veto power|veto power]] to block the adoption of proposed UN Security Council resolutions supporting the [[PLO]] and calling for a two-state solution to the [[Israeli-Palestinian conflict]].<ref>[ Pirates and emperors, old and new: international terrorism in the real world], [[Noam Chomsky]], p. 168.</ref><ref>The US has also used its veto to block resolutions that are critical of Israel.[ Uneasy neighbors], David T. Jones and David Kilgour, p. 235.</ref> The United States responded to the frequent criticism from UN organs by adopting the [[Negroponte doctrine]].",
},
}
func TestStringRemoveURI(t *testing.T) {
for _, td := range dataStringRemoveURI {
got := tekstus.StringRemoveURI(td.text)
assert(t, td.exp, got, true)
}
}
var dataStringMergeSpaces = []struct {
text string
exp string
}{
{
dataLines[5],
" a b c d ",
},
{
dataLines[6],
" a\nb c d\n",
},
}
func TestStringMergeSpaces(t *testing.T) {
for _, td := range dataStringMergeSpaces {
got := tekstus.StringMergeSpaces(td.text, true)
assert(t, td.exp, got, true)
}
}
var dataStringRemoveWikiMarkup = []struct {
text string
exp string
}{
{
dataLines[7],
`==External links==
*[http://www.bigfinish.com/24-Doctor-Who-The-Eye-of-the-Scorpion Big Finish Productions - ''The Eye of the Scorpion'']
*{{Doctor Who RG | id=who_bf24 | title=The Eye of the Scorpion}}
===Reviews===
* Test image .
* Test file .
*{{OG review | id=bf-24 | title=The Eye of the Scorpion}}
*{{DWRG | id=eyes | title=The Eye of the Scorpion}}
<br clear="all">
{{Fifthdoctoraudios}}
{{DoctorWho-stub}}`,
},
}
func TestStringRemoveWikiMarkup(t *testing.T) {
for _, td := range dataStringRemoveWikiMarkup {
got := tekstus.StringRemoveWikiMarkup(td.text)
assert(t, td.exp, got, true)
}
}