Skip to content

Commit

Permalink
#118 added ios missing localization tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ExNDY committed Jun 6, 2024
1 parent dc51d60 commit fab0b79
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2024 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
*/

package dev.icerock.moko.resources.desc

import dev.icerock.moko.resources.StringResource
import platform.Foundation.NSBundle
import kotlin.test.Test
import kotlin.test.assertEquals

class AppleLocalizationBundleTests {

@Test
fun localizedStringWithLocalizationCaseTest() {
val resource = StringResource(
resourceId = "noResultsFound",
bundle = NSBundle.bundleWithPath(NSBundle.mainBundle.bundlePath + "/tests.bundle")!!
)
StringDesc.localeType = StringDesc.LocaleType.Custom("es-US")
val stringDesc = ResourceStringDesc(
resource
)
assertEquals(
expected = "No se han encontrado resultados",
actual = stringDesc.localized()
)
StringDesc.localeType = StringDesc.LocaleType.System
}

@Test
fun localizedStringMissingLocalizationCaseTest() {
val resource = StringResource(
resourceId = "noInternetConnection",
bundle = NSBundle.bundleWithPath(NSBundle.mainBundle.bundlePath + "/tests.bundle")!!
)
StringDesc.localeType = StringDesc.LocaleType.Custom("es-US")
val stringDesc = ResourceStringDesc(
resource
)
assertEquals(
expected = "No internet connection",
actual = stringDesc.localized()
)
StringDesc.localeType = StringDesc.LocaleType.System
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@ class PluralFormattedStringDescStringTests {
)
}

@Test
fun testMissingLocalizationCase() {
StringDesc.localeType = StringDesc.LocaleType.Custom("es-US")
assertEquals(
expected = "6/10 items",
actual = createPluralFormatted(6).localized()
)
StringDesc.localeType = StringDesc.LocaleType.System
}

private fun createPluralFormatted(number: Int): PluralFormattedStringDesc {
val pluralResource = PluralsResource(
resourceId = "stringFormatted",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"noResultsFound" = "No results found";
"noInternetConnection" = "No internet connection";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"noResultsFound" = "No se han encontrado resultados";

0 comments on commit fab0b79

Please sign in to comment.