]> git.donarmstrong.com Git - perltidy.git/blob - t/testsa.t
fix up debian janitor merge commit to match actual pieces which were comitted
[perltidy.git] / t / testsa.t
1 use strict;
2 use Test;
3 use Carp;
4 BEGIN {plan tests => 1}
5 use Perl::Tidy; 
6
7 #----------------------------------------------------------------------
8 ## test string->array 
9 #     Also tests flags -ce and -l=60
10 #     Note that we have to use -npro to avoid using local .perltidyrc
11 #----------------------------------------------------------------------
12 my $source = <<'EOM';
13 $seqno = $type_sequence[$i];
14 if ($seqno) {
15   if (tok =~/[\(\[\{]/) {
16       $indentation{$seqno} = indentation
17   }
18 }
19 elsif (tok =~/[\)\]\}]/) {
20   $min_indentation = $indentation{$seqno};
21   delete $indentation{$seqno};
22   if ($indentation < $min_indentation) {$indentation = $min_indentation}
23 }
24 EOM
25
26 my @tidy_output;
27
28 Perl::Tidy::perltidy(
29     source      => \$source,
30     destination => \@tidy_output,
31     perltidyrc  => undef,
32     argv        => '-nsyn -ce -npro -l=60',
33 );
34
35 my @expected_output=<DATA>;
36 my $ok=1;
37 if (@expected_output == @tidy_output) {
38         while ( $_ = pop @tidy_output ) {
39             s/\s+$//;
40             my $expect = pop @expected_output;
41             $expect=~s/\s+$//;
42             if ( $expect ne $_ ) {
43                 print STDERR "got:$_";
44                 print STDERR "---\n";
45                 print STDERR "expected_output:$expect";
46                 $ok=0;
47                 last;
48             }
49         }
50 }
51 else {
52         print STDERR "Line Counts differ\n";
53         $ok=0;
54 }
55 ok ($ok,1);
56
57 # This is the expected result of 'perltidy -ce -l=60' on the above string:
58
59 __DATA__
60 $seqno = $type_sequence[$i];
61 if ($seqno) {
62     if ( tok =~ /[\(\[\{]/ ) {
63         $indentation{$seqno} = indentation;
64     }
65 } elsif ( tok =~ /[\)\]\}]/ ) {
66     $min_indentation = $indentation{$seqno};
67     delete $indentation{$seqno};
68     if ( $indentation < $min_indentation ) {
69         $indentation = $min_indentation;
70     }
71 }