logo       

4109 - in trunk/Template/tests: regression_tests regression_tests/array_fet: msg#00281

web.ezcomponents.cvs

Subject: 4109 - in trunk/Template/tests: regression_tests regression_tests/array_fetch regression_tests/array_fetch/correct scripts [eZComponents: Trunk]

Author: Jan Borsodi
Date: 2006-11-28 14:57:08 +0100 (Tue, 28 Nov 2006)
New Revision: 4109

Log:
- Fixed a special case in wrong block output generation.
- Added tests for array indexing.

Added:
trunk/Template/tests/regression_tests/array_fetch/
trunk/Template/tests/regression_tests/array_fetch/correct/
trunk/Template/tests/regression_tests/array_fetch/correct/comments.in
trunk/Template/tests/regression_tests/array_fetch/correct/comments.out
trunk/Template/tests/regression_tests/array_fetch/correct/indexes.in
trunk/Template/tests/regression_tests/array_fetch/correct/indexes.out
trunk/Template/tests/scripts/permutation_array_fetch.php
trunk/Template/tests/scripts/permutation_array_fetch_comments.php
Modified:
trunk/Template/tests/scripts/permutation.php
trunk/Template/tests/scripts/permutation_block_wrong.php

Added: trunk/Template/tests/regression_tests/array_fetch/correct/comments.in
===================================================================
--- trunk/Template/tests/regression_tests/array_fetch/correct/comments.in
2006-11-28 13:51:37 UTC (rev 4108)
+++ trunk/Template/tests/regression_tests/array_fetch/correct/comments.in
2006-11-28 13:57:08 UTC (rev 4109)
@@ -0,0 +1,46 @@
+{var $a = array( 0 => 'foo' )}
+{$a[0]}
+{$a[0 ]}
+{$a[0
+]}
+{$a[0/*c*/]}
+{$a[0//c
+]}
+{$a[ 0]}
+{$a[ 0 ]}
+{$a[ 0
+]}
+{$a[ 0/*c*/]}
+{$a[ 0//c
+]}
+{$a[
+0]}
+{$a[
+0 ]}
+{$a[
+0
+]}
+{$a[
+0/*c*/]}
+{$a[
+0//c
+]}
+{$a[/*c*/0]}
+{$a[/*c*/0 ]}
+{$a[/*c*/0
+]}
+{$a[/*c*/0/*c*/]}
+{$a[/*c*/0//c
+]}
+{$a[//c
+0]}
+{$a[//c
+0 ]}
+{$a[//c
+0
+]}
+{$a[//c
+0/*c*/]}
+{$a[//c
+0//c
+]}

Added: trunk/Template/tests/regression_tests/array_fetch/correct/comments.out
===================================================================
--- trunk/Template/tests/regression_tests/array_fetch/correct/comments.out
2006-11-28 13:51:37 UTC (rev 4108)
+++ trunk/Template/tests/regression_tests/array_fetch/correct/comments.out
2006-11-28 13:57:08 UTC (rev 4109)
@@ -0,0 +1,25 @@
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo
+foo

Added: trunk/Template/tests/regression_tests/array_fetch/correct/indexes.in
===================================================================
--- trunk/Template/tests/regression_tests/array_fetch/correct/indexes.in
2006-11-28 13:51:37 UTC (rev 4108)
+++ trunk/Template/tests/regression_tests/array_fetch/correct/indexes.in
2006-11-28 13:57:08 UTC (rev 4109)
@@ -0,0 +1,16 @@
+{var $a = array( 0 => array( 1 => array( 2 => 'foo' ) ) )}
+{$a[0]}
+{$a[0][1]}
+{$a[0] [1]}
+{$a[0]
+[1]}
+{$a[0]/*c*/[1]}
+{$a[0]//c
+[1]}
+{$a[0][1][2]}
+{$a[0][1] [2]}
+{$a[0][1]
+[2]}
+{$a[0][1]/*c*/[2]}
+{$a[0][1]//c
+[2]}

