1 package org.simantics.scl.compiler.tests;
3 import org.junit.Before;
5 import org.simantics.scl.compiler.commands.CommandSession;
6 import org.simantics.scl.compiler.module.repository.ModuleRepository;
7 import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler;
8 import org.simantics.scl.runtime.reporting.SCLReportingHandler;
10 public class TestCommandSession {
12 ModuleRepository moduleRepository;
15 public void initialize() throws Exception {
16 moduleRepository = InitialRepository.getInitialRepository();
19 private static class SCLErrorMessageException extends RuntimeException {
20 private static final long serialVersionUID = 418954639267697065L;
21 public SCLErrorMessageException(String message) {
26 private static final SCLReportingHandler TEST_HANDLER = new AbstractSCLReportingHandler() {
28 public void print(String text) {
29 System.out.println(text);
32 public void printError(String error) {
33 System.err.println(error);
34 throw new SCLErrorMessageException(error);
39 public void testCommandSession() {
40 CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
42 session.execute("a = 1");
43 session.execute("b = 2");
44 session.execute("a + b");
46 session.execute("x = 1\ny = 2");
47 session.execute("x + y");
51 public void testCommandSession2() {
52 CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
54 session.execute("f name coords = print \"\\(name :: String) \\(coords :: (Double, Double))\"");
55 session.execute("g name (x,y) = f name (x,y)");
59 public void testTyping1() {
60 CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
62 session.execute("apply f = f ()");
63 session.execute("printHello () = print \"Hello\"");
64 session.execute("apply printHello");
68 public void testTyping2() {
69 CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
71 session.execute("iter f (list :: [a]) = loop 0 where { len = length list ; loop i | i == len = 0 | otherwise = do f (list!i) ; loop (i+1) }");
72 session.execute("iter (\\i -> print i) [1,2,3]");
73 session.execute("iter (\\i -> print i) [(),(),()]");