]> git.vpit.fr Git - perl/modules/with.git/blob - t/12-keywords.t
Importing with-0.01
[perl/modules/with.git] / t / 12-keywords.t
1 #!perl -T
2
3 package main;
4
5 use strict;
6 use warnings;
7
8 use Test::More 'no_plan';
9
10 sub with::Mock::right { pass $_[1] }
11 sub with::Mock::wrong { fail $_[1] }
12 sub with::Mock::test  { is_deeply $_[1], $_[2], $_[3] }
13
14 use with \bless {}, 'with::Mock';
15
16 my $c = 0;
17 ++$c for 1 .. 10;
18 test $c, 10, 'for';
19
20 $c = 0;
21 while ($c < 5) { ++$c; }
22 test $c, 5, 'while';
23
24 $c = undef;
25 test !defined($c), 1, 'undef, defined';
26
27 my @a = (1, 2);
28
29 my $x = pop @a;
30 my $y = shift @a;
31 push @a, $y;
32 unshift @a, $x;
33 test \@a, [ 2, 1 ], 'pop/shift/push/unshift';
34
35 @a = reverse @a;
36 test \@a, [ 1, 2 ], 'reverse';
37
38 open my $fh, '<', $0 or die "$!";
39 my $d = do { local $/; <$fh> };
40 $d =~ s/^(\S+).*/$1/s;
41 test $d, '#!perl', 'open/do/local';
42
43 @a = map { $_ + 1 } 0 .. 5;
44 test \@a, [ 1 .. 6 ], 'map';
45
46 @a = grep { $_ > 2 } 0 .. 5;
47 test \@a, [ 3 .. 5 ], 'grep';
48
49 my %h = (foo => 1, bar => 2);
50 @a = sort { $h{$a} <=> $h{$b} } keys %h;
51 test \@a, [ 'foo', 'bar' ], 'sort/keys';
52
53 print STDERR "# boo" if 0;