Skip to content

Commit

Permalink
Merge pull request #63 from dtolnay/structcond
Browse files Browse the repository at this point in the history
Add test of automatic parenthesization of braced structs in cond
  • Loading branch information
dtolnay authored Dec 11, 2023
2 parents 11ebfab + 1575443 commit b2f30c7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ verbatim = ["syn/parsing"]

[dependencies]
proc-macro2 = { version = "1.0.63", default-features = false }
syn = { version = "2.0.31", default-features = false, features = ["full"] }
syn = { version = "2.0.40", default-features = false, features = ["full"] }

[dev-dependencies]
syn = { version = "2.0.31", default-features = false, features = ["parsing"] }
indoc = "2"
proc-macro2 = { version = "1", default-features = false }
quote = { version = "1", default-features = false }
syn = { version = "2.0.40", default-features = false, features = ["parsing"] }

[lib]
doc-scrape-examples = false
Expand Down
34 changes: 34 additions & 0 deletions tests/test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use indoc::indoc;
use proc_macro2::{Delimiter, Group, TokenStream};
use quote::quote;

#[track_caller]
fn test(tokens: TokenStream, expected: &str) {
let syntax_tree: syn::File = syn::parse2(tokens).unwrap();
let pretty = prettyplease::unparse(&syntax_tree);
assert_eq!(pretty, expected);
}

#[test]
fn test_parenthesize_cond() {
let s = Group::new(Delimiter::None, quote!(Struct {}));
test(
quote! {
fn main() {
if #s == #s {}
}
},
// FIXME this is not valid Rust syntax. It needs to be either:
//
// if (Struct {}) == (Struct {}) {}
//
// or:
//
// if (Struct {} == Struct {}) {}
indoc! {"
fn main() {
if Struct {} == Struct {} {}
}
"},
);
}

0 comments on commit b2f30c7

Please sign in to comment.