From 8780ab108f7545727d42ff049b02005870627e2b Mon Sep 17 00:00:00 2001 From: kwkr Date: Mon, 25 Sep 2023 09:21:05 +0200 Subject: [PATCH] add default separator param to ascii function --- __tests__/ascii.test.ts | 22 ++++++++++++++++++++++ src/chess.ts | 8 ++++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/__tests__/ascii.test.ts b/__tests__/ascii.test.ts index 93429925..4888f409 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 647f4d07..6a18e989 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