Skip to content

Commit

Permalink
tests: use insta for JS parser
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Oct 25, 2024
1 parent 28a2a6c commit 113d93b
Show file tree
Hide file tree
Showing 2,008 changed files with 183,212 additions and 167,207 deletions.
23 changes: 6 additions & 17 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/biome_configuration/src/javascript/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ pub struct JavascriptParser {
/// These decorators belong to an old proposal, and they are subject to change.
#[partial(bpaf(hide))]
pub unsafe_parameter_decorators_enabled: bool,

/// Enables parsing of Grit metavariables.
/// Defaults to `false`.
#[partial(bpaf(hide))]
pub grit_metavariables: bool,
}

/// Indicates the type of runtime or transformation used for interpreting JSX.
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_js_analyze/src/utils/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub fn assert_rename_binding_a_to_b_ok(before: &str, expected: &str) {
let after = root.to_string();
assert_eq!(expected, after.as_str());

assert!(!biome_js_parser::test_utils::has_bogus_nodes_or_empty_slots(&root));
assert!(!biome_test_utils::has_bogus_nodes_or_empty_slots(&root));
}

pub fn assert_rename_ts_binding_a_to_b_ok(before: &str, expected: &str) {
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn assert_rename_ts_binding_a_to_b_ok(before: &str, expected: &str) {
let after = root.to_string();
assert_eq!(expected, after.as_str());

assert!(!biome_js_parser::test_utils::has_bogus_nodes_or_empty_slots(&root));
assert!(!biome_test_utils::has_bogus_nodes_or_empty_slots(&root));
}

/// Search and renames one binding named "a" to "b".
Expand Down
14 changes: 10 additions & 4 deletions crates/biome_js_parser/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ smallvec = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
expect-test = "1.5.0"
quickcheck = { workspace = true }
quickcheck_macros = { workspace = true }
tests_macros = { workspace = true }
biome_configuration = { workspace = true }
biome_deserialize = { workspace = true }
biome_fs = { workspace = true }
biome_service = { workspace = true }
biome_test_utils = { workspace = true }
insta = { workspace = true }
quickcheck = { workspace = true }
quickcheck_macros = { workspace = true }
tests_macros = { path = "../tests_macros" }


[features]
schemars = ["dep:schemars"]
Expand Down
62 changes: 2 additions & 60 deletions crates/biome_js_parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,74 +57,16 @@
//! In conclusion, the use of both representations means we are not constrained to acting through
//! typed nodes. Which makes traversal hard and you often have to resort to autogenerated visitor patterns.
//! AST nodes are simply a way to easily access subproperties of a syntax node.event;
//!
//! ## Parser Tests
//!
//! Parser tests are comments that start with `test` or `test_err` followed by the test name, and then the code on its own line.
//!
//! ```rust,ignore
//! // test js feature_name
//! // let a = { new_feature : "" }
//! // let b = { new_feature : "" }
//! fn parse_new_feature(p: &mut Parser) -> ParsedSyntax {}
//! ```
//!
//! * `test`: Test for a valid program. Should not produce any diagnostics nor missing nodes.
//! * `test_err`: Test for a program with syntax error. Must produce a diagnostic.
//!
//! By default, the test runs as a JavaScript Module. You can customize the source type by specifying the
//! file type after `test` or `test_err`
//!
//! ```rust,ignore
//! // test ts typescript_test
//! // console.log("a");
//! if a {
//! // ..
//! }
//! ```
//!
//! The supported source types are:
//! * `js`
//! * `jsx`
//! * `ts`
//! * `tsx`
//! * `d.ts`
//!
//! To enable script mode, add a `// script` comment to the code.
//!
//! To extract the test cases, run `cargo codegen test`. Running the codegen is necessary whenever you add,
//! change, or remove inline tests .
//!
//! To update the test output, run
//!
//!
//! **Linux/MacOs**:
//!
//! ```bash
//! env UPDATE_EXPECT=1 cargo test
//! ```
//!
//! **Windows**
//!
//! ```powershell
//! set UPDATE_EXPECT=1 & cargo test
//! ```
mod parser;
#[macro_use]
mod lexer;
pub mod options;
mod parse;
mod prelude;
mod rewrite;
mod span;
mod state;

#[cfg(any(test, feature = "tests"))]
pub mod test_utils;
#[cfg(test)]
mod tests;

pub mod options;
mod prelude;
pub mod syntax;
mod token_source;

Expand Down
67 changes: 0 additions & 67 deletions crates/biome_js_parser/src/test_utils.rs

This file was deleted.

Loading

0 comments on commit 113d93b

Please sign in to comment.