[svn:parrot] r39601 - branches/cindent/t/codingstd
jkeenan at svn.parrot.org
jkeenan at svn.parrot.org
Wed Jun 17 02:13:23 UTC 2009
Author: jkeenan
Date: Wed Jun 17 02:13:22 2009
New Revision: 39601
URL: https://trac.parrot.org/parrot/changeset/39601
Log:
Consolidate 6 variables into a hash for ease in debugging.
Modified:
branches/cindent/t/codingstd/c_indent.t
Modified: branches/cindent/t/codingstd/c_indent.t
==============================================================================
--- branches/cindent/t/codingstd/c_indent.t Wed Jun 17 02:02:04 2009 (r39600)
+++ branches/cindent/t/codingstd/c_indent.t Wed Jun 17 02:13:22 2009 (r39601)
@@ -6,6 +6,7 @@
use warnings;
use lib qw( . lib ../lib ../../lib );
+use Data::Dumper;$Data::Dumper::Indent=1;
use Test::More tests => 2;
use Parrot::Distribution;
@@ -49,25 +50,27 @@
or die "Can not open '$path' for reading!\n";
@source = <$IN>;
- my @stack; # for tracking indention level
- my $line_cnt = 0;
- my $block_indent = undef;
- my $prev_last_char = '';
- my $last_char = '';
- my $in_comment = 0;
+ my %state = (
+ stack => [],
+ line_cnt => 0,
+ block_indent => undef,
+ prev_last_char => '',
+ last_char => '',
+ in_comment => 0,
+ );
foreach (@source) {
- $line_cnt++;
+ $state{line_cnt}++;
next unless defined $_;
chomp;
- $prev_last_char = $last_char;
- $last_char = substr( $_, -1, 1 );
+ $state{prev_last_char} = $state{last_char};
+ $state{last_char} = substr( $_, -1, 1 );
# ignore multi-line comments (except the first line)
- $in_comment = 0, next if $in_comment && m{\*/} && $' !~ m{/\*};
- next if $in_comment;
- $in_comment = 1 if m{/\*} && $' !~ m{\*/};
+ $state{in_comment} = 0, next if $state{in_comment} && m{\*/} && $' !~ m{/\*};
+ next if $state{in_comment};
+ $state{in_comment} = 1 if m{/\*} && $' !~ m{\*/};
## preprocessor scan
if (
@@ -81,14 +84,14 @@
next if (m/PARROT_IN_CORE|_GUARD/);
next if (m/__cplusplus/);
- my $indent = q{ } x @stack;
+ my $indent = q{ } x @{ $state{stack} };
if ( $1 ne $indent ) {
- push @pp_indent => "$path:$line_cnt\n"
+ push @pp_indent => "$path:$state{line_cnt}\n"
. " got: $_"
. "expected: #$indent$2 $3'\n";
$pp_failed{"$path\n"} = 1;
}
- push @stack, "#$2 $3";
+ push @{ $state{stack} }, "#$2 $3";
next;
}
if (
@@ -101,12 +104,12 @@
# stay where we are, but indenting should be
# back even with the opening brace.
- my $indent = q{ } x ( @stack - 1 );
+ my $indent = q{ } x ( @{ $state{stack} } - 1 );
if ( $1 ne $indent ) {
- push @pp_indent => "$path:$line_cnt\n"
+ push @pp_indent => "$path:$state{line_cnt}\n"
. " got: $_"
. "expected: #$indent$2 -- it's inside of "
- . ( join ' > ', @stack ) . "\n";
+ . ( join ' > ', @{ $state{stack} } ) . "\n";
$pp_failed{"$path\n"} = 1;
}
next;
@@ -118,18 +121,18 @@
/x
)
{
- my $indent = q{ } x ( @stack - 1 );
+ my $indent = q{ } x ( @{ $state{stack} } - 1 );
if ( $1 ne $indent ) {
- push @pp_indent => "$path:$line_cnt\n"
+ push @pp_indent => "$path:$state{line_cnt}\n"
. " got: $_"
. "expected: #$indent$2 -- it's inside of "
- . ( join ' > ', @stack ) . "\n";
+ . ( join ' > ', @{ $state{stack} } ) . "\n";
$pp_failed{"$path\n"} = 1;
}
- pop @stack;
+ pop @{ $state{stack} };
next;
}
- next unless @stack;
+ next unless @{ $state{stack} };
if (
m/ ^ \s* \#
@@ -139,12 +142,12 @@
)
{
next if (m/ASSERT_ARGS_/); # autogenerated by headerizer
- my $indent = q{ } x (@stack);
+ my $indent = q{ } x (@{ $state{stack} });
if ( $1 ne $indent ) {
- push @pp_indent => "$path:$line_cnt\n"
+ push @pp_indent => "$path:$state{line_cnt}\n"
. " got: $_"
. "expected: #$indent$2 -- it's inside of "
- . ( join ' > ', @stack ) . "\n";
+ . ( join ' > ', @{ $state{stack} } ) . "\n";
$pp_failed{"$path\n"} = 1;
}
next;
@@ -158,34 +161,34 @@
if (/^(\s*).*\{\s*$/) {
# note the beginning of a block, and its indent depth.
- $block_indent = length($1);
+ $state{block_indent} = length($1);
next;
}
if (/^\s*([\#\}])/) {
# skip the last line of the func or cpp directives.
- $block_indent = undef if ( $1 eq "}" );
+ $state{block_indent} = undef if ( $1 eq "}" );
next;
}
- if ( defined($block_indent) ) {
+ if ( defined($state{block_indent}) ) {
# first line of a block
- if ( $block_indent == 0 ) {
+ if ( $state{block_indent} == 0 ) {
# first line of a top-level block (first line of a function,
# in other words)
my ($indent) = /^(\s*)/;
if ( length($indent) != 4 ) {
- push @c_indent => "$path:$line_cnt\n"
+ push @c_indent => "$path:$state{line_cnt}\n"
. " apparent non-4 space indenting ("
. length($indent)
. " spaces)\n";
$c_failed{"$path\n"} = 1;
}
}
- $block_indent = undef;
+ $state{block_indent} = undef;
}
my ($indent) = /^(\s+)/ or next;
@@ -197,8 +200,8 @@
# The indentation of the previous line is not considered.
# Check sanity by verifying that the indentation of the current line
# is divisible by four.
- if ( $indent % 4 && !$in_comment && $prev_last_char eq ';' ) {
- push @c_indent => "$path:$line_cnt\n"
+ if ( $indent % 4 && !$state{in_comment} && $state{prev_last_char} eq ';' ) {
+ push @c_indent => "$path:$state{line_cnt}\n"
. " apparent non-4 space indenting ($indent space"
. ( $indent == 1 ? '' : 's' ) . ")\n";
$c_failed{"$path\n"} = 1;
More information about the parrot-commits
mailing list