Skip to content

Commit

Permalink
Fix handling of null cmd mode function results
Browse files Browse the repository at this point in the history
v1.11.3
  • Loading branch information
dhleong committed Mar 3, 2019
1 parent aba0d78 commit 40755ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ ext.deps = [

ext.config = [
name: 'Judo',
version: '1.11.2',
version: '1.11.3',
]
15 changes: 11 additions & 4 deletions core/src/main/kotlin/net/dhleong/judo/script/functional.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,22 @@ private abstract class FnBase(
)
}

protected inline fun <R> safely(block: () -> R): R =
try {
@Suppress("UNCHECKED_CAST")
engine.toJava(block() as Any) as R
protected inline fun <R> safely(block: () -> R): R {
val result = try {
block()
} catch (e: ClassCastException) {
throw IllegalArgumentException(
"Incorrect arguments to $name()", e
)
}

if (result == null) {
return result
}

@Suppress("UNCHECKED_CAST")
return engine.toJava(result as Any) as R
}
}

@FunctionalInterface
Expand Down
5 changes: 5 additions & 0 deletions core/src/test/kotlin/net/dhleong/judo/JudoCoreTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ class JudoCoreTest {
))
assert(judo.buffer.toString()).isNotEmpty()
}

@Test fun `esc cancels input() and returns null`() = assertionsWhileTyping(judo) {
yieldKeys(":print(input('test: '))<cr>hi<esc>")
assert(renderer.outputLines).isEqualTo(listOf("None"))
}
}

private fun JudoCore.appendOutput(buffer: String) =
Expand Down

0 comments on commit 40755ee

Please sign in to comment.