Skip to content

Commit

Permalink
Fix some warnings in tests (scala 3 migration)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScoreUnder committed Aug 25, 2022
1 parent d754ac0 commit 2db78a4
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 99 deletions.
72 changes: 36 additions & 36 deletions src/test/scala/score/discord/canti/collections/LogBufferTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,69 @@ class LogBufferTest extends AnyFlatSpec with should.Matchers:
content.foreach(buf ::= _)
buf

"size" should "be equal to the number of elements" in {
"size" `should` "be equal to the number of elements" in {
val capacity = 10
for n <- 1 to capacity * 4 do
val buf = LogBuffer[Int](capacity)
1 to n foreach (buf ::= _)
buf.size should be(n min capacity)
buf.size `should` be(n min capacity)
}

"head" should "be equal to the most recently added element" in {
"head" `should` "be equal to the most recently added element" in {
val capacity = 10
val buf = LogBuffer[Int](capacity)
for n <- 1 to capacity * 4 do
buf ::= n
buf.head should be(n)
buf.head `should` be(n)
}

it should "fail when the buffer is empty" in {
it `should` "fail when the buffer is empty" in {
val buf = LogBuffer[Int](20)
assertThrows[IndexOutOfBoundsException] {
buf.head
}
buf.headOption should be(None)
buf.headOption `should` be(None)
}

"last" should "be equal to the first added element, while capacity is not exceeded" in {
"last" `should` "be equal to the first added element, while capacity is not exceeded" in {
val capacity = 10
val buf = LogBuffer[Int](capacity)
for n <- 1 to capacity do
buf ::= n
buf.last should be(1)
buf.last `should` be(1)
}

it should "be equal to the element added $capacity-1 elements ago, when capacity is full" in {
it `should` "be equal to the element added $capacity-1 elements ago, when capacity is full" in {
val capacity = 10
val buf = bufWithContent(content = 0 until capacity, capacity = capacity)
for n <- capacity to capacity * 4 do
buf ::= n
buf.last should be(n - (capacity - 1))
buf.last `should` be(n - (capacity - 1))
}

it should "fail when the buffer is empty" in {
it `should` "fail when the buffer is empty" in {
val buf = LogBuffer[Int](20)
assertThrows[IndexOutOfBoundsException] {
buf.last
}
buf.lastOption should be(None)
buf.lastOption `should` be(None)
}

"apply(0)" should "be the same as head" in {
"apply(0)" `should` "be the same as head" in {
val capacity = 10
val buf = LogBuffer[Int](capacity)
for n <- 1 to capacity * 4 do
buf ::= n
buf(0) should equal(buf.head)
buf(0) `should` equal(buf.head)
}

it should "fail when the buffer is empty" in {
it `should` "fail when the buffer is empty" in {
assertThrows[IndexOutOfBoundsException] {
LogBuffer[Int](20)(0)
}
}

"apply(n)" should "fail when n >= size" in {
"apply(n)" `should` "fail when n >= size" in {
val capacity = 10
val buf = LogBuffer[Int](capacity)
for n <- 1 until capacity do
Expand All @@ -81,56 +81,56 @@ class LogBufferTest extends AnyFlatSpec with should.Matchers:
}
}

"iterator" should "return the same results as sequential apply()" in {
"iterator" `should` "return the same results as sequential apply()" in {
val capacity = 10
val buf = LogBuffer[Int](capacity)

def iteratorChecks(): Unit =
buf.iterator.zipWithIndex.map { case (v, i) =>
v should be(buf(i))
v `should` be(buf(i))
}
buf.iterator.toVector should equal(buf.toVector)
buf.iterator.size should equal(buf.size)
buf.iterator.toVector `should` equal(buf.toVector)
buf.iterator.size `should` equal(buf.size)

iteratorChecks() // Test empty case
for n <- 1 to capacity * 4 do
buf ::= n
iteratorChecks()
}

"findAndUpdate" should "replace exactly one element" in {
"findAndUpdate" `should` "replace exactly one element" in {
val buf = bufWithContent(1 to 20)
buf should not contain 0
buf `should` not `contain` 0
val oldCount = buf.count(_ > 15)
oldCount should not be 0
oldCount `should` not `be` 0
buf.findAndUpdate(_ > 15)(_ => 0)
buf.count(_ > 15) should be(oldCount - 1)
buf should contain(0)
buf.count(_ > 15) `should` be(oldCount - 1)
buf `should` contain(0)
}

it should "not fail when nothing is found" in {
it `should` "not fail when nothing is found" in {
val buf = bufWithContent(1 to 5)
buf should not contain 20
buf `should` not `contain` 20
buf.findAndUpdate(_ == 20)(_ => 123)
buf should not contain 20
buf should not contain 123
buf.size should be(5)
buf.toSeq should equal(5 to 1 by -1)
buf `should` not `contain` 20
buf `should` not `contain` 123
buf.size `should` be(5)
buf.toSeq `should` equal(5 to 1 by -1)
}

it should "not run when the collection is empty" in {
it `should` "not run when the collection is empty" in {
LogBuffer[Int](20).findAndUpdate(_ => true)(_ => throw AssertionError())
}

"isEmpty" should "return true when empty" in {
LogBuffer[Int](20).isEmpty should be(true)
"isEmpty" `should` "return true when empty" in {
LogBuffer[Int](20).isEmpty `should` be(true)
}

it should "return false when non-empty" in {
it `should` "return false when non-empty" in {
val capacity = 10
val buf = LogBuffer[Int](capacity)
for n <- 1 to capacity * 4 do
buf ::= n
buf.isEmpty should be(false)
buf.isEmpty `should` be(false)
}
end LogBufferTest
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,51 @@ import org.scalatest.matchers.should
import score.discord.canti.TestFixtures

class FuriganaCommandTest extends AnyFlatSpec with should.Matchers:
val fixture = TestFixtures.default
private val fixture = TestFixtures.default
import fixture.given

val furiganaCommand = FuriganaCommand()
private val furiganaCommand = FuriganaCommand()

"parseInput" should "accept plain text" in {
furiganaCommand.parseInput("asdf asdfasdf") should contain(("asdf asdfasdf", ""))
"parseInput" `should` "accept plain text" in {
furiganaCommand.parseInput("asdf asdfasdf") `should` contain(("asdf asdfasdf", ""))
}

it should "accept a furigana group" in {
furiganaCommand.parseInput("{asdf:asdfasdf}") should contain(("asdf", "asdfasdf"))
it `should` "accept a furigana group" in {
furiganaCommand.parseInput("{asdf:asdfasdf}") `should` contain(("asdf", "asdfasdf"))
}

it should "accept a furigana group with no furigana" in {
furiganaCommand.parseInput("{asdf:}") should contain(("asdf", ""))
it `should` "accept a furigana group with no furigana" in {
furiganaCommand.parseInput("{asdf:}") `should` contain(("asdf", ""))
}

it should "accept a furigana group with no text" in {
furiganaCommand.parseInput("{:asdfasdf}") should contain(("", "asdfasdf"))
it `should` "accept a furigana group with no text" in {
furiganaCommand.parseInput("{:asdfasdf}") `should` contain(("", "asdfasdf"))
}

it should "trim empty groups" in {
it `should` "trim empty groups" in {
val parsed = furiganaCommand.parseInput("{asdf:ghi}{:}{:}{:zxc}{vbn:}{qwe:rty}")
parsed should not contain (("", ""))
parsed `should` not `contain` (("", ""))
}

it should "split newlines properly" in {
furiganaCommand.parseInput("asdf\nghi") should equal(Seq(("asdf", ""), ("\n", ""), ("ghi", "")))
furiganaCommand.parseInput("a\n\n\na").count(_ == ("\n", "")) should be(3)
it `should` "split newlines properly" in {
furiganaCommand.parseInput("asdf\nghi") `should` equal(Seq(("asdf", ""), ("\n", ""), ("ghi", "")))
furiganaCommand.parseInput("a\n\n\na").count(_ == ("\n", "")) `should` be(3)
}

it should "give exact correct results" in {
furiganaCommand.parseInput("{郵便局:ゆうびんきょく}に{行:い}きました") should equal(
it `should` "give exact correct results" in {
furiganaCommand.parseInput("{郵便局:ゆうびんきょく}に{行:い}きました") `should` equal(
Seq(("郵便局", "ゆうびんきょく"), ("", ""), ("", ""), ("きました", ""))
)
furiganaCommand.parseInput("{asdf:ghi}{:}{:}{:zxc}{vbn:}{qwe:rty}") should equal(
furiganaCommand.parseInput("{asdf:ghi}{:}{:}{:zxc}{vbn:}{qwe:rty}") `should` equal(
Seq(("asdf", "ghi"), ("", "zxc"), ("vbn", ""), ("qwe", "rty"))
)
}

it should "accept fullwidth separators" in {
furiganaCommand.parseInput("{郵便局:ゆうびんきょく}に{行:い}きました") should equal(
it `should` "accept fullwidth separators" in {
furiganaCommand.parseInput("{郵便局:ゆうびんきょく}に{行:い}きました") `should` equal(
Seq(("郵便局", "ゆうびんきょく"), ("", ""), ("", ""), ("きました", ""))
)
furiganaCommand.parseInput("{郵便局:ゆうびんきょく}に{行:い}きました") should equal(
furiganaCommand.parseInput("{郵便局:ゆうびんきょく}に{行:い}きました") `should` equal(
Seq(("郵便局", "ゆうびんきょく"), ("", ""), ("", ""), ("きました", ""))
)
}
Expand Down
38 changes: 19 additions & 19 deletions src/test/scala/score/discord/canti/command/HelpCommandTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import score.discord.canti.wrappers.jda.RetrievableMessage
import scala.concurrent.Future

class HelpCommandTest extends AnyFlatSpec with should.Matchers:
val fixture = TestFixtures.default
private val fixture = TestFixtures.default
import fixture.{given, *}

private val dummyDesc = "dummy command"
private val dummyLongDesc = "this command is dummy"

private class DummyCommand(val name: String) extends GenericCommand:
override def description = dummyDesc
override def longDescription(invocation: String) = dummyLongDesc
override def permissions = CommandPermissions.Anyone
override def argSpec = Nil
override def description: String = dummyDesc
override def longDescription(invocation: String): String = dummyLongDesc
override def permissions: CommandPermissions = CommandPermissions.Anyone
override def argSpec: List[ArgSpec[?]] = Nil
override def execute(ctx: CommandInvocation): Future[RetrievableMessage] = ???

(1 to 100)
Expand All @@ -32,32 +32,32 @@ class HelpCommandTest extends AnyFlatSpec with should.Matchers:
private val cmd = HelpCommand(commands)
commands.register(cmd)

"The &help command" should "reject negative page numbers" in {
"The &help command" `should` "reject negative page numbers" in {
val embed = testCommand("&help -1").getEmbeds.get(0).nn
embed.getColor should be(BotMessages.ERROR_COLOR)
embed.getDescription.nn shouldNot include(dummyDesc)
embed.getColor `should` be(BotMessages.ERROR_COLOR)
embed.getDescription.nn `shouldNot` include(dummyDesc)
}

it should "reject excessive page numbers" in {
it `should` "reject excessive page numbers" in {
val embed = testCommand("&help 100").getEmbeds.get(0).nn
embed.getColor should be(BotMessages.ERROR_COLOR)
embed.getDescription.nn should include("That page does not exist")
embed.getColor `should` be(BotMessages.ERROR_COLOR)
embed.getDescription.nn `should` include("That page does not exist")
}

it should "show command descriptions" in {
it `should` "show command descriptions" in {
val embed = testCommand("&help").getEmbeds.get(0).nn
embed.getDescription.nn should include(dummyDesc)
embed.getDescription.nn `should` include(dummyDesc)
}

it should "show long descriptions" in {
it `should` "show long descriptions" in {
val helpText = testCommand("&help cmd53").getEmbeds.get(0).nn.getDescription.nn
helpText should include("cmd53")
helpText should include(dummyDesc)
helpText should include(dummyLongDesc)
helpText `should` include("cmd53")
helpText `should` include(dummyDesc)
helpText `should` include(dummyLongDesc)
}

it should "link to github from default help pages" in {
it `should` "link to github from default help pages" in {
val embed = testCommand("&help 3").getEmbeds.get(0).nn
embed.getDescription.nn should include("github.com/")
embed.getDescription.nn `should` include("github.com/")
}
end HelpCommandTest
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,46 @@ import org.scalatest.matchers.should
import score.discord.canti.TestFixtures

class QuoteCommandTest extends AnyFlatSpec with should.Matchers:
val fixture = TestFixtures.default
private val fixture = TestFixtures.default

import fixture.{given, *}

val quoterChannel = botChannel
val quoteeChannel = exampleChannel
private val quoterChannel = botChannel
private val quoteeChannel = exampleChannel

commands.register(QuoteCommand(messageCache))

def quoteCommandTest(invocation: String, expected: String): Unit =
testCommand(invocation).getEmbeds.get(0).nn.getDescription.nn should include(expected)
testCommand(invocation).getEmbeds.get(0).nn.getDescription.nn `should` include(expected)

"The &quote command" should "understand id + channel mention" in {
"The &quote command" `should` "understand id + channel mention" in {
quoteCommandTest(
s"&quote ${quoteeMessage.getIdLong} ${quoteeChannel.getAsMention}",
quoteeMessageData
)
}

it should "understand long-style message quotes" in {
it `should` "understand long-style message quotes" in {
quoteCommandTest(
s"&quote ${quoteeChannel.getIdLong}-${quoteeMessage.getIdLong}",
quoteeMessageData
)
}

it should "understand URL message quotes" in {
it `should` "understand URL message quotes" in {
quoteCommandTest(
s"&quote https://canary.discord.com/channels/${guild.getId}/${quoteeChannel.getIdLong}/${quoteeMessage.getIdLong}",
quoteeMessageData
)
}

it should "find cached messages" in {
it `should` "find cached messages" in {
// ensure message cache is populated with the message to find
messageCache.onEvent(MessageReceivedEvent(jda, 0, quotee2Message))

quoteCommandTest(s"&quote ${quotee2Message.getIdLong}", quotee2MessageData)
}

it should "find messages in the same channel" in {
it `should` "find messages in the same channel" in {
quoteCommandTest(s"&quote ${quotee3Message.getIdLong}", quotee3MessageData)
}
Loading

0 comments on commit 2db78a4

Please sign in to comment.