Skip to content

Commit 8d80630

Browse files
committed
Add test for non protobuf identifier handling.
This is just a compile test. Tests/SwiftProtobufPluginLibraryTests/Test_NamingUtils.swift also covers this behavior but making a full compile test to be safe. NOTE: This is a distict commit incase git/filesystem have issues with this file name and it ends up not working on linux. If that happens the commit can be reverted to remove this without losing any of the supporting code.
1 parent df51dbe commit 8d80630

File tree

7 files changed

+269
-1
lines changed

7 files changed

+269
-1
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ TEST_PROTOS= \
124124
Protos/unittest_swift_extension4.proto \
125125
Protos/unittest_swift_fieldorder.proto \
126126
Protos/unittest_swift_groups.proto \
127+
Protos/unittest_swift_größ.proto \
127128
Protos/unittest_swift_naming.proto \
128129
Protos/unittest_swift_naming_no_prefix.proto \
129130
Protos/unittest_swift_naming_number_prefix.proto \

Protos/unittest_swift_größ.proto

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Protos/unittest_swift_größ.proto - test proto
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
// -----------------------------------------------------------------------------
12+
///
13+
/// Test Swift reserved words used as enum or message names
14+
///
15+
// -----------------------------------------------------------------------------
16+
17+
syntax = "proto2";
18+
19+
// No package or Swift prefix.
20+
21+
message ToExtend {
22+
extensions 1 to 5000;
23+
}
24+
25+
extend ToExtend {
26+
optional int32 added = 101;
27+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// DO NOT EDIT.
2+
//
3+
// Generated by the Swift generator plugin for the protocol buffer compiler.
4+
// Source: unittest_swift_größ.proto
5+
//
6+
// For information on using the generated types, please see the documentation:
7+
// https://github.com/apple/swift-protobuf/
8+
9+
// Protos/unittest_swift_größ.proto - test proto
10+
//
11+
// This source file is part of the Swift.org open source project
12+
//
13+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
14+
// Licensed under Apache License v2.0 with Runtime Library Exception
15+
//
16+
// See http://swift.org/LICENSE.txt for license information
17+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
18+
//
19+
// -----------------------------------------------------------------------------
20+
///
21+
/// Test Swift reserved words used as enum or message names
22+
///
23+
// -----------------------------------------------------------------------------
24+
25+
import Foundation
26+
import SwiftProtobuf
27+
28+
// If the compiler emits an error on this type, it is because this file
29+
// was generated by a version of the `protoc` Swift plug-in that is
30+
// incompatible with the version of SwiftProtobuf to which you are linking.
31+
// Please ensure that you are building against the same version of the API
32+
// that was used to generate this file.
33+
fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck {
34+
struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {}
35+
typealias Version = _2
36+
}
37+
38+
struct ToExtend: SwiftProtobuf.ExtensibleMessage {
39+
// SwiftProtobuf.Message conformance is added in an extension below. See the
40+
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
41+
// methods supported on all messages.
42+
43+
var unknownFields = SwiftProtobuf.UnknownStorage()
44+
45+
init() {}
46+
47+
var _protobuf_extensionFieldValues = SwiftProtobuf.ExtensionFieldValueSet()
48+
}
49+
50+
// MARK: - Extension support defined in unittest_swift_größ.proto.
51+
52+
extension ToExtend {
53+
54+
var added: Int32 {
55+
get {return getExtensionValue(ext: Extensions_added) ?? 0}
56+
set {setExtensionValue(ext: Extensions_added, value: newValue)}
57+
}
58+
/// Returns true if extension `Extensions_added`
59+
/// has been explicitly set.
60+
var hasAdded: Bool {
61+
return hasExtensionValue(ext: Extensions_added)
62+
}
63+
/// Clears the value of extension `Extensions_added`.
64+
/// Subsequent reads from it will return its default value.
65+
mutating func clearAdded() {
66+
clearExtensionValue(ext: Extensions_added)
67+
}
68+
69+
}
70+
71+
/// A `SwiftProtobuf.SimpleExtensionMap` that includes all of the extensions defined by
72+
/// this .proto file. It can be used any place an `SwiftProtobuf.ExtensionMap` is needed
73+
/// in parsing, or it can be combined with other `SwiftProtobuf.SimpleExtensionMap`s to create
74+
/// a larger `SwiftProtobuf.SimpleExtensionMap`.
75+
let UnittestSwiftGröß_Extensions: SwiftProtobuf.SimpleExtensionMap = [
76+
Extensions_added
77+
]
78+
79+
let Extensions_added = SwiftProtobuf.MessageExtension<SwiftProtobuf.OptionalExtensionField<SwiftProtobuf.ProtobufInt32>, ToExtend>(
80+
_protobuf_fieldNumber: 101,
81+
fieldName: "added"
82+
)
83+
84+
// MARK: - Code below here is support for the SwiftProtobuf runtime.
85+
86+
extension ToExtend: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
87+
static let protoMessageName: String = "ToExtend"
88+
static let _protobuf_nameMap = SwiftProtobuf._NameMap()
89+
90+
public var isInitialized: Bool {
91+
if !_protobuf_extensionFieldValues.isInitialized {return false}
92+
return true
93+
}
94+
95+
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
96+
while let fieldNumber = try decoder.nextFieldNumber() {
97+
if (1 <= fieldNumber && fieldNumber < 5001) {
98+
try decoder.decodeExtensionField(values: &_protobuf_extensionFieldValues, messageType: ToExtend.self, fieldNumber: fieldNumber)
99+
}
100+
}
101+
}
102+
103+
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
104+
try visitor.visitExtensionFields(fields: _protobuf_extensionFieldValues, start: 1, end: 5001)
105+
try unknownFields.traverse(visitor: &visitor)
106+
}
107+
108+
static func ==(lhs: ToExtend, rhs: ToExtend) -> Bool {
109+
if lhs.unknownFields != rhs.unknownFields {return false}
110+
if lhs._protobuf_extensionFieldValues != rhs._protobuf_extensionFieldValues {return false}
111+
return true
112+
}
113+
}

