mirror of
https://github.com/edu4rdshl/gnome-shell.git
synced 2026-07-17 23:24:51 +00:00
util: Add a GNOME version comparison function
Add a function that can compare GNOME versions, including the new naming scheme for GNOME 40 and later. Used in https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3632 Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1619>
This commit is contained in:
parent
af4e54bfc9
commit
b0a48fad57
3 changed files with 92 additions and 2 deletions
52
tests/unit/versionCompare.js
Normal file
52
tests/unit/versionCompare.js
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||
|
||||
// Test cases for version comparison
|
||||
|
||||
const JsUnit = imports.jsUnit;
|
||||
|
||||
const Environment = imports.ui.environment;
|
||||
Environment.init();
|
||||
|
||||
const Util = imports.misc.util;
|
||||
|
||||
const tests = [
|
||||
{ v1: '40',
|
||||
v2: '40',
|
||||
res: 0 },
|
||||
{ v1: '40',
|
||||
v2: '42',
|
||||
res: -1 },
|
||||
{ v1: '42',
|
||||
v2: '40',
|
||||
res: 1 },
|
||||
{ v1: '3.38.0',
|
||||
v2: '40',
|
||||
res: -1 },
|
||||
{ v1: '40',
|
||||
v2: '3.38.0',
|
||||
res: 1 },
|
||||
{ v1: '40',
|
||||
v2: '3.38.0',
|
||||
res: 1 },
|
||||
{ v1: '40.alpha.1.1',
|
||||
v2: '40',
|
||||
res: -1 },
|
||||
{ v1: '40',
|
||||
v2: '40.alpha.1.1',
|
||||
res: 1 },
|
||||
{ v1: '40.beta',
|
||||
v2: '40',
|
||||
res: -1 },
|
||||
{ v1: '40.1',
|
||||
v2: '40',
|
||||
res: 1 },
|
||||
{ v1: '',
|
||||
v2: '40.alpha',
|
||||
res: -1 },
|
||||
];
|
||||
|
||||
for (let i = 0; i < tests.length; i++) {
|
||||
name = 'Test #' + i + ' v1: ' + tests[i].v1 + ', v2: ' + tests[i].v2;
|
||||
print(name);
|
||||
JsUnit.assertEquals(name, Util.GNOMEversionCompare (tests[i].v1, tests[i].v2), tests[i].res);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue