From 7a02e232de88890e83684f9035b93f8b540fb22b Mon Sep 17 00:00:00 2001 From: "Matthew \"strager\" Glazar" Date: Sun, 7 Jan 2024 12:35:15 -0500 Subject: [PATCH] refactor(test): replace some uses of DIAG_TYPE I want to remove the Diag_Collector-based matchers. Remove some uses of DIAG_TYPE. https://github.com/quick-lint/quick-lint-js/issues/1154 --- src/quick-lint-js/diag/diag-list.cpp | 9 +++++++++ src/quick-lint-js/diag/diag-list.h | 1 + test/test-parse-expression.cpp | 8 +++++--- test/test-parse-statement.cpp | 4 +--- test/test-parse.cpp | 11 +++++------ 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/quick-lint-js/diag/diag-list.cpp b/src/quick-lint-js/diag/diag-list.cpp index ec5656fced..b7fe2cc5ae 100644 --- a/src/quick-lint-js/diag/diag-list.cpp +++ b/src/quick-lint-js/diag/diag-list.cpp @@ -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. } diff --git a/src/quick-lint-js/diag/diag-list.h b/src/quick-lint-js/diag/diag-list.h index 7469e92db9..013f756382 100644 --- a/src/quick-lint-js/diag/diag-list.h +++ b/src/quick-lint-js/diag/diag-list.h @@ -63,6 +63,7 @@ class Diag_List { bool empty() const; bool reported_any_diagnostic_except_since( std::initializer_list ignored_types, const Rewind_State &); + bool have_diagnostic(Diag_Type type) const; void clear(); diff --git a/test/test-parse-expression.cpp b/test/test-parse-expression.cpp index 3ce1b1bb68..8517a47128 100644 --- a/test/test-parse-expression.cpp +++ b/test/test-parse-expression.cpp @@ -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) { diff --git a/test/test-parse-statement.cpp b/test/test-parse-statement.cpp index d91efbf7aa..46b9422f01 100644 --- a/test/test-parse-statement.cpp +++ b/test/test-parse-statement.cpp @@ -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)); } } diff --git a/test/test-parse.cpp b/test/test-parse.cpp index d8f0321fc4..8e7bae4b4b 100644 --- a/test/test-parse.cpp +++ b/test/test-parse.cpp @@ -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)); } { @@ -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)); } } @@ -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)); } {