File: unidecode_test.go

package info (click to toggle)
golang-github-rainycape-unidecode 0.0~git20150906.0.c9cf8cd-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,152 kB
  • ctags: 30
  • sloc: makefile: 8
file content (57 lines) | stat: -rw-r--r-- 976 bytes parent folder | download | duplicates (2)
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
package unidecode

import (
	"testing"
)

func testTransliteration(original string, decoded string, t *testing.T) {
	if r := Unidecode(original); r != decoded {
		t.Errorf("Expected '%s', got '%s'\n", decoded, r)
	}
}

func TestASCII(t *testing.T) {
	s := "ABCDEF"
	testTransliteration(s, s, t)
}

func TestKnosos(t *testing.T) {
	o := "Κνωσός"
	d := "Knosos"
	testTransliteration(o, d, t)
}

func TestBeiJing(t *testing.T) {
	o := "\u5317\u4EB0"
	d := "Bei Jing "
	testTransliteration(o, d, t)
}

func TestEmoji(t *testing.T) {
	o := "Hey Luna t belle 😵😂"
	d := "Hey Luna t belle "
	testTransliteration(o, d, t)
}

func BenchmarkUnidecode(b *testing.B) {
	cases := []string{
		"ABCDEF",
		"Κνωσός",
		"\u5317\u4EB0",
	}
	for ii := 0; ii < b.N; ii++ {
		for _, v := range cases {
			_ = Unidecode(v)
		}
	}
}

func BenchmarkDecodeTable(b *testing.B) {
	for ii := 0; ii < b.N; ii++ {
		decodeTransliterations()
	}
}

func init() {
	decodeTransliterations()
}