deno.land / std@0.224.0 / semver / range_intersects_test.ts

range_intersects_test.ts
View Documentation
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license.// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.import { assertEquals } from "../assert/mod.ts";import { parseRange } from "./parse_range.ts";import { rangeIntersects } from "./range_intersects.ts";
Deno.test({ name: "rangesIntersects()", fn: async (t) => { const versions: [string, string, boolean][] = [ ["1.3.0 || <1.0.0 >2.0.0", "1.3.0 || <1.0.0 >2.0.0", true], [">0.0.0", "<1.0.0 >2.0.0", false], ["<1.0.0 >2.0.0", ">1.4.0 <1.6.0", false], ["<1.0.0 >2.0.0", ">1.4.0 <1.6.0 || 2.0.0", false], [">1.0.0 <=2.0.0", "2.0.0", true], ["<1.0.0 >=2.0.0", "2.1.0", false], ["<1.0.0 >=2.0.0", ">1.4.0 <1.6.0 || 2.0.0", false], ["1.5.x", "<1.5.0 || >=1.6.0", false], ["<1.5.0 || >=1.6.0", "1.5.x", false], [ "<1.6.16 || >=1.7.0 <1.7.11 || >=1.8.0 <1.8.2", ">=1.6.16 <1.7.0 || >=1.7.11 <1.8.0 || >=1.8.2", false, ], [ "<=1.6.16 || >=1.7.0 <1.7.11 || >=1.8.0 <1.8.2", ">=1.6.16 <1.7.0 || >=1.7.11 <1.8.0 || >=1.8.2", true, ], [">=1.0.0", "<=1.0.0", true], [">1.0.0 <1.0.0", "<=0.0.0", false], // Pre-release ranges ["<1.0.0", ">1.0.0-5", true], [">1.0.0", "<1.0.0-5", false], [">1.0.0-2", "<=1.0.0-5", true], [">=1.0.0-2", "<1.0.0-5", true], ["<7.0.0-beta.20", ">7.0.0-beta.0", true], ["<7.0.0-beta.beta", ">7.0.0-beta.alpha", true], // Wildcards ["*", "0.0.1", true], ["*", ">=1.0.0", true], ["*", ">1.0.0", true], ["*", "~1.0.0", true], ["*", "<1.6.0", true], ["*", "<=1.6.0", true], ["1.*", "0.0.1", false], ["1.*", "2.0.0", false], ["1.*", "1.0.0", true], ["1.*", "<2.0.0", true], ["1.*", ">1.0.0", true], ["1.*", "<=1.0.0", true], ["1.*", "^1.0.0", true], ["1.0.*", "0.0.1", false], ["1.0.*", "<0.0.1", false], ["1.0.*", ">0.0.1", true], ["*", "1.3.0 || <1.0.0 >2.0.0", true], ["1.3.0 || <1.0.0 >2.0.0", "*", true], ["1.*", "1.3.0 || <1.0.0 >2.0.0", true], ["x", "0.0.1", true], ["x", ">=1.0.0", true], ["x", ">1.0.0", true], ["x", "~1.0.0", true], ["x", "<1.6.0", true], ["x", "<=1.6.0", true], ["1.x", "0.0.1", false], ["1.x", "2.0.0", false], ["1.x", "1.0.0", true], ["1.x", "<2.0.0", true], ["1.x", ">1.0.0", true], ["1.x", "<=1.0.0", true], ["1.x", "^1.0.0", true], ["1.0.x", "0.0.1", false], ["1.0.x", "<0.0.1", false], ["1.0.x", ">0.0.1", true], ["x", "1.3.0 || <1.0.0 >2.0.0", true], ["1.3.0 || <1.0.0 >2.0.0", "x", true], ["1.x", "1.3.0 || <1.0.0 >2.0.0", true], ["*", "*", true], ["x", "", true],
// One is a Version ["1.3.0", ">=1.3.0", true], ["1.3.0", ">1.3.0", false], [">=1.3.0", "1.3.0", true], [">1.3.0", "1.3.0", false],
// Same direction increasing [">1.3.0", ">1.2.0", true], [">1.2.0", ">1.3.0", true], [">=1.2.0", ">1.3.0", true], [">1.2.0", ">=1.3.0", true],
// Same direction decreasing ["<1.3.0", "<1.2.0", true], ["<1.2.0", "<1.3.0", true], ["<=1.2.0", "<1.3.0", true], ["<1.2.0", "<=1.3.0", true],
// Different directions, same semver and inclusive operator [">=1.3.0", "<=1.3.0", true], [">=v1.3.0", "<=1.3.0", true], [">=1.3.0", ">=1.3.0", true], ["<=1.3.0", "<=1.3.0", true], ["<=1.3.0", "<=v1.3.0", true], [">1.3.0", "<=1.3.0", false], [">=1.3.0", "<1.3.0", false],
// Opposite matching directions [">1.0.0", "<2.0.0", true], [">=1.0.0", "<2.0.0", true], [">=1.0.0", "<=2.0.0", true], [">1.0.0", "<=2.0.0", true], ["<=2.0.0", ">1.0.0", true], ["<=1.0.0", ">=2.0.0", false], ];
for (const [r1, r2, expected] of versions) { await t.step({ name: `${r1}${r2}`, fn: () => { const range1 = parseRange(r1); const range2 = parseRange(r2); const actual1 = rangeIntersects(range1, range2); const actual2 = rangeIntersects(range2, range1); assertEquals(actual1, expected); assertEquals(actual2, expected); }, }); } },});
std

Version Info

Tagged at
6 months ago