-
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.
Tuple Transform Check | Check Both Value and Compiler Encoding in Tests
- Loading branch information
1 parent
5bd9f12
commit 1d5cd5b
Showing
34 changed files
with
344 additions
and
284 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
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,33 @@ | ||
import { IsAsyncIterator, IsIterator, IsFunction, IsSymbol } from '@sinclair/typebox/value/guard' | ||
import { TSchema, StaticDecode, StaticEncode } from '@sinclair/typebox' | ||
import { TypeCompiler } from '@sinclair/typebox/compiler' | ||
import { Value } from '@sinclair/typebox/value' | ||
import { Assert } from '../../assert/index' | ||
|
||
function AssertSame(actual: unknown, expect: unknown) { | ||
if (IsAsyncIterator(actual) && IsAsyncIterator(expect)) return | ||
if (IsIterator(actual) && IsIterator(expect)) return | ||
if (IsSymbol(actual) && IsSymbol(expect)) return | ||
if (IsFunction(actual) && IsFunction(expect)) return | ||
Assert.IsEqual(actual, expect) | ||
} | ||
|
||
export function Decode<T extends TSchema, R = StaticDecode<T>>(schema: T, references: TSchema[], value: unknown): R | ||
export function Decode<T extends TSchema, R = StaticDecode<T>>(schema: T, value: unknown): R | ||
export function Decode(...args: any[]) { | ||
const [schema, references, value] = args.length === 2 ? [args[0], [], args[1]] : [args[0], args[1], args[2]] | ||
const value1 = TypeCompiler.Compile(schema as TSchema, references).Decode(value) | ||
const value2 = Value.Decode(schema as TSchema, references, value) | ||
AssertSame(value1, value2) | ||
return value2 | ||
} | ||
|
||
export function Encode<T extends TSchema, R = StaticEncode<T>>(schema: T, references: TSchema[], value: unknown): R | ||
export function Encode<T extends TSchema, R = StaticEncode<T>>(schema: T, value: unknown): R | ||
export function Encode(...args: any[]) { | ||
const [schema, references, value] = args.length === 2 ? [args[0], [], args[1]] : [args[0], args[1], args[2]] | ||
const value1 = TypeCompiler.Compile(schema as TSchema, references).Encode(value) | ||
const value2 = Value.Encode(schema as TSchema, references, value) | ||
AssertSame(value1, value2) | ||
return value2 | ||
} |
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
Oops, something went wrong.