From fad5c49c4e947f58f61d12a54b52e1465f4ca6ba Mon Sep 17 00:00:00 2001 From: Andrew Heard Date: Tue, 16 Apr 2024 12:14:19 -0400 Subject: [PATCH] Add public API tests for `GenerateContentResponse` (#133) --- Sources/GoogleAI/GenerateContentResponse.swift | 2 +- Tests/GoogleAITests/GoogleAITests.swift | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Sources/GoogleAI/GenerateContentResponse.swift b/Sources/GoogleAI/GenerateContentResponse.swift index 5cfa5ae..4b639c0 100644 --- a/Sources/GoogleAI/GenerateContentResponse.swift +++ b/Sources/GoogleAI/GenerateContentResponse.swift @@ -51,7 +51,7 @@ public struct GenerateContentResponse { } /// Initializer for SwiftUI previews or tests. - public init(candidates: [CandidateResponse], promptFeedback: PromptFeedback?) { + public init(candidates: [CandidateResponse], promptFeedback: PromptFeedback? = nil) { self.candidates = candidates self.promptFeedback = promptFeedback } diff --git a/Tests/GoogleAITests/GoogleAITests.swift b/Tests/GoogleAITests/GoogleAITests.swift index c0764bb..90b6fa6 100644 --- a/Tests/GoogleAITests/GoogleAITests.swift +++ b/Tests/GoogleAITests/GoogleAITests.swift @@ -149,6 +149,18 @@ final class GoogleGenerativeAITests: XCTestCase { _ = genAI.startChat(history: [ModelContent(parts: "abc")]) } + // Public API tests for GenerateContentResponse. + func generateContentResponseAPI() { + let response = GenerateContentResponse(candidates: []) + + let _: [CandidateResponse] = response.candidates + let _: PromptFeedback? = response.promptFeedback + + // Computed Properties + let _: String? = response.text + let _: [FunctionCall] = response.functionCalls + } + // Result builder alternative /*