@@ -190,7 +190,12 @@ constexpr const Char8 *nodejs_global_variables[] = {
190
190
u8" unescape" ,
191
191
};
192
192
193
- TEST (Test_Variable_Analyzer_Globals, global_variables_are_usable) {
193
+ class Test_Variable_Analyzer_Globals : public ::testing::Test {
194
+ protected:
195
+ Monotonic_Allocator memory_{" test" };
196
+ };
197
+
198
+ TEST_F (Test_Variable_Analyzer_Globals, global_variables_are_usable) {
194
199
// Array = null;
195
200
// Array;
196
201
for (const Char8 *global_variable : writable_global_variables) {
@@ -215,23 +220,22 @@ TEST(Test_Variable_Analyzer_Globals, global_variables_are_usable) {
215
220
}
216
221
}
217
222
218
- TEST (Test_Variable_Analyzer_Globals,
219
- immutable_global_variables_are_not_assignable) {
223
+ TEST_F (Test_Variable_Analyzer_Globals,
224
+ immutable_global_variables_are_not_assignable) {
220
225
for (const Char8 *global_variable : non_writable_global_variables) {
221
226
SCOPED_TRACE (out_string8 (global_variable));
222
227
223
228
// NaN = null; // ERROR
224
- Diag_Collector v ;
225
- Variable_Analyzer l (&v , &default_globals, javascript_var_options);
229
+ Diag_List_Diag_Reporter diags (& this -> memory_ ) ;
230
+ Variable_Analyzer l (&diags , &default_globals, javascript_var_options);
226
231
l.visit_variable_assignment (identifier_of (global_variable),
227
232
Variable_Assignment_Flags::none);
228
233
l.visit_end_of_module ();
229
234
230
- EXPECT_THAT (v.errors ,
231
- ElementsAreArray ({
232
- DIAG_TYPE_SPAN (Diag_Assignment_To_Const_Global_Variable,
233
- assignment, span_of (global_variable)),
234
- }));
235
+ auto *diag = get_only_diagnostic<Diag_Assignment_To_Const_Global_Variable>(
236
+ diags.diags (), Diag_Type::Diag_Assignment_To_Const_Global_Variable);
237
+ ASSERT_NE (diag, nullptr );
238
+ EXPECT_TRUE (same_pointers (diag->assignment , span_of (global_variable)));
235
239
}
236
240
237
241
for (const Char8 *global_variable : non_writable_global_variables) {
@@ -240,24 +244,23 @@ TEST(Test_Variable_Analyzer_Globals,
240
244
// (() => {
241
245
// NaN = null; // ERROR
242
246
// });
243
- Diag_Collector v ;
244
- Variable_Analyzer l (&v , &default_globals, javascript_var_options);
247
+ Diag_List_Diag_Reporter diags (& this -> memory_ ) ;
248
+ Variable_Analyzer l (&diags , &default_globals, javascript_var_options);
245
249
l.visit_enter_function_scope ();
246
250
l.visit_enter_function_scope_body ();
247
251
l.visit_variable_assignment (identifier_of (global_variable),
248
252
Variable_Assignment_Flags::none);
249
253
l.visit_exit_function_scope ();
250
254
l.visit_end_of_module ();
251
255
252
- EXPECT_THAT (v.errors ,
253
- ElementsAreArray ({
254
- DIAG_TYPE_SPAN (Diag_Assignment_To_Const_Global_Variable,
255
- assignment, span_of (global_variable)),
256
- }));
256
+ auto *diag = get_only_diagnostic<Diag_Assignment_To_Const_Global_Variable>(
257
+ diags.diags (), Diag_Type::Diag_Assignment_To_Const_Global_Variable);
258
+ ASSERT_NE (diag, nullptr );
259
+ EXPECT_TRUE (same_pointers (diag->assignment , span_of (global_variable)));
257
260
}
258
261
}
259
262
260
- TEST (Test_Variable_Analyzer_Globals, nodejs_global_variables_are_usable) {
263
+ TEST_F (Test_Variable_Analyzer_Globals, nodejs_global_variables_are_usable) {
261
264
for (const Char8 *global_variable : nodejs_global_variables) {
262
265
SCOPED_TRACE (out_string8 (global_variable));
263
266
Diag_Collector v;
@@ -268,8 +271,8 @@ TEST(Test_Variable_Analyzer_Globals, nodejs_global_variables_are_usable) {
268
271
}
269
272
}
270
273
271
- TEST (Test_Variable_Analyzer_Globals,
272
- non_module_nodejs_global_variables_are_shadowable) {
274
+ TEST_F (Test_Variable_Analyzer_Globals,
275
+ non_module_nodejs_global_variables_are_shadowable) {
273
276
for (Variable_Declaration_Flags flags :
274
277
{Variable_Declaration_Flags::none,
275
278
Variable_Declaration_Flags::initialized_with_equals}) {
@@ -286,41 +289,40 @@ TEST(Test_Variable_Analyzer_Globals,
286
289
}
287
290
}
288
291
289
- TEST (Test_Variable_Analyzer_Globals,
290
- type_only_global_variables_are_not_usable_in_expressions) {
292
+ TEST_F (Test_Variable_Analyzer_Globals,
293
+ type_only_global_variables_are_not_usable_in_expressions) {
291
294
for (const Char8 *global_variable : type_only_global_variables) {
292
295
SCOPED_TRACE (out_string8 (global_variable));
293
296
294
297
// Awaited;
295
298
{
296
- Diag_Collector v ;
297
- Variable_Analyzer l (&v , &default_globals, typescript_var_options);
299
+ Diag_List_Diag_Reporter diags (& this -> memory_ ) ;
300
+ Variable_Analyzer l (&diags , &default_globals, typescript_var_options);
298
301
l.visit_variable_use (identifier_of (global_variable));
299
302
l.visit_end_of_module ();
300
- EXPECT_THAT (v. errors , ElementsAreArray ({
301
- DIAG_TYPE_SPAN (Diag_Use_Of_Undeclared_Variable,
302
- name, span_of (global_variable)),
303
- } ));
303
+ auto *diag = get_only_diagnostic<Diag_Use_Of_Undeclared_Variable>(
304
+ diags. diags (), Diag_Type::Diag_Use_Of_Undeclared_Variable);
305
+ ASSERT_NE (diag, nullptr );
306
+ EXPECT_TRUE ( same_pointers (diag-> name , span_of (global_variable) ));
304
307
}
305
308
306
309
// Awaited = null;
307
310
{
308
- Diag_Collector v ;
309
- Variable_Analyzer l (&v , &default_globals, typescript_var_options);
311
+ Diag_List_Diag_Reporter diags (& this -> memory_ ) ;
312
+ Variable_Analyzer l (&diags , &default_globals, typescript_var_options);
310
313
l.visit_variable_assignment (identifier_of (global_variable),
311
314
Variable_Assignment_Flags::none);
312
315
l.visit_end_of_module ();
313
- EXPECT_THAT (v.errors ,
314
- ElementsAreArray ({
315
- DIAG_TYPE_SPAN (Diag_Assignment_To_Undeclared_Variable,
316
- assignment, span_of (global_variable)),
317
- }));
316
+ auto *diag = get_only_diagnostic<Diag_Assignment_To_Undeclared_Variable>(
317
+ diags.diags (), Diag_Type::Diag_Assignment_To_Undeclared_Variable);
318
+ ASSERT_NE (diag, nullptr );
319
+ EXPECT_TRUE (same_pointers (diag->assignment , span_of (global_variable)));
318
320
}
319
321
}
320
322
}
321
323
322
- TEST (Test_Variable_Analyzer_Globals,
323
- type_only_global_variables_are_usable_in_types) {
324
+ TEST_F (Test_Variable_Analyzer_Globals,
325
+ type_only_global_variables_are_usable_in_types) {
324
326
// null as Awaited;
325
327
for (const Char8 *global_variable : type_only_global_variables) {
326
328
SCOPED_TRACE (out_string8 (global_variable));
@@ -332,8 +334,8 @@ TEST(Test_Variable_Analyzer_Globals,
332
334
}
333
335
}
334
336
335
- TEST (Test_Variable_Analyzer_Globals,
336
- any_variable_is_declarable_and_usable_if_opted_into) {
337
+ TEST_F (Test_Variable_Analyzer_Globals,
338
+ any_variable_is_declarable_and_usable_if_opted_into) {
337
339
// This tests the "literally-anything" global group.
338
340
339
341
Global_Declared_Variable_Set globals;
0 commit comments