X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=tests%2Forg.simantics.scl.compiler.tests%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2FTestCommandSession.java;fp=tests%2Forg.simantics.scl.compiler.tests%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2FTestCommandSession.java;h=b86f097b84bf0445542619cfb30eef76ecce838e;hb=0364f8f54b009e9e5de482d5c9d1cb7efb023141;hp=0000000000000000000000000000000000000000;hpb=7ecf07ff9aacab300f1fb900f1f0f97beb1be139;p=simantics%2Fplatform.git 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 index 000000000..b86f097b8 --- /dev/null +++ b/tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/TestCommandSession.java @@ -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) [(),(),()]"); + } + +}