Checkpoint
This commit is contained in:
41
dataset/parser/adblock_test.go
Normal file
41
dataset/parser/adblock_test.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package parser
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestAdBlockParser(t *testing.T) {
|
||||
test := `[Adblock Plus 2.0]
|
||||
! Title: AdRules DNS List
|
||||
! Homepage: https://github.com/Cats-Team/AdRules
|
||||
! Powerd by Cats-Team
|
||||
! Expires: 1 (update frequency)
|
||||
! Description: The DNS Filters
|
||||
! Total count: 145270
|
||||
! Update: 2025-10-07 02:05:08(GMT+8)
|
||||
/^.+stat\.kugou\.com/
|
||||
/^admarvel\./
|
||||
||*-ad-sign.byteimg.com^
|
||||
||*-ad.a.yximgs.com^
|
||||
||*-applog.fqnovel.com^
|
||||
||*-datareceiver.aki-game.net^
|
||||
||*.exaapi.com^`
|
||||
want := []string{"*-ad-sign.byteimg.com", "*-ad.a.yximgs.com", "*-applog.fqnovel.com", "*-datareceiver.aki-game.net", "*.exaapi.com"}
|
||||
|
||||
parsed, ignored, err := ParseDomains(strings.NewReader(test))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
sort.Strings(parsed)
|
||||
if !reflect.DeepEqual(parsed, want) {
|
||||
t.Errorf("expected ParseDomains(domains) to return %v, got %v", want, parsed)
|
||||
}
|
||||
if ignored != 2 {
|
||||
t.Errorf("expected 2 ignored, got %d", ignored)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user