@@ -306,6 +306,67 @@ final class InternalPartTests: XCTestCase {
306
306
XCTAssertEqual ( executableCode. code, " print('hello') " )
307
307
}
308
308
309
+ func testDecodeExecutableCodePart_missingLanguage( ) throws {
310
+ let json = """
311
+ {
312
+ " executableCode " : {
313
+ " code " : " print('hello') "
314
+ }
315
+ }
316
+ """
317
+ let jsonData = try XCTUnwrap ( json. data ( using: . utf8) )
318
+
319
+ let part = try decoder. decode ( InternalPart . self, from: jsonData)
320
+
321
+ XCTAssertNil ( part. isThought)
322
+ guard case let . executableCode( executableCode) = part. data else {
323
+ XCTFail ( " Decoded part is not an executableCode part. " )
324
+ return
325
+ }
326
+ XCTAssertNil ( executableCode. language)
327
+ XCTAssertEqual ( executableCode. code, " print('hello') " )
328
+ }
329
+
330
+ func testDecodeExecutableCodePart_missingCode( ) throws {
331
+ let json = """
332
+ {
333
+ " executableCode " : {
334
+ " language " : " PYTHON "
335
+ }
336
+ }
337
+ """
338
+ let jsonData = try XCTUnwrap ( json. data ( using: . utf8) )
339
+
340
+ let part = try decoder. decode ( InternalPart . self, from: jsonData)
341
+
342
+ XCTAssertNil ( part. isThought)
343
+ guard case let . executableCode( executableCode) = part. data else {
344
+ XCTFail ( " Decoded part is not an executableCode part. " )
345
+ return
346
+ }
347
+ XCTAssertEqual ( executableCode. language, . init( kind: . python) )
348
+ XCTAssertNil ( executableCode. code)
349
+ }
350
+
351
+ func testDecodeExecutableCodePart_missingLanguageAndCode( ) throws {
352
+ let json = """
353
+ {
354
+ " executableCode " : {}
355
+ }
356
+ """
357
+ let jsonData = try XCTUnwrap ( json. data ( using: . utf8) )
358
+
359
+ let part = try decoder. decode ( InternalPart . self, from: jsonData)
360
+
361
+ XCTAssertNil ( part. isThought)
362
+ guard case let . executableCode( executableCode) = part. data else {
363
+ XCTFail ( " Decoded part is not an executableCode part. " )
364
+ return
365
+ }
366
+ XCTAssertNil ( executableCode. language)
367
+ XCTAssertNil ( executableCode. code)
368
+ }
369
+
309
370
func testDecodeCodeExecutionResultPart( ) throws {
310
371
let json = """
311
372
{
@@ -327,4 +388,65 @@ final class InternalPartTests: XCTestCase {
327
388
XCTAssertEqual ( codeExecutionResult. outcome, . init( kind: . ok) )
328
389
XCTAssertEqual ( codeExecutionResult. output, " hello " )
329
390
}
391
+
392
+ func testDecodeCodeExecutionResultPart_missingOutcome( ) throws {
393
+ let json = """
394
+ {
395
+ " codeExecutionResult " : {
396
+ " output " : " hello "
397
+ }
398
+ }
399
+ """
400
+ let jsonData = try XCTUnwrap ( json. data ( using: . utf8) )
401
+
402
+ let part = try decoder. decode ( InternalPart . self, from: jsonData)
403
+
404
+ XCTAssertNil ( part. isThought)
405
+ guard case let . codeExecutionResult( codeExecutionResult) = part. data else {
406
+ XCTFail ( " Decoded part is not a codeExecutionResult part. " )
407
+ return
408
+ }
409
+ XCTAssertNil ( codeExecutionResult. outcome)
410
+ XCTAssertEqual ( codeExecutionResult. output, " hello " )
411
+ }
412
+
413
+ func testDecodeCodeExecutionResultPart_missingOutput( ) throws {
414
+ let json = """
415
+ {
416
+ " codeExecutionResult " : {
417
+ " outcome " : " OUTCOME_OK "
418
+ }
419
+ }
420
+ """
421
+ let jsonData = try XCTUnwrap ( json. data ( using: . utf8) )
422
+
423
+ let part = try decoder. decode ( InternalPart . self, from: jsonData)
424
+
425
+ XCTAssertNil ( part. isThought)
426
+ guard case let . codeExecutionResult( codeExecutionResult) = part. data else {
427
+ XCTFail ( " Decoded part is not a codeExecutionResult part. " )
428
+ return
429
+ }
430
+ XCTAssertEqual ( codeExecutionResult. outcome, . init( kind: . ok) )
431
+ XCTAssertNil ( codeExecutionResult. output)
432
+ }
433
+
434
+ func testDecodeCodeExecutionResultPart_missingOutcomeAndOutput( ) throws {
435
+ let json = """
436
+ {
437
+ " codeExecutionResult " : {}
438
+ }
439
+ """
440
+ let jsonData = try XCTUnwrap ( json. data ( using: . utf8) )
441
+
442
+ let part = try decoder. decode ( InternalPart . self, from: jsonData)
443
+
444
+ XCTAssertNil ( part. isThought)
445
+ guard case let . codeExecutionResult( codeExecutionResult) = part. data else {
446
+ XCTFail ( " Decoded part is not a codeExecutionResult part. " )
447
+ return
448
+ }
449
+ XCTAssertNil ( codeExecutionResult. outcome)
450
+ XCTAssertNil ( codeExecutionResult. output)
451
+ }
330
452
}
0 commit comments