-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscan_test.go
117 lines (114 loc) · 1.99 KB
/
scan_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
package bpe
import (
"testing"
)
func TestIsEndOfSentence(t *testing.T) {
tt := []struct {
name string
prev string
lastRune rune
next string
expected bool
}{
{
name: "line start",
prev: "",
lastRune: 'E',
next: "xample",
expected: false,
},
{
name: "single new line",
prev: "",
lastRune: '\n',
next: "",
expected: false,
},
{
name: "123.45",
prev: "123",
lastRune: '.',
next: "45 text",
expected: false,
},
{
name: "float with EOF",
prev: "123",
lastRune: '.',
next: "",
expected: true,
},
{
name: "list item number",
prev: "1",
lastRune: '.',
next: " First",
// Yeah. It's hard to understand is it a list item number or something like year et the end of string.
expected: true,
},
{
name: "!",
prev: "Wow",
lastRune: '!',
next: " ",
expected: true,
},
{
name: "?",
prev: "Really",
lastRune: '?',
next: " ",
expected: true,
},
{
name: "eof",
prev: "Really",
lastRune: '?',
next: " ",
expected: true,
},
{
name: "abbreviation",
prev: "he's a Dr",
lastRune: '.',
next: " of",
expected: false,
},
{
name: "abbreviation 2",
prev: "Dr",
lastRune: '.',
next: " Michael",
expected: false,
},
{
name: "example.",
prev: "example",
lastRune: '.',
next: " New sentence",
expected: true,
},
{
name: "(lat",
prev: "(lat",
lastRune: '.',
next: " Loren Ipsum",
expected: false,
},
{
name: "4lat",
prev: "4lat",
lastRune: '.',
next: " New sentence",
expected: true,
},
}
for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
actual := isEndOfSentence(tc.lastRune, []byte(tc.prev), []byte(tc.next))
if tc.expected != actual {
t.Errorf("Expected: %v\nGot: %v\n", tc.expected, actual)
}
})
}
}