-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
api.matchKeys.js
47 lines (40 loc) · 1.7 KB
/
api.matchKeys.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
/*!
* nanomatch <https://github.com/jonschlinkert/nanomatch>
*
* Copyright (c) 2016, Jon Schlinkert.
* Licensed under the MIT License.
*/
'use strict';
var assert = require('assert');
var nm = require('..');
describe('.matchKeys method', function() {
describe('error handling', function() {
it('should throw when the first argument is not an object', function() {
assert.throws(function() {
nm.matchKeys();
});
assert.throws(function() {
nm.matchKeys('foo');
});
assert.throws(function() {
nm.matchKeys(['foo']);
});
});
});
describe('match object keys', function() {
it('should return a new object with only keys that match the given glob pattern', function() {
assert.deepEqual(nm.matchKeys({a: 'a', b: 'b', c: 'c'}, '*'), {a: 'a', b: 'b', c: 'c'});
assert.deepEqual(nm.matchKeys({a: 'a', b: 'b', c: 'c'}, 'a'), {a: 'a'});
assert.deepEqual(nm.matchKeys({a: 'a', b: 'b', c: 'c'}, '[a-b]'), {a: 'a', b: 'b'});
assert.deepEqual(nm.matchKeys({a: 'a', b: 'b', c: 'c'}, '(a|c)'), {a: 'a', c: 'c'});
assert.notDeepEqual(nm.matchKeys({a: 'a', b: 'b', c: 'c'}, 'a'), {b: 'b'});
});
it('should return a new object with only keys that match a regex:', function() {
assert.deepEqual(nm.matchKeys({a: 'a', b: 'b', c: 'c'}, /.*/), {a: 'a', b: 'b', c: 'c'});
assert.deepEqual(nm.matchKeys({a: 'a', b: 'b', c: 'c'}, /a/), {a: 'a'});
assert.deepEqual(nm.matchKeys({a: 'a', b: 'b', c: 'c'}, /[a-b]/), {a: 'a', b: 'b'});
assert.deepEqual(nm.matchKeys({a: 'a', b: 'b', c: 'c'}, /(a|c)/), {a: 'a', c: 'c'});
assert.notDeepEqual(nm.matchKeys({a: 'a', b: 'b', c: 'c'}, /a/), {b: 'b'});
});
});
});