9
9
#include < iostream>
10
10
#include < quick-lint-js/assert.h>
11
11
#include < quick-lint-js/characters.h>
12
+ #include < quick-lint-js/container/concat.h>
12
13
#include < quick-lint-js/container/linked-vector.h>
13
14
#include < quick-lint-js/container/padded-string.h>
14
15
#include < quick-lint-js/diag-collector.h>
@@ -248,7 +249,7 @@ TEST_F(test_lex, lex_line_comments) {
248
249
EXPECT_THAT (this ->lex_to_eof (u8" // hello" _sv), IsEmpty ());
249
250
for (string8_view line_terminator : line_terminators) {
250
251
this ->check_single_token (
251
- u8" // hello" + string8 ( line_terminator) + u8" world" , u8" world" _sv);
252
+ concat ( u8" // hello" _sv, line_terminator, u8" world" _sv) , u8" world" _sv);
252
253
}
253
254
EXPECT_THAT (this ->lex_to_eof (u8" // hello\n // world" _sv), IsEmpty ());
254
255
this ->check_tokens (u8" hello//*/\n \n \n world" _sv,
@@ -267,8 +268,8 @@ TEST_F(test_lex, lex_line_comments) {
267
268
TEST_F (test_lex, lex_line_comments_with_control_characters) {
268
269
for (string8_view control_character :
269
270
control_characters_except_line_terminators) {
270
- padded_string input (u8" // hello " + string8 (control_character) +
271
- u8" world\n 42.0" );
271
+ padded_string input (
272
+ concat ( u8" // hello " _sv, control_character, u8" world\n 42.0" _sv) );
272
273
SCOPED_TRACE (input);
273
274
this ->check_tokens (&input, {token_type::number});
274
275
}
@@ -278,16 +279,16 @@ TEST_F(test_lex, lex_html_open_comments) {
278
279
EXPECT_THAT (this ->lex_to_eof (u8" <!-- --> hello" _sv), IsEmpty ());
279
280
for (string8_view line_terminator : line_terminators) {
280
281
this ->check_single_token (
281
- u8" <!-- hello" + string8 ( line_terminator) + u8" world" , u8" world" _sv);
282
+ concat ( u8" <!-- hello" _sv, line_terminator, u8" world" _sv) , u8" world" _sv);
282
283
}
283
284
EXPECT_THAT (this ->lex_to_eof (u8" <!-- hello\n <!-- world" _sv), IsEmpty ());
284
285
EXPECT_THAT (this ->lex_to_eof (u8" <!--// hello" _sv), IsEmpty ());
285
286
this ->check_tokens (u8" hello<!--->\n \n \n world" _sv,
286
287
{token_type::identifier, token_type::identifier});
287
288
for (string8_view control_character :
288
289
control_characters_except_line_terminators) {
289
- padded_string input (u8" <!-- hello " + string8 (control_character) +
290
- u8" world\n 42.0" );
290
+ padded_string input (
291
+ concat ( u8" <!-- hello " _sv, control_character, u8" world\n 42.0" _sv) );
291
292
SCOPED_TRACE (input);
292
293
this ->check_tokens (&input, {token_type::number});
293
294
}
@@ -310,19 +311,22 @@ TEST_F(test_lex, lex_html_close_comments) {
310
311
for (string8_view line_terminator : line_terminators) {
311
312
string8 eol (line_terminator);
312
313
313
- this ->check_single_token (u8" -->" + eol + u8" hello" , u8" hello" _sv);
314
- this ->check_single_token (u8" --> comment" + eol + u8" hello" , u8" hello" _sv);
314
+ this ->check_single_token (concat (u8" -->" _sv, eol, u8" hello" _sv),
315
+ u8" hello" _sv);
316
+ this ->check_single_token (concat (u8" --> comment" _sv, eol, u8" hello" _sv),
317
+ u8" hello" _sv);
318
+ this ->check_single_token (concat (u8" --> comment1" _sv, eol,
319
+ u8" --> comment2" _sv, eol, u8" hello" _sv),
320
+ u8" hello" _sv);
321
+
315
322
this ->check_single_token (
316
- u8" --> comment1 " + eol + u8" --> comment2 " + eol + u8" hello" ,
323
+ concat ( u8" /* " _sv, eol, u8" */ --> comment " _sv, eol, u8" hello" _sv) ,
317
324
u8" hello" _sv);
318
-
319
- this ->check_single_token (u8" /*" + eol + u8" */--> comment" + eol + u8" hello" ,
320
- u8" hello" _sv);
321
325
this ->check_single_token (
322
- u8" /* */ /*" + eol + u8" */ --> comment" + eol + u8" hello" ,
326
+ concat ( u8" /* */ /*" _sv, eol, u8" */ --> comment" _sv, eol, u8" hello" _sv) ,
323
327
u8" hello" _sv);
324
328
this ->check_single_token (
325
- u8" /*" + eol + u8" */ /* */ --> comment" + eol + u8" hello" ,
329
+ concat ( u8" /*" _sv, eol, u8" */ /* */ --> comment" _sv, eol, u8" hello" _sv) ,
326
330
u8" hello" _sv);
327
331
}
328
332
@@ -1036,18 +1040,18 @@ TEST_F(test_lex, lex_strings) {
1036
1040
});
1037
1041
1038
1042
for (string8_view line_terminator : line_terminators) {
1039
- for (const char8* quotation_mark : {u8" '" , u8" \" " }) {
1040
- padded_string input (quotation_mark +
1041
- ( u8" line1 \\ " + string8 (line_terminator) + u8" line2" ) +
1042
- quotation_mark);
1043
+ for (string8_view quotation_mark : {u8" '" _sv , u8" \" " _sv }) {
1044
+ padded_string input (concat ( quotation_mark, u8" line1 \\ " _sv,
1045
+ line_terminator, u8" line2" _sv,
1046
+ quotation_mark) );
1043
1047
this ->check_tokens (&input, {token_type::string});
1044
1048
}
1045
1049
}
1046
1050
1047
1051
for (string8_view line_terminator : line_terminators_except_ls_ps) {
1048
1052
diag_collector v;
1049
- padded_string input (u8" 'unterminated " + string8 (line_terminator) +
1050
- u8" hello" );
1053
+ padded_string input (
1054
+ concat ( u8" 'unterminated " _sv, line_terminator, u8" hello" _sv) );
1051
1055
lexer l (&input, &v);
1052
1056
EXPECT_EQ (l.peek ().type , token_type::string);
1053
1057
l.skip ();
@@ -1063,7 +1067,8 @@ TEST_F(test_lex, lex_strings) {
1063
1067
1064
1068
for (string8_view line_terminator : line_terminators_except_ls_ps) {
1065
1069
diag_collector v;
1066
- padded_string input (u8" 'separated" + string8 (line_terminator) + u8" hello'" );
1070
+ padded_string input (
1071
+ concat (u8" 'separated" _sv, line_terminator, u8" hello'" _sv));
1067
1072
lexer l (&input, &v);
1068
1073
EXPECT_EQ (l.peek ().type , token_type::string);
1069
1074
l.skip ();
@@ -1079,8 +1084,8 @@ TEST_F(test_lex, lex_strings) {
1079
1084
1080
1085
for (string8_view line_terminator : line_terminators_except_ls_ps) {
1081
1086
diag_collector v;
1082
- padded_string input (u8" 'separated" + string8 ( line_terminator) +
1083
- string8 (line_terminator) + u8" hello'" );
1087
+ padded_string input (concat ( u8" 'separated" _sv, line_terminator,
1088
+ line_terminator, u8" hello'" _sv) );
1084
1089
lexer l (&input, &v);
1085
1090
EXPECT_EQ (l.peek ().type , token_type::string);
1086
1091
l.skip ();
@@ -1104,8 +1109,8 @@ TEST_F(test_lex, lex_strings) {
1104
1109
1105
1110
for (string8_view line_terminator : line_terminators_except_ls_ps) {
1106
1111
diag_collector v;
1107
- padded_string input (u8" let x = 'hello " + string8 (line_terminator) +
1108
- u8" let y = 'world'" );
1112
+ padded_string input (
1113
+ concat ( u8" let x = 'hello " _sv, line_terminator, u8" let y = 'world'" _sv) );
1109
1114
lexer l (&input, &v);
1110
1115
EXPECT_EQ (l.peek ().type , token_type::kw_let);
1111
1116
l.skip ();
@@ -1240,14 +1245,16 @@ TEST_F(test_lex, lex_strings) {
1240
1245
TEST_F (test_lex, lex_string_with_ascii_control_characters) {
1241
1246
for (string8_view control_character :
1242
1247
concat (control_characters_except_line_terminators, ls_and_ps)) {
1243
- padded_string input (u8" 'hello" + string8 (control_character) + u8" world'" );
1248
+ padded_string input (
1249
+ concat (u8" 'hello" _sv, control_character, u8" world'" _sv));
1244
1250
SCOPED_TRACE (input);
1245
1251
this ->check_tokens (&input, {token_type::string});
1246
1252
}
1247
1253
1248
1254
for (string8_view control_character :
1249
1255
control_characters_except_line_terminators) {
1250
- padded_string input (u8" 'hello\\ " + string8 (control_character) + u8" world'" );
1256
+ padded_string input (
1257
+ concat (u8" 'hello\\ " _sv, control_character, u8" world'" _sv));
1251
1258
SCOPED_TRACE (input);
1252
1259
this ->check_tokens (&input, {token_type::string});
1253
1260
}
@@ -1598,14 +1605,16 @@ TEST_F(test_lex, templates_do_not_buffer_valid_unicode_escapes) {
1598
1605
TEST_F (test_lex, lex_template_literal_with_ascii_control_characters) {
1599
1606
for (string8_view control_character :
1600
1607
concat (control_characters_except_line_terminators, line_terminators)) {
1601
- padded_string input (u8" `hello" + string8 (control_character) + u8" world`" );
1608
+ padded_string input (
1609
+ concat (u8" `hello" _sv, control_character, u8" world`" _sv));
1602
1610
SCOPED_TRACE (input);
1603
1611
this ->check_tokens (&input, {token_type::complete_template});
1604
1612
}
1605
1613
1606
1614
for (string8_view control_character :
1607
1615
control_characters_except_line_terminators) {
1608
- padded_string input (u8" `hello\\ " + string8 (control_character) + u8" world`" );
1616
+ padded_string input (
1617
+ concat (u8" `hello\\ " _sv, control_character, u8" world`" _sv));
1609
1618
SCOPED_TRACE (input);
1610
1619
this ->check_tokens (&input, {token_type::complete_template});
1611
1620
}
@@ -1660,8 +1669,8 @@ TEST_F(test_lex, lex_regular_expression_literals) {
1660
1669
}
1661
1670
1662
1671
for (string8_view line_terminator : line_terminators) {
1663
- padded_string code (u8" /first_line " + string8 (line_terminator) +
1664
- u8" second_line/" );
1672
+ padded_string code (
1673
+ concat ( u8" /first_line " _sv, line_terminator, u8" second_line/" _sv) );
1665
1674
SCOPED_TRACE (code);
1666
1675
diag_collector v;
1667
1676
lexer l (&code, &v);
@@ -1683,8 +1692,8 @@ TEST_F(test_lex, lex_regular_expression_literals) {
1683
1692
}
1684
1693
1685
1694
for (string8_view line_terminator : line_terminators) {
1686
- padded_string code (u8" /first[line " + string8 (line_terminator) +
1687
- u8" second]line/" );
1695
+ padded_string code (
1696
+ concat ( u8" /first[line " _sv, line_terminator, u8" second]line/" _sv) );
1688
1697
SCOPED_TRACE (code);
1689
1698
diag_collector v;
1690
1699
lexer l (&code, &v);
@@ -1781,7 +1790,8 @@ TEST_F(test_lex,
1781
1790
TEST_F (test_lex, lex_regular_expression_literal_with_ascii_control_characters) {
1782
1791
for (string8_view control_character :
1783
1792
control_characters_except_line_terminators) {
1784
- padded_string input (u8" /hello" + string8 (control_character) + u8" world/" );
1793
+ padded_string input (
1794
+ concat (u8" /hello" _sv, control_character, u8" world/" _sv));
1785
1795
SCOPED_TRACE (input);
1786
1796
diag_collector errors;
1787
1797
lexer l (&input, &errors);
@@ -1796,7 +1806,8 @@ TEST_F(test_lex, lex_regular_expression_literal_with_ascii_control_characters) {
1796
1806
1797
1807
for (string8_view control_character :
1798
1808
control_characters_except_line_terminators) {
1799
- padded_string input (u8" /hello\\ " + string8 (control_character) + u8" world/" );
1809
+ padded_string input (
1810
+ concat (u8" /hello\\ " _sv, control_character, u8" world/" _sv));
1800
1811
SCOPED_TRACE (input);
1801
1812
diag_collector errors;
1802
1813
lexer l (&input, &errors);
@@ -2830,7 +2841,7 @@ TEST_F(test_lex, ascii_control_characters_are_disallowed) {
2830
2841
2831
2842
TEST_F (test_lex, ascii_control_characters_sorta_treated_like_whitespace) {
2832
2843
for (string8_view control_character : control_characters_except_whitespace) {
2833
- padded_string input (u8" " + string8 ( control_character) + u8" hello" );
2844
+ padded_string input (concat ( u8" " _sv, control_character, u8" hello" _sv) );
2834
2845
SCOPED_TRACE (input);
2835
2846
diag_collector v;
2836
2847
lexer l (&input, &v);
@@ -2843,7 +2854,7 @@ TEST_F(test_lex, ascii_control_characters_sorta_treated_like_whitespace) {
2843
2854
2844
2855
TEST_F (test_lex, lex_token_notes_leading_newline) {
2845
2856
for (string8_view line_terminator : line_terminators) {
2846
- padded_string code (u8" a b" + string8 ( line_terminator) + u8" c d" );
2857
+ padded_string code (concat ( u8" a b" _sv, line_terminator, u8" c d" _sv) );
2847
2858
lexer l (&code, &null_diag_reporter::instance);
2848
2859
EXPECT_FALSE (l.peek ().has_leading_newline ); // a
2849
2860
l.skip ();
@@ -2857,7 +2868,7 @@ TEST_F(test_lex, lex_token_notes_leading_newline) {
2857
2868
2858
2869
TEST_F (test_lex, lex_token_notes_leading_newline_after_single_line_comment) {
2859
2870
for (string8_view line_terminator : line_terminators) {
2860
- padded_string code (u8" a // hello" + string8 ( line_terminator) + u8" b" );
2871
+ padded_string code (concat ( u8" a // hello" _sv, line_terminator, u8" b" _sv) );
2861
2872
lexer l (&code, &null_diag_reporter::instance);
2862
2873
EXPECT_FALSE (l.peek ().has_leading_newline ); // a
2863
2874
l.skip ();
@@ -2867,7 +2878,7 @@ TEST_F(test_lex, lex_token_notes_leading_newline_after_single_line_comment) {
2867
2878
2868
2879
TEST_F (test_lex, lex_token_notes_leading_newline_after_comment_with_newline) {
2869
2880
for (string8_view line_terminator : line_terminators) {
2870
- padded_string code (u8" a /*" + string8 ( line_terminator) + u8" */ b" );
2881
+ padded_string code (concat ( u8" a /*" _sv, line_terminator, u8" */ b" _sv) );
2871
2882
lexer l (&code, &null_diag_reporter::instance);
2872
2883
EXPECT_FALSE (l.peek ().has_leading_newline ); // a
2873
2884
l.skip ();
0 commit comments