Skip to content

Commit

Permalink
Add tests for symbol properties
Browse files Browse the repository at this point in the history
  • Loading branch information
JsonFreeman committed Feb 7, 2015
1 parent b60fa14 commit 779661c
Show file tree
Hide file tree
Showing 46 changed files with 443 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty10.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@target: ES6
class C {
[Symbol.iterator]: { x; y };
}
interface I {
[Symbol.iterator]?: { x };
}

var i: I;
i = new C;
var c: C = i;
9 changes: 9 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty11.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@target: ES6
class C { }
interface I {
[Symbol.iterator]?: { x };
}

var i: I;
i = new C;
var c: C = i;
11 changes: 11 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty12.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@target: ES6
class C {
private [Symbol.iterator]: { x };
}
interface I {
[Symbol.iterator]: { x };
}

var i: I;
i = new C;
var c: C = i;
17 changes: 17 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty13.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@target: ES6
class C {
[Symbol.iterator]: { x; y };
}
interface I {
[Symbol.iterator]: { x };
}

declare function foo(i: I): I;
declare function foo(a: any): any;

declare function bar(i: C): C;
declare function bar(a: any): any;

foo(new C);
var i: I;
bar(i);
17 changes: 17 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty14.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@target: ES6
class C {
[Symbol.iterator]: { x; y };
}
interface I {
[Symbol.iterator]?: { x };
}

declare function foo(i: I): I;
declare function foo(a: any): any;

declare function bar(i: C): C;
declare function bar(a: any): any;

foo(new C);
var i: I;
bar(i);
15 changes: 15 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty15.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@target: ES6
class C { }
interface I {
[Symbol.iterator]?: { x };
}

declare function foo(i: I): I;
declare function foo(a: any): any;

declare function bar(i: C): C;
declare function bar(a: any): any;

foo(new C);
var i: I;
bar(i);
17 changes: 17 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty16.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//@target: ES6
class C {
private [Symbol.iterator]: { x };
}
interface I {
[Symbol.iterator]: { x };
}

declare function foo(i: I): I;
declare function foo(a: any): any;

declare function bar(i: C): C;
declare function bar(a: any): any;

foo(new C);
var i: I;
bar(i);
9 changes: 9 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty17.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@target: ES6
interface I {
[Symbol.iterator]: number;
[s: Symbol]: string;
"__@iterator": string;
}

var i: I;
var it = i[Symbol.iterator];
10 changes: 10 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty18.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@target: ES6
var i = {
[Symbol.iterator]: 0,
[Symbol.toStringTag]() { return "" },
set [Symbol.toPrimitive](p: boolean) { }
}

var it = i[Symbol.iterator];
var str = i[Symbol.toStringTag]();
i[Symbol.toPrimitive] = false;
8 changes: 8 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty19.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@target: ES6
var i = {
[Symbol.iterator]: { p: null },
[Symbol.toStringTag]() { return { p: undefined }; }
}

var it = i[Symbol.iterator];
var str = i[Symbol.toStringTag]();
10 changes: 10 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@target: ES6
interface I {
[Symbol.iterator]: (s: string) => string;
[Symbol.toStringTag](s: number): number;
}

var i: I = {
[Symbol.iterator]: s => s,
[Symbol.toStringTag](n) { return n; }
}
13 changes: 13 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty21.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//@target: ES6
interface I<T, U> {
[Symbol.unscopables]: T;
[Symbol.isConcatSpreadable]: U;
}

declare function foo<T, U>(p: I<T, U>): { t: T; u: U };

foo({
[Symbol.isConcatSpreadable]: "",
[Symbol.isRegExp]: 0,
[Symbol.unscopables]: true
});
8 changes: 8 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty22.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@target: ES6
interface I<T, U> {
[Symbol.unscopables](x: T): U;
}

declare function foo<T, U>(p1: T, p2: I<T, U>): U;

foo("", { [Symbol.unscopables]: s => s.length });
10 changes: 10 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty23.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@target: ES6
interface I {
[Symbol.toPrimitive]: () => boolean;
}

