-
Notifications
You must be signed in to change notification settings - Fork 576
/
max_satisfying_test.ts
33 lines (30 loc) · 1.12 KB
/
max_satisfying_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
// 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 { parse } from "./parse.ts";
import { parseRange } from "./parse_range.ts";
import { maxSatisfying } from "./max_satisfying.ts";
import { MAX, MIN } from "./constants.ts";
Deno.test({
name: "maxSatisfying()",
fn: async (t) => {
const versions: [string[], string, string][] = [
[["1.2.3", "1.2.4"], "1.2", "1.2.4"],
[["1.2.4", "1.2.3"], "1.2", "1.2.4"],
[["1.2.3", "1.2.4", "1.2.5", "1.2.6"], "~1.2.3", "1.2.6"],
];
for (const [v, r, e] of versions) {
await t.step(r, () => {
const versions = v.map((v) => parse(v));
const range = parseRange(r);
const expect = parse(e);
const actual = maxSatisfying(versions, range);
assertEquals(actual, expect);
});
}
},
});
Deno.test("minSatisfying() handles bad ranges", function () {
const r = parseRange("some frogs and sneks-v2.5.6");
assertEquals(maxSatisfying([MIN, MAX], r), undefined);
});