Chromium Code Reviews| Index: tests/language/arg_param_trailing_comma_test.dart |
| diff --git a/tests/language/arg_param_trailing_comma_test.dart b/tests/language/arg_param_trailing_comma_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6db0ae6913f22017adeda08d8751e8f241c91685 |
| --- /dev/null |
| +++ b/tests/language/arg_param_trailing_comma_test.dart |
| @@ -0,0 +1,260 @@ |
| +// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| +// Dart test program for testing params. |
| + |
| +// Convenience values. |
| +var c = new C(); |
| +var x = 42; |
| +var y = 42; |
| +var z = 42; |
| + |
| +// Trailing comma in parameter litss. |
| + |
| +// Typedefs. |
| +typedef fx(x, ); |
| +typedef fy([y,]); |
| +typedef fxy(x, [y, ]); |
| +typedef fz({z,}); |
| +typedef fxz(x, {z, }); |
| + |
| +// As arguments type. |
| +argfx(void f(x, )) {} |
| +argfy(void f([y, ])) {} |
| +argfxy(void f(x, [y, ])) {} |
| +argfz(void f({z, })) {} |
| +argfxz(void f(x, {z, })) {} |
| + |
| +// Top level functions |
| +void topx(x,) {} |
| +void topy([y, ]) {} |
| +void topxy(x, [y, ]) {} |
| +void topz({z, }) {} |
| +void topxz(x, {z, }) {} |
| + |
| +void set topsetx(x, ) {} |
| + |
| +// After specific parameter formats. |
| +void afterDefaultValueY([int y = 42, ]) {} |
| +void afterDefaultValueZ({int z : 42, }) {} |
| +void afterFunsigX(int f(),) {} |
| +void afterFunsigY([int f(),]) {} |
| +void afterFunsigZ({int f(),}) {} |
| +void afterFunctionSignatre([int f(), ]) {} |
| + |
| +class C { |
| + C(); |
| + |
| + // Constructors. |
| + C.x(x, ); |
| + C.y([y, ]); |
| + C.xy(x, [y, ]); |
| + C.z({z, }); |
| + C.xz(x, {z, }); |
| + |
| + // Static members |
| + static void staticx(x,) {} |
| + static void staticy([y, ]) {} |
| + static void staticxy(x, [y, ]) {} |
| + static void staticz({z, }) {} |
| + static void staticxz(x, {z, }) {} |
| + |
| + static void set staticsetx(x, ) {} |
| + |
| + // Instance members |
| + void instancex(x,) {} |
| + void instancey([y, ]) {} |
| + void instancexy(x, [y, ]) {} |
| + void instancez({z, }) {} |
| + void instancexz(x, {z, }) {} |
| + |
| + void set instancesetx(x, ) {} |
| + |
| + operator +(x, ) => this; |
| + operator []=(x, y, ) {} |
| +} |
| + |
| +main(args, ) { |
| + // Check that all functions can be called normally |
| + topx(x); |
| + topy(y); |
| + topxy(x, y); |
| + topz(); |
| + topz(z: z); |
| + topxz(x); |
| + topxz(x, z: z); |
| + topsetx = x; |
| + afterDefaultValueY(); |
| + afterDefaultValueY(y); |
| + afterDefaultValueZ(); |
| + afterDefaultValueZ(z: z); |
| + new C.x(x); |
| + new C.xy(x); |
| + new C.xy(x, y); |
| + new C.y(y); |
| + new C.xz(x); |
| + new C.xz(x, z: z); |
| + new C.z(z: z); |
| + C.staticx(x); |
| + C.staticy(y); |
| + C.staticxy(x); |
| + C.staticxy(x, y); |
| + C.staticz(); |
| + C.staticz(z: z); |
| + C.staticxz(x); |
| + C.staticxz(x, z: z); |
| + C.staticsetx = x; |
| + c.instancex(x); |
| + c.instancey(); |
| + c.instancey(y); |
| + c.instancexy(x); |
| + c.instancexy(x, y); |
| + c.instancez(); |
| + c.instancez(z: z); |
| + c.instancexz(x); |
| + c.instancexz(x, z: z); |
| + c.instancesetx = x; |
| + c + x; |
| + c[x] = y; |
| + |
| + // Call with ekstra comma (not possible for setters and operators). |
|
hausner
2016/06/22 17:19:41
Dijkstra style comment :-)
Lasse Reichstein Nielsen
2016/06/24 11:50:55
I regret nothing!
|
| + topx(x, ); |
| + topy(y, ); |
| + topxy(x, y, ); |
| + topxy(x, ); |
| + topz(z: z, ); |
| + topxz(x, ); |
| + topxz(x, z: z, ); |
| + new C.x(x, ); |
| + new C.xy(x, y, ); |
| + new C.xy(x, ); |
| + new C.y(y, ); |
| + new C.xz(x, ); |
| + new C.xz(x, z: z, ); |
| + new C.z(z: z, ); |
| + C.staticx(x, ); |
| + C.staticy(y, ); |
| + C.staticxy(x, y, ); |
| + C.staticxy(x, ); |
| + C.staticz(z: z, ); |
| + C.staticxz(x, ); |
| + C.staticxz(x, z: z, ); |
| + c.instancex(x, ); |
| + c.instancey(y, ); |
| + c.instancexy(x, y, ); |
| + c.instancexy(x, ); |
| + c.instancez(z: z, ); |
| + c.instancexz(x, ); |
| + c.instancexz(x, z: z, ); |
| + |
| + // Typedefs work. |
| + if (topx is! fx) throw "Bad type: $fx"; |
| + if (topy is! fy) throw "Bad type: $fy"; |
| + if (topxy is! fxy) throw "Bad type: $fxy"; |
| + if (topz is! fz) throw "Bad type: $fz"; |
| + if (topxz is! fxz) throw "Bad type: $fxz"; |
| + |
| + // Parameter types work (checked mode only test). |
| + argfx(topx); |
| + argfy(topy); |
| + argfxy(topxy); |
| + argfz(topz); |
| + argfxz(topxz); |
| + |
| + // Make sure the Bad class is parsed. |
| + new Bad().method(); |
| +} |
| + |
| + |
| +// Invalid syntax |
| +void topBadEmpty(,) {} /// 01: compile-time error |
|
floitsch
2016/06/22 18:23:38
In theory, you would have a better test, if you on
Lasse Reichstein Nielsen
2016/06/24 11:50:55
True, that would ensure that some other unintended
|
| +void topBadStart(, a) {} /// 02: compile-time error |
| +void topBadEnd(a,,) {} /// 03: compile-time error |
| +void topBadMiddle(a,, b) {} /// 04: compile-time error |
| +void topBadPosEmpty([,]) {} /// 01: compile-time error |
| +void topBadPosStart([, a]) {} /// 02: compile-time error |
| +void topBadPosEnd([a,,]) {} /// 03: compile-time error |
| +void topBadPosMiddle({a,, b}) {} /// 04: compile-time error |
| +void topBadPosEmpty({,}) {} /// 01: compile-time error |
| +void topBadPosStart({, a}) {} /// 02: compile-time error |
| +void topBadPosEnd({a,,}) {} /// 03: compile-time error |
| +void topBadPosMiddle([a,, b]) {} /// 04: compile-time error |
| +void set topSetBadEmpty(,) {} /// 05: compile-time error |
| +void set topSetBadStart(, a) {} /// 06: compile-time error |
| +void set topSetBadEnd(a,,) {} /// 07: compile-time error |
| +void set topSetBadMiddle(a,, b) {} /// 08: compile-time error |
| +class Bad { |
| + Bad.empty(,) {} /// 09: compile-time error |
| + Bad.start(, a) {} /// 10: compile-time error |
| + Bad.end(a,,) {} /// 11: compile-time error |
| + Bad.middle(a,, b) {} /// 12: compile-time error |
| + static staticBadEmpty(,) {} /// 13: compile-time error |
| + static staticBadStart(, a) {} /// 14: compile-time error |
| + static staticBadEnd(a,,) {} /// 15: compile-time error |
| + static staticBadMiddle(a,, b) {} /// 16: compile-time error |
| + static void set staticSetBadEmpty(,) {} /// 17: compile-time error |
| + static void set staticSetBadStart(, a) {} /// 18: compile-time error |
| + static void set staticSetBadEnd(a,,) {} /// 19: compile-time error |
| + static void set staticSetBadMiddle(a,, b) {} /// 20: compile-time error |
| + instanceBadEmpty(,) {} /// 21: compile-time error |
| + instanceBadStart(, a) {} /// 22: compile-time error |
| + instanceBadEnd(a,,) {} /// 23: compile-time error |
| + instanceBadMiddle(a,, b) {} /// 24: compile-time error |
| + void set instanceSetBadEmpty(,) {} /// 25: compile-time error |
| + void set instanceSetBadStart(, a) {} /// 26: compile-time error |
| + void set instanceSetBadEnd(a,,) {} /// 27: compile-time error |
| + void set instanceSetBadMiddle(a,, b) {} /// 28: compile-time error |
| + void operator *(,); /// 29: compile-time error |
| + void operator *(, a); /// 30: compile-time error |
| + void operator *(a,,); /// 31: compile-time error |
| + void operator []=(, a); /// 32: compile-time error |
| + void operator []=(a,,); /// 33: compile-time error |
| + void operator []=(a,, b); /// 34: compile-time error |
| + void operator []=(a,); /// 35: compile-time error |
| + |
| + method() { |
| + // invalid calls. |
| + |
| + topx(,); /// 36: compile-time error |
| + topy(,); /// 37: compile-time error |
| + topz(,); /// 38: compile-time error |
| + topx(, x); /// 39: compile-time error |
| + topz(, z:z); /// 40: compile-time error |
| + topxy(x,, y); /// 41: compile-time error |
| + topxz(x,, z:z); /// 42: compile-time error |
| + topx(x,,); /// 43: compile-time error |
| + topz(z:z,,); /// 44: compile-time error |
| + |
| + new C.x(,); /// 45: compile-time error |
| + new C.y(,); /// 46: compile-time error |
| + new C.z(,); /// 47: compile-time error |
| + new C.x(, x); /// 48: compile-time error |
| + new C.z(, z:z); /// 49: compile-time error |
| + new C.xy(x,, y); /// 50: compile-time error |
| + new C.xz(x,, z:z); /// 51: compile-time error |
| + new C.x(x,,); /// 52: compile-time error |
| + new C.z(z:z,,); /// 53: compile-time error |
| + |
| + C.staticx(,); /// 54: compile-time error |
| + C.staticy(,); /// 55: compile-time error |
| + C.staticz(,); /// 56: compile-time error |
| + C.staticx(, x); /// 57: compile-time error |
| + C.staticz(, z:z); /// 58: compile-time error |
| + C.staticxy(x,, y); /// 59: compile-time error |
| + C.staticxz(x,, z:z); /// 60: compile-time error |
| + C.staticx(x,,); /// 61: compile-time error |
| + C.staticz(z:z,,); /// 62: compile-time error |
| + |
| + c.instancex(,); /// 63: compile-time error |
| + c.instancey(,); /// 64: compile-time error |
| + c.instancez(,); /// 65: compile-time error |
| + c.instancex(, x); /// 66: compile-time error |
| + c.instancez(, z:z); /// 67: compile-time error |
| + c.instancexy(x,, y); /// 68: compile-time error |
| + c.instancexz(x,, z:z); /// 69: compile-time error |
| + c.instancex(x,,); /// 70: compile-time error |
| + c.instancez(z:z,,); /// 71: compile-time error |
| + |
| + c[x,] = y; /// 72: compile-time error |
| + } |
| +} |