ipaddress 0.5.0 → 0.6.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.
@@ -83,7 +83,7 @@ class IPv6Test < Test::Unit::TestCase
83
83
  assert_equal 128, ip.prefix
84
84
  ip.prefix = 64
85
85
  assert_equal 64, ip.prefix
86
- assert_equal "2001:db8::8:800:200c:417a/64", ip.to_s
86
+ assert_equal "2001:db8::8:800:200c:417a/64", ip.to_string
87
87
  end
88
88
 
89
89
  def test_method_mapped?
@@ -111,18 +111,36 @@ class IPv6Test < Test::Unit::TestCase
111
111
  end
112
112
 
113
113
  def test_method_to_s
114
- assert_equal "2001:db8::8:800:200c:417a/64", @ip.to_s
114
+ assert_equal "2001:db8::8:800:200c:417a", @ip.to_s
115
115
  end
116
116
 
117
117
  def test_method_to_string
118
+ assert_equal "2001:db8::8:800:200c:417a/64", @ip.to_string
119
+ end
120
+
121
+ def test_method_to_string_uncompressed
118
122
  str = "2001:0db8:0000:0000:0008:0800:200c:417a/64"
119
- assert_equal str, @ip.to_string
123
+ assert_equal str, @ip.to_string_uncompressed
120
124
  end
121
125
 
122
126
  def test_method_data
123
127
  str = " \001\r\270\000\000\000\000\000\b\b\000 \fAz"
124
128
  assert_equal str, @ip.data
125
129
  end
130
+
131
+
132
+ def test_method_reverse
133
+ str = "f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.5.0.5.0.e.f.f.3.ip6.arpa"
134
+ assert_equal str, @klass.new("3ffe:505:2::f").reverse
135
+ end
136
+
137
+ # def test_ip6_int
138
+ # assert_equal("f.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.5.0.5.0.e.f.f.3.ip6.int", IPAddress("3ffe:505:2::f").ip6_int)
139
+ # assert_raises(ArgumentError) {
140
+ # IPAddress("192.168.2.1").ip6_int
141
+ # }
142
+ # end
143
+
126
144
 
127
145
  def test_method_compressed
128
146
  assert_equal "1:1:1::1", @klass.new("1:1:1:0:0:0:0:1").compressed
@@ -181,7 +199,7 @@ class IPv6Test < Test::Unit::TestCase
181
199
  ip = @klass.parse_data str
182
200
  assert_instance_of @klass, ip
183
201
  assert_equal "2001:0db8:0000:0000:0008:0800:200c:417a", ip.address
184
- assert_equal "2001:db8::8:800:200c:417a/128", ip.to_s
202
+ assert_equal "2001:db8::8:800:200c:417a/128", ip.to_string
185
203
  end
186
204
 
187
205
  def test_classhmethod_parse_u128
@@ -201,6 +219,7 @@ class IPv6UnspecifiedTest < Test::Unit::TestCase
201
219
  def setup
202
220
  @klass = IPAddress::IPv6::Unspecified
203
221
  @ip = @klass.new
222
+ @s = "::"
204
223
  @str = "::/128"
205
224
  @string = "0000:0000:0000:0000:0000:0000:0000:0000/128"
206
225
  @u128 = 0
@@ -216,8 +235,9 @@ class IPv6UnspecifiedTest < Test::Unit::TestCase
216
235
  assert_equal @address, @ip.compressed
217
236
  assert_equal 128, @ip.prefix
218
237
  assert_equal true, @ip.unspecified?
219
- assert_equal @str, @ip.to_s
220
- assert_equal @string, @ip.to_string
238
+ assert_equal @s, @ip.to_s
239
+ assert_equal @str, @ip.to_string
240
+ assert_equal @string, @ip.to_string_uncompressed
221
241
  assert_equal @u128, @ip.to_u128
222
242
  end
223
243
 
@@ -229,6 +249,7 @@ class IPv6LoopbackTest < Test::Unit::TestCase
229
249
  def setup
230
250
  @klass = IPAddress::IPv6::Loopback
231
251
  @ip = @klass.new
252
+ @s = "::1"
232
253
  @str = "::1/128"
233
254
  @string = "0000:0000:0000:0000:0000:0000:0000:0001/128"
234
255
  @u128 = 1
@@ -244,8 +265,9 @@ class IPv6LoopbackTest < Test::Unit::TestCase
244
265
  assert_equal @address, @ip.compressed
245
266
  assert_equal 128, @ip.prefix
246
267
  assert_equal true, @ip.loopback?
247
- assert_equal @str, @ip.to_s
248
- assert_equal @string, @ip.to_string
268
+ assert_equal @s, @ip.to_s
269
+ assert_equal @str, @ip.to_string
270
+ assert_equal @string, @ip.to_string_uncompressed
249
271
  assert_equal @u128, @ip.to_u128
250
272
  end
251
273
 
@@ -256,6 +278,7 @@ class IPv6MappedTest < Test::Unit::TestCase
256
278
  def setup
257
279
  @klass = IPAddress::IPv6::Mapped
258
280
  @ip = @klass.new("::172.16.10.1")
281
+ @s = "::ffff:172.16.10.1"
259
282
  @str = "::ffff:172.16.10.1/128"
260
283
  @string = "0000:0000:0000:0000:0000:ffff:ac10:0a01/128"
261
284
  @u128 = 281473568475649
@@ -278,8 +301,9 @@ class IPv6MappedTest < Test::Unit::TestCase
278
301
  def test_attributes
279
302
  assert_equal @address, @ip.compressed
280
303
  assert_equal 128, @ip.prefix
281
- assert_equal @str, @ip.to_s
282
- assert_equal @string, @ip.to_string
304
+ assert_equal @s, @ip.to_s
305
+ assert_equal @str, @ip.to_string
306
+ assert_equal @string, @ip.to_string_uncompressed
283
307
  assert_equal @u128, @ip.to_u128
284
308
  end
285
309
 
@@ -68,6 +68,21 @@ class Prefix32Test < Test::Unit::TestCase
68
68
  end
69
69
  end
70
70
 
71
+ def test_method_plus
72
+ p1 = @klass.new 8
73
+ p2 = @klass.new 10
74
+ assert_equal 18, p1+p2
75
+ assert_equal 12, p1+4
76
+ end
77
+
78
+ def test_method_minus
79
+ p1 = @klass.new 8
80
+ p2 = @klass.new 24
81
+ assert_equal 16, p1-p2
82
+ assert_equal 16, p2-p1
83
+ assert_equal 20, p2-4
84
+ end
85
+
71
86
  def test_initialize
72
87
  assert_raise (ArgumentError) do
73
88
  @klass.new 33
@@ -33,6 +33,23 @@ class IPAddressTest < Test::Unit::TestCase
33
33
 
34
34
  end
35
35
 
36
+ def test_module_method_valid?
37
+ assert_equal true, IPAddress::valid?("10.0.0.1")
38
+ assert_equal true, IPAddress::valid?("10.0.0.0")
39
+ assert_equal true, IPAddress::valid?("2002::1")
40
+ assert_equal true, IPAddress::valid?("dead:beef:cafe:babe::f0ad")
41
+ assert_equal false, IPAddress::valid?("10.0.0.256")
42
+ assert_equal false, IPAddress::valid?("10.0.0.0.0")
43
+ assert_equal false, IPAddress::valid?("10.0.0")
44
+ assert_equal false, IPAddress::valid?("10.0")
45
+ assert_equal false, IPAddress::valid?("2002:::1")
46
+ end
47
+
48
+ def test_module_method_valid_ipv4_netmark?
49
+ assert_equal true, IPAddress::valid_ipv4_netmask?("255.255.255.0")
50
+ assert_equal false, IPAddress::valid_ipv4_netmask?("10.0.0.1")
51
+ end
52
+
36
53
  end
37
54
 
38
55
 
@@ -1,15 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
- require 'ruby-prof'
4
-
5
3
 
6
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
6
  require 'ipaddress'
9
7
 
10
- class Test::Unit::TestCase
11
- end
12
-
13
8
  module Test::Unit
14
9
 
15
10
  class TestCase
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ipaddress
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 5
9
- - 0
10
- version: 0.5.0
4
+ version: 0.6.0
11
5
  platform: ruby
12
6
  authors:
13
7
  - Marco Ceresa
@@ -15,11 +9,11 @@ autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
11
 
18
- date: 2010-05-22 00:00:00 +01:00
12
+ date: 2010-07-19 00:00:00 +02:00
19
13
  default_executable:
20
14
  dependencies: []
21
15
 
22
- description:
16
+ description: " IPAddress is a Ruby library designed to make manipulation \n of IPv4 and IPv6 addresses both powerful and simple. It mantains\n a layer of compatibility with Ruby's own IPAddr, while \n addressing many of its issues.\n"
23
17
  email: ceresa@gmail.com
24
18
  executables: []
25
19
 
@@ -31,18 +25,17 @@ extra_rdoc_files:
31
25
  files:
32
26
  - .document
33
27
  - .gitignore
28
+ - CHANGELOG.rdoc
34
29
  - LICENSE
35
30
  - README.rdoc
36
31
  - Rakefile
37
32
  - VERSION
38
33
  - lib/ipaddress.rb
39
34
  - lib/ipaddress/extensions/extensions.rb
40
- - lib/ipaddress/ipbase.rb
41
35
  - lib/ipaddress/ipv4.rb
42
36
  - lib/ipaddress/ipv6.rb
43
37
  - lib/ipaddress/prefix.rb
44
38
  - test/ipaddress/extensions/extensions_test.rb
45
- - test/ipaddress/ipbase_test.rb
46
39
  - test/ipaddress/ipv4_test.rb
47
40
  - test/ipaddress/ipv6_test.rb
48
41
  - test/ipaddress/prefix_test.rb
@@ -58,35 +51,28 @@ rdoc_options:
58
51
  require_paths:
59
52
  - lib
60
53
  required_ruby_version: !ruby/object:Gem::Requirement
61
- none: false
62
54
  requirements:
63
55
  - - ">="
64
56
  - !ruby/object:Gem::Version
65
- hash: 3
66
- segments:
67
- - 0
68
57
  version: "0"
58
+ version:
69
59
  required_rubygems_version: !ruby/object:Gem::Requirement
70
- none: false
71
60
  requirements:
72
61
  - - ">="
73
62
  - !ruby/object:Gem::Version
74
- hash: 3
75
- segments:
76
- - 0
77
63
  version: "0"
64
+ version:
78
65
  requirements: []
79
66
 
80
67
  rubyforge_project:
81
- rubygems_version: 1.3.7
68
+ rubygems_version: 1.3.5
82
69
  signing_key:
83
70
  specification_version: 3
84
71
  summary: IPv4/IPv6 addresses manipulation library
85
72
  test_files:
86
- - test/ipaddress/prefix_test.rb
87
- - test/ipaddress/ipbase_test.rb
88
- - test/ipaddress/ipv4_test.rb
89
- - test/ipaddress/extensions/extensions_test.rb
90
- - test/ipaddress/ipv6_test.rb
91
73
  - test/test_helper.rb
92
74
  - test/ipaddress_test.rb
