-
Notifications
You must be signed in to change notification settings - Fork 89
/
func_test.go
48 lines (38 loc) · 1.13 KB
/
func_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
package xpath
import "testing"
type testQuery string
func (t testQuery) Select(_ iterator) NodeNavigator {
panic("implement me")
}
func (t testQuery) Clone() query {
return t
}
func (t testQuery) Evaluate(_ iterator) interface{} {
return string(t)
}
const strForNormalization = "\t \rloooooooonnnnnnngggggggg \r \n tes \u00a0 t strin \n\n \r g "
const expectedStrAfterNormalization = `loooooooonnnnnnngggggggg tes t strin g`
func Test_NormalizeSpaceFunc(t *testing.T) {
result := normalizespaceFunc(testQuery(strForNormalization), nil).(string)
if expectedStrAfterNormalization != result {
t.Fatalf("unexpected result '%s'", result)
}
}
func Test_ConcatFunc(t *testing.T) {
result := concatFunc(testQuery("a"), testQuery("b"))(nil, nil).(string)
if "ab" != result {
t.Fatalf("unexpected result '%s'", result)
}
}
func Benchmark_NormalizeSpaceFunc(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = normalizespaceFunc(testQuery(strForNormalization), nil)
}
}
func Benchmark_ConcatFunc(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = concatFunc(testQuery("a"), testQuery("b"))(nil, nil)
}
}