mirror of
https://github.com/denisidoro/navi.git
synced 2026-07-17 16:49:25 +00:00
Fixed all test cases
This commit is contained in:
parent
85fc192f84
commit
40bd436afe
2 changed files with 14 additions and 21 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue