Skip to content

Commit 641dbd9

Browse files
committed
refactor(test): replace some uses of DIAG_TYPE
I want to remove the Diag_Collector-based matchers. Remove some uses of DIAG_TYPE. #1154
1 parent b3a00ae commit 641dbd9

File tree

5 files changed

+21
-12
lines changed

5 files changed

+21
-12
lines changed

src/quick-lint-js/diag/diag-list.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ bool Diag_List::reported_any_diagnostic_except_since(
7777
return false;
7878
}
7979

80+
bool Diag_List::have_diagnostic(Diag_Type type) const {
81+
for (Node_Base *node = this->first_; node != nullptr; node = node->next) {
82+
if (node->type == type) {
83+
return true;
84+
}
85+
}
86+
return false;
87+
}
88+
8089
void Diag_List::clear() {
8190
// Leak. this->memory should be a Linked_Bump_Allocator managed by the caller.
8291
}

src/quick-lint-js/diag/diag-list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class Diag_List {
6363
bool empty() const;
6464
bool reported_any_diagnostic_except_since(
6565
std::initializer_list<Diag_Type> ignored_types, const Rewind_State &);
66+
bool have_diagnostic(Diag_Type type) const;
6667

6768
void clear();
6869

test/test-parse-expression.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3535,9 +3535,11 @@ TEST_F(Test_Parse_Expression, generator_misplaced_star) {
35353535
Test_Parser p(u8"(*function f(){})"_sv, capture_diags);
35363536
Expression* ast = p.parse_expression();
35373537
EXPECT_THAT(ast->child_0()->span(), p.matches_offsets(1, 16));
3538-
EXPECT_THAT(p.legacy_errors(),
3539-
ElementsAreArray({DIAG_TYPE(
3540-
Diag_Generator_Function_Star_Belongs_Before_Name)}));
3538+
assert_diagnostics(
3539+
p.code, p.errors,
3540+
{
3541+
u8"Diag_Generator_Function_Star_Belongs_Before_Name"_diag,
3542+
});
35413543
}
35423544

35433545
TEST_F(Test_Parse_Expression, unary_cannot_mix_with_star_star) {

test/test-parse-statement.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,9 +610,7 @@ TEST_F(Test_Parse_Statement, if_else_with_malformed_condition) {
610610
"visit_enter_block_scope", //
611611
"visit_variable_use", // e
612612
"visit_exit_block_scope"}));
613-
EXPECT_THAT(
614-
p.legacy_errors(),
615-
::testing::Not(::testing::Contains(DIAG_TYPE(Diag_Else_Has_No_If))));
613+
EXPECT_FALSE(p.errors.have_diagnostic(Diag_Type::Diag_Else_Has_No_If));
616614
}
617615
}
618616

test/test-parse.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,8 @@ TEST_F(Test_No_Overflow, parser_depth_limit_not_exceeded) {
753753
SCOPED_TRACE(p.code);
754754
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors();
755755
EXPECT_TRUE(ok);
756-
EXPECT_THAT(p.legacy_errors(), ::testing::Not(::testing::Contains(
757-
DIAG_TYPE(Diag_Depth_Limit_Exceeded))));
756+
EXPECT_FALSE(
757+
p.errors.have_diagnostic(Diag_Type::Diag_Depth_Limit_Exceeded));
758758
}
759759

760760
{
@@ -813,8 +813,8 @@ TEST_F(Test_No_Overflow, certain_syntax_does_not_have_stack_limit) {
813813
SCOPED_TRACE(p.code);
814814
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors();
815815
EXPECT_TRUE(ok);
816-
EXPECT_THAT(p.legacy_errors(), ::testing::Not(::testing::Contains(
817-
DIAG_TYPE(Diag_Depth_Limit_Exceeded))));
816+
EXPECT_FALSE(
817+
p.errors.have_diagnostic(Diag_Type::Diag_Depth_Limit_Exceeded));
818818
}
819819
}
820820

@@ -867,8 +867,7 @@ TEST_F(Test_Overflow, parser_depth_limit_exceeded) {
867867
capture_diags);
868868
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors();
869869
EXPECT_FALSE(ok);
870-
EXPECT_THAT(p.legacy_errors(),
871-
::testing::Contains(DIAG_TYPE(Diag_Depth_Limit_Exceeded)));
870+
EXPECT_TRUE(p.errors.have_diagnostic(Diag_Type::Diag_Depth_Limit_Exceeded));
872871
}
873872

874873
{

0 commit comments

Comments
 (0)