Skip to content

Commit

Permalink
add test cases and adjust (reduce) the transliteration (#37)
Browse files Browse the repository at this point in the history
* update tests

* revisit transliteration

* add more test cases and adjust the transliteration

* bump version
  • Loading branch information
alpancs authored Mar 20, 2024
1 parent 7f4143b commit c75f530
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "quranize"
version = "0.11.1"
version = "0.11.2"
authors = ["Alfan Nur Fauzan <[email protected]>"]
edition = "2021"
description = "Encoding transliterations into Quran forms."
Expand Down
12 changes: 8 additions & 4 deletions src/quranize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ mod tests {

#[test]
fn test_quranize_default() {
let q = Quranize::new(70);
let q = Quranize::default();
assert_eq!(q.e("allah"), vec!["اللَّهَ", "اللَّهُ", "ءاللَّهُ", "اللَّهِ"]);
assert_eq!(q.e("illa billah"), vec!["إِلّا بِاللَّهِ"]);
assert_eq!(q.e("alquran"), vec!["القُرءانَ", "القُرءانُ", "القُرءانِ"]);
Expand All @@ -225,6 +225,7 @@ mod tests {
assert_eq!(q.e("qulhuwallahuahad"), vec!["قُل هُوَ اللَّهُ أَحَدٌ"]);
assert_eq!(q.e("alla tahzani"), vec!["أَلّا تَحزَنى"]);
assert_eq!(q.e("innasya niaka"), vec!["إِنَّ شانِئَكَ"]);
assert_eq!(q.e("innasya ni'aka"), vec!["إِنَّ شانِئَكَ"]);
assert_eq!(q.e("wasalamun alaihi"), vec!["وَسَلٰمٌ عَلَيهِ"]);
assert_eq!(q.e("ulaika hum"), vec!["أُولٰئِكَ هُم", "أُولٰئِكَ هُمُ"]);
assert_eq!(q.e("waladdoollin"), vec!["وَلَا الضّالّينَ"]);
Expand All @@ -235,11 +236,14 @@ mod tests {
assert_eq!(q.e("robbil alamin"), vec!["رَبِّ العٰلَمينَ"]);
assert_eq!(q.e("husnul maab"), vec!["حُسنُ المَـٔابِ"]);
assert_eq!(q.e("kufuwan"), vec!["كُفُوًا"]);
assert_eq!(q.e("yukhodiun"), vec!["يُخٰدِعونَ"]);
assert_eq!(q.e("indallah"), vec!["عِندَ اللَّهِ", "عِندِ اللَّهِ"]);
assert_eq!(q.e("alimul ghoibi"), vec!["عٰلِمُ الغَيبِ"]);
}

#[test]
fn test_first_aya() {
let q = Quranize::new(70);
let q = Quranize::new(25);
assert_eq!(q.e("alif lam mim"), vec!["الم"]);
assert_eq!(q.e("alif laaam miiim"), vec!["الم"]);
assert_eq!(q.e("nuun"), vec!["ن"]);
Expand All @@ -249,7 +253,7 @@ mod tests {

#[test]
fn test_alfatihah() {
let q = Quranize::default();
let q = Quranize::new(100);
assert_eq!(
q.e("bismillahirrohmanirrohiim"),
vec!["بِسمِ اللَّهِ الرَّحمٰنِ الرَّحيمِ"]
Expand All @@ -273,7 +277,7 @@ mod tests {

#[test]
fn test_al_ikhlas() {
let q = Quranize::new(70);
let q = Quranize::new(50);
assert_eq!(q.e("qulhuwallahuahad"), vec!["قُل هُوَ اللَّهُ أَحَدٌ"]);
assert_eq!(q.e("allahussomad"), vec!["اللَّهُ الصَّمَدُ"]);
assert_eq!(q.e("lam yalid walam yulad"), vec!["لَم يَلِد وَلَم يولَد"]);
Expand Down
19 changes: 10 additions & 9 deletions src/quranize/transliterations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ pub(super) fn map(c: char) -> &'static [&'static str] {
match c {
SPACE => &[""],

LETTER_HAMZA => &["'", "k", "a", "i", "u"],
LETTER_ALEF_WITH_MADDA_ABOVE => &["a", "'a", "aa"],
LETTER_ALEF_WITH_HAMZA_ABOVE => &["'", "k", "a", "u"],
LETTER_WAW_WITH_HAMZA_ABOVE => &["'", "k", "u"],
LETTER_HAMZA => &["'", "a"],
LETTER_ALEF_WITH_MADDA_ABOVE => &["a", "aa"],
LETTER_ALEF_WITH_HAMZA_ABOVE => &["a", "u"],
LETTER_WAW_WITH_HAMZA_ABOVE => &["u"],
LETTER_ALEF_WITH_HAMZA_BELOW => &["i"],
LETTER_YEH_WITH_HAMZA_ABOVE => &["'", "k", "a", "i"],
LETTER_ALEF => &["a", "o", "aa", "oo"],
LETTER_YEH_WITH_HAMZA_ABOVE => &["'", "a", "i"],
LETTER_ALEF => &["a", "aa", "o", "oo"],
LETTER_BEH => &["b"],
LETTER_TEH_MARBUTA => &["h", "t"],
LETTER_TEH => &["t"],
Expand All @@ -32,7 +32,7 @@ pub(super) fn map(c: char) -> &'static [&'static str] {
LETTER_DAD => &["d", "dh", "dz"],
LETTER_TAH => &["t", "th"],
LETTER_ZAH => &["d", "dh", "dz"],
LETTER_AIN => &["'", "'a", "'i", "'u", "k", "a", "i", "u"],
LETTER_AIN => &["'", "a", "u", "i", "k"],
LETTER_GHAIN => &["g", "gh"],

TATWEEL => &["a", "o"],
Expand All @@ -44,9 +44,9 @@ pub(super) fn map(c: char) -> &'static [&'static str] {
LETTER_MEEM => &["m"],
LETTER_NOON => &["n"],
LETTER_HEH => &["h"],
LETTER_WAW => &["w", "u"],
LETTER_WAW => &["w", "u", "uu"],
LETTER_ALEF_MAKSURA => &["a", "o", "i"],
LETTER_YEH => &["y", "i", "ii", "iya", "iyi", "iyu"],
LETTER_YEH => &["y", "i", "ii"],

FATHATAN => &["an", "on", ""],
DAMMATAN => &["un", ""],
Expand All @@ -67,6 +67,7 @@ pub(super) fn contextual_map(c0: char, c1: char) -> &'static [&'static str] {
(SPACE, LETTER_ALEF)
| (LETTER_HAMZA, LETTER_ALEF)
| (LETTER_ALEF, LETTER_LAM)
| (LETTER_AIN, LETTER_WAW)
| (LETTER_AIN, LETTER_SUPERSCRIPT_ALEF)
| (LETTER_WAW, LETTER_ALEF)
| (FATHATAN, LETTER_ALEF)
Expand Down

0 comments on commit c75f530

Please sign in to comment.