Skip to content

Add smoke tests for function as type parameter and triple-shift #2603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Apr 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ecdf57f
beginning
jcollins-g Mar 18, 2021
5b22cd6
Merge branch 'master' into generic-metadata
jcollins-g Mar 18, 2021
f97ad5b
Merge branch 'master' into generic-metadata
jcollins-g Mar 19, 2021
eb67fc0
first test
jcollins-g Mar 22, 2021
125db39
test
jcollins-g Mar 22, 2021
dd354f5
begin extracting annotation
jcollins-g Mar 23, 2021
dbbe68d
dartfmt, comment
jcollins-g Mar 23, 2021
c7f64f6
Update skip
jcollins-g Mar 25, 2021
ee347a9
Merge branch 'master' into generic-metadata
jcollins-g Mar 30, 2021
d135ed4
Rebuild renderers
jcollins-g Mar 30, 2021
8ac15c7
Beginning feature refactor
jcollins-g Mar 30, 2021
1c35db9
Getting there
jcollins-g Mar 30, 2021
065ab93
obliterate strings
jcollins-g Mar 30, 2021
c4eac77
Final cleanups
jcollins-g Mar 30, 2021
d5ba425
Bypass @Native crashing us in flutter
jcollins-g Mar 31, 2021
4a295ef
Restrict ast import
jcollins-g Mar 31, 2021
6af13c4
Expand feature rendering out and get span classes fixed in parameters
jcollins-g Apr 1, 2021
525a9fa
dartfmt
jcollins-g Apr 1, 2021
89e4e1d
Very basic tests
jcollins-g Apr 1, 2021
06066db
Merge branch 'master' into generic-metadata+refactor-feature
jcollins-g Apr 2, 2021
77dafb7
review comments
jcollins-g Apr 2, 2021
223d19c
Merge branch 'generic-metadata+refactor-feature' into minor-features
jcollins-g Apr 2, 2021
eb7c31b
Add tests for triple-shift
jcollins-g Apr 2, 2021
32c2a0d
Merge branch 'master' into generic-metadata+refactor-feature
jcollins-g Apr 2, 2021
c2d3384
Merge branch 'generic-metadata+refactor-feature' into minor-features
jcollins-g Apr 2, 2021
9c05ab7
Merge branch 'minor-features' into minor-features+triple_shift
jcollins-g Apr 2, 2021
8624b29
dartfmt
jcollins-g Apr 2, 2021
0d2423a
Add skip outside 2.13
jcollins-g Apr 2, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions test/end2end/model_special_cases_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,60 @@ void main() {
VersionRange(min: Version.parse('2.13.0-0'), includeMin: true);
final _genericMetadataAllowed =
VersionRange(min: Version.parse('2.13.0-0'), includeMin: true);
final _tripleShiftAllowed =
VersionRange(min: Version.parse('2.13.0-0'), includeMin: true);

// Experimental features not yet enabled by default. Move tests out of this
// block when the feature is enabled by default.
group('Experiments', () {
group('triple-shift', () {
Library tripleShift;
Class C, E, F;
Extension ShiftIt;
Operator classShift, extensionShift;
Field constantTripleShifted;

setUpAll(() async {
tripleShift = (await _testPackageGraphExperiments)
.libraries
.firstWhere((l) => l.name == 'triple_shift');
C = tripleShift.classes.firstWhere((c) => c.name == 'C');
E = tripleShift.classes.firstWhere((c) => c.name == 'E');
F = tripleShift.classes.firstWhere((c) => c.name == 'F');
ShiftIt = tripleShift.extensions.firstWhere((e) => e.name == 'ShiftIt');
classShift =
C.instanceOperators.firstWhere((o) => o.name.contains('>>>'));
extensionShift =
ShiftIt.instanceOperators.firstWhere((o) => o.name.contains('>>>'));
constantTripleShifted = C.constantFields
.firstWhere((f) => f.name == 'constantTripleShifted');
});

test('constants with triple shift render correctly', () {
expect(constantTripleShifted.constantValue, equals('3 >>> 5'));
});

test('operators exist and are named correctly', () {
expect(classShift.name, equals('operator >>>'));
expect(extensionShift.name, equals('operator >>>'));
});

test(
'inheritance and overriding of triple shift operators works correctly',
() {
var tripleShiftE =
E.instanceOperators.firstWhere((o) => o.name.contains('>>>'));
var tripleShiftF =
F.instanceOperators.firstWhere((o) => o.name.contains('>>>'));

expect(tripleShiftE.isInherited, isTrue);
expect(tripleShiftE.canonicalModelElement, equals(classShift));
expect(tripleShiftE.modelType.returnType.name, equals('C'));
expect(tripleShiftF.isInherited, isFalse);
expect(tripleShiftF.modelType.returnType.name, equals('F'));
});
}, skip: !_tripleShiftAllowed.allows(_platformVersion));

group('generic metadata', () {
Library genericMetadata;
TopLevelVariable f;
Expand Down
1 change: 1 addition & 0 deletions testing/test_package_experiments/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ analyzer:
enable-experiment:
- non-nullable
- nonfunction-type-aliases
- triple-shift
- generic-metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.

/// Tests for verifying generic functions as type arguments.
library generic_function_type_args;

late List<T Function<T>(T)> idFunctions;
late S Function<S extends T Function<T>(T)>(S) ff;

typedef F = T Function<T>(T);

class C<T> {
final T value;
const C(this.value);
}

T f<T>(T value) => value;

extension E<T> on T {
T get extensionValue => this;
}

// A generic function type can be a type parameter bound.

// For a type alias:
typedef FB<T extends F> = S Function<S extends T>(S);

// For a class:
class CB<T extends FB<F>> {
final T function;
const CB(this.function);
}

// For a function:
T fb<T extends F>(T value) => value;

extension EB<T extends F> on T {
T get boundExtensionValue => this;

// Any function type has a `call` of its own type?
T get boundCall => this.call;
}

// Can be used as arguments to metadata too.
@C<F>(f)
@CB<FB<F>>(fb)
void main() {}
42 changes: 42 additions & 0 deletions testing/test_package_experiments/lib/triple_shift.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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.

/// Tests for verifying triple_shift operator, borrowed from the SDK.
library triple_shift;

class C {
static int ctr = 0;

/// Check that constants using a triple shift operator appear correctly.
static const int constantTripleShifted = 3>>>5;
final Object? _text;
C([Object? text]) : _text = text ?? "${++ctr}";

// It's possible to declare a `>>>` operator.
C operator >>>(arg) => C("(${++ctr}:$_text>>>$arg)");

// + binds more strongly than `>>`, `>>>` and `<<`.
C operator +(arg) => C("(${++ctr}:$_text+$arg)");
// Both `>>` and `<<` binds exactly as strongly as `>>>`.
C operator >>(arg) => C("(${++ctr}:$_text>>$arg)");
C operator <<(arg) => C("(${++ctr}:$_text<<$arg)");
// & binds less strongly than `>>`, `>>>` and `<<`.
C operator &(arg) => C("(${++ctr}:$_text&$arg)");

String toString() => "${_text}";
}

class _D extends C {}

class E extends _D {}

class F extends E {
@override
F operator >>>(arg) => F();
}

// Valid in extensions too.
extension ShiftIt<T> on T {
List<T> operator >>>(int count) => List<T>.filled(count, this);
}