-
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.
- Loading branch information
Showing
13 changed files
with
243 additions
and
9 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
File renamed without changes.
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,70 @@ | ||
use crate::runners::{setup_npm_script, JavaScriptRuntime}; | ||
|
||
use super::execute_command; | ||
|
||
#[inline] | ||
fn set_purs_tidy_args(cmd: &mut std::process::Command, snippet_path: &std::path::Path) { | ||
cmd.arg("format-in-place").arg(snippet_path); | ||
} | ||
|
||
#[inline] | ||
fn invoke_purs_tidy( | ||
mut cmd: std::process::Command, | ||
snippet_path: &std::path::Path, | ||
) -> std::io::Result<(bool, Option<String>)> { | ||
set_purs_tidy_args(&mut cmd, snippet_path); | ||
|
||
execute_command(&mut cmd, snippet_path) | ||
} | ||
|
||
#[inline] | ||
pub fn format_using_purs_tidy( | ||
snippet_path: &std::path::Path, | ||
) -> std::io::Result<(bool, Option<String>)> { | ||
invoke_purs_tidy( | ||
setup_npm_script(JavaScriptRuntime::default(), "purs-tidy"), | ||
snippet_path, | ||
) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_purs_tidy { | ||
use crate::{formatters::setup_snippet, languages::Language}; | ||
|
||
use super::format_using_purs_tidy; | ||
|
||
#[test] | ||
fn it_should_format_purescript() { | ||
let input = r#"module Test.Main where | ||
import Prelude | ||
import Effect (Effect) | ||
import Effect.Class.Console (log) | ||
main :: Effect Unit | ||
main = do | ||
log "You should add some tests.""#; | ||
|
||
let expected_output = r#"module Test.Main where | ||
import Prelude | ||
import Effect (Effect) | ||
import Effect.Class.Console (log) | ||
main :: Effect Unit | ||
main = do | ||
log "You should add some tests.""#; | ||
|
||
let snippet = setup_snippet(input, Language::PureScript.to_file_ext()) | ||
.expect("it to create a snippet file"); | ||
|
||
let output = format_using_purs_tidy(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
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
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,113 @@ | ||
use schemars::JsonSchema; | ||
|
||
use crate::formatters::{purs_tidy::format_using_purs_tidy, MdsfFormatter}; | ||
|
||
use super::{Lang, LanguageFormatter}; | ||
|
||
#[derive(Debug, Default, serde::Serialize, serde::Deserialize, JsonSchema)] | ||
#[cfg_attr(test, derive(PartialEq, Eq))] | ||
pub enum PureScript { | ||
#[default] | ||
#[serde(rename = "purs-tidy")] | ||
PursTidy, | ||
} | ||
|
||
impl Default for Lang<PureScript> { | ||
#[inline] | ||
fn default() -> Self { | ||
Self { | ||
enabled: true, | ||
formatter: MdsfFormatter::<PureScript>::default(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for MdsfFormatter<PureScript> { | ||
#[inline] | ||
fn default() -> Self { | ||
Self::Single(PureScript::PursTidy) | ||
} | ||
} | ||
|
||
impl LanguageFormatter for PureScript { | ||
#[inline] | ||
fn format_snippet( | ||
&self, | ||
snippet_path: &std::path::Path, | ||
) -> std::io::Result<(bool, Option<String>)> { | ||
match self { | ||
Self::PursTidy => format_using_purs_tidy(snippet_path), | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test_purescript { | ||
use crate::{ | ||
formatters::{setup_snippet, MdsfFormatter}, | ||
languages::Lang, | ||
}; | ||
|
||
use super::PureScript; | ||
|
||
const INPUT: &str = r#"module Test.Main where | ||
import Prelude | ||
import Effect (Effect) | ||
import Effect.Class.Console (log) | ||
main :: Effect Unit | ||
main = do | ||
log "You should add some tests.""#; | ||
|
||
const EXTENSION: &str = crate::languages::Language::PureScript.to_file_ext(); | ||
|
||
#[test] | ||
fn it_should_be_enabled_by_default() { | ||
assert!(Lang::<PureScript>::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!(Lang::<PureScript> { | ||
enabled: false, | ||
formatter: MdsfFormatter::Single(PureScript::default()) | ||
} | ||
.format(snippet_path) | ||
.expect("it to not fail") | ||
.is_none()); | ||
} | ||
|
||
#[test] | ||
fn test_purs_tidy() { | ||
let l = Lang::<PureScript> { | ||
enabled: true, | ||
formatter: MdsfFormatter::Single(PureScript::PursTidy), | ||
}; | ||
|
||
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"); | ||
|
||
let expected_output = r#"module Test.Main where | ||
import Prelude | ||
import Effect (Effect) | ||
import Effect.Class.Console (log) | ||
main :: Effect Unit | ||
main = do | ||
log "You should add some tests.""#; | ||
|
||
assert_eq!(output, expected_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