Skip to content

Commit

Permalink
Add test from example in PSL wiki
Browse files Browse the repository at this point in the history
Signed-off-by: ko-zu <[email protected]>
  • Loading branch information
ko-zu committed Jun 1, 2024
1 parent 84e8975 commit 21b6726
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions publicsuffixlist/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@ def test_ignored_trailing_dot(self):
self.assertEqual(self.psl.suffix("example.com."), "example.com")
self.assertEqual(self.psl.publicsuffix("example.com."), "com")

def test_wiki_example(self):
# from PSL Wiki
# https://github.com/publicsuffix/list/wiki/Format/ffd14e41e850c69222eecf0aab4248619b53905a
source = """
com
*.foo.com
*.jp
*.hokkaido.jp
*.tokyo.jp
!pref.hokkaido.jp
!metro.tokyo.jp
"""
psl = PublicSuffixList(source.splitlines())

self.assertEqual(psl.is_private("foo.com"), True)
self.assertEqual(psl.is_private("bar.foo.com"), False)
self.assertEqual(psl.is_private("example.bar.foo.com"), True)
self.assertEqual(psl.is_private("foo.bar.jp"), True)
self.assertEqual(psl.is_private("bar.jp"), False)
self.assertEqual(psl.is_private("foo.bar.hokkaido.jp"), True)
self.assertEqual(psl.is_private("bar.hokkaido.jp"), False)
self.assertEqual(psl.is_private("foo.bar.tokyo.jp"), True)
self.assertEqual(psl.is_private("bar.tokyo.jp"), False)
self.assertEqual(psl.is_private("pref.hokkaido.jp"), True)
self.assertEqual(psl.is_private("metro.tokyo.jp"), True)

def test_idn(self):
tld = u("香港")
self.assertEqual(self.psl.suffix(u("www.example.") + tld), u("example.") + tld)
Expand Down

0 comments on commit 21b6726

Please sign in to comment.