|
|
@@ -25,6 +25,7 @@ import XCTest
|
|
|
final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
func testProtobufCodeGenerator() throws {
|
|
|
try testCodeGeneration(
|
|
|
+ proto: Google_Protobuf_FileDescriptorProto.helloWorldNestedPackage,
|
|
|
indentation: 4,
|
|
|
visibility: .internal,
|
|
|
client: true,
|
|
|
@@ -58,13 +59,13 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
import DifferentModule
|
|
|
import ExtraModule
|
|
|
|
|
|
- internal enum Helloworld_Greeter {
|
|
|
+ internal enum Hello_World_Greeter {
|
|
|
internal enum Method {
|
|
|
internal enum SayHello {
|
|
|
- internal typealias Input = Helloworld_HelloRequest
|
|
|
- internal typealias Output = Helloworld_HelloReply
|
|
|
+ internal typealias Input = Hello_World_HelloRequest
|
|
|
+ internal typealias Output = Hello_World_HelloReply
|
|
|
internal static let descriptor = MethodDescriptor(
|
|
|
- service: "helloworld.Greeter",
|
|
|
+ service: "hello.world.Greeter",
|
|
|
method: "SayHello"
|
|
|
)
|
|
|
}
|
|
|
@@ -73,33 +74,33 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
]
|
|
|
}
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- internal typealias ClientProtocol = Helloworld_GreeterClientProtocol
|
|
|
+ internal typealias ClientProtocol = Hello_World_GreeterClientProtocol
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- internal typealias Client = Helloworld_GreeterClient
|
|
|
+ internal typealias Client = Hello_World_GreeterClient
|
|
|
}
|
|
|
|
|
|
/// The greeting service definition.
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- internal protocol Helloworld_GreeterClientProtocol: Sendable {
|
|
|
+ internal protocol Hello_World_GreeterClientProtocol: Sendable {
|
|
|
/// Sends a greeting.
|
|
|
func sayHello<R>(
|
|
|
- request: ClientRequest.Single<Helloworld_Greeter.Method.SayHello.Input>,
|
|
|
- serializer: some MessageSerializer<Helloworld_Greeter.Method.SayHello.Input>,
|
|
|
- deserializer: some MessageDeserializer<Helloworld_Greeter.Method.SayHello.Output>,
|
|
|
- _ body: @Sendable @escaping (ClientResponse.Single<Helloworld_Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
+ request: ClientRequest.Single<Hello_World_Greeter.Method.SayHello.Input>,
|
|
|
+ serializer: some MessageSerializer<Hello_World_Greeter.Method.SayHello.Input>,
|
|
|
+ deserializer: some MessageDeserializer<Hello_World_Greeter.Method.SayHello.Output>,
|
|
|
+ _ body: @Sendable @escaping (ClientResponse.Single<Hello_World_Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
) async throws -> R where R: Sendable
|
|
|
}
|
|
|
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- extension Helloworld_Greeter.ClientProtocol {
|
|
|
+ extension Hello_World_Greeter.ClientProtocol {
|
|
|
internal func sayHello<R>(
|
|
|
- request: ClientRequest.Single<Helloworld_Greeter.Method.SayHello.Input>,
|
|
|
- _ body: @Sendable @escaping (ClientResponse.Single<Helloworld_Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
+ request: ClientRequest.Single<Hello_World_Greeter.Method.SayHello.Input>,
|
|
|
+ _ body: @Sendable @escaping (ClientResponse.Single<Hello_World_Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
) async throws -> R where R: Sendable {
|
|
|
try await self.sayHello(
|
|
|
request: request,
|
|
|
- serializer: ProtobufSerializer<Helloworld_Greeter.Method.SayHello.Input>(),
|
|
|
- deserializer: ProtobufDeserializer<Helloworld_Greeter.Method.SayHello.Output>(),
|
|
|
+ serializer: ProtobufSerializer<Hello_World_Greeter.Method.SayHello.Input>(),
|
|
|
+ deserializer: ProtobufDeserializer<Hello_World_Greeter.Method.SayHello.Output>(),
|
|
|
body
|
|
|
)
|
|
|
}
|
|
|
@@ -107,7 +108,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
|
|
|
/// The greeting service definition.
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- internal struct Helloworld_GreeterClient: Helloworld_Greeter.ClientProtocol {
|
|
|
+ internal struct Hello_World_GreeterClient: Hello_World_Greeter.ClientProtocol {
|
|
|
private let client: GRPCCore.GRPCClient
|
|
|
|
|
|
internal init(client: GRPCCore.GRPCClient) {
|
|
|
@@ -116,14 +117,14 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
|
|
|
/// Sends a greeting.
|
|
|
internal func sayHello<R>(
|
|
|
- request: ClientRequest.Single<Helloworld_Greeter.Method.SayHello.Input>,
|
|
|
- serializer: some MessageSerializer<Helloworld_Greeter.Method.SayHello.Input>,
|
|
|
- deserializer: some MessageDeserializer<Helloworld_Greeter.Method.SayHello.Output>,
|
|
|
- _ body: @Sendable @escaping (ClientResponse.Single<Helloworld_Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
+ request: ClientRequest.Single<Hello_World_Greeter.Method.SayHello.Input>,
|
|
|
+ serializer: some MessageSerializer<Hello_World_Greeter.Method.SayHello.Input>,
|
|
|
+ deserializer: some MessageDeserializer<Hello_World_Greeter.Method.SayHello.Output>,
|
|
|
+ _ body: @Sendable @escaping (ClientResponse.Single<Hello_World_Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
) async throws -> R where R: Sendable {
|
|
|
try await self.client.unary(
|
|
|
request: request,
|
|
|
- descriptor: Helloworld_Greeter.Method.SayHello.descriptor,
|
|
|
+ descriptor: Hello_World_Greeter.Method.SayHello.descriptor,
|
|
|
serializer: serializer,
|
|
|
deserializer: deserializer,
|
|
|
handler: body
|
|
|
@@ -134,6 +135,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
)
|
|
|
|
|
|
try testCodeGeneration(
|
|
|
+ proto: Google_Protobuf_FileDescriptorProto.helloWorld,
|
|
|
indentation: 2,
|
|
|
visibility: .public,
|
|
|
client: false,
|
|
|
@@ -228,6 +230,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
"""
|
|
|
)
|
|
|
try testCodeGeneration(
|
|
|
+ proto: Google_Protobuf_FileDescriptorProto.helloWorldEmptyPackage,
|
|
|
indentation: 2,
|
|
|
visibility: .package,
|
|
|
client: true,
|
|
|
@@ -261,13 +264,13 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
import DifferentModule
|
|
|
import ExtraModule
|
|
|
|
|
|
- package enum Helloworld_Greeter {
|
|
|
+ package enum Greeter {
|
|
|
package enum Method {
|
|
|
package enum SayHello {
|
|
|
- package typealias Input = Helloworld_HelloRequest
|
|
|
- package typealias Output = Helloworld_HelloReply
|
|
|
+ package typealias Input = HelloRequest
|
|
|
+ package typealias Output = HelloReply
|
|
|
package static let descriptor = MethodDescriptor(
|
|
|
- service: "helloworld.Greeter",
|
|
|
+ service: "Greeter",
|
|
|
method: "SayHello"
|
|
|
)
|
|
|
}
|
|
|
@@ -276,31 +279,31 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
]
|
|
|
}
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- package typealias StreamingServiceProtocol = Helloworld_GreeterStreamingServiceProtocol
|
|
|
+ package typealias StreamingServiceProtocol = GreeterStreamingServiceProtocol
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- package typealias ServiceProtocol = Helloworld_GreeterServiceProtocol
|
|
|
+ package typealias ServiceProtocol = GreeterServiceProtocol
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- package typealias ClientProtocol = Helloworld_GreeterClientProtocol
|
|
|
+ package typealias ClientProtocol = GreeterClientProtocol
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- package typealias Client = Helloworld_GreeterClient
|
|
|
+ package typealias Client = GreeterClient
|
|
|
}
|
|
|
|
|
|
/// The greeting service definition.
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- package protocol Helloworld_GreeterStreamingServiceProtocol: GRPCCore.RegistrableRPCService {
|
|
|
+ package protocol GreeterStreamingServiceProtocol: GRPCCore.RegistrableRPCService {
|
|
|
/// Sends a greeting.
|
|
|
- func sayHello(request: ServerRequest.Stream<Helloworld_Greeter.Method.SayHello.Input>) async throws -> ServerResponse.Stream<Helloworld_Greeter.Method.SayHello.Output>
|
|
|
+ func sayHello(request: ServerRequest.Stream<Greeter.Method.SayHello.Input>) async throws -> ServerResponse.Stream<Greeter.Method.SayHello.Output>
|
|
|
}
|
|
|
|
|
|
/// Conformance to `GRPCCore.RegistrableRPCService`.
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- extension Helloworld_Greeter.StreamingServiceProtocol {
|
|
|
+ extension Greeter.StreamingServiceProtocol {
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
package func registerMethods(with router: inout GRPCCore.RPCRouter) {
|
|
|
router.registerHandler(
|
|
|
- forMethod: Helloworld_Greeter.Method.SayHello.descriptor,
|
|
|
- deserializer: ProtobufDeserializer<Helloworld_Greeter.Method.SayHello.Input>(),
|
|
|
- serializer: ProtobufSerializer<Helloworld_Greeter.Method.SayHello.Output>(),
|
|
|
+ forMethod: Greeter.Method.SayHello.descriptor,
|
|
|
+ deserializer: ProtobufDeserializer<Greeter.Method.SayHello.Input>(),
|
|
|
+ serializer: ProtobufSerializer<Greeter.Method.SayHello.Output>(),
|
|
|
handler: { request in
|
|
|
try await self.sayHello(request: request)
|
|
|
}
|
|
|
@@ -310,15 +313,15 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
|
|
|
/// The greeting service definition.
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- package protocol Helloworld_GreeterServiceProtocol: Helloworld_Greeter.StreamingServiceProtocol {
|
|
|
+ package protocol GreeterServiceProtocol: Greeter.StreamingServiceProtocol {
|
|
|
/// Sends a greeting.
|
|
|
- func sayHello(request: ServerRequest.Single<Helloworld_Greeter.Method.SayHello.Input>) async throws -> ServerResponse.Single<Helloworld_Greeter.Method.SayHello.Output>
|
|
|
+ func sayHello(request: ServerRequest.Single<Greeter.Method.SayHello.Input>) async throws -> ServerResponse.Single<Greeter.Method.SayHello.Output>
|
|
|
}
|
|
|
|
|
|
- /// Partial conformance to `Helloworld_GreeterStreamingServiceProtocol`.
|
|
|
+ /// Partial conformance to `GreeterStreamingServiceProtocol`.
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- extension Helloworld_Greeter.ServiceProtocol {
|
|
|
- package func sayHello(request: ServerRequest.Stream<Helloworld_Greeter.Method.SayHello.Input>) async throws -> ServerResponse.Stream<Helloworld_Greeter.Method.SayHello.Output> {
|
|
|
+ extension Greeter.ServiceProtocol {
|
|
|
+ package func sayHello(request: ServerRequest.Stream<Greeter.Method.SayHello.Input>) async throws -> ServerResponse.Stream<Greeter.Method.SayHello.Output> {
|
|
|
let response = try await self.sayHello(request: ServerRequest.Single(stream: request))
|
|
|
return ServerResponse.Stream(single: response)
|
|
|
}
|
|
|
@@ -326,26 +329,26 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
|
|
|
/// The greeting service definition.
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- package protocol Helloworld_GreeterClientProtocol: Sendable {
|
|
|
+ package protocol GreeterClientProtocol: Sendable {
|
|
|
/// Sends a greeting.
|
|
|
func sayHello<R>(
|
|
|
- request: ClientRequest.Single<Helloworld_Greeter.Method.SayHello.Input>,
|
|
|
- serializer: some MessageSerializer<Helloworld_Greeter.Method.SayHello.Input>,
|
|
|
- deserializer: some MessageDeserializer<Helloworld_Greeter.Method.SayHello.Output>,
|
|
|
- _ body: @Sendable @escaping (ClientResponse.Single<Helloworld_Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
+ request: ClientRequest.Single<Greeter.Method.SayHello.Input>,
|
|
|
+ serializer: some MessageSerializer<Greeter.Method.SayHello.Input>,
|
|
|
+ deserializer: some MessageDeserializer<Greeter.Method.SayHello.Output>,
|
|
|
+ _ body: @Sendable @escaping (ClientResponse.Single<Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
) async throws -> R where R: Sendable
|
|
|
}
|
|
|
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- extension Helloworld_Greeter.ClientProtocol {
|
|
|
+ extension Greeter.ClientProtocol {
|
|
|
package func sayHello<R>(
|
|
|
- request: ClientRequest.Single<Helloworld_Greeter.Method.SayHello.Input>,
|
|
|
- _ body: @Sendable @escaping (ClientResponse.Single<Helloworld_Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
+ request: ClientRequest.Single<Greeter.Method.SayHello.Input>,
|
|
|
+ _ body: @Sendable @escaping (ClientResponse.Single<Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
) async throws -> R where R: Sendable {
|
|
|
try await self.sayHello(
|
|
|
request: request,
|
|
|
- serializer: ProtobufSerializer<Helloworld_Greeter.Method.SayHello.Input>(),
|
|
|
- deserializer: ProtobufDeserializer<Helloworld_Greeter.Method.SayHello.Output>(),
|
|
|
+ serializer: ProtobufSerializer<Greeter.Method.SayHello.Input>(),
|
|
|
+ deserializer: ProtobufDeserializer<Greeter.Method.SayHello.Output>(),
|
|
|
body
|
|
|
)
|
|
|
}
|
|
|
@@ -353,7 +356,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
|
|
|
/// The greeting service definition.
|
|
|
@available(macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0, *)
|
|
|
- package struct Helloworld_GreeterClient: Helloworld_Greeter.ClientProtocol {
|
|
|
+ package struct GreeterClient: Greeter.ClientProtocol {
|
|
|
private let client: GRPCCore.GRPCClient
|
|
|
|
|
|
package init(client: GRPCCore.GRPCClient) {
|
|
|
@@ -362,14 +365,14 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
|
|
|
/// Sends a greeting.
|
|
|
package func sayHello<R>(
|
|
|
- request: ClientRequest.Single<Helloworld_Greeter.Method.SayHello.Input>,
|
|
|
- serializer: some MessageSerializer<Helloworld_Greeter.Method.SayHello.Input>,
|
|
|
- deserializer: some MessageDeserializer<Helloworld_Greeter.Method.SayHello.Output>,
|
|
|
- _ body: @Sendable @escaping (ClientResponse.Single<Helloworld_Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
+ request: ClientRequest.Single<Greeter.Method.SayHello.Input>,
|
|
|
+ serializer: some MessageSerializer<Greeter.Method.SayHello.Input>,
|
|
|
+ deserializer: some MessageDeserializer<Greeter.Method.SayHello.Output>,
|
|
|
+ _ body: @Sendable @escaping (ClientResponse.Single<Greeter.Method.SayHello.Output>) async throws -> R
|
|
|
) async throws -> R where R: Sendable {
|
|
|
try await self.client.unary(
|
|
|
request: request,
|
|
|
- descriptor: Helloworld_Greeter.Method.SayHello.descriptor,
|
|
|
+ descriptor: Greeter.Method.SayHello.descriptor,
|
|
|
serializer: serializer,
|
|
|
deserializer: deserializer,
|
|
|
handler: body
|
|
|
@@ -381,6 +384,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
}
|
|
|
|
|
|
func testCodeGeneration(
|
|
|
+ proto: Google_Protobuf_FileDescriptorProto,
|
|
|
indentation: Int,
|
|
|
visibility: SourceGenerator.Configuration.AccessLevel,
|
|
|
client: Bool,
|
|
|
@@ -400,7 +404,7 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
|
|
|
name: "different-module.proto",
|
|
|
package: "different-package"
|
|
|
),
|
|
|
- Google_Protobuf_FileDescriptorProto.helloWorld,
|
|
|
+ proto,
|
|
|
])
|
|
|
guard let fileDescriptor = descriptorSet.fileDescriptor(named: "helloworld.proto") else {
|
|
|
return XCTFail(
|