| Index: test/mjsunit/harmony/typesystem/typegen.js
|
| diff --git a/test/mjsunit/harmony/typesystem/typegen.js b/test/mjsunit/harmony/typesystem/typegen.js
|
| index d61c7071d1b3a1a617487d29ef84e953fbc18557..0cc890faf0d5b400a4e7859ad84cbe9b02a72fbb 100644
|
| --- a/test/mjsunit/harmony/typesystem/typegen.js
|
| +++ b/test/mjsunit/harmony/typesystem/typegen.js
|
| @@ -31,6 +31,7 @@ function ValidPrimaryTypes(size, proper=false) {
|
| t => "(" + t + "[])[]",
|
| ]),
|
| new TestGen(1, ValidTupleTypes, [t => t]),
|
| + new TestGen(1, ValidObjectTypes, [t => t]),
|
| proper && "number",
|
| proper && "boolean",
|
| proper && "string",
|
| @@ -61,6 +62,7 @@ function InvalidPrimaryTypes(size, proper=false) {
|
| t => "(" + t + "[])[]",
|
| ]),
|
| new TestGen(1, InvalidTupleTypes, [t => t]),
|
| + new TestGen(1, InvalidObjectTypes, [t => t]),
|
| // Line terminator in arrays.
|
| new TestGen(1, ValidTypes, [
|
| t => "(" + t + "\n[])"
|
| @@ -154,18 +156,29 @@ function ValidFunctionTypes(size, constr) {
|
| t => c + "(a:" + t + ", b:" + t + ", c, ...d) => " + t,
|
| t => c + "(a:" + t + ", b:" + t + ", c, ...d: string[]) => " + t
|
| ]),
|
| - // Parametric function types
|
| + // Parametric function types.
|
| "<A> (x: A) => A",
|
| "<A extends string> (x: A) => A",
|
| "<A, B> (x: A, y: B) => A",
|
| "<A, B extends number[], C> (x: A, y: B) => C",
|
| "<A, B, C, D> (x: A, y: B, z: C[], d: (e: D) => D) => A",
|
| - // String literal types
|
| + // String literal types.
|
| "(cmd: 'add', x: number, y: number) => number",
|
| '(cmd: "sum", a: number[]) => number',
|
| "(x: number, cmd: 'one', ...rest) => any",
|
| "(x: string, y: number, cmd: 'two', ...rest) => any",
|
| - "(x: number, cmd?: 'two', ...rest) => string"
|
| + "(x: number, cmd?: 'two', ...rest) => string",
|
| + // With binding patterns.
|
| + "([]: number[]) => boolean",
|
| + "([x, y]: number[]) => boolean",
|
| + "([x, ...rest]: number[]) => boolean",
|
| + "([,x, y]: number[]) => boolean",
|
| + "([x, y,]: number[]) => boolean",
|
| + "([x, y,,]: number[]) => boolean",
|
| + "([x, [a, b, c], z]: [number, any[], string]) => boolean",
|
| + "({x: a, y: b}: {x: number, y: string}) => boolean",
|
| + "({x: a, y: [b, c, ...rest]}: {x: number, y: string[]}) => boolean",
|
| + "({x: {a, b}, y: c}: {x: {a, b}, y: string}) => boolean"
|
| ]);
|
| }
|
|
|
| @@ -183,10 +196,12 @@ function InvalidFunctionTypes(size, constr) {
|
| t => c + "(a:" + t + ", b:" + t + ", c, ...d) => " + t,
|
| t => c + "(a:" + t + ", b:" + t + ", c, ...d: string[]) => " + t,
|
| ]),
|
| - // Parametric function types
|
| + // Parametric function types.
|
| "<A> A[]",
|
| "<> (x: number) => number",
|
| - "<A extends ()> (x: A) => A"
|
| + "<A extends ()> (x: A) => A",
|
| + // With illegal binding patterns.
|
| + "({x: {a; b}, y: c}: {x: {a; b}, y: string}) => boolean"
|
| ]);
|
| }
|
|
|
| @@ -224,6 +239,102 @@ function InvalidTupleTypes(size) {
|
| }
|
|
|
|
|
| +// Object types.
|
| +
|
| +function ValidObjectTypes(size) {
|
| + return Generate(size, [
|
| + // Empty object type.
|
| + "{}",
|
| + // Property signatures.
|
| + "{a}",
|
| + "{a, b}",
|
| + "{a, b?}",
|
| + "{a?, b}",
|
| + new TestGen(1, ValidTypes, [
|
| + t => "{a: " + t + "}",
|
| + t => "{a: " + t + ", b: " + t + "}",
|
| + t => "{a?: " + t + "}",
|
| + t => "{a: " + t + ", b?: " + t + "}",
|
| + ]),
|
| + // Method signatures.
|
| + "{f()}",
|
| + "{f?()}",
|
| + "{f(a)}",
|
| + "{f?(a)}",
|
| + "{f(a, b)}",
|
| + "{f?(a, b)}",
|
| + new TestGen(1, ValidTypes, [
|
| + t => "{f() : " + t + "}",
|
| + t => "{f?() : " + t + "}",
|
| + t => "{f(a: " + t + ")}",
|
| + t => "{f?(a: " + t + ")}",
|
| + t => "{f(a: " + t + ") : " + t + "}",
|
| + t => "{f?(a: " + t + ") : " + t + "}",
|
| + t => "{f<A>(a: " + t + ")}",
|
| + t => "{f?<A>(a: " + t + ")}",
|
| + t => "{f<A, B>(a: A, b: " + t + ") : B}",
|
| + t => "{f?<A, B>(a: A, b: " + t + ") : B}",
|
| + t => "{f<A extends " + t + ">(a: " + t + ")}",
|
| + t => "{f?<A extends " + t + ">(a: " + t + ")}",
|
| + t => "{f<A extends " + t + ", B>(a: A, b: " + t + ") : B}",
|
| + t => "{f?<A extends " + t + ", B>(a: A, b: " + t + ") : B}",
|
| + t => "{f<A extends " + t + ">(a: " + t + ") : " + t + "}",
|
| + t => "{f?<A extends " + t + ">(a: " + t + ") : " + t + "}"
|
| + ]),
|
| + // Call signatures.
|
| + "{()}",
|
| + "{(a)}",
|
| + "{(a, b)}",
|
| + new TestGen(1, ValidTypes, [
|
| + t => "{() : " + t + "}",
|
| + t => "{(a: " + t + ")}",
|
| + t => "{(a: " + t + ") : " + t + "}",
|
| + t => "{<A extends " + t + ">(a: " + t + ")}",
|
| + t => "{<A extends " + t + ">(a: " + t + ") : " + t + "}"
|
| + ]),
|
| + // Constructor signatures.
|
| + "{new ()}",
|
| + "{new (a)}",
|
| + "{new (a, b)}",
|
| + new TestGen(1, ValidTypes, [
|
| + t => "{new () : " + t + "}",
|
| + t => "{new (a: " + t + ")}",
|
| + t => "{new (a: " + t + ") : " + t + "}",
|
| + t => "{new <A extends " + t + ">(a: " + t + ")}",
|
| + t => "{new <A extends " + t + ">(a: " + t + ") : " + t + "}"
|
| + ]),
|
| + // Index signatures.
|
| + "{[a: number]}",
|
| + "{[a: string]}",
|
| + new TestGen(1, ValidTypes, [
|
| + t => "{[a: number] : " + t + "}",
|
| + t => "{[a: string] : " + t + "}"
|
| + ])
|
| + ]);
|
| +}
|
| +
|
| +function InvalidObjectTypes(size) {
|
| + return Generate(size, [
|
| + // Illegal types in legal places.
|
| + new TestGen(1, InvalidTypes, [
|
| + t => "{a: " + t + "}",
|
| + t => "{a: " + t + ", b?: " + t + "}",
|
| + t => "{f() : " + t + "}",
|
| + t => "{f(a: " + t + ")}",
|
| + t => "{f<A extends " + t + ">()}",
|
| + t => "{(a: " + t + ")}",
|
| + t => "{new () : " + t + "}"
|
| + ]),
|
| + // Valid binding patterns that are not tuple types.
|
| + "{a: []}",
|
| + "{a: [...rest]}",
|
| + // Invalid index signatures.
|
| + "{[a: any]}",
|
| + "{[a: any] : number}"
|
| + ]);
|
| +}
|
| +
|
| +
|
| // All types: simple, type references, type parametric, type queries
|
| // and tuples.
|
|
|
|
|