Functional Weave
Code in Rust

net.port-list@1.0.0

vectors.json

2,753 bytes · view raw

[
  {"name": "a single port", "args": ["22"], "expect": [22]},
  {"name": "a list keeps the order given, not sorted", "args": ["443,22,80"], "expect": [443, 22, 80]},
  {"name": "an inclusive range", "args": ["8000-8003"], "expect": [8000, 8001, 8002, 8003]},
  {"name": "ports and ranges mixed", "args": ["22,80,8000-8002"], "expect": [22, 80, 8000, 8001, 8002]},
  {"name": "spaces and tabs around items are allowed", "args": [" 22 ,\t80\t, 8000-8001 "], "expect": [22, 80, 8000, 8001]},
  {"name": "duplicates are dropped, keeping the first", "args": ["80,22,80,22"], "expect": [80, 22]},
  {"name": "a port inside an earlier range is not repeated", "args": ["20-23,22,19"], "expect": [20, 21, 22, 23, 19]},
  {"name": "a one-port range", "args": ["443-443"], "expect": [443]},
  {"name": "the extremes 1 and 65535", "args": ["65535,1"], "expect": [65535, 1]},
  {"name": "empty text", "args": [""], "expectError": "port list is empty"},
  {"name": "only spaces", "args": ["   "], "expectError": "port list is empty"},
  {"name": "an empty item between commas", "args": ["22,,80"], "expectError": "empty item in port list"},
  {"name": "a trailing comma", "args": ["22,80,"], "expectError": "empty item in port list"},
  {"name": "a word is not a port", "args": ["22,ssh"], "expectError": "invalid port \"ssh\""},
  {"name": "a leading plus is refused", "args": ["+22"], "expectError": "invalid port \"+22\""},
  {"name": "a leading zero is refused", "args": ["080"], "expectError": "invalid port \"080\""},
  {"name": "a trailing newline is not trimmed", "args": ["22,80\n"], "expectError": "invalid port \"80\n\""},
  {"name": "Arabic-Indic digits are not port numbers", "args": ["٨٠"], "expectError": "invalid port \"٨٠\""},
  {"name": "0 is not a port", "args": ["0"], "expectError": "port \"0\" is out of range 1-65535"},
  {"name": "65536 is not a port", "args": ["65536"], "expectError": "port \"65536\" is out of range 1-65535"},
  {"name": "six digits is out of range", "args": ["100000"], "expectError": "port \"100000\" is out of range 1-65535"},
  {"name": "a range that runs backwards", "args": ["8010-8000"], "expectError": "port range \"8010-8000\" runs backwards"},
  {"name": "a range with a missing end", "args": ["8000-"], "expectError": "invalid port range \"8000-\""},
  {"name": "a negative port reads as a malformed range", "args": ["-22"], "expectError": "invalid port range \"-22\""},
  {"name": "a range with an out-of-range end", "args": ["65000-70000"], "expectError": "port \"70000\" is out of range 1-65535"},
  {"name": "a three-part range", "args": ["1-2-3"], "expectError": "invalid port range \"1-2-3\""},
  {"name": "a number instead of text is refused", "args": [22], "expectError": "text must be a string"}
]