mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 17:10:23 +00:00
6e19ab2bbc
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
63 lines
1.3 KiB
C++
63 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2020, Fei Wu <f.eiwu@yahoo.com>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibTest/TestCase.h>
|
|
|
|
#include <AK/CircularDeque.h>
|
|
#include <AK/DeprecatedString.h>
|
|
#include <AK/StdLibExtras.h>
|
|
|
|
TEST_CASE(enqueue_begin)
|
|
{
|
|
CircularDeque<int, 3> ints;
|
|
|
|
ints.enqueue_begin(0);
|
|
EXPECT_EQ(ints.size(), 1u);
|
|
EXPECT_EQ(ints.first(), 0);
|
|
|
|
ints.enqueue_begin(1);
|
|
EXPECT_EQ(ints.size(), 2u);
|
|
EXPECT_EQ(ints.first(), 1);
|
|
EXPECT_EQ(ints.last(), 0);
|
|
|
|
ints.enqueue_begin(2);
|
|
EXPECT_EQ(ints.size(), 3u);
|
|
EXPECT_EQ(ints.first(), 2);
|
|
EXPECT_EQ(ints.last(), 0);
|
|
|
|
ints.enqueue_begin(3);
|
|
EXPECT_EQ(ints.size(), 3u);
|
|
EXPECT_EQ(ints.first(), 3);
|
|
EXPECT_EQ(ints.at(1), 2);
|
|
EXPECT_EQ(ints.last(), 1);
|
|
}
|
|
|
|
TEST_CASE(enqueue_begin_being_moved_from)
|
|
{
|
|
CircularDeque<DeprecatedString, 2> strings;
|
|
|
|
DeprecatedString str { "test" };
|
|
strings.enqueue_begin(move(str));
|
|
EXPECT(str.is_null());
|
|
}
|
|
|
|
TEST_CASE(deque_end)
|
|
{
|
|
CircularDeque<int, 3> ints;
|
|
ints.enqueue(0);
|
|
ints.enqueue(1);
|
|
ints.enqueue(2);
|
|
EXPECT_EQ(ints.size(), 3u);
|
|
|
|
EXPECT_EQ(ints.dequeue_end(), 2);
|
|
EXPECT_EQ(ints.size(), 2u);
|
|
|
|
EXPECT_EQ(ints.dequeue_end(), 1);
|
|
EXPECT_EQ(ints.size(), 1u);
|
|
|
|
EXPECT_EQ(ints.dequeue_end(), 0);
|
|
EXPECT(ints.is_empty());
|
|
}
|