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
53 lines (38 loc) · 1.48 KB
/
Copy pathUtilities.ts
File metadata and controls
53 lines (38 loc) · 1.48 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
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[]) {
for(var i=0;i<Math.max(b.length, a.length);i++) { // @TODO should be Math.max I think -- domasx2
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);
// I think this is surprising behaviour. null !== undefined, test lib should be strict about it -- domasx2
if ((typeof a === 'undefined' || a === null) && (typeof b === 'undefined' || b === null))
return true;
return a === b;
};