showdown/test/bootstrap.js

90 lines
2.2 KiB
JavaScript
Raw Normal View History

/**
* Created by Estevao on 08-06-2015.
*/
//jscs:disable requireCamelCaseOrUpperCaseIdentifiers
2015-06-17 08:26:50 +08:00
(function () {
'use strict';
require('source-map-support').install();
require('chai').should();
2016-02-02 08:29:06 +08:00
var fs = require('fs');
function getTestSuite (dir) {
2015-06-17 08:26:50 +08:00
return fs.readdirSync(dir)
.filter(filter())
.map(map(dir));
}
function filter () {
2015-06-17 08:26:50 +08:00
return function (file) {
var ext = file.slice(-3);
return (ext === '.md');
};
2015-06-17 08:26:50 +08:00
}
function map (dir) {
2015-06-17 08:26:50 +08:00
return function (file) {
var name = file.replace('.md', ''),
htmlPath = dir + name + '.html',
html = fs.readFileSync(htmlPath, 'utf8'),
mdPath = dir + name + '.md',
md = fs.readFileSync(mdPath, 'utf8');
2015-06-17 08:26:50 +08:00
return {
name: name,
input: md,
expected: html
};
};
}
function assertion (testCase, converter) {
2015-06-17 08:26:50 +08:00
return function () {
testCase.actual = converter.makeHtml(testCase.input);
testCase = normalize(testCase);
// Compare
testCase.actual.should.equal(testCase.expected);
};
}
//Normalize input/output
function normalize (testCase) {
2015-06-17 08:26:50 +08:00
// Normalize line returns
testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');
testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n');
// Ignore all leading/trailing whitespace
testCase.expected = testCase.expected.split('\n').map(function (x) {
return x.trim();
}).join('\n');
testCase.actual = testCase.actual.split('\n').map(function (x) {
return x.trim();
}).join('\n');
2015-06-17 08:26:50 +08:00
// Remove extra lines
testCase.expected = testCase.expected.trim();
testCase.actual = testCase.actual.trim();
2015-06-17 08:26:50 +08:00
//Beautify
2016-02-02 08:29:06 +08:00
//testCase.expected = beautify(testCase.expected, beauOptions);
//testCase.actual = beautify(testCase.actual, beauOptions);
2015-06-17 08:26:50 +08:00
// Normalize line returns
2015-07-15 03:53:28 +08:00
testCase.expected = testCase.expected.replace(/(\r\n)|\n|\r/g, '\n');
testCase.actual = testCase.actual.replace(/(\r\n)|\n|\r/g, '\n');
2015-06-17 08:26:50 +08:00
return testCase;
}
module.exports = {
getTestSuite: getTestSuite,
assertion: assertion,
normalize: normalize,
showdown: require('../.build/showdown.js')
};
2015-06-17 08:26:50 +08:00
})();