Skip to content

Commit

Permalink
Merge pull request #235 from samchon/v3.3
Browse files Browse the repository at this point in the history
Fix #234 - invalid `TypeGuardError.path` bug
  • Loading branch information
samchon authored Oct 10, 2022
2 parents f847952 + 4d0f06c commit 6d5ad22
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "typescript-json",
"version": "3.3.8",
"version": "3.3.9",
"description": "Runtime type checkers and 5x faster JSON.stringify() function",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
Expand Down
12 changes: 8 additions & 4 deletions src/programmers/FeatureProgrammer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ export namespace FeatureProgrammer {
tracable: explore.tracable,
source: explore.source,
from: "array",
postfix: explore.postfix.length
? explore.postfix.slice(0, -1) + INDEX_SYMBOL(rand)
: '"' + INDEX_SYMBOL(rand),
postfix: INDEX_SYMBOL(explore.postfix)(rand),
},
tags,
),
Expand Down Expand Up @@ -364,7 +362,13 @@ export namespace FeatureProgrammer {
};
}

const INDEX_SYMBOL = (rand: string) => `[" + index${rand} + "]"`;
const INDEX_SYMBOL = (prev: string) => (rand: string) => {
const tail: string = `"[" + index${rand} + "]"`;
if (prev === "") return tail;
else if (prev[prev.length - 1] === `"`)
return prev.substring(0, prev.length - 1) + tail.substring(1);
return prev + ` + ${tail}`;
};
const PARAMETERS = (initialize: null | boolean) => {
const tail =
initialize === null
Expand Down
37 changes: 37 additions & 0 deletions test/features/application/test_application_dynamic_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import TSON from "../../../src";
import { DynamicArray } from "../../structures/DynamicArray";
import { _test_application } from "./_test_application";

export const test_application_dynamic_array = _test_application(
"dynamic array",
TSON.application<[DynamicArray]>(),
{
schemas: [
{
$ref: "#/components/schemas/DynamicArray",
},
],
components: {
schemas: {
DynamicArray: {
type: "object",
properties: {},
patternProperties: {
"(.*)": {
type: "array",
items: {
type: "string",
nullable: false,
},
nullable: false,
},
},
nullable: false,
jsDocTags: [],
},
},
},
purpose: "swagger",
prefix: "#/components/schemas",
},
);
15 changes: 15 additions & 0 deletions test/features/assert/test_assert_dynamic_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import TSON from "../../../src";
import { DynamicArray } from "../../structures/DynamicArray";
import { _test_assert } from "./_test_assert";

export const test_assert_dynamic_array = _test_assert(
"dynamic array",
DynamicArray.generate,
(input) => TSON.assertType(input),
[
(input) => {
input["something"] = [0] as any;
return `$input.something[0]`;
},
],
);
10 changes: 10 additions & 0 deletions test/features/assert_equals/test_assert_equals_dynamic_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import TSON from "../../../src";
import { DynamicArray } from "../../structures/DynamicArray";
import { _test_assert_equals } from "./_test_assert_equals";

export const test_assert_equals_dynamic_array = _test_assert_equals(
"dynamic array",
DynamicArray.generate,
(input) => TSON.assertEquals(input),
false,
);
10 changes: 10 additions & 0 deletions test/features/equals/test_equals_dynamic_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import TSON from "../../../src";
import { DynamicArray } from "../../structures/DynamicArray";
import { _test_equals } from "./_test_equals";

export const test_equals_dynamic_array = _test_equals(
"dynamic array",
DynamicArray.generate,
(input) => TSON.equals(input),
0,
);
10 changes: 10 additions & 0 deletions test/features/is/test_is_dynamic_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import TSON from "../../../src";
import { DynamicArray } from "../../structures/DynamicArray";
import { _test_is } from "./_test_is";

export const test_is_dynamic_array = _test_is(
"dynamic array",
DynamicArray.generate,
(input) => TSON.is(input),
[(input) => (input["something"] = [0] as any)],
);
9 changes: 9 additions & 0 deletions test/features/stringify/test_stringify_dynamic_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import TSON from "../../../src";
import { DynamicArray } from "../../structures/DynamicArray";
import { _test_stringify } from "./_test_stringify";

export const test_stringify_dynamic_array = _test_stringify(
"dynamic array",
DynamicArray.generate(),
(input) => TSON.stringify(input),
);
16 changes: 16 additions & 0 deletions test/features/validate/test_validate_dynamic_array.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import TSON from "../../../src";
import { DynamicArray } from "../../structures/DynamicArray";
import { _test_validate } from "./_test_validate";

export const test_validate_dynamic_array = _test_validate(
"dynamic array",
DynamicArray.generate,
(input) => TSON.validate(input),
[
(input) => {
input["something"] = [0] as any;
input["another"] = [false] as any;
return [`$input.something[0]`, `$input.another[0]`];
},
],
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import TSON from "../../../src";
import { DynamicArray } from "../../structures/DynamicArray";
import { _test_validate_equals } from "./_test_validate_equals";

export const test_validate_equals_dynamic_array = _test_validate_equals(
"dynamic array",
DynamicArray.generate,
(input) => TSON.validateEquals(input),
false,
);
15 changes: 15 additions & 0 deletions test/structures/DynamicArray.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { RandomGenerator } from "../internal/RandomGenerator";

export interface DynamicArray {
[key: string]: string[];
}
export namespace DynamicArray {
export function generate(): DynamicArray {
const output: DynamicArray = {};
for (let i: number = 0; i < 10; ++i) {
const key: string = RandomGenerator.string();
output[key] = RandomGenerator.array(RandomGenerator.string);
}
return output;
}
}
2 changes: 1 addition & 1 deletion tsconfig.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
// "newLine": "crlf", /* Set the newline character for emitting files. */
"newLine": "lf", /* Set the newline character for emitting files. */
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
Expand Down

0 comments on commit 6d5ad22

Please sign in to comment.