Debian Codegraph @

t/45regex.t

raw
1 #########################
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 13;
7
8 use XML::LibXML;
9
10 {
11 my $regex = '[0-9]{5}(-[0-9]{4})?';
12 my $re = XML::LibXML::RegExp->new($regex);
13
14 # TEST
15 ok( $re, 'Regex object was initted.');
16 # TEST
17 ok( ! $re->matches('00'), 'Does not match 00' );
18 # TEST
19 ok( ! $re->matches('00-'), 'Does not match 00-' );
20 # TEST
21 ok( $re->matches('12345'), 'Matches 12345' );
22 # TEST
23 ok( !$re->matches('123456'), 'Does not match 123456' );
24
25 # TEST
26 ok( $re->matches('12345-1234'), 'Matches 12345-1234');
27 # TEST
28 ok( ! $re->matches(' 12345-1234'), 'Does not match leading space');
29 # TEST
30 ok( ! $re->matches(' 12345-12345'), 'Leading space No. 2' );
31 # TEST
32 ok( ! $re->matches('12345-1234 '), 'Trailing space' );
33
34 # TEST
35 ok( $re->isDeterministic, 'Regex is deterministic' );
36 }
37
38 {
39 my $nondet_regex = '(bc)|(bd)';
40 my $nondet_re = XML::LibXML::RegExp->new($nondet_regex);
41
42 # TEST
43 ok( $nondet_re, 'Non deterministic re was initted' );
44 # TEST
45 ok( ! $nondet_re->isDeterministic, 'It is not deterministic' );
46 }
47
48 {
49 my $bad_regex = '[0-9]{5}(-[0-9]{4}?';
50 eval { XML::LibXML::RegExp->new($bad_regex); };
51 # TEST
52 ok( $@, 'An exception was thrown on bad regex' );
53 }