forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools/doc: Add tests for the toHTML function
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
1 parent
64bf4b3
commit 524ebc7
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Title | ||
|
||
## Subsection | ||
|
||
### Class Method: Buffer.from(array) | ||
* `array` {Array} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"><Array></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(); |