'use strict';
const common = require('../common');
const assert = require('assert');
const fs = require('fs');
const html = require('../../tools/doc/html.js');
// Test data is a list of objects with two properties.
// The file property is the file path.
// The html property is some html which will be generated by the doctool.
// This html will be stripped of all whitespace because we don't currently
// have an html parser.
const testData = [
{
'file': common.fixturesDir + '/sample_document.md',
'html': '
- fish
fish
Redfish
' +
'- Bluefish
'
},
{
'file': common.fixturesDir + '/order_of_end_tags_5873.md',
'html': 'ClassMethod: Buffer.from(array) ' +
'#
'
},
{
'file': common.fixturesDir + '/doc_with_yaml.md',
'html': 'Sample Markdown with YAML info' +
'#
' +
'Foobar#
' +
'Added in: v1.0.0
' +
'Describe Foobar
in more detail here.
' +
'Foobar II#
' +
'Added in: v5.3.0, v4.2.0
' +
'Describe Foobar II
in more detail here.
' +
'Deprecated thingy#' +
'
' +
'Added in: v1.0.0' +
'Deprecated since: v2.0.0
Describe ' +
'Deprecated thingy
in more detail here.
' +
'Something#
' +
' ' +
'Describe Something
in more detail here. ' +
'
'
},
];
testData.forEach(function(item) {
// Normalize expected data by stripping whitespace
const expected = item.html.replace(/\s/g, '');
fs.readFile(item.file, 'utf8', common.mustCall(function(err, input) {
assert.ifError(err);
html(input, 'foo', 'doc/template.html',
common.mustCall(function(err, output) {
assert.ifError(err);
const actual = output.replace(/\s/g, '');
// Assert that the input stripped of all whitespace contains the
// expected list
assert.notEqual(actual.indexOf(expected), -1);
}));
}));
});