diff options
-rw-r--r-- | BUILD.bazel | 1 | ||||
-rw-r--r-- | compiler/build.gradle | 1 | ||||
-rw-r--r-- | compiler/src/main/java/android/databinding/tool/util/SymbolTableUtil.kt | 16 | ||||
-rw-r--r-- | compiler/src/test/java/android/databinding/tool/util/SymbolTableUtilTest.kt | 26 |
4 files changed, 32 insertions, 12 deletions
diff --git a/BUILD.bazel b/BUILD.bazel index 6670d54a..b4022c82 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -314,6 +314,7 @@ kotlin_test( "@maven//:com.google.truth.truth", "@maven//:commons-io.commons-io", "@maven//:junit.junit", + "@maven//:org.jetbrains.kotlin.kotlin-test", "@maven//:org.mockito.mockito-core", ], ) diff --git a/compiler/build.gradle b/compiler/build.gradle index e744f865..be805379 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -48,6 +48,7 @@ dependencies { implementation libs.juniversalchardet implementation libs.jaxb_runtime testImplementation libs.junit + testImplementation libs.kotlin_test testImplementation libs.mockito_core testImplementation libs.compile_testing testImplementation libs.truth diff --git a/compiler/src/main/java/android/databinding/tool/util/SymbolTableUtil.kt b/compiler/src/main/java/android/databinding/tool/util/SymbolTableUtil.kt index ab57d62e..1b6a4481 100644 --- a/compiler/src/main/java/android/databinding/tool/util/SymbolTableUtil.kt +++ b/compiler/src/main/java/android/databinding/tool/util/SymbolTableUtil.kt @@ -84,18 +84,10 @@ fun parseRTxtFiles( val symbolTables = ImmutableList.builder<SymbolTable>() // local resources at the front of the list symbolTables.add(parseLocalRTxt(localRFile)) - when { - dependenciesRFiles != null -> { - // then add the rest of the dependencies, in order - dependenciesRFiles.forEach { symbolTables.add(parsePackageAwareRTxt(it)) } - } - mergedDependenciesRFile != null -> { - parseMergedPackageAwareRTxt(mergedDependenciesRFile, symbolTables) - } - else -> { - error("Unexpected error: Missing dependency resources") - } - } + + // then add the rest of the dependencies, in order + dependenciesRFiles?.forEach { symbolTables.add(parsePackageAwareRTxt(it)) } + mergedDependenciesRFile?.let { parseMergedPackageAwareRTxt(it, symbolTables) } return Resources(symbolTables.build()) } diff --git a/compiler/src/test/java/android/databinding/tool/util/SymbolTableUtilTest.kt b/compiler/src/test/java/android/databinding/tool/util/SymbolTableUtilTest.kt index f33738c6..2c23649c 100644 --- a/compiler/src/test/java/android/databinding/tool/util/SymbolTableUtilTest.kt +++ b/compiler/src/test/java/android/databinding/tool/util/SymbolTableUtilTest.kt @@ -17,11 +17,13 @@ package android.databinding.tool.util import com.google.common.collect.ImmutableList +import com.google.common.truth.Truth.assertThat import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Test import java.lang.IllegalStateException import java.nio.file.Files +import kotlin.test.assertFailsWith class SymbolTableUtilTest { @@ -118,6 +120,30 @@ class SymbolTableUtilTest { } @Test + fun testParsingWithEmptyDependencies() { + val localFile = Files.createTempFile("local", "R.txt") + Files.write( + localFile, + """ + // This is a comment expected in package-aware R.txt + local + string first + """.trimIndent().toByteArray()) + val result = + parseRTxtFiles(localFile.toFile(), null, null) + + assertEquals(result.symbolTables!!.size, 1) + assertEquals(result.symbolTables!![0].rPackage, "") + + assertEquals(result.getRPackagePrefix(null, "string", "first"), "") + val failure = assertFailsWith<Exception> { + result.getRPackagePrefix(null, "string", "second") + } + assertThat(failure).hasMessageThat().contains("not found") + assertEquals(result.getRPackagePrefix("android", "string", "not_found"), "android.") + } + + @Test fun testParsingMergedDependencies() { val mergedR = Files.createTempFile("merged", "R.txt") Files.write( |