public_suffix_service 0.6.0 → 0.7.0

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.
@@ -18,7 +18,7 @@ module PublicSuffixService
18
18
 
19
19
  module Version
20
20
  MAJOR = 0
21
- MINOR = 6
21
+ MINOR = 7
22
22
  PATCH = 0
23
23
  BUILD = nil
24
24
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{public_suffix_service}
5
- s.version = "0.5.2"
5
+ s.version = "0.6.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Simone Carletti"]
9
- s.date = %q{2010-09-17}
9
+ s.date = %q{2010-09-18}
10
10
  s.description = %q{ Intelligent domain name parser based in the Public Suffic List. PublicSuffixService can parse and decompose a domain name into top level domain, domain and subdomains.
11
11
  }
12
12
  s.email = %q{weppos@weppos.net}
@@ -121,12 +121,19 @@ class PublicSuffixService::DomainTest < Test::Unit::TestCase
121
121
  end
122
122
 
123
123
  def test_valid_question
124
- assert @klass.new("com").valid?
125
- assert @klass.new("com", "google").valid?
126
- assert @klass.new("com", "google", "www").valid?
124
+ assert !@klass.new("com").valid?
125
+ assert @klass.new("com", "example").valid?
126
+ assert @klass.new("com", "example", "www").valid?
127
+
128
+ # not-assigned
127
129
  assert !@klass.new("zip").valid?
128
- assert !@klass.new("zip", "google").valid?
129
- assert !@klass.new("zip", "google", "www").valid?
130
+ assert !@klass.new("zip", "example").valid?
131
+ assert !@klass.new("zip", "example", "www").valid?
132
+
133
+ # not-allowed
134
+ assert !@klass.new("do").valid?
135
+ assert !@klass.new("do", "example").valid?
136
+ assert @klass.new("do", "example", "www").valid?
130
137
  end
131
138
 
132
139
  def test_valid_domain_question
@@ -20,7 +20,7 @@ class PublicSuffixService::RuleListTest < Test::Unit::TestCase
20
20
  assert_equal({}, @list.indexes)
21
21
  end
22
22
 
23
- def test_find__with_index
23
+ def test_indexes
24
24
  @list = PublicSuffixService::RuleList.parse(<<EOS)
25
25
  // com : http://en.wikipedia.org/wiki/.com
26
26
  com
@@ -56,6 +56,16 @@ EOS
56
56
  assert_equal 2, @list.length
57
57
  end
58
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
+
59
69
  def test_empty?
60
70
  assert @list.empty?
61
71
  @list.add(PublicSuffixService::Rule.factory(""))
@@ -134,52 +144,18 @@ EOS
134
144
 
135
145
  def test_self_reload
136
146
  PublicSuffixService::RuleList.default
137
- PublicSuffixService::RuleList.expects(:default_definition).returns("")
147
+ mock(PublicSuffixService::RuleList).default_definition { "" }
148
+
138
149
  PublicSuffixService::RuleList.reload
139
150
  assert_equal PublicSuffixService::RuleList.new, PublicSuffixService::RuleList.default
140
151
  end
141
152
 
153
+
142
154
  def test_self_parse
143
- input = <<EOS
155
+ list = PublicSuffixService::RuleList.parse(<<EOS)
144
156
  // ***** BEGIN LICENSE BLOCK *****
145
157
  // Version: MPL 1.1/GPL 2.0/LGPL 2.1
146
158
  //
