From 82c26cd1efcd4597f40760dfa817c98b89bf0169 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 6 Jul 2016 21:00:47 -0700 Subject: [PATCH] Adding selected tests from #6196 --- ...teralsAssertionsInEqualityComparisons01.ts | 3 ++ ...teralsAssertionsInEqualityComparisons02.ts | 6 ++++ .../stringLiteralsWithEqualityChecks01.ts | 22 ++++++++++++++ .../stringLiteralsWithEqualityChecks02.ts | 22 ++++++++++++++ .../stringLiteralsWithEqualityChecks03.ts | 29 +++++++++++++++++++ .../stringLiteralsWithEqualityChecks04.ts | 29 +++++++++++++++++++ .../stringLiteralsWithSwitchStatements01.ts | 12 ++++++++ .../stringLiteralsWithSwitchStatements02.ts | 14 +++++++++ .../stringLiteralsWithSwitchStatements03.ts | 26 +++++++++++++++++ .../stringLiteralsWithSwitchStatements04.ts | 21 ++++++++++++++ .../stringLiteralsWithTypeAssertions01.ts | 8 +++++ 11 files changed, 192 insertions(+) create mode 100644 tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts create mode 100644 tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts diff --git a/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts b/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts new file mode 100644 index 00000000000..b161660488c --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons01.ts @@ -0,0 +1,3 @@ +var a = "foo" === "bar" as string; +var b = "foo" !== ("bar" as string); +var c = "foo" == ("bar"); \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts b/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts new file mode 100644 index 00000000000..8ab4469055f --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsAssertionsInEqualityComparisons02.ts @@ -0,0 +1,6 @@ +type EnhancedString = string & { enhancements: any }; + +var a = "foo" === "bar" as "baz"; +var b = "foo" !== ("bar" as "foo"); +var c = "foo" == ("bar"); +var d = "foo" === ("bar" as EnhancedString); \ No newline at end of file diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts new file mode 100644 index 00000000000..3179be186ea --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks01.ts @@ -0,0 +1,22 @@ +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x === y; +b = "foo" === y +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; + +b = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; + diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts new file mode 100644 index 00000000000..25a687a8941 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks02.ts @@ -0,0 +1,22 @@ +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; + diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts new file mode 100644 index 00000000000..b4fb0648187 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks03.ts @@ -0,0 +1,29 @@ +interface Runnable { + isRunning: boolean; +} + +interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; +} + +let x: string; +let y: "foo" | Refrigerator; + +let b: boolean; +b = x === y; +b = "foo" === y +b = y === "foo"; +b = "foo" === "bar"; +b = "bar" === x; +b = x === "bar"; +b = y === "bar"; +b = "bar" === y; + +b = x !== y; +b = "foo" !== y +b = y !== "foo"; +b = "foo" !== "bar"; +b = "bar" !== x; +b = x !== "bar"; +b = y !== "bar"; +b = "bar" !== y; diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts new file mode 100644 index 00000000000..01e1c0896fb --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithEqualityChecks04.ts @@ -0,0 +1,29 @@ +interface Runnable { + isRunning: boolean; +} + +interface Refrigerator extends Runnable { + makesFoodGoBrrr: boolean; +} + +let x: string; +let y: "foo" | Refrigerator; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; +b = "bar" == x; +b = x == "bar"; +b = y == "bar"; +b = "bar" == y; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; +b = "bar" != x; +b = x != "bar"; +b = y != "bar"; +b = "bar" != y; diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts new file mode 100644 index 00000000000..b1c1aaa64ca --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements01.ts @@ -0,0 +1,12 @@ +let x: "foo"; +let y: "foo" | "bar"; + +switch (x) { + case "foo": + break; + case "bar": + break; + case y: + y; + break; +} diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts new file mode 100644 index 00000000000..d396eb16bed --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements02.ts @@ -0,0 +1,14 @@ +let x: "foo"; +let y: "foo" | "bar"; + +let b: boolean; +b = x == y; +b = "foo" == y +b = y == "foo"; +b = "foo" == "bar"; + +b = x != y; +b = "foo" != y +b = y != "foo"; +b = "foo" != "bar"; + diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts new file mode 100644 index 00000000000..289ffd11060 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements03.ts @@ -0,0 +1,26 @@ +let x: "foo"; +let y: "foo" | "bar"; +let z: "bar"; + +declare function randBool(): boolean; + +switch (x) { + case randBool() ? "foo" : "baz": + break; + case (randBool() ? ("bar") : "baz" ? "bar" : "baz"): + break; + case (("bar")): + break; + case (x, y, ("baz")): + x; + y; + break; + case (("foo" || ("bar"))): + break; + case (("bar" || ("baz"))): + break; + case z || "baz": + case "baz" || z: + z; + break; +} diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts new file mode 100644 index 00000000000..ee119cd1db5 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithSwitchStatements04.ts @@ -0,0 +1,21 @@ +let x: "foo"; +let y: "foo" | "bar"; + +declare function randBool(): boolean; + +switch (y) { + case "foo", x: + break; + case x, "foo": + break; + case x, "baz": + break; + case "baz", x: + break; + case "baz" && "bar": + break; + case "baz" && ("foo" || "bar"): + break; + case "bar" && ("baz" || "bar"): + break; +} diff --git a/tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts b/tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts new file mode 100644 index 00000000000..2e354270412 --- /dev/null +++ b/tests/cases/conformance/types/literal/stringLiteralsWithTypeAssertions01.ts @@ -0,0 +1,8 @@ +let fooOrBar: "foo" | "bar"; + +let a = "foo" as "bar"; +let b = "bar" as "foo"; +let c = fooOrBar as "foo"; +let d = fooOrBar as "bar"; +let e = fooOrBar as "baz"; +let f = "baz" as typeof fooOrBar; \ No newline at end of file