@@ -283,4 +283,48 @@ final class InternalPartTests: XCTestCase {
283
283
XCTAssertEqual ( functionResponse. name, functionName)
284
284
XCTAssertEqual ( functionResponse. response, [ " output " : . string( " someValue " ) ] )
285
285
}
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
+ }
286
330
}
0 commit comments