Skip to content

Commit

Permalink
Twak pgn comment parser
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce committed Nov 13, 2023
1 parent bbd2b5b commit c7b5f71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
9 changes: 7 additions & 2 deletions lib/src/pgn.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
18 changes: 12 additions & 6 deletions test/pgn_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,25 @@ 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(
text: 'prefix',
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]'),
Expand All @@ -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(
Expand Down

0 comments on commit c7b5f71

Please sign in to comment.