@@ -86,6 +86,40 @@ final class PartTests: XCTestCase {
86
86
XCTAssertEqual ( functionResponse. response, [ resultParameter: . string( resultValue) ] )
87
87
}
88
88
89
+ func testDecodeExecutableCodePart( ) throws {
90
+ let json = """
91
+ {
92
+ " executableCode " : {
93
+ " language " : " PYTHON " ,
94
+ " code " : " print('hello') "
95
+ }
96
+ }
97
+ """
98
+ let jsonData = try XCTUnwrap ( json. data ( using: . utf8) )
99
+
100
+ let part = try decoder. decode ( ExecutableCodePart . self, from: jsonData)
101
+
102
+ XCTAssertEqual ( part. language, . python)
103
+ XCTAssertEqual ( part. code, " print('hello') " )
104
+ }
105
+
106
+ func testDecodeCodeExecutionResultPart( ) throws {
107
+ let json = """
108
+ {
109
+ " codeExecutionResult " : {
110
+ " outcome " : " OUTCOME_OK " ,
111
+ " output " : " hello "
112
+ }
113
+ }
114
+ """
115
+ let jsonData = try XCTUnwrap ( json. data ( using: . utf8) )
116
+
117
+ let part = try decoder. decode ( CodeExecutionResultPart . self, from: jsonData)
118
+
119
+ XCTAssertEqual ( part. outcome, . ok)
120
+ XCTAssertEqual ( part. output, " hello " )
121
+ }
122
+
89
123
// MARK: - Part Encoding
90
124
91
125
func testEncodeTextPart( ) throws {
@@ -139,6 +173,38 @@ final class PartTests: XCTestCase {
139
173
""" )
140
174
}
141
175
176
+ func testEncodeExecutableCodePart( ) throws {
177
+ let executableCodePart = ExecutableCodePart ( language: . python, code: " print('hello') " )
178
+
179
+ let jsonData = try encoder. encode ( executableCodePart)
180
+
181
+ let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
182
+ XCTAssertEqual ( json, """
183
+ {
184
+ " executableCode " : {
185
+ " code " : " print('hello') " ,
186
+ " language " : " PYTHON "
187
+ }
188
+ }
189
+ """ )
190
+ }
191
+
192
+ func testEncodeCodeExecutionResultPart( ) throws {
193
+ let codeExecutionResultPart = CodeExecutionResultPart ( outcome: . ok, output: " hello " )
194
+
195
+ let jsonData = try encoder. encode ( codeExecutionResultPart)
196
+
197
+ let json = try XCTUnwrap ( String ( data: jsonData, encoding: . utf8) )
198
+ XCTAssertEqual ( json, """
199
+ {
200
+ " codeExecutionResult " : {
201
+ " outcome " : " OUTCOME_OK " ,
202
+ " output " : " hello "
203
+ }
204
+ }
205
+ """ )
206
+ }
207
+
142
208
// MARK: - Helpers
143
209
144
210
private static func bundle( ) -> Bundle {
0 commit comments