diff options
author | Timothy Flynn <trflynn89@pm.me> | 2023-01-20 07:20:01 -0500 |
---|---|---|
committer | Tim Flynn <trflynn89@pm.me> | 2023-01-20 14:24:12 -0500 |
commit | d48266a42039b801f5833e9a28634eb94eff7953 (patch) | |
tree | 71b06e42428c1e57ba5773d2efe51a2d615dcb5e /Tests | |
parent | e63477867988d2488d7493f7e716d587fde488d0 (diff) | |
download | serenity-d48266a42039b801f5833e9a28634eb94eff7953.zip |
AK: Support creating known short string literals at compile time
In cases where we know a string literal will fit in the short string
storage, we can do so at compile time without needing to handle error
propagation. If the provided string literal is too long, a compilation
error will be emitted due to the failed VERIFY statement being a non-
constant expression.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/AK/TestString.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Tests/AK/TestString.cpp b/Tests/AK/TestString.cpp index d78854b626..c089cfcf72 100644 --- a/Tests/AK/TestString.cpp +++ b/Tests/AK/TestString.cpp @@ -34,15 +34,25 @@ TEST_CASE(move_assignment) TEST_CASE(short_strings) { #ifdef AK_ARCH_64_BIT - auto string = MUST(String::from_utf8("abcdefg"sv)); - EXPECT_EQ(string.is_short_string(), true); - EXPECT_EQ(string.bytes().size(), 7u); - EXPECT_EQ(string.bytes_as_string_view(), "abcdefg"sv); + auto string1 = MUST(String::from_utf8("abcdefg"sv)); + EXPECT_EQ(string1.is_short_string(), true); + EXPECT_EQ(string1.bytes().size(), 7u); + EXPECT_EQ(string1.bytes_as_string_view(), "abcdefg"sv); + + constexpr auto string2 = String::from_utf8_short_string("abcdefg"sv); + EXPECT_EQ(string2.is_short_string(), true); + EXPECT_EQ(string2.bytes().size(), 7u); + EXPECT_EQ(string2, string1); #else - auto string = MUST(String::from_utf8("abc"sv)); - EXPECT_EQ(string.is_short_string(), true); - EXPECT_EQ(string.bytes().size(), 3u); - EXPECT_EQ(string.bytes_as_string_view(), "abc"sv); + auto string1 = MUST(String::from_utf8("abc"sv)); + EXPECT_EQ(string1.is_short_string(), true); + EXPECT_EQ(string1.bytes().size(), 3u); + EXPECT_EQ(string1.bytes_as_string_view(), "abc"sv); + + constexpr auto string2 = String::from_utf8_short_string("abc"sv); + EXPECT_EQ(string2.is_short_string(), true); + EXPECT_EQ(string2.bytes().size(), 3u); + EXPECT_EQ(string2, string1); #endif } |