Added: trunk/Template/tests/regression_tests/array_fetch/correct/indexes.out
===================================================================
--- trunk/Template/tests/regression_tests/array_fetch/correct/indexes.out
2006-11-28 13:51:37 UTC (rev 4108)
+++ trunk/Template/tests/regression_tests/array_fetch/correct/indexes.out
2006-11-28 13:57:08 UTC (rev 4109)
@@ -0,0 +1,11 @@
+Array
+Array
+Array
+Array
+Array
+Array
+foo
+foo
+foo
+foo
+foo

Modified: trunk/Template/tests/scripts/permutation.php
===================================================================
--- trunk/Template/tests/scripts/permutation.php 2006-11-28 13:51:37 UTC
(rev 4108)
+++ trunk/Template/tests/scripts/permutation.php 2006-11-28 13:57:08 UTC
(rev 4109)
@@ -69,25 +69,40 @@
$lines = preg_split( "#(\r\n|\r|\n)#", $text, -1,
PREG_SPLIT_DELIM_CAPTURE );
for ( $i = 0; $i < count( $lines ); $i += 2 )
{
- if ( $i == count( $lines ) - 1 )
+ if ( $i == count( $lines ) - 1 &&
+ strlen( $lines[$i] ) == 0 )
continue;
$lines[$i] = $indentation . $lines[$i];
}
return implode( "", $lines );
}
+
+ static function column( $text )
+ {
+ $lines = preg_split( "#(\r\n|\r|\n)#", $text, -1,
PREG_SPLIT_DELIM_CAPTURE );
+ for ( $i = 0; $i < count( $lines ); $i += 2 )
+ {
+ if ( $i == count( $lines ) - 1 )
+ break;
+ }
+ $c = strlen( $lines[$i] );
+ return $c;
+ }
}

class ezcTemplatePermutationList extends ezcTemplatePermutation
{
- public function __construct( $list = null )
+ public function __construct( $list = null, $indentation = '' )
{
parent::__construct();
$this->list = $list;
+ $this->indentation = $indentation;
}

public function generate()
{
- return self::generateString( $this->list );
+ return self::indentBlock( self::generateString( $this->list ),
+ $this->indentation );
}

public function increase()
@@ -272,6 +287,20 @@
echo $content;
}
}
+
+ public function close()
+ {
+ if ( $this->outputToFile )
+ {
+ if ( $this->fd === false )
+ {
+ throw new Exception( "File has not yet been opened" );
+ }
+ echo "Writing to ", $this->dir . "/" . $this->file, "\n";
+ fclose( $this->fd );
+ $this->fd = false;
+ }
+ }
}

function app( $file, $args, $dir = false )
@@ -285,6 +314,13 @@
return new ezcTemplatePermutationList( $args );
}

