diff options
author | Brian Gianforcaro <bgianf@serenityos.org> | 2021-06-15 02:33:59 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-16 10:40:01 +0200 |
commit | b7f8343f87a59b60fd4e2116eac3918b93adeebf (patch) | |
tree | 906a882cd4363cf42de33386cbcab000053ae189 /Tests | |
parent | 4586668fc38ecd14ab14b78eb4a44c41469f67d5 (diff) | |
download | serenity-b7f8343f87a59b60fd4e2116eac3918b93adeebf.zip |
AK+Tests: Add IntrusiveList<T,...>::insert_before(..) method
The insert_before method on AK::InlineLinkedList is used, so in order to
achieve feature parity, we need to implement it for AK::IntrusiveList as
well.
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/AK/TestIntrusiveList.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Tests/AK/TestIntrusiveList.cpp b/Tests/AK/TestIntrusiveList.cpp index 84f1d9f2c2..923de96f3e 100644 --- a/Tests/AK/TestIntrusiveList.cpp +++ b/Tests/AK/TestIntrusiveList.cpp @@ -33,6 +33,32 @@ TEST_CASE(insert) delete list.take_last(); } +TEST_CASE(insert_before) +{ + IntrusiveTestList list; + auto two = new IntrusiveTestItem(); + list.append(*two); + auto zero = new IntrusiveTestItem(); + list.append(*zero); + auto one = new IntrusiveTestItem(); + list.insert_before(*zero, *one); + + EXPECT_EQ(list.first(), two); + EXPECT_EQ(list.last(), zero); + EXPECT(list.contains(*zero)); + EXPECT(list.contains(*one)); + EXPECT(list.contains(*two)); + + EXPECT(zero->m_list_node.is_in_list()); + EXPECT(one->m_list_node.is_in_list()); + EXPECT(two->m_list_node.is_in_list()); + EXPECT_EQ(list.size_slow(), 3u); + + while (auto elem = list.take_first()) { + delete elem; + } +} + TEST_CASE(enumeration) { constexpr size_t expected_size = 10; |