logo       

4099 - trunk/Template/tests/scripts [eZComponents: Trunk]: msg#00269

web.ezcomponents.cvs

Subject: 4099 - trunk/Template/tests/scripts [eZComponents: Trunk]

Author: Jan Borsodi
Date: 2006-11-28 11:13:15 +0100 (Tue, 28 Nov 2006)
New Revision: 4099

Log:
- Fixed directory creation in permutation system.
- Fixed {case} entries in block_wrong permutation test.
- Fixed .out file for block_wrong tests.
- Added permutation for single-line blocks with text in front and after (no
space).

Added:
trunk/Template/tests/scripts/permutation_block_prepost.php
Modified:
trunk/Template/tests/scripts/permutation.php
trunk/Template/tests/scripts/permutation_block_wrong.php

Modified: trunk/Template/tests/scripts/permutation.php
===================================================================
--- trunk/Template/tests/scripts/permutation.php 2006-11-28 09:31:56 UTC
(rev 4098)
+++ trunk/Template/tests/scripts/permutation.php 2006-11-28 10:13:15 UTC
(rev 4099)
@@ -228,11 +228,6 @@
$this->outputToFile = true;
}
}
-
- if ( $this->outputToFile && !file_exists( $dir ) )
- {
- mkdir( $dir, 0777, true );
- }
}

public function store( $content, $file = false )
@@ -242,6 +237,11 @@

if ( $this->outputToFile )
{
+ if ( !file_exists( dirname( $file ) ) )
+ {
+ mkdir( dirname( $file ), 0777, true );
+ }
+
echo "Writing to ", $file, "\n";
file_put_contents( $file, $content );
}
@@ -258,7 +258,12 @@
{
if ( $this->fd === false )
{
- $this->fd = fopen( $this->dir . '/' . $this->file, "w" );
+ $file = $this->dir . '/' . $this->file;
+ if ( !file_exists( dirname( $file ) ) )
+ {
+ mkdir( dirname( $file ), 0777, true );
+ }
+ $this->fd = fopen( $file, "w" );
}
fwrite( $this->fd, $content );
}

Added: trunk/Template/tests/scripts/permutation_block_prepost.php
===================================================================
--- trunk/Template/tests/scripts/permutation_block_prepost.php 2006-11-28
09:31:56 UTC (rev 4098)
+++ trunk/Template/tests/scripts/permutation_block_prepost.php 2006-11-28
10:13:15 UTC (rev 4099)
@@ -0,0 +1,79 @@
+<?php
+
+require_once dirname( __FILE__ ) . "/permutation.php";
+
+// Writes to: regression_tests/blocks/incorrect/block_mangled_pre_post_*.in
+
+$preText = alt( "a",
+ "_"
+ );
+$blockNames = alt( "var",
+ "cycle",
+ "use",
+ "increment",
+ "decrement",
+ "reset",
+ "return"
+ );
+
+/*$blocksStartEnd = perm( $blocksStart,
+ "\n {\$foo}\n",
+ $blocksEnd,
+ "\n"
+ );
+
+$blocksNested = alt( perm( "{foreach \$array as \$bar}\n",
+ altI( ' ', clone $blocksStartEnd ),
+ "{/foreach}\n"
+ ) );*/
+
+$preList = perm( clone $blockNames,
+ clone $preText
+ );
+
+$postList = perm( clone $preText,
+ clone $blockNames
+ );
+
+$prePostList = perm( clone $preText,
+ clone $blockNames,
+ clone $preText
+ );
+
+/*
+mock:2:2: Unknown block <var_>.
+
+{var_}
+ ^
+*/
+
+$alternatives = alt( $preList, $postList, $prePostList );
+
+$list = perm( "{",
+ $alternatives,
+ "}\n"
+ );
+
+$dir = dirname( __FILE__ ) . "/../regression_tests/";
+
+$a = app( "", $argv );
+
+$i = 1;
+do
+{
+ $num = sprintf( "%04d", $i );
+ $str = $list->generate();
+ $fileIn = $dir . "blocks/incorrect/block_mangled_pre_post_" . $num .
".in";
+ $fileOut = $dir . "blocks/incorrect/block_mangled_pre_post_" . $num .
".out";
+ $name = $alternatives->generate();
+ $a->store( "{* file: " . "non_matching_block_" . $num . ".in" . " *}\n" .
$str . "\n",
+ $fileIn );
+ $a->store( "mock:2:2: Unknown block <{$name}>.\n" .
+ "\n" .
+ "{{$name}}\n" .
+ " ^\n",
+ $fileOut );
+ ++$i;
+} while( $list->increase() );
+
+?>


Property changes on: trunk/Template/tests/scripts/permutation_block_prepost.php
___________________________________________________________________
Name: svn:eol-style
+ native

