-
Notifications
You must be signed in to change notification settings - Fork 26
/
stringutils_test.go
109 lines (102 loc) · 2.56 KB
/
stringutils_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
// Package goarabic contains utility functions for working with strings.
package goarabic
import "testing"
// Reverse returns its argument string reversed rune-wise left to right.
func TestReverse(t *testing.T) {
cases := []struct {
in, want string
}{
{"Hello, world", "dlrow ,olleH"},
{"Crowdbotics", "scitobdworC"},
{"Hello, 世界", "界世 ,olleH"},
{"نص عربي", "يبرع صن"},
{"نَصٌ عَربِيٌّ", "ٌّيِبرَع ٌصَن"},
{"نَصٌ عَربِيٌّ!", "!ٌّيِبرَع ٌصَن"},
{"نَصٌ example, عَربِيٌّ!", "!ٌّيِبرَع ,elpmaxe ٌصَن"},
{"", ""},
}
for _, c := range cases {
got := Reverse(c.in)
if got != c.want {
t.Errorf("Reverse(%q) == %q, want %q", c.in, got, c.want)
}
}
}
func TestRemoveTashkeel(t *testing.T) {
cases := []struct {
in, want string
}{
{"نَصٌ عَربِيٌّ", "نص عربي"},
{"نص عربي", "نص عربي"},
{"", ""},
}
for _, c := range cases {
got := RemoveTashkeel(c.in)
if got != c.want {
t.Errorf("RemoveTashkeel(%q) == %q, want %q", c.in, got, c.want)
}
}
}
func TestSmartLength(t *testing.T) {
cases := []struct {
in string
want int
}{
{"نَصٌ عَربِيٌّ", 7},
{"نص عربي", 7},
{"Hello, world", 12},
{"Hello, 世界", 9},
{"", 0},
}
for _, c := range cases {
got := SmartLength(&c.in)
if got != c.want {
t.Errorf("SmartLength(...) got %d, want %d", got, c.want)
}
}
}
func TestToGlyph(t *testing.T) {
cases := []struct {
in string
want string
}{
{"تجربة النص العربي", "\ufe97\ufea0\ufeae\ufe91\ufe94 \u0627\ufedf\ufee8\ufeba \u0627\ufedf\ufecc\ufeae\ufe91\ufef2"},
{"", ""},
}
for _, c := range cases {
got := ToGlyph(c.in)
if got != c.want {
t.Errorf("ToGlyph(...) got %q, want %+q", got, c.want)
}
}
}
func TestRemoveTatweel(t *testing.T) {
cases := []struct {
in, want string
}{
{"نـــص عــربــي", "نص عربي"},
{"نـــَصٌ عَـربي", "نَصٌ عَربي"},
{"", ""},
}
for _, c := range cases {
got := RemoveTatweel(c.in)
if got != c.want {
t.Errorf("RemoveTatweel(%q) == %q, want %q", c.in, got, c.want)
}
}
}
func TestRemoveAllNonArabicChars(t *testing.T) {
cases := []struct {
in, want string
}{
{"عــربـabcـينـــص", "عــربــينـــص"},
{"عــربــينwo%%rd_ـــصa", "عــربــينـــص"},
{"", ""},
}
for _, c := range cases {
got := RemoveAllNonArabicChars(c.in)
if got != c.want {
t.Errorf("RemoveAllNonArabicChars(%q) == %q, want %q", c.in, got, c.want)
}
}
}