From: Steve Hancock Date: Wed, 22 Apr 2020 02:13:19 +0000 (-0700) Subject: added numerous tests to improve coverage X-Git-Tag: 20200619~82 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=5ba6f73957f410186c62b723b27b904fa9b7c80b;p=perltidy.git added numerous tests to improve coverage --- diff --git a/t/snippets/braces.in b/t/snippets/braces.in new file mode 100644 index 00000000..8b93c94a --- /dev/null +++ b/t/snippets/braces.in @@ -0,0 +1,12 @@ +sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } +} + +$myfun = sub { + print("Hello, World\n"); +}; diff --git a/t/snippets/braces1.par b/t/snippets/braces1.par new file mode 100644 index 00000000..e777cf53 --- /dev/null +++ b/t/snippets/braces1.par @@ -0,0 +1 @@ +-bl -asbl diff --git a/t/snippets/braces2.par b/t/snippets/braces2.par new file mode 100644 index 00000000..ba66778e --- /dev/null +++ b/t/snippets/braces2.par @@ -0,0 +1 @@ +-sbl diff --git a/t/snippets/braces3.par b/t/snippets/braces3.par new file mode 100644 index 00000000..3ee06bc1 --- /dev/null +++ b/t/snippets/braces3.par @@ -0,0 +1 @@ +-bli diff --git a/t/snippets/comments.in b/t/snippets/comments.in index 9fa0ee35..9328f6f3 100644 --- a/t/snippets/comments.in +++ b/t/snippets/comments.in @@ -9,16 +9,35 @@ sub macro_get_names { # # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment - local(%name)=(); +##local(%name); # a static block comment without indentation + local(%name)=(); ## a static side comment to test -ssc + + # a spaced block comment to test -isbc for (0..$ #mac_ver) { + # a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[$idx{$mac_exti[$_]}]; + $vmsfile =~ s/;[\d\-]*$//; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } + @month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec'); + + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + + # A blank line interrupts the hsc's; this is a block comment + +} # side comments at different indentation levels should not normally be aligned { { { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } } #end level 4 @@ -27,6 +46,15 @@ sub macro_get_names { # } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + + # some blank lines follow diff --git a/t/snippets/comments1.par b/t/snippets/comments1.par index cd3c9861..ceb3c038 100644 --- a/t/snippets/comments1.par +++ b/t/snippets/comments1.par @@ -1 +1 @@ --fpsc=40 -iscl -nibc +-fpsc=40 -iscl -nibc -nhsc -ssc diff --git a/t/snippets/comments3.par b/t/snippets/comments3.par index 20cd6284..4b5f9142 100644 --- a/t/snippets/comments3.par +++ b/t/snippets/comments3.par @@ -1 +1 @@ --mbl=2 +-mbl=2 -isbc diff --git a/t/snippets/comments4.par b/t/snippets/comments4.par index e006eaf3..ce467f5c 100644 --- a/t/snippets/comments4.par +++ b/t/snippets/comments4.par @@ -1 +1 @@ --kbl=2 +-kbl=2 -nolc -osbc diff --git a/t/snippets/comments5.par b/t/snippets/comments5.par index 52663e54..1fa4c457 100644 --- a/t/snippets/comments5.par +++ b/t/snippets/comments5.par @@ -1 +1 @@ --dsc +-dsc -nsbc diff --git a/t/snippets/coverage_missing.txt b/t/snippets/coverage_missing.txt index 35407170..a53b83fb 100644 --- a/t/snippets/coverage_missing.txt +++ b/t/snippets/coverage_missing.txt @@ -1,22 +1,20 @@ # No coverage in test snippets for these parameters DEBUG +assert-tidy +assert-untidy backlink block-brace-vertical-tightness-list -brace-left-and-indent brace-left-and-indent-list -break-after-all-operators break-at-old-attribute-breakpoints break-at-old-keyword-breakpoints break-at-old-logical-breakpoints break-at-old-ternary-breakpoints -break-before-all-operators cachedir closing-side-comment-list closing-side-comment-prefix closing-side-comment-warnings closing-side-comments-balanced closing-token-indentation -cuddled-block-list cuddled-block-list-exclusive dump-cuddled-block-list dump-defaults @@ -29,7 +27,6 @@ dump-want-left-space dump-want-right-space extended-syntax file-size-order -fixed-position-side-comment force-read-binary format-skipping format-skipping-begin @@ -100,10 +97,8 @@ html-src-extension html-table-of-contents html-toc-extension htmlroot -ignore-old-breakpoints -indent-block-comments indent-closing-brace -keep-interior-semicolons +keyword-group-blanks-list libpods logfile logfile-gap @@ -114,14 +109,9 @@ memoize no-profile nohtml-style-sheets noprofile -nospace-after-keyword notidy npro -opening-anonymous-sub-brace-on-new-line outdent-keyword-list -outdent-keywords -outdent-labels -outdent-static-block-comments outfile output-file-extension output-line-ending @@ -143,14 +133,11 @@ show-options space-after-keyword space-function-paren space-keyword-paren -space-terminal-semicolon stack-closing-block-brace stack-opening-block-brace standard-output static-block-comment-prefix -static-block-comments static-side-comment-prefix -static-side-comments stylesheet tabs tee-block-comments @@ -159,6 +146,7 @@ tee-side-comments title trim-pod trim-qw +use-unicode-gcstring valign version vertical-tightness diff --git a/t/snippets/coverage_values.txt b/t/snippets/coverage_values.txt index d2fe2fd3..b44d86ee 100644 --- a/t/snippets/coverage_values.txt +++ b/t/snippets/coverage_values.txt @@ -1,373 +1,493 @@ $VAR1 = { - 'outdent-long-quotes' => [ - 0, - 1 - ], - 'opening-square-bracket-right' => [ - 0, - 1 - ], - 'cuddled-else' => [ - 0, - 1 - ], - 'iterations' => [ - 1 - ], - 'indent-columns' => [ - 0, - 2, - 4 - ], - 'add-semicolons' => [ - 0, - 1 - ], - 'keep-old-blank-lines' => [ - 0, + 'space-terminal-semicolon' => [ + 0, + 1 + ], + 'format' => [ + 'html', + 'tidy' + ], + 'want-break-before' => [ + ' ', + '% + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=', + '% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=', + '=' + ], + 'cuddled-break-option' => [ 1 ], - 'stack-opening-paren' => [ - 0, - 1 - ], - 'stack-opening-hash-brace' => [ + 'keep-interior-semicolons' => [ 0, 1 ], - 'backup-file-extension' => [ - 'bak', - '~' - ], - 'timestamp' => [ - 0, - 1 - ], - 'opening-brace-on-new-line' => [ + 'paren-vertical-tightness' => [ + 0, + 1, + 2 + ], + 'closing-paren-indentation' => [ 0, - 1 + 1, + 2 ], - 'continuation-indentation' => [ + 'want-right-space' => [ + '= .= =~ !~ ? :' + ], + 'stack-closing-hash-brace' => [ 0, - 2, - 4 + 1 ], 'closing-brace-indentation' => [ 0, 1, 2 ], - 'closing-side-comment-else-flag' => [ + 'block-brace-vertical-tightness' => [ 0 ], - 'variable-maximum-line-length' => [ - 0, - 1 - ], - 'blanks-before-comments' => [ - 0, - 1 - ], - 'closing-side-comment-maximum-text' => [ - 20, - 40 - ], - 'fuzzy-line-length' => [ - 0, - 1 - ], - 'blank-lines-after-opening-block-list' => [ - '*' - ], - 'paren-vertical-tightness-closing' => [ + 'brace-vertical-tightness-closing' => [ 0, 2 ], - 'closing-side-comments' => [ - 0, - 1 - ], - 'starting-indentation-level' => [ - 0 - ], - 'paren-vertical-tightness' => [ - 0, - 1, - 2 - ], - 'recombine' => [ - 0, - 1 - ], - 'maximum-fields-per-table' => [ - 0 - ], - 'opening-paren-right' => [ + 'stack-opening-paren' => [ 0, 1 ], + 'add-whitespace' => [ + 0, + 1 + ], 'delete-semicolons' => [ 0, 1 ], - 'closing-paren-indentation' => [ - 0, - 1, - 2 - ], - 'hanging-side-comments' => [ + 'break-at-old-semicolon-breakpoints' => [ + 0, + 1 + ], + 'continuation-indentation' => [ + 0, + 2, + 4 + ], + 'brace-left-and-indent' => [ 0, 1 ], - 'comma-arrow-breakpoints' => [ - 1, - 5 - ], - 'opening-sub-brace-on-new-line' => [ - 0, - 1 - ], - 'square-bracket-tightness' => [ - 1, - 2 - ], - 'warning-output' => [ - 0, - 1 - ], - 'square-bracket-vertical-tightness-closing' => [ - 0, - 2 - ], - 'blanks-before-blocks' => [ - 0, - 1 - ], + 'square-bracket-vertical-tightness' => [ + 0, + 1, + 2 + ], + 'closing-side-comment-else-flag' => [ + 0 + ], + 'short-concatenation-item-length' => [ + 12, + 8 + ], + 'break-before-all-operators' => [ + 0, + 1 + ], 'delete-block-comments' => [ 0, 1 ], - 'add-newlines' => [ - 0, - 1 - ], - 'want-right-space' => [ - '= .= =~ !~ ? :' - ], - 'stack-closing-square-bracket' => [ - 0, - 1 - ], - 'want-break-before' => [ - ' ', - '% + - * / x != == >= <= =~ !~ < > | & = **= += *= &= <<= &&= -= /= |= >>= ||= //= .= %= ^= x=', - '% + - * / x != == >= <= =~ < > | & **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x=' - ], - 'entab-leading-whitespace' => [ - 8 - ], - 'space-backslash-quote' => [ + 'starting-indentation-level' => [ + 0 + ], + 'closing-side-comments' => [ + 0, 1 ], - 'add-whitespace' => [ - 0, - 1 - ], - 'space-for-semicolon' => [ + 'opening-paren-right' => [ 0, 1 ], - 'maximum-consecutive-blank-lines' => [ - 0, - 1, - 2 - ], - 'standard-error-output' => [ + 'blanks-before-comments' => [ + 0, + 1 + ], + 'minimum-space-to-comment' => [ + 10, + 2, + 4 + ], + 'square-bracket-vertical-tightness-closing' => [ + 0, + 2 + ], + 'indent-block-comments' => [ 0, 1 ], - 'closing-side-comment-interval' => [ - 20, - 6 - ], - 'brace-tightness' => [ - 0, - 1, - 2 - ], - 'nowant-right-space' => [ - '++ --', - '..' - ], - 'opening-brace-always-on-right' => [ - 0, - 1 - ], - 'blank-lines-after-opening-block' => [ - 2 + 'break-at-old-method-breakpoints' => [ + 0, + 1 ], - 'delete-closing-side-comments' => [ - 0, - 1 - ], - 'delete-old-whitespace' => [ - 0, - 1 - ], - 'cuddled-break-option' => [ - 1 + 'keep-old-blank-lines' => [ + 0, + 1, + 2 ], - 'blank-lines-before-closing-block' => [ - 1 - ], - 'block-brace-tightness' => [ + 'space-prototype-paren' => [ 0, 1, 2 ], - 'outdent-long-comments' => [ - 0, - 1 - ], - 'stack-closing-hash-brace' => [ + 'stack-opening-hash-brace' => [ 0, 1 ], - 'check-syntax' => [ - 0, - 1 - ], - 'line-up-parentheses' => [ - 0, - 1 - ], - 'ignore-side-comment-lengths' => [ + 'keyword-group-blanks-inside' => [ 0, 1 ], - 'default-tabsize' => [ - 8 - ], - 'delete-old-newlines' => [ - 0, - 1 - ], - 'character-encoding' => [ - 'none' - ], - 'tight-secret-operators' => [ + 'long-block-line-count' => [ + 8 + ], + 'blank-lines-before-subs' => [ + 0, + 1 + ], + 'closing-side-comment-maximum-text' => [ + 20, + 40 + ], + 'one-line-block-nesting' => [ 0, 1 ], + 'outdent-labels' => [ + 0, + 1 + ], + 'opening-hash-brace-right' => [ + 0, + 1 + ], + 'brace-vertical-tightness' => [ + 0, + 1, + 2 + ], + 'break-at-old-comma-breakpoints' => [ + 0, + 1 + ], + 'blank-lines-after-opening-block' => [ + 2 + ], + 'timestamp' => [ + 0, + 1 + ], + 'stack-opening-square-bracket' => [ + 0, + 1 + ], + 'blank-lines-before-closing-block' => [ + 1 + ], + 'cuddled-else' => [ + 0, + 1 + ], + 'outdent-long-quotes' => [ + 0, + 1 + ], + 'paren-vertical-tightness-closing' => [ + 0, + 2 + ], + 'iterations' => [ + 1 + ], 'delete-pod' => [ 0, 1 ], - 'maximum-line-length' => [ + 'standard-error-output' => [ + 0, + 1 + ], + 'space-for-semicolon' => [ 0, - 1, - 100, - 100000, - 160, - 77, - 78, - 80 + 1 ], + 'warning-output' => [ + 0, + 1 + ], + 'one-line-block-semicolons' => [ + 0, + 1, + 2 + ], + 'sub-alias-list' => [ + 'method fun' + ], + 'square-bracket-tightness' => [ + 0, + 1, + 2 + ], + 'variable-maximum-line-length' => [ + 0, + 1 + ], + 'block-brace-tightness' => [ + 0, + 1, + 2 + ], + 'keyword-group-blanks-repeat-count' => [ + 0 + ], + 'opening-brace-always-on-right' => [ + 0, + 1 + ], 'delete-side-comments' => [ 0, 1 ], - 'opening-hash-brace-right' => [ - 0, - 1 - ], + 'paren-tightness' => [ + 0, + 1, + 2 + ], + 'static-side-comments' => [ + 0, + 1 + ], 'blank-lines-before-packages' => [ 0, 1 ], - 'short-concatenation-item-length' => [ - 12, - 8 - ], - 'want-break-after' => [ - '% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x= . << >> -> && ||' - ], - 'brace-vertical-tightness-closing' => [ - 0, - 2 - ], - 'format' => [ - 'html', - 'tidy' - ], - 'want-left-space' => [ - '= .= =~ !~ :' - ], - 'indent-spaced-block-comments' => [ + 'indent-columns' => [ + 0, + 2, + 4 + ], + 'fuzzy-line-length' => [ + 0, + 1 + ], + 'blank-lines-after-opening-block-list' => [ + '*' + ], + 'entab-leading-whitespace' => [ + 8 + ], + 'add-newlines' => [ + 0, + 1 + ], + 'hanging-side-comments' => [ + 0, + 1 + ], + 'stack-closing-square-bracket' => [ 0, 1 ], - 'closing-square-bracket-indentation' => [ - 0, - 1, - 2 - ], - 'block-brace-vertical-tightness' => [ - 0 - ], - 'square-bracket-vertical-tightness' => [ - 0, - 1, - 2 - ], - 'brace-vertical-tightness' => [ - 0, - 1, - 2 + 'fixed-position-side-comment' => [ + 40 + ], + 'nospace-after-keyword' => [ + 'my for' + ], + 'add-semicolons' => [ + 0, + 1 + ], + 'delete-closing-side-comments' => [ + 0, + 1 + ], + 'want-left-space' => [ + '= .= =~ !~ :' + ], + 'delete-old-newlines' => [ + 0, + 1 + ], + 'weld-nested-containers' => [ + 0, + 1 + ], + 'maximum-fields-per-table' => [ + 0 ], - 'break-at-old-comma-breakpoints' => [ - 0, - 1 - ], - 'nowant-left-space' => [ - '++ -- ?', - '..' - ], - 'blank-lines-before-closing-block-list' => [ - '*' - ], + 'default-tabsize' => [ + 8 + ], 'backup-and-modify-in-place' => [ 0, 1 ], - 'blank-lines-before-subs' => [ - 0, - 1 - ], - 'stack-opening-square-bracket' => [ + 'closing-square-bracket-indentation' => [ + 0, + 1, + 2 + ], + 'character-encoding' => [ + 'guess' + ], + 'static-block-comments' => [ + 0, + 1 + ], + 'maximum-consecutive-blank-lines' => [ + 0, + 1, + 2 + ], + 'break-after-all-operators' => [ + 0, + 1 + ], + 'space-backslash-quote' => [ + 0, + 1, + 2 + ], + 'indent-spaced-block-comments' => [ 0, 1 ], - 'perl-syntax-check-flags' => [ - '-c -T' + 'backup-file-extension' => [ + 'bak', + '~' + ], + 'keyword-group-blanks-delete' => [ + 0, + 1 + ], + 'opening-square-bracket-right' => [ + 0, + 1 + ], + 'want-break-after' => [ + '% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x= . << >> -> && ||' + ], + 'recombine' => [ + 0, + 1 + ], + 'comma-arrow-breakpoints' => [ + 1, + 5 ], - 'paren-tightness' => [ + 'keyword-group-blanks-size' => [ + '5' + ], + 'brace-tightness' => [ + 0, 1, 2 ], - 'minimum-space-to-comment' => [ - 2, - 4 - ], - 'weld-nested-containers' => [ + 'outdent-keywords' => [ + 0, + 1 + ], + 'nowant-left-space' => [ + '++ -- ?', + '..', + '= + - / *' + ], + 'opening-anonymous-sub-brace-on-new-line' => [ + 0, + 1 + ], + 'stack-closing-paren' => [ + 0, + 1 + ], + 'tight-secret-operators' => [ 0, 1 ], - 'long-block-line-count' => [ - 8 + 'ignore-side-comment-lengths' => [ + 0, + 1 + ], + 'perl-syntax-check-flags' => [ + '-c -T' + ], + 'opening-brace-on-new-line' => [ + 0, + 1 + ], + 'blanks-before-blocks' => [ + 0, + 1 + ], + 'keyword-group-blanks-before' => [ + 1, + 2 + ], + 'blank-lines-before-closing-block-list' => [ + '*' + ], + 'delete-old-whitespace' => [ + 0, + 1 ], - 'stack-closing-paren' => [ + 'cuddled-block-list' => [ + 'map,sort,grep', + 'sort,map,grep' + ], + 'closing-side-comment-interval' => [ + 2, + 20, + 6 + ], + 'maximum-line-length' => [ + 0, + 1, + 100, + 100000, + 160, + 77, + 78, + 80 + ], + 'ignore-old-breakpoints' => [ + 0, + 1 + ], + 'check-syntax' => [ + 0, + 1 + ], + 'outdent-static-block-comments' => [ + 0, + 1 + ], + 'keyword-group-blanks-after' => [ + 1, + 2 + ], + 'line-up-parentheses' => [ 0, 1 - ] + ], + 'outdent-long-comments' => [ + 0, + 1 + ], + 'nowant-right-space' => [ + '++ --', + '..', + '= + - / *', + 'A' + ], + 'opening-sub-brace-on-new-line' => [ + 0, + 1 + ] }; diff --git a/t/snippets/csc.in b/t/snippets/csc.in new file mode 100644 index 00000000..87ba7a89 --- /dev/null +++ b/t/snippets/csc.in @@ -0,0 +1,8 @@ + sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } + } ## end sub message diff --git a/t/snippets/csc1.par b/t/snippets/csc1.par new file mode 100644 index 00000000..f0f1921d --- /dev/null +++ b/t/snippets/csc1.par @@ -0,0 +1 @@ +-csc -csci=2 -cscb diff --git a/t/snippets/csc2.par b/t/snippets/csc2.par new file mode 100644 index 00000000..fef4520c --- /dev/null +++ b/t/snippets/csc2.par @@ -0,0 +1 @@ +-dcsc diff --git a/t/snippets/expect/braces.braces1 b/t/snippets/expect/braces.braces1 new file mode 100644 index 00000000..364230b1 --- /dev/null +++ b/t/snippets/expect/braces.braces1 @@ -0,0 +1,16 @@ +sub message +{ + if ( !defined( $_[0] ) ) + { + print("Hello, World\n"); + } + else + { + print( $_[0], "\n" ); + } +} + +$myfun = sub +{ + print("Hello, World\n"); +}; diff --git a/t/snippets/expect/braces.braces2 b/t/snippets/expect/braces.braces2 new file mode 100644 index 00000000..c55b4c10 --- /dev/null +++ b/t/snippets/expect/braces.braces2 @@ -0,0 +1,13 @@ +sub message +{ + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } +} + +$myfun = sub { + print("Hello, World\n"); +}; diff --git a/t/snippets/expect/braces.braces3 b/t/snippets/expect/braces.braces3 new file mode 100644 index 00000000..bbce26ff --- /dev/null +++ b/t/snippets/expect/braces.braces3 @@ -0,0 +1,15 @@ +sub message + { + if ( !defined( $_[0] ) ) + { + print("Hello, World\n"); + } + else + { + print( $_[0], "\n" ); + } + } + +$myfun = sub { + print("Hello, World\n"); +}; diff --git a/t/snippets/expect/braces.def b/t/snippets/expect/braces.def new file mode 100644 index 00000000..8b93c94a --- /dev/null +++ b/t/snippets/expect/braces.def @@ -0,0 +1,12 @@ +sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } +} + +$myfun = sub { + print("Hello, World\n"); +}; diff --git a/t/snippets/expect/comments.comments1 b/t/snippets/expect/comments.comments1 index 5de00718..ba95d6f0 100644 --- a/t/snippets/expect/comments.comments1 +++ b/t/snippets/expect/comments.comments1 @@ -1,22 +1,45 @@ #!/usr/bin/perl -w # an initial hash bang line cannot be deleted with -dp sub length { return length( $_[0] ) } # side comment - # hanging side comment - # very longgggggggggggggggggggggggggggggggggggggggggggggggggggg hanging side comment + +# hanging side comment +# very longgggggggggggggggggggggggggggggggggggggggggggggggggggg hanging side comment # side comments following open brace are not currently treated as hanging side comments sub macro_get_names { # # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment - local (%name) = (); +##local(%name); # a static block comment without indentation + local (%name) = (); ## a static side comment to test -ssc + +# a spaced block comment to test -isbc for ( 0 .. $#mac_ver ) { + +# a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$//; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', +## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec' +); + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + +# This is a hanging side comment +# And so is this + +# A blank line interrupts the hsc's; this is a block comment + +} + # side comments at different indentation levels should not normally be aligned { { @@ -28,6 +51,14 @@ sub macro_get_names { # } # end level 2 } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + # some blank lines follow =pod diff --git a/t/snippets/expect/comments.comments2 b/t/snippets/expect/comments.comments2 index da485912..9de359bf 100644 --- a/t/snippets/expect/comments.comments2 +++ b/t/snippets/expect/comments.comments2 @@ -4,23 +4,47 @@ sub length { return length( $_[0] ) } # side comment # very longgggggggggggggggggggggggggggggggggggggggggggggggggggg hanging side comment sub macro_get_names { # - local (%name) = (); + local (%name) = (); ## a static side comment to test -ssc + for ( 0 .. $#mac_ver ) { $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$// + ; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + 'Nov', 'Dec' +); + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + +} + { { { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } - } #end level 4 + } #end level 4 } # end level 3 } # end level 2 } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + __END__ diff --git a/t/snippets/expect/comments.comments3 b/t/snippets/expect/comments.comments3 index 60b3059e..16e819be 100644 --- a/t/snippets/expect/comments.comments3 +++ b/t/snippets/expect/comments.comments3 @@ -6,30 +6,62 @@ sub length { return length( $_[0] ) } # side comment # side comments following open brace are not currently treated as hanging side comments sub macro_get_names { # - # - # %name = macro_get_names(); (key=macrohandle, value=macroname) - # -##local(%name); # a static block comment - local (%name) = (); +# +# %name = macro_get_names(); (key=macrohandle, value=macroname) +# +##local(%name); # a static block comment without indentation + local (%name) = (); ## a static side comment to test -ssc + + # a spaced block comment to test -isbc for ( 0 .. $#mac_ver ) { + +# a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$// + ; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec' +); + + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + + # A blank line interrupts the hsc's; this is a block comment + +} + # side comments at different indentation levels should not normally be aligned { { { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } - } #end level 4 + } #end level 4 } # end level 3 } # end level 2 } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + + # some blank lines follow diff --git a/t/snippets/expect/comments.comments4 b/t/snippets/expect/comments.comments4 index 0216c388..a6d1e831 100644 --- a/t/snippets/expect/comments.comments4 +++ b/t/snippets/expect/comments.comments4 @@ -9,16 +9,38 @@ sub macro_get_names { # # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment - local (%name) = (); +##local(%name); # a static block comment without indentation + local (%name) = (); ## a static side comment to test -ssc + + # a spaced block comment to test -isbc for ( 0 .. $#mac_ver ) { + + # a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$// + ; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec' +); + + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + + # A blank line interrupts the hsc's; this is a block comment + +} # side comments at different indentation levels should not normally be aligned { @@ -26,12 +48,21 @@ sub macro_get_names { # { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } - } #end level 4 + } #end level 4 } # end level 3 } # end level 2 } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + + # some blank lines follow diff --git a/t/snippets/expect/comments.comments5 b/t/snippets/expect/comments.comments5 index b21bbd17..04efd9c1 100644 --- a/t/snippets/expect/comments.comments5 +++ b/t/snippets/expect/comments.comments5 @@ -7,14 +7,34 @@ sub macro_get_names { # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment + ##local(%name); # a static block comment without indentation local (%name) = (); + + # a spaced block comment to test -isbc for ( 0 .. $#mac_ver ) { + +# a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$//; + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec' +); + +{ + my $IGNORE = 0; + + # A blank line interrupts the hsc's; this is a block comment + +} + # side comments at different indentation levels should not normally be aligned { { @@ -26,6 +46,14 @@ sub macro_get_names { } } +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + # some blank lines follow =pod diff --git a/t/snippets/expect/comments.def b/t/snippets/expect/comments.def index 883c68b1..177ce345 100644 --- a/t/snippets/expect/comments.def +++ b/t/snippets/expect/comments.def @@ -9,25 +9,55 @@ sub macro_get_names { # # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment - local (%name) = (); +##local(%name); # a static block comment without indentation + local (%name) = (); ## a static side comment to test -ssc + + # a spaced block comment to test -isbc for ( 0 .. $#mac_ver ) { + +# a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$// + ; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec' +); + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + + # A blank line interrupts the hsc's; this is a block comment + +} + # side comments at different indentation levels should not normally be aligned { { { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } - } #end level 4 + } #end level 4 } # end level 3 } # end level 2 } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + # some blank lines follow =pod diff --git a/t/snippets/expect/csc.csc1 b/t/snippets/expect/csc.csc1 new file mode 100644 index 00000000..e99b0394 --- /dev/null +++ b/t/snippets/expect/csc.csc1 @@ -0,0 +1,8 @@ + sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } ## end if ( !defined( $_[0] )) + else { + print( $_[0], "\n" ); + } ## end else [ if ( !defined( $_[0] ))] + } ## end sub message diff --git a/t/snippets/expect/csc.csc2 b/t/snippets/expect/csc.csc2 new file mode 100644 index 00000000..5d390ad6 --- /dev/null +++ b/t/snippets/expect/csc.csc2 @@ -0,0 +1,8 @@ + sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } + } diff --git a/t/snippets/expect/csc.def b/t/snippets/expect/csc.def new file mode 100644 index 00000000..87ba7a89 --- /dev/null +++ b/t/snippets/expect/csc.def @@ -0,0 +1,8 @@ + sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } + } ## end sub message diff --git a/t/snippets/expect/iob.def b/t/snippets/expect/iob.def new file mode 100644 index 00000000..181c341c --- /dev/null +++ b/t/snippets/expect/iob.def @@ -0,0 +1,3 @@ +return "this is a descriptive error message" + if $res->is_error + or not length $data; diff --git a/t/snippets/expect/iob.iob b/t/snippets/expect/iob.iob new file mode 100644 index 00000000..3b41a537 --- /dev/null +++ b/t/snippets/expect/iob.iob @@ -0,0 +1,2 @@ +return "this is a descriptive error message" + if $res->is_error or not length $data; diff --git a/t/snippets/expect/kis.def b/t/snippets/expect/kis.def new file mode 100644 index 00000000..84cf03cd --- /dev/null +++ b/t/snippets/expect/kis.def @@ -0,0 +1,4 @@ + dbmclose(%verb_delim); + undef %verb_delim; + dbmclose(%expanded); + undef %expanded; diff --git a/t/snippets/expect/kis.kis b/t/snippets/expect/kis.kis new file mode 100644 index 00000000..25f16195 --- /dev/null +++ b/t/snippets/expect/kis.kis @@ -0,0 +1,2 @@ + dbmclose(%verb_delim); undef %verb_delim; + dbmclose(%expanded); undef %expanded; diff --git a/t/snippets/expect/maths.def b/t/snippets/expect/maths.def new file mode 100644 index 00000000..0bf2818c --- /dev/null +++ b/t/snippets/expect/maths.def @@ -0,0 +1,15 @@ +$tmp = + $day - 32075 + + 1461 * ( $year + 4800 - ( 14 - $month ) / 12 ) / 4 + + 367 * ( $month - 2 + ( ( 14 - $month ) / 12 ) * 12 ) / 12 - + 3 * ( ( $year + 4900 - ( 14 - $month ) / 12 ) / 100 ) / 4; + +return ( $r**$n ) * + ( pi**( $n / 2 ) ) / + ( + sqrt(pi) * + factorial( 2 * ( int( $n / 2 ) ) + 2 ) / + factorial( int( $n / 2 ) + 1 ) / + ( 4**( int( $n / 2 ) + 1 ) ) ); + +$root = -$b + sqrt( $b * $b - 4. * $a * $c ) / ( 2. * $a ); diff --git a/t/snippets/expect/maths.maths1 b/t/snippets/expect/maths.maths1 new file mode 100644 index 00000000..8a82115e --- /dev/null +++ b/t/snippets/expect/maths.maths1 @@ -0,0 +1,15 @@ +$tmp + =$day-32075 + +1461*( $year+4800-( 14-$month )/12 )/4 + +367*( $month-2+( ( 14-$month )/12 )*12 )/12 + -3*( ( $year+4900-( 14-$month )/12 )/100 )/4; + +return ( $r**$n ) + *( pi**( $n/2 ) ) + /( + sqrt(pi) + *factorial( 2*( int( $n/2 ) )+2 ) + /factorial( int( $n/2 )+1 ) + /( 4**( int( $n/2 )+1 ) ) ); + +$root=-$b+sqrt( $b*$b-4.*$a*$c )/( 2.*$a ); diff --git a/t/snippets/expect/maths.maths2 b/t/snippets/expect/maths.maths2 new file mode 100644 index 00000000..e46ca241 --- /dev/null +++ b/t/snippets/expect/maths.maths2 @@ -0,0 +1,15 @@ +$tmp= + $day-32075+ + 1461*( $year+4800-( 14-$month )/12 )/4+ + 367*( $month-2+( ( 14-$month )/12 )*12 )/12- + 3*( ( $year+4900-( 14-$month )/12 )/100 )/4; + +return ( $r**$n )* + ( pi**( $n/2 ) )/ + ( + sqrt(pi)* + factorial( 2*( int( $n/2 ) )+2 )/ + factorial( int( $n/2 )+1 )/ + ( 4**( int( $n/2 )+1 ) ) ); + +$root=-$b+sqrt( $b*$b-4.*$a*$c )/( 2.*$a ); diff --git a/t/snippets/expect/misc_tests.def b/t/snippets/expect/misc_tests.def new file mode 100644 index 00000000..cac0a128 --- /dev/null +++ b/t/snippets/expect/misc_tests.def @@ -0,0 +1,5 @@ +for ( @a = @$ap, $u = shift @a ; @a ; $u = $v ) { ... } # test -sfs +$i = 1; # test -sts +$i = 0; ## =1; test -ssc +; # test -ndsm +my ( $a, $b, $c ) = @_; # test -nsak="my for" diff --git a/t/snippets/expect/misc_tests.misc_tests b/t/snippets/expect/misc_tests.misc_tests new file mode 100644 index 00000000..4be7e2fb --- /dev/null +++ b/t/snippets/expect/misc_tests.misc_tests @@ -0,0 +1,8 @@ +for( @a = @$ap, $u = shift @a ; @a ; $u = $v ) { ... } # test -sfs +$i = 1 ; # test -sts +$i = 0 ; ## =1; test -ssc +; +; +; +; # test -ndsm +my( $a, $b, $c ) = @_ ; # test -nsak="my for" diff --git a/t/snippets/expect/outdent.def b/t/snippets/expect/outdent.def new file mode 100644 index 00000000..3437dfae --- /dev/null +++ b/t/snippets/expect/outdent.def @@ -0,0 +1,8 @@ + # test -nola -okw + my $i; + LOOP: while ( $i = ) { + chomp($i); + next unless $i; + fixit($i); + } + diff --git a/t/snippets/expect/outdent.outdent1 b/t/snippets/expect/outdent.outdent1 new file mode 100644 index 00000000..0952f6e5 --- /dev/null +++ b/t/snippets/expect/outdent.outdent1 @@ -0,0 +1,8 @@ + # test -nola -okw + my $i; + LOOP: while ( $i = ) { + chomp($i); + next unless $i; + fixit($i); + } + diff --git a/t/snippets/expect/sbq.def b/t/snippets/expect/sbq.def new file mode 100644 index 00000000..2671c31f --- /dev/null +++ b/t/snippets/expect/sbq.def @@ -0,0 +1,2 @@ + $str1 = \"string1"; + $str2 = \ 'string2'; diff --git a/t/snippets/expect/sbq.sbq0 b/t/snippets/expect/sbq.sbq0 new file mode 100644 index 00000000..38fb8e04 --- /dev/null +++ b/t/snippets/expect/sbq.sbq0 @@ -0,0 +1,2 @@ + $str1 = \"string1"; + $str2 = \'string2'; diff --git a/t/snippets/expect/sbq.sbq2 b/t/snippets/expect/sbq.sbq2 new file mode 100644 index 00000000..da731752 --- /dev/null +++ b/t/snippets/expect/sbq.sbq2 @@ -0,0 +1,2 @@ + $str1 = \ "string1"; + $str2 = \ 'string2'; diff --git a/t/snippets/expect/tightness.def b/t/snippets/expect/tightness.def new file mode 100644 index 00000000..fb1a9427 --- /dev/null +++ b/t/snippets/expect/tightness.def @@ -0,0 +1,4 @@ +if ( ( my $len_tab = length($tabstr) ) > 0 ) { } # test -pt +$width = $col[ $j + $k ] - $col[$j]; # test -sbt +$obj->{ $parsed_sql->{'table'}[0] }; # test -bt +%bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # test -bbt diff --git a/t/snippets/expect/tightness.tightness1 b/t/snippets/expect/tightness.tightness1 new file mode 100644 index 00000000..9bb73598 --- /dev/null +++ b/t/snippets/expect/tightness.tightness1 @@ -0,0 +1,4 @@ +if ( ( my $len_tab = length( $tabstr ) ) > 0 ) { } # test -pt +$width = $col[ $j + $k ] - $col[ $j ]; # test -sbt +$obj->{ $parsed_sql->{ 'table' }[ 0 ] }; # test -bt +%bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # test -bbt diff --git a/t/snippets/expect/tightness.tightness2 b/t/snippets/expect/tightness.tightness2 new file mode 100644 index 00000000..a5ed1a59 --- /dev/null +++ b/t/snippets/expect/tightness.tightness2 @@ -0,0 +1,4 @@ +if ( ( my $len_tab = length($tabstr) ) > 0 ) { } # test -pt +$width = $col[ $j + $k ] - $col[$j]; # test -sbt +$obj->{ $parsed_sql->{'table'}[0] }; # test -bt +%bf = map { $_ => -M $_ } grep {/\.deb$/} dirents '.'; # test -bbt diff --git a/t/snippets/expect/tightness.tightness3 b/t/snippets/expect/tightness.tightness3 new file mode 100644 index 00000000..16c45bf8 --- /dev/null +++ b/t/snippets/expect/tightness.tightness3 @@ -0,0 +1,4 @@ +if ((my $len_tab = length($tabstr)) > 0) { } # test -pt +$width = $col[$j + $k] - $col[$j]; # test -sbt +$obj->{$parsed_sql->{'table'}[0]}; # test -bt +%bf = map {$_ => -M $_} grep {/\.deb$/} dirents '.'; # test -bbt diff --git a/t/snippets/iob.in b/t/snippets/iob.in new file mode 100644 index 00000000..181c341c --- /dev/null +++ b/t/snippets/iob.in @@ -0,0 +1,3 @@ +return "this is a descriptive error message" + if $res->is_error + or not length $data; diff --git a/t/snippets/iob.par b/t/snippets/iob.par new file mode 100644 index 00000000..0cfc705d --- /dev/null +++ b/t/snippets/iob.par @@ -0,0 +1 @@ +-iob diff --git a/t/snippets/kis.in b/t/snippets/kis.in new file mode 100644 index 00000000..c11e51c7 --- /dev/null +++ b/t/snippets/kis.in @@ -0,0 +1,2 @@ + dbmclose(%verb_delim); undef %verb_delim; + dbmclose(%expanded); undef %expanded; diff --git a/t/snippets/kis.par b/t/snippets/kis.par new file mode 100644 index 00000000..486dd1eb --- /dev/null +++ b/t/snippets/kis.par @@ -0,0 +1 @@ +-kis diff --git a/t/snippets/maths.in b/t/snippets/maths.in new file mode 100644 index 00000000..a5455080 --- /dev/null +++ b/t/snippets/maths.in @@ -0,0 +1,9 @@ +$tmp = $day - 32075 + 1461 * ( $year + 4800 - ( 14 - $month ) / 12 ) / 4 + 367 +* ( $month - 2 + ( ( 14 - $month ) / 12 ) * 12 ) / 12 - 3 * ( ( $year + 4900 - +( 14 - $month ) / 12 ) / 100 ) / 4; + +return ( $r**$n ) * ( pi**( $n / 2 ) ) / ( sqrt(pi) * factorial( 2 * ( int( $n +/ 2 ) ) + 2 ) / factorial( int( $n / 2 ) + 1 ) / ( 4**( int( $n / 2 ) + 1 ) ) +); + +$root=-$b+sqrt($b*$b-4.*$a*$c)/(2.*$a); diff --git a/t/snippets/maths1.par b/t/snippets/maths1.par new file mode 100644 index 00000000..02ae2b55 --- /dev/null +++ b/t/snippets/maths1.par @@ -0,0 +1 @@ +-bbao -nwls="= + - / *" -nwrs="= + - / *" diff --git a/t/snippets/maths2.par b/t/snippets/maths2.par new file mode 100644 index 00000000..7c8142fb --- /dev/null +++ b/t/snippets/maths2.par @@ -0,0 +1 @@ +-baao -nwls="= + - / *" -nwrs="= + - / *" diff --git a/t/snippets/misc_tests.in b/t/snippets/misc_tests.in new file mode 100644 index 00000000..0906d8c4 --- /dev/null +++ b/t/snippets/misc_tests.in @@ -0,0 +1,5 @@ +for ( @a = @$ap, $u = shift @a; @a; $u = $v ) { ... } # test -sfs +$i = 1 ; # test -sts +$i = 0; ## =1; test -ssc +;;;; # test -ndsm +my ( $a, $b, $c ) = @_; # test -nsak="my for" diff --git a/t/snippets/misc_tests.par b/t/snippets/misc_tests.par new file mode 100644 index 00000000..0903f616 --- /dev/null +++ b/t/snippets/misc_tests.par @@ -0,0 +1 @@ +-sts -ssc -sfs -nsak="my for" -ndsm diff --git a/t/snippets/outdent.in b/t/snippets/outdent.in new file mode 100644 index 00000000..b76a6f9d --- /dev/null +++ b/t/snippets/outdent.in @@ -0,0 +1,8 @@ +# test -nola -okw + my $i; + LOOP: while ( $i = ) { + chomp($i); + next unless $i; + fixit($i); + } + diff --git a/t/snippets/outdent1.par b/t/snippets/outdent1.par new file mode 100644 index 00000000..e2ba7631 --- /dev/null +++ b/t/snippets/outdent1.par @@ -0,0 +1 @@ +-nola -okw diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 776266de..87fc4ae7 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -177,6 +177,7 @@ ../snippets18.t wn7.wn ../snippets18.t wn8.def ../snippets18.t wn8.wn +../snippets18.t comments.comments5 ../snippets2.t angle.def ../snippets2.t arrows1.def ../snippets2.t arrows2.def @@ -337,4 +338,28 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def -../snippets18.t comments.comments5 +../snippets18.t braces.braces1 +../snippets18.t braces.braces2 +../snippets18.t braces.braces3 +../snippets18.t braces.def +../snippets18.t csc.csc1 +../snippets18.t csc.csc2 +../snippets18.t csc.def +../snippets18.t iob.def +../snippets18.t iob.iob +../snippets18.t kis.def +../snippets18.t kis.kis +../snippets18.t maths.def +../snippets18.t maths.maths1 +../snippets18.t maths.maths2 +../snippets18.t misc_tests.def +../snippets19.t misc_tests.misc_tests +../snippets19.t outdent.def +../snippets19.t outdent.outdent1 +../snippets19.t sbq.def +../snippets19.t sbq.sbq0 +../snippets19.t sbq.sbq2 +../snippets19.t tightness.def +../snippets19.t tightness.tightness1 +../snippets19.t tightness.tightness2 +../snippets19.t tightness.tightness3 diff --git a/t/snippets/sbq.in b/t/snippets/sbq.in new file mode 100644 index 00000000..3835503c --- /dev/null +++ b/t/snippets/sbq.in @@ -0,0 +1,2 @@ + $str1=\"string1"; + $str2=\ 'string2'; diff --git a/t/snippets/sbq0.par b/t/snippets/sbq0.par new file mode 100644 index 00000000..052483ef --- /dev/null +++ b/t/snippets/sbq0.par @@ -0,0 +1 @@ +-sbq=0 diff --git a/t/snippets/sbq2.par b/t/snippets/sbq2.par new file mode 100644 index 00000000..d288fee0 --- /dev/null +++ b/t/snippets/sbq2.par @@ -0,0 +1 @@ +-sbq=2 diff --git a/t/snippets/tightness.in b/t/snippets/tightness.in new file mode 100644 index 00000000..61a6e407 --- /dev/null +++ b/t/snippets/tightness.in @@ -0,0 +1,4 @@ +if (( my $len_tab = length( $tabstr ) ) > 0) { } # test -pt +$width = $col[ $j + $k ] - $col[ $j ]; # test -sbt +$obj->{ $parsed_sql->{ 'table' }[0] }; # test -bt +%bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # test -bbt diff --git a/t/snippets/tightness1.par b/t/snippets/tightness1.par new file mode 100644 index 00000000..50bcda09 --- /dev/null +++ b/t/snippets/tightness1.par @@ -0,0 +1 @@ +-pt=0 -sbt=0 -bt=0 -bbt=0 diff --git a/t/snippets/tightness2.par b/t/snippets/tightness2.par new file mode 100644 index 00000000..bb6c411c --- /dev/null +++ b/t/snippets/tightness2.par @@ -0,0 +1,2 @@ +-pt=1 -sbt=1 -bt=1 -bbt=1 + diff --git a/t/snippets/tightness3.par b/t/snippets/tightness3.par new file mode 100644 index 00000000..a672acf4 --- /dev/null +++ b/t/snippets/tightness3.par @@ -0,0 +1,2 @@ +-pt=2 -sbt=2 -bt=2 -bbt=2 + diff --git a/t/snippets17.t b/t/snippets17.t index c9cddd74..ae38fd88 100644 --- a/t/snippets17.t +++ b/t/snippets17.t @@ -38,10 +38,10 @@ BEGIN { ########################################### $rparams = { 'bos' => "-bos", - 'comments1' => "-fpsc=40 -iscl -nibc", + 'comments1' => "-fpsc=40 -iscl -nibc -nhsc -ssc", 'comments2' => "-msc=10 -dbc -dp", - 'comments3' => "-mbl=2", - 'comments4' => "-kbl=2", + 'comments3' => "-mbl=2 -isbc", + 'comments4' => "-kbl=2 -nolc -osbc", 'def' => "", 'long_line' => "-l=0", 'pbp' => "-pbp -nst -nse", @@ -78,16 +78,35 @@ sub macro_get_names { # # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment - local(%name)=(); +##local(%name); # a static block comment without indentation + local(%name)=(); ## a static side comment to test -ssc + + # a spaced block comment to test -isbc for (0..$ #mac_ver) { + # a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[$idx{$mac_exti[$_]}]; + $vmsfile =~ s/;[\d\-]*$//; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } + @month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec'); + + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + + # A blank line interrupts the hsc's; this is a block comment + +} # side comments at different indentation levels should not normally be aligned { { { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } } #end level 4 @@ -96,6 +115,15 @@ sub macro_get_names { # } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + + # some blank lines follow @@ -254,22 +282,45 @@ ok IsWindow($c_sub_khwnd), 'IsWindow works on the client'; #!/usr/bin/perl -w # an initial hash bang line cannot be deleted with -dp sub length { return length( $_[0] ) } # side comment - # hanging side comment - # very longgggggggggggggggggggggggggggggggggggggggggggggggggggg hanging side comment + +# hanging side comment +# very longgggggggggggggggggggggggggggggggggggggggggggggggggggg hanging side comment # side comments following open brace are not currently treated as hanging side comments sub macro_get_names { # # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment - local (%name) = (); +##local(%name); # a static block comment without indentation + local (%name) = (); ## a static side comment to test -ssc + +# a spaced block comment to test -isbc for ( 0 .. $#mac_ver ) { + +# a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$//; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', +## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec' +); + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + +# This is a hanging side comment +# And so is this + +# A blank line interrupts the hsc's; this is a block comment + +} + # side comments at different indentation levels should not normally be aligned { { @@ -281,6 +332,14 @@ sub macro_get_names { # } # end level 2 } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + # some blank lines follow =pod @@ -311,23 +370,47 @@ sub length { return length( $_[0] ) } # side comment # very longgggggggggggggggggggggggggggggggggggggggggggggggggggg hanging side comment sub macro_get_names { # - local (%name) = (); + local (%name) = (); ## a static side comment to test -ssc + for ( 0 .. $#mac_ver ) { $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$// + ; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + 'Nov', 'Dec' +); + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + +} + { { { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } - } #end level 4 + } #end level 4 } # end level 3 } # end level 2 } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + __END__ @@ -352,30 +435,62 @@ sub length { return length( $_[0] ) } # side comment # side comments following open brace are not currently treated as hanging side comments sub macro_get_names { # - # - # %name = macro_get_names(); (key=macrohandle, value=macroname) - # -##local(%name); # a static block comment - local (%name) = (); +# +# %name = macro_get_names(); (key=macrohandle, value=macroname) +# +##local(%name); # a static block comment without indentation + local (%name) = (); ## a static side comment to test -ssc + + # a spaced block comment to test -isbc for ( 0 .. $#mac_ver ) { + +# a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$// + ; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec' +); + + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + + # A blank line interrupts the hsc's; this is a block comment + +} + # side comments at different indentation levels should not normally be aligned { { { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } - } #end level 4 + } #end level 4 } # end level 3 } # end level 2 } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + + # some blank lines follow @@ -413,16 +528,38 @@ sub macro_get_names { # # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment - local (%name) = (); +##local(%name); # a static block comment without indentation + local (%name) = (); ## a static side comment to test -ssc + + # a spaced block comment to test -isbc for ( 0 .. $#mac_ver ) { + + # a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$// + ; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec' +); + + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + + # A blank line interrupts the hsc's; this is a block comment + +} # side comments at different indentation levels should not normally be aligned { @@ -430,12 +567,21 @@ sub macro_get_names { # { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } - } #end level 4 + } #end level 4 } # end level 3 } # end level 2 } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + + # some blank lines follow @@ -475,25 +621,55 @@ sub macro_get_names { # # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment - local (%name) = (); +##local(%name); # a static block comment without indentation + local (%name) = (); ## a static side comment to test -ssc + + # a spaced block comment to test -isbc for ( 0 .. $#mac_ver ) { + +# a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$// + ; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec' +); + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + + # A blank line interrupts the hsc's; this is a block comment + +} + # side comments at different indentation levels should not normally be aligned { { { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } - } #end level 4 + } #end level 4 } # end level 3 } # end level 2 } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + # some blank lines follow =pod diff --git a/t/snippets18.t b/t/snippets18.t index 30d7ae35..89f78edf 100644 --- a/t/snippets18.t +++ b/t/snippets18.t @@ -5,6 +5,21 @@ #2 wn8.def #3 wn8.wn #4 comments.comments5 +#5 braces.braces1 +#6 braces.braces2 +#7 braces.braces3 +#8 braces.def +#9 csc.csc1 +#10 csc.csc2 +#11 csc.def +#12 iob.def +#13 iob.iob +#14 kis.def +#15 kis.kis +#16 maths.def +#17 maths.maths1 +#18 maths.maths2 +#19 misc_tests.def # To locate test #13 you can search for its name or the string '#13' @@ -22,9 +37,22 @@ BEGIN { # BEGIN SECTION 1: Parameter combinations # ########################################### $rparams = { - 'comments5' => "-dsc", + 'braces1' => "-bl -asbl", + 'braces2' => "-sbl", + 'braces3' => "-bli", + 'comments5' => "-dsc -nsbc", + 'csc1' => "-csc -csci=2 -cscb", + 'csc2' => "-dcsc", 'def' => "", - 'wn' => "-wn", + 'iob' => "-iob", + 'kis' => "-kis", + 'maths1' => <<'----------', +-bbao -nwls="= + - / *" -nwrs="= + - / *" +---------- + 'maths2' => <<'----------', +-baao -nwls="= + - / *" -nwrs="= + - / *" +---------- + 'wn' => "-wn", }; ############################ @@ -32,6 +60,21 @@ BEGIN { ############################ $rsources = { + 'braces' => <<'----------', +sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } +} + +$myfun = sub { + print("Hello, World\n"); +}; +---------- + 'comments' => <<'----------', #!/usr/bin/perl -w # an initial hash bang line cannot be deleted with -dp @@ -44,16 +87,35 @@ sub macro_get_names { # # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment - local(%name)=(); +##local(%name); # a static block comment without indentation + local(%name)=(); ## a static side comment to test -ssc + + # a spaced block comment to test -isbc for (0..$ #mac_ver) { + # a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[$idx{$mac_exti[$_]}]; + $vmsfile =~ s/;[\d\-]*$//; # very long side comment; Clip off version number; we can use a newer version as well + } %name; } + @month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec'); + + +{ # this side comment will not align + my $IGNORE = 0; # This is a side comment + # This is a hanging side comment + # And so is this + + # A blank line interrupts the hsc's; this is a block comment + +} # side comments at different indentation levels should not normally be aligned { { { { { ${msg} = "Hello World!"; print "My message: ${msg}\n"; } } #end level 4 @@ -62,6 +124,15 @@ sub macro_get_names { # } # end level 1 +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + + # some blank lines follow @@ -83,6 +154,48 @@ Some pod after __END__ to delete with -dp =cut +---------- + + 'csc' => <<'----------', + sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } + } ## end sub message +---------- + + 'iob' => <<'----------', +return "this is a descriptive error message" + if $res->is_error + or not length $data; +---------- + + 'kis' => <<'----------', + dbmclose(%verb_delim); undef %verb_delim; + dbmclose(%expanded); undef %expanded; +---------- + + 'maths' => <<'----------', +$tmp = $day - 32075 + 1461 * ( $year + 4800 - ( 14 - $month ) / 12 ) / 4 + 367 +* ( $month - 2 + ( ( 14 - $month ) / 12 ) * 12 ) / 12 - 3 * ( ( $year + 4900 - +( 14 - $month ) / 12 ) / 100 ) / 4; + +return ( $r**$n ) * ( pi**( $n / 2 ) ) / ( sqrt(pi) * factorial( 2 * ( int( $n +/ 2 ) ) + 2 ) / factorial( int( $n / 2 ) + 1 ) / ( 4**( int( $n / 2 ) + 1 ) ) +); + +$root=-$b+sqrt($b*$b-4.*$a*$c)/(2.*$a); +---------- + + 'misc_tests' => <<'----------', +for ( @a = @$ap, $u = shift @a; @a; $u = $v ) { ... } # test -sfs +$i = 1 ; # test -sts +$i = 0; ## =1; test -ssc +;;;; # test -ndsm +my ( $a, $b, $c ) = @_; # test -nsak="my for" ---------- 'wn7' => <<'----------', @@ -202,14 +315,34 @@ sub macro_get_names { # # %name = macro_get_names(); (key=macrohandle, value=macroname) # -##local(%name); # a static block comment + ##local(%name); # a static block comment without indentation local (%name) = (); + + # a spaced block comment to test -isbc for ( 0 .. $#mac_ver ) { + +# a very long comment for testing the parameter --nooutdent-long-comments (or -nolc) $name{$_} = $mac_ext[ $idx{ $mac_exti[$_] } ]; + $vmsfile =~ s/;[\d\-]*$//; + } %name; } +@month_of_year = ( + 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', + + ## 'Dec', 'Nov' [a static block comment with indentation] + 'Nov', 'Dec' +); + +{ + my $IGNORE = 0; + + # A blank line interrupts the hsc's; this is a block comment + +} + # side comments at different indentation levels should not normally be aligned { { @@ -221,6 +354,14 @@ sub macro_get_names { } } +#<<< do not let perltidy touch this + my @list = (1, + 1, 1, + 1, 2, 1, + 1, 3, 3, 1, + 1, 4, 6, 4, 1,); +#>>> + # some blank lines follow =pod @@ -240,6 +381,252 @@ Some pod after __END__ to delete with -dp #4........... }, + + 'braces.braces1' => { + source => "braces", + params => "braces1", + expect => <<'#5...........', +sub message +{ + if ( !defined( $_[0] ) ) + { + print("Hello, World\n"); + } + else + { + print( $_[0], "\n" ); + } +} + +$myfun = sub +{ + print("Hello, World\n"); +}; +#5........... + }, + + 'braces.braces2' => { + source => "braces", + params => "braces2", + expect => <<'#6...........', +sub message +{ + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } +} + +$myfun = sub { + print("Hello, World\n"); +}; +#6........... + }, + + 'braces.braces3' => { + source => "braces", + params => "braces3", + expect => <<'#7...........', +sub message + { + if ( !defined( $_[0] ) ) + { + print("Hello, World\n"); + } + else + { + print( $_[0], "\n" ); + } + } + +$myfun = sub { + print("Hello, World\n"); +}; +#7........... + }, + + 'braces.def' => { + source => "braces", + params => "def", + expect => <<'#8...........', +sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } +} + +$myfun = sub { + print("Hello, World\n"); +}; +#8........... + }, + + 'csc.csc1' => { + source => "csc", + params => "csc1", + expect => <<'#9...........', + sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } ## end if ( !defined( $_[0] )) + else { + print( $_[0], "\n" ); + } ## end else [ if ( !defined( $_[0] ))] + } ## end sub message +#9........... + }, + + 'csc.csc2' => { + source => "csc", + params => "csc2", + expect => <<'#10...........', + sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } + } +#10........... + }, + + 'csc.def' => { + source => "csc", + params => "def", + expect => <<'#11...........', + sub message { + if ( !defined( $_[0] ) ) { + print("Hello, World\n"); + } + else { + print( $_[0], "\n" ); + } + } ## end sub message +#11........... + }, + + 'iob.def' => { + source => "iob", + params => "def", + expect => <<'#12...........', +return "this is a descriptive error message" + if $res->is_error + or not length $data; +#12........... + }, + + 'iob.iob' => { + source => "iob", + params => "iob", + expect => <<'#13...........', +return "this is a descriptive error message" + if $res->is_error or not length $data; +#13........... + }, + + 'kis.def' => { + source => "kis", + params => "def", + expect => <<'#14...........', + dbmclose(%verb_delim); + undef %verb_delim; + dbmclose(%expanded); + undef %expanded; +#14........... + }, + + 'kis.kis' => { + source => "kis", + params => "kis", + expect => <<'#15...........', + dbmclose(%verb_delim); undef %verb_delim; + dbmclose(%expanded); undef %expanded; +#15........... + }, + + 'maths.def' => { + source => "maths", + params => "def", + expect => <<'#16...........', +$tmp = + $day - 32075 + + 1461 * ( $year + 4800 - ( 14 - $month ) / 12 ) / 4 + + 367 * ( $month - 2 + ( ( 14 - $month ) / 12 ) * 12 ) / 12 - + 3 * ( ( $year + 4900 - ( 14 - $month ) / 12 ) / 100 ) / 4; + +return ( $r**$n ) * + ( pi**( $n / 2 ) ) / + ( + sqrt(pi) * + factorial( 2 * ( int( $n / 2 ) ) + 2 ) / + factorial( int( $n / 2 ) + 1 ) / + ( 4**( int( $n / 2 ) + 1 ) ) ); + +$root = -$b + sqrt( $b * $b - 4. * $a * $c ) / ( 2. * $a ); +#16........... + }, + + 'maths.maths1' => { + source => "maths", + params => "maths1", + expect => <<'#17...........', +$tmp + =$day-32075 + +1461*( $year+4800-( 14-$month )/12 )/4 + +367*( $month-2+( ( 14-$month )/12 )*12 )/12 + -3*( ( $year+4900-( 14-$month )/12 )/100 )/4; + +return ( $r**$n ) + *( pi**( $n/2 ) ) + /( + sqrt(pi) + *factorial( 2*( int( $n/2 ) )+2 ) + /factorial( int( $n/2 )+1 ) + /( 4**( int( $n/2 )+1 ) ) ); + +$root=-$b+sqrt( $b*$b-4.*$a*$c )/( 2.*$a ); +#17........... + }, + + 'maths.maths2' => { + source => "maths", + params => "maths2", + expect => <<'#18...........', +$tmp= + $day-32075+ + 1461*( $year+4800-( 14-$month )/12 )/4+ + 367*( $month-2+( ( 14-$month )/12 )*12 )/12- + 3*( ( $year+4900-( 14-$month )/12 )/100 )/4; + +return ( $r**$n )* + ( pi**( $n/2 ) )/ + ( + sqrt(pi)* + factorial( 2*( int( $n/2 ) )+2 )/ + factorial( int( $n/2 )+1 )/ + ( 4**( int( $n/2 )+1 ) ) ); + +$root=-$b+sqrt( $b*$b-4.*$a*$c )/( 2.*$a ); +#18........... + }, + + 'misc_tests.def' => { + source => "misc_tests", + params => "def", + expect => <<'#19...........', +for ( @a = @$ap, $u = shift @a ; @a ; $u = $v ) { ... } # test -sfs +$i = 1; # test -sts +$i = 0; ## =1; test -ssc +; # test -ndsm +my ( $a, $b, $c ) = @_; # test -nsak="my for" +#19........... + }, }; my $ntests = 0 + keys %{$rtests}; diff --git a/t/snippets19.t b/t/snippets19.t new file mode 100644 index 00000000..38f229a5 --- /dev/null +++ b/t/snippets19.t @@ -0,0 +1,259 @@ +# Created with: ./make_t.pl + +# Contents: +#1 misc_tests.misc_tests +#2 outdent.def +#3 outdent.outdent1 +#4 sbq.def +#5 sbq.sbq0 +#6 sbq.sbq2 +#7 tightness.def +#8 tightness.tightness1 +#9 tightness.tightness2 +#10 tightness.tightness3 + +# To locate test #13 you can search for its name or the string '#13' + +use strict; +use Test; +use Carp; +use Perl::Tidy; +my $rparams; +my $rsources; +my $rtests; + +BEGIN { + + ########################################### + # BEGIN SECTION 1: Parameter combinations # + ########################################### + $rparams = { + 'def' => "", + 'misc_tests' => <<'----------', +-sts -ssc -sfs -nsak="my for" -ndsm +---------- + 'outdent1' => "-nola -okw", + 'sbq0' => "-sbq=0", + 'sbq2' => "-sbq=2", + 'tightness1' => "-pt=0 -sbt=0 -bt=0 -bbt=0", + 'tightness2' => <<'----------', +-pt=1 -sbt=1 -bt=1 -bbt=1 + +---------- + 'tightness3' => <<'----------', +-pt=2 -sbt=2 -bt=2 -bbt=2 + +---------- + }; + + ############################ + # BEGIN SECTION 2: Sources # + ############################ + $rsources = { + + 'misc_tests' => <<'----------', +for ( @a = @$ap, $u = shift @a; @a; $u = $v ) { ... } # test -sfs +$i = 1 ; # test -sts +$i = 0; ## =1; test -ssc +;;;; # test -ndsm +my ( $a, $b, $c ) = @_; # test -nsak="my for" +---------- + + 'outdent' => <<'----------', +# test -nola -okw + my $i; + LOOP: while ( $i = ) { + chomp($i); + next unless $i; + fixit($i); + } + +---------- + + 'sbq' => <<'----------', + $str1=\"string1"; + $str2=\ 'string2'; +---------- + + 'tightness' => <<'----------', +if (( my $len_tab = length( $tabstr ) ) > 0) { } # test -pt +$width = $col[ $j + $k ] - $col[ $j ]; # test -sbt +$obj->{ $parsed_sql->{ 'table' }[0] }; # test -bt +%bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # test -bbt +---------- + }; + + #################################### + # BEGIN SECTION 3: Expected output # + #################################### + $rtests = { + + 'misc_tests.misc_tests' => { + source => "misc_tests", + params => "misc_tests", + expect => <<'#1...........', +for( @a = @$ap, $u = shift @a ; @a ; $u = $v ) { ... } # test -sfs +$i = 1 ; # test -sts +$i = 0 ; ## =1; test -ssc +; +; +; +; # test -ndsm +my( $a, $b, $c ) = @_ ; # test -nsak="my for" +#1........... + }, + + 'outdent.def' => { + source => "outdent", + params => "def", + expect => <<'#2...........', + # test -nola -okw + my $i; + LOOP: while ( $i = ) { + chomp($i); + next unless $i; + fixit($i); + } + +#2........... + }, + + 'outdent.outdent1' => { + source => "outdent", + params => "outdent1", + expect => <<'#3...........', + # test -nola -okw + my $i; + LOOP: while ( $i = ) { + chomp($i); + next unless $i; + fixit($i); + } + +#3........... + }, + + 'sbq.def' => { + source => "sbq", + params => "def", + expect => <<'#4...........', + $str1 = \"string1"; + $str2 = \ 'string2'; +#4........... + }, + + 'sbq.sbq0' => { + source => "sbq", + params => "sbq0", + expect => <<'#5...........', + $str1 = \"string1"; + $str2 = \'string2'; +#5........... + }, + + 'sbq.sbq2' => { + source => "sbq", + params => "sbq2", + expect => <<'#6...........', + $str1 = \ "string1"; + $str2 = \ 'string2'; +#6........... + }, + + 'tightness.def' => { + source => "tightness", + params => "def", + expect => <<'#7...........', +if ( ( my $len_tab = length($tabstr) ) > 0 ) { } # test -pt +$width = $col[ $j + $k ] - $col[$j]; # test -sbt +$obj->{ $parsed_sql->{'table'}[0] }; # test -bt +%bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # test -bbt +#7........... + }, + + 'tightness.tightness1' => { + source => "tightness", + params => "tightness1", + expect => <<'#8...........', +if ( ( my $len_tab = length( $tabstr ) ) > 0 ) { } # test -pt +$width = $col[ $j + $k ] - $col[ $j ]; # test -sbt +$obj->{ $parsed_sql->{ 'table' }[ 0 ] }; # test -bt +%bf = map { $_ => -M $_ } grep { /\.deb$/ } dirents '.'; # test -bbt +#8........... + }, + + 'tightness.tightness2' => { + source => "tightness", + params => "tightness2", + expect => <<'#9...........', +if ( ( my $len_tab = length($tabstr) ) > 0 ) { } # test -pt +$width = $col[ $j + $k ] - $col[$j]; # test -sbt +$obj->{ $parsed_sql->{'table'}[0] }; # test -bt +%bf = map { $_ => -M $_ } grep {/\.deb$/} dirents '.'; # test -bbt +#9........... + }, + + 'tightness.tightness3' => { + source => "tightness", + params => "tightness3", + expect => <<'#10...........', +if ((my $len_tab = length($tabstr)) > 0) { } # test -pt +$width = $col[$j + $k] - $col[$j]; # test -sbt +$obj->{$parsed_sql->{'table'}[0]}; # test -bt +%bf = map {$_ => -M $_} grep {/\.deb$/} dirents '.'; # test -bbt +#10........... + }, + }; + + 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 ) { + if ($err) { + print STDERR +"This error received calling Perl::Tidy with '$sname' + '$pname'\n"; + ok( !$err ); + } + if ($stderr_string) { + print STDERR "---------------------\n"; + print STDERR "<>\n$stderr_string\n"; + print STDERR "---------------------\n"; + print STDERR +"This error received calling Perl::Tidy with '$sname' + '$pname'\n"; + ok( !$stderr_string ); + } + if ($errorfile_string) { + print STDERR "---------------------\n"; + print STDERR "<<.ERR file>>\n$errorfile_string\n"; + print STDERR "---------------------\n"; + print STDERR +"This error received calling Perl::Tidy with '$sname' + '$pname'\n"; + ok( !$errorfile_string ); + } + } + else { + ok( $output, $expect ); + } +}