MyDSL/tests/Reader/StringReaderTest.php
2020-12-18 18:12:47 +08:00

55 lines
1.6 KiB
PHP

<?php
/**
* @filename StringReaderTest.php
* @author Jerry Yan <792602257@qq.com>
* @date 2020/12/18 12:19
*/
namespace JerryYan\DSL\Test\Reader;
use JerryYan\DSL\Reader\StringReader;
use PHPUnit\Framework\TestCase;
class StringReaderTest extends TestCase
{
protected $readerWithCn;
protected $reader;
protected function setUp(): void
{
$this->reader = new StringReader(" Ahhh This Is 一个 新的 TOken");
$this->readerWithCn = new StringReader(" 中文 这是 Is 一个 新的 TOken");
}
public function testGetNextChar()
{
$this->reader->reset();
$this->assertEquals('A', $this->reader->getNextChar(), "不匹配");
$this->readerWithCn->reset();
$this->assertEquals('中', $this->readerWithCn->getNextChar(), "不匹配");
}
public function testGetCurrentToken()
{
$this->reader->reset();
$this->assertEquals('Ahhh', $this->reader->getCurrentToken(), "不匹配");
$this->readerWithCn->reset();
$this->assertEquals('中文', $this->readerWithCn->getCurrentToken(), "不匹配");
}
/**
* @author Jerry Yan <792602257@qq.com>
* @date 2020/12/18 14:16
* @depends testGetNextChar
* @depends testGetCurrentToken
*/
public function testMoveToNextToken()
{
$this->reader->reset();
$this->reader->moveToNextToken();
$this->assertEquals('This', $this->reader->getCurrentToken(), "不匹配");
$this->readerWithCn->reset();
$this->readerWithCn->moveToNextToken();
$this->assertEquals('这是', $this->readerWithCn->getCurrentToken(), "不匹配");
}
}