Skip to content

Commit

Permalink
Test parse_quote implementation for Field
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Dec 12, 2023
1 parent c268c67 commit 5e15924
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion tests/test_parse_quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
mod macros;

use syn::punctuated::Punctuated;
use syn::{parse_quote, Attribute, Lit, Pat, Stmt, Token};
use syn::{parse_quote, Attribute, Field, Lit, Pat, Stmt, Token};

#[test]
fn test_attribute() {
Expand Down Expand Up @@ -35,6 +35,46 @@ fn test_attribute() {
"###);
}

#[test]
fn test_field() {
let field: Field = parse_quote!(pub enabled: bool);
snapshot!(field, @r###"
Field {
vis: Visibility::Public,
ident: Some("enabled"),
colon_token: Some,
ty: Type::Path {
path: Path {
segments: [
PathSegment {
ident: "bool",
},
],
},
},
}
"###);

let field: Field = parse_quote!(primitive::bool);
snapshot!(field, @r###"
Field {
vis: Visibility::Inherited,
ty: Type::Path {
path: Path {
segments: [
PathSegment {
ident: "primitive",
},
PathSegment {
ident: "bool",
},
],
},
},
}
"###);
}

#[test]
fn test_pat() {
let pat: Pat = parse_quote!(Some(false) | None);
Expand Down

0 comments on commit 5e15924

Please sign in to comment.