Skip to content

Commit 9447b40

Browse files
committed
fix(tests): update file URI normalization for Windows compatibility
1 parent a8dadbb commit 9447b40

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/textdocument/TextDocumentServiceHandlerTest.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,16 @@ class TextDocumentServiceHandlerTest {
365365
return uri
366366
}
367367

368-
if (uri.startsWith("file://C:/")) {
369-
val path = uri.substringAfter("file://C:/")
370-
return "file:///C:/$path"
368+
if (uri.startsWith("file://$windowsDrive:/")) {
369+
val path = uri.substringAfter("file://$windowsDrive:/")
370+
return "file:///$windowsDrive:/$path"
371371
}
372372

373373
val path = uri.substringAfter("file:///")
374-
return "file:///C:/$path"
374+
return "file:///$windowsDrive:/$path"
375375
}
376+
377+
private val windowsDrive: String
378+
get() = java.nio.file.Paths.get("").toAbsolutePath().root
379+
?.toString()?.firstOrNull()?.uppercaseChar()?.toString() ?: "C"
376380
}

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/util/FileUriUtilTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ class FileUriUtilTest {
2222
every { isDirectory } returns mockIsDirectory
2323
}
2424

25+
private val windowsDrive: String
26+
get() = java.nio.file.Paths.get("").toAbsolutePath().root
27+
?.toString()?.firstOrNull()?.uppercaseChar()?.toString() ?: "C"
28+
2529
private fun normalizeFileUri(uri: String): String {
2630
if (!System.getProperty("os.name").lowercase().contains("windows")) {
2731
return uri
@@ -32,7 +36,7 @@ class FileUriUtilTest {
3236
}
3337

3438
val path = uri.substringAfter("file:///")
35-
return "file:///C:/$path"
39+
return "file:///$windowsDrive:/$path"
3640
}
3741

3842
@Test

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/util/WorkspaceFolderUtilTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ class WorkspaceFolderUtilTest {
9797
}
9898

9999
// for windows unit tests
100+
private val windowsDrive: String
101+
get() = java.nio.file.Paths.get("").toAbsolutePath().root
102+
?.toString()?.firstOrNull()?.uppercaseChar()?.toString() ?: "C"
103+
100104
private fun normalizeFileUri(uri: String): String {
101105
if (!System.getProperty("os.name").lowercase().contains("windows")) {
102106
return uri
@@ -105,6 +109,6 @@ class WorkspaceFolderUtilTest {
105109
return uri
106110
}
107111
val path = uri.substringAfter("file:///")
108-
return "file:///C:/$path"
112+
return "file:///$windowsDrive:/$path"
109113
}
110114
}

plugins/amazonq/shared/jetbrains-community/tst/software/aws/toolkits/jetbrains/services/amazonq/lsp/workspace/WorkspaceServiceHandlerTest.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,10 @@ class WorkspaceServiceHandlerTest {
819819
}
820820

821821
// for windows unit tests
822+
private val windowsDrive: String
823+
get() = java.nio.file.Paths.get("").toAbsolutePath().root
824+
?.toString()?.firstOrNull()?.uppercaseChar()?.toString() ?: "C"
825+
822826
private fun normalizeFileUri(uri: String): String {
823827
if (!System.getProperty("os.name").lowercase().contains("windows")) {
824828
return uri
@@ -829,6 +833,6 @@ class WorkspaceServiceHandlerTest {
829833
}
830834

831835
val path = uri.substringAfter("file:///")
832-
return "file:///C:/$path"
836+
return "file:///$windowsDrive:/$path"
833837
}
834838
}

0 commit comments

Comments
 (0)