Skip to content

Commit 5677664

Browse files
Validate properties constants (#7281)
More typos!
1 parent 812423b commit 5677664

File tree

9 files changed

+85
-24
lines changed

9 files changed

+85
-24
lines changed

components/properties/src/props.rs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ macro_rules! create_const_array {
3838
impl $enum_ty:ident {
3939
$( $(#[$const_meta:meta])* $v:vis const $i:ident: $t:ty = $e:expr; )*
4040
}
41+
#[test]
42+
fn $consts_test:ident();
4143
) => {
4244
$( #[$meta] )*
4345
impl $enum_ty {
@@ -72,6 +74,25 @@ macro_rules! create_const_array {
7274
other.0 as u16
7375
}
7476
}
77+
78+
#[test]
79+
fn $consts_test() {
80+
$(
81+
assert_eq!(
82+
crate::names::PropertyNamesLong::<$enum_ty>::new().get($enum_ty::$i).unwrap()
83+
// Rust identifiers use camel case
84+
.replace('_', "")
85+
// We use Ethiopian
86+
.replace("Ethiopic", "Ethiopian")
87+
// Nastaliq is missing a long name?
88+
.replace("Aran", "Nastaliq")
89+
// We spell these out
90+
.replace("LVSyllable", "LeadingVowelSyllable")
91+
.replace("LVTSyllable", "LeadingVowelTrailingSyllable"),
92+
stringify!($i)
93+
);
94+
)*
95+
}
7596
}
7697
}
7798

@@ -199,6 +220,8 @@ impl BidiClass {
199220
/// (`PDI`) U+2069: terminates an isolate control
200221
pub const PopDirectionalIsolate: BidiClass = BidiClass(22);
201222
}
223+
#[test]
224+
fn bidi_props_consts();
202225
}
203226

204227
make_enumerated_property! {
@@ -353,6 +376,20 @@ impl GeneralCategory {
353376
];
354377
}
355378

379+
#[test]
380+
fn gc_variants() {
381+
for &variant in GeneralCategory::ALL_VALUES {
382+
assert_eq!(
383+
crate::names::PropertyNamesLong::<GeneralCategory>::new()
384+
.get(variant)
385+
.unwrap()
386+
// Rust identifiers use camel case
387+
.replace('_', ""),
388+
format!("{variant:?}")
389+
);
390+
}
391+
}
392+
356393
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash, Default)]
357394
/// Error value for `impl TryFrom<u8> for GeneralCategory`.
358395
#[non_exhaustive]
@@ -895,6 +932,8 @@ impl Script {
895932
pub const Yi: Script = Script(41);
896933
pub const ZanabazarSquare: Script = Script(177);
897934
}
935+
#[test]
936+
fn script_consts();
898937
}
899938

900939
impl Script {
@@ -988,6 +1027,8 @@ impl HangulSyllableType {
9881027
/// (`LVT`) a precomposed syllable with a leading consonant, a vowel, and a trailing consonant.
9891028
pub const LeadingVowelTrailingSyllable: HangulSyllableType = HangulSyllableType(5);
9901029
}
1030+
#[test]
1031+
fn hangul_syllable_type_consts();
9911032
}
9921033

9931034
make_enumerated_property! {
@@ -1047,6 +1088,8 @@ impl EastAsianWidth {
10471088
pub const Narrow: EastAsianWidth = EastAsianWidth(4); //name="Na"
10481089
pub const Wide: EastAsianWidth = EastAsianWidth(5); //name="W"
10491090
}
1091+
#[test]
1092+
fn east_asian_width_consts();
10501093
}
10511094

10521095
make_enumerated_property! {
@@ -1156,6 +1199,8 @@ impl LineBreak {
11561199
// Added in ICU 78:
11571200
pub const UnambiguousHyphen: LineBreak = LineBreak(48); // name="HH"
11581201
}
1202+
#[test]
1203+
fn line_break_consts();
11591204
}
11601205

11611206
make_enumerated_property! {
@@ -1233,6 +1278,8 @@ impl GraphemeClusterBreak {
12331278
pub const GlueAfterZwj: GraphemeClusterBreak = GraphemeClusterBreak(16); // name="GAZ"
12341279
pub const ZWJ: GraphemeClusterBreak = GraphemeClusterBreak(17); // name="ZWJ"
12351280
}
1281+
#[test]
1282+
fn gcb_consts();
12361283
}
12371284

12381285
make_enumerated_property! {
@@ -1315,6 +1362,8 @@ impl WordBreak {
13151362
pub const ZWJ: WordBreak = WordBreak(21); // name="ZWJ"
13161363
pub const WSegSpace: WordBreak = WordBreak(22); // name="WSegSpace"
13171364
}
1365+
#[test]
1366+
fn word_break_consts();
13181367
}
13191368

13201369
make_enumerated_property! {
@@ -1385,6 +1434,8 @@ impl SentenceBreak {
13851434
pub const LF: SentenceBreak = SentenceBreak(13); // name="LF"
13861435
pub const SContinue: SentenceBreak = SentenceBreak(14); // name="SC"
13871436
}
1437+
#[test]
1438+
fn sentence_break_consts();
13881439
}
13891440

13901441
make_enumerated_property! {
@@ -1506,6 +1557,8 @@ impl CanonicalCombiningClass {
15061557
pub const DoubleAbove: CanonicalCombiningClass = CanonicalCombiningClass(234); // name="DA"
15071558
pub const IotaSubscript: CanonicalCombiningClass = CanonicalCombiningClass(240); // name="IS"
15081559
}
1560+
#[test]
1561+
fn ccc_consts();
15091562
}
15101563

