apatrida
01/04/2017, 6:12 PMfun makeConfigurableEngine(defaultImports: List<String> = emptyList()): ResettableRepl =
ResettableRepl(scriptDefinition = ConfigurableAnnotationBasedScriptDefinition(
"varargTemplateWithMavenResolving",
ScriptTemplateWithArgs::class,
ScriptArgsWithTypes(EMPTY_SCRIPT_ARGS, EMPTY_SCRIPT_ARGS_TYPES),
defaultImports = defaultImports))
@Test
fun testConfigurableResolversEmpty() {
makeConfigurableEngine().use { repl ->
repl.compileAndEval("""val x = 10 + 100""")
assertEquals(110, repl.compileAndEval("""x""").resultValue)
}
}
@Test
fun testConfigurableResolversFailsWithoutCorrectImport() {
makeConfigurableEngine().use { repl ->
try {
repl.compileAndEval("""val now = Instant.now()""")
fail("Expected compile error")
} catch (ex: ReplCompilerException) {
assertTrue("unresolved reference: Instant" in ex.message!!)
}
}
}
@Test
fun testConfigurableResolversWithDefaultImports() {
makeConfigurableEngine(defaultImports = listOf("java.time.*")).use { repl ->
val now = Instant.now()
repl.compileAndEval("""val now = Instant.now()""")
val result = repl.compileAndEval("""now""").resultValue as Instant
assertTrue(result >= now)
}
}