-
Notifications
You must be signed in to change notification settings - Fork 7
/
bidi_test.go
143 lines (129 loc) · 2.45 KB
/
bidi_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package gostrutils
import (
"testing"
"golang.org/x/text/language"
)
func TestCountBidiChars(t *testing.T) {
type wordsInput struct {
desc string
input string
expected int
}
list := []wordsInput{
{
desc: "Testing English Alphabet",
input: "abcdefghijklmnopqrstuvwxyz",
expected: 0,
},
{
desc: "Hebrew with punctuation points",
input: "עִבְרִית",
expected: 8,
},
{
desc: "Arabic with punctuation points",
input: " اَلْعَرَبِيَّةُ",
expected: 15,
},
{
desc: "Test Hebrew with Arabic, no punctuation points",
input: "עברית العربية",
expected: 12,
},
{
desc: "Triple language",
input: "English, עברית ,العربية",
expected: 12,
},
}
for idx, words := range list {
result := CountBidiChars(words.input)
if result != words.expected {
t.Errorf("Test #%d. Got: %+v, got: %d", idx, words, result)
}
}
}
func TestCountStartBidiLanguage(t *testing.T) {
type wordsInput struct {
desc string
input string
expected int
}
list := []wordsInput{
{
desc: "English",
input: "a",
expected: 0,
},
{
desc: "Symbols",
input: "!@#$",
expected: -1,
},
{
desc: "Latin and symbols",
input: "a12",
expected: 0,
},
{
desc: "Hebrew, space and Latin",
input: "עברית a",
expected: 6,
},
{
desc: "Latin and Hebrew",
input: "a עברית",
expected: 0,
},
{
desc: "Number, space and Hebrew",
input: "100 מאה",
expected: 7,
},
{
desc: "Number, space, Hebrew, space and Latin",
input: "100 מאה hundred",
expected: 8,
},
}
for idx, words := range list {
result := CountStartBidiLanguage(words.input)
if result != words.expected {
t.Errorf("Test #%d. Got: %+v, got: %d", idx, words, result)
}
}
}
func TestTagIsBidi(t *testing.T) {
type tagsToTest struct {
input language.Tag
expected bool
}
list := []tagsToTest{
{
input: language.Afrikaans,
expected: false,
},
{
input: language.Arabic,
expected: true,
},
{
input: language.Persian,
expected: true,
},
{
input: language.Hebrew,
expected: true,
},
{
input: language.Urdu,
expected: true,
},
}
for idx, tag := range list {
result := TagIsBidi(tag.input)
if result != tag.expected {
t.Errorf("Test %d. Tag: %+v, got %t", idx, tag, result)
}
}
}