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