Skip to content

Commit

Permalink
test: add tests for markdownlint (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Jan 21, 2025
1 parent 63192bb commit d4895fb
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### [Unreleased](https://github.com/hougesen/mdsf/compare/v0.4.1...HEAD)

- test: add tests for markdownlint [`#621`](https://github.com/hougesen/mdsf/pull/621)
- feat: add support for mado [`#620`](https://github.com/hougesen/mdsf/pull/620)
- feat: add option to ignore output of tool [`#619`](https://github.com/hougesen/mdsf/pull/619)
- feat: add support for mado (#620) [`#617`](https://github.com/hougesen/mdsf/issues/617)

#### [v0.4.1](https://github.com/hougesen/mdsf/compare/v0.4.0...v0.4.1)

Expand Down
26 changes: 24 additions & 2 deletions mdsf/src/tools/markdownlint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
let commands = [
CommandType::NodeModules("markdownlint"),
CommandType::Direct("markdownlint"),
CommandType::Npm("markdownlint"),
CommandType::Npm("markdownlint-cli"),
];

for (index, cmd) in commands.iter().enumerate() {
Expand All @@ -39,4 +39,26 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
}

#[cfg(test)]
mod test_markdownlint {}
mod test_markdownlint {
#[test_with::executable(npx)]
fn test_markdownlint_markdown_1f615768d8e575c5() {
let input = r#"# Hello world
- asd
* vasd
"#;
let output = r#"# Hello world
- asd
- vasd
"#;
let file_ext = crate::fttype::get_file_extension("markdown");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::markdownlint::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
assert_eq!(result, output);
}
}
24 changes: 23 additions & 1 deletion mdsf/src/tools/markdownlint_cli_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,26 @@ pub fn run(file_path: &std::path::Path) -> Result<(bool, Option<String>), MdsfEr
}

#[cfg(test)]
mod test_markdownlint_cli_2 {}
mod test_markdownlint_cli_2 {
#[test_with::executable(npx)]
fn test_markdownlint_cli_2_markdown_1f615768d8e575c5() {
let input = r#"# Hello world
- asd
* vasd
"#;
let output = r#"# Hello world
- asd
- vasd
"#;
let file_ext = crate::fttype::get_file_extension("markdown");
let snippet =
crate::execution::setup_snippet(input, &file_ext).expect("it to create a snippet file");
let result = crate::tools::markdownlint_cli_2::run(snippet.path())
.expect("it to be successful")
.1
.expect("it to be some");
assert_eq!(result, output);
}
}
9 changes: 8 additions & 1 deletion tools/markdownlint-cli2/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
"commands": {
"": {
"arguments": ["--fix", "$PATH"],
"ignore_output": false
"ignore_output": false,
"tests": [
{
"language": "markdown",
"test_input": "# Hello world\n\n- asd \n* vasd\n",
"test_output": "# Hello world\n\n- asd\n- vasd\n"
}
]
}
},
"description": "A fast, flexible, configuration-based command-line interface for linting Markdown/CommonMark files with the markdownlint library",
Expand Down
11 changes: 9 additions & 2 deletions tools/markdownlint/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@
"commands": {
"": {
"arguments": ["--fix", "$PATH"],
"ignore_output": false
"ignore_output": false,
"tests": [
{
"language": "markdown",
"test_input": "# Hello world\n\n- asd \n* vasd\n",
"test_output": "# Hello world\n\n- asd\n- vasd\n"
}
]
}
},
"description": "A Node.js style checker and lint tool for Markdown/CommonMark files",
"homepage": "https://github.com/davidanson/markdownlint",
"languages": ["markdown"],
"npm": "markdownlint"
"npm": "markdownlint-cli"
}

0 comments on commit d4895fb

Please sign in to comment.