xref: /openbsd-src/gnu/usr.bin/perl/t/re/reg_email.t (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1#!./perl -w
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';
9    require './test.pl';
10}
11
12use strict;
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
70run_tests() unless caller;
71
72sub run_tests {
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__/ }
77    while (<DATA>) {
78	chomp;
79	next if /^#/;
80	like($_, qr/^$email$/, $_);
81    }
82
83    done_testing();
84}
85
861; # Because reg_email_thr.t will (indirectly) require this script.
87
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>
105