diff --git a/lib/entry/libimagentrymarkdown/src/processor.rs b/lib/entry/libimagentrymarkdown/src/processor.rs index 6a6f7376..4ac570c8 100644 --- a/lib/entry/libimagentrymarkdown/src/processor.rs +++ b/lib/entry/libimagentrymarkdown/src/processor.rs @@ -364,7 +364,7 @@ mod tests { let processor = LinkProcessor::default() .process_internal_links(true) .create_internal_targets(true) - .process_external_links(false) + .process_external_links(true) .process_refs(false); let result = processor.process(&mut base, &store); @@ -460,5 +460,92 @@ mod tests { assert_eq!(3, entries.len(), "Expected 3 links, got: {:?}", entries); println!("{:?}", entries); } + + #[test] + fn test_process_refs_with_ref_processing_switched_off() { + setup_logging(); + let store = get_store(); + + let mut base = store.create(PathBuf::from("test-5.1")).unwrap(); + + // As the ref target must exist, we're using /etc/hosts here + *base.get_content_mut() = format!( + r#"An [example ref](file:///etc/hosts) + is [here](file:///etc/group)."# + ); + + let update = store.update(&mut base); + assert!(update.is_ok()); + + let processor = LinkProcessor::default() + .process_internal_links(false) + .create_internal_targets(false) + .process_external_links(false) + .process_refs(false); + + let result = processor.process(&mut base, &store); + assert!(result.is_ok(), "Should be Ok(()): {:?}", result); + + let entries = store.entries(); + assert!(entries.is_ok()); + let entries : Vec<_> = entries.unwrap().collect(); + + assert_eq!(1, entries.len(), "Expected 1 entries, got: {:?}", entries); + println!("{:?}", entries); + } + + #[test] + fn test_process_external_link_with_external_link_processing_switched_off() { + setup_logging(); + let store = get_store(); + + let mut base = store.create(PathBuf::from("test-5.1")).unwrap(); + *base.get_content_mut() = format!("An [example](http://example.com) is here."); + + let update = store.update(&mut base); + assert!(update.is_ok()); + + let processor = LinkProcessor::default() + .process_internal_links(true) + .create_internal_targets(true) + .process_external_links(false) + .process_refs(false); + + let result = processor.process(&mut base, &store); + assert!(result.is_ok(), "Should be Ok(()): {:?}", result); + + let entries = store.entries(); + assert!(entries.is_ok()); + let entries : Vec<_> = entries.unwrap().collect(); + + assert_eq!(1, entries.len(), "Expected 1 entries, got: {:?}", entries); + } + + #[test] + fn test_process_one_existing_file_linked_with_internal_processing_switched_off() { + setup_logging(); + let store = get_store(); + + let mut base = store.create(PathBuf::from("test-2.1")).unwrap(); + *base.get_content_mut() = format!("This is an example entry with one [link](test-2.2)"); + + let update = store.update(&mut base); + assert!(update.is_ok()); + + // immediately drop as we don't need this entry right now + let _ = store.create(PathBuf::from("test-2.2")).unwrap(); + + let processor = LinkProcessor::default() + .process_internal_links(false) + .create_internal_targets(false) + .process_external_links(false) + .process_refs(false); + + let result = processor.process(&mut base, &store); + assert!(result.is_ok(), "Should be Ok(()): {:?}", result); + + assert_eq!(2, store.entries().unwrap().collect::>().len()); + } + }