This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathall_test.go
81 lines (70 loc) · 2.02 KB
/
all_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
// This code is in Public Domain. Take all the code you want, I'll just write more.
package main
import (
"testing"
)
func testIPConvOne(t *testing.T, s string) {
internal := ipAddrToInternal(s)
orig := ipAddrInternalToOriginal(internal)
if s != orig {
t.Fatalf("%q != %q", s, orig)
}
}
func testMakeInternalUserName(t *testing.T, given string, twitter bool, expected string) {
res := MakeInternalUserName(given, twitter)
if res != expected {
t.Fatalf("%q != %q", res, expected)
}
}
func testipAddrFromRemoteAddr(t *testing.T, s, expected string) {
res := ipAddrFromRemoteAddr(s)
if res != expected {
t.Fatalf("%q != %q", res, expected)
}
}
func testStringSliceEq(t *testing.T, s1, s2 []string) {
if len(s1) != len(s2) {
t.Fatalf("len(s1) != len(s2) (%d != %d)", len(s1), len(s2))
}
for i := range s1 {
if s1[i] != s2[i] {
t.Fatalf("s1[%d] != s2[%d] (%s != %s)", i, i, s1[i], s2[i])
}
}
}
func TestIpConv(t *testing.T) {
testIPConvOne(t, "127.0.0.1")
testIPConvOne(t, "27.3.255.238")
testIPConvOne(t, "hello kitty")
testMakeInternalUserName(t, "foo", false, "foo")
testMakeInternalUserName(t, "foo", true, "t:foo")
testMakeInternalUserName(t, "t:foo", false, "foo")
testMakeInternalUserName(t, "p:", false, "p")
testipAddrFromRemoteAddr(t, "foo", "foo")
testipAddrFromRemoteAddr(t, "[::1]:58292", "[::1]")
testipAddrFromRemoteAddr(t, "127.0.0.1:856", "127.0.0.1")
a := []string{"foo", "bar", "go"}
deleteStringIn(&a, "foo")
testStringSliceEq(t, a, []string{"go", "bar"})
deleteStringIn(&a, "go")
testStringSliceEq(t, a, []string{"bar"})
deleteStringIn(&a, "baro")
testStringSliceEq(t, a, []string{"bar"})
deleteStringIn(&a, "bar")
testStringSliceEq(t, a, []string{})
}
func testUnCaps(t *testing.T, s, exp string) {
got := UnCaps(s)
if got != exp {
t.Fatalf("\n%#v !=\n%#v (for '%#v')", got, exp, s)
}
}
func TestUnCaps(t *testing.T) {
d := []string{
"FOO", "Foo",
//"FOO BAR. IS IT ME?\nOR ME", "Foo bar. Is it me?\nOr me",
}
for i := 0; i < len(d)/2; i++ {
testUnCaps(t, d[i*2], d[i*2+1])
}
}