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
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);
}
};
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);
+ }
+ }
}