@@ -20,45 +20,84 @@ func TestFindAttrByClass(t *testing.T) {
20
20
}
21
21
}
22
22
23
- func TestFindTextByClass (t * testing.T ) {
23
+ func TestFindAttrById (t * testing.T ) {
24
24
if err := evalLua (t , `
25
25
local scrape = require("scrape")
26
- response, error = scrape.find_text_by_class ("` + httpBody + `", "testclass ")
27
- assert_equal("My First Heading ", response[1])
28
- assert_equal("My First Heading ", response[2])
26
+ response, error = scrape.find_attr_by_id ("` + httpBody + `", "href", "testid ")
27
+ assert_equal("testhref ", response[1])
28
+ assert_equal("testhref2 ", response[2])
29
29
` ); err != nil {
30
30
t .Errorf ("Failed to evaluate script: %s" , err )
31
31
}
32
32
}
33
33
34
- func TestFindAttrById (t * testing.T ) {
34
+ func TestFindAttrByTag (t * testing.T ) {
35
35
if err := evalLua (t , `
36
36
local scrape = require("scrape")
37
- response, error = scrape.find_attr_by_id ("` + httpBody + `", "href", "testid ")
37
+ response, error = scrape.find_attr_by_tag ("` + httpBody + `", "href", "h1 ")
38
38
assert_equal("testhref", response[1])
39
39
assert_equal("testhref2", response[2])
40
40
` ); err != nil {
41
41
t .Errorf ("Failed to evaluate script: %s" , err )
42
42
}
43
43
}
44
44
45
- func TestFindTextById (t * testing.T ) {
45
+ func TestFindAttrsByClass (t * testing.T ) {
46
46
if err := evalLua (t , `
47
47
local scrape = require("scrape")
48
- response, error = scrape.find_text_by_id("` + httpBody + `", "testid")
48
+ response, error = scrape.find_attrs_by_class("` + httpBody + `", 2, "id", "href", "testclass")
49
+ assert_equal("testhref", response[1]["href"])
50
+ assert_equal("testid", response[1]["id"])
51
+ assert_equal("testid", response[2]["id"])
52
+ assert_equal("testhref2", response[2]["href"])
53
+ ` ); err != nil {
54
+ t .Errorf ("Failed to evaluate script: %s" , err )
55
+ }
56
+ }
57
+
58
+ func TestFindAttrsById (t * testing.T ) {
59
+ if err := evalLua (t , `
60
+ local scrape = require("scrape")
61
+ response, error = scrape.find_attrs_by_id("` + httpBody + `", 2, "id", "href", "testid")
62
+ assert_equal("testhref", response[1]["href"])
63
+ assert_equal("testid", response[1]["id"])
64
+ assert_equal("testid", response[2]["id"])
65
+ assert_equal("testhref2", response[2]["href"])
66
+ ` ); err != nil {
67
+ t .Errorf ("Failed to evaluate script: %s" , err )
68
+ }
69
+ }
70
+
71
+ func TestFindAttrsByTag (t * testing.T ) {
72
+ if err := evalLua (t , `
73
+ local scrape = require("scrape")
74
+ response, error = scrape.find_attrs_by_tag("` + httpBody + `", 2, "id", "href", "h1")
75
+ assert_equal("testhref", response[1]["href"])
76
+ assert_equal("testid", response[1]["id"])
77
+ assert_equal("testid", response[2]["id"])
78
+ assert_equal("testhref2", response[2]["href"])
79
+ ` ); err != nil {
80
+ t .Errorf ("Failed to evaluate script: %s" , err )
81
+ }
82
+ }
83
+
84
+ func TestFindTextByClass (t * testing.T ) {
85
+ if err := evalLua (t , `
86
+ local scrape = require("scrape")
87
+ response, error = scrape.find_text_by_class("` + httpBody + `", "testclass")
49
88
assert_equal("My First Heading", response[1])
50
89
assert_equal("My First Heading", response[2])
51
90
` ); err != nil {
52
91
t .Errorf ("Failed to evaluate script: %s" , err )
53
92
}
54
93
}
55
94
56
- func TestFindAttrByTag (t * testing.T ) {
95
+ func TestFindTextById (t * testing.T ) {
57
96
if err := evalLua (t , `
58
97
local scrape = require("scrape")
59
- response, error = scrape.find_attr_by_tag ("` + httpBody + `", "href", "h1 ")
60
- assert_equal("testhref ", response[1])
61
- assert_equal("testhref2 ", response[2])
98
+ response, error = scrape.find_text_by_id ("` + httpBody + `", "testid ")
99
+ assert_equal("My First Heading ", response[1])
100
+ assert_equal("My First Heading ", response[2])
62
101
` ); err != nil {
63
102
t .Errorf ("Failed to evaluate script: %s" , err )
64
103
}
0 commit comments