Skip to content

Commit

Permalink
fix ModTimeline tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Oct 20, 2024
1 parent 96c5e59 commit 73b48fc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions modules/api/src/test/ModTimelineTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import lila.playban.TempBan
class ModTimelineTest extends munit.FunSuite:

import ModTimeline.*
import PublicLine.merge.sep

val now = nowInstant

Expand All @@ -24,18 +25,21 @@ class ModTimelineTest extends munit.FunSuite:
assertEquals(aggregateEvents(Nil), Nil)

test("public line merge"):
assertEquals(PublicLine.merge(l1, l1), l1.copy(text = "linguine|linguine").some)
assertEquals(PublicLine.merge(l1, l2), l1.copy(text = "linguine|fusilli").some)
assertEquals(PublicLine.merge(l1, l1), l1.some)
assertEquals(PublicLine.merge(l1, l2), l1.copy(text = s"linguine${sep}fusilli").some)
assertEquals(PublicLine.merge(l2, l3), none)

test("merge same line"):
assertEquals(aggregateEvents(List(l1)), List(l1))
assertEquals(aggregateEvents(List(l1, l1)), List(l1.copy(text = "linguine|linguine")))
assertEquals(aggregateEvents(List(l1, l1)), List(l1))

test("merge same source lines"):
assertEquals(aggregateEvents(List(l1, l2)), List(l1.copy(text = "linguine|fusilli")))
assertEquals(aggregateEvents(List(l2, l1)), List(l1.copy(text = "fusilli|linguine")))
assertEquals(aggregateEvents(List(l1, l2, l1)), List(l1.copy(text = "linguine|fusilli|linguine")))
assertEquals(aggregateEvents(List(l1, l2)), List(l1.copy(text = s"linguine${sep}fusilli")))
assertEquals(aggregateEvents(List(l2, l1)), List(l1.copy(text = s"fusilli${sep}linguine")))
assertEquals(
aggregateEvents(List(l1, l2, l1)),
List(l1.copy(text = s"linguine${sep}fusilli"))
)

test("merge different source lines"):
assertEquals(aggregateEvents(List(l1, l3)), List(l1, l3))
Expand All @@ -44,21 +48,21 @@ class ModTimelineTest extends munit.FunSuite:
test("merge consecutive lines"):
assertEquals(
aggregateEvents(List(l4, l1, l1, l2, l3)),
List(l4, l1.copy(text = "linguine|linguine|fusilli"), l3)
List(l4, l1.copy(text = s"linguine${sep}fusilli"), l3)
)
assertEquals(
aggregateEvents(List(l4, l5, l1, l2, l1, l3)),
List(l4.copy(text = "bucatini|rigatoni"), l1.copy(text = "linguine|fusilli|linguine"), l3)
List(l4.copy(text = s"bucatini${sep}rigatoni"), l1.copy(text = s"linguine${sep}fusilli"), l3)
)

test("merge mixed lines"):
assertEquals(
aggregateEvents(List(l1, l4, l1)),
List(l1.copy(text = "linguine|linguine"), l4)
List(l1, l4)
)
assertEquals(
aggregateEvents(List(l1, l4, l2, l3, l5)),
List(l1.copy(text = "linguine|fusilli"), l4.copy(text = "bucatini|rigatoni"), l3)
List(l1.copy(text = s"linguine${sep}fusilli"), l4.copy(text = s"bucatini${sep}rigatoni"), l3)
)

test("merge mixed events"):
Expand All @@ -72,22 +76,22 @@ class ModTimelineTest extends munit.FunSuite:
)
assertEquals(
aggregateEvents(List(ban1, l1, l1)),
List(ban1, l1.copy(text = "linguine|linguine"))
List(ban1, l1)
)
assertEquals(
aggregateEvents(List(ban1, l1, l1, ban2)),
List(ban1, l1.copy(text = "linguine|linguine"), ban2)
List(ban1, l1, ban2)
)
assertEquals(
aggregateEvents(List(ban1, l1, l4, l1, ban2)),
List(ban1, l1.copy(text = "linguine|linguine"), l4, ban2)
List(ban1, l1, l4, ban2)
)
assertEquals(
aggregateEvents(List(l1, ban1, l4, ban2, l2, l3, l5, ban3, ban3)),
List(
l1.copy(text = "linguine|fusilli"),
l1.copy(text = s"linguine${sep}fusilli"),
ban1,
l4.copy(text = "bucatini|rigatoni"),
l4.copy(text = s"bucatini${sep}rigatoni"),
ban2,
l3,
ban3,
Expand Down
2 changes: 1 addition & 1 deletion modules/shutup/src/main/PublicLine.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object PublicLine:
given BSONHandler[PublicLine] = Macros.handler

object merge:
private val sep = "_@_"
val sep = "_@_"
def apply(prev: PublicLine, next: PublicLine): Option[PublicLine] =
if prev.from != next.from then none
else if split(prev.text).contains(next.text) then prev.some
Expand Down

0 comments on commit 73b48fc

Please sign in to comment.