This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
re/reg_mesg.t: Add tests for suppressing warnings
[perl5.git] / t / re / regex_sets.t
1 #!./perl
2
3 # This tests (?[...]).  XXX These are just basic tests, as full ones would be
4 # best done with an infrastructure change to allow getting out the inversion
5 # list of the constructed set and then comparing it character by character
6 # with the expected result.
7
8 use strict;
9 use warnings;
10
11 $| = 1;
12
13 BEGIN {
14     chdir 't' if -d 't';
15     @INC = ('../lib','.');
16     require './test.pl';
17 }
18
19 use utf8;
20 no warnings 'experimental::regex_sets';
21
22 like("a", qr/(?[ [a]      # This is a comment
23                     ])/, 'Can ignore a comment');
24 like("a", qr/(?[ [a]      # [[:notaclass:]]
25                     ])/, 'A comment isn\'t parsed');
26 unlike("\x85", qr/(?[ \t\85 ])/, 'NEL is white space');
27 unlike("\x85", qr/(?[ [\t\85] ])/, '... including within nested []');
28 like("\x85", qr/(?[ \t + \\85 ])/, 'can escape NEL to match');
29 like("\x85", qr/(?[ [\\85] ])/, '... including within nested []');
30 like("\t", qr/(?[ \t + \\85 ])/, 'can do basic union');
31 like("\cK", qr/(?[ \s ])/, '\s matches \cK');
32 unlike("\cK", qr/(?[ \s - \cK ])/, 'can do basic subtraction');
33 like(" ", qr/(?[ \s - \cK ])/, 'can do basic subtraction');
34 like(":", qr/(?[ [:] ])/, '[:] is not a posix class');
35 unlike("\t", qr/(?[ ! \t ])/, 'can do basic complement');
36 like("\t", qr/(?[ ! [ ^ \t ] ])/, 'can do basic complement');
37 unlike("\r", qr/(?[ \t ])/, '\r doesn\'t match \t ');
38 like("\r", qr/(?[ ! \t ])/, 'can do basic complement');
39 like("0", qr/(?[ [:word:] & [:digit:] ])/, 'can do basic intersection');
40 unlike("A", qr/(?[ [:word:] & [:digit:] ])/, 'can do basic intersection');
41 like("0", qr/(?[[:word:]&[:digit:]])/, 'spaces around internal [] aren\'t required');
42
43 like("a", qr/(?[ [a] | [b] ])/, '| means union');
44 like("b", qr/(?[ [a] | [b] ])/, '| means union');
45 unlike("c", qr/(?[ [a] | [b] ])/, '| means union');
46
47 like("a", qr/(?[ [ab] ^ [bc] ])/, 'basic symmetric difference works');
48 unlike("b", qr/(?[ [ab] ^ [bc] ])/, 'basic symmetric difference works');
49 like("c", qr/(?[ [ab] ^ [bc] ])/, 'basic symmetric difference works');
50
51 like("2", qr/(?[ ( ( \pN & ( [a] + [2] ) ) ) ])/, 'Nesting parens and grouping');
52 unlike("a", qr/(?[ ( ( \pN & ( [a] + [2] ) ) ) ])/, 'Nesting parens and grouping');
53
54
55
56 done_testing();
57
58 1;