1 #[macro_use]
2 mod macros;
3
4 use proc_macro2::{Delimiter, Group, TokenStream, TokenTree};
5 use quote::quote;
6 use std::iter::FromIterator;
7 use syn::{Item, Pat, Stmt};
8
9 #[test]
test_pat_ident()10 fn test_pat_ident() {
11 match syn::parse2(quote!(self)).unwrap() {
12 Pat::Ident(_) => (),
13 value => panic!("expected PatIdent, got {:?}", value),
14 }
15 }
16
17 #[test]
test_pat_path()18 fn test_pat_path() {
19 match syn::parse2(quote!(self::CONST)).unwrap() {
20 Pat::Path(_) => (),
21 value => panic!("expected PatPath, got {:?}", value),
22 }
23 }
24
25 #[test]
test_leading_vert()26 fn test_leading_vert() {
27 // https://github.com/rust-lang/rust/blob/1.43.0/src/test/ui/or-patterns/remove-leading-vert.rs
28
29 syn::parse_str::<Item>("fn f() {}").unwrap();
30 syn::parse_str::<Item>("fn fun1(| A: E) {}").unwrap_err();
31 syn::parse_str::<Item>("fn fun2(|| A: E) {}").unwrap_err();
32
33 syn::parse_str::<Stmt>("let | () = ();").unwrap();
34 syn::parse_str::<Stmt>("let (| A): E;").unwrap();
35 syn::parse_str::<Stmt>("let (|| A): (E);").unwrap_err();
36 syn::parse_str::<Stmt>("let (| A,): (E,);").unwrap();
37 syn::parse_str::<Stmt>("let [| A]: [E; 1];").unwrap();
38 syn::parse_str::<Stmt>("let [|| A]: [E; 1];").unwrap_err();
39 syn::parse_str::<Stmt>("let TS(| A): TS;").unwrap();
40 syn::parse_str::<Stmt>("let TS(|| A): TS;").unwrap_err();
41 syn::parse_str::<Stmt>("let NS { f: | A }: NS;").unwrap();
42 syn::parse_str::<Stmt>("let NS { f: || A }: NS;").unwrap_err();
43 }
44
45 #[test]
test_group()46 fn test_group() {
47 let group = Group::new(Delimiter::None, quote!(Some(_)));
48 let tokens = TokenStream::from_iter(vec![TokenTree::Group(group)]);
49
50 snapshot!(tokens as Pat, @r###"
51 Pat::TupleStruct {
52 path: Path {
53 segments: [
54 PathSegment {
55 ident: "Some",
56 arguments: None,
57 },
58 ],
59 },
60 pat: PatTuple {
61 elems: [
62 Pat::Wild,
63 ],
64 },
65 }
66 "###);
67 }
68