File: Regexp-IPv6.t

package info (click to toggle)
libnet-ipv6addr-perl 1.02-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 328 kB
  • sloc: perl: 598; makefile: 2
file content (271 lines) | stat: -rw-r--r-- 5,216 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# These tests of IPv6 addresses were poached from Regexp::IPv6.

use Test::More;

#use Regexp::IPv6 qw($IPv6_re);

use Net::IPv6Addr 'ipv6_chkip';

# True or false depending on whether this test is supposed to match or not.

my $good;

#my $re = qr/^$IPv6_re$/;
#my $nare = qr/($IPv6_re)/;

while (<DATA>) {
    chomp;
    s/\s*#.*//;
    next if m/^$/;
    if (/^GOOD/) {
	$good = 1;
	next;
    }
    if (/^TODOGOOD/) {
	$todogood = 1;
	next;
    }
    if (/^BAD/) {
	$good = 0;
	next;
    }

    if ($good) {
	if ($todogood) {
	    TODO: {
		local $TODO = 'compressed + ipv4';
		ok (ipv6_chkip ($_), "good $_");
	    };
	}
	else {
	    ok (ipv6_chkip ($_), "good $_");
	}
    }
    else {
	ok (! ipv6_chkip ($_), "bad $_");
    }
}

done_testing ();
exit;

# most of the samples below were taken from the validate_ipv6.rb
# script by Christoph Petschnig (Michael Erickson pointed me there).

# some samples are from the Wikipedia.

# some samples contributed by Michael G. Schwern


__DATA__

GOOD:
::127.0.0.1
::1
2001:0db8:85a3:0000:0000:8a2e:0370:7334
2001:db8:85a3:0:0:8a2e:370:7334
2001:db8:85a3::8a2e:370:7334
2001:0db8:0000:0000:0000:0000:1428:57ab
2001:0db8:0000:0000:0000::1428:57ab
2001:0db8:0:0:0:0:1428:57ab
2001:0db8:0:0::1428:57ab
2001:0db8::1428:57ab
2001:db8::1428:57ab
::ffff:12.34.56.78
::ffff:0c22:384e
2001:0db8:1234:ffff:ffff:ffff:ffff:ffff
2001:0db8:1234:0000:0000:0000:0000:0000
2001:db8:a::123
fc00::
::ffff:0:0
2001::
2001:10::
2001:db8::
2001:0000:1234:0000:0000:C1C0:ABCD:0876
3ffe:0b00:0000:0000:0001:0000:0000:000a
FF02:0000:0000:0000:0000:0000:0000:0001
0000:0000:0000:0000:0000:0000:0000:0001
0000:0000:0000:0000:0000:0000:0000:0000
::ffff:192.168.1.26
2::10
ff02::1
fe80::
2002::
2001:db8::
2001:0db8:1234::
::ffff:0:0
::1
::ffff:192.168.1.1
1:2:3:4:5:6:7:8
1:2:3:4:5:6::8
1:2:3:4:5::8
1:2:3:4::8
1:2:3::8
1:2::8
1::8
1::2:3:4:5:6:7
1::2:3:4:5:6
1::2:3:4:5
1::2:3:4
1::2:3
1::8
::2:3:4:5:6:7:8
::2:3:4:5:6:7
::2:3:4:5:6
::2:3:4:5
::2:3:4
::2:3
::8
1:2:3:4:5:6::
1:2:3:4:5::
1:2:3:4::
1:2:3::
1:2::
1::
1:2:3:4:5::7:8
2001:0000:1234:0000:0000:C1C0:ABCD:0876
1:2:3:4::7:8
1:2:3::7:8
1:2::7:8
1::7:8
fe80::217:f2ff:fe07:ed62
2001:DB8:0:0:8:800:200C:417A # unicast, full
FF01:0:0:0:0:0:0:101 # multicast, full
0:0:0:0:0:0:0:1 # loopback, full
0:0:0:0:0:0:0:0 # unspecified, full
2001:DB8::8:800:200C:417A # unicast, compressed
FF01::101 # multicast, compressed
::1 # loopback, compressed, non-routable
0:0:0:0:0:0:13.1.68.3 # IPv4-compatible IPv6 address, full, deprecated
0:0:0:0:0:FFFF:129.144.52.38 # IPv4-mapped IPv6 address, full
::13.1.68.3 # IPv4-compatible IPv6 address, compressed, deprecated
::FFFF:129.144.52.38 # IPv4-mapped IPv6 address, compressed
fe80:0000:0000:0000:0204:61ff:fe9d:f156
fe80:0:0:0:204:61ff:fe9d:f156
fe80::204:61ff:fe9d:f156
fe80::
fe80::1
0000:0000:0000:0000:0000:0000:0000:0001
::1
::ffff:192.0.2.128
::ffff:c000:280
# Double colon is a valid address, so this was moved from BAD: to here.
# See also
# https://metacpan.org/pod/release/SALVA/Regexp-IPv6-0.03/lib/Regexp/IPv6.pm#DESCRIPTION
# https://rt.cpan.org/Public/Bug/Display.html?id=62125
::