147
- // The contents of this file are subject to the Mozilla Public License Version
148
- // 1.1 (the "License"); you may not use this file except in compliance with
149
- // the License. You may obtain a copy of the License at
150
- // http://www.mozilla.org/MPL/
151
- //
152
- // Software distributed under the License is distributed on an "AS IS" basis,
153
- // WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
154
- // for the specific language governing rights and limitations under the
155
- // License.
156
- //
157
- // The Original Code is the Public Suffix List.
158
- //
159
- // The Initial Developer of the Original Code is
160
- // Jo Hermans <jo.hermans@gmail.com>.
161
- // Portions created by the Initial Developer are Copyright (C) 2007
162
- // the Initial Developer. All Rights Reserved.
163
- //
164
- // Contributor(s):
165
- // Ruben Arakelyan <ruben@wackomenace.co.uk>
166
- // Gervase Markham <gerv@gerv.net>
167
- // Pamela Greene <pamg.bugs@gmail.com>
168
- // David Triendl <david@triendl.name>
169
- // The kind representatives of many TLD registries
170
- //
171
- // Alternatively, the contents of this file may be used under the terms of
172
- // either the GNU General Public License Version 2 or later (the "GPL"), or
173
- // the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
174
- // in which case the provisions of the GPL or the LGPL are applicable instead
175
- // of those above. If you wish to allow use of your version of this file only
176
- // under the terms of either the GPL or the LGPL, and not to allow others to
177
- // use your version of this file under the terms of the MPL, indicate your
178
- // decision by deleting the provisions above and replace them with the notice
179
- // and other provisions required by the GPL or the LGPL. If you do not delete
180
- // the provisions above, a recipient may use your version of this file under
181
- // the terms of any one of the MPL, the GPL or the LGPL.
182
- //
183
159
  // ***** END LICENSE BLOCK *****
184
160
 
185
161
  // ac : http://en.wikipedia.org/wiki/.ac
@@ -193,12 +169,25 @@ ad
193
169
  *.ar
194
170
  !congresodelalengua3.ar
195
171
  EOS
196
- expected = []
197
- list = PublicSuffixService::RuleList.parse(input)
198
172
 
199
173
  assert_instance_of PublicSuffixService::RuleList, list
200
174
  assert_equal 5, list.length
201
175
  assert_equal %w(ac com.ac ad *.ar !congresodelalengua3.ar).map { |name| PublicSuffixService::Rule.factory(name) }, list.to_a
202
176
  end
203
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
+
204
193
  end
@@ -60,15 +60,15 @@ class PublicSuffixService::RuleBaseTest < Test::Unit::TestCase
60
60
 
61
61
 
62
62
  def test_match
63
- assert @klass.new("uk").match?("google.uk")
64
- assert !@klass.new("gk").match?("google.uk")
65
- assert !@klass.new("google").match?("google.uk")
66
- assert @klass.new("uk").match?("google.co.uk")
67
- assert !@klass.new("gk").match?("google.co.uk")
68
- assert !@klass.new("co").match?("google.co.uk")
69
- assert @klass.new("co.uk").match?("google.co.uk")
70
- assert !@klass.new("uk.co").match?("google.co.uk")
71
- assert !@klass.new("go.uk").match?("google.co.uk")
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
+ assert @klass.new("uk").match?("example.co.uk")
67
+ assert !@klass.new("gk").match?("example.co.uk")
68
+ assert !@klass.new("co").match?("example.co.uk")
69
+ assert @klass.new("co.uk").match?("example.co.uk")
70
+ assert !@klass.new("uk.co").match?("example.co.uk")
71
+ assert !@klass.new("go.uk").match?("example.co.uk")
72
72
  end
73
73
 
74
74
  def test_length
@@ -104,17 +104,24 @@ class PublicSuffixService::RuleNormalTest < Test::Unit::TestCase
104
104
 
105
105
 
106
106
  def test_match
107
- assert @klass.new("uk").match?("google.uk")
108
- assert !@klass.new("gk").match?("google.uk")
109
- assert !@klass.new("google").match?("google.uk")
110
- assert @klass.new("uk").match?("google.co.uk")
111
- assert !@klass.new("gk").match?("google.co.uk")
112
- assert !@klass.new("co").match?("google.co.uk")
113
- assert @klass.new("co.uk").match?("google.co.uk")
114
- assert !@klass.new("uk.co").match?("google.co.uk")
115
- assert !@klass.new("go.uk").match?("google.co.uk")
107
+ assert @klass.new("uk").match?("example.uk")
108
+ assert !@klass.new("gk").match?("example.uk")
109
+ assert !@klass.new("example").match?("example.uk")
110
+ assert @klass.new("uk").match?("example.co.uk")
111
+ assert !@klass.new("gk").match?("example.co.uk")
112
+ assert !@klass.new("co").match?("example.co.uk")
113
+ assert @klass.new("co.uk").match?("example.co.uk")
114
+ assert !@klass.new("uk.co").match?("example.co.uk")
115
+ assert !@klass.new("go.uk").match?("example.co.uk")
116
116
  end
117
117
 
118
+ def test_allow
119
+ assert !@klass.new("com").allow?("com")
120
+ assert @klass.new("com").allow?("example.com")
121
+ assert @klass.new("com").allow?("www.example.com")
122
+ end
123
+
124
+
118
125
  def test_length
119
126
  assert_equal 1, @klass.new("com").length
120
127
  assert_equal 2, @klass.new("co.com").length
@@ -128,8 +135,8 @@ class PublicSuffixService::RuleNormalTest < Test::Unit::TestCase
128
135
  end
129
136
 
130
137
  def test_decompose
131
- assert_equal %w(google com), @klass.new("com").decompose("google.com")
132
- assert_equal %w(foo.google com), @klass.new("com").decompose("foo.google.com")
138
+ assert_equal %w(example com), @klass.new("com").decompose("example.com")
139
+ assert_equal %w(foo.example com), @klass.new("com").decompose("foo.example.com")
133
140
  end
134
141
 
135
142
  end
@@ -153,14 +160,15 @@ class PublicSuffixService::RuleExceptionTest < Test::Unit::TestCase
153
160
 
154
161
 
155
162
  def test_match
156
- assert @klass.new("!uk").match?("google.co.uk")
157
- assert !@klass.new("!gk").match?("google.co.uk")
158
- assert @klass.new("!co.uk").match?("google.co.uk")
159
- assert !@klass.new("!go.uk").match?("google.co.uk")
163
+ assert @klass.new("!uk").match?("example.co.uk")
164
+ assert !@klass.new("!gk").match?("example.co.uk")
165
+ assert @klass.new("!co.uk").match?("example.co.uk")
166
+ assert !@klass.new("!go.uk").match?("example.co.uk")
160
167
  assert @klass.new("!british-library.uk").match?("british-library.uk")
161
- assert !@klass.new("!british-library.uk").match?("google.co.uk")
168
+ assert !@klass.new("!british-library.uk").match?("example.co.uk")
162
169
  end
163
170
 
171
+
164
172
  def test_length
165
173
  assert_equal 1, @klass.new("!british-library.uk").length
166
174
  assert_equal 2, @klass.new("!foo.british-library.uk").length
@@ -197,12 +205,19 @@ class PublicSuffixService::RuleWildcardTest < Test::Unit::TestCase
197
205
 
198
206
 
199
207
  def test_match
200
- assert @klass.new("*.uk").match?("google.uk")
201
- assert @klass.new("*.uk").match?("google.co.uk")
202
- assert @klass.new("*.co.uk").match?("google.co.uk")
203
- assert !@klass.new("*.go.uk").match?("google.co.uk")
208
+ assert @klass.new("*.uk").match?("example.uk")
209
+ assert @klass.new("*.uk").match?("example.co.uk")
210
+ assert @klass.new("*.co.uk").match?("example.co.uk")
211
+ assert !@klass.new("*.go.uk").match?("example.co.uk")
204
212
  end
205
213
 
214
+ def test_allow
215
+ assert !@klass.new("*.com").allow?("com")
216
+ assert !@klass.new("*.com").allow?("example.com")
217
+ assert @klass.new("*.com").allow?("www.example.com")
218
+ end
219
+
220
+
206
221
  def test_length
207
222
  assert_equal 2, @klass.new("*.uk").length
208
223
  assert_equal 3, @klass.new("*.co.uk").length
@@ -3,50 +3,55 @@ require 'test_helper'
3
3
  class PublicSuffixServiceTest < Test::Unit::TestCase
4
4
 
5
5
  def test_self_parse_a_domain_with_tld_and_sld
6
- domain = PublicSuffixService.parse("google.com")
6
+ domain = PublicSuffixService.parse("example.com")
7
7
  assert_instance_of PublicSuffixService::Domain, domain
