Search in sources :

Example 1 with PlainCode

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));
}
Also used : Pattern(java.util.regex.Pattern) ArrayList(java.util.ArrayList) PlainCode(com.twosigma.beakerx.kernel.PlainCode)

Example 2 with PlainCode

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");
}
Also used : Message(com.twosigma.beakerx.message.Message) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Code(com.twosigma.beakerx.kernel.Code) PlainCode(com.twosigma.beakerx.kernel.PlainCode) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 3 with PlainCode

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);
}
Also used : Message(com.twosigma.beakerx.message.Message) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Code(com.twosigma.beakerx.kernel.Code) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest)

Example 4 with PlainCode

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"));
}
Also used : Message(com.twosigma.beakerx.message.Message) ImportPath(com.twosigma.beakerx.kernel.ImportPath) PlainCode(com.twosigma.beakerx.kernel.PlainCode) Code(com.twosigma.beakerx.kernel.Code) PlainCode(com.twosigma.beakerx.kernel.PlainCode) EvaluatorTest(com.twosigma.beakerx.evaluator.EvaluatorTest) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Aggregations

PlainCode (com.twosigma.beakerx.kernel.PlainCode)4 KernelTest (com.twosigma.beakerx.KernelTest)3 EvaluatorTest (com.twosigma.beakerx.evaluator.EvaluatorTest)3 Code (com.twosigma.beakerx.kernel.Code)3 Message (com.twosigma.beakerx.message.Message)3 Test (org.junit.Test)3 ImportPath (com.twosigma.beakerx.kernel.ImportPath)1 ArrayList (java.util.ArrayList)1 Pattern (java.util.regex.Pattern)1