-
Notifications
You must be signed in to change notification settings - Fork 137
/
uuid_test.go
73 lines (64 loc) · 1.81 KB
/
uuid_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
package bluetooth
import (
"strings"
"testing"
)
func TestUUIDString(t *testing.T) {
checkUUID(t, New16BitUUID(0x1234), "00001234-0000-1000-8000-00805f9b34fb")
}
func checkUUID(t *testing.T, uuid UUID, check string) {
if uuid.String() != check {
t.Errorf("expected UUID %s but got %s", check, uuid.String())
}
}
func TestParseUUIDTooSmall(t *testing.T) {
_, e := ParseUUID("00001234-0000-1000-8000-00805f9b34f")
if e != errInvalidUUID {
t.Errorf("expected errInvalidUUID but got %v", e)
}
}
func TestParseUUIDTooLarge(t *testing.T) {
_, e := ParseUUID("00001234-0000-1000-8000-00805F9B34FB0")
if e != errInvalidUUID {
t.Errorf("expected errInvalidUUID but got %v", e)
}
}
func TestStringUUID(t *testing.T) {
uuidString := "00001234-0000-1000-8000-00805f9b34fb"
u, e := ParseUUID(uuidString)
if e != nil {
t.Errorf("expected nil but got %v", e)
}
if u.String() != uuidString {
t.Errorf("expected %s but got %s", uuidString, u.String())
}
}
func TestStringUUIDUpperCase(t *testing.T) {
uuidString := strings.ToUpper("00001234-0000-1000-8000-00805f9b34fb")
u, e := ParseUUID(uuidString)
if e != nil {
t.Errorf("expected nil but got %v", e)
}
if !strings.EqualFold(u.String(), uuidString) {
t.Errorf("%s does not match %s ignoring case", uuidString, u.String())
}
}
func TestStringUUIDLowerCase(t *testing.T) {
uuidString := strings.ToLower("00001234-0000-1000-8000-00805f9b34fb")
u, e := ParseUUID(uuidString)
if e != nil {
t.Errorf("expected nil but got %v", e)
}
if !strings.EqualFold(u.String(), uuidString) {
t.Errorf("%s does not match %s ignoring case", uuidString, u.String())
}
}
func BenchmarkUUIDToString(b *testing.B) {
uuid, e := ParseUUID("00001234-0000-1000-8000-00805f9b34fb")
if e != nil {
b.Errorf("expected nil but got %v", e)
}
for i := 0; i < b.N; i++ {
_ = uuid.String()
}
}