-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
66 lines (50 loc) · 2.7 KB
/
main_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
package main
import (
"testing"
)
var testSentence = `This is a test sentence of go-alfred-sentence-splitter. Unittest is very im-
portant for software. It is not only testing system, but the easiest way (1, 2). So if you write code,
you sholud write unittest too. CI (Continuous Integration) is important too. Both systems will save
your codes' quality. written by Pudding`
var expectedNewlineRemoved = `This is a test sentence of go-alfred-sentence-splitter. Unittest is very im- portant for software. It is not only testing system, but the easiest way (1, 2). So if you write code, you sholud write unittest too. CI (Continuous Integration) is important too. Both systems will save your codes' quality. written by Pudding`
var expectedHyphenRemoved = `This is a test sentence of go-alfred-sentence-splitter. Unittest is very important for software. It is not only testing system, but the easiest way (1, 2). So if you write code,
you sholud write unittest too. CI (Continuous Integration) is important too. Both systems will save
your codes' quality. written by Pudding`
var expectedWhitespaceRemoved = `This is a test sentence of go-alfred-sentence-splitter. Unittest is very im-
portant for software. It is not only testing system, but the easiest way (1, 2). So if you write code,
you sholud write unittest too. CI (Continuous Integration) is important too. Both systems will save
your codes' quality. written by Pudding`
var expectedSplit = `This is a test sentence of go-alfred-sentence-splitter.
Unittest is very im- portant for software.
It is not only testing system, but the easiest way (1, 2).
So if you write code, you sholud write unittest too.
CI (Continuous Integration) is important too.
Both systems will save your codes' quality. written by Pudding`
func TestRemoveNewLine(t *testing.T) {
result := removeNewLine(testSentence)
if result != expectedNewlineRemoved {
outputError("removeNewLine", expectedNewlineRemoved, result, t)
}
}
func TestRemovedWhitespace(t *testing.T) {
result := removeConsecutiveWhiteSpace(testSentence)
if result != expectedWhitespaceRemoved {
outputError("removeConsecutiveWhiteSpace", expectedWhitespaceRemoved, result, t)
}
}
func TestRemoveEndHyphen(t *testing.T) {
result := removeEndHyphen(testSentence)
if result != expectedHyphenRemoved {
outputError("removeEndHyphen", expectedHyphenRemoved, result, t)
}
}
func TestSplit(t *testing.T) {
result := removeNewLine(testSentence)
result = split(result)
if result != expectedSplit {
outputError("split", expectedSplit, result, t)
}
}
func outputError(funcName string, expect string, result string, t *testing.T) {
t.Errorf("%v output invalid sentence. \nExpect: %v\nResult: %v", funcName, expect, result)
}