use core::future::Future;
use core::task::{Context, Poll, Waker};
use std::sync::Arc;
use std::task::Wake;
use std::thread::Thread;
#[macro_export]
macro_rules! for_each_event_store_rule {
($($callback:tt)+) => {
$($callback)+! {
two_fixture_instances_observe_none_of_each_others_appends,
two_handles_observe_each_others_appends,
acknowledged_writes_survive_a_reopen,
query_all_matches_every_event,
query_item_types_are_or,
query_item_tags_are_and,
query_item_tags_match_supersets,
query_item_rejects_partial_tag_overlap,
query_item_combines_types_and_tags_with_and,
query_items_are_or,
untagged_events_match_query_all,
duplicate_items_do_not_duplicate_events,
query_item_order_does_not_change_the_result_set,
query_matching_nothing_yields_empty,
query_union_is_item_concatenation,
read_from_is_inclusive,
read_backwards_reverses_order,
read_limit_truncates,
read_backwards_from_with_limit,
read_defaults_to_ascending_order,
reading_an_empty_store_yields_nothing,
read_limit_applies_after_filtering,
read_backwards_limit_applies_after_filtering,
read_from_composes_with_multi_item_query,
read_from_composes_with_limit,
read_to_is_inclusive,
read_from_and_to_bound_a_closed_window,
read_to_under_backwards_bounds_the_older_end,
read_to_composes_with_multi_item_query,
read_limit_zero_yields_nothing,
limit_applies_across_items_not_per_item,
read_to_composes_with_limit,
read_from_a_gap_position,
positions_are_unique,
positions_are_strictly_monotonic,
head_of_an_empty_store_is_none,
head_is_the_highest_visible_position,
head_advances_across_two_handles,
append_stamps_identity_and_time,
append_stamps_a_local_event_id,
event_ids_are_unique_within_a_store,
appending_equal_events_yields_two_events,
event_id_is_not_matchable_by_query,
reopened_store_does_not_reissue_an_event_id,
append_stamps_a_recorded_time,
recorded_time_survives_a_reopen,
contains_event_id_reports_membership,
contains_event_id_reports_a_held_row_above_the_frontier,
append_returns_last_written_position,
append_is_atomic,
append_is_atomic_under_a_mid_batch_fault,
arming_a_mid_batch_fault_makes_the_append_fail,
append_rejects_empty_batch,
empty_batch_is_refused_before_the_condition_is_evaluated,
append_preserves_event_payload,
batch_positions_follow_slice_order,
batch_is_not_evaluated_against_its_own_condition,
dropped_append_future_leaves_no_partial_batch,
reissued_conditional_batch_lands_once,
reissued_unconditional_batch_lands_twice,
reissued_batch_conditioned_on_other_events_lands_twice,
append_preserves_an_empty_payload,
metadata_distinguishes_absent_from_empty,
store_accepts_a_max_length_identifier,
store_accepts_non_ascii_identifiers,
store_accepts_the_guaranteed_minimum_payload,
store_accepts_the_guaranteed_minimum_tag_count,
store_evaluates_a_query_at_the_guaranteed_minimum_item_count,
store_accepts_the_guaranteed_minimum_batch_size,
tags_differing_only_by_unicode_normalisation_are_distinct,
tags_may_repeat_a_key,
append_preserves_event_type_and_tags_byte_for_byte,
append_reports_exceeded_store_limits,
condition_without_after_rejects_any_match,
condition_without_after_allows_non_match,
condition_matches_on_every_tag_in_an_item,
condition_matching_every_tag_rejects_the_append,
condition_after_ignores_events_at_the_boundary,
condition_after_rejects_events_beyond_the_boundary,
condition_after_ignores_non_matching_events,
condition_matches_on_tags,
condition_with_an_unheld_tag_does_not_reject,
condition_against_an_empty_store_admits_the_append,
condition_after_beyond_head_admits_the_append,
condition_after_beyond_the_last_matching_position_admits_the_append,
condition_rejection_leaves_store_unchanged,
condition_rejection_is_reported_as_condition_violated,
condition_guards_carry_independent_boundaries,
condition_with_one_guard_behaves_as_today,
racing_conditional_appends_elect_one_winner,
interleaved_appends_on_one_handle_elect_one_winner,
a_live_read_stream_does_not_block_an_append,
read_result_is_stable_under_concurrent_append,
query_items_share_one_snapshot,
arming_a_read_fault_makes_the_stream_yield_an_error,
nothing_below_an_observed_position_appears_later,
}
};
}
#[macro_export]
macro_rules! emit_tokio {
($($name:ident),* $(,)?) => {
$(
#[tokio::test]
async fn $name() {
$crate::__private::rules::$name(__conformance_fixture)
.await
.report(::core::stringify!($name));
}
)*
};
}
#[macro_export]
macro_rules! emit_blocking {
($($name:ident),* $(,)?) => {
$(
#[test]
fn $name() {
$crate::__private::block_on($crate::__private::rules::$name(__conformance_fixture))
.report(::core::stringify!($name));
}
)*
};
}
#[macro_export]
macro_rules! emit_wasm {
($($name:ident),* $(,)?) => {
$(
#[::wasm_bindgen_test::wasm_bindgen_test]
async fn $name() {
let __outcome = $crate::__private::rules::$name(__conformance_fixture).await;
if let Some(__line) = __outcome.skip_line(::core::stringify!($name)) {
::wasm_bindgen_test::console_log!("{}", __line);
}
}
)*
};
}
#[doc(hidden)]
#[macro_export]
macro_rules! __rule_names {
($($name:ident),* $(,)?) => { [ $( ::core::stringify!($name) ),* ] };
}
struct ParkWaker(Thread);
impl Wake for ParkWaker {
fn wake(self: Arc<Self>) {
self.0.unpark();
}
}
pub fn block_on<F: Future>(future: F) -> F::Output {
let waker = Waker::from(Arc::new(ParkWaker(std::thread::current())));
let mut context = Context::from_waker(&waker);
let mut future = Box::pin(future);
loop {
match future.as_mut().poll(&mut context) {
Poll::Ready(value) => return value,
Poll::Pending => std::thread::park(),
}
}
}
#[cfg(test)]
fn declared_rules() -> Vec<&'static str> {
const SOURCE: &str = include_str!("suite.rs");
const PREFIX: &str = " pub async fn ";
SOURCE
.lines()
.filter_map(|line| line.strip_prefix(PREFIX))
.map(|rest| {
rest.split(|c: char| !c.is_alphanumeric() && c != '_')
.next()
.unwrap_or("")
})
.collect()
}
#[cfg(test)]
#[test]
fn no_orphan_rules() {
let registered = crate::for_each_event_store_rule!(crate::__rule_names);
let declared = declared_rules();
let orphans: Vec<_> = declared
.iter()
.filter(|name| !registered.contains(*name))
.collect();
assert!(
orphans.is_empty(),
"these rules exist in `rules` but are absent from \
`for_each_event_store_rule!`, so no harness runs them: {orphans:?}"
);
let missing: Vec<_> = registered
.iter()
.filter(|name| !declared.contains(*name))
.collect();
assert!(
missing.is_empty(),
"these rules are registered but were not found in `suite.rs` — either \
they moved, or the source scan no longer matches the way they are \
written: {missing:?}"
);
}