Skip to content

Commit 6e31bc8

Browse files
committed
Merge branch 'zdebra-master'
2 parents 2e79d8c + bdb1071 commit 6e31bc8

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ html5ever = "0.25.1"
1919
clap = "2.33.3"
2020
lazy_static = "1.4.0"
2121
url = "2.2.2"
22+
23+
[dev-dependencies]
24+
assert_cmd = "2.0"
25+
predicates = "2.1"

tests/cli.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
use assert_cmd::Command;
2+
use predicates::prelude::*;
3+
4+
macro_rules! cmd_success_tests {
5+
($($name:ident: $value:expr,)*) => {
6+
$(
7+
#[test]
8+
fn $name(){
9+
let (stdin, args, expected) = $value;
10+
Command::cargo_bin("htmlq")
11+
.unwrap()
12+
.args(args)
13+
.write_stdin(stdin)
14+
.assert()
15+
.success()
16+
.stdout(predicate::str::diff(expected));
17+
}
18+
)*
19+
}
20+
}
21+
22+
cmd_success_tests!(
23+
find_by_class: (
24+
"<html><head></head><body><div class=\"hi\"><a href=\"/foo/bar\">Hello</a></div></body></html>",
25+
[".hi"],
26+
"<div class=\"hi\"><a href=\"/foo/bar\">Hello</a></div>\n"
27+
),
28+
find_by_id: (
29+
"<html><head></head><body><div id=\"my-id\"><a href=\"/foo/bar\">Hello</a></div></body></html>",
30+
["#my-id"],
31+
"<div id=\"my-id\"><a href=\"/foo/bar\">Hello</a></div>\n"
32+
),
33+
remove_links: (
34+
"<html><head></head><body><div id=\"my-id\"><a href=\"/foo/bar\">Hello</a></div></body></html>",
35+
["#my-id", "--remove-nodes", "a"],
36+
"<div id=\"my-id\"></div>\n",
37+
),
38+
);

0 commit comments

Comments
 (0)