Skip to content

Commit

Permalink
tools/doc: Add tests for the toHTML function
Browse files Browse the repository at this point in the history
Addresses nodejs#5955 on GitHub.
Test the toHTML function in html.js. Check that given valid markdown it
produces the expected html. One test case will prevent regressions of
big nodejs#5873.
  • Loading branch information
iankronquist committed Apr 4, 2016
1 parent 64bf4b3 commit 524ebc7
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tools/doc/tests/fixtures/order_of_end_tags_5873.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Title

## Subsection

### Class Method: Buffer.from(array)
* `array` {Array}
8 changes: 8 additions & 0 deletions tools/doc/tests/fixtures/sample_document.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Sample Markdown

## Seussian Rhymes
1. fish
2. fish

* Red fish
* Blue fish
50 changes: 50 additions & 0 deletions tools/doc/tests/test_html.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict';

var assert = require('assert');
var fs = require('fs');

var html = require('../html.js');

// Outputs valid html when given simple markdown
function test_toHTML() {
// 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.
var testData = [
{
'file': 'tools/doc/tests/fixtures/sample_document.markdown',
'html': '<ol><li>fish</li><li><p>fish</p></li><li><p>Redfish</p></li>' +
'<li>Bluefish</li></ol>'
},
{
'file': 'tools/doc/tests/fixtures/order_of_end_tags_5873.markdown',
'html': '<h3>ClassMethod: Buffer.from(array) <span> ' +
'<a class="mark" href="#foo_class_method_buffer_from_array" ' +
'id="foo_class_method_buffer_from_array">#</a> </span> </h3><div' +
'class="signature"><ul><li><code>array</code><a ' +
'href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/' +
'Reference/Global_Objects/Array" class="type">&lt;Array&gt;</a></li>' +
'</ul></div>'
},
];

testData.forEach(function(item) {
// Normalize expected data by stripping whitespace
var expected = item.html.replace(/\s/g, '');

fs.readFile(item.file, 'utf8', function(err, input) {
html(input, 'foo', 'doc/template.html', function(err, output) {

if (err) throw err;

var actual = output.replace(/\s/g, '');
// Assert that the input stripped of all whitespace contains the
// expected list
assert.notEqual(actual.indexOf(expected), -1);
});
});
});
}

test_toHTML();

0 comments on commit 524ebc7

Please sign in to comment.