use rust_xmpp::csi::{Buffer, important}; use std::time::{Duration, Instant}; #[test] fn native_importance_rules() { for xml in [ "", "", "", "", "news", ] { assert!(!important(xml, &[]), "{xml}"); } for xml in [ " ", "", "", "", "", "", "", "", "", "", "hey", ] { assert!(important(xml, &[]), "{xml}"); } assert!(important( "", &["{example:ns}custom/part".into()] )); } #[test] fn bounded_queue_flush_delay_activity_and_grace() { let mut b = Buffer::default(); b.configure(2, Duration::from_secs(5), vec![]); b.set_inactive(true); let now = Instant::now(); assert!(b.output("".into(), "a@example", now).is_empty()); assert!(b.output("".into(), "a@example", now).is_empty()); let output = b.output("".into(), "a@example", now); assert_eq!(output.len(), 3); assert!(output[0].contains("urn:xmpp:delay")); assert!(output[0].contains("a@example")); assert_eq!(b.output("".into(), "a@example", now).len(), 1); assert!( b.output( "".into(), "a@example", now + Duration::from_secs(6) ) .is_empty() ); assert_eq!(b.activity(now + Duration::from_secs(6)).len(), 1); b.set_inactive(true); b.output("".into(), "a@example", now); assert_eq!(b.set_inactive(false).len(), 1); b.set_inactive(true); b.output("".into(), "a@example", now); b.reset(); assert!(b.activity(now).is_empty()); assert_eq!(b.output("".into(), "a@example", now).len(), 1); }