Skip to content

Commit

Permalink
upy-fs-hex: Convert importFilesFromIntelHex optional args into option…
Browse files Browse the repository at this point in the history
…al obj.
  • Loading branch information
microbit-carlos committed Mar 14, 2019
1 parent 070c865 commit ef0403e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
9 changes: 4 additions & 5 deletions src/__tests__/micropython-fs-builder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,11 @@ describe('Writing files to the filesystem.', () => {
const shortData = shortMap.get(0x3c900);

it('Add files to hex.', () => {
const filesObj: { [filename: string]: Uint8Array } = {};
filesObj[files[0].fileName] = strToBytes(files[0].fileStr);
filesObj[files[1].fileName] = strToBytes(files[1].fileStr);

testResetFileSystem();
const fwWithFsOther = addIntelHexFiles(uPyHexFile, filesObj);
const fwWithFsOther = addIntelHexFiles(uPyHexFile, {
[files[0].fileName]: strToBytes(files[0].fileStr),
[files[1].fileName]: strToBytes(files[1].fileStr),
});
// fs.writeFileSync('./ignore/output2.hex', fwWithFsOther);

const opMap = MemoryMap.fromHex(fwWithFsOther);
Expand Down
31 changes: 15 additions & 16 deletions src/__tests__/micropython-fs-hex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,9 @@ describe('Test importing files from hex.', () => {
micropythonFs.write('a.py', originalFileContent);

const failCase = () => {
micropythonFs.importFilesFromIntelHex(hexStrWithFiles, false);
micropythonFs.importFilesFromIntelHex(hexStrWithFiles, {
overwrite: false,
});
};

expect(failCase).toThrow(Error);
Expand All @@ -456,7 +458,7 @@ describe('Test importing files from hex.', () => {
const originalFileContent = 'Original file content.';
micropythonFs.write('a.py', originalFileContent);

micropythonFs.importFilesFromIntelHex(hexStrWithFiles, true);
micropythonFs.importFilesFromIntelHex(hexStrWithFiles, { overwrite: true });

expect(micropythonFs.read('a.py')).not.toEqual(originalFileContent);
expect(micropythonFs.read('a.py')).toEqual(extraFiles['a.py']);
Expand Down Expand Up @@ -493,11 +495,10 @@ describe('Test importing files from hex.', () => {
const micropythonFs = new MicropythonFsHex(uPyHexFile);
micropythonFs.write('old_file.py', 'Some content.');

const fileList = micropythonFs.importFilesFromIntelHex(
hexStrWithFiles,
false,
true
);
const fileList = micropythonFs.importFilesFromIntelHex(hexStrWithFiles, {
overwrite: false,
formatFirst: true,
});

Object.keys(extraFiles).forEach((filename) => {
expect(fileList).toContain(filename);
Expand All @@ -510,15 +511,13 @@ describe('Test importing files from hex.', () => {
const micropythonFs = new MicropythonFsHex(uPyHexFile);
micropythonFs.write('old_file.py', 'Some content.');

const fileList1 = micropythonFs.importFilesFromIntelHex(
hexStrWithFiles,
false
);
const fileList2 = micropythonFs.importFilesFromIntelHex(
hexStrWithFiles,
true,
false
);
const fileList1 = micropythonFs.importFilesFromIntelHex(hexStrWithFiles, {
overwrite: false,
});
const fileList2 = micropythonFs.importFilesFromIntelHex(hexStrWithFiles, {
overwrite: true,
formatFirst: false,
});

Object.keys(extraFiles).forEach((filename) => {
expect(fileList1).toContain(filename);
Expand Down
6 changes: 4 additions & 2 deletions src/micropython-fs-hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,10 @@ export class MicropythonFsHex implements FsInterface {
*/
importFilesFromIntelHex(
intelHex: string,
overwrite?: boolean,
formatFirst?: boolean
{
overwrite = false,
formatFirst = false,
}: { overwrite?: boolean; formatFirst?: boolean } = {}
): string[] {
const files = getIntelHexFiles(intelHex);
if (formatFirst) {
Expand Down

0 comments on commit ef0403e

Please sign in to comment.