]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/TestCommandSession.java
Automatic execution of SCL tests in Maven
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / TestCommandSession.java
diff --git a/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/TestCommandSession.java b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/TestCommandSession.java
new file mode 100644 (file)
index 0000000..b86f097
--- /dev/null
@@ -0,0 +1,78 @@
+package org.simantics.scl.compiler.tests;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.simantics.scl.compiler.commands.CommandSession;
+import org.simantics.scl.compiler.module.repository.ModuleRepository;
+import org.simantics.scl.compiler.source.repository.CompositeModuleSourceRepository;
+import org.simantics.scl.compiler.source.repository.SourceRepositories;
+import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler;
+import org.simantics.scl.runtime.reporting.SCLReportingHandler;
+
+public class TestCommandSession {
+
+    ModuleRepository moduleRepository;
+
+    @Before
+    public void initialize() throws Exception {
+        moduleRepository = InitialRepository.getInitialRepository();
+    }
+    
+    private static class SCLErrorMessageException extends RuntimeException {
+        private static final long serialVersionUID = 418954639267697065L;
+        public SCLErrorMessageException(String message) {
+            super(message);
+        }
+    }
+    
+    private static final SCLReportingHandler TEST_HANDLER = new AbstractSCLReportingHandler() {
+        @Override
+        public void print(String text) {
+            System.out.println(text);
+        }
+        
+        public void printError(String error) {
+            System.err.println(error);
+            throw new SCLErrorMessageException(error);
+        }
+    };
+
+    @Test
+    public void testCommandSession() {
+        CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
+        
+        session.execute("a = 1");
+        session.execute("b = 2");
+        session.execute("a + b");
+        
+        session.execute("x = 1\ny = 2");
+        session.execute("x + y");
+    }
+    
+    @Test
+    public void testCommandSession2() {
+        CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
+        
+        session.execute("f name coords = print \"\\(name :: String) \\(coords :: (Double, Double))\"");
+        session.execute("g name (x,y) = f name (x,y)");
+    }
+    
+    @Test
+    public void testTyping1() {
+        CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
+        
+        session.execute("apply f = f ()");
+        session.execute("printHello () = print \"Hello\"");
+        session.execute("apply printHello");
+    }
+    
+    @Test
+    public void testTyping2() {
+        CommandSession session = new CommandSession(moduleRepository, TEST_HANDLER);
+        
+        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) }");
+        session.execute("iter (\\i -> print i) [1,2,3]");
+        session.execute("iter (\\i -> print i) [(),(),()]");
+    }
+
+}