SwiftProtobuf.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,9 @@
539539
F48FDD281E4D18060061D5C1 /* Test_TextFormat_proto3.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCCA0E751DB123F800957D74 /* Test_TextFormat_proto3.swift */; };
540540
F48FDD291E4D18080061D5C1 /* Test_TextFormat_proto2_extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9C5890A51DFF5EC8001CFC34 /* Test_TextFormat_proto2_extensions.swift */; };
541541
F48FDD2A1E4D18080061D5C1 /* Test_TextFormat_proto3.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCCA0E751DB123F800957D74 /* Test_TextFormat_proto3.swift */; };
542+
F498732323F307930077F336 /* unittest_swift_größ.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = F498732223F307930077F336 /* unittest_swift_größ.pb.swift */; };
543+
F498732423F307930077F336 /* unittest_swift_größ.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = F498732223F307930077F336 /* unittest_swift_größ.pb.swift */; };
544+
F498732523F307930077F336 /* unittest_swift_größ.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = F498732223F307930077F336 /* unittest_swift_größ.pb.swift */; };
542545
F49B576B2252771700350FFD /* TextFormatEncodingOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49B576A2252771700350FFD /* TextFormatEncodingOptions.swift */; };
543546
F49B576C2252771700350FFD /* TextFormatEncodingOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49B576A2252771700350FFD /* TextFormatEncodingOptions.swift */; };
544547
F49B576D2252771700350FFD /* TextFormatEncodingOptions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F49B576A2252771700350FFD /* TextFormatEncodingOptions.swift */; };
@@ -793,6 +796,7 @@
793796
F482B6911E857BBC00A25EF8 /* unittest_swift_naming_no_prefix.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = unittest_swift_naming_no_prefix.pb.swift; sourceTree = "<group>"; };
794797
F482B6B21E89940E00A25EF8 /* Version.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Version.swift; sourceTree = "<group>"; };
795798
F48769F723020B7D00D44224 /* descriptor.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = descriptor.pb.swift; sourceTree = "<group>"; };
799+
F498732223F307930077F336 /* unittest_swift_größ.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "unittest_swift_größ.pb.swift"; sourceTree = "<group>"; };
796800
F49B576A2252771700350FFD /* TextFormatEncodingOptions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFormatEncodingOptions.swift; sourceTree = "<group>"; };
797801
F4A07B2A1E4A3E500035678A /* test_messages_proto3.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = test_messages_proto3.pb.swift; sourceTree = "<group>"; };
798802
F4A1A8AB1E65E2EA0022E078 /* map_proto2_unittest.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = map_proto2_unittest.pb.swift; sourceTree = "<group>"; };
@@ -1168,6 +1172,7 @@
11681172
F4D315441DEC8110005D4A80 /* unittest_swift_extension3.pb.swift */,
11691173
F4D315521DECA0E5005D4A80 /* unittest_swift_extension4.pb.swift */,
11701174
__PBXFileRef_Tests/ProtobufTests/unittest_swift_fieldorder.pb.swift /* unittest_swift_fieldorder.pb.swift */,
1175+
F498732223F307930077F336 /* unittest_swift_größ.pb.swift */,
11711176
__PBXFileRef_Tests/ProtobufTests/unittest_swift_groups.pb.swift /* unittest_swift_groups.pb.swift */,
11721177
F482B6911E857BBC00A25EF8 /* unittest_swift_naming_no_prefix.pb.swift */,
11731178
F47CF9A023E88DD000C7B24C /* unittest_swift_naming_number_prefix.pb.swift */,
@@ -1427,6 +1432,7 @@
14271432
9C8CDA3A1D7A28F600E207CA /* Test_RecursiveMap.swift in Sources */,
14281433
9C60CBE91DF8AC3F00F7B14E /* Test_TextFormat_Map_proto3.swift in Sources */,
14291434
9C8CDA3B1D7A28F600E207CA /* Test_Required.swift in Sources */,
1435+
F498732423F307930077F336 /* unittest_swift_größ.pb.swift in Sources */,
14301436
9C8CDA3C1D7A28F600E207CA /* Test_Reserved.swift in Sources */,
14311437
9C8CDA3D1D7A28F600E207CA /* Test_Struct.swift in Sources */,
14321438
9C8CDA3E1D7A28F600E207CA /* Test_Timestamp.swift in Sources */,
@@ -1724,6 +1730,7 @@
17241730
9C60CBEC1DF9DEEA00F7B14E /* Test_TextFormat_proto2.swift in Sources */,
17251731
9C5890A71DFF5FFC001CFC34 /* Test_TextFormat_proto2_extensions.swift in Sources */,
17261732
BCCA0E7A1DB124B800957D74 /* Test_TextFormat_proto3.swift in Sources */,
1733+
F498732323F307930077F336 /* unittest_swift_größ.pb.swift in Sources */,
17271734
9CCD5F931E008203002D1940 /* Test_TextFormat_WKT_proto3.swift in Sources */,
17281735
F44F943A1DBFBB7400BC5B85 /* Test_BasicFields_Access_Proto3.swift in Sources */,
17291736
F44F94351DBF9AEA00BC5B85 /* Test_BasicFields_Access_Proto2.swift in Sources */,
@@ -1932,6 +1939,7 @@
19321939
9C60CBEE1DF9DEEA00F7B14E /* Test_TextFormat_proto2.swift in Sources */,
19331940
F44F93F81DAEA8C900BC5B85 /* unittest.pb.swift in Sources */,
19341941
F44F93E81DAEA8C900BC5B85 /* unittest_proto3_arena.pb.swift in Sources */,
1942+
F498732523F307930077F336 /* unittest_swift_größ.pb.swift in Sources */,
19351943
9C60CBEA1DF8AC3F00F7B14E /* Test_TextFormat_Map_proto3.swift in Sources */,
19361944
F44F93F21DAEA8C900BC5B85 /* unittest_swift_performance.pb.swift in Sources */,
19371945
F44F93B41DAEA8C900BC5B85 /* Test_Api.swift in Sources */,

