mirror of
https://github.com/yuzono/anime-extensions.git
synced 2026-10-20 10:51:36 +00:00
[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:
@@ -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
|
||||
|
||||
27
core/src/test/kotlin/keiyoushi/utils/CollectionsTest.kt
Normal file
27
core/src/test/kotlin/keiyoushi/utils/CollectionsTest.kt
Normal 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())
|
||||
}
|
||||
}
|
||||
39
core/src/test/kotlin/keiyoushi/utils/StringsTest.kt
Normal file
39
core/src/test/kotlin/keiyoushi/utils/StringsTest.kt
Normal 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())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user