]> git.donarmstrong.com Git - perltidy.git/blob - t/filter_example.t.SKIP
New upstream version 20181120
[perltidy.git] / t / filter_example.t.SKIP
1 # Test use of prefilter and postfilter parameters 
2 use strict;
3 use Carp;
4 use Perl::Tidy;
5 use Test;
6
7 BEGIN {
8     plan tests => 1;
9 }
10
11 my $source = <<'ENDS';
12 use Method::Signatures::Simple;
13
14  method foo1 { $self->bar }
15
16        # with signature
17     method foo2($bar, %opts) { $self->bar(reverse $bar) if $opts{rev};
18     }
19
20     # attributes
21     method foo3 : lvalue { $self->{foo} 
22 }
23
24  # change invocant name
25     method 
26 foo4 ($class: $bar) { $class->bar($bar) }
27 ENDS
28
29 my $expect = <<'ENDE';
30 use Method::Signatures::Simple;
31 method foo1 { $self->bar }
32
33 # with signature
34 method foo2 ( $bar, %opts ) {
35     $self->bar( reverse $bar ) if $opts{rev};
36 }
37
38 # attributes
39 method foo3 : lvalue {
40     $self->{foo};
41 }
42
43 # change invocant name
44 method foo4 ($class: $bar) { $class->bar($bar) }
45 ENDE
46
47 my $output;
48 my $stderr_string;
49 my $errorfile_string;
50 my $err = Perl::Tidy::perltidy(
51     argv => '-npro',  # fix for RT#127679, avoid reading unwanted .perltidyrc
52     prefilter =>
53       sub { $_ = $_[0]; s/^\s*method\s+(\w.*)/sub METHOD_$1/gm; return $_ },
54     postfilter  => sub { $_ = $_[0]; s/sub\s+METHOD_/method /gm; return $_ },
55     source      => \$source,
56     destination => \$output,
57     stderr    => \$stderr_string,
58     errorfile => \$errorfile_string,   # not used when -se flag is set
59 );
60 if ( $err || $stderr_string || $errorfile_string ) {
61     ok(0);
62 }
63 else {
64     ok( $output, $expect );
65 }