feat: add not

This commit is contained in:
BluJ
2022-07-15 12:52:50 -06:00
parent 5b21ee08b4
commit 3cac71aa96
2 changed files with 28 additions and 1 deletions

View File

@@ -87,6 +87,10 @@ export function rangeOr(...ranges: (string | Checker)[]): Checker {
return firstCheck;
}
export function notRange(range: string | Checker): Checker {
return rangeOf(range).not();
}
export class EmVar {
static from(range: string | EmVar): EmVar {
@@ -148,4 +152,7 @@ export class Checker {
public or(other: Checker): Checker {
return new Checker((value) => this.check(value) || other.check(value));
}
public not(): Checker {
return new Checker((value) => !this.check(value));
}
}

View File

@@ -1,6 +1,6 @@
import { expect } from "https://deno.land/x/expect@v0.2.9/mod.ts";
import { rangeAnd, rangeOf, rangeOr } from "./mod.ts";
import { notRange, rangeAnd, rangeOf, rangeOr } from "./mod.ts";
const { test } = Deno;
@@ -137,4 +137,24 @@ const { test } = Deno;
expect(checker.check("2")).toBe(false);
})
}
{
const checker = notRange(rangeOf('1.2.*'));
test(`!rangeOf(1.2.*) valid`, () => {
expect(checker.check("1.3")).toBe(true);
expect(checker.check("1.3.1")).toBe(true);
expect(checker.check("1.1.1")).toBe(true);
expect(checker.check("1.1")).toBe(true);
expect(checker.check("1")).toBe(true);
expect(checker.check("2")).toBe(true);
})
test(`!rangeOf(1.2.*) invalid `, () => {
expect(checker.check("1.2")).toBe(false);
expect(checker.check("1.2.1")).toBe(false);
})
}