Пример #1
0
 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);
 }
Пример #2
0
    function testStrDom()
    {
        $dom = new DOMDocument();
        $dom->loadHTML('<!DOCTYPE html PUBLIC "http://foo" "http://bar"><html><body foo="bar" baz="1">foo<b>bar</b>asdf</body></html>');
        $this->assertIdentical(HTML5_TestData::strDom($dom), <<<RESULT
| <!DOCTYPE html "http://foo" "http://bar">
| <html>
|   <body>
|     baz="1"
|     foo="bar"
|     "foo"
|     <b>
|       "bar"
|     "asdf"
RESULT
);
    }
Пример #3
0
 /**
  * This function generates unique test case classes corresponding
  * to test files in the testdata directory.
  */
 public static function generateTestCases($base, $prefix, $type, $glob)
 {
     foreach (HTML5_TestData::getList($type, $glob) as $filename) {
         $name = str_replace('-', '', basename($filename));
         $name = ucfirst(substr($name, 0, strcspn($name, '.')));
         if ($type === 'tree-construction') {
             // skip XFOREIGN tests for now
             $num = (int) substr($name, 5);
             if ($num >= 9) {
                 continue;
             }
         }
         $pfilename = var_export($filename, true);
         $code = "class {$prefix}{$name} extends {$base} { public \$filename = {$pfilename}; }";
         eval($code);
     }
 }
Пример #4
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');