Add unit tests for VersionRange (#40114)

* Add unit tests for VersionRange

Make it easier to understand the intended semantics next time I have to
read this code.

* I miss prettier
This commit is contained in:
Nathan Shively-Sanders
2020-08-18 13:06:17 -07:00
committed by GitHub
parent dbab46c363
commit 6fea7ff536
2 changed files with 26 additions and 3 deletions

View File

@@ -1,6 +1,29 @@
namespace ts {
import theory = Utils.theory;
describe("unittests:: semver", () => {
describe("VersionRange", () => {
function assertVersionRange(version: string, good: string[], bad: string[]): () => void {
return () => {
const range = VersionRange.tryParse(version)!;
assert(range);
for (const g of good) {
assert.isTrue(range.test(g), g);
}
for (const b of bad) {
assert.isFalse(range.test(b), b);
}
};
}
it("< works", assertVersionRange("<3.8.0", ["3.6", "3.7"], ["3.8", "3.9", "4.0"]));
it("<= works", assertVersionRange("<=3.8.0", ["3.6", "3.7", "3.8"], ["3.9", "4.0"]));
it("> works", assertVersionRange(">3.8.0", ["3.9", "4.0"], ["3.6", "3.7", "3.8"]));
it(">= works", assertVersionRange(">=3.8.0", ["3.8", "3.9", "4.0"], ["3.6", "3.7"]));
it("< works with prerelease", assertVersionRange("<3.8.0-0", ["3.6", "3.7"], ["3.8", "3.9", "4.0"]));
it("<= works with prerelease", assertVersionRange("<=3.8.0-0", ["3.6", "3.7"], ["3.8", "3.9", "4.0"]));
it("> works with prerelease", assertVersionRange(">3.8.0-0", ["3.8", "3.9", "4.0"], ["3.6", "3.7"]));
it(">= works with prerelease", assertVersionRange(">=3.8.0-0", ["3.8", "3.9", "4.0"], ["3.6", "3.7"]));
});
describe("Version", () => {
function assertVersion(version: Version, [major, minor, patch, prerelease, build]: [number, number, number, string[]?, string[]?]) {
assert.strictEqual(version.major, major);