diff --git a/scraping_test.go b/scraping_test.go
index 13f0140..dd1c97a 100644
--- a/scraping_test.go
+++ b/scraping_test.go
@@ -60,6 +60,36 @@ func TestFilterXPath(t *testing.T) {
}
}
+func TestFilterCSS(t *testing.T) {
+ var tests = []struct {
+ Query string
+ Want []string
+ }{
+ {"title", []string{"
title"}},
+ {".product-table tr td:last-child", []string{`100 | `, `200 | `, `300 | `, `400 | `}},
+ {".price", []string{`100 | `, `200 | `, `300 | `, `400 | `}},
+ {".product-table tr td:nth-child(2)", []string{`10 | `, `20 | `, `30 | `, `40 | `}},
+ {".stock", []string{`10 | `, `20 | `, `30 | `, `40 | `}},
+ }
+
+ for _, test := range tests {
+ testname := fmt.Sprintf("%s", test.Query)
+ t.Run(testname, func(t *testing.T) {
+ want := []string{}
+ getFilterResultCSS(
+ 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