module lang::rascal::tutor::repl::TutorCommandExecutor
rascal-0.40.13-BOOT2
rascal-tutor-0.19.9
Usage
import lang::rascal::tutor::repl::TutorCommandExecutor;
Dependencies
import util::Reflective;
data CommandExecutor
A closure-based object wrapper for Rascal REPL
data CommandExecutor
= executor(
PathConfig pcfg,
str () prompt,
void () reset,
map[str mimeType, str content] (str command) eval
)
;
Using an instance of CommandExecutor you can simulate the exact interactions between a Rascal REPL user and the REPL.
This was created to implement documentation pages with example REPL runs.
function createExecutor
Instantiates a ((CommandExecutor)) to simulate a REPL
CommandExecutor createExecutor(PathConfig pcfg)
Examples
It's funny that the current example is also executed by a CommandExecutor of the tutor compiler. Here we use to show how it works:
import lang::rascal::tutor::repl::TutorCommandExecutor;
import util::Reflective;
e = createExecutor(pathConfig());
// now we can find the current prompt:
e.prompt();
// and evaluate an assignment
e.eval("x = 1;");
// look what a continuation prompt looks like:
e.eval("println(\"abc\"")
e.prompt()
// finish the command we started
e.eval(")")
# Tests
## test executorSmokeTest {#lang-rascal-tutor-repl-TutorCommandExecutor-executorSmokeTest}
```rascal
test bool executorSmokeTest() {
exec = createExecutor(pathConfig());
if (exec.prompt() != "rascal\>") {
return false;
}
output = exec.eval("import IO;");
if (output["text/plain"] != "ok\n") {
return false;
}
exec.eval("println(\"haai\"");
if (exec.prompt() != "\>\>\>\>\>\>\>") {
return false;
}
output = exec.eval(")");
if (output["application/rascal+stdout"] != "haai\n") {
return false;
}
return true;
}