This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
perldelta for more switch changes
[perl5.git] / cpan / experimental / t / basic.t
1 #! perl
2
3 use Test::More 0.89;
4
5 local $SIG{__WARN__} = sub { fail("Got unexpected warning"); diag($_[0]) };
6
7 if ($] >= 5.010000) {
8         is (eval <<'END', 1, 'state compiles') or diag $@;
9         use experimental 'state';
10         state $foo = 1;
11         is($foo, 1, '$foo is 1');
12         1;
13 END
14 }
15 else {
16         fail("No experimental features available on perl $]");
17 }
18
19 if ($] >= 5.010001) {
20         is (eval <<'END', 1, 'switch compiles') or diag $@;
21         use experimental 'switch';
22         sub bar { 1 };
23         given(1) {
24                 whereso (\&bar) {
25                         pass("bar matches 1");
26                 }
27                 fail("bar matches 1");
28         }
29         1;
30 END
31 }
32
33 if ($] >= 5.010001) {
34         is (eval <<'END', 1, 'smartmatch compiles') or diag $@;
35         use experimental 'smartmatch';
36         { package Bar; use overload "~~" => sub { 1 }; }
37         is(1 ~~ bless({}, "Bar"), 1, "is 1");
38         1;
39 END
40 }
41
42 if ($] >= 5.018) {
43         is (eval <<'END', 1, 'lexical subs compiles') or diag $@;
44         use experimental 'lexical_subs';
45         my sub foo { 1 };
46         is(foo(), 1, "foo is 1");
47         1;
48 END
49 }
50
51 if ($] >= 5.021005) {
52         is (eval <<'END', 1, 'ref aliasing compiles') or diag $@;
53         use experimental 'refaliasing';
54         \@a = \@b;
55         is(\@a, \@b, '@a and @b are the same after \@a=\@b');
56         1;
57 END
58 }
59
60 done_testing;
61