@@ -8,32 +8,30 @@ import * as ihex from '../ihex';
8
8
9
9
describe ( 'Test createRecord() for standard records' , ( ) => {
10
10
it ( 'Creates standard data records' , ( ) => {
11
+ let a = [ 0x64 , 0x27 , 0x00 , 0x20 , 0x03 , 0x4b , 0x19 , 0x60 ] ;
12
+ let b = [ 0x43 , 0x68 , 0x03 , 0x49 , 0x9b , 0x00 , 0x5a , 0x50 ] ;
11
13
// Examples taken from a random micro:bit hex file
12
14
expect (
13
15
ihex . createRecord (
14
16
0x4290 ,
15
17
ihex . RecordType . Data ,
16
- new Uint8Array ( [
17
- 0x64 ,
18
- 0x27 ,
19
- 0x00 ,
20
- 0x20 ,
21
- 0x03 ,
22
- 0x4b ,
23
- 0x19 ,
24
- 0x60 ,
25
- 0x43 ,
26
- 0x68 ,
27
- 0x03 ,
28
- 0x49 ,
29
- 0x9b ,
30
- 0x00 ,
31
- 0x5a ,
32
- 0x50 ,
33
- ] )
18
+ new Uint8Array ( a . concat ( b ) )
34
19
)
35
20
) . toEqual ( ':1042900064270020034B1960436803499B005A5070' ) ;
36
21
22
+ a = [ 0x12 , 0xf0 , 0xd0 , 0xfb , 0x07 , 0xee , 0x90 , 0x0a , 0xf5 , 0xee , 0xc0 ] ;
23
+ b = [ 0x7a , 0xf1 , 0xee , 0x10 , 0xfa , 0x44 , 0xbf , 0x9f , 0xed , 0x08 , 0x7a ] ;
24
+ const c = [ 0x77 , 0xee , 0x87 , 0x7a , 0xfd , 0xee , 0xe7 , 0x7a , 0x17 , 0xee ] ;
25
+ expect (
26
+ ihex . createRecord (
27
+ 0x07e0 ,
28
+ ihex . RecordType . Data ,
29
+ new Uint8Array ( a . concat ( b ) . concat ( c ) )
30
+ )
31
+ ) . toEqual (
32
+ ':2007E00012F0D0FB07EE900AF5EEC07AF1EE10FA44BF9FED087A77EE877AFDEEE77A17EECF'
33
+ ) ;
34
+
37
35
expect (
38
36
ihex . createRecord (
39
37
0xf870 ,
@@ -51,7 +49,7 @@ describe('Test createRecord() for standard records', () => {
51
49
) . toEqual ( ':08E7D4000C1AFF7F0100000098' ) ;
52
50
} ) ;
53
51
54
- it ( 'Creates a custom End Of File record' , ( ) => {
52
+ it ( 'Creates an End Of File record' , ( ) => {
55
53
expect (
56
54
ihex . createRecord ( 0 , ihex . RecordType . EndOfFile , new Uint8Array ( [ ] ) )
57
55
) . toEqual ( ':00000001FF' ) ;
@@ -73,7 +71,7 @@ describe('Test createRecord() for standard records', () => {
73
71
74
72
expect ( ( ) => {
75
73
ihex . createRecord ( 0 , ihex . RecordType . Data , new Uint8Array ( data ) ) ;
76
- } ) . toThrow ( ) ;
74
+ } ) . toThrow ( 'data has too many bytes' ) ;
77
75
} ) ;
78
76
79
77
it ( 'Throws error when the address is too large' , ( ) => {
@@ -180,12 +178,20 @@ describe('Test getRecordData()', () => {
180
178
) ;
181
179
} ) ;
182
180
183
- it ( 'Get the data from a full Padding record' , ( ) => {
181
+ it ( 'Get the data from a half Padding record' , ( ) => {
184
182
expect (
185
183
ihex . getRecordData ( ':1080B00DFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC3' )
186
184
) . toEqual ( new Uint8Array ( new Array ( 16 ) . fill ( 0xff ) ) ) ;
187
185
} ) ;
188
186
187
+ it ( 'Get the data from a full Padding record' , ( ) => {
188
+ expect (
189
+ ihex . getRecordData (
190
+ ':1080B00DFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC3'
191
+ )
192
+ ) . toEqual ( new Uint8Array ( new Array ( 32 ) . fill ( 0xff ) ) ) ;
193
+ } ) ;
194
+
189
195
it ( 'Empty array when record is too short' , ( ) => {
190
196
expect ( ihex . getRecordData ( ':00000001' ) ) . toEqual ( new Uint8Array ( ) ) ;
191
197
} ) ;
@@ -198,54 +204,53 @@ describe('Test getRecordData()', () => {
198
204
} ) ;
199
205
200
206
describe ( 'Test parseRecord() for standard records' , ( ) => {
201
- it ( 'Parses data records of different lengths' , ( ) => {
202
- let result = ihex . parseRecord (
207
+ it ( 'Parses data records of different lengths (32)' , ( ) => {
208
+ const result = ihex . parseRecord (
209
+ ':201C400010F0D2FF3246CDE900013B463046394610F0EEFC02460B46DDE9000110F09AFE2C'
210
+ ) ;
211
+
212
+ expect ( result . byteCount ) . toEqual ( 0x20 ) ;
213
+ expect ( result . address ) . toEqual ( 0x1c40 ) ;
214
+ expect ( result . recordType ) . toEqual ( 0x00 ) ;
215
+ const a = [ 0x10 , 0xf0 , 0xd2 , 0xff , 0x32 , 0x46 , 0xcd , 0xe9 , 0x00 , 0x01 ] ;
216
+ const b = [ 0x3b , 0x46 , 0x30 , 0x46 , 0x39 , 0x46 , 0x10 , 0xf0 , 0xee , 0xfc ] ;
217
+ const c = [ 0x02 , 0x46 , 0x0b , 0x46 , 0xdd , 0xe9 , 0x00 , 0x01 , 0x10 , 0xf0 ] ;
218
+ const d = [ 0x9a , 0xfe ] ;
219
+ expect ( result . data ) . toEqual (
220
+ new Uint8Array ( a . concat ( b ) . concat ( c ) . concat ( d ) )
221
+ ) ;
222
+ expect ( result . checksum ) . toEqual ( 0x2c ) ;
223
+ } ) ;
224
+
225
+ it ( 'Parses data records of different lengths (16)' , ( ) => {
226
+ const result = ihex . parseRecord (
203
227
':10FFF0009B6D9847A06810F039FF0621A06810F0AB'
204
228
) ;
229
+
205
230
expect ( result . byteCount ) . toEqual ( 0x10 ) ;
206
231
expect ( result . address ) . toEqual ( 0xfff0 ) ;
207
232
expect ( result . recordType ) . toEqual ( 0x00 ) ;
208
- expect ( result . data ) . toEqual (
209
- new Uint8Array ( [
210
- 0x9b ,
211
- 0x6d ,
212
- 0x98 ,
213
- 0x47 ,
214
- 0xa0 ,
215
- 0x68 ,
216
- 0x10 ,
217
- 0xf0 ,
218
- 0x39 ,
219
- 0xff ,
220
- 0x06 ,
221
- 0x21 ,
222
- 0xa0 ,
223
- 0x68 ,
224
- 0x10 ,
225
- 0xf0 ,
226
- ] )
227
- ) ;
233
+ const a = [ 0x9b , 0x6d , 0x98 , 0x47 , 0xa0 , 0x68 , 0x10 , 0xf0 ] ;
234
+ const b = [ 0x39 , 0xff , 0x06 , 0x21 , 0xa0 , 0x68 , 0x10 , 0xf0 ] ;
235
+ expect ( result . data ) . toEqual ( new Uint8Array ( a . concat ( b ) ) ) ;
228
236
expect ( result . checksum ) . toEqual ( 0xab ) ;
237
+ } ) ;
238
+
239
+ it ( 'Parses data records of different lengths (8)' , ( ) => {
240
+ const result = ihex . parseRecord ( ':08AEE0007C53FF7F010000001C' ) ;
229
241
230
- result = ihex . parseRecord ( ':08AEE0007C53FF7F010000001C' ) ;
231
242
expect ( result . byteCount ) . toEqual ( 0x08 ) ;
232
243
expect ( result . address ) . toEqual ( 0xaee0 ) ;
233
244
expect ( result . recordType ) . toEqual ( 0x00 ) ;
234
245
expect ( result . data ) . toEqual (
235
246
new Uint8Array ( [ 0x7c , 0x53 , 0xff , 0x7f , 0x01 , 0x00 , 0x00 , 0x00 ] )
236
247
) ;
237
248
expect ( result . checksum ) . toEqual ( 0x1c ) ;
238
-
239
- result = ihex . parseRecord ( ':04F870000000000094' ) ;
240
- expect ( result . byteCount ) . toEqual ( 0x04 ) ;
241
- expect ( result . address ) . toEqual ( 0xf870 ) ;
242
- expect ( result . recordType ) . toEqual ( 0x00 ) ;
243
- expect ( result . data ) . toEqual ( new Uint8Array ( [ 0x00 , 0x00 , 0x00 , 0x00 ] ) ) ;
244
- expect ( result . checksum ) . toEqual ( 0x94 ) ;
245
249
} ) ;
246
250
247
- it ( 'Parses data records of different lengths' , ( ) => {
248
- const result = ihex . parseRecord ( ':04F870000000000094\r\n' ) ;
251
+ it ( 'Parses data records of different lengths (4)' , ( ) => {
252
+ const result = ihex . parseRecord ( ':04F870000000000094' ) ;
253
+
249
254
expect ( result . byteCount ) . toEqual ( 0x04 ) ;
250
255
expect ( result . address ) . toEqual ( 0xf870 ) ;
251
256
expect ( result . recordType ) . toEqual ( 0x00 ) ;
@@ -307,6 +312,14 @@ describe('Test extLinAddressRecord()', () => {
307
312
expect ( ihex . extLinAddressRecord ( 0x20000 ) ) . toEqual ( ':020000040002F8' ) ;
308
313
expect ( ihex . extLinAddressRecord ( 0x30000 ) ) . toEqual ( ':020000040003F7' ) ;
309
314
expect ( ihex . extLinAddressRecord ( 0x31234 ) ) . toEqual ( ':020000040003F7' ) ;
315
+ expect ( ihex . extLinAddressRecord ( 0x40000 ) ) . toEqual ( ':020000040004F6' ) ;
316
+ expect ( ihex . extLinAddressRecord ( 0x48264 ) ) . toEqual ( ':020000040004F6' ) ;
317
+ expect ( ihex . extLinAddressRecord ( 0x50000 ) ) . toEqual ( ':020000040005F5' ) ;
318
+ expect ( ihex . extLinAddressRecord ( 0x55555 ) ) . toEqual ( ':020000040005F5' ) ;
319
+ expect ( ihex . extLinAddressRecord ( 0x60000 ) ) . toEqual ( ':020000040006F4' ) ;
320
+ expect ( ihex . extLinAddressRecord ( 0x61230 ) ) . toEqual ( ':020000040006F4' ) ;
321
+ expect ( ihex . extLinAddressRecord ( 0x70000 ) ) . toEqual ( ':020000040007F3' ) ;
322
+ expect ( ihex . extLinAddressRecord ( 0x72946 ) ) . toEqual ( ':020000040007F3' ) ;
310
323
} ) ;
311
324
312
325
// TODO: Add tests for all thrown exceptions
@@ -339,6 +352,9 @@ describe('Test blockEndRecord()', () => {
339
352
expect ( ihex . blockEndRecord ( 0x10 ) ) . toEqual (
340
353
':1000000BFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5'
341
354
) ;
355
+ expect ( ihex . blockEndRecord ( 0x20 ) ) . toEqual (
356
+ ':2000000BFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5'
357
+ ) ;
342
358
} ) ;
343
359
344
360
it ( 'Throws error when the number of bytes to pad is a negative value' , ( ) => {
@@ -366,6 +382,9 @@ describe('Test paddedDataRecord()', () => {
366
382
expect ( ihex . paddedDataRecord ( 0x10 ) ) . toEqual (
367
383
':1000000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4'
368
384
) ;
385
+ expect ( ihex . paddedDataRecord ( 0x20 ) ) . toEqual (
386
+ ':2000000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4'
387
+ ) ;
369
388
} ) ;
370
389
371
390
it ( 'Throws error when the number of bytes to pad is a negative value' , ( ) => {
0 commit comments