+function permI()
+{
+ $args = func_get_args();
+ $indent = array_shift( $args );
+ return new ezcTemplatePermutationList( $args, $indent );
+}
+
function alt()
{
$args = func_get_args();

Added: trunk/Template/tests/scripts/permutation_array_fetch.php
===================================================================
--- trunk/Template/tests/scripts/permutation_array_fetch.php 2006-11-28
13:51:37 UTC (rev 4108)
+++ trunk/Template/tests/scripts/permutation_array_fetch.php 2006-11-28
13:57:08 UTC (rev 4109)
@@ -0,0 +1,78 @@
+<?php
+
+require_once dirname( __FILE__ ) . "/permutation.php";
+
+// Writes to: regression_tests/array_fetch/correct/indexes.in
+
+$ws = alt( "", " ", "\n" );
+$comment = alt( "/*c*/", "//c\n" );
+$wsComment = alt( clone $ws, clone $comment, clone $ws );
+$comments = alt( clone $ws, clone $comment/*, clone $wsComment*/ ) ;
+
+$indexPre = perm( "[1]",
+ clone $comments,
+ "[]",
+ clone $comments );
+
+$indexPost = perm( "[2]" );
+
+$entry1 = alt( "",
+ perm( clone $comments,
+ "[1]" ),
+ perm( "[1]",
+ clone $comments,
+ "[2]" ),
+ perm( $indexPre,
+ $indexPost )
+ );
+
+$var = perm( "{\$a[0]" );
+
+$fetch = perm( $var,
+ $entry1,
+ "}"
+ );
+
+$list = perm( $fetch,
+ "\n"
+ );
+
+
+$a = app( "array_fetch/correct/indexes.in", $argv );
+
+$top = "{var \$a = array( 0 => array( 1 => array( 2 => 'foo' ) ) )}\n";
+$a->output( $top );
+$i = 1;
+$out = '';
+$map = array( 0 => "Array\n",
+ 1 => "Array\n",
+ 2 => "foo\n",
+ 3 => '' );
+do
+{
+ $num = sprintf( "%04d", $i );
+ $str = $list->generate();
+ if ( $entry1->index == 3 )
+ {
+ $a->store( "{* file: indexes_{$num}.in *}\n" . $top . $str,
+ $a->dir . "/array_fetch/incorrect/indexes_{$num}.in" );
+/* $text = $fetch->generate();
+ $len = strlen( $text );
+ $a->store( "mock:3:{$len}: Unexpected array append '[]'. Did you
forget an expresssion between the brackets?\n" .
+ "\n" .
+ "{$text}\n" .
+ str_repeat( " ", ezcTemplatePermutation::column(
$var->generate() . $indexPre->generate() ) ) . "^\n",
+ $a->dir . "/array_fetch/incorrect/indexes_{$num}.out" );*/
+ }
+ else
+ {
+ $a->output( $str );
+ }
+ $out .= $map[$entry1->index];
+ ++$i;
+} while( $list->increase() );
+$a->close();
+$a->store( $out,
+ $a->dir . "/array_fetch/correct/indexes.out" );
+
+?>


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

Added: trunk/Template/tests/scripts/permutation_array_fetch_comments.php
===================================================================
--- trunk/Template/tests/scripts/permutation_array_fetch_comments.php
2006-11-28 13:51:37 UTC (rev 4108)
+++ trunk/Template/tests/scripts/permutation_array_fetch_comments.php
2006-11-28 13:57:08 UTC (rev 4109)
@@ -0,0 +1,34 @@
+<?php
+
+require_once dirname( __FILE__ ) . "/permutation.php";
+
+// Writes to: regression_tests/array_fetch/correct/comments.in
+
+$ws = alt( "", " \t", "\n" );
+$comment = alt( "/*c*/", "//c\n" );
+$wsComment = alt( clone $ws, clone $comment, clone $ws );
+$comments = alt( clone $ws, clone $comment/*, clone $wsComment*/ ) ;
+
+$list = perm( "{\$a[",
+ clone $comments,
+ '0',
+ clone $comments,
+ "]}\n"
+ );
+
+
+$a = app( "array_fetch/correct/comments.in", $argv );
+
+$a->output( "{var \$a = array( 0 => 'foo' )}\n" );
+$i = 0;
+do
+{
+ $str = $list->generate();
+ $a->output( $str );
+ ++$i;
+} while( $list->increase() );
+$a->close();
+$a->store( str_repeat( "foo\n", $i ),
+ $a->dir . "/array_fetch/correct/comments.out" );
+
+?>


Property changes on:
trunk/Template/tests/scripts/permutation_array_fetch_comments.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
13:51:37 UTC (rev 4108)
+++ trunk/Template/tests/scripts/permutation_block_wrong.php 2006-11-28
13:57:08 UTC (rev 4109)
@@ -261,6 +261,28 @@
$outFile );
++$outCount;
}
+ // Special case 3
+ elseif ( $start == 'elseif' ||
+ $start == 'else' )
+ {
+ $len = strlen( $start ) + 1 + 1 + 4; // 4 is for the identation
+ $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 4
+ elseif ( $start == 'switch' )
+ {
+ $a->store( "mock:5:9: Expecting an case block.\n" .
+ "\n" .
+ " {\$foo}\n" .
+ " ^\n",
+ $outFile );
+ ++$outCount;
+ }
elseif ( $start == '' )
{
$len = strlen( $endText ) + 4 + 1; // 4 is for the indentation



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

News | FAQ | advertise