mark.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. var test = require("tap").test
  2. var glob = require('../')
  3. process.chdir(__dirname)
  4. // expose timing issues
  5. var lag = 5
  6. glob.Glob.prototype._stat = function(o) { return function(f, cb) {
  7. var args = arguments
  8. setTimeout(function() {
  9. o.call(this, f, cb)
  10. }.bind(this), lag += 5)
  11. }}(glob.Glob.prototype._stat)
  12. test("mark, with **", function (t) {
  13. glob("a/*b*/**", {mark: true}, function (er, results) {
  14. if (er)
  15. throw er
  16. var expect =
  17. [ 'a/abcdef/',
  18. 'a/abcdef/g/',
  19. 'a/abcdef/g/h',
  20. 'a/abcfed/',
  21. 'a/abcfed/g/',
  22. 'a/abcfed/g/h',
  23. 'a/b/',
  24. 'a/b/c/',
  25. 'a/b/c/d',
  26. 'a/bc/',
  27. 'a/bc/e/',
  28. 'a/bc/e/f',
  29. 'a/cb/',
  30. 'a/cb/e/',
  31. 'a/cb/e/f' ]
  32. t.same(results, expect)
  33. t.end()
  34. })
  35. })
  36. test("mark, no / on pattern", function (t) {
  37. glob("a/*", {mark: true}, function (er, results) {
  38. if (er)
  39. throw er
  40. var expect = [ 'a/abcdef/',
  41. 'a/abcfed/',
  42. 'a/b/',
  43. 'a/bc/',
  44. 'a/c/',
  45. 'a/cb/' ]
  46. if (process.platform !== "win32")
  47. expect.push('a/symlink/')
  48. t.same(results, expect)
  49. t.end()
  50. }).on('match', function(m) {
  51. t.similar(m, /\/$/)
  52. })
  53. })
  54. test("mark=false, no / on pattern", function (t) {
  55. glob("a/*", function (er, results) {
  56. if (er)
  57. throw er
  58. var expect = [ 'a/abcdef',
  59. 'a/abcfed',
  60. 'a/b',
  61. 'a/bc',
  62. 'a/c',
  63. 'a/cb' ]
  64. if (process.platform !== "win32")
  65. expect.push('a/symlink')
  66. t.same(results, expect)
  67. t.end()
  68. }).on('match', function(m) {
  69. t.similar(m, /[^\/]$/)
  70. })
  71. })
  72. test("mark=true, / on pattern", function (t) {
  73. glob("a/*/", {mark: true}, function (er, results) {
  74. if (er)
  75. throw er
  76. var expect = [ 'a/abcdef/',
  77. 'a/abcfed/',
  78. 'a/b/',
  79. 'a/bc/',
  80. 'a/c/',
  81. 'a/cb/' ]
  82. if (process.platform !== "win32")
  83. expect.push('a/symlink/')
  84. t.same(results, expect)
  85. t.end()
  86. }).on('match', function(m) {
  87. t.similar(m, /\/$/)
  88. })
  89. })
  90. test("mark=false, / on pattern", function (t) {
  91. glob("a/*/", function (er, results) {
  92. if (er)
  93. throw er
  94. var expect = [ 'a/abcdef/',
  95. 'a/abcfed/',
  96. 'a/b/',
  97. 'a/bc/',
  98. 'a/c/',
  99. 'a/cb/' ]
  100. if (process.platform !== "win32")
  101. expect.push('a/symlink/')
  102. t.same(results, expect)
  103. t.end()
  104. }).on('match', function(m) {
  105. t.similar(m, /\/$/)
  106. })
  107. })