1 | 'use strict';
|
2 | var domino = require('../');
|
3 | var html5lib_tests = require('./html5lib-tests.json');
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | function cases(filename, tc) {
|
10 | return tc.filter(function(test) {
|
11 |
|
12 | if (test.fragment && test.fragment.ns) { return false; }
|
13 |
|
14 | if (test.script === 'off') { return false; }
|
15 | return true;
|
16 | }).reduce(function(r, test) {
|
17 | var input = test.data, expected = test.document.html,
|
18 | fragment = test.fragment && test.fragment.name;
|
19 |
|
20 | var trimmed = input, n, candidate;
|
21 | if (trimmed==='') { trimmed = '{no input}'; }
|
22 | if (fragment) { trimmed = fragment + ':' + trimmed; }
|
23 | if (r[trimmed]) {
|
24 |
|
25 | }
|
26 | for (n = 40; n < trimmed.length; n += 5) {
|
27 | candidate = trimmed.slice(0, n) + '...';
|
28 | if (!r[candidate]) { trimmed = candidate; break; }
|
29 | }
|
30 | if (/\n/.test(trimmed)) {
|
31 | candidate = trimmed.split(/\n/)[0] + '...';
|
32 | if (!r[candidate]) { trimmed = candidate; }
|
33 | }
|
34 | r[trimmed] = makeOneTest(fragment, input, expected);
|
35 | return r;
|
36 | }, {});
|
37 | }
|
38 |
|
39 | function makeOneTest(fragment, input, expected) {
|
40 | return function() {
|
41 | var doc, context;
|
42 | if (fragment) {
|
43 | doc = domino.createDocument();
|
44 | context = (fragment==='body') ? doc.body : doc.createElement(fragment);
|
45 | context.innerHTML = input;
|
46 | context.innerHTML.should.equal(expected);
|
47 | } else {
|
48 | doc = domino.createDocument(input, true);
|
49 | doc.outerHTML.should.equal(expected);
|
50 | }
|
51 | };
|
52 | }
|
53 |
|
54 | exports.parseAlgorithm = Object.keys(html5lib_tests).reduce(function(r, file) {
|
55 | r[file] = cases(file, html5lib_tests[file]);
|
56 | return r;
|
57 | }, {});
|
58 |
|
59 |
|
60 |
|
61 |
|
62 | exports.parseAlgorithm['github issue #20'] = {
|
63 | 'test1': makeOneTest(
|
64 | 'body', '<table><li><li></table>', '<li></li><li></li><table></table>'
|
65 | )
|
66 | };
|