Repository navigation
Expand file tree
/
Copy pathunidecode_test.go
More file actions
69 lines (58 loc) · 1.64 KB
/
Copy pathunidecode_test.go
File metadata and controls
69 lines (58 loc) · 1.64 KB
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
package unidecode_test
import (
"strings"
"testing"
"github.com/ohait/go-unidecode"
)
func TestUnidecode(t *testing.T) {
test := func(in, expected string) {
out := unidecode.Decode(in)
if out == expected {
t.Logf("%q => %q", in, out)
} else {
t.Fatalf("%q => expected %q but got %q", in, expected, out)
}
}
test("foo", "foo")
test("Hello World!", "Hello World!")
test("úñícøðé", "unicode")
test("北京", "Bei Jing ")
test("هر چه", "hr chh")
test("سلام", "slm")
test("خانه", "khnh")
}
func TestSlug(t *testing.T) {
test := func(in, expected string) {
out := unidecode.Slug(in)
if out == expected {
t.Logf("%q => %q", in, out)
} else {
t.Fatalf("%q => expected %q but got %q", in, expected, out)
}
}
test(" úñícøðé ", "unicode")
test(" Hello \n World \t From Go ", "Hello-World-From-Go")
test("北京 语言", "Bei-Jing-Yu-Yan")
long := strings.Repeat("a", 100)
out := unidecode.Slug(long)
if len(out) != 80 {
t.Fatalf("expected slug length 80 but got %d", len(out))
}
if out != strings.Repeat("a", 80) {
t.Fatalf("unexpected truncated slug: %q", out)
}
}
func TestSlugN(t *testing.T) {
if out := unidecode.SlugN("Hello World", 5); out != "Hello" {
t.Fatalf("expected %q but got %q", "Hello", out)
}
if out := unidecode.SlugN("Hello World", 20); out != "Hello-World" {
t.Fatalf("expected %q but got %q", "Hello-World", out)
}
if out := unidecode.SlugN("Hello World", 0); out != "" {
t.Fatalf("expected empty slug for maxLen=0 but got %q", out)
}
if out := unidecode.SlugN("Hello World", -1); out != "" {
t.Fatalf("expected empty slug for maxLen<0 but got %q", out)
}
}