mirror of
https://github.com/starship/starship.git
synced 2026-06-23 02:05:51 +07:00
feat: Add configuration to change the character for non-zero sta… (#133)
Prompt can now switch characters in addition to switching character color. Add configuration options in so that users can do either, both, or neither.
This commit is contained in:
committed by
Matan Kushner
parent
994a865d4d
commit
39598ec691
@@ -1,7 +1,7 @@
|
||||
use ansi_term::Color;
|
||||
use std::io;
|
||||
|
||||
use crate::common;
|
||||
use crate::common::{self, TestCommand};
|
||||
|
||||
#[test]
|
||||
fn char_module_success_status() -> io::Result<()> {
|
||||
@@ -26,26 +26,49 @@ fn char_module_success_status() -> io::Result<()> {
|
||||
fn char_module_failure_status() -> io::Result<()> {
|
||||
let expected = format!("{} ", Color::Red.bold().paint("➜"));
|
||||
|
||||
// Error status code 1
|
||||
let output = common::render_module("character")
|
||||
.arg("--status=1")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
let exit_values = ["1", "54321", "-5000"];
|
||||
|
||||
// Random non-zero status code
|
||||
let output = common::render_module("character")
|
||||
.arg("--status=54321")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
|
||||
// Negative status code!?
|
||||
let output = common::render_module("character")
|
||||
.arg("--status=-5000")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
for status in exit_values.iter() {
|
||||
let arg = format!("--status={}", status);
|
||||
let output = common::render_module("character").arg(arg).output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn char_module_symbolyes_status() -> io::Result<()> {
|
||||
let expected_fail = format!("{} ", Color::Red.bold().paint("✖"));
|
||||
let expected_success = format!("{} ", Color::Green.bold().paint("➜"));
|
||||
|
||||
let exit_values = ["1", "54321", "-5000"];
|
||||
|
||||
// Test failure values
|
||||
for status in exit_values.iter() {
|
||||
let arg = format!("--status={}", status);
|
||||
let output = common::render_module("character")
|
||||
.use_config(toml::toml! {
|
||||
[character]
|
||||
use_symbol_for_status = true
|
||||
})
|
||||
.arg(arg)
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
assert_eq!(expected_fail, actual);
|
||||
}
|
||||
|
||||
// Test success
|
||||
let output = common::render_module("character")
|
||||
.use_config(toml::toml! {
|
||||
[character]
|
||||
use_symbol_for_status = true
|
||||
})
|
||||
.arg("--status=0")
|
||||
.output()?;
|
||||
let actual = String::from_utf8(output.stdout).unwrap();
|
||||
assert_eq!(expected_success, actual);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user