From dd920dffaa4713481e96db05c54756191c9612ad Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Tue, 17 Dec 2024 16:16:04 +0100 Subject: [PATCH] Fix FileAccess test issues, now works everywhere --- .../engine/base/utility/FileAccessTest.kt | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/base/src/test/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt b/base/src/test/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt index 351af19..ec56b66 100644 --- a/base/src/test/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt +++ b/base/src/test/kotlin/de/staropensource/engine/base/utility/FileAccessTest.kt @@ -47,12 +47,13 @@ class FileAccessTest : TestBase() { * extensively in the tests provided by this class. * * @param path path string to transform + * @param raw if to instead target [FileAccess.toStringRaw] * @return transformed path string * @throws NullPointerException if [FileAccess.temporaryCacheDirectory] is `null` * @since v1-alpha10 */ @Throws(NullPointerException::class) - private fun transformToStringPath(path: String): String { + private fun transformToStringPath(path: String, raw: Boolean = false): String { var string: String = path // Replace formatting rules of this test class @@ -62,10 +63,19 @@ class FileAccessTest : TestBase() { // Apply operating system-specific updates when (Environment.operatingSystem) { - Environment.OperatingSystem.WINDOWS -> string = "C:${string}" + Environment.OperatingSystem.WINDOWS -> { + if (string.startsWith(File.separator) || string.startsWith("/")) + string = "C:${string}" + } else -> {} } + // Replace all slashes with File.separator or vice versa + string = if (raw) + string.replace("/", File.separator) + else + string.replace(File.separator, "/") + return string } @@ -78,7 +88,7 @@ class FileAccessTest : TestBase() { textBlock = """ "/some/test/file", "/some/test/file" "\very\nice\test\file.txt", "/very/nice/test/file.txt" - "/./did/somebody\\/say\\yoga?", "/did/somebody/say/yoga?" + "/./did/somebody\\/say\\yoga" , "/did/somebody/say/yoga" "test.txt", "+/test.txt"""" ) fun toStringTest(supplyValue: String, compareValue: String) { @@ -98,12 +108,12 @@ class FileAccessTest : TestBase() { textBlock = """ "/some/test/file", "%some%test%file" "\very\nice\test\file.txt", "%very%nice%test%file.txt" - "/./did/somebody\////say\\\yoga?", "%did%somebody%say%yoga?" + "/./did/somebody\////say\\\yoga", "%did%somebody%say%yoga" "test.txt", "+%test.txt"""" ) fun toStringRaw(supplyValue: String, compareValue: String) { assertEquals( - transformToStringPath(compareValue), + transformToStringPath(compareValue, raw = true), FileAccess .temporaryCacheDirectory!! .traverse(supplyValue) @@ -118,7 +128,7 @@ class FileAccessTest : TestBase() { textBlock = """ "/some/test/file", "file" "\very\nice\test\file.txt", "file.txt" - "/./did/somebody\\/say\\yoga?", "yoga?" + "/./did/somebody\\/say\\yoga", "yoga" "test.txt", "test.txt"""" ) fun getBaseName(supplyValue: String, compareValue: String) { @@ -137,10 +147,11 @@ class FileAccessTest : TestBase() { textBlock = """ "/some/test/file", "/some/test" "\very\nice\test\file.txt", "/very/nice/test" - "/./did/somebody\\/say\\yoga?", "/did/somebody/say" + "/./did/somebody\\/say\\yoga", "/did/somebody/say" "test.txt", "+" "configs/default.conf", "+/configs"""" ) + // TODO error / fun parent(supplyValue: String, compareValue: String) { assertEquals( transformToStringPath(compareValue),