diff --git a/scraping_test.go b/scraping_test.go
index 7ac0cfc..80f8bca 100644
--- a/scraping_test.go
+++ b/scraping_test.go
@@ -2,9 +2,61 @@ package main
import (
"fmt"
+ "reflect"
"testing"
)
+const HTML_STRING = `
+
+ title
+
+
+
+ product-table-caption
+
+
+ Name |
+ Stock |
+ Price |
+
+
+
+ product1 | 10 | 100 |
+ product2 | 20 | 200 |
+ product3 | 30 | 300 |
+ product4 | 40 | 400 |
+
+
+
+`
+
+func TestFilterXPath(t *testing.T) {
+ var tests = []struct {
+ Query string
+ Want []string
+ }{
+ {"//title", []string{"title"}},
+ {"//table[@id='product-table']//tr//td[last()]", []string{"100 | ", "200 | ", "300 | ", "400 | "}},
+ }
+
+ for _, test := range tests {
+ testname := fmt.Sprintf("%s", test.Query)
+ t.Run(testname, func(t *testing.T) {
+ want := []string{}
+ getFilterResultXPath(
+ HTML_STRING,
+ &Filter{
+ From: test.Query,
+ },
+ &want,
+ )
+ if !reflect.DeepEqual(test.Want, want) {
+ t.Errorf("Got %s, want %s", want, test.Want)
+ }
+ })
+ }
+}
+
func TestFilterSubstring(t *testing.T) {
var tests = []struct {
Input string