Skip to content

Commit e138d8c

Browse files
committed
refactor: avoid string8_view::string8_view(const char8_t*) constructor
Explicitly make string8_view objects instead of relying on the C-string-to-view converting constructor.
1 parent 05c3d48 commit e138d8c

15 files changed

+232
-218
lines changed

test/test-lex.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3408,7 +3408,7 @@ TEST_F(test_lex, unterminated_jsx_string) {
34083408
ElementsAreArray({
34093409
DIAG_TYPE_OFFSETS(&code,
34103410
diag_unclosed_jsx_string_literal, //
3411-
string_literal_begin, strlen(u8"! "), u8"'"),
3411+
string_literal_begin, strlen(u8"! "), u8"'"_sv),
34123412
}));
34133413

34143414
l.skip_in_jsx();
@@ -3503,16 +3503,16 @@ TEST_F(test_lex, jsx_text_children) {
35033503
errors.errors,
35043504
ElementsAreArray({
35053505
DIAG_TYPE_OFFSETS(&code, diag_unexpected_greater_in_jsx_text, //
3506-
greater, strlen(u8"<>"), u8">"),
3506+
greater, strlen(u8"<>"), u8">"_sv),
35073507
}));
35083508
} else if (text_begin == u8">>" || text_begin == u8">>=") {
35093509
EXPECT_THAT(
35103510
errors.errors,
35113511
ElementsAreArray({
35123512
DIAG_TYPE_OFFSETS(&code, diag_unexpected_greater_in_jsx_text, //
3513-
greater, strlen(u8"<>"), u8">"),
3513+
greater, strlen(u8"<>"), u8">"_sv),
35143514
DIAG_TYPE_OFFSETS(&code, diag_unexpected_greater_in_jsx_text, //
3515-
greater, strlen(u8"<>>"), u8">"),
3515+
greater, strlen(u8"<>>"), u8">"_sv),
35163516
}));
35173517
} else {
35183518
QLJS_UNREACHABLE();
@@ -3533,7 +3533,7 @@ TEST_F(test_lex, jsx_illegal_text_children) {
35333533
errors.errors,
35343534
ElementsAreArray({
35353535
DIAG_TYPE_OFFSETS(&code, diag_unexpected_greater_in_jsx_text, //
3536-
greater, strlen(u8"<>hello"), u8">"),
3536+
greater, strlen(u8"<>hello"), u8">"_sv),
35373537
}));
35383538
}
35393539

@@ -3549,7 +3549,7 @@ TEST_F(test_lex, jsx_illegal_text_children) {
35493549
ElementsAreArray({
35503550
DIAG_TYPE_OFFSETS(
35513551
&code, diag_unexpected_right_curly_in_jsx_text, //
3552-
right_curly, strlen(u8"<>hello"), u8"}"),
3552+
right_curly, strlen(u8"<>hello"), u8"}"_sv),
35533553
}));
35543554
}
35553555
}

test/test-lsp-server.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,15 +187,15 @@ TEST_F(test_linting_lsp_server, initialize_with_different_request_ids) {
187187

188188
// TODO(strager): Support numbers with fractional parts, such as 12.34.
189189
for (const test_case& test : {
190-
test_case{u8"null", ::boost::json::value()},
191-
test_case{u8"1", ::boost::json::value(1)},
192-
test_case{u8"9007199254740991",
190+
test_case{u8"null"_sv, ::boost::json::value()},
191+
test_case{u8"1"_sv, ::boost::json::value(1)},
192+
test_case{u8"9007199254740991"_sv,
193193
::boost::json::value(std::int64_t{9007199254740991LL})},
194-
test_case{u8"-12345", ::boost::json::value(-12345)},
195-
test_case{u8R"("A")", ::boost::json::value("A")},
196-
test_case{u8R"("id value goes \"here\"")",
194+
test_case{u8"-12345"_sv, ::boost::json::value(-12345)},
195+
test_case{u8R"("A")"_sv, ::boost::json::value("A")},
196+
test_case{u8R"("id value goes \"here\"")"_sv,
197197
::boost::json::value("id value goes \"here\"")},
198-
test_case{u8R"("id value goes \"here\"")",
198+
test_case{u8R"("id value goes \"here\"")"_sv,
199199
::boost::json::value("id value goes \"here\"")},
200200
}) {
201201
SCOPED_TRACE(out_string8(test.id_json));
@@ -518,8 +518,8 @@ TEST_F(test_linting_lsp_server, opening_document_lints) {
518518
padded_string_view code, string8_view uri_json,
519519
string8_view version,
520520
byte_buffer& notification_json) {
521-
EXPECT_EQ(code, u8"let x = x;");
522-
EXPECT_EQ(uri_json, u8"\"file:///test.js\"");
521+
EXPECT_EQ(code, u8"let x = x;"_sv);
522+
EXPECT_EQ(uri_json, u8"\"file:///test.js\""_sv);
523523
EXPECT_EQ(version, u8"10"sv);
524524

525525
notification_json.append_copy(
@@ -824,7 +824,7 @@ TEST_F(test_linting_lsp_server,
824824

825825
TEST_F(test_linting_lsp_server, linting_uses_config_from_file) {
826826
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
827-
u8R"({"globals": {"testGlobalVariable": true}})");
827+
u8R"({"globals": {"testGlobalVariable": true}})"_sv);
828828

829829
this->lint_callback = [&](configuration& config, linter_options,
830830
padded_string_view, string8_view, string8_view,
@@ -944,7 +944,7 @@ TEST_F(
944944
TEST_F(test_linting_lsp_server,
945945
linting_uses_config_from_file_with_special_chars_in_document_uri) {
946946
this->fs.create_file(this->fs.rooted("a%b~/quick-lint-js.config"),
947-
u8R"({"globals": {"testGlobalVariable": true}})");
947+
u8R"({"globals": {"testGlobalVariable": true}})"_sv);
948948

949949
this->lint_callback = [&](configuration& config, linter_options,
950950
padded_string_view, string8_view, string8_view,
@@ -979,7 +979,7 @@ TEST_F(test_linting_lsp_server, linting_uses_already_opened_config_file) {
979979
};
980980

981981
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
982-
u8R"({"globals": {"modified": false}})");
982+
u8R"({"globals": {"modified": false}})"_sv);
983983
this->server->append(
984984
make_message(concat(u8R"({
985985
"jsonrpc": "2.0",
@@ -1024,7 +1024,7 @@ TEST_F(test_linting_lsp_server,
10241024
};
10251025

10261026
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
1027-
u8R"({"globals": {"haveOuterConfig": false}})");
1027+
u8R"({"globals": {"haveOuterConfig": false}})"_sv);
10281028
this->server->append(
10291029
make_message(concat(u8R"({
10301030
"jsonrpc": "2.0",
@@ -1075,7 +1075,7 @@ TEST_F(test_linting_lsp_server, editing_config_relints_open_js_file) {
10751075
};
10761076

10771077
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
1078-
u8R"({"globals": {"before": true}})");
1078+
u8R"({"globals": {"before": true}})"_sv);
10791079
this->server->append(
10801080
make_message(concat(u8R"({
10811081
"jsonrpc": "2.0",
@@ -1136,7 +1136,7 @@ TEST_F(test_linting_lsp_server, editing_config_relints_open_js_file) {
11361136
TEST_F(test_linting_lsp_server,
11371137
editing_config_lints_latest_version_of_js_file) {
11381138
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
1139-
u8R"({"globals": {"before": true}})");
1139+
u8R"({"globals": {"before": true}})"_sv);
11401140
this->server->append(
11411141
make_message(concat(u8R"({
11421142
"jsonrpc": "2.0",
@@ -1245,7 +1245,7 @@ TEST_F(test_linting_lsp_server, editing_config_relints_many_open_js_files) {
12451245
};
12461246

12471247
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
1248-
u8R"({"globals": {"before": true}})");
1248+
u8R"({"globals": {"before": true}})"_sv);
12491249
this->server->append(
12501250
make_message(concat(u8R"({
12511251
"jsonrpc": "2.0",
@@ -1262,7 +1262,7 @@ TEST_F(test_linting_lsp_server, editing_config_relints_many_open_js_files) {
12621262
}
12631263
})"_sv)));
12641264

1265-
for (const char8* js_file : {u8"a.js", u8"b.js", u8"c.js"}) {
1265+
for (string8_view js_file : {u8"a.js"_sv, u8"b.js"_sv, u8"c.js"_sv}) {
12661266
this->server->append(
12671267
make_message(concat(u8R"({
12681268
"jsonrpc": "2.0",
@@ -1387,7 +1387,7 @@ TEST_F(test_linting_lsp_server, editing_config_relints_only_affected_js_files) {
13871387
}
13881388
})"_sv)));
13891389

1390-
for (const char8* js_file : {u8"dir-a/test.js", u8"dir-b/test.js"}) {
1390+
for (string8_view js_file : {u8"dir-a/test.js"_sv, u8"dir-b/test.js"_sv}) {
13911391
this->server->append(
13921392
make_message(concat(u8R"({
13931393
"jsonrpc": "2.0",
@@ -1558,7 +1558,7 @@ TEST_F(test_linting_lsp_server, opening_config_relints_open_js_files) {
15581558
};
15591559

15601560
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
1561-
u8R"({"globals": {"before": true}})");
1561+
u8R"({"globals": {"before": true}})"_sv);
15621562
this->server->append(
15631563
make_message(concat(u8R"({
15641564
"jsonrpc": "2.0",
@@ -1596,7 +1596,7 @@ TEST_F(test_linting_lsp_server, opening_config_relints_open_js_files) {
15961596
TEST_F(test_linting_lsp_server,
15971597
changing_config_on_filesystem_relints_open_js_files) {
15981598
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
1599-
u8R"({"globals": {"before": true}})");
1599+
u8R"({"globals": {"before": true}})"_sv);
16001600
this->server->append(
16011601
make_message(concat(u8R"({
16021602
"jsonrpc": "2.0",
@@ -1640,7 +1640,7 @@ TEST_F(test_linting_lsp_server,
16401640
this->client->messages.clear();
16411641

16421642
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
1643-
u8R"({"globals": {"after": true}})");
1643+
u8R"({"globals": {"after": true}})"_sv);
16441644
this->handler->filesystem_changed();
16451645
this->handler->flush_pending_notifications(*this->client);
16461646

@@ -1664,7 +1664,7 @@ TEST_F(
16641664
};
16651665

16661666
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
1667-
u8R"({"globals": {"v1": true}})");
1667+
u8R"({"globals": {"v1": true}})"_sv);
16681668
this->server->append(
16691669
make_message(concat(u8R"({
16701670
"jsonrpc": "2.0",
@@ -1714,7 +1714,7 @@ TEST_F(
17141714
TEST_F(test_linting_lsp_server,
17151715
closing_open_config_reloads_config_from_filesystem) {
17161716
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
1717-
u8R"({"globals": {"configFromFilesystem": true}})");
1717+
u8R"({"globals": {"configFromFilesystem": true}})"_sv);
17181718
this->server->append(
17191719
make_message(concat(u8R"({
17201720
"jsonrpc": "2.0",
@@ -1914,7 +1914,7 @@ TEST_F(test_linting_lsp_server,
19141914

19151915
TEST_F(test_linting_lsp_server, making_config_file_unreadable_relints) {
19161916
this->fs.create_file(this->fs.rooted("quick-lint-js.config"),
1917-
u8R"({"globals": {"configFromFilesystem": true}})");
1917+
u8R"({"globals": {"configFromFilesystem": true}})"_sv);
19181918

19191919
this->server->append(
19201920
make_message(concat(u8R"({

test/test-parse-class.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,8 @@ TEST_F(test_parse_class,
721721
ElementsAre(u8"myField", ::testing::_));
722722
}
723723

724-
for (string8_view first_member : {u8"3.14", u8"'bananas'", u8"[expr]"}) {
724+
for (string8_view first_member :
725+
{u8"3.14"_sv, u8"'bananas'"_sv, u8"[expr]"_sv}) {
725726
padded_string code(concat(u8"class C { "_sv, first_member, u8"\n"_sv,
726727
second_member, u8" }"_sv));
727728
SCOPED_TRACE(code);

test/test-parse-expression-statement.cpp

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ TEST_F(test_parse_expression_statement, statement_beginning_with_async_or_let) {
10631063
EXPECT_THAT(p.variable_uses, ElementsAreArray({name}));
10641064
}
10651065

1066-
for (const char8* unary_operator : {u8"++", u8"--"}) {
1066+
for (string8_view unary_operator : {u8"++"_sv, u8"--"_sv}) {
10671067
test_parser p(concat(name, unary_operator));
10681068
SCOPED_TRACE(p.code);
10691069
p.parse_and_visit_statement();
@@ -1108,22 +1108,22 @@ TEST_F(test_parse_expression_statement, statement_beginning_with_async_or_let) {
11081108
}));
11091109
}
11101110

1111-
for (const char8* binary_operator : {
1112-
u8"%=",
1113-
u8"&&=",
1114-
u8"&=",
1115-
u8"**=",
1116-
u8"*=",
1117-
u8"+=",
1118-
u8"-=",
1119-
u8"/=",
1120-
u8"<<=",
1121-
u8">>=",
1122-
u8">>>=",
1123-
u8"?\x3f=",
1124-
u8"^=",
1125-
u8"|=",
1126-
u8"||=",
1111+
for (string8_view binary_operator : {
1112+
u8"%="_sv,
1113+
u8"&&="_sv,
1114+
u8"&="_sv,
1115+
u8"**="_sv,
1116+
u8"*="_sv,
1117+
u8"+="_sv,
1118+
u8"-="_sv,
1119+
u8"/="_sv,
1120+
u8"<<="_sv,
1121+
u8">>="_sv,
1122+
u8">>>="_sv,
1123+
u8"?\x3f="_sv,
1124+
u8"^="_sv,
1125+
u8"|="_sv,
1126+
u8"||="_sv,
11271127
}) {
11281128
test_parser p(concat(name, u8" "_sv, binary_operator, u8" other"_sv));
11291129
SCOPED_TRACE(p.code);
@@ -1132,11 +1132,13 @@ TEST_F(test_parse_expression_statement, statement_beginning_with_async_or_let) {
11321132
EXPECT_THAT(p.variable_assignments, ElementsAreArray({name}));
11331133
}
11341134

1135-
for (const char8* binary_operator : {
1136-
u8"!=", u8"!==", u8"%", u8"&", u8"&&", u8"*", u8"**",
1137-
u8"+", u8",", u8"-", u8"/", u8"<", u8"<<", u8"<=",
1138-
u8"==", u8"===", u8">", u8">=", u8">>", u8">>>", u8"??",
1139-
u8"^", u8"in", u8"instanceof", u8"|", u8"||",
1135+
for (string8_view binary_operator : {
1136+
u8"!="_sv, u8"!=="_sv, u8"%"_sv, u8"&"_sv, u8"&&"_sv,
1137+
u8"*"_sv, u8"**"_sv, u8"+"_sv, u8","_sv, u8"-"_sv,
1138+
u8"/"_sv, u8"<"_sv, u8"<<"_sv, u8"<="_sv, u8"=="_sv,
1139+
u8"==="_sv, u8">"_sv, u8">="_sv, u8">>"_sv, u8">>>"_sv,
1140+
u8"??"_sv, u8"^"_sv, u8"in"_sv, u8"instanceof"_sv, u8"|"_sv,
1141+
u8"||"_sv,
11401142
}) {
11411143
test_parser p(concat(name, u8" "_sv, binary_operator, u8" other"_sv));
11421144
SCOPED_TRACE(p.code);
@@ -1608,23 +1610,24 @@ TEST_F(test_parse_expression_statement, invalid_parentheses) {
16081610
ElementsAreArray({
16091611
DIAG_TYPE_3_OFFSETS(
16101612
p.code, diag_missing_expression_between_parentheses, //
1611-
left_paren_to_right_paren, 0, u8"()", //
1612-
left_paren, 0, u8"(", //
1613-
right_paren, strlen(u8"("), u8")"),
1613+
left_paren_to_right_paren, 0, u8"()"_sv, //
1614+
left_paren, 0, u8"("_sv, //
1615+
right_paren, strlen(u8"("), u8")"_sv),
16141616
}));
16151617
}
16161618

16171619
{
16181620
test_parser p(u8"x = ()"_sv, capture_diags);
16191621
p.parse_and_visit_expression();
1620-
EXPECT_THAT(p.errors,
1621-
ElementsAreArray({
1622-
DIAG_TYPE_3_OFFSETS(
1623-
p.code, diag_missing_expression_between_parentheses, //
1624-
left_paren_to_right_paren, strlen(u8"x = "), u8"()", //
1625-
left_paren, strlen(u8"x = "), u8"(", //
1626-
right_paren, strlen(u8"x = ("), u8")"),
1627-
}));
1622+
EXPECT_THAT(
1623+
p.errors,
1624+
ElementsAreArray({
1625+
DIAG_TYPE_3_OFFSETS(
1626+
p.code, diag_missing_expression_between_parentheses, //
1627+
left_paren_to_right_paren, strlen(u8"x = "), u8"()"_sv, //
1628+
left_paren, strlen(u8"x = "), u8"("_sv, //
1629+
right_paren, strlen(u8"x = ("), u8")"_sv),
1630+
}));
16281631
}
16291632

16301633
{
@@ -1634,9 +1637,9 @@ TEST_F(test_parse_expression_statement, invalid_parentheses) {
16341637
ElementsAreArray({
16351638
DIAG_TYPE_3_OFFSETS(
16361639
p.code, diag_missing_expression_between_parentheses, //
1637-
left_paren_to_right_paren, 0, u8"()", //
1638-
left_paren, 0, u8"(", //
1639-
right_paren, strlen(u8"("), u8")"),
1640+
left_paren_to_right_paren, 0, u8"()"_sv, //
1641+
left_paren, 0, u8"("_sv, //
1642+
right_paren, strlen(u8"("), u8")"_sv),
16401643
}));
16411644
}
16421645
}

0 commit comments

Comments
 (0)