1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-06-03 17:10:50 +00:00
starship/tests/testsuite/shlvl.rs
Daniel A. White 0be9ffc0a1
feat(shlvl): Add shlvl module (#1385)
* initial commit of support for shlvl

* documentation for shlvl

* use a symbol instead

* test coverage for shlvl

* actually disable when the config says to

* fix docs

* tweak defaults some

* refactor from pr comments

* redisable

* return early to avoid indenting

* make default suffix empty space

* fixing tests after suffix change

* updating docs for format

* making shlvl compatible with formatting

* adding variables table for shlvl

* removing extra line

* doc clarity
2020-08-05 18:30:01 +02:00

160 lines
4.0 KiB
Rust

use ansi_term::{Color, Style};
use std::io;
use crate::common;
use crate::common::TestCommand;
const SHLVL_ENV_VAR: &str = "SHLVL";
fn style() -> Style {
// default style
Color::Yellow.bold()
}
#[test]
fn empty_config() -> io::Result<()> {
let output = common::render_module("shlvl")
.env_clear()
.use_config(toml::toml! {
[shlvl]
})
.env(SHLVL_ENV_VAR, "2")
.output()?;
let expected = "";
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn enabled() -> io::Result<()> {
let output = common::render_module("shlvl")
.env_clear()
.use_config(toml::toml! {
[shlvl]
disabled = false
})
.env(SHLVL_ENV_VAR, "2")
.output()?;
let expected = format!("{} ", style().paint("↕️ 2"));
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn no_level() -> io::Result<()> {
let output = common::render_module("shlvl")
.env_clear()
.use_config(toml::toml! {
[shlvl]
disabled = false
})
.output()?;
let expected = "";
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn enabled_config_level_1() -> io::Result<()> {
let output = common::render_module("shlvl")
.env_clear()
.use_config(toml::toml! {
[shlvl]
disabled = false
})
.env(SHLVL_ENV_VAR, "1")
.output()?;
let expected = "";
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn lower_threshold() -> io::Result<()> {
let output = common::render_module("shlvl")
.env_clear()
.use_config(toml::toml! {
[shlvl]
threshold = 1
disabled = false
})
.env(SHLVL_ENV_VAR, "1")
.output()?;
let expected = format!("{} ", style().paint("↕️ 1"));
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn higher_threshold() -> io::Result<()> {
let output = common::render_module("shlvl")
.env_clear()
.use_config(toml::toml! {
[shlvl]
threshold = 3
disabled = false
})
.env(SHLVL_ENV_VAR, "1")
.output()?;
let expected = "";
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn custom_style() -> io::Result<()> {
let output = common::render_module("shlvl")
.env_clear()
.use_config(toml::toml! {
[shlvl]
style = "Red Underline"
disabled = false
})
.env(SHLVL_ENV_VAR, "2")
.output()?;
let expected = format!("{} ", Color::Red.underline().paint("↕️ 2"));
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn custom_symbol() -> io::Result<()> {
let output = common::render_module("shlvl")
.env_clear()
.use_config(toml::toml! {
[shlvl]
symbol = "shlvl is "
disabled = false
})
.env(SHLVL_ENV_VAR, "2")
.output()?;
let expected = format!("{} ", style().paint("shlvl is 2"));
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}
#[test]
fn formatting() -> io::Result<()> {
let output = common::render_module("shlvl")
.env_clear()
.use_config(toml::toml! {
[shlvl]
format = "$symbol going down [$shlvl]($style) GOING UP "
disabled = false
})
.env(SHLVL_ENV_VAR, "2")
.output()?;
let expected = format!("↕️ going down {} GOING UP ", style().paint("2"));
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
Ok(())
}