mirror of
https://github.com/Start9Labs/start-sdk.git
synced 2026-03-26 02:11:56 +00:00
chore: Testing that we have some ranges for the and and or combinators
This commit is contained in:
@@ -72,6 +72,9 @@ export function rangeOf(range: string | Checker): Checker {
|
||||
}
|
||||
|
||||
export function rangeAnd(...ranges: (string | Checker)[]): Checker {
|
||||
if (ranges.length === 0) {
|
||||
throw new Error('No ranges given');
|
||||
}
|
||||
let [firstCheck, ...rest] = ranges.map(rangeOf);
|
||||
for (const checker of rest) {
|
||||
firstCheck = firstCheck.and(checker);
|
||||
@@ -80,6 +83,9 @@ export function rangeAnd(...ranges: (string | Checker)[]): Checker {
|
||||
}
|
||||
|
||||
export function rangeOr(...ranges: (string | Checker)[]): Checker {
|
||||
if (ranges.length === 0) {
|
||||
throw new Error('No ranges given');
|
||||
}
|
||||
let [firstCheck, ...rest] = ranges.map(rangeOf);
|
||||
for (const checker of rest) {
|
||||
firstCheck = firstCheck.or(checker);
|
||||
|
||||
@@ -157,4 +157,13 @@ const { test } = Deno;
|
||||
expect(checker.check("1.2")).toBe(false);
|
||||
expect(checker.check("1.2.1")).toBe(false);
|
||||
})
|
||||
}
|
||||
|
||||
{
|
||||
test(`no and ranges`, () => {
|
||||
expect(() => rangeAnd()).toThrow()
|
||||
})
|
||||
test(`no or ranges`, () => {
|
||||
expect(() => rangeOr()).toThrow()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user