75
+ - test/ipaddress/prefix_test.rb
76
+ - test/ipaddress/ipv6_test.rb
77
+ - test/ipaddress/extensions/extensions_test.rb
78
+ - test/ipaddress/ipv4_test.rb
@@ -1,83 +0,0 @@
1
- require 'ipaddress/extensions/extensions'
2
-
3
- module IPAddress
4
-
5
- #
6
- # Checks if the given string is a valid IP address,
7
- # either IPv4 or IPv6
8
- #
9
- # Example:
10
- #
11
- # IPAddress::valid? "2002::1"
12
- # #=> true
13
- #
14
- # IPAddress::valid? "10.0.0.256"
15
- # #=> false
16
- #
17
- def self.valid?(addr)
18
- valid_ipv4?(addr) || valid_ipv6?(addr)
19
- end
20
-
21
- #
22
- # Checks if the given string is a valid IPv4 address
23
- #
24
- # Example:
25
- #
26
- # IPAddress::valid_ipv4? "2002::1"
27
- # #=> false
28
- #
29
- # IPAddress::valid_ipv4? "172.16.10.1"
30
- # #=> true
31
- #
32
- def self.valid_ipv4?(addr)
33
- if /\A(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\Z/ =~ addr
34
- return $~.captures.all? {|i| i.to_i < 256}
35
- end
36
- false
37
- end
38
-
39
- #
40
- # Checks if the argument is a valid IPv4 netmark
41
- # expressed in dotted decimal format.
42
- #
43
- # IPAddress.valid_ipv4_netmask? "255.255.0.0"
44
- # #=> true
45
- #
46
- def self.valid_ipv4_netmask?(addr)
47
- arr = addr.split(".").map{|i| i.to_i}.pack("CCCC").unpack("B*").first.scan(/01/)
48
- arr.empty? && valid_ipv4?(addr)
49
- rescue
50
- return false
51
- end
52
-
53
- #
54
- # Checks if the given string is a valid IPv6 address
55
- #
56
- # Example:
57
- #
58
- # IPAddress::valid_ipv6? "2002::1"
59
- # #=> true
60
- #
61
- # IPAddress::valid_ipv6? "2002::DEAD::BEEF"
62
- # #=> false
63
- #
64
- def self.valid_ipv6?(addr)
65
- # IPv6 (normal)
66
- return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*\Z/ =~ addr
67
- return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/ =~ addr
68
- return true if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*)?\Z/ =~ addr
69
- # IPv6 (IPv4 compat)
70
- return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:/ =~ addr && valid_ipv4?($')
71
- return true if /\A[\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?($')
72
- return true if /\A::([\dA-Fa-f]{1,4}(:[\dA-Fa-f]{1,4})*:)?/ =~ addr && valid_ipv4?($')
73
- false
74
- end
75
-
76
- class IPBase; end
77
-
78
- end # module IPAddress
79
-
80
-
81
-
82
-
83
-
@@ -1,28 +0,0 @@
1
- require 'test_helper'
2
-
3
- class IpaddressTest < Test::Unit::TestCase
4
-
5
- must "be valid ip" do
6
- assert_equal true, IPAddress::valid?("10.0.0.1")
7
- assert_equal true, IPAddress::valid?("10.0.0.0")
8
- assert_equal true, IPAddress::valid?("2002::1")
9
- assert_equal true, IPAddress::valid?("dead:beef:cafe:babe::f0ad")
10
- end
11
-
12
- must "be valid netmask" do
13
- assert_equal true, IPAddress::valid_ipv4_netmask?("255.255.255.0")
14
- end
15
-
16
- must "be invalid netmask" do
17
- assert_equal false, IPAddress::valid_ipv4_netmask?("10.0.0.1")
18
- end
19
-
20
- must "be invalid" do
21
- assert_equal false, IPAddress::valid?("10.0.0.256")
22
- assert_equal false, IPAddress::valid?("10.0.0.0.0")
23
- assert_equal false, IPAddress::valid?("10.0.0")
24
- assert_equal false, IPAddress::valid?("10.0")
25
- assert_equal false, IPAddress::valid?("2002:::1")
26
- end
27
-
28
- end