refactor: move module tests into their files and startup into app::run

This commit is contained in:
2026-11-06 07:35:49 +08:00
parent 3ecf96fb04
commit a5c0b0801d
6 changed files with 790 additions and 800 deletions

View File

@@ -9,7 +9,7 @@ use tao::window::{Theme, Window};
pub const DEFAULT_W: f64 = 900.0;
pub const DEFAULT_H: f64 = 700.0;
use crate::UserEvent;
use crate::app::UserEvent;
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
pub enum ThemeChoice {
@@ -210,3 +210,26 @@ pub fn centered_geom(event_loop: &EventLoop<UserEvent>) -> WindowGeom {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn zoom_percent_is_clamped_to_supported_range() {
assert_eq!(clamp_zoom(10), 50);
assert_eq!(clamp_zoom(50), 50);
assert_eq!(clamp_zoom(105), 105);
assert_eq!(clamp_zoom(300), 300);
assert_eq!(clamp_zoom(999), 300);
}
#[test]
fn theme_choice_parses_menu_values() {
assert_eq!(ThemeChoice::from_str("system"), ThemeChoice::System);
assert_eq!(ThemeChoice::from_str("light"), ThemeChoice::Light);
assert_eq!(ThemeChoice::from_str("dark"), ThemeChoice::Dark);
assert_eq!(ThemeChoice::from_str("unexpected"), ThemeChoice::System);
assert_eq!(ThemeChoice::Dark.as_str(), "dark");
}
}