From d8ec85775ae80d0f497ab281ad99af8930410bc9 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Thu, 29 Sep 2016 15:11:51 -0700 Subject: [PATCH] Add tests --- tests/cases/compiler/controlFlowLetVar.ts | 119 +++++++++++++++++ .../compiler/controlFlowNoImplicitAny.ts | 120 ++++++++++++++++++ 2 files changed, 239 insertions(+) create mode 100644 tests/cases/compiler/controlFlowLetVar.ts create mode 100644 tests/cases/compiler/controlFlowNoImplicitAny.ts diff --git a/tests/cases/compiler/controlFlowLetVar.ts b/tests/cases/compiler/controlFlowLetVar.ts new file mode 100644 index 00000000000..6ef62cca21a --- /dev/null +++ b/tests/cases/compiler/controlFlowLetVar.ts @@ -0,0 +1,119 @@ +// @strictNullChecks: true + +declare let cond: boolean; + +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + function f() { + const z = x; + } +} + +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + const f = () => { + const z = x; + }; +} \ No newline at end of file diff --git a/tests/cases/compiler/controlFlowNoImplicitAny.ts b/tests/cases/compiler/controlFlowNoImplicitAny.ts new file mode 100644 index 00000000000..3c909ba61b6 --- /dev/null +++ b/tests/cases/compiler/controlFlowNoImplicitAny.ts @@ -0,0 +1,120 @@ +// @strictNullChecks: true +// @noImplicitAny: true + +declare let cond: boolean; + +function f1() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f2() { + let x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f3() { + let x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f4() { + let x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f5() { + var x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f6() { + var x = undefined; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f7() { + var x = null; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f8() { + var x: any; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; +} + +function f9() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + function f() { + const z = x; + } +} + +function f10() { + let x; + if (cond) { + x = 1; + } + if (cond) { + x = "hello"; + } + const y = x; + const f = () => { + const z = x; + }; +} \ No newline at end of file