From 2942de1d8e38b479adbf067b4dcb43afbe81bded Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Mon, 12 Sep 2016 16:00:24 -0700 Subject: [PATCH] Add test --- .../literalTypesAndTypeAssertions.js | 28 +++++++++ .../literalTypesAndTypeAssertions.symbols | 37 +++++++++++ .../literalTypesAndTypeAssertions.types | 62 +++++++++++++++++++ .../literal/literalTypesAndTypeAssertions.ts | 13 ++++ 4 files changed, 140 insertions(+) create mode 100644 tests/baselines/reference/literalTypesAndTypeAssertions.js create mode 100644 tests/baselines/reference/literalTypesAndTypeAssertions.symbols create mode 100644 tests/baselines/reference/literalTypesAndTypeAssertions.types create mode 100644 tests/cases/conformance/types/literal/literalTypesAndTypeAssertions.ts diff --git a/tests/baselines/reference/literalTypesAndTypeAssertions.js b/tests/baselines/reference/literalTypesAndTypeAssertions.js new file mode 100644 index 0000000000..ab6a82852a --- /dev/null +++ b/tests/baselines/reference/literalTypesAndTypeAssertions.js @@ -0,0 +1,28 @@ +//// [literalTypesAndTypeAssertions.ts] +const obj = { + a: "foo" as "foo", + b: <"foo">"foo", + c: "foo" +}; + +let x1 = 1 as (0 | 1); +let x2 = 1; + +let { a = "foo" } = { a: "foo" }; +let { b = "foo" as "foo" } = { b: "bar" }; +let { c = "foo" } = { c: "bar" as "bar" }; +let { d = "foo" as "foo" } = { d: "bar" as "bar" }; + + +//// [literalTypesAndTypeAssertions.js] +var obj = { + a: "foo", + b: "foo", + c: "foo" +}; +var x1 = 1; +var x2 = 1; +var _a = { a: "foo" }.a, a = _a === void 0 ? "foo" : _a; +var _b = { b: "bar" }.b, b = _b === void 0 ? "foo" : _b; +var _c = { c: "bar" }.c, c = _c === void 0 ? "foo" : _c; +var _d = { d: "bar" }.d, d = _d === void 0 ? "foo" : _d; diff --git a/tests/baselines/reference/literalTypesAndTypeAssertions.symbols b/tests/baselines/reference/literalTypesAndTypeAssertions.symbols new file mode 100644 index 0000000000..6a8f879060 --- /dev/null +++ b/tests/baselines/reference/literalTypesAndTypeAssertions.symbols @@ -0,0 +1,37 @@ +=== tests/cases/conformance/types/literal/literalTypesAndTypeAssertions.ts === +const obj = { +>obj : Symbol(obj, Decl(literalTypesAndTypeAssertions.ts, 0, 5)) + + a: "foo" as "foo", +>a : Symbol(a, Decl(literalTypesAndTypeAssertions.ts, 0, 13)) + + b: <"foo">"foo", +>b : Symbol(b, Decl(literalTypesAndTypeAssertions.ts, 1, 22)) + + c: "foo" +>c : Symbol(c, Decl(literalTypesAndTypeAssertions.ts, 2, 20)) + +}; + +let x1 = 1 as (0 | 1); +>x1 : Symbol(x1, Decl(literalTypesAndTypeAssertions.ts, 6, 3)) + +let x2 = 1; +>x2 : Symbol(x2, Decl(literalTypesAndTypeAssertions.ts, 7, 3)) + +let { a = "foo" } = { a: "foo" }; +>a : Symbol(a, Decl(literalTypesAndTypeAssertions.ts, 9, 5)) +>a : Symbol(a, Decl(literalTypesAndTypeAssertions.ts, 9, 21)) + +let { b = "foo" as "foo" } = { b: "bar" }; +>b : Symbol(b, Decl(literalTypesAndTypeAssertions.ts, 10, 5)) +>b : Symbol(b, Decl(literalTypesAndTypeAssertions.ts, 10, 30)) + +let { c = "foo" } = { c: "bar" as "bar" }; +>c : Symbol(c, Decl(literalTypesAndTypeAssertions.ts, 11, 5)) +>c : Symbol(c, Decl(literalTypesAndTypeAssertions.ts, 11, 21)) + +let { d = "foo" as "foo" } = { d: "bar" as "bar" }; +>d : Symbol(d, Decl(literalTypesAndTypeAssertions.ts, 12, 5)) +>d : Symbol(d, Decl(literalTypesAndTypeAssertions.ts, 12, 30)) + diff --git a/tests/baselines/reference/literalTypesAndTypeAssertions.types b/tests/baselines/reference/literalTypesAndTypeAssertions.types new file mode 100644 index 0000000000..4c38f74fd7 --- /dev/null +++ b/tests/baselines/reference/literalTypesAndTypeAssertions.types @@ -0,0 +1,62 @@ +=== tests/cases/conformance/types/literal/literalTypesAndTypeAssertions.ts === +const obj = { +>obj : { a: "foo"; b: "foo"; c: string; } +>{ a: "foo" as "foo", b: <"foo">"foo", c: "foo"} : { a: "foo"; b: "foo"; c: string; } + + a: "foo" as "foo", +>a : "foo" +>"foo" as "foo" : "foo" +>"foo" : "foo" + + b: <"foo">"foo", +>b : "foo" +><"foo">"foo" : "foo" +>"foo" : "foo" + + c: "foo" +>c : string +>"foo" : "foo" + +}; + +let x1 = 1 as (0 | 1); +>x1 : 0 | 1 +>1 as (0 | 1) : 0 | 1 +>1 : 1 + +let x2 = 1; +>x2 : number +>1 : 1 + +let { a = "foo" } = { a: "foo" }; +>a : string +>"foo" : "foo" +>{ a: "foo" } : { a?: string; } +>a : string +>"foo" : "foo" + +let { b = "foo" as "foo" } = { b: "bar" }; +>b : "foo" | "bar" +>"foo" as "foo" : "foo" +>"foo" : "foo" +>{ b: "bar" } : { b?: "bar"; } +>b : string +>"bar" : "bar" + +let { c = "foo" } = { c: "bar" as "bar" }; +>c : "foo" | "bar" +>"foo" : "foo" +>{ c: "bar" as "bar" } : { c?: "bar"; } +>c : "bar" +>"bar" as "bar" : "bar" +>"bar" : "bar" + +let { d = "foo" as "foo" } = { d: "bar" as "bar" }; +>d : "foo" | "bar" +>"foo" as "foo" : "foo" +>"foo" : "foo" +>{ d: "bar" as "bar" } : { d?: "bar"; } +>d : "bar" +>"bar" as "bar" : "bar" +>"bar" : "bar" + diff --git a/tests/cases/conformance/types/literal/literalTypesAndTypeAssertions.ts b/tests/cases/conformance/types/literal/literalTypesAndTypeAssertions.ts new file mode 100644 index 0000000000..5c11dd9103 --- /dev/null +++ b/tests/cases/conformance/types/literal/literalTypesAndTypeAssertions.ts @@ -0,0 +1,13 @@ +const obj = { + a: "foo" as "foo", + b: <"foo">"foo", + c: "foo" +}; + +let x1 = 1 as (0 | 1); +let x2 = 1; + +let { a = "foo" } = { a: "foo" }; +let { b = "foo" as "foo" } = { b: "bar" }; +let { c = "foo" } = { c: "bar" as "bar" }; +let { d = "foo" as "foo" } = { d: "bar" as "bar" };