-
Notifications
You must be signed in to change notification settings - Fork 0
/
substr_test.go
117 lines (102 loc) · 3.36 KB
/
substr_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 dirsyn
import (
"testing"
)
func TestSubstringAssertion(t *testing.T) {
var r RFC4517
for idx, raw := range []string{
`substring*substring`,
`substri*ng*thing`,
`*substring*substring*`,
`*substr*ing*end`,
`substring*substring*substring`,
`subst*`,
`*ubstr`,
} {
if ssa, err := r.SubstringAssertion(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 TestSubstringAssertion_codecov(t *testing.T) {
substrProcess1(`11*11`)
substrProcess1(`aaaa`)
substrProcess1(` `)
substrProcess2(`11*11`)
substrProcess2(`nil`)
substrProcess2(` `)
substrProcess2(`aaaa`)
substrProcess3(`11*11`)
substrProcess3(` `)
substrProcess3(`aaaa`)
substrProcess4(`11*11`)
substrProcess4(`aaaa`)
substrProcess4(` `)
prepareStringListAssertion([]string{`ahch`, `helkl4`}, `h*lk*4`)
assertSubstringAssertion(SubstringAssertion{})
substringAssertion(`aa*a`)
substrProcess1(`aa*a`)
substrProcess2(`aa*a`)
substrProcess3(`aa*a`)
substrProcess4(`aa*a`)
marshalSubstringAssertion(nil)
marshalSubstringAssertion(``)
marshalSubstringAssertion([]byte{})
marshalSubstringAssertion(`thisis**bogus`)
b, err := caseIgnoreSubstringsMatch(`this is a substring`, `this is*a*substring`)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
} else if !b.True() {
t.Errorf("%s failed:\nwant: TRUE\ngot: %s", t.Name(), b.String())
return
}
_, _ = caseIgnoreSubstringsMatch(``, `This*isa*Substring`)
_, _ = caseIgnoreSubstringsMatch(``, `ThisisaSubstring`)
_, _ = caseIgnoreSubstringsMatch(`this*isa*substring`, ``)
_, _ = caseIgnoreSubstringsMatch(`this*isa*substring`, `banana`)
b, err = caseExactSubstringsMatch(`this*isa*substring`, `This*isa*Substring`)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
} else if !b.False() {
t.Errorf("%s failed:\nwant: FALSE\ngot: %s", t.Name(), b.String())
return
}
_, _ = caseExactSubstringsMatch(``, `This*isa*Substring`)
_, _ = caseExactSubstringsMatch(``, `ThisisaSubstring`)
_, _ = caseExactSubstringsMatch(`this*isa*substring`, ``)
_, _ = caseExactSubstringsMatch(`this*isa*substring`, `banana`)
_, _ = caseExactSubstringsMatch(`this*isa*substring`, SubstringAssertion{
Initial: AssertionValue([]byte{0x1, 0x2}),
Final: AssertionValue([]byte{0x1, 0x2}),
})
_, _ = caseExactSubstringsMatch(`this*isa*substring`, SubstringAssertion{
Initial: AssertionValue([]byte{0x1, 0x2}),
Any: AssertionValue([]byte(`is*not*subs*ring`)),
Final: AssertionValue([]byte{0x1, 0x2}),
})
caseIgnoreListSubstringsMatch([]string{`ahch`, `helkl4`}, `h*lk*4`)
//var r RFC4517
//s, _ := r.SubstringAssertion(`this*this*this`)
//s.substringsMatch(`thisathisethis`, false)
//s = SubstringAssertion{}
//s.substringsMatch([]byte{})
//s.substringsMatch(nil)
//s.substringsMatch(SubstringAssertion{})
//s.substringsMatch(``)
//s = SubstringAssertion{Any: []byte(`this i* a substring`)}
//s.substringsMatch(`this is a substring`, true)
//s.substringsMatch(`athis is a substring`, false)
//s = SubstringAssertion{
// Initial: []byte(`this`),
// Any: []byte(`i* a `),
// Final: []byte(`substring`),
//}
//s.substringsMatch(`athis is a substring`)
//s.substringsMatch(`this is a substrink`)
//s.substringsMatch(`this es a substring`)
}