зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1543484 - Add version comparison to JEXL filter r=mythmon
Differential Revision: https://phabricator.services.mozilla.com/D26975 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
58348f299b
Коммит
a0d2fda5dd
|
@ -4,6 +4,7 @@
|
|||
|
||||
"use strict";
|
||||
|
||||
const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
||||
const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
|
||||
ChromeUtils.defineModuleGetter(this, "PreferenceFilters", "resource://gre/modules/components-utils/PreferenceFilters.jsm");
|
||||
|
@ -25,6 +26,7 @@ XPCOMUtils.defineLazyGetter(this, "jexl", () => {
|
|||
length,
|
||||
mapToProperty,
|
||||
regExpMatch,
|
||||
versionCompare,
|
||||
});
|
||||
jexl.addBinaryOp("intersect", 40, operatorIntersect);
|
||||
return jexl;
|
||||
|
@ -98,3 +100,15 @@ function regExpMatch(str, pattern, flags) {
|
|||
const re = new RegExp(pattern, flags);
|
||||
return str.match(re);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compares v1 to v2 and returns 0 if they are equal, a negative number if
|
||||
* v1 < v2 or a positive number if v1 > v2.
|
||||
* @param {string} v1
|
||||
* @param {string} v2
|
||||
* @return {number}
|
||||
*/
|
||||
function versionCompare(v1, v2) {
|
||||
return Services.vc.compare(v1, v2);
|
||||
}
|
||||
|
|
|
@ -305,3 +305,16 @@ add_task(async function test_regExpMatch() {
|
|||
"regExpMatch returns null if there are no matches",
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_versionCompare() {
|
||||
let val;
|
||||
|
||||
val = await FilterExpressions.eval('"1.0.0"|versionCompare("1")');
|
||||
ok(val === 0);
|
||||
|
||||
val = await FilterExpressions.eval('"1.0.0"|versionCompare("1.1")');
|
||||
ok(val < 0);
|
||||
|
||||
val = await FilterExpressions.eval('"1.0.0"|versionCompare("0.1")');
|
||||
ok(val > 0);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче