Skip to content

Commit

Permalink
Few more PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
gjcairo committed Jun 25, 2024
1 parent 835c55c commit 80123a9
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 64 deletions.
6 changes: 3 additions & 3 deletions Sources/SwiftProtobufPluginLibrary/Descriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public final class Descriptor {

/// The extension ranges declared for this message. They are returned in
/// the order they are defined in the .proto file.
public let protoExtensionRanges: [ExtensionRange]
public let messageExtensionRanges: [ExtensionRange]

/// The extension ranges declared for this message. They are returned in
/// the order they are defined in the .proto file.
Expand Down Expand Up @@ -619,7 +619,7 @@ public final class Descriptor {
return featureResolver.resolve($0.options, resolvedParent: resolvedFeatures)
}

self.protoExtensionRanges = proto.extensionRange.enumerated().map {
self.messageExtensionRanges = proto.extensionRange.enumerated().map {
return ExtensionRange(proto: $0.element,
index: $0.offset,
features: featureResolver.resolve($0.element.options,
Expand Down Expand Up @@ -673,7 +673,7 @@ public final class Descriptor {
fileprivate func bind(file: FileDescriptor, registry: Registry, containingType: Descriptor?) {
_file = file
self.containingType = containingType
protoExtensionRanges.forEach { $0.bind(containingType: self, registry: registry) }
messageExtensionRanges.forEach { $0.bind(containingType: self, registry: registry) }
enums.forEach { $0.bind(file: file, registry: registry, containingType: self) }
messages.forEach { $0.bind(file: file, registry: registry, containingType: self) }
fields.forEach { $0.bind(file: file, registry: registry, containingType: self) }
Expand Down
4 changes: 2 additions & 2 deletions Sources/protoc-gen-swift/Descriptor+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ extension Descriptor {

// If it can support extensions, then return true as an extension could
// have a required field.
if !descriptor.protoExtensionRanges.isEmpty {
if !descriptor.messageExtensionRanges.isEmpty {
return true
}

Expand All @@ -210,7 +210,7 @@ extension Descriptor {
/// This also uses Range<> since the options that could be on
/// `extensionRanges` no longer can apply as the things have been merged.
var _normalizedExtensionRanges: [Range<Int32>] {
var ordered: [Range<Int32>] = self.protoExtensionRanges.sorted(by: {
var ordered: [Range<Int32>] = self.messageExtensionRanges.sorted(by: {
return $0.start < $1.start }).map { return $0.start ..< $0.end
}
if ordered.count > 1 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/protoc-gen-swift/MessageGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class MessageGenerator {
self.namer = namer

visibility = generatorOptions.visibilitySourceSnippet
isExtensible = !descriptor.protoExtensionRanges.isEmpty
isExtensible = !descriptor.messageExtensionRanges.isEmpty
swiftRelativeName = namer.relativeName(message: descriptor)
swiftFullName = namer.fullName(message: descriptor)

Expand Down
64 changes: 32 additions & 32 deletions Tests/SwiftProtobufPluginLibraryTests/Test_Descriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,22 +213,22 @@ final class Test_Descriptor: XCTestCase {
XCTAssertEqual(proto2ForPresence.fields[14].name, "oneof_enum_field")
XCTAssertEqual(proto2ForPresence.fields[15].name, "oneof_message_field")

XCTAssertFalse(proto2ForPresence.fields[0].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[1].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[2].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[3].hasOptionalKeyword)
XCTAssertTrue(proto2ForPresence.fields[4].hasOptionalKeyword)
XCTAssertTrue(proto2ForPresence.fields[5].hasOptionalKeyword)
XCTAssertTrue(proto2ForPresence.fields[6].hasOptionalKeyword)
XCTAssertTrue(proto2ForPresence.fields[7].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[8].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[9].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[10].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[11].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[12].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[13].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[14].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[15].hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[0]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[1]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[2]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[3]._hasOptionalKeyword)
XCTAssertTrue(proto2ForPresence.fields[4]._hasOptionalKeyword)
XCTAssertTrue(proto2ForPresence.fields[5]._hasOptionalKeyword)
XCTAssertTrue(proto2ForPresence.fields[6]._hasOptionalKeyword)
XCTAssertTrue(proto2ForPresence.fields[7]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[8]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[9]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[10]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[11]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[12]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[13]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[14]._hasOptionalKeyword)
XCTAssertFalse(proto2ForPresence.fields[15]._hasOptionalKeyword)

XCTAssertTrue(proto2ForPresence.fields[0].hasPresence)
XCTAssertTrue(proto2ForPresence.fields[1].hasPresence)
Expand Down Expand Up @@ -274,22 +274,22 @@ final class Test_Descriptor: XCTestCase {
XCTAssertEqual(proto3ForPresence.fields[14].name, "oneof_enum_field")
XCTAssertEqual(proto3ForPresence.fields[15].name, "oneof_message_field")

XCTAssertFalse(proto3ForPresence.fields[0].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[1].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[2].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[3].hasOptionalKeyword)
XCTAssertTrue(proto3ForPresence.fields[4].hasOptionalKeyword)
XCTAssertTrue(proto3ForPresence.fields[5].hasOptionalKeyword)
XCTAssertTrue(proto3ForPresence.fields[6].hasOptionalKeyword)
XCTAssertTrue(proto3ForPresence.fields[7].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[8].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[9].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[10].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[11].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[12].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[13].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[14].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[15].hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[0]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[1]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[2]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[3]._hasOptionalKeyword)
XCTAssertTrue(proto3ForPresence.fields[4]._hasOptionalKeyword)
XCTAssertTrue(proto3ForPresence.fields[5]._hasOptionalKeyword)
XCTAssertTrue(proto3ForPresence.fields[6]._hasOptionalKeyword)
XCTAssertTrue(proto3ForPresence.fields[7]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[8]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[9]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[10]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[11]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[12]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[13]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[14]._hasOptionalKeyword)
XCTAssertFalse(proto3ForPresence.fields[15]._hasOptionalKeyword)

XCTAssertFalse(proto3ForPresence.fields[0].hasPresence)
XCTAssertFalse(proto3ForPresence.fields[1].hasPresence)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ final class Test_Descriptor_FeatureResolution: XCTestCase {
}
""")

let features = context.file.messages.first!.protoExtensionRanges.first!.features
let features = context.file.messages.first!.messageExtensionRanges.first!.features
XCTAssertTrue(features.hasSwiftFeatureTest_test)
XCTAssertEqual(features.SwiftFeatureTest_test.feature1, .value1)
XCTAssertEqual(features.SwiftFeatureTest_test.feature2, .value1)
Expand Down Expand Up @@ -300,7 +300,7 @@ final class Test_Descriptor_FeatureResolution: XCTestCase {
}
""")

let features = context.file.messages.first!.protoExtensionRanges.first!.features
let features = context.file.messages.first!.messageExtensionRanges.first!.features
XCTAssertTrue(features.hasSwiftFeatureTest_test)
XCTAssertEqual(features.SwiftFeatureTest_test.feature1, .value2) // File override
XCTAssertEqual(features.SwiftFeatureTest_test.feature2, .value3) // Message override
Expand Down
48 changes: 24 additions & 24 deletions Tests/protoc-gen-swiftTests/Test_DescriptorExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ final class Test_DescriptorExtensions: XCTestCase {

let msgDescriptor = descriptorSet.descriptor(named: "swift_descriptor_test.MsgExtensionRangeOrdering")!
// Quick check of what should be in the proto file
XCTAssertEqual(msgDescriptor.protoExtensionRanges.count, 9)
XCTAssertEqual(msgDescriptor.protoExtensionRanges[0].start, 1)
XCTAssertEqual(msgDescriptor.protoExtensionRanges[1].start, 3)
XCTAssertEqual(msgDescriptor.protoExtensionRanges[2].start, 2)
XCTAssertEqual(msgDescriptor.protoExtensionRanges[3].start, 4)
XCTAssertEqual(msgDescriptor.protoExtensionRanges[4].start, 7)
XCTAssertEqual(msgDescriptor.protoExtensionRanges[5].start, 9)
XCTAssertEqual(msgDescriptor.protoExtensionRanges[6].start, 100)
XCTAssertEqual(msgDescriptor.protoExtensionRanges[7].start, 126)
XCTAssertEqual(msgDescriptor.protoExtensionRanges[8].start, 111)
XCTAssertEqual(msgDescriptor.messageExtensionRanges.count, 9)
XCTAssertEqual(msgDescriptor.messageExtensionRanges[0].start, 1)
XCTAssertEqual(msgDescriptor.messageExtensionRanges[1].start, 3)
XCTAssertEqual(msgDescriptor.messageExtensionRanges[2].start, 2)
XCTAssertEqual(msgDescriptor.messageExtensionRanges[3].start, 4)
XCTAssertEqual(msgDescriptor.messageExtensionRanges[4].start, 7)
XCTAssertEqual(msgDescriptor.messageExtensionRanges[5].start, 9)
XCTAssertEqual(msgDescriptor.messageExtensionRanges[6].start, 100)
XCTAssertEqual(msgDescriptor.messageExtensionRanges[7].start, 126)
XCTAssertEqual(msgDescriptor.messageExtensionRanges[8].start, 111)

// Check sorting/merging
XCTAssertEqual(msgDescriptor._normalizedExtensionRanges.count, 5)
Expand All @@ -56,16 +56,16 @@ final class Test_DescriptorExtensions: XCTestCase {

let msgDescriptor2 = descriptorSet.descriptor(named: "swift_descriptor_test.MsgExtensionRangeOrderingWithFields")!
// Quick check of what should be in the proto file
XCTAssertEqual(msgDescriptor2.protoExtensionRanges.count, 9)
XCTAssertEqual(msgDescriptor2.protoExtensionRanges[0].start, 1)
XCTAssertEqual(msgDescriptor2.protoExtensionRanges[1].start, 3)
XCTAssertEqual(msgDescriptor2.protoExtensionRanges[2].start, 2)
XCTAssertEqual(msgDescriptor2.protoExtensionRanges[3].start, 4)
XCTAssertEqual(msgDescriptor2.protoExtensionRanges[4].start, 7)
XCTAssertEqual(msgDescriptor2.protoExtensionRanges[5].start, 9)
XCTAssertEqual(msgDescriptor2.protoExtensionRanges[6].start, 100)
XCTAssertEqual(msgDescriptor2.protoExtensionRanges[7].start, 126)
XCTAssertEqual(msgDescriptor2.protoExtensionRanges[8].start, 111)
XCTAssertEqual(msgDescriptor2.messageExtensionRanges.count, 9)
XCTAssertEqual(msgDescriptor2.messageExtensionRanges[0].start, 1)
XCTAssertEqual(msgDescriptor2.messageExtensionRanges[1].start, 3)
XCTAssertEqual(msgDescriptor2.messageExtensionRanges[2].start, 2)
XCTAssertEqual(msgDescriptor2.messageExtensionRanges[3].start, 4)
XCTAssertEqual(msgDescriptor2.messageExtensionRanges[4].start, 7)
XCTAssertEqual(msgDescriptor2.messageExtensionRanges[5].start, 9)
XCTAssertEqual(msgDescriptor2.messageExtensionRanges[6].start, 100)
XCTAssertEqual(msgDescriptor2.messageExtensionRanges[7].start, 126)
XCTAssertEqual(msgDescriptor2.messageExtensionRanges[8].start, 111)

// Check sorting/merging
XCTAssertEqual(msgDescriptor2._normalizedExtensionRanges.count, 5)
Expand All @@ -92,10 +92,10 @@ final class Test_DescriptorExtensions: XCTestCase {

let msgDescriptor3 = descriptorSet.descriptor(named: "swift_descriptor_test.MsgExtensionRangeOrderingNoMerging")!
// Quick check of what should be in the proto file
XCTAssertEqual(msgDescriptor3.protoExtensionRanges.count, 3)
XCTAssertEqual(msgDescriptor3.protoExtensionRanges[0].start, 3)
XCTAssertEqual(msgDescriptor3.protoExtensionRanges[1].start, 7)
XCTAssertEqual(msgDescriptor3.protoExtensionRanges[2].start, 16)
XCTAssertEqual(msgDescriptor3.messageExtensionRanges.count, 3)
XCTAssertEqual(msgDescriptor3.messageExtensionRanges[0].start, 3)
XCTAssertEqual(msgDescriptor3.messageExtensionRanges[1].start, 7)
XCTAssertEqual(msgDescriptor3.messageExtensionRanges[2].start, 16)

// Check sorting/merging
XCTAssertEqual(msgDescriptor3._normalizedExtensionRanges.count, 3)
Expand Down

0 comments on commit 80123a9

Please sign in to comment.