Adding test

This commit is contained in:
Anders Hejlsberg 2016-04-21 13:03:08 -07:00
parent 8a0bc3b992
commit d2b89be4bc
4 changed files with 507 additions and 0 deletions

View file

@ -0,0 +1,134 @@
//// [controlFlowTruthiness.ts]
declare function foo(): string | undefined;
function f1() {
let x = foo();
if (x) {
x; // string
}
else {
x; // string | undefined
}
}
function f2() {
let x: string | undefined;
x = foo();
if (x) {
x; // string
}
else {
x; // string | undefined
}
}
function f3() {
let x: string | undefined;
if (x = foo()) {
x; // string
}
else {
x; // string | undefined
}
}
function f4() {
let x: string | undefined;
if (!(x = foo())) {
x; // string | undefined
}
else {
x; // string
}
}
function f5() {
let x: string | undefined;
let y: string | undefined;
if (x = y = foo()) {
x; // string
y; // string | undefined
}
else {
x; // string | undefined
y; // string | undefined
}
}
function f6() {
let x: string | undefined;
let y: string | undefined;
if (x = foo(), y = foo()) {
x; // string | undefined
y; // string
}
else {
x; // string | undefined
y; // string | undefined
}
}
//// [controlFlowTruthiness.js]
function f1() {
var x = foo();
if (x) {
x; // string
}
else {
x; // string | undefined
}
}
function f2() {
var x;
x = foo();
if (x) {
x; // string
}
else {
x; // string | undefined
}
}
function f3() {
var x;
if (x = foo()) {
x; // string
}
else {
x; // string | undefined
}
}
function f4() {
var x;
if (!(x = foo())) {
x; // string | undefined
}
else {
x; // string
}
}
function f5() {
var x;
var y;
if (x = y = foo()) {
x; // string
y; // string | undefined
}
else {
x; // string | undefined
y; // string | undefined
}
}
function f6() {
var x;
var y;
if (x = foo(), y = foo()) {
x; // string | undefined
y; // string
}
else {
x; // string | undefined
y; // string | undefined
}
}

View file

@ -0,0 +1,143 @@
=== tests/cases/conformance/controlFlow/controlFlowTruthiness.ts ===
declare function foo(): string | undefined;
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
function f1() {
>f1 : Symbol(f1, Decl(controlFlowTruthiness.ts, 1, 43))
let x = foo();
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 4, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
if (x) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 4, 7))
x; // string
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 4, 7))
}
else {
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 4, 7))
}
}
function f2() {
>f2 : Symbol(f2, Decl(controlFlowTruthiness.ts, 11, 1))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 14, 7))
x = foo();
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 14, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
if (x) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 14, 7))
x; // string
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 14, 7))
}
else {
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 14, 7))
}
}
function f3() {
>f3 : Symbol(f3, Decl(controlFlowTruthiness.ts, 22, 1))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 25, 7))
if (x = foo()) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 25, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
x; // string
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 25, 7))
}
else {
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 25, 7))
}
}
function f4() {
>f4 : Symbol(f4, Decl(controlFlowTruthiness.ts, 32, 1))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 35, 7))
if (!(x = foo())) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 35, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 35, 7))
}
else {
x; // string
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 35, 7))
}
}
function f5() {
>f5 : Symbol(f5, Decl(controlFlowTruthiness.ts, 42, 1))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 45, 7))
let y: string | undefined;
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 46, 7))
if (x = y = foo()) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 45, 7))
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 46, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
x; // string
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 45, 7))
y; // string | undefined
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 46, 7))
}
else {
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 45, 7))
y; // string | undefined
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 46, 7))
}
}
function f6() {
>f6 : Symbol(f6, Decl(controlFlowTruthiness.ts, 55, 1))
let x: string | undefined;
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 58, 7))
let y: string | undefined;
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 59, 7))
if (x = foo(), y = foo()) {
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 58, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 59, 7))
>foo : Symbol(foo, Decl(controlFlowTruthiness.ts, 0, 0))
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 58, 7))
y; // string
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 59, 7))
}
else {
x; // string | undefined
>x : Symbol(x, Decl(controlFlowTruthiness.ts, 58, 7))
y; // string | undefined
>y : Symbol(y, Decl(controlFlowTruthiness.ts, 59, 7))
}
}

View file

@ -0,0 +1,160 @@
=== tests/cases/conformance/controlFlow/controlFlowTruthiness.ts ===
declare function foo(): string | undefined;
>foo : () => string | undefined
function f1() {
>f1 : () => void
let x = foo();
>x : string | undefined
>foo() : string | undefined
>foo : () => string | undefined
if (x) {
>x : string | undefined
x; // string
>x : string
}
else {
x; // string | undefined
>x : string | undefined
}
}
function f2() {
>f2 : () => void
let x: string | undefined;
>x : string | undefined
x = foo();
>x = foo() : string | undefined
>x : string | undefined
>foo() : string | undefined
>foo : () => string | undefined
if (x) {
>x : string | undefined
x; // string
>x : string
}
else {
x; // string | undefined
>x : string | undefined
}
}
function f3() {
>f3 : () => void
let x: string | undefined;
>x : string | undefined
if (x = foo()) {
>x = foo() : string | undefined
>x : string | undefined
>foo() : string | undefined
>foo : () => string | undefined
x; // string
>x : string
}
else {
x; // string | undefined
>x : string | undefined
}
}
function f4() {
>f4 : () => void
let x: string | undefined;
>x : string | undefined
if (!(x = foo())) {
>!(x = foo()) : boolean
>(x = foo()) : string | undefined
>x = foo() : string | undefined
>x : string | undefined
>foo() : string | undefined
>foo : () => string | undefined
x; // string | undefined
>x : string | undefined
}
else {
x; // string
>x : string
}
}
function f5() {
>f5 : () => void
let x: string | undefined;
>x : string | undefined
let y: string | undefined;
>y : string | undefined
if (x = y = foo()) {
>x = y = foo() : string | undefined
>x : string | undefined
>y = foo() : string | undefined
>y : string | undefined
>foo() : string | undefined
>foo : () => string | undefined
x; // string
>x : string
y; // string | undefined
>y : string | undefined
}
else {
x; // string | undefined
>x : string | undefined
y; // string | undefined
>y : string | undefined
}
}
function f6() {
>f6 : () => void
let x: string | undefined;
>x : string | undefined
let y: string | undefined;
>y : string | undefined
if (x = foo(), y = foo()) {
>x = foo(), y = foo() : string | undefined
>x = foo() : string | undefined
>x : string | undefined
>foo() : string | undefined
>foo : () => string | undefined
>y = foo() : string | undefined
>y : string | undefined
>foo() : string | undefined
>foo : () => string | undefined
x; // string | undefined
>x : string | undefined
y; // string
>y : string
}
else {
x; // string | undefined
>x : string | undefined
y; // string | undefined
>y : string | undefined
}
}

View file

@ -0,0 +1,70 @@
// @strictNullChecks: true
declare function foo(): string | undefined;
function f1() {
let x = foo();
if (x) {
x; // string
}
else {
x; // string | undefined
}
}
function f2() {
let x: string | undefined;
x = foo();
if (x) {
x; // string
}
else {
x; // string | undefined
}
}
function f3() {
let x: string | undefined;
if (x = foo()) {
x; // string
}
else {
x; // string | undefined
}
}
function f4() {
let x: string | undefined;
if (!(x = foo())) {
x; // string | undefined
}
else {
x; // string
}
}
function f5() {
let x: string | undefined;
let y: string | undefined;
if (x = y = foo()) {
x; // string
y; // string | undefined
}
else {
x; // string | undefined
y; // string | undefined
}
}
function f6() {
let x: string | undefined;
let y: string | undefined;
if (x = foo(), y = foo()) {
x; // string | undefined
y; // string
}
else {
x; // string | undefined
y; // string | undefined
}
}