@@ -15,17 +15,18 @@ const simpleIntelHex: string =
1515 ':1000000000400020ED530100295401002B54010051\n' +
1616 ':00000001FF\n' ;
1717
18+ const pyCode = 'from microbit import *\n' + "display.scroll('Hello, World!')" ;
19+ const pyCodeHex =
20+ ':020000040003F7\n' +
21+ ':10E000004D50360066726F6D206D6963726F626984\n' +
22+ ':10E010007420696D706F7274202A0A646973706C61\n' +
23+ ':10E0200061792E7363726F6C6C282748656C6C6F16\n' +
24+ ':10E030002C20576F726C642127290000000000001B' ;
25+
26+ const marker = ':::::::::::::::::::::::::::::::::::::::::::' ;
27+
1828describe ( 'Inject Python code into Intel Hex string' , ( ) => {
1929 it ( 'Inject Python code into an Intel Hex string' , ( ) => {
20- const pyCode =
21- 'from microbit import *\n' + "display.scroll('Hello, World!')" ;
22- const pyCodeHex =
23- ':020000040003F7\n' +
24- ':10E000004D50360066726F6D206D6963726F626984\n' +
25- ':10E010007420696D706F7274202A0A646973706C61\n' +
26- ':10E0200061792E7363726F6C6C282748656C6C6F16\n' +
27- ':10E030002C20576F726C642127290000000000001B' ;
28-
2930 const output : string = addIntelHexAppendedScript ( simpleIntelHex , pyCode ) ;
3031
3132 const fullHex : string [ ] = simpleIntelHex . split ( '\n' ) ;
@@ -34,14 +35,6 @@ describe('Inject Python code into Intel Hex string', () => {
3435 } ) ;
3536
3637 it ( 'Inject Python with present UICR and Start Linear Address record' , ( ) => {
37- const pyCode : string =
38- 'from microbit import *\n' + "display.scroll('Hello, World!')" ;
39- const pyCodeHex : string =
40- ':020000040003F7\n' +
41- ':10E000004D50360066726F6D206D6963726F626984\n' +
42- ':10E010007420696D706F7274202A0A646973706C61\n' +
43- ':10E0200061792E7363726F6C6C282748656C6C6F16\n' +
44- ':10E030002C20576F726C642127290000000000001B\n' ;
4538 const uicr : string =
4639 ':020000041000EA\n' +
4740 ':1010C0007CB0EE17FFFFFFFF0A0000000000E30006\n' +
@@ -57,10 +50,30 @@ describe('Inject Python code into Intel Hex string', () => {
5750
5851 const expectedHex : string [ ] = simpleIntelHex . split ( '\n' ) ;
5952 // Note that the 05 record is removed by nrf-intel-hex library!
60- expectedHex . splice ( 2 , 0 , pyCodeHex + uicr ) ;
53+ expectedHex . splice ( 2 , 0 , pyCodeHex + '\n' + uicr ) ;
6154 expect ( output ) . toEqual ( expectedHex . join ( '\n' ) ) ;
6255 } ) ;
6356
57+ it ( 'Inject Python in a hex with a marker' , ( ) => {
58+ const fullHexWithMarker : string [ ] = simpleIntelHex . split ( '\n' ) ;
59+ fullHexWithMarker . splice ( 2 , 0 , marker ) ;
60+ const fullHexWithout : string [ ] = simpleIntelHex . split ( '\n' ) ;
61+ const expectedHex : string [ ] = simpleIntelHex . split ( '\n' ) ;
62+ expectedHex . splice ( 2 , 0 , pyCodeHex ) ;
63+
64+ const outputWithMarker : string = addIntelHexAppendedScript (
65+ fullHexWithMarker . join ( '\n' ) ,
66+ pyCode
67+ ) ;
68+ const outputWithout : string = addIntelHexAppendedScript (
69+ fullHexWithout . join ( '\n' ) ,
70+ pyCode
71+ ) ;
72+
73+ expect ( outputWithMarker ) . toEqual ( expectedHex . join ( '\n' ) ) ;
74+ expect ( outputWithMarker ) . toEqual ( outputWithout ) ;
75+ } ) ;
76+
6477 it ( 'Fail to inject Python code too large for flash' , ( ) => {
6578 const failCase = ( ) => {
6679 const fakeCode : string = new Array ( 8 * 1024 + 2 ) . join ( 'a' ) ;
@@ -75,9 +88,15 @@ describe('Inject Python code into Intel Hex string', () => {
7588
7689describe ( 'Extract Python code from Intel Hex string' , ( ) => {
7790 it ( 'Extract Python code' , ( ) => {
78- const pyCode : string =
79- 'from microbit import *\n' + "display.scroll('Hello, World!')" ;
80- const intelHex : string =
91+ const intelHex1 : string =
92+ ':020000040000FA\n' +
93+ ':1000000000400020ED530100295401002B54010051\n' +
94+ ':020000040003F7\n' +
95+ pyCodeHex +
96+ '\n' +
97+ ':00000001FF\n' ;
98+ // pyCodeHex contains zeros to fill the record, this example doesn't
99+ const intelHex2 : string =
81100 ':020000040000FA\n' +
82101 ':1000000000400020ED530100295401002B54010051\n' +
83102 ':020000040003F7\n' +
@@ -87,14 +106,14 @@ describe('Extract Python code from Intel Hex string', () => {
87106 ':0AE030002C20576F726C6421272921\n' +
88107 ':00000001FF\n' ;
89108
90- const result : string = getIntelHexAppendedScript ( intelHex ) ;
109+ const result1 : string = getIntelHexAppendedScript ( intelHex1 ) ;
110+ const result2 : string = getIntelHexAppendedScript ( intelHex2 ) ;
91111
92- expect ( result ) . toEqual ( pyCode ) ;
112+ expect ( result1 ) . toEqual ( pyCode ) ;
113+ expect ( result2 ) . toEqual ( pyCode ) ;
93114 } ) ;
94115
95116 it ( 'Extract Python code with present UICR and Start Linear Address record)' , ( ) => {
96- const pyCode : string =
97- 'from microbit import *\n' + "display.scroll('Hello, World!')" ;
98117 const intelHex : string =
99118 ':020000040000FA\n' +
100119 ':1000000000400020ED530100295401002B54010051\n' +
0 commit comments