Skip to content
This repository has been archived by the owner on May 29, 2022. It is now read-only.

Commit

Permalink
Add test cases and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
aslamplr committed Mar 8, 2020
1 parent 33a875f commit 74a3472
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@ pub fn convert_to_mltt(
if let Some(value) = map.get(&key) {
while let Some(index) = text_to_convert.find(&key) {
let right_char = text_to_convert[index - 3..].chars().next().unwrap();
if index >= 9 {
let prev_char = text_to_convert[index - 9..].chars().next().unwrap();
if right_char == prev_char {
let right_char = text_to_convert[index - 9..index]
.chars()
.collect::<String>();
let right_val = map.get(&format!("{}", right_char)).unwrap();
let new_key = format!("{}{}", right_char, key);
let new_val = format!("{}{}", value, right_val);
text_to_convert = text_to_convert.replace(&new_key, &new_val);
continue;
}
if "്ര" == format!("്{}", right_char) {
let prev_right_char = format!("്{}", right_char);
let right_char = text_to_convert[index - 9..].chars().next().unwrap();
let prev_right_val = map.get(&format!("{}", prev_right_char)).unwrap();
let right_val = map.get(&format!("{}", right_char)).unwrap();
let new_key = format!("{}{}{}", right_char, prev_right_char, key);
let new_val = format!("{}{}{}", value, prev_right_val, right_val);
text_to_convert = text_to_convert.replace(&new_key, &new_val);
}
}
let right_val = map.get(&format!("{}", right_char)).unwrap();
let new_key = format!("{}{}", right_char, key);
let new_val = format!("{}{}", value, right_val);
Expand Down
100 changes: 100 additions & 0 deletions tests/convertion.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
extern crate unicode_to_mltt_converter;

use std::error::Error;
use unicode_to_mltt_converter::convert_text;

fn get_map_content() -> Result<String, Box<dyn Error>> {
Ok(std::fs::read_to_string("www/public/karthika.map")?)
}

fn test_convertion(input_text: &str, expected_text: &str) -> Result<(), Box<dyn Error>> {
let map_content = get_map_content()?;
assert_eq!(
convert_text(&input_text, &map_content)?,
String::from(expected_text)
);
Ok(())
}

#[test]
fn convert_case_1() -> Result<(), Box<dyn Error>> {
test_convertion(
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890",
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
)
}

#[test]
fn convert_case_short_1() -> Result<(), Box<dyn Error>> {
test_convertion(
r#"മലയാളം"#,
r#"aebmfw"#
)
}

#[test]
fn convert_case_short_2() -> Result<(), Box<dyn Error>> {
test_convertion(
r#"കേരളം"#,
r#"tIcfw"#
)
}

#[test]
fn convert_case_short_3() -> Result<(), Box<dyn Error>> {
test_convertion(
r#"കാണപ്പെടുന്ന"#,
r#"ImWs¸Sp¶"#
)
}

#[test]
fn convert_case_short_4() -> Result<(), Box<dyn Error>> {
test_convertion(
r#"ഉൾപ്പെടുന്ന"#,
r#"DÄs¸Sp¶"#
)
}

#[test]
fn convert_case_short_5() -> Result<(), Box<dyn Error>> {
test_convertion(
r#"ഫ്രൈ"#,
r#"ss{^"#
)
}

#[test]
fn convert_case_short_6() -> Result<(), Box<dyn Error>> {
test_convertion(
r#"സ്ഥലത്തേ"#,
r#"Øet¯"#
)
}

#[test]
#[ignore]
fn convert_case_short_7() -> Result<(), Box<dyn Error>> {
test_convertion(
r#"കണ്ടെത്താനാവൂ"#,
r#"Is­¯m\mhq"#
)
}

#[test]
#[ignore]
fn convert_case_short_8() -> Result<(), Box<dyn Error>> {
test_convertion(
r#"ക്രിമിനൽ"#,
r#"{Inan\Â"#
)
}

#[test]
#[ignore]
fn convert_case_long_1() -> Result<(), Box<dyn Error>> {
test_convertion(
r#"കേരളത്തിൽ വിരളമായി കാണപ്പെടുന്ന ഒരിനം പൂമ്പാറ്റയാണ് മലബാർ മിന്നൻ (Rapala lankana). ഇന്ത്യയിലെ പശ്ചിമഘട്ടത്തിലെ വളരെ കുറച്ച് സ്ഥലത്തേ അതായത് കേരളം, തമിഴ്നാട്, കർണ്ണാടകം ഉൾപ്പെടുന്ന പ്രദേശങ്ങളിൽ ഇവയെ കണ്ടെത്താനാവൂ."#,
r#"tIcf¯n hncfambn ImWs¸Sp¶ Hcn\w ]q¼mäbmWv ae_mÀ an¶³ (Rapala lankana). C´ybnse ]ÝnaL«¯nse hfsc Ipd¨v Øet¯ AXmbXv tIcfw, Xangv\mSv, IÀ®mSIw DÄs¸Sp¶ {]tZi§fn Chsb Is­¯m\mhq."#
)
}

0 comments on commit 74a3472

Please sign in to comment.