X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=tests%2Forg.simantics.scl.compiler.tests%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2FTestCommandSession.java;h=ffeaa6b6ff8fa7cc42e011f5c19c863aaa9db54b;hp=b86f097b84bf0445542619cfb30eef76ecce838e;hb=1dfeb7d5c49b1391cd9d877e1eddab18995cb151;hpb=5930811a7911090a0c4984380c3b45ed81a93cde 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 index b86f097b8..ffeaa6b6f 100644 --- 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 @@ -1,16 +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.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; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class TestCommandSession { + private static final Logger LOGGER = LoggerFactory.getLogger(TestCommandSession.class); ModuleRepository moduleRepository; @Before @@ -28,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); } }; @@ -74,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); + } + } }