UNPKG

1.23 kBJavaScriptView Raw
1var test = require('tape'),
2 wildcard = require('../');
3
4test('general wild card matching tests', function(t) {
5
6 t.plan(5);
7 t.ok(wildcard('foo.*', 'foo.bar'), 'foo.* should match foo.bar');
8 t.ok(wildcard('foo.*', 'foo'), 'foo.* should match foo');
9 t.notOk(wildcard('foo.*', 'bar'), 'foo.* should not match bar');
10 t.ok(wildcard('a.*.c', 'a.b.c'), 'a.*.c should match a.b.c');
11 t.notOk(wildcard('a.*.c', 'a.b'), 'a.*.c should not match a.b');
12});
13
14test('general wild card with separator matching tests', function(t) {
15
16 t.plan(5);
17 t.ok(wildcard('foo:*', 'foo:bar', ':'), 'foo:* should match foo:bar');
18 t.ok(wildcard('foo:*', 'foo', ':'), 'foo:* should match foo');
19 t.notOk(wildcard('foo:*', 'bar', ':'), 'foo:* should not match bar');
20 t.ok(wildcard('a:*:c', 'a:b:c', ':'), 'a:*:c should match a:b:c');
21 t.notOk(wildcard('a:*:c', 'a:b', ':'), 'a:*:c should not match a:b');
22});
23
24test('general wild card with tokens being returned', function(t) {
25
26 t.plan(5);
27 var parts = wildcard('foo.*', 'foo.bar');
28 t.ok(parts);
29 t.equal(parts.length, 2);
30 t.equal(parts[0], 'foo');
31 t.equal(parts[1], 'bar');
32
33 parts = wildcard('foo.*', 'not.matching');
34 t.notOk(parts);
35});