How to use isEof method of Token class

Best Gherkin-php code snippet using Token.isEof

CachingStreamTest.php

Source:CachingStreamTest.php Github

copy

Full Screen

1<?php2namespace Tests\Polygen\Integration\Stream;3use ArrayIterator;4use Mockery;5use Polygen\Language\Lexing\Lexer;6use Polygen\Language\Lexing\Matching\MatchedToken;7use Polygen\Language\Lexing\Position;8use Polygen\Language\Token\Token;9use Polygen\Stream\CachingStream;10use Polygen\Stream\TokenStream;11use Polygen\Stream\TokenStreamInterface;12use Tests\TestCase;13class CachingStreamTest extends TestCase14{15 /**16 * @test17 */18 public function it_knows_when_it_is_at_the_end_of_the_stream_if_it_never_read_it()19 {20 $subject = new CachingStream($this->given_a_token_stream([]));21 $this->assertTrue($subject->isEOF());22 }23 /**24 * @test25 */26 public function it_throws_an_exception_when_seeking_past_the_end_of_the_cache()27 {28 $subject = new CachingStream(29 $this->given_a_token_stream(30 [31 Token::terminatingSymbol('1'),32 Token::terminatingSymbol('2'),33 Token::terminatingSymbol('3'),34 ]35 )36 );37 $this->expectExceptionMessage('Can\'t seek ahead of the cache.');38 $subject->seek(2);39 }40 public function it_throws_an_exception_when_advancing_past_the_end_of_the_stream()41 {42 $subject = new CachingStream(43 $this->given_a_token_stream(44 [45 Token::terminatingSymbol('1'),46 ]47 )48 );49 $subject->advance();50 $this->expectExceptionMessage('Trying to read past the end of the stream.');51 $subject->advance();52 }53 /**54 * @test55 */56 public function it_does_not_advance_when_calling_nextToken()57 {58 $subject = new CachingStream(59 $this->given_a_token_stream(60 [61 Token::terminatingSymbol('1'),62 Token::terminatingSymbol('2'),63 Token::terminatingSymbol('3'),64 ]65 )66 );67 $this->assertEquals(68 new MatchedToken(69 Token::terminatingSymbol('1'),70 $this->given_a_position()71 ),72 $subject->nextToken()73 );74 $this->assertEquals(75 new MatchedToken(76 Token::terminatingSymbol('1'),77 $this->given_a_position()78 ),79 $subject->nextToken()80 );81 $this->assertEquals(82 new MatchedToken(83 Token::terminatingSymbol('1'),84 $this->given_a_position()85 ),86 $subject->nextToken()87 );88 $subject->advance();89 $this->assertEquals(90 new MatchedToken(91 Token::terminatingSymbol('2'),92 $this->given_a_position()93 ),94 $subject->nextToken()95 );96 }97 /**98 * @test99 */100 public function it_knows_when_it_is_at_the_end_of_the_stream_when_it_gets_there()101 {102 $subject = new CachingStream(103 $this->given_a_token_stream(104 [105 Token::terminatingSymbol('blah'),106 Token::terminatingSymbol('blah'),107 Token::terminatingSymbol('blah'),108 ]109 )110 );111 $this->assertFalse($subject->isEOF());112 $subject->advance();113 $this->assertFalse($subject->isEOF());114 $subject->advance();115 $this->assertTrue($subject->isEOF());116 }117 /**118 * @test119 */120 public function it_can_advance()121 {122 $subject = new CachingStream(123 $this->given_a_token_stream(124 [125 Token::terminatingSymbol('1'),126 Token::terminatingSymbol('2'),127 Token::terminatingSymbol('3'),128 ]129 )130 );131 $subject->advance();132 $this->assertFalse($subject->isEOF());133 $subject->advance();134 $this->assertEquals(135 new MatchedToken(136 Token::terminatingSymbol('3'),137 $this->given_a_position()138 ),139 $subject->nextToken()140 );141 $this->assertTrue($subject->isEOF());142 }143 /**144 * @test145 */146 public function it_knows_when_it_is_at_the_end_of_the_stream_after_rewinding()147 {148 $subject = new CachingStream(149 $this->given_a_token_stream(150 [151 Token::terminatingSymbol('1'),152 Token::terminatingSymbol('2'),153 Token::terminatingSymbol('3'),154 ]155 )156 );157 $this->assertFalse($subject->isEOF());158 $subject->advance();159 $this->assertFalse($subject->isEOF());160 $subject->advance();161 $this->assertTrue($subject->isEOF());162 $subject->seek(2);163 $this->assertTrue($subject->isEOF());164 $subject->seek(1);165 $this->assertFalse($subject->isEOF());166 $subject->seek(0);167 $this->assertFalse($subject->isEOF());168 $subject->advance();169 $this->assertFalse($subject->isEOF());170 $subject->advance();171 $this->assertTrue($subject->isEOF());172 }173 /**174 * @test175 */176 public function it_knows_the_offset_it_is_at()177 {178 $subject = new CachingStream(179 $this->given_a_token_stream(180 [181 Token::terminatingSymbol('1'),182 Token::terminatingSymbol('2'),183 Token::terminatingSymbol('3'),184 ]185 )186 );187 $this->assertEquals(0, $subject->tell());188 $subject->advance();189 $subject->nextToken();190 $subject->nextToken();191 $subject->nextToken();192 $this->assertEquals(1, $subject->tell());193 $subject->advance();194 $this->assertEquals(2, $subject->tell());195 $subject->seek(1);196 $this->assertEquals(1, $subject->tell());197 }198 /**199 * @test200 */201 public function it_does_not_allow_rewinding_before_the_start()202 {203 $this->expectExceptionMessage("Offset can't be negative.");204 $subject = new CachingStream($this->given_a_token_stream([Token::comment("")]));205 $subject->seek(-1);206 }207 /**208 * @test209 */210 public function it_throws_an_exception_if_passed_a_non_integer_number_to_seek()211 {212 $this->expectExceptionMessage("Offset must be an integer.");213 $subject = new CachingStream($this->given_a_token_stream([Token::comment("")]));214 $subject->seek(0.2);215 }216 /**217 * @param Token[]218 * @return TokenStreamInterface219 */220 private function given_a_token_stream(array $tokens)221 {222 return new TokenStream(223 Mockery::mock(224 Lexer::class,225 [226 'getTokens' => new ArrayIterator(227 array_map(228 function ($token)229 {230 return new MatchedToken($token, $this->given_a_position());231 },232 $tokens233 )234 ),235 ]236 )237 );238 }239 /**240 * Returns a position that is used various times in these tests.241 * @return Position242 */243 private function given_a_position()244 {245 return new Position(1, 1);246 }247}...

Full Screen

Full Screen

TokenQueueTest.php

Source:TokenQueueTest.php Github

copy

Full Screen

...32 }33 public function testIsEofAndNext()34 {35 // Token036 $this->assertFalse($this->queue->isEof());37 // Token138 $this->queue->next();39 $this->assertFalse($this->queue->isEof());40 // Token241 $this->queue->next();42 $this->assertFalse($this->queue->isEof());43 // Token344 $this->queue->next();45 $this->assertFalse($this->queue->isEof());46 // EOF47 $this->queue->next();48 $this->assertTrue($this->queue->isEof());49 }50 public function testIsEofEmptyQueue()51 {52 $queue = new TokenQueue();53 $this->assertTrue($queue->isEof());54 $queue->add(new Token(0, 'token'));55 $this->assertFalse($queue->isEof());56 }57 public function testGet()58 {59 $this->queue->reset();60 $this->assertEquals($this->token0, $this->queue->get());61 $this->assertEquals($this->token1, $this->queue->get());62 $this->assertEquals($this->token2, $this->queue->get());63 $this->assertEquals($this->token3, $this->queue->get());64 $this->assertEquals(false, $this->queue->get());65 }66 public function testGetIterator()67 {68 $this->assertEquals(69 array($this->token0, $this->token1, $this->token2, $this->token3),...

Full Screen

Full Screen

Token.php

Source:Token.php Github

copy

Full Screen

1<?php2namespace App\Core\Syntax\Token;3use App\Core\Syntax\Grammar\Terminal;4use JsonSerializable;5class Token implements JsonSerializable6{7 private $type;8 private $line;9 private $column;10 private $isEOF = false;11 private $text;12 public function __construct(TokenType $type = null)13 {14 $this->type = $type;15 }16 public static function eof()17 {18 $token = new Token();19 $token->text = '<EOF>';20 $token->isEOF = true;21 $token->type = TokenType::eoi();22 return $token;23 }24 public function getType()25 {26 return $this->type;27 }28 public function setType(TokenType $type)29 {30 $this->type = $type;31 }32 public function getColumn()33 {34 return $this->column;35 }36 public function setColumn(int $column)37 {38 $this->column = $column;39 }40 public function getLine()41 {42 return $this->line;43 }44 public function setLine(int $line)45 {46 $this->line = $line;47 }48 public function getText()49 {50 return $this->text;51 }52 public function setText(string $text)53 {54 $this->text = $text;55 }56 public function isEOF()57 {58 return $this->isEOF;59 }60 public function toTerminal()61 {62 return new Terminal($this->type);63 }64 public function jsonSerialize()65 {66 return [67 'type' => $this->type,68 'line' => $this->line,69 'column' => $this->column,70 'isEOF' => $this->isEOF,71 'text' => $this->text72 ];73 }74 public function __toString()75 {76 $txt = $this->text;77 if (isset($txt)) {78 $txt = str_replace('\n', '\\n', $txt);79 $txt = str_replace('\r', '\\r', $txt);80 $txt = str_replace('\t', '\\t', $txt);81 } else {82 $txt = '<no text>';83 }84 $typeString = strval($type);85 return "['$txt', <$typeString> $this->line:$this->column]";86 }87}...

Full Screen

Full Screen

TokenStreamTest.php

Source:TokenStreamTest.php Github

copy

Full Screen

1<?php2/*3 * This file is part of Twig.4 *5 * (c) Fabien Potencier6 *7 * For the full copyright and license information, please view the LICENSE8 * file that was distributed with this source code.9 */10use Twig\Token;11use Twig\TokenStream;12class Twig_Tests_TokenStreamTest extends \PHPUnit\Framework\TestCase13{14 protected static $tokens;15 protected function setUp()16 {17 self::$tokens = [18 new Token(Token::TEXT_TYPE, 1, 1),19 new Token(Token::TEXT_TYPE, 2, 1),20 new Token(Token::TEXT_TYPE, 3, 1),21 new Token(Token::TEXT_TYPE, 4, 1),22 new Token(Token::TEXT_TYPE, 5, 1),23 new Token(Token::TEXT_TYPE, 6, 1),24 new Token(Token::TEXT_TYPE, 7, 1),25 new Token(Token::EOF_TYPE, 0, 1),26 ];27 }28 public function testNext()29 {30 $stream = new TokenStream(self::$tokens);31 $repr = [];32 while (!$stream->isEOF()) {33 $token = $stream->next();34 $repr[] = $token->getValue();35 }36 $this->assertEquals('1, 2, 3, 4, 5, 6, 7', implode(', ', $repr), '->next() advances the pointer and returns the current token');37 }38 /**39 * @expectedException \Twig\Error\SyntaxError40 * @expectedExceptionMessage Unexpected end of template41 */42 public function testEndOfTemplateNext()43 {44 $stream = new TokenStream([45 new Token(Token::BLOCK_START_TYPE, 1, 1),46 ]);47 while (!$stream->isEOF()) {48 $stream->next();49 }50 }51 /**52 * @expectedException \Twig\Error\SyntaxError53 * @expectedExceptionMessage Unexpected end of template54 */55 public function testEndOfTemplateLook()56 {57 $stream = new TokenStream([58 new Token(Token::BLOCK_START_TYPE, 1, 1),59 ]);60 while (!$stream->isEOF()) {61 $stream->look();62 $stream->next();63 }64 }65}...

Full Screen

Full Screen

isEof

Using AI Code Generation

copy

Full Screen

1class Token {2 public $type;3 public $value;4 public function __construct($type, $value) {5 $this->type = $type;6 $this->value = $value;7 }8 public function isEof() {9 return $this->type == 'EOF';10 }11}12class Lexer {13 public $input;14 public $position;15 public $readPosition;16 public $ch;17 public function __construct($input) {18 $this->input = $input;19 $this->readChar();20 }21 public function readChar() {22 if ($this->readPosition >= strlen($this->input)) {23 $this->ch = 0;24 } else {25 $this->ch = $this->input[$this->readPosition];26 }27 $this->position = $this->readPosition;28 $this->readPosition++;29 }30 public function nextToken() {31 $tok = new Token('EOF', '');32 if ($this->ch == 0) {33 return $tok;34 }35 $tok = new Token('ILLEGAL', $this->ch);36 $this->readChar();37 return $tok;38 }39}40class Parser {41 public $l;42 public function __construct($l) {43 $this->l = $l;44 }45 public function parseProgram() {46 $program = [];47 while (!$this->l->peekToken()->isEof()) {48 $stmt = $this->parseStatement();49 if ($stmt != null) {50 $program[] = $stmt;51 }52 }53 return $program;54 }55 public function parseStatement() {56 $tok = $this->l->peekToken();57 switch ($tok->type) {58 return $this->parseLetStatement();59 return null;60 }61 }62 public function parseLetStatement() {63 $stmt = new LetStatement();64 if (!$this->expectPeek('IDENT')) {65 return null;66 }67 $stmt->name = new Identifier($this->l->curToken->value);68 if (!$this->expectPeek('=')) {69 return null;70 }71 while (!$this->curTokenIs(';')) {

Full Screen

Full Screen

isEof

Using AI Code Generation

copy

Full Screen

1$file = fopen('1.txt', 'r');2$token = new Token($file);3while(!$token->isEof()){4 $token->readNextToken();5 echo $token->getToken();6}7fclose($file);

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Gherkin-php automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in Token

Trigger isEof code on LambdaTest Cloud Grid

Execute automation tests with isEof on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful