FunctionNode example

 elseif ($next->isDelimiter([')'])) {
                            break;
                        } else {
                            throw SyntaxErrorException::unexpectedToken('an argument', $next);
                        }
                    }

                    if (!$arguments) {
                        throw SyntaxErrorException::unexpectedToken('at least one argument', $next);
                    }

                    $result = new Node\FunctionNode($result$identifier$arguments);
                }
            } else {
                throw SyntaxErrorException::unexpectedToken('selector', $peek);
            }
        }

        if (\count($stream->getUsed()) === $selectorStart) {
            throw SyntaxErrorException::unexpectedToken('selector', $stream->getPeek());
        }

        return [$result$pseudoElement];
    }
$xpath = $parser->parse('*')[0];
        $combinedXpath = $parser->parse('*')[0];
        $translator->addCombination('fake', $xpath$combinedXpath);
    }

    public function testAddFunctionNotExistsFunction()
    {
        $this->expectException(ExpressionErrorException::class);
        $translator = new Translator();
        $translator->registerExtension(new HtmlExtension($translator));
        $xpath = new XPathExpr();
        $function = new FunctionNode(new ElementNode(), 'fake');
        $translator->addFunction($xpath$function);
    }

    public function testAddPseudoClassNotExistsClass()
    {
        $this->expectException(ExpressionErrorException::class);
        $translator = new Translator();
        $translator->registerExtension(new HtmlExtension($translator));
        $xpath = new XPathExpr();
        $translator->addPseudoClass($xpath, 'fake');
    }

    
namespace Symfony\Component\CssSelector\Tests\Node;

use Symfony\Component\CssSelector\Node\ElementNode;
use Symfony\Component\CssSelector\Node\FunctionNode;
use Symfony\Component\CssSelector\Parser\Token;

class FunctionNodeTest extends AbstractNodeTestCase
{
    public static function getToStringConversionTestData()
    {
        return [
            [new FunctionNode(new ElementNode(), 'function'), 'Function[Element[*]:function()]'],
            [new FunctionNode(new ElementNode(), 'function', [
                new Token(Token::TYPE_IDENTIFIER, 'value', 0),
            ]), "Function[Element[*]:function(['value'])]"],
            [new FunctionNode(new ElementNode(), 'function', [
                new Token(Token::TYPE_STRING, 'value1', 0),
                new Token(Token::TYPE_NUMBER, 'value2', 0),
            ]), "Function[Element[*]:function(['value1', 'value2'])]"],
        ];
    }

    public static function getSpecificityValueTestData()
    {
case 'null':
                    case 'NULL':
                        return new Node\ConstantNode(null);

                    default:
                        if ('(' === $this->stream->current->value) {
                            if (false === isset($this->functions[$token->value])) {
                                throw new SyntaxError(sprintf('The function "%s" does not exist.', $token->value)$token->cursor, $this->stream->getExpression()$token->value, array_keys($this->functions));
                            }

                            $node = new Node\FunctionNode($token->value, $this->parseArguments());
                        } else {
                            if (!$this->lint || \is_array($this->names)) {
                                if (!\in_array($token->value, $this->names, true)) {
                                    throw new SyntaxError(sprintf('Variable "%s" is not valid.', $token->value)$token->cursor, $this->stream->getExpression()$token->value, $this->names);
                                }

                                // is the name used in the compiled code different                                 // from the name used in the expression?                                 if (\is_int($name = array_search($token->value, $this->names))) {
                                    $name = $token->value;
                                }
                            }
namespace Symfony\Component\ExpressionLanguage\Tests\Node;

use Symfony\Component\ExpressionLanguage\Node\ConstantNode;
use Symfony\Component\ExpressionLanguage\Node\FunctionNode;
use Symfony\Component\ExpressionLanguage\Node\Node;

class FunctionNodeTest extends AbstractNodeTestCase
{
    public static function getEvaluateData(): array
    {
        return [
            ['bar', new FunctionNode('foo', new Node([new ConstantNode('bar')]))[]['foo' => static::getCallables()]],
        ];
    }

    public static function getCompileData(): array
    {
        return [
            ['foo("bar")', new FunctionNode('foo', new Node([new ConstantNode('bar')]))['foo' => static::getCallables()]],
        ];
    }

    public static function getDumpData(): array
    {
Home | Imprint | This part of the site doesn't use cookies.