Files
duplicate_chess/src/engine/notation.test.ts
T
claude (duplicate_chess) 5db04109a2 fix: real project README and save-file version validation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-19 01:18:35 -04:00

28 lines
1016 B
TypeScript

import { describe, it, expect } from 'vitest';
import { toCoordinate, serialize, deserialize } from './notation';
import type { HistoryEntry } from './types';
describe('notation', () => {
it('renders a move as a coordinate token', () => {
expect(toCoordinate({ from: 'e2', to: 'e4' })).toBe('e2e4');
expect(toCoordinate({ from: 'e7', to: 'e8', promotion: 'q' })).toBe('e7e8q');
});
it('round-trips a game through serialize/deserialize', () => {
const history: HistoryEntry[] = [
{ player: 'N', from: 'e2', to: 'e4' },
{ player: 'S', from: 'e2', to: 'e4' },
];
const restored = deserialize(serialize(history));
expect(restored).toEqual(history);
});
it('rejects a file that is not a duplicate-chess save', () => {
expect(() => deserialize('{"variant":"chess","version":1,"moves":[]}')).toThrow();
});
it('rejects an unsupported save version', () => {
expect(() => deserialize('{"variant":"duplicate-chess","version":99,"moves":[]}')).toThrow();
});
});