# These are valid addresses, but the original Tony Monroe
# Net::IPv6Addr did not recognise them. From version 0.92, these are
# accepted by the module, so the disqualifier is no longer here.

1:2:3:4:5:6:1.2.3.4
1:2:3:4:5::1.2.3.4
1:2:3:4::1.2.3.4
1:2:3::1.2.3.4
1:2::1.2.3.4
1::1.2.3.4
1:2:3:4::5:1.2.3.4
1:2:3::5:1.2.3.4
1:2::5:1.2.3.4
1::5:1.2.3.4
1::5:11.22.33.44
fe80::217:f2ff:254.7.237.98
fe80:0:0:0:204:61ff:254.157.241.86
fe80::204:61ff:254.157.241.86

BAD:
127.0.0.1
:
2001:0000:1234:0000:0000:C1C0:ABCD:0876 0
2001:0000:1234: 0000:0000:C1C0:ABCD:0876
02001:0000:1234:0000:0000:C1C0:ABCD:0876 # extra 0 not allowed!
2001:0000:1234:0000:00001:C1C0:ABCD:0876 # extra 0 not allowed!
3ffe:0b00:0000:0001:0000:0000:000a
FF02:0000:0000:0000:0000:0000:0000:0000:0001
3ffe:b00::1::a
::1111:2222:3333:4444:5555:6666::
1:2:3::4:5::7:8
12345::6:7:8
1::5:400.2.3.4
1::5:260.2.3.4
1::5:256.2.3.4
1::5:1.256.3.4
1::5:1.2.256.4
1::5:1.2.3.256
1::5:300.2.3.4
1::5:1.300.3.4
1::5:1.2.300.4
1::5:1.2.3.300
1::5:900.2.3.4
1::5:1.900.3.4
1::5:1.2.900.4
1::5:1.2.3.900
1::5:300.300.300.300
1::5:3000.30.30.30
1::400.2.3.4
1::260.2.3.4
1::256.2.3.4
1::1.256.3.4
1::1.2.256.4
1::1.2.3.256
1::300.2.3.4
1::1.300.3.4
1::1.2.300.4
1::1.2.3.300
1::900.2.3.4
1::1.900.3.4
1::1.2.900.4
1::1.2.3.900
1::300.300.300.300
1::3000.30.30.30
::400.2.3.4
::260.2.3.4
::256.2.3.4
::1.256.3.4
::1.2.256.4
::1.2.3.256
::300.2.3.4
::1.300.3.4
::1.2.300.4
::1.2.3.300
::900.2.3.4
::1.900.3.4
::1.2.900.4
::1.2.3.900
::300.300.300.300
::3000.30.30.30
2001:DB8:0:0:8:800:200C:417A:221 # unicast, full
FF01::101::2 # multicast, compressed
1111:2222:3333:4444::5555:
1111:2222:3333::5555:
1111:2222::5555:
1111::5555:
::5555:
:::
1111:
:
:1111:2222:3333:4444::5555
:1111:2222:3333::5555
:1111:2222::5555
:1111::5555
:::5555
:::
1.2.3.4:1111:2222:3333:4444::5555
1.2.3.4:1111:2222:3333::5555
1.2.3.4:1111:2222::5555
1.2.3.4:1111::5555
1.2.3.4::5555
1.2.3.4::
123
ldkfj
2001::FFD3::57ab
2001:db8:85a3::8a2e:37023:7334
2001:db8:85a3::8a2e:370k:7334
1:2:3:4:5:6:7:8:9
1::2::3
1:::3:4:5
1:2:3::4:5:6:7:8:9
::ffff:2.3.4
::ffff:257.1.2.3
1.2.3.4