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>
89 lines
4.1 KiB
Dart
89 lines
4.1 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<a,b>-x` is properly parsed as a pair of
|
|
// expressions separated by a `,`, for all types of expressions that may appear
|
|
// as EXPR. We try to pay extra attention to expressions that will become
|
|
// ambiguous when the "constructor tearoffs" feature is enabled (that is, where
|
|
// interpreting the `<` and `>` as delimiting a list of type arguments 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);
|
|
|
|
Object? operator <(Object? other) =>
|
|
SyntaxTracker('(${syntax(this)} < ${syntax(other)})');
|
|
}
|
|
|
|
class ThisTest extends C {
|
|
ThisTest() : super.syntax('this');
|
|
|
|
void test() {
|
|
checkSyntax(f(this < C, C > -x), 'f((this < C), (C > (-x)))');
|
|
// Note: SyntaxTracker can't see the parens around `this` in the line below
|
|
checkSyntax(f((this) < C, C > -x), 'f((this < C), (C > (-x)))');
|
|
}
|
|
}
|
|
|
|
class SuperTest extends C {
|
|
SuperTest() : super.syntax('super');
|
|
|
|
void test() {
|
|
checkSyntax(f(super < C, C > -x), 'f((super < C), (C > (-x)))');
|
|
}
|
|
}
|
|
|
|
main() {
|
|
const y = 123;
|
|
SyntaxTracker.known[C] = 'C';
|
|
SyntaxTracker.known[#x] = '#x';
|
|
SyntaxTracker.known[y] = 'y';
|
|
checkSyntax(f(x < C, C > -x), 'f((x < C), (C > (-x)))');
|
|
checkSyntax(f(x.getter < C, C > -x), 'f((x.getter < C), (C > (-x)))');
|
|
checkSyntax(f(C() < C, C > -x), 'f((new C() < C), (C > (-x)))');
|
|
checkSyntax(f(new C() < C, C > -x), 'f((new C() < C), (C > (-x)))');
|
|
checkSyntax(f(f() < C, C > -x), 'f((f() < C), (C > (-x)))');
|
|
checkSyntax(f(x.method() < C, C > -x), 'f((x.method() < C), (C > (-x)))');
|
|
checkSyntax(f(x[0]() < C, C > -x), 'f((x[0]() < C), (C > (-x)))');
|
|
checkSyntax(f(#x < C, C > -x), 'f((#x < C), (C > (-x)))');
|
|
checkSyntax(f(null < C, C > -x), 'f((null < C), (C > (-x)))');
|
|
checkSyntax(f(0 < y, C > -x), 'f(true, (C > (-x)))');
|
|
checkSyntax(f(0.5 < y, C > -x), 'f(true, (C > (-x)))');
|
|
checkSyntax(f([] < C, C > -x), 'f(([] < C), (C > (-x)))');
|
|
checkSyntax(f([0] < C, C > -x), 'f(([0] < C), (C > (-x)))');
|
|
checkSyntax(f({} < C, C > -x), 'f(({} < C), (C > (-x)))');
|
|
checkSyntax(f({0} < C, C > -x), 'f(({0} < C), (C > (-x)))');
|
|
checkSyntax(f({0: 0} < C, C > -x), 'f(({ 0: 0 } < C), (C > (-x)))');
|
|
checkSyntax(f(true < C, C > -x), 'f((true < C), (C > (-x)))');
|
|
checkSyntax(f("s" < C, C > -x), 'f(("s" < C), (C > (-x)))');
|
|
checkSyntax(f(r"s" < C, C > -x), 'f(("s" < C), (C > (-x)))');
|
|
checkSyntax(f(x[0] < C, C > -x), 'f((x[0] < C), (C > (-x)))');
|
|
// Note: SyntaxTracker can't see the `!` in the line below
|
|
checkSyntax(f(x! < C, C > -x), 'f((x < C), (C > (-x)))');
|
|
// Note: SyntaxTracker can't see the parens around `x` in the line below
|
|
checkSyntax(f((x) < C, C > -x), 'f((x < C), (C > (-x)))');
|
|
checkSyntax(f(-x < C, C > -x), 'f(((-x) < C), (C > (-x)))');
|
|
checkSyntax(f(!true < C, C > -x), 'f((false < C), (C > (-x)))');
|
|
checkSyntax(f(!(true) < C, C > -x), 'f((false < C), (C > (-x)))');
|
|
checkSyntax(f(~x < C, C > -x), 'f(((~x) < C), (C > (-x)))');
|
|
checkSyntax(f(x * x < C, C > -x), 'f(((x * x) < C), (C > (-x)))');
|
|
checkSyntax(f(x / x < C, C > -x), 'f(((x / x) < C), (C > (-x)))');
|
|
checkSyntax(f(x ~/ x < C, C > -x), 'f(((x ~/ x) < C), (C > (-x)))');
|
|
checkSyntax(f(x % x < C, C > -x), 'f(((x % x) < C), (C > (-x)))');
|
|
checkSyntax(f(x + x < C, C > -x), 'f(((x + x) < C), (C > (-x)))');
|
|
checkSyntax(f(x - x < C, C > -x), 'f(((x - x) < C), (C > (-x)))');
|
|
checkSyntax(f(x << x < C, C > -x), 'f(((x << x) < C), (C > (-x)))');
|
|
checkSyntax(f(x >> x < C, C > -x), 'f(((x >> x) < C), (C > (-x)))');
|
|
checkSyntax(f(x & x < C, C > -x), 'f(((x & x) < C), (C > (-x)))');
|
|
checkSyntax(f(x ^ x < C, C > -x), 'f(((x ^ x) < C), (C > (-x)))');
|
|
checkSyntax(f(x | x < C, C > -x), 'f(((x | x) < C), (C > (-x)))');
|
|
ThisTest().test();
|
|
SuperTest().test();
|
|
}
|