1 | #![allow (clippy::from_iter_instead_of_collect)] |
2 | |
3 | use proc_macro2::{Delimiter, Group, Ident, Span, TokenStream, TokenTree}; |
4 | use std::iter; |
5 | |
6 | #[test] |
7 | fn test_fmt_group() { |
8 | let ident = Ident::new("x" , Span::call_site()); |
9 | let inner = TokenStream::from_iter(iter::once(TokenTree::Ident(ident))); |
10 | let parens_empty = Group::new(Delimiter::Parenthesis, TokenStream::new()); |
11 | let parens_nonempty = Group::new(Delimiter::Parenthesis, inner.clone()); |
12 | let brackets_empty = Group::new(Delimiter::Bracket, TokenStream::new()); |
13 | let brackets_nonempty = Group::new(Delimiter::Bracket, inner.clone()); |
14 | let braces_empty = Group::new(Delimiter::Brace, TokenStream::new()); |
15 | let braces_nonempty = Group::new(Delimiter::Brace, inner.clone()); |
16 | let none_empty = Group::new(Delimiter::None, TokenStream::new()); |
17 | let none_nonempty = Group::new(Delimiter::None, inner); |
18 | |
19 | // Matches libproc_macro. |
20 | assert_eq!("()" , parens_empty.to_string()); |
21 | assert_eq!("(x)" , parens_nonempty.to_string()); |
22 | assert_eq!("[]" , brackets_empty.to_string()); |
23 | assert_eq!("[x]" , brackets_nonempty.to_string()); |
24 | assert_eq!("{ }" , braces_empty.to_string()); |
25 | assert_eq!("{ x }" , braces_nonempty.to_string()); |
26 | assert_eq!("" , none_empty.to_string()); |
27 | assert_eq!("x" , none_nonempty.to_string()); |
28 | } |
29 | |