| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433 | var tap = require("tap")  , test = tap.test  , semver = require("./semver.js")  , eq = semver.eq  , gt = semver.gt  , lt = semver.lt  , neq = semver.neq  , cmp = semver.cmp  , gte = semver.gte  , lte = semver.lte  , satisfies = semver.satisfies  , validRange = semver.validRange  , inc = semver.inc  , replaceStars = semver.replaceStars  , toComparators = semver.toComparatorstap.plan(8)test("\ncomparison tests", function (t) {// [version1, version2]// version1 should be greater than version2; [ ["0.0.0", "0.0.0foo"]  , ["0.0.1", "0.0.0"]  , ["1.0.0", "0.9.9"]  , ["0.10.0", "0.9.0"]  , ["0.99.0", "0.10.0"]  , ["2.0.0", "1.2.3"]  , ["v0.0.0", "0.0.0foo"]  , ["v0.0.1", "0.0.0"]  , ["v1.0.0", "0.9.9"]  , ["v0.10.0", "0.9.0"]  , ["v0.99.0", "0.10.0"]  , ["v2.0.0", "1.2.3"]  , ["0.0.0", "v0.0.0foo"]  , ["0.0.1", "v0.0.0"]  , ["1.0.0", "v0.9.9"]  , ["0.10.0", "v0.9.0"]  , ["0.99.0", "v0.10.0"]  , ["2.0.0", "v1.2.3"]  , ["1.2.3", "1.2.3-asdf"]  , ["1.2.3-4", "1.2.3"]  , ["1.2.3-4-foo", "1.2.3"]  , ["1.2.3-5", "1.2.3-5-foo"]  , ["1.2.3-5", "1.2.3-4"]  , ["1.2.3-5-foo", "1.2.3-5-Foo"]  , ["3.0.0", "2.7.2+"]  ].forEach(function (v) {    var v0 = v[0]      , v1 = v[1]    t.ok(gt(v0, v1), "gt('"+v0+"', '"+v1+"')")    t.ok(lt(v1, v0), "lt('"+v1+"', '"+v0+"')")    t.ok(!gt(v1, v0), "!gt('"+v1+"', '"+v0+"')")    t.ok(!lt(v0, v1), "!lt('"+v0+"', '"+v1+"')")    t.ok(eq(v0, v0), "eq('"+v0+"', '"+v0+"')")    t.ok(eq(v1, v1), "eq('"+v1+"', '"+v1+"')")    t.ok(neq(v0, v1), "neq('"+v0+"', '"+v1+"')")    t.ok(cmp(v1, "==", v1), "cmp('"+v1+"' == '"+v1+"')")    t.ok(cmp(v0, ">=", v1), "cmp('"+v0+"' >= '"+v1+"')")    t.ok(cmp(v1, "<=", v0), "cmp('"+v1+"' <= '"+v0+"')")    t.ok(cmp(v0, "!=", v1), "cmp('"+v0+"' != '"+v1+"')")  })  t.end()})test("\nequality tests", function (t) {// [version1, version2]// version1 should be equivalent to version2; [ ["1.2.3", "v1.2.3"]  , ["1.2.3", "=1.2.3"]  , ["1.2.3", "v 1.2.3"]  , ["1.2.3", "= 1.2.3"]  , ["1.2.3", " v1.2.3"]  , ["1.2.3", " =1.2.3"]  , ["1.2.3", " v 1.2.3"]  , ["1.2.3", " = 1.2.3"]  , ["1.2.3-0", "v1.2.3-0"]  , ["1.2.3-0", "=1.2.3-0"]  , ["1.2.3-0", "v 1.2.3-0"]  , ["1.2.3-0", "= 1.2.3-0"]  , ["1.2.3-0", " v1.2.3-0"]  , ["1.2.3-0", " =1.2.3-0"]  , ["1.2.3-0", " v 1.2.3-0"]  , ["1.2.3-0", " = 1.2.3-0"]  , ["1.2.3-01", "v1.2.3-1"]  , ["1.2.3-01", "=1.2.3-1"]  , ["1.2.3-01", "v 1.2.3-1"]  , ["1.2.3-01", "= 1.2.3-1"]  , ["1.2.3-01", " v1.2.3-1"]  , ["1.2.3-01", " =1.2.3-1"]  , ["1.2.3-01", " v 1.2.3-1"]  , ["1.2.3-01", " = 1.2.3-1"]  , ["1.2.3beta", "v1.2.3beta"]  , ["1.2.3beta", "=1.2.3beta"]  , ["1.2.3beta", "v 1.2.3beta"]  , ["1.2.3beta", "= 1.2.3beta"]  , ["1.2.3beta", " v1.2.3beta"]  , ["1.2.3beta", " =1.2.3beta"]  , ["1.2.3beta", " v 1.2.3beta"]  , ["1.2.3beta", " = 1.2.3beta"]  ].forEach(function (v) {    var v0 = v[0]      , v1 = v[1]    t.ok(eq(v0, v1), "eq('"+v0+"', '"+v1+"')")    t.ok(!neq(v0, v1), "!neq('"+v0+"', '"+v1+"')")    t.ok(cmp(v0, "==", v1), "cmp("+v0+"=="+v1+")")    t.ok(!cmp(v0, "!=", v1), "!cmp("+v0+"!="+v1+")")    t.ok(!cmp(v0, "===", v1), "!cmp("+v0+"==="+v1+")")    t.ok(cmp(v0, "!==", v1), "cmp("+v0+"!=="+v1+")")    t.ok(!gt(v0, v1), "!gt('"+v0+"', '"+v1+"')")    t.ok(gte(v0, v1), "gte('"+v0+"', '"+v1+"')")    t.ok(!lt(v0, v1), "!lt('"+v0+"', '"+v1+"')")    t.ok(lte(v0, v1), "lte('"+v0+"', '"+v1+"')")  })  t.end()})test("\nrange tests", function (t) {// [range, version]// version should be included by range; [ ["1.0.0 - 2.0.0", "1.2.3"]  , ["1.0.0", "1.0.0"]  , [">=*", "0.2.4"]  , ["", "1.0.0"]  , ["*", "1.2.3"]  , ["*", "v1.2.3-foo"]  , [">=1.0.0", "1.0.0"]  , [">=1.0.0", "1.0.1"]  , [">=1.0.0", "1.1.0"]  , [">1.0.0", "1.0.1"]  , [">1.0.0", "1.1.0"]  , ["<=2.0.0", "2.0.0"]  , ["<=2.0.0", "1.9999.9999"]  , ["<=2.0.0", "0.2.9"]  , ["<2.0.0", "1.9999.9999"]  , ["<2.0.0", "0.2.9"]  , [">= 1.0.0", "1.0.0"]  , [">=  1.0.0", "1.0.1"]  , [">=   1.0.0", "1.1.0"]  , ["> 1.0.0", "1.0.1"]  , [">  1.0.0", "1.1.0"]  , ["<=   2.0.0", "2.0.0"]  , ["<= 2.0.0", "1.9999.9999"]  , ["<=  2.0.0", "0.2.9"]  , ["<    2.0.0", "1.9999.9999"]  , ["<\t2.0.0", "0.2.9"]  , [">=0.1.97", "v0.1.97"]  , [">=0.1.97", "0.1.97"]  , ["0.1.20 || 1.2.4", "1.2.4"]  , [">=0.2.3 || <0.0.1", "0.0.0"]  , [">=0.2.3 || <0.0.1", "0.2.3"]  , [">=0.2.3 || <0.0.1", "0.2.4"]  , ["||", "1.3.4"]  , ["2.x.x", "2.1.3"]  , ["1.2.x", "1.2.3"]  , ["1.2.x || 2.x", "2.1.3"]  , ["1.2.x || 2.x", "1.2.3"]  , ["x", "1.2.3"]  , ["2.*.*", "2.1.3"]  , ["1.2.*", "1.2.3"]  , ["1.2.* || 2.*", "2.1.3"]  , ["1.2.* || 2.*", "1.2.3"]  , ["*", "1.2.3"]  , ["2", "2.1.2"]  , ["2.3", "2.3.1"]  , ["~2.4", "2.4.0"] // >=2.4.0 <2.5.0  , ["~2.4", "2.4.5"]  , ["~>3.2.1", "3.2.2"] // >=3.2.1 <3.3.0  , ["~1", "1.2.3"] // >=1.0.0 <2.0.0  , ["~>1", "1.2.3"]  , ["~> 1", "1.2.3"]  , ["~1.0", "1.0.2"] // >=1.0.0 <1.1.0  , ["~ 1.0", "1.0.2"]  , [">=1", "1.0.0"]  , [">= 1", "1.0.0"]  , ["<1.2", "1.1.1"]  , ["< 1.2", "1.1.1"]  , ["1", "1.0.0beta"]  , ["~v0.5.4-pre", "0.5.5"]  , ["~v0.5.4-pre", "0.5.4"]  , ["=0.7.x", "0.7.2"]  , [">=0.7.x", "0.7.2"]  , ["=0.7.x", "0.7.0-asdf"]  , [">=0.7.x", "0.7.0-asdf"]  , ["<=0.7.x", "0.6.2"]  , ["~1.2.1 >=1.2.3", "1.2.3"]  , ["~1.2.1 =1.2.3", "1.2.3"]  , ["~1.2.1 1.2.3", "1.2.3"]  , ['~1.2.1 >=1.2.3 1.2.3', '1.2.3']  , ['~1.2.1 1.2.3 >=1.2.3', '1.2.3']  , ['~1.2.1 1.2.3', '1.2.3']  , ['>=1.2.1 1.2.3', '1.2.3']  , ['1.2.3 >=1.2.1', '1.2.3']  , ['>=1.2.3 >=1.2.1', '1.2.3']  , ['>=1.2.1 >=1.2.3', '1.2.3']  ].forEach(function (v) {    t.ok(satisfies(v[1], v[0]), v[0]+" satisfied by "+v[1])  })  t.end()})test("\nnegative range tests", function (t) {// [range, version]// version should not be included by range; [ ["1.0.0 - 2.0.0", "2.2.3"]  , ["1.0.0", "1.0.1"]  , [">=1.0.0", "0.0.0"]  , [">=1.0.0", "0.0.1"]  , [">=1.0.0", "0.1.0"]  , [">1.0.0", "0.0.1"]  , [">1.0.0", "0.1.0"]  , ["<=2.0.0", "3.0.0"]  , ["<=2.0.0", "2.9999.9999"]  , ["<=2.0.0", "2.2.9"]  , ["<2.0.0", "2.9999.9999"]  , ["<2.0.0", "2.2.9"]  , [">=0.1.97", "v0.1.93"]  , [">=0.1.97", "0.1.93"]  , ["0.1.20 || 1.2.4", "1.2.3"]  , [">=0.2.3 || <0.0.1", "0.0.3"]  , [">=0.2.3 || <0.0.1", "0.2.2"]  , ["2.x.x", "1.1.3"]  , ["2.x.x", "3.1.3"]  , ["1.2.x", "1.3.3"]  , ["1.2.x || 2.x", "3.1.3"]  , ["1.2.x || 2.x", "1.1.3"]  , ["2.*.*", "1.1.3"]  , ["2.*.*", "3.1.3"]  , ["1.2.*", "1.3.3"]  , ["1.2.* || 2.*", "3.1.3"]  , ["1.2.* || 2.*", "1.1.3"]  , ["2", "1.1.2"]  , ["2.3", "2.4.1"]  , ["~2.4", "2.5.0"] // >=2.4.0 <2.5.0  , ["~2.4", "2.3.9"]  , ["~>3.2.1", "3.3.2"] // >=3.2.1 <3.3.0  , ["~>3.2.1", "3.2.0"] // >=3.2.1 <3.3.0  , ["~1", "0.2.3"] // >=1.0.0 <2.0.0  , ["~>1", "2.2.3"]  , ["~1.0", "1.1.0"] // >=1.0.0 <1.1.0  , ["<1", "1.0.0"]  , [">=1.2", "1.1.1"]  , ["1", "2.0.0beta"]  , ["~v0.5.4-beta", "0.5.4-alpha"]  , ["<1", "1.0.0beta"]  , ["< 1", "1.0.0beta"]  , ["=0.7.x", "0.8.2"]  , [">=0.7.x", "0.6.2"]  , ["<=0.7.x", "0.7.2"]  ].forEach(function (v) {    t.ok(!satisfies(v[1], v[0]), v[0]+" not satisfied by "+v[1])  })  t.end()})test("\nincrement versions test", function (t) {// [version, inc, result]// inc(version, inc) -> result; [ [ "1.2.3",   "major", "2.0.0"   ]  , [ "1.2.3",   "minor", "1.3.0"   ]  , [ "1.2.3",   "patch", "1.2.4"   ]  , [ "1.2.3",   "build", "1.2.3-1" ]  , [ "1.2.3-4", "build", "1.2.3-5" ]  , [ "1.2.3tag",    "major", "2.0.0"   ]  , [ "1.2.3-tag",   "major", "2.0.0"   ]  , [ "1.2.3tag",    "build", "1.2.3-1" ]  , [ "1.2.3-tag",   "build", "1.2.3-1" ]  , [ "1.2.3-4-tag", "build", "1.2.3-5" ]  , [ "1.2.3-4tag",  "build", "1.2.3-5" ]  , [ "1.2.3", "fake",  null ]  , [ "fake",  "major", null ]  ].forEach(function (v) {    t.equal(inc(v[0], v[1]), v[2], "inc("+v[0]+", "+v[1]+") === "+v[2])  })  t.end()})test("\nreplace stars test", function (t) {// replace stars with ""; [ [ "", "" ]  , [ "*", "" ]  , [ "> *", "" ]  , [ "<*", "" ]  , [ " >=  *", "" ]  , [ "* || 1.2.3", " || 1.2.3" ]  ].forEach(function (v) {    t.equal(replaceStars(v[0]), v[1], "replaceStars("+v[0]+") === "+v[1])  })  t.end()})test("\nvalid range test", function (t) {// [range, result]// validRange(range) -> result// translate ranges into their canonical form; [ ["1.0.0 - 2.0.0", ">=1.0.0 <=2.0.0"]  , ["1.0.0", "1.0.0"]  , [">=*", ""]  , ["", ""]  , ["*", ""]  , ["*", ""]  , [">=1.0.0", ">=1.0.0"]  , [">1.0.0", ">1.0.0"]  , ["<=2.0.0", "<=2.0.0"]  , ["1", ">=1.0.0- <2.0.0-"]  , ["<=2.0.0", "<=2.0.0"]  , ["<=2.0.0", "<=2.0.0"]  , ["<2.0.0", "<2.0.0"]  , ["<2.0.0", "<2.0.0"]  , [">= 1.0.0", ">=1.0.0"]  , [">=  1.0.0", ">=1.0.0"]  , [">=   1.0.0", ">=1.0.0"]  , ["> 1.0.0", ">1.0.0"]  , [">  1.0.0", ">1.0.0"]  , ["<=   2.0.0", "<=2.0.0"]  , ["<= 2.0.0", "<=2.0.0"]  , ["<=  2.0.0", "<=2.0.0"]  , ["<    2.0.0", "<2.0.0"]  , ["<	2.0.0", "<2.0.0"]  , [">=0.1.97", ">=0.1.97"]  , [">=0.1.97", ">=0.1.97"]  , ["0.1.20 || 1.2.4", "0.1.20||1.2.4"]  , [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"]  , [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"]  , [">=0.2.3 || <0.0.1", ">=0.2.3||<0.0.1"]  , ["||", "||"]  , ["2.x.x", ">=2.0.0- <3.0.0-"]  , ["1.2.x", ">=1.2.0- <1.3.0-"]  , ["1.2.x || 2.x", ">=1.2.0- <1.3.0-||>=2.0.0- <3.0.0-"]  , ["1.2.x || 2.x", ">=1.2.0- <1.3.0-||>=2.0.0- <3.0.0-"]  , ["x", ""]  , ["2.*.*", null]  , ["1.2.*", null]  , ["1.2.* || 2.*", null]  , ["1.2.* || 2.*", null]  , ["*", ""]  , ["2", ">=2.0.0- <3.0.0-"]  , ["2.3", ">=2.3.0- <2.4.0-"]  , ["~2.4", ">=2.4.0- <2.5.0-"]  , ["~2.4", ">=2.4.0- <2.5.0-"]  , ["~>3.2.1", ">=3.2.1- <3.3.0-"]  , ["~1", ">=1.0.0- <2.0.0-"]  , ["~>1", ">=1.0.0- <2.0.0-"]  , ["~> 1", ">=1.0.0- <2.0.0-"]  , ["~1.0", ">=1.0.0- <1.1.0-"]  , ["~ 1.0", ">=1.0.0- <1.1.0-"]  , ["<1", "<1.0.0-"]  , ["< 1", "<1.0.0-"]  , [">=1", ">=1.0.0-"]  , [">= 1", ">=1.0.0-"]  , ["<1.2", "<1.2.0-"]  , ["< 1.2", "<1.2.0-"]  , ["1", ">=1.0.0- <2.0.0-"]  ].forEach(function (v) {    t.equal(validRange(v[0]), v[1], "validRange("+v[0]+") === "+v[1])  })  t.end()})test("\ncomparators test", function (t) {// [range, comparators]// turn range into a set of individual comparators; [ ["1.0.0 - 2.0.0", [[">=1.0.0", "<=2.0.0"]] ]  , ["1.0.0", [["1.0.0"]] ]  , [">=*", [[">=0.0.0-"]] ]  , ["", [[""]]]  , ["*", [[""]] ]  , ["*", [[""]] ]  , [">=1.0.0", [[">=1.0.0"]] ]  , [">=1.0.0", [[">=1.0.0"]] ]  , [">=1.0.0", [[">=1.0.0"]] ]  , [">1.0.0", [[">1.0.0"]] ]  , [">1.0.0", [[">1.0.0"]] ]  , ["<=2.0.0", [["<=2.0.0"]] ]  , ["1", [[">=1.0.0-", "<2.0.0-"]] ]  , ["<=2.0.0", [["<=2.0.0"]] ]  , ["<=2.0.0", [["<=2.0.0"]] ]  , ["<2.0.0", [["<2.0.0"]] ]  , ["<2.0.0", [["<2.0.0"]] ]  , [">= 1.0.0", [[">=1.0.0"]] ]  , [">=  1.0.0", [[">=1.0.0"]] ]  , [">=   1.0.0", [[">=1.0.0"]] ]  , ["> 1.0.0", [[">1.0.0"]] ]  , [">  1.0.0", [[">1.0.0"]] ]  , ["<=   2.0.0", [["<=2.0.0"]] ]  , ["<= 2.0.0", [["<=2.0.0"]] ]  , ["<=  2.0.0", [["<=2.0.0"]] ]  , ["<    2.0.0", [["<2.0.0"]] ]  , ["<\t2.0.0", [["<2.0.0"]] ]  , [">=0.1.97", [[">=0.1.97"]] ]  , [">=0.1.97", [[">=0.1.97"]] ]  , ["0.1.20 || 1.2.4", [["0.1.20"], ["1.2.4"]] ]  , [">=0.2.3 || <0.0.1", [[">=0.2.3"], ["<0.0.1"]] ]  , [">=0.2.3 || <0.0.1", [[">=0.2.3"], ["<0.0.1"]] ]  , [">=0.2.3 || <0.0.1", [[">=0.2.3"], ["<0.0.1"]] ]  , ["||", [[""], [""]] ]  , ["2.x.x", [[">=2.0.0-", "<3.0.0-"]] ]  , ["1.2.x", [[">=1.2.0-", "<1.3.0-"]] ]  , ["1.2.x || 2.x", [[">=1.2.0-", "<1.3.0-"], [">=2.0.0-", "<3.0.0-"]] ]  , ["1.2.x || 2.x", [[">=1.2.0-", "<1.3.0-"], [">=2.0.0-", "<3.0.0-"]] ]  , ["x", [[""]] ]  , ["2.*.*", [[">=2.0.0-", "<3.0.0-"]] ]  , ["1.2.*", [[">=1.2.0-", "<1.3.0-"]] ]  , ["1.2.* || 2.*", [[">=1.2.0-", "<1.3.0-"], [">=2.0.0-", "<3.0.0-"]] ]  , ["1.2.* || 2.*", [[">=1.2.0-", "<1.3.0-"], [">=2.0.0-", "<3.0.0-"]] ]  , ["*", [[""]] ]  , ["2", [[">=2.0.0-", "<3.0.0-"]] ]  , ["2.3", [[">=2.3.0-", "<2.4.0-"]] ]  , ["~2.4", [[">=2.4.0-", "<2.5.0-"]] ]  , ["~2.4", [[">=2.4.0-", "<2.5.0-"]] ]  , ["~>3.2.1", [[">=3.2.1-", "<3.3.0-"]] ]  , ["~1", [[">=1.0.0-", "<2.0.0-"]] ]  , ["~>1", [[">=1.0.0-", "<2.0.0-"]] ]  , ["~> 1", [[">=1.0.0-", "<2.0.0-"]] ]  , ["~1.0", [[">=1.0.0-", "<1.1.0-"]] ]  , ["~ 1.0", [[">=1.0.0-", "<1.1.0-"]] ]  , ["<1", [["<1.0.0-"]] ]  , ["< 1", [["<1.0.0-"]] ]  , [">=1", [[">=1.0.0-"]] ]  , [">= 1", [[">=1.0.0-"]] ]  , ["<1.2", [["<1.2.0-"]] ]  , ["< 1.2", [["<1.2.0-"]] ]  , ["1", [[">=1.0.0-", "<2.0.0-"]] ]  , ["1 2", [[">=1.0.0-", "<2.0.0-", ">=2.0.0-", "<3.0.0-"]] ]  ].forEach(function (v) {    t.equivalent(toComparators(v[0]), v[1], "toComparators("+v[0]+") === "+JSON.stringify(v[1]))  })  t.end()})
 |