summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/cpan/experimental/t/basic.t
blob: f39cc230ed366d0acf83dce43ebfbc8593eef0f7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#! perl

use strict;
use warnings;

use Test::More 0.89;

local $SIG{__WARN__} = sub { fail("Got unexpected warning"); diag($_[0]) };

if ($] >= 5.010000) {
	is (eval <<'END', 1, 'state compiles') or diag $@;
	use experimental 'state';
	state $foo = 1;
	is($foo, 1, '$foo is 1');
	1;
END
}

if ($] >= 5.010001) {
	if (eval '
		no warnings "experimental";
		use feature "switch";
		if(0) { when(3) {} }
		1;
	') {
		is (eval <<'END', 1, 'switch compiles') or diag $@;
		use experimental 'switch';
		sub bar { 1 };
		given(1) {
			when (\&bar) {
				pass("bar matches 1");
			}
			default {
				fail("bar matches 1");
			}
		}
		1;
END
	} else {
		is (eval <<'END', 1, 'switch compiles') or diag $@;
		use experimental 'switch';
		sub bar { 1 };
		given(1) {
			whereso (\&bar) {
				pass("bar matches 1");
			}
			fail("bar matches 1");
		}
		1;
END
	}
}

if ($] >= 5.010001) {
	is (eval <<'END', 1, 'smartmatch compiles') or diag $@;
	use experimental 'smartmatch';
	{ package Baz; use overload "~~" => sub { 1 }; }
	is(1 ~~ bless({}, "Baz"), 1, "is 1");
	1;
END
}

if ($] >= 5.018) {
	is (eval <<'END', 1, 'lexical subs compiles') or diag $@;
	use experimental 'lexical_subs';
	my sub foo { 1 };
	is(foo(), 1, "foo is 1");
	1;
END
}

if ($] >= 5.026000) {
	is (eval <<'END', 1, 'declared refs compiles') or diag $@;
	use experimental 'declared_refs';
	my @b;
	my \@a = \@b;
	is(\@a, \@b, '@a and @b are the same after \@a=\@b');
	1;
END
}
elsif ($] >= 5.021005) {
	is (eval <<'END', 1, 'ref aliasing compiles') or diag $@;
	use experimental 'refaliasing';
	my (@a, @b);
	\@a = \@b;
	is(\@a, \@b, '@a and @b are the same after \@a=\@b');
	1;
END
}

done_testing;