2019-06-06 14:18:00 +02:00
|
|
|
|
use ansi_term::Color;
|
|
|
|
|
use std::io;
|
|
|
|
|
|
2019-08-10 23:30:30 +02:00
|
|
|
|
use crate::common::{self, TestCommand};
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
|
|
|
|
#[test]
|
2020-07-08 00:45:32 +02:00
|
|
|
|
fn success_status() -> io::Result<()> {
|
2019-08-18 17:34:45 +02:00
|
|
|
|
let expected = format!("{} ", Color::Green.bold().paint("❯"));
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
|
|
|
|
// Status code 0
|
2019-07-19 22:18:52 +02:00
|
|
|
|
let output = common::render_module("character")
|
|
|
|
|
.arg("--status=0")
|
|
|
|
|
.output()?;
|
2019-06-06 14:18:00 +02:00
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
|
|
|
|
|
// No status code
|
2019-07-19 22:18:52 +02:00
|
|
|
|
let output = common::render_module("character").output()?;
|
2019-06-06 14:18:00 +02:00
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
assert_eq!(expected, actual);
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2020-07-08 00:45:32 +02:00
|
|
|
|
fn failure_status() -> io::Result<()> {
|
2019-08-18 17:34:45 +02:00
|
|
|
|
let expected = format!("{} ", Color::Red.bold().paint("❯"));
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
2019-08-10 23:30:30 +02:00
|
|
|
|
let exit_values = ["1", "54321", "-5000"];
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
2019-08-10 23:30:30 +02:00
|
|
|
|
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);
|
|
|
|
|
}
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
2019-08-10 23:30:30 +02:00
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2020-07-08 00:45:32 +02:00
|
|
|
|
fn custom_symbol() -> io::Result<()> {
|
2019-08-10 23:30:30 +02:00
|
|
|
|
let expected_fail = format!("{} ", Color::Red.bold().paint("✖"));
|
2020-07-08 00:45:32 +02:00
|
|
|
|
let expected_success = format!("{} ", Color::Green.bold().paint("➜"));
|
2019-08-10 23:30:30 +02:00
|
|
|
|
|
|
|
|
|
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]
|
2020-07-08 00:45:32 +02:00
|
|
|
|
success_symbol = "[➜](bold green)"
|
|
|
|
|
error_symbol = "[✖](bold red)"
|
|
|
|
|
|
2019-08-10 23:30:30 +02:00
|
|
|
|
})
|
|
|
|
|
.arg(arg)
|
|
|
|
|
.output()?;
|
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
|
|
|
|
assert_eq!(expected_fail, actual);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Test success
|
2019-07-19 22:18:52 +02:00
|
|
|
|
let output = common::render_module("character")
|
2019-08-10 23:30:30 +02:00
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
|
[character]
|
2020-07-08 00:45:32 +02:00
|
|
|
|
success_symbol = "[➜](bold green)"
|
|
|
|
|
error_symbol = "[✖](bold red)"
|
2019-08-10 23:30:30 +02:00
|
|
|
|
})
|
|
|
|
|
.arg("--status=0")
|
2019-06-06 14:18:00 +02:00
|
|
|
|
.output()?;
|
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2019-08-10 23:30:30 +02:00
|
|
|
|
assert_eq!(expected_success, actual);
|
2019-06-06 14:18:00 +02:00
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
2019-08-17 21:33:19 +02:00
|
|
|
|
|
|
|
|
|
#[test]
|
2020-07-08 00:45:32 +02:00
|
|
|
|
fn zsh_keymap() -> io::Result<()> {
|
|
|
|
|
let expected_vicmd = format!("{} ", Color::Green.bold().paint("❮"));
|
|
|
|
|
let expected_specified = format!("{} ", Color::Green.bold().paint("V"));
|
|
|
|
|
let expected_other = format!("{} ", Color::Green.bold().paint("❯"));
|
2019-08-17 21:33:19 +02:00
|
|
|
|
|
|
|
|
|
// zle keymap is vicmd
|
|
|
|
|
let output = common::render_module("character")
|
2019-08-31 09:59:18 +02:00
|
|
|
|
.env("STARSHIP_SHELL", "zsh")
|
2019-08-17 21:33:19 +02:00
|
|
|
|
.arg("--keymap=vicmd")
|
|
|
|
|
.output()?;
|
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-08 00:45:32 +02:00
|
|
|
|
assert_eq!(expected_vicmd, actual);
|
2019-08-17 21:33:19 +02:00
|
|
|
|
|
|
|
|
|
// specified vicmd character
|
|
|
|
|
let output = common::render_module("character")
|
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
|
[character]
|
2020-07-08 00:45:32 +02:00
|
|
|
|
vicmd_symbol = "[V](bold green)"
|
2019-08-17 21:33:19 +02:00
|
|
|
|
})
|
2019-08-31 09:59:18 +02:00
|
|
|
|
.env("STARSHIP_SHELL", "zsh")
|
2019-08-17 21:33:19 +02:00
|
|
|
|
.arg("--keymap=vicmd")
|
|
|
|
|
.output()?;
|
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-08 00:45:32 +02:00
|
|
|
|
assert_eq!(expected_specified, actual);
|
2019-08-17 21:33:19 +02:00
|
|
|
|
|
|
|
|
|
// zle keymap is other
|
|
|
|
|
let output = common::render_module("character")
|
2019-08-31 09:59:18 +02:00
|
|
|
|
.env("STARSHIP_SHELL", "zsh")
|
2019-08-17 21:33:19 +02:00
|
|
|
|
.arg("--keymap=visual")
|
|
|
|
|
.output()?;
|
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-08 00:45:32 +02:00
|
|
|
|
assert_eq!(expected_other, actual);
|
2019-08-31 09:59:18 +02:00
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
2020-07-08 00:45:32 +02:00
|
|
|
|
fn fish_keymap() -> io::Result<()> {
|
|
|
|
|
let expected_vicmd = format!("{} ", Color::Green.bold().paint("❮"));
|
|
|
|
|
let expected_specified = format!("{} ", Color::Green.bold().paint("V"));
|
|
|
|
|
let expected_other = format!("{} ", Color::Green.bold().paint("❯"));
|
2019-08-31 09:59:18 +02:00
|
|
|
|
|
|
|
|
|
// fish keymap is default
|
|
|
|
|
let output = common::render_module("character")
|
|
|
|
|
.env("STARSHIP_SHELL", "fish")
|
|
|
|
|
.arg("--keymap=default")
|
|
|
|
|
.output()?;
|
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-08 00:45:32 +02:00
|
|
|
|
assert_eq!(expected_vicmd, actual);
|
2019-08-31 09:59:18 +02:00
|
|
|
|
|
|
|
|
|
// specified vicmd character
|
|
|
|
|
let output = common::render_module("character")
|
|
|
|
|
.use_config(toml::toml! {
|
|
|
|
|
[character]
|
2020-07-08 00:45:32 +02:00
|
|
|
|
vicmd_symbol = "[V](bold green)"
|
2019-08-31 09:59:18 +02:00
|
|
|
|
})
|
|
|
|
|
.env("STARSHIP_SHELL", "fish")
|
|
|
|
|
.arg("--keymap=default")
|
|
|
|
|
.output()?;
|
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-08 00:45:32 +02:00
|
|
|
|
assert_eq!(expected_specified, actual);
|
2019-08-31 09:59:18 +02:00
|
|
|
|
|
|
|
|
|
// fish keymap is other
|
|
|
|
|
let output = common::render_module("character")
|
|
|
|
|
.env("STARSHIP_SHELL", "fish")
|
|
|
|
|
.arg("--keymap=visual")
|
|
|
|
|
.output()?;
|
|
|
|
|
let actual = String::from_utf8(output.stdout).unwrap();
|
2020-07-08 00:45:32 +02:00
|
|
|
|
assert_eq!(expected_other, actual);
|
2019-08-17 21:33:19 +02:00
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|