File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -19,3 +19,7 @@ html5ever = "0.25.1"
1919clap = " 2.33.3"
2020lazy_static = " 1.4.0"
2121url = " 2.2.2"
22+
23+ [dev-dependencies ]
24+ assert_cmd = " 2.0"
25+ predicates = " 2.1"
Original file line number Diff line number Diff line change 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+ ) ;
You can’t perform that action at this time.
0 commit comments