include!(concat!(env!("OUT_DIR"), "/case_folding_table.rs"));
pub fn simple_upper_folding() -> &'static [(u32, u32)] {
SIMPLE_UPPER_FOLDING
}
pub fn simple_lower_folding() -> &'static [(u32, u32)] {
SIMPLE_LOWER_FOLDING
}
pub fn encode_table_bytes(table: &[(u32, u32)]) -> Vec<u8> {
super::encode_u32_pair_table(table)
}
pub fn encoded_table_size(table: &[(u32, u32)]) -> usize {
super::encoded_u32_pair_table_size(table.len())
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn upper_table_sorted_and_non_empty() {
let table = SIMPLE_UPPER_FOLDING;
assert!(!table.is_empty(), "upper table must not be empty");
for win in table.windows(2) {
assert!(win[0].0 < win[1].0, "upper table must be sorted asc");
}
}
#[test]
fn lower_table_sorted_and_non_empty() {
let table = SIMPLE_LOWER_FOLDING;
assert!(!table.is_empty(), "lower table must not be empty");
for win in table.windows(2) {
assert!(win[0].0 < win[1].0, "lower table must be sorted asc");
}
}
#[test]
fn ascii_letters_present() {
let upper = SIMPLE_UPPER_FOLDING
.iter()
.find(|(k, _)| *k == 'a' as u32)
.expect("a -> A mapping");
assert_eq!(upper.1, 'A' as u32);
let lower = SIMPLE_LOWER_FOLDING
.iter()
.find(|(k, _)| *k == 'A' as u32)
.expect("A -> a mapping");
assert_eq!(lower.1, 'a' as u32);
}
#[test]
fn cyrillic_letters_present() {
let lower = SIMPLE_LOWER_FOLDING
.iter()
.find(|(k, _)| *k == 0x0420)
.expect("Р -> р mapping");
assert_eq!(lower.1, 0x0440);
let upper = SIMPLE_UPPER_FOLDING
.iter()
.find(|(k, _)| *k == 0x0440)
.expect("р -> Р mapping");
assert_eq!(upper.1, 0x0420);
}
#[test]
fn encode_table_bytes_layout() {
let toy: &[(u32, u32)] = &[(0x61, 0x41), (0x62, 0x42)];
let bytes = encode_table_bytes(toy);
assert_eq!(bytes.len(), 4 + 16);
assert_eq!(&bytes[0..4], &2u32.to_le_bytes());
assert_eq!(&bytes[4..8], &0x61u32.to_le_bytes());
assert_eq!(&bytes[8..12], &0x41u32.to_le_bytes());
}
}