Skip to content

Commit

Permalink
Add tests for Markdown broken links
Browse files Browse the repository at this point in the history
  • Loading branch information
kpp committed Oct 15, 2020
1 parent 7c9e436 commit 9d7ada7
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/scanners/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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);
}
}

0 comments on commit 9d7ada7

Please sign in to comment.