mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
deprecation(semver): rename rangeFormat()
to formatRange()
(#4090)
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
parent
2943c6c657
commit
3d74dbd2ca
14
semver/format_range.ts
Normal file
14
semver/format_range.ts
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
import type { SemVerRange } from "./types.ts";
|
||||
import { comparatorFormat } from "./comparator_format.ts";
|
||||
|
||||
/**
|
||||
* Formats the range into a string
|
||||
* @example >=0.0.0 || <1.0.0
|
||||
* @param range The range to format
|
||||
* @returns A string representation of the range
|
||||
*/
|
||||
export function formatRange(range: SemVerRange): string {
|
||||
return range.ranges.map((c) => c.map((c) => comparatorFormat(c)).join(" "))
|
||||
.join("||");
|
||||
}
|
73
semver/format_range_test.ts
Normal file
73
semver/format_range_test.ts
Normal file
@ -0,0 +1,73 @@
|
||||
// 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 { 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({
|
||||
name: `${r} -> ${expected}`,
|
||||
fn: () => {
|
||||
const range = parseRange(r);
|
||||
const actual = formatRange(range);
|
||||
assertEquals(actual, expected);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
@ -1,14 +1,16 @@
|
||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
import type { SemVerRange } from "./types.ts";
|
||||
import { comparatorFormat } from "./comparator_format.ts";
|
||||
|
||||
import { formatRange } from "./format_range.ts";
|
||||
import { SemVerRange } from "./types.ts";
|
||||
|
||||
/**
|
||||
* Formats the range into a string
|
||||
* @example >=0.0.0 || <1.0.0
|
||||
* @param range The range to format
|
||||
* @returns A string representation of the range
|
||||
*
|
||||
* @deprecated (will be removed after 0.213.0) Use {@linkcode formatRange} instead.
|
||||
*/
|
||||
export function rangeFormat(range: SemVerRange): string {
|
||||
return range.ranges.map((c) => c.map((c) => comparatorFormat(c)).join(" "))
|
||||
.join("||");
|
||||
return formatRange(range);
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license.
|
||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
import { assert, assertEquals } from "../assert/mod.ts";
|
||||
import { rangeFormat } from "./range_format.ts";
|
||||
import { assert } from "../assert/mod.ts";
|
||||
import { parse } from "./parse.ts";
|
||||
import { parseRange } from "./parse_range.ts";
|
||||
import { testRange } from "./test_range.ts";
|
||||
@ -217,71 +216,3 @@ Deno.test("negativeUnlockedPrereleaseRange", function () {
|
||||
assert(!found, `${v} satisfied by ${r} unexpectedly`);
|
||||
}
|
||||
});
|
||||
|
||||
Deno.test({
|
||||
name: "validRange",
|
||||
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({
|
||||
name: `${r} -> ${expected}`,
|
||||
fn: () => {
|
||||
const range = parseRange(r);
|
||||
const actual = rangeFormat(range);
|
||||
assertEquals(actual, expected);
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user