Unnamed repository; edit this file 'description' to name the repository.
move tests
Aleksey Kladov 2021-10-10
parent 6253213 · commit af76db3
-rw-r--r--crates/hir_def/src/macro_expansion_tests/mbe/regression.rs107
-rw-r--r--crates/mbe/src/tests/expand.rs66
2 files changed, 107 insertions, 66 deletions
diff --git a/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs b/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs
index 9762570412..527395992b 100644
--- a/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs
+++ b/crates/hir_def/src/macro_expansion_tests/mbe/regression.rs
@@ -533,3 +533,110 @@ impl <A: Arbitrary> $crate::arbitrary::Arbitrary for Vec<A> {
"#]],
);
}
+
+#[test]
+fn test_old_ridl() {
+ // This is from winapi 2.8, which do not have a link from github.
+ check(
+ r#"
+#[macro_export]
+macro_rules! RIDL {
+ (interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident)
+ {$(
+ fn $method:ident(&mut self $(,$p:ident : $t:ty)*) -> $rtr:ty
+ ),+}
+ ) => {
+ impl $interface {
+ $(pub unsafe fn $method(&mut self) -> $rtr {
+ ((*self.lpVtbl).$method)(self $(,$p)*)
+ })+
+ }
+ };
+}
+
+RIDL!{interface ID3D11Asynchronous(ID3D11AsynchronousVtbl): ID3D11DeviceChild(ID3D11DeviceChildVtbl) {
+ fn GetDataSize(&mut self) -> UINT
+}}
+"#,
+ expect![[r##"
+#[macro_export]
+macro_rules! RIDL {
+ (interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident)
+ {$(
+ fn $method:ident(&mut self $(,$p:ident : $t:ty)*) -> $rtr:ty
+ ),+}
+ ) => {
+ impl $interface {
+ $(pub unsafe fn $method(&mut self) -> $rtr {
+ ((*self.lpVtbl).$method)(self $(,$p)*)
+ })+
+ }
+ };
+}
+
+impl ID3D11Asynchronous {
+ pub unsafe fn GetDataSize(&mut self ) -> UINT {
+ ((*self .lpVtbl).GetDataSize)(self )
+ }
+}
+"##]],
+ );
+}
+
+#[test]
+fn test_quick_error() {
+ check(
+ r#"
+macro_rules! quick_error {
+ (SORT [enum $name:ident $( #[$meta:meta] )*]
+ items [$($( #[$imeta:meta] )*
+ => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+ {$( $ifuncs:tt )*} )* ]
+ buf [ ]
+ queue [ ]
+ ) => {
+ quick_error!(ENUMINITION [enum $name $( #[$meta] )*]
+ body []
+ queue [$(
+ $( #[$imeta] )*
+ =>
+ $iitem: $imode [$( $ivar: $ityp ),*]
+ )*]
+ );
+ };
+}
+quick_error ! (
+ SORT
+ [enum Wrapped #[derive(Debug)]]
+ items [
+ => One: UNIT [] {}
+ => Two: TUPLE [s :String] {display ("two: {}" , s) from ()} ]
+ buf [ ]
+ queue [ ]
+);
+
+"#,
+ expect![[r##"
+macro_rules! quick_error {
+ (SORT [enum $name:ident $( #[$meta:meta] )*]
+ items [$($( #[$imeta:meta] )*
+ => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
+ {$( $ifuncs:tt )*} )* ]
+ buf [ ]
+ queue [ ]
+ ) => {
+ quick_error!(ENUMINITION [enum $name $( #[$meta] )*]
+ body []
+ queue [$(
+ $( #[$imeta] )*
+ =>
+ $iitem: $imode [$( $ivar: $ityp ),*]
+ )*]
+ );
+ };
+}
+quick_error!(ENUMINITION[enum Wrapped#[derive(Debug)]]body[]queue[ = > One: UNIT[] = > Two: TUPLE[s: String]]);
+
+"##]],
+ )
+}
diff --git a/crates/mbe/src/tests/expand.rs b/crates/mbe/src/tests/expand.rs
index 300467306d..c3c753cf55 100644
--- a/crates/mbe/src/tests/expand.rs
+++ b/crates/mbe/src/tests/expand.rs
@@ -99,72 +99,6 @@ fn test_attr_to_token_tree() {
}
#[test]
-fn test_old_ridl() {
- // This is from winapi 2.8, which do not have a link from github
- //
- let expanded = parse_macro(
- r#"
-#[macro_export]
-macro_rules! RIDL {
- (interface $interface:ident ($vtbl:ident) : $pinterface:ident ($pvtbl:ident)
- {$(
- fn $method:ident(&mut self $(,$p:ident : $t:ty)*) -> $rtr:ty
- ),+}
- ) => {
- impl $interface {
- $(pub unsafe fn $method(&mut self) -> $rtr {
- ((*self.lpVtbl).$method)(self $(,$p)*)
- })+
- }
- };
-}"#,
- ).expand_tt(r#"
- RIDL!{interface ID3D11Asynchronous(ID3D11AsynchronousVtbl): ID3D11DeviceChild(ID3D11DeviceChildVtbl) {
- fn GetDataSize(&mut self) -> UINT
- }}"#);
-
- assert_eq!(expanded.to_string(), "impl ID3D11Asynchronous {pub unsafe fn GetDataSize (& mut self) -> UINT {((* self . lpVtbl) .GetDataSize) (self)}}");
-}
-
-#[test]
-fn test_quick_error() {
- let expanded = parse_macro(
- r#"
-macro_rules! quick_error {
-
- (SORT [enum $name:ident $( #[$meta:meta] )*]
- items [$($( #[$imeta:meta] )*
- => $iitem:ident: $imode:tt [$( $ivar:ident: $ityp:ty ),*]
- {$( $ifuncs:tt )*} )* ]
- buf [ ]
- queue [ ]
- ) => {
- quick_error!(ENUMINITION [enum $name $( #[$meta] )*]
- body []
- queue [$(
- $( #[$imeta] )*
- =>
- $iitem: $imode [$( $ivar: $ityp ),*]
- )*]
- );
-};
-
-}
-"#,
- )
- .expand_tt(
- r#"
-quick_error ! (SORT [enum Wrapped # [derive (Debug)]] items [
- => One : UNIT [] {}
- => Two : TUPLE [s :String] {display ("two: {}" , s) from ()}
- ] buf [] queue []) ;
-"#,
- );
-
- assert_eq!(expanded.to_string(), "quick_error ! (ENUMINITION [enum Wrapped # [derive (Debug)]] body [] queue [=> One : UNIT [] => Two : TUPLE [s : String]]) ;");
-}
-
-#[test]
fn test_empty_repeat_vars_in_empty_repeat_vars() {
parse_macro(
r#"