From dd505f77a4d67f7d0f484fea29105c29f4b40db8 Mon Sep 17 00:00:00 2001 From: Technosophos Date: Wed, 10 Apr 2013 17:07:22 -0500 Subject: Working on entity resolution. --- test/HTML5/Parser/EventStack.php | 13 +++++++++++-- test/HTML5/Parser/TokenizerTest.php | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) (limited to 'test/HTML5/Parser') diff --git a/test/HTML5/Parser/EventStack.php b/test/HTML5/Parser/EventStack.php index 213d893..a75402e 100644 --- a/test/HTML5/Parser/EventStack.php +++ b/test/HTML5/Parser/EventStack.php @@ -1,6 +1,10 @@ stack); } + public function get($index) { + return $this->stack[$index]; + } + protected function store($event, $data = NULL) { - $stack[] = array( + $this->stack[] = array( 'name' => $event, 'data' => $data, ); @@ -45,7 +53,8 @@ class EventStack implements EventHandler { } public function text($cdata) { - $this->store('character', array($cdata)); + fprintf(STDOUT, "Received TEXT event with: " . $cdata); + $this->store('text', array($cdata)); } public function eof() { diff --git a/test/HTML5/Parser/TokenizerTest.php b/test/HTML5/Parser/TokenizerTest.php index d10c683..0e93bb5 100644 --- a/test/HTML5/Parser/TokenizerTest.php +++ b/test/HTML5/Parser/TokenizerTest.php @@ -19,6 +19,37 @@ class TokenizerTest extends \HTML5\Tests\TestCase { $tok->parse(); - $this->assertEquals(0, $events->Depth()); + $this->assertEquals(1, $events->Depth()); + $this->assertEquals('eof', $e1['name']); + } + + public function testWhitespace() { + $spaces = ' '; + list($tok, $events) = $this->createTokenizer($spaces); + + $tok->parse(); + + $this->assertEquals(2, $events->depth()); + + $e1 = $events->get(0); + + $this->assertEquals('text', $e1['name']); + $this->assertEquals($spaces, $e1['data'][0]); + } + + public function testCharacterReference() { + $str = '&'; + list($tok, $events) = $this->createTokenizer($str); + + $tok->parse(); + $this->assertEquals(2, $events->depth()); + $e1 = $events->get(0); + + $this->assertEquals('&', $e1['data'][0]); + + // Test with hex charref + // Test with decimal charref + // Test with broken charref + // Test with stand-alone ampersand } } -- cgit v1.2.3