source: trip-planner-front/node_modules/wildcard/test/strings.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1var test = require('tape'),
2 wildcard = require('../');
3
4test('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
17test('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
25test('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
35test('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});
Note: See TracBrowser for help on using the repository browser.