30 lines
1.1 KiB
Rust
30 lines
1.1 KiB
Rust
use assert_cmd::Command;
|
|
use test_case::test_case;
|
|
|
|
static HTML: &str = "<h1 id=\"title\"> Heading </h1>";
|
|
static ID: &str = "title";
|
|
static SELECTOR: &str = "h1";
|
|
static TEXT: &str = " Heading ";
|
|
|
|
#[test]
|
|
fn test_stdin() {
|
|
let mut cmd = Command::cargo_bin("select-html").unwrap();
|
|
cmd.pipe_stdin("tests/full.html").unwrap();
|
|
cmd.args([SELECTOR]);
|
|
cmd.assert().success().stdout(format!("{HTML}\n"));
|
|
}
|
|
|
|
#[test_case("full", &[SELECTOR, "--attribute", "id"], ID; "attribute full")]
|
|
#[test_case("partial", &[SELECTOR, "-a", "id"], ID; "attribute partial")]
|
|
#[test_case("full", &[SELECTOR, "--text"], TEXT; "text full")]
|
|
#[test_case("partial", &[SELECTOR, "-t"], TEXT; "text partial")]
|
|
#[test_case("full", &[SELECTOR, "-t", "--trim"], TEXT.trim(); "trim full")]
|
|
#[test_case("partial", &[SELECTOR, "-t", "--trim"], TEXT.trim(); "trim partial")]
|
|
fn test_args(file: &str, args: &[&str], output: &str) {
|
|
let file = format!("tests/{file}.html");
|
|
let mut cmd = Command::cargo_bin("select-html").unwrap();
|
|
cmd.args(args);
|
|
cmd.args(["--file", &file]);
|
|
cmd.assert().success().stdout(format!("{output}\n"));
|
|
}
|