Skip to content

Commit

Permalink
cmd tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zdebra authored Mar 12, 2022
1 parent 103bb21 commit c69d759
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 0 deletions.
167 changes: 167 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,7 @@ html5ever = "0.25.1"
clap = "2.33.3"
lazy_static = "1.4.0"
url = "2.2.2"

[dev-dependencies]
assert_cmd = "2.0"
predicates = "2.1"
38 changes: 38 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use assert_cmd::Command;
use predicates::prelude::*;

macro_rules! cmd_success_tests {
($($name:ident: $value:expr,)*) => {
$(
#[test]
fn $name(){
let (stdin, args, expected) = $value;
Command::cargo_bin("htmlq")
.unwrap()
.args(args)
.write_stdin(stdin)
.assert()
.success()
.stdout(predicate::str::diff(expected));
}
)*
}
}

cmd_success_tests!(
find_by_class: (
"<html><head></head><body><div class=\"hi\"><a href=\"/foo/bar\">Hello</a></div></body></html>",
[".hi"],
"<div class=\"hi\"><a href=\"/foo/bar\">Hello</a></div>\n"
),
find_by_id: (
"<html><head></head><body><div id=\"my-id\"><a href=\"/foo/bar\">Hello</a></div></body></html>",
["#my-id"],
"<div id=\"my-id\"><a href=\"/foo/bar\">Hello</a></div>\n"
),
remove_links: (
"<html><head></head><body><div id=\"my-id\"><a href=\"/foo/bar\">Hello</a></div></body></html>",
["#my-id", "--remove-nodes", "a"],
"<div id=\"my-id\"></div>\n",
),
);

0 comments on commit c69d759

Please sign in to comment.