diff --git a/__tests__/ascii.test.ts b/__tests__/ascii.test.ts index 9342992..4888f40 100644 --- a/__tests__/ascii.test.ts +++ b/__tests__/ascii.test.ts @@ -22,4 +22,26 @@ describe('ASCII Board', () => { expect(chess.ascii()).toBe(output.join('\n')) }) + + it('Draws an ASCII board with a custom separator', () => { + const output = [ + ' +------------------------+', + ' 8 | r . . . . r k . |', + ' 7 | . . . . n q p p |', + ' 6 | . p . p . . . . |', + ' 5 | . . p P p p . . |', + ' 4 | b P P . P . . . |', + ' 3 | R . B . N Q . . |', + ' 2 | P . . . . P P P |', + ' 1 | . R . . . . K . |', + ' +------------------------+', + ' a b c d e f g h', + ] + + const chess = new Chess( + 'r4rk1/4nqpp/1p1p4/2pPpp2/bPP1P3/R1B1NQ2/P4PPP/1R4K1 w - - 0 28' + ) + + expect(chess.ascii("\r\n")).toBe(output.join('\r\n')) + }) }) diff --git a/src/chess.ts b/src/chess.ts index 647f4d0..6a18e98 100644 --- a/src/chess.ts +++ b/src/chess.ts @@ -2106,8 +2106,8 @@ export class Chess { return null } - ascii() { - let s = ' +------------------------+\n' + ascii(separator = '\n') { + let s = ` +------------------------+${separator}` for (let i = Ox88.a8; i <= Ox88.h1; i++) { // display the rank if (file(i) === 0) { @@ -2125,11 +2125,11 @@ export class Chess { } if ((i + 1) & 0x88) { - s += '|\n' + s += `|${separator}` i += 8 } } - s += ' +------------------------+\n' + s += ` +------------------------+${separator}` s += ' a b c d e f g h' return s