diff --git a/build.gradle b/build.gradle index a14668f..c874146 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ import org.ajoberstar.grgit.Status import java.nio.charset.Charset import java.nio.charset.StandardCharsets -final boolean proj_git = grgit!=null +final boolean proj_git = grgit != null final String proj_store = MORNY_CODE_STORE final String proj_commit = proj_git ? grgit.head().id : null final String proj_commit_path = MORNY_COMMIT_PATH @@ -23,7 +23,8 @@ if (!proj_git) println "[MornyBuild] git repository not available for current working space! git version tag will be disabled." else if (isCleanBuild()) { println "git: clean build at ${grgit.head().id}" -} else { +} +else { final Status status = grgit.status() println "git: non-clean-build" if (!status.unstaged.allChanges.empty) { @@ -45,7 +46,8 @@ final String proj_version_base = VERSION final String proj_version_delta = VERSION_DELTA final boolean proj_version_use_delta = Boolean.parseBoolean(USE_DELTA) final String proj_version = proj_version_base + (proj_version_use_delta ? "-δ${proj_version_delta}" : "") -final String proj_version_full = proj_version + (proj_git ? "+git.${proj_commit.substring(0, 8)}" + (proj_clean?"":".δ") : "") +final String proj_version_full = proj_version + (proj_git ? + "+git.${proj_commit.substring(0, 8)}" + (proj_clean ? "" : ".δ") : "") final String proj_version_codename = CODENAME final long proj_code_time = proj_clean ? grgit.head().dateTime.toInstant().toEpochMilli() : System.currentTimeMillis() @@ -53,7 +55,7 @@ final JavaVersion proj_java = JavaVersion.VERSION_17 final Charset proj_file_encoding = StandardCharsets.UTF_8 final proj_scala_api = 3 //final proj_scala_lib = proj_scala_api+'.4.0-RC1-bin-20230901-89e8dba-NIGHTLY' -final proj_scala_lib = proj_scala_api+'.3.1' +final proj_scala_lib = proj_scala_api + '.3.1' String publish_local_url = null String publish_remote_url = null String publish_remote_username = null @@ -80,6 +82,7 @@ dependencies { implementation "cc.sukazyo:messiva:${lib_messiva_v}" implementation "cc.sukazyo:resource-tools:${lib_resourcetools_v}" + testImplementation "cc.sukazyo:resource-tools:${lib_resourcetools_v}" implementation "com.github.pengrad:java-telegram-bot-api:${lib_javatelegramapi_v}" implementation "com.squareup.okhttp3:okhttp:${lib_okhttp_v}" @@ -88,7 +91,8 @@ dependencies { testImplementation "org.scalatest:scalatest_$proj_scala_api:${lib_scalatest_v}" testImplementation "org.scalatest:scalatest-freespec_$proj_scala_api:${lib_scalatest_v}" testRuntimeOnly "org.scala-lang.modules:scala-xml_$proj_scala_api:${lib_scalamodule_xml_v}" - testRuntimeOnly 'com.vladsch.flexmark:flexmark-all:0.64.6' // for generating HTML report // required by gradle-scalatest plugin + testRuntimeOnly 'com.vladsch.flexmark:flexmark-all:0.64.6' + // for generating HTML report // required by gradle-scalatest plugin } @@ -155,10 +159,10 @@ buildConfig { buildConfigField('String', 'VERSION_DELTA', proj_version_use_delta ? "\"${proj_version_delta}\"" : "null") buildConfigField('String', 'CODENAME', "\"${proj_version_codename}\"") buildConfigField('long', 'CODE_TIMESTAMP', "${proj_code_time}L") - buildConfigField('String', 'COMMIT', proj_git ? "\"${proj_commit}\"" : "null") + buildConfigField('String', 'COMMIT', proj_git ? "\"${proj_commit}\"" : "null") buildConfigField('boolean', 'CLEAN_BUILD', "${proj_clean}") - buildConfigField('String', 'CODE_STORE', proj_store==""?"null":"\"${proj_store}\"") - buildConfigField('String', 'COMMIT_PATH', proj_commit_path==""?"null":"\"${proj_commit_path}\"") + buildConfigField('String', 'CODE_STORE', proj_store == "" ? "null" : "\"${proj_store}\"") + buildConfigField('String', 'COMMIT_PATH', proj_commit_path == "" ? "null" : "\"${proj_commit_path}\"") } @@ -200,7 +204,7 @@ void listChanges (Status.Changes listing) { } publishing { - repositories{ + repositories { if (publish_local_url != null) maven { name 'archives' url publish_local_url @@ -216,7 +220,7 @@ publishing { } publications { //noinspection GroovyAssignabilityCheck - main (MavenPublication) { + main(MavenPublication) { //noinspection GroovyAssignabilityCheck from components.java //noinspection GroovyAssignabilityCheck diff --git a/src/test/resources/assets_morny_tests/md5.gif b/src/test/resources/assets_morny_tests/md5.gif new file mode 100644 index 0000000..eff7bd0 Binary files /dev/null and b/src/test/resources/assets_morny_tests/md5.gif differ diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/MornyTests.scala b/src/test/scala/cc/sukazyo/cono/morny/test/MornyTests.scala index 8d62c60..dd1fc9f 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/MornyTests.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/MornyTests.scala @@ -1,10 +1,14 @@ package cc.sukazyo.cono.morny.test +import cc.sukazyo.restools.ResourcesPackage import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should abstract class MornyTests extends AnyFreeSpec with should.Matchers { + val assets: ResourcesPackage = + ResourcesPackage(classOf[MornyTests], "assets_morny_tests") + val pending_val = "[not-implemented]" } diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/cc/sukazyo/cono/morny/bot/event/OnQuestionMarkReplyTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/bot/event/OnQuestionMarkReplyTest.scala similarity index 92% rename from src/test/scala/cc/sukazyo/cono/morny/test/cc/sukazyo/cono/morny/bot/event/OnQuestionMarkReplyTest.scala rename to src/test/scala/cc/sukazyo/cono/morny/test/bot/event/OnQuestionMarkReplyTest.scala index 3e23d57..1c8de88 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/cc/sukazyo/cono/morny/bot/event/OnQuestionMarkReplyTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/bot/event/OnQuestionMarkReplyTest.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.test.cc.sukazyo.cono.morny.bot.event +package cc.sukazyo.cono.morny.test.bot.event import cc.sukazyo.cono.morny.bot.event.OnQuestionMarkReply import cc.sukazyo.cono.morny.test.MornyTests diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/cc/sukazyo/cono/morny/daemon/MedicationTimerTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/cc/sukazyo/cono/morny/daemon/MedicationTimerTest.scala deleted file mode 100644 index b6057b9..0000000 --- a/src/test/scala/cc/sukazyo/cono/morny/test/cc/sukazyo/cono/morny/daemon/MedicationTimerTest.scala +++ /dev/null @@ -1,42 +0,0 @@ -package cc.sukazyo.cono.morny.test.cc.sukazyo.cono.morny.daemon - -import cc.sukazyo.cono.morny.daemon.MedicationTimer -import cc.sukazyo.cono.morny.test.MornyTests -import cc.sukazyo.cono.morny.util.EpochDateTime.EpochMillis -import org.scalatest.prop.TableDrivenPropertyChecks - -import java.time.ZoneOffset - -class MedicationTimerTest extends MornyTests with TableDrivenPropertyChecks { - - "on calculating next notify time :" - { - - val examples = Table( - ("current" , "notifyAt" , "useTimezone", "nextNotifyTime"), - (("2023-10-09T23:54:10.000","+8"), Set(1, 5, 19) , "+8" , ("2023-10-10T01:00:00.000","+8")), - (("2022-11-13T13:14:15.000","+2"), Set(7, 19, 21) , "+2" , ("2022-11-13T19:00:00.000","+2")), - (("2022-11-13T13:14:35.000","+8"), Set(7, 19, 21) , "+8" , ("2022-11-13T19:00:00" ,"+8")), - (("2022-11-13T13:14:35.174","+2"), Set(7, 19, 21) , "+2" , ("2022-11-13T19:00:00" ,"+2")), - (("1998-02-01T08:14:35.871","+8"), Set(7, 19, 21) , "+8" , ("1998-02-01T19:00:00" ,"+8")), - (("2022-11-13T00:00:00.000","-1"), Set(7, 19, 21) , "-1" , ("2022-11-13T07:00:00" ,"-1")), - (("2022-11-21T19:00:00.000","+0"), Set(7, 19, 21) , "+0" , ("2022-11-21T21:00:00" ,"+0")), - (("2022-12-31T21:00:00.000","+0"), Set(7, 19, 21) , "+0" , ("2023-01-01T07:00:00" ,"+0")), - (("2125-11-18T23:45:27.062","+0"), Set(7, 19, 21) , "+0" , ("2125-11-19T07:00:00" ,"+0")) - ) - - forAll (examples) { (current, notifyAt, useTimezone, nextNotifyTime) => - val _curr = EpochMillis(current) - val _tz = ZoneOffset of useTimezone - val _next = EpochMillis(nextNotifyTime) - - s"at time [$_curr], and need to be notify at hours ${notifyAt.mkString(",")} with $_tz :" - { - s"next notify should at time [$_curr]" in { - MedicationTimer.calcNextRoutineTimestamp(_curr, _tz, notifyAt) shouldEqual _next - } - } - - } - - } - -} diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/daemon/MedicationTimerTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/daemon/MedicationTimerTest.scala new file mode 100644 index 0000000..9ac6686 --- /dev/null +++ b/src/test/scala/cc/sukazyo/cono/morny/test/daemon/MedicationTimerTest.scala @@ -0,0 +1,42 @@ +package cc.sukazyo.cono.morny.test.daemon + +import cc.sukazyo.cono.morny.daemon.MedicationTimer +import cc.sukazyo.cono.morny.test.MornyTests +import cc.sukazyo.cono.morny.util.EpochDateTime.EpochMillis +import org.scalatest.prop.TableDrivenPropertyChecks + +import java.time.ZoneOffset + +class MedicationTimerTest extends MornyTests with TableDrivenPropertyChecks { + + "on calculating next notify time :" - { + + val examples = Table( + ("current", "notifyAt", "useTimezone", "nextNotifyTime"), + (("2023-10-09T23:54:10.000", "+8"), Set(1, 5, 19), "+8", ("2023-10-10T01:00:00.000", "+8")), + (("2022-11-13T13:14:15.000", "+2"), Set(7, 19, 21), "+2", ("2022-11-13T19:00:00.000", "+2")), + (("2022-11-13T13:14:35.000", "+8"), Set(7, 19, 21), "+8", ("2022-11-13T19:00:00", "+8")), + (("2022-11-13T13:14:35.174", "+2"), Set(7, 19, 21), "+2", ("2022-11-13T19:00:00", "+2")), + (("1998-02-01T08:14:35.871", "+8"), Set(7, 19, 21), "+8", ("1998-02-01T19:00:00", "+8")), + (("2022-11-13T00:00:00.000", "-1"), Set(7, 19, 21), "-1", ("2022-11-13T07:00:00", "-1")), + (("2022-11-21T19:00:00.000", "+0"), Set(7, 19, 21), "+0", ("2022-11-21T21:00:00", "+0")), + (("2022-12-31T21:00:00.000", "+0"), Set(7, 19, 21), "+0", ("2023-01-01T07:00:00", "+0")), + (("2125-11-18T23:45:27.062", "+0"), Set(7, 19, 21), "+0", ("2125-11-19T07:00:00", "+0")) + ) + + forAll(examples) { (current, notifyAt, useTimezone, nextNotifyTime) => + val _curr = EpochMillis(current) + val _tz = ZoneOffset of useTimezone + val _next = EpochMillis(nextNotifyTime) + + s"at time [$_curr], and need to be notify at hours ${notifyAt.mkString(",")} with $_tz :" - { + s"next notify should at time [$_curr]" in { + MedicationTimer.calcNextRoutineTimestamp(_curr, _tz, notifyAt) shouldEqual _next + } + } + + } + + } + +} diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/cc/sukazyo/cono/morny/data/BilibiliFormsTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/data/BilibiliFormsTest.scala similarity index 99% rename from src/test/scala/cc/sukazyo/cono/morny/test/cc/sukazyo/cono/morny/data/BilibiliFormsTest.scala rename to src/test/scala/cc/sukazyo/cono/morny/test/data/BilibiliFormsTest.scala index 93388f5..c3dde75 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/cc/sukazyo/cono/morny/data/BilibiliFormsTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/data/BilibiliFormsTest.scala @@ -1,4 +1,4 @@ -package cc.sukazyo.cono.morny.test.cc.sukazyo.cono.morny.data +package cc.sukazyo.cono.morny.test.data import cc.sukazyo.cono.morny.data.BilibiliForms.* import cc.sukazyo.cono.morny.test.MornyTests diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/utils/CommonEncryptTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/utils/CommonEncryptTest.scala index 9bd4a9d..06f5c38 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/utils/CommonEncryptTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/utils/CommonEncryptTest.scala @@ -67,13 +67,23 @@ class CommonEncryptTest extends MornyTests with TableDrivenPropertyChecks { "da39a3ee5e6b4b0d3255bfef95601890afd80709", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" - ) - ) + )), + ( + "md5.gif", ExampleHashValue( + "f5ca4f935d44b85c431a8bf788c0eaca", + "784cefac7a3699d704756d1a04189d6157405906", + "c0aa75d5345efae1019ca7a56eabc8673499dcee8ab8a8d657fb69f1f929b909", + "2d3123c543aa1745eeae57d2e6c31b6ea07dd2bb14cef2b5939116f9cf705953fb43cf6162c87ee1c7175d1de4af6d9de6f2bc817065cc854b912877848f937b" + )) ) forAll(examples_binary) { (file, hashes) => val _name = if file == null then "empty file" else s"file $file" - val _data = if file == null then Array.empty[Byte] else throw NotImplementedError("does not applied file get yet") + val _data = + if file == null then + Array.empty[Byte] + else + assets.getResource(file).read.readAllBytes s"while hashing binary $_name :" - { diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/utils/FileUtilsTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/utils/FileUtilsTest.scala deleted file mode 100644 index 1873d12..0000000 --- a/src/test/scala/cc/sukazyo/cono/morny/test/utils/FileUtilsTest.scala +++ /dev/null @@ -1,9 +0,0 @@ -package cc.sukazyo.cono.morny.test.utils - -import cc.sukazyo.cono.morny.test.MornyTests - -class FileUtilsTest extends MornyTests { - - "while getting the MD5 hash of a file :" in pending - -} diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/formatting/NamingUtilsTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/formatting/NamingUtilsTest.scala index 883d8aa..db8fe84 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/formatting/NamingUtilsTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/formatting/NamingUtilsTest.scala @@ -1,24 +1,39 @@ package cc.sukazyo.cono.morny.test.utils.tgapi.formatting import cc.sukazyo.cono.morny.test.MornyTests +import cc.sukazyo.cono.morny.util.tgapi.formatting.NamingUtils class NamingUtilsTest extends MornyTests { "while generating inline query result id :" - { + import NamingUtils.inlineQueryId + "while not use no data :" - { - "(different tag) should return different id" in pending - "(same tag) should return the same id" in pending + "(different tag) should return different id" in: + inlineQueryId("abc") should not equal inlineQueryId("abd") + inlineQueryId("abc") should not equal inlineQueryId("abe") + "(same tag) should return the same id" in: + inlineQueryId("abc") shouldEqual inlineQueryId("abc") + inlineQueryId("[e]vo]wvr'L\"pno[irvP)v]") shouldEqual inlineQueryId("[e]vo]wvr'L\"pno[irvP)v]") } "while use data :" - { - "(same tag) with (same data) should return the same id" in pending - "(same tag) with (different data) should return different id" in pending - "(different tag) with (same data) should return different id" in pending - "change tag and data position should return different id" in pending + "(same tag) with (same data) should return the same id" in: + inlineQueryId("random-tag", "123456789") shouldEqual + inlineQueryId("random-tag", "123456789") + "(same tag) with (different data) should return different id" in: + inlineQueryId("random-tag", "123456789") should not equal + inlineQueryId("random-tag", "987654321") + "(different tag) with (same data) should return different id" in: + inlineQueryId("random-tag", "123456789") should not equal + inlineQueryId("set-tag", "123456789") + "change tag and data position should return different id" in: + inlineQueryId("tag", "data") should not equal + inlineQueryId("data", "tag") } diff --git a/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/formatting/TelegramUserInformationTest.scala b/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/formatting/TelegramUserInformationTest.scala index c839a5b..a38ec53 100644 --- a/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/formatting/TelegramUserInformationTest.scala +++ b/src/test/scala/cc/sukazyo/cono/morny/test/utils/tgapi/formatting/TelegramUserInformationTest.scala @@ -9,6 +9,7 @@ class TelegramUserInformationTest extends MornyTests with TableDrivenPropertyChe private val examples_telegram_cdn = Table( ("username", "cdn"), ("Eyre_S", "cdn5"), + ("ankarinnie", "cdn1") ) forAll(examples_telegram_cdn) ((username, cdn) => s"while user is @$username :" - {