forked from anseki/leader-line
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
60 lines (52 loc) · 1.79 KB
/
util.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
(function() {
'use strict';
/**
* @param {Array} log - `traceLog.log`.
* @param {(string|string[])[]} keys - Each key is `'<setOptions>', '<position>'` or
* `['<updateLine>', 'lineColor']` to check the sequence.
* @returns {boolean} `true` if all `keys` are contained.
*/
function toContainAll(log, keys) {
var logSeq;
function containsSequence(keys) {
var ERR_MSG = '\\f that is used as marker is included.', keysSeq;
if (logSeq == null) {
if (log.join('').indexOf('\f') > -1) { throw new Error(ERR_MSG); }
logSeq = '\f' + log.join('\f') + '\f';
}
if (keys.join('').indexOf('\f') > -1) { throw new Error(ERR_MSG); }
keysSeq = '\f' + keys.join('\f') + '\f';
return logSeq.indexOf(keysSeq) > -1;
}
return Array.isArray(log) && Array.isArray(keys) &&
keys.every(function(key) {
return Array.isArray(key) ? containsSequence(key) : log.indexOf(key) > -1;
});
}
window.toContainAll = toContainAll;
/**
* @param {Array} log - `traceLog.log`.
* @param {string[]} keys - Each key is `'<setOptions>', '<position>'`.
* @returns {boolean} `true` if all `keys` are not contained.
*/
function toNotContainAny(log, keys) {
return Array.isArray(log) && Array.isArray(keys) &&
keys.every(function(key) {
return log.indexOf(key) === -1;
});
}
window.toNotContainAny = toNotContainAny;
var customMatchers = {
toContainAll: function() {
return {compare: function(actual, expected) {
return {pass: toContainAll(actual, expected)};
}};
},
toNotContainAny: function() {
return {compare: function(actual, expected) {
return {pass: toNotContainAny(actual, expected)};
}};
}
};
window.customMatchers = customMatchers;
})();