]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/TestCommandSession.java
Fixed multiple issues causing dangling references to discarded queries
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / TestCommandSession.java
index 4a9bffd093c0b0737804008a4f7f148e63e3c058..ffeaa6b6ff8fa7cc42e011f5c19c863aaa9db54b 100644 (file)
@@ -1,14 +1,20 @@
 package org.simantics.scl.compiler.tests;
 
+import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.simantics.scl.compiler.commands.CommandSession;
+import org.simantics.scl.compiler.errors.CompilationError;
 import org.simantics.scl.compiler.module.repository.ModuleRepository;
 import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler;
 import org.simantics.scl.runtime.reporting.SCLReportingHandler;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
 
 public class TestCommandSession {
 
+    private static final Logger LOGGER = LoggerFactory.getLogger(TestCommandSession.class);
     ModuleRepository moduleRepository;
 
     @Before
@@ -26,11 +32,11 @@ public class TestCommandSession {
     private static final SCLReportingHandler TEST_HANDLER = new AbstractSCLReportingHandler() {
         @Override
         public void print(String text) {
-            System.out.println(text);
+            LOGGER.info(text);
         }
         
         public void printError(String error) {
-            System.err.println(error);
+            LOGGER.error(error);
             throw new SCLErrorMessageException(error);
         }
     };
@@ -72,5 +78,33 @@ public class TestCommandSession {
         session.execute("iter (\\i -> print i) [1,2,3]");
         session.execute("iter (\\i -> print i) [(),(),()]");
     }
+    
+    @Test
+    public void testValidation() {
+        {
+            CompilationError[] errors = CommandSession.validate(moduleRepository, "1+1");
+            Assert.assertEquals(0, errors.length);
+        }
+        {
+            CompilationError[] errors = CommandSession.validate(moduleRepository, "\"a\"+1");
+            Assert.assertEquals(1, errors.length);
+        }
+        {
+            CompilationError[] errors = CommandSession.validate(moduleRepository,
+                    "a = 1\n" +
+                    "b = 2\n" +
+                    "a + b");
+            Assert.assertEquals(0, errors.length);
+        }
+        {
+            String source = 
+                    "a = 1\n" +
+                    "b = 2.0\n" +
+                    "a + b"; 
+            CompilationError[] errors = CommandSession.validate(moduleRepository, source);
+            //System.out.println(CompilationErrorFormatter.toString(source, errors));
+            Assert.assertEquals(1, errors.length);
+        }
+    }
 
 }