Functional Weave
Code in Rust

net.cidr-hosts@1.0.0

vectors.json

2,427 bytes · view raw

[
  { "name": "a /30 has two hosts, network and broadcast left out", "args": ["192.168.1.0/30", 16], "expect": ["192.168.1.1", "192.168.1.2"] },
  { "name": "a /29 has six", "args": ["10.0.0.8/29", 16], "expect": ["10.0.0.9", "10.0.0.10", "10.0.0.11", "10.0.0.12", "10.0.0.13", "10.0.0.14"] },
  { "name": "host bits in the block are dropped", "args": ["10.0.0.13/29", 6], "expect": ["10.0.0.9", "10.0.0.10", "10.0.0.11", "10.0.0.12", "10.0.0.13", "10.0.0.14"] },
  { "name": "a /31 point-to-point link: both addresses", "args": ["198.51.100.6/31", 2], "expect": ["198.51.100.6", "198.51.100.7"] },
  { "name": "a /32 is the address itself", "args": ["127.0.0.1/32", 1], "expect": ["127.0.0.1"] },
  { "name": "loopback /30 for a local sweep", "args": ["127.0.0.0/30", 4], "expect": ["127.0.0.1", "127.0.0.2"] },
  { "name": "crossing an octet boundary counts on through .255 to the next octet", "args": ["192.0.2.252/29", 8], "expect": ["192.0.2.249", "192.0.2.250", "192.0.2.251", "192.0.2.252", "192.0.2.253", "192.0.2.254"] },
  { "name": "a /28 crossing into the next third octet", "args": ["10.1.1.240/27", 30], "expect": ["10.1.1.225", "10.1.1.226", "10.1.1.227", "10.1.1.228", "10.1.1.229", "10.1.1.230", "10.1.1.231", "10.1.1.232", "10.1.1.233", "10.1.1.234", "10.1.1.235", "10.1.1.236", "10.1.1.237", "10.1.1.238", "10.1.1.239", "10.1.1.240", "10.1.1.241", "10.1.1.242", "10.1.1.243", "10.1.1.244", "10.1.1.245", "10.1.1.246", "10.1.1.247", "10.1.1.248", "10.1.1.249", "10.1.1.250", "10.1.1.251", "10.1.1.252", "10.1.1.253", "10.1.1.254"] },
  { "name": "exactly at the limit is allowed", "args": ["192.168.1.0/30", 2], "expect": ["192.168.1.1", "192.168.1.2"] },
  { "name": "one over the limit is refused", "args": ["192.168.1.0/29", 5], "expectError": "192.168.1.0/29 has 6 hosts, more than maxCount 5" },
  { "name": "a /8 is refused under a sweep-sized limit", "args": ["10.0.0.0/8", 1024], "expectError": "more than maxCount 1024" },
  { "name": "maxCount zero", "args": ["192.168.1.0/30", 0], "expectError": "maxCount must be a whole number of at least 1" },
  { "name": "maxCount fractional", "args": ["192.168.1.0/30", 2.5], "expectError": "maxCount must be a whole number of at least 1" },
  { "name": "an IPv6 block", "args": ["2001:db8::/126", 4], "expectError": "cidrInfo handles IPv4 blocks only" },
  { "name": "a malformed block", "args": ["192.168.1.0/", 4], "expectError": "is not a CIDR block" }
]