@@ -1077,7 +1077,6 @@ describe('Test createUniversalHex()', () => {
1077
1077
it ( 'Intel Hex without EoF record ends in one' , ( ) => {
1078
1078
const normalHex =
1079
1079
':020000040000FA\n' +
1080
- ':0400000A9900C0DEBB\n' +
1081
1080
':1000000000400020218E01005D8E01005F8E010006\n' +
1082
1081
':1000100000000000000000000000000000000000E0\n' +
1083
1082
':10002000000000000000000000000000618E0100E0\n' +
@@ -1106,7 +1105,6 @@ describe('Test createUniversalHex()', () => {
1106
1105
it ( 'Intel Hex with EoF in the middle throws errors' , ( ) => {
1107
1106
const normalHex =
1108
1107
':020000040000FA\n' +
1109
- ':0400000A9900C0DEBB\n' +
1110
1108
':1000000000400020218E01005D8E01005F8E010006\n' +
1111
1109
':1000100000000000000000000000000000000000E0\n' +
1112
1110
':10002000000000000000000000000000618E0100E0\n' +
@@ -1116,8 +1114,7 @@ describe('Test createUniversalHex()', () => {
1116
1114
':1000600069E80000D59A0100D9930100678E01006C\n' +
1117
1115
':10007000678E0100678E0100678E0100678E0100A8\n' +
1118
1116
':10008000678E0100678E0100678E0100678E010098\n' +
1119
- ':10009000678E01000D8A0100D98A0100A5E90000E0\n' +
1120
- ':0C00000BFFFFFFFFFFFFFFFFFFFFFFFFF5\n' ;
1117
+ ':10009000678E01000D8A0100D98A0100A5E90000E0\n' ;
1121
1118
const normalHexEof12 = normalHex . replace (
1122
1119
':10008000678E0100678E0100678E0100678E010098\n' ,
1123
1120
':10008000678E0100678E0100678E0100678E010098\n' + ':00000001FF\n'
@@ -1159,18 +1156,369 @@ describe('Test createUniversalHex()', () => {
1159
1156
} ;
1160
1157
1161
1158
expect ( failFirstBlocks ) . toThrow (
1162
- 'EoF record found at record 10 of 14 in Board ID 39168 hex'
1159
+ 'EoF record found at record 9 of 12 in Board ID 39168 hex'
1163
1160
) ;
1164
1161
expect ( failFirstSections ) . toThrow (
1165
- 'EoF record found at record 10 of 14 in Board ID 39168 hex'
1162
+ 'EoF record found at record 9 of 12 in Board ID 39168 hex'
1166
1163
) ;
1167
1164
expect ( failSecondBlocks ) . toThrow (
1168
- 'EoF record found at record 12 of 14 in Board ID 39171 hex'
1165
+ 'EoF record found at record 11 of 12 in Board ID 39171 hex'
1169
1166
) ;
1170
1167
expect ( failSecondSections ) . toThrow (
1171
- 'EoF record found at record 12 of 14 in Board ID 39171 hex'
1168
+ 'EoF record found at record 11 of 12 in Board ID 39171 hex'
1172
1169
) ;
1173
1170
} ) ;
1171
+
1172
+ it ( 'Universal Hex input throws errors' , ( ) => {
1173
+ const normalHex =
1174
+ ':020000040000FA\n' +
1175
+ ':1000000000400020218E01005D8E01005F8E010006\n' +
1176
+ ':1000100000000000000000000000000000000000E0\n' +
1177
+ ':10002000000000000000000000000000618E0100E0\n' +
1178
+ ':100030000000000000000000638E0100658E0100DA\n' +
1179
+ ':10004000678E01005D3D000065950100678E01002F\n' +
1180
+ ':10005000678E010000000000218F0100678E010003\n' +
1181
+ ':1000600069E80000D59A0100D9930100678E01006C\n' +
1182
+ ':10007000678E0100678E0100678E0100678E0100A8\n' +
1183
+ ':10008000678E0100678E0100678E0100678E010098\n' +
1184
+ ':10009000678E01000D8A0100D98A0100A5E90000E0\n' +
1185
+ ':0C00000BFFFFFFFFFFFFFFFFFFFFFFFFF5\n' +
1186
+ ':00000001FF\n' ;
1187
+ const universalHex =
1188
+ ':020000040000FA\n' +
1189
+ ':0400000A9900C0DEBB\n' +
1190
+ ':1000000000400020218E01005D8E01005F8E010006\n' +
1191
+ ':1000100000000000000000000000000000000000E0\n' +
1192
+ ':10002000000000000000000000000000618E0100E0\n' +
1193
+ ':100030000000000000000000638E0100658E0100DA\n' +
1194
+ ':10004000678E01005D3D000065950100678E01002F\n' +
1195
+ ':10005000678E010000000000218F0100678E010003\n' +
1196
+ ':1000600069E80000D59A0100D9930100678E01006C\n' +
1197
+ ':10007000678E0100678E0100678E0100678E0100A8\n' +
1198
+ ':10008000678E0100678E0100678E0100678E010098\n' +
1199
+ ':10009000678E01000D8A0100D98A0100A5E90000E0\n' +
1200
+ ':0C00000BFFFFFFFFFFFFFFFFFFFFFFFFF5\n' +
1201
+ ':00000001FF\n' ;
1202
+
1203
+ const failFirstBlocks = ( ) => {
1204
+ const result = uh . createUniversalHex (
1205
+ [
1206
+ { hex : universalHex , boardId : 0x9900 } ,
1207
+ { hex : normalHex , boardId : 0x9903 } ,
1208
+ ] ,
1209
+ true
1210
+ ) ;
1211
+ } ;
1212
+ const failFirstSections = ( ) => {
1213
+ const result = uh . createUniversalHex (
1214
+ [
1215
+ { hex : universalHex , boardId : 0x9900 } ,
1216
+ { hex : normalHex , boardId : 0x9903 } ,
1217
+ ] ,
1218
+ false
1219
+ ) ;
1220
+ } ;
1221
+ const failSecondBlocks = ( ) => {
1222
+ const result = uh . createUniversalHex (
1223
+ [
1224
+ { hex : normalHex , boardId : 0x9900 } ,
1225
+ { hex : universalHex , boardId : 0x9903 } ,
1226
+ ] ,
1227
+ true
1228
+ ) ;
1229
+ } ;
1230
+ const failSecondSections = ( ) => {
1231
+ const result = uh . createUniversalHex ( [
1232
+ { hex : normalHex , boardId : 0x9900 } ,
1233
+ { hex : universalHex , boardId : 0x9903 } ,
1234
+ ] ) ;
1235
+ } ;
1236
+
1237
+ expect ( failFirstBlocks ) . toThrow (
1238
+ 'Board ID 39168 Hex is already a Universal Hex'
1239
+ ) ;
1240
+ expect ( failFirstSections ) . toThrow (
1241
+ 'Board ID 39168 Hex is already a Universal Hex'
1242
+ ) ;
1243
+ expect ( failSecondBlocks ) . toThrow (
1244
+ 'Board ID 39171 Hex is already a Universal Hex'
1245
+ ) ;
1246
+ expect ( failSecondSections ) . toThrow (
1247
+ 'Board ID 39171 Hex is already a Universal Hex'
1248
+ ) ;
1249
+ } ) ;
1250
+
1251
+ it ( 'MakeCode v1 and v2 Hex (micro:bit V1) throws custom error message' , ( ) => {
1252
+ const normalHex =
1253
+ ':020000040000FA\n' +
1254
+ ':1000000000400020218E01005D8E01005F8E010006\n' +
1255
+ ':1000100000000000000000000000000000000000E0\n' +
1256
+ ':10002000000000000000000000000000618E0100E0\n' +
1257
+ ':100030000000000000000000638E0100658E0100DA\n' +
1258
+ ':10004000678E01005D3D000065950100678E01002F\n' +
1259
+ ':10005000678E010000000000218F0100678E010003\n' +
1260
+ ':1000600069E80000D59A0100D9930100678E01006C\n' +
1261
+ ':10007000678E0100678E0100678E0100678E0100A8\n' +
1262
+ ':10008000678E0100678E0100678E0100678E010098\n' +
1263
+ ':10009000678E01000D8A0100D98A0100A5E90000E0\n' +
1264
+ ':0C00000BFFFFFFFFFFFFFFFFFFFFFFFFF5\n' +
1265
+ ':00000001FF\n' ;
1266
+ const microbitV1MakecodeV0 =
1267
+ ':020000040000FA\n' +
1268
+ ':1000000000400020218E01005D8E01005F8E010006\n' +
1269
+ ':1000100000000000000000000000000000000000E0\n' +
1270
+ ':020000042000DA\n' +
1271
+ ':1000000041140E2FB82FA2BB9A005F02000000001F\n' +
1272
+ ':100010007B22636F6D7072657373696F6E223A2213\n' +
1273
+ ':00000001FF\n' +
1274
+ '\n' ;
1275
+ const microbitV1MakecodeV1 =
1276
+ ':020000040000FA\n' +
1277
+ ':1000000000400020218E01005D8E01005F8E010006\n' +
1278
+ ':1000100000000000000000000000000000000000E0\n' +
1279
+ ':00000001FF\n' +
1280
+ '\n' +
1281
+ ':020000042000DA\n' +
1282
+ ':1000000041140E2FB82FA2BB9A005F02000000001F\n' +
1283
+ ':100010007B22636F6D7072657373696F6E223A2213\n' +
1284
+ '\n' ;
1285
+ const microbitV1MakecodeV2 =
1286
+ ':020000040000FA\n' +
1287
+ ':1000000000400020218E01005D8E01005F8E010006\n' +
1288
+ ':1000100000000000000000000000000000000000E0\n' +
1289
+ ':00000001FF\n' +
1290
+ '\n' +
1291
+ '\n' +
1292
+ '\n' +
1293
+ ':1000000E41140E2FB82FA2BB9A006E020000000002\n' +
1294
+ ':1000100E7B22636F6D7072657373696F6E223A2205\n' +
1295
+ '\n' +
1296
+ '\n' ;
1297
+
1298
+ const failFirstV0Blocks = ( ) => {
1299
+ const result = uh . createUniversalHex (
1300
+ [
1301
+ { hex : microbitV1MakecodeV0 , boardId : 0x9900 } ,
1302
+ { hex : normalHex , boardId : 0x9903 } ,
1303
+ ] ,
1304
+ true
1305
+ ) ;
1306
+ } ;
1307
+ const failFirstV1Blocks = ( ) => {
1308
+ const result = uh . createUniversalHex (
1309
+ [
1310
+ { hex : microbitV1MakecodeV1 , boardId : 0x9900 } ,
1311
+ { hex : normalHex , boardId : 0x9903 } ,
1312
+ ] ,
1313
+ true
1314
+ ) ;
1315
+ } ;
1316
+ const failFirstV2Blocks = ( ) => {
1317
+ const result = uh . createUniversalHex (
1318
+ [
1319
+ { hex : microbitV1MakecodeV2 , boardId : 0x9900 } ,
1320
+ { hex : normalHex , boardId : 0x9903 } ,
1321
+ ] ,
1322
+ true
1323
+ ) ;
1324
+ } ;
1325
+ const failFirstV0Sections = ( ) => {
1326
+ const result = uh . createUniversalHex (
1327
+ [
1328
+ { hex : microbitV1MakecodeV0 , boardId : 0x9900 } ,
1329
+ { hex : normalHex , boardId : 0x9903 } ,
1330
+ ] ,
1331
+ false
1332
+ ) ;
1333
+ } ;
1334
+ const failFirstV1Sections = ( ) => {
1335
+ const result = uh . createUniversalHex (
1336
+ [
1337
+ { hex : microbitV1MakecodeV1 , boardId : 0x9900 } ,
1338
+ { hex : normalHex , boardId : 0x9903 } ,
1339
+ ] ,
1340
+ false
1341
+ ) ;
1342
+ } ;
1343
+ const failFirstV2Sections = ( ) => {
1344
+ const result = uh . createUniversalHex (
1345
+ [
1346
+ { hex : microbitV1MakecodeV2 , boardId : 0x9900 } ,
1347
+ { hex : normalHex , boardId : 0x9903 } ,
1348
+ ] ,
1349
+ false
1350
+ ) ;
1351
+ } ;
1352
+ const failSecondV0Blocks = ( ) => {
1353
+ const result = uh . createUniversalHex (
1354
+ [
1355
+ { hex : normalHex , boardId : 0x9900 } ,
1356
+ { hex : microbitV1MakecodeV0 , boardId : 0x9903 } ,
1357
+ ] ,
1358
+ true
1359
+ ) ;
1360
+ } ;
1361
+ const failSecondV1Blocks = ( ) => {
1362
+ const result = uh . createUniversalHex (
1363
+ [
1364
+ { hex : normalHex , boardId : 0x9900 } ,
1365
+ { hex : microbitV1MakecodeV1 , boardId : 0x9903 } ,
1366
+ ] ,
1367
+ true
1368
+ ) ;
1369
+ } ;
1370
+ const failSecondV2Blocks = ( ) => {
1371
+ const result = uh . createUniversalHex (
1372
+ [
1373
+ { hex : normalHex , boardId : 0x9900 } ,
1374
+ { hex : microbitV1MakecodeV2 , boardId : 0x9903 } ,
1375
+ ] ,
1376
+ true
1377
+ ) ;
1378
+ } ;
1379
+ const failSecondV0Sections = ( ) => {
1380
+ const result = uh . createUniversalHex (
1381
+ [
1382
+ { hex : normalHex , boardId : 0x9900 } ,
1383
+ { hex : microbitV1MakecodeV0 , boardId : 0x9903 } ,
1384
+ ] ,
1385
+ false
1386
+ ) ;
1387
+ } ;
1388
+ const failSecondV1Sections = ( ) => {
1389
+ const result = uh . createUniversalHex (
1390
+ [
1391
+ { hex : normalHex , boardId : 0x9900 } ,
1392
+ { hex : microbitV1MakecodeV1 , boardId : 0x9903 } ,
1393
+ ] ,
1394
+ false
1395
+ ) ;
1396
+ } ;
1397
+ const failSecondV2Sections = ( ) => {
1398
+ const result = uh . createUniversalHex (
1399
+ [
1400
+ { hex : normalHex , boardId : 0x9900 } ,
1401
+ { hex : microbitV1MakecodeV2 , boardId : 0x9903 } ,
1402
+ ] ,
1403
+ false
1404
+ ) ;
1405
+ } ;
1406
+
1407
+ // To avoid performing too many checks that'll slow down createUniversalHex
1408
+ // the V0 hex files will be able to be detected, and the MakeCode hex check
1409
+ // is only performed when an E0F record is not at the end of the hex file
1410
+ // expect(failFirstV0Blocks).toThrow(
1411
+ // 'Board ID 39168 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex'
1412
+ // );
1413
+ expect ( failFirstV1Blocks ) . toThrow (
1414
+ 'Board ID 39168 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex'
1415
+ ) ;
1416
+ expect ( failFirstV2Blocks ) . toThrow (
1417
+ 'Board ID 39168 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex.'
1418
+ ) ;
1419
+ // expect(failFirstV0Sections).toThrow(
1420
+ // 'Board ID 39168 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex.'
1421
+ // );
1422
+ expect ( failFirstV1Sections ) . toThrow (
1423
+ 'Board ID 39168 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex.'
1424
+ ) ;
1425
+ expect ( failFirstV2Sections ) . toThrow (
1426
+ 'Board ID 39168 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex.'
1427
+ ) ;
1428
+ // expect(failSecondV0Blocks).toThrow(
1429
+ // 'Board ID 39171 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex'
1430
+ // );
1431
+ expect ( failSecondV1Blocks ) . toThrow (
1432
+ 'Board ID 39171 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex'
1433
+ ) ;
1434
+ expect ( failSecondV2Blocks ) . toThrow (
1435
+ 'Board ID 39171 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex.'
1436
+ ) ;
1437
+ // expect(failSecondV0Sections).toThrow(
1438
+ // 'Board ID 39171 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex.'
1439
+ // );
1440
+ expect ( failSecondV1Sections ) . toThrow (
1441
+ 'Board ID 39171 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex.'
1442
+ ) ;
1443
+ expect ( failSecondV2Sections ) . toThrow (
1444
+ 'Board ID 39171 Hex is from MakeCode, import this hex into the MakeCode editor to create a Universal Hex.'
1445
+ ) ;
1446
+ } ) ;
1447
+ } ) ;
1448
+
1449
+ describe ( 'Test isUniversalHex()' , ( ) => {
1450
+ it ( 'Detects a MakeCode V0 hex for micro:bit V1.' , ( ) => {
1451
+ const microbitV1MakecodeV0 =
1452
+ ':020000040000FA\n' +
1453
+ ':1000000000400020218E01005D8E01005F8E010006\n' +
1454
+ ':1000100000000000000000000000000000000000E0\n' +
1455
+ ':020000042000DA\n' +
1456
+ ':1000000041140E2FB82FA2BB9A005F02000000001F\n' +
1457
+ ':100010007B22636F6D7072657373696F6E223A2213\n' +
1458
+ ':00000001FF\n' +
1459
+ '\n' ;
1460
+
1461
+ const result = uh . isMakeCodeForV1Hex ( microbitV1MakecodeV0 ) ;
1462
+
1463
+ expect ( result ) . toBeTruthy ( ) ;
1464
+ } ) ;
1465
+
1466
+ it ( 'Detects a MakeCode V1 hex for micro:bit V1.' , ( ) => {
1467
+ const microbitV1MakecodeV1 =
1468
+ ':020000040000FA\n' +
1469
+ ':1000000000400020218E01005D8E01005F8E010006\n' +
1470
+ ':1000100000000000000000000000000000000000E0\n' +
1471
+ ':00000001FF\n' +
1472
+ '\n' +
1473
+ ':020000042000DA\n' +
1474
+ ':1000000041140E2FB82FA2BB9A005F02000000001F\n' +
1475
+ ':100010007B22636F6D7072657373696F6E223A2213\n' +
1476
+ '\n' ;
1477
+
1478
+ const result = uh . isMakeCodeForV1Hex ( microbitV1MakecodeV1 ) ;
1479
+
1480
+ expect ( result ) . toBeTruthy ( ) ;
1481
+ } ) ;
1482
+
1483
+ it ( 'Detects a MakeCode V2/V3 hex for micro:bit V1.' , ( ) => {
1484
+ const microbitV1MakecodeV2 =
1485
+ ':020000040000FA\n' +
1486
+ ':1000000000400020218E01005D8E01005F8E010006\n' +
1487
+ ':1000100000000000000000000000000000000000E0\n' +
1488
+ ':00000001FF\n' +
1489
+ '\n' +
1490
+ '\n' +
1491
+ '\n' +
1492
+ ':1000000E41140E2FB82FA2BB9A006E020000000002\n' +
1493
+ ':1000100E7B22636F6D7072657373696F6E223A2205\n' +
1494
+ '\n' +
1495
+ '\n' ;
1496
+
1497
+ const result = uh . isMakeCodeForV1Hex ( microbitV1MakecodeV2 ) ;
1498
+
1499
+ expect ( result ) . toBeTruthy ( ) ;
1500
+ } ) ;
1501
+
1502
+ it ( 'A normal non MakeCode Intel Hex is not a false positive.' , ( ) => {
1503
+ const normalHex =
1504
+ ':020000040000FA\n' +
1505
+ ':1000000000400020218E01005D8E01005F8E010006\n' +
1506
+ ':1000100000000000000000000000000000000000E0\n' +
1507
+ ':10002000000000000000000000000000618E0100E0\n' +
1508
+ ':100030000000000000000000638E0100658E0100DA\n' +
1509
+ ':10004000678E01005D3D000065950100678E01002F\n' +
1510
+ ':10005000678E010000000000218F0100678E010003\n' +
1511
+ ':1000600069E80000D59A0100D9930100678E01006C\n' +
1512
+ ':10007000678E0100678E0100678E0100678E0100A8\n' +
1513
+ ':10008000678E0100678E0100678E0100678E010098\n' +
1514
+ ':10009000678E01000D8A0100D98A0100A5E90000E0\n' +
1515
+ ':0C00000BFFFFFFFFFFFFFFFFFFFFFFFFF5\n' +
1516
+ ':00000001FF\n' ;
1517
+
1518
+ const result = uh . isMakeCodeForV1Hex ( normalHex ) ;
1519
+
1520
+ expect ( result ) . toBeFalsy ( ) ;
1521
+ } ) ;
1174
1522
} ) ;
1175
1523
1176
1524
describe ( 'Test isUniversalHex()' , ( ) => {
0 commit comments