Skip to content

Commit

Permalink
test(markdown): prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Mar 11, 2024
1 parent c339358 commit cf47939
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/languages/elixir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl LanguageFormatter for Elixir {
}

#[cfg(test)]
mod test_elixir {
mod test_elixir {
use crate::{formatters::setup_snippet, languages::LanguageFormatter};

use super::{Elixir, ElixirFormatter};
Expand Down
50 changes: 49 additions & 1 deletion src/languages/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,58 @@ impl LanguageFormatter for Markdown {

#[cfg(test)]
mod test_markdown {
use crate::languages::markdown::Markdown;
use crate::{formatters::setup_snippet, languages::LanguageFormatter};

use super::{Markdown, MarkdownFormatter};

const INPUT: &str = "
# mads was here
the whitespace should be removed
";

const EXTENSION: &str = crate::languages::Language::Markdown.to_file_ext();

#[test]
fn it_should_be_enabled_by_default() {
assert!(!Markdown::default().enabled);
}

#[test]
fn it_should_not_format_when_enabled_is_false() {
let snippet = setup_snippet(INPUT, EXTENSION).expect("it to save the file");
let snippet_path = snippet.path();

assert!(Markdown {
enabled: false,
formatter: MarkdownFormatter::default(),
}
.format(snippet_path)
.expect("it to not fail")
.is_none());
}

#[test]
fn test_prettier() {
let expected_output = "# mads was here
the whitespace should be removed
";

let l = Markdown {
enabled: true,
formatter: MarkdownFormatter::Prettier,
};

let snippet = setup_snippet(INPUT, EXTENSION).expect("it to save the file");
let snippet_path = snippet.path();

let output = l
.format(snippet_path)
.expect("it to not fail")
.expect("it to be a snippet");

assert_eq!(output, expected_output);
}
}

0 comments on commit cf47939

Please sign in to comment.