Skip to content

Commit

Permalink
Merge pull request #486 from kraktus/tag_trimmed
Browse files Browse the repository at this point in the history
Trim PGN Tag content
  • Loading branch information
ornicar authored Oct 2, 2023
2 parents 3c3fbd1 + 949b779 commit c51157e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/main/scala/format/pgn/tagModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ object Tag:

def apply(name: String, value: Any): Tag = Tag(
name = tagType(name),
value = value.toString
value = value.toString.trim
)

def apply(name: Tag.type => TagType, value: Any): Tag = Tag(
name = name(this),
value = value.toString
value = value.toString.trim
)

def tagType(name: String) =
Expand Down
7 changes: 6 additions & 1 deletion test-kit/src/test/scala/format/pgn/Fixtures.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2020,7 +2020,12 @@ Rxg3 22. hxg3 Ne3+ 23. Kb5 a6+ 24. Ka4 Nxf1) 1-0
1. e2e4 e7e5 2. Ng1f3 Nb8c6 3. c2c3 Ng8f6 4. d2d4 e5xd4 5. e4e5 Nf6d5 6. Qd1b3 Nd5b6 7. c3xd4 d7d5 8. Bc1e3 Bc8f5 9. a2a3 Qd8d7 10. Nb1d2 Bf8e7 11. Bf1e2 a7a6 12. Ra1c1 O-O 13. O-O f7f6 14. Rf1d1 Kg8h8 15. Nd2b1 Nc6a5 16. Qb3c3 Na5c4 17. Be2c4 Nb6c4 18. Nb1d2 b7b5 19. Nd2b3 Bf5g4 20. e5xf6 Bg4f3 21. f6xe7 Qd7g4 22. e7xf8=Q+ {[%clk 10:26:01]} Ra8f8 {[%clk 10:27:09]} 0-1
"""

val tagsCommentsWithoutMoves1 ="""
val completeTagsWithSpaces = """
[Event " Мат в 1 ход [1-63] - Дорофеева: Мат в 1 ход - 43"]
[Variant " Standard "]
"""

val tagsCommentsWithoutMoves1 =s"""
[Event "Мат в 1 ход [1-63] - Дорофеева: Мат в 1 ход - 43"]
[Site "https://lichess.org/study/ZVU8ZBwM/LqSI1Pmt"]
[Result "*"]
Expand Down
6 changes: 6 additions & 0 deletions test-kit/src/test/scala/format/pgn/ParserTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,12 @@ class ParserTest extends ChessTest:
"example with tags & comments without moves 2" in:
parse(tagsCommentsWithoutMoves2) must beRight

"empty spaces in tags value should be removed" in:
parse(completeTagsWithSpaces) must beRight.like { a =>
a.tags(_.Variant) must_== Some("Standard")
a.tags(_.Event) must_== Some("Мат в 1 ход [1-63] - Дорофеева: Мат в 1 ход - 43")
}

"game with comments" in:
parse(gameWithComments) must beRight.like { a =>
a.mainline.size must_== 106
Expand Down
11 changes: 8 additions & 3 deletions test-kit/src/test/scala/format/pgn/TagTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class TagTest extends ChessTest:
Tag.BlackRatingDiff
)

"test" should:
"beSome" in:
Option(3) must beSome((_: Int) == 3)
"be trimmed" in:
List(
Tag(_.Site, " https://lichess.org/QuCzSfxw "),
Tag(_.Black, " penguingim1 ")
) must_== List(
Tag(_.Site, "https://lichess.org/QuCzSfxw"),
Tag(_.Black, "penguingim1")
)

0 comments on commit c51157e

Please sign in to comment.