move tests to their own subprojects, fix InputCommand tests

This commit is contained in:
A.C.Sukazyo Eyre 2025-02-27 18:31:49 +08:00
parent ea6bf80d48
commit 7b6e3ae9c4
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
22 changed files with 255 additions and 155 deletions

View File

@ -9,6 +9,4 @@ abstract class MornyTests extends AnyFreeSpec with should.Matchers {
val pack: ResourcePackage = ResourcePackage.get("assets_morny_tests")
val assets: ResourceDirectory = pack.getDirectory("assets_morny_tests")
val pending_val = "[not-implemented]"
}

View File

@ -1,79 +0,0 @@
package cc.sukazyo.cono.morny.test.utils.tgapi
import cc.sukazyo.cono.morny.system.telegram_api.command.InputCommand
import cc.sukazyo.cono.morny.test.MornyTests
import org.scalatest.prop.TableDrivenPropertyChecks
class InputCommandTest extends MornyTests with TableDrivenPropertyChecks {
"while create new InputCommand :" - {
val examples = Table[String|Array[String], String, String|Null, Array[String]](
(
"source",
"command",
"target",
"args"
),
(
"exit@sukazyo_deving_bot",
"exit",
"sukazyo_deving_bot",
Array.empty[String]
),
(
"test@a@b",
"test",
"a@b",
Array.empty[String]
),
(
"test-data@random#user",
"test-data",
"random#user",
Array.empty[String]
),
(
"info@sukazyo_deving_bot stickers.ID_403",
"info",
"sukazyo_deving_bot",
Array("stickers.ID_403")
),
(
"info some extra info",
"info",
null,
Array("some", "extra", "info")
),
(
"",
"",
null,
Array.empty[String]
)
)
examples forEvery { (source, command, target, args) =>
val _source_describe = source match
case s: String => s
case r: Array[String] => r.mkString
s"while input is $_source_describe:" - {
val _ic: InputCommand = source match
case s: String => InputCommand(s)
case r: Array[String] => InputCommand(r)
s"command should be '$command'" in { _ic.command shouldEqual command }
s"target should be '$target'" in {_ic.target shouldEqual target}
"args array should always exists" in { _ic.args shouldNot equal (null) }
s"args should parsed to array ${args.mkString}" in { _ic.args shouldEqual args }
}
}
}
}

View File

@ -1,9 +0,0 @@
package cc.sukazyo.cono.morny.test.utils.tgapi.formatting
import cc.sukazyo.cono.morny.test.MornyTests
class TelegramFormatterTest extends MornyTests {
"some test" in pending
}

View File

@ -0,0 +1,10 @@
package cc.sukazyo.cono.morny
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.prop.TableDrivenPropertyChecks
trait MornyCoreTests
extends AnyFreeSpec
with Matchers
with TableDrivenPropertyChecks

View File

