@@ -30,7 +30,7 @@ pub use crate::bidi::{BidiMirroringGlyph, BidiPairedBracketType};
30
30
/// ...
31
31
/// }
32
32
/// ```
33
- /// Produces `const ALL_CONSTS = &[("Neutral", 0u16), ...];` by
33
+ /// Produces `const ALL_VALUES = &[("Neutral", 0u16), ...];` by
34
34
/// explicitly casting first field of the struct to u16.
35
35
macro_rules! create_const_array {
36
36
(
@@ -46,11 +46,19 @@ macro_rules! create_const_array {
46
46
$v const $i: $t = $e;
47
47
) *
48
48
49
- #[ cfg( test) ]
50
- const ALL_CONSTS : & ' static [ ( & ' static str , u16 ) ] = & [
51
- $( ( stringify!( $i) , $enum_ty:: $i. 0 as u16 ) ) ,*
49
+ /// All possible values of this enum in the Unicode version
50
+ /// from this ICU4X release.
51
+ pub const ALL_VALUES : & ' static [ $enum_ty] = & [
52
+ $( $enum_ty:: $i) ,*
52
53
] ;
53
54
}
55
+
56
+
57
+ impl From <$enum_ty> for u16 {
58
+ fn from( other: $enum_ty) -> Self {
59
+ other. 0 as u16
60
+ }
61
+ }
54
62
}
55
63
}
56
64
@@ -269,6 +277,42 @@ pub(crate) mod gc {
269
277
270
278
pub use gc:: GeneralCategory ;
271
279
280
+ impl GeneralCategory {
281
+ /// All possible values of this enum
282
+ pub const ALL_VALUES : & ' static [ GeneralCategory ] = & [
283
+ GeneralCategory :: Unassigned ,
284
+ GeneralCategory :: UppercaseLetter ,
285
+ GeneralCategory :: LowercaseLetter ,
286
+ GeneralCategory :: TitlecaseLetter ,
287
+ GeneralCategory :: ModifierLetter ,
288
+ GeneralCategory :: OtherLetter ,
289
+ GeneralCategory :: NonspacingMark ,
290
+ GeneralCategory :: SpacingMark ,
291
+ GeneralCategory :: EnclosingMark ,
292
+ GeneralCategory :: DecimalNumber ,
293
+ GeneralCategory :: LetterNumber ,
294
+ GeneralCategory :: OtherNumber ,
295
+ GeneralCategory :: SpaceSeparator ,
296
+ GeneralCategory :: LineSeparator ,
297
+ GeneralCategory :: ParagraphSeparator ,
298
+ GeneralCategory :: Control ,
299
+ GeneralCategory :: Format ,
300
+ GeneralCategory :: PrivateUse ,
301
+ GeneralCategory :: Surrogate ,
302
+ GeneralCategory :: DashPunctuation ,
303
+ GeneralCategory :: OpenPunctuation ,
304
+ GeneralCategory :: ClosePunctuation ,
305
+ GeneralCategory :: ConnectorPunctuation ,
306
+ GeneralCategory :: InitialPunctuation ,
307
+ GeneralCategory :: FinalPunctuation ,
308
+ GeneralCategory :: OtherPunctuation ,
309
+ GeneralCategory :: MathSymbol ,
310
+ GeneralCategory :: CurrencySymbol ,
311
+ GeneralCategory :: ModifierSymbol ,
312
+ GeneralCategory :: OtherSymbol ,
313
+ ] ;
314
+ }
315
+
272
316
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , Debug , Hash , Default ) ]
273
317
/// Error value for `impl TryFrom<u8> for GeneralCategory`.
274
318
#[ non_exhaustive]
@@ -620,6 +664,7 @@ impl From<GeneralCategoryGroup> for u32 {
620
664
#[ repr( transparent) ]
621
665
pub struct Script ( pub u16 ) ;
622
666
667
+ create_const_array ! {
623
668
#[ allow( missing_docs) ] // These constants don't need individual documentation.
624
669
#[ allow( non_upper_case_globals) ]
625
670
impl Script {
@@ -789,6 +834,7 @@ impl Script {
789
834
pub const Yi : Script = Script ( 41 ) ;
790
835
pub const ZanabazarSquare : Script = Script ( 177 ) ;
791
836
}
837
+ }
792
838
793
839
make_enumerated_property ! {
794
840
name: "Script" ;
@@ -933,6 +979,7 @@ make_enumerated_property! {
933
979
#[ repr( transparent) ]
934
980
pub struct LineBreak ( pub u8 ) ;
935
981
982
+ create_const_array ! {
936
983
#[ allow( missing_docs) ] // These constants don't need individual documentation.
937
984
#[ allow( non_upper_case_globals) ]
938
985
impl LineBreak {
@@ -987,6 +1034,7 @@ impl LineBreak {
987
1034
pub const ViramaFinal : LineBreak = LineBreak ( 46 ) ; // name=VF"
988
1035
pub const Virama : LineBreak = LineBreak ( 47 ) ; // name=VI"
989
1036
}
1037
+ }
990
1038
991
1039
make_enumerated_property ! {
992
1040
name: "Line_Break" ;
@@ -1026,6 +1074,7 @@ make_enumerated_property! {
1026
1074
#[ repr( transparent) ]
1027
1075
pub struct GraphemeClusterBreak ( pub u8 ) ;
1028
1076
1077
+ create_const_array ! {
1029
1078
#[ allow( missing_docs) ] // These constants don't need individual documentation.
1030
1079
#[ allow( non_upper_case_globals) ]
1031
1080
impl GraphemeClusterBreak {
@@ -1052,6 +1101,7 @@ impl GraphemeClusterBreak {
1052
1101
pub const GlueAfterZwj : GraphemeClusterBreak = GraphemeClusterBreak ( 16 ) ; // name="GAZ"
1053
1102
pub const ZWJ : GraphemeClusterBreak = GraphemeClusterBreak ( 17 ) ; // name="ZWJ"
1054
1103
}
1104
+ }
1055
1105
1056
1106
make_enumerated_property ! {
1057
1107
name: "Grapheme_Cluster_Break" ;
@@ -2956,19 +3006,28 @@ mod test_enumerated_property_completeness {
2956
3006
use super :: * ;
2957
3007
use alloc:: collections:: BTreeMap ;
2958
3008
2959
- fn check_enum < ' a > (
3009
+ fn check_enum < ' a , T : NamedEnumeratedProperty > (
2960
3010
lookup : & crate :: provider:: names:: PropertyValueNameToEnumMapV1 < ' static > ,
2961
- consts : impl IntoIterator < Item = & ' a ( & ' static str , u16 ) > ,
2962
- ) {
3011
+ consts : impl IntoIterator < Item = & ' a T > ,
3012
+ ) where
3013
+ u16 : From < T > ,
3014
+ {
2963
3015
let mut data: BTreeMap < _ , _ > = lookup
2964
3016
. map
2965
3017
. iter ( )
2966
3018
. map ( |( name, value) | ( value, ( name, "Data" ) ) )
2967
3019
. collect ( ) ;
2968
3020
2969
- let consts = consts
2970
- . into_iter ( )
2971
- . map ( |( name, value) | ( * value as usize , ( name. to_string ( ) , "Consts" ) ) ) ;
3021
+ let names = crate :: PropertyNamesLong :: < T > :: new ( ) ;
3022
+ let consts = consts. into_iter ( ) . map ( |value| {
3023
+ (
3024
+ u16:: from ( * value) as usize ,
3025
+ (
3026
+ names. get ( * value) . unwrap_or ( "<unknown>" ) . to_string ( ) ,
3027
+ "Consts" ,
3028
+ ) ,
3029
+ )
3030
+ } ) ;
2972
3031
2973
3032
let mut diff = Vec :: new ( ) ;
2974
3033
for t @ ( value, _) in consts {
@@ -2994,63 +3053,63 @@ mod test_enumerated_property_completeness {
2994
3053
fn test_ea ( ) {
2995
3054
check_enum (
2996
3055
crate :: provider:: Baked :: SINGLETON_EAST_ASIAN_WIDTH_NAME_TO_VALUE_V2_MARKER ,
2997
- EastAsianWidth :: ALL_CONSTS ,
3056
+ EastAsianWidth :: ALL_VALUES ,
2998
3057
) ;
2999
3058
}
3000
3059
3001
3060
#[ test]
3002
3061
fn test_ccc ( ) {
3003
3062
check_enum (
3004
3063
crate :: provider:: Baked :: SINGLETON_CANONICAL_COMBINING_CLASS_NAME_TO_VALUE_V2_MARKER ,
3005
- CanonicalCombiningClass :: ALL_CONSTS ,
3064
+ CanonicalCombiningClass :: ALL_VALUES ,
3006
3065
) ;
3007
3066
}
3008
3067
3009
3068
#[ test]
3010
3069
fn test_jt ( ) {
3011
3070
check_enum (
3012
3071
crate :: provider:: Baked :: SINGLETON_JOINING_TYPE_NAME_TO_VALUE_V2_MARKER ,
3013
- JoiningType :: ALL_CONSTS ,
3072
+ JoiningType :: ALL_VALUES ,
3014
3073
) ;
3015
3074
}
3016
3075
3017
3076
#[ test]
3018
3077
fn test_insc ( ) {
3019
3078
check_enum (
3020
3079
crate :: provider:: Baked :: SINGLETON_INDIC_SYLLABIC_CATEGORY_NAME_TO_VALUE_V2_MARKER ,
3021
- IndicSyllabicCategory :: ALL_CONSTS ,
3080
+ IndicSyllabicCategory :: ALL_VALUES ,
3022
3081
) ;
3023
3082
}
3024
3083
3025
3084
#[ test]
3026
3085
fn test_sb ( ) {
3027
3086
check_enum (
3028
3087
crate :: provider:: Baked :: SINGLETON_SENTENCE_BREAK_NAME_TO_VALUE_V2_MARKER ,
3029
- SentenceBreak :: ALL_CONSTS ,
3088
+ SentenceBreak :: ALL_VALUES ,
3030
3089
) ;
3031
3090
}
3032
3091
3033
3092
#[ test]
3034
3093
fn test_wb ( ) {
3035
3094
check_enum (
3036
3095
crate :: provider:: Baked :: SINGLETON_WORD_BREAK_NAME_TO_VALUE_V2_MARKER ,
3037
- WordBreak :: ALL_CONSTS ,
3096
+ WordBreak :: ALL_VALUES ,
3038
3097
) ;
3039
3098
}
3040
3099
3041
3100
#[ test]
3042
3101
fn test_bc ( ) {
3043
3102
check_enum (
3044
3103
crate :: provider:: Baked :: SINGLETON_BIDI_CLASS_NAME_TO_VALUE_V2_MARKER ,
3045
- BidiClass :: ALL_CONSTS ,
3104
+ BidiClass :: ALL_VALUES ,
3046
3105
) ;
3047
3106
}
3048
3107
3049
3108
#[ test]
3050
3109
fn test_hst ( ) {
3051
3110
check_enum (
3052
3111
crate :: provider:: Baked :: SINGLETON_HANGUL_SYLLABLE_TYPE_NAME_TO_VALUE_V2_MARKER ,
3053
- HangulSyllableType :: ALL_CONSTS ,
3112
+ HangulSyllableType :: ALL_VALUES ,
3054
3113
) ;
3055
3114
}
3056
3115
}
0 commit comments