Skip to content

Commit

Permalink
Merge pull request #150 from samchon/v3.0
Browse files Browse the repository at this point in the history
Fix #149
  • Loading branch information
samchon authored Jul 9, 2022
2 parents 01d2b50 + 2be19b3 commit ff2e95c
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 45 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "3.0.11",
"version": "3.0.12",
"description": "Runtime type checkers and 5x faster JSON.stringify() function",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down Expand Up @@ -28,13 +28,13 @@
"typescript",
"transform",
"ajv",
"io-ts",
"schema",
"jsonschema",
"generator",
"validator",
"runtime",
"type",
"check",
"checker"
],
"author": "Jeongho Nam",
Expand Down
6 changes: 3 additions & 3 deletions src/programmers/CheckerProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export namespace CheckerProgrammer {
explore: IExplore,
): ts.Expression {
if (meta.any) return ValueFactory.BOOLEAN(true);
explore.tracable = explore.tracable && meta.size() === 1;
// explore.tracable = explore.tracable && meta.size() === 1;

const top: ts.Expression[] = [];
const binaries: ts.Expression[] = [];
Expand Down Expand Up @@ -227,7 +227,7 @@ export namespace CheckerProgrammer {
...top,
config.combiner({
...explore,
tracable: false,
// tracable: false,
})("or")(input, binaries, meta.getName()),
],
meta.getName(),
Expand Down Expand Up @@ -287,7 +287,7 @@ export namespace CheckerProgrammer {
from: "array",
postfix: explore.postfix.length
? `${explore.postfix.slice(0, -1)}[${index}]"`
: `"[${index}]"`,
: `[${index}]`,
},
),
);
Expand Down
7 changes: 2 additions & 5 deletions src/programmers/helpers/UnionExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,7 @@ export namespace UnionExplorer {
{
...explore,
tracable: false,
postfix:
IdentifierFactory.postfix(
"[0]",
),
postfix: `"[0]"`,
},
),
),
Expand All @@ -183,7 +180,7 @@ export namespace UnionExplorer {
meta,
{
...explore,
tracable: true,
tracable: false,
},
),
),
Expand Down
1 change: 0 additions & 1 deletion test/features/assert/_test_assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export function _test_assert<T>(
console.log({
input: path.value,
expected: exp.path,
value: elem,
});
}
throw new Error(
Expand Down
6 changes: 5 additions & 1 deletion test/features/assert/_test_assert_for_of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ export function _test_assert_for_of<T>(
exp.path === path.value
)
return;
else console.log(path.value, exp.path);
else
console.log({
input: path.value,
expected: exp.path,
});
}
throw new Error(
`Bug on TSON.assertType(): failed to detect error on the ${name} type.`,
Expand Down
6 changes: 3 additions & 3 deletions test/features/assert/test_assert_atomic_union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export const test_assert_atomic_union = _test_assert(
[
(input) => {
input[0] = [] as any;
return "$input";
return "$input[0]";
},
(input) => {
input[1] = {} as any;
return "$input";
return "$input[1]";
},
(input) => {
input[2] = undefined!;
return "$input";
return "$input[2]";
},
],
);
6 changes: 3 additions & 3 deletions test/features/assert/test_assert_constant_atomic_union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export const test_assert_constant_atomic_union = _test_assert(
[
(input) => {
input[0] = 3 as 1;
return "$input";
return "$input[0]";
},
(input) => {
input[1] = "two" as "three";
return "$input";
return "$input[1]";
},
(input) => {
input[2] = { key: "something" as "key" };
return "$input";
return "$input[2].key";
},
],
);
4 changes: 2 additions & 2 deletions test/features/assert/test_assert_functional_object_union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export const test_assert_functional_object_union = _test_assert_for_of(
(input) => {
if ((input as any).length) {
(input as any).length = {} as any;
return "$input";
return "$input.length";
}
(input as any).distance = [] as any;
return "$input";
return "$input.distance";
},
],
);
4 changes: 2 additions & 2 deletions test/features/assert/test_assert_functional_property_union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export const test_assert_functional_property_union = _test_assert_for_of(
[
(input) => {
input.closure = {} as any;
return "$input";
return "$input.closure";
},
(input) => {
input.closure = [] as any;
return "$input";
return "$input.closure";
},
],
);
2 changes: 1 addition & 1 deletion test/features/assert/test_assert_object_alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const test_assert_object_alias = _test_assert_for_of(
},
(input) => {
input.sex = 3 as 2;
return "$input"; // @todo
return "$input.sex";
},
(input) => {
input.age = "old" as any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TSON from "../../../src";
import { ObjectNullable } from "../../structures/ObjectNullable";
import { _test_assert_for_of } from "../assert/_test_assert_for_of";
import { _test_assert_for_of } from "./_test_assert_for_of";

export const test_assert_object_nullable = _test_assert_for_of(
"nullable object",
Expand Down Expand Up @@ -43,18 +43,18 @@ export const test_assert_object_nullable = _test_assert_for_of(
},
(input) => {
input.similar = undefined!;
return `$input`; // @todo
return `$input.similar`;
},
(input) => {
input.similar = {
type: "manufacturer",
name: undefined!,
};
return `$input`; // @todo
return `$input.similar.name`;
},
(input) => {
input.similar = [] as any;
return `$input`; // @todo
return `$input.similar`;
},
],
);
2 changes: 1 addition & 1 deletion test/features/assert/test_assert_object_primitive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const test_assert_object_primitive = _test_assert(
},
(input) => {
input.extension = "jpg" as "md";
return "$input"; // @todo
return "$input.extension";
},
(input) => {
input.files = {} as any;
Expand Down
4 changes: 2 additions & 2 deletions test/features/assert/test_assert_object_undefined.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ export const test_assert_object_undefined = _test_assert(
[
(input) => {
input[0].professor = null!;
return "$input[0]"; // @todo
return "$input[0].professor";
},
(input) => {
input[0].classroom = [] as any;
return "$input[0].classroom.id";
},
(input) => {
input[0].nothing = "undefined" as any;
return "$input[0]"; // @todo
return "$input[0].nothing";
},
],
);
16 changes: 14 additions & 2 deletions test/features/assert/test_assert_object_union_non_predictable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@ export const test_assert_object_union_non_predictable = _test_assert_for_of(
(input) => TSON.assertType(input),
[
(input) => {
input.value.value = null!;
return "$input"; // @todo
input.value.value.value.value = null!;
return "$input.value.value";
},
(input) => {
input.value.value.value.value = undefined!;
return "$input.value.value";
},
(input) => {
input.value.value.value.value = [] as any;
return "$input.value.value";
},
(input) => {
input.value.value.value.value = {} as any;
return "$input.value.value";
},
],
);
4 changes: 2 additions & 2 deletions test/features/assert/test_assert_tuple_hierarchical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const test_assert_tuple_hierarchical = _test_assert(
},
(input) => {
input[1] = "undefined" as any;
return "$input"; // @todo
return "$input[1]";
},
(input) => {
input[2] = "number" as any;
Expand All @@ -25,7 +25,7 @@ export const test_assert_tuple_hierarchical = _test_assert(
},
(input) => {
input[3][1] = "null" as any;
return "$input[3]"; // @todo
return "$input[3][1]";
},
(input) => {
input[3][2][0] = "number" as any;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import TSON from "../../../src";
import { ObjectNullable } from "../../structures/ObjectNullable";
import { _test_is } from "../is/_test_is";
import { _test_is } from "./_test_is";

export const test_is_object_nullable = _test_is(
"nullable object",
Expand Down
8 changes: 4 additions & 4 deletions test/features/is/test_is_object_union_non_predictable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const test_is_object_union_non_predictable = _test_is(
ObjectUnionNonPredictable.generate,
(input) => TSON.is(input),
[
(input) => (input[0].value.value = [] as any),
(input) => (input[1].value.value = {} as any),
(input) => (input[2].value.value = null!),
(input) => (input[3].value = undefined!),
(input) => (input[0].value.value.value.value = [] as any),
(input) => (input[1].value.value.value.value = {} as any),
(input) => (input[2].value.value.value = null!),
(input) => (input[3].value.value.value = undefined!),
],
);
2 changes: 1 addition & 1 deletion test/manual.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ runner.register({
compiler: "ttypescript",
});

const program = require("./features/assert/test_assert_array_atomic_simple.ts");
const program = require("./features/assert/test_assert_functional_array_union.ts");
for (const value of Object.values(program))
if (typeof value === "function") value();
11 changes: 6 additions & 5 deletions test/structures/ObjectUnionNonPredictable.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export type ObjectUnionNonPredictable = ObjectUnionNonPredictable.IUnion[];
export type ObjectUnionNonPredictable =
ObjectUnionNonPredictable.IWrapper<ObjectUnionNonPredictable.IUnion>[];
export namespace ObjectUnionNonPredictable {
export type IUnion =
| IWrapper<boolean>
Expand All @@ -13,10 +14,10 @@ export namespace ObjectUnionNonPredictable {

export function generate(): ObjectUnionNonPredictable {
return [
{ value: { value: false } },
{ value: { value: true } },
{ value: { value: 2 } },
{ value: { value: "three" } },
{ value: { value: { value: { value: false } } } },
{ value: { value: { value: { value: true } } } },
{ value: { value: { value: { value: 2 } } } },
{ value: { value: { value: { value: "three" } } } },
];
}
}

0 comments on commit ff2e95c

Please sign in to comment.