Skip to content

Commit

Permalink
Chore: add 1G1R tests (#570)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmercm authored Aug 14, 2023
1 parent 754fcde commit 88bbde7
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 24 deletions.
6 changes: 4 additions & 2 deletions src/types/logiqx/dat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ export default class DAT {

// Find all clones
this.getGames().forEach((game: Game) => {
// TODO(cemmer): a DAT fixture with parent/clone info
if (!game.isParent()) {
if (game.isClone()) {
const parent = this.gameNamesToParents.get(game.getParent());
if (parent) {
parent.addChild(game);
} else {
// The DAT is bad, the game is referencing a parent that doesn't exist
this.gameNamesToParents.set(game.getName(), new Parent(game.getName(), game));
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/dats/one.dat
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<release name="Foobar" region="USA"/>
<rom name="Foobar.lnx" size="7" crc="b22c9747" md5="14758f1afd44c09b7992073ccf00b43d" sha1="988881adc9fc3655077dc2d4d757d480b5ea0e11" status="verified"/>
</machine>
<machine name="Fizzbuzz">
<machine name="Fizzbuzz" cloneof="Foobar">
<description>Fizzbuzz</description>
<release name="Fizzbuzz" region="EUR"/>
<rom name="Fizzbuzz.nes" size="9" crc="370517b5" md5="cbe8410861130a91609295349918c2c2" sha1="5a316d9f0e06964d94cdd62a933803d7147ddadb" status="verified"/>
Expand Down
21 changes: 20 additions & 1 deletion test/igir.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ describe('with explicit DATs', () => {

it('should throw on DATs without parent/clone info', async () => {
await expect(async () => new Igir(new Options({
dat: ['test/fixtures/dats/*'],
dat: ['test/fixtures/dats/{headered,patchable}.dat'],
single: true,
}), new Logger(LogLevel.NEVER)).main()).rejects.toThrow(/parent\/clone/i);
});
Expand Down Expand Up @@ -159,6 +159,25 @@ describe('with explicit DATs', () => {
]);
});

it('should copy a 1G1R set', async () => {
await expectEndToEnd({
commands: ['copy'],
dat: ['dats/one.dat'],
single: true,
preferParent: true,
}, [
// Fizzbuzz.nes is explicitly missing!
['Foobar.lnx', 'b22c9747'],
['Lorem Ipsum.rom', '70856527'],
[`${path.join('One Three.zip')}|${path.join('1', 'one.rom')}`, 'f817a89f'],
[`${path.join('One Three.zip')}|${path.join('2', 'two.rom')}`, '96170874'],
[`${path.join('One Three.zip')}|${path.join('3', 'three.rom')}`, 'ff46c5d8'],
[path.join('Three Four Five', 'Five.rom'), '3e5daf67'],
[path.join('Three Four Five', 'Four.rom'), '1cf3ca74'],
[path.join('Three Four Five', 'Three.rom'), 'ff46c5d8'],
]);
});

it('should move, extract, test, and clean', async () => {
await expectEndToEnd({
commands: ['move', 'extract', 'test', 'clean'],
Expand Down
54 changes: 34 additions & 20 deletions test/modules/candidateGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import Options from '../../src/types/options.js';
import ReleaseCandidate from '../../src/types/releaseCandidate.js';
import ProgressBarFake from '../console/progressBarFake.js';

// TODO(cemmer): test parent/clone behavior
const gameWithNoRoms = new Game({
name: 'game with no ROMs',
});
Expand All @@ -32,14 +31,23 @@ const gameWithOneRom = new Game({
],
rom: new ROM('one.rom', 1, '12345678'),
});
const gameWithTwoRoms = new Game({
name: 'game with two ROMs',
release: new Release('game with two ROMs', 'WORLD'),
const gameWithTwoRomsParent = new Game({
name: 'game with two ROMs (parent)',
release: new Release('game with two ROMs (parent)', 'WORLD'),
rom: [
new ROM('two.a', 2, 'abcdef90'),
new ROM('two.b', 3, '09876543'),
],
});
const gameWithTwoRomsClone = new Game({
name: 'game with two ROMs (clone)',
cloneOf: gameWithTwoRomsParent.getName(),
release: new Release('game with two ROMs (clone)', 'JPN'),
rom: [
new ROM('three.a', 4, 'abcd1234'),
new ROM('three.b', 5, '86753090'),
],
});
const gameWithDuplicateRoms = new Game({
name: 'game with duplicate ROMs',
rom: [
Expand All @@ -50,7 +58,12 @@ const gameWithDuplicateRoms = new Game({
new ROM('Disc (Track 04).cue', 4, '11bf5dbd'),
],
});
const datWithThreeGames = new DAT(new Header(), [gameWithNoRoms, gameWithOneRom, gameWithTwoRoms]);
const datWithFourGames = new DAT(new Header(), [
gameWithNoRoms,
gameWithOneRom,
gameWithTwoRomsParent,
gameWithTwoRomsClone,
]);

async function candidateGenerator(
options: Options,
Expand Down Expand Up @@ -103,7 +116,7 @@ describe.each(['zip', 'extract', 'raw'])('command: %s', (command) => {
const files = await Promise.all(filePromises);

// When
const parentsToCandidates = await candidateGenerator(options, datWithThreeGames, files);
const parentsToCandidates = await candidateGenerator(options, datWithFourGames, files);

// Then
expect(parentsToCandidates.size).toEqual(3);
Expand All @@ -122,7 +135,7 @@ describe.each(['zip', 'extract', 'raw'])('command: %s', (command) => {
];

// When
const parentsToCandidates = await candidateGenerator(options, datWithThreeGames, files);
const parentsToCandidates = await candidateGenerator(options, datWithFourGames, files);

// Then
expect(parentsToCandidates.size).toEqual(3);
Expand Down Expand Up @@ -160,7 +173,7 @@ describe.each(['zip', 'extract', 'raw'])('command: %s', (command) => {
];

// When
const parentsToCandidates = await candidateGenerator(options, datWithThreeGames, files);
const parentsToCandidates = await candidateGenerator(options, datWithFourGames, files);

// Then
expect(parentsToCandidates.size).toEqual(3);
Expand Down Expand Up @@ -207,7 +220,7 @@ describe('with ROMs with headers', () => {
});

// When
const parentsToCandidates = await candidateGenerator(options, datWithThreeGames, filePromises);
const parentsToCandidates = await candidateGenerator(options, datWithFourGames, filePromises);

// Then
expect(parentsToCandidates.size).toEqual(3);
Expand All @@ -229,11 +242,11 @@ describe('with ROMs with headers', () => {
expect(candidate.getRomsWithFiles()).toHaveLength(2);
const candidateWithTwoRomsOutputOne = candidate.getRomsWithFiles()[0]
.getOutputFile() as ArchiveEntry<Zip>;
expect(candidateWithTwoRomsOutputOne.getFilePath()).toEqual('game with two ROMs.zip'); // respected DAT
expect(candidateWithTwoRomsOutputOne.getFilePath()).toEqual('game with two ROMs (parent).zip'); // respected DAT
expect(candidateWithTwoRomsOutputOne.getEntryPath()).toEqual('two.sfc'); // respected un-headered extension
const candidateWithTwoRomsOutputTwo = candidate.getRomsWithFiles()[1]
.getOutputFile() as ArchiveEntry<Zip>;
expect(candidateWithTwoRomsOutputTwo.getFilePath()).toEqual('game with two ROMs.zip'); // respected DAT
expect(candidateWithTwoRomsOutputTwo.getFilePath()).toEqual('game with two ROMs (parent).zip'); // respected DAT
expect(candidateWithTwoRomsOutputTwo.getEntryPath()).toEqual('two.b'); // respected DAT
});
});
Expand All @@ -246,7 +259,7 @@ describe('with ROMs with headers', () => {
});

// When
const parentsToCandidates = await candidateGenerator(options, datWithThreeGames, filePromises);
const parentsToCandidates = await candidateGenerator(options, datWithFourGames, filePromises);

// Then
expect(parentsToCandidates.size).toEqual(3);
Expand All @@ -263,8 +276,8 @@ describe('with ROMs with headers', () => {
expect(candidateWithTwoRoms).toHaveLength(1);
candidateWithTwoRoms.forEach((candidate) => {
expect(candidate.getRomsWithFiles()).toHaveLength(2);
expect(candidate.getRomsWithFiles()[0].getOutputFile().getFilePath()).toEqual(path.join('game with two ROMs', 'two.sfc')); // respected un-headered extension
expect(candidate.getRomsWithFiles()[1].getOutputFile().getFilePath()).toEqual(path.join('game with two ROMs', 'two.b')); // respected DAT
expect(candidate.getRomsWithFiles()[0].getOutputFile().getFilePath()).toEqual(path.join('game with two ROMs (parent)', 'two.sfc')); // respected un-headered extension
expect(candidate.getRomsWithFiles()[1].getOutputFile().getFilePath()).toEqual(path.join('game with two ROMs (parent)', 'two.b')); // respected DAT
});
});

Expand All @@ -276,7 +289,7 @@ describe('with ROMs with headers', () => {
});

// When
const parentsToCandidates = await candidateGenerator(options, datWithThreeGames, filePromises);
const parentsToCandidates = await candidateGenerator(options, datWithFourGames, filePromises);

// Then
expect(parentsToCandidates.size).toEqual(3);
Expand All @@ -294,9 +307,9 @@ describe('with ROMs with headers', () => {
candidateWithTwoRoms.forEach((candidate) => {
expect(candidate.getRomsWithFiles()).toHaveLength(2);
const candidateWithTwoRomsOutputOne = candidate.getRomsWithFiles()[0].getOutputFile();
expect(candidateWithTwoRomsOutputOne.getFilePath()).toEqual('game with two ROMs.7z'); // respected DAT and input extension
expect(candidateWithTwoRomsOutputOne.getFilePath()).toEqual('game with two ROMs (parent).7z'); // respected DAT and input extension
const candidateWithTwoRomsOutputTwo = candidate.getRomsWithFiles()[1].getOutputFile();
expect(candidateWithTwoRomsOutputTwo.getFilePath()).toEqual('game with two ROMs.7z'); // respected DAT and input extension
expect(candidateWithTwoRomsOutputTwo.getFilePath()).toEqual('game with two ROMs (parent).7z'); // respected DAT and input extension
});
});
});
Expand All @@ -314,7 +327,7 @@ describe('with different input files for every game ROM', () => {
const options = new Options({ commands: ['copy', command] });

// When
const parentsToCandidates = await candidateGenerator(options, datWithThreeGames, filePromises);
const parentsToCandidates = await candidateGenerator(options, datWithFourGames, filePromises);

// Then there should still be 3 parents, with the input -> output:
// (nothing) -> game with no ROMs
Expand Down Expand Up @@ -344,7 +357,7 @@ describe('with different input files for every game ROM', () => {
const options = new Options({ commands: ['copy'] });

// When
const parentsToCandidates = await candidateGenerator(options, datWithThreeGames, filePromises);
const parentsToCandidates = await candidateGenerator(options, datWithFourGames, filePromises);

// Then there should still be 3 parents, with the input -> output:
// (nothing) -> game with no ROMs
Expand Down Expand Up @@ -412,7 +425,8 @@ describe.each(['copy', 'move'])('prefer input files from the same archive when r
});

describe.each([
gameWithTwoRoms,
gameWithTwoRomsParent,
gameWithTwoRomsClone,
gameWithDuplicateRoms,
])('game: %s', (datGame) => {
const dat = new DAT(new Header(), [datGame]);
Expand Down

0 comments on commit 88bbde7

Please sign in to comment.