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( "f

\na", array(1,1,1,1, 2,2,2,2), array(3,6,7,10,0,3,4,8) ); } function testUnicode() { $this->assertPositions( "\xC2\xA2\xE2\x82\xACa\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", array(3,3), array(1,4) ); } function testMarkupDeclarationDoubleDash() { $this->assertPositions( '', array(1), array(12) ); } function testMarkupDeclarationDoctype() { $this->assertPositions( '', array(1), array(10) ); } function testAfterDoctypeNamePublic() { $this->assertPositions( '', array(1), array(23) ); } function testAfterDoctypeNameSystem() { $this->assertPositions( '', 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( '&#;', array(1,1), array(3,6) ); } function testNamedEntity() { $this->assertPositions( '"foo', array(1,1), array(9,12) ); } function testBadNamedEntity() { $this->assertPositions( '&zzz;b', array(1), array(6) ); } function testAttributeEntity() { $this->assertPositions( 'a', array( 1, 1), array(16,17) ); } function testBogusComment() { $this->assertPositions( "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'); } }