mirror of
https://github.com/whscullin/apple2js.git
synced 2024-01-12 14:14:38 +00:00
Fix disk format type checks (#176)
This commit is contained in:
parent
d042a5b319
commit
7a97414e5d
@ -150,12 +150,12 @@ export type DiskFormat = MemberOf<typeof DISK_FORMATS>;
|
|||||||
|
|
||||||
/** Type guard for nibble disk formats. */
|
/** Type guard for nibble disk formats. */
|
||||||
export function isNibbleDiskFormat(f: DiskFormat): f is NibbleFormat {
|
export function isNibbleDiskFormat(f: DiskFormat): f is NibbleFormat {
|
||||||
return f in NIBBLE_FORMATS;
|
return NIBBLE_FORMATS.includes(f as NibbleFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Type guard for block disk formats. */
|
/** Type guard for block disk formats. */
|
||||||
export function isBlockDiskFormat(f: DiskFormat): f is BlockFormat {
|
export function isBlockDiskFormat(f: DiskFormat): f is BlockFormat {
|
||||||
return f in BLOCK_FORMATS;
|
return BLOCK_FORMATS.includes(f as BlockFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isNoFloppyDisk(disk: Disk): disk is NoFloppyDisk {
|
export function isNoFloppyDisk(disk: Disk): disk is NoFloppyDisk {
|
||||||
|
65
test/js/formats/types.spec.ts
Normal file
65
test/js/formats/types.spec.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import {
|
||||||
|
isNibbleDisk,
|
||||||
|
isNibbleDiskFormat,
|
||||||
|
isBlockDiskFormat,
|
||||||
|
isWozDisk,
|
||||||
|
DiskFormat,
|
||||||
|
NibbleDisk,
|
||||||
|
WozDisk,
|
||||||
|
} from 'js/formats/types';
|
||||||
|
|
||||||
|
const nibbleDisk = {
|
||||||
|
encoding: 'nibble'
|
||||||
|
} as NibbleDisk;
|
||||||
|
|
||||||
|
const wozDisk = {
|
||||||
|
encoding: 'bitstream'
|
||||||
|
} as WozDisk;
|
||||||
|
|
||||||
|
describe('Format types', () => {
|
||||||
|
describe('isNibbleDisk', () => {
|
||||||
|
it.each([
|
||||||
|
[nibbleDisk, true],
|
||||||
|
[wozDisk, false],
|
||||||
|
])('%s is %s', (disk, value) => {
|
||||||
|
expect(isNibbleDisk(disk)).toEqual(value);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isNibbleDiskFormat', () => {
|
||||||
|
it.each([
|
||||||
|
['2mg', true],
|
||||||
|
['d13', true],
|
||||||
|
['do', true],
|
||||||
|
['dsk', true],
|
||||||
|
['po', true],
|
||||||
|
['nib', true],
|
||||||
|
['hdv', false],
|
||||||
|
])('%s is %s', (fmt, val) => {
|
||||||
|
expect(isNibbleDiskFormat(fmt as DiskFormat)).toEqual(val);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isBlockDiskFormat', () => {
|
||||||
|
it.each([
|
||||||
|
['2mg', true],
|
||||||
|
['d13', false],
|
||||||
|
['do', false],
|
||||||
|
['dsk', false],
|
||||||
|
['po', true],
|
||||||
|
['nib', false],
|
||||||
|
['hdv', true],
|
||||||
|
])('%s is %s', (fmt, val) => {
|
||||||
|
expect(isBlockDiskFormat(fmt as DiskFormat)).toEqual(val);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('isWozDisk', () => {
|
||||||
|
it.each([
|
||||||
|
[nibbleDisk, false],
|
||||||
|
[wozDisk, true],
|
||||||
|
])('%s is %s', (disk, value) => {
|
||||||
|
expect(isWozDisk(disk)).toEqual(value);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user