deno.land / std@0.177.1 / semver / comparators_test.ts

comparators_test.ts
نووسراو ببینە
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license.// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.import { assert, assertEquals } from "../testing/asserts.ts";import * as semver from "./mod.ts";
type Version = string;
Deno.test("comparators", function () { // [range, comparators] // turn range into a set of individual comparators const versions: [Version, string[][]][] = [ ["1.0.0 - 2.0.0", [[">=1.0.0", "<=2.0.0"]]], ["1.0.0", [["1.0.0"]]], [">=*", [[""]]], ["", [[""]]], ["*", [[""]]], ["*", [[""]]], [">=1.0.0", [[">=1.0.0"]]], [">=1.0.0", [[">=1.0.0"]]], [">=1.0.0", [[">=1.0.0"]]], [">1.0.0", [[">1.0.0"]]], [">1.0.0", [[">1.0.0"]]], ["<=2.0.0", [["<=2.0.0"]]], ["1", [[">=1.0.0", "<2.0.0"]]], ["<=2.0.0", [["<=2.0.0"]]], ["<=2.0.0", [["<=2.0.0"]]], ["<2.0.0", [["<2.0.0"]]], ["<2.0.0", [["<2.0.0"]]], [">=0.1.97", [[">=0.1.97"]]], [">=0.1.97", [[">=0.1.97"]]], ["0.1.20 || 1.2.4", [["0.1.20"], ["1.2.4"]]], [">=0.2.3 || <0.0.1", [[">=0.2.3"], ["<0.0.1"]]], [">=0.2.3 || <0.0.1", [[">=0.2.3"], ["<0.0.1"]]], [">=0.2.3 || <0.0.1", [[">=0.2.3"], ["<0.0.1"]]], ["||", [[""], [""]]], ["2.x.x", [[">=2.0.0", "<3.0.0"]]], ["1.2.x", [[">=1.2.0", "<1.3.0"]]], [ "1.2.x || 2.x", [ [">=1.2.0", "<1.3.0"], [">=2.0.0", "<3.0.0"], ], ], [ "1.2.x || 2.x", [ [">=1.2.0", "<1.3.0"], [">=2.0.0", "<3.0.0"], ], ], ["x", [[""]]], ["2.*.*", [[">=2.0.0", "<3.0.0"]]], ["1.2.*", [[">=1.2.0", "<1.3.0"]]], [ "1.2.* || 2.*", [ [">=1.2.0", "<1.3.0"], [">=2.0.0", "<3.0.0"], ], ], [ "1.2.* || 2.*", [ [">=1.2.0", "<1.3.0"], [">=2.0.0", "<3.0.0"], ], ], ["*", [[""]]], ["2", [[">=2.0.0", "<3.0.0"]]], ["2.3", [[">=2.3.0", "<2.4.0"]]], ["~2.4", [[">=2.4.0", "<2.5.0"]]], ["~2.4", [[">=2.4.0", "<2.5.0"]]], ["~>3.2.1", [[">=3.2.1", "<3.3.0"]]], ["~1", [[">=1.0.0", "<2.0.0"]]], ["~>1", [[">=1.0.0", "<2.0.0"]]], ["~1.0", [[">=1.0.0", "<1.1.0"]]], ["<1", [["<1.0.0"]]], [">=1", [[">=1.0.0"]]], ["<1.2", [["<1.2.0"]]], ["1", [[">=1.0.0", "<2.0.0"]]], ["1 2", [[">=1.0.0", "<2.0.0", ">=2.0.0", "<3.0.0"]]], ["1.2 - 3.4.5", [[">=1.2.0", "<=3.4.5"]]], ["1.2.3 - 3.4", [[">=1.2.3", "<3.5.0"]]], ["1.2.3 - 3", [[">=1.2.3", "<4.0.0"]]], [">*", [["<0.0.0"]]], ["<*", [["<0.0.0"]]], ];
versions.forEach(function (v) { const pre = v[0]; const wanted = v[1]; const found = semver.toComparators(v[0]); const jw = JSON.stringify(wanted); assertEquals(found, wanted, "toComparators(" + pre + ") === " + jw); });});
Deno.test("test", function () { const c = new semver.Comparator(">=1.2.3"); assert(c.test("1.2.4")); const c2 = new semver.Comparator(c); assert(c2.test("1.2.4"));});
Deno.test("intersect", function () { const versions: [string, string, boolean][] = [ // 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], ];
versions.forEach(function (v) { const comparator1 = new semver.Comparator(v[0]); const comparator2 = new semver.Comparator(v[1]); const expect = v[2];
const actual1 = comparator1.intersects(comparator2); const actual2 = comparator2.intersects(comparator1); const actual3 = semver.intersects(comparator1, comparator2); const actual4 = semver.intersects(comparator2, comparator1); const actual5 = semver.intersects(v[0], v[1]); const actual6 = semver.intersects(v[1], v[0]);
assertEquals(actual1, expect); assertEquals(actual2, expect); assertEquals(actual3, expect); assertEquals(actual4, expect); assertEquals(actual5, expect); assertEquals(actual6, expect); });});
Deno.test("tostrings", function () { assertEquals(new semver.Comparator(">= v1.2.3").toString(), ">=1.2.3");});
std

Version Info

Tagged at
10 months ago