8
8
  assert_equal "com", domain.tld
9
- assert_equal "google", domain.sld
9
+ assert_equal "example", domain.sld
10
10
  assert_equal nil, domain.trd
11
11
 
12
- domain = PublicSuffixService.parse("google.co.uk")
12
+ domain = PublicSuffixService.parse("example.co.uk")
13
13
  assert_instance_of PublicSuffixService::Domain, domain
14
14
  assert_equal "co.uk", domain.tld
15
- assert_equal "google", domain.sld
15
+ assert_equal "example", domain.sld
16
16
  assert_equal nil, domain.trd
17
17
  end
18
18
 
19
19
  def test_self_parse_a_domain_with_tld_and_sld_and_trd
20
- domain = PublicSuffixService.parse("alpha.google.com")
20
+ domain = PublicSuffixService.parse("alpha.example.com")
21
21
  assert_instance_of PublicSuffixService::Domain, domain
22
22
  assert_equal "com", domain.tld
23
- assert_equal "google", domain.sld
23
+ assert_equal "example", domain.sld
24
24
  assert_equal "alpha", domain.trd
25
25
 
26
- domain = PublicSuffixService.parse("alpha.google.co.uk")
26
+ domain = PublicSuffixService.parse("alpha.example.co.uk")
27
27
  assert_instance_of PublicSuffixService::Domain, domain
28
28
  assert_equal "co.uk", domain.tld
29
- assert_equal "google", domain.sld
29
+ assert_equal "example", domain.sld
30
30
  assert_equal "alpha", domain.trd
31
31
  end
32
32
 
33
33
  def test_self_parse_a_domain_with_tld_and_sld_and_4rd
34
- domain = PublicSuffixService.parse("one.two.google.com")
34
+ domain = PublicSuffixService.parse("one.two.example.com")
35
35
  assert_instance_of PublicSuffixService::Domain, domain
36
36
  assert_equal "com", domain.tld
37
- assert_equal "google", domain.sld
37
+ assert_equal "example", domain.sld
38
38
  assert_equal "one.two", domain.trd
39
39
 
40
- domain = PublicSuffixService.parse("one.two.google.co.uk")
40
+ domain = PublicSuffixService.parse("one.two.example.co.uk")
41
41
  assert_instance_of PublicSuffixService::Domain, domain
42
42
  assert_equal "co.uk", domain.tld
43
- assert_equal "google", domain.sld
43
+ assert_equal "example", domain.sld
44
44
  assert_equal "one.two", domain.trd
45
45
  end
46
46
 
47
47
  def test_self_parse_should_raise_with_invalid_domain
48
- error = assert_raise(PublicSuffixService::DomainInvalid) { PublicSuffixService.parse("google.zip") }
49
- assert_match %r{google\.zip}, error.message
48
+ error = assert_raise(PublicSuffixService::DomainInvalid) { PublicSuffixService.parse("example.zip") }
49
+ assert_match %r{example\.zip}, error.message
50
+ end
51
+
52
+ def test_self_parse_should_raise_with_unallowed_domain
53
+ error = assert_raise(PublicSuffixService::DomainNotAllowed) { PublicSuffixService.parse("example.do") }
54
+ assert_match %r{example\.do}, error.message
50
55
  end
51
56
 
52
57
 
data/test/test_helper.rb CHANGED
@@ -2,8 +2,9 @@ $:.unshift(File.dirname(__FILE__) + '/../lib')
2
2
 
3
3
  require 'rubygems'
4
4
  require 'test/unit'
5
- require 'mocha'
5
+ require 'rr'
6
6
  require 'public_suffix_service'
7
7
 
8
8
  class Test::Unit::TestCase
9
+ include RR::Adapters::TestUnit
9
10
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: public_suffix_service
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
8
+ - 7
9
9
  - 0
10
- version: 0.6.0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Simone Carletti
@@ -15,11 +15,11 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-18 00:00:00 +02:00
18
+ date: 2010-10-09 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
- name: mocha
22
+ name: rr
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
25
  none: false