Skip to content

Commit

Permalink
Merge 39c9118 into 70a4604
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowic committed Dec 28, 2018
2 parents 70a4604 + 39c9118 commit c90fd8d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"lint": "eslint ./src",
"testem": "testem",
"test": "nyc --reporter=html --reporter=text ava",
"test:watch": "ava --watch",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"docs": "jsdoc -c jsdoc.json"
},
Expand Down
23 changes: 16 additions & 7 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ class Parser {
}

compareVersion(version) {
let expectedResult = 0;
let expectedResults = [0];
let comparableVersion = version;
let isLoose = false;

Expand All @@ -405,20 +405,29 @@ class Parser {
return void 0;
}

if (version[0] === '>') {
expectedResult = 1;
comparableVersion = version.substr(1);
} else if (version[0] === '<') {
expectedResult = -1;
if (version[0] === '>' || version[0] === '<') {
comparableVersion = version.substr(1);
if (version[1] === '=') {
isLoose = true;
comparableVersion = version.substr(2);
} else {
expectedResults = [];
}
if (version[0] === '>') {
expectedResults.push(1);
} else {
expectedResults.push(-1);
}
} else if (version[0] === '=') {
comparableVersion = version.substr(1);
} else if (version[0] === '~') {
isLoose = true;
comparableVersion = version.substr(1);
}

return compareVersions(currentBrowserVersion, comparableVersion, isLoose) === expectedResult;
return expectedResults.indexOf(
compareVersions(currentBrowserVersion, comparableVersion, isLoose),
) > -1;
}

isOS(osName) {
Expand Down
1 change: 1 addition & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ class Utils {

// iterate in reverse order by reversed chunks array
precision -= 1;

while (precision >= lastPrecision) {
// 4) compare: "000000009" > "000000010" = false (but "9" > "10" = true)
if (chunks[0][precision] > chunks[1][precision]) {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ test('Parser.satisfies should make simple comparisons', (t) => {
t.is(parser.satisfies({ opera: '<44' }), true);
t.is(parser.satisfies({ opera: '=43.0.2442.1165' }), true);
t.is(parser.satisfies({ opera: '~43.0' }), true);
t.is(parser.satisfies({ opera: '>=43' }), true);
t.is(parser.satisfies({ opera: '<=43' }), true);
t.is(parser.satisfies({ opera: '>=43.0' }), true);
t.is(parser.satisfies({ opera: '>=43.0.2442.1165' }), true);
t.is(parser.satisfies({ opera: '<=43.0.2442.1165' }), true);
t.is(parser.satisfies({ opera: '>=43.0.2443' }), false);
t.is(parser.satisfies({ opera: '<=43.0.2443' }), true);
t.is(parser.satisfies({ opera: '>=43.0.2441' }), true);
t.is(parser.satisfies({ opera: '~43' }), true);
});

Expand Down

0 comments on commit c90fd8d

Please sign in to comment.