#[test] fn annotation_snapshot_requires_exact_current_bytes_and_publication() { let mut app = fixture(); let original_model = app.document.snapshot(); let original_source = app.source_snapshot.clone(); let publication = app.source_annotation_snapshot().unwrap().publication; let initial = app.source_annotation_snapshot().unwrap(); assert!(Arc::ptr_eq(&initial.source, &original_source)); assert_eq!(initial.path, app.source_workspace.active); assert!(std::ptr::eq(initial.diagnostics, app.source_diagnostics.as_slice())); // Republish identical diagnostics: old cached geometry must get a new identity. app.publish_source_diagnostics(app.source_diagnostics.clone()); assert_ne!(app.source_annotation_snapshot().unwrap().publication, publication); app.source_workspace.edit("// newer draft\n".into(), app.source_editor.cursor()); assert!(app.source_annotation_snapshot().is_none(), "old publication after a real draft edit"); // A current source key alone must not bind new ranges to the old displayed text. app.publish_source_diagnostics(Vec::new()); assert!(app.source_annotation_snapshot().is_none(), "displayed snapshot still contains old bytes"); app.show_source_file(false); let current = app.source_annotation_snapshot().unwrap(); assert_eq!(current.source.as_ref(), "// newer draft\n"); assert!(current.diagnostics.is_empty()); assert!(Arc::ptr_eq(&original_model, &app.document.snapshot())); app.text_workspace.reset(); assert!(app.source_annotation_snapshot().is_none()); } #[test] fn annotation_snapshot_tracks_real_file_round_trips_without_changing_model() { let mut project = Project::empty(); let element = project.add_element(oa_core::Kind::Activity, oa_core::Layer::Oa, "Assess incident", None).unwrap(); let mut app = App::with_project(project); app.page = Page::Text; app.publish_source_diagnostics(app.source_diagnostics.clone()); let model = app.document.snapshot(); let entry = app.source_workspace.entry.clone(); let fragment = app.document.compiled().index.declarations[&element].path.clone(); assert_ne!(entry, fragment); for path in [&entry, &fragment, &entry] { let _ = app.update(Message::SourceFile(path.clone())); let current = app.source_annotation_snapshot().unwrap(); assert_eq!(current.path, path); assert_eq!(current.source.as_ref(), app.source_workspace.files[path].text); assert!(Arc::ptr_eq(¤t.source, &app.source_snapshot)); assert!(Arc::ptr_eq(&model, &app.document.snapshot())); } }