objects.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. test('object result matching tests', function(t) {
  16. t.test('should return 4 matches for a.*', function(t) {
  17. var matches = wildcard('a.*', testdata);
  18. t.plan(4);
  19. t.ok(matches['a.b.c']);
  20. t.ok(matches['a.b']);
  21. t.ok(matches['a']);
  22. t.ok(matches['a.b.d']);
  23. t.end();
  24. });
  25. t.test('should return 4 matches for a:*', function(t) {
  26. var matches = wildcard('a:*', testdataSep, ':');
  27. t.plan(4);
  28. t.ok(matches['a:b:c']);
  29. t.ok(matches['a:b']);
  30. t.ok(matches['a']);
  31. t.ok(matches['a:b:d']);
  32. t.end();
  33. });
  34. t.test('should return 3 matches for a.b.*', function(t) {
  35. var matches = wildcard('a.b.*', testdata);
  36. t.plan(4);
  37. t.ok(matches['a.b.c']);
  38. t.ok(matches['a.b']);
  39. t.notOk(matches['a']);
  40. t.ok(matches['a.b.d']);
  41. t.end();
  42. });
  43. t.test('should return 3 matches for a:b:*', function(t) {
  44. var matches = wildcard('a:b:*', testdataSep, ':');
  45. t.plan(4);
  46. t.ok(matches['a:b:c']);
  47. t.ok(matches['a:b']);
  48. t.notOk(matches['a']);
  49. t.ok(matches['a:b:d']);
  50. t.end();
  51. });
  52. t.test('should return 1 matches for a.*.c', function(t) {
  53. var matches = wildcard('a.*.c', testdata);
  54. t.plan(4);
  55. t.ok(matches['a.b.c']);
  56. t.notOk(matches['a.b']);
  57. t.notOk(matches['a']);
  58. t.notOk(matches['a.b.d']);
  59. t.end();
  60. });
  61. t.test('should return 1 matches for a:*:c', function(t) {
  62. var matches = wildcard('a:*:c', testdataSep, ':');
  63. t.plan(4);
  64. t.ok(matches['a:b:c']);
  65. t.notOk(matches['a:b']);
  66. t.notOk(matches['a']);
  67. t.notOk(matches['a:b:d']);
  68. t.end();
  69. });
  70. t.test('should return 0 matches for b.*.d', function(t) {
  71. var matches = wildcard('b.*.d', testdata);
  72. t.plan(4);
  73. t.notOk(matches['a.b.c']);
  74. t.notOk(matches['a.b']);
  75. t.notOk(matches['a']);
  76. t.notOk(matches['a.b.d']);
  77. t.end();
  78. });
  79. t.test('should return 0 matches for b:*:d', function(t) {
  80. var matches = wildcard('b:*:d', testdataSep, ':');
  81. t.plan(4);
  82. t.notOk(matches['a:b:c']);
  83. t.notOk(matches['a:b']);
  84. t.notOk(matches['a']);
  85. t.notOk(matches['a:b:d']);
  86. t.end();
  87. });
  88. t.end();
  89. });