//! Logic guards for note titles and Markdown previews over synthetic text.usesuper::*;#[test]fn a_real_title_is_kept() { assert_eq!( note_display_title(Some("Groceries"), "oat milk"),Some("Groceries".to_string()) );}#[test]fn a_titleless_note_borrows_its_first_line() { assert_eq!( note_display_title(None, "Ring the plumber\nback door sticks"),Some("Ring the plumber".to_string()) );}#[test]fn a_whitespace_only_title_is_no_title_at_all() { assert_eq!( note_display_title(Some(" "), "Ring the plumber"),Some("Ring the plumber".to_string()) );}#[test]fn the_borrowed_line_comes_through_with_its_markdown_stripped() { assert_eq!( note_display_title(None, "# **Ring** the plumber"),Some("Ring the plumber".to_string()) );}#[test]fn leading_blank_lines_are_skipped() { assert_eq!( note_display_title(None, "\n\n Ring the plumber"),Some("Ring the plumber".to_string()) );}/// RULE: A derived title keeps the whole first line; only the drawing may truncate it, so no reader loses the person's opening words.#[test]fn a_derived_title_keeps_the_whole_first_line() { assert_eq!(note_display_title(None, "Asha wrote this on her phone.\nmore"), Some("Asha wrote this on her phone.".into()));let long = "A long opening line 🧵 ".repeat(20); assert_eq!(note_display_title(None, &format!("{long}\nmore")), Some(long.trim().to_string()));}#[test]fn nothing_to_call_it_answers_nothing() { assert_eq!(note_display_title(None, ""), None); assert_eq!(note_display_title(None, " \n "), None);}/// A body that is nothing but furniture — a rule and a bullet marker with no/// word after it — has no line to borrow either.#[test]fn a_body_of_pure_markdown_furniture_answers_nothing() { assert_eq!(note_display_title(None, "---\n\n> \n"), None);}#[test]fn a_link_becomes_its_label_and_an_image_its_alt_text() { assert_eq!( strip_markdown("[the vendor list](https://example.invalid/x)"),"the vendor list" ); assert_eq!(strip_markdown(""), "a chart");}#[test]fn a_fenced_block_keeps_its_words_and_loses_its_fence() { assert_eq!(strip_markdown("```rust\nlet x = 1;\n```"), "let x = 1;");}/// The emphasis pass is a left-to-right scan because the TypeScript's is a/// BACKREFERENCE: a mark only ever closes with the SAME mark that opened, and/// an unmatched one is text rather than the start of a wrapper.#[test]fn emphasis_marks_unwrap_and_a_lone_one_survives_as_text() { assert_eq!( strip_markdown("**bold** and *soft* and a lone * mark"),"bold and soft and a lone * mark" );}/// `.` carries no `s` flag over there, so a wrapper whose closing mark is on/// the next line is not a wrapper and survives as it was typed.#[test]fn a_wrapper_that_does_not_close_on_its_own_line_is_left_alone() { assert_eq!(strip_markdown("*not emphasis\nstill not*"), "*not emphasis\nstill not*");}/// Line breaks SURVIVE the strip — a note's lines are its structure, and the/// title takes the first of them rather than a fused sentence.#[test]fn the_lines_survive_and_only_the_blank_ones_are_dropped() { assert_eq!( strip_markdown("- one\n\n- two\n"),"one\ntwo" );}/// RULE: A preview strips Markdown before any length limit, including an already clipped link or code span, without dropping the words they name.#[test]fn a_plain_preview_keeps_words_without_complete_or_clipped_markdown() {for (raw, plain) in [ ("May I run `npm install`?", "May I run npm install?"), ("Hours are on [example.com](https://example.com/hours)", "Hours are on example.com"), ("Hours are on [example.com", "Hours are on example.com"), ("Hours are on [example.com](https://exam", "Hours are on example.com"), ("May I run `npm install", "May I run npm install"), ] { assert_eq!(plain_preview(raw), plain); }}