From c4656432d372aaf2136d6851f99065639a3084ba Mon Sep 17 00:00:00 2001 From: Geoff Date: Mon, 19 Aug 2024 10:14:16 -0400 Subject: [PATCH 1/6] Add custom matcher for StructError --- test/matchers.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ vitest.config.ts | 5 ++++ 2 files changed, 65 insertions(+) create mode 100644 test/matchers.ts create mode 100644 vitest.config.ts diff --git a/test/matchers.ts b/test/matchers.ts new file mode 100644 index 00000000..3088c919 --- /dev/null +++ b/test/matchers.ts @@ -0,0 +1,60 @@ +import { isEqual, pick } from 'lodash' +import { expect } from 'vitest' +import { StructError } from '../src' + +const FILTERED_PROPS = ['type', 'path', 'refinement', 'value', 'branch'] + +expect.extend({ + toMatchStructError: (received: StructError | undefined, expected: any) => { + // Make sure the error exists + if (!(received instanceof StructError)) { + return { + message: () => `Expected error to be a StructError`, + pass: false, + actual: received, + expected, + } + } + + const actualFailures = received + .failures() + .map((failure) => pick(failure, ...FILTERED_PROPS)) + + // Check that the failures match + if (!isEqual(actualFailures, expected)) { + return { + message: () => `Expected error.failures to match expected`, + pass: false, + actual: actualFailures, + expected, + } + } + + const strippedError = pick(received, ...FILTERED_PROPS) + + // Check that the first failure properties are also the properties of the StructError + if (!isEqual(strippedError, expected[0])) { + return { + message: () => + `Expected error properties to match first expected failure`, + pass: false, + actual: strippedError, + expected, + } + } + + return { + message: () => `${received} matches ${expected}`, + pass: true, + } + }, +}) + +interface CustomMatchers { + toMatchStructError: (expected: any) => void +} + +declare module 'vitest' { + interface Assertion extends CustomMatchers {} + interface AsymmetricMatchersContaining extends CustomMatchers {} +} diff --git a/vitest.config.ts b/vitest.config.ts new file mode 100644 index 00000000..fa914d2b --- /dev/null +++ b/vitest.config.ts @@ -0,0 +1,5 @@ +import { defineConfig } from 'vitest/config' + +export default defineConfig({ + test: { setupFiles: ['test/matchers.ts'] }, +}) From 0b2ce912f9ad08a7c591617ca8d9775c90aa1b6d Mon Sep 17 00:00:00 2001 From: Geoff Date: Mon, 19 Aug 2024 23:18:32 -0400 Subject: [PATCH 2/6] Run the codeshift --- rename.sh | 15 + test/validation/any/valid-number.ts | 12 +- test/validation/any/valid-string.ts | 12 +- test/validation/any/valid-undefined.ts | 12 +- .../array/invalid-element-property.ts | 28 +- test/validation/array/invalid-element.ts | 28 +- test/validation/array/invalid-opaque.ts | 28 +- test/validation/array/invalid.ts | 28 +- test/validation/array/valid-frozen.ts | 14 +- test/validation/array/valid-opaque.ts | 12 +- test/validation/array/valid.ts | 12 +- test/validation/assign/invalid-object.ts | 49 +-- test/validation/assign/invalid-type.ts | 35 ++- test/validation/assign/valid-object.ts | 22 +- test/validation/assign/valid-type.ts | 26 +- test/validation/bigint/invalid-number.ts | 28 +- test/validation/bigint/invalid.ts | 28 +- test/validation/bigint/valid.ts | 12 +- test/validation/boolean/invalid.ts | 28 +- test/validation/boolean/valid.ts | 12 +- test/validation/coerce/changed.ts | 16 +- test/validation/coerce/condition-not-met.ts | 30 +- test/validation/coerce/unchanged.ts | 16 +- test/validation/date/invalid-date.ts | 28 +- test/validation/date/invalid.ts | 28 +- test/validation/date/valid.ts | 12 +- test/validation/defaulted/function.ts | 14 +- test/validation/defaulted/mixin.ts | 38 +-- test/validation/defaulted/nested-double.ts | 34 +- test/validation/defaulted/nested.ts | 20 +- test/validation/defaulted/strict.ts | 56 ++-- test/validation/defaulted/value.ts | 14 +- test/validation/deprecated/invalid-null.ts | 28 +- .../validation/deprecated/invalid-property.ts | 36 ++- test/validation/deprecated/invalid.ts | 28 +- test/validation/deprecated/valid-property.ts | 24 +- test/validation/deprecated/valid-undefined.ts | 12 +- test/validation/deprecated/valid.ts | 12 +- test/validation/dynamic/invalid-reference.ts | 40 ++- test/validation/dynamic/invalid.ts | 28 +- test/validation/dynamic/valid-reference.ts | 28 +- test/validation/dynamic/valid.ts | 12 +- test/validation/dynamic/with-refiners.ts | 28 +- test/validation/empty/invalid-array.ts | 28 +- test/validation/empty/invalid-map.ts | 28 +- test/validation/empty/invalid-set.ts | 28 +- test/validation/empty/invalid-string.ts | 28 +- test/validation/empty/valid-array.ts | 12 +- test/validation/empty/valid-map.ts | 12 +- test/validation/empty/valid-set.ts | 12 +- test/validation/empty/valid-string.ts | 12 +- test/validation/enums/invalid-numbers.ts | 28 +- test/validation/enums/invalid-strings.ts | 28 +- test/validation/enums/valid.ts | 12 +- test/validation/function/invalid.ts | 28 +- test/validation/function/valid.ts | 12 +- test/validation/instance/invalid.ts | 28 +- test/validation/instance/valid.ts | 12 +- test/validation/integer/invalid-decimal.ts | 28 +- test/validation/integer/invalid.ts | 28 +- test/validation/integer/valid.ts | 12 +- .../intersection/invalid-refinement.ts | 28 +- test/validation/intersection/invalid.ts | 33 +- .../intersection/valid-refinement.ts | 12 +- test/validation/intersection/valid.ts | 22 +- test/validation/lazy/invalid.ts | 28 +- test/validation/lazy/valid.ts | 12 +- test/validation/lazy/with-refiners.ts | 28 +- test/validation/literal/invalid.ts | 28 +- test/validation/literal/valid.ts | 12 +- test/validation/map/invalid-opaque.ts | 28 +- test/validation/map/invalid-property.ts | 47 +-- test/validation/map/invalid.ts | 28 +- test/validation/map/valid-opaque.ts | 21 +- test/validation/map/valid.ts | 22 +- test/validation/max/invalid-exclusive.ts | 28 +- test/validation/max/invalid.ts | 28 +- test/validation/max/valid-inclusive.ts | 12 +- test/validation/max/valid.ts | 12 +- test/validation/min/invalid-exclusive.ts | 28 +- test/validation/min/invalid.ts | 28 +- test/validation/min/valid-inclusive.ts | 12 +- test/validation/min/valid.ts | 12 +- test/validation/never/invalid.ts | 28 +- test/validation/nullable/invalid.ts | 28 +- .../nullable/valid-defined-nested.ts | 28 +- test/validation/nullable/valid-defined.ts | 12 +- test/validation/nullable/valid-null-nested.ts | 28 +- test/validation/nullable/valid-null.ts | 12 +- test/validation/number/invalid.ts | 28 +- test/validation/number/valid.ts | 12 +- test/validation/object/invalid-array.ts | 28 +- .../object/invalid-element-nested.ts | 40 ++- test/validation/object/invalid-opaque.ts | 28 +- .../object/invalid-property-nested.ts | 52 ++-- .../object/invalid-property-unknown.ts | 42 +-- test/validation/object/invalid-property.ts | 58 ++-- test/validation/object/invalid-referential.ts | 48 +-- test/validation/object/invalid.ts | 34 +- test/validation/object/valid-frozen.ts | 30 +- test/validation/object/valid-nested.ts | 46 +-- test/validation/object/valid-opaque.ts | 22 +- test/validation/object/valid-referential.ts | 36 ++- test/validation/object/valid.ts | 28 +- .../validation/omit/invalid-element-nested.ts | 44 +-- .../omit/invalid-property-nested.ts | 54 ++-- .../omit/invalid-property-unknown.ts | 46 +-- test/validation/omit/invalid-property.ts | 44 +-- test/validation/omit/invalid.ts | 40 ++- test/validation/omit/valid-nested.ts | 48 +-- test/validation/omit/valid-type.ts | 34 +- test/validation/omit/valid.ts | 30 +- test/validation/optional/invalid.ts | 28 +- .../optional/valid-defined-nested.ts | 28 +- test/validation/optional/valid-defined.ts | 12 +- .../optional/valid-undefined-nested.ts | 24 +- test/validation/optional/valid-undefined.ts | 12 +- test/validation/partial/composed.ts | 28 +- .../partial/invalid-property-unknown.ts | 40 ++- test/validation/partial/invalid-property.ts | 38 ++- test/validation/partial/invalid.ts | 34 +- test/validation/partial/valid-empty.ts | 16 +- test/validation/partial/valid-full.ts | 28 +- test/validation/partial/valid-partial.ts | 24 +- test/validation/partial/valid-type.ts | 32 +- test/validation/pattern/invalid.ts | 28 +- test/validation/pattern/valid.ts | 12 +- .../validation/pick/invalid-element-nested.ts | 44 +-- .../pick/invalid-property-nested.ts | 54 ++-- .../pick/invalid-property-unknown.ts | 46 +-- test/validation/pick/invalid-property.ts | 44 +-- test/validation/pick/invalid.ts | 40 ++- test/validation/pick/valid-nested.ts | 48 +-- test/validation/pick/valid-type.ts | 34 +- test/validation/pick/valid.ts | 30 +- test/validation/record/invalid-array.ts | 28 +- test/validation/record/invalid-property.ts | 47 +-- test/validation/record/invalid.ts | 28 +- test/validation/record/valid-frozen.ts | 24 +- test/validation/record/valid.ts | 22 +- .../refine/invalid-multiple-refinements.ts | 64 ++-- test/validation/refine/invalid-shorthand.ts | 36 ++- test/validation/refine/invalid.ts | 28 +- test/validation/refine/valid.ts | 12 +- test/validation/regexp/invalid.ts | 28 +- test/validation/regexp/valid.ts | 12 +- test/validation/set/invalid-element.ts | 28 +- test/validation/set/invalid-opaque.ts | 28 +- test/validation/set/invalid.ts | 28 +- test/validation/set/valid-opaque.ts | 12 +- test/validation/set/valid.ts | 12 +- test/validation/size/invalid-array.ts | 28 +- test/validation/size/invalid-map.ts | 28 +- test/validation/size/invalid-number.ts | 28 +- test/validation/size/invalid-set.ts | 28 +- test/validation/size/invalid-string.ts | 28 +- test/validation/size/valid-array.ts | 12 +- test/validation/size/valid-exact.ts | 12 +- test/validation/size/valid-map.ts | 19 +- test/validation/size/valid-max-inclusive.ts | 12 +- test/validation/size/valid-min-inclusive.ts | 12 +- test/validation/size/valid-number.ts | 12 +- test/validation/size/valid-set.ts | 12 +- test/validation/size/valid-string.ts | 12 +- test/validation/string/invalid.ts | 28 +- test/validation/string/valid.ts | 12 +- test/validation/trimmed/invalid.ts | 30 +- test/validation/trimmed/valid.ts | 14 +- .../tuple/invalid-element-missing.ts | 28 +- .../tuple/invalid-element-unknown.ts | 28 +- test/validation/tuple/invalid-element.ts | 28 +- test/validation/tuple/invalid.ts | 28 +- test/validation/tuple/valid-frozen.ts | 14 +- test/validation/tuple/valid.ts | 12 +- test/validation/type/invalid-array.ts | 28 +- .../type/invalid-property-nested.ts | 44 +-- test/validation/type/invalid-property.ts | 40 ++- test/validation/type/invalid.ts | 34 +- test/validation/type/valid-frozen.ts | 30 +- test/validation/type/valid-instance.ts | 17 +- test/validation/type/valid.ts | 22 +- test/validation/union/coercion-object.ts | 14 +- test/validation/union/coercion-type.ts | 14 +- test/validation/union/coercion.ts | 14 +- test/validation/union/invalid.ts | 59 ++-- test/validation/union/valid.ts | 18 +- test/validation/unknown/valid-number.ts | 12 +- test/validation/unknown/valid-string.ts | 12 +- test/validation/unknown/valid-undefined.ts | 12 +- transform.cjs | 293 ++++++++++++++++++ 190 files changed, 3096 insertions(+), 2109 deletions(-) create mode 100755 rename.sh create mode 100644 transform.cjs diff --git a/rename.sh b/rename.sh new file mode 100755 index 00000000..ac0c2444 --- /dev/null +++ b/rename.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# Define the relative directory path +DIR="test/validation" + +# Find all .ts and .tsx files in the specified directory and rename them +find "$DIR" -type f \( -name "*.ts" -o -name "*.tsx" \) | while read -r file; do + # Construct the new file name with .test.ts extension + new_file="${file%.*}.test.ts" + + # Rename the file + mv "$file" "$new_file" + + echo "Renamed $file to $new_file" +done diff --git a/test/validation/any/valid-number.ts b/test/validation/any/valid-number.ts index 70af230d..0511b83d 100644 --- a/test/validation/any/valid-number.ts +++ b/test/validation/any/valid-number.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { any } from '../../../src' -export const Struct = any() - -export const data = 1 - -export const output = 1 +test("Valid any number", () => { + const data = 1; + assert(data, any()); + expect(data).toStrictEqual(1); +}); diff --git a/test/validation/any/valid-string.ts b/test/validation/any/valid-string.ts index 3ee3159d..c5d16cb0 100644 --- a/test/validation/any/valid-string.ts +++ b/test/validation/any/valid-string.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { any } from '../../../src' -export const Struct = any() - -export const data = 'valid' - -export const output = 'valid' +test("Valid any string", () => { + const data = 'valid'; + assert(data, any()); + expect(data).toStrictEqual('valid'); +}); diff --git a/test/validation/any/valid-undefined.ts b/test/validation/any/valid-undefined.ts index d22b8108..7da47090 100644 --- a/test/validation/any/valid-undefined.ts +++ b/test/validation/any/valid-undefined.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { any } from '../../../src' -export const Struct = any() - -export const data = undefined - -export const output = undefined +test("Valid any undefined", () => { + const data = undefined; + assert(data, any()); + expect(data).toStrictEqual(undefined); +}); diff --git a/test/validation/array/invalid-element-property.ts b/test/validation/array/invalid-element-property.ts index f7754163..c9e5d8bf 100644 --- a/test/validation/array/invalid-element-property.ts +++ b/test/validation/array/invalid-element-property.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { array, object, string } from '../../../src' -export const Struct = array(object({ id: string() })) +test("Invalid array element property", () => { + const data = [{ id: '1' }, { id: false }, { id: '3' }]; + const [err, res] = validate(data, array(object({ id: string() }))); + expect(res).toBeUndefined(); -export const data = [{ id: '1' }, { id: false }, { id: '3' }] - -export const failures = [ - { - value: false, - type: 'string', - refinement: undefined, - path: [1, 'id'], - branch: [data, data[1], data[1].id], - }, -] + expect(err).toMatchStructError([ + { + value: false, + type: 'string', + refinement: undefined, + path: [1, 'id'], + branch: [data, data[1], data[1].id], + }, + ]); +}); diff --git a/test/validation/array/invalid-element.ts b/test/validation/array/invalid-element.ts index 86738987..03d09447 100644 --- a/test/validation/array/invalid-element.ts +++ b/test/validation/array/invalid-element.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { array, number } from '../../../src' -export const Struct = array(number()) +test("Invalid array element", () => { + const data = [1, 'invalid', 3]; + const [err, res] = validate(data, array(number())); + expect(res).toBeUndefined(); -export const data = [1, 'invalid', 3] - -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: [1], - branch: [data, data[1]], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: [1], + branch: [data, data[1]], + }, + ]); +}); diff --git a/test/validation/array/invalid-opaque.ts b/test/validation/array/invalid-opaque.ts index 21685f08..73aa6dce 100644 --- a/test/validation/array/invalid-opaque.ts +++ b/test/validation/array/invalid-opaque.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { array } from '../../../src' -export const Struct = array() +test("Invalid array opaque", () => { + const data = 'invalid'; + const [err, res] = validate(data, array()); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'array', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'array', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/array/invalid.ts b/test/validation/array/invalid.ts index 5d1b040d..bb487a49 100644 --- a/test/validation/array/invalid.ts +++ b/test/validation/array/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { array, number } from '../../../src' -export const Struct = array(number()) +test("Invalid array", () => { + const data = 'invalid'; + const [err, res] = validate(data, array(number())); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'array', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'array', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/array/valid-frozen.ts b/test/validation/array/valid-frozen.ts index 814291fe..f40b4603 100644 --- a/test/validation/array/valid-frozen.ts +++ b/test/validation/array/valid-frozen.ts @@ -1,9 +1,9 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { array, number } from '../../../src' -export const Struct = array(number()) - -export const data = Object.freeze([1, 2, 3]) - -export const output = [1, 2, 3] - -export const create = true +test("Valid array frozen", () => { + const data = Object.freeze([1, 2, 3]); + const res = create(data, array(number())); + expect(res).toStrictEqual([1, 2, 3]); +}); diff --git a/test/validation/array/valid-opaque.ts b/test/validation/array/valid-opaque.ts index 21d50e56..ce780a24 100644 --- a/test/validation/array/valid-opaque.ts +++ b/test/validation/array/valid-opaque.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { array } from '../../../src' -export const Struct = array() - -export const data = [1, 'b', true] - -export const output = [1, 'b', true] +test("Valid array opaque", () => { + const data = [1, 'b', true]; + assert(data, array()); + expect(data).toStrictEqual([1, 'b', true]); +}); diff --git a/test/validation/array/valid.ts b/test/validation/array/valid.ts index a98de1cd..d3e7bca4 100644 --- a/test/validation/array/valid.ts +++ b/test/validation/array/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { array, number } from '../../../src' -export const Struct = array(number()) - -export const data = [1, 2, 3] - -export const output = [1, 2, 3] +test("Valid array", () => { + const data = [1, 2, 3]; + assert(data, array(number())); + expect(data).toStrictEqual([1, 2, 3]); +}); diff --git a/test/validation/assign/invalid-object.ts b/test/validation/assign/invalid-object.ts index 4ac6af5d..7c153dd4 100644 --- a/test/validation/assign/invalid-object.ts +++ b/test/validation/assign/invalid-object.ts @@ -1,29 +1,34 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { object, assign, string, number } from '../../../src' const A = object({ a: string() }) const B = object({ a: number(), b: number() }) -export const Struct = assign(A, B) +test("Invalid assign object", () => { + const data = { + a: 'invalid', + b: 2, + c: 5, + }; -export const data = { - a: 'invalid', - b: 2, - c: 5, -} + const [err, res] = validate(data, assign(A, B)); + expect(res).toBeUndefined(); -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: ['a'], - branch: [data, data.a], - }, - { - branch: [data, data.c], - path: ['c'], - refinement: undefined, - type: 'never', - value: 5, - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: ['a'], + branch: [data, data.a], + }, + { + branch: [data, data.c], + path: ['c'], + refinement: undefined, + type: 'never', + value: 5, + }, + ]); +}); diff --git a/test/validation/assign/invalid-type.ts b/test/validation/assign/invalid-type.ts index 840e5e23..caa03845 100644 --- a/test/validation/assign/invalid-type.ts +++ b/test/validation/assign/invalid-type.ts @@ -1,22 +1,27 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { type, object, assign, string, number } from '../../../src' const A = type({ a: string() }) const B = object({ a: number(), b: number() }) -export const Struct = assign(A, B) +test("Invalid assign type", () => { + const data = { + a: 'invalid', + b: 2, + c: 5, + }; -export const data = { - a: 'invalid', - b: 2, - c: 5, -} + const [err, res] = validate(data, assign(A, B)); + expect(res).toBeUndefined(); -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: ['a'], - branch: [data, data.a], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: ['a'], + branch: [data, data.a], + }, + ]); +}); diff --git a/test/validation/assign/valid-object.ts b/test/validation/assign/valid-object.ts index 237c5638..b6be915f 100644 --- a/test/validation/assign/valid-object.ts +++ b/test/validation/assign/valid-object.ts @@ -1,16 +1,20 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { type, assign, string, number } from '../../../src' const A = type({ a: string() }) const B = type({ a: number(), b: number() }) -export const Struct = assign(A, B) +test("Valid assign object", () => { + const data = { + a: 1, + b: 2, + }; -export const data = { - a: 1, - b: 2, -} + assert(data, assign(A, B)); -export const output = { - a: 1, - b: 2, -} + expect(data).toStrictEqual({ + a: 1, + b: 2, + }); +}); diff --git a/test/validation/assign/valid-type.ts b/test/validation/assign/valid-type.ts index fe2e1473..fa2af5aa 100644 --- a/test/validation/assign/valid-type.ts +++ b/test/validation/assign/valid-type.ts @@ -1,18 +1,22 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { type, object, assign, string, number } from '../../../src' const A = type({ a: string() }) const B = object({ b: number() }) -export const Struct = assign(A, B) +test("Valid assign type", () => { + const data = { + a: '1', + b: 2, + c: 3, + }; -export const data = { - a: '1', - b: 2, - c: 3, -} + assert(data, assign(A, B)); -export const output = { - a: '1', - b: 2, - c: 3, -} + expect(data).toStrictEqual({ + a: '1', + b: 2, + c: 3, + }); +}); diff --git a/test/validation/bigint/invalid-number.ts b/test/validation/bigint/invalid-number.ts index dc0e2662..dc2a35a2 100644 --- a/test/validation/bigint/invalid-number.ts +++ b/test/validation/bigint/invalid-number.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { bigint } from '../../../src' -export const Struct = bigint() +test("Invalid bigint number", () => { + const data = 3; + const [err, res] = validate(data, bigint()); + expect(res).toBeUndefined(); -export const data = 3 - -export const failures = [ - { - value: 3, - type: 'bigint', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 3, + type: 'bigint', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/bigint/invalid.ts b/test/validation/bigint/invalid.ts index bafb1785..0bcdfd62 100644 --- a/test/validation/bigint/invalid.ts +++ b/test/validation/bigint/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { bigint } from '../../../src' -export const Struct = bigint() +test("Invalid bigint", () => { + const data = 'invalid'; + const [err, res] = validate(data, bigint()); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'bigint', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'bigint', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/bigint/valid.ts b/test/validation/bigint/valid.ts index 4fcdfe60..c429c46f 100644 --- a/test/validation/bigint/valid.ts +++ b/test/validation/bigint/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { bigint } from '../../../src' -export const Struct = bigint() - -export const data = 542n - -export const output = 542n +test("Valid bigint", () => { + const data = 542n; + assert(data, bigint()); + expect(data).toStrictEqual(542n); +}); diff --git a/test/validation/boolean/invalid.ts b/test/validation/boolean/invalid.ts index 01b05be6..3bca802d 100644 --- a/test/validation/boolean/invalid.ts +++ b/test/validation/boolean/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { boolean } from '../../../src' -export const Struct = boolean() +test("Invalid boolean", () => { + const data = 'invalid'; + const [err, res] = validate(data, boolean()); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'boolean', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'boolean', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/boolean/valid.ts b/test/validation/boolean/valid.ts index 86d8c122..a6528798 100644 --- a/test/validation/boolean/valid.ts +++ b/test/validation/boolean/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { boolean } from '../../../src' -export const Struct = boolean() - -export const data = true - -export const output = true +test("Valid boolean", () => { + const data = true; + assert(data, boolean()); + expect(data).toStrictEqual(true); +}); diff --git a/test/validation/coerce/changed.ts b/test/validation/coerce/changed.ts index da3c9cdd..63ce631c 100644 --- a/test/validation/coerce/changed.ts +++ b/test/validation/coerce/changed.ts @@ -1,11 +1,13 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { string, unknown, coerce } from '../../../src' -export const Struct = coerce(string(), unknown(), (x) => - x == null ? 'unknown' : x -) +test("Changed coerce", () => { + const data = null; -export const data = null + const res = create(data, coerce(string(), unknown(), (x) => + x == null ? 'unknown' : x + )); -export const output = 'unknown' - -export const create = true + expect(res).toStrictEqual('unknown'); +}); diff --git a/test/validation/coerce/condition-not-met.ts b/test/validation/coerce/condition-not-met.ts index 2f36b2bc..acd353d4 100644 --- a/test/validation/coerce/condition-not-met.ts +++ b/test/validation/coerce/condition-not-met.ts @@ -1,17 +1,23 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { string, number, coerce } from '../../../src' -export const Struct = coerce(string(), number(), (x) => 'known') +test("Condition coerce not met", () => { + const data = false; -export const data = false + const [err, res] = validate(data, coerce(string(), number(), (x) => 'known'), { + coerce: true + }); -export const failures = [ - { - value: false, - type: 'string', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(res).toBeUndefined(); -export const create = true + expect(err).toMatchStructError([ + { + value: false, + type: 'string', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/coerce/unchanged.ts b/test/validation/coerce/unchanged.ts index abe5aeba..8a4dc524 100644 --- a/test/validation/coerce/unchanged.ts +++ b/test/validation/coerce/unchanged.ts @@ -1,11 +1,13 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { string, unknown, coerce } from '../../../src' -export const Struct = coerce(string(), unknown(), (x) => - x == null ? 'unknown' : x -) +test("Unchanged coerce", () => { + const data = 'known'; -export const data = 'known' + const res = create(data, coerce(string(), unknown(), (x) => + x == null ? 'unknown' : x + )); -export const output = 'known' - -export const create = true + expect(res).toStrictEqual('known'); +}); diff --git a/test/validation/date/invalid-date.ts b/test/validation/date/invalid-date.ts index 3ffdef33..a1b8c8c6 100644 --- a/test/validation/date/invalid-date.ts +++ b/test/validation/date/invalid-date.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { date } from '../../../src' -export const Struct = date() +test("Invalid date date", () => { + const data = new Date('invalid'); + const [err, res] = validate(data, date()); + expect(res).toBeUndefined(); -export const data = new Date('invalid') - -export const failures = [ - { - value: data, - type: 'date', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: data, + type: 'date', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/date/invalid.ts b/test/validation/date/invalid.ts index e4eca7c5..21d23f33 100644 --- a/test/validation/date/invalid.ts +++ b/test/validation/date/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { date } from '../../../src' -export const Struct = date() +test("Invalid date", () => { + const data = 'invalid'; + const [err, res] = validate(data, date()); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'date', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'date', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/date/valid.ts b/test/validation/date/valid.ts index 947156a3..65f43f08 100644 --- a/test/validation/date/valid.ts +++ b/test/validation/date/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { date } from '../../../src' -export const Struct = date() - -export const data = new Date(0) - -export const output = new Date(0) +test("Valid date", () => { + const data = new Date(0); + assert(data, date()); + expect(data).toStrictEqual(new Date(0)); +}); diff --git a/test/validation/defaulted/function.ts b/test/validation/defaulted/function.ts index aac1e68c..cd95d356 100644 --- a/test/validation/defaulted/function.ts +++ b/test/validation/defaulted/function.ts @@ -1,9 +1,9 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { number, defaulted } from '../../../src' -export const Struct = defaulted(number(), () => 42) - -export const data = undefined - -export const output = 42 - -export const create = true +test("Function defaulted", () => { + const data = undefined; + const res = create(data, defaulted(number(), () => 42)); + expect(res).toStrictEqual(42); +}); diff --git a/test/validation/defaulted/mixin.ts b/test/validation/defaulted/mixin.ts index f587c2d6..1518f960 100644 --- a/test/validation/defaulted/mixin.ts +++ b/test/validation/defaulted/mixin.ts @@ -1,22 +1,24 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { defaulted, string, object, number } from '../../../src' -export const Struct = defaulted( - object({ - title: string(), - version: number(), - }), - { - title: 'Untitled', - } -) - -export const data = { - version: 0, -} +test("Mixin defaulted", () => { + const data = { + version: 0, + }; -export const output = { - title: 'Untitled', - version: 0, -} + const res = create(data, defaulted( + object({ + title: string(), + version: number(), + }), + { + title: 'Untitled', + } + )); -export const create = true + expect(res).toStrictEqual({ + title: 'Untitled', + version: 0, + }); +}); diff --git a/test/validation/defaulted/nested-double.ts b/test/validation/defaulted/nested-double.ts index f661c285..a4f2ba6a 100644 --- a/test/validation/defaulted/nested-double.ts +++ b/test/validation/defaulted/nested-double.ts @@ -1,20 +1,22 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { defaulted, string, object } from '../../../src' -export const Struct = object({ - book: defaulted( - object({ - title: defaulted(string(), 'Untitled'), - }), - {} - ), -}) +test("Nested defaulted double", () => { + const data = {}; -export const data = {} + const res = create(data, object({ + book: defaulted( + object({ + title: defaulted(string(), 'Untitled'), + }), + {} + ), + })); -export const output = { - book: { - title: 'Untitled', - }, -} - -export const create = true + expect(res).toStrictEqual({ + book: { + title: 'Untitled', + }, + }); +}); diff --git a/test/validation/defaulted/nested.ts b/test/validation/defaulted/nested.ts index b432ea84..1002e958 100644 --- a/test/validation/defaulted/nested.ts +++ b/test/validation/defaulted/nested.ts @@ -1,13 +1,15 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { defaulted, string, object } from '../../../src' -export const Struct = object({ - title: defaulted(string(), 'Untitled'), -}) +test("Nested defaulted", () => { + const data = {}; -export const data = {} + const res = create(data, object({ + title: defaulted(string(), 'Untitled'), + })); -export const output = { - title: 'Untitled', -} - -export const create = true + expect(res).toStrictEqual({ + title: 'Untitled', + }); +}); diff --git a/test/validation/defaulted/strict.ts b/test/validation/defaulted/strict.ts index aa10f41a..960cd2d4 100644 --- a/test/validation/defaulted/strict.ts +++ b/test/validation/defaulted/strict.ts @@ -1,30 +1,36 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { defaulted, string, type, number } from '../../../src' -export const Struct = defaulted( - type({ - title: string(), - version: number(), - }), - { - title: 'Untitled', - }, - { - strict: true, - } -) +test("Strict defaulted", () => { + const data = { + version: 0, + }; -export const data = { - version: 0, -} + const [err, res] = validate(data, defaulted( + type({ + title: string(), + version: number(), + }), + { + title: 'Untitled', + }, + { + strict: true, + } + ), { + coerce: true + }); -export const failures = [ - { - value: undefined, - type: 'string', - refinement: undefined, - path: ['title'], - branch: [data, undefined], - }, -] + expect(res).toBeUndefined(); -export const create = true + expect(err).toMatchStructError([ + { + value: undefined, + type: 'string', + refinement: undefined, + path: ['title'], + branch: [data, undefined], + }, + ]); +}); diff --git a/test/validation/defaulted/value.ts b/test/validation/defaulted/value.ts index dc2acc59..14623027 100644 --- a/test/validation/defaulted/value.ts +++ b/test/validation/defaulted/value.ts @@ -1,9 +1,9 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { number, defaulted } from '../../../src' -export const Struct = defaulted(number(), 42) - -export const data = undefined - -export const output = 42 - -export const create = true +test("Value defaulted", () => { + const data = undefined; + const res = create(data, defaulted(number(), 42)); + expect(res).toStrictEqual(42); +}); diff --git a/test/validation/deprecated/invalid-null.ts b/test/validation/deprecated/invalid-null.ts index 03d3524b..671dd972 100644 --- a/test/validation/deprecated/invalid-null.ts +++ b/test/validation/deprecated/invalid-null.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { deprecated, string } from '../../../src' -export const Struct = deprecated(string(), () => {}) +test("Invalid deprecated null", () => { + const data = null; + const [err, res] = validate(data, deprecated(string(), () => {})); + expect(res).toBeUndefined(); -export const data = null - -export const failures = [ - { - value: null, - type: 'string', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: null, + type: 'string', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/deprecated/invalid-property.ts b/test/validation/deprecated/invalid-property.ts index 8eff69ac..36612d3e 100644 --- a/test/validation/deprecated/invalid-property.ts +++ b/test/validation/deprecated/invalid-property.ts @@ -1,19 +1,25 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { deprecated, number, object } from '../../../src' -export const Struct = object({ - deprecatedKey: deprecated(number(), () => {}), -}) +test("Invalid deprecated property", () => { + const data = { + deprecatedKey: '42', + }; -export const data = { - deprecatedKey: '42', -} + const [err, res] = validate(data, object({ + deprecatedKey: deprecated(number(), () => {}), + })); -export const failures = [ - { - value: '42', - type: 'number', - refinement: undefined, - path: ['deprecatedKey'], - branch: [data, data.deprecatedKey], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: '42', + type: 'number', + refinement: undefined, + path: ['deprecatedKey'], + branch: [data, data.deprecatedKey], + }, + ]); +}); diff --git a/test/validation/deprecated/invalid.ts b/test/validation/deprecated/invalid.ts index 54286efb..ce7620ae 100644 --- a/test/validation/deprecated/invalid.ts +++ b/test/validation/deprecated/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { deprecated, number } from '../../../src' -export const Struct = deprecated(number(), () => {}) +test("Invalid deprecated", () => { + const data = '42'; + const [err, res] = validate(data, deprecated(number(), () => {})); + expect(res).toBeUndefined(); -export const data = '42' - -export const failures = [ - { - value: '42', - type: 'number', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: '42', + type: 'number', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/deprecated/valid-property.ts b/test/validation/deprecated/valid-property.ts index ea10861a..f8914fb2 100644 --- a/test/validation/deprecated/valid-property.ts +++ b/test/validation/deprecated/valid-property.ts @@ -1,14 +1,18 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { type, number, deprecated, any } from '../../../src' -export const Struct = type({ - name: deprecated(any(), () => {}), - age: number(), -}) +test("Valid deprecated property", () => { + const data = { + age: 42, + }; -export const data = { - age: 42, -} + assert(data, type({ + name: deprecated(any(), () => {}), + age: number(), + })); -export const output = { - age: 42, -} + expect(data).toStrictEqual({ + age: 42, + }); +}); diff --git a/test/validation/deprecated/valid-undefined.ts b/test/validation/deprecated/valid-undefined.ts index 38a89b06..28f11e3e 100644 --- a/test/validation/deprecated/valid-undefined.ts +++ b/test/validation/deprecated/valid-undefined.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { deprecated, number } from '../../../src' -export const Struct = deprecated(number(), () => {}) - -export const data = undefined - -export const output = undefined +test("Valid deprecated undefined", () => { + const data = undefined; + assert(data, deprecated(number(), () => {})); + expect(data).toStrictEqual(undefined); +}); diff --git a/test/validation/deprecated/valid.ts b/test/validation/deprecated/valid.ts index 5bbf414a..d688d662 100644 --- a/test/validation/deprecated/valid.ts +++ b/test/validation/deprecated/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { deprecated, number } from '../../../src' -export const Struct = deprecated(number(), () => {}) - -export const data = 42 - -export const output = 42 +test("Valid deprecated", () => { + const data = 42; + assert(data, deprecated(number(), () => {})); + expect(data).toStrictEqual(42); +}); diff --git a/test/validation/dynamic/invalid-reference.ts b/test/validation/dynamic/invalid-reference.ts index 156b0678..8b186b26 100644 --- a/test/validation/dynamic/invalid-reference.ts +++ b/test/validation/dynamic/invalid-reference.ts @@ -1,3 +1,5 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { assert, type, dynamic, literal, number, string } from '../../../src' const Entity = type({ @@ -19,22 +21,26 @@ const map = { PRODUCT: Product, } -export const Struct = dynamic((entity) => { - assert(entity, Entity) - return map[entity.object] -}) +test("Invalid dynamic reference", () => { + const data = { + object: 'PRODUCT', + price: 'Only $19.99!', + }; -export const data = { - object: 'PRODUCT', - price: 'Only $19.99!', -} + const [err, res] = validate(data, dynamic((entity) => { + assert(entity, Entity) + return map[entity.object] + })); + + expect(res).toBeUndefined(); -export const failures = [ - { - value: 'Only $19.99!', - type: 'number', - refinement: undefined, - path: ['price'], - branch: [data, data.price], - }, -] + expect(err).toMatchStructError([ + { + value: 'Only $19.99!', + type: 'number', + refinement: undefined, + path: ['price'], + branch: [data, data.price], + }, + ]); +}); diff --git a/test/validation/dynamic/invalid.ts b/test/validation/dynamic/invalid.ts index b0bb6931..5dc76e54 100644 --- a/test/validation/dynamic/invalid.ts +++ b/test/validation/dynamic/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { dynamic, string } from '../../../src' -export const Struct = dynamic(() => string()) +test("Invalid dynamic", () => { + const data = 3; + const [err, res] = validate(data, dynamic(() => string())); + expect(res).toBeUndefined(); -export const data = 3 - -export const failures = [ - { - value: 3, - type: 'string', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 3, + type: 'string', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/dynamic/valid-reference.ts b/test/validation/dynamic/valid-reference.ts index 5156c89d..370e29dd 100644 --- a/test/validation/dynamic/valid-reference.ts +++ b/test/validation/dynamic/valid-reference.ts @@ -1,3 +1,5 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { assert, type, dynamic, literal, string, number } from '../../../src' const Entity = type({ @@ -19,17 +21,19 @@ const map = { PRODUCT: Product, } -export const Struct = dynamic((entity) => { - assert(entity, Entity) - return map[entity.object] -}) +test("Valid dynamic reference", () => { + const data = { + object: 'PRODUCT', + price: 1999, + }; -export const data = { - object: 'PRODUCT', - price: 1999, -} + assert(data, dynamic((entity) => { + assert(entity, Entity) + return map[entity.object] + })); -export const output = { - object: 'PRODUCT', - price: 1999, -} + expect(data).toStrictEqual({ + object: 'PRODUCT', + price: 1999, + }); +}); diff --git a/test/validation/dynamic/valid.ts b/test/validation/dynamic/valid.ts index 8cdb2e21..8ab31685 100644 --- a/test/validation/dynamic/valid.ts +++ b/test/validation/dynamic/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { dynamic, string } from '../../../src' -export const Struct = dynamic(() => string()) - -export const data = 'valid' - -export const output = 'valid' +test("Valid dynamic", () => { + const data = 'valid'; + assert(data, dynamic(() => string())); + expect(data).toStrictEqual('valid'); +}); diff --git a/test/validation/dynamic/with-refiners.ts b/test/validation/dynamic/with-refiners.ts index 9da48bce..98976689 100644 --- a/test/validation/dynamic/with-refiners.ts +++ b/test/validation/dynamic/with-refiners.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { dynamic, string, nonempty } from '../../../src' -export const Struct = dynamic(() => nonempty(string())) +test("With dynamic refiners", () => { + const data = ''; + const [err, res] = validate(data, dynamic(() => nonempty(string()))); + expect(res).toBeUndefined(); -export const data = '' - -export const failures = [ - { - value: data, - type: 'string', - refinement: 'nonempty', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: data, + type: 'string', + refinement: 'nonempty', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/empty/invalid-array.ts b/test/validation/empty/invalid-array.ts index 27abbfb6..010c00ea 100644 --- a/test/validation/empty/invalid-array.ts +++ b/test/validation/empty/invalid-array.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { array, empty, number } from '../../../src' -export const Struct = empty(array(number())) +test("Invalid empty array", () => { + const data = [1, 2, 3]; + const [err, res] = validate(data, empty(array(number()))); + expect(res).toBeUndefined(); -export const data = [1, 2, 3] - -export const failures = [ - { - value: data, - type: 'array', - refinement: 'empty', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: data, + type: 'array', + refinement: 'empty', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/empty/invalid-map.ts b/test/validation/empty/invalid-map.ts index 7deb6535..26751d98 100644 --- a/test/validation/empty/invalid-map.ts +++ b/test/validation/empty/invalid-map.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { map, empty, number, string } from '../../../src' -export const Struct = empty(map(number(), string())) +test("Invalid empty map", () => { + const data = new Map([[1, 'a']]); + const [err, res] = validate(data, empty(map(number(), string()))); + expect(res).toBeUndefined(); -export const data = new Map([[1, 'a']]) - -export const failures = [ - { - value: data, - type: 'map', - refinement: 'empty', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: data, + type: 'map', + refinement: 'empty', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/empty/invalid-set.ts b/test/validation/empty/invalid-set.ts index 1d21266c..96eedd2d 100644 --- a/test/validation/empty/invalid-set.ts +++ b/test/validation/empty/invalid-set.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { set, empty, number } from '../../../src' -export const Struct = empty(set(number())) +test("Invalid empty set", () => { + const data = new Set([1, 2, 3]); + const [err, res] = validate(data, empty(set(number()))); + expect(res).toBeUndefined(); -export const data = new Set([1, 2, 3]) - -export const failures = [ - { - value: data, - type: 'set', - refinement: 'empty', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: data, + type: 'set', + refinement: 'empty', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/empty/invalid-string.ts b/test/validation/empty/invalid-string.ts index 58e80560..b1459605 100644 --- a/test/validation/empty/invalid-string.ts +++ b/test/validation/empty/invalid-string.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { string, empty } from '../../../src' -export const Struct = empty(string()) +test("Invalid empty string", () => { + const data = 'invalid'; + const [err, res] = validate(data, empty(string())); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'string', - refinement: 'empty', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'string', + refinement: 'empty', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/empty/valid-array.ts b/test/validation/empty/valid-array.ts index d90e8cbd..4bb7b909 100644 --- a/test/validation/empty/valid-array.ts +++ b/test/validation/empty/valid-array.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, array, empty } from '../../../src' -export const Struct = empty(array(number())) - -export const data = [] - -export const output = [] +test("Valid empty array", () => { + const data = []; + assert(data, empty(array(number()))); + expect(data).toStrictEqual([]); +}); diff --git a/test/validation/empty/valid-map.ts b/test/validation/empty/valid-map.ts index e203f42e..269202a9 100644 --- a/test/validation/empty/valid-map.ts +++ b/test/validation/empty/valid-map.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { string, number, map, empty } from '../../../src' -export const Struct = empty(map(number(), string())) - -export const data = new Map() - -export const output = data +test("Valid empty map", () => { + const data = new Map(); + assert(data, empty(map(number(), string()))); + expect(data).toStrictEqual(data); +}); diff --git a/test/validation/empty/valid-set.ts b/test/validation/empty/valid-set.ts index a20bb7ca..500c72db 100644 --- a/test/validation/empty/valid-set.ts +++ b/test/validation/empty/valid-set.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, set, empty } from '../../../src' -export const Struct = empty(set(number())) - -export const data = new Set() - -export const output = data +test("Valid empty set", () => { + const data = new Set(); + assert(data, empty(set(number()))); + expect(data).toStrictEqual(data); +}); diff --git a/test/validation/empty/valid-string.ts b/test/validation/empty/valid-string.ts index 2925c2e8..bd98545b 100644 --- a/test/validation/empty/valid-string.ts +++ b/test/validation/empty/valid-string.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { string, empty } from '../../../src' -export const Struct = empty(string()) - -export const data = '' - -export const output = '' +test("Valid empty string", () => { + const data = ''; + assert(data, empty(string())); + expect(data).toStrictEqual(''); +}); diff --git a/test/validation/enums/invalid-numbers.ts b/test/validation/enums/invalid-numbers.ts index 8e3aeb2d..c5ff1fdd 100644 --- a/test/validation/enums/invalid-numbers.ts +++ b/test/validation/enums/invalid-numbers.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { enums } from '../../../src' -export const Struct = enums([1, 2]) +test("Invalid enums numbers", () => { + const data = 'invalid'; + const [err, res] = validate(data, enums([1, 2])); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'enums', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'enums', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/enums/invalid-strings.ts b/test/validation/enums/invalid-strings.ts index 2711dcc8..0ebc134e 100644 --- a/test/validation/enums/invalid-strings.ts +++ b/test/validation/enums/invalid-strings.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { enums } from '../../../src' -export const Struct = enums(['one', 'two']) +test("Invalid enums strings", () => { + const data = 'invalid'; + const [err, res] = validate(data, enums(['one', 'two'])); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'enums', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'enums', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/enums/valid.ts b/test/validation/enums/valid.ts index 5e63da93..3c83c728 100644 --- a/test/validation/enums/valid.ts +++ b/test/validation/enums/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { enums } from '../../../src' -export const Struct = enums(['one', 'two']) - -export const data = 'two' - -export const output = 'two' +test("Valid enums", () => { + const data = 'two'; + assert(data, enums(['one', 'two'])); + expect(data).toStrictEqual('two'); +}); diff --git a/test/validation/function/invalid.ts b/test/validation/function/invalid.ts index dbc7bdd8..0f85a010 100644 --- a/test/validation/function/invalid.ts +++ b/test/validation/function/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { func } from '../../../src' -export const Struct = func() +test("Invalid function", () => { + const data = false; + const [err, res] = validate(data, func()); + expect(res).toBeUndefined(); -export const data = false - -export const failures = [ - { - value: false, - type: 'func', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: false, + type: 'func', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/function/valid.ts b/test/validation/function/valid.ts index a9318bbe..2f15c960 100644 --- a/test/validation/function/valid.ts +++ b/test/validation/function/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { func } from '../../../src' -export const Struct = func() - -export const data = function () {} - -export const output = data +test("Valid function", () => { + const data = function () {}; + assert(data, func()); + expect(data).toStrictEqual(data); +}); diff --git a/test/validation/instance/invalid.ts b/test/validation/instance/invalid.ts index 73462668..871675eb 100644 --- a/test/validation/instance/invalid.ts +++ b/test/validation/instance/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { instance } from '../../../src' -export const Struct = instance(Array) +test("Invalid instance", () => { + const data = false; + const [err, res] = validate(data, instance(Array)); + expect(res).toBeUndefined(); -export const data = false - -export const failures = [ - { - value: false, - type: 'instance', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: false, + type: 'instance', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/instance/valid.ts b/test/validation/instance/valid.ts index 21645966..8e9f2a95 100644 --- a/test/validation/instance/valid.ts +++ b/test/validation/instance/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { instance } from '../../../src' -export const Struct = instance(Array) - -export const data = [1] - -export const output = [1] +test("Valid instance", () => { + const data = [1]; + assert(data, instance(Array)); + expect(data).toStrictEqual([1]); +}); diff --git a/test/validation/integer/invalid-decimal.ts b/test/validation/integer/invalid-decimal.ts index f39e1185..f09d5d1c 100644 --- a/test/validation/integer/invalid-decimal.ts +++ b/test/validation/integer/invalid-decimal.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { integer } from '../../../src' -export const Struct = integer() +test("Invalid integer decimal", () => { + const data = 3.14; + const [err, res] = validate(data, integer()); + expect(res).toBeUndefined(); -export const data = 3.14 - -export const failures = [ - { - value: 3.14, - type: 'integer', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 3.14, + type: 'integer', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/integer/invalid.ts b/test/validation/integer/invalid.ts index d3732b18..3544b3bd 100644 --- a/test/validation/integer/invalid.ts +++ b/test/validation/integer/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { integer } from '../../../src' -export const Struct = integer() +test("Invalid integer", () => { + const data = 'invalid'; + const [err, res] = validate(data, integer()); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'integer', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'integer', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/integer/valid.ts b/test/validation/integer/valid.ts index 34673bf2..27a81951 100644 --- a/test/validation/integer/valid.ts +++ b/test/validation/integer/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { integer } from '../../../src' -export const Struct = integer() - -export const data = 42 - -export const output = 42 +test("Valid integer", () => { + const data = 42; + assert(data, integer()); + expect(data).toStrictEqual(42); +}); diff --git a/test/validation/intersection/invalid-refinement.ts b/test/validation/intersection/invalid-refinement.ts index 701d7d02..455018e4 100644 --- a/test/validation/intersection/invalid-refinement.ts +++ b/test/validation/intersection/invalid-refinement.ts @@ -1,18 +1,22 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { intersection, refine, number } from '../../../src' const A = number() const B = refine(number(), 'positive', (value) => value > 0) -export const Struct = intersection([A, B]) +test("Invalid intersection refinement", () => { + const data = -1; + const [err, res] = validate(data, intersection([A, B])); + expect(res).toBeUndefined(); -export const data = -1 - -export const failures = [ - { - type: 'number', - refinement: 'positive', - value: -1, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + type: 'number', + refinement: 'positive', + value: -1, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/intersection/invalid.ts b/test/validation/intersection/invalid.ts index dab2d018..4522c953 100644 --- a/test/validation/intersection/invalid.ts +++ b/test/validation/intersection/invalid.ts @@ -1,21 +1,26 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { type, intersection, string, number } from '../../../src' const A = type({ a: string() }) const B = type({ b: number() }) -export const Struct = intersection([A, B]) +test("Invalid intersection", () => { + const data = { + a: 'a', + b: 'invalid', + }; -export const data = { - a: 'a', - b: 'invalid', -} + const [err, res] = validate(data, intersection([A, B])); + expect(res).toBeUndefined(); -export const failures = [ - { - type: 'number', - value: 'invalid', - refinement: undefined, - path: ['b'], - branch: [data, data.b], - }, -] + expect(err).toMatchStructError([ + { + type: 'number', + value: 'invalid', + refinement: undefined, + path: ['b'], + branch: [data, data.b], + }, + ]); +}); diff --git a/test/validation/intersection/valid-refinement.ts b/test/validation/intersection/valid-refinement.ts index 27d58c25..590617c7 100644 --- a/test/validation/intersection/valid-refinement.ts +++ b/test/validation/intersection/valid-refinement.ts @@ -1,10 +1,12 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { intersection, refine, number } from '../../../src' const A = number() const B = refine(number(), 'positive', (value) => value > 0) -export const Struct = intersection([A, B]) - -export const data = 1 - -export const output = 1 +test("Valid intersection refinement", () => { + const data = 1; + assert(data, intersection([A, B])); + expect(data).toStrictEqual(1); +}); diff --git a/test/validation/intersection/valid.ts b/test/validation/intersection/valid.ts index 3b2473bf..b98bc527 100644 --- a/test/validation/intersection/valid.ts +++ b/test/validation/intersection/valid.ts @@ -1,16 +1,20 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { type, intersection, string, number } from '../../../src' const A = type({ a: string() }) const B = type({ b: number() }) -export const Struct = intersection([A, B]) +test("Valid intersection", () => { + const data = { + a: 'a', + b: 42, + }; -export const data = { - a: 'a', - b: 42, -} + assert(data, intersection([A, B])); -export const output = { - a: 'a', - b: 42, -} + expect(data).toStrictEqual({ + a: 'a', + b: 42, + }); +}); diff --git a/test/validation/lazy/invalid.ts b/test/validation/lazy/invalid.ts index ac79bd1c..54bd59dc 100644 --- a/test/validation/lazy/invalid.ts +++ b/test/validation/lazy/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { lazy, string } from '../../../src' -export const Struct = lazy(() => string()) +test("Invalid lazy", () => { + const data = 3; + const [err, res] = validate(data, lazy(() => string())); + expect(res).toBeUndefined(); -export const data = 3 - -export const failures = [ - { - value: 3, - type: 'string', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 3, + type: 'string', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/lazy/valid.ts b/test/validation/lazy/valid.ts index b1802910..c4922054 100644 --- a/test/validation/lazy/valid.ts +++ b/test/validation/lazy/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { lazy, string } from '../../../src' -export const Struct = lazy(() => string()) - -export const data = 'two' - -export const output = 'two' +test("Valid lazy", () => { + const data = 'two'; + assert(data, lazy(() => string())); + expect(data).toStrictEqual('two'); +}); diff --git a/test/validation/lazy/with-refiners.ts b/test/validation/lazy/with-refiners.ts index 2261963b..5dcbcc24 100644 --- a/test/validation/lazy/with-refiners.ts +++ b/test/validation/lazy/with-refiners.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { lazy, nonempty, string } from '../../../src' -export const Struct = lazy(() => nonempty(string())) +test("With lazy refiners", () => { + const data = ''; + const [err, res] = validate(data, lazy(() => nonempty(string()))); + expect(res).toBeUndefined(); -export const data = '' - -export const failures = [ - { - value: data, - type: 'string', - refinement: 'nonempty', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: data, + type: 'string', + refinement: 'nonempty', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/literal/invalid.ts b/test/validation/literal/invalid.ts index f7473a3e..207e7f5a 100644 --- a/test/validation/literal/invalid.ts +++ b/test/validation/literal/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { literal } from '../../../src' -export const Struct = literal(42) +test("Invalid literal", () => { + const data = false; + const [err, res] = validate(data, literal(42)); + expect(res).toBeUndefined(); -export const data = false - -export const failures = [ - { - value: false, - type: 'literal', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: false, + type: 'literal', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/literal/valid.ts b/test/validation/literal/valid.ts index 70ea8fb4..52371783 100644 --- a/test/validation/literal/valid.ts +++ b/test/validation/literal/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { literal } from '../../../src' -export const Struct = literal(42) - -export const data = 42 - -export const output = 42 +test("Valid literal", () => { + const data = 42; + assert(data, literal(42)); + expect(data).toStrictEqual(42); +}); diff --git a/test/validation/map/invalid-opaque.ts b/test/validation/map/invalid-opaque.ts index 4dfe413a..14b33980 100644 --- a/test/validation/map/invalid-opaque.ts +++ b/test/validation/map/invalid-opaque.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { map } from '../../../src' -export const Struct = map() +test("Invalid map opaque", () => { + const data = 'invalid'; + const [err, res] = validate(data, map()); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'map', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'map', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/map/invalid-property.ts b/test/validation/map/invalid-property.ts index a89c3a3f..f26f63b1 100644 --- a/test/validation/map/invalid-property.ts +++ b/test/validation/map/invalid-property.ts @@ -1,25 +1,30 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { map, string, number } from '../../../src' -export const Struct = map(string(), number()) +test("Invalid map property", () => { + const data = new Map([ + ['a', 'a'], + ['b', 'b'], + ]); -export const data = new Map([ - ['a', 'a'], - ['b', 'b'], -]) + const [err, res] = validate(data, map(string(), number())); + expect(res).toBeUndefined(); -export const failures = [ - { - value: 'a', - type: 'number', - refinement: undefined, - path: ['a'], - branch: [data, 'a'], - }, - { - value: 'b', - type: 'number', - refinement: undefined, - path: ['b'], - branch: [data, 'b'], - }, -] + expect(err).toMatchStructError([ + { + value: 'a', + type: 'number', + refinement: undefined, + path: ['a'], + branch: [data, 'a'], + }, + { + value: 'b', + type: 'number', + refinement: undefined, + path: ['b'], + branch: [data, 'b'], + }, + ]); +}); diff --git a/test/validation/map/invalid.ts b/test/validation/map/invalid.ts index 9de01047..a165a6a6 100644 --- a/test/validation/map/invalid.ts +++ b/test/validation/map/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { map, string, number } from '../../../src' -export const Struct = map(string(), number()) +test("Invalid map", () => { + const data = 'invalid'; + const [err, res] = validate(data, map(string(), number())); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'map', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'map', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/map/valid-opaque.ts b/test/validation/map/valid-opaque.ts index 63d0f38c..8b3edd0c 100644 --- a/test/validation/map/valid-opaque.ts +++ b/test/validation/map/valid-opaque.ts @@ -1,10 +1,19 @@ +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { map } from '../../../src' -export const Struct = map() +test('Valid map opaque', () => { + const data = new Map([ + ['a', 1], + [2, true], + ] as any) -export const data = new Map([ - ['a', 1], - [2, true], -] as any) + assert(data, map()) -export const output = data + expect(data).toStrictEqual( + new Map([ + ['a', 1], + [2, true], + ] as any) + ) +}) diff --git a/test/validation/map/valid.ts b/test/validation/map/valid.ts index e7a24d7e..4eb6484e 100644 --- a/test/validation/map/valid.ts +++ b/test/validation/map/valid.ts @@ -1,13 +1,17 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { map, string, number } from '../../../src' -export const Struct = map(string(), number()) +test("Valid map", () => { + const data = new Map([ + ['a', 1], + ['b', 2], + ]); -export const data = new Map([ - ['a', 1], - ['b', 2], -]) + assert(data, map(string(), number())); -export const output = new Map([ - ['a', 1], - ['b', 2], -]) + expect(data).toStrictEqual(new Map([ + ['a', 1], + ['b', 2], + ])); +}); diff --git a/test/validation/max/invalid-exclusive.ts b/test/validation/max/invalid-exclusive.ts index 3e4f43f6..389a5328 100644 --- a/test/validation/max/invalid-exclusive.ts +++ b/test/validation/max/invalid-exclusive.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { number, max } from '../../../src' -export const Struct = max(number(), 0, { exclusive: true }) +test("Invalid max exclusive", () => { + const data = 0; + const [err, res] = validate(data, max(number(), 0, { exclusive: true })); + expect(res).toBeUndefined(); -export const data = 0 - -export const failures = [ - { - value: 0, - type: 'number', - refinement: 'max', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 0, + type: 'number', + refinement: 'max', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/max/invalid.ts b/test/validation/max/invalid.ts index 324ecd21..77590224 100644 --- a/test/validation/max/invalid.ts +++ b/test/validation/max/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { number, max } from '../../../src' -export const Struct = max(number(), 0) +test("Invalid max", () => { + const data = 1; + const [err, res] = validate(data, max(number(), 0)); + expect(res).toBeUndefined(); -export const data = 1 - -export const failures = [ - { - value: 1, - type: 'number', - refinement: 'max', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 1, + type: 'number', + refinement: 'max', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/max/valid-inclusive.ts b/test/validation/max/valid-inclusive.ts index b76c753d..b5dab7ae 100644 --- a/test/validation/max/valid-inclusive.ts +++ b/test/validation/max/valid-inclusive.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, max } from '../../../src' -export const Struct = max(number(), 0) - -export const data = 0 - -export const output = 0 +test("Valid max inclusive", () => { + const data = 0; + assert(data, max(number(), 0)); + expect(data).toStrictEqual(0); +}); diff --git a/test/validation/max/valid.ts b/test/validation/max/valid.ts index 5a94da8c..fb1f4444 100644 --- a/test/validation/max/valid.ts +++ b/test/validation/max/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, max } from '../../../src' -export const Struct = max(number(), 0) - -export const data = -1 - -export const output = -1 +test("Valid max", () => { + const data = -1; + assert(data, max(number(), 0)); + expect(data).toStrictEqual(-1); +}); diff --git a/test/validation/min/invalid-exclusive.ts b/test/validation/min/invalid-exclusive.ts index 5ece76ef..66289d77 100644 --- a/test/validation/min/invalid-exclusive.ts +++ b/test/validation/min/invalid-exclusive.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { number, min } from '../../../src' -export const Struct = min(number(), 0, { exclusive: true }) +test("Invalid min exclusive", () => { + const data = 0; + const [err, res] = validate(data, min(number(), 0, { exclusive: true })); + expect(res).toBeUndefined(); -export const data = 0 - -export const failures = [ - { - value: 0, - type: 'number', - refinement: 'min', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 0, + type: 'number', + refinement: 'min', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/min/invalid.ts b/test/validation/min/invalid.ts index 72f4e1ad..34f348cd 100644 --- a/test/validation/min/invalid.ts +++ b/test/validation/min/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { number, min } from '../../../src' -export const Struct = min(number(), 0) +test("Invalid min", () => { + const data = -1; + const [err, res] = validate(data, min(number(), 0)); + expect(res).toBeUndefined(); -export const data = -1 - -export const failures = [ - { - value: -1, - type: 'number', - refinement: 'min', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: -1, + type: 'number', + refinement: 'min', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/min/valid-inclusive.ts b/test/validation/min/valid-inclusive.ts index 48b0c9ea..1e29fa8d 100644 --- a/test/validation/min/valid-inclusive.ts +++ b/test/validation/min/valid-inclusive.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, min } from '../../../src' -export const Struct = min(number(), 0) - -export const data = 0 - -export const output = 0 +test("Valid min inclusive", () => { + const data = 0; + assert(data, min(number(), 0)); + expect(data).toStrictEqual(0); +}); diff --git a/test/validation/min/valid.ts b/test/validation/min/valid.ts index c33d7f6b..966c7a0b 100644 --- a/test/validation/min/valid.ts +++ b/test/validation/min/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, min } from '../../../src' -export const Struct = min(number(), 0) - -export const data = 3 - -export const output = 3 +test("Valid min", () => { + const data = 3; + assert(data, min(number(), 0)); + expect(data).toStrictEqual(3); +}); diff --git a/test/validation/never/invalid.ts b/test/validation/never/invalid.ts index 8b99fb39..6b58f81b 100644 --- a/test/validation/never/invalid.ts +++ b/test/validation/never/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { never } from '../../../src' -export const Struct = never() +test("Invalid never", () => { + const data = true; + const [err, res] = validate(data, never()); + expect(res).toBeUndefined(); -export const data = true - -export const failures = [ - { - value: true, - type: 'never', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: true, + type: 'never', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/nullable/invalid.ts b/test/validation/nullable/invalid.ts index 028d879e..4b8ef7cd 100644 --- a/test/validation/nullable/invalid.ts +++ b/test/validation/nullable/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { number, nullable } from '../../../src' -export const Struct = nullable(number()) +test("Invalid nullable", () => { + const data = 'invalid'; + const [err, res] = validate(data, nullable(number())); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/nullable/valid-defined-nested.ts b/test/validation/nullable/valid-defined-nested.ts index b357ba8e..59a9ba62 100644 --- a/test/validation/nullable/valid-defined-nested.ts +++ b/test/validation/nullable/valid-defined-nested.ts @@ -1,16 +1,20 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { type, string, number, nullable } from '../../../src' -export const Struct = type({ - name: nullable(string()), - age: number(), -}) +test("Valid nullable defined nested", () => { + const data = { + name: 'Jill', + age: 42, + }; -export const data = { - name: 'Jill', - age: 42, -} + assert(data, type({ + name: nullable(string()), + age: number(), + })); -export const output = { - name: 'Jill', - age: 42, -} + expect(data).toStrictEqual({ + name: 'Jill', + age: 42, + }); +}); diff --git a/test/validation/nullable/valid-defined.ts b/test/validation/nullable/valid-defined.ts index 18eb8a74..4334bf06 100644 --- a/test/validation/nullable/valid-defined.ts +++ b/test/validation/nullable/valid-defined.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, nullable } from '../../../src' -export const Struct = nullable(number()) - -export const data = 42 - -export const output = 42 +test("Valid nullable defined", () => { + const data = 42; + assert(data, nullable(number())); + expect(data).toStrictEqual(42); +}); diff --git a/test/validation/nullable/valid-null-nested.ts b/test/validation/nullable/valid-null-nested.ts index 9db75acb..21e2f5be 100644 --- a/test/validation/nullable/valid-null-nested.ts +++ b/test/validation/nullable/valid-null-nested.ts @@ -1,16 +1,20 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { type, string, number, nullable } from '../../../src' -export const Struct = type({ - name: nullable(string()), - age: number(), -}) +test("Valid nullable null nested", () => { + const data = { + name: null, + age: 42, + }; -export const data = { - name: null, - age: 42, -} + assert(data, type({ + name: nullable(string()), + age: number(), + })); -export const output = { - name: null, - age: 42, -} + expect(data).toStrictEqual({ + name: null, + age: 42, + }); +}); diff --git a/test/validation/nullable/valid-null.ts b/test/validation/nullable/valid-null.ts index 528493f0..38768520 100644 --- a/test/validation/nullable/valid-null.ts +++ b/test/validation/nullable/valid-null.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, nullable } from '../../../src' -export const Struct = nullable(number()) - -export const data = null - -export const output = null +test("Valid nullable null", () => { + const data = null; + assert(data, nullable(number())); + expect(data).toStrictEqual(null); +}); diff --git a/test/validation/number/invalid.ts b/test/validation/number/invalid.ts index 140420e7..cf5a8550 100644 --- a/test/validation/number/invalid.ts +++ b/test/validation/number/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { number } from '../../../src' -export const Struct = number() +test("Invalid number", () => { + const data = 'invalid'; + const [err, res] = validate(data, number()); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/number/valid.ts b/test/validation/number/valid.ts index 8ea8b9a2..534354eb 100644 --- a/test/validation/number/valid.ts +++ b/test/validation/number/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number } from '../../../src' -export const Struct = number() - -export const data = 42 - -export const output = 42 +test("Valid number", () => { + const data = 42; + assert(data, number()); + expect(data).toStrictEqual(42); +}); diff --git a/test/validation/object/invalid-array.ts b/test/validation/object/invalid-array.ts index 0555dae0..4c59b6d0 100644 --- a/test/validation/object/invalid-array.ts +++ b/test/validation/object/invalid-array.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { object } from '../../../src' -export const Struct = object() +test("Invalid object array", () => { + const data = []; + const [err, res] = validate(data, object()); + expect(res).toBeUndefined(); -export const data = [] - -export const failures = [ - { - value: [], - type: 'object', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: [], + type: 'object', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/object/invalid-element-nested.ts b/test/validation/object/invalid-element-nested.ts index e442244b..5cdeb466 100644 --- a/test/validation/object/invalid-element-nested.ts +++ b/test/validation/object/invalid-element-nested.ts @@ -1,21 +1,27 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { object, array, string } from '../../../src' -export const Struct = object({ - name: string(), - emails: array(string()), -}) +test("Invalid object element nested", () => { + const data = { + name: 'john', + emails: ['name@example.com', false], + }; -export const data = { - name: 'john', - emails: ['name@example.com', false], -} + const [err, res] = validate(data, object({ + name: string(), + emails: array(string()), + })); -export const failures = [ - { - value: false, - type: 'string', - refinement: undefined, - path: ['emails', 1], - branch: [data, data.emails, data.emails[1]], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: false, + type: 'string', + refinement: undefined, + path: ['emails', 1], + branch: [data, data.emails, data.emails[1]], + }, + ]); +}); diff --git a/test/validation/object/invalid-opaque.ts b/test/validation/object/invalid-opaque.ts index c2f1918c..3adf8dc6 100644 --- a/test/validation/object/invalid-opaque.ts +++ b/test/validation/object/invalid-opaque.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { object } from '../../../src' -export const Struct = object() +test("Invalid object opaque", () => { + const data = 'invalid'; + const [err, res] = validate(data, object()); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'object', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'object', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/object/invalid-property-nested.ts b/test/validation/object/invalid-property-nested.ts index 93960c9b..027a77a3 100644 --- a/test/validation/object/invalid-property-nested.ts +++ b/test/validation/object/invalid-property-nested.ts @@ -1,27 +1,33 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { object, string } from '../../../src' -export const Struct = object({ - name: string(), - address: object({ - street: string(), - city: string(), - }), -}) +test("Invalid object property nested", () => { + const data = { + name: 'john', + address: { + street: 123, + city: 'Springfield', + }, + }; -export const data = { - name: 'john', - address: { - street: 123, - city: 'Springfield', - }, -} + const [err, res] = validate(data, object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), + })); -export const failures = [ - { - value: 123, - type: 'string', - refinement: undefined, - path: ['address', 'street'], - branch: [data, data.address, data.address.street], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 123, + type: 'string', + refinement: undefined, + path: ['address', 'street'], + branch: [data, data.address, data.address.street], + }, + ]); +}); diff --git a/test/validation/object/invalid-property-unknown.ts b/test/validation/object/invalid-property-unknown.ts index b52d2479..d00a80c4 100644 --- a/test/validation/object/invalid-property-unknown.ts +++ b/test/validation/object/invalid-property-unknown.ts @@ -1,22 +1,28 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { object, string, number } from '../../../src' -export const Struct = object({ - name: string(), - age: number(), -}) +test("Invalid object property unknown", () => { + const data = { + name: 'john', + age: 42, + unknown: true, + }; -export const data = { - name: 'john', - age: 42, - unknown: true, -} + const [err, res] = validate(data, object({ + name: string(), + age: number(), + })); -export const failures = [ - { - value: true, - type: 'never', - refinement: undefined, - path: ['unknown'], - branch: [data, data.unknown], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: true, + type: 'never', + refinement: undefined, + path: ['unknown'], + branch: [data, data.unknown], + }, + ]); +}); diff --git a/test/validation/object/invalid-property.ts b/test/validation/object/invalid-property.ts index 1c575b99..fa42c259 100644 --- a/test/validation/object/invalid-property.ts +++ b/test/validation/object/invalid-property.ts @@ -1,30 +1,36 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { object, string, number } from '../../../src' -export const Struct = object({ - name: string(), - age: number(), - height: string(), -}) +test("Invalid object property", () => { + const data = { + name: 'john', + age: 'invalid', + height: 2, + }; -export const data = { - name: 'john', - age: 'invalid', - height: 2, -} + const [err, res] = validate(data, object({ + name: string(), + age: number(), + height: string(), + })); -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: ['age'], - branch: [data, data.age], - }, - { - value: 2, - type: 'string', - refinement: undefined, - path: ['height'], - branch: [data, data.height], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: ['age'], + branch: [data, data.age], + }, + { + value: 2, + type: 'string', + refinement: undefined, + path: ['height'], + branch: [data, data.height], + }, + ]); +}); diff --git a/test/validation/object/invalid-referential.ts b/test/validation/object/invalid-referential.ts index de3b745f..6c2ca916 100644 --- a/test/validation/object/invalid-referential.ts +++ b/test/validation/object/invalid-referential.ts @@ -1,27 +1,33 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { object, string, pattern, refine } from '../../../src' const Section = pattern(string(), /^\d+(\.\d+)*$/) -export const Struct = object({ - section: Section, - subsection: refine(Section, 'Subsection', (value, ctx) => { - const { branch } = ctx - const parent = branch[0] - return value.startsWith(`${parent.section}.`) - }), -}) +test("Invalid object referential", () => { + const data = { + section: '1', + subsection: '2.1', + }; -export const data = { - section: '1', - subsection: '2.1', -} + const [err, res] = validate(data, object({ + section: Section, + subsection: refine(Section, 'Subsection', (value, ctx) => { + const { branch } = ctx + const parent = branch[0] + return value.startsWith(`${parent.section}.`) + }), + })); -export const failures = [ - { - value: '2.1', - type: 'string', - refinement: 'Subsection', - path: ['subsection'], - branch: [data, data.subsection], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: '2.1', + type: 'string', + refinement: 'Subsection', + path: ['subsection'], + branch: [data, data.subsection], + }, + ]); +}); diff --git a/test/validation/object/invalid.ts b/test/validation/object/invalid.ts index 05252e82..194960ce 100644 --- a/test/validation/object/invalid.ts +++ b/test/validation/object/invalid.ts @@ -1,18 +1,24 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { object, string, number } from '../../../src' -export const Struct = object({ - name: string(), - age: number(), -}) +test("Invalid object", () => { + const data = 'invalid'; -export const data = 'invalid' + const [err, res] = validate(data, object({ + name: string(), + age: number(), + })); -export const failures = [ - { - value: 'invalid', - type: 'object', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'object', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/object/valid-frozen.ts b/test/validation/object/valid-frozen.ts index 462de9f1..8a0fd91b 100644 --- a/test/validation/object/valid-frozen.ts +++ b/test/validation/object/valid-frozen.ts @@ -1,18 +1,20 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { object, string, number } from '../../../src' -export const Struct = object({ - name: string(), - age: number(), -}) +test("Valid object frozen", () => { + const data = Object.freeze({ + name: 'john', + age: 42, + }); -export const data = Object.freeze({ - name: 'john', - age: 42, -}) + const res = create(data, object({ + name: string(), + age: number(), + })); -export const output = { - name: 'john', - age: 42, -} - -export const create = true + expect(res).toStrictEqual({ + name: 'john', + age: 42, + }); +}); diff --git a/test/validation/object/valid-nested.ts b/test/validation/object/valid-nested.ts index e7c46940..d66d0b46 100644 --- a/test/validation/object/valid-nested.ts +++ b/test/validation/object/valid-nested.ts @@ -1,25 +1,29 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { object, string } from '../../../src' -export const Struct = object({ - name: string(), - address: object({ - street: string(), - city: string(), - }), -}) +test("Valid object nested", () => { + const data = { + name: 'john', + address: { + street: '123 Fake St', + city: 'Springfield', + }, + }; -export const data = { - name: 'john', - address: { - street: '123 Fake St', - city: 'Springfield', - }, -} + assert(data, object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), + })); -export const output = { - name: 'john', - address: { - street: '123 Fake St', - city: 'Springfield', - }, -} + expect(data).toStrictEqual({ + name: 'john', + address: { + street: '123 Fake St', + city: 'Springfield', + }, + }); +}); diff --git a/test/validation/object/valid-opaque.ts b/test/validation/object/valid-opaque.ts index 9240a5bf..5742746a 100644 --- a/test/validation/object/valid-opaque.ts +++ b/test/validation/object/valid-opaque.ts @@ -1,13 +1,17 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { object } from '../../../src' -export const Struct = object() +test("Valid object opaque", () => { + const data = { + a: 'string', + b: 42, + }; -export const data = { - a: 'string', - b: 42, -} + assert(data, object()); -export const output = { - a: 'string', - b: 42, -} + expect(data).toStrictEqual({ + a: 'string', + b: 42, + }); +}); diff --git a/test/validation/object/valid-referential.ts b/test/validation/object/valid-referential.ts index 304dd75d..526d5949 100644 --- a/test/validation/object/valid-referential.ts +++ b/test/validation/object/valid-referential.ts @@ -1,22 +1,26 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { object, string, pattern, refine } from '../../../src' const Section = pattern(string(), /^\d+(\.\d+)*$/) -export const Struct = object({ - section: Section, - subsection: refine(Section, 'Subsection', (value, ctx) => { - const { branch } = ctx - const parent = branch[0] - return value.startsWith(`${parent.section}.`) - }), -}) +test("Valid object referential", () => { + const data = { + section: '1', + subsection: '1.1', + }; -export const data = { - section: '1', - subsection: '1.1', -} + assert(data, object({ + section: Section, + subsection: refine(Section, 'Subsection', (value, ctx) => { + const { branch } = ctx + const parent = branch[0] + return value.startsWith(`${parent.section}.`) + }), + })); -export const output = { - section: '1', - subsection: '1.1', -} + expect(data).toStrictEqual({ + section: '1', + subsection: '1.1', + }); +}); diff --git a/test/validation/object/valid.ts b/test/validation/object/valid.ts index 25833387..2d3e3687 100644 --- a/test/validation/object/valid.ts +++ b/test/validation/object/valid.ts @@ -1,16 +1,20 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { object, string, number } from '../../../src' -export const Struct = object({ - name: string(), - age: number(), -}) +test("Valid object", () => { + const data = { + name: 'john', + age: 42, + }; -export const data = { - name: 'john', - age: 42, -} + assert(data, object({ + name: string(), + age: number(), + })); -export const output = { - name: 'john', - age: 42, -} + expect(data).toStrictEqual({ + name: 'john', + age: 42, + }); +}); diff --git a/test/validation/omit/invalid-element-nested.ts b/test/validation/omit/invalid-element-nested.ts index 55150b66..1e250e0a 100644 --- a/test/validation/omit/invalid-element-nested.ts +++ b/test/validation/omit/invalid-element-nested.ts @@ -1,23 +1,29 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { omit, object, array, string } from '../../../src' -export const Struct = omit( - object({ - name: string(), - emails: array(string()), - }), - ['name'] -) +test("Invalid omit element nested", () => { + const data = { + emails: ['name@example.com', false], + }; -export const data = { - emails: ['name@example.com', false], -} + const [err, res] = validate(data, omit( + object({ + name: string(), + emails: array(string()), + }), + ['name'] + )); -export const failures = [ - { - value: false, - type: 'string', - refinement: undefined, - path: ['emails', 1], - branch: [data, data.emails, data.emails[1]], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: false, + type: 'string', + refinement: undefined, + path: ['emails', 1], + branch: [data, data.emails, data.emails[1]], + }, + ]); +}); diff --git a/test/validation/omit/invalid-property-nested.ts b/test/validation/omit/invalid-property-nested.ts index f4a45115..50006128 100644 --- a/test/validation/omit/invalid-property-nested.ts +++ b/test/validation/omit/invalid-property-nested.ts @@ -1,29 +1,35 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { omit, object, string } from '../../../src' -export const Struct = omit( - object({ - name: string(), - address: object({ - street: string(), - city: string(), +test("Invalid omit property nested", () => { + const data = { + address: { + street: 123, + city: 'Springfield', + }, + }; + + const [err, res] = validate(data, omit( + object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), }), - }), - ['name'] -) + ['name'] + )); -export const data = { - address: { - street: 123, - city: 'Springfield', - }, -} + expect(res).toBeUndefined(); -export const failures = [ - { - value: 123, - type: 'string', - refinement: undefined, - path: ['address', 'street'], - branch: [data, data.address, data.address.street], - }, -] + expect(err).toMatchStructError([ + { + value: 123, + type: 'string', + refinement: undefined, + path: ['address', 'street'], + branch: [data, data.address, data.address.street], + }, + ]); +}); diff --git a/test/validation/omit/invalid-property-unknown.ts b/test/validation/omit/invalid-property-unknown.ts index 055c18e6..d8eb5f54 100644 --- a/test/validation/omit/invalid-property-unknown.ts +++ b/test/validation/omit/invalid-property-unknown.ts @@ -1,24 +1,30 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { omit, object, string, number } from '../../../src' -export const Struct = omit( - object({ - name: string(), - age: number(), - }), - ['age'] -) +test("Invalid omit property unknown", () => { + const data = { + name: 'john', + age: 42, + }; -export const data = { - name: 'john', - age: 42, -} + const [err, res] = validate(data, omit( + object({ + name: string(), + age: number(), + }), + ['age'] + )); -export const failures = [ - { - value: 42, - type: 'never', - refinement: undefined, - path: ['age'], - branch: [data, data.age], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 42, + type: 'never', + refinement: undefined, + path: ['age'], + branch: [data, data.age], + }, + ]); +}); diff --git a/test/validation/omit/invalid-property.ts b/test/validation/omit/invalid-property.ts index ccf7bd11..ab76fbd1 100644 --- a/test/validation/omit/invalid-property.ts +++ b/test/validation/omit/invalid-property.ts @@ -1,23 +1,29 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { omit, object, string, number } from '../../../src' -export const Struct = omit( - object({ - name: string(), - age: number(), - }), - ['name'] -) +test("Invalid omit property", () => { + const data = { + age: 'invalid', + }; -export const data = { - age: 'invalid', -} + const [err, res] = validate(data, omit( + object({ + name: string(), + age: number(), + }), + ['name'] + )); -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: ['age'], - branch: [data, data.age], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: ['age'], + branch: [data, data.age], + }, + ]); +}); diff --git a/test/validation/omit/invalid.ts b/test/validation/omit/invalid.ts index fd9acc54..018bd303 100644 --- a/test/validation/omit/invalid.ts +++ b/test/validation/omit/invalid.ts @@ -1,21 +1,27 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { omit, object, string, number } from '../../../src' -export const Struct = omit( - object({ - name: string(), - age: number(), - }), - ['age'] -) +test("Invalid omit", () => { + const data = 'invalid'; -export const data = 'invalid' + const [err, res] = validate(data, omit( + object({ + name: string(), + age: number(), + }), + ['age'] + )); -export const failures = [ - { - value: 'invalid', - type: 'object', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'object', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/omit/valid-nested.ts b/test/validation/omit/valid-nested.ts index b5e7080a..2a0ca00a 100644 --- a/test/validation/omit/valid-nested.ts +++ b/test/validation/omit/valid-nested.ts @@ -1,26 +1,30 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { omit, object, string } from '../../../src' -export const Struct = omit( - object({ - name: string(), - address: object({ - street: string(), - city: string(), - }), - }), - ['name'] -) +test("Valid omit nested", () => { + const data = { + address: { + street: '123 Fake St', + city: 'Springfield', + }, + }; -export const data = { - address: { - street: '123 Fake St', - city: 'Springfield', - }, -} + assert(data, omit( + object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), + }), + ['name'] + )); -export const output = { - address: { - street: '123 Fake St', - city: 'Springfield', - }, -} + expect(data).toStrictEqual({ + address: { + street: '123 Fake St', + city: 'Springfield', + }, + }); +}); diff --git a/test/validation/omit/valid-type.ts b/test/validation/omit/valid-type.ts index ce7112f4..76fa0536 100644 --- a/test/validation/omit/valid-type.ts +++ b/test/validation/omit/valid-type.ts @@ -1,19 +1,23 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { omit, type, string, number } from '../../../src' -export const Struct = omit( - type({ - name: string(), - age: number(), - }), - ['age'] -) +test("Valid omit type", () => { + const data = { + name: 'john', + unknownProperty: 'unknown', + }; -export const data = { - name: 'john', - unknownProperty: 'unknown', -} + assert(data, omit( + type({ + name: string(), + age: number(), + }), + ['age'] + )); -export const output = { - name: 'john', - unknownProperty: 'unknown', -} + expect(data).toStrictEqual({ + name: 'john', + unknownProperty: 'unknown', + }); +}); diff --git a/test/validation/omit/valid.ts b/test/validation/omit/valid.ts index 45e1e6bf..f9e028bd 100644 --- a/test/validation/omit/valid.ts +++ b/test/validation/omit/valid.ts @@ -1,17 +1,21 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { omit, object, string, number } from '../../../src' -export const Struct = omit( - object({ - name: string(), - age: number(), - }), - ['age'] -) +test("Valid omit", () => { + const data = { + name: 'john', + }; -export const data = { - name: 'john', -} + assert(data, omit( + object({ + name: string(), + age: number(), + }), + ['age'] + )); -export const output = { - name: 'john', -} + expect(data).toStrictEqual({ + name: 'john', + }); +}); diff --git a/test/validation/optional/invalid.ts b/test/validation/optional/invalid.ts index e94d9d82..5340d169 100644 --- a/test/validation/optional/invalid.ts +++ b/test/validation/optional/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { number, optional } from '../../../src' -export const Struct = optional(number()) +test("Invalid optional", () => { + const data = 'invalid'; + const [err, res] = validate(data, optional(number())); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/optional/valid-defined-nested.ts b/test/validation/optional/valid-defined-nested.ts index 69171640..0e007b9b 100644 --- a/test/validation/optional/valid-defined-nested.ts +++ b/test/validation/optional/valid-defined-nested.ts @@ -1,16 +1,20 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { type, string, number, optional } from '../../../src' -export const Struct = type({ - name: optional(string()), - age: number(), -}) +test("Valid optional defined nested", () => { + const data = { + name: 'Jill', + age: 42, + }; -export const data = { - name: 'Jill', - age: 42, -} + assert(data, type({ + name: optional(string()), + age: number(), + })); -export const output = { - name: 'Jill', - age: 42, -} + expect(data).toStrictEqual({ + name: 'Jill', + age: 42, + }); +}); diff --git a/test/validation/optional/valid-defined.ts b/test/validation/optional/valid-defined.ts index 79049904..cdefc40b 100644 --- a/test/validation/optional/valid-defined.ts +++ b/test/validation/optional/valid-defined.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, optional } from '../../../src' -export const Struct = optional(number()) - -export const data = 42 - -export const output = 42 +test("Valid optional defined", () => { + const data = 42; + assert(data, optional(number())); + expect(data).toStrictEqual(42); +}); diff --git a/test/validation/optional/valid-undefined-nested.ts b/test/validation/optional/valid-undefined-nested.ts index d692a4ce..e9bf70c7 100644 --- a/test/validation/optional/valid-undefined-nested.ts +++ b/test/validation/optional/valid-undefined-nested.ts @@ -1,14 +1,18 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { type, string, number, optional } from '../../../src' -export const Struct = type({ - name: optional(string()), - age: number(), -}) +test("Valid optional undefined nested", () => { + const data = { + age: 42, + }; -export const data = { - age: 42, -} + assert(data, type({ + name: optional(string()), + age: number(), + })); -export const output = { - age: 42, -} + expect(data).toStrictEqual({ + age: 42, + }); +}); diff --git a/test/validation/optional/valid-undefined.ts b/test/validation/optional/valid-undefined.ts index 02907cfa..4ad5fa25 100644 --- a/test/validation/optional/valid-undefined.ts +++ b/test/validation/optional/valid-undefined.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, optional } from '../../../src' -export const Struct = optional(number()) - -export const data = undefined - -export const output = undefined +test("Valid optional undefined", () => { + const data = undefined; + assert(data, optional(number())); + expect(data).toStrictEqual(undefined); +}); diff --git a/test/validation/partial/composed.ts b/test/validation/partial/composed.ts index ae5e208d..d68c77e6 100644 --- a/test/validation/partial/composed.ts +++ b/test/validation/partial/composed.ts @@ -1,16 +1,20 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { partial, object, string, number } from '../../../src' -export const Struct = partial( - object({ - name: string(), - age: number(), - }) -) +test("Composed partial", () => { + const data = { + name: 'john', + }; -export const data = { - name: 'john', -} + assert(data, partial( + object({ + name: string(), + age: number(), + }) + )); -export const output = { - name: 'john', -} + expect(data).toStrictEqual({ + name: 'john', + }); +}); diff --git a/test/validation/partial/invalid-property-unknown.ts b/test/validation/partial/invalid-property-unknown.ts index d0063d2d..3d0e4d72 100644 --- a/test/validation/partial/invalid-property-unknown.ts +++ b/test/validation/partial/invalid-property-unknown.ts @@ -1,21 +1,27 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { partial, string, number } from '../../../src' -export const Struct = partial({ - name: string(), - age: number(), -}) +test("Invalid partial property unknown", () => { + const data = { + name: 'john', + unknown: true, + }; -export const data = { - name: 'john', - unknown: true, -} + const [err, res] = validate(data, partial({ + name: string(), + age: number(), + })); -export const failures = [ - { - value: true, - type: 'never', - refinement: undefined, - path: ['unknown'], - branch: [data, data.unknown], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: true, + type: 'never', + refinement: undefined, + path: ['unknown'], + branch: [data, data.unknown], + }, + ]); +}); diff --git a/test/validation/partial/invalid-property.ts b/test/validation/partial/invalid-property.ts index dfe5b391..f73d9185 100644 --- a/test/validation/partial/invalid-property.ts +++ b/test/validation/partial/invalid-property.ts @@ -1,20 +1,26 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { partial, string, number } from '../../../src' -export const Struct = partial({ - name: string(), - age: number(), -}) +test("Invalid partial property", () => { + const data = { + age: 'invalid', + }; -export const data = { - age: 'invalid', -} + const [err, res] = validate(data, partial({ + name: string(), + age: number(), + })); -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: ['age'], - branch: [data, data.age], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: ['age'], + branch: [data, data.age], + }, + ]); +}); diff --git a/test/validation/partial/invalid.ts b/test/validation/partial/invalid.ts index 58d9a1fd..bd65627e 100644 --- a/test/validation/partial/invalid.ts +++ b/test/validation/partial/invalid.ts @@ -1,18 +1,24 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { partial, string, number } from '../../../src' -export const Struct = partial({ - name: string(), - age: number(), -}) +test("Invalid partial", () => { + const data = 'invalid'; -export const data = 'invalid' + const [err, res] = validate(data, partial({ + name: string(), + age: number(), + })); -export const failures = [ - { - value: 'invalid', - type: 'object', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'object', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/partial/valid-empty.ts b/test/validation/partial/valid-empty.ts index d0c47825..84d5c84b 100644 --- a/test/validation/partial/valid-empty.ts +++ b/test/validation/partial/valid-empty.ts @@ -1,10 +1,14 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { partial, string, number } from '../../../src' -export const Struct = partial({ - name: string(), - age: number(), -}) +test("Valid partial empty", () => { + const data = {}; -export const data = {} + assert(data, partial({ + name: string(), + age: number(), + })); -export const output = {} + expect(data).toStrictEqual({}); +}); diff --git a/test/validation/partial/valid-full.ts b/test/validation/partial/valid-full.ts index 0fbf61a2..2cddd090 100644 --- a/test/validation/partial/valid-full.ts +++ b/test/validation/partial/valid-full.ts @@ -1,16 +1,20 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { partial, string, number } from '../../../src' -export const Struct = partial({ - name: string(), - age: number(), -}) +test("Valid partial full", () => { + const data = { + name: 'john', + age: 42, + }; -export const data = { - name: 'john', - age: 42, -} + assert(data, partial({ + name: string(), + age: number(), + })); -export const output = { - name: 'john', - age: 42, -} + expect(data).toStrictEqual({ + name: 'john', + age: 42, + }); +}); diff --git a/test/validation/partial/valid-partial.ts b/test/validation/partial/valid-partial.ts index 81d379d1..8be3450c 100644 --- a/test/validation/partial/valid-partial.ts +++ b/test/validation/partial/valid-partial.ts @@ -1,14 +1,18 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { partial, string, number } from '../../../src' -export const Struct = partial({ - name: string(), - age: number(), -}) +test("Valid partial partial", () => { + const data = { + name: 'john', + }; -export const data = { - name: 'john', -} + assert(data, partial({ + name: string(), + age: number(), + })); -export const output = { - name: 'john', -} + expect(data).toStrictEqual({ + name: 'john', + }); +}); diff --git a/test/validation/partial/valid-type.ts b/test/validation/partial/valid-type.ts index 51411a70..5b1e630e 100644 --- a/test/validation/partial/valid-type.ts +++ b/test/validation/partial/valid-type.ts @@ -1,18 +1,22 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, partial, string, type } from '../../../src' -export const Struct = partial( - type({ - name: string(), - age: number(), - }) -) +test("Valid partial type", () => { + const data = { + name: 'john', + unknownProperty: true, + }; -export const data = { - name: 'john', - unknownProperty: true, -} + assert(data, partial( + type({ + name: string(), + age: number(), + }) + )); -export const output = { - name: 'john', - unknownProperty: true, -} + expect(data).toStrictEqual({ + name: 'john', + unknownProperty: true, + }); +}); diff --git a/test/validation/pattern/invalid.ts b/test/validation/pattern/invalid.ts index cfba4d1c..d5e9f736 100644 --- a/test/validation/pattern/invalid.ts +++ b/test/validation/pattern/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { string, pattern } from '../../../src' -export const Struct = pattern(string(), /\d+/) +test("Invalid pattern", () => { + const data = 'invalid'; + const [err, res] = validate(data, pattern(string(), /\d+/)); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'string', - refinement: 'pattern', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'string', + refinement: 'pattern', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/pattern/valid.ts b/test/validation/pattern/valid.ts index 76181e53..4cb980b7 100644 --- a/test/validation/pattern/valid.ts +++ b/test/validation/pattern/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { string, pattern } from '../../../src' -export const Struct = pattern(string(), /\d+/) - -export const data = '123' - -export const output = '123' +test("Valid pattern", () => { + const data = '123'; + assert(data, pattern(string(), /\d+/)); + expect(data).toStrictEqual('123'); +}); diff --git a/test/validation/pick/invalid-element-nested.ts b/test/validation/pick/invalid-element-nested.ts index 86396d15..4838d09d 100644 --- a/test/validation/pick/invalid-element-nested.ts +++ b/test/validation/pick/invalid-element-nested.ts @@ -1,23 +1,29 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { pick, object, array, string } from '../../../src' -export const Struct = pick( - object({ - name: string(), - emails: array(string()), - }), - ['emails'] -) +test("Invalid pick element nested", () => { + const data = { + emails: ['name@example.com', false], + }; -export const data = { - emails: ['name@example.com', false], -} + const [err, res] = validate(data, pick( + object({ + name: string(), + emails: array(string()), + }), + ['emails'] + )); -export const failures = [ - { - value: false, - type: 'string', - refinement: undefined, - path: ['emails', 1], - branch: [data, data.emails, data.emails[1]], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: false, + type: 'string', + refinement: undefined, + path: ['emails', 1], + branch: [data, data.emails, data.emails[1]], + }, + ]); +}); diff --git a/test/validation/pick/invalid-property-nested.ts b/test/validation/pick/invalid-property-nested.ts index 17400b43..b430175c 100644 --- a/test/validation/pick/invalid-property-nested.ts +++ b/test/validation/pick/invalid-property-nested.ts @@ -1,29 +1,35 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { pick, object, string } from '../../../src' -export const Struct = pick( - object({ - name: string(), - address: object({ - street: string(), - city: string(), +test("Invalid pick property nested", () => { + const data = { + address: { + street: 123, + city: 'Springfield', + }, + }; + + const [err, res] = validate(data, pick( + object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), }), - }), - ['address'] -) + ['address'] + )); -export const data = { - address: { - street: 123, - city: 'Springfield', - }, -} + expect(res).toBeUndefined(); -export const failures = [ - { - value: 123, - type: 'string', - refinement: undefined, - path: ['address', 'street'], - branch: [data, data.address, data.address.street], - }, -] + expect(err).toMatchStructError([ + { + value: 123, + type: 'string', + refinement: undefined, + path: ['address', 'street'], + branch: [data, data.address, data.address.street], + }, + ]); +}); diff --git a/test/validation/pick/invalid-property-unknown.ts b/test/validation/pick/invalid-property-unknown.ts index 173a7f36..f011313b 100644 --- a/test/validation/pick/invalid-property-unknown.ts +++ b/test/validation/pick/invalid-property-unknown.ts @@ -1,24 +1,30 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { pick, object, string, number } from '../../../src' -export const Struct = pick( - object({ - name: string(), - age: number(), - }), - ['name'] -) +test("Invalid pick property unknown", () => { + const data = { + name: 'john', + age: 42, + }; -export const data = { - name: 'john', - age: 42, -} + const [err, res] = validate(data, pick( + object({ + name: string(), + age: number(), + }), + ['name'] + )); -export const failures = [ - { - value: 42, - type: 'never', - refinement: undefined, - path: ['age'], - branch: [data, data.age], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 42, + type: 'never', + refinement: undefined, + path: ['age'], + branch: [data, data.age], + }, + ]); +}); diff --git a/test/validation/pick/invalid-property.ts b/test/validation/pick/invalid-property.ts index 0999bc10..ebab1f0f 100644 --- a/test/validation/pick/invalid-property.ts +++ b/test/validation/pick/invalid-property.ts @@ -1,23 +1,29 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { pick, object, string, number } from '../../../src' -export const Struct = pick( - object({ - name: string(), - age: number(), - }), - ['age'] -) +test("Invalid pick property", () => { + const data = { + age: 'invalid', + }; -export const data = { - age: 'invalid', -} + const [err, res] = validate(data, pick( + object({ + name: string(), + age: number(), + }), + ['age'] + )); -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: ['age'], - branch: [data, data.age], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: ['age'], + branch: [data, data.age], + }, + ]); +}); diff --git a/test/validation/pick/invalid.ts b/test/validation/pick/invalid.ts index 7376027b..e9532c67 100644 --- a/test/validation/pick/invalid.ts +++ b/test/validation/pick/invalid.ts @@ -1,21 +1,27 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { pick, object, string, number } from '../../../src' -export const Struct = pick( - object({ - name: string(), - age: number(), - }), - ['name'] -) +test("Invalid pick", () => { + const data = 'invalid'; -export const data = 'invalid' + const [err, res] = validate(data, pick( + object({ + name: string(), + age: number(), + }), + ['name'] + )); -export const failures = [ - { - value: 'invalid', - type: 'object', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'object', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/pick/valid-nested.ts b/test/validation/pick/valid-nested.ts index 08874b82..95edcd11 100644 --- a/test/validation/pick/valid-nested.ts +++ b/test/validation/pick/valid-nested.ts @@ -1,26 +1,30 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { pick, object, string } from '../../../src' -export const Struct = pick( - object({ - name: string(), - address: object({ - street: string(), - city: string(), - }), - }), - ['address'] -) +test("Valid pick nested", () => { + const data = { + address: { + street: '123 Fake St', + city: 'Springfield', + }, + }; -export const data = { - address: { - street: '123 Fake St', - city: 'Springfield', - }, -} + assert(data, pick( + object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), + }), + ['address'] + )); -export const output = { - address: { - street: '123 Fake St', - city: 'Springfield', - }, -} + expect(data).toStrictEqual({ + address: { + street: '123 Fake St', + city: 'Springfield', + }, + }); +}); diff --git a/test/validation/pick/valid-type.ts b/test/validation/pick/valid-type.ts index 28f1a330..cda58d8c 100644 --- a/test/validation/pick/valid-type.ts +++ b/test/validation/pick/valid-type.ts @@ -1,19 +1,23 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, pick, string, type } from '../../../src' -export const Struct = pick( - type({ - name: string(), - age: number(), - }), - ['name'] -) +test("Valid pick type", () => { + const data = { + name: 'john', + unknownProperty: true, + }; -export const data = { - name: 'john', - unknownProperty: true, -} + assert(data, pick( + type({ + name: string(), + age: number(), + }), + ['name'] + )); -export const output = { - name: 'john', - unknownProperty: true, -} + expect(data).toStrictEqual({ + name: 'john', + unknownProperty: true, + }); +}); diff --git a/test/validation/pick/valid.ts b/test/validation/pick/valid.ts index 64c5a838..cb9c200e 100644 --- a/test/validation/pick/valid.ts +++ b/test/validation/pick/valid.ts @@ -1,17 +1,21 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { pick, object, string, number } from '../../../src' -export const Struct = pick( - object({ - name: string(), - age: number(), - }), - ['name'] -) +test("Valid pick", () => { + const data = { + name: 'john', + }; -export const data = { - name: 'john', -} + assert(data, pick( + object({ + name: string(), + age: number(), + }), + ['name'] + )); -export const output = { - name: 'john', -} + expect(data).toStrictEqual({ + name: 'john', + }); +}); diff --git a/test/validation/record/invalid-array.ts b/test/validation/record/invalid-array.ts index a1e58fc7..c58b913b 100644 --- a/test/validation/record/invalid-array.ts +++ b/test/validation/record/invalid-array.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { record, string, number } from '../../../src' -export const Struct = record(string(), number()) +test("Invalid record array", () => { + const data = []; + const [err, res] = validate(data, record(string(), number())); + expect(res).toBeUndefined(); -export const data = [] - -export const failures = [ - { - value: [], - type: 'record', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: [], + type: 'record', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/record/invalid-property.ts b/test/validation/record/invalid-property.ts index 226b6df9..0e678641 100644 --- a/test/validation/record/invalid-property.ts +++ b/test/validation/record/invalid-property.ts @@ -1,25 +1,30 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { record, string, number } from '../../../src' -export const Struct = record(string(), number()) +test("Invalid record property", () => { + const data = { + a: 'a', + b: 'b', + }; -export const data = { - a: 'a', - b: 'b', -} + const [err, res] = validate(data, record(string(), number())); + expect(res).toBeUndefined(); -export const failures = [ - { - value: 'a', - type: 'number', - refinement: undefined, - path: ['a'], - branch: [data, data.a], - }, - { - value: 'b', - type: 'number', - refinement: undefined, - path: ['b'], - branch: [data, data.b], - }, -] + expect(err).toMatchStructError([ + { + value: 'a', + type: 'number', + refinement: undefined, + path: ['a'], + branch: [data, data.a], + }, + { + value: 'b', + type: 'number', + refinement: undefined, + path: ['b'], + branch: [data, data.b], + }, + ]); +}); diff --git a/test/validation/record/invalid.ts b/test/validation/record/invalid.ts index 13d26fc9..b25f3901 100644 --- a/test/validation/record/invalid.ts +++ b/test/validation/record/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { record, string, number } from '../../../src' -export const Struct = record(string(), number()) +test("Invalid record", () => { + const data = 'invalid'; + const [err, res] = validate(data, record(string(), number())); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'record', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'record', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/record/valid-frozen.ts b/test/validation/record/valid-frozen.ts index 1bb5bd83..26b576c6 100644 --- a/test/validation/record/valid-frozen.ts +++ b/test/validation/record/valid-frozen.ts @@ -1,15 +1,17 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { record, string, number } from '../../../src' -export const Struct = record(string(), number()) +test("Valid record frozen", () => { + const data = Object.freeze({ + a: 1, + b: 2, + }); -export const data = Object.freeze({ - a: 1, - b: 2, -}) + const res = create(data, record(string(), number())); -export const output = { - a: 1, - b: 2, -} - -export const create = true + expect(res).toStrictEqual({ + a: 1, + b: 2, + }); +}); diff --git a/test/validation/record/valid.ts b/test/validation/record/valid.ts index c036d9f1..a2bd4148 100644 --- a/test/validation/record/valid.ts +++ b/test/validation/record/valid.ts @@ -1,13 +1,17 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { record, string, number } from '../../../src' -export const Struct = record(string(), number()) +test("Valid record", () => { + const data = { + a: 1, + b: 2, + }; -export const data = { - a: 1, - b: 2, -} + assert(data, record(string(), number())); -export const output = { - a: 1, - b: 2, -} + expect(data).toStrictEqual({ + a: 1, + b: 2, + }); +}); diff --git a/test/validation/refine/invalid-multiple-refinements.ts b/test/validation/refine/invalid-multiple-refinements.ts index b2ed1933..b75921b0 100644 --- a/test/validation/refine/invalid-multiple-refinements.ts +++ b/test/validation/refine/invalid-multiple-refinements.ts @@ -1,3 +1,5 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { string, refine, object } from '../../../src' const PasswordValidator = refine(string(), 'MinimumLength', (pw) => @@ -8,34 +10,38 @@ const changePasswordStruct = object({ confirmPassword: string(), }) -export const Struct = refine( - changePasswordStruct, - 'PasswordsDoNotMatch', - (values) => { - return values.newPassword === values.confirmPassword - ? true - : 'Passwords do not match' - } -) +test("Invalid refine multiple refinements", () => { + const data = { + newPassword: '1234567', + confirmPassword: '123456789', + }; + + const [err, res] = validate(data, refine( + changePasswordStruct, + 'PasswordsDoNotMatch', + (values) => { + return values.newPassword === values.confirmPassword + ? true + : 'Passwords do not match' + } + )); -export const data = { - newPassword: '1234567', - confirmPassword: '123456789', -} + expect(res).toBeUndefined(); -export const failures = [ - { - value: data.newPassword, - type: 'string', - refinement: 'MinimumLength', - path: ['newPassword'], - branch: [data, data.newPassword], - }, - { - value: data, - type: 'object', - refinement: 'PasswordsDoNotMatch', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: data.newPassword, + type: 'string', + refinement: 'MinimumLength', + path: ['newPassword'], + branch: [data, data.newPassword], + }, + { + value: data, + type: 'object', + refinement: 'PasswordsDoNotMatch', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/refine/invalid-shorthand.ts b/test/validation/refine/invalid-shorthand.ts index 04b2b1b1..a1666569 100644 --- a/test/validation/refine/invalid-shorthand.ts +++ b/test/validation/refine/invalid-shorthand.ts @@ -1,19 +1,25 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { number, refine } from '../../../src' -export const Struct = refine( - number(), - 'positive', - (v) => v > 0 || 'Number was not positive!' -) +test("Invalid refine shorthand", () => { + const data = -1; -export const data = -1 + const [err, res] = validate(data, refine( + number(), + 'positive', + (v) => v > 0 || 'Number was not positive!' + )); -export const failures = [ - { - value: -1, - type: 'number', - refinement: 'positive', - path: [], - branch: [data], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: -1, + type: 'number', + refinement: 'positive', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/refine/invalid.ts b/test/validation/refine/invalid.ts index b7c09141..8ce32e97 100644 --- a/test/validation/refine/invalid.ts +++ b/test/validation/refine/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { string, refine } from '../../../src' -export const Struct = refine(string(), 'email', (value) => value.includes('@')) +test("Invalid refine", () => { + const data = 'invalid'; + const [err, res] = validate(data, refine(string(), 'email', (value) => value.includes('@'))); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'string', - refinement: 'email', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'string', + refinement: 'email', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/refine/valid.ts b/test/validation/refine/valid.ts index d9a74c77..cdc47f06 100644 --- a/test/validation/refine/valid.ts +++ b/test/validation/refine/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { string, refine } from '../../../src' -export const Struct = refine(string(), 'email', (value) => value.includes('@')) - -export const data = 'name@example.com' - -export const output = 'name@example.com' +test("Valid refine", () => { + const data = 'name@example.com'; + assert(data, refine(string(), 'email', (value) => value.includes('@'))); + expect(data).toStrictEqual('name@example.com'); +}); diff --git a/test/validation/regexp/invalid.ts b/test/validation/regexp/invalid.ts index d0207cd4..1587a057 100644 --- a/test/validation/regexp/invalid.ts +++ b/test/validation/regexp/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { regexp } from '../../../src' -export const Struct = regexp() +test("Invalid regexp", () => { + const data = 'invalid'; + const [err, res] = validate(data, regexp()); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'regexp', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'regexp', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/regexp/valid.ts b/test/validation/regexp/valid.ts index 96daf68b..c7995257 100644 --- a/test/validation/regexp/valid.ts +++ b/test/validation/regexp/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { regexp } from '../../../src' -export const Struct = regexp() - -export const data = /./ - -export const output = data +test("Valid regexp", () => { + const data = /./; + assert(data, regexp()); + expect(data).toStrictEqual(data); +}); diff --git a/test/validation/set/invalid-element.ts b/test/validation/set/invalid-element.ts index 2b475cbd..f6a611d8 100644 --- a/test/validation/set/invalid-element.ts +++ b/test/validation/set/invalid-element.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { set, number } from '../../../src' -export const Struct = set(number()) +test("Invalid set element", () => { + const data = new Set([1, 'b', 3]); + const [err, res] = validate(data, set(number())); + expect(res).toBeUndefined(); -export const data = new Set([1, 'b', 3]) - -export const failures = [ - { - value: 'b', - type: 'number', - refinement: undefined, - path: ['b'], - branch: [data, 'b'], - }, -] + expect(err).toMatchStructError([ + { + value: 'b', + type: 'number', + refinement: undefined, + path: ['b'], + branch: [data, 'b'], + }, + ]); +}); diff --git a/test/validation/set/invalid-opaque.ts b/test/validation/set/invalid-opaque.ts index fa2e3991..66877cfd 100644 --- a/test/validation/set/invalid-opaque.ts +++ b/test/validation/set/invalid-opaque.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { set } from '../../../src' -export const Struct = set() +test("Invalid set opaque", () => { + const data = 'invalid'; + const [err, res] = validate(data, set()); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'set', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'set', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/set/invalid.ts b/test/validation/set/invalid.ts index 68edca5f..09afeabd 100644 --- a/test/validation/set/invalid.ts +++ b/test/validation/set/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { set, number } from '../../../src' -export const Struct = set(number()) +test("Invalid set", () => { + const data = 'invalid'; + const [err, res] = validate(data, set(number())); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'set', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'set', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/set/valid-opaque.ts b/test/validation/set/valid-opaque.ts index 5722178d..d5f2f9c4 100644 --- a/test/validation/set/valid-opaque.ts +++ b/test/validation/set/valid-opaque.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { set } from '../../../src' -export const Struct = set() - -export const data = new Set(['a', 2, true]) - -export const output = new Set(['a', 2, true]) +test("Valid set opaque", () => { + const data = new Set(['a', 2, true]); + assert(data, set()); + expect(data).toStrictEqual(new Set(['a', 2, true])); +}); diff --git a/test/validation/set/valid.ts b/test/validation/set/valid.ts index 77ab5978..ccec0575 100644 --- a/test/validation/set/valid.ts +++ b/test/validation/set/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { set, number } from '../../../src' -export const Struct = set(number()) - -export const data = new Set([1, 2, 3]) - -export const output = new Set([1, 2, 3]) +test("Valid set", () => { + const data = new Set([1, 2, 3]); + assert(data, set(number())); + expect(data).toStrictEqual(new Set([1, 2, 3])); +}); diff --git a/test/validation/size/invalid-array.ts b/test/validation/size/invalid-array.ts index b16d9479..36cd6d66 100644 --- a/test/validation/size/invalid-array.ts +++ b/test/validation/size/invalid-array.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { array, size, number } from '../../../src' -export const Struct = size(array(number()), 1, 5) +test("Invalid size array", () => { + const data = []; + const [err, res] = validate(data, size(array(number()), 1, 5)); + expect(res).toBeUndefined(); -export const data = [] - -export const failures = [ - { - value: [], - type: 'array', - refinement: 'size', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: [], + type: 'array', + refinement: 'size', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/size/invalid-map.ts b/test/validation/size/invalid-map.ts index 9fd5c1d8..a454313c 100644 --- a/test/validation/size/invalid-map.ts +++ b/test/validation/size/invalid-map.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { map, size, number, string } from '../../../src' -export const Struct = size(map(number(), string()), 1, 5) +test("Invalid size map", () => { + const data = new Map(); + const [err, res] = validate(data, size(map(number(), string()), 1, 5)); + expect(res).toBeUndefined(); -export const data = new Map() - -export const failures = [ - { - value: data, - type: 'map', - refinement: 'size', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: data, + type: 'map', + refinement: 'size', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/size/invalid-number.ts b/test/validation/size/invalid-number.ts index 9cf861c6..ba4c32bc 100644 --- a/test/validation/size/invalid-number.ts +++ b/test/validation/size/invalid-number.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { number, size } from '../../../src' -export const Struct = size(number(), 1, 5) +test("Invalid size number", () => { + const data = 0; + const [err, res] = validate(data, size(number(), 1, 5)); + expect(res).toBeUndefined(); -export const data = 0 - -export const failures = [ - { - value: 0, - type: 'number', - refinement: 'size', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 0, + type: 'number', + refinement: 'size', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/size/invalid-set.ts b/test/validation/size/invalid-set.ts index 0aab53c0..b7880113 100644 --- a/test/validation/size/invalid-set.ts +++ b/test/validation/size/invalid-set.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { set, size, number } from '../../../src' -export const Struct = size(set(number()), 1, 5) +test("Invalid size set", () => { + const data = new Set(); + const [err, res] = validate(data, size(set(number()), 1, 5)); + expect(res).toBeUndefined(); -export const data = new Set() - -export const failures = [ - { - value: data, - type: 'set', - refinement: 'size', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: data, + type: 'set', + refinement: 'size', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/size/invalid-string.ts b/test/validation/size/invalid-string.ts index af9b29ca..47cc2b6e 100644 --- a/test/validation/size/invalid-string.ts +++ b/test/validation/size/invalid-string.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { string, size } from '../../../src' -export const Struct = size(string(), 1, 5) +test("Invalid size string", () => { + const data = ''; + const [err, res] = validate(data, size(string(), 1, 5)); + expect(res).toBeUndefined(); -export const data = '' - -export const failures = [ - { - value: '', - type: 'string', - refinement: 'size', - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: '', + type: 'string', + refinement: 'size', + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/size/valid-array.ts b/test/validation/size/valid-array.ts index ed20ca2d..68845241 100644 --- a/test/validation/size/valid-array.ts +++ b/test/validation/size/valid-array.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, array, size } from '../../../src' -export const Struct = size(array(number()), 1, 5) - -export const data = [1, 2, 3] - -export const output = [1, 2, 3] +test("Valid size array", () => { + const data = [1, 2, 3]; + assert(data, size(array(number()), 1, 5)); + expect(data).toStrictEqual([1, 2, 3]); +}); diff --git a/test/validation/size/valid-exact.ts b/test/validation/size/valid-exact.ts index 55c9d74f..378045c2 100644 --- a/test/validation/size/valid-exact.ts +++ b/test/validation/size/valid-exact.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { string, size } from '../../../src' -export const Struct = size(string(), 4) - -export const data = 'abcd' - -export const output = 'abcd' +test("Valid size exact", () => { + const data = 'abcd'; + assert(data, size(string(), 4)); + expect(data).toStrictEqual('abcd'); +}); diff --git a/test/validation/size/valid-map.ts b/test/validation/size/valid-map.ts index 84e0cbed..dfbbe32c 100644 --- a/test/validation/size/valid-map.ts +++ b/test/validation/size/valid-map.ts @@ -1,11 +1,14 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { string, number, map, size } from '../../../src' -export const Struct = size(map(number(), string()), 1, 5) +test("Valid size map", () => { + const data = new Map([ + [1, 'a'], + [2, 'b'], + [3, 'c'], + ]); -export const data = new Map([ - [1, 'a'], - [2, 'b'], - [3, 'c'], -]) - -export const output = data + assert(data, size(map(number(), string()), 1, 5)); + expect(data).toStrictEqual(data); +}); diff --git a/test/validation/size/valid-max-inclusive.ts b/test/validation/size/valid-max-inclusive.ts index 1680ff65..f630690e 100644 --- a/test/validation/size/valid-max-inclusive.ts +++ b/test/validation/size/valid-max-inclusive.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { string, size } from '../../../src' -export const Struct = size(string(), 1, 5) - -export const data = 'abcde' - -export const output = 'abcde' +test("Valid size max inclusive", () => { + const data = 'abcde'; + assert(data, size(string(), 1, 5)); + expect(data).toStrictEqual('abcde'); +}); diff --git a/test/validation/size/valid-min-inclusive.ts b/test/validation/size/valid-min-inclusive.ts index 4492590b..28204bda 100644 --- a/test/validation/size/valid-min-inclusive.ts +++ b/test/validation/size/valid-min-inclusive.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { string, size } from '../../../src' -export const Struct = size(string(), 1, 5) - -export const data = 'a' - -export const output = 'a' +test("Valid size min inclusive", () => { + const data = 'a'; + assert(data, size(string(), 1, 5)); + expect(data).toStrictEqual('a'); +}); diff --git a/test/validation/size/valid-number.ts b/test/validation/size/valid-number.ts index 9a51e63d..7acec38d 100644 --- a/test/validation/size/valid-number.ts +++ b/test/validation/size/valid-number.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, size } from '../../../src' -export const Struct = size(number(), 1, 5) - -export const data = 3 - -export const output = 3 +test("Valid size number", () => { + const data = 3; + assert(data, size(number(), 1, 5)); + expect(data).toStrictEqual(3); +}); diff --git a/test/validation/size/valid-set.ts b/test/validation/size/valid-set.ts index ba2eb6d1..a88b5954 100644 --- a/test/validation/size/valid-set.ts +++ b/test/validation/size/valid-set.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { number, set, size } from '../../../src' -export const Struct = size(set(number()), 1, 5) - -export const data = new Set([1, 2, 3]) - -export const output = data +test("Valid size set", () => { + const data = new Set([1, 2, 3]); + assert(data, size(set(number()), 1, 5)); + expect(data).toStrictEqual(data); +}); diff --git a/test/validation/size/valid-string.ts b/test/validation/size/valid-string.ts index 24f8fcab..ba4e216a 100644 --- a/test/validation/size/valid-string.ts +++ b/test/validation/size/valid-string.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { string, size } from '../../../src' -export const Struct = size(string(), 1, 5) - -export const data = 'two' - -export const output = 'two' +test("Valid size string", () => { + const data = 'two'; + assert(data, size(string(), 1, 5)); + expect(data).toStrictEqual('two'); +}); diff --git a/test/validation/string/invalid.ts b/test/validation/string/invalid.ts index 16634387..67989637 100644 --- a/test/validation/string/invalid.ts +++ b/test/validation/string/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { string } from '../../../src' -export const Struct = string() +test("Invalid string", () => { + const data = false; + const [err, res] = validate(data, string()); + expect(res).toBeUndefined(); -export const data = false - -export const failures = [ - { - value: false, - type: 'string', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: false, + type: 'string', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/string/valid.ts b/test/validation/string/valid.ts index afc40fac..7c3c6858 100644 --- a/test/validation/string/valid.ts +++ b/test/validation/string/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { string } from '../../../src' -export const Struct = string() - -export const data = 'valid' - -export const output = 'valid' +test("Valid string", () => { + const data = 'valid'; + assert(data, string()); + expect(data).toStrictEqual('valid'); +}); diff --git a/test/validation/trimmed/invalid.ts b/test/validation/trimmed/invalid.ts index 891ff35a..9870599a 100644 --- a/test/validation/trimmed/invalid.ts +++ b/test/validation/trimmed/invalid.ts @@ -1,17 +1,23 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { string, trimmed } from '../../../src' -export const Struct = trimmed(string()) +test("Invalid trimmed", () => { + const data = false; -export const data = false + const [err, res] = validate(data, trimmed(string()), { + coerce: true + }); -export const failures = [ - { - value: false, - type: 'string', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(res).toBeUndefined(); -export const create = true + expect(err).toMatchStructError([ + { + value: false, + type: 'string', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/trimmed/valid.ts b/test/validation/trimmed/valid.ts index b6815382..39c19514 100644 --- a/test/validation/trimmed/valid.ts +++ b/test/validation/trimmed/valid.ts @@ -1,9 +1,9 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { string, trimmed } from '../../../src' -export const Struct = trimmed(string()) - -export const data = ' valid ' - -export const output = 'valid' - -export const create = true +test("Valid trimmed", () => { + const data = ' valid '; + const res = create(data, trimmed(string())); + expect(res).toStrictEqual('valid'); +}); diff --git a/test/validation/tuple/invalid-element-missing.ts b/test/validation/tuple/invalid-element-missing.ts index 48ca2e3c..95dcf873 100644 --- a/test/validation/tuple/invalid-element-missing.ts +++ b/test/validation/tuple/invalid-element-missing.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { tuple, string, number } from '../../../src' -export const Struct = tuple([string(), number()]) +test("Invalid tuple element missing", () => { + const data = ['A']; + const [err, res] = validate(data, tuple([string(), number()])); + expect(res).toBeUndefined(); -export const data = ['A'] - -export const failures = [ - { - value: undefined, - type: 'number', - refinement: undefined, - path: [1], - branch: [data, data[1]], - }, -] + expect(err).toMatchStructError([ + { + value: undefined, + type: 'number', + refinement: undefined, + path: [1], + branch: [data, data[1]], + }, + ]); +}); diff --git a/test/validation/tuple/invalid-element-unknown.ts b/test/validation/tuple/invalid-element-unknown.ts index ab6afcf7..32cdef2d 100644 --- a/test/validation/tuple/invalid-element-unknown.ts +++ b/test/validation/tuple/invalid-element-unknown.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { tuple, string, number } from '../../../src' -export const Struct = tuple([string(), number()]) +test("Invalid tuple element unknown", () => { + const data = ['A', 3, 'unknown']; + const [err, res] = validate(data, tuple([string(), number()])); + expect(res).toBeUndefined(); -export const data = ['A', 3, 'unknown'] - -export const failures = [ - { - value: 'unknown', - type: 'never', - refinement: undefined, - path: [2], - branch: [data, data[2]], - }, -] + expect(err).toMatchStructError([ + { + value: 'unknown', + type: 'never', + refinement: undefined, + path: [2], + branch: [data, data[2]], + }, + ]); +}); diff --git a/test/validation/tuple/invalid-element.ts b/test/validation/tuple/invalid-element.ts index 696c43a3..2cecf0ce 100644 --- a/test/validation/tuple/invalid-element.ts +++ b/test/validation/tuple/invalid-element.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { tuple, string, number } from '../../../src' -export const Struct = tuple([string(), number()]) +test("Invalid tuple element", () => { + const data = [false, 3]; + const [err, res] = validate(data, tuple([string(), number()])); + expect(res).toBeUndefined(); -export const data = [false, 3] - -export const failures = [ - { - value: false, - type: 'string', - refinement: undefined, - path: [0], - branch: [data, data[0]], - }, -] + expect(err).toMatchStructError([ + { + value: false, + type: 'string', + refinement: undefined, + path: [0], + branch: [data, data[0]], + }, + ]); +}); diff --git a/test/validation/tuple/invalid.ts b/test/validation/tuple/invalid.ts index f03c711a..ab304a04 100644 --- a/test/validation/tuple/invalid.ts +++ b/test/validation/tuple/invalid.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { tuple, string, number } from '../../../src' -export const Struct = tuple([string(), number()]) +test("Invalid tuple", () => { + const data = 'invalid'; + const [err, res] = validate(data, tuple([string(), number()])); + expect(res).toBeUndefined(); -export const data = 'invalid' - -export const failures = [ - { - value: 'invalid', - type: 'tuple', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'tuple', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/tuple/valid-frozen.ts b/test/validation/tuple/valid-frozen.ts index b084af38..40d18417 100644 --- a/test/validation/tuple/valid-frozen.ts +++ b/test/validation/tuple/valid-frozen.ts @@ -1,9 +1,9 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { tuple, string, number } from '../../../src' -export const Struct = tuple([string(), number()]) - -export const data = Object.freeze(['A', 1]) - -export const output = ['A', 1] - -export const create = true +test("Valid tuple frozen", () => { + const data = Object.freeze(['A', 1]); + const res = create(data, tuple([string(), number()])); + expect(res).toStrictEqual(['A', 1]); +}); diff --git a/test/validation/tuple/valid.ts b/test/validation/tuple/valid.ts index 3c0d8397..60771633 100644 --- a/test/validation/tuple/valid.ts +++ b/test/validation/tuple/valid.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { tuple, string, number } from '../../../src' -export const Struct = tuple([string(), number()]) - -export const data = ['A', 1] - -export const output = ['A', 1] +test("Valid tuple", () => { + const data = ['A', 1]; + assert(data, tuple([string(), number()])); + expect(data).toStrictEqual(['A', 1]); +}); diff --git a/test/validation/type/invalid-array.ts b/test/validation/type/invalid-array.ts index a0ec3972..4c2a35ab 100644 --- a/test/validation/type/invalid-array.ts +++ b/test/validation/type/invalid-array.ts @@ -1,15 +1,19 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { type } from '../../../src' -export const Struct = type({}) +test("Invalid type array", () => { + const data = []; + const [err, res] = validate(data, type({})); + expect(res).toBeUndefined(); -export const data = [] - -export const failures = [ - { - value: [], - type: 'type', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(err).toMatchStructError([ + { + value: [], + type: 'type', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/type/invalid-property-nested.ts b/test/validation/type/invalid-property-nested.ts index ee4cd218..59181a94 100644 --- a/test/validation/type/invalid-property-nested.ts +++ b/test/validation/type/invalid-property-nested.ts @@ -1,23 +1,29 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { type, string, number } from '../../../src' -export const Struct = type({ - id: number(), - person: type({ - name: string(), - age: number(), - }), -}) +test("Invalid type property nested", () => { + const data = { + id: 1, + }; -export const data = { - id: 1, -} + const [err, res] = validate(data, type({ + id: number(), + person: type({ + name: string(), + age: number(), + }), + })); -export const failures = [ - { - value: undefined, - type: 'type', - refinement: undefined, - path: ['person'], - branch: [data, undefined], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: undefined, + type: 'type', + refinement: undefined, + path: ['person'], + branch: [data, undefined], + }, + ]); +}); diff --git a/test/validation/type/invalid-property.ts b/test/validation/type/invalid-property.ts index 21cf52f3..48a33045 100644 --- a/test/validation/type/invalid-property.ts +++ b/test/validation/type/invalid-property.ts @@ -1,21 +1,27 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { type, string, number } from '../../../src' -export const Struct = type({ - name: string(), - age: number(), -}) +test("Invalid type property", () => { + const data = { + name: 'john', + age: 'invalid', + }; -export const data = { - name: 'john', - age: 'invalid', -} + const [err, res] = validate(data, type({ + name: string(), + age: number(), + })); -export const failures = [ - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: ['age'], - branch: [data, data.age], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: ['age'], + branch: [data, data.age], + }, + ]); +}); diff --git a/test/validation/type/invalid.ts b/test/validation/type/invalid.ts index b44b251f..23f355ba 100644 --- a/test/validation/type/invalid.ts +++ b/test/validation/type/invalid.ts @@ -1,18 +1,24 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { type, string, number } from '../../../src' -export const Struct = type({ - name: string(), - age: number(), -}) +test("Invalid type", () => { + const data = 'invalid'; -export const data = 'invalid' + const [err, res] = validate(data, type({ + name: string(), + age: number(), + })); -export const failures = [ - { - value: 'invalid', - type: 'type', - refinement: undefined, - path: [], - branch: [data], - }, -] + expect(res).toBeUndefined(); + + expect(err).toMatchStructError([ + { + value: 'invalid', + type: 'type', + refinement: undefined, + path: [], + branch: [data], + }, + ]); +}); diff --git a/test/validation/type/valid-frozen.ts b/test/validation/type/valid-frozen.ts index cdb08dbc..d8a6b670 100644 --- a/test/validation/type/valid-frozen.ts +++ b/test/validation/type/valid-frozen.ts @@ -1,18 +1,20 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { type, string, number } from '../../../src' -export const Struct = type({ - name: string(), - age: number(), -}) +test("Valid type frozen", () => { + const data = Object.freeze({ + name: 'john', + age: 42, + }); -export const data = Object.freeze({ - name: 'john', - age: 42, -}) + const res = create(data, type({ + name: string(), + age: number(), + })); -export const output = { - name: 'john', - age: 42, -} - -export const create = true + expect(res).toStrictEqual({ + name: 'john', + age: 42, + }); +}); diff --git a/test/validation/type/valid-instance.ts b/test/validation/type/valid-instance.ts index ad586db1..ea181c17 100644 --- a/test/validation/type/valid-instance.ts +++ b/test/validation/type/valid-instance.ts @@ -1,3 +1,5 @@ +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, string } from '../../../src' class Person { @@ -8,10 +10,15 @@ class Person { } } -export const Struct = type({ - name: string(), -}) +test('Valid type', () => { + const data = new Person('john') -export const data = new Person('john') + assert( + data, + type({ + name: string(), + }) + ) -export const output = data + expect(data).toStrictEqual(new Person('john')) +}) diff --git a/test/validation/type/valid.ts b/test/validation/type/valid.ts index 95315fde..00d0ee11 100644 --- a/test/validation/type/valid.ts +++ b/test/validation/type/valid.ts @@ -1,13 +1,17 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { type, string, number } from '../../../src' -export const Struct = type({ - name: string(), - age: number(), -}) +test("Valid type", () => { + const data = { + name: 'john', + age: 42, + }; -export const data = { - name: 'john', - age: 42, -} + assert(data, type({ + name: string(), + age: number(), + })); -export const output = data + expect(data).toStrictEqual(data); +}); diff --git a/test/validation/union/coercion-object.ts b/test/validation/union/coercion-object.ts index 2d08f7e5..f0d825c5 100644 --- a/test/validation/union/coercion-object.ts +++ b/test/validation/union/coercion-object.ts @@ -1,12 +1,12 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { union, string, number, defaulted, object } from '../../../src' const A = string() const B = object({ a: number(), b: defaulted(number(), 5) }) -export const Struct = union([A, B]) - -export const data = { a: 5 } - -export const output = { a: 5, b: 5 } - -export const create = true +test("Coercion union object", () => { + const data = { a: 5 }; + const res = create(data, union([A, B])); + expect(res).toStrictEqual({ a: 5, b: 5 }); +}); diff --git a/test/validation/union/coercion-type.ts b/test/validation/union/coercion-type.ts index 8dd25517..6c6bf800 100644 --- a/test/validation/union/coercion-type.ts +++ b/test/validation/union/coercion-type.ts @@ -1,12 +1,12 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { union, string, number, defaulted, type } from '../../../src' const A = string() const B = type({ a: number(), b: defaulted(number(), 5) }) -export const Struct = union([A, B]) - -export const data = { a: 5 } - -export const output = { a: 5, b: 5 } - -export const create = true +test("Coercion union type", () => { + const data = { a: 5 }; + const res = create(data, union([A, B])); + expect(res).toStrictEqual({ a: 5, b: 5 }); +}); diff --git a/test/validation/union/coercion.ts b/test/validation/union/coercion.ts index dd7a108f..cd616770 100644 --- a/test/validation/union/coercion.ts +++ b/test/validation/union/coercion.ts @@ -1,12 +1,12 @@ +import { create } from "../../../src"; +import { expect, test } from "vitest"; import { union, string, number, defaulted } from '../../../src' const A = defaulted(string(), 'foo') const B = number() -export const Struct = union([A, B]) - -export const data = undefined - -export const output = 'foo' - -export const create = true +test("Coercion union", () => { + const data = undefined; + const res = create(data, union([A, B])); + expect(res).toStrictEqual('foo'); +}); diff --git a/test/validation/union/invalid.ts b/test/validation/union/invalid.ts index ddb5bd8d..015a48c7 100644 --- a/test/validation/union/invalid.ts +++ b/test/validation/union/invalid.ts @@ -1,34 +1,39 @@ +import { validate } from "../../../src"; +import { expect, test } from "vitest"; import { type, union, string, number } from '../../../src' const A = type({ a: string() }) const B = type({ b: number() }) -export const Struct = union([A, B]) +test("Invalid union", () => { + const data = { + b: 'invalid', + }; -export const data = { - b: 'invalid', -} + const [err, res] = validate(data, union([A, B])); + expect(res).toBeUndefined(); -export const failures = [ - { - value: { b: 'invalid' }, - type: 'union', - refinement: undefined, - path: [], - branch: [data], - }, - { - value: undefined, - type: 'string', - refinement: undefined, - path: ['a'], - branch: [data, undefined], - }, - { - value: 'invalid', - type: 'number', - refinement: undefined, - path: ['b'], - branch: [data, data.b], - }, -] + expect(err).toMatchStructError([ + { + value: { b: 'invalid' }, + type: 'union', + refinement: undefined, + path: [], + branch: [data], + }, + { + value: undefined, + type: 'string', + refinement: undefined, + path: ['a'], + branch: [data, undefined], + }, + { + value: 'invalid', + type: 'number', + refinement: undefined, + path: ['b'], + branch: [data, data.b], + }, + ]); +}); diff --git a/test/validation/union/valid.ts b/test/validation/union/valid.ts index ef84c887..ed9faa58 100644 --- a/test/validation/union/valid.ts +++ b/test/validation/union/valid.ts @@ -1,14 +1,18 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { type, union, string, number } from '../../../src' const A = type({ a: string() }) const B = type({ b: number() }) -export const Struct = union([A, B]) +test("Valid union", () => { + const data = { + a: 'a', + }; -export const data = { - a: 'a', -} + assert(data, union([A, B])); -export const output = { - a: 'a', -} + expect(data).toStrictEqual({ + a: 'a', + }); +}); diff --git a/test/validation/unknown/valid-number.ts b/test/validation/unknown/valid-number.ts index 9238214a..98268cfb 100644 --- a/test/validation/unknown/valid-number.ts +++ b/test/validation/unknown/valid-number.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { unknown } from '../../../src' -export const Struct = unknown() - -export const data = 1 - -export const output = 1 +test("Valid unknown number", () => { + const data = 1; + assert(data, unknown()); + expect(data).toStrictEqual(1); +}); diff --git a/test/validation/unknown/valid-string.ts b/test/validation/unknown/valid-string.ts index 7e82b944..67c5edc9 100644 --- a/test/validation/unknown/valid-string.ts +++ b/test/validation/unknown/valid-string.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { unknown } from '../../../src' -export const Struct = unknown() - -export const data = 'valid' - -export const output = 'valid' +test("Valid unknown string", () => { + const data = 'valid'; + assert(data, unknown()); + expect(data).toStrictEqual('valid'); +}); diff --git a/test/validation/unknown/valid-undefined.ts b/test/validation/unknown/valid-undefined.ts index d90f1439..7e658da6 100644 --- a/test/validation/unknown/valid-undefined.ts +++ b/test/validation/unknown/valid-undefined.ts @@ -1,7 +1,9 @@ +import { assert } from "../../../src"; +import { expect, test } from "vitest"; import { unknown } from '../../../src' -export const Struct = unknown() - -export const data = undefined - -export const output = undefined +test("Valid unknown undefined", () => { + const data = undefined; + assert(data, unknown()); + expect(data).toStrictEqual(undefined); +}); diff --git a/transform.cjs b/transform.cjs new file mode 100644 index 00000000..dde47149 --- /dev/null +++ b/transform.cjs @@ -0,0 +1,293 @@ +export default function transformer(file, api) { + const j = api.jscodeshift + const root = j(file.source) + + const variablesToFind = ['Struct', 'data', 'output', 'create', 'failures'] + + let assertOrCreate = 'assert' // Default to "assert" + let dataDeclaration = null + let structExpression = null + let failureValue = null + let createValue = null + let outputValue = null + + // Define import specifiers + const expectSpecifier = j.importSpecifier(j.identifier('expect')) + const itSpecifier = j.importSpecifier(j.identifier('test')) + const validateSpecifier = j.importSpecifier(j.identifier('validate')) + + // Define import declarations + const vitestImportDeclaration = j.importDeclaration( + [expectSpecifier, itSpecifier], + j.literal('vitest') + ) + + // Find existing import declarations + const existingImports = root.find(j.ImportDeclaration) + + // Handle import for vitest + const hasVitestImport = existingImports + .nodes() + .some( + (importDecl) => + importDecl.source.value === 'vitest' && + importDecl.specifiers.some( + (specifier) => + specifier.imported.name === 'expect' || + specifier.imported.name === 'test' + ) + ) + + if (!hasVitestImport) { + // Add the new import declaration for `vitest` to the top of the file + root.find(j.Program).get('body', 0).insertBefore(vitestImportDeclaration) + } + + // Handle import for "../../../src" + const srcImport = existingImports.find(j.ImportDeclaration, { + source: { value: '../../../src' }, + }) + + // Iterate over the identifiers to find the relevant ones + root.find(j.VariableDeclarator).forEach((path) => { + const name = path.node.id.name + + if (variablesToFind.includes(name)) { + if (name === 'create') { + createValue = path.node.init + if ( + createValue && + createValue.type === 'Literal' && + createValue.value === true + ) { + assertOrCreate = 'create' + } + } else if (name === 'data') { + // Save the entire data variable declaration + dataDeclaration = j.variableDeclaration('const', [ + j.variableDeclarator(path.node.id, path.node.init), + ]) + } else if (name === 'Struct') { + structExpression = path.node.init // Use the expression directly + } else if (name === 'failures') { + failureValue = path.node.init // Use the expression directly + } else if (name === 'output') { + outputValue = path.node.init // Use the expression directly + } + } + }) + + if (failureValue !== null) { + if (srcImport.length > 0) { + // Add `validate` to the existing import declaration + srcImport.forEach((importDecl) => { + if ( + !importDecl.node.specifiers.some( + (specifier) => specifier.imported.name === 'validate' + ) + ) { + importDecl.node.specifiers.push(validateSpecifier) + } + }) + } else { + // Optionally handle the case where the import statement does not exist + // Here you can choose to add a new import declaration for `validate` if needed + const newSrcImportDeclaration = j.importDeclaration( + [validateSpecifier], + j.literal('../../../src') + ) + // Add the new import declaration to the top of the file + root.find(j.Program).get('body', 0).insertBefore(newSrcImportDeclaration) + } + } else if (srcImport.length > 0) { + // Add `validate` to the existing import declaration + srcImport.forEach((importDecl) => { + if ( + !importDecl.node.specifiers.some( + (specifier) => specifier.imported.name === assertOrCreate + ) + ) { + importDecl.node.specifiers.push( + j.importSpecifier(j.identifier(assertOrCreate)) + ) + } + }) + } else { + // Optionally handle the case where the import statement does not exist + // Here you can choose to add a new import declaration for `validate` if needed + const newSrcImportDeclaration = j.importDeclaration( + [j.importSpecifier(j.identifier(assertOrCreate))], + j.literal('../../../src') + ) + // Add the new import declaration to the top of the file + root.find(j.Program).get('body', 0).insertBefore(newSrcImportDeclaration) + } + + // Remove the original data declaration from the root + if (dataDeclaration) { + root + .find(j.VariableDeclaration) + .filter((path) => + path.node.declarations.some((decl) => decl.id.name === 'data') + ) + .remove() + } + + // Remove the original Struct declaration from the root + if (createValue) { + root + .find(j.VariableDeclaration) + .filter((path) => + path.node.declarations.some((decl) => decl.id.name === 'create') + ) + .remove() + } + + // Remove the original Struct declaration from the root + if (structExpression) { + root + .find(j.VariableDeclaration) + .filter((path) => + path.node.declarations.some((decl) => decl.id.name === 'Struct') + ) + .remove() + } + + // Remove the original Struct declaration from the root + if (outputValue) { + root + .find(j.VariableDeclaration) + .filter((path) => + path.node.declarations.some((decl) => decl.id.name === 'output') + ) + .remove() + } + + // Remove the original Struct declaration from the root + if (failureValue) { + root + .find(j.VariableDeclaration) + .filter((path) => + path.node.declarations.some((decl) => decl.id.name === 'failures') + ) + .remove() + } + + // Remove empty export statements + root + .find(j.ExportNamedDeclaration) + .filter((path) => path.node.specifiers.length === 0) + .remove() + + const validateOptions = j.objectExpression([ + j.property('init', j.identifier('coerce'), j.literal(true)), + ]) + + // Convert the filename to the test name + const fileName = file.path + .replace(/.*\/|\.ts$/g, '') // Remove the path and file extension + .toLowerCase() + + const path = file.path.split('/') // Extract the folder name + const folderName = path[path.length - 2] + + const testName = fileName.toLowerCase().replace('-', ' ').split(' ') + + let finalTestName = [testName[0], folderName, ...testName.slice(1)].join(' ') + + finalTestName = finalTestName.charAt(0).toUpperCase() + finalTestName.slice(1) + + finalTestName = finalTestName.replace('-', ' ') + + const testFunction = j.callExpression(j.identifier('test'), [ + j.literal(finalTestName), + j.arrowFunctionExpression( + [], + failureValue !== null + ? j.blockStatement([ + dataDeclaration, + j.variableDeclaration('const', [ + j.variableDeclarator( + j.arrayPattern([j.identifier('err'), j.identifier('res')]), + j.callExpression( + j.identifier('validate'), + assertOrCreate === 'create' + ? [j.identifier('data'), structExpression, validateOptions] + : [j.identifier('data'), structExpression] + ) + ), + ]), + j.expressionStatement( + j.callExpression( + j.memberExpression( + j.callExpression(j.identifier('expect'), [ + j.identifier('res'), + ]), + j.identifier('toBeUndefined') + ), + [] + ) + ), + j.expressionStatement( + j.callExpression( + j.memberExpression( + j.callExpression(j.identifier('expect'), [ + j.identifier('err'), + ]), + j.identifier('toMatchStructError') + ), + [failureValue] + ) + ), + ]) + : assertOrCreate === 'create' + ? j.blockStatement([ + dataDeclaration, + j.variableDeclaration('const', [ + j.variableDeclarator( + j.identifier('res'), + j.callExpression(j.identifier(assertOrCreate), [ + j.identifier('data'), + structExpression, + ]) + ), + ]), + j.expressionStatement( + j.callExpression( + j.memberExpression( + j.callExpression(j.identifier('expect'), [ + j.identifier('res'), + ]), + j.identifier('toStrictEqual') + ), + [outputValue] + ) + ), + ]) + : j.blockStatement([ + dataDeclaration, + j.expressionStatement( + j.callExpression(j.identifier(assertOrCreate), [ + j.identifier('data'), + structExpression, + ]) + ), + j.expressionStatement( + j.callExpression( + j.memberExpression( + j.callExpression(j.identifier('expect'), [ + j.identifier('data'), + ]), + j.identifier('toStrictEqual') + ), + [outputValue] + ) + ), + ]) + ), + ]) + + root.get().node.program.body.push(j.expressionStatement(testFunction)) + + return root.toSource() +} From 897a29765516802b6769576432b9c67ab0607efb Mon Sep 17 00:00:00 2001 From: Geoff Date: Mon, 19 Aug 2024 23:18:46 -0400 Subject: [PATCH 3/6] Run `npm run fix` --- test/validation/any/valid-number.ts | 14 +++---- test/validation/any/valid-string.ts | 14 +++---- test/validation/any/valid-undefined.ts | 14 +++---- .../array/invalid-element-property.ts | 16 +++---- test/validation/array/invalid-element.ts | 16 +++---- test/validation/array/invalid-opaque.ts | 16 +++---- test/validation/array/invalid.ts | 16 +++---- test/validation/array/valid-frozen.ts | 14 +++---- test/validation/array/valid-opaque.ts | 14 +++---- test/validation/array/valid.ts | 14 +++---- test/validation/assign/invalid-object.ts | 16 +++---- test/validation/assign/invalid-type.ts | 16 +++---- test/validation/assign/valid-object.ts | 14 +++---- test/validation/assign/valid-type.ts | 14 +++---- test/validation/bigint/invalid-number.ts | 16 +++---- test/validation/bigint/invalid.ts | 16 +++---- test/validation/bigint/valid.ts | 14 +++---- test/validation/boolean/invalid.ts | 16 +++---- test/validation/boolean/valid.ts | 14 +++---- test/validation/coerce/changed.ts | 19 +++++---- test/validation/coerce/condition-not-met.ts | 24 ++++++----- test/validation/coerce/unchanged.ts | 19 +++++---- test/validation/date/invalid-date.ts | 16 +++---- test/validation/date/invalid.ts | 16 +++---- test/validation/date/valid.ts | 14 +++---- test/validation/defaulted/function.ts | 17 ++++---- test/validation/defaulted/mixin.ts | 33 ++++++++------- test/validation/defaulted/nested-double.ts | 31 +++++++------- test/validation/defaulted/nested.ts | 21 ++++++---- test/validation/defaulted/strict.ts | 42 ++++++++++--------- test/validation/defaulted/value.ts | 14 +++---- test/validation/deprecated/invalid-null.ts | 19 +++++---- .../validation/deprecated/invalid-property.ts | 23 +++++----- test/validation/deprecated/invalid.ts | 19 +++++---- test/validation/deprecated/valid-property.ts | 23 +++++----- test/validation/deprecated/valid-undefined.ts | 17 ++++---- test/validation/deprecated/valid.ts | 17 ++++---- test/validation/dynamic/invalid-reference.ts | 25 ++++++----- test/validation/dynamic/invalid.ts | 19 +++++---- test/validation/dynamic/valid-reference.ts | 23 +++++----- test/validation/dynamic/valid.ts | 17 ++++---- test/validation/dynamic/with-refiners.ts | 19 +++++---- test/validation/empty/invalid-array.ts | 16 +++---- test/validation/empty/invalid-map.ts | 16 +++---- test/validation/empty/invalid-set.ts | 16 +++---- test/validation/empty/invalid-string.ts | 16 +++---- test/validation/empty/valid-array.ts | 14 +++---- test/validation/empty/valid-map.ts | 14 +++---- test/validation/empty/valid-set.ts | 14 +++---- test/validation/empty/valid-string.ts | 14 +++---- test/validation/enums/invalid-numbers.ts | 16 +++---- test/validation/enums/invalid-strings.ts | 16 +++---- test/validation/enums/valid.ts | 14 +++---- test/validation/function/invalid.ts | 16 +++---- test/validation/function/valid.ts | 14 +++---- test/validation/instance/invalid.ts | 16 +++---- test/validation/instance/valid.ts | 14 +++---- test/validation/integer/invalid-decimal.ts | 16 +++---- test/validation/integer/invalid.ts | 16 +++---- test/validation/integer/valid.ts | 14 +++---- .../intersection/invalid-refinement.ts | 16 +++---- test/validation/intersection/invalid.ts | 16 +++---- .../intersection/valid-refinement.ts | 14 +++---- test/validation/intersection/valid.ts | 14 +++---- test/validation/lazy/invalid.ts | 19 +++++---- test/validation/lazy/valid.ts | 17 ++++---- test/validation/lazy/with-refiners.ts | 19 +++++---- test/validation/literal/invalid.ts | 16 +++---- test/validation/literal/valid.ts | 14 +++---- test/validation/map/invalid-opaque.ts | 16 +++---- test/validation/map/invalid-property.ts | 16 +++---- test/validation/map/invalid.ts | 16 +++---- test/validation/map/valid.ts | 22 +++++----- test/validation/max/invalid-exclusive.ts | 16 +++---- test/validation/max/invalid.ts | 16 +++---- test/validation/max/valid-inclusive.ts | 14 +++---- test/validation/max/valid.ts | 14 +++---- test/validation/min/invalid-exclusive.ts | 16 +++---- test/validation/min/invalid.ts | 16 +++---- test/validation/min/valid-inclusive.ts | 14 +++---- test/validation/min/valid.ts | 14 +++---- test/validation/never/invalid.ts | 16 +++---- test/validation/nullable/invalid.ts | 16 +++---- .../nullable/valid-defined-nested.ts | 23 +++++----- test/validation/nullable/valid-defined.ts | 14 +++---- test/validation/nullable/valid-null-nested.ts | 23 +++++----- test/validation/nullable/valid-null.ts | 14 +++---- test/validation/number/invalid.ts | 16 +++---- test/validation/number/valid.ts | 14 +++---- test/validation/object/invalid-array.ts | 16 +++---- .../object/invalid-element-nested.ts | 25 ++++++----- test/validation/object/invalid-opaque.ts | 16 +++---- .../object/invalid-property-nested.ts | 31 +++++++------- .../object/invalid-property-unknown.ts | 25 ++++++----- test/validation/object/invalid-property.ts | 27 ++++++------ test/validation/object/invalid-referential.ts | 33 ++++++++------- test/validation/object/invalid.ts | 25 ++++++----- test/validation/object/valid-frozen.ts | 23 +++++----- test/validation/object/valid-nested.ts | 29 +++++++------ test/validation/object/valid-opaque.ts | 14 +++---- test/validation/object/valid-referential.ts | 31 +++++++------- test/validation/object/valid.ts | 23 +++++----- .../validation/omit/invalid-element-nested.ts | 31 +++++++------- .../omit/invalid-property-nested.ts | 35 +++++++++------- .../omit/invalid-property-unknown.ts | 31 +++++++------- test/validation/omit/invalid-property.ts | 31 +++++++------- test/validation/omit/invalid.ts | 31 +++++++------- test/validation/omit/valid-nested.ts | 33 ++++++++------- test/validation/omit/valid-type.ts | 29 +++++++------ test/validation/omit/valid.ts | 29 +++++++------ test/validation/optional/invalid.ts | 16 +++---- .../optional/valid-defined-nested.ts | 23 +++++----- test/validation/optional/valid-defined.ts | 14 +++---- .../optional/valid-undefined-nested.ts | 23 +++++----- test/validation/optional/valid-undefined.ts | 14 +++---- test/validation/partial/composed.ts | 27 ++++++------ .../partial/invalid-property-unknown.ts | 25 ++++++----- test/validation/partial/invalid-property.ts | 25 ++++++----- test/validation/partial/invalid.ts | 25 ++++++----- test/validation/partial/valid-empty.ts | 23 +++++----- test/validation/partial/valid-full.ts | 23 +++++----- test/validation/partial/valid-partial.ts | 23 +++++----- test/validation/partial/valid-type.ts | 27 ++++++------ test/validation/pattern/invalid.ts | 16 +++---- test/validation/pattern/valid.ts | 14 +++---- .../validation/pick/invalid-element-nested.ts | 31 +++++++------- .../pick/invalid-property-nested.ts | 35 +++++++++------- .../pick/invalid-property-unknown.ts | 31 +++++++------- test/validation/pick/invalid-property.ts | 31 +++++++------- test/validation/pick/invalid.ts | 31 +++++++------- test/validation/pick/valid-nested.ts | 33 ++++++++------- test/validation/pick/valid-type.ts | 29 +++++++------ test/validation/pick/valid.ts | 29 +++++++------ test/validation/record/invalid-array.ts | 16 +++---- test/validation/record/invalid-property.ts | 16 +++---- test/validation/record/invalid.ts | 16 +++---- test/validation/record/valid-frozen.ts | 14 +++---- test/validation/record/valid.ts | 14 +++---- .../refine/invalid-multiple-refinements.ts | 25 ++++++----- test/validation/refine/invalid-shorthand.ts | 23 +++++----- test/validation/refine/invalid.ts | 19 +++++---- test/validation/refine/valid.ts | 17 ++++---- test/validation/regexp/invalid.ts | 16 +++---- test/validation/regexp/valid.ts | 14 +++---- test/validation/set/invalid-element.ts | 16 +++---- test/validation/set/invalid-opaque.ts | 16 +++---- test/validation/set/invalid.ts | 16 +++---- test/validation/set/valid-opaque.ts | 14 +++---- test/validation/set/valid.ts | 14 +++---- test/validation/size/invalid-array.ts | 16 +++---- test/validation/size/invalid-map.ts | 16 +++---- test/validation/size/invalid-number.ts | 16 +++---- test/validation/size/invalid-set.ts | 16 +++---- test/validation/size/invalid-string.ts | 16 +++---- test/validation/size/valid-array.ts | 14 +++---- test/validation/size/valid-exact.ts | 14 +++---- test/validation/size/valid-map.ts | 14 +++---- test/validation/size/valid-max-inclusive.ts | 14 +++---- test/validation/size/valid-min-inclusive.ts | 14 +++---- test/validation/size/valid-number.ts | 14 +++---- test/validation/size/valid-set.ts | 14 +++---- test/validation/size/valid-string.ts | 14 +++---- test/validation/string/invalid.ts | 16 +++---- test/validation/string/valid.ts | 14 +++---- test/validation/trimmed/invalid.ts | 18 ++++---- test/validation/trimmed/valid.ts | 14 +++---- .../tuple/invalid-element-missing.ts | 16 +++---- .../tuple/invalid-element-unknown.ts | 16 +++---- test/validation/tuple/invalid-element.ts | 16 +++---- test/validation/tuple/invalid.ts | 16 +++---- test/validation/tuple/valid-frozen.ts | 14 +++---- test/validation/tuple/valid.ts | 14 +++---- test/validation/type/invalid-array.ts | 16 +++---- .../type/invalid-property-nested.ts | 31 +++++++------- test/validation/type/invalid-property.ts | 25 ++++++----- test/validation/type/invalid.ts | 25 ++++++----- test/validation/type/valid-frozen.ts | 23 +++++----- test/validation/type/valid.ts | 23 +++++----- test/validation/union/coercion-object.ts | 14 +++---- test/validation/union/coercion-type.ts | 14 +++---- test/validation/union/coercion.ts | 14 +++---- test/validation/union/invalid.ts | 16 +++---- test/validation/union/valid.ts | 14 +++---- test/validation/unknown/valid-number.ts | 14 +++---- test/validation/unknown/valid-string.ts | 14 +++---- test/validation/unknown/valid-undefined.ts | 14 +++---- 186 files changed, 1859 insertions(+), 1660 deletions(-) diff --git a/test/validation/any/valid-number.ts b/test/validation/any/valid-number.ts index 0511b83d..19342718 100644 --- a/test/validation/any/valid-number.ts +++ b/test/validation/any/valid-number.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { any } from '../../../src' -test("Valid any number", () => { - const data = 1; - assert(data, any()); - expect(data).toStrictEqual(1); -}); +test('Valid any number', () => { + const data = 1 + assert(data, any()) + expect(data).toStrictEqual(1) +}) diff --git a/test/validation/any/valid-string.ts b/test/validation/any/valid-string.ts index c5d16cb0..a2d48de4 100644 --- a/test/validation/any/valid-string.ts +++ b/test/validation/any/valid-string.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { any } from '../../../src' -test("Valid any string", () => { - const data = 'valid'; - assert(data, any()); - expect(data).toStrictEqual('valid'); -}); +test('Valid any string', () => { + const data = 'valid' + assert(data, any()) + expect(data).toStrictEqual('valid') +}) diff --git a/test/validation/any/valid-undefined.ts b/test/validation/any/valid-undefined.ts index 7da47090..c594d764 100644 --- a/test/validation/any/valid-undefined.ts +++ b/test/validation/any/valid-undefined.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { any } from '../../../src' -test("Valid any undefined", () => { - const data = undefined; - assert(data, any()); - expect(data).toStrictEqual(undefined); -}); +test('Valid any undefined', () => { + const data = undefined + assert(data, any()) + expect(data).toStrictEqual(undefined) +}) diff --git a/test/validation/array/invalid-element-property.ts b/test/validation/array/invalid-element-property.ts index c9e5d8bf..8fc4ef17 100644 --- a/test/validation/array/invalid-element-property.ts +++ b/test/validation/array/invalid-element-property.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { array, object, string } from '../../../src' -test("Invalid array element property", () => { - const data = [{ id: '1' }, { id: false }, { id: '3' }]; - const [err, res] = validate(data, array(object({ id: string() }))); - expect(res).toBeUndefined(); +test('Invalid array element property', () => { + const data = [{ id: '1' }, { id: false }, { id: '3' }] + const [err, res] = validate(data, array(object({ id: string() }))) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid array element property", () => { path: [1, 'id'], branch: [data, data[1], data[1].id], }, - ]); -}); + ]) +}) diff --git a/test/validation/array/invalid-element.ts b/test/validation/array/invalid-element.ts index 03d09447..654cea0b 100644 --- a/test/validation/array/invalid-element.ts +++ b/test/validation/array/invalid-element.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { array, number } from '../../../src' -test("Invalid array element", () => { - const data = [1, 'invalid', 3]; - const [err, res] = validate(data, array(number())); - expect(res).toBeUndefined(); +test('Invalid array element', () => { + const data = [1, 'invalid', 3] + const [err, res] = validate(data, array(number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid array element", () => { path: [1], branch: [data, data[1]], }, - ]); -}); + ]) +}) diff --git a/test/validation/array/invalid-opaque.ts b/test/validation/array/invalid-opaque.ts index 73aa6dce..ba93ed17 100644 --- a/test/validation/array/invalid-opaque.ts +++ b/test/validation/array/invalid-opaque.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { array } from '../../../src' -test("Invalid array opaque", () => { - const data = 'invalid'; - const [err, res] = validate(data, array()); - expect(res).toBeUndefined(); +test('Invalid array opaque', () => { + const data = 'invalid' + const [err, res] = validate(data, array()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid array opaque", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/array/invalid.ts b/test/validation/array/invalid.ts index bb487a49..a80827e1 100644 --- a/test/validation/array/invalid.ts +++ b/test/validation/array/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { array, number } from '../../../src' -test("Invalid array", () => { - const data = 'invalid'; - const [err, res] = validate(data, array(number())); - expect(res).toBeUndefined(); +test('Invalid array', () => { + const data = 'invalid' + const [err, res] = validate(data, array(number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid array", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/array/valid-frozen.ts b/test/validation/array/valid-frozen.ts index f40b4603..9e73b4ab 100644 --- a/test/validation/array/valid-frozen.ts +++ b/test/validation/array/valid-frozen.ts @@ -1,9 +1,9 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { array, number } from '../../../src' -test("Valid array frozen", () => { - const data = Object.freeze([1, 2, 3]); - const res = create(data, array(number())); - expect(res).toStrictEqual([1, 2, 3]); -}); +test('Valid array frozen', () => { + const data = Object.freeze([1, 2, 3]) + const res = create(data, array(number())) + expect(res).toStrictEqual([1, 2, 3]) +}) diff --git a/test/validation/array/valid-opaque.ts b/test/validation/array/valid-opaque.ts index ce780a24..545124af 100644 --- a/test/validation/array/valid-opaque.ts +++ b/test/validation/array/valid-opaque.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { array } from '../../../src' -test("Valid array opaque", () => { - const data = [1, 'b', true]; - assert(data, array()); - expect(data).toStrictEqual([1, 'b', true]); -}); +test('Valid array opaque', () => { + const data = [1, 'b', true] + assert(data, array()) + expect(data).toStrictEqual([1, 'b', true]) +}) diff --git a/test/validation/array/valid.ts b/test/validation/array/valid.ts index d3e7bca4..827d18c3 100644 --- a/test/validation/array/valid.ts +++ b/test/validation/array/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { array, number } from '../../../src' -test("Valid array", () => { - const data = [1, 2, 3]; - assert(data, array(number())); - expect(data).toStrictEqual([1, 2, 3]); -}); +test('Valid array', () => { + const data = [1, 2, 3] + assert(data, array(number())) + expect(data).toStrictEqual([1, 2, 3]) +}) diff --git a/test/validation/assign/invalid-object.ts b/test/validation/assign/invalid-object.ts index 7c153dd4..918ec025 100644 --- a/test/validation/assign/invalid-object.ts +++ b/test/validation/assign/invalid-object.ts @@ -1,19 +1,19 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { object, assign, string, number } from '../../../src' const A = object({ a: string() }) const B = object({ a: number(), b: number() }) -test("Invalid assign object", () => { +test('Invalid assign object', () => { const data = { a: 'invalid', b: 2, c: 5, - }; + } - const [err, res] = validate(data, assign(A, B)); - expect(res).toBeUndefined(); + const [err, res] = validate(data, assign(A, B)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -30,5 +30,5 @@ test("Invalid assign object", () => { type: 'never', value: 5, }, - ]); -}); + ]) +}) diff --git a/test/validation/assign/invalid-type.ts b/test/validation/assign/invalid-type.ts index caa03845..8be22b7f 100644 --- a/test/validation/assign/invalid-type.ts +++ b/test/validation/assign/invalid-type.ts @@ -1,19 +1,19 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { type, object, assign, string, number } from '../../../src' const A = type({ a: string() }) const B = object({ a: number(), b: number() }) -test("Invalid assign type", () => { +test('Invalid assign type', () => { const data = { a: 'invalid', b: 2, c: 5, - }; + } - const [err, res] = validate(data, assign(A, B)); - expect(res).toBeUndefined(); + const [err, res] = validate(data, assign(A, B)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -23,5 +23,5 @@ test("Invalid assign type", () => { path: ['a'], branch: [data, data.a], }, - ]); -}); + ]) +}) diff --git a/test/validation/assign/valid-object.ts b/test/validation/assign/valid-object.ts index b6be915f..17833c0e 100644 --- a/test/validation/assign/valid-object.ts +++ b/test/validation/assign/valid-object.ts @@ -1,20 +1,20 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, assign, string, number } from '../../../src' const A = type({ a: string() }) const B = type({ a: number(), b: number() }) -test("Valid assign object", () => { +test('Valid assign object', () => { const data = { a: 1, b: 2, - }; + } - assert(data, assign(A, B)); + assert(data, assign(A, B)) expect(data).toStrictEqual({ a: 1, b: 2, - }); -}); + }) +}) diff --git a/test/validation/assign/valid-type.ts b/test/validation/assign/valid-type.ts index fa2af5aa..af8a14d0 100644 --- a/test/validation/assign/valid-type.ts +++ b/test/validation/assign/valid-type.ts @@ -1,22 +1,22 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, object, assign, string, number } from '../../../src' const A = type({ a: string() }) const B = object({ b: number() }) -test("Valid assign type", () => { +test('Valid assign type', () => { const data = { a: '1', b: 2, c: 3, - }; + } - assert(data, assign(A, B)); + assert(data, assign(A, B)) expect(data).toStrictEqual({ a: '1', b: 2, c: 3, - }); -}); + }) +}) diff --git a/test/validation/bigint/invalid-number.ts b/test/validation/bigint/invalid-number.ts index dc2a35a2..e9989404 100644 --- a/test/validation/bigint/invalid-number.ts +++ b/test/validation/bigint/invalid-number.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { bigint } from '../../../src' -test("Invalid bigint number", () => { - const data = 3; - const [err, res] = validate(data, bigint()); - expect(res).toBeUndefined(); +test('Invalid bigint number', () => { + const data = 3 + const [err, res] = validate(data, bigint()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid bigint number", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/bigint/invalid.ts b/test/validation/bigint/invalid.ts index 0bcdfd62..2374c332 100644 --- a/test/validation/bigint/invalid.ts +++ b/test/validation/bigint/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { bigint } from '../../../src' -test("Invalid bigint", () => { - const data = 'invalid'; - const [err, res] = validate(data, bigint()); - expect(res).toBeUndefined(); +test('Invalid bigint', () => { + const data = 'invalid' + const [err, res] = validate(data, bigint()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid bigint", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/bigint/valid.ts b/test/validation/bigint/valid.ts index c429c46f..5eb16f40 100644 --- a/test/validation/bigint/valid.ts +++ b/test/validation/bigint/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { bigint } from '../../../src' -test("Valid bigint", () => { - const data = 542n; - assert(data, bigint()); - expect(data).toStrictEqual(542n); -}); +test('Valid bigint', () => { + const data = 542n + assert(data, bigint()) + expect(data).toStrictEqual(542n) +}) diff --git a/test/validation/boolean/invalid.ts b/test/validation/boolean/invalid.ts index 3bca802d..087f28b0 100644 --- a/test/validation/boolean/invalid.ts +++ b/test/validation/boolean/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { boolean } from '../../../src' -test("Invalid boolean", () => { - const data = 'invalid'; - const [err, res] = validate(data, boolean()); - expect(res).toBeUndefined(); +test('Invalid boolean', () => { + const data = 'invalid' + const [err, res] = validate(data, boolean()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid boolean", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/boolean/valid.ts b/test/validation/boolean/valid.ts index a6528798..b2d57559 100644 --- a/test/validation/boolean/valid.ts +++ b/test/validation/boolean/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { boolean } from '../../../src' -test("Valid boolean", () => { - const data = true; - assert(data, boolean()); - expect(data).toStrictEqual(true); -}); +test('Valid boolean', () => { + const data = true + assert(data, boolean()) + expect(data).toStrictEqual(true) +}) diff --git a/test/validation/coerce/changed.ts b/test/validation/coerce/changed.ts index 63ce631c..b72c6e66 100644 --- a/test/validation/coerce/changed.ts +++ b/test/validation/coerce/changed.ts @@ -1,13 +1,14 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { string, unknown, coerce } from '../../../src' -test("Changed coerce", () => { - const data = null; +test('Changed coerce', () => { + const data = null - const res = create(data, coerce(string(), unknown(), (x) => - x == null ? 'unknown' : x - )); + const res = create( + data, + coerce(string(), unknown(), (x) => (x == null ? 'unknown' : x)) + ) - expect(res).toStrictEqual('unknown'); -}); + expect(res).toStrictEqual('unknown') +}) diff --git a/test/validation/coerce/condition-not-met.ts b/test/validation/coerce/condition-not-met.ts index acd353d4..5a9e895a 100644 --- a/test/validation/coerce/condition-not-met.ts +++ b/test/validation/coerce/condition-not-met.ts @@ -1,15 +1,19 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { string, number, coerce } from '../../../src' -test("Condition coerce not met", () => { - const data = false; +test('Condition coerce not met', () => { + const data = false - const [err, res] = validate(data, coerce(string(), number(), (x) => 'known'), { - coerce: true - }); + const [err, res] = validate( + data, + coerce(string(), number(), (x) => 'known'), + { + coerce: true, + } + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -19,5 +23,5 @@ test("Condition coerce not met", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/coerce/unchanged.ts b/test/validation/coerce/unchanged.ts index 8a4dc524..87ba2310 100644 --- a/test/validation/coerce/unchanged.ts +++ b/test/validation/coerce/unchanged.ts @@ -1,13 +1,14 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { string, unknown, coerce } from '../../../src' -test("Unchanged coerce", () => { - const data = 'known'; +test('Unchanged coerce', () => { + const data = 'known' - const res = create(data, coerce(string(), unknown(), (x) => - x == null ? 'unknown' : x - )); + const res = create( + data, + coerce(string(), unknown(), (x) => (x == null ? 'unknown' : x)) + ) - expect(res).toStrictEqual('known'); -}); + expect(res).toStrictEqual('known') +}) diff --git a/test/validation/date/invalid-date.ts b/test/validation/date/invalid-date.ts index a1b8c8c6..68295012 100644 --- a/test/validation/date/invalid-date.ts +++ b/test/validation/date/invalid-date.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { date } from '../../../src' -test("Invalid date date", () => { - const data = new Date('invalid'); - const [err, res] = validate(data, date()); - expect(res).toBeUndefined(); +test('Invalid date date', () => { + const data = new Date('invalid') + const [err, res] = validate(data, date()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid date date", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/date/invalid.ts b/test/validation/date/invalid.ts index 21d23f33..07ebb114 100644 --- a/test/validation/date/invalid.ts +++ b/test/validation/date/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { date } from '../../../src' -test("Invalid date", () => { - const data = 'invalid'; - const [err, res] = validate(data, date()); - expect(res).toBeUndefined(); +test('Invalid date', () => { + const data = 'invalid' + const [err, res] = validate(data, date()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid date", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/date/valid.ts b/test/validation/date/valid.ts index 65f43f08..625fad3a 100644 --- a/test/validation/date/valid.ts +++ b/test/validation/date/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { date } from '../../../src' -test("Valid date", () => { - const data = new Date(0); - assert(data, date()); - expect(data).toStrictEqual(new Date(0)); -}); +test('Valid date', () => { + const data = new Date(0) + assert(data, date()) + expect(data).toStrictEqual(new Date(0)) +}) diff --git a/test/validation/defaulted/function.ts b/test/validation/defaulted/function.ts index cd95d356..a1892603 100644 --- a/test/validation/defaulted/function.ts +++ b/test/validation/defaulted/function.ts @@ -1,9 +1,12 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { number, defaulted } from '../../../src' -test("Function defaulted", () => { - const data = undefined; - const res = create(data, defaulted(number(), () => 42)); - expect(res).toStrictEqual(42); -}); +test('Function defaulted', () => { + const data = undefined + const res = create( + data, + defaulted(number(), () => 42) + ) + expect(res).toStrictEqual(42) +}) diff --git a/test/validation/defaulted/mixin.ts b/test/validation/defaulted/mixin.ts index 1518f960..45cf0dfd 100644 --- a/test/validation/defaulted/mixin.ts +++ b/test/validation/defaulted/mixin.ts @@ -1,24 +1,27 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { defaulted, string, object, number } from '../../../src' -test("Mixin defaulted", () => { +test('Mixin defaulted', () => { const data = { version: 0, - }; + } - const res = create(data, defaulted( - object({ - title: string(), - version: number(), - }), - { - title: 'Untitled', - } - )); + const res = create( + data, + defaulted( + object({ + title: string(), + version: number(), + }), + { + title: 'Untitled', + } + ) + ) expect(res).toStrictEqual({ title: 'Untitled', version: 0, - }); -}); + }) +}) diff --git a/test/validation/defaulted/nested-double.ts b/test/validation/defaulted/nested-double.ts index a4f2ba6a..97d76fb0 100644 --- a/test/validation/defaulted/nested-double.ts +++ b/test/validation/defaulted/nested-double.ts @@ -1,22 +1,25 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { defaulted, string, object } from '../../../src' -test("Nested defaulted double", () => { - const data = {}; +test('Nested defaulted double', () => { + const data = {} - const res = create(data, object({ - book: defaulted( - object({ - title: defaulted(string(), 'Untitled'), - }), - {} - ), - })); + const res = create( + data, + object({ + book: defaulted( + object({ + title: defaulted(string(), 'Untitled'), + }), + {} + ), + }) + ) expect(res).toStrictEqual({ book: { title: 'Untitled', }, - }); -}); + }) +}) diff --git a/test/validation/defaulted/nested.ts b/test/validation/defaulted/nested.ts index 1002e958..7a93c7d8 100644 --- a/test/validation/defaulted/nested.ts +++ b/test/validation/defaulted/nested.ts @@ -1,15 +1,18 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { defaulted, string, object } from '../../../src' -test("Nested defaulted", () => { - const data = {}; +test('Nested defaulted', () => { + const data = {} - const res = create(data, object({ - title: defaulted(string(), 'Untitled'), - })); + const res = create( + data, + object({ + title: defaulted(string(), 'Untitled'), + }) + ) expect(res).toStrictEqual({ title: 'Untitled', - }); -}); + }) +}) diff --git a/test/validation/defaulted/strict.ts b/test/validation/defaulted/strict.ts index 960cd2d4..e3f8a132 100644 --- a/test/validation/defaulted/strict.ts +++ b/test/validation/defaulted/strict.ts @@ -1,28 +1,32 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { defaulted, string, type, number } from '../../../src' -test("Strict defaulted", () => { +test('Strict defaulted', () => { const data = { version: 0, - }; + } - const [err, res] = validate(data, defaulted( - type({ - title: string(), - version: number(), - }), + const [err, res] = validate( + data, + defaulted( + type({ + title: string(), + version: number(), + }), + { + title: 'Untitled', + }, + { + strict: true, + } + ), { - title: 'Untitled', - }, - { - strict: true, + coerce: true, } - ), { - coerce: true - }); + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -32,5 +36,5 @@ test("Strict defaulted", () => { path: ['title'], branch: [data, undefined], }, - ]); -}); + ]) +}) diff --git a/test/validation/defaulted/value.ts b/test/validation/defaulted/value.ts index 14623027..3d3df041 100644 --- a/test/validation/defaulted/value.ts +++ b/test/validation/defaulted/value.ts @@ -1,9 +1,9 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { number, defaulted } from '../../../src' -test("Value defaulted", () => { - const data = undefined; - const res = create(data, defaulted(number(), 42)); - expect(res).toStrictEqual(42); -}); +test('Value defaulted', () => { + const data = undefined + const res = create(data, defaulted(number(), 42)) + expect(res).toStrictEqual(42) +}) diff --git a/test/validation/deprecated/invalid-null.ts b/test/validation/deprecated/invalid-null.ts index 671dd972..74c8d4c3 100644 --- a/test/validation/deprecated/invalid-null.ts +++ b/test/validation/deprecated/invalid-null.ts @@ -1,11 +1,14 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { deprecated, string } from '../../../src' -test("Invalid deprecated null", () => { - const data = null; - const [err, res] = validate(data, deprecated(string(), () => {})); - expect(res).toBeUndefined(); +test('Invalid deprecated null', () => { + const data = null + const [err, res] = validate( + data, + deprecated(string(), () => {}) + ) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +18,5 @@ test("Invalid deprecated null", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/deprecated/invalid-property.ts b/test/validation/deprecated/invalid-property.ts index 36612d3e..1e8d47a4 100644 --- a/test/validation/deprecated/invalid-property.ts +++ b/test/validation/deprecated/invalid-property.ts @@ -1,17 +1,20 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { deprecated, number, object } from '../../../src' -test("Invalid deprecated property", () => { +test('Invalid deprecated property', () => { const data = { deprecatedKey: '42', - }; + } - const [err, res] = validate(data, object({ - deprecatedKey: deprecated(number(), () => {}), - })); + const [err, res] = validate( + data, + object({ + deprecatedKey: deprecated(number(), () => {}), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -21,5 +24,5 @@ test("Invalid deprecated property", () => { path: ['deprecatedKey'], branch: [data, data.deprecatedKey], }, - ]); -}); + ]) +}) diff --git a/test/validation/deprecated/invalid.ts b/test/validation/deprecated/invalid.ts index ce7620ae..3b3e697d 100644 --- a/test/validation/deprecated/invalid.ts +++ b/test/validation/deprecated/invalid.ts @@ -1,11 +1,14 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { deprecated, number } from '../../../src' -test("Invalid deprecated", () => { - const data = '42'; - const [err, res] = validate(data, deprecated(number(), () => {})); - expect(res).toBeUndefined(); +test('Invalid deprecated', () => { + const data = '42' + const [err, res] = validate( + data, + deprecated(number(), () => {}) + ) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +18,5 @@ test("Invalid deprecated", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/deprecated/valid-property.ts b/test/validation/deprecated/valid-property.ts index f8914fb2..200675e3 100644 --- a/test/validation/deprecated/valid-property.ts +++ b/test/validation/deprecated/valid-property.ts @@ -1,18 +1,21 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, number, deprecated, any } from '../../../src' -test("Valid deprecated property", () => { +test('Valid deprecated property', () => { const data = { age: 42, - }; + } - assert(data, type({ - name: deprecated(any(), () => {}), - age: number(), - })); + assert( + data, + type({ + name: deprecated(any(), () => {}), + age: number(), + }) + ) expect(data).toStrictEqual({ age: 42, - }); -}); + }) +}) diff --git a/test/validation/deprecated/valid-undefined.ts b/test/validation/deprecated/valid-undefined.ts index 28f11e3e..50e5b929 100644 --- a/test/validation/deprecated/valid-undefined.ts +++ b/test/validation/deprecated/valid-undefined.ts @@ -1,9 +1,12 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { deprecated, number } from '../../../src' -test("Valid deprecated undefined", () => { - const data = undefined; - assert(data, deprecated(number(), () => {})); - expect(data).toStrictEqual(undefined); -}); +test('Valid deprecated undefined', () => { + const data = undefined + assert( + data, + deprecated(number(), () => {}) + ) + expect(data).toStrictEqual(undefined) +}) diff --git a/test/validation/deprecated/valid.ts b/test/validation/deprecated/valid.ts index d688d662..c2ba8ebd 100644 --- a/test/validation/deprecated/valid.ts +++ b/test/validation/deprecated/valid.ts @@ -1,9 +1,12 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { deprecated, number } from '../../../src' -test("Valid deprecated", () => { - const data = 42; - assert(data, deprecated(number(), () => {})); - expect(data).toStrictEqual(42); -}); +test('Valid deprecated', () => { + const data = 42 + assert( + data, + deprecated(number(), () => {}) + ) + expect(data).toStrictEqual(42) +}) diff --git a/test/validation/dynamic/invalid-reference.ts b/test/validation/dynamic/invalid-reference.ts index 8b186b26..41f92d87 100644 --- a/test/validation/dynamic/invalid-reference.ts +++ b/test/validation/dynamic/invalid-reference.ts @@ -1,5 +1,5 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { assert, type, dynamic, literal, number, string } from '../../../src' const Entity = type({ @@ -21,18 +21,21 @@ const map = { PRODUCT: Product, } -test("Invalid dynamic reference", () => { +test('Invalid dynamic reference', () => { const data = { object: 'PRODUCT', price: 'Only $19.99!', - }; + } - const [err, res] = validate(data, dynamic((entity) => { - assert(entity, Entity) - return map[entity.object] - })); + const [err, res] = validate( + data, + dynamic((entity) => { + assert(entity, Entity) + return map[entity.object] + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -42,5 +45,5 @@ test("Invalid dynamic reference", () => { path: ['price'], branch: [data, data.price], }, - ]); -}); + ]) +}) diff --git a/test/validation/dynamic/invalid.ts b/test/validation/dynamic/invalid.ts index 5dc76e54..52a502a7 100644 --- a/test/validation/dynamic/invalid.ts +++ b/test/validation/dynamic/invalid.ts @@ -1,11 +1,14 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { dynamic, string } from '../../../src' -test("Invalid dynamic", () => { - const data = 3; - const [err, res] = validate(data, dynamic(() => string())); - expect(res).toBeUndefined(); +test('Invalid dynamic', () => { + const data = 3 + const [err, res] = validate( + data, + dynamic(() => string()) + ) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +18,5 @@ test("Invalid dynamic", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/dynamic/valid-reference.ts b/test/validation/dynamic/valid-reference.ts index 370e29dd..26995883 100644 --- a/test/validation/dynamic/valid-reference.ts +++ b/test/validation/dynamic/valid-reference.ts @@ -1,5 +1,5 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { assert, type, dynamic, literal, string, number } from '../../../src' const Entity = type({ @@ -21,19 +21,22 @@ const map = { PRODUCT: Product, } -test("Valid dynamic reference", () => { +test('Valid dynamic reference', () => { const data = { object: 'PRODUCT', price: 1999, - }; + } - assert(data, dynamic((entity) => { - assert(entity, Entity) - return map[entity.object] - })); + assert( + data, + dynamic((entity) => { + assert(entity, Entity) + return map[entity.object] + }) + ) expect(data).toStrictEqual({ object: 'PRODUCT', price: 1999, - }); -}); + }) +}) diff --git a/test/validation/dynamic/valid.ts b/test/validation/dynamic/valid.ts index 8ab31685..42d94433 100644 --- a/test/validation/dynamic/valid.ts +++ b/test/validation/dynamic/valid.ts @@ -1,9 +1,12 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { dynamic, string } from '../../../src' -test("Valid dynamic", () => { - const data = 'valid'; - assert(data, dynamic(() => string())); - expect(data).toStrictEqual('valid'); -}); +test('Valid dynamic', () => { + const data = 'valid' + assert( + data, + dynamic(() => string()) + ) + expect(data).toStrictEqual('valid') +}) diff --git a/test/validation/dynamic/with-refiners.ts b/test/validation/dynamic/with-refiners.ts index 98976689..d2647629 100644 --- a/test/validation/dynamic/with-refiners.ts +++ b/test/validation/dynamic/with-refiners.ts @@ -1,11 +1,14 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { dynamic, string, nonempty } from '../../../src' -test("With dynamic refiners", () => { - const data = ''; - const [err, res] = validate(data, dynamic(() => nonempty(string()))); - expect(res).toBeUndefined(); +test('With dynamic refiners', () => { + const data = '' + const [err, res] = validate( + data, + dynamic(() => nonempty(string())) + ) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +18,5 @@ test("With dynamic refiners", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/empty/invalid-array.ts b/test/validation/empty/invalid-array.ts index 010c00ea..bf953c78 100644 --- a/test/validation/empty/invalid-array.ts +++ b/test/validation/empty/invalid-array.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { array, empty, number } from '../../../src' -test("Invalid empty array", () => { - const data = [1, 2, 3]; - const [err, res] = validate(data, empty(array(number()))); - expect(res).toBeUndefined(); +test('Invalid empty array', () => { + const data = [1, 2, 3] + const [err, res] = validate(data, empty(array(number()))) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid empty array", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/empty/invalid-map.ts b/test/validation/empty/invalid-map.ts index 26751d98..91f83cbc 100644 --- a/test/validation/empty/invalid-map.ts +++ b/test/validation/empty/invalid-map.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { map, empty, number, string } from '../../../src' -test("Invalid empty map", () => { - const data = new Map([[1, 'a']]); - const [err, res] = validate(data, empty(map(number(), string()))); - expect(res).toBeUndefined(); +test('Invalid empty map', () => { + const data = new Map([[1, 'a']]) + const [err, res] = validate(data, empty(map(number(), string()))) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid empty map", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/empty/invalid-set.ts b/test/validation/empty/invalid-set.ts index 96eedd2d..3b3923cf 100644 --- a/test/validation/empty/invalid-set.ts +++ b/test/validation/empty/invalid-set.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { set, empty, number } from '../../../src' -test("Invalid empty set", () => { - const data = new Set([1, 2, 3]); - const [err, res] = validate(data, empty(set(number()))); - expect(res).toBeUndefined(); +test('Invalid empty set', () => { + const data = new Set([1, 2, 3]) + const [err, res] = validate(data, empty(set(number()))) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid empty set", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/empty/invalid-string.ts b/test/validation/empty/invalid-string.ts index b1459605..af797862 100644 --- a/test/validation/empty/invalid-string.ts +++ b/test/validation/empty/invalid-string.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { string, empty } from '../../../src' -test("Invalid empty string", () => { - const data = 'invalid'; - const [err, res] = validate(data, empty(string())); - expect(res).toBeUndefined(); +test('Invalid empty string', () => { + const data = 'invalid' + const [err, res] = validate(data, empty(string())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid empty string", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/empty/valid-array.ts b/test/validation/empty/valid-array.ts index 4bb7b909..f09c3786 100644 --- a/test/validation/empty/valid-array.ts +++ b/test/validation/empty/valid-array.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, array, empty } from '../../../src' -test("Valid empty array", () => { - const data = []; - assert(data, empty(array(number()))); - expect(data).toStrictEqual([]); -}); +test('Valid empty array', () => { + const data = [] + assert(data, empty(array(number()))) + expect(data).toStrictEqual([]) +}) diff --git a/test/validation/empty/valid-map.ts b/test/validation/empty/valid-map.ts index 269202a9..11cfa405 100644 --- a/test/validation/empty/valid-map.ts +++ b/test/validation/empty/valid-map.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { string, number, map, empty } from '../../../src' -test("Valid empty map", () => { - const data = new Map(); - assert(data, empty(map(number(), string()))); - expect(data).toStrictEqual(data); -}); +test('Valid empty map', () => { + const data = new Map() + assert(data, empty(map(number(), string()))) + expect(data).toStrictEqual(data) +}) diff --git a/test/validation/empty/valid-set.ts b/test/validation/empty/valid-set.ts index 500c72db..a00a72f7 100644 --- a/test/validation/empty/valid-set.ts +++ b/test/validation/empty/valid-set.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, set, empty } from '../../../src' -test("Valid empty set", () => { - const data = new Set(); - assert(data, empty(set(number()))); - expect(data).toStrictEqual(data); -}); +test('Valid empty set', () => { + const data = new Set() + assert(data, empty(set(number()))) + expect(data).toStrictEqual(data) +}) diff --git a/test/validation/empty/valid-string.ts b/test/validation/empty/valid-string.ts index bd98545b..61d9d98f 100644 --- a/test/validation/empty/valid-string.ts +++ b/test/validation/empty/valid-string.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { string, empty } from '../../../src' -test("Valid empty string", () => { - const data = ''; - assert(data, empty(string())); - expect(data).toStrictEqual(''); -}); +test('Valid empty string', () => { + const data = '' + assert(data, empty(string())) + expect(data).toStrictEqual('') +}) diff --git a/test/validation/enums/invalid-numbers.ts b/test/validation/enums/invalid-numbers.ts index c5ff1fdd..8f6d2162 100644 --- a/test/validation/enums/invalid-numbers.ts +++ b/test/validation/enums/invalid-numbers.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { enums } from '../../../src' -test("Invalid enums numbers", () => { - const data = 'invalid'; - const [err, res] = validate(data, enums([1, 2])); - expect(res).toBeUndefined(); +test('Invalid enums numbers', () => { + const data = 'invalid' + const [err, res] = validate(data, enums([1, 2])) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid enums numbers", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/enums/invalid-strings.ts b/test/validation/enums/invalid-strings.ts index 0ebc134e..5f95c6e7 100644 --- a/test/validation/enums/invalid-strings.ts +++ b/test/validation/enums/invalid-strings.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { enums } from '../../../src' -test("Invalid enums strings", () => { - const data = 'invalid'; - const [err, res] = validate(data, enums(['one', 'two'])); - expect(res).toBeUndefined(); +test('Invalid enums strings', () => { + const data = 'invalid' + const [err, res] = validate(data, enums(['one', 'two'])) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid enums strings", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/enums/valid.ts b/test/validation/enums/valid.ts index 3c83c728..5093295e 100644 --- a/test/validation/enums/valid.ts +++ b/test/validation/enums/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { enums } from '../../../src' -test("Valid enums", () => { - const data = 'two'; - assert(data, enums(['one', 'two'])); - expect(data).toStrictEqual('two'); -}); +test('Valid enums', () => { + const data = 'two' + assert(data, enums(['one', 'two'])) + expect(data).toStrictEqual('two') +}) diff --git a/test/validation/function/invalid.ts b/test/validation/function/invalid.ts index 0f85a010..666f450c 100644 --- a/test/validation/function/invalid.ts +++ b/test/validation/function/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { func } from '../../../src' -test("Invalid function", () => { - const data = false; - const [err, res] = validate(data, func()); - expect(res).toBeUndefined(); +test('Invalid function', () => { + const data = false + const [err, res] = validate(data, func()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid function", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/function/valid.ts b/test/validation/function/valid.ts index 2f15c960..990136bf 100644 --- a/test/validation/function/valid.ts +++ b/test/validation/function/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { func } from '../../../src' -test("Valid function", () => { - const data = function () {}; - assert(data, func()); - expect(data).toStrictEqual(data); -}); +test('Valid function', () => { + const data = function () {} + assert(data, func()) + expect(data).toStrictEqual(data) +}) diff --git a/test/validation/instance/invalid.ts b/test/validation/instance/invalid.ts index 871675eb..da6137b1 100644 --- a/test/validation/instance/invalid.ts +++ b/test/validation/instance/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { instance } from '../../../src' -test("Invalid instance", () => { - const data = false; - const [err, res] = validate(data, instance(Array)); - expect(res).toBeUndefined(); +test('Invalid instance', () => { + const data = false + const [err, res] = validate(data, instance(Array)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid instance", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/instance/valid.ts b/test/validation/instance/valid.ts index 8e9f2a95..d86bf305 100644 --- a/test/validation/instance/valid.ts +++ b/test/validation/instance/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { instance } from '../../../src' -test("Valid instance", () => { - const data = [1]; - assert(data, instance(Array)); - expect(data).toStrictEqual([1]); -}); +test('Valid instance', () => { + const data = [1] + assert(data, instance(Array)) + expect(data).toStrictEqual([1]) +}) diff --git a/test/validation/integer/invalid-decimal.ts b/test/validation/integer/invalid-decimal.ts index f09d5d1c..5d7418f7 100644 --- a/test/validation/integer/invalid-decimal.ts +++ b/test/validation/integer/invalid-decimal.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { integer } from '../../../src' -test("Invalid integer decimal", () => { - const data = 3.14; - const [err, res] = validate(data, integer()); - expect(res).toBeUndefined(); +test('Invalid integer decimal', () => { + const data = 3.14 + const [err, res] = validate(data, integer()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid integer decimal", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/integer/invalid.ts b/test/validation/integer/invalid.ts index 3544b3bd..511cee34 100644 --- a/test/validation/integer/invalid.ts +++ b/test/validation/integer/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { integer } from '../../../src' -test("Invalid integer", () => { - const data = 'invalid'; - const [err, res] = validate(data, integer()); - expect(res).toBeUndefined(); +test('Invalid integer', () => { + const data = 'invalid' + const [err, res] = validate(data, integer()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid integer", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/integer/valid.ts b/test/validation/integer/valid.ts index 27a81951..dce4d4d3 100644 --- a/test/validation/integer/valid.ts +++ b/test/validation/integer/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { integer } from '../../../src' -test("Valid integer", () => { - const data = 42; - assert(data, integer()); - expect(data).toStrictEqual(42); -}); +test('Valid integer', () => { + const data = 42 + assert(data, integer()) + expect(data).toStrictEqual(42) +}) diff --git a/test/validation/intersection/invalid-refinement.ts b/test/validation/intersection/invalid-refinement.ts index 455018e4..dc924594 100644 --- a/test/validation/intersection/invalid-refinement.ts +++ b/test/validation/intersection/invalid-refinement.ts @@ -1,14 +1,14 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { intersection, refine, number } from '../../../src' const A = number() const B = refine(number(), 'positive', (value) => value > 0) -test("Invalid intersection refinement", () => { - const data = -1; - const [err, res] = validate(data, intersection([A, B])); - expect(res).toBeUndefined(); +test('Invalid intersection refinement', () => { + const data = -1 + const [err, res] = validate(data, intersection([A, B])) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -18,5 +18,5 @@ test("Invalid intersection refinement", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/intersection/invalid.ts b/test/validation/intersection/invalid.ts index 4522c953..d69cc21c 100644 --- a/test/validation/intersection/invalid.ts +++ b/test/validation/intersection/invalid.ts @@ -1,18 +1,18 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { type, intersection, string, number } from '../../../src' const A = type({ a: string() }) const B = type({ b: number() }) -test("Invalid intersection", () => { +test('Invalid intersection', () => { const data = { a: 'a', b: 'invalid', - }; + } - const [err, res] = validate(data, intersection([A, B])); - expect(res).toBeUndefined(); + const [err, res] = validate(data, intersection([A, B])) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -22,5 +22,5 @@ test("Invalid intersection", () => { path: ['b'], branch: [data, data.b], }, - ]); -}); + ]) +}) diff --git a/test/validation/intersection/valid-refinement.ts b/test/validation/intersection/valid-refinement.ts index 590617c7..213e9a71 100644 --- a/test/validation/intersection/valid-refinement.ts +++ b/test/validation/intersection/valid-refinement.ts @@ -1,12 +1,12 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { intersection, refine, number } from '../../../src' const A = number() const B = refine(number(), 'positive', (value) => value > 0) -test("Valid intersection refinement", () => { - const data = 1; - assert(data, intersection([A, B])); - expect(data).toStrictEqual(1); -}); +test('Valid intersection refinement', () => { + const data = 1 + assert(data, intersection([A, B])) + expect(data).toStrictEqual(1) +}) diff --git a/test/validation/intersection/valid.ts b/test/validation/intersection/valid.ts index b98bc527..992e06e3 100644 --- a/test/validation/intersection/valid.ts +++ b/test/validation/intersection/valid.ts @@ -1,20 +1,20 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, intersection, string, number } from '../../../src' const A = type({ a: string() }) const B = type({ b: number() }) -test("Valid intersection", () => { +test('Valid intersection', () => { const data = { a: 'a', b: 42, - }; + } - assert(data, intersection([A, B])); + assert(data, intersection([A, B])) expect(data).toStrictEqual({ a: 'a', b: 42, - }); -}); + }) +}) diff --git a/test/validation/lazy/invalid.ts b/test/validation/lazy/invalid.ts index 54bd59dc..69a06be7 100644 --- a/test/validation/lazy/invalid.ts +++ b/test/validation/lazy/invalid.ts @@ -1,11 +1,14 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { lazy, string } from '../../../src' -test("Invalid lazy", () => { - const data = 3; - const [err, res] = validate(data, lazy(() => string())); - expect(res).toBeUndefined(); +test('Invalid lazy', () => { + const data = 3 + const [err, res] = validate( + data, + lazy(() => string()) + ) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +18,5 @@ test("Invalid lazy", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/lazy/valid.ts b/test/validation/lazy/valid.ts index c4922054..3fa45b18 100644 --- a/test/validation/lazy/valid.ts +++ b/test/validation/lazy/valid.ts @@ -1,9 +1,12 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { lazy, string } from '../../../src' -test("Valid lazy", () => { - const data = 'two'; - assert(data, lazy(() => string())); - expect(data).toStrictEqual('two'); -}); +test('Valid lazy', () => { + const data = 'two' + assert( + data, + lazy(() => string()) + ) + expect(data).toStrictEqual('two') +}) diff --git a/test/validation/lazy/with-refiners.ts b/test/validation/lazy/with-refiners.ts index 5dcbcc24..813576a9 100644 --- a/test/validation/lazy/with-refiners.ts +++ b/test/validation/lazy/with-refiners.ts @@ -1,11 +1,14 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { lazy, nonempty, string } from '../../../src' -test("With lazy refiners", () => { - const data = ''; - const [err, res] = validate(data, lazy(() => nonempty(string()))); - expect(res).toBeUndefined(); +test('With lazy refiners', () => { + const data = '' + const [err, res] = validate( + data, + lazy(() => nonempty(string())) + ) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +18,5 @@ test("With lazy refiners", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/literal/invalid.ts b/test/validation/literal/invalid.ts index 207e7f5a..0ae52a9c 100644 --- a/test/validation/literal/invalid.ts +++ b/test/validation/literal/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { literal } from '../../../src' -test("Invalid literal", () => { - const data = false; - const [err, res] = validate(data, literal(42)); - expect(res).toBeUndefined(); +test('Invalid literal', () => { + const data = false + const [err, res] = validate(data, literal(42)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid literal", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/literal/valid.ts b/test/validation/literal/valid.ts index 52371783..6b5f912a 100644 --- a/test/validation/literal/valid.ts +++ b/test/validation/literal/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { literal } from '../../../src' -test("Valid literal", () => { - const data = 42; - assert(data, literal(42)); - expect(data).toStrictEqual(42); -}); +test('Valid literal', () => { + const data = 42 + assert(data, literal(42)) + expect(data).toStrictEqual(42) +}) diff --git a/test/validation/map/invalid-opaque.ts b/test/validation/map/invalid-opaque.ts index 14b33980..6e15ac5c 100644 --- a/test/validation/map/invalid-opaque.ts +++ b/test/validation/map/invalid-opaque.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { map } from '../../../src' -test("Invalid map opaque", () => { - const data = 'invalid'; - const [err, res] = validate(data, map()); - expect(res).toBeUndefined(); +test('Invalid map opaque', () => { + const data = 'invalid' + const [err, res] = validate(data, map()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid map opaque", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/map/invalid-property.ts b/test/validation/map/invalid-property.ts index f26f63b1..dec77f68 100644 --- a/test/validation/map/invalid-property.ts +++ b/test/validation/map/invalid-property.ts @@ -1,15 +1,15 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { map, string, number } from '../../../src' -test("Invalid map property", () => { +test('Invalid map property', () => { const data = new Map([ ['a', 'a'], ['b', 'b'], - ]); + ]) - const [err, res] = validate(data, map(string(), number())); - expect(res).toBeUndefined(); + const [err, res] = validate(data, map(string(), number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -26,5 +26,5 @@ test("Invalid map property", () => { path: ['b'], branch: [data, 'b'], }, - ]); -}); + ]) +}) diff --git a/test/validation/map/invalid.ts b/test/validation/map/invalid.ts index a165a6a6..562c1665 100644 --- a/test/validation/map/invalid.ts +++ b/test/validation/map/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { map, string, number } from '../../../src' -test("Invalid map", () => { - const data = 'invalid'; - const [err, res] = validate(data, map(string(), number())); - expect(res).toBeUndefined(); +test('Invalid map', () => { + const data = 'invalid' + const [err, res] = validate(data, map(string(), number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid map", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/map/valid.ts b/test/validation/map/valid.ts index 4eb6484e..9224345e 100644 --- a/test/validation/map/valid.ts +++ b/test/validation/map/valid.ts @@ -1,17 +1,19 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { map, string, number } from '../../../src' -test("Valid map", () => { +test('Valid map', () => { const data = new Map([ ['a', 1], ['b', 2], - ]); + ]) - assert(data, map(string(), number())); + assert(data, map(string(), number())) - expect(data).toStrictEqual(new Map([ - ['a', 1], - ['b', 2], - ])); -}); + expect(data).toStrictEqual( + new Map([ + ['a', 1], + ['b', 2], + ]) + ) +}) diff --git a/test/validation/max/invalid-exclusive.ts b/test/validation/max/invalid-exclusive.ts index 389a5328..fc835105 100644 --- a/test/validation/max/invalid-exclusive.ts +++ b/test/validation/max/invalid-exclusive.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { number, max } from '../../../src' -test("Invalid max exclusive", () => { - const data = 0; - const [err, res] = validate(data, max(number(), 0, { exclusive: true })); - expect(res).toBeUndefined(); +test('Invalid max exclusive', () => { + const data = 0 + const [err, res] = validate(data, max(number(), 0, { exclusive: true })) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid max exclusive", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/max/invalid.ts b/test/validation/max/invalid.ts index 77590224..d6e8b693 100644 --- a/test/validation/max/invalid.ts +++ b/test/validation/max/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { number, max } from '../../../src' -test("Invalid max", () => { - const data = 1; - const [err, res] = validate(data, max(number(), 0)); - expect(res).toBeUndefined(); +test('Invalid max', () => { + const data = 1 + const [err, res] = validate(data, max(number(), 0)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid max", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/max/valid-inclusive.ts b/test/validation/max/valid-inclusive.ts index b5dab7ae..e9673cbf 100644 --- a/test/validation/max/valid-inclusive.ts +++ b/test/validation/max/valid-inclusive.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, max } from '../../../src' -test("Valid max inclusive", () => { - const data = 0; - assert(data, max(number(), 0)); - expect(data).toStrictEqual(0); -}); +test('Valid max inclusive', () => { + const data = 0 + assert(data, max(number(), 0)) + expect(data).toStrictEqual(0) +}) diff --git a/test/validation/max/valid.ts b/test/validation/max/valid.ts index fb1f4444..0fc87e32 100644 --- a/test/validation/max/valid.ts +++ b/test/validation/max/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, max } from '../../../src' -test("Valid max", () => { - const data = -1; - assert(data, max(number(), 0)); - expect(data).toStrictEqual(-1); -}); +test('Valid max', () => { + const data = -1 + assert(data, max(number(), 0)) + expect(data).toStrictEqual(-1) +}) diff --git a/test/validation/min/invalid-exclusive.ts b/test/validation/min/invalid-exclusive.ts index 66289d77..32fc5407 100644 --- a/test/validation/min/invalid-exclusive.ts +++ b/test/validation/min/invalid-exclusive.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { number, min } from '../../../src' -test("Invalid min exclusive", () => { - const data = 0; - const [err, res] = validate(data, min(number(), 0, { exclusive: true })); - expect(res).toBeUndefined(); +test('Invalid min exclusive', () => { + const data = 0 + const [err, res] = validate(data, min(number(), 0, { exclusive: true })) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid min exclusive", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/min/invalid.ts b/test/validation/min/invalid.ts index 34f348cd..74aa3404 100644 --- a/test/validation/min/invalid.ts +++ b/test/validation/min/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { number, min } from '../../../src' -test("Invalid min", () => { - const data = -1; - const [err, res] = validate(data, min(number(), 0)); - expect(res).toBeUndefined(); +test('Invalid min', () => { + const data = -1 + const [err, res] = validate(data, min(number(), 0)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid min", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/min/valid-inclusive.ts b/test/validation/min/valid-inclusive.ts index 1e29fa8d..7fe72045 100644 --- a/test/validation/min/valid-inclusive.ts +++ b/test/validation/min/valid-inclusive.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, min } from '../../../src' -test("Valid min inclusive", () => { - const data = 0; - assert(data, min(number(), 0)); - expect(data).toStrictEqual(0); -}); +test('Valid min inclusive', () => { + const data = 0 + assert(data, min(number(), 0)) + expect(data).toStrictEqual(0) +}) diff --git a/test/validation/min/valid.ts b/test/validation/min/valid.ts index 966c7a0b..bbcfbee2 100644 --- a/test/validation/min/valid.ts +++ b/test/validation/min/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, min } from '../../../src' -test("Valid min", () => { - const data = 3; - assert(data, min(number(), 0)); - expect(data).toStrictEqual(3); -}); +test('Valid min', () => { + const data = 3 + assert(data, min(number(), 0)) + expect(data).toStrictEqual(3) +}) diff --git a/test/validation/never/invalid.ts b/test/validation/never/invalid.ts index 6b58f81b..8965a6e9 100644 --- a/test/validation/never/invalid.ts +++ b/test/validation/never/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { never } from '../../../src' -test("Invalid never", () => { - const data = true; - const [err, res] = validate(data, never()); - expect(res).toBeUndefined(); +test('Invalid never', () => { + const data = true + const [err, res] = validate(data, never()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid never", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/nullable/invalid.ts b/test/validation/nullable/invalid.ts index 4b8ef7cd..8df7b8e9 100644 --- a/test/validation/nullable/invalid.ts +++ b/test/validation/nullable/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { number, nullable } from '../../../src' -test("Invalid nullable", () => { - const data = 'invalid'; - const [err, res] = validate(data, nullable(number())); - expect(res).toBeUndefined(); +test('Invalid nullable', () => { + const data = 'invalid' + const [err, res] = validate(data, nullable(number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid nullable", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/nullable/valid-defined-nested.ts b/test/validation/nullable/valid-defined-nested.ts index 59a9ba62..75e76f37 100644 --- a/test/validation/nullable/valid-defined-nested.ts +++ b/test/validation/nullable/valid-defined-nested.ts @@ -1,20 +1,23 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, string, number, nullable } from '../../../src' -test("Valid nullable defined nested", () => { +test('Valid nullable defined nested', () => { const data = { name: 'Jill', age: 42, - }; + } - assert(data, type({ - name: nullable(string()), - age: number(), - })); + assert( + data, + type({ + name: nullable(string()), + age: number(), + }) + ) expect(data).toStrictEqual({ name: 'Jill', age: 42, - }); -}); + }) +}) diff --git a/test/validation/nullable/valid-defined.ts b/test/validation/nullable/valid-defined.ts index 4334bf06..1820a30b 100644 --- a/test/validation/nullable/valid-defined.ts +++ b/test/validation/nullable/valid-defined.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, nullable } from '../../../src' -test("Valid nullable defined", () => { - const data = 42; - assert(data, nullable(number())); - expect(data).toStrictEqual(42); -}); +test('Valid nullable defined', () => { + const data = 42 + assert(data, nullable(number())) + expect(data).toStrictEqual(42) +}) diff --git a/test/validation/nullable/valid-null-nested.ts b/test/validation/nullable/valid-null-nested.ts index 21e2f5be..488c431b 100644 --- a/test/validation/nullable/valid-null-nested.ts +++ b/test/validation/nullable/valid-null-nested.ts @@ -1,20 +1,23 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, string, number, nullable } from '../../../src' -test("Valid nullable null nested", () => { +test('Valid nullable null nested', () => { const data = { name: null, age: 42, - }; + } - assert(data, type({ - name: nullable(string()), - age: number(), - })); + assert( + data, + type({ + name: nullable(string()), + age: number(), + }) + ) expect(data).toStrictEqual({ name: null, age: 42, - }); -}); + }) +}) diff --git a/test/validation/nullable/valid-null.ts b/test/validation/nullable/valid-null.ts index 38768520..0e91f6ba 100644 --- a/test/validation/nullable/valid-null.ts +++ b/test/validation/nullable/valid-null.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, nullable } from '../../../src' -test("Valid nullable null", () => { - const data = null; - assert(data, nullable(number())); - expect(data).toStrictEqual(null); -}); +test('Valid nullable null', () => { + const data = null + assert(data, nullable(number())) + expect(data).toStrictEqual(null) +}) diff --git a/test/validation/number/invalid.ts b/test/validation/number/invalid.ts index cf5a8550..da946a34 100644 --- a/test/validation/number/invalid.ts +++ b/test/validation/number/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { number } from '../../../src' -test("Invalid number", () => { - const data = 'invalid'; - const [err, res] = validate(data, number()); - expect(res).toBeUndefined(); +test('Invalid number', () => { + const data = 'invalid' + const [err, res] = validate(data, number()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid number", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/number/valid.ts b/test/validation/number/valid.ts index 534354eb..6f54c5c9 100644 --- a/test/validation/number/valid.ts +++ b/test/validation/number/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number } from '../../../src' -test("Valid number", () => { - const data = 42; - assert(data, number()); - expect(data).toStrictEqual(42); -}); +test('Valid number', () => { + const data = 42 + assert(data, number()) + expect(data).toStrictEqual(42) +}) diff --git a/test/validation/object/invalid-array.ts b/test/validation/object/invalid-array.ts index 4c59b6d0..901bfd30 100644 --- a/test/validation/object/invalid-array.ts +++ b/test/validation/object/invalid-array.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { object } from '../../../src' -test("Invalid object array", () => { - const data = []; - const [err, res] = validate(data, object()); - expect(res).toBeUndefined(); +test('Invalid object array', () => { + const data = [] + const [err, res] = validate(data, object()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid object array", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/object/invalid-element-nested.ts b/test/validation/object/invalid-element-nested.ts index 5cdeb466..0048e494 100644 --- a/test/validation/object/invalid-element-nested.ts +++ b/test/validation/object/invalid-element-nested.ts @@ -1,19 +1,22 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { object, array, string } from '../../../src' -test("Invalid object element nested", () => { +test('Invalid object element nested', () => { const data = { name: 'john', emails: ['name@example.com', false], - }; + } - const [err, res] = validate(data, object({ - name: string(), - emails: array(string()), - })); + const [err, res] = validate( + data, + object({ + name: string(), + emails: array(string()), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -23,5 +26,5 @@ test("Invalid object element nested", () => { path: ['emails', 1], branch: [data, data.emails, data.emails[1]], }, - ]); -}); + ]) +}) diff --git a/test/validation/object/invalid-opaque.ts b/test/validation/object/invalid-opaque.ts index 3adf8dc6..14f8059d 100644 --- a/test/validation/object/invalid-opaque.ts +++ b/test/validation/object/invalid-opaque.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { object } from '../../../src' -test("Invalid object opaque", () => { - const data = 'invalid'; - const [err, res] = validate(data, object()); - expect(res).toBeUndefined(); +test('Invalid object opaque', () => { + const data = 'invalid' + const [err, res] = validate(data, object()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid object opaque", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/object/invalid-property-nested.ts b/test/validation/object/invalid-property-nested.ts index 027a77a3..19499812 100644 --- a/test/validation/object/invalid-property-nested.ts +++ b/test/validation/object/invalid-property-nested.ts @@ -1,25 +1,28 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { object, string } from '../../../src' -test("Invalid object property nested", () => { +test('Invalid object property nested', () => { const data = { name: 'john', address: { street: 123, city: 'Springfield', }, - }; + } - const [err, res] = validate(data, object({ - name: string(), - address: object({ - street: string(), - city: string(), - }), - })); + const [err, res] = validate( + data, + object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -29,5 +32,5 @@ test("Invalid object property nested", () => { path: ['address', 'street'], branch: [data, data.address, data.address.street], }, - ]); -}); + ]) +}) diff --git a/test/validation/object/invalid-property-unknown.ts b/test/validation/object/invalid-property-unknown.ts index d00a80c4..0af71381 100644 --- a/test/validation/object/invalid-property-unknown.ts +++ b/test/validation/object/invalid-property-unknown.ts @@ -1,20 +1,23 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { object, string, number } from '../../../src' -test("Invalid object property unknown", () => { +test('Invalid object property unknown', () => { const data = { name: 'john', age: 42, unknown: true, - }; + } - const [err, res] = validate(data, object({ - name: string(), - age: number(), - })); + const [err, res] = validate( + data, + object({ + name: string(), + age: number(), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -24,5 +27,5 @@ test("Invalid object property unknown", () => { path: ['unknown'], branch: [data, data.unknown], }, - ]); -}); + ]) +}) diff --git a/test/validation/object/invalid-property.ts b/test/validation/object/invalid-property.ts index fa42c259..7cc205eb 100644 --- a/test/validation/object/invalid-property.ts +++ b/test/validation/object/invalid-property.ts @@ -1,21 +1,24 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { object, string, number } from '../../../src' -test("Invalid object property", () => { +test('Invalid object property', () => { const data = { name: 'john', age: 'invalid', height: 2, - }; + } - const [err, res] = validate(data, object({ - name: string(), - age: number(), - height: string(), - })); + const [err, res] = validate( + data, + object({ + name: string(), + age: number(), + height: string(), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -32,5 +35,5 @@ test("Invalid object property", () => { path: ['height'], branch: [data, data.height], }, - ]); -}); + ]) +}) diff --git a/test/validation/object/invalid-referential.ts b/test/validation/object/invalid-referential.ts index 6c2ca916..b4549c3a 100644 --- a/test/validation/object/invalid-referential.ts +++ b/test/validation/object/invalid-referential.ts @@ -1,25 +1,28 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { object, string, pattern, refine } from '../../../src' const Section = pattern(string(), /^\d+(\.\d+)*$/) -test("Invalid object referential", () => { +test('Invalid object referential', () => { const data = { section: '1', subsection: '2.1', - }; + } - const [err, res] = validate(data, object({ - section: Section, - subsection: refine(Section, 'Subsection', (value, ctx) => { - const { branch } = ctx - const parent = branch[0] - return value.startsWith(`${parent.section}.`) - }), - })); + const [err, res] = validate( + data, + object({ + section: Section, + subsection: refine(Section, 'Subsection', (value, ctx) => { + const { branch } = ctx + const parent = branch[0] + return value.startsWith(`${parent.section}.`) + }), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -29,5 +32,5 @@ test("Invalid object referential", () => { path: ['subsection'], branch: [data, data.subsection], }, - ]); -}); + ]) +}) diff --git a/test/validation/object/invalid.ts b/test/validation/object/invalid.ts index 194960ce..91dc3ce3 100644 --- a/test/validation/object/invalid.ts +++ b/test/validation/object/invalid.ts @@ -1,16 +1,19 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { object, string, number } from '../../../src' -test("Invalid object", () => { - const data = 'invalid'; +test('Invalid object', () => { + const data = 'invalid' - const [err, res] = validate(data, object({ - name: string(), - age: number(), - })); + const [err, res] = validate( + data, + object({ + name: string(), + age: number(), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -20,5 +23,5 @@ test("Invalid object", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/object/valid-frozen.ts b/test/validation/object/valid-frozen.ts index 8a0fd91b..f196c125 100644 --- a/test/validation/object/valid-frozen.ts +++ b/test/validation/object/valid-frozen.ts @@ -1,20 +1,23 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { object, string, number } from '../../../src' -test("Valid object frozen", () => { +test('Valid object frozen', () => { const data = Object.freeze({ name: 'john', age: 42, - }); + }) - const res = create(data, object({ - name: string(), - age: number(), - })); + const res = create( + data, + object({ + name: string(), + age: number(), + }) + ) expect(res).toStrictEqual({ name: 'john', age: 42, - }); -}); + }) +}) diff --git a/test/validation/object/valid-nested.ts b/test/validation/object/valid-nested.ts index d66d0b46..bddcafb5 100644 --- a/test/validation/object/valid-nested.ts +++ b/test/validation/object/valid-nested.ts @@ -1,23 +1,26 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { object, string } from '../../../src' -test("Valid object nested", () => { +test('Valid object nested', () => { const data = { name: 'john', address: { street: '123 Fake St', city: 'Springfield', }, - }; + } - assert(data, object({ - name: string(), - address: object({ - street: string(), - city: string(), - }), - })); + assert( + data, + object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), + }) + ) expect(data).toStrictEqual({ name: 'john', @@ -25,5 +28,5 @@ test("Valid object nested", () => { street: '123 Fake St', city: 'Springfield', }, - }); -}); + }) +}) diff --git a/test/validation/object/valid-opaque.ts b/test/validation/object/valid-opaque.ts index 5742746a..c03c8aad 100644 --- a/test/validation/object/valid-opaque.ts +++ b/test/validation/object/valid-opaque.ts @@ -1,17 +1,17 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { object } from '../../../src' -test("Valid object opaque", () => { +test('Valid object opaque', () => { const data = { a: 'string', b: 42, - }; + } - assert(data, object()); + assert(data, object()) expect(data).toStrictEqual({ a: 'string', b: 42, - }); -}); + }) +}) diff --git a/test/validation/object/valid-referential.ts b/test/validation/object/valid-referential.ts index 526d5949..e938dc40 100644 --- a/test/validation/object/valid-referential.ts +++ b/test/validation/object/valid-referential.ts @@ -1,26 +1,29 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { object, string, pattern, refine } from '../../../src' const Section = pattern(string(), /^\d+(\.\d+)*$/) -test("Valid object referential", () => { +test('Valid object referential', () => { const data = { section: '1', subsection: '1.1', - }; + } - assert(data, object({ - section: Section, - subsection: refine(Section, 'Subsection', (value, ctx) => { - const { branch } = ctx - const parent = branch[0] - return value.startsWith(`${parent.section}.`) - }), - })); + assert( + data, + object({ + section: Section, + subsection: refine(Section, 'Subsection', (value, ctx) => { + const { branch } = ctx + const parent = branch[0] + return value.startsWith(`${parent.section}.`) + }), + }) + ) expect(data).toStrictEqual({ section: '1', subsection: '1.1', - }); -}); + }) +}) diff --git a/test/validation/object/valid.ts b/test/validation/object/valid.ts index 2d3e3687..d195a92d 100644 --- a/test/validation/object/valid.ts +++ b/test/validation/object/valid.ts @@ -1,20 +1,23 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { object, string, number } from '../../../src' -test("Valid object", () => { +test('Valid object', () => { const data = { name: 'john', age: 42, - }; + } - assert(data, object({ - name: string(), - age: number(), - })); + assert( + data, + object({ + name: string(), + age: number(), + }) + ) expect(data).toStrictEqual({ name: 'john', age: 42, - }); -}); + }) +}) diff --git a/test/validation/omit/invalid-element-nested.ts b/test/validation/omit/invalid-element-nested.ts index 1e250e0a..aaf6fc0f 100644 --- a/test/validation/omit/invalid-element-nested.ts +++ b/test/validation/omit/invalid-element-nested.ts @@ -1,21 +1,24 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { omit, object, array, string } from '../../../src' -test("Invalid omit element nested", () => { +test('Invalid omit element nested', () => { const data = { emails: ['name@example.com', false], - }; + } - const [err, res] = validate(data, omit( - object({ - name: string(), - emails: array(string()), - }), - ['name'] - )); + const [err, res] = validate( + data, + omit( + object({ + name: string(), + emails: array(string()), + }), + ['name'] + ) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -25,5 +28,5 @@ test("Invalid omit element nested", () => { path: ['emails', 1], branch: [data, data.emails, data.emails[1]], }, - ]); -}); + ]) +}) diff --git a/test/validation/omit/invalid-property-nested.ts b/test/validation/omit/invalid-property-nested.ts index 50006128..107584e9 100644 --- a/test/validation/omit/invalid-property-nested.ts +++ b/test/validation/omit/invalid-property-nested.ts @@ -1,27 +1,30 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { omit, object, string } from '../../../src' -test("Invalid omit property nested", () => { +test('Invalid omit property nested', () => { const data = { address: { street: 123, city: 'Springfield', }, - }; + } - const [err, res] = validate(data, omit( - object({ - name: string(), - address: object({ - street: string(), - city: string(), + const [err, res] = validate( + data, + omit( + object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), }), - }), - ['name'] - )); + ['name'] + ) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -31,5 +34,5 @@ test("Invalid omit property nested", () => { path: ['address', 'street'], branch: [data, data.address, data.address.street], }, - ]); -}); + ]) +}) diff --git a/test/validation/omit/invalid-property-unknown.ts b/test/validation/omit/invalid-property-unknown.ts index d8eb5f54..9e48d27e 100644 --- a/test/validation/omit/invalid-property-unknown.ts +++ b/test/validation/omit/invalid-property-unknown.ts @@ -1,22 +1,25 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { omit, object, string, number } from '../../../src' -test("Invalid omit property unknown", () => { +test('Invalid omit property unknown', () => { const data = { name: 'john', age: 42, - }; + } - const [err, res] = validate(data, omit( - object({ - name: string(), - age: number(), - }), - ['age'] - )); + const [err, res] = validate( + data, + omit( + object({ + name: string(), + age: number(), + }), + ['age'] + ) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -26,5 +29,5 @@ test("Invalid omit property unknown", () => { path: ['age'], branch: [data, data.age], }, - ]); -}); + ]) +}) diff --git a/test/validation/omit/invalid-property.ts b/test/validation/omit/invalid-property.ts index ab76fbd1..5b5a8cec 100644 --- a/test/validation/omit/invalid-property.ts +++ b/test/validation/omit/invalid-property.ts @@ -1,21 +1,24 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { omit, object, string, number } from '../../../src' -test("Invalid omit property", () => { +test('Invalid omit property', () => { const data = { age: 'invalid', - }; + } - const [err, res] = validate(data, omit( - object({ - name: string(), - age: number(), - }), - ['name'] - )); + const [err, res] = validate( + data, + omit( + object({ + name: string(), + age: number(), + }), + ['name'] + ) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -25,5 +28,5 @@ test("Invalid omit property", () => { path: ['age'], branch: [data, data.age], }, - ]); -}); + ]) +}) diff --git a/test/validation/omit/invalid.ts b/test/validation/omit/invalid.ts index 018bd303..6ca3fca3 100644 --- a/test/validation/omit/invalid.ts +++ b/test/validation/omit/invalid.ts @@ -1,19 +1,22 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { omit, object, string, number } from '../../../src' -test("Invalid omit", () => { - const data = 'invalid'; +test('Invalid omit', () => { + const data = 'invalid' - const [err, res] = validate(data, omit( - object({ - name: string(), - age: number(), - }), - ['age'] - )); + const [err, res] = validate( + data, + omit( + object({ + name: string(), + age: number(), + }), + ['age'] + ) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -23,5 +26,5 @@ test("Invalid omit", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/omit/valid-nested.ts b/test/validation/omit/valid-nested.ts index 2a0ca00a..02e2b1ec 100644 --- a/test/validation/omit/valid-nested.ts +++ b/test/validation/omit/valid-nested.ts @@ -1,30 +1,33 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { omit, object, string } from '../../../src' -test("Valid omit nested", () => { +test('Valid omit nested', () => { const data = { address: { street: '123 Fake St', city: 'Springfield', }, - }; + } - assert(data, omit( - object({ - name: string(), - address: object({ - street: string(), - city: string(), + assert( + data, + omit( + object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), }), - }), - ['name'] - )); + ['name'] + ) + ) expect(data).toStrictEqual({ address: { street: '123 Fake St', city: 'Springfield', }, - }); -}); + }) +}) diff --git a/test/validation/omit/valid-type.ts b/test/validation/omit/valid-type.ts index 76fa0536..516d0a99 100644 --- a/test/validation/omit/valid-type.ts +++ b/test/validation/omit/valid-type.ts @@ -1,23 +1,26 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { omit, type, string, number } from '../../../src' -test("Valid omit type", () => { +test('Valid omit type', () => { const data = { name: 'john', unknownProperty: 'unknown', - }; + } - assert(data, omit( - type({ - name: string(), - age: number(), - }), - ['age'] - )); + assert( + data, + omit( + type({ + name: string(), + age: number(), + }), + ['age'] + ) + ) expect(data).toStrictEqual({ name: 'john', unknownProperty: 'unknown', - }); -}); + }) +}) diff --git a/test/validation/omit/valid.ts b/test/validation/omit/valid.ts index f9e028bd..a23ed0c5 100644 --- a/test/validation/omit/valid.ts +++ b/test/validation/omit/valid.ts @@ -1,21 +1,24 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { omit, object, string, number } from '../../../src' -test("Valid omit", () => { +test('Valid omit', () => { const data = { name: 'john', - }; + } - assert(data, omit( - object({ - name: string(), - age: number(), - }), - ['age'] - )); + assert( + data, + omit( + object({ + name: string(), + age: number(), + }), + ['age'] + ) + ) expect(data).toStrictEqual({ name: 'john', - }); -}); + }) +}) diff --git a/test/validation/optional/invalid.ts b/test/validation/optional/invalid.ts index 5340d169..4d5ea6ef 100644 --- a/test/validation/optional/invalid.ts +++ b/test/validation/optional/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { number, optional } from '../../../src' -test("Invalid optional", () => { - const data = 'invalid'; - const [err, res] = validate(data, optional(number())); - expect(res).toBeUndefined(); +test('Invalid optional', () => { + const data = 'invalid' + const [err, res] = validate(data, optional(number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid optional", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/optional/valid-defined-nested.ts b/test/validation/optional/valid-defined-nested.ts index 0e007b9b..9b2250fd 100644 --- a/test/validation/optional/valid-defined-nested.ts +++ b/test/validation/optional/valid-defined-nested.ts @@ -1,20 +1,23 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, string, number, optional } from '../../../src' -test("Valid optional defined nested", () => { +test('Valid optional defined nested', () => { const data = { name: 'Jill', age: 42, - }; + } - assert(data, type({ - name: optional(string()), - age: number(), - })); + assert( + data, + type({ + name: optional(string()), + age: number(), + }) + ) expect(data).toStrictEqual({ name: 'Jill', age: 42, - }); -}); + }) +}) diff --git a/test/validation/optional/valid-defined.ts b/test/validation/optional/valid-defined.ts index cdefc40b..3e871614 100644 --- a/test/validation/optional/valid-defined.ts +++ b/test/validation/optional/valid-defined.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, optional } from '../../../src' -test("Valid optional defined", () => { - const data = 42; - assert(data, optional(number())); - expect(data).toStrictEqual(42); -}); +test('Valid optional defined', () => { + const data = 42 + assert(data, optional(number())) + expect(data).toStrictEqual(42) +}) diff --git a/test/validation/optional/valid-undefined-nested.ts b/test/validation/optional/valid-undefined-nested.ts index e9bf70c7..01cb566f 100644 --- a/test/validation/optional/valid-undefined-nested.ts +++ b/test/validation/optional/valid-undefined-nested.ts @@ -1,18 +1,21 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, string, number, optional } from '../../../src' -test("Valid optional undefined nested", () => { +test('Valid optional undefined nested', () => { const data = { age: 42, - }; + } - assert(data, type({ - name: optional(string()), - age: number(), - })); + assert( + data, + type({ + name: optional(string()), + age: number(), + }) + ) expect(data).toStrictEqual({ age: 42, - }); -}); + }) +}) diff --git a/test/validation/optional/valid-undefined.ts b/test/validation/optional/valid-undefined.ts index 4ad5fa25..38da0734 100644 --- a/test/validation/optional/valid-undefined.ts +++ b/test/validation/optional/valid-undefined.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, optional } from '../../../src' -test("Valid optional undefined", () => { - const data = undefined; - assert(data, optional(number())); - expect(data).toStrictEqual(undefined); -}); +test('Valid optional undefined', () => { + const data = undefined + assert(data, optional(number())) + expect(data).toStrictEqual(undefined) +}) diff --git a/test/validation/partial/composed.ts b/test/validation/partial/composed.ts index d68c77e6..e908dbc0 100644 --- a/test/validation/partial/composed.ts +++ b/test/validation/partial/composed.ts @@ -1,20 +1,23 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { partial, object, string, number } from '../../../src' -test("Composed partial", () => { +test('Composed partial', () => { const data = { name: 'john', - }; + } - assert(data, partial( - object({ - name: string(), - age: number(), - }) - )); + assert( + data, + partial( + object({ + name: string(), + age: number(), + }) + ) + ) expect(data).toStrictEqual({ name: 'john', - }); -}); + }) +}) diff --git a/test/validation/partial/invalid-property-unknown.ts b/test/validation/partial/invalid-property-unknown.ts index 3d0e4d72..7160a95b 100644 --- a/test/validation/partial/invalid-property-unknown.ts +++ b/test/validation/partial/invalid-property-unknown.ts @@ -1,19 +1,22 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { partial, string, number } from '../../../src' -test("Invalid partial property unknown", () => { +test('Invalid partial property unknown', () => { const data = { name: 'john', unknown: true, - }; + } - const [err, res] = validate(data, partial({ - name: string(), - age: number(), - })); + const [err, res] = validate( + data, + partial({ + name: string(), + age: number(), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -23,5 +26,5 @@ test("Invalid partial property unknown", () => { path: ['unknown'], branch: [data, data.unknown], }, - ]); -}); + ]) +}) diff --git a/test/validation/partial/invalid-property.ts b/test/validation/partial/invalid-property.ts index f73d9185..cb988a12 100644 --- a/test/validation/partial/invalid-property.ts +++ b/test/validation/partial/invalid-property.ts @@ -1,18 +1,21 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { partial, string, number } from '../../../src' -test("Invalid partial property", () => { +test('Invalid partial property', () => { const data = { age: 'invalid', - }; + } - const [err, res] = validate(data, partial({ - name: string(), - age: number(), - })); + const [err, res] = validate( + data, + partial({ + name: string(), + age: number(), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -22,5 +25,5 @@ test("Invalid partial property", () => { path: ['age'], branch: [data, data.age], }, - ]); -}); + ]) +}) diff --git a/test/validation/partial/invalid.ts b/test/validation/partial/invalid.ts index bd65627e..65738584 100644 --- a/test/validation/partial/invalid.ts +++ b/test/validation/partial/invalid.ts @@ -1,16 +1,19 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { partial, string, number } from '../../../src' -test("Invalid partial", () => { - const data = 'invalid'; +test('Invalid partial', () => { + const data = 'invalid' - const [err, res] = validate(data, partial({ - name: string(), - age: number(), - })); + const [err, res] = validate( + data, + partial({ + name: string(), + age: number(), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -20,5 +23,5 @@ test("Invalid partial", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/partial/valid-empty.ts b/test/validation/partial/valid-empty.ts index 84d5c84b..c5ae1d82 100644 --- a/test/validation/partial/valid-empty.ts +++ b/test/validation/partial/valid-empty.ts @@ -1,14 +1,17 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { partial, string, number } from '../../../src' -test("Valid partial empty", () => { - const data = {}; +test('Valid partial empty', () => { + const data = {} - assert(data, partial({ - name: string(), - age: number(), - })); + assert( + data, + partial({ + name: string(), + age: number(), + }) + ) - expect(data).toStrictEqual({}); -}); + expect(data).toStrictEqual({}) +}) diff --git a/test/validation/partial/valid-full.ts b/test/validation/partial/valid-full.ts index 2cddd090..58a15c4b 100644 --- a/test/validation/partial/valid-full.ts +++ b/test/validation/partial/valid-full.ts @@ -1,20 +1,23 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { partial, string, number } from '../../../src' -test("Valid partial full", () => { +test('Valid partial full', () => { const data = { name: 'john', age: 42, - }; + } - assert(data, partial({ - name: string(), - age: number(), - })); + assert( + data, + partial({ + name: string(), + age: number(), + }) + ) expect(data).toStrictEqual({ name: 'john', age: 42, - }); -}); + }) +}) diff --git a/test/validation/partial/valid-partial.ts b/test/validation/partial/valid-partial.ts index 8be3450c..bda51d56 100644 --- a/test/validation/partial/valid-partial.ts +++ b/test/validation/partial/valid-partial.ts @@ -1,18 +1,21 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { partial, string, number } from '../../../src' -test("Valid partial partial", () => { +test('Valid partial partial', () => { const data = { name: 'john', - }; + } - assert(data, partial({ - name: string(), - age: number(), - })); + assert( + data, + partial({ + name: string(), + age: number(), + }) + ) expect(data).toStrictEqual({ name: 'john', - }); -}); + }) +}) diff --git a/test/validation/partial/valid-type.ts b/test/validation/partial/valid-type.ts index 5b1e630e..75c41424 100644 --- a/test/validation/partial/valid-type.ts +++ b/test/validation/partial/valid-type.ts @@ -1,22 +1,25 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, partial, string, type } from '../../../src' -test("Valid partial type", () => { +test('Valid partial type', () => { const data = { name: 'john', unknownProperty: true, - }; + } - assert(data, partial( - type({ - name: string(), - age: number(), - }) - )); + assert( + data, + partial( + type({ + name: string(), + age: number(), + }) + ) + ) expect(data).toStrictEqual({ name: 'john', unknownProperty: true, - }); -}); + }) +}) diff --git a/test/validation/pattern/invalid.ts b/test/validation/pattern/invalid.ts index d5e9f736..52b5c9d0 100644 --- a/test/validation/pattern/invalid.ts +++ b/test/validation/pattern/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { string, pattern } from '../../../src' -test("Invalid pattern", () => { - const data = 'invalid'; - const [err, res] = validate(data, pattern(string(), /\d+/)); - expect(res).toBeUndefined(); +test('Invalid pattern', () => { + const data = 'invalid' + const [err, res] = validate(data, pattern(string(), /\d+/)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid pattern", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/pattern/valid.ts b/test/validation/pattern/valid.ts index 4cb980b7..febae266 100644 --- a/test/validation/pattern/valid.ts +++ b/test/validation/pattern/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { string, pattern } from '../../../src' -test("Valid pattern", () => { - const data = '123'; - assert(data, pattern(string(), /\d+/)); - expect(data).toStrictEqual('123'); -}); +test('Valid pattern', () => { + const data = '123' + assert(data, pattern(string(), /\d+/)) + expect(data).toStrictEqual('123') +}) diff --git a/test/validation/pick/invalid-element-nested.ts b/test/validation/pick/invalid-element-nested.ts index 4838d09d..5c2fb725 100644 --- a/test/validation/pick/invalid-element-nested.ts +++ b/test/validation/pick/invalid-element-nested.ts @@ -1,21 +1,24 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { pick, object, array, string } from '../../../src' -test("Invalid pick element nested", () => { +test('Invalid pick element nested', () => { const data = { emails: ['name@example.com', false], - }; + } - const [err, res] = validate(data, pick( - object({ - name: string(), - emails: array(string()), - }), - ['emails'] - )); + const [err, res] = validate( + data, + pick( + object({ + name: string(), + emails: array(string()), + }), + ['emails'] + ) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -25,5 +28,5 @@ test("Invalid pick element nested", () => { path: ['emails', 1], branch: [data, data.emails, data.emails[1]], }, - ]); -}); + ]) +}) diff --git a/test/validation/pick/invalid-property-nested.ts b/test/validation/pick/invalid-property-nested.ts index b430175c..b75d602a 100644 --- a/test/validation/pick/invalid-property-nested.ts +++ b/test/validation/pick/invalid-property-nested.ts @@ -1,27 +1,30 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { pick, object, string } from '../../../src' -test("Invalid pick property nested", () => { +test('Invalid pick property nested', () => { const data = { address: { street: 123, city: 'Springfield', }, - }; + } - const [err, res] = validate(data, pick( - object({ - name: string(), - address: object({ - street: string(), - city: string(), + const [err, res] = validate( + data, + pick( + object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), }), - }), - ['address'] - )); + ['address'] + ) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -31,5 +34,5 @@ test("Invalid pick property nested", () => { path: ['address', 'street'], branch: [data, data.address, data.address.street], }, - ]); -}); + ]) +}) diff --git a/test/validation/pick/invalid-property-unknown.ts b/test/validation/pick/invalid-property-unknown.ts index f011313b..f2de7b01 100644 --- a/test/validation/pick/invalid-property-unknown.ts +++ b/test/validation/pick/invalid-property-unknown.ts @@ -1,22 +1,25 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { pick, object, string, number } from '../../../src' -test("Invalid pick property unknown", () => { +test('Invalid pick property unknown', () => { const data = { name: 'john', age: 42, - }; + } - const [err, res] = validate(data, pick( - object({ - name: string(), - age: number(), - }), - ['name'] - )); + const [err, res] = validate( + data, + pick( + object({ + name: string(), + age: number(), + }), + ['name'] + ) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -26,5 +29,5 @@ test("Invalid pick property unknown", () => { path: ['age'], branch: [data, data.age], }, - ]); -}); + ]) +}) diff --git a/test/validation/pick/invalid-property.ts b/test/validation/pick/invalid-property.ts index ebab1f0f..9e047a5c 100644 --- a/test/validation/pick/invalid-property.ts +++ b/test/validation/pick/invalid-property.ts @@ -1,21 +1,24 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { pick, object, string, number } from '../../../src' -test("Invalid pick property", () => { +test('Invalid pick property', () => { const data = { age: 'invalid', - }; + } - const [err, res] = validate(data, pick( - object({ - name: string(), - age: number(), - }), - ['age'] - )); + const [err, res] = validate( + data, + pick( + object({ + name: string(), + age: number(), + }), + ['age'] + ) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -25,5 +28,5 @@ test("Invalid pick property", () => { path: ['age'], branch: [data, data.age], }, - ]); -}); + ]) +}) diff --git a/test/validation/pick/invalid.ts b/test/validation/pick/invalid.ts index e9532c67..06e7474e 100644 --- a/test/validation/pick/invalid.ts +++ b/test/validation/pick/invalid.ts @@ -1,19 +1,22 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { pick, object, string, number } from '../../../src' -test("Invalid pick", () => { - const data = 'invalid'; +test('Invalid pick', () => { + const data = 'invalid' - const [err, res] = validate(data, pick( - object({ - name: string(), - age: number(), - }), - ['name'] - )); + const [err, res] = validate( + data, + pick( + object({ + name: string(), + age: number(), + }), + ['name'] + ) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -23,5 +26,5 @@ test("Invalid pick", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/pick/valid-nested.ts b/test/validation/pick/valid-nested.ts index 95edcd11..aec6f47b 100644 --- a/test/validation/pick/valid-nested.ts +++ b/test/validation/pick/valid-nested.ts @@ -1,30 +1,33 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { pick, object, string } from '../../../src' -test("Valid pick nested", () => { +test('Valid pick nested', () => { const data = { address: { street: '123 Fake St', city: 'Springfield', }, - }; + } - assert(data, pick( - object({ - name: string(), - address: object({ - street: string(), - city: string(), + assert( + data, + pick( + object({ + name: string(), + address: object({ + street: string(), + city: string(), + }), }), - }), - ['address'] - )); + ['address'] + ) + ) expect(data).toStrictEqual({ address: { street: '123 Fake St', city: 'Springfield', }, - }); -}); + }) +}) diff --git a/test/validation/pick/valid-type.ts b/test/validation/pick/valid-type.ts index cda58d8c..e8e6b505 100644 --- a/test/validation/pick/valid-type.ts +++ b/test/validation/pick/valid-type.ts @@ -1,23 +1,26 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, pick, string, type } from '../../../src' -test("Valid pick type", () => { +test('Valid pick type', () => { const data = { name: 'john', unknownProperty: true, - }; + } - assert(data, pick( - type({ - name: string(), - age: number(), - }), - ['name'] - )); + assert( + data, + pick( + type({ + name: string(), + age: number(), + }), + ['name'] + ) + ) expect(data).toStrictEqual({ name: 'john', unknownProperty: true, - }); -}); + }) +}) diff --git a/test/validation/pick/valid.ts b/test/validation/pick/valid.ts index cb9c200e..9777812e 100644 --- a/test/validation/pick/valid.ts +++ b/test/validation/pick/valid.ts @@ -1,21 +1,24 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { pick, object, string, number } from '../../../src' -test("Valid pick", () => { +test('Valid pick', () => { const data = { name: 'john', - }; + } - assert(data, pick( - object({ - name: string(), - age: number(), - }), - ['name'] - )); + assert( + data, + pick( + object({ + name: string(), + age: number(), + }), + ['name'] + ) + ) expect(data).toStrictEqual({ name: 'john', - }); -}); + }) +}) diff --git a/test/validation/record/invalid-array.ts b/test/validation/record/invalid-array.ts index c58b913b..62e56049 100644 --- a/test/validation/record/invalid-array.ts +++ b/test/validation/record/invalid-array.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { record, string, number } from '../../../src' -test("Invalid record array", () => { - const data = []; - const [err, res] = validate(data, record(string(), number())); - expect(res).toBeUndefined(); +test('Invalid record array', () => { + const data = [] + const [err, res] = validate(data, record(string(), number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid record array", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/record/invalid-property.ts b/test/validation/record/invalid-property.ts index 0e678641..7147f771 100644 --- a/test/validation/record/invalid-property.ts +++ b/test/validation/record/invalid-property.ts @@ -1,15 +1,15 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { record, string, number } from '../../../src' -test("Invalid record property", () => { +test('Invalid record property', () => { const data = { a: 'a', b: 'b', - }; + } - const [err, res] = validate(data, record(string(), number())); - expect(res).toBeUndefined(); + const [err, res] = validate(data, record(string(), number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -26,5 +26,5 @@ test("Invalid record property", () => { path: ['b'], branch: [data, data.b], }, - ]); -}); + ]) +}) diff --git a/test/validation/record/invalid.ts b/test/validation/record/invalid.ts index b25f3901..4bcf07b9 100644 --- a/test/validation/record/invalid.ts +++ b/test/validation/record/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { record, string, number } from '../../../src' -test("Invalid record", () => { - const data = 'invalid'; - const [err, res] = validate(data, record(string(), number())); - expect(res).toBeUndefined(); +test('Invalid record', () => { + const data = 'invalid' + const [err, res] = validate(data, record(string(), number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid record", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/record/valid-frozen.ts b/test/validation/record/valid-frozen.ts index 26b576c6..339e65b5 100644 --- a/test/validation/record/valid-frozen.ts +++ b/test/validation/record/valid-frozen.ts @@ -1,17 +1,17 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { record, string, number } from '../../../src' -test("Valid record frozen", () => { +test('Valid record frozen', () => { const data = Object.freeze({ a: 1, b: 2, - }); + }) - const res = create(data, record(string(), number())); + const res = create(data, record(string(), number())) expect(res).toStrictEqual({ a: 1, b: 2, - }); -}); + }) +}) diff --git a/test/validation/record/valid.ts b/test/validation/record/valid.ts index a2bd4148..335a88f7 100644 --- a/test/validation/record/valid.ts +++ b/test/validation/record/valid.ts @@ -1,17 +1,17 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { record, string, number } from '../../../src' -test("Valid record", () => { +test('Valid record', () => { const data = { a: 1, b: 2, - }; + } - assert(data, record(string(), number())); + assert(data, record(string(), number())) expect(data).toStrictEqual({ a: 1, b: 2, - }); -}); + }) +}) diff --git a/test/validation/refine/invalid-multiple-refinements.ts b/test/validation/refine/invalid-multiple-refinements.ts index b75921b0..5bc6e9b1 100644 --- a/test/validation/refine/invalid-multiple-refinements.ts +++ b/test/validation/refine/invalid-multiple-refinements.ts @@ -1,5 +1,5 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { string, refine, object } from '../../../src' const PasswordValidator = refine(string(), 'MinimumLength', (pw) => @@ -10,23 +10,22 @@ const changePasswordStruct = object({ confirmPassword: string(), }) -test("Invalid refine multiple refinements", () => { +test('Invalid refine multiple refinements', () => { const data = { newPassword: '1234567', confirmPassword: '123456789', - }; + } - const [err, res] = validate(data, refine( - changePasswordStruct, - 'PasswordsDoNotMatch', - (values) => { + const [err, res] = validate( + data, + refine(changePasswordStruct, 'PasswordsDoNotMatch', (values) => { return values.newPassword === values.confirmPassword ? true : 'Passwords do not match' - } - )); + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -43,5 +42,5 @@ test("Invalid refine multiple refinements", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/refine/invalid-shorthand.ts b/test/validation/refine/invalid-shorthand.ts index a1666569..612e1e08 100644 --- a/test/validation/refine/invalid-shorthand.ts +++ b/test/validation/refine/invalid-shorthand.ts @@ -1,17 +1,16 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { number, refine } from '../../../src' -test("Invalid refine shorthand", () => { - const data = -1; +test('Invalid refine shorthand', () => { + const data = -1 - const [err, res] = validate(data, refine( - number(), - 'positive', - (v) => v > 0 || 'Number was not positive!' - )); + const [err, res] = validate( + data, + refine(number(), 'positive', (v) => v > 0 || 'Number was not positive!') + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -21,5 +20,5 @@ test("Invalid refine shorthand", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/refine/invalid.ts b/test/validation/refine/invalid.ts index 8ce32e97..7a6d1db6 100644 --- a/test/validation/refine/invalid.ts +++ b/test/validation/refine/invalid.ts @@ -1,11 +1,14 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { string, refine } from '../../../src' -test("Invalid refine", () => { - const data = 'invalid'; - const [err, res] = validate(data, refine(string(), 'email', (value) => value.includes('@'))); - expect(res).toBeUndefined(); +test('Invalid refine', () => { + const data = 'invalid' + const [err, res] = validate( + data, + refine(string(), 'email', (value) => value.includes('@')) + ) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +18,5 @@ test("Invalid refine", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/refine/valid.ts b/test/validation/refine/valid.ts index cdc47f06..1bac26c0 100644 --- a/test/validation/refine/valid.ts +++ b/test/validation/refine/valid.ts @@ -1,9 +1,12 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { string, refine } from '../../../src' -test("Valid refine", () => { - const data = 'name@example.com'; - assert(data, refine(string(), 'email', (value) => value.includes('@'))); - expect(data).toStrictEqual('name@example.com'); -}); +test('Valid refine', () => { + const data = 'name@example.com' + assert( + data, + refine(string(), 'email', (value) => value.includes('@')) + ) + expect(data).toStrictEqual('name@example.com') +}) diff --git a/test/validation/regexp/invalid.ts b/test/validation/regexp/invalid.ts index 1587a057..e3cc837d 100644 --- a/test/validation/regexp/invalid.ts +++ b/test/validation/regexp/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { regexp } from '../../../src' -test("Invalid regexp", () => { - const data = 'invalid'; - const [err, res] = validate(data, regexp()); - expect(res).toBeUndefined(); +test('Invalid regexp', () => { + const data = 'invalid' + const [err, res] = validate(data, regexp()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid regexp", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/regexp/valid.ts b/test/validation/regexp/valid.ts index c7995257..569b2fc4 100644 --- a/test/validation/regexp/valid.ts +++ b/test/validation/regexp/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { regexp } from '../../../src' -test("Valid regexp", () => { - const data = /./; - assert(data, regexp()); - expect(data).toStrictEqual(data); -}); +test('Valid regexp', () => { + const data = /./ + assert(data, regexp()) + expect(data).toStrictEqual(data) +}) diff --git a/test/validation/set/invalid-element.ts b/test/validation/set/invalid-element.ts index f6a611d8..51804b6a 100644 --- a/test/validation/set/invalid-element.ts +++ b/test/validation/set/invalid-element.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { set, number } from '../../../src' -test("Invalid set element", () => { - const data = new Set([1, 'b', 3]); - const [err, res] = validate(data, set(number())); - expect(res).toBeUndefined(); +test('Invalid set element', () => { + const data = new Set([1, 'b', 3]) + const [err, res] = validate(data, set(number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid set element", () => { path: ['b'], branch: [data, 'b'], }, - ]); -}); + ]) +}) diff --git a/test/validation/set/invalid-opaque.ts b/test/validation/set/invalid-opaque.ts index 66877cfd..6a312ee7 100644 --- a/test/validation/set/invalid-opaque.ts +++ b/test/validation/set/invalid-opaque.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { set } from '../../../src' -test("Invalid set opaque", () => { - const data = 'invalid'; - const [err, res] = validate(data, set()); - expect(res).toBeUndefined(); +test('Invalid set opaque', () => { + const data = 'invalid' + const [err, res] = validate(data, set()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid set opaque", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/set/invalid.ts b/test/validation/set/invalid.ts index 09afeabd..eb9840ed 100644 --- a/test/validation/set/invalid.ts +++ b/test/validation/set/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { set, number } from '../../../src' -test("Invalid set", () => { - const data = 'invalid'; - const [err, res] = validate(data, set(number())); - expect(res).toBeUndefined(); +test('Invalid set', () => { + const data = 'invalid' + const [err, res] = validate(data, set(number())) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid set", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/set/valid-opaque.ts b/test/validation/set/valid-opaque.ts index d5f2f9c4..f033e00a 100644 --- a/test/validation/set/valid-opaque.ts +++ b/test/validation/set/valid-opaque.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { set } from '../../../src' -test("Valid set opaque", () => { - const data = new Set(['a', 2, true]); - assert(data, set()); - expect(data).toStrictEqual(new Set(['a', 2, true])); -}); +test('Valid set opaque', () => { + const data = new Set(['a', 2, true]) + assert(data, set()) + expect(data).toStrictEqual(new Set(['a', 2, true])) +}) diff --git a/test/validation/set/valid.ts b/test/validation/set/valid.ts index ccec0575..9739421e 100644 --- a/test/validation/set/valid.ts +++ b/test/validation/set/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { set, number } from '../../../src' -test("Valid set", () => { - const data = new Set([1, 2, 3]); - assert(data, set(number())); - expect(data).toStrictEqual(new Set([1, 2, 3])); -}); +test('Valid set', () => { + const data = new Set([1, 2, 3]) + assert(data, set(number())) + expect(data).toStrictEqual(new Set([1, 2, 3])) +}) diff --git a/test/validation/size/invalid-array.ts b/test/validation/size/invalid-array.ts index 36cd6d66..0ef60ccf 100644 --- a/test/validation/size/invalid-array.ts +++ b/test/validation/size/invalid-array.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { array, size, number } from '../../../src' -test("Invalid size array", () => { - const data = []; - const [err, res] = validate(data, size(array(number()), 1, 5)); - expect(res).toBeUndefined(); +test('Invalid size array', () => { + const data = [] + const [err, res] = validate(data, size(array(number()), 1, 5)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid size array", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/size/invalid-map.ts b/test/validation/size/invalid-map.ts index a454313c..95503ca8 100644 --- a/test/validation/size/invalid-map.ts +++ b/test/validation/size/invalid-map.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { map, size, number, string } from '../../../src' -test("Invalid size map", () => { - const data = new Map(); - const [err, res] = validate(data, size(map(number(), string()), 1, 5)); - expect(res).toBeUndefined(); +test('Invalid size map', () => { + const data = new Map() + const [err, res] = validate(data, size(map(number(), string()), 1, 5)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid size map", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/size/invalid-number.ts b/test/validation/size/invalid-number.ts index ba4c32bc..4a5e478f 100644 --- a/test/validation/size/invalid-number.ts +++ b/test/validation/size/invalid-number.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { number, size } from '../../../src' -test("Invalid size number", () => { - const data = 0; - const [err, res] = validate(data, size(number(), 1, 5)); - expect(res).toBeUndefined(); +test('Invalid size number', () => { + const data = 0 + const [err, res] = validate(data, size(number(), 1, 5)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid size number", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/size/invalid-set.ts b/test/validation/size/invalid-set.ts index b7880113..ed68e697 100644 --- a/test/validation/size/invalid-set.ts +++ b/test/validation/size/invalid-set.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { set, size, number } from '../../../src' -test("Invalid size set", () => { - const data = new Set(); - const [err, res] = validate(data, size(set(number()), 1, 5)); - expect(res).toBeUndefined(); +test('Invalid size set', () => { + const data = new Set() + const [err, res] = validate(data, size(set(number()), 1, 5)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid size set", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/size/invalid-string.ts b/test/validation/size/invalid-string.ts index 47cc2b6e..959e623d 100644 --- a/test/validation/size/invalid-string.ts +++ b/test/validation/size/invalid-string.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { string, size } from '../../../src' -test("Invalid size string", () => { - const data = ''; - const [err, res] = validate(data, size(string(), 1, 5)); - expect(res).toBeUndefined(); +test('Invalid size string', () => { + const data = '' + const [err, res] = validate(data, size(string(), 1, 5)) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid size string", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/size/valid-array.ts b/test/validation/size/valid-array.ts index 68845241..8f7494db 100644 --- a/test/validation/size/valid-array.ts +++ b/test/validation/size/valid-array.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, array, size } from '../../../src' -test("Valid size array", () => { - const data = [1, 2, 3]; - assert(data, size(array(number()), 1, 5)); - expect(data).toStrictEqual([1, 2, 3]); -}); +test('Valid size array', () => { + const data = [1, 2, 3] + assert(data, size(array(number()), 1, 5)) + expect(data).toStrictEqual([1, 2, 3]) +}) diff --git a/test/validation/size/valid-exact.ts b/test/validation/size/valid-exact.ts index 378045c2..b8b7475b 100644 --- a/test/validation/size/valid-exact.ts +++ b/test/validation/size/valid-exact.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { string, size } from '../../../src' -test("Valid size exact", () => { - const data = 'abcd'; - assert(data, size(string(), 4)); - expect(data).toStrictEqual('abcd'); -}); +test('Valid size exact', () => { + const data = 'abcd' + assert(data, size(string(), 4)) + expect(data).toStrictEqual('abcd') +}) diff --git a/test/validation/size/valid-map.ts b/test/validation/size/valid-map.ts index dfbbe32c..e8561d40 100644 --- a/test/validation/size/valid-map.ts +++ b/test/validation/size/valid-map.ts @@ -1,14 +1,14 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { string, number, map, size } from '../../../src' -test("Valid size map", () => { +test('Valid size map', () => { const data = new Map([ [1, 'a'], [2, 'b'], [3, 'c'], - ]); + ]) - assert(data, size(map(number(), string()), 1, 5)); - expect(data).toStrictEqual(data); -}); + assert(data, size(map(number(), string()), 1, 5)) + expect(data).toStrictEqual(data) +}) diff --git a/test/validation/size/valid-max-inclusive.ts b/test/validation/size/valid-max-inclusive.ts index f630690e..ecc7db5c 100644 --- a/test/validation/size/valid-max-inclusive.ts +++ b/test/validation/size/valid-max-inclusive.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { string, size } from '../../../src' -test("Valid size max inclusive", () => { - const data = 'abcde'; - assert(data, size(string(), 1, 5)); - expect(data).toStrictEqual('abcde'); -}); +test('Valid size max inclusive', () => { + const data = 'abcde' + assert(data, size(string(), 1, 5)) + expect(data).toStrictEqual('abcde') +}) diff --git a/test/validation/size/valid-min-inclusive.ts b/test/validation/size/valid-min-inclusive.ts index 28204bda..8b24630b 100644 --- a/test/validation/size/valid-min-inclusive.ts +++ b/test/validation/size/valid-min-inclusive.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { string, size } from '../../../src' -test("Valid size min inclusive", () => { - const data = 'a'; - assert(data, size(string(), 1, 5)); - expect(data).toStrictEqual('a'); -}); +test('Valid size min inclusive', () => { + const data = 'a' + assert(data, size(string(), 1, 5)) + expect(data).toStrictEqual('a') +}) diff --git a/test/validation/size/valid-number.ts b/test/validation/size/valid-number.ts index 7acec38d..53adaf6d 100644 --- a/test/validation/size/valid-number.ts +++ b/test/validation/size/valid-number.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, size } from '../../../src' -test("Valid size number", () => { - const data = 3; - assert(data, size(number(), 1, 5)); - expect(data).toStrictEqual(3); -}); +test('Valid size number', () => { + const data = 3 + assert(data, size(number(), 1, 5)) + expect(data).toStrictEqual(3) +}) diff --git a/test/validation/size/valid-set.ts b/test/validation/size/valid-set.ts index a88b5954..e303f0d7 100644 --- a/test/validation/size/valid-set.ts +++ b/test/validation/size/valid-set.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { number, set, size } from '../../../src' -test("Valid size set", () => { - const data = new Set([1, 2, 3]); - assert(data, size(set(number()), 1, 5)); - expect(data).toStrictEqual(data); -}); +test('Valid size set', () => { + const data = new Set([1, 2, 3]) + assert(data, size(set(number()), 1, 5)) + expect(data).toStrictEqual(data) +}) diff --git a/test/validation/size/valid-string.ts b/test/validation/size/valid-string.ts index ba4e216a..083875c5 100644 --- a/test/validation/size/valid-string.ts +++ b/test/validation/size/valid-string.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { string, size } from '../../../src' -test("Valid size string", () => { - const data = 'two'; - assert(data, size(string(), 1, 5)); - expect(data).toStrictEqual('two'); -}); +test('Valid size string', () => { + const data = 'two' + assert(data, size(string(), 1, 5)) + expect(data).toStrictEqual('two') +}) diff --git a/test/validation/string/invalid.ts b/test/validation/string/invalid.ts index 67989637..8dca56f8 100644 --- a/test/validation/string/invalid.ts +++ b/test/validation/string/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { string } from '../../../src' -test("Invalid string", () => { - const data = false; - const [err, res] = validate(data, string()); - expect(res).toBeUndefined(); +test('Invalid string', () => { + const data = false + const [err, res] = validate(data, string()) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid string", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/string/valid.ts b/test/validation/string/valid.ts index 7c3c6858..60f4b2de 100644 --- a/test/validation/string/valid.ts +++ b/test/validation/string/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { string } from '../../../src' -test("Valid string", () => { - const data = 'valid'; - assert(data, string()); - expect(data).toStrictEqual('valid'); -}); +test('Valid string', () => { + const data = 'valid' + assert(data, string()) + expect(data).toStrictEqual('valid') +}) diff --git a/test/validation/trimmed/invalid.ts b/test/validation/trimmed/invalid.ts index 9870599a..2cef8ee9 100644 --- a/test/validation/trimmed/invalid.ts +++ b/test/validation/trimmed/invalid.ts @@ -1,15 +1,15 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { string, trimmed } from '../../../src' -test("Invalid trimmed", () => { - const data = false; +test('Invalid trimmed', () => { + const data = false const [err, res] = validate(data, trimmed(string()), { - coerce: true - }); + coerce: true, + }) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -19,5 +19,5 @@ test("Invalid trimmed", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/trimmed/valid.ts b/test/validation/trimmed/valid.ts index 39c19514..6212caf1 100644 --- a/test/validation/trimmed/valid.ts +++ b/test/validation/trimmed/valid.ts @@ -1,9 +1,9 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { string, trimmed } from '../../../src' -test("Valid trimmed", () => { - const data = ' valid '; - const res = create(data, trimmed(string())); - expect(res).toStrictEqual('valid'); -}); +test('Valid trimmed', () => { + const data = ' valid ' + const res = create(data, trimmed(string())) + expect(res).toStrictEqual('valid') +}) diff --git a/test/validation/tuple/invalid-element-missing.ts b/test/validation/tuple/invalid-element-missing.ts index 95dcf873..e4b522e7 100644 --- a/test/validation/tuple/invalid-element-missing.ts +++ b/test/validation/tuple/invalid-element-missing.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { tuple, string, number } from '../../../src' -test("Invalid tuple element missing", () => { - const data = ['A']; - const [err, res] = validate(data, tuple([string(), number()])); - expect(res).toBeUndefined(); +test('Invalid tuple element missing', () => { + const data = ['A'] + const [err, res] = validate(data, tuple([string(), number()])) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid tuple element missing", () => { path: [1], branch: [data, data[1]], }, - ]); -}); + ]) +}) diff --git a/test/validation/tuple/invalid-element-unknown.ts b/test/validation/tuple/invalid-element-unknown.ts index 32cdef2d..e03297c9 100644 --- a/test/validation/tuple/invalid-element-unknown.ts +++ b/test/validation/tuple/invalid-element-unknown.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { tuple, string, number } from '../../../src' -test("Invalid tuple element unknown", () => { - const data = ['A', 3, 'unknown']; - const [err, res] = validate(data, tuple([string(), number()])); - expect(res).toBeUndefined(); +test('Invalid tuple element unknown', () => { + const data = ['A', 3, 'unknown'] + const [err, res] = validate(data, tuple([string(), number()])) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid tuple element unknown", () => { path: [2], branch: [data, data[2]], }, - ]); -}); + ]) +}) diff --git a/test/validation/tuple/invalid-element.ts b/test/validation/tuple/invalid-element.ts index 2cecf0ce..de6d8d72 100644 --- a/test/validation/tuple/invalid-element.ts +++ b/test/validation/tuple/invalid-element.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { tuple, string, number } from '../../../src' -test("Invalid tuple element", () => { - const data = [false, 3]; - const [err, res] = validate(data, tuple([string(), number()])); - expect(res).toBeUndefined(); +test('Invalid tuple element', () => { + const data = [false, 3] + const [err, res] = validate(data, tuple([string(), number()])) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid tuple element", () => { path: [0], branch: [data, data[0]], }, - ]); -}); + ]) +}) diff --git a/test/validation/tuple/invalid.ts b/test/validation/tuple/invalid.ts index ab304a04..f8c1fb07 100644 --- a/test/validation/tuple/invalid.ts +++ b/test/validation/tuple/invalid.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { tuple, string, number } from '../../../src' -test("Invalid tuple", () => { - const data = 'invalid'; - const [err, res] = validate(data, tuple([string(), number()])); - expect(res).toBeUndefined(); +test('Invalid tuple', () => { + const data = 'invalid' + const [err, res] = validate(data, tuple([string(), number()])) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid tuple", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/tuple/valid-frozen.ts b/test/validation/tuple/valid-frozen.ts index 40d18417..83029b5b 100644 --- a/test/validation/tuple/valid-frozen.ts +++ b/test/validation/tuple/valid-frozen.ts @@ -1,9 +1,9 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { tuple, string, number } from '../../../src' -test("Valid tuple frozen", () => { - const data = Object.freeze(['A', 1]); - const res = create(data, tuple([string(), number()])); - expect(res).toStrictEqual(['A', 1]); -}); +test('Valid tuple frozen', () => { + const data = Object.freeze(['A', 1]) + const res = create(data, tuple([string(), number()])) + expect(res).toStrictEqual(['A', 1]) +}) diff --git a/test/validation/tuple/valid.ts b/test/validation/tuple/valid.ts index 60771633..3ea445e3 100644 --- a/test/validation/tuple/valid.ts +++ b/test/validation/tuple/valid.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { tuple, string, number } from '../../../src' -test("Valid tuple", () => { - const data = ['A', 1]; - assert(data, tuple([string(), number()])); - expect(data).toStrictEqual(['A', 1]); -}); +test('Valid tuple', () => { + const data = ['A', 1] + assert(data, tuple([string(), number()])) + expect(data).toStrictEqual(['A', 1]) +}) diff --git a/test/validation/type/invalid-array.ts b/test/validation/type/invalid-array.ts index 4c2a35ab..f44f5fbd 100644 --- a/test/validation/type/invalid-array.ts +++ b/test/validation/type/invalid-array.ts @@ -1,11 +1,11 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { type } from '../../../src' -test("Invalid type array", () => { - const data = []; - const [err, res] = validate(data, type({})); - expect(res).toBeUndefined(); +test('Invalid type array', () => { + const data = [] + const [err, res] = validate(data, type({})) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -15,5 +15,5 @@ test("Invalid type array", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/type/invalid-property-nested.ts b/test/validation/type/invalid-property-nested.ts index 59181a94..ae5e66b7 100644 --- a/test/validation/type/invalid-property-nested.ts +++ b/test/validation/type/invalid-property-nested.ts @@ -1,21 +1,24 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { type, string, number } from '../../../src' -test("Invalid type property nested", () => { +test('Invalid type property nested', () => { const data = { id: 1, - }; + } - const [err, res] = validate(data, type({ - id: number(), - person: type({ - name: string(), - age: number(), - }), - })); + const [err, res] = validate( + data, + type({ + id: number(), + person: type({ + name: string(), + age: number(), + }), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -25,5 +28,5 @@ test("Invalid type property nested", () => { path: ['person'], branch: [data, undefined], }, - ]); -}); + ]) +}) diff --git a/test/validation/type/invalid-property.ts b/test/validation/type/invalid-property.ts index 48a33045..3cf8b4a0 100644 --- a/test/validation/type/invalid-property.ts +++ b/test/validation/type/invalid-property.ts @@ -1,19 +1,22 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { type, string, number } from '../../../src' -test("Invalid type property", () => { +test('Invalid type property', () => { const data = { name: 'john', age: 'invalid', - }; + } - const [err, res] = validate(data, type({ - name: string(), - age: number(), - })); + const [err, res] = validate( + data, + type({ + name: string(), + age: number(), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -23,5 +26,5 @@ test("Invalid type property", () => { path: ['age'], branch: [data, data.age], }, - ]); -}); + ]) +}) diff --git a/test/validation/type/invalid.ts b/test/validation/type/invalid.ts index 23f355ba..ebf7a038 100644 --- a/test/validation/type/invalid.ts +++ b/test/validation/type/invalid.ts @@ -1,16 +1,19 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { type, string, number } from '../../../src' -test("Invalid type", () => { - const data = 'invalid'; +test('Invalid type', () => { + const data = 'invalid' - const [err, res] = validate(data, type({ - name: string(), - age: number(), - })); + const [err, res] = validate( + data, + type({ + name: string(), + age: number(), + }) + ) - expect(res).toBeUndefined(); + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -20,5 +23,5 @@ test("Invalid type", () => { path: [], branch: [data], }, - ]); -}); + ]) +}) diff --git a/test/validation/type/valid-frozen.ts b/test/validation/type/valid-frozen.ts index d8a6b670..fe22a68b 100644 --- a/test/validation/type/valid-frozen.ts +++ b/test/validation/type/valid-frozen.ts @@ -1,20 +1,23 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { type, string, number } from '../../../src' -test("Valid type frozen", () => { +test('Valid type frozen', () => { const data = Object.freeze({ name: 'john', age: 42, - }); + }) - const res = create(data, type({ - name: string(), - age: number(), - })); + const res = create( + data, + type({ + name: string(), + age: number(), + }) + ) expect(res).toStrictEqual({ name: 'john', age: 42, - }); -}); + }) +}) diff --git a/test/validation/type/valid.ts b/test/validation/type/valid.ts index 00d0ee11..bc548067 100644 --- a/test/validation/type/valid.ts +++ b/test/validation/type/valid.ts @@ -1,17 +1,20 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, string, number } from '../../../src' -test("Valid type", () => { +test('Valid type', () => { const data = { name: 'john', age: 42, - }; + } - assert(data, type({ - name: string(), - age: number(), - })); + assert( + data, + type({ + name: string(), + age: number(), + }) + ) - expect(data).toStrictEqual(data); -}); + expect(data).toStrictEqual(data) +}) diff --git a/test/validation/union/coercion-object.ts b/test/validation/union/coercion-object.ts index f0d825c5..ac0d2db7 100644 --- a/test/validation/union/coercion-object.ts +++ b/test/validation/union/coercion-object.ts @@ -1,12 +1,12 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { union, string, number, defaulted, object } from '../../../src' const A = string() const B = object({ a: number(), b: defaulted(number(), 5) }) -test("Coercion union object", () => { - const data = { a: 5 }; - const res = create(data, union([A, B])); - expect(res).toStrictEqual({ a: 5, b: 5 }); -}); +test('Coercion union object', () => { + const data = { a: 5 } + const res = create(data, union([A, B])) + expect(res).toStrictEqual({ a: 5, b: 5 }) +}) diff --git a/test/validation/union/coercion-type.ts b/test/validation/union/coercion-type.ts index 6c6bf800..6f776add 100644 --- a/test/validation/union/coercion-type.ts +++ b/test/validation/union/coercion-type.ts @@ -1,12 +1,12 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { union, string, number, defaulted, type } from '../../../src' const A = string() const B = type({ a: number(), b: defaulted(number(), 5) }) -test("Coercion union type", () => { - const data = { a: 5 }; - const res = create(data, union([A, B])); - expect(res).toStrictEqual({ a: 5, b: 5 }); -}); +test('Coercion union type', () => { + const data = { a: 5 } + const res = create(data, union([A, B])) + expect(res).toStrictEqual({ a: 5, b: 5 }) +}) diff --git a/test/validation/union/coercion.ts b/test/validation/union/coercion.ts index cd616770..8b7b39b0 100644 --- a/test/validation/union/coercion.ts +++ b/test/validation/union/coercion.ts @@ -1,12 +1,12 @@ -import { create } from "../../../src"; -import { expect, test } from "vitest"; +import { create } from '../../../src' +import { expect, test } from 'vitest' import { union, string, number, defaulted } from '../../../src' const A = defaulted(string(), 'foo') const B = number() -test("Coercion union", () => { - const data = undefined; - const res = create(data, union([A, B])); - expect(res).toStrictEqual('foo'); -}); +test('Coercion union', () => { + const data = undefined + const res = create(data, union([A, B])) + expect(res).toStrictEqual('foo') +}) diff --git a/test/validation/union/invalid.ts b/test/validation/union/invalid.ts index 015a48c7..942ffa9e 100644 --- a/test/validation/union/invalid.ts +++ b/test/validation/union/invalid.ts @@ -1,17 +1,17 @@ -import { validate } from "../../../src"; -import { expect, test } from "vitest"; +import { validate } from '../../../src' +import { expect, test } from 'vitest' import { type, union, string, number } from '../../../src' const A = type({ a: string() }) const B = type({ b: number() }) -test("Invalid union", () => { +test('Invalid union', () => { const data = { b: 'invalid', - }; + } - const [err, res] = validate(data, union([A, B])); - expect(res).toBeUndefined(); + const [err, res] = validate(data, union([A, B])) + expect(res).toBeUndefined() expect(err).toMatchStructError([ { @@ -35,5 +35,5 @@ test("Invalid union", () => { path: ['b'], branch: [data, data.b], }, - ]); -}); + ]) +}) diff --git a/test/validation/union/valid.ts b/test/validation/union/valid.ts index ed9faa58..76964d14 100644 --- a/test/validation/union/valid.ts +++ b/test/validation/union/valid.ts @@ -1,18 +1,18 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { type, union, string, number } from '../../../src' const A = type({ a: string() }) const B = type({ b: number() }) -test("Valid union", () => { +test('Valid union', () => { const data = { a: 'a', - }; + } - assert(data, union([A, B])); + assert(data, union([A, B])) expect(data).toStrictEqual({ a: 'a', - }); -}); + }) +}) diff --git a/test/validation/unknown/valid-number.ts b/test/validation/unknown/valid-number.ts index 98268cfb..56965055 100644 --- a/test/validation/unknown/valid-number.ts +++ b/test/validation/unknown/valid-number.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { unknown } from '../../../src' -test("Valid unknown number", () => { - const data = 1; - assert(data, unknown()); - expect(data).toStrictEqual(1); -}); +test('Valid unknown number', () => { + const data = 1 + assert(data, unknown()) + expect(data).toStrictEqual(1) +}) diff --git a/test/validation/unknown/valid-string.ts b/test/validation/unknown/valid-string.ts index 67c5edc9..f42be5c2 100644 --- a/test/validation/unknown/valid-string.ts +++ b/test/validation/unknown/valid-string.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { unknown } from '../../../src' -test("Valid unknown string", () => { - const data = 'valid'; - assert(data, unknown()); - expect(data).toStrictEqual('valid'); -}); +test('Valid unknown string', () => { + const data = 'valid' + assert(data, unknown()) + expect(data).toStrictEqual('valid') +}) diff --git a/test/validation/unknown/valid-undefined.ts b/test/validation/unknown/valid-undefined.ts index 7e658da6..c30eab7b 100644 --- a/test/validation/unknown/valid-undefined.ts +++ b/test/validation/unknown/valid-undefined.ts @@ -1,9 +1,9 @@ -import { assert } from "../../../src"; -import { expect, test } from "vitest"; +import { assert } from '../../../src' +import { expect, test } from 'vitest' import { unknown } from '../../../src' -test("Valid unknown undefined", () => { - const data = undefined; - assert(data, unknown()); - expect(data).toStrictEqual(undefined); -}); +test('Valid unknown undefined', () => { + const data = undefined + assert(data, unknown()) + expect(data).toStrictEqual(undefined) +}) From c46e9d378bc5ac541d924875eed9e72a3e26cc27 Mon Sep 17 00:00:00 2001 From: Geoff Date: Mon, 19 Aug 2024 23:19:49 -0400 Subject: [PATCH 4/6] Rename all files to have `.test.ts` --- test/validation/any/{valid-number.ts => valid-number.test.ts} | 0 test/validation/any/{valid-string.ts => valid-string.test.ts} | 0 .../any/{valid-undefined.ts => valid-undefined.test.ts} | 0 ...valid-element-property.ts => invalid-element-property.test.ts} | 0 .../array/{invalid-element.ts => invalid-element.test.ts} | 0 .../array/{invalid-opaque.ts => invalid-opaque.test.ts} | 0 test/validation/array/{invalid.ts => invalid.test.ts} | 0 test/validation/array/{valid-frozen.ts => valid-frozen.test.ts} | 0 test/validation/array/{valid-opaque.ts => valid-opaque.test.ts} | 0 test/validation/array/{valid.ts => valid.test.ts} | 0 .../assign/{invalid-object.ts => invalid-object.test.ts} | 0 test/validation/assign/{invalid-type.ts => invalid-type.test.ts} | 0 test/validation/assign/{valid-object.ts => valid-object.test.ts} | 0 test/validation/assign/{valid-type.ts => valid-type.test.ts} | 0 .../bigint/{invalid-number.ts => invalid-number.test.ts} | 0 test/validation/bigint/{invalid.ts => invalid.test.ts} | 0 test/validation/bigint/{valid.ts => valid.test.ts} | 0 test/validation/boolean/{invalid.ts => invalid.test.ts} | 0 test/validation/boolean/{valid.ts => valid.test.ts} | 0 test/validation/coerce/{changed.ts => changed.test.ts} | 0 .../coerce/{condition-not-met.ts => condition-not-met.test.ts} | 0 test/validation/coerce/{unchanged.ts => unchanged.test.ts} | 0 test/validation/date/{invalid-date.ts => invalid-date.test.ts} | 0 test/validation/date/{invalid.ts => invalid.test.ts} | 0 test/validation/date/{valid.ts => valid.test.ts} | 0 test/validation/defaulted/{function.ts => function.test.ts} | 0 test/validation/defaulted/{mixin.ts => mixin.test.ts} | 0 .../defaulted/{nested-double.ts => nested-double.test.ts} | 0 test/validation/defaulted/{nested.ts => nested.test.ts} | 0 test/validation/defaulted/{strict.ts => strict.test.ts} | 0 test/validation/defaulted/{value.ts => value.test.ts} | 0 .../deprecated/{invalid-null.ts => invalid-null.test.ts} | 0 .../deprecated/{invalid-property.ts => invalid-property.test.ts} | 0 test/validation/deprecated/{invalid.ts => invalid.test.ts} | 0 .../deprecated/{valid-property.ts => valid-property.test.ts} | 0 .../deprecated/{valid-undefined.ts => valid-undefined.test.ts} | 0 test/validation/deprecated/{valid.ts => valid.test.ts} | 0 .../dynamic/{invalid-reference.ts => invalid-reference.test.ts} | 0 test/validation/dynamic/{invalid.ts => invalid.test.ts} | 0 .../dynamic/{valid-reference.ts => valid-reference.test.ts} | 0 test/validation/dynamic/{valid.ts => valid.test.ts} | 0 .../dynamic/{with-refiners.ts => with-refiners.test.ts} | 0 test/validation/empty/{invalid-array.ts => invalid-array.test.ts} | 0 test/validation/empty/{invalid-map.ts => invalid-map.test.ts} | 0 test/validation/empty/{invalid-set.ts => invalid-set.test.ts} | 0 .../empty/{invalid-string.ts => invalid-string.test.ts} | 0 test/validation/empty/{valid-array.ts => valid-array.test.ts} | 0 test/validation/empty/{valid-map.ts => valid-map.test.ts} | 0 test/validation/empty/{valid-set.ts => valid-set.test.ts} | 0 test/validation/empty/{valid-string.ts => valid-string.test.ts} | 0 .../enums/{invalid-numbers.ts => invalid-numbers.test.ts} | 0 .../enums/{invalid-strings.ts => invalid-strings.test.ts} | 0 test/validation/enums/{valid.ts => valid.test.ts} | 0 test/validation/function/{invalid.ts => invalid.test.ts} | 0 test/validation/function/{valid.ts => valid.test.ts} | 0 test/validation/instance/{invalid.ts => invalid.test.ts} | 0 test/validation/instance/{valid.ts => valid.test.ts} | 0 .../integer/{invalid-decimal.ts => invalid-decimal.test.ts} | 0 test/validation/integer/{invalid.ts => invalid.test.ts} | 0 test/validation/integer/{valid.ts => valid.test.ts} | 0 .../{invalid-refinement.ts => invalid-refinement.test.ts} | 0 test/validation/intersection/{invalid.ts => invalid.test.ts} | 0 .../{valid-refinement.ts => valid-refinement.test.ts} | 0 test/validation/intersection/{valid.ts => valid.test.ts} | 0 test/validation/lazy/{invalid.ts => invalid.test.ts} | 0 test/validation/lazy/{valid.ts => valid.test.ts} | 0 test/validation/lazy/{with-refiners.ts => with-refiners.test.ts} | 0 test/validation/literal/{invalid.ts => invalid.test.ts} | 0 test/validation/literal/{valid.ts => valid.test.ts} | 0 test/validation/map/{invalid-opaque.ts => invalid-opaque.test.ts} | 0 .../map/{invalid-property.ts => invalid-property.test.ts} | 0 test/validation/map/{invalid.ts => invalid.test.ts} | 0 test/validation/map/{valid-opaque.ts => valid-opaque.test.ts} | 0 test/validation/map/{valid.ts => valid.test.ts} | 0 .../max/{invalid-exclusive.ts => invalid-exclusive.test.ts} | 0 test/validation/max/{invalid.ts => invalid.test.ts} | 0 .../max/{valid-inclusive.ts => valid-inclusive.test.ts} | 0 test/validation/max/{valid.ts => valid.test.ts} | 0 .../min/{invalid-exclusive.ts => invalid-exclusive.test.ts} | 0 test/validation/min/{invalid.ts => invalid.test.ts} | 0 .../min/{valid-inclusive.ts => valid-inclusive.test.ts} | 0 test/validation/min/{valid.ts => valid.test.ts} | 0 test/validation/never/{invalid.ts => invalid.test.ts} | 0 test/validation/nullable/{invalid.ts => invalid.test.ts} | 0 .../{valid-defined-nested.ts => valid-defined-nested.test.ts} | 0 .../nullable/{valid-defined.ts => valid-defined.test.ts} | 0 .../nullable/{valid-null-nested.ts => valid-null-nested.test.ts} | 0 test/validation/nullable/{valid-null.ts => valid-null.test.ts} | 0 test/validation/number/{invalid.ts => invalid.test.ts} | 0 test/validation/number/{valid.ts => valid.test.ts} | 0 .../validation/object/{invalid-array.ts => invalid-array.test.ts} | 0 .../{invalid-element-nested.ts => invalid-element-nested.test.ts} | 0 .../object/{invalid-opaque.ts => invalid-opaque.test.ts} | 0 ...invalid-property-nested.ts => invalid-property-nested.test.ts} | 0 ...valid-property-unknown.ts => invalid-property-unknown.test.ts} | 0 .../object/{invalid-property.ts => invalid-property.test.ts} | 0 .../{invalid-referential.ts => invalid-referential.test.ts} | 0 test/validation/object/{invalid.ts => invalid.test.ts} | 0 test/validation/object/{valid-frozen.ts => valid-frozen.test.ts} | 0 test/validation/object/{valid-nested.ts => valid-nested.test.ts} | 0 test/validation/object/{valid-opaque.ts => valid-opaque.test.ts} | 0 .../object/{valid-referential.ts => valid-referential.test.ts} | 0 test/validation/object/{valid.ts => valid.test.ts} | 0 .../{invalid-element-nested.ts => invalid-element-nested.test.ts} | 0 ...invalid-property-nested.ts => invalid-property-nested.test.ts} | 0 ...valid-property-unknown.ts => invalid-property-unknown.test.ts} | 0 .../omit/{invalid-property.ts => invalid-property.test.ts} | 0 test/validation/omit/{invalid.ts => invalid.test.ts} | 0 test/validation/omit/{valid-nested.ts => valid-nested.test.ts} | 0 test/validation/omit/{valid-type.ts => valid-type.test.ts} | 0 test/validation/omit/{valid.ts => valid.test.ts} | 0 test/validation/optional/{invalid.ts => invalid.test.ts} | 0 .../{valid-defined-nested.ts => valid-defined-nested.test.ts} | 0 .../optional/{valid-defined.ts => valid-defined.test.ts} | 0 .../{valid-undefined-nested.ts => valid-undefined-nested.test.ts} | 0 .../optional/{valid-undefined.ts => valid-undefined.test.ts} | 0 test/validation/partial/{composed.ts => composed.test.ts} | 0 ...valid-property-unknown.ts => invalid-property-unknown.test.ts} | 0 .../partial/{invalid-property.ts => invalid-property.test.ts} | 0 test/validation/partial/{invalid.ts => invalid.test.ts} | 0 test/validation/partial/{valid-empty.ts => valid-empty.test.ts} | 0 test/validation/partial/{valid-full.ts => valid-full.test.ts} | 0 .../partial/{valid-partial.ts => valid-partial.test.ts} | 0 test/validation/partial/{valid-type.ts => valid-type.test.ts} | 0 test/validation/pattern/{invalid.ts => invalid.test.ts} | 0 test/validation/pattern/{valid.ts => valid.test.ts} | 0 .../{invalid-element-nested.ts => invalid-element-nested.test.ts} | 0 ...invalid-property-nested.ts => invalid-property-nested.test.ts} | 0 ...valid-property-unknown.ts => invalid-property-unknown.test.ts} | 0 .../pick/{invalid-property.ts => invalid-property.test.ts} | 0 test/validation/pick/{invalid.ts => invalid.test.ts} | 0 test/validation/pick/{valid-nested.ts => valid-nested.test.ts} | 0 test/validation/pick/{valid-type.ts => valid-type.test.ts} | 0 test/validation/pick/{valid.ts => valid.test.ts} | 0 .../validation/record/{invalid-array.ts => invalid-array.test.ts} | 0 .../record/{invalid-property.ts => invalid-property.test.ts} | 0 test/validation/record/{invalid.ts => invalid.test.ts} | 0 test/validation/record/{valid-frozen.ts => valid-frozen.test.ts} | 0 test/validation/record/{valid.ts => valid.test.ts} | 0 ...ltiple-refinements.ts => invalid-multiple-refinements.test.ts} | 0 .../refine/{invalid-shorthand.ts => invalid-shorthand.test.ts} | 0 test/validation/refine/{invalid.ts => invalid.test.ts} | 0 test/validation/refine/{valid.ts => valid.test.ts} | 0 test/validation/regexp/{invalid.ts => invalid.test.ts} | 0 test/validation/regexp/{valid.ts => valid.test.ts} | 0 .../set/{invalid-element.ts => invalid-element.test.ts} | 0 test/validation/set/{invalid-opaque.ts => invalid-opaque.test.ts} | 0 test/validation/set/{invalid.ts => invalid.test.ts} | 0 test/validation/set/{valid-opaque.ts => valid-opaque.test.ts} | 0 test/validation/set/{valid.ts => valid.test.ts} | 0 test/validation/size/{invalid-array.ts => invalid-array.test.ts} | 0 test/validation/size/{invalid-map.ts => invalid-map.test.ts} | 0 .../validation/size/{invalid-number.ts => invalid-number.test.ts} | 0 test/validation/size/{invalid-set.ts => invalid-set.test.ts} | 0 .../validation/size/{invalid-string.ts => invalid-string.test.ts} | 0 test/validation/size/{valid-array.ts => valid-array.test.ts} | 0 test/validation/size/{valid-exact.ts => valid-exact.test.ts} | 0 test/validation/size/{valid-map.ts => valid-map.test.ts} | 0 .../size/{valid-max-inclusive.ts => valid-max-inclusive.test.ts} | 0 .../size/{valid-min-inclusive.ts => valid-min-inclusive.test.ts} | 0 test/validation/size/{valid-number.ts => valid-number.test.ts} | 0 test/validation/size/{valid-set.ts => valid-set.test.ts} | 0 test/validation/size/{valid-string.ts => valid-string.test.ts} | 0 test/validation/string/{invalid.ts => invalid.test.ts} | 0 test/validation/string/{valid.ts => valid.test.ts} | 0 test/validation/trimmed/{invalid.ts => invalid.test.ts} | 0 test/validation/trimmed/{valid.ts => valid.test.ts} | 0 ...invalid-element-missing.ts => invalid-element-missing.test.ts} | 0 ...invalid-element-unknown.ts => invalid-element-unknown.test.ts} | 0 .../tuple/{invalid-element.ts => invalid-element.test.ts} | 0 test/validation/tuple/{invalid.ts => invalid.test.ts} | 0 test/validation/tuple/{valid-frozen.ts => valid-frozen.test.ts} | 0 test/validation/tuple/{valid.ts => valid.test.ts} | 0 test/validation/type/{invalid-array.ts => invalid-array.test.ts} | 0 ...invalid-property-nested.ts => invalid-property-nested.test.ts} | 0 .../type/{invalid-property.ts => invalid-property.test.ts} | 0 test/validation/type/{invalid.ts => invalid.test.ts} | 0 test/validation/type/{valid-frozen.ts => valid-frozen.test.ts} | 0 .../validation/type/{valid-instance.ts => valid-instance.test.ts} | 0 test/validation/type/{valid.ts => valid.test.ts} | 0 .../union/{coercion-object.ts => coercion-object.test.ts} | 0 test/validation/union/{coercion-type.ts => coercion-type.test.ts} | 0 test/validation/union/{coercion.ts => coercion.test.ts} | 0 test/validation/union/{invalid.ts => invalid.test.ts} | 0 test/validation/union/{valid.ts => valid.test.ts} | 0 test/validation/unknown/{valid-number.ts => valid-number.test.ts} | 0 test/validation/unknown/{valid-string.ts => valid-string.test.ts} | 0 .../unknown/{valid-undefined.ts => valid-undefined.test.ts} | 0 188 files changed, 0 insertions(+), 0 deletions(-) rename test/validation/any/{valid-number.ts => valid-number.test.ts} (100%) rename test/validation/any/{valid-string.ts => valid-string.test.ts} (100%) rename test/validation/any/{valid-undefined.ts => valid-undefined.test.ts} (100%) rename test/validation/array/{invalid-element-property.ts => invalid-element-property.test.ts} (100%) rename test/validation/array/{invalid-element.ts => invalid-element.test.ts} (100%) rename test/validation/array/{invalid-opaque.ts => invalid-opaque.test.ts} (100%) rename test/validation/array/{invalid.ts => invalid.test.ts} (100%) rename test/validation/array/{valid-frozen.ts => valid-frozen.test.ts} (100%) rename test/validation/array/{valid-opaque.ts => valid-opaque.test.ts} (100%) rename test/validation/array/{valid.ts => valid.test.ts} (100%) rename test/validation/assign/{invalid-object.ts => invalid-object.test.ts} (100%) rename test/validation/assign/{invalid-type.ts => invalid-type.test.ts} (100%) rename test/validation/assign/{valid-object.ts => valid-object.test.ts} (100%) rename test/validation/assign/{valid-type.ts => valid-type.test.ts} (100%) rename test/validation/bigint/{invalid-number.ts => invalid-number.test.ts} (100%) rename test/validation/bigint/{invalid.ts => invalid.test.ts} (100%) rename test/validation/bigint/{valid.ts => valid.test.ts} (100%) rename test/validation/boolean/{invalid.ts => invalid.test.ts} (100%) rename test/validation/boolean/{valid.ts => valid.test.ts} (100%) rename test/validation/coerce/{changed.ts => changed.test.ts} (100%) rename test/validation/coerce/{condition-not-met.ts => condition-not-met.test.ts} (100%) rename test/validation/coerce/{unchanged.ts => unchanged.test.ts} (100%) rename test/validation/date/{invalid-date.ts => invalid-date.test.ts} (100%) rename test/validation/date/{invalid.ts => invalid.test.ts} (100%) rename test/validation/date/{valid.ts => valid.test.ts} (100%) rename test/validation/defaulted/{function.ts => function.test.ts} (100%) rename test/validation/defaulted/{mixin.ts => mixin.test.ts} (100%) rename test/validation/defaulted/{nested-double.ts => nested-double.test.ts} (100%) rename test/validation/defaulted/{nested.ts => nested.test.ts} (100%) rename test/validation/defaulted/{strict.ts => strict.test.ts} (100%) rename test/validation/defaulted/{value.ts => value.test.ts} (100%) rename test/validation/deprecated/{invalid-null.ts => invalid-null.test.ts} (100%) rename test/validation/deprecated/{invalid-property.ts => invalid-property.test.ts} (100%) rename test/validation/deprecated/{invalid.ts => invalid.test.ts} (100%) rename test/validation/deprecated/{valid-property.ts => valid-property.test.ts} (100%) rename test/validation/deprecated/{valid-undefined.ts => valid-undefined.test.ts} (100%) rename test/validation/deprecated/{valid.ts => valid.test.ts} (100%) rename test/validation/dynamic/{invalid-reference.ts => invalid-reference.test.ts} (100%) rename test/validation/dynamic/{invalid.ts => invalid.test.ts} (100%) rename test/validation/dynamic/{valid-reference.ts => valid-reference.test.ts} (100%) rename test/validation/dynamic/{valid.ts => valid.test.ts} (100%) rename test/validation/dynamic/{with-refiners.ts => with-refiners.test.ts} (100%) rename test/validation/empty/{invalid-array.ts => invalid-array.test.ts} (100%) rename test/validation/empty/{invalid-map.ts => invalid-map.test.ts} (100%) rename test/validation/empty/{invalid-set.ts => invalid-set.test.ts} (100%) rename test/validation/empty/{invalid-string.ts => invalid-string.test.ts} (100%) rename test/validation/empty/{valid-array.ts => valid-array.test.ts} (100%) rename test/validation/empty/{valid-map.ts => valid-map.test.ts} (100%) rename test/validation/empty/{valid-set.ts => valid-set.test.ts} (100%) rename test/validation/empty/{valid-string.ts => valid-string.test.ts} (100%) rename test/validation/enums/{invalid-numbers.ts => invalid-numbers.test.ts} (100%) rename test/validation/enums/{invalid-strings.ts => invalid-strings.test.ts} (100%) rename test/validation/enums/{valid.ts => valid.test.ts} (100%) rename test/validation/function/{invalid.ts => invalid.test.ts} (100%) rename test/validation/function/{valid.ts => valid.test.ts} (100%) rename test/validation/instance/{invalid.ts => invalid.test.ts} (100%) rename test/validation/instance/{valid.ts => valid.test.ts} (100%) rename test/validation/integer/{invalid-decimal.ts => invalid-decimal.test.ts} (100%) rename test/validation/integer/{invalid.ts => invalid.test.ts} (100%) rename test/validation/integer/{valid.ts => valid.test.ts} (100%) rename test/validation/intersection/{invalid-refinement.ts => invalid-refinement.test.ts} (100%) rename test/validation/intersection/{invalid.ts => invalid.test.ts} (100%) rename test/validation/intersection/{valid-refinement.ts => valid-refinement.test.ts} (100%) rename test/validation/intersection/{valid.ts => valid.test.ts} (100%) rename test/validation/lazy/{invalid.ts => invalid.test.ts} (100%) rename test/validation/lazy/{valid.ts => valid.test.ts} (100%) rename test/validation/lazy/{with-refiners.ts => with-refiners.test.ts} (100%) rename test/validation/literal/{invalid.ts => invalid.test.ts} (100%) rename test/validation/literal/{valid.ts => valid.test.ts} (100%) rename test/validation/map/{invalid-opaque.ts => invalid-opaque.test.ts} (100%) rename test/validation/map/{invalid-property.ts => invalid-property.test.ts} (100%) rename test/validation/map/{invalid.ts => invalid.test.ts} (100%) rename test/validation/map/{valid-opaque.ts => valid-opaque.test.ts} (100%) rename test/validation/map/{valid.ts => valid.test.ts} (100%) rename test/validation/max/{invalid-exclusive.ts => invalid-exclusive.test.ts} (100%) rename test/validation/max/{invalid.ts => invalid.test.ts} (100%) rename test/validation/max/{valid-inclusive.ts => valid-inclusive.test.ts} (100%) rename test/validation/max/{valid.ts => valid.test.ts} (100%) rename test/validation/min/{invalid-exclusive.ts => invalid-exclusive.test.ts} (100%) rename test/validation/min/{invalid.ts => invalid.test.ts} (100%) rename test/validation/min/{valid-inclusive.ts => valid-inclusive.test.ts} (100%) rename test/validation/min/{valid.ts => valid.test.ts} (100%) rename test/validation/never/{invalid.ts => invalid.test.ts} (100%) rename test/validation/nullable/{invalid.ts => invalid.test.ts} (100%) rename test/validation/nullable/{valid-defined-nested.ts => valid-defined-nested.test.ts} (100%) rename test/validation/nullable/{valid-defined.ts => valid-defined.test.ts} (100%) rename test/validation/nullable/{valid-null-nested.ts => valid-null-nested.test.ts} (100%) rename test/validation/nullable/{valid-null.ts => valid-null.test.ts} (100%) rename test/validation/number/{invalid.ts => invalid.test.ts} (100%) rename test/validation/number/{valid.ts => valid.test.ts} (100%) rename test/validation/object/{invalid-array.ts => invalid-array.test.ts} (100%) rename test/validation/object/{invalid-element-nested.ts => invalid-element-nested.test.ts} (100%) rename test/validation/object/{invalid-opaque.ts => invalid-opaque.test.ts} (100%) rename test/validation/object/{invalid-property-nested.ts => invalid-property-nested.test.ts} (100%) rename test/validation/object/{invalid-property-unknown.ts => invalid-property-unknown.test.ts} (100%) rename test/validation/object/{invalid-property.ts => invalid-property.test.ts} (100%) rename test/validation/object/{invalid-referential.ts => invalid-referential.test.ts} (100%) rename test/validation/object/{invalid.ts => invalid.test.ts} (100%) rename test/validation/object/{valid-frozen.ts => valid-frozen.test.ts} (100%) rename test/validation/object/{valid-nested.ts => valid-nested.test.ts} (100%) rename test/validation/object/{valid-opaque.ts => valid-opaque.test.ts} (100%) rename test/validation/object/{valid-referential.ts => valid-referential.test.ts} (100%) rename test/validation/object/{valid.ts => valid.test.ts} (100%) rename test/validation/omit/{invalid-element-nested.ts => invalid-element-nested.test.ts} (100%) rename test/validation/omit/{invalid-property-nested.ts => invalid-property-nested.test.ts} (100%) rename test/validation/omit/{invalid-property-unknown.ts => invalid-property-unknown.test.ts} (100%) rename test/validation/omit/{invalid-property.ts => invalid-property.test.ts} (100%) rename test/validation/omit/{invalid.ts => invalid.test.ts} (100%) rename test/validation/omit/{valid-nested.ts => valid-nested.test.ts} (100%) rename test/validation/omit/{valid-type.ts => valid-type.test.ts} (100%) rename test/validation/omit/{valid.ts => valid.test.ts} (100%) rename test/validation/optional/{invalid.ts => invalid.test.ts} (100%) rename test/validation/optional/{valid-defined-nested.ts => valid-defined-nested.test.ts} (100%) rename test/validation/optional/{valid-defined.ts => valid-defined.test.ts} (100%) rename test/validation/optional/{valid-undefined-nested.ts => valid-undefined-nested.test.ts} (100%) rename test/validation/optional/{valid-undefined.ts => valid-undefined.test.ts} (100%) rename test/validation/partial/{composed.ts => composed.test.ts} (100%) rename test/validation/partial/{invalid-property-unknown.ts => invalid-property-unknown.test.ts} (100%) rename test/validation/partial/{invalid-property.ts => invalid-property.test.ts} (100%) rename test/validation/partial/{invalid.ts => invalid.test.ts} (100%) rename test/validation/partial/{valid-empty.ts => valid-empty.test.ts} (100%) rename test/validation/partial/{valid-full.ts => valid-full.test.ts} (100%) rename test/validation/partial/{valid-partial.ts => valid-partial.test.ts} (100%) rename test/validation/partial/{valid-type.ts => valid-type.test.ts} (100%) rename test/validation/pattern/{invalid.ts => invalid.test.ts} (100%) rename test/validation/pattern/{valid.ts => valid.test.ts} (100%) rename test/validation/pick/{invalid-element-nested.ts => invalid-element-nested.test.ts} (100%) rename test/validation/pick/{invalid-property-nested.ts => invalid-property-nested.test.ts} (100%) rename test/validation/pick/{invalid-property-unknown.ts => invalid-property-unknown.test.ts} (100%) rename test/validation/pick/{invalid-property.ts => invalid-property.test.ts} (100%) rename test/validation/pick/{invalid.ts => invalid.test.ts} (100%) rename test/validation/pick/{valid-nested.ts => valid-nested.test.ts} (100%) rename test/validation/pick/{valid-type.ts => valid-type.test.ts} (100%) rename test/validation/pick/{valid.ts => valid.test.ts} (100%) rename test/validation/record/{invalid-array.ts => invalid-array.test.ts} (100%) rename test/validation/record/{invalid-property.ts => invalid-property.test.ts} (100%) rename test/validation/record/{invalid.ts => invalid.test.ts} (100%) rename test/validation/record/{valid-frozen.ts => valid-frozen.test.ts} (100%) rename test/validation/record/{valid.ts => valid.test.ts} (100%) rename test/validation/refine/{invalid-multiple-refinements.ts => invalid-multiple-refinements.test.ts} (100%) rename test/validation/refine/{invalid-shorthand.ts => invalid-shorthand.test.ts} (100%) rename test/validation/refine/{invalid.ts => invalid.test.ts} (100%) rename test/validation/refine/{valid.ts => valid.test.ts} (100%) rename test/validation/regexp/{invalid.ts => invalid.test.ts} (100%) rename test/validation/regexp/{valid.ts => valid.test.ts} (100%) rename test/validation/set/{invalid-element.ts => invalid-element.test.ts} (100%) rename test/validation/set/{invalid-opaque.ts => invalid-opaque.test.ts} (100%) rename test/validation/set/{invalid.ts => invalid.test.ts} (100%) rename test/validation/set/{valid-opaque.ts => valid-opaque.test.ts} (100%) rename test/validation/set/{valid.ts => valid.test.ts} (100%) rename test/validation/size/{invalid-array.ts => invalid-array.test.ts} (100%) rename test/validation/size/{invalid-map.ts => invalid-map.test.ts} (100%) rename test/validation/size/{invalid-number.ts => invalid-number.test.ts} (100%) rename test/validation/size/{invalid-set.ts => invalid-set.test.ts} (100%) rename test/validation/size/{invalid-string.ts => invalid-string.test.ts} (100%) rename test/validation/size/{valid-array.ts => valid-array.test.ts} (100%) rename test/validation/size/{valid-exact.ts => valid-exact.test.ts} (100%) rename test/validation/size/{valid-map.ts => valid-map.test.ts} (100%) rename test/validation/size/{valid-max-inclusive.ts => valid-max-inclusive.test.ts} (100%) rename test/validation/size/{valid-min-inclusive.ts => valid-min-inclusive.test.ts} (100%) rename test/validation/size/{valid-number.ts => valid-number.test.ts} (100%) rename test/validation/size/{valid-set.ts => valid-set.test.ts} (100%) rename test/validation/size/{valid-string.ts => valid-string.test.ts} (100%) rename test/validation/string/{invalid.ts => invalid.test.ts} (100%) rename test/validation/string/{valid.ts => valid.test.ts} (100%) rename test/validation/trimmed/{invalid.ts => invalid.test.ts} (100%) rename test/validation/trimmed/{valid.ts => valid.test.ts} (100%) rename test/validation/tuple/{invalid-element-missing.ts => invalid-element-missing.test.ts} (100%) rename test/validation/tuple/{invalid-element-unknown.ts => invalid-element-unknown.test.ts} (100%) rename test/validation/tuple/{invalid-element.ts => invalid-element.test.ts} (100%) rename test/validation/tuple/{invalid.ts => invalid.test.ts} (100%) rename test/validation/tuple/{valid-frozen.ts => valid-frozen.test.ts} (100%) rename test/validation/tuple/{valid.ts => valid.test.ts} (100%) rename test/validation/type/{invalid-array.ts => invalid-array.test.ts} (100%) rename test/validation/type/{invalid-property-nested.ts => invalid-property-nested.test.ts} (100%) rename test/validation/type/{invalid-property.ts => invalid-property.test.ts} (100%) rename test/validation/type/{invalid.ts => invalid.test.ts} (100%) rename test/validation/type/{valid-frozen.ts => valid-frozen.test.ts} (100%) rename test/validation/type/{valid-instance.ts => valid-instance.test.ts} (100%) rename test/validation/type/{valid.ts => valid.test.ts} (100%) rename test/validation/union/{coercion-object.ts => coercion-object.test.ts} (100%) rename test/validation/union/{coercion-type.ts => coercion-type.test.ts} (100%) rename test/validation/union/{coercion.ts => coercion.test.ts} (100%) rename test/validation/union/{invalid.ts => invalid.test.ts} (100%) rename test/validation/union/{valid.ts => valid.test.ts} (100%) rename test/validation/unknown/{valid-number.ts => valid-number.test.ts} (100%) rename test/validation/unknown/{valid-string.ts => valid-string.test.ts} (100%) rename test/validation/unknown/{valid-undefined.ts => valid-undefined.test.ts} (100%) diff --git a/test/validation/any/valid-number.ts b/test/validation/any/valid-number.test.ts similarity index 100% rename from test/validation/any/valid-number.ts rename to test/validation/any/valid-number.test.ts diff --git a/test/validation/any/valid-string.ts b/test/validation/any/valid-string.test.ts similarity index 100% rename from test/validation/any/valid-string.ts rename to test/validation/any/valid-string.test.ts diff --git a/test/validation/any/valid-undefined.ts b/test/validation/any/valid-undefined.test.ts similarity index 100% rename from test/validation/any/valid-undefined.ts rename to test/validation/any/valid-undefined.test.ts diff --git a/test/validation/array/invalid-element-property.ts b/test/validation/array/invalid-element-property.test.ts similarity index 100% rename from test/validation/array/invalid-element-property.ts rename to test/validation/array/invalid-element-property.test.ts diff --git a/test/validation/array/invalid-element.ts b/test/validation/array/invalid-element.test.ts similarity index 100% rename from test/validation/array/invalid-element.ts rename to test/validation/array/invalid-element.test.ts diff --git a/test/validation/array/invalid-opaque.ts b/test/validation/array/invalid-opaque.test.ts similarity index 100% rename from test/validation/array/invalid-opaque.ts rename to test/validation/array/invalid-opaque.test.ts diff --git a/test/validation/array/invalid.ts b/test/validation/array/invalid.test.ts similarity index 100% rename from test/validation/array/invalid.ts rename to test/validation/array/invalid.test.ts diff --git a/test/validation/array/valid-frozen.ts b/test/validation/array/valid-frozen.test.ts similarity index 100% rename from test/validation/array/valid-frozen.ts rename to test/validation/array/valid-frozen.test.ts diff --git a/test/validation/array/valid-opaque.ts b/test/validation/array/valid-opaque.test.ts similarity index 100% rename from test/validation/array/valid-opaque.ts rename to test/validation/array/valid-opaque.test.ts diff --git a/test/validation/array/valid.ts b/test/validation/array/valid.test.ts similarity index 100% rename from test/validation/array/valid.ts rename to test/validation/array/valid.test.ts diff --git a/test/validation/assign/invalid-object.ts b/test/validation/assign/invalid-object.test.ts similarity index 100% rename from test/validation/assign/invalid-object.ts rename to test/validation/assign/invalid-object.test.ts diff --git a/test/validation/assign/invalid-type.ts b/test/validation/assign/invalid-type.test.ts similarity index 100% rename from test/validation/assign/invalid-type.ts rename to test/validation/assign/invalid-type.test.ts diff --git a/test/validation/assign/valid-object.ts b/test/validation/assign/valid-object.test.ts similarity index 100% rename from test/validation/assign/valid-object.ts rename to test/validation/assign/valid-object.test.ts diff --git a/test/validation/assign/valid-type.ts b/test/validation/assign/valid-type.test.ts similarity index 100% rename from test/validation/assign/valid-type.ts rename to test/validation/assign/valid-type.test.ts diff --git a/test/validation/bigint/invalid-number.ts b/test/validation/bigint/invalid-number.test.ts similarity index 100% rename from test/validation/bigint/invalid-number.ts rename to test/validation/bigint/invalid-number.test.ts diff --git a/test/validation/bigint/invalid.ts b/test/validation/bigint/invalid.test.ts similarity index 100% rename from test/validation/bigint/invalid.ts rename to test/validation/bigint/invalid.test.ts diff --git a/test/validation/bigint/valid.ts b/test/validation/bigint/valid.test.ts similarity index 100% rename from test/validation/bigint/valid.ts rename to test/validation/bigint/valid.test.ts diff --git a/test/validation/boolean/invalid.ts b/test/validation/boolean/invalid.test.ts similarity index 100% rename from test/validation/boolean/invalid.ts rename to test/validation/boolean/invalid.test.ts diff --git a/test/validation/boolean/valid.ts b/test/validation/boolean/valid.test.ts similarity index 100% rename from test/validation/boolean/valid.ts rename to test/validation/boolean/valid.test.ts diff --git a/test/validation/coerce/changed.ts b/test/validation/coerce/changed.test.ts similarity index 100% rename from test/validation/coerce/changed.ts rename to test/validation/coerce/changed.test.ts diff --git a/test/validation/coerce/condition-not-met.ts b/test/validation/coerce/condition-not-met.test.ts similarity index 100% rename from test/validation/coerce/condition-not-met.ts rename to test/validation/coerce/condition-not-met.test.ts diff --git a/test/validation/coerce/unchanged.ts b/test/validation/coerce/unchanged.test.ts similarity index 100% rename from test/validation/coerce/unchanged.ts rename to test/validation/coerce/unchanged.test.ts diff --git a/test/validation/date/invalid-date.ts b/test/validation/date/invalid-date.test.ts similarity index 100% rename from test/validation/date/invalid-date.ts rename to test/validation/date/invalid-date.test.ts diff --git a/test/validation/date/invalid.ts b/test/validation/date/invalid.test.ts similarity index 100% rename from test/validation/date/invalid.ts rename to test/validation/date/invalid.test.ts diff --git a/test/validation/date/valid.ts b/test/validation/date/valid.test.ts similarity index 100% rename from test/validation/date/valid.ts rename to test/validation/date/valid.test.ts diff --git a/test/validation/defaulted/function.ts b/test/validation/defaulted/function.test.ts similarity index 100% rename from test/validation/defaulted/function.ts rename to test/validation/defaulted/function.test.ts diff --git a/test/validation/defaulted/mixin.ts b/test/validation/defaulted/mixin.test.ts similarity index 100% rename from test/validation/defaulted/mixin.ts rename to test/validation/defaulted/mixin.test.ts diff --git a/test/validation/defaulted/nested-double.ts b/test/validation/defaulted/nested-double.test.ts similarity index 100% rename from test/validation/defaulted/nested-double.ts rename to test/validation/defaulted/nested-double.test.ts diff --git a/test/validation/defaulted/nested.ts b/test/validation/defaulted/nested.test.ts similarity index 100% rename from test/validation/defaulted/nested.ts rename to test/validation/defaulted/nested.test.ts diff --git a/test/validation/defaulted/strict.ts b/test/validation/defaulted/strict.test.ts similarity index 100% rename from test/validation/defaulted/strict.ts rename to test/validation/defaulted/strict.test.ts diff --git a/test/validation/defaulted/value.ts b/test/validation/defaulted/value.test.ts similarity index 100% rename from test/validation/defaulted/value.ts rename to test/validation/defaulted/value.test.ts diff --git a/test/validation/deprecated/invalid-null.ts b/test/validation/deprecated/invalid-null.test.ts similarity index 100% rename from test/validation/deprecated/invalid-null.ts rename to test/validation/deprecated/invalid-null.test.ts diff --git a/test/validation/deprecated/invalid-property.ts b/test/validation/deprecated/invalid-property.test.ts similarity index 100% rename from test/validation/deprecated/invalid-property.ts rename to test/validation/deprecated/invalid-property.test.ts diff --git a/test/validation/deprecated/invalid.ts b/test/validation/deprecated/invalid.test.ts similarity index 100% rename from test/validation/deprecated/invalid.ts rename to test/validation/deprecated/invalid.test.ts diff --git a/test/validation/deprecated/valid-property.ts b/test/validation/deprecated/valid-property.test.ts similarity index 100% rename from test/validation/deprecated/valid-property.ts rename to test/validation/deprecated/valid-property.test.ts diff --git a/test/validation/deprecated/valid-undefined.ts b/test/validation/deprecated/valid-undefined.test.ts similarity index 100% rename from test/validation/deprecated/valid-undefined.ts rename to test/validation/deprecated/valid-undefined.test.ts diff --git a/test/validation/deprecated/valid.ts b/test/validation/deprecated/valid.test.ts similarity index 100% rename from test/validation/deprecated/valid.ts rename to test/validation/deprecated/valid.test.ts diff --git a/test/validation/dynamic/invalid-reference.ts b/test/validation/dynamic/invalid-reference.test.ts similarity index 100% rename from test/validation/dynamic/invalid-reference.ts rename to test/validation/dynamic/invalid-reference.test.ts diff --git a/test/validation/dynamic/invalid.ts b/test/validation/dynamic/invalid.test.ts similarity index 100% rename from test/validation/dynamic/invalid.ts rename to test/validation/dynamic/invalid.test.ts diff --git a/test/validation/dynamic/valid-reference.ts b/test/validation/dynamic/valid-reference.test.ts similarity index 100% rename from test/validation/dynamic/valid-reference.ts rename to test/validation/dynamic/valid-reference.test.ts diff --git a/test/validation/dynamic/valid.ts b/test/validation/dynamic/valid.test.ts similarity index 100% rename from test/validation/dynamic/valid.ts rename to test/validation/dynamic/valid.test.ts diff --git a/test/validation/dynamic/with-refiners.ts b/test/validation/dynamic/with-refiners.test.ts similarity index 100% rename from test/validation/dynamic/with-refiners.ts rename to test/validation/dynamic/with-refiners.test.ts diff --git a/test/validation/empty/invalid-array.ts b/test/validation/empty/invalid-array.test.ts similarity index 100% rename from test/validation/empty/invalid-array.ts rename to test/validation/empty/invalid-array.test.ts diff --git a/test/validation/empty/invalid-map.ts b/test/validation/empty/invalid-map.test.ts similarity index 100% rename from test/validation/empty/invalid-map.ts rename to test/validation/empty/invalid-map.test.ts diff --git a/test/validation/empty/invalid-set.ts b/test/validation/empty/invalid-set.test.ts similarity index 100% rename from test/validation/empty/invalid-set.ts rename to test/validation/empty/invalid-set.test.ts diff --git a/test/validation/empty/invalid-string.ts b/test/validation/empty/invalid-string.test.ts similarity index 100% rename from test/validation/empty/invalid-string.ts rename to test/validation/empty/invalid-string.test.ts diff --git a/test/validation/empty/valid-array.ts b/test/validation/empty/valid-array.test.ts similarity index 100% rename from test/validation/empty/valid-array.ts rename to test/validation/empty/valid-array.test.ts diff --git a/test/validation/empty/valid-map.ts b/test/validation/empty/valid-map.test.ts similarity index 100% rename from test/validation/empty/valid-map.ts rename to test/validation/empty/valid-map.test.ts diff --git a/test/validation/empty/valid-set.ts b/test/validation/empty/valid-set.test.ts similarity index 100% rename from test/validation/empty/valid-set.ts rename to test/validation/empty/valid-set.test.ts diff --git a/test/validation/empty/valid-string.ts b/test/validation/empty/valid-string.test.ts similarity index 100% rename from test/validation/empty/valid-string.ts rename to test/validation/empty/valid-string.test.ts diff --git a/test/validation/enums/invalid-numbers.ts b/test/validation/enums/invalid-numbers.test.ts similarity index 100% rename from test/validation/enums/invalid-numbers.ts rename to test/validation/enums/invalid-numbers.test.ts diff --git a/test/validation/enums/invalid-strings.ts b/test/validation/enums/invalid-strings.test.ts similarity index 100% rename from test/validation/enums/invalid-strings.ts rename to test/validation/enums/invalid-strings.test.ts diff --git a/test/validation/enums/valid.ts b/test/validation/enums/valid.test.ts similarity index 100% rename from test/validation/enums/valid.ts rename to test/validation/enums/valid.test.ts diff --git a/test/validation/function/invalid.ts b/test/validation/function/invalid.test.ts similarity index 100% rename from test/validation/function/invalid.ts rename to test/validation/function/invalid.test.ts diff --git a/test/validation/function/valid.ts b/test/validation/function/valid.test.ts similarity index 100% rename from test/validation/function/valid.ts rename to test/validation/function/valid.test.ts diff --git a/test/validation/instance/invalid.ts b/test/validation/instance/invalid.test.ts similarity index 100% rename from test/validation/instance/invalid.ts rename to test/validation/instance/invalid.test.ts diff --git a/test/validation/instance/valid.ts b/test/validation/instance/valid.test.ts similarity index 100% rename from test/validation/instance/valid.ts rename to test/validation/instance/valid.test.ts diff --git a/test/validation/integer/invalid-decimal.ts b/test/validation/integer/invalid-decimal.test.ts similarity index 100% rename from test/validation/integer/invalid-decimal.ts rename to test/validation/integer/invalid-decimal.test.ts diff --git a/test/validation/integer/invalid.ts b/test/validation/integer/invalid.test.ts similarity index 100% rename from test/validation/integer/invalid.ts rename to test/validation/integer/invalid.test.ts diff --git a/test/validation/integer/valid.ts b/test/validation/integer/valid.test.ts similarity index 100% rename from test/validation/integer/valid.ts rename to test/validation/integer/valid.test.ts diff --git a/test/validation/intersection/invalid-refinement.ts b/test/validation/intersection/invalid-refinement.test.ts similarity index 100% rename from test/validation/intersection/invalid-refinement.ts rename to test/validation/intersection/invalid-refinement.test.ts diff --git a/test/validation/intersection/invalid.ts b/test/validation/intersection/invalid.test.ts similarity index 100% rename from test/validation/intersection/invalid.ts rename to test/validation/intersection/invalid.test.ts diff --git a/test/validation/intersection/valid-refinement.ts b/test/validation/intersection/valid-refinement.test.ts similarity index 100% rename from test/validation/intersection/valid-refinement.ts rename to test/validation/intersection/valid-refinement.test.ts diff --git a/test/validation/intersection/valid.ts b/test/validation/intersection/valid.test.ts similarity index 100% rename from test/validation/intersection/valid.ts rename to test/validation/intersection/valid.test.ts diff --git a/test/validation/lazy/invalid.ts b/test/validation/lazy/invalid.test.ts similarity index 100% rename from test/validation/lazy/invalid.ts rename to test/validation/lazy/invalid.test.ts diff --git a/test/validation/lazy/valid.ts b/test/validation/lazy/valid.test.ts similarity index 100% rename from test/validation/lazy/valid.ts rename to test/validation/lazy/valid.test.ts diff --git a/test/validation/lazy/with-refiners.ts b/test/validation/lazy/with-refiners.test.ts similarity index 100% rename from test/validation/lazy/with-refiners.ts rename to test/validation/lazy/with-refiners.test.ts diff --git a/test/validation/literal/invalid.ts b/test/validation/literal/invalid.test.ts similarity index 100% rename from test/validation/literal/invalid.ts rename to test/validation/literal/invalid.test.ts diff --git a/test/validation/literal/valid.ts b/test/validation/literal/valid.test.ts similarity index 100% rename from test/validation/literal/valid.ts rename to test/validation/literal/valid.test.ts diff --git a/test/validation/map/invalid-opaque.ts b/test/validation/map/invalid-opaque.test.ts similarity index 100% rename from test/validation/map/invalid-opaque.ts rename to test/validation/map/invalid-opaque.test.ts diff --git a/test/validation/map/invalid-property.ts b/test/validation/map/invalid-property.test.ts similarity index 100% rename from test/validation/map/invalid-property.ts rename to test/validation/map/invalid-property.test.ts diff --git a/test/validation/map/invalid.ts b/test/validation/map/invalid.test.ts similarity index 100% rename from test/validation/map/invalid.ts rename to test/validation/map/invalid.test.ts diff --git a/test/validation/map/valid-opaque.ts b/test/validation/map/valid-opaque.test.ts similarity index 100% rename from test/validation/map/valid-opaque.ts rename to test/validation/map/valid-opaque.test.ts diff --git a/test/validation/map/valid.ts b/test/validation/map/valid.test.ts similarity index 100% rename from test/validation/map/valid.ts rename to test/validation/map/valid.test.ts diff --git a/test/validation/max/invalid-exclusive.ts b/test/validation/max/invalid-exclusive.test.ts similarity index 100% rename from test/validation/max/invalid-exclusive.ts rename to test/validation/max/invalid-exclusive.test.ts diff --git a/test/validation/max/invalid.ts b/test/validation/max/invalid.test.ts similarity index 100% rename from test/validation/max/invalid.ts rename to test/validation/max/invalid.test.ts diff --git a/test/validation/max/valid-inclusive.ts b/test/validation/max/valid-inclusive.test.ts similarity index 100% rename from test/validation/max/valid-inclusive.ts rename to test/validation/max/valid-inclusive.test.ts diff --git a/test/validation/max/valid.ts b/test/validation/max/valid.test.ts similarity index 100% rename from test/validation/max/valid.ts rename to test/validation/max/valid.test.ts diff --git a/test/validation/min/invalid-exclusive.ts b/test/validation/min/invalid-exclusive.test.ts similarity index 100% rename from test/validation/min/invalid-exclusive.ts rename to test/validation/min/invalid-exclusive.test.ts diff --git a/test/validation/min/invalid.ts b/test/validation/min/invalid.test.ts similarity index 100% rename from test/validation/min/invalid.ts rename to test/validation/min/invalid.test.ts diff --git a/test/validation/min/valid-inclusive.ts b/test/validation/min/valid-inclusive.test.ts similarity index 100% rename from test/validation/min/valid-inclusive.ts rename to test/validation/min/valid-inclusive.test.ts diff --git a/test/validation/min/valid.ts b/test/validation/min/valid.test.ts similarity index 100% rename from test/validation/min/valid.ts rename to test/validation/min/valid.test.ts diff --git a/test/validation/never/invalid.ts b/test/validation/never/invalid.test.ts similarity index 100% rename from test/validation/never/invalid.ts rename to test/validation/never/invalid.test.ts diff --git a/test/validation/nullable/invalid.ts b/test/validation/nullable/invalid.test.ts similarity index 100% rename from test/validation/nullable/invalid.ts rename to test/validation/nullable/invalid.test.ts diff --git a/test/validation/nullable/valid-defined-nested.ts b/test/validation/nullable/valid-defined-nested.test.ts similarity index 100% rename from test/validation/nullable/valid-defined-nested.ts rename to test/validation/nullable/valid-defined-nested.test.ts diff --git a/test/validation/nullable/valid-defined.ts b/test/validation/nullable/valid-defined.test.ts similarity index 100% rename from test/validation/nullable/valid-defined.ts rename to test/validation/nullable/valid-defined.test.ts diff --git a/test/validation/nullable/valid-null-nested.ts b/test/validation/nullable/valid-null-nested.test.ts similarity index 100% rename from test/validation/nullable/valid-null-nested.ts rename to test/validation/nullable/valid-null-nested.test.ts diff --git a/test/validation/nullable/valid-null.ts b/test/validation/nullable/valid-null.test.ts similarity index 100% rename from test/validation/nullable/valid-null.ts rename to test/validation/nullable/valid-null.test.ts diff --git a/test/validation/number/invalid.ts b/test/validation/number/invalid.test.ts similarity index 100% rename from test/validation/number/invalid.ts rename to test/validation/number/invalid.test.ts diff --git a/test/validation/number/valid.ts b/test/validation/number/valid.test.ts similarity index 100% rename from test/validation/number/valid.ts rename to test/validation/number/valid.test.ts diff --git a/test/validation/object/invalid-array.ts b/test/validation/object/invalid-array.test.ts similarity index 100% rename from test/validation/object/invalid-array.ts rename to test/validation/object/invalid-array.test.ts diff --git a/test/validation/object/invalid-element-nested.ts b/test/validation/object/invalid-element-nested.test.ts similarity index 100% rename from test/validation/object/invalid-element-nested.ts rename to test/validation/object/invalid-element-nested.test.ts diff --git a/test/validation/object/invalid-opaque.ts b/test/validation/object/invalid-opaque.test.ts similarity index 100% rename from test/validation/object/invalid-opaque.ts rename to test/validation/object/invalid-opaque.test.ts diff --git a/test/validation/object/invalid-property-nested.ts b/test/validation/object/invalid-property-nested.test.ts similarity index 100% rename from test/validation/object/invalid-property-nested.ts rename to test/validation/object/invalid-property-nested.test.ts diff --git a/test/validation/object/invalid-property-unknown.ts b/test/validation/object/invalid-property-unknown.test.ts similarity index 100% rename from test/validation/object/invalid-property-unknown.ts rename to test/validation/object/invalid-property-unknown.test.ts diff --git a/test/validation/object/invalid-property.ts b/test/validation/object/invalid-property.test.ts similarity index 100% rename from test/validation/object/invalid-property.ts rename to test/validation/object/invalid-property.test.ts diff --git a/test/validation/object/invalid-referential.ts b/test/validation/object/invalid-referential.test.ts similarity index 100% rename from test/validation/object/invalid-referential.ts rename to test/validation/object/invalid-referential.test.ts diff --git a/test/validation/object/invalid.ts b/test/validation/object/invalid.test.ts similarity index 100% rename from test/validation/object/invalid.ts rename to test/validation/object/invalid.test.ts diff --git a/test/validation/object/valid-frozen.ts b/test/validation/object/valid-frozen.test.ts similarity index 100% rename from test/validation/object/valid-frozen.ts rename to test/validation/object/valid-frozen.test.ts diff --git a/test/validation/object/valid-nested.ts b/test/validation/object/valid-nested.test.ts similarity index 100% rename from test/validation/object/valid-nested.ts rename to test/validation/object/valid-nested.test.ts diff --git a/test/validation/object/valid-opaque.ts b/test/validation/object/valid-opaque.test.ts similarity index 100% rename from test/validation/object/valid-opaque.ts rename to test/validation/object/valid-opaque.test.ts diff --git a/test/validation/object/valid-referential.ts b/test/validation/object/valid-referential.test.ts similarity index 100% rename from test/validation/object/valid-referential.ts rename to test/validation/object/valid-referential.test.ts diff --git a/test/validation/object/valid.ts b/test/validation/object/valid.test.ts similarity index 100% rename from test/validation/object/valid.ts rename to test/validation/object/valid.test.ts diff --git a/test/validation/omit/invalid-element-nested.ts b/test/validation/omit/invalid-element-nested.test.ts similarity index 100% rename from test/validation/omit/invalid-element-nested.ts rename to test/validation/omit/invalid-element-nested.test.ts diff --git a/test/validation/omit/invalid-property-nested.ts b/test/validation/omit/invalid-property-nested.test.ts similarity index 100% rename from test/validation/omit/invalid-property-nested.ts rename to test/validation/omit/invalid-property-nested.test.ts diff --git a/test/validation/omit/invalid-property-unknown.ts b/test/validation/omit/invalid-property-unknown.test.ts similarity index 100% rename from test/validation/omit/invalid-property-unknown.ts rename to test/validation/omit/invalid-property-unknown.test.ts diff --git a/test/validation/omit/invalid-property.ts b/test/validation/omit/invalid-property.test.ts similarity index 100% rename from test/validation/omit/invalid-property.ts rename to test/validation/omit/invalid-property.test.ts diff --git a/test/validation/omit/invalid.ts b/test/validation/omit/invalid.test.ts similarity index 100% rename from test/validation/omit/invalid.ts rename to test/validation/omit/invalid.test.ts diff --git a/test/validation/omit/valid-nested.ts b/test/validation/omit/valid-nested.test.ts similarity index 100% rename from test/validation/omit/valid-nested.ts rename to test/validation/omit/valid-nested.test.ts diff --git a/test/validation/omit/valid-type.ts b/test/validation/omit/valid-type.test.ts similarity index 100% rename from test/validation/omit/valid-type.ts rename to test/validation/omit/valid-type.test.ts diff --git a/test/validation/omit/valid.ts b/test/validation/omit/valid.test.ts similarity index 100% rename from test/validation/omit/valid.ts rename to test/validation/omit/valid.test.ts diff --git a/test/validation/optional/invalid.ts b/test/validation/optional/invalid.test.ts similarity index 100% rename from test/validation/optional/invalid.ts rename to test/validation/optional/invalid.test.ts diff --git a/test/validation/optional/valid-defined-nested.ts b/test/validation/optional/valid-defined-nested.test.ts similarity index 100% rename from test/validation/optional/valid-defined-nested.ts rename to test/validation/optional/valid-defined-nested.test.ts diff --git a/test/validation/optional/valid-defined.ts b/test/validation/optional/valid-defined.test.ts similarity index 100% rename from test/validation/optional/valid-defined.ts rename to test/validation/optional/valid-defined.test.ts diff --git a/test/validation/optional/valid-undefined-nested.ts b/test/validation/optional/valid-undefined-nested.test.ts similarity index 100% rename from test/validation/optional/valid-undefined-nested.ts rename to test/validation/optional/valid-undefined-nested.test.ts diff --git a/test/validation/optional/valid-undefined.ts b/test/validation/optional/valid-undefined.test.ts similarity index 100% rename from test/validation/optional/valid-undefined.ts rename to test/validation/optional/valid-undefined.test.ts diff --git a/test/validation/partial/composed.ts b/test/validation/partial/composed.test.ts similarity index 100% rename from test/validation/partial/composed.ts rename to test/validation/partial/composed.test.ts diff --git a/test/validation/partial/invalid-property-unknown.ts b/test/validation/partial/invalid-property-unknown.test.ts similarity index 100% rename from test/validation/partial/invalid-property-unknown.ts rename to test/validation/partial/invalid-property-unknown.test.ts diff --git a/test/validation/partial/invalid-property.ts b/test/validation/partial/invalid-property.test.ts similarity index 100% rename from test/validation/partial/invalid-property.ts rename to test/validation/partial/invalid-property.test.ts diff --git a/test/validation/partial/invalid.ts b/test/validation/partial/invalid.test.ts similarity index 100% rename from test/validation/partial/invalid.ts rename to test/validation/partial/invalid.test.ts diff --git a/test/validation/partial/valid-empty.ts b/test/validation/partial/valid-empty.test.ts similarity index 100% rename from test/validation/partial/valid-empty.ts rename to test/validation/partial/valid-empty.test.ts diff --git a/test/validation/partial/valid-full.ts b/test/validation/partial/valid-full.test.ts similarity index 100% rename from test/validation/partial/valid-full.ts rename to test/validation/partial/valid-full.test.ts diff --git a/test/validation/partial/valid-partial.ts b/test/validation/partial/valid-partial.test.ts similarity index 100% rename from test/validation/partial/valid-partial.ts rename to test/validation/partial/valid-partial.test.ts diff --git a/test/validation/partial/valid-type.ts b/test/validation/partial/valid-type.test.ts similarity index 100% rename from test/validation/partial/valid-type.ts rename to test/validation/partial/valid-type.test.ts diff --git a/test/validation/pattern/invalid.ts b/test/validation/pattern/invalid.test.ts similarity index 100% rename from test/validation/pattern/invalid.ts rename to test/validation/pattern/invalid.test.ts diff --git a/test/validation/pattern/valid.ts b/test/validation/pattern/valid.test.ts similarity index 100% rename from test/validation/pattern/valid.ts rename to test/validation/pattern/valid.test.ts diff --git a/test/validation/pick/invalid-element-nested.ts b/test/validation/pick/invalid-element-nested.test.ts similarity index 100% rename from test/validation/pick/invalid-element-nested.ts rename to test/validation/pick/invalid-element-nested.test.ts diff --git a/test/validation/pick/invalid-property-nested.ts b/test/validation/pick/invalid-property-nested.test.ts similarity index 100% rename from test/validation/pick/invalid-property-nested.ts rename to test/validation/pick/invalid-property-nested.test.ts diff --git a/test/validation/pick/invalid-property-unknown.ts b/test/validation/pick/invalid-property-unknown.test.ts similarity index 100% rename from test/validation/pick/invalid-property-unknown.ts rename to test/validation/pick/invalid-property-unknown.test.ts diff --git a/test/validation/pick/invalid-property.ts b/test/validation/pick/invalid-property.test.ts similarity index 100% rename from test/validation/pick/invalid-property.ts rename to test/validation/pick/invalid-property.test.ts diff --git a/test/validation/pick/invalid.ts b/test/validation/pick/invalid.test.ts similarity index 100% rename from test/validation/pick/invalid.ts rename to test/validation/pick/invalid.test.ts diff --git a/test/validation/pick/valid-nested.ts b/test/validation/pick/valid-nested.test.ts similarity index 100% rename from test/validation/pick/valid-nested.ts rename to test/validation/pick/valid-nested.test.ts diff --git a/test/validation/pick/valid-type.ts b/test/validation/pick/valid-type.test.ts similarity index 100% rename from test/validation/pick/valid-type.ts rename to test/validation/pick/valid-type.test.ts diff --git a/test/validation/pick/valid.ts b/test/validation/pick/valid.test.ts similarity index 100% rename from test/validation/pick/valid.ts rename to test/validation/pick/valid.test.ts diff --git a/test/validation/record/invalid-array.ts b/test/validation/record/invalid-array.test.ts similarity index 100% rename from test/validation/record/invalid-array.ts rename to test/validation/record/invalid-array.test.ts diff --git a/test/validation/record/invalid-property.ts b/test/validation/record/invalid-property.test.ts similarity index 100% rename from test/validation/record/invalid-property.ts rename to test/validation/record/invalid-property.test.ts diff --git a/test/validation/record/invalid.ts b/test/validation/record/invalid.test.ts similarity index 100% rename from test/validation/record/invalid.ts rename to test/validation/record/invalid.test.ts diff --git a/test/validation/record/valid-frozen.ts b/test/validation/record/valid-frozen.test.ts similarity index 100% rename from test/validation/record/valid-frozen.ts rename to test/validation/record/valid-frozen.test.ts diff --git a/test/validation/record/valid.ts b/test/validation/record/valid.test.ts similarity index 100% rename from test/validation/record/valid.ts rename to test/validation/record/valid.test.ts diff --git a/test/validation/refine/invalid-multiple-refinements.ts b/test/validation/refine/invalid-multiple-refinements.test.ts similarity index 100% rename from test/validation/refine/invalid-multiple-refinements.ts rename to test/validation/refine/invalid-multiple-refinements.test.ts diff --git a/test/validation/refine/invalid-shorthand.ts b/test/validation/refine/invalid-shorthand.test.ts similarity index 100% rename from test/validation/refine/invalid-shorthand.ts rename to test/validation/refine/invalid-shorthand.test.ts diff --git a/test/validation/refine/invalid.ts b/test/validation/refine/invalid.test.ts similarity index 100% rename from test/validation/refine/invalid.ts rename to test/validation/refine/invalid.test.ts diff --git a/test/validation/refine/valid.ts b/test/validation/refine/valid.test.ts similarity index 100% rename from test/validation/refine/valid.ts rename to test/validation/refine/valid.test.ts diff --git a/test/validation/regexp/invalid.ts b/test/validation/regexp/invalid.test.ts similarity index 100% rename from test/validation/regexp/invalid.ts rename to test/validation/regexp/invalid.test.ts diff --git a/test/validation/regexp/valid.ts b/test/validation/regexp/valid.test.ts similarity index 100% rename from test/validation/regexp/valid.ts rename to test/validation/regexp/valid.test.ts diff --git a/test/validation/set/invalid-element.ts b/test/validation/set/invalid-element.test.ts similarity index 100% rename from test/validation/set/invalid-element.ts rename to test/validation/set/invalid-element.test.ts diff --git a/test/validation/set/invalid-opaque.ts b/test/validation/set/invalid-opaque.test.ts similarity index 100% rename from test/validation/set/invalid-opaque.ts rename to test/validation/set/invalid-opaque.test.ts diff --git a/test/validation/set/invalid.ts b/test/validation/set/invalid.test.ts similarity index 100% rename from test/validation/set/invalid.ts rename to test/validation/set/invalid.test.ts diff --git a/test/validation/set/valid-opaque.ts b/test/validation/set/valid-opaque.test.ts similarity index 100% rename from test/validation/set/valid-opaque.ts rename to test/validation/set/valid-opaque.test.ts diff --git a/test/validation/set/valid.ts b/test/validation/set/valid.test.ts similarity index 100% rename from test/validation/set/valid.ts rename to test/validation/set/valid.test.ts diff --git a/test/validation/size/invalid-array.ts b/test/validation/size/invalid-array.test.ts similarity index 100% rename from test/validation/size/invalid-array.ts rename to test/validation/size/invalid-array.test.ts diff --git a/test/validation/size/invalid-map.ts b/test/validation/size/invalid-map.test.ts similarity index 100% rename from test/validation/size/invalid-map.ts rename to test/validation/size/invalid-map.test.ts diff --git a/test/validation/size/invalid-number.ts b/test/validation/size/invalid-number.test.ts similarity index 100% rename from test/validation/size/invalid-number.ts rename to test/validation/size/invalid-number.test.ts diff --git a/test/validation/size/invalid-set.ts b/test/validation/size/invalid-set.test.ts similarity index 100% rename from test/validation/size/invalid-set.ts rename to test/validation/size/invalid-set.test.ts diff --git a/test/validation/size/invalid-string.ts b/test/validation/size/invalid-string.test.ts similarity index 100% rename from test/validation/size/invalid-string.ts rename to test/validation/size/invalid-string.test.ts diff --git a/test/validation/size/valid-array.ts b/test/validation/size/valid-array.test.ts similarity index 100% rename from test/validation/size/valid-array.ts rename to test/validation/size/valid-array.test.ts diff --git a/test/validation/size/valid-exact.ts b/test/validation/size/valid-exact.test.ts similarity index 100% rename from test/validation/size/valid-exact.ts rename to test/validation/size/valid-exact.test.ts diff --git a/test/validation/size/valid-map.ts b/test/validation/size/valid-map.test.ts similarity index 100% rename from test/validation/size/valid-map.ts rename to test/validation/size/valid-map.test.ts diff --git a/test/validation/size/valid-max-inclusive.ts b/test/validation/size/valid-max-inclusive.test.ts similarity index 100% rename from test/validation/size/valid-max-inclusive.ts rename to test/validation/size/valid-max-inclusive.test.ts diff --git a/test/validation/size/valid-min-inclusive.ts b/test/validation/size/valid-min-inclusive.test.ts similarity index 100% rename from test/validation/size/valid-min-inclusive.ts rename to test/validation/size/valid-min-inclusive.test.ts diff --git a/test/validation/size/valid-number.ts b/test/validation/size/valid-number.test.ts similarity index 100% rename from test/validation/size/valid-number.ts rename to test/validation/size/valid-number.test.ts diff --git a/test/validation/size/valid-set.ts b/test/validation/size/valid-set.test.ts similarity index 100% rename from test/validation/size/valid-set.ts rename to test/validation/size/valid-set.test.ts diff --git a/test/validation/size/valid-string.ts b/test/validation/size/valid-string.test.ts similarity index 100% rename from test/validation/size/valid-string.ts rename to test/validation/size/valid-string.test.ts diff --git a/test/validation/string/invalid.ts b/test/validation/string/invalid.test.ts similarity index 100% rename from test/validation/string/invalid.ts rename to test/validation/string/invalid.test.ts diff --git a/test/validation/string/valid.ts b/test/validation/string/valid.test.ts similarity index 100% rename from test/validation/string/valid.ts rename to test/validation/string/valid.test.ts diff --git a/test/validation/trimmed/invalid.ts b/test/validation/trimmed/invalid.test.ts similarity index 100% rename from test/validation/trimmed/invalid.ts rename to test/validation/trimmed/invalid.test.ts diff --git a/test/validation/trimmed/valid.ts b/test/validation/trimmed/valid.test.ts similarity index 100% rename from test/validation/trimmed/valid.ts rename to test/validation/trimmed/valid.test.ts diff --git a/test/validation/tuple/invalid-element-missing.ts b/test/validation/tuple/invalid-element-missing.test.ts similarity index 100% rename from test/validation/tuple/invalid-element-missing.ts rename to test/validation/tuple/invalid-element-missing.test.ts diff --git a/test/validation/tuple/invalid-element-unknown.ts b/test/validation/tuple/invalid-element-unknown.test.ts similarity index 100% rename from test/validation/tuple/invalid-element-unknown.ts rename to test/validation/tuple/invalid-element-unknown.test.ts diff --git a/test/validation/tuple/invalid-element.ts b/test/validation/tuple/invalid-element.test.ts similarity index 100% rename from test/validation/tuple/invalid-element.ts rename to test/validation/tuple/invalid-element.test.ts diff --git a/test/validation/tuple/invalid.ts b/test/validation/tuple/invalid.test.ts similarity index 100% rename from test/validation/tuple/invalid.ts rename to test/validation/tuple/invalid.test.ts diff --git a/test/validation/tuple/valid-frozen.ts b/test/validation/tuple/valid-frozen.test.ts similarity index 100% rename from test/validation/tuple/valid-frozen.ts rename to test/validation/tuple/valid-frozen.test.ts diff --git a/test/validation/tuple/valid.ts b/test/validation/tuple/valid.test.ts similarity index 100% rename from test/validation/tuple/valid.ts rename to test/validation/tuple/valid.test.ts diff --git a/test/validation/type/invalid-array.ts b/test/validation/type/invalid-array.test.ts similarity index 100% rename from test/validation/type/invalid-array.ts rename to test/validation/type/invalid-array.test.ts diff --git a/test/validation/type/invalid-property-nested.ts b/test/validation/type/invalid-property-nested.test.ts similarity index 100% rename from test/validation/type/invalid-property-nested.ts rename to test/validation/type/invalid-property-nested.test.ts diff --git a/test/validation/type/invalid-property.ts b/test/validation/type/invalid-property.test.ts similarity index 100% rename from test/validation/type/invalid-property.ts rename to test/validation/type/invalid-property.test.ts diff --git a/test/validation/type/invalid.ts b/test/validation/type/invalid.test.ts similarity index 100% rename from test/validation/type/invalid.ts rename to test/validation/type/invalid.test.ts diff --git a/test/validation/type/valid-frozen.ts b/test/validation/type/valid-frozen.test.ts similarity index 100% rename from test/validation/type/valid-frozen.ts rename to test/validation/type/valid-frozen.test.ts diff --git a/test/validation/type/valid-instance.ts b/test/validation/type/valid-instance.test.ts similarity index 100% rename from test/validation/type/valid-instance.ts rename to test/validation/type/valid-instance.test.ts diff --git a/test/validation/type/valid.ts b/test/validation/type/valid.test.ts similarity index 100% rename from test/validation/type/valid.ts rename to test/validation/type/valid.test.ts diff --git a/test/validation/union/coercion-object.ts b/test/validation/union/coercion-object.test.ts similarity index 100% rename from test/validation/union/coercion-object.ts rename to test/validation/union/coercion-object.test.ts diff --git a/test/validation/union/coercion-type.ts b/test/validation/union/coercion-type.test.ts similarity index 100% rename from test/validation/union/coercion-type.ts rename to test/validation/union/coercion-type.test.ts diff --git a/test/validation/union/coercion.ts b/test/validation/union/coercion.test.ts similarity index 100% rename from test/validation/union/coercion.ts rename to test/validation/union/coercion.test.ts diff --git a/test/validation/union/invalid.ts b/test/validation/union/invalid.test.ts similarity index 100% rename from test/validation/union/invalid.ts rename to test/validation/union/invalid.test.ts diff --git a/test/validation/union/valid.ts b/test/validation/union/valid.test.ts similarity index 100% rename from test/validation/union/valid.ts rename to test/validation/union/valid.test.ts diff --git a/test/validation/unknown/valid-number.ts b/test/validation/unknown/valid-number.test.ts similarity index 100% rename from test/validation/unknown/valid-number.ts rename to test/validation/unknown/valid-number.test.ts diff --git a/test/validation/unknown/valid-string.ts b/test/validation/unknown/valid-string.test.ts similarity index 100% rename from test/validation/unknown/valid-string.ts rename to test/validation/unknown/valid-string.test.ts diff --git a/test/validation/unknown/valid-undefined.ts b/test/validation/unknown/valid-undefined.test.ts similarity index 100% rename from test/validation/unknown/valid-undefined.ts rename to test/validation/unknown/valid-undefined.test.ts From a5a759f4d24dce4d3237fd84fbfd0e90dc4dae75 Mon Sep 17 00:00:00 2001 From: Geoff Date: Mon, 19 Aug 2024 23:20:19 -0400 Subject: [PATCH 5/6] Remove the old test runner --- test/index.test.ts | 81 ---------------------------------------------- 1 file changed, 81 deletions(-) delete mode 100644 test/index.test.ts diff --git a/test/index.test.ts b/test/index.test.ts deleted file mode 100644 index bb990e2a..00000000 --- a/test/index.test.ts +++ /dev/null @@ -1,81 +0,0 @@ -import fs from 'fs' -import { pick } from 'lodash' -import { basename, extname, resolve } from 'path' -import { describe, expect, it } from 'vitest' -import { - assert as assertValue, - create as createValue, - StructError, -} from '../src' -describe('superstruct', () => { - describe('validation', () => { - const kindsDir = resolve(__dirname, 'validation') - const kinds = fs - .readdirSync(kindsDir) - .filter((t) => t[0] !== '.') - .map((t) => basename(t, extname(t))) - - for (const kind of kinds) { - describe(kind, async () => { - const testsDir = resolve(kindsDir, kind) - const tests = fs - .readdirSync(testsDir) - .filter((t) => t[0] !== '.') - .map((t) => basename(t, extname(t))) - - for (const name of tests) { - const module = await import(resolve(testsDir, name)) - const { Struct, data, create, only, skip, output, failures } = module - const run = only ? it.only : skip ? it.skip : it - run(name, () => { - let actual - let err - - try { - if (create) { - actual = createValue(data, Struct) - } else { - assertValue(data, Struct) - actual = data - } - } catch (e) { - if (!(e instanceof StructError)) { - throw e - } - - err = e - } - - if ('output' in module) { - if (err) { - throw new Error( - `Expected "${name}" fixture not to throw an error but it did:\n\n${err}` - ) - } - - expect(actual).toStrictEqual(output) - } else if ('failures' in module) { - if (!err) { - throw new Error( - `Expected "${name}" fixture to throw an error but it did not.` - ) - } - - const props = ['type', 'path', 'refinement', 'value', 'branch'] - const actualFailures = err - .failures() - .map((failure) => pick(failure, ...props)) - - expect(actualFailures).toStrictEqual(failures) - expect(pick(err, ...props)).toStrictEqual(failures[0]) - } else { - throw new Error( - `The "${name}" fixture did not define an \`output\` or \`failures\` export.` - ) - } - }) - } - }) - } - }) -}) From 122c5148d22af95a6c410d143223f3e9df48d256 Mon Sep 17 00:00:00 2001 From: Geoff Date: Mon, 19 Aug 2024 23:23:52 -0400 Subject: [PATCH 6/6] Manual type fixes --- test/validation/dynamic/valid-reference.test.ts | 1 - test/validation/empty/valid-array.test.ts | 2 +- test/validation/object/invalid-array.test.ts | 2 +- test/validation/record/invalid-array.test.ts | 2 +- test/validation/size/invalid-array.test.ts | 2 +- test/validation/type/invalid-array.test.ts | 2 +- 6 files changed, 5 insertions(+), 6 deletions(-) diff --git a/test/validation/dynamic/valid-reference.test.ts b/test/validation/dynamic/valid-reference.test.ts index 26995883..f1d52f48 100644 --- a/test/validation/dynamic/valid-reference.test.ts +++ b/test/validation/dynamic/valid-reference.test.ts @@ -1,4 +1,3 @@ -import { assert } from '../../../src' import { expect, test } from 'vitest' import { assert, type, dynamic, literal, string, number } from '../../../src' diff --git a/test/validation/empty/valid-array.test.ts b/test/validation/empty/valid-array.test.ts index f09c3786..e5ab8af9 100644 --- a/test/validation/empty/valid-array.test.ts +++ b/test/validation/empty/valid-array.test.ts @@ -3,7 +3,7 @@ import { expect, test } from 'vitest' import { number, array, empty } from '../../../src' test('Valid empty array', () => { - const data = [] + const data: any[] = [] assert(data, empty(array(number()))) expect(data).toStrictEqual([]) }) diff --git a/test/validation/object/invalid-array.test.ts b/test/validation/object/invalid-array.test.ts index 901bfd30..1fa004e8 100644 --- a/test/validation/object/invalid-array.test.ts +++ b/test/validation/object/invalid-array.test.ts @@ -3,7 +3,7 @@ import { expect, test } from 'vitest' import { object } from '../../../src' test('Invalid object array', () => { - const data = [] + const data: any[] = [] const [err, res] = validate(data, object()) expect(res).toBeUndefined() diff --git a/test/validation/record/invalid-array.test.ts b/test/validation/record/invalid-array.test.ts index 62e56049..6629c09f 100644 --- a/test/validation/record/invalid-array.test.ts +++ b/test/validation/record/invalid-array.test.ts @@ -3,7 +3,7 @@ import { expect, test } from 'vitest' import { record, string, number } from '../../../src' test('Invalid record array', () => { - const data = [] + const data: any[] = [] const [err, res] = validate(data, record(string(), number())) expect(res).toBeUndefined() diff --git a/test/validation/size/invalid-array.test.ts b/test/validation/size/invalid-array.test.ts index 0ef60ccf..f6c7f4f1 100644 --- a/test/validation/size/invalid-array.test.ts +++ b/test/validation/size/invalid-array.test.ts @@ -3,7 +3,7 @@ import { expect, test } from 'vitest' import { array, size, number } from '../../../src' test('Invalid size array', () => { - const data = [] + const data: any[] = [] const [err, res] = validate(data, size(array(number()), 1, 5)) expect(res).toBeUndefined() diff --git a/test/validation/type/invalid-array.test.ts b/test/validation/type/invalid-array.test.ts index f44f5fbd..79958b80 100644 --- a/test/validation/type/invalid-array.test.ts +++ b/test/validation/type/invalid-array.test.ts @@ -3,7 +3,7 @@ import { expect, test } from 'vitest' import { type } from '../../../src' test('Invalid type array', () => { - const data = [] + const data: any[] = [] const [err, res] = validate(data, type({})) expect(res).toBeUndefined()