Skip to content

Commit 35866d5

Browse files
committed
Add decoding tests with and without "thought": true
1 parent 1162598 commit 35866d5

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

FirebaseAI/Tests/Unit/Types/InternalPartTests.swift

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,30 @@ final class InternalPartTests: XCTestCase {
284284
XCTAssertEqual(functionResponse.response, ["output": .string("someValue")])
285285
}
286286

287-
func testDecodeExecutableCodePart() throws {
287+
func testDecodeExecutableCodePartWithThought() throws {
288+
let json = """
289+
{
290+
"executableCode": {
291+
"language": "PYTHON",
292+
"code": "print('hello')"
293+
},
294+
"thought": true
295+
}
296+
"""
297+
let jsonData = try XCTUnwrap(json.data(using: .utf8))
298+
299+
let part = try decoder.decode(InternalPart.self, from: jsonData)
300+
301+
XCTAssertEqual(part.isThought, true)
302+
guard case let .executableCode(executableCode) = part.data else {
303+
XCTFail("Decoded part is not an executableCode part.")
304+
return
305+
}
306+
XCTAssertEqual(executableCode.language, .init(kind: .python))
307+
XCTAssertEqual(executableCode.code, "print('hello')")
308+
}
309+
310+
func testDecodeExecutableCodePartWithoutThought() throws {
288311
let json = """
289312
{
290313
"executableCode": {
@@ -367,7 +390,30 @@ final class InternalPartTests: XCTestCase {
367390
XCTAssertNil(executableCode.code)
368391
}
369392

370-
func testDecodeCodeExecutionResultPart() throws {
393+
func testDecodeCodeExecutionResultPartWithThought() throws {
394+
let json = """
395+
{
396+
"codeExecutionResult": {
397+
"outcome": "OUTCOME_OK",
398+
"output": "hello"
399+
},
400+
"thought": true
401+
}
402+
"""
403+
let jsonData = try XCTUnwrap(json.data(using: .utf8))
404+
405+
let part = try decoder.decode(InternalPart.self, from: jsonData)
406+
407+
XCTAssertEqual(part.isThought, true)
408+
guard case let .codeExecutionResult(codeExecutionResult) = part.data else {
409+
XCTFail("Decoded part is not a codeExecutionResult part.")
410+
return
411+
}
412+
XCTAssertEqual(codeExecutionResult.outcome, .init(kind: .ok))
413+
XCTAssertEqual(codeExecutionResult.output, "hello")
414+
}
415+
416+
func testDecodeCodeExecutionResultPartWithoutThought() throws {
371417
let json = """
372418
{
373419
"codeExecutionResult": {

0 commit comments

Comments
 (0)