Add tests for classes, methods, accessors with computed properties

This commit is contained in:
Jason Freeman 2015-01-13 16:10:24 -08:00
parent de3eb36b2c
commit 96b5f1fe43
23 changed files with 800 additions and 0 deletions

View file

@ -0,0 +1,46 @@
//// [computedPropertyNames10.ts]
var s: string;
var n: number;
var a: any;
var v = {
[s]() { },
[n]() { },
[s + s]() { },
[s + n]() { },
[+s]() { },
[""]() { },
[0]() { },
[a]() { },
[<any>true]() { },
[`hello bye`]() { },
[`hello ${a} bye`]() { }
}
//// [computedPropertyNames10.js]
var s;
var n;
var a;
var v = {
[s]() {
},
[n]() {
},
[s + s]() {
},
[s + n]() {
},
[+s]() {
},
[""]() {
},
[0]() {
},
[a]() {
},
[true]() {
},
[`hello bye`]() {
},
[`hello ${a} bye`]() {
}
};

View file

@ -0,0 +1,46 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames10.ts ===
var s: string;
>s : string
var n: number;
>n : number
var a: any;
>a : any
var v = {
>v : {}
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : {}
[s]() { },
>s : string
[n]() { },
>n : number
[s + s]() { },
>s + s : string
>s : string
>s : string
[s + n]() { },
>s + n : string
>s : string
>n : number
[+s]() { },
>+s : number
>s : string
[""]() { },
[0]() { },
[a]() { },
>a : any
[<any>true]() { },
><any>true : any
[`hello bye`]() { },
[`hello ${a} bye`]() { }
>a : any
}

View file

@ -0,0 +1,52 @@
//// [computedPropertyNames11.ts]
var s: string;
var n: number;
var a: any;
var v = {
get [s]() { return 0; },
set [n](v) { },
get [s + s]() { return 0; },
set [s + n](v) { },
get [+s]() { return 0; },
set [""](v) { },
get [0]() { return 0; },
set [a](v) { },
get [<any>true]() { return 0; },
set [`hello bye`](v) { },
get [`hello ${a} bye`]() { return 0; }
}
//// [computedPropertyNames11.js]
var s;
var n;
var a;
var v = {
get [s]() {
return 0;
},
set [n](v) {
},
get [s + s]() {
return 0;
},
set [s + n](v) {
},
get [+s]() {
return 0;
},
set [""](v) {
},
get [0]() {
return 0;
},
set [a](v) {
},
get [true]() {
return 0;
},
set [`hello bye`](v) {
},
get [`hello ${a} bye`]() {
return 0;
}
};

View file

@ -0,0 +1,53 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames11.ts ===
var s: string;
>s : string
var n: number;
>n : number
var a: any;
>a : any
var v = {
>v : {}
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : {}
get [s]() { return 0; },
>s : string
set [n](v) { },
>n : number
>v : any
get [s + s]() { return 0; },
>s + s : string
>s : string
>s : string
set [s + n](v) { },
>s + n : string
>s : string
>n : number
>v : any
get [+s]() { return 0; },
>+s : number
>s : string
set [""](v) { },
>v : any
get [0]() { return 0; },
set [a](v) { },
>a : any
>v : any
get [<any>true]() { return 0; },
><any>true : any
set [`hello bye`](v) { },
>v : any
get [`hello ${a} bye`]() { return 0; }
>a : any
}

View file

@ -0,0 +1,52 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(5,5): error TS1166: Computed property names are not allowed in class property declarations.
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(6,5): error TS1166: Computed property names are not allowed in class property declarations.
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(7,12): error TS1166: Computed property names are not allowed in class property declarations.
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(8,5): error TS1166: Computed property names are not allowed in class property declarations.
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(9,5): error TS1166: Computed property names are not allowed in class property declarations.
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(10,12): error TS1166: Computed property names are not allowed in class property declarations.
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(11,5): error TS1166: Computed property names are not allowed in class property declarations.
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(12,5): error TS1166: Computed property names are not allowed in class property declarations.
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(13,12): error TS1166: Computed property names are not allowed in class property declarations.
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(14,5): error TS1166: Computed property names are not allowed in class property declarations.
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(15,12): error TS1166: Computed property names are not allowed in class property declarations.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts (11 errors) ====
var s: string;
var n: number;
var a: any;
class C {
[s]: number;
~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
[n] = n;
~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
static [s + s]: string;
~~~~~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
[s + n] = 2;
~~~~~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
[+s]: typeof s;
~~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
static [""]: number;
~~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
[0]: number;
~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
[a]: number;
~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
static [<any>true]: number;
~~~~~~~~~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
[`hello bye`] = 0;
~~~~~~~~~~~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
static [`hello ${a} bye`] = 0
~~~~~~~~~~~~~~~~~~
!!! error TS1166: Computed property names are not allowed in class property declarations.
}

View file

@ -0,0 +1,49 @@
//// [computedPropertyNames13.ts]
var s: string;
var n: number;
var a: any;
class C {
[s]() {}
[n]() { }
static [s + s]() { }
[s + n]() { }
[+s]() { }
static [""]() { }
[0]() { }
[a]() { }
static [<any>true]() { }
[`hello bye`]() { }
static [`hello ${a} bye`]() { }
}
//// [computedPropertyNames13.js]
var s;
var n;
var a;
var C = (function () {
function C() {
}
C.prototype[s] = function () {
};
C.prototype[n] = function () {
};
C[s + s] = function () {
};
C.prototype[s + n] = function () {
};
C.prototype[+s] = function () {
};
C[""] = function () {
};
C.prototype[0] = function () {
};
C.prototype[a] = function () {
};
C[true] = function () {
};
C.prototype[`hello bye`] = function () {
};
C[`hello ${a} bye`] = function () {
};
return C;
})();

View file

@ -0,0 +1,45 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames13.ts ===
var s: string;
>s : string
var n: number;
>n : number
var a: any;
>a : any
class C {
>C : C
[s]() {}
>s : string
[n]() { }
>n : number
static [s + s]() { }
>s + s : string
>s : string
>s : string
[s + n]() { }
>s + n : string
>s : string
>n : number
[+s]() { }
>+s : number
>s : string
static [""]() { }
[0]() { }
[a]() { }
>a : any
static [<any>true]() { }
><any>true : any
[`hello bye`]() { }
static [`hello ${a} bye`]() { }
>a : any
}

View file

