use super::*;
#[test]
fn hook_error_display() {
let errors: &[HookError] = &[
HookError::Unsupported,
HookError::AccessibilityDenied,
HookError::MacOsTap("test reason".into()),
#[cfg(target_os = "linux")]
HookError::NoDeviceFound,
#[cfg(target_os = "linux")]
HookError::Linux(std::io::Error::other("test reason")),
];
for e in errors {
assert!(!e.to_string().is_empty(), "empty display for {e:?}");
}
}
#[test]
fn mouse_event_clone_and_debug() {
let events = [
MouseEvent::Button {
id: ButtonId::Back,
pressed: true,
},
MouseEvent::Scroll {
delta_x: 1.0,
delta_y: -1.5,
},
];
for e in &events {
let cloned = e.clone();
let _ = format!("{e:?}");
let _ = format!("{cloned:?}");
}
}
#[test]
fn event_disposition_equality() {
assert_eq!(EventDisposition::PassThrough, EventDisposition::PassThrough);
assert_eq!(EventDisposition::Suppress, EventDisposition::Suppress);
assert_ne!(EventDisposition::PassThrough, EventDisposition::Suppress);
}
#[cfg(not(any(target_os = "macos", target_os = "linux")))]
#[test]
fn unsupported_start_returns_unsupported() {
let result = Hook::start(|_| EventDisposition::PassThrough);
assert!(matches!(result, Err(HookError::Unsupported)));
}
#[cfg(target_os = "linux")]
#[test]
fn linux_start_does_not_return_unsupported() {
let result = Hook::start(|_| EventDisposition::PassThrough);
assert!(
!matches!(result, Err(HookError::Unsupported)),
"Hook::start returned Unsupported on Linux"
);
if let Ok(hook) = result {
hook.stop();
}
}
#[cfg(not(target_os = "macos"))]
#[test]
fn non_macos_has_accessibility_is_true() {
assert!(Hook::has_accessibility());
}