mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:27:17 +00:00
b2281e14f3
In these tests I've tried to test a lot of the corner cases surrounding the addition of a `<type arguments>` selector to the grammar (which we intend to do as part of constructor tearoffs), to make sure that when we do so, we don't break any existing functionality. Change-Id: I765195cdd3745904f4aeb36663f59afe03381ab8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/200001 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
59 lines
2.4 KiB
Dart
59 lines
2.4 KiB
Dart
// Copyright (c) 2021, 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.
|
|
|
|
// This test verifies that `EXPR<typeArguments>(arguments)` is properly parsed
|
|
// as a generic invocation, for all types of expressions that may appear as
|
|
// EXPR. We try to pay extra attention to ambiguous expressions (that is, where
|
|
// interpreting the `<` and `>` as operators would also have led to a valid
|
|
// parse).
|
|
|
|
import '../syntax_helper.dart';
|
|
|
|
class C extends SyntaxTracker {
|
|
C([Object? x = absent, Object? y = absent])
|
|
: super('new C${SyntaxTracker.args(x, y)}');
|
|
|
|
C.syntax(String s) : super(s);
|
|
}
|
|
|
|
class ThisTest extends C {
|
|
ThisTest() : super.syntax('this');
|
|
|
|
void test() {
|
|
checkSyntax(f(this<C, C>(0)), 'f(this<C, C>(0))');
|
|
// Note: SyntaxTracker can't see the parens around `this` in the line below
|
|
checkSyntax(f((this)<C, C>(0)), 'f(this<C, C>(0))');
|
|
}
|
|
}
|
|
|
|
main() {
|
|
SyntaxTracker.known[C] = 'C';
|
|
SyntaxTracker.known[#x] = '#x';
|
|
checkSyntax(f(f<C, C>(0)), 'f(f<C, C>(0))');
|
|
checkSyntax(f(x.method<C, C>(0)), 'f(x.method<C, C>(0))');
|
|
checkSyntax(f(C()<C, C>(0)), 'f(new C()<C, C>(0))');
|
|
checkSyntax(f(new C()<C, C>(0)), 'f(new C()<C, C>(0))');
|
|
checkSyntax(f(f()<C, C>(0)), 'f(f()<C, C>(0))');
|
|
checkSyntax(f(x.method()<C, C>(0)), 'f(x.method()<C, C>(0))');
|
|
checkSyntax(f(x[0]()<C, C>(0)), 'f(x[0]()<C, C>(0))');
|
|
checkSyntax(f(#x<C, C>(0)), 'f(#x<C, C>(0))');
|
|
checkSyntax(f(null<C, C>(0)), 'f(null<C, C>(0))');
|
|
checkSyntax(f(0<C, C>(0)), 'f(0<C, C>(0))');
|
|
checkSyntax(f(0.5<C, C>(0)), 'f(0.5<C, C>(0))');
|
|
checkSyntax(f([]<C, C>(0)), 'f([]<C, C>(0))');
|
|
checkSyntax(f([0]<C, C>(0)), 'f([0]<C, C>(0))');
|
|
checkSyntax(f({}<C, C>(0)), 'f({}<C, C>(0))');
|
|
checkSyntax(f({0}<C, C>(0)), 'f({0}<C, C>(0))');
|
|
checkSyntax(f({0: 0}<C, C>(0)), 'f({ 0: 0 }<C, C>(0))');
|
|
checkSyntax(f(true<C, C>(0)), 'f(true<C, C>(0))');
|
|
checkSyntax(f("s"<C, C>(0)), 'f("s"<C, C>(0))');
|
|
checkSyntax(f(r"s"<C, C>(0)), 'f("s"<C, C>(0))');
|
|
checkSyntax(f(x[0]<C, C>(0)), 'f(x[0]<C, C>(0))');
|
|
// Note: SyntaxTracker can't see the `!` in the line below
|
|
checkSyntax(f(x!<C, C>(0)), 'f(x<C, C>(0))');
|
|
// Note: SyntaxTracker can't see the parens around `x` in the line below
|
|
checkSyntax(f((x)<C, C>(0)), 'f(x<C, C>(0))');
|
|
ThisTest().test();
|
|
}
|