-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitstr_test.go
64 lines (54 loc) · 1.55 KB
/
bitstr_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
package dirsyn
import (
"testing"
)
func TestBitString(t *testing.T) {
var r RFC4517
var raw string = `'10100101'B`
if result := bitString(raw); !result.True() {
t.Errorf("%s failed:\nwant: %s\ngot: %s",
t.Name(), `TRUE`, result)
return
}
bs, err := r.BitString(raw)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
} else if bs.IsZero() {
t.Errorf("%s failed: instance is zero", t.Name())
} else if got := bs.String(); raw != got {
t.Errorf("%s failed:\nwant: %s\ngot: %s",
t.Name(), raw, got)
}
}
func TestBitString_codecov(t *testing.T) {
_, _ = assertBitString([]byte{})
_, _ = assertBitString(struct{}{})
_ = bitString([]byte{})
_ = bitString(struct{}{})
_, _ = bitStringMatch([]byte{}, struct{}{})
_, _ = bitStringMatch([]byte(`'010110'B`), struct{}{})
_, _ = bitStringMatch([]byte{}, []byte{})
_, _ = bitStringMatch(struct{}{}, struct{}{})
_, _ = bitStringMatch([]byte(`'010110'B`), []byte(`'01'B`))
b, err := bitStringMatch(`'1010100'B`, `'1010000'B`)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
} else if !b.False() {
t.Errorf("%s failed:\nwant: %s\ngot: %s",
t.Name(), `FALSE`, b.String())
return
}
b, err = bitStringMatch(`'1010100'B`, `'1010100'B`)
if err != nil {
t.Errorf("%s failed: %v", t.Name(), err)
return
} else if !b.True() {
t.Errorf("%s failed:\nwant: %s\ngot: %s",
t.Name(), `TRUE`, b.String())
return
}
_ = stripTrailingZeros([]byte{0x1, 0x2, 0x0, 0x0}, 2)
_ = stripTrailingZeros([]byte{0x1, 0x2, 0x0, 0x0}, 4)
_ = stripTrailingZeros([]byte{}, 0)
}