-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesearch_test.go
76 lines (65 loc) · 2.51 KB
/
filesearch_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
package main
import (
"fmt"
"testing"
"golang.org/x/text/language"
"golang.org/x/text/search"
)
func TestProcessLine(t *testing.T) {
fs := fileSearcher{}
matcher := search.New(language.English)
p := matcher.CompileString("test")
expected := fmt.Sprintf("%s", fs.modifyPrintColor("test", colorRed))
actual, found := fs.processLine("test", p)
if !found {
t.Errorf("expected %t, but got %t instead", true, found)
}
if expected != actual {
t.Errorf("expected %q, but got %q instead", expected, actual)
}
expected = fmt.Sprintf("%s%s", "this is a ", fs.modifyPrintColor("test", colorRed))
actual, found = fs.processLine("this is a test", p)
if !found {
t.Errorf("expected %t, but got %t instead", true, found)
}
if expected != actual {
t.Errorf("expected %q, but got %q instead", expected, actual)
}
expected = fmt.Sprintf("%s%s%s%s", "this is a ", fs.modifyPrintColor("test", colorRed), " this is a ", fs.modifyPrintColor("test", colorRed))
actual, found = fs.processLine("this is a test this is a test", p)
if !found {
t.Errorf("expected %t, but got %t instead", true, found)
}
if expected != actual {
t.Errorf("expected %q, but got %q instead", expected, actual)
}
expected = fmt.Sprintf("%s%s%s%s%s", "this is a ", fs.modifyPrintColor("test", colorRed), " ", fs.modifyPrintColor("test", colorRed), " a is this")
actual, found = fs.processLine("this is a test test a is this", p)
if expected != actual {
t.Errorf("expected %q, but got %q instead", expected, actual)
}
expected = fmt.Sprintf("%s%s%s", fs.modifyPrintColor("test", colorRed), fs.modifyPrintColor("test", colorRed), fs.modifyPrintColor("test", colorRed))
actual, found = fs.processLine("testtesttest", p)
if !found {
t.Errorf("expected %t, but got %t instead", true, found)
}
if expected != actual {
t.Errorf("expected %q, but got %q instead", expected, actual)
}
expected = fmt.Sprintf("%s%s%s%s%s", fs.modifyPrintColor("test", colorRed), " ", fs.modifyPrintColor("test", colorRed), " ", fs.modifyPrintColor("test", colorRed))
actual, found = fs.processLine("test test test", p)
if !found {
t.Errorf("expected %t, but got %t instead", true, found)
}
if expected != actual {
t.Errorf("expected %q, but got %q instead", expected, actual)
}
expected = fmt.Sprintf("%s", "expect nothing out of this")
actual, found = fs.processLine("expect nothing out of this", p)
if found {
t.Errorf("expected %t, but got %t instead", false, found)
}
if expected != actual {
t.Errorf("expected %q, but got %q instead", expected, actual)
}
}