/** */ public function testAddTokenAfterFlush() { $token = Token::factory(Token::TYPE_UNESCAPED, "x", 1, "x"); $buffer = ReferenceBuffer::factory()->addToken($token)->flush()->reset(); $token = Token::factory(Token::TYPE_UNESCAPED, "y", 1, "y"); $reference = $buffer->addToken($token)->flush()->getReference(); $this->assertEquals('y', $reference->getKey(), "Incorrect reference value built from tokens added after resetting flushed buffer"); }
/** * @param int $tokenAmount * @dataProvider providerTokenAmount */ public function testNotIsEndAfterAddingToken(int $tokenAmount) { $buffer = TokenBuffer::factory(); for ($i = 0; $i < $tokenAmount; $i++) { $token = Token::factory(Token::TYPE_SLASH, "/", 1); $buffer->addToken($token); } $this->assertFalse($buffer->isEnd(), "End condition after adding token to buffer"); }
/** * @param int $tokenAmount * @dataProvider providerTokenAmount */ public function testIsEndAfterReadingAllTokensFromBuffer(int $tokenAmount) { $buffer = TokenBuffer::factory(); for ($i = 0; $i < $tokenAmount; $i++) { $token = Token::factory(Token::TYPE_SLASH, "/", 1); $buffer->addToken($token); } for ($i = 0; $i < $tokenAmount; $i++) { $buffer->readToken(); } $this->assertTrue($buffer->isEnd(), "No end condition after reading"); }
/** * @expectedException \DomainException */ public function testSettingNegativePositionThrowsSplException() { Token::factory()->setPosition(-1); }
/** */ public function testNoErrorAfterSettingNonErrorType() { $token = Token::factory()->setType(Token::TYPE_SLASH); $this->assertFalse($token->isError(), "Error in token after setting non-error type"); }
public function testReadingSameTokenAfterUnreading() { $buffer = TokenBuffer::factory(); $token = Token::factory(Token::TYPE_SLASH, "/", 1); $buffer->addToken($token); $token = Token::factory(Token::TYPE_UNESCAPED, "a", 1, "a"); $buffer->addToken($token); $firstToken = $buffer->readToken(); $secondToken = $buffer->unreadToken()->readToken(); $this->assertSame($firstToken, $secondToken, "Reading after unreading returns different tokens"); }
/** * @expectedException \LengthException */ public function testSettingEmptyTextThrowsSplException() { Token::factory()->setText(''); }
/** * @param int[] $typeList * @return Token|null * @todo Split method in two. */ protected function matchNextToken(array $typeList) { $token = null; foreach ($typeList as $type) { $text = $this->matchTokenTextAtCursor($type); if (null !== $text) { $token = Token::factory($type, $text, $this->getTextLength($text)); switch ($type) { case Token::TYPE_ESCAPED: $token->setValue($this->unescape($text)); break; case Token::TYPE_UNESCAPED: $token->setValue($text); break; } $this->advanceCursor(strlen($text)); break; } } return $token; }