@ -0,0 +1,30 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(3,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(4,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(6,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(8,12): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts (6 errors) ====
var b: boolean;
class C {
[b]() {}
~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
static [true]() { }
~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[[]]() { }
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
static [{}]() { }
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[undefined]() { }
~~~~~~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
static [null]() { }
~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
}

View file

@ -0,0 +1,30 @@
//// [computedPropertyNames14.ts]
var b: boolean;
class C {
[b]() {}
static [true]() { }
[[]]() { }
static [{}]() { }
[undefined]() { }
static [null]() { }
}
//// [computedPropertyNames14.js]
var b;
var C = (function () {
function C() {
}
C.prototype[b] = function () {
};
C[true] = function () {
};
C.prototype[[]] = function () {
};
C[{}] = function () {
};
C.prototype[undefined] = function () {
};
C[null] = function () {
};
return C;
})();

View file

@ -0,0 +1,20 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(5,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(6,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(7,5): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts (3 errors) ====
var p1: number | string;
var p2: number | number[];
var p3: string | boolean;
class C {
[p1]() { }
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[p2]() { }
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
[p3]() { }
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
}

View file

@ -0,0 +1,25 @@
//// [computedPropertyNames15.ts]
var p1: number | string;
var p2: number | number[];
var p3: string | boolean;
class C {
[p1]() { }
[p2]() { }
[p3]() { }
}
//// [computedPropertyNames15.js]
var p1;
var p2;
var p3;
var C = (function () {
function C() {
}
C.prototype[p1] = function () {
};
C.prototype[p2] = function () {
};
C.prototype[p3] = function () {
};
return C;
})();

View file

@ -0,0 +1,99 @@
//// [computedPropertyNames16.ts]
var s: string;
var n: number;
var a: any;
class C {
get [s]() { return 0;}
set [n](v) { }
static get [s + s]() { return 0; }
set [s + n](v) { }
get [+s]() { return 0; }
static set [""](v) { }
get [0]() { return 0; }
set [a](v) { }
static get [<any>true]() { return 0; }
set [`hello bye`](v) { }
get [`hello ${a} bye`]() { return 0; }
}
//// [computedPropertyNames16.js]
var s;
var n;
var a;
var C = (function () {
function C() {
}
Object.defineProperty(C.prototype, s, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, n, {
set: function (v) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C, s + s, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, s + n, {
set: function (v) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, +s, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(C, "", {
set: function (v) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, 0, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, a, {
set: function (v) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C, true, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, `hello bye`, {
set: function (v) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, `hello ${a} bye`, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
});
return C;
})();

View file

@ -0,0 +1,52 @@
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames16.ts ===
var s: string;
>s : string
var n: number;
>n : number
var a: any;
>a : any
class C {
>C : C
get [s]() { return 0;}
>s : string
set [n](v) { }
>n : number
>v : any
static get [s + s]() { return 0; }
>s + s : string
>s : string
>s : string
set [s + n](v) { }
>s + n : string
>s : string
>n : number
>v : any
get [+s]() { return 0; }
>+s : number
>s : string
static set [""](v) { }
>v : any
get [0]() { return 0; }
set [a](v) { }
>a : any
>v : any
static get [<any>true]() { return 0; }
><any>true : any
set [`hello bye`](v) { }
>v : any
get [`hello ${a} bye`]() { return 0; }
>a : any
}

View file

@ -0,0 +1,30 @@
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(3,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(4,16): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(5,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(6,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(7,16): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(8,9): error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts (6 errors) ====
var b: boolean;
class C {
get [b]() { return 0;}
~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
static set [true](v) { }
~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
get [[]]() { return 0; }
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
set [{}](v) { }
~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
static get [undefined]() { return 0; }
~~~~~~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
set [null](v) { }
~~~~~~
!!! error TS2463: A computed property name must be of type 'string', 'number', or 'any'.
}

View file

@ -0,0 +1,57 @@
//// [computedPropertyNames17.ts]
var b: boolean;
class C {
get [b]() { return 0;}
static set [true](v) { }
get [[]]() { return 0; }
set [{}](v) { }
static get [undefined]() { return 0; }
set [null](v) { }
}
//// [computedPropertyNames17.js]
var b;
var C = (function () {
function C() {
}
Object.defineProperty(C.prototype, b, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(C, true, {
set: function (v) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, [], {
get: function () {
return 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, {}, {
set: function (v) {
},
enumerable: true,
configurable: true
});
Object.defineProperty(C, undefined, {
get: function () {
return 0;
},
enumerable: true,
configurable: true
});
Object.defineProperty(C.prototype, null, {
set: function (v) {
},
enumerable: true,
configurable: true
});
return C;
})();

View file

@ -0,0 +1,17 @@
// @target: es6
var s: string;
var n: number;
var a: any;
var v = {
[s]() { },
[n]() { },
[s + s]() { },
[s + n]() { },
[+s]() { },
[""]() { },
[0]() { },
[a]() { },
[<any>true]() { },
[`hello bye`]() { },
[`hello ${a} bye`]() { }
}

View file

@ -0,0 +1,17 @@
// @target: es6
var s: string;
var n: number;
var a: any;
var v = {
get [s]() { return 0; },
set [n](v) { },
get [s + s]() { return 0; },
set [s + n](v) { },
get [+s]() { return 0; },
set [""](v) { },
get [0]() { return 0; },
set [a](v) { },
get [<any>true]() { return 0; },
set [`hello bye`](v) { },
get [`hello ${a} bye`]() { return 0; }
}

View file

@ -0,0 +1,17 @@
// @target: es6
var s: string;
var n: number;
var a: any;
class C {
[s]: number;
[n] = n;
static [s + s]: string;
[s + n] = 2;
[+s]: typeof s;
static [""]: number;
[0]: number;
[a]: number;
static [<any>true]: number;
[`hello bye`] = 0;
static [`hello ${a} bye`] = 0
}

View file

@ -0,0 +1,17 @@
// @target: es6
var s: string;
var n: number;
var a: any;
class C {
[s]() {}
[n]() { }
static [s + s]() { }
[s + n]() { }
[+s]() { }
static [""]() { }
[0]() { }
[a]() { }
static [<any>true]() { }
[`hello bye`]() { }
static [`hello ${a} bye`]() { }
}

View file

@ -0,0 +1,10 @@
// @target: es6
var b: boolean;
class C {
[b]() {}
static [true]() { }
[[]]() { }
static [{}]() { }
[undefined]() { }
static [null]() { }
}

View file

@ -0,0 +1,9 @@
// @target: es6
var p1: number | string;
var p2: number | number[];
var p3: string | boolean;
class C {
[p1]() { }
[p2]() { }
[p3]() { }
}

View file

@ -0,0 +1,17 @@
// @target: es6
var s: string;
var n: number;
var a: any;
class C {
get [s]() { return 0;}
set [n](v) { }
static get [s + s]() { return 0; }
set [s + n](v) { }
get [+s]() { return 0; }
static set [""](v) { }
get [0]() { return 0; }
set [a](v) { }
static get [<any>true]() { return 0; }
set [`hello bye`](v) { }
get [`hello ${a} bye`]() { return 0; }
}

View file

@ -0,0 +1,10 @@
// @target: es6
var b: boolean;
class C {
get [b]() { return 0;}
static set [true](v) { }
get [[]]() { return 0; }
set [{}](v) { }
static get [undefined]() { return 0; }
set [null](v) { }
}