Tests/LinuxMain.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,8 @@ extension Test_ValidIdentifiers {
780780
static var allTests = [
781781
("testFieldNames", testFieldNames),
782782
("testOneofNames", testOneofNames),
783-
("testEnumCaseNames", testEnumCaseNames)
783+
("testEnumCaseNames", testEnumCaseNames),
784+
("testExtensionMapNaming", testExtensionMapNaming)
784785
]
785786
}
786787

Tests/SwiftProtobufTests/Test_Naming.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,4 +910,9 @@ class Test_ValidIdentifiers: XCTestCase {
910910
msg.enumField = ._2
911911
msg.enumField = ._3Value
912912
}
913+
914+
func testExtensionMapNaming() {
915+
// Symbol should exist based on the unittest_swift_größ.proto name.
916+
let _ = UnittestSwiftGröß_Extensions
917+
}
913918
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// DO NOT EDIT.
2+
//
3+
// Generated by the Swift generator plugin for the protocol buffer compiler.
4+
// Source: unittest_swift_größ.proto
5+
//
6+
// For information on using the generated types, please see the documentation:
7+
// https://github.com/apple/swift-protobuf/
8+
9+
// Protos/unittest_swift_größ.proto - test proto
10+
//
11+
// This source file is part of the Swift.org open source project
12+
//
13+
// Copyright (c) 2020 Apple Inc. and the Swift project authors
14+
// Licensed under Apache License v2.0 with Runtime Library Exception
15+
//
16+
// See http://swift.org/LICENSE.txt for license information
17+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
18+
//
19+
// -----------------------------------------------------------------------------
20+
///
21+
/// Test Swift reserved words used as enum or message names
22+
///
23+
// -----------------------------------------------------------------------------
24+
25+
import Foundation
26+
import SwiftProtobuf
27+
28+
// If the compiler emits an error on this type, it is because this file
29+
// was generated by a version of the `protoc` Swift plug-in that is
30+
// incompatible with the version of SwiftProtobuf to which you are linking.
31+
// Please ensure that you are building against the same version of the API
32+
// that was used to generate this file.
33+
fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck {
34+
struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {}
35+
typealias Version = _2
36+
}
37+
38+
struct ToExtend: SwiftProtobuf.ExtensibleMessage {
39+
// SwiftProtobuf.Message conformance is added in an extension below. See the
40+
// `Message` and `Message+*Additions` files in the SwiftProtobuf library for
41+
// methods supported on all messages.
42+
43+
var unknownFields = SwiftProtobuf.UnknownStorage()
44+
45+
init() {}
46+
47+
var _protobuf_extensionFieldValues = SwiftProtobuf.ExtensionFieldValueSet()
48+
}
49+
50+
// MARK: - Extension support defined in unittest_swift_größ.proto.
51+
52+
extension ToExtend {
53+
54+
var added: Int32 {
55+
get {return getExtensionValue(ext: Extensions_added) ?? 0}
56+
set {setExtensionValue(ext: Extensions_added, value: newValue)}
57+
}
58+
/// Returns true if extension `Extensions_added`
59+
/// has been explicitly set.
60+
var hasAdded: Bool {
61+
return hasExtensionValue(ext: Extensions_added)
62+
}
63+
/// Clears the value of extension `Extensions_added`.
64+
/// Subsequent reads from it will return its default value.
65+
mutating func clearAdded() {
66+
clearExtensionValue(ext: Extensions_added)
67+
}
68+
69+
}
70+
71+
/// A `SwiftProtobuf.SimpleExtensionMap` that includes all of the extensions defined by
72+
/// this .proto file. It can be used any place an `SwiftProtobuf.ExtensionMap` is needed
73+
/// in parsing, or it can be combined with other `SwiftProtobuf.SimpleExtensionMap`s to create
74+
/// a larger `SwiftProtobuf.SimpleExtensionMap`.
75+
let UnittestSwiftGröß_Extensions: SwiftProtobuf.SimpleExtensionMap = [
76+
Extensions_added
77+
]
78+
79+
let Extensions_added = SwiftProtobuf.MessageExtension<SwiftProtobuf.OptionalExtensionField<SwiftProtobuf.ProtobufInt32>, ToExtend>(
80+
_protobuf_fieldNumber: 101,
81+
fieldName: "added"
82+
)
83+
84+
// MARK: - Code below here is support for the SwiftProtobuf runtime.
85+
86+
extension ToExtend: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
87+
static let protoMessageName: String = "ToExtend"
88+
static let _protobuf_nameMap = SwiftProtobuf._NameMap()
89+
90+
public var isInitialized: Bool {
91+
if !_protobuf_extensionFieldValues.isInitialized {return false}
92+
return true
93+
}
94+
95+
mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
96+
while let fieldNumber = try decoder.nextFieldNumber() {
97+
if (1 <= fieldNumber && fieldNumber < 5001) {
98+
try decoder.decodeExtensionField(values: &_protobuf_extensionFieldValues, messageType: ToExtend.self, fieldNumber: fieldNumber)
99+
}
100+
}
101+
}
102+
103+
func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
104+
try visitor.visitExtensionFields(fields: _protobuf_extensionFieldValues, start: 1, end: 5001)
105+
try unknownFields.traverse(visitor: &visitor)
106+
}
107+
108+
static func ==(lhs: ToExtend, rhs: ToExtend) -> Bool {
109+
if lhs.unknownFields != rhs.unknownFields {return false}
110+
if lhs._protobuf_extensionFieldValues != rhs._protobuf_extensionFieldValues {return false}
111+
return true
112+
}
113+
}

0 commit comments

Comments
 (0)