react / wstein / node_modules / jest-cli / node_modules / istanbul / node_modules / fileset / node_modules / minimatch / test / defaults.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" ])1415tap.test("basic tests", function (t) {16var start = Date.now()1718// [ pattern, [matches], MM opts, files, TAP opts]19; [ "http://www.bashcookbook.com/bashinfo" +20"/source/bash-1.14.7/tests/glob-test"21, ["a*", ["a", "abc", "abd", "abe"]]22, ["X*", ["X*"], {nonull: true}]2324// allow null glob expansion25, ["X*", []]2627// isaacs: Slightly different than bash/sh/ksh28// \\* is not un-escaped to literal "*" in a failed match,29// but it does make it get treated as a literal star30, ["\\*", ["\\*"], {nonull: true}]31, ["\\**", ["\\**"], {nonull: true}]32, ["\\*\\*", ["\\*\\*"], {nonull: true}]3334, ["b*/", ["bdir/"]]35, ["c*", ["c", "ca", "cb"]]36, ["**", files]3738, ["\\.\\./*/", ["\\.\\./*/"], {nonull: true}]39, ["s/\\..*//", ["s/\\..*//"], {nonull: true}]4041, "legendary larry crashes bashes"42, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"43, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"], {nonull: true}]44, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"45, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"], {nonull: true}]4647, "character classes"48, ["[a-c]b*", ["abc", "abd", "abe", "bb", "cb"]]49, ["[a-y]*[^c]", ["abd", "abe", "bb", "bcd",50"bdir/", "ca", "cb", "dd", "de"]]51, ["a*[^c]", ["abd", "abe"]]52, function () { files.push("a-b", "aXb") }53, ["a[X-]b", ["a-b", "aXb"]]54, function () { files.push(".x", ".y") }55, ["[^a-c]*", ["d", "dd", "de"]]56, function () { files.push("a*b/", "a*b/ooo") }57, ["a\\*b/*", ["a*b/ooo"]]58, ["a\\*?/*", ["a*b/ooo"]]59, ["*\\\\!*", [], {null: true}, ["echo !7"]]60, ["*\\!*", ["echo !7"], null, ["echo !7"]]61, ["*.\\*", ["r.*"], null, ["r.*"]]62, ["a[b]c", ["abc"]]63, ["a[\\b]c", ["abc"]]64, ["a?c", ["abc"]]65, ["a\\*c", [], {null: true}, ["abc"]]66, ["", [""], { null: true }, [""]]6768, "http://www.opensource.apple.com/source/bash/bash-23/" +69"bash/tests/glob-test"70, function () { files.push("man/", "man/man1/", "man/man1/bash.1") }71, ["*/man*/bash.*", ["man/man1/bash.1"]]72, ["man/man1/bash.1", ["man/man1/bash.1"]]73, ["a***c", ["abc"], null, ["abc"]]74, ["a*****?c", ["abc"], null, ["abc"]]75, ["?*****??", ["abc"], null, ["abc"]]76, ["*****??", ["abc"], null, ["abc"]]77, ["?*****?c", ["abc"], null, ["abc"]]78, ["?***?****c", ["abc"], null, ["abc"]]79, ["?***?****?", ["abc"], null, ["abc"]]80, ["?***?****", ["abc"], null, ["abc"]]81, ["*******c", ["abc"], null, ["abc"]]82, ["*******?", ["abc"], null, ["abc"]]83, ["a*cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]84, ["a**?**cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]85, ["a**?**cd**?**??k***", ["abcdecdhjk"], null, ["abcdecdhjk"]]86, ["a**?**cd**?**??***k", ["abcdecdhjk"], null, ["abcdecdhjk"]]87, ["a**?**cd**?**??***k**", ["abcdecdhjk"], null, ["abcdecdhjk"]]88, ["a****c**?**??*****", ["abcdecdhjk"], null, ["abcdecdhjk"]]89, ["[-abc]", ["-"], null, ["-"]]90, ["[abc-]", ["-"], null, ["-"]]91, ["\\", ["\\"], null, ["\\"]]92, ["[\\\\]", ["\\"], null, ["\\"]]93, ["[[]", ["["], null, ["["]]94, ["[", ["["], null, ["["]]95, ["[*", ["[abc"], null, ["[abc"]]96, "a right bracket shall lose its special meaning and\n" +97"represent itself in a bracket expression if it occurs\n" +98"first in the list. -- POSIX.2 2.8.3.2"99, ["[]]", ["]"], null, ["]"]]100, ["[]-]", ["]"], null, ["]"]]101, ["[a-\z]", ["p"], null, ["p"]]102, ["??**********?****?", [], { null: true }, ["abc"]]103, ["??**********?****c", [], { null: true }, ["abc"]]104, ["?************c****?****", [], { null: true }, ["abc"]]105, ["*c*?**", [], { null: true }, ["abc"]]106, ["a*****c*?**", [], { null: true }, ["abc"]]107, ["a********???*******", [], { null: true }, ["abc"]]108, ["[]", [], { null: true }, ["a"]]109, ["[abc", [], { null: true }, ["["]]110111, "nocase tests"112, ["XYZ", ["xYz"], { nocase: true, null: true }113, ["xYz", "ABC", "IjK"]]114, ["ab*", ["ABC"], { nocase: true, null: true }115, ["xYz", "ABC", "IjK"]]116, ["[ia]?[ck]", ["ABC", "IjK"], { nocase: true, null: true }117, ["xYz", "ABC", "IjK"]]118119// [ pattern, [matches], MM opts, files, TAP opts]120, "onestar/twostar"121, ["{/*,*}", [], {null: true}, ["/asdf/asdf/asdf"]]122, ["{/?,*}", ["/a", "bb"], {null: true}123, ["/a", "/b/b", "/a/b/c", "bb"]]124125, "dots should not match unless requested"126, ["**", ["a/b"], {}, ["a/b", "a/.d", ".a/.d"]]127128// .. and . can only match patterns starting with .,129// even when options.dot is set.130, function () {131files = ["a/./b", "a/../b", "a/c/b", "a/.d/b"]132}133, ["a/*/b", ["a/c/b", "a/.d/b"], {dot: true}]134, ["a/.*/b", ["a/./b", "a/../b", "a/.d/b"], {dot: true}]135, ["a/*/b", ["a/c/b"], {dot:false}]136, ["a/.*/b", ["a/./b", "a/../b", "a/.d/b"], {dot: false}]137138139// this also tests that changing the options needs140// to change the cache key, even if the pattern is141// the same!142, ["**", ["a/b","a/.d",".a/.d"], { dot: true }143, [ ".a/.d", "a/.d", "a/b"]]144145, "paren sets cannot contain slashes"146, ["*(a/b)", ["*(a/b)"], {nonull: true}, ["a/b"]]147148// brace sets trump all else.149//150// invalid glob pattern. fails on bash4 and bsdglob.151// however, in this implementation, it's easier just152// to do the intuitive thing, and let brace-expansion153// actually come before parsing any extglob patterns,154// like the documentation seems to say.155//156// XXX: if anyone complains about this, either fix it157// or tell them to grow up and stop complaining.158//159// bash/bsdglob says this:160// , ["*(a|{b),c)}", ["*(a|{b),c)}"], {}, ["a", "ab", "ac", "ad"]]161// but we do this instead:162, ["*(a|{b),c)}", ["a", "ab", "ac"], {}, ["a", "ab", "ac", "ad"]]163164// test partial parsing in the presence of comment/negation chars165, ["[!a*", ["[!ab"], {}, ["[!ab", "[ab"]]166, ["[#a*", ["[#ab"], {}, ["[#ab", "[ab"]]167168// like: {a,b|c\\,d\\\|e} except it's unclosed, so it has to be escaped.169, ["+(a|*\\|c\\\\|d\\\\\\|e\\\\\\\\|f\\\\\\\\\\|g"170, ["+(a|b\\|c\\\\|d\\\\|e\\\\\\\\|f\\\\\\\\|g"]171, {}172, ["+(a|b\\|c\\\\|d\\\\|e\\\\\\\\|f\\\\\\\\|g", "a", "b\\c"]]173174175// crazy nested {,,} and *(||) tests.176, function () {177files = [ "a", "b", "c", "d"178, "ab", "ac", "ad"179, "bc", "cb"180, "bc,d", "c,db", "c,d"181, "d)", "(b|c", "*(b|c"182, "b|c", "b|cc", "cb|c"183, "x(a|b|c)", "x(a|c)"184, "(a|b|c)", "(a|c)"]185}186, ["*(a|{b,c})", ["a", "b", "c", "ab", "ac"]]187, ["{a,*(b|c,d)}", ["a","(b|c", "*(b|c", "d)"]]188// a189// *(b|c)190// *(b|d)191, ["{a,*(b|{c,d})}", ["a","b", "bc", "cb", "c", "d"]]192, ["*(a|{b|c,c})", ["a", "b", "c", "ab", "ac", "bc", "cb"]]193194195// test various flag settings.196, [ "*(a|{b|c,c})", ["x(a|b|c)", "x(a|c)", "(a|b|c)", "(a|c)"]197, { noext: true } ]198, ["a?b", ["x/y/acb", "acb/"], {matchBase: true}199, ["x/y/acb", "acb/", "acb/d/e", "x/y/acb/d"] ]200, ["#*", ["#a", "#b"], {nocomment: true}, ["#a", "#b", "c#d"]]201202203// begin channelling Boole and deMorgan...204, "negation tests"205, function () {206files = ["d", "e", "!ab", "!abc", "a!b", "\\!a"]207}208209// anything that is NOT a* matches.210, ["!a*", ["\\!a", "d", "e", "!ab", "!abc"]]211212// anything that IS !a* matches.213, ["!a*", ["!ab", "!abc"], {nonegate: true}]214215// anything that IS a* matches216, ["!!a*", ["a!b"]]217218// anything that is NOT !a* matches219, ["!\\!a*", ["a!b", "d", "e", "\\!a"]]220221// negation nestled within a pattern222, function () {223files = [ "foo.js"224, "foo.bar"225// can't match this one without negative lookbehind.226, "foo.js.js"227, "blar.js"228, "foo."229, "boo.js.boo" ]230}231, ["*.!(js)", ["foo.bar", "foo.", "boo.js.boo"] ]232233].forEach(function (c) {234if (typeof c === "function") return c()235if (typeof c === "string") return t.comment(c)236237var pattern = c[0]238, expect = c[1].sort(alpha)239, options = c[2]240, f = c[3] || files241, tapOpts = c[4] || {}242243// options.debug = true244var Class = mm.defaults(options).Minimatch245var m = new Class(pattern, {})246var r = m.makeRe()247tapOpts.re = String(r) || JSON.stringify(r)248tapOpts.files = JSON.stringify(f)249tapOpts.pattern = pattern250tapOpts.set = m.set251tapOpts.negated = m.negate252253var actual = mm.match(f, pattern, options)254actual.sort(alpha)255256t.equivalent( actual, expect257, JSON.stringify(pattern) + " " + JSON.stringify(expect)258, tapOpts )259})260261t.comment("time=" + (Date.now() - start) + "ms")262t.end()263})264265tap.test("global leak test", function (t) {266var globalAfter = Object.keys(global)267t.equivalent(globalAfter, globalBefore, "no new globals, please")268t.end()269})270271function alpha (a, b) {272return a > b ? 1 : -1273}274275276