diff options
author | Matt Butcher <[email protected]> | 2013-04-13 13:32:23 -0500 |
---|---|---|
committer | Matt Butcher <[email protected]> | 2013-04-13 13:32:23 -0500 |
commit | b94fe2a6e67475aa819a97779a3c5ec07e2f53b5 (patch) | |
tree | b01ae40879b2f00d7537fde9e13a671f8bf7b5ad /test/SimpleTest/TokenizerTest.php | |
parent | 9457e0951ebc69238917c7178c015f0c9bf68d62 (diff) |
Relocated deprecated tests.
Diffstat (limited to 'test/SimpleTest/TokenizerTest.php')
-rw-r--r-- | test/SimpleTest/TokenizerTest.php | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/test/SimpleTest/TokenizerTest.php b/test/SimpleTest/TokenizerTest.php new file mode 100644 index 0000000..d00fa78 --- /dev/null +++ b/test/SimpleTest/TokenizerTest.php @@ -0,0 +1,88 @@ +<?php + +require_once dirname(__FILE__) . '/../autorun.php'; + +SimpleTest::ignore('HTML5_TokenizerHarness'); +abstract class HTML5_TokenizerHarness extends HTML5_JSONHarness +{ + public function invoke($test) { + //echo get_class($this) . ': ' . $test->description ."\n"; + if (!isset($test->contentModelFlags)) { + $test->contentModelFlags = array('PCDATA'); + } + if (!isset($test->ignoreErrorOrder)) { + $test->ignoreErrorOrder = false; + } + + // Get expected result array (and maybe error count). + $expect = array(); + $expectedErrorCount = 0; // This is only used when ignoreErrorOrder = true. + foreach ($test->output as $tok) { + // If we're ignoring error order and this is a parse error, just count. + if ($test->ignoreErrorOrder && $tok === 'ParseError') { + $expectedErrorCount++; + } else { + // Normalize character tokens from the test + if ($expect && $tok[0] === 'Character' && $expect[count($expect) - 1][0] === 'Character') { + $expect[count($expect) - 1][1] .= $tok[1]; + } else { + $expect[] = $tok; + } + } + } + + // Run test for each content model flag. + foreach ($test->contentModelFlags as $flag) { + $output = $this->tokenize($test, $flag); + $result = array(); + $resultErrorCount = 0; // This is only used when ignoreErrorOrder = true. + foreach ($output as $tok) { + // If we're ignoring error order and this is a parse error, just count. + if ($test->ignoreErrorOrder && $tok === 'ParseError') { + $resultErrorCount++; + } else { + $result[] = $tok; + } + } + $this->assertIdentical($expect, $result, + 'In test "'.str_replace('%', '%%', $test->description). + '" with content model '.$flag.': %s' + ); + if ($test->ignoreErrorOrder) { + $this->assertIdentical($expectedErrorCount, $resultErrorCount, + 'Wrong error count in test "'.str_replace('%', '%%', $test->description). + '" with content model '.$flag.': %s' + ); + } + if ($expect != $result || ($test->ignoreErrorOrder && $expectedErrorCount !== $resultErrorCount)) { + echo "Input: "; str_dump($test->input); + echo "\nExpected: \n"; echo $this->tokenDump($expect); + echo "\nActual: \n"; echo $this->tokenDump($result); + echo "\n"; + } + } + } + private function tokenDump($tokens) { + $ret = ''; + foreach ($tokens as $i => $token) { + $ret .= ($i+1).". {$token[0]}: {$token[1]}\n"; + } + return $ret; + } + public function tokenize($test, $flag) { + $flag = constant("HTML5_Tokenizer::$flag"); + if (!isset($test->lastStartTag)) $test->lastStartTag = null; + $tokenizer = new HTML5_TestableTokenizer($test->input, $flag, $test->lastStartTag); + $GLOBALS['TIME'] -= get_microtime(); + $tokenizer->parse(); + $GLOBALS['TIME'] += get_microtime(); + return $tokenizer->outputTokens; + } +} + +// generate test suites for tokenizer +HTML5_TestData::generateTestCases( + 'HTML5_TokenizerHarness', + 'HTML5_TokenizerTestOf', + 'tokenizer', '*.test' +); |