Skip to content

Commit

Permalink
test mason syntax inside comments on %-lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jonswar committed Oct 4, 2012
1 parent 5ce44f5 commit b1ed497
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
15 changes: 8 additions & 7 deletions lib/Mason/Tidy.pm
Expand Up @@ -87,8 +87,8 @@ method tidy_method ($source) {

# Hide <% %> and <& &>
#
while ( $source =~ s/($open_block_regex.*?<\/%\2>)/$self->replace_with_marker($1)/se ) { }
while ( $source =~ s/(<(%|&\|?)(?!perl).*?\2>)/$self->replace_with_marker($1)/se ) { }
while ( $source =~ s/($open_block_regex.*?<\/%\2>)/$self->replace_with_marker($1)/se ) { }
while ( $source =~ s/(<(%|&\|?)(?![A-Za-z]+>).*?\2>)/$self->replace_with_marker($1)/se ) { }

my @lines = split( /\n/, $source, -1 );
pop(@lines) if @lines && $lines[-1] eq '';
Expand Down Expand Up @@ -196,9 +196,10 @@ method tidy_method ($source) {
#
my @replacements;
undef pos($final);
while ( $final =~ /$open_block_regex[\t ]*\n?/mg ) {
my ( $block_type, $block_args ) = ( $1, $2 );
my $start_pos = pos($final);
while ( $final =~ /^(.*)$open_block_regex[\t ]*\n?/mg ) {
my ( $preceding, $block_type, $block_args ) = ( $1, $2, $3 );
next if length($preceding) > 0 && substr( $preceding, 0, 1 ) eq '%';
my $start_pos = pos($final) + length($preceding);
if ( $final =~ /(\n?[\t ]*<\/%$block_type>)/g ) {
my $length = pos($final) - $start_pos - length($1);
my $untidied_block_contents = substr( $final, $start_pos, $length );
Expand Down Expand Up @@ -277,7 +278,7 @@ method handle_block ($block_type, $block_args, $block_contents) {
}

method replace_with_perl_comment ($obj) {
return "# " . $self->replace_with_marker($obj);
return "# _LINE_" . $self->replace_with_marker($obj);
}

method replace_with_marker ($obj) {
Expand All @@ -288,7 +289,7 @@ method replace_with_marker ($obj) {

method marker_in_line ($line) {
my $marker_prefix = $self->_marker_prefix;
if ( my ($marker) = ( $line =~ /(${marker_prefix}_\d+)/ ) ) {
if ( my ($marker) = ( $line =~ /_LINE_(${marker_prefix}_\d+)/ ) ) {
return $marker;
}
return undef;
Expand Down
20 changes: 6 additions & 14 deletions lib/Mason/Tidy/t/Basic.pm
Expand Up @@ -72,20 +72,8 @@ if ($foo) {
sub test_mixed_sections : Tests {
tidy(
desc => 'method',
source => '
<%method foo>
%if ( $foo) {
content
%}
</%method>
',
expect => '
<%method foo>
% if ($foo) {
content
% }
</%method>
'
source => '<%method foo>\n%if ( $foo) {\ncontent\n%}\n</%method>\n',
expect => '<%method foo>\n% if ($foo) {\ncontent\n% }\n</%method>\n'
);
}

Expand Down Expand Up @@ -161,6 +149,10 @@ $d => "foo"
}

sub test_perl_lines_and_perl_blocks : Tests {
tidy(
desc => 'perl lines with commented out tags',
source => '% # <%init>\n% # <% $foo %>\n% # <& "foo" &>\n'
);
tidy(
desc => 'perl lines',
source => '
Expand Down

0 comments on commit b1ed497

Please sign in to comment.