strings.js 1.3 KB

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