This repository has been archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmisc_test.go
65 lines (58 loc) · 1.59 KB
/
misc_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
package stackage
import (
"testing"
)
var strInSliceMap map[int]map[int][]bool = map[int]map[int][]bool{
// case match
0: {
0: {true, true, true, true, true},
1: {true, true, true, true, true},
},
// case fold
1: {
0: {true, true, true, true, true},
1: {true, true, true, true, true},
},
}
func TestStrInSlice(t *testing.T) {
for idx, fn := range []func(string, []string) bool{
strInSlice,
strInSliceFold,
} {
for i, values := range [][]string{
{`cAndidate1`, `blarGetty`, `CANndidate7`, `squatcobbler`, `<censored>`},
{`Ó-aîï4Åø´øH«w%);<wï`, `piles`, `4378295fmitty`, string(rune(0)), `broccolI`},
} {
for j, val := range values {
result_expected := strInSliceMap[idx][i][j]
// warp the candidate value such that
// it no longer matches the slice from
// whence it originates. j² is used as
// its quicker and less stupid than
// adding a rand generator.
if isPowerOfTwo(j) {
var R []rune = []rune(val)
for g, h := 0, len(R)-1; g < h; g, h = g+1, h-1 {
R[g], R[h] = R[h], R[g]
}
val = string(R)
result_expected = !result_expected // invert
}
result_received := fn(val, values)
if result_expected != result_received {
t.Errorf("%s[%d->%d] failed; []byte(%v) in %v: %t (wanted %t)",
t.Name(), i, j, []byte(val), values, result_received, result_expected)
return
}
}
}
}
}
func TestDeref(t *testing.T) {
c := Cond(`this`, Eq, `that`)
ptr := &c
if T, V := derefPtr(ptr); V.IsZero() || T.Kind() == 0x0 {
t.Errorf("%s failed; pointer deref unsuccessful", t.Name())
return
}
}