Skip to content

Commit

Permalink
Validate path to common test resources in IntelliJ (#349)
Browse files Browse the repository at this point in the history
Thanks to this, one can click in the IDE to go to the test resource:

<img width="1040" alt="Screenshot 2025-01-09 at 22 25 04"
src="https://github.com/user-attachments/assets/6eeef159-d48b-438b-9b9e-7953cb16b17d"
/>

and invalid paths are highlighted with red:

<img width="594" alt="Screenshot 2025-01-09 at 22 25 30"
src="https://github.com/user-attachments/assets/3abedb1d-de78-4b35-bdcf-3b09b4ebf16c"
/>

To achieve it, we need to have a leading slash, hence the changes in all
call sites of `stringFromResources` function.
  • Loading branch information
krzema12 authored Jan 22, 2025
1 parent 9d1e000 commit 2c11161
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ kotlin {
implementation("io.kotest:kotest-framework-engine:6.0.0.M1")
implementation("io.kotest:kotest-framework-api:6.0.0.M1")
implementation("io.kotest:kotest-assertions-core:6.0.0.M1")
implementation("org.jetbrains:annotations:26.0.2")
// Overridig coroutines' version to solve a problem with WASM JS tests.
// See https://kotlinlang.slack.com/archives/CDFP59223/p1736191408326039?thread_ts=1734964013.996149&cid=CDFP59223
// TODO: remove this workaround in https://github.com/krzema12/snakeyaml-engine-kmp/issues/337
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import okio.Path.Companion.toPath
import okio.Sink
import okio.Source
import okio.buffer
import org.intellij.lang.annotations.Language

/**
* Retrieves a string content from common resources using a given path.
Expand All @@ -20,7 +21,7 @@ import okio.buffer
* @return The content of the resource as a UTF-8 encoded string with normalized line breaks.
* @throws IllegalArgumentException if the resource doesn't exist.
*/
fun stringFromResources(path: String): String {
fun stringFromResources(@Language("file-reference") path: String): String {
require(path.startsWith("/")) { "A leading slash is required!" }
val path = path.drop(1).toPath()
return CommonTestResourcesFileSystem.source(path).buffer().readUtf8()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import it.krzeminski.snakeyaml.engine.kmp.api.lowlevel.Parse
import it.krzeminski.snakeyaml.engine.kmp.events.Event
import it.krzeminski.snakeyaml.engine.kmp.exceptions.ParserException
import it.krzeminski.snakeyaml.engine.kmp.stringFromResources
import org.intellij.lang.annotations.Language

class GlobalDirectivesTest : FunSpec({
fun yamlToEvents(resourceName: String): Iterable<Event> {
fun yamlToEvents(@Language("file-reference") resourceName: String): Iterable<Event> {
val input = stringFromResources(resourceName)
val parser = Parse(LoadSettings.builder().build())
return parser.parse(input)
Expand Down

0 comments on commit 2c11161

Please sign in to comment.