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
|
// 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_property;
use unic_char_property::PartialCharProperty;
char_property! {
pub enum MyProp {
abbr => "mp";
long => "My_Prop";
human => "My Property";
/// Variants can have multi-line documentations,
/// and/or other attributes.
Variant1 {
abbr => V1,
long => Variant_1,
human => "Variant 1",
}
/// One line works too, or...
Variant2 {
abbr => V2,
long => Variant_2,
human => "Variant 2",
}
Variant3 {
abbr => V3,
long => Variant_3,
human => "Variant 3",
}
}
pub mod abbr_names for abbr;
pub mod long_names for long;
}
impl PartialCharProperty for MyProp {
fn of(_: char) -> Option<Self> {
None
}
}
#[test]
fn test_basic_macro_use() {
use unic_char_property::EnumeratedCharProperty;
assert_eq!(MyProp::Variant1, abbr_names::V1);
assert_eq!(MyProp::Variant2, abbr_names::V2);
assert_eq!(MyProp::Variant3, abbr_names::V3);
assert_eq!(MyProp::Variant1, long_names::Variant_1);
assert_eq!(MyProp::Variant2, long_names::Variant_2);
assert_eq!(MyProp::Variant3, long_names::Variant_3);
assert_eq!(MyProp::Variant1.abbr_name(), "V1");
assert_eq!(MyProp::Variant2.abbr_name(), "V2");
assert_eq!(MyProp::Variant3.abbr_name(), "V3");
assert_eq!(MyProp::Variant1.long_name(), "Variant_1");
assert_eq!(MyProp::Variant2.long_name(), "Variant_2");
assert_eq!(MyProp::Variant3.long_name(), "Variant_3");
assert_eq!(MyProp::Variant1.human_name(), "Variant 1");
assert_eq!(MyProp::Variant2.human_name(), "Variant 2");
assert_eq!(MyProp::Variant3.human_name(), "Variant 3");
}
#[test]
fn test_fromstr_ignores_case() {
use crate::abbr_names::V1;
assert_eq!("variant_1".parse(), Ok(V1));
assert_eq!("VaRiAnT_1".parse(), Ok(V1));
assert_eq!("vArIaNt_1".parse(), Ok(V1));
assert_eq!("VARIANT_1".parse(), Ok(V1));
}
|