public_suffix_service 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +0 -1
- data/.travis.yml +11 -0
- data/.yardopts +1 -1
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +6 -4
- data/README.md +8 -135
- data/Rakefile +23 -31
- data/lib/public_suffix.rb +134 -0
- data/lib/{public_suffix_service → public_suffix}/definitions.txt +282 -1
- data/lib/{public_suffix_service → public_suffix}/domain.rb +50 -50
- data/lib/{public_suffix_service → public_suffix}/errors.rb +12 -12
- data/lib/{public_suffix_service/rule_list.rb → public_suffix/list.rb} +54 -55
- data/lib/{public_suffix_service → public_suffix}/rule.rb +29 -29
- data/lib/public_suffix/rule_list.rb +14 -0
- data/lib/{public_suffix_service → public_suffix}/version.rb +4 -4
- data/lib/public_suffix_service.rb +5 -121
- data/public_suffix_service.gemspec +18 -15
- data/test/acceptance_test.rb +3 -3
- data/test/test_helper.rb +2 -6
- data/test/{public_suffix_service → unit}/domain_test.rb +11 -11
- data/test/unit/errors_test.rb +23 -0
- data/test/unit/list_test.rb +193 -0
- data/test/unit/public_suffix_test.rb +85 -0
- data/test/{public_suffix_service → unit}/rule_test.rb +22 -22
- metadata +66 -59
- data/test/public_suffix_service/errors_test.rb +0 -23
- data/test/public_suffix_service/rule_list_test.rb +0 -193
- data/test/public_suffix_service_test.rb +0 -85
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class PublicSuffixTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def test_self_parse_a_domain_with_tld_and_sld
|
6
|
+
domain = PublicSuffix.parse("example.com")
|
7
|
+
assert_instance_of PublicSuffix::Domain, domain
|
8
|
+
assert_equal "com", domain.tld
|
9
|
+
assert_equal "example", domain.sld
|
10
|
+
assert_equal nil, domain.trd
|
11
|
+
|
12
|
+
domain = PublicSuffix.parse("example.co.uk")
|
13
|
+
assert_instance_of PublicSuffix::Domain, domain
|
14
|
+
assert_equal "co.uk", domain.tld
|
15
|
+
assert_equal "example", domain.sld
|
16
|
+
assert_equal nil, domain.trd
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_self_parse_a_domain_with_tld_and_sld_and_trd
|
20
|
+
domain = PublicSuffix.parse("alpha.example.com")
|
21
|
+
assert_instance_of PublicSuffix::Domain, domain
|
22
|
+
assert_equal "com", domain.tld
|
23
|
+
assert_equal "example", domain.sld
|
24
|
+
assert_equal "alpha", domain.trd
|
25
|
+
|
26
|
+
domain = PublicSuffix.parse("alpha.example.co.uk")
|
27
|
+
assert_instance_of PublicSuffix::Domain, domain
|
28
|
+
assert_equal "co.uk", domain.tld
|
29
|
+
assert_equal "example", domain.sld
|
30
|
+
assert_equal "alpha", domain.trd
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_self_parse_a_domain_with_tld_and_sld_and_4rd
|
34
|
+
domain = PublicSuffix.parse("one.two.example.com")
|
35
|
+
assert_instance_of PublicSuffix::Domain, domain
|
36
|
+
assert_equal "com", domain.tld
|
37
|
+
assert_equal "example", domain.sld
|
38
|
+
assert_equal "one.two", domain.trd
|
39
|
+
|
40
|
+
domain = PublicSuffix.parse("one.two.example.co.uk")
|
41
|
+
assert_instance_of PublicSuffix::Domain, domain
|
42
|
+
assert_equal "co.uk", domain.tld
|
43
|
+
assert_equal "example", domain.sld
|
44
|
+
assert_equal "one.two", domain.trd
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_self_parse_a_fully_qualified_domain_name
|
48
|
+
domain = PublicSuffix.parse("www.example.com.")
|
49
|
+
assert_instance_of PublicSuffix::Domain, domain
|
50
|
+
assert_equal "com", domain.tld
|
51
|
+
assert_equal "example", domain.sld
|
52
|
+
assert_equal "www", domain.trd
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_self_parse_should_raise_with_invalid_domain
|
56
|
+
error = assert_raise(PublicSuffix::DomainInvalid) { PublicSuffix.parse("example.zip") }
|
57
|
+
assert_match %r{example\.zip}, error.message
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_self_parse_should_raise_with_unallowed_domain
|
61
|
+
error = assert_raise(PublicSuffix::DomainNotAllowed) { PublicSuffix.parse("example.ke") }
|
62
|
+
assert_match %r{example\.ke}, error.message
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
def test_self_valid
|
67
|
+
assert PublicSuffix.valid?("google.com")
|
68
|
+
assert PublicSuffix.valid?("www.google.com")
|
69
|
+
assert PublicSuffix.valid?("google.co.uk")
|
70
|
+
assert PublicSuffix.valid?("www.google.co.uk")
|
71
|
+
end
|
72
|
+
|
73
|
+
# Returns false when domain has an invalid TLD
|
74
|
+
def test_self_valid_with_invalid_tld
|
75
|
+
assert !PublicSuffix.valid?("google.zip")
|
76
|
+
assert !PublicSuffix.valid?("www.google.zip")
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_self_valid_with_fully_qualified_domain_name
|
80
|
+
assert PublicSuffix.valid?("google.com.")
|
81
|
+
assert PublicSuffix.valid?("google.co.uk.")
|
82
|
+
assert !PublicSuffix.valid?("google.zip.")
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
@@ -1,38 +1,38 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
|
3
|
-
class
|
3
|
+
class PublicSuffix::RuleTest < Test::Unit::TestCase
|
4
4
|
|
5
5
|
def test_factory_should_return_rule_normal
|
6
|
-
rule =
|
7
|
-
assert_instance_of
|
6
|
+
rule = PublicSuffix::Rule.factory("com")
|
7
|
+
assert_instance_of PublicSuffix::Rule::Normal, rule
|
8
8
|
|
9
|
-
rule =
|
10
|
-
assert_instance_of
|
9
|
+
rule = PublicSuffix::Rule.factory("verona.it")
|
10
|
+
assert_instance_of PublicSuffix::Rule::Normal, rule
|
11
11
|
end
|
12
12
|
|
13
13
|
def test_factory_should_return_rule_exception
|
14
|
-
rule =
|
15
|
-
assert_instance_of
|
14
|
+
rule = PublicSuffix::Rule.factory("!british-library.uk")
|
15
|
+
assert_instance_of PublicSuffix::Rule::Exception, rule
|
16
16
|
end
|
17
17
|
|
18
18
|
def test_factory_should_return_rule_wildcard
|
19
|
-
rule =
|
20
|
-
assert_instance_of
|
19
|
+
rule = PublicSuffix::Rule.factory("*.do")
|
20
|
+
assert_instance_of PublicSuffix::Rule::Wildcard, rule
|
21
21
|
|
22
|
-
rule =
|
23
|
-
assert_instance_of
|
22
|
+
rule = PublicSuffix::Rule.factory("*.sch.uk")
|
23
|
+
assert_instance_of PublicSuffix::Rule::Wildcard, rule
|
24
24
|
end
|
25
25
|
|
26
26
|
end
|
27
27
|
|
28
28
|
|
29
|
-
class
|
29
|
+
class PublicSuffix::RuleBaseTest < Test::Unit::TestCase
|
30
30
|
|
31
|
-
class ::
|
31
|
+
class ::PublicSuffix::Rule::Test < ::PublicSuffix::Rule::Base
|
32
32
|
end
|
33
33
|
|
34
34
|
def setup
|
35
|
-
@klass =
|
35
|
+
@klass = PublicSuffix::Rule::Base
|
36
36
|
end
|
37
37
|
|
38
38
|
|
@@ -47,14 +47,14 @@ class PublicSuffixService::RuleBaseTest < Test::Unit::TestCase
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def test_equality_with_self
|
50
|
-
rule =
|
50
|
+
rule = PublicSuffix::Rule::Base.new("foo")
|
51
51
|
assert_equal rule, rule
|
52
52
|
end
|
53
53
|
|
54
54
|
def test_equality_with_internals
|
55
55
|
assert_equal @klass.new("foo"), @klass.new("foo")
|
56
56
|
assert_not_equal @klass.new("foo"), @klass.new("bar")
|
57
|
-
assert_not_equal @klass.new("foo"),
|
57
|
+
assert_not_equal @klass.new("foo"), PublicSuffix::Rule::Test.new("bar")
|
58
58
|
assert_not_equal @klass.new("foo"), Class.new { def name; foo; end }.new
|
59
59
|
end
|
60
60
|
|
@@ -88,10 +88,10 @@ class PublicSuffixService::RuleBaseTest < Test::Unit::TestCase
|
|
88
88
|
end
|
89
89
|
|
90
90
|
|
91
|
-
class
|
91
|
+
class PublicSuffix::RuleNormalTest < Test::Unit::TestCase
|
92
92
|
|
93
93
|
def setup
|
94
|
-
@klass =
|
94
|
+
@klass = PublicSuffix::Rule::Normal
|
95
95
|
end
|
96
96
|
|
97
97
|
|
@@ -165,10 +165,10 @@ class PublicSuffixService::RuleNormalTest < Test::Unit::TestCase
|
|
165
165
|
end
|
166
166
|
|
167
167
|
|
168
|
-
class
|
168
|
+
class PublicSuffix::RuleExceptionTest < Test::Unit::TestCase
|
169
169
|
|
170
170
|
def setup
|
171
|
-
@klass =
|
171
|
+
@klass = PublicSuffix::Rule::Exception
|
172
172
|
end
|
173
173
|
|
174
174
|
|
@@ -236,10 +236,10 @@ class PublicSuffixService::RuleExceptionTest < Test::Unit::TestCase
|
|
236
236
|
end
|
237
237
|
|
238
238
|
|
239
|
-
class
|
239
|
+
class PublicSuffix::RuleWildcardTest < Test::Unit::TestCase
|
240
240
|
|
241
241
|
def setup
|
242
|
-
@klass =
|
242
|
+
@klass = PublicSuffix::Rule::Wildcard
|
243
243
|
end
|
244
244
|
|
245
245
|
|
metadata
CHANGED
@@ -1,50 +1,58 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: public_suffix_service
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.1
|
4
5
|
prerelease:
|
5
|
-
version: 0.9.0
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
7
|
+
authors:
|
8
8
|
- Simone Carletti
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2011-12-24 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: &70168588273080 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
23
22
|
type: :development
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
26
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *70168588273080
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: mocha
|
27
|
+
requirement: &70168588268020 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70168588268020
|
36
|
+
- !ruby/object:Gem::Dependency
|
27
37
|
name: yard
|
28
|
-
requirement: &
|
38
|
+
requirement: &70168588259580 !ruby/object:Gem::Requirement
|
29
39
|
none: false
|
30
|
-
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version:
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
34
44
|
type: :development
|
35
45
|
prerelease: false
|
36
|
-
version_requirements: *
|
37
|
-
description: PublicSuffixService
|
46
|
+
version_requirements: *70168588259580
|
47
|
+
description: PublicSuffixService gem is now known as PublicSuffix.
|
38
48
|
email: weppos@weppos.net
|
39
49
|
executables: []
|
40
|
-
|
41
50
|
extensions: []
|
42
|
-
|
43
51
|
extra_rdoc_files: []
|
44
|
-
|
45
|
-
files:
|
52
|
+
files:
|
46
53
|
- .gemtest
|
47
54
|
- .gitignore
|
55
|
+
- .travis.yml
|
48
56
|
- .yardopts
|
49
57
|
- CHANGELOG.md
|
50
58
|
- Gemfile
|
@@ -52,53 +60,52 @@ files:
|
|
52
60
|
- LICENSE
|
53
61
|
- README.md
|
54
62
|
- Rakefile
|
63
|
+
- lib/public_suffix.rb
|
64
|
+
- lib/public_suffix/definitions.txt
|
65
|
+
- lib/public_suffix/domain.rb
|
66
|
+
- lib/public_suffix/errors.rb
|
67
|
+
- lib/public_suffix/list.rb
|
68
|
+
- lib/public_suffix/rule.rb
|
69
|
+
- lib/public_suffix/rule_list.rb
|
70
|
+
- lib/public_suffix/version.rb
|
55
71
|
- lib/public_suffix_service.rb
|
56
|
-
- lib/public_suffix_service/definitions.txt
|
57
|
-
- lib/public_suffix_service/domain.rb
|
58
|
-
- lib/public_suffix_service/errors.rb
|
59
|
-
- lib/public_suffix_service/rule.rb
|
60
|
-
- lib/public_suffix_service/rule_list.rb
|
61
|
-
- lib/public_suffix_service/version.rb
|
62
72
|
- public_suffix_service.gemspec
|
63
73
|
- test/acceptance_test.rb
|
64
|
-
- test/public_suffix_service/domain_test.rb
|
65
|
-
- test/public_suffix_service/errors_test.rb
|
66
|
-
- test/public_suffix_service/rule_list_test.rb
|
67
|
-
- test/public_suffix_service/rule_test.rb
|
68
|
-
- test/public_suffix_service_test.rb
|
69
74
|
- test/test_helper.rb
|
70
|
-
|
75
|
+
- test/unit/domain_test.rb
|
76
|
+
- test/unit/errors_test.rb
|
77
|
+
- test/unit/list_test.rb
|
78
|
+
- test/unit/public_suffix_test.rb
|
79
|
+
- test/unit/rule_test.rb
|
80
|
+
homepage: http://www.simonecarletti.com/code/public_suffix
|
71
81
|
licenses: []
|
72
|
-
|
73
82
|
post_install_message:
|
74
83
|
rdoc_options: []
|
75
|
-
|
76
|
-
require_paths:
|
84
|
+
require_paths:
|
77
85
|
- lib
|
78
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
87
|
none: false
|
80
|
-
requirements:
|
81
|
-
- -
|
82
|
-
- !ruby/object:Gem::Version
|
88
|
+
requirements:
|
89
|
+
- - ! '>='
|
90
|
+
- !ruby/object:Gem::Version
|
83
91
|
version: 1.8.7
|
84
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
93
|
none: false
|
86
|
-
requirements:
|
87
|
-
- -
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version:
|
94
|
+
requirements:
|
95
|
+
- - ! '>='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
90
98
|
requirements: []
|
91
|
-
|
92
99
|
rubyforge_project:
|
93
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.11
|
94
101
|
signing_key:
|
95
102
|
specification_version: 3
|
96
103
|
summary: Domain name parser based in the Public Suffix List.
|
97
|
-
test_files:
|
104
|
+
test_files:
|
98
105
|
- test/acceptance_test.rb
|
99
|
-
- test/public_suffix_service/domain_test.rb
|
100
|
-
- test/public_suffix_service/errors_test.rb
|
101
|
-
- test/public_suffix_service/rule_list_test.rb
|
102
|
-
- test/public_suffix_service/rule_test.rb
|
103
|
-
- test/public_suffix_service_test.rb
|
104
106
|
- test/test_helper.rb
|
107
|
+
- test/unit/domain_test.rb
|
108
|
+
- test/unit/errors_test.rb
|
109
|
+
- test/unit/list_test.rb
|
110
|
+
- test/unit/public_suffix_test.rb
|
111
|
+
- test/unit/rule_test.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class ErrorsTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
# Inherits from StandardError
|
6
|
-
def test_error_inheritance
|
7
|
-
assert_kind_of StandardError,
|
8
|
-
PublicSuffixService::Error.new
|
9
|
-
end
|
10
|
-
|
11
|
-
# Inherits from PublicSuffixService::Error
|
12
|
-
def test_domain_invalid_inheritance
|
13
|
-
assert_kind_of PublicSuffixService::Error,
|
14
|
-
PublicSuffixService::DomainInvalid.new
|
15
|
-
end
|
16
|
-
|
17
|
-
# Inherits from PublicSuffixService::DomainInvalid
|
18
|
-
def test_domain_not_allowed_inheritance
|
19
|
-
assert_kind_of PublicSuffixService::DomainInvalid,
|
20
|
-
PublicSuffixService::DomainNotAllowed.new
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,193 +0,0 @@
|
|
1
|
-
require 'test_helper'
|
2
|
-
|
3
|
-
class PublicSuffixService::RuleListTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@list = PublicSuffixService::RuleList.new
|
7
|
-
end
|
8
|
-
|
9
|
-
def teardown
|
10
|
-
PublicSuffixService::RuleList.clear
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
def test_initialize
|
15
|
-
assert_instance_of PublicSuffixService::RuleList, @list
|
16
|
-
assert_equal 0, @list.length
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_initialize_create_index_when_empty
|
20
|
-
assert_equal({}, @list.indexes)
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_indexes
|
24
|
-
@list = PublicSuffixService::RuleList.parse(<<EOS)
|
25
|
-
// com : http://en.wikipedia.org/wiki/.com
|
26
|
-
com
|
27
|
-
|
28
|
-
// uk : http://en.wikipedia.org/wiki/.uk
|
29
|
-
*.uk
|
30
|
-
*.sch.uk
|
31
|
-
!bl.uk
|
32
|
-
!british-library.uk
|
33
|
-
EOS
|
34
|
-
|
35
|
-
assert !@list.indexes.empty?
|
36
|
-
assert_equal [1,2,3,4], @list.indexes.delete('uk')
|
37
|
-
assert_equal [0], @list.indexes.delete('com')
|
38
|
-
assert @list.indexes.empty?
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
def test_equality_with_self
|
43
|
-
list = PublicSuffixService::RuleList.new
|
44
|
-
assert_equal list, list
|
45
|
-
end
|
46
|
-
|
47
|
-
def test_equality_with_internals
|
48
|
-
rule = PublicSuffixService::Rule.factory("com")
|
49
|
-
assert_equal PublicSuffixService::RuleList.new.add(rule), PublicSuffixService::RuleList.new.add(rule)
|
50
|
-
end
|
51
|
-
|
52
|
-
|
53
|
-
def test_add
|
54
|
-
assert_equal @list, @list.add(PublicSuffixService::Rule.factory(""))
|
55
|
-
assert_equal @list, @list << PublicSuffixService::Rule.factory("")
|
56
|
-
assert_equal 2, @list.length
|
57
|
-
end
|
58
|
-
|
59
|
-
def test_add_should_recreate_index
|
60
|
-
@list = PublicSuffixService::RuleList.parse("com")
|
61
|
-
assert_equal PublicSuffixService::Rule.factory("com"), @list.find("google.com")
|
62
|
-
assert_equal nil, @list.find("google.net")
|
63
|
-
|
64
|
-
@list << PublicSuffixService::Rule.factory("net")
|
65
|
-
assert_equal PublicSuffixService::Rule.factory("com"), @list.find("google.com")
|
66
|
-
assert_equal PublicSuffixService::Rule.factory("net"), @list.find("google.net")
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_empty?
|
70
|
-
assert @list.empty?
|
71
|
-
@list.add(PublicSuffixService::Rule.factory(""))
|
72
|
-
assert !@list.empty?
|
73
|
-
end
|
74
|
-
|
75
|
-
def test_size
|
76
|
-
assert_equal 0, @list.length
|
77
|
-
assert_equal @list, @list.add(PublicSuffixService::Rule.factory(""))
|
78
|
-
assert_equal 1, @list.length
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_clear
|
82
|
-
assert_equal 0, @list.length
|
83
|
-
assert_equal @list, @list.add(PublicSuffixService::Rule.factory(""))
|
84
|
-
assert_equal 1, @list.length
|
85
|
-
assert_equal @list, @list.clear
|
86
|
-
assert_equal 0, @list.length
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
def test_find
|
91
|
-
@list = PublicSuffixService::RuleList.parse(<<EOS)
|
92
|
-
// com : http://en.wikipedia.org/wiki/.com
|
93
|
-
com
|
94
|
-
|
95
|
-
// uk : http://en.wikipedia.org/wiki/.uk
|
96
|
-
*.uk
|
97
|
-
*.sch.uk
|
98
|
-
!bl.uk
|
99
|
-
!british-library.uk
|
100
|
-
EOS
|
101
|
-
assert_equal PublicSuffixService::Rule.factory("com"), @list.find("google.com")
|
102
|
-
assert_equal PublicSuffixService::Rule.factory("com"), @list.find("foo.google.com")
|
103
|
-
assert_equal PublicSuffixService::Rule.factory("*.uk"), @list.find("google.uk")
|
104
|
-
assert_equal PublicSuffixService::Rule.factory("*.uk"), @list.find("google.co.uk")
|
105
|
-
assert_equal PublicSuffixService::Rule.factory("*.uk"), @list.find("foo.google.co.uk")
|
106
|
-
assert_equal PublicSuffixService::Rule.factory("!british-library.uk"), @list.find("british-library.uk")
|
107
|
-
assert_equal PublicSuffixService::Rule.factory("!british-library.uk"), @list.find("foo.british-library.uk")
|
108
|
-
end
|
109
|
-
|
110
|
-
def test_select
|
111
|
-
@list = PublicSuffixService::RuleList.parse(<<EOS)
|
112
|
-
// com : http://en.wikipedia.org/wiki/.com
|
113
|
-
com
|
114
|
-
|
115
|
-
// uk : http://en.wikipedia.org/wiki/.uk
|
116
|
-
*.uk
|
117
|
-
*.sch.uk
|
118
|
-
!bl.uk
|
119
|
-
!british-library.uk
|
120
|
-
EOS
|
121
|
-
assert_equal 2, @list.select("british-library.uk").size
|
122
|
-
end
|
123
|
-
|
124
|
-
|
125
|
-
def test_self_default_getter
|
126
|
-
assert_equal nil, PublicSuffixService::RuleList.send(:class_variable_get, :"@@default")
|
127
|
-
PublicSuffixService::RuleList.default
|
128
|
-
assert_not_equal nil, PublicSuffixService::RuleList.send(:class_variable_get, :"@@default")
|
129
|
-
end
|
130
|
-
|
131
|
-
def test_self_default_setter
|
132
|
-
PublicSuffixService::RuleList.default
|
133
|
-
assert_not_equal nil, PublicSuffixService::RuleList.send(:class_variable_get, :"@@default")
|
134
|
-
PublicSuffixService::RuleList.default = nil
|
135
|
-
assert_equal nil, PublicSuffixService::RuleList.send(:class_variable_get, :"@@default")
|
136
|
-
end
|
137
|
-
|
138
|
-
def test_self_clear
|
139
|
-
PublicSuffixService::RuleList.default
|
140
|
-
assert_not_equal nil, PublicSuffixService::RuleList.send(:class_variable_get, :"@@default")
|
141
|
-
PublicSuffixService::RuleList.clear
|
142
|
-
assert_equal nil, PublicSuffixService::RuleList.send(:class_variable_get, :"@@default")
|
143
|
-
end
|
144
|
-
|
145
|
-
def test_self_reload
|
146
|
-
PublicSuffixService::RuleList.default
|
147
|
-
mock(PublicSuffixService::RuleList).default_definition { "" }
|
148
|
-
|
149
|
-
PublicSuffixService::RuleList.reload
|
150
|
-
assert_equal PublicSuffixService::RuleList.new, PublicSuffixService::RuleList.default
|
151
|
-
end
|
152
|
-
|
153
|
-
|
154
|
-
def test_self_parse
|
155
|
-
list = PublicSuffixService::RuleList.parse(<<EOS)
|
156
|
-
// ***** BEGIN LICENSE BLOCK *****
|
157
|
-
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
158
|
-
//
|
159
|
-
// ***** END LICENSE BLOCK *****
|
160
|
-
|
161
|
-
// ac : http://en.wikipedia.org/wiki/.ac
|
162
|
-
ac
|
163
|
-
com.ac
|
164
|
-
|
165
|
-
// ad : http://en.wikipedia.org/wiki/.ad
|
166
|
-
ad
|
167
|
-
|
168
|
-
// ar : http://en.wikipedia.org/wiki/.ar
|
169
|
-
*.ar
|
170
|
-
!congresodelalengua3.ar
|
171
|
-
EOS
|
172
|
-
|
173
|
-
assert_instance_of PublicSuffixService::RuleList, list
|
174
|
-
assert_equal 5, list.length
|
175
|
-
assert_equal %w(ac com.ac ad *.ar !congresodelalengua3.ar).map { |name| PublicSuffixService::Rule.factory(name) }, list.to_a
|
176
|
-
end
|
177
|
-
|
178
|
-
def test_self_parse_should_create_cache
|
179
|
-
list = PublicSuffixService::RuleList.parse(<<EOS)
|
180
|
-
// com : http://en.wikipedia.org/wiki/.com
|
181
|
-
com
|
182
|
-
|
183
|
-
// uk : http://en.wikipedia.org/wiki/.uk
|
184
|
-
*.uk
|
185
|
-
*.sch.uk
|
186
|
-
!bl.uk
|
187
|
-
!british-library.uk
|
188
|
-
EOS
|
189
|
-
|
190
|
-
assert_equal PublicSuffixService::Rule.factory("com"), list.find("google.com")
|
191
|
-
end
|
192
|
-
|
193
|
-
end
|