summaryrefslogtreecommitdiffstats
path: root/vendor/unicode-security/src/tests.rs
blob: 903f385dfe2eb2e903caf9d72f0a4d6921e1914c (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// 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.

#[test]
fn test_general_security_profile_identifier_allowed() {
    use crate::GeneralSecurityProfile;
    assert_eq!(GeneralSecurityProfile::identifier_allowed('A'), true);
    assert_eq!('A'.identifier_allowed(), true);
    assert_eq!(GeneralSecurityProfile::identifier_allowed('0'), true);
    assert_eq!('0'.identifier_allowed(), true);
    assert_eq!(GeneralSecurityProfile::identifier_allowed('_'), true);
    assert_eq!('_'.identifier_allowed(), true);
    assert_eq!(GeneralSecurityProfile::identifier_allowed('\x00'), false);
    assert_eq!('\x00'.identifier_allowed(), false);
    // U+00B5 MICRO SIGN
    assert_eq!(GeneralSecurityProfile::identifier_allowed('µ'), false);
    assert_eq!('µ'.identifier_allowed(), false);
    // U+2160 ROMAN NUMERAL ONE
    assert_eq!(GeneralSecurityProfile::identifier_allowed('Ⅰ'), false);
    assert_eq!('Ⅰ'.identifier_allowed(), false);
}

#[test]
fn test_mixed_script() {
    use crate::MixedScript;
    assert_eq!("".is_single_script(), true);
    assert_eq!("".resolve_script_set().is_empty(), false);
    assert_eq!("".resolve_script_set().is_all(), true);
    assert_eq!("A".is_single_script(), true);
    assert_eq!("A".resolve_script_set().is_empty(), false);
    assert_eq!("A".resolve_script_set().is_all(), false);
    assert_eq!("A0".is_single_script(), true);
    assert_eq!("A0".resolve_script_set().is_empty(), false);
    assert_eq!("A0".resolve_script_set().is_all(), false);
    assert_eq!("0.".is_single_script(), true);
    assert_eq!("0.".resolve_script_set().is_empty(), false);
    assert_eq!("0.".resolve_script_set().is_all(), true);
    assert_eq!("福".is_single_script(), true);
    assert_eq!("福".resolve_script_set().is_empty(), false);
    assert_eq!("福".resolve_script_set().is_all(), false);
    assert_eq!("冬の雪".is_single_script(), true);
    assert_eq!("冬の雪".resolve_script_set().is_empty(), false);
    assert_eq!("冬の雪".resolve_script_set().is_all(), false);
    assert_eq!("幻ㄒㄧㄤ".is_single_script(), true);
    assert_eq!("幻ㄒㄧㄤ".resolve_script_set().is_empty(), false);
    assert_eq!("幻ㄒㄧㄤ".resolve_script_set().is_all(), false);
    assert_eq!("日出은".is_single_script(), true);
    assert_eq!("日出은".resolve_script_set().is_empty(), false);
    assert_eq!("日出은".resolve_script_set().is_all(), false);
    assert_eq!("夏の幻ㄒㄧㄤ".is_single_script(), false);
    assert_eq!("夏の幻ㄒㄧㄤ".resolve_script_set().is_empty(), true);
    assert_eq!("夏の幻ㄒㄧㄤ".resolve_script_set().is_all(), false);
}

#[test]
fn test_confusable_detection() {
    use crate::skeleton;
    use std::string::String;
    assert_eq!(&skeleton("").collect::<String>(), "");
    assert_eq!(&skeleton("s").collect::<String>(), "s");
    assert_eq!(&skeleton("sss").collect::<String>(), "sss");
    assert_eq!(&skeleton("ﶛ").collect::<String>(), "نمى");
    assert_eq!(&skeleton("ﶛﶛ").collect::<String>(), "نمىنمى");
}

#[test]
fn test_potential_mixed_script_detection() {
    use crate::is_potential_mixed_script_confusable_char;

    assert!(is_potential_mixed_script_confusable_char('A'));
    assert!(!is_potential_mixed_script_confusable_char('D'));
}

#[test]
fn test_augmented_script_set_fmt_debug() {
    use crate::mixed_script::AugmentedScriptSet;
    let augmented_script_sets = vec![
        AugmentedScriptSet::default(),
        AugmentedScriptSet::from('0'),
        AugmentedScriptSet::from('a'),
        AugmentedScriptSet::from('μ'),
        AugmentedScriptSet::from('汉'),
        AugmentedScriptSet::from('ひ'),
        AugmentedScriptSet::from('カ'),
        AugmentedScriptSet::from('한'),
        AugmentedScriptSet::from("汉ひ"),
        AugmentedScriptSet::from("汉a"),
        AugmentedScriptSet::from("汉μ"),
        AugmentedScriptSet::from("〆切"),
    ];
    let debug_output = vec![
        "AugmentedScriptSet {ALL}",
        "AugmentedScriptSet {ALL}",
        "AugmentedScriptSet {Latn}",
        "AugmentedScriptSet {Grek}",
        "AugmentedScriptSet {Hanb, Jpan, Kore, Hani}",
        "AugmentedScriptSet {Jpan, Hira}",
        "AugmentedScriptSet {Jpan, Kana}",
        "AugmentedScriptSet {Kore, Hang}",
        "AugmentedScriptSet {Jpan}",
        "AugmentedScriptSet {∅}",
        "AugmentedScriptSet {∅}",
        "AugmentedScriptSet {Hanb, Jpan, Kore, Hani}",
    ];

    for (ss, output) in augmented_script_sets.into_iter().zip(debug_output) {
        assert_eq!(format!("{:?}", ss), output);
    }
}

#[test]
fn test_augmented_script_set_fmt_display() {
    use crate::mixed_script::AugmentedScriptSet;
    let augmented_script_sets = vec![
        AugmentedScriptSet::default(),
        AugmentedScriptSet::from('0'),
        AugmentedScriptSet::from('a'),
        AugmentedScriptSet::from('μ'),
        AugmentedScriptSet::from('汉'),
        AugmentedScriptSet::from('ひ'),
        AugmentedScriptSet::from('カ'),
        AugmentedScriptSet::from('한'),
        AugmentedScriptSet::from("汉ひ"),
        AugmentedScriptSet::from("汉a"),
        AugmentedScriptSet::from("汉μ"),
        AugmentedScriptSet::from("〆切"),
    ];
    let debug_output = vec![
        "All",
        "All",
        "Latin",
        "Greek",
        "Han with Bopomofo, Japanese, Korean, Han",
        "Japanese, Hiragana",
        "Japanese, Katakana",
        "Korean, Hangul",
        "Japanese",
        "Empty",
        "Empty",
        "Han with Bopomofo, Japanese, Korean, Han",
    ];

    for (ss, output) in augmented_script_sets.into_iter().zip(debug_output) {
        assert_eq!(format!("{}", ss), output);
    }
}