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.compiler.source.repository.CompositeModuleSourceRepository;
8 import org.simantics.scl.compiler.source.repository.SourceRepositories;
9 import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler;
10 import org.simantics.scl.runtime.reporting.SCLReportingHandler;
12 public class TestCommandSession {
14 ModuleRepository moduleRepository;
17 public void initialize() throws Exception {
18 moduleRepository = new ModuleRepository(
19 new CompositeModuleSourceRepository(
20 SourceRepositories.BUILTIN_SOURCE_REPOSITORY,
21 SourceRepositories.PRELUDE_SOURCE_REPOSITORY
25 private static class SCLErrorMessageException extends RuntimeException {
26 private static final long serialVersionUID = 418954639267697065L;
27 public SCLErrorMessageException(String message) {
32 private static final SCLReportingHandler TEST_HANDLER = new AbstractSCLReportingHandler() {
34 public void print(String text) {
35 System.out.println(text);
38 public void printError(String error) {
39 System.err.println(error);
40 throw new SCLErrorMessageException(error);
45 public void testCommandSession() {
46 CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
48 session.execute("a = 1");
49 session.execute("b = 2");
50 session.execute("a + b");
52 session.execute("x = 1\ny = 2");
53 session.execute("x + y");
57 public void testCommandSession2() {
58 CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
60 session.execute("f name coords = print \"\\(name :: String) \\(coords :: (Double, Double))\"");
61 session.execute("g name (x,y) = f name (x,y)");
65 public void testTyping1() {
66 CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
68 session.execute("apply f = f ()");
69 session.execute("printHello () = print \"Hello\"");
70 session.execute("apply printHello");
74 public void testTyping2() {
75 CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
77 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) }");
78 session.execute("iter (\\i -> print i) [1,2,3]");
79 session.execute("iter (\\i -> print i) [(),(),()]");