//! `include_frontmatter` (SPEC 16): the properties table renders at the top //! of the page only when the option asks for it, and hostile property counts //! are capped with an honest overflow line. mod support; use notescraft_pdf::{ExportOptions, NoAssets, export}; use support::{options, text}; /// Options with the properties option on. fn properties() -> ExportOptions { let mut opts = options(); opts.include_frontmatter = true; opts } /// The rendered text of one export. fn render(source: &str, opts: &ExportOptions) -> String { let pdf = export(source, opts, &NoAssets).unwrap_or_else(|error| panic!("export: {error}")); text(&pdf) } #[test] fn nothing_is_drawn_without_frontmatter_or_option() { let bare = render("# Just\n\nBody\n", &properties()); assert_eq!(bare.find("tags"), None, "a note without frontmatter draws no table"); let defaults = options(); let hidden = render("---\ntags: blue\n---\n\n# T\n\nBody\n", &defaults); assert!(hidden.find("tags").is_none(), "frontmatter is hidden by default"); } #[test] fn keys_and_values_render_when_asked_for() { let shown = render("---\ncolor: blue\nsize: 10\n---\n# T\nBody", &properties()); assert!(shown.contains("color"), "the key is drawn: {shown}"); assert!(shown.contains("blue"), "the value is drawn: {shown}"); assert!(shown.contains("size"), "the other key is drawn: {shown}"); assert!(shown.contains("10"), "and its value"); } /// A hostile note with 1000 properties: two hundred rows render, the rest is /// reported as one overflow line instead of growing the page list. #[test] fn a_hostile_property_count_is_capped() { let mut frontmatter = String::from("---\n"); for index in 0..1000 { let _ = std::fmt::Write::write_fmt(&mut frontmatter, format_args!("key{index}: value{index}\n")); } frontmatter.push_str("---\n# T\nBody\n"); let shown = render(&frontmatter, &properties()); assert!(shown.contains("key0"), "the first row renders"); assert!(shown.contains("key199"), "and the two-hundredth"); assert_eq!(shown.find("key200"), None, "no row beyond the cap"); assert!(shown.contains("… 800 more"), "the overflow is reported: {shown}"); }