-
Notifications
You must be signed in to change notification settings - Fork 305
Expand file tree
/
Copy patharabic_test.go
More file actions
187 lines (178 loc) · 5.6 KB
/
Copy patharabic_test.go
File metadata and controls
187 lines (178 loc) · 5.6 KB
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package gopdf
import (
"testing"
)
func TestGetShaddaLigature(t *testing.T) {
tests := []struct {
name string
vowel rune
expected rune
}{
{"Fatha + Shadda", FATHA, SHADDA_FATHA},
{"Damma + Shadda", DAMMA, SHADDA_DAMMA},
{"Kasra + Shadda", KASRA, SHADDA_KASRA},
{"Tanween Damm + Shadda", TANWEEN_DAMM, SHADDA_DAMMATAN},
{"Tanween Kasr + Shadda", TANWEEN_KASR, SHADDA_KASRATAN},
{"Superscript Alef + Shadda", SUPERSCRIPT_ALEF, SHADDA_SUPERSCRIPT_ALEF},
{"Tanween Fath (no ligature)", TANWEEN_FATH, 0},
{"Sukun (no ligature)", SUKUN, 0},
{"Non-tashkeel (no ligature)", 'a', 0},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := GetShaddaLigature(tt.vowel)
if got != tt.expected {
t.Errorf("GetShaddaLigature(%U) = %U, want %U", tt.vowel, got, tt.expected)
}
})
}
}
func TestIsTashkeel(t *testing.T) {
tests := []struct {
name string
input rune
expected bool
}{
{"Fatha is tashkeel", FATHA, true},
{"Damma is tashkeel", DAMMA, true},
{"Kasra is tashkeel", KASRA, true},
{"Shadda is tashkeel", SHADDA, true},
{"Sukun is tashkeel", SUKUN, true},
{"Tanween Fath is tashkeel", TANWEEN_FATH, true},
{"Tanween Damm is tashkeel", TANWEEN_DAMM, true},
{"Tanween Kasr is tashkeel", TANWEEN_KASR, true},
{"Superscript Alef is tashkeel", SUPERSCRIPT_ALEF, true},
{"Beh is not tashkeel", BEH.Unicode, false},
{"Alef is not tashkeel", ALEF.Unicode, false},
{"Space is not tashkeel", ' ', false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := IsTashkeel(tt.input)
if got != tt.expected {
t.Errorf("IsTashkeel(%U) = %v, want %v", tt.input, got, tt.expected)
}
})
}
}
func TestToArabicWithTashkeel(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "Word with fatha - letters should join",
input: "بَاب", // Beh + Fatha + Alef + Beh
// Tashkeel now comes BEFORE its base letter in output
// Reversed: Beh(iso), Alef(final), Fatha+Beh(beg)
expected: string([]rune{BEH.Isolated, ALEF.Final, FATHA, BEH.Beginning}),
},
{
name: "Word with shadda",
input: "شدّة", // Sheen + Dal + Shadda + Teh_Marbuta
// Tashkeel now comes BEFORE its base letter in output
// Reversed: Teh_Marbuta(iso), Shadda+Dal(mid), Sheen(beg)
expected: string([]rune{TEH_MARBUTA.Isolated, SHADDA, DAL.Middle, SHEEN.Beginning}),
},
{
name: "Lam-Alef ligature with fatha between",
input: "لَا", // Lam + Fatha + Alef
// Tashkeel now comes BEFORE its base letter
// Reversed: Fatha+LAM_ALEF(isolated)
expected: string([]rune{FATHA, LAM_ALEF.Isolated}),
},
{
name: "Bismillah start",
input: "بِسْمِ", // Beh + Kasra + Seen + Sukun + Meem + Kasra
// Tashkeel now comes BEFORE its base letter
// Reversed: Kasra+Meem(final), Sukun+Seen(mid), Kasra+Beh(beg)
expected: string([]rune{KASRA, MEEM.Final, SUKUN, SEEN.Middle, KASRA, BEH.Beginning}),
},
{
name: "Multiple tashkeel on one letter",
input: "بًّ", // Beh + Tanween_Fath + Shadda
// No ligature for Tanween_Fath+Shadda, output separately
expected: string([]rune{TANWEEN_FATH, SHADDA, BEH.Isolated}),
},
{
name: "Shadda + Fatha ligature",
input: "رَّ", // Reh + Fatha + Shadda
// Output: Combined Shadda+Fatha ligature
expected: string([]rune{SHADDA_FATHA, REH.Isolated}),
},
{
name: "Shadda + Kasra ligature",
input: "بِّ", // Beh + Kasra + Shadda
// Output: Combined Shadda+Kasra ligature
expected: string([]rune{SHADDA_KASRA, BEH.Isolated}),
},
{
name: "Allah ligature",
input: "الله", // Alef + Lam + Lam + Heh (without tashkeel)
// Now converted to Allah ligature U+FDF2
expected: string([]rune{ALLAH_LIGATURE}),
},
{
name: "Allah in sentence - بسم الله",
input: "بسم الله", // Beh + Seen + Meem + Space + Alef + Lam + Lam + Heh
// Allah becomes ligature U+FDF2
expected: string([]rune{
ALLAH_LIGATURE,
' ',
MEEM.Final, SEEN.Middle, BEH.Beginning,
}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ToArabic(tt.input)
if got != tt.expected {
t.Errorf("ToArabic(%q) = %x, want %x", tt.input, []rune(got), []rune(tt.expected))
}
t.Log(got)
})
}
}
func TestToArabic(t *testing.T) {
tests := []struct {
name string
input string
expected string
}{
{
name: "Normal connected word (Salam)",
input: "سلامً", // Seen, Lam, Alef, Meem, Tanween_Fath
// Seen: Beg (since next is Lam) -> SEEN.Beginning
// Lam+Alef: Ligature. Prev is Seen (connected). -> LAM_ALEF.Final
// Meem: Isolated (since prev LamAlef doesn't connect left). -> MEEM.Isolated
// Tanween_Fath: now comes BEFORE Meem in output
// Reverse order: Tanween+Meem, LamAlef, Seen.
expected: string([]rune{TANWEEN_FATH, MEEM.Isolated, LAM_ALEF.Final, SEEN.Beginning}),
},
{
name: "Isolated Ligature (La)",
input: "لا", // Lam, Alef
// Ligature Isolated.
expected: string([]rune{LAM_ALEF.Isolated}),
},
{
name: "Word without ligature (Kitab)",
input: "كتاب", // Kaf, Teh, Alef, Beh
// Kaf: Beg -> KAF.Beginning
// Teh: Mid -> TEH.Middle
// Alef: Final (connects to Teh) -> ALEF.Final
// Beh: Isolated (Alef doesn't connect left) -> BEH.Isolated
// Reverse: Beh, Alef, Teh, Kaf
expected: string([]rune{BEH.Isolated, ALEF.Final, TEH.Middle, KAF.Beginning}),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := ToArabic(tt.input)
if got != tt.expected {
t.Errorf("ToArabic(%q) = %x, want %x", tt.input, []rune(got), []rune(tt.expected))
}
})
}
}