-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: clarify return types of predefined predicates
- Loading branch information
Showing
24 changed files
with
90 additions
and
86 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
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,20 @@ | ||
import { anything } from './anything' | ||
import { createSatisfier } from './createSatisfier' | ||
import { testArrow, testFn, testSymbol } from './testPredicates' | ||
|
||
|
||
test('matches against anything', () => { | ||
const s = createSatisfier(anything) | ||
expect(s.exec(undefined)).toBeUndefined() | ||
expect(s.exec(null)).toBeUndefined() | ||
expect(s.exec(false)).toBeUndefined() | ||
expect(s.exec(1)).toBeUndefined() | ||
expect(s.exec(1n)).toBeUndefined() | ||
expect(s.exec('a')).toBeUndefined() | ||
expect(s.exec(Symbol())).toBeUndefined() | ||
expect(s.exec({})).toBeUndefined() | ||
expect(s.exec([])).toBeUndefined() | ||
expect(s.exec(testSymbol)).toBeUndefined() | ||
expect(s.exec(testFn)).toBeUndefined() | ||
expect(s.exec(testArrow)).toBeUndefined() | ||
}) |
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
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
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
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
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
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
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
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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
export * from './anything'; | ||
export * from './createSatisfier'; | ||
export * from './every'; | ||
export * from './formatDiffs'; | ||
export * from './has'; | ||
export * from './interfaces'; | ||
export * from './isInInterval'; | ||
export * from './isInRange'; | ||
export * from './isTypeOf'; | ||
export * from './none'; | ||
export * from './satisfies'; | ||
export * from './some'; | ||
export * from './startsWith'; | ||
export * from './anything' | ||
export * from './createSatisfier' | ||
export * from './every' | ||
export * from './formatDiffs' | ||
export * from './has' | ||
export * from './interfaces' | ||
export * from './isInInterval' | ||
export * from './isInRange' | ||
export * from './isTypeOf' | ||
export * from './none' | ||
export * from './satisfies' | ||
export * from './some' | ||
export * from './startsWith' |
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
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 |
---|---|---|
@@ -1,16 +1,17 @@ | ||
import { tersible } from 'tersify' | ||
import { Tersible, tersible } from 'tersify' | ||
import { Predicate } from './interfaces' | ||
|
||
export function isInOpenInterval(start: number, end: number) { | ||
export function isInOpenInterval(start: number, end: number): Tersible<Predicate> { | ||
return tersible((a: any) => a > start && (a < end), () => `(${start}...${end})`) | ||
} | ||
export function isInClosedInterval(start: number, end: number) { | ||
export function isInClosedInterval(start: number, end: number): Tersible<Predicate> { | ||
return tersible((a: any) => a >= start && a <= end, () => `[${start}...${end}]`) | ||
} | ||
|
||
export function isInLeftClosedInterval(start: number, end: number) { | ||
export function isInLeftClosedInterval(start: number, end: number): Tersible<Predicate> { | ||
return tersible((a: any) => a >= start && (a < end), () => `[${start}...${end})`) | ||
} | ||
|
||
export function isInRightClosedInterval(start: number, end: number) { | ||
export function isInRightClosedInterval(start: number, end: number): Tersible<Predicate> { | ||
return tersible((a: any) => a > start && a <= end, () => `(${start}...${end}]`) | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import { tersible } from 'tersify' | ||
import { Tersible, tersible } from 'tersify' | ||
import { Predicate } from './interfaces' | ||
|
||
export function isInRange(start: number, end: number) { | ||
export function isInRange(start: number, end: number): Tersible<Predicate> { | ||
return tersible((a: any) => a >= start && a <= end, () => `[${start}...${end}]`) | ||
} |
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
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
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { tersible, tersify } from 'tersify' | ||
import { Tersible, tersible, tersify } from 'tersify' | ||
import { createSatisfier } from './createSatisfier' | ||
import { Predicate } from './interfaces' | ||
|
||
/** | ||
* Check if an array have no entry satisfying the expectation. | ||
* @param expectation expectation | ||
*/ | ||
export function none(expectation: any) { | ||
export function none(expectation: any): Tersible<Predicate> { | ||
const s = createSatisfier(expectation) | ||
return tersible((e: any) => e && Array.isArray(e) && !e.some(v => s.test(v)), () => `none(${tersify(expectation)})`) | ||
} |
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
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
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
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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { tersible, tersify } from 'tersify' | ||
import { Tersible, tersible, tersify } from 'tersify' | ||
import { createSatisfier, Expectation } from './createSatisfier' | ||
import { Predicate } from './interfaces' | ||
|
||
/** | ||
* Check if an array have at least one entry satisfying the expectation. | ||
* @param expectation expectation | ||
*/ | ||
export function some<E extends Expectation>(expectation: E) { | ||
export function some<E extends Expectation>(expectation: E): Tersible<Predicate> { | ||
const s = createSatisfier(expectation) | ||
return tersible((e: any) => e && Array.isArray(e) && e.some(v => s.test(v)), () => `some(${tersify(expectation)})`) | ||
} |
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
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
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,7 @@ | ||
/** | ||
* internal for testing | ||
*/ | ||
|
||
export const testSymbol = Symbol() | ||
export const testArrow = () => true | ||
export const testFn = function () { return true } |
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