Debian Codegraph @

debian/rust-vendor/prettyplease/tests/test.rs

raw
1 use indoc::indoc;
2 use proc_macro2::{Delimiter, Group, TokenStream};
3 use quote::quote;
4
5 #[track_caller]
6 fn test(tokens: TokenStream, expected: &str) {
7 let syntax_tree: syn::File = syn::parse2(tokens).unwrap();
8 let pretty = prettyplease::unparse(&syntax_tree);
9 assert_eq!(pretty, expected);
10 }
11
12 #[test]
13 fn test_parenthesize_cond() {
14 let s = Group::new(Delimiter::None, quote!(Struct {}));
15 test(
16 quote! {
17 fn main() {
18 if #s == #s {}
19 }
20 },
21 indoc! {"
22 fn main() {
23 if (Struct {}) == (Struct {}) {}
24 }
25 "},
26 );
27 }
28
29 #[test]
30 fn test_parenthesize_match_guard() {
31 let expr_struct = Group::new(Delimiter::None, quote!(Struct {}));
32 let expr_binary = Group::new(Delimiter::None, quote!(true && false));
33 test(
34 quote! {
35 fn main() {
36 match () {
37 () if let _ = #expr_struct => {}
38 () if let _ = #expr_binary => {}
39 }
40 }
41 },
42 indoc! {"
43 fn main() {
44 match () {
45 () if let _ = Struct {} => {}
46 () if let _ = (true && false) => {}
47 }
48 }
49 "},
50 );
51 }