diff options
author | Technosophos <[email protected]> | 2013-04-10 17:07:22 -0500 |
---|---|---|
committer | Technosophos <[email protected]> | 2013-04-10 17:07:22 -0500 |
commit | dd505f77a4d67f7d0f484fea29105c29f4b40db8 (patch) | |
tree | 88d894019f73e4541335219799a3564b30819b5f /test | |
parent | 503a3d00cdf2358cc66ce63959ce6dd5f6abf953 (diff) |
Working on entity resolution.
Diffstat (limited to 'test')
-rw-r--r-- | test/HTML5/Parser/EventStack.php | 13 | ||||
-rw-r--r-- | test/HTML5/Parser/TokenizerTest.php | 33 |
2 files changed, 43 insertions, 3 deletions
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 @@ <?php namespace HTML5\Parser; +/** + * This testing class gathers events from a parser and builds a stack of events. + * It is useful for checking the output of a tokenizer. + */ class EventStack implements EventHandler { protected $stack; @@ -19,8 +23,12 @@ class EventStack implements EventHandler { return count($this->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 } } |