public_suffix 1.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,307 @@
1
+ require 'test_helper'
2
+
3
+ class PublicSuffix::RuleTest < Test::Unit::TestCase
4
+
5
+ def test_factory_should_return_rule_normal
6
+ rule = PublicSuffix::Rule.factory("com")
7
+ assert_instance_of PublicSuffix::Rule::Normal, rule
8
+
9
+ rule = PublicSuffix::Rule.factory("verona.it")
10
+ assert_instance_of PublicSuffix::Rule::Normal, rule
11
+ end
12
+
13
+ def test_factory_should_return_rule_exception
14
+ rule = PublicSuffix::Rule.factory("!british-library.uk")
15
+ assert_instance_of PublicSuffix::Rule::Exception, rule
16
+ end
17
+
18
+ def test_factory_should_return_rule_wildcard
19
+ rule = PublicSuffix::Rule.factory("*.do")
20
+ assert_instance_of PublicSuffix::Rule::Wildcard, rule
21
+
22
+ rule = PublicSuffix::Rule.factory("*.sch.uk")
23
+ assert_instance_of PublicSuffix::Rule::Wildcard, rule
24
+ end
25
+
26
+ end
27
+
28
+
29
+ class PublicSuffix::RuleBaseTest < Test::Unit::TestCase
30
+
31
+ class ::PublicSuffix::Rule::Test < ::PublicSuffix::Rule::Base
32
+ end
33
+
34
+ def setup
35
+ @klass = PublicSuffix::Rule::Base
36
+ end
37
+
38
+
39
+ def test_initialize
40
+ rule = @klass.new("verona.it")
41
+ assert_instance_of @klass, rule
42
+
43
+ assert_equal :base, rule.type
44
+ assert_equal "verona.it", rule.name
45
+ assert_equal "verona.it", rule.value
46
+ assert_equal %w(verona it).reverse, rule.labels
47
+ end
48
+
49
+ def test_equality_with_self
50
+ rule = PublicSuffix::Rule::Base.new("foo")
51
+ assert_equal rule, rule
52
+ end
53
+
54
+ def test_equality_with_internals
55
+ assert_equal @klass.new("foo"), @klass.new("foo")
56
+ assert_not_equal @klass.new("foo"), @klass.new("bar")
57
+ assert_not_equal @klass.new("foo"), PublicSuffix::Rule::Test.new("bar")
58
+ assert_not_equal @klass.new("foo"), Class.new { def name; foo; end }.new
59
+ end
60
+
61
+
62
+ def test_match
63
+ assert @klass.new("uk").match?("example.uk")
64
+ assert !@klass.new("gk").match?("example.uk")
65
+ assert !@klass.new("example").match?("example.uk")
66
+
67
+ assert @klass.new("uk").match?("example.co.uk")
68
+ assert !@klass.new("gk").match?("example.co.uk")
69
+ assert !@klass.new("co").match?("example.co.uk")
70
+
71
+ assert @klass.new("co.uk").match?("example.co.uk")
72
+ assert !@klass.new("uk.co").match?("example.co.uk")
73
+ assert !@klass.new("go.uk").match?("example.co.uk")
74
+ end
75
+
76
+ def test_length
77
+ assert_raise(NotImplementedError) { @klass.new("com").length }
78
+ end
79
+
80
+ def test_parts
81
+ assert_raise(NotImplementedError) { @klass.new("com").parts }
82
+ end
83
+
84
+ def test_decompose
85
+ assert_raise(NotImplementedError) { @klass.new("com").decompose("google.com") }
86
+ end
87
+
88
+ end
89
+
90
+
91
+ class PublicSuffix::RuleNormalTest < Test::Unit::TestCase
92
+
93
+ def setup
94
+ @klass = PublicSuffix::Rule::Normal
95
+ end
96
+
97
+
98
+ def test_initialize
99
+ rule = @klass.new("verona.it")
100
+ assert_instance_of @klass, rule
101
+ assert_equal :normal, rule.type
102
+ assert_equal "verona.it", rule.name
103
+ assert_equal "verona.it", rule.value
104
+ assert_equal %w(verona it).reverse, rule.labels
105
+ end
106
+
107
+
108
+ def test_match
109
+ assert @klass.new("uk").match?("example.uk")
110
+ assert !@klass.new("gk").match?("example.uk")
111
+ assert !@klass.new("example").match?("example.uk")
112
+
113
+ assert @klass.new("uk").match?("example.co.uk")
114
+ assert !@klass.new("gk").match?("example.co.uk")
115
+ assert !@klass.new("co").match?("example.co.uk")
116
+
117
+ assert @klass.new("co.uk").match?("example.co.uk")
118
+ assert !@klass.new("uk.co").match?("example.co.uk")
119
+ assert !@klass.new("go.uk").match?("example.co.uk")
120
+ end
121
+
122
+ def test_match_with_fully_qualified_domain_name
123
+ assert @klass.new("com").match?("com.")
124
+ assert @klass.new("com").match?("example.com.")
125
+ assert @klass.new("com").match?("www.example.com.")
126
+ end
127
+
128
+ def test_allow
129
+ assert !@klass.new("com").allow?("com")
130
+ assert @klass.new("com").allow?("example.com")
131
+ assert @klass.new("com").allow?("www.example.com")
132
+ end
133
+
134
+ def test_allow_with_fully_qualified_domain_name
135
+ assert !@klass.new("com").allow?("com.")
136
+ assert @klass.new("com").allow?("example.com.")
137
+ assert @klass.new("com").allow?("www.example.com.")
138
+ end
139
+
140
+
141
+ def test_length
142
+ assert_equal 1, @klass.new("com").length
143
+ assert_equal 2, @klass.new("co.com").length
144
+ assert_equal 3, @klass.new("mx.co.com").length
145
+ end
146
+
147
+ def test_parts
148
+ assert_equal %w(com), @klass.new("com").parts
149
+ assert_equal %w(co com), @klass.new("co.com").parts
150
+ assert_equal %w(mx co com), @klass.new("mx.co.com").parts
151
+ end
152
+
153
+ def test_decompose
154
+ assert_equal [nil, nil], @klass.new("com").decompose("com")
155
+ assert_equal %w( example com ), @klass.new("com").decompose("example.com")
156
+ assert_equal %w( foo.example com ), @klass.new("com").decompose("foo.example.com")
157
+ end
158
+
159
+ def test_decompose_with_fully_qualified_domain_name
160
+ assert_equal [nil, nil], @klass.new("com").decompose("com.")
161
+ assert_equal %w( example com ), @klass.new("com").decompose("example.com.")
162
+ assert_equal %w( foo.example com ), @klass.new("com").decompose("foo.example.com.")
163
+ end
164
+
165
+ end
166
+
167
+
168
+ class PublicSuffix::RuleExceptionTest < Test::Unit::TestCase
169
+
170
+ def setup
171
+ @klass = PublicSuffix::Rule::Exception
172
+ end
173
+
174
+
175
+ def test_initialize
176
+ rule = @klass.new("!british-library.uk")
177
+ assert_instance_of @klass, rule
178
+ assert_equal :exception, rule.type
179
+ assert_equal "!british-library.uk", rule.name
180
+ assert_equal "british-library.uk", rule.value
181
+ assert_equal %w(british-library uk).reverse, rule.labels
182
+ end
183
+
184
+
185
+ def test_match
186
+ assert @klass.new("!uk").match?("example.co.uk")
187
+ assert !@klass.new("!gk").match?("example.co.uk")
188
+ assert @klass.new("!co.uk").match?("example.co.uk")
189
+ assert !@klass.new("!go.uk").match?("example.co.uk")
190
+ assert @klass.new("!british-library.uk").match?("british-library.uk")
191
+ assert !@klass.new("!british-library.uk").match?("example.co.uk")
192
+ end
193
+
194
+ def test_match_with_fully_qualified_domain_name
195
+ assert @klass.new("!uk").match?("uk.")
196
+ assert @klass.new("!uk").match?("co.uk.")
197
+ assert @klass.new("!uk").match?("example.co.uk.")
198
+ assert @klass.new("!uk").match?("www.example.co.uk.")
199
+ end
200
+
201
+ def test_allow
202
+ assert !@klass.new("!british-library.uk").allow?("uk")
203
+ assert @klass.new("!british-library.uk").allow?("british-library.uk")
204
+ assert @klass.new("!british-library.uk").allow?("www.british-library.uk")
205
+ end
206
+
207
+ def test_allow_with_fully_qualified_domain_name
208
+ assert !@klass.new("!british-library.uk").allow?("uk.")
209
+ assert @klass.new("!british-library.uk").allow?("british-library.uk.")
210
+ assert @klass.new("!british-library.uk").allow?("www.british-library.uk.")
211
+ end
212
+
213
+
214
+ def test_length
215
+ assert_equal 1, @klass.new("!british-library.uk").length
216
+ assert_equal 2, @klass.new("!foo.british-library.uk").length
217
+ end
218
+
219
+ def test_parts
220
+ assert_equal %w( uk ), @klass.new("!british-library.uk").parts
221
+ assert_equal %w( tokyo jp ), @klass.new("!metro.tokyo.jp").parts
222
+ end
223
+
224
+ def test_decompose
225
+ assert_equal [nil, nil], @klass.new("!british-library.uk").decompose("uk")
226
+ assert_equal %w( british-library uk ), @klass.new("!british-library.uk").decompose("british-library.uk")
227
+ assert_equal %w( foo.british-library uk ), @klass.new("!british-library.uk").decompose("foo.british-library.uk")
228
+ end
229
+
230
+ def test_decompose_with_fully_qualified_domain_name
231
+ assert_equal [nil, nil], @klass.new("!british-library.uk").decompose("uk.")
232
+ assert_equal %w( british-library uk ), @klass.new("!british-library.uk").decompose("british-library.uk.")
233
+ assert_equal %w( foo.british-library uk ), @klass.new("!british-library.uk").decompose("foo.british-library.uk.")
234
+ end
235
+
236
+ end
237
+
238
+
239
+ class PublicSuffix::RuleWildcardTest < Test::Unit::TestCase
240
+
241
+ def setup
242
+ @klass = PublicSuffix::Rule::Wildcard
243
+ end
244
+
245
+
246
+ def test_initialize
247
+ rule = @klass.new("*.aichi.jp")
248
+ assert_instance_of @klass, rule
249
+ assert_equal :wildcard, rule.type
250
+ assert_equal "*.aichi.jp", rule.name
251
+ assert_equal "aichi.jp", rule.value
252
+ assert_equal %w(aichi jp).reverse, rule.labels
253
+ end
254
+
255
+
256
+ def test_match
257
+ assert @klass.new("*.uk").match?("example.uk")
258
+ assert @klass.new("*.uk").match?("example.co.uk")
259
+ assert @klass.new("*.co.uk").match?("example.co.uk")
260
+ assert !@klass.new("*.go.uk").match?("example.co.uk")
261
+ end
262
+
263
+ def test_match_with_fully_qualified_domain_name
264
+ assert @klass.new("*.uk").match?("uk.")
265
+ assert @klass.new("*.uk").match?("co.uk.")
266
+ assert @klass.new("*.uk").match?("example.co.uk.")
267
+ assert @klass.new("*.uk").match?("www.example.co.uk.")
268
+ end
269
+
270
+ def test_allow
271
+ assert !@klass.new("*.uk").allow?("uk")
272
+ assert !@klass.new("*.uk").allow?("co.uk")
273
+ assert @klass.new("*.uk").allow?("example.co.uk")
274
+ assert @klass.new("*.uk").allow?("www.example.co.uk")
275
+ end
276
+
277
+ def test_allow_with_fully_qualified_domain_name
278
+ assert !@klass.new("*.uk").allow?("uk.")
279
+ assert !@klass.new("*.uk").allow?("co.uk.")
280
+ assert @klass.new("*.uk").allow?("example.co.uk.")
281
+ assert @klass.new("*.uk").allow?("www.example.co.uk.")
282
+ end
283
+
284
+
285
+ def test_length
286
+ assert_equal 2, @klass.new("*.uk").length
287
+ assert_equal 3, @klass.new("*.co.uk").length
288
+ end
289
+
290
+ def test_parts
291
+ assert_equal %w( uk ), @klass.new("*.uk").parts
292
+ assert_equal %w( co uk ), @klass.new("*.co.uk").parts
293
+ end
294
+
295
+ def test_decompose
296
+ assert_equal [nil, nil], @klass.new("*.do").decompose("nic.do")
297
+ assert_equal %w( google co.uk ), @klass.new("*.uk").decompose("google.co.uk")
298
+ assert_equal %w( foo.google co.uk ), @klass.new("*.uk").decompose("foo.google.co.uk")
299
+ end
300
+
301
+ def test_decompose_with_fully_qualified_domain_name
302
+ assert_equal [nil, nil], @klass.new("*.do").decompose("nic.do.")
303
+ assert_equal %w( google co.uk ), @klass.new("*.uk").decompose("google.co.uk.")
304
+ assert_equal %w( foo.google co.uk ), @klass.new("*.uk").decompose("foo.google.co.uk.")
305
+ end
306
+
307
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: public_suffix
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.rc1
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Simone Carletti
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-12-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &70218169484160 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70218169484160
25
+ - !ruby/object:Gem::Dependency
26
+ name: mocha
27
+ requirement: &70218169483060 !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: *70218169483060
36
+ - !ruby/object:Gem::Dependency
37
+ name: yard
38
+ requirement: &70218169480880 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70218169480880
47
+ description: PublicSuffix can parse and decompose a domain name into top level domain,
48
+ domain and subdomains.
49
+ email: weppos@weppos.net
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gemtest
55
+ - .gitignore
56
+ - .travis.yml
57
+ - .yardopts
58
+ - CHANGELOG.md
59
+ - Gemfile
60
+ - Gemfile.lock
61
+ - LICENSE
62
+ - README.md
63
+ - Rakefile
64
+ - lib/public_suffix.rb
65
+ - lib/public_suffix/definitions.txt
66
+ - lib/public_suffix/domain.rb
67
+ - lib/public_suffix/errors.rb
68
+ - lib/public_suffix/list.rb
69
+ - lib/public_suffix/rule.rb
70
+ - lib/public_suffix/rule_list.rb
71
+ - lib/public_suffix/version.rb
72
+ - public_suffix.gemspec
73
+ - test/acceptance_test.rb
74
+ - test/test_helper.rb
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_service
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 1.8.7
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>'
96
+ - !ruby/object:Gem::Version
97
+ version: 1.3.1
98
+ requirements: []
99
+ rubyforge_project:
100
+ rubygems_version: 1.8.11
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: Domain name parser based in the Public Suffix List.
104
+ test_files:
105
+ - test/acceptance_test.rb
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