summaryrefslogtreecommitdiff
path: root/test/HTML5/Parser
diff options
context:
space:
mode:
authorTechnosophos <[email protected]>2013-04-11 17:39:22 -0500
committerTechnosophos <[email protected]>2013-04-11 17:39:22 -0500
commitf0da96a373b912eb649954d7920a96c6284f9455 (patch)
tree2492b865ea4067f1a015c270158f8e0349bd9934 /test/HTML5/Parser
parent4b48113eed8e21ccc6b8b4bbb310cbecdd85af65 (diff)
Working on closing tag and bogus comments.
Diffstat (limited to 'test/HTML5/Parser')
-rw-r--r--test/HTML5/Parser/EventStack.php2
-rw-r--r--test/HTML5/Parser/TokenizerTest.php58
2 files changed, 51 insertions, 9 deletions
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 = '</+this is a bogus comment. +>';
- $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>' => 'a',
+ '</test>' => 'test',
+ '</test
+ >' => 'test',
+ // See 8.2.4.10, which requires this and does not say error.
+ '</a<b>' => 'a<b',
+ );
+ foreach ($succeed as $test => $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 class="monkey">' => 'a',
+ '</a <b>' => '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());
+ }
+ }
}