File: unidecode_test.go

package info (click to toggle)
golang-github-gosimple-unidecode 1.0.1-2.1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 984 kB
  • sloc: makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,049 bytes parent folder | download
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
package unidecode

import (
	"testing"
)

func TestUnidecode(t *testing.T) {
	tests := map[string]struct {
		s    string
		want string
	}{
		"ASCII": {
			"ABCDEF",
			"ABCDEF",
		},
		"Knosos": {
			"Κνωσός",
			"Knosos",
		},
		"BeiJing": {
			"\u5317\u4EB0",
			"Bei Jing ",
		},
		"Emoji": {
			"Hey Luna t belle 😵😂",
			"Hey Luna t belle ",
		},
		"U+10000 plain string": {
			"𐀀",
			"",
		},
		"U+10000 ASCII string": {
			"\U00010000",
			"",
		},
	}
	for name, tt := range tests {
		tt := tt
		name := name
		t.Run(name, func(t *testing.T) {
			t.Parallel()
			if got := Unidecode(tt.s); got != tt.want {
				t.Errorf("Unidecode() = %v, want %v", got, tt.want)
			}
		})
	}
}

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()
}