diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:20:29 +0000 |
commit | 631cd5845e8de329d0e227aaa707d7ea228b8f8f (patch) | |
tree | a1b87c8f8cad01cf18f7c5f57a08f102771ed303 /vendor/syn/tests/test_receiver.rs | |
parent | Adding debian version 1.69.0+dfsg1-1. (diff) | |
download | rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.tar.xz rustc-631cd5845e8de329d0e227aaa707d7ea228b8f8f.zip |
Merging upstream version 1.70.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/syn/tests/test_receiver.rs')
-rw-r--r-- | vendor/syn/tests/test_receiver.rs | 328 |
1 files changed, 261 insertions, 67 deletions
diff --git a/vendor/syn/tests/test_receiver.rs b/vendor/syn/tests/test_receiver.rs index 923df96ba..8decb555c 100644 --- a/vendor/syn/tests/test_receiver.rs +++ b/vendor/syn/tests/test_receiver.rs @@ -1,127 +1,321 @@ -use syn::{parse_quote, FnArg, Receiver, TraitItemMethod}; +#![allow(clippy::uninlined_format_args)] + +#[macro_use] +mod macros; + +use syn::{parse_quote, TraitItemFn}; #[test] fn test_by_value() { - let TraitItemMethod { sig, .. } = parse_quote! { + let TraitItemFn { sig, .. } = parse_quote! { fn by_value(self: Self); }; - match sig.receiver() { - Some(FnArg::Typed(_)) => (), - value => panic!("expected FnArg::Typed, got {:?}", value), - } + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + colon_token: Some, + ty: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }, + }) + "###); } #[test] fn test_by_mut_value() { - let TraitItemMethod { sig, .. } = parse_quote! { + let TraitItemFn { sig, .. } = parse_quote! { fn by_mut(mut self: Self); }; - match sig.receiver() { - Some(FnArg::Typed(_)) => (), - value => panic!("expected FnArg::Typed, got {:?}", value), - } + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + mutability: Some, + colon_token: Some, + ty: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }, + }) + "###); } #[test] fn test_by_ref() { - let TraitItemMethod { sig, .. } = parse_quote! { + let TraitItemFn { sig, .. } = parse_quote! { fn by_ref(self: &Self); }; - match sig.receiver() { - Some(FnArg::Typed(_)) => (), - value => panic!("expected FnArg::Typed, got {:?}", value), - } + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + colon_token: Some, + ty: Type::Reference { + elem: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }, + }, + }) + "###); } #[test] fn test_by_box() { - let TraitItemMethod { sig, .. } = parse_quote! { + let TraitItemFn { sig, .. } = parse_quote! { fn by_box(self: Box<Self>); }; - match sig.receiver() { - Some(FnArg::Typed(_)) => (), - value => panic!("expected FnArg::Typed, got {:?}", value), - } + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + colon_token: Some, + ty: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Box", + arguments: PathArguments::AngleBracketed { + args: [ + GenericArgument::Type(Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }), + ], + }, + }, + ], + }, + }, + }) + "###); } #[test] fn test_by_pin() { - let TraitItemMethod { sig, .. } = parse_quote! { + let TraitItemFn { sig, .. } = parse_quote! { fn by_pin(self: Pin<Self>); }; - match sig.receiver() { - Some(FnArg::Typed(_)) => (), - value => panic!("expected FnArg::Typed, got {:?}", value), - } + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + colon_token: Some, + ty: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Pin", + arguments: PathArguments::AngleBracketed { + args: [ + GenericArgument::Type(Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }), + ], + }, + }, + ], + }, + }, + }) + "###); } #[test] fn test_explicit_type() { - let TraitItemMethod { sig, .. } = parse_quote! { + let TraitItemFn { sig, .. } = parse_quote! { fn explicit_type(self: Pin<MyType>); }; - match sig.receiver() { - Some(FnArg::Typed(_)) => (), - value => panic!("expected FnArg::Typed, got {:?}", value), - } + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + colon_token: Some, + ty: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Pin", + arguments: PathArguments::AngleBracketed { + args: [ + GenericArgument::Type(Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "MyType", + }, + ], + }, + }), + ], + }, + }, + ], + }, + }, + }) + "###); } #[test] fn test_value_shorthand() { - let TraitItemMethod { sig, .. } = parse_quote! { + let TraitItemFn { sig, .. } = parse_quote! { fn value_shorthand(self); }; - match sig.receiver() { - Some(FnArg::Receiver(Receiver { - reference: None, - mutability: None, - .. - })) => (), - value => panic!("expected FnArg::Receiver without ref/mut, got {:?}", value), - } + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + ty: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }, + }) + "###); } #[test] fn test_mut_value_shorthand() { - let TraitItemMethod { sig, .. } = parse_quote! { + let TraitItemFn { sig, .. } = parse_quote! { fn mut_value_shorthand(mut self); }; - match sig.receiver() { - Some(FnArg::Receiver(Receiver { - reference: None, - mutability: Some(_), - .. - })) => (), - value => panic!("expected FnArg::Receiver with mut, got {:?}", value), - } + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + mutability: Some, + ty: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }, + }) + "###); } #[test] fn test_ref_shorthand() { - let TraitItemMethod { sig, .. } = parse_quote! { + let TraitItemFn { sig, .. } = parse_quote! { fn ref_shorthand(&self); }; - match sig.receiver() { - Some(FnArg::Receiver(Receiver { - reference: Some(_), - mutability: None, - .. - })) => (), - value => panic!("expected FnArg::Receiver with ref, got {:?}", value), - } + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + reference: Some(None), + ty: Type::Reference { + elem: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }, + }, + }) + "###); +} + +#[test] +fn test_ref_shorthand_with_lifetime() { + let TraitItemFn { sig, .. } = parse_quote! { + fn ref_shorthand(&'a self); + }; + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + reference: Some(Some(Lifetime { + ident: "a", + })), + ty: Type::Reference { + lifetime: Some(Lifetime { + ident: "a", + }), + elem: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }, + }, + }) + "###); } #[test] fn test_ref_mut_shorthand() { - let TraitItemMethod { sig, .. } = parse_quote! { + let TraitItemFn { sig, .. } = parse_quote! { fn ref_mut_shorthand(&mut self); }; - match sig.receiver() { - Some(FnArg::Receiver(Receiver { - reference: Some(_), - mutability: Some(_), - .. - })) => (), - value => panic!("expected FnArg::Receiver with ref+mut, got {:?}", value), - } + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + reference: Some(None), + mutability: Some, + ty: Type::Reference { + mutability: Some, + elem: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }, + }, + }) + "###); +} + +#[test] +fn test_ref_mut_shorthand_with_lifetime() { + let TraitItemFn { sig, .. } = parse_quote! { + fn ref_mut_shorthand(&'a mut self); + }; + snapshot!(&sig.inputs[0], @r###" + FnArg::Receiver(Receiver { + reference: Some(Some(Lifetime { + ident: "a", + })), + mutability: Some, + ty: Type::Reference { + lifetime: Some(Lifetime { + ident: "a", + }), + mutability: Some, + elem: Type::Path { + path: Path { + segments: [ + PathSegment { + ident: "Self", + }, + ], + }, + }, + }, + }) + "###); } |