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