summaryrefslogtreecommitdiffstats
path: root/vendor/unic-char-property/tests/tables_tests.rs
blob: d206495879449a35970b209bbd8f9d8cd8e186f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2017 The UNIC Project Developers.
//
// See the COPYRIGHT file at the top-level directory of this distribution.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[macro_use]
extern crate unic_char_range;

use unic_char_property::tables::CharDataTable;

#[test]
fn test_range_value_table() {
    const TABLE: CharDataTable<u32> = CharDataTable::Range(&[
        (chars!('a'..='g'), 1),
        (chars!('j'..='q'), 2),
        (chars!('w'..='z'), 3),
    ]);
    for ch in chars!('a'..='g') {
        assert_eq!(TABLE.find(ch), Some(1));
        assert_eq!(TABLE.find_or_default(ch), 1);
    }
    for ch in chars!('h'..='i') {
        assert_eq!(TABLE.find(ch), None);
        assert_eq!(TABLE.find_or_default(ch), 0);
    }
    for ch in chars!('j'..='q') {
        assert_eq!(TABLE.find(ch), Some(2));
        assert_eq!(TABLE.find_or_default(ch), 2);
    }
    for ch in chars!('r'..='v') {
        assert_eq!(TABLE.find(ch), None);
        assert_eq!(TABLE.find_or_default(ch), 0);
    }
    for ch in chars!('x'..='z') {
        assert_eq!(TABLE.find(ch), Some(3));
        assert_eq!(TABLE.find_or_default(ch), 3);
    }
}