Skip to content

Commit

Permalink
chore(semver): add test for parse_range (4309)
Browse files Browse the repository at this point in the history
  • Loading branch information
javihernant committed Feb 16, 2024
1 parent 453cc36 commit 4083f9f
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions semver/parse_range_test.ts
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))
}
});

0 comments on commit 4083f9f

Please sign in to comment.