From: Steve Hancock Date: Sun, 3 Nov 2024 00:55:22 +0000 (-0700) Subject: add -btct test cases X-Git-Tag: 20240903.05~2 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=72e15c6b7a3716650537ca3166cab70c1ad02aa9;p=perltidy.git add -btct test cases --- diff --git a/MANIFEST b/MANIFEST index 0070037d..479e3ab2 100644 --- a/MANIFEST +++ b/MANIFEST @@ -79,6 +79,7 @@ t/snippets28.t t/snippets29.t t/snippets3.t t/snippets30.t +t/snippets31.t t/snippets4.t t/snippets5.t t/snippets6.t diff --git a/bin/perltidy b/bin/perltidy index 3ed9508d..d3dd954a 100755 --- a/bin/perltidy +++ b/bin/perltidy @@ -4230,7 +4230,7 @@ we can add a trailing comma and break the container open with 'g', Canvas => $overview_canvas, ); -After that, we could use -btct='f(b' to keep the container open +After that, we could use C<-btct='f(b'> to keep the container open =item * diff --git a/t/snippets/btct.in b/t/snippets/btct.in new file mode 100644 index 00000000..43996da4 --- /dev/null +++ b/t/snippets/btct.in @@ -0,0 +1,13 @@ +$w->bind( + '' => xx, +); + +$w->bind( '' => xx,); + +$w->bind( + '' => xx +); + +$w->bind( '' => xx); + +$lut = byte [ [ 0, 0, 0 ], [ 10, 1, 10 ], [ 2, 20, 20 ], [ 30, 30, 3 ], ]; diff --git a/t/snippets/btct1.par b/t/snippets/btct1.par new file mode 100644 index 00000000..7faeb11d --- /dev/null +++ b/t/snippets/btct1.par @@ -0,0 +1 @@ +-btct=1 diff --git a/t/snippets/btct2.par b/t/snippets/btct2.par new file mode 100644 index 00000000..970d0dbc --- /dev/null +++ b/t/snippets/btct2.par @@ -0,0 +1 @@ +-btct=1 -atc -wtc=1 diff --git a/t/snippets/btct3.par b/t/snippets/btct3.par new file mode 100644 index 00000000..970d0dbc --- /dev/null +++ b/t/snippets/btct3.par @@ -0,0 +1 @@ +-btct=1 -atc -wtc=1 diff --git a/t/snippets/expect/btct.btct1 b/t/snippets/expect/btct.btct1 new file mode 100644 index 00000000..8896a786 --- /dev/null +++ b/t/snippets/expect/btct.btct1 @@ -0,0 +1,15 @@ +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$w->bind( '' => xx ); + +$w->bind( '' => xx ); + +$lut = byte [ + [ 0, 0, 0 ], [ 10, 1, 10 ], [ 2, 20, 20 ], [ 30, 30, 3 ], +]; diff --git a/t/snippets/expect/btct.btct2 b/t/snippets/expect/btct.btct2 new file mode 100644 index 00000000..7ade8623 --- /dev/null +++ b/t/snippets/expect/btct.btct2 @@ -0,0 +1,27 @@ +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$lut = byte [ + [ + 0, 0, 0, + ], [ + 10, 1, 10, + ], [ + 2, 20, 20, + ], [ + 30, 30, 3, + ], +]; diff --git a/t/snippets/expect/btct.btct3 b/t/snippets/expect/btct.btct3 new file mode 100644 index 00000000..7ade8623 --- /dev/null +++ b/t/snippets/expect/btct.btct3 @@ -0,0 +1,27 @@ +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$lut = byte [ + [ + 0, 0, 0, + ], [ + 10, 1, 10, + ], [ + 2, 20, 20, + ], [ + 30, 30, 3, + ], +]; diff --git a/t/snippets/expect/btct.def b/t/snippets/expect/btct.def new file mode 100644 index 00000000..7c975929 --- /dev/null +++ b/t/snippets/expect/btct.def @@ -0,0 +1,9 @@ +$w->bind( '' => xx, ); + +$w->bind( '' => xx, ); + +$w->bind( '' => xx ); + +$w->bind( '' => xx ); + +$lut = byte [ [ 0, 0, 0 ], [ 10, 1, 10 ], [ 2, 20, 20 ], [ 30, 30, 3 ], ]; diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index febdba54..77f42a26 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -580,3 +580,7 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def +../snippets30.t btct.btct1 +../snippets31.t btct.btct2 +../snippets31.t btct.btct3 +../snippets31.t btct.def diff --git a/t/snippets30.t b/t/snippets30.t index 3170b972..66582f72 100644 --- a/t/snippets30.t +++ b/t/snippets30.t @@ -19,6 +19,7 @@ #16 git162.git162 #17 qwaf.def #18 qwaf.qwaf +#19 btct.btct1 # To locate test #13 you can search for its name or the string '#13' @@ -38,6 +39,7 @@ BEGIN { $rparams = { 'altc1' => "-naltc -atc -wtc=m", 'altc2' => "-altc -atc -wtc=m", + 'btct1' => "-btct=1", 'csc3' => "-csc -csci=2 -ncscb", 'def' => "", 'dltc1' => "-dtc -wtc=0", @@ -71,6 +73,22 @@ $self->make_grammar( version => $self->version } ); +---------- + + 'btct' => <<'----------', +$w->bind( + '' => xx, +); + +$w->bind( '' => xx,); + +$w->bind( + '' => xx +); + +$w->bind( '' => xx); + +$lut = byte [ [ 0, 0, 0 ], [ 10, 1, 10 ], [ 2, 20, 20 ], [ 30, 30, 3 ], ]; ---------- 'csc' => <<'----------', @@ -486,6 +504,28 @@ use Digest::MD5 qw(md5_hex); @list = qw( \ ); #18........... }, + + 'btct.btct1' => { + source => "btct", + params => "btct1", + expect => <<'#19...........', +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$w->bind( '' => xx ); + +$w->bind( '' => xx ); + +$lut = byte [ + [ 0, 0, 0 ], [ 10, 1, 10 ], [ 2, 20, 20 ], [ 30, 30, 3 ], +]; +#19........... + }, }; my $ntests = 0 + keys %{$rtests}; diff --git a/t/snippets31.t b/t/snippets31.t new file mode 100644 index 00000000..27f54210 --- /dev/null +++ b/t/snippets31.t @@ -0,0 +1,199 @@ +# Created with: ./make_t.pl + +# Contents: +#1 btct.btct2 +#2 btct.btct3 +#3 btct.def + +# To locate test #13 you can search for its name or the string '#13' + +use strict; +use Test::More; +use Carp; +use Perl::Tidy; +my $rparams; +my $rsources; +my $rtests; + +BEGIN { + + ########################################### + # BEGIN SECTION 1: Parameter combinations # + ########################################### + $rparams = { + 'btct2' => "-btct=1 -atc -wtc=1", + 'btct3' => "-btct=1 -atc -wtc=1", + 'def' => "", + }; + + ############################ + # BEGIN SECTION 2: Sources # + ############################ + $rsources = { + + 'btct' => <<'----------', +$w->bind( + '' => xx, +); + +$w->bind( '' => xx,); + +$w->bind( + '' => xx +); + +$w->bind( '' => xx); + +$lut = byte [ [ 0, 0, 0 ], [ 10, 1, 10 ], [ 2, 20, 20 ], [ 30, 30, 3 ], ]; +---------- + }; + + #################################### + # BEGIN SECTION 3: Expected output # + #################################### + $rtests = { + + 'btct.btct2' => { + source => "btct", + params => "btct2", + expect => <<'#1...........', +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$lut = byte [ + [ + 0, 0, 0, + ], [ + 10, 1, 10, + ], [ + 2, 20, 20, + ], [ + 30, 30, 3, + ], +]; +#1........... + }, + + 'btct.btct3' => { + source => "btct", + params => "btct3", + expect => <<'#2...........', +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$w->bind( + '' => xx, +); + +$lut = byte [ + [ + 0, 0, 0, + ], [ + 10, 1, 10, + ], [ + 2, 20, 20, + ], [ + 30, 30, 3, + ], +]; +#2........... + }, + + 'btct.def' => { + source => "btct", + params => "def", + expect => <<'#3...........', +$w->bind( '' => xx, ); + +$w->bind( '' => xx, ); + +$w->bind( '' => xx ); + +$w->bind( '' => xx ); + +$lut = byte [ [ 0, 0, 0 ], [ 10, 1, 10 ], [ 2, 20, 20 ], [ 30, 30, 3 ], ]; +#3........... + }, + }; + + my $ntests = 0 + keys %{$rtests}; + plan tests => $ntests; +} + +############### +# EXECUTE TESTS +############### + +foreach my $key ( sort keys %{$rtests} ) { + my $output; + my $sname = $rtests->{$key}->{source}; + my $expect = $rtests->{$key}->{expect}; + my $pname = $rtests->{$key}->{params}; + my $source = $rsources->{$sname}; + my $params = defined($pname) ? $rparams->{$pname} : ""; + my $stderr_string; + my $errorfile_string; + my $err = Perl::Tidy::perltidy( + source => \$source, + destination => \$output, + perltidyrc => \$params, + argv => '', # for safety; hide any ARGV from perltidy + stderr => \$stderr_string, + errorfile => \$errorfile_string, # not used when -se flag is set + ); + if ( $err || $stderr_string || $errorfile_string ) { + print STDERR "Error output received for test '$key'\n"; + if ($err) { + print STDERR "An error flag '$err' was returned\n"; + ok( !$err ); + } + if ($stderr_string) { + print STDERR "---------------------\n"; + print STDERR "<>\n$stderr_string\n"; + print STDERR "---------------------\n"; + ok( !$stderr_string ); + } + if ($errorfile_string) { + print STDERR "---------------------\n"; + print STDERR "<<.ERR file>>\n$errorfile_string\n"; + print STDERR "---------------------\n"; + ok( !$errorfile_string ); + } + } + else { + if ( !is( $output, $expect, $key ) ) { + my $leno = length($output); + my $lene = length($expect); + if ( $leno == $lene ) { + print STDERR +"#> Test '$key' gave unexpected output. Strings differ but both have length $leno\n"; + } + else { + print STDERR +"#> Test '$key' gave unexpected output. String lengths differ: output=$leno, expected=$lene\n"; + } + } + } +}