#![warn(missing_docs)]
#![allow(uncommon_codepoints)]
#![doc = include_str!("../readme-footer.md")]
pub use facet_macro_types::*;
pub use facet_macro_parse::*;
#[cfg(feature = "function")]
pub mod function;
mod process_enum;
mod process_struct;
#[cfg(all(feature = "doc", facet_no_doc))]
pub const fn is_no_doc() -> bool {
true
}
#[cfg(all(feature = "doc", not(facet_no_doc)))]
pub const fn is_no_doc() -> bool {
false
}
mod derive;
pub use derive::*;
mod plugin;
pub use plugin::*;
mod extension;
pub use extension::*;
mod on_error;
pub use on_error::*;
pub mod attr_grammar;
#[cfg(test)]
mod tests {
use super::*;
use quote::quote;
#[test]
fn test_struct_with_field_doc_comments() {
let input = quote! {
#[derive(Facet)]
pub struct User {
#[doc = " The user's unique identifier"]
pub id: u64,
}
};
let mut it = input.to_token_iter();
let parsed = it.parse::<Struct>().expect("Failed to parse struct");
assert_eq!(parsed.name.to_string(), "User");
if let StructKind::Struct { fields, .. } = &parsed.kind {
assert_eq!(fields.content.len(), 1);
let id_field = &fields.content[0].value;
assert_eq!(id_field.name.to_string(), "id");
let mut doc_found = false;
for attr in &id_field.attributes {
match &attr.body.content {
AttributeInner::Doc(doc_inner) => {
assert_eq!(doc_inner.value, " The user's unique identifier");
doc_found = true;
}
_ => {
}
}
}
assert!(doc_found, "Should have found a doc comment");
} else {
panic!("Expected a regular struct with named fields");
}
}
}