summaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2014-09-06 19:32:03 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2014-09-06 19:32:03 -0700
commit7c7d772c93a04958c695d7519e62f7b1560ecc45 (patch)
treee73138847394210a69fc3eebf15fffe430797dfd /js
parent9d53a1778c2416af37f1a9ee6caffb730f6669a5 (diff)
parent15d8fbee774d5847237eb8285921c7daf1161478 (diff)
Merge pull request #81 from BurtHarris/master
Resolve test.js line-ending sensitivity blocking running tests on Windows
Diffstat (limited to 'js')
-rwxr-xr-xjs/test.js19
1 files changed, 11 insertions, 8 deletions
diff --git a/js/test.js b/js/test.js
index b16b2f1..19c0c92 100755
--- a/js/test.js
+++ b/js/test.js
@@ -1,9 +1,8 @@
#!/usr/bin/env node
var fs = require('fs');
-var util = require('util');
var stmd = require('./stmd');
-var ansi = require('./ansi/ansi')
+var ansi = require('./ansi/ansi');
var cursor = ansi(process.stdout);
var writer = new stmd.HtmlRenderer();
@@ -15,19 +14,23 @@ var failed = 0;
var showSpaces = function(s) {
var t = s;
return t.replace(/\t/g,'→')
- .replace(/ /g,'␣');
-}
+ .replace(/ /g,'␣');
+};
fs.readFile('spec.txt', 'utf8', function(err, data) {
if (err) {
return console.log(err);
}
+ var i;
var examples = [];
var current_section = "";
var example_number = 0;
- tests = data.replace(/^<!-- END TESTS -->(.|[\n])*/m,'');
+ var tests = data
+ .replace(/\r\n?/g, "\n") // Normalize newlines for platform independence
+ .replace(/^<!-- END TESTS -->(.|[\n])*/m, '');
+
tests.replace(/^\.\n([\s\S]*?)^\.\n([\s\S]*?)^\.$|^#{1,6} *(.*)$/gm,
- function(_,x,y,z,w){
+ function(_,x,y,z){
if (z) {
current_section = z;
} else {
@@ -45,7 +48,7 @@ fs.readFile('spec.txt', 'utf8', function(err, data) {
for (i = 0; i < examples.length; i++) {
var example = examples[i];
- if (example.section != current_section) {
+ if (example.section !== current_section) {
if (current_section !== '') {
cursor.write('\n');
}
@@ -53,7 +56,7 @@ fs.readFile('spec.txt', 'utf8', function(err, data) {
cursor.reset().write(current_section).reset().write(' ');
}
var actual = writer.renderBlock(reader.parse(example.markdown.replace(/→/g, '\t')));
- if (actual == example.html) {
+ if (actual === example.html) {
passed++;
cursor.green().write('✓').reset();
} else {