Skip to content

Commit

Permalink
Merge pull request #86 from novasamatech/fix/captialize_locale
Browse files Browse the repository at this point in the history
Fix/captialize locale
  • Loading branch information
valentunn authored Apr 12, 2024
2 parents 45e1de2 + 22a7808 commit b844a47
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
// App version
versionName = '2.0.1'
versionName = '2.0.2'
versionCode = 1

// SDK and tools
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.novasama.substrate_sdk_android.hash.isNegative
import java.math.BigInteger
import java.nio.ByteBuffer
import java.nio.ByteOrder
import java.util.Locale

inline fun <T, R> Iterable<T>.tryFindNonNull(transform: (T) -> R?): R? {
for (item in this) {
Expand Down Expand Up @@ -108,7 +109,7 @@ fun ByteArray.split(divider: ByteArray): List<ByteArray> {
internal fun String.snakeCaseToCamelCase(): String {
return split("_").mapIndexed { index, segment ->
if (index > 0) { // do not capitalize first segment
segment.capitalize()
segment.capitalize(Locale.ROOT)
} else {
segment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.novasama.substrate_sdk_android.runtime.definitions.types.generics

import io.novasama.substrate_sdk_android.encrypt.EncryptionType
import io.novasama.substrate_sdk_android.runtime.definitions.types.composite.DictEnum
import java.util.Locale

class MultiSignature(val encryptionType: EncryptionType, val value: ByteArray)

Expand All @@ -16,7 +17,7 @@ fun Extrinsic.Signature.tryExtractMultiSignature(): MultiSignature? {
}

private val EncryptionType.multiSignatureName
get() = rawName.capitalize()
get() = rawName.capitalize(Locale.ROOT)

fun MultiSignature.prepareForEncoding(): Any {
return DictEnum.Entry(encryptionType.multiSignatureName, value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
package io.novasama.substrate_sdk_android.extensions

import org.junit.Assert.*
import org.junit.Assert.assertEquals
import org.junit.Test
import java.util.Locale

class SnakeToCamelCaseTest {

@Test
fun test() {
fun shouldPerformConversion() {
runTest("", "")
runTest("test", "test")
runTest("one_two", "oneTwo")
runTest("one_two_three", "oneTwoThree")
}

@Test
fun shouldIgnoreLocale() {
// turkish languages is one of those who has exotic rules for letter capitalization, specifically for letter 'i'
Locale.setDefault(Locale("tr"))

runTest("fund_index", "fundIndex")
}

private fun runTest(
origin: String,
expected: String
Expand Down

0 comments on commit b844a47

Please sign in to comment.