#!/usr/bin/env ruby # ## Unit test for Net::CIDR # require 'rubygems' require File.join(File.dirname(__FILE__), 'cidr') require 'spec' describe Net::CIDR do it "should handle range2cidr on IPv4, test 1" do result = Net::CIDR::range2cidr("192.68.0.0-192.68.255.255", "10.0.0.0-10.3.255.255") result.should eql(%w(192.68.0.0/16 10.0.0.0/14)) end it "should handle range2cidr on IPv6" do result = Net::CIDR::range2cidr("dead:beef::-dead:beef:ffff:ffff:ffff:ffff:ffff:ffff") result.should eql(%w(dead:beef::/32)) end it "should handle range2cidr on IPv4, test 2" do result = Net::CIDR::range2cidr("192.68.1.0-192.68.2.255") result.should eql(%w(192.68.1.0/24 192.68.2.0/24)) end it "should handle cidr2range on IPv4, test 1" do result = Net::CIDR::cidr2range("192.68.0.0/16") result.should eql(%w(192.68.0.0-192.68.255.255)) end it "should handle cidr2range on IPv6, test 1" do result = Net::CIDR::cidr2range("dead::beef::/46") result.should eql(%w(dead:beef::-dead:beef:3:ffff:ffff:ffff:ffff:ffff)) end it "should handle cidradd, test 1" do list = ["192.68.0.0/24"] result = Net::CIDR::cidradd("192.68.1.0-192.68.1.255", list) result.should eql(%w(192.68.0.0/23)) end it "should handle cidr2octets, test 1" do result = Net::CIDR::cidr2octets("192.68.0.0/22") result.should eql(%w(192.68.0 192.68.1 192.68.2 192.68.3)) end it "should handle cidr2octets with IPv6, test 1" do result = Net::CIDR::cidr2octets("dead::beef::/46") result.should eql(%w(dead:beef:0000 dead:beef:0001 dead:beef:0002 dead:beef:0003)) end it "should handle cidrlookup, test 1" do list = ["192.68.0.0/24"] result = Net::CIDR::cidrlookup("192.68.0.12", list) result.should eql(true) end it "should handle addr2cidr with IPv4, test 1" do result = Net::CIDR::addr2cidr("192.68.0.31") result.should eql(%w( 192.68.0.31/32 192.68.0.30/31 192.68.0.28/30 192.68.0.24/29 192.68.0.16/28 192.68.0.0/27 192.68.0.0/26 192.68.0.0/25 192.68.0.0/24 192.68.0.0/23 192.68.0.0/22 192.68.0.0/21 192.68.0.0/20 192.68.0.0/19 192.68.0.0/18 192.68.0.0/17 192.68.0.0/16 192.68.0.0/15 192.68.0.0/14 192.64.0.0/13 192.64.0.0/12 192.64.0.0/11 192.64.0.0/10 192.0.0.0/9 192.0.0.0/8 192.0.0.0/7 192.0.0.0/6 192.0.0.0/5 192.0.0.0/4 192.0.0.0/3 192.0.0.0/2 128.0.0.0/1 0.0.0.0/0 )) end it "should handle addrandmask2cidr with IPv4, test 1" do result = Net::CIDR::addrandmask2cidr("195.149.50.61", "255.255.255.248") result.should eql("195.149.50.56/29") end it "should handle cidrlookup with IPv4, test 2" do list = ["192.68.1.0/24"] result = Net::CIDR::cidrlookup("192.68.0.12", list) result.should eql(false) end end