-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b81b16f
commit c80904a
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
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,25 @@ | ||
package introprog | ||
|
||
val tmpDir = "target/tmp" | ||
|
||
class TestIO extends munit.FunSuite { | ||
test("TestIO: createDirIfNotExist, saveString, appendString, loadLines, appendLines") { | ||
val existed = IO.createDirIfNotExist(tmpDir) | ||
assert(IO.isExisting(tmpDir), s"dir should exists: $tmpDir") | ||
val s1 = "hello" | ||
val fn = s"$tmpDir/hello.txt" | ||
IO.saveString(s1, fileName = fn) | ||
val s2 = IO.loadString(fileName = fn) | ||
assertEquals(s1, s2, "saved string different from loaded") | ||
IO.appendString("!\n", fileName = fn ) | ||
val s3 = IO.loadString(fileName = fn) | ||
assertEquals(s3, s2 + "!\n", "saved string is missing appended '!+newline'") | ||
IO.appendLines(Seq("line2"),fileName = fn) | ||
val s4 = IO.loadLines(fileName = fn) | ||
assertEquals(s4, Vector("hello!", "line2"), s"loadLines not as expected: $s4") | ||
val s5 = IO.loadString(fileName = fn) | ||
assertEquals(s5, "hello!\nline2\n", s"loadLines not as expected: $s5") | ||
IO.appendLines(Seq(),fileName = fn) // nothing should be added, not even newline | ||
assertEquals(s5, IO.loadString(fileName = fn), s"loadLines not as expected: $s5") | ||
} | ||
} |