-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
- Loading branch information
1 parent
2943c6c
commit 3d74dbd
Showing
4 changed files
with
94 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("||"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}, | ||
}); | ||
} | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters