Skip to content

Commit

Permalink
Fix native xml parser and add ios native tests (#4207)
Browse files Browse the repository at this point in the history
Co-authored-by: Da Risk <[email protected]>
  • Loading branch information
terrakok and fbarthelery authored Jan 30, 2024
1 parent 6c38a4a commit b4881ff
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 191 deletions.
4 changes: 4 additions & 0 deletions components/resources/library/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import org.jetbrains.compose.ExperimentalComposeLibrary
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

Expand Down Expand Up @@ -76,6 +77,9 @@ kotlin {
dependencies {
implementation(libs.kotlinx.coroutines.test)
implementation(kotlin("test"))
implementation(compose.material3)
@OptIn(ExperimentalComposeLibrary::class)
implementation(compose.uiTest)
}
}
val blockingMain by creating {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@ import androidx.compose.runtime.*
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.runComposeUiTest
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.*

@OptIn(ExperimentalTestApi::class, ExperimentalResourceApi::class, InternalResourceApi::class)
class ComposeResourceTest {

@Before
fun dropCaches() {
init {
dropStringsCache()
dropImageCache()
}

@Before
fun configureTestEnvironment() {
getResourceEnvironment = ::getTestEnvironment
}

Expand Down Expand Up @@ -111,6 +102,10 @@ class ComposeResourceTest {
"Compose Resources App",
stringResource(TestStringResource("app_name"))
)
assertEquals(
"Créer une table",
stringResource(TestStringResource("accentuated_characters"))
)
assertEquals(
"Hello, test-name! You have 42 new messages.",
stringResource(TestStringResource("str_template"), "test-name", 42)
Expand All @@ -127,12 +122,12 @@ class ComposeResourceTest {

@Test
fun testLoadStringResource() = runBlockingTest {
kotlin.test.assertEquals("Compose Resources App", getString(TestStringResource("app_name")))
kotlin.test.assertEquals(
assertEquals("Compose Resources App", getString(TestStringResource("app_name")))
assertEquals(
"Hello, test-name! You have 42 new messages.",
getString(TestStringResource("str_template"), "test-name", 42)
)
kotlin.test.assertEquals(listOf("item 1", "item 2", "item 3"), getStringArray(TestStringResource("str_arr")))
assertEquals(listOf("item 1", "item 2", "item 3"), getStringArray(TestStringResource("str_arr")))
}

@Test
Expand All @@ -143,17 +138,18 @@ class ComposeResourceTest {
val error = assertFailsWith<IllegalStateException> {
getString(TestStringResource("unknown_id"))
}
kotlin.test.assertEquals("String ID=`unknown_id` is not found!", error.message)
assertEquals("String ID=`unknown_id` is not found!", error.message)
}

@Test
fun testReadFileResource() = runBlockingTest {
val bytes = readResourceBytes("strings.xml")
kotlin.test.assertEquals(
assertEquals(
"""
<resources>
<string name="app_name">Compose Resources App</string>
<string name="hello">😊 Hello world!</string>
<string name="accentuated_characters">Créer une table</string>
<string name="str_template">Hello, %1${'$'}s! You have %2${'$'}d new messages.</string>
<string-array name="str_arr">
<item>item 1</item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<resources>
<string name="app_name">Compose Resources App</string>
<string name="hello">😊 Hello world!</string>
<string name="accentuated_characters">Créer une table</string>
<string name="str_template">Hello, %1$s! You have %2$d new messages.</string>
<string-array name="str_arr">
<item>item 1</item>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ private class DomXmlParser : NSObject(), NSXMLParserDelegateProtocol {
}

override fun parser(parser: NSXMLParser, foundCharacters: String) {
nodeStack.lastOrNull()?.textContent = foundCharacters
nodeStack.lastOrNull()?.let { node ->
node.textContent = node.textContent.orEmpty() + foundCharacters
}
}

override fun parser(
Expand Down
6 changes: 1 addition & 5 deletions components/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
cd "$(dirname "$0")" # Run always in current dir
set -euo pipefail # Fail fast

# Unit tests
./gradlew :resources:library:test
./gradlew :resources:library:desktopTest

# Android integration tests
./gradlew :resources:library:pixel5DebugAndroidTest

./gradlew :resources:library:iosSimulatorArm64Test

0 comments on commit b4881ff

Please sign in to comment.