Fixes test file loader for iOS

This commit is contained in:
Vitor Pamplona
2026-02-18 12:34:55 -05:00
parent ee7d20e939
commit 086e2046db
2 changed files with 27 additions and 14 deletions
@@ -56,18 +56,20 @@ class HintIndexerTest {
)
}
val relays =
TestResourceLoader()
.loadString("relayDB.txt")
.split('\n')
.mapNotNull {
val relay = RelayUrlNormalizer.normalizeOrNull(it)
if (relay == null || relay.isLocalHost()) {
null
} else {
relay
val relays by
lazy {
TestResourceLoader()
.loadString("relayDB.txt")
.split('\n')
.mapNotNull {
val relay = RelayUrlNormalizer.normalizeOrNull(it)
if (relay == null || relay.isLocalHost()) {
null
} else {
relay
}
}
}
}
val indexer by lazy {
val result = HintIndexer()
@@ -32,11 +32,22 @@ import platform.darwin.NSObjectMeta
actual class TestResourceLoader {
@OptIn(ExperimentalForeignApi::class, BetaInteropApi::class)
actual fun loadString(file: String): String {
val bundle = NSBundle.Companion.bundleForClass(BundleMarker)
// Split the filename and extension (e.g., "data.json" -> "data", "json")
val basename = file.substringBeforeLast(".")
val extension = file.substringAfterLast(".", "")
// Locate the file in the main application bundle
val path =
bundle.pathForResource(file, ofType = null)
NSBundle.mainBundle.pathForResource(basename, ofType = extension)
?: throw IllegalArgumentException("Resource not found: $file")
return NSString.Companion.stringWithContentsOfFile(path, encoding = NSUTF8StringEncoding, error = null)!!
// Read the file content as a UTF-8 string
return NSString
.stringWithContentsOfFile(
path = path,
encoding = NSUTF8StringEncoding,
error = null,
).toString()
}
private class BundleMarker : NSObject() {