Skip to content
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

Fix tests are changes in core #12

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 17 additions & 16 deletions Sources/GRPCProtobufCodeGen/ProtobufCodeGenParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
*/

internal import Foundation
internal import GRPCCodeGen
internal import SwiftProtobufPluginLibrary

internal import struct GRPCCodeGen.CodeGenerationRequest
internal import struct GRPCCodeGen.SourceGenerator

/// Parses a ``FileDescriptor`` object into a ``CodeGenerationRequest`` object.
internal struct ProtobufCodeGenParser {
let input: FileDescriptor
Expand Down Expand Up @@ -68,7 +66,7 @@ internal struct ProtobufCodeGenParser {
"GRPCProtobuf.ProtobufDeserializer<\(messageType)>()"
}
let services = self.input.services.map {
CodeGenerationRequest.ServiceDescriptor(
ServiceDescriptor(
descriptor: $0,
package: input.package,
protobufNamer: self.namer,
Expand All @@ -88,41 +86,41 @@ internal struct ProtobufCodeGenParser {
}

extension ProtobufCodeGenParser {
fileprivate var codeDependencies: [CodeGenerationRequest.Dependency] {
var codeDependencies: [CodeGenerationRequest.Dependency] = [
fileprivate var codeDependencies: [Dependency] {
var codeDependencies: [Dependency] = [
.init(module: "GRPCProtobuf", accessLevel: .internal)
]
// Adding as dependencies the modules containing generated code or types for
// '.proto' files imported in the '.proto' file we are parsing.
codeDependencies.append(
contentsOf: (self.protoToModuleMappings.neededModules(forFile: self.input) ?? []).map {
CodeGenerationRequest.Dependency(module: $0, accessLevel: self.accessLevel)
Dependency(module: $0, accessLevel: self.accessLevel)
}
)
// Adding extra imports passed in as an option to the plugin.
codeDependencies.append(
contentsOf: self.extraModuleImports.sorted().map {
CodeGenerationRequest.Dependency(module: $0, accessLevel: self.accessLevel)
Dependency(module: $0, accessLevel: self.accessLevel)
}
)
return codeDependencies
}
}

extension CodeGenerationRequest.ServiceDescriptor {
extension GRPCCodeGen.ServiceDescriptor {
fileprivate init(
descriptor: ServiceDescriptor,
descriptor: SwiftProtobufPluginLibrary.ServiceDescriptor,
package: String,
protobufNamer: SwiftProtobufNamer,
file: FileDescriptor
) {
let methods = descriptor.methods.map {
CodeGenerationRequest.ServiceDescriptor.MethodDescriptor(
GRPCCodeGen.MethodDescriptor(
descriptor: $0,
protobufNamer: protobufNamer
)
}
let name = CodeGenerationRequest.Name(
let name = Name(
base: descriptor.name,
// The service name from the '.proto' file is expected to be in upper camel case
generatedUpperCase: descriptor.name,
Expand All @@ -131,7 +129,7 @@ extension CodeGenerationRequest.ServiceDescriptor {

// Packages that are based on the path of the '.proto' file usually
// contain dots. For example: "grpc.test".
let namespace = CodeGenerationRequest.Name(
let namespace = Name(
base: package,
generatedUpperCase: protobufNamer.formattedUpperCasePackage(file: file),
generatedLowerCase: protobufNamer.formattedLowerCasePackage(file: file)
Expand All @@ -141,9 +139,12 @@ extension CodeGenerationRequest.ServiceDescriptor {
}
}

extension CodeGenerationRequest.ServiceDescriptor.MethodDescriptor {
fileprivate init(descriptor: MethodDescriptor, protobufNamer: SwiftProtobufNamer) {
let name = CodeGenerationRequest.Name(
extension GRPCCodeGen.MethodDescriptor {
fileprivate init(
descriptor: SwiftProtobufPluginLibrary.MethodDescriptor,
protobufNamer: SwiftProtobufNamer
) {
let name = Name(
base: descriptor.name,
// The method name from the '.proto' file is expected to be in upper camel case
generatedUpperCase: descriptor.name,
Expand Down
30 changes: 15 additions & 15 deletions Tests/GRPCProtobufCodeGenTests/ProtobufCodeGenParserTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ final class ProtobufCodeGenParserTests: XCTestCase {

self.testCommonHelloworldParsedRequestFields(for: parsedCodeGenRequest)

let expectedMethod = CodeGenerationRequest.ServiceDescriptor.MethodDescriptor(
let expectedMethod = MethodDescriptor(
documentation: "/// Sends a greeting.\n",
name: CodeGenerationRequest.Name(
name: Name(
base: "SayHello",
generatedUpperCase: "SayHello",
generatedLowerCase: "sayHello"
Expand All @@ -76,14 +76,14 @@ final class ProtobufCodeGenParserTests: XCTestCase {
guard let method = parsedCodeGenRequest.services.first?.methods.first else { return XCTFail() }
XCTAssertEqual(method, expectedMethod)

let expectedService = CodeGenerationRequest.ServiceDescriptor(
let expectedService = ServiceDescriptor(
documentation: "/// The greeting service definition.\n",
name: CodeGenerationRequest.Name(
name: Name(
base: "Greeter",
generatedUpperCase: "Greeter",
generatedLowerCase: "greeter"
),
namespace: CodeGenerationRequest.Name(
namespace: Name(
base: "helloworld",
generatedUpperCase: "Helloworld",
generatedLowerCase: "helloworld"
Expand Down Expand Up @@ -143,9 +143,9 @@ final class ProtobufCodeGenParserTests: XCTestCase {

self.testCommonHelloworldParsedRequestFields(for: parsedCodeGenRequest)

let expectedMethod = CodeGenerationRequest.ServiceDescriptor.MethodDescriptor(
let expectedMethod = MethodDescriptor(
documentation: "/// Sends a greeting.\n",
name: CodeGenerationRequest.Name(
name: Name(
base: "SayHello",
generatedUpperCase: "SayHello",
generatedLowerCase: "sayHello"
Expand All @@ -158,14 +158,14 @@ final class ProtobufCodeGenParserTests: XCTestCase {
guard let method = parsedCodeGenRequest.services.first?.methods.first else { return XCTFail() }
XCTAssertEqual(method, expectedMethod)

let expectedService = CodeGenerationRequest.ServiceDescriptor(
let expectedService = ServiceDescriptor(
documentation: "/// The greeting service definition.\n",
name: CodeGenerationRequest.Name(
name: Name(
base: "Greeter",
generatedUpperCase: "Greeter",
generatedLowerCase: "greeter"
),
namespace: CodeGenerationRequest.Name(
namespace: Name(
base: "hello.world",
generatedUpperCase: "Hello_World",
generatedLowerCase: "hello_world"
Expand Down Expand Up @@ -225,9 +225,9 @@ final class ProtobufCodeGenParserTests: XCTestCase {

self.testCommonHelloworldParsedRequestFields(for: parsedCodeGenRequest)

let expectedMethod = CodeGenerationRequest.ServiceDescriptor.MethodDescriptor(
let expectedMethod = MethodDescriptor(
documentation: "/// Sends a greeting.\n",
name: CodeGenerationRequest.Name(
name: Name(
base: "SayHello",
generatedUpperCase: "SayHello",
generatedLowerCase: "sayHello"
Expand All @@ -240,14 +240,14 @@ final class ProtobufCodeGenParserTests: XCTestCase {
guard let method = parsedCodeGenRequest.services.first?.methods.first else { return XCTFail() }
XCTAssertEqual(method, expectedMethod)

let expectedService = CodeGenerationRequest.ServiceDescriptor(
let expectedService = ServiceDescriptor(
documentation: "/// The greeting service definition.\n",
name: CodeGenerationRequest.Name(
name: Name(
base: "Greeter",
generatedUpperCase: "Greeter",
generatedLowerCase: "greeter"
),
namespace: CodeGenerationRequest.Name(
namespace: Name(
base: "",
generatedUpperCase: "",
generatedLowerCase: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,11 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
internal struct Hello_World_Greeter_Client: Hello_World_Greeter.ClientProtocol {
private let client: GRPCCore.GRPCClient

internal init(wrapping client: GRPCCore.GRPCClient) {
self.client = client
}

/// Sends a greeting.
internal func sayHello<R>(
request: GRPCCore.ClientRequest<Hello_World_HelloRequest>,
Expand Down Expand Up @@ -473,11 +473,11 @@ final class ProtobufCodeGeneratorTests: XCTestCase {
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
package struct Greeter_Client: Greeter.ClientProtocol {
private let client: GRPCCore.GRPCClient

package init(wrapping client: GRPCCore.GRPCClient) {
self.client = client
}

/// Sends a greeting.
package func sayHello<R>(
request: GRPCCore.ClientRequest<HelloRequest>,
Expand Down
Loading