Skip to content

Commit ee8d0f0

Browse files
committed
v0: use a t_const! macro for const generics tests.
1 parent 023fc05 commit ee8d0f0

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

src/v0.rs

Lines changed: 32 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,11 @@ impl<'a, 'b, 's> Printer<'a, 'b, 's> {
10501050
mod tests {
10511051
use std::prelude::v1::*;
10521052

1053+
macro_rules! t {
1054+
($a:expr, $b:expr) => {{
1055+
assert_eq!(format!("{}", ::demangle($a)), $b);
1056+
}};
1057+
}
10531058
macro_rules! t_nohash {
10541059
($a:expr, $b:expr) => {{
10551060
assert_eq!(format!("{:#}", ::demangle($a)), $b);
@@ -1060,6 +1065,23 @@ mod tests {
10601065
t_nohash!(concat!("_RMC0", $a), concat!("<", $b, ">"))
10611066
};
10621067
}
1068+
macro_rules! t_const {
1069+
($mangled:expr, $value:expr) => {
1070+
t_nohash!(
1071+
concat!("_RIC0K", $mangled, "E"),
1072+
concat!("::<", $value, ">")
1073+
)
1074+
};
1075+
}
1076+
macro_rules! t_const_typed {
1077+
($mangled:expr, $value:expr, $value_ty:expr) => {{
1078+
t_const!($mangled, $value);
1079+
t!(
1080+
concat!("_RIC0K", $mangled, "E"),
1081+
concat!("[0]::<", $value, ": ", $value_ty, ">")
1082+
);
1083+
}};
1084+
}
10631085

10641086
#[test]
10651087
fn demangle_crate_with_leading_digit() {
@@ -1102,46 +1124,20 @@ mod tests {
11021124
"INtC8arrayvec8ArrayVechKj7b_E",
11031125
"arrayvec::ArrayVec<u8, 123>"
11041126
);
1127+
t_const_typed!("j7b_", "123", "usize");
11051128
}
11061129

11071130
#[test]
11081131
fn demangle_min_const_generics() {
1109-
t_nohash!(
1110-
"_RMCs4fqI2P2rA04_13const_genericINtB0_8UnsignedKhb_E",
1111-
"<const_generic::Unsigned<11>>"
1112-
);
1113-
t_nohash!(
1114-
"_RMCs4fqI2P2rA04_13const_genericINtB0_6SignedKs98_E",
1115-
"<const_generic::Signed<152>>"
1116-
);
1117-
t_nohash!(
1118-
"_RMCs4fqI2P2rA04_13const_genericINtB0_6SignedKanb_E",
1119-
"<const_generic::Signed<-11>>"
1120-
);
1121-
t_nohash!(
1122-
"_RMCs4fqI2P2rA04_13const_genericINtB0_4BoolKb0_E",
1123-
"<const_generic::Bool<false>>"
1124-
);
1125-
t_nohash!(
1126-
"_RMCs4fqI2P2rA04_13const_genericINtB0_4BoolKb1_E",
1127-
"<const_generic::Bool<true>>"
1128-
);
1129-
t_nohash!(
1130-
"_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKc76_E",
1131-
"<const_generic::Char<'v'>>"
1132-
);
1133-
t_nohash!(
1134-
"_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKca_E",
1135-
"<const_generic::Char<'\\n'>>"
1136-
);
1137-
t_nohash!(
1138-
"_RMCs4fqI2P2rA04_13const_genericINtB0_4CharKc2202_E",
1139-
"<const_generic::Char<'∂'>>"
1140-
);
1141-
t_nohash!(
1142-
"_RNvNvMCs4fqI2P2rA04_13const_genericINtB4_3FooKpE3foo3FOO",
1143-
"<const_generic::Foo<_>>::foo::FOO"
1144-
);
1132+
t_const!("p", "_");
1133+
t_const_typed!("hb_", "11", "u8");
1134+
t_const_typed!("s98_", "152", "i16");
1135+
t_const_typed!("anb_", "-11", "i8");
1136+
t_const_typed!("b0_", "false", "bool");
1137+
t_const_typed!("b1_", "true", "bool");
1138+
t_const_typed!("c76_", "'v'", "char");
1139+
t_const_typed!("ca_", "'\\n'", "char");
1140+
t_const_typed!("c2202_", "'∂'", "char");
11451141
}
11461142

11471143
#[test]

0 commit comments

Comments
 (0)