Modified: trunk/Template/tests/scripts/permutation_block_wrong.php
===================================================================
--- trunk/Template/tests/scripts/permutation_block_wrong.php 2006-11-28
09:31:56 UTC (rev 4098)
+++ trunk/Template/tests/scripts/permutation_block_wrong.php 2006-11-28
10:13:15 UTC (rev 4099)
@@ -12,7 +12,7 @@
"{elseif \$foo}",
"{else}",
"{switch \$foo}",
- "{case \$foo}",
+ "{case 5}",
"{default}"
);
$blocksEnd = alt( "",
@@ -25,24 +25,38 @@
"{/default}"
);

-$blocksStartEnd = perm( $blocksStart,
+$blocksStart1 = clone $blocksStart;
+$blocksEnd1 = clone $blocksEnd;
+
+$blocksStartEnd = perm( $blocksStart1,
"\n {\$foo}\n",
- $blocksEnd,
+ $blocksEnd1,
"\n"
);

+$blocksStart2 = clone $blocksStart;
+$blocksEnd2 = clone $blocksEnd;
+
+$blocksStartEnd2 = perm( $blocksStart2,
+ "\n {\$foo}\n",
+ $blocksEnd2,
+ "\n"
+ );
+
$blocksNested = alt( perm( "{foreach \$array as \$bar}\n",
- altI( ' ', clone $blocksStartEnd ),
+ altI( ' ', $blocksStartEnd2 ),
"{/foreach}\n"
) );

-$list = perm( alt( clone $blocksStartEnd,
- clone $blocksNested
- )
- );
+$alt = alt( $blocksStartEnd,
+ $blocksNested
+ );

-$dir = dirname( __FILE__ ) . "/regression_tests/blocks/incorrect/";
+$list = perm( $alt
+ );

+$dir = dirname( __FILE__ ) . "/../regression_tests/blocks/incorrect/";
+
$a = app( "", $argv, $dir );

$i = 1;
@@ -52,14 +66,239 @@
echo $top;
}

