4 // helpers used on the specs
8 var _fs = require('fs');
9 var _path = require('path');
10 var stripJsonComments = require('strip-json-comments');
17 exports.COMPARE_FOLDER = _path.join(__dirname, 'compare');
23 exports.readIn = function(id) {
24 return exports.readFile(_path.join(exports.COMPARE_FOLDER, id + '-in.js'));
28 exports.readOut = function(id) {
29 return exports.readFile(_path.join(exports.COMPARE_FOLDER, id + '-out.js'));
33 exports.readConfig = function(id) {
34 var filePath = _path.join(exports.COMPARE_FOLDER, id + '-config.json');
35 return JSON.parse(stripJsonComments(exports.readFile(filePath) + '\n'));
39 exports.readFile = function(path) {
40 // we cache the results to avoid redundant I/O
41 if (!(path in exports.CACHE)) {
42 exports.CACHE[path] = exports.lineFeed(_fs.readFileSync(path).toString());
44 return exports.CACHE[path];
48 exports.purge = function(dir) {
49 if (!exports.SHOULD_PURGE) return;
50 _fs.readdirSync(dir).forEach(function(relPath) {
51 var path = _path.join(dir, relPath);
52 if (_fs.statSync(path).isDirectory()) {
62 exports.mkdir = function(dir) {
63 if (!_fs.existsSync(dir)) {
68 exports.lineFeed = function(text) {
69 return text.replace(/\r\n?|[\n\u2028\u2029]/g, "\n");