Skip to content

Commit 129e08c

Browse files
authored
[pigeon] Run swift-format on ungenerated example app Swift files (flutter#5934)
Run `swift-format` linter/formatter on Swift files in example apps. This only touches Swift files in example/test code. This also doesn't format any autogenerated Swift files, which would require changed in the pigeon generator: flutter#141799 Part of turning on swift-format CI formatting flutter/packages#5928
1 parent 9379e4a commit 129e08c

19 files changed

+493
-388
lines changed

packages/pigeon/example/README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,14 @@ private class PigeonApiImplementation: ExampleHostApi {
127127
}
128128

129129
func add(_ a: Int64, to b: Int64) throws -> Int64 {
130-
if (a < 0 || b < 0) {
131-
throw FlutterError(code: "code", message: "message", details: "details");
130+
if a < 0 || b < 0 {
131+
throw FlutterError(code: "code", message: "message", details: "details")
132132
}
133133
return a + b
134134
}
135135

136136
func sendMessage(message: MessageData, completion: @escaping (Result<Bool, Error>) -> Void) {
137-
if (message.code == Code.one) {
137+
if message.code == Code.one {
138138
completion(.failure(FlutterError(code: "code", message: "message", details: "details")))
139139
return
140140
}
@@ -237,7 +237,9 @@ private class PigeonFlutterApi {
237237
flutterAPI = MessageFlutterApi(binaryMessenger: binaryMessenger)
238238
}
239239

240-
func callFlutterMethod(aString aStringArg: String?, completion: @escaping (Result<String, Error>) -> Void) {
240+
func callFlutterMethod(
241+
aString aStringArg: String?, completion: @escaping (Result<String, Error>) -> Void
242+
) {
241243
flutterAPI.flutterMethod(aString: aStringArg) {
242244
completion(.success($0))
243245
}

packages/pigeon/example/app/ios/Runner/AppDelegate.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ private class PigeonApiImplementation: ExampleHostApi {
1515
}
1616

1717
func add(_ a: Int64, to b: Int64) throws -> Int64 {
18-
if (a < 0 || b < 0) {
19-
throw FlutterError(code: "code", message: "message", details: "details");
18+
if a < 0 || b < 0 {
19+
throw FlutterError(code: "code", message: "message", details: "details")
2020
}
2121
return a + b
2222
}
2323

2424
func sendMessage(message: MessageData, completion: @escaping (Result<Bool, Error>) -> Void) {
25-
if (message.code == Code.one) {
25+
if message.code == Code.one {
2626
completion(.failure(FlutterError(code: "code", message: "message", details: "details")))
2727
return
2828
}
@@ -39,7 +39,9 @@ private class PigeonFlutterApi {
3939
flutterAPI = MessageFlutterApi(binaryMessenger: binaryMessenger)
4040
}
4141

42-
func callFlutterMethod(aString aStringArg: String?, completion: @escaping (Result<String, Error>) -> Void) {
42+
func callFlutterMethod(
43+
aString aStringArg: String?, completion: @escaping (Result<String, Error>) -> Void
44+
) {
4345
flutterAPI.flutterMethod(aString: aStringArg) {
4446
completion(.success($0))
4547
}

packages/pigeon/platform_tests/alternate_language_test_plugin/example/macos/RunnerTests/RunnerTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import FlutterMacOS
65
import Cocoa
6+
import FlutterMacOS
77
import XCTest
88

99
@testable import alternate_language_test_plugin

packages/pigeon/platform_tests/test_plugin/example/ios/Runner/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import UIKit
65
import Flutter
6+
import UIKit
77

88
@UIApplicationMain
99
@objc class AppDelegate: FlutterAppDelegate {

packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AllDatatypesTests.swift

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import Flutter
66
import XCTest
7+
78
@testable import test_plugin
89

910
class AllDatatypesTests: XCTestCase {
@@ -17,25 +18,25 @@ class AllDatatypesTests: XCTestCase {
1718

1819
api.echoNullable(everything) { result in
1920
switch result {
20-
case .success(let res) :
21-
XCTAssertNotNil(res)
22-
XCTAssertNil(res!.aNullableBool)
23-
XCTAssertNil(res!.aNullableInt)
24-
XCTAssertNil(res!.aNullableDouble)
25-
XCTAssertNil(res!.aNullableString)
26-
XCTAssertNil(res!.aNullableByteArray)
27-
XCTAssertNil(res!.aNullable4ByteArray)
28-
XCTAssertNil(res!.aNullable8ByteArray)
29-
XCTAssertNil(res!.aNullableFloatArray)
30-
XCTAssertNil(res!.aNullableList)
31-
XCTAssertNil(res!.aNullableMap)
32-
XCTAssertNil(res!.nullableNestedList)
33-
XCTAssertNil(res!.nullableMapWithAnnotations)
34-
XCTAssertNil(res!.nullableMapWithObject)
35-
expectation.fulfill()
36-
case .failure(_) :
37-
return
38-
21+
case .success(let res):
22+
XCTAssertNotNil(res)
23+
XCTAssertNil(res!.aNullableBool)
24+
XCTAssertNil(res!.aNullableInt)
25+
XCTAssertNil(res!.aNullableDouble)
26+
XCTAssertNil(res!.aNullableString)
27+
XCTAssertNil(res!.aNullableByteArray)
28+
XCTAssertNil(res!.aNullable4ByteArray)
29+
XCTAssertNil(res!.aNullable8ByteArray)
30+
XCTAssertNil(res!.aNullableFloatArray)
31+
XCTAssertNil(res!.aNullableList)
32+
XCTAssertNil(res!.aNullableMap)
33+
XCTAssertNil(res!.nullableNestedList)
34+
XCTAssertNil(res!.nullableMapWithAnnotations)
35+
XCTAssertNil(res!.nullableMapWithObject)
36+
expectation.fulfill()
37+
case .failure(_):
38+
return
39+
3940
}
4041
}
4142

@@ -55,36 +56,36 @@ class AllDatatypesTests: XCTestCase {
5556
aNullableMap: ["hello": 1234],
5657
nullableNestedList: [[true, false], [true]],
5758
nullableMapWithAnnotations: ["hello": "world"],
58-
nullableMapWithObject: ["hello": 1234, "goodbye" : "world"],
59+
nullableMapWithObject: ["hello": 1234, "goodbye": "world"],
5960
aNullableString: "123"
6061
)
61-
62+
6263
let binaryMessenger = EchoBinaryMessenger(codec: FlutterIntegrationCoreApiCodec.shared)
6364
let api = FlutterIntegrationCoreApi(binaryMessenger: binaryMessenger)
6465

6566
let expectation = XCTestExpectation(description: "callback")
6667

6768
api.echoNullable(everything) { result in
68-
switch result {
69-
case .success(let res) :
70-
XCTAssertNotNil(res)
71-
XCTAssertEqual(res!.aNullableBool, everything.aNullableBool)
72-
XCTAssertEqual(res!.aNullableInt, everything.aNullableInt)
73-
XCTAssertEqual(res!.aNullableDouble, everything.aNullableDouble)
74-
XCTAssertEqual(res!.aNullableString, everything.aNullableString)
75-
XCTAssertEqual(res!.aNullableByteArray, everything.aNullableByteArray)
76-
XCTAssertEqual(res!.aNullable4ByteArray, everything.aNullable4ByteArray)
77-
XCTAssertEqual(res!.aNullable8ByteArray, everything.aNullable8ByteArray)
78-
XCTAssertEqual(res!.aNullableFloatArray, everything.aNullableFloatArray)
79-
XCTAssert(equalsList(res!.aNullableList, everything.aNullableList))
80-
XCTAssert(equalsDictionary(res!.aNullableMap, everything.aNullableMap))
81-
XCTAssertEqual(res!.nullableNestedList, everything.nullableNestedList)
82-
XCTAssertEqual(res!.nullableMapWithAnnotations, everything.nullableMapWithAnnotations)
83-
XCTAssert(equalsDictionary(res!.nullableMapWithObject, everything.nullableMapWithObject))
84-
expectation.fulfill()
85-
return
86-
case .failure(_) :
87-
return
69+
switch result {
70+
case .success(let res):
71+
XCTAssertNotNil(res)
72+
XCTAssertEqual(res!.aNullableBool, everything.aNullableBool)
73+
XCTAssertEqual(res!.aNullableInt, everything.aNullableInt)
74+
XCTAssertEqual(res!.aNullableDouble, everything.aNullableDouble)
75+
XCTAssertEqual(res!.aNullableString, everything.aNullableString)
76+
XCTAssertEqual(res!.aNullableByteArray, everything.aNullableByteArray)
77+
XCTAssertEqual(res!.aNullable4ByteArray, everything.aNullable4ByteArray)
78+
XCTAssertEqual(res!.aNullable8ByteArray, everything.aNullable8ByteArray)
79+
XCTAssertEqual(res!.aNullableFloatArray, everything.aNullableFloatArray)
80+
XCTAssert(equalsList(res!.aNullableList, everything.aNullableList))
81+
XCTAssert(equalsDictionary(res!.aNullableMap, everything.aNullableMap))
82+
XCTAssertEqual(res!.nullableNestedList, everything.nullableNestedList)
83+
XCTAssertEqual(res!.nullableMapWithAnnotations, everything.nullableMapWithAnnotations)
84+
XCTAssert(equalsDictionary(res!.nullableMapWithObject, everything.nullableMapWithObject))
85+
expectation.fulfill()
86+
return
87+
case .failure(_):
88+
return
8889
}
8990
}
9091
wait(for: [expectation], timeout: 1.0)

packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/AsyncHandlersTest.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44
import Flutter
55
import XCTest
6+
67
@testable import test_plugin
78

89
class MockHostSmallApi: HostSmallApi {
@@ -27,20 +28,21 @@ class AsyncHandlersTest: XCTestCase {
2728

2829
let expectation = XCTestExpectation(description: "callback")
2930
flutterApi.echo(value) { result in
30-
switch result {
31-
case .success(let res) :
32-
XCTAssertEqual(res, value)
33-
expectation.fulfill()
34-
case .failure(_) :
35-
return
31+
switch result {
32+
case .success(let res):
33+
XCTAssertEqual(res, value)
34+
expectation.fulfill()
35+
case .failure(_):
36+
return
3637
}
3738

3839
}
3940
wait(for: [expectation], timeout: 1.0)
4041
}
4142

4243
func testAsyncFlutter2HostVoidVoid() throws {
43-
let binaryMessenger = MockBinaryMessenger<String>(codec: FlutterStandardMessageCodec.sharedInstance())
44+
let binaryMessenger = MockBinaryMessenger<String>(
45+
codec: FlutterStandardMessageCodec.sharedInstance())
4446
let mockHostSmallApi = MockHostSmallApi()
4547
HostSmallApiSetup.setUp(binaryMessenger: binaryMessenger, api: mockHostSmallApi)
4648
let channelName = "dev.flutter.pigeon.pigeon_integration_tests.HostSmallApi.voidVoid"
@@ -49,14 +51,15 @@ class AsyncHandlersTest: XCTestCase {
4951
let expectation = XCTestExpectation(description: "voidvoid callback")
5052
binaryMessenger.handlers[channelName]?(nil) { data in
5153
let outputList = binaryMessenger.codec.decode(data) as? [Any]
52-
XCTAssertEqual(outputList?.first as! NSNull, NSNull())
54+
XCTAssertEqual(outputList?.first as! NSNull, NSNull())
5355
expectation.fulfill()
5456
}
5557
wait(for: [expectation], timeout: 1.0)
5658
}
5759

5860
func testAsyncFlutter2Host() throws {
59-
let binaryMessenger = MockBinaryMessenger<String>(codec: FlutterStandardMessageCodec.sharedInstance())
61+
let binaryMessenger = MockBinaryMessenger<String>(
62+
codec: FlutterStandardMessageCodec.sharedInstance())
6063
let mockHostSmallApi = MockHostSmallApi()
6164
let value = "Test"
6265
mockHostSmallApi.output = value
@@ -69,7 +72,7 @@ class AsyncHandlersTest: XCTestCase {
6972
let expectation = XCTestExpectation(description: "echo callback")
7073
binaryMessenger.handlers[channelName]?(inputEncoded) { data in
7174
let outputList = binaryMessenger.codec.decode(data) as? [Any]
72-
let output = outputList?.first as? String
75+
let output = outputList?.first as? String
7376
XCTAssertEqual(output, value)
7477
expectation.fulfill()
7578
}

packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/EchoBinaryMessenger.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,30 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
import Foundation
65
import Flutter
6+
import Foundation
77

88
class EchoBinaryMessenger: NSObject, FlutterBinaryMessenger {
99
let codec: FlutterMessageCodec
1010
private(set) var count = 0
1111
var defaultReturn: Any?
12-
12+
1313
init(codec: FlutterMessageCodec) {
1414
self.codec = codec
1515
super.init()
1616
}
17-
17+
1818
func send(onChannel channel: String, message: Data?) {
1919
// Method not implemented because this messenger is just for echoing
2020
}
21-
21+
2222
func send(
2323
onChannel channel: String,
2424
message: Data?,
2525
binaryReply callback: FlutterBinaryReply? = nil
2626
) {
2727
guard let callback = callback else { return }
28-
28+
2929
guard
3030
let args = self.codec.decode(message) as? [Any?],
3131
let firstArg = args.first,
@@ -34,20 +34,21 @@ class EchoBinaryMessenger: NSObject, FlutterBinaryMessenger {
3434
callback(self.defaultReturn.flatMap { self.codec.encode([$0]) })
3535
return
3636
}
37-
37+
3838
callback(self.codec.encode([castedFirstArg]))
3939
}
40-
40+
4141
func setMessageHandlerOnChannel(
42-
_ channel: String, binaryMessageHandler handler:
43-
FlutterBinaryMessageHandler? = nil
42+
_ channel: String,
43+
binaryMessageHandler handler:
44+
FlutterBinaryMessageHandler? = nil
4445
) -> FlutterBinaryMessengerConnection {
4546
self.count += 1
4647
return FlutterBinaryMessengerConnection(self.count)
4748
}
48-
49+
4950
func cleanUpConnection(_ connection: FlutterBinaryMessengerConnection) {
50-
// Method not implemented because this messenger is just for echoing
51+
// Method not implemented because this messenger is just for echoing
5152
}
5253

5354
private func nilOrValue<T>(_ value: Any?) -> T? {

packages/pigeon/platform_tests/test_plugin/example/ios/RunnerTests/EnumTests.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// found in the LICENSE file.
44

55
import XCTest
6+
67
@testable import test_plugin
78

89
class MockEnumApi2Host: EnumApi2Host {
@@ -32,7 +33,7 @@ class EnumTests: XCTestCase {
3233
binaryMessenger.handlers[channelName]?(inputEncoded) { data in
3334
let outputMap = binaryMessenger.codec.decode(data) as? [Any]
3435
XCTAssertNotNil(outputMap)
35-
36+
3637
let output = outputMap?.first as? DataWithEnum
3738
XCTAssertEqual(output, input)
3839
XCTAssertTrue(outputMap?.count == 1)
@@ -49,11 +50,11 @@ class EnumTests: XCTestCase {
4950
let expectation = XCTestExpectation(description: "callback")
5051
api.echo(data: data) { result in
5152
switch result {
52-
case .success(let res) :
53-
XCTAssertEqual(res.state, res.state)
54-
expectation.fulfill()
55-
case .failure(_) :
56-
return
53+
case .success(let res):
54+
XCTAssertEqual(res.state, res.state)
55+
expectation.fulfill()
56+
case .failure(_):
57+
return
5758
}
5859
}
5960
wait(for: [expectation], timeout: 1.0)

0 commit comments

Comments
 (0)