forked from ageitgey/node-unfluff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest-setup.js
43 lines (37 loc) · 1.6 KB
/
test-setup.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
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS203: Remove `|| {}` from converted for-own loops
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const path = require('path');
const util = require('util');
const fs = require('fs');
const deepEqual = require('deep-equal');
const object = require('assert');
for (let name in object) { const func = object[name]; global[name] = func; }
// See http://wiki.ecmascript.org/doku.php?id=harmony:egal
const egal = function(a, b) {
if (a === b) {
return (a !== 0) || ((1/a) === (1/b));
} else {
return (a !== a) && (b !== b);
}
};
// A recursive functional equivalence helper; uses egal for testing equivalence.
var arrayEgal = function(a, b) {
if (egal(a, b)) { return true;
} else if ((Array.isArray(a)) && Array.isArray(b)) {
if (a.length !== b.length) { return false; }
for (let idx = 0; idx < a.length; idx++) { const el = a[idx]; if (!arrayEgal(el, b[idx])) { return false; } }
return true;
}
};
global.inspect = o => util.inspect(o, false, 2, true);
global.eq = (a, b, msg) => ok(egal(a, b), msg != null ? msg : `${inspect(a)} === ${inspect(b)}`);
global.arrayEq = (a, b, msg) => ok(arrayEgal(a, b), msg != null ? msg : `${inspect(a)} === ${inspect(b)}`);
global.deepEq = (a, b, msg) => ok(deepEqual(a, b), msg != null ? msg : `${inspect(a)} === ${inspect(b)}`);
global.fs = fs;
const object1 = require('./');
for (let k of Object.keys(object1 || {})) { const v = object1[k]; global[k] = v; }