Skip to content

Commit

Permalink
Add test cases for GH-31
Browse files Browse the repository at this point in the history
  • Loading branch information
weppos committed Nov 20, 2016
1 parent d5b7003 commit 4db7531
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 6 deletions.
82 changes: 77 additions & 5 deletions publicsuffix/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ func TestValid(t *testing.T) {

type privateTestCase struct {
input string
domain string
ignore bool
error bool
domain string
}

func TestIncludePrivate(t *testing.T) {
testCases := []privateTestCase{
privateTestCase{"blogspot.com", false, true, ""},
privateTestCase{"blogspot.com", true, false, "blogspot.com"},
privateTestCase{"blogspot.com", "", false, true},
privateTestCase{"blogspot.com", "blogspot.com", true, false},

privateTestCase{"foo.blogspot.com", false, false, "foo.blogspot.com"},
privateTestCase{"foo.blogspot.com", true, false, "blogspot.com"},
privateTestCase{"foo.blogspot.com", "foo.blogspot.com", false, false},
privateTestCase{"foo.blogspot.com", "blogspot.com", true, false},
}

for _, testCase := range testCases {
Expand All @@ -76,5 +76,77 @@ func TestIncludePrivate(t *testing.T) {
t.Errorf("Domain(%v) = %v, want %v", testCase.input, got, want)
}
}
}

type idnaTestCase struct {
input string
domain string
error bool
}

func TestIDNA(t *testing.T) {
testACases := []idnaTestCase{
// A-labels are supported
// Check single IDN part
idnaTestCase{"xn--p1ai", "", true},
idnaTestCase{"example.xn--p1ai", "example.xn--p1ai", false},
idnaTestCase{"subdomain.example.xn--p1ai", "example.xn--p1ai", false},
// Check multiple IDN parts
idnaTestCase{"xn--example--3bhk5a.xn--p1ai", "xn--example--3bhk5a.xn--p1ai", false},
idnaTestCase{"subdomain.xn--example--3bhk5a.xn--p1ai", "xn--example--3bhk5a.xn--p1ai", false},
// Check multiple IDN rules
idnaTestCase{"example.xn--o1ach.xn--90a3ac", "example.xn--o1ach.xn--90a3ac", false},
idnaTestCase{"sudbomain.example.xn--o1ach.xn--90a3ac", "example.xn--o1ach.xn--90a3ac", false},
}

// TODO(weppos): some tests are passing because of the default rule *
// Consider to add some tests overriding the default rule to nil.
// Right now, setting the default rule to nil with cause a panic if the lookup results in a nil.
for _, testCase := range testACases {
got, err := DomainFromListWithOptions(DefaultList, testCase.input, nil)

if testCase.error && err == nil {
t.Errorf("A-label %v should have returned error, got: %v", testCase.input, got)
continue
}
if !testCase.error && err != nil {
t.Errorf("A-label %v returned error: %v", testCase.input, err)
continue
}

if want := testCase.domain; want != got {
t.Errorf("A-label Domain(%v) = %v, want %v", testCase.input, got, want)
}
}

testUCases := []idnaTestCase{
// U-labels are NOT supported
// Check single IDN part
idnaTestCase{"рф", "", true},
idnaTestCase{"example.рф", "", true},
idnaTestCase{"subdomain.example.рф", "", true},
// Check multiple IDN parts
idnaTestCase{"example-упр.рф", "", true},
idnaTestCase{"subdomain.example-упр.рф", "", true},
// Check multiple IDN rules
idnaTestCase{"example.упр.срб", "", true},
idnaTestCase{"sudbomain.example.упр.срб", "", true},
}

for _, testCase := range testUCases {
got, err := DomainFromListWithOptions(DefaultList, testCase.input, nil)

if testCase.error && err == nil {
t.Errorf("U-label %v should have returned error, got: %v", testCase.input, got)
continue
}
if !testCase.error && err != nil {
t.Errorf("U-label %v returned error: %v", testCase.input, err)
continue
}

if want := testCase.domain; want != got {
t.Errorf("U-label Domain(%v) = %v, want %v", testCase.input, got, want)
}
}
}
2 changes: 1 addition & 1 deletion publicsuffix/publicsuffix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ blogspot.com
// ===END PRIVATE DOMAINS===
`

// FIXME
// TODO(weppos): abiliuty to set type to a rule.
p1 := NewRule("blogspot.com")
p1.Private = true

Expand Down

0 comments on commit 4db7531

Please sign in to comment.