-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Support Intersect Value Conversion * Update Test To Include Non Converted Property
- Loading branch information
1 parent
4211f4a
commit 4edc46c
Showing
5 changed files
with
57 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,45 @@ | ||
import { Value } from '@sinclair/typebox/value' | ||
import { Type } from '@sinclair/typebox' | ||
import { Assert } from '../../assert/index' | ||
|
||
describe('value/convert/Intersect', () => { | ||
it('Should convert intersected objects', () => { | ||
// prettier-ignore | ||
const T = Type.Intersect([ | ||
Type.Object({ x: Type.Number() }), | ||
Type.Object({ y: Type.Number() }) | ||
]) | ||
const R = Value.Convert(T, { x: '1', y: '2' }) | ||
Assert.IsEqual(R, { x: 1, y: 2 }) | ||
}) | ||
it('Should not convert for non object exclusive intersect', () => { | ||
// prettier-ignore | ||
const T = Type.Intersect([ | ||
Type.Number(), | ||
Type.Object({ x: Type.Number() }), | ||
Type.Object({ y: Type.Number() }) | ||
]) | ||
const R = Value.Convert(T, { x: '1', y: '2' }) | ||
Assert.IsEqual(R, { x: '1', y: '2' }) | ||
}) | ||
it('Should convert first type for object exclusive intersect 1', () => { | ||
// prettier-ignore | ||
const T = Type.Intersect([ | ||
Type.Number(), | ||
Type.Object({ x: Type.Number() }), | ||
Type.Object({ y: Type.Number() }) | ||
]) | ||
const R = Value.Convert(T, '123') | ||
Assert.IsEqual(R, 123) | ||
}) | ||
it('Should convert first type for object exclusive intersect 2', () => { | ||
// prettier-ignore | ||
const T = Type.Intersect([ | ||
Type.Object({ x: Type.Number() }), | ||
Type.Object({ y: Type.Number() }), | ||
Type.Number(), | ||
]) | ||
const R = Value.Convert(T, { x: '3', y: '4' }) | ||
Assert.IsEqual(R, { x: 3, y: '4' }) | ||
}) | ||
}) |