cocalc/src / smc-project / node_modules / forever-monitor / node_modules / minimatch / test / basic.js
50655 views// http://www.bashcookbook.com/bashinfo/source/bash-1.14.7/tests/glob-test12var tap = require("tap")3, globalBefore = Object.keys(global)4, mm = require("../")5, files = [ "a", "b", "c", "d", "abc"6, "abd", "abe", "bb", "bcd"7, "ca", "cb", "dd", "de"8, "bdir/", "bdir/cfile"]9, next = files.concat([ "a-b", "aXb"10, ".x", ".y" ])1112tap.test("basic tests", function (t) {13var start = Date.now()1415// [ pattern, [matches], MM opts, files, TAP opts]16; [ "http://www.bashcookbook.com/bashinfo" +17"/source/bash-1.14.7/tests/glob-test"18, ["a*", ["a", "abc", "abd", "abe"]]19, ["X*", ["X*"]]20// allow null glob expansion21, ["X*", [], { null: true }]2223// isaacs: Slightly different than bash/sh/ksh24// \\* is not un-escaped to literal "*" in a failed match,25// but it does make it get treated as a literal star26, ["\\*", ["\\*"]]27, ["\\**", ["\\**"]]2829, ["b*/", ["bdir/"]]30, ["c*", ["c", "ca", "cb"]]31, ["**", files]323334, ["\\.\\./*/", ["\\.\\./*/"]]35, ["s/\\..*//", ["s/\\..*//"]]3637, "legendary larry crashes bashes"38, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"39, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\\1/"]]40, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"41, ["/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/"]]4243, "character classes"44, ["[a-c]b*", ["abc", "abd", "abe", "bb", "cb"]]45, ["[a-y]*[^c]", ["abd", "abe", "bb", "bcd",46"bdir/", "ca", "cb", "dd", "de"]]47, ["a*[^c]", ["abd", "abe"]]48, function () { files.push("a-b", "aXb") }49, ["a[X-]b", ["a-b", "aXb"]]50, function () { files.push(".x", ".y") }51, ["[^a-c]*", ["d", "dd", "de"]]52, function () { files.push("a*b/", "a*b/ooo") }53, ["a\\*b/*", ["a*b/ooo"]]54, ["a\\*?/*", ["a*b/ooo"]]55, ["*\\\\!*", [], {null: true}, ["echo !7"]]56, ["*\\!*", ["echo !7"], null, ["echo !7"]]57, ["*.\\*", ["r.*"], null, ["r.*"]]58, ["a[b]c", ["abc"]]59, ["a[\\b]c", ["abc"]]60, ["a?c", ["abc"]]61, ["a\\*c", [], {null: true}, ["abc"]]62, ["", [""], { null: true }, [""]]6364, "http://www.opensource.apple.com/source/bash/bash-23/" +65"bash/tests/glob-test"66, function () { files.push("man/", "man/man1/", "man/man1/bash.1") }67, ["*/man*/bash.*", ["man/man1/bash.1"]]68, ["man/man1/bash.1", ["man/man1/bash.1"]]69, ["a***c", ["abc"], null, ["abc"]]70, ["a*****?c", ["abc"], null, ["abc"]]71, ["?*****??", ["abc"], null, ["abc"]]72, ["*****??", ["abc"], null, ["abc"]]73, ["?*****?c", ["abc"], null, ["abc"]]74, ["?***?****c", ["abc"], null, ["abc"]]75, ["?***?****?", ["abc"], null, ["abc"]]76, ["?***?****", ["abc"], null, ["abc"]]77, ["*******c", ["abc"], null, ["abc"]]78, ["*******?", ["abc"], null, ["abc"]]79, ["a*cd**?**??k", ["abcdecdhjk"], null, ["abcdecdhjk"]]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****c**?**??*****", ["abcdecdhjk"], null, ["abcdecdhjk"]]85, ["[-abc]", ["-"], null, ["-"]]86, ["[abc-]", ["-"], null, ["-"]]87, ["\\", ["\\"], null, ["\\"]]88, ["[\\\\]", ["\\"], null, ["\\"]]89, ["[[]", ["["], null, ["["]]90, ["[", ["["], null, ["["]]91, ["[*", ["[abc"], null, ["[abc"]]92, "a right bracket shall lose its special meaning and\n" +93"represent itself in a bracket expression if it occurs\n" +94"first in the list. -- POSIX.2 2.8.3.2"95, ["[]]", ["]"], null, ["]"]]96, ["[]-]", ["]"], null, ["]"]]97, ["[a-\z]", ["p"], null, ["p"]]98, ["[/\\\\]*", ["/tmp"], null, ["/tmp"]]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// this also tests that changing the options needs126// to change the cache key, even if the pattern is127// the same!128, ["**", ["a/b","a/.d",".a/.d"], { dot: true }129, [ ".a/.d", "a/.d", "a/b"]]130131].forEach(function (c) {132if (typeof c === "function") return c()133if (typeof c === "string") return t.comment(c)134135var pattern = c[0]136, expect = c[1].sort(alpha)137, options = c[2] || {}138, f = c[3] || files139, tapOpts = c[4] || {}140141// options.debug = true142var r = mm.makeRe(pattern, options)143tapOpts.re = String(r) || JSON.stringify(r)144tapOpts.files = JSON.stringify(f)145tapOpts.pattern = pattern146147var actual = mm.match(f, pattern, options)148149t.equivalent( actual, expect150, JSON.stringify(pattern) + " " + JSON.stringify(expect)151, tapOpts )152})153154t.comment("time=" + (Date.now() - start) + "ms")155t.end()156})157158tap.test("global leak test", function (t) {159var globalAfter = Object.keys(global)160t.equivalent(globalAfter, globalBefore, "no new globals, please")161t.end()162})163164function alpha (a, b) {165return a > b ? 1 : -1166}167168169