|
7 | 7 | #include <quick-lint-js/diag-matcher.h>
|
8 | 8 | #include <quick-lint-js/diag/diag-list.h>
|
9 | 9 | #include <quick-lint-js/diag/diagnostic-types.h>
|
| 10 | +#include <quick-lint-js/diagnostic-assertion.h> |
10 | 11 | #include <quick-lint-js/fe/lex.h>
|
11 | 12 | #include <quick-lint-js/identifier-support.h>
|
12 | 13 | #include <type_traits>
|
@@ -189,6 +190,41 @@ TEST(Test_Diag_List, pretty_print_one_diag) {
|
189 | 190 | EXPECT_EQ(ss.str(), "1 diagnostic: {\n Diag_Let_With_No_Bindings,\n}");
|
190 | 191 | }
|
191 | 192 | }
|
| 193 | + |
| 194 | +TEST(Test_Diag_List, moving_diag_list_clears_original) { |
| 195 | + Linked_Bump_Allocator memory("test"); |
| 196 | + Diag_List diags_1(&memory); |
| 197 | + Padded_String code(u8"hello"_sv); |
| 198 | + diags_1.add(Diag_Let_With_No_Bindings{.where = span_of(code)}); |
| 199 | + Diag_List diags_2 = std::move(diags_1); |
| 200 | + EXPECT_EQ(diags_1.size(), 0); |
| 201 | +} |
| 202 | + |
| 203 | +TEST(Test_Diag_List, moving_diag_list_keeps_single_diag) { |
| 204 | + Linked_Bump_Allocator memory("test"); |
| 205 | + Diag_List diags_1(&memory); |
| 206 | + Padded_String code(u8"hello"_sv); |
| 207 | + diags_1.add(Diag_Let_With_No_Bindings{.where = span_of(code)}); |
| 208 | + |
| 209 | + Diag_List diags_2 = std::move(diags_1); |
| 210 | + EXPECT_EQ(diags_2.size(), 1); |
| 211 | +} |
| 212 | + |
| 213 | +TEST(Test_Diag_List, moving_diag_list_keeps_multiple_diags) { |
| 214 | + Linked_Bump_Allocator memory("test"); |
| 215 | + Diag_List diags_1(&memory); |
| 216 | + Padded_String code(u8"hello"_sv); |
| 217 | + diags_1.add(Diag_Let_With_No_Bindings{.where = span_of(code)}); |
| 218 | + diags_1.add(Diag_Expected_Parenthesis_Around_If_Condition{ |
| 219 | + .where = span_of(code), |
| 220 | + .token = u8')', |
| 221 | + }); |
| 222 | + |
| 223 | + Diag_List diags_2 = std::move(diags_1); |
| 224 | + assert_diagnostics(&code, diags_2, |
| 225 | + {u8"Diag_Let_With_No_Bindings"_diag, |
| 226 | + u8"Diag_Expected_Parenthesis_Around_If_Condition"_diag}); |
| 227 | +} |
192 | 228 | }
|
193 | 229 | }
|
194 | 230 |
|
|
0 commit comments