Profile::default() + T13 cadence-clamp unit test
Profile and Mode derive Default so the T13 cadence-clamp test can build a Session without a real profile file. Mode uses #[default] on the Maps variant (the natural first option). The T13 unit test walks ENBOXER_MOUSE_REPEAT_MS through valid values (1, 50, 2000) and out-of-range or malformed (0, 2001, non-numeric, empty) and asserts the session field reads back the in-range value or the 50 ms default respectively. cargo test 99+/0; clippy clean.
This commit is contained in:
parent
0ec7957224
commit
b6937158e4
@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
pub struct Profile {
|
||||
pub name: String,
|
||||
#[serde(default = "default_client")]
|
||||
@ -63,10 +63,14 @@ fn default_mode() -> Mode {
|
||||
Mode::Maps
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[derive(
|
||||
Debug, Clone, Copy, PartialEq, Eq, Default,
|
||||
Serialize, Deserialize,
|
||||
)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum Mode {
|
||||
/// 1: only configured maps; everything else goes to the front window
|
||||
#[default]
|
||||
Maps,
|
||||
/// 2: clone keys to the other game windows (front window still gets the real key)
|
||||
#[serde(alias = "repeater")]
|
||||
|
||||
@ -1252,6 +1252,43 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mouse_repeat_ms_clamps_env_var() {
|
||||
// The default cadence is 50 ms when the env var is unset
|
||||
// or malformed; explicit values in [1, 2000] pass through;
|
||||
// out-of-range values fall back to 50. We assert the bounds
|
||||
// by reading back Session.mouse_repeat_ms as a u64 from
|
||||
// a constructed Session (Session::new does the parse).
|
||||
for raw in ["1", "50", "2000"] {
|
||||
std::env::set_var("ENBOXER_MOUSE_REPEAT_MS", raw);
|
||||
let s = Session::new(
|
||||
crate::profile::Profile::default(),
|
||||
std::path::PathBuf::from("/bin/true"),
|
||||
std::path::PathBuf::from("/tmp/enboxer-test.sock"),
|
||||
)
|
||||
.expect("Session::new should succeed for a valid profile");
|
||||
let v: u64 = raw.parse().unwrap();
|
||||
assert_eq!(
|
||||
s.mouse_repeat_ms, v,
|
||||
"ENBOXER_MOUSE_REPEAT_MS={raw} should pass through"
|
||||
);
|
||||
}
|
||||
for raw in ["0", "2001", "not_a_number", ""] {
|
||||
std::env::set_var("ENBOXER_MOUSE_REPEAT_MS", raw);
|
||||
let s = Session::new(
|
||||
crate::profile::Profile::default(),
|
||||
std::path::PathBuf::from("/bin/true"),
|
||||
std::path::PathBuf::from("/tmp/enboxer-test.sock"),
|
||||
)
|
||||
.expect("Session::new should succeed for a valid profile");
|
||||
assert_eq!(
|
||||
s.mouse_repeat_ms, 50,
|
||||
"ENBOXER_MOUSE_REPEAT_MS={raw} should fall back to 50"
|
||||
);
|
||||
}
|
||||
std::env::remove_var("ENBOXER_MOUSE_REPEAT_MS");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn others_excludes_leader() {
|
||||
let slots = vec![
|
||||
|
||||
Loading…
Reference in New Issue
Block a user