32 lines
578 B
Go
32 lines
578 B
Go
package parser
|
|
|
|
import (
|
|
"reflect"
|
|
"sort"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestParseDomains(t *testing.T) {
|
|
test := `# This is a comment
|
|
facebook.com
|
|
tiktok.com
|
|
bogus ignored
|
|
youtube.com`
|
|
want := []string{"facebook.com", "tiktok.com", "youtube.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 != 1 {
|
|
t.Errorf("expected 1 ignored, got %d", ignored)
|
|
}
|
|
}
|