-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from samchon/v2.0
Fix #32
- Loading branch information
Showing
8 changed files
with
193 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// import TSON from "../../src"; | ||
|
||
// export function test_stringify_array_generic_alias(): void | ||
// { | ||
// const alias: Alias<number> = [1, 2, 3]; | ||
// const json: string = TSON.stringify(alias); | ||
// const expected: string = JSON.stringify(alias); | ||
|
||
// if (json !== expected) | ||
// throw new Error("Bug on TSON.stringify(): failed to understand the generic array alias type."); | ||
// } | ||
|
||
// type Alias<T> = T[]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import TSON from "../../src"; | ||
|
||
export function test_stringify_object_generic_alias(): void | ||
{ | ||
const something: ISomething<string> = { | ||
value: "value", | ||
child: { | ||
child_value: "child_value", | ||
child_next: "child_next" | ||
}, | ||
elements: ["one", "two", "three"], | ||
}; | ||
const json: string = TSON.stringify<ISomething<string>>(something); | ||
const expected: string = JSON.stringify(something); | ||
|
||
if (json !== expected) | ||
throw new Error("Bug on TSON.stringify(): failed to understand the generic object type."); | ||
} | ||
|
||
interface ISomething<T> | ||
{ | ||
value: T; | ||
child: IChild<T>; | ||
elements: T[]; | ||
} | ||
interface IChild<U> | ||
{ | ||
child_value: U; | ||
child_next: U; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import TSON from "../../src"; | ||
import { Primitive } from "../internal/Primitive"; | ||
|
||
export function test_stringify_object_generic_alias(): void | ||
{ | ||
const alias: Alias = { | ||
value: "Something" | ||
}; | ||
const stringify: (input: Alias) => string = TSON.createStringifier<Alias>(); | ||
|
||
const json: string = stringify(alias); | ||
const parsed: Alias = JSON.parse(json); | ||
|
||
if (Primitive.equal_to(alias, parsed) === false) | ||
throw new Error("Bug on TSON.createStringifier(): failed to understand the object alias type."); | ||
} | ||
|
||
interface ISomething<T> | ||
{ | ||
value: T; | ||
} | ||
type Alias = ISomething<string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { v4 } from "uuid"; | ||
|
||
import TSON from "../../src"; | ||
|
||
import { RandomGenerator } from "../internal/RandomGenerator"; | ||
|
||
export function test_stringify_object_generic_union(): void | ||
{ | ||
const question: ISaleQuestion = { | ||
id: v4(), | ||
writer: "robot", | ||
contents: RandomGenerator.array(() => ({ | ||
id: v4(), | ||
title: RandomGenerator.string(), | ||
body: RandomGenerator.string(), | ||
files: RandomGenerator.array(() => ({ | ||
id: v4(), | ||
name: RandomGenerator.string(), | ||
extension: RandomGenerator.string(), | ||
url: RandomGenerator.string(), | ||
})), | ||
created_at: new Date().toString() | ||
})), | ||
answer: null, | ||
created_at: new Date().toString(), | ||
hit: 0, | ||
}; | ||
|
||
const json: string = TSON.stringify<ISaleEntireArticle>(question); | ||
const expected: string = JSON.stringify(question); | ||
|
||
if (json !== expected) | ||
throw new Error("Bug on TSON.stringify(): failed to understand the generic union object type."); | ||
} | ||
|
||
type ISaleEntireArticle = ISaleQuestion | ISaleReview; | ||
type ISaleQuestion = ISaleInquiry<ISaleQuestion.IContent>; | ||
namespace ISaleQuestion | ||
{ | ||
export type IContent = ISaleInquiry.IContent; | ||
} | ||
type ISaleReview = ISaleInquiry<ISaleReview.IContent>; | ||
namespace ISaleReview | ||
{ | ||
export interface IContent extends ISaleInquiry.IContent | ||
{ | ||
score: number; | ||
} | ||
} | ||
|
||
interface ISaleInquiry<Content extends ISaleInquiry.IContent> | ||
extends ISaleArticle<Content> | ||
{ | ||
writer: string; | ||
answer: ISaleAnswer | null; | ||
} | ||
namespace ISaleInquiry | ||
{ | ||
export type IContent = ISaleArticle.IContent; | ||
} | ||
type ISaleAnswer = ISaleArticle<ISaleAnswer.IContent> | ||
namespace ISaleAnswer | ||
{ | ||
export type IContent = ISaleArticle.IContent; | ||
} | ||
interface ISaleArticle<Content extends ISaleArticle.IContent> | ||
{ | ||
id: string; | ||
hit: number; | ||
contents: Content[]; | ||
created_at: string; | ||
} | ||
namespace ISaleArticle | ||
{ | ||
export interface IContent extends IUpdate | ||
{ | ||
id: string; | ||
created_at: string; | ||
} | ||
export interface IUpdate | ||
{ | ||
title: string; | ||
body: string; | ||
files: Omit<IAttachmentFile, "id">[]; | ||
} | ||
} | ||
|
||
interface IAttachmentFile | ||
{ | ||
id: string; | ||
name: string; | ||
extension: string | null; | ||
url: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters