8000 Respect the ignoreErrorOrder flag on tokenizer tests (this fixes one … · html5lib/html5lib-php@370ae4e · GitHub
[go: up one dir, main page]

Skip to content

Commit 370ae4e

Browse files
committed
Respect the ignoreErrorOrder flag on tokenizer tests (this fixes one test).
1 parent 8f16a35 commit 370ae4e

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

tests/HTML5/TokenizerTest.php

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,51 @@ public function invoke($test) {
1010
if (!isset($test->contentModelFlags)) {
1111
$test->contentModelFlags = array('PCDATA');
1212
}
13-
foreach ($test->contentModelFlags as $flag) {
14-
$result = $this->tokenize($test, $flag);
15-
$expect = array();
16-
$last = null;
17-
foreach ($test->output as $tok) {
13+
if (!isset($test->ignoreErrorOrder)) {
14+
$test->ignoreErrorOrder = false;
15+
}
16+
17+
// Get expected result array (and maybe error count).
18+
$expect = array();
19+
$expectedErrorCount = 0; // This is only used when ignoreErrorOrder = true.
20+
foreach ($test->output as $tok) {
21+
// If we're ignoring error order and this is a parse error, just count.
22+
if ($test->ignoreErrorOrder && $tok === 'ParseError') {
23+
$expectedErrorCount++;
24+
} else {
1825
// Normalize character tokens from the test
19-
if ($tok[0] === 'Character' && $last[0] === 'Character') {
20-
$last[1] .= $tok[1];
21-
continue;
26+
if ($expect && $tok[0] === 'Character' && $expect[count($expect) - 1][0] === 'Character') {
27+
$expect[count($expect) - 1][1] .= $tok[1];
28+
} else {
29+
$expect[] = $tok;
30+
}
31+
}
32+
}
33+
34+
// Run test for each content model flag.
35+
foreach ($test->contentModelFlags as $flag) {
36+
$output = $this->tokenize($test, $flag);
37+
$result = array();
38+
$resultErrorCount = 0; // This is only used when ignoreErrorOrder = true.
39+
foreach ($output as $tok) {
40+
// If we're ignoring error order and this is a parse error, just count.
41+
if ($test->ignoreErrorOrder && $tok === 'ParseError') {
42+
$resultErrorCount++;
43+
} else {
44+
$result[] = $tok;
2245
}
23-
// XXX we should also normalize our results... somewhere
24-
// (probably not here)
25-
$expect[] = $tok;
26-
$last =& $expect[count($expect) - 1];
2746
}
2847
$this->assertIdentical($expect, $result,
2948
'In test "'.str_replace('%', '%%', $test->description).
3049
'" with content model '.$flag.': %s'
3150
);
32-
if ($expect != $result) {
51+
if ($test->ignoreErrorOrder) {
52+
$this->assertIdentical($expectedErrorCount, $resultErrorCount,
53+
'Wrong error count in test "'.str_replace('%', '%%', $test->description).
54+
'" with content model '.$flag.': %s'
55+
);
56+
}
57+
if ($expect != $result || ($test->ignoreErrorOrder && $expectedErrorCount !== $resultErrorCount)) {
3358
echo "Input: "; str_dump($test->input);
3459
echo "\nExpected: \n"; echo $this->tokenDump($expect);
3560
echo "\nActual: \n"; echo $this->tokenDump($result);

0 commit comments

Comments
 (0)
0