use of com.twosigma.beakerx.kernel.PlainCode in project beakerx by twosigma.
the class CodeFactory method createFrameForPlainCode.
private static CodeFrame createFrameForPlainCode(String line, Scanner scanner) {
List<String> result = new ArrayList<>();
result.add(line);
Pattern p = Pattern.compile("\\s*%.*");
while (scanner.hasNext() && !scanner.hasNext(p)) {
String str = scanner.nextLine().trim();
result.add(str);
}
return new PlainCode(String.join(System.lineSeparator(), result));
}
use of com.twosigma.beakerx.kernel.PlainCode in project beakerx by twosigma.
the class MagicCommandResultOrderTest method codeResultShouldBeLast.
@Test
public void codeResultShouldBeLast() {
// given
String allCode = "" + "%classpath add jar " + DOC_CONTENTS_DEMO_RESOURCES_BEAKERX_TEST_LIBRARY_JAR + "\n" + "%classpath\n" + "code code code";
// when
Code code = CodeFactory.create(allCode, new Message(), kernel);
code.execute(kernel, 1);
// then
PlainCode actual = (PlainCode) code.getCodeFrames().get(2);
assertThat(actual.getPlainCode()).isEqualTo("code code code");
}
use of com.twosigma.beakerx.kernel.PlainCode in project beakerx by twosigma.
the class ClasspathMagicCommandTest method handleClasspathAddJarMagicCommand.
@Test
public void handleClasspathAddJarMagicCommand() {
// given
String allCode = "" + CLASSPATH_ADD_JAR + " " + CLASSPATH_TO_JAR_PATH + "\n" + "code code code";
Code code = CodeFactory.create(allCode, new Message(), kernel);
// when
code.execute(kernel, 1);
// then
PlainCode actual = (PlainCode) code.getCodeFrames().get(1);
Assertions.assertThat(actual.getPlainCode()).isEqualTo("code code code");
assertThat(kernel.getClasspath().get(0)).contains(FOO_JAR);
}
use of com.twosigma.beakerx.kernel.PlainCode in project beakerx by twosigma.
the class ImportMagicCommandTest method addImport.
@Test
public void addImport() {
// given
String allCode = "%import com.twosigma.beakerx.widget.IntSlider\n" + "w = new IntSlider()";
Code code = CodeFactory.create(allCode, new Message(), kernel);
// when
code.execute(kernel, 1);
// then
PlainCode actual = (PlainCode) code.getCodeFrames().get(1);
assertThat(actual.getPlainCode()).isEqualTo("w = new IntSlider()");
assertThat(kernel.getImports().getImportPaths()).contains(new ImportPath("com.twosigma.beakerx.widget.IntSlider"));
}
Aggregations