This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Merge CPAN version.pm tests into CORE.
[perl5.git] / lib / version / t / 04strict_lax.t
1 #! /usr/local/perl -w
2 # Before `make install' is performed this script should be runnable with
3 # `make test'. After `make install' it should work as `perl test.pl'
4
5 #########################
6
7 use Test::More qw/no_plan/;
8
9 # do strict lax tests in a sub to isolate a package to test importing
10 SKIP: {
11     skip 'No extended regexes Perl < 5.006', 172
12         if $] < 5.006_000;
13     strict_lax_tests();
14 }
15
16 sub strict_lax_tests {
17   package temp12345;
18   # copied from perl core test t/op/packagev.t
19   # format: STRING STRICT_OK LAX_OK
20   my $strict_lax_data = << 'CASE_DATA';
21 1.00            pass    pass
22 1.00001         pass    pass
23 0.123           pass    pass
24 12.345          pass    pass
25 42              pass    pass
26 0               pass    pass
27 0.0             pass    pass
28 v1.2.3          pass    pass
29 v1.2.3.4        pass    pass
30 v0.1.2          pass    pass
31 v0.0.0          pass    pass
32 01              fail    pass
33 01.0203         fail    pass
34 v01             fail    pass
35 v01.02.03       fail    pass
36 .1              fail    pass
37 .1.2            fail    pass
38 1.              fail    pass
39 1.a             fail    fail
40 1._             fail    fail
41 1.02_03         fail    pass
42 v1.2_3          fail    pass
43 v1.02_03        fail    pass
44 v1.2_3_4        fail    fail
45 v1.2_3.4        fail    fail
46 1.2_3.4         fail    fail
47 0_              fail    fail
48 1_              fail    fail
49 1_.             fail    fail
50 1.1_            fail    fail
51 1.02_03_04      fail    fail
52 1.2.3           fail    pass
53 v1.2            fail    pass
54 v0              fail    pass
55 v1              fail    pass
56 v.1.2.3         fail    fail
57 v               fail    fail
58 v1.2345.6       fail    pass
59 undef           fail    pass
60 1a              fail    fail
61 1.2a3           fail    fail
62 bar             fail    fail
63 _               fail    fail
64 CASE_DATA
65
66   require version;
67   version->import( qw/is_strict is_lax/ );
68   for my $case ( split qr/\n/, $strict_lax_data ) {
69     my ($v, $strict, $lax) = split qr/\t+/, $case;
70     main::ok( $strict eq 'pass' ? is_strict($v) : ! is_strict($v), "is_strict($v) [$strict]" );
71     main::ok( $strict eq 'pass' ? version::is_strict($v) : ! version::is_strict($v), "version::is_strict($v) [$strict]" );
72     main::ok( $lax eq 'pass' ? is_lax($v) : ! is_lax($v), "is_lax($v) [$lax]" );
73     main::ok( $lax eq 'pass' ? version::is_lax($v) : ! version::is_lax($v), "version::is_lax($v) [$lax]" );
74   }
75 }