1
0
mirror of https://github.com/lancedikson/bowser synced 2026-03-02 03:40:27 +00:00

Adds loose comparison support

This commit is contained in:
udivankin
2018-08-16 19:04:10 +03:00
committed by udi
parent 42b4c8cfa3
commit 6204d9f417
5 changed files with 44 additions and 15 deletions

View File

@@ -57,8 +57,13 @@ test('Skip parsing shouldn\'t parse', (t) => {
t.deepEqual((new Parser(UA, true)).getResult(), {});
});
test('Parser.check should make simple comparison', (t) => {
test('Parser.check should make simple comparisons', (t) => {
// also covers Parser.compareVersion() method
t.is(parser.satisfies({ opera: '>42' }), true);
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);
});
test('Parser.check should make complex comparison', (t) => {

View File

@@ -22,6 +22,9 @@ test('compareVersions', (t) => {
['1.10.2.1', '1.8.2.1.90', 1],
['1.010.2.1', '1.08.2.1.90', 1],
['1.10.2.1', '1.10.2.1', 0],
['1.10.2.1', '1.10.2', 0, true],
['1.10.2.1', '1.10', 0, true],
['1.10.2.1', '1', 0, true],
['1.10.2.1', '1.0800.2', -1],
['1.0.0-alpha', '1.0.0-alpha.1', -1],
['1.0.0-alpha.1', '1.0.0-alpha.beta', -1],
@@ -35,7 +38,8 @@ test('compareVersions', (t) => {
const versionA = testingParams[0];
const versionB = testingParams[1];
const result = testingParams[2];
let matching = ' == ';
const isLoose = testingParams.length > 3 ? testingParams[3] : false;
let matching = isLoose ? '~' : ' == ';
if (result > 0) {
matching = ' > ';
@@ -43,6 +47,6 @@ test('compareVersions', (t) => {
matching = ' < ';
}
t.is(compareVersions(versionA, versionB), result, `version ${versionA} should be ${matching} version ${versionB}`);
t.is(compareVersions(versionA, versionB, isLoose), result, `version ${versionA} should be ${matching} version ${versionB}`);
});
});