From 432f0f58822d1a7572220a09a97f2708270cc750 Mon Sep 17 00:00:00 2001 From: isaacs Date: Mon, 24 Jun 2013 15:12:21 -0700 Subject: [PATCH] Correct maxSatisfying Was using the wrong compare in the sort function. Closes #35 --- semver.js | 2 +- test/index.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/semver.js b/semver.js index aa1b518f..80b2b032 100644 --- a/semver.js +++ b/semver.js @@ -835,7 +835,7 @@ exports.maxSatisfying = maxSatisfying; function maxSatisfying(versions, range, loose) { return versions.filter(function(version) { return satisfies(version, range, loose); - }).sort(compare)[0] || null; + }).sort(rcompare)[0] || null; } exports.validRange = validRange; diff --git a/test/index.js b/test/index.js index 2ac51deb..a62aaa56 100644 --- a/test/index.js +++ b/test/index.js @@ -514,3 +514,18 @@ test('\nstrict vs loose ranges', function(t) { }); t.end(); }); + +test('\nmax satisfying', function(t) { + [[['1.2.3', '1.2.4'], '1.2', '1.2.4'], + [['1.2.4', '1.2.3'], '1.2', '1.2.4'], + [['1.2.3','1.2.4','1.2.5','1.2.6'], '~1.2.3', '1.2.6'] + ].forEach(function(v) { + var versions = v[0]; + var range = v[1]; + var expect = v[2]; + var loose = v[3]; + var actual = semver.maxSatisfying(versions, range, loose); + t.equal(actual, expect); + }); + t.end(); +});