Skip to content

fix(tests): update file URI normalization for Windows compatibility #5959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -365,12 +365,16 @@ class TextDocumentServiceHandlerTest {
return uri
}

if (uri.startsWith("file://C:/")) {
val path = uri.substringAfter("file://C:/")
return "file:///C:/$path"
if (uri.startsWith("file://$windowsDrive:/")) {
val path = uri.substringAfter("file://$windowsDrive:/")
return "file:///$windowsDrive:/$path"
}

val path = uri.substringAfter("file:///")
return "file:///C:/$path"
return "file:///$windowsDrive:/$path"
}

private val windowsDrive: String
get() = java.nio.file.Paths.get("").toAbsolutePath().root
?.toString()?.firstOrNull()?.uppercaseChar()?.toString() ?: "C"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ class FileUriUtilTest {
every { isDirectory } returns mockIsDirectory
}

private val windowsDrive: String
get() = java.nio.file.Paths.get("").toAbsolutePath().root
?.toString()?.firstOrNull()?.uppercaseChar()?.toString() ?: "C"

private fun normalizeFileUri(uri: String): String {
if (!System.getProperty("os.name").lowercase().contains("windows")) {
return uri
Expand All @@ -32,7 +36,7 @@ class FileUriUtilTest {
}

val path = uri.substringAfter("file:///")
return "file:///C:/$path"
return "file:///$windowsDrive:/$path"
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class WorkspaceFolderUtilTest {
}

// for windows unit tests
private val windowsDrive: String
get() = java.nio.file.Paths.get("").toAbsolutePath().root
?.toString()?.firstOrNull()?.uppercaseChar()?.toString() ?: "C"

private fun normalizeFileUri(uri: String): String {
if (!System.getProperty("os.name").lowercase().contains("windows")) {
return uri
Expand All @@ -105,6 +109,6 @@ class WorkspaceFolderUtilTest {
return uri
}
val path = uri.substringAfter("file:///")
return "file:///C:/$path"
return "file:///$windowsDrive:/$path"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,10 @@ class WorkspaceServiceHandlerTest {
}

// for windows unit tests
private val windowsDrive: String
get() = java.nio.file.Paths.get("").toAbsolutePath().root
?.toString()?.firstOrNull()?.uppercaseChar()?.toString() ?: "C"

private fun normalizeFileUri(uri: String): String {
if (!System.getProperty("os.name").lowercase().contains("windows")) {
return uri
Expand All @@ -829,6 +833,6 @@ class WorkspaceServiceHandlerTest {
}

val path = uri.substringAfter("file:///")
return "file:///C:/$path"
return "file:///$windowsDrive:/$path"
}
}