From 40bd436afe5c7d7262164608894f5ac11a485b32 Mon Sep 17 00:00:00 2001 From: emma31-dev Date: Mon, 13 Apr 2026 12:34:59 +0100 Subject: [PATCH] Fixed all test cases --- src/common/terminal.rs | 23 ++++++++--------------- src/filesystem.rs | 12 ++++++------ 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/common/terminal.rs b/src/common/terminal.rs index b88bf41..7b557e0 100644 --- a/src/common/terminal.rs +++ b/src/common/terminal.rs @@ -1,5 +1,4 @@ use crate::prelude::*; -use crossterm::style; use crossterm::terminal; use std::process::Command; @@ -45,21 +44,15 @@ pub fn width() -> u16 { } } -pub fn parse_ansi(ansi: &str) -> Option { - style::Color::parse_ansi(&format!("5;{ansi}")) -} +#[cfg(test)] +mod tests { + use super::*; -#[derive(Debug, Clone)] -pub struct Color(#[allow(unused)] pub style::Color); // suppress warning: field `0` is never read. + #[test] + fn test_width_with_shell_out() { + let result = width_with_shell_out().expect("Shell error"); + let is_ok = if result == 0 { false } else { true }; -impl FromStr for Color { - type Err = &'static str; - - fn from_str(ansi: &str) -> Result { - if let Some(c) = parse_ansi(ansi) { - Ok(Color(c)) - } else { - Err("Invalid color") - } + assert!(is_ok); } } diff --git a/src/filesystem.rs b/src/filesystem.rs index 4d0b4e5..62b0b3a 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -98,12 +98,12 @@ pub fn cheat_paths(path: Option) -> Result { /// /// We are currently handling two cases: When the platform is `macOS` and when the platform isn't (including `Windows` and `Linux/Unix` platforms) fn get_data_dir_by_platform() -> Result { - if cfg!(target_os = "macos") { - let base_dirs = etcetera::base_strategy::Apple::new()?; + if cfg!(target_os = "windows") { + let base_dirs = etcetera::choose_base_strategy()?; Ok(base_dirs.data_dir()) } else { - let base_dirs = etcetera::choose_base_strategy()?; + let base_dirs = etcetera::base_strategy::Xdg::new()?; Ok(base_dirs.data_dir()) } @@ -113,12 +113,12 @@ fn get_data_dir_by_platform() -> Result { /// /// We are currently handling two cases: When the platform is `macOS` and when the platform isn't (including `Windows` and `Linux/Unix` platforms) fn get_config_dir_by_platform() -> Result { - if cfg!(target_os = "macos") { - let base_dirs = etcetera::base_strategy::Apple::new()?; + if cfg!(target_os = "windows") { + let base_dirs = etcetera::choose_base_strategy()?; Ok(base_dirs.config_dir()) } else { - let base_dirs = etcetera::choose_base_strategy()?; + let base_dirs = etcetera::base_strategy::Xdg::new()?; Ok(base_dirs.config_dir()) }