]> git.donarmstrong.com Git - perltidy.git/blob - t/testsa.t
[svn-inject] Installing original source of perltidy
[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             my $expect = pop @expected_output;
40             if ( $expect ne $_ ) {
41                 print STDERR "got:$_";
42                 print STDERR "---\n";
43                 print STDERR "expected_output:$expect";
44                 $ok=0;
45                 last;
46             }
47         }
48 }
49 else {
50         print STDERR "Line Counts differ\n";
51         $ok=0;
52 }
53 ok ($ok,1);
54
55 # This is the expected result of 'perltidy -ce -l=60' on the above string:
56
57 __DATA__
58 $seqno = $type_sequence[$i];
59 if ($seqno) {
60     if ( tok =~ /[\(\[\{]/ ) {
61         $indentation{$seqno} = indentation;
62     }
63 } elsif ( tok =~ /[\)\]\}]/ ) {
64     $min_indentation =
65       $indentation{$seqno} delete $indentation{$seqno}
66       if ( $indentation < $min_indentation )
67     {
68         $indentation = $min_indentation;
69     }
70 }