Fixed all test cases

This commit is contained in:
emma31-dev 2026-04-13 12:34:59 +01:00
parent 85fc192f84
commit 40bd436afe
2 changed files with 14 additions and 21 deletions

View file

@ -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> {
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<Self, Self::Err> {
if let Some(c) = parse_ansi(ansi) {
Ok(Color(c))
} else {
Err("Invalid color")
}
assert!(is_ok);
}
}

View file

@ -98,12 +98,12 @@ pub fn cheat_paths(path: Option<String>) -> Result<String> {
///
/// 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<PathBuf> {
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<PathBuf> {
///
/// 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<PathBuf> {
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())
}