]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/TestCommandSession.java
Merge "Remove unused import in DeleteHandler"
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / TestCommandSession.java
1 package org.simantics.scl.compiler.tests;
2
3 import org.junit.Before;
4 import org.junit.Test;
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;
9
10 public class TestCommandSession {
11
12     ModuleRepository moduleRepository;
13
14     @Before
15     public void initialize() throws Exception {
16         moduleRepository = InitialRepository.getInitialRepository();
17     }
18     
19     private static class SCLErrorMessageException extends RuntimeException {
20         private static final long serialVersionUID = 418954639267697065L;
21         public SCLErrorMessageException(String message) {
22             super(message);
23         }
24     }
25     
26     private static final SCLReportingHandler TEST_HANDLER = new AbstractSCLReportingHandler() {
27         @Override
28         public void print(String text) {
29             System.out.println(text);
30         }
31         
32         public void printError(String error) {
33             System.err.println(error);
34             throw new SCLErrorMessageException(error);
35         }
36     };
37
38     @Test
39     public void testCommandSession() {
40         CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
41         
42         session.execute("a = 1");
43         session.execute("b = 2");
44         session.execute("a + b");
45         
46         session.execute("x = 1\ny = 2");
47         session.execute("x + y");
48     }
49     
50     @Test
51     public void testCommandSession2() {
52         CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
53         
54         session.execute("f name coords = print \"\\(name :: String) \\(coords :: (Double, Double))\"");
55         session.execute("g name (x,y) = f name (x,y)");
56     }
57     
58     @Test
59     public void testTyping1() {
60         CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
61         
62         session.execute("apply f = f ()");
63         session.execute("printHello () = print \"Hello\"");
64         session.execute("apply printHello");
65     }
66     
67     @Test
68     public void testTyping2() {
69         CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
70         
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) [(),(),()]");
74     }
75
76 }