| 1 |
// Integration tests from https://github.com/reklatsmasters/saslprep (MIT License) |
| 2 |
extern crate stringprep; |
| 3 |
|
| 4 |
use stringprep::{saslprep, Error}; |
| 5 |
|
| 6 |
fn assert_prohibited_character<T>(result: Result<T, Error>) { |
| 7 |
assert!(result.is_err()); |
| 8 |
} |
| 9 |
|
| 10 |
fn assert_prohibited_bidirectional_text<T>(result: Result<T, Error>) { |
| 11 |
assert!(result.is_err()); |
| 12 |
} |
| 13 |
|
| 14 |
#[test] |
| 15 |
fn should_work_with_latin_letters() { |
| 16 |
assert_eq!(saslprep("user").unwrap(), "user"); |
| 17 |
} |
| 18 |
|
| 19 |
#[test] |
| 20 |
fn should_preserve_case() { |
| 21 |
assert_eq!(saslprep("USER").unwrap(), "USER"); |
| 22 |
} |
| 23 |
|
| 24 |
#[test] |
| 25 |
fn should_remove_mapped_to_nothing() { |
| 26 |
assert_eq!(saslprep("I\u{00AD}X").unwrap(), "IX"); |
| 27 |
} |
| 28 |
|
| 29 |
#[test] |
| 30 |
fn should_replace_non_ascii_space() { |
| 31 |
assert_eq!(saslprep("a\u{00A0}b").unwrap(), "a\u{0020}b"); |
| 32 |
} |
| 33 |
|
| 34 |
#[test] |
| 35 |
fn should_normalize_as_nfkc() { |
| 36 |
assert_eq!(saslprep("\u{00AA}").unwrap(), "a"); |
| 37 |
assert_eq!(saslprep("\u{2168}").unwrap(), "IX"); |
| 38 |
} |
| 39 |
|
| 40 |
#[test] |
| 41 |
fn should_not_allow_prohibited_characters() { |
| 42 |
// C.2.1 ASCII control characters |
| 43 |
assert_prohibited_character(saslprep("a\u{007F}b")); |
| 44 |
|
| 45 |
// C.2.2 Non-ASCII control characters |
| 46 |
assert_prohibited_character(saslprep("a\u{06DD}b")); |
| 47 |
|
| 48 |
// C.3 Private use |
| 49 |
assert_prohibited_character(saslprep("a\u{E000}b")); |
| 50 |
|
| 51 |
// C.4 Non-character code points |
| 52 |
assert_prohibited_character(saslprep("a\u{1FFFE}b")); |
| 53 |
|
| 54 |
// C.5 Surrogate codes |
| 55 |
// forbidden by rust |
| 56 |
|
| 57 |
// C.6 Inappropriate for plain text |
| 58 |
assert_prohibited_character(saslprep("a\u{FFF9}b")); |
| 59 |
|
| 60 |
// C.7 Inappropriate for canonical representation |
| 61 |
assert_prohibited_character(saslprep("a\u{2FF0}b")); |
| 62 |
|
| 63 |
// C.8 Change display properties or are deprecated |
| 64 |
assert_prohibited_character(saslprep("a\u{200E}b")); |
| 65 |
|
| 66 |
// C.9 Tagging characters |
| 67 |
assert_prohibited_character(saslprep("a\u{E0001}b")); |
| 68 |
} |
| 69 |
|
| 70 |
#[test] |
| 71 |
fn randalcat_should_be_first_and_last() { |
| 72 |
assert_eq!( |
| 73 |
saslprep("\u{0627}\u{0031}\u{0628}").unwrap(), |
| 74 |
"\u{0627}\u{0031}\u{0628}" |
| 75 |
); |
| 76 |
assert_prohibited_bidirectional_text(saslprep("\u{0627}\u{0031}")); |
| 77 |
} |
| 78 |
|
| 79 |
#[test] |
| 80 |
fn should_handle_unassigned_code_points() { |
| 81 |
assert_prohibited_character(saslprep("a\u{0487}")); |
| 82 |
} |