-
Notifications
You must be signed in to change notification settings - Fork 101
/
var_test.go
92 lines (72 loc) · 2.69 KB
/
var_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
package main
import (
"testing"
)
func TestVarName(t *testing.T) {
v := VarName("memstats.Alloc")
slice := v.ToSlice()
if len(slice) != 2 || slice[0] != "memstats" || slice[1] != "Alloc" {
t.Fatalf("ToSlice failed: %v", slice)
}
short := v.Short()
if short != "Alloc" {
t.Fatalf("Expecting Short() to be 'Alloc', but got: %s", short)
}
kind := v.Kind()
if kind != KindDefault {
t.Fatalf("Expecting kind to be %v, but got: %v", KindDefault, kind)
}
v = VarName("mem:memstats.Alloc")
slice = v.ToSlice()
if len(slice) != 2 || slice[0] != "memstats" || slice[1] != "Alloc" {
t.Fatalf("ToSlice failed: %v", slice)
}
short = v.Short()
if short != "Alloc" {
t.Fatalf("Expecting Short() to be 'Alloc', but got: %s", short)
}
kind = v.Kind()
if kind != KindMemory {
t.Fatalf("Expecting kind to be %v, but got: %v", KindMemory, kind)
}
v = VarName("duration:ResponseTimes.API.Users")
kind = v.Kind()
if kind != KindDuration {
t.Fatalf("Expecting kind to be %v, but got: %v", KindDuration, kind)
}
// single \. escapes the dot
v = VarName(`bleve.indexes.bench\.bleve.index.lookup_queue_len`)
slice = v.ToSlice()
if len(slice) != 5 || slice[0] != "bleve" || slice[1] != "indexes" || slice[2] != "bench.bleve" ||
slice[3] != "index" || slice[4] != "lookup_queue_len" {
t.Fatalf("ToSlice failed: %v", slice)
}
// double \\. escapes backslash, not dot
v = VarName(`bleve.indexes.bench\\.bleve.index.lookup_queue_len`)
slice = v.ToSlice()
if len(slice) != 6 || slice[0] != "bleve" || slice[1] != "indexes" || slice[2] != "bench\\" ||
slice[3] != "bleve" || slice[4] != "index" || slice[5] != "lookup_queue_len" {
t.Fatalf("ToSlice failed: %v", slice)
}
// triple \\\. escapes backslash then dot
v = VarName(`bleve.indexes.bench\\\.bleve.index.lookup_queue_len`)
slice = v.ToSlice()
if len(slice) != 5 || slice[0] != "bleve" || slice[1] != "indexes" || slice[2] != "bench\\.bleve" ||
slice[3] != "index" || slice[4] != "lookup_queue_len" {
t.Fatalf("ToSlice failed: %v", slice)
}
// quadruple \\\\. escapes two backslashes, not dot
v = VarName(`bleve.indexes.bench\\\\.bleve.index.lookup_queue_len`)
slice = v.ToSlice()
if len(slice) != 6 || slice[0] != "bleve" || slice[1] != "indexes" || slice[2] != "bench\\\\" ||
slice[3] != "bleve" || slice[4] != "index" || slice[5] != "lookup_queue_len" {
t.Fatalf("ToSlice failed: %v", slice)
}
// unsupported \x passes through unaltered
v = VarName(`bleve.indexes.bench\xbleve.index.lookup_queue_len`)
slice = v.ToSlice()
if len(slice) != 5 || slice[0] != "bleve" || slice[1] != "indexes" || slice[2] != "bench\\xbleve" ||
slice[3] != "index" || slice[4] != "lookup_queue_len" {
t.Fatalf("ToSlice failed: %v", slice)
}
}