forked from ffMathy/FluffySpoon.JavaScript.Testing.Faking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.ts
More file actions
54 lines (39 loc) · 1.35 KB
/
Copy pathUtilities.ts
File metadata and controls
54 lines (39 loc) · 1.35 KB
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
import { Argument, AllArguments } from "./Arguments";
import util = require('util')
export type Call = any[] // list of args
export function stringifyArguments(args: any[]) {
args = args.map(x => util.inspect(x));
return args && args.length > 0 ? 'arguments [' + args.join(', ') + ']' : 'no arguments';
};
export function areArgumentArraysEqual(a: any[], b: any[]) {
if (a.find(x => x instanceof AllArguments) || b.find(b => b instanceof AllArguments)) {
return true;
}
for (var i = 0; i < Math.max(b.length, a.length); i++) {
if (!areArgumentsEqual(b[i], a[i])) {
return false;
}
}
return true;
}
export function stringifyCalls(calls: Call[]) {
if(calls.length === 0)
return ' (no calls)';
let output = '';
for (let call of calls) {
output += '\n-> call with ' + (call.length ? stringifyArguments(call) : '(no arguments)')
}
return output;
};
export function areArgumentsEqual(a: any, b: any) {
if(a instanceof Argument && b instanceof Argument) {
return false;
}
if(a instanceof AllArguments || b instanceof AllArguments)
return true;
if(a instanceof Argument)
return a.matches(b);
if(b instanceof Argument)
return b.matches(a);
return a === b;
};