Debian Codegraph @

debian/rust-vendor/zerotrie/tests/ignorecase_test.rs

raw
1 // This file is part of ICU4X. For terms of use, please see the file
2 // called LICENSE at the top level of the ICU4X source tree
3 // (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5 use zerotrie::ZeroAsciiIgnoreCaseTrie;
6
7 mod testdata {
8 include!("data/data.rs");
9 }
10
11 use testdata::strings_to_litemap;
12
13 #[test]
14 fn test_ignore_case_coverage() {
15 let litemap = strings_to_litemap(&["", "aBc", "aBcD", "aBce", "aBcF", "aBcghi"]);
16
17 // Test both construction paths
18 ZeroAsciiIgnoreCaseTrie::try_from(&litemap).unwrap();
19 let trie = litemap
20 .iter()
21 .map(|(k, v)| (*k, *v))
22 .collect::<ZeroAsciiIgnoreCaseTrie<Vec<u8>>>();
23
24 // Test lookup
25 for (k, v) in litemap.iter() {
26 assert_eq!(trie.get(k), Some(*v), "normal: {k:?}");
27 let k_upper = k
28 .iter()
29 .map(|c| c.to_ascii_uppercase())
30 .collect::<Vec<u8>>();
31 assert_eq!(trie.get(k_upper), Some(*v), "upper: {k:?}");
32 let k_lower = k
33 .iter()
34 .map(|c| c.to_ascii_lowercase())
35 .collect::<Vec<u8>>();
36 assert_eq!(trie.get(k_lower), Some(*v), "lower: {k:?}");
37 }
38
39 // Test mixed-case strings
40 let problematic_strs = &["A", "ab", "abc", "aBcd", "aBcgHi"];
41 for problematic_str in problematic_strs {
42 let mut litemap = litemap.clone();
43 litemap.insert(problematic_str.as_bytes(), 100);
44 ZeroAsciiIgnoreCaseTrie::try_from(&litemap).expect_err(problematic_str);
45 }
46 }