-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from benbalter/domain-parts
Abstract out domain parsing
- Loading branch information
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
"foo", | ||
"", | ||
nil, | ||
" ", | ||
] | ||
|
||
class TestGman < Test::Unit::TestCase | ||
|
@@ -87,4 +88,21 @@ class TestGman < Test::Unit::TestCase | |
end | ||
end | ||
|
||
should "not err out on invalid domains" do | ||
assert_equal false, Gman.valid?("[email protected]") | ||
assert_equal "act.gov.au", Gman.get_domain("[email protected]") | ||
assert_equal nil, Gman.domain_parts("[email protected]") | ||
end | ||
|
||
should "return public suffix domain" do | ||
assert_equal PublicSuffix::Domain, Gman.domain_parts("whitehouse.gov").class | ||
assert_equal NilClass, Gman.domain_parts("foo.bar").class | ||
end | ||
|
||
should "parse domain parts" do | ||
assert_equal "gov", Gman.domain_parts("[email protected]").tld | ||
assert_equal "bar", Gman.domain_parts("foo.bar.gov").sld | ||
assert_equal "bar", Gman.domain_parts("https://foo.bar.gov").sld | ||
assert_equal "bar.gov", Gman.domain_parts("[email protected]").domain | ||
end | ||
end |