2015-02-23 23:39:20 -08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var fs = require("fs");
|
|
|
|
var path = require("path");
|
2015-03-17 22:34:47 -07:00
|
|
|
var md = require("markdown-it")();
|
2015-03-12 23:42:06 -07:00
|
|
|
var Q = require("q");
|
2015-02-23 23:39:20 -08:00
|
|
|
var markdownlint = require("../lib/markdownlint");
|
2015-03-08 23:08:43 -07:00
|
|
|
var shared = require("../lib/shared");
|
2015-03-17 22:34:47 -07:00
|
|
|
var rules = require("../lib/rules");
|
2015-05-03 22:40:34 -07:00
|
|
|
var polyfills = require("../demo/browser-polyfills");
|
2015-07-20 22:06:48 -07:00
|
|
|
var defaultConfig = require("./markdownlint-test-default-config.json");
|
2015-02-27 22:06:54 -08:00
|
|
|
|
2015-02-23 23:39:20 -08:00
|
|
|
function createTestForFile(file) {
|
2015-02-24 18:40:37 -08:00
|
|
|
return function testForFile(test) {
|
2015-03-01 22:15:02 -08:00
|
|
|
test.expect(1);
|
|
|
|
var configFile = file.replace(/\.md$/, ".json");
|
|
|
|
var actualPromise = Q.nfcall(fs.stat, configFile)
|
|
|
|
.then(
|
|
|
|
function configFileExists() {
|
2015-03-15 23:39:17 -07:00
|
|
|
return Q.nfcall(fs.readFile, configFile, shared.utf8Encoding)
|
2015-03-01 22:15:02 -08:00
|
|
|
.then(
|
|
|
|
function configFileContents(contents) {
|
|
|
|
return JSON.parse(contents);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
function noConfigFile() {
|
2015-09-26 16:55:33 -07:00
|
|
|
return {};
|
2015-03-01 22:15:02 -08:00
|
|
|
})
|
|
|
|
.then(
|
|
|
|
function lintWithConfig(config) {
|
2015-09-26 16:55:33 -07:00
|
|
|
var mergedConfig = shared.assign(shared.clone(defaultConfig), config);
|
2015-03-01 22:15:02 -08:00
|
|
|
return Q.nfcall(markdownlint, {
|
|
|
|
"files": [ file ],
|
2015-07-20 22:06:48 -07:00
|
|
|
"config": mergedConfig
|
2015-03-01 22:15:02 -08:00
|
|
|
});
|
|
|
|
});
|
2015-03-15 23:39:17 -07:00
|
|
|
var expectedPromise = Q.nfcall(fs.readFile, file, shared.utf8Encoding)
|
2015-03-01 22:15:02 -08:00
|
|
|
.then(
|
|
|
|
function fileContents(contents) {
|
2015-03-08 23:08:43 -07:00
|
|
|
var lines = contents.split(shared.newLineRe);
|
2015-02-27 22:06:54 -08:00
|
|
|
var results = {};
|
|
|
|
lines.forEach(function forLine(line, lineNum) {
|
2015-03-04 18:09:46 -08:00
|
|
|
var regex = /\{(MD\d+)(?::(\d+))?\}/g;
|
2015-09-26 22:22:22 -07:00
|
|
|
var match = null;
|
2015-03-04 18:09:46 -08:00
|
|
|
while ((match = regex.exec(line))) {
|
2015-02-27 22:06:54 -08:00
|
|
|
var rule = match[1];
|
|
|
|
var errors = results[rule] || [];
|
2015-03-04 18:09:46 -08:00
|
|
|
errors.push(match[2] ? parseInt(match[2], 10) : lineNum + 1);
|
2015-02-27 22:06:54 -08:00
|
|
|
results[rule] = errors;
|
|
|
|
}
|
|
|
|
});
|
2015-03-17 18:02:05 -07:00
|
|
|
var sortedResults = {};
|
|
|
|
Object.keys(results).sort().forEach(function forKey(key) {
|
|
|
|
sortedResults[key] = results[key];
|
|
|
|
});
|
|
|
|
return sortedResults;
|
2015-02-24 18:40:37 -08:00
|
|
|
});
|
2015-03-01 22:15:02 -08:00
|
|
|
Q.all([ actualPromise, expectedPromise ])
|
|
|
|
.then(
|
|
|
|
function compareResults(fulfillments) {
|
|
|
|
var actual = fulfillments[0];
|
|
|
|
var results = fulfillments[1];
|
|
|
|
var expected = {};
|
|
|
|
expected[file] = results;
|
|
|
|
test.deepEqual(actual, expected, "Line numbers are not correct.");
|
|
|
|
})
|
|
|
|
.done(test.done, test.done);
|
2015-02-23 23:39:20 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
fs.readdirSync("./test").forEach(function forFile(file) {
|
2015-02-23 23:39:20 -08:00
|
|
|
if (file.match(/\.md$/)) {
|
2015-03-17 22:34:47 -07:00
|
|
|
module.exports[file] = createTestForFile(path.join("./test", file));
|
2015-02-23 23:39:20 -08:00
|
|
|
}
|
|
|
|
});
|
2015-03-11 21:13:21 -07:00
|
|
|
|
2015-03-12 23:42:06 -07:00
|
|
|
module.exports.projectFiles = function projectFiles(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
2016-01-12 21:29:17 -08:00
|
|
|
"files": [ "README.md" ],
|
|
|
|
"config": { "MD013": false }
|
2015-03-12 23:42:06 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actual) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expected = { "README.md": {} };
|
|
|
|
test.deepEqual(actual, expected, "Issue(s) with project files.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-13 09:13:07 -07:00
|
|
|
module.exports.resultFormatting = function resultFormatting(test) {
|
2016-01-12 21:29:17 -08:00
|
|
|
test.expect(4);
|
2015-03-13 09:13:07 -07:00
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
2015-07-20 22:06:48 -07:00
|
|
|
],
|
|
|
|
"config": defaultConfig
|
2015-03-13 09:13:07 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {
|
|
|
|
"MD002": [ 3 ],
|
|
|
|
"MD018": [ 1 ],
|
|
|
|
"MD019": [ 3, 5 ]
|
|
|
|
},
|
|
|
|
"./test/first_header_bad_atx.md": {
|
|
|
|
"MD002": [ 1 ]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
var actualMessage = actualResult.toString();
|
|
|
|
var expectedMessage =
|
|
|
|
"./test/atx_header_spacing.md: 3: MD002" +
|
|
|
|
" First header should be a h1 header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 1: MD018" +
|
|
|
|
" No space after hash on atx style header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 3: MD019" +
|
|
|
|
" Multiple spaces after hash on atx style header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 5: MD019" +
|
|
|
|
" Multiple spaces after hash on atx style header\n" +
|
|
|
|
"./test/first_header_bad_atx.md: 1: MD002" +
|
|
|
|
" First header should be a h1 header";
|
2016-01-12 21:29:17 -08:00
|
|
|
test.equal(actualMessage, expectedMessage, "Incorrect message (name).");
|
|
|
|
actualMessage = actualResult.toString(true);
|
|
|
|
expectedMessage =
|
|
|
|
"./test/atx_header_spacing.md: 3: first-header-h1" +
|
|
|
|
" First header should be a h1 header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 1: no-missing-space-atx" +
|
|
|
|
" No space after hash on atx style header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 3: no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 5: no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style header\n" +
|
|
|
|
"./test/first_header_bad_atx.md: 1: first-header-h1" +
|
|
|
|
" First header should be a h1 header";
|
|
|
|
test.equal(actualMessage, expectedMessage, "Incorrect message (alias).");
|
2015-03-13 09:13:07 -07:00
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
module.exports.resultFormattingSync = function resultFormattingSync(test) {
|
2016-01-12 21:29:17 -08:00
|
|
|
test.expect(3);
|
2015-03-20 00:09:55 -07:00
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
2015-07-20 22:06:48 -07:00
|
|
|
],
|
|
|
|
"config": defaultConfig
|
2015-03-20 00:09:55 -07:00
|
|
|
};
|
|
|
|
var actualResult = markdownlint.sync(options);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {
|
|
|
|
"MD002": [ 3 ],
|
|
|
|
"MD018": [ 1 ],
|
|
|
|
"MD019": [ 3, 5 ]
|
|
|
|
},
|
|
|
|
"./test/first_header_bad_atx.md": {
|
|
|
|
"MD002": [ 1 ]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
var actualMessage = actualResult.toString();
|
|
|
|
var expectedMessage =
|
|
|
|
"./test/atx_header_spacing.md: 3: MD002" +
|
|
|
|
" First header should be a h1 header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 1: MD018" +
|
|
|
|
" No space after hash on atx style header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 3: MD019" +
|
|
|
|
" Multiple spaces after hash on atx style header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 5: MD019" +
|
|
|
|
" Multiple spaces after hash on atx style header\n" +
|
|
|
|
"./test/first_header_bad_atx.md: 1: MD002" +
|
|
|
|
" First header should be a h1 header";
|
2016-01-12 21:29:17 -08:00
|
|
|
test.equal(actualMessage, expectedMessage, "Incorrect message (name).");
|
|
|
|
actualMessage = actualResult.toString(true);
|
|
|
|
expectedMessage =
|
|
|
|
"./test/atx_header_spacing.md: 3: first-header-h1" +
|
|
|
|
" First header should be a h1 header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 1: no-missing-space-atx" +
|
|
|
|
" No space after hash on atx style header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 3: no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style header\n" +
|
|
|
|
"./test/atx_header_spacing.md: 5: no-multiple-space-atx" +
|
|
|
|
" Multiple spaces after hash on atx style header\n" +
|
|
|
|
"./test/first_header_bad_atx.md: 1: first-header-h1" +
|
|
|
|
" First header should be a h1 header";
|
|
|
|
test.equal(actualMessage, expectedMessage, "Incorrect message (alias).");
|
2015-03-20 00:09:55 -07:00
|
|
|
test.done();
|
|
|
|
};
|
|
|
|
|
2015-04-29 18:46:52 -07:00
|
|
|
module.exports.stringInputLineEndings = function stringInputLineEndings(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"strings": {
|
2015-05-02 17:41:41 -07:00
|
|
|
"cr": "One\rTwo\r#Three",
|
2015-04-29 18:46:52 -07:00
|
|
|
"lf": "One\nTwo\n#Three",
|
|
|
|
"crlf": "One\r\nTwo\r\n#Three",
|
2015-05-02 17:41:41 -07:00
|
|
|
"mixed": "One\rTwo\n#Three"
|
2015-07-20 22:06:48 -07:00
|
|
|
},
|
|
|
|
"config": defaultConfig
|
2015-04-29 18:46:52 -07:00
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
2015-05-02 17:41:41 -07:00
|
|
|
"cr": { "MD018": [ 3 ] },
|
2015-04-29 18:46:52 -07:00
|
|
|
"lf": { "MD018": [ 3 ] },
|
|
|
|
"crlf": { "MD018": [ 3 ] },
|
|
|
|
"mixed": { "MD018": [ 3 ] }
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-07-22 23:17:08 -07:00
|
|
|
module.exports.inputOnlyNewline = function inputOnlyNewline(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"strings": {
|
|
|
|
"cr": "\r",
|
|
|
|
"lf": "\n",
|
|
|
|
"crlf": "\r\n"
|
|
|
|
},
|
|
|
|
"config": {
|
|
|
|
"default": false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"cr": {},
|
|
|
|
"lf": {},
|
|
|
|
"crlf": {}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-16 23:25:06 -07:00
|
|
|
module.exports.defaultTrue = function defaultTrue(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"default": true
|
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {
|
|
|
|
"MD002": [ 3 ],
|
|
|
|
"MD018": [ 1 ],
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD019": [ 3, 5 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-03-16 23:25:06 -07:00
|
|
|
},
|
|
|
|
"./test/first_header_bad_atx.md": {
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD002": [ 1 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-03-16 23:25:06 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.defaultFalse = function defaultFalse(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"default": false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {},
|
|
|
|
"./test/first_header_bad_atx.md": {}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-18 22:45:51 -07:00
|
|
|
module.exports.defaultUndefined = function defaultUndefined(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {
|
|
|
|
"MD002": [ 3 ],
|
|
|
|
"MD018": [ 1 ],
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD019": [ 3, 5 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-03-18 22:45:51 -07:00
|
|
|
},
|
|
|
|
"./test/first_header_bad_atx.md": {
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD002": [ 1 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-03-18 22:45:51 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-16 23:25:06 -07:00
|
|
|
module.exports.disableRules = function disableRules(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"MD002": false,
|
|
|
|
"default": true,
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD019": false,
|
2016-01-12 21:29:17 -08:00
|
|
|
"first-line-h1": false
|
2015-03-16 23:25:06 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {
|
|
|
|
"MD018": [ 1 ]
|
|
|
|
},
|
|
|
|
"./test/first_header_bad_atx.md": {}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.enableRules = function enableRules(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"MD002": true,
|
|
|
|
"default": false,
|
2016-01-12 21:29:17 -08:00
|
|
|
"no-multiple-space-atx": true
|
2015-03-16 23:25:06 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {
|
|
|
|
"MD002": [ 3 ],
|
|
|
|
"MD019": [ 3, 5 ]
|
|
|
|
},
|
|
|
|
"./test/first_header_bad_atx.md": {
|
|
|
|
"MD002": [ 1 ]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-09-21 23:21:17 -07:00
|
|
|
module.exports.enableRulesMixedCase = function enableRulesMixedCase(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"Md002": true,
|
|
|
|
"DeFaUlT": false,
|
2016-01-12 21:29:17 -08:00
|
|
|
"nO-mUlTiPlE-sPaCe-AtX": true
|
2015-09-21 23:21:17 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {
|
|
|
|
"MD002": [ 3 ],
|
|
|
|
"MD019": [ 3, 5 ]
|
|
|
|
},
|
|
|
|
"./test/first_header_bad_atx.md": {
|
|
|
|
"MD002": [ 1 ]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-16 23:25:06 -07:00
|
|
|
module.exports.disableTag = function disableTag(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"default": true,
|
|
|
|
"spaces": false
|
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD002": [ 3 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-03-16 23:25:06 -07:00
|
|
|
},
|
|
|
|
"./test/first_header_bad_atx.md": {
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD002": [ 1 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-03-16 23:25:06 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.enableTag = function enableTag(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"default": false,
|
2015-09-26 16:55:33 -07:00
|
|
|
"spaces": true,
|
|
|
|
"notatag": true
|
2015-03-16 23:25:06 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {
|
|
|
|
"MD018": [ 1 ],
|
|
|
|
"MD019": [ 3, 5 ]
|
|
|
|
},
|
|
|
|
"./test/first_header_bad_atx.md": {}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-09-21 23:21:17 -07:00
|
|
|
module.exports.enableTagMixedCase = function enableTagMixedCase(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
|
|
|
],
|
|
|
|
"config": {
|
|
|
|
"DeFaUlT": false,
|
2015-09-26 16:55:33 -07:00
|
|
|
"SpAcEs": true,
|
|
|
|
"NoTaTaG": true
|
2015-09-21 23:21:17 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/atx_header_spacing.md": {
|
|
|
|
"MD018": [ 1 ],
|
|
|
|
"MD019": [ 3, 5 ]
|
|
|
|
},
|
|
|
|
"./test/first_header_bad_atx.md": {}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-17 22:34:47 -07:00
|
|
|
module.exports.styleFiles = function styleFiles(test) {
|
|
|
|
test.expect(4);
|
|
|
|
fs.readdir("./style", function readdir(err, files) {
|
|
|
|
test.ifError(err);
|
|
|
|
files.forEach(function forFile(file) {
|
|
|
|
test.ok(require(path.join("../style", file)), "Unable to load/parse.");
|
|
|
|
});
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-17 18:02:05 -07:00
|
|
|
module.exports.styleAll = function styleAll(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [ "./test/break-all-the-rules.md" ],
|
|
|
|
"config": require("../style/all.json")
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/break-all-the-rules.md": {
|
|
|
|
"MD001": [ 3 ],
|
|
|
|
"MD002": [ 1 ],
|
|
|
|
"MD003": [ 5, 30 ],
|
|
|
|
"MD004": [ 8 ],
|
|
|
|
"MD005": [ 12 ],
|
|
|
|
"MD006": [ 8 ],
|
|
|
|
"MD007": [ 8, 11 ],
|
|
|
|
"MD009": [ 14 ],
|
|
|
|
"MD010": [ 14 ],
|
|
|
|
"MD011": [ 16 ],
|
|
|
|
"MD012": [ 18 ],
|
|
|
|
"MD013": [ 21 ],
|
|
|
|
"MD014": [ 23 ],
|
|
|
|
"MD018": [ 25 ],
|
|
|
|
"MD019": [ 27 ],
|
|
|
|
"MD020": [ 29 ],
|
|
|
|
"MD021": [ 30 ],
|
|
|
|
"MD022": [ 30 ],
|
|
|
|
"MD023": [ 30 ],
|
|
|
|
"MD024": [ 34 ],
|
|
|
|
"MD026": [ 40 ],
|
|
|
|
"MD027": [ 42 ],
|
|
|
|
"MD028": [ 43 ],
|
|
|
|
"MD029": [ 47 ],
|
|
|
|
"MD030": [ 8 ],
|
|
|
|
"MD031": [ 50 ],
|
2015-04-16 09:39:04 -07:00
|
|
|
"MD032": [ 51 ],
|
|
|
|
"MD033": [ 55 ],
|
|
|
|
"MD034": [ 57 ],
|
|
|
|
"MD035": [ 61 ],
|
|
|
|
"MD036": [ 65 ],
|
|
|
|
"MD037": [ 67 ],
|
|
|
|
"MD038": [ 69 ],
|
|
|
|
"MD039": [ 71 ],
|
2015-07-20 22:06:48 -07:00
|
|
|
"MD040": [ 73 ],
|
|
|
|
"MD041": [ 1 ]
|
2015-03-17 18:02:05 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.styleRelaxed = function styleRelaxed(test) {
|
|
|
|
test.expect(2);
|
|
|
|
var options = {
|
|
|
|
"files": [ "./test/break-all-the-rules.md" ],
|
|
|
|
"config": require("../style/relaxed.json")
|
|
|
|
};
|
|
|
|
markdownlint(options, function callback(err, actualResult) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"./test/break-all-the-rules.md": {
|
|
|
|
"MD001": [ 3 ],
|
|
|
|
"MD002": [ 1 ],
|
|
|
|
"MD003": [ 5, 30 ],
|
|
|
|
"MD004": [ 8 ],
|
|
|
|
"MD005": [ 12 ],
|
|
|
|
"MD011": [ 16 ],
|
|
|
|
"MD014": [ 23 ],
|
|
|
|
"MD018": [ 25 ],
|
|
|
|
"MD019": [ 27 ],
|
|
|
|
"MD020": [ 29 ],
|
|
|
|
"MD021": [ 30 ],
|
|
|
|
"MD022": [ 30 ],
|
|
|
|
"MD023": [ 30 ],
|
|
|
|
"MD024": [ 34 ],
|
|
|
|
"MD026": [ 40 ],
|
|
|
|
"MD029": [ 47 ],
|
|
|
|
"MD031": [ 50 ],
|
2015-04-16 09:39:04 -07:00
|
|
|
"MD032": [ 51 ],
|
|
|
|
"MD035": [ 61 ],
|
|
|
|
"MD036": [ 65 ]
|
2015-03-17 18:02:05 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-07-25 22:18:30 -07:00
|
|
|
module.exports.nullFrontMatter = function nullFrontMatter(test) {
|
|
|
|
test.expect(2);
|
|
|
|
markdownlint({
|
|
|
|
"strings": {
|
|
|
|
"content": "---\n\t\n---\n# Header\n"
|
|
|
|
},
|
|
|
|
"frontMatter": null,
|
|
|
|
"config": {
|
|
|
|
"default": false,
|
|
|
|
"MD010": true
|
|
|
|
}
|
|
|
|
}, function callback(err, result) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"content": { "MD010": [ 2 ] }
|
|
|
|
};
|
|
|
|
test.deepEqual(result, expectedResult, "Undetected issues.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.customFrontMatter = function customFrontMatter(test) {
|
|
|
|
test.expect(2);
|
|
|
|
markdownlint({
|
|
|
|
"strings": {
|
|
|
|
"content": "<head>\n\t\n</head>\n# Header\n"
|
|
|
|
},
|
|
|
|
"frontMatter": /<head>[^]*<\/head>/,
|
|
|
|
"config": {
|
|
|
|
"default": false,
|
|
|
|
"MD010": true
|
|
|
|
}
|
|
|
|
}, function callback(err, result) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"content": {}
|
|
|
|
};
|
|
|
|
test.deepEqual(result, expectedResult, "Did not get empty results.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-04-29 18:46:52 -07:00
|
|
|
module.exports.filesArrayNotModified = function filesArrayNotModified(test) {
|
2015-03-13 18:20:56 -07:00
|
|
|
test.expect(2);
|
|
|
|
var files = [
|
|
|
|
"./test/atx_header_spacing.md",
|
|
|
|
"./test/first_header_bad_atx.md"
|
|
|
|
];
|
|
|
|
var expectedFiles = files.slice();
|
|
|
|
markdownlint({ "files": files }, function callback(err) {
|
|
|
|
test.ifError(err);
|
|
|
|
test.deepEqual(files, expectedFiles, "Files modified.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-03-11 21:13:21 -07:00
|
|
|
module.exports.missingOptions = function missingOptions(test) {
|
|
|
|
test.expect(2);
|
|
|
|
markdownlint(null, function callback(err, result) {
|
|
|
|
test.ifError(err);
|
2015-04-29 18:46:52 -07:00
|
|
|
test.deepEqual(result, {}, "Did not get empty result for missing options.");
|
2015-03-11 21:13:21 -07:00
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-04-29 18:46:52 -07:00
|
|
|
module.exports.missingFilesAndStrings = function missingFilesAndStrings(test) {
|
2015-03-11 21:13:21 -07:00
|
|
|
test.expect(2);
|
|
|
|
markdownlint({}, function callback(err, result) {
|
|
|
|
test.ifError(err);
|
2015-04-29 18:46:52 -07:00
|
|
|
test.ok(result, "Did not get result for missing files/strings.");
|
2015-03-11 21:13:21 -07:00
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.missingCallback = function missingCallback(test) {
|
|
|
|
test.expect(0);
|
|
|
|
markdownlint();
|
|
|
|
test.done();
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.badFile = function badFile(test) {
|
2015-03-20 00:09:55 -07:00
|
|
|
test.expect(4);
|
2015-03-11 21:13:21 -07:00
|
|
|
markdownlint({
|
|
|
|
"files": [ "./badFile" ]
|
|
|
|
}, function callback(err, result) {
|
|
|
|
test.ok(err, "Did not get an error for bad file.");
|
2015-03-20 00:09:55 -07:00
|
|
|
test.ok(err instanceof Error, "Error not instance of Error.");
|
2015-03-11 21:13:21 -07:00
|
|
|
test.equal(err.code, "ENOENT", "Error code for bad file not ENOENT.");
|
|
|
|
test.ok(!result, "Got result for bad file.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
2015-03-17 22:34:47 -07:00
|
|
|
|
2015-03-20 00:09:55 -07:00
|
|
|
module.exports.badFileSync = function badFileSync(test) {
|
2015-04-29 18:46:52 -07:00
|
|
|
test.expect(4);
|
2015-03-20 00:09:55 -07:00
|
|
|
test.throws(function badFileCall() {
|
|
|
|
markdownlint.sync({
|
|
|
|
"files": [ "./badFile" ]
|
|
|
|
});
|
|
|
|
}, function testError(err) {
|
2015-04-29 18:46:52 -07:00
|
|
|
test.ok(err, "Did not get an error for bad file.");
|
2015-03-20 00:09:55 -07:00
|
|
|
test.ok(err instanceof Error, "Error not instance of Error.");
|
|
|
|
test.equal(err.code, "ENOENT", "Error code for bad file not ENOENT.");
|
|
|
|
return true;
|
|
|
|
}, "Did not get exception for bad file.");
|
|
|
|
test.done();
|
|
|
|
};
|
|
|
|
|
2015-04-29 18:46:52 -07:00
|
|
|
module.exports.missingStringValue = function missingStringValue(test) {
|
|
|
|
test.expect(2);
|
|
|
|
markdownlint({
|
|
|
|
"strings": {
|
|
|
|
"undefined": undefined,
|
|
|
|
"null": null,
|
|
|
|
"empty": ""
|
2015-07-20 22:06:48 -07:00
|
|
|
},
|
|
|
|
"config": defaultConfig
|
2015-04-29 18:46:52 -07:00
|
|
|
}, function callback(err, result) {
|
|
|
|
test.ifError(err);
|
|
|
|
var expectedResult = {
|
|
|
|
"undefined": {},
|
|
|
|
"null": {},
|
|
|
|
"empty": {}
|
|
|
|
};
|
|
|
|
test.deepEqual(result, expectedResult, "Did not get empty results.");
|
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-09-21 23:21:17 -07:00
|
|
|
module.exports.ruleNamesUpperCase = function ruleNamesUpperCase(test) {
|
|
|
|
test.expect(37);
|
|
|
|
rules.forEach(function forRule(rule) {
|
|
|
|
test.equal(rule.name, rule.name.toUpperCase(), "Rule name not upper-case.");
|
|
|
|
});
|
|
|
|
test.done();
|
|
|
|
};
|
|
|
|
|
2016-01-12 21:29:17 -08:00
|
|
|
module.exports.uniqueAliases = function uniqueAliases(test) {
|
|
|
|
test.expect(74);
|
|
|
|
var tags = [];
|
|
|
|
rules.forEach(function forRule(rule) {
|
|
|
|
Array.prototype.push.apply(tags, rule.tags);
|
|
|
|
});
|
|
|
|
var aliases = [];
|
|
|
|
rules.forEach(function forRule(rule) {
|
|
|
|
rule.aliases.forEach(function forAlias(alias) {
|
|
|
|
test.ok(tags.indexOf(alias) === -1, "Alias not unique in tags.");
|
|
|
|
test.ok(aliases.indexOf(alias) === -1, "Alias not unique in aliases.");
|
|
|
|
aliases.push(alias);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
test.done();
|
|
|
|
};
|
|
|
|
|
2015-03-17 22:34:47 -07:00
|
|
|
module.exports.readme = function readme(test) {
|
2015-07-20 22:06:48 -07:00
|
|
|
test.expect(97);
|
2015-04-14 00:01:57 -07:00
|
|
|
var tagToRules = {};
|
|
|
|
rules.forEach(function forRule(rule) {
|
|
|
|
rule.tags.forEach(function forTag(tag) {
|
|
|
|
var tagRules = tagToRules[tag] || [];
|
|
|
|
tagRules.push(rule.name);
|
|
|
|
tagToRules[tag] = tagRules;
|
|
|
|
});
|
|
|
|
});
|
2015-03-17 22:34:47 -07:00
|
|
|
fs.readFile("README.md", shared.utf8Encoding,
|
|
|
|
function readFile(err, contents) {
|
|
|
|
test.ifError(err);
|
|
|
|
var rulesLeft = rules.slice();
|
|
|
|
var seenRules = false;
|
|
|
|
var inRules = false;
|
|
|
|
var seenTags = false;
|
|
|
|
var inTags = false;
|
|
|
|
md.parse(contents, {}).forEach(function forToken(token) {
|
|
|
|
if (token.type === "bullet_list_open") {
|
|
|
|
if (!seenRules) {
|
|
|
|
seenRules = true;
|
|
|
|
inRules = true;
|
|
|
|
} else if (!seenTags) {
|
|
|
|
seenTags = true;
|
|
|
|
inTags = true;
|
|
|
|
}
|
|
|
|
} else if (token.type === "bullet_list_close") {
|
|
|
|
inRules = false;
|
|
|
|
inTags = false;
|
|
|
|
} else if (token.type === "inline") {
|
|
|
|
if (inRules) {
|
|
|
|
var rule = rulesLeft.shift();
|
2015-04-14 00:01:57 -07:00
|
|
|
test.ok(rule,
|
|
|
|
"Missing rule implementation for " + token.content + ".");
|
|
|
|
if (rule) {
|
2016-01-12 21:29:17 -08:00
|
|
|
var expected = "**" + rule.name + "** *" +
|
|
|
|
rule.aliases.join(", ") + "* - " + rule.desc;
|
2015-04-14 00:01:57 -07:00
|
|
|
test.equal(token.content, expected, "Rule mismatch.");
|
|
|
|
}
|
2015-03-17 22:34:47 -07:00
|
|
|
} else if (inTags) {
|
|
|
|
var parts = token.content.replace(/\*\*/g, "").split(/ - |, |,\n/);
|
|
|
|
var tag = parts.shift();
|
2015-04-14 00:01:57 -07:00
|
|
|
test.deepEqual(parts, tagToRules[tag] || [],
|
|
|
|
"Rule mismatch for tag " + tag + ".");
|
|
|
|
delete tagToRules[tag];
|
2015-03-17 22:34:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-04-14 00:01:57 -07:00
|
|
|
var ruleLeft = rulesLeft.shift();
|
|
|
|
test.ok(!ruleLeft,
|
|
|
|
"Missing rule documentation for " + (ruleLeft || {}).name + ".");
|
|
|
|
var tagLeft = Object.keys(tagToRules).shift();
|
|
|
|
test.ok(!tagLeft, "Undocumented tag " + tagLeft + ".");
|
2015-03-17 22:34:47 -07:00
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.doc = function doc(test) {
|
2016-01-12 21:29:17 -08:00
|
|
|
test.expect(274);
|
2015-03-17 22:34:47 -07:00
|
|
|
fs.readFile("doc/Rules.md", shared.utf8Encoding,
|
|
|
|
function readFile(err, contents) {
|
|
|
|
test.ifError(err);
|
|
|
|
var rulesLeft = rules.slice();
|
|
|
|
var inHeading = false;
|
|
|
|
var rule = null;
|
2015-12-13 21:42:51 -08:00
|
|
|
var ruleHasTags = true;
|
2016-01-12 21:29:17 -08:00
|
|
|
var ruleHasAliases = true;
|
2015-12-13 21:42:51 -08:00
|
|
|
var ruleUsesParams = null;
|
2016-01-12 21:29:17 -08:00
|
|
|
var tagAliasParameterRe = /, |: | /;
|
|
|
|
function testTagsAliasesParams() {
|
2015-12-13 21:42:51 -08:00
|
|
|
test.ok(ruleHasTags,
|
|
|
|
"Missing tags for rule " + (rule || {}).name + ".");
|
2016-01-12 21:29:17 -08:00
|
|
|
test.ok(ruleHasAliases,
|
|
|
|
"Missing aliases for rule " + (rule || {}).name + ".");
|
2015-12-13 21:42:51 -08:00
|
|
|
test.ok(!ruleUsesParams,
|
|
|
|
"Missing parameters for rule " + (rule || {}).name + ".");
|
|
|
|
}
|
2015-03-17 22:34:47 -07:00
|
|
|
md.parse(contents, {}).forEach(function forToken(token) {
|
2015-03-18 23:14:44 -07:00
|
|
|
if ((token.type === "heading_open") && (token.tag === "h2")) {
|
2015-03-17 22:34:47 -07:00
|
|
|
inHeading = true;
|
|
|
|
} else if (token.type === "heading_close") {
|
|
|
|
inHeading = false;
|
|
|
|
} else if (token.type === "inline") {
|
|
|
|
if (inHeading) {
|
2016-01-12 21:29:17 -08:00
|
|
|
testTagsAliasesParams();
|
2015-03-17 22:34:47 -07:00
|
|
|
rule = rulesLeft.shift();
|
2016-01-12 21:29:17 -08:00
|
|
|
ruleHasTags = ruleHasAliases = false;
|
2015-04-14 00:01:57 -07:00
|
|
|
test.ok(rule,
|
|
|
|
"Missing rule implementation for " + token.content + ".");
|
2015-12-13 21:42:51 -08:00
|
|
|
test.equal(token.content, rule.name + " - " + rule.desc,
|
|
|
|
"Rule mismatch.");
|
|
|
|
ruleUsesParams = rule.func.toString()
|
|
|
|
.match(/params\.options\.[_a-z]*/gi);
|
|
|
|
if (ruleUsesParams) {
|
|
|
|
ruleUsesParams = ruleUsesParams.map(function forUse(use) {
|
|
|
|
return use.split(".").pop();
|
|
|
|
});
|
2015-04-14 00:01:57 -07:00
|
|
|
}
|
|
|
|
} else if (/^Tags: /.test(token.content) && rule) {
|
2016-01-12 21:29:17 -08:00
|
|
|
test.deepEqual(token.content.split(tagAliasParameterRe).slice(1),
|
|
|
|
rule.tags, "Tag mismatch for rule " + rule.name + ".");
|
2015-12-13 21:42:51 -08:00
|
|
|
ruleHasTags = true;
|
2016-01-12 21:29:17 -08:00
|
|
|
} else if (/^Aliases: /.test(token.content) && rule) {
|
|
|
|
test.deepEqual(token.content.split(tagAliasParameterRe).slice(1),
|
|
|
|
rule.aliases, "Alias mismatch for rule " + rule.name + ".");
|
|
|
|
ruleHasAliases = true;
|
2015-12-13 21:42:51 -08:00
|
|
|
} else if (/^Parameters: /.test(token.content) && rule) {
|
|
|
|
var inDetails = false;
|
2016-01-12 21:29:17 -08:00
|
|
|
var parameters = token.content.split(tagAliasParameterRe)
|
2015-12-13 21:42:51 -08:00
|
|
|
.slice(1)
|
|
|
|
.filter(function forPart(part) {
|
|
|
|
inDetails = inDetails || (part[0] === "(");
|
|
|
|
return !inDetails;
|
|
|
|
});
|
|
|
|
test.deepEqual(parameters, ruleUsesParams,
|
|
|
|
"Missing parameter for rule " + rule.name);
|
|
|
|
ruleUsesParams = null;
|
2015-03-17 22:34:47 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-04-14 00:01:57 -07:00
|
|
|
var ruleLeft = rulesLeft.shift();
|
|
|
|
test.ok(!ruleLeft,
|
|
|
|
"Missing rule documentation for " + (ruleLeft || {}).name + ".");
|
2016-01-12 21:29:17 -08:00
|
|
|
testTagsAliasesParams();
|
2015-03-17 22:34:47 -07:00
|
|
|
test.done();
|
|
|
|
});
|
|
|
|
};
|
2015-05-07 17:42:13 -07:00
|
|
|
|
|
|
|
module.exports.typeAllFiles = function typeAllFiles(test) {
|
|
|
|
// Simulates typing each test file to validate handling of partial input
|
2015-09-07 14:04:28 -07:00
|
|
|
function validate(file, content) {
|
|
|
|
var results = markdownlint.sync({
|
|
|
|
"strings": {
|
|
|
|
"content": content
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var contentLineCount = content.split(shared.newLineRe).length;
|
|
|
|
Object.keys(results.content).forEach(function forKey(ruleName) {
|
|
|
|
results.content[ruleName].forEach(function forLine(line) {
|
|
|
|
test.ok((line >= 1) && (line <= contentLineCount),
|
|
|
|
"Line number out of range: " + line +
|
|
|
|
" (" + file + ", " + content.length + ", " + ruleName + ")");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2015-05-07 17:42:13 -07:00
|
|
|
var files = fs.readdirSync("./test");
|
|
|
|
files.forEach(function forFile(file) {
|
|
|
|
if (/\.md$/.test(file)) {
|
|
|
|
var content = fs.readFileSync(
|
|
|
|
path.join("./test", file), shared.utf8Encoding);
|
|
|
|
while (content) {
|
2015-09-07 14:04:28 -07:00
|
|
|
validate(file, content);
|
2015-05-07 17:42:13 -07:00
|
|
|
content = content.slice(0, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
test.done();
|
|
|
|
};
|
2015-05-03 22:40:34 -07:00
|
|
|
|
|
|
|
module.exports.trimPolyfills = function trimPolyfills(test) {
|
|
|
|
var inputs = [
|
|
|
|
"text text",
|
|
|
|
" text text ",
|
|
|
|
" text text ",
|
|
|
|
// ECMAScript Whitespace
|
|
|
|
"\u0009 text text \u0009",
|
|
|
|
"\u000b text text \u000b",
|
|
|
|
"\u000c text text \u000c",
|
|
|
|
"\u0020 text text \u0020",
|
|
|
|
"\u00a0 text text \u00a0",
|
|
|
|
"\ufeff text text \ufeff",
|
|
|
|
// ECMAScript LineTerminator
|
|
|
|
"\u000a text text \u000a",
|
|
|
|
"\u000d text text \u000d",
|
|
|
|
"\u2028 text text \u2028",
|
|
|
|
"\u2029 text text \u2029"
|
|
|
|
];
|
|
|
|
test.expect(inputs.length * 2);
|
|
|
|
inputs.forEach(function forInput(input) {
|
|
|
|
test.equal(polyfills.trimLeftPolyfill.call(input), input.trimLeft(),
|
|
|
|
"trimLeft incorrect for '" + input + "'");
|
|
|
|
test.equal(polyfills.trimRightPolyfill.call(input), input.trimRight(),
|
|
|
|
"trimRight incorrect for '" + input + "'");
|
|
|
|
});
|
|
|
|
test.done();
|
|
|
|
};
|