Skip to content

Commit

Permalink
test: validate taplo works
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen committed Mar 7, 2024
1 parent d3ae6e7 commit a8398a9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
- run: rustup toolchain install stable --profile minimal
- run: rustup component add rustfmt clippy

- run: cargo install taplo
- run: pip install ruff

- run: cargo test
6 changes: 3 additions & 3 deletions src/formatters/ruff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ mod test_ruff {
use super::format_using_ruff;

#[test]
fn it_should_format_code() {
let snippet = r"def add( a: int , b:int)->int: return a+b";
fn it_should_format_python() {
let input = "def add( a: int , b:int)->int: return a+b";

let expected_output = "def add(a: int, b: int) -> int:\n return a + b\n";

let snippet = setup_snippet(snippet, Language::Python.to_file_ext())
let snippet = setup_snippet(input, Language::Python.to_file_ext())
.expect("it to create a snippet file");

let output = format_using_ruff(snippet.path())
Expand Down
6 changes: 3 additions & 3 deletions src/formatters/rustfmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ mod test_rustfmt {
use super::format_using_rustfmt;

#[test]
fn it_should_format_code() {
let snippet = r"pub
fn it_should_format_rust() {
let input = "pub
async
fn add( a: i32,
b:i32 )-> i32 {a+b}
";

let expected_output = "pub async fn add(a: i32, b: i32) -> i32 {\n a + b\n}\n";

let snippet = setup_snippet(snippet, Language::Rust.to_file_ext())
let snippet = setup_snippet(input, Language::Rust.to_file_ext())
.expect("it to create a snippet file");

let output = format_using_rustfmt(snippet.path())
Expand Down
28 changes: 28 additions & 0 deletions src/formatters/taplo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,31 @@ pub fn format_using_taplo(file_path: &std::path::Path) -> std::io::Result<Option

Ok(None)
}

#[cfg(test)]
mod test_taplo {
use crate::{
formatters::{setup_snippet, taplo::format_using_taplo},
languages::Language,
};

#[test]
fn it_should_format_toml() {
let input = r#" package = "mdsf"
author = "Mads Hougesen"
"#;

let expected_output = r#"package = "mdsf"
author = "Mads Hougesen"
"#;

let snippet = setup_snippet(input, Language::Toml.to_file_ext())
.expect("it to create a snippet file");

let output = format_using_taplo(snippet.path())
.expect("it to be succesful")
.expect("it to be some");

assert_eq!(expected_output, output);
}
}

0 comments on commit a8398a9

Please sign in to comment.