|
| 1 | +use core::unicode::unicode_data; |
| 2 | +use std::ops::RangeInclusive; |
| 3 | + |
| 4 | +mod test_data; |
| 5 | + |
1 | 6 | #[test] |
2 | 7 | pub fn version() { |
3 | 8 | let (major, _minor, _update) = core::char::UNICODE_VERSION; |
4 | 9 | assert!(major >= 10); |
5 | 10 | } |
| 11 | + |
| 12 | +#[track_caller] |
| 13 | +fn test_boolean_property(ranges: &[RangeInclusive<char>], lookup: fn(char) -> bool) { |
| 14 | + let mut start = '\u{80}'; |
| 15 | + for range in ranges { |
| 16 | + for c in start..*range.start() { |
| 17 | + assert!(!lookup(c), "{c:?}"); |
| 18 | + } |
| 19 | + for c in range.clone() { |
| 20 | + assert!(lookup(c), "{c:?}"); |
| 21 | + } |
| 22 | + start = char::from_u32(*range.end() as u32 + 1).unwrap(); |
| 23 | + } |
| 24 | + for c in start..=char::MAX { |
| 25 | + assert!(!lookup(c), "{c:?}"); |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +#[track_caller] |
| 30 | +fn test_case_mapping(ranges: &[(char, [char; 3])], lookup: fn(char) -> [char; 3]) { |
| 31 | + let mut start = '\u{80}'; |
| 32 | + for &(key, val) in ranges { |
| 33 | + for c in start..key { |
| 34 | + assert_eq!(lookup(c), [c, '\0', '\0'], "{c:?}"); |
| 35 | + } |
| 36 | + assert_eq!(lookup(key), val, "{key:?}"); |
| 37 | + start = char::from_u32(key as u32 + 1).unwrap(); |
| 38 | + } |
| 39 | + for c in start..=char::MAX { |
| 40 | + assert_eq!(lookup(c), [c, '\0', '\0'], "{c:?}"); |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +#[test] |
| 45 | +#[cfg_attr(miri, ignore)] |
| 46 | +fn alphabetic() { |
| 47 | + test_boolean_property(test_data::ALPHABETIC, unicode_data::alphabetic::lookup); |
| 48 | +} |
| 49 | + |
| 50 | +#[test] |
| 51 | +#[cfg_attr(miri, ignore)] |
| 52 | +fn case_ignorable() { |
| 53 | + test_boolean_property(test_data::CASE_IGNORABLE, unicode_data::case_ignorable::lookup); |
| 54 | +} |
| 55 | + |
| 56 | +#[test] |
| 57 | +#[cfg_attr(miri, ignore)] |
| 58 | +fn cased() { |
| 59 | + test_boolean_property(test_data::CASED, unicode_data::cased::lookup); |
| 60 | +} |
| 61 | + |
| 62 | +#[test] |
| 63 | +#[cfg_attr(miri, ignore)] |
| 64 | +fn grapheme_extend() { |
| 65 | + test_boolean_property(test_data::GRAPHEME_EXTEND, unicode_data::grapheme_extend::lookup); |
| 66 | +} |
| 67 | + |
| 68 | +#[test] |
| 69 | +#[cfg_attr(miri, ignore)] |
| 70 | +fn lowercase() { |
| 71 | + test_boolean_property(test_data::LOWERCASE, unicode_data::lowercase::lookup); |
| 72 | +} |
| 73 | + |
| 74 | +#[test] |
| 75 | +fn n() { |
| 76 | + test_boolean_property(test_data::N, unicode_data::n::lookup); |
| 77 | +} |
| 78 | + |
| 79 | +#[test] |
| 80 | +#[cfg_attr(miri, ignore)] |
| 81 | +fn uppercase() { |
| 82 | + test_boolean_property(test_data::UPPERCASE, unicode_data::uppercase::lookup); |
| 83 | +} |
| 84 | + |
| 85 | +#[test] |
| 86 | +#[cfg_attr(miri, ignore)] |
| 87 | +fn white_space() { |
| 88 | + test_boolean_property(test_data::WHITE_SPACE, unicode_data::white_space::lookup); |
| 89 | +} |
| 90 | + |
| 91 | +#[test] |
| 92 | +#[cfg_attr(miri, ignore)] |
| 93 | +fn to_lowercase() { |
| 94 | + test_case_mapping(test_data::TO_LOWER, unicode_data::conversions::to_lower); |
| 95 | +} |
| 96 | + |
| 97 | +#[test] |
| 98 | +#[cfg_attr(miri, ignore)] |
| 99 | +fn to_uppercase() { |
| 100 | + test_case_mapping(test_data::TO_UPPER, unicode_data::conversions::to_upper); |
| 101 | +} |
0 commit comments