@@ -15,17 +15,18 @@ const simpleIntelHex: string =
15
15
':1000000000400020ED530100295401002B54010051\n' +
16
16
':00000001FF\n' ;
17
17
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
+
18
28
describe ( 'Inject Python code into Intel Hex string' , ( ) => {
19
29
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
-
29
30
const output : string = addIntelHexAppendedScript ( simpleIntelHex , pyCode ) ;
30
31
31
32
const fullHex : string [ ] = simpleIntelHex . split ( '\n' ) ;
@@ -34,14 +35,6 @@ describe('Inject Python code into Intel Hex string', () => {
34
35
} ) ;
35
36
36
37
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' ;
45
38
const uicr : string =
46
39
':020000041000EA\n' +
47
40
':1010C0007CB0EE17FFFFFFFF0A0000000000E30006\n' +
@@ -57,10 +50,30 @@ describe('Inject Python code into Intel Hex string', () => {
57
50
58
51
const expectedHex : string [ ] = simpleIntelHex . split ( '\n' ) ;
59
52
// 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 ) ;
61
54
expect ( output ) . toEqual ( expectedHex . join ( '\n' ) ) ;
62
55
} ) ;
63
56
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
+
64
77
it ( 'Fail to inject Python code too large for flash' , ( ) => {
65
78
const failCase = ( ) => {
66
79
const fakeCode : string = new Array ( 8 * 1024 + 2 ) . join ( 'a' ) ;
@@ -75,9 +88,15 @@ describe('Inject Python code into Intel Hex string', () => {
75
88
76
89
describe ( 'Extract Python code from Intel Hex string' , ( ) => {
77
90
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 =
81
100
':020000040000FA\n' +
82
101
':1000000000400020ED530100295401002B54010051\n' +
83
102
':020000040003F7\n' +
@@ -87,14 +106,14 @@ describe('Extract Python code from Intel Hex string', () => {
87
106
':0AE030002C20576F726C6421272921\n' +
88
107
':00000001FF\n' ;
89
108
90
- const result : string = getIntelHexAppendedScript ( intelHex ) ;
109
+ const result1 : string = getIntelHexAppendedScript ( intelHex1 ) ;
110
+ const result2 : string = getIntelHexAppendedScript ( intelHex2 ) ;
91
111
92
- expect ( result ) . toEqual ( pyCode ) ;
112
+ expect ( result1 ) . toEqual ( pyCode ) ;
113
+ expect ( result2 ) . toEqual ( pyCode ) ;
93
114
} ) ;
94
115
95
116
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!')" ;
98
117
const intelHex : string =
99
118
':020000040000FA\n' +
100
119
':1000000000400020ED530100295401002B54010051\n' +
0 commit comments