public_suffix 5.0.3 → 5.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,222 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class PublicSuffix::RuleTest < Minitest::Test
6
-
7
- def test_factory_should_return_rule_normal
8
- rule = PublicSuffix::Rule.factory("com")
9
- assert_instance_of PublicSuffix::Rule::Normal, rule
10
-
11
- rule = PublicSuffix::Rule.factory("verona.it")
12
- assert_instance_of PublicSuffix::Rule::Normal, rule
13
- end
14
-
15
- def test_factory_should_return_rule_exception
16
- rule = PublicSuffix::Rule.factory("!british-library.uk")
17
- assert_instance_of PublicSuffix::Rule::Exception, rule
18
- end
19
-
20
- def test_factory_should_return_rule_wildcard
21
- rule = PublicSuffix::Rule.factory("*.do")
22
- assert_instance_of PublicSuffix::Rule::Wildcard, rule
23
-
24
- rule = PublicSuffix::Rule.factory("*.sch.uk")
25
- assert_instance_of PublicSuffix::Rule::Wildcard, rule
26
- end
27
-
28
-
29
- def test_default_returns_default_wildcard
30
- default = PublicSuffix::Rule.default
31
- assert_equal PublicSuffix::Rule::Wildcard.build("*"), default
32
- assert_equal %w[example tldnotlisted], default.decompose("example.tldnotlisted")
33
- assert_equal %w[www.example tldnotlisted], default.decompose("www.example.tldnotlisted")
34
- end
35
-
36
- end
37
-
38
-
39
- class PublicSuffix::RuleBaseTest < Minitest::Test
40
-
41
- class ::PublicSuffix::Rule::Test < ::PublicSuffix::Rule::Base
42
- end
43
-
44
- def setup
45
- @klass = PublicSuffix::Rule::Base
46
- end
47
-
48
-
49
- def test_initialize
50
- rule = @klass.new(value: "verona.it")
51
- assert_instance_of @klass, rule
52
- assert_equal "verona.it", rule.value
53
- end
54
-
55
-
56
- def test_equality_with_self
57
- rule = PublicSuffix::Rule::Base.new(value: "foo")
58
- assert_equal rule, rule
59
- end
60
-
61
- # rubocop:disable Style/SingleLineMethods
62
- def test_equality_with_internals
63
- assert_equal @klass.new(value: "foo"), @klass.new(value: "foo")
64
- refute_equal @klass.new(value: "foo"), @klass.new(value: "bar")
65
- refute_equal @klass.new(value: "foo"), PublicSuffix::Rule::Test.new(value: "foo")
66
- refute_equal @klass.new(value: "foo"), PublicSuffix::Rule::Test.new(value: "bar")
67
- refute_equal @klass.new(value: "foo"), Class.new { def name; foo; end }.new
68
- end
69
- # rubocop:enable Style/SingleLineMethods
70
-
71
- def test_match
72
- [
73
- # standard match
74
- [PublicSuffix::Rule.factory("uk"), "uk", true],
75
- [PublicSuffix::Rule.factory("uk"), "example.uk", true],
76
- [PublicSuffix::Rule.factory("uk"), "example.co.uk", true],
77
- [PublicSuffix::Rule.factory("co.uk"), "example.co.uk", true],
78
-
79
- # FIXME
80
- # [PublicSuffix::Rule.factory("*.com"), "com", false],
81
- [PublicSuffix::Rule.factory("*.com"), "example.com", true],
82
- [PublicSuffix::Rule.factory("*.com"), "foo.example.com", true],
83
- [PublicSuffix::Rule.factory("!example.com"), "com", false],
84
- [PublicSuffix::Rule.factory("!example.com"), "example.com", true],
85
- [PublicSuffix::Rule.factory("!example.com"), "foo.example.com", true],
86
-
87
- # TLD mismatch
88
- [PublicSuffix::Rule.factory("gk"), "example.uk", false],
89
- [PublicSuffix::Rule.factory("gk"), "example.co.uk", false],
90
- [PublicSuffix::Rule.factory("co.uk"), "uk", false],
91
-
92
- # general mismatch
93
- [PublicSuffix::Rule.factory("uk.co"), "example.co.uk", false],
94
- [PublicSuffix::Rule.factory("go.uk"), "example.co.uk", false],
95
- [PublicSuffix::Rule.factory("co.uk"), "uk", false],
96
-
97
- # partial matches/mismatches
98
- [PublicSuffix::Rule.factory("co"), "example.co.uk", false],
99
- [PublicSuffix::Rule.factory("example"), "example.uk", false],
100
- [PublicSuffix::Rule.factory("le.it"), "example.it", false],
101
- [PublicSuffix::Rule.factory("le.it"), "le.it", true],
102
- [PublicSuffix::Rule.factory("le.it"), "foo.le.it", true],
103
-
104
- ].each do |rule, input, expected|
105
- assert_equal expected, rule.match?(input)
106
- end
107
- end
108
-
109
-
110
- def test_parts
111
- assert_raises(NotImplementedError) { @klass.new(value: "com").parts }
112
- end
113
-
114
- def test_decompose
115
- assert_raises(NotImplementedError) { @klass.new(value: "com").decompose("google.com") }
116
- end
117
-
118
- end
119
-
120
-
121
- class PublicSuffix::RuleNormalTest < Minitest::Test
122
-
123
- def setup
124
- @klass = PublicSuffix::Rule::Normal
125
- end
126
-
127
-
128
- def test_build
129
- rule = @klass.build("verona.it")
130
- assert_instance_of @klass, rule
131
- assert_equal "verona.it", rule.value
132
- assert_equal "verona.it", rule.rule
133
- end
134
-
135
-
136
- def test_length
137
- assert_equal 1, @klass.build("com").length
138
- assert_equal 2, @klass.build("co.com").length
139
- assert_equal 3, @klass.build("mx.co.com").length
140
- end
141
-
142
- def test_parts
143
- assert_equal %w[com], @klass.build("com").parts
144
- assert_equal %w[co com], @klass.build("co.com").parts
145
- assert_equal %w[mx co com], @klass.build("mx.co.com").parts
146
- end
147
-
148
- def test_decompose
149
- assert_equal [nil, nil], @klass.build("com").decompose("com")
150
- assert_equal %w[example com], @klass.build("com").decompose("example.com")
151
- assert_equal %w[foo.example com], @klass.build("com").decompose("foo.example.com")
152
- end
153
-
154
- end
155
-
156
-
157
- class PublicSuffix::RuleExceptionTest < Minitest::Test
158
-
159
- def setup
160
- @klass = PublicSuffix::Rule::Exception
161
- end
162
-
163
-
164
- def test_initialize
165
- rule = @klass.build("!british-library.uk")
166
- assert_instance_of @klass, rule
167
- assert_equal "british-library.uk", rule.value
168
- assert_equal "!british-library.uk", rule.rule
169
- end
170
-
171
-
172
- def test_length
173
- assert_equal 2, @klass.build("!british-library.uk").length
174
- assert_equal 3, @klass.build("!foo.british-library.uk").length
175
- end
176
-
177
- def test_parts
178
- assert_equal %w[uk], @klass.build("!british-library.uk").parts
179
- assert_equal %w[tokyo jp], @klass.build("!metro.tokyo.jp").parts
180
- end
181
-
182
- def test_decompose
183
- assert_equal [nil, nil], @klass.build("!british-library.uk").decompose("uk")
184
- assert_equal %w[british-library uk], @klass.build("!british-library.uk").decompose("british-library.uk")
185
- assert_equal %w[foo.british-library uk], @klass.build("!british-library.uk").decompose("foo.british-library.uk")
186
- end
187
-
188
- end
189
-
190
-
191
- class PublicSuffix::RuleWildcardTest < Minitest::Test
192
-
193
- def setup
194
- @klass = PublicSuffix::Rule::Wildcard
195
- end
196
-
197
-
198
- def test_initialize
199
- rule = @klass.build("*.aichi.jp")
200
- assert_instance_of @klass, rule
201
- assert_equal "aichi.jp", rule.value
202
- assert_equal "*.aichi.jp", rule.rule
203
- end
204
-
205
-
206
- def test_length
207
- assert_equal 2, @klass.build("*.uk").length
208
- assert_equal 3, @klass.build("*.co.uk").length
209
- end
210
-
211
- def test_parts
212
- assert_equal %w[uk], @klass.build("*.uk").parts
213
- assert_equal %w[co uk], @klass.build("*.co.uk").parts
214
- end
215
-
216
- def test_decompose
217
- assert_equal [nil, nil], @klass.build("*.do").decompose("nic.do")
218
- assert_equal %w[google co.uk], @klass.build("*.uk").decompose("google.co.uk")
219
- assert_equal %w[foo.google co.uk], @klass.build("*.uk").decompose("foo.google.co.uk")
220
- end
221
-
222
- end