From c7b5f71662ebc72df0112599928b6caf3f6ab260 Mon Sep 17 00:00:00 2001 From: Vincent Velociter Date: Mon, 13 Nov 2023 15:49:06 +0100 Subject: [PATCH] Twak pgn comment parser --- lib/src/pgn.dart | 9 +++++++-- test/pgn_test.dart | 18 ++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/src/pgn.dart b/lib/src/pgn.dart index c4b1bca..ad69013 100644 --- a/lib/src/pgn.dart +++ b/lib/src/pgn.dart @@ -490,7 +490,8 @@ class PgnComment { this.shapes = const IListConst([]), this.clock, this.emt, - this.eval}); + this.eval}) + : assert(text == null || text != ''); /// Comment string. final String? text; @@ -562,7 +563,11 @@ class PgnComment { }).trim(); return PgnComment( - text: text, shapes: IList(shapes), emt: emt, clock: clock, eval: eval); + text: text.isNotEmpty ? text : null, + shapes: IList(shapes), + emt: emt, + clock: clock, + eval: eval); } /// Make a PGN string from this comment. diff --git a/test/pgn_test.dart b/test/pgn_test.dart index f879c8b..db67052 100644 --- a/test/pgn_test.dart +++ b/test/pgn_test.dart @@ -87,6 +87,12 @@ void main() { eval: PgnEvaluation.pawns(pawns: -0.42), )); + expect( + PgnComment.fromPgn('[%eval -0.42]'), + const PgnComment( + eval: PgnEvaluation.pawns(pawns: -0.42), + )); + expect( PgnComment.fromPgn('prefix [%emt 1:02:03.4]'), const PgnComment( @@ -94,6 +100,12 @@ void main() { emt: Duration(hours: 1, minutes: 2, seconds: 3, milliseconds: 400), )); + expect( + PgnComment.fromPgn('[%clk 00:02:05]'), + const PgnComment( + clock: Duration(minutes: 2, seconds: 5), + )); + expect( PgnComment.fromPgn( '[%csl Ya1][%cal Ra1a1,Be1e2]commentary [%csl Gh8]'), @@ -108,12 +120,6 @@ void main() { color: CommentShapeColor.green, from: 63, to: 63) ]))); - expect( - PgnComment.fromPgn('[%eval -0.42] suffix'), - const PgnComment( - text: 'suffix', - eval: PgnEvaluation.pawns(pawns: -0.42), - )); expect( PgnComment.fromPgn('prefix [%eval .99,23]'), const PgnComment(