This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Convert t/re/reg_email.t to test.pl, strict and warnings.
[perl5.git] / t / re / reg_email.t
CommitLineData
c7056ede 1#!./perl -w
e7707071
YO
2#
3# Tests to make sure the regexp engine doesn't run into limits too soon.
4#
5
6BEGIN {
7 chdir 't' if -d 't';
8 @INC = '../lib';
c7056ede 9 require './test.pl';
e7707071
YO
10}
11
c7056ede 12use strict;
e7707071
YO
13
14my $email = qr {
15 (?(DEFINE)
16 (?<address> (?&mailbox) | (?&group))
17 (?<mailbox> (?&name_addr) | (?&addr_spec))
18 (?<name_addr> (?&display_name)? (?&angle_addr))
19 (?<angle_addr> (?&CFWS)? < (?&addr_spec) > (?&CFWS)?)
20 (?<group> (?&display_name) : (?:(?&mailbox_list) | (?&CFWS))? ;
21 (?&CFWS)?)
22 (?<display_name> (?&phrase))
23 (?<mailbox_list> (?&mailbox) (?: , (?&mailbox))*)
24
25 (?<addr_spec> (?&local_part) \@ (?&domain))
26 (?<local_part> (?&dot_atom) | (?&quoted_string))
27 (?<domain> (?&dot_atom) | (?&domain_literal))
28 (?<domain_literal> (?&CFWS)? \[ (?: (?&FWS)? (?&dcontent))* (?&FWS)?
29 \] (?&CFWS)?)
30 (?<dcontent> (?&dtext) | (?&quoted_pair))
31 (?<dtext> (?&NO_WS_CTL) | [\x21-\x5a\x5e-\x7e])
32
33 (?<atext> (?&ALPHA) | (?&DIGIT) | [!#\$%&'*+-/=?^_`{|}~])
34 (?<atom> (?&CFWS)? (?&atext)+ (?&CFWS)?)
35 (?<dot_atom> (?&CFWS)? (?&dot_atom_text) (?&CFWS)?)
36 (?<dot_atom_text> (?&atext)+ (?: \. (?&atext)+)*)
37
38 (?<text> [\x01-\x09\x0b\x0c\x0e-\x7f])
39 (?<quoted_pair> \\ (?&text))
40
41 (?<qtext> (?&NO_WS_CTL) | [\x21\x23-\x5b\x5d-\x7e])
42 (?<qcontent> (?&qtext) | (?&quoted_pair))
43 (?<quoted_string> (?&CFWS)? (?&DQUOTE) (?:(?&FWS)? (?&qcontent))*
44 (?&FWS)? (?&DQUOTE) (?&CFWS)?)
45
46 (?<word> (?&atom) | (?&quoted_string))
47 (?<phrase> (?&word)+)
48
49 # Folding white space
50 (?<FWS> (?: (?&WSP)* (?&CRLF))? (?&WSP)+)
51 (?<ctext> (?&NO_WS_CTL) | [\x21-\x27\x2a-\x5b\x5d-\x7e])
52 (?<ccontent> (?&ctext) | (?&quoted_pair) | (?&comment))
53 (?<comment> \( (?: (?&FWS)? (?&ccontent))* (?&FWS)? \) )
54 (?<CFWS> (?: (?&FWS)? (?&comment))*
55 (?: (?:(?&FWS)? (?&comment)) | (?&FWS)))
56
57 # No whitespace control
58 (?<NO_WS_CTL> [\x01-\x08\x0b\x0c\x0e-\x1f\x7f])
59
60 (?<ALPHA> [A-Za-z])
61 (?<DIGIT> [0-9])
62 (?<CRLF> \x0d \x0a)
63 (?<DQUOTE> ")
64 (?<WSP> [\x20\x09])
65 )
66
67 (?&address)
68}x;
69
e3faa678
NC
70run_tests() unless caller;
71
72sub run_tests {
a0e63aba
RGS
73 # rewinding DATA is necessary with PERLIO=stdio when this
74 # test is run from another thread
75 seek *DATA, 0, 0;
76 while (<DATA>) { last if /^__DATA__/ }
e3faa678
NC
77 while (<DATA>) {
78 chomp;
79 next if /^#/;
c7056ede 80 like($_, qr/^$email$/, $_);
e3faa678 81 }
c7056ede
NC
82
83 done_testing();
e7707071
YO
84}
85
c7056ede
NC
861; # Because reg_email_thr.t will (indirectly) require this script.
87
e7707071
YO
88#
89# Acme::MetaSyntactic ++
90#
91__DATA__
92Jeff_Tracy@thunderbirds.org
93"Lady Penelope"@thunderbirds.org
94"The\ Hood"@thunderbirds.org
95fred @ flintstones.net
96barney (rubble) @ flintstones.org
97bammbamm (bam! bam! (bam! bam! (bam!)) bam!) @ flintstones.org
98Michelangelo@[127.0.0.1]
99Donatello @ [127.0.0.1]
100Raphael (He as well) @ [127.0.0.1]
101"Leonardo" @ [127.0.0.1]
102Barbapapa <barbapapa @ barbapapa.net>
103"Barba Mama" <barbamama @ [127.0.0.1]>
104Barbalala (lalalalalalalala) <barbalala (Yes, her!) @ (barba) barbapapa.net>