Add support and tests for .markdown files (#152)

This commit is contained in:
Matthias 2021-02-21 09:48:44 +01:00 committed by GitHub
parent b8f24bfa3b
commit 41b82cb459
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -9,7 +9,7 @@ use std::path::Path;
use std::{collections::HashSet, convert::TryFrom};
use url::Url;
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum FileType {
Html,
Markdown,
@ -28,7 +28,7 @@ impl<P: AsRef<Path>> From<P> for FileType {
let path = p.as_ref();
match path.extension() {
Some(ext) => match ext {
_ if ext == "md" => FileType::Markdown,
_ if (ext == "md" || ext == "markdown") => FileType::Markdown,
_ if (ext == "htm" || ext == "html") => FileType::Html,
_ => FileType::Plaintext,
},
@ -202,6 +202,25 @@ mod test {
content
}
#[test]
fn test_file_type() {
assert_eq!(FileType::from(Path::new("test.md")), FileType::Markdown);
assert_eq!(
FileType::from(Path::new("test.markdown")),
FileType::Markdown
);
assert_eq!(FileType::from(Path::new("test.html")), FileType::Html);
assert_eq!(FileType::from(Path::new("test.txt")), FileType::Plaintext);
assert_eq!(
FileType::from(Path::new("test.something")),
FileType::Plaintext
);
assert_eq!(
FileType::from(Path::new("/absolute/path/to/test.something")),
FileType::Plaintext
);
}
#[test]
fn test_extract_markdown_links() {
let input = "This is [a test](https://endler.dev). This is a relative link test [Relative Link Test](relative_link)";