summaryrefslogtreecommitdiff
path: root/AK/Tests/TestString.cpp
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-15 13:36:50 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-15 13:50:42 +0200
commitd8aa2a6997800779cd2dc4303cb2256a32ffc2f3 (patch)
tree27b9d3e1d1fe541b346ffdb2d597a0a93e064ea8 /AK/Tests/TestString.cpp
parent85f2987848e24bd32ff093ee678d11df63492423 (diff)
downloadserenity-d8aa2a6997800779cd2dc4303cb2256a32ffc2f3.zip
AK: StringBuilder with 0 initial capacity shouldn't build null String
With 0 initial capacity, we don't allocate an underlying ByteBuffer for the StringBuilder, which would then lead to a null String() being returned from to_string(). This patch makes sure we always build a valid String.
Diffstat (limited to 'AK/Tests/TestString.cpp')
-rw-r--r--AK/Tests/TestString.cpp9
1 files changed, 9 insertions, 0 deletions
diff --git a/AK/Tests/TestString.cpp b/AK/Tests/TestString.cpp
index bd9a8fbc73..5576bcec90 100644
--- a/AK/Tests/TestString.cpp
+++ b/AK/Tests/TestString.cpp
@@ -199,4 +199,13 @@ TEST_CASE(split)
EXPECT_EQ(parts[2].characters()[3], '\0');
}
+TEST_CASE(builder_zero_initial_capacity)
+{
+ StringBuilder builder(0);
+ builder.append("");
+ auto built = builder.build();
+ EXPECT_EQ(built.is_null(), false);
+ EXPECT_EQ(built.length(), 0u);
+}
+
TEST_MAIN(String)