Skip to content

Commit 4c8d1a0

Browse files
committed
fix time control parser
1 parent 75b5a36 commit 4c8d1a0

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

core/src/main/scala/TournamentClock.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,17 @@ object TournamentClock:
2121

2222
object parse:
2323

24-
private val cleanRegex = "(move|minutes|minute|min|m|seconds|second|sec|s|'|\"|/)".r
24+
private val cleanRegex = "(/move|minutes|minute|min|m|seconds|second|sec|s|'|\")".r
2525

2626
private def make(a: Int, b: Int) =
2727
val limit = LimitSeconds(if a > 180 then a else a * 60)
2828
TournamentClock(limit, IncrementSeconds(b))
2929

3030
def apply(str: String): Option[TournamentClock] =
3131
cleanRegex
32-
.replaceAllIn(str.toLowerCase, "")
33-
.replace(" ", "")
34-
.split('+') match
35-
case Array(a) => a.toIntOption.map(make(_, 0))
36-
case Array(a, b) => (a.toIntOption, b.toIntOption).mapN(make)
37-
case _ => none
32+
.replaceAllIn(str.toLowerCase.replace(" ", ""), "")
33+
.split('+')
34+
.match
35+
case Array(a) => a.toIntOption.map(make(_, 0))
36+
case Array(a, b) => (a.toIntOption, b.toIntOption).mapN(make)
37+
case _ => none

test-kit/src/test/scala/TournamentClockTest.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,7 @@ class TournamentClockTest extends ChessTest:
4343
assertEquals(parse("180"), someClock(180, 0))
4444
assertEquals(parse("240"), someClock(4, 0))
4545

46+
assertEquals(parse("120 min / 40 moves + 30 min"), None)
47+
4648
// we're not there yet
4749
// assertEquals(parse("90 min / 40 moves + 30 min + 30 sec / move"), ???)

0 commit comments

Comments
 (0)