File: 60alias.t

package info (click to toggle)
libkavorka-perl 0.039-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 696 kB
  • sloc: perl: 2,850; makefile: 6; sh: 6
file content (120 lines) | stat: -rw-r--r-- 1,627 bytes parent folder | download
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
=pod

=encoding utf-8

=head1 PURPOSE

Test the C<alias> trait.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT AND LICENCE

This software is copyright (c) 2013-2014, 2017 by Toby Inkster.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut

use strict;
use warnings;
use Test::More;
use Test::Fatal;

BEGIN {
	$INC{'Devel/Cover.pm'} and plan skip_all => "broken with Devel::Cover";
};

{
	package Example;
	use Kavorka;
	
	fun foo ($x is alias) {
		++$x;
	}
	
	fun bar (Int $x is alias) {
		++$x;
	}
}

my $x = 1;

is(Example::foo($x), 2);
is(Example::bar($x), 3);
is(Example::foo($x), 4);
is(Example::bar($x), 5);
is($x, 5);

{
	package Example2;
	use Kavorka;
	
	fun foo ($_ is alias) {
		++ $_;
	}
	
	fun bar (Int $_ is alias) {
		++ $_;
	}
}

my $y = 1;

is(Example2::foo($y), 2);
is(Example2::bar($y), 3);
is(Example2::foo($y), 4);
is(Example2::bar($y), 5);
is($y, 5);

{
	package Example3;
	use Kavorka;
	
	fun foo (:$z is alias) {
		++$z;
	}
	
	fun bar (Int :$z is alias) {
		++$z;
	}
}

my $z = 1;

is(Example3::foo(z => $z), 2);
is(Example3::bar(z => $z), 3);
is(Example3::foo(z => $z), 4);
is(Example3::bar(z => $z), 5);
is($z, 5);

{
	package Example4;
	use Kavorka;
	
	fun foo (:\%foo)
	{
		$foo{yyy} = 42;
		return $foo{xxx};
	}

	fun bar (\@bar)
	{
		$bar[1] = 42;
		return $bar[0];
	}
}

my $foo = { xxx => 666 };
is(Example4::foo(foo => $foo), 666);
is_deeply($foo, { xxx => 666, yyy => 42 });

my $bar = [ 666, 0 ];
is(Example4::bar($bar), 666);
is_deeply($bar, [ 666, 42 ]);

done_testing;