From f0da96a373b912eb649954d7920a96c6284f9455 Mon Sep 17 00:00:00 2001 From: Technosophos Date: Thu, 11 Apr 2013 17:39:22 -0500 Subject: Working on closing tag and bogus comments. --- test/HTML5/Parser/EventStack.php | 2 +- test/HTML5/Parser/TokenizerTest.php | 58 ++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 9 deletions(-) (limited to 'test/HTML5/Parser') diff --git a/test/HTML5/Parser/EventStack.php b/test/HTML5/Parser/EventStack.php index 36e2f29..4d82629 100644 --- a/test/HTML5/Parser/EventStack.php +++ b/test/HTML5/Parser/EventStack.php @@ -64,7 +64,7 @@ class EventStack implements EventHandler { public function parseError($msg, $line, $col) { //throw new EventStackParseError(sprintf("%s (line %d, col %d)", $msg, $line, $col)); //$this->store(sprintf("%s (line %d, col %d)", $msg, $line, $col)); - $this->store('comment', func_get_args()); + $this->store('error', func_get_args()); } diff --git a/test/HTML5/Parser/TokenizerTest.php b/test/HTML5/Parser/TokenizerTest.php index e006fb9..c31d74b 100644 --- a/test/HTML5/Parser/TokenizerTest.php +++ b/test/HTML5/Parser/TokenizerTest.php @@ -4,18 +4,21 @@ require __DIR__ . '/../TestCase.php'; require 'EventStack.php'; class TokenizerTest extends \HTML5\Tests\TestCase { - protected function createTokenizer($string) { + protected function createTokenizer($string, $debug = FALSE) { $eventHandler = new EventStack(); $stream = new StringInputStream($string); $scanner = new Scanner($stream); + + $scanner->debug = $debug; + return array( new Tokenizer($scanner, $eventHandler), $eventHandler, ); } - public function parse($string) { - list($tok, $events) = $this->createTokenizer($string); + public function parse($string, $debug = FALSE) { + list($tok, $events) = $this->createTokenizer($string, $debug); $tok->parse(); return $events; @@ -75,20 +78,59 @@ class TokenizerTest extends \HTML5\Tests\TestCase { } - /** - * @expectedException \HTML5\Parser\EventStackParseError - */ public function testBrokenCharacterReference() { // Test with broken charref $str = '&foo'; $events = $this->parse($str); + $e1 = $events->get(0); + $this->assertEquals('error', $e1['name']); } public function testBogusComment() { $str = ''; - $events = $this->parse($str); - $e1 = $events->get(0); + $events = $this->parse($str . ' '); + $e0 = $events->get(0); + $this->assertEquals('error', $e0['name']); + $e1 = $events->get(1); $this->assertEquals('comment', $e1['name']); $this->assertEquals($str, $e1['data'][0]); } + + public function testEndTag() { + $succeed = array( + '' => 'a', + '' => 'test', + '' => 'test', + // See 8.2.4.10, which requires this and does not say error. + '' => 'a $result) { + $events = $this->parse($test); + $this->assertEquals(2, $events->depth()); + $e1 = $events->get(0); + $this->assertEquals('endTag', $e1['name'], "Parsing $test expects $result."); + $this->assertEquals($result, $e1['data'][0], "Parse end tag " . $test); + } + + + $fail = array( + '' => 'a', + '' => 'a', + '' => 'a', + '' => '', + '' => '', + ); + foreach ($fail as $test => $result) { + $events = $this->parse($test); + // Should have triggered an error. + $e0 = $events->get(0); + $this->assertEquals('error', $e0['name'], "Parsing $test expects a leading error." . print_r($events, TRUE)); + // Should have tried to parse anyway. + $e1 = $events->get(1); + $this->assertEquals('endTag', $e1['name'], "Parsing $test expects resolution to $result." . print_r($events, TRUE)); + $this->assertEquals($result, $e1['data'][0], "Parse end tag " . $test); + $this->assertEquals(3, $events->depth()); + } + } } -- cgit v1.2.3