diff options
author | Andrew Kaster <akaster@serenityos.org> | 2021-07-17 16:27:12 -0600 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2021-07-19 05:17:05 +0430 |
commit | 64aac345d38f98520c367c080829f06fd47472b6 (patch) | |
tree | 940f21fcfe1ab3f31cdf5dcf3993d42017bf510d /Tests/AK | |
parent | 4842c8c90286b56e4bac6767c28076191ba5b00e (diff) | |
download | serenity-64aac345d38f98520c367c080829f06fd47472b6.zip |
AK: Use new Formatter for each element in Formatter<Vector<T>>
The state of the formatter for the previous element should be thrown
away for each iteration. This showed up when trying to format a
Vector<String>, since Formatter<StringView> was unhappy about some state
that gets set when it's called. Add a test for Formatter<Vector>.
Diffstat (limited to 'Tests/AK')
-rw-r--r-- | Tests/AK/TestFormat.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Tests/AK/TestFormat.cpp b/Tests/AK/TestFormat.cpp index 3c61179879..28696cce28 100644 --- a/Tests/AK/TestFormat.cpp +++ b/Tests/AK/TestFormat.cpp @@ -8,6 +8,7 @@ #include <AK/String.h> #include <AK/StringBuilder.h> +#include <AK/Vector.h> TEST_CASE(is_integral_works_properly) { @@ -306,3 +307,19 @@ TEST_CASE(hex_dump) EXPECT_EQ(String::formatted("{:>2hex-dump}", "0000"), "3030 00\n3030 00"); EXPECT_EQ(String::formatted("{:*>4hex-dump}", "0000"), "30303030****0000"); } + +TEST_CASE(vector_format) +{ + { + Vector<int> v { 1, 2, 3, 4 }; + EXPECT_EQ(String::formatted("{}", v), "[ 1, 2, 3, 4 ]"); + } + { + Vector<StringView> v { "1"sv, "2"sv, "3"sv, "4"sv }; + EXPECT_EQ(String::formatted("{}", v), "[ 1, 2, 3, 4 ]"); + } + { + Vector<Vector<String>> v { { "1"sv, "2"sv }, { "3"sv, "4"sv } }; + EXPECT_EQ(String::formatted("{}", v), "[ [ 1, 2 ], [ 3, 4 ] ]"); + } +} |