@@ -1016,6 +1016,21 @@ describe('Test importing files from Intel Hex.', () => {
1016
1016
} ) ;
1017
1017
} ) ;
1018
1018
1019
+ describe ( 'Test importing files from Universal Hex.' , ( ) => {
1020
+ // TODO: These tests
1021
+ // it('Correctly read files from a Universal Hex.', () => {});
1022
+ // it('Throws an error if it is not a Universal hex.', () => {});
1023
+ // it('Throws an error if there are no files to import.', () => {});
1024
+ // it('Throws an error if files in the individual hexes do not match.', () => {});
1025
+ // it('Disabled overwrite flag throws an error when file exists.', () => {});
1026
+ // it('Enabled overwrite flag replaces the file.', () => {});
1027
+ // it('By default it throws an error if a filename already exists.', () => {});
1028
+ // it('Constructor hex file with files to import throws an error.', () => {});
1029
+ // it('Enabling formatFirst flag erases the previous files.', () => {});
1030
+ // it('Enabling formatFirst flag only formats if there are files to import.', () => {});
1031
+ // it('Disabling formatFirst flag, and by default, keeps old files.', () => {});
1032
+ } ) ;
1033
+
1019
1034
describe ( 'Test MicroPython hex filesystem size.' , ( ) => {
1020
1035
it ( 'Get how much available fs space there is in a MicroPython hex file.' , ( ) => {
1021
1036
const micropythonFs = new MicropythonFsHex ( uPy1HexFile ) ;
@@ -1047,16 +1062,13 @@ describe('Test MicroPython hex filesystem size.', () => {
1047
1062
} ) ;
1048
1063
1049
1064
describe ( 'End-to-end loop around.' , ( ) => {
1050
- it ( 'Create some files, export hex, and import in a new instance' , ( ) => {
1065
+ it ( 'Create some files, export Intel hex, and import in a new instance' , ( ) => {
1051
1066
const microbitFs = new MicropythonFsHex ( uPy1HexFile ) ;
1052
1067
microbitFs . write ( 'a.txt' , 'This is some content' ) ;
1053
1068
microbitFs . write ( 'main.py' , 'print("This is my code")' ) ;
1054
-
1055
1069
const iHexWithFiles = microbitFs . getIntelHex ( ) ;
1056
- const microbitFsImported = new MicropythonFsHex ( [
1057
- { hex : uPy1HexFile , boardId : 0x9900 } ,
1058
- { hex : uPy2HexFile , boardId : 0x9903 } ,
1059
- ] ) ;
1070
+
1071
+ const microbitFsImported = new MicropythonFsHex ( uPy2HexFile ) ;
1060
1072
const importedFiles = microbitFsImported . importFilesFromIntelHex (
1061
1073
iHexWithFiles
1062
1074
) ;
@@ -1077,8 +1089,46 @@ describe('End-to-end loop around.', () => {
1077
1089
expect ( microbitFsImported . getStorageUsed ( ) ) . toEqual (
1078
1090
microbitFs . getStorageUsed ( )
1079
1091
) ;
1092
+ } ) ;
1093
+
1094
+ it ( 'Create some files, export Universal hex, and import in a new instance' , ( ) => {
1095
+ const microbitFs = new MicropythonFsHex ( [
1096
+ { hex : uPy1HexFile , boardId : microbitBoardId . V1 } ,
1097
+ { hex : uPy2HexFile , boardId : microbitBoardId . V2 } ,
1098
+ ] ) ;
1099
+ microbitFs . write ( 'a.txt' , 'This is some content' ) ;
1100
+ microbitFs . write ( 'main.py' , 'print("This is my code")' ) ;
1101
+ const uHexWithFiles = microbitFs . getUniversalHex ( ) ;
1102
+
1103
+ const microbitFsImported = new MicropythonFsHex ( [
1104
+ { hex : uPy1HexFile , boardId : microbitBoardId . V1 } ,
1105
+ { hex : uPy2HexFile , boardId : microbitBoardId . V2 } ,
1106
+ ] ) ;
1107
+ const importedFiles = microbitFsImported . importFilesFromHex ( uHexWithFiles ) ;
1108
+
1109
+ expect ( microbitFs . ls ( ) ) . toEqual ( importedFiles ) ;
1110
+ expect ( microbitFs . ls ( ) ) . toEqual ( [ 'a.txt' , 'main.py' ] ) ;
1111
+ expect ( microbitFsImported . ls ( ) ) . toEqual ( microbitFs . ls ( ) ) ;
1112
+
1113
+ expect ( microbitFs . read ( 'a.txt' ) ) . toEqual ( 'This is some content' ) ;
1114
+ expect ( microbitFsImported . read ( 'a.txt' ) ) . toEqual ( microbitFs . read ( 'a.txt' ) ) ;
1115
+
1116
+ expect ( microbitFsImported . readBytes ( 'a.txt' ) ) . toEqual (
1117
+ microbitFs . readBytes ( 'a.txt' )
1118
+ ) ;
1119
+
1120
+ expect ( microbitFsImported . size ( 'a.txt' ) ) . toEqual ( microbitFs . size ( 'a.txt' ) ) ;
1121
+
1122
+ expect ( microbitFsImported . getStorageUsed ( ) ) . toEqual (
1123
+ microbitFs . getStorageUsed ( )
1124
+ ) ;
1080
1125
1081
- expect ( microbitFsImported . getIntelHex ( 0x9900 ) ) . toEqual ( iHexWithFiles ) ;
1126
+ expect ( microbitFsImported . getIntelHex ( microbitBoardId . V1 ) ) . toEqual (
1127
+ microbitFs . getIntelHex ( microbitBoardId . V1 )
1128
+ ) ;
1129
+ expect ( microbitFsImported . getIntelHex ( microbitBoardId . V2 ) ) . toEqual (
1130
+ microbitFs . getIntelHex ( microbitBoardId . V2 )
1131
+ ) ;
1082
1132
} ) ;
1083
1133
} ) ;
1084
1134
0 commit comments