forked from 01walid/goarabic
-
Notifications
You must be signed in to change notification settings - Fork 1
/
stringutils_test.go
130 lines (122 loc) · 3.24 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// 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"},
{"تجربة لا النص العربي", "\ufe97\ufea0\ufeae\ufe91\ufe94 \ufefb \u0627\ufedf\ufee8\ufeba \u0627\ufedf\ufecc\ufeae\ufe91\ufef2"},
{"۰۱۲۳۴۵۶۷۸۹", "۰۱۲۳۴۵۶۷۸۹"},
{"0123456789", "۰۱۲۳۴۵۶۷۸۹"},
{"0123456789", "۰۱۲۳۴۵۶۷۸۹"},
{"", ""},
{"Sample english", "Sample english"},
}
for _, c := range cases {
got := ToGlyph(c.in)
if got != c.want {
t.Errorf("ToGlyph(...) got %q, want %+q", got, c.want)
}
}
}
func TestFixArabic(t *testing.T) {
cases := []struct {
in string
want string
}{
{"تجربة text العربي", "ﻲﺑﺮﻌﻟا text ﺔﺑﺮﺠﺗ"},
{"Sample جمله english", "english ﻪﻠﻤﺟ Sample"},
}
for _, c := range cases {
got := FixArabic(c.in)
if got != c.want {
t.Errorf("FixArabic(...) 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)
}
}
}