4
0
Fork 0
mirror of https://github.com/Anvilcraft/modpacktools synced 2024-06-10 22:49:26 +02:00

improve tests

This commit is contained in:
LordMZTE 2020-08-06 12:44:10 +02:00
parent 40681a10ca
commit 0c13479ddc
2 changed files with 18 additions and 8 deletions

View file

@ -19,9 +19,8 @@ fun fPrint(x: Any?, vararg formatters: (String) -> String) = System.out.fPrint(x
* @param x the object to print
* @param formatters the formatters to apply to x, they will be ran in the order they are supplied in
*/
fun PrintStream.fPrint(x: Any?, vararg formatters: (String) -> String) = this.print(
formatters.fold(x.toString()) {acc, f -> f(acc)}
)
fun PrintStream.fPrint(x: Any?, vararg formatters: (String) -> String) =
this.print(formatters.fold(x.toString()) {acc, f -> f(acc)})
/**
* applies all given formatters to the string representation of the object and then prints it with a newline at the end

View file

@ -6,13 +6,24 @@ import java.io.ByteArrayOutputStream
import java.io.PrintStream
class CLIUtilTest {
fun prntStr(f: PrintStream.() -> Unit): String =
ByteArrayOutputStream().apply {
PrintStream(this, true, "UTF-8").use(f)
}.use {it.toString("UTF-8")}
@Test
fun testFPrintln() {
val baos = ByteArrayOutputStream()
PrintStream(baos, true, "UTF-8").use {
it.fPrintln("Test String", {s -> "$s Formatted"})
}
assertEquals(
"Test String Formatted\n",
prntStr {this.fPrintln("Test String", {"$it Formatted"})}
)
}
assertEquals("Test String Formatted\n", baos.toString("UTF-8"))
@Test
fun testFPrintlnNull() {
assertEquals(
"null\n",
prntStr {this.fPrintln(null)}
)
}
}