Hopefully fix paths on Windoze?
All checks were successful
PRs & Pushes / test (push) Successful in 3m8s
PRs & Pushes / build (push) Successful in 3m12s
PRs & Pushes / build-apidoc (push) Successful in 3m37s

This commit is contained in:
JeremyStar™ 2024-12-17 15:57:11 +01:00
parent 5e1dd3fc35
commit bec621e410
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -35,6 +35,40 @@ import kotlin.test.assertTrue
@Suppress("LargeClass")
class FileAccessTest : TestBase() {
// -----> Utility methods
// These help in tests
/**
* Transforms file paths returned by
* [FileAccess.toString] for proper comparison.
*
* This method takes platform-specific restrictions and
* quirks into consideration to transform the supplied
* path. It also applies various formatting rules used
* extensively in the tests provided by this class.
*
* @param path path string to transform
* @return transformed path string
* @throws NullPointerException if [FileAccess.temporaryCacheDirectory] is `null`
* @since v1-alpha10
*/
@Throws(NullPointerException::class)
private fun transformToStringPath(path: String): String {
var string: String = path
// Replace formatting rules of this test class
string = string
.replace("+", FileAccess.temporaryCacheDirectory!!.toString())
.replace("%", File.separator)
// Apply operating system-specific updates
when (Environment.operatingSystem) {
Environment.OperatingSystem.WINDOWS -> string = "C:${string}"
else -> {}
}
return string
}
// -----> Tests on non-existent files
// These tests are executed on paths which likely do not exist
@ParameterizedTest
@ -49,8 +83,7 @@ class FileAccessTest : TestBase() {
)
fun toStringTest(supplyValue: String, compareValue: String) {
assertEquals(
compareValue
.replace("+", FileAccess.temporaryCacheDirectory!!.toString()),
transformToStringPath(compareValue),
FileAccess
.temporaryCacheDirectory!!
.traverse(supplyValue)
@ -70,9 +103,7 @@ class FileAccessTest : TestBase() {
)
fun toStringRaw(supplyValue: String, compareValue: String) {
assertEquals(
compareValue
.replace("+", FileAccess.temporaryCacheDirectory!!.toString())
.replace("%", File.separator),
transformToStringPath(compareValue),
FileAccess
.temporaryCacheDirectory!!
.traverse(supplyValue)
@ -92,7 +123,7 @@ class FileAccessTest : TestBase() {
)
fun getBaseName(supplyValue: String, compareValue: String) {
assertEquals(
compareValue,
transformToStringPath(compareValue),
FileAccess
.temporaryCacheDirectory!!
.traverse(supplyValue)
@ -112,8 +143,7 @@ class FileAccessTest : TestBase() {
)
fun parent(supplyValue: String, compareValue: String) {
assertEquals(
compareValue
.replace("+", FileAccess.temporaryCacheDirectory!!.toString()),
transformToStringPath(compareValue),
FileAccess
.temporaryCacheDirectory!!
.traverse(supplyValue)
@ -403,9 +433,7 @@ class FileAccessTest : TestBase() {
)
fun getLinkDestinationReal(supplyValue: String, compareValue: String) {
assertEquals(
compareValue
.replace("+", FileAccess.temporaryCacheDirectory!!.toString())
.replace("%", File.separator),
transformToStringPath(compareValue),
FileAccess
.temporaryCacheDirectory!!
.traverse("getLinkDestinationSymlinkReal.link.txt")
@ -434,9 +462,7 @@ class FileAccessTest : TestBase() {
)
fun getLinkDestinationFake(supplyValue: String, compareValue: String) {
assertEquals(
compareValue
.replace("+", FileAccess.temporaryCacheDirectory!!.toString())
.replace("%", File.separator),
transformToStringPath(compareValue),
FileAccess
.temporaryCacheDirectory!!
.traverse("getLinkDestinationSymlinkFake.link.txt")