//! Mandatory test 2 (the core's half): a highlight's position survives re-rendering and re-import, and a changed //! edition degrades to "approximate" or "lost", never to other text. Font size and theme do not exist here: they //! never reach the tree (the app's test renders the same chapter under different settings). mod common; use common::*; use liber_format::position::{Point, anchor, offset_of, point_at, resolve}; use liber_format::{Limits, Resolved, open}; const CH0: &str = "
Úvodní slovo.
"; const CH1: &str = "Bylo to v temné a bouřlivé noci, když 😀 robot poprvé promluvil.
\Druhý odstavec s 1 poznámkou.
\ "; const CH2: &str = "Konec.
"; fn book(ch1: &str) -> Vecis the second element (after
Bylo to", "
Nový úvodní odstavec.
Bylo to") .replace("temné a bouřlivé", "temné a bouřlivé"); let d2 = open(&book(&edited), None, &Limits::default()).unwrap(); let r = resolve(&d2, &a); assert!(matches!(r, Resolved::Approximate { chapter: 1, .. }), "{r:?}"); assert_eq!(quote_at(&d2, &r), "robot poprvé promluvil"); } #[test] fn a_moved_chapter_is_found_in_another_chapter() { let d1 = open(&book(CH1), None, &Limits::default()).unwrap(); let t = d1.chapters[1].text(); let (s, e) = find16(&t, "Druhý odstavec"); let a = anchor(&d1, 1, s, e).unwrap(); let moved = Epub::new("R.U.R.") .chapter("Kapitola první", CH1) .chapter("Prolog", CH0) .chapter("Kapitola druhá", CH2) .build(); let d2 = open(&moved, None, &Limits::default()).unwrap(); let r = resolve(&d2, &a); assert!(matches!(r, Resolved::Approximate { chapter: 0, .. }), "{r:?}"); assert_eq!(quote_at(&d2, &r), "Druhý odstavec"); } #[test] fn removed_text_is_lost_never_elsewhere() { let d1 = open(&book(CH1), None, &Limits::default()).unwrap(); let t = d1.chapters[1].text(); let (s, e) = find16(&t, "robot poprvé promluvil"); let a = anchor(&d1, 1, s, e).unwrap(); // Same length, same structure, different words: the CFI still resolves, but to other text. let reworded = CH1.replace("robot poprvé promluvil", "stroj zase mlčel dlouho"); let d2 = open(&book(&reworded), None, &Limits::default()).unwrap(); assert_eq!(resolve(&d2, &a), Resolved::Lost); } #[test] fn an_ambiguous_quote_is_lost() { let ch = "
ano ano
ano ano
"; let d1 = open(&Epub::new("A").chapter("A", ch).build(), None, &Limits::default()).unwrap(); let a = anchor(&d1, 0, 0, 3).unwrap(); // The same file: exact. assert!(matches!(resolve(&d1, &a), Resolved::Exact { .. })); // A new edition where the context no longer tells the occurrences apart. let d2 = open(&Epub::new("A").chapter("A", "x
ano ano
ano ano
").build(), None, &Limits::default()) .unwrap(); let r = resolve(&d2, &a); assert!(r == Resolved::Lost || quote_at(&d2, &r) == "ano", "{r:?}"); } #[test] fn footnotes_and_links() { let d = open(&book(CH1), None, &Limits::default()).unwrap(); assert!(d.chapters[1].xhtml.contains("data-href=\"1#n1\""), "{}", d.chapters[1].xhtml); assert_eq!(d.footnotes.get("1#n1").map(|s| s.contains("Poznámka pod čarou")), Some(true)); }