Auto-format Framework (#160545)

This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
This commit is contained in:
Michael Goderbauer
2024-12-19 12:06:21 -08:00
committed by GitHub
parent 8e0993eda8
commit 5491c8c146
4411 changed files with 455108 additions and 415991 deletions

View File

@@ -26,34 +26,19 @@ void main() {
});
test('validates base href', () {
expect(
() => PathUrlStrategy(location),
returnsNormally,
);
expect(() => PathUrlStrategy(location), returnsNormally);
location.baseHref = '/foo/';
expect(
() => PathUrlStrategy(location),
returnsNormally,
);
expect(() => PathUrlStrategy(location), returnsNormally);
location.baseHref = '';
expect(
() => PathUrlStrategy(location),
throwsException,
);
expect(() => PathUrlStrategy(location), throwsException);
location.baseHref = 'foo';
expect(
() => PathUrlStrategy(location),
throwsException,
);
expect(() => PathUrlStrategy(location), throwsException);
location.baseHref = '/foo';
expect(
() => PathUrlStrategy(location),
throwsException,
);
expect(() => PathUrlStrategy(location), throwsException);
});
test('leading slash is always prepended', () {
@@ -80,20 +65,23 @@ void main() {
expect(strategy.getPath(), '/bar');
});
test('gets path correctly in the presence of query params and omits fragment if no flag specified', () {
location.baseHref = 'https://example.com/foo/';
location.pathname = '/foo/bar';
final PathUrlStrategy strategy = PathUrlStrategy(location);
test(
'gets path correctly in the presence of query params and omits fragment if no flag specified',
() {
location.baseHref = 'https://example.com/foo/';
location.pathname = '/foo/bar';
final PathUrlStrategy strategy = PathUrlStrategy(location);
location.search = '?q=1';
expect(strategy.getPath(), '/bar?q=1');
location.search = '?q=1';
expect(strategy.getPath(), '/bar?q=1');
location.search = '?q=1&t=r';
expect(strategy.getPath(), '/bar?q=1&t=r');
location.search = '?q=1&t=r';
expect(strategy.getPath(), '/bar?q=1&t=r');
location.hash = '#fragment=1';
expect(strategy.getPath(), '/bar?q=1&t=r');
});
location.hash = '#fragment=1';
expect(strategy.getPath(), '/bar?q=1&t=r');
},
);
test('gets path correctly in the presence of query params and fragment', () {
location.baseHref = 'https://example.com/foo/';

View File

@@ -24,14 +24,12 @@ void main() {
test('can send events to an $EventChannel (deprecated API)', () async {
const EventChannel listeningChannel = EventChannel('test');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test');
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test');
final StreamController<String> controller = StreamController<String>();
sendingChannel.setController(controller);
expect(listeningChannel.receiveBroadcastStream(),
emitsInOrder(<String>['hello', 'world']));
expect(listeningChannel.receiveBroadcastStream(), emitsInOrder(<String>['hello', 'world']));
controller.add('hello');
controller.add('world');
@@ -40,14 +38,12 @@ void main() {
test('can send events to an $EventChannel', () async {
const EventChannel listeningChannel = EventChannel('test');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test');
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test');
final StreamController<String> controller = StreamController<String>();
sendingChannel.setController(controller);
expect(listeningChannel.receiveBroadcastStream(),
emitsInOrder(<String>['hello', 'world']));
expect(listeningChannel.receiveBroadcastStream(), emitsInOrder(<String>['hello', 'world']));
controller.add('hello');
controller.add('world');
@@ -56,16 +52,17 @@ void main() {
test('can send errors to an $EventChannel (deprecated API)', () async {
const EventChannel listeningChannel = EventChannel('test2');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test2');
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test2');
final StreamController<String> controller = StreamController<String>();
sendingChannel.setController(controller);
expect(
listeningChannel.receiveBroadcastStream(),
emitsError(predicate<dynamic>((dynamic e) =>
e is PlatformException && e.message == 'Test error')));
listeningChannel.receiveBroadcastStream(),
emitsError(
predicate<dynamic>((dynamic e) => e is PlatformException && e.message == 'Test error'),
),
);
controller.addError('Test error');
await controller.close();
@@ -73,16 +70,17 @@ void main() {
test('can send errors to an $EventChannel', () async {
const EventChannel listeningChannel = EventChannel('test2');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test2');
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test2');
final StreamController<String> controller = StreamController<String>();
sendingChannel.setController(controller);
expect(
listeningChannel.receiveBroadcastStream(),
emitsError(predicate<dynamic>((dynamic e) =>
e is PlatformException && e.message == 'Test error')));
listeningChannel.receiveBroadcastStream(),
emitsError(
predicate<dynamic>((dynamic e) => e is PlatformException && e.message == 'Test error'),
),
);
controller.addError('Test error');
await controller.close();
@@ -90,15 +88,14 @@ void main() {
test('receives a listen event (deprecated API)', () async {
const EventChannel listeningChannel = EventChannel('test3');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test3');
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test3');
final StreamController<String> controller = StreamController<String>(
onListen: expectAsync0<void>(() {}));
onListen: expectAsync0<void>(() {}),
);
sendingChannel.setController(controller);
expect(listeningChannel.receiveBroadcastStream(),
emitsInOrder(<String>['hello']));
expect(listeningChannel.receiveBroadcastStream(), emitsInOrder(<String>['hello']));
controller.add('hello');
await controller.close();
@@ -106,15 +103,14 @@ void main() {
test('receives a listen event', () async {
const EventChannel listeningChannel = EventChannel('test3');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test3');
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test3');
final StreamController<String> controller = StreamController<String>(
onListen: expectAsync0<void>(() {}));
onListen: expectAsync0<void>(() {}),
);
sendingChannel.setController(controller);
expect(listeningChannel.receiveBroadcastStream(),
emitsInOrder(<String>['hello']));
expect(listeningChannel.receiveBroadcastStream(), emitsInOrder(<String>['hello']));
controller.add('hello');
await controller.close();
@@ -122,42 +118,42 @@ void main() {
test('receives a cancel event (deprecated API)', () async {
const EventChannel listeningChannel = EventChannel('test4');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test4');
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test4');
final StreamController<String> controller =
StreamController<String>(onCancel: expectAsync0<void>(() {}));
final StreamController<String> controller = StreamController<String>(
onCancel: expectAsync0<void>(() {}),
);
sendingChannel.setController(controller);
final Stream<dynamic> eventStream =
listeningChannel.receiveBroadcastStream();
final Stream<dynamic> eventStream = listeningChannel.receiveBroadcastStream();
late StreamSubscription<dynamic> subscription;
subscription =
eventStream.listen(expectAsync1<void, dynamic>((dynamic x) {
expect(x, equals('hello'));
subscription.cancel();
}));
subscription = eventStream.listen(
expectAsync1<void, dynamic>((dynamic x) {
expect(x, equals('hello'));
subscription.cancel();
}),
);
controller.add('hello');
});
test('receives a cancel event', () async {
const EventChannel listeningChannel = EventChannel('test4');
const PluginEventChannel<String> sendingChannel =
PluginEventChannel<String>('test4');
const PluginEventChannel<String> sendingChannel = PluginEventChannel<String>('test4');
final StreamController<String> controller =
StreamController<String>(onCancel: expectAsync0<void>(() {}));
final StreamController<String> controller = StreamController<String>(
onCancel: expectAsync0<void>(() {}),
);
sendingChannel.setController(controller);
final Stream<dynamic> eventStream =
listeningChannel.receiveBroadcastStream();
final Stream<dynamic> eventStream = listeningChannel.receiveBroadcastStream();
late StreamSubscription<dynamic> subscription;
subscription =
eventStream.listen(expectAsync1<void, dynamic>((dynamic x) {
expect(x, equals('hello'));
subscription.cancel();
}));
subscription = eventStream.listen(
expectAsync1<void, dynamic>((dynamic x) {
expect(x, equals('hello'));
subscription.cancel();
}),
);
controller.add('hello');
});

View File

@@ -44,8 +44,7 @@ void main() {
test('can register a plugin', () {
TestPlugin.calledMethods.clear();
const MethodChannel frameworkChannel =
MethodChannel('test_plugin');
const MethodChannel frameworkChannel = MethodChannel('test_plugin');
frameworkChannel.invokeMethod<void>('test1');
expect(TestPlugin.calledMethods, equals(<String>['test1']));
@@ -55,22 +54,20 @@ void main() {
const StandardMessageCodec codec = StandardMessageCodec();
final List<String> loggedMessages = <String>[];
ServicesBinding.instance.defaultBinaryMessenger
.setMessageHandler('test_send', (ByteData? data) {
ServicesBinding.instance.defaultBinaryMessenger.setMessageHandler('test_send', (
ByteData? data,
) {
loggedMessages.add(codec.decodeMessage(data)! as String);
return Future<ByteData?>.value();
});
await pluginBinaryMessenger.send(
'test_send', codec.encodeMessage('hello'));
await pluginBinaryMessenger.send('test_send', codec.encodeMessage('hello'));
expect(loggedMessages, equals(<String>['hello']));
await pluginBinaryMessenger.send(
'test_send', codec.encodeMessage('world'));
await pluginBinaryMessenger.send('test_send', codec.encodeMessage('world'));
expect(loggedMessages, equals(<String>['hello', 'world']));
ServicesBinding.instance.defaultBinaryMessenger
.setMessageHandler('test_send', null);
ServicesBinding.instance.defaultBinaryMessenger.setMessageHandler('test_send', null);
});
});
}