more unit tests, better highlighting
This commit is contained in:
27
src/tests/highlight.rs
Normal file
27
src/tests/highlight.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
|
||||
use insta::assert_snapshot;
|
||||
|
||||
use crate::prompt::highlight::FernHighlighter;
|
||||
|
||||
use super::super::*;
|
||||
|
||||
#[test]
|
||||
fn highlight_simple() {
|
||||
let line = "echo foo bar";
|
||||
let styled = FernHighlighter::new(line.to_string()).hl_input();
|
||||
assert_snapshot!(styled)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn highlight_cmd_sub() {
|
||||
let line = "echo foo $(echo bar)";
|
||||
let styled = FernHighlighter::new(line.to_string()).hl_input();
|
||||
assert_snapshot!(styled)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn highlight_cmd_sub_in_dquotes() {
|
||||
let line = "echo \"foo $(echo bar) biz\"";
|
||||
let styled = FernHighlighter::new(line.to_string()).hl_input();
|
||||
assert_snapshot!(styled)
|
||||
}
|
||||
@@ -24,6 +24,8 @@ pub mod expand;
|
||||
pub mod term;
|
||||
pub mod error;
|
||||
pub mod getopt;
|
||||
pub mod script;
|
||||
pub mod highlight;
|
||||
|
||||
/// Unsafe to use outside of tests
|
||||
pub fn get_nodes<F1>(input: &str, filter: F1) -> Vec<Node>
|
||||
|
||||
52
src/tests/script.rs
Normal file
52
src/tests/script.rs
Normal file
@@ -0,0 +1,52 @@
|
||||
use std::process::{self, Output};
|
||||
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::super::*;
|
||||
fn get_script_output(name: &str, args: &[&str]) -> Output {
|
||||
// Resolve the path to the fern binary.
|
||||
// Do not question me.
|
||||
let mut fern_path = env::current_exe()
|
||||
.expect("Failed to get test executable"); // The path to the test executable
|
||||
fern_path.pop(); // Hocus pocus
|
||||
fern_path.pop();
|
||||
fern_path.push("fern"); // Abra Kadabra
|
||||
|
||||
if !fern_path.is_file() {
|
||||
fern_path.pop();
|
||||
fern_path.pop();
|
||||
fern_path.push("release");
|
||||
fern_path.push("fern");
|
||||
}
|
||||
|
||||
if !fern_path.is_file() {
|
||||
panic!("where the hell is the binary")
|
||||
}
|
||||
|
||||
process::Command::new(fern_path) // Alakazam
|
||||
.arg(name)
|
||||
.args(args)
|
||||
.output()
|
||||
.expect("Failed to run script")
|
||||
}
|
||||
#[test]
|
||||
fn script_hello_world() {
|
||||
let output = get_script_output("./test_scripts/hello.sh", &[]);
|
||||
assert!(output.status.success());
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
assert_eq!(stdout.trim(), "Hello, World!")
|
||||
}
|
||||
#[test]
|
||||
fn script_cmdsub() {
|
||||
let output = get_script_output("./test_scripts/cmdsub.sh", &[]);
|
||||
assert!(output.status.success());
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
assert_eq!(stdout.trim(), "foo Hello bar")
|
||||
}
|
||||
#[test]
|
||||
fn script_multiline() {
|
||||
let output = get_script_output("./test_scripts/multiline.sh", &[]);
|
||||
assert!(output.status.success());
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
assert_eq!(stdout.trim(), "foo\nbar\nbiz\nbuzz")
|
||||
}
|
||||
@@ -3,8 +3,8 @@ source: src/tests/error.rs
|
||||
expression: err_fmt
|
||||
---
|
||||
[31m[1mParse Error[0m - Unclosed subshell
|
||||
[36m[1m->[0m [[36m[1m1[0m;[36m[1m1[0m]
|
||||
[36m[1m->[0m [[36m[1m1[0m;[36m[1m2[0m]
|
||||
[36m[1m |[0m
|
||||
[36m[1m1 |[0m (foo
|
||||
[36m[1m |[0m [31m[1m^[0m
|
||||
[36m[1m |[0m [31m[1m^[0m
|
||||
[36m[1m |[0m
|
||||
|
||||
Reference in New Issue
Block a user