mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-14 22:22:26 +00:00
Format and add test
This commit is contained in:
parent
11124b9ff0
commit
de190a4bfb
1 changed files with 10 additions and 2 deletions
|
@ -6,9 +6,9 @@ use super::Configurable;
|
||||||
use crate::config_file::Config;
|
use crate::config_file::Config;
|
||||||
use crate::print_error;
|
use crate::print_error;
|
||||||
|
|
||||||
use std::env;
|
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use std::env;
|
||||||
|
|
||||||
/// A collection of flags on how to use colors.
|
/// A collection of flags on how to use colors.
|
||||||
#[derive(Clone, Debug, Copy, PartialEq, Eq, Default)]
|
#[derive(Clone, Debug, Copy, PartialEq, Eq, Default)]
|
||||||
|
@ -93,7 +93,7 @@ impl Configurable<Self> for ColorOption {
|
||||||
|
|
||||||
fn from_environment() -> Option<Self> {
|
fn from_environment() -> Option<Self> {
|
||||||
if env::var("NO_COLOR").is_ok() {
|
if env::var("NO_COLOR").is_ok() {
|
||||||
return Some(Self::Never)
|
return Some(Self::Never);
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,8 @@ mod test_color_option {
|
||||||
use crate::config_file::{self, Config};
|
use crate::config_file::{self, Config};
|
||||||
use crate::flags::Configurable;
|
use crate::flags::Configurable;
|
||||||
|
|
||||||
|
use std::env::set_var;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_arg_matches_none() {
|
fn test_from_arg_matches_none() {
|
||||||
let argv = vec!["lsd"];
|
let argv = vec!["lsd"];
|
||||||
|
@ -152,6 +154,12 @@ mod test_color_option {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_from_env_no_color() {
|
||||||
|
set_var("NO_COLOR", "true");
|
||||||
|
assert_eq!(Some(ColorOption::Never), ColorOption::from_environment());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_arg_matches_classic_mode() {
|
fn test_from_arg_matches_classic_mode() {
|
||||||
let argv = vec!["lsd", "--color", "always", "--classic"];
|
let argv = vec!["lsd", "--color", "always", "--classic"];
|
||||||
|
|
Loading…
Reference in a new issue