Source of file TokenizerPositionTest.php
Size: 4,227 Bytes - Last Modified: 2021-12-23T10:31:58+00:00
/var/www/docs.ssmods.com/process/src/thirdparty/html5lib-php/tests/HTML5/TokenizerPositionTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 | <?php require_once dirname(__FILE__) . '/../autorun.php'; class HTML5_PositionTestableTokenizer extends HTML5_TestableTokenizer { public $outputLines = array(); public $outputCols = array(); private $characterTokens = array(); protected function emitToken($token, $checkStream = true, $dry = false) { parent::emitToken($token, $checkStream, $dry); // XXX: The tests should really include the parse errors, but I'm lazy. switch ($token['type']) { case self::PARSEERROR: return; case self::CHARACTER: if ($this->characterTokens) { array_pop($this->outputLines); array_pop($this->outputCols); } $this->characterTokens[] = $token; default: $this->outputLines[] = $this->stream()->getCurrentLine(); $this->outputCols[] = $this->stream()->getColumnOffset(); } if ($token['type'] !== self::CHARACTER) { $this->characterTokens = array(); } } } class HTML5_TokenizerTestOfPosition extends UnitTestCase { function testBasic() { $this->assertPositions( "<b><i>f<p>\n<b>a</b>", array(1,1,1,1, 2,2,2,2), array(3,6,7,10,0,3,4,8) ); } function testUnicode() { $this->assertPositions( "\xC2\xA2<b>\xE2\x82\xACa<b>\xf4\x8a\xaf\x8d", array(1,1,1,1,1), array(1,4,6,9,10) ); } function testData() { $this->assertPositions( "a\na\n\xC2\xA2<b>", array(3,3), array(1,4) ); } function testMarkupDeclarationDoubleDash() { $this->assertPositions( '<!-- foo -->', array(1), array(12) ); } function testMarkupDeclarationDoctype() { $this->assertPositions( '<!DOCTYPE>', array(1), array(10) ); } function testAfterDoctypeNamePublic() { $this->assertPositions( '<!DOCTYPE PUBLIC "foo">', array(1), array(23) ); } function testAfterDoctypeNameSystem() { $this->assertPositions( '<!DOCTYPE SYSTEM "foo">', array(1), array(23) ); } function testDecEntitySansSemicolon() { $this->assertPositions( 'Ĭ', array(1), array(5) ); } function testDecEntityWithSemicolon() { $this->assertPositions( 'Ĭ', array(1), array(6) ); } function testHexEntity() { $this->assertPositions( '̀', array(1), array(7) ); } function testEmptyEntity() { $this->assertPositions( '&#;<b>', array(1,1), array(3,6) ); } function testNamedEntity() { $this->assertPositions( '"foo<b>', array(1,1), array(9,12) ); } function testBadNamedEntity() { $this->assertPositions( '&zzz;b', array(1), array(6) ); } function testAttributeEntity() { $this->assertPositions( '<b foo="&er">a', array( 1, 1), array(16,17) ); } function testBogusComment() { $this->assertPositions( "<!as asdfe \nasdf>d", array(2,2), array(5,6) ); } protected function assertPositions($input, $lines, $cols, $flag = HTML5_Tokenizer::PCDATA, $lastStartTag = null) { $tokenizer = new HTML5_PositionTestableTokenizer($input, $flag, $lastStartTag); $GLOBALS['TIME'] -= get_microtime(); $tokenizer->parse($input); $GLOBALS['TIME'] += get_microtime(); $this->assertIdentical($tokenizer->outputLines, $lines, 'Lines: %s'); $this->assertIdentical($tokenizer->outputCols, $cols, 'Cols: %s'); } } |