apple2js/test/js/formats/woz.spec.ts
Ian Flanigan 62b48d3893
Move disk data to a disk field in the drive
Before, disk data was mixed in with state about the drive itself (like
track, motor phase, etc.). This made it hard to know exactly what data
was necessary for different image formats.

Now, the disk data is in a `disk` field whose type depends on the
drive type.  This makes responisbility a bit easier.

One oddity, though, is that the `Drive` has metadata _and_ the `Disk`
has metadata.  When a disk is in the drive, these should be `===`, but
when there is no disk in the drive, obviously only the drive metadata
is set.

All tests pass, everything compiles, and both WOZ and nibble disks
work in the emulator (both preact and classic).
2022-09-09 10:26:29 +02:00

91 lines
2.5 KiB
TypeScript

import { ENCODING_BITSTREAM } from 'js/formats/types';
import createDiskFromWoz from 'js/formats/woz';
import {
mockWoz1,
mockWoz2,
mockTMAP
} from './testdata/woz';
describe('woz', () => {
beforeEach(() => {
jest.spyOn(console, 'log').mockImplementation();
});
it('can parse Woz version 1', () => {
const options = {
name: 'Unknown',
volume: 254,
readOnly: true,
rawData: mockWoz1
};
const disk = createDiskFromWoz(options);
expect(disk).toEqual({
metadata: { name: 'Mock Woz 1', side: undefined },
readOnly: true,
encoding: ENCODING_BITSTREAM,
format: 'woz',
trackMap: mockTMAP,
rawTracks: [new Uint8Array([
1, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0,
])],
info: {
bitTiming: 0,
bootSector: 0,
cleaned: 0,
compatibleHardware: 0,
creator: 'Apple2JS ',
diskType: 1,
largestTrack: 0,
requiredRAM: 0,
sides: 0,
synchronized: 1,
version: 1,
writeProtected: 0
}
});
});
it('can parse Woz version 2', () => {
const options = {
name: 'Unknown',
volume: 254,
readOnly: true,
rawData: mockWoz2
};
const disk = createDiskFromWoz(options);
expect(disk).toEqual({
metadata: {
name: 'Mock Woz 2',
side: 'B',
},
readOnly: true,
encoding: ENCODING_BITSTREAM,
format: 'woz',
trackMap: mockTMAP,
rawTracks: [new Uint8Array([
1, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0,
])],
info: {
bitTiming: 0,
bootSector: 0,
cleaned: 0,
compatibleHardware: 0,
creator: 'Apple2JS ',
diskType: 1,
largestTrack: 0,
requiredRAM: 0,
sides: 1,
synchronized: 1,
version: 2,
writeProtected: 0
}
});
});
});