1 | var wildcard = require('../'),
|
---|
2 | test = require('tape'),
|
---|
3 | testdata = {
|
---|
4 | 'a.b.c' : {},
|
---|
5 | 'a.b' : {},
|
---|
6 | 'a' : {},
|
---|
7 | 'a.b.d' : {}
|
---|
8 | },
|
---|
9 | testdataSep = {
|
---|
10 | 'a:b:c' : {},
|
---|
11 | 'a:b' : {},
|
---|
12 | 'a' : {},
|
---|
13 | 'a:b:d' : {}
|
---|
14 | };
|
---|
15 |
|
---|
16 | test('object result matching tests', function(t) {
|
---|
17 | t.test('should return 4 matches for a.*', function(t) {
|
---|
18 | var matches = wildcard('a.*', testdata);
|
---|
19 |
|
---|
20 | t.plan(4);
|
---|
21 | t.ok(matches['a.b.c']);
|
---|
22 | t.ok(matches['a.b']);
|
---|
23 | t.ok(matches['a']);
|
---|
24 | t.ok(matches['a.b.d']);
|
---|
25 | t.end();
|
---|
26 | });
|
---|
27 |
|
---|
28 | t.test('should return 4 matches for a:*', function(t) {
|
---|
29 | var matches = wildcard('a:*', testdataSep, ':');
|
---|
30 |
|
---|
31 | t.plan(4);
|
---|
32 | t.ok(matches['a:b:c']);
|
---|
33 | t.ok(matches['a:b']);
|
---|
34 | t.ok(matches['a']);
|
---|
35 | t.ok(matches['a:b:d']);
|
---|
36 | t.end();
|
---|
37 | });
|
---|
38 |
|
---|
39 | t.test('should return 3 matches for a.b.*', function(t) {
|
---|
40 | var matches = wildcard('a.b.*', testdata);
|
---|
41 |
|
---|
42 | t.plan(4);
|
---|
43 | t.ok(matches['a.b.c']);
|
---|
44 | t.ok(matches['a.b']);
|
---|
45 | t.notOk(matches['a']);
|
---|
46 | t.ok(matches['a.b.d']);
|
---|
47 | t.end();
|
---|
48 | });
|
---|
49 |
|
---|
50 | t.test('should return 3 matches for a:b:*', function(t) {
|
---|
51 | var matches = wildcard('a:b:*', testdataSep, ':');
|
---|
52 |
|
---|
53 | t.plan(4);
|
---|
54 | t.ok(matches['a:b:c']);
|
---|
55 | t.ok(matches['a:b']);
|
---|
56 | t.notOk(matches['a']);
|
---|
57 | t.ok(matches['a:b:d']);
|
---|
58 | t.end();
|
---|
59 | });
|
---|
60 |
|
---|
61 | t.test('should return 1 matches for a.*.c', function(t) {
|
---|
62 | var matches = wildcard('a.*.c', testdata);
|
---|
63 |
|
---|
64 | t.plan(4);
|
---|
65 | t.ok(matches['a.b.c']);
|
---|
66 | t.notOk(matches['a.b']);
|
---|
67 | t.notOk(matches['a']);
|
---|
68 | t.notOk(matches['a.b.d']);
|
---|
69 | t.end();
|
---|
70 | });
|
---|
71 |
|
---|
72 | t.test('should return 1 matches for a:*:c', function(t) {
|
---|
73 | var matches = wildcard('a:*:c', testdataSep, ':');
|
---|
74 |
|
---|
75 | t.plan(4);
|
---|
76 | t.ok(matches['a:b:c']);
|
---|
77 | t.notOk(matches['a:b']);
|
---|
78 | t.notOk(matches['a']);
|
---|
79 | t.notOk(matches['a:b:d']);
|
---|
80 | t.end();
|
---|
81 | });
|
---|
82 |
|
---|
83 | t.test('should return 0 matches for b.*.d', function(t) {
|
---|
84 | var matches = wildcard('b.*.d', testdata);
|
---|
85 |
|
---|
86 | t.plan(4);
|
---|
87 | t.notOk(matches['a.b.c']);
|
---|
88 | t.notOk(matches['a.b']);
|
---|
89 | t.notOk(matches['a']);
|
---|
90 | t.notOk(matches['a.b.d']);
|
---|
91 | t.end();
|
---|
92 | });
|
---|
93 |
|
---|
94 | t.test('should return 0 matches for b:*:d', function(t) {
|
---|
95 | var matches = wildcard('b:*:d', testdataSep, ':');
|
---|
96 |
|
---|
97 | t.plan(4);
|
---|
98 | t.notOk(matches['a:b:c']);
|
---|
99 | t.notOk(matches['a:b']);
|
---|
100 | t.notOk(matches['a']);
|
---|
101 | t.notOk(matches['a:b:d']);
|
---|
102 | t.end();
|
---|
103 | });
|
---|
104 |
|
---|
105 | t.end();
|
---|
106 | });
|
---|