Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions Tests/FischerCoreTests/PGN/KasparovPGNFileTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Foundation
import Testing
@testable import FischerCore

final class KasparovPGNFileTests {
@Test("Kasparov PGN file parses all games")
func parseKasparovPGNFileFromResources() async throws {
let fileURL = try #require(
Bundle.module.url(forResource: "garry-kasparov-on-gk-part-1", withExtension: "pgn")
)

let fileContents = try String(contentsOf: fileURL, encoding: .isoLatin1)
let firstTagIndex = try #require(fileContents.firstIndex(of: "["))
let pgn = fileContents[firstTagIndex...]
let eventTagCount = fileContents
.split(separator: "\n", omittingEmptySubsequences: false)
.filter { $0.hasPrefix("[Event ") }
.count
let games = try BasicPGNParser().parse(String(pgn))

#expect(fileContents.contains("% BOOKTITLE = Kasparov on Kasparov 1973-85"))
#expect(eventTagCount == 137)
#expect(games.count == 137)
#expect(games.count == eventTagCount)
#expect(games.first?.tags[.white] == "About this Publication")
#expect(games.last?.tags[.event] == "100: World Championship Match, Moscow")
}
}
Loading
Loading