mirror of
https://github.com/apple/swift-protobuf.git
synced 2026-05-17 10:20:36 +00:00
3c93acf277
Fixes #1943 and supersedes #1979. This PR adds support for well known types in the Swift PM plugin by either: - Looking for the types next to the binary when the env variable or a direct protoc path is specified - Looking for the source directory of our vendored protobuf repo Co-authored-by: Thomas Van Lenten <thomasvl@google.com>
65 lines
1.6 KiB
Swift
65 lines
1.6 KiB
Swift
import CustomProtoPath
|
|
import Import
|
|
import Nested
|
|
import Simple
|
|
import UsesWKTs
|
|
import XCTest
|
|
|
|
#if compiler(>=6.2.3)
|
|
import Nonexhaustive
|
|
#endif
|
|
|
|
final class ExampleTests: XCTestCase {
|
|
func testSimple() {
|
|
let simple = Simple.with { $0.name = "Simple" }
|
|
XCTAssertEqual(simple.name, "Simple")
|
|
}
|
|
|
|
func testNested() {
|
|
let nested = Nested.with { $0.name = "Nested" }
|
|
XCTAssertEqual(nested.name, "Nested")
|
|
}
|
|
|
|
func testImport() {
|
|
let foo = Import.Foo.with { $0.bar = .with { $0.name = "Bar" } }
|
|
XCTAssertEqual(foo.bar.name, "Bar")
|
|
}
|
|
|
|
func testCustomProtoPath() {
|
|
let main = CustomProtoPath.Main.with {
|
|
$0.bar = .with { $0.name = "Bar" }
|
|
$0.foo = .with { $0.bar = .with { $0.name = "BarInFoo" } }
|
|
}
|
|
XCTAssertEqual(main.bar.name, "Bar")
|
|
XCTAssertEqual(main.foo.bar.name, "BarInFoo")
|
|
}
|
|
|
|
#if compiler(>=6.2.3)
|
|
func testNonexhaustive() {
|
|
let testEnum = TestEnum.valueA
|
|
switch testEnum {
|
|
case .valueA: break
|
|
case .valueB: break
|
|
case .unknown: break
|
|
case .UNRECOGNIZED: break
|
|
@unknown default: break
|
|
}
|
|
|
|
let testMessage = TestMessage.with { $0.payload = .text("test") }
|
|
switch testMessage.payload! {
|
|
case .text: break
|
|
case .data: break
|
|
@unknown default: break
|
|
}
|
|
}
|
|
#endif
|
|
func testUsesWKTs() {
|
|
let usesWKTs = UsesWKTs.with {
|
|
$0.name = "UsesWKTs"
|
|
$0.aTimestamp.seconds = 2
|
|
}
|
|
XCTAssertEqual(usesWKTs.name, "UsesWKTs")
|
|
XCTAssertEqual(usesWKTs.aTimestamp.seconds, 2)
|
|
}
|
|
}
|