45#include <doctest/doctest.h>
93template<
typename L,
typename Factory>
94[[nodiscard]]
auto build(Factory& f) {
104template<
typename L,
typename Factory>
108 SUBCASE(
"D-10: push_back emits one Insert with index=size_before") {
109 auto list = factory();
111 list->push_back(std::make_shared<T>());
112 REQUIRE(log.
events.size() == 1);
114 CHECK(log.
events[0].index == 0);
115 CHECK_FALSE(log.
events[0].item_was_null);
118 SUBCASE(
"D-10: remove_at emits one Remove with valid item ptr") {
119 auto list = factory();
120 list->push_back(std::make_shared<T>());
121 list->push_back(std::make_shared<T>());
124 REQUIRE(log.
events.size() == 1);
126 CHECK(log.
events[0].index == 0);
127 CHECK_FALSE(log.
events[0].item_was_null);
130 SUBCASE(
"D-10: clear emits one Reset with item == nullptr") {
131 auto list = factory();
132 list->push_back(std::make_shared<T>());
133 list->push_back(std::make_shared<T>());
136 REQUIRE(log.
events.size() == 1);
138 CHECK(log.
events[0].index == 0);
139 CHECK(log.
events[0].item_was_null);
147template<
typename L,
typename Factory>
151 SUBCASE(
"D-11: insert_range emits per-element Inserts in order") {
152 auto list = factory();
154 std::vector<std::shared_ptr<T>> in{
155 std::make_shared<T>(),
156 std::make_shared<T>(),
157 std::make_shared<T>(),
159 list->insert_range(0, in.begin(), in.end());
160 REQUIRE(log.
events.size() == 3);
162 CHECK(log.
events[0].index == 0);
164 CHECK(log.
events[1].index == 1);
166 CHECK(log.
events[2].index == 2);
169 SUBCASE(
"D-11: remove_range reports each Remove with index = pos") {
172 auto list = factory();
173 for (
int i = 0; i < 4; ++i) list->push_back(std::make_shared<T>());
175 list->remove_range(1, 2);
176 REQUIRE(log.
events.size() == 2);
178 CHECK(log.
events[0].index == 1);
180 CHECK(log.
events[1].index == 1);
188template<
typename L,
typename Factory>
192 SUBCASE(
"D-20: unsubscribe inside emit skips a pending observer") {
193 auto list = factory();
195 int hits_a = 0, hits_b = 0;
203 list->push_back(std::make_shared<T>());
208 list->push_back(std::make_shared<T>());
213 SUBCASE(
"D-21: throwing handler does not break siblings") {
214 auto list = factory();
217 throw std::runtime_error(
"naughty observer");
219 auto sub_count = list->observe([&](
const ListChange<T>&) { ++after; });
221 list->push_back(std::make_shared<T>());
234template<
typename L,
typename Factory>
236 static_assert(::aria::ListSource<L>,
237 "run_list_source_conformance<L>: L does not satisfy aria::ListSource. "
238 "See docs/list-diff-contract.md D-40.");
RAII handle to a single subscription.
Definition subscription.hpp:44
void release() noexcept
Explicitly disconnect now (instead of at destruction).
Definition subscription.hpp:83
Definition list_conformance.hpp:60
auto build(Factory &f)
Helper: most generic factory accepts a closure producing a shared_ptr<L>.
Definition list_conformance.hpp:94
Definition list_conformance.hpp:58
void check_batch_ops(Factory factory)
Definition list_conformance.hpp:148
void check_reentrancy(Factory factory)
Definition list_conformance.hpp:189
void run_list_source_conformance(Factory factory)
Definition list_conformance.hpp:235
void check_single_element_ops(Factory factory)
Definition list_conformance.hpp:105
typename detail::list_source_value_impl< std::remove_cvref_t< L > >::type list_source_value_t
Element type for a list source.
Definition list_source.hpp:76
ListChangeKind
Definition list_change.hpp:10
@ Remove
Definition list_change.hpp:10
@ Reset
Definition list_change.hpp:10
@ Insert
Definition list_change.hpp:10
An owning event in a sequential list edit stream.
Definition list_change.hpp:16
std::size_t index
Definition list_change.hpp:19
std::shared_ptr< T > item
Definition list_change.hpp:20
std::size_t from_index
Definition list_change.hpp:21
ListChangeKind kind
Definition list_change.hpp:18
Definition list_conformance.hpp:67
bool item_was_null
Definition list_conformance.hpp:71
ListChangeKind kind
Definition list_conformance.hpp:68
std::size_t from_index
Definition list_conformance.hpp:70
std::size_t index
Definition list_conformance.hpp:69
Tiny event log used by every conformance probe.
Definition list_conformance.hpp:66
Subscription sub
Definition list_conformance.hpp:75
std::vector< Entry > events
Definition list_conformance.hpp:74
EventLog(L &list)
Definition list_conformance.hpp:78