blob: 2ce12066f55658ae3ec1f646ff1d39547a4b6938 [file] [log] [blame]
Haibo Huang4fbebf92020-05-26 17:08:50 -07001#[macro_use]
2mod macros;
3
4use proc_macro2::{Delimiter, Group, Ident, Punct, Spacing, Span, TokenStream, TokenTree};
5use quote::quote;
6use std::iter::FromIterator;
7use syn::{Expr, Type};
8
9#[test]
10fn parse_interpolated_leading_component() {
11 // mimics the token stream corresponding to `$mod::rest`
12 let tokens = TokenStream::from_iter(vec![
13 TokenTree::Group(Group::new(Delimiter::None, quote! { first })),
14 TokenTree::Punct(Punct::new(':', Spacing::Joint)),
15 TokenTree::Punct(Punct::new(':', Spacing::Alone)),
16 TokenTree::Ident(Ident::new("rest", Span::call_site())),
17 ]);
18
19 snapshot!(tokens.clone() as Expr, @r###"
20 Expr::Path {
21 path: Path {
22 segments: [
23 PathSegment {
24 ident: "first",
25 arguments: None,
26 },
27 PathSegment {
28 ident: "rest",
29 arguments: None,
30 },
31 ],
32 },
33 }
34 "###);
35
36 snapshot!(tokens as Type, @r###"
37 Type::Path {
38 path: Path {
39 segments: [
40 PathSegment {
41 ident: "first",
42 arguments: None,
43 },
44 PathSegment {
45 ident: "rest",
46 arguments: None,
47 },
48 ],
49 },
50 }
51 "###);
52}