Fix truncateIdForDisplay and add test
This commit is contained in:
parent
22ed2dd8aa
commit
58cf8d57bf
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue