From c8816e679a623bb4ad197e563914de9a71ad5652 Mon Sep 17 00:00:00 2001 From: Him188 Date: Fri, 6 Dec 2019 18:05:21 +0800 Subject: [PATCH] Add test --- .../src/main/java/japttest/SuspendTest.java | 29 +++++++++++++++++++ mirai-debug/src/main/kotlin/test/JaptTest.kt | 13 +++++++++ 2 files changed, 42 insertions(+) create mode 100644 mirai-debug/src/main/java/japttest/SuspendTest.java create mode 100644 mirai-debug/src/main/kotlin/test/JaptTest.kt diff --git a/mirai-debug/src/main/java/japttest/SuspendTest.java b/mirai-debug/src/main/java/japttest/SuspendTest.java new file mode 100644 index 000000000..8a8df0f01 --- /dev/null +++ b/mirai-debug/src/main/java/japttest/SuspendTest.java @@ -0,0 +1,29 @@ +package japttest; + +import kotlinx.coroutines.BuildersKt; +import kotlinx.coroutines.GlobalScope; +import net.mamoe.mirai.Bot; +import net.mamoe.mirai.BotAccount; +import net.mamoe.mirai.network.protocol.tim.packet.login.LoginResult; +import net.mamoe.mirai.network.protocol.tim.packet.login.SubmitPasswordPacket; +import test.JaptTestKt; + +@SuppressWarnings("unused") +public class SuspendTest { + + public static void main(String[] args) throws InterruptedException { + // TODO: 2019/12/6 Kotlin or IDE bug here + boolean bool = JaptTestKt.getLoginResult() == LoginResult.YOU_CAN_WRITE_ANY_THING; + + BuildersKt.runBlocking(GlobalScope.INSTANCE.getCoroutineContext(), (scope, continuation) -> { + Bot bot = new Bot(new BotAccount(1994701021L, ""), scope.getCoroutineContext()); + if (bot.network.login(continuation) instanceof SubmitPasswordPacket.LoginResponse.Success) { + System.out.println("login successful"); + } + return null; + }); + + System.out.println("Hello world finished"); + + } +} diff --git a/mirai-debug/src/main/kotlin/test/JaptTest.kt b/mirai-debug/src/main/kotlin/test/JaptTest.kt new file mode 100644 index 000000000..596d63f12 --- /dev/null +++ b/mirai-debug/src/main/kotlin/test/JaptTest.kt @@ -0,0 +1,13 @@ +package test + +import net.mamoe.mirai.network.protocol.tim.packet.login.LoginResult + +@Suppress("RedundantSuspendModifier") +suspend fun suspendPrintln(arg: String) = println(arg) + +suspend fun main() { + suspendPrintln("Hello") + suspendPrintln(" World!") +} + +fun getLoginResult(): LoginResult = LoginResult.SUCCESS \ No newline at end of file