N°2651 Remove lib test files from index

This commit is contained in:
Pierre Goiffon
2019-12-20 17:05:26 +01:00
parent 27a6abeeb3
commit 0d231d9b94
15 changed files with 384 additions and 0 deletions

1
.gitignore vendored
View File

@@ -20,6 +20,7 @@ test/vendor/*
/lib/**/tests/**
/lib/**/Test/**
/lib/**/Tests/**
!/lib/twig/**/Expression/Test/**
# all datas but listing prevention
/data/**

View File

@@ -0,0 +1,11 @@
<?php
use Twig\Node\Expression\Test\ConstantTest;
class_exists('Twig\Node\Expression\Test\ConstantTest');
if (\false) {
class Twig_Node_Expression_Test_Constant extends ConstantTest
{
}
}

View File

@@ -0,0 +1,11 @@
<?php
use Twig\Node\Expression\Test\DefinedTest;
class_exists('Twig\Node\Expression\Test\DefinedTest');
if (\false) {
class Twig_Node_Expression_Test_Defined extends DefinedTest
{
}
}

View File

@@ -0,0 +1,11 @@
<?php
use Twig\Node\Expression\Test\DivisiblebyTest;
class_exists('Twig\Node\Expression\Test\DivisiblebyTest');
if (\false) {
class Twig_Node_Expression_Test_Divisibleby extends DivisiblebyTest
{
}
}

View File

@@ -0,0 +1,11 @@
<?php
use Twig\Node\Expression\Test\EvenTest;
class_exists('Twig\Node\Expression\Test\EvenTest');
if (\false) {
class Twig_Node_Expression_Test_Even extends EvenTest
{
}
}

View File

@@ -0,0 +1,11 @@
<?php
use Twig\Node\Expression\Test\NullTest;
class_exists('Twig\Node\Expression\Test\NullTest');
if (\false) {
class Twig_Node_Expression_Test_Null extends NullTest
{
}
}

View File

@@ -0,0 +1,11 @@
<?php
use Twig\Node\Expression\Test\OddTest;
class_exists('Twig\Node\Expression\Test\OddTest');
if (\false) {
class Twig_Node_Expression_Test_Odd extends OddTest
{
}
}

View File

@@ -0,0 +1,11 @@
<?php
use Twig\Node\Expression\Test\SameasTest;
class_exists('Twig\Node\Expression\Test\SameasTest');
if (\false) {
class Twig_Node_Expression_Test_Sameas extends SameasTest
{
}
}

View File

@@ -0,0 +1,51 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Node\Expression\Test;
use Twig\Compiler;
use Twig\Node\Expression\TestExpression;
/**
* Checks if a variable is the exact same value as a constant.
*
* {% if post.status is constant('Post::PUBLISHED') %}
* the status attribute is exactly the same as Post::PUBLISHED
* {% endif %}
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class ConstantTest extends TestExpression
{
public function compile(Compiler $compiler)
{
$compiler
->raw('(')
->subcompile($this->getNode('node'))
->raw(' === constant(')
;
if ($this->getNode('arguments')->hasNode(1)) {
$compiler
->raw('get_class(')
->subcompile($this->getNode('arguments')->getNode(1))
->raw(')."::".')
;
}
$compiler
->subcompile($this->getNode('arguments')->getNode(0))
->raw('))')
;
}
}
class_alias('Twig\Node\Expression\Test\ConstantTest', 'Twig_Node_Expression_Test_Constant');

View File

@@ -0,0 +1,71 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Node\Expression\Test;
use Twig\Compiler;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\ArrayExpression;
use Twig\Node\Expression\BlockReferenceExpression;
use Twig\Node\Expression\ConstantExpression;
use Twig\Node\Expression\FunctionExpression;
use Twig\Node\Expression\GetAttrExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Expression\TestExpression;
/**
* Checks if a variable is defined in the current context.
*
* {# defined works with variable names and variable attributes #}
* {% if foo is defined %}
* {# ... #}
* {% endif %}
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class DefinedTest extends TestExpression
{
public function __construct(\Twig_NodeInterface $node, $name, \Twig_NodeInterface $arguments = null, $lineno)
{
if ($node instanceof NameExpression) {
$node->setAttribute('is_defined_test', true);
} elseif ($node instanceof GetAttrExpression) {
$node->setAttribute('is_defined_test', true);
$this->changeIgnoreStrictCheck($node);
} elseif ($node instanceof BlockReferenceExpression) {
$node->setAttribute('is_defined_test', true);
} elseif ($node instanceof FunctionExpression && 'constant' === $node->getAttribute('name')) {
$node->setAttribute('is_defined_test', true);
} elseif ($node instanceof ConstantExpression || $node instanceof ArrayExpression) {
$node = new ConstantExpression(true, $node->getTemplateLine());
} else {
throw new SyntaxError('The "defined" test only works with simple variables.', $lineno);
}
parent::__construct($node, $name, $arguments, $lineno);
}
protected function changeIgnoreStrictCheck(GetAttrExpression $node)
{
$node->setAttribute('ignore_strict_check', true);
if ($node->getNode('node') instanceof GetAttrExpression) {
$this->changeIgnoreStrictCheck($node->getNode('node'));
}
}
public function compile(Compiler $compiler)
{
$compiler->subcompile($this->getNode('node'));
}
}
class_alias('Twig\Node\Expression\Test\DefinedTest', 'Twig_Node_Expression_Test_Defined');

View File

@@ -0,0 +1,38 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Node\Expression\Test;
use Twig\Compiler;
use Twig\Node\Expression\TestExpression;
/**
* Checks if a variable is divisible by a number.
*
* {% if loop.index is divisible by(3) %}
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class DivisiblebyTest extends TestExpression
{
public function compile(Compiler $compiler)
{
$compiler
->raw('(0 == ')
->subcompile($this->getNode('node'))
->raw(' % ')
->subcompile($this->getNode('arguments')->getNode(0))
->raw(')')
;
}
}
class_alias('Twig\Node\Expression\Test\DivisiblebyTest', 'Twig_Node_Expression_Test_Divisibleby');

View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Node\Expression\Test;
use Twig\Compiler;
use Twig\Node\Expression\TestExpression;
/**
* Checks if a number is even.
*
* {{ var is even }}
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class EvenTest extends TestExpression
{
public function compile(Compiler $compiler)
{
$compiler
->raw('(')
->subcompile($this->getNode('node'))
->raw(' % 2 == 0')
->raw(')')
;
}
}
class_alias('Twig\Node\Expression\Test\EvenTest', 'Twig_Node_Expression_Test_Even');

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Node\Expression\Test;
use Twig\Compiler;
use Twig\Node\Expression\TestExpression;
/**
* Checks that a variable is null.
*
* {{ var is none }}
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class NullTest extends TestExpression
{
public function compile(Compiler $compiler)
{
$compiler
->raw('(null === ')
->subcompile($this->getNode('node'))
->raw(')')
;
}
}
class_alias('Twig\Node\Expression\Test\NullTest', 'Twig_Node_Expression_Test_Null');

View File

@@ -0,0 +1,37 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Node\Expression\Test;
use Twig\Compiler;
use Twig\Node\Expression\TestExpression;
/**
* Checks if a number is odd.
*
* {{ var is odd }}
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class OddTest extends TestExpression
{
public function compile(Compiler $compiler)
{
$compiler
->raw('(')
->subcompile($this->getNode('node'))
->raw(' % 2 == 1')
->raw(')')
;
}
}
class_alias('Twig\Node\Expression\Test\OddTest', 'Twig_Node_Expression_Test_Odd');

View File

@@ -0,0 +1,36 @@
<?php
/*
* This file is part of Twig.
*
* (c) Fabien Potencier
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Twig\Node\Expression\Test;
use Twig\Compiler;
use Twig\Node\Expression\TestExpression;
/**
* Checks if a variable is the same as another one (=== in PHP).
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class SameasTest extends TestExpression
{
public function compile(Compiler $compiler)
{
$compiler
->raw('(')
->subcompile($this->getNode('node'))
->raw(' === ')
->subcompile($this->getNode('arguments')->getNode(0))
->raw(')')
;
}
}
class_alias('Twig\Node\Expression\Test\SameasTest', 'Twig_Node_Expression_Test_Sameas');