-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers_test.go
58 lines (52 loc) · 1.25 KB
/
helpers_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
package ts3
import (
"testing"
)
var testQuote = []struct {
in, expected string
}{
{"", ""},
{" ", `\s`},
{"Hello\a", "Hello\\a"},
{"Hello buddy!", `Hello\sbuddy!`},
{"id|1 id|2", `id\p1\sid\p2`},
{"heyooo\n\r", "heyooo\\n\\r"},
{"Lots\tof\vtabs", "Lots\\tof\\vtabs"},
{"I've never used these: \b, \f", `I've\snever\sused\sthese:\s\b,\s\f`},
}
var testUnquote = []struct {
in, expected string
}{
{"", ""},
{`\s`, " "},
{"Hello\\a", "Hello\a"},
{`Hello\sbuddy!`, "Hello buddy!"},
{`id\p1\sid\p2`, "id|1 id|2"},
{"heyooo\\n\\r", "heyooo\n\r"},
{"Lots\\tof\\vtabs", "Lots\tof\vtabs"},
{`I've\snever\sused\sthese:\s\b,\s\f`, "I've never used these: \b, \f"},
}
func TestQuote(t *testing.T) {
for index, tt := range testQuote {
output := Quote(tt.in)
if output != tt.expected {
t.Errorf("%d. Got %q, want %q", index+1, output, tt.expected)
}
}
}
func TestUnquote(t *testing.T) {
for index, tt := range testUnquote {
output := Unquote(tt.in)
if output != tt.expected {
t.Errorf("%d. Got %q, want %q", index+1, output, tt.expected)
}
}
}
func TestQuoteUnquote(t *testing.T) {
for index, tt := range testQuote {
output := Unquote(Quote(tt.in))
if output != tt.in {
t.Errorf("%d. Got %q, want %q", index+1, output, tt.in)
}
}
}