Skip to content

Commit

Permalink
Simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sancane committed Dec 4, 2021
1 parent b56bf95 commit dea87c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 41 deletions.
30 changes: 10 additions & 20 deletions precis-profiles/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,47 +77,37 @@ mod profile_rules {
#[test]
fn test_normalization_rule() {
let res = normalization_form_nfc("");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "");
assert_eq!(res, Ok(Cow::from("")));

let res = normalization_form_nfc("\u{212b}");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "\u{00c5}");
assert_eq!(res, Ok(Cow::from("\u{00c5}")));

let res = normalization_form_nfc("a\u{212b}");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "a\u{00c5}");
assert_eq!(res, Ok(Cow::from("a\u{00c5}")));

let res = normalization_form_nfc("\u{212b}a");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "\u{00c5}a");
assert_eq!(res, Ok(Cow::from("\u{00c5}a")));

let res = normalization_form_nfc("\u{212b}\u{2126}\u{1e0b}\u{0323}");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "\u{00c5}\u{03a9}\u{1e0d}\u{0307}");
assert_eq!(res, Ok(Cow::from("\u{00c5}\u{03a9}\u{1e0d}\u{0307}")));
}

#[test]
fn test_case_mapping_rule() {
let res = case_mapping_rule("");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "");
assert_eq!(res, Ok(Cow::from("")));

let res = case_mapping_rule("T");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "t");
assert_eq!(res, Ok(Cow::from("t")));

let res = case_mapping_rule("aT");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "at");
assert_eq!(res, Ok(Cow::from("at")));

let res = case_mapping_rule("Ta");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "ta");
assert_eq!(res, Ok(Cow::from("ta")));

let res = case_mapping_rule("TestUserName");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "testusername");
assert_eq!(res, Ok(Cow::from("testusername")));
}

#[test]
Expand Down
32 changes: 11 additions & 21 deletions precis-profiles/src/usernames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,55 +294,45 @@ mod profile_rules {
#[test]
fn test_width_mapping_rule() {
let res = width_mapping_rule("");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "");
assert_eq!(res, Ok(Cow::from("")));

// Valid username with no modifications
let res = width_mapping_rule("TestName");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "TestName");
assert_eq!(res, Ok(Cow::from("TestName")));

// Mapping code point `U+FF03` (`#`) to `U+0023` (`#`)
let res = width_mapping_rule("\u{ff03}");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "\u{0023}");
assert_eq!(res, Ok(Cow::from("\u{0023}")));

let res = width_mapping_rule("a\u{ff03}");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "a\u{0023}");
assert_eq!(res, Ok(Cow::from("a\u{0023}")));

let res = width_mapping_rule("\u{ff03}a");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "\u{0023}a");
assert_eq!(res, Ok(Cow::from("\u{0023}a")));

let res = width_mapping_rule("\u{ff03}\u{ff03}\u{ff03}");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "\u{0023}\u{0023}\u{0023}");
assert_eq!(res, Ok(Cow::from("\u{0023}\u{0023}\u{0023}")));
}

#[test]
fn test_directionality_rule() {
let res = directionality_rule("");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "");
assert_eq!(res, Ok(Cow::from("")));

// No `RTL` label
let res = directionality_rule("Hello");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "Hello");
assert_eq!(res, Ok(Cow::from("Hello")));

// `RTL` label
let res = directionality_rule("\u{05be}");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "\u{05be}");
assert_eq!(res, Ok(Cow::from("\u{05be}")));

// `LTR` label
let res = directionality_rule("\u{00aa}");
assert_eq!(res.is_ok(), true);
assert_eq!(res.unwrap(), "\u{00aa}");
assert_eq!(res, Ok(Cow::from("\u{00aa}")));

// Invalid label
let res = directionality_rule("\u{05be}Hello");
assert_eq!(res.is_ok(), false);
assert_eq!(res, Err(Error::Invalid));
}
}

0 comments on commit dea87c3

Please sign in to comment.