#[macro_use]
#[cfg(feature = "dummy_serialization")]
extern crate serde;
pub mod filters;
mod counters;
mod table;
pub use crate::counters::*;
pub use crate::table::*;
mod noop;
#[cfg(feature="debug_counters")]
pub type DebugCounters = Counters;
#[cfg(not(feature="debug_counters"))]
pub type DebugCounters = crate::noop::Counters;
#[cfg(feature="debug_counters")]
pub type DebugTable = Table;
#[cfg(not(feature="debug_counters"))]
pub type DebugTable = crate::noop::Table;
#[cfg(feature = "dummy_serialization")]
#[cfg_attr(feature = "dummy_serialization", derive(Serialize, Deserialize))]
struct Dummy;
#[test]
fn it_works() {
use crate::filters::*;
let counters = Counters::new();
counters.event("foo::bar");
counters.event("foo::bar");
counters.event("foo::baz");
counters.event("meh");
counters.event("fooo");
assert_eq!(counters.get("foo::bar"), 2);
assert_eq!(counters.get("foo::baz"), 1);
assert_eq!(counters.accumulate("foo::"), 3);
counters.apply(Contains("foo::bar"), |_, val| val * 2);
assert_eq!(counters.get("foo::bar"), 4);
counters.reset_events(EndsWith("bar"));
assert_eq!(counters.get("foo::bar"), 0);
assert_eq!(counters.get("foo::baz"), 1);
assert_eq!(counters.accumulate("foo::"), 1);
counters.retain(Select(|key, _| key == "meh"));
counters.reset_all();
assert_eq!(counters.get("foo::bar"), 0);
assert_eq!(counters.get("foo::baz"), 0);
assert_eq!(counters.accumulate("foo::"), 0);
}
#[test]
fn noop() {
use crate::filters::*;
let counters = DebugCounters::new();
counters.event("foo::bar");
counters.event("foo::bar");
counters.event("foo::baz");
counters.event("meh");
counters.event("fooo");
assert_eq!(counters.get("foo::bar"), 0);
assert_eq!(counters.get("foo::baz"), 0);
assert_eq!(counters.accumulate("foo::"), 0);
counters.apply(Contains("foo::bar"), |_, val| val * 2);
assert_eq!(counters.get("foo::bar"), 0);
counters.reset_events(EndsWith("bar"));
assert_eq!(counters.get("foo::bar"), 0);
assert_eq!(counters.get("foo::baz"), 0);
assert_eq!(counters.accumulate("foo::"), 0);
counters.reset_all();
assert_eq!(counters.get("foo::bar"), 0);
assert_eq!(counters.get("foo::baz"), 0);
assert_eq!(counters.accumulate("foo::"), 0);
}