-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(java): add google-java-format (#89)
- Loading branch information
Showing
5 changed files
with
89 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use super::execute_command; | ||
|
||
#[inline] | ||
pub fn format_using_google_java_format( | ||
snippet_path: &std::path::Path, | ||
) -> std::io::Result<(bool, Option<String>)> { | ||
let mut cmd = std::process::Command::new("google-java-format"); | ||
|
||
cmd.arg("-i").arg(snippet_path); | ||
|
||
execute_command(&mut cmd, snippet_path) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_google_java_format { | ||
use crate::{formatters::setup_snippet, languages::Language}; | ||
|
||
use super::format_using_google_java_format; | ||
|
||
#[test_with::executable(google-java-format)] | ||
#[test] | ||
fn it_should_format_java() { | ||
let input = "class HelloWorld { | ||
public static void main(String[] args) { | ||
System.out.println(\"Hello\"); | ||
System.out.println(\"World!\"); | ||
} | ||
}"; | ||
|
||
let expected_output = "class HelloWorld { | ||
public static void main(String[] args) { | ||
System.out.println(\"Hello\"); | ||
System.out.println(\"World!\"); | ||
} | ||
} | ||
"; | ||
|
||
let snippet = setup_snippet(input, Language::Java.to_file_ext()) | ||
.expect("it to create a snippet file"); | ||
|
||
let output = format_using_google_java_format(snippet.path()) | ||
.expect("it to be successful") | ||
.1 | ||
.expect("it to be some"); | ||
|
||
assert_eq!(expected_output, output); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters