-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubstr_test.go
More file actions
131 lines (112 loc) · 2.54 KB
/
Copy pathsubstr_test.go
File metadata and controls
131 lines (112 loc) · 2.54 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
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package syntax
import (
"fmt"
"testing"
)
func ExampleSubstrings_roundTripBER() {
sub, err := NewSubstrings(`substring*substring*substring`)
if err != nil {
fmt.Println(err)
return
}
var enc []byte
if enc, err = sub.Encode(); err != nil {
fmt.Println(err)
return
}
var dec Substrings
if err = dec.Decode(enc); err != nil {
fmt.Println(err)
return
}
fmt.Printf("%v\n", dec)
// Output: substring*substring*substring
}
func ExampleSubstringAny_roundTripBER() {
Any := SubstringAny{
AssertionValue{0x73, 0x75, 0x62, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67},
AssertionValue{0x73, 0x75, 0x62, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67},
}
enc, err := Any.Encode()
if err != nil {
fmt.Println(err)
return
}
var dec SubstringAny
if err = dec.Decode(enc); err != nil {
fmt.Println(err)
return
}
fmt.Printf("%s\n", dec)
// Output: [substring substring]
}
func ExampleSubstringInitial_roundTripBER() {
Sub := SubstringInitial{0x73, 0x75, 0x62, 0x73, 0x74, 0x72, 0x69, 0x6e, 0x67}
enc, err := Sub.Encode()
if err != nil {
fmt.Println(err)
return
}
var dec SubstringInitial
if err = dec.Decode(enc); err != nil {
fmt.Println(err)
return
}
fmt.Printf("%s\n", dec)
// Output: substring
}
func TestSubstrings(t *testing.T) {
for idx, raw := range []string{
`substring*substring`,
`substri*ng*thing`,
`*substring*substring*`,
`*substr*ing*end`,
`substring*substring*substring`,
`subst*`,
`*ubstr`,
} {
if ssa, err := NewSubstrings(raw); err != nil {
t.Errorf("%s[%d] failed: %v", t.Name(), idx, err)
} else if got := ssa.String(); got != raw {
t.Errorf("%s[%d] failed:\n\twant:%s\n\tgot: %s\n",
t.Name(), idx, raw, got)
}
}
}
func BenchmarkNewSubstrings(b *testing.B) {
b.StopTimer()
assn := [][]byte{
[]byte(`+1*555*134`),
[]byte(`substring*substring`),
[]byte(`substri*ng*thing`),
[]byte(`*substring*substring*`),
[]byte(`*substr*ing*end`),
[]byte(`substring*substring*substring`),
[]byte(`subst*`),
[]byte(`*ubstr`),
}
maxIdx := len(assn)
b.StartTimer()
for i := 0; i < b.N; i++ {
_, _ = NewSubstrings(assn[i%maxIdx])
}
}
func BenchmarkSubstringMatch(b *testing.B) {
match := []byte(`substring`)
b.StopTimer()
assn := [][]byte{
[]byte(`+1*555*134`),
[]byte(`substring*substring`),
[]byte(`substri*ng*thing`),
[]byte(`*substring*substring*`),
[]byte(`*substr*ing*end`),
[]byte(`substring*substring*substring`),
[]byte(`subst*`),
[]byte(`*ubstr`),
}
maxIdx := len(assn)
b.StartTimer()
for i := 0; i < b.N; i++ {
_, _ = substringsMatch(match, assn[i%maxIdx])
}
}