]> git.donarmstrong.com Git - perltidy.git/blob - examples/testfa.t
[svn-inject] Installing original source of perltidy
[perltidy.git] / examples / testfa.t
1 use strict;
2 use Test;
3 use Carp;
4 BEGIN {plan tests => 1}
5 use Perl::Tidy; 
6
7 #----------------------------------------------------------------------
8 ## test file->array 
9 #
10 #   Also tests:
11 #     passing perltidyrc (we cannot allow local .perltidyrc flags to be used)
12 #     the -gnu flag
13 #----------------------------------------------------------------------
14 my $source = "lextest";
15 my $perltidyrc = <<'EOM';
16 -gnu
17 EOM
18
19 my @tidy_output;
20
21 Perl::Tidy::perltidy(
22     source      => $source,
23     destination => \@tidy_output,
24     perltidyrc  => \$perltidyrc,
25     argv        => '-nsyn',
26 );
27
28 my @expected_output=<DATA>;
29 my $ok=1;
30 if (@expected_output == @tidy_output) {
31         while ( $_ = pop @tidy_output ) {
32             my $expect = pop @expected_output;
33             if ( $expect ne $_ ) {
34                 print STDERR "got:$_";
35                 print STDERR "---\n";
36                 print STDERR "expected_output:$expect";
37                 $ok=0;
38                 last;
39             }
40         }
41 }
42 else {
43         print STDERR "Line Counts differ\n";
44         $ok=0;
45 }
46 ok ($ok,1);
47
48 # This is the expected result of 'perltidy -gnu lextest':
49
50 __DATA__
51 # This is a simple testfile to demonstrate perltidy, from perlop(1).
52 # One way (of several) to run perltidy is as follows:
53 #
54 #   perl ./perltidy lextest
55 #
56 # The output will be "lextest.tdy"
57 $_ = <<'EOL';
58    $url = new URI::URL "http://www/";   die if $url eq "xXx";
59 EOL
60 LOOP:
61 {
62     print(" digits"),       redo LOOP if /\G\d+\b[,.;]?\s*/gc;
63     print(" lowercase"),    redo LOOP if /\G[a-z]+\b[,.;]?\s*/gc;
64     print(" UPPERCASE"),    redo LOOP if /\G[A-Z]+\b[,.;]?\s*/gc;
65     print(" Capitalized"),  redo LOOP if /\G[A-Z][a-z]+\b[,.;]?\s*/gc;
66     print(" MiXeD"),        redo LOOP if /\G[A-Za-z]+\b[,.;]?\s*/gc;
67     print(" alphanumeric"), redo LOOP if /\G[A-Za-z0-9]+\b[,.;]?\s*/gc;
68     print(" line-noise"),   redo LOOP if /\G[^A-Za-z0-9]+/gc;
69     print ". That's all!\n";
70 }