+$inCount = 0;
+$outCount = 0;
+
do
{
$num = sprintf( "%04d", $i );
$str = $list->generate();
- $file = $dir . "/non_matching_block_" . $num . ".in";
- $a->store( "{* file: " . "non_matching_block_" . $num . ".in" . " *}\n" .
$top . $str . "\n",
- $file );
+ $inFile = $dir . "/non_matching_block_" . $num . ".in";
+ $outFile = $dir . "/non_matching_block_" . $num . ".out";
+ $useEntry = false;
+
+ // Check for valid entries.
+ if ( $alt->index == 0 )
+ {
+ $start = $startText = $blocksStart1->generate();
+ $end = $endText = $blocksEnd1->generate();
+ }
+ elseif ( $alt->index == 1 )
+ {
+ $start = $startText = $blocksStart2->generate();
+ $end = $endText = $blocksEnd2->generate();
+// echo "s:{$start}:s\n";
+// echo "e:{$end}:e\n";
+ }
+ else
+ {
+ throw new Exception( "Unknown index {$alt->index}" );
+ }
+
+ if ( preg_match( "#^{/?([a-zA-Z0-9_]+)#", $start, $matches ) )
+ {
+ $start = $matches[1];
+ }
+ if ( preg_match( "#^{/?([a-zA-Z0-9_]+)#", $end, $matches ) )
+ {
+ $end = $matches[1];
+ }
+ if ( strcmp( $start, $end ) == 0 )
+ {
+ // Some exceptions
+ if ( $start == 'delimiter' ||
+ $start == 'switch' ||
+ $start == 'case' ||
+ $start == 'default' )
+ {
+// $useEntry = true;
+ }
+ else
+ {
+// echo "same\n";
+ }
+ }
+ else
+ {
+ $useEntry = true;
+ }
+
+ if ( $useEntry )
+ {
+ $a->store( "{* file: " . "non_matching_block_" . $num . ".in" . "
*}\n" . $top . $str . "\n",
+ $inFile );
+ ++$inCount;
+
+ if ( $alt->index == 0 )
+ {
+ // Special case 1
+ if ( $start == 'delimiter' )
+ {
+ $len = strlen( $startText );
+ $name = ucfirst( $start );
+ $a->store( "mock:3:{$len}: Delimiter can only be used inside a
foreach block.\n" .
+ "\n" .
+ "{$startText}\n" .
+ str_repeat( " ", $len - 1 ) . "^\n",
+ $outFile );
+ ++$outCount;
+ }
+ // Special case 2
+ elseif ( $start == 'elseif' ||
+ $start == 'else' )
+ {
+ $len = strlen( $start ) + 1 + 1;
+ $a->store( "mock:3:{$len}: Unexpected block {{$start}} at this
position. Some blocks can only be used inside other blocks.\n" .
+ "\n" .
+ "{$startText}\n" .
+ str_repeat( " ", $len - 1 ) . "^\n",
+ $outFile );
+ ++$outCount;
+ }
+ // Special case 3
+ elseif ( $start == 'switch' )
+ {
+ $a->store( "mock:4:5: Expecting an case block.\n" .
+ "\n" .
+ " {\$foo}\n" .
+ " ^\n",
+ $outFile );
+ ++$outCount;
+ }
+ // Special case 4
+ elseif ( $start == 'case' ||
+ $start == 'default' )
+ {
+ if ( $end == "aaa" )
+ {
+// $len = strlen( $startText ) + 1;
+ $a->store( /*"mock:3:7: Expecting a literal.\n" .
+ "\n" .
+ "{case 5}\n" .
+ " ^\n",*/
+ "Incorrect nesting in code, close block {/{$start}}
expected.\n" .
+ "\n" .
+ " {\$foo}\n" .
+ "\n" .
+ "\n" .
+ "\n" .
+ "^\n",
+ /*"mock:3:{$len}: Unexpected block {{$start}} at this
position. Some blocks can only be used inside other blocks.\n" .
+ "\n" .
+ "{$startText}\n" .
+ str_repeat( " ", $len - 1 ) . "^\n",*/
+ $outFile );
+ }
+ else
+ {
+ $len = strlen( $start ) + 1 + 1;
+ $a->store( "mock:3:{$len}: Unexpected block {{$start}} at
this position. Some blocks can only be used inside other blocks.\n" .
+ "\n" .
+ "{$startText}\n" .
+ str_repeat( " ", $len - 1 ) . "^\n",
+ $outFile );
+ }
+ ++$outCount;
+ }
+ elseif ( $start == '' )
+ {
+ $len = strlen( $endText ) + 1;
+ $a->store( "mock:5:{$len}: Found closing block {/{$end}}
without an opening block.\n" .
+ "\n" .
+ "{$endText}\n" .
+ str_repeat( " ", $len - 1 ) . "^\n",
+ $outFile );
+ ++$outCount;
+ }
+ elseif ( $end == '' )
+ {
+ $a->store( "mock:7:1: Incorrect nesting in code, close block
{/{$start}} expected.\n" .
+ "\n" .
+ " {\$foo}\n" .
+ "\n" .
+ "\n" .
+ "\n" .
+ "^\n",
+ $outFile );
+ ++$outCount;
+ }
+ else
+ {
+ $len = strlen( $endText ) + 1;
+ $a->store( "mock:5:{$len}: Open and close block do not match:
{{$start}} and {/{$end}}\n" .
+ "\n" .
+ "{$endText}\n" .
+ str_repeat( " ", $len - 1 ) . "^\n",
+ $outFile );
+ ++$outCount;
+ }
+ }
+ elseif ( $alt->index == 1 )
+ {
+ // Special case 1
+ if ( $start == '' &&
+ $end == 'foreach' )
+ {
+ $a->store( "mock:7:11: Found closing block {/foreach} without
an opening block.\n" .
+ "\n" .
+ "{/foreach}\n" .
+ " ^\n",
+ $outFile );
+ ++$outCount;
+ }
+ // Special case 2
+ elseif ( $start == 'foreach' &&
+ $end == '' )
+ {
+ // TODO: consider better error message for this one since EOF
+ // is reached and there is a block still open
+ $a->store( "mock:9:1: Incorrect nesting in code, close block
{/foreach} expected.\n" .
+ "\n" .
+ "{/foreach}\n" .
+ "\n" .
+ "\n" .
+ "^\n",
+ $outFile );
+ ++$outCount;
+ }
+ elseif ( $start == '' )
+ {
+ $len = strlen( $endText ) + 4 + 1; // 4 is for the indentation
+ $a->store( "mock:6:{$len}: Open and close block do not match:
{foreach} and {/{$end}}\n" .
+ "\n" .
+ " {$endText}\n" .
+ str_repeat( " ", $len - 1 ) . "^\n",
+ $outFile );
+ ++$outCount;
+ }
+ elseif ( $end == '' )
+ {
+ // Matches hardcoded {/foreach} so the text is nearly static
+ $a->store( "mock:7:11: Open and close block do not match:
{{$start}} and {/foreach}\n" .
+ "\n" .
+ "{/foreach}\n" .
+ " ^\n",
+ $outFile );
+ ++$outCount;
+ }
+ else
+ {
+ $len = strlen( $endText ) + 4 + 1; // 4 is for the indentation
+ $a->store( "mock:6:{$len}: Open and close block do not match:
{{$start}} and {/{$end}}\n" .
+ "\n" .
+ " {$endText}\n" .
+ str_repeat( " ", $len - 1 ) . "^\n",
+ $outFile );
+ ++$outCount;
+ }
+ }
+ }
++$i;
} while( $list->increase() );

+if ( $inCount != $outCount )
+{
+ throw new Exception( ".in count ({$inCount}) does not match .out count
({$outCount})" );
+}
+
?>



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise