99#include < iostream>
1010#include < quick-lint-js/assert.h>
1111#include < quick-lint-js/characters.h>
12+ #include < quick-lint-js/container/concat.h>
1213#include < quick-lint-js/container/linked-vector.h>
1314#include < quick-lint-js/container/padded-string.h>
1415#include < quick-lint-js/diag-collector.h>
@@ -248,7 +249,7 @@ TEST_F(test_lex, lex_line_comments) {
248249 EXPECT_THAT (this ->lex_to_eof (u8" // hello" _sv), IsEmpty ());
249250 for (string8_view line_terminator : line_terminators) {
250251 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);
252253 }
253254 EXPECT_THAT (this ->lex_to_eof (u8" // hello\n // world" _sv), IsEmpty ());
254255 this ->check_tokens (u8" hello//*/\n \n \n world" _sv,
@@ -267,8 +268,8 @@ TEST_F(test_lex, lex_line_comments) {
267268TEST_F (test_lex, lex_line_comments_with_control_characters) {
268269 for (string8_view control_character :
269270 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) );
272273 SCOPED_TRACE (input);
273274 this ->check_tokens (&input, {token_type::number});
274275 }
@@ -278,16 +279,16 @@ TEST_F(test_lex, lex_html_open_comments) {
278279 EXPECT_THAT (this ->lex_to_eof (u8" <!-- --> hello" _sv), IsEmpty ());
279280 for (string8_view line_terminator : line_terminators) {
280281 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);
282283 }
283284 EXPECT_THAT (this ->lex_to_eof (u8" <!-- hello\n <!-- world" _sv), IsEmpty ());
284285 EXPECT_THAT (this ->lex_to_eof (u8" <!--// hello" _sv), IsEmpty ());
285286 this ->check_tokens (u8" hello<!--->\n \n \n world" _sv,
286287 {token_type::identifier, token_type::identifier});
287288 for (string8_view control_character :
288289 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) );
291292 SCOPED_TRACE (input);
292293 this ->check_tokens (&input, {token_type::number});
293294 }
@@ -310,19 +311,22 @@ TEST_F(test_lex, lex_html_close_comments) {
310311 for (string8_view line_terminator : line_terminators) {
311312 string8 eol (line_terminator);
312313
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+
315322 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) ,
317324 u8" hello" _sv);
318-
319- this ->check_single_token (u8" /*" + eol + u8" */--> comment" + eol + u8" hello" ,
320- u8" hello" _sv);
321325 this ->check_single_token (
322- u8" /* */ /*" + eol + u8" */ --> comment" + eol + u8" hello" ,
326+ concat ( u8" /* */ /*" _sv, eol, u8" */ --> comment" _sv, eol, u8" hello" _sv) ,
323327 u8" hello" _sv);
324328 this ->check_single_token (
325- u8" /*" + eol + u8" */ /* */ --> comment" + eol + u8" hello" ,
329+ concat ( u8" /*" _sv, eol, u8" */ /* */ --> comment" _sv, eol, u8" hello" _sv) ,
326330 u8" hello" _sv);
327331 }
328332
@@ -1036,18 +1040,18 @@ TEST_F(test_lex, lex_strings) {
10361040 });
10371041
10381042 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) );
10431047 this ->check_tokens (&input, {token_type::string});
10441048 }
10451049 }
10461050
10471051 for (string8_view line_terminator : line_terminators_except_ls_ps) {
10481052 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) );
10511055 lexer l (&input, &v);
10521056 EXPECT_EQ (l.peek ().type , token_type::string);
10531057 l.skip ();
@@ -1063,7 +1067,8 @@ TEST_F(test_lex, lex_strings) {
10631067
10641068 for (string8_view line_terminator : line_terminators_except_ls_ps) {
10651069 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));
10671072 lexer l (&input, &v);
10681073 EXPECT_EQ (l.peek ().type , token_type::string);
10691074 l.skip ();
@@ -1079,8 +1084,8 @@ TEST_F(test_lex, lex_strings) {
10791084
10801085 for (string8_view line_terminator : line_terminators_except_ls_ps) {
10811086 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) );
10841089 lexer l (&input, &v);
10851090 EXPECT_EQ (l.peek ().type , token_type::string);
10861091 l.skip ();
@@ -1104,8 +1109,8 @@ TEST_F(test_lex, lex_strings) {
11041109
11051110 for (string8_view line_terminator : line_terminators_except_ls_ps) {
11061111 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) );
11091114 lexer l (&input, &v);
11101115 EXPECT_EQ (l.peek ().type , token_type::kw_let);
11111116 l.skip ();
@@ -1240,14 +1245,16 @@ TEST_F(test_lex, lex_strings) {
12401245TEST_F (test_lex, lex_string_with_ascii_control_characters) {
12411246 for (string8_view control_character :
12421247 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));
12441250 SCOPED_TRACE (input);
12451251 this ->check_tokens (&input, {token_type::string});
12461252 }
12471253
12481254 for (string8_view control_character :
12491255 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));
12511258 SCOPED_TRACE (input);
12521259 this ->check_tokens (&input, {token_type::string});
12531260 }
@@ -1598,14 +1605,16 @@ TEST_F(test_lex, templates_do_not_buffer_valid_unicode_escapes) {
15981605TEST_F (test_lex, lex_template_literal_with_ascii_control_characters) {
15991606 for (string8_view control_character :
16001607 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));
16021610 SCOPED_TRACE (input);
16031611 this ->check_tokens (&input, {token_type::complete_template});
16041612 }
16051613
16061614 for (string8_view control_character :
16071615 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));
16091618 SCOPED_TRACE (input);
16101619 this ->check_tokens (&input, {token_type::complete_template});
16111620 }
@@ -1660,8 +1669,8 @@ TEST_F(test_lex, lex_regular_expression_literals) {
16601669 }
16611670
16621671 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) );
16651674 SCOPED_TRACE (code);
16661675 diag_collector v;
16671676 lexer l (&code, &v);
@@ -1683,8 +1692,8 @@ TEST_F(test_lex, lex_regular_expression_literals) {
16831692 }
16841693
16851694 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) );
16881697 SCOPED_TRACE (code);
16891698 diag_collector v;
16901699 lexer l (&code, &v);
@@ -1781,7 +1790,8 @@ TEST_F(test_lex,
17811790TEST_F (test_lex, lex_regular_expression_literal_with_ascii_control_characters) {
17821791 for (string8_view control_character :
17831792 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));
17851795 SCOPED_TRACE (input);
17861796 diag_collector errors;
17871797 lexer l (&input, &errors);
@@ -1796,7 +1806,8 @@ TEST_F(test_lex, lex_regular_expression_literal_with_ascii_control_characters) {
17961806
17971807 for (string8_view control_character :
17981808 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));
18001811 SCOPED_TRACE (input);
18011812 diag_collector errors;
18021813 lexer l (&input, &errors);
@@ -2830,7 +2841,7 @@ TEST_F(test_lex, ascii_control_characters_are_disallowed) {
28302841
28312842TEST_F (test_lex, ascii_control_characters_sorta_treated_like_whitespace) {
28322843 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) );
28342845 SCOPED_TRACE (input);
28352846 diag_collector v;
28362847 lexer l (&input, &v);
@@ -2843,7 +2854,7 @@ TEST_F(test_lex, ascii_control_characters_sorta_treated_like_whitespace) {
28432854
28442855TEST_F (test_lex, lex_token_notes_leading_newline) {
28452856 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) );
28472858 lexer l (&code, &null_diag_reporter::instance);
28482859 EXPECT_FALSE (l.peek ().has_leading_newline ); // a
28492860 l.skip ();
@@ -2857,7 +2868,7 @@ TEST_F(test_lex, lex_token_notes_leading_newline) {
28572868
28582869TEST_F (test_lex, lex_token_notes_leading_newline_after_single_line_comment) {
28592870 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) );
28612872 lexer l (&code, &null_diag_reporter::instance);
28622873 EXPECT_FALSE (l.peek ().has_leading_newline ); // a
28632874 l.skip ();
@@ -2867,7 +2878,7 @@ TEST_F(test_lex, lex_token_notes_leading_newline_after_single_line_comment) {
28672878
28682879TEST_F (test_lex, lex_token_notes_leading_newline_after_comment_with_newline) {
28692880 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) );
28712882 lexer l (&code, &null_diag_reporter::instance);
28722883 EXPECT_FALSE (l.peek ().has_leading_newline ); // a
28732884 l.skip ();
0 commit comments