-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
117 lines (111 loc) · 1.83 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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestUrlify(t *testing.T) {
tests := []struct {
s string
sExp string
}{
{
s: "Laws of marketing #22 (resources) ",
sExp: "laws-of-marketing-22-resources",
},
{
s: "t -_",
sExp: "t-_",
},
{
s: "foo.htML ",
sExp: "foo.html",
},
}
for _, test := range tests {
sGot := urlify(test.s)
assert.Equal(t, test.sExp, sGot)
}
}
func TestTrimEmptyLines(t *testing.T) {
tests := []struct {
a []string
exp []string
}{
{
a: []string{"a"},
exp: []string{"a"},
},
{
a: []string{"a", "", "", "b"},
exp: []string{"a", "", "b"},
},
{
a: []string{"", "a", ""},
exp: []string{"a"},
},
{
a: []string{"", "", "a", "", "b", "", ""},
exp: []string{"a", "", "b"},
},
}
for _, test := range tests {
got := trimEmptyLines(test.a)
assert.Equal(t, test.exp, got)
}
}
func TestRemoveHashtags(t *testing.T) {
tests := []struct {
s string
tags []string
sExp string
}{
{
s: "#idea Build a web service ",
sExp: "Build a web service",
tags: []string{"idea"},
},
{
s: "#foo #BAr and #me",
sExp: "and",
tags: []string{"foo", "bar", "me"},
},
{
s: "not #found here",
sExp: "not #found here",
tags: nil,
},
{
s: "#foo not a#hash",
sExp: "not a#hash",
tags: []string{"foo"},
},
}
for _, test := range tests {
sGot, tags := removeHashTags(test.s)
assert.Equal(t, test.sExp, sGot)
assert.Equal(t, test.tags, tags)
}
}
func TestCapitalize(t *testing.T) {
tests := []struct {
s string
exp string
}{
{
s: "foo",
exp: "Foo",
},
{
s: "FOO",
exp: "Foo",
},
{
s: "FOO baR",
exp: "Foo bar",
},
}
for _, test := range tests {
got := capitalize(test.s)
assert.Equal(t, test.exp, got)
}
}