mirror of
https://github.com/Anvilcraft/modpacktools
synced 2024-11-17 23:41:55 +01:00
improve tests
This commit is contained in:
parent
40681a10ca
commit
0c13479ddc
2 changed files with 18 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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)}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue