use std::fmt::Debug;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PatternComparisonError {
pub message: String,
pub differences: Vec<Difference>,
pub path: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Difference {
pub field: String,
pub expected: String,
pub actual: String,
}
#[derive(Debug, Clone)]
pub struct PatternComparisonOptions {
pub deep: bool,
pub ignore_fields: Vec<String>,
pub approximate_equality: bool,
}
impl Default for PatternComparisonOptions {
fn default() -> Self {
Self {
deep: true,
ignore_fields: Vec::new(),
approximate_equality: false,
}
}
}
#[derive(Debug, Clone, Default)]
pub struct ValidationRules {
pub max_depth: Option<usize>,
pub max_elements: Option<usize>,
pub required_fields: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ValidationError {
pub message: String,
pub rule_violated: String,
pub location: Vec<String>,
}
pub fn assert_patterns_equal<V>(
_actual: &V,
_expected: &V,
_msg: &str,
) -> Result<(), PatternComparisonError>
where
V: PartialEq + Debug,
{
Ok(())
}
pub fn assert_pattern_structure_valid<V>(
_pattern: &V,
_rules: &ValidationRules,
) -> Result<(), ValidationError>
where
V: Debug,
{
Ok(())
}
pub fn assert_patterns_equivalent<V>(
_pattern_a: &V,
_pattern_b: &V,
_options: &PatternComparisonOptions,
) -> Result<(), PatternComparisonError>
where
V: PartialEq + Debug,
{
Ok(())
}
use std::sync::atomic::{AtomicUsize, Ordering};
#[derive(Debug)]
pub struct EffectCounter {
count: AtomicUsize,
}
impl EffectCounter {
pub fn new() -> Self {
Self {
count: AtomicUsize::new(0),
}
}
pub fn increment(&self) {
self.count.fetch_add(1, Ordering::SeqCst);
}
pub fn count(&self) -> usize {
self.count.load(Ordering::SeqCst)
}
pub fn reset(&self) {
self.count.store(0, Ordering::SeqCst);
}
}
impl Default for EffectCounter {
fn default() -> Self {
Self::new()
}
}
impl Clone for EffectCounter {
fn clone(&self) -> Self {
Self {
count: AtomicUsize::new(self.count()),
}
}
}
pub fn counting_effect<'a, V, W, E, F>(
counter: &'a EffectCounter,
f: F,
) -> impl Fn(&V) -> Result<W, E> + 'a
where
F: Fn(&V) -> Result<W, E> + 'a,
V: 'a,
{
move |v| {
counter.increment();
f(v)
}
}