Fix truncateIdForDisplay and add test

This commit is contained in:
andrew 2023-06-01 10:50:31 +09:30
parent 22ed2dd8aa
commit 58cf8d57bf
2 changed files with 26 additions and 1 deletions

View File

@ -1,4 +1,4 @@
package org.session.libsession.utilities
fun truncateIdForDisplay(id: String): String =
id.takeIf { it.length > 8 }?.apply{ "${take(4)}${takeLast(4)}" } ?: id
id.takeIf { it.length > 8 }?.run{ "${take(4)}${takeLast(4)}" } ?: id

View File

@ -0,0 +1,25 @@
package org.session.libsession.utilities
import org.junit.Assert
import org.junit.Test
class IdUtilTest {
@Test
fun testTruncate() {
val testString = "123456789"
val result = truncateIdForDisplay(testString)
Assert.assertEquals(result, "1234…6789")
}
@Test
fun testDontTruncateShortMessage() {
val testString = "not much"
val result = truncateIdForDisplay(testString)
Assert.assertEquals(result, "not much")
}
}