2024-01-08 02:55:23 +00:00
|
|
|
// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license.
|
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-29 02:57:30 +00:00
|
|
|
import { assertEquals } from "@std/assert";
|
2024-01-08 02:55:23 +00:00
|
|
|
import { formatRange } from "./format_range.ts";
|
|
|
|
import { parseRange } from "./parse_range.ts";
|
|
|
|
|
|
|
|
Deno.test({
|
|
|
|
name: "formatRange()",
|
|
|
|
fn: async (t) => {
|
|
|
|
const versions: [string, 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"],
|
|
|
|
["<=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"],
|
|
|
|
["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"],
|
|
|
|
["^0", ">=0.0.0 <1.0.0"],
|
|
|
|
["^0.1", ">=0.1.0 <0.2.0"],
|
|
|
|
["^1.0", ">=1.0.0 <2.0.0"],
|
|
|
|
["^1.2", ">=1.2.0 <2.0.0"],
|
|
|
|
["^0.0.1", ">=0.0.1 <0.0.2"],
|
|
|
|
["^0.0.1-beta", ">=0.0.1-beta <0.0.2"],
|
|
|
|
["^0.1.2", ">=0.1.2 <0.2.0"],
|
|
|
|
["^1.2.3", ">=1.2.3 <2.0.0"],
|
|
|
|
["^1.2.3-beta.4", ">=1.2.3-beta.4 <2.0.0"],
|
|
|
|
["<1", "<1.0.0"],
|
|
|
|
[">=1", ">=1.0.0"],
|
|
|
|
["<1.2", "<1.2.0"],
|
|
|
|
["1", ">=1.0.0 <2.0.0"],
|
|
|
|
];
|
|
|
|
|
|
|
|
for (const [r, expected] of versions) {
|
|
|
|
await t.step({
|
2024-02-29 04:00:20 +00:00
|
|
|
name: r,
|
2024-01-08 02:55:23 +00:00
|
|
|
fn: () => {
|
|
|
|
const range = parseRange(r);
|
|
|
|
const actual = formatRange(range);
|
|
|
|
assertEquals(actual, expected);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|