-
-
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 #238 from samchon/features/enum
Close #237 - support enumeration typed property
- Loading branch information
Showing
17 changed files
with
243 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicConstant } from "../../structures/DynamicConstant"; | ||
import { _test_assert } from "./_test_assert"; | ||
|
||
export const test_assert_dynamic_constant = _test_assert( | ||
"dynamic constant", | ||
DynamicConstant.generate, | ||
(input) => TSON.assertType(input), | ||
[ | ||
(input) => { | ||
input["a"] = "zero" as any; | ||
return "$input.a"; | ||
}, | ||
(input) => { | ||
input["b"] = null!; | ||
return "$input.b"; | ||
}, | ||
], | ||
); |
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,19 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicEnumeration } from "../../structures/DynamicEnumeration"; | ||
import { _test_assert } from "./_test_assert"; | ||
|
||
export const test_assert_dynamic_enumeration = _test_assert( | ||
"dynamic enumeration", | ||
DynamicEnumeration.generate, | ||
(input) => TSON.assertType(input), | ||
[ | ||
(input) => { | ||
input["fr"] = null!; | ||
return "$input.fr"; | ||
}, | ||
(input) => { | ||
input["ar"] = 0 as any; | ||
return "$input.ar"; | ||
}, | ||
], | ||
); |
9 changes: 9 additions & 0 deletions
9
test/features/assert_equals/test_assert_equals_dynamic_constant.ts
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,9 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicConstant } from "../../structures/DynamicConstant"; | ||
import { _test_assert_equals } from "./_test_assert_equals"; | ||
|
||
export const test_assert_equals_dynamic_constant = _test_assert_equals( | ||
"dynamic constant", | ||
DynamicConstant.generate, | ||
(input) => TSON.assertEquals(input), | ||
); |
9 changes: 9 additions & 0 deletions
9
test/features/assert_equals/test_assert_equals_dynamic_enumeration.ts
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,9 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicEnumeration } from "../../structures/DynamicEnumeration"; | ||
import { _test_assert_equals } from "./_test_assert_equals"; | ||
|
||
export const test_assert_equals_dynamic_enumeration = _test_assert_equals( | ||
"dynamic enumeration", | ||
DynamicEnumeration.generate, | ||
(input) => TSON.assertEquals(input), | ||
); |
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,9 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicConstant } from "../../structures/DynamicConstant"; | ||
import { _test_equals } from "./_test_equals"; | ||
|
||
export const test_equals_dynamic_constant = _test_equals( | ||
"dynamic constant", | ||
DynamicConstant.generate, | ||
(input) => TSON.equals(input), | ||
); |
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,9 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicEnumeration } from "../../structures/DynamicEnumeration"; | ||
import { _test_equals } from "./_test_equals"; | ||
|
||
export const test_equals_dynamic_enumeration = _test_equals( | ||
"dynamic enumeration", | ||
DynamicEnumeration.generate, | ||
(input) => TSON.equals(input), | ||
); |
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,10 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicConstant } from "../../structures/DynamicConstant"; | ||
import { _test_is } from "./_test_is"; | ||
|
||
export const test_is_dynamic_constant = _test_is( | ||
"dynamic constant", | ||
DynamicConstant.generate, | ||
(input) => TSON.is(input), | ||
[(input) => (input["a"] = "zero" as any), (input) => (input["b"] = null!)], | ||
); |
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,10 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicEnumeration } from "../../structures/DynamicEnumeration"; | ||
import { _test_is } from "./_test_is"; | ||
|
||
export const test_is_dynamic_enumeration = _test_is( | ||
"dynamic enumeration", | ||
DynamicEnumeration.generate, | ||
(input) => TSON.is(input), | ||
[(input) => (input["fr"] = null!), (input) => (input["ar"] = 0 as any)], | ||
); |
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,19 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicConstant } from "../../structures/DynamicConstant"; | ||
import { _test_validate } from "./_test_validate"; | ||
|
||
export const test_validate_dynamic_constant = _test_validate( | ||
"dynamic constant", | ||
DynamicConstant.generate, | ||
(input) => TSON.validate(input), | ||
[ | ||
(input) => { | ||
input["a"] = "zero" as any; | ||
return ["$input.a"]; | ||
}, | ||
(input) => { | ||
input["b"] = null!; | ||
return ["$input.b"]; | ||
}, | ||
], | ||
); |
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,19 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicEnumeration } from "../../structures/DynamicEnumeration"; | ||
import { _test_validate } from "./_test_validate"; | ||
|
||
export const test_validate_dynamic_enumeration = _test_validate( | ||
"dynamic enumeration", | ||
DynamicEnumeration.generate, | ||
(input) => TSON.validate(input), | ||
[ | ||
(input) => { | ||
input["fr"] = null!; | ||
return ["$input.fr"]; | ||
}, | ||
(input) => { | ||
input["ar"] = 0 as any; | ||
return ["$input.ar"]; | ||
}, | ||
], | ||
); |
9 changes: 9 additions & 0 deletions
9
test/features/validate_equals/test_validate_equals_dynamic_constant.ts
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,9 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicConstant } from "../../structures/DynamicConstant"; | ||
import { _test_validate_equals } from "./_test_validate_equals"; | ||
|
||
export const test_validate_equals_dynamic_constant = _test_validate_equals( | ||
"dynamic constant", | ||
DynamicConstant.generate, | ||
(input) => TSON.validateEquals(input), | ||
); |
9 changes: 9 additions & 0 deletions
9
test/features/validate_equals/test_validate_equals_dynamic_enumeration.ts
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,9 @@ | ||
import TSON from "../../../src"; | ||
import { DynamicEnumeration } from "../../structures/DynamicEnumeration"; | ||
import { _test_validate_equals } from "./_test_validate_equals"; | ||
|
||
export const test_validate_equals_dynamic_enumeration = _test_validate_equals( | ||
"dynamic enumeration", | ||
DynamicEnumeration.generate, | ||
(input) => TSON.validateEquals(input), | ||
); |
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,28 @@ | ||
import { equals, is } from "../../src"; | ||
|
||
const enum LanguageCode { | ||
Arabic = "ar", | ||
ChineseSimp = "zh-Hans", | ||
ChineseTrad = "zh-Hant", | ||
English = "en", | ||
French = "fr", | ||
German = "de", | ||
Japanese = "ja", | ||
Korean = "ko", // <-- this line | ||
Portuguese = "pt", | ||
Russian = "ru", | ||
} | ||
|
||
type DynamicEnumeration = { | ||
[P in LanguageCode]?: string; | ||
}; | ||
|
||
const data: DynamicEnumeration = { | ||
en: "Line 1", | ||
ko: "1호선", // <-- this line | ||
"zh-Hans": "1号线", | ||
"zh-Hant": "1號線", | ||
}; | ||
(data as any).kr = "2호선"; | ||
console.log("is", is(data)); | ||
console.log("equals", equals(data)); |
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 @@ | ||
export type DynamicConstant = { | ||
[P in "a" | "b" | "c" | "d"]: number; | ||
}; | ||
export namespace DynamicConstant { | ||
export function generate(): DynamicConstant { | ||
return { | ||
a: 1, | ||
b: 2, | ||
c: 3, | ||
d: 4, | ||
}; | ||
} | ||
} |
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,26 @@ | ||
export type DynamicEnumeration = { | ||
[P in DynamicEnumeration.LanguageCode]?: string; | ||
}; | ||
export namespace DynamicEnumeration { | ||
export enum LanguageCode { | ||
Arabic = "ar", | ||
ChineseSimp = "zh-Hans", | ||
ChineseTrad = "zh-Hant", | ||
English = "en", | ||
French = "fr", | ||
German = "de", | ||
Japanese = "ja", | ||
Korean = "ko", // <-- this line | ||
Portuguese = "pt", | ||
Russian = "ru", | ||
} | ||
|
||
export function generate(): DynamicEnumeration { | ||
return { | ||
en: "Line 1", | ||
ko: "1호선 ", | ||
"zh-Hans": "1号线", | ||
"zh-Hant": "1號線", | ||
}; | ||
} | ||
} |