xref: /third_party/rust/crates/unicode-ident/tests/compare.rs (revision 6e652d70)
  • Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/rust/crates/unicode-ident/tests/
1mod fst;
2mod roaring;
3mod trie;
4
5#[test]
6fn compare_all_implementations() {
7    let xid_start_fst = fst::xid_start_fst();
8    let xid_continue_fst = fst::xid_continue_fst();
9    let xid_start_roaring = roaring::xid_start_bitmap();
10    let xid_continue_roaring = roaring::xid_continue_bitmap();
11
12    for ch in '\0'..=char::MAX {
13        let thought_to_be_start = unicode_ident::is_xid_start(ch);
14        let thought_to_be_continue = unicode_ident::is_xid_continue(ch);
15
16        // unicode-xid
17        assert_eq!(
18            thought_to_be_start,
19            unicode_xid::UnicodeXID::is_xid_start(ch),
20            "{ch:?}",
21        );
22        assert_eq!(
23            thought_to_be_continue,
24            unicode_xid::UnicodeXID::is_xid_continue(ch),
25            "{ch:?}",
26        );
27
28        // ucd-trie
29        assert_eq!(
30            thought_to_be_start,
31            trie::XID_START.contains_char(ch),
32            "{ch:?}",
33        );
34        assert_eq!(
35            thought_to_be_continue,
36            trie::XID_CONTINUE.contains_char(ch),
37            "{ch:?}",
38        );
39
40        // fst
41        assert_eq!(
42            thought_to_be_start,
43            xid_start_fst.contains((ch as u32).to_be_bytes()),
44            "{ch:?}",
45        );
46        assert_eq!(
47            thought_to_be_continue,
48            xid_continue_fst.contains((ch as u32).to_be_bytes()),
49            "{ch:?}",
50        );
51
52        // roaring
53        assert_eq!(
54            thought_to_be_start,
55            xid_start_roaring.contains(ch as u32),
56            "{ch:?}",
57        );
58        assert_eq!(
59            thought_to_be_continue,
60            xid_continue_roaring.contains(ch as u32),
61            "{ch:?}",
62        );
63    }
64}
65

Indexes created Thu Nov 07 10:32:03 CST 2024