test/version.test.mjs (2226B)
1 import { test } from 'node:test';
2 import assert from 'node:assert/strict';
3 import { compareDebian, comparePhp, parsePhpVersion, isSuryBuild } from '../site/lib/version.js';
4
5 // [a, b, expected]: must match the result of dpkg --compare-versions.
6 export const DEB_CASES = [
7 ['1.0', '1.0-1', -1],
8 ['1.0~rc1', '1.0', -1],
9 ['1.0~rc1-1', '1.0-1', -1],
10 ['1:1.0', '2.0', 1],
11 ['8.2.35-1~deb12u1', '8.2.34-1~deb12u1', 1],
12 ['8.2.35-1~deb12u1', '8.2.35-1', -1],
13 ['8.2.26-1~deb12u1', '8.2.35-1~deb12u1', -1],
14 ['8.1.2-1ubuntu2.28', '8.1.2-1ubuntu2.9', 1],
15 ['8.1.2-1ubuntu2.20', '8.1.2-1ubuntu2.28', -1],
16 ['8.1.2-1ubuntu2.28', '8.1.2-1ubuntu2.28', 0],
17 ['7.4.3-4ubuntu2.29+esm5', '7.4.3-4ubuntu2.29', 1],
18 ['5.5.9+dfsg-1ubuntu4.29+esm18', '5.5.9+dfsg-1ubuntu4.29+esm9', 1],
19 ['8.3.6-0ubuntu0.24.04.13', '8.3.6-0ubuntu0.24.04.4', 1],
20 ['1.0a', '1.0+', -1],
21 ['1.0', '1.00', 0],
22 ['2.0.0', '10.0', -1],
23 ];
24
25 test('compareDebian gives the same results as dpkg', () => {
26 for (const [a, b, want] of DEB_CASES) {
27 assert.equal(compareDebian(a, b), want, `${a} vs ${b}`);
28 assert.equal(compareDebian(b, a), want === 0 ? 0 : -want, `${b} vs ${a}`);
29 }
30 });
31
32 test('parsePhpVersion separates the distribution revision and pre-releases', () => {
33 assert.deepEqual(
34 (({ branch, upstream, revision, pre }) => ({ branch, upstream, revision, pre }))(parsePhpVersion('8.1.2-1ubuntu2.20')),
35 { branch: '8.1', upstream: '8.1.2', revision: '1ubuntu2.20', pre: '' },
36 );
37 assert.equal(parsePhpVersion('8.6.0RC3').pre, 'RC3');
38 assert.equal(parsePhpVersion('hello'), null);
39 });
40
41 test('comparePhp sorts pre-releases below final releases', () => {
42 assert.equal(comparePhp('8.4.27', '8.4.27'), 0);
43 assert.equal(comparePhp('8.4.26', '8.4.27'), -1);
44 assert.equal(comparePhp('8.4.100', '8.4.27'), 1);
45 assert.equal(comparePhp('8.6.0RC4', '8.6.0'), -1);
46 assert.equal(comparePhp('8.2.35-1~deb12u1', '8.2.35'), 0);
47 });
48
49 test('isSuryBuild recognises deb.sury.org builds', () => {
50 assert.ok(isSuryBuild('8.3.14-1+ubuntu22.04.1+deb.sury.org+1'));
51 assert.ok(isSuryBuild('8.3.14-1+0~20241122.43+debian12~1.gbp9f1e3a'));
52 assert.ok(!isSuryBuild('8.2.35-1~deb12u1'));
53 assert.ok(!isSuryBuild('8.1.2-1ubuntu2.28'));
54 });