1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 10:57:35 +00:00

Everywhere: Prefer using "..."sv over StringView { "..." }

This commit is contained in:
Gunnar Beutner 2021-07-04 11:08:46 +02:00 committed by Andreas Kling
parent ea8ff03475
commit 3bbe86d8ea
11 changed files with 35 additions and 35 deletions

View file

@ -39,9 +39,9 @@ TEST_CASE(reorder_format_arguments)
EXPECT_EQ(String::formatted("{1}{0}", "a", "b"), "ba");
EXPECT_EQ(String::formatted("{0}{1}", "a", "b"), "ab");
// Compiletime check bypass: ignoring a passed argument.
EXPECT_EQ(String::formatted(StringView { "{0}{0}{0}" }, "a", "b"), "aaa");
EXPECT_EQ(String::formatted("{0}{0}{0}"sv, "a", "b"), "aaa");
// Compiletime check bypass: ignoring a passed argument.
EXPECT_EQ(String::formatted(StringView { "{1}{}{0}" }, "a", "b", "c"), "baa");
EXPECT_EQ(String::formatted("{1}{}{0}"sv, "a", "b", "c"), "baa");
}
TEST_CASE(escape_braces)
@ -108,7 +108,7 @@ TEST_CASE(replacement_field)
EXPECT_EQ(String::formatted("{:*>{1}}", 13, static_cast<size_t>(10)), "********13");
EXPECT_EQ(String::formatted("{:*<{1}}", 7, 4), "7***");
// Compiletime check bypass: intentionally ignoring extra arguments
EXPECT_EQ(String::formatted(StringView { "{:{2}}" }, -5, 8, 16), " -5");
EXPECT_EQ(String::formatted("{:{2}}"sv, -5, 8, 16), " -5");
EXPECT_EQ(String::formatted("{{{:*^{1}}}}", 1, 3), "{*1*}");
EXPECT_EQ(String::formatted("{:0{}}", 1, 3), "001");
}
@ -116,7 +116,7 @@ TEST_CASE(replacement_field)
TEST_CASE(replacement_field_regression)
{
// FIXME: Compiletime check bypass: cannot parse '}}' correctly.
EXPECT_EQ(String::formatted(StringView { "{:{}}" }, "", static_cast<unsigned long>(6)), " ");
EXPECT_EQ(String::formatted("{:{}}"sv, "", static_cast<unsigned long>(6)), " ");
}
TEST_CASE(complex_string_specifiers)
@ -224,7 +224,7 @@ TEST_CASE(file_descriptor)
Array<u8, 256> buffer;
const auto nread = fread(buffer.data(), 1, buffer.size(), file);
EXPECT_EQ(StringView { "Hello, World!\nfoobar\n" }, StringView { buffer.span().trim(nread) });
EXPECT_EQ("Hello, World!\nfoobar\n"sv, StringView { buffer.span().trim(nread) });
fclose(file);
}

View file

@ -17,25 +17,25 @@ TEST_CASE(should_constexpr_construct_from_empty_string_view)
TEST_CASE(should_construct_from_string_view)
{
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(!sut.is_eof());
}
TEST_CASE(should_constexpr_tell)
{
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(sut.tell() == 0);
}
TEST_CASE(should_constexpr_tell_remaining)
{
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(sut.tell_remaining() == 6);
}
TEST_CASE(should_constexpr_peek)
{
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(sut.peek() == 'a');
static_assert(sut.peek(2) == 'c');
static_assert(sut.peek(100) == '\0');
@ -43,16 +43,16 @@ TEST_CASE(should_constexpr_peek)
TEST_CASE(should_constexpr_next_is)
{
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(sut.next_is('a'));
static_assert(sut.next_is("abc"));
static_assert(sut.next_is(StringView { "abc" }));
static_assert(sut.next_is("abc"sv));
}
TEST_CASE(should_constexpr_retreat)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.consume();
sut.retreat();
return sut;
@ -63,7 +63,7 @@ TEST_CASE(should_constexpr_retreat)
TEST_CASE(should_constexpr_consume_1)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.consume();
return sut;
}();
@ -73,7 +73,7 @@ TEST_CASE(should_constexpr_consume_1)
TEST_CASE(should_constexpr_consume_specific_char)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.consume_specific('a');
return sut;
}();
@ -83,8 +83,8 @@ TEST_CASE(should_constexpr_consume_specific_char)
TEST_CASE(should_constexpr_consume_specific_string_view)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
sut.consume_specific(StringView { "ab" });
GenericLexer sut("abcdef"sv);
sut.consume_specific("ab"sv);
return sut;
}();
static_assert(sut.peek() == 'c');
@ -93,7 +93,7 @@ TEST_CASE(should_constexpr_consume_specific_string_view)
TEST_CASE(should_constexpr_consume_specific_cstring)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.consume_specific("abcd");
return sut;
}();
@ -103,7 +103,7 @@ TEST_CASE(should_constexpr_consume_specific_cstring)
TEST_CASE(should_constexpr_ignore_until)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.ignore_until('d');
return sut;
}();
@ -113,7 +113,7 @@ TEST_CASE(should_constexpr_ignore_until)
TEST_CASE(should_constexpr_ignore_until_cstring)
{
constexpr auto sut = [] {
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.ignore_until("cde");
return sut;
}();
@ -125,7 +125,7 @@ TEST_CASE(should_constexpr_next_is_pred)
constexpr auto pred = [](auto c) {
return c == 'a';
};
constexpr GenericLexer sut(StringView { "abcdef" });
constexpr GenericLexer sut("abcdef"sv);
static_assert(sut.next_is(pred));
}
@ -136,7 +136,7 @@ TEST_CASE(should_constexpr_ignore_while_pred)
return c == 'a';
};
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.ignore_while(pred);
return sut;
}();
@ -150,7 +150,7 @@ TEST_CASE(should_constexpr_ignore_until_pred)
return c == 'c';
};
GenericLexer sut(StringView { "abcdef" });
GenericLexer sut("abcdef"sv);
sut.ignore_until(pred);
return sut;
}();