Skip to content

Commit

Permalink
Rename expect/actual files to intellij convention
Browse files Browse the repository at this point in the history
  • Loading branch information
ajalt committed May 11, 2024
1 parent 6f11d25 commit 76d98a4
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ internal expect fun exitProcessMpp(status: Int)
internal expect fun readFileIfExists(filename: String): String?

internal expect fun runningInBrowser(): Boolean

internal expect fun cwd() : String
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.ajalt.mordant.platform

import com.github.ajalt.mordant.internal.cwd
import com.github.ajalt.mordant.internal.runningInBrowser
import io.kotest.matchers.nulls.shouldNotBeNull
import io.kotest.matchers.shouldBe
Expand All @@ -25,7 +26,7 @@ class MultiplatformSystemTest {
) ?: MultiplatformSystem.readFileAsUtf8(
// js targets have a cwd of $projectDir/build/js/packages/mordant-mordant-test
"../../../../mordant/src/commonTest/resources/multiplatform_system_test.txt"
)
) ?: cwd()
if (runningInBrowser()) return // No files in browsers
actual shouldBe "pass\n"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@ private class NodeTerminalCursor(terminal: Terminal) : PrintTerminalCursor(termi
}

internal actual val CR_IMPLIES_LF: Boolean = false
internal actual fun cwd(): String {
return process.cwd() as String
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,6 @@ internal actual fun readFileIfExists(filename: String): String? {
return file.bufferedReader().use { it.readText() }
}

internal actual fun cwd(): String {
return System.getProperty("user.dir")
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ internal actual fun ttySetEcho(echo: Boolean) = memScoped {
}
SetConsoleMode(stdinHandle, newMode)
}

internal actual fun cwd(): String = memScoped {
val buf = allocArray<ByteVar>(4096)
GetCurrentDirectoryA(4096U, buf)
return buf.toKString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.github.ajalt.mordant.internal

import kotlinx.cinterop.*
import platform.posix.getcwd
import platform.posix.size_t

@OptIn(ExperimentalForeignApi::class)
internal actual fun cwd(): String = memScoped{
val buf = allocArray<ByteVar>(4096)
return getcwd(buf, 4096UL)?.toKString() ?: "??"
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ private external object process {
fun on(event: String, listener: () -> Unit)
fun removeListener(event: String, listener: () -> Unit)
fun exit(status: Int)
fun cwd() : String
}

private external interface FsModule {
Expand Down Expand Up @@ -135,3 +136,6 @@ private fun importNodeFsModule(): FsModule =

// For some reason, \r seems to be treated as \r\n on wasm
internal actual val CR_IMPLIES_LF: Boolean = true
internal actual fun cwd(): String {
return process.cwd()
}

0 comments on commit 76d98a4

Please sign in to comment.