|
1 | | -import { Chess, DEFAULT_POSITION, SEVEN_TAG_ROSTER } from '../src/chess' |
2 | 1 | import { expect, test } from 'vitest' |
| 2 | +import { |
| 3 | + BLACK, |
| 4 | + Chess, |
| 5 | + DEFAULT_POSITION, |
| 6 | + KING, |
| 7 | + QUEEN, |
| 8 | + SEVEN_TAG_ROSTER, |
| 9 | + WHITE, |
| 10 | +} from '../src/chess' |
3 | 11 |
|
4 | 12 | test('load - default position', () => { |
5 | 13 | const chess = new Chess() |
@@ -56,6 +64,66 @@ test('load - missing FEN tokens (no castling rights, ep square, or move numbers) |
56 | 64 | expect(() => chess.load(fen)).not.toThrow() |
57 | 65 | }) |
58 | 66 |
|
| 67 | +test('load - full castling rights but white king moved', () => { |
| 68 | + const chess = new Chess() |
| 69 | + const fen = 'r3k2r/8/8/8/8/8/8/R2K3R w KQkq - 0 1' |
| 70 | + chess.load(fen) |
| 71 | + expect(chess.getCastlingRights(WHITE)).toEqual({ |
| 72 | + [KING]: false, |
| 73 | + [QUEEN]: false, |
| 74 | + }) |
| 75 | +}) |
| 76 | + |
| 77 | +test('load - full castling rights but white kingside rook moved', () => { |
| 78 | + const chess = new Chess() |
| 79 | + const fen = 'r3k2r/8/8/8/8/8/8/R3K1R1 w KQkq - 0 1' |
| 80 | + chess.load(fen) |
| 81 | + expect(chess.getCastlingRights(WHITE)).toEqual({ |
| 82 | + [KING]: false, |
| 83 | + [QUEEN]: true, |
| 84 | + }) |
| 85 | +}) |
| 86 | + |
| 87 | +test('load - full castling rights but white queenside rook moved', () => { |
| 88 | + const chess = new Chess() |
| 89 | + const fen = 'r3k2r/8/8/8/8/8/8/1R2K2R w KQkq - 0 1' |
| 90 | + chess.load(fen) |
| 91 | + expect(chess.getCastlingRights(WHITE)).toEqual({ |
| 92 | + [KING]: true, |
| 93 | + [QUEEN]: false, |
| 94 | + }) |
| 95 | +}) |
| 96 | + |
| 97 | +test('load - full castling rights but black king moved', () => { |
| 98 | + const chess = new Chess() |
| 99 | + const fen = 'r2k3r/8/8/8/8/8/8/R3K2R w KQkq - 0 1' |
| 100 | + chess.load(fen) |
| 101 | + expect(chess.getCastlingRights(BLACK)).toEqual({ |
| 102 | + [KING]: false, |
| 103 | + [QUEEN]: false, |
| 104 | + }) |
| 105 | +}) |
| 106 | + |
| 107 | +test('load - full castling rights but black kingside rook moved', () => { |
| 108 | + const chess = new Chess() |
| 109 | + const fen = 'r3k1r1/8/8/8/8/8/8/R3K2R w KQkq - 0 1' |
| 110 | + chess.load(fen) |
| 111 | + expect(chess.getCastlingRights(BLACK)).toEqual({ |
| 112 | + [KING]: false, |
| 113 | + [QUEEN]: true, |
| 114 | + }) |
| 115 | +}) |
| 116 | + |
| 117 | +test('load - full castling rights but black queenside rook moved', () => { |
| 118 | + const chess = new Chess() |
| 119 | + const fen = '1r2k2r/8/8/8/8/8/8/R3K2R w KQkq - 0 1' |
| 120 | + chess.load(fen) |
| 121 | + expect(chess.getCastlingRights(BLACK)).toEqual({ |
| 122 | + [KING]: true, |
| 123 | + [QUEEN]: false, |
| 124 | + }) |
| 125 | +}) |
| 126 | + |
59 | 127 | test('load - preserveHeaders = false', () => { |
60 | 128 | const chess = new Chess() |
61 | 129 | chess.setHeader('White', 'Magnus Carlsen') |
|
0 commit comments