-
Notifications
You must be signed in to change notification settings - Fork 21
/
readme.js
58 lines (44 loc) · 1.66 KB
/
readme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @fileoverview Unit tests for the README.
* @author Kevin Partington
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
var assert = require("chai").assert,
fs = require("fs"),
path = require("path");
//------------------------------------------------------------------------------
// Tests
//------------------------------------------------------------------------------
describe("README", function () {
var ruleGroupRegex = /## Available Rules[\s\S]*(?:\n(?=##)|$)/,
ruleRegex = /^\* \[([a-z-]+)\]\(\.\/docs\/rules\/\1\.md\)$/gm,
fileContents,
availableRules;
before(function (done) {
fs.readFile("./README.md", "utf8", function (err, contents) {
if (err) throw err;
fileContents = contents;
fs.readdir("./lib/rules", function (err, files) {
if (err) throw err;
availableRules = files.map(function (file) {
return path.basename(file, ".js");
});
done();
});
});
});
it("should find the rules", function () {
var match = ruleGroupRegex.exec(fileContents),
foundRules = [],
ruleSection;
assert.ok(match, "Rule section should be present");
ruleSection = match[0];
while ((match = ruleRegex.exec(ruleSection)) !== null) {
foundRules.push(match[1]);
}
assert.deepEqual(foundRules, availableRules, "Rules in README should match available rules");
});
});