-
Notifications
You must be signed in to change notification settings - Fork 1
/
util_test.go
56 lines (51 loc) · 1.16 KB
/
util_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
package main
import (
"testing"
"github.com/google/go-cmp/cmp"
)
func TestWrapPrefix(t *testing.T) {
for i, tc := range []struct {
in string
out string
}{
{
in: "asldfj afdlk, jgha fdkll gjhfda lkjghfd. lkjgfh lkaf jdhg adl kdjhfgs dkjgh ds!",
out: "----asldfj afdlk, \n----jgha fdkll \n----gjhfda lkjghfd.\n---- lkjgfh lkaf \n----jdhg adl \n----kdjhfgs dkjgh \n----ds!\n",
},
{
in: "snarf\nblarg\n",
out: "----snarf\n\n----blarg\n\n",
},
} {
q := WrapPrefix(tc.in, "----", 15)
if diff := cmp.Diff(q, tc.out); diff != "" {
t.Errorf("unexpected %d:\n%s\n", i, diff)
}
}
}
func TestHostname(t *testing.T) {
hn := GetHostname()
t.Log(hn)
if hn == "unknown-host" {
t.Fatal("why does hostname not work?")
}
}
func TestTableQuote(t *testing.T) {
for i, tc := range []struct {
input []byte
output string
}{
{[]byte("\n"), `\n`},
{[]byte(`\`), `\\`},
{[]byte(`\n`), `\\n`},
{[]byte(`"`), `"`},
{nil, ""},
{[]byte(""), ""},
{[]byte("hello"), "hello"},
{[]byte("hello, world"), "hello, world"},
} {
if out := TableQuote(tc.input); out != tc.output {
t.Errorf("test case %d: %q != %q", i, out, tc.output)
}
}
}