1 #![allow(
2 clippy::elidable_lifetime_names,
3 clippy::needless_lifetimes,
4 clippy::uninlined_format_args
5 )]
6
7 #[macro_use]
8 mod macros;
9
10 use proc_macro2::{Delimiter, Group, Literal, Punct, Spacing, TokenStream, TokenTree};
11 use syn::Expr;
12
13 #[test]
test_grouping()14 fn test_grouping() {
15 let tokens: TokenStream = TokenStream::from_iter([
16 TokenTree::Literal(Literal::i32_suffixed(1)),
17 TokenTree::Punct(Punct::new('+', Spacing::Alone)),
18 TokenTree::Group(Group::new(
19 Delimiter::None,
20 TokenStream::from_iter([
21 TokenTree::Literal(Literal::i32_suffixed(2)),
22 TokenTree::Punct(Punct::new('+', Spacing::Alone)),
23 TokenTree::Literal(Literal::i32_suffixed(3)),
24 ]),
25 )),
26 TokenTree::Punct(Punct::new('*', Spacing::Alone)),
27 TokenTree::Literal(Literal::i32_suffixed(4)),
28 ]);
29
30 assert_eq!(tokens.to_string(), "1i32 + 2i32 + 3i32 * 4i32");
31
32 snapshot!(tokens as Expr, @r#"
33 Expr::Binary {
34 left: Expr::Lit {
35 lit: 1i32,
36 },
37 op: BinOp::Add,
38 right: Expr::Binary {
39 left: Expr::Group {
40 expr: Expr::Binary {
41 left: Expr::Lit {
42 lit: 2i32,
43 },
44 op: BinOp::Add,
45 right: Expr::Lit {
46 lit: 3i32,
47 },
48 },
49 },
50 op: BinOp::Mul,
51 right: Expr::Lit {
52 lit: 4i32,
53 },
54 },
55 }
56 "#);
57 }
58