From 9d7ada7db485dc15391e15ce982d90fcb05dce4e Mon Sep 17 00:00:00 2001 From: Roman Proskuryakov Date: Thu, 15 Oct 2020 20:04:25 +0300 Subject: [PATCH] Add tests for Markdown broken links --- src/scanners/markdown.rs | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/src/scanners/markdown.rs b/src/scanners/markdown.rs index c56c89569..2b9b3af09 100644 --- a/src/scanners/markdown.rs +++ b/src/scanners/markdown.rs @@ -60,6 +60,15 @@ mod tests { ![Look, an image!](https://imgur.com/gallery/f28OkrB) [nowhere]: https://dev.null/ + +- [x] Comments +- [ ] Issues + +```sql +ALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] name [ * ] + action [, ... ] +``` + "#; let should_be = vec![ (String::from("https://example.com"), Span::new(17, 44)), @@ -75,4 +84,40 @@ mod tests { assert_eq!(got, should_be); } + + #[test] + fn detect_broken_links_in_markdown() { + let src = r#" +# Some Heading + +[this](https://example.com) is a link [to nowhere][nowhere]. But +[this](../README.md) points somewhere on disk. + +![Look, an image!](https://imgur.com/gallery/f28OkrB) + +[nowhere]: https://dev.null/ + +- [x] Comments +- [ ] Issues + +```sql +ALTER FOREIGN TABLE [ IF EXISTS ] [ ONLY ] name [ * ] + action [, ... ] +``` + + "#; + let should_be = vec![ + (String::from("https://example.com"), Span::new(17, 44)), + (String::from("https://dev.null/"), Span::new(55, 76)), + (String::from("../README.md"), Span::new(82, 102)), + ( + String::from("https://imgur.com/gallery/f28OkrB"), + Span::new(130, 183), + ), + ]; + + let got: Vec<_> = markdown_with_broken_link_callback(src, &|a, b| Some((a.to_string(), b.to_string()))).collect(); + + assert_eq!(got, should_be); + } }