This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
eviscerate smartmatch
[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                 when (\&bar) {
25                         pass("bar matches 1");
26                 }
27                 default {
28                         fail("bar matches 1");
29                 }
30         }
31         1;
32 END
33 }
34
35 if ($] >= 5.010001) {
36         is (eval <<'END', 1, 'smartmatch compiles') or diag $@;
37         use experimental 'smartmatch';
38         { package Bar; use overload "~~" => sub { 1 }; }
39         is(1 ~~ bless({}, "Bar"), 1, "is 1");
40         1;
41 END
42 }
43
44 if ($] >= 5.018) {
45         is (eval <<'END', 1, 'lexical subs compiles') or diag $@;
46         use experimental 'lexical_subs';
47         my sub foo { 1 };
48         is(foo(), 1, "foo is 1");
49         1;
50 END
51 }
52
53 if ($] >= 5.021005) {
54         is (eval <<'END', 1, 'ref aliasing compiles') or diag $@;
55         use experimental 'refaliasing';
56         \@a = \@b;
57         is(\@a, \@b, '@a and @b are the same after \@a=\@b');
58         1;
59 END
60 }
61
62 done_testing;
63