This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
update experimental to 0.024 from CPAN
[perl5.git] / cpan / experimental / t / basic.t
1 #! perl
2
3 use strict;
4 use warnings;
5
6 use Test::More 0.89;
7
8 plan skip_all => 'This module is a no-op on perls earlier than 5.010' if "$]" < 5.010000;
9
10 local $SIG{__WARN__} = sub { fail("Got unexpected warning"); diag($_[0]) };
11
12 if ($] >= 5.010000) {
13         is (eval <<'END', 1, 'state compiles') or diag $@;
14         use experimental 'state';
15         state $foo = 1;
16         is($foo, 1, '$foo is 1');
17         1;
18 END
19 }
20
21 if ($] >= 5.010001) {
22         is (eval <<'END', 1, 'switch compiles') or diag $@;
23         use experimental 'switch';
24         sub bar { 1 };
25         given(1) {
26                 when (\&bar) {
27                         pass("bar matches 1");
28                 }
29                 default {
30                         fail("bar matches 1");
31                 }
32         }
33         1;
34 END
35 }
36
37 if ($] >= 5.010001) {
38         is (eval <<'END', 1, 'smartmatch compiles') or diag $@;
39         use experimental 'smartmatch';
40         sub baz { 1 };
41         is(1 ~~ \&baz, 1, "is 1");
42         1;
43 END
44 }
45
46 if ($] >= 5.018) {
47         is (eval <<'END', 1, 'lexical subs compiles') or diag $@;
48         use experimental 'lexical_subs';
49         my sub foo { 1 };
50         is(foo(), 1, "foo is 1");
51         1;
52 END
53 }
54
55 if ($] >= 5.026000) {
56         is (eval <<'END', 1, 'declared refs compiles') or diag $@;
57         use experimental 'declared_refs';
58         my @b;
59         my \@a = \@b;
60         is(\@a, \@b, '@a and @b are the same after \@a=\@b');
61         1;
62 END
63 }
64 elsif ($] >= 5.021005) {
65         is (eval <<'END', 1, 'ref aliasing compiles') or diag $@;
66         use experimental 'refaliasing';
67         my (@a, @b);
68         \@a = \@b;
69         is(\@a, \@b, '@a and @b are the same after \@a=\@b');
70         1;
71 END
72 }
73
74 done_testing;
75