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