react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / fileset / node_modules / minimatch / test / basic.js
80713 views// http://www.bashcookbook.com/bashinfo/source/bash-1.14.7/tests/glob-test1//2// TODO: Some of these tests do very bad things with backslashes, and will3// most likely fail badly on windows. They should probably be skipped.45var 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" ])141516var patterns =17[ "http://www.bashcookbook.com/bashinfo/source/bash-1.14.7/tests/glob-test"18, ["a*", ["a", "abc", "abd", "abe"]]19, ["X*", ["X*"], {nonull: true}]2021// allow null glob expansion22, ["X*", []]2324// isaacs: Slightly different than bash/sh/ksh25// \\* is not un-escaped to literal "*" in a failed match,26// but it does make it get treated as a literal star27, ["\\*", ["\\*"], {nonull: true}]28, ["\\**", ["\\**"], {nonull: true}]29, ["\\*\\*", ["\\*\\*"], {nonull: true}]3031, ["b*/", ["bdir/"]]32, ["c*", ["c", "ca", "cb"]]33, ["**", files]3435, ["\\.\\./*/", ["\\.\\./*/"], {nonull: true}]36, ["s/\\..*//", ["s/\\..*//"], {nonull: true}]3738, "legendary larry crashes bashes"39, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"40, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"], {nonull: true}]41, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"42, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"], {nonull: true}]4344, "character classes"45, ["[a-c]b*", ["abc", "abd", "abe", "bb", "cb"]]46, ["[a-y]*[^c]", ["abd", "abe", "bb", "bcd",47"bdir/", "ca", "cb", "dd", "de"]]48, ["a*[^c]", ["abd", "abe"]]49, function () { files.push("a-b", "aXb") }50, ["a[X-]b", ["a-b", "aXb"]]51, function () { files.push(".x", ".y") }52, ["[^a-c]*", ["d", "dd", "de"]]53, function () { files.push("a*b/", "a*b/ooo") }54, ["a\\*b/*", ["a*b/ooo"]]55, ["a\\*?/*", ["a*b/ooo"]]56, ["*\\\\!*", [], {null: true}, ["echo !7"]]57, ["*\\!*", ["echo !7"], null, ["echo !7"]]58, ["*.\\*", ["r.*"], null, ["r.*"]]59, ["a[b]c", ["abc"]]60, ["a[\\b]c", ["abc"]]61, ["a?c", ["abc"]]62, ["a\\*c", [], {null: true}, ["abc"]]63, ["", [""], { null: true }, [""]]6465, "http://www.opensource.apple.com/source/bash/bash-23/" +66"bash/tests/glob-test"67, function () { files.push("man/", "man/man1/", "man/man1/bash.1") }68, ["*/man*/bash.*", ["man/man1/bash.1"]]69, ["man/man1/bash.1", ["man/man1/bash.1"]]70, ["a***c", ["abc"], null, ["abc"]]71, ["a*****?c", ["abc"], null, ["abc"]]72, ["?*****??", ["abc"], null, ["abc"]]73, ["*****??", ["abc"], null, ["abc"]]74, ["?*****?c", ["abc"], null, ["abc"]]75, ["?***?****c", ["abc"], null, ["abc"]]76, ["?***?****?", ["abc"], null, ["abc"]]77, ["?***?****", ["abc"], null, ["abc"]]78, ["*******c", ["abc"], null, ["abc"]]79, ["*******?", ["abc"], null, ["abc"]]80, ["a*cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]81, ["a**?**cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]82, ["a**?**cd**?**??k***", ["abcdecdhjk"], null, ["abcdecdhjk"]]83, ["a**?**cd**?**??***k", ["abcdecdhjk"], null, ["abcdecdhjk"]]84, ["a**?**cd**?**??***k**", ["abcdecdhjk"], null, ["abcdecdhjk"]]85, ["a****c**?**??*****", ["abcdecdhjk"], null, ["abcdecdhjk"]]86, ["[-abc]", ["-"], null, ["-"]]87, ["[abc-]", ["-"], null, ["-"]]88, ["\\", ["\\"], null, ["\\"]]89, ["[\\\\]", ["\\"], null, ["\\"]]90, ["[[]", ["["], null, ["["]]91, ["[", ["["], null, ["["]]92, ["[*", ["[abc"], null, ["[abc"]]93, "a right bracket shall lose its special meaning and\n" +94"represent itself in a bracket expression if it occurs\n" +95"first in the list. -- POSIX.2 2.8.3.2"96, ["[]]", ["]"], null, ["]"]]97, ["[]-]", ["]"], null, ["]"]]98, ["[a-\z]", ["p"], null, ["p"]]99, ["??**********?****?", [], { null: true }, ["abc"]]100, ["??**********?****c", [], { null: true }, ["abc"]]101, ["?************c****?****", [], { null: true }, ["abc"]]102, ["*c*?**", [], { null: true }, ["abc"]]103, ["a*****c*?**", [], { null: true }, ["abc"]]104, ["a********???*******", [], { null: true }, ["abc"]]105, ["[]", [], { null: true }, ["a"]]106, ["[abc", [], { null: true }, ["["]]107108, "nocase tests"109, ["XYZ", ["xYz"], { nocase: true, null: true }110, ["xYz", "ABC", "IjK"]]111, ["ab*", ["ABC"], { nocase: true, null: true }112, ["xYz", "ABC", "IjK"]]113, ["[ia]?[ck]", ["ABC", "IjK"], { nocase: true, null: true }114, ["xYz", "ABC", "IjK"]]115116// [ pattern, [matches], MM opts, files, TAP opts]117, "onestar/twostar"118, ["{/*,*}", [], {null: true}, ["/asdf/asdf/asdf"]]119, ["{/?,*}", ["/a", "bb"], {null: true}120, ["/a", "/b/b", "/a/b/c", "bb"]]121122, "dots should not match unless requested"123, ["**", ["a/b"], {}, ["a/b", "a/.d", ".a/.d"]]124125// .. and . can only match patterns starting with .,126// even when options.dot is set.127, function () {128files = ["a/./b", "a/../b", "a/c/b", "a/.d/b"]129}130, ["a/*/b", ["a/c/b", "a/.d/b"], {dot: true}]131, ["a/.*/b", ["a/./b", "a/../b", "a/.d/b"], {dot: true}]132, ["a/*/b", ["a/c/b"], {dot:false}]133, ["a/.*/b", ["a/./b", "a/../b", "a/.d/b"], {dot: false}]134135136// this also tests that changing the options needs137// to change the cache key, even if the pattern is138// the same!139, ["**", ["a/b","a/.d",".a/.d"], { dot: true }140, [ ".a/.d", "a/.d", "a/b"]]141142, "paren sets cannot contain slashes"143, ["*(a/b)", ["*(a/b)"], {nonull: true}, ["a/b"]]144145// brace sets trump all else.146//147// invalid glob pattern. fails on bash4 and bsdglob.148// however, in this implementation, it's easier just149// to do the intuitive thing, and let brace-expansion150// actually come before parsing any extglob patterns,151// like the documentation seems to say.152//153// XXX: if anyone complains about this, either fix it154// or tell them to grow up and stop complaining.155//156// bash/bsdglob says this:157// , ["*(a|{b),c)}", ["*(a|{b),c)}"], {}, ["a", "ab", "ac", "ad"]]158// but we do this instead:159, ["*(a|{b),c)}", ["a", "ab", "ac"], {}, ["a", "ab", "ac", "ad"]]160161// test partial parsing in the presence of comment/negation chars162, ["[!a*", ["[!ab"], {}, ["[!ab", "[ab"]]163, ["[#a*", ["[#ab"], {}, ["[#ab", "[ab"]]164165// like: {a,b|c\\,d\\\|e} except it's unclosed, so it has to be escaped.166, ["+(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g"167, ["+(a|b\\|c\\\\|d\\\\|e\\\\\\\\|f\\\\\\\\|g"]168, {}169, ["+(a|b\\|c\\\\|d\\\\|e\\\\\\\\|f\\\\\\\\|g", "a", "b\\c"]]170171172// crazy nested {,,} and *(||) tests.173, function () {174files = [ "a", "b", "c", "d"175, "ab", "ac", "ad"176, "bc", "cb"177, "bc,d", "c,db", "c,d"178, "d)", "(b|c", "*(b|c"179, "b|c", "b|cc", "cb|c"180, "x(a|b|c)", "x(a|c)"181, "(a|b|c)", "(a|c)"]182}183, ["*(a|{b,c})", ["a", "b", "c", "ab", "ac"]]184, ["{a,*(b|c,d)}", ["a","(b|c", "*(b|c", "d)"]]185// a186// *(b|c)187// *(b|d)188, ["{a,*(b|{c,d})}", ["a","b", "bc", "cb", "c", "d"]]189, ["*(a|{b|c,c})", ["a", "b", "c", "ab", "ac", "bc", "cb"]]190191192// test various flag settings.193, [ "*(a|{b|c,c})", ["x(a|b|c)", "x(a|c)", "(a|b|c)", "(a|c)"]194, { noext: true } ]195, ["a?b", ["x/y/acb", "acb/"], {matchBase: true}196, ["x/y/acb", "acb/", "acb/d/e", "x/y/acb/d"] ]197, ["#*", ["#a", "#b"], {nocomment: true}, ["#a", "#b", "c#d"]]198199200// begin channelling Boole and deMorgan...201, "negation tests"202, function () {203files = ["d", "e", "!ab", "!abc", "a!b", "\\!a"]204}205206// anything that is NOT a* matches.207, ["!a*", ["\\!a", "d", "e", "!ab", "!abc"]]208209// anything that IS !a* matches.210, ["!a*", ["!ab", "!abc"], {nonegate: true}]211212// anything that IS a* matches213, ["!!a*", ["a!b"]]214215// anything that is NOT !a* matches216, ["!\\!a*", ["a!b", "d", "e", "\\!a"]]217218// negation nestled within a pattern219, function () {220files = [ "foo.js"221, "foo.bar"222// can't match this one without negative lookbehind.223, "foo.js.js"224, "blar.js"225, "foo."226, "boo.js.boo" ]227}228, ["*.!(js)", ["foo.bar", "foo.", "boo.js.boo"] ]229230// https://github.com/isaacs/minimatch/issues/5231, function () {232files = [ 'a/b/.x/c'233, 'a/b/.x/c/d'234, 'a/b/.x/c/d/e'235, 'a/b/.x'236, 'a/b/.x/'237, 'a/.x/b'238, '.x'239, '.x/'240, '.x/a'241, '.x/a/b'242, 'a/.x/b/.x/c'243, '.x/.x' ]244}245, ["**/.x/**", [ '.x/'246, '.x/a'247, '.x/a/b'248, 'a/.x/b'249, 'a/b/.x/'250, 'a/b/.x/c'251, 'a/b/.x/c/d'252, 'a/b/.x/c/d/e' ] ]253254]255256var regexps =257[ '/^(?:(?=.)a[^/]*?)$/',258'/^(?:(?=.)X[^/]*?)$/',259'/^(?:(?=.)X[^/]*?)$/',260'/^(?:\\*)$/',261'/^(?:(?=.)\\*[^/]*?)$/',262'/^(?:\\*\\*)$/',263'/^(?:(?=.)b[^/]*?\\/)$/',264'/^(?:(?=.)c[^/]*?)$/',265'/^(?:(?:(?!(?:\\/|^)\\.).)*?)$/',266'/^(?:\\.\\.\\/(?!\\.)(?=.)[^/]*?\\/)$/',267'/^(?:s\\/(?=.)\\.\\.[^/]*?\\/)$/',268'/^(?:\\/\\^root:\\/\\{s\\/(?=.)\\^[^:][^/]*?:[^:][^/]*?:\\([^:]\\)[^/]*?\\.[^/]*?\\$\\/1\\/)$/',269'/^(?:\\/\\^root:\\/\\{s\\/(?=.)\\^[^:][^/]*?:[^:][^/]*?:\\([^:]\\)[^/]*?\\.[^/]*?\\$\\/\u0001\\/)$/',270'/^(?:(?!\\.)(?=.)[a-c]b[^/]*?)$/',271'/^(?:(?!\\.)(?=.)[a-y][^/]*?[^c])$/',272'/^(?:(?=.)a[^/]*?[^c])$/',273'/^(?:(?=.)a[X-]b)$/',274'/^(?:(?!\\.)(?=.)[^a-c][^/]*?)$/',275'/^(?:a\\*b\\/(?!\\.)(?=.)[^/]*?)$/',276'/^(?:(?=.)a\\*[^/]\\/(?!\\.)(?=.)[^/]*?)$/',277'/^(?:(?!\\.)(?=.)[^/]*?\\\\\\![^/]*?)$/',278'/^(?:(?!\\.)(?=.)[^/]*?\\![^/]*?)$/',279'/^(?:(?!\\.)(?=.)[^/]*?\\.\\*)$/',280'/^(?:(?=.)a[b]c)$/',281'/^(?:(?=.)a[b]c)$/',282'/^(?:(?=.)a[^/]c)$/',283'/^(?:a\\*c)$/',284'false',285'/^(?:(?!\\.)(?=.)[^/]*?\\/(?=.)man[^/]*?\\/(?=.)bash\\.[^/]*?)$/',286'/^(?:man\\/man1\\/bash\\.1)$/',287'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?c)$/',288'/^(?:(?=.)a[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/',289'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/',290'/^(?:(?!\\.)(?=.)[^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/][^/])$/',291'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/]*?[^/]*?[^/]c)$/',292'/^(?:(?!\\.)(?=.)[^/][^/]*?[^/]*?[^/]*?[^/][^/]*?[^/]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)\\.[^/]*?\\/b)$/',329'/^(?:a\\/(?!\\.)(?=.)[^/]*?\\/b)$/',330'/^(?:a\\/(?=.)\\.[^/]*?\\/b)$/',331'/^(?:(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?)$/',332'/^(?:(?!\\.)(?=.)[^/]*?\\(a\\/b\\))$/',333'/^(?:(?!\\.)(?=.)(?:a|b)*|(?!\\.)(?=.)(?:a|c)*)$/',334'/^(?:(?=.)\\[(?=.)\\!a[^/]*?)$/',335'/^(?:(?=.)\\[(?=.)#a[^/]*?)$/',336'/^(?:(?=.)\\+\\(a\\|[^/]*?\\|c\\\\\\\\\\|d\\\\\\\\\\|e\\\\\\\\\\\\\\\\\\|f\\\\\\\\\\\\\\\\\\|g)$/',337'/^(?:(?!\\.)(?=.)(?:a|b)*|(?!\\.)(?=.)(?:a|c)*)$/',338'/^(?:a|(?!\\.)(?=.)[^/]*?\\(b\\|c|d\\))$/',339'/^(?:a|(?!\\.)(?=.)(?:b|c)*|(?!\\.)(?=.)(?:b|d)*)$/',340'/^(?:(?!\\.)(?=.)(?:a|b|c)*|(?!\\.)(?=.)(?:a|c)*)$/',341'/^(?:(?!\\.)(?=.)[^/]*?\\(a\\|b\\|c\\)|(?!\\.)(?=.)[^/]*?\\(a\\|c\\))$/',342'/^(?:(?=.)a[^/]b)$/',343'/^(?:(?=.)#[^/]*?)$/',344'/^(?!^(?:(?=.)a[^/]*?)$).*$/',345'/^(?:(?=.)\\!a[^/]*?)$/',346'/^(?:(?=.)a[^/]*?)$/',347'/^(?!^(?:(?=.)\\!a[^/]*?)$).*$/',348'/^(?:(?!\\.)(?=.)[^/]*?\\.(?:(?!js)[^/]*?))$/',349'/^(?:(?:(?!(?:\\/|^)\\.).)*?\\/\\.x\\/(?:(?!(?:\\/|^)\\.).)*?)$/' ]350var re = 0;351352tap.test("basic tests", function (t) {353var start = Date.now()354355// [ pattern, [matches], MM opts, files, TAP opts]356patterns.forEach(function (c) {357if (typeof c === "function") return c()358if (typeof c === "string") return t.comment(c)359360var pattern = c[0]361, expect = c[1].sort(alpha)362, options = c[2] || {}363, f = c[3] || files364, tapOpts = c[4] || {}365366// options.debug = true367var m = new mm.Minimatch(pattern, options)368var r = m.makeRe()369var expectRe = regexps[re++]370tapOpts.re = String(r) || JSON.stringify(r)371tapOpts.files = JSON.stringify(f)372tapOpts.pattern = pattern373tapOpts.set = m.set374tapOpts.negated = m.negate375376var actual = mm.match(f, pattern, options)377actual.sort(alpha)378379t.equivalent( actual, expect380, JSON.stringify(pattern) + " " + JSON.stringify(expect)381, tapOpts )382383t.equal(tapOpts.re, expectRe, tapOpts)384})385386t.comment("time=" + (Date.now() - start) + "ms")387t.end()388})389390tap.test("global leak test", function (t) {391var globalAfter = Object.keys(global)392t.equivalent(globalAfter, globalBefore, "no new globals, please")393t.end()394})395396function alpha (a, b) {397return a > b ? 1 : -1398}399400401