use super::{is_paste_modifier, paste_key_available_from_env, paste_rpc_enabled};
use evdev::KeyCode;
use tempfile::tempdir;

#[test]
fn paste_rpc_disabled_when_env_off() {
    assert!(!paste_rpc_enabled(false, false));
    assert!(!paste_rpc_enabled(false, true));
}

#[test]
fn paste_rpc_disabled_without_key() {
    assert!(!paste_rpc_enabled(true, false));
}

#[test]
fn paste_rpc_enabled_with_key() {
    assert!(paste_rpc_enabled(true, true));
}

#[test]
fn paste_key_detection_accepts_explicit_key_file() {
    let dir = tempdir().expect("tempdir");
    let path = dir.path().join("paste-key");
    std::fs::write(
        &path,
        "hex:00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff",
    )
    .expect("write key file");
    temp_env::with_vars(
        [
            ("LESAVKA_PASTE_KEY", None::<&str>),
            ("LESAVKA_PASTE_KEY_FILE", path.to_str()),
        ],
        || {
            assert!(paste_key_available_from_env());
        },
    );
}

#[test]
fn paste_modifier_recognizes_ctrl_alt_only() {
    assert!(is_paste_modifier(KeyCode::KEY_LEFTCTRL));
    assert!(is_paste_modifier(KeyCode::KEY_RIGHTCTRL));
    assert!(is_paste_modifier(KeyCode::KEY_LEFTALT));
    assert!(is_paste_modifier(KeyCode::KEY_RIGHTALT));
    assert!(!is_paste_modifier(KeyCode::KEY_V));
    assert!(!is_paste_modifier(KeyCode::KEY_LEFTSHIFT));
}
