forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathversion.test.ts
More file actions
33 lines (29 loc) · 1.06 KB
/
version.test.ts
File metadata and controls
33 lines (29 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { calcCompatibleVersion } from '../../src/utils/version';
const NO_COMPATIBLE_VERSIONS = /no compatible versions/;
test.each([
['*', '*', '*'],
['1.0.0', '1.0.0', '1.0.0'],
['^1.0.0', '^1.0.0', '^1.0.0'],
['*', undefined, '*'],
[undefined, undefined, '*'],
['^1.0.0', undefined, '^1.0.0'],
['*', '^1.0.0', '^1.0.0'],
['^1.0.0', '^1.0.2', '^1.0.2'],
['^1.2.0', '^1.1.2', '^1.2.0'],
['^1.0.0', '1.0.2', '1.0.2'],
])('calc compatible versions "%i" & "%i" should be "%i"', (a, b, expected) => {
expect(calcCompatibleVersion(a, b)).toBe(expected);
expect(calcCompatibleVersion(b, a)).toBe(expected); // 应该满足交换律
});
test.each([
['^0.2.0', '^0.1.2', NO_COMPATIBLE_VERSIONS],
['>0.2.0', '^0.1.2', NO_COMPATIBLE_VERSIONS],
['1.0.1', '1.0.2', NO_COMPATIBLE_VERSIONS],
])('calc compatible versions "%i" & "%i" should be no compatible versions', (a, b, expected) => {
expect(() => {
calcCompatibleVersion(a, b);
}).toThrow(expected);
expect(() => {
calcCompatibleVersion(b, a); // 应该满足交换律
}).toThrow(expected);
});