-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder_test.go
43 lines (35 loc) · 1005 Bytes
/
encoder_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
package systemd
import (
"bytes"
"testing"
)
func TestEscapeBusLabel(t *testing.T) {
tt := map[string]string{
"": "_",
"dbus": "dbus",
"dbus.service": "dbus_2eservice",
"[email protected]": "foo_40bar_2eservice",
"[email protected]": "foo_5fbar_40bar_2eservice",
"systemd-networkd-wait-online.service": "systemd_2dnetworkd_2dwait_2donline_2eservice",
"555": "_3555",
"dev-ttyS8.device": "dev_2dttyS8_2edevice",
}
buf := &bytes.Buffer{}
for name, want := range tt {
buf.Reset()
escapeBusLabel(name, buf)
got := buf.String()
if want != got {
t.Errorf("expected %q got %q", want, got)
}
}
}
func BenchmarkEscapeBusLabel(b *testing.B) {
buf := &bytes.Buffer{}
b.ResetTimer()
for i := 0; i < b.N; i++ {
buf.Reset()
escapeBusLabel("dbus.service", buf)
got = buf.Bytes()
}
}