@@ -39,24 +39,6 @@ struct Counter
39
39
40
40
int Counter::instanceCount = 0 ;
41
41
42
- // TODO: delete this and replace all other use of this function with matchParseError
43
- std::string getParseError (const std::string& code)
44
- {
45
- Fixture f;
46
-
47
- try
48
- {
49
- f.parse (code);
50
- }
51
- catch (const Luau::ParseErrors& e)
52
- {
53
- // in general, tests check only the first error
54
- return e.getErrors ().front ().getMessage ();
55
- }
56
-
57
- throw std::runtime_error (" Expected a parse error in '" + code + " '" );
58
- }
59
-
60
42
} // namespace
61
43
62
44
TEST_SUITE_BEGIN (" AllocatorTests" );
@@ -465,62 +447,38 @@ TEST_CASE_FIXTURE(Fixture, "type_alias_span_is_correct")
465
447
466
448
TEST_CASE_FIXTURE (Fixture, " parse_error_messages" )
467
449
{
468
- CHECK_EQ (
469
- getParseError (R"(
470
- local a: (number, number) -> (string
471
- )" ),
472
- " Expected ')' (to close '(' at line 2), got <eof>"
473
- );
450
+ matchParseError (R"(
451
+ local a: (number, number) -> (string
452
+ )" , " Expected ')' (to close '(' at line 2), got <eof>" );
474
453
475
- CHECK_EQ (
476
- getParseError (R"(
477
- local a: (number, number) -> (
478
- string
479
- )" ),
480
- " Expected ')' (to close '(' at line 2), got <eof>"
481
- );
454
+ matchParseError (R"(
455
+ local a: (number, number) -> (
456
+ string
457
+ )" , " Expected ')' (to close '(' at line 2), got <eof>" );
482
458
483
- CHECK_EQ (
484
- getParseError (R"(
485
- local a: (number, number)
486
- )" ),
487
- " Expected '->' when parsing function type, got <eof>"
488
- );
459
+ matchParseError (R"(
460
+ local a: (number, number)
461
+ )" , " Expected '->' when parsing function type, got <eof>" );
489
462
490
- CHECK_EQ (
491
- getParseError (R"(
492
- local a: (number, number
493
- )" ),
494
- " Expected ')' (to close '(' at line 2), got <eof>"
495
- );
463
+ matchParseError (R"(
464
+ local a: (number, number
465
+ )" , " Expected ')' (to close '(' at line 2), got <eof>" );
496
466
497
- CHECK_EQ (
498
- getParseError (R"(
499
- local a: {foo: string,
500
- )" ),
501
- " Expected identifier when parsing table field, got <eof>"
502
- );
467
+ matchParseError (R"(
468
+ local a: {foo: string,
469
+ )" , " Expected identifier when parsing table field, got <eof>" );
503
470
504
- CHECK_EQ (
505
- getParseError (R"(
506
- local a: {foo: string
507
- )" ),
508
- " Expected '}' (to close '{' at line 2), got <eof>"
509
- );
471
+ matchParseError (R"(
472
+ local a: {foo: string
473
+ )" , " Expected '}' (to close '{' at line 2), got <eof>" );
510
474
511
- CHECK_EQ (
512
- getParseError (R"(
513
- local a: { [string]: number, [number]: string }
514
- )" ),
515
- " Cannot have more than one table indexer"
516
- );
475
+ matchParseError (R"(
476
+ local a: { [string]: number, [number]: string }
477
+ )" , " Cannot have more than one table indexer" );
517
478
518
- CHECK_EQ (
519
- getParseError (R"(
520
- type T = <a>foo
521
- )" ),
522
- " Expected '(' when parsing function parameters, got 'foo'"
523
- );
479
+ matchParseError (R"(
480
+ type T = <a>foo
481
+ )" , " Expected '(' when parsing function parameters, got 'foo'" );
524
482
}
525
483
526
484
TEST_CASE_FIXTURE (Fixture, " mixed_intersection_and_union_not_allowed" )
@@ -548,10 +506,10 @@ TEST_CASE_FIXTURE(Fixture, "cannot_write_multiple_values_in_type_groups")
548
506
549
507
TEST_CASE_FIXTURE (Fixture, " type_alias_error_messages" )
550
508
{
551
- CHECK_EQ ( getParseError ( " type 5 = number" ) , " Expected identifier when parsing type name, got '5'" );
552
- CHECK_EQ ( getParseError ( " type A" ) , " Expected '=' when parsing type alias, got <eof>" );
553
- CHECK_EQ ( getParseError ( " type A<" ) , " Expected identifier, got <eof>" );
554
- CHECK_EQ ( getParseError ( " type A<B" ) , " Expected '>' (to close '<' at column 7), got <eof>" );
509
+ matchParseError ( " type 5 = number" , " Expected identifier when parsing type name, got '5'" );
510
+ matchParseError ( " type A" , " Expected '=' when parsing type alias, got <eof>" );
511
+ matchParseError ( " type A<" , " Expected identifier, got <eof>" );
512
+ matchParseError ( " type A<B" , " Expected '>' (to close '<' at column 7), got <eof>" );
555
513
}
556
514
557
515
TEST_CASE_FIXTURE (Fixture, " type_assertion_expression" )
@@ -655,12 +613,9 @@ TEST_CASE_FIXTURE(Fixture, "vertical_space")
655
613
656
614
TEST_CASE_FIXTURE (Fixture, " parse_error_type_name" )
657
615
{
658
- CHECK_EQ (
659
- getParseError (R"(
660
- local a: Foo.=
661
- )" ),
662
- " Expected identifier when parsing field name, got '='"
663
- );
616
+ matchParseError (R"(
617
+ local a: Foo.=
618
+ )" , " Expected identifier when parsing field name, got '='" );
664
619
}
665
620
666
621
TEST_CASE_FIXTURE (Fixture, " parse_numbers_decimal" )
@@ -706,28 +661,25 @@ TEST_CASE_FIXTURE(Fixture, "parse_numbers_binary")
706
661
707
662
TEST_CASE_FIXTURE (Fixture, " parse_numbers_error" )
708
663
{
709
- CHECK_EQ ( getParseError ( " return 0b123" ) , " Malformed number" );
710
- CHECK_EQ ( getParseError ( " return 123x" ) , " Malformed number" );
711
- CHECK_EQ ( getParseError ( " return 0xg" ) , " Malformed number" );
712
- CHECK_EQ ( getParseError ( " return 0x0x123" ) , " Malformed number" );
713
- CHECK_EQ ( getParseError ( " return 0xffffffffffffffffffffllllllg" ) , " Malformed number" );
714
- CHECK_EQ ( getParseError ( " return 0x0xffffffffffffffffffffffffffff" ) , " Malformed number" );
664
+ matchParseError ( " return 0b123" , " Malformed number" );
665
+ matchParseError ( " return 123x" , " Malformed number" );
666
+ matchParseError ( " return 0xg" , " Malformed number" );
667
+ matchParseError ( " return 0x0x123" , " Malformed number" );
668
+ matchParseError ( " return 0xffffffffffffffffffffllllllg" , " Malformed number" );
669
+ matchParseError ( " return 0x0xffffffffffffffffffffffffffff" , " Malformed number" );
715
670
}
716
671
717
672
TEST_CASE_FIXTURE (Fixture, " break_return_not_last_error" )
718
673
{
719
- CHECK_EQ ( getParseError ( " return 0 print(5)" ) , " Expected <eof>, got 'print'" );
720
- CHECK_EQ ( getParseError ( " while true do break print(5) end" ) , " Expected 'end' (to close 'do' at column 12), got 'print'" );
674
+ matchParseError ( " return 0 print(5)" , " Expected <eof>, got 'print'" );
675
+ matchParseError ( " while true do break print(5) end" , " Expected 'end' (to close 'do' at column 12), got 'print'" );
721
676
}
722
677
723
678
TEST_CASE_FIXTURE (Fixture, " error_on_unicode" )
724
679
{
725
- CHECK_EQ (
726
- getParseError (R"(
680
+ matchParseError (R"(
727
681
local ☃ = 10
728
- )" ),
729
- " Expected identifier when parsing variable name, got Unicode character U+2603"
730
- );
682
+ )" , " Expected identifier when parsing variable name, got Unicode character U+2603" );
731
683
}
732
684
733
685
TEST_CASE_FIXTURE (Fixture, " allow_unicode_in_string" )
@@ -738,20 +690,17 @@ TEST_CASE_FIXTURE(Fixture, "allow_unicode_in_string")
738
690
739
691
TEST_CASE_FIXTURE (Fixture, " error_on_confusable" )
740
692
{
741
- CHECK_EQ (
742
- getParseError (R"(
743
- local pi = 3․13
744
- )" ),
745
- " Expected identifier when parsing expression, got Unicode character U+2024 (did you mean '.'?)"
746
- );
693
+ matchParseError (R"(
694
+ local pi = 3․13
695
+ )" , " Expected identifier when parsing expression, got Unicode character U+2024 (did you mean '.'?)" );
747
696
}
748
697
749
698
TEST_CASE_FIXTURE (Fixture, " error_on_non_utf8_sequence" )
750
699
{
751
700
const char * expected = " Expected identifier when parsing expression, got invalid UTF-8 sequence" ;
752
701
753
- CHECK_EQ ( getParseError ( " local pi = \xFF !" ) , expected);
754
- CHECK_EQ ( getParseError ( " local pi = \xE2 !" ) , expected);
702
+ matchParseError ( " local pi = \xFF !" , expected);
703
+ matchParseError ( " local pi = \xE2 !" , expected);
755
704
}
756
705
757
706
TEST_CASE_FIXTURE (Fixture, " lex_broken_unicode" )
@@ -819,7 +768,7 @@ TEST_CASE_FIXTURE(Fixture, "parse_continue")
819
768
820
769
TEST_CASE_FIXTURE (Fixture, " continue_not_last_error" )
821
770
{
822
- CHECK_EQ ( getParseError ( " while true do continue print(5) end" ) , " Expected 'end' (to close 'do' at column 12), got 'print'" );
771
+ matchParseError ( " while true do continue print(5) end" , " Expected 'end' (to close 'do' at column 12), got 'print'" );
823
772
}
824
773
825
774
TEST_CASE_FIXTURE (Fixture, " parse_export_type" )
@@ -862,7 +811,7 @@ TEST_CASE_FIXTURE(Fixture, "export_is_an_identifier_only_when_followed_by_type")
862
811
863
812
TEST_CASE_FIXTURE (Fixture, " incomplete_statement_error" )
864
813
{
865
- CHECK_EQ ( getParseError ( " fiddlesticks" ) , " Incomplete statement: expected assignment or a function call" );
814
+ matchParseError ( " fiddlesticks" , " Incomplete statement: expected assignment or a function call" );
866
815
}
867
816
868
817
TEST_CASE_FIXTURE (Fixture, " parse_compound_assignment" )
0 commit comments