Пример #1
0
<?php

require_once dirname(__FILE__) . '/../autorun.php';
SimpleTest::ignore('HTML5_TreeBuilderHarness');
class HTML5_TreeBuilderHarness extends HTML5_TestDataHarness
{
    public function assertIdentical($expect, $actual, $test = array())
    {
        $input = $test['data'];
        if (isset($test['document-fragment'])) {
            $input .= "\nFragment: " . $test['document-fragment'];
        }
        parent::assertIdentical($expect, $actual, "Identical expectation failed\nInput:\n{$input}\n\nExpected:\n{$expect}\n\nActual:\n{$actual}\n");
    }
    public function invoke($test)
    {
        // this is totally the wrong interface to use, but
        // for now we need testing
        $tokenizer = new HTML5_Tokenizer($test['data']);
        $GLOBALS['TIME'] -= get_microtime();
        if (isset($test['document-fragment'])) {
            $tokenizer->parseFragment($test['document-fragment']);
        } else {
            $tokenizer->parse();
        }
        $GLOBALS['TIME'] += get_microtime();
        $this->assertIdentical($test['document'], HTML5_TestData::strDom($tokenizer->save()), $test);
    }
}
HTML5_TestData::generateTestCases('HTML5_TreeBuilderHarness', 'HTML5_TreeBuilderTestOf', 'tree-construction', '*.dat');
Пример #2
0
                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');