-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeyword_test.go
More file actions
80 lines (74 loc) · 2.14 KB
/
keyword_test.go
File metadata and controls
80 lines (74 loc) · 2.14 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
package tanuki
import (
"testing"
)
func TestKeywordAdd(t *testing.T) {
kwm := &keywordManager{
keywords: make(map[string]keyword),
fileExtensions: make(map[string]keyword),
}
targKeyword1 := keyword{
category: elementCategoryEpisodePrefix,
options: keywordOptionsDefault,
}
targKeyword2 := keyword{
category: elementCategoryFileExtension,
options: keywordOptionsDefault,
}
kwm.add(elementCategoryEpisodePrefix, keywordOptionsDefault, []string{"TEST"})
kwm.add(elementCategoryFileExtension, keywordOptionsDefault, []string{"TEST"})
if kwm.keywords["TEST"] != targKeyword1 {
t.Error("keyword did not match targKeyword1")
}
if kwm.fileExtensions["TEST"] != targKeyword2 {
t.Error("keyword did not match targKeyword2")
}
}
func TestKeywordFind(t *testing.T) {
kwm := newKeywordManager()
_, found := kwm.find("MKV", elementCategoryFileExtension)
if !found {
t.Error("expected true, got false")
}
_, found = kwm.find("MKV", elementCategoryUnknown)
if found {
t.Error("expected false, got true")
}
_, found = kwm.find("SAISON", elementCategoryAnimeSeasonPrefix)
if !found {
t.Error("expected true, got false")
}
_, found = kwm.find("SAISON", elementCategoryFileExtension)
if found {
t.Error("expected false, got true")
}
}
func TestKeywordFindWithoutCategory(t *testing.T) {
kwm := newKeywordManager()
_, found := kwm.findWithoutCategory("MKV")
if !found {
t.Error("expected true, got false")
}
_, found = kwm.findWithoutCategory("SAISON")
if !found {
t.Error("expected true, got false")
}
_, found = kwm.findWithoutCategory("TESTINGTHIS")
if found {
t.Error("expected false, got true")
}
}
func TestKeywordPeek(t *testing.T) {
psr := getTestParser("")
testStr := "this is a Dual Audio"
idxSets := psr.tokenizer.keywordManager.peek(testStr, psr.tokenizer.elements)
if idxSets[0].beginPos != 10 {
t.Errorf("expected 10, got %d", idxSets[0].beginPos)
}
if idxSets[0].endPos != 20 {
t.Errorf("expected 19, got %d", idxSets[0].endPos)
}
if testStr[idxSets[0].beginPos:idxSets[0].endPos] != "Dual Audio" {
t.Errorf("expected \"%s\", got \"%s\"", "Dual Audio", testStr[idxSets[0].beginPos:idxSets[0].endPos])
}
}