Skip to content

Commit 31d8dbd

Browse files
committed
Add CodeExecution tool encoding test
1 parent 1301338 commit 31d8dbd

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

FirebaseAI/Tests/Unit/Types/ToolTests.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ final class ToolTests: XCTestCase {
2727

2828
func testEncodeTool_googleSearch() throws {
2929
let tool = Tool.googleSearch()
30+
3031
let jsonData = try encoder.encode(tool)
32+
3133
let jsonString = try XCTUnwrap(String(data: jsonData, encoding: .utf8))
3234
XCTAssertEqual(jsonString, """
3335
{
@@ -38,18 +40,31 @@ final class ToolTests: XCTestCase {
3840
""")
3941
}
4042

43+
func testEncodeTool_codeExecution() throws {
44+
let tool = Tool.codeExecution()
45+
46+
let jsonData = try encoder.encode(tool)
47+
48+
let jsonString = try XCTUnwrap(String(data: jsonData, encoding: .utf8))
49+
XCTAssertEqual(jsonString, """
50+
{
51+
"codeExecution" : {
52+
53+
}
54+
}
55+
""")
56+
}
57+
4158
func testEncodeTool_functionDeclarations() throws {
4259
let functionDecl = FunctionDeclaration(
4360
name: "test_function",
4461
description: "A test function.",
4562
parameters: ["param1": .string()]
4663
)
4764
let tool = Tool.functionDeclarations([functionDecl])
48-
49-
encoder.outputFormatting.insert(.withoutEscapingSlashes)
5065
let jsonData = try encoder.encode(tool)
51-
let jsonString = try XCTUnwrap(String(data: jsonData, encoding: .utf8))
5266

67+
let jsonString = try XCTUnwrap(String(data: jsonData, encoding: .utf8))
5368
XCTAssertEqual(jsonString, """
5469
{
5570
"functionDeclarations" : [

0 commit comments

Comments
 (0)