[6a3a178] | 1 | var test = require('tape'),
|
---|
| 2 | wildcard = require('../');
|
---|
| 3 |
|
---|
| 4 | test('general wild card matching tests', function(t) {
|
---|
| 5 |
|
---|
| 6 | t.plan(8);
|
---|
| 7 | t.ok(wildcard('*', 'test'), '* should match test');
|
---|
| 8 | t.ok(wildcard('foo.*', 'foo.bar'), 'foo.* should match foo.bar');
|
---|
| 9 | t.ok(wildcard('foo.*', 'foo'), 'foo.* should match foo');
|
---|
| 10 | t.ok(wildcard('*.foo.com', 'test.foo.com'), 'test.foo.com should match *.foo.com');
|
---|
| 11 | t.notOk(wildcard('foo.*', 'bar'), 'foo.* should not match bar');
|
---|
| 12 | t.ok(wildcard('a.*.c', 'a.b.c'), 'a.*.c should match a.b.c');
|
---|
| 13 | t.notOk(wildcard('a.*.c', 'a.b'), 'a.*.c should not match a.b');
|
---|
| 14 | t.notOk(wildcard('a', 'a.b.c'), 'a should not match a.b.c');
|
---|
| 15 | });
|
---|
| 16 |
|
---|
| 17 | test('regex wildcard matching tests', function(t) {
|
---|
| 18 | t.plan(4);
|
---|
| 19 | t.ok(wildcard('*foo', 'foo'), '*foo should match foo');
|
---|
| 20 | t.ok(wildcard('*foo.b', 'foo.b'), '*foo.b should match foo.b');
|
---|
| 21 | t.ok(wildcard('a.*foo.c', 'a.barfoo.c'), 'a.barfoo.c should match a.*foo.c');
|
---|
| 22 | t.ok(wildcard('a.foo*.c', 'a.foobar.c'), 'a.foobar.c should match a.foo*.c');
|
---|
| 23 | });
|
---|
| 24 |
|
---|
| 25 | test('general wild card with separator matching tests', function(t) {
|
---|
| 26 |
|
---|
| 27 | t.plan(5);
|
---|
| 28 | t.ok(wildcard('foo:*', 'foo:bar', ':'), 'foo:* should match foo:bar');
|
---|
| 29 | t.ok(wildcard('foo:*', 'foo', ':'), 'foo:* should match foo');
|
---|
| 30 | t.notOk(wildcard('foo:*', 'bar', ':'), 'foo:* should not match bar');
|
---|
| 31 | t.ok(wildcard('a:*:c', 'a:b:c', ':'), 'a:*:c should match a:b:c');
|
---|
| 32 | t.notOk(wildcard('a:*:c', 'a:b', ':'), 'a:*:c should not match a:b');
|
---|
| 33 | });
|
---|
| 34 |
|
---|
| 35 | test('general wild card with tokens being returned', function(t) {
|
---|
| 36 |
|
---|
| 37 | t.plan(5);
|
---|
| 38 | var parts = wildcard('foo.*', 'foo.bar');
|
---|
| 39 | t.ok(parts);
|
---|
| 40 | t.equal(parts.length, 2);
|
---|
| 41 | t.equal(parts[0], 'foo');
|
---|
| 42 | t.equal(parts[1], 'bar');
|
---|
| 43 |
|
---|
| 44 | parts = wildcard('foo.*', 'not.matching');
|
---|
| 45 | t.notOk(parts);
|
---|
| 46 | });
|
---|