-
Notifications
You must be signed in to change notification settings - Fork 26
/
slugify_test.go
68 lines (59 loc) · 2.08 KB
/
slugify_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
package strutil
import (
"fmt"
"testing"
)
func TestSlugifySpecial(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"", ""},
{" ", ""},
{"lorem ", "lorem"},
{"We löve Motörhead", "we-love-motorhead"},
{"žůžo", "zuzo"},
{"yağmur -- yağarken", "yagmur-yagarken"},
{"résumé", "resume"},
{"Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. ", "lorem-ipsum-comes-from-sections-1-10-32-and-1-10-33-of-de-finibus-bonorum-et-malorum-the-extremes-of-good-and-evil-by-cicero-written-in-45-bc"},
}
for i, test := range tests {
output := SlugifySpecial(test.input, "-")
Assert(t, test.expected, output, "Test case %d is not successful\n", i)
}
}
func ExampleSlugifySpecial() {
fmt.Println(SlugifySpecial("We löve Motörhead", "_"))
// Output: we_love_motorhead
}
func TestSlugify(t *testing.T) {
tests := []struct {
input string
expected string
}{
{"", ""},
{" ", ""},
{"lorem ", "lorem"},
{"We löve Motörhead", "we-love-motorhead"},
{"žůžo", "zuzo"},
{"yağmur -- yağarken", "yagmur-yagarken"},
{"résumé", "resume"},
{" - lorem Ipsum - ", "lorem-ipsum"},
{"-lorem Ipsum - ", "lorem-ipsum"},
{"Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. ", "lorem-ipsum-comes-from-sections-1-10-32-and-1-10-33-of-de-finibus-bonorum-et-malorum-the-extremes-of-good-and-evil-by-cicero-written-in-45-bc"},
}
for i, test := range tests {
output := Slugify(test.input)
Assert(t, test.expected, output, "Test case %d is not successful\n", i)
}
}
func ExampleSlugify() {
fmt.Println(Slugify("We löve Motörhead"))
// Output: we-love-motorhead
}
var slugifyTestString = "Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero"
func BenchmarkSlugifySpecial(b *testing.B) {
for n := 0; n < b.N; n++ {
SlugifySpecial(slugifyTestString, "-")
}
}