-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit tests for KotlinxIo functions and extensions
- Loading branch information
Showing
1 changed file
with
74 additions
and
0 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
...de-build/roborazzi-core/src/jvmTest/kotlin/io/github/takahirom/roborazzi/KotlinxIoTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package io.github.takahirom.roborazzi | ||
|
||
import com.github.takahirom.roborazzi.KotlinxIo | ||
import com.github.takahirom.roborazzi.absolutePath | ||
import com.github.takahirom.roborazzi.nameWithoutExtension | ||
import com.github.takahirom.roborazzi.relativeTo | ||
import kotlinx.io.files.Path | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.TemporaryFolder | ||
|
||
class KotlinxIoTest { | ||
|
||
@get:Rule | ||
val tmpDir:TemporaryFolder = TemporaryFolder.builder().assureDeletion().build() | ||
|
||
@Test | ||
fun testAbsolutePath() { | ||
val path = Path("/Users/roborazzi/file.txt") | ||
assertEquals("/Users/roborazzi/file.txt", path.absolutePath) | ||
} | ||
|
||
@Test | ||
fun testNameWithoutExtension() { | ||
val path = Path("/Users/roborazzi/file.txt") | ||
assertEquals("file", path.nameWithoutExtension) | ||
} | ||
|
||
@Test | ||
fun testRelativeToSamePath() { | ||
val path = Path("/Users/roborazzi/file.txt") | ||
assertEquals(Path(""), path.relativeTo(path)) | ||
} | ||
|
||
@Test | ||
fun testRelativeToDifferentPath() { | ||
val base = Path("/Users/roborazzi") | ||
val path = Path("/Users/roborazzi/docs/file.txt") | ||
assertEquals(Path("docs/file.txt"), path.relativeTo(base)) | ||
} | ||
|
||
@Test | ||
fun testRelativeToDifferentBase() { | ||
val base = Path("/Users/roborazzi/docs") | ||
val path = Path("/Users/roborazzi/music/file.mp3") | ||
assertEquals(Path("../music/file.mp3"), path.relativeTo(base)) | ||
} | ||
|
||
@Test | ||
fun testReadText() { | ||
val testFile = tmpDir.newFile("kotlinx_io_write_test.txt") | ||
val expectedReadText = "Sample text for KotlinxIo" | ||
testFile.writeText(expectedReadText) | ||
|
||
val actualReadText = KotlinxIo.readText(Path(testFile.absolutePath)) | ||
|
||
assertEquals(expectedReadText, actualReadText) | ||
} | ||
|
||
@Test | ||
fun testWriteText() { | ||
val expectedWriteText = "Write a new text to the file" | ||
val file = tmpDir.newFile("kotlinx_io_write_test.txt") | ||
|
||
val path = Path(file.absolutePath) | ||
KotlinxIo.writeText(path, expectedWriteText) | ||
|
||
val actualReadText = KotlinxIo.readText(path) | ||
|
||
assertEquals(expectedWriteText, actualReadText) | ||
} | ||
|
||
} |