-
-
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.
Signed-off-by: Lexus Drumgold <[email protected]>
- Loading branch information
1 parent
44293c1
commit 85bf244
Showing
7 changed files
with
179 additions
and
1 deletion.
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
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,28 @@ | ||
/** | ||
* @file Type Tests - TestFunction | ||
* @module unist-util-types/tests/unit-d/TestFunction | ||
*/ | ||
|
||
import type * as docast from '@flex-development/docast' | ||
import type Index from '../index-number' | ||
import type Parents from '../parents' | ||
import type TestSubject from '../test-function' | ||
|
||
describe('unit-d:TestFunction', () => { | ||
type T = docast.InlineTag | ||
type P = Parents<docast.Root, T> | ||
type U = { trash: WeakSet<docast.DocastNode> } | ||
type Subject = TestSubject<T, P, U> | ||
|
||
it('should be callable with [T, Index?, P?]', () => { | ||
expectTypeOf<Subject>().parameters.toEqualTypeOf<[T, Index?, P?]>() | ||
}) | ||
|
||
it('should match [this: U]', () => { | ||
expectTypeOf<Subject>().thisParameter.toEqualTypeOf<U>() | ||
}) | ||
|
||
it('should return boolean | undefined | void', () => { | ||
expectTypeOf<Subject>().returns.toEqualTypeOf<boolean | undefined | void>() | ||
}) | ||
}) |
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,37 @@ | ||
/** | ||
* @file Type Tests - Test | ||
* @module unist-util-types/tests/unit-d/Test | ||
*/ | ||
|
||
import type { Node } from 'unist' | ||
import type TestSubject from '../test' | ||
import type TestFunction from '../test-function' | ||
import type Type from '../type' | ||
|
||
describe('unit-d:Test', () => { | ||
it('should extract (Node | TestFunction | Type)[]', () => { | ||
expectTypeOf<TestSubject>() | ||
.extract<(Node | TestFunction | Type)[]>() | ||
.not.toBeNever() | ||
}) | ||
|
||
it('should extract Node', () => { | ||
expectTypeOf<TestSubject>().extract<Node>().not.toBeNever() | ||
}) | ||
|
||
it('should extract TestFunction', () => { | ||
expectTypeOf<TestSubject>().extract<TestFunction>().not.toBeNever() | ||
}) | ||
|
||
it('should extract Type', () => { | ||
expectTypeOf<TestSubject>().extract<Type>().not.toBeNever() | ||
}) | ||
|
||
it('should extract null', () => { | ||
expectTypeOf<TestSubject>().extract<null>().not.toBeNever() | ||
}) | ||
|
||
it('should extract undefined', () => { | ||
expectTypeOf<TestSubject>().extract<undefined>().not.toBeNever() | ||
}) | ||
}) |
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,38 @@ | ||
/** | ||
* @file TestFunction | ||
* @module unist-util-types/TestFunction | ||
*/ | ||
|
||
import type { Node, Parent } from 'unist' | ||
import type Index from './index-number' | ||
|
||
/** | ||
* Check if `node` passes a test. | ||
* | ||
* @see {@linkcode Index} | ||
* @see {@linkcode Node} | ||
* @see {@linkcode Parent} | ||
* | ||
* @template {Node} [T=Node] - Node to check | ||
* @template {Parent} [P=Parent] - Parent of node | ||
* @template {any} [U=unknown] - `this` context | ||
* | ||
* @this {U} | ||
* | ||
* @param {T} node - Node to check | ||
* @param {Index?} [index] - Index of `node` in `parent.children` | ||
* @param {P?} [parent] - Parent of `node` | ||
* @return {boolean | undefined | void} Test result | ||
*/ | ||
type TestFunction< | ||
T extends Node = Node, | ||
P extends Parent = Parent, | ||
U = unknown | ||
> = ( | ||
this: U, | ||
node: T, | ||
index?: Index, | ||
parent?: P | ||
) => boolean | undefined | void | ||
|
||
export type { TestFunction as default } |
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,25 @@ | ||
/** | ||
* @file Test | ||
* @module unist-util-types/Test | ||
*/ | ||
|
||
import type { Node } from 'unist' | ||
import type TestFunction from './test-function' | ||
import type Type from './type' | ||
|
||
/** | ||
* Union of test types for a {@linkcode Node}. | ||
* | ||
* @see {@linkcode TestFunction} | ||
* @see {@linkcode Type} | ||
* @see https://github.com/syntax-tree/unist-util-is | ||
*/ | ||
type Test = | ||
| (Node | TestFunction | Type)[] | ||
| Node | ||
| TestFunction | ||
| Type | ||
| null | ||
| undefined | ||
|
||
export type { Test as default } |