strings.js 1.8 KB

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