Skip to content

Commit afa1c72

Browse files
committed
Add more auto-parenthesization tests
1 parent 532d3a3 commit afa1c72

1 file changed

Lines changed: 34 additions & 13 deletions

File tree

tests/test_expr.rs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -655,17 +655,38 @@ fn test_fixup() {
655655
}
656656
}
657657

658-
let tokens = quote!(2 * (1 + 1));
659-
let original: Expr = syn::parse2(tokens).unwrap();
660-
661-
let mut flat = original.clone();
662-
FlattenParens.visit_expr_mut(&mut flat);
663-
let reconstructed: Expr = syn::parse2(flat.to_token_stream()).unwrap();
664-
665-
assert!(
666-
original == reconstructed,
667-
"original: {}\nreconstructed: {}",
668-
original.to_token_stream(),
669-
reconstructed.to_token_stream(),
670-
);
658+
for tokens in [
659+
quote! { 2 * (1 + 1) },
660+
quote! { 0 + (0 + 0) },
661+
quote! { (a = b) = c },
662+
quote! { (x as i32) < 0 },
663+
quote! { (1 + x as i32) < 0 },
664+
quote! { (1 + 1).abs() },
665+
quote! { (lo..hi)[..] },
666+
quote! { (a..b)..(c..d) },
667+
quote! { (&mut fut).await },
668+
quote! { &mut (x as i32) },
669+
quote! { -(x as i32) },
670+
quote! { if (S {} == 1) {} },
671+
quote! { { (m! {}) - 1 } },
672+
quote! { match m { _ => ({}) - 1 } },
673+
quote! { if let _ = (a && b) && c {} },
674+
quote! { if let _ = (S {}) {} },
675+
] {
676+
let original: Expr = syn::parse2(tokens).unwrap();
677+
678+
let mut flat = original.clone();
679+
FlattenParens.visit_expr_mut(&mut flat);
680+
let reconstructed: Expr = match syn::parse2(flat.to_token_stream()) {
681+
Ok(reconstructed) => reconstructed,
682+
Err(err) => panic!("failed to parse `{}`: {}", flat.to_token_stream(), err),
683+
};
684+
685+
assert!(
686+
original == reconstructed,
687+
"original: {}\nreconstructed: {}",
688+
original.to_token_stream(),
689+
reconstructed.to_token_stream(),
690+
);
691+
}
671692
}

0 commit comments

Comments
 (0)