@ -1,10 +1,9 @@
package cc.sukazyo.cono.morny.test.utils
package cc.sukazyo.cono.morny.utils
import cc.sukazyo.cono.morny.test.MornyTests
import cc.sukazyo.cono.morny.MornyCoreTests
import cc.sukazyo.cono.morny.util.CommonFormat.{formatDate, formatDuration}
import org.scalatest.prop.TableDrivenPropertyChecks
class CommonFormatTest extends MornyTests with TableDrivenPropertyChecks {
class TestCommonFormat extends MornyCoreTests {
"while using #formatDate :" - {

View File

@ -1,8 +1,8 @@
package cc.sukazyo.cono.morny.test.utils.schedule
package cc.sukazyo.cono.morny.utils.schedule
import cc.sukazyo.cono.morny.test.MornyTests
import cc.sukazyo.cono.morny.util.schedule.{CronTask, Scheduler}
import cc.sukazyo.cono.morny.util.CommonFormat.formatDate
import cc.sukazyo.cono.morny.MornyCoreTests
import com.cronutils.builder.CronBuilder
import com.cronutils.model.definition.CronDefinitionBuilder
import com.cronutils.model.field.expression.FieldExpressionFactory as C
@ -13,7 +13,7 @@ import java.lang.System.currentTimeMillis
import java.time.{ZonedDateTime, ZoneOffset}
import java.time.temporal.ChronoUnit
class CronTaskTest extends MornyTests {
class TestCronTask extends MornyCoreTests {
"cron task works fine" taggedAs Slow in {

View File

@ -1,10 +1,10 @@
package cc.sukazyo.cono.morny.test.utils.schedule
package cc.sukazyo.cono.morny.utils.schedule
import cc.sukazyo.cono.morny.test.MornyTests
import cc.sukazyo.cono.morny.util.schedule.{IntervalWithTimesTask, Scheduler}
import cc.sukazyo.cono.morny.MornyCoreTests
import org.scalatest.tagobjects.Slow
class IntervalsTest extends MornyTests {
class TestIntervalTask extends MornyCoreTests {
"IntervalWithTimesTest should work even scheduler is scheduled to stop" taggedAs Slow in {
val scheduler = Scheduler()

View File

@ -1,10 +1,10 @@
package cc.sukazyo.cono.morny.test.utils.schedule
package cc.sukazyo.cono.morny.utils.schedule
import cc.sukazyo.cono.morny.test.MornyTests
import cc.sukazyo.cono.morny.util.schedule.Task
import cc.sukazyo.cono.morny.MornyCoreTests
import org.scalatest.tagobjects.Slow
class TaskBasicTest extends MornyTests {
class TestTaskBasics extends MornyCoreTests {
"while comparing tasks :" - {

View File

@ -1,12 +1,12 @@
package cc.sukazyo.cono.morny.test.utils.schedule
package cc.sukazyo.cono.morny.utils.schedule
import cc.sukazyo.cono.morny.test.MornyTests
import cc.sukazyo.cono.morny.util.schedule.{DelayedTask, Scheduler, Task}
import cc.sukazyo.cono.morny.MornyCoreTests
import org.scalatest.tagobjects.Slow
import scala.collection.mutable
class SchedulerTest extends MornyTests {
class TestTaskScheduler extends MornyCoreTests {
"While executing tasks using scheduler :" - {

View File

@ -1,9 +1,9 @@
package cc.sukazyo.cono.morny.test.utils.var_text
package cc.sukazyo.cono.morny.utils.var_text
import cc.sukazyo.cono.morny.test.MornyTests
import cc.sukazyo.cono.morny.util.var_text.{VarText, VTNodeLiteral, VTNodeVar}
import cc.sukazyo.cono.morny.MornyCoreTests
class VarTextTest extends MornyTests {
class TestVarText extends MornyCoreTests {
"VarText template convertor works." in {
VarText("abcdefg {one_var}{following}it /{escaped}it and this is //double-escape-literal, with a /no-need-to-escape then {{non formatted}}xxx {missing_part")

View File

Before

Width:  |  Height:  |  Size: 84 KiB

After

Width:  |  Height:  |  Size: 84 KiB

View File

@ -0,0 +1,28 @@
package cc.sukazyo.cono.morny.system
import cc.sukazyo.restools.{ResourceDirectory, ResourcePackage}
import org.scalatest.freespec.AnyFreeSpec
import org.scalatest.matchers.should.Matchers
import org.scalatest.prop.TableDrivenPropertyChecks
trait MornySystemTests
extends AnyFreeSpec
with Matchers
with TableDrivenPropertyChecks {
object Assets {
val pack: ResourcePackage = ResourcePackage.get("assets/morny-system/tests")
val root: ResourceDirectory = pack.getDirectory("assets/morny-system/tests")
}
object Sttp {
import sttp.client3.{basicRequest, Empty, RequestT}
import sttp.model.{Header, HeaderNames}
val testingBasicRequest: RequestT[Empty, Either[String, String], Any] =
basicRequest
.header(Header(HeaderNames.UserAgent, s"MornySystem / 0.0.0-tests"), true)
}
}

View File

@ -0,0 +1,151 @@
package cc.sukazyo.cono.morny.system.telegram_api.command
import cc.sukazyo.cono.morny.system.MornySystemTests
class TestInputCommand extends MornySystemTests {
"On creating InputCommand" - {
"using the basic constructor without target field, " - {
"constructor should be able to receive string array" in {
// language=scala 3
"""InputCommand(Array("test", "arg1", "arg2"))
|""".stripMargin should compile
}
"constructor should be able to receive one string" in {
// language=scala 3
"""InputCommand("test arg1 arg2")
|""".stripMargin should compile
}
"the first args should be the command name" in {
val command = InputCommand(Array("test", "arg1", "arg2"))
command.command shouldEqual "test"
}
"the rest args should be the command args" in {
val command = InputCommand(Array("test", "arg1", "arg2"))
command.args shouldEqual Array("arg1", "arg2")
}
"the command args should be an empty array if there is no args" in {
val command = InputCommand(Array("test"))
command.args shouldEqual Array.empty[String]
}
"the target should always be null" in {
val command = InputCommand(Array("test", "arg1", "arg2"))
command.target shouldBe null
val command2 = InputCommand("test")
command2.target shouldBe null
}
"when receiving one single string, it should be split using UniversalCommand format" in {
val command = InputCommand("test arg1 arg2")
command.command shouldEqual "test"
command.args shouldEqual Array("arg1", "arg2")
val command2 = InputCommand("""'test a' 'something'""")
command2.command shouldEqual "test a"
command2.args shouldEqual Array("something")
}
"the prefix '/' should not be removed" in {
val command = InputCommand("/test arg1 arg2")
command.command shouldEqual "/test"
}
"the '@' symbol in the first args should not be processed as target separator" in {
val command = InputCommand(Array("test@something", "arg1", "arg2"))
command.command shouldEqual "test@something"
command.target shouldBe null
}
def blanks (ic: InputCommand) = {
"the command name should be blank string" in {
ic.command shouldEqual ""
}
}
"when using empty array to constructor" - {
blanks(InputCommand(Array.empty[String]))
}
"when using blank string to constructor" - {
blanks(InputCommand(""))
}
}
"using the basic constructor with target field, " - {
"the target should be the second parameter" in {
val command = InputCommand(Array("test", "arg1", "arg2"), "target")
command.target shouldEqual "target"
val command2 = InputCommand("command something", "target name")
command2.target shouldEqual "target name"
}
"the first parameter should be processed like the basic constructor" in {
val command1 = InputCommand(Array("test", "arg1", "arg2"), "target")
command1.command shouldEqual "test"
command1.args shouldEqual Array("arg1", "arg2")
val command2 = InputCommand("command something", "target name")
command2.command shouldEqual "command"
command2.args shouldEqual Array("something")
}
}
"using the telegram constructor, " - {
"the string formatted command should be accepted" in {
// language=scala 3
"""InputCommand.inTelegram("test arg1 arg2")
|""".stripMargin should compile
}
"the string array formatted command should be accepted" in {
// language=scala 3
"""InputCommand.inTelegram(Array("test", "arg1", "arg2"))
|""".stripMargin should compile
}
"the command should be prased like basic constructor" in {
val command = InputCommand.inTelegram("test arg1 arg2")
command.command shouldEqual "test"
command.args shouldEqual Array("arg1", "arg2")
val command2 = InputCommand.inTelegram(Array("test", "arg1", "arg2"))
command2.command shouldEqual "test"
command2.args shouldEqual Array("arg1", "arg2")
}
"there should be no second parameter as manually defined target" in {
// language=scala 3
"""InputCommand.inTelegram("test arg1 arg2", "target")
|""".stripMargin shouldNot compile
}
"the prefix '/' should not be removed" in {
val command = InputCommand.inTelegram("/test arg1 arg2")
command.command shouldEqual "/test"
}
"the '@' symbol in the first args should be processed as target separator" in {
val command = InputCommand.inTelegram(Array("test@something", "arg1", "arg2"))
command.command shouldEqual "test"
command.target shouldEqual "something"
}
"only first '@' symbol should be processed as target separator" in {
val command = InputCommand.inTelegram(Array("test@something@else", "arg1", "arg2"))
command.command shouldEqual "test"
command.target shouldBe "something@else"
}
}
}
}

View File

@ -1,9 +1,8 @@
package cc.sukazyo.cono.morny.test.utils.tgapi.formatting
package cc.sukazyo.cono.morny.system.telegram_api.formatting
import cc.sukazyo.cono.morny.system.telegram_api.formatting.NamingUtils
import cc.sukazyo.cono.morny.test.MornyTests
import cc.sukazyo.cono.morny.system.MornySystemTests
class NamingUtilsTest extends MornyTests {
class TestNamingUtils extends MornySystemTests {
"while generating inline query result id :" - {

View File

@ -0,0 +1,9 @@
package cc.sukazyo.cono.morny.system.telegram_api.formatting
import cc.sukazyo.cono.morny.system.MornySystemTests
class TestTelegramFormatter extends MornySystemTests {
"TelegramFormatter test" in pending
}

View File

@ -1,8 +1,8 @@
package cc.sukazyo.cono.morny.test.utils.tgapi.formatting
package cc.sukazyo.cono.morny.system.telegram_api.formatting
import cc.sukazyo.cono.morny.test.MornyTests
import cc.sukazyo.cono.morny.system.MornySystemTests
class TelegramParseEscapeTest extends MornyTests {
class TestTelegramParseEscape extends MornySystemTests {
"while escape HTML document :" - {

View File

@ -1,11 +1,9 @@
package cc.sukazyo.cono.morny.test.utils.tgapi.formatting
package cc.sukazyo.cono.morny.system.telegram_api.formatting
import cc.sukazyo.cono.morny.test.MornyTests
import cc.sukazyo.cono.morny.util.SttpPublic
import org.scalatest.prop.TableDrivenPropertyChecks
import cc.sukazyo.cono.morny.system.MornySystemTests
import org.scalatest.tagobjects.{Network, Slow}
class TelegramUserInformationTest extends MornyTests with TableDrivenPropertyChecks {
class TestTelegramUserInformation extends MornySystemTests {
private val examples_telegram_cdn = Table(
("username", "cdn"),
@ -18,7 +16,7 @@ class TelegramUserInformationTest extends MornyTests with TableDrivenPropertyChe
import cc.sukazyo.cono.morny.system.telegram_api.formatting.TelegramUserInformation.*
s"datacenter should be $cdn" taggedAs (Slow, Network) in:
getDataCenterFromUser(username)(using SttpPublic.mornyBasicRequest) shouldEqual cdn
getDataCenterFromUser(username)(using Sttp.testingBasicRequest) shouldEqual cdn
"formatted data should as expected" in:
pending

View File

@ -1,15 +1,13 @@
package cc.sukazyo.cono.morny.test.utils
package cc.sukazyo.cono.morny.system.utils
import cc.sukazyo.cono.morny.test.MornyTests
import org.scalatest.prop.TableDrivenPropertyChecks
import cc.sukazyo.cono.morny.system.MornySystemTests
import cc.sukazyo.cono.morny.system.utils.CommonEncrypt.{MD5, SHA1, SHA256, SHA512}
import cc.sukazyo.cono.morny.system.utils.ConvertByteHex.toHex
class CommonEncryptTest extends MornyTests with TableDrivenPropertyChecks {
class TestCommonEncrypt extends MornySystemTests {
"while doing hash :" - {
import cc.sukazyo.cono.morny.system.utils.CommonEncrypt.{MD5, SHA1, SHA256, SHA512}
import cc.sukazyo.cono.morny.system.utils.ConvertByteHex.toHex
val examples = Table(
(
"text",
@ -52,7 +50,6 @@ class CommonEncryptTest extends MornyTests with TableDrivenPropertyChecks {
}
}
// todo: binary file source
case class ExampleHashValue (
md5: String,
sha1: String,
@ -83,7 +80,7 @@ class CommonEncryptTest extends MornyTests with TableDrivenPropertyChecks {
if file == null then
Array.empty[Byte]
else
assets.getFile(file).read.readAllBytes
Assets.root.getFile(file).read.readAllBytes
s"while hashing binary $_name :" - {

View File

@ -1,9 +1,9 @@
package cc.sukazyo.cono.morny.test.utils
package cc.sukazyo.cono.morny.system.utils
import cc.sukazyo.cono.morny.test.MornyTests
import org.scalatest.prop.TableDrivenPropertyChecks
import cc.sukazyo.cono.morny.system.MornySystemTests
import cc.sukazyo.cono.morny.system.utils.ConvertByteHex.toHex
class ConvertByteHexTest extends MornyTests with TableDrivenPropertyChecks {
class TestConvertByteHex extends MornySystemTests {
private val examples_hex = Table(
("byte" , "hex"),
@ -19,7 +19,6 @@ class ConvertByteHexTest extends MornyTests with TableDrivenPropertyChecks {
"while using Byte#toHex :" - forAll (examples_hex) ((byte, hex) => {
s"byte ($byte) should be hex '$hex''" in {
import cc.sukazyo.cono.morny.system.utils.ConvertByteHex.toHex
(byte toHex) shouldEqual hex
}
})
@ -37,7 +36,6 @@ class ConvertByteHexTest extends MornyTests with TableDrivenPropertyChecks {
"while using Array[Byte]#toHex :" - forAll(examples_hexs) ((bytes, hex) => {
s"byte array(${bytes mkString ","}) should be hex string $hex" in {
import cc.sukazyo.cono.morny.system.utils.ConvertByteHex.toHex
(bytes toHex) shouldEqual hex
}
})

View File

@ -1,10 +1,9 @@
package cc.sukazyo.cono.morny.test.utils
package cc.sukazyo.cono.morny.system.utils
import cc.sukazyo.cono.morny.system.MornySystemTests
import cc.sukazyo.cono.morny.system.utils.EpochDateTime.{EpochDays, EpochMillis, EpochSeconds}
import cc.sukazyo.cono.morny.test.MornyTests
import org.scalatest.prop.TableDrivenPropertyChecks
class EpochDateTimeTest extends MornyTests with TableDrivenPropertyChecks {
class TestEpochDateTime extends MornySystemTests {
"while converting to EpochMillis :" - {

View File

@ -1,14 +1,13 @@
package cc.sukazyo.cono.morny.test.utils
package cc.sukazyo.cono.morny.system.utils
import cc.sukazyo.cono.morny.test.MornyTests
import org.scalatest.matchers.should.Matchers
import org.scalatest.prop.TableDrivenPropertyChecks
import UniversalCommand as Cmd
class UniversalCommandTest extends MornyTests with Matchers with TableDrivenPropertyChecks {
import cc.sukazyo.cono.morny.system.MornySystemTests
import cc.sukazyo.cono.morny.system.utils.UniversalCommand.Lossy as Lmd
class TestUniversalCommand extends MornySystemTests {
"while formatting command from String :" - {
import cc.sukazyo.cono.morny.system.utils.UniversalCommand as Cmd
import cc.sukazyo.cono.morny.system.utils.UniversalCommand.Lossy as Lmd
def whileLossy (info: String): String = "in lossy mode " + info
def whileStrict (info: String): String = "in strict mode" + info
@ -25,6 +24,8 @@ class UniversalCommandTest extends MornyTests with Matchers with TableDrivenProp
"""texts and ascii-spaces in '' should grouped in one arg""" in:
Cmd("""tests 'data set'""") shouldEqual Array("tests", "data set")
Lmd("""tests 'data set'""") shouldEqual Array("tests", "data set")
Cmd("""'rich command' arg1 arg2""") shouldEqual Array("rich command", "arg1", "arg2")
Lmd("""'rich command' arg1 arg2""") shouldEqual Array("rich command", "arg1", "arg2")
"""texts and ascii-spaces in "" should grouped in one arg""" in :
Cmd("""tests "data set"""") shouldEqual Array("tests", "data set")
Lmd("""tests "data set"""") shouldEqual Array("tests", "data set")

View File

@ -45,7 +45,6 @@ object MornyConfiguration {
"com.github.spotbugs" % "spotbugs-annotations" % "4.9.1" % Compile,
"cc.sukazyo" % "messiva" % "0.2.0",
"cc.sukazyo" % "resource-tools" % "0.3.1",
"cc.sukazyo" % "da4a" % "0.2.0-SNAPSHOT" changing(),
"com.github.pengrad" % "java-telegram-bot-api" % "6.2.0",
@ -56,6 +55,8 @@ object MornyConfiguration {
"org.jsoup" % "jsoup" % "1.18.3",
"cc.sukazyo" % "resource-tools" % "0.3.2-SNAPSHOT" % Test changing(),
"org.scalatest" %% "scalatest" % "3.2.19" % Test,
"org.scalatest" %% "scalatest-freespec" % "3.2.19" % Test,
// for test report