basic.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. // http://www.bashcookbook.com/bashinfo/source/bash-1.14.7/tests/glob-test
  2. //
  3. // TODO: Some of these tests do very bad things with backslashes, and will
  4. // most likely fail badly on windows. They should probably be skipped.
  5. var tap = require("tap")
  6. , globalBefore = Object.keys(global)
  7. , mm = require("../")
  8. , files = [ "a", "b", "c", "d", "abc"
  9. , "abd", "abe", "bb", "bcd"
  10. , "ca", "cb", "dd", "de"
  11. , "bdir/", "bdir/cfile"]
  12. , next = files.concat([ "a-b", "aXb"
  13. , ".x", ".y" ])
  14. var patterns =
  15. [ "http://www.bashcookbook.com/bashinfo/source/bash-1.14.7/tests/glob-test"
  16. , ["a*", ["a", "abc", "abd", "abe"]]
  17. , ["X*", ["X*"], {nonull: true}]
  18. // allow null glob expansion
  19. , ["X*", []]
  20. // isaacs: Slightly different than bash/sh/ksh
  21. // \\* is not un-escaped to literal "*" in a failed match,
  22. // but it does make it get treated as a literal star
  23. , ["\\*", ["\\*"], {nonull: true}]
  24. , ["\\**", ["\\**"], {nonull: true}]
  25. , ["\\*\\*", ["\\*\\*"], {nonull: true}]
  26. , ["b*/", ["bdir/"]]
  27. , ["c*", ["c", "ca", "cb"]]
  28. , ["**", files]
  29. , ["\\.\\./*/", ["\\.\\./*/"], {nonull: true}]
  30. , ["s/\\..*//", ["s/\\..*//"], {nonull: true}]
  31. , "legendary larry crashes bashes"
  32. , ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"
  33. , ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"], {nonull: true}]
  34. , ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"
  35. , ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"], {nonull: true}]
  36. , "character classes"
  37. , ["[a-c]b*", ["abc", "abd", "abe", "bb", "cb"]]
  38. , ["[a-y]*[^c]", ["abd", "abe", "bb", "bcd",
  39. "bdir/", "ca", "cb", "dd", "de"]]
  40. , ["a*[^c]", ["abd", "abe"]]
  41. , function () { files.push("a-b", "aXb") }
  42. , ["a[X-]b", ["a-b", "aXb"]]
  43. , function () { files.push(".x", ".y") }
  44. , ["[^a-c]*", ["d", "dd", "de"]]
  45. , function () { files.push("a*b/", "a*b/ooo") }
  46. , ["a\\*b/*", ["a*b/ooo"]]
  47. , ["a\\*?/*", ["a*b/ooo"]]
  48. , ["*\\\\!*", [], {null: true}, ["echo !7"]]
  49. , ["*\\!*", ["echo !7"], null, ["echo !7"]]
  50. , ["*.\\*", ["r.*"], null, ["r.*"]]
  51. , ["a[b]c", ["abc"]]
  52. , ["a[\\b]c", ["abc"]]
  53. , ["a?c", ["abc"]]
  54. , ["a\\*c", [], {null: true}, ["abc"]]
  55. , ["", [""], { null: true }, [""]]
  56. , "http://www.opensource.apple.com/source/bash/bash-23/" +
  57. "bash/tests/glob-test"
  58. , function () { files.push("man/", "man/man1/", "man/man1/bash.1") }
  59. , ["*/man*/bash.*", ["man/man1/bash.1"]]
  60. , ["man/man1/bash.1", ["man/man1/bash.1"]]
  61. , ["a***c", ["abc"], null, ["abc"]]
  62. , ["a*****?c", ["abc"], null, ["abc"]]
  63. , ["?*****??", ["abc"], null, ["abc"]]
  64. , ["*****??", ["abc"], null, ["abc"]]
  65. , ["?*****?c", ["abc"], null, ["abc"]]
  66. , ["?***?****c", ["abc"], null, ["abc"]]
  67. , ["?***?****?", ["abc"], null, ["abc"]]
  68. , ["?***?****", ["abc"], null, ["abc"]]
  69. , ["*******c", ["abc"], null, ["abc"]]
  70. , ["*******?", ["abc"], null, ["abc"]]
  71. , ["a*cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]
  72. , ["a**?**cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]
  73. , ["a**?**cd**?**??k***", ["abcdecdhjk"], null, ["abcdecdhjk"]]
  74. , ["a**?**cd**?**??***k", ["abcdecdhjk"], null, ["abcdecdhjk"]]
  75. , ["a**?**cd**?**??***k**", ["abcdecdhjk"], null, ["abcdecdhjk"]]
  76. , ["a****c**?**??*****", ["abcdecdhjk"], null, ["abcdecdhjk"]]
  77. , ["[-abc]", ["-"], null, ["-"]]
  78. , ["[abc-]", ["-"], null, ["-"]]
  79. , ["\\", ["\\"], null, ["\\"]]
  80. , ["[\\\\]", ["\\"], null, ["\\"]]
  81. , ["[[]", ["["], null, ["["]]
  82. , ["[", ["["], null, ["["]]
  83. , ["[*", ["[abc"], null, ["[abc"]]
  84. , "a right bracket shall lose its special meaning and\n" +
  85. "represent itself in a bracket expression if it occurs\n" +
  86. "first in the list. -- POSIX.2 2.8.3.2"
  87. , ["[]]", ["]"], null, ["]"]]
  88. , ["[]-]", ["]"], null, ["]"]]
  89. , ["[a-\z]", ["p"], null, ["p"]]
  90. , ["??**********?****?", [], { null: true }, ["abc"]]
  91. , ["??**********?****c", [], { null: true }, ["abc"]]
  92. , ["?************c****?****", [], { null: true }, ["abc"]]
  93. , ["*c*?**", [], { null: true }, ["abc"]]
  94. , ["a*****c*?**", [], { null: true }, ["abc"]]
  95. , ["a********???*******", [], { null: true }, ["abc"]]
  96. , ["[]", [], { null: true }, ["a"]]
  97. , ["[abc", [], { null: true }, ["["]]
  98. , "nocase tests"
  99. , ["XYZ", ["xYz"], { nocase: true, null: true }
  100. , ["xYz", "ABC", "IjK"]]
  101. , ["ab*", ["ABC"], { nocase: true, null: true }
  102. , ["xYz", "ABC", "IjK"]]
  103. , ["[ia]?[ck]", ["ABC", "IjK"], { nocase: true, null: true }
  104. , ["xYz", "ABC", "IjK"]]
  105. // [ pattern, [matches], MM opts, files, TAP opts]
  106. , "onestar/twostar"
  107. , ["{/*,*}", [], {null: true}, ["/asdf/asdf/asdf"]]
  108. , ["{/?,*}", ["/a", "bb"], {null: true}
  109. , ["/a", "/b/b", "/a/b/c", "bb"]]
  110. , "dots should not match unless requested"
  111. , ["**", ["a/b"], {}, ["a/b", "a/.d", ".a/.d"]]
  112. // .. and . can only match patterns starting with .,
  113. // even when options.dot is set.
  114. , function () {
  115. files = ["a/./b", "a/../b", "a/c/b", "a/.d/b"]
  116. }
  117. , ["a/*/b", ["a/c/b", "a/.d/b"], {dot: true}]
  118. , ["a/.*/b", ["a/./b", "a/../b", "a/.d/b"], {dot: true}]
  119. , ["a/*/b", ["a/c/b"], {dot:false}]
  120. , ["a/.*/b", ["a/./b", "a/../b", "a/.d/b"], {dot: false}]
  121. // this also tests that changing the options needs
  122. // to change the cache key, even if the pattern is
  123. // the same!
  124. , ["**", ["a/b","a/.d",".a/.d"], { dot: true }
  125. , [ ".a/.d", "a/.d", "a/b"]]
  126. , "paren sets cannot contain slashes"
  127. , ["*(a/b)", ["*(a/b)"], {nonull: true}, ["a/b"]]
  128. // brace sets trump all else.
  129. //
  130. // invalid glob pattern. fails on bash4 and bsdglob.
  131. // however, in this implementation, it's easier just
  132. // to do the intuitive thing, and let brace-expansion
  133. // actually come before parsing any extglob patterns,
  134. // like the documentation seems to say.
  135. //
  136. // XXX: if anyone complains about this, either fix it
  137. // or tell them to grow up and stop complaining.
  138. //
  139. // bash/bsdglob says this:
  140. // , ["*(a|{b),c)}", ["*(a|{b),c)}"], {}, ["a", "ab", "ac", "ad"]]
  141. // but we do this instead:
  142. , ["*(a|{b),c)}", ["a", "ab", "ac"], {}, ["a", "ab", "ac", "ad"]]
  143. // test partial parsing in the presence of comment/negation chars
  144. , ["[!a*", ["[!ab"], {}, ["[!ab", "[ab"]]
  145. , ["[#a*", ["[#ab"], {}, ["[#ab", "[ab"]]
  146. // like: {a,b|c\\,d\\\|e} except it's unclosed, so it has to be escaped.
  147. , ["+(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g"
  148. , ["+(a|b\\|c\\\\|d\\\\|e\\\\\\\\|f\\\\\\\\|g"]
  149. , {}
  150. , ["+(a|b\\|c\\\\|d\\\\|e\\\\\\\\|f\\\\\\\\|g", "a", "b\\c"]]
  151. // crazy nested {,,} and *(||) tests.
  152. , function () {
  153. files = [ "a", "b", "c", "d"
  154. , "ab", "ac", "ad"
  155. , "bc", "cb"
  156. , "bc,d", "c,db", "c,d"
  157. , "d)", "(b|c", "*(b|c"
  158. , "b|c", "b|cc", "cb|c"
  159. , "x(a|b|c)", "x(a|c)"
  160. , "(a|b|c)", "(a|c)"]
  161. }
  162. , ["*(a|{b,c})", ["a", "b", "c", "ab", "ac"]]
  163. , ["{a,*(b|c,d)}", ["a","(b|c", "*(b|c", "d)"]]
  164. // a
  165. // *(b|c)
  166. // *(b|d)
  167. , ["{a,*(b|{c,d})}", ["a","b", "bc", "cb", "c", "d"]]
  168. , ["*(a|{b|c,c})", ["a", "b", "c", "ab", "ac", "bc", "cb"]]
  169. // test various flag settings.
  170. , [ "*(a|{b|c,c})", ["x(a|b|c)", "x(a|c)", "(a|b|c)", "(a|c)"]
  171. , { noext: true } ]
  172. , ["a?b", ["x/y/acb", "acb/"], {matchBase: true}
  173. , ["x/y/acb", "acb/", "acb/d/e", "x/y/acb/d"] ]
  174. , ["#*", ["#a", "#b"], {nocomment: true}, ["#a", "#b", "c#d"]]
  175. // begin channelling Boole and deMorgan...
  176. , "negation tests"
  177. , function () {
  178. files = ["d", "e", "!ab", "!abc", "a!b", "\\!a"]
  179. }
  180. // anything that is NOT a* matches.
  181. , ["!a*", ["\\!a", "d", "e", "!ab", "!abc"]]
  182. // anything that IS !a* matches.
  183. , ["!a*", ["!ab", "!abc"], {nonegate: true}]
  184. // anything that IS a* matches
  185. , ["!!a*", ["a!b"]]
  186. // anything that is NOT !a* matches
  187. , ["!\\!a*", ["a!b", "d", "e", "\\!a"]]
  188. // negation nestled within a pattern
  189. , function () {
  190. files = [ "foo.js"
  191. , "foo.bar"
  192. // can't match this one without negative lookbehind.
  193. , "foo.js.js"
  194. , "blar.js"
  195. , "foo."
  196. , "boo.js.boo" ]
  197. }
  198. , ["*.!(js)", ["foo.bar", "foo.", "boo.js.boo"] ]
  199. // https://github.com/isaacs/minimatch/issues/5
  200. , function () {
  201. files = [ 'a/b/.x/c'
  202. , 'a/b/.x/c/d'
  203. , 'a/b/.x/c/d/e'
  204. , 'a/b/.x'
  205. , 'a/b/.x/'
  206. , 'a/.x/b'
  207. , '.x'
  208. , '.x/'
  209. , '.x/a'
  210. , '.x/a/b'
  211. , 'a/.x/b/.x/c'
  212. , '.x/.x' ]
  213. }
  214. , ["**/.x/**", [ '.x/'
  215. , '.x/a'
  216. , '.x/a/b'
  217. , 'a/.x/b'
  218. , 'a/b/.x/'
  219. , 'a/b/.x/c'
  220. , 'a/b/.x/c/d'
  221. , 'a/b/.x/c/d/e' ] ]
  222. ]
  223. var regexps =
  224. [ '/^(?:(?=.)a[^/]*?)$/',
  225. '/^(?:(?=.)X[^/]*?)$/',
  226. '/^(?:(?=.)X[^/]*?)$/',
  227. '/^(?:\\*)$/',
  228. '/^(?:(?=.)\\*[^/]*?)$/',
  229. '/^(?:\\*\\*)$/',
  230. '/^(?:(?=.)b[^/]*?\\/)$/',
  231. '/^(?:(?=.)c[^/]*?)$/',
  232. '/^(?:(?:(?!(?:\\/|^)\\.).)*?)$/',
  233. '/^(?:\\.\\.\\/(?!\\.)(?=.)[^/]*?\\/)$/',
  234. '/^(?:s\\/(?=.)\\.\\.[^/]*?\\/)$/',
  235. '/^(?:\\/\\^root:\\/\\{s\\/(?=.)\\^[^:][^/]*?:[^:][^/]*?:\\([^:]\\)[^/]*?\\.[^/]*?\\$\\/1\\/)$/',
  236. '/^(?:\\/\\^root:\\/\\{s\\/(?=.)\\^[^:][^/]*?:[^:][^/]*?:\\([^:]\\)[^/]*?\\.[^/]*?\\$\\/\u0001\\/)$/',
  237. '/^(?:(?!\\.)(?=.)[a-c]b[^/]*?)$/',
  238. '/^(?:(?!\\.)(?=.)[a-y][^/]*?[^c])$/',
  239. '/^(?:(?=.)a[^/]*?[^c])$/',
  240. '/^(?:(?=.)a[X-]b)$/',
  241. '/^(?:(?!\\.)(?=.)[^a-c][^/]*?)$/',
  242. '/^(?:a\\*b\\/(?!\\.)(?=.)[^/]*?)$/',
  243. '/^(?:(?=.)a\\*[^/]\\/(?!\\.)(?=.)[^/]*?)$/',
  244. '/^(?:(?!\\.)(?=.)[^/]*?\\\\\\![^/]*?)$/',
  245. '/^(?:(?!\\.)(?=.)[^/]*?\\![^/]*?)$/',
  246. '/^(?:(?!\\.)(?=.)[^/]*?\\.\\*)$/',
  247. '/^(?:(?=.)a[b]c)$/',
  248. '/^(?:(?=.)a[b]c)$/',
  249. '/^(?:(?=.)a[^/]c)$/',
  250. '/^(?:a\\*c)$/',
  251. 'false',
  252. '/^(?:(?!\\.)(?=.)[^/]*?\\/(?=.)man[^/]*?\\/(?=.)bash\\.[^/]*?)$/',
  253. '/^(?:man\\/man1\\/bash\\.1)$/',
  254. '/^(?:(?=.)a[^/]*?[^/]*?[^/]*?c)$/',
  255. '/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/',
  256. '/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/',
  257. '/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/',
  258. '/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/',
  259. '/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?c)$/',
  260. '/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/])$/',
  261. '/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?)$/',
  262. '/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c)$/',
  263. '/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/])$/',
  264. '/^(?:(?=.)a[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k)$/',
  265. '/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k)$/',
  266. '/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/]k[^/]*?[^/]*?[^/]*?)$/',
  267. '/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?k)$/',
  268. '/^(?:(?=.)a[^/]*?[^/]*?[^/][^/]*?[^/]*?cd[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?k[^/]*?[^/]*?)$/',
  269. '/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?)$/',
  270. '/^(?:(?!\\.)(?=.)[-abc])$/',
  271. '/^(?:(?!\\.)(?=.)[abc-])$/',
  272. '/^(?:\\\\)$/',
  273. '/^(?:(?!\\.)(?=.)[\\\\])$/',
  274. '/^(?:(?!\\.)(?=.)[\\[])$/',
  275. '/^(?:\\[)$/',
  276. '/^(?:(?=.)\\[(?!\\.)(?=.)[^/]*?)$/',
  277. '/^(?:(?!\\.)(?=.)[\\]])$/',
  278. '/^(?:(?!\\.)(?=.)[\\]-])$/',
  279. '/^(?:(?!\\.)(?=.)[a-z])$/',
  280. '/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/])$/',
  281. '/^(?:(?!\\.)(?=.)[^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?c)$/',
  282. '/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]*?[^/]*?[^/]*?)$/',
  283. '/^(?:(?!\\.)(?=.)[^/]*?c[^/]*?[^/][^/]*?[^/]*?)$/',
  284. '/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?c[^/]*?[^/][^/]*?[^/]*?)$/',
  285. '/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/][^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?)$/',
  286. '/^(?:\\[\\])$/',
  287. '/^(?:\\[abc)$/',
  288. '/^(?:(?=.)XYZ)$/i',
  289. '/^(?:(?=.)ab[^/]*?)$/i',
  290. '/^(?:(?!\\.)(?=.)[ia][^/][ck])$/i',
  291. '/^(?:\\/(?!\\.)(?=.)[^/]*?|(?!\\.)(?=.)[^/]*?)$/',
  292. '/^(?:\\/(?!\\.)(?=.)[^/]|(?!\\.)(?=.)[^/]*?)$/',
  293. '/^(?:(?:(?!(?:\\/|^)\\.).)*?)$/',
  294. '/^(?:a\\/(?!(?:^|\\/)\\.{1,2}(?:$|\\/))(?=.)[^/]*?\\/b)$/',
  295. '/^(?:a\\/(?=.)\\.[^/]*?\\/b)$/',
  296. '/^(?:a\\/(?!\\.)(?=.)[^/]*?\\/b)$/',
  297. '/^(?:a\\/(?=.)\\.[^/]*?\\/b)$/',
  298. '/^(?:(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)$/',
  299. '/^(?:(?!\\.)(?=.)[^/]*?\\(a\\/b\\))$/',
  300. '/^(?:(?!\\.)(?=.)(?:a|b)*|(?!\\.)(?=.)(?:a|c)*)$/',
  301. '/^(?:(?=.)\\[(?=.)\\!a[^/]*?)$/',
  302. '/^(?:(?=.)\\[(?=.)#a[^/]*?)$/',
  303. '/^(?:(?=.)\\+\\(a\\|[^/]*?\\|c\\\\\\\\\\|d\\\\\\\\\\|e\\\\\\\\\\\\\\\\\\|f\\\\\\\\\\\\\\\\\\|g)$/',
  304. '/^(?:(?!\\.)(?=.)(?:a|b)*|(?!\\.)(?=.)(?:a|c)*)$/',
  305. '/^(?:a|(?!\\.)(?=.)[^/]*?\\(b\\|c|d\\))$/',
  306. '/^(?:a|(?!\\.)(?=.)(?:b|c)*|(?!\\.)(?=.)(?:b|d)*)$/',
  307. '/^(?:(?!\\.)(?=.)(?:a|b|c)*|(?!\\.)(?=.)(?:a|c)*)$/',
  308. '/^(?:(?!\\.)(?=.)[^/]*?\\(a\\|b\\|c\\)|(?!\\.)(?=.)[^/]*?\\(a\\|c\\))$/',
  309. '/^(?:(?=.)a[^/]b)$/',
  310. '/^(?:(?=.)#[^/]*?)$/',
  311. '/^(?!^(?:(?=.)a[^/]*?)$).*$/',
  312. '/^(?:(?=.)\\!a[^/]*?)$/',
  313. '/^(?:(?=.)a[^/]*?)$/',
  314. '/^(?!^(?:(?=.)\\!a[^/]*?)$).*$/',
  315. '/^(?:(?!\\.)(?=.)[^/]*?\\.(?:(?!js)[^/]*?))$/',
  316. '/^(?:(?:(?!(?:\\/|^)\\.).)*?\\/\\.x\\/(?:(?!(?:\\/|^)\\.).)*?)$/' ]
  317. var re = 0;
  318. tap.test("basic tests", function (t) {
  319. var start = Date.now()
  320. // [ pattern, [matches], MM opts, files, TAP opts]
  321. patterns.forEach(function (c) {
  322. if (typeof c === "function") return c()
  323. if (typeof c === "string") return t.comment(c)
  324. var pattern = c[0]
  325. , expect = c[1].sort(alpha)
  326. , options = c[2] || {}
  327. , f = c[3] || files
  328. , tapOpts = c[4] || {}
  329. // options.debug = true
  330. var m = new mm.Minimatch(pattern, options)
  331. var r = m.makeRe()
  332. var expectRe = regexps[re++]
  333. tapOpts.re = String(r) || JSON.stringify(r)
  334. tapOpts.files = JSON.stringify(f)
  335. tapOpts.pattern = pattern
  336. tapOpts.set = m.set
  337. tapOpts.negated = m.negate
  338. var actual = mm.match(f, pattern, options)
  339. actual.sort(alpha)
  340. t.equivalent( actual, expect
  341. , JSON.stringify(pattern) + " " + JSON.stringify(expect)
  342. , tapOpts )
  343. t.equal(tapOpts.re, expectRe, tapOpts)
  344. })
  345. t.comment("time=" + (Date.now() - start) + "ms")
  346. t.end()
  347. })
  348. tap.test("global leak test", function (t) {
  349. var globalAfter = Object.keys(global)
  350. t.equivalent(globalAfter, globalBefore, "no new globals, please")
  351. t.end()
  352. })
  353. function alpha (a, b) {
  354. return a > b ? 1 : -1
  355. }