-
Notifications
You must be signed in to change notification settings - Fork 629
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(semver): add test for parse_range (4309)
- Loading branch information
1 parent
453cc36
commit 4083f9f
Showing
1 changed file
with
77 additions
and
0 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,77 @@ | ||
// Copyright Isaac Z. Schlueter and Contributors. All rights reserved. ISC license. | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
import { assert } from "../assert/mod.ts"; | ||
import { parseRange } from "./parse_range.ts"; | ||
import type { Comparator, Range } from "./types.ts"; | ||
|
||
function equalComp( | ||
c0: Comparator, | ||
c1: Comparator, | ||
): boolean { | ||
return ( | ||
c0.operator === c1.operator && | ||
c0.major === c1.major && | ||
c0.minor === c1.minor && | ||
c0.patch === c1.patch | ||
); | ||
} | ||
|
||
function equalComps( | ||
cs0: Comparator[], | ||
cs1: Comparator[], | ||
): boolean { | ||
if (cs0.length !== cs1.length) { | ||
return false; | ||
} | ||
for (let i = 0; i < cs0.length; i++) { | ||
if (!equalComp(cs0[i], cs1[i])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
function equalRanges( | ||
r0: Range, | ||
r1: Range, | ||
): boolean { | ||
if (r0.length !== r1.length) { | ||
return false; | ||
} | ||
for (let i = 0; i < r0.length; i++) { | ||
if (!equalComps(r0[i], r1[i])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
Deno.test("parseRange", () => { | ||
const ranges: [string, Range][] = [ | ||
["1.0.0 - 2.0.0", [ | ||
[ | ||
{ | ||
operator: ">=", | ||
major: 1, | ||
minor: 0, | ||
patch: 0, | ||
prerelease: [], | ||
build: [], | ||
}, | ||
{ | ||
operator: "<=", | ||
major: 2, | ||
minor: 0, | ||
patch: 0, | ||
prerelease: [], | ||
build: [], | ||
}, | ||
], | ||
]], | ||
]; | ||
|
||
for (const [r, expected] of ranges) { | ||
const range = parseRange(r); | ||
assert(equalRanges(range,expected)) | ||
} | ||
}); |