Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wasm test for new parser #841

Merged
merged 1 commit into from
Feb 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 30 additions & 10 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/analyzer/src/namespace/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,8 +1665,8 @@ impl ImplId {
|| other == Type::SelfType(TraitOrType::TypeId(self.receiver(db))).id(db)
}

/// Returns `true` if the `type_in_impl` can stand in for the `type_in_trait` as a type used
/// for a parameter or as a return type
/// Returns `true` if the `type_in_impl` can stand in for the
/// `type_in_trait` as a type used for a parameter or as a return type
pub fn can_stand_in_for(
&self,
db: &dyn AnalyzerDb,
Expand Down
7 changes: 6 additions & 1 deletion crates/parser2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ fxhash = "0.2.1"
lazy_static = "1.4.0"

[dev-dependencies]
fe-compiler-test-utils = { path = "../test-utils" }
fe-compiler-test-utils = { path = "../test-utils" }
dir-test = "0.1"
wasm-bindgen-test = "0.3"

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = "0.2"
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/parser2/tests/syntax_node.rs
expression: snapshot
expression: node
input_file: crates/parser2/test_files/syntax_node/exprs/if.fe
---
Root@0..279
IfExpr@0..15
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/parser2/tests/syntax_node.rs
expression: snapshot
expression: node
input_file: crates/parser2/test_files/syntax_node/exprs/match.fe
---
Root@0..516
MatchExpr@0..10
Expand Down
122 changes: 68 additions & 54 deletions crates/parser2/tests/error_recovery.rs
Original file line number Diff line number Diff line change
@@ -1,64 +1,78 @@
use fe_parser2::{
parser::{expr::parse_expr, item::ItemListScope, stmt::parse_stmt},
syntax_node::SyntaxNode,
};
use dir_test::{dir_test, Fixture};

use fe_compiler_test_utils::snap_test;

mod test_runner;
use test_runner::*;
fe_compiler_test_utils::build_debug_snap_tests! {
"parser2/test_files/error_recovery/items",
"parser2/test_files/error_recovery/items",
test_item_list
}
fn test_item_list(input: &str) -> SyntaxNode {
let runner = TestRunner::new(
|parser| {
parser.parse(ItemListScope::default(), None);
},
false,
);
runner.run(input)
}

fe_compiler_test_utils::build_debug_snap_tests! {
"parser2/test_files/error_recovery/exprs",
"parser2/test_files/error_recovery/exprs",
test_expr
#[dir_test(
dir: "$CARGO_MANIFEST_DIR/test_files/error_recovery/items",
glob: "*.fe"
)]
fn test_item_list(fixture: Fixture<&str>) {
let runner = TestRunner::item_list(false);
let node = format! {"{:#?}", runner.run(fixture.content())};
snap_test!(node, fixture.path());
}
fn test_expr(input: &str) -> SyntaxNode {
let runner = TestRunner::new(
|parser| {
parser.set_newline_as_trivia(false);

bump_newlines(parser);
while parser.current_kind().is_some() {
bump_newlines(parser);
parse_expr(parser);
bump_newlines(parser);
}
},
false,
);
runner.run(input)
#[dir_test(
dir: "$CARGO_MANIFEST_DIR/test_files/error_recovery/stmts",
glob: "*.fe"
)]
fn test_stmt(fixture: Fixture<&str>) {
let runner = TestRunner::stmt_list(false);
let node = format! {"{:#?}", runner.run(fixture.content())};
snap_test!(node, fixture.path());
}

fe_compiler_test_utils::build_debug_snap_tests! {
"parser2/test_files/error_recovery/stmts",
"parser2/test_files/error_recovery/stmts",
test_stmt
#[dir_test(
dir: "$CARGO_MANIFEST_DIR/test_files/error_recovery/exprs",
glob: "*.fe"
)]
fn test_expr(fixture: Fixture<&str>) {
let runner = TestRunner::expr_list(false);
let node = format! {"{:#?}", runner.run(fixture.content())};
snap_test!(node, fixture.path());
}
fn test_stmt(input: &str) -> SyntaxNode {
let runner = TestRunner::new(
|parser| {
parser.set_newline_as_trivia(false);

bump_newlines(parser);
while parser.current_kind().is_some() {
bump_newlines(parser);
parse_stmt(parser, None);
bump_newlines(parser);
}
},
false,
);
runner.run(input)
#[cfg(target_family = "wasm")]
mod wasm {
use super::*;
use wasm_bindgen_test::wasm_bindgen_test;

#[dir_test(
dir: "$CARGO_MANIFEST_DIR/test_files/error_recovery/items",
glob: "*.fe"
postfix: "wasm"
)]
#[dir_test_attr(
#[wasm_bindgen_test]
)]
fn test_item_list(fixture: Fixture<&str>) {
TestRunner::item_list(false).run(fixture.content());
}

#[dir_test(
dir: "$CARGO_MANIFEST_DIR/test_files/error_recovery/stmts",
glob: "*.fe"
postfix: "wasm"
)]
#[dir_test_attr(
#[wasm_bindgen_test]
)]
fn test_stmt(fixture: Fixture<&str>) {
TestRunner::stmt_list(false).run(fixture.content());
}

#[dir_test(
dir: "$CARGO_MANIFEST_DIR/test_files/error_recovery/exprs",
glob: "*.fe"
postfix: "wasm"
)]
#[dir_test_attr(
#[wasm_bindgen_test]
)]
fn test_expr(fixture: Fixture<&str>) {
TestRunner::expr_list(false).run(fixture.content());
}
}
Loading