-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(format/grit): add tests for grit formatter (#3937)
Co-authored-by: Carson McManus <dyc3@users.noreply.github.com>
- Loading branch information
Showing
22 changed files
with
404 additions
and
26 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
use biome_formatter_test::TestFormatLanguage; | ||
use biome_grit_formatter::{context::GritFormatContext, GritFormatLanguage}; | ||
use biome_grit_parser::parse_grit; | ||
use biome_grit_syntax::GritLanguage; | ||
|
||
#[derive(Default)] | ||
pub struct GritTestFormatLanguage; | ||
|
||
impl TestFormatLanguage for GritTestFormatLanguage { | ||
type ServiceLanguage = GritLanguage; | ||
type Context = GritFormatContext; | ||
type FormatLanguage = GritFormatLanguage; | ||
|
||
fn parse(&self, text: &str) -> biome_parser::AnyParse { | ||
parse_grit(text).into() | ||
} | ||
|
||
fn to_format_language( | ||
&self, | ||
_settings: &biome_service::settings::Settings, | ||
_file_source: &biome_service::workspace::DocumentFileSource, | ||
) -> Self::FormatLanguage { | ||
todo!() | ||
} | ||
} |
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,27 @@ | ||
use biome_formatter_test::spec::{SpecSnapshot, SpecTestFile}; | ||
use biome_grit_formatter::{context::GritFormatOptions, GritFormatLanguage}; | ||
use std::path::Path; | ||
|
||
mod language { | ||
include!("language.rs"); | ||
} | ||
|
||
pub fn run(spec_input_file: &str, _expected_file: &str, test_directory: &str, _file_type: &str) { | ||
let root_path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/tests/specs/")); | ||
|
||
let Some(test_file) = SpecTestFile::try_from_file(spec_input_file, root_path, None) else { | ||
panic!("Failed to set up snapshot test"); | ||
}; | ||
|
||
let options = GritFormatOptions::default(); | ||
let language = language::GritTestFormatLanguage; | ||
|
||
let snapshot = SpecSnapshot::new( | ||
test_file, | ||
test_directory, | ||
language, | ||
GritFormatLanguage::new(options), | ||
); | ||
|
||
snapshot.test() | ||
} |
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,8 @@ | ||
mod spec_test; | ||
|
||
mod formatter { | ||
|
||
mod grit_module { | ||
tests_macros::gen_tests! {"tests/specs/grit/**/*.grit", crate::spec_test::run, ""} | ||
} | ||
} |
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 @@ | ||
file(body = contains `console.$method` => `println`) |
33 changes: 33 additions & 0 deletions
33
crates/biome_grit_formatter/tests/specs/grit/file_node.grit.snap
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,33 @@ | ||
--- | ||
source: crates/biome_formatter_test/src/snapshot_builder.rs | ||
info: grit/file_node.grit | ||
--- | ||
# Input | ||
|
||
```grit | ||
file(body = contains `console.$method` => `println`) | ||
``` | ||
|
||
|
||
============================= | ||
|
||
# Outputs | ||
|
||
## Output 1 | ||
|
||
----- | ||
Indent style: Tab | ||
Indent width: 2 | ||
Line ending: LF | ||
Line width: 80 | ||
Attribute Position: Auto | ||
----- | ||
|
||
```grit | ||
file(body = contains `console.$method` => `println`)``` | ||
|
||
|
||
|
||
## Unimplemented nodes/tokens | ||
|
||
"file(body = contains `console.$method` => `println`)" => 0..52 |
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
Oops, something went wrong.