mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
[ruby/ipaddr] Added to_json/as_json method
Updated to use cidr method when return address with prefix in #as_json
cf8181d53e
This commit is contained in:
parent
6b1268c7bf
commit
eb8cf1d60e
2 changed files with 30 additions and 0 deletions
|
@ -260,6 +260,20 @@ class TC_IPAddr < Test::Unit::TestCase
|
|||
assert_equal("3ffe:505:2::1", IPAddr.new("3ffe:505:2::1").to_s)
|
||||
end
|
||||
|
||||
def test_as_json
|
||||
assert_equal("192.168.1.2", IPAddr.new("192.168.1.2").as_json)
|
||||
assert_equal("192.168.1.0/24", IPAddr.new("192.168.1.2/24").as_json)
|
||||
assert_equal("2001:200:300::1", IPAddr.new("2001:200:300::1").as_json)
|
||||
assert_equal("2001:200:300::/48", IPAddr.new("2001:200:300::/48").as_json)
|
||||
end
|
||||
|
||||
def test_to_json
|
||||
assert_equal("\"192.168.1.2\"", IPAddr.new("192.168.1.2").to_json)
|
||||
assert_equal("\"192.168.1.0/24\"", IPAddr.new("192.168.1.2/24").to_json)
|
||||
assert_equal("\"2001:200:300::1\"", IPAddr.new("2001:200:300::1").to_json)
|
||||
assert_equal("\"2001:200:300::/48\"", IPAddr.new("2001:200:300::/48").to_json)
|
||||
end
|
||||
|
||||
def test_netmask
|
||||
a = IPAddr.new("192.168.1.2/8")
|
||||
assert_equal(a.netmask, "255.0.0.0")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue