From f28e424d31cb06b141a81580122cb43495066e54 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Tue, 1 Sep 2015 13:16:54 -0700 Subject: [PATCH] Adding tests --- .../destructuringWithLiteralInitializers.js | 117 +++++++++ ...structuringWithLiteralInitializers.symbols | 150 +++++++++++ ...destructuringWithLiteralInitializers.types | 235 ++++++++++++++++++ .../destructuringWithLiteralInitializers.ts | 51 ++++ 4 files changed, 553 insertions(+) create mode 100644 tests/baselines/reference/destructuringWithLiteralInitializers.js create mode 100644 tests/baselines/reference/destructuringWithLiteralInitializers.symbols create mode 100644 tests/baselines/reference/destructuringWithLiteralInitializers.types create mode 100644 tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.js b/tests/baselines/reference/destructuringWithLiteralInitializers.js new file mode 100644 index 0000000000..c25216a55f --- /dev/null +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.js @@ -0,0 +1,117 @@ +//// [destructuringWithLiteralInitializers.ts] +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +f1({ x: 1, y: 1 }); + +function f2({ x, y = 0 }) { } +f2({ x: 1 }); +f2({ x: 1, y: 1 }); + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +f3({}); +f3({ x: 1 }); +f3({ y: 1 }); +f3({ x: 1, y: 1 }); + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +f4(); +f4({ x: 1, y: 1 }); + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +f5(); +f5({ x: 1 }); +f5({ x: 1, y: 1 }); + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +f6(); +f6({}); +f6({ x: 1 }); +f6({ y: 1 }); +f6({ x: 1, y: 1 }); + +// (arg: [any, any]) => void +function g1([x, y]) { } +g1([1, 1]); + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +g2([1, 1]); + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +g3(); +g3([1, 1]); + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +g4(); +g4([1, 1]); + + +//// [destructuringWithLiteralInitializers.js] +// (arg: { x: any, y: any }) => void +function f1(_a) { + var x = _a.x, y = _a.y; +} +f1({ x: 1, y: 1 }); +function f2(_a) { + var x = _a.x, _b = _a.y, y = _b === void 0 ? 0 : _b; +} +f2({ x: 1 }); +f2({ x: 1, y: 1 }); +// (arg: { x?: number, y?: number }) => void +function f3(_a) { + var _b = _a.x, x = _b === void 0 ? 0 : _b, _c = _a.y, y = _c === void 0 ? 0 : _c; +} +f3({}); +f3({ x: 1 }); +f3({ y: 1 }); +f3({ x: 1, y: 1 }); +// (arg?: { x: number, y: number }) => void +function f4(_a) { + var _b = _a === void 0 ? { x: 0, y: 0 } : _a, x = _b.x, y = _b.y; +} +f4(); +f4({ x: 1, y: 1 }); +// (arg?: { x: number, y?: number }) => void +function f5(_a) { + var _b = _a === void 0 ? { x: 0 } : _a, x = _b.x, _c = _b.y, y = _c === void 0 ? 0 : _c; +} +f5(); +f5({ x: 1 }); +f5({ x: 1, y: 1 }); +// (arg?: { x?: number, y?: number }) => void +function f6(_a) { + var _b = _a === void 0 ? {} : _a, _c = _b.x, x = _c === void 0 ? 0 : _c, _d = _b.y, y = _d === void 0 ? 0 : _d; +} +f6(); +f6({}); +f6({ x: 1 }); +f6({ y: 1 }); +f6({ x: 1, y: 1 }); +// (arg: [any, any]) => void +function g1(_a) { + var x = _a[0], y = _a[1]; +} +g1([1, 1]); +// (arg: [number, number]) => void +function g2(_a) { + var _b = _a[0], x = _b === void 0 ? 0 : _b, _c = _a[1], y = _c === void 0 ? 0 : _c; +} +g2([1, 1]); +// (arg?: [any, any]) => void +function g3(_a) { + var _b = _a === void 0 ? [] : _a, x = _b[0], y = _b[1]; +} +g3(); +g3([1, 1]); +// (arg?: [number, number]) => void +function g4(_a) { + var _b = _a === void 0 ? [0, 0] : _a, x = _b[0], y = _b[1]; +} +g4(); +g4([1, 1]); diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.symbols b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols new file mode 100644 index 0000000000..992a9c3ace --- /dev/null +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.symbols @@ -0,0 +1,150 @@ +=== tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts === +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +>f1 : Symbol(f1, Decl(destructuringWithLiteralInitializers.ts, 0, 0)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 1, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 1, 16)) + +f1({ x: 1, y: 1 }); +>f1 : Symbol(f1, Decl(destructuringWithLiteralInitializers.ts, 0, 0)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 2, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 2, 10)) + +function f2({ x, y = 0 }) { } +>f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 4, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 4, 16)) + +f2({ x: 1 }); +>f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 5, 4)) + +f2({ x: 1, y: 1 }); +>f2 : Symbol(f2, Decl(destructuringWithLiteralInitializers.ts, 2, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 6, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 6, 10)) + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 9, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 9, 20)) + +f3({}); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) + +f3({ x: 1 }); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 11, 4)) + +f3({ y: 1 }); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 12, 4)) + +f3({ x: 1, y: 1 }); +>f3 : Symbol(f3, Decl(destructuringWithLiteralInitializers.ts, 6, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 13, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 13, 10)) + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 16, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 16, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 16, 24)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 16, 30)) + +f4(); +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) + +f4({ x: 1, y: 1 }); +>f4 : Symbol(f4, Decl(destructuringWithLiteralInitializers.ts, 13, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 18, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 18, 10)) + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 21, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 21, 16)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 21, 28)) + +f5(); +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) + +f5({ x: 1 }); +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 23, 4)) + +f5({ x: 1, y: 1 }); +>f5 : Symbol(f5, Decl(destructuringWithLiteralInitializers.ts, 18, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 24, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 24, 10)) + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 27, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 27, 20)) + +f6(); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) + +f6({}); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) + +f6({ x: 1 }); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 30, 4)) + +f6({ y: 1 }); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 31, 4)) + +f6({ x: 1, y: 1 }); +>f6 : Symbol(f6, Decl(destructuringWithLiteralInitializers.ts, 24, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 32, 4)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 32, 10)) + +// (arg: [any, any]) => void +function g1([x, y]) { } +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 32, 19)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 35, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 35, 15)) + +g1([1, 1]); +>g1 : Symbol(g1, Decl(destructuringWithLiteralInitializers.ts, 32, 19)) + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 36, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 39, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 39, 19)) + +g2([1, 1]); +>g2 : Symbol(g2, Decl(destructuringWithLiteralInitializers.ts, 36, 11)) + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 43, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 43, 15)) + +g3(); +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) + +g3([1, 1]); +>g3 : Symbol(g3, Decl(destructuringWithLiteralInitializers.ts, 40, 11)) + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) +>x : Symbol(x, Decl(destructuringWithLiteralInitializers.ts, 48, 13)) +>y : Symbol(y, Decl(destructuringWithLiteralInitializers.ts, 48, 15)) + +g4(); +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) + +g4([1, 1]); +>g4 : Symbol(g4, Decl(destructuringWithLiteralInitializers.ts, 45, 11)) + diff --git a/tests/baselines/reference/destructuringWithLiteralInitializers.types b/tests/baselines/reference/destructuringWithLiteralInitializers.types new file mode 100644 index 0000000000..c0577cb995 --- /dev/null +++ b/tests/baselines/reference/destructuringWithLiteralInitializers.types @@ -0,0 +1,235 @@ +=== tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts === +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +>f1 : ({ x, y }: { x: any; y: any; }) => void +>x : any +>y : any + +f1({ x: 1, y: 1 }); +>f1({ x: 1, y: 1 }) : void +>f1 : ({ x, y }: { x: any; y: any; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +function f2({ x, y = 0 }) { } +>f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void +>x : any +>y : number +>0 : number + +f2({ x: 1 }); +>f2({ x: 1 }) : void +>f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f2({ x: 1, y: 1 }); +>f2({ x: 1, y: 1 }) : void +>f2 : ({ x, y = 0 }: { x: any; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>x : number +>0 : number +>y : number +>0 : number + +f3({}); +>f3({}) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{} : {} + +f3({ x: 1 }); +>f3({ x: 1 }) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f3({ y: 1 }); +>f3({ y: 1 }) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{ y: 1 } : { y: number; } +>y : number +>1 : number + +f3({ x: 1, y: 1 }); +>f3({ x: 1, y: 1 }) : void +>f3 : ({ x = 0, y = 0 }: { x?: number; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +>f4 : ({ x, y }?: { x: number; y: number; }) => void +>x : number +>y : number +>{ x: 0, y: 0 } : { x: number; y: number; } +>x : number +>0 : number +>y : number +>0 : number + +f4(); +>f4() : void +>f4 : ({ x, y }?: { x: number; y: number; }) => void + +f4({ x: 1, y: 1 }); +>f4({ x: 1, y: 1 }) : void +>f4 : ({ x, y }?: { x: number; y: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void +>x : number +>y : number +>0 : number +>{ x: 0 } : { x: number; y?: number; } +>x : number +>0 : number + +f5(); +>f5() : void +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void + +f5({ x: 1 }); +>f5({ x: 1 }) : void +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f5({ x: 1, y: 1 }); +>f5({ x: 1, y: 1 }) : void +>f5 : ({ x, y = 0 }?: { x: number; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>x : number +>0 : number +>y : number +>0 : number +>{} : { x?: number; y?: number; } + +f6(); +>f6() : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void + +f6({}); +>f6({}) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{} : {} + +f6({ x: 1 }); +>f6({ x: 1 }) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{ x: 1 } : { x: number; } +>x : number +>1 : number + +f6({ y: 1 }); +>f6({ y: 1 }) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{ y: 1 } : { y: number; } +>y : number +>1 : number + +f6({ x: 1, y: 1 }); +>f6({ x: 1, y: 1 }) : void +>f6 : ({ x = 0, y = 0 }?: { x?: number; y?: number; }) => void +>{ x: 1, y: 1 } : { x: number; y: number; } +>x : number +>1 : number +>y : number +>1 : number + +// (arg: [any, any]) => void +function g1([x, y]) { } +>g1 : ([x, y]: [any, any]) => void +>x : any +>y : any + +g1([1, 1]); +>g1([1, 1]) : void +>g1 : ([x, y]: [any, any]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +>g2 : ([x = 0, y = 0]: [number, number]) => void +>x : number +>0 : number +>y : number +>0 : number + +g2([1, 1]); +>g2([1, 1]) : void +>g2 : ([x = 0, y = 0]: [number, number]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +>g3 : ([x, y]?: [any, any]) => void +>x : any +>y : any +>[] : [any, any] + +g3(); +>g3() : void +>g3 : ([x, y]?: [any, any]) => void + +g3([1, 1]); +>g3([1, 1]) : void +>g3 : ([x, y]?: [any, any]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +>g4 : ([x, y]?: [number, number]) => void +>x : number +>y : number +>[0, 0] : [number, number] +>0 : number +>0 : number + +g4(); +>g4() : void +>g4 : ([x, y]?: [number, number]) => void + +g4([1, 1]); +>g4([1, 1]) : void +>g4 : ([x, y]?: [number, number]) => void +>[1, 1] : [number, number] +>1 : number +>1 : number + diff --git a/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts new file mode 100644 index 0000000000..8f6b77d95c --- /dev/null +++ b/tests/cases/conformance/es6/destructuring/destructuringWithLiteralInitializers.ts @@ -0,0 +1,51 @@ +// (arg: { x: any, y: any }) => void +function f1({ x, y }) { } +f1({ x: 1, y: 1 }); + +function f2({ x, y = 0 }) { } +f2({ x: 1 }); +f2({ x: 1, y: 1 }); + +// (arg: { x?: number, y?: number }) => void +function f3({ x = 0, y = 0 }) { } +f3({}); +f3({ x: 1 }); +f3({ y: 1 }); +f3({ x: 1, y: 1 }); + +// (arg?: { x: number, y: number }) => void +function f4({ x, y } = { x: 0, y: 0 }) { } +f4(); +f4({ x: 1, y: 1 }); + +// (arg?: { x: number, y?: number }) => void +function f5({ x, y = 0 } = { x: 0 }) { } +f5(); +f5({ x: 1 }); +f5({ x: 1, y: 1 }); + +// (arg?: { x?: number, y?: number }) => void +function f6({ x = 0, y = 0 } = {}) { } +f6(); +f6({}); +f6({ x: 1 }); +f6({ y: 1 }); +f6({ x: 1, y: 1 }); + +// (arg: [any, any]) => void +function g1([x, y]) { } +g1([1, 1]); + +// (arg: [number, number]) => void +function g2([x = 0, y = 0]) { } +g2([1, 1]); + +// (arg?: [any, any]) => void +function g3([x, y] = []) { } +g3(); +g3([1, 1]); + +// (arg?: [number, number]) => void +function g4([x, y] = [0, 0]) { } +g4(); +g4([1, 1]);