-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathquranize_test.go
116 lines (101 loc) · 3.84 KB
/
quranize_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
package quranize
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
var (
quranizeTest Quranize
)
func TestMain(m *testing.M) {
quranizeTest = NewDefaultQuranize()
os.Exit(m.Run())
}
func TestEncodeEmptyString(t *testing.T) {
input := ""
expected := []string{}
actual := quranizeTest.Encode(input)
assert.Equal(t, expected, actual)
}
func TestEncodeNonAlquran(t *testing.T) {
input := "alfan nur fauzan"
expected := []string{}
actual := quranizeTest.Encode(input)
assert.Equal(t, expected, actual)
}
func TestEncodeAlquran(t *testing.T) {
testCases := map[string][]string{
"tajri": {"تجري"},
"alhamdulillah": {"الحمد لله"},
"bismillah": {"بسم الله", "بشماله"},
"wa'tasimu": {"واعتصموا"},
"wa'tasimu bihablillah": {"واعتصموا بحبل الله"},
"shummun bukmun": {"صم وبكم", "صم بكم", "الصم البكم"},
"kahfi": {"الكهف"},
"wabasyiris sobirin": {"وبشر الصابرين"},
"bissobri wassolah": {"بالصبر والصلاة"},
"ya aiyuhalladzina": {"يا أيها الذين"},
"syai in 'alim": {"شيء عليم"},
"'alal qoumil kafirin": {"على القوم الكافرين"},
"subhanalladzi asro": {"سبحان الذي أسرى"},
"sabbihisma robbikal": {"سبح اسم ربك"},
"hal ataka hadisul": {"هل أتاك حديث"},
"kutiba 'alaikumus": {"كتب عليكم"},
"bismillah hirrohman nirrohim": {"بسم الله الرحمن الرحيم"},
"bismillaahirrahmaanirrahiim": {"بسم الله الرحمن الرحيم"},
"alhamdu lillahi robbil 'alamin": {"الحمد لله رب العالمين"},
"arrohma nirrohim": {"الرحمن الرحيم"},
"maaliki yau middin": {"مالك يوم الدين", "الملك يومئذ"},
"iyya kanakbudu waiyya kanastain": {"إياك نعبد وإياك نستعين"},
"ihdinash shirothol mustaqim": {"اهدنا الصراط المستقيم"},
"shirotholladzina an'am ta'alaihim ghoiril maghdzu bi'alaihim waladh dhollin": {"صراط الذين أنعمت عليهم غير المغضوب عليهم ولا الضالين"},
}
for input, expected := range testCases {
actual := quranizeTest.Encode(input)
assert.ElementsMatchf(t, expected, actual, "input = %#v\nexpected = %#v\nactual = %#v", input, expected, actual)
}
}
func ExampleQuranize_Encode() {
quranize := NewDefaultQuranize()
fmt.Println(quranize.Encode("alhamdulillah hirobbil 'alamin"))
// Output: [الحمد لله رب العالمين]
}
func ExampleQuranize_Locate() {
quranize := NewDefaultQuranize()
fmt.Println(quranize.Locate("الحمد لله رب العالمين"))
// Output: [{1 2 0} {10 10 10} {39 75 13} {40 65 10}]
}
func TestLocateEmptyString(t *testing.T) {
input := ""
expected := zeroLocs
actual := quranizeTest.Locate(input)
assert.Equal(t, expected, actual)
}
func TestLocateNonAlquran(t *testing.T) {
input := "alfan"
expected := zeroLocs
actual := quranizeTest.Locate(input)
assert.Equal(t, expected, actual)
}
func TestLocateAlquran(t *testing.T) {
input := "بسم الله الرحمن الرحيم"
expected := []Location{NewLocation(1, 1, 0), NewLocation(27, 30, 4)}
actual := quranizeTest.Locate(input)
assert.Equal(t, expected, actual)
}
func TestLocateAlquranBeforeBuildIndex(t *testing.T) {
root := quranizeTest.root
defer func() { quranizeTest.root = root }()
quranizeTest.root = nil
input := "بسم الله الرحمن الرحيم"
expected := zeroLocs
actual := quranizeTest.Locate(input)
assert.Equal(t, expected, actual)
}
func TestRemoveConsecutiveChars(t *testing.T) {
input := "bismillaahirrahmaanirrahiim"
expected := "bismilahirahmanirahim"
actual := removeConsecutiveChars(input)
assert.Equal(t, expected, actual)
}