Skip to content

Commit 5e9dcf3

Browse files
committed
fix: simplify trim, add ESCAPE rule tests, fix CHANGELOG links, remove debug placeholder
1 parent 158b843 commit 5e9dcf3

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,8 @@ and this project adheres to
348348
- New grammar supporting the full PGN specification including RAV (recursive
349349
annotated variations) and NAG (numeric annotation glyphs)
350350

351-
[unreleased]: https://github.com/mormubis/pgn/compare/v3.10.0...HEAD
351+
[unreleased]: https://github.com/mormubis/pgn/compare/v3.10.1...HEAD
352+
[3.10.1]: https://github.com/mormubis/pgn/compare/v3.10.0...v3.10.1
352353
[3.10.0]: https://github.com/mormubis/pgn/compare/v3.9.1...v3.10.0
353354
[3.9.1]: https://github.com/mormubis/pgn/compare/v3.9.0...v3.9.1
354355
[3.9.0]: https://github.com/mormubis/pgn/compare/v3.8.3...v3.9.0

src/__tests__/debug-variants.spec.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/__tests__/index.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ describe('PGN Parser', () => {
9696
expect(result[0]?.meta['Event']).toBe(String.raw`A\"B`);
9797
});
9898

99+
it('ignores % escape lines between moves', () => {
100+
const pgn = '1. e4\n% this is an escape line\ne5 1-0';
101+
const result = parse(pgn);
102+
expect(result).toHaveLength(1);
103+
expect(result[0]?.moves[0]?.[2]).toMatchObject({ piece: 'P', to: 'e5' });
104+
});
105+
106+
it('ignores % escape lines between games', () => {
107+
const pgn = '1. e4 e5 1-0\n% separator line\n1. d4 d5 0-1';
108+
const result = parse(pgn);
109+
expect(result).toHaveLength(2);
110+
expect(result[0]?.result).toBe(1);
111+
expect(result[1]?.result).toBe(0);
112+
});
113+
99114
it('parses a game with no tags', () => {
100115
const pgn = '1. e4 e5 2. Nf3 Nc6 1-0';
101116
const result = parse(pgn);

src/parse.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ function toParseError(thrown: unknown): ParseError {
222222
* @param input
223223
*/
224224
export default function parse(input: string, options?: ParseOptions): PGN[] {
225-
const cleaned = input.replace(/^\uFEFF/, '').replaceAll(/^\s+|\s+$/g, '');
225+
const cleaned = input.replace(/^\uFEFF/, '').trim();
226226

227227
try {
228228
const games = parser.parse(cleaned, {

0 commit comments

Comments
 (0)