Skip to content

Commit b4881ff

Browse files
Fix native xml parser and add ios native tests (JetBrains#4207)
Co-authored-by: Da Risk <[email protected]>
1 parent 6c38a4a commit b4881ff

File tree

6 files changed

+21
-191
lines changed

6 files changed

+21
-191
lines changed

Diff for: components/resources/library/build.gradle.kts

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import org.jetbrains.compose.ExperimentalComposeLibrary
12
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
23
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl
34

@@ -76,6 +77,9 @@ kotlin {
7677
dependencies {
7778
implementation(libs.kotlinx.coroutines.test)
7879
implementation(kotlin("test"))
80+
implementation(compose.material3)
81+
@OptIn(ExperimentalComposeLibrary::class)
82+
implementation(compose.uiTest)
7983
}
8084
}
8185
val blockingMain by creating {
+12-16
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,14 @@ import androidx.compose.runtime.*
66
import androidx.compose.ui.test.ExperimentalTestApi
77
import androidx.compose.ui.test.runComposeUiTest
88
import kotlinx.coroutines.flow.MutableStateFlow
9-
import org.junit.Assert.assertEquals
10-
import org.junit.Before
11-
import org.junit.Test
12-
import kotlin.test.assertEquals
13-
import kotlin.test.assertFailsWith
9+
import kotlin.test.*
1410

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

18-
@Before
19-
fun dropCaches() {
14+
init {
2015
dropStringsCache()
2116
dropImageCache()
22-
}
23-
24-
@Before
25-
fun configureTestEnvironment() {
2617
getResourceEnvironment = ::getTestEnvironment
2718
}
2819

@@ -111,6 +102,10 @@ class ComposeResourceTest {
111102
"Compose Resources App",
112103
stringResource(TestStringResource("app_name"))
113104
)
105+
assertEquals(
106+
"Créer une table",
107+
stringResource(TestStringResource("accentuated_characters"))
108+
)
114109
assertEquals(
115110
"Hello, test-name! You have 42 new messages.",
116111
stringResource(TestStringResource("str_template"), "test-name", 42)
@@ -127,12 +122,12 @@ class ComposeResourceTest {
127122

128123
@Test
129124
fun testLoadStringResource() = runBlockingTest {
130-
kotlin.test.assertEquals("Compose Resources App", getString(TestStringResource("app_name")))
131-
kotlin.test.assertEquals(
125+
assertEquals("Compose Resources App", getString(TestStringResource("app_name")))
126+
assertEquals(
132127
"Hello, test-name! You have 42 new messages.",
133128
getString(TestStringResource("str_template"), "test-name", 42)
134129
)
135-
kotlin.test.assertEquals(listOf("item 1", "item 2", "item 3"), getStringArray(TestStringResource("str_arr")))
130+
assertEquals(listOf("item 1", "item 2", "item 3"), getStringArray(TestStringResource("str_arr")))
136131
}
137132

138133
@Test
@@ -143,17 +138,18 @@ class ComposeResourceTest {
143138
val error = assertFailsWith<IllegalStateException> {
144139
getString(TestStringResource("unknown_id"))
145140
}
146-
kotlin.test.assertEquals("String ID=`unknown_id` is not found!", error.message)
141+
assertEquals("String ID=`unknown_id` is not found!", error.message)
147142
}
148143

149144
@Test
150145
fun testReadFileResource() = runBlockingTest {
151146
val bytes = readResourceBytes("strings.xml")
152-
kotlin.test.assertEquals(
147+
assertEquals(
153148
"""
154149
<resources>
155150
<string name="app_name">Compose Resources App</string>
156151
<string name="hello">😊 Hello world!</string>
152+
<string name="accentuated_characters">Créer une table</string>
157153
<string name="str_template">Hello, %1${'$'}s! You have %2${'$'}d new messages.</string>
158154
<string-array name="str_arr">
159155
<item>item 1</item>

Diff for: components/resources/library/src/commonTest/resources/strings.xml

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<resources>
22
<string name="app_name">Compose Resources App</string>
33
<string name="hello">😊 Hello world!</string>
4+
<string name="accentuated_characters">Créer une table</string>
45
<string name="str_template">Hello, %1$s! You have %2$d new messages.</string>
56
<string-array name="str_arr">
67
<item>item 1</item>

Diff for: components/resources/library/src/desktopTest/kotlin/org/jetbrains/compose/resources/ComposeResourceTest.desktop.kt

-169
This file was deleted.

Diff for: components/resources/library/src/nativeMain/kotlin/org/jetbrains/compose/resources/vector/xmldom/DomXmlParser.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ private class DomXmlParser : NSObject(), NSXMLParserDelegateProtocol {
9494
}
9595

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

100102
override fun parser(

Diff for: components/test.sh

+1-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
cd "$(dirname "$0")" # Run always in current dir
33
set -euo pipefail # Fail fast
44

5-
# Unit tests
6-
./gradlew :resources:library:test
75
./gradlew :resources:library:desktopTest
8-
9-
# Android integration tests
106
./gradlew :resources:library:pixel5DebugAndroidTest
11-
7+
./gradlew :resources:library:iosSimulatorArm64Test

0 commit comments

Comments
 (0)