15111564
make_enumerated_property! {
@@ -1569,6 +1622,8 @@ impl IndicConjunctBreak {
15691622
pub const Extend: IndicConjunctBreak = IndicConjunctBreak(2);
15701623
pub const Linker: IndicConjunctBreak = IndicConjunctBreak(3);
15711624
}
1625+
#[test]
1626+
fn indic_conjunct_break_consts();
15721627
}
15731628

15741629
make_enumerated_property! {
@@ -1634,8 +1689,8 @@ impl IndicSyllabicCategory {
16341689
pub const ConsonantPlaceholder: IndicSyllabicCategory = IndicSyllabicCategory(12);
16351690
pub const ConsonantPrecedingRepha: IndicSyllabicCategory = IndicSyllabicCategory(13);
16361691
pub const ConsonantPrefixed: IndicSyllabicCategory = IndicSyllabicCategory(14);
1637-
pub const ConsonantSucceedingRepha: IndicSyllabicCategory = IndicSyllabicCategory(15);
1638-
pub const ConsonantSubjoined: IndicSyllabicCategory = IndicSyllabicCategory(16);
1692+
pub const ConsonantSubjoined: IndicSyllabicCategory = IndicSyllabicCategory(15);
1693+
pub const ConsonantSucceedingRepha: IndicSyllabicCategory = IndicSyllabicCategory(16);
16391694
pub const ConsonantWithStacker: IndicSyllabicCategory = IndicSyllabicCategory(17);
16401695
pub const GeminationMark: IndicSyllabicCategory = IndicSyllabicCategory(18);
16411696
pub const InvisibleStacker: IndicSyllabicCategory = IndicSyllabicCategory(19);
@@ -1657,6 +1712,8 @@ impl IndicSyllabicCategory {
16571712
pub const VowelIndependent: IndicSyllabicCategory = IndicSyllabicCategory(35);
16581713
pub const ReorderingKiller: IndicSyllabicCategory = IndicSyllabicCategory(36);
16591714
}
1715+
#[test]
1716+
fn indic_syllabic_category_consts();
16601717
}
16611718

16621719
make_enumerated_property! {
@@ -1715,6 +1772,8 @@ impl JoiningType {
17151772
pub const RightJoining: JoiningType = JoiningType(4); // name="R"
17161773
pub const Transparent: JoiningType = JoiningType(5); // name="T"
17171774
}
1775+
#[test]
1776+
fn joining_type_consts();
17181777
}
17191778

17201779
make_enumerated_property! {
@@ -1779,6 +1838,8 @@ impl VerticalOrientation {
17791838
pub const TransformedUpright: VerticalOrientation = VerticalOrientation(2); // name="Tu"
17801839
pub const Upright: VerticalOrientation = VerticalOrientation(3); // name="U"
17811840
}
1841+
#[test]
1842+
fn vertical_orientation_consts();
17821843
}
17831844

17841845
make_enumerated_property! {

ffi/capi/bindings/c/IndicSyllabicCategory.d.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/cpp/icu4x/IndicSyllabicCategory.d.hpp

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/bindings/cpp/icu4x/IndicSyllabicCategory.hpp

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/capi/src/properties_enums.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2401,15 +2401,15 @@ pub mod ffi {
24012401
)]
24022402
ConsonantPrefixed = 14,
24032403
#[diplomat::rust_link(
2404-
icu::properties::props::IndicSyllabicCategory::ConsonantSucceedingRepha,
2404+
icu::properties::props::IndicSyllabicCategory::ConsonantSubjoined,
24052405
AssociatedConstantInStruct
24062406
)]
2407-
ConsonantSucceedingRepha = 15,
2407+
ConsonantSubjoined = 15,
24082408
#[diplomat::rust_link(
2409-
icu::properties::props::IndicSyllabicCategory::ConsonantSubjoined,
2409+
icu::properties::props::IndicSyllabicCategory::ConsonantSucceedingRepha,
24102410
AssociatedConstantInStruct
24112411
)]
2412-
ConsonantSubjoined = 16,
2412+
ConsonantSucceedingRepha = 16,
24132413
#[diplomat::rust_link(
24142414
icu::properties::props::IndicSyllabicCategory::ConsonantWithStacker,
24152415
AssociatedConstantInStruct
@@ -2552,8 +2552,8 @@ pub mod ffi {
25522552
12 => Self::ConsonantPlaceholder,
25532553
13 => Self::ConsonantPrecedingRepha,
25542554
14 => Self::ConsonantPrefixed,
2555-
15 => Self::ConsonantSucceedingRepha,
2556-
16 => Self::ConsonantSubjoined,
2555+
15 => Self::ConsonantSubjoined,
2556+
16 => Self::ConsonantSucceedingRepha,
25572557
17 => Self::ConsonantWithStacker,
25582558
18 => Self::GeminationMark,
25592559
19 => Self::InvisibleStacker,

ffi/dart/lib/src/bindings/IndicSyllabicCategory.g.dart

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/mvn/src/main/kotlin/src/main/kotlin/org/unicode/icu4x/IndicSyllabicCategory.kt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/npm/lib/IndicSyllabicCategory.d.ts

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ffi/npm/lib/IndicSyllabicCategory.mjs

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)