InterpreterResult implements Serializable, JsonSerializable { public List<InterpreterResultMessage> message() { return msg; } InterpreterResult(Code code);  InterpreterResult(Code code, List<InterpreterResultMessage> msgs);  InterpreterResult(Code code, String msg);  InterpreterResult(Code code, Type type, String msg); void add(String msg); void add(Type type, String data); void add(InterpreterResultMessage interpreterResultMessage); Code code(); List<InterpreterResultMessage> message(); String toJson(); static InterpreterResult fromJson(String json); String toString();  }
@Test public void testTextType() { InterpreterResult result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "this is a TEXT type"); assertEquals("No magic", InterpreterResult.Type.TEXT, result.message().get(0).getType()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%this is a TEXT type"); assertEquals("No magic", InterpreterResult.Type.TEXT, result.message().get(0).getType()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%\n"); assertEquals(0, result.message().size()); }
@Test public void testSimpleMagicType() { InterpreterResult result = null; result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%table col1\tcol2\naaa\t123\n"); assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%table\ncol1\tcol2\naaa\t123\n"); assertEquals(InterpreterResult.Type.TABLE, result.message().get(0).getType()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "some text before magic word\n%table col1\tcol2\naaa\t123\n"); assertEquals(InterpreterResult.Type.TABLE, result.message().get(1).getType()); }
@Test public void testComplexMagicType() { InterpreterResult result = null; result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "some text before %table col1\tcol2\naaa\t123\n"); assertEquals("some text before magic return magic", InterpreterResult.Type.TEXT, result.message().get(0).getType()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "some text before\n%table col1\tcol2\naaa\t123\n"); assertEquals("some text before magic return magic", InterpreterResult.Type.TEXT, result.message().get(0).getType()); assertEquals("some text before magic return magic", InterpreterResult.Type.TABLE, result.message().get(1).getType()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%html <h3> This is a hack </h3> %table\n col1\tcol2\naaa\t123\n"); assertEquals("magic A before magic B return magic A", InterpreterResult.Type.HTML, result.message().get(0).getType()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "some text before magic word %table col1\tcol2\naaa\t123\n %html " + "<h3> This is a hack </h3>"); assertEquals("text & magic A before magic B return magic A", InterpreterResult.Type.TEXT, result.message().get(0).getType()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%table col1\tcol2\naaa\t123\n %html <h3> This is a hack </h3> %table col1\naaa\n123\n"); assertEquals("magic A, magic B, magic a' return magic A", InterpreterResult.Type.TABLE, result.message().get(0).getType()); }
@Test public void testSimpleMagicData() { InterpreterResult result = null; result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%table col1\tcol2\naaa\t123\n"); assertEquals("%table col1\tcol2\naaa\t123\n", "col1\tcol2\naaa\t123\n", result.message().get(0).getData()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "%table\ncol1\tcol2\naaa\t123\n"); assertEquals("%table\ncol1\tcol2\naaa\t123\n", "col1\tcol2\naaa\t123\n", result.message().get(0).getData()); result = new InterpreterResult(InterpreterResult.Code.SUCCESS, "some text before magic word\n%table col1\tcol2\naaa\t123\n"); assertEquals("some text before magic word\n%table col1\tcol2\naaa\t123\n", "col1\tcol2\naaa\t123\n", result.message().get(1).getData()); }