@@ -411,20 +411,20 @@ describe('Test importing files from hex.', () => {
411
411
addIntelHexFileSpy . mockReset ( ) ;
412
412
} ) ;
413
413
414
- const hexStrWithFiles = ( ) : string => {
414
+ const createHexStrWithFiles = ( ) : string => {
415
415
const fullUpyFsMemMap = MemoryMap . fromHex ( uPyHexFile ) ;
416
416
const filesMap = MemoryMap . fromHex ( extraFilesHex ) ;
417
417
filesMap . forEach ( ( value : Uint8Array , index : number ) => {
418
418
fullUpyFsMemMap . set ( index , value ) ;
419
419
} ) ;
420
420
return fullUpyFsMemMap . asHexString ( ) ;
421
421
} ;
422
+ const hexStrWithFiles : string = createHexStrWithFiles ( ) ;
422
423
423
424
it ( 'Correctly read files from a hex.' , ( ) => {
424
- const hexWithFiles = hexStrWithFiles ( ) ;
425
425
const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
426
426
427
- const fileList = micropythonFs . importFilesFromIntelHex ( hexWithFiles ) ;
427
+ const fileList = micropythonFs . importFilesFromIntelHex ( hexStrWithFiles ) ;
428
428
429
429
Object . keys ( extraFiles ) . forEach ( ( filename ) => {
430
430
expect ( fileList ) . toContain ( filename ) ;
@@ -433,53 +433,55 @@ describe('Test importing files from hex.', () => {
433
433
} ) ;
434
434
435
435
it ( 'Disabled overwrite flag throws an error when file exists.' , ( ) => {
436
- const hexWithFiles = hexStrWithFiles ( ) ;
437
436
const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
438
437
const originalFileContent = 'Original file content.' ;
439
438
micropythonFs . write ( 'a.py' , originalFileContent ) ;
440
439
441
440
const failCase = ( ) => {
442
- micropythonFs . importFilesFromIntelHex ( hexWithFiles , false ) ;
441
+ micropythonFs . importFilesFromIntelHex ( hexStrWithFiles , false ) ;
443
442
} ;
444
443
445
444
expect ( failCase ) . toThrow ( Error ) ;
446
445
expect ( micropythonFs . read ( 'a.py' ) ) . toEqual ( originalFileContent ) ;
447
446
} ) ;
448
447
449
448
it ( 'Enabled overwrite flag replaces the file.' , ( ) => {
450
- const hexWithFiles = hexStrWithFiles ( ) ;
451
449
const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
452
450
const originalFileContent = 'Original file content.' ;
453
451
micropythonFs . write ( 'a.py' , originalFileContent ) ;
454
452
455
- micropythonFs . importFilesFromIntelHex ( hexWithFiles , true ) ;
453
+ micropythonFs . importFilesFromIntelHex ( hexStrWithFiles , true ) ;
456
454
457
455
expect ( micropythonFs . read ( 'a.py' ) ) . not . toEqual ( originalFileContent ) ;
458
456
expect ( micropythonFs . read ( 'a.py' ) ) . toEqual ( extraFiles [ 'a.py' ] ) ;
459
457
} ) ;
460
458
461
459
it ( 'By default it throws an error if a filename already exists.' , ( ) => {
462
- const hexWithFiles = hexStrWithFiles ( ) ;
463
460
const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
464
461
micropythonFs . write ( 'a.py' , 'some content' ) ;
465
462
466
463
const failCase = ( ) => {
467
- micropythonFs . importFilesFromIntelHex ( hexWithFiles ) ;
464
+ micropythonFs . importFilesFromIntelHex ( hexStrWithFiles ) ;
468
465
} ;
469
466
470
467
expect ( failCase ) . toThrow ( Error ) ;
471
468
} ) ;
472
469
473
470
it ( 'When files are imported it still uses the constructor hex file.' , ( ) => {
474
- const hexWithFiles = hexStrWithFiles ( ) ;
475
471
const micropythonFs = new MicropythonFsHex ( uPyHexFile ) ;
476
472
477
- micropythonFs . importFilesFromIntelHex ( hexWithFiles ) ;
473
+ micropythonFs . importFilesFromIntelHex ( hexStrWithFiles ) ;
478
474
const returnedIntelHex = micropythonFs . getIntelHex ( ) ;
479
475
480
476
expect ( addIntelHexFileSpy . mock . calls . length ) . toEqual ( 3 ) ;
481
477
expect ( addIntelHexFileSpy . mock . calls [ 0 ] [ 0 ] ) . toBe ( uPyHexFile ) ;
482
478
} ) ;
479
+
480
+ it ( 'Constructor hex file with files to import thorws an error.' , ( ) => {
481
+ const failCase = ( ) => new MicropythonFsHex ( hexStrWithFiles ) ;
482
+
483
+ expect ( failCase ) . toThrow ( Error ) ;
484
+ } ) ;
483
485
} ) ;
484
486
485
487
/*
0 commit comments