From 002bb6f04b5fb7fecf8decf1c331d07b222b27e5 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Tue, 27 Oct 2015 15:23:38 -0700 Subject: [PATCH] Added tests. --- .../matchable/equalityWithUnionTypes01.ts | 20 +++++++++++++++ .../matchable/switchCaseWithUnionTypes01.ts | 25 +++++++++++++++++++ .../typeAssertionsWithUnionTypes01.ts | 16 ++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts create mode 100644 tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts create mode 100644 tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts diff --git a/tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts b/tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts new file mode 100644 index 00000000000..d83277b975a --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/matchable/equalityWithUnionTypes01.ts @@ -0,0 +1,20 @@ +interface I1 { + p1: number +} + +interface I2 extends I1 { + p2: number; +} + +var x = { p1: 10, p2: 20 }; +var y: number | I2 = x; +var z: I1 = x; + +if (y === z || z === y) { +} +else if (y !== z || z !== y) { +} +else if (y == z || z == y) { +} +else if (y != z || z != y) { +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts b/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts new file mode 100644 index 00000000000..bdbfaf2df47 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/matchable/switchCaseWithUnionTypes01.ts @@ -0,0 +1,25 @@ + +var strOrNum: string | number; +var numOrBool: number | boolean; +var str: string; +var num: number; +var bool: boolean; + +switch (strOrNum) { + // Identical + case strOrNum: + break; + + // Constituents + case str: + case num: + break; + + // Overlap in constituents + case numOrBool: + break; + + // No relation + case bool: + break; +} \ No newline at end of file diff --git a/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts b/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts new file mode 100644 index 00000000000..3010c5f159a --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/matchable/typeAssertionsWithUnionTypes01.ts @@ -0,0 +1,16 @@ +interface I1 { + p1: number +} + +interface I2 extends I1 { + p2: number; +} + +var x = { p1: 10, p2: 20 }; +var y: number | I2 = x; +var z: I1 = x; + +var a = z; +var b = z; +var c = z; +var d = y;