Skip to content

Commit

Permalink
Fix: File/ArchiveFile equality (#1232)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Jul 22, 2024
1 parent 216994d commit 29a3482
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
6 changes: 2 additions & 4 deletions src/types/files/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export default class File implements FileProps {
}
} else {
finalSize = finalSize ?? 0;
finalCrcWithHeader = finalCrcWithHeader ?? '';
}
finalCrcWithoutHeader = finalCrcWithoutHeader ?? finalCrcWithHeader;
finalMd5WithoutHeader = finalMd5WithoutHeader ?? finalMd5WithHeader;
Expand Down Expand Up @@ -517,8 +516,7 @@ export default class File implements FileProps {
return true;
}
return this.getFilePath() === other.getFilePath()
&& this.getSize() === other.getSize()
&& this.getCrc32() === other.getCrc32()
&& this.getCrc32WithoutHeader() === other.getCrc32WithoutHeader();
&& this.hashCode() === other.hashCode()
&& this.getFileHeader() === other.getFileHeader();
}
}
17 changes: 15 additions & 2 deletions test/types/files/file.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import ROMScanner from '../../../src/modules/romScanner.js';
import bufferPoly from '../../../src/polyfill/bufferPoly.js';
import FilePoly from '../../../src/polyfill/filePoly.js';
import fsPoly from '../../../src/polyfill/fsPoly.js';
import ArchiveEntry from '../../../src/types/files/archives/archiveEntry.js';
import ArchiveFile from '../../../src/types/files/archives/archiveFile.js';
import Zip from '../../../src/types/files/archives/zip.js';
import File from '../../../src/types/files/file.js';
import { ChecksumBitmask } from '../../../src/types/files/fileChecksums.js';
import ROMHeader from '../../../src/types/files/romHeader.js';
Expand All @@ -20,8 +23,8 @@ describe('fileOf', () => {
expect(file.getSize()).toEqual(0);
expect(file.getSizeWithoutHeader()).toEqual(0);
expect(file.getExtractedFilePath()).toEqual(path.basename(tempFile));
expect(file.getCrc32()).toEqual('00000000');
expect(file.getCrc32WithoutHeader()).toEqual('00000000');
expect(file.getCrc32()).toBeUndefined();
expect(file.getCrc32WithoutHeader()).toBeUndefined();
expect(file.getMd5()).toBeUndefined();
expect(file.getMd5WithoutHeader()).toBeUndefined();
expect(file.getSha1()).toBeUndefined();
Expand Down Expand Up @@ -473,4 +476,14 @@ describe('equals', () => {
expect(second.equals(third)).toEqual(false);
expect(third.equals(first)).toEqual(false);
});

it('should equal an ArchiveFile', async () => {
const filePath = 'file.zip';
const file = await File.fileOf({ filePath });

const entry = await ArchiveEntry.entryOf({ archive: new Zip(filePath), entryPath: 'entry.rom' });
const archiveFile = new ArchiveFile(entry.getArchive(), {});

expect(file.equals(archiveFile)).toEqual(true);
});
});

0 comments on commit 29a3482

Please sign in to comment.