class C implements I {
[Symbol.toPrimitive]() {
return true;
}
}
10 changes: 10 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty24.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@target: ES6
interface I {
[Symbol.toPrimitive]: () => boolean;
}

class C implements I {
[Symbol.toPrimitive]() {
return "";
}
}
10 changes: 10 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty25.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@target: ES6
interface I {
[Symbol.toPrimitive]: () => boolean;
}

class C implements I {
[Symbol.toStringTag]() {
return "";
}
}
12 changes: 12 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty26.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@target: ES6
class C1 {
[Symbol.toStringTag]() {
return "";
}
}

class C2 extends C1 {
[Symbol.toStringTag]() {
return "";
}
}
12 changes: 12 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty27.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@target: ES6
class C1 {
[Symbol.toStringTag]() {
return {};
}
}

class C2 extends C1 {
[Symbol.toStringTag]() {
return "";
}
}
11 changes: 11 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty28.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@target: ES6
class C1 {
[Symbol.toStringTag]() {
return { x: "" };
}
}

class C2 extends C1 { }

var c: C2;
var obj = c[Symbol.toStringTag]().x;
7 changes: 7 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty29.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@target: ES6
class C1 {
[Symbol.toStringTag]() {
return { x: "" };
}
[s: Symbol]: () => { x: string };
}
7 changes: 7 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty30.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@target: ES6
class C1 {
[Symbol.toStringTag]() {
return { x: "" };
}
[s: Symbol]: () => { x: number };
}
9 changes: 9 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty31.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@target: ES6
class C1 {
[Symbol.toStringTag]() {
return { x: "" };
}
}
class C2 extends C1 {
[s: Symbol]: () => { x: string };
}
9 changes: 9 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty32.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@target: ES6
class C1 {
[Symbol.toStringTag]() {
return { x: "" };
}
}
class C2 extends C1 {
[s: Symbol]: () => { x: number };
}
9 changes: 9 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty33.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@target: ES6
class C1 extends C2 {
[Symbol.toStringTag]() {
return { x: "" };
}
}
class C2 {
[s: Symbol]: () => { x: string };
}
9 changes: 9 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty34.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@target: ES6
class C1 extends C2 {
[Symbol.toStringTag]() {
return { x: "" };
}
}
class C2 {
[s: Symbol]: () => { x: number };
}
9 changes: 9 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty35.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//@target: ES6
interface I1 {
[Symbol.toStringTag](): { x: string }
}
interface I2 {
[Symbol.toStringTag](): { x: number }
}

interface I3 extends I1, I2 { }
5 changes: 5 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty36.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@target: ES6
var x = {
[Symbol.isConcatSpreadable]: 0,
[Symbol.isConcatSpreadable]: 1
}
5 changes: 5 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty37.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
//@target: ES6
interface I {
[Symbol.isConcatSpreadable]: string;
[Symbol.isConcatSpreadable]: string;
}
7 changes: 7 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty38.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//@target: ES6
interface I {
[Symbol.isConcatSpreadable]: string;
}
interface I {
[Symbol.isConcatSpreadable]: string;
}
11 changes: 11 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty39.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@target: ES6
class C {
[Symbol.iterator](x: string): string;
[Symbol.iterator](x: number): number;
[Symbol.iterator](x: any) {
return undefined;
}
[Symbol.iterator](x: any) {
return undefined;
}
}
12 changes: 12 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty40.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@target: ES6
class C {
[Symbol.iterator](x: string): string;
[Symbol.iterator](x: number): number;
[Symbol.iterator](x: any) {
return undefined;
}
}

var c = new C;
c[Symbol.iterator]("");
c[Symbol.iterator](0);
12 changes: 12 additions & 0 deletions tests/cases/conformance/es6/Symbols/symbolProperty41.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@target: ES6
class C {
[Symbol.iterator](x: string): { x: string };
[Symbol.iterator](x: "hello"): { x: string; hello: string };
[Symbol.iterator](x: any) {
return undefined;
}
}

var c = new C;
c[Symbol.iterator]("");
c[Symbol.iterator]("hello");
Loading

0 comments on commit 779661c

Please sign in to comment.