[skip yuzono ci] core: add tests for unescapeUnicode and chunkedPairs

StringsTest covers both hex cases, paired and lone surrogate halves, other and malformed escapes being left untouched, and the escaped-backslash case the KDoc describes. CollectionsTest covers chunkedPairs on empty, even-length and odd-length lists and on a sequence.

Only tests are added, so nothing needs bumping or building.
This commit is contained in:
Cuong-Tran
2026-10-15 18:22:26 +07:00
parent 1e0245670f
commit 46c449836d
3 changed files with 69 additions and 3 deletions

View File

@@ -24,9 +24,9 @@ Module paths are colon-separated and mirror the directory layout: `:src:en:mirur
### Tests
`core/src/test/kotlin/keiyoushi/utils/` holds the repo's only unit tests (`NextJsTest`, `UrlUtilsTest`).
Extensions have none – they are verified by compiling and running against the live site
(`CONTRIBUTING.md#submitting-the-changes` ~ `1369`).
The repo's only unit tests are in `core/src/test/kotlin/keiyoushi/utils/`, `lib/unpacker/test/kotlin/`
and `lib/megaextractor/test/`. Extensions have none – they are verified by compiling and running
against the live site (`CONTRIBUTING.md#submitting-the-changes` ~ `1369`).
```bash
./gradlew --continue :core:testDebugUnitTest :lib:unpacker:testDebugUnitTest :lib:megaextractor:testDebugUnitTest

View File

@@ -0,0 +1,27 @@
package keiyoushi.utils
import org.junit.Assert.assertEquals
import org.junit.Test
class CollectionsTest {
@Test
fun `chunkedPairs of an empty list is empty`() {
assertEquals(emptyList<Pair<Int, Int>>(), emptyList<Int>().chunkedPairs())
}
@Test
fun `chunkedPairs groups an even-length list into pairs`() {
assertEquals(listOf(1 to 2, 3 to 4), listOf(1, 2, 3, 4).chunkedPairs())
}
@Test
fun `chunkedPairs drops a trailing element without a partner`() {
assertEquals(listOf(1 to 2), listOf(1, 2, 3).chunkedPairs())
}
@Test
fun `chunkedPairs on a sequence drops a trailing element without a partner`() {
assertEquals(listOf(1 to 2, 3 to 4), sequenceOf(1, 2, 3, 4, 5).chunkedPairs().toList())
}
}

View File

@@ -0,0 +1,39 @@
package keiyoushi.utils
import org.junit.Assert.assertEquals
import org.junit.Test
class StringsTest {
@Test
fun `unescapeUnicode decodes escapes in either hex case`() {
assertEquals("Fran\u00e7ais \u00e7", """Fran\u00e7ais \u00E7""".unescapeUnicode())
}
@Test
fun `unescapeUnicode decodes each surrogate half`() {
assertEquals("\uD83D\uDE00", """\ud83d\ude00""".unescapeUnicode())
}
@Test
fun `unescapeUnicode decodes a lone surrogate half`() {
assertEquals("\uD83D", """\ud83d""".unescapeUnicode())
}
@Test
fun `unescapeUnicode leaves other escapes untouched`() {
val input = """https:\/\/a.com\/e\n\\"""
assertEquals(input, input.unescapeUnicode())
}
@Test
fun `unescapeUnicode leaves malformed escapes untouched`() {
val input = """\u12 \u12zz \u"""
assertEquals(input, input.unescapeUnicode())
}
@Test
fun `unescapeUnicode decodes the escape after an escaped backslash`() {
assertEquals("""\A""", """\\u0041""".unescapeUnicode())
}
}