| 1 | #!/usr/bin/perl |
| 2 | |
| 3 | use strictscip-perl cpan Regexp-Common 2024080801 strict/; |
| 4 | use warningsscip-perl cpan Regexp-Common 2024080801 warnings/; |
| 5 | no warnings 'syntax'; |
| 6 | |
| 7 | use Regexp::Commonscip-perl cpan Regexp-Common 2024080801 Regexp/Common/; |
| 8 | |
| 9 | my $count = 0; |
| 10 | my $PAT; |
| 11 | |
| 12 | END {printscip-perl cpan Regexp-Common 2024080801 main/print(). "1..$count\n"} |
| 13 | |
| 14 | sub tryscip-perl cpan Regexp-Common 2024080801 main/try(). { |
| 15 | $PAT = shiftscip-perl cpan Regexp-Common 2024080801 main/shift().; |
| 16 | my $name = shiftscip-perl cpan Regexp-Common 2024080801 main/shift().; |
| 17 | printscip-perl cpan Regexp-Common 2024080801 main/print(). "# $name\n"; |
| 18 | } |
| 19 | |
| 20 | sub passscip-perl cpan Regexp-Common 2024080801 main/pass(). { |
| 21 | my $address = shiftscip-perl cpan Regexp-Common 2024080801 main/shift().; |
| 22 | my $r = $address =~ /^$PAT/ && $address eq $&scip-perl cpan Regexp-Common 2024080801 main/`$&`.; |
| 23 | printfscip-perl cpan Regexp-Common 2024080801 main/printf(). "%s %d # Matching %s\n", $r ? "ok" : "not ok", ++ $count, $address; |
| 24 | } |
| 25 | |
| 26 | sub failscip-perl cpan Regexp-Common 2024080801 main/fail(). { |
| 27 | my $address = shiftscip-perl cpan Regexp-Common 2024080801 main/shift().; |
| 28 | my $r = $address !~ /^$PAT/ || $address ne $&scip-perl cpan Regexp-Common 2024080801 main/`$&`.; |
| 29 | printfscip-perl cpan Regexp-Common 2024080801 main/printf(). "%s %d # Failing %s\n", $r ? "ok" : "not ok", ++ $count, $address; |
| 30 | } |
| 31 | |
| 32 | sub matchscip-perl cpan Regexp-Common 2024080801 main/match(). { |
| 33 | my $address = $_scip-perl cpan Regexp-Common 2024080801 main/`@_`. [0]; |
| 34 | my @matches = @_scip-perl cpan Regexp-Common 2024080801 main/`@_`.; |
| 35 | |
| 36 | my $r = $address =~ /^$PAT/ && $address eq $&scip-perl cpan Regexp-Common 2024080801 main/`$&`.; |
| 37 | printfscip-perl cpan Regexp-Common 2024080801 main/printf(). "%s %d # Matching %s\n", $r ? "ok" : "not ok", ++ $count, $address; |
| 38 | |
| 39 | if (!$r) { |
| 40 | for my $i (0 .. @matches) { |
| 41 | printfscip-perl cpan Regexp-Common 2024080801 main/printf(). "not ok %d # SKIP\n" => ++ $count; |
| 42 | } |
| 43 | return; |
| 44 | } |
| 45 | |
| 46 | # |
| 47 | # Correct number of matches? |
| 48 | # |
| 49 | printfscip-perl cpan Regexp-Common 2024080801 main/printf(). "%s %d # Number of matches\n" => |
| 50 | @matches == @-scip-perl cpan Regexp-Common 2024080801 main/`@-`. - 1 ? "ok" : "not ok", ++ $count; |
| 51 | |
| 52 | for (my $i = 0; $i < @matches; $i ++) { |
| 53 | no strict 'refs'; |
| 54 | my $matched = ${$i + 1}; |
| 55 | printfscip-perl cpan Regexp-Common 2024080801 main/printf(). "%s %d # \$%d eq '%s'\n" => |
| 56 | $matched eq $matches [$i] ? "ok" : "not ok", |
| 57 | ++ $count, $i + 1, $matches [$i]; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | |
| 62 | |
| 63 | try $RE {net} {IPv6} => '$RE {net} {IPv6}'; |
| 64 | |
| 65 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; |
| 66 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001:db8:85a3:0:0:8a2e:370:7334"; # Leading 0's removed |
| 67 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001:DB8:85A3:0:0:8A2E:370:7334"; # Upper case allowed |
| 68 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001:Db8:85A3:0:0:8a2E:370:7334"; # Mixed case allowed |
| 69 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001:db8:85a3::8a2e:370:7334"; # Contractions |
| 70 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001:db8::8a2e:370:7334"; |
| 71 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001::8a2e:370:7334"; |
| 72 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "::8a2e:370:7334"; |
| 73 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "::370:7334"; |
| 74 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "::7334"; |
| 75 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "::"; |
| 76 | |
| 77 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:0db8:85a3:0000:0000:8a2e:0370:7334:1234"; # Too many parts |
| 78 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:0db8:85a3:0000:0000:8a2e:0370"; # Not enough parts |
| 79 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "20013:db8:85a3:0:0:8a2e:370:7334"; # Part too long |
| 80 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:0db8:85a3:0000:0000:8a2e:0370:7334:"; # Trailing separator |
| 81 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). ":2001:0db8:85a3:0000:0000:8a2e:0370:7334"; # Leading separator |
| 82 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:db8:85a3:0::8a2e:370:7334"; # Only one unit removed |
| 83 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001::8a2e:370::7334"; # Two contractions |
| 84 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:::8a2e:370:7334"; # Three separators |
| 85 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001.db8.85a3.0.0.8a2e.370.7334"; # Wrong separator |
| 86 | |
| 87 | try $RE {net} {IPv6} {-style => "hex"} => '$RE {net} {IPv6} {-style => "hex"}'; |
| 88 | |
| 89 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001:db8:85a3:0:0:8a2e:370:7334"; # Lower case allowed |
| 90 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:DB8:85A3:0:0:8A2E:370:7334"; # Upper case not allowed |
| 91 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:Db8:85A3:0:0:8a2E:370:7334"; # Mixed case not allowed |
| 92 | |
| 93 | try $RE {net} {IPv6} {-style => "HEX"} => '$RE {net} {IPv6} {-style => "HEX"}'; |
| 94 | |
| 95 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:db8:85a3:0:0:8a2e:370:7334"; # Lower case allowed |
| 96 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001:DB8:85A3:0:0:8A2E:370:7334"; # Upper case not allowed |
| 97 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:Db8:85A3:0:0:8a2E:370:7334"; # Mixed case not allowed |
| 98 | |
| 99 | try $RE {net} {IPv6} {-sep => "[.]"} => '$RE {net} {IPv6} {-sep => "[.]"}'; |
| 100 | |
| 101 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001.db8.85a3.0.0.8a2e.370.7334"; # Lower case allowed |
| 102 | passscip-perl cpan Regexp-Common 2024080801 main/pass(). "2001.DB8.85A3.0.0.8A2E.370.7334"; # Upper case allowed |
| 103 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:db8:85a3:0:0:8a2e:370:7334"; # Fail on default sep |
| 104 | |
| 105 | |
| 106 | try $RE {net} {IPv6} {-keep} => '$RE {net} {IPv6} {-keep}'; |
| 107 | |
| 108 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "2001:0db8:85a3:0000:0000:8a2e:0370:7334" => |
| 109 | "2001", "0db8", "85a3", "0000", "0000", "8a2e", "0370", "7334"; |
| 110 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "2001:0db8:85a3:0:0:8a2e:0370:7334" => |
| 111 | "2001", "0db8", "85a3", "0", "0", "8a2e", "0370", "7334"; |
| 112 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "2001:db8:85a3:0:0:8a2e:370:7334" => |
| 113 | "2001", "db8", "85a3", "0", "0", "8a2e", "370", "7334"; |
| 114 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "2001:db8:85a3::8a2e:370:7334" => |
| 115 | "2001", "db8", "85a3", "", "", "8a2e", "370", "7334"; |
| 116 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "2001:db8::8a2e:370:7334" => |
| 117 | "2001", "db8", "", "", "", "8a2e", "370", "7334"; |
| 118 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "2001::8a2e:370:7334" => |
| 119 | "2001", "", "", "", "", "8a2e", "370", "7334"; |
| 120 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "::8a2e:370:7334" => |
| 121 | "", "", "", "", "", "8a2e", "370", "7334"; |
| 122 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "::370:7334" => |
| 123 | "", "", "", "", "", "", "370", "7334"; |
| 124 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "::7334" => |
| 125 | "", "", "", "", "", "", "", "7334"; |
| 126 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "::" => |
| 127 | "", "", "", "", "", "", "", ""; |
| 128 | |
| 129 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:0db8:85a3:0000:0000:8a2e:0370:7334:1234"; # Too many parts |
| 130 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:0db8:85a3:0000:0000:8a2e:0370"; # Not enough parts |
| 131 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "20013:db8:85a3:0:0:8a2e:370:7334"; # Part too long |
| 132 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:0db8:85a3:0000:0000:8a2e:0370:7334:"; # Trailing separator |
| 133 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). ":2001:0db8:85a3:0000:0000:8a2e:0370:7334"; # Leading separator |
| 134 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:db8:85a3:0::8a2e:370:7334"; # Only one unit removed |
| 135 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001::8a2e:370::7334"; # Two contractions |
| 136 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001:::8a2e:370:7334"; # Three separators |
| 137 | failscip-perl cpan Regexp-Common 2024080801 main/fail(). "2001.db8.85a3.0.0.8a2e.370.7334"; # Wrong separator |
| 138 | |
| 139 | |
| 140 | try $RE {net} {IPv6} {-style => 'HEX'} {-sep => '[.]'} {-keep} => |
| 141 | q [$RE {net} {IPv6} {-style => 'HEX'} {-sep => '[.]'} {-keep}]; |
| 142 | |
| 143 | matchscip-perl cpan Regexp-Common 2024080801 main/match(). "2001.DB8.85A3..8A2E.370.7334" => |
| 144 | "2001", "DB8", "85A3", "", "", "8A2E", "370", "7334"; |
| 145 | |
| 146 | __END__ |