Skip to content

Commit 92fb160

Browse files
committed
- [+] add more tests
1 parent edb1c9c commit 92fb160

File tree

7 files changed

+52
-5
lines changed

7 files changed

+52
-5
lines changed

piece_test.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,30 @@ import (
44
"testing"
55
)
66

7-
func TestPieceAttr(t *testing.T) {
7+
func TestPiece(t *testing.T) {
8+
testCases(t, "Piece raw html", []testCase{
9+
{"piece_raw_a",
10+
[]string{"-i", "opt_piece_attr.html", "-o", "-c", "ul > li", "-p", "Source=RAW:a"},
11+
},
12+
})
813
testCases(t, "Piece Attributes", []testCase{
914
{"id",
10-
[]string{"-i", "opt_piece_attr.html", "-o", "-c", "li > a", "-p", "url=ATTR:id"},
15+
[]string{"-i", "opt_piece_attr.html", "-o", "-c", "li > a", "-p", "id=ATTR:id"},
1116
},
1217
{"href",
1318
[]string{"-i", "opt_piece_attr.html", "-o", "-c", "li > a", "-p", "url=ATTR:href"},
1419
},
15-
//{"both_fields",},
16-
//{"noexist"},
20+
{"both_fields",
21+
[]string{"-i", "opt_piece_attr.html", "-o", "-c", "li > a",
22+
"-p", "id=ATTR:id", "-p", "url=ATTR:href"},
23+
},
24+
25+
{"noexist",
26+
[]string{"-i", "opt_piece_attr.html", "-o", "-c", "li > a", "-p", "NoExist=ATTR:noexist"},
27+
},
28+
{"script_src",
29+
[]string{"-i", "opt_piece_script.html", "-o", "-c", "html > head > script", "-p", "SourceJS=ATTR:src"},
30+
},
1731
//{},
1832
})
1933
}

test/both_fields.ref

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
id url
2+
a1 http://www.google.com/finance
3+
a2 http://finance.yahoo.com/
4+
a3 https://www.google.com/news
5+
a4 http://news.yahoo.com
6+

test/id.ref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
url
1+
id
22
a1
33
a2
44
a3

test/noexist.ref

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
NoExist
2+
3+
4+
5+
6+

test/opt_piece_script.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<html>
2+
<head>
3+
<script src="foo.js"></script>
4+
<script src="bar.js"></script>
5+
<script src="baz.js"></script>
6+
</head>
7+
</html>

test/piece_raw_a.ref

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Source
2+
<a id="a1" href="http://www.google.com/finance">
3+
</a>
4+
<a id="a2" href="http://finance.yahoo.com/">
5+
</a>
6+
<a id="a3" href="https://www.google.com/news"></a>
7+
<a id="a4" href="http://news.yahoo.com">
8+
</a>
9+

test/script_src.ref

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
SourceJS
2+
foo.js
3+
bar.js
4+
baz.js
5+

0 commit comments

Comments
 (0)