@@ -29,16 +29,25 @@ using ::testing::UnorderedElementsAreArray;
29
29
30
30
namespace quick_lint_js {
31
31
namespace {
32
- class Test_Parse : public Test_Parse_Expression {};
32
+ class Test_Parse : public Test_Parse_Expression {
33
+ public:
34
+ Monotonic_Allocator memory_{" test" };
35
+ };
33
36
34
37
// TODO(strager): Put Test_Escape_First_Character_In_Keyword tests into their
35
38
// own test file.
36
39
class Test_Escape_First_Character_In_Keyword : public ::testing::Test {};
37
40
38
41
// TODO(strager): Put Test_No_Overflow and test_overflow tests into their own
39
42
// test file.
40
- class Test_No_Overflow : public Test_Parse_Expression {};
41
- class Test_Overflow : public Test_Parse_Expression {};
43
+ class Test_No_Overflow : public Test_Parse_Expression {
44
+ public:
45
+ Monotonic_Allocator memory_{" test" };
46
+ };
47
+ class Test_Overflow : public Test_Parse_Expression {
48
+ public:
49
+ Monotonic_Allocator memory_{" test" };
50
+ };
42
51
43
52
TEST_F (Test_Parse, statement_starting_with_invalid_token) {
44
53
for (String8_View token : {
@@ -562,9 +571,10 @@ Padded_String unimplemented_token_code(u8"]"_sv);
562
571
563
572
#if defined(GTEST_HAS_DEATH_TEST) && GTEST_HAS_DEATH_TEST
564
573
TEST_F (Test_Parse, unimplemented_token_crashes_SLOW) {
565
- auto check = [] {
574
+ auto check = [&] {
575
+ Diag_List_Diag_Reporter diags (&this ->memory_ );
576
+ Parser p (&unimplemented_token_code, &diags, javascript_options);
566
577
Spy_Visitor v;
567
- Parser p (&unimplemented_token_code, &v, javascript_options);
568
578
p.parse_and_visit_module (v);
569
579
};
570
580
EXPECT_DEATH (check (), " token not implemented" );
@@ -573,24 +583,25 @@ TEST_F(Test_Parse, unimplemented_token_crashes_SLOW) {
573
583
574
584
TEST_F (Test_Parse, unimplemented_token_doesnt_crash_if_caught) {
575
585
{
586
+ Diag_Collector diags;
587
+ Parser p (&unimplemented_token_code, &diags, javascript_options);
576
588
Spy_Visitor v;
577
- Parser p (&unimplemented_token_code, &v, javascript_options);
578
589
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors (v);
579
590
EXPECT_FALSE (ok);
580
591
EXPECT_THAT (v.visits , IsEmpty ());
581
- EXPECT_THAT (v .errors , ElementsAreArray ({
582
- DIAG_TYPE_OFFSETS (&unimplemented_token_code,
583
- Diag_Unexpected_Token, //
584
- token, 0 , u8" ]" _sv),
585
- }));
592
+ EXPECT_THAT (diags .errors , ElementsAreArray ({
593
+ DIAG_TYPE_OFFSETS (&unimplemented_token_code,
594
+ Diag_Unexpected_Token, //
595
+ token, 0 , u8" ]" _sv),
596
+ }));
586
597
}
587
598
}
588
599
589
600
TEST_F (Test_Parse, unimplemented_token_returns_to_innermost_handler) {
590
601
{
591
602
Padded_String code (u8" hello world" _sv);
592
- Spy_Visitor v ;
593
- Parser p (&code, &v , javascript_options);
603
+ Diag_List_Diag_Reporter diags (& this -> memory_ ) ;
604
+ Parser p (&code, &diags , javascript_options);
594
605
volatile bool inner_catch_returned = false ;
595
606
bool outer_ok = p.catch_fatal_parse_errors ([&] {
596
607
bool inner_ok = p.catch_fatal_parse_errors (
@@ -600,7 +611,7 @@ TEST_F(Test_Parse, unimplemented_token_returns_to_innermost_handler) {
600
611
});
601
612
EXPECT_TRUE (outer_ok);
602
613
EXPECT_TRUE (inner_catch_returned);
603
- assert_diagnostics (&code, v. errors ,
614
+ assert_diagnostics (&code, diags. diags () ,
604
615
{
605
616
u8" Diag_Unexpected_Token" _diag,
606
617
});
@@ -611,8 +622,8 @@ TEST_F(Test_Parse,
611
622
unimplemented_token_after_handler_ends_returns_to_outer_handler) {
612
623
{
613
624
Padded_String code (u8" hello world" _sv);
614
- Spy_Visitor v ;
615
- Parser p (&code, &v , javascript_options);
625
+ Diag_List_Diag_Reporter diags (& this -> memory_ ) ;
626
+ Parser p (&code, &diags , javascript_options);
616
627
volatile bool inner_catch_returned = false ;
617
628
bool outer_ok = p.catch_fatal_parse_errors ([&] {
618
629
bool inner_ok = p.catch_fatal_parse_errors ([] {
@@ -624,7 +635,7 @@ TEST_F(Test_Parse,
624
635
});
625
636
EXPECT_FALSE (outer_ok);
626
637
EXPECT_TRUE (inner_catch_returned);
627
- assert_diagnostics (&code, v. errors ,
638
+ assert_diagnostics (&code, diags. diags () ,
628
639
{
629
640
u8" Diag_Unexpected_Token" _diag,
630
641
});
@@ -634,8 +645,7 @@ TEST_F(Test_Parse,
634
645
TEST_F (Test_Parse, unimplemented_token_rolls_back_parser_depth) {
635
646
{
636
647
Padded_String code (u8" hello world" _sv);
637
- Spy_Visitor v;
638
- Parser p (&code, &v, javascript_options);
648
+ Parser p (&code, &Null_Diag_Reporter::instance, javascript_options);
639
649
volatile bool inner_catch_returned = false ;
640
650
bool outer_ok = p.catch_fatal_parse_errors ([&] {
641
651
Parser::Depth_Guard outer_g (&p);
@@ -657,19 +667,21 @@ TEST_F(Test_Parse, unimplemented_token_rolls_back_parser_depth) {
657
667
TEST_F (Test_Parse, unimplemented_token_is_reported_on_outer_diag_reporter) {
658
668
{
659
669
Padded_String code (u8" hello world" _sv);
660
- Spy_Visitor v ;
661
- Parser p (&code, &v , javascript_options);
670
+ Diag_List_Diag_Reporter diags (& this -> memory_ ) ;
671
+ Parser p (&code, &diags , javascript_options);
662
672
663
673
Parser_Transaction transaction = p.begin_transaction ();
664
674
bool ok = p.catch_fatal_parse_errors (
665
675
[&] { QLJS_PARSER_UNIMPLEMENTED_WITH_PARSER (&p); });
666
676
EXPECT_FALSE (ok);
667
677
668
- EXPECT_THAT (v.errors , IsEmpty ())
669
- << " Diag_Unexpected_Token should be buffered in the transaction" ;
678
+ assert_diagnostics (&code, diags.diags (), {});
679
+ // Diag_Unexpected_Token should be buffered in the transaction.
680
+ // FIXME(#1154): Instead of buffering, use a rewind mechanism. (No rewinding
681
+ // should happen in this test.)
670
682
p.commit_transaction (std::move (transaction));
671
683
// Diag_Unexpected_Token should be reported when committing the transaction.
672
- assert_diagnostics (&code, v. errors ,
684
+ assert_diagnostics (&code, diags. diags () ,
673
685
{
674
686
u8" Diag_Unexpected_Token" _diag,
675
687
});
@@ -769,23 +781,25 @@ TEST_F(Test_No_Overflow, parser_depth_limit_not_exceeded) {
769
781
}) {
770
782
Padded_String code (u8" return " + jsx);
771
783
SCOPED_TRACE (code);
784
+ Diag_List_Diag_Reporter diags (&this ->memory_ );
785
+ Parser p (&code, &diags, jsx_options);
772
786
Spy_Visitor v;
773
- Parser p (&code, &v, jsx_options);
774
787
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors (v);
775
788
EXPECT_TRUE (ok);
776
- EXPECT_THAT (v. errors , IsEmpty () );
789
+ assert_diagnostics (&code, diags. diags (), {} );
777
790
}
778
791
779
792
for (const String8& type : {
780
793
repeated_str (u8" (" _sv, u8" T" _sv, u8" )" _sv, Parser::stack_limit - 2 ),
781
794
}) {
782
795
Padded_String code (concat (u8" let x: " _sv, type, u8" ;" _sv));
783
796
SCOPED_TRACE (code);
797
+ Diag_List_Diag_Reporter diags (&this ->memory_ );
798
+ Parser p (&code, &diags, typescript_options);
784
799
Spy_Visitor v;
785
- Parser p (&code, &v, typescript_options);
786
800
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors (v);
787
801
EXPECT_TRUE (ok);
788
- EXPECT_THAT (v. errors , IsEmpty () );
802
+ assert_diagnostics (&code, diags. diags (), {} );
789
803
}
790
804
}
791
805
@@ -836,11 +850,12 @@ TEST_F(Test_Overflow, parser_depth_limit_exceeded) {
836
850
}) {
837
851
Padded_String code (exps);
838
852
SCOPED_TRACE (code);
853
+ Diag_List_Diag_Reporter diags (&this ->memory_ );
854
+ Parser p (&code, &diags, javascript_options);
839
855
Spy_Visitor v;
840
- Parser p (&code, &v, javascript_options);
841
856
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors (v);
842
857
EXPECT_FALSE (ok);
843
- assert_diagnostics (&code, v. errors ,
858
+ assert_diagnostics (&code, diags. diags () ,
844
859
{
845
860
u8" Diag_Depth_Limit_Exceeded" _diag,
846
861
});
@@ -884,11 +899,12 @@ TEST_F(Test_Overflow, parser_depth_limit_exceeded) {
884
899
}) {
885
900
Padded_String code (concat (u8" return " _sv, jsx));
886
901
SCOPED_TRACE (code);
902
+ Diag_List_Diag_Reporter diags (&this ->memory_ );
903
+ Parser p (&code, &diags, jsx_options);
887
904
Spy_Visitor v;
888
- Parser p (&code, &v, jsx_options);
889
905
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors (v);
890
906
EXPECT_FALSE (ok);
891
- assert_diagnostics (&code, v. errors ,
907
+ assert_diagnostics (&code, diags. diags () ,
892
908
{
893
909
u8" Diag_Depth_Limit_Exceeded" _diag,
894
910
});
@@ -899,11 +915,12 @@ TEST_F(Test_Overflow, parser_depth_limit_exceeded) {
899
915
}) {
900
916
Padded_String code (concat (u8" let x: " _sv, type, u8" ;" _sv));
901
917
SCOPED_TRACE (code);
918
+ Diag_List_Diag_Reporter diags (&this ->memory_ );
919
+ Parser p (&code, &diags, typescript_options);
902
920
Spy_Visitor v;
903
- Parser p (&code, &v, typescript_options);
904
921
bool ok = p.parse_and_visit_module_catching_fatal_parse_errors (v);
905
922
EXPECT_FALSE (ok);
906
- assert_diagnostics (&code, v. errors ,
923
+ assert_diagnostics (&code, diags. diags () ,
907
924
{
908
925
u8" Diag_Depth_Limit_Exceeded" _diag,
909
926
});
0 commit comments