Skip to content

Commit b4b5676

Browse files
committed
Add InternalPartTests for ExecutedCode and CodeExecutionResult
1 parent 31d8dbd commit b4b5676

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

FirebaseAI/Tests/Unit/Types/InternalPartTests.swift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,48 @@ final class InternalPartTests: XCTestCase {
283283
XCTAssertEqual(functionResponse.name, functionName)
284284
XCTAssertEqual(functionResponse.response, ["output": .string("someValue")])
285285
}
286+
287+
func testDecodeExecutableCodePart() throws {
288+
let json = """
289+
{
290+
"executableCode": {
291+
"language": "PYTHON",
292+
"code": "print('hello')"
293+
}
294+
}
295+
"""
296+
let jsonData = try XCTUnwrap(json.data(using: .utf8))
297+
298+
let part = try decoder.decode(InternalPart.self, from: jsonData)
299+
300+
XCTAssertNil(part.isThought)
301+
guard case let .executableCode(executableCode) = part.data else {
302+
XCTFail("Decoded part is not an executableCode part.")
303+
return
304+
}
305+
XCTAssertEqual(executableCode.language, .init(kind: .python))
306+
XCTAssertEqual(executableCode.code, "print('hello')")
307+
}
308+
309+
func testDecodeCodeExecutionResultPart() throws {
310+
let json = """
311+
{
312+
"codeExecutionResult": {
313+
"outcome": "OUTCOME_OK",
314+
"output": "hello"
315+
}
316+
}
317+
"""
318+
let jsonData = try XCTUnwrap(json.data(using: .utf8))
319+
320+
let part = try decoder.decode(InternalPart.self, from: jsonData)
321+
322+
XCTAssertNil(part.isThought)
323+
guard case let .codeExecutionResult(codeExecutionResult) = part.data else {
324+
XCTFail("Decoded part is not a codeExecutionResult part.")
325+
return
326+
}
327+
XCTAssertEqual(codeExecutionResult.outcome, .init(kind: .ok))
328+
XCTAssertEqual(codeExecutionResult.output, "hello")
329+
}
286330
}

0 commit comments

Comments
 (0)