// SPDX-License-Identifier: BSD-2-Clause // author: Max Kellermann #include "util/IntrusiveForwardList.hxx" #include #include namespace { struct CharItem final : IntrusiveForwardListHook { char ch; constexpr CharItem(char _ch) noexcept:ch(_ch) {} }; static std::string ToString(const IntrusiveForwardList &list) noexcept { std::string result; for (const auto &i : list) result.push_back(i.ch); return result; } } // anonymous namespace TEST(IntrusiveForwardList, Basic) { using Item = CharItem; Item items[]{'a', 'b', 'c'}; IntrusiveForwardList list; ASSERT_EQ(ToString(list), ""); list.reverse(); ASSERT_EQ(ToString(list), ""); for (auto &i : items) list.push_front(i); ASSERT_EQ(ToString(list), "cba"); list.reverse(); ASSERT_EQ(ToString(list), "abc"); list.pop_front(); ASSERT_EQ(ToString(list), "bc"); list.reverse(); ASSERT_EQ(ToString(list), "cb"); }