]> git.proxmox.com Git - cargo.git/blob - vendor/syn/tests/test_ty.rs
New upstream version 0.47.0
[cargo.git] / vendor / syn / tests / test_ty.rs
1 #[macro_use]
2 mod macros;
3
4 use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
5 use quote::quote;
6 use std::iter::FromIterator;
7 use syn::Type;
8
9 #[test]
10 fn test_mut_self() {
11 syn::parse_str::<Type>("fn(mut self)").unwrap();
12 syn::parse_str::<Type>("fn(mut self: ())").unwrap();
13 syn::parse_str::<Type>("fn(mut self: ...)").unwrap_err();
14 syn::parse_str::<Type>("fn(mut self: mut self)").unwrap_err();
15 syn::parse_str::<Type>("fn(mut self::T)").unwrap_err();
16 }
17
18 #[test]
19 fn test_macro_variable_type() {
20 // mimics the token stream corresponding to `$ty<T>`
21 let tokens = TokenStream::from_iter(vec![
22 TokenTree::Group(Group::new(Delimiter::None, quote! { ty })),
23 TokenTree::Punct(Punct::new('<', Spacing::Alone)),
24 TokenTree::Ident(Ident::new("T", Span::call_site())),
25 TokenTree::Punct(Punct::new('>', Spacing::Alone)),
26 ]);
27
28 snapshot!(tokens as Type, @r###"
29 Type::Path {
30 path: Path {
31 segments: [
32 PathSegment {
33 ident: "ty",
34 arguments: PathArguments::AngleBracketed {
35 args: [
36 Type(Type::Path {
37 path: Path {
38 segments: [
39 PathSegment {
40 ident: "T",
41 arguments: None,
42 },
43 ],
44 },
45 }),
46 ],
47 },
48 },
49 ],
50 },
51 }
52 "###);
53 }