1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 12:27:36 +00:00

Everywhere: Rename {Deprecated => Byte}String

This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
This commit is contained in:
Ali Mohammad Pur 2023-12-16 17:49:34 +03:30 committed by Ali Mohammad Pur
parent 38d62563b3
commit 5e1499d104
1615 changed files with 10257 additions and 10257 deletions

View file

@ -13,13 +13,13 @@ set(AK_TEST_SOURCES
TestBitStream.cpp
TestBuiltinWrappers.cpp
TestByteBuffer.cpp
TestByteString.cpp
TestCharacterTypes.cpp
TestChecked.cpp
TestCircularBuffer.cpp
TestCircularDeque.cpp
TestCircularQueue.cpp
TestComplex.cpp
TestDeprecatedString.cpp
TestDisjointChunks.cpp
TestDistinctNumeric.cpp
TestDoublyLinkedList.cpp

View file

@ -7,14 +7,14 @@
#include <LibTest/TestCase.h>
#include <AK/Base64.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <string.h>
TEST_CASE(test_decode)
{
auto decode_equal = [&](StringView input, StringView expected) {
auto decoded = TRY_OR_FAIL(decode_base64(input));
EXPECT(DeprecatedString::copy(decoded) == expected);
EXPECT(ByteString::copy(decoded) == expected);
EXPECT(expected.length() <= calculate_base64_decoded_length(input.bytes()));
};

View file

@ -7,7 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/BinaryHeap.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
using namespace Test::Randomized;
@ -46,7 +46,7 @@ TEST_CASE(populate_int)
TEST_CASE(populate_string)
{
BinaryHeap<int, DeprecatedString, 5> strings;
BinaryHeap<int, ByteString, 5> strings;
strings.insert(1, "ABC");
strings.insert(2, "DEF");
EXPECT_EQ(strings.size(), 2u);

View file

@ -51,20 +51,20 @@ TEST_CASE(array_doubles)
TEST_CASE(vector_strings)
{
Vector<DeprecatedString> strings;
Vector<ByteString> strings;
strings.append("bat");
strings.append("cat");
strings.append("dog");
auto string_compare = [](DeprecatedString const& a, DeprecatedString const& b) -> int {
auto string_compare = [](ByteString const& a, ByteString const& b) -> int {
return strcmp(a.characters(), b.characters());
};
auto test1 = *binary_search(strings, DeprecatedString("bat"), nullptr, string_compare);
auto test2 = *binary_search(strings, DeprecatedString("cat"), nullptr, string_compare);
auto test3 = *binary_search(strings, DeprecatedString("dog"), nullptr, string_compare);
EXPECT_EQ(test1, DeprecatedString("bat"));
EXPECT_EQ(test2, DeprecatedString("cat"));
EXPECT_EQ(test3, DeprecatedString("dog"));
auto test1 = *binary_search(strings, ByteString("bat"), nullptr, string_compare);
auto test2 = *binary_search(strings, ByteString("cat"), nullptr, string_compare);
auto test3 = *binary_search(strings, ByteString("dog"), nullptr, string_compare);
EXPECT_EQ(test1, ByteString("bat"));
EXPECT_EQ(test2, ByteString("cat"));
EXPECT_EQ(test3, ByteString("dog"));
}
TEST_CASE(single_element)

View file

@ -6,26 +6,26 @@
#include <LibTest/TestCase.h>
#include <AK/ByteString.h>
#include <AK/DeprecatedFlyString.h>
#include <AK/DeprecatedString.h>
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <cstring>
TEST_CASE(construct_empty)
{
EXPECT(DeprecatedString().is_empty());
EXPECT(DeprecatedString().characters() != nullptr);
EXPECT(ByteString().is_empty());
EXPECT(ByteString().characters() != nullptr);
EXPECT(DeprecatedString("").is_empty());
EXPECT(DeprecatedString("").characters() != nullptr);
EXPECT(ByteString("").is_empty());
EXPECT(ByteString("").characters() != nullptr);
EXPECT(DeprecatedString("").impl() == DeprecatedString::empty().impl());
EXPECT(ByteString("").impl() == ByteString::empty().impl());
}
TEST_CASE(construct_contents)
{
DeprecatedString test_string = "ABCDEF";
ByteString test_string = "ABCDEF";
EXPECT(!test_string.is_empty());
EXPECT_EQ(test_string.length(), 6u);
EXPECT_EQ(test_string.length(), strlen(test_string.characters()));
@ -39,45 +39,45 @@ TEST_CASE(construct_contents)
TEST_CASE(equal)
{
EXPECT_EQ(DeprecatedString::empty(), DeprecatedString {});
EXPECT_EQ(ByteString::empty(), ByteString {});
}
TEST_CASE(compare)
{
EXPECT("a"sv < DeprecatedString("b"));
EXPECT(!("a"sv > DeprecatedString("b")));
EXPECT("b"sv > DeprecatedString("a"));
EXPECT(!("b"sv < DeprecatedString("b")));
EXPECT("a"sv >= DeprecatedString("a"));
EXPECT(!("a"sv >= DeprecatedString("b")));
EXPECT("a"sv <= DeprecatedString("a"));
EXPECT(!("b"sv <= DeprecatedString("a")));
EXPECT("a"sv < ByteString("b"));
EXPECT(!("a"sv > ByteString("b")));
EXPECT("b"sv > ByteString("a"));
EXPECT(!("b"sv < ByteString("b")));
EXPECT("a"sv >= ByteString("a"));
EXPECT(!("a"sv >= ByteString("b")));
EXPECT("a"sv <= ByteString("a"));
EXPECT(!("b"sv <= ByteString("a")));
EXPECT(DeprecatedString("a") > DeprecatedString());
EXPECT(!(DeprecatedString() > DeprecatedString("a")));
EXPECT(DeprecatedString() < DeprecatedString("a"));
EXPECT(!(DeprecatedString("a") < DeprecatedString()));
EXPECT(DeprecatedString("a") >= DeprecatedString());
EXPECT(!(DeprecatedString() >= DeprecatedString("a")));
EXPECT(DeprecatedString() <= DeprecatedString("a"));
EXPECT(!(DeprecatedString("a") <= DeprecatedString()));
EXPECT(ByteString("a") > ByteString());
EXPECT(!(ByteString() > ByteString("a")));
EXPECT(ByteString() < ByteString("a"));
EXPECT(!(ByteString("a") < ByteString()));
EXPECT(ByteString("a") >= ByteString());
EXPECT(!(ByteString() >= ByteString("a")));
EXPECT(ByteString() <= ByteString("a"));
EXPECT(!(ByteString("a") <= ByteString()));
EXPECT(!(DeprecatedString() > DeprecatedString()));
EXPECT(!(DeprecatedString() < DeprecatedString()));
EXPECT(DeprecatedString() >= DeprecatedString());
EXPECT(DeprecatedString() <= DeprecatedString());
EXPECT(!(ByteString() > ByteString()));
EXPECT(!(ByteString() < ByteString()));
EXPECT(ByteString() >= ByteString());
EXPECT(ByteString() <= ByteString());
}
TEST_CASE(index_access)
{
DeprecatedString test_string = "ABCDEF";
ByteString test_string = "ABCDEF";
EXPECT_EQ(test_string[0], 'A');
EXPECT_EQ(test_string[1], 'B');
}
TEST_CASE(starts_with)
{
DeprecatedString test_string = "ABCDEF";
ByteString test_string = "ABCDEF";
EXPECT(test_string.starts_with("AB"sv));
EXPECT(test_string.starts_with('A'));
EXPECT(!test_string.starts_with('B'));
@ -89,7 +89,7 @@ TEST_CASE(starts_with)
TEST_CASE(ends_with)
{
DeprecatedString test_string = "ABCDEF";
ByteString test_string = "ABCDEF";
EXPECT(test_string.ends_with("EF"sv));
EXPECT(test_string.ends_with('F'));
EXPECT(!test_string.ends_with('E'));
@ -101,7 +101,7 @@ TEST_CASE(ends_with)
TEST_CASE(copy_string)
{
DeprecatedString test_string = "ABCDEF";
ByteString test_string = "ABCDEF";
auto test_string_copy = test_string;
EXPECT_EQ(test_string, test_string_copy);
EXPECT_EQ(test_string.characters(), test_string_copy.characters());
@ -109,7 +109,7 @@ TEST_CASE(copy_string)
TEST_CASE(move_string)
{
DeprecatedString test_string = "ABCDEF";
ByteString test_string = "ABCDEF";
auto test_string_copy = test_string;
auto test_string_move = move(test_string_copy);
EXPECT_EQ(test_string, test_string_move);
@ -118,25 +118,25 @@ TEST_CASE(move_string)
TEST_CASE(repeated)
{
EXPECT_EQ(DeprecatedString::repeated('x', 0), "");
EXPECT_EQ(DeprecatedString::repeated('x', 1), "x");
EXPECT_EQ(DeprecatedString::repeated('x', 2), "xx");
EXPECT_EQ(ByteString::repeated('x', 0), "");
EXPECT_EQ(ByteString::repeated('x', 1), "x");
EXPECT_EQ(ByteString::repeated('x', 2), "xx");
}
TEST_CASE(to_int)
{
EXPECT_EQ(DeprecatedString("123").to_int().value(), 123);
EXPECT_EQ(DeprecatedString("-123").to_int().value(), -123);
EXPECT_EQ(ByteString("123").to_int().value(), 123);
EXPECT_EQ(ByteString("-123").to_int().value(), -123);
}
TEST_CASE(to_lowercase)
{
EXPECT(DeprecatedString("ABC").to_lowercase() == "abc");
EXPECT(ByteString("ABC").to_lowercase() == "abc");
}
TEST_CASE(to_uppercase)
{
EXPECT(DeprecatedString("AbC").to_uppercase() == "ABC");
EXPECT(ByteString("AbC").to_uppercase() == "ABC");
}
TEST_CASE(flystring)
@ -148,12 +148,12 @@ TEST_CASE(flystring)
}
{
DeprecatedString a = "foo";
ByteString a = "foo";
DeprecatedFlyString b = a;
StringBuilder builder;
builder.append('f');
builder.append("oo"sv);
DeprecatedFlyString c = builder.to_deprecated_string();
DeprecatedFlyString c = builder.to_byte_string();
EXPECT_EQ(a.impl(), b.impl());
EXPECT_EQ(a.impl(), c.impl());
}
@ -161,7 +161,7 @@ TEST_CASE(flystring)
TEST_CASE(replace)
{
DeprecatedString test_string = "Well, hello Friends!";
ByteString test_string = "Well, hello Friends!";
test_string = test_string.replace("Friends"sv, "Testers"sv, ReplaceMode::FirstOnly);
EXPECT(test_string == "Well, hello Testers!");
@ -172,7 +172,7 @@ TEST_CASE(replace)
test_string = test_string.replace("!"sv, " :^)"sv, ReplaceMode::FirstOnly);
EXPECT(test_string == "We're, he'reo Testers :^)");
test_string = DeprecatedString("111._.111._.111");
test_string = ByteString("111._.111._.111");
test_string = test_string.replace("111"sv, "|||"sv, ReplaceMode::All);
EXPECT(test_string == "|||._.|||._.|||");
@ -182,7 +182,7 @@ TEST_CASE(replace)
TEST_CASE(count)
{
DeprecatedString test_string = "Well, hello Friends!";
ByteString test_string = "Well, hello Friends!";
u32 count = test_string.count("Friends"sv);
EXPECT(count == 1);
@ -192,7 +192,7 @@ TEST_CASE(count)
count = test_string.count("!"sv);
EXPECT(count == 1);
test_string = DeprecatedString("111._.111._.111");
test_string = ByteString("111._.111._.111");
count = test_string.count("111"sv);
EXPECT(count == 3);
@ -202,7 +202,7 @@ TEST_CASE(count)
TEST_CASE(substring)
{
DeprecatedString test = "abcdef";
ByteString test = "abcdef";
EXPECT_EQ(test.substring(0, 6), test);
EXPECT_EQ(test.substring(0, 3), "abc");
EXPECT_EQ(test.substring(3, 3), "def");
@ -212,7 +212,7 @@ TEST_CASE(substring)
TEST_CASE(split)
{
DeprecatedString test = "foo bar baz";
ByteString test = "foo bar baz";
auto parts = test.split(' ');
EXPECT_EQ(parts.size(), 3u);
EXPECT_EQ(parts[0], "foo");
@ -249,13 +249,13 @@ TEST_CASE(builder_zero_initial_capacity)
{
StringBuilder builder(0);
builder.append(""sv);
auto built = builder.to_deprecated_string();
auto built = builder.to_byte_string();
EXPECT_EQ(built.length(), 0u);
}
TEST_CASE(find)
{
DeprecatedString a = "foobarbar";
ByteString a = "foobarbar";
EXPECT_EQ(a.find("bar"sv), Optional<size_t> { 3 });
EXPECT_EQ(a.find("baz"sv), Optional<size_t> {});
EXPECT_EQ(a.find("bar"sv, 4), Optional<size_t> { 6 });
@ -271,7 +271,7 @@ TEST_CASE(find)
TEST_CASE(find_with_empty_needle)
{
DeprecatedString string = "";
ByteString string = "";
EXPECT_EQ(string.find(""sv), 0u);
EXPECT_EQ(string.find_all(""sv), (Vector<size_t> { 0u }));
@ -282,33 +282,33 @@ TEST_CASE(find_with_empty_needle)
TEST_CASE(bijective_base)
{
EXPECT_EQ(DeprecatedString::bijective_base_from(0), "A");
EXPECT_EQ(DeprecatedString::bijective_base_from(25), "Z");
EXPECT_EQ(DeprecatedString::bijective_base_from(26), "AA");
EXPECT_EQ(DeprecatedString::bijective_base_from(52), "BA");
EXPECT_EQ(DeprecatedString::bijective_base_from(701), "ZZ");
EXPECT_EQ(DeprecatedString::bijective_base_from(702), "AAA");
EXPECT_EQ(DeprecatedString::bijective_base_from(730), "ABC");
EXPECT_EQ(DeprecatedString::bijective_base_from(18277), "ZZZ");
EXPECT_EQ(ByteString::bijective_base_from(0), "A");
EXPECT_EQ(ByteString::bijective_base_from(25), "Z");
EXPECT_EQ(ByteString::bijective_base_from(26), "AA");
EXPECT_EQ(ByteString::bijective_base_from(52), "BA");
EXPECT_EQ(ByteString::bijective_base_from(701), "ZZ");
EXPECT_EQ(ByteString::bijective_base_from(702), "AAA");
EXPECT_EQ(ByteString::bijective_base_from(730), "ABC");
EXPECT_EQ(ByteString::bijective_base_from(18277), "ZZZ");
}
TEST_CASE(roman_numerals)
{
auto zero = DeprecatedString::roman_number_from(0);
auto zero = ByteString::roman_number_from(0);
EXPECT_EQ(zero, "");
auto one = DeprecatedString::roman_number_from(1);
auto one = ByteString::roman_number_from(1);
EXPECT_EQ(one, "I");
auto nine = DeprecatedString::roman_number_from(9);
auto nine = ByteString::roman_number_from(9);
EXPECT_EQ(nine, "IX");
auto fourty_eight = DeprecatedString::roman_number_from(48);
auto fourty_eight = ByteString::roman_number_from(48);
EXPECT_EQ(fourty_eight, "XLVIII");
auto one_thousand_nine_hundred_ninety_eight = DeprecatedString::roman_number_from(1998);
auto one_thousand_nine_hundred_ninety_eight = ByteString::roman_number_from(1998);
EXPECT_EQ(one_thousand_nine_hundred_ninety_eight, "MCMXCVIII");
auto four_thousand = DeprecatedString::roman_number_from(4000);
auto four_thousand = ByteString::roman_number_from(4000);
EXPECT_EQ(four_thousand, "4000");
}

View file

@ -6,8 +6,8 @@
#include <LibTest/TestCase.h>
#include <AK/ByteString.h>
#include <AK/CircularDeque.h>
#include <AK/DeprecatedString.h>
#include <AK/StdLibExtras.h>
TEST_CASE(enqueue_begin)
@ -37,9 +37,9 @@ TEST_CASE(enqueue_begin)
TEST_CASE(enqueue_begin_being_moved_from)
{
CircularDeque<DeprecatedString, 2> strings;
CircularDeque<ByteString, 2> strings;
DeprecatedString str { "test" };
ByteString str { "test" };
strings.enqueue_begin(move(str));
EXPECT(str.is_empty());
}

View file

@ -6,8 +6,8 @@
#include <LibTest/TestCase.h>
#include <AK/ByteString.h>
#include <AK/CircularQueue.h>
#include <AK/DeprecatedString.h>
TEST_CASE(basic)
{
@ -28,7 +28,7 @@ TEST_CASE(basic)
TEST_CASE(complex_type)
{
CircularQueue<DeprecatedString, 2> strings;
CircularQueue<ByteString, 2> strings;
strings.enqueue("ABC");
strings.enqueue("DEF");
@ -44,7 +44,7 @@ TEST_CASE(complex_type)
TEST_CASE(complex_type_clear)
{
CircularQueue<DeprecatedString, 5> strings;
CircularQueue<ByteString, 5> strings;
strings.enqueue("xxx");
strings.enqueue("xxx");
strings.enqueue("xxx");

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/DisjointChunks.h>
#include <AK/FixedArray.h>
#include <AK/Vector.h>

View file

@ -168,134 +168,134 @@ TEST_CASE(cast)
TEST_CASE(formatter)
{
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(123.456)), "123.455993"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-123.456)), "-123.455993"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<4>(123.456)), "123.4375"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<4>(-123.456)), "-123.4375"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16> {}), "0"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(0.1)), "0.100006"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(0.02)), "0.020004"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(0.003)), "0.003005"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(0.0004)), "0.000396"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(0.0000000005)), "0"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.1)), "-0.100006"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.02)), "-0.020004"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", FixedPoint<16>(-0.0000000005)), "0"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16>(123.456)), "123.455993"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16>(-123.456)), "-123.455993"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<4>(123.456)), "123.4375"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<4>(-123.456)), "-123.4375"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16> {}), "0"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16>(0.1)), "0.100006"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16>(0.02)), "0.020004"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16>(0.003)), "0.003005"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16>(0.0004)), "0.000396"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16>(0.0000000005)), "0"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16>(-0.1)), "-0.100006"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16>(-0.02)), "-0.020004"sv);
EXPECT_EQ(ByteString::formatted("{}", FixedPoint<16>(-0.0000000005)), "0"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", Type(-1)), "-1"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", Type(-2)), "-2"sv);
EXPECT_EQ(DeprecatedString::formatted("{}", Type(-3)), "-3"sv);
EXPECT_EQ(ByteString::formatted("{}", Type(-1)), "-1"sv);
EXPECT_EQ(ByteString::formatted("{}", Type(-2)), "-2"sv);
EXPECT_EQ(ByteString::formatted("{}", Type(-3)), "-3"sv);
// exact representation
EXPECT_EQ(DeprecatedString::formatted("{:.30}", FixedPoint<16>(123.456)), "123.45599365234375"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30}", FixedPoint<16>(-0.1)), "-0.100006103515625"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30}", FixedPoint<16>(-0.02)), "-0.0200042724609375"sv);
EXPECT_EQ(ByteString::formatted("{:.30}", FixedPoint<16>(123.456)), "123.45599365234375"sv);
EXPECT_EQ(ByteString::formatted("{:.30}", FixedPoint<16>(-0.1)), "-0.100006103515625"sv);
EXPECT_EQ(ByteString::formatted("{:.30}", FixedPoint<16>(-0.02)), "-0.0200042724609375"sv);
// maximum fraction per precision; 1 - 2^-precision
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<7, u64>::create_raw((1ull << 7) - 1)), "0.99218750000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<8, u64>::create_raw((1ull << 8) - 1)), "0.99609375000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<9, u64>::create_raw((1ull << 9) - 1)), "0.99804687500000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<10, u64>::create_raw((1ull << 10) - 1)), "0.99902343750000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<11, u64>::create_raw((1ull << 11) - 1)), "0.99951171875000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<12, u64>::create_raw((1ull << 12) - 1)), "0.99975585937500000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<13, u64>::create_raw((1ull << 13) - 1)), "0.99987792968750000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<14, u64>::create_raw((1ull << 14) - 1)), "0.99993896484375000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<15, u64>::create_raw((1ull << 15) - 1)), "0.99996948242187500000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<16, u64>::create_raw((1ull << 16) - 1)), "0.99998474121093750000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<17, u64>::create_raw((1ull << 17) - 1)), "0.99999237060546875000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<18, u64>::create_raw((1ull << 18) - 1)), "0.99999618530273437500"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.20}", AK::FixedPoint<19, u64>::create_raw((1ull << 19) - 1)), "0.99999809265136718750"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<7, u64>::create_raw((1ull << 7) - 1)), "0.99218750000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<8, u64>::create_raw((1ull << 8) - 1)), "0.99609375000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<9, u64>::create_raw((1ull << 9) - 1)), "0.99804687500000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<10, u64>::create_raw((1ull << 10) - 1)), "0.99902343750000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<11, u64>::create_raw((1ull << 11) - 1)), "0.99951171875000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<12, u64>::create_raw((1ull << 12) - 1)), "0.99975585937500000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<13, u64>::create_raw((1ull << 13) - 1)), "0.99987792968750000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<14, u64>::create_raw((1ull << 14) - 1)), "0.99993896484375000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<15, u64>::create_raw((1ull << 15) - 1)), "0.99996948242187500000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<16, u64>::create_raw((1ull << 16) - 1)), "0.99998474121093750000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<17, u64>::create_raw((1ull << 17) - 1)), "0.99999237060546875000"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<18, u64>::create_raw((1ull << 18) - 1)), "0.99999618530273437500"sv);
EXPECT_EQ(ByteString::formatted("{:0.20}", AK::FixedPoint<19, u64>::create_raw((1ull << 19) - 1)), "0.99999809265136718750"sv);
// maximum factor and precision >= 20 bits/digits will overflow u64: (5^20)*(2^20 - 1) > 2^64
// EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<20, u64>::create_raw((1ull << 20) - 1)), "0.99999904632568359375"sv);
// EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<20, u64>::create_raw((1ull << 20) - 1)), "0.99999904632568359375"sv);
// minimum fraction per precision; 2^-precision
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<7, u64>::create_raw(1)), "0.007812500000000000000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<8, u64>::create_raw(1)), "0.003906250000000000000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<9, u64>::create_raw(1)), "0.001953125000000000000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<10, u64>::create_raw(1)), "0.000976562500000000000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<11, u64>::create_raw(1)), "0.000488281250000000000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<12, u64>::create_raw(1)), "0.000244140625000000000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<13, u64>::create_raw(1)), "0.000122070312500000000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<14, u64>::create_raw(1)), "0.000061035156250000000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<15, u64>::create_raw(1)), "0.000030517578125000000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<16, u64>::create_raw(1)), "0.000015258789062500000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<17, u64>::create_raw(1)), "0.000007629394531250000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<18, u64>::create_raw(1)), "0.000003814697265625000000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<19, u64>::create_raw(1)), "0.000001907348632812500000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<20, u64>::create_raw(1)), "0.000000953674316406250000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<21, u64>::create_raw(1)), "0.000000476837158203125000000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<22, u64>::create_raw(1)), "0.000000238418579101562500000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<23, u64>::create_raw(1)), "0.000000119209289550781250000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<24, u64>::create_raw(1)), "0.000000059604644775390625000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<25, u64>::create_raw(1)), "0.000000029802322387695312500000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<26, u64>::create_raw(1)), "0.000000014901161193847656250000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<27, u64>::create_raw(1)), "0.000000007450580596923828125000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<7, u64>::create_raw(1)), "0.007812500000000000000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<8, u64>::create_raw(1)), "0.003906250000000000000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<9, u64>::create_raw(1)), "0.001953125000000000000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<10, u64>::create_raw(1)), "0.000976562500000000000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<11, u64>::create_raw(1)), "0.000488281250000000000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<12, u64>::create_raw(1)), "0.000244140625000000000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<13, u64>::create_raw(1)), "0.000122070312500000000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<14, u64>::create_raw(1)), "0.000061035156250000000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<15, u64>::create_raw(1)), "0.000030517578125000000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<16, u64>::create_raw(1)), "0.000015258789062500000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<17, u64>::create_raw(1)), "0.000007629394531250000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<18, u64>::create_raw(1)), "0.000003814697265625000000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<19, u64>::create_raw(1)), "0.000001907348632812500000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<20, u64>::create_raw(1)), "0.000000953674316406250000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<21, u64>::create_raw(1)), "0.000000476837158203125000000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<22, u64>::create_raw(1)), "0.000000238418579101562500000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<23, u64>::create_raw(1)), "0.000000119209289550781250000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<24, u64>::create_raw(1)), "0.000000059604644775390625000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<25, u64>::create_raw(1)), "0.000000029802322387695312500000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<26, u64>::create_raw(1)), "0.000000014901161193847656250000"sv);
EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<27, u64>::create_raw(1)), "0.000000007450580596923828125000"sv);
// minimum factor and precision >= 28 bits/digits will overflow u64: (5^28)*(1) > 2^64
// EXPECT_EQ(DeprecatedString::formatted("{:0.30}", AK::FixedPoint<28, u64>::create_raw(1)), "0.000000003725290298461914062500"sv);
// EXPECT_EQ(ByteString::formatted("{:0.30}", AK::FixedPoint<28, u64>::create_raw(1)), "0.000000003725290298461914062500"sv);
EXPECT_EQ(DeprecatedString::formatted("{:a}", FixedPoint<16>(42.42)), "2a.6b85"sv);
EXPECT_EQ(DeprecatedString::formatted("{:o}", FixedPoint<16>(42.42)), "52.327024"sv);
EXPECT_EQ(DeprecatedString::formatted("{:b}", FixedPoint<16>(42.42)), "101010.01101"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.10a}", FixedPoint<16>(69.69)), "45.b0a4000000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.10o}", FixedPoint<16>(69.69)), "105.5412200000"sv);
EXPECT_EQ(DeprecatedString::formatted("{:0.10b}", FixedPoint<16>(69.69)), "1000101.1011000010"sv);
EXPECT_EQ(ByteString::formatted("{:a}", FixedPoint<16>(42.42)), "2a.6b85"sv);
EXPECT_EQ(ByteString::formatted("{:o}", FixedPoint<16>(42.42)), "52.327024"sv);
EXPECT_EQ(ByteString::formatted("{:b}", FixedPoint<16>(42.42)), "101010.01101"sv);
EXPECT_EQ(ByteString::formatted("{:0.10a}", FixedPoint<16>(69.69)), "45.b0a4000000"sv);
EXPECT_EQ(ByteString::formatted("{:0.10o}", FixedPoint<16>(69.69)), "105.5412200000"sv);
EXPECT_EQ(ByteString::formatted("{:0.10b}", FixedPoint<16>(69.69)), "1000101.1011000010"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30o}", AK::FixedPoint<13, u64>::create_raw(1)), "0.00004"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30b}", AK::FixedPoint<13, u64>::create_raw(1)), "0.0000000000001"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30o}", AK::FixedPoint<21, u64>::create_raw(0211234567)), "21.1234567"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30b}", AK::FixedPoint<13, u64>::create_raw(0b110011011010110)), "11.001101101011"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30o}", AK::FixedPoint<11, u64>::create_raw((1ull << 11) - 1)), "0.7776"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30b}", AK::FixedPoint<11, u64>::create_raw((1ull << 11) - 1)), "0.11111111111"sv);
EXPECT_EQ(ByteString::formatted("{:.30o}", AK::FixedPoint<13, u64>::create_raw(1)), "0.00004"sv);
EXPECT_EQ(ByteString::formatted("{:.30b}", AK::FixedPoint<13, u64>::create_raw(1)), "0.0000000000001"sv);
EXPECT_EQ(ByteString::formatted("{:.30o}", AK::FixedPoint<21, u64>::create_raw(0211234567)), "21.1234567"sv);
EXPECT_EQ(ByteString::formatted("{:.30b}", AK::FixedPoint<13, u64>::create_raw(0b110011011010110)), "11.001101101011"sv);
EXPECT_EQ(ByteString::formatted("{:.30o}", AK::FixedPoint<11, u64>::create_raw((1ull << 11) - 1)), "0.7776"sv);
EXPECT_EQ(ByteString::formatted("{:.30b}", AK::FixedPoint<11, u64>::create_raw((1ull << 11) - 1)), "0.11111111111"sv);
// maximum fraction per precision rendered in hexadecimal; 1 - 2^-precision; no overflow
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<7, u64>::create_raw((1ull << 7) - 1)), "0.fe"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<8, u64>::create_raw((1ull << 8) - 1)), "0.ff"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<9, u64>::create_raw((1ull << 9) - 1)), "0.ff8"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<10, u64>::create_raw((1ull << 10) - 1)), "0.ffc"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<11, u64>::create_raw((1ull << 11) - 1)), "0.ffe"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<12, u64>::create_raw((1ull << 12) - 1)), "0.fff"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<13, u64>::create_raw((1ull << 13) - 1)), "0.fff8"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<14, u64>::create_raw((1ull << 14) - 1)), "0.fffc"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<15, u64>::create_raw((1ull << 15) - 1)), "0.fffe"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<16, u64>::create_raw((1ull << 16) - 1)), "0.ffff"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<17, u64>::create_raw((1ull << 17) - 1)), "0.ffff8"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<18, u64>::create_raw((1ull << 18) - 1)), "0.ffffc"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<19, u64>::create_raw((1ull << 19) - 1)), "0.ffffe"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<20, u64>::create_raw((1ull << 20) - 1)), "0.fffff"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<21, u64>::create_raw((1ull << 21) - 1)), "0.fffff8"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<7, u64>::create_raw((1ull << 7) - 1)), "0.fe"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<8, u64>::create_raw((1ull << 8) - 1)), "0.ff"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<9, u64>::create_raw((1ull << 9) - 1)), "0.ff8"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<10, u64>::create_raw((1ull << 10) - 1)), "0.ffc"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<11, u64>::create_raw((1ull << 11) - 1)), "0.ffe"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<12, u64>::create_raw((1ull << 12) - 1)), "0.fff"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<13, u64>::create_raw((1ull << 13) - 1)), "0.fff8"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<14, u64>::create_raw((1ull << 14) - 1)), "0.fffc"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<15, u64>::create_raw((1ull << 15) - 1)), "0.fffe"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<16, u64>::create_raw((1ull << 16) - 1)), "0.ffff"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<17, u64>::create_raw((1ull << 17) - 1)), "0.ffff8"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<18, u64>::create_raw((1ull << 18) - 1)), "0.ffffc"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<19, u64>::create_raw((1ull << 19) - 1)), "0.ffffe"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<20, u64>::create_raw((1ull << 20) - 1)), "0.fffff"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<21, u64>::create_raw((1ull << 21) - 1)), "0.fffff8"sv);
// ...skip some precisions
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<56, u64>::create_raw((1ull << 56) - 1)), "0.ffffffffffffff"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<57, u64>::create_raw((1ull << 57) - 1)), "0.ffffffffffffff8"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<58, u64>::create_raw((1ull << 58) - 1)), "0.ffffffffffffffc"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<59, u64>::create_raw((1ull << 59) - 1)), "0.ffffffffffffffe"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<60, u64>::create_raw((1ull << 60) - 1)), "0.fffffffffffffff"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<61, u64>::create_raw((1ull << 61) - 1)), "0.fffffffffffffff8"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<62, u64>::create_raw((1ull << 62) - 1)), "0.fffffffffffffffc"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<63, u64>::create_raw((1ull << 63) - 1)), "0.fffffffffffffffe"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<56, u64>::create_raw((1ull << 56) - 1)), "0.ffffffffffffff"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<57, u64>::create_raw((1ull << 57) - 1)), "0.ffffffffffffff8"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<58, u64>::create_raw((1ull << 58) - 1)), "0.ffffffffffffffc"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<59, u64>::create_raw((1ull << 59) - 1)), "0.ffffffffffffffe"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<60, u64>::create_raw((1ull << 60) - 1)), "0.fffffffffffffff"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<61, u64>::create_raw((1ull << 61) - 1)), "0.fffffffffffffff8"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<62, u64>::create_raw((1ull << 62) - 1)), "0.fffffffffffffffc"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<63, u64>::create_raw((1ull << 63) - 1)), "0.fffffffffffffffe"sv);
// minimum fraction per precision rendered in hexadecimal; 2^-precision; no overflow
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<7, u64>::create_raw(1)), "0.02"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<8, u64>::create_raw(1)), "0.01"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<9, u64>::create_raw(1)), "0.008"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<10, u64>::create_raw(1)), "0.004"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<11, u64>::create_raw(1)), "0.002"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<12, u64>::create_raw(1)), "0.001"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<13, u64>::create_raw(1)), "0.0008"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<14, u64>::create_raw(1)), "0.0004"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<15, u64>::create_raw(1)), "0.0002"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<16, u64>::create_raw(1)), "0.0001"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<17, u64>::create_raw(1)), "0.00008"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<18, u64>::create_raw(1)), "0.00004"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<19, u64>::create_raw(1)), "0.00002"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<20, u64>::create_raw(1)), "0.00001"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<21, u64>::create_raw(1)), "0.000008"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<7, u64>::create_raw(1)), "0.02"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<8, u64>::create_raw(1)), "0.01"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<9, u64>::create_raw(1)), "0.008"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<10, u64>::create_raw(1)), "0.004"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<11, u64>::create_raw(1)), "0.002"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<12, u64>::create_raw(1)), "0.001"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<13, u64>::create_raw(1)), "0.0008"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<14, u64>::create_raw(1)), "0.0004"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<15, u64>::create_raw(1)), "0.0002"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<16, u64>::create_raw(1)), "0.0001"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<17, u64>::create_raw(1)), "0.00008"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<18, u64>::create_raw(1)), "0.00004"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<19, u64>::create_raw(1)), "0.00002"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<20, u64>::create_raw(1)), "0.00001"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<21, u64>::create_raw(1)), "0.000008"sv);
// ..skip some precisions
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<56, u64>::create_raw(1)), "0.00000000000001"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<57, u64>::create_raw(1)), "0.000000000000008"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<58, u64>::create_raw(1)), "0.000000000000004"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<59, u64>::create_raw(1)), "0.000000000000002"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<60, u64>::create_raw(1)), "0.000000000000001"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<61, u64>::create_raw(1)), "0.0000000000000008"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<62, u64>::create_raw(1)), "0.0000000000000004"sv);
EXPECT_EQ(DeprecatedString::formatted("{:.30a}", AK::FixedPoint<63, u64>::create_raw(1)), "0.0000000000000002"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<56, u64>::create_raw(1)), "0.00000000000001"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<57, u64>::create_raw(1)), "0.000000000000008"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<58, u64>::create_raw(1)), "0.000000000000004"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<59, u64>::create_raw(1)), "0.000000000000002"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<60, u64>::create_raw(1)), "0.000000000000001"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<61, u64>::create_raw(1)), "0.0000000000000008"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<62, u64>::create_raw(1)), "0.0000000000000004"sv);
EXPECT_EQ(ByteString::formatted("{:.30a}", AK::FixedPoint<63, u64>::create_raw(1)), "0.0000000000000002"sv);
}

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/StringBuilder.h>
#include <AK/Vector.h>
#include <math.h>
@ -20,55 +20,55 @@ TEST_CASE(is_integral_works_properly)
TEST_CASE(format_string_literals)
{
EXPECT_EQ(DeprecatedString::formatted("prefix-{}-suffix", "abc"), "prefix-abc-suffix");
EXPECT_EQ(DeprecatedString::formatted("{}{}{}", "a", "b", "c"), "abc");
EXPECT_EQ(ByteString::formatted("prefix-{}-suffix", "abc"), "prefix-abc-suffix");
EXPECT_EQ(ByteString::formatted("{}{}{}", "a", "b", "c"), "abc");
}
TEST_CASE(format_integers)
{
EXPECT_EQ(DeprecatedString::formatted("{}", 42u), "42");
EXPECT_EQ(DeprecatedString::formatted("{:4}", 42u), " 42");
EXPECT_EQ(DeprecatedString::formatted("{:08}", 42u), "00000042");
EXPECT_EQ(DeprecatedString::formatted("{:7}", -17), " -17");
EXPECT_EQ(DeprecatedString::formatted("{}", -17), "-17");
EXPECT_EQ(DeprecatedString::formatted("{:04}", 13), "0013");
EXPECT_EQ(DeprecatedString::formatted("{:08x}", 4096), "00001000");
EXPECT_EQ(DeprecatedString::formatted("{:x}", 0x1111222233334444ull), "1111222233334444");
EXPECT_EQ(DeprecatedString::formatted("{:4}", 12345678), "12345678");
EXPECT_EQ(DeprecatedString::formatted("{}", AK::NumericLimits<i64>::min()), "-9223372036854775808");
EXPECT_EQ(DeprecatedString::formatted("{:x}", AK::NumericLimits<i64>::min()), "-8000000000000000");
EXPECT_EQ(DeprecatedString::formatted("{:'}", 0), "0");
EXPECT_EQ(DeprecatedString::formatted("{:'}", 4096), "4,096");
EXPECT_EQ(DeprecatedString::formatted("{:'}", 16777216), "16,777,216");
EXPECT_EQ(DeprecatedString::formatted("{:'}", AK::NumericLimits<u64>::max()), "18,446,744,073,709,551,615");
EXPECT_EQ(DeprecatedString::formatted("{:'}", AK::NumericLimits<u64>::max()), "18,446,744,073,709,551,615");
EXPECT_EQ(DeprecatedString::formatted("{:'}", AK::NumericLimits<i64>::min() + 1), "-9,223,372,036,854,775,807");
EXPECT_EQ(DeprecatedString::formatted("{:'x}", 0), "0");
EXPECT_EQ(DeprecatedString::formatted("{:'x}", 16777216), "1,000,000");
EXPECT_EQ(DeprecatedString::formatted("{:'x}", AK::NumericLimits<u64>::max()), "f,fff,fff,fff,fff,fff");
EXPECT_EQ(DeprecatedString::formatted("{:'x}", AK::NumericLimits<i64>::min() + 1), "-7,fff,fff,fff,fff,fff");
EXPECT_EQ(DeprecatedString::formatted("{:'b}", AK::NumericLimits<u64>::max()), "1,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111");
EXPECT_EQ(ByteString::formatted("{}", 42u), "42");
EXPECT_EQ(ByteString::formatted("{:4}", 42u), " 42");
EXPECT_EQ(ByteString::formatted("{:08}", 42u), "00000042");
EXPECT_EQ(ByteString::formatted("{:7}", -17), " -17");
EXPECT_EQ(ByteString::formatted("{}", -17), "-17");
EXPECT_EQ(ByteString::formatted("{:04}", 13), "0013");
EXPECT_EQ(ByteString::formatted("{:08x}", 4096), "00001000");
EXPECT_EQ(ByteString::formatted("{:x}", 0x1111222233334444ull), "1111222233334444");
EXPECT_EQ(ByteString::formatted("{:4}", 12345678), "12345678");
EXPECT_EQ(ByteString::formatted("{}", AK::NumericLimits<i64>::min()), "-9223372036854775808");
EXPECT_EQ(ByteString::formatted("{:x}", AK::NumericLimits<i64>::min()), "-8000000000000000");
EXPECT_EQ(ByteString::formatted("{:'}", 0), "0");
EXPECT_EQ(ByteString::formatted("{:'}", 4096), "4,096");
EXPECT_EQ(ByteString::formatted("{:'}", 16777216), "16,777,216");
EXPECT_EQ(ByteString::formatted("{:'}", AK::NumericLimits<u64>::max()), "18,446,744,073,709,551,615");
EXPECT_EQ(ByteString::formatted("{:'}", AK::NumericLimits<u64>::max()), "18,446,744,073,709,551,615");
EXPECT_EQ(ByteString::formatted("{:'}", AK::NumericLimits<i64>::min() + 1), "-9,223,372,036,854,775,807");
EXPECT_EQ(ByteString::formatted("{:'x}", 0), "0");
EXPECT_EQ(ByteString::formatted("{:'x}", 16777216), "1,000,000");
EXPECT_EQ(ByteString::formatted("{:'x}", AK::NumericLimits<u64>::max()), "f,fff,fff,fff,fff,fff");
EXPECT_EQ(ByteString::formatted("{:'x}", AK::NumericLimits<i64>::min() + 1), "-7,fff,fff,fff,fff,fff");
EXPECT_EQ(ByteString::formatted("{:'b}", AK::NumericLimits<u64>::max()), "1,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111");
}
TEST_CASE(reorder_format_arguments)
{
EXPECT_EQ(DeprecatedString::formatted("{1}{0}", "a", "b"), "ba");
EXPECT_EQ(DeprecatedString::formatted("{0}{1}", "a", "b"), "ab");
EXPECT_EQ(ByteString::formatted("{1}{0}", "a", "b"), "ba");
EXPECT_EQ(ByteString::formatted("{0}{1}", "a", "b"), "ab");
// Compiletime check bypass: ignoring a passed argument.
EXPECT_EQ(DeprecatedString::formatted("{0}{0}{0}"sv, "a", "b"), "aaa");
EXPECT_EQ(ByteString::formatted("{0}{0}{0}"sv, "a", "b"), "aaa");
// Compiletime check bypass: ignoring a passed argument.
EXPECT_EQ(DeprecatedString::formatted("{1}{}{0}"sv, "a", "b", "c"), "baa");
EXPECT_EQ(ByteString::formatted("{1}{}{0}"sv, "a", "b", "c"), "baa");
}
TEST_CASE(escape_braces)
{
EXPECT_EQ(DeprecatedString::formatted("{{{}", "foo"), "{foo");
EXPECT_EQ(DeprecatedString::formatted("{}}}", "bar"), "bar}");
EXPECT_EQ(ByteString::formatted("{{{}", "foo"), "{foo");
EXPECT_EQ(ByteString::formatted("{}}}", "bar"), "bar}");
}
TEST_CASE(everything)
{
EXPECT_EQ(DeprecatedString::formatted("{{{:04}/{}/{0:8}/{1}", 42u, "foo"), "{0042/foo/ 42/foo");
EXPECT_EQ(ByteString::formatted("{{{:04}/{}/{0:8}/{1}", 42u, "foo"), "{0042/foo/ 42/foo");
}
TEST_CASE(string_builder)
@ -77,92 +77,92 @@ TEST_CASE(string_builder)
builder.appendff(" {} ", 42);
builder.appendff("{1}{0} ", 1, 2);
EXPECT_EQ(builder.to_deprecated_string(), " 42 21 ");
EXPECT_EQ(builder.to_byte_string(), " 42 21 ");
}
TEST_CASE(format_without_arguments)
{
EXPECT_EQ(DeprecatedString::formatted("foo"), "foo");
EXPECT_EQ(ByteString::formatted("foo"), "foo");
}
TEST_CASE(format_upper_case_integer)
{
EXPECT_EQ(DeprecatedString::formatted("{:4X}", 0xff), " FF");
EXPECT_EQ(DeprecatedString::formatted("{:#4X}", 0xff), "0XFF");
EXPECT_EQ(ByteString::formatted("{:4X}", 0xff), " FF");
EXPECT_EQ(ByteString::formatted("{:#4X}", 0xff), "0XFF");
EXPECT_EQ(DeprecatedString::formatted("{:b}", 0xff), "11111111");
EXPECT_EQ(DeprecatedString::formatted("{:B}", 0xff), "11111111");
EXPECT_EQ(DeprecatedString::formatted("{:#b}", 0xff), "0b11111111");
EXPECT_EQ(ByteString::formatted("{:b}", 0xff), "11111111");
EXPECT_EQ(ByteString::formatted("{:B}", 0xff), "11111111");
EXPECT_EQ(ByteString::formatted("{:#b}", 0xff), "0b11111111");
}
TEST_CASE(format_aligned)
{
EXPECT_EQ(DeprecatedString::formatted("{:*<8}", 13), "13******");
EXPECT_EQ(DeprecatedString::formatted("{:*^8}", 13), "***13***");
EXPECT_EQ(DeprecatedString::formatted("{:*>8}", 13), "******13");
EXPECT_EQ(DeprecatedString::formatted("{:*>+8}", 13), "*****+13");
EXPECT_EQ(DeprecatedString::formatted("{:*^ 8}", 13), "** 13***");
EXPECT_EQ(ByteString::formatted("{:*<8}", 13), "13******");
EXPECT_EQ(ByteString::formatted("{:*^8}", 13), "***13***");
EXPECT_EQ(ByteString::formatted("{:*>8}", 13), "******13");
EXPECT_EQ(ByteString::formatted("{:*>+8}", 13), "*****+13");
EXPECT_EQ(ByteString::formatted("{:*^ 8}", 13), "** 13***");
}
TEST_CASE(format_octal)
{
EXPECT_EQ(DeprecatedString::formatted("{:o}", 0744), "744");
EXPECT_EQ(DeprecatedString::formatted("{:#o}", 0744), "0744");
EXPECT_EQ(DeprecatedString::formatted("{:'o}", 054321), "54,321");
EXPECT_EQ(DeprecatedString::formatted("{:'o}", 0567012340), "567,012,340");
EXPECT_EQ(ByteString::formatted("{:o}", 0744), "744");
EXPECT_EQ(ByteString::formatted("{:#o}", 0744), "0744");
EXPECT_EQ(ByteString::formatted("{:'o}", 054321), "54,321");
EXPECT_EQ(ByteString::formatted("{:'o}", 0567012340), "567,012,340");
}
TEST_CASE(zero_pad)
{
EXPECT_EQ(DeprecatedString::formatted("{: <010}", 42), "42 ");
EXPECT_EQ(DeprecatedString::formatted("{:010}", 42), "0000000042");
EXPECT_EQ(DeprecatedString::formatted("{:/^010}", 42), "////42////");
EXPECT_EQ(DeprecatedString::formatted("{:04x}", -32), "-0020");
EXPECT_EQ(DeprecatedString::formatted("{:#06x}", -64), "-0x000040");
EXPECT_EQ(ByteString::formatted("{: <010}", 42), "42 ");
EXPECT_EQ(ByteString::formatted("{:010}", 42), "0000000042");
EXPECT_EQ(ByteString::formatted("{:/^010}", 42), "////42////");
EXPECT_EQ(ByteString::formatted("{:04x}", -32), "-0020");
EXPECT_EQ(ByteString::formatted("{:#06x}", -64), "-0x000040");
}
TEST_CASE(replacement_field)
{
EXPECT_EQ(DeprecatedString::formatted("{:*>{1}}", 13, static_cast<size_t>(10)), "********13");
EXPECT_EQ(DeprecatedString::formatted("{:*<{1}}", 7, 4), "7***");
EXPECT_EQ(ByteString::formatted("{:*>{1}}", 13, static_cast<size_t>(10)), "********13");
EXPECT_EQ(ByteString::formatted("{:*<{1}}", 7, 4), "7***");
// Compiletime check bypass: intentionally ignoring extra arguments
EXPECT_EQ(DeprecatedString::formatted("{:{2}}"sv, -5, 8, 16), " -5");
EXPECT_EQ(DeprecatedString::formatted("{{{:*^{1}}}}", 1, 3), "{*1*}");
EXPECT_EQ(DeprecatedString::formatted("{:0{}}", 1, 3), "001");
EXPECT_EQ(ByteString::formatted("{:{2}}"sv, -5, 8, 16), " -5");
EXPECT_EQ(ByteString::formatted("{{{:*^{1}}}}", 1, 3), "{*1*}");
EXPECT_EQ(ByteString::formatted("{:0{}}", 1, 3), "001");
}
TEST_CASE(replacement_field_regression)
{
// FIXME: Compiletime check bypass: cannot parse '}}' correctly.
EXPECT_EQ(DeprecatedString::formatted("{:{}}"sv, "", static_cast<unsigned long>(6)), " ");
EXPECT_EQ(ByteString::formatted("{:{}}"sv, "", static_cast<unsigned long>(6)), " ");
}
TEST_CASE(complex_string_specifiers)
{
EXPECT_EQ(DeprecatedString::formatted("{:.8}", "123456789"), "12345678");
EXPECT_EQ(DeprecatedString::formatted("{:9}", "abcd"), "abcd ");
EXPECT_EQ(DeprecatedString::formatted("{:>9}", "abcd"), " abcd");
EXPECT_EQ(DeprecatedString::formatted("{:^9}", "abcd"), " abcd ");
EXPECT_EQ(DeprecatedString::formatted("{:4.6}", "a"), "a ");
EXPECT_EQ(DeprecatedString::formatted("{:4.6}", "abcdef"), "abcdef");
EXPECT_EQ(DeprecatedString::formatted("{:4.6}", "abcdefghi"), "abcdef");
EXPECT_EQ(ByteString::formatted("{:.8}", "123456789"), "12345678");
EXPECT_EQ(ByteString::formatted("{:9}", "abcd"), "abcd ");
EXPECT_EQ(ByteString::formatted("{:>9}", "abcd"), " abcd");
EXPECT_EQ(ByteString::formatted("{:^9}", "abcd"), " abcd ");
EXPECT_EQ(ByteString::formatted("{:4.6}", "a"), "a ");
EXPECT_EQ(ByteString::formatted("{:4.6}", "abcdef"), "abcdef");
EXPECT_EQ(ByteString::formatted("{:4.6}", "abcdefghi"), "abcdef");
}
TEST_CASE(cast_integer_to_character)
{
EXPECT_EQ(DeprecatedString::formatted("{:c}", static_cast<int>('a')), "a");
EXPECT_EQ(DeprecatedString::formatted("{:c}", static_cast<unsigned int>('f')), "f");
EXPECT_EQ(ByteString::formatted("{:c}", static_cast<int>('a')), "a");
EXPECT_EQ(ByteString::formatted("{:c}", static_cast<unsigned int>('f')), "f");
}
TEST_CASE(boolean_values)
{
EXPECT_EQ(DeprecatedString::formatted("{}", true), "true");
EXPECT_EQ(DeprecatedString::formatted("{}", false), "false");
EXPECT_EQ(DeprecatedString::formatted("{:6}", true), "true ");
EXPECT_EQ(DeprecatedString::formatted("{:>4}", false), "false");
EXPECT_EQ(DeprecatedString::formatted("{:d}", false), "0");
EXPECT_EQ(DeprecatedString::formatted("{:d}", true), "1");
EXPECT_EQ(DeprecatedString::formatted("{:#08x}", true), "0x00000001");
EXPECT_EQ(ByteString::formatted("{}", true), "true");
EXPECT_EQ(ByteString::formatted("{}", false), "false");
EXPECT_EQ(ByteString::formatted("{:6}", true), "true ");
EXPECT_EQ(ByteString::formatted("{:>4}", false), "false");
EXPECT_EQ(ByteString::formatted("{:d}", false), "0");
EXPECT_EQ(ByteString::formatted("{:d}", true), "1");
EXPECT_EQ(ByteString::formatted("{:#08x}", true), "0x00000001");
}
TEST_CASE(pointers)
@ -170,13 +170,13 @@ TEST_CASE(pointers)
void* ptr = reinterpret_cast<void*>(0x4000);
if (sizeof(void*) == 4) {
EXPECT_EQ(DeprecatedString::formatted("{:p}", 32), "0x00000020");
EXPECT_EQ(DeprecatedString::formatted("{:p}", ptr), "0x00004000");
EXPECT_EQ(DeprecatedString::formatted("{}", ptr), "0x00004000");
EXPECT_EQ(ByteString::formatted("{:p}", 32), "0x00000020");
EXPECT_EQ(ByteString::formatted("{:p}", ptr), "0x00004000");
EXPECT_EQ(ByteString::formatted("{}", ptr), "0x00004000");
} else if (sizeof(void*) == 8) {
EXPECT_EQ(DeprecatedString::formatted("{:p}", 32), "0x0000000000000020");
EXPECT_EQ(DeprecatedString::formatted("{:p}", ptr), "0x0000000000004000");
EXPECT_EQ(DeprecatedString::formatted("{}", ptr), "0x0000000000004000");
EXPECT_EQ(ByteString::formatted("{:p}", 32), "0x0000000000000020");
EXPECT_EQ(ByteString::formatted("{:p}", ptr), "0x0000000000004000");
EXPECT_EQ(ByteString::formatted("{}", ptr), "0x0000000000004000");
} else {
VERIFY_NOT_REACHED();
}
@ -188,12 +188,12 @@ TEST_CASE(pointers)
// This is a bit scary, thus this test. At least this test should fail in this case.
TEST_CASE(ensure_that_format_works)
{
if (DeprecatedString::formatted("FAIL") != "FAIL") {
if (ByteString::formatted("FAIL") != "FAIL") {
fprintf(stderr, "FAIL\n");
exit(1);
}
if (DeprecatedString::formatted("{} FAIL {}", 1, 2) != "1 FAIL 2") {
if (ByteString::formatted("{} FAIL {}", 1, 2) != "1 FAIL 2") {
fprintf(stderr, "FAIL\n");
exit(1);
}
@ -202,13 +202,13 @@ TEST_CASE(ensure_that_format_works)
TEST_CASE(format_string_literal_as_pointer)
{
char const* literal = "abc";
EXPECT_EQ(DeprecatedString::formatted("{:p}", literal), DeprecatedString::formatted("{:p}", reinterpret_cast<FlatPtr>(literal)));
EXPECT_EQ(ByteString::formatted("{:p}", literal), ByteString::formatted("{:p}", reinterpret_cast<FlatPtr>(literal)));
}
TEST_CASE(format_character)
{
char a = 'a';
EXPECT_EQ(DeprecatedString::formatted("{}", true ? a : 'b'), "a");
EXPECT_EQ(ByteString::formatted("{}", true ? a : 'b'), "a");
}
struct A {
@ -225,8 +225,8 @@ struct AK::Formatter<B> : Formatter<StringView> {
TEST_CASE(format_if_supported)
{
EXPECT_EQ(DeprecatedString::formatted("{}", FormatIfSupported { A {} }), "?");
EXPECT_EQ(DeprecatedString::formatted("{}", FormatIfSupported { B {} }), "B");
EXPECT_EQ(ByteString::formatted("{}", FormatIfSupported { A {} }), "?");
EXPECT_EQ(ByteString::formatted("{}", FormatIfSupported { B {} }), "B");
}
TEST_CASE(file_descriptor)
@ -254,39 +254,39 @@ TEST_CASE(file_descriptor)
TEST_CASE(floating_point_numbers)
{
EXPECT_EQ(DeprecatedString::formatted("{}", 1.12), "1.12");
EXPECT_EQ(DeprecatedString::formatted("{}", 1.), "1");
EXPECT_EQ(DeprecatedString::formatted("{:.3}", 1.12), "1.12");
EXPECT_EQ(DeprecatedString::formatted("{:.1}", 1.12), "1.1");
EXPECT_EQ(DeprecatedString::formatted("{}", -1.12), "-1.12");
EXPECT_EQ(DeprecatedString::formatted("{:'.4}", 1234.5678), "1,234.5678");
EXPECT_EQ(DeprecatedString::formatted("{:'.4}", -1234.5678), "-1,234.5678");
EXPECT_EQ(ByteString::formatted("{}", 1.12), "1.12");
EXPECT_EQ(ByteString::formatted("{}", 1.), "1");
EXPECT_EQ(ByteString::formatted("{:.3}", 1.12), "1.12");
EXPECT_EQ(ByteString::formatted("{:.1}", 1.12), "1.1");
EXPECT_EQ(ByteString::formatted("{}", -1.12), "-1.12");
EXPECT_EQ(ByteString::formatted("{:'.4}", 1234.5678), "1,234.5678");
EXPECT_EQ(ByteString::formatted("{:'.4}", -1234.5678), "-1,234.5678");
EXPECT_EQ(DeprecatedString::formatted("{:.30f}", 1.0), "1.000000000000000000000000000000");
EXPECT_EQ(DeprecatedString::formatted("{:.30f}", 1.5), "1.500000000000000000000000000000");
EXPECT_EQ(DeprecatedString::formatted("{:.30f}", -2.0), "-2.000000000000000000000000000000");
EXPECT_EQ(ByteString::formatted("{:.30f}", 1.0), "1.000000000000000000000000000000");
EXPECT_EQ(ByteString::formatted("{:.30f}", 1.5), "1.500000000000000000000000000000");
EXPECT_EQ(ByteString::formatted("{:.30f}", -2.0), "-2.000000000000000000000000000000");
EXPECT_EQ(DeprecatedString::formatted("{:.0f}", 1.4), "1");
EXPECT_EQ(DeprecatedString::formatted("{:.0f}", 1.5), "2");
EXPECT_EQ(DeprecatedString::formatted("{:.0f}", -1.9), "-2");
EXPECT_EQ(ByteString::formatted("{:.0f}", 1.4), "1");
EXPECT_EQ(ByteString::formatted("{:.0f}", 1.5), "2");
EXPECT_EQ(ByteString::formatted("{:.0f}", -1.9), "-2");
EXPECT_EQ(DeprecatedString::formatted("{:.1f}", 1.4), "1.4");
EXPECT_EQ(DeprecatedString::formatted("{:.1f}", 1.99), "2.0");
EXPECT_EQ(DeprecatedString::formatted("{:.1f}", 9.999), "10.0");
EXPECT_EQ(ByteString::formatted("{:.1f}", 1.4), "1.4");
EXPECT_EQ(ByteString::formatted("{:.1f}", 1.99), "2.0");
EXPECT_EQ(ByteString::formatted("{:.1f}", 9.999), "10.0");
EXPECT_EQ(DeprecatedString::formatted("{}", NAN), "nan");
EXPECT_EQ(DeprecatedString::formatted("{}", INFINITY), "inf");
EXPECT_EQ(DeprecatedString::formatted("{}", -INFINITY), "-inf");
EXPECT_EQ(ByteString::formatted("{}", NAN), "nan");
EXPECT_EQ(ByteString::formatted("{}", INFINITY), "inf");
EXPECT_EQ(ByteString::formatted("{}", -INFINITY), "-inf");
// FIXME: There is always the question what we mean with the width field. Do we mean significant digits?
// Do we mean the whole width? This is what was the simplest to implement:
EXPECT_EQ(DeprecatedString::formatted("{:x>5.1}", 1.12), "xx1.1");
EXPECT_EQ(ByteString::formatted("{:x>5.1}", 1.12), "xx1.1");
}
TEST_CASE(floating_point_default_precision)
{
#define EXPECT_FORMAT(lit, value) \
EXPECT_EQ(DeprecatedString::formatted("{}", lit), value##sv)
EXPECT_EQ(ByteString::formatted("{}", lit), value##sv)
EXPECT_FORMAT(10.3f, "10.3");
EXPECT_FORMAT(123e4f, "1230000");
@ -307,24 +307,24 @@ TEST_CASE(floating_point_default_precision)
TEST_CASE(no_precision_no_trailing_number)
{
EXPECT_EQ(DeprecatedString::formatted("{:.0}", 0.1), "0");
EXPECT_EQ(ByteString::formatted("{:.0}", 0.1), "0");
}
TEST_CASE(precision_with_trailing_zeros)
{
EXPECT_EQ(DeprecatedString::formatted("{:0.3}", 1.12), "1.120");
EXPECT_EQ(DeprecatedString::formatted("{:0.1}", 1.12), "1.1");
EXPECT_EQ(ByteString::formatted("{:0.3}", 1.12), "1.120");
EXPECT_EQ(ByteString::formatted("{:0.1}", 1.12), "1.1");
}
TEST_CASE(magnitude_less_than_zero)
{
EXPECT_EQ(DeprecatedString::formatted("{}", -0.654), "-0.654");
EXPECT_EQ(DeprecatedString::formatted("{}", 0.654), "0.654");
EXPECT_EQ(ByteString::formatted("{}", -0.654), "-0.654");
EXPECT_EQ(ByteString::formatted("{}", 0.654), "0.654");
}
TEST_CASE(format_nullptr)
{
EXPECT_EQ(DeprecatedString::formatted("{}", nullptr), DeprecatedString::formatted("{:p}", static_cast<FlatPtr>(0)));
EXPECT_EQ(ByteString::formatted("{}", nullptr), ByteString::formatted("{:p}", static_cast<FlatPtr>(0)));
}
struct C {
@ -340,12 +340,12 @@ struct AK::Formatter<C> : AK::Formatter<FormatString> {
TEST_CASE(use_format_string_formatter)
{
EXPECT_EQ(DeprecatedString::formatted("{:*<10}", C { 42 }), "C(i=42)***");
EXPECT_EQ(ByteString::formatted("{:*<10}", C { 42 }), "C(i=42)***");
}
TEST_CASE(long_long_regression)
{
EXPECT_EQ(DeprecatedString::formatted("{}", 0x0123456789abcdefLL), "81985529216486895");
EXPECT_EQ(ByteString::formatted("{}", 0x0123456789abcdefLL), "81985529216486895");
StringBuilder builder;
AK::FormatBuilder fmtbuilder { builder };
@ -356,28 +356,28 @@ TEST_CASE(long_long_regression)
TEST_CASE(hex_dump)
{
EXPECT_EQ(DeprecatedString::formatted("{:hex-dump}", "0000"), "30303030");
EXPECT_EQ(DeprecatedString::formatted("{:>4hex-dump}", "0000"), "30303030 0000");
EXPECT_EQ(DeprecatedString::formatted("{:>2hex-dump}", "0000"), "3030 00\n3030 00");
EXPECT_EQ(DeprecatedString::formatted("{:*>4hex-dump}", "0000"), "30303030****0000");
EXPECT_EQ(ByteString::formatted("{:hex-dump}", "0000"), "30303030");
EXPECT_EQ(ByteString::formatted("{:>4hex-dump}", "0000"), "30303030 0000");
EXPECT_EQ(ByteString::formatted("{:>2hex-dump}", "0000"), "3030 00\n3030 00");
EXPECT_EQ(ByteString::formatted("{:*>4hex-dump}", "0000"), "30303030****0000");
}
TEST_CASE(span_format)
{
{
Vector<int> v { 1, 2, 3, 4 };
EXPECT_EQ(DeprecatedString::formatted("{}", v.span()), "[ 1, 2, 3, 4 ]");
EXPECT_EQ(DeprecatedString::formatted("{}", const_cast<AddConst<decltype(v)>&>(v).span()), "[ 1, 2, 3, 4 ]");
EXPECT_EQ(ByteString::formatted("{}", v.span()), "[ 1, 2, 3, 4 ]");
EXPECT_EQ(ByteString::formatted("{}", const_cast<AddConst<decltype(v)>&>(v).span()), "[ 1, 2, 3, 4 ]");
}
{
Vector<StringView> v { "1"sv, "2"sv, "3"sv, "4"sv };
EXPECT_EQ(DeprecatedString::formatted("{}", v.span()), "[ 1, 2, 3, 4 ]");
EXPECT_EQ(DeprecatedString::formatted("{}", const_cast<AddConst<decltype(v)>&>(v).span()), "[ 1, 2, 3, 4 ]");
EXPECT_EQ(ByteString::formatted("{}", v.span()), "[ 1, 2, 3, 4 ]");
EXPECT_EQ(ByteString::formatted("{}", const_cast<AddConst<decltype(v)>&>(v).span()), "[ 1, 2, 3, 4 ]");
}
{
Vector<Vector<DeprecatedString>> v { { "1"sv, "2"sv }, { "3"sv, "4"sv } };
EXPECT_EQ(DeprecatedString::formatted("{}", v.span()), "[ [ 1, 2 ], [ 3, 4 ] ]");
EXPECT_EQ(DeprecatedString::formatted("{}", const_cast<AddConst<decltype(v)>&>(v).span()), "[ [ 1, 2 ], [ 3, 4 ] ]");
Vector<Vector<ByteString>> v { { "1"sv, "2"sv }, { "3"sv, "4"sv } };
EXPECT_EQ(ByteString::formatted("{}", v.span()), "[ [ 1, 2 ], [ 3, 4 ] ]");
EXPECT_EQ(ByteString::formatted("{}", const_cast<AddConst<decltype(v)>&>(v).span()), "[ [ 1, 2 ], [ 3, 4 ] ]");
}
}
@ -385,28 +385,28 @@ TEST_CASE(vector_format)
{
{
Vector<int> v { 1, 2, 3, 4 };
EXPECT_EQ(DeprecatedString::formatted("{}", v), "[ 1, 2, 3, 4 ]");
EXPECT_EQ(ByteString::formatted("{}", v), "[ 1, 2, 3, 4 ]");
}
{
Vector<StringView> v { "1"sv, "2"sv, "3"sv, "4"sv };
EXPECT_EQ(DeprecatedString::formatted("{}", v), "[ 1, 2, 3, 4 ]");
EXPECT_EQ(ByteString::formatted("{}", v), "[ 1, 2, 3, 4 ]");
}
{
Vector<Vector<DeprecatedString>> v { { "1"sv, "2"sv }, { "3"sv, "4"sv } };
EXPECT_EQ(DeprecatedString::formatted("{}", v), "[ [ 1, 2 ], [ 3, 4 ] ]");
Vector<Vector<ByteString>> v { { "1"sv, "2"sv }, { "3"sv, "4"sv } };
EXPECT_EQ(ByteString::formatted("{}", v), "[ [ 1, 2 ], [ 3, 4 ] ]");
}
}
TEST_CASE(format_wchar)
{
EXPECT_EQ(DeprecatedString::formatted("{}", L'a'), "a");
EXPECT_EQ(DeprecatedString::formatted("{}", L'\U0001F41E'), "\xF0\x9F\x90\x9E");
EXPECT_EQ(DeprecatedString::formatted("{:x}", L'a'), "61");
EXPECT_EQ(DeprecatedString::formatted("{:x}", L'\U0001F41E'), "1f41e");
EXPECT_EQ(DeprecatedString::formatted("{:d}", L'a'), "97");
EXPECT_EQ(DeprecatedString::formatted("{:d}", L'\U0001F41E'), "128030");
EXPECT_EQ(ByteString::formatted("{}", L'a'), "a");
EXPECT_EQ(ByteString::formatted("{}", L'\U0001F41E'), "\xF0\x9F\x90\x9E");
EXPECT_EQ(ByteString::formatted("{:x}", L'a'), "61");
EXPECT_EQ(ByteString::formatted("{:x}", L'\U0001F41E'), "1f41e");
EXPECT_EQ(ByteString::formatted("{:d}", L'a'), "97");
EXPECT_EQ(ByteString::formatted("{:d}", L'\U0001F41E'), "128030");
EXPECT_EQ(DeprecatedString::formatted("{:6}", L'a'), "a ");
EXPECT_EQ(DeprecatedString::formatted("{:6d}", L'a'), " 97");
EXPECT_EQ(DeprecatedString::formatted("{:#x}", L'\U0001F41E'), "0x1f41e");
EXPECT_EQ(ByteString::formatted("{:6}", L'a'), "a ");
EXPECT_EQ(ByteString::formatted("{:6d}", L'a'), " 97");
EXPECT_EQ(ByteString::formatted("{:#x}", L'\U0001F41E'), "0x1f41e");
}

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/HashMap.h>
#include <AK/OwnPtr.h>
#include <AK/String.h>
@ -20,7 +20,7 @@ TEST_CASE(construct)
TEST_CASE(construct_from_initializer_list)
{
HashMap<int, DeprecatedString> number_to_string {
HashMap<int, ByteString> number_to_string {
{ 1, "One" },
{ 2, "Two" },
{ 3, "Three" },
@ -31,7 +31,7 @@ TEST_CASE(construct_from_initializer_list)
TEST_CASE(populate)
{
HashMap<int, DeprecatedString> number_to_string;
HashMap<int, ByteString> number_to_string;
number_to_string.set(1, "One");
number_to_string.set(2, "Two");
number_to_string.set(3, "Three");
@ -42,7 +42,7 @@ TEST_CASE(populate)
TEST_CASE(range_loop)
{
HashMap<int, DeprecatedString> number_to_string;
HashMap<int, ByteString> number_to_string;
EXPECT_EQ(number_to_string.set(1, "One"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(number_to_string.set(2, "Two"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(number_to_string.set(3, "Three"), AK::HashSetResult::InsertedNewEntry);
@ -57,7 +57,7 @@ TEST_CASE(range_loop)
TEST_CASE(map_remove)
{
HashMap<int, DeprecatedString> number_to_string;
HashMap<int, ByteString> number_to_string;
EXPECT_EQ(number_to_string.set(1, "One"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(number_to_string.set(2, "Two"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(number_to_string.set(3, "Three"), AK::HashSetResult::InsertedNewEntry);
@ -74,7 +74,7 @@ TEST_CASE(map_remove)
TEST_CASE(remove_all_matching)
{
HashMap<int, DeprecatedString> map;
HashMap<int, ByteString> map;
map.set(1, "One");
map.set(2, "Two");
@ -83,27 +83,27 @@ TEST_CASE(remove_all_matching)
EXPECT_EQ(map.size(), 4u);
EXPECT_EQ(map.remove_all_matching([&](int key, DeprecatedString const& value) { return key == 1 || value == "Two"; }), true);
EXPECT_EQ(map.remove_all_matching([&](int key, ByteString const& value) { return key == 1 || value == "Two"; }), true);
EXPECT_EQ(map.size(), 2u);
EXPECT_EQ(map.remove_all_matching([&](int, DeprecatedString const&) { return false; }), false);
EXPECT_EQ(map.remove_all_matching([&](int, ByteString const&) { return false; }), false);
EXPECT_EQ(map.size(), 2u);
EXPECT(map.contains(3));
EXPECT(map.contains(4));
EXPECT_EQ(map.remove_all_matching([&](int, DeprecatedString const&) { return true; }), true);
EXPECT_EQ(map.remove_all_matching([&](int, DeprecatedString const&) { return false; }), false);
EXPECT_EQ(map.remove_all_matching([&](int, ByteString const&) { return true; }), true);
EXPECT_EQ(map.remove_all_matching([&](int, ByteString const&) { return false; }), false);
EXPECT(map.is_empty());
EXPECT_EQ(map.remove_all_matching([&](int, DeprecatedString const&) { return true; }), false);
EXPECT_EQ(map.remove_all_matching([&](int, ByteString const&) { return true; }), false);
}
TEST_CASE(case_insensitive)
{
HashMap<DeprecatedString, int, CaseInsensitiveStringTraits> casemap;
EXPECT_EQ(DeprecatedString("nickserv").to_lowercase(), DeprecatedString("NickServ").to_lowercase());
HashMap<ByteString, int, CaseInsensitiveStringTraits> casemap;
EXPECT_EQ(ByteString("nickserv").to_lowercase(), ByteString("NickServ").to_lowercase());
EXPECT_EQ(casemap.set("nickserv", 3), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(casemap.set("NickServ", 3), AK::HashSetResult::ReplacedExistingEntry);
EXPECT_EQ(casemap.size(), 1u);
@ -120,11 +120,11 @@ TEST_CASE(case_insensitive_stringview)
TEST_CASE(hashmap_of_nonnullownptr_get)
{
struct Object {
Object(DeprecatedString const& s)
Object(ByteString const& s)
: string(s)
{
}
DeprecatedString string;
ByteString string;
};
HashMap<int, NonnullOwnPtr<Object>> objects;
@ -151,16 +151,16 @@ TEST_CASE(hashmap_of_nonnullownptr_get)
TEST_CASE(many_strings)
{
HashMap<DeprecatedString, int> strings;
HashMap<ByteString, int> strings;
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.set(DeprecatedString::number(i), i), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set(ByteString::number(i), i), AK::HashSetResult::InsertedNewEntry);
}
EXPECT_EQ(strings.size(), 999u);
for (auto& it : strings) {
EXPECT_EQ(it.key.to_int().value(), it.value);
}
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.remove(DeprecatedString::number(i)), true);
EXPECT_EQ(strings.remove(ByteString::number(i)), true);
}
EXPECT_EQ(strings.is_empty(), true);
}
@ -213,7 +213,7 @@ TEST_CASE(basic_contains)
TEST_CASE(in_place_rehashing_ordered_loop_bug)
{
OrderedHashMap<DeprecatedString, DeprecatedString> map;
OrderedHashMap<ByteString, ByteString> map;
map.set("yt.innertube::nextId", "");
map.set("yt.innertube::requests", "");
map.remove("yt.innertube::nextId");

View file

@ -7,7 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/HashTable.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/Vector.h>
@ -46,7 +46,7 @@ TEST_CASE(move_is_not_swap)
TEST_CASE(populate)
{
HashTable<DeprecatedString> strings;
HashTable<ByteString> strings;
strings.set("One");
strings.set("Two");
strings.set("Three");
@ -57,7 +57,7 @@ TEST_CASE(populate)
TEST_CASE(range_loop)
{
HashTable<DeprecatedString> strings;
HashTable<ByteString> strings;
EXPECT_EQ(strings.set("One"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set("Two"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set("Three"), AK::HashSetResult::InsertedNewEntry);
@ -73,7 +73,7 @@ TEST_CASE(range_loop)
TEST_CASE(range_loop_reverse)
{
Array strings = { "One"sv, "Two"sv, "Three"sv };
OrderedHashTable<DeprecatedString> table;
OrderedHashTable<ByteString> table;
EXPECT_EQ(table.set(strings[0]), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(table.set(strings[1]), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(table.set(strings[2]), AK::HashSetResult::InsertedNewEntry);
@ -90,7 +90,7 @@ TEST_CASE(range_loop_reverse)
TEST_CASE(table_remove)
{
HashTable<DeprecatedString> strings;
HashTable<ByteString> strings;
EXPECT_EQ(strings.set("One"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set("Two"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set("Three"), AK::HashSetResult::InsertedNewEntry);
@ -133,8 +133,8 @@ TEST_CASE(remove_all_matching)
TEST_CASE(case_insensitive)
{
HashTable<DeprecatedString, CaseInsensitiveStringTraits> casetable;
EXPECT_EQ(DeprecatedString("nickserv").to_lowercase(), DeprecatedString("NickServ").to_lowercase());
HashTable<ByteString, CaseInsensitiveStringTraits> casetable;
EXPECT_EQ(ByteString("nickserv").to_lowercase(), ByteString("NickServ").to_lowercase());
EXPECT_EQ(casetable.set("nickserv"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(casetable.set("NickServ"), AK::HashSetResult::ReplacedExistingEntry);
EXPECT_EQ(casetable.size(), 1u);
@ -142,33 +142,33 @@ TEST_CASE(case_insensitive)
TEST_CASE(many_strings)
{
HashTable<DeprecatedString> strings;
HashTable<ByteString> strings;
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.set(DeprecatedString::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set(ByteString::number(i)), AK::HashSetResult::InsertedNewEntry);
}
EXPECT_EQ(strings.size(), 999u);
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.remove(DeprecatedString::number(i)), true);
EXPECT_EQ(strings.remove(ByteString::number(i)), true);
}
EXPECT_EQ(strings.is_empty(), true);
}
TEST_CASE(many_collisions)
{
struct StringCollisionTraits : public DefaultTraits<DeprecatedString> {
static unsigned hash(DeprecatedString const&) { return 0; }
struct StringCollisionTraits : public DefaultTraits<ByteString> {
static unsigned hash(ByteString const&) { return 0; }
};
HashTable<DeprecatedString, StringCollisionTraits> strings;
HashTable<ByteString, StringCollisionTraits> strings;
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.set(DeprecatedString::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.set(ByteString::number(i)), AK::HashSetResult::InsertedNewEntry);
}
EXPECT_EQ(strings.set("foo"), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.size(), 1000u);
for (int i = 0; i < 999; ++i) {
EXPECT_EQ(strings.remove(DeprecatedString::number(i)), true);
EXPECT_EQ(strings.remove(ByteString::number(i)), true);
}
EXPECT(strings.find("foo") != strings.end());
@ -176,24 +176,24 @@ TEST_CASE(many_collisions)
TEST_CASE(space_reuse)
{
struct StringCollisionTraits : public DefaultTraits<DeprecatedString> {
static unsigned hash(DeprecatedString const&) { return 0; }
struct StringCollisionTraits : public DefaultTraits<ByteString> {
static unsigned hash(ByteString const&) { return 0; }
};
HashTable<DeprecatedString, StringCollisionTraits> strings;
HashTable<ByteString, StringCollisionTraits> strings;
// Add a few items to allow it to do initial resizing.
EXPECT_EQ(strings.set("0"), AK::HashSetResult::InsertedNewEntry);
for (int i = 1; i < 5; ++i) {
EXPECT_EQ(strings.set(DeprecatedString::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.remove(DeprecatedString::number(i - 1)), true);
EXPECT_EQ(strings.set(ByteString::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.remove(ByteString::number(i - 1)), true);
}
auto capacity = strings.capacity();
for (int i = 5; i < 999; ++i) {
EXPECT_EQ(strings.set(DeprecatedString::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.remove(DeprecatedString::number(i - 1)), true);
EXPECT_EQ(strings.set(ByteString::number(i)), AK::HashSetResult::InsertedNewEntry);
EXPECT_EQ(strings.remove(ByteString::number(i - 1)), true);
}
EXPECT_EQ(strings.capacity(), capacity);
@ -301,7 +301,7 @@ TEST_CASE(doubles)
TEST_CASE(reinsertion)
{
OrderedHashTable<DeprecatedString> map;
OrderedHashTable<ByteString> map;
map.set("ytidb::LAST_RESULT_ENTRY_KEY");
map.set("__sak");
map.remove("__sak");
@ -445,7 +445,7 @@ TEST_CASE(ordered_remove_from_head)
TEST_CASE(ordered_infinite_loop_clang_regression)
{
OrderedHashTable<DeprecatedString> map;
OrderedHashTable<ByteString> map;
map.set("");
map.set("1");
map.set("_cb");

View file

@ -61,7 +61,7 @@ TEST_CASE(should_convert_to_string)
{
constexpr IPv4Address addr(1, 25, 39, 42);
EXPECT_EQ("1.25.39.42", addr.to_deprecated_string());
EXPECT_EQ("1.25.39.42", addr.to_byte_string());
}
TEST_CASE(should_make_ipv4_address_from_string)

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/HashMap.h>
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
@ -14,7 +14,7 @@
TEST_CASE(load_form)
{
DeprecatedString raw_form_json = R"(
ByteString raw_form_json = R"(
{
"name": "Form1",
"widgets": [
@ -40,7 +40,7 @@ TEST_CASE(load_form)
EXPECT(form_json.is_object());
auto name = form_json.as_object().get_deprecated_string("name"sv);
auto name = form_json.as_object().get_byte_string("name"sv);
EXPECT(name.has_value());
EXPECT_EQ(name.value(), "Form1");
@ -50,7 +50,7 @@ TEST_CASE(load_form)
widgets->for_each([&](JsonValue const& widget_value) {
auto& widget_object = widget_value.as_object();
auto widget_class = widget_object.get_deprecated_string("class"sv).value();
auto widget_class = widget_object.get_byte_string("class"sv).value();
widget_object.for_each_member([&]([[maybe_unused]] auto& property_name, [[maybe_unused]] const JsonValue& property_value) {
});
});
@ -109,13 +109,13 @@ TEST_CASE(json_duplicate_keys)
json.set("test", "foo");
json.set("test", "bar");
json.set("test", "baz");
EXPECT_EQ(json.to_deprecated_string(), "{\"test\":\"baz\"}");
EXPECT_EQ(json.to_byte_string(), "{\"test\":\"baz\"}");
}
TEST_CASE(json_u64_roundtrip)
{
auto big_value = 0xffffffffffffffffull;
auto json = JsonValue(big_value).to_deprecated_string();
auto json = JsonValue(big_value).to_byte_string();
auto value = JsonValue::from_string(json);
EXPECT_EQ_FORCE(value.is_error(), false);
EXPECT_EQ(value.value().as_u64(), big_value);
@ -292,7 +292,7 @@ private:
TEST_CASE(fallible_json_object_for_each)
{
DeprecatedString raw_json = R"(
ByteString raw_json = R"(
{
"name": "anon",
"home": "/home/anon",
@ -332,7 +332,7 @@ TEST_CASE(fallible_json_object_for_each)
TEST_CASE(fallible_json_array_for_each)
{
DeprecatedString raw_json = R"(
ByteString raw_json = R"(
[
"anon",
"/home/anon",
@ -489,7 +489,7 @@ TEST_CASE(json_array_serialize)
auto array = json_value.as_array();
StringBuilder builder {};
array.serialize(builder);
EXPECT_EQ(builder.to_deprecated_string(), raw_json);
EXPECT_EQ(builder.to_byte_string(), raw_json);
}
TEST_CASE(json_array_values)

View file

@ -7,7 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/LexicalPath.h>
TEST_CASE(relative_path)

View file

@ -80,7 +80,7 @@ TEST_CASE(should_equality_compare)
TEST_CASE(should_string_format)
{
MACAddress sut(1, 2, 3, 4, 5, 6);
EXPECT_EQ("01:02:03:04:05:06", sut.to_deprecated_string());
EXPECT_EQ("01:02:03:04:05:06", sut.to_byte_string());
}
TEST_CASE(should_make_mac_address_from_string_numbers)

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/MemMem.h>
#include <AK/Memory.h>
@ -78,9 +78,9 @@ TEST_CASE(kmp_two_chunks)
TEST_CASE(timing_safe_compare)
{
DeprecatedString data_set = "abcdefghijklmnopqrstuvwxyz123456789";
ByteString data_set = "abcdefghijklmnopqrstuvwxyz123456789";
EXPECT_EQ(true, AK::timing_safe_compare(data_set.characters(), data_set.characters(), data_set.length()));
DeprecatedString reversed = data_set.reverse();
ByteString reversed = data_set.reverse();
EXPECT_EQ(false, AK::timing_safe_compare(data_set.characters(), reversed.characters(), reversed.length()));
}

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/OwnPtr.h>
#include <AK/String.h>

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/NonnullRefPtr.h>
#include <AK/OwnPtr.h>

View file

@ -7,7 +7,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Optional.h>
#include <AK/Vector.h>
@ -59,7 +59,7 @@ TEST_CASE(optional_rvalue_ref_qualified_getters)
TEST_CASE(optional_leak_1)
{
struct Structure {
Optional<DeprecatedString> str;
Optional<ByteString> str;
};
// This used to leak, it does not anymore.
@ -81,7 +81,7 @@ TEST_CASE(comparison_without_values)
{
Optional<StringView> opt0;
Optional<StringView> opt1;
Optional<DeprecatedString> opt2;
Optional<ByteString> opt2;
EXPECT_EQ(opt0, opt1);
EXPECT_EQ(opt0, opt2);
}
@ -90,7 +90,7 @@ TEST_CASE(comparison_with_values)
{
Optional<StringView> opt0;
Optional<StringView> opt1 = "foo"sv;
Optional<DeprecatedString> opt2 = "foo"sv;
Optional<ByteString> opt2 = "foo"sv;
Optional<StringView> opt3 = "bar"sv;
EXPECT_NE(opt0, opt1);
EXPECT_EQ(opt1, opt2);
@ -99,14 +99,14 @@ TEST_CASE(comparison_with_values)
TEST_CASE(comparison_to_underlying_types)
{
Optional<DeprecatedString> opt0;
EXPECT_NE(opt0, DeprecatedString());
Optional<ByteString> opt0;
EXPECT_NE(opt0, ByteString());
EXPECT_NE(opt0, "foo");
Optional<StringView> opt1 = "foo"sv;
EXPECT_EQ(opt1, "foo");
EXPECT_NE(opt1, "bar");
EXPECT_EQ(opt1, DeprecatedString("foo"));
EXPECT_EQ(opt1, ByteString("foo"));
}
TEST_CASE(comparison_with_numeric_types)
@ -262,7 +262,7 @@ TEST_CASE(comparison_reference)
StringView test = "foo"sv;
Optional<StringView&> opt0;
Optional<StringView const&> opt1 = test;
Optional<DeprecatedString> opt2 = "foo"sv;
Optional<ByteString> opt2 = "foo"sv;
Optional<StringView> opt3 = "bar"sv;
EXPECT_NE(opt0, opt1);

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Queue.h>
TEST_CASE(construct)
@ -32,7 +32,7 @@ TEST_CASE(populate_int)
TEST_CASE(populate_string)
{
Queue<DeprecatedString> strings;
Queue<ByteString> strings;
strings.enqueue("ABC");
strings.enqueue("DEF");
EXPECT_EQ(strings.size(), 2u);
@ -43,11 +43,11 @@ TEST_CASE(populate_string)
TEST_CASE(order)
{
Queue<DeprecatedString> strings;
Queue<ByteString> strings;
EXPECT(strings.is_empty());
for (size_t i = 0; i < 10000; ++i) {
strings.enqueue(DeprecatedString::number(i));
strings.enqueue(ByteString::number(i));
EXPECT_EQ(strings.size(), i + 1);
}

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/NonnullRefPtr.h>
struct Object : public RefCounted<Object> {

View file

@ -26,7 +26,7 @@ TEST_CASE(basic)
TEST_CASE(complex_type)
{
AK::Stack<DeprecatedString, 4> stack;
AK::Stack<ByteString, 4> stack;
EXPECT_EQ(stack.is_empty(), true);
EXPECT(stack.push("Well"));

View file

@ -22,11 +22,11 @@ TEST_CASE(hash_compatible)
static_assert(AK::Concepts::HashCompatible<FlyString, String>);
static_assert(AK::Concepts::HashCompatible<FlyString, StringView>);
static_assert(AK::Concepts::HashCompatible<DeprecatedString, StringView>);
static_assert(AK::Concepts::HashCompatible<DeprecatedString, DeprecatedFlyString>);
static_assert(AK::Concepts::HashCompatible<StringView, DeprecatedString>);
static_assert(AK::Concepts::HashCompatible<ByteString, StringView>);
static_assert(AK::Concepts::HashCompatible<ByteString, DeprecatedFlyString>);
static_assert(AK::Concepts::HashCompatible<StringView, ByteString>);
static_assert(AK::Concepts::HashCompatible<StringView, DeprecatedFlyString>);
static_assert(AK::Concepts::HashCompatible<DeprecatedFlyString, DeprecatedString>);
static_assert(AK::Concepts::HashCompatible<DeprecatedFlyString, ByteString>);
static_assert(AK::Concepts::HashCompatible<DeprecatedFlyString, StringView>);
static_assert(AK::Concepts::HashCompatible<StringView, ByteBuffer>);
@ -328,7 +328,7 @@ TEST_CASE(convert_to_floating_point)
TEST_CASE(ends_with)
{
DeprecatedString test_string = "ABCDEF";
ByteString test_string = "ABCDEF";
EXPECT(AK::StringUtils::ends_with(test_string, "DEF"sv, CaseSensitivity::CaseSensitive));
EXPECT(AK::StringUtils::ends_with(test_string, "ABCDEF"sv, CaseSensitivity::CaseSensitive));
EXPECT(!AK::StringUtils::ends_with(test_string, "ABCDE"sv, CaseSensitivity::CaseSensitive));
@ -339,7 +339,7 @@ TEST_CASE(ends_with)
TEST_CASE(starts_with)
{
DeprecatedString test_string = "ABCDEF";
ByteString test_string = "ABCDEF";
EXPECT(AK::StringUtils::starts_with(test_string, "ABC"sv, CaseSensitivity::CaseSensitive));
EXPECT(AK::StringUtils::starts_with(test_string, "ABCDEF"sv, CaseSensitivity::CaseSensitive));
EXPECT(!AK::StringUtils::starts_with(test_string, "BCDEF"sv, CaseSensitivity::CaseSensitive));
@ -350,7 +350,7 @@ TEST_CASE(starts_with)
TEST_CASE(contains)
{
DeprecatedString test_string = "ABCDEFABCXYZ";
ByteString test_string = "ABCDEFABCXYZ";
EXPECT(AK::StringUtils::contains(test_string, "ABC"sv, CaseSensitivity::CaseSensitive));
EXPECT(AK::StringUtils::contains(test_string, "ABC"sv, CaseSensitivity::CaseInsensitive));
EXPECT(AK::StringUtils::contains(test_string, "AbC"sv, CaseSensitivity::CaseInsensitive));
@ -368,7 +368,7 @@ TEST_CASE(contains)
EXPECT(!AK::StringUtils::contains(test_string, "L"sv, CaseSensitivity::CaseSensitive));
EXPECT(!AK::StringUtils::contains(test_string, "L"sv, CaseSensitivity::CaseInsensitive));
DeprecatedString command_palette_bug_string = "Go Go Back";
ByteString command_palette_bug_string = "Go Go Back";
EXPECT(AK::StringUtils::contains(command_palette_bug_string, "Go Back"sv, AK::CaseSensitivity::CaseSensitive));
EXPECT(AK::StringUtils::contains(command_palette_bug_string, "gO bAcK"sv, AK::CaseSensitivity::CaseInsensitive));
}
@ -397,7 +397,7 @@ TEST_CASE(trim)
TEST_CASE(find)
{
DeprecatedString test_string = "1234567";
ByteString test_string = "1234567";
EXPECT_EQ(AK::StringUtils::find(test_string, "1"sv).value_or(1), 0u);
EXPECT_EQ(AK::StringUtils::find(test_string, "2"sv).value_or(2), 1u);
EXPECT_EQ(AK::StringUtils::find(test_string, "3"sv).value_or(3), 2u);

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/Vector.h>
TEST_CASE(construct_empty)
@ -29,8 +29,8 @@ TEST_CASE(view_literal)
TEST_CASE(compare_views)
{
DeprecatedString foo1 = "foo";
DeprecatedString foo2 = "foo";
ByteString foo1 = "foo";
ByteString foo2 = "foo";
auto view1 = foo1.view();
auto view2 = foo2.view();
@ -43,7 +43,7 @@ TEST_CASE(compare_views)
TEST_CASE(string_view_literal_operator)
{
StringView literal_view = "foo"sv;
DeprecatedString test_string = "foo";
ByteString test_string = "foo";
EXPECT_EQ(literal_view.length(), test_string.length());
EXPECT_EQ(literal_view, test_string);
@ -51,7 +51,7 @@ TEST_CASE(string_view_literal_operator)
TEST_CASE(starts_with)
{
DeprecatedString test_string = "ABCDEF";
ByteString test_string = "ABCDEF";
StringView test_string_view = test_string.view();
EXPECT(test_string_view.starts_with('A'));
EXPECT(!test_string_view.starts_with('B'));
@ -64,7 +64,7 @@ TEST_CASE(starts_with)
TEST_CASE(ends_with)
{
DeprecatedString test_string = "ABCDEF";
ByteString test_string = "ABCDEF";
StringView test_string_view = test_string.view();
EXPECT(test_string_view.ends_with("DEF"sv));
EXPECT(test_string_view.ends_with('F'));
@ -78,23 +78,23 @@ TEST_CASE(ends_with)
TEST_CASE(lines)
{
DeprecatedString test_string = "a\rb\nc\r\nd";
ByteString test_string = "a\rb\nc\r\nd";
StringView test_string_view = test_string.view();
Vector<StringView> test_string_vector = test_string_view.lines();
EXPECT_EQ(test_string_vector.size(), 4u);
EXPECT(test_string_vector.at(0) == DeprecatedString("a"));
EXPECT(test_string_vector.at(1) == DeprecatedString("b"));
EXPECT(test_string_vector.at(2) == DeprecatedString("c"));
EXPECT(test_string_vector.at(3) == DeprecatedString("d"));
EXPECT(test_string_vector.at(0) == ByteString("a"));
EXPECT(test_string_vector.at(1) == ByteString("b"));
EXPECT(test_string_vector.at(2) == ByteString("c"));
EXPECT(test_string_vector.at(3) == ByteString("d"));
test_string = "```\nHello there\r\nHello there\n```";
test_string_view = test_string.view();
test_string_vector = test_string_view.lines();
EXPECT_EQ(test_string_vector.size(), 4u);
EXPECT(test_string_vector.at(0) == DeprecatedString("```"));
EXPECT(test_string_vector.at(1) == DeprecatedString("Hello there"));
EXPECT(test_string_vector.at(2) == DeprecatedString("Hello there"));
EXPECT(test_string_vector.at(3) == DeprecatedString("```"));
EXPECT(test_string_vector.at(0) == ByteString("```"));
EXPECT(test_string_vector.at(1) == ByteString("Hello there"));
EXPECT(test_string_vector.at(2) == ByteString("Hello there"));
EXPECT(test_string_vector.at(3) == ByteString("```"));
test_string = "\n\n\n";
test_string_view = test_string.view();

View file

@ -11,12 +11,12 @@
TEST_CASE(normal_behavior)
{
Trie<char, DeprecatedString> dictionary('/', "");
Trie<char, ByteString> dictionary('/', "");
constexpr StringView data[] { "test"sv, "example"sv, "foo"sv, "foobar"sv };
constexpr size_t total_chars = 18; // root (1), 'test' (4), 'example' (7), 'foo' (3), 'foobar' (3, "foo" already stored).
for (auto& view : data) {
auto it = view.begin();
MUST(dictionary.insert(it, view.end(), view, [](auto& parent, auto& it) -> Optional<DeprecatedString> { return DeprecatedString::formatted("{}{}", parent.metadata_value(), *it); }));
MUST(dictionary.insert(it, view.end(), view, [](auto& parent, auto& it) -> Optional<ByteString> { return ByteString::formatted("{}{}", parent.metadata_value(), *it); }));
}
size_t i = 0;

View file

@ -10,41 +10,41 @@
TEST_CASE(basic)
{
Tuple<int, DeprecatedString> value { 1, "foo" };
Tuple<int, ByteString> value { 1, "foo" };
EXPECT_EQ(value.get<int>(), 1);
EXPECT_EQ(value.get<DeprecatedString>(), "foo");
EXPECT_EQ(value.get<ByteString>(), "foo");
EXPECT_EQ(value.get<0>(), 1);
EXPECT_EQ(value.get<1>(), "foo");
// Move assignment
value = { 2, "bar" };
EXPECT_EQ(value.get<int>(), 2);
EXPECT_EQ(value.get<DeprecatedString>(), "bar");
EXPECT_EQ(value.get<ByteString>(), "bar");
EXPECT_EQ(value.get<0>(), 2);
EXPECT_EQ(value.get<1>(), "bar");
// Copy ctor
auto other_value { value };
EXPECT_EQ(other_value.get<int>(), 2);
EXPECT_EQ(other_value.get<DeprecatedString>(), "bar");
EXPECT_EQ(other_value.get<ByteString>(), "bar");
EXPECT_EQ(other_value.get<0>(), 2);
EXPECT_EQ(other_value.get<1>(), "bar");
// Move ctor
auto moved_to_value { move(value) };
EXPECT_EQ(moved_to_value.get<int>(), 2);
EXPECT_EQ(moved_to_value.get<DeprecatedString>(), "bar");
EXPECT_EQ(moved_to_value.get<ByteString>(), "bar");
EXPECT_EQ(moved_to_value.get<0>(), 2);
EXPECT_EQ(moved_to_value.get<1>(), "bar");
// Copy assignment
value = moved_to_value;
EXPECT_EQ(moved_to_value.get<int>(), 2);
EXPECT_EQ(moved_to_value.get<DeprecatedString>(), "bar");
EXPECT_EQ(moved_to_value.get<ByteString>(), "bar");
EXPECT_EQ(moved_to_value.get<0>(), 2);
EXPECT_EQ(moved_to_value.get<1>(), "bar");
EXPECT_EQ(value.get<int>(), 2);
EXPECT_EQ(value.get<DeprecatedString>(), "bar");
EXPECT_EQ(value.get<ByteString>(), "bar");
EXPECT_EQ(value.get<0>(), 2);
EXPECT_EQ(value.get<1>(), "bar");
}
@ -68,12 +68,12 @@ TEST_CASE(no_copy)
TEST_CASE(apply)
{
Tuple<int, int, DeprecatedString> args { 1, 2, "foo" };
Tuple<int, int, ByteString> args { 1, 2, "foo" };
// With copy
{
bool was_called = false;
args.apply_as_args([&](int a, int b, DeprecatedString c) {
args.apply_as_args([&](int a, int b, ByteString c) {
was_called = true;
EXPECT_EQ(a, 1);
EXPECT_EQ(b, 2);
@ -85,7 +85,7 @@ TEST_CASE(apply)
// With reference
{
bool was_called = false;
args.apply_as_args([&](int& a, int& b, DeprecatedString& c) {
args.apply_as_args([&](int& a, int& b, ByteString& c) {
was_called = true;
EXPECT_EQ(a, 1);
EXPECT_EQ(b, 2);
@ -98,7 +98,7 @@ TEST_CASE(apply)
{
bool was_called = false;
auto const& args_ref = args;
args_ref.apply_as_args([&](int const& a, int const& b, DeprecatedString const& c) {
args_ref.apply_as_args([&](int const& a, int const& b, ByteString const& c) {
was_called = true;
EXPECT_EQ(a, 1);
EXPECT_EQ(b, 2);

View file

@ -412,21 +412,21 @@ TEST_CASE(leading_whitespace)
{
URL url { " https://foo.com/"sv };
EXPECT(url.is_valid());
EXPECT_EQ(url.to_deprecated_string(), "https://foo.com/");
EXPECT_EQ(url.to_byte_string(), "https://foo.com/");
}
TEST_CASE(trailing_whitespace)
{
URL url { "https://foo.com/ "sv };
EXPECT(url.is_valid());
EXPECT_EQ(url.to_deprecated_string(), "https://foo.com/");
EXPECT_EQ(url.to_byte_string(), "https://foo.com/");
}
TEST_CASE(leading_and_trailing_whitespace)
{
URL url { " https://foo.com/ "sv };
EXPECT(url.is_valid());
EXPECT_EQ(url.to_deprecated_string(), "https://foo.com/");
EXPECT_EQ(url.to_byte_string(), "https://foo.com/");
}
TEST_CASE(unicode)

View file

@ -34,7 +34,7 @@ TEST_CASE(decode_utf8)
EXPECT(valid_bytes == (size_t)utf8.byte_length());
u32 expected[] = { 1055, 1088, 1080, 1074, 1077, 1090, 44, 32, 1084, 1080, 1088, 33, 32, 128512, 32, 947, 949, 953, 940, 32, 963, 959, 965, 32, 954, 972, 963, 956, 959, 962, 32, 12371, 12435, 12395, 12385, 12399, 19990, 30028 };
DeprecatedString expected_underlying_bytes[] = { "П", "р", "и", "в", "е", "т", ",", " ", "м", "и", "р", "!", " ", "😀", " ", "γ", "ε", "ι", "ά", " ", "σ", "ο", "υ", " ", "κ", "ό", "σ", "μ", "ο", "ς", " ", "", "", "", "", "", "", "" };
ByteString expected_underlying_bytes[] = { "П", "р", "и", "в", "е", "т", ",", " ", "м", "и", "р", "!", " ", "😀", " ", "γ", "ε", "ι", "ά", " ", "σ", "ο", "υ", " ", "κ", "ό", "σ", "μ", "ο", "ς", " ", "", "", "", "", "", "", "" };
size_t expected_size = sizeof(expected) / sizeof(expected[0]);
size_t i = 0;
@ -166,7 +166,7 @@ TEST_CASE(decode_invalid_ut8)
char raw_data[] = { 'a', 'b', (char)0xA0, 'd' };
Utf8View view { StringView { raw_data, 4 } };
u32 expected_characters[] = { 'a', 'b', 0xFFFD, 'd' };
DeprecatedString expected_underlying_bytes[] = { "a", "b", "\xA0", "d" };
ByteString expected_underlying_bytes[] = { "a", "b", "\xA0", "d" };
size_t expected_size = sizeof(expected_characters) / sizeof(expected_characters[0]);
size_t i = 0;
for (auto it = view.begin(); it != view.end(); ++it) {
@ -184,7 +184,7 @@ TEST_CASE(decode_invalid_ut8)
char raw_data[] = { 'a', 'b', (char)0xC0, 'd', 'e' };
Utf8View view { StringView { raw_data, 5 } };
u32 expected_characters[] = { 'a', 'b', 0xFFFD, 'd', 'e' };
DeprecatedString expected_underlying_bytes[] = { "a", "b", "\xC0", "d", "e" };
ByteString expected_underlying_bytes[] = { "a", "b", "\xC0", "d", "e" };
size_t expected_size = sizeof(expected_characters) / sizeof(expected_characters[0]);
size_t i = 0;
for (auto it = view.begin(); it != view.end(); ++it) {
@ -202,7 +202,7 @@ TEST_CASE(decode_invalid_ut8)
char raw_data[] = { 'a', 'b', (char)0x90, 'd' };
Utf8View view { StringView { raw_data, 4 } };
u32 expected_characters[] = { 'a', 'b', 0xFFFD, 'd' };
DeprecatedString expected_underlying_bytes[] = { "a", "b", "\x90", "d" };
ByteString expected_underlying_bytes[] = { "a", "b", "\x90", "d" };
size_t expected_size = sizeof(expected_characters) / sizeof(expected_characters[0]);
size_t i = 0;
for (auto it = view.begin(); it != view.end(); ++it) {
@ -220,7 +220,7 @@ TEST_CASE(decode_invalid_ut8)
char raw_data[] = { 'a', 'b', 'c', (char)0x90 };
Utf8View view { StringView { raw_data, 4 } };
u32 expected_characters[] = { 'a', 'b', 'c', 0xFFFD };
DeprecatedString expected_underlying_bytes[] = { "a", "b", "c", "\x90" };
ByteString expected_underlying_bytes[] = { "a", "b", "c", "\x90" };
size_t expected_size = sizeof(expected_characters) / sizeof(expected_characters[0]);
size_t i = 0;
for (auto it = view.begin(); it != view.end(); ++it) {
@ -247,7 +247,7 @@ TEST_CASE(decode_invalid_ut8)
// https://www.unicode.org/versions/Unicode14.0.0/ch03.pdf , section "U+FFFD Substitution of Maximal Subparts"
// However, that would go against how we deal with several other kinds of errors, so we stick to emitting only one U+FFFD.
u32 expected_characters[] = { 'a', 0xFFFD, 'b' };
DeprecatedString expected_underlying_bytes[] = { "a", "\xF4\xA3\x91\x96", "b" };
ByteString expected_underlying_bytes[] = { "a", "\xF4\xA3\x91\x96", "b" };
size_t expected_size = sizeof(expected_characters) / sizeof(expected_characters[0]);
size_t i = 0;
for (auto it = view.begin(); it != view.end(); ++it) {

View file

@ -18,21 +18,21 @@ struct Object : public RefCounted<Object> {
TEST_CASE(basic)
{
Variant<int, DeprecatedString> the_value { 42 };
Variant<int, ByteString> the_value { 42 };
EXPECT(the_value.has<int>());
EXPECT_EQ(the_value.get<int>(), 42);
the_value = DeprecatedString("42");
EXPECT(the_value.has<DeprecatedString>());
EXPECT_EQ(the_value.get<DeprecatedString>(), "42");
the_value = ByteString("42");
EXPECT(the_value.has<ByteString>());
EXPECT_EQ(the_value.get<ByteString>(), "42");
}
TEST_CASE(visit)
{
bool correct = false;
Variant<int, DeprecatedString, float> the_value { 42.0f };
Variant<int, ByteString, float> the_value { 42.0f };
the_value.visit(
[&](int const&) { correct = false; },
[&](DeprecatedString const&) { correct = false; },
[&](ByteString const&) { correct = false; },
[&](float const&) { correct = true; });
EXPECT(correct);
}
@ -40,10 +40,10 @@ TEST_CASE(visit)
TEST_CASE(visit_const)
{
bool correct = false;
Variant<int, DeprecatedString> const the_value { "42"sv };
Variant<int, ByteString> const the_value { "42"sv };
the_value.visit(
[&](DeprecatedString const&) { correct = true; },
[&](ByteString const&) { correct = true; },
[&](auto&) {},
[&](auto const&) {});
@ -52,7 +52,7 @@ TEST_CASE(visit_const)
correct = false;
auto the_value_but_not_const = the_value;
the_value_but_not_const.visit(
[&](DeprecatedString const&) { correct = true; },
[&](ByteString const&) { correct = true; },
[&](auto&) {});
EXPECT(correct);
@ -168,13 +168,13 @@ TEST_CASE(duplicated_types)
TEST_CASE(return_values)
{
using MyVariant = Variant<int, DeprecatedString, float>;
using MyVariant = Variant<int, ByteString, float>;
{
MyVariant the_value { 42.0f };
float value = the_value.visit(
[&](int const&) { return 1.0f; },
[&](DeprecatedString const&) { return 2.0f; },
[&](ByteString const&) { return 2.0f; },
[&](float const& f) { return f; });
EXPECT_EQ(value, 42.0f);
}
@ -183,17 +183,17 @@ TEST_CASE(return_values)
int value = the_value.visit(
[&](int& i) { return i; },
[&](DeprecatedString&) { return 2; },
[&](ByteString&) { return 2; },
[&](float&) { return 3; });
EXPECT_EQ(value, 42);
}
{
const MyVariant the_value { "str" };
DeprecatedString value = the_value.visit(
[&](int const&) { return DeprecatedString { "wrong" }; },
[&](DeprecatedString const& s) { return s; },
[&](float const&) { return DeprecatedString { "wrong" }; });
ByteString value = the_value.visit(
[&](int const&) { return ByteString { "wrong" }; },
[&](ByteString const& s) { return s; },
[&](float const&) { return ByteString { "wrong" }; });
EXPECT_EQ(value, "str");
}
}
@ -201,11 +201,11 @@ TEST_CASE(return_values)
TEST_CASE(return_values_by_reference)
{
auto ref = adopt_ref_if_nonnull(new (nothrow) Object());
Variant<int, DeprecatedString, float> the_value { 42.0f };
Variant<int, ByteString, float> the_value { 42.0f };
auto& value = the_value.visit(
[&](int const&) -> RefPtr<Object>& { return ref; },
[&](DeprecatedString const&) -> RefPtr<Object>& { return ref; },
[&](ByteString const&) -> RefPtr<Object>& { return ref; },
[&](float const&) -> RefPtr<Object>& { return ref; });
EXPECT_EQ(ref, value);
@ -223,7 +223,7 @@ struct HoldsFloat {
TEST_CASE(copy_assign)
{
{
Variant<int, DeprecatedString, float> the_value { 42.0f };
Variant<int, ByteString, float> the_value { 42.0f };
VERIFY(the_value.has<float>());
EXPECT_EQ(the_value.get<float>(), 42.0f);
@ -233,12 +233,12 @@ TEST_CASE(copy_assign)
VERIFY(the_value.has<int>());
EXPECT_EQ(the_value.get<int>(), 12);
the_value = DeprecatedString("Hello, world!");
VERIFY(the_value.has<DeprecatedString>());
EXPECT_EQ(the_value.get<DeprecatedString>(), "Hello, world!");
the_value = ByteString("Hello, world!");
VERIFY(the_value.has<ByteString>());
EXPECT_EQ(the_value.get<ByteString>(), "Hello, world!");
}
{
Variant<HoldsInt, DeprecatedString, HoldsFloat> the_value { HoldsFloat { 42.0f } };
Variant<HoldsInt, ByteString, HoldsFloat> the_value { HoldsFloat { 42.0f } };
VERIFY(the_value.has<HoldsFloat>());
EXPECT_EQ(the_value.get<HoldsFloat>().f, 42.0f);
@ -248,9 +248,9 @@ TEST_CASE(copy_assign)
VERIFY(the_value.has<HoldsInt>());
EXPECT_EQ(the_value.get<HoldsInt>().i, 12);
the_value = DeprecatedString("Hello, world!");
VERIFY(the_value.has<DeprecatedString>());
EXPECT_EQ(the_value.get<DeprecatedString>(), "Hello, world!");
the_value = ByteString("Hello, world!");
VERIFY(the_value.has<ByteString>());
EXPECT_EQ(the_value.get<ByteString>(), "Hello, world!");
}
}

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/OwnPtr.h>
#include <AK/ReverseIterator.h>
#include <AK/String.h>
@ -38,18 +38,18 @@ TEST_CASE(ints)
TEST_CASE(strings)
{
Vector<DeprecatedString> strings;
Vector<ByteString> strings;
strings.append("ABC");
strings.append("DEF");
int loop_counter = 0;
for (DeprecatedString const& string : strings) {
for (ByteString const& string : strings) {
EXPECT(!string.is_empty());
++loop_counter;
}
loop_counter = 0;
for (auto& string : (const_cast<Vector<DeprecatedString> const&>(strings))) {
for (auto& string : (const_cast<Vector<ByteString> const&>(strings))) {
EXPECT(!string.is_empty());
++loop_counter;
}
@ -58,7 +58,7 @@ TEST_CASE(strings)
TEST_CASE(strings_insert_ordered)
{
Vector<DeprecatedString> strings;
Vector<ByteString> strings;
strings.append("abc");
strings.append("def");
strings.append("ghi");
@ -161,12 +161,12 @@ TEST_CASE(vector_compare)
EXPECT_EQ(ints.size(), 1000u);
EXPECT_EQ(ints, same_ints);
Vector<DeprecatedString> strings;
Vector<DeprecatedString> same_strings;
Vector<ByteString> strings;
Vector<ByteString> same_strings;
for (int i = 0; i < 1000; ++i) {
strings.append(DeprecatedString::number(i));
same_strings.append(DeprecatedString::number(i));
strings.append(ByteString::number(i));
same_strings.append(ByteString::number(i));
}
EXPECT_EQ(strings.size(), 1000u);
@ -176,9 +176,9 @@ TEST_CASE(vector_compare)
TEST_CASE(grow_past_inline_capacity)
{
auto make_vector = [] {
Vector<DeprecatedString, 16> strings;
Vector<ByteString, 16> strings;
for (int i = 0; i < 32; ++i) {
strings.append(DeprecatedString::number(i));
strings.append(ByteString::number(i));
}
return strings;
};
@ -284,7 +284,7 @@ TEST_CASE(remove_all_matching)
TEST_CASE(nonnullownptrvector)
{
struct Object {
DeprecatedString string;
ByteString string;
};
Vector<NonnullOwnPtr<Object>> objects;

View file

@ -6,7 +6,7 @@
#include <LibTest/TestCase.h>
#include <AK/DeprecatedString.h>
#include <AK/ByteString.h>
#include <AK/WeakPtr.h>
#include <AK/Weakable.h>