-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: (backup) cqcode serialization
- Loading branch information
Showing
6 changed files
with
53 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 7 additions & 10 deletions
17
...ization-cqcode/src/commonTest/kotlin/io/github/mystere/serialization/cqcode/CQCodeTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,18 @@ | ||
package io.github.mystere.serialization.cqcode | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.assertIs | ||
import kotlin.test.assertTrue | ||
import kotlin.test.assertEquals | ||
|
||
class CQCodeTest { | ||
@Test | ||
fun singleFaceTest() { | ||
val faceId = 142L | ||
val message = fromString("singleFaceTest", "[CQ:face,id=$faceId]") | ||
assertTrue("items not only one") { message.size == 1 } | ||
assertTrue("item not a Face") { message[0].type == CQCodeMessageItem.Type.Face } | ||
assertTrue("Face id not $faceId") { (message[0] as CQCodeMessageItem.Face).id == faceId } | ||
} | ||
|
||
private fun fromString(callFrom: String, string: String): CQCodeMessage { | ||
return CQCode.decodeFromString(string).also { | ||
println("fromString<$callFrom>: $it") | ||
fromString("[CQ:face,id=142]") { | ||
assertSize(1) | ||
assertEquals(0, CQCodeMessageItem.Face( | ||
id = 142L | ||
)) | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...serialization-cqcode/src/commonTest/kotlin/io/github/mystere/serialization/cqcode/Util.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.mystere.serialization.cqcode | ||
|
||
import kotlin.test.assertTrue | ||
|
||
|
||
fun fromString(string: String, block: CQCodeMessage.() -> Unit) { | ||
with(CQCode.decodeFromString(string), block) | ||
} | ||
|
||
fun CQCodeMessage.assertSize(size: Int) { | ||
kotlin.with(this@assertSize.size) { | ||
assertTrue("items size is not $size, but $this") { this == size } | ||
} | ||
} | ||
fun CQCodeMessage.with(index: Int, block: CQCodeMessageItem.() -> Unit) { | ||
with(this[index], block) | ||
} | ||
inline fun <reified T: CQCodeMessageItem> CQCodeMessageItem.assertEquals(item: T) { | ||
kotlin.test.assertIs<T>(this, "item is not ${T::class.simpleName}, but ${this::class.simpleName}") | ||
kotlin.test.assertEquals(this, item, "expect item is $item, but $this") | ||
} | ||
inline fun <reified T: CQCodeMessageItem> CQCodeMessage.assertEquals(index: Int, item: T) { | ||
with(index) { | ||
assertEquals(item) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,7 +57,7 @@ kotlin { | |
// jvm | ||
val jvmMain by getting { | ||
dependencies { | ||
implementation(mystere.logback.classic) | ||
|
||
} | ||
} | ||
|
||
|