protected function Twig_Tests_LexerTest::countToken

1 call to Twig_Tests_LexerTest::countToken()
Twig_Tests_LexerTest::testBracketsNesting in drupal/core/vendor/twig/twig/test/Twig/Tests/LexerTest.php

File

drupal/core/vendor/twig/twig/test/Twig/Tests/LexerTest.php, line 43

Class

Twig_Tests_LexerTest

Code

protected function countToken($template, $type, $value = null) {
  $lexer = new Twig_Lexer(new Twig_Environment());
  $stream = $lexer
    ->tokenize($template);
  $count = 0;
  $tokens = array();
  while (!$stream
    ->isEOF()) {
    $token = $stream
      ->next();
    if ($type === $token
      ->getType()) {
      if (null === $value || $value === $token
        ->getValue()) {
        ++$count;
      }
    }
  }
  return $count;
}