Skip to content

Commit

Permalink
refactor(test): replace some uses of DIAG_TYPE
Browse files Browse the repository at this point in the history
I want to remove the Diag_Collector-based matchers. Remove some uses
of DIAG_TYPE.
  • Loading branch information
strager committed Jan 7, 2024
1 parent 9d46145 commit 0738d21
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/quick-lint-js/diag/diag-list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ bool Diag_List::reported_any_diagnostic_except_since(
return false;
}

bool Diag_List::have_diagnostic(Diag_Type type) const {
for (Node_Base *node = this->first_; node != nullptr; node = node->next) {
if (node->type == type) {
return true;
}
}
return false;
}

void Diag_List::clear() {
// Leak. this->memory should be a Linked_Bump_Allocator managed by the caller.
}
Expand Down
1 change: 1 addition & 0 deletions src/quick-lint-js/diag/diag-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Diag_List {
bool empty() const;
bool reported_any_diagnostic_except_since(
std::initializer_list<Diag_Type> ignored_types, const Rewind_State &);
bool have_diagnostic(Diag_Type type) const;

void clear();

Expand Down
8 changes: 5 additions & 3 deletions test/test-parse-expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3535,9 +3535,11 @@ TEST_F(Test_Parse_Expression, generator_misplaced_star) {
Test_Parser p(u8"(*function f(){})"_sv, capture_diags);
Expression* ast = p.parse_expression();
EXPECT_THAT(ast->child_0()->span(), p.matches_offsets(1, 16));
EXPECT_THAT(p.legacy_errors(),
ElementsAreArray({DIAG_TYPE(
Diag_Generator_Function_Star_Belongs_Before_Name)}));
assert_diagnostics(
p.code, p.errors,
{
u8"Diag_Generator_Function_Star_Belongs_Before_Name"_diag,
});
}

TEST_F(Test_Parse_Expression, unary_cannot_mix_with_star_star) {
Expand Down
4 changes: 1 addition & 3 deletions test/test-parse-statement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,9 +610,7 @@ TEST_F(Test_Parse_Statement, if_else_with_malformed_condition) {
"visit_enter_block_scope", //
"visit_variable_use", // e
"visit_exit_block_scope"}));
EXPECT_THAT(
p.legacy_errors(),
::testing::Not(::testing::Contains(DIAG_TYPE(Diag_Else_Has_No_If))));
EXPECT_FALSE(p.errors.have_diagnostic(Diag_Type::Diag_Else_Has_No_If));
}
}

Expand Down
11 changes: 5 additions & 6 deletions test/test-parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,8 +753,8 @@ TEST_F(Test_No_Overflow, parser_depth_limit_not_exceeded) {
SCOPED_TRACE(p.code);
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors();
EXPECT_TRUE(ok);
EXPECT_THAT(p.legacy_errors(), ::testing::Not(::testing::Contains(
DIAG_TYPE(Diag_Depth_Limit_Exceeded))));
EXPECT_FALSE(
p.errors.have_diagnostic(Diag_Type::Diag_Depth_Limit_Exceeded));
}

{
Expand Down Expand Up @@ -813,8 +813,8 @@ TEST_F(Test_No_Overflow, certain_syntax_does_not_have_stack_limit) {
SCOPED_TRACE(p.code);
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors();
EXPECT_TRUE(ok);
EXPECT_THAT(p.legacy_errors(), ::testing::Not(::testing::Contains(
DIAG_TYPE(Diag_Depth_Limit_Exceeded))));
EXPECT_FALSE(
p.errors.have_diagnostic(Diag_Type::Diag_Depth_Limit_Exceeded));
}
}

Expand Down Expand Up @@ -867,8 +867,7 @@ TEST_F(Test_Overflow, parser_depth_limit_exceeded) {
capture_diags);
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors();
EXPECT_FALSE(ok);
EXPECT_THAT(p.legacy_errors(),
::testing::Contains(DIAG_TYPE(Diag_Depth_Limit_Exceeded)));
EXPECT_TRUE(p.errors.have_diagnostic(Diag_Type::Diag_Depth_Limit_Exceeded));
}

{
Expand Down

0 comments on commit 0738d21

Please sign in to comment.