-
-
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 <unicornware@flexdevelopment.llc>
- Loading branch information
1 parent
e863ed5
commit 92112e6
Showing
23 changed files
with
593 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,4 +89,5 @@ ignore: | |
- '!src/index.ts' | ||
|
||
profiling: | ||
critical_files_paths: [] | ||
critical_files_paths: | ||
- src/u.ts |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`unit:u > children builder > should build parent 1`] = ` | ||
{ | ||
"children": [], | ||
"type": "root", | ||
} | ||
`; | ||
|
||
exports[`unit:u > properties builder > should build node 1`] = ` | ||
{ | ||
"type": "undefined", | ||
"value": undefined, | ||
} | ||
`; | ||
|
||
exports[`unit:u > should build leaf if builder is undefined 1`] = ` | ||
{ | ||
"type": "root", | ||
} | ||
`; | ||
|
||
exports[`unit:u > value builder > RegExp > should build literal 1`] = ` | ||
{ | ||
"type": "regexp", | ||
"value": /\\^node:/, | ||
} | ||
`; | ||
|
||
exports[`unit:u > value builder > bigint > should build literal 1`] = ` | ||
{ | ||
"type": "bigint", | ||
"value": 3n, | ||
} | ||
`; | ||
|
||
exports[`unit:u > value builder > boolean > should build literal 1`] = ` | ||
{ | ||
"type": "boolean", | ||
"value": true, | ||
} | ||
`; | ||
|
||
exports[`unit:u > value builder > null > should build literal 1`] = ` | ||
{ | ||
"type": "null", | ||
"value": null, | ||
} | ||
`; | ||
|
||
exports[`unit:u > value builder > number > should build literal 1`] = ` | ||
{ | ||
"type": "number", | ||
"value": 3, | ||
} | ||
`; | ||
|
||
exports[`unit:u > value builder > string > should build literal 1`] = ` | ||
{ | ||
"type": "string", | ||
"value": "node", | ||
} | ||
`; |
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,12 @@ | ||
/** | ||
* @file E2E Tests - api | ||
* @module unist-util-builder/tests/e2e/api | ||
*/ | ||
|
||
import * as testSubject from '../index' | ||
|
||
describe('e2e:unist-util-builder', () => { | ||
it('should expose public api', () => { | ||
expect(testSubject).to.have.keys(['u']) | ||
}) | ||
}) |
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,62 @@ | ||
/** | ||
* @file Unit Tests - u | ||
* @module unist-util-builder/tests/unit/u | ||
*/ | ||
|
||
import testSubject from '../u' | ||
|
||
describe('unit:u', () => { | ||
it('should build leaf if builder is undefined', () => { | ||
expect(testSubject('root')).toMatchSnapshot() | ||
}) | ||
|
||
describe('children builder', () => { | ||
it('should build parent', () => { | ||
expect(testSubject('root', [])).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('properties builder', () => { | ||
it('should build node', () => { | ||
expect(testSubject('undefined', { value: undefined })).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('value builder', () => { | ||
describe('RegExp', () => { | ||
it('should build literal', () => { | ||
expect(testSubject('regexp', /^node:/)).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('bigint', () => { | ||
it('should build literal', () => { | ||
expect(testSubject('bigint', 3n)).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('boolean', () => { | ||
it('should build literal', () => { | ||
expect(testSubject('boolean', true)).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('null', () => { | ||
it('should build literal', () => { | ||
expect(testSubject('null', null)).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('number', () => { | ||
it('should build literal', () => { | ||
expect(testSubject('number', 3)).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
describe('string', () => { | ||
it('should build literal', () => { | ||
expect(testSubject('string', 'node')).toMatchSnapshot() | ||
}) | ||
}) | ||
}) | ||
}) |
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 |
---|---|---|
|
@@ -3,4 +3,5 @@ | |
* @module unist-util-builder | ||
*/ | ||
|
||
export {} | ||
export type * from './types' | ||
export { default as u } from './u' |
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,23 @@ | ||
/** | ||
* @file Type Tests - AnyBuilder | ||
* @module unist-util-builder/tests/types/unit-d/AnyBuilder | ||
*/ | ||
|
||
import type TestSubject from '../any-builder' | ||
import type BuilderChildren from '../builder-children' | ||
import type BuilderProps from '../builder-props' | ||
import type BuilderValue from '../builder-value' | ||
|
||
describe('unit-d:types/AnyBuilder', () => { | ||
it('should extract BuilderChildren', () => { | ||
expectTypeOf<TestSubject>().extract<BuilderChildren>().not.toBeNever() | ||
}) | ||
|
||
it('should extract BuilderProps', () => { | ||
expectTypeOf<TestSubject>().extract<BuilderProps>().not.toBeNever() | ||
}) | ||
|
||
it('should extract BuilderValue', () => { | ||
expectTypeOf<TestSubject>().extract<BuilderValue>().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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @file Type Tests - BuilderChildren | ||
* @module unist-util-builder/tests/types/unit-d/BuilderChildren | ||
*/ | ||
|
||
import type * as docast from '@flex-development/docast' | ||
import type TestSubject from '../builder-children' | ||
|
||
describe('unit-d:types/BuilderChildren', () => { | ||
it('should equal T[]', () => { | ||
// Arrange | ||
type T = docast.PhrasingContent | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<T>>().toEqualTypeOf<T[]>() | ||
}) | ||
}) |
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,12 @@ | ||
/** | ||
* @file Type Tests - BuilderProps | ||
* @module unist-util-builder/tests/types/unit-d/BuilderProps | ||
*/ | ||
|
||
import type TestSubject from '../builder-props' | ||
|
||
describe('unit-d:types/BuilderProps', () => { | ||
it('should equal { [x: string]: unknown }', () => { | ||
expectTypeOf<TestSubject>().toEqualTypeOf<{ [x: string]: unknown }>() | ||
}) | ||
}) |
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 - BuilderValue | ||
* @module unist-util-builder/tests/types/unit-d/BuilderValue | ||
*/ | ||
|
||
import type TestSubject from '../builder-value' | ||
|
||
describe('unit-d:types/BuilderValue', () => { | ||
it('should extract RegExp', () => { | ||
expectTypeOf<TestSubject>().extract<RegExp>().not.toBeNever() | ||
}) | ||
|
||
it('should extract bigint', () => { | ||
expectTypeOf<TestSubject>().extract<bigint>().not.toBeNever() | ||
}) | ||
|
||
it('should extract boolean', () => { | ||
expectTypeOf<TestSubject>().extract<boolean>().not.toBeNever() | ||
}) | ||
|
||
it('should extract number', () => { | ||
expectTypeOf<TestSubject>().extract<number>().not.toBeNever() | ||
}) | ||
|
||
it('should extract null', () => { | ||
expectTypeOf<TestSubject>().extract<null>().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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* @file Type Tests - Builder | ||
* @module unist-util-builder/tests/types/unit-d/Builder | ||
*/ | ||
|
||
import type * as docast from '@flex-development/docast' | ||
import type { Children } from '@flex-development/unist-util-types' | ||
import type * as mdast from 'mdast' | ||
import type TestSubject from '../builder' | ||
import type BuilderValue from '../builder-value' | ||
|
||
describe('unit-d:types/Builder', () => { | ||
it('should extract Extract<MatchValue<N, Type<N>>, BuilderValue>', () => { | ||
// Arrange | ||
type N = { type: string; value: BuilderValue | Date } | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<N>>().extract<Date>().toBeNever() | ||
}) | ||
|
||
it('should extract MatchChildren<N, Type<N>>', () => { | ||
// Arrange | ||
type N = docast.Root | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<N>>().extract<Children<N>>().not.toBeNever() | ||
}) | ||
|
||
it('should extract MatchProperties<N, Type<N>>', () => { | ||
// Arrange | ||
type N = mdast.Code | ||
|
||
// Expect | ||
expectTypeOf<TestSubject<N>>().extract<Omit<N, 'type'>>().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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* @file Type Aliases - AnyBuilder | ||
* @module unist-util-builder/types/AnyBuilder | ||
*/ | ||
|
||
import type BuilderChildren from './builder-children' | ||
import type BuilderProps from './builder-props' | ||
import type BuilderValue from './builder-value' | ||
|
||
/** | ||
* Union of types used to build any node. | ||
* | ||
* @see {@linkcode BuilderChildren} | ||
* @see {@linkcode BuilderProps} | ||
* @see {@linkcode BuilderValue} | ||
*/ | ||
type AnyBuilder = BuilderChildren | BuilderProps | BuilderValue | ||
|
||
export type { AnyBuilder 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,18 @@ | ||
/** | ||
* @file Type Aliases - BuilderChildren | ||
* @module unist-util-BuilderChildren/types/BuilderChildren | ||
*/ | ||
|
||
import type { Node } from 'unist' | ||
|
||
/** | ||
* List of [*child*][child] nodes used to build a [parent]. | ||
* | ||
* [child]: https://github.com/syntax-tree/unist#child | ||
* [parent]: https://github.com/syntax-tree/unist#parent | ||
* | ||
* @template {Node} [T=Node] - Child node | ||
*/ | ||
type BuilderChildren<T extends Node = Node> = T[] | ||
|
||
export type { BuilderChildren 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,14 @@ | ||
/** | ||
* @file Type Aliases - BuilderProps | ||
* @module unist-util-BuilderProps/types/BuilderProps | ||
*/ | ||
|
||
/** | ||
* Node properties object. | ||
* | ||
* > 👉 Properties of a node are all fields except `type`. If a `type` field is | ||
* > present on a builder object, it will be ignored. | ||
*/ | ||
type BuilderProps = { [x: string]: unknown } | ||
|
||
export type { BuilderProps as default } |
Oops, something went wrong.