Пример #1
0
 public function testRewind()
 {
     $stream = new Twig_TokenStream(self::$tokens, '', false);
     $this->assertEquals(2, $stream->look()->getValue(), '->look() returns the next token');
     $this->assertEquals(3, $stream->look()->getValue(), '->look() can be called several times to look more than one upcoming token');
     $this->assertEquals(4, $stream->look()->getValue(), '->look() can be called several times to look more than one upcoming token');
     $this->assertEquals(5, $stream->look()->getValue(), '->look() can be called several times to look more than one upcoming token');
     $stream->rewind();
     $repr = array();
     while (!$stream->isEOF()) {
         $token = $stream->next(false);
         $repr[] = $token->getValue();
     }
     $this->assertEquals('1, 2, 3, 4, 5, 6, 7', implode(', ', $repr), '->rewind() pushes all pushed tokens to the token array');
 }
Пример #2
0
$repr = array();
while (!$stream->isEOF()) {
    $token = $stream->next();
    $repr[] = $token->getValue();
}
$t->is(implode(', ', $repr), '1, 2, 3, 4, 5, 6, 7', '->look() pushes the token to the stack');
$stream = new Twig_TokenStream($tokens, '', false);
$t->is($stream->look()->getValue(), 2, '->look() returns the next token');
$t->is($stream->look()->getValue(), 3, '->look() can be called several times to look more than one upcoming token');
$t->is($stream->look()->getValue(), 4, '->look() can be called several times to look more than one upcoming token');
$t->is($stream->look()->getValue(), 5, '->look() can be called several times to look more than one upcoming token');
$repr = array();
while (!$stream->isEOF()) {
    $token = $stream->next();
    $repr[] = $token->getValue();
}
$t->is(implode(', ', $repr), '1, 2, 3, 4, 5, 6, 7', '->look() pushes the token to the stack');
// ->rewind()
$t->diag('->rewind()');
$stream = new Twig_TokenStream($tokens, '', false);
$t->is($stream->look()->getValue(), 2, '->look() returns the next token');
$t->is($stream->look()->getValue(), 3, '->look() can be called several times to look more than one upcoming token');
$t->is($stream->look()->getValue(), 4, '->look() can be called several times to look more than one upcoming token');
$t->is($stream->look()->getValue(), 5, '->look() can be called several times to look more than one upcoming token');
$stream->rewind();
$repr = array();
while (!$stream->isEOF()) {
    $token = $stream->next(false);
    $repr[] = $token->getValue();
}
$t->is(implode(', ', $repr), '1, 2, 3, 4, 5, 6, 7', '->rewind() pushes all pushed tokens to the token array');